blob: 2e3b19e7e0798a744106ff88c9b8c720360741b2 [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
Anil Gurumurthy889d0d42015-11-26 03:54:45 -05002 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
3 * Copyright (c) 2014- QLogic Corporation.
Jing Huang7725ccf2009-09-23 17:46:15 -07004 * All rights reserved
Anil Gurumurthy889d0d42015-11-26 03:54:45 -05005 * www.qlogic.com
Jing Huang7725ccf2009-09-23 17:46:15 -07006 *
Anil Gurumurthy31e1d562015-11-26 03:54:46 -05007 * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
Jing Huang7725ccf2009-09-23 17:46:15 -07008 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License (GPL) Version 2 as
11 * published by the Free Software Foundation
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 */
18
Jing Huang5fbe25c2010-10-18 17:17:23 -070019/*
Jing Huang7725ccf2009-09-23 17:46:15 -070020 * fcpim.c - FCP initiator mode i-t nexus state machine
21 */
22
Maggie Zhangf16a1752010-12-09 19:12:32 -080023#include "bfad_drv.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070024#include "bfa_fcs.h"
25#include "bfa_fcbuild.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070026#include "bfad_im.h"
Jing Huang7725ccf2009-09-23 17:46:15 -070027
28BFA_TRC_FILE(FCS, FCPIM);
29
30/*
31 * forward declarations
32 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070033static void bfa_fcs_itnim_timeout(void *arg);
34static void bfa_fcs_itnim_free(struct bfa_fcs_itnim_s *itnim);
35static void bfa_fcs_itnim_send_prli(void *itnim_cbarg,
Jing Huang7725ccf2009-09-23 17:46:15 -070036 struct bfa_fcxp_s *fcxp_alloced);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070037static void bfa_fcs_itnim_prli_response(void *fcsarg,
38 struct bfa_fcxp_s *fcxp, void *cbarg,
39 bfa_status_t req_status, u32 rsp_len,
40 u32 resid_len, struct fchs_s *rsp_fchs);
Krishna Gudipati7826f302011-07-20 16:59:13 -070041static void bfa_fcs_itnim_aen_post(struct bfa_fcs_itnim_s *itnim,
42 enum bfa_itnim_aen_event event);
Jing Huang7725ccf2009-09-23 17:46:15 -070043
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070044static void bfa_fcs_itnim_sm_offline(struct bfa_fcs_itnim_s *itnim,
Jing Huang7725ccf2009-09-23 17:46:15 -070045 enum bfa_fcs_itnim_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070046static void bfa_fcs_itnim_sm_prli_send(struct bfa_fcs_itnim_s *itnim,
Jing Huang7725ccf2009-09-23 17:46:15 -070047 enum bfa_fcs_itnim_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070048static void bfa_fcs_itnim_sm_prli(struct bfa_fcs_itnim_s *itnim,
Jing Huang7725ccf2009-09-23 17:46:15 -070049 enum bfa_fcs_itnim_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070050static void bfa_fcs_itnim_sm_prli_retry(struct bfa_fcs_itnim_s *itnim,
Jing Huang7725ccf2009-09-23 17:46:15 -070051 enum bfa_fcs_itnim_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070052static void bfa_fcs_itnim_sm_hcb_online(struct bfa_fcs_itnim_s *itnim,
Jing Huang7725ccf2009-09-23 17:46:15 -070053 enum bfa_fcs_itnim_event event);
Krishna Gudipati61ba4392012-08-22 19:52:58 -070054static void bfa_fcs_itnim_sm_hal_rport_online(struct bfa_fcs_itnim_s *itnim,
55 enum bfa_fcs_itnim_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070056static void bfa_fcs_itnim_sm_online(struct bfa_fcs_itnim_s *itnim,
Jing Huang7725ccf2009-09-23 17:46:15 -070057 enum bfa_fcs_itnim_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070058static void bfa_fcs_itnim_sm_hcb_offline(struct bfa_fcs_itnim_s *itnim,
Jing Huang7725ccf2009-09-23 17:46:15 -070059 enum bfa_fcs_itnim_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070060static void bfa_fcs_itnim_sm_initiator(struct bfa_fcs_itnim_s *itnim,
Jing Huang7725ccf2009-09-23 17:46:15 -070061 enum bfa_fcs_itnim_event event);
62
63static struct bfa_sm_table_s itnim_sm_table[] = {
64 {BFA_SM(bfa_fcs_itnim_sm_offline), BFA_ITNIM_OFFLINE},
65 {BFA_SM(bfa_fcs_itnim_sm_prli_send), BFA_ITNIM_PRLI_SEND},
66 {BFA_SM(bfa_fcs_itnim_sm_prli), BFA_ITNIM_PRLI_SENT},
67 {BFA_SM(bfa_fcs_itnim_sm_prli_retry), BFA_ITNIM_PRLI_RETRY},
68 {BFA_SM(bfa_fcs_itnim_sm_hcb_online), BFA_ITNIM_HCB_ONLINE},
69 {BFA_SM(bfa_fcs_itnim_sm_online), BFA_ITNIM_ONLINE},
70 {BFA_SM(bfa_fcs_itnim_sm_hcb_offline), BFA_ITNIM_HCB_OFFLINE},
71 {BFA_SM(bfa_fcs_itnim_sm_initiator), BFA_ITNIM_INITIATIOR},
72};
73
Jing Huang5fbe25c2010-10-18 17:17:23 -070074/*
Jing Huang7725ccf2009-09-23 17:46:15 -070075 * fcs_itnim_sm FCS itnim state machine
76 */
77
78static void
79bfa_fcs_itnim_sm_offline(struct bfa_fcs_itnim_s *itnim,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070080 enum bfa_fcs_itnim_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -070081{
82 bfa_trc(itnim->fcs, itnim->rport->pwwn);
83 bfa_trc(itnim->fcs, event);
84
85 switch (event) {
Krishna Gudipati61ba4392012-08-22 19:52:58 -070086 case BFA_FCS_ITNIM_SM_FCS_ONLINE:
Jing Huang7725ccf2009-09-23 17:46:15 -070087 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_prli_send);
Jing Huang41188cf2010-07-08 19:52:00 -070088 itnim->prli_retries = 0;
Jing Huang7725ccf2009-09-23 17:46:15 -070089 bfa_fcs_itnim_send_prli(itnim, NULL);
90 break;
91
92 case BFA_FCS_ITNIM_SM_OFFLINE:
Maggie Zhangf7f738122010-12-09 19:08:43 -080093 bfa_sm_send_event(itnim->rport, RPSM_EVENT_FC4_OFFLINE);
Jing Huang7725ccf2009-09-23 17:46:15 -070094 break;
95
96 case BFA_FCS_ITNIM_SM_INITIATOR:
97 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_initiator);
98 break;
99
100 case BFA_FCS_ITNIM_SM_DELETE:
101 bfa_fcs_itnim_free(itnim);
102 break;
103
104 default:
Krishna Gudipatie641de32010-03-05 19:35:02 -0800105 bfa_sm_fault(itnim->fcs, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700106 }
107
108}
109
110static void
111bfa_fcs_itnim_sm_prli_send(struct bfa_fcs_itnim_s *itnim,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700112 enum bfa_fcs_itnim_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700113{
114 bfa_trc(itnim->fcs, itnim->rport->pwwn);
115 bfa_trc(itnim->fcs, event);
116
117 switch (event) {
118 case BFA_FCS_ITNIM_SM_FRMSENT:
119 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_prli);
120 break;
121
122 case BFA_FCS_ITNIM_SM_INITIATOR:
123 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_initiator);
124 bfa_fcxp_walloc_cancel(itnim->fcs->bfa, &itnim->fcxp_wqe);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700125 bfa_sm_send_event(itnim->rport, RPSM_EVENT_FC4_FCS_ONLINE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700126 break;
127
128 case BFA_FCS_ITNIM_SM_OFFLINE:
129 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline);
130 bfa_fcxp_walloc_cancel(itnim->fcs->bfa, &itnim->fcxp_wqe);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800131 bfa_sm_send_event(itnim->rport, RPSM_EVENT_FC4_OFFLINE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700132 break;
133
134 case BFA_FCS_ITNIM_SM_DELETE:
135 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline);
136 bfa_fcxp_walloc_cancel(itnim->fcs->bfa, &itnim->fcxp_wqe);
137 bfa_fcs_itnim_free(itnim);
138 break;
139
140 default:
Krishna Gudipatie641de32010-03-05 19:35:02 -0800141 bfa_sm_fault(itnim->fcs, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700142 }
143}
144
145static void
146bfa_fcs_itnim_sm_prli(struct bfa_fcs_itnim_s *itnim,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700147 enum bfa_fcs_itnim_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700148{
149 bfa_trc(itnim->fcs, itnim->rport->pwwn);
150 bfa_trc(itnim->fcs, event);
151
152 switch (event) {
153 case BFA_FCS_ITNIM_SM_RSP_OK:
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700154 if (itnim->rport->scsi_function == BFA_RPORT_INITIATOR)
Jing Huang4b5e7592010-07-08 19:55:41 -0700155 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_initiator);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700156 else
157 bfa_sm_set_state(itnim,
158 bfa_fcs_itnim_sm_hal_rport_online);
159
160 bfa_sm_send_event(itnim->rport, RPSM_EVENT_FC4_FCS_ONLINE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700161 break;
162
163 case BFA_FCS_ITNIM_SM_RSP_ERROR:
164 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_prli_retry);
165 bfa_timer_start(itnim->fcs->bfa, &itnim->timer,
166 bfa_fcs_itnim_timeout, itnim,
167 BFA_FCS_RETRY_TIMEOUT);
168 break;
169
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700170 case BFA_FCS_ITNIM_SM_RSP_NOT_SUPP:
171 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline);
172 break;
173
Jing Huang7725ccf2009-09-23 17:46:15 -0700174 case BFA_FCS_ITNIM_SM_OFFLINE:
175 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline);
176 bfa_fcxp_discard(itnim->fcxp);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800177 bfa_sm_send_event(itnim->rport, RPSM_EVENT_FC4_OFFLINE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700178 break;
179
180 case BFA_FCS_ITNIM_SM_INITIATOR:
181 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_initiator);
Jing Huang4b5e7592010-07-08 19:55:41 -0700182 bfa_fcxp_discard(itnim->fcxp);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700183 bfa_sm_send_event(itnim->rport, RPSM_EVENT_FC4_FCS_ONLINE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700184 break;
185
186 case BFA_FCS_ITNIM_SM_DELETE:
187 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline);
188 bfa_fcxp_discard(itnim->fcxp);
189 bfa_fcs_itnim_free(itnim);
190 break;
191
192 default:
Krishna Gudipatie641de32010-03-05 19:35:02 -0800193 bfa_sm_fault(itnim->fcs, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700194 }
195}
196
197static void
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700198bfa_fcs_itnim_sm_hal_rport_online(struct bfa_fcs_itnim_s *itnim,
199 enum bfa_fcs_itnim_event event)
200{
201 bfa_trc(itnim->fcs, itnim->rport->pwwn);
202 bfa_trc(itnim->fcs, event);
203
204 switch (event) {
205 case BFA_FCS_ITNIM_SM_HAL_ONLINE:
206 if (!itnim->bfa_itnim)
207 itnim->bfa_itnim = bfa_itnim_create(itnim->fcs->bfa,
208 itnim->rport->bfa_rport, itnim);
209
210 if (itnim->bfa_itnim) {
211 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_hcb_online);
212 bfa_itnim_online(itnim->bfa_itnim, itnim->seq_rec);
213 } else {
214 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline);
215 bfa_sm_send_event(itnim->rport, RPSM_EVENT_DELETE);
216 }
217
218 break;
219
220 case BFA_FCS_ITNIM_SM_OFFLINE:
221 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline);
222 bfa_sm_send_event(itnim->rport, RPSM_EVENT_FC4_OFFLINE);
223 break;
224
225 case BFA_FCS_ITNIM_SM_DELETE:
226 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline);
227 bfa_fcs_itnim_free(itnim);
228 break;
229
230 default:
231 bfa_sm_fault(itnim->fcs, event);
232 }
233}
234
235static void
Jing Huang7725ccf2009-09-23 17:46:15 -0700236bfa_fcs_itnim_sm_prli_retry(struct bfa_fcs_itnim_s *itnim,
237 enum bfa_fcs_itnim_event event)
238{
239 bfa_trc(itnim->fcs, itnim->rport->pwwn);
240 bfa_trc(itnim->fcs, event);
241
242 switch (event) {
243 case BFA_FCS_ITNIM_SM_TIMEOUT:
Jing Huang41188cf2010-07-08 19:52:00 -0700244 if (itnim->prli_retries < BFA_FCS_RPORT_MAX_RETRIES) {
245 itnim->prli_retries++;
246 bfa_trc(itnim->fcs, itnim->prli_retries);
247 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_prli_send);
248 bfa_fcs_itnim_send_prli(itnim, NULL);
249 } else {
250 /* invoke target offline */
251 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800252 bfa_sm_send_event(itnim->rport, RPSM_EVENT_LOGO_IMP);
Jing Huang41188cf2010-07-08 19:52:00 -0700253 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700254 break;
255
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700256
Jing Huang7725ccf2009-09-23 17:46:15 -0700257 case BFA_FCS_ITNIM_SM_OFFLINE:
258 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline);
259 bfa_timer_stop(&itnim->timer);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800260 bfa_sm_send_event(itnim->rport, RPSM_EVENT_FC4_OFFLINE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700261 break;
262
263 case BFA_FCS_ITNIM_SM_INITIATOR:
264 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_initiator);
265 bfa_timer_stop(&itnim->timer);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700266 bfa_sm_send_event(itnim->rport, RPSM_EVENT_FC4_FCS_ONLINE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700267 break;
268
269 case BFA_FCS_ITNIM_SM_DELETE:
270 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline);
271 bfa_timer_stop(&itnim->timer);
272 bfa_fcs_itnim_free(itnim);
273 break;
274
275 default:
Krishna Gudipatie641de32010-03-05 19:35:02 -0800276 bfa_sm_fault(itnim->fcs, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700277 }
278}
279
280static void
281bfa_fcs_itnim_sm_hcb_online(struct bfa_fcs_itnim_s *itnim,
282 enum bfa_fcs_itnim_event event)
283{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700284 struct bfad_s *bfad = (struct bfad_s *)itnim->fcs->bfad;
285 char lpwwn_buf[BFA_STRING_32];
286 char rpwwn_buf[BFA_STRING_32];
287
Jing Huang7725ccf2009-09-23 17:46:15 -0700288 bfa_trc(itnim->fcs, itnim->rport->pwwn);
289 bfa_trc(itnim->fcs, event);
290
291 switch (event) {
292 case BFA_FCS_ITNIM_SM_HCB_ONLINE:
293 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_online);
294 bfa_fcb_itnim_online(itnim->itnim_drv);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700295 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(itnim->rport->port));
296 wwn2str(rpwwn_buf, itnim->rport->pwwn);
Jing Huang88166242010-12-09 17:11:53 -0800297 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700298 "Target (WWN = %s) is online for initiator (WWN = %s)\n",
299 rpwwn_buf, lpwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -0700300 bfa_fcs_itnim_aen_post(itnim, BFA_ITNIM_AEN_ONLINE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700301 break;
302
303 case BFA_FCS_ITNIM_SM_OFFLINE:
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700304 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_hcb_offline);
Jing Huang7725ccf2009-09-23 17:46:15 -0700305 bfa_itnim_offline(itnim->bfa_itnim);
Jing Huang7725ccf2009-09-23 17:46:15 -0700306 break;
307
308 case BFA_FCS_ITNIM_SM_DELETE:
309 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline);
310 bfa_fcs_itnim_free(itnim);
311 break;
312
313 default:
Krishna Gudipatie641de32010-03-05 19:35:02 -0800314 bfa_sm_fault(itnim->fcs, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700315 }
316}
317
318static void
319bfa_fcs_itnim_sm_online(struct bfa_fcs_itnim_s *itnim,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700320 enum bfa_fcs_itnim_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700321{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700322 struct bfad_s *bfad = (struct bfad_s *)itnim->fcs->bfad;
323 char lpwwn_buf[BFA_STRING_32];
324 char rpwwn_buf[BFA_STRING_32];
325
Jing Huang7725ccf2009-09-23 17:46:15 -0700326 bfa_trc(itnim->fcs, itnim->rport->pwwn);
327 bfa_trc(itnim->fcs, event);
328
329 switch (event) {
330 case BFA_FCS_ITNIM_SM_OFFLINE:
331 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_hcb_offline);
332 bfa_fcb_itnim_offline(itnim->itnim_drv);
333 bfa_itnim_offline(itnim->bfa_itnim);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700334 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(itnim->rport->port));
335 wwn2str(rpwwn_buf, itnim->rport->pwwn);
Krishna Gudipati7826f302011-07-20 16:59:13 -0700336 if (bfa_fcs_lport_is_online(itnim->rport->port) == BFA_TRUE) {
Jing Huang88166242010-12-09 17:11:53 -0800337 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700338 "Target (WWN = %s) connectivity lost for "
339 "initiator (WWN = %s)\n", rpwwn_buf, lpwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -0700340 bfa_fcs_itnim_aen_post(itnim, BFA_ITNIM_AEN_DISCONNECT);
341 } else {
Jing Huang88166242010-12-09 17:11:53 -0800342 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700343 "Target (WWN = %s) offlined by initiator (WWN = %s)\n",
344 rpwwn_buf, lpwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -0700345 bfa_fcs_itnim_aen_post(itnim, BFA_ITNIM_AEN_OFFLINE);
346 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700347 break;
348
349 case BFA_FCS_ITNIM_SM_DELETE:
350 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline);
351 bfa_fcs_itnim_free(itnim);
352 break;
353
354 default:
Krishna Gudipatie641de32010-03-05 19:35:02 -0800355 bfa_sm_fault(itnim->fcs, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700356 }
357}
358
359static void
360bfa_fcs_itnim_sm_hcb_offline(struct bfa_fcs_itnim_s *itnim,
361 enum bfa_fcs_itnim_event event)
362{
363 bfa_trc(itnim->fcs, itnim->rport->pwwn);
364 bfa_trc(itnim->fcs, event);
365
366 switch (event) {
367 case BFA_FCS_ITNIM_SM_HCB_OFFLINE:
368 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800369 bfa_sm_send_event(itnim->rport, RPSM_EVENT_FC4_OFFLINE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700370 break;
371
372 case BFA_FCS_ITNIM_SM_DELETE:
373 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline);
374 bfa_fcs_itnim_free(itnim);
375 break;
376
377 default:
Krishna Gudipatie641de32010-03-05 19:35:02 -0800378 bfa_sm_fault(itnim->fcs, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700379 }
380}
381
382/*
383 * This state is set when a discovered rport is also in intiator mode.
384 * This ITN is marked as no_op and is not active and will not be truned into
385 * online state.
386 */
387static void
388bfa_fcs_itnim_sm_initiator(struct bfa_fcs_itnim_s *itnim,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700389 enum bfa_fcs_itnim_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700390{
391 bfa_trc(itnim->fcs, itnim->rport->pwwn);
392 bfa_trc(itnim->fcs, event);
393
394 switch (event) {
395 case BFA_FCS_ITNIM_SM_OFFLINE:
396 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800397 bfa_sm_send_event(itnim->rport, RPSM_EVENT_FC4_OFFLINE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700398 break;
399
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700400 /*
401 * fcs_online is expected here for well known initiator ports
402 */
403 case BFA_FCS_ITNIM_SM_FCS_ONLINE:
404 bfa_sm_send_event(itnim->rport, RPSM_EVENT_FC4_FCS_ONLINE);
405 break;
406
Jing Huang7725ccf2009-09-23 17:46:15 -0700407 case BFA_FCS_ITNIM_SM_RSP_ERROR:
Jing Huang7725ccf2009-09-23 17:46:15 -0700408 case BFA_FCS_ITNIM_SM_INITIATOR:
409 break;
410
411 case BFA_FCS_ITNIM_SM_DELETE:
412 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline);
413 bfa_fcs_itnim_free(itnim);
414 break;
415
416 default:
Krishna Gudipatie641de32010-03-05 19:35:02 -0800417 bfa_sm_fault(itnim->fcs, event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700418 }
419}
420
Jing Huang7725ccf2009-09-23 17:46:15 -0700421static void
Krishna Gudipati7826f302011-07-20 16:59:13 -0700422bfa_fcs_itnim_aen_post(struct bfa_fcs_itnim_s *itnim,
423 enum bfa_itnim_aen_event event)
424{
425 struct bfa_fcs_rport_s *rport = itnim->rport;
426 struct bfad_s *bfad = (struct bfad_s *)itnim->fcs->bfad;
427 struct bfa_aen_entry_s *aen_entry;
428
429 /* Don't post events for well known addresses */
430 if (BFA_FCS_PID_IS_WKA(rport->pid))
431 return;
432
433 bfad_get_aen_entry(bfad, aen_entry);
434 if (!aen_entry)
435 return;
436
437 aen_entry->aen_data.itnim.vf_id = rport->port->fabric->vf_id;
438 aen_entry->aen_data.itnim.ppwwn = bfa_fcs_lport_get_pwwn(
439 bfa_fcs_get_base_port(itnim->fcs));
440 aen_entry->aen_data.itnim.lpwwn = bfa_fcs_lport_get_pwwn(rport->port);
441 aen_entry->aen_data.itnim.rpwwn = rport->pwwn;
442
443 /* Send the AEN notification */
444 bfad_im_post_vendor_event(aen_entry, bfad, ++rport->fcs->fcs_aen_seq,
445 BFA_AEN_CAT_ITNIM, event);
446}
447
448static void
Jing Huang7725ccf2009-09-23 17:46:15 -0700449bfa_fcs_itnim_send_prli(void *itnim_cbarg, struct bfa_fcxp_s *fcxp_alloced)
450{
451 struct bfa_fcs_itnim_s *itnim = itnim_cbarg;
452 struct bfa_fcs_rport_s *rport = itnim->rport;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700453 struct bfa_fcs_lport_s *port = rport->port;
454 struct fchs_s fchs;
Jing Huang7725ccf2009-09-23 17:46:15 -0700455 struct bfa_fcxp_s *fcxp;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700456 int len;
Jing Huang7725ccf2009-09-23 17:46:15 -0700457
458 bfa_trc(itnim->fcs, itnim->rport->pwwn);
459
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700460 fcxp = fcxp_alloced ? fcxp_alloced :
461 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700462 if (!fcxp) {
463 itnim->stats.fcxp_alloc_wait++;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700464 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &itnim->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -0700465 bfa_fcs_itnim_send_prli, itnim, BFA_TRUE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700466 return;
467 }
468 itnim->fcxp = fcxp;
469
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700470 len = fc_prli_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
471 itnim->rport->pid, bfa_fcs_lport_get_fcid(port), 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700472
473 bfa_fcxp_send(fcxp, rport->bfa_rport, port->fabric->vf_id, port->lp_tag,
474 BFA_FALSE, FC_CLASS_3, len, &fchs,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700475 bfa_fcs_itnim_prli_response, (void *)itnim,
476 FC_MAX_PDUSZ, FC_ELS_TOV);
Jing Huang7725ccf2009-09-23 17:46:15 -0700477
478 itnim->stats.prli_sent++;
479 bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_FRMSENT);
480}
481
482static void
483bfa_fcs_itnim_prli_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
484 bfa_status_t req_status, u32 rsp_len,
485 u32 resid_len, struct fchs_s *rsp_fchs)
486{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700487 struct bfa_fcs_itnim_s *itnim = (struct bfa_fcs_itnim_s *) cbarg;
488 struct fc_els_cmd_s *els_cmd;
489 struct fc_prli_s *prli_resp;
490 struct fc_ls_rjt_s *ls_rjt;
Jing Huang7725ccf2009-09-23 17:46:15 -0700491 struct fc_prli_params_s *sparams;
492
493 bfa_trc(itnim->fcs, req_status);
494
495 /*
496 * Sanity Checks
497 */
498 if (req_status != BFA_STATUS_OK) {
499 itnim->stats.prli_rsp_err++;
500 bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_RSP_ERROR);
501 return;
502 }
503
504 els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
505
506 if (els_cmd->els_code == FC_ELS_ACC) {
507 prli_resp = (struct fc_prli_s *) els_cmd;
508
509 if (fc_prli_rsp_parse(prli_resp, rsp_len) != FC_PARSE_OK) {
510 bfa_trc(itnim->fcs, rsp_len);
511 /*
512 * Check if this r-port is also in Initiator mode.
513 * If so, we need to set this ITN as a no-op.
514 */
515 if (prli_resp->parampage.servparams.initiator) {
516 bfa_trc(itnim->fcs, prli_resp->parampage.type);
517 itnim->rport->scsi_function =
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700518 BFA_RPORT_INITIATOR;
Jing Huang7725ccf2009-09-23 17:46:15 -0700519 itnim->stats.prli_rsp_acc++;
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700520 itnim->stats.initiator++;
Jing Huang7725ccf2009-09-23 17:46:15 -0700521 bfa_sm_send_event(itnim,
Jing Huang4b5e7592010-07-08 19:55:41 -0700522 BFA_FCS_ITNIM_SM_RSP_OK);
Jing Huang7725ccf2009-09-23 17:46:15 -0700523 return;
524 }
525
526 itnim->stats.prli_rsp_parse_err++;
527 return;
528 }
529 itnim->rport->scsi_function = BFA_RPORT_TARGET;
530
531 sparams = &prli_resp->parampage.servparams;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700532 itnim->seq_rec = sparams->retry;
533 itnim->rec_support = sparams->rec_support;
Jing Huang7725ccf2009-09-23 17:46:15 -0700534 itnim->task_retry_id = sparams->task_retry_id;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700535 itnim->conf_comp = sparams->confirm;
Jing Huang7725ccf2009-09-23 17:46:15 -0700536
537 itnim->stats.prli_rsp_acc++;
538 bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_RSP_OK);
539 } else {
540 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
541
542 bfa_trc(itnim->fcs, ls_rjt->reason_code);
543 bfa_trc(itnim->fcs, ls_rjt->reason_code_expl);
544
545 itnim->stats.prli_rsp_rjt++;
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700546 if (ls_rjt->reason_code == FC_LS_RJT_RSN_CMD_NOT_SUPP) {
547 bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_RSP_NOT_SUPP);
548 return;
549 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700550 bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_RSP_ERROR);
551 }
552}
553
554static void
555bfa_fcs_itnim_timeout(void *arg)
556{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700557 struct bfa_fcs_itnim_s *itnim = (struct bfa_fcs_itnim_s *) arg;
Jing Huang7725ccf2009-09-23 17:46:15 -0700558
559 itnim->stats.timeout++;
560 bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_TIMEOUT);
561}
562
563static void
564bfa_fcs_itnim_free(struct bfa_fcs_itnim_s *itnim)
565{
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700566 if (itnim->bfa_itnim) {
567 bfa_itnim_delete(itnim->bfa_itnim);
568 itnim->bfa_itnim = NULL;
569 }
570
Jing Huang7725ccf2009-09-23 17:46:15 -0700571 bfa_fcb_itnim_free(itnim->fcs->bfad, itnim->itnim_drv);
572}
573
574
575
Jing Huang5fbe25c2010-10-18 17:17:23 -0700576/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700577 * itnim_public FCS ITNIM public interfaces
578 */
579
Jing Huang5fbe25c2010-10-18 17:17:23 -0700580/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700581 * Called by rport when a new rport is created.
Jing Huang7725ccf2009-09-23 17:46:15 -0700582 *
583 * @param[in] rport - remote port.
584 */
585struct bfa_fcs_itnim_s *
586bfa_fcs_itnim_create(struct bfa_fcs_rport_s *rport)
587{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700588 struct bfa_fcs_lport_s *port = rport->port;
Jing Huang7725ccf2009-09-23 17:46:15 -0700589 struct bfa_fcs_itnim_s *itnim;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700590 struct bfad_itnim_s *itnim_drv;
Dan Carpenter4e51af92016-04-13 14:14:41 +0300591 int ret;
Jing Huang7725ccf2009-09-23 17:46:15 -0700592
593 /*
594 * call bfad to allocate the itnim
595 */
Dan Carpenter4e51af92016-04-13 14:14:41 +0300596 ret = bfa_fcb_itnim_alloc(port->fcs->bfad, &itnim, &itnim_drv);
597 if (ret) {
Jing Huang7725ccf2009-09-23 17:46:15 -0700598 bfa_trc(port->fcs, rport->pwwn);
599 return NULL;
600 }
601
602 /*
603 * Initialize itnim
604 */
605 itnim->rport = rport;
606 itnim->fcs = rport->fcs;
607 itnim->itnim_drv = itnim_drv;
608
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700609 itnim->bfa_itnim = NULL;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700610 itnim->seq_rec = BFA_FALSE;
611 itnim->rec_support = BFA_FALSE;
612 itnim->conf_comp = BFA_FALSE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700613 itnim->task_retry_id = BFA_FALSE;
614
615 /*
616 * Set State machine
617 */
618 bfa_sm_set_state(itnim, bfa_fcs_itnim_sm_offline);
619
620 return itnim;
621}
622
Jing Huang5fbe25c2010-10-18 17:17:23 -0700623/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700624 * Called by rport to delete the instance of FCPIM.
Jing Huang7725ccf2009-09-23 17:46:15 -0700625 *
626 * @param[in] rport - remote port.
627 */
628void
629bfa_fcs_itnim_delete(struct bfa_fcs_itnim_s *itnim)
630{
631 bfa_trc(itnim->fcs, itnim->rport->pid);
632 bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_DELETE);
633}
634
Jing Huang5fbe25c2010-10-18 17:17:23 -0700635/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700636 * Notification from rport that PLOGI is complete to initiate FC-4 session.
637 */
638void
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700639bfa_fcs_itnim_brp_online(struct bfa_fcs_itnim_s *itnim)
Jing Huang7725ccf2009-09-23 17:46:15 -0700640{
641 itnim->stats.onlines++;
642
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700643 if (!BFA_FCS_PID_IS_WKA(itnim->rport->pid))
644 bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_HAL_ONLINE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700645}
646
Jing Huang5fbe25c2010-10-18 17:17:23 -0700647/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700648 * Called by rport to handle a remote device offline.
649 */
650void
651bfa_fcs_itnim_rport_offline(struct bfa_fcs_itnim_s *itnim)
652{
653 itnim->stats.offlines++;
654 bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_OFFLINE);
655}
656
Jing Huang5fbe25c2010-10-18 17:17:23 -0700657/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700658 * Called by rport when remote port is known to be an initiator from
659 * PRLI received.
660 */
661void
662bfa_fcs_itnim_is_initiator(struct bfa_fcs_itnim_s *itnim)
663{
664 bfa_trc(itnim->fcs, itnim->rport->pid);
665 itnim->stats.initiator++;
666 bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_INITIATOR);
667}
668
Jing Huang5fbe25c2010-10-18 17:17:23 -0700669/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700670 * Called by rport to check if the itnim is online.
671 */
672bfa_status_t
673bfa_fcs_itnim_get_online_state(struct bfa_fcs_itnim_s *itnim)
674{
675 bfa_trc(itnim->fcs, itnim->rport->pid);
676 switch (bfa_sm_to_state(itnim_sm_table, itnim->sm)) {
677 case BFA_ITNIM_ONLINE:
678 case BFA_ITNIM_INITIATIOR:
679 return BFA_STATUS_OK;
680
681 default:
682 return BFA_STATUS_NO_FCPIM_NEXUS;
Jing Huang7725ccf2009-09-23 17:46:15 -0700683 }
684}
685
Jing Huang5fbe25c2010-10-18 17:17:23 -0700686/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700687 * BFA completion callback for bfa_itnim_online().
688 */
689void
690bfa_cb_itnim_online(void *cbarg)
691{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700692 struct bfa_fcs_itnim_s *itnim = (struct bfa_fcs_itnim_s *) cbarg;
Jing Huang7725ccf2009-09-23 17:46:15 -0700693
694 bfa_trc(itnim->fcs, itnim->rport->pwwn);
695 bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_HCB_ONLINE);
696}
697
Jing Huang5fbe25c2010-10-18 17:17:23 -0700698/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700699 * BFA completion callback for bfa_itnim_offline().
700 */
701void
702bfa_cb_itnim_offline(void *cb_arg)
703{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700704 struct bfa_fcs_itnim_s *itnim = (struct bfa_fcs_itnim_s *) cb_arg;
Jing Huang7725ccf2009-09-23 17:46:15 -0700705
706 bfa_trc(itnim->fcs, itnim->rport->pwwn);
707 bfa_sm_send_event(itnim, BFA_FCS_ITNIM_SM_HCB_OFFLINE);
708}
709
Jing Huang5fbe25c2010-10-18 17:17:23 -0700710/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700711 * Mark the beginning of PATH TOV handling. IO completion callbacks
712 * are still pending.
713 */
714void
715bfa_cb_itnim_tov_begin(void *cb_arg)
716{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700717 struct bfa_fcs_itnim_s *itnim = (struct bfa_fcs_itnim_s *) cb_arg;
Jing Huang7725ccf2009-09-23 17:46:15 -0700718
719 bfa_trc(itnim->fcs, itnim->rport->pwwn);
Jing Huang7725ccf2009-09-23 17:46:15 -0700720}
721
Jing Huang5fbe25c2010-10-18 17:17:23 -0700722/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700723 * Mark the end of PATH TOV handling. All pending IOs are already cleaned up.
724 */
725void
726bfa_cb_itnim_tov(void *cb_arg)
727{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700728 struct bfa_fcs_itnim_s *itnim = (struct bfa_fcs_itnim_s *) cb_arg;
729 struct bfad_itnim_s *itnim_drv = itnim->itnim_drv;
Jing Huang7725ccf2009-09-23 17:46:15 -0700730
731 bfa_trc(itnim->fcs, itnim->rport->pwwn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700732 itnim_drv->state = ITNIM_STATE_TIMEOUT;
Jing Huang7725ccf2009-09-23 17:46:15 -0700733}
734
Jing Huang5fbe25c2010-10-18 17:17:23 -0700735/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700736 * BFA notification to FCS/driver for second level error recovery.
Jing Huang7725ccf2009-09-23 17:46:15 -0700737 *
738 * Atleast one I/O request has timedout and target is unresponsive to
739 * repeated abort requests. Second level error recovery should be initiated
740 * by starting implicit logout and recovery procedures.
741 */
742void
743bfa_cb_itnim_sler(void *cb_arg)
744{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700745 struct bfa_fcs_itnim_s *itnim = (struct bfa_fcs_itnim_s *) cb_arg;
Jing Huang7725ccf2009-09-23 17:46:15 -0700746
747 itnim->stats.sler++;
748 bfa_trc(itnim->fcs, itnim->rport->pwwn);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800749 bfa_sm_send_event(itnim->rport, RPSM_EVENT_LOGO_IMP);
Jing Huang7725ccf2009-09-23 17:46:15 -0700750}
751
752struct bfa_fcs_itnim_s *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700753bfa_fcs_itnim_lookup(struct bfa_fcs_lport_s *port, wwn_t rpwwn)
Jing Huang7725ccf2009-09-23 17:46:15 -0700754{
755 struct bfa_fcs_rport_s *rport;
756 rport = bfa_fcs_rport_lookup(port, rpwwn);
757
758 if (!rport)
759 return NULL;
760
Jing Huangd4b671c2010-12-26 21:46:35 -0800761 WARN_ON(rport->itnim == NULL);
Jing Huangf8ceafd2009-09-25 12:29:54 -0700762 return rport->itnim;
Jing Huang7725ccf2009-09-23 17:46:15 -0700763}
764
765bfa_status_t
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700766bfa_fcs_itnim_attr_get(struct bfa_fcs_lport_s *port, wwn_t rpwwn,
Jing Huang7725ccf2009-09-23 17:46:15 -0700767 struct bfa_itnim_attr_s *attr)
768{
769 struct bfa_fcs_itnim_s *itnim = NULL;
770
771 itnim = bfa_fcs_itnim_lookup(port, rpwwn);
772
773 if (itnim == NULL)
774 return BFA_STATUS_NO_FCPIM_NEXUS;
775
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700776 attr->state = bfa_sm_to_state(itnim_sm_table, itnim->sm);
777 attr->retry = itnim->seq_rec;
778 attr->rec_support = itnim->rec_support;
779 attr->conf_comp = itnim->conf_comp;
Jing Huang7725ccf2009-09-23 17:46:15 -0700780 attr->task_retry_id = itnim->task_retry_id;
Jing Huang7725ccf2009-09-23 17:46:15 -0700781 return BFA_STATUS_OK;
782}
783
784bfa_status_t
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700785bfa_fcs_itnim_stats_get(struct bfa_fcs_lport_s *port, wwn_t rpwwn,
Jing Huang7725ccf2009-09-23 17:46:15 -0700786 struct bfa_itnim_stats_s *stats)
787{
788 struct bfa_fcs_itnim_s *itnim = NULL;
789
Jing Huangd4b671c2010-12-26 21:46:35 -0800790 WARN_ON(port == NULL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700791
792 itnim = bfa_fcs_itnim_lookup(port, rpwwn);
793
794 if (itnim == NULL)
795 return BFA_STATUS_NO_FCPIM_NEXUS;
796
Jing Huang6a18b162010-10-18 17:08:54 -0700797 memcpy(stats, &itnim->stats, sizeof(struct bfa_itnim_stats_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700798
799 return BFA_STATUS_OK;
800}
801
802bfa_status_t
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700803bfa_fcs_itnim_stats_clear(struct bfa_fcs_lport_s *port, wwn_t rpwwn)
Jing Huang7725ccf2009-09-23 17:46:15 -0700804{
805 struct bfa_fcs_itnim_s *itnim = NULL;
806
Jing Huangd4b671c2010-12-26 21:46:35 -0800807 WARN_ON(port == NULL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700808
809 itnim = bfa_fcs_itnim_lookup(port, rpwwn);
810
811 if (itnim == NULL)
812 return BFA_STATUS_NO_FCPIM_NEXUS;
813
Jing Huang6a18b162010-10-18 17:08:54 -0700814 memset(&itnim->stats, 0, sizeof(struct bfa_itnim_stats_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700815 return BFA_STATUS_OK;
816}
817
818void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700819bfa_fcs_fcpim_uf_recv(struct bfa_fcs_itnim_s *itnim,
820 struct fchs_s *fchs, u16 len)
Jing Huang7725ccf2009-09-23 17:46:15 -0700821{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700822 struct fc_els_cmd_s *els_cmd;
Jing Huang7725ccf2009-09-23 17:46:15 -0700823
824 bfa_trc(itnim->fcs, fchs->type);
825
826 if (fchs->type != FC_TYPE_ELS)
827 return;
828
829 els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
830
831 bfa_trc(itnim->fcs, els_cmd->els_code);
832
833 switch (els_cmd->els_code) {
834 case FC_ELS_PRLO:
Jing Huang4b5e7592010-07-08 19:55:41 -0700835 bfa_fcs_rport_prlo(itnim->rport, fchs->ox_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700836 break;
837
838 default:
Jing Huangd4b671c2010-12-26 21:46:35 -0800839 WARN_ON(1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700840 }
841}