Commit | Line | Data |
---|---|---|
7725ccfd | 1 | /* |
a36c61f9 | 2 | * Copyright (c) 2005-2010 Brocade Communications Systems, Inc. |
7725ccfd JH |
3 | * All rights reserved |
4 | * www.brocade.com | |
5 | * | |
6 | * Linux driver for Brocade Fibre Channel Host Bus Adapter. | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify it | |
9 | * under the terms of the GNU General Public License (GPL) Version 2 as | |
10 | * published by the Free Software Foundation | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | */ | |
17 | ||
5fbe25c7 | 18 | /* |
7725ccfd JH |
19 | * rport.c Remote port implementation. |
20 | */ | |
21 | ||
f16a1750 | 22 | #include "bfad_drv.h" |
a36c61f9 KG |
23 | #include "bfa_fcs.h" |
24 | #include "bfa_fcbuild.h" | |
7725ccfd JH |
25 | |
26 | BFA_TRC_FILE(FCS, RPORT); | |
27 | ||
a36c61f9 KG |
28 | static u32 |
29 | bfa_fcs_rport_del_timeout = BFA_FCS_RPORT_DEF_DEL_TIMEOUT * 1000; | |
30 | /* In millisecs */ | |
7725ccfd JH |
31 | /* |
32 | * forward declarations | |
33 | */ | |
a36c61f9 KG |
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, | |
7725ccfd | 44 | struct bfa_fcxp_s *fcxp_alloced); |
a36c61f9 KG |
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, | |
7725ccfd | 52 | struct bfa_fcxp_s *fcxp_alloced); |
a36c61f9 KG |
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, | |
7725ccfd | 58 | struct bfa_fcxp_s *fcxp_alloced); |
a36c61f9 KG |
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, | |
7725ccfd | 68 | struct bfa_fcxp_s *fcxp_alloced); |
a36c61f9 KG |
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, | |
74 | u8 reason_code_expl); | |
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); | |
7725ccfd | 78 | |
a36c61f9 | 79 | static void bfa_fcs_rport_sm_uninit(struct bfa_fcs_rport_s *rport, |
7725ccfd | 80 | enum rport_event event); |
a36c61f9 KG |
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, | |
7725ccfd | 84 | enum rport_event event); |
a36c61f9 KG |
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, | |
7725ccfd | 88 | enum rport_event event); |
a36c61f9 KG |
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, | |
7725ccfd | 94 | enum rport_event event); |
a36c61f9 | 95 | static void bfa_fcs_rport_sm_nsquery(struct bfa_fcs_rport_s *rport, |
7725ccfd | 96 | enum rport_event event); |
a36c61f9 KG |
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, | |
7725ccfd | 116 | enum rport_event event); |
a36c61f9 KG |
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, | |
7725ccfd | 124 | enum rport_event event); |
7725ccfd JH |
125 | |
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}, | |
149 | }; | |
150 | ||
5fbe25c7 | 151 | /* |
a36c61f9 | 152 | * Beginning state. |
7725ccfd JH |
153 | */ |
154 | static void | |
155 | bfa_fcs_rport_sm_uninit(struct bfa_fcs_rport_s *rport, enum rport_event event) | |
156 | { | |
157 | bfa_trc(rport->fcs, rport->pwwn); | |
158 | bfa_trc(rport->fcs, rport->pid); | |
159 | bfa_trc(rport->fcs, event); | |
160 | ||
161 | switch (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); | |
166 | break; | |
167 | ||
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); | |
171 | break; | |
172 | ||
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); | |
176 | break; | |
177 | ||
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; | |
a36c61f9 | 182 | bfa_fcs_rport_send_nsdisc(rport, NULL); |
7725ccfd | 183 | break; |
7725ccfd | 184 | default: |
e641de37 | 185 | bfa_sm_fault(rport->fcs, event); |
7725ccfd JH |
186 | } |
187 | } | |
188 | ||
5fbe25c7 | 189 | /* |
a36c61f9 | 190 | * PLOGI is being sent. |
7725ccfd JH |
191 | */ |
192 | static void | |
193 | bfa_fcs_rport_sm_plogi_sending(struct bfa_fcs_rport_s *rport, | |
a36c61f9 | 194 | enum rport_event event) |
7725ccfd JH |
195 | { |
196 | bfa_trc(rport->fcs, rport->pwwn); | |
197 | bfa_trc(rport->fcs, rport->pid); | |
198 | bfa_trc(rport->fcs, event); | |
199 | ||
200 | switch (event) { | |
201 | case RPSM_EVENT_FCXP_SENT: | |
202 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi); | |
203 | break; | |
204 | ||
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); | |
209 | break; | |
210 | ||
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); | |
215 | break; | |
216 | ||
217 | case RPSM_EVENT_ADDRESS_CHANGE: | |
a36c61f9 KG |
218 | case RPSM_EVENT_SCN: |
219 | /* query the NS */ | |
7725ccfd JH |
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; | |
a36c61f9 | 223 | bfa_fcs_rport_send_nsdisc(rport, NULL); |
7725ccfd JH |
224 | break; |
225 | ||
226 | case RPSM_EVENT_LOGO_IMP: | |
227 | rport->pid = 0; | |
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); | |
233 | break; | |
234 | ||
7725ccfd JH |
235 | |
236 | default: | |
e641de37 | 237 | bfa_sm_fault(rport->fcs, event); |
7725ccfd JH |
238 | } |
239 | } | |
240 | ||
5fbe25c7 | 241 | /* |
a36c61f9 | 242 | * PLOGI is being sent. |
7725ccfd JH |
243 | */ |
244 | static void | |
245 | bfa_fcs_rport_sm_plogiacc_sending(struct bfa_fcs_rport_s *rport, | |
a36c61f9 | 246 | enum rport_event event) |
7725ccfd JH |
247 | { |
248 | bfa_trc(rport->fcs, rport->pwwn); | |
249 | bfa_trc(rport->fcs, rport->pid); | |
250 | bfa_trc(rport->fcs, event); | |
251 | ||
252 | switch (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); | |
256 | break; | |
257 | ||
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); | |
262 | break; | |
263 | ||
a36c61f9 | 264 | case RPSM_EVENT_PLOGI_RCVD: |
d7be54cc | 265 | case RPSM_EVENT_PLOGI_COMP: |
7725ccfd | 266 | case RPSM_EVENT_SCN: |
5fbe25c7 | 267 | /* |
7725ccfd JH |
268 | * Ignore, SCN is possibly online notification. |
269 | */ | |
270 | break; | |
271 | ||
272 | case RPSM_EVENT_ADDRESS_CHANGE: | |
273 | bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe); | |
274 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending); | |
275 | rport->ns_retries = 0; | |
a36c61f9 | 276 | bfa_fcs_rport_send_nsdisc(rport, NULL); |
7725ccfd JH |
277 | break; |
278 | ||
279 | case RPSM_EVENT_LOGO_IMP: | |
280 | rport->pid = 0; | |
281 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline); | |
282 | bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe); | |
283 | bfa_timer_start(rport->fcs->bfa, &rport->timer, | |
284 | bfa_fcs_rport_timeout, rport, | |
285 | bfa_fcs_rport_del_timeout); | |
286 | break; | |
287 | ||
288 | case RPSM_EVENT_HCB_OFFLINE: | |
5fbe25c7 | 289 | /* |
7725ccfd JH |
290 | * Ignore BFA callback, on a PLOGI receive we call bfa offline. |
291 | */ | |
292 | break; | |
293 | ||
294 | default: | |
e641de37 | 295 | bfa_sm_fault(rport->fcs, event); |
7725ccfd JH |
296 | } |
297 | } | |
298 | ||
5fbe25c7 | 299 | /* |
a36c61f9 | 300 | * PLOGI is sent. |
7725ccfd JH |
301 | */ |
302 | static void | |
303 | bfa_fcs_rport_sm_plogi_retry(struct bfa_fcs_rport_s *rport, | |
304 | enum rport_event event) | |
305 | { | |
306 | bfa_trc(rport->fcs, rport->pwwn); | |
307 | bfa_trc(rport->fcs, rport->pid); | |
308 | bfa_trc(rport->fcs, event); | |
309 | ||
310 | switch (event) { | |
7725ccfd | 311 | case RPSM_EVENT_TIMEOUT: |
a36c61f9 KG |
312 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending); |
313 | bfa_fcs_rport_send_plogi(rport, NULL); | |
7725ccfd JH |
314 | break; |
315 | ||
316 | case RPSM_EVENT_DELETE: | |
317 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit); | |
318 | bfa_timer_stop(&rport->timer); | |
319 | bfa_fcs_rport_free(rport); | |
320 | break; | |
321 | ||
4b5e759d | 322 | case RPSM_EVENT_PRLO_RCVD: |
7725ccfd JH |
323 | case RPSM_EVENT_LOGO_RCVD: |
324 | break; | |
325 | ||
326 | case RPSM_EVENT_PLOGI_RCVD: | |
327 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending); | |
328 | bfa_timer_stop(&rport->timer); | |
329 | bfa_fcs_rport_send_plogiacc(rport, NULL); | |
330 | break; | |
331 | ||
332 | case RPSM_EVENT_ADDRESS_CHANGE: | |
a36c61f9 | 333 | case RPSM_EVENT_SCN: |
7725ccfd JH |
334 | bfa_timer_stop(&rport->timer); |
335 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending); | |
336 | rport->ns_retries = 0; | |
a36c61f9 | 337 | bfa_fcs_rport_send_nsdisc(rport, NULL); |
7725ccfd JH |
338 | break; |
339 | ||
340 | case RPSM_EVENT_LOGO_IMP: | |
341 | rport->pid = 0; | |
342 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline); | |
343 | bfa_timer_stop(&rport->timer); | |
344 | bfa_timer_start(rport->fcs->bfa, &rport->timer, | |
345 | bfa_fcs_rport_timeout, rport, | |
346 | bfa_fcs_rport_del_timeout); | |
347 | break; | |
348 | ||
349 | case RPSM_EVENT_PLOGI_COMP: | |
350 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online); | |
351 | bfa_timer_stop(&rport->timer); | |
352 | bfa_fcs_rport_hal_online(rport); | |
353 | break; | |
354 | ||
355 | default: | |
e641de37 | 356 | bfa_sm_fault(rport->fcs, event); |
7725ccfd JH |
357 | } |
358 | } | |
359 | ||
5fbe25c7 | 360 | /* |
a36c61f9 | 361 | * PLOGI is sent. |
7725ccfd JH |
362 | */ |
363 | static void | |
364 | bfa_fcs_rport_sm_plogi(struct bfa_fcs_rport_s *rport, enum rport_event event) | |
365 | { | |
366 | bfa_trc(rport->fcs, rport->pwwn); | |
367 | bfa_trc(rport->fcs, rport->pid); | |
368 | bfa_trc(rport->fcs, event); | |
369 | ||
370 | switch (event) { | |
371 | case RPSM_EVENT_ACCEPTED: | |
372 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online); | |
373 | rport->plogi_retries = 0; | |
374 | bfa_fcs_rport_hal_online(rport); | |
375 | break; | |
376 | ||
377 | case RPSM_EVENT_LOGO_RCVD: | |
378 | bfa_fcs_rport_send_logo_acc(rport); | |
4b5e759d JH |
379 | /* |
380 | * !! fall through !! | |
381 | */ | |
382 | case RPSM_EVENT_PRLO_RCVD: | |
383 | if (rport->prlo == BFA_TRUE) | |
384 | bfa_fcs_rport_send_prlo_acc(rport); | |
385 | ||
7725ccfd JH |
386 | bfa_fcxp_discard(rport->fcxp); |
387 | /* | |
388 | * !! fall through !! | |
389 | */ | |
390 | case RPSM_EVENT_FAILED: | |
a36c61f9 KG |
391 | if (rport->plogi_retries < BFA_FCS_RPORT_MAX_RETRIES) { |
392 | rport->plogi_retries++; | |
393 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_retry); | |
394 | bfa_timer_start(rport->fcs->bfa, &rport->timer, | |
395 | bfa_fcs_rport_timeout, rport, | |
396 | BFA_FCS_RETRY_TIMEOUT); | |
397 | } else { | |
398 | bfa_stats(rport->port, rport_del_max_plogi_retry); | |
399 | rport->pid = 0; | |
400 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline); | |
401 | bfa_timer_start(rport->fcs->bfa, &rport->timer, | |
402 | bfa_fcs_rport_timeout, rport, | |
403 | bfa_fcs_rport_del_timeout); | |
404 | } | |
405 | break; | |
406 | ||
407 | case RPSM_EVENT_PLOGI_RETRY: | |
408 | rport->plogi_retries = 0; | |
7725ccfd JH |
409 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_retry); |
410 | bfa_timer_start(rport->fcs->bfa, &rport->timer, | |
411 | bfa_fcs_rport_timeout, rport, | |
a36c61f9 | 412 | (FC_RA_TOV * 1000)); |
7725ccfd JH |
413 | break; |
414 | ||
415 | case RPSM_EVENT_LOGO_IMP: | |
416 | rport->pid = 0; | |
417 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline); | |
418 | bfa_fcxp_discard(rport->fcxp); | |
419 | bfa_timer_start(rport->fcs->bfa, &rport->timer, | |
420 | bfa_fcs_rport_timeout, rport, | |
421 | bfa_fcs_rport_del_timeout); | |
422 | break; | |
423 | ||
424 | case RPSM_EVENT_ADDRESS_CHANGE: | |
a36c61f9 | 425 | case RPSM_EVENT_SCN: |
7725ccfd JH |
426 | bfa_fcxp_discard(rport->fcxp); |
427 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending); | |
428 | rport->ns_retries = 0; | |
a36c61f9 | 429 | bfa_fcs_rport_send_nsdisc(rport, NULL); |
7725ccfd JH |
430 | break; |
431 | ||
432 | case RPSM_EVENT_PLOGI_RCVD: | |
433 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending); | |
434 | bfa_fcxp_discard(rport->fcxp); | |
435 | bfa_fcs_rport_send_plogiacc(rport, NULL); | |
436 | break; | |
437 | ||
7725ccfd JH |
438 | case RPSM_EVENT_DELETE: |
439 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit); | |
440 | bfa_fcxp_discard(rport->fcxp); | |
441 | bfa_fcs_rport_free(rport); | |
442 | break; | |
443 | ||
444 | case RPSM_EVENT_PLOGI_COMP: | |
445 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online); | |
446 | bfa_fcxp_discard(rport->fcxp); | |
447 | bfa_fcs_rport_hal_online(rport); | |
448 | break; | |
449 | ||
450 | default: | |
e641de37 | 451 | bfa_sm_fault(rport->fcs, event); |
7725ccfd JH |
452 | } |
453 | } | |
454 | ||
5fbe25c7 | 455 | /* |
a36c61f9 KG |
456 | * PLOGI is complete. Awaiting BFA rport online callback. FC-4s |
457 | * are offline. | |
7725ccfd JH |
458 | */ |
459 | static void | |
460 | bfa_fcs_rport_sm_hal_online(struct bfa_fcs_rport_s *rport, | |
461 | enum rport_event event) | |
462 | { | |
463 | bfa_trc(rport->fcs, rport->pwwn); | |
464 | bfa_trc(rport->fcs, rport->pid); | |
465 | bfa_trc(rport->fcs, event); | |
466 | ||
467 | switch (event) { | |
468 | case RPSM_EVENT_HCB_ONLINE: | |
469 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_online); | |
470 | bfa_fcs_rport_online_action(rport); | |
471 | break; | |
472 | ||
4b5e759d | 473 | case RPSM_EVENT_PRLO_RCVD: |
d7be54cc | 474 | case RPSM_EVENT_PLOGI_COMP: |
4b5e759d JH |
475 | break; |
476 | ||
7725ccfd JH |
477 | case RPSM_EVENT_LOGO_RCVD: |
478 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logorcv); | |
f7f73812 | 479 | bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE); |
7725ccfd JH |
480 | break; |
481 | ||
482 | case RPSM_EVENT_LOGO_IMP: | |
483 | case RPSM_EVENT_ADDRESS_CHANGE: | |
484 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_offline); | |
f7f73812 | 485 | bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE); |
7725ccfd JH |
486 | break; |
487 | ||
488 | case RPSM_EVENT_PLOGI_RCVD: | |
d7be54cc KG |
489 | rport->plogi_pending = BFA_TRUE; |
490 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_offline); | |
f7f73812 | 491 | bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE); |
7725ccfd JH |
492 | break; |
493 | ||
494 | case RPSM_EVENT_DELETE: | |
495 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logosend); | |
f7f73812 | 496 | bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE); |
7725ccfd JH |
497 | break; |
498 | ||
499 | case RPSM_EVENT_SCN: | |
5fbe25c7 | 500 | /* |
7725ccfd JH |
501 | * @todo |
502 | * Ignore SCN - PLOGI just completed, FC-4 login should detect | |
503 | * device failures. | |
504 | */ | |
505 | break; | |
506 | ||
507 | default: | |
e641de37 | 508 | bfa_sm_fault(rport->fcs, event); |
7725ccfd JH |
509 | } |
510 | } | |
511 | ||
5fbe25c7 | 512 | /* |
a36c61f9 | 513 | * Rport is ONLINE. FC-4s active. |
7725ccfd JH |
514 | */ |
515 | static void | |
516 | bfa_fcs_rport_sm_online(struct bfa_fcs_rport_s *rport, enum rport_event event) | |
517 | { | |
518 | bfa_trc(rport->fcs, rport->pwwn); | |
519 | bfa_trc(rport->fcs, rport->pid); | |
520 | bfa_trc(rport->fcs, event); | |
521 | ||
522 | switch (event) { | |
523 | case RPSM_EVENT_SCN: | |
7725ccfd JH |
524 | if (bfa_fcs_fabric_is_switched(rport->port->fabric)) { |
525 | bfa_sm_set_state(rport, | |
526 | bfa_fcs_rport_sm_nsquery_sending); | |
527 | rport->ns_retries = 0; | |
a36c61f9 | 528 | bfa_fcs_rport_send_nsdisc(rport, NULL); |
7725ccfd JH |
529 | } else { |
530 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc_sending); | |
531 | bfa_fcs_rport_send_adisc(rport, NULL); | |
532 | } | |
533 | break; | |
534 | ||
535 | case RPSM_EVENT_PLOGI_RCVD: | |
536 | case RPSM_EVENT_LOGO_IMP: | |
537 | case RPSM_EVENT_ADDRESS_CHANGE: | |
538 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline); | |
539 | bfa_fcs_rport_offline_action(rport); | |
540 | break; | |
541 | ||
542 | case RPSM_EVENT_DELETE: | |
543 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend); | |
544 | bfa_fcs_rport_offline_action(rport); | |
545 | break; | |
546 | ||
547 | case RPSM_EVENT_LOGO_RCVD: | |
4b5e759d | 548 | case RPSM_EVENT_PRLO_RCVD: |
7725ccfd JH |
549 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv); |
550 | bfa_fcs_rport_offline_action(rport); | |
551 | break; | |
552 | ||
553 | case RPSM_EVENT_PLOGI_COMP: | |
554 | break; | |
555 | ||
556 | default: | |
e641de37 | 557 | bfa_sm_fault(rport->fcs, event); |
7725ccfd JH |
558 | } |
559 | } | |
560 | ||
5fbe25c7 | 561 | /* |
a36c61f9 KG |
562 | * An SCN event is received in ONLINE state. NS query is being sent |
563 | * prior to ADISC authentication with rport. FC-4s are paused. | |
7725ccfd JH |
564 | */ |
565 | static void | |
566 | bfa_fcs_rport_sm_nsquery_sending(struct bfa_fcs_rport_s *rport, | |
a36c61f9 | 567 | enum rport_event event) |
7725ccfd JH |
568 | { |
569 | bfa_trc(rport->fcs, rport->pwwn); | |
570 | bfa_trc(rport->fcs, rport->pid); | |
571 | bfa_trc(rport->fcs, event); | |
572 | ||
573 | switch (event) { | |
574 | case RPSM_EVENT_FCXP_SENT: | |
575 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsquery); | |
576 | break; | |
577 | ||
578 | case RPSM_EVENT_DELETE: | |
579 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend); | |
580 | bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe); | |
581 | bfa_fcs_rport_offline_action(rport); | |
582 | break; | |
583 | ||
584 | case RPSM_EVENT_SCN: | |
5fbe25c7 | 585 | /* |
7725ccfd JH |
586 | * ignore SCN, wait for response to query itself |
587 | */ | |
588 | break; | |
589 | ||
590 | case RPSM_EVENT_LOGO_RCVD: | |
4b5e759d | 591 | case RPSM_EVENT_PRLO_RCVD: |
7725ccfd JH |
592 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv); |
593 | bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe); | |
594 | bfa_fcs_rport_offline_action(rport); | |
595 | break; | |
596 | ||
597 | case RPSM_EVENT_LOGO_IMP: | |
598 | rport->pid = 0; | |
599 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline); | |
600 | bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe); | |
601 | bfa_timer_start(rport->fcs->bfa, &rport->timer, | |
602 | bfa_fcs_rport_timeout, rport, | |
603 | bfa_fcs_rport_del_timeout); | |
604 | break; | |
605 | ||
606 | case RPSM_EVENT_PLOGI_RCVD: | |
607 | case RPSM_EVENT_ADDRESS_CHANGE: | |
608 | case RPSM_EVENT_PLOGI_COMP: | |
609 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline); | |
610 | bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe); | |
611 | bfa_fcs_rport_offline_action(rport); | |
612 | break; | |
613 | ||
614 | default: | |
e641de37 | 615 | bfa_sm_fault(rport->fcs, event); |
7725ccfd JH |
616 | } |
617 | } | |
618 | ||
5fbe25c7 | 619 | /* |
a36c61f9 KG |
620 | * An SCN event is received in ONLINE state. NS query is sent to rport. |
621 | * FC-4s are paused. | |
7725ccfd JH |
622 | */ |
623 | static void | |
624 | bfa_fcs_rport_sm_nsquery(struct bfa_fcs_rport_s *rport, enum rport_event event) | |
625 | { | |
626 | bfa_trc(rport->fcs, rport->pwwn); | |
627 | bfa_trc(rport->fcs, rport->pid); | |
628 | bfa_trc(rport->fcs, event); | |
629 | ||
630 | switch (event) { | |
631 | case RPSM_EVENT_ACCEPTED: | |
632 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc_sending); | |
633 | bfa_fcs_rport_send_adisc(rport, NULL); | |
634 | break; | |
635 | ||
636 | case RPSM_EVENT_FAILED: | |
637 | rport->ns_retries++; | |
638 | if (rport->ns_retries < BFA_FCS_RPORT_MAX_RETRIES) { | |
639 | bfa_sm_set_state(rport, | |
640 | bfa_fcs_rport_sm_nsquery_sending); | |
a36c61f9 | 641 | bfa_fcs_rport_send_nsdisc(rport, NULL); |
7725ccfd JH |
642 | } else { |
643 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline); | |
644 | bfa_fcs_rport_offline_action(rport); | |
645 | } | |
646 | break; | |
647 | ||
648 | case RPSM_EVENT_DELETE: | |
649 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend); | |
650 | bfa_fcxp_discard(rport->fcxp); | |
651 | bfa_fcs_rport_offline_action(rport); | |
652 | break; | |
653 | ||
654 | case RPSM_EVENT_SCN: | |
655 | break; | |
656 | ||
657 | case RPSM_EVENT_LOGO_RCVD: | |
4b5e759d | 658 | case RPSM_EVENT_PRLO_RCVD: |
7725ccfd JH |
659 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv); |
660 | bfa_fcxp_discard(rport->fcxp); | |
661 | bfa_fcs_rport_offline_action(rport); | |
662 | break; | |
663 | ||
664 | case RPSM_EVENT_PLOGI_COMP: | |
665 | case RPSM_EVENT_ADDRESS_CHANGE: | |
666 | case RPSM_EVENT_PLOGI_RCVD: | |
667 | case RPSM_EVENT_LOGO_IMP: | |
668 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline); | |
669 | bfa_fcxp_discard(rport->fcxp); | |
670 | bfa_fcs_rport_offline_action(rport); | |
671 | break; | |
672 | ||
673 | default: | |
e641de37 | 674 | bfa_sm_fault(rport->fcs, event); |
7725ccfd JH |
675 | } |
676 | } | |
677 | ||
5fbe25c7 | 678 | /* |
a36c61f9 KG |
679 | * An SCN event is received in ONLINE state. ADISC is being sent for |
680 | * authenticating with rport. FC-4s are paused. | |
7725ccfd JH |
681 | */ |
682 | static void | |
683 | bfa_fcs_rport_sm_adisc_sending(struct bfa_fcs_rport_s *rport, | |
a36c61f9 | 684 | enum rport_event event) |
7725ccfd JH |
685 | { |
686 | bfa_trc(rport->fcs, rport->pwwn); | |
687 | bfa_trc(rport->fcs, rport->pid); | |
688 | bfa_trc(rport->fcs, event); | |
689 | ||
690 | switch (event) { | |
691 | case RPSM_EVENT_FCXP_SENT: | |
692 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc); | |
693 | break; | |
694 | ||
695 | case RPSM_EVENT_DELETE: | |
696 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend); | |
697 | bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe); | |
698 | bfa_fcs_rport_offline_action(rport); | |
699 | break; | |
700 | ||
701 | case RPSM_EVENT_LOGO_IMP: | |
702 | case RPSM_EVENT_ADDRESS_CHANGE: | |
703 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline); | |
704 | bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe); | |
705 | bfa_fcs_rport_offline_action(rport); | |
706 | break; | |
707 | ||
708 | case RPSM_EVENT_LOGO_RCVD: | |
4b5e759d | 709 | case RPSM_EVENT_PRLO_RCVD: |
7725ccfd JH |
710 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv); |
711 | bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe); | |
712 | bfa_fcs_rport_offline_action(rport); | |
713 | break; | |
714 | ||
715 | case RPSM_EVENT_SCN: | |
716 | break; | |
717 | ||
718 | case RPSM_EVENT_PLOGI_RCVD: | |
719 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline); | |
720 | bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe); | |
721 | bfa_fcs_rport_offline_action(rport); | |
722 | break; | |
723 | ||
724 | default: | |
e641de37 | 725 | bfa_sm_fault(rport->fcs, event); |
7725ccfd JH |
726 | } |
727 | } | |
728 | ||
5fbe25c7 | 729 | /* |
a36c61f9 KG |
730 | * An SCN event is received in ONLINE state. ADISC is to rport. |
731 | * FC-4s are paused. | |
7725ccfd JH |
732 | */ |
733 | static void | |
734 | bfa_fcs_rport_sm_adisc(struct bfa_fcs_rport_s *rport, enum rport_event event) | |
735 | { | |
736 | bfa_trc(rport->fcs, rport->pwwn); | |
737 | bfa_trc(rport->fcs, rport->pid); | |
738 | bfa_trc(rport->fcs, event); | |
739 | ||
740 | switch (event) { | |
741 | case RPSM_EVENT_ACCEPTED: | |
742 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_online); | |
7725ccfd JH |
743 | break; |
744 | ||
745 | case RPSM_EVENT_PLOGI_RCVD: | |
5fbe25c7 | 746 | /* |
7725ccfd JH |
747 | * Too complex to cleanup FC-4 & rport and then acc to PLOGI. |
748 | * At least go offline when a PLOGI is received. | |
749 | */ | |
750 | bfa_fcxp_discard(rport->fcxp); | |
751 | /* | |
752 | * !!! fall through !!! | |
753 | */ | |
754 | ||
755 | case RPSM_EVENT_FAILED: | |
756 | case RPSM_EVENT_ADDRESS_CHANGE: | |
757 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline); | |
758 | bfa_fcs_rport_offline_action(rport); | |
759 | break; | |
760 | ||
761 | case RPSM_EVENT_DELETE: | |
762 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend); | |
763 | bfa_fcxp_discard(rport->fcxp); | |
764 | bfa_fcs_rport_offline_action(rport); | |
765 | break; | |
766 | ||
767 | case RPSM_EVENT_SCN: | |
5fbe25c7 | 768 | /* |
7725ccfd JH |
769 | * already processing RSCN |
770 | */ | |
771 | break; | |
772 | ||
773 | case RPSM_EVENT_LOGO_IMP: | |
774 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline); | |
775 | bfa_fcxp_discard(rport->fcxp); | |
776 | bfa_fcs_rport_offline_action(rport); | |
777 | break; | |
778 | ||
779 | case RPSM_EVENT_LOGO_RCVD: | |
4b5e759d | 780 | case RPSM_EVENT_PRLO_RCVD: |
7725ccfd JH |
781 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv); |
782 | bfa_fcxp_discard(rport->fcxp); | |
783 | bfa_fcs_rport_offline_action(rport); | |
784 | break; | |
785 | ||
786 | default: | |
e641de37 | 787 | bfa_sm_fault(rport->fcs, event); |
7725ccfd JH |
788 | } |
789 | } | |
790 | ||
5fbe25c7 | 791 | /* |
a36c61f9 | 792 | * Rport has sent LOGO. Awaiting FC-4 offline completion callback. |
7725ccfd JH |
793 | */ |
794 | static void | |
795 | bfa_fcs_rport_sm_fc4_logorcv(struct bfa_fcs_rport_s *rport, | |
796 | enum rport_event event) | |
797 | { | |
798 | bfa_trc(rport->fcs, rport->pwwn); | |
799 | bfa_trc(rport->fcs, rport->pid); | |
800 | bfa_trc(rport->fcs, event); | |
801 | ||
802 | switch (event) { | |
803 | case RPSM_EVENT_FC4_OFFLINE: | |
804 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logorcv); | |
f7f73812 | 805 | bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE); |
7725ccfd JH |
806 | break; |
807 | ||
808 | case RPSM_EVENT_DELETE: | |
809 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend); | |
810 | break; | |
811 | ||
812 | case RPSM_EVENT_LOGO_RCVD: | |
4b5e759d | 813 | case RPSM_EVENT_PRLO_RCVD: |
7725ccfd JH |
814 | case RPSM_EVENT_ADDRESS_CHANGE: |
815 | break; | |
816 | ||
817 | default: | |
e641de37 | 818 | bfa_sm_fault(rport->fcs, event); |
7725ccfd JH |
819 | } |
820 | } | |
821 | ||
5fbe25c7 | 822 | /* |
a36c61f9 KG |
823 | * LOGO needs to be sent to rport. Awaiting FC-4 offline completion |
824 | * callback. | |
7725ccfd JH |
825 | */ |
826 | static void | |
827 | bfa_fcs_rport_sm_fc4_logosend(struct bfa_fcs_rport_s *rport, | |
a36c61f9 | 828 | enum rport_event event) |
7725ccfd JH |
829 | { |
830 | bfa_trc(rport->fcs, rport->pwwn); | |
831 | bfa_trc(rport->fcs, rport->pid); | |
832 | bfa_trc(rport->fcs, event); | |
833 | ||
834 | switch (event) { | |
835 | case RPSM_EVENT_FC4_OFFLINE: | |
836 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logosend); | |
f7f73812 | 837 | bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE); |
7725ccfd JH |
838 | break; |
839 | ||
840 | default: | |
e641de37 | 841 | bfa_sm_fault(rport->fcs, event); |
7725ccfd JH |
842 | } |
843 | } | |
844 | ||
5fbe25c7 | 845 | /* |
a36c61f9 | 846 | * Rport is going offline. Awaiting FC-4 offline completion callback. |
7725ccfd JH |
847 | */ |
848 | static void | |
849 | bfa_fcs_rport_sm_fc4_offline(struct bfa_fcs_rport_s *rport, | |
850 | enum rport_event event) | |
851 | { | |
852 | bfa_trc(rport->fcs, rport->pwwn); | |
853 | bfa_trc(rport->fcs, rport->pid); | |
854 | bfa_trc(rport->fcs, event); | |
855 | ||
856 | switch (event) { | |
857 | case RPSM_EVENT_FC4_OFFLINE: | |
858 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_offline); | |
f7f73812 | 859 | bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_OFFLINE); |
7725ccfd JH |
860 | break; |
861 | ||
862 | case RPSM_EVENT_SCN: | |
863 | case RPSM_EVENT_LOGO_IMP: | |
864 | case RPSM_EVENT_LOGO_RCVD: | |
4b5e759d | 865 | case RPSM_EVENT_PRLO_RCVD: |
7725ccfd | 866 | case RPSM_EVENT_ADDRESS_CHANGE: |
5fbe25c7 | 867 | /* |
7725ccfd JH |
868 | * rport is already going offline. |
869 | * SCN - ignore and wait till transitioning to offline state | |
870 | */ | |
871 | break; | |
872 | ||
873 | case RPSM_EVENT_DELETE: | |
874 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend); | |
875 | break; | |
876 | ||
877 | default: | |
e641de37 | 878 | bfa_sm_fault(rport->fcs, event); |
7725ccfd JH |
879 | } |
880 | } | |
881 | ||
5fbe25c7 | 882 | /* |
a36c61f9 KG |
883 | * Rport is offline. FC-4s are offline. Awaiting BFA rport offline |
884 | * callback. | |
7725ccfd JH |
885 | */ |
886 | static void | |
887 | bfa_fcs_rport_sm_hcb_offline(struct bfa_fcs_rport_s *rport, | |
a36c61f9 | 888 | enum rport_event event) |
7725ccfd JH |
889 | { |
890 | bfa_trc(rport->fcs, rport->pwwn); | |
891 | bfa_trc(rport->fcs, rport->pid); | |
892 | bfa_trc(rport->fcs, event); | |
893 | ||
894 | switch (event) { | |
895 | case RPSM_EVENT_HCB_OFFLINE: | |
d7be54cc KG |
896 | if (bfa_fcs_lport_is_online(rport->port) && |
897 | (rport->plogi_pending)) { | |
898 | rport->plogi_pending = BFA_FALSE; | |
899 | bfa_sm_set_state(rport, | |
900 | bfa_fcs_rport_sm_plogiacc_sending); | |
901 | bfa_fcs_rport_send_plogiacc(rport, NULL); | |
902 | break; | |
903 | } | |
904 | /* | |
905 | * !! fall through !! | |
906 | */ | |
907 | ||
7725ccfd | 908 | case RPSM_EVENT_ADDRESS_CHANGE: |
a36c61f9 | 909 | if (bfa_fcs_lport_is_online(rport->port)) { |
72041ed8 KG |
910 | if (bfa_fcs_fabric_is_switched(rport->port->fabric)) { |
911 | bfa_sm_set_state(rport, | |
912 | bfa_fcs_rport_sm_nsdisc_sending); | |
913 | rport->ns_retries = 0; | |
a36c61f9 | 914 | bfa_fcs_rport_send_nsdisc(rport, NULL); |
72041ed8 KG |
915 | } else { |
916 | bfa_sm_set_state(rport, | |
917 | bfa_fcs_rport_sm_plogi_sending); | |
918 | rport->plogi_retries = 0; | |
919 | bfa_fcs_rport_send_plogi(rport, NULL); | |
920 | } | |
7725ccfd JH |
921 | } else { |
922 | rport->pid = 0; | |
923 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline); | |
924 | bfa_timer_start(rport->fcs->bfa, &rport->timer, | |
925 | bfa_fcs_rport_timeout, rport, | |
926 | bfa_fcs_rport_del_timeout); | |
927 | } | |
928 | break; | |
929 | ||
930 | case RPSM_EVENT_DELETE: | |
931 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit); | |
932 | bfa_fcs_rport_free(rport); | |
933 | break; | |
934 | ||
935 | case RPSM_EVENT_SCN: | |
936 | case RPSM_EVENT_LOGO_RCVD: | |
4b5e759d | 937 | case RPSM_EVENT_PRLO_RCVD: |
d7be54cc KG |
938 | case RPSM_EVENT_PLOGI_RCVD: |
939 | case RPSM_EVENT_LOGO_IMP: | |
5fbe25c7 | 940 | /* |
7725ccfd JH |
941 | * Ignore, already offline. |
942 | */ | |
943 | break; | |
944 | ||
945 | default: | |
e641de37 | 946 | bfa_sm_fault(rport->fcs, event); |
7725ccfd JH |
947 | } |
948 | } | |
949 | ||
5fbe25c7 | 950 | /* |
a36c61f9 KG |
951 | * Rport is offline. FC-4s are offline. Awaiting BFA rport offline |
952 | * callback to send LOGO accept. | |
7725ccfd JH |
953 | */ |
954 | static void | |
955 | bfa_fcs_rport_sm_hcb_logorcv(struct bfa_fcs_rport_s *rport, | |
956 | enum rport_event event) | |
957 | { | |
958 | bfa_trc(rport->fcs, rport->pwwn); | |
959 | bfa_trc(rport->fcs, rport->pid); | |
960 | bfa_trc(rport->fcs, event); | |
961 | ||
962 | switch (event) { | |
963 | case RPSM_EVENT_HCB_OFFLINE: | |
964 | case RPSM_EVENT_ADDRESS_CHANGE: | |
4b5e759d JH |
965 | if (rport->pid && (rport->prlo == BFA_TRUE)) |
966 | bfa_fcs_rport_send_prlo_acc(rport); | |
967 | if (rport->pid && (rport->prlo == BFA_FALSE)) | |
7725ccfd JH |
968 | bfa_fcs_rport_send_logo_acc(rport); |
969 | /* | |
a36c61f9 KG |
970 | * If the lport is online and if the rport is not a well |
971 | * known address port, | |
972 | * we try to re-discover the r-port. | |
7725ccfd | 973 | */ |
a36c61f9 KG |
974 | if (bfa_fcs_lport_is_online(rport->port) && |
975 | (!BFA_FCS_PID_IS_WKA(rport->pid))) { | |
d7be54cc KG |
976 | if (bfa_fcs_fabric_is_switched(rport->port->fabric)) { |
977 | bfa_sm_set_state(rport, | |
978 | bfa_fcs_rport_sm_nsdisc_sending); | |
979 | rport->ns_retries = 0; | |
980 | bfa_fcs_rport_send_nsdisc(rport, NULL); | |
981 | } else { | |
982 | /* For N2N Direct Attach, try to re-login */ | |
983 | bfa_sm_set_state(rport, | |
984 | bfa_fcs_rport_sm_plogi_sending); | |
985 | rport->plogi_retries = 0; | |
986 | bfa_fcs_rport_send_plogi(rport, NULL); | |
987 | } | |
7725ccfd JH |
988 | } else { |
989 | /* | |
a36c61f9 KG |
990 | * if it is not a well known address, reset the |
991 | * pid to 0. | |
7725ccfd JH |
992 | */ |
993 | if (!BFA_FCS_PID_IS_WKA(rport->pid)) | |
994 | rport->pid = 0; | |
995 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline); | |
996 | bfa_timer_start(rport->fcs->bfa, &rport->timer, | |
997 | bfa_fcs_rport_timeout, rport, | |
998 | bfa_fcs_rport_del_timeout); | |
999 | } | |
1000 | break; | |
1001 | ||
1002 | case RPSM_EVENT_DELETE: | |
1003 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logosend); | |
1004 | break; | |
1005 | ||
1006 | case RPSM_EVENT_LOGO_IMP: | |
1007 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_offline); | |
1008 | break; | |
1009 | ||
1010 | case RPSM_EVENT_LOGO_RCVD: | |
4b5e759d | 1011 | case RPSM_EVENT_PRLO_RCVD: |
5fbe25c7 | 1012 | /* |
7725ccfd JH |
1013 | * Ignore - already processing a LOGO. |
1014 | */ | |
1015 | break; | |
1016 | ||
1017 | default: | |
e641de37 | 1018 | bfa_sm_fault(rport->fcs, event); |
7725ccfd JH |
1019 | } |
1020 | } | |
1021 | ||
5fbe25c7 | 1022 | /* |
a36c61f9 KG |
1023 | * Rport is being deleted. FC-4s are offline. |
1024 | * Awaiting BFA rport offline | |
1025 | * callback to send LOGO. | |
7725ccfd JH |
1026 | */ |
1027 | static void | |
1028 | bfa_fcs_rport_sm_hcb_logosend(struct bfa_fcs_rport_s *rport, | |
a36c61f9 | 1029 | enum rport_event event) |
7725ccfd JH |
1030 | { |
1031 | bfa_trc(rport->fcs, rport->pwwn); | |
1032 | bfa_trc(rport->fcs, rport->pid); | |
1033 | bfa_trc(rport->fcs, event); | |
1034 | ||
1035 | switch (event) { | |
1036 | case RPSM_EVENT_HCB_OFFLINE: | |
1037 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_logo_sending); | |
1038 | bfa_fcs_rport_send_logo(rport, NULL); | |
1039 | break; | |
1040 | ||
1041 | case RPSM_EVENT_LOGO_RCVD: | |
4b5e759d | 1042 | case RPSM_EVENT_PRLO_RCVD: |
7725ccfd JH |
1043 | case RPSM_EVENT_ADDRESS_CHANGE: |
1044 | break; | |
1045 | ||
1046 | default: | |
e641de37 | 1047 | bfa_sm_fault(rport->fcs, event); |
7725ccfd JH |
1048 | } |
1049 | } | |
1050 | ||
5fbe25c7 | 1051 | /* |
a36c61f9 | 1052 | * Rport is being deleted. FC-4s are offline. LOGO is being sent. |
7725ccfd JH |
1053 | */ |
1054 | static void | |
1055 | bfa_fcs_rport_sm_logo_sending(struct bfa_fcs_rport_s *rport, | |
a36c61f9 | 1056 | enum rport_event event) |
7725ccfd JH |
1057 | { |
1058 | bfa_trc(rport->fcs, rport->pwwn); | |
1059 | bfa_trc(rport->fcs, rport->pid); | |
1060 | bfa_trc(rport->fcs, event); | |
1061 | ||
1062 | switch (event) { | |
1063 | case RPSM_EVENT_FCXP_SENT: | |
a36c61f9 | 1064 | /* Once LOGO is sent, we donot wait for the response */ |
7725ccfd JH |
1065 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit); |
1066 | bfa_fcs_rport_free(rport); | |
1067 | break; | |
1068 | ||
1069 | case RPSM_EVENT_SCN: | |
1070 | case RPSM_EVENT_ADDRESS_CHANGE: | |
1071 | break; | |
1072 | ||
1073 | case RPSM_EVENT_LOGO_RCVD: | |
4b5e759d | 1074 | case RPSM_EVENT_PRLO_RCVD: |
7725ccfd JH |
1075 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit); |
1076 | bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe); | |
1077 | bfa_fcs_rport_free(rport); | |
1078 | break; | |
1079 | ||
1080 | default: | |
e641de37 | 1081 | bfa_sm_fault(rport->fcs, event); |
7725ccfd JH |
1082 | } |
1083 | } | |
1084 | ||
5fbe25c7 | 1085 | /* |
a36c61f9 KG |
1086 | * Rport is offline. FC-4s are offline. BFA rport is offline. |
1087 | * Timer active to delete stale rport. | |
7725ccfd JH |
1088 | */ |
1089 | static void | |
1090 | bfa_fcs_rport_sm_offline(struct bfa_fcs_rport_s *rport, enum rport_event event) | |
1091 | { | |
1092 | bfa_trc(rport->fcs, rport->pwwn); | |
1093 | bfa_trc(rport->fcs, rport->pid); | |
1094 | bfa_trc(rport->fcs, event); | |
1095 | ||
1096 | switch (event) { | |
1097 | case RPSM_EVENT_TIMEOUT: | |
1098 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit); | |
1099 | bfa_fcs_rport_free(rport); | |
1100 | break; | |
1101 | ||
1102 | case RPSM_EVENT_SCN: | |
1103 | case RPSM_EVENT_ADDRESS_CHANGE: | |
1104 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending); | |
1105 | bfa_timer_stop(&rport->timer); | |
1106 | rport->ns_retries = 0; | |
a36c61f9 | 1107 | bfa_fcs_rport_send_nsdisc(rport, NULL); |
7725ccfd JH |
1108 | break; |
1109 | ||
1110 | case RPSM_EVENT_DELETE: | |
1111 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit); | |
1112 | bfa_timer_stop(&rport->timer); | |
1113 | bfa_fcs_rport_free(rport); | |
1114 | break; | |
1115 | ||
1116 | case RPSM_EVENT_PLOGI_RCVD: | |
1117 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending); | |
1118 | bfa_timer_stop(&rport->timer); | |
1119 | bfa_fcs_rport_send_plogiacc(rport, NULL); | |
1120 | break; | |
1121 | ||
1122 | case RPSM_EVENT_LOGO_RCVD: | |
4b5e759d | 1123 | case RPSM_EVENT_PRLO_RCVD: |
7725ccfd JH |
1124 | case RPSM_EVENT_LOGO_IMP: |
1125 | break; | |
1126 | ||
1127 | case RPSM_EVENT_PLOGI_COMP: | |
1128 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online); | |
1129 | bfa_timer_stop(&rport->timer); | |
1130 | bfa_fcs_rport_hal_online(rport); | |
1131 | break; | |
1132 | ||
1133 | case RPSM_EVENT_PLOGI_SEND: | |
1134 | bfa_timer_stop(&rport->timer); | |
1135 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending); | |
1136 | rport->plogi_retries = 0; | |
1137 | bfa_fcs_rport_send_plogi(rport, NULL); | |
1138 | break; | |
1139 | ||
1140 | default: | |
e641de37 | 1141 | bfa_sm_fault(rport->fcs, event); |
7725ccfd JH |
1142 | } |
1143 | } | |
1144 | ||
5fbe25c7 | 1145 | /* |
a36c61f9 | 1146 | * Rport address has changed. Nameserver discovery request is being sent. |
7725ccfd JH |
1147 | */ |
1148 | static void | |
1149 | bfa_fcs_rport_sm_nsdisc_sending(struct bfa_fcs_rport_s *rport, | |
a36c61f9 | 1150 | enum rport_event event) |
7725ccfd JH |
1151 | { |
1152 | bfa_trc(rport->fcs, rport->pwwn); | |
1153 | bfa_trc(rport->fcs, rport->pid); | |
1154 | bfa_trc(rport->fcs, event); | |
1155 | ||
1156 | switch (event) { | |
1157 | case RPSM_EVENT_FCXP_SENT: | |
1158 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sent); | |
1159 | break; | |
1160 | ||
1161 | case RPSM_EVENT_DELETE: | |
1162 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit); | |
1163 | bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe); | |
1164 | bfa_fcs_rport_free(rport); | |
1165 | break; | |
1166 | ||
1167 | case RPSM_EVENT_PLOGI_RCVD: | |
1168 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending); | |
1169 | bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe); | |
1170 | bfa_fcs_rport_send_plogiacc(rport, NULL); | |
1171 | break; | |
1172 | ||
1173 | case RPSM_EVENT_SCN: | |
1174 | case RPSM_EVENT_LOGO_RCVD: | |
4b5e759d | 1175 | case RPSM_EVENT_PRLO_RCVD: |
7725ccfd JH |
1176 | case RPSM_EVENT_PLOGI_SEND: |
1177 | break; | |
1178 | ||
1179 | case RPSM_EVENT_ADDRESS_CHANGE: | |
a36c61f9 | 1180 | rport->ns_retries = 0; /* reset the retry count */ |
7725ccfd JH |
1181 | break; |
1182 | ||
1183 | case RPSM_EVENT_LOGO_IMP: | |
1184 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline); | |
1185 | bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe); | |
1186 | bfa_timer_start(rport->fcs->bfa, &rport->timer, | |
1187 | bfa_fcs_rport_timeout, rport, | |
1188 | bfa_fcs_rport_del_timeout); | |
1189 | break; | |
1190 | ||
1191 | case RPSM_EVENT_PLOGI_COMP: | |
1192 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online); | |
1193 | bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe); | |
1194 | bfa_fcs_rport_hal_online(rport); | |
1195 | break; | |
1196 | ||
1197 | default: | |
e641de37 | 1198 | bfa_sm_fault(rport->fcs, event); |
7725ccfd JH |
1199 | } |
1200 | } | |
1201 | ||
5fbe25c7 | 1202 | /* |
a36c61f9 | 1203 | * Nameserver discovery failed. Waiting for timeout to retry. |
7725ccfd JH |
1204 | */ |
1205 | static void | |
1206 | bfa_fcs_rport_sm_nsdisc_retry(struct bfa_fcs_rport_s *rport, | |
a36c61f9 | 1207 | enum rport_event event) |
7725ccfd JH |
1208 | { |
1209 | bfa_trc(rport->fcs, rport->pwwn); | |
1210 | bfa_trc(rport->fcs, rport->pid); | |
1211 | bfa_trc(rport->fcs, event); | |
1212 | ||
1213 | switch (event) { | |
1214 | case RPSM_EVENT_TIMEOUT: | |
1215 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending); | |
a36c61f9 | 1216 | bfa_fcs_rport_send_nsdisc(rport, NULL); |
7725ccfd JH |
1217 | break; |
1218 | ||
1219 | case RPSM_EVENT_SCN: | |
1220 | case RPSM_EVENT_ADDRESS_CHANGE: | |
1221 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending); | |
1222 | bfa_timer_stop(&rport->timer); | |
1223 | rport->ns_retries = 0; | |
a36c61f9 | 1224 | bfa_fcs_rport_send_nsdisc(rport, NULL); |
7725ccfd JH |
1225 | break; |
1226 | ||
1227 | case RPSM_EVENT_DELETE: | |
1228 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit); | |
1229 | bfa_timer_stop(&rport->timer); | |
1230 | bfa_fcs_rport_free(rport); | |
1231 | break; | |
1232 | ||
1233 | case RPSM_EVENT_PLOGI_RCVD: | |
1234 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending); | |
1235 | bfa_timer_stop(&rport->timer); | |
1236 | bfa_fcs_rport_send_plogiacc(rport, NULL); | |
1237 | break; | |
1238 | ||
1239 | case RPSM_EVENT_LOGO_IMP: | |
1240 | rport->pid = 0; | |
1241 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline); | |
1242 | bfa_timer_stop(&rport->timer); | |
1243 | bfa_timer_start(rport->fcs->bfa, &rport->timer, | |
1244 | bfa_fcs_rport_timeout, rport, | |
1245 | bfa_fcs_rport_del_timeout); | |
1246 | break; | |
1247 | ||
1248 | case RPSM_EVENT_LOGO_RCVD: | |
1249 | bfa_fcs_rport_send_logo_acc(rport); | |
1250 | break; | |
4b5e759d JH |
1251 | case RPSM_EVENT_PRLO_RCVD: |
1252 | bfa_fcs_rport_send_prlo_acc(rport); | |
1253 | break; | |
1254 | ||
7725ccfd JH |
1255 | case RPSM_EVENT_PLOGI_COMP: |
1256 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online); | |
1257 | bfa_timer_stop(&rport->timer); | |
1258 | bfa_fcs_rport_hal_online(rport); | |
1259 | break; | |
1260 | ||
1261 | default: | |
e641de37 | 1262 | bfa_sm_fault(rport->fcs, event); |
7725ccfd JH |
1263 | } |
1264 | } | |
1265 | ||
5fbe25c7 | 1266 | /* |
a36c61f9 | 1267 | * Rport address has changed. Nameserver discovery request is sent. |
7725ccfd JH |
1268 | */ |
1269 | static void | |
1270 | bfa_fcs_rport_sm_nsdisc_sent(struct bfa_fcs_rport_s *rport, | |
1271 | enum rport_event event) | |
1272 | { | |
1273 | bfa_trc(rport->fcs, rport->pwwn); | |
1274 | bfa_trc(rport->fcs, rport->pid); | |
1275 | bfa_trc(rport->fcs, event); | |
1276 | ||
1277 | switch (event) { | |
1278 | case RPSM_EVENT_ACCEPTED: | |
1279 | case RPSM_EVENT_ADDRESS_CHANGE: | |
1280 | if (rport->pid) { | |
1281 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending); | |
1282 | bfa_fcs_rport_send_plogi(rport, NULL); | |
1283 | } else { | |
1284 | bfa_sm_set_state(rport, | |
a36c61f9 | 1285 | bfa_fcs_rport_sm_nsdisc_sending); |
7725ccfd | 1286 | rport->ns_retries = 0; |
a36c61f9 | 1287 | bfa_fcs_rport_send_nsdisc(rport, NULL); |
7725ccfd JH |
1288 | } |
1289 | break; | |
1290 | ||
1291 | case RPSM_EVENT_FAILED: | |
1292 | rport->ns_retries++; | |
1293 | if (rport->ns_retries < BFA_FCS_RPORT_MAX_RETRIES) { | |
1294 | bfa_sm_set_state(rport, | |
a36c61f9 KG |
1295 | bfa_fcs_rport_sm_nsdisc_sending); |
1296 | bfa_fcs_rport_send_nsdisc(rport, NULL); | |
7725ccfd JH |
1297 | } else { |
1298 | rport->pid = 0; | |
1299 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline); | |
1300 | bfa_timer_start(rport->fcs->bfa, &rport->timer, | |
1301 | bfa_fcs_rport_timeout, rport, | |
1302 | bfa_fcs_rport_del_timeout); | |
1303 | }; | |
1304 | break; | |
1305 | ||
1306 | case RPSM_EVENT_DELETE: | |
1307 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit); | |
1308 | bfa_fcxp_discard(rport->fcxp); | |
1309 | bfa_fcs_rport_free(rport); | |
1310 | break; | |
1311 | ||
1312 | case RPSM_EVENT_PLOGI_RCVD: | |
1313 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending); | |
1314 | bfa_fcxp_discard(rport->fcxp); | |
1315 | bfa_fcs_rport_send_plogiacc(rport, NULL); | |
1316 | break; | |
1317 | ||
1318 | case RPSM_EVENT_LOGO_IMP: | |
1319 | rport->pid = 0; | |
1320 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline); | |
1321 | bfa_fcxp_discard(rport->fcxp); | |
1322 | bfa_timer_start(rport->fcs->bfa, &rport->timer, | |
1323 | bfa_fcs_rport_timeout, rport, | |
1324 | bfa_fcs_rport_del_timeout); | |
1325 | break; | |
1326 | ||
a36c61f9 | 1327 | |
4b5e759d JH |
1328 | case RPSM_EVENT_PRLO_RCVD: |
1329 | bfa_fcs_rport_send_prlo_acc(rport); | |
1330 | break; | |
7725ccfd | 1331 | case RPSM_EVENT_SCN: |
5fbe25c7 | 1332 | /* |
7725ccfd JH |
1333 | * ignore, wait for NS query response |
1334 | */ | |
1335 | break; | |
1336 | ||
1337 | case RPSM_EVENT_LOGO_RCVD: | |
5fbe25c7 | 1338 | /* |
7725ccfd JH |
1339 | * Not logged-in yet. Accept LOGO. |
1340 | */ | |
1341 | bfa_fcs_rport_send_logo_acc(rport); | |
1342 | break; | |
1343 | ||
1344 | case RPSM_EVENT_PLOGI_COMP: | |
1345 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online); | |
1346 | bfa_fcxp_discard(rport->fcxp); | |
1347 | bfa_fcs_rport_hal_online(rport); | |
1348 | break; | |
1349 | ||
1350 | default: | |
e641de37 | 1351 | bfa_sm_fault(rport->fcs, event); |
7725ccfd JH |
1352 | } |
1353 | } | |
1354 | ||
1355 | ||
1356 | ||
5fbe25c7 | 1357 | /* |
7725ccfd JH |
1358 | * fcs_rport_private FCS RPORT provate functions |
1359 | */ | |
1360 | ||
1361 | static void | |
1362 | bfa_fcs_rport_send_plogi(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced) | |
1363 | { | |
1364 | struct bfa_fcs_rport_s *rport = rport_cbarg; | |
a36c61f9 KG |
1365 | struct bfa_fcs_lport_s *port = rport->port; |
1366 | struct fchs_s fchs; | |
1367 | int len; | |
7725ccfd JH |
1368 | struct bfa_fcxp_s *fcxp; |
1369 | ||
1370 | bfa_trc(rport->fcs, rport->pwwn); | |
1371 | ||
1372 | fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs); | |
1373 | if (!fcxp) { | |
a36c61f9 KG |
1374 | bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe, |
1375 | bfa_fcs_rport_send_plogi, rport); | |
7725ccfd JH |
1376 | return; |
1377 | } | |
1378 | rport->fcxp = fcxp; | |
1379 | ||
1380 | len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid, | |
a36c61f9 KG |
1381 | bfa_fcs_lport_get_fcid(port), 0, |
1382 | port->port_cfg.pwwn, port->port_cfg.nwwn, | |
be540a99 KG |
1383 | bfa_fcport_get_maxfrsize(port->fcs->bfa), |
1384 | bfa_fcport_get_rx_bbcredit(port->fcs->bfa)); | |
7725ccfd JH |
1385 | |
1386 | bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE, | |
a36c61f9 KG |
1387 | FC_CLASS_3, len, &fchs, bfa_fcs_rport_plogi_response, |
1388 | (void *)rport, FC_MAX_PDUSZ, FC_ELS_TOV); | |
7725ccfd JH |
1389 | |
1390 | rport->stats.plogis++; | |
1391 | bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT); | |
1392 | } | |
1393 | ||
1394 | static void | |
1395 | bfa_fcs_rport_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg, | |
a36c61f9 KG |
1396 | bfa_status_t req_status, u32 rsp_len, |
1397 | u32 resid_len, struct fchs_s *rsp_fchs) | |
7725ccfd | 1398 | { |
a36c61f9 | 1399 | struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg; |
7725ccfd JH |
1400 | struct fc_logi_s *plogi_rsp; |
1401 | struct fc_ls_rjt_s *ls_rjt; | |
1402 | struct bfa_fcs_rport_s *twin; | |
a36c61f9 | 1403 | struct list_head *qe; |
7725ccfd JH |
1404 | |
1405 | bfa_trc(rport->fcs, rport->pwwn); | |
1406 | ||
1407 | /* | |
1408 | * Sanity Checks | |
1409 | */ | |
1410 | if (req_status != BFA_STATUS_OK) { | |
1411 | bfa_trc(rport->fcs, req_status); | |
1412 | rport->stats.plogi_failed++; | |
1413 | bfa_sm_send_event(rport, RPSM_EVENT_FAILED); | |
1414 | return; | |
1415 | } | |
1416 | ||
1417 | plogi_rsp = (struct fc_logi_s *) BFA_FCXP_RSP_PLD(fcxp); | |
1418 | ||
5fbe25c7 | 1419 | /* |
7725ccfd JH |
1420 | * Check for failure first. |
1421 | */ | |
1422 | if (plogi_rsp->els_cmd.els_code != FC_ELS_ACC) { | |
1423 | ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp); | |
1424 | ||
1425 | bfa_trc(rport->fcs, ls_rjt->reason_code); | |
1426 | bfa_trc(rport->fcs, ls_rjt->reason_code_expl); | |
1427 | ||
a36c61f9 KG |
1428 | if ((ls_rjt->reason_code == FC_LS_RJT_RSN_UNABLE_TO_PERF_CMD) && |
1429 | (ls_rjt->reason_code_expl == FC_LS_RJT_EXP_INSUFF_RES)) { | |
1430 | rport->stats.rjt_insuff_res++; | |
1431 | bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RETRY); | |
1432 | return; | |
1433 | } | |
1434 | ||
7725ccfd JH |
1435 | rport->stats.plogi_rejects++; |
1436 | bfa_sm_send_event(rport, RPSM_EVENT_FAILED); | |
1437 | return; | |
1438 | } | |
1439 | ||
5fbe25c7 | 1440 | /* |
7725ccfd JH |
1441 | * PLOGI is complete. Make sure this device is not one of the known |
1442 | * device with a new FC port address. | |
1443 | */ | |
1444 | list_for_each(qe, &rport->port->rport_q) { | |
a36c61f9 | 1445 | twin = (struct bfa_fcs_rport_s *) qe; |
7725ccfd JH |
1446 | if (twin == rport) |
1447 | continue; | |
1448 | if (!rport->pwwn && (plogi_rsp->port_name == twin->pwwn)) { | |
1449 | bfa_trc(rport->fcs, twin->pid); | |
1450 | bfa_trc(rport->fcs, rport->pid); | |
1451 | ||
a36c61f9 KG |
1452 | /* Update plogi stats in twin */ |
1453 | twin->stats.plogis += rport->stats.plogis; | |
1454 | twin->stats.plogi_rejects += | |
1455 | rport->stats.plogi_rejects; | |
1456 | twin->stats.plogi_timeouts += | |
1457 | rport->stats.plogi_timeouts; | |
1458 | twin->stats.plogi_failed += | |
1459 | rport->stats.plogi_failed; | |
1460 | twin->stats.plogi_rcvd += rport->stats.plogi_rcvd; | |
7725ccfd JH |
1461 | twin->stats.plogi_accs++; |
1462 | ||
f7f73812 | 1463 | bfa_sm_send_event(rport, RPSM_EVENT_DELETE); |
7725ccfd JH |
1464 | |
1465 | bfa_fcs_rport_update(twin, plogi_rsp); | |
1466 | twin->pid = rsp_fchs->s_id; | |
1467 | bfa_sm_send_event(twin, RPSM_EVENT_PLOGI_COMP); | |
1468 | return; | |
1469 | } | |
1470 | } | |
1471 | ||
5fbe25c7 | 1472 | /* |
7725ccfd JH |
1473 | * Normal login path -- no evil twins. |
1474 | */ | |
1475 | rport->stats.plogi_accs++; | |
1476 | bfa_fcs_rport_update(rport, plogi_rsp); | |
1477 | bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED); | |
1478 | } | |
1479 | ||
1480 | static void | |
1481 | bfa_fcs_rport_send_plogiacc(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced) | |
1482 | { | |
1483 | struct bfa_fcs_rport_s *rport = rport_cbarg; | |
a36c61f9 KG |
1484 | struct bfa_fcs_lport_s *port = rport->port; |
1485 | struct fchs_s fchs; | |
1486 | int len; | |
7725ccfd JH |
1487 | struct bfa_fcxp_s *fcxp; |
1488 | ||
1489 | bfa_trc(rport->fcs, rport->pwwn); | |
1490 | bfa_trc(rport->fcs, rport->reply_oxid); | |
1491 | ||
1492 | fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs); | |
1493 | if (!fcxp) { | |
a36c61f9 KG |
1494 | bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe, |
1495 | bfa_fcs_rport_send_plogiacc, rport); | |
7725ccfd JH |
1496 | return; |
1497 | } | |
1498 | rport->fcxp = fcxp; | |
1499 | ||
a36c61f9 KG |
1500 | len = fc_plogi_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), |
1501 | rport->pid, bfa_fcs_lport_get_fcid(port), | |
1502 | rport->reply_oxid, port->port_cfg.pwwn, | |
1503 | port->port_cfg.nwwn, | |
be540a99 KG |
1504 | bfa_fcport_get_maxfrsize(port->fcs->bfa), |
1505 | bfa_fcport_get_rx_bbcredit(port->fcs->bfa)); | |
7725ccfd JH |
1506 | |
1507 | bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE, | |
a36c61f9 | 1508 | FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0); |
7725ccfd JH |
1509 | |
1510 | bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT); | |
1511 | } | |
1512 | ||
1513 | static void | |
1514 | bfa_fcs_rport_send_adisc(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced) | |
1515 | { | |
1516 | struct bfa_fcs_rport_s *rport = rport_cbarg; | |
a36c61f9 KG |
1517 | struct bfa_fcs_lport_s *port = rport->port; |
1518 | struct fchs_s fchs; | |
1519 | int len; | |
7725ccfd JH |
1520 | struct bfa_fcxp_s *fcxp; |
1521 | ||
1522 | bfa_trc(rport->fcs, rport->pwwn); | |
1523 | ||
1524 | fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs); | |
1525 | if (!fcxp) { | |
a36c61f9 KG |
1526 | bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe, |
1527 | bfa_fcs_rport_send_adisc, rport); | |
7725ccfd JH |
1528 | return; |
1529 | } | |
1530 | rport->fcxp = fcxp; | |
1531 | ||
1532 | len = fc_adisc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid, | |
a36c61f9 KG |
1533 | bfa_fcs_lport_get_fcid(port), 0, |
1534 | port->port_cfg.pwwn, port->port_cfg.nwwn); | |
7725ccfd JH |
1535 | |
1536 | bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE, | |
a36c61f9 KG |
1537 | FC_CLASS_3, len, &fchs, bfa_fcs_rport_adisc_response, |
1538 | rport, FC_MAX_PDUSZ, FC_ELS_TOV); | |
7725ccfd JH |
1539 | |
1540 | rport->stats.adisc_sent++; | |
1541 | bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT); | |
1542 | } | |
1543 | ||
1544 | static void | |
1545 | bfa_fcs_rport_adisc_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg, | |
a36c61f9 KG |
1546 | bfa_status_t req_status, u32 rsp_len, |
1547 | u32 resid_len, struct fchs_s *rsp_fchs) | |
7725ccfd | 1548 | { |
a36c61f9 KG |
1549 | struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg; |
1550 | void *pld = bfa_fcxp_get_rspbuf(fcxp); | |
1551 | struct fc_ls_rjt_s *ls_rjt; | |
7725ccfd JH |
1552 | |
1553 | if (req_status != BFA_STATUS_OK) { | |
1554 | bfa_trc(rport->fcs, req_status); | |
1555 | rport->stats.adisc_failed++; | |
1556 | bfa_sm_send_event(rport, RPSM_EVENT_FAILED); | |
1557 | return; | |
1558 | } | |
1559 | ||
1560 | if (fc_adisc_rsp_parse((struct fc_adisc_s *)pld, rsp_len, rport->pwwn, | |
a36c61f9 | 1561 | rport->nwwn) == FC_PARSE_OK) { |
7725ccfd JH |
1562 | rport->stats.adisc_accs++; |
1563 | bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED); | |
1564 | return; | |
1565 | } | |
1566 | ||
1567 | rport->stats.adisc_rejects++; | |
1568 | ls_rjt = pld; | |
1569 | bfa_trc(rport->fcs, ls_rjt->els_cmd.els_code); | |
1570 | bfa_trc(rport->fcs, ls_rjt->reason_code); | |
1571 | bfa_trc(rport->fcs, ls_rjt->reason_code_expl); | |
1572 | bfa_sm_send_event(rport, RPSM_EVENT_FAILED); | |
1573 | } | |
1574 | ||
1575 | static void | |
a36c61f9 | 1576 | bfa_fcs_rport_send_nsdisc(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced) |
7725ccfd JH |
1577 | { |
1578 | struct bfa_fcs_rport_s *rport = rport_cbarg; | |
a36c61f9 KG |
1579 | struct bfa_fcs_lport_s *port = rport->port; |
1580 | struct fchs_s fchs; | |
7725ccfd | 1581 | struct bfa_fcxp_s *fcxp; |
a36c61f9 KG |
1582 | int len; |
1583 | bfa_cb_fcxp_send_t cbfn; | |
7725ccfd JH |
1584 | |
1585 | bfa_trc(rport->fcs, rport->pid); | |
1586 | ||
1587 | fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs); | |
1588 | if (!fcxp) { | |
a36c61f9 KG |
1589 | bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe, |
1590 | bfa_fcs_rport_send_nsdisc, rport); | |
7725ccfd JH |
1591 | return; |
1592 | } | |
1593 | rport->fcxp = fcxp; | |
1594 | ||
a36c61f9 KG |
1595 | if (rport->pwwn) { |
1596 | len = fc_gidpn_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), | |
1597 | bfa_fcs_lport_get_fcid(port), 0, rport->pwwn); | |
1598 | cbfn = bfa_fcs_rport_gidpn_response; | |
1599 | } else { | |
1600 | len = fc_gpnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), | |
1601 | bfa_fcs_lport_get_fcid(port), 0, rport->pid); | |
1602 | cbfn = bfa_fcs_rport_gpnid_response; | |
1603 | } | |
7725ccfd JH |
1604 | |
1605 | bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE, | |
a36c61f9 KG |
1606 | FC_CLASS_3, len, &fchs, cbfn, |
1607 | (void *)rport, FC_MAX_PDUSZ, FC_FCCT_TOV); | |
7725ccfd JH |
1608 | |
1609 | bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT); | |
1610 | } | |
1611 | ||
1612 | static void | |
1613 | bfa_fcs_rport_gidpn_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg, | |
a36c61f9 KG |
1614 | bfa_status_t req_status, u32 rsp_len, |
1615 | u32 resid_len, struct fchs_s *rsp_fchs) | |
7725ccfd | 1616 | { |
a36c61f9 KG |
1617 | struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg; |
1618 | struct ct_hdr_s *cthdr; | |
7725ccfd | 1619 | struct fcgs_gidpn_resp_s *gidpn_rsp; |
a36c61f9 KG |
1620 | struct bfa_fcs_rport_s *twin; |
1621 | struct list_head *qe; | |
7725ccfd JH |
1622 | |
1623 | bfa_trc(rport->fcs, rport->pwwn); | |
1624 | ||
1625 | cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp); | |
ba816ea8 | 1626 | cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code); |
7725ccfd JH |
1627 | |
1628 | if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) { | |
a36c61f9 | 1629 | /* Check if the pid is the same as before. */ |
7725ccfd JH |
1630 | gidpn_rsp = (struct fcgs_gidpn_resp_s *) (cthdr + 1); |
1631 | ||
1632 | if (gidpn_rsp->dap == rport->pid) { | |
a36c61f9 | 1633 | /* Device is online */ |
7725ccfd JH |
1634 | bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED); |
1635 | } else { | |
1636 | /* | |
a36c61f9 KG |
1637 | * Device's PID has changed. We need to cleanup |
1638 | * and re-login. If there is another device with | |
1639 | * the the newly discovered pid, send an scn notice | |
1640 | * so that its new pid can be discovered. | |
7725ccfd JH |
1641 | */ |
1642 | list_for_each(qe, &rport->port->rport_q) { | |
a36c61f9 | 1643 | twin = (struct bfa_fcs_rport_s *) qe; |
7725ccfd JH |
1644 | if (twin == rport) |
1645 | continue; | |
1646 | if (gidpn_rsp->dap == twin->pid) { | |
1647 | bfa_trc(rport->fcs, twin->pid); | |
1648 | bfa_trc(rport->fcs, rport->pid); | |
1649 | ||
1650 | twin->pid = 0; | |
1651 | bfa_sm_send_event(twin, | |
a36c61f9 | 1652 | RPSM_EVENT_ADDRESS_CHANGE); |
7725ccfd JH |
1653 | } |
1654 | } | |
1655 | rport->pid = gidpn_rsp->dap; | |
1656 | bfa_sm_send_event(rport, RPSM_EVENT_ADDRESS_CHANGE); | |
1657 | } | |
1658 | return; | |
1659 | } | |
1660 | ||
1661 | /* | |
1662 | * Reject Response | |
1663 | */ | |
1664 | switch (cthdr->reason_code) { | |
1665 | case CT_RSN_LOGICAL_BUSY: | |
1666 | /* | |
1667 | * Need to retry | |
1668 | */ | |
1669 | bfa_sm_send_event(rport, RPSM_EVENT_TIMEOUT); | |
1670 | break; | |
1671 | ||
1672 | case CT_RSN_UNABLE_TO_PERF: | |
1673 | /* | |
1674 | * device doesn't exist : Start timer to cleanup this later. | |
1675 | */ | |
1676 | bfa_sm_send_event(rport, RPSM_EVENT_FAILED); | |
1677 | break; | |
1678 | ||
1679 | default: | |
1680 | bfa_sm_send_event(rport, RPSM_EVENT_FAILED); | |
1681 | break; | |
1682 | } | |
1683 | } | |
1684 | ||
a36c61f9 KG |
1685 | static void |
1686 | bfa_fcs_rport_gpnid_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg, | |
1687 | bfa_status_t req_status, u32 rsp_len, | |
1688 | u32 resid_len, struct fchs_s *rsp_fchs) | |
1689 | { | |
1690 | struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg; | |
1691 | struct ct_hdr_s *cthdr; | |
1692 | ||
1693 | bfa_trc(rport->fcs, rport->pwwn); | |
1694 | ||
1695 | cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp); | |
ba816ea8 | 1696 | cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code); |
a36c61f9 KG |
1697 | |
1698 | if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) { | |
1699 | bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED); | |
1700 | return; | |
1701 | } | |
1702 | ||
1703 | /* | |
1704 | * Reject Response | |
1705 | */ | |
1706 | switch (cthdr->reason_code) { | |
1707 | case CT_RSN_LOGICAL_BUSY: | |
1708 | /* | |
1709 | * Need to retry | |
1710 | */ | |
1711 | bfa_sm_send_event(rport, RPSM_EVENT_TIMEOUT); | |
1712 | break; | |
1713 | ||
1714 | case CT_RSN_UNABLE_TO_PERF: | |
1715 | /* | |
1716 | * device doesn't exist : Start timer to cleanup this later. | |
1717 | */ | |
1718 | bfa_sm_send_event(rport, RPSM_EVENT_FAILED); | |
1719 | break; | |
1720 | ||
1721 | default: | |
1722 | bfa_sm_send_event(rport, RPSM_EVENT_FAILED); | |
1723 | break; | |
1724 | } | |
1725 | } | |
1726 | ||
5fbe25c7 | 1727 | /* |
a36c61f9 | 1728 | * Called to send a logout to the rport. |
7725ccfd JH |
1729 | */ |
1730 | static void | |
1731 | bfa_fcs_rport_send_logo(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced) | |
1732 | { | |
1733 | struct bfa_fcs_rport_s *rport = rport_cbarg; | |
a36c61f9 KG |
1734 | struct bfa_fcs_lport_s *port; |
1735 | struct fchs_s fchs; | |
7725ccfd | 1736 | struct bfa_fcxp_s *fcxp; |
a36c61f9 | 1737 | u16 len; |
7725ccfd JH |
1738 | |
1739 | bfa_trc(rport->fcs, rport->pid); | |
1740 | ||
1741 | port = rport->port; | |
1742 | ||
1743 | fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs); | |
1744 | if (!fcxp) { | |
a36c61f9 KG |
1745 | bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe, |
1746 | bfa_fcs_rport_send_logo, rport); | |
7725ccfd JH |
1747 | return; |
1748 | } | |
1749 | rport->fcxp = fcxp; | |
1750 | ||
1751 | len = fc_logo_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid, | |
a36c61f9 KG |
1752 | bfa_fcs_lport_get_fcid(port), 0, |
1753 | bfa_fcs_lport_get_pwwn(port)); | |
7725ccfd JH |
1754 | |
1755 | bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE, | |
a36c61f9 KG |
1756 | FC_CLASS_3, len, &fchs, NULL, |
1757 | rport, FC_MAX_PDUSZ, FC_ELS_TOV); | |
7725ccfd JH |
1758 | |
1759 | rport->stats.logos++; | |
1760 | bfa_fcxp_discard(rport->fcxp); | |
1761 | bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT); | |
1762 | } | |
1763 | ||
5fbe25c7 | 1764 | /* |
a36c61f9 | 1765 | * Send ACC for a LOGO received. |
7725ccfd JH |
1766 | */ |
1767 | static void | |
1768 | bfa_fcs_rport_send_logo_acc(void *rport_cbarg) | |
1769 | { | |
1770 | struct bfa_fcs_rport_s *rport = rport_cbarg; | |
a36c61f9 KG |
1771 | struct bfa_fcs_lport_s *port; |
1772 | struct fchs_s fchs; | |
7725ccfd | 1773 | struct bfa_fcxp_s *fcxp; |
a36c61f9 | 1774 | u16 len; |
7725ccfd JH |
1775 | |
1776 | bfa_trc(rport->fcs, rport->pid); | |
1777 | ||
1778 | port = rport->port; | |
1779 | ||
1780 | fcxp = bfa_fcs_fcxp_alloc(port->fcs); | |
1781 | if (!fcxp) | |
1782 | return; | |
1783 | ||
1784 | rport->stats.logo_rcvd++; | |
a36c61f9 KG |
1785 | len = fc_logo_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), |
1786 | rport->pid, bfa_fcs_lport_get_fcid(port), | |
1787 | rport->reply_oxid); | |
7725ccfd JH |
1788 | |
1789 | bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE, | |
a36c61f9 | 1790 | FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0); |
7725ccfd JH |
1791 | } |
1792 | ||
5fbe25c7 | 1793 | /* |
a36c61f9 KG |
1794 | * brief |
1795 | * This routine will be called by bfa_timer on timer timeouts. | |
7725ccfd | 1796 | * |
a36c61f9 KG |
1797 | * param[in] rport - pointer to bfa_fcs_lport_ns_t. |
1798 | * param[out] rport_status - pointer to return vport status in | |
7725ccfd | 1799 | * |
a36c61f9 KG |
1800 | * return |
1801 | * void | |
7725ccfd | 1802 | * |
a36c61f9 | 1803 | * Special Considerations: |
7725ccfd | 1804 | * |
a36c61f9 | 1805 | * note |
7725ccfd JH |
1806 | */ |
1807 | static void | |
1808 | bfa_fcs_rport_timeout(void *arg) | |
1809 | { | |
a36c61f9 | 1810 | struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) arg; |
7725ccfd JH |
1811 | |
1812 | rport->stats.plogi_timeouts++; | |
a36c61f9 | 1813 | bfa_stats(rport->port, rport_plogi_timeouts); |
7725ccfd JH |
1814 | bfa_sm_send_event(rport, RPSM_EVENT_TIMEOUT); |
1815 | } | |
1816 | ||
1817 | static void | |
1818 | bfa_fcs_rport_process_prli(struct bfa_fcs_rport_s *rport, | |
1819 | struct fchs_s *rx_fchs, u16 len) | |
1820 | { | |
1821 | struct bfa_fcxp_s *fcxp; | |
a36c61f9 KG |
1822 | struct fchs_s fchs; |
1823 | struct bfa_fcs_lport_s *port = rport->port; | |
1824 | struct fc_prli_s *prli; | |
7725ccfd JH |
1825 | |
1826 | bfa_trc(port->fcs, rx_fchs->s_id); | |
1827 | bfa_trc(port->fcs, rx_fchs->d_id); | |
1828 | ||
1829 | rport->stats.prli_rcvd++; | |
1830 | ||
7725ccfd | 1831 | /* |
a36c61f9 | 1832 | * We are in Initiator Mode |
7725ccfd JH |
1833 | */ |
1834 | prli = (struct fc_prli_s *) (rx_fchs + 1); | |
1835 | ||
a36c61f9 | 1836 | if (prli->parampage.servparams.target) { |
7725ccfd | 1837 | /* |
a36c61f9 KG |
1838 | * PRLI from a target ? |
1839 | * Send the Acc. | |
1840 | * PRLI sent by us will be used to transition the IT nexus, | |
1841 | * once the response is received from the target. | |
7725ccfd JH |
1842 | */ |
1843 | bfa_trc(port->fcs, rx_fchs->s_id); | |
1844 | rport->scsi_function = BFA_RPORT_TARGET; | |
a36c61f9 KG |
1845 | } else { |
1846 | bfa_trc(rport->fcs, prli->parampage.type); | |
1847 | rport->scsi_function = BFA_RPORT_INITIATOR; | |
1848 | bfa_fcs_itnim_is_initiator(rport->itnim); | |
7725ccfd JH |
1849 | } |
1850 | ||
1851 | fcxp = bfa_fcs_fcxp_alloc(port->fcs); | |
1852 | if (!fcxp) | |
1853 | return; | |
1854 | ||
a36c61f9 KG |
1855 | len = fc_prli_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), |
1856 | rx_fchs->s_id, bfa_fcs_lport_get_fcid(port), | |
1857 | rx_fchs->ox_id, port->port_cfg.roles); | |
7725ccfd JH |
1858 | |
1859 | bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE, | |
a36c61f9 | 1860 | FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0); |
7725ccfd JH |
1861 | } |
1862 | ||
1863 | static void | |
1864 | bfa_fcs_rport_process_rpsc(struct bfa_fcs_rport_s *rport, | |
1865 | struct fchs_s *rx_fchs, u16 len) | |
1866 | { | |
1867 | struct bfa_fcxp_s *fcxp; | |
a36c61f9 KG |
1868 | struct fchs_s fchs; |
1869 | struct bfa_fcs_lport_s *port = rport->port; | |
7725ccfd | 1870 | struct fc_rpsc_speed_info_s speeds; |
a36c61f9 | 1871 | struct bfa_port_attr_s pport_attr; |
7725ccfd JH |
1872 | |
1873 | bfa_trc(port->fcs, rx_fchs->s_id); | |
1874 | bfa_trc(port->fcs, rx_fchs->d_id); | |
1875 | ||
1876 | rport->stats.rpsc_rcvd++; | |
1877 | speeds.port_speed_cap = | |
1878 | RPSC_SPEED_CAP_1G | RPSC_SPEED_CAP_2G | RPSC_SPEED_CAP_4G | | |
1879 | RPSC_SPEED_CAP_8G; | |
1880 | ||
1881 | /* | |
1882 | * get curent speed from pport attributes from BFA | |
1883 | */ | |
1c8a4c37 | 1884 | bfa_fcport_get_attr(port->fcs->bfa, &pport_attr); |
7725ccfd JH |
1885 | |
1886 | speeds.port_op_speed = fc_bfa_speed_to_rpsc_operspeed(pport_attr.speed); | |
1887 | ||
1888 | fcxp = bfa_fcs_fcxp_alloc(port->fcs); | |
1889 | if (!fcxp) | |
1890 | return; | |
1891 | ||
a36c61f9 KG |
1892 | len = fc_rpsc_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), |
1893 | rx_fchs->s_id, bfa_fcs_lport_get_fcid(port), | |
1894 | rx_fchs->ox_id, &speeds); | |
7725ccfd JH |
1895 | |
1896 | bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE, | |
a36c61f9 | 1897 | FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0); |
7725ccfd JH |
1898 | } |
1899 | ||
1900 | static void | |
1901 | bfa_fcs_rport_process_adisc(struct bfa_fcs_rport_s *rport, | |
1902 | struct fchs_s *rx_fchs, u16 len) | |
1903 | { | |
1904 | struct bfa_fcxp_s *fcxp; | |
a36c61f9 KG |
1905 | struct fchs_s fchs; |
1906 | struct bfa_fcs_lport_s *port = rport->port; | |
1907 | struct fc_adisc_s *adisc; | |
7725ccfd JH |
1908 | |
1909 | bfa_trc(port->fcs, rx_fchs->s_id); | |
1910 | bfa_trc(port->fcs, rx_fchs->d_id); | |
1911 | ||
1912 | rport->stats.adisc_rcvd++; | |
1913 | ||
7725ccfd JH |
1914 | adisc = (struct fc_adisc_s *) (rx_fchs + 1); |
1915 | ||
1916 | /* | |
a36c61f9 KG |
1917 | * Accept if the itnim for this rport is online. |
1918 | * Else reject the ADISC. | |
7725ccfd JH |
1919 | */ |
1920 | if (bfa_fcs_itnim_get_online_state(rport->itnim) == BFA_STATUS_OK) { | |
1921 | ||
1922 | fcxp = bfa_fcs_fcxp_alloc(port->fcs); | |
1923 | if (!fcxp) | |
1924 | return; | |
1925 | ||
1926 | len = fc_adisc_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), | |
a36c61f9 KG |
1927 | rx_fchs->s_id, bfa_fcs_lport_get_fcid(port), |
1928 | rx_fchs->ox_id, port->port_cfg.pwwn, | |
1929 | port->port_cfg.nwwn); | |
7725ccfd JH |
1930 | |
1931 | bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, | |
a36c61f9 KG |
1932 | BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL, |
1933 | FC_MAX_PDUSZ, 0); | |
7725ccfd JH |
1934 | } else { |
1935 | rport->stats.adisc_rejected++; | |
1936 | bfa_fcs_rport_send_ls_rjt(rport, rx_fchs, | |
1937 | FC_LS_RJT_RSN_UNABLE_TO_PERF_CMD, | |
1938 | FC_LS_RJT_EXP_LOGIN_REQUIRED); | |
1939 | } | |
7725ccfd JH |
1940 | } |
1941 | ||
1942 | static void | |
1943 | bfa_fcs_rport_hal_online(struct bfa_fcs_rport_s *rport) | |
1944 | { | |
a36c61f9 | 1945 | struct bfa_fcs_lport_s *port = rport->port; |
7725ccfd JH |
1946 | struct bfa_rport_info_s rport_info; |
1947 | ||
1948 | rport_info.pid = rport->pid; | |
1949 | rport_info.local_pid = port->pid; | |
1950 | rport_info.lp_tag = port->lp_tag; | |
1951 | rport_info.vf_id = port->fabric->vf_id; | |
1952 | rport_info.vf_en = port->fabric->is_vf; | |
1953 | rport_info.fc_class = rport->fc_cos; | |
1954 | rport_info.cisc = rport->cisc; | |
1955 | rport_info.max_frmsz = rport->maxfrsize; | |
1956 | bfa_rport_online(rport->bfa_rport, &rport_info); | |
1957 | } | |
1958 | ||
7725ccfd | 1959 | static struct bfa_fcs_rport_s * |
a36c61f9 | 1960 | bfa_fcs_rport_alloc(struct bfa_fcs_lport_s *port, wwn_t pwwn, u32 rpid) |
7725ccfd | 1961 | { |
a36c61f9 | 1962 | struct bfa_fcs_s *fcs = port->fcs; |
7725ccfd | 1963 | struct bfa_fcs_rport_s *rport; |
a36c61f9 | 1964 | struct bfad_rport_s *rport_drv; |
7725ccfd | 1965 | |
5fbe25c7 | 1966 | /* |
7725ccfd JH |
1967 | * allocate rport |
1968 | */ | |
1969 | if (bfa_fcb_rport_alloc(fcs->bfad, &rport, &rport_drv) | |
a36c61f9 | 1970 | != BFA_STATUS_OK) { |
7725ccfd JH |
1971 | bfa_trc(fcs, rpid); |
1972 | return NULL; | |
1973 | } | |
1974 | ||
1975 | /* | |
1976 | * Initialize r-port | |
1977 | */ | |
1978 | rport->port = port; | |
1979 | rport->fcs = fcs; | |
1980 | rport->rp_drv = rport_drv; | |
1981 | rport->pid = rpid; | |
1982 | rport->pwwn = pwwn; | |
1983 | ||
5fbe25c7 | 1984 | /* |
7725ccfd JH |
1985 | * allocate BFA rport |
1986 | */ | |
1987 | rport->bfa_rport = bfa_rport_create(port->fcs->bfa, rport); | |
1988 | if (!rport->bfa_rport) { | |
1989 | bfa_trc(fcs, rpid); | |
1990 | kfree(rport_drv); | |
1991 | return NULL; | |
1992 | } | |
1993 | ||
5fbe25c7 | 1994 | /* |
7725ccfd JH |
1995 | * allocate FC-4s |
1996 | */ | |
d4b671c5 | 1997 | WARN_ON(!bfa_fcs_lport_is_initiator(port)); |
7725ccfd | 1998 | |
a36c61f9 | 1999 | if (bfa_fcs_lport_is_initiator(port)) { |
7725ccfd JH |
2000 | rport->itnim = bfa_fcs_itnim_create(rport); |
2001 | if (!rport->itnim) { | |
2002 | bfa_trc(fcs, rpid); | |
da99dcc9 MZ |
2003 | bfa_sm_send_event(rport->bfa_rport, |
2004 | BFA_RPORT_SM_DELETE); | |
7725ccfd JH |
2005 | kfree(rport_drv); |
2006 | return NULL; | |
2007 | } | |
2008 | } | |
2009 | ||
a36c61f9 | 2010 | bfa_fcs_lport_add_rport(port, rport); |
7725ccfd JH |
2011 | |
2012 | bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit); | |
2013 | ||
a36c61f9 | 2014 | /* Initialize the Rport Features(RPF) Sub Module */ |
7725ccfd JH |
2015 | if (!BFA_FCS_PID_IS_WKA(rport->pid)) |
2016 | bfa_fcs_rpf_init(rport); | |
2017 | ||
2018 | return rport; | |
2019 | } | |
2020 | ||
2021 | ||
2022 | static void | |
2023 | bfa_fcs_rport_free(struct bfa_fcs_rport_s *rport) | |
2024 | { | |
a36c61f9 | 2025 | struct bfa_fcs_lport_s *port = rport->port; |
7725ccfd | 2026 | |
5fbe25c7 | 2027 | /* |
7725ccfd JH |
2028 | * - delete FC-4s |
2029 | * - delete BFA rport | |
2030 | * - remove from queue of rports | |
2031 | */ | |
a36c61f9 | 2032 | if (bfa_fcs_lport_is_initiator(port)) { |
7725ccfd | 2033 | bfa_fcs_itnim_delete(rport->itnim); |
a36c61f9 KG |
2034 | if (rport->pid != 0 && !BFA_FCS_PID_IS_WKA(rport->pid)) |
2035 | bfa_fcs_rpf_rport_offline(rport); | |
2036 | } | |
7725ccfd | 2037 | |
f7f73812 | 2038 | bfa_sm_send_event(rport->bfa_rport, BFA_RPORT_SM_DELETE); |
a36c61f9 | 2039 | bfa_fcs_lport_del_rport(port, rport); |
7725ccfd JH |
2040 | kfree(rport->rp_drv); |
2041 | } | |
2042 | ||
7725ccfd JH |
2043 | static void |
2044 | bfa_fcs_rport_online_action(struct bfa_fcs_rport_s *rport) | |
2045 | { | |
a36c61f9 KG |
2046 | struct bfa_fcs_lport_s *port = rport->port; |
2047 | struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad; | |
2048 | char lpwwn_buf[BFA_STRING_32]; | |
2049 | char rpwwn_buf[BFA_STRING_32]; | |
7725ccfd JH |
2050 | |
2051 | rport->stats.onlines++; | |
2052 | ||
d7be54cc KG |
2053 | if ((!rport->pid) || (!rport->pwwn)) { |
2054 | bfa_trc(rport->fcs, rport->pid); | |
2055 | bfa_sm_fault(rport->fcs, rport->pid); | |
2056 | } | |
2057 | ||
a36c61f9 | 2058 | if (bfa_fcs_lport_is_initiator(port)) { |
7725ccfd JH |
2059 | bfa_fcs_itnim_rport_online(rport->itnim); |
2060 | if (!BFA_FCS_PID_IS_WKA(rport->pid)) | |
2061 | bfa_fcs_rpf_rport_online(rport); | |
2062 | }; | |
2063 | ||
a36c61f9 KG |
2064 | wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port)); |
2065 | wwn2str(rpwwn_buf, rport->pwwn); | |
7725ccfd | 2066 | if (!BFA_FCS_PID_IS_WKA(rport->pid)) |
88166242 | 2067 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, |
a36c61f9 KG |
2068 | "Remote port (WWN = %s) online for logical port (WWN = %s)\n", |
2069 | rpwwn_buf, lpwwn_buf); | |
7725ccfd JH |
2070 | } |
2071 | ||
2072 | static void | |
2073 | bfa_fcs_rport_offline_action(struct bfa_fcs_rport_s *rport) | |
2074 | { | |
a36c61f9 KG |
2075 | struct bfa_fcs_lport_s *port = rport->port; |
2076 | struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad; | |
2077 | char lpwwn_buf[BFA_STRING_32]; | |
2078 | char rpwwn_buf[BFA_STRING_32]; | |
7725ccfd JH |
2079 | |
2080 | rport->stats.offlines++; | |
d7be54cc | 2081 | rport->plogi_pending = BFA_FALSE; |
7725ccfd | 2082 | |
a36c61f9 KG |
2083 | wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port)); |
2084 | wwn2str(rpwwn_buf, rport->pwwn); | |
7725ccfd | 2085 | if (!BFA_FCS_PID_IS_WKA(rport->pid)) { |
a36c61f9 | 2086 | if (bfa_fcs_lport_is_online(rport->port) == BFA_TRUE) |
88166242 | 2087 | BFA_LOG(KERN_ERR, bfad, bfa_log_level, |
a36c61f9 KG |
2088 | "Remote port (WWN = %s) connectivity lost for " |
2089 | "logical port (WWN = %s)\n", | |
2090 | rpwwn_buf, lpwwn_buf); | |
2091 | else | |
88166242 | 2092 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, |
a36c61f9 KG |
2093 | "Remote port (WWN = %s) offlined by " |
2094 | "logical port (WWN = %s)\n", | |
2095 | rpwwn_buf, lpwwn_buf); | |
7725ccfd JH |
2096 | } |
2097 | ||
a36c61f9 | 2098 | if (bfa_fcs_lport_is_initiator(port)) { |
7725ccfd JH |
2099 | bfa_fcs_itnim_rport_offline(rport->itnim); |
2100 | if (!BFA_FCS_PID_IS_WKA(rport->pid)) | |
2101 | bfa_fcs_rpf_rport_offline(rport); | |
2102 | } | |
7725ccfd JH |
2103 | } |
2104 | ||
5fbe25c7 | 2105 | /* |
7725ccfd JH |
2106 | * Update rport parameters from PLOGI or PLOGI accept. |
2107 | */ | |
2108 | static void | |
2109 | bfa_fcs_rport_update(struct bfa_fcs_rport_s *rport, struct fc_logi_s *plogi) | |
2110 | { | |
a36c61f9 | 2111 | bfa_fcs_lport_t *port = rport->port; |
7725ccfd | 2112 | |
5fbe25c7 | 2113 | /* |
7725ccfd JH |
2114 | * - port name |
2115 | * - node name | |
2116 | */ | |
2117 | rport->pwwn = plogi->port_name; | |
2118 | rport->nwwn = plogi->node_name; | |
2119 | ||
5fbe25c7 | 2120 | /* |
7725ccfd JH |
2121 | * - class of service |
2122 | */ | |
2123 | rport->fc_cos = 0; | |
2124 | if (plogi->class3.class_valid) | |
2125 | rport->fc_cos = FC_CLASS_3; | |
2126 | ||
2127 | if (plogi->class2.class_valid) | |
2128 | rport->fc_cos |= FC_CLASS_2; | |
2129 | ||
5fbe25c7 | 2130 | /* |
7725ccfd JH |
2131 | * - CISC |
2132 | * - MAX receive frame size | |
2133 | */ | |
2134 | rport->cisc = plogi->csp.cisc; | |
ba816ea8 | 2135 | rport->maxfrsize = be16_to_cpu(plogi->class3.rxsz); |
7725ccfd | 2136 | |
ba816ea8 | 2137 | bfa_trc(port->fcs, be16_to_cpu(plogi->csp.bbcred)); |
7725ccfd | 2138 | bfa_trc(port->fcs, port->fabric->bb_credit); |
5fbe25c7 | 2139 | /* |
7725ccfd JH |
2140 | * Direct Attach P2P mode : |
2141 | * This is to handle a bug (233476) in IBM targets in Direct Attach | |
a36c61f9 KG |
2142 | * Mode. Basically, in FLOGI Accept the target would have |
2143 | * erroneously set the BB Credit to the value used in the FLOGI | |
2144 | * sent by the HBA. It uses the correct value (its own BB credit) | |
2145 | * in PLOGI. | |
7725ccfd | 2146 | */ |
a36c61f9 | 2147 | if ((!bfa_fcs_fabric_is_switched(port->fabric)) && |
ba816ea8 | 2148 | (be16_to_cpu(plogi->csp.bbcred) < port->fabric->bb_credit)) { |
7725ccfd | 2149 | |
ba816ea8 | 2150 | bfa_trc(port->fcs, be16_to_cpu(plogi->csp.bbcred)); |
7725ccfd JH |
2151 | bfa_trc(port->fcs, port->fabric->bb_credit); |
2152 | ||
ba816ea8 | 2153 | port->fabric->bb_credit = be16_to_cpu(plogi->csp.bbcred); |
1c8a4c37 | 2154 | bfa_fcport_set_tx_bbcredit(port->fcs->bfa, |
be540a99 | 2155 | port->fabric->bb_credit, 0); |
7725ccfd JH |
2156 | } |
2157 | ||
2158 | } | |
2159 | ||
5fbe25c7 | 2160 | /* |
a36c61f9 | 2161 | * Called to handle LOGO received from an existing remote port. |
7725ccfd JH |
2162 | */ |
2163 | static void | |
2164 | bfa_fcs_rport_process_logo(struct bfa_fcs_rport_s *rport, struct fchs_s *fchs) | |
2165 | { | |
2166 | rport->reply_oxid = fchs->ox_id; | |
2167 | bfa_trc(rport->fcs, rport->reply_oxid); | |
2168 | ||
4b5e759d | 2169 | rport->prlo = BFA_FALSE; |
7725ccfd JH |
2170 | rport->stats.logo_rcvd++; |
2171 | bfa_sm_send_event(rport, RPSM_EVENT_LOGO_RCVD); | |
2172 | } | |
2173 | ||
2174 | ||
2175 | ||
5fbe25c7 | 2176 | /* |
7725ccfd JH |
2177 | * fcs_rport_public FCS rport public interfaces |
2178 | */ | |
2179 | ||
5fbe25c7 | 2180 | /* |
a36c61f9 KG |
2181 | * Called by bport/vport to create a remote port instance for a discovered |
2182 | * remote device. | |
7725ccfd JH |
2183 | * |
2184 | * @param[in] port - base port or vport | |
2185 | * @param[in] rpid - remote port ID | |
2186 | * | |
2187 | * @return None | |
2188 | */ | |
2189 | struct bfa_fcs_rport_s * | |
a36c61f9 | 2190 | bfa_fcs_rport_create(struct bfa_fcs_lport_s *port, u32 rpid) |
7725ccfd JH |
2191 | { |
2192 | struct bfa_fcs_rport_s *rport; | |
2193 | ||
2194 | bfa_trc(port->fcs, rpid); | |
2195 | rport = bfa_fcs_rport_alloc(port, WWN_NULL, rpid); | |
2196 | if (!rport) | |
2197 | return NULL; | |
2198 | ||
2199 | bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_SEND); | |
2200 | return rport; | |
2201 | } | |
2202 | ||
5fbe25c7 | 2203 | /* |
7725ccfd JH |
2204 | * Called to create a rport for which only the wwn is known. |
2205 | * | |
2206 | * @param[in] port - base port | |
2207 | * @param[in] rpwwn - remote port wwn | |
2208 | * | |
2209 | * @return None | |
2210 | */ | |
2211 | struct bfa_fcs_rport_s * | |
a36c61f9 | 2212 | bfa_fcs_rport_create_by_wwn(struct bfa_fcs_lport_s *port, wwn_t rpwwn) |
7725ccfd JH |
2213 | { |
2214 | struct bfa_fcs_rport_s *rport; | |
7725ccfd JH |
2215 | bfa_trc(port->fcs, rpwwn); |
2216 | rport = bfa_fcs_rport_alloc(port, rpwwn, 0); | |
2217 | if (!rport) | |
2218 | return NULL; | |
2219 | ||
2220 | bfa_sm_send_event(rport, RPSM_EVENT_ADDRESS_DISC); | |
2221 | return rport; | |
2222 | } | |
5fbe25c7 | 2223 | /* |
7725ccfd JH |
2224 | * Called by bport in private loop topology to indicate that a |
2225 | * rport has been discovered and plogi has been completed. | |
2226 | * | |
2227 | * @param[in] port - base port or vport | |
2228 | * @param[in] rpid - remote port ID | |
2229 | */ | |
2230 | void | |
a36c61f9 KG |
2231 | bfa_fcs_rport_start(struct bfa_fcs_lport_s *port, struct fchs_s *fchs, |
2232 | struct fc_logi_s *plogi) | |
7725ccfd JH |
2233 | { |
2234 | struct bfa_fcs_rport_s *rport; | |
2235 | ||
2236 | rport = bfa_fcs_rport_alloc(port, WWN_NULL, fchs->s_id); | |
2237 | if (!rport) | |
2238 | return; | |
2239 | ||
2240 | bfa_fcs_rport_update(rport, plogi); | |
2241 | ||
2242 | bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_COMP); | |
2243 | } | |
2244 | ||
5fbe25c7 | 2245 | /* |
a36c61f9 KG |
2246 | * Called by bport/vport to handle PLOGI received from a new remote port. |
2247 | * If an existing rport does a plogi, it will be handled separately. | |
7725ccfd JH |
2248 | */ |
2249 | void | |
a36c61f9 KG |
2250 | bfa_fcs_rport_plogi_create(struct bfa_fcs_lport_s *port, struct fchs_s *fchs, |
2251 | struct fc_logi_s *plogi) | |
7725ccfd JH |
2252 | { |
2253 | struct bfa_fcs_rport_s *rport; | |
2254 | ||
2255 | rport = bfa_fcs_rport_alloc(port, plogi->port_name, fchs->s_id); | |
2256 | if (!rport) | |
2257 | return; | |
2258 | ||
2259 | bfa_fcs_rport_update(rport, plogi); | |
2260 | ||
2261 | rport->reply_oxid = fchs->ox_id; | |
2262 | bfa_trc(rport->fcs, rport->reply_oxid); | |
2263 | ||
2264 | rport->stats.plogi_rcvd++; | |
2265 | bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RCVD); | |
2266 | } | |
2267 | ||
5fbe25c7 | 2268 | /* |
a36c61f9 KG |
2269 | * Called by bport/vport to handle PLOGI received from an existing |
2270 | * remote port. | |
7725ccfd JH |
2271 | */ |
2272 | void | |
2273 | bfa_fcs_rport_plogi(struct bfa_fcs_rport_s *rport, struct fchs_s *rx_fchs, | |
a36c61f9 | 2274 | struct fc_logi_s *plogi) |
7725ccfd | 2275 | { |
5fbe25c7 | 2276 | /* |
7725ccfd JH |
2277 | * @todo Handle P2P and initiator-initiator. |
2278 | */ | |
2279 | ||
2280 | bfa_fcs_rport_update(rport, plogi); | |
2281 | ||
2282 | rport->reply_oxid = rx_fchs->ox_id; | |
2283 | bfa_trc(rport->fcs, rport->reply_oxid); | |
2284 | ||
d7be54cc KG |
2285 | rport->pid = rx_fchs->s_id; |
2286 | bfa_trc(rport->fcs, rport->pid); | |
2287 | ||
7725ccfd JH |
2288 | rport->stats.plogi_rcvd++; |
2289 | bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RCVD); | |
2290 | } | |
2291 | ||
7725ccfd | 2292 | |
5fbe25c7 | 2293 | /* |
a36c61f9 | 2294 | * Called by bport/vport to notify SCN for the remote port |
7725ccfd JH |
2295 | */ |
2296 | void | |
2297 | bfa_fcs_rport_scn(struct bfa_fcs_rport_s *rport) | |
2298 | { | |
7725ccfd JH |
2299 | rport->stats.rscns++; |
2300 | bfa_sm_send_event(rport, RPSM_EVENT_SCN); | |
2301 | } | |
2302 | ||
7725ccfd | 2303 | |
5fbe25c7 | 2304 | /* |
a36c61f9 KG |
2305 | * brief |
2306 | * This routine BFA callback for bfa_rport_online() call. | |
7725ccfd | 2307 | * |
a36c61f9 | 2308 | * param[in] cb_arg - rport struct. |
7725ccfd | 2309 | * |
a36c61f9 KG |
2310 | * return |
2311 | * void | |
7725ccfd | 2312 | * |
a36c61f9 | 2313 | * Special Considerations: |
7725ccfd | 2314 | * |
a36c61f9 | 2315 | * note |
7725ccfd JH |
2316 | */ |
2317 | void | |
2318 | bfa_cb_rport_online(void *cbarg) | |
2319 | { | |
2320 | ||
a36c61f9 | 2321 | struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg; |
7725ccfd JH |
2322 | |
2323 | bfa_trc(rport->fcs, rport->pwwn); | |
2324 | bfa_sm_send_event(rport, RPSM_EVENT_HCB_ONLINE); | |
2325 | } | |
2326 | ||
5fbe25c7 | 2327 | /* |
a36c61f9 KG |
2328 | * brief |
2329 | * This routine BFA callback for bfa_rport_offline() call. | |
7725ccfd | 2330 | * |
a36c61f9 | 2331 | * param[in] rport - |
7725ccfd | 2332 | * |
a36c61f9 KG |
2333 | * return |
2334 | * void | |
7725ccfd | 2335 | * |
a36c61f9 | 2336 | * Special Considerations: |
7725ccfd | 2337 | * |
a36c61f9 | 2338 | * note |
7725ccfd JH |
2339 | */ |
2340 | void | |
2341 | bfa_cb_rport_offline(void *cbarg) | |
2342 | { | |
a36c61f9 | 2343 | struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg; |
7725ccfd JH |
2344 | |
2345 | bfa_trc(rport->fcs, rport->pwwn); | |
2346 | bfa_sm_send_event(rport, RPSM_EVENT_HCB_OFFLINE); | |
2347 | } | |
2348 | ||
5fbe25c7 | 2349 | /* |
a36c61f9 KG |
2350 | * brief |
2351 | * This routine is a static BFA callback when there is a QoS flow_id | |
2352 | * change notification | |
7725ccfd | 2353 | * |
a36c61f9 | 2354 | * param[in] rport - |
7725ccfd | 2355 | * |
a36c61f9 KG |
2356 | * return |
2357 | * void | |
7725ccfd | 2358 | * |
a36c61f9 | 2359 | * Special Considerations: |
7725ccfd | 2360 | * |
a36c61f9 | 2361 | * note |
7725ccfd JH |
2362 | */ |
2363 | void | |
2364 | bfa_cb_rport_qos_scn_flowid(void *cbarg, | |
a36c61f9 KG |
2365 | struct bfa_rport_qos_attr_s old_qos_attr, |
2366 | struct bfa_rport_qos_attr_s new_qos_attr) | |
7725ccfd | 2367 | { |
a36c61f9 | 2368 | struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg; |
7725ccfd JH |
2369 | |
2370 | bfa_trc(rport->fcs, rport->pwwn); | |
7725ccfd JH |
2371 | } |
2372 | ||
5fbe25c7 | 2373 | /* |
a36c61f9 KG |
2374 | * brief |
2375 | * This routine is a static BFA callback when there is a QoS priority | |
2376 | * change notification | |
7725ccfd | 2377 | * |
a36c61f9 | 2378 | * param[in] rport - |
7725ccfd | 2379 | * |
a36c61f9 KG |
2380 | * return |
2381 | * void | |
7725ccfd | 2382 | * |
a36c61f9 | 2383 | * Special Considerations: |
7725ccfd | 2384 | * |
a36c61f9 | 2385 | * note |
7725ccfd JH |
2386 | */ |
2387 | void | |
a36c61f9 KG |
2388 | bfa_cb_rport_qos_scn_prio(void *cbarg, |
2389 | struct bfa_rport_qos_attr_s old_qos_attr, | |
2390 | struct bfa_rport_qos_attr_s new_qos_attr) | |
7725ccfd | 2391 | { |
a36c61f9 | 2392 | struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *) cbarg; |
7725ccfd JH |
2393 | |
2394 | bfa_trc(rport->fcs, rport->pwwn); | |
7725ccfd JH |
2395 | } |
2396 | ||
5fbe25c7 | 2397 | /* |
a36c61f9 | 2398 | * Called to process any unsolicted frames from this remote port |
7725ccfd JH |
2399 | */ |
2400 | void | |
a36c61f9 KG |
2401 | bfa_fcs_rport_uf_recv(struct bfa_fcs_rport_s *rport, |
2402 | struct fchs_s *fchs, u16 len) | |
7725ccfd | 2403 | { |
a36c61f9 KG |
2404 | struct bfa_fcs_lport_s *port = rport->port; |
2405 | struct fc_els_cmd_s *els_cmd; | |
7725ccfd JH |
2406 | |
2407 | bfa_trc(rport->fcs, fchs->s_id); | |
2408 | bfa_trc(rport->fcs, fchs->d_id); | |
2409 | bfa_trc(rport->fcs, fchs->type); | |
2410 | ||
2411 | if (fchs->type != FC_TYPE_ELS) | |
2412 | return; | |
2413 | ||
2414 | els_cmd = (struct fc_els_cmd_s *) (fchs + 1); | |
2415 | ||
2416 | bfa_trc(rport->fcs, els_cmd->els_code); | |
2417 | ||
2418 | switch (els_cmd->els_code) { | |
2419 | case FC_ELS_LOGO: | |
a36c61f9 | 2420 | bfa_stats(port, plogi_rcvd); |
7725ccfd JH |
2421 | bfa_fcs_rport_process_logo(rport, fchs); |
2422 | break; | |
2423 | ||
2424 | case FC_ELS_ADISC: | |
a36c61f9 | 2425 | bfa_stats(port, adisc_rcvd); |
7725ccfd JH |
2426 | bfa_fcs_rport_process_adisc(rport, fchs, len); |
2427 | break; | |
2428 | ||
2429 | case FC_ELS_PRLO: | |
a36c61f9 KG |
2430 | bfa_stats(port, prlo_rcvd); |
2431 | if (bfa_fcs_lport_is_initiator(port)) | |
7725ccfd | 2432 | bfa_fcs_fcpim_uf_recv(rport->itnim, fchs, len); |
7725ccfd JH |
2433 | break; |
2434 | ||
2435 | case FC_ELS_PRLI: | |
a36c61f9 | 2436 | bfa_stats(port, prli_rcvd); |
7725ccfd JH |
2437 | bfa_fcs_rport_process_prli(rport, fchs, len); |
2438 | break; | |
2439 | ||
2440 | case FC_ELS_RPSC: | |
a36c61f9 | 2441 | bfa_stats(port, rpsc_rcvd); |
7725ccfd JH |
2442 | bfa_fcs_rport_process_rpsc(rport, fchs, len); |
2443 | break; | |
2444 | ||
2445 | default: | |
a36c61f9 | 2446 | bfa_stats(port, un_handled_els_rcvd); |
7725ccfd JH |
2447 | bfa_fcs_rport_send_ls_rjt(rport, fchs, |
2448 | FC_LS_RJT_RSN_CMD_NOT_SUPP, | |
2449 | FC_LS_RJT_EXP_NO_ADDL_INFO); | |
2450 | break; | |
2451 | } | |
2452 | } | |
2453 | ||
a36c61f9 | 2454 | /* send best case acc to prlo */ |
4b5e759d JH |
2455 | static void |
2456 | bfa_fcs_rport_send_prlo_acc(struct bfa_fcs_rport_s *rport) | |
2457 | { | |
a36c61f9 KG |
2458 | struct bfa_fcs_lport_s *port = rport->port; |
2459 | struct fchs_s fchs; | |
4b5e759d | 2460 | struct bfa_fcxp_s *fcxp; |
a36c61f9 | 2461 | int len; |
4b5e759d JH |
2462 | |
2463 | bfa_trc(rport->fcs, rport->pid); | |
2464 | ||
2465 | fcxp = bfa_fcs_fcxp_alloc(port->fcs); | |
2466 | if (!fcxp) | |
2467 | return; | |
4b5e759d | 2468 | len = fc_prlo_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), |
a36c61f9 | 2469 | rport->pid, bfa_fcs_lport_get_fcid(port), |
4b5e759d JH |
2470 | rport->reply_oxid, 0); |
2471 | ||
2472 | bfa_fcxp_send(fcxp, rport->bfa_rport, port->fabric->vf_id, | |
a36c61f9 KG |
2473 | port->lp_tag, BFA_FALSE, FC_CLASS_3, len, &fchs, |
2474 | NULL, NULL, FC_MAX_PDUSZ, 0); | |
4b5e759d JH |
2475 | } |
2476 | ||
7725ccfd JH |
2477 | /* |
2478 | * Send a LS reject | |
2479 | */ | |
2480 | static void | |
2481 | bfa_fcs_rport_send_ls_rjt(struct bfa_fcs_rport_s *rport, struct fchs_s *rx_fchs, | |
2482 | u8 reason_code, u8 reason_code_expl) | |
2483 | { | |
a36c61f9 KG |
2484 | struct bfa_fcs_lport_s *port = rport->port; |
2485 | struct fchs_s fchs; | |
7725ccfd | 2486 | struct bfa_fcxp_s *fcxp; |
a36c61f9 | 2487 | int len; |
7725ccfd JH |
2488 | |
2489 | bfa_trc(rport->fcs, rx_fchs->s_id); | |
2490 | ||
2491 | fcxp = bfa_fcs_fcxp_alloc(rport->fcs); | |
2492 | if (!fcxp) | |
2493 | return; | |
2494 | ||
a36c61f9 KG |
2495 | len = fc_ls_rjt_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), |
2496 | rx_fchs->s_id, bfa_fcs_lport_get_fcid(port), | |
2497 | rx_fchs->ox_id, reason_code, reason_code_expl); | |
7725ccfd | 2498 | |
a36c61f9 KG |
2499 | bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, |
2500 | BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL, | |
2501 | FC_MAX_PDUSZ, 0); | |
7725ccfd JH |
2502 | } |
2503 | ||
5fbe25c7 | 2504 | /* |
7725ccfd JH |
2505 | * Return state of rport. |
2506 | */ | |
2507 | int | |
2508 | bfa_fcs_rport_get_state(struct bfa_fcs_rport_s *rport) | |
2509 | { | |
2510 | return bfa_sm_to_state(rport_sm_table, rport->sm); | |
2511 | } | |
2512 | ||
f7f73812 | 2513 | |
5fbe25c7 | 2514 | /* |
a36c61f9 KG |
2515 | * brief |
2516 | * Called by the Driver to set rport delete/ageout timeout | |
7725ccfd | 2517 | * |
a36c61f9 | 2518 | * param[in] rport timeout value in seconds. |
7725ccfd | 2519 | * |
a36c61f9 | 2520 | * return None |
7725ccfd JH |
2521 | */ |
2522 | void | |
2523 | bfa_fcs_rport_set_del_timeout(u8 rport_tmo) | |
2524 | { | |
a36c61f9 | 2525 | /* convert to Millisecs */ |
7725ccfd JH |
2526 | if (rport_tmo > 0) |
2527 | bfa_fcs_rport_del_timeout = rport_tmo * 1000; | |
2528 | } | |
4b5e759d | 2529 | void |
50444a34 | 2530 | bfa_fcs_rport_prlo(struct bfa_fcs_rport_s *rport, __be16 ox_id) |
4b5e759d JH |
2531 | { |
2532 | bfa_trc(rport->fcs, rport->pid); | |
2533 | ||
2534 | rport->prlo = BFA_TRUE; | |
2535 | rport->reply_oxid = ox_id; | |
2536 | bfa_sm_send_event(rport, RPSM_EVENT_PRLO_RCVD); | |
2537 | } | |
a36c61f9 KG |
2538 | |
2539 | ||
2540 | ||
5fbe25c7 | 2541 | /* |
a36c61f9 KG |
2542 | * Remote port implementation. |
2543 | */ | |
2544 | ||
5fbe25c7 | 2545 | /* |
a36c61f9 KG |
2546 | * fcs_rport_api FCS rport API. |
2547 | */ | |
2548 | ||
a36c61f9 KG |
2549 | struct bfa_fcs_rport_s * |
2550 | bfa_fcs_rport_lookup(struct bfa_fcs_lport_s *port, wwn_t rpwwn) | |
2551 | { | |
2552 | struct bfa_fcs_rport_s *rport; | |
2553 | ||
2554 | rport = bfa_fcs_lport_get_rport_by_pwwn(port, rpwwn); | |
2555 | if (rport == NULL) { | |
2556 | /* | |
2557 | * TBD Error handling | |
2558 | */ | |
2559 | } | |
2560 | ||
2561 | return rport; | |
2562 | } | |
2563 | ||
2564 | struct bfa_fcs_rport_s * | |
2565 | bfa_fcs_rport_lookup_by_nwwn(struct bfa_fcs_lport_s *port, wwn_t rnwwn) | |
2566 | { | |
2567 | struct bfa_fcs_rport_s *rport; | |
2568 | ||
2569 | rport = bfa_fcs_lport_get_rport_by_nwwn(port, rnwwn); | |
2570 | if (rport == NULL) { | |
2571 | /* | |
2572 | * TBD Error handling | |
2573 | */ | |
2574 | } | |
2575 | ||
2576 | return rport; | |
2577 | } | |
2578 | ||
5fbe25c7 | 2579 | /* |
a36c61f9 KG |
2580 | * Remote port features (RPF) implementation. |
2581 | */ | |
2582 | ||
2583 | #define BFA_FCS_RPF_RETRIES (3) | |
2584 | #define BFA_FCS_RPF_RETRY_TIMEOUT (1000) /* 1 sec (In millisecs) */ | |
2585 | ||
2586 | static void bfa_fcs_rpf_send_rpsc2(void *rport_cbarg, | |
2587 | struct bfa_fcxp_s *fcxp_alloced); | |
2588 | static void bfa_fcs_rpf_rpsc2_response(void *fcsarg, | |
2589 | struct bfa_fcxp_s *fcxp, | |
2590 | void *cbarg, | |
2591 | bfa_status_t req_status, | |
2592 | u32 rsp_len, | |
2593 | u32 resid_len, | |
2594 | struct fchs_s *rsp_fchs); | |
2595 | ||
2596 | static void bfa_fcs_rpf_timeout(void *arg); | |
2597 | ||
5fbe25c7 | 2598 | /* |
a36c61f9 KG |
2599 | * fcs_rport_ftrs_sm FCS rport state machine events |
2600 | */ | |
2601 | ||
2602 | enum rpf_event { | |
2603 | RPFSM_EVENT_RPORT_OFFLINE = 1, /* Rport offline */ | |
2604 | RPFSM_EVENT_RPORT_ONLINE = 2, /* Rport online */ | |
2605 | RPFSM_EVENT_FCXP_SENT = 3, /* Frame from has been sent */ | |
2606 | RPFSM_EVENT_TIMEOUT = 4, /* Rport SM timeout event */ | |
2607 | RPFSM_EVENT_RPSC_COMP = 5, | |
2608 | RPFSM_EVENT_RPSC_FAIL = 6, | |
2609 | RPFSM_EVENT_RPSC_ERROR = 7, | |
2610 | }; | |
2611 | ||
2612 | static void bfa_fcs_rpf_sm_uninit(struct bfa_fcs_rpf_s *rpf, | |
2613 | enum rpf_event event); | |
2614 | static void bfa_fcs_rpf_sm_rpsc_sending(struct bfa_fcs_rpf_s *rpf, | |
2615 | enum rpf_event event); | |
2616 | static void bfa_fcs_rpf_sm_rpsc(struct bfa_fcs_rpf_s *rpf, | |
2617 | enum rpf_event event); | |
2618 | static void bfa_fcs_rpf_sm_rpsc_retry(struct bfa_fcs_rpf_s *rpf, | |
2619 | enum rpf_event event); | |
2620 | static void bfa_fcs_rpf_sm_offline(struct bfa_fcs_rpf_s *rpf, | |
2621 | enum rpf_event event); | |
2622 | static void bfa_fcs_rpf_sm_online(struct bfa_fcs_rpf_s *rpf, | |
2623 | enum rpf_event event); | |
2624 | ||
2625 | static void | |
2626 | bfa_fcs_rpf_sm_uninit(struct bfa_fcs_rpf_s *rpf, enum rpf_event event) | |
2627 | { | |
2628 | struct bfa_fcs_rport_s *rport = rpf->rport; | |
2629 | struct bfa_fcs_fabric_s *fabric = &rport->fcs->fabric; | |
2630 | ||
2631 | bfa_trc(rport->fcs, rport->pwwn); | |
2632 | bfa_trc(rport->fcs, rport->pid); | |
2633 | bfa_trc(rport->fcs, event); | |
2634 | ||
2635 | switch (event) { | |
2636 | case RPFSM_EVENT_RPORT_ONLINE: | |
2637 | /* Send RPSC2 to a Brocade fabric only. */ | |
2638 | if ((!BFA_FCS_PID_IS_WKA(rport->pid)) && | |
f7f73812 | 2639 | ((rport->port->fabric->lps->brcd_switch) || |
a36c61f9 KG |
2640 | (bfa_fcs_fabric_get_switch_oui(fabric) == |
2641 | BFA_FCS_BRCD_SWITCH_OUI))) { | |
2642 | bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending); | |
2643 | rpf->rpsc_retries = 0; | |
2644 | bfa_fcs_rpf_send_rpsc2(rpf, NULL); | |
2645 | } | |
2646 | break; | |
2647 | ||
2648 | case RPFSM_EVENT_RPORT_OFFLINE: | |
2649 | break; | |
2650 | ||
2651 | default: | |
2652 | bfa_sm_fault(rport->fcs, event); | |
2653 | } | |
2654 | } | |
2655 | ||
2656 | static void | |
2657 | bfa_fcs_rpf_sm_rpsc_sending(struct bfa_fcs_rpf_s *rpf, enum rpf_event event) | |
2658 | { | |
2659 | struct bfa_fcs_rport_s *rport = rpf->rport; | |
2660 | ||
2661 | bfa_trc(rport->fcs, event); | |
2662 | ||
2663 | switch (event) { | |
2664 | case RPFSM_EVENT_FCXP_SENT: | |
2665 | bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc); | |
2666 | break; | |
2667 | ||
2668 | case RPFSM_EVENT_RPORT_OFFLINE: | |
2669 | bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline); | |
2670 | bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rpf->fcxp_wqe); | |
2671 | rpf->rpsc_retries = 0; | |
2672 | break; | |
2673 | ||
2674 | default: | |
2675 | bfa_sm_fault(rport->fcs, event); | |
2676 | } | |
2677 | } | |
2678 | ||
2679 | static void | |
2680 | bfa_fcs_rpf_sm_rpsc(struct bfa_fcs_rpf_s *rpf, enum rpf_event event) | |
2681 | { | |
2682 | struct bfa_fcs_rport_s *rport = rpf->rport; | |
2683 | ||
2684 | bfa_trc(rport->fcs, rport->pid); | |
2685 | bfa_trc(rport->fcs, event); | |
2686 | ||
2687 | switch (event) { | |
2688 | case RPFSM_EVENT_RPSC_COMP: | |
2689 | bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online); | |
2690 | /* Update speed info in f/w via BFA */ | |
2691 | if (rpf->rpsc_speed != BFA_PORT_SPEED_UNKNOWN) | |
2692 | bfa_rport_speed(rport->bfa_rport, rpf->rpsc_speed); | |
2693 | else if (rpf->assigned_speed != BFA_PORT_SPEED_UNKNOWN) | |
2694 | bfa_rport_speed(rport->bfa_rport, rpf->assigned_speed); | |
2695 | break; | |
2696 | ||
2697 | case RPFSM_EVENT_RPSC_FAIL: | |
2698 | /* RPSC not supported by rport */ | |
2699 | bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online); | |
2700 | break; | |
2701 | ||
2702 | case RPFSM_EVENT_RPSC_ERROR: | |
2703 | /* need to retry...delayed a bit. */ | |
2704 | if (rpf->rpsc_retries++ < BFA_FCS_RPF_RETRIES) { | |
2705 | bfa_timer_start(rport->fcs->bfa, &rpf->timer, | |
2706 | bfa_fcs_rpf_timeout, rpf, | |
2707 | BFA_FCS_RPF_RETRY_TIMEOUT); | |
2708 | bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_retry); | |
2709 | } else { | |
2710 | bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online); | |
2711 | } | |
2712 | break; | |
2713 | ||
2714 | case RPFSM_EVENT_RPORT_OFFLINE: | |
2715 | bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline); | |
2716 | bfa_fcxp_discard(rpf->fcxp); | |
2717 | rpf->rpsc_retries = 0; | |
2718 | break; | |
2719 | ||
2720 | default: | |
2721 | bfa_sm_fault(rport->fcs, event); | |
2722 | } | |
2723 | } | |
2724 | ||
2725 | static void | |
2726 | bfa_fcs_rpf_sm_rpsc_retry(struct bfa_fcs_rpf_s *rpf, enum rpf_event event) | |
2727 | { | |
2728 | struct bfa_fcs_rport_s *rport = rpf->rport; | |
2729 | ||
2730 | bfa_trc(rport->fcs, rport->pid); | |
2731 | bfa_trc(rport->fcs, event); | |
2732 | ||
2733 | switch (event) { | |
2734 | case RPFSM_EVENT_TIMEOUT: | |
2735 | /* re-send the RPSC */ | |
2736 | bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending); | |
2737 | bfa_fcs_rpf_send_rpsc2(rpf, NULL); | |
2738 | break; | |
2739 | ||
2740 | case RPFSM_EVENT_RPORT_OFFLINE: | |
2741 | bfa_timer_stop(&rpf->timer); | |
2742 | bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline); | |
2743 | rpf->rpsc_retries = 0; | |
2744 | break; | |
2745 | ||
2746 | default: | |
2747 | bfa_sm_fault(rport->fcs, event); | |
2748 | } | |
2749 | } | |
2750 | ||
2751 | static void | |
2752 | bfa_fcs_rpf_sm_online(struct bfa_fcs_rpf_s *rpf, enum rpf_event event) | |
2753 | { | |
2754 | struct bfa_fcs_rport_s *rport = rpf->rport; | |
2755 | ||
2756 | bfa_trc(rport->fcs, rport->pwwn); | |
2757 | bfa_trc(rport->fcs, rport->pid); | |
2758 | bfa_trc(rport->fcs, event); | |
2759 | ||
2760 | switch (event) { | |
2761 | case RPFSM_EVENT_RPORT_OFFLINE: | |
2762 | bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline); | |
2763 | rpf->rpsc_retries = 0; | |
2764 | break; | |
2765 | ||
2766 | default: | |
2767 | bfa_sm_fault(rport->fcs, event); | |
2768 | } | |
2769 | } | |
2770 | ||
2771 | static void | |
2772 | bfa_fcs_rpf_sm_offline(struct bfa_fcs_rpf_s *rpf, enum rpf_event event) | |
2773 | { | |
2774 | struct bfa_fcs_rport_s *rport = rpf->rport; | |
2775 | ||
2776 | bfa_trc(rport->fcs, rport->pwwn); | |
2777 | bfa_trc(rport->fcs, rport->pid); | |
2778 | bfa_trc(rport->fcs, event); | |
2779 | ||
2780 | switch (event) { | |
2781 | case RPFSM_EVENT_RPORT_ONLINE: | |
2782 | bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending); | |
2783 | bfa_fcs_rpf_send_rpsc2(rpf, NULL); | |
2784 | break; | |
2785 | ||
2786 | case RPFSM_EVENT_RPORT_OFFLINE: | |
2787 | break; | |
2788 | ||
2789 | default: | |
2790 | bfa_sm_fault(rport->fcs, event); | |
2791 | } | |
2792 | } | |
5fbe25c7 | 2793 | /* |
a36c61f9 KG |
2794 | * Called when Rport is created. |
2795 | */ | |
2796 | void | |
2797 | bfa_fcs_rpf_init(struct bfa_fcs_rport_s *rport) | |
2798 | { | |
2799 | struct bfa_fcs_rpf_s *rpf = &rport->rpf; | |
2800 | ||
2801 | bfa_trc(rport->fcs, rport->pid); | |
2802 | rpf->rport = rport; | |
2803 | ||
2804 | bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_uninit); | |
2805 | } | |
2806 | ||
5fbe25c7 | 2807 | /* |
a36c61f9 KG |
2808 | * Called when Rport becomes online |
2809 | */ | |
2810 | void | |
2811 | bfa_fcs_rpf_rport_online(struct bfa_fcs_rport_s *rport) | |
2812 | { | |
2813 | bfa_trc(rport->fcs, rport->pid); | |
2814 | ||
2815 | if (__fcs_min_cfg(rport->port->fcs)) | |
2816 | return; | |
2817 | ||
2818 | if (bfa_fcs_fabric_is_switched(rport->port->fabric)) | |
2819 | bfa_sm_send_event(&rport->rpf, RPFSM_EVENT_RPORT_ONLINE); | |
2820 | } | |
2821 | ||
5fbe25c7 | 2822 | /* |
a36c61f9 KG |
2823 | * Called when Rport becomes offline |
2824 | */ | |
2825 | void | |
2826 | bfa_fcs_rpf_rport_offline(struct bfa_fcs_rport_s *rport) | |
2827 | { | |
2828 | bfa_trc(rport->fcs, rport->pid); | |
2829 | ||
2830 | if (__fcs_min_cfg(rport->port->fcs)) | |
2831 | return; | |
2832 | ||
2833 | rport->rpf.rpsc_speed = 0; | |
2834 | bfa_sm_send_event(&rport->rpf, RPFSM_EVENT_RPORT_OFFLINE); | |
2835 | } | |
2836 | ||
2837 | static void | |
2838 | bfa_fcs_rpf_timeout(void *arg) | |
2839 | { | |
2840 | struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *) arg; | |
2841 | struct bfa_fcs_rport_s *rport = rpf->rport; | |
2842 | ||
2843 | bfa_trc(rport->fcs, rport->pid); | |
2844 | bfa_sm_send_event(rpf, RPFSM_EVENT_TIMEOUT); | |
2845 | } | |
2846 | ||
2847 | static void | |
2848 | bfa_fcs_rpf_send_rpsc2(void *rpf_cbarg, struct bfa_fcxp_s *fcxp_alloced) | |
2849 | { | |
2850 | struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *)rpf_cbarg; | |
2851 | struct bfa_fcs_rport_s *rport = rpf->rport; | |
2852 | struct bfa_fcs_lport_s *port = rport->port; | |
2853 | struct fchs_s fchs; | |
2854 | int len; | |
2855 | struct bfa_fcxp_s *fcxp; | |
2856 | ||
2857 | bfa_trc(rport->fcs, rport->pwwn); | |
2858 | ||
2859 | fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs); | |
2860 | if (!fcxp) { | |
2861 | bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &rpf->fcxp_wqe, | |
2862 | bfa_fcs_rpf_send_rpsc2, rpf); | |
2863 | return; | |
2864 | } | |
2865 | rpf->fcxp = fcxp; | |
2866 | ||
2867 | len = fc_rpsc2_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid, | |
2868 | bfa_fcs_lport_get_fcid(port), &rport->pid, 1); | |
2869 | ||
2870 | bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE, | |
2871 | FC_CLASS_3, len, &fchs, bfa_fcs_rpf_rpsc2_response, | |
2872 | rpf, FC_MAX_PDUSZ, FC_ELS_TOV); | |
2873 | rport->stats.rpsc_sent++; | |
2874 | bfa_sm_send_event(rpf, RPFSM_EVENT_FCXP_SENT); | |
2875 | ||
2876 | } | |
2877 | ||
2878 | static void | |
2879 | bfa_fcs_rpf_rpsc2_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg, | |
2880 | bfa_status_t req_status, u32 rsp_len, | |
2881 | u32 resid_len, struct fchs_s *rsp_fchs) | |
2882 | { | |
2883 | struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *) cbarg; | |
2884 | struct bfa_fcs_rport_s *rport = rpf->rport; | |
2885 | struct fc_ls_rjt_s *ls_rjt; | |
2886 | struct fc_rpsc2_acc_s *rpsc2_acc; | |
2887 | u16 num_ents; | |
2888 | ||
2889 | bfa_trc(rport->fcs, req_status); | |
2890 | ||
2891 | if (req_status != BFA_STATUS_OK) { | |
2892 | bfa_trc(rport->fcs, req_status); | |
2893 | if (req_status == BFA_STATUS_ETIMER) | |
2894 | rport->stats.rpsc_failed++; | |
2895 | bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR); | |
2896 | return; | |
2897 | } | |
2898 | ||
2899 | rpsc2_acc = (struct fc_rpsc2_acc_s *) BFA_FCXP_RSP_PLD(fcxp); | |
2900 | if (rpsc2_acc->els_cmd == FC_ELS_ACC) { | |
2901 | rport->stats.rpsc_accs++; | |
ba816ea8 | 2902 | num_ents = be16_to_cpu(rpsc2_acc->num_pids); |
a36c61f9 KG |
2903 | bfa_trc(rport->fcs, num_ents); |
2904 | if (num_ents > 0) { | |
d4b671c5 | 2905 | WARN_ON(rpsc2_acc->port_info[0].pid == rport->pid); |
a36c61f9 | 2906 | bfa_trc(rport->fcs, |
ba816ea8 | 2907 | be16_to_cpu(rpsc2_acc->port_info[0].pid)); |
a36c61f9 | 2908 | bfa_trc(rport->fcs, |
ba816ea8 | 2909 | be16_to_cpu(rpsc2_acc->port_info[0].speed)); |
a36c61f9 | 2910 | bfa_trc(rport->fcs, |
ba816ea8 | 2911 | be16_to_cpu(rpsc2_acc->port_info[0].index)); |
a36c61f9 KG |
2912 | bfa_trc(rport->fcs, |
2913 | rpsc2_acc->port_info[0].type); | |
2914 | ||
2915 | if (rpsc2_acc->port_info[0].speed == 0) { | |
2916 | bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR); | |
2917 | return; | |
2918 | } | |
2919 | ||
2920 | rpf->rpsc_speed = fc_rpsc_operspeed_to_bfa_speed( | |
ba816ea8 | 2921 | be16_to_cpu(rpsc2_acc->port_info[0].speed)); |
a36c61f9 KG |
2922 | |
2923 | bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_COMP); | |
2924 | } | |
2925 | } else { | |
2926 | ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp); | |
2927 | bfa_trc(rport->fcs, ls_rjt->reason_code); | |
2928 | bfa_trc(rport->fcs, ls_rjt->reason_code_expl); | |
2929 | rport->stats.rpsc_rejects++; | |
2930 | if (ls_rjt->reason_code == FC_LS_RJT_RSN_CMD_NOT_SUPP) | |
2931 | bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_FAIL); | |
2932 | else | |
2933 | bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR); | |
2934 | } | |
2935 | } |