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:
267 * Ignore, SCN is possibly online notification.
271 case RPSM_EVENT_ADDRESS_CHANGE:
272 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
273 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
274 rport->ns_retries = 0;
275 bfa_fcs_rport_send_nsdisc(rport, NULL);
278 case RPSM_EVENT_LOGO_IMP:
280 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
281 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
282 bfa_timer_start(rport->fcs->bfa, &rport->timer,
283 bfa_fcs_rport_timeout, rport,
284 bfa_fcs_rport_del_timeout);
287 case RPSM_EVENT_HCB_OFFLINE:
289 * Ignore BFA callback, on a PLOGI receive we call bfa offline.
294 bfa_sm_fault(rport->fcs, event);
302 bfa_fcs_rport_sm_plogi_retry(struct bfa_fcs_rport_s *rport,
303 enum rport_event event)
305 bfa_trc(rport->fcs, rport->pwwn);
306 bfa_trc(rport->fcs, rport->pid);
307 bfa_trc(rport->fcs, event);
310 case RPSM_EVENT_TIMEOUT:
311 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
312 bfa_fcs_rport_send_plogi(rport, NULL);
315 case RPSM_EVENT_DELETE:
316 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
317 bfa_timer_stop(&rport->timer);
318 bfa_fcs_rport_free(rport);
321 case RPSM_EVENT_PRLO_RCVD:
322 case RPSM_EVENT_LOGO_RCVD:
325 case RPSM_EVENT_PLOGI_RCVD:
326 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
327 bfa_timer_stop(&rport->timer);
328 bfa_fcs_rport_send_plogiacc(rport, NULL);
331 case RPSM_EVENT_ADDRESS_CHANGE:
333 bfa_timer_stop(&rport->timer);
334 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
335 rport->ns_retries = 0;
336 bfa_fcs_rport_send_nsdisc(rport, NULL);
339 case RPSM_EVENT_LOGO_IMP:
341 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
342 bfa_timer_stop(&rport->timer);
343 bfa_timer_start(rport->fcs->bfa, &rport->timer,
344 bfa_fcs_rport_timeout, rport,
345 bfa_fcs_rport_del_timeout);
348 case RPSM_EVENT_PLOGI_COMP:
349 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
350 bfa_timer_stop(&rport->timer);
351 bfa_fcs_rport_hal_online(rport);
355 bfa_sm_fault(rport->fcs, event);
363 bfa_fcs_rport_sm_plogi(struct bfa_fcs_rport_s *rport, enum rport_event event)
365 bfa_trc(rport->fcs, rport->pwwn);
366 bfa_trc(rport->fcs, rport->pid);
367 bfa_trc(rport->fcs, event);
370 case RPSM_EVENT_ACCEPTED:
371 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
372 rport->plogi_retries = 0;
373 bfa_fcs_rport_hal_online(rport);
376 case RPSM_EVENT_LOGO_RCVD:
377 bfa_fcs_rport_send_logo_acc(rport);
381 case RPSM_EVENT_PRLO_RCVD:
382 if (rport->prlo == BFA_TRUE)
383 bfa_fcs_rport_send_prlo_acc(rport);
385 bfa_fcxp_discard(rport->fcxp);
389 case RPSM_EVENT_FAILED:
390 if (rport->plogi_retries < BFA_FCS_RPORT_MAX_RETRIES) {
391 rport->plogi_retries++;
392 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_retry);
393 bfa_timer_start(rport->fcs->bfa, &rport->timer,
394 bfa_fcs_rport_timeout, rport,
395 BFA_FCS_RETRY_TIMEOUT);
397 bfa_stats(rport->port, rport_del_max_plogi_retry);
399 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
400 bfa_timer_start(rport->fcs->bfa, &rport->timer,
401 bfa_fcs_rport_timeout, rport,
402 bfa_fcs_rport_del_timeout);
406 case RPSM_EVENT_PLOGI_RETRY:
407 rport->plogi_retries = 0;
408 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_retry);
409 bfa_timer_start(rport->fcs->bfa, &rport->timer,
410 bfa_fcs_rport_timeout, rport,
414 case RPSM_EVENT_LOGO_IMP:
416 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
417 bfa_fcxp_discard(rport->fcxp);
418 bfa_timer_start(rport->fcs->bfa, &rport->timer,
419 bfa_fcs_rport_timeout, rport,
420 bfa_fcs_rport_del_timeout);
423 case RPSM_EVENT_ADDRESS_CHANGE:
425 bfa_fcxp_discard(rport->fcxp);
426 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
427 rport->ns_retries = 0;
428 bfa_fcs_rport_send_nsdisc(rport, NULL);
431 case RPSM_EVENT_PLOGI_RCVD:
432 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
433 bfa_fcxp_discard(rport->fcxp);
434 bfa_fcs_rport_send_plogiacc(rport, NULL);
437 case RPSM_EVENT_DELETE:
438 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
439 bfa_fcxp_discard(rport->fcxp);
440 bfa_fcs_rport_free(rport);
443 case RPSM_EVENT_PLOGI_COMP:
444 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
445 bfa_fcxp_discard(rport->fcxp);
446 bfa_fcs_rport_hal_online(rport);
450 bfa_sm_fault(rport->fcs, event);
455 * PLOGI is complete. Awaiting BFA rport online callback. FC-4s
459 bfa_fcs_rport_sm_hal_online(struct bfa_fcs_rport_s *rport,
460 enum rport_event event)
462 bfa_trc(rport->fcs, rport->pwwn);
463 bfa_trc(rport->fcs, rport->pid);
464 bfa_trc(rport->fcs, event);
467 case RPSM_EVENT_HCB_ONLINE:
468 bfa_sm_set_state(rport, bfa_fcs_rport_sm_online);
469 bfa_fcs_rport_online_action(rport);
472 case RPSM_EVENT_PRLO_RCVD:
475 case RPSM_EVENT_LOGO_RCVD:
476 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logorcv);
477 bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE);
480 case RPSM_EVENT_LOGO_IMP:
481 case RPSM_EVENT_ADDRESS_CHANGE:
482 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_offline);
483 bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE);
486 case RPSM_EVENT_PLOGI_RCVD:
487 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
488 bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE);
489 bfa_fcs_rport_send_plogiacc(rport, NULL);
492 case RPSM_EVENT_DELETE:
493 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logosend);
494 bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE);
500 * Ignore SCN - PLOGI just completed, FC-4 login should detect
506 bfa_sm_fault(rport->fcs, event);
511 * Rport is ONLINE. FC-4s active.
514 bfa_fcs_rport_sm_online(struct bfa_fcs_rport_s *rport, enum rport_event event)
516 bfa_trc(rport->fcs, rport->pwwn);
517 bfa_trc(rport->fcs, rport->pid);
518 bfa_trc(rport->fcs, event);
522 if (bfa_fcs_fabric_is_switched(rport->port->fabric)) {
523 bfa_sm_set_state(rport,
524 bfa_fcs_rport_sm_nsquery_sending);
525 rport->ns_retries = 0;
526 bfa_fcs_rport_send_nsdisc(rport, NULL);
528 bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc_sending);
529 bfa_fcs_rport_send_adisc(rport, NULL);
533 case RPSM_EVENT_PLOGI_RCVD:
534 case RPSM_EVENT_LOGO_IMP:
535 case RPSM_EVENT_ADDRESS_CHANGE:
536 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
537 bfa_fcs_rport_offline_action(rport);
540 case RPSM_EVENT_DELETE:
541 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
542 bfa_fcs_rport_offline_action(rport);
545 case RPSM_EVENT_LOGO_RCVD:
546 case RPSM_EVENT_PRLO_RCVD:
547 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
548 bfa_fcs_rport_offline_action(rport);
551 case RPSM_EVENT_PLOGI_COMP:
555 bfa_sm_fault(rport->fcs, event);
560 * An SCN event is received in ONLINE state. NS query is being sent
561 * prior to ADISC authentication with rport. FC-4s are paused.
564 bfa_fcs_rport_sm_nsquery_sending(struct bfa_fcs_rport_s *rport,
565 enum rport_event event)
567 bfa_trc(rport->fcs, rport->pwwn);
568 bfa_trc(rport->fcs, rport->pid);
569 bfa_trc(rport->fcs, event);
572 case RPSM_EVENT_FCXP_SENT:
573 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsquery);
576 case RPSM_EVENT_DELETE:
577 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
578 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
579 bfa_fcs_rport_offline_action(rport);
584 * ignore SCN, wait for response to query itself
588 case RPSM_EVENT_LOGO_RCVD:
589 case RPSM_EVENT_PRLO_RCVD:
590 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
591 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
592 bfa_fcs_rport_offline_action(rport);
595 case RPSM_EVENT_LOGO_IMP:
597 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
598 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
599 bfa_timer_start(rport->fcs->bfa, &rport->timer,
600 bfa_fcs_rport_timeout, rport,
601 bfa_fcs_rport_del_timeout);
604 case RPSM_EVENT_PLOGI_RCVD:
605 case RPSM_EVENT_ADDRESS_CHANGE:
606 case RPSM_EVENT_PLOGI_COMP:
607 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
608 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
609 bfa_fcs_rport_offline_action(rport);
613 bfa_sm_fault(rport->fcs, event);
618 * An SCN event is received in ONLINE state. NS query is sent to rport.
622 bfa_fcs_rport_sm_nsquery(struct bfa_fcs_rport_s *rport, enum rport_event event)
624 bfa_trc(rport->fcs, rport->pwwn);
625 bfa_trc(rport->fcs, rport->pid);
626 bfa_trc(rport->fcs, event);
629 case RPSM_EVENT_ACCEPTED:
630 bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc_sending);
631 bfa_fcs_rport_send_adisc(rport, NULL);
634 case RPSM_EVENT_FAILED:
636 if (rport->ns_retries < BFA_FCS_RPORT_MAX_RETRIES) {
637 bfa_sm_set_state(rport,
638 bfa_fcs_rport_sm_nsquery_sending);
639 bfa_fcs_rport_send_nsdisc(rport, NULL);
641 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
642 bfa_fcs_rport_offline_action(rport);
646 case RPSM_EVENT_DELETE:
647 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
648 bfa_fcxp_discard(rport->fcxp);
649 bfa_fcs_rport_offline_action(rport);
655 case RPSM_EVENT_LOGO_RCVD:
656 case RPSM_EVENT_PRLO_RCVD:
657 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
658 bfa_fcxp_discard(rport->fcxp);
659 bfa_fcs_rport_offline_action(rport);
662 case RPSM_EVENT_PLOGI_COMP:
663 case RPSM_EVENT_ADDRESS_CHANGE:
664 case RPSM_EVENT_PLOGI_RCVD:
665 case RPSM_EVENT_LOGO_IMP:
666 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
667 bfa_fcxp_discard(rport->fcxp);
668 bfa_fcs_rport_offline_action(rport);
672 bfa_sm_fault(rport->fcs, event);
677 * An SCN event is received in ONLINE state. ADISC is being sent for
678 * authenticating with rport. FC-4s are paused.
681 bfa_fcs_rport_sm_adisc_sending(struct bfa_fcs_rport_s *rport,
682 enum rport_event event)
684 bfa_trc(rport->fcs, rport->pwwn);
685 bfa_trc(rport->fcs, rport->pid);
686 bfa_trc(rport->fcs, event);
689 case RPSM_EVENT_FCXP_SENT:
690 bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc);
693 case RPSM_EVENT_DELETE:
694 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
695 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
696 bfa_fcs_rport_offline_action(rport);
699 case RPSM_EVENT_LOGO_IMP:
700 case RPSM_EVENT_ADDRESS_CHANGE:
701 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
702 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
703 bfa_fcs_rport_offline_action(rport);
706 case RPSM_EVENT_LOGO_RCVD:
707 case RPSM_EVENT_PRLO_RCVD:
708 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
709 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
710 bfa_fcs_rport_offline_action(rport);
716 case RPSM_EVENT_PLOGI_RCVD:
717 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
718 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
719 bfa_fcs_rport_offline_action(rport);
723 bfa_sm_fault(rport->fcs, event);
728 * An SCN event is received in ONLINE state. ADISC is to rport.
732 bfa_fcs_rport_sm_adisc(struct bfa_fcs_rport_s *rport, enum rport_event event)
734 bfa_trc(rport->fcs, rport->pwwn);
735 bfa_trc(rport->fcs, rport->pid);
736 bfa_trc(rport->fcs, event);
739 case RPSM_EVENT_ACCEPTED:
740 bfa_sm_set_state(rport, bfa_fcs_rport_sm_online);
743 case RPSM_EVENT_PLOGI_RCVD:
745 * Too complex to cleanup FC-4 & rport and then acc to PLOGI.
746 * At least go offline when a PLOGI is received.
748 bfa_fcxp_discard(rport->fcxp);
750 * !!! fall through !!!
753 case RPSM_EVENT_FAILED:
754 case RPSM_EVENT_ADDRESS_CHANGE:
755 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
756 bfa_fcs_rport_offline_action(rport);
759 case RPSM_EVENT_DELETE:
760 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
761 bfa_fcxp_discard(rport->fcxp);
762 bfa_fcs_rport_offline_action(rport);
767 * already processing RSCN
771 case RPSM_EVENT_LOGO_IMP:
772 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
773 bfa_fcxp_discard(rport->fcxp);
774 bfa_fcs_rport_offline_action(rport);
777 case RPSM_EVENT_LOGO_RCVD:
778 case RPSM_EVENT_PRLO_RCVD:
779 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
780 bfa_fcxp_discard(rport->fcxp);
781 bfa_fcs_rport_offline_action(rport);
785 bfa_sm_fault(rport->fcs, event);
790 * Rport has sent LOGO. Awaiting FC-4 offline completion callback.
793 bfa_fcs_rport_sm_fc4_logorcv(struct bfa_fcs_rport_s *rport,
794 enum rport_event event)
796 bfa_trc(rport->fcs, rport->pwwn);
797 bfa_trc(rport->fcs, rport->pid);
798 bfa_trc(rport->fcs, event);
801 case RPSM_EVENT_FC4_OFFLINE:
802 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logorcv);
803 bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE);
806 case RPSM_EVENT_DELETE:
807 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
810 case RPSM_EVENT_LOGO_RCVD:
811 case RPSM_EVENT_PRLO_RCVD:
812 case RPSM_EVENT_ADDRESS_CHANGE:
816 bfa_sm_fault(rport->fcs, event);
821 * LOGO needs to be sent to rport. Awaiting FC-4 offline completion
825 bfa_fcs_rport_sm_fc4_logosend(struct bfa_fcs_rport_s *rport,
826 enum rport_event event)
828 bfa_trc(rport->fcs, rport->pwwn);
829 bfa_trc(rport->fcs, rport->pid);
830 bfa_trc(rport->fcs, event);
833 case RPSM_EVENT_FC4_OFFLINE:
834 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logosend);
835 bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE);
839 bfa_sm_fault(rport->fcs, event);
844 * Rport is going offline. Awaiting FC-4 offline completion callback.
847 bfa_fcs_rport_sm_fc4_offline(struct bfa_fcs_rport_s *rport,
848 enum rport_event event)
850 bfa_trc(rport->fcs, rport->pwwn);
851 bfa_trc(rport->fcs, rport->pid);
852 bfa_trc(rport->fcs, event);
855 case RPSM_EVENT_FC4_OFFLINE:
856 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_offline);
857 bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE);
861 case RPSM_EVENT_LOGO_IMP:
862 case RPSM_EVENT_LOGO_RCVD:
863 case RPSM_EVENT_PRLO_RCVD:
864 case RPSM_EVENT_ADDRESS_CHANGE:
866 * rport is already going offline.
867 * SCN - ignore and wait till transitioning to offline state
871 case RPSM_EVENT_DELETE:
872 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
876 bfa_sm_fault(rport->fcs, event);
881 * Rport is offline. FC-4s are offline. Awaiting BFA rport offline
885 bfa_fcs_rport_sm_hcb_offline(struct bfa_fcs_rport_s *rport,
886 enum rport_event event)
888 bfa_trc(rport->fcs, rport->pwwn);
889 bfa_trc(rport->fcs, rport->pid);
890 bfa_trc(rport->fcs, event);
893 case RPSM_EVENT_HCB_OFFLINE:
894 case RPSM_EVENT_ADDRESS_CHANGE:
895 if (bfa_fcs_lport_is_online(rport->port)) {
896 if (bfa_fcs_fabric_is_switched(rport->port->fabric)) {
897 bfa_sm_set_state(rport,
898 bfa_fcs_rport_sm_nsdisc_sending);
899 rport->ns_retries = 0;
900 bfa_fcs_rport_send_nsdisc(rport, NULL);
902 bfa_sm_set_state(rport,
903 bfa_fcs_rport_sm_plogi_sending);
904 rport->plogi_retries = 0;
905 bfa_fcs_rport_send_plogi(rport, NULL);
909 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
910 bfa_timer_start(rport->fcs->bfa, &rport->timer,
911 bfa_fcs_rport_timeout, rport,
912 bfa_fcs_rport_del_timeout);
916 case RPSM_EVENT_DELETE:
917 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
918 bfa_fcs_rport_free(rport);
922 case RPSM_EVENT_LOGO_RCVD:
923 case RPSM_EVENT_PRLO_RCVD:
925 * Ignore, already offline.
930 bfa_sm_fault(rport->fcs, event);
935 * Rport is offline. FC-4s are offline. Awaiting BFA rport offline
936 * callback to send LOGO accept.
939 bfa_fcs_rport_sm_hcb_logorcv(struct bfa_fcs_rport_s *rport,
940 enum rport_event event)
942 bfa_trc(rport->fcs, rport->pwwn);
943 bfa_trc(rport->fcs, rport->pid);
944 bfa_trc(rport->fcs, event);
947 case RPSM_EVENT_HCB_OFFLINE:
948 case RPSM_EVENT_ADDRESS_CHANGE:
949 if (rport->pid && (rport->prlo == BFA_TRUE))
950 bfa_fcs_rport_send_prlo_acc(rport);
951 if (rport->pid && (rport->prlo == BFA_FALSE))
952 bfa_fcs_rport_send_logo_acc(rport);
954 * If the lport is online and if the rport is not a well
955 * known address port,
956 * we try to re-discover the r-port.
958 if (bfa_fcs_lport_is_online(rport->port) &&
959 (!BFA_FCS_PID_IS_WKA(rport->pid))) {
960 bfa_sm_set_state(rport,
961 bfa_fcs_rport_sm_nsdisc_sending);
962 rport->ns_retries = 0;
963 bfa_fcs_rport_send_nsdisc(rport, NULL);
966 * if it is not a well known address, reset the
969 if (!BFA_FCS_PID_IS_WKA(rport->pid))
971 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
972 bfa_timer_start(rport->fcs->bfa, &rport->timer,
973 bfa_fcs_rport_timeout, rport,
974 bfa_fcs_rport_del_timeout);
978 case RPSM_EVENT_DELETE:
979 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logosend);
982 case RPSM_EVENT_LOGO_IMP:
983 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_offline);
986 case RPSM_EVENT_LOGO_RCVD:
987 case RPSM_EVENT_PRLO_RCVD:
989 * Ignore - already processing a LOGO.
994 bfa_sm_fault(rport->fcs, event);
999 * Rport is being deleted. FC-4s are offline.
1000 * Awaiting BFA rport offline
1001 * callback to send LOGO.
1004 bfa_fcs_rport_sm_hcb_logosend(struct bfa_fcs_rport_s *rport,
1005 enum rport_event event)
1007 bfa_trc(rport->fcs, rport->pwwn);
1008 bfa_trc(rport->fcs, rport->pid);
1009 bfa_trc(rport->fcs, event);
1012 case RPSM_EVENT_HCB_OFFLINE:
1013 bfa_sm_set_state(rport, bfa_fcs_rport_sm_logo_sending);
1014 bfa_fcs_rport_send_logo(rport, NULL);
1017 case RPSM_EVENT_LOGO_RCVD:
1018 case RPSM_EVENT_PRLO_RCVD:
1019 case RPSM_EVENT_ADDRESS_CHANGE:
1023 bfa_sm_fault(rport->fcs, event);
1028 * Rport is being deleted. FC-4s are offline. LOGO is being sent.
1031 bfa_fcs_rport_sm_logo_sending(struct bfa_fcs_rport_s *rport,
1032 enum rport_event event)
1034 bfa_trc(rport->fcs, rport->pwwn);
1035 bfa_trc(rport->fcs, rport->pid);
1036 bfa_trc(rport->fcs, event);
1039 case RPSM_EVENT_FCXP_SENT:
1040 /* Once LOGO is sent, we donot wait for the response */
1041 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1042 bfa_fcs_rport_free(rport);
1045 case RPSM_EVENT_SCN:
1046 case RPSM_EVENT_ADDRESS_CHANGE:
1049 case RPSM_EVENT_LOGO_RCVD:
1050 case RPSM_EVENT_PRLO_RCVD:
1051 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1052 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
1053 bfa_fcs_rport_free(rport);
1057 bfa_sm_fault(rport->fcs, event);
1062 * Rport is offline. FC-4s are offline. BFA rport is offline.
1063 * Timer active to delete stale rport.
1066 bfa_fcs_rport_sm_offline(struct bfa_fcs_rport_s *rport, enum rport_event event)
1068 bfa_trc(rport->fcs, rport->pwwn);
1069 bfa_trc(rport->fcs, rport->pid);
1070 bfa_trc(rport->fcs, event);
1073 case RPSM_EVENT_TIMEOUT:
1074 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1075 bfa_fcs_rport_free(rport);
1078 case RPSM_EVENT_SCN:
1079 case RPSM_EVENT_ADDRESS_CHANGE:
1080 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
1081 bfa_timer_stop(&rport->timer);
1082 rport->ns_retries = 0;
1083 bfa_fcs_rport_send_nsdisc(rport, NULL);
1086 case RPSM_EVENT_DELETE:
1087 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1088 bfa_timer_stop(&rport->timer);
1089 bfa_fcs_rport_free(rport);
1092 case RPSM_EVENT_PLOGI_RCVD:
1093 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
1094 bfa_timer_stop(&rport->timer);
1095 bfa_fcs_rport_send_plogiacc(rport, NULL);
1098 case RPSM_EVENT_LOGO_RCVD:
1099 case RPSM_EVENT_PRLO_RCVD:
1100 case RPSM_EVENT_LOGO_IMP:
1103 case RPSM_EVENT_PLOGI_COMP:
1104 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
1105 bfa_timer_stop(&rport->timer);
1106 bfa_fcs_rport_hal_online(rport);
1109 case RPSM_EVENT_PLOGI_SEND:
1110 bfa_timer_stop(&rport->timer);
1111 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
1112 rport->plogi_retries = 0;
1113 bfa_fcs_rport_send_plogi(rport, NULL);
1117 bfa_sm_fault(rport->fcs, event);
1122 * Rport address has changed. Nameserver discovery request is being sent.
1125 bfa_fcs_rport_sm_nsdisc_sending(struct bfa_fcs_rport_s *rport,
1126 enum rport_event event)
1128 bfa_trc(rport->fcs, rport->pwwn);
1129 bfa_trc(rport->fcs, rport->pid);
1130 bfa_trc(rport->fcs, event);
1133 case RPSM_EVENT_FCXP_SENT:
1134 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sent);
1137 case RPSM_EVENT_DELETE:
1138 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1139 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
1140 bfa_fcs_rport_free(rport);
1143 case RPSM_EVENT_PLOGI_RCVD:
1144 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
1145 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
1146 bfa_fcs_rport_send_plogiacc(rport, NULL);
1149 case RPSM_EVENT_SCN:
1150 case RPSM_EVENT_LOGO_RCVD:
1151 case RPSM_EVENT_PRLO_RCVD:
1152 case RPSM_EVENT_PLOGI_SEND:
1155 case RPSM_EVENT_ADDRESS_CHANGE:
1156 rport->ns_retries = 0; /* reset the retry count */
1159 case RPSM_EVENT_LOGO_IMP:
1160 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
1161 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
1162 bfa_timer_start(rport->fcs->bfa, &rport->timer,
1163 bfa_fcs_rport_timeout, rport,
1164 bfa_fcs_rport_del_timeout);
1167 case RPSM_EVENT_PLOGI_COMP:
1168 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
1169 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
1170 bfa_fcs_rport_hal_online(rport);
1174 bfa_sm_fault(rport->fcs, event);
1179 * Nameserver discovery failed. Waiting for timeout to retry.
1182 bfa_fcs_rport_sm_nsdisc_retry(struct bfa_fcs_rport_s *rport,
1183 enum rport_event event)
1185 bfa_trc(rport->fcs, rport->pwwn);
1186 bfa_trc(rport->fcs, rport->pid);
1187 bfa_trc(rport->fcs, event);
1190 case RPSM_EVENT_TIMEOUT:
1191 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
1192 bfa_fcs_rport_send_nsdisc(rport, NULL);
1195 case RPSM_EVENT_SCN:
1196 case RPSM_EVENT_ADDRESS_CHANGE:
1197 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
1198 bfa_timer_stop(&rport->timer);
1199 rport->ns_retries = 0;
1200 bfa_fcs_rport_send_nsdisc(rport, NULL);
1203 case RPSM_EVENT_DELETE:
1204 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1205 bfa_timer_stop(&rport->timer);
1206 bfa_fcs_rport_free(rport);
1209 case RPSM_EVENT_PLOGI_RCVD:
1210 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
1211 bfa_timer_stop(&rport->timer);
1212 bfa_fcs_rport_send_plogiacc(rport, NULL);
1215 case RPSM_EVENT_LOGO_IMP:
1217 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
1218 bfa_timer_stop(&rport->timer);
1219 bfa_timer_start(rport->fcs->bfa, &rport->timer,
1220 bfa_fcs_rport_timeout, rport,
1221 bfa_fcs_rport_del_timeout);
1224 case RPSM_EVENT_LOGO_RCVD:
1225 bfa_fcs_rport_send_logo_acc(rport);
1227 case RPSM_EVENT_PRLO_RCVD:
1228 bfa_fcs_rport_send_prlo_acc(rport);
1231 case RPSM_EVENT_PLOGI_COMP:
1232 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
1233 bfa_timer_stop(&rport->timer);
1234 bfa_fcs_rport_hal_online(rport);
1238 bfa_sm_fault(rport->fcs, event);
1243 * Rport address has changed. Nameserver discovery request is sent.
1246 bfa_fcs_rport_sm_nsdisc_sent(struct bfa_fcs_rport_s *rport,
1247 enum rport_event event)
1249 bfa_trc(rport->fcs, rport->pwwn);
1250 bfa_trc(rport->fcs, rport->pid);
1251 bfa_trc(rport->fcs, event);
1254 case RPSM_EVENT_ACCEPTED:
1255 case RPSM_EVENT_ADDRESS_CHANGE:
1257 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
1258 bfa_fcs_rport_send_plogi(rport, NULL);
1260 bfa_sm_set_state(rport,
1261 bfa_fcs_rport_sm_nsdisc_sending);
1262 rport->ns_retries = 0;
1263 bfa_fcs_rport_send_nsdisc(rport, NULL);
1267 case RPSM_EVENT_FAILED:
1268 rport->ns_retries++;
1269 if (rport->ns_retries < BFA_FCS_RPORT_MAX_RETRIES) {
1270 bfa_sm_set_state(rport,
1271 bfa_fcs_rport_sm_nsdisc_sending);
1272 bfa_fcs_rport_send_nsdisc(rport, NULL);
1275 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
1276 bfa_timer_start(rport->fcs->bfa, &rport->timer,
1277 bfa_fcs_rport_timeout, rport,
1278 bfa_fcs_rport_del_timeout);
1282 case RPSM_EVENT_DELETE:
1283 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1284 bfa_fcxp_discard(rport->fcxp);
1285 bfa_fcs_rport_free(rport);
1288 case RPSM_EVENT_PLOGI_RCVD:
1289 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
1290 bfa_fcxp_discard(rport->fcxp);
1291 bfa_fcs_rport_send_plogiacc(rport, NULL);
1294 case RPSM_EVENT_LOGO_IMP:
1296 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
1297 bfa_fcxp_discard(rport->fcxp);
1298 bfa_timer_start(rport->fcs->bfa, &rport->timer,
1299 bfa_fcs_rport_timeout, rport,
1300 bfa_fcs_rport_del_timeout);
1304 case RPSM_EVENT_PRLO_RCVD:
1305 bfa_fcs_rport_send_prlo_acc(rport);
1307 case RPSM_EVENT_SCN:
1309 * ignore, wait for NS query response
1313 case RPSM_EVENT_LOGO_RCVD:
1315 * Not logged-in yet. Accept LOGO.
1317 bfa_fcs_rport_send_logo_acc(rport);
1320 case RPSM_EVENT_PLOGI_COMP:
1321 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
1322 bfa_fcxp_discard(rport->fcxp);
1323 bfa_fcs_rport_hal_online(rport);
1327 bfa_sm_fault(rport->fcs, event);
1334 * fcs_rport_private FCS RPORT provate functions
1338 bfa_fcs_rport_send_plogi(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1340 struct bfa_fcs_rport_s *rport = rport_cbarg;
1341 struct bfa_fcs_lport_s *port = rport->port;
1344 struct bfa_fcxp_s *fcxp;
1346 bfa_trc(rport->fcs, rport->pwwn);
1348 fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
1350 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
1351 bfa_fcs_rport_send_plogi, rport);
1356 len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
1357 bfa_fcs_lport_get_fcid(port), 0,
1358 port->port_cfg.pwwn, port->port_cfg.nwwn,
1359 bfa_fcport_get_maxfrsize(port->fcs->bfa));
1361 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1362 FC_CLASS_3, len, &fchs, bfa_fcs_rport_plogi_response,
1363 (void *)rport, FC_MAX_PDUSZ, FC_ELS_TOV);
1365 rport->stats.plogis++;
1366 bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
1370 bfa_fcs_rport_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1371 bfa_status_t req_status, u32 rsp_len,
1372 u32 resid_len, struct fchs_s *rsp_fchs)
1374 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
1375 struct fc_logi_s *plogi_rsp;
1376 struct fc_ls_rjt_s *ls_rjt;
1377 struct bfa_fcs_rport_s *twin;
1378 struct list_head *qe;
1380 bfa_trc(rport->fcs, rport->pwwn);
1385 if (req_status != BFA_STATUS_OK) {
1386 bfa_trc(rport->fcs, req_status);
1387 rport->stats.plogi_failed++;
1388 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1392 plogi_rsp = (struct fc_logi_s *) BFA_FCXP_RSP_PLD(fcxp);
1395 * Check for failure first.
1397 if (plogi_rsp->els_cmd.els_code != FC_ELS_ACC) {
1398 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
1400 bfa_trc(rport->fcs, ls_rjt->reason_code);
1401 bfa_trc(rport->fcs, ls_rjt->reason_code_expl);
1403 if ((ls_rjt->reason_code == FC_LS_RJT_RSN_UNABLE_TO_PERF_CMD) &&
1404 (ls_rjt->reason_code_expl == FC_LS_RJT_EXP_INSUFF_RES)) {
1405 rport->stats.rjt_insuff_res++;
1406 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RETRY);
1410 rport->stats.plogi_rejects++;
1411 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1416 * PLOGI is complete. Make sure this device is not one of the known
1417 * device with a new FC port address.
1419 list_for_each(qe, &rport->port->rport_q) {
1420 twin = (struct bfa_fcs_rport_s *) qe;
1423 if (!rport->pwwn && (plogi_rsp->port_name == twin->pwwn)) {
1424 bfa_trc(rport->fcs, twin->pid);
1425 bfa_trc(rport->fcs, rport->pid);
1427 /* Update plogi stats in twin */
1428 twin->stats.plogis += rport->stats.plogis;
1429 twin->stats.plogi_rejects +=
1430 rport->stats.plogi_rejects;
1431 twin->stats.plogi_timeouts +=
1432 rport->stats.plogi_timeouts;
1433 twin->stats.plogi_failed +=
1434 rport->stats.plogi_failed;
1435 twin->stats.plogi_rcvd += rport->stats.plogi_rcvd;
1436 twin->stats.plogi_accs++;
1438 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
1440 bfa_fcs_rport_update(twin, plogi_rsp);
1441 twin->pid = rsp_fchs->s_id;
1442 bfa_sm_send_event(twin, RPSM_EVENT_PLOGI_COMP);
1448 * Normal login path -- no evil twins.
1450 rport->stats.plogi_accs++;
1451 bfa_fcs_rport_update(rport, plogi_rsp);
1452 bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
1456 bfa_fcs_rport_send_plogiacc(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1458 struct bfa_fcs_rport_s *rport = rport_cbarg;
1459 struct bfa_fcs_lport_s *port = rport->port;
1462 struct bfa_fcxp_s *fcxp;
1464 bfa_trc(rport->fcs, rport->pwwn);
1465 bfa_trc(rport->fcs, rport->reply_oxid);
1467 fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
1469 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
1470 bfa_fcs_rport_send_plogiacc, rport);
1475 len = fc_plogi_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1476 rport->pid, bfa_fcs_lport_get_fcid(port),
1477 rport->reply_oxid, port->port_cfg.pwwn,
1478 port->port_cfg.nwwn,
1479 bfa_fcport_get_maxfrsize(port->fcs->bfa));
1481 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1482 FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
1484 bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
1488 bfa_fcs_rport_send_adisc(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1490 struct bfa_fcs_rport_s *rport = rport_cbarg;
1491 struct bfa_fcs_lport_s *port = rport->port;
1494 struct bfa_fcxp_s *fcxp;
1496 bfa_trc(rport->fcs, rport->pwwn);
1498 fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
1500 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
1501 bfa_fcs_rport_send_adisc, rport);
1506 len = fc_adisc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
1507 bfa_fcs_lport_get_fcid(port), 0,
1508 port->port_cfg.pwwn, port->port_cfg.nwwn);
1510 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1511 FC_CLASS_3, len, &fchs, bfa_fcs_rport_adisc_response,
1512 rport, FC_MAX_PDUSZ, FC_ELS_TOV);
1514 rport->stats.adisc_sent++;
1515 bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
1519 bfa_fcs_rport_adisc_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1520 bfa_status_t req_status, u32 rsp_len,
1521 u32 resid_len, struct fchs_s *rsp_fchs)
1523 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
1524 void *pld = bfa_fcxp_get_rspbuf(fcxp);
1525 struct fc_ls_rjt_s *ls_rjt;
1527 if (req_status != BFA_STATUS_OK) {
1528 bfa_trc(rport->fcs, req_status);
1529 rport->stats.adisc_failed++;
1530 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1534 if (fc_adisc_rsp_parse((struct fc_adisc_s *)pld, rsp_len, rport->pwwn,
1535 rport->nwwn) == FC_PARSE_OK) {
1536 rport->stats.adisc_accs++;
1537 bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
1541 rport->stats.adisc_rejects++;
1543 bfa_trc(rport->fcs, ls_rjt->els_cmd.els_code);
1544 bfa_trc(rport->fcs, ls_rjt->reason_code);
1545 bfa_trc(rport->fcs, ls_rjt->reason_code_expl);
1546 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1550 bfa_fcs_rport_send_nsdisc(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1552 struct bfa_fcs_rport_s *rport = rport_cbarg;
1553 struct bfa_fcs_lport_s *port = rport->port;
1555 struct bfa_fcxp_s *fcxp;
1557 bfa_cb_fcxp_send_t cbfn;
1559 bfa_trc(rport->fcs, rport->pid);
1561 fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
1563 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
1564 bfa_fcs_rport_send_nsdisc, rport);
1570 len = fc_gidpn_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1571 bfa_fcs_lport_get_fcid(port), 0, rport->pwwn);
1572 cbfn = bfa_fcs_rport_gidpn_response;
1574 len = fc_gpnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1575 bfa_fcs_lport_get_fcid(port), 0, rport->pid);
1576 cbfn = bfa_fcs_rport_gpnid_response;
1579 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1580 FC_CLASS_3, len, &fchs, cbfn,
1581 (void *)rport, FC_MAX_PDUSZ, FC_FCCT_TOV);
1583 bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
1587 bfa_fcs_rport_gidpn_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1588 bfa_status_t req_status, u32 rsp_len,
1589 u32 resid_len, struct fchs_s *rsp_fchs)
1591 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
1592 struct ct_hdr_s *cthdr;
1593 struct fcgs_gidpn_resp_s *gidpn_rsp;
1594 struct bfa_fcs_rport_s *twin;
1595 struct list_head *qe;
1597 bfa_trc(rport->fcs, rport->pwwn);
1599 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
1600 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
1602 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
1603 /* Check if the pid is the same as before. */
1604 gidpn_rsp = (struct fcgs_gidpn_resp_s *) (cthdr + 1);
1606 if (gidpn_rsp->dap == rport->pid) {
1607 /* Device is online */
1608 bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
1611 * Device's PID has changed. We need to cleanup
1612 * and re-login. If there is another device with
1613 * the the newly discovered pid, send an scn notice
1614 * so that its new pid can be discovered.
1616 list_for_each(qe, &rport->port->rport_q) {
1617 twin = (struct bfa_fcs_rport_s *) qe;
1620 if (gidpn_rsp->dap == twin->pid) {
1621 bfa_trc(rport->fcs, twin->pid);
1622 bfa_trc(rport->fcs, rport->pid);
1625 bfa_sm_send_event(twin,
1626 RPSM_EVENT_ADDRESS_CHANGE);
1629 rport->pid = gidpn_rsp->dap;
1630 bfa_sm_send_event(rport, RPSM_EVENT_ADDRESS_CHANGE);
1638 switch (cthdr->reason_code) {
1639 case CT_RSN_LOGICAL_BUSY:
1643 bfa_sm_send_event(rport, RPSM_EVENT_TIMEOUT);
1646 case CT_RSN_UNABLE_TO_PERF:
1648 * device doesn't exist : Start timer to cleanup this later.
1650 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1654 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1660 bfa_fcs_rport_gpnid_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1661 bfa_status_t req_status, u32 rsp_len,
1662 u32 resid_len, struct fchs_s *rsp_fchs)
1664 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
1665 struct ct_hdr_s *cthdr;
1667 bfa_trc(rport->fcs, rport->pwwn);
1669 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
1670 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
1672 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
1673 bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
1680 switch (cthdr->reason_code) {
1681 case CT_RSN_LOGICAL_BUSY:
1685 bfa_sm_send_event(rport, RPSM_EVENT_TIMEOUT);
1688 case CT_RSN_UNABLE_TO_PERF:
1690 * device doesn't exist : Start timer to cleanup this later.
1692 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1696 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1702 * Called to send a logout to the rport.
1705 bfa_fcs_rport_send_logo(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1707 struct bfa_fcs_rport_s *rport = rport_cbarg;
1708 struct bfa_fcs_lport_s *port;
1710 struct bfa_fcxp_s *fcxp;
1713 bfa_trc(rport->fcs, rport->pid);
1717 fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
1719 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
1720 bfa_fcs_rport_send_logo, rport);
1725 len = fc_logo_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
1726 bfa_fcs_lport_get_fcid(port), 0,
1727 bfa_fcs_lport_get_pwwn(port));
1729 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1730 FC_CLASS_3, len, &fchs, NULL,
1731 rport, FC_MAX_PDUSZ, FC_ELS_TOV);
1733 rport->stats.logos++;
1734 bfa_fcxp_discard(rport->fcxp);
1735 bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
1739 * Send ACC for a LOGO received.
1742 bfa_fcs_rport_send_logo_acc(void *rport_cbarg)
1744 struct bfa_fcs_rport_s *rport = rport_cbarg;
1745 struct bfa_fcs_lport_s *port;
1747 struct bfa_fcxp_s *fcxp;
1750 bfa_trc(rport->fcs, rport->pid);
1754 fcxp = bfa_fcs_fcxp_alloc(port->fcs);
1758 rport->stats.logo_rcvd++;
1759 len = fc_logo_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1760 rport->pid, bfa_fcs_lport_get_fcid(port),
1763 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1764 FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
1769 * This routine will be called by bfa_timer on timer timeouts.
1771 * param[in] rport - pointer to bfa_fcs_lport_ns_t.
1772 * param[out] rport_status - pointer to return vport status in
1777 * Special Considerations:
1782 bfa_fcs_rport_timeout(void *arg)
1784 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) arg;
1786 rport->stats.plogi_timeouts++;
1787 bfa_stats(rport->port, rport_plogi_timeouts);
1788 bfa_sm_send_event(rport, RPSM_EVENT_TIMEOUT);
1792 bfa_fcs_rport_process_prli(struct bfa_fcs_rport_s *rport,
1793 struct fchs_s *rx_fchs, u16 len)
1795 struct bfa_fcxp_s *fcxp;
1797 struct bfa_fcs_lport_s *port = rport->port;
1798 struct fc_prli_s *prli;
1800 bfa_trc(port->fcs, rx_fchs->s_id);
1801 bfa_trc(port->fcs, rx_fchs->d_id);
1803 rport->stats.prli_rcvd++;
1806 * We are in Initiator Mode
1808 prli = (struct fc_prli_s *) (rx_fchs + 1);
1810 if (prli->parampage.servparams.target) {
1812 * PRLI from a target ?
1814 * PRLI sent by us will be used to transition the IT nexus,
1815 * once the response is received from the target.
1817 bfa_trc(port->fcs, rx_fchs->s_id);
1818 rport->scsi_function = BFA_RPORT_TARGET;
1820 bfa_trc(rport->fcs, prli->parampage.type);
1821 rport->scsi_function = BFA_RPORT_INITIATOR;
1822 bfa_fcs_itnim_is_initiator(rport->itnim);
1825 fcxp = bfa_fcs_fcxp_alloc(port->fcs);
1829 len = fc_prli_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1830 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
1831 rx_fchs->ox_id, port->port_cfg.roles);
1833 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1834 FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
1838 bfa_fcs_rport_process_rpsc(struct bfa_fcs_rport_s *rport,
1839 struct fchs_s *rx_fchs, u16 len)
1841 struct bfa_fcxp_s *fcxp;
1843 struct bfa_fcs_lport_s *port = rport->port;
1844 struct fc_rpsc_speed_info_s speeds;
1845 struct bfa_port_attr_s pport_attr;
1847 bfa_trc(port->fcs, rx_fchs->s_id);
1848 bfa_trc(port->fcs, rx_fchs->d_id);
1850 rport->stats.rpsc_rcvd++;
1851 speeds.port_speed_cap =
1852 RPSC_SPEED_CAP_1G | RPSC_SPEED_CAP_2G | RPSC_SPEED_CAP_4G |
1856 * get curent speed from pport attributes from BFA
1858 bfa_fcport_get_attr(port->fcs->bfa, &pport_attr);
1860 speeds.port_op_speed = fc_bfa_speed_to_rpsc_operspeed(pport_attr.speed);
1862 fcxp = bfa_fcs_fcxp_alloc(port->fcs);
1866 len = fc_rpsc_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1867 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
1868 rx_fchs->ox_id, &speeds);
1870 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1871 FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
1875 bfa_fcs_rport_process_adisc(struct bfa_fcs_rport_s *rport,
1876 struct fchs_s *rx_fchs, u16 len)
1878 struct bfa_fcxp_s *fcxp;
1880 struct bfa_fcs_lport_s *port = rport->port;
1881 struct fc_adisc_s *adisc;
1883 bfa_trc(port->fcs, rx_fchs->s_id);
1884 bfa_trc(port->fcs, rx_fchs->d_id);
1886 rport->stats.adisc_rcvd++;
1888 adisc = (struct fc_adisc_s *) (rx_fchs + 1);
1891 * Accept if the itnim for this rport is online.
1892 * Else reject the ADISC.
1894 if (bfa_fcs_itnim_get_online_state(rport->itnim) == BFA_STATUS_OK) {
1896 fcxp = bfa_fcs_fcxp_alloc(port->fcs);
1900 len = fc_adisc_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1901 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
1902 rx_fchs->ox_id, port->port_cfg.pwwn,
1903 port->port_cfg.nwwn);
1905 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag,
1906 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
1909 rport->stats.adisc_rejected++;
1910 bfa_fcs_rport_send_ls_rjt(rport, rx_fchs,
1911 FC_LS_RJT_RSN_UNABLE_TO_PERF_CMD,
1912 FC_LS_RJT_EXP_LOGIN_REQUIRED);
1917 bfa_fcs_rport_hal_online(struct bfa_fcs_rport_s *rport)
1919 struct bfa_fcs_lport_s *port = rport->port;
1920 struct bfa_rport_info_s rport_info;
1922 rport_info.pid = rport->pid;
1923 rport_info.local_pid = port->pid;
1924 rport_info.lp_tag = port->lp_tag;
1925 rport_info.vf_id = port->fabric->vf_id;
1926 rport_info.vf_en = port->fabric->is_vf;
1927 rport_info.fc_class = rport->fc_cos;
1928 rport_info.cisc = rport->cisc;
1929 rport_info.max_frmsz = rport->maxfrsize;
1930 bfa_rport_online(rport->bfa_rport, &rport_info);
1933 static struct bfa_fcs_rport_s *
1934 bfa_fcs_rport_alloc(struct bfa_fcs_lport_s *port, wwn_t pwwn, u32 rpid)
1936 struct bfa_fcs_s *fcs = port->fcs;
1937 struct bfa_fcs_rport_s *rport;
1938 struct bfad_rport_s *rport_drv;
1943 if (bfa_fcb_rport_alloc(fcs->bfad, &rport, &rport_drv)
1954 rport->rp_drv = rport_drv;
1959 * allocate BFA rport
1961 rport->bfa_rport = bfa_rport_create(port->fcs->bfa, rport);
1962 if (!rport->bfa_rport) {
1971 bfa_assert(bfa_fcs_lport_is_initiator(port));
1973 if (bfa_fcs_lport_is_initiator(port)) {
1974 rport->itnim = bfa_fcs_itnim_create(rport);
1975 if (!rport->itnim) {
1977 bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_DELETE);
1983 bfa_fcs_lport_add_rport(port, rport);
1985 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1987 /* Initialize the Rport Features(RPF) Sub Module */
1988 if (!BFA_FCS_PID_IS_WKA(rport->pid))
1989 bfa_fcs_rpf_init(rport);
1996 bfa_fcs_rport_free(struct bfa_fcs_rport_s *rport)
1998 struct bfa_fcs_lport_s *port = rport->port;
2002 * - delete BFA rport
2003 * - remove from queue of rports
2005 if (bfa_fcs_lport_is_initiator(port)) {
2006 bfa_fcs_itnim_delete(rport->itnim);
2007 if (rport->pid != 0 && !BFA_FCS_PID_IS_WKA(rport->pid))
2008 bfa_fcs_rpf_rport_offline(rport);
2011 bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_DELETE);
2012 bfa_fcs_lport_del_rport(port, rport);
2013 kfree(rport->rp_drv);
2017 bfa_fcs_rport_online_action(struct bfa_fcs_rport_s *rport)
2019 struct bfa_fcs_lport_s *port = rport->port;
2020 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
2021 char lpwwn_buf[BFA_STRING_32];
2022 char rpwwn_buf[BFA_STRING_32];
2024 rport->stats.onlines++;
2026 if (bfa_fcs_lport_is_initiator(port)) {
2027 bfa_fcs_itnim_rport_online(rport->itnim);
2028 if (!BFA_FCS_PID_IS_WKA(rport->pid))
2029 bfa_fcs_rpf_rport_online(rport);
2032 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
2033 wwn2str(rpwwn_buf, rport->pwwn);
2034 if (!BFA_FCS_PID_IS_WKA(rport->pid))
2035 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
2036 "Remote port (WWN = %s) online for logical port (WWN = %s)\n",
2037 rpwwn_buf, lpwwn_buf);
2041 bfa_fcs_rport_offline_action(struct bfa_fcs_rport_s *rport)
2043 struct bfa_fcs_lport_s *port = rport->port;
2044 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
2045 char lpwwn_buf[BFA_STRING_32];
2046 char rpwwn_buf[BFA_STRING_32];
2048 rport->stats.offlines++;
2050 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
2051 wwn2str(rpwwn_buf, rport->pwwn);
2052 if (!BFA_FCS_PID_IS_WKA(rport->pid)) {
2053 if (bfa_fcs_lport_is_online(rport->port) == BFA_TRUE)
2054 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
2055 "Remote port (WWN = %s) connectivity lost for "
2056 "logical port (WWN = %s)\n",
2057 rpwwn_buf, lpwwn_buf);
2059 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
2060 "Remote port (WWN = %s) offlined by "
2061 "logical port (WWN = %s)\n",
2062 rpwwn_buf, lpwwn_buf);
2065 if (bfa_fcs_lport_is_initiator(port)) {
2066 bfa_fcs_itnim_rport_offline(rport->itnim);
2067 if (!BFA_FCS_PID_IS_WKA(rport->pid))
2068 bfa_fcs_rpf_rport_offline(rport);
2073 * Update rport parameters from PLOGI or PLOGI accept.
2076 bfa_fcs_rport_update(struct bfa_fcs_rport_s *rport, struct fc_logi_s *plogi)
2078 bfa_fcs_lport_t *port = rport->port;
2084 rport->pwwn = plogi->port_name;
2085 rport->nwwn = plogi->node_name;
2088 * - class of service
2091 if (plogi->class3.class_valid)
2092 rport->fc_cos = FC_CLASS_3;
2094 if (plogi->class2.class_valid)
2095 rport->fc_cos |= FC_CLASS_2;
2099 * - MAX receive frame size
2101 rport->cisc = plogi->csp.cisc;
2102 rport->maxfrsize = be16_to_cpu(plogi->class3.rxsz);
2104 bfa_trc(port->fcs, be16_to_cpu(plogi->csp.bbcred));
2105 bfa_trc(port->fcs, port->fabric->bb_credit);
2107 * Direct Attach P2P mode :
2108 * This is to handle a bug (233476) in IBM targets in Direct Attach
2109 * Mode. Basically, in FLOGI Accept the target would have
2110 * erroneously set the BB Credit to the value used in the FLOGI
2111 * sent by the HBA. It uses the correct value (its own BB credit)
2114 if ((!bfa_fcs_fabric_is_switched(port->fabric)) &&
2115 (be16_to_cpu(plogi->csp.bbcred) < port->fabric->bb_credit)) {
2117 bfa_trc(port->fcs, be16_to_cpu(plogi->csp.bbcred));
2118 bfa_trc(port->fcs, port->fabric->bb_credit);
2120 port->fabric->bb_credit = be16_to_cpu(plogi->csp.bbcred);
2121 bfa_fcport_set_tx_bbcredit(port->fcs->bfa,
2122 port->fabric->bb_credit);
2128 * Called to handle LOGO received from an existing remote port.
2131 bfa_fcs_rport_process_logo(struct bfa_fcs_rport_s *rport, struct fchs_s *fchs)
2133 rport->reply_oxid = fchs->ox_id;
2134 bfa_trc(rport->fcs, rport->reply_oxid);
2136 rport->prlo = BFA_FALSE;
2137 rport->stats.logo_rcvd++;
2138 bfa_sm_send_event(rport, RPSM_EVENT_LOGO_RCVD);
2144 * fcs_rport_public FCS rport public interfaces
2148 * Called by bport/vport to create a remote port instance for a discovered
2151 * @param[in] port - base port or vport
2152 * @param[in] rpid - remote port ID
2156 struct bfa_fcs_rport_s *
2157 bfa_fcs_rport_create(struct bfa_fcs_lport_s *port, u32 rpid)
2159 struct bfa_fcs_rport_s *rport;
2161 bfa_trc(port->fcs, rpid);
2162 rport = bfa_fcs_rport_alloc(port, WWN_NULL, rpid);
2166 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_SEND);
2171 * Called to create a rport for which only the wwn is known.
2173 * @param[in] port - base port
2174 * @param[in] rpwwn - remote port wwn
2178 struct bfa_fcs_rport_s *
2179 bfa_fcs_rport_create_by_wwn(struct bfa_fcs_lport_s *port, wwn_t rpwwn)
2181 struct bfa_fcs_rport_s *rport;
2182 bfa_trc(port->fcs, rpwwn);
2183 rport = bfa_fcs_rport_alloc(port, rpwwn, 0);
2187 bfa_sm_send_event(rport, RPSM_EVENT_ADDRESS_DISC);
2191 * Called by bport in private loop topology to indicate that a
2192 * rport has been discovered and plogi has been completed.
2194 * @param[in] port - base port or vport
2195 * @param[in] rpid - remote port ID
2198 bfa_fcs_rport_start(struct bfa_fcs_lport_s *port, struct fchs_s *fchs,
2199 struct fc_logi_s *plogi)
2201 struct bfa_fcs_rport_s *rport;
2203 rport = bfa_fcs_rport_alloc(port, WWN_NULL, fchs->s_id);
2207 bfa_fcs_rport_update(rport, plogi);
2209 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_COMP);
2213 * Called by bport/vport to handle PLOGI received from a new remote port.
2214 * If an existing rport does a plogi, it will be handled separately.
2217 bfa_fcs_rport_plogi_create(struct bfa_fcs_lport_s *port, struct fchs_s *fchs,
2218 struct fc_logi_s *plogi)
2220 struct bfa_fcs_rport_s *rport;
2222 rport = bfa_fcs_rport_alloc(port, plogi->port_name, fchs->s_id);
2226 bfa_fcs_rport_update(rport, plogi);
2228 rport->reply_oxid = fchs->ox_id;
2229 bfa_trc(rport->fcs, rport->reply_oxid);
2231 rport->stats.plogi_rcvd++;
2232 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RCVD);
2236 wwn_compare(wwn_t wwn1, wwn_t wwn2)
2238 u8 *b1 = (u8 *) &wwn1;
2239 u8 *b2 = (u8 *) &wwn2;
2242 for (i = 0; i < sizeof(wwn_t); i++) {
2252 * Called by bport/vport to handle PLOGI received from an existing
2256 bfa_fcs_rport_plogi(struct bfa_fcs_rport_s *rport, struct fchs_s *rx_fchs,
2257 struct fc_logi_s *plogi)
2260 * @todo Handle P2P and initiator-initiator.
2263 bfa_fcs_rport_update(rport, plogi);
2265 rport->reply_oxid = rx_fchs->ox_id;
2266 bfa_trc(rport->fcs, rport->reply_oxid);
2269 * In Switched fabric topology,
2270 * PLOGI to each other. If our pwwn is smaller, ignore it,
2271 * if it is not a well known address.
2272 * If the link topology is N2N,
2273 * this Plogi should be accepted.
2275 if ((wwn_compare(rport->port->port_cfg.pwwn, rport->pwwn) == -1) &&
2276 (bfa_fcs_fabric_is_switched(rport->port->fabric)) &&
2277 (!BFA_FCS_PID_IS_WKA(rport->pid))) {
2278 bfa_trc(rport->fcs, rport->pid);
2282 rport->stats.plogi_rcvd++;
2283 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RCVD);
2288 * Called by bport/vport to notify SCN for the remote port
2291 bfa_fcs_rport_scn(struct bfa_fcs_rport_s *rport)
2293 rport->stats.rscns++;
2294 bfa_sm_send_event(rport, RPSM_EVENT_SCN);
2300 * This routine BFA callback for bfa_rport_online() call.
2302 * param[in] cb_arg - rport struct.
2307 * Special Considerations:
2312 bfa_cb_rport_online(void *cbarg)
2315 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
2317 bfa_trc(rport->fcs, rport->pwwn);
2318 bfa_sm_send_event(rport, RPSM_EVENT_HCB_ONLINE);
2323 * This routine BFA callback for bfa_rport_offline() call.
2330 * Special Considerations:
2335 bfa_cb_rport_offline(void *cbarg)
2337 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
2339 bfa_trc(rport->fcs, rport->pwwn);
2340 bfa_sm_send_event(rport, RPSM_EVENT_HCB_OFFLINE);
2345 * This routine is a static BFA callback when there is a QoS flow_id
2346 * change notification
2353 * Special Considerations:
2358 bfa_cb_rport_qos_scn_flowid(void *cbarg,
2359 struct bfa_rport_qos_attr_s old_qos_attr,
2360 struct bfa_rport_qos_attr_s new_qos_attr)
2362 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
2364 bfa_trc(rport->fcs, rport->pwwn);
2369 * This routine is a static BFA callback when there is a QoS priority
2370 * change notification
2377 * Special Considerations:
2382 bfa_cb_rport_qos_scn_prio(void *cbarg,
2383 struct bfa_rport_qos_attr_s old_qos_attr,
2384 struct bfa_rport_qos_attr_s new_qos_attr)
2386 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
2388 bfa_trc(rport->fcs, rport->pwwn);
2392 * Called to process any unsolicted frames from this remote port
2395 bfa_fcs_rport_uf_recv(struct bfa_fcs_rport_s *rport,
2396 struct fchs_s *fchs, u16 len)
2398 struct bfa_fcs_lport_s *port = rport->port;
2399 struct fc_els_cmd_s *els_cmd;
2401 bfa_trc(rport->fcs, fchs->s_id);
2402 bfa_trc(rport->fcs, fchs->d_id);
2403 bfa_trc(rport->fcs, fchs->type);
2405 if (fchs->type != FC_TYPE_ELS)
2408 els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
2410 bfa_trc(rport->fcs, els_cmd->els_code);
2412 switch (els_cmd->els_code) {
2414 bfa_stats(port, plogi_rcvd);
2415 bfa_fcs_rport_process_logo(rport, fchs);
2419 bfa_stats(port, adisc_rcvd);
2420 bfa_fcs_rport_process_adisc(rport, fchs, len);
2424 bfa_stats(port, prlo_rcvd);
2425 if (bfa_fcs_lport_is_initiator(port))
2426 bfa_fcs_fcpim_uf_recv(rport->itnim, fchs, len);
2430 bfa_stats(port, prli_rcvd);
2431 bfa_fcs_rport_process_prli(rport, fchs, len);
2435 bfa_stats(port, rpsc_rcvd);
2436 bfa_fcs_rport_process_rpsc(rport, fchs, len);
2440 bfa_stats(port, un_handled_els_rcvd);
2441 bfa_fcs_rport_send_ls_rjt(rport, fchs,
2442 FC_LS_RJT_RSN_CMD_NOT_SUPP,
2443 FC_LS_RJT_EXP_NO_ADDL_INFO);
2448 /* send best case acc to prlo */
2450 bfa_fcs_rport_send_prlo_acc(struct bfa_fcs_rport_s *rport)
2452 struct bfa_fcs_lport_s *port = rport->port;
2454 struct bfa_fcxp_s *fcxp;
2457 bfa_trc(rport->fcs, rport->pid);
2459 fcxp = bfa_fcs_fcxp_alloc(port->fcs);
2462 len = fc_prlo_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
2463 rport->pid, bfa_fcs_lport_get_fcid(port),
2464 rport->reply_oxid, 0);
2466 bfa_fcxp_send(fcxp, rport->bfa_rport, port->fabric->vf_id,
2467 port->lp_tag, BFA_FALSE, FC_CLASS_3, len, &fchs,
2468 NULL, NULL, FC_MAX_PDUSZ, 0);
2475 bfa_fcs_rport_send_ls_rjt(struct bfa_fcs_rport_s *rport, struct fchs_s *rx_fchs,
2476 u8 reason_code, u8 reason_code_expl)
2478 struct bfa_fcs_lport_s *port = rport->port;
2480 struct bfa_fcxp_s *fcxp;
2483 bfa_trc(rport->fcs, rx_fchs->s_id);
2485 fcxp = bfa_fcs_fcxp_alloc(rport->fcs);
2489 len = fc_ls_rjt_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
2490 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
2491 rx_fchs->ox_id, reason_code, reason_code_expl);
2493 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag,
2494 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
2499 * Return state of rport.
2502 bfa_fcs_rport_get_state(struct bfa_fcs_rport_s *rport)
2504 return bfa_sm_to_state(rport_sm_table, rport->sm);
2510 * Called by the Driver to set rport delete/ageout timeout
2512 * param[in] rport timeout value in seconds.
2517 bfa_fcs_rport_set_del_timeout(u8 rport_tmo)
2519 /* convert to Millisecs */
2521 bfa_fcs_rport_del_timeout = rport_tmo * 1000;
2524 bfa_fcs_rport_prlo(struct bfa_fcs_rport_s *rport, __be16 ox_id)
2526 bfa_trc(rport->fcs, rport->pid);
2528 rport->prlo = BFA_TRUE;
2529 rport->reply_oxid = ox_id;
2530 bfa_sm_send_event(rport, RPSM_EVENT_PRLO_RCVD);
2536 * Remote port implementation.
2540 * fcs_rport_api FCS rport API.
2543 struct bfa_fcs_rport_s *
2544 bfa_fcs_rport_lookup(struct bfa_fcs_lport_s *port, wwn_t rpwwn)
2546 struct bfa_fcs_rport_s *rport;
2548 rport = bfa_fcs_lport_get_rport_by_pwwn(port, rpwwn);
2549 if (rport == NULL) {
2551 * TBD Error handling
2558 struct bfa_fcs_rport_s *
2559 bfa_fcs_rport_lookup_by_nwwn(struct bfa_fcs_lport_s *port, wwn_t rnwwn)
2561 struct bfa_fcs_rport_s *rport;
2563 rport = bfa_fcs_lport_get_rport_by_nwwn(port, rnwwn);
2564 if (rport == NULL) {
2566 * TBD Error handling
2574 * Remote port features (RPF) implementation.
2577 #define BFA_FCS_RPF_RETRIES (3)
2578 #define BFA_FCS_RPF_RETRY_TIMEOUT (1000) /* 1 sec (In millisecs) */
2580 static void bfa_fcs_rpf_send_rpsc2(void *rport_cbarg,
2581 struct bfa_fcxp_s *fcxp_alloced);
2582 static void bfa_fcs_rpf_rpsc2_response(void *fcsarg,
2583 struct bfa_fcxp_s *fcxp,
2585 bfa_status_t req_status,
2588 struct fchs_s *rsp_fchs);
2590 static void bfa_fcs_rpf_timeout(void *arg);
2593 * fcs_rport_ftrs_sm FCS rport state machine events
2597 RPFSM_EVENT_RPORT_OFFLINE = 1, /* Rport offline */
2598 RPFSM_EVENT_RPORT_ONLINE = 2, /* Rport online */
2599 RPFSM_EVENT_FCXP_SENT = 3, /* Frame from has been sent */
2600 RPFSM_EVENT_TIMEOUT = 4, /* Rport SM timeout event */
2601 RPFSM_EVENT_RPSC_COMP = 5,
2602 RPFSM_EVENT_RPSC_FAIL = 6,
2603 RPFSM_EVENT_RPSC_ERROR = 7,
2606 static void bfa_fcs_rpf_sm_uninit(struct bfa_fcs_rpf_s *rpf,
2607 enum rpf_event event);
2608 static void bfa_fcs_rpf_sm_rpsc_sending(struct bfa_fcs_rpf_s *rpf,
2609 enum rpf_event event);
2610 static void bfa_fcs_rpf_sm_rpsc(struct bfa_fcs_rpf_s *rpf,
2611 enum rpf_event event);
2612 static void bfa_fcs_rpf_sm_rpsc_retry(struct bfa_fcs_rpf_s *rpf,
2613 enum rpf_event event);
2614 static void bfa_fcs_rpf_sm_offline(struct bfa_fcs_rpf_s *rpf,
2615 enum rpf_event event);
2616 static void bfa_fcs_rpf_sm_online(struct bfa_fcs_rpf_s *rpf,
2617 enum rpf_event event);
2620 bfa_fcs_rpf_sm_uninit(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
2622 struct bfa_fcs_rport_s *rport = rpf->rport;
2623 struct bfa_fcs_fabric_s *fabric = &rport->fcs->fabric;
2625 bfa_trc(rport->fcs, rport->pwwn);
2626 bfa_trc(rport->fcs, rport->pid);
2627 bfa_trc(rport->fcs, event);
2630 case RPFSM_EVENT_RPORT_ONLINE:
2631 /* Send RPSC2 to a Brocade fabric only. */
2632 if ((!BFA_FCS_PID_IS_WKA(rport->pid)) &&
2633 ((rport->port->fabric->lps->brcd_switch) ||
2634 (bfa_fcs_fabric_get_switch_oui(fabric) ==
2635 BFA_FCS_BRCD_SWITCH_OUI))) {
2636 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
2637 rpf->rpsc_retries = 0;
2638 bfa_fcs_rpf_send_rpsc2(rpf, NULL);
2642 case RPFSM_EVENT_RPORT_OFFLINE:
2646 bfa_sm_fault(rport->fcs, event);
2651 bfa_fcs_rpf_sm_rpsc_sending(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
2653 struct bfa_fcs_rport_s *rport = rpf->rport;
2655 bfa_trc(rport->fcs, event);
2658 case RPFSM_EVENT_FCXP_SENT:
2659 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc);
2662 case RPFSM_EVENT_RPORT_OFFLINE:
2663 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
2664 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rpf->fcxp_wqe);
2665 rpf->rpsc_retries = 0;
2669 bfa_sm_fault(rport->fcs, event);
2674 bfa_fcs_rpf_sm_rpsc(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
2676 struct bfa_fcs_rport_s *rport = rpf->rport;
2678 bfa_trc(rport->fcs, rport->pid);
2679 bfa_trc(rport->fcs, event);
2682 case RPFSM_EVENT_RPSC_COMP:
2683 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
2684 /* Update speed info in f/w via BFA */
2685 if (rpf->rpsc_speed != BFA_PORT_SPEED_UNKNOWN)
2686 bfa_rport_speed(rport->bfa_rport, rpf->rpsc_speed);
2687 else if (rpf->assigned_speed != BFA_PORT_SPEED_UNKNOWN)
2688 bfa_rport_speed(rport->bfa_rport, rpf->assigned_speed);
2691 case RPFSM_EVENT_RPSC_FAIL:
2692 /* RPSC not supported by rport */
2693 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
2696 case RPFSM_EVENT_RPSC_ERROR:
2697 /* need to retry...delayed a bit. */
2698 if (rpf->rpsc_retries++ < BFA_FCS_RPF_RETRIES) {
2699 bfa_timer_start(rport->fcs->bfa, &rpf->timer,
2700 bfa_fcs_rpf_timeout, rpf,
2701 BFA_FCS_RPF_RETRY_TIMEOUT);
2702 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_retry);
2704 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
2708 case RPFSM_EVENT_RPORT_OFFLINE:
2709 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
2710 bfa_fcxp_discard(rpf->fcxp);
2711 rpf->rpsc_retries = 0;
2715 bfa_sm_fault(rport->fcs, event);
2720 bfa_fcs_rpf_sm_rpsc_retry(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
2722 struct bfa_fcs_rport_s *rport = rpf->rport;
2724 bfa_trc(rport->fcs, rport->pid);
2725 bfa_trc(rport->fcs, event);
2728 case RPFSM_EVENT_TIMEOUT:
2729 /* re-send the RPSC */
2730 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
2731 bfa_fcs_rpf_send_rpsc2(rpf, NULL);
2734 case RPFSM_EVENT_RPORT_OFFLINE:
2735 bfa_timer_stop(&rpf->timer);
2736 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
2737 rpf->rpsc_retries = 0;
2741 bfa_sm_fault(rport->fcs, event);
2746 bfa_fcs_rpf_sm_online(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
2748 struct bfa_fcs_rport_s *rport = rpf->rport;
2750 bfa_trc(rport->fcs, rport->pwwn);
2751 bfa_trc(rport->fcs, rport->pid);
2752 bfa_trc(rport->fcs, event);
2755 case RPFSM_EVENT_RPORT_OFFLINE:
2756 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
2757 rpf->rpsc_retries = 0;
2761 bfa_sm_fault(rport->fcs, event);
2766 bfa_fcs_rpf_sm_offline(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
2768 struct bfa_fcs_rport_s *rport = rpf->rport;
2770 bfa_trc(rport->fcs, rport->pwwn);
2771 bfa_trc(rport->fcs, rport->pid);
2772 bfa_trc(rport->fcs, event);
2775 case RPFSM_EVENT_RPORT_ONLINE:
2776 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
2777 bfa_fcs_rpf_send_rpsc2(rpf, NULL);
2780 case RPFSM_EVENT_RPORT_OFFLINE:
2784 bfa_sm_fault(rport->fcs, event);
2788 * Called when Rport is created.
2791 bfa_fcs_rpf_init(struct bfa_fcs_rport_s *rport)
2793 struct bfa_fcs_rpf_s *rpf = &rport->rpf;
2795 bfa_trc(rport->fcs, rport->pid);
2798 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_uninit);
2802 * Called when Rport becomes online
2805 bfa_fcs_rpf_rport_online(struct bfa_fcs_rport_s *rport)
2807 bfa_trc(rport->fcs, rport->pid);
2809 if (__fcs_min_cfg(rport->port->fcs))
2812 if (bfa_fcs_fabric_is_switched(rport->port->fabric))
2813 bfa_sm_send_event(&rport->rpf, RPFSM_EVENT_RPORT_ONLINE);
2817 * Called when Rport becomes offline
2820 bfa_fcs_rpf_rport_offline(struct bfa_fcs_rport_s *rport)
2822 bfa_trc(rport->fcs, rport->pid);
2824 if (__fcs_min_cfg(rport->port->fcs))
2827 rport->rpf.rpsc_speed = 0;
2828 bfa_sm_send_event(&rport->rpf, RPFSM_EVENT_RPORT_OFFLINE);
2832 bfa_fcs_rpf_timeout(void *arg)
2834 struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *) arg;
2835 struct bfa_fcs_rport_s *rport = rpf->rport;
2837 bfa_trc(rport->fcs, rport->pid);
2838 bfa_sm_send_event(rpf, RPFSM_EVENT_TIMEOUT);
2842 bfa_fcs_rpf_send_rpsc2(void *rpf_cbarg, struct bfa_fcxp_s *fcxp_alloced)
2844 struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *)rpf_cbarg;
2845 struct bfa_fcs_rport_s *rport = rpf->rport;
2846 struct bfa_fcs_lport_s *port = rport->port;
2849 struct bfa_fcxp_s *fcxp;
2851 bfa_trc(rport->fcs, rport->pwwn);
2853 fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
2855 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rpf->fcxp_wqe,
2856 bfa_fcs_rpf_send_rpsc2, rpf);
2861 len = fc_rpsc2_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
2862 bfa_fcs_lport_get_fcid(port), &rport->pid, 1);
2864 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
2865 FC_CLASS_3, len, &fchs, bfa_fcs_rpf_rpsc2_response,
2866 rpf, FC_MAX_PDUSZ, FC_ELS_TOV);
2867 rport->stats.rpsc_sent++;
2868 bfa_sm_send_event(rpf, RPFSM_EVENT_FCXP_SENT);
2873 bfa_fcs_rpf_rpsc2_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
2874 bfa_status_t req_status, u32 rsp_len,
2875 u32 resid_len, struct fchs_s *rsp_fchs)
2877 struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *) cbarg;
2878 struct bfa_fcs_rport_s *rport = rpf->rport;
2879 struct fc_ls_rjt_s *ls_rjt;
2880 struct fc_rpsc2_acc_s *rpsc2_acc;
2883 bfa_trc(rport->fcs, req_status);
2885 if (req_status != BFA_STATUS_OK) {
2886 bfa_trc(rport->fcs, req_status);
2887 if (req_status == BFA_STATUS_ETIMER)
2888 rport->stats.rpsc_failed++;
2889 bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);
2893 rpsc2_acc = (struct fc_rpsc2_acc_s *) BFA_FCXP_RSP_PLD(fcxp);
2894 if (rpsc2_acc->els_cmd == FC_ELS_ACC) {
2895 rport->stats.rpsc_accs++;
2896 num_ents = be16_to_cpu(rpsc2_acc->num_pids);
2897 bfa_trc(rport->fcs, num_ents);
2899 bfa_assert(rpsc2_acc->port_info[0].pid != rport->pid);
2901 be16_to_cpu(rpsc2_acc->port_info[0].pid));
2903 be16_to_cpu(rpsc2_acc->port_info[0].speed));
2905 be16_to_cpu(rpsc2_acc->port_info[0].index));
2907 rpsc2_acc->port_info[0].type);
2909 if (rpsc2_acc->port_info[0].speed == 0) {
2910 bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);
2914 rpf->rpsc_speed = fc_rpsc_operspeed_to_bfa_speed(
2915 be16_to_cpu(rpsc2_acc->port_info[0].speed));
2917 bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_COMP);
2920 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
2921 bfa_trc(rport->fcs, ls_rjt->reason_code);
2922 bfa_trc(rport->fcs, ls_rjt->reason_code_expl);
2923 rport->stats.rpsc_rejects++;
2924 if (ls_rjt->reason_code == FC_LS_RJT_RSN_CMD_NOT_SUPP)
2925 bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_FAIL);
2927 bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);