2 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
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
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.
19 * rport.c Remote port implementation.
24 #include "bfa_fcbuild.h"
26 BFA_TRC_FILE(FCS, RPORT);
29 bfa_fcs_rport_del_timeout = BFA_FCS_RPORT_DEF_DEL_TIMEOUT * 1000;
32 * forward declarations
34 static struct bfa_fcs_rport_s *bfa_fcs_rport_alloc(
35 struct bfa_fcs_lport_s *port, wwn_t pwwn, u32 rpid);
36 static void bfa_fcs_rport_free(struct bfa_fcs_rport_s *rport);
37 static void bfa_fcs_rport_hal_online(struct bfa_fcs_rport_s *rport);
38 static void bfa_fcs_rport_online_action(struct bfa_fcs_rport_s *rport);
39 static void bfa_fcs_rport_offline_action(struct bfa_fcs_rport_s *rport);
40 static void bfa_fcs_rport_update(struct bfa_fcs_rport_s *rport,
41 struct fc_logi_s *plogi);
42 static void bfa_fcs_rport_timeout(void *arg);
43 static void bfa_fcs_rport_send_plogi(void *rport_cbarg,
44 struct bfa_fcxp_s *fcxp_alloced);
45 static void bfa_fcs_rport_send_plogiacc(void *rport_cbarg,
46 struct bfa_fcxp_s *fcxp_alloced);
47 static void bfa_fcs_rport_plogi_response(void *fcsarg,
48 struct bfa_fcxp_s *fcxp, void *cbarg,
49 bfa_status_t req_status, u32 rsp_len,
50 u32 resid_len, struct fchs_s *rsp_fchs);
51 static void bfa_fcs_rport_send_adisc(void *rport_cbarg,
52 struct bfa_fcxp_s *fcxp_alloced);
53 static void bfa_fcs_rport_adisc_response(void *fcsarg,
54 struct bfa_fcxp_s *fcxp, void *cbarg,
55 bfa_status_t req_status, u32 rsp_len,
56 u32 resid_len, struct fchs_s *rsp_fchs);
57 static void bfa_fcs_rport_send_nsdisc(void *rport_cbarg,
58 struct bfa_fcxp_s *fcxp_alloced);
59 static void bfa_fcs_rport_gidpn_response(void *fcsarg,
60 struct bfa_fcxp_s *fcxp, void *cbarg,
61 bfa_status_t req_status, u32 rsp_len,
62 u32 resid_len, struct fchs_s *rsp_fchs);
63 static void bfa_fcs_rport_gpnid_response(void *fcsarg,
64 struct bfa_fcxp_s *fcxp, void *cbarg,
65 bfa_status_t req_status, u32 rsp_len,
66 u32 resid_len, struct fchs_s *rsp_fchs);
67 static void bfa_fcs_rport_send_logo(void *rport_cbarg,
68 struct bfa_fcxp_s *fcxp_alloced);
69 static void bfa_fcs_rport_send_logo_acc(void *rport_cbarg);
70 static void bfa_fcs_rport_process_prli(struct bfa_fcs_rport_s *rport,
71 struct fchs_s *rx_fchs, u16 len);
72 static void bfa_fcs_rport_send_ls_rjt(struct bfa_fcs_rport_s *rport,
73 struct fchs_s *rx_fchs, u8 reason_code,
75 static void bfa_fcs_rport_process_adisc(struct bfa_fcs_rport_s *rport,
76 struct fchs_s *rx_fchs, u16 len);
77 static void bfa_fcs_rport_send_prlo_acc(struct bfa_fcs_rport_s *rport);
79 static void bfa_fcs_rport_sm_uninit(struct bfa_fcs_rport_s *rport,
80 enum rport_event event);
81 static void bfa_fcs_rport_sm_plogi_sending(struct bfa_fcs_rport_s *rport,
82 enum rport_event event);
83 static void bfa_fcs_rport_sm_plogiacc_sending(struct bfa_fcs_rport_s *rport,
84 enum rport_event event);
85 static void bfa_fcs_rport_sm_plogi_retry(struct bfa_fcs_rport_s *rport,
86 enum rport_event event);
87 static void bfa_fcs_rport_sm_plogi(struct bfa_fcs_rport_s *rport,
88 enum rport_event event);
89 static void bfa_fcs_rport_sm_hal_online(struct bfa_fcs_rport_s *rport,
90 enum rport_event event);
91 static void bfa_fcs_rport_sm_online(struct bfa_fcs_rport_s *rport,
92 enum rport_event event);
93 static void bfa_fcs_rport_sm_nsquery_sending(struct bfa_fcs_rport_s *rport,
94 enum rport_event event);
95 static void bfa_fcs_rport_sm_nsquery(struct bfa_fcs_rport_s *rport,
96 enum rport_event event);
97 static void bfa_fcs_rport_sm_adisc_sending(struct bfa_fcs_rport_s *rport,
98 enum rport_event event);
99 static void bfa_fcs_rport_sm_adisc(struct bfa_fcs_rport_s *rport,
100 enum rport_event event);
101 static void bfa_fcs_rport_sm_fc4_logorcv(struct bfa_fcs_rport_s *rport,
102 enum rport_event event);
103 static void bfa_fcs_rport_sm_fc4_logosend(struct bfa_fcs_rport_s *rport,
104 enum rport_event event);
105 static void bfa_fcs_rport_sm_fc4_offline(struct bfa_fcs_rport_s *rport,
106 enum rport_event event);
107 static void bfa_fcs_rport_sm_hcb_offline(struct bfa_fcs_rport_s *rport,
108 enum rport_event event);
109 static void bfa_fcs_rport_sm_hcb_logorcv(struct bfa_fcs_rport_s *rport,
110 enum rport_event event);
111 static void bfa_fcs_rport_sm_hcb_logosend(struct bfa_fcs_rport_s *rport,
112 enum rport_event event);
113 static void bfa_fcs_rport_sm_logo_sending(struct bfa_fcs_rport_s *rport,
114 enum rport_event event);
115 static void bfa_fcs_rport_sm_offline(struct bfa_fcs_rport_s *rport,
116 enum rport_event event);
117 static void bfa_fcs_rport_sm_nsdisc_sending(struct bfa_fcs_rport_s *rport,
118 enum rport_event event);
119 static void bfa_fcs_rport_sm_nsdisc_retry(struct bfa_fcs_rport_s *rport,
120 enum rport_event event);
121 static void bfa_fcs_rport_sm_nsdisc_sent(struct bfa_fcs_rport_s *rport,
122 enum rport_event event);
123 static void bfa_fcs_rport_sm_nsdisc_sent(struct bfa_fcs_rport_s *rport,
124 enum rport_event event);
126 static struct bfa_sm_table_s rport_sm_table[] = {
127 {BFA_SM(bfa_fcs_rport_sm_uninit), BFA_RPORT_UNINIT},
128 {BFA_SM(bfa_fcs_rport_sm_plogi_sending), BFA_RPORT_PLOGI},
129 {BFA_SM(bfa_fcs_rport_sm_plogiacc_sending), BFA_RPORT_ONLINE},
130 {BFA_SM(bfa_fcs_rport_sm_plogi_retry), BFA_RPORT_PLOGI_RETRY},
131 {BFA_SM(bfa_fcs_rport_sm_plogi), BFA_RPORT_PLOGI},
132 {BFA_SM(bfa_fcs_rport_sm_hal_online), BFA_RPORT_ONLINE},
133 {BFA_SM(bfa_fcs_rport_sm_online), BFA_RPORT_ONLINE},
134 {BFA_SM(bfa_fcs_rport_sm_nsquery_sending), BFA_RPORT_NSQUERY},
135 {BFA_SM(bfa_fcs_rport_sm_nsquery), BFA_RPORT_NSQUERY},
136 {BFA_SM(bfa_fcs_rport_sm_adisc_sending), BFA_RPORT_ADISC},
137 {BFA_SM(bfa_fcs_rport_sm_adisc), BFA_RPORT_ADISC},
138 {BFA_SM(bfa_fcs_rport_sm_fc4_logorcv), BFA_RPORT_LOGORCV},
139 {BFA_SM(bfa_fcs_rport_sm_fc4_logosend), BFA_RPORT_LOGO},
140 {BFA_SM(bfa_fcs_rport_sm_fc4_offline), BFA_RPORT_OFFLINE},
141 {BFA_SM(bfa_fcs_rport_sm_hcb_offline), BFA_RPORT_OFFLINE},
142 {BFA_SM(bfa_fcs_rport_sm_hcb_logorcv), BFA_RPORT_LOGORCV},
143 {BFA_SM(bfa_fcs_rport_sm_hcb_logosend), BFA_RPORT_LOGO},
144 {BFA_SM(bfa_fcs_rport_sm_logo_sending), BFA_RPORT_LOGO},
145 {BFA_SM(bfa_fcs_rport_sm_offline), BFA_RPORT_OFFLINE},
146 {BFA_SM(bfa_fcs_rport_sm_nsdisc_sending), BFA_RPORT_NSDISC},
147 {BFA_SM(bfa_fcs_rport_sm_nsdisc_retry), BFA_RPORT_NSDISC},
148 {BFA_SM(bfa_fcs_rport_sm_nsdisc_sent), BFA_RPORT_NSDISC},
155 bfa_fcs_rport_sm_uninit(struct bfa_fcs_rport_s *rport, enum rport_event event)
157 bfa_trc(rport->fcs, rport->pwwn);
158 bfa_trc(rport->fcs, rport->pid);
159 bfa_trc(rport->fcs, event);
162 case RPSM_EVENT_PLOGI_SEND:
163 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
164 rport->plogi_retries = 0;
165 bfa_fcs_rport_send_plogi(rport, NULL);
168 case RPSM_EVENT_PLOGI_RCVD:
169 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
170 bfa_fcs_rport_send_plogiacc(rport, NULL);
173 case RPSM_EVENT_PLOGI_COMP:
174 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
175 bfa_fcs_rport_hal_online(rport);
178 case RPSM_EVENT_ADDRESS_CHANGE:
179 case RPSM_EVENT_ADDRESS_DISC:
180 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
181 rport->ns_retries = 0;
182 bfa_fcs_rport_send_nsdisc(rport, NULL);
185 bfa_sm_fault(rport->fcs, event);
190 * PLOGI is being sent.
193 bfa_fcs_rport_sm_plogi_sending(struct bfa_fcs_rport_s *rport,
194 enum rport_event event)
196 bfa_trc(rport->fcs, rport->pwwn);
197 bfa_trc(rport->fcs, rport->pid);
198 bfa_trc(rport->fcs, event);
201 case RPSM_EVENT_FCXP_SENT:
202 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi);
205 case RPSM_EVENT_DELETE:
206 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
207 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
208 bfa_fcs_rport_free(rport);
211 case RPSM_EVENT_PLOGI_RCVD:
212 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
213 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
214 bfa_fcs_rport_send_plogiacc(rport, NULL);
217 case RPSM_EVENT_ADDRESS_CHANGE:
220 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
221 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
222 rport->ns_retries = 0;
223 bfa_fcs_rport_send_nsdisc(rport, NULL);
226 case RPSM_EVENT_LOGO_IMP:
228 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
229 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
230 bfa_timer_start(rport->fcs->bfa, &rport->timer,
231 bfa_fcs_rport_timeout, rport,
232 bfa_fcs_rport_del_timeout);
237 bfa_sm_fault(rport->fcs, event);
242 * PLOGI is being sent.
245 bfa_fcs_rport_sm_plogiacc_sending(struct bfa_fcs_rport_s *rport,
246 enum rport_event event)
248 bfa_trc(rport->fcs, rport->pwwn);
249 bfa_trc(rport->fcs, rport->pid);
250 bfa_trc(rport->fcs, event);
253 case RPSM_EVENT_FCXP_SENT:
254 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
255 bfa_fcs_rport_hal_online(rport);
258 case RPSM_EVENT_DELETE:
259 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
260 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
261 bfa_fcs_rport_free(rport);
264 case RPSM_EVENT_PLOGI_RCVD:
265 case RPSM_EVENT_PLOGI_COMP:
268 * Ignore, SCN is possibly online notification.
272 case RPSM_EVENT_ADDRESS_CHANGE:
273 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
274 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
275 rport->ns_retries = 0;
276 bfa_fcs_rport_send_nsdisc(rport, NULL);
279 case RPSM_EVENT_LOGO_IMP:
281 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
282 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
283 bfa_timer_start(rport->fcs->bfa, &rport->timer,
284 bfa_fcs_rport_timeout, rport,
285 bfa_fcs_rport_del_timeout);
288 case RPSM_EVENT_HCB_OFFLINE:
290 * Ignore BFA callback, on a PLOGI receive we call bfa offline.
295 bfa_sm_fault(rport->fcs, event);
303 bfa_fcs_rport_sm_plogi_retry(struct bfa_fcs_rport_s *rport,
304 enum rport_event event)
306 bfa_trc(rport->fcs, rport->pwwn);
307 bfa_trc(rport->fcs, rport->pid);
308 bfa_trc(rport->fcs, event);
311 case RPSM_EVENT_TIMEOUT:
312 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
313 bfa_fcs_rport_send_plogi(rport, NULL);
316 case RPSM_EVENT_DELETE:
317 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
318 bfa_timer_stop(&rport->timer);
319 bfa_fcs_rport_free(rport);
322 case RPSM_EVENT_PRLO_RCVD:
323 case RPSM_EVENT_LOGO_RCVD:
326 case RPSM_EVENT_PLOGI_RCVD:
327 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
328 bfa_timer_stop(&rport->timer);
329 bfa_fcs_rport_send_plogiacc(rport, NULL);
332 case RPSM_EVENT_ADDRESS_CHANGE:
334 bfa_timer_stop(&rport->timer);
335 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
336 rport->ns_retries = 0;
337 bfa_fcs_rport_send_nsdisc(rport, NULL);
340 case RPSM_EVENT_LOGO_IMP:
342 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
343 bfa_timer_stop(&rport->timer);
344 bfa_timer_start(rport->fcs->bfa, &rport->timer,
345 bfa_fcs_rport_timeout, rport,
346 bfa_fcs_rport_del_timeout);
349 case RPSM_EVENT_PLOGI_COMP:
350 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
351 bfa_timer_stop(&rport->timer);
352 bfa_fcs_rport_hal_online(rport);
356 bfa_sm_fault(rport->fcs, event);
364 bfa_fcs_rport_sm_plogi(struct bfa_fcs_rport_s *rport, enum rport_event event)
366 bfa_trc(rport->fcs, rport->pwwn);
367 bfa_trc(rport->fcs, rport->pid);
368 bfa_trc(rport->fcs, event);
371 case RPSM_EVENT_ACCEPTED:
372 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
373 rport->plogi_retries = 0;
374 bfa_fcs_rport_hal_online(rport);
377 case RPSM_EVENT_LOGO_RCVD:
378 bfa_fcs_rport_send_logo_acc(rport);
382 case RPSM_EVENT_PRLO_RCVD:
383 if (rport->prlo == BFA_TRUE)
384 bfa_fcs_rport_send_prlo_acc(rport);
386 bfa_fcxp_discard(rport->fcxp);
390 case RPSM_EVENT_FAILED:
391 if (rport->plogi_retries < BFA_FCS_RPORT_MAX_RETRIES) {
392 rport->plogi_retries++;
393 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_retry);
394 bfa_timer_start(rport->fcs->bfa, &rport->timer,
395 bfa_fcs_rport_timeout, rport,
396 BFA_FCS_RETRY_TIMEOUT);
398 bfa_stats(rport->port, rport_del_max_plogi_retry);
400 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
401 bfa_timer_start(rport->fcs->bfa, &rport->timer,
402 bfa_fcs_rport_timeout, rport,
403 bfa_fcs_rport_del_timeout);
407 case RPSM_EVENT_PLOGI_RETRY:
408 rport->plogi_retries = 0;
409 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_retry);
410 bfa_timer_start(rport->fcs->bfa, &rport->timer,
411 bfa_fcs_rport_timeout, rport,
415 case RPSM_EVENT_LOGO_IMP:
417 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
418 bfa_fcxp_discard(rport->fcxp);
419 bfa_timer_start(rport->fcs->bfa, &rport->timer,
420 bfa_fcs_rport_timeout, rport,
421 bfa_fcs_rport_del_timeout);
424 case RPSM_EVENT_ADDRESS_CHANGE:
426 bfa_fcxp_discard(rport->fcxp);
427 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
428 rport->ns_retries = 0;
429 bfa_fcs_rport_send_nsdisc(rport, NULL);
432 case RPSM_EVENT_PLOGI_RCVD:
433 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
434 bfa_fcxp_discard(rport->fcxp);
435 bfa_fcs_rport_send_plogiacc(rport, NULL);
438 case RPSM_EVENT_DELETE:
439 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
440 bfa_fcxp_discard(rport->fcxp);
441 bfa_fcs_rport_free(rport);
444 case RPSM_EVENT_PLOGI_COMP:
445 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
446 bfa_fcxp_discard(rport->fcxp);
447 bfa_fcs_rport_hal_online(rport);
451 bfa_sm_fault(rport->fcs, event);
456 * PLOGI is complete. Awaiting BFA rport online callback. FC-4s
460 bfa_fcs_rport_sm_hal_online(struct bfa_fcs_rport_s *rport,
461 enum rport_event event)
463 bfa_trc(rport->fcs, rport->pwwn);
464 bfa_trc(rport->fcs, rport->pid);
465 bfa_trc(rport->fcs, event);
468 case RPSM_EVENT_HCB_ONLINE:
469 bfa_sm_set_state(rport, bfa_fcs_rport_sm_online);
470 bfa_fcs_rport_online_action(rport);
473 case RPSM_EVENT_PRLO_RCVD:
474 case RPSM_EVENT_PLOGI_COMP:
477 case RPSM_EVENT_LOGO_RCVD:
478 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logorcv);
479 bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE);
482 case RPSM_EVENT_LOGO_IMP:
483 case RPSM_EVENT_ADDRESS_CHANGE:
484 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_offline);
485 bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE);
488 case RPSM_EVENT_PLOGI_RCVD:
489 rport->plogi_pending = BFA_TRUE;
490 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_offline);
491 bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE);
494 case RPSM_EVENT_DELETE:
495 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logosend);
496 bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE);
502 * Ignore SCN - PLOGI just completed, FC-4 login should detect
508 bfa_sm_fault(rport->fcs, event);
513 * Rport is ONLINE. FC-4s active.
516 bfa_fcs_rport_sm_online(struct bfa_fcs_rport_s *rport, enum rport_event event)
518 bfa_trc(rport->fcs, rport->pwwn);
519 bfa_trc(rport->fcs, rport->pid);
520 bfa_trc(rport->fcs, event);
524 if (bfa_fcs_fabric_is_switched(rport->port->fabric)) {
525 bfa_sm_set_state(rport,
526 bfa_fcs_rport_sm_nsquery_sending);
527 rport->ns_retries = 0;
528 bfa_fcs_rport_send_nsdisc(rport, NULL);
530 bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc_sending);
531 bfa_fcs_rport_send_adisc(rport, NULL);
535 case RPSM_EVENT_PLOGI_RCVD:
536 case RPSM_EVENT_LOGO_IMP:
537 case RPSM_EVENT_ADDRESS_CHANGE:
538 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
539 bfa_fcs_rport_offline_action(rport);
542 case RPSM_EVENT_DELETE:
543 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
544 bfa_fcs_rport_offline_action(rport);
547 case RPSM_EVENT_LOGO_RCVD:
548 case RPSM_EVENT_PRLO_RCVD:
549 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
550 bfa_fcs_rport_offline_action(rport);
553 case RPSM_EVENT_PLOGI_COMP:
557 bfa_sm_fault(rport->fcs, event);
562 * An SCN event is received in ONLINE state. NS query is being sent
563 * prior to ADISC authentication with rport. FC-4s are paused.
566 bfa_fcs_rport_sm_nsquery_sending(struct bfa_fcs_rport_s *rport,
567 enum rport_event event)
569 bfa_trc(rport->fcs, rport->pwwn);
570 bfa_trc(rport->fcs, rport->pid);
571 bfa_trc(rport->fcs, event);
574 case RPSM_EVENT_FCXP_SENT:
575 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsquery);
578 case RPSM_EVENT_DELETE:
579 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
580 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
581 bfa_fcs_rport_offline_action(rport);
586 * ignore SCN, wait for response to query itself
590 case RPSM_EVENT_LOGO_RCVD:
591 case RPSM_EVENT_PRLO_RCVD:
592 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
593 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
594 bfa_fcs_rport_offline_action(rport);
597 case RPSM_EVENT_LOGO_IMP:
599 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
600 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
601 bfa_timer_start(rport->fcs->bfa, &rport->timer,
602 bfa_fcs_rport_timeout, rport,
603 bfa_fcs_rport_del_timeout);
606 case RPSM_EVENT_PLOGI_RCVD:
607 case RPSM_EVENT_ADDRESS_CHANGE:
608 case RPSM_EVENT_PLOGI_COMP:
609 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
610 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
611 bfa_fcs_rport_offline_action(rport);
615 bfa_sm_fault(rport->fcs, event);
620 * An SCN event is received in ONLINE state. NS query is sent to rport.
624 bfa_fcs_rport_sm_nsquery(struct bfa_fcs_rport_s *rport, enum rport_event event)
626 bfa_trc(rport->fcs, rport->pwwn);
627 bfa_trc(rport->fcs, rport->pid);
628 bfa_trc(rport->fcs, event);
631 case RPSM_EVENT_ACCEPTED:
632 bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc_sending);
633 bfa_fcs_rport_send_adisc(rport, NULL);
636 case RPSM_EVENT_FAILED:
638 if (rport->ns_retries < BFA_FCS_RPORT_MAX_RETRIES) {
639 bfa_sm_set_state(rport,
640 bfa_fcs_rport_sm_nsquery_sending);
641 bfa_fcs_rport_send_nsdisc(rport, NULL);
643 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
644 bfa_fcs_rport_offline_action(rport);
648 case RPSM_EVENT_DELETE:
649 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
650 bfa_fcxp_discard(rport->fcxp);
651 bfa_fcs_rport_offline_action(rport);
657 case RPSM_EVENT_LOGO_RCVD:
658 case RPSM_EVENT_PRLO_RCVD:
659 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
660 bfa_fcxp_discard(rport->fcxp);
661 bfa_fcs_rport_offline_action(rport);
664 case RPSM_EVENT_PLOGI_COMP:
665 case RPSM_EVENT_ADDRESS_CHANGE:
666 case RPSM_EVENT_PLOGI_RCVD:
667 case RPSM_EVENT_LOGO_IMP:
668 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
669 bfa_fcxp_discard(rport->fcxp);
670 bfa_fcs_rport_offline_action(rport);
674 bfa_sm_fault(rport->fcs, event);
679 * An SCN event is received in ONLINE state. ADISC is being sent for
680 * authenticating with rport. FC-4s are paused.
683 bfa_fcs_rport_sm_adisc_sending(struct bfa_fcs_rport_s *rport,
684 enum rport_event event)
686 bfa_trc(rport->fcs, rport->pwwn);
687 bfa_trc(rport->fcs, rport->pid);
688 bfa_trc(rport->fcs, event);
691 case RPSM_EVENT_FCXP_SENT:
692 bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc);
695 case RPSM_EVENT_DELETE:
696 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
697 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
698 bfa_fcs_rport_offline_action(rport);
701 case RPSM_EVENT_LOGO_IMP:
702 case RPSM_EVENT_ADDRESS_CHANGE:
703 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
704 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
705 bfa_fcs_rport_offline_action(rport);
708 case RPSM_EVENT_LOGO_RCVD:
709 case RPSM_EVENT_PRLO_RCVD:
710 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
711 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
712 bfa_fcs_rport_offline_action(rport);
718 case RPSM_EVENT_PLOGI_RCVD:
719 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
720 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
721 bfa_fcs_rport_offline_action(rport);
725 bfa_sm_fault(rport->fcs, event);
730 * An SCN event is received in ONLINE state. ADISC is to rport.
734 bfa_fcs_rport_sm_adisc(struct bfa_fcs_rport_s *rport, enum rport_event event)
736 bfa_trc(rport->fcs, rport->pwwn);
737 bfa_trc(rport->fcs, rport->pid);
738 bfa_trc(rport->fcs, event);
741 case RPSM_EVENT_ACCEPTED:
742 bfa_sm_set_state(rport, bfa_fcs_rport_sm_online);
745 case RPSM_EVENT_PLOGI_RCVD:
747 * Too complex to cleanup FC-4 & rport and then acc to PLOGI.
748 * At least go offline when a PLOGI is received.
750 bfa_fcxp_discard(rport->fcxp);
752 * !!! fall through !!!
755 case RPSM_EVENT_FAILED:
756 case RPSM_EVENT_ADDRESS_CHANGE:
757 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
758 bfa_fcs_rport_offline_action(rport);
761 case RPSM_EVENT_DELETE:
762 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
763 bfa_fcxp_discard(rport->fcxp);
764 bfa_fcs_rport_offline_action(rport);
769 * already processing RSCN
773 case RPSM_EVENT_LOGO_IMP:
774 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
775 bfa_fcxp_discard(rport->fcxp);
776 bfa_fcs_rport_offline_action(rport);
779 case RPSM_EVENT_LOGO_RCVD:
780 case RPSM_EVENT_PRLO_RCVD:
781 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
782 bfa_fcxp_discard(rport->fcxp);
783 bfa_fcs_rport_offline_action(rport);
787 bfa_sm_fault(rport->fcs, event);
792 * Rport has sent LOGO. Awaiting FC-4 offline completion callback.
795 bfa_fcs_rport_sm_fc4_logorcv(struct bfa_fcs_rport_s *rport,
796 enum rport_event event)
798 bfa_trc(rport->fcs, rport->pwwn);
799 bfa_trc(rport->fcs, rport->pid);
800 bfa_trc(rport->fcs, event);
803 case RPSM_EVENT_FC4_OFFLINE:
804 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logorcv);
805 bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE);
808 case RPSM_EVENT_DELETE:
809 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
812 case RPSM_EVENT_LOGO_RCVD:
813 case RPSM_EVENT_PRLO_RCVD:
814 case RPSM_EVENT_ADDRESS_CHANGE:
818 bfa_sm_fault(rport->fcs, event);
823 * LOGO needs to be sent to rport. Awaiting FC-4 offline completion
827 bfa_fcs_rport_sm_fc4_logosend(struct bfa_fcs_rport_s *rport,
828 enum rport_event event)
830 bfa_trc(rport->fcs, rport->pwwn);
831 bfa_trc(rport->fcs, rport->pid);
832 bfa_trc(rport->fcs, event);
835 case RPSM_EVENT_FC4_OFFLINE:
836 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logosend);
837 bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE);
841 bfa_sm_fault(rport->fcs, event);
846 * Rport is going offline. Awaiting FC-4 offline completion callback.
849 bfa_fcs_rport_sm_fc4_offline(struct bfa_fcs_rport_s *rport,
850 enum rport_event event)
852 bfa_trc(rport->fcs, rport->pwwn);
853 bfa_trc(rport->fcs, rport->pid);
854 bfa_trc(rport->fcs, event);
857 case RPSM_EVENT_FC4_OFFLINE:
858 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_offline);
859 bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE);
863 case RPSM_EVENT_LOGO_IMP:
864 case RPSM_EVENT_LOGO_RCVD:
865 case RPSM_EVENT_PRLO_RCVD:
866 case RPSM_EVENT_ADDRESS_CHANGE:
868 * rport is already going offline.
869 * SCN - ignore and wait till transitioning to offline state
873 case RPSM_EVENT_DELETE:
874 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
878 bfa_sm_fault(rport->fcs, event);
883 * Rport is offline. FC-4s are offline. Awaiting BFA rport offline
887 bfa_fcs_rport_sm_hcb_offline(struct bfa_fcs_rport_s *rport,
888 enum rport_event event)
890 bfa_trc(rport->fcs, rport->pwwn);
891 bfa_trc(rport->fcs, rport->pid);
892 bfa_trc(rport->fcs, event);
895 case RPSM_EVENT_HCB_OFFLINE:
896 if (bfa_fcs_lport_is_online(rport->port) &&
897 (rport->plogi_pending)) {
898 rport->plogi_pending = BFA_FALSE;
899 bfa_sm_set_state(rport,
900 bfa_fcs_rport_sm_plogiacc_sending);
901 bfa_fcs_rport_send_plogiacc(rport, NULL);
908 case RPSM_EVENT_ADDRESS_CHANGE:
909 if (bfa_fcs_lport_is_online(rport->port)) {
910 if (bfa_fcs_fabric_is_switched(rport->port->fabric)) {
911 bfa_sm_set_state(rport,
912 bfa_fcs_rport_sm_nsdisc_sending);
913 rport->ns_retries = 0;
914 bfa_fcs_rport_send_nsdisc(rport, NULL);
916 bfa_sm_set_state(rport,
917 bfa_fcs_rport_sm_plogi_sending);
918 rport->plogi_retries = 0;
919 bfa_fcs_rport_send_plogi(rport, NULL);
923 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
924 bfa_timer_start(rport->fcs->bfa, &rport->timer,
925 bfa_fcs_rport_timeout, rport,
926 bfa_fcs_rport_del_timeout);
930 case RPSM_EVENT_DELETE:
931 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
932 bfa_fcs_rport_free(rport);
936 case RPSM_EVENT_LOGO_RCVD:
937 case RPSM_EVENT_PRLO_RCVD:
938 case RPSM_EVENT_PLOGI_RCVD:
939 case RPSM_EVENT_LOGO_IMP:
941 * Ignore, already offline.
946 bfa_sm_fault(rport->fcs, event);
951 * Rport is offline. FC-4s are offline. Awaiting BFA rport offline
952 * callback to send LOGO accept.
955 bfa_fcs_rport_sm_hcb_logorcv(struct bfa_fcs_rport_s *rport,
956 enum rport_event event)
958 bfa_trc(rport->fcs, rport->pwwn);
959 bfa_trc(rport->fcs, rport->pid);
960 bfa_trc(rport->fcs, event);
963 case RPSM_EVENT_HCB_OFFLINE:
964 case RPSM_EVENT_ADDRESS_CHANGE:
965 if (rport->pid && (rport->prlo == BFA_TRUE))
966 bfa_fcs_rport_send_prlo_acc(rport);
967 if (rport->pid && (rport->prlo == BFA_FALSE))
968 bfa_fcs_rport_send_logo_acc(rport);
970 * If the lport is online and if the rport is not a well
971 * known address port,
972 * we try to re-discover the r-port.
974 if (bfa_fcs_lport_is_online(rport->port) &&
975 (!BFA_FCS_PID_IS_WKA(rport->pid))) {
976 if (bfa_fcs_fabric_is_switched(rport->port->fabric)) {
977 bfa_sm_set_state(rport,
978 bfa_fcs_rport_sm_nsdisc_sending);
979 rport->ns_retries = 0;
980 bfa_fcs_rport_send_nsdisc(rport, NULL);
982 /* For N2N Direct Attach, try to re-login */
983 bfa_sm_set_state(rport,
984 bfa_fcs_rport_sm_plogi_sending);
985 rport->plogi_retries = 0;
986 bfa_fcs_rport_send_plogi(rport, NULL);
990 * if it is not a well known address, reset the
993 if (!BFA_FCS_PID_IS_WKA(rport->pid))
995 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
996 bfa_timer_start(rport->fcs->bfa, &rport->timer,
997 bfa_fcs_rport_timeout, rport,
998 bfa_fcs_rport_del_timeout);
1002 case RPSM_EVENT_DELETE:
1003 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logosend);
1006 case RPSM_EVENT_LOGO_IMP:
1007 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_offline);
1010 case RPSM_EVENT_LOGO_RCVD:
1011 case RPSM_EVENT_PRLO_RCVD:
1013 * Ignore - already processing a LOGO.
1018 bfa_sm_fault(rport->fcs, event);
1023 * Rport is being deleted. FC-4s are offline.
1024 * Awaiting BFA rport offline
1025 * callback to send LOGO.
1028 bfa_fcs_rport_sm_hcb_logosend(struct bfa_fcs_rport_s *rport,
1029 enum rport_event event)
1031 bfa_trc(rport->fcs, rport->pwwn);
1032 bfa_trc(rport->fcs, rport->pid);
1033 bfa_trc(rport->fcs, event);
1036 case RPSM_EVENT_HCB_OFFLINE:
1037 bfa_sm_set_state(rport, bfa_fcs_rport_sm_logo_sending);
1038 bfa_fcs_rport_send_logo(rport, NULL);
1041 case RPSM_EVENT_LOGO_RCVD:
1042 case RPSM_EVENT_PRLO_RCVD:
1043 case RPSM_EVENT_ADDRESS_CHANGE:
1047 bfa_sm_fault(rport->fcs, event);
1052 * Rport is being deleted. FC-4s are offline. LOGO is being sent.
1055 bfa_fcs_rport_sm_logo_sending(struct bfa_fcs_rport_s *rport,
1056 enum rport_event event)
1058 bfa_trc(rport->fcs, rport->pwwn);
1059 bfa_trc(rport->fcs, rport->pid);
1060 bfa_trc(rport->fcs, event);
1063 case RPSM_EVENT_FCXP_SENT:
1064 /* Once LOGO is sent, we donot wait for the response */
1065 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1066 bfa_fcs_rport_free(rport);
1069 case RPSM_EVENT_SCN:
1070 case RPSM_EVENT_ADDRESS_CHANGE:
1073 case RPSM_EVENT_LOGO_RCVD:
1074 case RPSM_EVENT_PRLO_RCVD:
1075 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1076 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
1077 bfa_fcs_rport_free(rport);
1081 bfa_sm_fault(rport->fcs, event);
1086 * Rport is offline. FC-4s are offline. BFA rport is offline.
1087 * Timer active to delete stale rport.
1090 bfa_fcs_rport_sm_offline(struct bfa_fcs_rport_s *rport, enum rport_event event)
1092 bfa_trc(rport->fcs, rport->pwwn);
1093 bfa_trc(rport->fcs, rport->pid);
1094 bfa_trc(rport->fcs, event);
1097 case RPSM_EVENT_TIMEOUT:
1098 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1099 bfa_fcs_rport_free(rport);
1102 case RPSM_EVENT_SCN:
1103 case RPSM_EVENT_ADDRESS_CHANGE:
1104 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
1105 bfa_timer_stop(&rport->timer);
1106 rport->ns_retries = 0;
1107 bfa_fcs_rport_send_nsdisc(rport, NULL);
1110 case RPSM_EVENT_DELETE:
1111 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1112 bfa_timer_stop(&rport->timer);
1113 bfa_fcs_rport_free(rport);
1116 case RPSM_EVENT_PLOGI_RCVD:
1117 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
1118 bfa_timer_stop(&rport->timer);
1119 bfa_fcs_rport_send_plogiacc(rport, NULL);
1122 case RPSM_EVENT_LOGO_RCVD:
1123 case RPSM_EVENT_PRLO_RCVD:
1124 case RPSM_EVENT_LOGO_IMP:
1127 case RPSM_EVENT_PLOGI_COMP:
1128 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
1129 bfa_timer_stop(&rport->timer);
1130 bfa_fcs_rport_hal_online(rport);
1133 case RPSM_EVENT_PLOGI_SEND:
1134 bfa_timer_stop(&rport->timer);
1135 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
1136 rport->plogi_retries = 0;
1137 bfa_fcs_rport_send_plogi(rport, NULL);
1141 bfa_sm_fault(rport->fcs, event);
1146 * Rport address has changed. Nameserver discovery request is being sent.
1149 bfa_fcs_rport_sm_nsdisc_sending(struct bfa_fcs_rport_s *rport,
1150 enum rport_event event)
1152 bfa_trc(rport->fcs, rport->pwwn);
1153 bfa_trc(rport->fcs, rport->pid);
1154 bfa_trc(rport->fcs, event);
1157 case RPSM_EVENT_FCXP_SENT:
1158 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sent);
1161 case RPSM_EVENT_DELETE:
1162 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1163 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
1164 bfa_fcs_rport_free(rport);
1167 case RPSM_EVENT_PLOGI_RCVD:
1168 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
1169 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
1170 bfa_fcs_rport_send_plogiacc(rport, NULL);
1173 case RPSM_EVENT_SCN:
1174 case RPSM_EVENT_LOGO_RCVD:
1175 case RPSM_EVENT_PRLO_RCVD:
1176 case RPSM_EVENT_PLOGI_SEND:
1179 case RPSM_EVENT_ADDRESS_CHANGE:
1180 rport->ns_retries = 0; /* reset the retry count */
1183 case RPSM_EVENT_LOGO_IMP:
1184 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
1185 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
1186 bfa_timer_start(rport->fcs->bfa, &rport->timer,
1187 bfa_fcs_rport_timeout, rport,
1188 bfa_fcs_rport_del_timeout);
1191 case RPSM_EVENT_PLOGI_COMP:
1192 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
1193 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
1194 bfa_fcs_rport_hal_online(rport);
1198 bfa_sm_fault(rport->fcs, event);
1203 * Nameserver discovery failed. Waiting for timeout to retry.
1206 bfa_fcs_rport_sm_nsdisc_retry(struct bfa_fcs_rport_s *rport,
1207 enum rport_event event)
1209 bfa_trc(rport->fcs, rport->pwwn);
1210 bfa_trc(rport->fcs, rport->pid);
1211 bfa_trc(rport->fcs, event);
1214 case RPSM_EVENT_TIMEOUT:
1215 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
1216 bfa_fcs_rport_send_nsdisc(rport, NULL);
1219 case RPSM_EVENT_SCN:
1220 case RPSM_EVENT_ADDRESS_CHANGE:
1221 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
1222 bfa_timer_stop(&rport->timer);
1223 rport->ns_retries = 0;
1224 bfa_fcs_rport_send_nsdisc(rport, NULL);
1227 case RPSM_EVENT_DELETE:
1228 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1229 bfa_timer_stop(&rport->timer);
1230 bfa_fcs_rport_free(rport);
1233 case RPSM_EVENT_PLOGI_RCVD:
1234 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
1235 bfa_timer_stop(&rport->timer);
1236 bfa_fcs_rport_send_plogiacc(rport, NULL);
1239 case RPSM_EVENT_LOGO_IMP:
1241 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
1242 bfa_timer_stop(&rport->timer);
1243 bfa_timer_start(rport->fcs->bfa, &rport->timer,
1244 bfa_fcs_rport_timeout, rport,
1245 bfa_fcs_rport_del_timeout);
1248 case RPSM_EVENT_LOGO_RCVD:
1249 bfa_fcs_rport_send_logo_acc(rport);
1251 case RPSM_EVENT_PRLO_RCVD:
1252 bfa_fcs_rport_send_prlo_acc(rport);
1255 case RPSM_EVENT_PLOGI_COMP:
1256 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
1257 bfa_timer_stop(&rport->timer);
1258 bfa_fcs_rport_hal_online(rport);
1262 bfa_sm_fault(rport->fcs, event);
1267 * Rport address has changed. Nameserver discovery request is sent.
1270 bfa_fcs_rport_sm_nsdisc_sent(struct bfa_fcs_rport_s *rport,
1271 enum rport_event event)
1273 bfa_trc(rport->fcs, rport->pwwn);
1274 bfa_trc(rport->fcs, rport->pid);
1275 bfa_trc(rport->fcs, event);
1278 case RPSM_EVENT_ACCEPTED:
1279 case RPSM_EVENT_ADDRESS_CHANGE:
1281 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
1282 bfa_fcs_rport_send_plogi(rport, NULL);
1284 bfa_sm_set_state(rport,
1285 bfa_fcs_rport_sm_nsdisc_sending);
1286 rport->ns_retries = 0;
1287 bfa_fcs_rport_send_nsdisc(rport, NULL);
1291 case RPSM_EVENT_FAILED:
1292 rport->ns_retries++;
1293 if (rport->ns_retries < BFA_FCS_RPORT_MAX_RETRIES) {
1294 bfa_sm_set_state(rport,
1295 bfa_fcs_rport_sm_nsdisc_sending);
1296 bfa_fcs_rport_send_nsdisc(rport, NULL);
1299 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
1300 bfa_timer_start(rport->fcs->bfa, &rport->timer,
1301 bfa_fcs_rport_timeout, rport,
1302 bfa_fcs_rport_del_timeout);
1306 case RPSM_EVENT_DELETE:
1307 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1308 bfa_fcxp_discard(rport->fcxp);
1309 bfa_fcs_rport_free(rport);
1312 case RPSM_EVENT_PLOGI_RCVD:
1313 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
1314 bfa_fcxp_discard(rport->fcxp);
1315 bfa_fcs_rport_send_plogiacc(rport, NULL);
1318 case RPSM_EVENT_LOGO_IMP:
1320 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
1321 bfa_fcxp_discard(rport->fcxp);
1322 bfa_timer_start(rport->fcs->bfa, &rport->timer,
1323 bfa_fcs_rport_timeout, rport,
1324 bfa_fcs_rport_del_timeout);
1328 case RPSM_EVENT_PRLO_RCVD:
1329 bfa_fcs_rport_send_prlo_acc(rport);
1331 case RPSM_EVENT_SCN:
1333 * ignore, wait for NS query response
1337 case RPSM_EVENT_LOGO_RCVD:
1339 * Not logged-in yet. Accept LOGO.
1341 bfa_fcs_rport_send_logo_acc(rport);
1344 case RPSM_EVENT_PLOGI_COMP:
1345 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
1346 bfa_fcxp_discard(rport->fcxp);
1347 bfa_fcs_rport_hal_online(rport);
1351 bfa_sm_fault(rport->fcs, event);
1358 * fcs_rport_private FCS RPORT provate functions
1362 bfa_fcs_rport_send_plogi(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1364 struct bfa_fcs_rport_s *rport = rport_cbarg;
1365 struct bfa_fcs_lport_s *port = rport->port;
1368 struct bfa_fcxp_s *fcxp;
1370 bfa_trc(rport->fcs, rport->pwwn);
1372 fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
1374 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
1375 bfa_fcs_rport_send_plogi, rport);
1380 len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
1381 bfa_fcs_lport_get_fcid(port), 0,
1382 port->port_cfg.pwwn, port->port_cfg.nwwn,
1383 bfa_fcport_get_maxfrsize(port->fcs->bfa),
1384 bfa_fcport_get_rx_bbcredit(port->fcs->bfa));
1386 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1387 FC_CLASS_3, len, &fchs, bfa_fcs_rport_plogi_response,
1388 (void *)rport, FC_MAX_PDUSZ, FC_ELS_TOV);
1390 rport->stats.plogis++;
1391 bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
1395 bfa_fcs_rport_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1396 bfa_status_t req_status, u32 rsp_len,
1397 u32 resid_len, struct fchs_s *rsp_fchs)
1399 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
1400 struct fc_logi_s *plogi_rsp;
1401 struct fc_ls_rjt_s *ls_rjt;
1402 struct bfa_fcs_rport_s *twin;
1403 struct list_head *qe;
1405 bfa_trc(rport->fcs, rport->pwwn);
1410 if (req_status != BFA_STATUS_OK) {
1411 bfa_trc(rport->fcs, req_status);
1412 rport->stats.plogi_failed++;
1413 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1417 plogi_rsp = (struct fc_logi_s *) BFA_FCXP_RSP_PLD(fcxp);
1420 * Check for failure first.
1422 if (plogi_rsp->els_cmd.els_code != FC_ELS_ACC) {
1423 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
1425 bfa_trc(rport->fcs, ls_rjt->reason_code);
1426 bfa_trc(rport->fcs, ls_rjt->reason_code_expl);
1428 if ((ls_rjt->reason_code == FC_LS_RJT_RSN_UNABLE_TO_PERF_CMD) &&
1429 (ls_rjt->reason_code_expl == FC_LS_RJT_EXP_INSUFF_RES)) {
1430 rport->stats.rjt_insuff_res++;
1431 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RETRY);
1435 rport->stats.plogi_rejects++;
1436 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1441 * PLOGI is complete. Make sure this device is not one of the known
1442 * device with a new FC port address.
1444 list_for_each(qe, &rport->port->rport_q) {
1445 twin = (struct bfa_fcs_rport_s *) qe;
1448 if (!rport->pwwn && (plogi_rsp->port_name == twin->pwwn)) {
1449 bfa_trc(rport->fcs, twin->pid);
1450 bfa_trc(rport->fcs, rport->pid);
1452 /* Update plogi stats in twin */
1453 twin->stats.plogis += rport->stats.plogis;
1454 twin->stats.plogi_rejects +=
1455 rport->stats.plogi_rejects;
1456 twin->stats.plogi_timeouts +=
1457 rport->stats.plogi_timeouts;
1458 twin->stats.plogi_failed +=
1459 rport->stats.plogi_failed;
1460 twin->stats.plogi_rcvd += rport->stats.plogi_rcvd;
1461 twin->stats.plogi_accs++;
1463 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
1465 bfa_fcs_rport_update(twin, plogi_rsp);
1466 twin->pid = rsp_fchs->s_id;
1467 bfa_sm_send_event(twin, RPSM_EVENT_PLOGI_COMP);
1473 * Normal login path -- no evil twins.
1475 rport->stats.plogi_accs++;
1476 bfa_fcs_rport_update(rport, plogi_rsp);
1477 bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
1481 bfa_fcs_rport_send_plogiacc(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1483 struct bfa_fcs_rport_s *rport = rport_cbarg;
1484 struct bfa_fcs_lport_s *port = rport->port;
1487 struct bfa_fcxp_s *fcxp;
1489 bfa_trc(rport->fcs, rport->pwwn);
1490 bfa_trc(rport->fcs, rport->reply_oxid);
1492 fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
1494 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
1495 bfa_fcs_rport_send_plogiacc, rport);
1500 len = fc_plogi_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1501 rport->pid, bfa_fcs_lport_get_fcid(port),
1502 rport->reply_oxid, port->port_cfg.pwwn,
1503 port->port_cfg.nwwn,
1504 bfa_fcport_get_maxfrsize(port->fcs->bfa),
1505 bfa_fcport_get_rx_bbcredit(port->fcs->bfa));
1507 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1508 FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
1510 bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
1514 bfa_fcs_rport_send_adisc(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1516 struct bfa_fcs_rport_s *rport = rport_cbarg;
1517 struct bfa_fcs_lport_s *port = rport->port;
1520 struct bfa_fcxp_s *fcxp;
1522 bfa_trc(rport->fcs, rport->pwwn);
1524 fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
1526 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
1527 bfa_fcs_rport_send_adisc, rport);
1532 len = fc_adisc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
1533 bfa_fcs_lport_get_fcid(port), 0,
1534 port->port_cfg.pwwn, port->port_cfg.nwwn);
1536 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1537 FC_CLASS_3, len, &fchs, bfa_fcs_rport_adisc_response,
1538 rport, FC_MAX_PDUSZ, FC_ELS_TOV);
1540 rport->stats.adisc_sent++;
1541 bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
1545 bfa_fcs_rport_adisc_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1546 bfa_status_t req_status, u32 rsp_len,
1547 u32 resid_len, struct fchs_s *rsp_fchs)
1549 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
1550 void *pld = bfa_fcxp_get_rspbuf(fcxp);
1551 struct fc_ls_rjt_s *ls_rjt;
1553 if (req_status != BFA_STATUS_OK) {
1554 bfa_trc(rport->fcs, req_status);
1555 rport->stats.adisc_failed++;
1556 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1560 if (fc_adisc_rsp_parse((struct fc_adisc_s *)pld, rsp_len, rport->pwwn,
1561 rport->nwwn) == FC_PARSE_OK) {
1562 rport->stats.adisc_accs++;
1563 bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
1567 rport->stats.adisc_rejects++;
1569 bfa_trc(rport->fcs, ls_rjt->els_cmd.els_code);
1570 bfa_trc(rport->fcs, ls_rjt->reason_code);
1571 bfa_trc(rport->fcs, ls_rjt->reason_code_expl);
1572 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1576 bfa_fcs_rport_send_nsdisc(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1578 struct bfa_fcs_rport_s *rport = rport_cbarg;
1579 struct bfa_fcs_lport_s *port = rport->port;
1581 struct bfa_fcxp_s *fcxp;
1583 bfa_cb_fcxp_send_t cbfn;
1585 bfa_trc(rport->fcs, rport->pid);
1587 fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
1589 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
1590 bfa_fcs_rport_send_nsdisc, rport);
1596 len = fc_gidpn_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1597 bfa_fcs_lport_get_fcid(port), 0, rport->pwwn);
1598 cbfn = bfa_fcs_rport_gidpn_response;
1600 len = fc_gpnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1601 bfa_fcs_lport_get_fcid(port), 0, rport->pid);
1602 cbfn = bfa_fcs_rport_gpnid_response;
1605 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1606 FC_CLASS_3, len, &fchs, cbfn,
1607 (void *)rport, FC_MAX_PDUSZ, FC_FCCT_TOV);
1609 bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
1613 bfa_fcs_rport_gidpn_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1614 bfa_status_t req_status, u32 rsp_len,
1615 u32 resid_len, struct fchs_s *rsp_fchs)
1617 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
1618 struct ct_hdr_s *cthdr;
1619 struct fcgs_gidpn_resp_s *gidpn_rsp;
1620 struct bfa_fcs_rport_s *twin;
1621 struct list_head *qe;
1623 bfa_trc(rport->fcs, rport->pwwn);
1625 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
1626 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
1628 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
1629 /* Check if the pid is the same as before. */
1630 gidpn_rsp = (struct fcgs_gidpn_resp_s *) (cthdr + 1);
1632 if (gidpn_rsp->dap == rport->pid) {
1633 /* Device is online */
1634 bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
1637 * Device's PID has changed. We need to cleanup
1638 * and re-login. If there is another device with
1639 * the the newly discovered pid, send an scn notice
1640 * so that its new pid can be discovered.
1642 list_for_each(qe, &rport->port->rport_q) {
1643 twin = (struct bfa_fcs_rport_s *) qe;
1646 if (gidpn_rsp->dap == twin->pid) {
1647 bfa_trc(rport->fcs, twin->pid);
1648 bfa_trc(rport->fcs, rport->pid);
1651 bfa_sm_send_event(twin,
1652 RPSM_EVENT_ADDRESS_CHANGE);
1655 rport->pid = gidpn_rsp->dap;
1656 bfa_sm_send_event(rport, RPSM_EVENT_ADDRESS_CHANGE);
1664 switch (cthdr->reason_code) {
1665 case CT_RSN_LOGICAL_BUSY:
1669 bfa_sm_send_event(rport, RPSM_EVENT_TIMEOUT);
1672 case CT_RSN_UNABLE_TO_PERF:
1674 * device doesn't exist : Start timer to cleanup this later.
1676 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1680 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1686 bfa_fcs_rport_gpnid_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1687 bfa_status_t req_status, u32 rsp_len,
1688 u32 resid_len, struct fchs_s *rsp_fchs)
1690 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
1691 struct ct_hdr_s *cthdr;
1693 bfa_trc(rport->fcs, rport->pwwn);
1695 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
1696 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
1698 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
1699 bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
1706 switch (cthdr->reason_code) {
1707 case CT_RSN_LOGICAL_BUSY:
1711 bfa_sm_send_event(rport, RPSM_EVENT_TIMEOUT);
1714 case CT_RSN_UNABLE_TO_PERF:
1716 * device doesn't exist : Start timer to cleanup this later.
1718 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1722 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1728 * Called to send a logout to the rport.
1731 bfa_fcs_rport_send_logo(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1733 struct bfa_fcs_rport_s *rport = rport_cbarg;
1734 struct bfa_fcs_lport_s *port;
1736 struct bfa_fcxp_s *fcxp;
1739 bfa_trc(rport->fcs, rport->pid);
1743 fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
1745 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
1746 bfa_fcs_rport_send_logo, rport);
1751 len = fc_logo_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
1752 bfa_fcs_lport_get_fcid(port), 0,
1753 bfa_fcs_lport_get_pwwn(port));
1755 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1756 FC_CLASS_3, len, &fchs, NULL,
1757 rport, FC_MAX_PDUSZ, FC_ELS_TOV);
1759 rport->stats.logos++;
1760 bfa_fcxp_discard(rport->fcxp);
1761 bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
1765 * Send ACC for a LOGO received.
1768 bfa_fcs_rport_send_logo_acc(void *rport_cbarg)
1770 struct bfa_fcs_rport_s *rport = rport_cbarg;
1771 struct bfa_fcs_lport_s *port;
1773 struct bfa_fcxp_s *fcxp;
1776 bfa_trc(rport->fcs, rport->pid);
1780 fcxp = bfa_fcs_fcxp_alloc(port->fcs);
1784 rport->stats.logo_rcvd++;
1785 len = fc_logo_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1786 rport->pid, bfa_fcs_lport_get_fcid(port),
1789 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1790 FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
1795 * This routine will be called by bfa_timer on timer timeouts.
1797 * param[in] rport - pointer to bfa_fcs_lport_ns_t.
1798 * param[out] rport_status - pointer to return vport status in
1803 * Special Considerations:
1808 bfa_fcs_rport_timeout(void *arg)
1810 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) arg;
1812 rport->stats.plogi_timeouts++;
1813 bfa_stats(rport->port, rport_plogi_timeouts);
1814 bfa_sm_send_event(rport, RPSM_EVENT_TIMEOUT);
1818 bfa_fcs_rport_process_prli(struct bfa_fcs_rport_s *rport,
1819 struct fchs_s *rx_fchs, u16 len)
1821 struct bfa_fcxp_s *fcxp;
1823 struct bfa_fcs_lport_s *port = rport->port;
1824 struct fc_prli_s *prli;
1826 bfa_trc(port->fcs, rx_fchs->s_id);
1827 bfa_trc(port->fcs, rx_fchs->d_id);
1829 rport->stats.prli_rcvd++;
1832 * We are in Initiator Mode
1834 prli = (struct fc_prli_s *) (rx_fchs + 1);
1836 if (prli->parampage.servparams.target) {
1838 * PRLI from a target ?
1840 * PRLI sent by us will be used to transition the IT nexus,
1841 * once the response is received from the target.
1843 bfa_trc(port->fcs, rx_fchs->s_id);
1844 rport->scsi_function = BFA_RPORT_TARGET;
1846 bfa_trc(rport->fcs, prli->parampage.type);
1847 rport->scsi_function = BFA_RPORT_INITIATOR;
1848 bfa_fcs_itnim_is_initiator(rport->itnim);
1851 fcxp = bfa_fcs_fcxp_alloc(port->fcs);
1855 len = fc_prli_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1856 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
1857 rx_fchs->ox_id, port->port_cfg.roles);
1859 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1860 FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
1864 bfa_fcs_rport_process_rpsc(struct bfa_fcs_rport_s *rport,
1865 struct fchs_s *rx_fchs, u16 len)
1867 struct bfa_fcxp_s *fcxp;
1869 struct bfa_fcs_lport_s *port = rport->port;
1870 struct fc_rpsc_speed_info_s speeds;
1871 struct bfa_port_attr_s pport_attr;
1873 bfa_trc(port->fcs, rx_fchs->s_id);
1874 bfa_trc(port->fcs, rx_fchs->d_id);
1876 rport->stats.rpsc_rcvd++;
1877 speeds.port_speed_cap =
1878 RPSC_SPEED_CAP_1G | RPSC_SPEED_CAP_2G | RPSC_SPEED_CAP_4G |
1882 * get curent speed from pport attributes from BFA
1884 bfa_fcport_get_attr(port->fcs->bfa, &pport_attr);
1886 speeds.port_op_speed = fc_bfa_speed_to_rpsc_operspeed(pport_attr.speed);
1888 fcxp = bfa_fcs_fcxp_alloc(port->fcs);
1892 len = fc_rpsc_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1893 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
1894 rx_fchs->ox_id, &speeds);
1896 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1897 FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
1901 bfa_fcs_rport_process_adisc(struct bfa_fcs_rport_s *rport,
1902 struct fchs_s *rx_fchs, u16 len)
1904 struct bfa_fcxp_s *fcxp;
1906 struct bfa_fcs_lport_s *port = rport->port;
1907 struct fc_adisc_s *adisc;
1909 bfa_trc(port->fcs, rx_fchs->s_id);
1910 bfa_trc(port->fcs, rx_fchs->d_id);
1912 rport->stats.adisc_rcvd++;
1914 adisc = (struct fc_adisc_s *) (rx_fchs + 1);
1917 * Accept if the itnim for this rport is online.
1918 * Else reject the ADISC.
1920 if (bfa_fcs_itnim_get_online_state(rport->itnim) == BFA_STATUS_OK) {
1922 fcxp = bfa_fcs_fcxp_alloc(port->fcs);
1926 len = fc_adisc_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1927 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
1928 rx_fchs->ox_id, port->port_cfg.pwwn,
1929 port->port_cfg.nwwn);
1931 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag,
1932 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
1935 rport->stats.adisc_rejected++;
1936 bfa_fcs_rport_send_ls_rjt(rport, rx_fchs,
1937 FC_LS_RJT_RSN_UNABLE_TO_PERF_CMD,
1938 FC_LS_RJT_EXP_LOGIN_REQUIRED);
1943 bfa_fcs_rport_hal_online(struct bfa_fcs_rport_s *rport)
1945 struct bfa_fcs_lport_s *port = rport->port;
1946 struct bfa_rport_info_s rport_info;
1948 rport_info.pid = rport->pid;
1949 rport_info.local_pid = port->pid;
1950 rport_info.lp_tag = port->lp_tag;
1951 rport_info.vf_id = port->fabric->vf_id;
1952 rport_info.vf_en = port->fabric->is_vf;
1953 rport_info.fc_class = rport->fc_cos;
1954 rport_info.cisc = rport->cisc;
1955 rport_info.max_frmsz = rport->maxfrsize;
1956 bfa_rport_online(rport->bfa_rport, &rport_info);
1959 static struct bfa_fcs_rport_s *
1960 bfa_fcs_rport_alloc(struct bfa_fcs_lport_s *port, wwn_t pwwn, u32 rpid)
1962 struct bfa_fcs_s *fcs = port->fcs;
1963 struct bfa_fcs_rport_s *rport;
1964 struct bfad_rport_s *rport_drv;
1969 if (bfa_fcb_rport_alloc(fcs->bfad, &rport, &rport_drv)
1980 rport->rp_drv = rport_drv;
1985 * allocate BFA rport
1987 rport->bfa_rport = bfa_rport_create(port->fcs->bfa, rport);
1988 if (!rport->bfa_rport) {
1997 WARN_ON(!bfa_fcs_lport_is_initiator(port));
1999 if (bfa_fcs_lport_is_initiator(port)) {
2000 rport->itnim = bfa_fcs_itnim_create(rport);
2001 if (!rport->itnim) {
2003 bfa_sm_send_event(rport->bfa_rport,
2004 BFA_RPORT_SM_DELETE);
2010 bfa_fcs_lport_add_rport(port, rport);
2012 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
2014 /* Initialize the Rport Features(RPF) Sub Module */
2015 if (!BFA_FCS_PID_IS_WKA(rport->pid))
2016 bfa_fcs_rpf_init(rport);
2023 bfa_fcs_rport_free(struct bfa_fcs_rport_s *rport)
2025 struct bfa_fcs_lport_s *port = rport->port;
2029 * - delete BFA rport
2030 * - remove from queue of rports
2032 if (bfa_fcs_lport_is_initiator(port)) {
2033 bfa_fcs_itnim_delete(rport->itnim);
2034 if (rport->pid != 0 && !BFA_FCS_PID_IS_WKA(rport->pid))
2035 bfa_fcs_rpf_rport_offline(rport);
2038 bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_DELETE);
2039 bfa_fcs_lport_del_rport(port, rport);
2040 kfree(rport->rp_drv);
2044 bfa_fcs_rport_online_action(struct bfa_fcs_rport_s *rport)
2046 struct bfa_fcs_lport_s *port = rport->port;
2047 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
2048 char lpwwn_buf[BFA_STRING_32];
2049 char rpwwn_buf[BFA_STRING_32];
2051 rport->stats.onlines++;
2053 if ((!rport->pid) || (!rport->pwwn)) {
2054 bfa_trc(rport->fcs, rport->pid);
2055 bfa_sm_fault(rport->fcs, rport->pid);
2058 if (bfa_fcs_lport_is_initiator(port)) {
2059 bfa_fcs_itnim_rport_online(rport->itnim);
2060 if (!BFA_FCS_PID_IS_WKA(rport->pid))
2061 bfa_fcs_rpf_rport_online(rport);
2064 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
2065 wwn2str(rpwwn_buf, rport->pwwn);
2066 if (!BFA_FCS_PID_IS_WKA(rport->pid))
2067 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
2068 "Remote port (WWN = %s) online for logical port (WWN = %s)\n",
2069 rpwwn_buf, lpwwn_buf);
2073 bfa_fcs_rport_offline_action(struct bfa_fcs_rport_s *rport)
2075 struct bfa_fcs_lport_s *port = rport->port;
2076 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
2077 char lpwwn_buf[BFA_STRING_32];
2078 char rpwwn_buf[BFA_STRING_32];
2080 rport->stats.offlines++;
2081 rport->plogi_pending = BFA_FALSE;
2083 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
2084 wwn2str(rpwwn_buf, rport->pwwn);
2085 if (!BFA_FCS_PID_IS_WKA(rport->pid)) {
2086 if (bfa_fcs_lport_is_online(rport->port) == BFA_TRUE)
2087 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
2088 "Remote port (WWN = %s) connectivity lost for "
2089 "logical port (WWN = %s)\n",
2090 rpwwn_buf, lpwwn_buf);
2092 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
2093 "Remote port (WWN = %s) offlined by "
2094 "logical port (WWN = %s)\n",
2095 rpwwn_buf, lpwwn_buf);
2098 if (bfa_fcs_lport_is_initiator(port)) {
2099 bfa_fcs_itnim_rport_offline(rport->itnim);
2100 if (!BFA_FCS_PID_IS_WKA(rport->pid))
2101 bfa_fcs_rpf_rport_offline(rport);
2106 * Update rport parameters from PLOGI or PLOGI accept.
2109 bfa_fcs_rport_update(struct bfa_fcs_rport_s *rport, struct fc_logi_s *plogi)
2111 bfa_fcs_lport_t *port = rport->port;
2117 rport->pwwn = plogi->port_name;
2118 rport->nwwn = plogi->node_name;
2121 * - class of service
2124 if (plogi->class3.class_valid)
2125 rport->fc_cos = FC_CLASS_3;
2127 if (plogi->class2.class_valid)
2128 rport->fc_cos |= FC_CLASS_2;
2132 * - MAX receive frame size
2134 rport->cisc = plogi->csp.cisc;
2135 rport->maxfrsize = be16_to_cpu(plogi->class3.rxsz);
2137 bfa_trc(port->fcs, be16_to_cpu(plogi->csp.bbcred));
2138 bfa_trc(port->fcs, port->fabric->bb_credit);
2140 * Direct Attach P2P mode :
2141 * This is to handle a bug (233476) in IBM targets in Direct Attach
2142 * Mode. Basically, in FLOGI Accept the target would have
2143 * erroneously set the BB Credit to the value used in the FLOGI
2144 * sent by the HBA. It uses the correct value (its own BB credit)
2147 if ((!bfa_fcs_fabric_is_switched(port->fabric)) &&
2148 (be16_to_cpu(plogi->csp.bbcred) < port->fabric->bb_credit)) {
2150 bfa_trc(port->fcs, be16_to_cpu(plogi->csp.bbcred));
2151 bfa_trc(port->fcs, port->fabric->bb_credit);
2153 port->fabric->bb_credit = be16_to_cpu(plogi->csp.bbcred);
2154 bfa_fcport_set_tx_bbcredit(port->fcs->bfa,
2155 port->fabric->bb_credit, 0);
2161 * Called to handle LOGO received from an existing remote port.
2164 bfa_fcs_rport_process_logo(struct bfa_fcs_rport_s *rport, struct fchs_s *fchs)
2166 rport->reply_oxid = fchs->ox_id;
2167 bfa_trc(rport->fcs, rport->reply_oxid);
2169 rport->prlo = BFA_FALSE;
2170 rport->stats.logo_rcvd++;
2171 bfa_sm_send_event(rport, RPSM_EVENT_LOGO_RCVD);
2177 * fcs_rport_public FCS rport public interfaces
2181 * Called by bport/vport to create a remote port instance for a discovered
2184 * @param[in] port - base port or vport
2185 * @param[in] rpid - remote port ID
2189 struct bfa_fcs_rport_s *
2190 bfa_fcs_rport_create(struct bfa_fcs_lport_s *port, u32 rpid)
2192 struct bfa_fcs_rport_s *rport;
2194 bfa_trc(port->fcs, rpid);
2195 rport = bfa_fcs_rport_alloc(port, WWN_NULL, rpid);
2199 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_SEND);
2204 * Called to create a rport for which only the wwn is known.
2206 * @param[in] port - base port
2207 * @param[in] rpwwn - remote port wwn
2211 struct bfa_fcs_rport_s *
2212 bfa_fcs_rport_create_by_wwn(struct bfa_fcs_lport_s *port, wwn_t rpwwn)
2214 struct bfa_fcs_rport_s *rport;
2215 bfa_trc(port->fcs, rpwwn);
2216 rport = bfa_fcs_rport_alloc(port, rpwwn, 0);
2220 bfa_sm_send_event(rport, RPSM_EVENT_ADDRESS_DISC);
2224 * Called by bport in private loop topology to indicate that a
2225 * rport has been discovered and plogi has been completed.
2227 * @param[in] port - base port or vport
2228 * @param[in] rpid - remote port ID
2231 bfa_fcs_rport_start(struct bfa_fcs_lport_s *port, struct fchs_s *fchs,
2232 struct fc_logi_s *plogi)
2234 struct bfa_fcs_rport_s *rport;
2236 rport = bfa_fcs_rport_alloc(port, WWN_NULL, fchs->s_id);
2240 bfa_fcs_rport_update(rport, plogi);
2242 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_COMP);
2246 * Called by bport/vport to handle PLOGI received from a new remote port.
2247 * If an existing rport does a plogi, it will be handled separately.
2250 bfa_fcs_rport_plogi_create(struct bfa_fcs_lport_s *port, struct fchs_s *fchs,
2251 struct fc_logi_s *plogi)
2253 struct bfa_fcs_rport_s *rport;
2255 rport = bfa_fcs_rport_alloc(port, plogi->port_name, fchs->s_id);
2259 bfa_fcs_rport_update(rport, plogi);
2261 rport->reply_oxid = fchs->ox_id;
2262 bfa_trc(rport->fcs, rport->reply_oxid);
2264 rport->stats.plogi_rcvd++;
2265 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RCVD);
2269 * Called by bport/vport to handle PLOGI received from an existing
2273 bfa_fcs_rport_plogi(struct bfa_fcs_rport_s *rport, struct fchs_s *rx_fchs,
2274 struct fc_logi_s *plogi)
2277 * @todo Handle P2P and initiator-initiator.
2280 bfa_fcs_rport_update(rport, plogi);
2282 rport->reply_oxid = rx_fchs->ox_id;
2283 bfa_trc(rport->fcs, rport->reply_oxid);
2285 rport->pid = rx_fchs->s_id;
2286 bfa_trc(rport->fcs, rport->pid);
2288 rport->stats.plogi_rcvd++;
2289 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RCVD);
2294 * Called by bport/vport to notify SCN for the remote port
2297 bfa_fcs_rport_scn(struct bfa_fcs_rport_s *rport)
2299 rport->stats.rscns++;
2300 bfa_sm_send_event(rport, RPSM_EVENT_SCN);
2306 * This routine BFA callback for bfa_rport_online() call.
2308 * param[in] cb_arg - rport struct.
2313 * Special Considerations:
2318 bfa_cb_rport_online(void *cbarg)
2321 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
2323 bfa_trc(rport->fcs, rport->pwwn);
2324 bfa_sm_send_event(rport, RPSM_EVENT_HCB_ONLINE);
2329 * This routine BFA callback for bfa_rport_offline() call.
2336 * Special Considerations:
2341 bfa_cb_rport_offline(void *cbarg)
2343 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
2345 bfa_trc(rport->fcs, rport->pwwn);
2346 bfa_sm_send_event(rport, RPSM_EVENT_HCB_OFFLINE);
2351 * This routine is a static BFA callback when there is a QoS flow_id
2352 * change notification
2359 * Special Considerations:
2364 bfa_cb_rport_qos_scn_flowid(void *cbarg,
2365 struct bfa_rport_qos_attr_s old_qos_attr,
2366 struct bfa_rport_qos_attr_s new_qos_attr)
2368 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
2370 bfa_trc(rport->fcs, rport->pwwn);
2375 * This routine is a static BFA callback when there is a QoS priority
2376 * change notification
2383 * Special Considerations:
2388 bfa_cb_rport_qos_scn_prio(void *cbarg,
2389 struct bfa_rport_qos_attr_s old_qos_attr,
2390 struct bfa_rport_qos_attr_s new_qos_attr)
2392 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
2394 bfa_trc(rport->fcs, rport->pwwn);
2398 * Called to process any unsolicted frames from this remote port
2401 bfa_fcs_rport_uf_recv(struct bfa_fcs_rport_s *rport,
2402 struct fchs_s *fchs, u16 len)
2404 struct bfa_fcs_lport_s *port = rport->port;
2405 struct fc_els_cmd_s *els_cmd;
2407 bfa_trc(rport->fcs, fchs->s_id);
2408 bfa_trc(rport->fcs, fchs->d_id);
2409 bfa_trc(rport->fcs, fchs->type);
2411 if (fchs->type != FC_TYPE_ELS)
2414 els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
2416 bfa_trc(rport->fcs, els_cmd->els_code);
2418 switch (els_cmd->els_code) {
2420 bfa_stats(port, plogi_rcvd);
2421 bfa_fcs_rport_process_logo(rport, fchs);
2425 bfa_stats(port, adisc_rcvd);
2426 bfa_fcs_rport_process_adisc(rport, fchs, len);
2430 bfa_stats(port, prlo_rcvd);
2431 if (bfa_fcs_lport_is_initiator(port))
2432 bfa_fcs_fcpim_uf_recv(rport->itnim, fchs, len);
2436 bfa_stats(port, prli_rcvd);
2437 bfa_fcs_rport_process_prli(rport, fchs, len);
2441 bfa_stats(port, rpsc_rcvd);
2442 bfa_fcs_rport_process_rpsc(rport, fchs, len);
2446 bfa_stats(port, un_handled_els_rcvd);
2447 bfa_fcs_rport_send_ls_rjt(rport, fchs,
2448 FC_LS_RJT_RSN_CMD_NOT_SUPP,
2449 FC_LS_RJT_EXP_NO_ADDL_INFO);
2454 /* send best case acc to prlo */
2456 bfa_fcs_rport_send_prlo_acc(struct bfa_fcs_rport_s *rport)
2458 struct bfa_fcs_lport_s *port = rport->port;
2460 struct bfa_fcxp_s *fcxp;
2463 bfa_trc(rport->fcs, rport->pid);
2465 fcxp = bfa_fcs_fcxp_alloc(port->fcs);
2468 len = fc_prlo_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
2469 rport->pid, bfa_fcs_lport_get_fcid(port),
2470 rport->reply_oxid, 0);
2472 bfa_fcxp_send(fcxp, rport->bfa_rport, port->fabric->vf_id,
2473 port->lp_tag, BFA_FALSE, FC_CLASS_3, len, &fchs,
2474 NULL, NULL, FC_MAX_PDUSZ, 0);
2481 bfa_fcs_rport_send_ls_rjt(struct bfa_fcs_rport_s *rport, struct fchs_s *rx_fchs,
2482 u8 reason_code, u8 reason_code_expl)
2484 struct bfa_fcs_lport_s *port = rport->port;
2486 struct bfa_fcxp_s *fcxp;
2489 bfa_trc(rport->fcs, rx_fchs->s_id);
2491 fcxp = bfa_fcs_fcxp_alloc(rport->fcs);
2495 len = fc_ls_rjt_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
2496 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
2497 rx_fchs->ox_id, reason_code, reason_code_expl);
2499 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag,
2500 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
2505 * Return state of rport.
2508 bfa_fcs_rport_get_state(struct bfa_fcs_rport_s *rport)
2510 return bfa_sm_to_state(rport_sm_table, rport->sm);
2516 * Called by the Driver to set rport delete/ageout timeout
2518 * param[in] rport timeout value in seconds.
2523 bfa_fcs_rport_set_del_timeout(u8 rport_tmo)
2525 /* convert to Millisecs */
2527 bfa_fcs_rport_del_timeout = rport_tmo * 1000;
2530 bfa_fcs_rport_prlo(struct bfa_fcs_rport_s *rport, __be16 ox_id)
2532 bfa_trc(rport->fcs, rport->pid);
2534 rport->prlo = BFA_TRUE;
2535 rport->reply_oxid = ox_id;
2536 bfa_sm_send_event(rport, RPSM_EVENT_PRLO_RCVD);
2540 bfa_fcs_rport_get_attr(struct bfa_fcs_rport_s *rport,
2541 struct bfa_rport_attr_s *rport_attr)
2543 struct bfa_rport_qos_attr_s qos_attr;
2544 struct bfa_fcs_lport_s *port = rport->port;
2545 bfa_port_speed_t rport_speed = rport->rpf.rpsc_speed;
2547 memset(rport_attr, 0, sizeof(struct bfa_rport_attr_s));
2548 memset(&qos_attr, 0, sizeof(struct bfa_rport_qos_attr_s));
2550 rport_attr->pid = rport->pid;
2551 rport_attr->pwwn = rport->pwwn;
2552 rport_attr->nwwn = rport->nwwn;
2553 rport_attr->cos_supported = rport->fc_cos;
2554 rport_attr->df_sz = rport->maxfrsize;
2555 rport_attr->state = bfa_fcs_rport_get_state(rport);
2556 rport_attr->fc_cos = rport->fc_cos;
2557 rport_attr->cisc = rport->cisc;
2558 rport_attr->scsi_function = rport->scsi_function;
2559 rport_attr->curr_speed = rport->rpf.rpsc_speed;
2560 rport_attr->assigned_speed = rport->rpf.assigned_speed;
2562 qos_attr.qos_priority = rport->bfa_rport->qos_attr.qos_priority;
2563 qos_attr.qos_flow_id =
2564 cpu_to_be32(rport->bfa_rport->qos_attr.qos_flow_id);
2565 rport_attr->qos_attr = qos_attr;
2567 rport_attr->trl_enforced = BFA_FALSE;
2568 if (bfa_fcport_is_ratelim(port->fcs->bfa) &&
2569 (rport->scsi_function == BFA_RPORT_TARGET)) {
2570 if (rport_speed == BFA_PORT_SPEED_UNKNOWN)
2572 bfa_fcport_get_ratelim_speed(rport->fcs->bfa);
2574 if (rport_speed < bfa_fcs_lport_get_rport_max_speed(port))
2575 rport_attr->trl_enforced = BFA_TRUE;
2580 * Remote port implementation.
2584 * fcs_rport_api FCS rport API.
2587 struct bfa_fcs_rport_s *
2588 bfa_fcs_rport_lookup(struct bfa_fcs_lport_s *port, wwn_t rpwwn)
2590 struct bfa_fcs_rport_s *rport;
2592 rport = bfa_fcs_lport_get_rport_by_pwwn(port, rpwwn);
2593 if (rport == NULL) {
2595 * TBD Error handling
2602 struct bfa_fcs_rport_s *
2603 bfa_fcs_rport_lookup_by_nwwn(struct bfa_fcs_lport_s *port, wwn_t rnwwn)
2605 struct bfa_fcs_rport_s *rport;
2607 rport = bfa_fcs_lport_get_rport_by_nwwn(port, rnwwn);
2608 if (rport == NULL) {
2610 * TBD Error handling
2618 * Remote port features (RPF) implementation.
2621 #define BFA_FCS_RPF_RETRIES (3)
2622 #define BFA_FCS_RPF_RETRY_TIMEOUT (1000) /* 1 sec (In millisecs) */
2624 static void bfa_fcs_rpf_send_rpsc2(void *rport_cbarg,
2625 struct bfa_fcxp_s *fcxp_alloced);
2626 static void bfa_fcs_rpf_rpsc2_response(void *fcsarg,
2627 struct bfa_fcxp_s *fcxp,
2629 bfa_status_t req_status,
2632 struct fchs_s *rsp_fchs);
2634 static void bfa_fcs_rpf_timeout(void *arg);
2637 * fcs_rport_ftrs_sm FCS rport state machine events
2641 RPFSM_EVENT_RPORT_OFFLINE = 1, /* Rport offline */
2642 RPFSM_EVENT_RPORT_ONLINE = 2, /* Rport online */
2643 RPFSM_EVENT_FCXP_SENT = 3, /* Frame from has been sent */
2644 RPFSM_EVENT_TIMEOUT = 4, /* Rport SM timeout event */
2645 RPFSM_EVENT_RPSC_COMP = 5,
2646 RPFSM_EVENT_RPSC_FAIL = 6,
2647 RPFSM_EVENT_RPSC_ERROR = 7,
2650 static void bfa_fcs_rpf_sm_uninit(struct bfa_fcs_rpf_s *rpf,
2651 enum rpf_event event);
2652 static void bfa_fcs_rpf_sm_rpsc_sending(struct bfa_fcs_rpf_s *rpf,
2653 enum rpf_event event);
2654 static void bfa_fcs_rpf_sm_rpsc(struct bfa_fcs_rpf_s *rpf,
2655 enum rpf_event event);
2656 static void bfa_fcs_rpf_sm_rpsc_retry(struct bfa_fcs_rpf_s *rpf,
2657 enum rpf_event event);
2658 static void bfa_fcs_rpf_sm_offline(struct bfa_fcs_rpf_s *rpf,
2659 enum rpf_event event);
2660 static void bfa_fcs_rpf_sm_online(struct bfa_fcs_rpf_s *rpf,
2661 enum rpf_event event);
2664 bfa_fcs_rpf_sm_uninit(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
2666 struct bfa_fcs_rport_s *rport = rpf->rport;
2667 struct bfa_fcs_fabric_s *fabric = &rport->fcs->fabric;
2669 bfa_trc(rport->fcs, rport->pwwn);
2670 bfa_trc(rport->fcs, rport->pid);
2671 bfa_trc(rport->fcs, event);
2674 case RPFSM_EVENT_RPORT_ONLINE:
2675 /* Send RPSC2 to a Brocade fabric only. */
2676 if ((!BFA_FCS_PID_IS_WKA(rport->pid)) &&
2677 ((rport->port->fabric->lps->brcd_switch) ||
2678 (bfa_fcs_fabric_get_switch_oui(fabric) ==
2679 BFA_FCS_BRCD_SWITCH_OUI))) {
2680 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
2681 rpf->rpsc_retries = 0;
2682 bfa_fcs_rpf_send_rpsc2(rpf, NULL);
2686 case RPFSM_EVENT_RPORT_OFFLINE:
2690 bfa_sm_fault(rport->fcs, event);
2695 bfa_fcs_rpf_sm_rpsc_sending(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
2697 struct bfa_fcs_rport_s *rport = rpf->rport;
2699 bfa_trc(rport->fcs, event);
2702 case RPFSM_EVENT_FCXP_SENT:
2703 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc);
2706 case RPFSM_EVENT_RPORT_OFFLINE:
2707 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
2708 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rpf->fcxp_wqe);
2709 rpf->rpsc_retries = 0;
2713 bfa_sm_fault(rport->fcs, event);
2718 bfa_fcs_rpf_sm_rpsc(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
2720 struct bfa_fcs_rport_s *rport = rpf->rport;
2722 bfa_trc(rport->fcs, rport->pid);
2723 bfa_trc(rport->fcs, event);
2726 case RPFSM_EVENT_RPSC_COMP:
2727 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
2728 /* Update speed info in f/w via BFA */
2729 if (rpf->rpsc_speed != BFA_PORT_SPEED_UNKNOWN)
2730 bfa_rport_speed(rport->bfa_rport, rpf->rpsc_speed);
2731 else if (rpf->assigned_speed != BFA_PORT_SPEED_UNKNOWN)
2732 bfa_rport_speed(rport->bfa_rport, rpf->assigned_speed);
2735 case RPFSM_EVENT_RPSC_FAIL:
2736 /* RPSC not supported by rport */
2737 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
2740 case RPFSM_EVENT_RPSC_ERROR:
2741 /* need to retry...delayed a bit. */
2742 if (rpf->rpsc_retries++ < BFA_FCS_RPF_RETRIES) {
2743 bfa_timer_start(rport->fcs->bfa, &rpf->timer,
2744 bfa_fcs_rpf_timeout, rpf,
2745 BFA_FCS_RPF_RETRY_TIMEOUT);
2746 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_retry);
2748 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
2752 case RPFSM_EVENT_RPORT_OFFLINE:
2753 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
2754 bfa_fcxp_discard(rpf->fcxp);
2755 rpf->rpsc_retries = 0;
2759 bfa_sm_fault(rport->fcs, event);
2764 bfa_fcs_rpf_sm_rpsc_retry(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
2766 struct bfa_fcs_rport_s *rport = rpf->rport;
2768 bfa_trc(rport->fcs, rport->pid);
2769 bfa_trc(rport->fcs, event);
2772 case RPFSM_EVENT_TIMEOUT:
2773 /* re-send the RPSC */
2774 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
2775 bfa_fcs_rpf_send_rpsc2(rpf, NULL);
2778 case RPFSM_EVENT_RPORT_OFFLINE:
2779 bfa_timer_stop(&rpf->timer);
2780 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
2781 rpf->rpsc_retries = 0;
2785 bfa_sm_fault(rport->fcs, event);
2790 bfa_fcs_rpf_sm_online(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
2792 struct bfa_fcs_rport_s *rport = rpf->rport;
2794 bfa_trc(rport->fcs, rport->pwwn);
2795 bfa_trc(rport->fcs, rport->pid);
2796 bfa_trc(rport->fcs, event);
2799 case RPFSM_EVENT_RPORT_OFFLINE:
2800 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
2801 rpf->rpsc_retries = 0;
2805 bfa_sm_fault(rport->fcs, event);
2810 bfa_fcs_rpf_sm_offline(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
2812 struct bfa_fcs_rport_s *rport = rpf->rport;
2814 bfa_trc(rport->fcs, rport->pwwn);
2815 bfa_trc(rport->fcs, rport->pid);
2816 bfa_trc(rport->fcs, event);
2819 case RPFSM_EVENT_RPORT_ONLINE:
2820 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
2821 bfa_fcs_rpf_send_rpsc2(rpf, NULL);
2824 case RPFSM_EVENT_RPORT_OFFLINE:
2828 bfa_sm_fault(rport->fcs, event);
2832 * Called when Rport is created.
2835 bfa_fcs_rpf_init(struct bfa_fcs_rport_s *rport)
2837 struct bfa_fcs_rpf_s *rpf = &rport->rpf;
2839 bfa_trc(rport->fcs, rport->pid);
2842 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_uninit);
2846 * Called when Rport becomes online
2849 bfa_fcs_rpf_rport_online(struct bfa_fcs_rport_s *rport)
2851 bfa_trc(rport->fcs, rport->pid);
2853 if (__fcs_min_cfg(rport->port->fcs))
2856 if (bfa_fcs_fabric_is_switched(rport->port->fabric))
2857 bfa_sm_send_event(&rport->rpf, RPFSM_EVENT_RPORT_ONLINE);
2861 * Called when Rport becomes offline
2864 bfa_fcs_rpf_rport_offline(struct bfa_fcs_rport_s *rport)
2866 bfa_trc(rport->fcs, rport->pid);
2868 if (__fcs_min_cfg(rport->port->fcs))
2871 rport->rpf.rpsc_speed = 0;
2872 bfa_sm_send_event(&rport->rpf, RPFSM_EVENT_RPORT_OFFLINE);
2876 bfa_fcs_rpf_timeout(void *arg)
2878 struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *) arg;
2879 struct bfa_fcs_rport_s *rport = rpf->rport;
2881 bfa_trc(rport->fcs, rport->pid);
2882 bfa_sm_send_event(rpf, RPFSM_EVENT_TIMEOUT);
2886 bfa_fcs_rpf_send_rpsc2(void *rpf_cbarg, struct bfa_fcxp_s *fcxp_alloced)
2888 struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *)rpf_cbarg;
2889 struct bfa_fcs_rport_s *rport = rpf->rport;
2890 struct bfa_fcs_lport_s *port = rport->port;
2893 struct bfa_fcxp_s *fcxp;
2895 bfa_trc(rport->fcs, rport->pwwn);
2897 fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
2899 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rpf->fcxp_wqe,
2900 bfa_fcs_rpf_send_rpsc2, rpf);
2905 len = fc_rpsc2_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
2906 bfa_fcs_lport_get_fcid(port), &rport->pid, 1);
2908 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
2909 FC_CLASS_3, len, &fchs, bfa_fcs_rpf_rpsc2_response,
2910 rpf, FC_MAX_PDUSZ, FC_ELS_TOV);
2911 rport->stats.rpsc_sent++;
2912 bfa_sm_send_event(rpf, RPFSM_EVENT_FCXP_SENT);
2917 bfa_fcs_rpf_rpsc2_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
2918 bfa_status_t req_status, u32 rsp_len,
2919 u32 resid_len, struct fchs_s *rsp_fchs)
2921 struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *) cbarg;
2922 struct bfa_fcs_rport_s *rport = rpf->rport;
2923 struct fc_ls_rjt_s *ls_rjt;
2924 struct fc_rpsc2_acc_s *rpsc2_acc;
2927 bfa_trc(rport->fcs, req_status);
2929 if (req_status != BFA_STATUS_OK) {
2930 bfa_trc(rport->fcs, req_status);
2931 if (req_status == BFA_STATUS_ETIMER)
2932 rport->stats.rpsc_failed++;
2933 bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);
2937 rpsc2_acc = (struct fc_rpsc2_acc_s *) BFA_FCXP_RSP_PLD(fcxp);
2938 if (rpsc2_acc->els_cmd == FC_ELS_ACC) {
2939 rport->stats.rpsc_accs++;
2940 num_ents = be16_to_cpu(rpsc2_acc->num_pids);
2941 bfa_trc(rport->fcs, num_ents);
2943 WARN_ON(rpsc2_acc->port_info[0].pid == rport->pid);
2945 be16_to_cpu(rpsc2_acc->port_info[0].pid));
2947 be16_to_cpu(rpsc2_acc->port_info[0].speed));
2949 be16_to_cpu(rpsc2_acc->port_info[0].index));
2951 rpsc2_acc->port_info[0].type);
2953 if (rpsc2_acc->port_info[0].speed == 0) {
2954 bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);
2958 rpf->rpsc_speed = fc_rpsc_operspeed_to_bfa_speed(
2959 be16_to_cpu(rpsc2_acc->port_info[0].speed));
2961 bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_COMP);
2964 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
2965 bfa_trc(rport->fcs, ls_rjt->reason_code);
2966 bfa_trc(rport->fcs, ls_rjt->reason_code_expl);
2967 rport->stats.rpsc_rejects++;
2968 if (ls_rjt->reason_code == FC_LS_RJT_RSN_CMD_NOT_SUPP)
2969 bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_FAIL);
2971 bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);