blob: 1633963c66cac646cea41c4a1ba7a386873fa4c7 [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
Jing Huang7725ccf2009-09-23 17:46:15 -07003 * All rights reserved
4 * www.brocade.com
5 *
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License (GPL) Version 2 as
10 * published by the Free Software Foundation
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 */
17
Maggie Zhangf16a1752010-12-09 19:12:32 -080018#include "bfad_drv.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070019#include "bfa_modules.h"
Jing Huang7725ccf2009-09-23 17:46:15 -070020
21BFA_TRC_FILE(HAL, FCPIM);
Jing Huang7725ccf2009-09-23 17:46:15 -070022
Jing Huang5fbe25c2010-10-18 17:17:23 -070023/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070024 * BFA ITNIM Related definitions
25 */
26static void bfa_itnim_update_del_itn_stats(struct bfa_itnim_s *itnim);
Krishna Gudipati83763d52011-07-20 17:04:03 -070027static void bfa_ioim_lm_init(struct bfa_s *bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070028
29#define BFA_ITNIM_FROM_TAG(_fcpim, _tag) \
30 (((_fcpim)->itnim_arr + ((_tag) & ((_fcpim)->num_itnims - 1))))
31
32#define bfa_fcpim_additn(__itnim) \
33 list_add_tail(&(__itnim)->qe, &(__itnim)->fcpim->itnim_q)
34#define bfa_fcpim_delitn(__itnim) do { \
Jing Huangd4b671c2010-12-26 21:46:35 -080035 WARN_ON(!bfa_q_is_on_q(&(__itnim)->fcpim->itnim_q, __itnim)); \
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070036 bfa_itnim_update_del_itn_stats(__itnim); \
37 list_del(&(__itnim)->qe); \
Jing Huangd4b671c2010-12-26 21:46:35 -080038 WARN_ON(!list_empty(&(__itnim)->io_q)); \
39 WARN_ON(!list_empty(&(__itnim)->io_cleanup_q)); \
40 WARN_ON(!list_empty(&(__itnim)->pending_q)); \
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070041} while (0)
42
43#define bfa_itnim_online_cb(__itnim) do { \
44 if ((__itnim)->bfa->fcs) \
45 bfa_cb_itnim_online((__itnim)->ditn); \
46 else { \
47 bfa_cb_queue((__itnim)->bfa, &(__itnim)->hcb_qe, \
48 __bfa_cb_itnim_online, (__itnim)); \
49 } \
50} while (0)
51
52#define bfa_itnim_offline_cb(__itnim) do { \
53 if ((__itnim)->bfa->fcs) \
54 bfa_cb_itnim_offline((__itnim)->ditn); \
55 else { \
56 bfa_cb_queue((__itnim)->bfa, &(__itnim)->hcb_qe, \
57 __bfa_cb_itnim_offline, (__itnim)); \
58 } \
59} while (0)
60
61#define bfa_itnim_sler_cb(__itnim) do { \
62 if ((__itnim)->bfa->fcs) \
63 bfa_cb_itnim_sler((__itnim)->ditn); \
64 else { \
65 bfa_cb_queue((__itnim)->bfa, &(__itnim)->hcb_qe, \
66 __bfa_cb_itnim_sler, (__itnim)); \
67 } \
68} while (0)
69
Krishna Gudipati83763d52011-07-20 17:04:03 -070070enum bfa_ioim_lm_ua_status {
71 BFA_IOIM_LM_UA_RESET = 0,
72 BFA_IOIM_LM_UA_SET = 1,
73};
74
Jing Huang5fbe25c2010-10-18 17:17:23 -070075/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -080076 * itnim state machine event
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070077 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070078enum bfa_itnim_event {
79 BFA_ITNIM_SM_CREATE = 1, /* itnim is created */
80 BFA_ITNIM_SM_ONLINE = 2, /* itnim is online */
81 BFA_ITNIM_SM_OFFLINE = 3, /* itnim is offline */
82 BFA_ITNIM_SM_FWRSP = 4, /* firmware response */
83 BFA_ITNIM_SM_DELETE = 5, /* deleting an existing itnim */
84 BFA_ITNIM_SM_CLEANUP = 6, /* IO cleanup completion */
85 BFA_ITNIM_SM_SLER = 7, /* second level error recovery */
86 BFA_ITNIM_SM_HWFAIL = 8, /* IOC h/w failure event */
87 BFA_ITNIM_SM_QRESUME = 9, /* queue space available */
88};
89
Jing Huang5fbe25c2010-10-18 17:17:23 -070090/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070091 * BFA IOIM related definitions
92 */
93#define bfa_ioim_move_to_comp_q(__ioim) do { \
94 list_del(&(__ioim)->qe); \
95 list_add_tail(&(__ioim)->qe, &(__ioim)->fcpim->ioim_comp_q); \
96} while (0)
97
98
99#define bfa_ioim_cb_profile_comp(__fcpim, __ioim) do { \
100 if ((__fcpim)->profile_comp) \
101 (__fcpim)->profile_comp(__ioim); \
102} while (0)
103
104#define bfa_ioim_cb_profile_start(__fcpim, __ioim) do { \
105 if ((__fcpim)->profile_start) \
106 (__fcpim)->profile_start(__ioim); \
107} while (0)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700108
Jing Huang5fbe25c2010-10-18 17:17:23 -0700109/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700110 * IO state machine events
111 */
112enum bfa_ioim_event {
113 BFA_IOIM_SM_START = 1, /* io start request from host */
114 BFA_IOIM_SM_COMP_GOOD = 2, /* io good comp, resource free */
115 BFA_IOIM_SM_COMP = 3, /* io comp, resource is free */
116 BFA_IOIM_SM_COMP_UTAG = 4, /* io comp, resource is free */
117 BFA_IOIM_SM_DONE = 5, /* io comp, resource not free */
118 BFA_IOIM_SM_FREE = 6, /* io resource is freed */
119 BFA_IOIM_SM_ABORT = 7, /* abort request from scsi stack */
120 BFA_IOIM_SM_ABORT_COMP = 8, /* abort from f/w */
121 BFA_IOIM_SM_ABORT_DONE = 9, /* abort completion from f/w */
122 BFA_IOIM_SM_QRESUME = 10, /* CQ space available to queue IO */
123 BFA_IOIM_SM_SGALLOCED = 11, /* SG page allocation successful */
124 BFA_IOIM_SM_SQRETRY = 12, /* sequence recovery retry */
125 BFA_IOIM_SM_HCB = 13, /* bfa callback complete */
126 BFA_IOIM_SM_CLEANUP = 14, /* IO cleanup from itnim */
127 BFA_IOIM_SM_TMSTART = 15, /* IO cleanup from tskim */
128 BFA_IOIM_SM_TMDONE = 16, /* IO cleanup from tskim */
129 BFA_IOIM_SM_HWFAIL = 17, /* IOC h/w failure event */
130 BFA_IOIM_SM_IOTOV = 18, /* ITN offline TOV */
131};
132
133
Jing Huang5fbe25c2010-10-18 17:17:23 -0700134/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700135 * BFA TSKIM related definitions
136 */
137
Jing Huang5fbe25c2010-10-18 17:17:23 -0700138/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700139 * task management completion handling
140 */
141#define bfa_tskim_qcomp(__tskim, __cbfn) do { \
142 bfa_cb_queue((__tskim)->bfa, &(__tskim)->hcb_qe, __cbfn, (__tskim));\
143 bfa_tskim_notify_comp(__tskim); \
144} while (0)
145
146#define bfa_tskim_notify_comp(__tskim) do { \
147 if ((__tskim)->notify) \
148 bfa_itnim_tskdone((__tskim)->itnim); \
149} while (0)
150
151
152enum bfa_tskim_event {
153 BFA_TSKIM_SM_START = 1, /* TM command start */
154 BFA_TSKIM_SM_DONE = 2, /* TM completion */
155 BFA_TSKIM_SM_QRESUME = 3, /* resume after qfull */
156 BFA_TSKIM_SM_HWFAIL = 5, /* IOC h/w failure event */
157 BFA_TSKIM_SM_HCB = 6, /* BFA callback completion */
158 BFA_TSKIM_SM_IOS_DONE = 7, /* IO and sub TM completions */
159 BFA_TSKIM_SM_CLEANUP = 8, /* TM cleanup on ITN offline */
160 BFA_TSKIM_SM_CLEANUP_DONE = 9, /* TM abort completion */
161};
162
Jing Huang5fbe25c2010-10-18 17:17:23 -0700163/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700164 * forward declaration for BFA ITNIM functions
165 */
166static void bfa_itnim_iocdisable_cleanup(struct bfa_itnim_s *itnim);
167static bfa_boolean_t bfa_itnim_send_fwcreate(struct bfa_itnim_s *itnim);
168static bfa_boolean_t bfa_itnim_send_fwdelete(struct bfa_itnim_s *itnim);
169static void bfa_itnim_cleanp_comp(void *itnim_cbarg);
170static void bfa_itnim_cleanup(struct bfa_itnim_s *itnim);
171static void __bfa_cb_itnim_online(void *cbarg, bfa_boolean_t complete);
172static void __bfa_cb_itnim_offline(void *cbarg, bfa_boolean_t complete);
173static void __bfa_cb_itnim_sler(void *cbarg, bfa_boolean_t complete);
174static void bfa_itnim_iotov_online(struct bfa_itnim_s *itnim);
175static void bfa_itnim_iotov_cleanup(struct bfa_itnim_s *itnim);
176static void bfa_itnim_iotov(void *itnim_arg);
177static void bfa_itnim_iotov_start(struct bfa_itnim_s *itnim);
178static void bfa_itnim_iotov_stop(struct bfa_itnim_s *itnim);
179static void bfa_itnim_iotov_delete(struct bfa_itnim_s *itnim);
180
Jing Huang5fbe25c2010-10-18 17:17:23 -0700181/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700182 * forward declaration of ITNIM state machine
183 */
184static void bfa_itnim_sm_uninit(struct bfa_itnim_s *itnim,
185 enum bfa_itnim_event event);
186static void bfa_itnim_sm_created(struct bfa_itnim_s *itnim,
187 enum bfa_itnim_event event);
188static void bfa_itnim_sm_fwcreate(struct bfa_itnim_s *itnim,
189 enum bfa_itnim_event event);
190static void bfa_itnim_sm_delete_pending(struct bfa_itnim_s *itnim,
191 enum bfa_itnim_event event);
192static void bfa_itnim_sm_online(struct bfa_itnim_s *itnim,
193 enum bfa_itnim_event event);
194static void bfa_itnim_sm_sler(struct bfa_itnim_s *itnim,
195 enum bfa_itnim_event event);
196static void bfa_itnim_sm_cleanup_offline(struct bfa_itnim_s *itnim,
197 enum bfa_itnim_event event);
198static void bfa_itnim_sm_cleanup_delete(struct bfa_itnim_s *itnim,
199 enum bfa_itnim_event event);
200static void bfa_itnim_sm_fwdelete(struct bfa_itnim_s *itnim,
201 enum bfa_itnim_event event);
202static void bfa_itnim_sm_offline(struct bfa_itnim_s *itnim,
203 enum bfa_itnim_event event);
204static void bfa_itnim_sm_iocdisable(struct bfa_itnim_s *itnim,
205 enum bfa_itnim_event event);
206static void bfa_itnim_sm_deleting(struct bfa_itnim_s *itnim,
207 enum bfa_itnim_event event);
208static void bfa_itnim_sm_fwcreate_qfull(struct bfa_itnim_s *itnim,
209 enum bfa_itnim_event event);
210static void bfa_itnim_sm_fwdelete_qfull(struct bfa_itnim_s *itnim,
211 enum bfa_itnim_event event);
212static void bfa_itnim_sm_deleting_qfull(struct bfa_itnim_s *itnim,
213 enum bfa_itnim_event event);
214
Jing Huang5fbe25c2010-10-18 17:17:23 -0700215/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700216 * forward declaration for BFA IOIM functions
217 */
218static bfa_boolean_t bfa_ioim_send_ioreq(struct bfa_ioim_s *ioim);
Maggie Zhange3e7d3e2010-12-09 19:10:27 -0800219static bfa_boolean_t bfa_ioim_sgpg_alloc(struct bfa_ioim_s *ioim);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700220static bfa_boolean_t bfa_ioim_send_abort(struct bfa_ioim_s *ioim);
221static void bfa_ioim_notify_cleanup(struct bfa_ioim_s *ioim);
222static void __bfa_cb_ioim_good_comp(void *cbarg, bfa_boolean_t complete);
223static void __bfa_cb_ioim_comp(void *cbarg, bfa_boolean_t complete);
224static void __bfa_cb_ioim_abort(void *cbarg, bfa_boolean_t complete);
225static void __bfa_cb_ioim_failed(void *cbarg, bfa_boolean_t complete);
226static void __bfa_cb_ioim_pathtov(void *cbarg, bfa_boolean_t complete);
227static bfa_boolean_t bfa_ioim_is_abortable(struct bfa_ioim_s *ioim);
228
Jing Huang5fbe25c2010-10-18 17:17:23 -0700229/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700230 * forward declaration of BFA IO state machine
231 */
232static void bfa_ioim_sm_uninit(struct bfa_ioim_s *ioim,
233 enum bfa_ioim_event event);
234static void bfa_ioim_sm_sgalloc(struct bfa_ioim_s *ioim,
235 enum bfa_ioim_event event);
236static void bfa_ioim_sm_active(struct bfa_ioim_s *ioim,
237 enum bfa_ioim_event event);
238static void bfa_ioim_sm_abort(struct bfa_ioim_s *ioim,
239 enum bfa_ioim_event event);
240static void bfa_ioim_sm_cleanup(struct bfa_ioim_s *ioim,
241 enum bfa_ioim_event event);
242static void bfa_ioim_sm_qfull(struct bfa_ioim_s *ioim,
243 enum bfa_ioim_event event);
244static void bfa_ioim_sm_abort_qfull(struct bfa_ioim_s *ioim,
245 enum bfa_ioim_event event);
246static void bfa_ioim_sm_cleanup_qfull(struct bfa_ioim_s *ioim,
247 enum bfa_ioim_event event);
248static void bfa_ioim_sm_hcb(struct bfa_ioim_s *ioim,
249 enum bfa_ioim_event event);
250static void bfa_ioim_sm_hcb_free(struct bfa_ioim_s *ioim,
251 enum bfa_ioim_event event);
252static void bfa_ioim_sm_resfree(struct bfa_ioim_s *ioim,
253 enum bfa_ioim_event event);
254static void bfa_ioim_sm_cmnd_retry(struct bfa_ioim_s *ioim,
255 enum bfa_ioim_event event);
Jing Huang5fbe25c2010-10-18 17:17:23 -0700256/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700257 * forward declaration for BFA TSKIM functions
258 */
259static void __bfa_cb_tskim_done(void *cbarg, bfa_boolean_t complete);
260static void __bfa_cb_tskim_failed(void *cbarg, bfa_boolean_t complete);
261static bfa_boolean_t bfa_tskim_match_scope(struct bfa_tskim_s *tskim,
Maggie Zhangf3148782010-12-09 19:11:39 -0800262 struct scsi_lun lun);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700263static void bfa_tskim_gather_ios(struct bfa_tskim_s *tskim);
264static void bfa_tskim_cleanp_comp(void *tskim_cbarg);
265static void bfa_tskim_cleanup_ios(struct bfa_tskim_s *tskim);
266static bfa_boolean_t bfa_tskim_send(struct bfa_tskim_s *tskim);
267static bfa_boolean_t bfa_tskim_send_abort(struct bfa_tskim_s *tskim);
268static void bfa_tskim_iocdisable_ios(struct bfa_tskim_s *tskim);
269
Jing Huang5fbe25c2010-10-18 17:17:23 -0700270/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700271 * forward declaration of BFA TSKIM state machine
272 */
273static void bfa_tskim_sm_uninit(struct bfa_tskim_s *tskim,
274 enum bfa_tskim_event event);
275static void bfa_tskim_sm_active(struct bfa_tskim_s *tskim,
276 enum bfa_tskim_event event);
277static void bfa_tskim_sm_cleanup(struct bfa_tskim_s *tskim,
278 enum bfa_tskim_event event);
279static void bfa_tskim_sm_iocleanup(struct bfa_tskim_s *tskim,
280 enum bfa_tskim_event event);
281static void bfa_tskim_sm_qfull(struct bfa_tskim_s *tskim,
282 enum bfa_tskim_event event);
283static void bfa_tskim_sm_cleanup_qfull(struct bfa_tskim_s *tskim,
284 enum bfa_tskim_event event);
285static void bfa_tskim_sm_hcb(struct bfa_tskim_s *tskim,
286 enum bfa_tskim_event event);
Jing Huang5fbe25c2010-10-18 17:17:23 -0700287/*
Maggie Zhangdf0f1932010-12-09 19:07:46 -0800288 * BFA FCP Initiator Mode module
Jing Huang7725ccf2009-09-23 17:46:15 -0700289 */
290
Jing Huang5fbe25c2010-10-18 17:17:23 -0700291/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -0800292 * Compute and return memory needed by FCP(im) module.
Jing Huang7725ccf2009-09-23 17:46:15 -0700293 */
294static void
Krishna Gudipati45070252011-06-24 20:24:29 -0700295bfa_fcpim_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len)
Jing Huang7725ccf2009-09-23 17:46:15 -0700296{
Krishna Gudipati45070252011-06-24 20:24:29 -0700297 bfa_itnim_meminfo(cfg, km_len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700298
Jing Huang5fbe25c2010-10-18 17:17:23 -0700299 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700300 * IO memory
301 */
Jing Huang7725ccf2009-09-23 17:46:15 -0700302 *km_len += cfg->fwcfg.num_ioim_reqs *
303 (sizeof(struct bfa_ioim_s) + sizeof(struct bfa_ioim_sp_s));
304
Jing Huang5fbe25c2010-10-18 17:17:23 -0700305 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700306 * task management command memory
307 */
308 if (cfg->fwcfg.num_tskim_reqs < BFA_TSKIM_MIN)
309 cfg->fwcfg.num_tskim_reqs = BFA_TSKIM_MIN;
310 *km_len += cfg->fwcfg.num_tskim_reqs * sizeof(struct bfa_tskim_s);
311}
312
313
314static void
Krishna Gudipatie2187d72011-06-13 15:53:58 -0700315bfa_fcpim_attach(struct bfa_fcp_mod_s *fcp, void *bfad,
Krishna Gudipati45070252011-06-24 20:24:29 -0700316 struct bfa_iocfc_cfg_s *cfg, struct bfa_pcidev_s *pcidev)
Jing Huang7725ccf2009-09-23 17:46:15 -0700317{
Krishna Gudipatie2187d72011-06-13 15:53:58 -0700318 struct bfa_fcpim_s *fcpim = &fcp->fcpim;
319 struct bfa_s *bfa = fcp->bfa;
Jing Huang7725ccf2009-09-23 17:46:15 -0700320
321 bfa_trc(bfa, cfg->drvcfg.path_tov);
322 bfa_trc(bfa, cfg->fwcfg.num_rports);
323 bfa_trc(bfa, cfg->fwcfg.num_ioim_reqs);
324 bfa_trc(bfa, cfg->fwcfg.num_tskim_reqs);
325
Krishna Gudipatie2187d72011-06-13 15:53:58 -0700326 fcpim->fcp = fcp;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700327 fcpim->bfa = bfa;
328 fcpim->num_itnims = cfg->fwcfg.num_rports;
Jing Huang7725ccf2009-09-23 17:46:15 -0700329 fcpim->num_tskim_reqs = cfg->fwcfg.num_tskim_reqs;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700330 fcpim->path_tov = cfg->drvcfg.path_tov;
331 fcpim->delay_comp = cfg->drvcfg.delay_comp;
332 fcpim->profile_comp = NULL;
333 fcpim->profile_start = NULL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700334
Krishna Gudipati45070252011-06-24 20:24:29 -0700335 bfa_itnim_attach(fcpim);
336 bfa_tskim_attach(fcpim);
337 bfa_ioim_attach(fcpim);
Jing Huang7725ccf2009-09-23 17:46:15 -0700338}
339
340static void
Krishna Gudipatie2187d72011-06-13 15:53:58 -0700341bfa_fcpim_iocdisable(struct bfa_fcp_mod_s *fcp)
Jing Huang7725ccf2009-09-23 17:46:15 -0700342{
Krishna Gudipatie2187d72011-06-13 15:53:58 -0700343 struct bfa_fcpim_s *fcpim = &fcp->fcpim;
Jing Huang7725ccf2009-09-23 17:46:15 -0700344 struct bfa_itnim_s *itnim;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700345 struct list_head *qe, *qen;
Jing Huang7725ccf2009-09-23 17:46:15 -0700346
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700347 /* Enqueue unused ioim resources to free_q */
348 list_splice_tail_init(&fcpim->tskim_unused_q, &fcpim->tskim_free_q);
349
Jing Huang7725ccf2009-09-23 17:46:15 -0700350 list_for_each_safe(qe, qen, &fcpim->itnim_q) {
351 itnim = (struct bfa_itnim_s *) qe;
352 bfa_itnim_iocdisable(itnim);
353 }
354}
355
356void
357bfa_fcpim_path_tov_set(struct bfa_s *bfa, u16 path_tov)
358{
Krishna Gudipatie2187d72011-06-13 15:53:58 -0700359 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -0700360
361 fcpim->path_tov = path_tov * 1000;
362 if (fcpim->path_tov > BFA_FCPIM_PATHTOV_MAX)
363 fcpim->path_tov = BFA_FCPIM_PATHTOV_MAX;
364}
365
366u16
367bfa_fcpim_path_tov_get(struct bfa_s *bfa)
368{
Krishna Gudipatie2187d72011-06-13 15:53:58 -0700369 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -0700370
Jing Huangf8ceafd2009-09-25 12:29:54 -0700371 return fcpim->path_tov / 1000;
Jing Huang7725ccf2009-09-23 17:46:15 -0700372}
373
Krishna Gudipati60138062011-06-24 20:25:15 -0700374#define bfa_fcpim_add_iostats(__l, __r, __stats) \
375 (__l->__stats += __r->__stats)
376
377void
378bfa_fcpim_add_stats(struct bfa_itnim_iostats_s *lstats,
379 struct bfa_itnim_iostats_s *rstats)
380{
381 bfa_fcpim_add_iostats(lstats, rstats, total_ios);
382 bfa_fcpim_add_iostats(lstats, rstats, qresumes);
383 bfa_fcpim_add_iostats(lstats, rstats, no_iotags);
384 bfa_fcpim_add_iostats(lstats, rstats, io_aborts);
385 bfa_fcpim_add_iostats(lstats, rstats, no_tskims);
386 bfa_fcpim_add_iostats(lstats, rstats, iocomp_ok);
387 bfa_fcpim_add_iostats(lstats, rstats, iocomp_underrun);
388 bfa_fcpim_add_iostats(lstats, rstats, iocomp_overrun);
389 bfa_fcpim_add_iostats(lstats, rstats, iocomp_aborted);
390 bfa_fcpim_add_iostats(lstats, rstats, iocomp_timedout);
391 bfa_fcpim_add_iostats(lstats, rstats, iocom_nexus_abort);
392 bfa_fcpim_add_iostats(lstats, rstats, iocom_proto_err);
393 bfa_fcpim_add_iostats(lstats, rstats, iocom_dif_err);
394 bfa_fcpim_add_iostats(lstats, rstats, iocom_sqer_needed);
395 bfa_fcpim_add_iostats(lstats, rstats, iocom_res_free);
396 bfa_fcpim_add_iostats(lstats, rstats, iocom_hostabrts);
397 bfa_fcpim_add_iostats(lstats, rstats, iocom_utags);
398 bfa_fcpim_add_iostats(lstats, rstats, io_cleanups);
399 bfa_fcpim_add_iostats(lstats, rstats, io_tmaborts);
400 bfa_fcpim_add_iostats(lstats, rstats, onlines);
401 bfa_fcpim_add_iostats(lstats, rstats, offlines);
402 bfa_fcpim_add_iostats(lstats, rstats, creates);
403 bfa_fcpim_add_iostats(lstats, rstats, deletes);
404 bfa_fcpim_add_iostats(lstats, rstats, create_comps);
405 bfa_fcpim_add_iostats(lstats, rstats, delete_comps);
406 bfa_fcpim_add_iostats(lstats, rstats, sler_events);
407 bfa_fcpim_add_iostats(lstats, rstats, fw_create);
408 bfa_fcpim_add_iostats(lstats, rstats, fw_delete);
409 bfa_fcpim_add_iostats(lstats, rstats, ioc_disabled);
410 bfa_fcpim_add_iostats(lstats, rstats, cleanup_comps);
411 bfa_fcpim_add_iostats(lstats, rstats, tm_cmnds);
412 bfa_fcpim_add_iostats(lstats, rstats, tm_fw_rsps);
413 bfa_fcpim_add_iostats(lstats, rstats, tm_success);
414 bfa_fcpim_add_iostats(lstats, rstats, tm_failures);
415 bfa_fcpim_add_iostats(lstats, rstats, tm_io_comps);
416 bfa_fcpim_add_iostats(lstats, rstats, tm_qresumes);
417 bfa_fcpim_add_iostats(lstats, rstats, tm_iocdowns);
418 bfa_fcpim_add_iostats(lstats, rstats, tm_cleanups);
419 bfa_fcpim_add_iostats(lstats, rstats, tm_cleanup_comps);
420 bfa_fcpim_add_iostats(lstats, rstats, io_comps);
421 bfa_fcpim_add_iostats(lstats, rstats, input_reqs);
422 bfa_fcpim_add_iostats(lstats, rstats, output_reqs);
423 bfa_fcpim_add_iostats(lstats, rstats, rd_throughput);
424 bfa_fcpim_add_iostats(lstats, rstats, wr_throughput);
425}
426
427bfa_status_t
428bfa_fcpim_port_iostats(struct bfa_s *bfa,
429 struct bfa_itnim_iostats_s *stats, u8 lp_tag)
430{
431 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
432 struct list_head *qe, *qen;
433 struct bfa_itnim_s *itnim;
434
435 /* accumulate IO stats from itnim */
436 memset(stats, 0, sizeof(struct bfa_itnim_iostats_s));
437 list_for_each_safe(qe, qen, &fcpim->itnim_q) {
438 itnim = (struct bfa_itnim_s *) qe;
439 if (itnim->rport->rport_info.lp_tag != lp_tag)
440 continue;
441 bfa_fcpim_add_stats(stats, &(itnim->stats));
442 }
443 return BFA_STATUS_OK;
444}
445
Krishna Gudipati42a8e6e2011-07-20 17:01:52 -0700446void
447bfa_ioim_profile_comp(struct bfa_ioim_s *ioim)
448{
449 struct bfa_itnim_latency_s *io_lat =
450 &(ioim->itnim->ioprofile.io_latency);
451 u32 val, idx;
452
453 val = (u32)(jiffies - ioim->start_time);
454 idx = bfa_ioim_get_index(scsi_bufflen((struct scsi_cmnd *)ioim->dio));
455 bfa_itnim_ioprofile_update(ioim->itnim, idx);
456
457 io_lat->count[idx]++;
458 io_lat->min[idx] = (io_lat->min[idx] < val) ? io_lat->min[idx] : val;
459 io_lat->max[idx] = (io_lat->max[idx] > val) ? io_lat->max[idx] : val;
460 io_lat->avg[idx] += val;
461}
462
463void
464bfa_ioim_profile_start(struct bfa_ioim_s *ioim)
465{
466 ioim->start_time = jiffies;
467}
468
469bfa_status_t
470bfa_fcpim_profile_on(struct bfa_s *bfa, u32 time)
471{
472 struct bfa_itnim_s *itnim;
473 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
474 struct list_head *qe, *qen;
475
476 /* accumulate IO stats from itnim */
477 list_for_each_safe(qe, qen, &fcpim->itnim_q) {
478 itnim = (struct bfa_itnim_s *) qe;
479 bfa_itnim_clear_stats(itnim);
480 }
481 fcpim->io_profile = BFA_TRUE;
482 fcpim->io_profile_start_time = time;
483 fcpim->profile_comp = bfa_ioim_profile_comp;
484 fcpim->profile_start = bfa_ioim_profile_start;
485 return BFA_STATUS_OK;
486}
487
488bfa_status_t
489bfa_fcpim_profile_off(struct bfa_s *bfa)
490{
491 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
492 fcpim->io_profile = BFA_FALSE;
493 fcpim->io_profile_start_time = 0;
494 fcpim->profile_comp = NULL;
495 fcpim->profile_start = NULL;
496 return BFA_STATUS_OK;
497}
498
Jing Huang7725ccf2009-09-23 17:46:15 -0700499u16
500bfa_fcpim_qdepth_get(struct bfa_s *bfa)
501{
Krishna Gudipatie2187d72011-06-13 15:53:58 -0700502 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -0700503
Jing Huangf8ceafd2009-09-25 12:29:54 -0700504 return fcpim->q_depth;
Jing Huang7725ccf2009-09-23 17:46:15 -0700505}
506
Jing Huang5fbe25c2010-10-18 17:17:23 -0700507/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700508 * BFA ITNIM module state machine functions
509 */
510
Jing Huang5fbe25c2010-10-18 17:17:23 -0700511/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -0800512 * Beginning/unallocated state - no events expected.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700513 */
514static void
515bfa_itnim_sm_uninit(struct bfa_itnim_s *itnim, enum bfa_itnim_event event)
516{
517 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
518 bfa_trc(itnim->bfa, event);
519
520 switch (event) {
521 case BFA_ITNIM_SM_CREATE:
522 bfa_sm_set_state(itnim, bfa_itnim_sm_created);
523 itnim->is_online = BFA_FALSE;
524 bfa_fcpim_additn(itnim);
525 break;
526
527 default:
528 bfa_sm_fault(itnim->bfa, event);
529 }
530}
531
Jing Huang5fbe25c2010-10-18 17:17:23 -0700532/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -0800533 * Beginning state, only online event expected.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700534 */
535static void
536bfa_itnim_sm_created(struct bfa_itnim_s *itnim, enum bfa_itnim_event event)
537{
538 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
539 bfa_trc(itnim->bfa, event);
540
541 switch (event) {
542 case BFA_ITNIM_SM_ONLINE:
543 if (bfa_itnim_send_fwcreate(itnim))
544 bfa_sm_set_state(itnim, bfa_itnim_sm_fwcreate);
545 else
546 bfa_sm_set_state(itnim, bfa_itnim_sm_fwcreate_qfull);
547 break;
548
549 case BFA_ITNIM_SM_DELETE:
550 bfa_sm_set_state(itnim, bfa_itnim_sm_uninit);
551 bfa_fcpim_delitn(itnim);
552 break;
553
554 case BFA_ITNIM_SM_HWFAIL:
555 bfa_sm_set_state(itnim, bfa_itnim_sm_iocdisable);
556 break;
557
558 default:
559 bfa_sm_fault(itnim->bfa, event);
560 }
561}
562
Jing Huang5fbe25c2010-10-18 17:17:23 -0700563/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700564 * Waiting for itnim create response from firmware.
565 */
566static void
567bfa_itnim_sm_fwcreate(struct bfa_itnim_s *itnim, enum bfa_itnim_event event)
568{
569 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
570 bfa_trc(itnim->bfa, event);
571
572 switch (event) {
573 case BFA_ITNIM_SM_FWRSP:
574 bfa_sm_set_state(itnim, bfa_itnim_sm_online);
575 itnim->is_online = BFA_TRUE;
576 bfa_itnim_iotov_online(itnim);
577 bfa_itnim_online_cb(itnim);
578 break;
579
580 case BFA_ITNIM_SM_DELETE:
581 bfa_sm_set_state(itnim, bfa_itnim_sm_delete_pending);
582 break;
583
584 case BFA_ITNIM_SM_OFFLINE:
585 if (bfa_itnim_send_fwdelete(itnim))
586 bfa_sm_set_state(itnim, bfa_itnim_sm_fwdelete);
587 else
588 bfa_sm_set_state(itnim, bfa_itnim_sm_fwdelete_qfull);
589 break;
590
591 case BFA_ITNIM_SM_HWFAIL:
592 bfa_sm_set_state(itnim, bfa_itnim_sm_iocdisable);
593 break;
594
595 default:
596 bfa_sm_fault(itnim->bfa, event);
597 }
598}
599
600static void
601bfa_itnim_sm_fwcreate_qfull(struct bfa_itnim_s *itnim,
602 enum bfa_itnim_event event)
603{
604 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
605 bfa_trc(itnim->bfa, event);
606
607 switch (event) {
608 case BFA_ITNIM_SM_QRESUME:
609 bfa_sm_set_state(itnim, bfa_itnim_sm_fwcreate);
610 bfa_itnim_send_fwcreate(itnim);
611 break;
612
613 case BFA_ITNIM_SM_DELETE:
614 bfa_sm_set_state(itnim, bfa_itnim_sm_uninit);
615 bfa_reqq_wcancel(&itnim->reqq_wait);
616 bfa_fcpim_delitn(itnim);
617 break;
618
619 case BFA_ITNIM_SM_OFFLINE:
620 bfa_sm_set_state(itnim, bfa_itnim_sm_offline);
621 bfa_reqq_wcancel(&itnim->reqq_wait);
622 bfa_itnim_offline_cb(itnim);
623 break;
624
625 case BFA_ITNIM_SM_HWFAIL:
626 bfa_sm_set_state(itnim, bfa_itnim_sm_iocdisable);
627 bfa_reqq_wcancel(&itnim->reqq_wait);
628 break;
629
630 default:
631 bfa_sm_fault(itnim->bfa, event);
632 }
633}
634
Jing Huang5fbe25c2010-10-18 17:17:23 -0700635/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -0800636 * Waiting for itnim create response from firmware, a delete is pending.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700637 */
638static void
639bfa_itnim_sm_delete_pending(struct bfa_itnim_s *itnim,
640 enum bfa_itnim_event event)
641{
642 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
643 bfa_trc(itnim->bfa, event);
644
645 switch (event) {
646 case BFA_ITNIM_SM_FWRSP:
647 if (bfa_itnim_send_fwdelete(itnim))
648 bfa_sm_set_state(itnim, bfa_itnim_sm_deleting);
649 else
650 bfa_sm_set_state(itnim, bfa_itnim_sm_deleting_qfull);
651 break;
652
653 case BFA_ITNIM_SM_HWFAIL:
654 bfa_sm_set_state(itnim, bfa_itnim_sm_uninit);
655 bfa_fcpim_delitn(itnim);
656 break;
657
658 default:
659 bfa_sm_fault(itnim->bfa, event);
660 }
661}
662
Jing Huang5fbe25c2010-10-18 17:17:23 -0700663/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -0800664 * Online state - normal parking state.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700665 */
666static void
667bfa_itnim_sm_online(struct bfa_itnim_s *itnim, enum bfa_itnim_event event)
668{
669 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
670 bfa_trc(itnim->bfa, event);
671
672 switch (event) {
673 case BFA_ITNIM_SM_OFFLINE:
674 bfa_sm_set_state(itnim, bfa_itnim_sm_cleanup_offline);
675 itnim->is_online = BFA_FALSE;
676 bfa_itnim_iotov_start(itnim);
677 bfa_itnim_cleanup(itnim);
678 break;
679
680 case BFA_ITNIM_SM_DELETE:
681 bfa_sm_set_state(itnim, bfa_itnim_sm_cleanup_delete);
682 itnim->is_online = BFA_FALSE;
683 bfa_itnim_cleanup(itnim);
684 break;
685
686 case BFA_ITNIM_SM_SLER:
687 bfa_sm_set_state(itnim, bfa_itnim_sm_sler);
688 itnim->is_online = BFA_FALSE;
689 bfa_itnim_iotov_start(itnim);
690 bfa_itnim_sler_cb(itnim);
691 break;
692
693 case BFA_ITNIM_SM_HWFAIL:
694 bfa_sm_set_state(itnim, bfa_itnim_sm_iocdisable);
695 itnim->is_online = BFA_FALSE;
696 bfa_itnim_iotov_start(itnim);
697 bfa_itnim_iocdisable_cleanup(itnim);
698 break;
699
700 default:
701 bfa_sm_fault(itnim->bfa, event);
702 }
703}
704
Jing Huang5fbe25c2010-10-18 17:17:23 -0700705/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -0800706 * Second level error recovery need.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700707 */
708static void
709bfa_itnim_sm_sler(struct bfa_itnim_s *itnim, enum bfa_itnim_event event)
710{
711 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
712 bfa_trc(itnim->bfa, event);
713
714 switch (event) {
715 case BFA_ITNIM_SM_OFFLINE:
716 bfa_sm_set_state(itnim, bfa_itnim_sm_cleanup_offline);
717 bfa_itnim_cleanup(itnim);
718 break;
719
720 case BFA_ITNIM_SM_DELETE:
721 bfa_sm_set_state(itnim, bfa_itnim_sm_cleanup_delete);
722 bfa_itnim_cleanup(itnim);
723 bfa_itnim_iotov_delete(itnim);
724 break;
725
726 case BFA_ITNIM_SM_HWFAIL:
727 bfa_sm_set_state(itnim, bfa_itnim_sm_iocdisable);
728 bfa_itnim_iocdisable_cleanup(itnim);
729 break;
730
731 default:
732 bfa_sm_fault(itnim->bfa, event);
733 }
734}
735
Jing Huang5fbe25c2010-10-18 17:17:23 -0700736/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -0800737 * Going offline. Waiting for active IO cleanup.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700738 */
739static void
740bfa_itnim_sm_cleanup_offline(struct bfa_itnim_s *itnim,
741 enum bfa_itnim_event event)
742{
743 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
744 bfa_trc(itnim->bfa, event);
745
746 switch (event) {
747 case BFA_ITNIM_SM_CLEANUP:
748 if (bfa_itnim_send_fwdelete(itnim))
749 bfa_sm_set_state(itnim, bfa_itnim_sm_fwdelete);
750 else
751 bfa_sm_set_state(itnim, bfa_itnim_sm_fwdelete_qfull);
752 break;
753
754 case BFA_ITNIM_SM_DELETE:
755 bfa_sm_set_state(itnim, bfa_itnim_sm_cleanup_delete);
756 bfa_itnim_iotov_delete(itnim);
757 break;
758
759 case BFA_ITNIM_SM_HWFAIL:
760 bfa_sm_set_state(itnim, bfa_itnim_sm_iocdisable);
761 bfa_itnim_iocdisable_cleanup(itnim);
762 bfa_itnim_offline_cb(itnim);
763 break;
764
765 case BFA_ITNIM_SM_SLER:
766 break;
767
768 default:
769 bfa_sm_fault(itnim->bfa, event);
770 }
771}
772
Jing Huang5fbe25c2010-10-18 17:17:23 -0700773/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -0800774 * Deleting itnim. Waiting for active IO cleanup.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700775 */
776static void
777bfa_itnim_sm_cleanup_delete(struct bfa_itnim_s *itnim,
778 enum bfa_itnim_event event)
779{
780 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
781 bfa_trc(itnim->bfa, event);
782
783 switch (event) {
784 case BFA_ITNIM_SM_CLEANUP:
785 if (bfa_itnim_send_fwdelete(itnim))
786 bfa_sm_set_state(itnim, bfa_itnim_sm_deleting);
787 else
788 bfa_sm_set_state(itnim, bfa_itnim_sm_deleting_qfull);
789 break;
790
791 case BFA_ITNIM_SM_HWFAIL:
792 bfa_sm_set_state(itnim, bfa_itnim_sm_iocdisable);
793 bfa_itnim_iocdisable_cleanup(itnim);
794 break;
795
796 default:
797 bfa_sm_fault(itnim->bfa, event);
798 }
799}
800
Jing Huang5fbe25c2010-10-18 17:17:23 -0700801/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700802 * Rport offline. Fimrware itnim is being deleted - awaiting f/w response.
803 */
804static void
805bfa_itnim_sm_fwdelete(struct bfa_itnim_s *itnim, enum bfa_itnim_event event)
806{
807 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
808 bfa_trc(itnim->bfa, event);
809
810 switch (event) {
811 case BFA_ITNIM_SM_FWRSP:
812 bfa_sm_set_state(itnim, bfa_itnim_sm_offline);
813 bfa_itnim_offline_cb(itnim);
814 break;
815
816 case BFA_ITNIM_SM_DELETE:
817 bfa_sm_set_state(itnim, bfa_itnim_sm_deleting);
818 break;
819
820 case BFA_ITNIM_SM_HWFAIL:
821 bfa_sm_set_state(itnim, bfa_itnim_sm_iocdisable);
822 bfa_itnim_offline_cb(itnim);
823 break;
824
825 default:
826 bfa_sm_fault(itnim->bfa, event);
827 }
828}
829
830static void
831bfa_itnim_sm_fwdelete_qfull(struct bfa_itnim_s *itnim,
832 enum bfa_itnim_event event)
833{
834 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
835 bfa_trc(itnim->bfa, event);
836
837 switch (event) {
838 case BFA_ITNIM_SM_QRESUME:
839 bfa_sm_set_state(itnim, bfa_itnim_sm_fwdelete);
840 bfa_itnim_send_fwdelete(itnim);
841 break;
842
843 case BFA_ITNIM_SM_DELETE:
844 bfa_sm_set_state(itnim, bfa_itnim_sm_deleting_qfull);
845 break;
846
847 case BFA_ITNIM_SM_HWFAIL:
848 bfa_sm_set_state(itnim, bfa_itnim_sm_iocdisable);
849 bfa_reqq_wcancel(&itnim->reqq_wait);
850 bfa_itnim_offline_cb(itnim);
851 break;
852
853 default:
854 bfa_sm_fault(itnim->bfa, event);
855 }
856}
857
Jing Huang5fbe25c2010-10-18 17:17:23 -0700858/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -0800859 * Offline state.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700860 */
861static void
862bfa_itnim_sm_offline(struct bfa_itnim_s *itnim, enum bfa_itnim_event event)
863{
864 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
865 bfa_trc(itnim->bfa, event);
866
867 switch (event) {
868 case BFA_ITNIM_SM_DELETE:
869 bfa_sm_set_state(itnim, bfa_itnim_sm_uninit);
870 bfa_itnim_iotov_delete(itnim);
871 bfa_fcpim_delitn(itnim);
872 break;
873
874 case BFA_ITNIM_SM_ONLINE:
875 if (bfa_itnim_send_fwcreate(itnim))
876 bfa_sm_set_state(itnim, bfa_itnim_sm_fwcreate);
877 else
878 bfa_sm_set_state(itnim, bfa_itnim_sm_fwcreate_qfull);
879 break;
880
881 case BFA_ITNIM_SM_HWFAIL:
882 bfa_sm_set_state(itnim, bfa_itnim_sm_iocdisable);
883 break;
884
885 default:
886 bfa_sm_fault(itnim->bfa, event);
887 }
888}
889
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700890static void
891bfa_itnim_sm_iocdisable(struct bfa_itnim_s *itnim,
892 enum bfa_itnim_event event)
893{
894 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
895 bfa_trc(itnim->bfa, event);
896
897 switch (event) {
898 case BFA_ITNIM_SM_DELETE:
899 bfa_sm_set_state(itnim, bfa_itnim_sm_uninit);
900 bfa_itnim_iotov_delete(itnim);
901 bfa_fcpim_delitn(itnim);
902 break;
903
904 case BFA_ITNIM_SM_OFFLINE:
905 bfa_itnim_offline_cb(itnim);
906 break;
907
908 case BFA_ITNIM_SM_ONLINE:
909 if (bfa_itnim_send_fwcreate(itnim))
910 bfa_sm_set_state(itnim, bfa_itnim_sm_fwcreate);
911 else
912 bfa_sm_set_state(itnim, bfa_itnim_sm_fwcreate_qfull);
913 break;
914
915 case BFA_ITNIM_SM_HWFAIL:
916 break;
917
918 default:
919 bfa_sm_fault(itnim->bfa, event);
920 }
921}
922
Jing Huang5fbe25c2010-10-18 17:17:23 -0700923/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -0800924 * Itnim is deleted, waiting for firmware response to delete.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700925 */
926static void
927bfa_itnim_sm_deleting(struct bfa_itnim_s *itnim, enum bfa_itnim_event event)
928{
929 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
930 bfa_trc(itnim->bfa, event);
931
932 switch (event) {
933 case BFA_ITNIM_SM_FWRSP:
934 case BFA_ITNIM_SM_HWFAIL:
935 bfa_sm_set_state(itnim, bfa_itnim_sm_uninit);
936 bfa_fcpim_delitn(itnim);
937 break;
938
939 default:
940 bfa_sm_fault(itnim->bfa, event);
941 }
942}
943
944static void
945bfa_itnim_sm_deleting_qfull(struct bfa_itnim_s *itnim,
946 enum bfa_itnim_event event)
947{
948 bfa_trc(itnim->bfa, itnim->rport->rport_tag);
949 bfa_trc(itnim->bfa, event);
950
951 switch (event) {
952 case BFA_ITNIM_SM_QRESUME:
953 bfa_sm_set_state(itnim, bfa_itnim_sm_deleting);
954 bfa_itnim_send_fwdelete(itnim);
955 break;
956
957 case BFA_ITNIM_SM_HWFAIL:
958 bfa_sm_set_state(itnim, bfa_itnim_sm_uninit);
959 bfa_reqq_wcancel(&itnim->reqq_wait);
960 bfa_fcpim_delitn(itnim);
961 break;
962
963 default:
964 bfa_sm_fault(itnim->bfa, event);
965 }
966}
967
Jing Huang5fbe25c2010-10-18 17:17:23 -0700968/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -0800969 * Initiate cleanup of all IOs on an IOC failure.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700970 */
971static void
972bfa_itnim_iocdisable_cleanup(struct bfa_itnim_s *itnim)
973{
974 struct bfa_tskim_s *tskim;
975 struct bfa_ioim_s *ioim;
976 struct list_head *qe, *qen;
977
978 list_for_each_safe(qe, qen, &itnim->tsk_q) {
979 tskim = (struct bfa_tskim_s *) qe;
980 bfa_tskim_iocdisable(tskim);
981 }
982
983 list_for_each_safe(qe, qen, &itnim->io_q) {
984 ioim = (struct bfa_ioim_s *) qe;
985 bfa_ioim_iocdisable(ioim);
986 }
987
Jing Huang5fbe25c2010-10-18 17:17:23 -0700988 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700989 * For IO request in pending queue, we pretend an early timeout.
990 */
991 list_for_each_safe(qe, qen, &itnim->pending_q) {
992 ioim = (struct bfa_ioim_s *) qe;
993 bfa_ioim_tov(ioim);
994 }
995
996 list_for_each_safe(qe, qen, &itnim->io_cleanup_q) {
997 ioim = (struct bfa_ioim_s *) qe;
998 bfa_ioim_iocdisable(ioim);
999 }
1000}
1001
Jing Huang5fbe25c2010-10-18 17:17:23 -07001002/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08001003 * IO cleanup completion
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001004 */
1005static void
1006bfa_itnim_cleanp_comp(void *itnim_cbarg)
1007{
1008 struct bfa_itnim_s *itnim = itnim_cbarg;
1009
1010 bfa_stats(itnim, cleanup_comps);
1011 bfa_sm_send_event(itnim, BFA_ITNIM_SM_CLEANUP);
1012}
1013
Jing Huang5fbe25c2010-10-18 17:17:23 -07001014/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08001015 * Initiate cleanup of all IOs.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001016 */
1017static void
1018bfa_itnim_cleanup(struct bfa_itnim_s *itnim)
1019{
1020 struct bfa_ioim_s *ioim;
1021 struct bfa_tskim_s *tskim;
1022 struct list_head *qe, *qen;
1023
1024 bfa_wc_init(&itnim->wc, bfa_itnim_cleanp_comp, itnim);
1025
1026 list_for_each_safe(qe, qen, &itnim->io_q) {
1027 ioim = (struct bfa_ioim_s *) qe;
1028
Jing Huang5fbe25c2010-10-18 17:17:23 -07001029 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001030 * Move IO to a cleanup queue from active queue so that a later
1031 * TM will not pickup this IO.
1032 */
1033 list_del(&ioim->qe);
1034 list_add_tail(&ioim->qe, &itnim->io_cleanup_q);
1035
1036 bfa_wc_up(&itnim->wc);
1037 bfa_ioim_cleanup(ioim);
1038 }
1039
1040 list_for_each_safe(qe, qen, &itnim->tsk_q) {
1041 tskim = (struct bfa_tskim_s *) qe;
1042 bfa_wc_up(&itnim->wc);
1043 bfa_tskim_cleanup(tskim);
1044 }
1045
1046 bfa_wc_wait(&itnim->wc);
1047}
1048
1049static void
1050__bfa_cb_itnim_online(void *cbarg, bfa_boolean_t complete)
1051{
1052 struct bfa_itnim_s *itnim = cbarg;
1053
1054 if (complete)
1055 bfa_cb_itnim_online(itnim->ditn);
1056}
1057
1058static void
1059__bfa_cb_itnim_offline(void *cbarg, bfa_boolean_t complete)
1060{
1061 struct bfa_itnim_s *itnim = cbarg;
1062
1063 if (complete)
1064 bfa_cb_itnim_offline(itnim->ditn);
1065}
1066
1067static void
1068__bfa_cb_itnim_sler(void *cbarg, bfa_boolean_t complete)
1069{
1070 struct bfa_itnim_s *itnim = cbarg;
1071
1072 if (complete)
1073 bfa_cb_itnim_sler(itnim->ditn);
1074}
1075
Jing Huang5fbe25c2010-10-18 17:17:23 -07001076/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001077 * Call to resume any I/O requests waiting for room in request queue.
1078 */
1079static void
1080bfa_itnim_qresume(void *cbarg)
1081{
1082 struct bfa_itnim_s *itnim = cbarg;
1083
1084 bfa_sm_send_event(itnim, BFA_ITNIM_SM_QRESUME);
1085}
1086
Jing Huang5fbe25c2010-10-18 17:17:23 -07001087/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001088 * bfa_itnim_public
1089 */
1090
1091void
1092bfa_itnim_iodone(struct bfa_itnim_s *itnim)
1093{
1094 bfa_wc_down(&itnim->wc);
1095}
1096
1097void
1098bfa_itnim_tskdone(struct bfa_itnim_s *itnim)
1099{
1100 bfa_wc_down(&itnim->wc);
1101}
1102
1103void
Krishna Gudipati45070252011-06-24 20:24:29 -07001104bfa_itnim_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001105{
Jing Huang5fbe25c2010-10-18 17:17:23 -07001106 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001107 * ITN memory
1108 */
1109 *km_len += cfg->fwcfg.num_rports * sizeof(struct bfa_itnim_s);
1110}
1111
1112void
Krishna Gudipati45070252011-06-24 20:24:29 -07001113bfa_itnim_attach(struct bfa_fcpim_s *fcpim)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001114{
1115 struct bfa_s *bfa = fcpim->bfa;
Krishna Gudipati45070252011-06-24 20:24:29 -07001116 struct bfa_fcp_mod_s *fcp = fcpim->fcp;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001117 struct bfa_itnim_s *itnim;
1118 int i, j;
1119
1120 INIT_LIST_HEAD(&fcpim->itnim_q);
1121
Krishna Gudipati45070252011-06-24 20:24:29 -07001122 itnim = (struct bfa_itnim_s *) bfa_mem_kva_curp(fcp);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001123 fcpim->itnim_arr = itnim;
1124
1125 for (i = 0; i < fcpim->num_itnims; i++, itnim++) {
Jing Huang6a18b162010-10-18 17:08:54 -07001126 memset(itnim, 0, sizeof(struct bfa_itnim_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001127 itnim->bfa = bfa;
1128 itnim->fcpim = fcpim;
1129 itnim->reqq = BFA_REQQ_QOS_LO;
1130 itnim->rport = BFA_RPORT_FROM_TAG(bfa, i);
1131 itnim->iotov_active = BFA_FALSE;
1132 bfa_reqq_winit(&itnim->reqq_wait, bfa_itnim_qresume, itnim);
1133
1134 INIT_LIST_HEAD(&itnim->io_q);
1135 INIT_LIST_HEAD(&itnim->io_cleanup_q);
1136 INIT_LIST_HEAD(&itnim->pending_q);
1137 INIT_LIST_HEAD(&itnim->tsk_q);
1138 INIT_LIST_HEAD(&itnim->delay_comp_q);
1139 for (j = 0; j < BFA_IOBUCKET_MAX; j++)
1140 itnim->ioprofile.io_latency.min[j] = ~0;
1141 bfa_sm_set_state(itnim, bfa_itnim_sm_uninit);
1142 }
1143
Krishna Gudipati45070252011-06-24 20:24:29 -07001144 bfa_mem_kva_curp(fcp) = (u8 *) itnim;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001145}
1146
1147void
1148bfa_itnim_iocdisable(struct bfa_itnim_s *itnim)
1149{
1150 bfa_stats(itnim, ioc_disabled);
1151 bfa_sm_send_event(itnim, BFA_ITNIM_SM_HWFAIL);
1152}
1153
1154static bfa_boolean_t
1155bfa_itnim_send_fwcreate(struct bfa_itnim_s *itnim)
1156{
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07001157 struct bfi_itn_create_req_s *m;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001158
1159 itnim->msg_no++;
1160
Jing Huang5fbe25c2010-10-18 17:17:23 -07001161 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001162 * check for room in queue to send request now
1163 */
1164 m = bfa_reqq_next(itnim->bfa, itnim->reqq);
1165 if (!m) {
1166 bfa_reqq_wait(itnim->bfa, itnim->reqq, &itnim->reqq_wait);
1167 return BFA_FALSE;
1168 }
1169
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07001170 bfi_h2i_set(m->mh, BFI_MC_ITN, BFI_ITN_H2I_CREATE_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001171 bfa_fn_lpu(itnim->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001172 m->fw_handle = itnim->rport->fw_handle;
1173 m->class = FC_CLASS_3;
1174 m->seq_rec = itnim->seq_rec;
1175 m->msg_no = itnim->msg_no;
1176 bfa_stats(itnim, fw_create);
1177
Jing Huang5fbe25c2010-10-18 17:17:23 -07001178 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001179 * queue I/O message to firmware
1180 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001181 bfa_reqq_produce(itnim->bfa, itnim->reqq, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001182 return BFA_TRUE;
1183}
1184
1185static bfa_boolean_t
1186bfa_itnim_send_fwdelete(struct bfa_itnim_s *itnim)
1187{
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07001188 struct bfi_itn_delete_req_s *m;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001189
Jing Huang5fbe25c2010-10-18 17:17:23 -07001190 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001191 * check for room in queue to send request now
1192 */
1193 m = bfa_reqq_next(itnim->bfa, itnim->reqq);
1194 if (!m) {
1195 bfa_reqq_wait(itnim->bfa, itnim->reqq, &itnim->reqq_wait);
1196 return BFA_FALSE;
1197 }
1198
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07001199 bfi_h2i_set(m->mh, BFI_MC_ITN, BFI_ITN_H2I_DELETE_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001200 bfa_fn_lpu(itnim->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001201 m->fw_handle = itnim->rport->fw_handle;
1202 bfa_stats(itnim, fw_delete);
1203
Jing Huang5fbe25c2010-10-18 17:17:23 -07001204 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001205 * queue I/O message to firmware
1206 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001207 bfa_reqq_produce(itnim->bfa, itnim->reqq, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001208 return BFA_TRUE;
1209}
1210
Jing Huang5fbe25c2010-10-18 17:17:23 -07001211/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001212 * Cleanup all pending failed inflight requests.
1213 */
1214static void
1215bfa_itnim_delayed_comp(struct bfa_itnim_s *itnim, bfa_boolean_t iotov)
1216{
1217 struct bfa_ioim_s *ioim;
1218 struct list_head *qe, *qen;
1219
1220 list_for_each_safe(qe, qen, &itnim->delay_comp_q) {
1221 ioim = (struct bfa_ioim_s *)qe;
1222 bfa_ioim_delayed_comp(ioim, iotov);
1223 }
1224}
1225
Jing Huang5fbe25c2010-10-18 17:17:23 -07001226/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001227 * Start all pending IO requests.
1228 */
1229static void
1230bfa_itnim_iotov_online(struct bfa_itnim_s *itnim)
1231{
1232 struct bfa_ioim_s *ioim;
1233
1234 bfa_itnim_iotov_stop(itnim);
1235
Jing Huang5fbe25c2010-10-18 17:17:23 -07001236 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001237 * Abort all inflight IO requests in the queue
1238 */
1239 bfa_itnim_delayed_comp(itnim, BFA_FALSE);
1240
Jing Huang5fbe25c2010-10-18 17:17:23 -07001241 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001242 * Start all pending IO requests.
1243 */
1244 while (!list_empty(&itnim->pending_q)) {
1245 bfa_q_deq(&itnim->pending_q, &ioim);
1246 list_add_tail(&ioim->qe, &itnim->io_q);
1247 bfa_ioim_start(ioim);
1248 }
1249}
1250
Jing Huang5fbe25c2010-10-18 17:17:23 -07001251/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001252 * Fail all pending IO requests
1253 */
1254static void
1255bfa_itnim_iotov_cleanup(struct bfa_itnim_s *itnim)
1256{
1257 struct bfa_ioim_s *ioim;
1258
Jing Huang5fbe25c2010-10-18 17:17:23 -07001259 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001260 * Fail all inflight IO requests in the queue
1261 */
1262 bfa_itnim_delayed_comp(itnim, BFA_TRUE);
1263
Jing Huang5fbe25c2010-10-18 17:17:23 -07001264 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001265 * Fail any pending IO requests.
1266 */
1267 while (!list_empty(&itnim->pending_q)) {
1268 bfa_q_deq(&itnim->pending_q, &ioim);
1269 list_add_tail(&ioim->qe, &ioim->fcpim->ioim_comp_q);
1270 bfa_ioim_tov(ioim);
1271 }
1272}
1273
Jing Huang5fbe25c2010-10-18 17:17:23 -07001274/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001275 * IO TOV timer callback. Fail any pending IO requests.
1276 */
1277static void
1278bfa_itnim_iotov(void *itnim_arg)
1279{
1280 struct bfa_itnim_s *itnim = itnim_arg;
1281
1282 itnim->iotov_active = BFA_FALSE;
1283
1284 bfa_cb_itnim_tov_begin(itnim->ditn);
1285 bfa_itnim_iotov_cleanup(itnim);
1286 bfa_cb_itnim_tov(itnim->ditn);
1287}
1288
Jing Huang5fbe25c2010-10-18 17:17:23 -07001289/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001290 * Start IO TOV timer for failing back pending IO requests in offline state.
1291 */
1292static void
1293bfa_itnim_iotov_start(struct bfa_itnim_s *itnim)
1294{
1295 if (itnim->fcpim->path_tov > 0) {
1296
1297 itnim->iotov_active = BFA_TRUE;
Jing Huangd4b671c2010-12-26 21:46:35 -08001298 WARN_ON(!bfa_itnim_hold_io(itnim));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001299 bfa_timer_start(itnim->bfa, &itnim->timer,
1300 bfa_itnim_iotov, itnim, itnim->fcpim->path_tov);
1301 }
1302}
1303
Jing Huang5fbe25c2010-10-18 17:17:23 -07001304/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001305 * Stop IO TOV timer.
1306 */
1307static void
1308bfa_itnim_iotov_stop(struct bfa_itnim_s *itnim)
1309{
1310 if (itnim->iotov_active) {
1311 itnim->iotov_active = BFA_FALSE;
1312 bfa_timer_stop(&itnim->timer);
1313 }
1314}
1315
Jing Huang5fbe25c2010-10-18 17:17:23 -07001316/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001317 * Stop IO TOV timer.
1318 */
1319static void
1320bfa_itnim_iotov_delete(struct bfa_itnim_s *itnim)
1321{
1322 bfa_boolean_t pathtov_active = BFA_FALSE;
1323
1324 if (itnim->iotov_active)
1325 pathtov_active = BFA_TRUE;
1326
1327 bfa_itnim_iotov_stop(itnim);
1328 if (pathtov_active)
1329 bfa_cb_itnim_tov_begin(itnim->ditn);
1330 bfa_itnim_iotov_cleanup(itnim);
1331 if (pathtov_active)
1332 bfa_cb_itnim_tov(itnim->ditn);
1333}
1334
1335static void
1336bfa_itnim_update_del_itn_stats(struct bfa_itnim_s *itnim)
1337{
Krishna Gudipatie2187d72011-06-13 15:53:58 -07001338 struct bfa_fcpim_s *fcpim = BFA_FCPIM(itnim->bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001339 fcpim->del_itn_stats.del_itn_iocomp_aborted +=
1340 itnim->stats.iocomp_aborted;
1341 fcpim->del_itn_stats.del_itn_iocomp_timedout +=
1342 itnim->stats.iocomp_timedout;
1343 fcpim->del_itn_stats.del_itn_iocom_sqer_needed +=
1344 itnim->stats.iocom_sqer_needed;
1345 fcpim->del_itn_stats.del_itn_iocom_res_free +=
1346 itnim->stats.iocom_res_free;
1347 fcpim->del_itn_stats.del_itn_iocom_hostabrts +=
1348 itnim->stats.iocom_hostabrts;
1349 fcpim->del_itn_stats.del_itn_total_ios += itnim->stats.total_ios;
1350 fcpim->del_itn_stats.del_io_iocdowns += itnim->stats.io_iocdowns;
1351 fcpim->del_itn_stats.del_tm_iocdowns += itnim->stats.tm_iocdowns;
1352}
1353
Jing Huang5fbe25c2010-10-18 17:17:23 -07001354/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08001355 * bfa_itnim_public
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001356 */
1357
Jing Huang5fbe25c2010-10-18 17:17:23 -07001358/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08001359 * Itnim interrupt processing.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001360 */
1361void
1362bfa_itnim_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
1363{
Krishna Gudipatie2187d72011-06-13 15:53:58 -07001364 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07001365 union bfi_itn_i2h_msg_u msg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001366 struct bfa_itnim_s *itnim;
1367
1368 bfa_trc(bfa, m->mhdr.msg_id);
1369
1370 msg.msg = m;
1371
1372 switch (m->mhdr.msg_id) {
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07001373 case BFI_ITN_I2H_CREATE_RSP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001374 itnim = BFA_ITNIM_FROM_TAG(fcpim,
1375 msg.create_rsp->bfa_handle);
Jing Huangd4b671c2010-12-26 21:46:35 -08001376 WARN_ON(msg.create_rsp->status != BFA_STATUS_OK);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001377 bfa_stats(itnim, create_comps);
1378 bfa_sm_send_event(itnim, BFA_ITNIM_SM_FWRSP);
1379 break;
1380
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07001381 case BFI_ITN_I2H_DELETE_RSP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001382 itnim = BFA_ITNIM_FROM_TAG(fcpim,
1383 msg.delete_rsp->bfa_handle);
Jing Huangd4b671c2010-12-26 21:46:35 -08001384 WARN_ON(msg.delete_rsp->status != BFA_STATUS_OK);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001385 bfa_stats(itnim, delete_comps);
1386 bfa_sm_send_event(itnim, BFA_ITNIM_SM_FWRSP);
1387 break;
1388
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -07001389 case BFI_ITN_I2H_SLER_EVENT:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001390 itnim = BFA_ITNIM_FROM_TAG(fcpim,
1391 msg.sler_event->bfa_handle);
1392 bfa_stats(itnim, sler_events);
1393 bfa_sm_send_event(itnim, BFA_ITNIM_SM_SLER);
1394 break;
1395
1396 default:
1397 bfa_trc(bfa, m->mhdr.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08001398 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001399 }
1400}
1401
Jing Huang5fbe25c2010-10-18 17:17:23 -07001402/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08001403 * bfa_itnim_api
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001404 */
1405
1406struct bfa_itnim_s *
1407bfa_itnim_create(struct bfa_s *bfa, struct bfa_rport_s *rport, void *ditn)
1408{
Krishna Gudipatie2187d72011-06-13 15:53:58 -07001409 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001410 struct bfa_itnim_s *itnim;
1411
Krishna Gudipatie2187d72011-06-13 15:53:58 -07001412 bfa_itn_create(bfa, rport, bfa_itnim_isr);
1413
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001414 itnim = BFA_ITNIM_FROM_TAG(fcpim, rport->rport_tag);
Jing Huangd4b671c2010-12-26 21:46:35 -08001415 WARN_ON(itnim->rport != rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001416
1417 itnim->ditn = ditn;
1418
1419 bfa_stats(itnim, creates);
1420 bfa_sm_send_event(itnim, BFA_ITNIM_SM_CREATE);
1421
1422 return itnim;
1423}
1424
1425void
1426bfa_itnim_delete(struct bfa_itnim_s *itnim)
1427{
1428 bfa_stats(itnim, deletes);
1429 bfa_sm_send_event(itnim, BFA_ITNIM_SM_DELETE);
1430}
1431
1432void
1433bfa_itnim_online(struct bfa_itnim_s *itnim, bfa_boolean_t seq_rec)
1434{
1435 itnim->seq_rec = seq_rec;
1436 bfa_stats(itnim, onlines);
1437 bfa_sm_send_event(itnim, BFA_ITNIM_SM_ONLINE);
1438}
1439
1440void
1441bfa_itnim_offline(struct bfa_itnim_s *itnim)
1442{
1443 bfa_stats(itnim, offlines);
1444 bfa_sm_send_event(itnim, BFA_ITNIM_SM_OFFLINE);
1445}
1446
Jing Huang5fbe25c2010-10-18 17:17:23 -07001447/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001448 * Return true if itnim is considered offline for holding off IO request.
1449 * IO is not held if itnim is being deleted.
1450 */
1451bfa_boolean_t
1452bfa_itnim_hold_io(struct bfa_itnim_s *itnim)
1453{
1454 return itnim->fcpim->path_tov && itnim->iotov_active &&
1455 (bfa_sm_cmp_state(itnim, bfa_itnim_sm_fwcreate) ||
1456 bfa_sm_cmp_state(itnim, bfa_itnim_sm_sler) ||
1457 bfa_sm_cmp_state(itnim, bfa_itnim_sm_cleanup_offline) ||
1458 bfa_sm_cmp_state(itnim, bfa_itnim_sm_fwdelete) ||
1459 bfa_sm_cmp_state(itnim, bfa_itnim_sm_offline) ||
1460 bfa_sm_cmp_state(itnim, bfa_itnim_sm_iocdisable));
1461}
1462
Krishna Gudipati42a8e6e2011-07-20 17:01:52 -07001463#define bfa_io_lat_clock_res_div HZ
1464#define bfa_io_lat_clock_res_mul 1000
1465bfa_status_t
1466bfa_itnim_get_ioprofile(struct bfa_itnim_s *itnim,
1467 struct bfa_itnim_ioprofile_s *ioprofile)
1468{
Krishna Gudipati61ba4392012-08-22 19:52:58 -07001469 struct bfa_fcpim_s *fcpim;
1470
1471 if (!itnim)
1472 return BFA_STATUS_NO_FCPIM_NEXUS;
1473
1474 fcpim = BFA_FCPIM(itnim->bfa);
1475
Krishna Gudipati42a8e6e2011-07-20 17:01:52 -07001476 if (!fcpim->io_profile)
1477 return BFA_STATUS_IOPROFILE_OFF;
1478
1479 itnim->ioprofile.index = BFA_IOBUCKET_MAX;
1480 itnim->ioprofile.io_profile_start_time =
1481 bfa_io_profile_start_time(itnim->bfa);
1482 itnim->ioprofile.clock_res_mul = bfa_io_lat_clock_res_mul;
1483 itnim->ioprofile.clock_res_div = bfa_io_lat_clock_res_div;
1484 *ioprofile = itnim->ioprofile;
1485
1486 return BFA_STATUS_OK;
1487}
1488
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001489void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001490bfa_itnim_clear_stats(struct bfa_itnim_s *itnim)
1491{
1492 int j;
Krishna Gudipati61ba4392012-08-22 19:52:58 -07001493
1494 if (!itnim)
1495 return;
1496
Jing Huang6a18b162010-10-18 17:08:54 -07001497 memset(&itnim->stats, 0, sizeof(itnim->stats));
1498 memset(&itnim->ioprofile, 0, sizeof(itnim->ioprofile));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001499 for (j = 0; j < BFA_IOBUCKET_MAX; j++)
1500 itnim->ioprofile.io_latency.min[j] = ~0;
1501}
1502
Jing Huang5fbe25c2010-10-18 17:17:23 -07001503/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001504 * BFA IO module state machine functions
1505 */
1506
Jing Huang5fbe25c2010-10-18 17:17:23 -07001507/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08001508 * IO is not started (unallocated).
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001509 */
1510static void
1511bfa_ioim_sm_uninit(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1512{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001513 switch (event) {
1514 case BFA_IOIM_SM_START:
1515 if (!bfa_itnim_is_online(ioim->itnim)) {
1516 if (!bfa_itnim_hold_io(ioim->itnim)) {
1517 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1518 list_del(&ioim->qe);
1519 list_add_tail(&ioim->qe,
1520 &ioim->fcpim->ioim_comp_q);
1521 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe,
1522 __bfa_cb_ioim_pathtov, ioim);
1523 } else {
1524 list_del(&ioim->qe);
1525 list_add_tail(&ioim->qe,
1526 &ioim->itnim->pending_q);
1527 }
1528 break;
1529 }
1530
1531 if (ioim->nsges > BFI_SGE_INLINE) {
Maggie Zhange3e7d3e2010-12-09 19:10:27 -08001532 if (!bfa_ioim_sgpg_alloc(ioim)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001533 bfa_sm_set_state(ioim, bfa_ioim_sm_sgalloc);
1534 return;
1535 }
1536 }
1537
1538 if (!bfa_ioim_send_ioreq(ioim)) {
1539 bfa_sm_set_state(ioim, bfa_ioim_sm_qfull);
1540 break;
1541 }
1542
1543 bfa_sm_set_state(ioim, bfa_ioim_sm_active);
1544 break;
1545
1546 case BFA_IOIM_SM_IOTOV:
1547 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1548 bfa_ioim_move_to_comp_q(ioim);
1549 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe,
1550 __bfa_cb_ioim_pathtov, ioim);
1551 break;
1552
1553 case BFA_IOIM_SM_ABORT:
Jing Huang5fbe25c2010-10-18 17:17:23 -07001554 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001555 * IO in pending queue can get abort requests. Complete abort
1556 * requests immediately.
1557 */
1558 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
Jing Huangd4b671c2010-12-26 21:46:35 -08001559 WARN_ON(!bfa_q_is_on_q(&ioim->itnim->pending_q, ioim));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001560 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe,
Krishna Gudipati83763d52011-07-20 17:04:03 -07001561 __bfa_cb_ioim_abort, ioim);
1562 break;
1563
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001564 default:
1565 bfa_sm_fault(ioim->bfa, event);
1566 }
1567}
1568
Jing Huang5fbe25c2010-10-18 17:17:23 -07001569/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08001570 * IO is waiting for SG pages.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001571 */
1572static void
1573bfa_ioim_sm_sgalloc(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1574{
1575 bfa_trc(ioim->bfa, ioim->iotag);
1576 bfa_trc(ioim->bfa, event);
1577
1578 switch (event) {
1579 case BFA_IOIM_SM_SGALLOCED:
1580 if (!bfa_ioim_send_ioreq(ioim)) {
1581 bfa_sm_set_state(ioim, bfa_ioim_sm_qfull);
1582 break;
1583 }
1584 bfa_sm_set_state(ioim, bfa_ioim_sm_active);
1585 break;
1586
1587 case BFA_IOIM_SM_CLEANUP:
1588 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1589 bfa_sgpg_wcancel(ioim->bfa, &ioim->iosp->sgpg_wqe);
1590 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_failed,
1591 ioim);
1592 bfa_ioim_notify_cleanup(ioim);
1593 break;
1594
1595 case BFA_IOIM_SM_ABORT:
1596 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1597 bfa_sgpg_wcancel(ioim->bfa, &ioim->iosp->sgpg_wqe);
1598 bfa_ioim_move_to_comp_q(ioim);
1599 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_abort,
1600 ioim);
1601 break;
1602
1603 case BFA_IOIM_SM_HWFAIL:
1604 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1605 bfa_sgpg_wcancel(ioim->bfa, &ioim->iosp->sgpg_wqe);
1606 bfa_ioim_move_to_comp_q(ioim);
1607 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_failed,
1608 ioim);
1609 break;
1610
1611 default:
1612 bfa_sm_fault(ioim->bfa, event);
1613 }
1614}
1615
Jing Huang5fbe25c2010-10-18 17:17:23 -07001616/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08001617 * IO is active.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001618 */
1619static void
1620bfa_ioim_sm_active(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1621{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001622 switch (event) {
1623 case BFA_IOIM_SM_COMP_GOOD:
1624 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1625 bfa_ioim_move_to_comp_q(ioim);
1626 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe,
1627 __bfa_cb_ioim_good_comp, ioim);
1628 break;
1629
1630 case BFA_IOIM_SM_COMP:
1631 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1632 bfa_ioim_move_to_comp_q(ioim);
1633 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_comp,
1634 ioim);
1635 break;
1636
1637 case BFA_IOIM_SM_DONE:
1638 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb_free);
1639 bfa_ioim_move_to_comp_q(ioim);
1640 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_comp,
1641 ioim);
1642 break;
1643
1644 case BFA_IOIM_SM_ABORT:
1645 ioim->iosp->abort_explicit = BFA_TRUE;
1646 ioim->io_cbfn = __bfa_cb_ioim_abort;
1647
1648 if (bfa_ioim_send_abort(ioim))
1649 bfa_sm_set_state(ioim, bfa_ioim_sm_abort);
1650 else {
1651 bfa_sm_set_state(ioim, bfa_ioim_sm_abort_qfull);
1652 bfa_stats(ioim->itnim, qwait);
1653 bfa_reqq_wait(ioim->bfa, ioim->reqq,
1654 &ioim->iosp->reqq_wait);
1655 }
1656 break;
1657
1658 case BFA_IOIM_SM_CLEANUP:
1659 ioim->iosp->abort_explicit = BFA_FALSE;
1660 ioim->io_cbfn = __bfa_cb_ioim_failed;
1661
1662 if (bfa_ioim_send_abort(ioim))
1663 bfa_sm_set_state(ioim, bfa_ioim_sm_cleanup);
1664 else {
1665 bfa_sm_set_state(ioim, bfa_ioim_sm_cleanup_qfull);
1666 bfa_stats(ioim->itnim, qwait);
1667 bfa_reqq_wait(ioim->bfa, ioim->reqq,
1668 &ioim->iosp->reqq_wait);
1669 }
1670 break;
1671
1672 case BFA_IOIM_SM_HWFAIL:
1673 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1674 bfa_ioim_move_to_comp_q(ioim);
1675 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_failed,
1676 ioim);
1677 break;
1678
1679 case BFA_IOIM_SM_SQRETRY:
Krishna Gudipati15821f02010-12-13 16:23:27 -08001680 if (bfa_ioim_maxretry_reached(ioim)) {
1681 /* max retry reached, free IO */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001682 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb_free);
1683 bfa_ioim_move_to_comp_q(ioim);
1684 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe,
1685 __bfa_cb_ioim_failed, ioim);
1686 break;
1687 }
1688 /* waiting for IO tag resource free */
1689 bfa_sm_set_state(ioim, bfa_ioim_sm_cmnd_retry);
1690 break;
1691
1692 default:
1693 bfa_sm_fault(ioim->bfa, event);
1694 }
1695}
1696
Jing Huang5fbe25c2010-10-18 17:17:23 -07001697/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08001698 * IO is retried with new tag.
1699 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001700static void
1701bfa_ioim_sm_cmnd_retry(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1702{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001703 switch (event) {
1704 case BFA_IOIM_SM_FREE:
1705 /* abts and rrq done. Now retry the IO with new tag */
Krishna Gudipati15821f02010-12-13 16:23:27 -08001706 bfa_ioim_update_iotag(ioim);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001707 if (!bfa_ioim_send_ioreq(ioim)) {
1708 bfa_sm_set_state(ioim, bfa_ioim_sm_qfull);
1709 break;
1710 }
1711 bfa_sm_set_state(ioim, bfa_ioim_sm_active);
1712 break;
1713
1714 case BFA_IOIM_SM_CLEANUP:
1715 ioim->iosp->abort_explicit = BFA_FALSE;
1716 ioim->io_cbfn = __bfa_cb_ioim_failed;
1717
1718 if (bfa_ioim_send_abort(ioim))
1719 bfa_sm_set_state(ioim, bfa_ioim_sm_cleanup);
1720 else {
1721 bfa_sm_set_state(ioim, bfa_ioim_sm_cleanup_qfull);
1722 bfa_stats(ioim->itnim, qwait);
1723 bfa_reqq_wait(ioim->bfa, ioim->reqq,
1724 &ioim->iosp->reqq_wait);
1725 }
1726 break;
1727
1728 case BFA_IOIM_SM_HWFAIL:
1729 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1730 bfa_ioim_move_to_comp_q(ioim);
1731 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe,
1732 __bfa_cb_ioim_failed, ioim);
1733 break;
1734
1735 case BFA_IOIM_SM_ABORT:
Jing Huang5fbe25c2010-10-18 17:17:23 -07001736 /* in this state IO abort is done.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001737 * Waiting for IO tag resource free.
1738 */
1739 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb_free);
1740 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_abort,
1741 ioim);
1742 break;
1743
1744 default:
1745 bfa_sm_fault(ioim->bfa, event);
1746 }
1747}
1748
Jing Huang5fbe25c2010-10-18 17:17:23 -07001749/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08001750 * IO is being aborted, waiting for completion from firmware.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001751 */
1752static void
1753bfa_ioim_sm_abort(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1754{
1755 bfa_trc(ioim->bfa, ioim->iotag);
1756 bfa_trc(ioim->bfa, event);
1757
1758 switch (event) {
1759 case BFA_IOIM_SM_COMP_GOOD:
1760 case BFA_IOIM_SM_COMP:
1761 case BFA_IOIM_SM_DONE:
1762 case BFA_IOIM_SM_FREE:
1763 break;
1764
1765 case BFA_IOIM_SM_ABORT_DONE:
1766 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb_free);
1767 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_abort,
1768 ioim);
1769 break;
1770
1771 case BFA_IOIM_SM_ABORT_COMP:
1772 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1773 bfa_ioim_move_to_comp_q(ioim);
1774 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_abort,
1775 ioim);
1776 break;
1777
1778 case BFA_IOIM_SM_COMP_UTAG:
1779 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1780 bfa_ioim_move_to_comp_q(ioim);
1781 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_abort,
1782 ioim);
1783 break;
1784
1785 case BFA_IOIM_SM_CLEANUP:
Jing Huangd4b671c2010-12-26 21:46:35 -08001786 WARN_ON(ioim->iosp->abort_explicit != BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001787 ioim->iosp->abort_explicit = BFA_FALSE;
1788
1789 if (bfa_ioim_send_abort(ioim))
1790 bfa_sm_set_state(ioim, bfa_ioim_sm_cleanup);
1791 else {
1792 bfa_sm_set_state(ioim, bfa_ioim_sm_cleanup_qfull);
1793 bfa_stats(ioim->itnim, qwait);
1794 bfa_reqq_wait(ioim->bfa, ioim->reqq,
1795 &ioim->iosp->reqq_wait);
1796 }
1797 break;
1798
1799 case BFA_IOIM_SM_HWFAIL:
1800 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1801 bfa_ioim_move_to_comp_q(ioim);
1802 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_failed,
1803 ioim);
1804 break;
1805
1806 default:
1807 bfa_sm_fault(ioim->bfa, event);
1808 }
1809}
1810
Jing Huang5fbe25c2010-10-18 17:17:23 -07001811/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001812 * IO is being cleaned up (implicit abort), waiting for completion from
1813 * firmware.
1814 */
1815static void
1816bfa_ioim_sm_cleanup(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1817{
1818 bfa_trc(ioim->bfa, ioim->iotag);
1819 bfa_trc(ioim->bfa, event);
1820
1821 switch (event) {
1822 case BFA_IOIM_SM_COMP_GOOD:
1823 case BFA_IOIM_SM_COMP:
1824 case BFA_IOIM_SM_DONE:
1825 case BFA_IOIM_SM_FREE:
1826 break;
1827
1828 case BFA_IOIM_SM_ABORT:
Jing Huang5fbe25c2010-10-18 17:17:23 -07001829 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001830 * IO is already being aborted implicitly
1831 */
1832 ioim->io_cbfn = __bfa_cb_ioim_abort;
1833 break;
1834
1835 case BFA_IOIM_SM_ABORT_DONE:
1836 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb_free);
1837 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, ioim->io_cbfn, ioim);
1838 bfa_ioim_notify_cleanup(ioim);
1839 break;
1840
1841 case BFA_IOIM_SM_ABORT_COMP:
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;
1846
1847 case BFA_IOIM_SM_COMP_UTAG:
1848 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1849 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, ioim->io_cbfn, ioim);
1850 bfa_ioim_notify_cleanup(ioim);
1851 break;
1852
1853 case BFA_IOIM_SM_HWFAIL:
1854 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1855 bfa_ioim_move_to_comp_q(ioim);
1856 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_failed,
1857 ioim);
1858 break;
1859
1860 case BFA_IOIM_SM_CLEANUP:
Jing Huang5fbe25c2010-10-18 17:17:23 -07001861 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001862 * IO can be in cleanup state already due to TM command.
1863 * 2nd cleanup request comes from ITN offline event.
1864 */
1865 break;
1866
1867 default:
1868 bfa_sm_fault(ioim->bfa, event);
1869 }
1870}
1871
Jing Huang5fbe25c2010-10-18 17:17:23 -07001872/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08001873 * IO is waiting for room in request CQ
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001874 */
1875static void
1876bfa_ioim_sm_qfull(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1877{
1878 bfa_trc(ioim->bfa, ioim->iotag);
1879 bfa_trc(ioim->bfa, event);
1880
1881 switch (event) {
1882 case BFA_IOIM_SM_QRESUME:
1883 bfa_sm_set_state(ioim, bfa_ioim_sm_active);
1884 bfa_ioim_send_ioreq(ioim);
1885 break;
1886
1887 case BFA_IOIM_SM_ABORT:
1888 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1889 bfa_reqq_wcancel(&ioim->iosp->reqq_wait);
1890 bfa_ioim_move_to_comp_q(ioim);
1891 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_abort,
1892 ioim);
1893 break;
1894
1895 case BFA_IOIM_SM_CLEANUP:
1896 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1897 bfa_reqq_wcancel(&ioim->iosp->reqq_wait);
1898 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_failed,
1899 ioim);
1900 bfa_ioim_notify_cleanup(ioim);
1901 break;
1902
1903 case BFA_IOIM_SM_HWFAIL:
1904 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1905 bfa_reqq_wcancel(&ioim->iosp->reqq_wait);
1906 bfa_ioim_move_to_comp_q(ioim);
1907 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_failed,
1908 ioim);
1909 break;
1910
1911 default:
1912 bfa_sm_fault(ioim->bfa, event);
1913 }
1914}
1915
Jing Huang5fbe25c2010-10-18 17:17:23 -07001916/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08001917 * Active IO is being aborted, waiting for room in request CQ.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001918 */
1919static void
1920bfa_ioim_sm_abort_qfull(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1921{
1922 bfa_trc(ioim->bfa, ioim->iotag);
1923 bfa_trc(ioim->bfa, event);
1924
1925 switch (event) {
1926 case BFA_IOIM_SM_QRESUME:
1927 bfa_sm_set_state(ioim, bfa_ioim_sm_abort);
1928 bfa_ioim_send_abort(ioim);
1929 break;
1930
1931 case BFA_IOIM_SM_CLEANUP:
Jing Huangd4b671c2010-12-26 21:46:35 -08001932 WARN_ON(ioim->iosp->abort_explicit != BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001933 ioim->iosp->abort_explicit = BFA_FALSE;
1934 bfa_sm_set_state(ioim, bfa_ioim_sm_cleanup_qfull);
1935 break;
1936
1937 case BFA_IOIM_SM_COMP_GOOD:
1938 case BFA_IOIM_SM_COMP:
1939 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1940 bfa_reqq_wcancel(&ioim->iosp->reqq_wait);
1941 bfa_ioim_move_to_comp_q(ioim);
1942 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_abort,
1943 ioim);
1944 break;
1945
1946 case BFA_IOIM_SM_DONE:
1947 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb_free);
1948 bfa_reqq_wcancel(&ioim->iosp->reqq_wait);
1949 bfa_ioim_move_to_comp_q(ioim);
1950 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_abort,
1951 ioim);
1952 break;
1953
1954 case BFA_IOIM_SM_HWFAIL:
1955 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1956 bfa_reqq_wcancel(&ioim->iosp->reqq_wait);
1957 bfa_ioim_move_to_comp_q(ioim);
1958 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_failed,
1959 ioim);
1960 break;
1961
1962 default:
1963 bfa_sm_fault(ioim->bfa, event);
1964 }
1965}
1966
Jing Huang5fbe25c2010-10-18 17:17:23 -07001967/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08001968 * Active IO is being cleaned up, waiting for room in request CQ.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001969 */
1970static void
1971bfa_ioim_sm_cleanup_qfull(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
1972{
1973 bfa_trc(ioim->bfa, ioim->iotag);
1974 bfa_trc(ioim->bfa, event);
1975
1976 switch (event) {
1977 case BFA_IOIM_SM_QRESUME:
1978 bfa_sm_set_state(ioim, bfa_ioim_sm_cleanup);
1979 bfa_ioim_send_abort(ioim);
1980 break;
1981
1982 case BFA_IOIM_SM_ABORT:
Jing Huang5fbe25c2010-10-18 17:17:23 -07001983 /*
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001984 * IO is already being cleaned up implicitly
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001985 */
1986 ioim->io_cbfn = __bfa_cb_ioim_abort;
1987 break;
1988
1989 case BFA_IOIM_SM_COMP_GOOD:
1990 case BFA_IOIM_SM_COMP:
1991 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
1992 bfa_reqq_wcancel(&ioim->iosp->reqq_wait);
1993 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, ioim->io_cbfn, ioim);
1994 bfa_ioim_notify_cleanup(ioim);
1995 break;
1996
1997 case BFA_IOIM_SM_DONE:
1998 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb_free);
1999 bfa_reqq_wcancel(&ioim->iosp->reqq_wait);
2000 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, ioim->io_cbfn, ioim);
2001 bfa_ioim_notify_cleanup(ioim);
2002 break;
2003
2004 case BFA_IOIM_SM_HWFAIL:
2005 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
2006 bfa_reqq_wcancel(&ioim->iosp->reqq_wait);
2007 bfa_ioim_move_to_comp_q(ioim);
2008 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, __bfa_cb_ioim_failed,
2009 ioim);
2010 break;
2011
2012 default:
2013 bfa_sm_fault(ioim->bfa, event);
2014 }
2015}
2016
Jing Huang5fbe25c2010-10-18 17:17:23 -07002017/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002018 * IO bfa callback is pending.
2019 */
2020static void
2021bfa_ioim_sm_hcb(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
2022{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002023 switch (event) {
2024 case BFA_IOIM_SM_HCB:
2025 bfa_sm_set_state(ioim, bfa_ioim_sm_uninit);
2026 bfa_ioim_free(ioim);
2027 break;
2028
2029 case BFA_IOIM_SM_CLEANUP:
2030 bfa_ioim_notify_cleanup(ioim);
2031 break;
2032
2033 case BFA_IOIM_SM_HWFAIL:
2034 break;
2035
2036 default:
2037 bfa_sm_fault(ioim->bfa, event);
2038 }
2039}
2040
Jing Huang5fbe25c2010-10-18 17:17:23 -07002041/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002042 * IO bfa callback is pending. IO resource cannot be freed.
2043 */
2044static void
2045bfa_ioim_sm_hcb_free(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
2046{
2047 bfa_trc(ioim->bfa, ioim->iotag);
2048 bfa_trc(ioim->bfa, event);
2049
2050 switch (event) {
2051 case BFA_IOIM_SM_HCB:
2052 bfa_sm_set_state(ioim, bfa_ioim_sm_resfree);
2053 list_del(&ioim->qe);
2054 list_add_tail(&ioim->qe, &ioim->fcpim->ioim_resfree_q);
2055 break;
2056
2057 case BFA_IOIM_SM_FREE:
2058 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
2059 break;
2060
2061 case BFA_IOIM_SM_CLEANUP:
2062 bfa_ioim_notify_cleanup(ioim);
2063 break;
2064
2065 case BFA_IOIM_SM_HWFAIL:
2066 bfa_sm_set_state(ioim, bfa_ioim_sm_hcb);
2067 break;
2068
2069 default:
2070 bfa_sm_fault(ioim->bfa, event);
2071 }
2072}
2073
Jing Huang5fbe25c2010-10-18 17:17:23 -07002074/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002075 * IO is completed, waiting resource free from firmware.
2076 */
2077static void
2078bfa_ioim_sm_resfree(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
2079{
2080 bfa_trc(ioim->bfa, ioim->iotag);
2081 bfa_trc(ioim->bfa, event);
2082
2083 switch (event) {
2084 case BFA_IOIM_SM_FREE:
2085 bfa_sm_set_state(ioim, bfa_ioim_sm_uninit);
2086 bfa_ioim_free(ioim);
2087 break;
2088
2089 case BFA_IOIM_SM_CLEANUP:
2090 bfa_ioim_notify_cleanup(ioim);
2091 break;
2092
2093 case BFA_IOIM_SM_HWFAIL:
2094 break;
2095
2096 default:
2097 bfa_sm_fault(ioim->bfa, event);
2098 }
2099}
2100
Krishna Gudipati83763d52011-07-20 17:04:03 -07002101/*
2102 * This is called from bfa_fcpim_start after the bfa_init() with flash read
2103 * is complete by driver. now invalidate the stale content of lun mask
2104 * like unit attention, rp tag and lp tag.
2105 */
2106static void
2107bfa_ioim_lm_init(struct bfa_s *bfa)
2108{
2109 struct bfa_lun_mask_s *lunm_list;
2110 int i;
2111
2112 if (bfa_get_lun_mask_status(bfa) == BFA_LUNMASK_MINCFG)
2113 return;
2114
2115 lunm_list = bfa_get_lun_mask_list(bfa);
2116 for (i = 0; i < MAX_LUN_MASK_CFG; i++) {
2117 lunm_list[i].ua = BFA_IOIM_LM_UA_RESET;
2118 lunm_list[i].lp_tag = BFA_LP_TAG_INVALID;
2119 lunm_list[i].rp_tag = BFA_RPORT_TAG_INVALID;
2120 }
2121}
2122
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002123static void
2124__bfa_cb_ioim_good_comp(void *cbarg, bfa_boolean_t complete)
2125{
2126 struct bfa_ioim_s *ioim = cbarg;
2127
2128 if (!complete) {
2129 bfa_sm_send_event(ioim, BFA_IOIM_SM_HCB);
2130 return;
2131 }
2132
2133 bfa_cb_ioim_good_comp(ioim->bfa->bfad, ioim->dio);
2134}
2135
2136static void
2137__bfa_cb_ioim_comp(void *cbarg, bfa_boolean_t complete)
2138{
2139 struct bfa_ioim_s *ioim = cbarg;
2140 struct bfi_ioim_rsp_s *m;
2141 u8 *snsinfo = NULL;
2142 u8 sns_len = 0;
2143 s32 residue = 0;
2144
2145 if (!complete) {
2146 bfa_sm_send_event(ioim, BFA_IOIM_SM_HCB);
2147 return;
2148 }
2149
2150 m = (struct bfi_ioim_rsp_s *) &ioim->iosp->comp_rspmsg;
2151 if (m->io_status == BFI_IOIM_STS_OK) {
Jing Huang5fbe25c2010-10-18 17:17:23 -07002152 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002153 * setup sense information, if present
2154 */
2155 if ((m->scsi_status == SCSI_STATUS_CHECK_CONDITION) &&
2156 m->sns_len) {
2157 sns_len = m->sns_len;
Krishna Gudipatie2187d72011-06-13 15:53:58 -07002158 snsinfo = BFA_SNSINFO_FROM_TAG(ioim->fcpim->fcp,
2159 ioim->iotag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002160 }
2161
Jing Huang5fbe25c2010-10-18 17:17:23 -07002162 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002163 * setup residue value correctly for normal completions
2164 */
2165 if (m->resid_flags == FCP_RESID_UNDER) {
Jing Huangba816ea2010-10-18 17:10:50 -07002166 residue = be32_to_cpu(m->residue);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002167 bfa_stats(ioim->itnim, iocomp_underrun);
2168 }
2169 if (m->resid_flags == FCP_RESID_OVER) {
Jing Huangba816ea2010-10-18 17:10:50 -07002170 residue = be32_to_cpu(m->residue);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002171 residue = -residue;
2172 bfa_stats(ioim->itnim, iocomp_overrun);
2173 }
2174 }
2175
2176 bfa_cb_ioim_done(ioim->bfa->bfad, ioim->dio, m->io_status,
2177 m->scsi_status, sns_len, snsinfo, residue);
2178}
2179
Krishna Gudipati83763d52011-07-20 17:04:03 -07002180void
2181bfa_fcpim_lunmask_rp_update(struct bfa_s *bfa, wwn_t lp_wwn, wwn_t rp_wwn,
2182 u16 rp_tag, u8 lp_tag)
2183{
2184 struct bfa_lun_mask_s *lun_list;
2185 u8 i;
2186
2187 if (bfa_get_lun_mask_status(bfa) == BFA_LUNMASK_MINCFG)
2188 return;
2189
2190 lun_list = bfa_get_lun_mask_list(bfa);
2191 for (i = 0; i < MAX_LUN_MASK_CFG; i++) {
2192 if (lun_list[i].state == BFA_IOIM_LUN_MASK_ACTIVE) {
2193 if ((lun_list[i].lp_wwn == lp_wwn) &&
2194 (lun_list[i].rp_wwn == rp_wwn)) {
2195 lun_list[i].rp_tag = rp_tag;
2196 lun_list[i].lp_tag = lp_tag;
2197 }
2198 }
2199 }
2200}
2201
Krishna Gudipati4c5d22b2011-07-20 17:04:24 -07002202/*
2203 * set UA for all active luns in LM DB
2204 */
2205static void
2206bfa_ioim_lm_set_ua(struct bfa_s *bfa)
2207{
2208 struct bfa_lun_mask_s *lunm_list;
2209 int i;
2210
2211 lunm_list = bfa_get_lun_mask_list(bfa);
2212 for (i = 0; i < MAX_LUN_MASK_CFG; i++) {
2213 if (lunm_list[i].state != BFA_IOIM_LUN_MASK_ACTIVE)
2214 continue;
2215 lunm_list[i].ua = BFA_IOIM_LM_UA_SET;
2216 }
2217}
2218
2219bfa_status_t
2220bfa_fcpim_lunmask_update(struct bfa_s *bfa, u32 update)
2221{
2222 struct bfa_lunmask_cfg_s *lun_mask;
2223
2224 bfa_trc(bfa, bfa_get_lun_mask_status(bfa));
2225 if (bfa_get_lun_mask_status(bfa) == BFA_LUNMASK_MINCFG)
2226 return BFA_STATUS_FAILED;
2227
2228 if (bfa_get_lun_mask_status(bfa) == update)
2229 return BFA_STATUS_NO_CHANGE;
2230
2231 lun_mask = bfa_get_lun_mask(bfa);
2232 lun_mask->status = update;
2233
2234 if (bfa_get_lun_mask_status(bfa) == BFA_LUNMASK_ENABLED)
2235 bfa_ioim_lm_set_ua(bfa);
2236
2237 return bfa_dconf_update(bfa);
2238}
2239
2240bfa_status_t
2241bfa_fcpim_lunmask_clear(struct bfa_s *bfa)
2242{
2243 int i;
2244 struct bfa_lun_mask_s *lunm_list;
2245
2246 bfa_trc(bfa, bfa_get_lun_mask_status(bfa));
2247 if (bfa_get_lun_mask_status(bfa) == BFA_LUNMASK_MINCFG)
2248 return BFA_STATUS_FAILED;
2249
2250 lunm_list = bfa_get_lun_mask_list(bfa);
2251 for (i = 0; i < MAX_LUN_MASK_CFG; i++) {
2252 if (lunm_list[i].state == BFA_IOIM_LUN_MASK_ACTIVE) {
2253 if (lunm_list[i].rp_tag != BFA_RPORT_TAG_INVALID)
2254 bfa_rport_unset_lunmask(bfa,
2255 BFA_RPORT_FROM_TAG(bfa, lunm_list[i].rp_tag));
2256 }
2257 }
2258
2259 memset(lunm_list, 0, sizeof(struct bfa_lun_mask_s) * MAX_LUN_MASK_CFG);
2260 return bfa_dconf_update(bfa);
2261}
2262
2263bfa_status_t
2264bfa_fcpim_lunmask_query(struct bfa_s *bfa, void *buf)
2265{
2266 struct bfa_lunmask_cfg_s *lun_mask;
2267
2268 bfa_trc(bfa, bfa_get_lun_mask_status(bfa));
2269 if (bfa_get_lun_mask_status(bfa) == BFA_LUNMASK_MINCFG)
2270 return BFA_STATUS_FAILED;
2271
2272 lun_mask = bfa_get_lun_mask(bfa);
2273 memcpy(buf, lun_mask, sizeof(struct bfa_lunmask_cfg_s));
2274 return BFA_STATUS_OK;
2275}
2276
2277bfa_status_t
2278bfa_fcpim_lunmask_add(struct bfa_s *bfa, u16 vf_id, wwn_t *pwwn,
2279 wwn_t rpwwn, struct scsi_lun lun)
2280{
2281 struct bfa_lun_mask_s *lunm_list;
2282 struct bfa_rport_s *rp = NULL;
2283 int i, free_index = MAX_LUN_MASK_CFG + 1;
2284 struct bfa_fcs_lport_s *port = NULL;
2285 struct bfa_fcs_rport_s *rp_fcs;
2286
2287 bfa_trc(bfa, bfa_get_lun_mask_status(bfa));
2288 if (bfa_get_lun_mask_status(bfa) == BFA_LUNMASK_MINCFG)
2289 return BFA_STATUS_FAILED;
2290
2291 port = bfa_fcs_lookup_port(&((struct bfad_s *)bfa->bfad)->bfa_fcs,
2292 vf_id, *pwwn);
2293 if (port) {
2294 *pwwn = port->port_cfg.pwwn;
2295 rp_fcs = bfa_fcs_lport_get_rport_by_pwwn(port, rpwwn);
Krishna Gudipati6bc62042011-12-20 18:54:30 -08002296 if (rp_fcs)
2297 rp = rp_fcs->bfa_rport;
Krishna Gudipati4c5d22b2011-07-20 17:04:24 -07002298 }
2299
2300 lunm_list = bfa_get_lun_mask_list(bfa);
2301 /* if entry exists */
2302 for (i = 0; i < MAX_LUN_MASK_CFG; i++) {
2303 if (lunm_list[i].state != BFA_IOIM_LUN_MASK_ACTIVE)
2304 free_index = i;
2305 if ((lunm_list[i].lp_wwn == *pwwn) &&
2306 (lunm_list[i].rp_wwn == rpwwn) &&
2307 (scsilun_to_int((struct scsi_lun *)&lunm_list[i].lun) ==
2308 scsilun_to_int((struct scsi_lun *)&lun)))
2309 return BFA_STATUS_ENTRY_EXISTS;
2310 }
2311
2312 if (free_index > MAX_LUN_MASK_CFG)
2313 return BFA_STATUS_MAX_ENTRY_REACHED;
2314
2315 if (rp) {
2316 lunm_list[free_index].lp_tag = bfa_lps_get_tag_from_pid(bfa,
2317 rp->rport_info.local_pid);
2318 lunm_list[free_index].rp_tag = rp->rport_tag;
2319 } else {
2320 lunm_list[free_index].lp_tag = BFA_LP_TAG_INVALID;
2321 lunm_list[free_index].rp_tag = BFA_RPORT_TAG_INVALID;
2322 }
2323
2324 lunm_list[free_index].lp_wwn = *pwwn;
2325 lunm_list[free_index].rp_wwn = rpwwn;
2326 lunm_list[free_index].lun = lun;
2327 lunm_list[free_index].state = BFA_IOIM_LUN_MASK_ACTIVE;
2328
2329 /* set for all luns in this rp */
2330 for (i = 0; i < MAX_LUN_MASK_CFG; i++) {
2331 if ((lunm_list[i].lp_wwn == *pwwn) &&
2332 (lunm_list[i].rp_wwn == rpwwn))
2333 lunm_list[i].ua = BFA_IOIM_LM_UA_SET;
2334 }
2335
2336 return bfa_dconf_update(bfa);
2337}
2338
2339bfa_status_t
2340bfa_fcpim_lunmask_delete(struct bfa_s *bfa, u16 vf_id, wwn_t *pwwn,
2341 wwn_t rpwwn, struct scsi_lun lun)
2342{
2343 struct bfa_lun_mask_s *lunm_list;
2344 struct bfa_rport_s *rp = NULL;
2345 struct bfa_fcs_lport_s *port = NULL;
2346 struct bfa_fcs_rport_s *rp_fcs;
2347 int i;
2348
2349 /* in min cfg lunm_list could be NULL but no commands should run. */
2350 if (bfa_get_lun_mask_status(bfa) == BFA_LUNMASK_MINCFG)
2351 return BFA_STATUS_FAILED;
2352
2353 bfa_trc(bfa, bfa_get_lun_mask_status(bfa));
2354 bfa_trc(bfa, *pwwn);
2355 bfa_trc(bfa, rpwwn);
2356 bfa_trc(bfa, scsilun_to_int((struct scsi_lun *)&lun));
2357
2358 if (*pwwn == 0) {
2359 port = bfa_fcs_lookup_port(
2360 &((struct bfad_s *)bfa->bfad)->bfa_fcs,
2361 vf_id, *pwwn);
2362 if (port) {
2363 *pwwn = port->port_cfg.pwwn;
2364 rp_fcs = bfa_fcs_lport_get_rport_by_pwwn(port, rpwwn);
Krishna Gudipati6bc62042011-12-20 18:54:30 -08002365 if (rp_fcs)
2366 rp = rp_fcs->bfa_rport;
Krishna Gudipati4c5d22b2011-07-20 17:04:24 -07002367 }
2368 }
2369
2370 lunm_list = bfa_get_lun_mask_list(bfa);
2371 for (i = 0; i < MAX_LUN_MASK_CFG; i++) {
2372 if ((lunm_list[i].lp_wwn == *pwwn) &&
2373 (lunm_list[i].rp_wwn == rpwwn) &&
2374 (scsilun_to_int((struct scsi_lun *)&lunm_list[i].lun) ==
2375 scsilun_to_int((struct scsi_lun *)&lun))) {
2376 lunm_list[i].lp_wwn = 0;
2377 lunm_list[i].rp_wwn = 0;
2378 int_to_scsilun(0, &lunm_list[i].lun);
2379 lunm_list[i].state = BFA_IOIM_LUN_MASK_INACTIVE;
2380 if (lunm_list[i].rp_tag != BFA_RPORT_TAG_INVALID) {
2381 lunm_list[i].rp_tag = BFA_RPORT_TAG_INVALID;
2382 lunm_list[i].lp_tag = BFA_LP_TAG_INVALID;
2383 }
2384 return bfa_dconf_update(bfa);
2385 }
2386 }
2387
2388 /* set for all luns in this rp */
2389 for (i = 0; i < MAX_LUN_MASK_CFG; i++) {
2390 if ((lunm_list[i].lp_wwn == *pwwn) &&
2391 (lunm_list[i].rp_wwn == rpwwn))
2392 lunm_list[i].ua = BFA_IOIM_LM_UA_SET;
2393 }
2394
2395 return BFA_STATUS_ENTRY_NOT_EXISTS;
2396}
2397
Krishna Gudipati83763d52011-07-20 17:04:03 -07002398static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002399__bfa_cb_ioim_failed(void *cbarg, bfa_boolean_t complete)
2400{
2401 struct bfa_ioim_s *ioim = cbarg;
2402
2403 if (!complete) {
2404 bfa_sm_send_event(ioim, BFA_IOIM_SM_HCB);
2405 return;
2406 }
2407
2408 bfa_cb_ioim_done(ioim->bfa->bfad, ioim->dio, BFI_IOIM_STS_ABORTED,
2409 0, 0, NULL, 0);
2410}
2411
2412static void
2413__bfa_cb_ioim_pathtov(void *cbarg, bfa_boolean_t complete)
2414{
2415 struct bfa_ioim_s *ioim = cbarg;
2416
2417 bfa_stats(ioim->itnim, path_tov_expired);
2418 if (!complete) {
2419 bfa_sm_send_event(ioim, BFA_IOIM_SM_HCB);
2420 return;
2421 }
2422
2423 bfa_cb_ioim_done(ioim->bfa->bfad, ioim->dio, BFI_IOIM_STS_PATHTOV,
2424 0, 0, NULL, 0);
2425}
2426
2427static void
2428__bfa_cb_ioim_abort(void *cbarg, bfa_boolean_t complete)
2429{
2430 struct bfa_ioim_s *ioim = cbarg;
2431
2432 if (!complete) {
2433 bfa_sm_send_event(ioim, BFA_IOIM_SM_HCB);
2434 return;
2435 }
2436
2437 bfa_cb_ioim_abort(ioim->bfa->bfad, ioim->dio);
2438}
2439
2440static void
2441bfa_ioim_sgpg_alloced(void *cbarg)
2442{
2443 struct bfa_ioim_s *ioim = cbarg;
2444
2445 ioim->nsgpgs = BFA_SGPG_NPAGE(ioim->nsges);
2446 list_splice_tail_init(&ioim->iosp->sgpg_wqe.sgpg_q, &ioim->sgpg_q);
Maggie Zhange3e7d3e2010-12-09 19:10:27 -08002447 ioim->sgpg = bfa_q_first(&ioim->sgpg_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002448 bfa_sm_send_event(ioim, BFA_IOIM_SM_SGALLOCED);
2449}
2450
Jing Huang5fbe25c2010-10-18 17:17:23 -07002451/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002452 * Send I/O request to firmware.
2453 */
2454static bfa_boolean_t
2455bfa_ioim_send_ioreq(struct bfa_ioim_s *ioim)
2456{
2457 struct bfa_itnim_s *itnim = ioim->itnim;
2458 struct bfi_ioim_req_s *m;
Maggie Zhangda99dcc2010-12-09 19:13:20 -08002459 static struct fcp_cmnd_s cmnd_z0 = { { { 0 } } };
Maggie Zhange3e7d3e2010-12-09 19:10:27 -08002460 struct bfi_sge_s *sge, *sgpge;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002461 u32 pgdlen = 0;
2462 u32 fcp_dl;
2463 u64 addr;
2464 struct scatterlist *sg;
Maggie Zhange3e7d3e2010-12-09 19:10:27 -08002465 struct bfa_sgpg_s *sgpg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002466 struct scsi_cmnd *cmnd = (struct scsi_cmnd *) ioim->dio;
Maggie Zhange3e7d3e2010-12-09 19:10:27 -08002467 u32 i, sge_id, pgcumsz;
Maggie Zhangf3148782010-12-09 19:11:39 -08002468 enum dma_data_direction dmadir;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002469
Jing Huang5fbe25c2010-10-18 17:17:23 -07002470 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002471 * check for room in queue to send request now
2472 */
2473 m = bfa_reqq_next(ioim->bfa, ioim->reqq);
2474 if (!m) {
2475 bfa_stats(ioim->itnim, qwait);
2476 bfa_reqq_wait(ioim->bfa, ioim->reqq,
2477 &ioim->iosp->reqq_wait);
2478 return BFA_FALSE;
2479 }
2480
Jing Huang5fbe25c2010-10-18 17:17:23 -07002481 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002482 * build i/o request message next
2483 */
Jing Huangba816ea2010-10-18 17:10:50 -07002484 m->io_tag = cpu_to_be16(ioim->iotag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002485 m->rport_hdl = ioim->itnim->rport->fw_handle;
Maggie Zhangf3148782010-12-09 19:11:39 -08002486 m->io_timeout = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002487
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002488 sge = &m->sges[0];
Maggie Zhange3e7d3e2010-12-09 19:10:27 -08002489 sgpg = ioim->sgpg;
2490 sge_id = 0;
2491 sgpge = NULL;
2492 pgcumsz = 0;
2493 scsi_for_each_sg(cmnd, sg, ioim->nsges, i) {
2494 if (i == 0) {
2495 /* build inline IO SG element */
Maggie Zhangf16a1752010-12-09 19:12:32 -08002496 addr = bfa_sgaddr_le(sg_dma_address(sg));
Maggie Zhange3e7d3e2010-12-09 19:10:27 -08002497 sge->sga = *(union bfi_addr_u *) &addr;
2498 pgdlen = sg_dma_len(sg);
2499 sge->sg_len = pgdlen;
2500 sge->flags = (ioim->nsges > BFI_SGE_INLINE) ?
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002501 BFI_SGE_DATA_CPL : BFI_SGE_DATA_LAST;
Maggie Zhange3e7d3e2010-12-09 19:10:27 -08002502 bfa_sge_to_be(sge);
2503 sge++;
2504 } else {
2505 if (sge_id == 0)
2506 sgpge = sgpg->sgpg->sges;
2507
Maggie Zhangf16a1752010-12-09 19:12:32 -08002508 addr = bfa_sgaddr_le(sg_dma_address(sg));
Maggie Zhange3e7d3e2010-12-09 19:10:27 -08002509 sgpge->sga = *(union bfi_addr_u *) &addr;
2510 sgpge->sg_len = sg_dma_len(sg);
2511 pgcumsz += sgpge->sg_len;
2512
2513 /* set flags */
2514 if (i < (ioim->nsges - 1) &&
2515 sge_id < (BFI_SGPG_DATA_SGES - 1))
2516 sgpge->flags = BFI_SGE_DATA;
2517 else if (i < (ioim->nsges - 1))
2518 sgpge->flags = BFI_SGE_DATA_CPL;
2519 else
2520 sgpge->flags = BFI_SGE_DATA_LAST;
2521
2522 bfa_sge_to_le(sgpge);
2523
2524 sgpge++;
2525 if (i == (ioim->nsges - 1)) {
2526 sgpge->flags = BFI_SGE_PGDLEN;
2527 sgpge->sga.a32.addr_lo = 0;
2528 sgpge->sga.a32.addr_hi = 0;
2529 sgpge->sg_len = pgcumsz;
2530 bfa_sge_to_le(sgpge);
2531 } else if (++sge_id == BFI_SGPG_DATA_SGES) {
2532 sgpg = (struct bfa_sgpg_s *) bfa_q_next(sgpg);
2533 sgpge->flags = BFI_SGE_LINK;
2534 sgpge->sga = sgpg->sgpg_pa;
2535 sgpge->sg_len = pgcumsz;
2536 bfa_sge_to_le(sgpge);
2537 sge_id = 0;
2538 pgcumsz = 0;
2539 }
2540 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002541 }
2542
2543 if (ioim->nsges > BFI_SGE_INLINE) {
2544 sge->sga = ioim->sgpg->sgpg_pa;
2545 } else {
2546 sge->sga.a32.addr_lo = 0;
2547 sge->sga.a32.addr_hi = 0;
2548 }
2549 sge->sg_len = pgdlen;
2550 sge->flags = BFI_SGE_PGDLEN;
2551 bfa_sge_to_be(sge);
2552
Jing Huang5fbe25c2010-10-18 17:17:23 -07002553 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002554 * set up I/O command parameters
2555 */
Jing Huang6a18b162010-10-18 17:08:54 -07002556 m->cmnd = cmnd_z0;
Maggie Zhangf3148782010-12-09 19:11:39 -08002557 int_to_scsilun(cmnd->device->lun, &m->cmnd.lun);
2558 dmadir = cmnd->sc_data_direction;
2559 if (dmadir == DMA_TO_DEVICE)
2560 m->cmnd.iodir = FCP_IODIR_WRITE;
2561 else if (dmadir == DMA_FROM_DEVICE)
2562 m->cmnd.iodir = FCP_IODIR_READ;
2563 else
2564 m->cmnd.iodir = FCP_IODIR_NONE;
2565
Jing Huang8f4bfad2010-12-26 21:50:10 -08002566 m->cmnd.cdb = *(struct scsi_cdb_s *) cmnd->cmnd;
Maggie Zhangf3148782010-12-09 19:11:39 -08002567 fcp_dl = scsi_bufflen(cmnd);
Jing Huangba816ea2010-10-18 17:10:50 -07002568 m->cmnd.fcp_dl = cpu_to_be32(fcp_dl);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002569
Jing Huang5fbe25c2010-10-18 17:17:23 -07002570 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002571 * set up I/O message header
2572 */
2573 switch (m->cmnd.iodir) {
2574 case FCP_IODIR_READ:
Krishna Gudipati3fd45982011-06-24 20:24:08 -07002575 bfi_h2i_set(m->mh, BFI_MC_IOIM_READ, 0, bfa_fn_lpu(ioim->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002576 bfa_stats(itnim, input_reqs);
2577 ioim->itnim->stats.rd_throughput += fcp_dl;
2578 break;
2579 case FCP_IODIR_WRITE:
Krishna Gudipati3fd45982011-06-24 20:24:08 -07002580 bfi_h2i_set(m->mh, BFI_MC_IOIM_WRITE, 0, bfa_fn_lpu(ioim->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002581 bfa_stats(itnim, output_reqs);
2582 ioim->itnim->stats.wr_throughput += fcp_dl;
2583 break;
2584 case FCP_IODIR_RW:
2585 bfa_stats(itnim, input_reqs);
2586 bfa_stats(itnim, output_reqs);
2587 default:
Krishna Gudipati3fd45982011-06-24 20:24:08 -07002588 bfi_h2i_set(m->mh, BFI_MC_IOIM_IO, 0, bfa_fn_lpu(ioim->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002589 }
2590 if (itnim->seq_rec ||
Maggie Zhangf3148782010-12-09 19:11:39 -08002591 (scsi_bufflen(cmnd) & (sizeof(u32) - 1)))
Krishna Gudipati3fd45982011-06-24 20:24:08 -07002592 bfi_h2i_set(m->mh, BFI_MC_IOIM_IO, 0, bfa_fn_lpu(ioim->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002593
Jing Huang5fbe25c2010-10-18 17:17:23 -07002594 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002595 * queue I/O message to firmware
2596 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07002597 bfa_reqq_produce(ioim->bfa, ioim->reqq, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002598 return BFA_TRUE;
2599}
2600
Jing Huang5fbe25c2010-10-18 17:17:23 -07002601/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002602 * Setup any additional SG pages needed.Inline SG element is setup
2603 * at queuing time.
2604 */
2605static bfa_boolean_t
Maggie Zhange3e7d3e2010-12-09 19:10:27 -08002606bfa_ioim_sgpg_alloc(struct bfa_ioim_s *ioim)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002607{
2608 u16 nsgpgs;
2609
Jing Huangd4b671c2010-12-26 21:46:35 -08002610 WARN_ON(ioim->nsges <= BFI_SGE_INLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002611
Jing Huang5fbe25c2010-10-18 17:17:23 -07002612 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002613 * allocate SG pages needed
2614 */
2615 nsgpgs = BFA_SGPG_NPAGE(ioim->nsges);
2616 if (!nsgpgs)
2617 return BFA_TRUE;
2618
2619 if (bfa_sgpg_malloc(ioim->bfa, &ioim->sgpg_q, nsgpgs)
2620 != BFA_STATUS_OK) {
2621 bfa_sgpg_wait(ioim->bfa, &ioim->iosp->sgpg_wqe, nsgpgs);
2622 return BFA_FALSE;
2623 }
2624
2625 ioim->nsgpgs = nsgpgs;
Maggie Zhange3e7d3e2010-12-09 19:10:27 -08002626 ioim->sgpg = bfa_q_first(&ioim->sgpg_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002627
2628 return BFA_TRUE;
2629}
2630
Jing Huang5fbe25c2010-10-18 17:17:23 -07002631/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002632 * Send I/O abort request to firmware.
2633 */
2634static bfa_boolean_t
2635bfa_ioim_send_abort(struct bfa_ioim_s *ioim)
2636{
2637 struct bfi_ioim_abort_req_s *m;
2638 enum bfi_ioim_h2i msgop;
2639
Jing Huang5fbe25c2010-10-18 17:17:23 -07002640 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002641 * check for room in queue to send request now
2642 */
2643 m = bfa_reqq_next(ioim->bfa, ioim->reqq);
2644 if (!m)
2645 return BFA_FALSE;
2646
Jing Huang5fbe25c2010-10-18 17:17:23 -07002647 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002648 * build i/o request message next
2649 */
2650 if (ioim->iosp->abort_explicit)
2651 msgop = BFI_IOIM_H2I_IOABORT_REQ;
2652 else
2653 msgop = BFI_IOIM_H2I_IOCLEANUP_REQ;
2654
Krishna Gudipati3fd45982011-06-24 20:24:08 -07002655 bfi_h2i_set(m->mh, BFI_MC_IOIM, msgop, bfa_fn_lpu(ioim->bfa));
Jing Huangba816ea2010-10-18 17:10:50 -07002656 m->io_tag = cpu_to_be16(ioim->iotag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002657 m->abort_tag = ++ioim->abort_tag;
2658
Jing Huang5fbe25c2010-10-18 17:17:23 -07002659 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002660 * queue I/O message to firmware
2661 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07002662 bfa_reqq_produce(ioim->bfa, ioim->reqq, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002663 return BFA_TRUE;
2664}
2665
Jing Huang5fbe25c2010-10-18 17:17:23 -07002666/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002667 * Call to resume any I/O requests waiting for room in request queue.
2668 */
2669static void
2670bfa_ioim_qresume(void *cbarg)
2671{
2672 struct bfa_ioim_s *ioim = cbarg;
2673
2674 bfa_stats(ioim->itnim, qresumes);
2675 bfa_sm_send_event(ioim, BFA_IOIM_SM_QRESUME);
2676}
2677
2678
2679static void
2680bfa_ioim_notify_cleanup(struct bfa_ioim_s *ioim)
2681{
Jing Huang5fbe25c2010-10-18 17:17:23 -07002682 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002683 * Move IO from itnim queue to fcpim global queue since itnim will be
2684 * freed.
2685 */
2686 list_del(&ioim->qe);
2687 list_add_tail(&ioim->qe, &ioim->fcpim->ioim_comp_q);
2688
2689 if (!ioim->iosp->tskim) {
2690 if (ioim->fcpim->delay_comp && ioim->itnim->iotov_active) {
2691 bfa_cb_dequeue(&ioim->hcb_qe);
2692 list_del(&ioim->qe);
2693 list_add_tail(&ioim->qe, &ioim->itnim->delay_comp_q);
2694 }
2695 bfa_itnim_iodone(ioim->itnim);
2696 } else
Maggie Zhangf7f738122010-12-09 19:08:43 -08002697 bfa_wc_down(&ioim->iosp->tskim->wc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002698}
2699
2700static bfa_boolean_t
2701bfa_ioim_is_abortable(struct bfa_ioim_s *ioim)
2702{
2703 if ((bfa_sm_cmp_state(ioim, bfa_ioim_sm_uninit) &&
2704 (!bfa_q_is_on_q(&ioim->itnim->pending_q, ioim))) ||
2705 (bfa_sm_cmp_state(ioim, bfa_ioim_sm_abort)) ||
2706 (bfa_sm_cmp_state(ioim, bfa_ioim_sm_abort_qfull)) ||
2707 (bfa_sm_cmp_state(ioim, bfa_ioim_sm_hcb)) ||
2708 (bfa_sm_cmp_state(ioim, bfa_ioim_sm_hcb_free)) ||
2709 (bfa_sm_cmp_state(ioim, bfa_ioim_sm_resfree)))
2710 return BFA_FALSE;
2711
2712 return BFA_TRUE;
2713}
2714
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002715void
2716bfa_ioim_delayed_comp(struct bfa_ioim_s *ioim, bfa_boolean_t iotov)
2717{
Jing Huang5fbe25c2010-10-18 17:17:23 -07002718 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002719 * If path tov timer expired, failback with PATHTOV status - these
2720 * IO requests are not normally retried by IO stack.
2721 *
2722 * Otherwise device cameback online and fail it with normal failed
2723 * status so that IO stack retries these failed IO requests.
2724 */
2725 if (iotov)
2726 ioim->io_cbfn = __bfa_cb_ioim_pathtov;
2727 else {
2728 ioim->io_cbfn = __bfa_cb_ioim_failed;
2729 bfa_stats(ioim->itnim, iocom_nexus_abort);
2730 }
2731 bfa_cb_queue(ioim->bfa, &ioim->hcb_qe, ioim->io_cbfn, ioim);
2732
Jing Huang5fbe25c2010-10-18 17:17:23 -07002733 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002734 * Move IO to fcpim global queue since itnim will be
2735 * freed.
2736 */
2737 list_del(&ioim->qe);
2738 list_add_tail(&ioim->qe, &ioim->fcpim->ioim_comp_q);
2739}
2740
2741
Jing Huang5fbe25c2010-10-18 17:17:23 -07002742/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002743 * Memory allocation and initialization.
2744 */
2745void
Krishna Gudipati45070252011-06-24 20:24:29 -07002746bfa_ioim_attach(struct bfa_fcpim_s *fcpim)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002747{
2748 struct bfa_ioim_s *ioim;
Krishna Gudipati45070252011-06-24 20:24:29 -07002749 struct bfa_fcp_mod_s *fcp = fcpim->fcp;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002750 struct bfa_ioim_sp_s *iosp;
2751 u16 i;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002752
Jing Huang5fbe25c2010-10-18 17:17:23 -07002753 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002754 * claim memory first
2755 */
Krishna Gudipati45070252011-06-24 20:24:29 -07002756 ioim = (struct bfa_ioim_s *) bfa_mem_kva_curp(fcp);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002757 fcpim->ioim_arr = ioim;
Krishna Gudipati45070252011-06-24 20:24:29 -07002758 bfa_mem_kva_curp(fcp) = (u8 *) (ioim + fcpim->fcp->num_ioim_reqs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002759
Krishna Gudipati45070252011-06-24 20:24:29 -07002760 iosp = (struct bfa_ioim_sp_s *) bfa_mem_kva_curp(fcp);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002761 fcpim->ioim_sp_arr = iosp;
Krishna Gudipati45070252011-06-24 20:24:29 -07002762 bfa_mem_kva_curp(fcp) = (u8 *) (iosp + fcpim->fcp->num_ioim_reqs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002763
Jing Huang5fbe25c2010-10-18 17:17:23 -07002764 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002765 * Initialize ioim free queues
2766 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002767 INIT_LIST_HEAD(&fcpim->ioim_resfree_q);
2768 INIT_LIST_HEAD(&fcpim->ioim_comp_q);
2769
Krishna Gudipatie2187d72011-06-13 15:53:58 -07002770 for (i = 0; i < fcpim->fcp->num_ioim_reqs;
2771 i++, ioim++, iosp++) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002772 /*
2773 * initialize IOIM
2774 */
Jing Huang6a18b162010-10-18 17:08:54 -07002775 memset(ioim, 0, sizeof(struct bfa_ioim_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002776 ioim->iotag = i;
2777 ioim->bfa = fcpim->bfa;
2778 ioim->fcpim = fcpim;
2779 ioim->iosp = iosp;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002780 INIT_LIST_HEAD(&ioim->sgpg_q);
2781 bfa_reqq_winit(&ioim->iosp->reqq_wait,
2782 bfa_ioim_qresume, ioim);
2783 bfa_sgpg_winit(&ioim->iosp->sgpg_wqe,
2784 bfa_ioim_sgpg_alloced, ioim);
2785 bfa_sm_set_state(ioim, bfa_ioim_sm_uninit);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002786 }
2787}
2788
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002789void
2790bfa_ioim_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
2791{
Krishna Gudipatie2187d72011-06-13 15:53:58 -07002792 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002793 struct bfi_ioim_rsp_s *rsp = (struct bfi_ioim_rsp_s *) m;
2794 struct bfa_ioim_s *ioim;
2795 u16 iotag;
2796 enum bfa_ioim_event evt = BFA_IOIM_SM_COMP;
2797
Jing Huangba816ea2010-10-18 17:10:50 -07002798 iotag = be16_to_cpu(rsp->io_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002799
2800 ioim = BFA_IOIM_FROM_TAG(fcpim, iotag);
Jing Huangd4b671c2010-12-26 21:46:35 -08002801 WARN_ON(ioim->iotag != iotag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002802
2803 bfa_trc(ioim->bfa, ioim->iotag);
2804 bfa_trc(ioim->bfa, rsp->io_status);
2805 bfa_trc(ioim->bfa, rsp->reuse_io_tag);
2806
2807 if (bfa_sm_cmp_state(ioim, bfa_ioim_sm_active))
Jing Huang6a18b162010-10-18 17:08:54 -07002808 ioim->iosp->comp_rspmsg = *m;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002809
2810 switch (rsp->io_status) {
2811 case BFI_IOIM_STS_OK:
2812 bfa_stats(ioim->itnim, iocomp_ok);
2813 if (rsp->reuse_io_tag == 0)
2814 evt = BFA_IOIM_SM_DONE;
2815 else
2816 evt = BFA_IOIM_SM_COMP;
2817 break;
2818
2819 case BFI_IOIM_STS_TIMEDOUT:
2820 bfa_stats(ioim->itnim, iocomp_timedout);
2821 case BFI_IOIM_STS_ABORTED:
2822 rsp->io_status = BFI_IOIM_STS_ABORTED;
2823 bfa_stats(ioim->itnim, iocomp_aborted);
2824 if (rsp->reuse_io_tag == 0)
2825 evt = BFA_IOIM_SM_DONE;
2826 else
2827 evt = BFA_IOIM_SM_COMP;
2828 break;
2829
2830 case BFI_IOIM_STS_PROTO_ERR:
2831 bfa_stats(ioim->itnim, iocom_proto_err);
Jing Huangd4b671c2010-12-26 21:46:35 -08002832 WARN_ON(!rsp->reuse_io_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002833 evt = BFA_IOIM_SM_COMP;
2834 break;
2835
2836 case BFI_IOIM_STS_SQER_NEEDED:
2837 bfa_stats(ioim->itnim, iocom_sqer_needed);
Jing Huangd4b671c2010-12-26 21:46:35 -08002838 WARN_ON(rsp->reuse_io_tag != 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002839 evt = BFA_IOIM_SM_SQRETRY;
2840 break;
2841
2842 case BFI_IOIM_STS_RES_FREE:
2843 bfa_stats(ioim->itnim, iocom_res_free);
2844 evt = BFA_IOIM_SM_FREE;
2845 break;
2846
2847 case BFI_IOIM_STS_HOST_ABORTED:
2848 bfa_stats(ioim->itnim, iocom_hostabrts);
2849 if (rsp->abort_tag != ioim->abort_tag) {
2850 bfa_trc(ioim->bfa, rsp->abort_tag);
2851 bfa_trc(ioim->bfa, ioim->abort_tag);
2852 return;
2853 }
2854
2855 if (rsp->reuse_io_tag)
2856 evt = BFA_IOIM_SM_ABORT_COMP;
2857 else
2858 evt = BFA_IOIM_SM_ABORT_DONE;
2859 break;
2860
2861 case BFI_IOIM_STS_UTAG:
2862 bfa_stats(ioim->itnim, iocom_utags);
2863 evt = BFA_IOIM_SM_COMP_UTAG;
2864 break;
2865
2866 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08002867 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002868 }
2869
2870 bfa_sm_send_event(ioim, evt);
2871}
2872
2873void
2874bfa_ioim_good_comp_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
2875{
Krishna Gudipatie2187d72011-06-13 15:53:58 -07002876 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002877 struct bfi_ioim_rsp_s *rsp = (struct bfi_ioim_rsp_s *) m;
2878 struct bfa_ioim_s *ioim;
2879 u16 iotag;
2880
Jing Huangba816ea2010-10-18 17:10:50 -07002881 iotag = be16_to_cpu(rsp->io_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002882
2883 ioim = BFA_IOIM_FROM_TAG(fcpim, iotag);
Jing Huangd4b671c2010-12-26 21:46:35 -08002884 WARN_ON(BFA_IOIM_TAG_2_ID(ioim->iotag) != iotag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002885
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002886 bfa_ioim_cb_profile_comp(fcpim, ioim);
Krishna Gudipati83763d52011-07-20 17:04:03 -07002887
Krishna Gudipati8ca2dd82011-12-20 18:55:07 -08002888 bfa_sm_send_event(ioim, BFA_IOIM_SM_COMP_GOOD);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002889}
2890
Jing Huang5fbe25c2010-10-18 17:17:23 -07002891/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002892 * Called by itnim to clean up IO while going offline.
2893 */
2894void
2895bfa_ioim_cleanup(struct bfa_ioim_s *ioim)
2896{
2897 bfa_trc(ioim->bfa, ioim->iotag);
2898 bfa_stats(ioim->itnim, io_cleanups);
2899
2900 ioim->iosp->tskim = NULL;
2901 bfa_sm_send_event(ioim, BFA_IOIM_SM_CLEANUP);
2902}
2903
2904void
2905bfa_ioim_cleanup_tm(struct bfa_ioim_s *ioim, struct bfa_tskim_s *tskim)
2906{
2907 bfa_trc(ioim->bfa, ioim->iotag);
2908 bfa_stats(ioim->itnim, io_tmaborts);
2909
2910 ioim->iosp->tskim = tskim;
2911 bfa_sm_send_event(ioim, BFA_IOIM_SM_CLEANUP);
2912}
2913
Jing Huang5fbe25c2010-10-18 17:17:23 -07002914/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002915 * IOC failure handling.
2916 */
2917void
2918bfa_ioim_iocdisable(struct bfa_ioim_s *ioim)
2919{
2920 bfa_trc(ioim->bfa, ioim->iotag);
2921 bfa_stats(ioim->itnim, io_iocdowns);
2922 bfa_sm_send_event(ioim, BFA_IOIM_SM_HWFAIL);
2923}
2924
Jing Huang5fbe25c2010-10-18 17:17:23 -07002925/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002926 * IO offline TOV popped. Fail the pending IO.
2927 */
2928void
2929bfa_ioim_tov(struct bfa_ioim_s *ioim)
2930{
2931 bfa_trc(ioim->bfa, ioim->iotag);
2932 bfa_sm_send_event(ioim, BFA_IOIM_SM_IOTOV);
2933}
2934
2935
Jing Huang5fbe25c2010-10-18 17:17:23 -07002936/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002937 * Allocate IOIM resource for initiator mode I/O request.
2938 */
2939struct bfa_ioim_s *
2940bfa_ioim_alloc(struct bfa_s *bfa, struct bfad_ioim_s *dio,
2941 struct bfa_itnim_s *itnim, u16 nsges)
2942{
Krishna Gudipatie2187d72011-06-13 15:53:58 -07002943 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002944 struct bfa_ioim_s *ioim;
Krishna Gudipatie2187d72011-06-13 15:53:58 -07002945 struct bfa_iotag_s *iotag = NULL;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002946
Jing Huang5fbe25c2010-10-18 17:17:23 -07002947 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002948 * alocate IOIM resource
2949 */
Krishna Gudipatie2187d72011-06-13 15:53:58 -07002950 bfa_q_deq(&fcpim->fcp->iotag_ioim_free_q, &iotag);
2951 if (!iotag) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002952 bfa_stats(itnim, no_iotags);
2953 return NULL;
2954 }
2955
Krishna Gudipatie2187d72011-06-13 15:53:58 -07002956 ioim = BFA_IOIM_FROM_TAG(fcpim, iotag->tag);
2957
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002958 ioim->dio = dio;
2959 ioim->itnim = itnim;
2960 ioim->nsges = nsges;
2961 ioim->nsgpgs = 0;
2962
2963 bfa_stats(itnim, total_ios);
2964 fcpim->ios_active++;
2965
2966 list_add_tail(&ioim->qe, &itnim->io_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002967
2968 return ioim;
2969}
2970
2971void
2972bfa_ioim_free(struct bfa_ioim_s *ioim)
2973{
Krishna Gudipatie2187d72011-06-13 15:53:58 -07002974 struct bfa_fcpim_s *fcpim = ioim->fcpim;
2975 struct bfa_iotag_s *iotag;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002976
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002977 if (ioim->nsgpgs > 0)
2978 bfa_sgpg_mfree(ioim->bfa, &ioim->sgpg_q, ioim->nsgpgs);
2979
2980 bfa_stats(ioim->itnim, io_comps);
2981 fcpim->ios_active--;
2982
Krishna Gudipati15821f02010-12-13 16:23:27 -08002983 ioim->iotag &= BFA_IOIM_IOTAG_MASK;
Krishna Gudipatie2187d72011-06-13 15:53:58 -07002984
2985 WARN_ON(!(ioim->iotag <
2986 (fcpim->fcp->num_ioim_reqs + fcpim->fcp->num_fwtio_reqs)));
2987 iotag = BFA_IOTAG_FROM_TAG(fcpim->fcp, ioim->iotag);
2988
2989 if (ioim->iotag < fcpim->fcp->num_ioim_reqs)
2990 list_add_tail(&iotag->qe, &fcpim->fcp->iotag_ioim_free_q);
2991 else
2992 list_add_tail(&iotag->qe, &fcpim->fcp->iotag_tio_free_q);
2993
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002994 list_del(&ioim->qe);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002995}
2996
2997void
2998bfa_ioim_start(struct bfa_ioim_s *ioim)
2999{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003000 bfa_ioim_cb_profile_start(ioim->fcpim, ioim);
3001
Jing Huang5fbe25c2010-10-18 17:17:23 -07003002 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003003 * Obtain the queue over which this request has to be issued
3004 */
3005 ioim->reqq = bfa_fcpim_ioredirect_enabled(ioim->bfa) ?
Maggie Zhangf3148782010-12-09 19:11:39 -08003006 BFA_FALSE : bfa_itnim_get_reqq(ioim);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003007
3008 bfa_sm_send_event(ioim, BFA_IOIM_SM_START);
3009}
3010
Jing Huang5fbe25c2010-10-18 17:17:23 -07003011/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003012 * Driver I/O abort request.
3013 */
3014bfa_status_t
3015bfa_ioim_abort(struct bfa_ioim_s *ioim)
3016{
3017
3018 bfa_trc(ioim->bfa, ioim->iotag);
3019
3020 if (!bfa_ioim_is_abortable(ioim))
3021 return BFA_STATUS_FAILED;
3022
3023 bfa_stats(ioim->itnim, io_aborts);
3024 bfa_sm_send_event(ioim, BFA_IOIM_SM_ABORT);
3025
3026 return BFA_STATUS_OK;
3027}
3028
Jing Huang5fbe25c2010-10-18 17:17:23 -07003029/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003030 * BFA TSKIM state machine functions
3031 */
3032
Jing Huang5fbe25c2010-10-18 17:17:23 -07003033/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08003034 * Task management command beginning state.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003035 */
3036static void
3037bfa_tskim_sm_uninit(struct bfa_tskim_s *tskim, enum bfa_tskim_event event)
3038{
3039 bfa_trc(tskim->bfa, event);
3040
3041 switch (event) {
3042 case BFA_TSKIM_SM_START:
3043 bfa_sm_set_state(tskim, bfa_tskim_sm_active);
3044 bfa_tskim_gather_ios(tskim);
3045
Jing Huang5fbe25c2010-10-18 17:17:23 -07003046 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003047 * If device is offline, do not send TM on wire. Just cleanup
3048 * any pending IO requests and complete TM request.
3049 */
3050 if (!bfa_itnim_is_online(tskim->itnim)) {
3051 bfa_sm_set_state(tskim, bfa_tskim_sm_iocleanup);
3052 tskim->tsk_status = BFI_TSKIM_STS_OK;
3053 bfa_tskim_cleanup_ios(tskim);
3054 return;
3055 }
3056
3057 if (!bfa_tskim_send(tskim)) {
3058 bfa_sm_set_state(tskim, bfa_tskim_sm_qfull);
3059 bfa_stats(tskim->itnim, tm_qwait);
3060 bfa_reqq_wait(tskim->bfa, tskim->itnim->reqq,
3061 &tskim->reqq_wait);
3062 }
3063 break;
3064
3065 default:
3066 bfa_sm_fault(tskim->bfa, event);
3067 }
3068}
3069
Jing Huang5fbe25c2010-10-18 17:17:23 -07003070/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08003071 * TM command is active, awaiting completion from firmware to
3072 * cleanup IO requests in TM scope.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003073 */
3074static void
3075bfa_tskim_sm_active(struct bfa_tskim_s *tskim, enum bfa_tskim_event event)
3076{
3077 bfa_trc(tskim->bfa, event);
3078
3079 switch (event) {
3080 case BFA_TSKIM_SM_DONE:
3081 bfa_sm_set_state(tskim, bfa_tskim_sm_iocleanup);
3082 bfa_tskim_cleanup_ios(tskim);
3083 break;
3084
3085 case BFA_TSKIM_SM_CLEANUP:
3086 bfa_sm_set_state(tskim, bfa_tskim_sm_cleanup);
3087 if (!bfa_tskim_send_abort(tskim)) {
3088 bfa_sm_set_state(tskim, bfa_tskim_sm_cleanup_qfull);
3089 bfa_stats(tskim->itnim, tm_qwait);
3090 bfa_reqq_wait(tskim->bfa, tskim->itnim->reqq,
3091 &tskim->reqq_wait);
3092 }
3093 break;
3094
3095 case BFA_TSKIM_SM_HWFAIL:
3096 bfa_sm_set_state(tskim, bfa_tskim_sm_hcb);
3097 bfa_tskim_iocdisable_ios(tskim);
3098 bfa_tskim_qcomp(tskim, __bfa_cb_tskim_failed);
3099 break;
3100
3101 default:
3102 bfa_sm_fault(tskim->bfa, event);
3103 }
3104}
3105
Jing Huang5fbe25c2010-10-18 17:17:23 -07003106/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08003107 * An active TM is being cleaned up since ITN is offline. Awaiting cleanup
3108 * completion event from firmware.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003109 */
3110static void
3111bfa_tskim_sm_cleanup(struct bfa_tskim_s *tskim, enum bfa_tskim_event event)
3112{
3113 bfa_trc(tskim->bfa, event);
3114
3115 switch (event) {
3116 case BFA_TSKIM_SM_DONE:
Jing Huang5fbe25c2010-10-18 17:17:23 -07003117 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003118 * Ignore and wait for ABORT completion from firmware.
3119 */
3120 break;
3121
3122 case BFA_TSKIM_SM_CLEANUP_DONE:
3123 bfa_sm_set_state(tskim, bfa_tskim_sm_iocleanup);
3124 bfa_tskim_cleanup_ios(tskim);
3125 break;
3126
3127 case BFA_TSKIM_SM_HWFAIL:
3128 bfa_sm_set_state(tskim, bfa_tskim_sm_hcb);
3129 bfa_tskim_iocdisable_ios(tskim);
3130 bfa_tskim_qcomp(tskim, __bfa_cb_tskim_failed);
3131 break;
3132
3133 default:
3134 bfa_sm_fault(tskim->bfa, event);
3135 }
3136}
3137
3138static void
3139bfa_tskim_sm_iocleanup(struct bfa_tskim_s *tskim, enum bfa_tskim_event event)
3140{
3141 bfa_trc(tskim->bfa, event);
3142
3143 switch (event) {
3144 case BFA_TSKIM_SM_IOS_DONE:
3145 bfa_sm_set_state(tskim, bfa_tskim_sm_hcb);
3146 bfa_tskim_qcomp(tskim, __bfa_cb_tskim_done);
3147 break;
3148
3149 case BFA_TSKIM_SM_CLEANUP:
Jing Huang5fbe25c2010-10-18 17:17:23 -07003150 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003151 * Ignore, TM command completed on wire.
3152 * Notify TM conmpletion on IO cleanup completion.
3153 */
3154 break;
3155
3156 case BFA_TSKIM_SM_HWFAIL:
3157 bfa_sm_set_state(tskim, bfa_tskim_sm_hcb);
3158 bfa_tskim_iocdisable_ios(tskim);
3159 bfa_tskim_qcomp(tskim, __bfa_cb_tskim_failed);
3160 break;
3161
3162 default:
3163 bfa_sm_fault(tskim->bfa, event);
3164 }
3165}
3166
Jing Huang5fbe25c2010-10-18 17:17:23 -07003167/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08003168 * Task management command is waiting for room in request CQ
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003169 */
3170static void
3171bfa_tskim_sm_qfull(struct bfa_tskim_s *tskim, enum bfa_tskim_event event)
3172{
3173 bfa_trc(tskim->bfa, event);
3174
3175 switch (event) {
3176 case BFA_TSKIM_SM_QRESUME:
3177 bfa_sm_set_state(tskim, bfa_tskim_sm_active);
3178 bfa_tskim_send(tskim);
3179 break;
3180
3181 case BFA_TSKIM_SM_CLEANUP:
Jing Huang5fbe25c2010-10-18 17:17:23 -07003182 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003183 * No need to send TM on wire since ITN is offline.
3184 */
3185 bfa_sm_set_state(tskim, bfa_tskim_sm_iocleanup);
3186 bfa_reqq_wcancel(&tskim->reqq_wait);
3187 bfa_tskim_cleanup_ios(tskim);
3188 break;
3189
3190 case BFA_TSKIM_SM_HWFAIL:
3191 bfa_sm_set_state(tskim, bfa_tskim_sm_hcb);
3192 bfa_reqq_wcancel(&tskim->reqq_wait);
3193 bfa_tskim_iocdisable_ios(tskim);
3194 bfa_tskim_qcomp(tskim, __bfa_cb_tskim_failed);
3195 break;
3196
3197 default:
3198 bfa_sm_fault(tskim->bfa, event);
3199 }
3200}
3201
Jing Huang5fbe25c2010-10-18 17:17:23 -07003202/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08003203 * Task management command is active, awaiting for room in request CQ
3204 * to send clean up request.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003205 */
3206static void
3207bfa_tskim_sm_cleanup_qfull(struct bfa_tskim_s *tskim,
3208 enum bfa_tskim_event event)
3209{
3210 bfa_trc(tskim->bfa, event);
3211
3212 switch (event) {
3213 case BFA_TSKIM_SM_DONE:
3214 bfa_reqq_wcancel(&tskim->reqq_wait);
Jing Huang5fbe25c2010-10-18 17:17:23 -07003215 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003216 * Fall through !!!
3217 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003218 case BFA_TSKIM_SM_QRESUME:
3219 bfa_sm_set_state(tskim, bfa_tskim_sm_cleanup);
3220 bfa_tskim_send_abort(tskim);
3221 break;
3222
3223 case BFA_TSKIM_SM_HWFAIL:
3224 bfa_sm_set_state(tskim, bfa_tskim_sm_hcb);
3225 bfa_reqq_wcancel(&tskim->reqq_wait);
3226 bfa_tskim_iocdisable_ios(tskim);
3227 bfa_tskim_qcomp(tskim, __bfa_cb_tskim_failed);
3228 break;
3229
3230 default:
3231 bfa_sm_fault(tskim->bfa, event);
3232 }
3233}
3234
Jing Huang5fbe25c2010-10-18 17:17:23 -07003235/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08003236 * BFA callback is pending
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003237 */
3238static void
3239bfa_tskim_sm_hcb(struct bfa_tskim_s *tskim, enum bfa_tskim_event event)
3240{
3241 bfa_trc(tskim->bfa, event);
3242
3243 switch (event) {
3244 case BFA_TSKIM_SM_HCB:
3245 bfa_sm_set_state(tskim, bfa_tskim_sm_uninit);
3246 bfa_tskim_free(tskim);
3247 break;
3248
3249 case BFA_TSKIM_SM_CLEANUP:
3250 bfa_tskim_notify_comp(tskim);
3251 break;
3252
3253 case BFA_TSKIM_SM_HWFAIL:
3254 break;
3255
3256 default:
3257 bfa_sm_fault(tskim->bfa, event);
3258 }
3259}
3260
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003261static void
3262__bfa_cb_tskim_done(void *cbarg, bfa_boolean_t complete)
3263{
3264 struct bfa_tskim_s *tskim = cbarg;
3265
3266 if (!complete) {
3267 bfa_sm_send_event(tskim, BFA_TSKIM_SM_HCB);
3268 return;
3269 }
3270
3271 bfa_stats(tskim->itnim, tm_success);
3272 bfa_cb_tskim_done(tskim->bfa->bfad, tskim->dtsk, tskim->tsk_status);
3273}
3274
3275static void
3276__bfa_cb_tskim_failed(void *cbarg, bfa_boolean_t complete)
3277{
3278 struct bfa_tskim_s *tskim = cbarg;
3279
3280 if (!complete) {
3281 bfa_sm_send_event(tskim, BFA_TSKIM_SM_HCB);
3282 return;
3283 }
3284
3285 bfa_stats(tskim->itnim, tm_failures);
3286 bfa_cb_tskim_done(tskim->bfa->bfad, tskim->dtsk,
3287 BFI_TSKIM_STS_FAILED);
3288}
3289
Maggie Zhangda99dcc2010-12-09 19:13:20 -08003290static bfa_boolean_t
Maggie Zhangf3148782010-12-09 19:11:39 -08003291bfa_tskim_match_scope(struct bfa_tskim_s *tskim, struct scsi_lun lun)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003292{
3293 switch (tskim->tm_cmnd) {
3294 case FCP_TM_TARGET_RESET:
3295 return BFA_TRUE;
3296
3297 case FCP_TM_ABORT_TASK_SET:
3298 case FCP_TM_CLEAR_TASK_SET:
3299 case FCP_TM_LUN_RESET:
3300 case FCP_TM_CLEAR_ACA:
Maggie Zhangda99dcc2010-12-09 19:13:20 -08003301 return !memcmp(&tskim->lun, &lun, sizeof(lun));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003302
3303 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08003304 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003305 }
3306
3307 return BFA_FALSE;
3308}
3309
Jing Huang5fbe25c2010-10-18 17:17:23 -07003310/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08003311 * Gather affected IO requests and task management commands.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003312 */
3313static void
3314bfa_tskim_gather_ios(struct bfa_tskim_s *tskim)
3315{
3316 struct bfa_itnim_s *itnim = tskim->itnim;
3317 struct bfa_ioim_s *ioim;
Maggie Zhangf3148782010-12-09 19:11:39 -08003318 struct list_head *qe, *qen;
3319 struct scsi_cmnd *cmnd;
3320 struct scsi_lun scsilun;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003321
3322 INIT_LIST_HEAD(&tskim->io_q);
3323
Jing Huang5fbe25c2010-10-18 17:17:23 -07003324 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003325 * Gather any active IO requests first.
3326 */
3327 list_for_each_safe(qe, qen, &itnim->io_q) {
3328 ioim = (struct bfa_ioim_s *) qe;
Maggie Zhangf3148782010-12-09 19:11:39 -08003329 cmnd = (struct scsi_cmnd *) ioim->dio;
3330 int_to_scsilun(cmnd->device->lun, &scsilun);
3331 if (bfa_tskim_match_scope(tskim, scsilun)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003332 list_del(&ioim->qe);
3333 list_add_tail(&ioim->qe, &tskim->io_q);
3334 }
3335 }
3336
Jing Huang5fbe25c2010-10-18 17:17:23 -07003337 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003338 * Failback any pending IO requests immediately.
3339 */
3340 list_for_each_safe(qe, qen, &itnim->pending_q) {
3341 ioim = (struct bfa_ioim_s *) qe;
Maggie Zhangf3148782010-12-09 19:11:39 -08003342 cmnd = (struct scsi_cmnd *) ioim->dio;
3343 int_to_scsilun(cmnd->device->lun, &scsilun);
3344 if (bfa_tskim_match_scope(tskim, scsilun)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003345 list_del(&ioim->qe);
3346 list_add_tail(&ioim->qe, &ioim->fcpim->ioim_comp_q);
3347 bfa_ioim_tov(ioim);
3348 }
3349 }
3350}
3351
Jing Huang5fbe25c2010-10-18 17:17:23 -07003352/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08003353 * IO cleanup completion
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003354 */
3355static void
3356bfa_tskim_cleanp_comp(void *tskim_cbarg)
3357{
3358 struct bfa_tskim_s *tskim = tskim_cbarg;
3359
3360 bfa_stats(tskim->itnim, tm_io_comps);
3361 bfa_sm_send_event(tskim, BFA_TSKIM_SM_IOS_DONE);
3362}
3363
Jing Huang5fbe25c2010-10-18 17:17:23 -07003364/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08003365 * Gather affected IO requests and task management commands.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003366 */
3367static void
3368bfa_tskim_cleanup_ios(struct bfa_tskim_s *tskim)
3369{
3370 struct bfa_ioim_s *ioim;
3371 struct list_head *qe, *qen;
3372
3373 bfa_wc_init(&tskim->wc, bfa_tskim_cleanp_comp, tskim);
3374
3375 list_for_each_safe(qe, qen, &tskim->io_q) {
3376 ioim = (struct bfa_ioim_s *) qe;
3377 bfa_wc_up(&tskim->wc);
3378 bfa_ioim_cleanup_tm(ioim, tskim);
3379 }
3380
3381 bfa_wc_wait(&tskim->wc);
3382}
3383
Jing Huang5fbe25c2010-10-18 17:17:23 -07003384/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08003385 * Send task management request to firmware.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003386 */
3387static bfa_boolean_t
3388bfa_tskim_send(struct bfa_tskim_s *tskim)
3389{
3390 struct bfa_itnim_s *itnim = tskim->itnim;
3391 struct bfi_tskim_req_s *m;
3392
Jing Huang5fbe25c2010-10-18 17:17:23 -07003393 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003394 * check for room in queue to send request now
3395 */
3396 m = bfa_reqq_next(tskim->bfa, itnim->reqq);
3397 if (!m)
3398 return BFA_FALSE;
3399
Jing Huang5fbe25c2010-10-18 17:17:23 -07003400 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003401 * build i/o request message next
3402 */
3403 bfi_h2i_set(m->mh, BFI_MC_TSKIM, BFI_TSKIM_H2I_TM_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003404 bfa_fn_lpu(tskim->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003405
Jing Huangba816ea2010-10-18 17:10:50 -07003406 m->tsk_tag = cpu_to_be16(tskim->tsk_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003407 m->itn_fhdl = tskim->itnim->rport->fw_handle;
3408 m->t_secs = tskim->tsecs;
3409 m->lun = tskim->lun;
3410 m->tm_flags = tskim->tm_cmnd;
3411
Jing Huang5fbe25c2010-10-18 17:17:23 -07003412 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003413 * queue I/O message to firmware
3414 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003415 bfa_reqq_produce(tskim->bfa, itnim->reqq, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003416 return BFA_TRUE;
3417}
3418
Jing Huang5fbe25c2010-10-18 17:17:23 -07003419/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08003420 * Send abort request to cleanup an active TM to firmware.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003421 */
3422static bfa_boolean_t
3423bfa_tskim_send_abort(struct bfa_tskim_s *tskim)
3424{
3425 struct bfa_itnim_s *itnim = tskim->itnim;
3426 struct bfi_tskim_abortreq_s *m;
3427
Jing Huang5fbe25c2010-10-18 17:17:23 -07003428 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003429 * check for room in queue to send request now
3430 */
3431 m = bfa_reqq_next(tskim->bfa, itnim->reqq);
3432 if (!m)
3433 return BFA_FALSE;
3434
Jing Huang5fbe25c2010-10-18 17:17:23 -07003435 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003436 * build i/o request message next
3437 */
3438 bfi_h2i_set(m->mh, BFI_MC_TSKIM, BFI_TSKIM_H2I_ABORT_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003439 bfa_fn_lpu(tskim->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003440
Jing Huangba816ea2010-10-18 17:10:50 -07003441 m->tsk_tag = cpu_to_be16(tskim->tsk_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003442
Jing Huang5fbe25c2010-10-18 17:17:23 -07003443 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003444 * queue I/O message to firmware
3445 */
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003446 bfa_reqq_produce(tskim->bfa, itnim->reqq, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003447 return BFA_TRUE;
3448}
3449
Jing Huang5fbe25c2010-10-18 17:17:23 -07003450/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08003451 * Call to resume task management cmnd waiting for room in request queue.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003452 */
3453static void
3454bfa_tskim_qresume(void *cbarg)
3455{
3456 struct bfa_tskim_s *tskim = cbarg;
3457
3458 bfa_stats(tskim->itnim, tm_qresumes);
3459 bfa_sm_send_event(tskim, BFA_TSKIM_SM_QRESUME);
3460}
3461
Jing Huang5fbe25c2010-10-18 17:17:23 -07003462/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003463 * Cleanup IOs associated with a task mangement command on IOC failures.
3464 */
3465static void
3466bfa_tskim_iocdisable_ios(struct bfa_tskim_s *tskim)
3467{
3468 struct bfa_ioim_s *ioim;
3469 struct list_head *qe, *qen;
3470
3471 list_for_each_safe(qe, qen, &tskim->io_q) {
3472 ioim = (struct bfa_ioim_s *) qe;
3473 bfa_ioim_iocdisable(ioim);
3474 }
3475}
3476
Jing Huang5fbe25c2010-10-18 17:17:23 -07003477/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003478 * Notification on completions from related ioim.
3479 */
3480void
3481bfa_tskim_iodone(struct bfa_tskim_s *tskim)
3482{
3483 bfa_wc_down(&tskim->wc);
3484}
3485
Jing Huang5fbe25c2010-10-18 17:17:23 -07003486/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003487 * Handle IOC h/w failure notification from itnim.
3488 */
3489void
3490bfa_tskim_iocdisable(struct bfa_tskim_s *tskim)
3491{
3492 tskim->notify = BFA_FALSE;
3493 bfa_stats(tskim->itnim, tm_iocdowns);
3494 bfa_sm_send_event(tskim, BFA_TSKIM_SM_HWFAIL);
3495}
3496
Jing Huang5fbe25c2010-10-18 17:17:23 -07003497/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003498 * Cleanup TM command and associated IOs as part of ITNIM offline.
3499 */
3500void
3501bfa_tskim_cleanup(struct bfa_tskim_s *tskim)
3502{
3503 tskim->notify = BFA_TRUE;
3504 bfa_stats(tskim->itnim, tm_cleanups);
3505 bfa_sm_send_event(tskim, BFA_TSKIM_SM_CLEANUP);
3506}
3507
Jing Huang5fbe25c2010-10-18 17:17:23 -07003508/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08003509 * Memory allocation and initialization.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003510 */
3511void
Krishna Gudipati45070252011-06-24 20:24:29 -07003512bfa_tskim_attach(struct bfa_fcpim_s *fcpim)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003513{
3514 struct bfa_tskim_s *tskim;
Krishna Gudipati45070252011-06-24 20:24:29 -07003515 struct bfa_fcp_mod_s *fcp = fcpim->fcp;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003516 u16 i;
3517
3518 INIT_LIST_HEAD(&fcpim->tskim_free_q);
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003519 INIT_LIST_HEAD(&fcpim->tskim_unused_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003520
Krishna Gudipati45070252011-06-24 20:24:29 -07003521 tskim = (struct bfa_tskim_s *) bfa_mem_kva_curp(fcp);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003522 fcpim->tskim_arr = tskim;
3523
3524 for (i = 0; i < fcpim->num_tskim_reqs; i++, tskim++) {
3525 /*
3526 * initialize TSKIM
3527 */
Jing Huang6a18b162010-10-18 17:08:54 -07003528 memset(tskim, 0, sizeof(struct bfa_tskim_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003529 tskim->tsk_tag = i;
3530 tskim->bfa = fcpim->bfa;
3531 tskim->fcpim = fcpim;
3532 tskim->notify = BFA_FALSE;
3533 bfa_reqq_winit(&tskim->reqq_wait, bfa_tskim_qresume,
3534 tskim);
3535 bfa_sm_set_state(tskim, bfa_tskim_sm_uninit);
3536
3537 list_add_tail(&tskim->qe, &fcpim->tskim_free_q);
3538 }
3539
Krishna Gudipati45070252011-06-24 20:24:29 -07003540 bfa_mem_kva_curp(fcp) = (u8 *) tskim;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003541}
3542
3543void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003544bfa_tskim_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
3545{
Krishna Gudipatie2187d72011-06-13 15:53:58 -07003546 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003547 struct bfi_tskim_rsp_s *rsp = (struct bfi_tskim_rsp_s *) m;
3548 struct bfa_tskim_s *tskim;
Jing Huangba816ea2010-10-18 17:10:50 -07003549 u16 tsk_tag = be16_to_cpu(rsp->tsk_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003550
3551 tskim = BFA_TSKIM_FROM_TAG(fcpim, tsk_tag);
Jing Huangd4b671c2010-12-26 21:46:35 -08003552 WARN_ON(tskim->tsk_tag != tsk_tag);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003553
3554 tskim->tsk_status = rsp->tsk_status;
3555
Jing Huang5fbe25c2010-10-18 17:17:23 -07003556 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003557 * Firmware sends BFI_TSKIM_STS_ABORTED status for abort
3558 * requests. All other statuses are for normal completions.
3559 */
3560 if (rsp->tsk_status == BFI_TSKIM_STS_ABORTED) {
3561 bfa_stats(tskim->itnim, tm_cleanup_comps);
3562 bfa_sm_send_event(tskim, BFA_TSKIM_SM_CLEANUP_DONE);
3563 } else {
3564 bfa_stats(tskim->itnim, tm_fw_rsps);
3565 bfa_sm_send_event(tskim, BFA_TSKIM_SM_DONE);
3566 }
3567}
3568
3569
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003570struct bfa_tskim_s *
3571bfa_tskim_alloc(struct bfa_s *bfa, struct bfad_tskim_s *dtsk)
3572{
Krishna Gudipatie2187d72011-06-13 15:53:58 -07003573 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003574 struct bfa_tskim_s *tskim;
3575
3576 bfa_q_deq(&fcpim->tskim_free_q, &tskim);
3577
3578 if (tskim)
3579 tskim->dtsk = dtsk;
3580
3581 return tskim;
3582}
3583
3584void
3585bfa_tskim_free(struct bfa_tskim_s *tskim)
3586{
Jing Huangd4b671c2010-12-26 21:46:35 -08003587 WARN_ON(!bfa_q_is_on_q_func(&tskim->itnim->tsk_q, &tskim->qe));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003588 list_del(&tskim->qe);
3589 list_add_tail(&tskim->qe, &tskim->fcpim->tskim_free_q);
3590}
3591
Jing Huang5fbe25c2010-10-18 17:17:23 -07003592/*
Maggie Zhangda99dcc2010-12-09 19:13:20 -08003593 * Start a task management command.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003594 *
3595 * @param[in] tskim BFA task management command instance
3596 * @param[in] itnim i-t nexus for the task management command
3597 * @param[in] lun lun, if applicable
3598 * @param[in] tm_cmnd Task management command code.
3599 * @param[in] t_secs Timeout in seconds
3600 *
3601 * @return None.
3602 */
3603void
Maggie Zhangf3148782010-12-09 19:11:39 -08003604bfa_tskim_start(struct bfa_tskim_s *tskim, struct bfa_itnim_s *itnim,
3605 struct scsi_lun lun,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003606 enum fcp_tm_cmnd tm_cmnd, u8 tsecs)
3607{
3608 tskim->itnim = itnim;
3609 tskim->lun = lun;
3610 tskim->tm_cmnd = tm_cmnd;
3611 tskim->tsecs = tsecs;
3612 tskim->notify = BFA_FALSE;
3613 bfa_stats(itnim, tm_cmnds);
3614
3615 list_add_tail(&tskim->qe, &itnim->tsk_q);
3616 bfa_sm_send_event(tskim, BFA_TSKIM_SM_START);
3617}
Krishna Gudipatie2187d72011-06-13 15:53:58 -07003618
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003619void
3620bfa_tskim_res_recfg(struct bfa_s *bfa, u16 num_tskim_fw)
3621{
3622 struct bfa_fcpim_s *fcpim = BFA_FCPIM(bfa);
3623 struct list_head *qe;
3624 int i;
3625
3626 for (i = 0; i < (fcpim->num_tskim_reqs - num_tskim_fw); i++) {
3627 bfa_q_deq_tail(&fcpim->tskim_free_q, &qe);
3628 list_add_tail(qe, &fcpim->tskim_unused_q);
3629 }
3630}
3631
Krishna Gudipatie2187d72011-06-13 15:53:58 -07003632/* BFA FCP module - parent module for fcpim */
3633
3634BFA_MODULE(fcp);
3635
3636static void
Krishna Gudipati45070252011-06-24 20:24:29 -07003637bfa_fcp_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo,
3638 struct bfa_s *bfa)
Krishna Gudipatie2187d72011-06-13 15:53:58 -07003639{
Krishna Gudipati45070252011-06-24 20:24:29 -07003640 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
3641 struct bfa_mem_kva_s *fcp_kva = BFA_MEM_FCP_KVA(bfa);
3642 struct bfa_mem_dma_s *seg_ptr;
3643 u16 nsegs, idx, per_seg_ios, num_io_req;
3644 u32 km_len = 0;
Krishna Gudipatie2187d72011-06-13 15:53:58 -07003645
3646 /*
3647 * ZERO for num_ioim_reqs and num_fwtio_reqs is allowed config value.
3648 * So if the values are non zero, adjust them appropriately.
3649 */
3650 if (cfg->fwcfg.num_ioim_reqs &&
3651 cfg->fwcfg.num_ioim_reqs < BFA_IOIM_MIN)
3652 cfg->fwcfg.num_ioim_reqs = BFA_IOIM_MIN;
3653 else if (cfg->fwcfg.num_ioim_reqs > BFA_IOIM_MAX)
3654 cfg->fwcfg.num_ioim_reqs = BFA_IOIM_MAX;
3655
3656 if (cfg->fwcfg.num_fwtio_reqs > BFA_FWTIO_MAX)
3657 cfg->fwcfg.num_fwtio_reqs = BFA_FWTIO_MAX;
3658
3659 num_io_req = (cfg->fwcfg.num_ioim_reqs + cfg->fwcfg.num_fwtio_reqs);
3660 if (num_io_req > BFA_IO_MAX) {
3661 if (cfg->fwcfg.num_ioim_reqs && cfg->fwcfg.num_fwtio_reqs) {
3662 cfg->fwcfg.num_ioim_reqs = BFA_IO_MAX/2;
3663 cfg->fwcfg.num_fwtio_reqs = BFA_IO_MAX/2;
3664 } else if (cfg->fwcfg.num_fwtio_reqs)
3665 cfg->fwcfg.num_fwtio_reqs = BFA_FWTIO_MAX;
3666 else
3667 cfg->fwcfg.num_ioim_reqs = BFA_IOIM_MAX;
3668 }
3669
Krishna Gudipati45070252011-06-24 20:24:29 -07003670 bfa_fcpim_meminfo(cfg, &km_len);
Krishna Gudipatie2187d72011-06-13 15:53:58 -07003671
3672 num_io_req = (cfg->fwcfg.num_ioim_reqs + cfg->fwcfg.num_fwtio_reqs);
Krishna Gudipati45070252011-06-24 20:24:29 -07003673 km_len += num_io_req * sizeof(struct bfa_iotag_s);
3674 km_len += cfg->fwcfg.num_rports * sizeof(struct bfa_itn_s);
3675
3676 /* dma memory */
3677 nsegs = BFI_MEM_DMA_NSEGS(num_io_req, BFI_IOIM_SNSLEN);
3678 per_seg_ios = BFI_MEM_NREQS_SEG(BFI_IOIM_SNSLEN);
3679
3680 bfa_mem_dma_seg_iter(fcp, seg_ptr, nsegs, idx) {
3681 if (num_io_req >= per_seg_ios) {
3682 num_io_req -= per_seg_ios;
3683 bfa_mem_dma_setup(minfo, seg_ptr,
3684 per_seg_ios * BFI_IOIM_SNSLEN);
3685 } else
3686 bfa_mem_dma_setup(minfo, seg_ptr,
3687 num_io_req * BFI_IOIM_SNSLEN);
3688 }
3689
3690 /* kva memory */
3691 bfa_mem_kva_setup(minfo, fcp_kva, km_len);
Krishna Gudipatie2187d72011-06-13 15:53:58 -07003692}
3693
3694static void
3695bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07003696 struct bfa_pcidev_s *pcidev)
Krishna Gudipatie2187d72011-06-13 15:53:58 -07003697{
3698 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
Krishna Gudipati45070252011-06-24 20:24:29 -07003699 struct bfa_mem_dma_s *seg_ptr;
3700 u16 idx, nsegs, num_io_req;
Krishna Gudipatie2187d72011-06-13 15:53:58 -07003701
3702 fcp->num_ioim_reqs = cfg->fwcfg.num_ioim_reqs;
3703 fcp->num_fwtio_reqs = cfg->fwcfg.num_fwtio_reqs;
Krishna Gudipati45070252011-06-24 20:24:29 -07003704 fcp->num_itns = cfg->fwcfg.num_rports;
Krishna Gudipatie2187d72011-06-13 15:53:58 -07003705 fcp->bfa = bfa;
3706
Krishna Gudipati45070252011-06-24 20:24:29 -07003707 /*
3708 * Setup the pool of snsbase addr's, that is passed to fw as
3709 * part of bfi_iocfc_cfg_s.
3710 */
3711 num_io_req = (cfg->fwcfg.num_ioim_reqs + cfg->fwcfg.num_fwtio_reqs);
3712 nsegs = BFI_MEM_DMA_NSEGS(num_io_req, BFI_IOIM_SNSLEN);
Krishna Gudipatie2187d72011-06-13 15:53:58 -07003713
Krishna Gudipati45070252011-06-24 20:24:29 -07003714 bfa_mem_dma_seg_iter(fcp, seg_ptr, nsegs, idx) {
Krishna Gudipatie2187d72011-06-13 15:53:58 -07003715
Krishna Gudipati45070252011-06-24 20:24:29 -07003716 if (!bfa_mem_dma_virt(seg_ptr))
3717 break;
Krishna Gudipatie2187d72011-06-13 15:53:58 -07003718
Krishna Gudipati45070252011-06-24 20:24:29 -07003719 fcp->snsbase[idx].pa = bfa_mem_dma_phys(seg_ptr);
3720 fcp->snsbase[idx].kva = bfa_mem_dma_virt(seg_ptr);
3721 bfa_iocfc_set_snsbase(bfa, idx, fcp->snsbase[idx].pa);
3722 }
3723
3724 bfa_fcpim_attach(fcp, bfad, cfg, pcidev);
3725
3726 bfa_iotag_attach(fcp);
3727
3728 fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
3729 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
Krishna Gudipatie2187d72011-06-13 15:53:58 -07003730 (fcp->num_itns * sizeof(struct bfa_itn_s));
3731 memset(fcp->itn_arr, 0,
3732 (fcp->num_itns * sizeof(struct bfa_itn_s)));
Krishna Gudipatie2187d72011-06-13 15:53:58 -07003733}
3734
3735static void
3736bfa_fcp_detach(struct bfa_s *bfa)
3737{
3738}
3739
3740static void
3741bfa_fcp_start(struct bfa_s *bfa)
3742{
Krishna Gudipati83763d52011-07-20 17:04:03 -07003743 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
3744
3745 /*
3746 * bfa_init() with flash read is complete. now invalidate the stale
3747 * content of lun mask like unit attention, rp tag and lp tag.
3748 */
3749 bfa_ioim_lm_init(fcp->bfa);
Krishna Gudipatie2187d72011-06-13 15:53:58 -07003750}
3751
3752static void
3753bfa_fcp_stop(struct bfa_s *bfa)
3754{
3755}
3756
3757static void
3758bfa_fcp_iocdisable(struct bfa_s *bfa)
3759{
3760 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
3761
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003762 /* Enqueue unused ioim resources to free_q */
3763 list_splice_tail_init(&fcp->iotag_unused_q, &fcp->iotag_ioim_free_q);
3764
Krishna Gudipatie2187d72011-06-13 15:53:58 -07003765 bfa_fcpim_iocdisable(fcp);
3766}
3767
3768void
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003769bfa_fcp_res_recfg(struct bfa_s *bfa, u16 num_ioim_fw)
3770{
3771 struct bfa_fcp_mod_s *mod = BFA_FCP_MOD(bfa);
3772 struct list_head *qe;
3773 int i;
3774
3775 for (i = 0; i < (mod->num_ioim_reqs - num_ioim_fw); i++) {
3776 bfa_q_deq_tail(&mod->iotag_ioim_free_q, &qe);
3777 list_add_tail(qe, &mod->iotag_unused_q);
3778 }
3779}
3780
3781void
Krishna Gudipatie2187d72011-06-13 15:53:58 -07003782bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
3783 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
3784{
3785 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
3786 struct bfa_itn_s *itn;
3787
3788 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
3789 itn->isr = isr;
3790}
3791
3792/*
3793 * Itn interrupt processing.
3794 */
3795void
3796bfa_itn_isr(struct bfa_s *bfa, struct bfi_msg_s *m)
3797{
3798 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
3799 union bfi_itn_i2h_msg_u msg;
3800 struct bfa_itn_s *itn;
3801
3802 msg.msg = m;
3803 itn = BFA_ITN_FROM_TAG(fcp, msg.create_rsp->bfa_handle);
3804
3805 if (itn->isr)
3806 itn->isr(bfa, m);
3807 else
3808 WARN_ON(1);
3809}
3810
3811void
Krishna Gudipati45070252011-06-24 20:24:29 -07003812bfa_iotag_attach(struct bfa_fcp_mod_s *fcp)
Krishna Gudipatie2187d72011-06-13 15:53:58 -07003813{
3814 struct bfa_iotag_s *iotag;
3815 u16 num_io_req, i;
3816
Krishna Gudipati45070252011-06-24 20:24:29 -07003817 iotag = (struct bfa_iotag_s *) bfa_mem_kva_curp(fcp);
Krishna Gudipatie2187d72011-06-13 15:53:58 -07003818 fcp->iotag_arr = iotag;
3819
3820 INIT_LIST_HEAD(&fcp->iotag_ioim_free_q);
3821 INIT_LIST_HEAD(&fcp->iotag_tio_free_q);
Krishna Gudipati3fd45982011-06-24 20:24:08 -07003822 INIT_LIST_HEAD(&fcp->iotag_unused_q);
Krishna Gudipatie2187d72011-06-13 15:53:58 -07003823
3824 num_io_req = fcp->num_ioim_reqs + fcp->num_fwtio_reqs;
3825 for (i = 0; i < num_io_req; i++, iotag++) {
3826 memset(iotag, 0, sizeof(struct bfa_iotag_s));
3827 iotag->tag = i;
3828 if (i < fcp->num_ioim_reqs)
3829 list_add_tail(&iotag->qe, &fcp->iotag_ioim_free_q);
3830 else
3831 list_add_tail(&iotag->qe, &fcp->iotag_tio_free_q);
3832 }
3833
Krishna Gudipati45070252011-06-24 20:24:29 -07003834 bfa_mem_kva_curp(fcp) = (u8 *) iotag;
Krishna Gudipatie2187d72011-06-13 15:53:58 -07003835}