x86/mm/pat: Don't report PAT on CPUs that don't support it
[linux/fpc-iii.git] / drivers / scsi / bfa / bfa_fcs_lport.c
blob4ddda72f60e62b8f787c2843d32d40fd4851f75b
1 /*
2 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
3 * Copyright (c) 2014- QLogic Corporation.
4 * All rights reserved
5 * www.qlogic.com
7 * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License (GPL) Version 2 as
11 * published by the Free Software Foundation
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
19 #include "bfad_drv.h"
20 #include "bfad_im.h"
21 #include "bfa_fcs.h"
22 #include "bfa_fcbuild.h"
23 #include "bfa_fc.h"
25 BFA_TRC_FILE(FCS, PORT);
28 * ALPA to LIXA bitmap mapping
30 * ALPA 0x00 (Word 0, Bit 30) is invalid for N_Ports. Also Word 0 Bit 31
31 * is for L_bit (login required) and is filled as ALPA 0x00 here.
33 static const u8 loop_alpa_map[] = {
34 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x0F, 0x10, /* Word 0 Bits 31..24 */
35 0x17, 0x18, 0x1B, 0x1D, 0x1E, 0x1F, 0x23, 0x25, /* Word 0 Bits 23..16 */
36 0x26, 0x27, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, /* Word 0 Bits 15..08 */
37 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x39, 0x3A, /* Word 0 Bits 07..00 */
39 0x3C, 0x43, 0x45, 0x46, 0x47, 0x49, 0x4A, 0x4B, /* Word 1 Bits 31..24 */
40 0x4C, 0x4D, 0x4E, 0x51, 0x52, 0x53, 0x54, 0x55, /* Word 1 Bits 23..16 */
41 0x56, 0x59, 0x5A, 0x5C, 0x63, 0x65, 0x66, 0x67, /* Word 1 Bits 15..08 */
42 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x71, 0x72, /* Word 1 Bits 07..00 */
44 0x73, 0x74, 0x75, 0x76, 0x79, 0x7A, 0x7C, 0x80, /* Word 2 Bits 31..24 */
45 0x81, 0x82, 0x84, 0x88, 0x8F, 0x90, 0x97, 0x98, /* Word 2 Bits 23..16 */
46 0x9B, 0x9D, 0x9E, 0x9F, 0xA3, 0xA5, 0xA6, 0xA7, /* Word 2 Bits 15..08 */
47 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xB1, 0xB2, /* Word 2 Bits 07..00 */
49 0xB3, 0xB4, 0xB5, 0xB6, 0xB9, 0xBA, 0xBC, 0xC3, /* Word 3 Bits 31..24 */
50 0xC5, 0xC6, 0xC7, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, /* Word 3 Bits 23..16 */
51 0xCE, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD9, /* Word 3 Bits 15..08 */
52 0xDA, 0xDC, 0xE0, 0xE1, 0xE2, 0xE4, 0xE8, 0xEF, /* Word 3 Bits 07..00 */
55 static void bfa_fcs_lport_send_ls_rjt(struct bfa_fcs_lport_s *port,
56 struct fchs_s *rx_fchs, u8 reason_code,
57 u8 reason_code_expl);
58 static void bfa_fcs_lport_plogi(struct bfa_fcs_lport_s *port,
59 struct fchs_s *rx_fchs, struct fc_logi_s *plogi);
60 static void bfa_fcs_lport_online_actions(struct bfa_fcs_lport_s *port);
61 static void bfa_fcs_lport_offline_actions(struct bfa_fcs_lport_s *port);
62 static void bfa_fcs_lport_unknown_init(struct bfa_fcs_lport_s *port);
63 static void bfa_fcs_lport_unknown_online(struct bfa_fcs_lport_s *port);
64 static void bfa_fcs_lport_unknown_offline(struct bfa_fcs_lport_s *port);
65 static void bfa_fcs_lport_deleted(struct bfa_fcs_lport_s *port);
66 static void bfa_fcs_lport_echo(struct bfa_fcs_lport_s *port,
67 struct fchs_s *rx_fchs,
68 struct fc_echo_s *echo, u16 len);
69 static void bfa_fcs_lport_rnid(struct bfa_fcs_lport_s *port,
70 struct fchs_s *rx_fchs,
71 struct fc_rnid_cmd_s *rnid, u16 len);
72 static void bfa_fs_port_get_gen_topo_data(struct bfa_fcs_lport_s *port,
73 struct fc_rnid_general_topology_data_s *gen_topo_data);
75 static void bfa_fcs_lport_fab_init(struct bfa_fcs_lport_s *port);
76 static void bfa_fcs_lport_fab_online(struct bfa_fcs_lport_s *port);
77 static void bfa_fcs_lport_fab_offline(struct bfa_fcs_lport_s *port);
79 static void bfa_fcs_lport_n2n_init(struct bfa_fcs_lport_s *port);
80 static void bfa_fcs_lport_n2n_online(struct bfa_fcs_lport_s *port);
81 static void bfa_fcs_lport_n2n_offline(struct bfa_fcs_lport_s *port);
83 static void bfa_fcs_lport_loop_init(struct bfa_fcs_lport_s *port);
84 static void bfa_fcs_lport_loop_online(struct bfa_fcs_lport_s *port);
85 static void bfa_fcs_lport_loop_offline(struct bfa_fcs_lport_s *port);
87 static struct {
88 void (*init) (struct bfa_fcs_lport_s *port);
89 void (*online) (struct bfa_fcs_lport_s *port);
90 void (*offline) (struct bfa_fcs_lport_s *port);
91 } __port_action[] = {
93 bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
94 bfa_fcs_lport_unknown_offline}, {
95 bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
96 bfa_fcs_lport_fab_offline}, {
97 bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
98 bfa_fcs_lport_n2n_offline}, {
99 bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
100 bfa_fcs_lport_loop_offline},
104 * fcs_port_sm FCS logical port state machine
107 enum bfa_fcs_lport_event {
108 BFA_FCS_PORT_SM_CREATE = 1,
109 BFA_FCS_PORT_SM_ONLINE = 2,
110 BFA_FCS_PORT_SM_OFFLINE = 3,
111 BFA_FCS_PORT_SM_DELETE = 4,
112 BFA_FCS_PORT_SM_DELRPORT = 5,
113 BFA_FCS_PORT_SM_STOP = 6,
116 static void bfa_fcs_lport_sm_uninit(struct bfa_fcs_lport_s *port,
117 enum bfa_fcs_lport_event event);
118 static void bfa_fcs_lport_sm_init(struct bfa_fcs_lport_s *port,
119 enum bfa_fcs_lport_event event);
120 static void bfa_fcs_lport_sm_online(struct bfa_fcs_lport_s *port,
121 enum bfa_fcs_lport_event event);
122 static void bfa_fcs_lport_sm_offline(struct bfa_fcs_lport_s *port,
123 enum bfa_fcs_lport_event event);
124 static void bfa_fcs_lport_sm_deleting(struct bfa_fcs_lport_s *port,
125 enum bfa_fcs_lport_event event);
126 static void bfa_fcs_lport_sm_stopping(struct bfa_fcs_lport_s *port,
127 enum bfa_fcs_lport_event event);
129 static void
130 bfa_fcs_lport_sm_uninit(
131 struct bfa_fcs_lport_s *port,
132 enum bfa_fcs_lport_event event)
134 bfa_trc(port->fcs, port->port_cfg.pwwn);
135 bfa_trc(port->fcs, event);
137 switch (event) {
138 case BFA_FCS_PORT_SM_CREATE:
139 bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
140 break;
142 default:
143 bfa_sm_fault(port->fcs, event);
147 static void
148 bfa_fcs_lport_sm_init(struct bfa_fcs_lport_s *port,
149 enum bfa_fcs_lport_event event)
151 bfa_trc(port->fcs, port->port_cfg.pwwn);
152 bfa_trc(port->fcs, event);
154 switch (event) {
155 case BFA_FCS_PORT_SM_ONLINE:
156 bfa_sm_set_state(port, bfa_fcs_lport_sm_online);
157 bfa_fcs_lport_online_actions(port);
158 break;
160 case BFA_FCS_PORT_SM_DELETE:
161 bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
162 bfa_fcs_lport_deleted(port);
163 break;
165 case BFA_FCS_PORT_SM_STOP:
166 /* If vport - send completion call back */
167 if (port->vport)
168 bfa_fcs_vport_stop_comp(port->vport);
169 else
170 bfa_wc_down(&(port->fabric->stop_wc));
171 break;
173 case BFA_FCS_PORT_SM_OFFLINE:
174 break;
176 default:
177 bfa_sm_fault(port->fcs, event);
181 static void
182 bfa_fcs_lport_sm_online(
183 struct bfa_fcs_lport_s *port,
184 enum bfa_fcs_lport_event event)
186 struct bfa_fcs_rport_s *rport;
187 struct list_head *qe, *qen;
189 bfa_trc(port->fcs, port->port_cfg.pwwn);
190 bfa_trc(port->fcs, event);
192 switch (event) {
193 case BFA_FCS_PORT_SM_OFFLINE:
194 bfa_sm_set_state(port, bfa_fcs_lport_sm_offline);
195 bfa_fcs_lport_offline_actions(port);
196 break;
198 case BFA_FCS_PORT_SM_STOP:
199 __port_action[port->fabric->fab_type].offline(port);
201 if (port->num_rports == 0) {
202 bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
203 /* If vport - send completion call back */
204 if (port->vport)
205 bfa_fcs_vport_stop_comp(port->vport);
206 else
207 bfa_wc_down(&(port->fabric->stop_wc));
208 } else {
209 bfa_sm_set_state(port, bfa_fcs_lport_sm_stopping);
210 list_for_each_safe(qe, qen, &port->rport_q) {
211 rport = (struct bfa_fcs_rport_s *) qe;
212 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
215 break;
217 case BFA_FCS_PORT_SM_DELETE:
219 __port_action[port->fabric->fab_type].offline(port);
221 if (port->num_rports == 0) {
222 bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
223 bfa_fcs_lport_deleted(port);
224 } else {
225 bfa_sm_set_state(port, bfa_fcs_lport_sm_deleting);
226 list_for_each_safe(qe, qen, &port->rport_q) {
227 rport = (struct bfa_fcs_rport_s *) qe;
228 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
231 break;
233 case BFA_FCS_PORT_SM_DELRPORT:
234 break;
236 default:
237 bfa_sm_fault(port->fcs, event);
241 static void
242 bfa_fcs_lport_sm_offline(
243 struct bfa_fcs_lport_s *port,
244 enum bfa_fcs_lport_event event)
246 struct bfa_fcs_rport_s *rport;
247 struct list_head *qe, *qen;
249 bfa_trc(port->fcs, port->port_cfg.pwwn);
250 bfa_trc(port->fcs, event);
252 switch (event) {
253 case BFA_FCS_PORT_SM_ONLINE:
254 bfa_sm_set_state(port, bfa_fcs_lport_sm_online);
255 bfa_fcs_lport_online_actions(port);
256 break;
258 case BFA_FCS_PORT_SM_STOP:
259 if (port->num_rports == 0) {
260 bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
261 /* If vport - send completion call back */
262 if (port->vport)
263 bfa_fcs_vport_stop_comp(port->vport);
264 else
265 bfa_wc_down(&(port->fabric->stop_wc));
266 } else {
267 bfa_sm_set_state(port, bfa_fcs_lport_sm_stopping);
268 list_for_each_safe(qe, qen, &port->rport_q) {
269 rport = (struct bfa_fcs_rport_s *) qe;
270 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
273 break;
275 case BFA_FCS_PORT_SM_DELETE:
276 if (port->num_rports == 0) {
277 bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
278 bfa_fcs_lport_deleted(port);
279 } else {
280 bfa_sm_set_state(port, bfa_fcs_lport_sm_deleting);
281 list_for_each_safe(qe, qen, &port->rport_q) {
282 rport = (struct bfa_fcs_rport_s *) qe;
283 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
286 break;
288 case BFA_FCS_PORT_SM_DELRPORT:
289 case BFA_FCS_PORT_SM_OFFLINE:
290 break;
292 default:
293 bfa_sm_fault(port->fcs, event);
297 static void
298 bfa_fcs_lport_sm_stopping(struct bfa_fcs_lport_s *port,
299 enum bfa_fcs_lport_event event)
301 bfa_trc(port->fcs, port->port_cfg.pwwn);
302 bfa_trc(port->fcs, event);
304 switch (event) {
305 case BFA_FCS_PORT_SM_DELRPORT:
306 if (port->num_rports == 0) {
307 bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
308 /* If vport - send completion call back */
309 if (port->vport)
310 bfa_fcs_vport_stop_comp(port->vport);
311 else
312 bfa_wc_down(&(port->fabric->stop_wc));
314 break;
316 default:
317 bfa_sm_fault(port->fcs, event);
321 static void
322 bfa_fcs_lport_sm_deleting(
323 struct bfa_fcs_lport_s *port,
324 enum bfa_fcs_lport_event event)
326 bfa_trc(port->fcs, port->port_cfg.pwwn);
327 bfa_trc(port->fcs, event);
329 switch (event) {
330 case BFA_FCS_PORT_SM_DELRPORT:
331 if (port->num_rports == 0) {
332 bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
333 bfa_fcs_lport_deleted(port);
335 break;
337 default:
338 bfa_sm_fault(port->fcs, event);
343 * fcs_port_pvt
347 * Send AEN notification
349 static void
350 bfa_fcs_lport_aen_post(struct bfa_fcs_lport_s *port,
351 enum bfa_lport_aen_event event)
353 struct bfad_s *bfad = (struct bfad_s *)port->fabric->fcs->bfad;
354 struct bfa_aen_entry_s *aen_entry;
356 bfad_get_aen_entry(bfad, aen_entry);
357 if (!aen_entry)
358 return;
360 aen_entry->aen_data.lport.vf_id = port->fabric->vf_id;
361 aen_entry->aen_data.lport.roles = port->port_cfg.roles;
362 aen_entry->aen_data.lport.ppwwn = bfa_fcs_lport_get_pwwn(
363 bfa_fcs_get_base_port(port->fcs));
364 aen_entry->aen_data.lport.lpwwn = bfa_fcs_lport_get_pwwn(port);
366 /* Send the AEN notification */
367 bfad_im_post_vendor_event(aen_entry, bfad, ++port->fcs->fcs_aen_seq,
368 BFA_AEN_CAT_LPORT, event);
372 * Send a LS reject
374 static void
375 bfa_fcs_lport_send_ls_rjt(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs,
376 u8 reason_code, u8 reason_code_expl)
378 struct fchs_s fchs;
379 struct bfa_fcxp_s *fcxp;
380 struct bfa_rport_s *bfa_rport = NULL;
381 int len;
383 bfa_trc(port->fcs, rx_fchs->d_id);
384 bfa_trc(port->fcs, rx_fchs->s_id);
386 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
387 if (!fcxp)
388 return;
390 len = fc_ls_rjt_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
391 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
392 rx_fchs->ox_id, reason_code, reason_code_expl);
394 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
395 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
396 FC_MAX_PDUSZ, 0);
400 * Send a FCCT Reject
402 static void
403 bfa_fcs_lport_send_fcgs_rjt(struct bfa_fcs_lport_s *port,
404 struct fchs_s *rx_fchs, u8 reason_code, u8 reason_code_expl)
406 struct fchs_s fchs;
407 struct bfa_fcxp_s *fcxp;
408 struct bfa_rport_s *bfa_rport = NULL;
409 int len;
410 struct ct_hdr_s *rx_cthdr = (struct ct_hdr_s *)(rx_fchs + 1);
411 struct ct_hdr_s *ct_hdr;
413 bfa_trc(port->fcs, rx_fchs->d_id);
414 bfa_trc(port->fcs, rx_fchs->s_id);
416 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
417 if (!fcxp)
418 return;
420 ct_hdr = bfa_fcxp_get_reqbuf(fcxp);
421 ct_hdr->gs_type = rx_cthdr->gs_type;
422 ct_hdr->gs_sub_type = rx_cthdr->gs_sub_type;
424 len = fc_gs_rjt_build(&fchs, ct_hdr, rx_fchs->s_id,
425 bfa_fcs_lport_get_fcid(port),
426 rx_fchs->ox_id, reason_code, reason_code_expl);
428 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
429 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
430 FC_MAX_PDUSZ, 0);
434 * Process incoming plogi from a remote port.
436 static void
437 bfa_fcs_lport_plogi(struct bfa_fcs_lport_s *port,
438 struct fchs_s *rx_fchs, struct fc_logi_s *plogi)
440 struct bfa_fcs_rport_s *rport;
442 bfa_trc(port->fcs, rx_fchs->d_id);
443 bfa_trc(port->fcs, rx_fchs->s_id);
446 * If min cfg mode is enabled, drop any incoming PLOGIs
448 if (__fcs_min_cfg(port->fcs)) {
449 bfa_trc(port->fcs, rx_fchs->s_id);
450 return;
453 if (fc_plogi_parse(rx_fchs) != FC_PARSE_OK) {
454 bfa_trc(port->fcs, rx_fchs->s_id);
456 * send a LS reject
458 bfa_fcs_lport_send_ls_rjt(port, rx_fchs,
459 FC_LS_RJT_RSN_PROTOCOL_ERROR,
460 FC_LS_RJT_EXP_SPARMS_ERR_OPTIONS);
461 return;
465 * Direct Attach P2P mode : verify address assigned by the r-port.
467 if ((!bfa_fcs_fabric_is_switched(port->fabric)) &&
468 (memcmp((void *)&bfa_fcs_lport_get_pwwn(port),
469 (void *)&plogi->port_name, sizeof(wwn_t)) < 0)) {
470 if (BFA_FCS_PID_IS_WKA(rx_fchs->d_id)) {
471 /* Address assigned to us cannot be a WKA */
472 bfa_fcs_lport_send_ls_rjt(port, rx_fchs,
473 FC_LS_RJT_RSN_PROTOCOL_ERROR,
474 FC_LS_RJT_EXP_INVALID_NPORT_ID);
475 return;
477 port->pid = rx_fchs->d_id;
478 bfa_lps_set_n2n_pid(port->fabric->lps, rx_fchs->d_id);
482 * First, check if we know the device by pwwn.
484 rport = bfa_fcs_lport_get_rport_by_pwwn(port, plogi->port_name);
485 if (rport) {
487 * Direct Attach P2P mode : handle address assigned by r-port.
489 if ((!bfa_fcs_fabric_is_switched(port->fabric)) &&
490 (memcmp((void *)&bfa_fcs_lport_get_pwwn(port),
491 (void *)&plogi->port_name, sizeof(wwn_t)) < 0)) {
492 port->pid = rx_fchs->d_id;
493 bfa_lps_set_n2n_pid(port->fabric->lps, rx_fchs->d_id);
494 rport->pid = rx_fchs->s_id;
496 bfa_fcs_rport_plogi(rport, rx_fchs, plogi);
497 return;
501 * Next, lookup rport by PID.
503 rport = bfa_fcs_lport_get_rport_by_pid(port, rx_fchs->s_id);
504 if (!rport) {
506 * Inbound PLOGI from a new device.
508 bfa_fcs_rport_plogi_create(port, rx_fchs, plogi);
509 return;
513 * Rport is known only by PID.
515 if (rport->pwwn) {
517 * This is a different device with the same pid. Old device
518 * disappeared. Send implicit LOGO to old device.
520 WARN_ON(rport->pwwn == plogi->port_name);
521 bfa_sm_send_event(rport, RPSM_EVENT_LOGO_IMP);
524 * Inbound PLOGI from a new device (with old PID).
526 bfa_fcs_rport_plogi_create(port, rx_fchs, plogi);
527 return;
531 * PLOGI crossing each other.
533 WARN_ON(rport->pwwn != WWN_NULL);
534 bfa_fcs_rport_plogi(rport, rx_fchs, plogi);
538 * Process incoming ECHO.
539 * Since it does not require a login, it is processed here.
541 static void
542 bfa_fcs_lport_echo(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs,
543 struct fc_echo_s *echo, u16 rx_len)
545 struct fchs_s fchs;
546 struct bfa_fcxp_s *fcxp;
547 struct bfa_rport_s *bfa_rport = NULL;
548 int len, pyld_len;
550 bfa_trc(port->fcs, rx_fchs->s_id);
551 bfa_trc(port->fcs, rx_fchs->d_id);
553 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
554 if (!fcxp)
555 return;
557 len = fc_ls_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
558 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
559 rx_fchs->ox_id);
562 * Copy the payload (if any) from the echo frame
564 pyld_len = rx_len - sizeof(struct fchs_s);
565 bfa_trc(port->fcs, rx_len);
566 bfa_trc(port->fcs, pyld_len);
568 if (pyld_len > len)
569 memcpy(((u8 *) bfa_fcxp_get_reqbuf(fcxp)) +
570 sizeof(struct fc_echo_s), (echo + 1),
571 (pyld_len - sizeof(struct fc_echo_s)));
573 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
574 BFA_FALSE, FC_CLASS_3, pyld_len, &fchs, NULL, NULL,
575 FC_MAX_PDUSZ, 0);
579 * Process incoming RNID.
580 * Since it does not require a login, it is processed here.
582 static void
583 bfa_fcs_lport_rnid(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs,
584 struct fc_rnid_cmd_s *rnid, u16 rx_len)
586 struct fc_rnid_common_id_data_s common_id_data;
587 struct fc_rnid_general_topology_data_s gen_topo_data;
588 struct fchs_s fchs;
589 struct bfa_fcxp_s *fcxp;
590 struct bfa_rport_s *bfa_rport = NULL;
591 u16 len;
592 u32 data_format;
594 bfa_trc(port->fcs, rx_fchs->s_id);
595 bfa_trc(port->fcs, rx_fchs->d_id);
596 bfa_trc(port->fcs, rx_len);
598 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
599 if (!fcxp)
600 return;
603 * Check Node Indentification Data Format
604 * We only support General Topology Discovery Format.
605 * For any other requested Data Formats, we return Common Node Id Data
606 * only, as per FC-LS.
608 bfa_trc(port->fcs, rnid->node_id_data_format);
609 if (rnid->node_id_data_format == RNID_NODEID_DATA_FORMAT_DISCOVERY) {
610 data_format = RNID_NODEID_DATA_FORMAT_DISCOVERY;
612 * Get General topology data for this port
614 bfa_fs_port_get_gen_topo_data(port, &gen_topo_data);
615 } else {
616 data_format = RNID_NODEID_DATA_FORMAT_COMMON;
620 * Copy the Node Id Info
622 common_id_data.port_name = bfa_fcs_lport_get_pwwn(port);
623 common_id_data.node_name = bfa_fcs_lport_get_nwwn(port);
625 len = fc_rnid_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
626 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
627 rx_fchs->ox_id, data_format, &common_id_data,
628 &gen_topo_data);
630 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
631 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
632 FC_MAX_PDUSZ, 0);
636 * Fill out General Topolpgy Discovery Data for RNID ELS.
638 static void
639 bfa_fs_port_get_gen_topo_data(struct bfa_fcs_lport_s *port,
640 struct fc_rnid_general_topology_data_s *gen_topo_data)
642 memset(gen_topo_data, 0,
643 sizeof(struct fc_rnid_general_topology_data_s));
645 gen_topo_data->asso_type = cpu_to_be32(RNID_ASSOCIATED_TYPE_HOST);
646 gen_topo_data->phy_port_num = 0; /* @todo */
647 gen_topo_data->num_attached_nodes = cpu_to_be32(1);
650 static void
651 bfa_fcs_lport_online_actions(struct bfa_fcs_lport_s *port)
653 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
654 char lpwwn_buf[BFA_STRING_32];
656 bfa_trc(port->fcs, port->fabric->oper_type);
658 __port_action[port->fabric->fab_type].init(port);
659 __port_action[port->fabric->fab_type].online(port);
661 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
662 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
663 "Logical port online: WWN = %s Role = %s\n",
664 lpwwn_buf, "Initiator");
665 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_ONLINE);
667 bfad->bfad_flags |= BFAD_PORT_ONLINE;
670 static void
671 bfa_fcs_lport_offline_actions(struct bfa_fcs_lport_s *port)
673 struct list_head *qe, *qen;
674 struct bfa_fcs_rport_s *rport;
675 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
676 char lpwwn_buf[BFA_STRING_32];
678 bfa_trc(port->fcs, port->fabric->oper_type);
680 __port_action[port->fabric->fab_type].offline(port);
682 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
683 if (bfa_sm_cmp_state(port->fabric,
684 bfa_fcs_fabric_sm_online) == BFA_TRUE) {
685 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
686 "Logical port lost fabric connectivity: WWN = %s Role = %s\n",
687 lpwwn_buf, "Initiator");
688 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_DISCONNECT);
689 } else {
690 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
691 "Logical port taken offline: WWN = %s Role = %s\n",
692 lpwwn_buf, "Initiator");
693 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_OFFLINE);
696 list_for_each_safe(qe, qen, &port->rport_q) {
697 rport = (struct bfa_fcs_rport_s *) qe;
698 bfa_sm_send_event(rport, RPSM_EVENT_LOGO_IMP);
702 static void
703 bfa_fcs_lport_unknown_init(struct bfa_fcs_lport_s *port)
705 WARN_ON(1);
708 static void
709 bfa_fcs_lport_unknown_online(struct bfa_fcs_lport_s *port)
711 WARN_ON(1);
714 static void
715 bfa_fcs_lport_unknown_offline(struct bfa_fcs_lport_s *port)
717 WARN_ON(1);
720 static void
721 bfa_fcs_lport_abts_acc(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs)
723 struct fchs_s fchs;
724 struct bfa_fcxp_s *fcxp;
725 int len;
727 bfa_trc(port->fcs, rx_fchs->d_id);
728 bfa_trc(port->fcs, rx_fchs->s_id);
730 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
731 if (!fcxp)
732 return;
734 len = fc_ba_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
735 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
736 rx_fchs->ox_id, 0);
738 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag,
739 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
740 FC_MAX_PDUSZ, 0);
742 static void
743 bfa_fcs_lport_deleted(struct bfa_fcs_lport_s *port)
745 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
746 char lpwwn_buf[BFA_STRING_32];
748 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
749 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
750 "Logical port deleted: WWN = %s Role = %s\n",
751 lpwwn_buf, "Initiator");
752 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_DELETE);
754 /* Base port will be deleted by the OS driver */
755 if (port->vport)
756 bfa_fcs_vport_delete_comp(port->vport);
757 else
758 bfa_wc_down(&port->fabric->wc);
763 * Unsolicited frame receive handling.
765 void
766 bfa_fcs_lport_uf_recv(struct bfa_fcs_lport_s *lport,
767 struct fchs_s *fchs, u16 len)
769 u32 pid = fchs->s_id;
770 struct bfa_fcs_rport_s *rport = NULL;
771 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
773 bfa_stats(lport, uf_recvs);
774 bfa_trc(lport->fcs, fchs->type);
776 if (!bfa_fcs_lport_is_online(lport)) {
778 * In direct attach topology, it is possible to get a PLOGI
779 * before the lport is online due to port feature
780 * (QoS/Trunk/FEC/CR), so send a rjt
782 if ((fchs->type == FC_TYPE_ELS) &&
783 (els_cmd->els_code == FC_ELS_PLOGI)) {
784 bfa_fcs_lport_send_ls_rjt(lport, fchs,
785 FC_LS_RJT_RSN_UNABLE_TO_PERF_CMD,
786 FC_LS_RJT_EXP_NO_ADDL_INFO);
787 bfa_stats(lport, plogi_rcvd);
788 } else
789 bfa_stats(lport, uf_recv_drops);
791 return;
795 * First, handle ELSs that donot require a login.
798 * Handle PLOGI first
800 if ((fchs->type == FC_TYPE_ELS) &&
801 (els_cmd->els_code == FC_ELS_PLOGI)) {
802 bfa_fcs_lport_plogi(lport, fchs, (struct fc_logi_s *) els_cmd);
803 return;
807 * Handle ECHO separately.
809 if ((fchs->type == FC_TYPE_ELS) && (els_cmd->els_code == FC_ELS_ECHO)) {
810 bfa_fcs_lport_echo(lport, fchs,
811 (struct fc_echo_s *)els_cmd, len);
812 return;
816 * Handle RNID separately.
818 if ((fchs->type == FC_TYPE_ELS) && (els_cmd->els_code == FC_ELS_RNID)) {
819 bfa_fcs_lport_rnid(lport, fchs,
820 (struct fc_rnid_cmd_s *) els_cmd, len);
821 return;
824 if (fchs->type == FC_TYPE_BLS) {
825 if ((fchs->routing == FC_RTG_BASIC_LINK) &&
826 (fchs->cat_info == FC_CAT_ABTS))
827 bfa_fcs_lport_abts_acc(lport, fchs);
828 return;
831 if (fchs->type == FC_TYPE_SERVICES) {
833 * Unhandled FC-GS frames. Send a FC-CT Reject
835 bfa_fcs_lport_send_fcgs_rjt(lport, fchs, CT_RSN_NOT_SUPP,
836 CT_NS_EXP_NOADDITIONAL);
837 return;
841 * look for a matching remote port ID
843 rport = bfa_fcs_lport_get_rport_by_pid(lport, pid);
844 if (rport) {
845 bfa_trc(rport->fcs, fchs->s_id);
846 bfa_trc(rport->fcs, fchs->d_id);
847 bfa_trc(rport->fcs, fchs->type);
849 bfa_fcs_rport_uf_recv(rport, fchs, len);
850 return;
854 * Only handles ELS frames for now.
856 if (fchs->type != FC_TYPE_ELS) {
857 bfa_trc(lport->fcs, fchs->s_id);
858 bfa_trc(lport->fcs, fchs->d_id);
859 /* ignore type FC_TYPE_FC_FSS */
860 if (fchs->type != FC_TYPE_FC_FSS)
861 bfa_sm_fault(lport->fcs, fchs->type);
862 return;
865 bfa_trc(lport->fcs, els_cmd->els_code);
866 if (els_cmd->els_code == FC_ELS_RSCN) {
867 bfa_fcs_lport_scn_process_rscn(lport, fchs, len);
868 return;
871 if (els_cmd->els_code == FC_ELS_LOGO) {
873 * @todo Handle LOGO frames received.
875 return;
878 if (els_cmd->els_code == FC_ELS_PRLI) {
880 * @todo Handle PRLI frames received.
882 return;
886 * Unhandled ELS frames. Send a LS_RJT.
888 bfa_fcs_lport_send_ls_rjt(lport, fchs, FC_LS_RJT_RSN_CMD_NOT_SUPP,
889 FC_LS_RJT_EXP_NO_ADDL_INFO);
894 * PID based Lookup for a R-Port in the Port R-Port Queue
896 struct bfa_fcs_rport_s *
897 bfa_fcs_lport_get_rport_by_pid(struct bfa_fcs_lport_s *port, u32 pid)
899 struct bfa_fcs_rport_s *rport;
900 struct list_head *qe;
902 list_for_each(qe, &port->rport_q) {
903 rport = (struct bfa_fcs_rport_s *) qe;
904 if (rport->pid == pid)
905 return rport;
908 bfa_trc(port->fcs, pid);
909 return NULL;
913 * OLD_PID based Lookup for a R-Port in the Port R-Port Queue
915 struct bfa_fcs_rport_s *
916 bfa_fcs_lport_get_rport_by_old_pid(struct bfa_fcs_lport_s *port, u32 pid)
918 struct bfa_fcs_rport_s *rport;
919 struct list_head *qe;
921 list_for_each(qe, &port->rport_q) {
922 rport = (struct bfa_fcs_rport_s *) qe;
923 if (rport->old_pid == pid)
924 return rport;
927 bfa_trc(port->fcs, pid);
928 return NULL;
932 * PWWN based Lookup for a R-Port in the Port R-Port Queue
934 struct bfa_fcs_rport_s *
935 bfa_fcs_lport_get_rport_by_pwwn(struct bfa_fcs_lport_s *port, wwn_t pwwn)
937 struct bfa_fcs_rport_s *rport;
938 struct list_head *qe;
940 list_for_each(qe, &port->rport_q) {
941 rport = (struct bfa_fcs_rport_s *) qe;
942 if (wwn_is_equal(rport->pwwn, pwwn))
943 return rport;
946 bfa_trc(port->fcs, pwwn);
947 return NULL;
951 * NWWN based Lookup for a R-Port in the Port R-Port Queue
953 struct bfa_fcs_rport_s *
954 bfa_fcs_lport_get_rport_by_nwwn(struct bfa_fcs_lport_s *port, wwn_t nwwn)
956 struct bfa_fcs_rport_s *rport;
957 struct list_head *qe;
959 list_for_each(qe, &port->rport_q) {
960 rport = (struct bfa_fcs_rport_s *) qe;
961 if (wwn_is_equal(rport->nwwn, nwwn))
962 return rport;
965 bfa_trc(port->fcs, nwwn);
966 return NULL;
970 * PWWN & PID based Lookup for a R-Port in the Port R-Port Queue
972 struct bfa_fcs_rport_s *
973 bfa_fcs_lport_get_rport_by_qualifier(struct bfa_fcs_lport_s *port,
974 wwn_t pwwn, u32 pid)
976 struct bfa_fcs_rport_s *rport;
977 struct list_head *qe;
979 list_for_each(qe, &port->rport_q) {
980 rport = (struct bfa_fcs_rport_s *) qe;
981 if (wwn_is_equal(rport->pwwn, pwwn) && rport->pid == pid)
982 return rport;
985 bfa_trc(port->fcs, pwwn);
986 return NULL;
990 * Called by rport module when new rports are discovered.
992 void
993 bfa_fcs_lport_add_rport(
994 struct bfa_fcs_lport_s *port,
995 struct bfa_fcs_rport_s *rport)
997 list_add_tail(&rport->qe, &port->rport_q);
998 port->num_rports++;
1002 * Called by rport module to when rports are deleted.
1004 void
1005 bfa_fcs_lport_del_rport(
1006 struct bfa_fcs_lport_s *port,
1007 struct bfa_fcs_rport_s *rport)
1009 WARN_ON(!bfa_q_is_on_q(&port->rport_q, rport));
1010 list_del(&rport->qe);
1011 port->num_rports--;
1013 bfa_sm_send_event(port, BFA_FCS_PORT_SM_DELRPORT);
1017 * Called by fabric for base port when fabric login is complete.
1018 * Called by vport for virtual ports when FDISC is complete.
1020 void
1021 bfa_fcs_lport_online(struct bfa_fcs_lport_s *port)
1023 bfa_sm_send_event(port, BFA_FCS_PORT_SM_ONLINE);
1027 * Called by fabric for base port when fabric goes offline.
1028 * Called by vport for virtual ports when virtual port becomes offline.
1030 void
1031 bfa_fcs_lport_offline(struct bfa_fcs_lport_s *port)
1033 bfa_sm_send_event(port, BFA_FCS_PORT_SM_OFFLINE);
1037 * Called by fabric for base port and by vport for virtual ports
1038 * when target mode driver is unloaded.
1040 void
1041 bfa_fcs_lport_stop(struct bfa_fcs_lport_s *port)
1043 bfa_sm_send_event(port, BFA_FCS_PORT_SM_STOP);
1047 * Called by fabric to delete base lport and associated resources.
1049 * Called by vport to delete lport and associated resources. Should call
1050 * bfa_fcs_vport_delete_comp() for vports on completion.
1052 void
1053 bfa_fcs_lport_delete(struct bfa_fcs_lport_s *port)
1055 bfa_sm_send_event(port, BFA_FCS_PORT_SM_DELETE);
1059 * Return TRUE if port is online, else return FALSE
1061 bfa_boolean_t
1062 bfa_fcs_lport_is_online(struct bfa_fcs_lport_s *port)
1064 return bfa_sm_cmp_state(port, bfa_fcs_lport_sm_online);
1068 * Attach time initialization of logical ports.
1070 void
1071 bfa_fcs_lport_attach(struct bfa_fcs_lport_s *lport, struct bfa_fcs_s *fcs,
1072 u16 vf_id, struct bfa_fcs_vport_s *vport)
1074 lport->fcs = fcs;
1075 lport->fabric = bfa_fcs_vf_lookup(fcs, vf_id);
1076 lport->vport = vport;
1077 lport->lp_tag = (vport) ? vport->lps->bfa_tag :
1078 lport->fabric->lps->bfa_tag;
1080 INIT_LIST_HEAD(&lport->rport_q);
1081 lport->num_rports = 0;
1085 * Logical port initialization of base or virtual port.
1086 * Called by fabric for base port or by vport for virtual ports.
1089 void
1090 bfa_fcs_lport_init(struct bfa_fcs_lport_s *lport,
1091 struct bfa_lport_cfg_s *port_cfg)
1093 struct bfa_fcs_vport_s *vport = lport->vport;
1094 struct bfad_s *bfad = (struct bfad_s *)lport->fcs->bfad;
1095 char lpwwn_buf[BFA_STRING_32];
1097 lport->port_cfg = *port_cfg;
1099 lport->bfad_port = bfa_fcb_lport_new(lport->fcs->bfad, lport,
1100 lport->port_cfg.roles,
1101 lport->fabric->vf_drv,
1102 vport ? vport->vport_drv : NULL);
1104 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(lport));
1105 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
1106 "New logical port created: WWN = %s Role = %s\n",
1107 lpwwn_buf, "Initiator");
1108 bfa_fcs_lport_aen_post(lport, BFA_LPORT_AEN_NEW);
1110 bfa_sm_set_state(lport, bfa_fcs_lport_sm_uninit);
1111 bfa_sm_send_event(lport, BFA_FCS_PORT_SM_CREATE);
1114 void
1115 bfa_fcs_lport_set_symname(struct bfa_fcs_lport_s *port,
1116 char *symname)
1118 strcpy(port->port_cfg.sym_name.symname, symname);
1120 if (bfa_sm_cmp_state(port, bfa_fcs_lport_sm_online))
1121 bfa_fcs_lport_ns_util_send_rspn_id(
1122 BFA_FCS_GET_NS_FROM_PORT(port), NULL);
1126 * fcs_lport_api
1129 void
1130 bfa_fcs_lport_get_attr(
1131 struct bfa_fcs_lport_s *port,
1132 struct bfa_lport_attr_s *port_attr)
1134 if (bfa_sm_cmp_state(port, bfa_fcs_lport_sm_online))
1135 port_attr->pid = port->pid;
1136 else
1137 port_attr->pid = 0;
1139 port_attr->port_cfg = port->port_cfg;
1141 if (port->fabric) {
1142 port_attr->port_type = port->fabric->oper_type;
1143 port_attr->loopback = bfa_sm_cmp_state(port->fabric,
1144 bfa_fcs_fabric_sm_loopback);
1145 port_attr->authfail =
1146 bfa_sm_cmp_state(port->fabric,
1147 bfa_fcs_fabric_sm_auth_failed);
1148 port_attr->fabric_name = bfa_fcs_lport_get_fabric_name(port);
1149 memcpy(port_attr->fabric_ip_addr,
1150 bfa_fcs_lport_get_fabric_ipaddr(port),
1151 BFA_FCS_FABRIC_IPADDR_SZ);
1153 if (port->vport != NULL) {
1154 port_attr->port_type = BFA_PORT_TYPE_VPORT;
1155 port_attr->fpma_mac =
1156 port->vport->lps->lp_mac;
1157 } else {
1158 port_attr->fpma_mac =
1159 port->fabric->lps->lp_mac;
1161 } else {
1162 port_attr->port_type = BFA_PORT_TYPE_UNKNOWN;
1163 port_attr->state = BFA_LPORT_UNINIT;
1168 * bfa_fcs_lport_fab port fab functions
1172 * Called by port to initialize fabric services of the base port.
1174 static void
1175 bfa_fcs_lport_fab_init(struct bfa_fcs_lport_s *port)
1177 bfa_fcs_lport_ns_init(port);
1178 bfa_fcs_lport_scn_init(port);
1179 bfa_fcs_lport_ms_init(port);
1183 * Called by port to notify transition to online state.
1185 static void
1186 bfa_fcs_lport_fab_online(struct bfa_fcs_lport_s *port)
1188 bfa_fcs_lport_ns_online(port);
1189 bfa_fcs_lport_fab_scn_online(port);
1193 * Called by port to notify transition to offline state.
1195 static void
1196 bfa_fcs_lport_fab_offline(struct bfa_fcs_lport_s *port)
1198 bfa_fcs_lport_ns_offline(port);
1199 bfa_fcs_lport_scn_offline(port);
1200 bfa_fcs_lport_ms_offline(port);
1204 * bfa_fcs_lport_n2n functions
1208 * Called by fcs/port to initialize N2N topology.
1210 static void
1211 bfa_fcs_lport_n2n_init(struct bfa_fcs_lport_s *port)
1216 * Called by fcs/port to notify transition to online state.
1218 static void
1219 bfa_fcs_lport_n2n_online(struct bfa_fcs_lport_s *port)
1221 struct bfa_fcs_lport_n2n_s *n2n_port = &port->port_topo.pn2n;
1222 struct bfa_lport_cfg_s *pcfg = &port->port_cfg;
1223 struct bfa_fcs_rport_s *rport;
1225 bfa_trc(port->fcs, pcfg->pwwn);
1228 * If our PWWN is > than that of the r-port, we have to initiate PLOGI
1229 * and assign an Address. if not, we need to wait for its PLOGI.
1231 * If our PWWN is < than that of the remote port, it will send a PLOGI
1232 * with the PIDs assigned. The rport state machine take care of this
1233 * incoming PLOGI.
1235 if (memcmp
1236 ((void *)&pcfg->pwwn, (void *)&n2n_port->rem_port_wwn,
1237 sizeof(wwn_t)) > 0) {
1238 port->pid = N2N_LOCAL_PID;
1239 bfa_lps_set_n2n_pid(port->fabric->lps, N2N_LOCAL_PID);
1241 * First, check if we know the device by pwwn.
1243 rport = bfa_fcs_lport_get_rport_by_pwwn(port,
1244 n2n_port->rem_port_wwn);
1245 if (rport) {
1246 bfa_trc(port->fcs, rport->pid);
1247 bfa_trc(port->fcs, rport->pwwn);
1248 rport->pid = N2N_REMOTE_PID;
1249 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_SEND);
1250 return;
1254 * In n2n there can be only one rport. Delete the old one
1255 * whose pid should be zero, because it is offline.
1257 if (port->num_rports > 0) {
1258 rport = bfa_fcs_lport_get_rport_by_pid(port, 0);
1259 WARN_ON(rport == NULL);
1260 if (rport) {
1261 bfa_trc(port->fcs, rport->pwwn);
1262 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
1265 bfa_fcs_rport_create(port, N2N_REMOTE_PID);
1270 * Called by fcs/port to notify transition to offline state.
1272 static void
1273 bfa_fcs_lport_n2n_offline(struct bfa_fcs_lport_s *port)
1275 struct bfa_fcs_lport_n2n_s *n2n_port = &port->port_topo.pn2n;
1277 bfa_trc(port->fcs, port->pid);
1278 port->pid = 0;
1279 n2n_port->rem_port_wwn = 0;
1280 n2n_port->reply_oxid = 0;
1283 void
1284 bfa_fcport_get_loop_attr(struct bfa_fcs_lport_s *port)
1286 int i = 0, j = 0, bit = 0, alpa_bit = 0;
1287 u8 k = 0;
1288 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(port->fcs->bfa);
1290 port->port_topo.ploop.alpabm_valid = fcport->alpabm_valid;
1291 port->pid = fcport->myalpa;
1292 port->pid = bfa_hton3b(port->pid);
1294 for (i = 0; i < (FC_ALPA_MAX / 8); i++) {
1295 for (j = 0, alpa_bit = 0; j < 8; j++, alpa_bit++) {
1296 bfa_trc(port->fcs->bfa, fcport->alpabm.alpa_bm[i]);
1297 bit = (fcport->alpabm.alpa_bm[i] & (1 << (7 - j)));
1298 if (bit) {
1299 port->port_topo.ploop.alpa_pos_map[k] =
1300 loop_alpa_map[(i * 8) + alpa_bit];
1301 k++;
1302 bfa_trc(port->fcs->bfa, k);
1303 bfa_trc(port->fcs->bfa,
1304 port->port_topo.ploop.alpa_pos_map[k]);
1308 port->port_topo.ploop.num_alpa = k;
1312 * Called by fcs/port to initialize Loop topology.
1314 static void
1315 bfa_fcs_lport_loop_init(struct bfa_fcs_lport_s *port)
1320 * Called by fcs/port to notify transition to online state.
1322 static void
1323 bfa_fcs_lport_loop_online(struct bfa_fcs_lport_s *port)
1325 u8 num_alpa = 0, alpabm_valid = 0;
1326 struct bfa_fcs_rport_s *rport;
1327 u8 *alpa_map = NULL;
1328 int i = 0;
1329 u32 pid;
1331 bfa_fcport_get_loop_attr(port);
1333 num_alpa = port->port_topo.ploop.num_alpa;
1334 alpabm_valid = port->port_topo.ploop.alpabm_valid;
1335 alpa_map = port->port_topo.ploop.alpa_pos_map;
1337 bfa_trc(port->fcs->bfa, port->pid);
1338 bfa_trc(port->fcs->bfa, num_alpa);
1339 if (alpabm_valid == 1) {
1340 for (i = 0; i < num_alpa; i++) {
1341 bfa_trc(port->fcs->bfa, alpa_map[i]);
1342 if (alpa_map[i] != bfa_hton3b(port->pid)) {
1343 pid = alpa_map[i];
1344 bfa_trc(port->fcs->bfa, pid);
1345 rport = bfa_fcs_lport_get_rport_by_pid(port,
1346 bfa_hton3b(pid));
1347 if (!rport)
1348 rport = bfa_fcs_rport_create(port,
1349 bfa_hton3b(pid));
1352 } else {
1353 for (i = 0; i < MAX_ALPA_COUNT; i++) {
1354 if (alpa_map[i] != port->pid) {
1355 pid = loop_alpa_map[i];
1356 bfa_trc(port->fcs->bfa, pid);
1357 rport = bfa_fcs_lport_get_rport_by_pid(port,
1358 bfa_hton3b(pid));
1359 if (!rport)
1360 rport = bfa_fcs_rport_create(port,
1361 bfa_hton3b(pid));
1368 * Called by fcs/port to notify transition to offline state.
1370 static void
1371 bfa_fcs_lport_loop_offline(struct bfa_fcs_lport_s *port)
1375 #define BFA_FCS_FDMI_CMD_MAX_RETRIES 2
1378 * forward declarations
1380 static void bfa_fcs_lport_fdmi_send_rhba(void *fdmi_cbarg,
1381 struct bfa_fcxp_s *fcxp_alloced);
1382 static void bfa_fcs_lport_fdmi_send_rprt(void *fdmi_cbarg,
1383 struct bfa_fcxp_s *fcxp_alloced);
1384 static void bfa_fcs_lport_fdmi_send_rpa(void *fdmi_cbarg,
1385 struct bfa_fcxp_s *fcxp_alloced);
1386 static void bfa_fcs_lport_fdmi_rhba_response(void *fcsarg,
1387 struct bfa_fcxp_s *fcxp,
1388 void *cbarg,
1389 bfa_status_t req_status,
1390 u32 rsp_len,
1391 u32 resid_len,
1392 struct fchs_s *rsp_fchs);
1393 static void bfa_fcs_lport_fdmi_rprt_response(void *fcsarg,
1394 struct bfa_fcxp_s *fcxp,
1395 void *cbarg,
1396 bfa_status_t req_status,
1397 u32 rsp_len,
1398 u32 resid_len,
1399 struct fchs_s *rsp_fchs);
1400 static void bfa_fcs_lport_fdmi_rpa_response(void *fcsarg,
1401 struct bfa_fcxp_s *fcxp,
1402 void *cbarg,
1403 bfa_status_t req_status,
1404 u32 rsp_len,
1405 u32 resid_len,
1406 struct fchs_s *rsp_fchs);
1407 static void bfa_fcs_lport_fdmi_timeout(void *arg);
1408 static u16 bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s *fdmi,
1409 u8 *pyld);
1410 static u16 bfa_fcs_lport_fdmi_build_rprt_pyld(struct bfa_fcs_lport_fdmi_s *fdmi,
1411 u8 *pyld);
1412 static u16 bfa_fcs_lport_fdmi_build_rpa_pyld(struct bfa_fcs_lport_fdmi_s *fdmi,
1413 u8 *pyld);
1414 static u16 bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s *
1415 fdmi, u8 *pyld);
1416 static void bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s *fdmi,
1417 struct bfa_fcs_fdmi_hba_attr_s *hba_attr);
1418 static void bfa_fcs_fdmi_get_portattr(struct bfa_fcs_lport_fdmi_s *fdmi,
1419 struct bfa_fcs_fdmi_port_attr_s *port_attr);
1420 u32 bfa_fcs_fdmi_convert_speed(enum bfa_port_speed pport_speed);
1423 * fcs_fdmi_sm FCS FDMI state machine
1427 * FDMI State Machine events
1429 enum port_fdmi_event {
1430 FDMISM_EVENT_PORT_ONLINE = 1,
1431 FDMISM_EVENT_PORT_OFFLINE = 2,
1432 FDMISM_EVENT_RSP_OK = 4,
1433 FDMISM_EVENT_RSP_ERROR = 5,
1434 FDMISM_EVENT_TIMEOUT = 6,
1435 FDMISM_EVENT_RHBA_SENT = 7,
1436 FDMISM_EVENT_RPRT_SENT = 8,
1437 FDMISM_EVENT_RPA_SENT = 9,
1440 static void bfa_fcs_lport_fdmi_sm_offline(struct bfa_fcs_lport_fdmi_s *fdmi,
1441 enum port_fdmi_event event);
1442 static void bfa_fcs_lport_fdmi_sm_sending_rhba(
1443 struct bfa_fcs_lport_fdmi_s *fdmi,
1444 enum port_fdmi_event event);
1445 static void bfa_fcs_lport_fdmi_sm_rhba(struct bfa_fcs_lport_fdmi_s *fdmi,
1446 enum port_fdmi_event event);
1447 static void bfa_fcs_lport_fdmi_sm_rhba_retry(
1448 struct bfa_fcs_lport_fdmi_s *fdmi,
1449 enum port_fdmi_event event);
1450 static void bfa_fcs_lport_fdmi_sm_sending_rprt(
1451 struct bfa_fcs_lport_fdmi_s *fdmi,
1452 enum port_fdmi_event event);
1453 static void bfa_fcs_lport_fdmi_sm_rprt(struct bfa_fcs_lport_fdmi_s *fdmi,
1454 enum port_fdmi_event event);
1455 static void bfa_fcs_lport_fdmi_sm_rprt_retry(
1456 struct bfa_fcs_lport_fdmi_s *fdmi,
1457 enum port_fdmi_event event);
1458 static void bfa_fcs_lport_fdmi_sm_sending_rpa(
1459 struct bfa_fcs_lport_fdmi_s *fdmi,
1460 enum port_fdmi_event event);
1461 static void bfa_fcs_lport_fdmi_sm_rpa(struct bfa_fcs_lport_fdmi_s *fdmi,
1462 enum port_fdmi_event event);
1463 static void bfa_fcs_lport_fdmi_sm_rpa_retry(
1464 struct bfa_fcs_lport_fdmi_s *fdmi,
1465 enum port_fdmi_event event);
1466 static void bfa_fcs_lport_fdmi_sm_online(struct bfa_fcs_lport_fdmi_s *fdmi,
1467 enum port_fdmi_event event);
1468 static void bfa_fcs_lport_fdmi_sm_disabled(
1469 struct bfa_fcs_lport_fdmi_s *fdmi,
1470 enum port_fdmi_event event);
1472 * Start in offline state - awaiting MS to send start.
1474 static void
1475 bfa_fcs_lport_fdmi_sm_offline(struct bfa_fcs_lport_fdmi_s *fdmi,
1476 enum port_fdmi_event event)
1478 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1480 bfa_trc(port->fcs, port->port_cfg.pwwn);
1481 bfa_trc(port->fcs, event);
1483 fdmi->retry_cnt = 0;
1485 switch (event) {
1486 case FDMISM_EVENT_PORT_ONLINE:
1487 if (port->vport) {
1489 * For Vports, register a new port.
1491 bfa_sm_set_state(fdmi,
1492 bfa_fcs_lport_fdmi_sm_sending_rprt);
1493 bfa_fcs_lport_fdmi_send_rprt(fdmi, NULL);
1494 } else {
1496 * For a base port, we should first register the HBA
1497 * attribute. The HBA attribute also contains the base
1498 * port registration.
1500 bfa_sm_set_state(fdmi,
1501 bfa_fcs_lport_fdmi_sm_sending_rhba);
1502 bfa_fcs_lport_fdmi_send_rhba(fdmi, NULL);
1504 break;
1506 case FDMISM_EVENT_PORT_OFFLINE:
1507 break;
1509 default:
1510 bfa_sm_fault(port->fcs, event);
1514 static void
1515 bfa_fcs_lport_fdmi_sm_sending_rhba(struct bfa_fcs_lport_fdmi_s *fdmi,
1516 enum port_fdmi_event event)
1518 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1520 bfa_trc(port->fcs, port->port_cfg.pwwn);
1521 bfa_trc(port->fcs, event);
1523 switch (event) {
1524 case FDMISM_EVENT_RHBA_SENT:
1525 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rhba);
1526 break;
1528 case FDMISM_EVENT_PORT_OFFLINE:
1529 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1530 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
1531 &fdmi->fcxp_wqe);
1532 break;
1534 default:
1535 bfa_sm_fault(port->fcs, event);
1539 static void
1540 bfa_fcs_lport_fdmi_sm_rhba(struct bfa_fcs_lport_fdmi_s *fdmi,
1541 enum port_fdmi_event event)
1543 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1545 bfa_trc(port->fcs, port->port_cfg.pwwn);
1546 bfa_trc(port->fcs, event);
1548 switch (event) {
1549 case FDMISM_EVENT_RSP_ERROR:
1551 * if max retries have not been reached, start timer for a
1552 * delayed retry
1554 if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
1555 bfa_sm_set_state(fdmi,
1556 bfa_fcs_lport_fdmi_sm_rhba_retry);
1557 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
1558 &fdmi->timer,
1559 bfa_fcs_lport_fdmi_timeout, fdmi,
1560 BFA_FCS_RETRY_TIMEOUT);
1561 } else {
1563 * set state to offline
1565 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1567 break;
1569 case FDMISM_EVENT_RSP_OK:
1571 * Initiate Register Port Attributes
1573 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rpa);
1574 fdmi->retry_cnt = 0;
1575 bfa_fcs_lport_fdmi_send_rpa(fdmi, NULL);
1576 break;
1578 case FDMISM_EVENT_PORT_OFFLINE:
1579 bfa_fcxp_discard(fdmi->fcxp);
1580 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1581 break;
1583 default:
1584 bfa_sm_fault(port->fcs, event);
1588 static void
1589 bfa_fcs_lport_fdmi_sm_rhba_retry(struct bfa_fcs_lport_fdmi_s *fdmi,
1590 enum port_fdmi_event event)
1592 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1594 bfa_trc(port->fcs, port->port_cfg.pwwn);
1595 bfa_trc(port->fcs, event);
1597 switch (event) {
1598 case FDMISM_EVENT_TIMEOUT:
1600 * Retry Timer Expired. Re-send
1602 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rhba);
1603 bfa_fcs_lport_fdmi_send_rhba(fdmi, NULL);
1604 break;
1606 case FDMISM_EVENT_PORT_OFFLINE:
1607 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1608 bfa_timer_stop(&fdmi->timer);
1609 break;
1611 default:
1612 bfa_sm_fault(port->fcs, event);
1617 * RPRT : Register Port
1619 static void
1620 bfa_fcs_lport_fdmi_sm_sending_rprt(struct bfa_fcs_lport_fdmi_s *fdmi,
1621 enum port_fdmi_event event)
1623 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1625 bfa_trc(port->fcs, port->port_cfg.pwwn);
1626 bfa_trc(port->fcs, event);
1628 switch (event) {
1629 case FDMISM_EVENT_RPRT_SENT:
1630 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rprt);
1631 break;
1633 case FDMISM_EVENT_PORT_OFFLINE:
1634 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1635 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
1636 &fdmi->fcxp_wqe);
1637 break;
1639 default:
1640 bfa_sm_fault(port->fcs, event);
1644 static void
1645 bfa_fcs_lport_fdmi_sm_rprt(struct bfa_fcs_lport_fdmi_s *fdmi,
1646 enum port_fdmi_event event)
1648 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1650 bfa_trc(port->fcs, port->port_cfg.pwwn);
1651 bfa_trc(port->fcs, event);
1653 switch (event) {
1654 case FDMISM_EVENT_RSP_ERROR:
1656 * if max retries have not been reached, start timer for a
1657 * delayed retry
1659 if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
1660 bfa_sm_set_state(fdmi,
1661 bfa_fcs_lport_fdmi_sm_rprt_retry);
1662 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
1663 &fdmi->timer,
1664 bfa_fcs_lport_fdmi_timeout, fdmi,
1665 BFA_FCS_RETRY_TIMEOUT);
1667 } else {
1669 * set state to offline
1671 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1672 fdmi->retry_cnt = 0;
1674 break;
1676 case FDMISM_EVENT_RSP_OK:
1677 fdmi->retry_cnt = 0;
1678 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_online);
1679 break;
1681 case FDMISM_EVENT_PORT_OFFLINE:
1682 bfa_fcxp_discard(fdmi->fcxp);
1683 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1684 break;
1686 default:
1687 bfa_sm_fault(port->fcs, event);
1691 static void
1692 bfa_fcs_lport_fdmi_sm_rprt_retry(struct bfa_fcs_lport_fdmi_s *fdmi,
1693 enum port_fdmi_event event)
1695 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1697 bfa_trc(port->fcs, port->port_cfg.pwwn);
1698 bfa_trc(port->fcs, event);
1700 switch (event) {
1701 case FDMISM_EVENT_TIMEOUT:
1703 * Retry Timer Expired. Re-send
1705 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rprt);
1706 bfa_fcs_lport_fdmi_send_rprt(fdmi, NULL);
1707 break;
1709 case FDMISM_EVENT_PORT_OFFLINE:
1710 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1711 bfa_timer_stop(&fdmi->timer);
1712 break;
1714 default:
1715 bfa_sm_fault(port->fcs, event);
1720 * Register Port Attributes
1722 static void
1723 bfa_fcs_lport_fdmi_sm_sending_rpa(struct bfa_fcs_lport_fdmi_s *fdmi,
1724 enum port_fdmi_event event)
1726 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1728 bfa_trc(port->fcs, port->port_cfg.pwwn);
1729 bfa_trc(port->fcs, event);
1731 switch (event) {
1732 case FDMISM_EVENT_RPA_SENT:
1733 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rpa);
1734 break;
1736 case FDMISM_EVENT_PORT_OFFLINE:
1737 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1738 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
1739 &fdmi->fcxp_wqe);
1740 break;
1742 default:
1743 bfa_sm_fault(port->fcs, event);
1747 static void
1748 bfa_fcs_lport_fdmi_sm_rpa(struct bfa_fcs_lport_fdmi_s *fdmi,
1749 enum port_fdmi_event event)
1751 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1753 bfa_trc(port->fcs, port->port_cfg.pwwn);
1754 bfa_trc(port->fcs, event);
1756 switch (event) {
1757 case FDMISM_EVENT_RSP_ERROR:
1759 * if max retries have not been reached, start timer for a
1760 * delayed retry
1762 if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
1763 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rpa_retry);
1764 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
1765 &fdmi->timer,
1766 bfa_fcs_lport_fdmi_timeout, fdmi,
1767 BFA_FCS_RETRY_TIMEOUT);
1768 } else {
1770 * set state to offline
1772 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1773 fdmi->retry_cnt = 0;
1775 break;
1777 case FDMISM_EVENT_RSP_OK:
1778 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_online);
1779 fdmi->retry_cnt = 0;
1780 break;
1782 case FDMISM_EVENT_PORT_OFFLINE:
1783 bfa_fcxp_discard(fdmi->fcxp);
1784 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1785 break;
1787 default:
1788 bfa_sm_fault(port->fcs, event);
1792 static void
1793 bfa_fcs_lport_fdmi_sm_rpa_retry(struct bfa_fcs_lport_fdmi_s *fdmi,
1794 enum port_fdmi_event event)
1796 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1798 bfa_trc(port->fcs, port->port_cfg.pwwn);
1799 bfa_trc(port->fcs, event);
1801 switch (event) {
1802 case FDMISM_EVENT_TIMEOUT:
1804 * Retry Timer Expired. Re-send
1806 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rpa);
1807 bfa_fcs_lport_fdmi_send_rpa(fdmi, NULL);
1808 break;
1810 case FDMISM_EVENT_PORT_OFFLINE:
1811 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1812 bfa_timer_stop(&fdmi->timer);
1813 break;
1815 default:
1816 bfa_sm_fault(port->fcs, event);
1820 static void
1821 bfa_fcs_lport_fdmi_sm_online(struct bfa_fcs_lport_fdmi_s *fdmi,
1822 enum port_fdmi_event event)
1824 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1826 bfa_trc(port->fcs, port->port_cfg.pwwn);
1827 bfa_trc(port->fcs, event);
1829 switch (event) {
1830 case FDMISM_EVENT_PORT_OFFLINE:
1831 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1832 break;
1834 default:
1835 bfa_sm_fault(port->fcs, event);
1839 * FDMI is disabled state.
1841 static void
1842 bfa_fcs_lport_fdmi_sm_disabled(struct bfa_fcs_lport_fdmi_s *fdmi,
1843 enum port_fdmi_event event)
1845 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1847 bfa_trc(port->fcs, port->port_cfg.pwwn);
1848 bfa_trc(port->fcs, event);
1850 /* No op State. It can only be enabled at Driver Init. */
1854 * RHBA : Register HBA Attributes.
1856 static void
1857 bfa_fcs_lport_fdmi_send_rhba(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1859 struct bfa_fcs_lport_fdmi_s *fdmi = fdmi_cbarg;
1860 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1861 struct fchs_s fchs;
1862 int len, attr_len;
1863 struct bfa_fcxp_s *fcxp;
1864 u8 *pyld;
1866 bfa_trc(port->fcs, port->port_cfg.pwwn);
1868 fcxp = fcxp_alloced ? fcxp_alloced :
1869 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
1870 if (!fcxp) {
1871 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
1872 bfa_fcs_lport_fdmi_send_rhba, fdmi, BFA_TRUE);
1873 return;
1875 fdmi->fcxp = fcxp;
1877 pyld = bfa_fcxp_get_reqbuf(fcxp);
1878 memset(pyld, 0, FC_MAX_PDUSZ);
1880 len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
1881 FDMI_RHBA);
1883 attr_len =
1884 bfa_fcs_lport_fdmi_build_rhba_pyld(fdmi,
1885 (u8 *) ((struct ct_hdr_s *) pyld
1886 + 1));
1888 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1889 FC_CLASS_3, (len + attr_len), &fchs,
1890 bfa_fcs_lport_fdmi_rhba_response, (void *)fdmi,
1891 FC_MAX_PDUSZ, FC_FCCT_TOV);
1893 bfa_sm_send_event(fdmi, FDMISM_EVENT_RHBA_SENT);
1896 static u16
1897 bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
1899 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1900 struct bfa_fcs_fdmi_hba_attr_s hba_attr;
1901 struct bfa_fcs_fdmi_hba_attr_s *fcs_hba_attr = &hba_attr;
1902 struct fdmi_rhba_s *rhba = (struct fdmi_rhba_s *) pyld;
1903 struct fdmi_attr_s *attr;
1904 u8 *curr_ptr;
1905 u16 len, count;
1906 u16 templen;
1909 * get hba attributes
1911 bfa_fcs_fdmi_get_hbaattr(fdmi, fcs_hba_attr);
1913 rhba->hba_id = bfa_fcs_lport_get_pwwn(port);
1914 rhba->port_list.num_ports = cpu_to_be32(1);
1915 rhba->port_list.port_entry = bfa_fcs_lport_get_pwwn(port);
1917 len = sizeof(rhba->hba_id) + sizeof(rhba->port_list);
1919 count = 0;
1920 len += sizeof(rhba->hba_attr_blk.attr_count);
1923 * fill out the invididual entries of the HBA attrib Block
1925 curr_ptr = (u8 *) &rhba->hba_attr_blk.hba_attr;
1928 * Node Name
1930 attr = (struct fdmi_attr_s *) curr_ptr;
1931 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_NODENAME);
1932 templen = sizeof(wwn_t);
1933 memcpy(attr->value, &bfa_fcs_lport_get_nwwn(port), templen);
1934 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1935 len += templen;
1936 count++;
1937 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1938 sizeof(templen));
1941 * Manufacturer
1943 attr = (struct fdmi_attr_s *) curr_ptr;
1944 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MANUFACTURER);
1945 templen = (u16) strlen(fcs_hba_attr->manufacturer);
1946 memcpy(attr->value, fcs_hba_attr->manufacturer, templen);
1947 templen = fc_roundup(templen, sizeof(u32));
1948 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1949 len += templen;
1950 count++;
1951 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1952 sizeof(templen));
1955 * Serial Number
1957 attr = (struct fdmi_attr_s *) curr_ptr;
1958 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_SERIALNUM);
1959 templen = (u16) strlen(fcs_hba_attr->serial_num);
1960 memcpy(attr->value, fcs_hba_attr->serial_num, templen);
1961 templen = fc_roundup(templen, sizeof(u32));
1962 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1963 len += templen;
1964 count++;
1965 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1966 sizeof(templen));
1969 * Model
1971 attr = (struct fdmi_attr_s *) curr_ptr;
1972 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MODEL);
1973 templen = (u16) strlen(fcs_hba_attr->model);
1974 memcpy(attr->value, fcs_hba_attr->model, templen);
1975 templen = fc_roundup(templen, sizeof(u32));
1976 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1977 len += templen;
1978 count++;
1979 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1980 sizeof(templen));
1983 * Model Desc
1985 attr = (struct fdmi_attr_s *) curr_ptr;
1986 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MODEL_DESC);
1987 templen = (u16) strlen(fcs_hba_attr->model_desc);
1988 memcpy(attr->value, fcs_hba_attr->model_desc, templen);
1989 templen = fc_roundup(templen, sizeof(u32));
1990 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1991 len += templen;
1992 count++;
1993 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1994 sizeof(templen));
1997 * H/W Version
1999 if (fcs_hba_attr->hw_version[0] != '\0') {
2000 attr = (struct fdmi_attr_s *) curr_ptr;
2001 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_HW_VERSION);
2002 templen = (u16) strlen(fcs_hba_attr->hw_version);
2003 memcpy(attr->value, fcs_hba_attr->hw_version, templen);
2004 templen = fc_roundup(templen, sizeof(u32));
2005 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2006 len += templen;
2007 count++;
2008 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2009 sizeof(templen));
2013 * Driver Version
2015 attr = (struct fdmi_attr_s *) curr_ptr;
2016 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_DRIVER_VERSION);
2017 templen = (u16) strlen(fcs_hba_attr->driver_version);
2018 memcpy(attr->value, fcs_hba_attr->driver_version, templen);
2019 templen = fc_roundup(templen, sizeof(u32));
2020 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2021 len += templen;
2022 count++;
2023 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2024 sizeof(templen));
2027 * Option Rom Version
2029 if (fcs_hba_attr->option_rom_ver[0] != '\0') {
2030 attr = (struct fdmi_attr_s *) curr_ptr;
2031 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_ROM_VERSION);
2032 templen = (u16) strlen(fcs_hba_attr->option_rom_ver);
2033 memcpy(attr->value, fcs_hba_attr->option_rom_ver, templen);
2034 templen = fc_roundup(templen, sizeof(u32));
2035 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2036 len += templen;
2037 count++;
2038 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2039 sizeof(templen));
2042 attr = (struct fdmi_attr_s *) curr_ptr;
2043 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_FW_VERSION);
2044 templen = (u16) strlen(fcs_hba_attr->fw_version);
2045 memcpy(attr->value, fcs_hba_attr->fw_version, templen);
2046 templen = fc_roundup(templen, sizeof(u32));
2047 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2048 len += templen;
2049 count++;
2050 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2051 sizeof(templen));
2054 * OS Name
2056 if (fcs_hba_attr->os_name[0] != '\0') {
2057 attr = (struct fdmi_attr_s *) curr_ptr;
2058 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_OS_NAME);
2059 templen = (u16) strlen(fcs_hba_attr->os_name);
2060 memcpy(attr->value, fcs_hba_attr->os_name, templen);
2061 templen = fc_roundup(templen, sizeof(u32));
2062 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2063 len += templen;
2064 count++;
2065 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2066 sizeof(templen));
2070 * MAX_CT_PAYLOAD
2072 attr = (struct fdmi_attr_s *) curr_ptr;
2073 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MAX_CT);
2074 templen = sizeof(fcs_hba_attr->max_ct_pyld);
2075 memcpy(attr->value, &fcs_hba_attr->max_ct_pyld, templen);
2076 templen = fc_roundup(templen, sizeof(u32));
2077 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2078 len += templen;
2079 count++;
2080 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2081 sizeof(templen));
2083 * Send extended attributes ( FOS 7.1 support )
2085 if (fdmi->retry_cnt == 0) {
2086 attr = (struct fdmi_attr_s *) curr_ptr;
2087 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_NODE_SYM_NAME);
2088 templen = sizeof(fcs_hba_attr->node_sym_name);
2089 memcpy(attr->value, &fcs_hba_attr->node_sym_name, templen);
2090 templen = fc_roundup(templen, sizeof(u32));
2091 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2092 len += templen;
2093 count++;
2094 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2095 sizeof(templen));
2097 attr = (struct fdmi_attr_s *) curr_ptr;
2098 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_VENDOR_ID);
2099 templen = sizeof(fcs_hba_attr->vendor_info);
2100 memcpy(attr->value, &fcs_hba_attr->vendor_info, templen);
2101 templen = fc_roundup(templen, sizeof(u32));
2102 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2103 len += templen;
2104 count++;
2105 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2106 sizeof(templen));
2108 attr = (struct fdmi_attr_s *) curr_ptr;
2109 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_NUM_PORTS);
2110 templen = sizeof(fcs_hba_attr->num_ports);
2111 memcpy(attr->value, &fcs_hba_attr->num_ports, templen);
2112 templen = fc_roundup(templen, sizeof(u32));
2113 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2114 len += templen;
2115 count++;
2116 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2117 sizeof(templen));
2119 attr = (struct fdmi_attr_s *) curr_ptr;
2120 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_FABRIC_NAME);
2121 templen = sizeof(fcs_hba_attr->fabric_name);
2122 memcpy(attr->value, &fcs_hba_attr->fabric_name, templen);
2123 templen = fc_roundup(templen, sizeof(u32));
2124 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2125 len += templen;
2126 count++;
2127 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2128 sizeof(templen));
2130 attr = (struct fdmi_attr_s *) curr_ptr;
2131 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_BIOS_VER);
2132 templen = sizeof(fcs_hba_attr->bios_ver);
2133 memcpy(attr->value, &fcs_hba_attr->bios_ver, templen);
2134 templen = fc_roundup(attr->len, sizeof(u32));
2135 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2136 len += templen;
2137 count++;
2138 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2139 sizeof(templen));
2143 * Update size of payload
2145 len += ((sizeof(attr->type) + sizeof(attr->len)) * count);
2147 rhba->hba_attr_blk.attr_count = cpu_to_be32(count);
2148 return len;
2151 static void
2152 bfa_fcs_lport_fdmi_rhba_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
2153 void *cbarg, bfa_status_t req_status,
2154 u32 rsp_len, u32 resid_len,
2155 struct fchs_s *rsp_fchs)
2157 struct bfa_fcs_lport_fdmi_s *fdmi =
2158 (struct bfa_fcs_lport_fdmi_s *) cbarg;
2159 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2160 struct ct_hdr_s *cthdr = NULL;
2162 bfa_trc(port->fcs, port->port_cfg.pwwn);
2165 * Sanity Checks
2167 if (req_status != BFA_STATUS_OK) {
2168 bfa_trc(port->fcs, req_status);
2169 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2170 return;
2173 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
2174 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
2176 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
2177 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
2178 return;
2181 bfa_trc(port->fcs, cthdr->reason_code);
2182 bfa_trc(port->fcs, cthdr->exp_code);
2183 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2187 * RPRT : Register Port
2189 static void
2190 bfa_fcs_lport_fdmi_send_rprt(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
2192 struct bfa_fcs_lport_fdmi_s *fdmi = fdmi_cbarg;
2193 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2194 struct fchs_s fchs;
2195 u16 len, attr_len;
2196 struct bfa_fcxp_s *fcxp;
2197 u8 *pyld;
2199 bfa_trc(port->fcs, port->port_cfg.pwwn);
2201 fcxp = fcxp_alloced ? fcxp_alloced :
2202 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
2203 if (!fcxp) {
2204 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
2205 bfa_fcs_lport_fdmi_send_rprt, fdmi, BFA_TRUE);
2206 return;
2208 fdmi->fcxp = fcxp;
2210 pyld = bfa_fcxp_get_reqbuf(fcxp);
2211 memset(pyld, 0, FC_MAX_PDUSZ);
2213 len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
2214 FDMI_RPRT);
2216 attr_len =
2217 bfa_fcs_lport_fdmi_build_rprt_pyld(fdmi,
2218 (u8 *) ((struct ct_hdr_s *) pyld
2219 + 1));
2221 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
2222 FC_CLASS_3, len + attr_len, &fchs,
2223 bfa_fcs_lport_fdmi_rprt_response, (void *)fdmi,
2224 FC_MAX_PDUSZ, FC_FCCT_TOV);
2226 bfa_sm_send_event(fdmi, FDMISM_EVENT_RPRT_SENT);
2230 * This routine builds Port Attribute Block that used in RPA, RPRT commands.
2232 static u16
2233 bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s *fdmi,
2234 u8 *pyld)
2236 struct bfa_fcs_fdmi_port_attr_s fcs_port_attr;
2237 struct fdmi_port_attr_s *port_attrib = (struct fdmi_port_attr_s *) pyld;
2238 struct fdmi_attr_s *attr;
2239 u8 *curr_ptr;
2240 u16 len;
2241 u8 count = 0;
2242 u16 templen;
2245 * get port attributes
2247 bfa_fcs_fdmi_get_portattr(fdmi, &fcs_port_attr);
2249 len = sizeof(port_attrib->attr_count);
2252 * fill out the invididual entries
2254 curr_ptr = (u8 *) &port_attrib->port_attr;
2257 * FC4 Types
2259 attr = (struct fdmi_attr_s *) curr_ptr;
2260 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_FC4_TYPES);
2261 templen = sizeof(fcs_port_attr.supp_fc4_types);
2262 memcpy(attr->value, fcs_port_attr.supp_fc4_types, templen);
2263 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2264 len += templen;
2265 ++count;
2266 attr->len =
2267 cpu_to_be16(templen + sizeof(attr->type) +
2268 sizeof(templen));
2271 * Supported Speed
2273 attr = (struct fdmi_attr_s *) curr_ptr;
2274 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_SUPP_SPEED);
2275 templen = sizeof(fcs_port_attr.supp_speed);
2276 memcpy(attr->value, &fcs_port_attr.supp_speed, templen);
2277 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2278 len += templen;
2279 ++count;
2280 attr->len =
2281 cpu_to_be16(templen + sizeof(attr->type) +
2282 sizeof(templen));
2285 * current Port Speed
2287 attr = (struct fdmi_attr_s *) curr_ptr;
2288 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_SPEED);
2289 templen = sizeof(fcs_port_attr.curr_speed);
2290 memcpy(attr->value, &fcs_port_attr.curr_speed, templen);
2291 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2292 len += templen;
2293 ++count;
2294 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2295 sizeof(templen));
2298 * max frame size
2300 attr = (struct fdmi_attr_s *) curr_ptr;
2301 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_FRAME_SIZE);
2302 templen = sizeof(fcs_port_attr.max_frm_size);
2303 memcpy(attr->value, &fcs_port_attr.max_frm_size, templen);
2304 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2305 len += templen;
2306 ++count;
2307 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2308 sizeof(templen));
2311 * OS Device Name
2313 if (fcs_port_attr.os_device_name[0] != '\0') {
2314 attr = (struct fdmi_attr_s *) curr_ptr;
2315 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_DEV_NAME);
2316 templen = (u16) strlen(fcs_port_attr.os_device_name);
2317 memcpy(attr->value, fcs_port_attr.os_device_name, templen);
2318 templen = fc_roundup(templen, sizeof(u32));
2319 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2320 len += templen;
2321 ++count;
2322 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2323 sizeof(templen));
2326 * Host Name
2328 if (fcs_port_attr.host_name[0] != '\0') {
2329 attr = (struct fdmi_attr_s *) curr_ptr;
2330 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_HOST_NAME);
2331 templen = (u16) strlen(fcs_port_attr.host_name);
2332 memcpy(attr->value, fcs_port_attr.host_name, templen);
2333 templen = fc_roundup(templen, sizeof(u32));
2334 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2335 len += templen;
2336 ++count;
2337 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2338 sizeof(templen));
2341 if (fdmi->retry_cnt == 0) {
2342 attr = (struct fdmi_attr_s *) curr_ptr;
2343 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_NODE_NAME);
2344 templen = sizeof(fcs_port_attr.node_name);
2345 memcpy(attr->value, &fcs_port_attr.node_name, templen);
2346 templen = fc_roundup(templen, sizeof(u32));
2347 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2348 len += templen;
2349 ++count;
2350 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2351 sizeof(templen));
2353 attr = (struct fdmi_attr_s *) curr_ptr;
2354 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_NAME);
2355 templen = sizeof(fcs_port_attr.port_name);
2356 memcpy(attr->value, &fcs_port_attr.port_name, templen);
2357 templen = fc_roundup(templen, sizeof(u32));
2358 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + templen;
2359 len += templen;
2360 ++count;
2361 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2362 sizeof(templen));
2364 if (fcs_port_attr.port_sym_name.symname[0] != '\0') {
2365 attr = (struct fdmi_attr_s *) curr_ptr;
2366 attr->type =
2367 cpu_to_be16(FDMI_PORT_ATTRIB_PORT_SYM_NAME);
2368 templen = sizeof(fcs_port_attr.port_sym_name);
2369 memcpy(attr->value,
2370 &fcs_port_attr.port_sym_name, templen);
2371 templen = fc_roundup(templen, sizeof(u32));
2372 curr_ptr += sizeof(attr->type) +
2373 sizeof(templen) + templen;
2374 len += templen;
2375 ++count;
2376 attr->len = cpu_to_be16(templen +
2377 sizeof(attr->type) + sizeof(templen));
2380 attr = (struct fdmi_attr_s *) curr_ptr;
2381 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_TYPE);
2382 templen = sizeof(fcs_port_attr.port_type);
2383 memcpy(attr->value, &fcs_port_attr.port_type, templen);
2384 templen = fc_roundup(templen, sizeof(u32));
2385 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2386 len += templen;
2387 ++count;
2388 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2389 sizeof(templen));
2391 attr = (struct fdmi_attr_s *) curr_ptr;
2392 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_SUPP_COS);
2393 templen = sizeof(fcs_port_attr.scos);
2394 memcpy(attr->value, &fcs_port_attr.scos, templen);
2395 templen = fc_roundup(templen, sizeof(u32));
2396 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2397 len += templen;
2398 ++count;
2399 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2400 sizeof(templen));
2402 attr = (struct fdmi_attr_s *) curr_ptr;
2403 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_FAB_NAME);
2404 templen = sizeof(fcs_port_attr.port_fabric_name);
2405 memcpy(attr->value, &fcs_port_attr.port_fabric_name, templen);
2406 templen = fc_roundup(templen, sizeof(u32));
2407 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2408 len += templen;
2409 ++count;
2410 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2411 sizeof(templen));
2413 attr = (struct fdmi_attr_s *) curr_ptr;
2414 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_FC4_TYPE);
2415 templen = sizeof(fcs_port_attr.port_act_fc4_type);
2416 memcpy(attr->value, fcs_port_attr.port_act_fc4_type,
2417 templen);
2418 templen = fc_roundup(templen, sizeof(u32));
2419 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2420 len += templen;
2421 ++count;
2422 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2423 sizeof(templen));
2425 attr = (struct fdmi_attr_s *) curr_ptr;
2426 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_STATE);
2427 templen = sizeof(fcs_port_attr.port_state);
2428 memcpy(attr->value, &fcs_port_attr.port_state, templen);
2429 templen = fc_roundup(templen, sizeof(u32));
2430 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2431 len += templen;
2432 ++count;
2433 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2434 sizeof(templen));
2436 attr = (struct fdmi_attr_s *) curr_ptr;
2437 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_NUM_RPRT);
2438 templen = sizeof(fcs_port_attr.num_ports);
2439 memcpy(attr->value, &fcs_port_attr.num_ports, templen);
2440 templen = fc_roundup(templen, sizeof(u32));
2441 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2442 len += templen;
2443 ++count;
2444 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2445 sizeof(templen));
2449 * Update size of payload
2451 port_attrib->attr_count = cpu_to_be32(count);
2452 len += ((sizeof(attr->type) + sizeof(attr->len)) * count);
2453 return len;
2456 static u16
2457 bfa_fcs_lport_fdmi_build_rprt_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
2459 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2460 struct fdmi_rprt_s *rprt = (struct fdmi_rprt_s *) pyld;
2461 u16 len;
2463 rprt->hba_id = bfa_fcs_lport_get_pwwn(bfa_fcs_get_base_port(port->fcs));
2464 rprt->port_name = bfa_fcs_lport_get_pwwn(port);
2466 len = bfa_fcs_lport_fdmi_build_portattr_block(fdmi,
2467 (u8 *) &rprt->port_attr_blk);
2469 len += sizeof(rprt->hba_id) + sizeof(rprt->port_name);
2471 return len;
2474 static void
2475 bfa_fcs_lport_fdmi_rprt_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
2476 void *cbarg, bfa_status_t req_status,
2477 u32 rsp_len, u32 resid_len,
2478 struct fchs_s *rsp_fchs)
2480 struct bfa_fcs_lport_fdmi_s *fdmi =
2481 (struct bfa_fcs_lport_fdmi_s *) cbarg;
2482 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2483 struct ct_hdr_s *cthdr = NULL;
2485 bfa_trc(port->fcs, port->port_cfg.pwwn);
2488 * Sanity Checks
2490 if (req_status != BFA_STATUS_OK) {
2491 bfa_trc(port->fcs, req_status);
2492 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2493 return;
2496 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
2497 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
2499 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
2500 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
2501 return;
2504 bfa_trc(port->fcs, cthdr->reason_code);
2505 bfa_trc(port->fcs, cthdr->exp_code);
2506 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2510 * RPA : Register Port Attributes.
2512 static void
2513 bfa_fcs_lport_fdmi_send_rpa(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
2515 struct bfa_fcs_lport_fdmi_s *fdmi = fdmi_cbarg;
2516 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2517 struct fchs_s fchs;
2518 u16 len, attr_len;
2519 struct bfa_fcxp_s *fcxp;
2520 u8 *pyld;
2522 bfa_trc(port->fcs, port->port_cfg.pwwn);
2524 fcxp = fcxp_alloced ? fcxp_alloced :
2525 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
2526 if (!fcxp) {
2527 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
2528 bfa_fcs_lport_fdmi_send_rpa, fdmi, BFA_TRUE);
2529 return;
2531 fdmi->fcxp = fcxp;
2533 pyld = bfa_fcxp_get_reqbuf(fcxp);
2534 memset(pyld, 0, FC_MAX_PDUSZ);
2536 len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
2537 FDMI_RPA);
2539 attr_len = bfa_fcs_lport_fdmi_build_rpa_pyld(fdmi,
2540 (u8 *) ((struct ct_hdr_s *) pyld + 1));
2542 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
2543 FC_CLASS_3, len + attr_len, &fchs,
2544 bfa_fcs_lport_fdmi_rpa_response, (void *)fdmi,
2545 FC_MAX_PDUSZ, FC_FCCT_TOV);
2547 bfa_sm_send_event(fdmi, FDMISM_EVENT_RPA_SENT);
2550 static u16
2551 bfa_fcs_lport_fdmi_build_rpa_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
2553 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2554 struct fdmi_rpa_s *rpa = (struct fdmi_rpa_s *) pyld;
2555 u16 len;
2557 rpa->port_name = bfa_fcs_lport_get_pwwn(port);
2559 len = bfa_fcs_lport_fdmi_build_portattr_block(fdmi,
2560 (u8 *) &rpa->port_attr_blk);
2562 len += sizeof(rpa->port_name);
2564 return len;
2567 static void
2568 bfa_fcs_lport_fdmi_rpa_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
2569 void *cbarg, bfa_status_t req_status, u32 rsp_len,
2570 u32 resid_len, struct fchs_s *rsp_fchs)
2572 struct bfa_fcs_lport_fdmi_s *fdmi =
2573 (struct bfa_fcs_lport_fdmi_s *) cbarg;
2574 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2575 struct ct_hdr_s *cthdr = NULL;
2577 bfa_trc(port->fcs, port->port_cfg.pwwn);
2580 * Sanity Checks
2582 if (req_status != BFA_STATUS_OK) {
2583 bfa_trc(port->fcs, req_status);
2584 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2585 return;
2588 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
2589 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
2591 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
2592 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
2593 return;
2596 bfa_trc(port->fcs, cthdr->reason_code);
2597 bfa_trc(port->fcs, cthdr->exp_code);
2598 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2601 static void
2602 bfa_fcs_lport_fdmi_timeout(void *arg)
2604 struct bfa_fcs_lport_fdmi_s *fdmi = (struct bfa_fcs_lport_fdmi_s *) arg;
2606 bfa_sm_send_event(fdmi, FDMISM_EVENT_TIMEOUT);
2609 static void
2610 bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s *fdmi,
2611 struct bfa_fcs_fdmi_hba_attr_s *hba_attr)
2613 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2614 struct bfa_fcs_driver_info_s *driver_info = &port->fcs->driver_info;
2615 struct bfa_fcs_fdmi_port_attr_s fcs_port_attr;
2617 memset(hba_attr, 0, sizeof(struct bfa_fcs_fdmi_hba_attr_s));
2619 bfa_ioc_get_adapter_manufacturer(&port->fcs->bfa->ioc,
2620 hba_attr->manufacturer);
2621 bfa_ioc_get_adapter_serial_num(&port->fcs->bfa->ioc,
2622 hba_attr->serial_num);
2623 bfa_ioc_get_adapter_model(&port->fcs->bfa->ioc,
2624 hba_attr->model);
2625 bfa_ioc_get_adapter_model(&port->fcs->bfa->ioc,
2626 hba_attr->model_desc);
2627 bfa_ioc_get_pci_chip_rev(&port->fcs->bfa->ioc,
2628 hba_attr->hw_version);
2629 bfa_ioc_get_adapter_optrom_ver(&port->fcs->bfa->ioc,
2630 hba_attr->option_rom_ver);
2631 bfa_ioc_get_adapter_fw_ver(&port->fcs->bfa->ioc,
2632 hba_attr->fw_version);
2634 strncpy(hba_attr->driver_version, (char *)driver_info->version,
2635 sizeof(hba_attr->driver_version));
2637 strncpy(hba_attr->os_name, driver_info->host_os_name,
2638 sizeof(hba_attr->os_name));
2641 * If there is a patch level, append it
2642 * to the os name along with a separator
2644 if (driver_info->host_os_patch[0] != '\0') {
2645 strncat(hba_attr->os_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
2646 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
2647 strncat(hba_attr->os_name, driver_info->host_os_patch,
2648 sizeof(driver_info->host_os_patch));
2651 /* Retrieve the max frame size from the port attr */
2652 bfa_fcs_fdmi_get_portattr(fdmi, &fcs_port_attr);
2653 hba_attr->max_ct_pyld = fcs_port_attr.max_frm_size;
2655 strncpy(hba_attr->node_sym_name.symname,
2656 port->port_cfg.node_sym_name.symname, BFA_SYMNAME_MAXLEN);
2657 strcpy(hba_attr->vendor_info, "QLogic");
2658 hba_attr->num_ports =
2659 cpu_to_be32(bfa_ioc_get_nports(&port->fcs->bfa->ioc));
2660 hba_attr->fabric_name = port->fabric->lps->pr_nwwn;
2661 strncpy(hba_attr->bios_ver, hba_attr->option_rom_ver, BFA_VERSION_LEN);
2665 static void
2666 bfa_fcs_fdmi_get_portattr(struct bfa_fcs_lport_fdmi_s *fdmi,
2667 struct bfa_fcs_fdmi_port_attr_s *port_attr)
2669 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2670 struct bfa_fcs_driver_info_s *driver_info = &port->fcs->driver_info;
2671 struct bfa_port_attr_s pport_attr;
2672 struct bfa_lport_attr_s lport_attr;
2674 memset(port_attr, 0, sizeof(struct bfa_fcs_fdmi_port_attr_s));
2677 * get pport attributes from hal
2679 bfa_fcport_get_attr(port->fcs->bfa, &pport_attr);
2682 * get FC4 type Bitmask
2684 fc_get_fc4type_bitmask(FC_TYPE_FCP, port_attr->supp_fc4_types);
2687 * Supported Speeds
2689 switch (pport_attr.speed_supported) {
2690 case BFA_PORT_SPEED_16GBPS:
2691 port_attr->supp_speed =
2692 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_16G);
2693 break;
2695 case BFA_PORT_SPEED_10GBPS:
2696 port_attr->supp_speed =
2697 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_10G);
2698 break;
2700 case BFA_PORT_SPEED_8GBPS:
2701 port_attr->supp_speed =
2702 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_8G);
2703 break;
2705 case BFA_PORT_SPEED_4GBPS:
2706 port_attr->supp_speed =
2707 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_4G);
2708 break;
2710 default:
2711 bfa_sm_fault(port->fcs, pport_attr.speed_supported);
2715 * Current Speed
2717 port_attr->curr_speed = cpu_to_be32(
2718 bfa_fcs_fdmi_convert_speed(pport_attr.speed));
2721 * Max PDU Size.
2723 port_attr->max_frm_size = cpu_to_be32(pport_attr.pport_cfg.maxfrsize);
2726 * OS device Name
2728 strncpy(port_attr->os_device_name, (char *)driver_info->os_device_name,
2729 sizeof(port_attr->os_device_name));
2732 * Host name
2734 strncpy(port_attr->host_name, (char *)driver_info->host_machine_name,
2735 sizeof(port_attr->host_name));
2737 port_attr->node_name = bfa_fcs_lport_get_nwwn(port);
2738 port_attr->port_name = bfa_fcs_lport_get_pwwn(port);
2740 strncpy(port_attr->port_sym_name.symname,
2741 (char *)&bfa_fcs_lport_get_psym_name(port), BFA_SYMNAME_MAXLEN);
2742 bfa_fcs_lport_get_attr(port, &lport_attr);
2743 port_attr->port_type = cpu_to_be32(lport_attr.port_type);
2744 port_attr->scos = pport_attr.cos_supported;
2745 port_attr->port_fabric_name = port->fabric->lps->pr_nwwn;
2746 fc_get_fc4type_bitmask(FC_TYPE_FCP, port_attr->port_act_fc4_type);
2747 port_attr->port_state = cpu_to_be32(pport_attr.port_state);
2748 port_attr->num_ports = cpu_to_be32(port->num_rports);
2752 * Convert BFA speed to FDMI format.
2755 bfa_fcs_fdmi_convert_speed(bfa_port_speed_t pport_speed)
2757 u32 ret;
2759 switch (pport_speed) {
2760 case BFA_PORT_SPEED_1GBPS:
2761 case BFA_PORT_SPEED_2GBPS:
2762 ret = pport_speed;
2763 break;
2765 case BFA_PORT_SPEED_4GBPS:
2766 ret = FDMI_TRANS_SPEED_4G;
2767 break;
2769 case BFA_PORT_SPEED_8GBPS:
2770 ret = FDMI_TRANS_SPEED_8G;
2771 break;
2773 case BFA_PORT_SPEED_10GBPS:
2774 ret = FDMI_TRANS_SPEED_10G;
2775 break;
2777 case BFA_PORT_SPEED_16GBPS:
2778 ret = FDMI_TRANS_SPEED_16G;
2779 break;
2781 default:
2782 ret = FDMI_TRANS_SPEED_UNKNOWN;
2784 return ret;
2787 void
2788 bfa_fcs_lport_fdmi_init(struct bfa_fcs_lport_ms_s *ms)
2790 struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
2792 fdmi->ms = ms;
2793 if (ms->port->fcs->fdmi_enabled)
2794 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
2795 else
2796 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_disabled);
2799 void
2800 bfa_fcs_lport_fdmi_offline(struct bfa_fcs_lport_ms_s *ms)
2802 struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
2804 fdmi->ms = ms;
2805 bfa_sm_send_event(fdmi, FDMISM_EVENT_PORT_OFFLINE);
2808 void
2809 bfa_fcs_lport_fdmi_online(struct bfa_fcs_lport_ms_s *ms)
2811 struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
2813 fdmi->ms = ms;
2814 bfa_sm_send_event(fdmi, FDMISM_EVENT_PORT_ONLINE);
2817 #define BFA_FCS_MS_CMD_MAX_RETRIES 2
2820 * forward declarations
2822 static void bfa_fcs_lport_ms_send_plogi(void *ms_cbarg,
2823 struct bfa_fcxp_s *fcxp_alloced);
2824 static void bfa_fcs_lport_ms_timeout(void *arg);
2825 static void bfa_fcs_lport_ms_plogi_response(void *fcsarg,
2826 struct bfa_fcxp_s *fcxp,
2827 void *cbarg,
2828 bfa_status_t req_status,
2829 u32 rsp_len,
2830 u32 resid_len,
2831 struct fchs_s *rsp_fchs);
2833 static void bfa_fcs_lport_ms_send_gmal(void *ms_cbarg,
2834 struct bfa_fcxp_s *fcxp_alloced);
2835 static void bfa_fcs_lport_ms_gmal_response(void *fcsarg,
2836 struct bfa_fcxp_s *fcxp,
2837 void *cbarg,
2838 bfa_status_t req_status,
2839 u32 rsp_len,
2840 u32 resid_len,
2841 struct fchs_s *rsp_fchs);
2842 static void bfa_fcs_lport_ms_send_gfn(void *ms_cbarg,
2843 struct bfa_fcxp_s *fcxp_alloced);
2844 static void bfa_fcs_lport_ms_gfn_response(void *fcsarg,
2845 struct bfa_fcxp_s *fcxp,
2846 void *cbarg,
2847 bfa_status_t req_status,
2848 u32 rsp_len,
2849 u32 resid_len,
2850 struct fchs_s *rsp_fchs);
2852 * fcs_ms_sm FCS MS state machine
2856 * MS State Machine events
2858 enum port_ms_event {
2859 MSSM_EVENT_PORT_ONLINE = 1,
2860 MSSM_EVENT_PORT_OFFLINE = 2,
2861 MSSM_EVENT_RSP_OK = 3,
2862 MSSM_EVENT_RSP_ERROR = 4,
2863 MSSM_EVENT_TIMEOUT = 5,
2864 MSSM_EVENT_FCXP_SENT = 6,
2865 MSSM_EVENT_PORT_FABRIC_RSCN = 7
2868 static void bfa_fcs_lport_ms_sm_offline(struct bfa_fcs_lport_ms_s *ms,
2869 enum port_ms_event event);
2870 static void bfa_fcs_lport_ms_sm_plogi_sending(struct bfa_fcs_lport_ms_s *ms,
2871 enum port_ms_event event);
2872 static void bfa_fcs_lport_ms_sm_plogi(struct bfa_fcs_lport_ms_s *ms,
2873 enum port_ms_event event);
2874 static void bfa_fcs_lport_ms_sm_plogi_retry(struct bfa_fcs_lport_ms_s *ms,
2875 enum port_ms_event event);
2876 static void bfa_fcs_lport_ms_sm_gmal_sending(struct bfa_fcs_lport_ms_s *ms,
2877 enum port_ms_event event);
2878 static void bfa_fcs_lport_ms_sm_gmal(struct bfa_fcs_lport_ms_s *ms,
2879 enum port_ms_event event);
2880 static void bfa_fcs_lport_ms_sm_gmal_retry(struct bfa_fcs_lport_ms_s *ms,
2881 enum port_ms_event event);
2882 static void bfa_fcs_lport_ms_sm_gfn_sending(struct bfa_fcs_lport_ms_s *ms,
2883 enum port_ms_event event);
2884 static void bfa_fcs_lport_ms_sm_gfn(struct bfa_fcs_lport_ms_s *ms,
2885 enum port_ms_event event);
2886 static void bfa_fcs_lport_ms_sm_gfn_retry(struct bfa_fcs_lport_ms_s *ms,
2887 enum port_ms_event event);
2888 static void bfa_fcs_lport_ms_sm_online(struct bfa_fcs_lport_ms_s *ms,
2889 enum port_ms_event event);
2891 * Start in offline state - awaiting NS to send start.
2893 static void
2894 bfa_fcs_lport_ms_sm_offline(struct bfa_fcs_lport_ms_s *ms,
2895 enum port_ms_event event)
2897 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2898 bfa_trc(ms->port->fcs, event);
2900 switch (event) {
2901 case MSSM_EVENT_PORT_ONLINE:
2902 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi_sending);
2903 bfa_fcs_lport_ms_send_plogi(ms, NULL);
2904 break;
2906 case MSSM_EVENT_PORT_OFFLINE:
2907 break;
2909 default:
2910 bfa_sm_fault(ms->port->fcs, event);
2914 static void
2915 bfa_fcs_lport_ms_sm_plogi_sending(struct bfa_fcs_lport_ms_s *ms,
2916 enum port_ms_event event)
2918 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2919 bfa_trc(ms->port->fcs, event);
2921 switch (event) {
2922 case MSSM_EVENT_FCXP_SENT:
2923 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi);
2924 break;
2926 case MSSM_EVENT_PORT_OFFLINE:
2927 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
2928 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
2929 &ms->fcxp_wqe);
2930 break;
2932 default:
2933 bfa_sm_fault(ms->port->fcs, event);
2937 static void
2938 bfa_fcs_lport_ms_sm_plogi(struct bfa_fcs_lport_ms_s *ms,
2939 enum port_ms_event event)
2941 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2942 bfa_trc(ms->port->fcs, event);
2944 switch (event) {
2945 case MSSM_EVENT_RSP_ERROR:
2947 * Start timer for a delayed retry
2949 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi_retry);
2950 ms->port->stats.ms_retries++;
2951 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
2952 &ms->timer, bfa_fcs_lport_ms_timeout, ms,
2953 BFA_FCS_RETRY_TIMEOUT);
2954 break;
2956 case MSSM_EVENT_RSP_OK:
2958 * since plogi is done, now invoke MS related sub-modules
2960 bfa_fcs_lport_fdmi_online(ms);
2963 * if this is a Vport, go to online state.
2965 if (ms->port->vport) {
2966 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_online);
2967 break;
2971 * For a base port we need to get the
2972 * switch's IP address.
2974 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal_sending);
2975 bfa_fcs_lport_ms_send_gmal(ms, NULL);
2976 break;
2978 case MSSM_EVENT_PORT_OFFLINE:
2979 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
2980 bfa_fcxp_discard(ms->fcxp);
2981 break;
2983 default:
2984 bfa_sm_fault(ms->port->fcs, event);
2988 static void
2989 bfa_fcs_lport_ms_sm_plogi_retry(struct bfa_fcs_lport_ms_s *ms,
2990 enum port_ms_event event)
2992 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2993 bfa_trc(ms->port->fcs, event);
2995 switch (event) {
2996 case MSSM_EVENT_TIMEOUT:
2998 * Retry Timer Expired. Re-send
3000 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi_sending);
3001 bfa_fcs_lport_ms_send_plogi(ms, NULL);
3002 break;
3004 case MSSM_EVENT_PORT_OFFLINE:
3005 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3006 bfa_timer_stop(&ms->timer);
3007 break;
3009 default:
3010 bfa_sm_fault(ms->port->fcs, event);
3014 static void
3015 bfa_fcs_lport_ms_sm_online(struct bfa_fcs_lport_ms_s *ms,
3016 enum port_ms_event event)
3018 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3019 bfa_trc(ms->port->fcs, event);
3021 switch (event) {
3022 case MSSM_EVENT_PORT_OFFLINE:
3023 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3024 break;
3026 case MSSM_EVENT_PORT_FABRIC_RSCN:
3027 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
3028 ms->retry_cnt = 0;
3029 bfa_fcs_lport_ms_send_gfn(ms, NULL);
3030 break;
3032 default:
3033 bfa_sm_fault(ms->port->fcs, event);
3037 static void
3038 bfa_fcs_lport_ms_sm_gmal_sending(struct bfa_fcs_lport_ms_s *ms,
3039 enum port_ms_event event)
3041 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3042 bfa_trc(ms->port->fcs, event);
3044 switch (event) {
3045 case MSSM_EVENT_FCXP_SENT:
3046 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal);
3047 break;
3049 case MSSM_EVENT_PORT_OFFLINE:
3050 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3051 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
3052 &ms->fcxp_wqe);
3053 break;
3055 default:
3056 bfa_sm_fault(ms->port->fcs, event);
3060 static void
3061 bfa_fcs_lport_ms_sm_gmal(struct bfa_fcs_lport_ms_s *ms,
3062 enum port_ms_event event)
3064 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3065 bfa_trc(ms->port->fcs, event);
3067 switch (event) {
3068 case MSSM_EVENT_RSP_ERROR:
3070 * Start timer for a delayed retry
3072 if (ms->retry_cnt++ < BFA_FCS_MS_CMD_MAX_RETRIES) {
3073 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal_retry);
3074 ms->port->stats.ms_retries++;
3075 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
3076 &ms->timer, bfa_fcs_lport_ms_timeout, ms,
3077 BFA_FCS_RETRY_TIMEOUT);
3078 } else {
3079 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
3080 bfa_fcs_lport_ms_send_gfn(ms, NULL);
3081 ms->retry_cnt = 0;
3083 break;
3085 case MSSM_EVENT_RSP_OK:
3086 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
3087 bfa_fcs_lport_ms_send_gfn(ms, NULL);
3088 break;
3090 case MSSM_EVENT_PORT_OFFLINE:
3091 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3092 bfa_fcxp_discard(ms->fcxp);
3093 break;
3095 default:
3096 bfa_sm_fault(ms->port->fcs, event);
3100 static void
3101 bfa_fcs_lport_ms_sm_gmal_retry(struct bfa_fcs_lport_ms_s *ms,
3102 enum port_ms_event event)
3104 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3105 bfa_trc(ms->port->fcs, event);
3107 switch (event) {
3108 case MSSM_EVENT_TIMEOUT:
3110 * Retry Timer Expired. Re-send
3112 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal_sending);
3113 bfa_fcs_lport_ms_send_gmal(ms, NULL);
3114 break;
3116 case MSSM_EVENT_PORT_OFFLINE:
3117 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3118 bfa_timer_stop(&ms->timer);
3119 break;
3121 default:
3122 bfa_sm_fault(ms->port->fcs, event);
3126 * ms_pvt MS local functions
3129 static void
3130 bfa_fcs_lport_ms_send_gmal(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
3132 struct bfa_fcs_lport_ms_s *ms = ms_cbarg;
3133 bfa_fcs_lport_t *port = ms->port;
3134 struct fchs_s fchs;
3135 int len;
3136 struct bfa_fcxp_s *fcxp;
3138 bfa_trc(port->fcs, port->pid);
3140 fcxp = fcxp_alloced ? fcxp_alloced :
3141 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
3142 if (!fcxp) {
3143 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
3144 bfa_fcs_lport_ms_send_gmal, ms, BFA_TRUE);
3145 return;
3147 ms->fcxp = fcxp;
3149 len = fc_gmal_req_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
3150 bfa_fcs_lport_get_fcid(port),
3151 port->fabric->lps->pr_nwwn);
3153 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
3154 FC_CLASS_3, len, &fchs,
3155 bfa_fcs_lport_ms_gmal_response, (void *)ms,
3156 FC_MAX_PDUSZ, FC_FCCT_TOV);
3158 bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
3161 static void
3162 bfa_fcs_lport_ms_gmal_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
3163 void *cbarg, bfa_status_t req_status,
3164 u32 rsp_len, u32 resid_len,
3165 struct fchs_s *rsp_fchs)
3167 struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) cbarg;
3168 bfa_fcs_lport_t *port = ms->port;
3169 struct ct_hdr_s *cthdr = NULL;
3170 struct fcgs_gmal_resp_s *gmal_resp;
3171 struct fcgs_gmal_entry_s *gmal_entry;
3172 u32 num_entries;
3173 u8 *rsp_str;
3175 bfa_trc(port->fcs, req_status);
3176 bfa_trc(port->fcs, port->port_cfg.pwwn);
3179 * Sanity Checks
3181 if (req_status != BFA_STATUS_OK) {
3182 bfa_trc(port->fcs, req_status);
3183 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3184 return;
3187 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
3188 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
3190 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
3191 gmal_resp = (struct fcgs_gmal_resp_s *)(cthdr + 1);
3193 num_entries = be32_to_cpu(gmal_resp->ms_len);
3194 if (num_entries == 0) {
3195 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3196 return;
3199 * The response could contain multiple Entries.
3200 * Entries for SNMP interface, etc.
3201 * We look for the entry with a telnet prefix.
3202 * First "http://" entry refers to IP addr
3205 gmal_entry = (struct fcgs_gmal_entry_s *)gmal_resp->ms_ma;
3206 while (num_entries > 0) {
3207 if (strncmp(gmal_entry->prefix,
3208 CT_GMAL_RESP_PREFIX_HTTP,
3209 sizeof(gmal_entry->prefix)) == 0) {
3212 * if the IP address is terminating with a '/',
3213 * remove it.
3214 * Byte 0 consists of the length of the string.
3216 rsp_str = &(gmal_entry->prefix[0]);
3217 if (rsp_str[gmal_entry->len-1] == '/')
3218 rsp_str[gmal_entry->len-1] = 0;
3220 /* copy IP Address to fabric */
3221 strncpy(bfa_fcs_lport_get_fabric_ipaddr(port),
3222 gmal_entry->ip_addr,
3223 BFA_FCS_FABRIC_IPADDR_SZ);
3224 break;
3225 } else {
3226 --num_entries;
3227 ++gmal_entry;
3231 bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
3232 return;
3235 bfa_trc(port->fcs, cthdr->reason_code);
3236 bfa_trc(port->fcs, cthdr->exp_code);
3237 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3240 static void
3241 bfa_fcs_lport_ms_sm_gfn_sending(struct bfa_fcs_lport_ms_s *ms,
3242 enum port_ms_event event)
3244 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3245 bfa_trc(ms->port->fcs, event);
3247 switch (event) {
3248 case MSSM_EVENT_FCXP_SENT:
3249 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn);
3250 break;
3252 case MSSM_EVENT_PORT_OFFLINE:
3253 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3254 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
3255 &ms->fcxp_wqe);
3256 break;
3258 default:
3259 bfa_sm_fault(ms->port->fcs, event);
3263 static void
3264 bfa_fcs_lport_ms_sm_gfn(struct bfa_fcs_lport_ms_s *ms,
3265 enum port_ms_event event)
3267 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3268 bfa_trc(ms->port->fcs, event);
3270 switch (event) {
3271 case MSSM_EVENT_RSP_ERROR:
3273 * Start timer for a delayed retry
3275 if (ms->retry_cnt++ < BFA_FCS_MS_CMD_MAX_RETRIES) {
3276 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_retry);
3277 ms->port->stats.ms_retries++;
3278 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
3279 &ms->timer, bfa_fcs_lport_ms_timeout, ms,
3280 BFA_FCS_RETRY_TIMEOUT);
3281 } else {
3282 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_online);
3283 ms->retry_cnt = 0;
3285 break;
3287 case MSSM_EVENT_RSP_OK:
3288 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_online);
3289 break;
3291 case MSSM_EVENT_PORT_OFFLINE:
3292 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3293 bfa_fcxp_discard(ms->fcxp);
3294 break;
3296 default:
3297 bfa_sm_fault(ms->port->fcs, event);
3301 static void
3302 bfa_fcs_lport_ms_sm_gfn_retry(struct bfa_fcs_lport_ms_s *ms,
3303 enum port_ms_event event)
3305 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3306 bfa_trc(ms->port->fcs, event);
3308 switch (event) {
3309 case MSSM_EVENT_TIMEOUT:
3311 * Retry Timer Expired. Re-send
3313 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
3314 bfa_fcs_lport_ms_send_gfn(ms, NULL);
3315 break;
3317 case MSSM_EVENT_PORT_OFFLINE:
3318 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3319 bfa_timer_stop(&ms->timer);
3320 break;
3322 default:
3323 bfa_sm_fault(ms->port->fcs, event);
3327 * ms_pvt MS local functions
3330 static void
3331 bfa_fcs_lport_ms_send_gfn(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
3333 struct bfa_fcs_lport_ms_s *ms = ms_cbarg;
3334 bfa_fcs_lport_t *port = ms->port;
3335 struct fchs_s fchs;
3336 int len;
3337 struct bfa_fcxp_s *fcxp;
3339 bfa_trc(port->fcs, port->pid);
3341 fcxp = fcxp_alloced ? fcxp_alloced :
3342 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
3343 if (!fcxp) {
3344 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
3345 bfa_fcs_lport_ms_send_gfn, ms, BFA_TRUE);
3346 return;
3348 ms->fcxp = fcxp;
3350 len = fc_gfn_req_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
3351 bfa_fcs_lport_get_fcid(port),
3352 port->fabric->lps->pr_nwwn);
3354 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
3355 FC_CLASS_3, len, &fchs,
3356 bfa_fcs_lport_ms_gfn_response, (void *)ms,
3357 FC_MAX_PDUSZ, FC_FCCT_TOV);
3359 bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
3362 static void
3363 bfa_fcs_lport_ms_gfn_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
3364 void *cbarg, bfa_status_t req_status, u32 rsp_len,
3365 u32 resid_len, struct fchs_s *rsp_fchs)
3367 struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) cbarg;
3368 bfa_fcs_lport_t *port = ms->port;
3369 struct ct_hdr_s *cthdr = NULL;
3370 wwn_t *gfn_resp;
3372 bfa_trc(port->fcs, req_status);
3373 bfa_trc(port->fcs, port->port_cfg.pwwn);
3376 * Sanity Checks
3378 if (req_status != BFA_STATUS_OK) {
3379 bfa_trc(port->fcs, req_status);
3380 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3381 return;
3384 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
3385 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
3387 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
3388 gfn_resp = (wwn_t *)(cthdr + 1);
3389 /* check if it has actually changed */
3390 if ((memcmp((void *)&bfa_fcs_lport_get_fabric_name(port),
3391 gfn_resp, sizeof(wwn_t)) != 0)) {
3392 bfa_fcs_fabric_set_fabric_name(port->fabric, *gfn_resp);
3394 bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
3395 return;
3398 bfa_trc(port->fcs, cthdr->reason_code);
3399 bfa_trc(port->fcs, cthdr->exp_code);
3400 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3404 * ms_pvt MS local functions
3407 static void
3408 bfa_fcs_lport_ms_send_plogi(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
3410 struct bfa_fcs_lport_ms_s *ms = ms_cbarg;
3411 struct bfa_fcs_lport_s *port = ms->port;
3412 struct fchs_s fchs;
3413 int len;
3414 struct bfa_fcxp_s *fcxp;
3416 bfa_trc(port->fcs, port->pid);
3418 fcxp = fcxp_alloced ? fcxp_alloced :
3419 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
3420 if (!fcxp) {
3421 port->stats.ms_plogi_alloc_wait++;
3422 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
3423 bfa_fcs_lport_ms_send_plogi, ms, BFA_TRUE);
3424 return;
3426 ms->fcxp = fcxp;
3428 len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
3429 bfa_hton3b(FC_MGMT_SERVER),
3430 bfa_fcs_lport_get_fcid(port), 0,
3431 port->port_cfg.pwwn, port->port_cfg.nwwn,
3432 bfa_fcport_get_maxfrsize(port->fcs->bfa),
3433 bfa_fcport_get_rx_bbcredit(port->fcs->bfa));
3435 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
3436 FC_CLASS_3, len, &fchs,
3437 bfa_fcs_lport_ms_plogi_response, (void *)ms,
3438 FC_MAX_PDUSZ, FC_ELS_TOV);
3440 port->stats.ms_plogi_sent++;
3441 bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
3444 static void
3445 bfa_fcs_lport_ms_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
3446 void *cbarg, bfa_status_t req_status,
3447 u32 rsp_len, u32 resid_len, struct fchs_s *rsp_fchs)
3449 struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) cbarg;
3450 struct bfa_fcs_lport_s *port = ms->port;
3451 struct fc_els_cmd_s *els_cmd;
3452 struct fc_ls_rjt_s *ls_rjt;
3454 bfa_trc(port->fcs, req_status);
3455 bfa_trc(port->fcs, port->port_cfg.pwwn);
3458 * Sanity Checks
3460 if (req_status != BFA_STATUS_OK) {
3461 port->stats.ms_plogi_rsp_err++;
3462 bfa_trc(port->fcs, req_status);
3463 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3464 return;
3467 els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
3469 switch (els_cmd->els_code) {
3471 case FC_ELS_ACC:
3472 if (rsp_len < sizeof(struct fc_logi_s)) {
3473 bfa_trc(port->fcs, rsp_len);
3474 port->stats.ms_plogi_acc_err++;
3475 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3476 break;
3478 port->stats.ms_plogi_accepts++;
3479 bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
3480 break;
3482 case FC_ELS_LS_RJT:
3483 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
3485 bfa_trc(port->fcs, ls_rjt->reason_code);
3486 bfa_trc(port->fcs, ls_rjt->reason_code_expl);
3488 port->stats.ms_rejects++;
3489 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3490 break;
3492 default:
3493 port->stats.ms_plogi_unknown_rsp++;
3494 bfa_trc(port->fcs, els_cmd->els_code);
3495 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3499 static void
3500 bfa_fcs_lport_ms_timeout(void *arg)
3502 struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) arg;
3504 ms->port->stats.ms_timeouts++;
3505 bfa_sm_send_event(ms, MSSM_EVENT_TIMEOUT);
3509 void
3510 bfa_fcs_lport_ms_init(struct bfa_fcs_lport_s *port)
3512 struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
3514 ms->port = port;
3515 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3518 * Invoke init routines of sub modules.
3520 bfa_fcs_lport_fdmi_init(ms);
3523 void
3524 bfa_fcs_lport_ms_offline(struct bfa_fcs_lport_s *port)
3526 struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
3528 ms->port = port;
3529 bfa_sm_send_event(ms, MSSM_EVENT_PORT_OFFLINE);
3530 bfa_fcs_lport_fdmi_offline(ms);
3533 void
3534 bfa_fcs_lport_ms_online(struct bfa_fcs_lport_s *port)
3536 struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
3538 ms->port = port;
3539 bfa_sm_send_event(ms, MSSM_EVENT_PORT_ONLINE);
3541 void
3542 bfa_fcs_lport_ms_fabric_rscn(struct bfa_fcs_lport_s *port)
3544 struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
3546 /* todo. Handle this only when in Online state */
3547 if (bfa_sm_cmp_state(ms, bfa_fcs_lport_ms_sm_online))
3548 bfa_sm_send_event(ms, MSSM_EVENT_PORT_FABRIC_RSCN);
3552 * @page ns_sm_info VPORT NS State Machine
3554 * @section ns_sm_interactions VPORT NS State Machine Interactions
3556 * @section ns_sm VPORT NS State Machine
3557 * img ns_sm.jpg
3561 * forward declarations
3563 static void bfa_fcs_lport_ns_send_plogi(void *ns_cbarg,
3564 struct bfa_fcxp_s *fcxp_alloced);
3565 static void bfa_fcs_lport_ns_send_rspn_id(void *ns_cbarg,
3566 struct bfa_fcxp_s *fcxp_alloced);
3567 static void bfa_fcs_lport_ns_send_rft_id(void *ns_cbarg,
3568 struct bfa_fcxp_s *fcxp_alloced);
3569 static void bfa_fcs_lport_ns_send_rff_id(void *ns_cbarg,
3570 struct bfa_fcxp_s *fcxp_alloced);
3571 static void bfa_fcs_lport_ns_send_gid_ft(void *ns_cbarg,
3572 struct bfa_fcxp_s *fcxp_alloced);
3573 static void bfa_fcs_lport_ns_send_rnn_id(void *ns_cbarg,
3574 struct bfa_fcxp_s *fcxp_alloced);
3575 static void bfa_fcs_lport_ns_send_rsnn_nn(void *ns_cbarg,
3576 struct bfa_fcxp_s *fcxp_alloced);
3577 static void bfa_fcs_lport_ns_timeout(void *arg);
3578 static void bfa_fcs_lport_ns_plogi_response(void *fcsarg,
3579 struct bfa_fcxp_s *fcxp,
3580 void *cbarg,
3581 bfa_status_t req_status,
3582 u32 rsp_len,
3583 u32 resid_len,
3584 struct fchs_s *rsp_fchs);
3585 static void bfa_fcs_lport_ns_rspn_id_response(void *fcsarg,
3586 struct bfa_fcxp_s *fcxp,
3587 void *cbarg,
3588 bfa_status_t req_status,
3589 u32 rsp_len,
3590 u32 resid_len,
3591 struct fchs_s *rsp_fchs);
3592 static void bfa_fcs_lport_ns_rft_id_response(void *fcsarg,
3593 struct bfa_fcxp_s *fcxp,
3594 void *cbarg,
3595 bfa_status_t req_status,
3596 u32 rsp_len,
3597 u32 resid_len,
3598 struct fchs_s *rsp_fchs);
3599 static void bfa_fcs_lport_ns_rff_id_response(void *fcsarg,
3600 struct bfa_fcxp_s *fcxp,
3601 void *cbarg,
3602 bfa_status_t req_status,
3603 u32 rsp_len,
3604 u32 resid_len,
3605 struct fchs_s *rsp_fchs);
3606 static void bfa_fcs_lport_ns_gid_ft_response(void *fcsarg,
3607 struct bfa_fcxp_s *fcxp,
3608 void *cbarg,
3609 bfa_status_t req_status,
3610 u32 rsp_len,
3611 u32 resid_len,
3612 struct fchs_s *rsp_fchs);
3613 static void bfa_fcs_lport_ns_rnn_id_response(void *fcsarg,
3614 struct bfa_fcxp_s *fcxp,
3615 void *cbarg,
3616 bfa_status_t req_status,
3617 u32 rsp_len,
3618 u32 resid_len,
3619 struct fchs_s *rsp_fchs);
3620 static void bfa_fcs_lport_ns_rsnn_nn_response(void *fcsarg,
3621 struct bfa_fcxp_s *fcxp,
3622 void *cbarg,
3623 bfa_status_t req_status,
3624 u32 rsp_len,
3625 u32 resid_len,
3626 struct fchs_s *rsp_fchs);
3627 static void bfa_fcs_lport_ns_process_gidft_pids(
3628 struct bfa_fcs_lport_s *port,
3629 u32 *pid_buf, u32 n_pids);
3631 static void bfa_fcs_lport_ns_boot_target_disc(bfa_fcs_lport_t *port);
3633 * fcs_ns_sm FCS nameserver interface state machine
3637 * VPort NS State Machine events
3639 enum vport_ns_event {
3640 NSSM_EVENT_PORT_ONLINE = 1,
3641 NSSM_EVENT_PORT_OFFLINE = 2,
3642 NSSM_EVENT_PLOGI_SENT = 3,
3643 NSSM_EVENT_RSP_OK = 4,
3644 NSSM_EVENT_RSP_ERROR = 5,
3645 NSSM_EVENT_TIMEOUT = 6,
3646 NSSM_EVENT_NS_QUERY = 7,
3647 NSSM_EVENT_RSPNID_SENT = 8,
3648 NSSM_EVENT_RFTID_SENT = 9,
3649 NSSM_EVENT_RFFID_SENT = 10,
3650 NSSM_EVENT_GIDFT_SENT = 11,
3651 NSSM_EVENT_RNNID_SENT = 12,
3652 NSSM_EVENT_RSNN_NN_SENT = 13,
3655 static void bfa_fcs_lport_ns_sm_offline(struct bfa_fcs_lport_ns_s *ns,
3656 enum vport_ns_event event);
3657 static void bfa_fcs_lport_ns_sm_plogi_sending(struct bfa_fcs_lport_ns_s *ns,
3658 enum vport_ns_event event);
3659 static void bfa_fcs_lport_ns_sm_plogi(struct bfa_fcs_lport_ns_s *ns,
3660 enum vport_ns_event event);
3661 static void bfa_fcs_lport_ns_sm_plogi_retry(struct bfa_fcs_lport_ns_s *ns,
3662 enum vport_ns_event event);
3663 static void bfa_fcs_lport_ns_sm_sending_rspn_id(
3664 struct bfa_fcs_lport_ns_s *ns,
3665 enum vport_ns_event event);
3666 static void bfa_fcs_lport_ns_sm_rspn_id(struct bfa_fcs_lport_ns_s *ns,
3667 enum vport_ns_event event);
3668 static void bfa_fcs_lport_ns_sm_rspn_id_retry(struct bfa_fcs_lport_ns_s *ns,
3669 enum vport_ns_event event);
3670 static void bfa_fcs_lport_ns_sm_sending_rft_id(
3671 struct bfa_fcs_lport_ns_s *ns,
3672 enum vport_ns_event event);
3673 static void bfa_fcs_lport_ns_sm_rft_id_retry(struct bfa_fcs_lport_ns_s *ns,
3674 enum vport_ns_event event);
3675 static void bfa_fcs_lport_ns_sm_rft_id(struct bfa_fcs_lport_ns_s *ns,
3676 enum vport_ns_event event);
3677 static void bfa_fcs_lport_ns_sm_sending_rff_id(
3678 struct bfa_fcs_lport_ns_s *ns,
3679 enum vport_ns_event event);
3680 static void bfa_fcs_lport_ns_sm_rff_id_retry(struct bfa_fcs_lport_ns_s *ns,
3681 enum vport_ns_event event);
3682 static void bfa_fcs_lport_ns_sm_rff_id(struct bfa_fcs_lport_ns_s *ns,
3683 enum vport_ns_event event);
3684 static void bfa_fcs_lport_ns_sm_sending_gid_ft(
3685 struct bfa_fcs_lport_ns_s *ns,
3686 enum vport_ns_event event);
3687 static void bfa_fcs_lport_ns_sm_gid_ft(struct bfa_fcs_lport_ns_s *ns,
3688 enum vport_ns_event event);
3689 static void bfa_fcs_lport_ns_sm_gid_ft_retry(struct bfa_fcs_lport_ns_s *ns,
3690 enum vport_ns_event event);
3691 static void bfa_fcs_lport_ns_sm_online(struct bfa_fcs_lport_ns_s *ns,
3692 enum vport_ns_event event);
3693 static void bfa_fcs_lport_ns_sm_sending_rnn_id(
3694 struct bfa_fcs_lport_ns_s *ns,
3695 enum vport_ns_event event);
3696 static void bfa_fcs_lport_ns_sm_rnn_id(struct bfa_fcs_lport_ns_s *ns,
3697 enum vport_ns_event event);
3698 static void bfa_fcs_lport_ns_sm_rnn_id_retry(struct bfa_fcs_lport_ns_s *ns,
3699 enum vport_ns_event event);
3700 static void bfa_fcs_lport_ns_sm_sending_rsnn_nn(
3701 struct bfa_fcs_lport_ns_s *ns,
3702 enum vport_ns_event event);
3703 static void bfa_fcs_lport_ns_sm_rsnn_nn(struct bfa_fcs_lport_ns_s *ns,
3704 enum vport_ns_event event);
3705 static void bfa_fcs_lport_ns_sm_rsnn_nn_retry(
3706 struct bfa_fcs_lport_ns_s *ns,
3707 enum vport_ns_event event);
3709 * Start in offline state - awaiting linkup
3711 static void
3712 bfa_fcs_lport_ns_sm_offline(struct bfa_fcs_lport_ns_s *ns,
3713 enum vport_ns_event event)
3715 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3716 bfa_trc(ns->port->fcs, event);
3718 switch (event) {
3719 case NSSM_EVENT_PORT_ONLINE:
3720 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi_sending);
3721 bfa_fcs_lport_ns_send_plogi(ns, NULL);
3722 break;
3724 case NSSM_EVENT_PORT_OFFLINE:
3725 break;
3727 default:
3728 bfa_sm_fault(ns->port->fcs, event);
3732 static void
3733 bfa_fcs_lport_ns_sm_plogi_sending(struct bfa_fcs_lport_ns_s *ns,
3734 enum vport_ns_event event)
3736 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3737 bfa_trc(ns->port->fcs, event);
3739 switch (event) {
3740 case NSSM_EVENT_PLOGI_SENT:
3741 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi);
3742 break;
3744 case NSSM_EVENT_PORT_OFFLINE:
3745 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3746 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3747 &ns->fcxp_wqe);
3748 break;
3750 default:
3751 bfa_sm_fault(ns->port->fcs, event);
3755 static void
3756 bfa_fcs_lport_ns_sm_plogi(struct bfa_fcs_lport_ns_s *ns,
3757 enum vport_ns_event event)
3759 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3760 bfa_trc(ns->port->fcs, event);
3762 switch (event) {
3763 case NSSM_EVENT_RSP_ERROR:
3765 * Start timer for a delayed retry
3767 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi_retry);
3768 ns->port->stats.ns_retries++;
3769 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3770 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
3771 BFA_FCS_RETRY_TIMEOUT);
3772 break;
3774 case NSSM_EVENT_RSP_OK:
3775 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rnn_id);
3776 ns->num_rnnid_retries = 0;
3777 bfa_fcs_lport_ns_send_rnn_id(ns, NULL);
3778 break;
3780 case NSSM_EVENT_PORT_OFFLINE:
3781 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3782 bfa_fcxp_discard(ns->fcxp);
3783 break;
3785 default:
3786 bfa_sm_fault(ns->port->fcs, event);
3790 static void
3791 bfa_fcs_lport_ns_sm_plogi_retry(struct bfa_fcs_lport_ns_s *ns,
3792 enum vport_ns_event event)
3794 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3795 bfa_trc(ns->port->fcs, event);
3797 switch (event) {
3798 case NSSM_EVENT_TIMEOUT:
3800 * Retry Timer Expired. Re-send
3802 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi_sending);
3803 bfa_fcs_lport_ns_send_plogi(ns, NULL);
3804 break;
3806 case NSSM_EVENT_PORT_OFFLINE:
3807 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3808 bfa_timer_stop(&ns->timer);
3809 break;
3811 default:
3812 bfa_sm_fault(ns->port->fcs, event);
3816 static void
3817 bfa_fcs_lport_ns_sm_sending_rnn_id(struct bfa_fcs_lport_ns_s *ns,
3818 enum vport_ns_event event)
3820 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3821 bfa_trc(ns->port->fcs, event);
3823 switch (event) {
3824 case NSSM_EVENT_RNNID_SENT:
3825 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rnn_id);
3826 break;
3828 case NSSM_EVENT_PORT_OFFLINE:
3829 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3830 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3831 &ns->fcxp_wqe);
3832 break;
3833 default:
3834 bfa_sm_fault(ns->port->fcs, event);
3838 static void
3839 bfa_fcs_lport_ns_sm_rnn_id(struct bfa_fcs_lport_ns_s *ns,
3840 enum vport_ns_event event)
3842 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3843 bfa_trc(ns->port->fcs, event);
3845 switch (event) {
3846 case NSSM_EVENT_RSP_OK:
3847 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rsnn_nn);
3848 ns->num_rnnid_retries = 0;
3849 ns->num_rsnn_nn_retries = 0;
3850 bfa_fcs_lport_ns_send_rsnn_nn(ns, NULL);
3851 break;
3853 case NSSM_EVENT_RSP_ERROR:
3854 if (ns->num_rnnid_retries < BFA_FCS_MAX_NS_RETRIES) {
3855 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rnn_id_retry);
3856 ns->port->stats.ns_retries++;
3857 ns->num_rnnid_retries++;
3858 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3859 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
3860 BFA_FCS_RETRY_TIMEOUT);
3861 } else {
3862 bfa_sm_set_state(ns,
3863 bfa_fcs_lport_ns_sm_sending_rspn_id);
3864 bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
3866 break;
3868 case NSSM_EVENT_PORT_OFFLINE:
3869 bfa_fcxp_discard(ns->fcxp);
3870 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3871 break;
3873 default:
3874 bfa_sm_fault(ns->port->fcs, event);
3878 static void
3879 bfa_fcs_lport_ns_sm_rnn_id_retry(struct bfa_fcs_lport_ns_s *ns,
3880 enum vport_ns_event event)
3882 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3883 bfa_trc(ns->port->fcs, event);
3885 switch (event) {
3886 case NSSM_EVENT_TIMEOUT:
3887 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rnn_id);
3888 bfa_fcs_lport_ns_send_rnn_id(ns, NULL);
3889 break;
3891 case NSSM_EVENT_PORT_OFFLINE:
3892 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3893 bfa_timer_stop(&ns->timer);
3894 break;
3896 default:
3897 bfa_sm_fault(ns->port->fcs, event);
3901 static void
3902 bfa_fcs_lport_ns_sm_sending_rsnn_nn(struct bfa_fcs_lport_ns_s *ns,
3903 enum vport_ns_event event)
3905 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3906 bfa_trc(ns->port->fcs, event);
3908 switch (event) {
3909 case NSSM_EVENT_RSNN_NN_SENT:
3910 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rsnn_nn);
3911 break;
3913 case NSSM_EVENT_PORT_OFFLINE:
3914 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3915 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3916 &ns->fcxp_wqe);
3917 break;
3919 default:
3920 bfa_sm_fault(ns->port->fcs, event);
3924 static void
3925 bfa_fcs_lport_ns_sm_rsnn_nn(struct bfa_fcs_lport_ns_s *ns,
3926 enum vport_ns_event event)
3928 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3929 bfa_trc(ns->port->fcs, event);
3931 switch (event) {
3932 case NSSM_EVENT_RSP_OK:
3933 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rspn_id);
3934 ns->num_rsnn_nn_retries = 0;
3935 bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
3936 break;
3938 case NSSM_EVENT_RSP_ERROR:
3939 if (ns->num_rsnn_nn_retries < BFA_FCS_MAX_NS_RETRIES) {
3940 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rsnn_nn_retry);
3941 ns->port->stats.ns_retries++;
3942 ns->num_rsnn_nn_retries++;
3943 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3944 &ns->timer, bfa_fcs_lport_ns_timeout,
3945 ns, BFA_FCS_RETRY_TIMEOUT);
3946 } else {
3947 bfa_sm_set_state(ns,
3948 bfa_fcs_lport_ns_sm_sending_rspn_id);
3949 bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
3951 break;
3953 case NSSM_EVENT_PORT_OFFLINE:
3954 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3955 bfa_fcxp_discard(ns->fcxp);
3956 break;
3958 default:
3959 bfa_sm_fault(ns->port->fcs, event);
3963 static void
3964 bfa_fcs_lport_ns_sm_rsnn_nn_retry(struct bfa_fcs_lport_ns_s *ns,
3965 enum vport_ns_event event)
3967 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3968 bfa_trc(ns->port->fcs, event);
3970 switch (event) {
3971 case NSSM_EVENT_TIMEOUT:
3972 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rsnn_nn);
3973 bfa_fcs_lport_ns_send_rsnn_nn(ns, NULL);
3974 break;
3976 case NSSM_EVENT_PORT_OFFLINE:
3977 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3978 bfa_timer_stop(&ns->timer);
3979 break;
3981 default:
3982 bfa_sm_fault(ns->port->fcs, event);
3986 static void
3987 bfa_fcs_lport_ns_sm_sending_rspn_id(struct bfa_fcs_lport_ns_s *ns,
3988 enum vport_ns_event event)
3990 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3991 bfa_trc(ns->port->fcs, event);
3993 switch (event) {
3994 case NSSM_EVENT_RSPNID_SENT:
3995 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rspn_id);
3996 break;
3998 case NSSM_EVENT_PORT_OFFLINE:
3999 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4000 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4001 &ns->fcxp_wqe);
4002 break;
4004 default:
4005 bfa_sm_fault(ns->port->fcs, event);
4009 static void
4010 bfa_fcs_lport_ns_sm_rspn_id(struct bfa_fcs_lport_ns_s *ns,
4011 enum vport_ns_event event)
4013 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4014 bfa_trc(ns->port->fcs, event);
4016 switch (event) {
4017 case NSSM_EVENT_RSP_ERROR:
4019 * Start timer for a delayed retry
4021 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rspn_id_retry);
4022 ns->port->stats.ns_retries++;
4023 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4024 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
4025 BFA_FCS_RETRY_TIMEOUT);
4026 break;
4028 case NSSM_EVENT_RSP_OK:
4029 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rft_id);
4030 bfa_fcs_lport_ns_send_rft_id(ns, NULL);
4031 break;
4033 case NSSM_EVENT_PORT_OFFLINE:
4034 bfa_fcxp_discard(ns->fcxp);
4035 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4036 break;
4038 default:
4039 bfa_sm_fault(ns->port->fcs, event);
4043 static void
4044 bfa_fcs_lport_ns_sm_rspn_id_retry(struct bfa_fcs_lport_ns_s *ns,
4045 enum vport_ns_event event)
4047 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4048 bfa_trc(ns->port->fcs, event);
4050 switch (event) {
4051 case NSSM_EVENT_TIMEOUT:
4053 * Retry Timer Expired. Re-send
4055 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rspn_id);
4056 bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
4057 break;
4059 case NSSM_EVENT_PORT_OFFLINE:
4060 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4061 bfa_timer_stop(&ns->timer);
4062 break;
4064 default:
4065 bfa_sm_fault(ns->port->fcs, event);
4069 static void
4070 bfa_fcs_lport_ns_sm_sending_rft_id(struct bfa_fcs_lport_ns_s *ns,
4071 enum vport_ns_event event)
4073 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4074 bfa_trc(ns->port->fcs, event);
4076 switch (event) {
4077 case NSSM_EVENT_RFTID_SENT:
4078 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rft_id);
4079 break;
4081 case NSSM_EVENT_PORT_OFFLINE:
4082 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4083 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4084 &ns->fcxp_wqe);
4085 break;
4087 default:
4088 bfa_sm_fault(ns->port->fcs, event);
4092 static void
4093 bfa_fcs_lport_ns_sm_rft_id(struct bfa_fcs_lport_ns_s *ns,
4094 enum vport_ns_event event)
4096 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4097 bfa_trc(ns->port->fcs, event);
4099 switch (event) {
4100 case NSSM_EVENT_RSP_OK:
4101 /* Now move to register FC4 Features */
4102 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rff_id);
4103 bfa_fcs_lport_ns_send_rff_id(ns, NULL);
4104 break;
4106 case NSSM_EVENT_RSP_ERROR:
4108 * Start timer for a delayed retry
4110 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rft_id_retry);
4111 ns->port->stats.ns_retries++;
4112 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4113 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
4114 BFA_FCS_RETRY_TIMEOUT);
4115 break;
4117 case NSSM_EVENT_PORT_OFFLINE:
4118 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4119 bfa_fcxp_discard(ns->fcxp);
4120 break;
4122 default:
4123 bfa_sm_fault(ns->port->fcs, event);
4127 static void
4128 bfa_fcs_lport_ns_sm_rft_id_retry(struct bfa_fcs_lport_ns_s *ns,
4129 enum vport_ns_event event)
4131 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4132 bfa_trc(ns->port->fcs, event);
4134 switch (event) {
4135 case NSSM_EVENT_TIMEOUT:
4136 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rft_id);
4137 bfa_fcs_lport_ns_send_rft_id(ns, NULL);
4138 break;
4140 case NSSM_EVENT_PORT_OFFLINE:
4141 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4142 bfa_timer_stop(&ns->timer);
4143 break;
4145 default:
4146 bfa_sm_fault(ns->port->fcs, event);
4150 static void
4151 bfa_fcs_lport_ns_sm_sending_rff_id(struct bfa_fcs_lport_ns_s *ns,
4152 enum vport_ns_event event)
4154 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4155 bfa_trc(ns->port->fcs, event);
4157 switch (event) {
4158 case NSSM_EVENT_RFFID_SENT:
4159 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rff_id);
4160 break;
4162 case NSSM_EVENT_PORT_OFFLINE:
4163 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4164 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4165 &ns->fcxp_wqe);
4166 break;
4168 default:
4169 bfa_sm_fault(ns->port->fcs, event);
4173 static void
4174 bfa_fcs_lport_ns_sm_rff_id(struct bfa_fcs_lport_ns_s *ns,
4175 enum vport_ns_event event)
4177 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4178 bfa_trc(ns->port->fcs, event);
4180 switch (event) {
4181 case NSSM_EVENT_RSP_OK:
4184 * If min cfg mode is enabled, we donot initiate rport
4185 * discovery with the fabric. Instead, we will retrieve the
4186 * boot targets from HAL/FW.
4188 if (__fcs_min_cfg(ns->port->fcs)) {
4189 bfa_fcs_lport_ns_boot_target_disc(ns->port);
4190 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_online);
4191 return;
4195 * If the port role is Initiator Mode issue NS query.
4196 * If it is Target Mode, skip this and go to online.
4198 if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns->port)) {
4199 bfa_sm_set_state(ns,
4200 bfa_fcs_lport_ns_sm_sending_gid_ft);
4201 bfa_fcs_lport_ns_send_gid_ft(ns, NULL);
4204 * kick off mgmt srvr state machine
4206 bfa_fcs_lport_ms_online(ns->port);
4207 break;
4209 case NSSM_EVENT_RSP_ERROR:
4211 * Start timer for a delayed retry
4213 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rff_id_retry);
4214 ns->port->stats.ns_retries++;
4215 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4216 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
4217 BFA_FCS_RETRY_TIMEOUT);
4218 break;
4220 case NSSM_EVENT_PORT_OFFLINE:
4221 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4222 bfa_fcxp_discard(ns->fcxp);
4223 break;
4225 default:
4226 bfa_sm_fault(ns->port->fcs, event);
4230 static void
4231 bfa_fcs_lport_ns_sm_rff_id_retry(struct bfa_fcs_lport_ns_s *ns,
4232 enum vport_ns_event event)
4234 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4235 bfa_trc(ns->port->fcs, event);
4237 switch (event) {
4238 case NSSM_EVENT_TIMEOUT:
4239 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rff_id);
4240 bfa_fcs_lport_ns_send_rff_id(ns, NULL);
4241 break;
4243 case NSSM_EVENT_PORT_OFFLINE:
4244 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4245 bfa_timer_stop(&ns->timer);
4246 break;
4248 default:
4249 bfa_sm_fault(ns->port->fcs, event);
4252 static void
4253 bfa_fcs_lport_ns_sm_sending_gid_ft(struct bfa_fcs_lport_ns_s *ns,
4254 enum vport_ns_event event)
4256 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4257 bfa_trc(ns->port->fcs, event);
4259 switch (event) {
4260 case NSSM_EVENT_GIDFT_SENT:
4261 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_gid_ft);
4262 break;
4264 case NSSM_EVENT_PORT_OFFLINE:
4265 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4266 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4267 &ns->fcxp_wqe);
4268 break;
4270 default:
4271 bfa_sm_fault(ns->port->fcs, event);
4275 static void
4276 bfa_fcs_lport_ns_sm_gid_ft(struct bfa_fcs_lport_ns_s *ns,
4277 enum vport_ns_event event)
4279 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4280 bfa_trc(ns->port->fcs, event);
4282 switch (event) {
4283 case NSSM_EVENT_RSP_OK:
4284 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_online);
4285 break;
4287 case NSSM_EVENT_RSP_ERROR:
4289 * TBD: for certain reject codes, we don't need to retry
4292 * Start timer for a delayed retry
4294 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_gid_ft_retry);
4295 ns->port->stats.ns_retries++;
4296 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4297 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
4298 BFA_FCS_RETRY_TIMEOUT);
4299 break;
4301 case NSSM_EVENT_PORT_OFFLINE:
4302 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4303 bfa_fcxp_discard(ns->fcxp);
4304 break;
4306 case NSSM_EVENT_NS_QUERY:
4307 break;
4309 default:
4310 bfa_sm_fault(ns->port->fcs, event);
4314 static void
4315 bfa_fcs_lport_ns_sm_gid_ft_retry(struct bfa_fcs_lport_ns_s *ns,
4316 enum vport_ns_event event)
4318 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4319 bfa_trc(ns->port->fcs, event);
4321 switch (event) {
4322 case NSSM_EVENT_TIMEOUT:
4323 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_gid_ft);
4324 bfa_fcs_lport_ns_send_gid_ft(ns, NULL);
4325 break;
4327 case NSSM_EVENT_PORT_OFFLINE:
4328 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4329 bfa_timer_stop(&ns->timer);
4330 break;
4332 default:
4333 bfa_sm_fault(ns->port->fcs, event);
4337 static void
4338 bfa_fcs_lport_ns_sm_online(struct bfa_fcs_lport_ns_s *ns,
4339 enum vport_ns_event event)
4341 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4342 bfa_trc(ns->port->fcs, event);
4344 switch (event) {
4345 case NSSM_EVENT_PORT_OFFLINE:
4346 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4347 break;
4349 case NSSM_EVENT_NS_QUERY:
4351 * If the port role is Initiator Mode issue NS query.
4352 * If it is Target Mode, skip this and go to online.
4354 if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns->port)) {
4355 bfa_sm_set_state(ns,
4356 bfa_fcs_lport_ns_sm_sending_gid_ft);
4357 bfa_fcs_lport_ns_send_gid_ft(ns, NULL);
4359 break;
4361 default:
4362 bfa_sm_fault(ns->port->fcs, event);
4369 * ns_pvt Nameserver local functions
4372 static void
4373 bfa_fcs_lport_ns_send_plogi(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4375 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4376 struct bfa_fcs_lport_s *port = ns->port;
4377 struct fchs_s fchs;
4378 int len;
4379 struct bfa_fcxp_s *fcxp;
4381 bfa_trc(port->fcs, port->pid);
4383 fcxp = fcxp_alloced ? fcxp_alloced :
4384 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4385 if (!fcxp) {
4386 port->stats.ns_plogi_alloc_wait++;
4387 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4388 bfa_fcs_lport_ns_send_plogi, ns, BFA_TRUE);
4389 return;
4391 ns->fcxp = fcxp;
4393 len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4394 bfa_hton3b(FC_NAME_SERVER),
4395 bfa_fcs_lport_get_fcid(port), 0,
4396 port->port_cfg.pwwn, port->port_cfg.nwwn,
4397 bfa_fcport_get_maxfrsize(port->fcs->bfa),
4398 bfa_fcport_get_rx_bbcredit(port->fcs->bfa));
4400 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4401 FC_CLASS_3, len, &fchs,
4402 bfa_fcs_lport_ns_plogi_response, (void *)ns,
4403 FC_MAX_PDUSZ, FC_ELS_TOV);
4404 port->stats.ns_plogi_sent++;
4406 bfa_sm_send_event(ns, NSSM_EVENT_PLOGI_SENT);
4409 static void
4410 bfa_fcs_lport_ns_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4411 void *cbarg, bfa_status_t req_status, u32 rsp_len,
4412 u32 resid_len, struct fchs_s *rsp_fchs)
4414 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4415 struct bfa_fcs_lport_s *port = ns->port;
4416 /* struct fc_logi_s *plogi_resp; */
4417 struct fc_els_cmd_s *els_cmd;
4418 struct fc_ls_rjt_s *ls_rjt;
4420 bfa_trc(port->fcs, req_status);
4421 bfa_trc(port->fcs, port->port_cfg.pwwn);
4424 * Sanity Checks
4426 if (req_status != BFA_STATUS_OK) {
4427 bfa_trc(port->fcs, req_status);
4428 port->stats.ns_plogi_rsp_err++;
4429 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4430 return;
4433 els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
4435 switch (els_cmd->els_code) {
4437 case FC_ELS_ACC:
4438 if (rsp_len < sizeof(struct fc_logi_s)) {
4439 bfa_trc(port->fcs, rsp_len);
4440 port->stats.ns_plogi_acc_err++;
4441 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4442 break;
4444 port->stats.ns_plogi_accepts++;
4445 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4446 break;
4448 case FC_ELS_LS_RJT:
4449 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
4451 bfa_trc(port->fcs, ls_rjt->reason_code);
4452 bfa_trc(port->fcs, ls_rjt->reason_code_expl);
4454 port->stats.ns_rejects++;
4456 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4457 break;
4459 default:
4460 port->stats.ns_plogi_unknown_rsp++;
4461 bfa_trc(port->fcs, els_cmd->els_code);
4462 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4467 * Register node name for port_id
4469 static void
4470 bfa_fcs_lport_ns_send_rnn_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4472 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4473 struct bfa_fcs_lport_s *port = ns->port;
4474 struct fchs_s fchs;
4475 int len;
4476 struct bfa_fcxp_s *fcxp;
4478 bfa_trc(port->fcs, port->port_cfg.pwwn);
4480 fcxp = fcxp_alloced ? fcxp_alloced :
4481 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4482 if (!fcxp) {
4483 port->stats.ns_rnnid_alloc_wait++;
4484 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4485 bfa_fcs_lport_ns_send_rnn_id, ns, BFA_TRUE);
4486 return;
4489 ns->fcxp = fcxp;
4491 len = fc_rnnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4492 bfa_fcs_lport_get_fcid(port),
4493 bfa_fcs_lport_get_fcid(port),
4494 bfa_fcs_lport_get_nwwn(port));
4496 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4497 FC_CLASS_3, len, &fchs,
4498 bfa_fcs_lport_ns_rnn_id_response, (void *)ns,
4499 FC_MAX_PDUSZ, FC_FCCT_TOV);
4501 port->stats.ns_rnnid_sent++;
4502 bfa_sm_send_event(ns, NSSM_EVENT_RNNID_SENT);
4505 static void
4506 bfa_fcs_lport_ns_rnn_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4507 void *cbarg, bfa_status_t req_status,
4508 u32 rsp_len, u32 resid_len,
4509 struct fchs_s *rsp_fchs)
4512 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4513 struct bfa_fcs_lport_s *port = ns->port;
4514 struct ct_hdr_s *cthdr = NULL;
4516 bfa_trc(port->fcs, port->port_cfg.pwwn);
4519 * Sanity Checks
4521 if (req_status != BFA_STATUS_OK) {
4522 bfa_trc(port->fcs, req_status);
4523 port->stats.ns_rnnid_rsp_err++;
4524 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4525 return;
4528 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4529 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4531 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4532 port->stats.ns_rnnid_accepts++;
4533 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4534 return;
4537 port->stats.ns_rnnid_rejects++;
4538 bfa_trc(port->fcs, cthdr->reason_code);
4539 bfa_trc(port->fcs, cthdr->exp_code);
4540 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4544 * Register the symbolic node name for a given node name.
4546 static void
4547 bfa_fcs_lport_ns_send_rsnn_nn(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4549 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4550 struct bfa_fcs_lport_s *port = ns->port;
4551 struct fchs_s fchs;
4552 int len;
4553 struct bfa_fcxp_s *fcxp;
4554 u8 *nsymbl;
4556 bfa_trc(port->fcs, port->port_cfg.pwwn);
4558 fcxp = fcxp_alloced ? fcxp_alloced :
4559 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4560 if (!fcxp) {
4561 port->stats.ns_rsnn_nn_alloc_wait++;
4562 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4563 bfa_fcs_lport_ns_send_rsnn_nn, ns, BFA_TRUE);
4564 return;
4566 ns->fcxp = fcxp;
4568 nsymbl = (u8 *) &(bfa_fcs_lport_get_nsym_name(
4569 bfa_fcs_get_base_port(port->fcs)));
4571 len = fc_rsnn_nn_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4572 bfa_fcs_lport_get_fcid(port),
4573 bfa_fcs_lport_get_nwwn(port), nsymbl);
4575 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4576 FC_CLASS_3, len, &fchs,
4577 bfa_fcs_lport_ns_rsnn_nn_response, (void *)ns,
4578 FC_MAX_PDUSZ, FC_FCCT_TOV);
4580 port->stats.ns_rsnn_nn_sent++;
4582 bfa_sm_send_event(ns, NSSM_EVENT_RSNN_NN_SENT);
4585 static void
4586 bfa_fcs_lport_ns_rsnn_nn_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4587 void *cbarg, bfa_status_t req_status,
4588 u32 rsp_len, u32 resid_len,
4589 struct fchs_s *rsp_fchs)
4591 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4592 struct bfa_fcs_lport_s *port = ns->port;
4593 struct ct_hdr_s *cthdr = NULL;
4595 bfa_trc(port->fcs, port->port_cfg.pwwn);
4598 * Sanity Checks
4600 if (req_status != BFA_STATUS_OK) {
4601 bfa_trc(port->fcs, req_status);
4602 port->stats.ns_rsnn_nn_rsp_err++;
4603 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4604 return;
4607 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4608 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4610 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4611 port->stats.ns_rsnn_nn_accepts++;
4612 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4613 return;
4616 port->stats.ns_rsnn_nn_rejects++;
4617 bfa_trc(port->fcs, cthdr->reason_code);
4618 bfa_trc(port->fcs, cthdr->exp_code);
4619 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4623 * Register the symbolic port name.
4625 static void
4626 bfa_fcs_lport_ns_send_rspn_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4628 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4629 struct bfa_fcs_lport_s *port = ns->port;
4630 struct fchs_s fchs;
4631 int len;
4632 struct bfa_fcxp_s *fcxp;
4633 u8 symbl[256];
4634 u8 *psymbl = &symbl[0];
4636 memset(symbl, 0, sizeof(symbl));
4638 bfa_trc(port->fcs, port->port_cfg.pwwn);
4640 fcxp = fcxp_alloced ? fcxp_alloced :
4641 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4642 if (!fcxp) {
4643 port->stats.ns_rspnid_alloc_wait++;
4644 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4645 bfa_fcs_lport_ns_send_rspn_id, ns, BFA_TRUE);
4646 return;
4648 ns->fcxp = fcxp;
4651 * for V-Port, form a Port Symbolic Name
4653 if (port->vport) {
4655 * For Vports, we append the vport's port symbolic name
4656 * to that of the base port.
4659 strncpy((char *)psymbl,
4660 (char *) &
4661 (bfa_fcs_lport_get_psym_name
4662 (bfa_fcs_get_base_port(port->fcs))),
4663 strlen((char *) &
4664 bfa_fcs_lport_get_psym_name(bfa_fcs_get_base_port
4665 (port->fcs))));
4667 /* Ensure we have a null terminating string. */
4668 ((char *)psymbl)[strlen((char *) &
4669 bfa_fcs_lport_get_psym_name(bfa_fcs_get_base_port
4670 (port->fcs)))] = 0;
4671 strncat((char *)psymbl,
4672 (char *) &(bfa_fcs_lport_get_psym_name(port)),
4673 strlen((char *) &bfa_fcs_lport_get_psym_name(port)));
4674 } else {
4675 psymbl = (u8 *) &(bfa_fcs_lport_get_psym_name(port));
4678 len = fc_rspnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4679 bfa_fcs_lport_get_fcid(port), 0, psymbl);
4681 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4682 FC_CLASS_3, len, &fchs,
4683 bfa_fcs_lport_ns_rspn_id_response, (void *)ns,
4684 FC_MAX_PDUSZ, FC_FCCT_TOV);
4686 port->stats.ns_rspnid_sent++;
4688 bfa_sm_send_event(ns, NSSM_EVENT_RSPNID_SENT);
4691 static void
4692 bfa_fcs_lport_ns_rspn_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4693 void *cbarg, bfa_status_t req_status,
4694 u32 rsp_len, u32 resid_len,
4695 struct fchs_s *rsp_fchs)
4697 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4698 struct bfa_fcs_lport_s *port = ns->port;
4699 struct ct_hdr_s *cthdr = NULL;
4701 bfa_trc(port->fcs, port->port_cfg.pwwn);
4704 * Sanity Checks
4706 if (req_status != BFA_STATUS_OK) {
4707 bfa_trc(port->fcs, req_status);
4708 port->stats.ns_rspnid_rsp_err++;
4709 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4710 return;
4713 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4714 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4716 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4717 port->stats.ns_rspnid_accepts++;
4718 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4719 return;
4722 port->stats.ns_rspnid_rejects++;
4723 bfa_trc(port->fcs, cthdr->reason_code);
4724 bfa_trc(port->fcs, cthdr->exp_code);
4725 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4729 * Register FC4-Types
4731 static void
4732 bfa_fcs_lport_ns_send_rft_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4734 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4735 struct bfa_fcs_lport_s *port = ns->port;
4736 struct fchs_s fchs;
4737 int len;
4738 struct bfa_fcxp_s *fcxp;
4740 bfa_trc(port->fcs, port->port_cfg.pwwn);
4742 fcxp = fcxp_alloced ? fcxp_alloced :
4743 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4744 if (!fcxp) {
4745 port->stats.ns_rftid_alloc_wait++;
4746 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4747 bfa_fcs_lport_ns_send_rft_id, ns, BFA_TRUE);
4748 return;
4750 ns->fcxp = fcxp;
4752 len = fc_rftid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4753 bfa_fcs_lport_get_fcid(port), 0, port->port_cfg.roles);
4755 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4756 FC_CLASS_3, len, &fchs,
4757 bfa_fcs_lport_ns_rft_id_response, (void *)ns,
4758 FC_MAX_PDUSZ, FC_FCCT_TOV);
4760 port->stats.ns_rftid_sent++;
4761 bfa_sm_send_event(ns, NSSM_EVENT_RFTID_SENT);
4764 static void
4765 bfa_fcs_lport_ns_rft_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4766 void *cbarg, bfa_status_t req_status,
4767 u32 rsp_len, u32 resid_len,
4768 struct fchs_s *rsp_fchs)
4770 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4771 struct bfa_fcs_lport_s *port = ns->port;
4772 struct ct_hdr_s *cthdr = NULL;
4774 bfa_trc(port->fcs, port->port_cfg.pwwn);
4777 * Sanity Checks
4779 if (req_status != BFA_STATUS_OK) {
4780 bfa_trc(port->fcs, req_status);
4781 port->stats.ns_rftid_rsp_err++;
4782 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4783 return;
4786 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4787 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4789 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4790 port->stats.ns_rftid_accepts++;
4791 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4792 return;
4795 port->stats.ns_rftid_rejects++;
4796 bfa_trc(port->fcs, cthdr->reason_code);
4797 bfa_trc(port->fcs, cthdr->exp_code);
4798 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4802 * Register FC4-Features : Should be done after RFT_ID
4804 static void
4805 bfa_fcs_lport_ns_send_rff_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4807 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4808 struct bfa_fcs_lport_s *port = ns->port;
4809 struct fchs_s fchs;
4810 int len;
4811 struct bfa_fcxp_s *fcxp;
4812 u8 fc4_ftrs = 0;
4814 bfa_trc(port->fcs, port->port_cfg.pwwn);
4816 fcxp = fcxp_alloced ? fcxp_alloced :
4817 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4818 if (!fcxp) {
4819 port->stats.ns_rffid_alloc_wait++;
4820 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4821 bfa_fcs_lport_ns_send_rff_id, ns, BFA_TRUE);
4822 return;
4824 ns->fcxp = fcxp;
4826 if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns->port))
4827 fc4_ftrs = FC_GS_FCP_FC4_FEATURE_INITIATOR;
4829 len = fc_rffid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4830 bfa_fcs_lport_get_fcid(port), 0,
4831 FC_TYPE_FCP, fc4_ftrs);
4833 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4834 FC_CLASS_3, len, &fchs,
4835 bfa_fcs_lport_ns_rff_id_response, (void *)ns,
4836 FC_MAX_PDUSZ, FC_FCCT_TOV);
4838 port->stats.ns_rffid_sent++;
4839 bfa_sm_send_event(ns, NSSM_EVENT_RFFID_SENT);
4842 static void
4843 bfa_fcs_lport_ns_rff_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4844 void *cbarg, bfa_status_t req_status,
4845 u32 rsp_len, u32 resid_len,
4846 struct fchs_s *rsp_fchs)
4848 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4849 struct bfa_fcs_lport_s *port = ns->port;
4850 struct ct_hdr_s *cthdr = NULL;
4852 bfa_trc(port->fcs, port->port_cfg.pwwn);
4855 * Sanity Checks
4857 if (req_status != BFA_STATUS_OK) {
4858 bfa_trc(port->fcs, req_status);
4859 port->stats.ns_rffid_rsp_err++;
4860 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4861 return;
4864 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4865 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4867 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4868 port->stats.ns_rffid_accepts++;
4869 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4870 return;
4873 port->stats.ns_rffid_rejects++;
4874 bfa_trc(port->fcs, cthdr->reason_code);
4875 bfa_trc(port->fcs, cthdr->exp_code);
4877 if (cthdr->reason_code == CT_RSN_NOT_SUPP) {
4878 /* if this command is not supported, we don't retry */
4879 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4880 } else
4881 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4884 * Query Fabric for FC4-Types Devices.
4886 * TBD : Need to use a local (FCS private) response buffer, since the response
4887 * can be larger than 2K.
4889 static void
4890 bfa_fcs_lport_ns_send_gid_ft(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4892 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4893 struct bfa_fcs_lport_s *port = ns->port;
4894 struct fchs_s fchs;
4895 int len;
4896 struct bfa_fcxp_s *fcxp;
4898 bfa_trc(port->fcs, port->pid);
4900 fcxp = fcxp_alloced ? fcxp_alloced :
4901 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4902 if (!fcxp) {
4903 port->stats.ns_gidft_alloc_wait++;
4904 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4905 bfa_fcs_lport_ns_send_gid_ft, ns, BFA_TRUE);
4906 return;
4908 ns->fcxp = fcxp;
4911 * This query is only initiated for FCP initiator mode.
4913 len = fc_gid_ft_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4914 ns->port->pid, FC_TYPE_FCP);
4916 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4917 FC_CLASS_3, len, &fchs,
4918 bfa_fcs_lport_ns_gid_ft_response, (void *)ns,
4919 bfa_fcxp_get_maxrsp(port->fcs->bfa), FC_FCCT_TOV);
4921 port->stats.ns_gidft_sent++;
4923 bfa_sm_send_event(ns, NSSM_EVENT_GIDFT_SENT);
4926 static void
4927 bfa_fcs_lport_ns_gid_ft_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4928 void *cbarg, bfa_status_t req_status,
4929 u32 rsp_len, u32 resid_len,
4930 struct fchs_s *rsp_fchs)
4932 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4933 struct bfa_fcs_lport_s *port = ns->port;
4934 struct ct_hdr_s *cthdr = NULL;
4935 u32 n_pids;
4937 bfa_trc(port->fcs, port->port_cfg.pwwn);
4940 * Sanity Checks
4942 if (req_status != BFA_STATUS_OK) {
4943 bfa_trc(port->fcs, req_status);
4944 port->stats.ns_gidft_rsp_err++;
4945 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4946 return;
4949 if (resid_len != 0) {
4951 * TBD : we will need to allocate a larger buffer & retry the
4952 * command
4954 bfa_trc(port->fcs, rsp_len);
4955 bfa_trc(port->fcs, resid_len);
4956 return;
4959 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4960 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4962 switch (cthdr->cmd_rsp_code) {
4964 case CT_RSP_ACCEPT:
4966 port->stats.ns_gidft_accepts++;
4967 n_pids = (fc_get_ctresp_pyld_len(rsp_len) / sizeof(u32));
4968 bfa_trc(port->fcs, n_pids);
4969 bfa_fcs_lport_ns_process_gidft_pids(port,
4970 (u32 *) (cthdr + 1),
4971 n_pids);
4972 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4973 break;
4975 case CT_RSP_REJECT:
4978 * Check the reason code & explanation.
4979 * There may not have been any FC4 devices in the fabric
4981 port->stats.ns_gidft_rejects++;
4982 bfa_trc(port->fcs, cthdr->reason_code);
4983 bfa_trc(port->fcs, cthdr->exp_code);
4985 if ((cthdr->reason_code == CT_RSN_UNABLE_TO_PERF)
4986 && (cthdr->exp_code == CT_NS_EXP_FT_NOT_REG)) {
4988 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4989 } else {
4991 * for all other errors, retry
4993 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4995 break;
4997 default:
4998 port->stats.ns_gidft_unknown_rsp++;
4999 bfa_trc(port->fcs, cthdr->cmd_rsp_code);
5000 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
5005 * This routine will be called by bfa_timer on timer timeouts.
5007 * param[in] port - pointer to bfa_fcs_lport_t.
5009 * return
5010 * void
5012 * Special Considerations:
5014 * note
5016 static void
5017 bfa_fcs_lport_ns_timeout(void *arg)
5019 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) arg;
5021 ns->port->stats.ns_timeouts++;
5022 bfa_sm_send_event(ns, NSSM_EVENT_TIMEOUT);
5026 * Process the PID list in GID_FT response
5028 static void
5029 bfa_fcs_lport_ns_process_gidft_pids(struct bfa_fcs_lport_s *port, u32 *pid_buf,
5030 u32 n_pids)
5032 struct fcgs_gidft_resp_s *gidft_entry;
5033 struct bfa_fcs_rport_s *rport;
5034 u32 ii;
5035 struct bfa_fcs_fabric_s *fabric = port->fabric;
5036 struct bfa_fcs_vport_s *vport;
5037 struct list_head *qe;
5038 u8 found = 0;
5040 for (ii = 0; ii < n_pids; ii++) {
5041 gidft_entry = (struct fcgs_gidft_resp_s *) &pid_buf[ii];
5043 if (gidft_entry->pid == port->pid)
5044 continue;
5047 * Ignore PID if it is of base port
5048 * (Avoid vports discovering base port as remote port)
5050 if (gidft_entry->pid == fabric->bport.pid)
5051 continue;
5054 * Ignore PID if it is of vport created on the same base port
5055 * (Avoid vport discovering every other vport created on the
5056 * same port as remote port)
5058 list_for_each(qe, &fabric->vport_q) {
5059 vport = (struct bfa_fcs_vport_s *) qe;
5060 if (vport->lport.pid == gidft_entry->pid)
5061 found = 1;
5064 if (found) {
5065 found = 0;
5066 continue;
5070 * Check if this rport already exists
5072 rport = bfa_fcs_lport_get_rport_by_pid(port, gidft_entry->pid);
5073 if (rport == NULL) {
5075 * this is a new device. create rport
5077 rport = bfa_fcs_rport_create(port, gidft_entry->pid);
5078 } else {
5080 * this rport already exists
5082 bfa_fcs_rport_scn(rport);
5085 bfa_trc(port->fcs, gidft_entry->pid);
5088 * if the last entry bit is set, bail out.
5090 if (gidft_entry->last)
5091 return;
5096 * fcs_ns_public FCS nameserver public interfaces
5100 * Functions called by port/fab.
5101 * These will send relevant Events to the ns state machine.
5103 void
5104 bfa_fcs_lport_ns_init(struct bfa_fcs_lport_s *port)
5106 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
5108 ns->port = port;
5109 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
5112 void
5113 bfa_fcs_lport_ns_offline(struct bfa_fcs_lport_s *port)
5115 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
5117 ns->port = port;
5118 bfa_sm_send_event(ns, NSSM_EVENT_PORT_OFFLINE);
5121 void
5122 bfa_fcs_lport_ns_online(struct bfa_fcs_lport_s *port)
5124 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
5126 ns->port = port;
5127 bfa_sm_send_event(ns, NSSM_EVENT_PORT_ONLINE);
5130 void
5131 bfa_fcs_lport_ns_query(struct bfa_fcs_lport_s *port)
5133 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
5135 bfa_trc(port->fcs, port->pid);
5136 if (bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_online))
5137 bfa_sm_send_event(ns, NSSM_EVENT_NS_QUERY);
5140 static void
5141 bfa_fcs_lport_ns_boot_target_disc(bfa_fcs_lport_t *port)
5144 struct bfa_fcs_rport_s *rport;
5145 u8 nwwns;
5146 wwn_t wwns[BFA_PREBOOT_BOOTLUN_MAX];
5147 int ii;
5149 bfa_iocfc_get_bootwwns(port->fcs->bfa, &nwwns, wwns);
5151 for (ii = 0 ; ii < nwwns; ++ii) {
5152 rport = bfa_fcs_rport_create_by_wwn(port, wwns[ii]);
5153 WARN_ON(!rport);
5157 void
5158 bfa_fcs_lport_ns_util_send_rspn_id(void *cbarg, struct bfa_fcxp_s *fcxp_alloced)
5160 struct bfa_fcs_lport_ns_s *ns = cbarg;
5161 struct bfa_fcs_lport_s *port = ns->port;
5162 struct fchs_s fchs;
5163 struct bfa_fcxp_s *fcxp;
5164 u8 symbl[256];
5165 u8 *psymbl = &symbl[0];
5166 int len;
5168 /* Avoid sending RSPN in the following states. */
5169 if (bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_offline) ||
5170 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi_sending) ||
5171 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi) ||
5172 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi_retry) ||
5173 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_rspn_id_retry))
5174 return;
5176 memset(symbl, 0, sizeof(symbl));
5177 bfa_trc(port->fcs, port->port_cfg.pwwn);
5179 fcxp = fcxp_alloced ? fcxp_alloced :
5180 bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
5181 if (!fcxp) {
5182 port->stats.ns_rspnid_alloc_wait++;
5183 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
5184 bfa_fcs_lport_ns_util_send_rspn_id, ns, BFA_FALSE);
5185 return;
5188 ns->fcxp = fcxp;
5190 if (port->vport) {
5192 * For Vports, we append the vport's port symbolic name
5193 * to that of the base port.
5195 strncpy((char *)psymbl, (char *)&(bfa_fcs_lport_get_psym_name
5196 (bfa_fcs_get_base_port(port->fcs))),
5197 strlen((char *)&bfa_fcs_lport_get_psym_name(
5198 bfa_fcs_get_base_port(port->fcs))));
5200 /* Ensure we have a null terminating string. */
5201 ((char *)psymbl)[strlen((char *)&bfa_fcs_lport_get_psym_name(
5202 bfa_fcs_get_base_port(port->fcs)))] = 0;
5204 strncat((char *)psymbl,
5205 (char *)&(bfa_fcs_lport_get_psym_name(port)),
5206 strlen((char *)&bfa_fcs_lport_get_psym_name(port)));
5209 len = fc_rspnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
5210 bfa_fcs_lport_get_fcid(port), 0, psymbl);
5212 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
5213 FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
5215 port->stats.ns_rspnid_sent++;
5219 * FCS SCN
5222 #define FC_QOS_RSCN_EVENT 0x0c
5223 #define FC_FABRIC_NAME_RSCN_EVENT 0x0d
5226 * forward declarations
5228 static void bfa_fcs_lport_scn_send_scr(void *scn_cbarg,
5229 struct bfa_fcxp_s *fcxp_alloced);
5230 static void bfa_fcs_lport_scn_scr_response(void *fcsarg,
5231 struct bfa_fcxp_s *fcxp,
5232 void *cbarg,
5233 bfa_status_t req_status,
5234 u32 rsp_len,
5235 u32 resid_len,
5236 struct fchs_s *rsp_fchs);
5237 static void bfa_fcs_lport_scn_send_ls_acc(struct bfa_fcs_lport_s *port,
5238 struct fchs_s *rx_fchs);
5239 static void bfa_fcs_lport_scn_timeout(void *arg);
5242 * fcs_scm_sm FCS SCN state machine
5246 * VPort SCN State Machine events
5248 enum port_scn_event {
5249 SCNSM_EVENT_PORT_ONLINE = 1,
5250 SCNSM_EVENT_PORT_OFFLINE = 2,
5251 SCNSM_EVENT_RSP_OK = 3,
5252 SCNSM_EVENT_RSP_ERROR = 4,
5253 SCNSM_EVENT_TIMEOUT = 5,
5254 SCNSM_EVENT_SCR_SENT = 6,
5257 static void bfa_fcs_lport_scn_sm_offline(struct bfa_fcs_lport_scn_s *scn,
5258 enum port_scn_event event);
5259 static void bfa_fcs_lport_scn_sm_sending_scr(
5260 struct bfa_fcs_lport_scn_s *scn,
5261 enum port_scn_event event);
5262 static void bfa_fcs_lport_scn_sm_scr(struct bfa_fcs_lport_scn_s *scn,
5263 enum port_scn_event event);
5264 static void bfa_fcs_lport_scn_sm_scr_retry(struct bfa_fcs_lport_scn_s *scn,
5265 enum port_scn_event event);
5266 static void bfa_fcs_lport_scn_sm_online(struct bfa_fcs_lport_scn_s *scn,
5267 enum port_scn_event event);
5270 * Starting state - awaiting link up.
5272 static void
5273 bfa_fcs_lport_scn_sm_offline(struct bfa_fcs_lport_scn_s *scn,
5274 enum port_scn_event event)
5276 switch (event) {
5277 case SCNSM_EVENT_PORT_ONLINE:
5278 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_sending_scr);
5279 bfa_fcs_lport_scn_send_scr(scn, NULL);
5280 break;
5282 case SCNSM_EVENT_PORT_OFFLINE:
5283 break;
5285 default:
5286 bfa_sm_fault(scn->port->fcs, event);
5290 static void
5291 bfa_fcs_lport_scn_sm_sending_scr(struct bfa_fcs_lport_scn_s *scn,
5292 enum port_scn_event event)
5294 switch (event) {
5295 case SCNSM_EVENT_SCR_SENT:
5296 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_scr);
5297 break;
5299 case SCNSM_EVENT_PORT_OFFLINE:
5300 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5301 bfa_fcxp_walloc_cancel(scn->port->fcs->bfa, &scn->fcxp_wqe);
5302 break;
5304 default:
5305 bfa_sm_fault(scn->port->fcs, event);
5309 static void
5310 bfa_fcs_lport_scn_sm_scr(struct bfa_fcs_lport_scn_s *scn,
5311 enum port_scn_event event)
5313 struct bfa_fcs_lport_s *port = scn->port;
5315 switch (event) {
5316 case SCNSM_EVENT_RSP_OK:
5317 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_online);
5318 break;
5320 case SCNSM_EVENT_RSP_ERROR:
5321 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_scr_retry);
5322 bfa_timer_start(port->fcs->bfa, &scn->timer,
5323 bfa_fcs_lport_scn_timeout, scn,
5324 BFA_FCS_RETRY_TIMEOUT);
5325 break;
5327 case SCNSM_EVENT_PORT_OFFLINE:
5328 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5329 bfa_fcxp_discard(scn->fcxp);
5330 break;
5332 default:
5333 bfa_sm_fault(port->fcs, event);
5337 static void
5338 bfa_fcs_lport_scn_sm_scr_retry(struct bfa_fcs_lport_scn_s *scn,
5339 enum port_scn_event event)
5341 switch (event) {
5342 case SCNSM_EVENT_TIMEOUT:
5343 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_sending_scr);
5344 bfa_fcs_lport_scn_send_scr(scn, NULL);
5345 break;
5347 case SCNSM_EVENT_PORT_OFFLINE:
5348 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5349 bfa_timer_stop(&scn->timer);
5350 break;
5352 default:
5353 bfa_sm_fault(scn->port->fcs, event);
5357 static void
5358 bfa_fcs_lport_scn_sm_online(struct bfa_fcs_lport_scn_s *scn,
5359 enum port_scn_event event)
5361 switch (event) {
5362 case SCNSM_EVENT_PORT_OFFLINE:
5363 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5364 break;
5366 default:
5367 bfa_sm_fault(scn->port->fcs, event);
5374 * fcs_scn_private FCS SCN private functions
5378 * This routine will be called to send a SCR command.
5380 static void
5381 bfa_fcs_lport_scn_send_scr(void *scn_cbarg, struct bfa_fcxp_s *fcxp_alloced)
5383 struct bfa_fcs_lport_scn_s *scn = scn_cbarg;
5384 struct bfa_fcs_lport_s *port = scn->port;
5385 struct fchs_s fchs;
5386 int len;
5387 struct bfa_fcxp_s *fcxp;
5389 bfa_trc(port->fcs, port->pid);
5390 bfa_trc(port->fcs, port->port_cfg.pwwn);
5392 fcxp = fcxp_alloced ? fcxp_alloced :
5393 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
5394 if (!fcxp) {
5395 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &scn->fcxp_wqe,
5396 bfa_fcs_lport_scn_send_scr, scn, BFA_TRUE);
5397 return;
5399 scn->fcxp = fcxp;
5401 /* Handle VU registrations for Base port only */
5402 if ((!port->vport) && bfa_ioc_get_fcmode(&port->fcs->bfa->ioc)) {
5403 len = fc_scr_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
5404 port->fabric->lps->brcd_switch,
5405 port->pid, 0);
5406 } else {
5407 len = fc_scr_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
5408 BFA_FALSE,
5409 port->pid, 0);
5412 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
5413 FC_CLASS_3, len, &fchs,
5414 bfa_fcs_lport_scn_scr_response,
5415 (void *)scn, FC_MAX_PDUSZ, FC_ELS_TOV);
5417 bfa_sm_send_event(scn, SCNSM_EVENT_SCR_SENT);
5420 static void
5421 bfa_fcs_lport_scn_scr_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
5422 void *cbarg, bfa_status_t req_status, u32 rsp_len,
5423 u32 resid_len, struct fchs_s *rsp_fchs)
5425 struct bfa_fcs_lport_scn_s *scn = (struct bfa_fcs_lport_scn_s *) cbarg;
5426 struct bfa_fcs_lport_s *port = scn->port;
5427 struct fc_els_cmd_s *els_cmd;
5428 struct fc_ls_rjt_s *ls_rjt;
5430 bfa_trc(port->fcs, port->port_cfg.pwwn);
5433 * Sanity Checks
5435 if (req_status != BFA_STATUS_OK) {
5436 bfa_trc(port->fcs, req_status);
5437 bfa_sm_send_event(scn, SCNSM_EVENT_RSP_ERROR);
5438 return;
5441 els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
5443 switch (els_cmd->els_code) {
5445 case FC_ELS_ACC:
5446 bfa_sm_send_event(scn, SCNSM_EVENT_RSP_OK);
5447 break;
5449 case FC_ELS_LS_RJT:
5451 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
5453 bfa_trc(port->fcs, ls_rjt->reason_code);
5454 bfa_trc(port->fcs, ls_rjt->reason_code_expl);
5456 bfa_sm_send_event(scn, SCNSM_EVENT_RSP_ERROR);
5457 break;
5459 default:
5460 bfa_sm_send_event(scn, SCNSM_EVENT_RSP_ERROR);
5465 * Send a LS Accept
5467 static void
5468 bfa_fcs_lport_scn_send_ls_acc(struct bfa_fcs_lport_s *port,
5469 struct fchs_s *rx_fchs)
5471 struct fchs_s fchs;
5472 struct bfa_fcxp_s *fcxp;
5473 struct bfa_rport_s *bfa_rport = NULL;
5474 int len;
5476 bfa_trc(port->fcs, rx_fchs->s_id);
5478 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
5479 if (!fcxp)
5480 return;
5482 len = fc_ls_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
5483 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
5484 rx_fchs->ox_id);
5486 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
5487 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
5488 FC_MAX_PDUSZ, 0);
5492 * This routine will be called by bfa_timer on timer timeouts.
5494 * param[in] vport - pointer to bfa_fcs_lport_t.
5495 * param[out] vport_status - pointer to return vport status in
5497 * return
5498 * void
5500 * Special Considerations:
5502 * note
5504 static void
5505 bfa_fcs_lport_scn_timeout(void *arg)
5507 struct bfa_fcs_lport_scn_s *scn = (struct bfa_fcs_lport_scn_s *) arg;
5509 bfa_sm_send_event(scn, SCNSM_EVENT_TIMEOUT);
5515 * fcs_scn_public FCS state change notification public interfaces
5519 * Functions called by port/fab
5521 void
5522 bfa_fcs_lport_scn_init(struct bfa_fcs_lport_s *port)
5524 struct bfa_fcs_lport_scn_s *scn = BFA_FCS_GET_SCN_FROM_PORT(port);
5526 scn->port = port;
5527 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5530 void
5531 bfa_fcs_lport_scn_offline(struct bfa_fcs_lport_s *port)
5533 struct bfa_fcs_lport_scn_s *scn = BFA_FCS_GET_SCN_FROM_PORT(port);
5535 scn->port = port;
5536 bfa_sm_send_event(scn, SCNSM_EVENT_PORT_OFFLINE);
5539 void
5540 bfa_fcs_lport_fab_scn_online(struct bfa_fcs_lport_s *port)
5542 struct bfa_fcs_lport_scn_s *scn = BFA_FCS_GET_SCN_FROM_PORT(port);
5544 scn->port = port;
5545 bfa_sm_send_event(scn, SCNSM_EVENT_PORT_ONLINE);
5548 static void
5549 bfa_fcs_lport_scn_portid_rscn(struct bfa_fcs_lport_s *port, u32 rpid)
5551 struct bfa_fcs_rport_s *rport;
5552 struct bfa_fcs_fabric_s *fabric = port->fabric;
5553 struct bfa_fcs_vport_s *vport;
5554 struct list_head *qe;
5556 bfa_trc(port->fcs, rpid);
5559 * Ignore PID if it is of base port or of vports created on the
5560 * same base port. It is to avoid vports discovering base port or
5561 * other vports created on same base port as remote port
5563 if (rpid == fabric->bport.pid)
5564 return;
5566 list_for_each(qe, &fabric->vport_q) {
5567 vport = (struct bfa_fcs_vport_s *) qe;
5568 if (vport->lport.pid == rpid)
5569 return;
5572 * If this is an unknown device, then it just came online.
5573 * Otherwise let rport handle the RSCN event.
5575 rport = bfa_fcs_lport_get_rport_by_pid(port, rpid);
5576 if (!rport)
5577 rport = bfa_fcs_lport_get_rport_by_old_pid(port, rpid);
5579 if (rport == NULL) {
5581 * If min cfg mode is enabled, we donot need to
5582 * discover any new rports.
5584 if (!__fcs_min_cfg(port->fcs))
5585 rport = bfa_fcs_rport_create(port, rpid);
5586 } else
5587 bfa_fcs_rport_scn(rport);
5591 * rscn format based PID comparison
5593 #define __fc_pid_match(__c0, __c1, __fmt) \
5594 (((__fmt) == FC_RSCN_FORMAT_FABRIC) || \
5595 (((__fmt) == FC_RSCN_FORMAT_DOMAIN) && \
5596 ((__c0)[0] == (__c1)[0])) || \
5597 (((__fmt) == FC_RSCN_FORMAT_AREA) && \
5598 ((__c0)[0] == (__c1)[0]) && \
5599 ((__c0)[1] == (__c1)[1])))
5601 static void
5602 bfa_fcs_lport_scn_multiport_rscn(struct bfa_fcs_lport_s *port,
5603 enum fc_rscn_format format,
5604 u32 rscn_pid)
5606 struct bfa_fcs_rport_s *rport;
5607 struct list_head *qe, *qe_next;
5608 u8 *c0, *c1;
5610 bfa_trc(port->fcs, format);
5611 bfa_trc(port->fcs, rscn_pid);
5613 c0 = (u8 *) &rscn_pid;
5615 list_for_each_safe(qe, qe_next, &port->rport_q) {
5616 rport = (struct bfa_fcs_rport_s *) qe;
5617 c1 = (u8 *) &rport->pid;
5618 if (__fc_pid_match(c0, c1, format))
5619 bfa_fcs_rport_scn(rport);
5624 void
5625 bfa_fcs_lport_scn_process_rscn(struct bfa_fcs_lport_s *port,
5626 struct fchs_s *fchs, u32 len)
5628 struct fc_rscn_pl_s *rscn = (struct fc_rscn_pl_s *) (fchs + 1);
5629 int num_entries;
5630 u32 rscn_pid;
5631 bfa_boolean_t nsquery = BFA_FALSE, found;
5632 int i = 0, j;
5634 num_entries =
5635 (be16_to_cpu(rscn->payldlen) -
5636 sizeof(u32)) / sizeof(rscn->event[0]);
5638 bfa_trc(port->fcs, num_entries);
5640 port->stats.num_rscn++;
5642 bfa_fcs_lport_scn_send_ls_acc(port, fchs);
5644 for (i = 0; i < num_entries; i++) {
5645 rscn_pid = rscn->event[i].portid;
5647 bfa_trc(port->fcs, rscn->event[i].format);
5648 bfa_trc(port->fcs, rscn_pid);
5650 /* check for duplicate entries in the list */
5651 found = BFA_FALSE;
5652 for (j = 0; j < i; j++) {
5653 if (rscn->event[j].portid == rscn_pid) {
5654 found = BFA_TRUE;
5655 break;
5659 /* if found in down the list, pid has been already processed */
5660 if (found) {
5661 bfa_trc(port->fcs, rscn_pid);
5662 continue;
5665 switch (rscn->event[i].format) {
5666 case FC_RSCN_FORMAT_PORTID:
5667 if (rscn->event[i].qualifier == FC_QOS_RSCN_EVENT) {
5669 * Ignore this event.
5670 * f/w would have processed it
5672 bfa_trc(port->fcs, rscn_pid);
5673 } else {
5674 port->stats.num_portid_rscn++;
5675 bfa_fcs_lport_scn_portid_rscn(port, rscn_pid);
5677 break;
5679 case FC_RSCN_FORMAT_FABRIC:
5680 if (rscn->event[i].qualifier ==
5681 FC_FABRIC_NAME_RSCN_EVENT) {
5682 bfa_fcs_lport_ms_fabric_rscn(port);
5683 break;
5685 /* !!!!!!!!! Fall Through !!!!!!!!!!!!! */
5687 case FC_RSCN_FORMAT_AREA:
5688 case FC_RSCN_FORMAT_DOMAIN:
5689 nsquery = BFA_TRUE;
5690 bfa_fcs_lport_scn_multiport_rscn(port,
5691 rscn->event[i].format,
5692 rscn_pid);
5693 break;
5696 default:
5697 WARN_ON(1);
5698 nsquery = BFA_TRUE;
5703 * If any of area, domain or fabric RSCN is received, do a fresh
5704 * discovery to find new devices.
5706 if (nsquery)
5707 bfa_fcs_lport_ns_query(port);
5711 * BFA FCS port
5714 * fcs_port_api BFA FCS port API
5716 struct bfa_fcs_lport_s *
5717 bfa_fcs_get_base_port(struct bfa_fcs_s *fcs)
5719 return &fcs->fabric.bport;
5722 wwn_t
5723 bfa_fcs_lport_get_rport(struct bfa_fcs_lport_s *port, wwn_t wwn, int index,
5724 int nrports, bfa_boolean_t bwwn)
5726 struct list_head *qh, *qe;
5727 struct bfa_fcs_rport_s *rport = NULL;
5728 int i;
5729 struct bfa_fcs_s *fcs;
5731 if (port == NULL || nrports == 0)
5732 return (wwn_t) 0;
5734 fcs = port->fcs;
5735 bfa_trc(fcs, (u32) nrports);
5737 i = 0;
5738 qh = &port->rport_q;
5739 qe = bfa_q_first(qh);
5741 while ((qe != qh) && (i < nrports)) {
5742 rport = (struct bfa_fcs_rport_s *) qe;
5743 if (bfa_ntoh3b(rport->pid) > 0xFFF000) {
5744 qe = bfa_q_next(qe);
5745 bfa_trc(fcs, (u32) rport->pwwn);
5746 bfa_trc(fcs, rport->pid);
5747 bfa_trc(fcs, i);
5748 continue;
5751 if (bwwn) {
5752 if (!memcmp(&wwn, &rport->pwwn, 8))
5753 break;
5754 } else {
5755 if (i == index)
5756 break;
5759 i++;
5760 qe = bfa_q_next(qe);
5763 bfa_trc(fcs, i);
5764 if (rport)
5765 return rport->pwwn;
5766 else
5767 return (wwn_t) 0;
5770 void
5771 bfa_fcs_lport_get_rport_quals(struct bfa_fcs_lport_s *port,
5772 struct bfa_rport_qualifier_s rports[], int *nrports)
5774 struct list_head *qh, *qe;
5775 struct bfa_fcs_rport_s *rport = NULL;
5776 int i;
5777 struct bfa_fcs_s *fcs;
5779 if (port == NULL || rports == NULL || *nrports == 0)
5780 return;
5782 fcs = port->fcs;
5783 bfa_trc(fcs, (u32) *nrports);
5785 i = 0;
5786 qh = &port->rport_q;
5787 qe = bfa_q_first(qh);
5789 while ((qe != qh) && (i < *nrports)) {
5790 rport = (struct bfa_fcs_rport_s *) qe;
5791 if (bfa_ntoh3b(rport->pid) > 0xFFF000) {
5792 qe = bfa_q_next(qe);
5793 bfa_trc(fcs, (u32) rport->pwwn);
5794 bfa_trc(fcs, rport->pid);
5795 bfa_trc(fcs, i);
5796 continue;
5799 if (!rport->pwwn && !rport->pid) {
5800 qe = bfa_q_next(qe);
5801 continue;
5804 rports[i].pwwn = rport->pwwn;
5805 rports[i].pid = rport->pid;
5807 i++;
5808 qe = bfa_q_next(qe);
5811 bfa_trc(fcs, i);
5812 *nrports = i;
5816 * Iterate's through all the rport's in the given port to
5817 * determine the maximum operating speed.
5819 * !!!! To be used in TRL Functionality only !!!!
5821 bfa_port_speed_t
5822 bfa_fcs_lport_get_rport_max_speed(bfa_fcs_lport_t *port)
5824 struct list_head *qh, *qe;
5825 struct bfa_fcs_rport_s *rport = NULL;
5826 struct bfa_fcs_s *fcs;
5827 bfa_port_speed_t max_speed = 0;
5828 struct bfa_port_attr_s port_attr;
5829 bfa_port_speed_t port_speed, rport_speed;
5830 bfa_boolean_t trl_enabled;
5832 if (port == NULL)
5833 return 0;
5835 fcs = port->fcs;
5836 trl_enabled = bfa_fcport_is_ratelim(port->fcs->bfa);
5838 /* Get Physical port's current speed */
5839 bfa_fcport_get_attr(port->fcs->bfa, &port_attr);
5840 port_speed = port_attr.speed;
5841 bfa_trc(fcs, port_speed);
5843 qh = &port->rport_q;
5844 qe = bfa_q_first(qh);
5846 while (qe != qh) {
5847 rport = (struct bfa_fcs_rport_s *) qe;
5848 if ((bfa_ntoh3b(rport->pid) > 0xFFF000) ||
5849 (bfa_fcs_rport_get_state(rport) == BFA_RPORT_OFFLINE) ||
5850 (rport->scsi_function != BFA_RPORT_TARGET)) {
5851 qe = bfa_q_next(qe);
5852 continue;
5855 rport_speed = rport->rpf.rpsc_speed;
5856 if ((trl_enabled) && (rport_speed ==
5857 BFA_PORT_SPEED_UNKNOWN)) {
5858 /* Use default ratelim speed setting */
5859 rport_speed =
5860 bfa_fcport_get_ratelim_speed(port->fcs->bfa);
5863 if (rport_speed > max_speed)
5864 max_speed = rport_speed;
5866 qe = bfa_q_next(qe);
5869 if (max_speed > port_speed)
5870 max_speed = port_speed;
5872 bfa_trc(fcs, max_speed);
5873 return max_speed;
5876 struct bfa_fcs_lport_s *
5877 bfa_fcs_lookup_port(struct bfa_fcs_s *fcs, u16 vf_id, wwn_t lpwwn)
5879 struct bfa_fcs_vport_s *vport;
5880 bfa_fcs_vf_t *vf;
5882 WARN_ON(fcs == NULL);
5884 vf = bfa_fcs_vf_lookup(fcs, vf_id);
5885 if (vf == NULL) {
5886 bfa_trc(fcs, vf_id);
5887 return NULL;
5890 if (!lpwwn || (vf->bport.port_cfg.pwwn == lpwwn))
5891 return &vf->bport;
5893 vport = bfa_fcs_fabric_vport_lookup(vf, lpwwn);
5894 if (vport)
5895 return &vport->lport;
5897 return NULL;
5901 * API corresponding to NPIV_VPORT_GETINFO.
5903 void
5904 bfa_fcs_lport_get_info(struct bfa_fcs_lport_s *port,
5905 struct bfa_lport_info_s *port_info)
5908 bfa_trc(port->fcs, port->fabric->fabric_name);
5910 if (port->vport == NULL) {
5912 * This is a Physical port
5914 port_info->port_type = BFA_LPORT_TYPE_PHYSICAL;
5917 * @todo : need to fix the state & reason
5919 port_info->port_state = 0;
5920 port_info->offline_reason = 0;
5922 port_info->port_wwn = bfa_fcs_lport_get_pwwn(port);
5923 port_info->node_wwn = bfa_fcs_lport_get_nwwn(port);
5925 port_info->max_vports_supp =
5926 bfa_lps_get_max_vport(port->fcs->bfa);
5927 port_info->num_vports_inuse =
5928 port->fabric->num_vports;
5929 port_info->max_rports_supp = BFA_FCS_MAX_RPORTS_SUPP;
5930 port_info->num_rports_inuse = port->num_rports;
5931 } else {
5933 * This is a virtual port
5935 port_info->port_type = BFA_LPORT_TYPE_VIRTUAL;
5938 * @todo : need to fix the state & reason
5940 port_info->port_state = 0;
5941 port_info->offline_reason = 0;
5943 port_info->port_wwn = bfa_fcs_lport_get_pwwn(port);
5944 port_info->node_wwn = bfa_fcs_lport_get_nwwn(port);
5948 void
5949 bfa_fcs_lport_get_stats(struct bfa_fcs_lport_s *fcs_port,
5950 struct bfa_lport_stats_s *port_stats)
5952 *port_stats = fcs_port->stats;
5955 void
5956 bfa_fcs_lport_clear_stats(struct bfa_fcs_lport_s *fcs_port)
5958 memset(&fcs_port->stats, 0, sizeof(struct bfa_lport_stats_s));
5962 * Let new loop map create missing rports
5964 void
5965 bfa_fcs_lport_lip_scn_online(struct bfa_fcs_lport_s *port)
5967 bfa_fcs_lport_loop_online(port);
5971 * FCS virtual port state machine
5974 #define __vport_fcs(__vp) ((__vp)->lport.fcs)
5975 #define __vport_pwwn(__vp) ((__vp)->lport.port_cfg.pwwn)
5976 #define __vport_nwwn(__vp) ((__vp)->lport.port_cfg.nwwn)
5977 #define __vport_bfa(__vp) ((__vp)->lport.fcs->bfa)
5978 #define __vport_fcid(__vp) ((__vp)->lport.pid)
5979 #define __vport_fabric(__vp) ((__vp)->lport.fabric)
5980 #define __vport_vfid(__vp) ((__vp)->lport.fabric->vf_id)
5982 #define BFA_FCS_VPORT_MAX_RETRIES 5
5984 * Forward declarations
5986 static void bfa_fcs_vport_do_fdisc(struct bfa_fcs_vport_s *vport);
5987 static void bfa_fcs_vport_timeout(void *vport_arg);
5988 static void bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s *vport);
5989 static void bfa_fcs_vport_free(struct bfa_fcs_vport_s *vport);
5992 * fcs_vport_sm FCS virtual port state machine
5996 * VPort State Machine events
5998 enum bfa_fcs_vport_event {
5999 BFA_FCS_VPORT_SM_CREATE = 1, /* vport create event */
6000 BFA_FCS_VPORT_SM_DELETE = 2, /* vport delete event */
6001 BFA_FCS_VPORT_SM_START = 3, /* vport start request */
6002 BFA_FCS_VPORT_SM_STOP = 4, /* stop: unsupported */
6003 BFA_FCS_VPORT_SM_ONLINE = 5, /* fabric online */
6004 BFA_FCS_VPORT_SM_OFFLINE = 6, /* fabric offline event */
6005 BFA_FCS_VPORT_SM_FRMSENT = 7, /* fdisc/logo sent events */
6006 BFA_FCS_VPORT_SM_RSP_OK = 8, /* good response */
6007 BFA_FCS_VPORT_SM_RSP_ERROR = 9, /* error/bad response */
6008 BFA_FCS_VPORT_SM_TIMEOUT = 10, /* delay timer event */
6009 BFA_FCS_VPORT_SM_DELCOMP = 11, /* lport delete completion */
6010 BFA_FCS_VPORT_SM_RSP_DUP_WWN = 12, /* Dup wnn error*/
6011 BFA_FCS_VPORT_SM_RSP_FAILED = 13, /* non-retryable failure */
6012 BFA_FCS_VPORT_SM_STOPCOMP = 14, /* vport delete completion */
6013 BFA_FCS_VPORT_SM_FABRIC_MAX = 15, /* max vports on fabric */
6016 static void bfa_fcs_vport_sm_uninit(struct bfa_fcs_vport_s *vport,
6017 enum bfa_fcs_vport_event event);
6018 static void bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s *vport,
6019 enum bfa_fcs_vport_event event);
6020 static void bfa_fcs_vport_sm_offline(struct bfa_fcs_vport_s *vport,
6021 enum bfa_fcs_vport_event event);
6022 static void bfa_fcs_vport_sm_fdisc(struct bfa_fcs_vport_s *vport,
6023 enum bfa_fcs_vport_event event);
6024 static void bfa_fcs_vport_sm_fdisc_retry(struct bfa_fcs_vport_s *vport,
6025 enum bfa_fcs_vport_event event);
6026 static void bfa_fcs_vport_sm_fdisc_rsp_wait(struct bfa_fcs_vport_s *vport,
6027 enum bfa_fcs_vport_event event);
6028 static void bfa_fcs_vport_sm_online(struct bfa_fcs_vport_s *vport,
6029 enum bfa_fcs_vport_event event);
6030 static void bfa_fcs_vport_sm_deleting(struct bfa_fcs_vport_s *vport,
6031 enum bfa_fcs_vport_event event);
6032 static void bfa_fcs_vport_sm_cleanup(struct bfa_fcs_vport_s *vport,
6033 enum bfa_fcs_vport_event event);
6034 static void bfa_fcs_vport_sm_logo(struct bfa_fcs_vport_s *vport,
6035 enum bfa_fcs_vport_event event);
6036 static void bfa_fcs_vport_sm_error(struct bfa_fcs_vport_s *vport,
6037 enum bfa_fcs_vport_event event);
6038 static void bfa_fcs_vport_sm_stopping(struct bfa_fcs_vport_s *vport,
6039 enum bfa_fcs_vport_event event);
6040 static void bfa_fcs_vport_sm_logo_for_stop(struct bfa_fcs_vport_s *vport,
6041 enum bfa_fcs_vport_event event);
6043 static struct bfa_sm_table_s vport_sm_table[] = {
6044 {BFA_SM(bfa_fcs_vport_sm_uninit), BFA_FCS_VPORT_UNINIT},
6045 {BFA_SM(bfa_fcs_vport_sm_created), BFA_FCS_VPORT_CREATED},
6046 {BFA_SM(bfa_fcs_vport_sm_offline), BFA_FCS_VPORT_OFFLINE},
6047 {BFA_SM(bfa_fcs_vport_sm_fdisc), BFA_FCS_VPORT_FDISC},
6048 {BFA_SM(bfa_fcs_vport_sm_fdisc_retry), BFA_FCS_VPORT_FDISC_RETRY},
6049 {BFA_SM(bfa_fcs_vport_sm_fdisc_rsp_wait), BFA_FCS_VPORT_FDISC_RSP_WAIT},
6050 {BFA_SM(bfa_fcs_vport_sm_online), BFA_FCS_VPORT_ONLINE},
6051 {BFA_SM(bfa_fcs_vport_sm_deleting), BFA_FCS_VPORT_DELETING},
6052 {BFA_SM(bfa_fcs_vport_sm_cleanup), BFA_FCS_VPORT_CLEANUP},
6053 {BFA_SM(bfa_fcs_vport_sm_logo), BFA_FCS_VPORT_LOGO},
6054 {BFA_SM(bfa_fcs_vport_sm_error), BFA_FCS_VPORT_ERROR}
6058 * Beginning state.
6060 static void
6061 bfa_fcs_vport_sm_uninit(struct bfa_fcs_vport_s *vport,
6062 enum bfa_fcs_vport_event event)
6064 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6065 bfa_trc(__vport_fcs(vport), event);
6067 switch (event) {
6068 case BFA_FCS_VPORT_SM_CREATE:
6069 bfa_sm_set_state(vport, bfa_fcs_vport_sm_created);
6070 bfa_fcs_fabric_addvport(__vport_fabric(vport), vport);
6071 break;
6073 default:
6074 bfa_sm_fault(__vport_fcs(vport), event);
6079 * Created state - a start event is required to start up the state machine.
6081 static void
6082 bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s *vport,
6083 enum bfa_fcs_vport_event event)
6085 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6086 bfa_trc(__vport_fcs(vport), event);
6088 switch (event) {
6089 case BFA_FCS_VPORT_SM_START:
6090 if (bfa_sm_cmp_state(__vport_fabric(vport),
6091 bfa_fcs_fabric_sm_online)
6092 && bfa_fcs_fabric_npiv_capable(__vport_fabric(vport))) {
6093 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
6094 bfa_fcs_vport_do_fdisc(vport);
6095 } else {
6097 * Fabric is offline or not NPIV capable, stay in
6098 * offline state.
6100 vport->vport_stats.fab_no_npiv++;
6101 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
6103 break;
6105 case BFA_FCS_VPORT_SM_DELETE:
6106 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6107 bfa_fcs_lport_delete(&vport->lport);
6108 break;
6110 case BFA_FCS_VPORT_SM_ONLINE:
6111 case BFA_FCS_VPORT_SM_OFFLINE:
6113 * Ignore ONLINE/OFFLINE events from fabric
6114 * till vport is started.
6116 break;
6118 default:
6119 bfa_sm_fault(__vport_fcs(vport), event);
6124 * Offline state - awaiting ONLINE event from fabric SM.
6126 static void
6127 bfa_fcs_vport_sm_offline(struct bfa_fcs_vport_s *vport,
6128 enum bfa_fcs_vport_event event)
6130 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6131 bfa_trc(__vport_fcs(vport), event);
6133 switch (event) {
6134 case BFA_FCS_VPORT_SM_DELETE:
6135 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6136 bfa_fcs_lport_delete(&vport->lport);
6137 break;
6139 case BFA_FCS_VPORT_SM_ONLINE:
6140 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
6141 vport->fdisc_retries = 0;
6142 bfa_fcs_vport_do_fdisc(vport);
6143 break;
6145 case BFA_FCS_VPORT_SM_STOP:
6146 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6147 bfa_sm_send_event(&vport->lport, BFA_FCS_PORT_SM_STOP);
6148 break;
6150 case BFA_FCS_VPORT_SM_OFFLINE:
6152 * This can happen if the vport couldn't be initialzied
6153 * due the fact that the npiv was not enabled on the switch.
6154 * In that case we will put the vport in offline state.
6155 * However, the link can go down and cause the this event to
6156 * be sent when we are already offline. Ignore it.
6158 break;
6160 default:
6161 bfa_sm_fault(__vport_fcs(vport), event);
6167 * FDISC is sent and awaiting reply from fabric.
6169 static void
6170 bfa_fcs_vport_sm_fdisc(struct bfa_fcs_vport_s *vport,
6171 enum bfa_fcs_vport_event event)
6173 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6174 bfa_trc(__vport_fcs(vport), event);
6176 switch (event) {
6177 case BFA_FCS_VPORT_SM_DELETE:
6178 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc_rsp_wait);
6179 break;
6181 case BFA_FCS_VPORT_SM_OFFLINE:
6182 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
6183 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
6184 break;
6186 case BFA_FCS_VPORT_SM_RSP_OK:
6187 bfa_sm_set_state(vport, bfa_fcs_vport_sm_online);
6188 bfa_fcs_lport_online(&vport->lport);
6189 break;
6191 case BFA_FCS_VPORT_SM_RSP_ERROR:
6192 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc_retry);
6193 bfa_timer_start(__vport_bfa(vport), &vport->timer,
6194 bfa_fcs_vport_timeout, vport,
6195 BFA_FCS_RETRY_TIMEOUT);
6196 break;
6198 case BFA_FCS_VPORT_SM_RSP_FAILED:
6199 case BFA_FCS_VPORT_SM_FABRIC_MAX:
6200 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
6201 break;
6203 case BFA_FCS_VPORT_SM_RSP_DUP_WWN:
6204 bfa_sm_set_state(vport, bfa_fcs_vport_sm_error);
6205 break;
6207 default:
6208 bfa_sm_fault(__vport_fcs(vport), event);
6213 * FDISC attempt failed - a timer is active to retry FDISC.
6215 static void
6216 bfa_fcs_vport_sm_fdisc_retry(struct bfa_fcs_vport_s *vport,
6217 enum bfa_fcs_vport_event event)
6219 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6220 bfa_trc(__vport_fcs(vport), event);
6222 switch (event) {
6223 case BFA_FCS_VPORT_SM_DELETE:
6224 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6225 bfa_timer_stop(&vport->timer);
6226 bfa_fcs_lport_delete(&vport->lport);
6227 break;
6229 case BFA_FCS_VPORT_SM_OFFLINE:
6230 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
6231 bfa_timer_stop(&vport->timer);
6232 break;
6234 case BFA_FCS_VPORT_SM_TIMEOUT:
6235 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
6236 vport->vport_stats.fdisc_retries++;
6237 vport->fdisc_retries++;
6238 bfa_fcs_vport_do_fdisc(vport);
6239 break;
6241 default:
6242 bfa_sm_fault(__vport_fcs(vport), event);
6247 * FDISC is in progress and we got a vport delete request -
6248 * this is a wait state while we wait for fdisc response and
6249 * we will transition to the appropriate state - on rsp status.
6251 static void
6252 bfa_fcs_vport_sm_fdisc_rsp_wait(struct bfa_fcs_vport_s *vport,
6253 enum bfa_fcs_vport_event event)
6255 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6256 bfa_trc(__vport_fcs(vport), event);
6258 switch (event) {
6259 case BFA_FCS_VPORT_SM_RSP_OK:
6260 bfa_sm_set_state(vport, bfa_fcs_vport_sm_deleting);
6261 bfa_fcs_lport_delete(&vport->lport);
6262 break;
6264 case BFA_FCS_VPORT_SM_DELETE:
6265 break;
6267 case BFA_FCS_VPORT_SM_OFFLINE:
6268 case BFA_FCS_VPORT_SM_RSP_ERROR:
6269 case BFA_FCS_VPORT_SM_RSP_FAILED:
6270 case BFA_FCS_VPORT_SM_FABRIC_MAX:
6271 case BFA_FCS_VPORT_SM_RSP_DUP_WWN:
6272 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6273 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
6274 bfa_fcs_lport_delete(&vport->lport);
6275 break;
6277 default:
6278 bfa_sm_fault(__vport_fcs(vport), event);
6283 * Vport is online (FDISC is complete).
6285 static void
6286 bfa_fcs_vport_sm_online(struct bfa_fcs_vport_s *vport,
6287 enum bfa_fcs_vport_event event)
6289 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6290 bfa_trc(__vport_fcs(vport), event);
6292 switch (event) {
6293 case BFA_FCS_VPORT_SM_DELETE:
6294 bfa_sm_set_state(vport, bfa_fcs_vport_sm_deleting);
6295 bfa_fcs_lport_delete(&vport->lport);
6296 break;
6298 case BFA_FCS_VPORT_SM_STOP:
6299 bfa_sm_set_state(vport, bfa_fcs_vport_sm_stopping);
6300 bfa_sm_send_event(&vport->lport, BFA_FCS_PORT_SM_STOP);
6301 break;
6303 case BFA_FCS_VPORT_SM_OFFLINE:
6304 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
6305 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
6306 bfa_fcs_lport_offline(&vport->lport);
6307 break;
6309 default:
6310 bfa_sm_fault(__vport_fcs(vport), event);
6315 * Vport is being stopped - awaiting lport stop completion to send
6316 * LOGO to fabric.
6318 static void
6319 bfa_fcs_vport_sm_stopping(struct bfa_fcs_vport_s *vport,
6320 enum bfa_fcs_vport_event event)
6322 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6323 bfa_trc(__vport_fcs(vport), event);
6325 switch (event) {
6326 case BFA_FCS_VPORT_SM_STOPCOMP:
6327 bfa_sm_set_state(vport, bfa_fcs_vport_sm_logo_for_stop);
6328 bfa_fcs_vport_do_logo(vport);
6329 break;
6331 case BFA_FCS_VPORT_SM_OFFLINE:
6332 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6333 break;
6335 default:
6336 bfa_sm_fault(__vport_fcs(vport), event);
6341 * Vport is being deleted - awaiting lport delete completion to send
6342 * LOGO to fabric.
6344 static void
6345 bfa_fcs_vport_sm_deleting(struct bfa_fcs_vport_s *vport,
6346 enum bfa_fcs_vport_event event)
6348 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6349 bfa_trc(__vport_fcs(vport), event);
6351 switch (event) {
6352 case BFA_FCS_VPORT_SM_DELETE:
6353 break;
6355 case BFA_FCS_VPORT_SM_DELCOMP:
6356 bfa_sm_set_state(vport, bfa_fcs_vport_sm_logo);
6357 bfa_fcs_vport_do_logo(vport);
6358 break;
6360 case BFA_FCS_VPORT_SM_OFFLINE:
6361 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6362 break;
6364 default:
6365 bfa_sm_fault(__vport_fcs(vport), event);
6370 * Error State.
6371 * This state will be set when the Vport Creation fails due
6372 * to errors like Dup WWN. In this state only operation allowed
6373 * is a Vport Delete.
6375 static void
6376 bfa_fcs_vport_sm_error(struct bfa_fcs_vport_s *vport,
6377 enum bfa_fcs_vport_event event)
6379 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6380 bfa_trc(__vport_fcs(vport), event);
6382 switch (event) {
6383 case BFA_FCS_VPORT_SM_DELETE:
6384 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6385 bfa_fcs_lport_delete(&vport->lport);
6386 break;
6388 default:
6389 bfa_trc(__vport_fcs(vport), event);
6394 * Lport cleanup is in progress since vport is being deleted. Fabric is
6395 * offline, so no LOGO is needed to complete vport deletion.
6397 static void
6398 bfa_fcs_vport_sm_cleanup(struct bfa_fcs_vport_s *vport,
6399 enum bfa_fcs_vport_event event)
6401 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6402 bfa_trc(__vport_fcs(vport), event);
6404 switch (event) {
6405 case BFA_FCS_VPORT_SM_DELCOMP:
6406 bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
6407 bfa_fcs_vport_free(vport);
6408 break;
6410 case BFA_FCS_VPORT_SM_STOPCOMP:
6411 bfa_sm_set_state(vport, bfa_fcs_vport_sm_created);
6412 break;
6414 case BFA_FCS_VPORT_SM_DELETE:
6415 break;
6417 default:
6418 bfa_sm_fault(__vport_fcs(vport), event);
6423 * LOGO is sent to fabric. Vport stop is in progress. Lport stop cleanup
6424 * is done.
6426 static void
6427 bfa_fcs_vport_sm_logo_for_stop(struct bfa_fcs_vport_s *vport,
6428 enum bfa_fcs_vport_event event)
6430 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6431 bfa_trc(__vport_fcs(vport), event);
6433 switch (event) {
6434 case BFA_FCS_VPORT_SM_OFFLINE:
6435 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
6437 * !!! fall through !!!
6440 case BFA_FCS_VPORT_SM_RSP_OK:
6441 case BFA_FCS_VPORT_SM_RSP_ERROR:
6442 bfa_sm_set_state(vport, bfa_fcs_vport_sm_created);
6443 break;
6445 default:
6446 bfa_sm_fault(__vport_fcs(vport), event);
6451 * LOGO is sent to fabric. Vport delete is in progress. Lport delete cleanup
6452 * is done.
6454 static void
6455 bfa_fcs_vport_sm_logo(struct bfa_fcs_vport_s *vport,
6456 enum bfa_fcs_vport_event event)
6458 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6459 bfa_trc(__vport_fcs(vport), event);
6461 switch (event) {
6462 case BFA_FCS_VPORT_SM_OFFLINE:
6463 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
6465 * !!! fall through !!!
6468 case BFA_FCS_VPORT_SM_RSP_OK:
6469 case BFA_FCS_VPORT_SM_RSP_ERROR:
6470 bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
6471 bfa_fcs_vport_free(vport);
6472 break;
6474 case BFA_FCS_VPORT_SM_DELETE:
6475 break;
6477 default:
6478 bfa_sm_fault(__vport_fcs(vport), event);
6485 * fcs_vport_private FCS virtual port private functions
6488 * Send AEN notification
6490 static void
6491 bfa_fcs_vport_aen_post(struct bfa_fcs_lport_s *port,
6492 enum bfa_lport_aen_event event)
6494 struct bfad_s *bfad = (struct bfad_s *)port->fabric->fcs->bfad;
6495 struct bfa_aen_entry_s *aen_entry;
6497 bfad_get_aen_entry(bfad, aen_entry);
6498 if (!aen_entry)
6499 return;
6501 aen_entry->aen_data.lport.vf_id = port->fabric->vf_id;
6502 aen_entry->aen_data.lport.roles = port->port_cfg.roles;
6503 aen_entry->aen_data.lport.ppwwn = bfa_fcs_lport_get_pwwn(
6504 bfa_fcs_get_base_port(port->fcs));
6505 aen_entry->aen_data.lport.lpwwn = bfa_fcs_lport_get_pwwn(port);
6507 /* Send the AEN notification */
6508 bfad_im_post_vendor_event(aen_entry, bfad, ++port->fcs->fcs_aen_seq,
6509 BFA_AEN_CAT_LPORT, event);
6513 * This routine will be called to send a FDISC command.
6515 static void
6516 bfa_fcs_vport_do_fdisc(struct bfa_fcs_vport_s *vport)
6518 bfa_lps_fdisc(vport->lps, vport,
6519 bfa_fcport_get_maxfrsize(__vport_bfa(vport)),
6520 __vport_pwwn(vport), __vport_nwwn(vport));
6521 vport->vport_stats.fdisc_sent++;
6524 static void
6525 bfa_fcs_vport_fdisc_rejected(struct bfa_fcs_vport_s *vport)
6527 u8 lsrjt_rsn = vport->lps->lsrjt_rsn;
6528 u8 lsrjt_expl = vport->lps->lsrjt_expl;
6530 bfa_trc(__vport_fcs(vport), lsrjt_rsn);
6531 bfa_trc(__vport_fcs(vport), lsrjt_expl);
6533 /* For certain reason codes, we don't want to retry. */
6534 switch (vport->lps->lsrjt_expl) {
6535 case FC_LS_RJT_EXP_INV_PORT_NAME: /* by brocade */
6536 case FC_LS_RJT_EXP_INVALID_NPORT_ID: /* by Cisco */
6537 if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
6538 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6539 else {
6540 bfa_fcs_vport_aen_post(&vport->lport,
6541 BFA_LPORT_AEN_NPIV_DUP_WWN);
6542 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_DUP_WWN);
6544 break;
6546 case FC_LS_RJT_EXP_INSUFF_RES:
6548 * This means max logins per port/switch setting on the
6549 * switch was exceeded.
6551 if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
6552 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6553 else {
6554 bfa_fcs_vport_aen_post(&vport->lport,
6555 BFA_LPORT_AEN_NPIV_FABRIC_MAX);
6556 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_FABRIC_MAX);
6558 break;
6560 default:
6561 if (vport->fdisc_retries == 0)
6562 bfa_fcs_vport_aen_post(&vport->lport,
6563 BFA_LPORT_AEN_NPIV_UNKNOWN);
6564 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6569 * Called to send a logout to the fabric. Used when a V-Port is
6570 * deleted/stopped.
6572 static void
6573 bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s *vport)
6575 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6577 vport->vport_stats.logo_sent++;
6578 bfa_lps_fdisclogo(vport->lps);
6583 * This routine will be called by bfa_timer on timer timeouts.
6585 * param[in] vport - pointer to bfa_fcs_vport_t.
6586 * param[out] vport_status - pointer to return vport status in
6588 * return
6589 * void
6591 * Special Considerations:
6593 * note
6595 static void
6596 bfa_fcs_vport_timeout(void *vport_arg)
6598 struct bfa_fcs_vport_s *vport = (struct bfa_fcs_vport_s *) vport_arg;
6600 vport->vport_stats.fdisc_timeouts++;
6601 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_TIMEOUT);
6604 static void
6605 bfa_fcs_vport_free(struct bfa_fcs_vport_s *vport)
6607 struct bfad_vport_s *vport_drv =
6608 (struct bfad_vport_s *)vport->vport_drv;
6610 bfa_fcs_fabric_delvport(__vport_fabric(vport), vport);
6611 bfa_lps_delete(vport->lps);
6613 if (vport_drv->comp_del) {
6614 complete(vport_drv->comp_del);
6615 return;
6619 * We queue the vport delete work to the IM work_q from here.
6620 * The memory for the bfad_vport_s is freed from the FC function
6621 * template vport_delete entry point.
6623 bfad_im_port_delete(vport_drv->drv_port.bfad, &vport_drv->drv_port);
6627 * fcs_vport_public FCS virtual port public interfaces
6631 * Online notification from fabric SM.
6633 void
6634 bfa_fcs_vport_online(struct bfa_fcs_vport_s *vport)
6636 vport->vport_stats.fab_online++;
6637 if (bfa_fcs_fabric_npiv_capable(__vport_fabric(vport)))
6638 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_ONLINE);
6639 else
6640 vport->vport_stats.fab_no_npiv++;
6644 * Offline notification from fabric SM.
6646 void
6647 bfa_fcs_vport_offline(struct bfa_fcs_vport_s *vport)
6649 vport->vport_stats.fab_offline++;
6650 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_OFFLINE);
6654 * Cleanup notification from fabric SM on link timer expiry.
6656 void
6657 bfa_fcs_vport_cleanup(struct bfa_fcs_vport_s *vport)
6659 vport->vport_stats.fab_cleanup++;
6663 * Stop notification from fabric SM. To be invoked from within FCS.
6665 void
6666 bfa_fcs_vport_fcs_stop(struct bfa_fcs_vport_s *vport)
6668 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOP);
6672 * delete notification from fabric SM. To be invoked from within FCS.
6674 void
6675 bfa_fcs_vport_fcs_delete(struct bfa_fcs_vport_s *vport)
6677 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELETE);
6681 * Stop completion callback from associated lport
6683 void
6684 bfa_fcs_vport_stop_comp(struct bfa_fcs_vport_s *vport)
6686 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOPCOMP);
6690 * Delete completion callback from associated lport
6692 void
6693 bfa_fcs_vport_delete_comp(struct bfa_fcs_vport_s *vport)
6695 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELCOMP);
6701 * fcs_vport_api Virtual port API
6705 * Use this function to instantiate a new FCS vport object. This
6706 * function will not trigger any HW initialization process (which will be
6707 * done in vport_start() call)
6709 * param[in] vport - pointer to bfa_fcs_vport_t. This space
6710 * needs to be allocated by the driver.
6711 * param[in] fcs - FCS instance
6712 * param[in] vport_cfg - vport configuration
6713 * param[in] vf_id - VF_ID if vport is created within a VF.
6714 * FC_VF_ID_NULL to specify base fabric.
6715 * param[in] vport_drv - Opaque handle back to the driver's vport
6716 * structure
6718 * retval BFA_STATUS_OK - on success.
6719 * retval BFA_STATUS_FAILED - on failure.
6721 bfa_status_t
6722 bfa_fcs_vport_create(struct bfa_fcs_vport_s *vport, struct bfa_fcs_s *fcs,
6723 u16 vf_id, struct bfa_lport_cfg_s *vport_cfg,
6724 struct bfad_vport_s *vport_drv)
6726 if (vport_cfg->pwwn == 0)
6727 return BFA_STATUS_INVALID_WWN;
6729 if (bfa_fcs_lport_get_pwwn(&fcs->fabric.bport) == vport_cfg->pwwn)
6730 return BFA_STATUS_VPORT_WWN_BP;
6732 if (bfa_fcs_vport_lookup(fcs, vf_id, vport_cfg->pwwn) != NULL)
6733 return BFA_STATUS_VPORT_EXISTS;
6735 if (fcs->fabric.num_vports ==
6736 bfa_lps_get_max_vport(fcs->bfa))
6737 return BFA_STATUS_VPORT_MAX;
6739 vport->lps = bfa_lps_alloc(fcs->bfa);
6740 if (!vport->lps)
6741 return BFA_STATUS_VPORT_MAX;
6743 vport->vport_drv = vport_drv;
6744 vport_cfg->preboot_vp = BFA_FALSE;
6746 bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
6747 bfa_fcs_lport_attach(&vport->lport, fcs, vf_id, vport);
6748 bfa_fcs_lport_init(&vport->lport, vport_cfg);
6749 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_CREATE);
6751 return BFA_STATUS_OK;
6755 * Use this function to instantiate a new FCS PBC vport object. This
6756 * function will not trigger any HW initialization process (which will be
6757 * done in vport_start() call)
6759 * param[in] vport - pointer to bfa_fcs_vport_t. This space
6760 * needs to be allocated by the driver.
6761 * param[in] fcs - FCS instance
6762 * param[in] vport_cfg - vport configuration
6763 * param[in] vf_id - VF_ID if vport is created within a VF.
6764 * FC_VF_ID_NULL to specify base fabric.
6765 * param[in] vport_drv - Opaque handle back to the driver's vport
6766 * structure
6768 * retval BFA_STATUS_OK - on success.
6769 * retval BFA_STATUS_FAILED - on failure.
6771 bfa_status_t
6772 bfa_fcs_pbc_vport_create(struct bfa_fcs_vport_s *vport, struct bfa_fcs_s *fcs,
6773 u16 vf_id, struct bfa_lport_cfg_s *vport_cfg,
6774 struct bfad_vport_s *vport_drv)
6776 bfa_status_t rc;
6778 rc = bfa_fcs_vport_create(vport, fcs, vf_id, vport_cfg, vport_drv);
6779 vport->lport.port_cfg.preboot_vp = BFA_TRUE;
6781 return rc;
6785 * Use this function to findout if this is a pbc vport or not.
6787 * @param[in] vport - pointer to bfa_fcs_vport_t.
6789 * @returns None
6791 bfa_boolean_t
6792 bfa_fcs_is_pbc_vport(struct bfa_fcs_vport_s *vport)
6795 if (vport && (vport->lport.port_cfg.preboot_vp == BFA_TRUE))
6796 return BFA_TRUE;
6797 else
6798 return BFA_FALSE;
6803 * Use this function initialize the vport.
6805 * @param[in] vport - pointer to bfa_fcs_vport_t.
6807 * @returns None
6809 bfa_status_t
6810 bfa_fcs_vport_start(struct bfa_fcs_vport_s *vport)
6812 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_START);
6814 return BFA_STATUS_OK;
6818 * Use this function quiese the vport object. This function will return
6819 * immediately, when the vport is actually stopped, the
6820 * bfa_drv_vport_stop_cb() will be called.
6822 * param[in] vport - pointer to bfa_fcs_vport_t.
6824 * return None
6826 bfa_status_t
6827 bfa_fcs_vport_stop(struct bfa_fcs_vport_s *vport)
6829 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOP);
6831 return BFA_STATUS_OK;
6835 * Use this function to delete a vport object. Fabric object should
6836 * be stopped before this function call.
6838 * !!!!!!! Donot invoke this from within FCS !!!!!!!
6840 * param[in] vport - pointer to bfa_fcs_vport_t.
6842 * return None
6844 bfa_status_t
6845 bfa_fcs_vport_delete(struct bfa_fcs_vport_s *vport)
6848 if (vport->lport.port_cfg.preboot_vp)
6849 return BFA_STATUS_PBC;
6851 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELETE);
6853 return BFA_STATUS_OK;
6857 * Use this function to get vport's current status info.
6859 * param[in] vport pointer to bfa_fcs_vport_t.
6860 * param[out] attr pointer to return vport attributes
6862 * return None
6864 void
6865 bfa_fcs_vport_get_attr(struct bfa_fcs_vport_s *vport,
6866 struct bfa_vport_attr_s *attr)
6868 if (vport == NULL || attr == NULL)
6869 return;
6871 memset(attr, 0, sizeof(struct bfa_vport_attr_s));
6873 bfa_fcs_lport_get_attr(&vport->lport, &attr->port_attr);
6874 attr->vport_state = bfa_sm_to_state(vport_sm_table, vport->sm);
6879 * Lookup a virtual port. Excludes base port from lookup.
6881 struct bfa_fcs_vport_s *
6882 bfa_fcs_vport_lookup(struct bfa_fcs_s *fcs, u16 vf_id, wwn_t vpwwn)
6884 struct bfa_fcs_vport_s *vport;
6885 struct bfa_fcs_fabric_s *fabric;
6887 bfa_trc(fcs, vf_id);
6888 bfa_trc(fcs, vpwwn);
6890 fabric = bfa_fcs_vf_lookup(fcs, vf_id);
6891 if (!fabric) {
6892 bfa_trc(fcs, vf_id);
6893 return NULL;
6896 vport = bfa_fcs_fabric_vport_lookup(fabric, vpwwn);
6897 return vport;
6901 * FDISC Response
6903 void
6904 bfa_cb_lps_fdisc_comp(void *bfad, void *uarg, bfa_status_t status)
6906 struct bfa_fcs_vport_s *vport = uarg;
6908 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6909 bfa_trc(__vport_fcs(vport), status);
6911 switch (status) {
6912 case BFA_STATUS_OK:
6914 * Initialize the V-Port fields
6916 __vport_fcid(vport) = vport->lps->lp_pid;
6917 vport->vport_stats.fdisc_accepts++;
6918 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_OK);
6919 break;
6921 case BFA_STATUS_INVALID_MAC:
6922 /* Only for CNA */
6923 vport->vport_stats.fdisc_acc_bad++;
6924 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6926 break;
6928 case BFA_STATUS_EPROTOCOL:
6929 switch (vport->lps->ext_status) {
6930 case BFA_EPROTO_BAD_ACCEPT:
6931 vport->vport_stats.fdisc_acc_bad++;
6932 break;
6934 case BFA_EPROTO_UNKNOWN_RSP:
6935 vport->vport_stats.fdisc_unknown_rsp++;
6936 break;
6938 default:
6939 break;
6942 if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
6943 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6944 else
6945 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_FAILED);
6947 break;
6949 case BFA_STATUS_ETIMER:
6950 vport->vport_stats.fdisc_timeouts++;
6951 if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
6952 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6953 else
6954 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_FAILED);
6955 break;
6957 case BFA_STATUS_FABRIC_RJT:
6958 vport->vport_stats.fdisc_rejects++;
6959 bfa_fcs_vport_fdisc_rejected(vport);
6960 break;
6962 default:
6963 vport->vport_stats.fdisc_rsp_err++;
6964 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6969 * LOGO response
6971 void
6972 bfa_cb_lps_fdisclogo_comp(void *bfad, void *uarg)
6974 struct bfa_fcs_vport_s *vport = uarg;
6975 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_OK);
6979 * Received clear virtual link
6981 void
6982 bfa_cb_lps_cvl_event(void *bfad, void *uarg)
6984 struct bfa_fcs_vport_s *vport = uarg;
6986 /* Send an Offline followed by an ONLINE */
6987 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_OFFLINE);
6988 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_ONLINE);