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.
25 #include "bfa_fcbuild.h"
27 BFA_TRC_FILE(FCS, RPORT);
30 bfa_fcs_rport_del_timeout = BFA_FCS_RPORT_DEF_DEL_TIMEOUT * 1000;
33 * bfa_fcs_rport_max_logins is max count of bfa_fcs_rports
34 * whereas DEF_CFG_NUM_RPORTS is max count of bfa_rports
36 static u32 bfa_fcs_rport_max_logins = BFA_FCS_MAX_RPORT_LOGINS;
39 * forward declarations
41 static struct bfa_fcs_rport_s *bfa_fcs_rport_alloc(
42 struct bfa_fcs_lport_s *port, wwn_t pwwn, u32 rpid);
43 static void bfa_fcs_rport_free(struct bfa_fcs_rport_s *rport);
44 static void bfa_fcs_rport_hal_online(struct bfa_fcs_rport_s *rport);
45 static void bfa_fcs_rport_fcs_online_action(struct bfa_fcs_rport_s *rport);
46 static void bfa_fcs_rport_hal_online_action(struct bfa_fcs_rport_s *rport);
47 static void bfa_fcs_rport_fcs_offline_action(struct bfa_fcs_rport_s *rport);
48 static void bfa_fcs_rport_hal_offline_action(struct bfa_fcs_rport_s *rport);
49 static void bfa_fcs_rport_update(struct bfa_fcs_rport_s *rport,
50 struct fc_logi_s *plogi);
51 static void bfa_fcs_rport_timeout(void *arg);
52 static void bfa_fcs_rport_send_plogi(void *rport_cbarg,
53 struct bfa_fcxp_s *fcxp_alloced);
54 static void bfa_fcs_rport_send_plogiacc(void *rport_cbarg,
55 struct bfa_fcxp_s *fcxp_alloced);
56 static void bfa_fcs_rport_plogi_response(void *fcsarg,
57 struct bfa_fcxp_s *fcxp, void *cbarg,
58 bfa_status_t req_status, u32 rsp_len,
59 u32 resid_len, struct fchs_s *rsp_fchs);
60 static void bfa_fcs_rport_send_adisc(void *rport_cbarg,
61 struct bfa_fcxp_s *fcxp_alloced);
62 static void bfa_fcs_rport_adisc_response(void *fcsarg,
63 struct bfa_fcxp_s *fcxp, void *cbarg,
64 bfa_status_t req_status, u32 rsp_len,
65 u32 resid_len, struct fchs_s *rsp_fchs);
66 static void bfa_fcs_rport_send_nsdisc(void *rport_cbarg,
67 struct bfa_fcxp_s *fcxp_alloced);
68 static void bfa_fcs_rport_gidpn_response(void *fcsarg,
69 struct bfa_fcxp_s *fcxp, void *cbarg,
70 bfa_status_t req_status, u32 rsp_len,
71 u32 resid_len, struct fchs_s *rsp_fchs);
72 static void bfa_fcs_rport_gpnid_response(void *fcsarg,
73 struct bfa_fcxp_s *fcxp, void *cbarg,
74 bfa_status_t req_status, u32 rsp_len,
75 u32 resid_len, struct fchs_s *rsp_fchs);
76 static void bfa_fcs_rport_send_logo(void *rport_cbarg,
77 struct bfa_fcxp_s *fcxp_alloced);
78 static void bfa_fcs_rport_send_logo_acc(void *rport_cbarg);
79 static void bfa_fcs_rport_process_prli(struct bfa_fcs_rport_s *rport,
80 struct fchs_s *rx_fchs, u16 len);
81 static void bfa_fcs_rport_send_ls_rjt(struct bfa_fcs_rport_s *rport,
82 struct fchs_s *rx_fchs, u8 reason_code,
84 static void bfa_fcs_rport_process_adisc(struct bfa_fcs_rport_s *rport,
85 struct fchs_s *rx_fchs, u16 len);
86 static void bfa_fcs_rport_send_prlo_acc(struct bfa_fcs_rport_s *rport);
87 static void bfa_fcs_rport_hal_offline(struct bfa_fcs_rport_s *rport);
89 static void bfa_fcs_rport_sm_uninit(struct bfa_fcs_rport_s *rport,
90 enum rport_event event);
91 static void bfa_fcs_rport_sm_plogi_sending(struct bfa_fcs_rport_s *rport,
92 enum rport_event event);
93 static void bfa_fcs_rport_sm_plogiacc_sending(struct bfa_fcs_rport_s *rport,
94 enum rport_event event);
95 static void bfa_fcs_rport_sm_plogi_retry(struct bfa_fcs_rport_s *rport,
96 enum rport_event event);
97 static void bfa_fcs_rport_sm_plogi(struct bfa_fcs_rport_s *rport,
98 enum rport_event event);
99 static void bfa_fcs_rport_sm_fc4_fcs_online(struct bfa_fcs_rport_s *rport,
100 enum rport_event event);
101 static void bfa_fcs_rport_sm_hal_online(struct bfa_fcs_rport_s *rport,
102 enum rport_event event);
103 static void bfa_fcs_rport_sm_online(struct bfa_fcs_rport_s *rport,
104 enum rport_event event);
105 static void bfa_fcs_rport_sm_nsquery_sending(struct bfa_fcs_rport_s *rport,
106 enum rport_event event);
107 static void bfa_fcs_rport_sm_nsquery(struct bfa_fcs_rport_s *rport,
108 enum rport_event event);
109 static void bfa_fcs_rport_sm_adisc_sending(struct bfa_fcs_rport_s *rport,
110 enum rport_event event);
111 static void bfa_fcs_rport_sm_adisc(struct bfa_fcs_rport_s *rport,
112 enum rport_event event);
113 static void bfa_fcs_rport_sm_fc4_logorcv(struct bfa_fcs_rport_s *rport,
114 enum rport_event event);
115 static void bfa_fcs_rport_sm_fc4_logosend(struct bfa_fcs_rport_s *rport,
116 enum rport_event event);
117 static void bfa_fcs_rport_sm_fc4_offline(struct bfa_fcs_rport_s *rport,
118 enum rport_event event);
119 static void bfa_fcs_rport_sm_hcb_offline(struct bfa_fcs_rport_s *rport,
120 enum rport_event event);
121 static void bfa_fcs_rport_sm_hcb_logorcv(struct bfa_fcs_rport_s *rport,
122 enum rport_event event);
123 static void bfa_fcs_rport_sm_hcb_logosend(struct bfa_fcs_rport_s *rport,
124 enum rport_event event);
125 static void bfa_fcs_rport_sm_logo_sending(struct bfa_fcs_rport_s *rport,
126 enum rport_event event);
127 static void bfa_fcs_rport_sm_offline(struct bfa_fcs_rport_s *rport,
128 enum rport_event event);
129 static void bfa_fcs_rport_sm_nsdisc_sending(struct bfa_fcs_rport_s *rport,
130 enum rport_event event);
131 static void bfa_fcs_rport_sm_nsdisc_retry(struct bfa_fcs_rport_s *rport,
132 enum rport_event event);
133 static void bfa_fcs_rport_sm_nsdisc_sent(struct bfa_fcs_rport_s *rport,
134 enum rport_event event);
135 static void bfa_fcs_rport_sm_nsdisc_sent(struct bfa_fcs_rport_s *rport,
136 enum rport_event event);
137 static void bfa_fcs_rport_sm_fc4_off_delete(struct bfa_fcs_rport_s *rport,
138 enum rport_event event);
139 static void bfa_fcs_rport_sm_delete_pending(struct bfa_fcs_rport_s *rport,
140 enum rport_event event);
142 static struct bfa_sm_table_s rport_sm_table[] = {
143 {BFA_SM(bfa_fcs_rport_sm_uninit), BFA_RPORT_UNINIT},
144 {BFA_SM(bfa_fcs_rport_sm_plogi_sending), BFA_RPORT_PLOGI},
145 {BFA_SM(bfa_fcs_rport_sm_plogiacc_sending), BFA_RPORT_ONLINE},
146 {BFA_SM(bfa_fcs_rport_sm_plogi_retry), BFA_RPORT_PLOGI_RETRY},
147 {BFA_SM(bfa_fcs_rport_sm_plogi), BFA_RPORT_PLOGI},
148 {BFA_SM(bfa_fcs_rport_sm_fc4_fcs_online), BFA_RPORT_ONLINE},
149 {BFA_SM(bfa_fcs_rport_sm_hal_online), BFA_RPORT_ONLINE},
150 {BFA_SM(bfa_fcs_rport_sm_online), BFA_RPORT_ONLINE},
151 {BFA_SM(bfa_fcs_rport_sm_nsquery_sending), BFA_RPORT_NSQUERY},
152 {BFA_SM(bfa_fcs_rport_sm_nsquery), BFA_RPORT_NSQUERY},
153 {BFA_SM(bfa_fcs_rport_sm_adisc_sending), BFA_RPORT_ADISC},
154 {BFA_SM(bfa_fcs_rport_sm_adisc), BFA_RPORT_ADISC},
155 {BFA_SM(bfa_fcs_rport_sm_fc4_logorcv), BFA_RPORT_LOGORCV},
156 {BFA_SM(bfa_fcs_rport_sm_fc4_logosend), BFA_RPORT_LOGO},
157 {BFA_SM(bfa_fcs_rport_sm_fc4_offline), BFA_RPORT_OFFLINE},
158 {BFA_SM(bfa_fcs_rport_sm_hcb_offline), BFA_RPORT_OFFLINE},
159 {BFA_SM(bfa_fcs_rport_sm_hcb_logorcv), BFA_RPORT_LOGORCV},
160 {BFA_SM(bfa_fcs_rport_sm_hcb_logosend), BFA_RPORT_LOGO},
161 {BFA_SM(bfa_fcs_rport_sm_logo_sending), BFA_RPORT_LOGO},
162 {BFA_SM(bfa_fcs_rport_sm_offline), BFA_RPORT_OFFLINE},
163 {BFA_SM(bfa_fcs_rport_sm_nsdisc_sending), BFA_RPORT_NSDISC},
164 {BFA_SM(bfa_fcs_rport_sm_nsdisc_retry), BFA_RPORT_NSDISC},
165 {BFA_SM(bfa_fcs_rport_sm_nsdisc_sent), BFA_RPORT_NSDISC},
172 bfa_fcs_rport_sm_uninit(struct bfa_fcs_rport_s *rport, enum rport_event event)
174 bfa_trc(rport->fcs, rport->pwwn);
175 bfa_trc(rport->fcs, rport->pid);
176 bfa_trc(rport->fcs, event);
179 case RPSM_EVENT_PLOGI_SEND:
180 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
181 rport->plogi_retries = 0;
182 bfa_fcs_rport_send_plogi(rport, NULL);
185 case RPSM_EVENT_PLOGI_RCVD:
186 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
187 bfa_fcs_rport_fcs_online_action(rport);
190 case RPSM_EVENT_PLOGI_COMP:
191 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
192 bfa_fcs_rport_hal_online(rport);
195 case RPSM_EVENT_ADDRESS_CHANGE:
196 case RPSM_EVENT_ADDRESS_DISC:
197 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
198 rport->ns_retries = 0;
199 bfa_fcs_rport_send_nsdisc(rport, NULL);
202 bfa_sm_fault(rport->fcs, event);
207 * PLOGI is being sent.
210 bfa_fcs_rport_sm_plogi_sending(struct bfa_fcs_rport_s *rport,
211 enum rport_event event)
213 bfa_trc(rport->fcs, rport->pwwn);
214 bfa_trc(rport->fcs, rport->pid);
215 bfa_trc(rport->fcs, event);
218 case RPSM_EVENT_FCXP_SENT:
219 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi);
222 case RPSM_EVENT_DELETE:
223 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
224 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
225 bfa_fcs_rport_free(rport);
228 case RPSM_EVENT_PLOGI_RCVD:
229 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
230 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
231 bfa_fcs_rport_send_plogiacc(rport, NULL);
234 case RPSM_EVENT_ADDRESS_CHANGE:
237 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
238 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
239 rport->ns_retries = 0;
240 bfa_fcs_rport_send_nsdisc(rport, NULL);
243 case RPSM_EVENT_LOGO_IMP:
245 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
246 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
247 bfa_timer_start(rport->fcs->bfa, &rport->timer,
248 bfa_fcs_rport_timeout, rport,
249 bfa_fcs_rport_del_timeout);
254 bfa_sm_fault(rport->fcs, event);
259 * PLOGI is being sent.
262 bfa_fcs_rport_sm_plogiacc_sending(struct bfa_fcs_rport_s *rport,
263 enum rport_event event)
265 bfa_trc(rport->fcs, rport->pwwn);
266 bfa_trc(rport->fcs, rport->pid);
267 bfa_trc(rport->fcs, event);
270 case RPSM_EVENT_FCXP_SENT:
271 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
272 bfa_fcs_rport_fcs_online_action(rport);
275 case RPSM_EVENT_DELETE:
276 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
277 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
278 bfa_fcs_rport_free(rport);
281 case RPSM_EVENT_PLOGI_RCVD:
282 case RPSM_EVENT_PLOGI_COMP:
285 * Ignore, SCN is possibly online notification.
289 case RPSM_EVENT_ADDRESS_CHANGE:
290 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
291 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
292 rport->ns_retries = 0;
293 bfa_fcs_rport_send_nsdisc(rport, NULL);
296 case RPSM_EVENT_LOGO_IMP:
298 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
299 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
300 bfa_timer_start(rport->fcs->bfa, &rport->timer,
301 bfa_fcs_rport_timeout, rport,
302 bfa_fcs_rport_del_timeout);
305 case RPSM_EVENT_HCB_OFFLINE:
307 * Ignore BFA callback, on a PLOGI receive we call bfa offline.
312 bfa_sm_fault(rport->fcs, event);
320 bfa_fcs_rport_sm_plogi_retry(struct bfa_fcs_rport_s *rport,
321 enum rport_event event)
323 bfa_trc(rport->fcs, rport->pwwn);
324 bfa_trc(rport->fcs, rport->pid);
325 bfa_trc(rport->fcs, event);
328 case RPSM_EVENT_TIMEOUT:
329 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
330 bfa_fcs_rport_send_plogi(rport, NULL);
333 case RPSM_EVENT_DELETE:
334 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
335 bfa_timer_stop(&rport->timer);
336 bfa_fcs_rport_free(rport);
339 case RPSM_EVENT_PRLO_RCVD:
340 case RPSM_EVENT_LOGO_RCVD:
343 case RPSM_EVENT_PLOGI_RCVD:
344 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
345 bfa_timer_stop(&rport->timer);
346 bfa_fcs_rport_send_plogiacc(rport, NULL);
349 case RPSM_EVENT_ADDRESS_CHANGE:
351 bfa_timer_stop(&rport->timer);
352 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
353 rport->ns_retries = 0;
354 bfa_fcs_rport_send_nsdisc(rport, NULL);
357 case RPSM_EVENT_LOGO_IMP:
359 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
360 bfa_timer_stop(&rport->timer);
361 bfa_timer_start(rport->fcs->bfa, &rport->timer,
362 bfa_fcs_rport_timeout, rport,
363 bfa_fcs_rport_del_timeout);
366 case RPSM_EVENT_PLOGI_COMP:
367 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
368 bfa_timer_stop(&rport->timer);
369 bfa_fcs_rport_fcs_online_action(rport);
373 bfa_sm_fault(rport->fcs, event);
381 bfa_fcs_rport_sm_plogi(struct bfa_fcs_rport_s *rport, enum rport_event event)
383 bfa_trc(rport->fcs, rport->pwwn);
384 bfa_trc(rport->fcs, rport->pid);
385 bfa_trc(rport->fcs, event);
388 case RPSM_EVENT_ACCEPTED:
389 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
390 rport->plogi_retries = 0;
391 bfa_fcs_rport_fcs_online_action(rport);
394 case RPSM_EVENT_LOGO_RCVD:
395 bfa_fcs_rport_send_logo_acc(rport);
399 case RPSM_EVENT_PRLO_RCVD:
400 if (rport->prlo == BFA_TRUE)
401 bfa_fcs_rport_send_prlo_acc(rport);
403 bfa_fcxp_discard(rport->fcxp);
407 case RPSM_EVENT_FAILED:
408 if (rport->plogi_retries < BFA_FCS_RPORT_MAX_RETRIES) {
409 rport->plogi_retries++;
410 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_retry);
411 bfa_timer_start(rport->fcs->bfa, &rport->timer,
412 bfa_fcs_rport_timeout, rport,
413 BFA_FCS_RETRY_TIMEOUT);
415 bfa_stats(rport->port, rport_del_max_plogi_retry);
416 rport->old_pid = rport->pid;
418 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
419 bfa_timer_start(rport->fcs->bfa, &rport->timer,
420 bfa_fcs_rport_timeout, rport,
421 bfa_fcs_rport_del_timeout);
425 case RPSM_EVENT_PLOGI_RETRY:
426 rport->plogi_retries = 0;
427 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_retry);
428 bfa_timer_start(rport->fcs->bfa, &rport->timer,
429 bfa_fcs_rport_timeout, rport,
433 case RPSM_EVENT_LOGO_IMP:
435 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
436 bfa_fcxp_discard(rport->fcxp);
437 bfa_timer_start(rport->fcs->bfa, &rport->timer,
438 bfa_fcs_rport_timeout, rport,
439 bfa_fcs_rport_del_timeout);
442 case RPSM_EVENT_ADDRESS_CHANGE:
444 bfa_fcxp_discard(rport->fcxp);
445 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
446 rport->ns_retries = 0;
447 bfa_fcs_rport_send_nsdisc(rport, NULL);
450 case RPSM_EVENT_PLOGI_RCVD:
451 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
452 bfa_fcxp_discard(rport->fcxp);
453 bfa_fcs_rport_send_plogiacc(rport, NULL);
456 case RPSM_EVENT_DELETE:
457 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
458 bfa_fcxp_discard(rport->fcxp);
459 bfa_fcs_rport_free(rport);
462 case RPSM_EVENT_PLOGI_COMP:
463 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
464 bfa_fcxp_discard(rport->fcxp);
465 bfa_fcs_rport_fcs_online_action(rport);
469 bfa_sm_fault(rport->fcs, event);
474 * PLOGI is done. Await bfa_fcs_itnim to ascertain the scsi function
477 bfa_fcs_rport_sm_fc4_fcs_online(struct bfa_fcs_rport_s *rport,
478 enum rport_event event)
480 bfa_trc(rport->fcs, rport->pwwn);
481 bfa_trc(rport->fcs, rport->pid);
482 bfa_trc(rport->fcs, event);
485 case RPSM_EVENT_FC4_FCS_ONLINE:
486 if (rport->scsi_function == BFA_RPORT_INITIATOR) {
487 if (!BFA_FCS_PID_IS_WKA(rport->pid))
488 bfa_fcs_rpf_rport_online(rport);
489 bfa_sm_set_state(rport, bfa_fcs_rport_sm_online);
493 if (!rport->bfa_rport)
495 bfa_rport_create(rport->fcs->bfa, rport);
497 if (rport->bfa_rport) {
498 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
499 bfa_fcs_rport_hal_online(rport);
501 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
502 bfa_fcs_rport_fcs_offline_action(rport);
506 case RPSM_EVENT_PLOGI_RCVD:
507 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
508 rport->plogi_pending = BFA_TRUE;
509 bfa_fcs_rport_fcs_offline_action(rport);
512 case RPSM_EVENT_PLOGI_COMP:
513 case RPSM_EVENT_LOGO_IMP:
514 case RPSM_EVENT_ADDRESS_CHANGE:
516 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
517 bfa_fcs_rport_fcs_offline_action(rport);
520 case RPSM_EVENT_LOGO_RCVD:
521 case RPSM_EVENT_PRLO_RCVD:
522 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
523 bfa_fcs_rport_fcs_offline_action(rport);
526 case RPSM_EVENT_DELETE:
527 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
528 bfa_fcs_rport_fcs_offline_action(rport);
532 bfa_sm_fault(rport->fcs, event);
538 * PLOGI is complete. Awaiting BFA rport online callback. FC-4s
542 bfa_fcs_rport_sm_hal_online(struct bfa_fcs_rport_s *rport,
543 enum rport_event event)
545 bfa_trc(rport->fcs, rport->pwwn);
546 bfa_trc(rport->fcs, rport->pid);
547 bfa_trc(rport->fcs, event);
550 case RPSM_EVENT_HCB_ONLINE:
551 bfa_sm_set_state(rport, bfa_fcs_rport_sm_online);
552 bfa_fcs_rport_hal_online_action(rport);
555 case RPSM_EVENT_PLOGI_COMP:
558 case RPSM_EVENT_PRLO_RCVD:
559 case RPSM_EVENT_LOGO_RCVD:
560 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
561 bfa_fcs_rport_fcs_offline_action(rport);
565 case RPSM_EVENT_LOGO_IMP:
566 case RPSM_EVENT_ADDRESS_CHANGE:
567 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
568 bfa_fcs_rport_fcs_offline_action(rport);
571 case RPSM_EVENT_PLOGI_RCVD:
572 rport->plogi_pending = BFA_TRUE;
573 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
574 bfa_fcs_rport_fcs_offline_action(rport);
577 case RPSM_EVENT_DELETE:
578 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
579 bfa_fcs_rport_fcs_offline_action(rport);
583 bfa_sm_fault(rport->fcs, event);
588 * Rport is ONLINE. FC-4s active.
591 bfa_fcs_rport_sm_online(struct bfa_fcs_rport_s *rport, enum rport_event event)
593 bfa_trc(rport->fcs, rport->pwwn);
594 bfa_trc(rport->fcs, rport->pid);
595 bfa_trc(rport->fcs, event);
599 if (bfa_fcs_fabric_is_switched(rport->port->fabric)) {
600 bfa_sm_set_state(rport,
601 bfa_fcs_rport_sm_nsquery_sending);
602 rport->ns_retries = 0;
603 bfa_fcs_rport_send_nsdisc(rport, NULL);
605 bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc_sending);
606 bfa_fcs_rport_send_adisc(rport, NULL);
610 case RPSM_EVENT_PLOGI_RCVD:
611 case RPSM_EVENT_LOGO_IMP:
612 case RPSM_EVENT_ADDRESS_CHANGE:
613 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
614 bfa_fcs_rport_hal_offline_action(rport);
617 case RPSM_EVENT_DELETE:
618 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
619 bfa_fcs_rport_hal_offline_action(rport);
622 case RPSM_EVENT_LOGO_RCVD:
623 case RPSM_EVENT_PRLO_RCVD:
624 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
625 bfa_fcs_rport_hal_offline_action(rport);
628 case RPSM_EVENT_PLOGI_COMP:
632 bfa_sm_fault(rport->fcs, event);
637 * An SCN event is received in ONLINE state. NS query is being sent
638 * prior to ADISC authentication with rport. FC-4s are paused.
641 bfa_fcs_rport_sm_nsquery_sending(struct bfa_fcs_rport_s *rport,
642 enum rport_event event)
644 bfa_trc(rport->fcs, rport->pwwn);
645 bfa_trc(rport->fcs, rport->pid);
646 bfa_trc(rport->fcs, event);
649 case RPSM_EVENT_FCXP_SENT:
650 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsquery);
653 case RPSM_EVENT_DELETE:
654 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
655 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
656 bfa_fcs_rport_hal_offline_action(rport);
661 * ignore SCN, wait for response to query itself
665 case RPSM_EVENT_LOGO_RCVD:
666 case RPSM_EVENT_PRLO_RCVD:
667 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
668 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
669 bfa_fcs_rport_hal_offline_action(rport);
672 case RPSM_EVENT_LOGO_IMP:
673 case RPSM_EVENT_PLOGI_RCVD:
674 case RPSM_EVENT_ADDRESS_CHANGE:
675 case RPSM_EVENT_PLOGI_COMP:
676 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
677 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
678 bfa_fcs_rport_hal_offline_action(rport);
682 bfa_sm_fault(rport->fcs, event);
687 * An SCN event is received in ONLINE state. NS query is sent to rport.
691 bfa_fcs_rport_sm_nsquery(struct bfa_fcs_rport_s *rport, enum rport_event event)
693 bfa_trc(rport->fcs, rport->pwwn);
694 bfa_trc(rport->fcs, rport->pid);
695 bfa_trc(rport->fcs, event);
698 case RPSM_EVENT_ACCEPTED:
699 bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc_sending);
700 bfa_fcs_rport_send_adisc(rport, NULL);
703 case RPSM_EVENT_FAILED:
705 if (rport->ns_retries < BFA_FCS_RPORT_MAX_RETRIES) {
706 bfa_sm_set_state(rport,
707 bfa_fcs_rport_sm_nsquery_sending);
708 bfa_fcs_rport_send_nsdisc(rport, NULL);
710 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
711 bfa_fcs_rport_hal_offline_action(rport);
715 case RPSM_EVENT_DELETE:
716 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
717 bfa_fcxp_discard(rport->fcxp);
718 bfa_fcs_rport_hal_offline_action(rport);
724 case RPSM_EVENT_LOGO_RCVD:
725 case RPSM_EVENT_PRLO_RCVD:
726 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
727 bfa_fcxp_discard(rport->fcxp);
728 bfa_fcs_rport_hal_offline_action(rport);
731 case RPSM_EVENT_PLOGI_COMP:
732 case RPSM_EVENT_ADDRESS_CHANGE:
733 case RPSM_EVENT_PLOGI_RCVD:
734 case RPSM_EVENT_LOGO_IMP:
735 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
736 bfa_fcxp_discard(rport->fcxp);
737 bfa_fcs_rport_hal_offline_action(rport);
741 bfa_sm_fault(rport->fcs, event);
746 * An SCN event is received in ONLINE state. ADISC is being sent for
747 * authenticating with rport. FC-4s are paused.
750 bfa_fcs_rport_sm_adisc_sending(struct bfa_fcs_rport_s *rport,
751 enum rport_event event)
753 bfa_trc(rport->fcs, rport->pwwn);
754 bfa_trc(rport->fcs, rport->pid);
755 bfa_trc(rport->fcs, event);
758 case RPSM_EVENT_FCXP_SENT:
759 bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc);
762 case RPSM_EVENT_DELETE:
763 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
764 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
765 bfa_fcs_rport_hal_offline_action(rport);
768 case RPSM_EVENT_LOGO_IMP:
769 case RPSM_EVENT_ADDRESS_CHANGE:
770 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
771 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
772 bfa_fcs_rport_hal_offline_action(rport);
775 case RPSM_EVENT_LOGO_RCVD:
776 case RPSM_EVENT_PRLO_RCVD:
777 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
778 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
779 bfa_fcs_rport_hal_offline_action(rport);
785 case RPSM_EVENT_PLOGI_RCVD:
786 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
787 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
788 bfa_fcs_rport_hal_offline_action(rport);
792 bfa_sm_fault(rport->fcs, event);
797 * An SCN event is received in ONLINE state. ADISC is to rport.
801 bfa_fcs_rport_sm_adisc(struct bfa_fcs_rport_s *rport, enum rport_event event)
803 bfa_trc(rport->fcs, rport->pwwn);
804 bfa_trc(rport->fcs, rport->pid);
805 bfa_trc(rport->fcs, event);
808 case RPSM_EVENT_ACCEPTED:
809 bfa_sm_set_state(rport, bfa_fcs_rport_sm_online);
812 case RPSM_EVENT_PLOGI_RCVD:
814 * Too complex to cleanup FC-4 & rport and then acc to PLOGI.
815 * At least go offline when a PLOGI is received.
817 bfa_fcxp_discard(rport->fcxp);
819 * !!! fall through !!!
822 case RPSM_EVENT_FAILED:
823 case RPSM_EVENT_ADDRESS_CHANGE:
824 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
825 bfa_fcs_rport_hal_offline_action(rport);
828 case RPSM_EVENT_DELETE:
829 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
830 bfa_fcxp_discard(rport->fcxp);
831 bfa_fcs_rport_hal_offline_action(rport);
836 * already processing RSCN
840 case RPSM_EVENT_LOGO_IMP:
841 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
842 bfa_fcxp_discard(rport->fcxp);
843 bfa_fcs_rport_hal_offline_action(rport);
846 case RPSM_EVENT_LOGO_RCVD:
847 case RPSM_EVENT_PRLO_RCVD:
848 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
849 bfa_fcxp_discard(rport->fcxp);
850 bfa_fcs_rport_hal_offline_action(rport);
854 bfa_sm_fault(rport->fcs, event);
859 * Rport has sent LOGO. Awaiting FC-4 offline completion callback.
862 bfa_fcs_rport_sm_fc4_logorcv(struct bfa_fcs_rport_s *rport,
863 enum rport_event event)
865 bfa_trc(rport->fcs, rport->pwwn);
866 bfa_trc(rport->fcs, rport->pid);
867 bfa_trc(rport->fcs, event);
870 case RPSM_EVENT_FC4_OFFLINE:
871 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logorcv);
872 bfa_fcs_rport_hal_offline(rport);
875 case RPSM_EVENT_DELETE:
876 if (rport->pid && (rport->prlo == BFA_TRUE))
877 bfa_fcs_rport_send_prlo_acc(rport);
878 if (rport->pid && (rport->prlo == BFA_FALSE))
879 bfa_fcs_rport_send_logo_acc(rport);
881 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_off_delete);
884 case RPSM_EVENT_HCB_ONLINE:
885 case RPSM_EVENT_LOGO_RCVD:
886 case RPSM_EVENT_PRLO_RCVD:
887 case RPSM_EVENT_ADDRESS_CHANGE:
891 bfa_sm_fault(rport->fcs, event);
896 * LOGO needs to be sent to rport. Awaiting FC-4 offline completion
900 bfa_fcs_rport_sm_fc4_logosend(struct bfa_fcs_rport_s *rport,
901 enum rport_event event)
903 bfa_trc(rport->fcs, rport->pwwn);
904 bfa_trc(rport->fcs, rport->pid);
905 bfa_trc(rport->fcs, event);
908 case RPSM_EVENT_FC4_OFFLINE:
909 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logosend);
910 bfa_fcs_rport_hal_offline(rport);
913 case RPSM_EVENT_LOGO_RCVD:
914 bfa_fcs_rport_send_logo_acc(rport);
915 case RPSM_EVENT_PRLO_RCVD:
916 if (rport->prlo == BFA_TRUE)
917 bfa_fcs_rport_send_prlo_acc(rport);
918 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_off_delete);
921 case RPSM_EVENT_HCB_ONLINE:
922 case RPSM_EVENT_DELETE:
923 /* Rport is being deleted */
927 bfa_sm_fault(rport->fcs, event);
932 * Rport is going offline. Awaiting FC-4 offline completion callback.
935 bfa_fcs_rport_sm_fc4_offline(struct bfa_fcs_rport_s *rport,
936 enum rport_event event)
938 bfa_trc(rport->fcs, rport->pwwn);
939 bfa_trc(rport->fcs, rport->pid);
940 bfa_trc(rport->fcs, event);
943 case RPSM_EVENT_FC4_OFFLINE:
944 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_offline);
945 bfa_fcs_rport_hal_offline(rport);
948 case RPSM_EVENT_LOGO_RCVD:
950 * Rport is going offline. Just ack the logo
952 bfa_fcs_rport_send_logo_acc(rport);
955 case RPSM_EVENT_PRLO_RCVD:
956 bfa_fcs_rport_send_prlo_acc(rport);
959 case RPSM_EVENT_HCB_ONLINE:
961 case RPSM_EVENT_LOGO_IMP:
962 case RPSM_EVENT_ADDRESS_CHANGE:
964 * rport is already going offline.
965 * SCN - ignore and wait till transitioning to offline state
969 case RPSM_EVENT_DELETE:
970 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
974 bfa_sm_fault(rport->fcs, event);
979 * Rport is offline. FC-4s are offline. Awaiting BFA rport offline
983 bfa_fcs_rport_sm_hcb_offline(struct bfa_fcs_rport_s *rport,
984 enum rport_event event)
986 bfa_trc(rport->fcs, rport->pwwn);
987 bfa_trc(rport->fcs, rport->pid);
988 bfa_trc(rport->fcs, event);
991 case RPSM_EVENT_HCB_OFFLINE:
992 if (bfa_fcs_lport_is_online(rport->port) &&
993 (rport->plogi_pending)) {
994 rport->plogi_pending = BFA_FALSE;
995 bfa_sm_set_state(rport,
996 bfa_fcs_rport_sm_plogiacc_sending);
997 bfa_fcs_rport_send_plogiacc(rport, NULL);
1001 * !! fall through !!
1004 case RPSM_EVENT_ADDRESS_CHANGE:
1005 if (!bfa_fcs_lport_is_online(rport->port)) {
1007 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
1008 bfa_timer_start(rport->fcs->bfa, &rport->timer,
1009 bfa_fcs_rport_timeout, rport,
1010 bfa_fcs_rport_del_timeout);
1013 if (bfa_fcs_fabric_is_switched(rport->port->fabric)) {
1014 bfa_sm_set_state(rport,
1015 bfa_fcs_rport_sm_nsdisc_sending);
1016 rport->ns_retries = 0;
1017 bfa_fcs_rport_send_nsdisc(rport, NULL);
1019 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
1020 rport->plogi_retries = 0;
1021 bfa_fcs_rport_send_plogi(rport, NULL);
1025 case RPSM_EVENT_DELETE:
1026 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1027 bfa_fcs_rport_free(rport);
1030 case RPSM_EVENT_SCN:
1031 case RPSM_EVENT_LOGO_RCVD:
1032 case RPSM_EVENT_PRLO_RCVD:
1033 case RPSM_EVENT_PLOGI_RCVD:
1034 case RPSM_EVENT_LOGO_IMP:
1036 * Ignore, already offline.
1041 bfa_sm_fault(rport->fcs, event);
1046 * Rport is offline. FC-4s are offline. Awaiting BFA rport offline
1047 * callback to send LOGO accept.
1050 bfa_fcs_rport_sm_hcb_logorcv(struct bfa_fcs_rport_s *rport,
1051 enum rport_event event)
1053 bfa_trc(rport->fcs, rport->pwwn);
1054 bfa_trc(rport->fcs, rport->pid);
1055 bfa_trc(rport->fcs, event);
1058 case RPSM_EVENT_HCB_OFFLINE:
1059 case RPSM_EVENT_ADDRESS_CHANGE:
1060 if (rport->pid && (rport->prlo == BFA_TRUE))
1061 bfa_fcs_rport_send_prlo_acc(rport);
1062 if (rport->pid && (rport->prlo == BFA_FALSE))
1063 bfa_fcs_rport_send_logo_acc(rport);
1065 * If the lport is online and if the rport is not a well
1066 * known address port,
1067 * we try to re-discover the r-port.
1069 if (bfa_fcs_lport_is_online(rport->port) &&
1070 (!BFA_FCS_PID_IS_WKA(rport->pid))) {
1071 if (bfa_fcs_fabric_is_switched(rport->port->fabric)) {
1072 bfa_sm_set_state(rport,
1073 bfa_fcs_rport_sm_nsdisc_sending);
1074 rport->ns_retries = 0;
1075 bfa_fcs_rport_send_nsdisc(rport, NULL);
1077 /* For N2N Direct Attach, try to re-login */
1078 bfa_sm_set_state(rport,
1079 bfa_fcs_rport_sm_plogi_sending);
1080 rport->plogi_retries = 0;
1081 bfa_fcs_rport_send_plogi(rport, NULL);
1085 * if it is not a well known address, reset the
1088 if (!BFA_FCS_PID_IS_WKA(rport->pid))
1090 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
1091 bfa_timer_start(rport->fcs->bfa, &rport->timer,
1092 bfa_fcs_rport_timeout, rport,
1093 bfa_fcs_rport_del_timeout);
1097 case RPSM_EVENT_DELETE:
1098 bfa_sm_set_state(rport, bfa_fcs_rport_sm_delete_pending);
1099 if (rport->pid && (rport->prlo == BFA_TRUE))
1100 bfa_fcs_rport_send_prlo_acc(rport);
1101 if (rport->pid && (rport->prlo == BFA_FALSE))
1102 bfa_fcs_rport_send_logo_acc(rport);
1105 case RPSM_EVENT_LOGO_IMP:
1106 bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_offline);
1109 case RPSM_EVENT_LOGO_RCVD:
1110 case RPSM_EVENT_PRLO_RCVD:
1112 * Ignore - already processing a LOGO.
1117 bfa_sm_fault(rport->fcs, event);
1122 * Rport is being deleted. FC-4s are offline.
1123 * Awaiting BFA rport offline
1124 * callback to send LOGO.
1127 bfa_fcs_rport_sm_hcb_logosend(struct bfa_fcs_rport_s *rport,
1128 enum rport_event event)
1130 bfa_trc(rport->fcs, rport->pwwn);
1131 bfa_trc(rport->fcs, rport->pid);
1132 bfa_trc(rport->fcs, event);
1135 case RPSM_EVENT_HCB_OFFLINE:
1136 bfa_sm_set_state(rport, bfa_fcs_rport_sm_logo_sending);
1137 bfa_fcs_rport_send_logo(rport, NULL);
1140 case RPSM_EVENT_LOGO_RCVD:
1141 bfa_fcs_rport_send_logo_acc(rport);
1142 case RPSM_EVENT_PRLO_RCVD:
1143 if (rport->prlo == BFA_TRUE)
1144 bfa_fcs_rport_send_prlo_acc(rport);
1146 bfa_sm_set_state(rport, bfa_fcs_rport_sm_delete_pending);
1149 case RPSM_EVENT_ADDRESS_CHANGE:
1153 bfa_sm_fault(rport->fcs, event);
1158 * Rport is being deleted. FC-4s are offline. LOGO is being sent.
1161 bfa_fcs_rport_sm_logo_sending(struct bfa_fcs_rport_s *rport,
1162 enum rport_event event)
1164 bfa_trc(rport->fcs, rport->pwwn);
1165 bfa_trc(rport->fcs, rport->pid);
1166 bfa_trc(rport->fcs, event);
1169 case RPSM_EVENT_FCXP_SENT:
1170 /* Once LOGO is sent, we donot wait for the response */
1171 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1172 bfa_fcs_rport_free(rport);
1175 case RPSM_EVENT_SCN:
1176 case RPSM_EVENT_ADDRESS_CHANGE:
1179 case RPSM_EVENT_LOGO_RCVD:
1180 bfa_fcs_rport_send_logo_acc(rport);
1181 case RPSM_EVENT_PRLO_RCVD:
1182 if (rport->prlo == BFA_TRUE)
1183 bfa_fcs_rport_send_prlo_acc(rport);
1185 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1186 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
1187 bfa_fcs_rport_free(rport);
1191 bfa_sm_fault(rport->fcs, event);
1196 * Rport is offline. FC-4s are offline. BFA rport is offline.
1197 * Timer active to delete stale rport.
1200 bfa_fcs_rport_sm_offline(struct bfa_fcs_rport_s *rport, enum rport_event event)
1202 bfa_trc(rport->fcs, rport->pwwn);
1203 bfa_trc(rport->fcs, rport->pid);
1204 bfa_trc(rport->fcs, event);
1207 case RPSM_EVENT_TIMEOUT:
1208 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1209 bfa_fcs_rport_free(rport);
1212 case RPSM_EVENT_SCN:
1213 case RPSM_EVENT_ADDRESS_CHANGE:
1214 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
1215 bfa_timer_stop(&rport->timer);
1216 rport->ns_retries = 0;
1217 bfa_fcs_rport_send_nsdisc(rport, NULL);
1220 case RPSM_EVENT_DELETE:
1221 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1222 bfa_timer_stop(&rport->timer);
1223 bfa_fcs_rport_free(rport);
1226 case RPSM_EVENT_PLOGI_RCVD:
1227 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
1228 bfa_timer_stop(&rport->timer);
1229 bfa_fcs_rport_send_plogiacc(rport, NULL);
1232 case RPSM_EVENT_LOGO_RCVD:
1233 case RPSM_EVENT_PRLO_RCVD:
1234 case RPSM_EVENT_LOGO_IMP:
1237 case RPSM_EVENT_PLOGI_COMP:
1238 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
1239 bfa_timer_stop(&rport->timer);
1240 bfa_fcs_rport_fcs_online_action(rport);
1243 case RPSM_EVENT_PLOGI_SEND:
1244 bfa_timer_stop(&rport->timer);
1245 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
1246 rport->plogi_retries = 0;
1247 bfa_fcs_rport_send_plogi(rport, NULL);
1251 bfa_sm_fault(rport->fcs, event);
1256 * Rport address has changed. Nameserver discovery request is being sent.
1259 bfa_fcs_rport_sm_nsdisc_sending(struct bfa_fcs_rport_s *rport,
1260 enum rport_event event)
1262 bfa_trc(rport->fcs, rport->pwwn);
1263 bfa_trc(rport->fcs, rport->pid);
1264 bfa_trc(rport->fcs, event);
1267 case RPSM_EVENT_FCXP_SENT:
1268 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sent);
1271 case RPSM_EVENT_DELETE:
1272 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1273 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
1274 bfa_fcs_rport_free(rport);
1277 case RPSM_EVENT_PLOGI_RCVD:
1278 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
1279 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
1280 bfa_fcs_rport_send_plogiacc(rport, NULL);
1283 case RPSM_EVENT_SCN:
1284 case RPSM_EVENT_LOGO_RCVD:
1285 case RPSM_EVENT_PRLO_RCVD:
1286 case RPSM_EVENT_PLOGI_SEND:
1289 case RPSM_EVENT_ADDRESS_CHANGE:
1290 rport->ns_retries = 0; /* reset the retry count */
1293 case RPSM_EVENT_LOGO_IMP:
1294 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
1295 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
1296 bfa_timer_start(rport->fcs->bfa, &rport->timer,
1297 bfa_fcs_rport_timeout, rport,
1298 bfa_fcs_rport_del_timeout);
1301 case RPSM_EVENT_PLOGI_COMP:
1302 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
1303 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
1304 bfa_fcs_rport_fcs_online_action(rport);
1308 bfa_sm_fault(rport->fcs, event);
1313 * Nameserver discovery failed. Waiting for timeout to retry.
1316 bfa_fcs_rport_sm_nsdisc_retry(struct bfa_fcs_rport_s *rport,
1317 enum rport_event event)
1319 bfa_trc(rport->fcs, rport->pwwn);
1320 bfa_trc(rport->fcs, rport->pid);
1321 bfa_trc(rport->fcs, event);
1324 case RPSM_EVENT_TIMEOUT:
1325 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
1326 bfa_fcs_rport_send_nsdisc(rport, NULL);
1329 case RPSM_EVENT_SCN:
1330 case RPSM_EVENT_ADDRESS_CHANGE:
1331 bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
1332 bfa_timer_stop(&rport->timer);
1333 rport->ns_retries = 0;
1334 bfa_fcs_rport_send_nsdisc(rport, NULL);
1337 case RPSM_EVENT_DELETE:
1338 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1339 bfa_timer_stop(&rport->timer);
1340 bfa_fcs_rport_free(rport);
1343 case RPSM_EVENT_PLOGI_RCVD:
1344 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
1345 bfa_timer_stop(&rport->timer);
1346 bfa_fcs_rport_send_plogiacc(rport, NULL);
1349 case RPSM_EVENT_LOGO_IMP:
1351 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
1352 bfa_timer_stop(&rport->timer);
1353 bfa_timer_start(rport->fcs->bfa, &rport->timer,
1354 bfa_fcs_rport_timeout, rport,
1355 bfa_fcs_rport_del_timeout);
1358 case RPSM_EVENT_LOGO_RCVD:
1359 bfa_fcs_rport_send_logo_acc(rport);
1361 case RPSM_EVENT_PRLO_RCVD:
1362 bfa_fcs_rport_send_prlo_acc(rport);
1365 case RPSM_EVENT_PLOGI_COMP:
1366 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
1367 bfa_timer_stop(&rport->timer);
1368 bfa_fcs_rport_fcs_online_action(rport);
1372 bfa_sm_fault(rport->fcs, event);
1377 * Rport address has changed. Nameserver discovery request is sent.
1380 bfa_fcs_rport_sm_nsdisc_sent(struct bfa_fcs_rport_s *rport,
1381 enum rport_event event)
1383 bfa_trc(rport->fcs, rport->pwwn);
1384 bfa_trc(rport->fcs, rport->pid);
1385 bfa_trc(rport->fcs, event);
1388 case RPSM_EVENT_ACCEPTED:
1389 case RPSM_EVENT_ADDRESS_CHANGE:
1391 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
1392 bfa_fcs_rport_send_plogi(rport, NULL);
1394 bfa_sm_set_state(rport,
1395 bfa_fcs_rport_sm_nsdisc_sending);
1396 rport->ns_retries = 0;
1397 bfa_fcs_rport_send_nsdisc(rport, NULL);
1401 case RPSM_EVENT_FAILED:
1402 rport->ns_retries++;
1403 if (rport->ns_retries < BFA_FCS_RPORT_MAX_RETRIES) {
1404 bfa_sm_set_state(rport,
1405 bfa_fcs_rport_sm_nsdisc_sending);
1406 bfa_fcs_rport_send_nsdisc(rport, NULL);
1408 rport->old_pid = rport->pid;
1410 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
1411 bfa_timer_start(rport->fcs->bfa, &rport->timer,
1412 bfa_fcs_rport_timeout, rport,
1413 bfa_fcs_rport_del_timeout);
1417 case RPSM_EVENT_DELETE:
1418 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1419 bfa_fcxp_discard(rport->fcxp);
1420 bfa_fcs_rport_free(rport);
1423 case RPSM_EVENT_PLOGI_RCVD:
1424 bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
1425 bfa_fcxp_discard(rport->fcxp);
1426 bfa_fcs_rport_send_plogiacc(rport, NULL);
1429 case RPSM_EVENT_LOGO_IMP:
1431 bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
1432 bfa_fcxp_discard(rport->fcxp);
1433 bfa_timer_start(rport->fcs->bfa, &rport->timer,
1434 bfa_fcs_rport_timeout, rport,
1435 bfa_fcs_rport_del_timeout);
1439 case RPSM_EVENT_PRLO_RCVD:
1440 bfa_fcs_rport_send_prlo_acc(rport);
1442 case RPSM_EVENT_SCN:
1444 * ignore, wait for NS query response
1448 case RPSM_EVENT_LOGO_RCVD:
1450 * Not logged-in yet. Accept LOGO.
1452 bfa_fcs_rport_send_logo_acc(rport);
1455 case RPSM_EVENT_PLOGI_COMP:
1456 bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_fcs_online);
1457 bfa_fcxp_discard(rport->fcxp);
1458 bfa_fcs_rport_fcs_online_action(rport);
1462 bfa_sm_fault(rport->fcs, event);
1467 * Rport needs to be deleted
1468 * waiting for ITNIM clean up to finish
1471 bfa_fcs_rport_sm_fc4_off_delete(struct bfa_fcs_rport_s *rport,
1472 enum rport_event event)
1474 bfa_trc(rport->fcs, rport->pwwn);
1475 bfa_trc(rport->fcs, rport->pid);
1476 bfa_trc(rport->fcs, event);
1479 case RPSM_EVENT_FC4_OFFLINE:
1480 bfa_sm_set_state(rport, bfa_fcs_rport_sm_delete_pending);
1481 bfa_fcs_rport_hal_offline(rport);
1484 case RPSM_EVENT_DELETE:
1485 case RPSM_EVENT_PLOGI_RCVD:
1486 /* Ignore these events */
1490 bfa_sm_fault(rport->fcs, event);
1496 * RPort needs to be deleted
1497 * waiting for BFA/FW to finish current processing
1500 bfa_fcs_rport_sm_delete_pending(struct bfa_fcs_rport_s *rport,
1501 enum rport_event event)
1503 bfa_trc(rport->fcs, rport->pwwn);
1504 bfa_trc(rport->fcs, rport->pid);
1505 bfa_trc(rport->fcs, event);
1508 case RPSM_EVENT_HCB_OFFLINE:
1509 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
1510 bfa_fcs_rport_free(rport);
1513 case RPSM_EVENT_DELETE:
1514 case RPSM_EVENT_LOGO_IMP:
1515 case RPSM_EVENT_PLOGI_RCVD:
1516 /* Ignore these events */
1520 bfa_sm_fault(rport->fcs, event);
1525 * fcs_rport_private FCS RPORT provate functions
1529 bfa_fcs_rport_send_plogi(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1531 struct bfa_fcs_rport_s *rport = rport_cbarg;
1532 struct bfa_fcs_lport_s *port = rport->port;
1535 struct bfa_fcxp_s *fcxp;
1537 bfa_trc(rport->fcs, rport->pwwn);
1539 fcxp = fcxp_alloced ? fcxp_alloced :
1540 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
1542 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
1543 bfa_fcs_rport_send_plogi, rport, BFA_TRUE);
1548 len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
1549 bfa_fcs_lport_get_fcid(port), 0,
1550 port->port_cfg.pwwn, port->port_cfg.nwwn,
1551 bfa_fcport_get_maxfrsize(port->fcs->bfa),
1552 bfa_fcport_get_rx_bbcredit(port->fcs->bfa));
1554 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1555 FC_CLASS_3, len, &fchs, bfa_fcs_rport_plogi_response,
1556 (void *)rport, FC_MAX_PDUSZ, FC_ELS_TOV);
1558 rport->stats.plogis++;
1559 bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
1563 bfa_fcs_rport_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1564 bfa_status_t req_status, u32 rsp_len,
1565 u32 resid_len, struct fchs_s *rsp_fchs)
1567 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
1568 struct fc_logi_s *plogi_rsp;
1569 struct fc_ls_rjt_s *ls_rjt;
1570 struct bfa_fcs_rport_s *twin;
1571 struct list_head *qe;
1573 bfa_trc(rport->fcs, rport->pwwn);
1578 if (req_status != BFA_STATUS_OK) {
1579 bfa_trc(rport->fcs, req_status);
1580 rport->stats.plogi_failed++;
1581 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1585 plogi_rsp = (struct fc_logi_s *) BFA_FCXP_RSP_PLD(fcxp);
1588 * Check for failure first.
1590 if (plogi_rsp->els_cmd.els_code != FC_ELS_ACC) {
1591 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
1593 bfa_trc(rport->fcs, ls_rjt->reason_code);
1594 bfa_trc(rport->fcs, ls_rjt->reason_code_expl);
1596 if ((ls_rjt->reason_code == FC_LS_RJT_RSN_UNABLE_TO_PERF_CMD) &&
1597 (ls_rjt->reason_code_expl == FC_LS_RJT_EXP_INSUFF_RES)) {
1598 rport->stats.rjt_insuff_res++;
1599 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RETRY);
1603 rport->stats.plogi_rejects++;
1604 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1609 * PLOGI is complete. Make sure this device is not one of the known
1610 * device with a new FC port address.
1612 list_for_each(qe, &rport->port->rport_q) {
1613 twin = (struct bfa_fcs_rport_s *) qe;
1616 if (!rport->pwwn && (plogi_rsp->port_name == twin->pwwn)) {
1617 bfa_trc(rport->fcs, twin->pid);
1618 bfa_trc(rport->fcs, rport->pid);
1620 /* Update plogi stats in twin */
1621 twin->stats.plogis += rport->stats.plogis;
1622 twin->stats.plogi_rejects +=
1623 rport->stats.plogi_rejects;
1624 twin->stats.plogi_timeouts +=
1625 rport->stats.plogi_timeouts;
1626 twin->stats.plogi_failed +=
1627 rport->stats.plogi_failed;
1628 twin->stats.plogi_rcvd += rport->stats.plogi_rcvd;
1629 twin->stats.plogi_accs++;
1631 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
1633 bfa_fcs_rport_update(twin, plogi_rsp);
1634 twin->pid = rsp_fchs->s_id;
1635 bfa_sm_send_event(twin, RPSM_EVENT_PLOGI_COMP);
1641 * Normal login path -- no evil twins.
1643 rport->stats.plogi_accs++;
1644 bfa_fcs_rport_update(rport, plogi_rsp);
1645 bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
1649 bfa_fcs_rport_send_plogiacc(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1651 struct bfa_fcs_rport_s *rport = rport_cbarg;
1652 struct bfa_fcs_lport_s *port = rport->port;
1655 struct bfa_fcxp_s *fcxp;
1657 bfa_trc(rport->fcs, rport->pwwn);
1658 bfa_trc(rport->fcs, rport->reply_oxid);
1660 fcxp = fcxp_alloced ? fcxp_alloced :
1661 bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
1663 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
1664 bfa_fcs_rport_send_plogiacc, rport, BFA_FALSE);
1669 len = fc_plogi_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1670 rport->pid, bfa_fcs_lport_get_fcid(port),
1671 rport->reply_oxid, port->port_cfg.pwwn,
1672 port->port_cfg.nwwn,
1673 bfa_fcport_get_maxfrsize(port->fcs->bfa),
1674 bfa_fcport_get_rx_bbcredit(port->fcs->bfa));
1676 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1677 FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
1679 bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
1683 bfa_fcs_rport_send_adisc(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1685 struct bfa_fcs_rport_s *rport = rport_cbarg;
1686 struct bfa_fcs_lport_s *port = rport->port;
1689 struct bfa_fcxp_s *fcxp;
1691 bfa_trc(rport->fcs, rport->pwwn);
1693 fcxp = fcxp_alloced ? fcxp_alloced :
1694 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
1696 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
1697 bfa_fcs_rport_send_adisc, rport, BFA_TRUE);
1702 len = fc_adisc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
1703 bfa_fcs_lport_get_fcid(port), 0,
1704 port->port_cfg.pwwn, port->port_cfg.nwwn);
1706 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1707 FC_CLASS_3, len, &fchs, bfa_fcs_rport_adisc_response,
1708 rport, FC_MAX_PDUSZ, FC_ELS_TOV);
1710 rport->stats.adisc_sent++;
1711 bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
1715 bfa_fcs_rport_adisc_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1716 bfa_status_t req_status, u32 rsp_len,
1717 u32 resid_len, struct fchs_s *rsp_fchs)
1719 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
1720 void *pld = bfa_fcxp_get_rspbuf(fcxp);
1721 struct fc_ls_rjt_s *ls_rjt;
1723 if (req_status != BFA_STATUS_OK) {
1724 bfa_trc(rport->fcs, req_status);
1725 rport->stats.adisc_failed++;
1726 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1730 if (fc_adisc_rsp_parse((struct fc_adisc_s *)pld, rsp_len, rport->pwwn,
1731 rport->nwwn) == FC_PARSE_OK) {
1732 rport->stats.adisc_accs++;
1733 bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
1737 rport->stats.adisc_rejects++;
1739 bfa_trc(rport->fcs, ls_rjt->els_cmd.els_code);
1740 bfa_trc(rport->fcs, ls_rjt->reason_code);
1741 bfa_trc(rport->fcs, ls_rjt->reason_code_expl);
1742 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1746 bfa_fcs_rport_send_nsdisc(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1748 struct bfa_fcs_rport_s *rport = rport_cbarg;
1749 struct bfa_fcs_lport_s *port = rport->port;
1751 struct bfa_fcxp_s *fcxp;
1753 bfa_cb_fcxp_send_t cbfn;
1755 bfa_trc(rport->fcs, rport->pid);
1757 fcxp = fcxp_alloced ? fcxp_alloced :
1758 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
1760 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
1761 bfa_fcs_rport_send_nsdisc, rport, BFA_TRUE);
1767 len = fc_gidpn_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1768 bfa_fcs_lport_get_fcid(port), 0, rport->pwwn);
1769 cbfn = bfa_fcs_rport_gidpn_response;
1771 len = fc_gpnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1772 bfa_fcs_lport_get_fcid(port), 0, rport->pid);
1773 cbfn = bfa_fcs_rport_gpnid_response;
1776 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1777 FC_CLASS_3, len, &fchs, cbfn,
1778 (void *)rport, FC_MAX_PDUSZ, FC_FCCT_TOV);
1780 bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
1784 bfa_fcs_rport_gidpn_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1785 bfa_status_t req_status, u32 rsp_len,
1786 u32 resid_len, struct fchs_s *rsp_fchs)
1788 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
1789 struct ct_hdr_s *cthdr;
1790 struct fcgs_gidpn_resp_s *gidpn_rsp;
1791 struct bfa_fcs_rport_s *twin;
1792 struct list_head *qe;
1794 bfa_trc(rport->fcs, rport->pwwn);
1796 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
1797 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
1799 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
1800 /* Check if the pid is the same as before. */
1801 gidpn_rsp = (struct fcgs_gidpn_resp_s *) (cthdr + 1);
1803 if (gidpn_rsp->dap == rport->pid) {
1804 /* Device is online */
1805 bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
1808 * Device's PID has changed. We need to cleanup
1809 * and re-login. If there is another device with
1810 * the the newly discovered pid, send an scn notice
1811 * so that its new pid can be discovered.
1813 list_for_each(qe, &rport->port->rport_q) {
1814 twin = (struct bfa_fcs_rport_s *) qe;
1817 if (gidpn_rsp->dap == twin->pid) {
1818 bfa_trc(rport->fcs, twin->pid);
1819 bfa_trc(rport->fcs, rport->pid);
1822 bfa_sm_send_event(twin,
1823 RPSM_EVENT_ADDRESS_CHANGE);
1826 rport->pid = gidpn_rsp->dap;
1827 bfa_sm_send_event(rport, RPSM_EVENT_ADDRESS_CHANGE);
1835 switch (cthdr->reason_code) {
1836 case CT_RSN_LOGICAL_BUSY:
1840 bfa_sm_send_event(rport, RPSM_EVENT_TIMEOUT);
1843 case CT_RSN_UNABLE_TO_PERF:
1845 * device doesn't exist : Start timer to cleanup this later.
1847 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1851 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1857 bfa_fcs_rport_gpnid_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1858 bfa_status_t req_status, u32 rsp_len,
1859 u32 resid_len, struct fchs_s *rsp_fchs)
1861 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
1862 struct ct_hdr_s *cthdr;
1864 bfa_trc(rport->fcs, rport->pwwn);
1866 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
1867 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
1869 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
1870 bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
1877 switch (cthdr->reason_code) {
1878 case CT_RSN_LOGICAL_BUSY:
1882 bfa_sm_send_event(rport, RPSM_EVENT_TIMEOUT);
1885 case CT_RSN_UNABLE_TO_PERF:
1887 * device doesn't exist : Start timer to cleanup this later.
1889 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1893 bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
1899 * Called to send a logout to the rport.
1902 bfa_fcs_rport_send_logo(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1904 struct bfa_fcs_rport_s *rport = rport_cbarg;
1905 struct bfa_fcs_lport_s *port;
1907 struct bfa_fcxp_s *fcxp;
1910 bfa_trc(rport->fcs, rport->pid);
1914 fcxp = fcxp_alloced ? fcxp_alloced :
1915 bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
1917 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
1918 bfa_fcs_rport_send_logo, rport, BFA_FALSE);
1923 len = fc_logo_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
1924 bfa_fcs_lport_get_fcid(port), 0,
1925 bfa_fcs_lport_get_pwwn(port));
1927 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1928 FC_CLASS_3, len, &fchs, NULL,
1929 rport, FC_MAX_PDUSZ, FC_ELS_TOV);
1931 rport->stats.logos++;
1932 bfa_fcxp_discard(rport->fcxp);
1933 bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
1937 * Send ACC for a LOGO received.
1940 bfa_fcs_rport_send_logo_acc(void *rport_cbarg)
1942 struct bfa_fcs_rport_s *rport = rport_cbarg;
1943 struct bfa_fcs_lport_s *port;
1945 struct bfa_fcxp_s *fcxp;
1948 bfa_trc(rport->fcs, rport->pid);
1952 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
1956 rport->stats.logo_rcvd++;
1957 len = fc_logo_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1958 rport->pid, bfa_fcs_lport_get_fcid(port),
1961 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1962 FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
1967 * This routine will be called by bfa_timer on timer timeouts.
1969 * param[in] rport - pointer to bfa_fcs_lport_ns_t.
1970 * param[out] rport_status - pointer to return vport status in
1975 * Special Considerations:
1980 bfa_fcs_rport_timeout(void *arg)
1982 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) arg;
1984 rport->stats.plogi_timeouts++;
1985 bfa_stats(rport->port, rport_plogi_timeouts);
1986 bfa_sm_send_event(rport, RPSM_EVENT_TIMEOUT);
1990 bfa_fcs_rport_process_prli(struct bfa_fcs_rport_s *rport,
1991 struct fchs_s *rx_fchs, u16 len)
1993 struct bfa_fcxp_s *fcxp;
1995 struct bfa_fcs_lport_s *port = rport->port;
1996 struct fc_prli_s *prli;
1998 bfa_trc(port->fcs, rx_fchs->s_id);
1999 bfa_trc(port->fcs, rx_fchs->d_id);
2001 rport->stats.prli_rcvd++;
2004 * We are in Initiator Mode
2006 prli = (struct fc_prli_s *) (rx_fchs + 1);
2008 if (prli->parampage.servparams.target) {
2010 * PRLI from a target ?
2012 * PRLI sent by us will be used to transition the IT nexus,
2013 * once the response is received from the target.
2015 bfa_trc(port->fcs, rx_fchs->s_id);
2016 rport->scsi_function = BFA_RPORT_TARGET;
2018 bfa_trc(rport->fcs, prli->parampage.type);
2019 rport->scsi_function = BFA_RPORT_INITIATOR;
2020 bfa_fcs_itnim_is_initiator(rport->itnim);
2023 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
2027 len = fc_prli_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
2028 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
2029 rx_fchs->ox_id, port->port_cfg.roles);
2031 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
2032 FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
2036 bfa_fcs_rport_process_rpsc(struct bfa_fcs_rport_s *rport,
2037 struct fchs_s *rx_fchs, u16 len)
2039 struct bfa_fcxp_s *fcxp;
2041 struct bfa_fcs_lport_s *port = rport->port;
2042 struct fc_rpsc_speed_info_s speeds;
2043 struct bfa_port_attr_s pport_attr;
2045 bfa_trc(port->fcs, rx_fchs->s_id);
2046 bfa_trc(port->fcs, rx_fchs->d_id);
2048 rport->stats.rpsc_rcvd++;
2049 speeds.port_speed_cap =
2050 RPSC_SPEED_CAP_1G | RPSC_SPEED_CAP_2G | RPSC_SPEED_CAP_4G |
2054 * get curent speed from pport attributes from BFA
2056 bfa_fcport_get_attr(port->fcs->bfa, &pport_attr);
2058 speeds.port_op_speed = fc_bfa_speed_to_rpsc_operspeed(pport_attr.speed);
2060 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
2064 len = fc_rpsc_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
2065 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
2066 rx_fchs->ox_id, &speeds);
2068 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
2069 FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
2073 bfa_fcs_rport_process_adisc(struct bfa_fcs_rport_s *rport,
2074 struct fchs_s *rx_fchs, u16 len)
2076 struct bfa_fcxp_s *fcxp;
2078 struct bfa_fcs_lport_s *port = rport->port;
2079 struct fc_adisc_s *adisc;
2081 bfa_trc(port->fcs, rx_fchs->s_id);
2082 bfa_trc(port->fcs, rx_fchs->d_id);
2084 rport->stats.adisc_rcvd++;
2086 adisc = (struct fc_adisc_s *) (rx_fchs + 1);
2089 * Accept if the itnim for this rport is online.
2090 * Else reject the ADISC.
2092 if (bfa_fcs_itnim_get_online_state(rport->itnim) == BFA_STATUS_OK) {
2094 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
2098 len = fc_adisc_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
2099 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
2100 rx_fchs->ox_id, port->port_cfg.pwwn,
2101 port->port_cfg.nwwn);
2103 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag,
2104 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
2107 rport->stats.adisc_rejected++;
2108 bfa_fcs_rport_send_ls_rjt(rport, rx_fchs,
2109 FC_LS_RJT_RSN_UNABLE_TO_PERF_CMD,
2110 FC_LS_RJT_EXP_LOGIN_REQUIRED);
2115 bfa_fcs_rport_hal_online(struct bfa_fcs_rport_s *rport)
2117 struct bfa_fcs_lport_s *port = rport->port;
2118 struct bfa_rport_info_s rport_info;
2120 rport_info.pid = rport->pid;
2121 rport_info.local_pid = port->pid;
2122 rport_info.lp_tag = port->lp_tag;
2123 rport_info.vf_id = port->fabric->vf_id;
2124 rport_info.vf_en = port->fabric->is_vf;
2125 rport_info.fc_class = rport->fc_cos;
2126 rport_info.cisc = rport->cisc;
2127 rport_info.max_frmsz = rport->maxfrsize;
2128 bfa_rport_online(rport->bfa_rport, &rport_info);
2132 bfa_fcs_rport_hal_offline(struct bfa_fcs_rport_s *rport)
2134 if (rport->bfa_rport)
2135 bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE);
2137 bfa_cb_rport_offline(rport);
2140 static struct bfa_fcs_rport_s *
2141 bfa_fcs_rport_alloc(struct bfa_fcs_lport_s *port, wwn_t pwwn, u32 rpid)
2143 struct bfa_fcs_s *fcs = port->fcs;
2144 struct bfa_fcs_rport_s *rport;
2145 struct bfad_rport_s *rport_drv;
2150 if (fcs->num_rport_logins >= bfa_fcs_rport_max_logins) {
2155 if (bfa_fcb_rport_alloc(fcs->bfad, &rport, &rport_drv)
2166 rport->rp_drv = rport_drv;
2171 rport->bfa_rport = NULL;
2176 WARN_ON(!bfa_fcs_lport_is_initiator(port));
2178 if (bfa_fcs_lport_is_initiator(port)) {
2179 rport->itnim = bfa_fcs_itnim_create(rport);
2180 if (!rport->itnim) {
2187 bfa_fcs_lport_add_rport(port, rport);
2188 fcs->num_rport_logins++;
2190 bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
2192 /* Initialize the Rport Features(RPF) Sub Module */
2193 if (!BFA_FCS_PID_IS_WKA(rport->pid))
2194 bfa_fcs_rpf_init(rport);
2201 bfa_fcs_rport_free(struct bfa_fcs_rport_s *rport)
2203 struct bfa_fcs_lport_s *port = rport->port;
2204 struct bfa_fcs_s *fcs = port->fcs;
2208 * - delete BFA rport
2209 * - remove from queue of rports
2211 rport->plogi_pending = BFA_FALSE;
2213 if (bfa_fcs_lport_is_initiator(port)) {
2214 bfa_fcs_itnim_delete(rport->itnim);
2215 if (rport->pid != 0 && !BFA_FCS_PID_IS_WKA(rport->pid))
2216 bfa_fcs_rpf_rport_offline(rport);
2219 if (rport->bfa_rport) {
2220 bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_DELETE);
2221 rport->bfa_rport = NULL;
2224 bfa_fcs_lport_del_rport(port, rport);
2225 fcs->num_rport_logins--;
2226 kfree(rport->rp_drv);
2230 bfa_fcs_rport_aen_post(struct bfa_fcs_rport_s *rport,
2231 enum bfa_rport_aen_event event,
2232 struct bfa_rport_aen_data_s *data)
2234 struct bfa_fcs_lport_s *port = rport->port;
2235 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
2236 struct bfa_aen_entry_s *aen_entry;
2238 bfad_get_aen_entry(bfad, aen_entry);
2242 if (event == BFA_RPORT_AEN_QOS_PRIO)
2243 aen_entry->aen_data.rport.priv.qos = data->priv.qos;
2244 else if (event == BFA_RPORT_AEN_QOS_FLOWID)
2245 aen_entry->aen_data.rport.priv.qos = data->priv.qos;
2247 aen_entry->aen_data.rport.vf_id = rport->port->fabric->vf_id;
2248 aen_entry->aen_data.rport.ppwwn = bfa_fcs_lport_get_pwwn(
2249 bfa_fcs_get_base_port(rport->fcs));
2250 aen_entry->aen_data.rport.lpwwn = bfa_fcs_lport_get_pwwn(rport->port);
2251 aen_entry->aen_data.rport.rpwwn = rport->pwwn;
2253 /* Send the AEN notification */
2254 bfad_im_post_vendor_event(aen_entry, bfad, ++rport->fcs->fcs_aen_seq,
2255 BFA_AEN_CAT_RPORT, event);
2259 bfa_fcs_rport_fcs_online_action(struct bfa_fcs_rport_s *rport)
2261 if ((!rport->pid) || (!rport->pwwn)) {
2262 bfa_trc(rport->fcs, rport->pid);
2263 bfa_sm_fault(rport->fcs, rport->pid);
2266 bfa_sm_send_event(rport->itnim, BFA_FCS_ITNIM_SM_FCS_ONLINE);
2270 bfa_fcs_rport_hal_online_action(struct bfa_fcs_rport_s *rport)
2272 struct bfa_fcs_lport_s *port = rport->port;
2273 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
2274 char lpwwn_buf[BFA_STRING_32];
2275 char rpwwn_buf[BFA_STRING_32];
2277 rport->stats.onlines++;
2279 if ((!rport->pid) || (!rport->pwwn)) {
2280 bfa_trc(rport->fcs, rport->pid);
2281 bfa_sm_fault(rport->fcs, rport->pid);
2284 if (bfa_fcs_lport_is_initiator(port)) {
2285 bfa_fcs_itnim_brp_online(rport->itnim);
2286 if (!BFA_FCS_PID_IS_WKA(rport->pid))
2287 bfa_fcs_rpf_rport_online(rport);
2290 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
2291 wwn2str(rpwwn_buf, rport->pwwn);
2292 if (!BFA_FCS_PID_IS_WKA(rport->pid)) {
2293 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
2294 "Remote port (WWN = %s) online for logical port (WWN = %s)\n",
2295 rpwwn_buf, lpwwn_buf);
2296 bfa_fcs_rport_aen_post(rport, BFA_RPORT_AEN_ONLINE, NULL);
2301 bfa_fcs_rport_fcs_offline_action(struct bfa_fcs_rport_s *rport)
2303 if (!BFA_FCS_PID_IS_WKA(rport->pid))
2304 bfa_fcs_rpf_rport_offline(rport);
2306 bfa_fcs_itnim_rport_offline(rport->itnim);
2310 bfa_fcs_rport_hal_offline_action(struct bfa_fcs_rport_s *rport)
2312 struct bfa_fcs_lport_s *port = rport->port;
2313 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
2314 char lpwwn_buf[BFA_STRING_32];
2315 char rpwwn_buf[BFA_STRING_32];
2317 if (!rport->bfa_rport) {
2318 bfa_fcs_rport_fcs_offline_action(rport);
2322 rport->stats.offlines++;
2324 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
2325 wwn2str(rpwwn_buf, rport->pwwn);
2326 if (!BFA_FCS_PID_IS_WKA(rport->pid)) {
2327 if (bfa_fcs_lport_is_online(rport->port) == BFA_TRUE) {
2328 BFA_LOG(KERN_ERR, bfad, bfa_log_level,
2329 "Remote port (WWN = %s) connectivity lost for "
2330 "logical port (WWN = %s)\n",
2331 rpwwn_buf, lpwwn_buf);
2332 bfa_fcs_rport_aen_post(rport,
2333 BFA_RPORT_AEN_DISCONNECT, NULL);
2335 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
2336 "Remote port (WWN = %s) offlined by "
2337 "logical port (WWN = %s)\n",
2338 rpwwn_buf, lpwwn_buf);
2339 bfa_fcs_rport_aen_post(rport,
2340 BFA_RPORT_AEN_OFFLINE, NULL);
2344 if (bfa_fcs_lport_is_initiator(port)) {
2345 bfa_fcs_itnim_rport_offline(rport->itnim);
2346 if (!BFA_FCS_PID_IS_WKA(rport->pid))
2347 bfa_fcs_rpf_rport_offline(rport);
2352 * Update rport parameters from PLOGI or PLOGI accept.
2355 bfa_fcs_rport_update(struct bfa_fcs_rport_s *rport, struct fc_logi_s *plogi)
2357 bfa_fcs_lport_t *port = rport->port;
2363 rport->pwwn = plogi->port_name;
2364 rport->nwwn = plogi->node_name;
2367 * - class of service
2370 if (plogi->class3.class_valid)
2371 rport->fc_cos = FC_CLASS_3;
2373 if (plogi->class2.class_valid)
2374 rport->fc_cos |= FC_CLASS_2;
2378 * - MAX receive frame size
2380 rport->cisc = plogi->csp.cisc;
2381 if (be16_to_cpu(plogi->class3.rxsz) < be16_to_cpu(plogi->csp.rxsz))
2382 rport->maxfrsize = be16_to_cpu(plogi->class3.rxsz);
2384 rport->maxfrsize = be16_to_cpu(plogi->csp.rxsz);
2386 bfa_trc(port->fcs, be16_to_cpu(plogi->csp.bbcred));
2387 bfa_trc(port->fcs, port->fabric->bb_credit);
2389 * Direct Attach P2P mode :
2390 * This is to handle a bug (233476) in IBM targets in Direct Attach
2391 * Mode. Basically, in FLOGI Accept the target would have
2392 * erroneously set the BB Credit to the value used in the FLOGI
2393 * sent by the HBA. It uses the correct value (its own BB credit)
2396 if ((!bfa_fcs_fabric_is_switched(port->fabric)) &&
2397 (be16_to_cpu(plogi->csp.bbcred) < port->fabric->bb_credit)) {
2399 bfa_trc(port->fcs, be16_to_cpu(plogi->csp.bbcred));
2400 bfa_trc(port->fcs, port->fabric->bb_credit);
2402 port->fabric->bb_credit = be16_to_cpu(plogi->csp.bbcred);
2403 bfa_fcport_set_tx_bbcredit(port->fcs->bfa,
2404 port->fabric->bb_credit, 0);
2410 * Called to handle LOGO received from an existing remote port.
2413 bfa_fcs_rport_process_logo(struct bfa_fcs_rport_s *rport, struct fchs_s *fchs)
2415 rport->reply_oxid = fchs->ox_id;
2416 bfa_trc(rport->fcs, rport->reply_oxid);
2418 rport->prlo = BFA_FALSE;
2419 rport->stats.logo_rcvd++;
2420 bfa_sm_send_event(rport, RPSM_EVENT_LOGO_RCVD);
2426 * fcs_rport_public FCS rport public interfaces
2430 * Called by bport/vport to create a remote port instance for a discovered
2433 * @param[in] port - base port or vport
2434 * @param[in] rpid - remote port ID
2438 struct bfa_fcs_rport_s *
2439 bfa_fcs_rport_create(struct bfa_fcs_lport_s *port, u32 rpid)
2441 struct bfa_fcs_rport_s *rport;
2443 bfa_trc(port->fcs, rpid);
2444 rport = bfa_fcs_rport_alloc(port, WWN_NULL, rpid);
2448 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_SEND);
2453 * Called to create a rport for which only the wwn is known.
2455 * @param[in] port - base port
2456 * @param[in] rpwwn - remote port wwn
2460 struct bfa_fcs_rport_s *
2461 bfa_fcs_rport_create_by_wwn(struct bfa_fcs_lport_s *port, wwn_t rpwwn)
2463 struct bfa_fcs_rport_s *rport;
2464 bfa_trc(port->fcs, rpwwn);
2465 rport = bfa_fcs_rport_alloc(port, rpwwn, 0);
2469 bfa_sm_send_event(rport, RPSM_EVENT_ADDRESS_DISC);
2473 * Called by bport in private loop topology to indicate that a
2474 * rport has been discovered and plogi has been completed.
2476 * @param[in] port - base port or vport
2477 * @param[in] rpid - remote port ID
2480 bfa_fcs_rport_start(struct bfa_fcs_lport_s *port, struct fchs_s *fchs,
2481 struct fc_logi_s *plogi)
2483 struct bfa_fcs_rport_s *rport;
2485 rport = bfa_fcs_rport_alloc(port, WWN_NULL, fchs->s_id);
2489 bfa_fcs_rport_update(rport, plogi);
2491 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_COMP);
2495 * Called by bport/vport to handle PLOGI received from a new remote port.
2496 * If an existing rport does a plogi, it will be handled separately.
2499 bfa_fcs_rport_plogi_create(struct bfa_fcs_lport_s *port, struct fchs_s *fchs,
2500 struct fc_logi_s *plogi)
2502 struct bfa_fcs_rport_s *rport;
2504 rport = bfa_fcs_rport_alloc(port, plogi->port_name, fchs->s_id);
2508 bfa_fcs_rport_update(rport, plogi);
2510 rport->reply_oxid = fchs->ox_id;
2511 bfa_trc(rport->fcs, rport->reply_oxid);
2513 rport->stats.plogi_rcvd++;
2514 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RCVD);
2518 * Called by bport/vport to handle PLOGI received from an existing
2522 bfa_fcs_rport_plogi(struct bfa_fcs_rport_s *rport, struct fchs_s *rx_fchs,
2523 struct fc_logi_s *plogi)
2526 * @todo Handle P2P and initiator-initiator.
2529 bfa_fcs_rport_update(rport, plogi);
2531 rport->reply_oxid = rx_fchs->ox_id;
2532 bfa_trc(rport->fcs, rport->reply_oxid);
2534 rport->pid = rx_fchs->s_id;
2535 bfa_trc(rport->fcs, rport->pid);
2537 rport->stats.plogi_rcvd++;
2538 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RCVD);
2543 * Called by bport/vport to notify SCN for the remote port
2546 bfa_fcs_rport_scn(struct bfa_fcs_rport_s *rport)
2548 rport->stats.rscns++;
2549 bfa_sm_send_event(rport, RPSM_EVENT_SCN);
2554 * This routine BFA callback for bfa_rport_online() call.
2556 * param[in] cb_arg - rport struct.
2561 * Special Considerations:
2566 bfa_cb_rport_online(void *cbarg)
2569 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
2571 bfa_trc(rport->fcs, rport->pwwn);
2572 bfa_sm_send_event(rport, RPSM_EVENT_HCB_ONLINE);
2577 * This routine BFA callback for bfa_rport_offline() call.
2584 * Special Considerations:
2589 bfa_cb_rport_offline(void *cbarg)
2591 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
2593 bfa_trc(rport->fcs, rport->pwwn);
2594 bfa_sm_send_event(rport, RPSM_EVENT_HCB_OFFLINE);
2599 * This routine is a static BFA callback when there is a QoS flow_id
2600 * change notification
2607 * Special Considerations:
2612 bfa_cb_rport_qos_scn_flowid(void *cbarg,
2613 struct bfa_rport_qos_attr_s old_qos_attr,
2614 struct bfa_rport_qos_attr_s new_qos_attr)
2616 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
2617 struct bfa_rport_aen_data_s aen_data;
2619 bfa_trc(rport->fcs, rport->pwwn);
2620 aen_data.priv.qos = new_qos_attr;
2621 bfa_fcs_rport_aen_post(rport, BFA_RPORT_AEN_QOS_FLOWID, &aen_data);
2626 * This routine is a static BFA callback when there is a QoS priority
2627 * change notification
2634 * Special Considerations:
2639 bfa_cb_rport_qos_scn_prio(void *cbarg,
2640 struct bfa_rport_qos_attr_s old_qos_attr,
2641 struct bfa_rport_qos_attr_s new_qos_attr)
2643 struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg;
2644 struct bfa_rport_aen_data_s aen_data;
2646 bfa_trc(rport->fcs, rport->pwwn);
2647 aen_data.priv.qos = new_qos_attr;
2648 bfa_fcs_rport_aen_post(rport, BFA_RPORT_AEN_QOS_PRIO, &aen_data);
2652 * Called to process any unsolicted frames from this remote port
2655 bfa_fcs_rport_uf_recv(struct bfa_fcs_rport_s *rport,
2656 struct fchs_s *fchs, u16 len)
2658 struct bfa_fcs_lport_s *port = rport->port;
2659 struct fc_els_cmd_s *els_cmd;
2661 bfa_trc(rport->fcs, fchs->s_id);
2662 bfa_trc(rport->fcs, fchs->d_id);
2663 bfa_trc(rport->fcs, fchs->type);
2665 if (fchs->type != FC_TYPE_ELS)
2668 els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
2670 bfa_trc(rport->fcs, els_cmd->els_code);
2672 switch (els_cmd->els_code) {
2674 bfa_stats(port, plogi_rcvd);
2675 bfa_fcs_rport_process_logo(rport, fchs);
2679 bfa_stats(port, adisc_rcvd);
2680 bfa_fcs_rport_process_adisc(rport, fchs, len);
2684 bfa_stats(port, prlo_rcvd);
2685 if (bfa_fcs_lport_is_initiator(port))
2686 bfa_fcs_fcpim_uf_recv(rport->itnim, fchs, len);
2690 bfa_stats(port, prli_rcvd);
2691 bfa_fcs_rport_process_prli(rport, fchs, len);
2695 bfa_stats(port, rpsc_rcvd);
2696 bfa_fcs_rport_process_rpsc(rport, fchs, len);
2700 bfa_stats(port, un_handled_els_rcvd);
2701 bfa_fcs_rport_send_ls_rjt(rport, fchs,
2702 FC_LS_RJT_RSN_CMD_NOT_SUPP,
2703 FC_LS_RJT_EXP_NO_ADDL_INFO);
2708 /* send best case acc to prlo */
2710 bfa_fcs_rport_send_prlo_acc(struct bfa_fcs_rport_s *rport)
2712 struct bfa_fcs_lport_s *port = rport->port;
2714 struct bfa_fcxp_s *fcxp;
2717 bfa_trc(rport->fcs, rport->pid);
2719 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
2722 len = fc_prlo_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
2723 rport->pid, bfa_fcs_lport_get_fcid(port),
2724 rport->reply_oxid, 0);
2726 bfa_fcxp_send(fcxp, rport->bfa_rport, port->fabric->vf_id,
2727 port->lp_tag, BFA_FALSE, FC_CLASS_3, len, &fchs,
2728 NULL, NULL, FC_MAX_PDUSZ, 0);
2735 bfa_fcs_rport_send_ls_rjt(struct bfa_fcs_rport_s *rport, struct fchs_s *rx_fchs,
2736 u8 reason_code, u8 reason_code_expl)
2738 struct bfa_fcs_lport_s *port = rport->port;
2740 struct bfa_fcxp_s *fcxp;
2743 bfa_trc(rport->fcs, rx_fchs->s_id);
2745 fcxp = bfa_fcs_fcxp_alloc(rport->fcs, BFA_FALSE);
2749 len = fc_ls_rjt_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
2750 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
2751 rx_fchs->ox_id, reason_code, reason_code_expl);
2753 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag,
2754 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
2759 * Return state of rport.
2762 bfa_fcs_rport_get_state(struct bfa_fcs_rport_s *rport)
2764 return bfa_sm_to_state(rport_sm_table, rport->sm);
2770 * Called by the Driver to set rport delete/ageout timeout
2772 * param[in] rport timeout value in seconds.
2777 bfa_fcs_rport_set_del_timeout(u8 rport_tmo)
2779 /* convert to Millisecs */
2781 bfa_fcs_rport_del_timeout = rport_tmo * 1000;
2784 bfa_fcs_rport_prlo(struct bfa_fcs_rport_s *rport, __be16 ox_id)
2786 bfa_trc(rport->fcs, rport->pid);
2788 rport->prlo = BFA_TRUE;
2789 rport->reply_oxid = ox_id;
2790 bfa_sm_send_event(rport, RPSM_EVENT_PRLO_RCVD);
2794 * Called by BFAD to set the max limit on number of bfa_fcs_rport allocation
2795 * which limits number of concurrent logins to remote ports
2798 bfa_fcs_rport_set_max_logins(u32 max_logins)
2801 bfa_fcs_rport_max_logins = max_logins;
2805 bfa_fcs_rport_get_attr(struct bfa_fcs_rport_s *rport,
2806 struct bfa_rport_attr_s *rport_attr)
2808 struct bfa_rport_qos_attr_s qos_attr;
2809 struct bfa_fcs_lport_s *port = rport->port;
2810 bfa_port_speed_t rport_speed = rport->rpf.rpsc_speed;
2812 memset(rport_attr, 0, sizeof(struct bfa_rport_attr_s));
2813 memset(&qos_attr, 0, sizeof(struct bfa_rport_qos_attr_s));
2815 rport_attr->pid = rport->pid;
2816 rport_attr->pwwn = rport->pwwn;
2817 rport_attr->nwwn = rport->nwwn;
2818 rport_attr->cos_supported = rport->fc_cos;
2819 rport_attr->df_sz = rport->maxfrsize;
2820 rport_attr->state = bfa_fcs_rport_get_state(rport);
2821 rport_attr->fc_cos = rport->fc_cos;
2822 rport_attr->cisc = rport->cisc;
2823 rport_attr->scsi_function = rport->scsi_function;
2824 rport_attr->curr_speed = rport->rpf.rpsc_speed;
2825 rport_attr->assigned_speed = rport->rpf.assigned_speed;
2827 if (rport->bfa_rport) {
2828 qos_attr.qos_priority = rport->bfa_rport->qos_attr.qos_priority;
2829 qos_attr.qos_flow_id =
2830 cpu_to_be32(rport->bfa_rport->qos_attr.qos_flow_id);
2832 rport_attr->qos_attr = qos_attr;
2834 rport_attr->trl_enforced = BFA_FALSE;
2835 if (bfa_fcport_is_ratelim(port->fcs->bfa) &&
2836 (rport->scsi_function == BFA_RPORT_TARGET)) {
2837 if (rport_speed == BFA_PORT_SPEED_UNKNOWN)
2839 bfa_fcport_get_ratelim_speed(rport->fcs->bfa);
2841 if (rport_speed < bfa_fcs_lport_get_rport_max_speed(port))
2842 rport_attr->trl_enforced = BFA_TRUE;
2847 * Remote port implementation.
2851 * fcs_rport_api FCS rport API.
2854 struct bfa_fcs_rport_s *
2855 bfa_fcs_rport_lookup(struct bfa_fcs_lport_s *port, wwn_t rpwwn)
2857 struct bfa_fcs_rport_s *rport;
2859 rport = bfa_fcs_lport_get_rport_by_pwwn(port, rpwwn);
2860 if (rport == NULL) {
2862 * TBD Error handling
2869 struct bfa_fcs_rport_s *
2870 bfa_fcs_rport_lookup_by_nwwn(struct bfa_fcs_lport_s *port, wwn_t rnwwn)
2872 struct bfa_fcs_rport_s *rport;
2874 rport = bfa_fcs_lport_get_rport_by_nwwn(port, rnwwn);
2875 if (rport == NULL) {
2877 * TBD Error handling
2885 * Remote port features (RPF) implementation.
2888 #define BFA_FCS_RPF_RETRIES (3)
2889 #define BFA_FCS_RPF_RETRY_TIMEOUT (1000) /* 1 sec (In millisecs) */
2891 static void bfa_fcs_rpf_send_rpsc2(void *rport_cbarg,
2892 struct bfa_fcxp_s *fcxp_alloced);
2893 static void bfa_fcs_rpf_rpsc2_response(void *fcsarg,
2894 struct bfa_fcxp_s *fcxp,
2896 bfa_status_t req_status,
2899 struct fchs_s *rsp_fchs);
2901 static void bfa_fcs_rpf_timeout(void *arg);
2904 * fcs_rport_ftrs_sm FCS rport state machine events
2908 RPFSM_EVENT_RPORT_OFFLINE = 1, /* Rport offline */
2909 RPFSM_EVENT_RPORT_ONLINE = 2, /* Rport online */
2910 RPFSM_EVENT_FCXP_SENT = 3, /* Frame from has been sent */
2911 RPFSM_EVENT_TIMEOUT = 4, /* Rport SM timeout event */
2912 RPFSM_EVENT_RPSC_COMP = 5,
2913 RPFSM_EVENT_RPSC_FAIL = 6,
2914 RPFSM_EVENT_RPSC_ERROR = 7,
2917 static void bfa_fcs_rpf_sm_uninit(struct bfa_fcs_rpf_s *rpf,
2918 enum rpf_event event);
2919 static void bfa_fcs_rpf_sm_rpsc_sending(struct bfa_fcs_rpf_s *rpf,
2920 enum rpf_event event);
2921 static void bfa_fcs_rpf_sm_rpsc(struct bfa_fcs_rpf_s *rpf,
2922 enum rpf_event event);
2923 static void bfa_fcs_rpf_sm_rpsc_retry(struct bfa_fcs_rpf_s *rpf,
2924 enum rpf_event event);
2925 static void bfa_fcs_rpf_sm_offline(struct bfa_fcs_rpf_s *rpf,
2926 enum rpf_event event);
2927 static void bfa_fcs_rpf_sm_online(struct bfa_fcs_rpf_s *rpf,
2928 enum rpf_event event);
2931 bfa_fcs_rpf_sm_uninit(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
2933 struct bfa_fcs_rport_s *rport = rpf->rport;
2934 struct bfa_fcs_fabric_s *fabric = &rport->fcs->fabric;
2936 bfa_trc(rport->fcs, rport->pwwn);
2937 bfa_trc(rport->fcs, rport->pid);
2938 bfa_trc(rport->fcs, event);
2941 case RPFSM_EVENT_RPORT_ONLINE:
2942 /* Send RPSC2 to a Brocade fabric only. */
2943 if ((!BFA_FCS_PID_IS_WKA(rport->pid)) &&
2944 ((rport->port->fabric->lps->brcd_switch) ||
2945 (bfa_fcs_fabric_get_switch_oui(fabric) ==
2946 BFA_FCS_BRCD_SWITCH_OUI))) {
2947 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
2948 rpf->rpsc_retries = 0;
2949 bfa_fcs_rpf_send_rpsc2(rpf, NULL);
2953 case RPFSM_EVENT_RPORT_OFFLINE:
2957 bfa_sm_fault(rport->fcs, event);
2962 bfa_fcs_rpf_sm_rpsc_sending(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
2964 struct bfa_fcs_rport_s *rport = rpf->rport;
2966 bfa_trc(rport->fcs, event);
2969 case RPFSM_EVENT_FCXP_SENT:
2970 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc);
2973 case RPFSM_EVENT_RPORT_OFFLINE:
2974 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
2975 bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rpf->fcxp_wqe);
2976 rpf->rpsc_retries = 0;
2980 bfa_sm_fault(rport->fcs, event);
2985 bfa_fcs_rpf_sm_rpsc(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
2987 struct bfa_fcs_rport_s *rport = rpf->rport;
2989 bfa_trc(rport->fcs, rport->pid);
2990 bfa_trc(rport->fcs, event);
2993 case RPFSM_EVENT_RPSC_COMP:
2994 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
2995 /* Update speed info in f/w via BFA */
2996 if (rpf->rpsc_speed != BFA_PORT_SPEED_UNKNOWN)
2997 bfa_rport_speed(rport->bfa_rport, rpf->rpsc_speed);
2998 else if (rpf->assigned_speed != BFA_PORT_SPEED_UNKNOWN)
2999 bfa_rport_speed(rport->bfa_rport, rpf->assigned_speed);
3002 case RPFSM_EVENT_RPSC_FAIL:
3003 /* RPSC not supported by rport */
3004 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
3007 case RPFSM_EVENT_RPSC_ERROR:
3008 /* need to retry...delayed a bit. */
3009 if (rpf->rpsc_retries++ < BFA_FCS_RPF_RETRIES) {
3010 bfa_timer_start(rport->fcs->bfa, &rpf->timer,
3011 bfa_fcs_rpf_timeout, rpf,
3012 BFA_FCS_RPF_RETRY_TIMEOUT);
3013 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_retry);
3015 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
3019 case RPFSM_EVENT_RPORT_OFFLINE:
3020 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
3021 bfa_fcxp_discard(rpf->fcxp);
3022 rpf->rpsc_retries = 0;
3026 bfa_sm_fault(rport->fcs, event);
3031 bfa_fcs_rpf_sm_rpsc_retry(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
3033 struct bfa_fcs_rport_s *rport = rpf->rport;
3035 bfa_trc(rport->fcs, rport->pid);
3036 bfa_trc(rport->fcs, event);
3039 case RPFSM_EVENT_TIMEOUT:
3040 /* re-send the RPSC */
3041 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
3042 bfa_fcs_rpf_send_rpsc2(rpf, NULL);
3045 case RPFSM_EVENT_RPORT_OFFLINE:
3046 bfa_timer_stop(&rpf->timer);
3047 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
3048 rpf->rpsc_retries = 0;
3052 bfa_sm_fault(rport->fcs, event);
3057 bfa_fcs_rpf_sm_online(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
3059 struct bfa_fcs_rport_s *rport = rpf->rport;
3061 bfa_trc(rport->fcs, rport->pwwn);
3062 bfa_trc(rport->fcs, rport->pid);
3063 bfa_trc(rport->fcs, event);
3066 case RPFSM_EVENT_RPORT_OFFLINE:
3067 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
3068 rpf->rpsc_retries = 0;
3072 bfa_sm_fault(rport->fcs, event);
3077 bfa_fcs_rpf_sm_offline(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
3079 struct bfa_fcs_rport_s *rport = rpf->rport;
3081 bfa_trc(rport->fcs, rport->pwwn);
3082 bfa_trc(rport->fcs, rport->pid);
3083 bfa_trc(rport->fcs, event);
3086 case RPFSM_EVENT_RPORT_ONLINE:
3087 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
3088 bfa_fcs_rpf_send_rpsc2(rpf, NULL);
3091 case RPFSM_EVENT_RPORT_OFFLINE:
3095 bfa_sm_fault(rport->fcs, event);
3099 * Called when Rport is created.
3102 bfa_fcs_rpf_init(struct bfa_fcs_rport_s *rport)
3104 struct bfa_fcs_rpf_s *rpf = &rport->rpf;
3106 bfa_trc(rport->fcs, rport->pid);
3109 bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_uninit);
3113 * Called when Rport becomes online
3116 bfa_fcs_rpf_rport_online(struct bfa_fcs_rport_s *rport)
3118 bfa_trc(rport->fcs, rport->pid);
3120 if (__fcs_min_cfg(rport->port->fcs))
3123 if (bfa_fcs_fabric_is_switched(rport->port->fabric))
3124 bfa_sm_send_event(&rport->rpf, RPFSM_EVENT_RPORT_ONLINE);
3128 * Called when Rport becomes offline
3131 bfa_fcs_rpf_rport_offline(struct bfa_fcs_rport_s *rport)
3133 bfa_trc(rport->fcs, rport->pid);
3135 if (__fcs_min_cfg(rport->port->fcs))
3138 rport->rpf.rpsc_speed = 0;
3139 bfa_sm_send_event(&rport->rpf, RPFSM_EVENT_RPORT_OFFLINE);
3143 bfa_fcs_rpf_timeout(void *arg)
3145 struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *) arg;
3146 struct bfa_fcs_rport_s *rport = rpf->rport;
3148 bfa_trc(rport->fcs, rport->pid);
3149 bfa_sm_send_event(rpf, RPFSM_EVENT_TIMEOUT);
3153 bfa_fcs_rpf_send_rpsc2(void *rpf_cbarg, struct bfa_fcxp_s *fcxp_alloced)
3155 struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *)rpf_cbarg;
3156 struct bfa_fcs_rport_s *rport = rpf->rport;
3157 struct bfa_fcs_lport_s *port = rport->port;
3160 struct bfa_fcxp_s *fcxp;
3162 bfa_trc(rport->fcs, rport->pwwn);
3164 fcxp = fcxp_alloced ? fcxp_alloced :
3165 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
3167 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rpf->fcxp_wqe,
3168 bfa_fcs_rpf_send_rpsc2, rpf, BFA_TRUE);
3173 len = fc_rpsc2_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
3174 bfa_fcs_lport_get_fcid(port), &rport->pid, 1);
3176 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
3177 FC_CLASS_3, len, &fchs, bfa_fcs_rpf_rpsc2_response,
3178 rpf, FC_MAX_PDUSZ, FC_ELS_TOV);
3179 rport->stats.rpsc_sent++;
3180 bfa_sm_send_event(rpf, RPFSM_EVENT_FCXP_SENT);
3185 bfa_fcs_rpf_rpsc2_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
3186 bfa_status_t req_status, u32 rsp_len,
3187 u32 resid_len, struct fchs_s *rsp_fchs)
3189 struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *) cbarg;
3190 struct bfa_fcs_rport_s *rport = rpf->rport;
3191 struct fc_ls_rjt_s *ls_rjt;
3192 struct fc_rpsc2_acc_s *rpsc2_acc;
3195 bfa_trc(rport->fcs, req_status);
3197 if (req_status != BFA_STATUS_OK) {
3198 bfa_trc(rport->fcs, req_status);
3199 if (req_status == BFA_STATUS_ETIMER)
3200 rport->stats.rpsc_failed++;
3201 bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);
3205 rpsc2_acc = (struct fc_rpsc2_acc_s *) BFA_FCXP_RSP_PLD(fcxp);
3206 if (rpsc2_acc->els_cmd == FC_ELS_ACC) {
3207 rport->stats.rpsc_accs++;
3208 num_ents = be16_to_cpu(rpsc2_acc->num_pids);
3209 bfa_trc(rport->fcs, num_ents);
3211 WARN_ON(rpsc2_acc->port_info[0].pid == rport->pid);
3213 be16_to_cpu(rpsc2_acc->port_info[0].pid));
3215 be16_to_cpu(rpsc2_acc->port_info[0].speed));
3217 be16_to_cpu(rpsc2_acc->port_info[0].index));
3219 rpsc2_acc->port_info[0].type);
3221 if (rpsc2_acc->port_info[0].speed == 0) {
3222 bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);
3226 rpf->rpsc_speed = fc_rpsc_operspeed_to_bfa_speed(
3227 be16_to_cpu(rpsc2_acc->port_info[0].speed));
3229 bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_COMP);
3232 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
3233 bfa_trc(rport->fcs, ls_rjt->reason_code);
3234 bfa_trc(rport->fcs, ls_rjt->reason_code_expl);
3235 rport->stats.rpsc_rejects++;
3236 if (ls_rjt->reason_code == FC_LS_RJT_RSN_CMD_NOT_SUPP)
3237 bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_FAIL);
3239 bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);