WIP FPC-III support
[linux/fpc-iii.git] / drivers / scsi / bfa / bfa_fcpim.c
blob38d1c453074dc1d91198d1aed575b18f40c1afbe
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
4 * Copyright (c) 2014- QLogic Corporation.
5 * All rights reserved
6 * www.qlogic.com
8 * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
9 */
11 #include "bfad_drv.h"
12 #include "bfa_modules.h"
14 BFA_TRC_FILE(HAL, FCPIM);
17 * BFA ITNIM Related definitions
19 static void bfa_itnim_update_del_itn_stats(struct bfa_itnim_s *itnim);
21 #define BFA_ITNIM_FROM_TAG(_fcpim, _tag) \
22 (((_fcpim)->itnim_arr + ((_tag) & ((_fcpim)->num_itnims - 1))))
24 #define bfa_fcpim_additn(__itnim) \
25 list_add_tail(&(__itnim)->qe, &(__itnim)->fcpim->itnim_q)
26 #define bfa_fcpim_delitn(__itnim) do { \
27 WARN_ON(!bfa_q_is_on_q(&(__itnim)->fcpim->itnim_q, __itnim)); \
28 bfa_itnim_update_del_itn_stats(__itnim); \
29 list_del(&(__itnim)->qe); \
30 WARN_ON(!list_empty(&(__itnim)->io_q)); \
31 WARN_ON(!list_empty(&(__itnim)->io_cleanup_q)); \
32 WARN_ON(!list_empty(&(__itnim)->pending_q)); \
33 } while (0)
35 #define bfa_itnim_online_cb(__itnim) do { \
36 if ((__itnim)->bfa->fcs) \
37 bfa_cb_itnim_online((__itnim)->ditn); \
38 else { \
39 bfa_cb_queue((__itnim)->bfa, &(__itnim)->hcb_qe, \
40 __bfa_cb_itnim_online, (__itnim)); \
41 } \
42 } while (0)
44 #define bfa_itnim_offline_cb(__itnim) do { \
45 if ((__itnim)->bfa->fcs) \
46 bfa_cb_itnim_offline((__itnim)->ditn); \
47 else { \
48 bfa_cb_queue((__itnim)->bfa, &(__itnim)->hcb_qe, \
49 __bfa_cb_itnim_offline, (__itnim)); \
50 } \
51 } while (0)
53 #define bfa_itnim_sler_cb(__itnim) do { \
54 if ((__itnim)->bfa->fcs) \
55 bfa_cb_itnim_sler((__itnim)->ditn); \
56 else { \
57 bfa_cb_queue((__itnim)->bfa, &(__itnim)->hcb_qe, \
58 __bfa_cb_itnim_sler, (__itnim)); \
59 } \
60 } while (0)
62 enum bfa_ioim_lm_ua_status {
63 BFA_IOIM_LM_UA_RESET = 0,
64 BFA_IOIM_LM_UA_SET = 1,
68 * itnim state machine event
70 enum bfa_itnim_event {
71 BFA_ITNIM_SM_CREATE = 1, /* itnim is created */
72 BFA_ITNIM_SM_ONLINE = 2, /* itnim is online */
73 BFA_ITNIM_SM_OFFLINE = 3, /* itnim is offline */
74 BFA_ITNIM_SM_FWRSP = 4, /* firmware response */
75 BFA_ITNIM_SM_DELETE = 5, /* deleting an existing itnim */
76 BFA_ITNIM_SM_CLEANUP = 6, /* IO cleanup completion */
77 BFA_ITNIM_SM_SLER = 7, /* second level error recovery */
78 BFA_ITNIM_SM_HWFAIL = 8, /* IOC h/w failure event */
79 BFA_ITNIM_SM_QRESUME = 9, /* queue space available */
83 * BFA IOIM related definitions
85 #define bfa_ioim_move_to_comp_q(__ioim) do { \
86 list_del(&(__ioim)->qe); \
87 list_add_tail(&(__ioim)->qe, &(__ioim)->fcpim->ioim_comp_q); \
88 } while (0)
91 #define bfa_ioim_cb_profile_comp(__fcpim, __ioim) do { \
92 if ((__fcpim)->profile_comp) \
93 (__fcpim)->profile_comp(__ioim); \
94 } while (0)
96 #define bfa_ioim_cb_profile_start(__fcpim, __ioim) do { \
97 if ((__fcpim)->profile_start) \
98 (__fcpim)->profile_start(__ioim); \
99 } while (0)
102 * IO state machine events
104 enum bfa_ioim_event {
105 BFA_IOIM_SM_START = 1, /* io start request from host */
106 BFA_IOIM_SM_COMP_GOOD = 2, /* io good comp, resource free */
107 BFA_IOIM_SM_COMP = 3, /* io comp, resource is free */
108 BFA_IOIM_SM_COMP_UTAG = 4, /* io comp, resource is free */
109 BFA_IOIM_SM_DONE = 5, /* io comp, resource not free */
110 BFA_IOIM_SM_FREE = 6, /* io resource is freed */
111 BFA_IOIM_SM_ABORT = 7, /* abort request from scsi stack */
112 BFA_IOIM_SM_ABORT_COMP = 8, /* abort from f/w */
113 BFA_IOIM_SM_ABORT_DONE = 9, /* abort completion from f/w */
114 BFA_IOIM_SM_QRESUME = 10, /* CQ space available to queue IO */
115 BFA_IOIM_SM_SGALLOCED = 11, /* SG page allocation successful */
116 BFA_IOIM_SM_SQRETRY = 12, /* sequence recovery retry */
117 BFA_IOIM_SM_HCB = 13, /* bfa callback complete */
118 BFA_IOIM_SM_CLEANUP = 14, /* IO cleanup from itnim */
119 BFA_IOIM_SM_TMSTART = 15, /* IO cleanup from tskim */
120 BFA_IOIM_SM_TMDONE = 16, /* IO cleanup from tskim */
121 BFA_IOIM_SM_HWFAIL = 17, /* IOC h/w failure event */
122 BFA_IOIM_SM_IOTOV = 18, /* ITN offline TOV */
127 * BFA TSKIM related definitions
131 * task management completion handling
133 #define bfa_tskim_qcomp(__tskim, __cbfn) do { \
134 bfa_cb_queue((__tskim)->bfa, &(__tskim)->hcb_qe, __cbfn, (__tskim));\
135 bfa_tskim_notify_comp(__tskim); \
136 } while (0)
138 #define bfa_tskim_notify_comp(__tskim) do { \
139 if ((__tskim)->notify) \
140 bfa_itnim_tskdone((__tskim)->itnim); \
141 } while (0)
144 enum bfa_tskim_event {
145 BFA_TSKIM_SM_START = 1, /* TM command start */
146 BFA_TSKIM_SM_DONE = 2, /* TM completion */
147 BFA_TSKIM_SM_QRESUME = 3, /* resume after qfull */
148 BFA_TSKIM_SM_HWFAIL = 5, /* IOC h/w failure event */
149 BFA_TSKIM_SM_HCB = 6, /* BFA callback completion */
150 BFA_TSKIM_SM_IOS_DONE = 7, /* IO and sub TM completions */
151 BFA_TSKIM_SM_CLEANUP = 8, /* TM cleanup on ITN offline */
152 BFA_TSKIM_SM_CLEANUP_DONE = 9, /* TM abort completion */
153 BFA_TSKIM_SM_UTAG = 10, /* TM completion unknown tag */
157 * forward declaration for BFA ITNIM functions
159 static void bfa_itnim_iocdisable_cleanup(struct bfa_itnim_s *itnim);
160 static bfa_boolean_t bfa_itnim_send_fwcreate(struct bfa_itnim_s *itnim);
161 static bfa_boolean_t bfa_itnim_send_fwdelete(struct bfa_itnim_s *itnim);
162 static void bfa_itnim_cleanp_comp(void *itnim_cbarg);
163 static void bfa_itnim_cleanup(struct bfa_itnim_s *itnim);
164 static void __bfa_cb_itnim_online(void *cbarg, bfa_boolean_t complete);
165 static void __bfa_cb_itnim_offline(void *cbarg, bfa_boolean_t complete);
166 static void __bfa_cb_itnim_sler(void *cbarg, bfa_boolean_t complete);
167 static void bfa_itnim_iotov_online(struct bfa_itnim_s *itnim);
168 static void bfa_itnim_iotov_cleanup(struct bfa_itnim_s *itnim);
169 static void bfa_itnim_iotov(void *itnim_arg);
170 static void bfa_itnim_iotov_start(struct bfa_itnim_s *itnim);
171 static void bfa_itnim_iotov_stop(struct bfa_itnim_s *itnim);
172 static void bfa_itnim_iotov_delete(struct bfa_itnim_s *itnim);
175 * forward declaration of ITNIM state machine
177 static void bfa_itnim_sm_uninit(struct bfa_itnim_s *itnim,
178 enum bfa_itnim_event event);
179 static void bfa_itnim_sm_created(struct bfa_itnim_s *itnim,
180 enum bfa_itnim_event event);
181 static void bfa_itnim_sm_fwcreate(struct bfa_itnim_s *itnim,
182 enum bfa_itnim_event event);
183 static void bfa_itnim_sm_delete_pending(struct bfa_itnim_s *itnim,
184 enum bfa_itnim_event event);
185 static void bfa_itnim_sm_online(struct bfa_itnim_s *itnim,
186 enum bfa_itnim_event event);
187 static void bfa_itnim_sm_sler(struct bfa_itnim_s *itnim,
188 enum bfa_itnim_event event);
189 static void bfa_itnim_sm_cleanup_offline(struct bfa_itnim_s *itnim,
190 enum bfa_itnim_event event);
191 static void bfa_itnim_sm_cleanup_delete(struct bfa_itnim_s *itnim,
192 enum bfa_itnim_event event);
193 static void bfa_itnim_sm_fwdelete(struct bfa_itnim_s *itnim,
194 enum bfa_itnim_event event);
195 static void bfa_itnim_sm_offline(struct bfa_itnim_s *itnim,
196 enum bfa_itnim_event event);
197 static void bfa_itnim_sm_iocdisable(struct bfa_itnim_s *itnim,
198 enum bfa_itnim_event event);
199 static void bfa_itnim_sm_deleting(struct bfa_itnim_s *itnim,
200 enum bfa_itnim_event event);
201 static void bfa_itnim_sm_fwcreate_qfull(struct bfa_itnim_s *itnim,
202 enum bfa_itnim_event event);
203 static void bfa_itnim_sm_fwdelete_qfull(struct bfa_itnim_s *itnim,
204 enum bfa_itnim_event event);
205 static void bfa_itnim_sm_deleting_qfull(struct bfa_itnim_s *itnim,
206 enum bfa_itnim_event event);
209 * forward declaration for BFA IOIM functions
211 static bfa_boolean_t bfa_ioim_send_ioreq(struct bfa_ioim_s *ioim);
212 static bfa_boolean_t bfa_ioim_sgpg_alloc(struct bfa_ioim_s *ioim);
213 static bfa_boolean_t bfa_ioim_send_abort(struct bfa_ioim_s *ioim);
214 static void bfa_ioim_notify_cleanup(struct bfa_ioim_s *ioim);
215 static void __bfa_cb_ioim_good_comp(void *cbarg, bfa_boolean_t complete);
216 static void __bfa_cb_ioim_comp(void *cbarg, bfa_boolean_t complete);
217 static void __bfa_cb_ioim_abort(void *cbarg, bfa_boolean_t complete);
218 static void __bfa_cb_ioim_failed(void *cbarg, bfa_boolean_t complete);
219 static void __bfa_cb_ioim_pathtov(void *cbarg, bfa_boolean_t complete);
220 static bfa_boolean_t bfa_ioim_is_abortable(struct bfa_ioim_s *ioim);
223 * forward declaration of BFA IO state machine
225 static void bfa_ioim_sm_uninit(struct bfa_ioim_s *ioim,
226 enum bfa_ioim_event event);
227 static void bfa_ioim_sm_sgalloc(struct bfa_ioim_s *ioim,
228 enum bfa_ioim_event event);
229 static void bfa_ioim_sm_active(struct bfa_ioim_s *ioim,
230 enum bfa_ioim_event event);
231 static void bfa_ioim_sm_abort(struct bfa_ioim_s *ioim,
232 enum bfa_ioim_event event);
233 static void bfa_ioim_sm_cleanup(struct bfa_ioim_s *ioim,
234 enum bfa_ioim_event event);
235 static void bfa_ioim_sm_qfull(struct bfa_ioim_s *ioim,
236 enum bfa_ioim_event event);
237 static void bfa_ioim_sm_abort_qfull(struct bfa_ioim_s *ioim,
238 enum bfa_ioim_event event);
239 static void bfa_ioim_sm_cleanup_qfull(struct bfa_ioim_s *ioim,
240 enum bfa_ioim_event event);
241 static void bfa_ioim_sm_hcb(struct bfa_ioim_s *ioim,
242 enum bfa_ioim_event event);
243 static void bfa_ioim_sm_hcb_free(struct bfa_ioim_s *ioim,
244 enum bfa_ioim_event event);
245 static void bfa_ioim_sm_resfree(struct bfa_ioim_s *ioim,
246 enum bfa_ioim_event event);
247 static void bfa_ioim_sm_cmnd_retry(struct bfa_ioim_s *ioim,
248 enum bfa_ioim_event event);
250 * forward declaration for BFA TSKIM functions
252 static void __bfa_cb_tskim_done(void *cbarg, bfa_boolean_t complete);
253 static void __bfa_cb_tskim_failed(void *cbarg, bfa_boolean_t complete);
254 static bfa_boolean_t bfa_tskim_match_scope(struct bfa_tskim_s *tskim,
255 struct scsi_lun lun);
256 static void bfa_tskim_gather_ios(struct bfa_tskim_s *tskim);
257 static void bfa_tskim_cleanp_comp(void *tskim_cbarg);
258 static void bfa_tskim_cleanup_ios(struct bfa_tskim_s *tskim);
259 static bfa_boolean_t bfa_tskim_send(struct bfa_tskim_s *tskim);
260 static bfa_boolean_t bfa_tskim_send_abort(struct bfa_tskim_s *tskim);
261 static void bfa_tskim_iocdisable_ios(struct bfa_tskim_s *tskim);
264 * forward declaration of BFA TSKIM state machine
266 static void bfa_tskim_sm_uninit(struct bfa_tskim_s *tskim,
267 enum bfa_tskim_event event);
268 static void bfa_tskim_sm_active(struct bfa_tskim_s *tskim,
269 enum bfa_tskim_event event);
270 static void bfa_tskim_sm_cleanup(struct bfa_tskim_s *tskim,
271 enum bfa_tskim_event event);
272 static void bfa_tskim_sm_iocleanup(struct bfa_tskim_s *tskim,
273 enum bfa_tskim_event event);
274 static void bfa_tskim_sm_qfull(struct bfa_tskim_s *tskim,
275 enum bfa_tskim_event event);
276 static void bfa_tskim_sm_cleanup_qfull(struct bfa_tskim_s *tskim,
277 enum bfa_tskim_event event);
278 static void bfa_tskim_sm_hcb(struct bfa_tskim_s *tskim,
279 enum bfa_tskim_event event);
281 * BFA FCP Initiator Mode module
285 * Compute and return memory needed by FCP(im) module.
287 static void
288 bfa_fcpim_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len)
290 bfa_itnim_meminfo(cfg, km_len);
293 * IO memory
295 *km_len += cfg->fwcfg.num_ioim_reqs *
296 (sizeof(struct bfa_ioim_s) + sizeof(struct bfa_ioim_sp_s));
299 * task management command memory
301 if (cfg->fwcfg.num_tskim_reqs < BFA_TSKIM_MIN)
302 cfg->fwcfg.num_tskim_reqs = BFA_TSKIM_MIN;
303 *km_len += cfg->fwcfg.num_tskim_reqs * sizeof(struct bfa_tskim_s);
307 static void
308 bfa_fcpim_attach(struct bfa_fcp_mod_s *fcp, void *bfad,
309 struct bfa_iocfc_cfg_s *cfg, struct bfa_pcidev_s *pcidev)
311 struct bfa_fcpim_s *fcpim = &fcp->fcpim;
312 struct bfa_s *bfa = fcp->bfa;
314 bfa_trc(bfa, cfg->drvcfg.path_tov);
315 bfa_trc(bfa, cfg->fwcfg.num_rports);
316 bfa_trc(bfa, cfg->fwcfg.num_ioim_reqs);
317 bfa_trc(bfa, cfg->fwcfg.num_tskim_reqs);
319 fcpim->fcp = fcp;
320 fcpim->bfa = bfa;
321 fcpim->num_itnims = cfg->fwcfg.num_rports;
322 fcpim->num_tskim_reqs = cfg->fwcfg.num_tskim_reqs;
323 fcpim->path_tov = cfg->drvcfg.path_tov;
324 fcpim->delay_comp = cfg->drvcfg.delay_comp;
325 fcpim->profile_comp = NULL;
326 fcpim->profile_start = NULL;
328 bfa_itnim_attach(fcpim);
329 bfa_tskim_attach(fcpim);
330 bfa_ioim_attach(fcpim);
333 void
334 bfa_fcpim_iocdisable(struct bfa_fcp_mod_s *fcp)
336 struct bfa_fcpim_s *fcpim = &fcp->fcpim;
337 struct bfa_itnim_s *itnim;
338 struct list_head *qe, *qen;
340 /* Enqueue unused ioim resources to free_q */
341 list_splice_tail_init(&fcpim->tskim_unused_q, &fcpim->tskim_free_q);
343 list_for_each_safe(qe, qen, &fcpim->itnim_q) {
344 itnim = (struct bfa_itnim_s *) qe;
345 bfa_itnim_iocdisable(itnim);
349 void
350 bfa_fcpim_path_tov_set(struct bfa_s *bfa, u16 path_tov)
352 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
354 fcpim->path_tov = path_tov * 1000;
355 if (fcpim->path_tov > BFA_FCPIM_PATHTOV_MAX)
356 fcpim->path_tov = BFA_FCPIM_PATHTOV_MAX;
360 bfa_fcpim_path_tov_get(struct bfa_s *bfa)
362 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
364 return fcpim->path_tov / 1000;
367 #define bfa_fcpim_add_iostats(__l, __r, __stats) \
368 (__l->__stats += __r->__stats)
370 void
371 bfa_fcpim_add_stats(struct bfa_itnim_iostats_s *lstats,
372 struct bfa_itnim_iostats_s *rstats)
374 bfa_fcpim_add_iostats(lstats, rstats, total_ios);
375 bfa_fcpim_add_iostats(lstats, rstats, qresumes);
376 bfa_fcpim_add_iostats(lstats, rstats, no_iotags);
377 bfa_fcpim_add_iostats(lstats, rstats, io_aborts);
378 bfa_fcpim_add_iostats(lstats, rstats, no_tskims);
379 bfa_fcpim_add_iostats(lstats, rstats, iocomp_ok);
380 bfa_fcpim_add_iostats(lstats, rstats, iocomp_underrun);
381 bfa_fcpim_add_iostats(lstats, rstats, iocomp_overrun);
382 bfa_fcpim_add_iostats(lstats, rstats, iocomp_aborted);
383 bfa_fcpim_add_iostats(lstats, rstats, iocomp_timedout);
384 bfa_fcpim_add_iostats(lstats, rstats, iocom_nexus_abort);
385 bfa_fcpim_add_iostats(lstats, rstats, iocom_proto_err);
386 bfa_fcpim_add_iostats(lstats, rstats, iocom_dif_err);
387 bfa_fcpim_add_iostats(lstats, rstats, iocom_sqer_needed);
388 bfa_fcpim_add_iostats(lstats, rstats, iocom_res_free);
389 bfa_fcpim_add_iostats(lstats, rstats, iocom_hostabrts);
390 bfa_fcpim_add_iostats(lstats, rstats, iocom_utags);
391 bfa_fcpim_add_iostats(lstats, rstats, io_cleanups);
392 bfa_fcpim_add_iostats(lstats, rstats, io_tmaborts);
393 bfa_fcpim_add_iostats(lstats, rstats, onlines);
394 bfa_fcpim_add_iostats(lstats, rstats, offlines);
395 bfa_fcpim_add_iostats(lstats, rstats, creates);
396 bfa_fcpim_add_iostats(lstats, rstats, deletes);
397 bfa_fcpim_add_iostats(lstats, rstats, create_comps);
398 bfa_fcpim_add_iostats(lstats, rstats, delete_comps);
399 bfa_fcpim_add_iostats(lstats, rstats, sler_events);
400 bfa_fcpim_add_iostats(lstats, rstats, fw_create);
401 bfa_fcpim_add_iostats(lstats, rstats, fw_delete);
402 bfa_fcpim_add_iostats(lstats, rstats, ioc_disabled);
403 bfa_fcpim_add_iostats(lstats, rstats, cleanup_comps);
404 bfa_fcpim_add_iostats(lstats, rstats, tm_cmnds);
405 bfa_fcpim_add_iostats(lstats, rstats, tm_fw_rsps);
406 bfa_fcpim_add_iostats(lstats, rstats, tm_success);
407 bfa_fcpim_add_iostats(lstats, rstats, tm_failures);
408 bfa_fcpim_add_iostats(lstats, rstats, tm_io_comps);
409 bfa_fcpim_add_iostats(lstats, rstats, tm_qresumes);
410 bfa_fcpim_add_iostats(lstats, rstats, tm_iocdowns);
411 bfa_fcpim_add_iostats(lstats, rstats, tm_cleanups);
412 bfa_fcpim_add_iostats(lstats, rstats, tm_cleanup_comps);
413 bfa_fcpim_add_iostats(lstats, rstats, io_comps);
414 bfa_fcpim_add_iostats(lstats, rstats, input_reqs);
415 bfa_fcpim_add_iostats(lstats, rstats, output_reqs);
416 bfa_fcpim_add_iostats(lstats, rstats, rd_throughput);
417 bfa_fcpim_add_iostats(lstats, rstats, wr_throughput);
420 bfa_status_t
421 bfa_fcpim_port_iostats(struct bfa_s *bfa,
422 struct bfa_itnim_iostats_s *stats, u8 lp_tag)
424 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
425 struct list_head *qe, *qen;
426 struct bfa_itnim_s *itnim;
428 /* accumulate IO stats from itnim */
429 memset(stats, 0, sizeof(struct bfa_itnim_iostats_s));
430 list_for_each_safe(qe, qen, &fcpim->itnim_q) {
431 itnim = (struct bfa_itnim_s *) qe;
432 if (itnim->rport->rport_info.lp_tag != lp_tag)
433 continue;
434 bfa_fcpim_add_stats(stats, &(itnim->stats));
436 return BFA_STATUS_OK;
439 static void
440 bfa_ioim_profile_comp(struct bfa_ioim_s *ioim)
442 struct bfa_itnim_latency_s *io_lat =
443 &(ioim->itnim->ioprofile.io_latency);
444 u32 val, idx;
446 val = (u32)(jiffies - ioim->start_time);
447 idx = bfa_ioim_get_index(scsi_bufflen((struct scsi_cmnd *)ioim->dio));
448 bfa_itnim_ioprofile_update(ioim->itnim, idx);
450 io_lat->count[idx]++;
451 io_lat->min[idx] = (io_lat->min[idx] < val) ? io_lat->min[idx] : val;
452 io_lat->max[idx] = (io_lat->max[idx] > val) ? io_lat->max[idx] : val;
453 io_lat->avg[idx] += val;
456 static void
457 bfa_ioim_profile_start(struct bfa_ioim_s *ioim)
459 ioim->start_time = jiffies;
462 bfa_status_t
463 bfa_fcpim_profile_on(struct bfa_s *bfa, time64_t time)
465 struct bfa_itnim_s *itnim;
466 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
467 struct list_head *qe, *qen;
469 /* accumulate IO stats from itnim */
470 list_for_each_safe(qe, qen, &fcpim->itnim_q) {
471 itnim = (struct bfa_itnim_s *) qe;
472 bfa_itnim_clear_stats(itnim);
474 fcpim->io_profile = BFA_TRUE;
475 fcpim->io_profile_start_time = time;
476 fcpim->profile_comp = bfa_ioim_profile_comp;
477 fcpim->profile_start = bfa_ioim_profile_start;
478 return BFA_STATUS_OK;
481 bfa_status_t
482 bfa_fcpim_profile_off(struct bfa_s *bfa)
484 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
485 fcpim->io_profile = BFA_FALSE;
486 fcpim->io_profile_start_time = 0;
487 fcpim->profile_comp = NULL;
488 fcpim->profile_start = NULL;
489 return BFA_STATUS_OK;
493 bfa_fcpim_qdepth_get(struct bfa_s *bfa)
495 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
497 return fcpim->q_depth;
501 * BFA ITNIM module state machine functions
505 * Beginning/unallocated state - no events expected.
507 static void
508 bfa_itnim_sm_uninit(struct bfa_itnim_s *itnim, enum bfa_itnim_event event)
510 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
511 bfa_trc(itnim->bfa, event);
513 switch (event) {
514 case BFA_ITNIM_SM_CREATE:
515 bfa_sm_set_state(itnim, bfa_itnim_sm_created);
516 itnim->is_online = BFA_FALSE;
517 bfa_fcpim_additn(itnim);
518 break;
520 default:
521 bfa_sm_fault(itnim->bfa, event);
526 * Beginning state, only online event expected.
528 static void
529 bfa_itnim_sm_created(struct bfa_itnim_s *itnim, enum bfa_itnim_event event)
531 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
532 bfa_trc(itnim->bfa, event);
534 switch (event) {
535 case BFA_ITNIM_SM_ONLINE:
536 if (bfa_itnim_send_fwcreate(itnim))
537 bfa_sm_set_state(itnim, bfa_itnim_sm_fwcreate);
538 else
539 bfa_sm_set_state(itnim, bfa_itnim_sm_fwcreate_qfull);
540 break;
542 case BFA_ITNIM_SM_DELETE:
543 bfa_sm_set_state(itnim, bfa_itnim_sm_uninit);
544 bfa_fcpim_delitn(itnim);
545 break;
547 case BFA_ITNIM_SM_HWFAIL:
548 bfa_sm_set_state(itnim, bfa_itnim_sm_iocdisable);
549 break;
551 default:
552 bfa_sm_fault(itnim->bfa, event);
557 * Waiting for itnim create response from firmware.
559 static void
560 bfa_itnim_sm_fwcreate(struct bfa_itnim_s *itnim, enum bfa_itnim_event event)
562 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
563 bfa_trc(itnim->bfa, event);
565 switch (event) {
566 case BFA_ITNIM_SM_FWRSP:
567 bfa_sm_set_state(itnim, bfa_itnim_sm_online);
568 itnim->is_online = BFA_TRUE;
569 bfa_itnim_iotov_online(itnim);
570 bfa_itnim_online_cb(itnim);
571 break;
573 case BFA_ITNIM_SM_DELETE:
574 bfa_sm_set_state(itnim, bfa_itnim_sm_delete_pending);
575 break;
577 case BFA_ITNIM_SM_OFFLINE:
578 if (bfa_itnim_send_fwdelete(itnim))
579 bfa_sm_set_state(itnim, bfa_itnim_sm_fwdelete);
580 else
581 bfa_sm_set_state(itnim, bfa_itnim_sm_fwdelete_qfull);
582 break;
584 case BFA_ITNIM_SM_HWFAIL:
585 bfa_sm_set_state(itnim, bfa_itnim_sm_iocdisable);
586 break;
588 default:
589 bfa_sm_fault(itnim->bfa, event);
593 static void
594 bfa_itnim_sm_fwcreate_qfull(struct bfa_itnim_s *itnim,
595 enum bfa_itnim_event event)
597 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
598 bfa_trc(itnim->bfa, event);
600 switch (event) {
601 case BFA_ITNIM_SM_QRESUME:
602 bfa_sm_set_state(itnim, bfa_itnim_sm_fwcreate);
603 bfa_itnim_send_fwcreate(itnim);
604 break;
606 case BFA_ITNIM_SM_DELETE:
607 bfa_sm_set_state(itnim, bfa_itnim_sm_uninit);
608 bfa_reqq_wcancel(&itnim->reqq_wait);
609 bfa_fcpim_delitn(itnim);
610 break;
612 case BFA_ITNIM_SM_OFFLINE:
613 bfa_sm_set_state(itnim, bfa_itnim_sm_offline);
614 bfa_reqq_wcancel(&itnim->reqq_wait);
615 bfa_itnim_offline_cb(itnim);
616 break;
618 case BFA_ITNIM_SM_HWFAIL:
619 bfa_sm_set_state(itnim, bfa_itnim_sm_iocdisable);
620 bfa_reqq_wcancel(&itnim->reqq_wait);
621 break;
623 default:
624 bfa_sm_fault(itnim->bfa, event);
629 * Waiting for itnim create response from firmware, a delete is pending.
631 static void
632 bfa_itnim_sm_delete_pending(struct bfa_itnim_s *itnim,
633 enum bfa_itnim_event event)
635 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
636 bfa_trc(itnim->bfa, event);
638 switch (event) {
639 case BFA_ITNIM_SM_FWRSP:
640 if (bfa_itnim_send_fwdelete(itnim))
641 bfa_sm_set_state(itnim, bfa_itnim_sm_deleting);
642 else
643 bfa_sm_set_state(itnim, bfa_itnim_sm_deleting_qfull);
644 break;
646 case BFA_ITNIM_SM_HWFAIL:
647 bfa_sm_set_state(itnim, bfa_itnim_sm_uninit);
648 bfa_fcpim_delitn(itnim);
649 break;
651 default:
652 bfa_sm_fault(itnim->bfa, event);
657 * Online state - normal parking state.
659 static void
660 bfa_itnim_sm_online(struct bfa_itnim_s *itnim, enum bfa_itnim_event event)
662 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
663 bfa_trc(itnim->bfa, event);
665 switch (event) {
666 case BFA_ITNIM_SM_OFFLINE:
667 bfa_sm_set_state(itnim, bfa_itnim_sm_cleanup_offline);
668 itnim->is_online = BFA_FALSE;
669 bfa_itnim_iotov_start(itnim);
670 bfa_itnim_cleanup(itnim);
671 break;
673 case BFA_ITNIM_SM_DELETE:
674 bfa_sm_set_state(itnim, bfa_itnim_sm_cleanup_delete);
675 itnim->is_online = BFA_FALSE;
676 bfa_itnim_cleanup(itnim);
677 break;
679 case BFA_ITNIM_SM_SLER:
680 bfa_sm_set_state(itnim, bfa_itnim_sm_sler);
681 itnim->is_online = BFA_FALSE;
682 bfa_itnim_iotov_start(itnim);
683 bfa_itnim_sler_cb(itnim);
684 break;
686 case BFA_ITNIM_SM_HWFAIL:
687 bfa_sm_set_state(itnim, bfa_itnim_sm_iocdisable);
688 itnim->is_online = BFA_FALSE;
689 bfa_itnim_iotov_start(itnim);
690 bfa_itnim_iocdisable_cleanup(itnim);
691 break;
693 default:
694 bfa_sm_fault(itnim->bfa, event);
699 * Second level error recovery need.
701 static void
702 bfa_itnim_sm_sler(struct bfa_itnim_s *itnim, enum bfa_itnim_event event)
704 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
705 bfa_trc(itnim->bfa, event);
707 switch (event) {
708 case BFA_ITNIM_SM_OFFLINE:
709 bfa_sm_set_state(itnim, bfa_itnim_sm_cleanup_offline);
710 bfa_itnim_cleanup(itnim);
711 break;
713 case BFA_ITNIM_SM_DELETE:
714 bfa_sm_set_state(itnim, bfa_itnim_sm_cleanup_delete);
715 bfa_itnim_cleanup(itnim);
716 bfa_itnim_iotov_delete(itnim);
717 break;
719 case BFA_ITNIM_SM_HWFAIL:
720 bfa_sm_set_state(itnim, bfa_itnim_sm_iocdisable);
721 bfa_itnim_iocdisable_cleanup(itnim);
722 break;
724 default:
725 bfa_sm_fault(itnim->bfa, event);
730 * Going offline. Waiting for active IO cleanup.
732 static void
733 bfa_itnim_sm_cleanup_offline(struct bfa_itnim_s *itnim,
734 enum bfa_itnim_event event)
736 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
737 bfa_trc(itnim->bfa, event);
739 switch (event) {
740 case BFA_ITNIM_SM_CLEANUP:
741 if (bfa_itnim_send_fwdelete(itnim))
742 bfa_sm_set_state(itnim, bfa_itnim_sm_fwdelete);
743 else
744 bfa_sm_set_state(itnim, bfa_itnim_sm_fwdelete_qfull);
745 break;
747 case BFA_ITNIM_SM_DELETE:
748 bfa_sm_set_state(itnim, bfa_itnim_sm_cleanup_delete);
749 bfa_itnim_iotov_delete(itnim);
750 break;
752 case BFA_ITNIM_SM_HWFAIL:
753 bfa_sm_set_state(itnim, bfa_itnim_sm_iocdisable);
754 bfa_itnim_iocdisable_cleanup(itnim);
755 bfa_itnim_offline_cb(itnim);
756 break;
758 case BFA_ITNIM_SM_SLER:
759 break;
761 default:
762 bfa_sm_fault(itnim->bfa, event);
767 * Deleting itnim. Waiting for active IO cleanup.
769 static void
770 bfa_itnim_sm_cleanup_delete(struct bfa_itnim_s *itnim,
771 enum bfa_itnim_event event)
773 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
774 bfa_trc(itnim->bfa, event);
776 switch (event) {
777 case BFA_ITNIM_SM_CLEANUP:
778 if (bfa_itnim_send_fwdelete(itnim))
779 bfa_sm_set_state(itnim, bfa_itnim_sm_deleting);
780 else
781 bfa_sm_set_state(itnim, bfa_itnim_sm_deleting_qfull);
782 break;
784 case BFA_ITNIM_SM_HWFAIL:
785 bfa_sm_set_state(itnim, bfa_itnim_sm_iocdisable);
786 bfa_itnim_iocdisable_cleanup(itnim);
787 break;
789 default:
790 bfa_sm_fault(itnim->bfa, event);
795 * Rport offline. Fimrware itnim is being deleted - awaiting f/w response.
797 static void
798 bfa_itnim_sm_fwdelete(struct bfa_itnim_s *itnim, enum bfa_itnim_event event)
800 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
801 bfa_trc(itnim->bfa, event);
803 switch (event) {
804 case BFA_ITNIM_SM_FWRSP:
805 bfa_sm_set_state(itnim, bfa_itnim_sm_offline);
806 bfa_itnim_offline_cb(itnim);
807 break;
809 case BFA_ITNIM_SM_DELETE:
810 bfa_sm_set_state(itnim, bfa_itnim_sm_deleting);
811 break;
813 case BFA_ITNIM_SM_HWFAIL:
814 bfa_sm_set_state(itnim, bfa_itnim_sm_iocdisable);
815 bfa_itnim_offline_cb(itnim);
816 break;
818 default:
819 bfa_sm_fault(itnim->bfa, event);
823 static void
824 bfa_itnim_sm_fwdelete_qfull(struct bfa_itnim_s *itnim,
825 enum bfa_itnim_event event)
827 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
828 bfa_trc(itnim->bfa, event);
830 switch (event) {
831 case BFA_ITNIM_SM_QRESUME:
832 bfa_sm_set_state(itnim, bfa_itnim_sm_fwdelete);
833 bfa_itnim_send_fwdelete(itnim);
834 break;
836 case BFA_ITNIM_SM_DELETE:
837 bfa_sm_set_state(itnim, bfa_itnim_sm_deleting_qfull);
838 break;
840 case BFA_ITNIM_SM_HWFAIL:
841 bfa_sm_set_state(itnim, bfa_itnim_sm_iocdisable);
842 bfa_reqq_wcancel(&itnim->reqq_wait);
843 bfa_itnim_offline_cb(itnim);
844 break;
846 default:
847 bfa_sm_fault(itnim->bfa, event);
852 * Offline state.
854 static void
855 bfa_itnim_sm_offline(struct bfa_itnim_s *itnim, enum bfa_itnim_event event)
857 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
858 bfa_trc(itnim->bfa, event);
860 switch (event) {
861 case BFA_ITNIM_SM_DELETE:
862 bfa_sm_set_state(itnim, bfa_itnim_sm_uninit);
863 bfa_itnim_iotov_delete(itnim);
864 bfa_fcpim_delitn(itnim);
865 break;
867 case BFA_ITNIM_SM_ONLINE:
868 if (bfa_itnim_send_fwcreate(itnim))
869 bfa_sm_set_state(itnim, bfa_itnim_sm_fwcreate);
870 else
871 bfa_sm_set_state(itnim, bfa_itnim_sm_fwcreate_qfull);
872 break;
874 case BFA_ITNIM_SM_HWFAIL:
875 bfa_sm_set_state(itnim, bfa_itnim_sm_iocdisable);
876 break;
878 default:
879 bfa_sm_fault(itnim->bfa, event);
883 static void
884 bfa_itnim_sm_iocdisable(struct bfa_itnim_s *itnim,
885 enum bfa_itnim_event event)
887 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
888 bfa_trc(itnim->bfa, event);
890 switch (event) {
891 case BFA_ITNIM_SM_DELETE:
892 bfa_sm_set_state(itnim, bfa_itnim_sm_uninit);
893 bfa_itnim_iotov_delete(itnim);
894 bfa_fcpim_delitn(itnim);
895 break;
897 case BFA_ITNIM_SM_OFFLINE:
898 bfa_itnim_offline_cb(itnim);
899 break;
901 case BFA_ITNIM_SM_ONLINE:
902 if (bfa_itnim_send_fwcreate(itnim))
903 bfa_sm_set_state(itnim, bfa_itnim_sm_fwcreate);
904 else
905 bfa_sm_set_state(itnim, bfa_itnim_sm_fwcreate_qfull);
906 break;
908 case BFA_ITNIM_SM_HWFAIL:
909 break;
911 default:
912 bfa_sm_fault(itnim->bfa, event);
917 * Itnim is deleted, waiting for firmware response to delete.
919 static void
920 bfa_itnim_sm_deleting(struct bfa_itnim_s *itnim, enum bfa_itnim_event event)
922 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
923 bfa_trc(itnim->bfa, event);
925 switch (event) {
926 case BFA_ITNIM_SM_FWRSP:
927 case BFA_ITNIM_SM_HWFAIL:
928 bfa_sm_set_state(itnim, bfa_itnim_sm_uninit);
929 bfa_fcpim_delitn(itnim);
930 break;
932 default:
933 bfa_sm_fault(itnim->bfa, event);
937 static void
938 bfa_itnim_sm_deleting_qfull(struct bfa_itnim_s *itnim,
939 enum bfa_itnim_event event)
941 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
942 bfa_trc(itnim->bfa, event);
944 switch (event) {
945 case BFA_ITNIM_SM_QRESUME:
946 bfa_sm_set_state(itnim, bfa_itnim_sm_deleting);
947 bfa_itnim_send_fwdelete(itnim);
948 break;
950 case BFA_ITNIM_SM_HWFAIL:
951 bfa_sm_set_state(itnim, bfa_itnim_sm_uninit);
952 bfa_reqq_wcancel(&itnim->reqq_wait);
953 bfa_fcpim_delitn(itnim);
954 break;
956 default:
957 bfa_sm_fault(itnim->bfa, event);
962 * Initiate cleanup of all IOs on an IOC failure.
964 static void
965 bfa_itnim_iocdisable_cleanup(struct bfa_itnim_s *itnim)
967 struct bfa_tskim_s *tskim;
968 struct bfa_ioim_s *ioim;
969 struct list_head *qe, *qen;
971 list_for_each_safe(qe, qen, &itnim->tsk_q) {
972 tskim = (struct bfa_tskim_s *) qe;
973 bfa_tskim_iocdisable(tskim);
976 list_for_each_safe(qe, qen, &itnim->io_q) {
977 ioim = (struct bfa_ioim_s *) qe;
978 bfa_ioim_iocdisable(ioim);
982 * For IO request in pending queue, we pretend an early timeout.
984 list_for_each_safe(qe, qen, &itnim->pending_q) {
985 ioim = (struct bfa_ioim_s *) qe;
986 bfa_ioim_tov(ioim);
989 list_for_each_safe(qe, qen, &itnim->io_cleanup_q) {
990 ioim = (struct bfa_ioim_s *) qe;
991 bfa_ioim_iocdisable(ioim);
996 * IO cleanup completion
998 static void
999 bfa_itnim_cleanp_comp(void *itnim_cbarg)
1001 struct bfa_itnim_s *itnim = itnim_cbarg;
1003 bfa_stats(itnim, cleanup_comps);
1004 bfa_sm_send_event(itnim, BFA_ITNIM_SM_CLEANUP);
1008 * Initiate cleanup of all IOs.
1010 static void
1011 bfa_itnim_cleanup(struct bfa_itnim_s *itnim)
1013 struct bfa_ioim_s *ioim;
1014 struct bfa_tskim_s *tskim;
1015 struct list_head *qe, *qen;
1017 bfa_wc_init(&itnim->wc, bfa_itnim_cleanp_comp, itnim);
1019 list_for_each_safe(qe, qen, &itnim->io_q) {
1020 ioim = (struct bfa_ioim_s *) qe;
1023 * Move IO to a cleanup queue from active queue so that a later
1024 * TM will not pickup this IO.
1026 list_del(&ioim->qe);
1027 list_add_tail(&ioim->qe, &itnim->io_cleanup_q);
1029 bfa_wc_up(&itnim->wc);
1030 bfa_ioim_cleanup(ioim);
1033 list_for_each_safe(qe, qen, &itnim->tsk_q) {
1034 tskim = (struct bfa_tskim_s *) qe;
1035 bfa_wc_up(&itnim->wc);
1036 bfa_tskim_cleanup(tskim);
1039 bfa_wc_wait(&itnim->wc);
1042 static void
1043 __bfa_cb_itnim_online(void *cbarg, bfa_boolean_t complete)
1045 struct bfa_itnim_s *itnim = cbarg;
1047 if (complete)
1048 bfa_cb_itnim_online(itnim->ditn);
1051 static void
1052 __bfa_cb_itnim_offline(void *cbarg, bfa_boolean_t complete)
1054 struct bfa_itnim_s *itnim = cbarg;
1056 if (complete)
1057 bfa_cb_itnim_offline(itnim->ditn);
1060 static void
1061 __bfa_cb_itnim_sler(void *cbarg, bfa_boolean_t complete)
1063 struct bfa_itnim_s *itnim = cbarg;
1065 if (complete)
1066 bfa_cb_itnim_sler(itnim->ditn);
1070 * Call to resume any I/O requests waiting for room in request queue.
1072 static void
1073 bfa_itnim_qresume(void *cbarg)
1075 struct bfa_itnim_s *itnim = cbarg;
1077 bfa_sm_send_event(itnim, BFA_ITNIM_SM_QRESUME);
1081 * bfa_itnim_public
1084 void
1085 bfa_itnim_iodone(struct bfa_itnim_s *itnim)
1087 bfa_wc_down(&itnim->wc);
1090 void
1091 bfa_itnim_tskdone(struct bfa_itnim_s *itnim)
1093 bfa_wc_down(&itnim->wc);
1096 void
1097 bfa_itnim_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len)
1100 * ITN memory
1102 *km_len += cfg->fwcfg.num_rports * sizeof(struct bfa_itnim_s);
1105 void
1106 bfa_itnim_attach(struct bfa_fcpim_s *fcpim)
1108 struct bfa_s *bfa = fcpim->bfa;
1109 struct bfa_fcp_mod_s *fcp = fcpim->fcp;
1110 struct bfa_itnim_s *itnim;
1111 int i, j;
1113 INIT_LIST_HEAD(&fcpim->itnim_q);
1115 itnim = (struct bfa_itnim_s *) bfa_mem_kva_curp(fcp);
1116 fcpim->itnim_arr = itnim;
1118 for (i = 0; i < fcpim->num_itnims; i++, itnim++) {
1119 memset(itnim, 0, sizeof(struct bfa_itnim_s));
1120 itnim->bfa = bfa;
1121 itnim->fcpim = fcpim;
1122 itnim->reqq = BFA_REQQ_QOS_LO;
1123 itnim->rport = BFA_RPORT_FROM_TAG(bfa, i);
1124 itnim->iotov_active = BFA_FALSE;
1125 bfa_reqq_winit(&itnim->reqq_wait, bfa_itnim_qresume, itnim);
1127 INIT_LIST_HEAD(&itnim->io_q);
1128 INIT_LIST_HEAD(&itnim->io_cleanup_q);
1129 INIT_LIST_HEAD(&itnim->pending_q);
1130 INIT_LIST_HEAD(&itnim->tsk_q);
1131 INIT_LIST_HEAD(&itnim->delay_comp_q);
1132 for (j = 0; j < BFA_IOBUCKET_MAX; j++)
1133 itnim->ioprofile.io_latency.min[j] = ~0;
1134 bfa_sm_set_state(itnim, bfa_itnim_sm_uninit);
1137 bfa_mem_kva_curp(fcp) = (u8 *) itnim;
1140 void
1141 bfa_itnim_iocdisable(struct bfa_itnim_s *itnim)
1143 bfa_stats(itnim, ioc_disabled);
1144 bfa_sm_send_event(itnim, BFA_ITNIM_SM_HWFAIL);
1147 static bfa_boolean_t
1148 bfa_itnim_send_fwcreate(struct bfa_itnim_s *itnim)
1150 struct bfi_itn_create_req_s *m;
1152 itnim->msg_no++;
1155 * check for room in queue to send request now
1157 m = bfa_reqq_next(itnim->bfa, itnim->reqq);
1158 if (!m) {
1159 bfa_reqq_wait(itnim->bfa, itnim->reqq, &itnim->reqq_wait);
1160 return BFA_FALSE;
1163 bfi_h2i_set(m->mh, BFI_MC_ITN, BFI_ITN_H2I_CREATE_REQ,
1164 bfa_fn_lpu(itnim->bfa));
1165 m->fw_handle = itnim->rport->fw_handle;
1166 m->class = FC_CLASS_3;
1167 m->seq_rec = itnim->seq_rec;
1168 m->msg_no = itnim->msg_no;
1169 bfa_stats(itnim, fw_create);
1172 * queue I/O message to firmware
1174 bfa_reqq_produce(itnim->bfa, itnim->reqq, m->mh);
1175 return BFA_TRUE;
1178 static bfa_boolean_t
1179 bfa_itnim_send_fwdelete(struct bfa_itnim_s *itnim)
1181 struct bfi_itn_delete_req_s *m;
1184 * check for room in queue to send request now
1186 m = bfa_reqq_next(itnim->bfa, itnim->reqq);
1187 if (!m) {
1188 bfa_reqq_wait(itnim->bfa, itnim->reqq, &itnim->reqq_wait);
1189 return BFA_FALSE;
1192 bfi_h2i_set(m->mh, BFI_MC_ITN, BFI_ITN_H2I_DELETE_REQ,
1193 bfa_fn_lpu(itnim->bfa));
1194 m->fw_handle = itnim->rport->fw_handle;
1195 bfa_stats(itnim, fw_delete);
1198 * queue I/O message to firmware
1200 bfa_reqq_produce(itnim->bfa, itnim->reqq, m->mh);
1201 return BFA_TRUE;
1205 * Cleanup all pending failed inflight requests.
1207 static void
1208 bfa_itnim_delayed_comp(struct bfa_itnim_s *itnim, bfa_boolean_t iotov)
1210 struct bfa_ioim_s *ioim;
1211 struct list_head *qe, *qen;
1213 list_for_each_safe(qe, qen, &itnim->delay_comp_q) {
1214 ioim = (struct bfa_ioim_s *)qe;
1215 bfa_ioim_delayed_comp(ioim, iotov);
1220 * Start all pending IO requests.
1222 static void
1223 bfa_itnim_iotov_online(struct bfa_itnim_s *itnim)
1225 struct bfa_ioim_s *ioim;
1227 bfa_itnim_iotov_stop(itnim);
1230 * Abort all inflight IO requests in the queue
1232 bfa_itnim_delayed_comp(itnim, BFA_FALSE);
1235 * Start all pending IO requests.
1237 while (!list_empty(&itnim->pending_q)) {
1238 bfa_q_deq(&itnim->pending_q, &ioim);
1239 list_add_tail(&ioim->qe, &itnim->io_q);
1240 bfa_ioim_start(ioim);
1245 * Fail all pending IO requests
1247 static void
1248 bfa_itnim_iotov_cleanup(struct bfa_itnim_s *itnim)
1250 struct bfa_ioim_s *ioim;
1253 * Fail all inflight IO requests in the queue
1255 bfa_itnim_delayed_comp(itnim, BFA_TRUE);
1258 * Fail any pending IO requests.
1260 while (!list_empty(&itnim->pending_q)) {
1261 bfa_q_deq(&itnim->pending_q, &ioim);
1262 list_add_tail(&ioim->qe, &ioim->fcpim->ioim_comp_q);
1263 bfa_ioim_tov(ioim);
1268 * IO TOV timer callback. Fail any pending IO requests.
1270 static void
1271 bfa_itnim_iotov(void *itnim_arg)
1273 struct bfa_itnim_s *itnim = itnim_arg;
1275 itnim->iotov_active = BFA_FALSE;
1277 bfa_cb_itnim_tov_begin(itnim->ditn);
1278 bfa_itnim_iotov_cleanup(itnim);
1279 bfa_cb_itnim_tov(itnim->ditn);
1283 * Start IO TOV timer for failing back pending IO requests in offline state.
1285 static void
1286 bfa_itnim_iotov_start(struct bfa_itnim_s *itnim)
1288 if (itnim->fcpim->path_tov > 0) {
1290 itnim->iotov_active = BFA_TRUE;
1291 WARN_ON(!bfa_itnim_hold_io(itnim));
1292 bfa_timer_start(itnim->bfa, &itnim->timer,
1293 bfa_itnim_iotov, itnim, itnim->fcpim->path_tov);
1298 * Stop IO TOV timer.
1300 static void
1301 bfa_itnim_iotov_stop(struct bfa_itnim_s *itnim)
1303 if (itnim->iotov_active) {
1304 itnim->iotov_active = BFA_FALSE;
1305 bfa_timer_stop(&itnim->timer);
1310 * Stop IO TOV timer.
1312 static void
1313 bfa_itnim_iotov_delete(struct bfa_itnim_s *itnim)
1315 bfa_boolean_t pathtov_active = BFA_FALSE;
1317 if (itnim->iotov_active)
1318 pathtov_active = BFA_TRUE;
1320 bfa_itnim_iotov_stop(itnim);
1321 if (pathtov_active)
1322 bfa_cb_itnim_tov_begin(itnim->ditn);
1323 bfa_itnim_iotov_cleanup(itnim);
1324 if (pathtov_active)
1325 bfa_cb_itnim_tov(itnim->ditn);
1328 static void
1329 bfa_itnim_update_del_itn_stats(struct bfa_itnim_s *itnim)
1331 struct bfa_fcpim_s *fcpim = BFA_FCPIM(itnim->bfa);
1332 fcpim->del_itn_stats.del_itn_iocomp_aborted +=
1333 itnim->stats.iocomp_aborted;
1334 fcpim->del_itn_stats.del_itn_iocomp_timedout +=
1335 itnim->stats.iocomp_timedout;
1336 fcpim->del_itn_stats.del_itn_iocom_sqer_needed +=
1337 itnim->stats.iocom_sqer_needed;
1338 fcpim->del_itn_stats.del_itn_iocom_res_free +=
1339 itnim->stats.iocom_res_free;
1340 fcpim->del_itn_stats.del_itn_iocom_hostabrts +=
1341 itnim->stats.iocom_hostabrts;
1342 fcpim->del_itn_stats.del_itn_total_ios += itnim->stats.total_ios;
1343 fcpim->del_itn_stats.del_io_iocdowns += itnim->stats.io_iocdowns;
1344 fcpim->del_itn_stats.del_tm_iocdowns += itnim->stats.tm_iocdowns;
1348 * bfa_itnim_public
1352 * Itnim interrupt processing.
1354 void
1355 bfa_itnim_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
1357 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
1358 union bfi_itn_i2h_msg_u msg;
1359 struct bfa_itnim_s *itnim;
1361 bfa_trc(bfa, m->mhdr.msg_id);
1363 msg.msg = m;
1365 switch (m->mhdr.msg_id) {
1366 case BFI_ITN_I2H_CREATE_RSP:
1367 itnim = BFA_ITNIM_FROM_TAG(fcpim,
1368 msg.create_rsp->bfa_handle);
1369 WARN_ON(msg.create_rsp->status != BFA_STATUS_OK);
1370 bfa_stats(itnim, create_comps);
1371 bfa_sm_send_event(itnim, BFA_ITNIM_SM_FWRSP);
1372 break;
1374 case BFI_ITN_I2H_DELETE_RSP:
1375 itnim = BFA_ITNIM_FROM_TAG(fcpim,
1376 msg.delete_rsp->bfa_handle);
1377 WARN_ON(msg.delete_rsp->status != BFA_STATUS_OK);
1378 bfa_stats(itnim, delete_comps);
1379 bfa_sm_send_event(itnim, BFA_ITNIM_SM_FWRSP);
1380 break;
1382 case BFI_ITN_I2H_SLER_EVENT:
1383 itnim = BFA_ITNIM_FROM_TAG(fcpim,
1384 msg.sler_event->bfa_handle);
1385 bfa_stats(itnim, sler_events);
1386 bfa_sm_send_event(itnim, BFA_ITNIM_SM_SLER);
1387 break;
1389 default:
1390 bfa_trc(bfa, m->mhdr.msg_id);
1391 WARN_ON(1);
1396 * bfa_itnim_api
1399 struct bfa_itnim_s *
1400 bfa_itnim_create(struct bfa_s *bfa, struct bfa_rport_s *rport, void *ditn)
1402 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
1403 struct bfa_itnim_s *itnim;
1405 bfa_itn_create(bfa, rport, bfa_itnim_isr);
1407 itnim = BFA_ITNIM_FROM_TAG(fcpim, rport->rport_tag);
1408 WARN_ON(itnim->rport != rport);
1410 itnim->ditn = ditn;
1412 bfa_stats(itnim, creates);
1413 bfa_sm_send_event(itnim, BFA_ITNIM_SM_CREATE);
1415 return itnim;
1418 void
1419 bfa_itnim_delete(struct bfa_itnim_s *itnim)
1421 bfa_stats(itnim, deletes);
1422 bfa_sm_send_event(itnim, BFA_ITNIM_SM_DELETE);
1425 void
1426 bfa_itnim_online(struct bfa_itnim_s *itnim, bfa_boolean_t seq_rec)
1428 itnim->seq_rec = seq_rec;
1429 bfa_stats(itnim, onlines);
1430 bfa_sm_send_event(itnim, BFA_ITNIM_SM_ONLINE);
1433 void
1434 bfa_itnim_offline(struct bfa_itnim_s *itnim)
1436 bfa_stats(itnim, offlines);
1437 bfa_sm_send_event(itnim, BFA_ITNIM_SM_OFFLINE);
1441 * Return true if itnim is considered offline for holding off IO request.
1442 * IO is not held if itnim is being deleted.
1444 bfa_boolean_t
1445 bfa_itnim_hold_io(struct bfa_itnim_s *itnim)
1447 return itnim->fcpim->path_tov && itnim->iotov_active &&
1448 (bfa_sm_cmp_state(itnim, bfa_itnim_sm_fwcreate) ||
1449 bfa_sm_cmp_state(itnim, bfa_itnim_sm_sler) ||
1450 bfa_sm_cmp_state(itnim, bfa_itnim_sm_cleanup_offline) ||
1451 bfa_sm_cmp_state(itnim, bfa_itnim_sm_fwdelete) ||
1452 bfa_sm_cmp_state(itnim, bfa_itnim_sm_offline) ||
1453 bfa_sm_cmp_state(itnim, bfa_itnim_sm_iocdisable));
1456 #define bfa_io_lat_clock_res_div HZ
1457 #define bfa_io_lat_clock_res_mul 1000
1458 bfa_status_t
1459 bfa_itnim_get_ioprofile(struct bfa_itnim_s *itnim,
1460 struct bfa_itnim_ioprofile_s *ioprofile)
1462 struct bfa_fcpim_s *fcpim;
1464 if (!itnim)
1465 return BFA_STATUS_NO_FCPIM_NEXUS;
1467 fcpim = BFA_FCPIM(itnim->bfa);
1469 if (!fcpim->io_profile)
1470 return BFA_STATUS_IOPROFILE_OFF;
1472 itnim->ioprofile.index = BFA_IOBUCKET_MAX;
1473 /* unsigned 32-bit time_t overflow here in y2106 */
1474 itnim->ioprofile.io_profile_start_time =
1475 bfa_io_profile_start_time(itnim->bfa);
1476 itnim->ioprofile.clock_res_mul = bfa_io_lat_clock_res_mul;
1477 itnim->ioprofile.clock_res_div = bfa_io_lat_clock_res_div;
1478 *ioprofile = itnim->ioprofile;
1480 return BFA_STATUS_OK;
1483 void
1484 bfa_itnim_clear_stats(struct bfa_itnim_s *itnim)
1486 int j;
1488 if (!itnim)
1489 return;
1491 memset(&itnim->stats, 0, sizeof(itnim->stats));
1492 memset(&itnim->ioprofile, 0, sizeof(itnim->ioprofile));
1493 for (j = 0; j < BFA_IOBUCKET_MAX; j++)
1494 itnim->ioprofile.io_latency.min[j] = ~0;
1498 * BFA IO module state machine functions
1502 * IO is not started (unallocated).
1504 static void
1505 bfa_ioim_sm_uninit(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1507 switch (event) {
1508 case BFA_IOIM_SM_START:
1509 if (!bfa_itnim_is_online(ioim->itnim)) {
1510 if (!bfa_itnim_hold_io(ioim->itnim)) {
1511 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1512 list_del(&ioim->qe);
1513 list_add_tail(&ioim->qe,
1514 &ioim->fcpim->ioim_comp_q);
1515 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe,
1516 __bfa_cb_ioim_pathtov, ioim);
1517 } else {
1518 list_del(&ioim->qe);
1519 list_add_tail(&ioim->qe,
1520 &ioim->itnim->pending_q);
1522 break;
1525 if (ioim->nsges > BFI_SGE_INLINE) {
1526 if (!bfa_ioim_sgpg_alloc(ioim)) {
1527 bfa_sm_set_state(ioim, bfa_ioim_sm_sgalloc);
1528 return;
1532 if (!bfa_ioim_send_ioreq(ioim)) {
1533 bfa_sm_set_state(ioim, bfa_ioim_sm_qfull);
1534 break;
1537 bfa_sm_set_state(ioim, bfa_ioim_sm_active);
1538 break;
1540 case BFA_IOIM_SM_IOTOV:
1541 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1542 bfa_ioim_move_to_comp_q(ioim);
1543 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe,
1544 __bfa_cb_ioim_pathtov, ioim);
1545 break;
1547 case BFA_IOIM_SM_ABORT:
1549 * IO in pending queue can get abort requests. Complete abort
1550 * requests immediately.
1552 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1553 WARN_ON(!bfa_q_is_on_q(&ioim->itnim->pending_q, ioim));
1554 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe,
1555 __bfa_cb_ioim_abort, ioim);
1556 break;
1558 default:
1559 bfa_sm_fault(ioim->bfa, event);
1564 * IO is waiting for SG pages.
1566 static void
1567 bfa_ioim_sm_sgalloc(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1569 bfa_trc(ioim->bfa, ioim->iotag);
1570 bfa_trc(ioim->bfa, event);
1572 switch (event) {
1573 case BFA_IOIM_SM_SGALLOCED:
1574 if (!bfa_ioim_send_ioreq(ioim)) {
1575 bfa_sm_set_state(ioim, bfa_ioim_sm_qfull);
1576 break;
1578 bfa_sm_set_state(ioim, bfa_ioim_sm_active);
1579 break;
1581 case BFA_IOIM_SM_CLEANUP:
1582 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1583 bfa_sgpg_wcancel(ioim->bfa, &ioim->iosp->sgpg_wqe);
1584 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_failed,
1585 ioim);
1586 bfa_ioim_notify_cleanup(ioim);
1587 break;
1589 case BFA_IOIM_SM_ABORT:
1590 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1591 bfa_sgpg_wcancel(ioim->bfa, &ioim->iosp->sgpg_wqe);
1592 bfa_ioim_move_to_comp_q(ioim);
1593 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_abort,
1594 ioim);
1595 break;
1597 case BFA_IOIM_SM_HWFAIL:
1598 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1599 bfa_sgpg_wcancel(ioim->bfa, &ioim->iosp->sgpg_wqe);
1600 bfa_ioim_move_to_comp_q(ioim);
1601 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_failed,
1602 ioim);
1603 break;
1605 default:
1606 bfa_sm_fault(ioim->bfa, event);
1611 * IO is active.
1613 static void
1614 bfa_ioim_sm_active(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1616 switch (event) {
1617 case BFA_IOIM_SM_COMP_GOOD:
1618 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1619 bfa_ioim_move_to_comp_q(ioim);
1620 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe,
1621 __bfa_cb_ioim_good_comp, ioim);
1622 break;
1624 case BFA_IOIM_SM_COMP:
1625 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1626 bfa_ioim_move_to_comp_q(ioim);
1627 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_comp,
1628 ioim);
1629 break;
1631 case BFA_IOIM_SM_DONE:
1632 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb_free);
1633 bfa_ioim_move_to_comp_q(ioim);
1634 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_comp,
1635 ioim);
1636 break;
1638 case BFA_IOIM_SM_ABORT:
1639 ioim->iosp->abort_explicit = BFA_TRUE;
1640 ioim->io_cbfn = __bfa_cb_ioim_abort;
1642 if (bfa_ioim_send_abort(ioim))
1643 bfa_sm_set_state(ioim, bfa_ioim_sm_abort);
1644 else {
1645 bfa_sm_set_state(ioim, bfa_ioim_sm_abort_qfull);
1646 bfa_stats(ioim->itnim, qwait);
1647 bfa_reqq_wait(ioim->bfa, ioim->reqq,
1648 &ioim->iosp->reqq_wait);
1650 break;
1652 case BFA_IOIM_SM_CLEANUP:
1653 ioim->iosp->abort_explicit = BFA_FALSE;
1654 ioim->io_cbfn = __bfa_cb_ioim_failed;
1656 if (bfa_ioim_send_abort(ioim))
1657 bfa_sm_set_state(ioim, bfa_ioim_sm_cleanup);
1658 else {
1659 bfa_sm_set_state(ioim, bfa_ioim_sm_cleanup_qfull);
1660 bfa_stats(ioim->itnim, qwait);
1661 bfa_reqq_wait(ioim->bfa, ioim->reqq,
1662 &ioim->iosp->reqq_wait);
1664 break;
1666 case BFA_IOIM_SM_HWFAIL:
1667 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1668 bfa_ioim_move_to_comp_q(ioim);
1669 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_failed,
1670 ioim);
1671 break;
1673 case BFA_IOIM_SM_SQRETRY:
1674 if (bfa_ioim_maxretry_reached(ioim)) {
1675 /* max retry reached, free IO */
1676 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb_free);
1677 bfa_ioim_move_to_comp_q(ioim);
1678 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe,
1679 __bfa_cb_ioim_failed, ioim);
1680 break;
1682 /* waiting for IO tag resource free */
1683 bfa_sm_set_state(ioim, bfa_ioim_sm_cmnd_retry);
1684 break;
1686 default:
1687 bfa_sm_fault(ioim->bfa, event);
1692 * IO is retried with new tag.
1694 static void
1695 bfa_ioim_sm_cmnd_retry(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1697 switch (event) {
1698 case BFA_IOIM_SM_FREE:
1699 /* abts and rrq done. Now retry the IO with new tag */
1700 bfa_ioim_update_iotag(ioim);
1701 if (!bfa_ioim_send_ioreq(ioim)) {
1702 bfa_sm_set_state(ioim, bfa_ioim_sm_qfull);
1703 break;
1705 bfa_sm_set_state(ioim, bfa_ioim_sm_active);
1706 break;
1708 case BFA_IOIM_SM_CLEANUP:
1709 ioim->iosp->abort_explicit = BFA_FALSE;
1710 ioim->io_cbfn = __bfa_cb_ioim_failed;
1712 if (bfa_ioim_send_abort(ioim))
1713 bfa_sm_set_state(ioim, bfa_ioim_sm_cleanup);
1714 else {
1715 bfa_sm_set_state(ioim, bfa_ioim_sm_cleanup_qfull);
1716 bfa_stats(ioim->itnim, qwait);
1717 bfa_reqq_wait(ioim->bfa, ioim->reqq,
1718 &ioim->iosp->reqq_wait);
1720 break;
1722 case BFA_IOIM_SM_HWFAIL:
1723 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1724 bfa_ioim_move_to_comp_q(ioim);
1725 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe,
1726 __bfa_cb_ioim_failed, ioim);
1727 break;
1729 case BFA_IOIM_SM_ABORT:
1730 /* in this state IO abort is done.
1731 * Waiting for IO tag resource free.
1733 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb_free);
1734 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_abort,
1735 ioim);
1736 break;
1738 default:
1739 bfa_sm_fault(ioim->bfa, event);
1744 * IO is being aborted, waiting for completion from firmware.
1746 static void
1747 bfa_ioim_sm_abort(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1749 bfa_trc(ioim->bfa, ioim->iotag);
1750 bfa_trc(ioim->bfa, event);
1752 switch (event) {
1753 case BFA_IOIM_SM_COMP_GOOD:
1754 case BFA_IOIM_SM_COMP:
1755 case BFA_IOIM_SM_DONE:
1756 case BFA_IOIM_SM_FREE:
1757 break;
1759 case BFA_IOIM_SM_ABORT_DONE:
1760 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb_free);
1761 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_abort,
1762 ioim);
1763 break;
1765 case BFA_IOIM_SM_ABORT_COMP:
1766 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1767 bfa_ioim_move_to_comp_q(ioim);
1768 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_abort,
1769 ioim);
1770 break;
1772 case BFA_IOIM_SM_COMP_UTAG:
1773 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1774 bfa_ioim_move_to_comp_q(ioim);
1775 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_abort,
1776 ioim);
1777 break;
1779 case BFA_IOIM_SM_CLEANUP:
1780 WARN_ON(ioim->iosp->abort_explicit != BFA_TRUE);
1781 ioim->iosp->abort_explicit = BFA_FALSE;
1783 if (bfa_ioim_send_abort(ioim))
1784 bfa_sm_set_state(ioim, bfa_ioim_sm_cleanup);
1785 else {
1786 bfa_sm_set_state(ioim, bfa_ioim_sm_cleanup_qfull);
1787 bfa_stats(ioim->itnim, qwait);
1788 bfa_reqq_wait(ioim->bfa, ioim->reqq,
1789 &ioim->iosp->reqq_wait);
1791 break;
1793 case BFA_IOIM_SM_HWFAIL:
1794 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1795 bfa_ioim_move_to_comp_q(ioim);
1796 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_failed,
1797 ioim);
1798 break;
1800 default:
1801 bfa_sm_fault(ioim->bfa, event);
1806 * IO is being cleaned up (implicit abort), waiting for completion from
1807 * firmware.
1809 static void
1810 bfa_ioim_sm_cleanup(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1812 bfa_trc(ioim->bfa, ioim->iotag);
1813 bfa_trc(ioim->bfa, event);
1815 switch (event) {
1816 case BFA_IOIM_SM_COMP_GOOD:
1817 case BFA_IOIM_SM_COMP:
1818 case BFA_IOIM_SM_DONE:
1819 case BFA_IOIM_SM_FREE:
1820 break;
1822 case BFA_IOIM_SM_ABORT:
1824 * IO is already being aborted implicitly
1826 ioim->io_cbfn = __bfa_cb_ioim_abort;
1827 break;
1829 case BFA_IOIM_SM_ABORT_DONE:
1830 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb_free);
1831 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, ioim->io_cbfn, ioim);
1832 bfa_ioim_notify_cleanup(ioim);
1833 break;
1835 case BFA_IOIM_SM_ABORT_COMP:
1836 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1837 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, ioim->io_cbfn, ioim);
1838 bfa_ioim_notify_cleanup(ioim);
1839 break;
1841 case BFA_IOIM_SM_COMP_UTAG:
1842 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1843 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, ioim->io_cbfn, ioim);
1844 bfa_ioim_notify_cleanup(ioim);
1845 break;
1847 case BFA_IOIM_SM_HWFAIL:
1848 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1849 bfa_ioim_move_to_comp_q(ioim);
1850 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_failed,
1851 ioim);
1852 break;
1854 case BFA_IOIM_SM_CLEANUP:
1856 * IO can be in cleanup state already due to TM command.
1857 * 2nd cleanup request comes from ITN offline event.
1859 break;
1861 default:
1862 bfa_sm_fault(ioim->bfa, event);
1867 * IO is waiting for room in request CQ
1869 static void
1870 bfa_ioim_sm_qfull(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1872 bfa_trc(ioim->bfa, ioim->iotag);
1873 bfa_trc(ioim->bfa, event);
1875 switch (event) {
1876 case BFA_IOIM_SM_QRESUME:
1877 bfa_sm_set_state(ioim, bfa_ioim_sm_active);
1878 bfa_ioim_send_ioreq(ioim);
1879 break;
1881 case BFA_IOIM_SM_ABORT:
1882 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1883 bfa_reqq_wcancel(&ioim->iosp->reqq_wait);
1884 bfa_ioim_move_to_comp_q(ioim);
1885 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_abort,
1886 ioim);
1887 break;
1889 case BFA_IOIM_SM_CLEANUP:
1890 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1891 bfa_reqq_wcancel(&ioim->iosp->reqq_wait);
1892 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_failed,
1893 ioim);
1894 bfa_ioim_notify_cleanup(ioim);
1895 break;
1897 case BFA_IOIM_SM_HWFAIL:
1898 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1899 bfa_reqq_wcancel(&ioim->iosp->reqq_wait);
1900 bfa_ioim_move_to_comp_q(ioim);
1901 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_failed,
1902 ioim);
1903 break;
1905 default:
1906 bfa_sm_fault(ioim->bfa, event);
1911 * Active IO is being aborted, waiting for room in request CQ.
1913 static void
1914 bfa_ioim_sm_abort_qfull(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1916 bfa_trc(ioim->bfa, ioim->iotag);
1917 bfa_trc(ioim->bfa, event);
1919 switch (event) {
1920 case BFA_IOIM_SM_QRESUME:
1921 bfa_sm_set_state(ioim, bfa_ioim_sm_abort);
1922 bfa_ioim_send_abort(ioim);
1923 break;
1925 case BFA_IOIM_SM_CLEANUP:
1926 WARN_ON(ioim->iosp->abort_explicit != BFA_TRUE);
1927 ioim->iosp->abort_explicit = BFA_FALSE;
1928 bfa_sm_set_state(ioim, bfa_ioim_sm_cleanup_qfull);
1929 break;
1931 case BFA_IOIM_SM_COMP_GOOD:
1932 case BFA_IOIM_SM_COMP:
1933 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1934 bfa_reqq_wcancel(&ioim->iosp->reqq_wait);
1935 bfa_ioim_move_to_comp_q(ioim);
1936 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_abort,
1937 ioim);
1938 break;
1940 case BFA_IOIM_SM_DONE:
1941 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb_free);
1942 bfa_reqq_wcancel(&ioim->iosp->reqq_wait);
1943 bfa_ioim_move_to_comp_q(ioim);
1944 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_abort,
1945 ioim);
1946 break;
1948 case BFA_IOIM_SM_HWFAIL:
1949 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1950 bfa_reqq_wcancel(&ioim->iosp->reqq_wait);
1951 bfa_ioim_move_to_comp_q(ioim);
1952 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_failed,
1953 ioim);
1954 break;
1956 default:
1957 bfa_sm_fault(ioim->bfa, event);
1962 * Active IO is being cleaned up, waiting for room in request CQ.
1964 static void
1965 bfa_ioim_sm_cleanup_qfull(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1967 bfa_trc(ioim->bfa, ioim->iotag);
1968 bfa_trc(ioim->bfa, event);
1970 switch (event) {
1971 case BFA_IOIM_SM_QRESUME:
1972 bfa_sm_set_state(ioim, bfa_ioim_sm_cleanup);
1973 bfa_ioim_send_abort(ioim);
1974 break;
1976 case BFA_IOIM_SM_ABORT:
1978 * IO is already being cleaned up implicitly
1980 ioim->io_cbfn = __bfa_cb_ioim_abort;
1981 break;
1983 case BFA_IOIM_SM_COMP_GOOD:
1984 case BFA_IOIM_SM_COMP:
1985 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1986 bfa_reqq_wcancel(&ioim->iosp->reqq_wait);
1987 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, ioim->io_cbfn, ioim);
1988 bfa_ioim_notify_cleanup(ioim);
1989 break;
1991 case BFA_IOIM_SM_DONE:
1992 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb_free);
1993 bfa_reqq_wcancel(&ioim->iosp->reqq_wait);
1994 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, ioim->io_cbfn, ioim);
1995 bfa_ioim_notify_cleanup(ioim);
1996 break;
1998 case BFA_IOIM_SM_HWFAIL:
1999 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
2000 bfa_reqq_wcancel(&ioim->iosp->reqq_wait);
2001 bfa_ioim_move_to_comp_q(ioim);
2002 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_failed,
2003 ioim);
2004 break;
2006 default:
2007 bfa_sm_fault(ioim->bfa, event);
2012 * IO bfa callback is pending.
2014 static void
2015 bfa_ioim_sm_hcb(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
2017 switch (event) {
2018 case BFA_IOIM_SM_HCB:
2019 bfa_sm_set_state(ioim, bfa_ioim_sm_uninit);
2020 bfa_ioim_free(ioim);
2021 break;
2023 case BFA_IOIM_SM_CLEANUP:
2024 bfa_ioim_notify_cleanup(ioim);
2025 break;
2027 case BFA_IOIM_SM_HWFAIL:
2028 break;
2030 default:
2031 bfa_sm_fault(ioim->bfa, event);
2036 * IO bfa callback is pending. IO resource cannot be freed.
2038 static void
2039 bfa_ioim_sm_hcb_free(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
2041 bfa_trc(ioim->bfa, ioim->iotag);
2042 bfa_trc(ioim->bfa, event);
2044 switch (event) {
2045 case BFA_IOIM_SM_HCB:
2046 bfa_sm_set_state(ioim, bfa_ioim_sm_resfree);
2047 list_del(&ioim->qe);
2048 list_add_tail(&ioim->qe, &ioim->fcpim->ioim_resfree_q);
2049 break;
2051 case BFA_IOIM_SM_FREE:
2052 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
2053 break;
2055 case BFA_IOIM_SM_CLEANUP:
2056 bfa_ioim_notify_cleanup(ioim);
2057 break;
2059 case BFA_IOIM_SM_HWFAIL:
2060 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
2061 break;
2063 default:
2064 bfa_sm_fault(ioim->bfa, event);
2069 * IO is completed, waiting resource free from firmware.
2071 static void
2072 bfa_ioim_sm_resfree(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
2074 bfa_trc(ioim->bfa, ioim->iotag);
2075 bfa_trc(ioim->bfa, event);
2077 switch (event) {
2078 case BFA_IOIM_SM_FREE:
2079 bfa_sm_set_state(ioim, bfa_ioim_sm_uninit);
2080 bfa_ioim_free(ioim);
2081 break;
2083 case BFA_IOIM_SM_CLEANUP:
2084 bfa_ioim_notify_cleanup(ioim);
2085 break;
2087 case BFA_IOIM_SM_HWFAIL:
2088 break;
2090 default:
2091 bfa_sm_fault(ioim->bfa, event);
2096 * This is called from bfa_fcpim_start after the bfa_init() with flash read
2097 * is complete by driver. now invalidate the stale content of lun mask
2098 * like unit attention, rp tag and lp tag.
2100 void
2101 bfa_ioim_lm_init(struct bfa_s *bfa)
2103 struct bfa_lun_mask_s *lunm_list;
2104 int i;
2106 if (bfa_get_lun_mask_status(bfa) == BFA_LUNMASK_MINCFG)
2107 return;
2109 lunm_list = bfa_get_lun_mask_list(bfa);
2110 for (i = 0; i < MAX_LUN_MASK_CFG; i++) {
2111 lunm_list[i].ua = BFA_IOIM_LM_UA_RESET;
2112 lunm_list[i].lp_tag = BFA_LP_TAG_INVALID;
2113 lunm_list[i].rp_tag = BFA_RPORT_TAG_INVALID;
2117 static void
2118 __bfa_cb_ioim_good_comp(void *cbarg, bfa_boolean_t complete)
2120 struct bfa_ioim_s *ioim = cbarg;
2122 if (!complete) {
2123 bfa_sm_send_event(ioim, BFA_IOIM_SM_HCB);
2124 return;
2127 bfa_cb_ioim_good_comp(ioim->bfa->bfad, ioim->dio);
2130 static void
2131 __bfa_cb_ioim_comp(void *cbarg, bfa_boolean_t complete)
2133 struct bfa_ioim_s *ioim = cbarg;
2134 struct bfi_ioim_rsp_s *m;
2135 u8 *snsinfo = NULL;
2136 u8 sns_len = 0;
2137 s32 residue = 0;
2139 if (!complete) {
2140 bfa_sm_send_event(ioim, BFA_IOIM_SM_HCB);
2141 return;
2144 m = (struct bfi_ioim_rsp_s *) &ioim->iosp->comp_rspmsg;
2145 if (m->io_status == BFI_IOIM_STS_OK) {
2147 * setup sense information, if present
2149 if ((m->scsi_status == SCSI_STATUS_CHECK_CONDITION) &&
2150 m->sns_len) {
2151 sns_len = m->sns_len;
2152 snsinfo = BFA_SNSINFO_FROM_TAG(ioim->fcpim->fcp,
2153 ioim->iotag);
2157 * setup residue value correctly for normal completions
2159 if (m->resid_flags == FCP_RESID_UNDER) {
2160 residue = be32_to_cpu(m->residue);
2161 bfa_stats(ioim->itnim, iocomp_underrun);
2163 if (m->resid_flags == FCP_RESID_OVER) {
2164 residue = be32_to_cpu(m->residue);
2165 residue = -residue;
2166 bfa_stats(ioim->itnim, iocomp_overrun);
2170 bfa_cb_ioim_done(ioim->bfa->bfad, ioim->dio, m->io_status,
2171 m->scsi_status, sns_len, snsinfo, residue);
2174 void
2175 bfa_fcpim_lunmask_rp_update(struct bfa_s *bfa, wwn_t lp_wwn, wwn_t rp_wwn,
2176 u16 rp_tag, u8 lp_tag)
2178 struct bfa_lun_mask_s *lun_list;
2179 u8 i;
2181 if (bfa_get_lun_mask_status(bfa) == BFA_LUNMASK_MINCFG)
2182 return;
2184 lun_list = bfa_get_lun_mask_list(bfa);
2185 for (i = 0; i < MAX_LUN_MASK_CFG; i++) {
2186 if (lun_list[i].state == BFA_IOIM_LUN_MASK_ACTIVE) {
2187 if ((lun_list[i].lp_wwn == lp_wwn) &&
2188 (lun_list[i].rp_wwn == rp_wwn)) {
2189 lun_list[i].rp_tag = rp_tag;
2190 lun_list[i].lp_tag = lp_tag;
2197 * set UA for all active luns in LM DB
2199 static void
2200 bfa_ioim_lm_set_ua(struct bfa_s *bfa)
2202 struct bfa_lun_mask_s *lunm_list;
2203 int i;
2205 lunm_list = bfa_get_lun_mask_list(bfa);
2206 for (i = 0; i < MAX_LUN_MASK_CFG; i++) {
2207 if (lunm_list[i].state != BFA_IOIM_LUN_MASK_ACTIVE)
2208 continue;
2209 lunm_list[i].ua = BFA_IOIM_LM_UA_SET;
2213 bfa_status_t
2214 bfa_fcpim_lunmask_update(struct bfa_s *bfa, u32 update)
2216 struct bfa_lunmask_cfg_s *lun_mask;
2218 bfa_trc(bfa, bfa_get_lun_mask_status(bfa));
2219 if (bfa_get_lun_mask_status(bfa) == BFA_LUNMASK_MINCFG)
2220 return BFA_STATUS_FAILED;
2222 if (bfa_get_lun_mask_status(bfa) == update)
2223 return BFA_STATUS_NO_CHANGE;
2225 lun_mask = bfa_get_lun_mask(bfa);
2226 lun_mask->status = update;
2228 if (bfa_get_lun_mask_status(bfa) == BFA_LUNMASK_ENABLED)
2229 bfa_ioim_lm_set_ua(bfa);
2231 return bfa_dconf_update(bfa);
2234 bfa_status_t
2235 bfa_fcpim_lunmask_clear(struct bfa_s *bfa)
2237 int i;
2238 struct bfa_lun_mask_s *lunm_list;
2240 bfa_trc(bfa, bfa_get_lun_mask_status(bfa));
2241 if (bfa_get_lun_mask_status(bfa) == BFA_LUNMASK_MINCFG)
2242 return BFA_STATUS_FAILED;
2244 lunm_list = bfa_get_lun_mask_list(bfa);
2245 for (i = 0; i < MAX_LUN_MASK_CFG; i++) {
2246 if (lunm_list[i].state == BFA_IOIM_LUN_MASK_ACTIVE) {
2247 if (lunm_list[i].rp_tag != BFA_RPORT_TAG_INVALID)
2248 bfa_rport_unset_lunmask(bfa,
2249 BFA_RPORT_FROM_TAG(bfa, lunm_list[i].rp_tag));
2253 memset(lunm_list, 0, sizeof(struct bfa_lun_mask_s) * MAX_LUN_MASK_CFG);
2254 return bfa_dconf_update(bfa);
2257 bfa_status_t
2258 bfa_fcpim_lunmask_query(struct bfa_s *bfa, void *buf)
2260 struct bfa_lunmask_cfg_s *lun_mask;
2262 bfa_trc(bfa, bfa_get_lun_mask_status(bfa));
2263 if (bfa_get_lun_mask_status(bfa) == BFA_LUNMASK_MINCFG)
2264 return BFA_STATUS_FAILED;
2266 lun_mask = bfa_get_lun_mask(bfa);
2267 memcpy(buf, lun_mask, sizeof(struct bfa_lunmask_cfg_s));
2268 return BFA_STATUS_OK;
2271 bfa_status_t
2272 bfa_fcpim_lunmask_add(struct bfa_s *bfa, u16 vf_id, wwn_t *pwwn,
2273 wwn_t rpwwn, struct scsi_lun lun)
2275 struct bfa_lun_mask_s *lunm_list;
2276 struct bfa_rport_s *rp = NULL;
2277 int i, free_index = MAX_LUN_MASK_CFG + 1;
2278 struct bfa_fcs_lport_s *port = NULL;
2279 struct bfa_fcs_rport_s *rp_fcs;
2281 bfa_trc(bfa, bfa_get_lun_mask_status(bfa));
2282 if (bfa_get_lun_mask_status(bfa) == BFA_LUNMASK_MINCFG)
2283 return BFA_STATUS_FAILED;
2285 port = bfa_fcs_lookup_port(&((struct bfad_s *)bfa->bfad)->bfa_fcs,
2286 vf_id, *pwwn);
2287 if (port) {
2288 *pwwn = port->port_cfg.pwwn;
2289 rp_fcs = bfa_fcs_lport_get_rport_by_pwwn(port, rpwwn);
2290 if (rp_fcs)
2291 rp = rp_fcs->bfa_rport;
2294 lunm_list = bfa_get_lun_mask_list(bfa);
2295 /* if entry exists */
2296 for (i = 0; i < MAX_LUN_MASK_CFG; i++) {
2297 if (lunm_list[i].state != BFA_IOIM_LUN_MASK_ACTIVE)
2298 free_index = i;
2299 if ((lunm_list[i].lp_wwn == *pwwn) &&
2300 (lunm_list[i].rp_wwn == rpwwn) &&
2301 (scsilun_to_int((struct scsi_lun *)&lunm_list[i].lun) ==
2302 scsilun_to_int((struct scsi_lun *)&lun)))
2303 return BFA_STATUS_ENTRY_EXISTS;
2306 if (free_index > MAX_LUN_MASK_CFG)
2307 return BFA_STATUS_MAX_ENTRY_REACHED;
2309 if (rp) {
2310 lunm_list[free_index].lp_tag = bfa_lps_get_tag_from_pid(bfa,
2311 rp->rport_info.local_pid);
2312 lunm_list[free_index].rp_tag = rp->rport_tag;
2313 } else {
2314 lunm_list[free_index].lp_tag = BFA_LP_TAG_INVALID;
2315 lunm_list[free_index].rp_tag = BFA_RPORT_TAG_INVALID;
2318 lunm_list[free_index].lp_wwn = *pwwn;
2319 lunm_list[free_index].rp_wwn = rpwwn;
2320 lunm_list[free_index].lun = lun;
2321 lunm_list[free_index].state = BFA_IOIM_LUN_MASK_ACTIVE;
2323 /* set for all luns in this rp */
2324 for (i = 0; i < MAX_LUN_MASK_CFG; i++) {
2325 if ((lunm_list[i].lp_wwn == *pwwn) &&
2326 (lunm_list[i].rp_wwn == rpwwn))
2327 lunm_list[i].ua = BFA_IOIM_LM_UA_SET;
2330 return bfa_dconf_update(bfa);
2333 bfa_status_t
2334 bfa_fcpim_lunmask_delete(struct bfa_s *bfa, u16 vf_id, wwn_t *pwwn,
2335 wwn_t rpwwn, struct scsi_lun lun)
2337 struct bfa_lun_mask_s *lunm_list;
2338 struct bfa_fcs_lport_s *port = NULL;
2339 int i;
2341 /* in min cfg lunm_list could be NULL but no commands should run. */
2342 if (bfa_get_lun_mask_status(bfa) == BFA_LUNMASK_MINCFG)
2343 return BFA_STATUS_FAILED;
2345 bfa_trc(bfa, bfa_get_lun_mask_status(bfa));
2346 bfa_trc(bfa, *pwwn);
2347 bfa_trc(bfa, rpwwn);
2348 bfa_trc(bfa, scsilun_to_int((struct scsi_lun *)&lun));
2350 if (*pwwn == 0) {
2351 port = bfa_fcs_lookup_port(
2352 &((struct bfad_s *)bfa->bfad)->bfa_fcs,
2353 vf_id, *pwwn);
2354 if (port)
2355 *pwwn = port->port_cfg.pwwn;
2358 lunm_list = bfa_get_lun_mask_list(bfa);
2359 for (i = 0; i < MAX_LUN_MASK_CFG; i++) {
2360 if ((lunm_list[i].lp_wwn == *pwwn) &&
2361 (lunm_list[i].rp_wwn == rpwwn) &&
2362 (scsilun_to_int((struct scsi_lun *)&lunm_list[i].lun) ==
2363 scsilun_to_int((struct scsi_lun *)&lun))) {
2364 lunm_list[i].lp_wwn = 0;
2365 lunm_list[i].rp_wwn = 0;
2366 int_to_scsilun(0, &lunm_list[i].lun);
2367 lunm_list[i].state = BFA_IOIM_LUN_MASK_INACTIVE;
2368 if (lunm_list[i].rp_tag != BFA_RPORT_TAG_INVALID) {
2369 lunm_list[i].rp_tag = BFA_RPORT_TAG_INVALID;
2370 lunm_list[i].lp_tag = BFA_LP_TAG_INVALID;
2372 return bfa_dconf_update(bfa);
2376 /* set for all luns in this rp */
2377 for (i = 0; i < MAX_LUN_MASK_CFG; i++) {
2378 if ((lunm_list[i].lp_wwn == *pwwn) &&
2379 (lunm_list[i].rp_wwn == rpwwn))
2380 lunm_list[i].ua = BFA_IOIM_LM_UA_SET;
2383 return BFA_STATUS_ENTRY_NOT_EXISTS;
2386 static void
2387 __bfa_cb_ioim_failed(void *cbarg, bfa_boolean_t complete)
2389 struct bfa_ioim_s *ioim = cbarg;
2391 if (!complete) {
2392 bfa_sm_send_event(ioim, BFA_IOIM_SM_HCB);
2393 return;
2396 bfa_cb_ioim_done(ioim->bfa->bfad, ioim->dio, BFI_IOIM_STS_ABORTED,
2397 0, 0, NULL, 0);
2400 static void
2401 __bfa_cb_ioim_pathtov(void *cbarg, bfa_boolean_t complete)
2403 struct bfa_ioim_s *ioim = cbarg;
2405 bfa_stats(ioim->itnim, path_tov_expired);
2406 if (!complete) {
2407 bfa_sm_send_event(ioim, BFA_IOIM_SM_HCB);
2408 return;
2411 bfa_cb_ioim_done(ioim->bfa->bfad, ioim->dio, BFI_IOIM_STS_PATHTOV,
2412 0, 0, NULL, 0);
2415 static void
2416 __bfa_cb_ioim_abort(void *cbarg, bfa_boolean_t complete)
2418 struct bfa_ioim_s *ioim = cbarg;
2420 if (!complete) {
2421 bfa_sm_send_event(ioim, BFA_IOIM_SM_HCB);
2422 return;
2425 bfa_cb_ioim_abort(ioim->bfa->bfad, ioim->dio);
2428 static void
2429 bfa_ioim_sgpg_alloced(void *cbarg)
2431 struct bfa_ioim_s *ioim = cbarg;
2433 ioim->nsgpgs = BFA_SGPG_NPAGE(ioim->nsges);
2434 list_splice_tail_init(&ioim->iosp->sgpg_wqe.sgpg_q, &ioim->sgpg_q);
2435 ioim->sgpg = bfa_q_first(&ioim->sgpg_q);
2436 bfa_sm_send_event(ioim, BFA_IOIM_SM_SGALLOCED);
2440 * Send I/O request to firmware.
2442 static bfa_boolean_t
2443 bfa_ioim_send_ioreq(struct bfa_ioim_s *ioim)
2445 struct bfa_itnim_s *itnim = ioim->itnim;
2446 struct bfi_ioim_req_s *m;
2447 static struct fcp_cmnd_s cmnd_z0 = { { { 0 } } };
2448 struct bfi_sge_s *sge, *sgpge;
2449 u32 pgdlen = 0;
2450 u32 fcp_dl;
2451 u64 addr;
2452 struct scatterlist *sg;
2453 struct bfa_sgpg_s *sgpg;
2454 struct scsi_cmnd *cmnd = (struct scsi_cmnd *) ioim->dio;
2455 u32 i, sge_id, pgcumsz;
2456 enum dma_data_direction dmadir;
2459 * check for room in queue to send request now
2461 m = bfa_reqq_next(ioim->bfa, ioim->reqq);
2462 if (!m) {
2463 bfa_stats(ioim->itnim, qwait);
2464 bfa_reqq_wait(ioim->bfa, ioim->reqq,
2465 &ioim->iosp->reqq_wait);
2466 return BFA_FALSE;
2470 * build i/o request message next
2472 m->io_tag = cpu_to_be16(ioim->iotag);
2473 m->rport_hdl = ioim->itnim->rport->fw_handle;
2474 m->io_timeout = 0;
2476 sge = &m->sges[0];
2477 sgpg = ioim->sgpg;
2478 sge_id = 0;
2479 sgpge = NULL;
2480 pgcumsz = 0;
2481 scsi_for_each_sg(cmnd, sg, ioim->nsges, i) {
2482 if (i == 0) {
2483 /* build inline IO SG element */
2484 addr = bfa_sgaddr_le(sg_dma_address(sg));
2485 sge->sga = *(union bfi_addr_u *) &addr;
2486 pgdlen = sg_dma_len(sg);
2487 sge->sg_len = pgdlen;
2488 sge->flags = (ioim->nsges > BFI_SGE_INLINE) ?
2489 BFI_SGE_DATA_CPL : BFI_SGE_DATA_LAST;
2490 bfa_sge_to_be(sge);
2491 sge++;
2492 } else {
2493 if (sge_id == 0)
2494 sgpge = sgpg->sgpg->sges;
2496 addr = bfa_sgaddr_le(sg_dma_address(sg));
2497 sgpge->sga = *(union bfi_addr_u *) &addr;
2498 sgpge->sg_len = sg_dma_len(sg);
2499 pgcumsz += sgpge->sg_len;
2501 /* set flags */
2502 if (i < (ioim->nsges - 1) &&
2503 sge_id < (BFI_SGPG_DATA_SGES - 1))
2504 sgpge->flags = BFI_SGE_DATA;
2505 else if (i < (ioim->nsges - 1))
2506 sgpge->flags = BFI_SGE_DATA_CPL;
2507 else
2508 sgpge->flags = BFI_SGE_DATA_LAST;
2510 bfa_sge_to_le(sgpge);
2512 sgpge++;
2513 if (i == (ioim->nsges - 1)) {
2514 sgpge->flags = BFI_SGE_PGDLEN;
2515 sgpge->sga.a32.addr_lo = 0;
2516 sgpge->sga.a32.addr_hi = 0;
2517 sgpge->sg_len = pgcumsz;
2518 bfa_sge_to_le(sgpge);
2519 } else if (++sge_id == BFI_SGPG_DATA_SGES) {
2520 sgpg = (struct bfa_sgpg_s *) bfa_q_next(sgpg);
2521 sgpge->flags = BFI_SGE_LINK;
2522 sgpge->sga = sgpg->sgpg_pa;
2523 sgpge->sg_len = pgcumsz;
2524 bfa_sge_to_le(sgpge);
2525 sge_id = 0;
2526 pgcumsz = 0;
2531 if (ioim->nsges > BFI_SGE_INLINE) {
2532 sge->sga = ioim->sgpg->sgpg_pa;
2533 } else {
2534 sge->sga.a32.addr_lo = 0;
2535 sge->sga.a32.addr_hi = 0;
2537 sge->sg_len = pgdlen;
2538 sge->flags = BFI_SGE_PGDLEN;
2539 bfa_sge_to_be(sge);
2542 * set up I/O command parameters
2544 m->cmnd = cmnd_z0;
2545 int_to_scsilun(cmnd->device->lun, &m->cmnd.lun);
2546 dmadir = cmnd->sc_data_direction;
2547 if (dmadir == DMA_TO_DEVICE)
2548 m->cmnd.iodir = FCP_IODIR_WRITE;
2549 else if (dmadir == DMA_FROM_DEVICE)
2550 m->cmnd.iodir = FCP_IODIR_READ;
2551 else
2552 m->cmnd.iodir = FCP_IODIR_NONE;
2554 m->cmnd.cdb = *(struct scsi_cdb_s *) cmnd->cmnd;
2555 fcp_dl = scsi_bufflen(cmnd);
2556 m->cmnd.fcp_dl = cpu_to_be32(fcp_dl);
2559 * set up I/O message header
2561 switch (m->cmnd.iodir) {
2562 case FCP_IODIR_READ:
2563 bfi_h2i_set(m->mh, BFI_MC_IOIM_READ, 0, bfa_fn_lpu(ioim->bfa));
2564 bfa_stats(itnim, input_reqs);
2565 ioim->itnim->stats.rd_throughput += fcp_dl;
2566 break;
2567 case FCP_IODIR_WRITE:
2568 bfi_h2i_set(m->mh, BFI_MC_IOIM_WRITE, 0, bfa_fn_lpu(ioim->bfa));
2569 bfa_stats(itnim, output_reqs);
2570 ioim->itnim->stats.wr_throughput += fcp_dl;
2571 break;
2572 case FCP_IODIR_RW:
2573 bfa_stats(itnim, input_reqs);
2574 bfa_stats(itnim, output_reqs);
2575 fallthrough;
2576 default:
2577 bfi_h2i_set(m->mh, BFI_MC_IOIM_IO, 0, bfa_fn_lpu(ioim->bfa));
2579 if (itnim->seq_rec ||
2580 (scsi_bufflen(cmnd) & (sizeof(u32) - 1)))
2581 bfi_h2i_set(m->mh, BFI_MC_IOIM_IO, 0, bfa_fn_lpu(ioim->bfa));
2584 * queue I/O message to firmware
2586 bfa_reqq_produce(ioim->bfa, ioim->reqq, m->mh);
2587 return BFA_TRUE;
2591 * Setup any additional SG pages needed.Inline SG element is setup
2592 * at queuing time.
2594 static bfa_boolean_t
2595 bfa_ioim_sgpg_alloc(struct bfa_ioim_s *ioim)
2597 u16 nsgpgs;
2599 WARN_ON(ioim->nsges <= BFI_SGE_INLINE);
2602 * allocate SG pages needed
2604 nsgpgs = BFA_SGPG_NPAGE(ioim->nsges);
2605 if (!nsgpgs)
2606 return BFA_TRUE;
2608 if (bfa_sgpg_malloc(ioim->bfa, &ioim->sgpg_q, nsgpgs)
2609 != BFA_STATUS_OK) {
2610 bfa_sgpg_wait(ioim->bfa, &ioim->iosp->sgpg_wqe, nsgpgs);
2611 return BFA_FALSE;
2614 ioim->nsgpgs = nsgpgs;
2615 ioim->sgpg = bfa_q_first(&ioim->sgpg_q);
2617 return BFA_TRUE;
2621 * Send I/O abort request to firmware.
2623 static bfa_boolean_t
2624 bfa_ioim_send_abort(struct bfa_ioim_s *ioim)
2626 struct bfi_ioim_abort_req_s *m;
2627 enum bfi_ioim_h2i msgop;
2630 * check for room in queue to send request now
2632 m = bfa_reqq_next(ioim->bfa, ioim->reqq);
2633 if (!m)
2634 return BFA_FALSE;
2637 * build i/o request message next
2639 if (ioim->iosp->abort_explicit)
2640 msgop = BFI_IOIM_H2I_IOABORT_REQ;
2641 else
2642 msgop = BFI_IOIM_H2I_IOCLEANUP_REQ;
2644 bfi_h2i_set(m->mh, BFI_MC_IOIM, msgop, bfa_fn_lpu(ioim->bfa));
2645 m->io_tag = cpu_to_be16(ioim->iotag);
2646 m->abort_tag = ++ioim->abort_tag;
2649 * queue I/O message to firmware
2651 bfa_reqq_produce(ioim->bfa, ioim->reqq, m->mh);
2652 return BFA_TRUE;
2656 * Call to resume any I/O requests waiting for room in request queue.
2658 static void
2659 bfa_ioim_qresume(void *cbarg)
2661 struct bfa_ioim_s *ioim = cbarg;
2663 bfa_stats(ioim->itnim, qresumes);
2664 bfa_sm_send_event(ioim, BFA_IOIM_SM_QRESUME);
2668 static void
2669 bfa_ioim_notify_cleanup(struct bfa_ioim_s *ioim)
2672 * Move IO from itnim queue to fcpim global queue since itnim will be
2673 * freed.
2675 list_del(&ioim->qe);
2676 list_add_tail(&ioim->qe, &ioim->fcpim->ioim_comp_q);
2678 if (!ioim->iosp->tskim) {
2679 if (ioim->fcpim->delay_comp && ioim->itnim->iotov_active) {
2680 bfa_cb_dequeue(&ioim->hcb_qe);
2681 list_del(&ioim->qe);
2682 list_add_tail(&ioim->qe, &ioim->itnim->delay_comp_q);
2684 bfa_itnim_iodone(ioim->itnim);
2685 } else
2686 bfa_wc_down(&ioim->iosp->tskim->wc);
2689 static bfa_boolean_t
2690 bfa_ioim_is_abortable(struct bfa_ioim_s *ioim)
2692 if ((bfa_sm_cmp_state(ioim, bfa_ioim_sm_uninit) &&
2693 (!bfa_q_is_on_q(&ioim->itnim->pending_q, ioim))) ||
2694 (bfa_sm_cmp_state(ioim, bfa_ioim_sm_abort)) ||
2695 (bfa_sm_cmp_state(ioim, bfa_ioim_sm_abort_qfull)) ||
2696 (bfa_sm_cmp_state(ioim, bfa_ioim_sm_hcb)) ||
2697 (bfa_sm_cmp_state(ioim, bfa_ioim_sm_hcb_free)) ||
2698 (bfa_sm_cmp_state(ioim, bfa_ioim_sm_resfree)))
2699 return BFA_FALSE;
2701 return BFA_TRUE;
2704 void
2705 bfa_ioim_delayed_comp(struct bfa_ioim_s *ioim, bfa_boolean_t iotov)
2708 * If path tov timer expired, failback with PATHTOV status - these
2709 * IO requests are not normally retried by IO stack.
2711 * Otherwise device cameback online and fail it with normal failed
2712 * status so that IO stack retries these failed IO requests.
2714 if (iotov)
2715 ioim->io_cbfn = __bfa_cb_ioim_pathtov;
2716 else {
2717 ioim->io_cbfn = __bfa_cb_ioim_failed;
2718 bfa_stats(ioim->itnim, iocom_nexus_abort);
2720 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, ioim->io_cbfn, ioim);
2723 * Move IO to fcpim global queue since itnim will be
2724 * freed.
2726 list_del(&ioim->qe);
2727 list_add_tail(&ioim->qe, &ioim->fcpim->ioim_comp_q);
2732 * Memory allocation and initialization.
2734 void
2735 bfa_ioim_attach(struct bfa_fcpim_s *fcpim)
2737 struct bfa_ioim_s *ioim;
2738 struct bfa_fcp_mod_s *fcp = fcpim->fcp;
2739 struct bfa_ioim_sp_s *iosp;
2740 u16 i;
2743 * claim memory first
2745 ioim = (struct bfa_ioim_s *) bfa_mem_kva_curp(fcp);
2746 fcpim->ioim_arr = ioim;
2747 bfa_mem_kva_curp(fcp) = (u8 *) (ioim + fcpim->fcp->num_ioim_reqs);
2749 iosp = (struct bfa_ioim_sp_s *) bfa_mem_kva_curp(fcp);
2750 fcpim->ioim_sp_arr = iosp;
2751 bfa_mem_kva_curp(fcp) = (u8 *) (iosp + fcpim->fcp->num_ioim_reqs);
2754 * Initialize ioim free queues
2756 INIT_LIST_HEAD(&fcpim->ioim_resfree_q);
2757 INIT_LIST_HEAD(&fcpim->ioim_comp_q);
2759 for (i = 0; i < fcpim->fcp->num_ioim_reqs;
2760 i++, ioim++, iosp++) {
2762 * initialize IOIM
2764 memset(ioim, 0, sizeof(struct bfa_ioim_s));
2765 ioim->iotag = i;
2766 ioim->bfa = fcpim->bfa;
2767 ioim->fcpim = fcpim;
2768 ioim->iosp = iosp;
2769 INIT_LIST_HEAD(&ioim->sgpg_q);
2770 bfa_reqq_winit(&ioim->iosp->reqq_wait,
2771 bfa_ioim_qresume, ioim);
2772 bfa_sgpg_winit(&ioim->iosp->sgpg_wqe,
2773 bfa_ioim_sgpg_alloced, ioim);
2774 bfa_sm_set_state(ioim, bfa_ioim_sm_uninit);
2778 void
2779 bfa_ioim_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
2781 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
2782 struct bfi_ioim_rsp_s *rsp = (struct bfi_ioim_rsp_s *) m;
2783 struct bfa_ioim_s *ioim;
2784 u16 iotag;
2785 enum bfa_ioim_event evt = BFA_IOIM_SM_COMP;
2787 iotag = be16_to_cpu(rsp->io_tag);
2789 ioim = BFA_IOIM_FROM_TAG(fcpim, iotag);
2790 WARN_ON(ioim->iotag != iotag);
2792 bfa_trc(ioim->bfa, ioim->iotag);
2793 bfa_trc(ioim->bfa, rsp->io_status);
2794 bfa_trc(ioim->bfa, rsp->reuse_io_tag);
2796 if (bfa_sm_cmp_state(ioim, bfa_ioim_sm_active))
2797 ioim->iosp->comp_rspmsg = *m;
2799 switch (rsp->io_status) {
2800 case BFI_IOIM_STS_OK:
2801 bfa_stats(ioim->itnim, iocomp_ok);
2802 if (rsp->reuse_io_tag == 0)
2803 evt = BFA_IOIM_SM_DONE;
2804 else
2805 evt = BFA_IOIM_SM_COMP;
2806 break;
2808 case BFI_IOIM_STS_TIMEDOUT:
2809 bfa_stats(ioim->itnim, iocomp_timedout);
2810 fallthrough;
2811 case BFI_IOIM_STS_ABORTED:
2812 rsp->io_status = BFI_IOIM_STS_ABORTED;
2813 bfa_stats(ioim->itnim, iocomp_aborted);
2814 if (rsp->reuse_io_tag == 0)
2815 evt = BFA_IOIM_SM_DONE;
2816 else
2817 evt = BFA_IOIM_SM_COMP;
2818 break;
2820 case BFI_IOIM_STS_PROTO_ERR:
2821 bfa_stats(ioim->itnim, iocom_proto_err);
2822 WARN_ON(!rsp->reuse_io_tag);
2823 evt = BFA_IOIM_SM_COMP;
2824 break;
2826 case BFI_IOIM_STS_SQER_NEEDED:
2827 bfa_stats(ioim->itnim, iocom_sqer_needed);
2828 WARN_ON(rsp->reuse_io_tag != 0);
2829 evt = BFA_IOIM_SM_SQRETRY;
2830 break;
2832 case BFI_IOIM_STS_RES_FREE:
2833 bfa_stats(ioim->itnim, iocom_res_free);
2834 evt = BFA_IOIM_SM_FREE;
2835 break;
2837 case BFI_IOIM_STS_HOST_ABORTED:
2838 bfa_stats(ioim->itnim, iocom_hostabrts);
2839 if (rsp->abort_tag != ioim->abort_tag) {
2840 bfa_trc(ioim->bfa, rsp->abort_tag);
2841 bfa_trc(ioim->bfa, ioim->abort_tag);
2842 return;
2845 if (rsp->reuse_io_tag)
2846 evt = BFA_IOIM_SM_ABORT_COMP;
2847 else
2848 evt = BFA_IOIM_SM_ABORT_DONE;
2849 break;
2851 case BFI_IOIM_STS_UTAG:
2852 bfa_stats(ioim->itnim, iocom_utags);
2853 evt = BFA_IOIM_SM_COMP_UTAG;
2854 break;
2856 default:
2857 WARN_ON(1);
2860 bfa_sm_send_event(ioim, evt);
2863 void
2864 bfa_ioim_good_comp_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
2866 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
2867 struct bfi_ioim_rsp_s *rsp = (struct bfi_ioim_rsp_s *) m;
2868 struct bfa_ioim_s *ioim;
2869 u16 iotag;
2871 iotag = be16_to_cpu(rsp->io_tag);
2873 ioim = BFA_IOIM_FROM_TAG(fcpim, iotag);
2874 WARN_ON(ioim->iotag != iotag);
2876 bfa_ioim_cb_profile_comp(fcpim, ioim);
2878 bfa_sm_send_event(ioim, BFA_IOIM_SM_COMP_GOOD);
2882 * Called by itnim to clean up IO while going offline.
2884 void
2885 bfa_ioim_cleanup(struct bfa_ioim_s *ioim)
2887 bfa_trc(ioim->bfa, ioim->iotag);
2888 bfa_stats(ioim->itnim, io_cleanups);
2890 ioim->iosp->tskim = NULL;
2891 bfa_sm_send_event(ioim, BFA_IOIM_SM_CLEANUP);
2894 void
2895 bfa_ioim_cleanup_tm(struct bfa_ioim_s *ioim, struct bfa_tskim_s *tskim)
2897 bfa_trc(ioim->bfa, ioim->iotag);
2898 bfa_stats(ioim->itnim, io_tmaborts);
2900 ioim->iosp->tskim = tskim;
2901 bfa_sm_send_event(ioim, BFA_IOIM_SM_CLEANUP);
2905 * IOC failure handling.
2907 void
2908 bfa_ioim_iocdisable(struct bfa_ioim_s *ioim)
2910 bfa_trc(ioim->bfa, ioim->iotag);
2911 bfa_stats(ioim->itnim, io_iocdowns);
2912 bfa_sm_send_event(ioim, BFA_IOIM_SM_HWFAIL);
2916 * IO offline TOV popped. Fail the pending IO.
2918 void
2919 bfa_ioim_tov(struct bfa_ioim_s *ioim)
2921 bfa_trc(ioim->bfa, ioim->iotag);
2922 bfa_sm_send_event(ioim, BFA_IOIM_SM_IOTOV);
2927 * Allocate IOIM resource for initiator mode I/O request.
2929 struct bfa_ioim_s *
2930 bfa_ioim_alloc(struct bfa_s *bfa, struct bfad_ioim_s *dio,
2931 struct bfa_itnim_s *itnim, u16 nsges)
2933 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
2934 struct bfa_ioim_s *ioim;
2935 struct bfa_iotag_s *iotag = NULL;
2938 * alocate IOIM resource
2940 bfa_q_deq(&fcpim->fcp->iotag_ioim_free_q, &iotag);
2941 if (!iotag) {
2942 bfa_stats(itnim, no_iotags);
2943 return NULL;
2946 ioim = BFA_IOIM_FROM_TAG(fcpim, iotag->tag);
2948 ioim->dio = dio;
2949 ioim->itnim = itnim;
2950 ioim->nsges = nsges;
2951 ioim->nsgpgs = 0;
2953 bfa_stats(itnim, total_ios);
2954 fcpim->ios_active++;
2956 list_add_tail(&ioim->qe, &itnim->io_q);
2958 return ioim;
2961 void
2962 bfa_ioim_free(struct bfa_ioim_s *ioim)
2964 struct bfa_fcpim_s *fcpim = ioim->fcpim;
2965 struct bfa_iotag_s *iotag;
2967 if (ioim->nsgpgs > 0)
2968 bfa_sgpg_mfree(ioim->bfa, &ioim->sgpg_q, ioim->nsgpgs);
2970 bfa_stats(ioim->itnim, io_comps);
2971 fcpim->ios_active--;
2973 ioim->iotag &= BFA_IOIM_IOTAG_MASK;
2975 WARN_ON(!(ioim->iotag <
2976 (fcpim->fcp->num_ioim_reqs + fcpim->fcp->num_fwtio_reqs)));
2977 iotag = BFA_IOTAG_FROM_TAG(fcpim->fcp, ioim->iotag);
2979 if (ioim->iotag < fcpim->fcp->num_ioim_reqs)
2980 list_add_tail(&iotag->qe, &fcpim->fcp->iotag_ioim_free_q);
2981 else
2982 list_add_tail(&iotag->qe, &fcpim->fcp->iotag_tio_free_q);
2984 list_del(&ioim->qe);
2987 void
2988 bfa_ioim_start(struct bfa_ioim_s *ioim)
2990 bfa_ioim_cb_profile_start(ioim->fcpim, ioim);
2993 * Obtain the queue over which this request has to be issued
2995 ioim->reqq = bfa_fcpim_ioredirect_enabled(ioim->bfa) ?
2996 BFA_FALSE : bfa_itnim_get_reqq(ioim);
2998 bfa_sm_send_event(ioim, BFA_IOIM_SM_START);
3002 * Driver I/O abort request.
3004 bfa_status_t
3005 bfa_ioim_abort(struct bfa_ioim_s *ioim)
3008 bfa_trc(ioim->bfa, ioim->iotag);
3010 if (!bfa_ioim_is_abortable(ioim))
3011 return BFA_STATUS_FAILED;
3013 bfa_stats(ioim->itnim, io_aborts);
3014 bfa_sm_send_event(ioim, BFA_IOIM_SM_ABORT);
3016 return BFA_STATUS_OK;
3020 * BFA TSKIM state machine functions
3024 * Task management command beginning state.
3026 static void
3027 bfa_tskim_sm_uninit(struct bfa_tskim_s *tskim, enum bfa_tskim_event event)
3029 bfa_trc(tskim->bfa, tskim->tsk_tag << 16 | event);
3031 switch (event) {
3032 case BFA_TSKIM_SM_START:
3033 bfa_sm_set_state(tskim, bfa_tskim_sm_active);
3034 bfa_tskim_gather_ios(tskim);
3037 * If device is offline, do not send TM on wire. Just cleanup
3038 * any pending IO requests and complete TM request.
3040 if (!bfa_itnim_is_online(tskim->itnim)) {
3041 bfa_sm_set_state(tskim, bfa_tskim_sm_iocleanup);
3042 tskim->tsk_status = BFI_TSKIM_STS_OK;
3043 bfa_tskim_cleanup_ios(tskim);
3044 return;
3047 if (!bfa_tskim_send(tskim)) {
3048 bfa_sm_set_state(tskim, bfa_tskim_sm_qfull);
3049 bfa_stats(tskim->itnim, tm_qwait);
3050 bfa_reqq_wait(tskim->bfa, tskim->itnim->reqq,
3051 &tskim->reqq_wait);
3053 break;
3055 default:
3056 bfa_sm_fault(tskim->bfa, event);
3061 * TM command is active, awaiting completion from firmware to
3062 * cleanup IO requests in TM scope.
3064 static void
3065 bfa_tskim_sm_active(struct bfa_tskim_s *tskim, enum bfa_tskim_event event)
3067 bfa_trc(tskim->bfa, tskim->tsk_tag << 16 | event);
3069 switch (event) {
3070 case BFA_TSKIM_SM_DONE:
3071 bfa_sm_set_state(tskim, bfa_tskim_sm_iocleanup);
3072 bfa_tskim_cleanup_ios(tskim);
3073 break;
3075 case BFA_TSKIM_SM_CLEANUP:
3076 bfa_sm_set_state(tskim, bfa_tskim_sm_cleanup);
3077 if (!bfa_tskim_send_abort(tskim)) {
3078 bfa_sm_set_state(tskim, bfa_tskim_sm_cleanup_qfull);
3079 bfa_stats(tskim->itnim, tm_qwait);
3080 bfa_reqq_wait(tskim->bfa, tskim->itnim->reqq,
3081 &tskim->reqq_wait);
3083 break;
3085 case BFA_TSKIM_SM_HWFAIL:
3086 bfa_sm_set_state(tskim, bfa_tskim_sm_hcb);
3087 bfa_tskim_iocdisable_ios(tskim);
3088 bfa_tskim_qcomp(tskim, __bfa_cb_tskim_failed);
3089 break;
3091 default:
3092 bfa_sm_fault(tskim->bfa, event);
3097 * An active TM is being cleaned up since ITN is offline. Awaiting cleanup
3098 * completion event from firmware.
3100 static void
3101 bfa_tskim_sm_cleanup(struct bfa_tskim_s *tskim, enum bfa_tskim_event event)
3103 bfa_trc(tskim->bfa, tskim->tsk_tag << 16 | event);
3105 switch (event) {
3106 case BFA_TSKIM_SM_DONE:
3108 * Ignore and wait for ABORT completion from firmware.
3110 break;
3112 case BFA_TSKIM_SM_UTAG:
3113 case BFA_TSKIM_SM_CLEANUP_DONE:
3114 bfa_sm_set_state(tskim, bfa_tskim_sm_iocleanup);
3115 bfa_tskim_cleanup_ios(tskim);
3116 break;
3118 case BFA_TSKIM_SM_HWFAIL:
3119 bfa_sm_set_state(tskim, bfa_tskim_sm_hcb);
3120 bfa_tskim_iocdisable_ios(tskim);
3121 bfa_tskim_qcomp(tskim, __bfa_cb_tskim_failed);
3122 break;
3124 default:
3125 bfa_sm_fault(tskim->bfa, event);
3129 static void
3130 bfa_tskim_sm_iocleanup(struct bfa_tskim_s *tskim, enum bfa_tskim_event event)
3132 bfa_trc(tskim->bfa, tskim->tsk_tag << 16 | event);
3134 switch (event) {
3135 case BFA_TSKIM_SM_IOS_DONE:
3136 bfa_sm_set_state(tskim, bfa_tskim_sm_hcb);
3137 bfa_tskim_qcomp(tskim, __bfa_cb_tskim_done);
3138 break;
3140 case BFA_TSKIM_SM_CLEANUP:
3142 * Ignore, TM command completed on wire.
3143 * Notify TM conmpletion on IO cleanup completion.
3145 break;
3147 case BFA_TSKIM_SM_HWFAIL:
3148 bfa_sm_set_state(tskim, bfa_tskim_sm_hcb);
3149 bfa_tskim_iocdisable_ios(tskim);
3150 bfa_tskim_qcomp(tskim, __bfa_cb_tskim_failed);
3151 break;
3153 default:
3154 bfa_sm_fault(tskim->bfa, event);
3159 * Task management command is waiting for room in request CQ
3161 static void
3162 bfa_tskim_sm_qfull(struct bfa_tskim_s *tskim, enum bfa_tskim_event event)
3164 bfa_trc(tskim->bfa, tskim->tsk_tag << 16 | event);
3166 switch (event) {
3167 case BFA_TSKIM_SM_QRESUME:
3168 bfa_sm_set_state(tskim, bfa_tskim_sm_active);
3169 bfa_tskim_send(tskim);
3170 break;
3172 case BFA_TSKIM_SM_CLEANUP:
3174 * No need to send TM on wire since ITN is offline.
3176 bfa_sm_set_state(tskim, bfa_tskim_sm_iocleanup);
3177 bfa_reqq_wcancel(&tskim->reqq_wait);
3178 bfa_tskim_cleanup_ios(tskim);
3179 break;
3181 case BFA_TSKIM_SM_HWFAIL:
3182 bfa_sm_set_state(tskim, bfa_tskim_sm_hcb);
3183 bfa_reqq_wcancel(&tskim->reqq_wait);
3184 bfa_tskim_iocdisable_ios(tskim);
3185 bfa_tskim_qcomp(tskim, __bfa_cb_tskim_failed);
3186 break;
3188 default:
3189 bfa_sm_fault(tskim->bfa, event);
3194 * Task management command is active, awaiting for room in request CQ
3195 * to send clean up request.
3197 static void
3198 bfa_tskim_sm_cleanup_qfull(struct bfa_tskim_s *tskim,
3199 enum bfa_tskim_event event)
3201 bfa_trc(tskim->bfa, tskim->tsk_tag << 16 | event);
3203 switch (event) {
3204 case BFA_TSKIM_SM_DONE:
3205 bfa_reqq_wcancel(&tskim->reqq_wait);
3206 fallthrough;
3207 case BFA_TSKIM_SM_QRESUME:
3208 bfa_sm_set_state(tskim, bfa_tskim_sm_cleanup);
3209 bfa_tskim_send_abort(tskim);
3210 break;
3212 case BFA_TSKIM_SM_HWFAIL:
3213 bfa_sm_set_state(tskim, bfa_tskim_sm_hcb);
3214 bfa_reqq_wcancel(&tskim->reqq_wait);
3215 bfa_tskim_iocdisable_ios(tskim);
3216 bfa_tskim_qcomp(tskim, __bfa_cb_tskim_failed);
3217 break;
3219 default:
3220 bfa_sm_fault(tskim->bfa, event);
3225 * BFA callback is pending
3227 static void
3228 bfa_tskim_sm_hcb(struct bfa_tskim_s *tskim, enum bfa_tskim_event event)
3230 bfa_trc(tskim->bfa, tskim->tsk_tag << 16 | event);
3232 switch (event) {
3233 case BFA_TSKIM_SM_HCB:
3234 bfa_sm_set_state(tskim, bfa_tskim_sm_uninit);
3235 bfa_tskim_free(tskim);
3236 break;
3238 case BFA_TSKIM_SM_CLEANUP:
3239 bfa_tskim_notify_comp(tskim);
3240 break;
3242 case BFA_TSKIM_SM_HWFAIL:
3243 break;
3245 default:
3246 bfa_sm_fault(tskim->bfa, event);
3250 static void
3251 __bfa_cb_tskim_done(void *cbarg, bfa_boolean_t complete)
3253 struct bfa_tskim_s *tskim = cbarg;
3255 if (!complete) {
3256 bfa_sm_send_event(tskim, BFA_TSKIM_SM_HCB);
3257 return;
3260 bfa_stats(tskim->itnim, tm_success);
3261 bfa_cb_tskim_done(tskim->bfa->bfad, tskim->dtsk, tskim->tsk_status);
3264 static void
3265 __bfa_cb_tskim_failed(void *cbarg, bfa_boolean_t complete)
3267 struct bfa_tskim_s *tskim = cbarg;
3269 if (!complete) {
3270 bfa_sm_send_event(tskim, BFA_TSKIM_SM_HCB);
3271 return;
3274 bfa_stats(tskim->itnim, tm_failures);
3275 bfa_cb_tskim_done(tskim->bfa->bfad, tskim->dtsk,
3276 BFI_TSKIM_STS_FAILED);
3279 static bfa_boolean_t
3280 bfa_tskim_match_scope(struct bfa_tskim_s *tskim, struct scsi_lun lun)
3282 switch (tskim->tm_cmnd) {
3283 case FCP_TM_TARGET_RESET:
3284 return BFA_TRUE;
3286 case FCP_TM_ABORT_TASK_SET:
3287 case FCP_TM_CLEAR_TASK_SET:
3288 case FCP_TM_LUN_RESET:
3289 case FCP_TM_CLEAR_ACA:
3290 return !memcmp(&tskim->lun, &lun, sizeof(lun));
3292 default:
3293 WARN_ON(1);
3296 return BFA_FALSE;
3300 * Gather affected IO requests and task management commands.
3302 static void
3303 bfa_tskim_gather_ios(struct bfa_tskim_s *tskim)
3305 struct bfa_itnim_s *itnim = tskim->itnim;
3306 struct bfa_ioim_s *ioim;
3307 struct list_head *qe, *qen;
3308 struct scsi_cmnd *cmnd;
3309 struct scsi_lun scsilun;
3311 INIT_LIST_HEAD(&tskim->io_q);
3314 * Gather any active IO requests first.
3316 list_for_each_safe(qe, qen, &itnim->io_q) {
3317 ioim = (struct bfa_ioim_s *) qe;
3318 cmnd = (struct scsi_cmnd *) ioim->dio;
3319 int_to_scsilun(cmnd->device->lun, &scsilun);
3320 if (bfa_tskim_match_scope(tskim, scsilun)) {
3321 list_del(&ioim->qe);
3322 list_add_tail(&ioim->qe, &tskim->io_q);
3327 * Failback any pending IO requests immediately.
3329 list_for_each_safe(qe, qen, &itnim->pending_q) {
3330 ioim = (struct bfa_ioim_s *) qe;
3331 cmnd = (struct scsi_cmnd *) ioim->dio;
3332 int_to_scsilun(cmnd->device->lun, &scsilun);
3333 if (bfa_tskim_match_scope(tskim, scsilun)) {
3334 list_del(&ioim->qe);
3335 list_add_tail(&ioim->qe, &ioim->fcpim->ioim_comp_q);
3336 bfa_ioim_tov(ioim);
3342 * IO cleanup completion
3344 static void
3345 bfa_tskim_cleanp_comp(void *tskim_cbarg)
3347 struct bfa_tskim_s *tskim = tskim_cbarg;
3349 bfa_stats(tskim->itnim, tm_io_comps);
3350 bfa_sm_send_event(tskim, BFA_TSKIM_SM_IOS_DONE);
3354 * Gather affected IO requests and task management commands.
3356 static void
3357 bfa_tskim_cleanup_ios(struct bfa_tskim_s *tskim)
3359 struct bfa_ioim_s *ioim;
3360 struct list_head *qe, *qen;
3362 bfa_wc_init(&tskim->wc, bfa_tskim_cleanp_comp, tskim);
3364 list_for_each_safe(qe, qen, &tskim->io_q) {
3365 ioim = (struct bfa_ioim_s *) qe;
3366 bfa_wc_up(&tskim->wc);
3367 bfa_ioim_cleanup_tm(ioim, tskim);
3370 bfa_wc_wait(&tskim->wc);
3374 * Send task management request to firmware.
3376 static bfa_boolean_t
3377 bfa_tskim_send(struct bfa_tskim_s *tskim)
3379 struct bfa_itnim_s *itnim = tskim->itnim;
3380 struct bfi_tskim_req_s *m;
3383 * check for room in queue to send request now
3385 m = bfa_reqq_next(tskim->bfa, itnim->reqq);
3386 if (!m)
3387 return BFA_FALSE;
3390 * build i/o request message next
3392 bfi_h2i_set(m->mh, BFI_MC_TSKIM, BFI_TSKIM_H2I_TM_REQ,
3393 bfa_fn_lpu(tskim->bfa));
3395 m->tsk_tag = cpu_to_be16(tskim->tsk_tag);
3396 m->itn_fhdl = tskim->itnim->rport->fw_handle;
3397 m->t_secs = tskim->tsecs;
3398 m->lun = tskim->lun;
3399 m->tm_flags = tskim->tm_cmnd;
3402 * queue I/O message to firmware
3404 bfa_reqq_produce(tskim->bfa, itnim->reqq, m->mh);
3405 return BFA_TRUE;
3409 * Send abort request to cleanup an active TM to firmware.
3411 static bfa_boolean_t
3412 bfa_tskim_send_abort(struct bfa_tskim_s *tskim)
3414 struct bfa_itnim_s *itnim = tskim->itnim;
3415 struct bfi_tskim_abortreq_s *m;
3418 * check for room in queue to send request now
3420 m = bfa_reqq_next(tskim->bfa, itnim->reqq);
3421 if (!m)
3422 return BFA_FALSE;
3425 * build i/o request message next
3427 bfi_h2i_set(m->mh, BFI_MC_TSKIM, BFI_TSKIM_H2I_ABORT_REQ,
3428 bfa_fn_lpu(tskim->bfa));
3430 m->tsk_tag = cpu_to_be16(tskim->tsk_tag);
3433 * queue I/O message to firmware
3435 bfa_reqq_produce(tskim->bfa, itnim->reqq, m->mh);
3436 return BFA_TRUE;
3440 * Call to resume task management cmnd waiting for room in request queue.
3442 static void
3443 bfa_tskim_qresume(void *cbarg)
3445 struct bfa_tskim_s *tskim = cbarg;
3447 bfa_stats(tskim->itnim, tm_qresumes);
3448 bfa_sm_send_event(tskim, BFA_TSKIM_SM_QRESUME);
3452 * Cleanup IOs associated with a task mangement command on IOC failures.
3454 static void
3455 bfa_tskim_iocdisable_ios(struct bfa_tskim_s *tskim)
3457 struct bfa_ioim_s *ioim;
3458 struct list_head *qe, *qen;
3460 list_for_each_safe(qe, qen, &tskim->io_q) {
3461 ioim = (struct bfa_ioim_s *) qe;
3462 bfa_ioim_iocdisable(ioim);
3467 * Notification on completions from related ioim.
3469 void
3470 bfa_tskim_iodone(struct bfa_tskim_s *tskim)
3472 bfa_wc_down(&tskim->wc);
3476 * Handle IOC h/w failure notification from itnim.
3478 void
3479 bfa_tskim_iocdisable(struct bfa_tskim_s *tskim)
3481 tskim->notify = BFA_FALSE;
3482 bfa_stats(tskim->itnim, tm_iocdowns);
3483 bfa_sm_send_event(tskim, BFA_TSKIM_SM_HWFAIL);
3487 * Cleanup TM command and associated IOs as part of ITNIM offline.
3489 void
3490 bfa_tskim_cleanup(struct bfa_tskim_s *tskim)
3492 tskim->notify = BFA_TRUE;
3493 bfa_stats(tskim->itnim, tm_cleanups);
3494 bfa_sm_send_event(tskim, BFA_TSKIM_SM_CLEANUP);
3498 * Memory allocation and initialization.
3500 void
3501 bfa_tskim_attach(struct bfa_fcpim_s *fcpim)
3503 struct bfa_tskim_s *tskim;
3504 struct bfa_fcp_mod_s *fcp = fcpim->fcp;
3505 u16 i;
3507 INIT_LIST_HEAD(&fcpim->tskim_free_q);
3508 INIT_LIST_HEAD(&fcpim->tskim_unused_q);
3510 tskim = (struct bfa_tskim_s *) bfa_mem_kva_curp(fcp);
3511 fcpim->tskim_arr = tskim;
3513 for (i = 0; i < fcpim->num_tskim_reqs; i++, tskim++) {
3515 * initialize TSKIM
3517 memset(tskim, 0, sizeof(struct bfa_tskim_s));
3518 tskim->tsk_tag = i;
3519 tskim->bfa = fcpim->bfa;
3520 tskim->fcpim = fcpim;
3521 tskim->notify = BFA_FALSE;
3522 bfa_reqq_winit(&tskim->reqq_wait, bfa_tskim_qresume,
3523 tskim);
3524 bfa_sm_set_state(tskim, bfa_tskim_sm_uninit);
3526 list_add_tail(&tskim->qe, &fcpim->tskim_free_q);
3529 bfa_mem_kva_curp(fcp) = (u8 *) tskim;
3532 void
3533 bfa_tskim_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
3535 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
3536 struct bfi_tskim_rsp_s *rsp = (struct bfi_tskim_rsp_s *) m;
3537 struct bfa_tskim_s *tskim;
3538 u16 tsk_tag = be16_to_cpu(rsp->tsk_tag);
3540 tskim = BFA_TSKIM_FROM_TAG(fcpim, tsk_tag);
3541 WARN_ON(tskim->tsk_tag != tsk_tag);
3543 tskim->tsk_status = rsp->tsk_status;
3546 * Firmware sends BFI_TSKIM_STS_ABORTED status for abort
3547 * requests. All other statuses are for normal completions.
3549 if (rsp->tsk_status == BFI_TSKIM_STS_ABORTED) {
3550 bfa_stats(tskim->itnim, tm_cleanup_comps);
3551 bfa_sm_send_event(tskim, BFA_TSKIM_SM_CLEANUP_DONE);
3552 } else if (rsp->tsk_status == BFI_TSKIM_STS_UTAG) {
3553 bfa_sm_send_event(tskim, BFA_TSKIM_SM_UTAG);
3554 } else {
3555 bfa_stats(tskim->itnim, tm_fw_rsps);
3556 bfa_sm_send_event(tskim, BFA_TSKIM_SM_DONE);
3561 struct bfa_tskim_s *
3562 bfa_tskim_alloc(struct bfa_s *bfa, struct bfad_tskim_s *dtsk)
3564 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
3565 struct bfa_tskim_s *tskim;
3567 bfa_q_deq(&fcpim->tskim_free_q, &tskim);
3569 if (tskim)
3570 tskim->dtsk = dtsk;
3572 return tskim;
3575 void
3576 bfa_tskim_free(struct bfa_tskim_s *tskim)
3578 WARN_ON(!bfa_q_is_on_q_func(&tskim->itnim->tsk_q, &tskim->qe));
3579 list_del(&tskim->qe);
3580 list_add_tail(&tskim->qe, &tskim->fcpim->tskim_free_q);
3584 * Start a task management command.
3586 * @param[in] tskim BFA task management command instance
3587 * @param[in] itnim i-t nexus for the task management command
3588 * @param[in] lun lun, if applicable
3589 * @param[in] tm_cmnd Task management command code.
3590 * @param[in] t_secs Timeout in seconds
3592 * @return None.
3594 void
3595 bfa_tskim_start(struct bfa_tskim_s *tskim, struct bfa_itnim_s *itnim,
3596 struct scsi_lun lun,
3597 enum fcp_tm_cmnd tm_cmnd, u8 tsecs)
3599 tskim->itnim = itnim;
3600 tskim->lun = lun;
3601 tskim->tm_cmnd = tm_cmnd;
3602 tskim->tsecs = tsecs;
3603 tskim->notify = BFA_FALSE;
3604 bfa_stats(itnim, tm_cmnds);
3606 list_add_tail(&tskim->qe, &itnim->tsk_q);
3607 bfa_sm_send_event(tskim, BFA_TSKIM_SM_START);
3610 void
3611 bfa_tskim_res_recfg(struct bfa_s *bfa, u16 num_tskim_fw)
3613 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
3614 struct list_head *qe;
3615 int i;
3617 for (i = 0; i < (fcpim->num_tskim_reqs - num_tskim_fw); i++) {
3618 bfa_q_deq_tail(&fcpim->tskim_free_q, &qe);
3619 list_add_tail(qe, &fcpim->tskim_unused_q);
3623 void
3624 bfa_fcp_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
3625 struct bfa_s *bfa)
3627 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
3628 struct bfa_mem_kva_s *fcp_kva = BFA_MEM_FCP_KVA(bfa);
3629 struct bfa_mem_dma_s *seg_ptr;
3630 u16 nsegs, idx, per_seg_ios, num_io_req;
3631 u32 km_len = 0;
3634 * ZERO for num_ioim_reqs and num_fwtio_reqs is allowed config value.
3635 * So if the values are non zero, adjust them appropriately.
3637 if (cfg->fwcfg.num_ioim_reqs &&
3638 cfg->fwcfg.num_ioim_reqs < BFA_IOIM_MIN)
3639 cfg->fwcfg.num_ioim_reqs = BFA_IOIM_MIN;
3640 else if (cfg->fwcfg.num_ioim_reqs > BFA_IOIM_MAX)
3641 cfg->fwcfg.num_ioim_reqs = BFA_IOIM_MAX;
3643 if (cfg->fwcfg.num_fwtio_reqs > BFA_FWTIO_MAX)
3644 cfg->fwcfg.num_fwtio_reqs = BFA_FWTIO_MAX;
3646 num_io_req = (cfg->fwcfg.num_ioim_reqs + cfg->fwcfg.num_fwtio_reqs);
3647 if (num_io_req > BFA_IO_MAX) {
3648 if (cfg->fwcfg.num_ioim_reqs && cfg->fwcfg.num_fwtio_reqs) {
3649 cfg->fwcfg.num_ioim_reqs = BFA_IO_MAX/2;
3650 cfg->fwcfg.num_fwtio_reqs = BFA_IO_MAX/2;
3651 } else if (cfg->fwcfg.num_fwtio_reqs)
3652 cfg->fwcfg.num_fwtio_reqs = BFA_FWTIO_MAX;
3653 else
3654 cfg->fwcfg.num_ioim_reqs = BFA_IOIM_MAX;
3657 bfa_fcpim_meminfo(cfg, &km_len);
3659 num_io_req = (cfg->fwcfg.num_ioim_reqs + cfg->fwcfg.num_fwtio_reqs);
3660 km_len += num_io_req * sizeof(struct bfa_iotag_s);
3661 km_len += cfg->fwcfg.num_rports * sizeof(struct bfa_itn_s);
3663 /* dma memory */
3664 nsegs = BFI_MEM_DMA_NSEGS(num_io_req, BFI_IOIM_SNSLEN);
3665 per_seg_ios = BFI_MEM_NREQS_SEG(BFI_IOIM_SNSLEN);
3667 bfa_mem_dma_seg_iter(fcp, seg_ptr, nsegs, idx) {
3668 if (num_io_req >= per_seg_ios) {
3669 num_io_req -= per_seg_ios;
3670 bfa_mem_dma_setup(minfo, seg_ptr,
3671 per_seg_ios * BFI_IOIM_SNSLEN);
3672 } else
3673 bfa_mem_dma_setup(minfo, seg_ptr,
3674 num_io_req * BFI_IOIM_SNSLEN);
3677 /* kva memory */
3678 bfa_mem_kva_setup(minfo, fcp_kva, km_len);
3681 void
3682 bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
3683 struct bfa_pcidev_s *pcidev)
3685 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
3686 struct bfa_mem_dma_s *seg_ptr;
3687 u16 idx, nsegs, num_io_req;
3689 fcp->max_ioim_reqs = cfg->fwcfg.num_ioim_reqs;
3690 fcp->num_ioim_reqs = cfg->fwcfg.num_ioim_reqs;
3691 fcp->num_fwtio_reqs = cfg->fwcfg.num_fwtio_reqs;
3692 fcp->num_itns = cfg->fwcfg.num_rports;
3693 fcp->bfa = bfa;
3696 * Setup the pool of snsbase addr's, that is passed to fw as
3697 * part of bfi_iocfc_cfg_s.
3699 num_io_req = (cfg->fwcfg.num_ioim_reqs + cfg->fwcfg.num_fwtio_reqs);
3700 nsegs = BFI_MEM_DMA_NSEGS(num_io_req, BFI_IOIM_SNSLEN);
3702 bfa_mem_dma_seg_iter(fcp, seg_ptr, nsegs, idx) {
3704 if (!bfa_mem_dma_virt(seg_ptr))
3705 break;
3707 fcp->snsbase[idx].pa = bfa_mem_dma_phys(seg_ptr);
3708 fcp->snsbase[idx].kva = bfa_mem_dma_virt(seg_ptr);
3709 bfa_iocfc_set_snsbase(bfa, idx, fcp->snsbase[idx].pa);
3712 fcp->throttle_update_required = 1;
3713 bfa_fcpim_attach(fcp, bfad, cfg, pcidev);
3715 bfa_iotag_attach(fcp);
3717 fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
3718 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
3719 (fcp->num_itns * sizeof(struct bfa_itn_s));
3720 memset(fcp->itn_arr, 0,
3721 (fcp->num_itns * sizeof(struct bfa_itn_s)));
3724 void
3725 bfa_fcp_iocdisable(struct bfa_s *bfa)
3727 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
3729 bfa_fcpim_iocdisable(fcp);
3732 void
3733 bfa_fcp_res_recfg(struct bfa_s *bfa, u16 num_ioim_fw, u16 max_ioim_fw)
3735 struct bfa_fcp_mod_s *mod = BFA_FCP_MOD(bfa);
3736 struct list_head *qe;
3737 int i;
3739 /* Update io throttle value only once during driver load time */
3740 if (!mod->throttle_update_required)
3741 return;
3743 for (i = 0; i < (mod->num_ioim_reqs - num_ioim_fw); i++) {
3744 bfa_q_deq_tail(&mod->iotag_ioim_free_q, &qe);
3745 list_add_tail(qe, &mod->iotag_unused_q);
3748 if (mod->num_ioim_reqs != num_ioim_fw) {
3749 bfa_trc(bfa, mod->num_ioim_reqs);
3750 bfa_trc(bfa, num_ioim_fw);
3753 mod->max_ioim_reqs = max_ioim_fw;
3754 mod->num_ioim_reqs = num_ioim_fw;
3755 mod->throttle_update_required = 0;
3758 void
3759 bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
3760 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
3762 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
3763 struct bfa_itn_s *itn;
3765 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
3766 itn->isr = isr;
3770 * Itn interrupt processing.
3772 void
3773 bfa_itn_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
3775 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
3776 union bfi_itn_i2h_msg_u msg;
3777 struct bfa_itn_s *itn;
3779 msg.msg = m;
3780 itn = BFA_ITN_FROM_TAG(fcp, msg.create_rsp->bfa_handle);
3782 if (itn->isr)
3783 itn->isr(bfa, m);
3784 else
3785 WARN_ON(1);
3788 void
3789 bfa_iotag_attach(struct bfa_fcp_mod_s *fcp)
3791 struct bfa_iotag_s *iotag;
3792 u16 num_io_req, i;
3794 iotag = (struct bfa_iotag_s *) bfa_mem_kva_curp(fcp);
3795 fcp->iotag_arr = iotag;
3797 INIT_LIST_HEAD(&fcp->iotag_ioim_free_q);
3798 INIT_LIST_HEAD(&fcp->iotag_tio_free_q);
3799 INIT_LIST_HEAD(&fcp->iotag_unused_q);
3801 num_io_req = fcp->num_ioim_reqs + fcp->num_fwtio_reqs;
3802 for (i = 0; i < num_io_req; i++, iotag++) {
3803 memset(iotag, 0, sizeof(struct bfa_iotag_s));
3804 iotag->tag = i;
3805 if (i < fcp->num_ioim_reqs)
3806 list_add_tail(&iotag->qe, &fcp->iotag_ioim_free_q);
3807 else
3808 list_add_tail(&iotag->qe, &fcp->iotag_tio_free_q);
3811 bfa_mem_kva_curp(fcp) = (u8 *) iotag;
3816 * To send config req, first try to use throttle value from flash
3817 * If 0, then use driver parameter
3818 * We need to use min(flash_val, drv_val) because
3819 * memory allocation was done based on this cfg'd value
3822 bfa_fcpim_get_throttle_cfg(struct bfa_s *bfa, u16 drv_cfg_param)
3824 u16 tmp;
3825 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
3828 * If throttle value from flash is already in effect after driver is
3829 * loaded then until next load, always return current value instead
3830 * of actual flash value
3832 if (!fcp->throttle_update_required)
3833 return (u16)fcp->num_ioim_reqs;
3835 tmp = bfa_dconf_read_data_valid(bfa) ? bfa_fcpim_read_throttle(bfa) : 0;
3836 if (!tmp || (tmp > drv_cfg_param))
3837 tmp = drv_cfg_param;
3839 return tmp;
3842 bfa_status_t
3843 bfa_fcpim_write_throttle(struct bfa_s *bfa, u16 value)
3845 if (!bfa_dconf_get_min_cfg(bfa)) {
3846 BFA_DCONF_MOD(bfa)->dconf->throttle_cfg.value = value;
3847 BFA_DCONF_MOD(bfa)->dconf->throttle_cfg.is_valid = 1;
3848 return BFA_STATUS_OK;
3851 return BFA_STATUS_FAILED;
3855 bfa_fcpim_read_throttle(struct bfa_s *bfa)
3857 struct bfa_throttle_cfg_s *throttle_cfg =
3858 &(BFA_DCONF_MOD(bfa)->dconf->throttle_cfg);
3860 return ((!bfa_dconf_get_min_cfg(bfa)) ?
3861 ((throttle_cfg->is_valid == 1) ? (throttle_cfg->value) : 0) : 0);
3864 bfa_status_t
3865 bfa_fcpim_throttle_set(struct bfa_s *bfa, u16 value)
3867 /* in min cfg no commands should run. */
3868 if ((bfa_dconf_get_min_cfg(bfa) == BFA_TRUE) ||
3869 (!bfa_dconf_read_data_valid(bfa)))
3870 return BFA_STATUS_FAILED;
3872 bfa_fcpim_write_throttle(bfa, value);
3874 return bfa_dconf_update(bfa);
3877 bfa_status_t
3878 bfa_fcpim_throttle_get(struct bfa_s *bfa, void *buf)
3880 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
3881 struct bfa_defs_fcpim_throttle_s throttle;
3883 if ((bfa_dconf_get_min_cfg(bfa) == BFA_TRUE) ||
3884 (!bfa_dconf_read_data_valid(bfa)))
3885 return BFA_STATUS_FAILED;
3887 memset(&throttle, 0, sizeof(struct bfa_defs_fcpim_throttle_s));
3889 throttle.cur_value = (u16)(fcpim->fcp->num_ioim_reqs);
3890 throttle.cfg_value = bfa_fcpim_read_throttle(bfa);
3891 if (!throttle.cfg_value)
3892 throttle.cfg_value = throttle.cur_value;
3893 throttle.max_value = (u16)(fcpim->fcp->max_ioim_reqs);
3894 memcpy(buf, &throttle, sizeof(struct bfa_defs_fcpim_throttle_s));
3896 return BFA_STATUS_OK;