blob: cc43b2a58ce33ac9478cc25b9c9fc0509f4eeb96 [file] [log] [blame]
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001/*
2 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
3 * All rights reserved
4 * www.brocade.com
5 *
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License (GPL) Version 2 as
10 * published by the Free Software Foundation
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 */
17
Jing Huang5fbe25c2010-10-18 17:17:23 -070018/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070019 * rport.c Remote port implementation.
20 */
21
Maggie Zhangf16a1752010-12-09 19:12:32 -080022#include "bfad_drv.h"
Krishna Gudipati7826f302011-07-20 16:59:13 -070023#include "bfad_im.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
27BFA_TRC_FILE(FCS, RPORT);
28
29static u32
30bfa_fcs_rport_del_timeout = BFA_FCS_RPORT_DEF_DEL_TIMEOUT * 1000;
31 /* In millisecs */
32/*
Krishna Gudipati61ba4392012-08-22 19:52:58 -070033 * bfa_fcs_rport_max_logins is max count of bfa_fcs_rports
34 * whereas DEF_CFG_NUM_RPORTS is max count of bfa_rports
35 */
36static u32 bfa_fcs_rport_max_logins = BFA_FCS_MAX_RPORT_LOGINS;
37
38/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070039 * forward declarations
40 */
41static struct bfa_fcs_rport_s *bfa_fcs_rport_alloc(
42 struct bfa_fcs_lport_s *port, wwn_t pwwn, u32 rpid);
43static void bfa_fcs_rport_free(struct bfa_fcs_rport_s *rport);
44static void bfa_fcs_rport_hal_online(struct bfa_fcs_rport_s *rport);
Krishna Gudipati61ba4392012-08-22 19:52:58 -070045static void bfa_fcs_rport_fcs_online_action(struct bfa_fcs_rport_s *rport);
46static void bfa_fcs_rport_hal_online_action(struct bfa_fcs_rport_s *rport);
47static void bfa_fcs_rport_fcs_offline_action(struct bfa_fcs_rport_s *rport);
48static void bfa_fcs_rport_hal_offline_action(struct bfa_fcs_rport_s *rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070049static void bfa_fcs_rport_update(struct bfa_fcs_rport_s *rport,
50 struct fc_logi_s *plogi);
51static void bfa_fcs_rport_timeout(void *arg);
52static void bfa_fcs_rport_send_plogi(void *rport_cbarg,
53 struct bfa_fcxp_s *fcxp_alloced);
54static void bfa_fcs_rport_send_plogiacc(void *rport_cbarg,
55 struct bfa_fcxp_s *fcxp_alloced);
56static void bfa_fcs_rport_plogi_response(void *fcsarg,
57 struct bfa_fcxp_s *fcxp, void *cbarg,
58 bfa_status_t req_status, u32 rsp_len,
59 u32 resid_len, struct fchs_s *rsp_fchs);
60static void bfa_fcs_rport_send_adisc(void *rport_cbarg,
61 struct bfa_fcxp_s *fcxp_alloced);
62static void bfa_fcs_rport_adisc_response(void *fcsarg,
63 struct bfa_fcxp_s *fcxp, void *cbarg,
64 bfa_status_t req_status, u32 rsp_len,
65 u32 resid_len, struct fchs_s *rsp_fchs);
66static void bfa_fcs_rport_send_nsdisc(void *rport_cbarg,
67 struct bfa_fcxp_s *fcxp_alloced);
68static void bfa_fcs_rport_gidpn_response(void *fcsarg,
69 struct bfa_fcxp_s *fcxp, void *cbarg,
70 bfa_status_t req_status, u32 rsp_len,
71 u32 resid_len, struct fchs_s *rsp_fchs);
72static void bfa_fcs_rport_gpnid_response(void *fcsarg,
73 struct bfa_fcxp_s *fcxp, void *cbarg,
74 bfa_status_t req_status, u32 rsp_len,
75 u32 resid_len, struct fchs_s *rsp_fchs);
76static void bfa_fcs_rport_send_logo(void *rport_cbarg,
77 struct bfa_fcxp_s *fcxp_alloced);
78static void bfa_fcs_rport_send_logo_acc(void *rport_cbarg);
79static void bfa_fcs_rport_process_prli(struct bfa_fcs_rport_s *rport,
80 struct fchs_s *rx_fchs, u16 len);
81static void bfa_fcs_rport_send_ls_rjt(struct bfa_fcs_rport_s *rport,
82 struct fchs_s *rx_fchs, u8 reason_code,
83 u8 reason_code_expl);
84static void bfa_fcs_rport_process_adisc(struct bfa_fcs_rport_s *rport,
85 struct fchs_s *rx_fchs, u16 len);
86static void bfa_fcs_rport_send_prlo_acc(struct bfa_fcs_rport_s *rport);
Krishna Gudipati61ba4392012-08-22 19:52:58 -070087static void bfa_fcs_rport_hal_offline(struct bfa_fcs_rport_s *rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070088
89static void bfa_fcs_rport_sm_uninit(struct bfa_fcs_rport_s *rport,
90 enum rport_event event);
91static void bfa_fcs_rport_sm_plogi_sending(struct bfa_fcs_rport_s *rport,
92 enum rport_event event);
93static void bfa_fcs_rport_sm_plogiacc_sending(struct bfa_fcs_rport_s *rport,
94 enum rport_event event);
95static void bfa_fcs_rport_sm_plogi_retry(struct bfa_fcs_rport_s *rport,
96 enum rport_event event);
97static void bfa_fcs_rport_sm_plogi(struct bfa_fcs_rport_s *rport,
98 enum rport_event event);
Krishna Gudipati61ba4392012-08-22 19:52:58 -070099static void bfa_fcs_rport_sm_fc4_fcs_online(struct bfa_fcs_rport_s *rport,
100 enum rport_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700101static void bfa_fcs_rport_sm_hal_online(struct bfa_fcs_rport_s *rport,
102 enum rport_event event);
103static void bfa_fcs_rport_sm_online(struct bfa_fcs_rport_s *rport,
104 enum rport_event event);
105static void bfa_fcs_rport_sm_nsquery_sending(struct bfa_fcs_rport_s *rport,
106 enum rport_event event);
107static void bfa_fcs_rport_sm_nsquery(struct bfa_fcs_rport_s *rport,
108 enum rport_event event);
109static void bfa_fcs_rport_sm_adisc_sending(struct bfa_fcs_rport_s *rport,
110 enum rport_event event);
111static void bfa_fcs_rport_sm_adisc(struct bfa_fcs_rport_s *rport,
112 enum rport_event event);
113static void bfa_fcs_rport_sm_fc4_logorcv(struct bfa_fcs_rport_s *rport,
114 enum rport_event event);
115static void bfa_fcs_rport_sm_fc4_logosend(struct bfa_fcs_rport_s *rport,
116 enum rport_event event);
117static void bfa_fcs_rport_sm_fc4_offline(struct bfa_fcs_rport_s *rport,
118 enum rport_event event);
119static void bfa_fcs_rport_sm_hcb_offline(struct bfa_fcs_rport_s *rport,
120 enum rport_event event);
121static void bfa_fcs_rport_sm_hcb_logorcv(struct bfa_fcs_rport_s *rport,
122 enum rport_event event);
123static void bfa_fcs_rport_sm_hcb_logosend(struct bfa_fcs_rport_s *rport,
124 enum rport_event event);
125static void bfa_fcs_rport_sm_logo_sending(struct bfa_fcs_rport_s *rport,
126 enum rport_event event);
127static void bfa_fcs_rport_sm_offline(struct bfa_fcs_rport_s *rport,
128 enum rport_event event);
129static void bfa_fcs_rport_sm_nsdisc_sending(struct bfa_fcs_rport_s *rport,
130 enum rport_event event);
131static void bfa_fcs_rport_sm_nsdisc_retry(struct bfa_fcs_rport_s *rport,
132 enum rport_event event);
133static void bfa_fcs_rport_sm_nsdisc_sent(struct bfa_fcs_rport_s *rport,
134 enum rport_event event);
135static void bfa_fcs_rport_sm_nsdisc_sent(struct bfa_fcs_rport_s *rport,
136 enum rport_event event);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700137static void bfa_fcs_rport_sm_fc4_off_delete(struct bfa_fcs_rport_s *rport,
138 enum rport_event event);
139static void bfa_fcs_rport_sm_delete_pending(struct bfa_fcs_rport_s *rport,
140 enum rport_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700141
142static struct bfa_sm_table_s rport_sm_table[] = {
143 {BFA_SM(bfa_fcs_rport_sm_uninit), BFA_RPORT_UNINIT},
144 {BFA_SM(bfa_fcs_rport_sm_plogi_sending), BFA_RPORT_PLOGI},
145 {BFA_SM(bfa_fcs_rport_sm_plogiacc_sending), BFA_RPORT_ONLINE},
146 {BFA_SM(bfa_fcs_rport_sm_plogi_retry), BFA_RPORT_PLOGI_RETRY},
147 {BFA_SM(bfa_fcs_rport_sm_plogi), BFA_RPORT_PLOGI},
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700148 {BFA_SM(bfa_fcs_rport_sm_fc4_fcs_online), BFA_RPORT_ONLINE},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700149 {BFA_SM(bfa_fcs_rport_sm_hal_online), BFA_RPORT_ONLINE},
150 {BFA_SM(bfa_fcs_rport_sm_online), BFA_RPORT_ONLINE},
151 {BFA_SM(bfa_fcs_rport_sm_nsquery_sending), BFA_RPORT_NSQUERY},
152 {BFA_SM(bfa_fcs_rport_sm_nsquery), BFA_RPORT_NSQUERY},
153 {BFA_SM(bfa_fcs_rport_sm_adisc_sending), BFA_RPORT_ADISC},
154 {BFA_SM(bfa_fcs_rport_sm_adisc), BFA_RPORT_ADISC},
155 {BFA_SM(bfa_fcs_rport_sm_fc4_logorcv), BFA_RPORT_LOGORCV},
156 {BFA_SM(bfa_fcs_rport_sm_fc4_logosend), BFA_RPORT_LOGO},
157 {BFA_SM(bfa_fcs_rport_sm_fc4_offline), BFA_RPORT_OFFLINE},
158 {BFA_SM(bfa_fcs_rport_sm_hcb_offline), BFA_RPORT_OFFLINE},
159 {BFA_SM(bfa_fcs_rport_sm_hcb_logorcv), BFA_RPORT_LOGORCV},
160 {BFA_SM(bfa_fcs_rport_sm_hcb_logosend), BFA_RPORT_LOGO},
161 {BFA_SM(bfa_fcs_rport_sm_logo_sending), BFA_RPORT_LOGO},
162 {BFA_SM(bfa_fcs_rport_sm_offline), BFA_RPORT_OFFLINE},
163 {BFA_SM(bfa_fcs_rport_sm_nsdisc_sending), BFA_RPORT_NSDISC},
164 {BFA_SM(bfa_fcs_rport_sm_nsdisc_retry), BFA_RPORT_NSDISC},
165 {BFA_SM(bfa_fcs_rport_sm_nsdisc_sent), BFA_RPORT_NSDISC},
166};
167
Jing Huang5fbe25c2010-10-18 17:17:23 -0700168/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700169 * Beginning state.
170 */
171static void
172bfa_fcs_rport_sm_uninit(struct bfa_fcs_rport_s *rport, enum rport_event event)
173{
174 bfa_trc(rport->fcs, rport->pwwn);
175 bfa_trc(rport->fcs, rport->pid);
176 bfa_trc(rport->fcs, event);
177
178 switch (event) {
179 case RPSM_EVENT_PLOGI_SEND:
180 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
181 rport->plogi_retries = 0;
182 bfa_fcs_rport_send_plogi(rport, NULL);
183 break;
184
185 case RPSM_EVENT_PLOGI_RCVD:
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700186 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
187 bfa_fcs_rport_fcs_online_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700188 break;
189
190 case RPSM_EVENT_PLOGI_COMP:
191 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
192 bfa_fcs_rport_hal_online(rport);
193 break;
194
195 case RPSM_EVENT_ADDRESS_CHANGE:
196 case RPSM_EVENT_ADDRESS_DISC:
197 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
198 rport->ns_retries = 0;
199 bfa_fcs_rport_send_nsdisc(rport, NULL);
200 break;
201 default:
202 bfa_sm_fault(rport->fcs, event);
203 }
204}
205
Jing Huang5fbe25c2010-10-18 17:17:23 -0700206/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700207 * PLOGI is being sent.
208 */
209static void
210bfa_fcs_rport_sm_plogi_sending(struct bfa_fcs_rport_s *rport,
211 enum rport_event event)
212{
213 bfa_trc(rport->fcs, rport->pwwn);
214 bfa_trc(rport->fcs, rport->pid);
215 bfa_trc(rport->fcs, event);
216
217 switch (event) {
218 case RPSM_EVENT_FCXP_SENT:
219 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi);
220 break;
221
222 case RPSM_EVENT_DELETE:
223 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
224 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
225 bfa_fcs_rport_free(rport);
226 break;
227
228 case RPSM_EVENT_PLOGI_RCVD:
229 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
230 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
231 bfa_fcs_rport_send_plogiacc(rport, NULL);
232 break;
233
234 case RPSM_EVENT_ADDRESS_CHANGE:
235 case RPSM_EVENT_SCN:
236 /* query the NS */
237 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
238 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
239 rport->ns_retries = 0;
240 bfa_fcs_rport_send_nsdisc(rport, NULL);
241 break;
242
243 case RPSM_EVENT_LOGO_IMP:
244 rport->pid = 0;
245 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
246 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
247 bfa_timer_start(rport->fcs->bfa, &rport->timer,
248 bfa_fcs_rport_timeout, rport,
249 bfa_fcs_rport_del_timeout);
250 break;
251
252
253 default:
254 bfa_sm_fault(rport->fcs, event);
255 }
256}
257
Jing Huang5fbe25c2010-10-18 17:17:23 -0700258/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700259 * PLOGI is being sent.
260 */
261static void
262bfa_fcs_rport_sm_plogiacc_sending(struct bfa_fcs_rport_s *rport,
263 enum rport_event event)
264{
265 bfa_trc(rport->fcs, rport->pwwn);
266 bfa_trc(rport->fcs, rport->pid);
267 bfa_trc(rport->fcs, event);
268
269 switch (event) {
270 case RPSM_EVENT_FCXP_SENT:
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700271 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
272 bfa_fcs_rport_fcs_online_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700273 break;
274
275 case RPSM_EVENT_DELETE:
276 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
277 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
278 bfa_fcs_rport_free(rport);
279 break;
280
281 case RPSM_EVENT_PLOGI_RCVD:
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700282 case RPSM_EVENT_PLOGI_COMP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700283 case RPSM_EVENT_SCN:
Jing Huang5fbe25c2010-10-18 17:17:23 -0700284 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700285 * Ignore, SCN is possibly online notification.
286 */
287 break;
288
289 case RPSM_EVENT_ADDRESS_CHANGE:
290 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
291 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
292 rport->ns_retries = 0;
293 bfa_fcs_rport_send_nsdisc(rport, NULL);
294 break;
295
296 case RPSM_EVENT_LOGO_IMP:
297 rport->pid = 0;
298 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
299 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
300 bfa_timer_start(rport->fcs->bfa, &rport->timer,
301 bfa_fcs_rport_timeout, rport,
302 bfa_fcs_rport_del_timeout);
303 break;
304
305 case RPSM_EVENT_HCB_OFFLINE:
Jing Huang5fbe25c2010-10-18 17:17:23 -0700306 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700307 * Ignore BFA callback, on a PLOGI receive we call bfa offline.
308 */
309 break;
310
311 default:
312 bfa_sm_fault(rport->fcs, event);
313 }
314}
315
Jing Huang5fbe25c2010-10-18 17:17:23 -0700316/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700317 * PLOGI is sent.
318 */
319static void
320bfa_fcs_rport_sm_plogi_retry(struct bfa_fcs_rport_s *rport,
321 enum rport_event event)
322{
323 bfa_trc(rport->fcs, rport->pwwn);
324 bfa_trc(rport->fcs, rport->pid);
325 bfa_trc(rport->fcs, event);
326
327 switch (event) {
328 case RPSM_EVENT_TIMEOUT:
329 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
330 bfa_fcs_rport_send_plogi(rport, NULL);
331 break;
332
333 case RPSM_EVENT_DELETE:
334 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
335 bfa_timer_stop(&rport->timer);
336 bfa_fcs_rport_free(rport);
337 break;
338
339 case RPSM_EVENT_PRLO_RCVD:
340 case RPSM_EVENT_LOGO_RCVD:
341 break;
342
343 case RPSM_EVENT_PLOGI_RCVD:
344 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
345 bfa_timer_stop(&rport->timer);
346 bfa_fcs_rport_send_plogiacc(rport, NULL);
347 break;
348
349 case RPSM_EVENT_ADDRESS_CHANGE:
350 case RPSM_EVENT_SCN:
351 bfa_timer_stop(&rport->timer);
352 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
353 rport->ns_retries = 0;
354 bfa_fcs_rport_send_nsdisc(rport, NULL);
355 break;
356
357 case RPSM_EVENT_LOGO_IMP:
358 rport->pid = 0;
359 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
360 bfa_timer_stop(&rport->timer);
361 bfa_timer_start(rport->fcs->bfa, &rport->timer,
362 bfa_fcs_rport_timeout, rport,
363 bfa_fcs_rport_del_timeout);
364 break;
365
366 case RPSM_EVENT_PLOGI_COMP:
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700367 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700368 bfa_timer_stop(&rport->timer);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700369 bfa_fcs_rport_fcs_online_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700370 break;
371
372 default:
373 bfa_sm_fault(rport->fcs, event);
374 }
375}
376
Jing Huang5fbe25c2010-10-18 17:17:23 -0700377/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700378 * PLOGI is sent.
379 */
380static void
381bfa_fcs_rport_sm_plogi(struct bfa_fcs_rport_s *rport, enum rport_event event)
382{
383 bfa_trc(rport->fcs, rport->pwwn);
384 bfa_trc(rport->fcs, rport->pid);
385 bfa_trc(rport->fcs, event);
386
387 switch (event) {
388 case RPSM_EVENT_ACCEPTED:
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700389 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700390 rport->plogi_retries = 0;
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700391 bfa_fcs_rport_fcs_online_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700392 break;
393
394 case RPSM_EVENT_LOGO_RCVD:
395 bfa_fcs_rport_send_logo_acc(rport);
396 /*
397 * !! fall through !!
398 */
399 case RPSM_EVENT_PRLO_RCVD:
400 if (rport->prlo == BFA_TRUE)
401 bfa_fcs_rport_send_prlo_acc(rport);
402
403 bfa_fcxp_discard(rport->fcxp);
404 /*
405 * !! fall through !!
406 */
407 case RPSM_EVENT_FAILED:
408 if (rport->plogi_retries < BFA_FCS_RPORT_MAX_RETRIES) {
409 rport->plogi_retries++;
410 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_retry);
411 bfa_timer_start(rport->fcs->bfa, &rport->timer,
412 bfa_fcs_rport_timeout, rport,
413 BFA_FCS_RETRY_TIMEOUT);
414 } else {
415 bfa_stats(rport->port, rport_del_max_plogi_retry);
Krishna Gudipatiee1a4a42012-08-22 19:50:43 -0700416 rport->old_pid = rport->pid;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700417 rport->pid = 0;
418 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
419 bfa_timer_start(rport->fcs->bfa, &rport->timer,
420 bfa_fcs_rport_timeout, rport,
421 bfa_fcs_rport_del_timeout);
422 }
423 break;
424
425 case RPSM_EVENT_PLOGI_RETRY:
426 rport->plogi_retries = 0;
427 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_retry);
428 bfa_timer_start(rport->fcs->bfa, &rport->timer,
429 bfa_fcs_rport_timeout, rport,
430 (FC_RA_TOV * 1000));
431 break;
432
433 case RPSM_EVENT_LOGO_IMP:
434 rport->pid = 0;
435 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
436 bfa_fcxp_discard(rport->fcxp);
437 bfa_timer_start(rport->fcs->bfa, &rport->timer,
438 bfa_fcs_rport_timeout, rport,
439 bfa_fcs_rport_del_timeout);
440 break;
441
442 case RPSM_EVENT_ADDRESS_CHANGE:
443 case RPSM_EVENT_SCN:
444 bfa_fcxp_discard(rport->fcxp);
445 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
446 rport->ns_retries = 0;
447 bfa_fcs_rport_send_nsdisc(rport, NULL);
448 break;
449
450 case RPSM_EVENT_PLOGI_RCVD:
451 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
452 bfa_fcxp_discard(rport->fcxp);
453 bfa_fcs_rport_send_plogiacc(rport, NULL);
454 break;
455
456 case RPSM_EVENT_DELETE:
457 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
458 bfa_fcxp_discard(rport->fcxp);
459 bfa_fcs_rport_free(rport);
460 break;
461
462 case RPSM_EVENT_PLOGI_COMP:
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700463 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700464 bfa_fcxp_discard(rport->fcxp);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700465 bfa_fcs_rport_fcs_online_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700466 break;
467
468 default:
469 bfa_sm_fault(rport->fcs, event);
470 }
471}
472
Jing Huang5fbe25c2010-10-18 17:17:23 -0700473/*
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700474 * PLOGI is done. Await bfa_fcs_itnim to ascertain the scsi function
475 */
476static void
477bfa_fcs_rport_sm_fc4_fcs_online(struct bfa_fcs_rport_s *rport,
478 enum rport_event event)
479{
480 bfa_trc(rport->fcs, rport->pwwn);
481 bfa_trc(rport->fcs, rport->pid);
482 bfa_trc(rport->fcs, event);
483
484 switch (event) {
485 case RPSM_EVENT_FC4_FCS_ONLINE:
486 if (rport->scsi_function == BFA_RPORT_INITIATOR) {
487 if (!BFA_FCS_PID_IS_WKA(rport->pid))
488 bfa_fcs_rpf_rport_online(rport);
489 bfa_sm_set_state(rport, bfa_fcs_rport_sm_online);
490 break;
491 }
492
493 if (!rport->bfa_rport)
494 rport->bfa_rport =
495 bfa_rport_create(rport->fcs->bfa, rport);
496
497 if (rport->bfa_rport) {
498 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
499 bfa_fcs_rport_hal_online(rport);
500 } else {
501 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
502 bfa_fcs_rport_fcs_offline_action(rport);
503 }
504 break;
505
506 case RPSM_EVENT_PLOGI_RCVD:
507 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
508 rport->plogi_pending = BFA_TRUE;
509 bfa_fcs_rport_fcs_offline_action(rport);
510 break;
511
512 case RPSM_EVENT_PLOGI_COMP:
513 case RPSM_EVENT_LOGO_IMP:
514 case RPSM_EVENT_ADDRESS_CHANGE:
515 case RPSM_EVENT_SCN:
516 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
517 bfa_fcs_rport_fcs_offline_action(rport);
518 break;
519
520 case RPSM_EVENT_LOGO_RCVD:
521 case RPSM_EVENT_PRLO_RCVD:
522 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
523 bfa_fcs_rport_fcs_offline_action(rport);
524 break;
525
526 case RPSM_EVENT_DELETE:
527 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
528 bfa_fcs_rport_fcs_offline_action(rport);
529 break;
530
531 default:
532 bfa_sm_fault(rport->fcs, event);
533 break;
534 }
535}
536
537/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700538 * PLOGI is complete. Awaiting BFA rport online callback. FC-4s
539 * are offline.
540 */
541static void
542bfa_fcs_rport_sm_hal_online(struct bfa_fcs_rport_s *rport,
543 enum rport_event event)
544{
545 bfa_trc(rport->fcs, rport->pwwn);
546 bfa_trc(rport->fcs, rport->pid);
547 bfa_trc(rport->fcs, event);
548
549 switch (event) {
550 case RPSM_EVENT_HCB_ONLINE:
551 bfa_sm_set_state(rport, bfa_fcs_rport_sm_online);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700552 bfa_fcs_rport_hal_online_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700553 break;
554
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700555 case RPSM_EVENT_PLOGI_COMP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700556 break;
557
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700558 case RPSM_EVENT_PRLO_RCVD:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700559 case RPSM_EVENT_LOGO_RCVD:
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700560 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
561 bfa_fcs_rport_fcs_offline_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700562 break;
563
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700564 case RPSM_EVENT_SCN:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700565 case RPSM_EVENT_LOGO_IMP:
566 case RPSM_EVENT_ADDRESS_CHANGE:
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700567 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
568 bfa_fcs_rport_fcs_offline_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700569 break;
570
571 case RPSM_EVENT_PLOGI_RCVD:
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700572 rport->plogi_pending = BFA_TRUE;
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700573 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
574 bfa_fcs_rport_fcs_offline_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700575 break;
576
577 case RPSM_EVENT_DELETE:
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700578 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
579 bfa_fcs_rport_fcs_offline_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700580 break;
581
582 default:
583 bfa_sm_fault(rport->fcs, event);
584 }
585}
586
Jing Huang5fbe25c2010-10-18 17:17:23 -0700587/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700588 * Rport is ONLINE. FC-4s active.
589 */
590static void
591bfa_fcs_rport_sm_online(struct bfa_fcs_rport_s *rport, enum rport_event event)
592{
593 bfa_trc(rport->fcs, rport->pwwn);
594 bfa_trc(rport->fcs, rport->pid);
595 bfa_trc(rport->fcs, event);
596
597 switch (event) {
598 case RPSM_EVENT_SCN:
599 if (bfa_fcs_fabric_is_switched(rport->port->fabric)) {
600 bfa_sm_set_state(rport,
601 bfa_fcs_rport_sm_nsquery_sending);
602 rport->ns_retries = 0;
603 bfa_fcs_rport_send_nsdisc(rport, NULL);
604 } else {
605 bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc_sending);
606 bfa_fcs_rport_send_adisc(rport, NULL);
607 }
608 break;
609
610 case RPSM_EVENT_PLOGI_RCVD:
611 case RPSM_EVENT_LOGO_IMP:
612 case RPSM_EVENT_ADDRESS_CHANGE:
613 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700614 bfa_fcs_rport_hal_offline_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700615 break;
616
617 case RPSM_EVENT_DELETE:
618 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700619 bfa_fcs_rport_hal_offline_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700620 break;
621
622 case RPSM_EVENT_LOGO_RCVD:
623 case RPSM_EVENT_PRLO_RCVD:
624 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700625 bfa_fcs_rport_hal_offline_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700626 break;
627
628 case RPSM_EVENT_PLOGI_COMP:
629 break;
630
631 default:
632 bfa_sm_fault(rport->fcs, event);
633 }
634}
635
Jing Huang5fbe25c2010-10-18 17:17:23 -0700636/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700637 * An SCN event is received in ONLINE state. NS query is being sent
638 * prior to ADISC authentication with rport. FC-4s are paused.
639 */
640static void
641bfa_fcs_rport_sm_nsquery_sending(struct bfa_fcs_rport_s *rport,
642 enum rport_event event)
643{
644 bfa_trc(rport->fcs, rport->pwwn);
645 bfa_trc(rport->fcs, rport->pid);
646 bfa_trc(rport->fcs, event);
647
648 switch (event) {
649 case RPSM_EVENT_FCXP_SENT:
650 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsquery);
651 break;
652
653 case RPSM_EVENT_DELETE:
654 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
655 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700656 bfa_fcs_rport_hal_offline_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700657 break;
658
659 case RPSM_EVENT_SCN:
Jing Huang5fbe25c2010-10-18 17:17:23 -0700660 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700661 * ignore SCN, wait for response to query itself
662 */
663 break;
664
665 case RPSM_EVENT_LOGO_RCVD:
666 case RPSM_EVENT_PRLO_RCVD:
667 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
668 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700669 bfa_fcs_rport_hal_offline_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700670 break;
671
672 case RPSM_EVENT_LOGO_IMP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700673 case RPSM_EVENT_PLOGI_RCVD:
674 case RPSM_EVENT_ADDRESS_CHANGE:
675 case RPSM_EVENT_PLOGI_COMP:
676 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
677 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700678 bfa_fcs_rport_hal_offline_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700679 break;
680
681 default:
682 bfa_sm_fault(rport->fcs, event);
683 }
684}
685
Jing Huang5fbe25c2010-10-18 17:17:23 -0700686/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700687 * An SCN event is received in ONLINE state. NS query is sent to rport.
688 * FC-4s are paused.
689 */
690static void
691bfa_fcs_rport_sm_nsquery(struct bfa_fcs_rport_s *rport, enum rport_event event)
692{
693 bfa_trc(rport->fcs, rport->pwwn);
694 bfa_trc(rport->fcs, rport->pid);
695 bfa_trc(rport->fcs, event);
696
697 switch (event) {
698 case RPSM_EVENT_ACCEPTED:
699 bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc_sending);
700 bfa_fcs_rport_send_adisc(rport, NULL);
701 break;
702
703 case RPSM_EVENT_FAILED:
704 rport->ns_retries++;
705 if (rport->ns_retries < BFA_FCS_RPORT_MAX_RETRIES) {
706 bfa_sm_set_state(rport,
707 bfa_fcs_rport_sm_nsquery_sending);
708 bfa_fcs_rport_send_nsdisc(rport, NULL);
709 } else {
710 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700711 bfa_fcs_rport_hal_offline_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700712 }
713 break;
714
715 case RPSM_EVENT_DELETE:
716 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
717 bfa_fcxp_discard(rport->fcxp);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700718 bfa_fcs_rport_hal_offline_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700719 break;
720
721 case RPSM_EVENT_SCN:
722 break;
723
724 case RPSM_EVENT_LOGO_RCVD:
725 case RPSM_EVENT_PRLO_RCVD:
726 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
727 bfa_fcxp_discard(rport->fcxp);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700728 bfa_fcs_rport_hal_offline_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700729 break;
730
731 case RPSM_EVENT_PLOGI_COMP:
732 case RPSM_EVENT_ADDRESS_CHANGE:
733 case RPSM_EVENT_PLOGI_RCVD:
734 case RPSM_EVENT_LOGO_IMP:
735 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
736 bfa_fcxp_discard(rport->fcxp);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700737 bfa_fcs_rport_hal_offline_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700738 break;
739
740 default:
741 bfa_sm_fault(rport->fcs, event);
742 }
743}
744
Jing Huang5fbe25c2010-10-18 17:17:23 -0700745/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700746 * An SCN event is received in ONLINE state. ADISC is being sent for
747 * authenticating with rport. FC-4s are paused.
748 */
749static void
750bfa_fcs_rport_sm_adisc_sending(struct bfa_fcs_rport_s *rport,
751 enum rport_event event)
752{
753 bfa_trc(rport->fcs, rport->pwwn);
754 bfa_trc(rport->fcs, rport->pid);
755 bfa_trc(rport->fcs, event);
756
757 switch (event) {
758 case RPSM_EVENT_FCXP_SENT:
759 bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc);
760 break;
761
762 case RPSM_EVENT_DELETE:
763 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
764 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700765 bfa_fcs_rport_hal_offline_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700766 break;
767
768 case RPSM_EVENT_LOGO_IMP:
769 case RPSM_EVENT_ADDRESS_CHANGE:
770 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
771 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700772 bfa_fcs_rport_hal_offline_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700773 break;
774
775 case RPSM_EVENT_LOGO_RCVD:
776 case RPSM_EVENT_PRLO_RCVD:
777 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
778 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700779 bfa_fcs_rport_hal_offline_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700780 break;
781
782 case RPSM_EVENT_SCN:
783 break;
784
785 case RPSM_EVENT_PLOGI_RCVD:
786 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
787 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700788 bfa_fcs_rport_hal_offline_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700789 break;
790
791 default:
792 bfa_sm_fault(rport->fcs, event);
793 }
794}
795
Jing Huang5fbe25c2010-10-18 17:17:23 -0700796/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700797 * An SCN event is received in ONLINE state. ADISC is to rport.
798 * FC-4s are paused.
799 */
800static void
801bfa_fcs_rport_sm_adisc(struct bfa_fcs_rport_s *rport, enum rport_event event)
802{
803 bfa_trc(rport->fcs, rport->pwwn);
804 bfa_trc(rport->fcs, rport->pid);
805 bfa_trc(rport->fcs, event);
806
807 switch (event) {
808 case RPSM_EVENT_ACCEPTED:
809 bfa_sm_set_state(rport, bfa_fcs_rport_sm_online);
810 break;
811
812 case RPSM_EVENT_PLOGI_RCVD:
Jing Huang5fbe25c2010-10-18 17:17:23 -0700813 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700814 * Too complex to cleanup FC-4 & rport and then acc to PLOGI.
815 * At least go offline when a PLOGI is received.
816 */
817 bfa_fcxp_discard(rport->fcxp);
818 /*
819 * !!! fall through !!!
820 */
821
822 case RPSM_EVENT_FAILED:
823 case RPSM_EVENT_ADDRESS_CHANGE:
824 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700825 bfa_fcs_rport_hal_offline_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700826 break;
827
828 case RPSM_EVENT_DELETE:
829 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
830 bfa_fcxp_discard(rport->fcxp);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700831 bfa_fcs_rport_hal_offline_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700832 break;
833
834 case RPSM_EVENT_SCN:
Jing Huang5fbe25c2010-10-18 17:17:23 -0700835 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700836 * already processing RSCN
837 */
838 break;
839
840 case RPSM_EVENT_LOGO_IMP:
841 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
842 bfa_fcxp_discard(rport->fcxp);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700843 bfa_fcs_rport_hal_offline_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700844 break;
845
846 case RPSM_EVENT_LOGO_RCVD:
847 case RPSM_EVENT_PRLO_RCVD:
848 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
849 bfa_fcxp_discard(rport->fcxp);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700850 bfa_fcs_rport_hal_offline_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700851 break;
852
853 default:
854 bfa_sm_fault(rport->fcs, event);
855 }
856}
857
Jing Huang5fbe25c2010-10-18 17:17:23 -0700858/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700859 * Rport has sent LOGO. Awaiting FC-4 offline completion callback.
860 */
861static void
862bfa_fcs_rport_sm_fc4_logorcv(struct bfa_fcs_rport_s *rport,
863 enum rport_event event)
864{
865 bfa_trc(rport->fcs, rport->pwwn);
866 bfa_trc(rport->fcs, rport->pid);
867 bfa_trc(rport->fcs, event);
868
869 switch (event) {
870 case RPSM_EVENT_FC4_OFFLINE:
871 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logorcv);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700872 bfa_fcs_rport_hal_offline(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700873 break;
874
875 case RPSM_EVENT_DELETE:
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700876 if (rport->pid && (rport->prlo == BFA_TRUE))
877 bfa_fcs_rport_send_prlo_acc(rport);
878 if (rport->pid && (rport->prlo == BFA_FALSE))
879 bfa_fcs_rport_send_logo_acc(rport);
880
881 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_off_delete);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700882 break;
883
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700884 case RPSM_EVENT_HCB_ONLINE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700885 case RPSM_EVENT_LOGO_RCVD:
886 case RPSM_EVENT_PRLO_RCVD:
887 case RPSM_EVENT_ADDRESS_CHANGE:
888 break;
889
890 default:
891 bfa_sm_fault(rport->fcs, event);
892 }
893}
894
Jing Huang5fbe25c2010-10-18 17:17:23 -0700895/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700896 * LOGO needs to be sent to rport. Awaiting FC-4 offline completion
897 * callback.
898 */
899static void
900bfa_fcs_rport_sm_fc4_logosend(struct bfa_fcs_rport_s *rport,
901 enum rport_event event)
902{
903 bfa_trc(rport->fcs, rport->pwwn);
904 bfa_trc(rport->fcs, rport->pid);
905 bfa_trc(rport->fcs, event);
906
907 switch (event) {
908 case RPSM_EVENT_FC4_OFFLINE:
909 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logosend);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700910 bfa_fcs_rport_hal_offline(rport);
911 break;
912
913 case RPSM_EVENT_LOGO_RCVD:
914 bfa_fcs_rport_send_logo_acc(rport);
915 case RPSM_EVENT_PRLO_RCVD:
916 if (rport->prlo == BFA_TRUE)
917 bfa_fcs_rport_send_prlo_acc(rport);
918 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_off_delete);
919 break;
920
921 case RPSM_EVENT_HCB_ONLINE:
922 case RPSM_EVENT_DELETE:
923 /* Rport is being deleted */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700924 break;
925
926 default:
927 bfa_sm_fault(rport->fcs, event);
928 }
929}
930
Jing Huang5fbe25c2010-10-18 17:17:23 -0700931/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700932 * Rport is going offline. Awaiting FC-4 offline completion callback.
933 */
934static void
935bfa_fcs_rport_sm_fc4_offline(struct bfa_fcs_rport_s *rport,
936 enum rport_event event)
937{
938 bfa_trc(rport->fcs, rport->pwwn);
939 bfa_trc(rport->fcs, rport->pid);
940 bfa_trc(rport->fcs, event);
941
942 switch (event) {
943 case RPSM_EVENT_FC4_OFFLINE:
944 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_offline);
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700945 bfa_fcs_rport_hal_offline(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700946 break;
947
Krishna Gudipati61ba4392012-08-22 19:52:58 -0700948 case RPSM_EVENT_LOGO_RCVD:
949 /*
950 * Rport is going offline. Just ack the logo
951 */
952 bfa_fcs_rport_send_logo_acc(rport);
953 break;
954
955 case RPSM_EVENT_PRLO_RCVD:
956 bfa_fcs_rport_send_prlo_acc(rport);
957 break;
958
959 case RPSM_EVENT_HCB_ONLINE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700960 case RPSM_EVENT_SCN:
961 case RPSM_EVENT_LOGO_IMP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700962 case RPSM_EVENT_ADDRESS_CHANGE:
Jing Huang5fbe25c2010-10-18 17:17:23 -0700963 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700964 * rport is already going offline.
965 * SCN - ignore and wait till transitioning to offline state
966 */
967 break;
968
969 case RPSM_EVENT_DELETE:
970 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
971 break;
972
973 default:
974 bfa_sm_fault(rport->fcs, event);
975 }
976}
977
Jing Huang5fbe25c2010-10-18 17:17:23 -0700978/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700979 * Rport is offline. FC-4s are offline. Awaiting BFA rport offline
980 * callback.
981 */
982static void
983bfa_fcs_rport_sm_hcb_offline(struct bfa_fcs_rport_s *rport,
984 enum rport_event event)
985{
986 bfa_trc(rport->fcs, rport->pwwn);
987 bfa_trc(rport->fcs, rport->pid);
988 bfa_trc(rport->fcs, event);
989
990 switch (event) {
991 case RPSM_EVENT_HCB_OFFLINE:
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700992 if (bfa_fcs_lport_is_online(rport->port) &&
993 (rport->plogi_pending)) {
994 rport->plogi_pending = BFA_FALSE;
995 bfa_sm_set_state(rport,
996 bfa_fcs_rport_sm_plogiacc_sending);
997 bfa_fcs_rport_send_plogiacc(rport, NULL);
998 break;
999 }
1000 /*
1001 * !! fall through !!
1002 */
1003
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001004 case RPSM_EVENT_ADDRESS_CHANGE:
Krishna Gudipati61ba4392012-08-22 19:52:58 -07001005 if (!bfa_fcs_lport_is_online(rport->port)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001006 rport->pid = 0;
1007 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
1008 bfa_timer_start(rport->fcs->bfa, &rport->timer,
1009 bfa_fcs_rport_timeout, rport,
1010 bfa_fcs_rport_del_timeout);
Krishna Gudipati61ba4392012-08-22 19:52:58 -07001011 break;
1012 }
1013 if (bfa_fcs_fabric_is_switched(rport->port->fabric)) {
1014 bfa_sm_set_state(rport,
1015 bfa_fcs_rport_sm_nsdisc_sending);
1016 rport->ns_retries = 0;
1017 bfa_fcs_rport_send_nsdisc(rport, NULL);
1018 } else {
1019 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
1020 rport->plogi_retries = 0;
1021 bfa_fcs_rport_send_plogi(rport, NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001022 }
1023 break;
1024
1025 case RPSM_EVENT_DELETE:
1026 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1027 bfa_fcs_rport_free(rport);
1028 break;
1029
1030 case RPSM_EVENT_SCN:
1031 case RPSM_EVENT_LOGO_RCVD:
1032 case RPSM_EVENT_PRLO_RCVD:
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07001033 case RPSM_EVENT_PLOGI_RCVD:
1034 case RPSM_EVENT_LOGO_IMP:
Jing Huang5fbe25c2010-10-18 17:17:23 -07001035 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001036 * Ignore, already offline.
1037 */
1038 break;
1039
1040 default:
1041 bfa_sm_fault(rport->fcs, event);
1042 }
1043}
1044
Jing Huang5fbe25c2010-10-18 17:17:23 -07001045/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001046 * Rport is offline. FC-4s are offline. Awaiting BFA rport offline
1047 * callback to send LOGO accept.
1048 */
1049static void
1050bfa_fcs_rport_sm_hcb_logorcv(struct bfa_fcs_rport_s *rport,
1051 enum rport_event event)
1052{
1053 bfa_trc(rport->fcs, rport->pwwn);
1054 bfa_trc(rport->fcs, rport->pid);
1055 bfa_trc(rport->fcs, event);
1056
1057 switch (event) {
1058 case RPSM_EVENT_HCB_OFFLINE:
1059 case RPSM_EVENT_ADDRESS_CHANGE:
1060 if (rport->pid && (rport->prlo == BFA_TRUE))
1061 bfa_fcs_rport_send_prlo_acc(rport);
1062 if (rport->pid && (rport->prlo == BFA_FALSE))
1063 bfa_fcs_rport_send_logo_acc(rport);
1064 /*
1065 * If the lport is online and if the rport is not a well
1066 * known address port,
1067 * we try to re-discover the r-port.
1068 */
1069 if (bfa_fcs_lport_is_online(rport->port) &&
1070 (!BFA_FCS_PID_IS_WKA(rport->pid))) {
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07001071 if (bfa_fcs_fabric_is_switched(rport->port->fabric)) {
1072 bfa_sm_set_state(rport,
1073 bfa_fcs_rport_sm_nsdisc_sending);
1074 rport->ns_retries = 0;
1075 bfa_fcs_rport_send_nsdisc(rport, NULL);
1076 } else {
1077 /* For N2N Direct Attach, try to re-login */
1078 bfa_sm_set_state(rport,
1079 bfa_fcs_rport_sm_plogi_sending);
1080 rport->plogi_retries = 0;
1081 bfa_fcs_rport_send_plogi(rport, NULL);
1082 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001083 } else {
1084 /*
1085 * if it is not a well known address, reset the
1086 * pid to 0.
1087 */
1088 if (!BFA_FCS_PID_IS_WKA(rport->pid))
1089 rport->pid = 0;
1090 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
1091 bfa_timer_start(rport->fcs->bfa, &rport->timer,
1092 bfa_fcs_rport_timeout, rport,
1093 bfa_fcs_rport_del_timeout);
1094 }
1095 break;
1096
1097 case RPSM_EVENT_DELETE:
Krishna Gudipati61ba4392012-08-22 19:52:58 -07001098 bfa_sm_set_state(rport, bfa_fcs_rport_sm_delete_pending);
1099 if (rport->pid && (rport->prlo == BFA_TRUE))
1100 bfa_fcs_rport_send_prlo_acc(rport);
1101 if (rport->pid && (rport->prlo == BFA_FALSE))
1102 bfa_fcs_rport_send_logo_acc(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001103 break;
1104
1105 case RPSM_EVENT_LOGO_IMP:
1106 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_offline);
1107 break;
1108
1109 case RPSM_EVENT_LOGO_RCVD:
1110 case RPSM_EVENT_PRLO_RCVD:
Jing Huang5fbe25c2010-10-18 17:17:23 -07001111 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001112 * Ignore - already processing a LOGO.
1113 */
1114 break;
1115
1116 default:
1117 bfa_sm_fault(rport->fcs, event);
1118 }
1119}
1120
Jing Huang5fbe25c2010-10-18 17:17:23 -07001121/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001122 * Rport is being deleted. FC-4s are offline.
1123 * Awaiting BFA rport offline
1124 * callback to send LOGO.
1125 */
1126static void
1127bfa_fcs_rport_sm_hcb_logosend(struct bfa_fcs_rport_s *rport,
1128 enum rport_event event)
1129{
1130 bfa_trc(rport->fcs, rport->pwwn);
1131 bfa_trc(rport->fcs, rport->pid);
1132 bfa_trc(rport->fcs, event);
1133
1134 switch (event) {
1135 case RPSM_EVENT_HCB_OFFLINE:
1136 bfa_sm_set_state(rport, bfa_fcs_rport_sm_logo_sending);
1137 bfa_fcs_rport_send_logo(rport, NULL);
1138 break;
1139
1140 case RPSM_EVENT_LOGO_RCVD:
Krishna Gudipati61ba4392012-08-22 19:52:58 -07001141 bfa_fcs_rport_send_logo_acc(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001142 case RPSM_EVENT_PRLO_RCVD:
Krishna Gudipati61ba4392012-08-22 19:52:58 -07001143 if (rport->prlo == BFA_TRUE)
1144 bfa_fcs_rport_send_prlo_acc(rport);
1145
1146 bfa_sm_set_state(rport, bfa_fcs_rport_sm_delete_pending);
1147 break;
1148
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001149 case RPSM_EVENT_ADDRESS_CHANGE:
1150 break;
1151
1152 default:
1153 bfa_sm_fault(rport->fcs, event);
1154 }
1155}
1156
Jing Huang5fbe25c2010-10-18 17:17:23 -07001157/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001158 * Rport is being deleted. FC-4s are offline. LOGO is being sent.
1159 */
1160static void
1161bfa_fcs_rport_sm_logo_sending(struct bfa_fcs_rport_s *rport,
1162 enum rport_event event)
1163{
1164 bfa_trc(rport->fcs, rport->pwwn);
1165 bfa_trc(rport->fcs, rport->pid);
1166 bfa_trc(rport->fcs, event);
1167
1168 switch (event) {
1169 case RPSM_EVENT_FCXP_SENT:
1170 /* Once LOGO is sent, we donot wait for the response */
1171 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1172 bfa_fcs_rport_free(rport);
1173 break;
1174
1175 case RPSM_EVENT_SCN:
1176 case RPSM_EVENT_ADDRESS_CHANGE:
1177 break;
1178
1179 case RPSM_EVENT_LOGO_RCVD:
Krishna Gudipati61ba4392012-08-22 19:52:58 -07001180 bfa_fcs_rport_send_logo_acc(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001181 case RPSM_EVENT_PRLO_RCVD:
Krishna Gudipati61ba4392012-08-22 19:52:58 -07001182 if (rport->prlo == BFA_TRUE)
1183 bfa_fcs_rport_send_prlo_acc(rport);
1184
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001185 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1186 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
1187 bfa_fcs_rport_free(rport);
1188 break;
1189
1190 default:
1191 bfa_sm_fault(rport->fcs, event);
1192 }
1193}
1194
Jing Huang5fbe25c2010-10-18 17:17:23 -07001195/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001196 * Rport is offline. FC-4s are offline. BFA rport is offline.
1197 * Timer active to delete stale rport.
1198 */
1199static void
1200bfa_fcs_rport_sm_offline(struct bfa_fcs_rport_s *rport, enum rport_event event)
1201{
1202 bfa_trc(rport->fcs, rport->pwwn);
1203 bfa_trc(rport->fcs, rport->pid);
1204 bfa_trc(rport->fcs, event);
1205
1206 switch (event) {
1207 case RPSM_EVENT_TIMEOUT:
1208 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1209 bfa_fcs_rport_free(rport);
1210 break;
1211
1212 case RPSM_EVENT_SCN:
1213 case RPSM_EVENT_ADDRESS_CHANGE:
1214 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
1215 bfa_timer_stop(&rport->timer);
1216 rport->ns_retries = 0;
1217 bfa_fcs_rport_send_nsdisc(rport, NULL);
1218 break;
1219
1220 case RPSM_EVENT_DELETE:
1221 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1222 bfa_timer_stop(&rport->timer);
1223 bfa_fcs_rport_free(rport);
1224 break;
1225
1226 case RPSM_EVENT_PLOGI_RCVD:
1227 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
1228 bfa_timer_stop(&rport->timer);
1229 bfa_fcs_rport_send_plogiacc(rport, NULL);
1230 break;
1231
1232 case RPSM_EVENT_LOGO_RCVD:
1233 case RPSM_EVENT_PRLO_RCVD:
1234 case RPSM_EVENT_LOGO_IMP:
1235 break;
1236
1237 case RPSM_EVENT_PLOGI_COMP:
Krishna Gudipati61ba4392012-08-22 19:52:58 -07001238 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001239 bfa_timer_stop(&rport->timer);
Krishna Gudipati61ba4392012-08-22 19:52:58 -07001240 bfa_fcs_rport_fcs_online_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001241 break;
1242
1243 case RPSM_EVENT_PLOGI_SEND:
1244 bfa_timer_stop(&rport->timer);
1245 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
1246 rport->plogi_retries = 0;
1247 bfa_fcs_rport_send_plogi(rport, NULL);
1248 break;
1249
1250 default:
1251 bfa_sm_fault(rport->fcs, event);
1252 }
1253}
1254
Jing Huang5fbe25c2010-10-18 17:17:23 -07001255/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001256 * Rport address has changed. Nameserver discovery request is being sent.
1257 */
1258static void
1259bfa_fcs_rport_sm_nsdisc_sending(struct bfa_fcs_rport_s *rport,
1260 enum rport_event event)
1261{
1262 bfa_trc(rport->fcs, rport->pwwn);
1263 bfa_trc(rport->fcs, rport->pid);
1264 bfa_trc(rport->fcs, event);
1265
1266 switch (event) {
1267 case RPSM_EVENT_FCXP_SENT:
1268 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sent);
1269 break;
1270
1271 case RPSM_EVENT_DELETE:
1272 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1273 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
1274 bfa_fcs_rport_free(rport);
1275 break;
1276
1277 case RPSM_EVENT_PLOGI_RCVD:
1278 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
1279 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
1280 bfa_fcs_rport_send_plogiacc(rport, NULL);
1281 break;
1282
1283 case RPSM_EVENT_SCN:
1284 case RPSM_EVENT_LOGO_RCVD:
1285 case RPSM_EVENT_PRLO_RCVD:
1286 case RPSM_EVENT_PLOGI_SEND:
1287 break;
1288
1289 case RPSM_EVENT_ADDRESS_CHANGE:
1290 rport->ns_retries = 0; /* reset the retry count */
1291 break;
1292
1293 case RPSM_EVENT_LOGO_IMP:
1294 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
1295 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
1296 bfa_timer_start(rport->fcs->bfa, &rport->timer,
1297 bfa_fcs_rport_timeout, rport,
1298 bfa_fcs_rport_del_timeout);
1299 break;
1300
1301 case RPSM_EVENT_PLOGI_COMP:
Krishna Gudipati61ba4392012-08-22 19:52:58 -07001302 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001303 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
Krishna Gudipati61ba4392012-08-22 19:52:58 -07001304 bfa_fcs_rport_fcs_online_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001305 break;
1306
1307 default:
1308 bfa_sm_fault(rport->fcs, event);
1309 }
1310}
1311
Jing Huang5fbe25c2010-10-18 17:17:23 -07001312/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001313 * Nameserver discovery failed. Waiting for timeout to retry.
1314 */
1315static void
1316bfa_fcs_rport_sm_nsdisc_retry(struct bfa_fcs_rport_s *rport,
1317 enum rport_event event)
1318{
1319 bfa_trc(rport->fcs, rport->pwwn);
1320 bfa_trc(rport->fcs, rport->pid);
1321 bfa_trc(rport->fcs, event);
1322
1323 switch (event) {
1324 case RPSM_EVENT_TIMEOUT:
1325 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
1326 bfa_fcs_rport_send_nsdisc(rport, NULL);
1327 break;
1328
1329 case RPSM_EVENT_SCN:
1330 case RPSM_EVENT_ADDRESS_CHANGE:
1331 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
1332 bfa_timer_stop(&rport->timer);
1333 rport->ns_retries = 0;
1334 bfa_fcs_rport_send_nsdisc(rport, NULL);
1335 break;
1336
1337 case RPSM_EVENT_DELETE:
1338 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1339 bfa_timer_stop(&rport->timer);
1340 bfa_fcs_rport_free(rport);
1341 break;
1342
1343 case RPSM_EVENT_PLOGI_RCVD:
1344 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
1345 bfa_timer_stop(&rport->timer);
1346 bfa_fcs_rport_send_plogiacc(rport, NULL);
1347 break;
1348
1349 case RPSM_EVENT_LOGO_IMP:
1350 rport->pid = 0;
1351 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
1352 bfa_timer_stop(&rport->timer);
1353 bfa_timer_start(rport->fcs->bfa, &rport->timer,
1354 bfa_fcs_rport_timeout, rport,
1355 bfa_fcs_rport_del_timeout);
1356 break;
1357
1358 case RPSM_EVENT_LOGO_RCVD:
1359 bfa_fcs_rport_send_logo_acc(rport);
1360 break;
1361 case RPSM_EVENT_PRLO_RCVD:
1362 bfa_fcs_rport_send_prlo_acc(rport);
1363 break;
1364
1365 case RPSM_EVENT_PLOGI_COMP:
Krishna Gudipati61ba4392012-08-22 19:52:58 -07001366 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001367 bfa_timer_stop(&rport->timer);
Krishna Gudipati61ba4392012-08-22 19:52:58 -07001368 bfa_fcs_rport_fcs_online_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001369 break;
1370
1371 default:
1372 bfa_sm_fault(rport->fcs, event);
1373 }
1374}
1375
Jing Huang5fbe25c2010-10-18 17:17:23 -07001376/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001377 * Rport address has changed. Nameserver discovery request is sent.
1378 */
1379static void
1380bfa_fcs_rport_sm_nsdisc_sent(struct bfa_fcs_rport_s *rport,
1381 enum rport_event event)
1382{
1383 bfa_trc(rport->fcs, rport->pwwn);
1384 bfa_trc(rport->fcs, rport->pid);
1385 bfa_trc(rport->fcs, event);
1386
1387 switch (event) {
1388 case RPSM_EVENT_ACCEPTED:
1389 case RPSM_EVENT_ADDRESS_CHANGE:
1390 if (rport->pid) {
1391 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
1392 bfa_fcs_rport_send_plogi(rport, NULL);
1393 } else {
1394 bfa_sm_set_state(rport,
1395 bfa_fcs_rport_sm_nsdisc_sending);
1396 rport->ns_retries = 0;
1397 bfa_fcs_rport_send_nsdisc(rport, NULL);
1398 }
1399 break;
1400
1401 case RPSM_EVENT_FAILED:
1402 rport->ns_retries++;
1403 if (rport->ns_retries < BFA_FCS_RPORT_MAX_RETRIES) {
1404 bfa_sm_set_state(rport,
1405 bfa_fcs_rport_sm_nsdisc_sending);
1406 bfa_fcs_rport_send_nsdisc(rport, NULL);
1407 } else {
Krishna Gudipatiee1a4a42012-08-22 19:50:43 -07001408 rport->old_pid = rport->pid;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001409 rport->pid = 0;
1410 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
1411 bfa_timer_start(rport->fcs->bfa, &rport->timer,
1412 bfa_fcs_rport_timeout, rport,
1413 bfa_fcs_rport_del_timeout);
1414 };
1415 break;
1416
1417 case RPSM_EVENT_DELETE:
1418 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1419 bfa_fcxp_discard(rport->fcxp);
1420 bfa_fcs_rport_free(rport);
1421 break;
1422
1423 case RPSM_EVENT_PLOGI_RCVD:
1424 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
1425 bfa_fcxp_discard(rport->fcxp);
1426 bfa_fcs_rport_send_plogiacc(rport, NULL);
1427 break;
1428
1429 case RPSM_EVENT_LOGO_IMP:
1430 rport->pid = 0;
1431 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
1432 bfa_fcxp_discard(rport->fcxp);
1433 bfa_timer_start(rport->fcs->bfa, &rport->timer,
1434 bfa_fcs_rport_timeout, rport,
1435 bfa_fcs_rport_del_timeout);
1436 break;
1437
1438
1439 case RPSM_EVENT_PRLO_RCVD:
1440 bfa_fcs_rport_send_prlo_acc(rport);
1441 break;
1442 case RPSM_EVENT_SCN:
Jing Huang5fbe25c2010-10-18 17:17:23 -07001443 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001444 * ignore, wait for NS query response
1445 */
1446 break;
1447
1448 case RPSM_EVENT_LOGO_RCVD:
Jing Huang5fbe25c2010-10-18 17:17:23 -07001449 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001450 * Not logged-in yet. Accept LOGO.
1451 */
1452 bfa_fcs_rport_send_logo_acc(rport);
1453 break;
1454
1455 case RPSM_EVENT_PLOGI_COMP:
Krishna Gudipati61ba4392012-08-22 19:52:58 -07001456 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001457 bfa_fcxp_discard(rport->fcxp);
Krishna Gudipati61ba4392012-08-22 19:52:58 -07001458 bfa_fcs_rport_fcs_online_action(rport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001459 break;
1460
1461 default:
1462 bfa_sm_fault(rport->fcs, event);
1463 }
1464}
1465
Krishna Gudipati61ba4392012-08-22 19:52:58 -07001466/*
1467 * Rport needs to be deleted
1468 * waiting for ITNIM clean up to finish
1469 */
1470static void
1471bfa_fcs_rport_sm_fc4_off_delete(struct bfa_fcs_rport_s *rport,
1472 enum rport_event event)
1473{
1474 bfa_trc(rport->fcs, rport->pwwn);
1475 bfa_trc(rport->fcs, rport->pid);
1476 bfa_trc(rport->fcs, event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001477
Krishna Gudipati61ba4392012-08-22 19:52:58 -07001478 switch (event) {
1479 case RPSM_EVENT_FC4_OFFLINE:
1480 bfa_sm_set_state(rport, bfa_fcs_rport_sm_delete_pending);
1481 bfa_fcs_rport_hal_offline(rport);
1482 break;
1483
1484 case RPSM_EVENT_DELETE:
1485 case RPSM_EVENT_PLOGI_RCVD:
1486 /* Ignore these events */
1487 break;
1488
1489 default:
1490 bfa_sm_fault(rport->fcs, event);
1491 break;
1492 }
1493}
1494
1495/*
1496 * RPort needs to be deleted
1497 * waiting for BFA/FW to finish current processing
1498 */
1499static void
1500bfa_fcs_rport_sm_delete_pending(struct bfa_fcs_rport_s *rport,
1501 enum rport_event event)
1502{
1503 bfa_trc(rport->fcs, rport->pwwn);
1504 bfa_trc(rport->fcs, rport->pid);
1505 bfa_trc(rport->fcs, event);
1506
1507 switch (event) {
1508 case RPSM_EVENT_HCB_OFFLINE:
1509 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1510 bfa_fcs_rport_free(rport);
1511 break;
1512
1513 case RPSM_EVENT_DELETE:
1514 case RPSM_EVENT_LOGO_IMP:
1515 case RPSM_EVENT_PLOGI_RCVD:
1516 /* Ignore these events */
1517 break;
1518
1519 default:
1520 bfa_sm_fault(rport->fcs, event);
1521 }
1522}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001523
Jing Huang5fbe25c2010-10-18 17:17:23 -07001524/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001525 * fcs_rport_private FCS RPORT provate functions
1526 */
1527
1528static void
1529bfa_fcs_rport_send_plogi(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1530{
1531 struct bfa_fcs_rport_s *rport = rport_cbarg;
1532 struct bfa_fcs_lport_s *port = rport->port;
1533 struct fchs_s fchs;
1534 int len;
1535 struct bfa_fcxp_s *fcxp;
1536
1537 bfa_trc(rport->fcs, rport->pwwn);
1538
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001539 fcxp = fcxp_alloced ? fcxp_alloced :
1540 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001541 if (!fcxp) {
1542 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001543 bfa_fcs_rport_send_plogi, rport, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001544 return;
1545 }
1546 rport->fcxp = fcxp;
1547
1548 len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
1549 bfa_fcs_lport_get_fcid(port), 0,
1550 port->port_cfg.pwwn, port->port_cfg.nwwn,
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001551 bfa_fcport_get_maxfrsize(port->fcs->bfa),
1552 bfa_fcport_get_rx_bbcredit(port->fcs->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001553
1554 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1555 FC_CLASS_3, len, &fchs, bfa_fcs_rport_plogi_response,
1556 (void *)rport, FC_MAX_PDUSZ, FC_ELS_TOV);
1557
1558 rport->stats.plogis++;
1559 bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
1560}
1561
1562static void
1563bfa_fcs_rport_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1564 bfa_status_t req_status, u32 rsp_len,
1565 u32 resid_len, struct fchs_s *rsp_fchs)
1566{
1567 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
1568 struct fc_logi_s *plogi_rsp;
1569 struct fc_ls_rjt_s *ls_rjt;
1570 struct bfa_fcs_rport_s *twin;
1571 struct list_head *qe;
1572
1573 bfa_trc(rport->fcs, rport->pwwn);
1574
1575 /*
1576 * Sanity Checks
1577 */
1578 if (req_status != BFA_STATUS_OK) {
1579 bfa_trc(rport->fcs, req_status);
1580 rport->stats.plogi_failed++;
1581 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1582 return;
1583 }
1584
1585 plogi_rsp = (struct fc_logi_s *) BFA_FCXP_RSP_PLD(fcxp);
1586
Jing Huang5fbe25c2010-10-18 17:17:23 -07001587 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001588 * Check for failure first.
1589 */
1590 if (plogi_rsp->els_cmd.els_code != FC_ELS_ACC) {
1591 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
1592
1593 bfa_trc(rport->fcs, ls_rjt->reason_code);
1594 bfa_trc(rport->fcs, ls_rjt->reason_code_expl);
1595
1596 if ((ls_rjt->reason_code == FC_LS_RJT_RSN_UNABLE_TO_PERF_CMD) &&
1597 (ls_rjt->reason_code_expl == FC_LS_RJT_EXP_INSUFF_RES)) {
1598 rport->stats.rjt_insuff_res++;
1599 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RETRY);
1600 return;
1601 }
1602
1603 rport->stats.plogi_rejects++;
1604 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1605 return;
1606 }
1607
Jing Huang5fbe25c2010-10-18 17:17:23 -07001608 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001609 * PLOGI is complete. Make sure this device is not one of the known
1610 * device with a new FC port address.
1611 */
1612 list_for_each(qe, &rport->port->rport_q) {
1613 twin = (struct bfa_fcs_rport_s *) qe;
1614 if (twin == rport)
1615 continue;
1616 if (!rport->pwwn && (plogi_rsp->port_name == twin->pwwn)) {
1617 bfa_trc(rport->fcs, twin->pid);
1618 bfa_trc(rport->fcs, rport->pid);
1619
1620 /* Update plogi stats in twin */
1621 twin->stats.plogis += rport->stats.plogis;
1622 twin->stats.plogi_rejects +=
1623 rport->stats.plogi_rejects;
1624 twin->stats.plogi_timeouts +=
1625 rport->stats.plogi_timeouts;
1626 twin->stats.plogi_failed +=
1627 rport->stats.plogi_failed;
1628 twin->stats.plogi_rcvd += rport->stats.plogi_rcvd;
1629 twin->stats.plogi_accs++;
1630
Maggie Zhangf7f738122010-12-09 19:08:43 -08001631 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001632
1633 bfa_fcs_rport_update(twin, plogi_rsp);
1634 twin->pid = rsp_fchs->s_id;
1635 bfa_sm_send_event(twin, RPSM_EVENT_PLOGI_COMP);
1636 return;
1637 }
1638 }
1639
Jing Huang5fbe25c2010-10-18 17:17:23 -07001640 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001641 * Normal login path -- no evil twins.
1642 */
1643 rport->stats.plogi_accs++;
1644 bfa_fcs_rport_update(rport, plogi_rsp);
1645 bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
1646}
1647
1648static void
1649bfa_fcs_rport_send_plogiacc(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1650{
1651 struct bfa_fcs_rport_s *rport = rport_cbarg;
1652 struct bfa_fcs_lport_s *port = rport->port;
1653 struct fchs_s fchs;
1654 int len;
1655 struct bfa_fcxp_s *fcxp;
1656
1657 bfa_trc(rport->fcs, rport->pwwn);
1658 bfa_trc(rport->fcs, rport->reply_oxid);
1659
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001660 fcxp = fcxp_alloced ? fcxp_alloced :
1661 bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001662 if (!fcxp) {
1663 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001664 bfa_fcs_rport_send_plogiacc, rport, BFA_FALSE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001665 return;
1666 }
1667 rport->fcxp = fcxp;
1668
1669 len = fc_plogi_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1670 rport->pid, bfa_fcs_lport_get_fcid(port),
1671 rport->reply_oxid, port->port_cfg.pwwn,
1672 port->port_cfg.nwwn,
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001673 bfa_fcport_get_maxfrsize(port->fcs->bfa),
1674 bfa_fcport_get_rx_bbcredit(port->fcs->bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001675
1676 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1677 FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
1678
1679 bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
1680}
1681
1682static void
1683bfa_fcs_rport_send_adisc(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1684{
1685 struct bfa_fcs_rport_s *rport = rport_cbarg;
1686 struct bfa_fcs_lport_s *port = rport->port;
1687 struct fchs_s fchs;
1688 int len;
1689 struct bfa_fcxp_s *fcxp;
1690
1691 bfa_trc(rport->fcs, rport->pwwn);
1692
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001693 fcxp = fcxp_alloced ? fcxp_alloced :
1694 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001695 if (!fcxp) {
1696 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001697 bfa_fcs_rport_send_adisc, rport, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001698 return;
1699 }
1700 rport->fcxp = fcxp;
1701
1702 len = fc_adisc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
1703 bfa_fcs_lport_get_fcid(port), 0,
1704 port->port_cfg.pwwn, port->port_cfg.nwwn);
1705
1706 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1707 FC_CLASS_3, len, &fchs, bfa_fcs_rport_adisc_response,
1708 rport, FC_MAX_PDUSZ, FC_ELS_TOV);
1709
1710 rport->stats.adisc_sent++;
1711 bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
1712}
1713
1714static void
1715bfa_fcs_rport_adisc_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1716 bfa_status_t req_status, u32 rsp_len,
1717 u32 resid_len, struct fchs_s *rsp_fchs)
1718{
1719 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
1720 void *pld = bfa_fcxp_get_rspbuf(fcxp);
1721 struct fc_ls_rjt_s *ls_rjt;
1722
1723 if (req_status != BFA_STATUS_OK) {
1724 bfa_trc(rport->fcs, req_status);
1725 rport->stats.adisc_failed++;
1726 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1727 return;
1728 }
1729
1730 if (fc_adisc_rsp_parse((struct fc_adisc_s *)pld, rsp_len, rport->pwwn,
1731 rport->nwwn) == FC_PARSE_OK) {
1732 rport->stats.adisc_accs++;
1733 bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
1734 return;
1735 }
1736
1737 rport->stats.adisc_rejects++;
1738 ls_rjt = pld;
1739 bfa_trc(rport->fcs, ls_rjt->els_cmd.els_code);
1740 bfa_trc(rport->fcs, ls_rjt->reason_code);
1741 bfa_trc(rport->fcs, ls_rjt->reason_code_expl);
1742 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1743}
1744
1745static void
1746bfa_fcs_rport_send_nsdisc(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1747{
1748 struct bfa_fcs_rport_s *rport = rport_cbarg;
1749 struct bfa_fcs_lport_s *port = rport->port;
1750 struct fchs_s fchs;
1751 struct bfa_fcxp_s *fcxp;
1752 int len;
1753 bfa_cb_fcxp_send_t cbfn;
1754
1755 bfa_trc(rport->fcs, rport->pid);
1756
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001757 fcxp = fcxp_alloced ? fcxp_alloced :
1758 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001759 if (!fcxp) {
1760 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001761 bfa_fcs_rport_send_nsdisc, rport, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001762 return;
1763 }
1764 rport->fcxp = fcxp;
1765
1766 if (rport->pwwn) {
1767 len = fc_gidpn_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1768 bfa_fcs_lport_get_fcid(port), 0, rport->pwwn);
1769 cbfn = bfa_fcs_rport_gidpn_response;
1770 } else {
1771 len = fc_gpnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1772 bfa_fcs_lport_get_fcid(port), 0, rport->pid);
1773 cbfn = bfa_fcs_rport_gpnid_response;
1774 }
1775
1776 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1777 FC_CLASS_3, len, &fchs, cbfn,
1778 (void *)rport, FC_MAX_PDUSZ, FC_FCCT_TOV);
1779
1780 bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
1781}
1782
1783static void
1784bfa_fcs_rport_gidpn_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1785 bfa_status_t req_status, u32 rsp_len,
1786 u32 resid_len, struct fchs_s *rsp_fchs)
1787{
1788 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
1789 struct ct_hdr_s *cthdr;
1790 struct fcgs_gidpn_resp_s *gidpn_rsp;
1791 struct bfa_fcs_rport_s *twin;
1792 struct list_head *qe;
1793
1794 bfa_trc(rport->fcs, rport->pwwn);
1795
1796 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07001797 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001798
1799 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
1800 /* Check if the pid is the same as before. */
1801 gidpn_rsp = (struct fcgs_gidpn_resp_s *) (cthdr + 1);
1802
1803 if (gidpn_rsp->dap == rport->pid) {
1804 /* Device is online */
1805 bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
1806 } else {
1807 /*
1808 * Device's PID has changed. We need to cleanup
1809 * and re-login. If there is another device with
1810 * the the newly discovered pid, send an scn notice
1811 * so that its new pid can be discovered.
1812 */
1813 list_for_each(qe, &rport->port->rport_q) {
1814 twin = (struct bfa_fcs_rport_s *) qe;
1815 if (twin == rport)
1816 continue;
1817 if (gidpn_rsp->dap == twin->pid) {
1818 bfa_trc(rport->fcs, twin->pid);
1819 bfa_trc(rport->fcs, rport->pid);
1820
1821 twin->pid = 0;
1822 bfa_sm_send_event(twin,
1823 RPSM_EVENT_ADDRESS_CHANGE);
1824 }
1825 }
1826 rport->pid = gidpn_rsp->dap;
1827 bfa_sm_send_event(rport, RPSM_EVENT_ADDRESS_CHANGE);
1828 }
1829 return;
1830 }
1831
1832 /*
1833 * Reject Response
1834 */
1835 switch (cthdr->reason_code) {
1836 case CT_RSN_LOGICAL_BUSY:
1837 /*
1838 * Need to retry
1839 */
1840 bfa_sm_send_event(rport, RPSM_EVENT_TIMEOUT);
1841 break;
1842
1843 case CT_RSN_UNABLE_TO_PERF:
1844 /*
1845 * device doesn't exist : Start timer to cleanup this later.
1846 */
1847 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1848 break;
1849
1850 default:
1851 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1852 break;
1853 }
1854}
1855
1856static void
1857bfa_fcs_rport_gpnid_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1858 bfa_status_t req_status, u32 rsp_len,
1859 u32 resid_len, struct fchs_s *rsp_fchs)
1860{
1861 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
1862 struct ct_hdr_s *cthdr;
1863
1864 bfa_trc(rport->fcs, rport->pwwn);
1865
1866 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
Jing Huangba816ea2010-10-18 17:10:50 -07001867 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001868
1869 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
1870 bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
1871 return;
1872 }
1873
1874 /*
1875 * Reject Response
1876 */
1877 switch (cthdr->reason_code) {
1878 case CT_RSN_LOGICAL_BUSY:
1879 /*
1880 * Need to retry
1881 */
1882 bfa_sm_send_event(rport, RPSM_EVENT_TIMEOUT);
1883 break;
1884
1885 case CT_RSN_UNABLE_TO_PERF:
1886 /*
1887 * device doesn't exist : Start timer to cleanup this later.
1888 */
1889 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1890 break;
1891
1892 default:
1893 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1894 break;
1895 }
1896}
1897
Jing Huang5fbe25c2010-10-18 17:17:23 -07001898/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001899 * Called to send a logout to the rport.
1900 */
1901static void
1902bfa_fcs_rport_send_logo(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1903{
1904 struct bfa_fcs_rport_s *rport = rport_cbarg;
1905 struct bfa_fcs_lport_s *port;
1906 struct fchs_s fchs;
1907 struct bfa_fcxp_s *fcxp;
1908 u16 len;
1909
1910 bfa_trc(rport->fcs, rport->pid);
1911
1912 port = rport->port;
1913
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001914 fcxp = fcxp_alloced ? fcxp_alloced :
1915 bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001916 if (!fcxp) {
1917 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001918 bfa_fcs_rport_send_logo, rport, BFA_FALSE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001919 return;
1920 }
1921 rport->fcxp = fcxp;
1922
1923 len = fc_logo_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
1924 bfa_fcs_lport_get_fcid(port), 0,
1925 bfa_fcs_lport_get_pwwn(port));
1926
1927 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1928 FC_CLASS_3, len, &fchs, NULL,
1929 rport, FC_MAX_PDUSZ, FC_ELS_TOV);
1930
1931 rport->stats.logos++;
1932 bfa_fcxp_discard(rport->fcxp);
1933 bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
1934}
1935
Jing Huang5fbe25c2010-10-18 17:17:23 -07001936/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001937 * Send ACC for a LOGO received.
1938 */
1939static void
1940bfa_fcs_rport_send_logo_acc(void *rport_cbarg)
1941{
1942 struct bfa_fcs_rport_s *rport = rport_cbarg;
1943 struct bfa_fcs_lport_s *port;
1944 struct fchs_s fchs;
1945 struct bfa_fcxp_s *fcxp;
1946 u16 len;
1947
1948 bfa_trc(rport->fcs, rport->pid);
1949
1950 port = rport->port;
1951
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001952 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001953 if (!fcxp)
1954 return;
1955
1956 rport->stats.logo_rcvd++;
1957 len = fc_logo_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1958 rport->pid, bfa_fcs_lport_get_fcid(port),
1959 rport->reply_oxid);
1960
1961 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1962 FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
1963}
1964
Jing Huang5fbe25c2010-10-18 17:17:23 -07001965/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001966 * brief
1967 * This routine will be called by bfa_timer on timer timeouts.
1968 *
1969 * param[in] rport - pointer to bfa_fcs_lport_ns_t.
1970 * param[out] rport_status - pointer to return vport status in
1971 *
1972 * return
1973 * void
1974 *
1975 * Special Considerations:
1976 *
1977 * note
1978 */
1979static void
1980bfa_fcs_rport_timeout(void *arg)
1981{
1982 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) arg;
1983
1984 rport->stats.plogi_timeouts++;
1985 bfa_stats(rport->port, rport_plogi_timeouts);
1986 bfa_sm_send_event(rport, RPSM_EVENT_TIMEOUT);
1987}
1988
1989static void
1990bfa_fcs_rport_process_prli(struct bfa_fcs_rport_s *rport,
1991 struct fchs_s *rx_fchs, u16 len)
1992{
1993 struct bfa_fcxp_s *fcxp;
1994 struct fchs_s fchs;
1995 struct bfa_fcs_lport_s *port = rport->port;
1996 struct fc_prli_s *prli;
1997
1998 bfa_trc(port->fcs, rx_fchs->s_id);
1999 bfa_trc(port->fcs, rx_fchs->d_id);
2000
2001 rport->stats.prli_rcvd++;
2002
2003 /*
2004 * We are in Initiator Mode
2005 */
2006 prli = (struct fc_prli_s *) (rx_fchs + 1);
2007
2008 if (prli->parampage.servparams.target) {
2009 /*
2010 * PRLI from a target ?
2011 * Send the Acc.
2012 * PRLI sent by us will be used to transition the IT nexus,
2013 * once the response is received from the target.
2014 */
2015 bfa_trc(port->fcs, rx_fchs->s_id);
2016 rport->scsi_function = BFA_RPORT_TARGET;
2017 } else {
2018 bfa_trc(rport->fcs, prli->parampage.type);
2019 rport->scsi_function = BFA_RPORT_INITIATOR;
2020 bfa_fcs_itnim_is_initiator(rport->itnim);
2021 }
2022
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07002023 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002024 if (!fcxp)
2025 return;
2026
2027 len = fc_prli_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
2028 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
2029 rx_fchs->ox_id, port->port_cfg.roles);
2030
2031 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
2032 FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
2033}
2034
2035static void
2036bfa_fcs_rport_process_rpsc(struct bfa_fcs_rport_s *rport,
2037 struct fchs_s *rx_fchs, u16 len)
2038{
2039 struct bfa_fcxp_s *fcxp;
2040 struct fchs_s fchs;
2041 struct bfa_fcs_lport_s *port = rport->port;
2042 struct fc_rpsc_speed_info_s speeds;
2043 struct bfa_port_attr_s pport_attr;
2044
2045 bfa_trc(port->fcs, rx_fchs->s_id);
2046 bfa_trc(port->fcs, rx_fchs->d_id);
2047
2048 rport->stats.rpsc_rcvd++;
2049 speeds.port_speed_cap =
2050 RPSC_SPEED_CAP_1G | RPSC_SPEED_CAP_2G | RPSC_SPEED_CAP_4G |
2051 RPSC_SPEED_CAP_8G;
2052
2053 /*
2054 * get curent speed from pport attributes from BFA
2055 */
2056 bfa_fcport_get_attr(port->fcs->bfa, &pport_attr);
2057
2058 speeds.port_op_speed = fc_bfa_speed_to_rpsc_operspeed(pport_attr.speed);
2059
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07002060 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002061 if (!fcxp)
2062 return;
2063
2064 len = fc_rpsc_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
2065 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
2066 rx_fchs->ox_id, &speeds);
2067
2068 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
2069 FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
2070}
2071
2072static void
2073bfa_fcs_rport_process_adisc(struct bfa_fcs_rport_s *rport,
2074 struct fchs_s *rx_fchs, u16 len)
2075{
2076 struct bfa_fcxp_s *fcxp;
2077 struct fchs_s fchs;
2078 struct bfa_fcs_lport_s *port = rport->port;
2079 struct fc_adisc_s *adisc;
2080
2081 bfa_trc(port->fcs, rx_fchs->s_id);
2082 bfa_trc(port->fcs, rx_fchs->d_id);
2083
2084 rport->stats.adisc_rcvd++;
2085
2086 adisc = (struct fc_adisc_s *) (rx_fchs + 1);
2087
2088 /*
2089 * Accept if the itnim for this rport is online.
2090 * Else reject the ADISC.
2091 */
2092 if (bfa_fcs_itnim_get_online_state(rport->itnim) == BFA_STATUS_OK) {
2093
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07002094 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002095 if (!fcxp)
2096 return;
2097
2098 len = fc_adisc_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
2099 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
2100 rx_fchs->ox_id, port->port_cfg.pwwn,
2101 port->port_cfg.nwwn);
2102
2103 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag,
2104 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
2105 FC_MAX_PDUSZ, 0);
2106 } else {
2107 rport->stats.adisc_rejected++;
2108 bfa_fcs_rport_send_ls_rjt(rport, rx_fchs,
2109 FC_LS_RJT_RSN_UNABLE_TO_PERF_CMD,
2110 FC_LS_RJT_EXP_LOGIN_REQUIRED);
2111 }
2112}
2113
2114static void
2115bfa_fcs_rport_hal_online(struct bfa_fcs_rport_s *rport)
2116{
2117 struct bfa_fcs_lport_s *port = rport->port;
2118 struct bfa_rport_info_s rport_info;
2119
2120 rport_info.pid = rport->pid;
2121 rport_info.local_pid = port->pid;
2122 rport_info.lp_tag = port->lp_tag;
2123 rport_info.vf_id = port->fabric->vf_id;
2124 rport_info.vf_en = port->fabric->is_vf;
2125 rport_info.fc_class = rport->fc_cos;
2126 rport_info.cisc = rport->cisc;
2127 rport_info.max_frmsz = rport->maxfrsize;
2128 bfa_rport_online(rport->bfa_rport, &rport_info);
2129}
2130
Krishna Gudipati61ba4392012-08-22 19:52:58 -07002131static void
2132bfa_fcs_rport_hal_offline(struct bfa_fcs_rport_s *rport)
2133{
2134 if (rport->bfa_rport)
2135 bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE);
2136 else
2137 bfa_cb_rport_offline(rport);
2138}
2139
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002140static struct bfa_fcs_rport_s *
2141bfa_fcs_rport_alloc(struct bfa_fcs_lport_s *port, wwn_t pwwn, u32 rpid)
2142{
2143 struct bfa_fcs_s *fcs = port->fcs;
2144 struct bfa_fcs_rport_s *rport;
2145 struct bfad_rport_s *rport_drv;
2146
Jing Huang5fbe25c2010-10-18 17:17:23 -07002147 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002148 * allocate rport
2149 */
Krishna Gudipati61ba4392012-08-22 19:52:58 -07002150 if (fcs->num_rport_logins >= bfa_fcs_rport_max_logins) {
2151 bfa_trc(fcs, rpid);
2152 return NULL;
2153 }
2154
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002155 if (bfa_fcb_rport_alloc(fcs->bfad, &rport, &rport_drv)
2156 != BFA_STATUS_OK) {
2157 bfa_trc(fcs, rpid);
2158 return NULL;
2159 }
2160
2161 /*
2162 * Initialize r-port
2163 */
2164 rport->port = port;
2165 rport->fcs = fcs;
2166 rport->rp_drv = rport_drv;
2167 rport->pid = rpid;
2168 rport->pwwn = pwwn;
Krishna Gudipatiee1a4a42012-08-22 19:50:43 -07002169 rport->old_pid = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002170
Krishna Gudipati61ba4392012-08-22 19:52:58 -07002171 rport->bfa_rport = NULL;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002172
Jing Huang5fbe25c2010-10-18 17:17:23 -07002173 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002174 * allocate FC-4s
2175 */
Jing Huangd4b671c2010-12-26 21:46:35 -08002176 WARN_ON(!bfa_fcs_lport_is_initiator(port));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002177
2178 if (bfa_fcs_lport_is_initiator(port)) {
2179 rport->itnim = bfa_fcs_itnim_create(rport);
2180 if (!rport->itnim) {
2181 bfa_trc(fcs, rpid);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002182 kfree(rport_drv);
2183 return NULL;
2184 }
2185 }
2186
2187 bfa_fcs_lport_add_rport(port, rport);
Krishna Gudipati61ba4392012-08-22 19:52:58 -07002188 fcs->num_rport_logins++;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002189
2190 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
2191
2192 /* Initialize the Rport Features(RPF) Sub Module */
2193 if (!BFA_FCS_PID_IS_WKA(rport->pid))
2194 bfa_fcs_rpf_init(rport);
2195
2196 return rport;
2197}
2198
2199
2200static void
2201bfa_fcs_rport_free(struct bfa_fcs_rport_s *rport)
2202{
2203 struct bfa_fcs_lport_s *port = rport->port;
Krishna Gudipati61ba4392012-08-22 19:52:58 -07002204 struct bfa_fcs_s *fcs = port->fcs;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002205
Jing Huang5fbe25c2010-10-18 17:17:23 -07002206 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002207 * - delete FC-4s
2208 * - delete BFA rport
2209 * - remove from queue of rports
2210 */
Krishna Gudipati61ba4392012-08-22 19:52:58 -07002211 rport->plogi_pending = BFA_FALSE;
2212
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002213 if (bfa_fcs_lport_is_initiator(port)) {
2214 bfa_fcs_itnim_delete(rport->itnim);
2215 if (rport->pid != 0 && !BFA_FCS_PID_IS_WKA(rport->pid))
2216 bfa_fcs_rpf_rport_offline(rport);
2217 }
2218
Krishna Gudipati61ba4392012-08-22 19:52:58 -07002219 if (rport->bfa_rport) {
2220 bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_DELETE);
2221 rport->bfa_rport = NULL;
2222 }
2223
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002224 bfa_fcs_lport_del_rport(port, rport);
Krishna Gudipati61ba4392012-08-22 19:52:58 -07002225 fcs->num_rport_logins--;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002226 kfree(rport->rp_drv);
2227}
2228
2229static void
Krishna Gudipati7826f302011-07-20 16:59:13 -07002230bfa_fcs_rport_aen_post(struct bfa_fcs_rport_s *rport,
2231 enum bfa_rport_aen_event event,
2232 struct bfa_rport_aen_data_s *data)
2233{
2234 struct bfa_fcs_lport_s *port = rport->port;
2235 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
2236 struct bfa_aen_entry_s *aen_entry;
2237
2238 bfad_get_aen_entry(bfad, aen_entry);
2239 if (!aen_entry)
2240 return;
2241
2242 if (event == BFA_RPORT_AEN_QOS_PRIO)
2243 aen_entry->aen_data.rport.priv.qos = data->priv.qos;
2244 else if (event == BFA_RPORT_AEN_QOS_FLOWID)
2245 aen_entry->aen_data.rport.priv.qos = data->priv.qos;
2246
2247 aen_entry->aen_data.rport.vf_id = rport->port->fabric->vf_id;
2248 aen_entry->aen_data.rport.ppwwn = bfa_fcs_lport_get_pwwn(
2249 bfa_fcs_get_base_port(rport->fcs));
2250 aen_entry->aen_data.rport.lpwwn = bfa_fcs_lport_get_pwwn(rport->port);
2251 aen_entry->aen_data.rport.rpwwn = rport->pwwn;
2252
2253 /* Send the AEN notification */
2254 bfad_im_post_vendor_event(aen_entry, bfad, ++rport->fcs->fcs_aen_seq,
2255 BFA_AEN_CAT_RPORT, event);
2256}
2257
2258static void
Krishna Gudipati61ba4392012-08-22 19:52:58 -07002259bfa_fcs_rport_fcs_online_action(struct bfa_fcs_rport_s *rport)
2260{
2261 if ((!rport->pid) || (!rport->pwwn)) {
2262 bfa_trc(rport->fcs, rport->pid);
2263 bfa_sm_fault(rport->fcs, rport->pid);
2264 }
2265
2266 bfa_sm_send_event(rport->itnim, BFA_FCS_ITNIM_SM_FCS_ONLINE);
2267}
2268
2269static void
2270bfa_fcs_rport_hal_online_action(struct bfa_fcs_rport_s *rport)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002271{
2272 struct bfa_fcs_lport_s *port = rport->port;
2273 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
2274 char lpwwn_buf[BFA_STRING_32];
2275 char rpwwn_buf[BFA_STRING_32];
2276
2277 rport->stats.onlines++;
2278
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07002279 if ((!rport->pid) || (!rport->pwwn)) {
2280 bfa_trc(rport->fcs, rport->pid);
2281 bfa_sm_fault(rport->fcs, rport->pid);
2282 }
2283
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002284 if (bfa_fcs_lport_is_initiator(port)) {
Krishna Gudipati61ba4392012-08-22 19:52:58 -07002285 bfa_fcs_itnim_brp_online(rport->itnim);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002286 if (!BFA_FCS_PID_IS_WKA(rport->pid))
2287 bfa_fcs_rpf_rport_online(rport);
2288 };
2289
2290 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
2291 wwn2str(rpwwn_buf, rport->pwwn);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002292 if (!BFA_FCS_PID_IS_WKA(rport->pid)) {
Jing Huang88166242010-12-09 17:11:53 -08002293 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002294 "Remote port (WWN = %s) online for logical port (WWN = %s)\n",
2295 rpwwn_buf, lpwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002296 bfa_fcs_rport_aen_post(rport, BFA_RPORT_AEN_ONLINE, NULL);
2297 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002298}
2299
2300static void
Krishna Gudipati61ba4392012-08-22 19:52:58 -07002301bfa_fcs_rport_fcs_offline_action(struct bfa_fcs_rport_s *rport)
2302{
2303 if (!BFA_FCS_PID_IS_WKA(rport->pid))
2304 bfa_fcs_rpf_rport_offline(rport);
2305
2306 bfa_fcs_itnim_rport_offline(rport->itnim);
2307}
2308
2309static void
2310bfa_fcs_rport_hal_offline_action(struct bfa_fcs_rport_s *rport)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002311{
2312 struct bfa_fcs_lport_s *port = rport->port;
2313 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
2314 char lpwwn_buf[BFA_STRING_32];
2315 char rpwwn_buf[BFA_STRING_32];
2316
Krishna Gudipati61ba4392012-08-22 19:52:58 -07002317 if (!rport->bfa_rport) {
2318 bfa_fcs_rport_fcs_offline_action(rport);
2319 return;
2320 }
2321
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002322 rport->stats.offlines++;
2323
2324 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
2325 wwn2str(rpwwn_buf, rport->pwwn);
2326 if (!BFA_FCS_PID_IS_WKA(rport->pid)) {
Krishna Gudipati7826f302011-07-20 16:59:13 -07002327 if (bfa_fcs_lport_is_online(rport->port) == BFA_TRUE) {
Jing Huang88166242010-12-09 17:11:53 -08002328 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002329 "Remote port (WWN = %s) connectivity lost for "
2330 "logical port (WWN = %s)\n",
2331 rpwwn_buf, lpwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002332 bfa_fcs_rport_aen_post(rport,
2333 BFA_RPORT_AEN_DISCONNECT, NULL);
2334 } else {
Jing Huang88166242010-12-09 17:11:53 -08002335 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002336 "Remote port (WWN = %s) offlined by "
2337 "logical port (WWN = %s)\n",
2338 rpwwn_buf, lpwwn_buf);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002339 bfa_fcs_rport_aen_post(rport,
2340 BFA_RPORT_AEN_OFFLINE, NULL);
2341 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002342 }
2343
2344 if (bfa_fcs_lport_is_initiator(port)) {
2345 bfa_fcs_itnim_rport_offline(rport->itnim);
2346 if (!BFA_FCS_PID_IS_WKA(rport->pid))
2347 bfa_fcs_rpf_rport_offline(rport);
2348 }
2349}
2350
Jing Huang5fbe25c2010-10-18 17:17:23 -07002351/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002352 * Update rport parameters from PLOGI or PLOGI accept.
2353 */
2354static void
2355bfa_fcs_rport_update(struct bfa_fcs_rport_s *rport, struct fc_logi_s *plogi)
2356{
2357 bfa_fcs_lport_t *port = rport->port;
2358
Jing Huang5fbe25c2010-10-18 17:17:23 -07002359 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002360 * - port name
2361 * - node name
2362 */
2363 rport->pwwn = plogi->port_name;
2364 rport->nwwn = plogi->node_name;
2365
Jing Huang5fbe25c2010-10-18 17:17:23 -07002366 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002367 * - class of service
2368 */
2369 rport->fc_cos = 0;
2370 if (plogi->class3.class_valid)
2371 rport->fc_cos = FC_CLASS_3;
2372
2373 if (plogi->class2.class_valid)
2374 rport->fc_cos |= FC_CLASS_2;
2375
Jing Huang5fbe25c2010-10-18 17:17:23 -07002376 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002377 * - CISC
2378 * - MAX receive frame size
2379 */
2380 rport->cisc = plogi->csp.cisc;
Krishna Gudipatibd5a0262012-03-13 17:41:02 -07002381 if (be16_to_cpu(plogi->class3.rxsz) < be16_to_cpu(plogi->csp.rxsz))
2382 rport->maxfrsize = be16_to_cpu(plogi->class3.rxsz);
2383 else
2384 rport->maxfrsize = be16_to_cpu(plogi->csp.rxsz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002385
Jing Huangba816ea2010-10-18 17:10:50 -07002386 bfa_trc(port->fcs, be16_to_cpu(plogi->csp.bbcred));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002387 bfa_trc(port->fcs, port->fabric->bb_credit);
Jing Huang5fbe25c2010-10-18 17:17:23 -07002388 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002389 * Direct Attach P2P mode :
2390 * This is to handle a bug (233476) in IBM targets in Direct Attach
2391 * Mode. Basically, in FLOGI Accept the target would have
2392 * erroneously set the BB Credit to the value used in the FLOGI
2393 * sent by the HBA. It uses the correct value (its own BB credit)
2394 * in PLOGI.
2395 */
2396 if ((!bfa_fcs_fabric_is_switched(port->fabric)) &&
Jing Huangba816ea2010-10-18 17:10:50 -07002397 (be16_to_cpu(plogi->csp.bbcred) < port->fabric->bb_credit)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002398
Jing Huangba816ea2010-10-18 17:10:50 -07002399 bfa_trc(port->fcs, be16_to_cpu(plogi->csp.bbcred));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002400 bfa_trc(port->fcs, port->fabric->bb_credit);
2401
Jing Huangba816ea2010-10-18 17:10:50 -07002402 port->fabric->bb_credit = be16_to_cpu(plogi->csp.bbcred);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002403 bfa_fcport_set_tx_bbcredit(port->fcs->bfa,
Krishna Gudipatibe540a92011-06-13 15:53:04 -07002404 port->fabric->bb_credit, 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002405 }
2406
2407}
2408
Jing Huang5fbe25c2010-10-18 17:17:23 -07002409/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002410 * Called to handle LOGO received from an existing remote port.
2411 */
2412static void
2413bfa_fcs_rport_process_logo(struct bfa_fcs_rport_s *rport, struct fchs_s *fchs)
2414{
2415 rport->reply_oxid = fchs->ox_id;
2416 bfa_trc(rport->fcs, rport->reply_oxid);
2417
2418 rport->prlo = BFA_FALSE;
2419 rport->stats.logo_rcvd++;
2420 bfa_sm_send_event(rport, RPSM_EVENT_LOGO_RCVD);
2421}
2422
2423
2424
Jing Huang5fbe25c2010-10-18 17:17:23 -07002425/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002426 * fcs_rport_public FCS rport public interfaces
2427 */
2428
Jing Huang5fbe25c2010-10-18 17:17:23 -07002429/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002430 * Called by bport/vport to create a remote port instance for a discovered
2431 * remote device.
2432 *
2433 * @param[in] port - base port or vport
2434 * @param[in] rpid - remote port ID
2435 *
2436 * @return None
2437 */
2438struct bfa_fcs_rport_s *
2439bfa_fcs_rport_create(struct bfa_fcs_lport_s *port, u32 rpid)
2440{
2441 struct bfa_fcs_rport_s *rport;
2442
2443 bfa_trc(port->fcs, rpid);
2444 rport = bfa_fcs_rport_alloc(port, WWN_NULL, rpid);
2445 if (!rport)
2446 return NULL;
2447
2448 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_SEND);
2449 return rport;
2450}
2451
Jing Huang5fbe25c2010-10-18 17:17:23 -07002452/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002453 * Called to create a rport for which only the wwn is known.
2454 *
2455 * @param[in] port - base port
2456 * @param[in] rpwwn - remote port wwn
2457 *
2458 * @return None
2459 */
2460struct bfa_fcs_rport_s *
2461bfa_fcs_rport_create_by_wwn(struct bfa_fcs_lport_s *port, wwn_t rpwwn)
2462{
2463 struct bfa_fcs_rport_s *rport;
2464 bfa_trc(port->fcs, rpwwn);
2465 rport = bfa_fcs_rport_alloc(port, rpwwn, 0);
2466 if (!rport)
2467 return NULL;
2468
2469 bfa_sm_send_event(rport, RPSM_EVENT_ADDRESS_DISC);
2470 return rport;
2471}
Jing Huang5fbe25c2010-10-18 17:17:23 -07002472/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002473 * Called by bport in private loop topology to indicate that a
2474 * rport has been discovered and plogi has been completed.
2475 *
2476 * @param[in] port - base port or vport
2477 * @param[in] rpid - remote port ID
2478 */
2479void
2480bfa_fcs_rport_start(struct bfa_fcs_lport_s *port, struct fchs_s *fchs,
2481 struct fc_logi_s *plogi)
2482{
2483 struct bfa_fcs_rport_s *rport;
2484
2485 rport = bfa_fcs_rport_alloc(port, WWN_NULL, fchs->s_id);
2486 if (!rport)
2487 return;
2488
2489 bfa_fcs_rport_update(rport, plogi);
2490
2491 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_COMP);
2492}
2493
Jing Huang5fbe25c2010-10-18 17:17:23 -07002494/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002495 * Called by bport/vport to handle PLOGI received from a new remote port.
2496 * If an existing rport does a plogi, it will be handled separately.
2497 */
2498void
2499bfa_fcs_rport_plogi_create(struct bfa_fcs_lport_s *port, struct fchs_s *fchs,
2500 struct fc_logi_s *plogi)
2501{
2502 struct bfa_fcs_rport_s *rport;
2503
2504 rport = bfa_fcs_rport_alloc(port, plogi->port_name, fchs->s_id);
2505 if (!rport)
2506 return;
2507
2508 bfa_fcs_rport_update(rport, plogi);
2509
2510 rport->reply_oxid = fchs->ox_id;
2511 bfa_trc(rport->fcs, rport->reply_oxid);
2512
2513 rport->stats.plogi_rcvd++;
2514 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RCVD);
2515}
2516
Jing Huang5fbe25c2010-10-18 17:17:23 -07002517/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002518 * Called by bport/vport to handle PLOGI received from an existing
2519 * remote port.
2520 */
2521void
2522bfa_fcs_rport_plogi(struct bfa_fcs_rport_s *rport, struct fchs_s *rx_fchs,
2523 struct fc_logi_s *plogi)
2524{
Jing Huang5fbe25c2010-10-18 17:17:23 -07002525 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002526 * @todo Handle P2P and initiator-initiator.
2527 */
2528
2529 bfa_fcs_rport_update(rport, plogi);
2530
2531 rport->reply_oxid = rx_fchs->ox_id;
2532 bfa_trc(rport->fcs, rport->reply_oxid);
2533
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07002534 rport->pid = rx_fchs->s_id;
2535 bfa_trc(rport->fcs, rport->pid);
2536
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002537 rport->stats.plogi_rcvd++;
2538 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RCVD);
2539}
2540
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002541
Jing Huang5fbe25c2010-10-18 17:17:23 -07002542/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002543 * Called by bport/vport to notify SCN for the remote port
2544 */
2545void
2546bfa_fcs_rport_scn(struct bfa_fcs_rport_s *rport)
2547{
2548 rport->stats.rscns++;
2549 bfa_sm_send_event(rport, RPSM_EVENT_SCN);
2550}
2551
Jing Huang5fbe25c2010-10-18 17:17:23 -07002552/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002553 * brief
2554 * This routine BFA callback for bfa_rport_online() call.
2555 *
2556 * param[in] cb_arg - rport struct.
2557 *
2558 * return
2559 * void
2560 *
2561 * Special Considerations:
2562 *
2563 * note
2564 */
2565void
2566bfa_cb_rport_online(void *cbarg)
2567{
2568
2569 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
2570
2571 bfa_trc(rport->fcs, rport->pwwn);
2572 bfa_sm_send_event(rport, RPSM_EVENT_HCB_ONLINE);
2573}
2574
Jing Huang5fbe25c2010-10-18 17:17:23 -07002575/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002576 * brief
2577 * This routine BFA callback for bfa_rport_offline() call.
2578 *
2579 * param[in] rport -
2580 *
2581 * return
2582 * void
2583 *
2584 * Special Considerations:
2585 *
2586 * note
2587 */
2588void
2589bfa_cb_rport_offline(void *cbarg)
2590{
2591 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
2592
2593 bfa_trc(rport->fcs, rport->pwwn);
2594 bfa_sm_send_event(rport, RPSM_EVENT_HCB_OFFLINE);
2595}
2596
Jing Huang5fbe25c2010-10-18 17:17:23 -07002597/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002598 * brief
2599 * This routine is a static BFA callback when there is a QoS flow_id
2600 * change notification
2601 *
2602 * param[in] rport -
2603 *
2604 * return
2605 * void
2606 *
2607 * Special Considerations:
2608 *
2609 * note
2610 */
2611void
2612bfa_cb_rport_qos_scn_flowid(void *cbarg,
2613 struct bfa_rport_qos_attr_s old_qos_attr,
2614 struct bfa_rport_qos_attr_s new_qos_attr)
2615{
2616 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
Krishna Gudipati7826f302011-07-20 16:59:13 -07002617 struct bfa_rport_aen_data_s aen_data;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002618
2619 bfa_trc(rport->fcs, rport->pwwn);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002620 aen_data.priv.qos = new_qos_attr;
2621 bfa_fcs_rport_aen_post(rport, BFA_RPORT_AEN_QOS_FLOWID, &aen_data);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002622}
2623
Jing Huang5fbe25c2010-10-18 17:17:23 -07002624/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002625 * brief
2626 * This routine is a static BFA callback when there is a QoS priority
2627 * change notification
2628 *
2629 * param[in] rport -
2630 *
2631 * return
2632 * void
2633 *
2634 * Special Considerations:
2635 *
2636 * note
2637 */
2638void
2639bfa_cb_rport_qos_scn_prio(void *cbarg,
2640 struct bfa_rport_qos_attr_s old_qos_attr,
2641 struct bfa_rport_qos_attr_s new_qos_attr)
2642{
2643 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
Krishna Gudipati7826f302011-07-20 16:59:13 -07002644 struct bfa_rport_aen_data_s aen_data;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002645
2646 bfa_trc(rport->fcs, rport->pwwn);
Krishna Gudipati7826f302011-07-20 16:59:13 -07002647 aen_data.priv.qos = new_qos_attr;
2648 bfa_fcs_rport_aen_post(rport, BFA_RPORT_AEN_QOS_PRIO, &aen_data);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002649}
2650
Jing Huang5fbe25c2010-10-18 17:17:23 -07002651/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002652 * Called to process any unsolicted frames from this remote port
2653 */
2654void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002655bfa_fcs_rport_uf_recv(struct bfa_fcs_rport_s *rport,
2656 struct fchs_s *fchs, u16 len)
2657{
2658 struct bfa_fcs_lport_s *port = rport->port;
2659 struct fc_els_cmd_s *els_cmd;
2660
2661 bfa_trc(rport->fcs, fchs->s_id);
2662 bfa_trc(rport->fcs, fchs->d_id);
2663 bfa_trc(rport->fcs, fchs->type);
2664
2665 if (fchs->type != FC_TYPE_ELS)
2666 return;
2667
2668 els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
2669
2670 bfa_trc(rport->fcs, els_cmd->els_code);
2671
2672 switch (els_cmd->els_code) {
2673 case FC_ELS_LOGO:
2674 bfa_stats(port, plogi_rcvd);
2675 bfa_fcs_rport_process_logo(rport, fchs);
2676 break;
2677
2678 case FC_ELS_ADISC:
2679 bfa_stats(port, adisc_rcvd);
2680 bfa_fcs_rport_process_adisc(rport, fchs, len);
2681 break;
2682
2683 case FC_ELS_PRLO:
2684 bfa_stats(port, prlo_rcvd);
2685 if (bfa_fcs_lport_is_initiator(port))
2686 bfa_fcs_fcpim_uf_recv(rport->itnim, fchs, len);
2687 break;
2688
2689 case FC_ELS_PRLI:
2690 bfa_stats(port, prli_rcvd);
2691 bfa_fcs_rport_process_prli(rport, fchs, len);
2692 break;
2693
2694 case FC_ELS_RPSC:
2695 bfa_stats(port, rpsc_rcvd);
2696 bfa_fcs_rport_process_rpsc(rport, fchs, len);
2697 break;
2698
2699 default:
2700 bfa_stats(port, un_handled_els_rcvd);
2701 bfa_fcs_rport_send_ls_rjt(rport, fchs,
2702 FC_LS_RJT_RSN_CMD_NOT_SUPP,
2703 FC_LS_RJT_EXP_NO_ADDL_INFO);
2704 break;
2705 }
2706}
2707
2708/* send best case acc to prlo */
2709static void
2710bfa_fcs_rport_send_prlo_acc(struct bfa_fcs_rport_s *rport)
2711{
2712 struct bfa_fcs_lport_s *port = rport->port;
2713 struct fchs_s fchs;
2714 struct bfa_fcxp_s *fcxp;
2715 int len;
2716
2717 bfa_trc(rport->fcs, rport->pid);
2718
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07002719 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002720 if (!fcxp)
2721 return;
2722 len = fc_prlo_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
2723 rport->pid, bfa_fcs_lport_get_fcid(port),
2724 rport->reply_oxid, 0);
2725
2726 bfa_fcxp_send(fcxp, rport->bfa_rport, port->fabric->vf_id,
2727 port->lp_tag, BFA_FALSE, FC_CLASS_3, len, &fchs,
2728 NULL, NULL, FC_MAX_PDUSZ, 0);
2729}
2730
2731/*
2732 * Send a LS reject
2733 */
2734static void
2735bfa_fcs_rport_send_ls_rjt(struct bfa_fcs_rport_s *rport, struct fchs_s *rx_fchs,
2736 u8 reason_code, u8 reason_code_expl)
2737{
2738 struct bfa_fcs_lport_s *port = rport->port;
2739 struct fchs_s fchs;
2740 struct bfa_fcxp_s *fcxp;
2741 int len;
2742
2743 bfa_trc(rport->fcs, rx_fchs->s_id);
2744
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07002745 fcxp = bfa_fcs_fcxp_alloc(rport->fcs, BFA_FALSE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002746 if (!fcxp)
2747 return;
2748
2749 len = fc_ls_rjt_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
2750 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
2751 rx_fchs->ox_id, reason_code, reason_code_expl);
2752
2753 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag,
2754 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
2755 FC_MAX_PDUSZ, 0);
2756}
2757
Jing Huang5fbe25c2010-10-18 17:17:23 -07002758/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002759 * Return state of rport.
2760 */
2761int
2762bfa_fcs_rport_get_state(struct bfa_fcs_rport_s *rport)
2763{
2764 return bfa_sm_to_state(rport_sm_table, rport->sm);
2765}
2766
Maggie Zhangf7f738122010-12-09 19:08:43 -08002767
Jing Huang5fbe25c2010-10-18 17:17:23 -07002768/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002769 * brief
2770 * Called by the Driver to set rport delete/ageout timeout
2771 *
2772 * param[in] rport timeout value in seconds.
2773 *
2774 * return None
2775 */
2776void
2777bfa_fcs_rport_set_del_timeout(u8 rport_tmo)
2778{
2779 /* convert to Millisecs */
2780 if (rport_tmo > 0)
2781 bfa_fcs_rport_del_timeout = rport_tmo * 1000;
2782}
2783void
Maggie50444a32010-11-29 18:26:32 -08002784bfa_fcs_rport_prlo(struct bfa_fcs_rport_s *rport, __be16 ox_id)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002785{
2786 bfa_trc(rport->fcs, rport->pid);
2787
2788 rport->prlo = BFA_TRUE;
2789 rport->reply_oxid = ox_id;
2790 bfa_sm_send_event(rport, RPSM_EVENT_PRLO_RCVD);
2791}
2792
Krishna Gudipati61ba4392012-08-22 19:52:58 -07002793/*
2794 * Called by BFAD to set the max limit on number of bfa_fcs_rport allocation
2795 * which limits number of concurrent logins to remote ports
2796 */
2797void
2798bfa_fcs_rport_set_max_logins(u32 max_logins)
2799{
2800 if (max_logins > 0)
2801 bfa_fcs_rport_max_logins = max_logins;
2802}
2803
Krishna Gudipati60138062011-06-24 20:25:15 -07002804void
2805bfa_fcs_rport_get_attr(struct bfa_fcs_rport_s *rport,
2806 struct bfa_rport_attr_s *rport_attr)
2807{
2808 struct bfa_rport_qos_attr_s qos_attr;
2809 struct bfa_fcs_lport_s *port = rport->port;
2810 bfa_port_speed_t rport_speed = rport->rpf.rpsc_speed;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002811
Krishna Gudipati60138062011-06-24 20:25:15 -07002812 memset(rport_attr, 0, sizeof(struct bfa_rport_attr_s));
2813 memset(&qos_attr, 0, sizeof(struct bfa_rport_qos_attr_s));
2814
2815 rport_attr->pid = rport->pid;
2816 rport_attr->pwwn = rport->pwwn;
2817 rport_attr->nwwn = rport->nwwn;
2818 rport_attr->cos_supported = rport->fc_cos;
2819 rport_attr->df_sz = rport->maxfrsize;
2820 rport_attr->state = bfa_fcs_rport_get_state(rport);
2821 rport_attr->fc_cos = rport->fc_cos;
2822 rport_attr->cisc = rport->cisc;
2823 rport_attr->scsi_function = rport->scsi_function;
2824 rport_attr->curr_speed = rport->rpf.rpsc_speed;
2825 rport_attr->assigned_speed = rport->rpf.assigned_speed;
2826
Krishna Gudipati61ba4392012-08-22 19:52:58 -07002827 if (rport->bfa_rport) {
2828 qos_attr.qos_priority = rport->bfa_rport->qos_attr.qos_priority;
2829 qos_attr.qos_flow_id =
2830 cpu_to_be32(rport->bfa_rport->qos_attr.qos_flow_id);
2831 }
Krishna Gudipati60138062011-06-24 20:25:15 -07002832 rport_attr->qos_attr = qos_attr;
2833
2834 rport_attr->trl_enforced = BFA_FALSE;
2835 if (bfa_fcport_is_ratelim(port->fcs->bfa) &&
2836 (rport->scsi_function == BFA_RPORT_TARGET)) {
2837 if (rport_speed == BFA_PORT_SPEED_UNKNOWN)
2838 rport_speed =
2839 bfa_fcport_get_ratelim_speed(rport->fcs->bfa);
2840
2841 if (rport_speed < bfa_fcs_lport_get_rport_max_speed(port))
2842 rport_attr->trl_enforced = BFA_TRUE;
2843 }
2844}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002845
Jing Huang5fbe25c2010-10-18 17:17:23 -07002846/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002847 * Remote port implementation.
2848 */
2849
Jing Huang5fbe25c2010-10-18 17:17:23 -07002850/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002851 * fcs_rport_api FCS rport API.
2852 */
2853
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002854struct bfa_fcs_rport_s *
2855bfa_fcs_rport_lookup(struct bfa_fcs_lport_s *port, wwn_t rpwwn)
2856{
2857 struct bfa_fcs_rport_s *rport;
2858
2859 rport = bfa_fcs_lport_get_rport_by_pwwn(port, rpwwn);
2860 if (rport == NULL) {
2861 /*
2862 * TBD Error handling
2863 */
2864 }
2865
2866 return rport;
2867}
2868
2869struct bfa_fcs_rport_s *
2870bfa_fcs_rport_lookup_by_nwwn(struct bfa_fcs_lport_s *port, wwn_t rnwwn)
2871{
2872 struct bfa_fcs_rport_s *rport;
2873
2874 rport = bfa_fcs_lport_get_rport_by_nwwn(port, rnwwn);
2875 if (rport == NULL) {
2876 /*
2877 * TBD Error handling
2878 */
2879 }
2880
2881 return rport;
2882}
2883
2884/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002885 * Remote port features (RPF) implementation.
2886 */
2887
2888#define BFA_FCS_RPF_RETRIES (3)
2889#define BFA_FCS_RPF_RETRY_TIMEOUT (1000) /* 1 sec (In millisecs) */
2890
2891static void bfa_fcs_rpf_send_rpsc2(void *rport_cbarg,
2892 struct bfa_fcxp_s *fcxp_alloced);
2893static void bfa_fcs_rpf_rpsc2_response(void *fcsarg,
2894 struct bfa_fcxp_s *fcxp,
2895 void *cbarg,
2896 bfa_status_t req_status,
2897 u32 rsp_len,
2898 u32 resid_len,
2899 struct fchs_s *rsp_fchs);
2900
2901static void bfa_fcs_rpf_timeout(void *arg);
2902
Jing Huang5fbe25c2010-10-18 17:17:23 -07002903/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002904 * fcs_rport_ftrs_sm FCS rport state machine events
2905 */
2906
2907enum rpf_event {
2908 RPFSM_EVENT_RPORT_OFFLINE = 1, /* Rport offline */
2909 RPFSM_EVENT_RPORT_ONLINE = 2, /* Rport online */
2910 RPFSM_EVENT_FCXP_SENT = 3, /* Frame from has been sent */
2911 RPFSM_EVENT_TIMEOUT = 4, /* Rport SM timeout event */
2912 RPFSM_EVENT_RPSC_COMP = 5,
2913 RPFSM_EVENT_RPSC_FAIL = 6,
2914 RPFSM_EVENT_RPSC_ERROR = 7,
2915};
2916
2917static void bfa_fcs_rpf_sm_uninit(struct bfa_fcs_rpf_s *rpf,
2918 enum rpf_event event);
2919static void bfa_fcs_rpf_sm_rpsc_sending(struct bfa_fcs_rpf_s *rpf,
2920 enum rpf_event event);
2921static void bfa_fcs_rpf_sm_rpsc(struct bfa_fcs_rpf_s *rpf,
2922 enum rpf_event event);
2923static void bfa_fcs_rpf_sm_rpsc_retry(struct bfa_fcs_rpf_s *rpf,
2924 enum rpf_event event);
2925static void bfa_fcs_rpf_sm_offline(struct bfa_fcs_rpf_s *rpf,
2926 enum rpf_event event);
2927static void bfa_fcs_rpf_sm_online(struct bfa_fcs_rpf_s *rpf,
2928 enum rpf_event event);
2929
2930static void
2931bfa_fcs_rpf_sm_uninit(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
2932{
2933 struct bfa_fcs_rport_s *rport = rpf->rport;
2934 struct bfa_fcs_fabric_s *fabric = &rport->fcs->fabric;
2935
2936 bfa_trc(rport->fcs, rport->pwwn);
2937 bfa_trc(rport->fcs, rport->pid);
2938 bfa_trc(rport->fcs, event);
2939
2940 switch (event) {
2941 case RPFSM_EVENT_RPORT_ONLINE:
2942 /* Send RPSC2 to a Brocade fabric only. */
2943 if ((!BFA_FCS_PID_IS_WKA(rport->pid)) &&
Maggie Zhangf7f738122010-12-09 19:08:43 -08002944 ((rport->port->fabric->lps->brcd_switch) ||
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002945 (bfa_fcs_fabric_get_switch_oui(fabric) ==
2946 BFA_FCS_BRCD_SWITCH_OUI))) {
2947 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
2948 rpf->rpsc_retries = 0;
2949 bfa_fcs_rpf_send_rpsc2(rpf, NULL);
2950 }
2951 break;
2952
2953 case RPFSM_EVENT_RPORT_OFFLINE:
2954 break;
2955
2956 default:
2957 bfa_sm_fault(rport->fcs, event);
2958 }
2959}
2960
2961static void
2962bfa_fcs_rpf_sm_rpsc_sending(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
2963{
2964 struct bfa_fcs_rport_s *rport = rpf->rport;
2965
2966 bfa_trc(rport->fcs, event);
2967
2968 switch (event) {
2969 case RPFSM_EVENT_FCXP_SENT:
2970 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc);
2971 break;
2972
2973 case RPFSM_EVENT_RPORT_OFFLINE:
2974 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
2975 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rpf->fcxp_wqe);
2976 rpf->rpsc_retries = 0;
2977 break;
2978
2979 default:
2980 bfa_sm_fault(rport->fcs, event);
2981 }
2982}
2983
2984static void
2985bfa_fcs_rpf_sm_rpsc(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
2986{
2987 struct bfa_fcs_rport_s *rport = rpf->rport;
2988
2989 bfa_trc(rport->fcs, rport->pid);
2990 bfa_trc(rport->fcs, event);
2991
2992 switch (event) {
2993 case RPFSM_EVENT_RPSC_COMP:
2994 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
2995 /* Update speed info in f/w via BFA */
2996 if (rpf->rpsc_speed != BFA_PORT_SPEED_UNKNOWN)
2997 bfa_rport_speed(rport->bfa_rport, rpf->rpsc_speed);
2998 else if (rpf->assigned_speed != BFA_PORT_SPEED_UNKNOWN)
2999 bfa_rport_speed(rport->bfa_rport, rpf->assigned_speed);
3000 break;
3001
3002 case RPFSM_EVENT_RPSC_FAIL:
3003 /* RPSC not supported by rport */
3004 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
3005 break;
3006
3007 case RPFSM_EVENT_RPSC_ERROR:
3008 /* need to retry...delayed a bit. */
3009 if (rpf->rpsc_retries++ < BFA_FCS_RPF_RETRIES) {
3010 bfa_timer_start(rport->fcs->bfa, &rpf->timer,
3011 bfa_fcs_rpf_timeout, rpf,
3012 BFA_FCS_RPF_RETRY_TIMEOUT);
3013 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_retry);
3014 } else {
3015 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
3016 }
3017 break;
3018
3019 case RPFSM_EVENT_RPORT_OFFLINE:
3020 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
3021 bfa_fcxp_discard(rpf->fcxp);
3022 rpf->rpsc_retries = 0;
3023 break;
3024
3025 default:
3026 bfa_sm_fault(rport->fcs, event);
3027 }
3028}
3029
3030static void
3031bfa_fcs_rpf_sm_rpsc_retry(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
3032{
3033 struct bfa_fcs_rport_s *rport = rpf->rport;
3034
3035 bfa_trc(rport->fcs, rport->pid);
3036 bfa_trc(rport->fcs, event);
3037
3038 switch (event) {
3039 case RPFSM_EVENT_TIMEOUT:
3040 /* re-send the RPSC */
3041 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
3042 bfa_fcs_rpf_send_rpsc2(rpf, NULL);
3043 break;
3044
3045 case RPFSM_EVENT_RPORT_OFFLINE:
3046 bfa_timer_stop(&rpf->timer);
3047 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
3048 rpf->rpsc_retries = 0;
3049 break;
3050
3051 default:
3052 bfa_sm_fault(rport->fcs, event);
3053 }
3054}
3055
3056static void
3057bfa_fcs_rpf_sm_online(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
3058{
3059 struct bfa_fcs_rport_s *rport = rpf->rport;
3060
3061 bfa_trc(rport->fcs, rport->pwwn);
3062 bfa_trc(rport->fcs, rport->pid);
3063 bfa_trc(rport->fcs, event);
3064
3065 switch (event) {
3066 case RPFSM_EVENT_RPORT_OFFLINE:
3067 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
3068 rpf->rpsc_retries = 0;
3069 break;
3070
3071 default:
3072 bfa_sm_fault(rport->fcs, event);
3073 }
3074}
3075
3076static void
3077bfa_fcs_rpf_sm_offline(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
3078{
3079 struct bfa_fcs_rport_s *rport = rpf->rport;
3080
3081 bfa_trc(rport->fcs, rport->pwwn);
3082 bfa_trc(rport->fcs, rport->pid);
3083 bfa_trc(rport->fcs, event);
3084
3085 switch (event) {
3086 case RPFSM_EVENT_RPORT_ONLINE:
3087 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
3088 bfa_fcs_rpf_send_rpsc2(rpf, NULL);
3089 break;
3090
3091 case RPFSM_EVENT_RPORT_OFFLINE:
3092 break;
3093
3094 default:
3095 bfa_sm_fault(rport->fcs, event);
3096 }
3097}
Jing Huang5fbe25c2010-10-18 17:17:23 -07003098/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003099 * Called when Rport is created.
3100 */
3101void
3102bfa_fcs_rpf_init(struct bfa_fcs_rport_s *rport)
3103{
3104 struct bfa_fcs_rpf_s *rpf = &rport->rpf;
3105
3106 bfa_trc(rport->fcs, rport->pid);
3107 rpf->rport = rport;
3108
3109 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_uninit);
3110}
3111
Jing Huang5fbe25c2010-10-18 17:17:23 -07003112/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003113 * Called when Rport becomes online
3114 */
3115void
3116bfa_fcs_rpf_rport_online(struct bfa_fcs_rport_s *rport)
3117{
3118 bfa_trc(rport->fcs, rport->pid);
3119
3120 if (__fcs_min_cfg(rport->port->fcs))
3121 return;
3122
3123 if (bfa_fcs_fabric_is_switched(rport->port->fabric))
3124 bfa_sm_send_event(&rport->rpf, RPFSM_EVENT_RPORT_ONLINE);
3125}
3126
Jing Huang5fbe25c2010-10-18 17:17:23 -07003127/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003128 * Called when Rport becomes offline
3129 */
3130void
3131bfa_fcs_rpf_rport_offline(struct bfa_fcs_rport_s *rport)
3132{
3133 bfa_trc(rport->fcs, rport->pid);
3134
3135 if (__fcs_min_cfg(rport->port->fcs))
3136 return;
3137
3138 rport->rpf.rpsc_speed = 0;
3139 bfa_sm_send_event(&rport->rpf, RPFSM_EVENT_RPORT_OFFLINE);
3140}
3141
3142static void
3143bfa_fcs_rpf_timeout(void *arg)
3144{
3145 struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *) arg;
3146 struct bfa_fcs_rport_s *rport = rpf->rport;
3147
3148 bfa_trc(rport->fcs, rport->pid);
3149 bfa_sm_send_event(rpf, RPFSM_EVENT_TIMEOUT);
3150}
3151
3152static void
3153bfa_fcs_rpf_send_rpsc2(void *rpf_cbarg, struct bfa_fcxp_s *fcxp_alloced)
3154{
3155 struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *)rpf_cbarg;
3156 struct bfa_fcs_rport_s *rport = rpf->rport;
3157 struct bfa_fcs_lport_s *port = rport->port;
3158 struct fchs_s fchs;
3159 int len;
3160 struct bfa_fcxp_s *fcxp;
3161
3162 bfa_trc(rport->fcs, rport->pwwn);
3163
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07003164 fcxp = fcxp_alloced ? fcxp_alloced :
3165 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003166 if (!fcxp) {
3167 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rpf->fcxp_wqe,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07003168 bfa_fcs_rpf_send_rpsc2, rpf, BFA_TRUE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003169 return;
3170 }
3171 rpf->fcxp = fcxp;
3172
3173 len = fc_rpsc2_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
3174 bfa_fcs_lport_get_fcid(port), &rport->pid, 1);
3175
3176 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
3177 FC_CLASS_3, len, &fchs, bfa_fcs_rpf_rpsc2_response,
3178 rpf, FC_MAX_PDUSZ, FC_ELS_TOV);
3179 rport->stats.rpsc_sent++;
3180 bfa_sm_send_event(rpf, RPFSM_EVENT_FCXP_SENT);
3181
3182}
3183
3184static void
3185bfa_fcs_rpf_rpsc2_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
3186 bfa_status_t req_status, u32 rsp_len,
3187 u32 resid_len, struct fchs_s *rsp_fchs)
3188{
3189 struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *) cbarg;
3190 struct bfa_fcs_rport_s *rport = rpf->rport;
3191 struct fc_ls_rjt_s *ls_rjt;
3192 struct fc_rpsc2_acc_s *rpsc2_acc;
3193 u16 num_ents;
3194
3195 bfa_trc(rport->fcs, req_status);
3196
3197 if (req_status != BFA_STATUS_OK) {
3198 bfa_trc(rport->fcs, req_status);
3199 if (req_status == BFA_STATUS_ETIMER)
3200 rport->stats.rpsc_failed++;
3201 bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);
3202 return;
3203 }
3204
3205 rpsc2_acc = (struct fc_rpsc2_acc_s *) BFA_FCXP_RSP_PLD(fcxp);
3206 if (rpsc2_acc->els_cmd == FC_ELS_ACC) {
3207 rport->stats.rpsc_accs++;
Jing Huangba816ea2010-10-18 17:10:50 -07003208 num_ents = be16_to_cpu(rpsc2_acc->num_pids);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003209 bfa_trc(rport->fcs, num_ents);
3210 if (num_ents > 0) {
Jing Huangd4b671c2010-12-26 21:46:35 -08003211 WARN_ON(rpsc2_acc->port_info[0].pid == rport->pid);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003212 bfa_trc(rport->fcs,
Jing Huangba816ea2010-10-18 17:10:50 -07003213 be16_to_cpu(rpsc2_acc->port_info[0].pid));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003214 bfa_trc(rport->fcs,
Jing Huangba816ea2010-10-18 17:10:50 -07003215 be16_to_cpu(rpsc2_acc->port_info[0].speed));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003216 bfa_trc(rport->fcs,
Jing Huangba816ea2010-10-18 17:10:50 -07003217 be16_to_cpu(rpsc2_acc->port_info[0].index));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003218 bfa_trc(rport->fcs,
3219 rpsc2_acc->port_info[0].type);
3220
3221 if (rpsc2_acc->port_info[0].speed == 0) {
3222 bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);
3223 return;
3224 }
3225
3226 rpf->rpsc_speed = fc_rpsc_operspeed_to_bfa_speed(
Jing Huangba816ea2010-10-18 17:10:50 -07003227 be16_to_cpu(rpsc2_acc->port_info[0].speed));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003228
3229 bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_COMP);
3230 }
3231 } else {
3232 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
3233 bfa_trc(rport->fcs, ls_rjt->reason_code);
3234 bfa_trc(rport->fcs, ls_rjt->reason_code_expl);
3235 rport->stats.rpsc_rejects++;
3236 if (ls_rjt->reason_code == FC_LS_RJT_RSN_CMD_NOT_SUPP)
3237 bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_FAIL);
3238 else
3239 bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);
3240 }
3241}