2 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
3 * Copyright (c) 2014- QLogic Corporation.
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.
22 #include "bfa_fcbuild.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,
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);
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);
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);
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);
138 case BFA_FCS_PORT_SM_CREATE:
139 bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
143 bfa_sm_fault(port->fcs, event);
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);
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);
160 case BFA_FCS_PORT_SM_DELETE:
161 bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
162 bfa_fcs_lport_deleted(port);
165 case BFA_FCS_PORT_SM_STOP:
166 /* If vport - send completion call back */
168 bfa_fcs_vport_stop_comp(port->vport);
170 bfa_wc_down(&(port->fabric->stop_wc));
173 case BFA_FCS_PORT_SM_OFFLINE:
177 bfa_sm_fault(port->fcs, event);
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);
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);
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 */
205 bfa_fcs_vport_stop_comp(port->vport);
207 bfa_wc_down(&(port->fabric->stop_wc));
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);
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);
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);
233 case BFA_FCS_PORT_SM_DELRPORT:
237 bfa_sm_fault(port->fcs, event);
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);
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);
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 */
263 bfa_fcs_vport_stop_comp(port->vport);
265 bfa_wc_down(&(port->fabric->stop_wc));
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);
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);
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);
288 case BFA_FCS_PORT_SM_DELRPORT:
289 case BFA_FCS_PORT_SM_OFFLINE:
293 bfa_sm_fault(port->fcs, event);
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);
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 */
310 bfa_fcs_vport_stop_comp(port->vport);
312 bfa_wc_down(&(port->fabric->stop_wc));
317 bfa_sm_fault(port->fcs, event);
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);
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);
338 bfa_sm_fault(port->fcs, event);
347 * Send AEN notification
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);
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);
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)
379 struct bfa_fcxp_s *fcxp;
380 struct bfa_rport_s *bfa_rport = NULL;
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);
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,
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)
407 struct bfa_fcxp_s *fcxp;
408 struct bfa_rport_s *bfa_rport = NULL;
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);
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,
434 * Process incoming plogi from a remote port.
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);
453 if (fc_plogi_parse(rx_fchs) != FC_PARSE_OK) {
454 bfa_trc(port->fcs, rx_fchs->s_id);
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);
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);
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);
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);
501 * Next, lookup rport by PID.
503 rport = bfa_fcs_lport_get_rport_by_pid(port, rx_fchs->s_id);
506 * Inbound PLOGI from a new device.
508 bfa_fcs_rport_plogi_create(port, rx_fchs, plogi);
513 * Rport is known only by PID.
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);
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.
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)
546 struct bfa_fcxp_s *fcxp;
547 struct bfa_rport_s *bfa_rport = NULL;
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);
557 len = fc_ls_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
558 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
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);
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,
579 * Process incoming RNID.
580 * Since it does not require a login, it is processed here.
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;
589 struct bfa_fcxp_s *fcxp;
590 struct bfa_rport_s *bfa_rport = NULL;
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);
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);
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,
630 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
631 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
636 * Fill out General Topolpgy Discovery Data for RNID ELS.
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);
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;
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);
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);
703 bfa_fcs_lport_unknown_init(struct bfa_fcs_lport_s *port)
709 bfa_fcs_lport_unknown_online(struct bfa_fcs_lport_s *port)
715 bfa_fcs_lport_unknown_offline(struct bfa_fcs_lport_s *port)
721 bfa_fcs_lport_abts_acc(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs)
724 struct bfa_fcxp_s *fcxp;
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);
734 len = fc_ba_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
735 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
738 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag,
739 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
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 */
756 bfa_fcs_vport_delete_comp(port->vport);
758 bfa_wc_down(&port->fabric->wc);
763 * Unsolicited frame receive handling.
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);
789 bfa_stats(lport, uf_recv_drops);
795 * First, handle ELSs that donot require a login.
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);
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);
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);
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);
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);
841 * look for a matching remote port ID
843 rport = bfa_fcs_lport_get_rport_by_pid(lport, pid);
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);
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);
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);
871 if (els_cmd->els_code == FC_ELS_LOGO) {
873 * @todo Handle LOGO frames received.
878 if (els_cmd->els_code == FC_ELS_PRLI) {
880 * @todo Handle PRLI frames received.
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)
908 bfa_trc(port->fcs, pid);
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)
927 bfa_trc(port->fcs, pid);
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))
946 bfa_trc(port->fcs, pwwn);
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))
965 bfa_trc(port->fcs, nwwn);
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,
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)
985 bfa_trc(port->fcs, pwwn);
990 * Called by rport module when new rports are discovered.
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);
1002 * Called by rport module to when rports are deleted.
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);
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.
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.
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.
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.
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
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.
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)
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.
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);
1115 bfa_fcs_lport_set_symname(struct bfa_fcs_lport_s *port,
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);
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;
1139 port_attr->port_cfg = port->port_cfg;
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;
1158 port_attr->fpma_mac =
1159 port->fabric->lps->lp_mac;
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.
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.
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.
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.
1211 bfa_fcs_lport_n2n_init(struct bfa_fcs_lport_s *port)
1216 * Called by fcs/port to notify transition to online state.
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
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);
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);
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);
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.
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);
1279 n2n_port->rem_port_wwn = 0;
1280 n2n_port->reply_oxid = 0;
1284 bfa_fcport_get_loop_attr(struct bfa_fcs_lport_s *port)
1286 int i = 0, j = 0, bit = 0, alpa_bit = 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)));
1299 port->port_topo.ploop.alpa_pos_map[k] =
1300 loop_alpa_map[(i * 8) + alpa_bit];
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.
1315 bfa_fcs_lport_loop_init(struct bfa_fcs_lport_s *port)
1320 * Called by fcs/port to notify transition to online state.
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;
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)) {
1344 bfa_trc(port->fcs->bfa, pid);
1345 rport = bfa_fcs_lport_get_rport_by_pid(port,
1348 rport = bfa_fcs_rport_create(port,
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,
1360 rport = bfa_fcs_rport_create(port,
1368 * Called by fcs/port to notify transition to offline state.
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,
1389 bfa_status_t req_status,
1392 struct fchs_s *rsp_fchs);
1393 static void bfa_fcs_lport_fdmi_rprt_response(void *fcsarg,
1394 struct bfa_fcxp_s *fcxp,
1396 bfa_status_t req_status,
1399 struct fchs_s *rsp_fchs);
1400 static void bfa_fcs_lport_fdmi_rpa_response(void *fcsarg,
1401 struct bfa_fcxp_s *fcxp,
1403 bfa_status_t req_status,
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,
1410 static u16 bfa_fcs_lport_fdmi_build_rprt_pyld(struct bfa_fcs_lport_fdmi_s *fdmi,
1412 static u16 bfa_fcs_lport_fdmi_build_rpa_pyld(struct bfa_fcs_lport_fdmi_s *fdmi,
1414 static u16 bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s *
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.
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;
1486 case FDMISM_EVENT_PORT_ONLINE:
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);
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);
1506 case FDMISM_EVENT_PORT_OFFLINE:
1510 bfa_sm_fault(port->fcs, event);
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);
1524 case FDMISM_EVENT_RHBA_SENT:
1525 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rhba);
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),
1535 bfa_sm_fault(port->fcs, event);
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);
1549 case FDMISM_EVENT_RSP_ERROR:
1551 * if max retries have not been reached, start timer for a
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),
1559 bfa_fcs_lport_fdmi_timeout, fdmi,
1560 BFA_FCS_RETRY_TIMEOUT);
1563 * set state to offline
1565 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
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);
1578 case FDMISM_EVENT_PORT_OFFLINE:
1579 bfa_fcxp_discard(fdmi->fcxp);
1580 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1584 bfa_sm_fault(port->fcs, event);
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);
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);
1606 case FDMISM_EVENT_PORT_OFFLINE:
1607 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1608 bfa_timer_stop(&fdmi->timer);
1612 bfa_sm_fault(port->fcs, event);
1617 * RPRT : Register Port
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);
1629 case FDMISM_EVENT_RPRT_SENT:
1630 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rprt);
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),
1640 bfa_sm_fault(port->fcs, event);
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);
1654 case FDMISM_EVENT_RSP_ERROR:
1656 * if max retries have not been reached, start timer for a
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),
1664 bfa_fcs_lport_fdmi_timeout, fdmi,
1665 BFA_FCS_RETRY_TIMEOUT);
1669 * set state to offline
1671 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1672 fdmi->retry_cnt = 0;
1676 case FDMISM_EVENT_RSP_OK:
1677 fdmi->retry_cnt = 0;
1678 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_online);
1681 case FDMISM_EVENT_PORT_OFFLINE:
1682 bfa_fcxp_discard(fdmi->fcxp);
1683 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1687 bfa_sm_fault(port->fcs, event);
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);
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);
1709 case FDMISM_EVENT_PORT_OFFLINE:
1710 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1711 bfa_timer_stop(&fdmi->timer);
1715 bfa_sm_fault(port->fcs, event);
1720 * Register Port Attributes
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);
1732 case FDMISM_EVENT_RPA_SENT:
1733 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rpa);
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),
1743 bfa_sm_fault(port->fcs, event);
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);
1757 case FDMISM_EVENT_RSP_ERROR:
1759 * if max retries have not been reached, start timer for a
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),
1766 bfa_fcs_lport_fdmi_timeout, fdmi,
1767 BFA_FCS_RETRY_TIMEOUT);
1770 * set state to offline
1772 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1773 fdmi->retry_cnt = 0;
1777 case FDMISM_EVENT_RSP_OK:
1778 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_online);
1779 fdmi->retry_cnt = 0;
1782 case FDMISM_EVENT_PORT_OFFLINE:
1783 bfa_fcxp_discard(fdmi->fcxp);
1784 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1788 bfa_sm_fault(port->fcs, event);
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);
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);
1810 case FDMISM_EVENT_PORT_OFFLINE:
1811 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1812 bfa_timer_stop(&fdmi->timer);
1816 bfa_sm_fault(port->fcs, event);
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);
1830 case FDMISM_EVENT_PORT_OFFLINE:
1831 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1835 bfa_sm_fault(port->fcs, event);
1839 * FDMI is disabled state.
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.
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;
1863 struct bfa_fcxp_s *fcxp;
1866 bfa_trc(port->fcs, port->port_cfg.pwwn);
1868 fcxp = fcxp_alloced ? fcxp_alloced :
1869 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
1871 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
1872 bfa_fcs_lport_fdmi_send_rhba, fdmi, BFA_TRUE);
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),
1884 bfa_fcs_lport_fdmi_build_rhba_pyld(fdmi,
1885 (u8 *) ((struct ct_hdr_s *) pyld
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);
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;
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);
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;
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;
1937 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
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;
1951 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
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;
1965 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
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;
1979 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
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;
1993 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
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;
2008 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
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;
2023 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
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;
2038 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
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;
2050 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
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;
2065 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
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;
2080 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
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;
2094 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
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;
2105 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
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;
2116 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
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;
2127 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
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;
2138 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
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);
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);
2167 if (req_status != BFA_STATUS_OK) {
2168 bfa_trc(port->fcs, req_status);
2169 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
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);
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
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;
2196 struct bfa_fcxp_s *fcxp;
2199 bfa_trc(port->fcs, port->port_cfg.pwwn);
2201 fcxp = fcxp_alloced ? fcxp_alloced :
2202 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
2204 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
2205 bfa_fcs_lport_fdmi_send_rprt, fdmi, BFA_TRUE);
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),
2217 bfa_fcs_lport_fdmi_build_rprt_pyld(fdmi,
2218 (u8 *) ((struct ct_hdr_s *) pyld
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.
2233 bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s *fdmi,
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;
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;
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;
2267 cpu_to_be16(templen + sizeof(attr->type) +
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;
2281 cpu_to_be16(templen + sizeof(attr->type) +
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;
2294 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
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;
2307 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
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;
2322 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
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;
2337 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
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;
2350 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
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;
2361 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2364 if (fcs_port_attr.port_sym_name.symname[0] != '\0') {
2365 attr = (struct fdmi_attr_s *) curr_ptr;
2367 cpu_to_be16(FDMI_PORT_ATTRIB_PORT_SYM_NAME);
2368 templen = sizeof(fcs_port_attr.port_sym_name);
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;
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;
2388 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
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;
2399 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
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;
2410 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
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,
2418 templen = fc_roundup(templen, sizeof(u32));
2419 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2422 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
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;
2433 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
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;
2444 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2449 * Update size of payload
2451 port_attrib->attr_count = cpu_to_be32(count);
2452 len += ((sizeof(attr->type) + sizeof(attr->len)) * count);
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;
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);
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);
2490 if (req_status != BFA_STATUS_OK) {
2491 bfa_trc(port->fcs, req_status);
2492 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
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);
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.
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;
2519 struct bfa_fcxp_s *fcxp;
2522 bfa_trc(port->fcs, port->port_cfg.pwwn);
2524 fcxp = fcxp_alloced ? fcxp_alloced :
2525 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
2527 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
2528 bfa_fcs_lport_fdmi_send_rpa, fdmi, BFA_TRUE);
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),
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);
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;
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);
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);
2582 if (req_status != BFA_STATUS_OK) {
2583 bfa_trc(port->fcs, req_status);
2584 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
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);
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);
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);
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,
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 strlcpy(hba_attr->driver_version, (char *)driver_info->version,
2635 sizeof(hba_attr->driver_version));
2637 strlcpy(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 strlcat(hba_attr->os_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
2646 sizeof(hba_attr->os_name));
2647 strlcat(hba_attr->os_name, driver_info->host_os_patch,
2648 sizeof(hba_attr->os_name));
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 strlcpy(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 strlcpy(hba_attr->bios_ver, hba_attr->option_rom_ver, BFA_VERSION_LEN);
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);
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);
2695 case BFA_PORT_SPEED_10GBPS:
2696 port_attr->supp_speed =
2697 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_10G);
2700 case BFA_PORT_SPEED_8GBPS:
2701 port_attr->supp_speed =
2702 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_8G);
2705 case BFA_PORT_SPEED_4GBPS:
2706 port_attr->supp_speed =
2707 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_4G);
2711 bfa_sm_fault(port->fcs, pport_attr.speed_supported);
2717 port_attr->curr_speed = cpu_to_be32(
2718 bfa_fcs_fdmi_convert_speed(pport_attr.speed));
2723 port_attr->max_frm_size = cpu_to_be32(pport_attr.pport_cfg.maxfrsize);
2728 strlcpy(port_attr->os_device_name, driver_info->os_device_name,
2729 sizeof(port_attr->os_device_name));
2734 strlcpy(port_attr->host_name, 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 strlcpy(port_attr->port_sym_name.symname,
2741 bfa_fcs_lport_get_psym_name(port).symname, 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)
2759 switch (pport_speed) {
2760 case BFA_PORT_SPEED_1GBPS:
2761 case BFA_PORT_SPEED_2GBPS:
2765 case BFA_PORT_SPEED_4GBPS:
2766 ret = FDMI_TRANS_SPEED_4G;
2769 case BFA_PORT_SPEED_8GBPS:
2770 ret = FDMI_TRANS_SPEED_8G;
2773 case BFA_PORT_SPEED_10GBPS:
2774 ret = FDMI_TRANS_SPEED_10G;
2777 case BFA_PORT_SPEED_16GBPS:
2778 ret = FDMI_TRANS_SPEED_16G;
2782 ret = FDMI_TRANS_SPEED_UNKNOWN;
2788 bfa_fcs_lport_fdmi_init(struct bfa_fcs_lport_ms_s *ms)
2790 struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
2793 if (ms->port->fcs->fdmi_enabled)
2794 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
2796 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_disabled);
2800 bfa_fcs_lport_fdmi_offline(struct bfa_fcs_lport_ms_s *ms)
2802 struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
2805 bfa_sm_send_event(fdmi, FDMISM_EVENT_PORT_OFFLINE);
2809 bfa_fcs_lport_fdmi_online(struct bfa_fcs_lport_ms_s *ms)
2811 struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
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,
2828 bfa_status_t req_status,
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,
2838 bfa_status_t req_status,
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,
2847 bfa_status_t req_status,
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.
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);
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);
2906 case MSSM_EVENT_PORT_OFFLINE:
2910 bfa_sm_fault(ms->port->fcs, event);
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);
2922 case MSSM_EVENT_FCXP_SENT:
2923 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi);
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),
2933 bfa_sm_fault(ms->port->fcs, event);
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);
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);
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);
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);
2978 case MSSM_EVENT_PORT_OFFLINE:
2979 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
2980 bfa_fcxp_discard(ms->fcxp);
2984 bfa_sm_fault(ms->port->fcs, event);
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);
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);
3004 case MSSM_EVENT_PORT_OFFLINE:
3005 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3006 bfa_timer_stop(&ms->timer);
3010 bfa_sm_fault(ms->port->fcs, event);
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);
3022 case MSSM_EVENT_PORT_OFFLINE:
3023 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3026 case MSSM_EVENT_PORT_FABRIC_RSCN:
3027 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
3029 bfa_fcs_lport_ms_send_gfn(ms, NULL);
3033 bfa_sm_fault(ms->port->fcs, event);
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);
3045 case MSSM_EVENT_FCXP_SENT:
3046 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal);
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),
3056 bfa_sm_fault(ms->port->fcs, event);
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);
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);
3079 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
3080 bfa_fcs_lport_ms_send_gfn(ms, NULL);
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);
3090 case MSSM_EVENT_PORT_OFFLINE:
3091 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3092 bfa_fcxp_discard(ms->fcxp);
3096 bfa_sm_fault(ms->port->fcs, event);
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);
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);
3116 case MSSM_EVENT_PORT_OFFLINE:
3117 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3118 bfa_timer_stop(&ms->timer);
3122 bfa_sm_fault(ms->port->fcs, event);
3126 * ms_pvt MS local functions
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;
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);
3143 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
3144 bfa_fcs_lport_ms_send_gmal, ms, BFA_TRUE);
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);
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;
3175 bfa_trc(port->fcs, req_status);
3176 bfa_trc(port->fcs, port->port_cfg.pwwn);
3181 if (req_status != BFA_STATUS_OK) {
3182 bfa_trc(port->fcs, req_status);
3183 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
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);
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 '/',
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 strlcpy(bfa_fcs_lport_get_fabric_ipaddr(port),
3222 gmal_entry->ip_addr,
3223 BFA_FCS_FABRIC_IPADDR_SZ);
3231 bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
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);
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);
3248 case MSSM_EVENT_FCXP_SENT:
3249 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn);
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),
3259 bfa_sm_fault(ms->port->fcs, event);
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);
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);
3282 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_online);
3287 case MSSM_EVENT_RSP_OK:
3288 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_online);
3291 case MSSM_EVENT_PORT_OFFLINE:
3292 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3293 bfa_fcxp_discard(ms->fcxp);
3297 bfa_sm_fault(ms->port->fcs, event);
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);
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);
3317 case MSSM_EVENT_PORT_OFFLINE:
3318 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3319 bfa_timer_stop(&ms->timer);
3323 bfa_sm_fault(ms->port->fcs, event);
3327 * ms_pvt MS local functions
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;
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);
3344 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
3345 bfa_fcs_lport_ms_send_gfn, ms, BFA_TRUE);
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);
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;
3372 bfa_trc(port->fcs, req_status);
3373 bfa_trc(port->fcs, port->port_cfg.pwwn);
3378 if (req_status != BFA_STATUS_OK) {
3379 bfa_trc(port->fcs, req_status);
3380 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
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);
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
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;
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);
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);
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);
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);
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);
3467 els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
3469 switch (els_cmd->els_code) {
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);
3478 port->stats.ms_plogi_accepts++;
3479 bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
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);
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);
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);
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);
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);
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);
3529 bfa_sm_send_event(ms, MSSM_EVENT_PORT_OFFLINE);
3530 bfa_fcs_lport_fdmi_offline(ms);
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);
3539 bfa_sm_send_event(ms, MSSM_EVENT_PORT_ONLINE);
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
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,
3581 bfa_status_t req_status,
3584 struct fchs_s *rsp_fchs);
3585 static void bfa_fcs_lport_ns_rspn_id_response(void *fcsarg,
3586 struct bfa_fcxp_s *fcxp,
3588 bfa_status_t req_status,
3591 struct fchs_s *rsp_fchs);
3592 static void bfa_fcs_lport_ns_rft_id_response(void *fcsarg,
3593 struct bfa_fcxp_s *fcxp,
3595 bfa_status_t req_status,
3598 struct fchs_s *rsp_fchs);
3599 static void bfa_fcs_lport_ns_rff_id_response(void *fcsarg,
3600 struct bfa_fcxp_s *fcxp,
3602 bfa_status_t req_status,
3605 struct fchs_s *rsp_fchs);
3606 static void bfa_fcs_lport_ns_gid_ft_response(void *fcsarg,
3607 struct bfa_fcxp_s *fcxp,
3609 bfa_status_t req_status,
3612 struct fchs_s *rsp_fchs);
3613 static void bfa_fcs_lport_ns_rnn_id_response(void *fcsarg,
3614 struct bfa_fcxp_s *fcxp,
3616 bfa_status_t req_status,
3619 struct fchs_s *rsp_fchs);
3620 static void bfa_fcs_lport_ns_rsnn_nn_response(void *fcsarg,
3621 struct bfa_fcxp_s *fcxp,
3623 bfa_status_t req_status,
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
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);
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);
3724 case NSSM_EVENT_PORT_OFFLINE:
3728 bfa_sm_fault(ns->port->fcs, event);
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);
3740 case NSSM_EVENT_PLOGI_SENT:
3741 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi);
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),
3751 bfa_sm_fault(ns->port->fcs, event);
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);
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);
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);
3780 case NSSM_EVENT_PORT_OFFLINE:
3781 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3782 bfa_fcxp_discard(ns->fcxp);
3786 bfa_sm_fault(ns->port->fcs, event);
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);
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);
3806 case NSSM_EVENT_PORT_OFFLINE:
3807 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3808 bfa_timer_stop(&ns->timer);
3812 bfa_sm_fault(ns->port->fcs, event);
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);
3824 case NSSM_EVENT_RNNID_SENT:
3825 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rnn_id);
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),
3834 bfa_sm_fault(ns->port->fcs, event);
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);
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);
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);
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);
3868 case NSSM_EVENT_PORT_OFFLINE:
3869 bfa_fcxp_discard(ns->fcxp);
3870 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3874 bfa_sm_fault(ns->port->fcs, event);
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);
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);
3891 case NSSM_EVENT_PORT_OFFLINE:
3892 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3893 bfa_timer_stop(&ns->timer);
3897 bfa_sm_fault(ns->port->fcs, event);
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);
3909 case NSSM_EVENT_RSNN_NN_SENT:
3910 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rsnn_nn);
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),
3920 bfa_sm_fault(ns->port->fcs, event);
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);
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);
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);
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);
3953 case NSSM_EVENT_PORT_OFFLINE:
3954 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3955 bfa_fcxp_discard(ns->fcxp);
3959 bfa_sm_fault(ns->port->fcs, event);
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);
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);
3976 case NSSM_EVENT_PORT_OFFLINE:
3977 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3978 bfa_timer_stop(&ns->timer);
3982 bfa_sm_fault(ns->port->fcs, event);
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);
3994 case NSSM_EVENT_RSPNID_SENT:
3995 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rspn_id);
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),
4005 bfa_sm_fault(ns->port->fcs, event);
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);
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);
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);
4033 case NSSM_EVENT_PORT_OFFLINE:
4034 bfa_fcxp_discard(ns->fcxp);
4035 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4039 bfa_sm_fault(ns->port->fcs, event);
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);
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);
4059 case NSSM_EVENT_PORT_OFFLINE:
4060 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4061 bfa_timer_stop(&ns->timer);
4065 bfa_sm_fault(ns->port->fcs, event);
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);
4077 case NSSM_EVENT_RFTID_SENT:
4078 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rft_id);
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),
4088 bfa_sm_fault(ns->port->fcs, event);
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);
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);
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);
4117 case NSSM_EVENT_PORT_OFFLINE:
4118 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4119 bfa_fcxp_discard(ns->fcxp);
4123 bfa_sm_fault(ns->port->fcs, event);
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);
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);
4140 case NSSM_EVENT_PORT_OFFLINE:
4141 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4142 bfa_timer_stop(&ns->timer);
4146 bfa_sm_fault(ns->port->fcs, event);
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);
4158 case NSSM_EVENT_RFFID_SENT:
4159 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rff_id);
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),
4169 bfa_sm_fault(ns->port->fcs, event);
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);
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);
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);
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);
4220 case NSSM_EVENT_PORT_OFFLINE:
4221 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4222 bfa_fcxp_discard(ns->fcxp);
4226 bfa_sm_fault(ns->port->fcs, event);
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);
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);
4243 case NSSM_EVENT_PORT_OFFLINE:
4244 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4245 bfa_timer_stop(&ns->timer);
4249 bfa_sm_fault(ns->port->fcs, event);
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);
4260 case NSSM_EVENT_GIDFT_SENT:
4261 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_gid_ft);
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),
4271 bfa_sm_fault(ns->port->fcs, event);
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);
4283 case NSSM_EVENT_RSP_OK:
4284 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_online);
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);
4301 case NSSM_EVENT_PORT_OFFLINE:
4302 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4303 bfa_fcxp_discard(ns->fcxp);
4306 case NSSM_EVENT_NS_QUERY:
4310 bfa_sm_fault(ns->port->fcs, event);
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);
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);
4327 case NSSM_EVENT_PORT_OFFLINE:
4328 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4329 bfa_timer_stop(&ns->timer);
4333 bfa_sm_fault(ns->port->fcs, event);
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);
4345 case NSSM_EVENT_PORT_OFFLINE:
4346 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
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);
4362 bfa_sm_fault(ns->port->fcs, event);
4369 * ns_pvt Nameserver local functions
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;
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);
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);
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);
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);
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);
4433 els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
4435 switch (els_cmd->els_code) {
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);
4444 port->stats.ns_plogi_accepts++;
4445 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
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);
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
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;
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);
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);
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);
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);
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);
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);
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.
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;
4553 struct bfa_fcxp_s *fcxp;
4556 bfa_trc(port->fcs, port->port_cfg.pwwn);
4558 fcxp = fcxp_alloced ? fcxp_alloced :
4559 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
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);
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);
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);
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);
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);
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.
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;
4632 struct bfa_fcxp_s *fcxp;
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);
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);
4651 * for V-Port, form a Port Symbolic Name
4655 * For Vports, we append the vport's port symbolic name
4656 * to that of the base port.
4660 (char *)&(bfa_fcs_lport_get_psym_name
4661 (bfa_fcs_get_base_port(port->fcs))),
4664 strlcat(symbl, (char *)&(bfa_fcs_lport_get_psym_name(port)),
4667 psymbl = (u8 *) &(bfa_fcs_lport_get_psym_name(port));
4670 len = fc_rspnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4671 bfa_fcs_lport_get_fcid(port), 0, psymbl);
4673 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4674 FC_CLASS_3, len, &fchs,
4675 bfa_fcs_lport_ns_rspn_id_response, (void *)ns,
4676 FC_MAX_PDUSZ, FC_FCCT_TOV);
4678 port->stats.ns_rspnid_sent++;
4680 bfa_sm_send_event(ns, NSSM_EVENT_RSPNID_SENT);
4684 bfa_fcs_lport_ns_rspn_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4685 void *cbarg, bfa_status_t req_status,
4686 u32 rsp_len, u32 resid_len,
4687 struct fchs_s *rsp_fchs)
4689 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4690 struct bfa_fcs_lport_s *port = ns->port;
4691 struct ct_hdr_s *cthdr = NULL;
4693 bfa_trc(port->fcs, port->port_cfg.pwwn);
4698 if (req_status != BFA_STATUS_OK) {
4699 bfa_trc(port->fcs, req_status);
4700 port->stats.ns_rspnid_rsp_err++;
4701 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4705 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4706 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4708 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4709 port->stats.ns_rspnid_accepts++;
4710 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4714 port->stats.ns_rspnid_rejects++;
4715 bfa_trc(port->fcs, cthdr->reason_code);
4716 bfa_trc(port->fcs, cthdr->exp_code);
4717 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4721 * Register FC4-Types
4724 bfa_fcs_lport_ns_send_rft_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4726 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4727 struct bfa_fcs_lport_s *port = ns->port;
4730 struct bfa_fcxp_s *fcxp;
4732 bfa_trc(port->fcs, port->port_cfg.pwwn);
4734 fcxp = fcxp_alloced ? fcxp_alloced :
4735 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4737 port->stats.ns_rftid_alloc_wait++;
4738 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4739 bfa_fcs_lport_ns_send_rft_id, ns, BFA_TRUE);
4744 len = fc_rftid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4745 bfa_fcs_lport_get_fcid(port), 0, port->port_cfg.roles);
4747 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4748 FC_CLASS_3, len, &fchs,
4749 bfa_fcs_lport_ns_rft_id_response, (void *)ns,
4750 FC_MAX_PDUSZ, FC_FCCT_TOV);
4752 port->stats.ns_rftid_sent++;
4753 bfa_sm_send_event(ns, NSSM_EVENT_RFTID_SENT);
4757 bfa_fcs_lport_ns_rft_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4758 void *cbarg, bfa_status_t req_status,
4759 u32 rsp_len, u32 resid_len,
4760 struct fchs_s *rsp_fchs)
4762 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4763 struct bfa_fcs_lport_s *port = ns->port;
4764 struct ct_hdr_s *cthdr = NULL;
4766 bfa_trc(port->fcs, port->port_cfg.pwwn);
4771 if (req_status != BFA_STATUS_OK) {
4772 bfa_trc(port->fcs, req_status);
4773 port->stats.ns_rftid_rsp_err++;
4774 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4778 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4779 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4781 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4782 port->stats.ns_rftid_accepts++;
4783 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4787 port->stats.ns_rftid_rejects++;
4788 bfa_trc(port->fcs, cthdr->reason_code);
4789 bfa_trc(port->fcs, cthdr->exp_code);
4790 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4794 * Register FC4-Features : Should be done after RFT_ID
4797 bfa_fcs_lport_ns_send_rff_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4799 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4800 struct bfa_fcs_lport_s *port = ns->port;
4803 struct bfa_fcxp_s *fcxp;
4806 bfa_trc(port->fcs, port->port_cfg.pwwn);
4808 fcxp = fcxp_alloced ? fcxp_alloced :
4809 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4811 port->stats.ns_rffid_alloc_wait++;
4812 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4813 bfa_fcs_lport_ns_send_rff_id, ns, BFA_TRUE);
4818 if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns->port))
4819 fc4_ftrs = FC_GS_FCP_FC4_FEATURE_INITIATOR;
4821 len = fc_rffid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4822 bfa_fcs_lport_get_fcid(port), 0,
4823 FC_TYPE_FCP, fc4_ftrs);
4825 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4826 FC_CLASS_3, len, &fchs,
4827 bfa_fcs_lport_ns_rff_id_response, (void *)ns,
4828 FC_MAX_PDUSZ, FC_FCCT_TOV);
4830 port->stats.ns_rffid_sent++;
4831 bfa_sm_send_event(ns, NSSM_EVENT_RFFID_SENT);
4835 bfa_fcs_lport_ns_rff_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4836 void *cbarg, bfa_status_t req_status,
4837 u32 rsp_len, u32 resid_len,
4838 struct fchs_s *rsp_fchs)
4840 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4841 struct bfa_fcs_lport_s *port = ns->port;
4842 struct ct_hdr_s *cthdr = NULL;
4844 bfa_trc(port->fcs, port->port_cfg.pwwn);
4849 if (req_status != BFA_STATUS_OK) {
4850 bfa_trc(port->fcs, req_status);
4851 port->stats.ns_rffid_rsp_err++;
4852 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4856 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4857 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4859 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4860 port->stats.ns_rffid_accepts++;
4861 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4865 port->stats.ns_rffid_rejects++;
4866 bfa_trc(port->fcs, cthdr->reason_code);
4867 bfa_trc(port->fcs, cthdr->exp_code);
4869 if (cthdr->reason_code == CT_RSN_NOT_SUPP) {
4870 /* if this command is not supported, we don't retry */
4871 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4873 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4876 * Query Fabric for FC4-Types Devices.
4878 * TBD : Need to use a local (FCS private) response buffer, since the response
4879 * can be larger than 2K.
4882 bfa_fcs_lport_ns_send_gid_ft(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4884 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4885 struct bfa_fcs_lport_s *port = ns->port;
4888 struct bfa_fcxp_s *fcxp;
4890 bfa_trc(port->fcs, port->pid);
4892 fcxp = fcxp_alloced ? fcxp_alloced :
4893 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4895 port->stats.ns_gidft_alloc_wait++;
4896 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4897 bfa_fcs_lport_ns_send_gid_ft, ns, BFA_TRUE);
4903 * This query is only initiated for FCP initiator mode.
4905 len = fc_gid_ft_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4906 ns->port->pid, FC_TYPE_FCP);
4908 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4909 FC_CLASS_3, len, &fchs,
4910 bfa_fcs_lport_ns_gid_ft_response, (void *)ns,
4911 bfa_fcxp_get_maxrsp(port->fcs->bfa), FC_FCCT_TOV);
4913 port->stats.ns_gidft_sent++;
4915 bfa_sm_send_event(ns, NSSM_EVENT_GIDFT_SENT);
4919 bfa_fcs_lport_ns_gid_ft_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4920 void *cbarg, bfa_status_t req_status,
4921 u32 rsp_len, u32 resid_len,
4922 struct fchs_s *rsp_fchs)
4924 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4925 struct bfa_fcs_lport_s *port = ns->port;
4926 struct ct_hdr_s *cthdr = NULL;
4929 bfa_trc(port->fcs, port->port_cfg.pwwn);
4934 if (req_status != BFA_STATUS_OK) {
4935 bfa_trc(port->fcs, req_status);
4936 port->stats.ns_gidft_rsp_err++;
4937 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4941 if (resid_len != 0) {
4943 * TBD : we will need to allocate a larger buffer & retry the
4946 bfa_trc(port->fcs, rsp_len);
4947 bfa_trc(port->fcs, resid_len);
4951 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4952 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4954 switch (cthdr->cmd_rsp_code) {
4958 port->stats.ns_gidft_accepts++;
4959 n_pids = (fc_get_ctresp_pyld_len(rsp_len) / sizeof(u32));
4960 bfa_trc(port->fcs, n_pids);
4961 bfa_fcs_lport_ns_process_gidft_pids(port,
4962 (u32 *) (cthdr + 1),
4964 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4970 * Check the reason code & explanation.
4971 * There may not have been any FC4 devices in the fabric
4973 port->stats.ns_gidft_rejects++;
4974 bfa_trc(port->fcs, cthdr->reason_code);
4975 bfa_trc(port->fcs, cthdr->exp_code);
4977 if ((cthdr->reason_code == CT_RSN_UNABLE_TO_PERF)
4978 && (cthdr->exp_code == CT_NS_EXP_FT_NOT_REG)) {
4980 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4983 * for all other errors, retry
4985 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4990 port->stats.ns_gidft_unknown_rsp++;
4991 bfa_trc(port->fcs, cthdr->cmd_rsp_code);
4992 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4997 * This routine will be called by bfa_timer on timer timeouts.
4999 * param[in] port - pointer to bfa_fcs_lport_t.
5004 * Special Considerations:
5009 bfa_fcs_lport_ns_timeout(void *arg)
5011 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) arg;
5013 ns->port->stats.ns_timeouts++;
5014 bfa_sm_send_event(ns, NSSM_EVENT_TIMEOUT);
5018 * Process the PID list in GID_FT response
5021 bfa_fcs_lport_ns_process_gidft_pids(struct bfa_fcs_lport_s *port, u32 *pid_buf,
5024 struct fcgs_gidft_resp_s *gidft_entry;
5025 struct bfa_fcs_rport_s *rport;
5027 struct bfa_fcs_fabric_s *fabric = port->fabric;
5028 struct bfa_fcs_vport_s *vport;
5029 struct list_head *qe;
5032 for (ii = 0; ii < n_pids; ii++) {
5033 gidft_entry = (struct fcgs_gidft_resp_s *) &pid_buf[ii];
5035 if (gidft_entry->pid == port->pid)
5039 * Ignore PID if it is of base port
5040 * (Avoid vports discovering base port as remote port)
5042 if (gidft_entry->pid == fabric->bport.pid)
5046 * Ignore PID if it is of vport created on the same base port
5047 * (Avoid vport discovering every other vport created on the
5048 * same port as remote port)
5050 list_for_each(qe, &fabric->vport_q) {
5051 vport = (struct bfa_fcs_vport_s *) qe;
5052 if (vport->lport.pid == gidft_entry->pid)
5062 * Check if this rport already exists
5064 rport = bfa_fcs_lport_get_rport_by_pid(port, gidft_entry->pid);
5065 if (rport == NULL) {
5067 * this is a new device. create rport
5069 rport = bfa_fcs_rport_create(port, gidft_entry->pid);
5072 * this rport already exists
5074 bfa_fcs_rport_scn(rport);
5077 bfa_trc(port->fcs, gidft_entry->pid);
5080 * if the last entry bit is set, bail out.
5082 if (gidft_entry->last)
5088 * fcs_ns_public FCS nameserver public interfaces
5092 * Functions called by port/fab.
5093 * These will send relevant Events to the ns state machine.
5096 bfa_fcs_lport_ns_init(struct bfa_fcs_lport_s *port)
5098 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
5101 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
5105 bfa_fcs_lport_ns_offline(struct bfa_fcs_lport_s *port)
5107 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
5110 bfa_sm_send_event(ns, NSSM_EVENT_PORT_OFFLINE);
5114 bfa_fcs_lport_ns_online(struct bfa_fcs_lport_s *port)
5116 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
5119 bfa_sm_send_event(ns, NSSM_EVENT_PORT_ONLINE);
5123 bfa_fcs_lport_ns_query(struct bfa_fcs_lport_s *port)
5125 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
5127 bfa_trc(port->fcs, port->pid);
5128 if (bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_online))
5129 bfa_sm_send_event(ns, NSSM_EVENT_NS_QUERY);
5133 bfa_fcs_lport_ns_boot_target_disc(bfa_fcs_lport_t *port)
5136 struct bfa_fcs_rport_s *rport;
5138 wwn_t wwns[BFA_PREBOOT_BOOTLUN_MAX];
5141 bfa_iocfc_get_bootwwns(port->fcs->bfa, &nwwns, wwns);
5143 for (ii = 0 ; ii < nwwns; ++ii) {
5144 rport = bfa_fcs_rport_create_by_wwn(port, wwns[ii]);
5150 bfa_fcs_lport_ns_util_send_rspn_id(void *cbarg, struct bfa_fcxp_s *fcxp_alloced)
5152 struct bfa_fcs_lport_ns_s *ns = cbarg;
5153 struct bfa_fcs_lport_s *port = ns->port;
5155 struct bfa_fcxp_s *fcxp;
5159 /* Avoid sending RSPN in the following states. */
5160 if (bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_offline) ||
5161 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi_sending) ||
5162 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi) ||
5163 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi_retry) ||
5164 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_rspn_id_retry))
5167 memset(symbl, 0, sizeof(symbl));
5168 bfa_trc(port->fcs, port->port_cfg.pwwn);
5170 fcxp = fcxp_alloced ? fcxp_alloced :
5171 bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
5173 port->stats.ns_rspnid_alloc_wait++;
5174 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
5175 bfa_fcs_lport_ns_util_send_rspn_id, ns, BFA_FALSE);
5183 * For Vports, we append the vport's port symbolic name
5184 * to that of the base port.
5186 strlcpy(symbl, (char *)&(bfa_fcs_lport_get_psym_name
5187 (bfa_fcs_get_base_port(port->fcs))),
5191 (char *)&(bfa_fcs_lport_get_psym_name(port)),
5195 len = fc_rspnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
5196 bfa_fcs_lport_get_fcid(port), 0, symbl);
5198 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
5199 FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
5201 port->stats.ns_rspnid_sent++;
5208 #define FC_QOS_RSCN_EVENT 0x0c
5209 #define FC_FABRIC_NAME_RSCN_EVENT 0x0d
5212 * forward declarations
5214 static void bfa_fcs_lport_scn_send_scr(void *scn_cbarg,
5215 struct bfa_fcxp_s *fcxp_alloced);
5216 static void bfa_fcs_lport_scn_scr_response(void *fcsarg,
5217 struct bfa_fcxp_s *fcxp,
5219 bfa_status_t req_status,
5222 struct fchs_s *rsp_fchs);
5223 static void bfa_fcs_lport_scn_send_ls_acc(struct bfa_fcs_lport_s *port,
5224 struct fchs_s *rx_fchs);
5225 static void bfa_fcs_lport_scn_timeout(void *arg);
5228 * fcs_scm_sm FCS SCN state machine
5232 * VPort SCN State Machine events
5234 enum port_scn_event {
5235 SCNSM_EVENT_PORT_ONLINE = 1,
5236 SCNSM_EVENT_PORT_OFFLINE = 2,
5237 SCNSM_EVENT_RSP_OK = 3,
5238 SCNSM_EVENT_RSP_ERROR = 4,
5239 SCNSM_EVENT_TIMEOUT = 5,
5240 SCNSM_EVENT_SCR_SENT = 6,
5243 static void bfa_fcs_lport_scn_sm_offline(struct bfa_fcs_lport_scn_s *scn,
5244 enum port_scn_event event);
5245 static void bfa_fcs_lport_scn_sm_sending_scr(
5246 struct bfa_fcs_lport_scn_s *scn,
5247 enum port_scn_event event);
5248 static void bfa_fcs_lport_scn_sm_scr(struct bfa_fcs_lport_scn_s *scn,
5249 enum port_scn_event event);
5250 static void bfa_fcs_lport_scn_sm_scr_retry(struct bfa_fcs_lport_scn_s *scn,
5251 enum port_scn_event event);
5252 static void bfa_fcs_lport_scn_sm_online(struct bfa_fcs_lport_scn_s *scn,
5253 enum port_scn_event event);
5256 * Starting state - awaiting link up.
5259 bfa_fcs_lport_scn_sm_offline(struct bfa_fcs_lport_scn_s *scn,
5260 enum port_scn_event event)
5263 case SCNSM_EVENT_PORT_ONLINE:
5264 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_sending_scr);
5265 bfa_fcs_lport_scn_send_scr(scn, NULL);
5268 case SCNSM_EVENT_PORT_OFFLINE:
5272 bfa_sm_fault(scn->port->fcs, event);
5277 bfa_fcs_lport_scn_sm_sending_scr(struct bfa_fcs_lport_scn_s *scn,
5278 enum port_scn_event event)
5281 case SCNSM_EVENT_SCR_SENT:
5282 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_scr);
5285 case SCNSM_EVENT_PORT_OFFLINE:
5286 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5287 bfa_fcxp_walloc_cancel(scn->port->fcs->bfa, &scn->fcxp_wqe);
5291 bfa_sm_fault(scn->port->fcs, event);
5296 bfa_fcs_lport_scn_sm_scr(struct bfa_fcs_lport_scn_s *scn,
5297 enum port_scn_event event)
5299 struct bfa_fcs_lport_s *port = scn->port;
5302 case SCNSM_EVENT_RSP_OK:
5303 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_online);
5306 case SCNSM_EVENT_RSP_ERROR:
5307 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_scr_retry);
5308 bfa_timer_start(port->fcs->bfa, &scn->timer,
5309 bfa_fcs_lport_scn_timeout, scn,
5310 BFA_FCS_RETRY_TIMEOUT);
5313 case SCNSM_EVENT_PORT_OFFLINE:
5314 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5315 bfa_fcxp_discard(scn->fcxp);
5319 bfa_sm_fault(port->fcs, event);
5324 bfa_fcs_lport_scn_sm_scr_retry(struct bfa_fcs_lport_scn_s *scn,
5325 enum port_scn_event event)
5328 case SCNSM_EVENT_TIMEOUT:
5329 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_sending_scr);
5330 bfa_fcs_lport_scn_send_scr(scn, NULL);
5333 case SCNSM_EVENT_PORT_OFFLINE:
5334 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5335 bfa_timer_stop(&scn->timer);
5339 bfa_sm_fault(scn->port->fcs, event);
5344 bfa_fcs_lport_scn_sm_online(struct bfa_fcs_lport_scn_s *scn,
5345 enum port_scn_event event)
5348 case SCNSM_EVENT_PORT_OFFLINE:
5349 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5353 bfa_sm_fault(scn->port->fcs, event);
5360 * fcs_scn_private FCS SCN private functions
5364 * This routine will be called to send a SCR command.
5367 bfa_fcs_lport_scn_send_scr(void *scn_cbarg, struct bfa_fcxp_s *fcxp_alloced)
5369 struct bfa_fcs_lport_scn_s *scn = scn_cbarg;
5370 struct bfa_fcs_lport_s *port = scn->port;
5373 struct bfa_fcxp_s *fcxp;
5375 bfa_trc(port->fcs, port->pid);
5376 bfa_trc(port->fcs, port->port_cfg.pwwn);
5378 fcxp = fcxp_alloced ? fcxp_alloced :
5379 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
5381 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &scn->fcxp_wqe,
5382 bfa_fcs_lport_scn_send_scr, scn, BFA_TRUE);
5387 /* Handle VU registrations for Base port only */
5388 if ((!port->vport) && bfa_ioc_get_fcmode(&port->fcs->bfa->ioc)) {
5389 len = fc_scr_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
5390 port->fabric->lps->brcd_switch,
5393 len = fc_scr_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
5398 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
5399 FC_CLASS_3, len, &fchs,
5400 bfa_fcs_lport_scn_scr_response,
5401 (void *)scn, FC_MAX_PDUSZ, FC_ELS_TOV);
5403 bfa_sm_send_event(scn, SCNSM_EVENT_SCR_SENT);
5407 bfa_fcs_lport_scn_scr_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
5408 void *cbarg, bfa_status_t req_status, u32 rsp_len,
5409 u32 resid_len, struct fchs_s *rsp_fchs)
5411 struct bfa_fcs_lport_scn_s *scn = (struct bfa_fcs_lport_scn_s *) cbarg;
5412 struct bfa_fcs_lport_s *port = scn->port;
5413 struct fc_els_cmd_s *els_cmd;
5414 struct fc_ls_rjt_s *ls_rjt;
5416 bfa_trc(port->fcs, port->port_cfg.pwwn);
5421 if (req_status != BFA_STATUS_OK) {
5422 bfa_trc(port->fcs, req_status);
5423 bfa_sm_send_event(scn, SCNSM_EVENT_RSP_ERROR);
5427 els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
5429 switch (els_cmd->els_code) {
5432 bfa_sm_send_event(scn, SCNSM_EVENT_RSP_OK);
5437 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
5439 bfa_trc(port->fcs, ls_rjt->reason_code);
5440 bfa_trc(port->fcs, ls_rjt->reason_code_expl);
5442 bfa_sm_send_event(scn, SCNSM_EVENT_RSP_ERROR);
5446 bfa_sm_send_event(scn, SCNSM_EVENT_RSP_ERROR);
5454 bfa_fcs_lport_scn_send_ls_acc(struct bfa_fcs_lport_s *port,
5455 struct fchs_s *rx_fchs)
5458 struct bfa_fcxp_s *fcxp;
5459 struct bfa_rport_s *bfa_rport = NULL;
5462 bfa_trc(port->fcs, rx_fchs->s_id);
5464 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
5468 len = fc_ls_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
5469 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
5472 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
5473 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
5478 * This routine will be called by bfa_timer on timer timeouts.
5480 * param[in] vport - pointer to bfa_fcs_lport_t.
5481 * param[out] vport_status - pointer to return vport status in
5486 * Special Considerations:
5491 bfa_fcs_lport_scn_timeout(void *arg)
5493 struct bfa_fcs_lport_scn_s *scn = (struct bfa_fcs_lport_scn_s *) arg;
5495 bfa_sm_send_event(scn, SCNSM_EVENT_TIMEOUT);
5501 * fcs_scn_public FCS state change notification public interfaces
5505 * Functions called by port/fab
5508 bfa_fcs_lport_scn_init(struct bfa_fcs_lport_s *port)
5510 struct bfa_fcs_lport_scn_s *scn = BFA_FCS_GET_SCN_FROM_PORT(port);
5513 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5517 bfa_fcs_lport_scn_offline(struct bfa_fcs_lport_s *port)
5519 struct bfa_fcs_lport_scn_s *scn = BFA_FCS_GET_SCN_FROM_PORT(port);
5522 bfa_sm_send_event(scn, SCNSM_EVENT_PORT_OFFLINE);
5526 bfa_fcs_lport_fab_scn_online(struct bfa_fcs_lport_s *port)
5528 struct bfa_fcs_lport_scn_s *scn = BFA_FCS_GET_SCN_FROM_PORT(port);
5531 bfa_sm_send_event(scn, SCNSM_EVENT_PORT_ONLINE);
5535 bfa_fcs_lport_scn_portid_rscn(struct bfa_fcs_lport_s *port, u32 rpid)
5537 struct bfa_fcs_rport_s *rport;
5538 struct bfa_fcs_fabric_s *fabric = port->fabric;
5539 struct bfa_fcs_vport_s *vport;
5540 struct list_head *qe;
5542 bfa_trc(port->fcs, rpid);
5545 * Ignore PID if it is of base port or of vports created on the
5546 * same base port. It is to avoid vports discovering base port or
5547 * other vports created on same base port as remote port
5549 if (rpid == fabric->bport.pid)
5552 list_for_each(qe, &fabric->vport_q) {
5553 vport = (struct bfa_fcs_vport_s *) qe;
5554 if (vport->lport.pid == rpid)
5558 * If this is an unknown device, then it just came online.
5559 * Otherwise let rport handle the RSCN event.
5561 rport = bfa_fcs_lport_get_rport_by_pid(port, rpid);
5563 rport = bfa_fcs_lport_get_rport_by_old_pid(port, rpid);
5565 if (rport == NULL) {
5567 * If min cfg mode is enabled, we donot need to
5568 * discover any new rports.
5570 if (!__fcs_min_cfg(port->fcs))
5571 rport = bfa_fcs_rport_create(port, rpid);
5573 bfa_fcs_rport_scn(rport);
5577 * rscn format based PID comparison
5579 #define __fc_pid_match(__c0, __c1, __fmt) \
5580 (((__fmt) == FC_RSCN_FORMAT_FABRIC) || \
5581 (((__fmt) == FC_RSCN_FORMAT_DOMAIN) && \
5582 ((__c0)[0] == (__c1)[0])) || \
5583 (((__fmt) == FC_RSCN_FORMAT_AREA) && \
5584 ((__c0)[0] == (__c1)[0]) && \
5585 ((__c0)[1] == (__c1)[1])))
5588 bfa_fcs_lport_scn_multiport_rscn(struct bfa_fcs_lport_s *port,
5589 enum fc_rscn_format format,
5592 struct bfa_fcs_rport_s *rport;
5593 struct list_head *qe, *qe_next;
5596 bfa_trc(port->fcs, format);
5597 bfa_trc(port->fcs, rscn_pid);
5599 c0 = (u8 *) &rscn_pid;
5601 list_for_each_safe(qe, qe_next, &port->rport_q) {
5602 rport = (struct bfa_fcs_rport_s *) qe;
5603 c1 = (u8 *) &rport->pid;
5604 if (__fc_pid_match(c0, c1, format))
5605 bfa_fcs_rport_scn(rport);
5611 bfa_fcs_lport_scn_process_rscn(struct bfa_fcs_lport_s *port,
5612 struct fchs_s *fchs, u32 len)
5614 struct fc_rscn_pl_s *rscn = (struct fc_rscn_pl_s *) (fchs + 1);
5617 bfa_boolean_t nsquery = BFA_FALSE, found;
5621 (be16_to_cpu(rscn->payldlen) -
5622 sizeof(u32)) / sizeof(rscn->event[0]);
5624 bfa_trc(port->fcs, num_entries);
5626 port->stats.num_rscn++;
5628 bfa_fcs_lport_scn_send_ls_acc(port, fchs);
5630 for (i = 0; i < num_entries; i++) {
5631 rscn_pid = rscn->event[i].portid;
5633 bfa_trc(port->fcs, rscn->event[i].format);
5634 bfa_trc(port->fcs, rscn_pid);
5636 /* check for duplicate entries in the list */
5638 for (j = 0; j < i; j++) {
5639 if (rscn->event[j].portid == rscn_pid) {
5645 /* if found in down the list, pid has been already processed */
5647 bfa_trc(port->fcs, rscn_pid);
5651 switch (rscn->event[i].format) {
5652 case FC_RSCN_FORMAT_PORTID:
5653 if (rscn->event[i].qualifier == FC_QOS_RSCN_EVENT) {
5655 * Ignore this event.
5656 * f/w would have processed it
5658 bfa_trc(port->fcs, rscn_pid);
5660 port->stats.num_portid_rscn++;
5661 bfa_fcs_lport_scn_portid_rscn(port, rscn_pid);
5665 case FC_RSCN_FORMAT_FABRIC:
5666 if (rscn->event[i].qualifier ==
5667 FC_FABRIC_NAME_RSCN_EVENT) {
5668 bfa_fcs_lport_ms_fabric_rscn(port);
5671 /* !!!!!!!!! Fall Through !!!!!!!!!!!!! */
5673 case FC_RSCN_FORMAT_AREA:
5674 case FC_RSCN_FORMAT_DOMAIN:
5676 bfa_fcs_lport_scn_multiport_rscn(port,
5677 rscn->event[i].format,
5689 * If any of area, domain or fabric RSCN is received, do a fresh
5690 * discovery to find new devices.
5693 bfa_fcs_lport_ns_query(port);
5700 * fcs_port_api BFA FCS port API
5702 struct bfa_fcs_lport_s *
5703 bfa_fcs_get_base_port(struct bfa_fcs_s *fcs)
5705 return &fcs->fabric.bport;
5709 bfa_fcs_lport_get_rport(struct bfa_fcs_lport_s *port, wwn_t wwn, int index,
5710 int nrports, bfa_boolean_t bwwn)
5712 struct list_head *qh, *qe;
5713 struct bfa_fcs_rport_s *rport = NULL;
5715 struct bfa_fcs_s *fcs;
5717 if (port == NULL || nrports == 0)
5721 bfa_trc(fcs, (u32) nrports);
5724 qh = &port->rport_q;
5725 qe = bfa_q_first(qh);
5727 while ((qe != qh) && (i < nrports)) {
5728 rport = (struct bfa_fcs_rport_s *) qe;
5729 if (bfa_ntoh3b(rport->pid) > 0xFFF000) {
5730 qe = bfa_q_next(qe);
5731 bfa_trc(fcs, (u32) rport->pwwn);
5732 bfa_trc(fcs, rport->pid);
5738 if (!memcmp(&wwn, &rport->pwwn, 8))
5746 qe = bfa_q_next(qe);
5757 bfa_fcs_lport_get_rport_quals(struct bfa_fcs_lport_s *port,
5758 struct bfa_rport_qualifier_s rports[], int *nrports)
5760 struct list_head *qh, *qe;
5761 struct bfa_fcs_rport_s *rport = NULL;
5763 struct bfa_fcs_s *fcs;
5765 if (port == NULL || rports == NULL || *nrports == 0)
5769 bfa_trc(fcs, (u32) *nrports);
5772 qh = &port->rport_q;
5773 qe = bfa_q_first(qh);
5775 while ((qe != qh) && (i < *nrports)) {
5776 rport = (struct bfa_fcs_rport_s *) qe;
5777 if (bfa_ntoh3b(rport->pid) > 0xFFF000) {
5778 qe = bfa_q_next(qe);
5779 bfa_trc(fcs, (u32) rport->pwwn);
5780 bfa_trc(fcs, rport->pid);
5785 if (!rport->pwwn && !rport->pid) {
5786 qe = bfa_q_next(qe);
5790 rports[i].pwwn = rport->pwwn;
5791 rports[i].pid = rport->pid;
5794 qe = bfa_q_next(qe);
5802 * Iterate's through all the rport's in the given port to
5803 * determine the maximum operating speed.
5805 * !!!! To be used in TRL Functionality only !!!!
5808 bfa_fcs_lport_get_rport_max_speed(bfa_fcs_lport_t *port)
5810 struct list_head *qh, *qe;
5811 struct bfa_fcs_rport_s *rport = NULL;
5812 struct bfa_fcs_s *fcs;
5813 bfa_port_speed_t max_speed = 0;
5814 struct bfa_port_attr_s port_attr;
5815 bfa_port_speed_t port_speed, rport_speed;
5816 bfa_boolean_t trl_enabled;
5822 trl_enabled = bfa_fcport_is_ratelim(port->fcs->bfa);
5824 /* Get Physical port's current speed */
5825 bfa_fcport_get_attr(port->fcs->bfa, &port_attr);
5826 port_speed = port_attr.speed;
5827 bfa_trc(fcs, port_speed);
5829 qh = &port->rport_q;
5830 qe = bfa_q_first(qh);
5833 rport = (struct bfa_fcs_rport_s *) qe;
5834 if ((bfa_ntoh3b(rport->pid) > 0xFFF000) ||
5835 (bfa_fcs_rport_get_state(rport) == BFA_RPORT_OFFLINE) ||
5836 (rport->scsi_function != BFA_RPORT_TARGET)) {
5837 qe = bfa_q_next(qe);
5841 rport_speed = rport->rpf.rpsc_speed;
5842 if ((trl_enabled) && (rport_speed ==
5843 BFA_PORT_SPEED_UNKNOWN)) {
5844 /* Use default ratelim speed setting */
5846 bfa_fcport_get_ratelim_speed(port->fcs->bfa);
5849 if (rport_speed > max_speed)
5850 max_speed = rport_speed;
5852 qe = bfa_q_next(qe);
5855 if (max_speed > port_speed)
5856 max_speed = port_speed;
5858 bfa_trc(fcs, max_speed);
5862 struct bfa_fcs_lport_s *
5863 bfa_fcs_lookup_port(struct bfa_fcs_s *fcs, u16 vf_id, wwn_t lpwwn)
5865 struct bfa_fcs_vport_s *vport;
5868 WARN_ON(fcs == NULL);
5870 vf = bfa_fcs_vf_lookup(fcs, vf_id);
5872 bfa_trc(fcs, vf_id);
5876 if (!lpwwn || (vf->bport.port_cfg.pwwn == lpwwn))
5879 vport = bfa_fcs_fabric_vport_lookup(vf, lpwwn);
5881 return &vport->lport;
5887 * API corresponding to NPIV_VPORT_GETINFO.
5890 bfa_fcs_lport_get_info(struct bfa_fcs_lport_s *port,
5891 struct bfa_lport_info_s *port_info)
5894 bfa_trc(port->fcs, port->fabric->fabric_name);
5896 if (port->vport == NULL) {
5898 * This is a Physical port
5900 port_info->port_type = BFA_LPORT_TYPE_PHYSICAL;
5903 * @todo : need to fix the state & reason
5905 port_info->port_state = 0;
5906 port_info->offline_reason = 0;
5908 port_info->port_wwn = bfa_fcs_lport_get_pwwn(port);
5909 port_info->node_wwn = bfa_fcs_lport_get_nwwn(port);
5911 port_info->max_vports_supp =
5912 bfa_lps_get_max_vport(port->fcs->bfa);
5913 port_info->num_vports_inuse =
5914 port->fabric->num_vports;
5915 port_info->max_rports_supp = BFA_FCS_MAX_RPORTS_SUPP;
5916 port_info->num_rports_inuse = port->num_rports;
5919 * This is a virtual port
5921 port_info->port_type = BFA_LPORT_TYPE_VIRTUAL;
5924 * @todo : need to fix the state & reason
5926 port_info->port_state = 0;
5927 port_info->offline_reason = 0;
5929 port_info->port_wwn = bfa_fcs_lport_get_pwwn(port);
5930 port_info->node_wwn = bfa_fcs_lport_get_nwwn(port);
5935 bfa_fcs_lport_get_stats(struct bfa_fcs_lport_s *fcs_port,
5936 struct bfa_lport_stats_s *port_stats)
5938 *port_stats = fcs_port->stats;
5942 bfa_fcs_lport_clear_stats(struct bfa_fcs_lport_s *fcs_port)
5944 memset(&fcs_port->stats, 0, sizeof(struct bfa_lport_stats_s));
5948 * Let new loop map create missing rports
5951 bfa_fcs_lport_lip_scn_online(struct bfa_fcs_lport_s *port)
5953 bfa_fcs_lport_loop_online(port);
5957 * FCS virtual port state machine
5960 #define __vport_fcs(__vp) ((__vp)->lport.fcs)
5961 #define __vport_pwwn(__vp) ((__vp)->lport.port_cfg.pwwn)
5962 #define __vport_nwwn(__vp) ((__vp)->lport.port_cfg.nwwn)
5963 #define __vport_bfa(__vp) ((__vp)->lport.fcs->bfa)
5964 #define __vport_fcid(__vp) ((__vp)->lport.pid)
5965 #define __vport_fabric(__vp) ((__vp)->lport.fabric)
5966 #define __vport_vfid(__vp) ((__vp)->lport.fabric->vf_id)
5968 #define BFA_FCS_VPORT_MAX_RETRIES 5
5970 * Forward declarations
5972 static void bfa_fcs_vport_do_fdisc(struct bfa_fcs_vport_s *vport);
5973 static void bfa_fcs_vport_timeout(void *vport_arg);
5974 static void bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s *vport);
5975 static void bfa_fcs_vport_free(struct bfa_fcs_vport_s *vport);
5978 * fcs_vport_sm FCS virtual port state machine
5982 * VPort State Machine events
5984 enum bfa_fcs_vport_event {
5985 BFA_FCS_VPORT_SM_CREATE = 1, /* vport create event */
5986 BFA_FCS_VPORT_SM_DELETE = 2, /* vport delete event */
5987 BFA_FCS_VPORT_SM_START = 3, /* vport start request */
5988 BFA_FCS_VPORT_SM_STOP = 4, /* stop: unsupported */
5989 BFA_FCS_VPORT_SM_ONLINE = 5, /* fabric online */
5990 BFA_FCS_VPORT_SM_OFFLINE = 6, /* fabric offline event */
5991 BFA_FCS_VPORT_SM_FRMSENT = 7, /* fdisc/logo sent events */
5992 BFA_FCS_VPORT_SM_RSP_OK = 8, /* good response */
5993 BFA_FCS_VPORT_SM_RSP_ERROR = 9, /* error/bad response */
5994 BFA_FCS_VPORT_SM_TIMEOUT = 10, /* delay timer event */
5995 BFA_FCS_VPORT_SM_DELCOMP = 11, /* lport delete completion */
5996 BFA_FCS_VPORT_SM_RSP_DUP_WWN = 12, /* Dup wnn error*/
5997 BFA_FCS_VPORT_SM_RSP_FAILED = 13, /* non-retryable failure */
5998 BFA_FCS_VPORT_SM_STOPCOMP = 14, /* vport delete completion */
5999 BFA_FCS_VPORT_SM_FABRIC_MAX = 15, /* max vports on fabric */
6002 static void bfa_fcs_vport_sm_uninit(struct bfa_fcs_vport_s *vport,
6003 enum bfa_fcs_vport_event event);
6004 static void bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s *vport,
6005 enum bfa_fcs_vport_event event);
6006 static void bfa_fcs_vport_sm_offline(struct bfa_fcs_vport_s *vport,
6007 enum bfa_fcs_vport_event event);
6008 static void bfa_fcs_vport_sm_fdisc(struct bfa_fcs_vport_s *vport,
6009 enum bfa_fcs_vport_event event);
6010 static void bfa_fcs_vport_sm_fdisc_retry(struct bfa_fcs_vport_s *vport,
6011 enum bfa_fcs_vport_event event);
6012 static void bfa_fcs_vport_sm_fdisc_rsp_wait(struct bfa_fcs_vport_s *vport,
6013 enum bfa_fcs_vport_event event);
6014 static void bfa_fcs_vport_sm_online(struct bfa_fcs_vport_s *vport,
6015 enum bfa_fcs_vport_event event);
6016 static void bfa_fcs_vport_sm_deleting(struct bfa_fcs_vport_s *vport,
6017 enum bfa_fcs_vport_event event);
6018 static void bfa_fcs_vport_sm_cleanup(struct bfa_fcs_vport_s *vport,
6019 enum bfa_fcs_vport_event event);
6020 static void bfa_fcs_vport_sm_logo(struct bfa_fcs_vport_s *vport,
6021 enum bfa_fcs_vport_event event);
6022 static void bfa_fcs_vport_sm_error(struct bfa_fcs_vport_s *vport,
6023 enum bfa_fcs_vport_event event);
6024 static void bfa_fcs_vport_sm_stopping(struct bfa_fcs_vport_s *vport,
6025 enum bfa_fcs_vport_event event);
6026 static void bfa_fcs_vport_sm_logo_for_stop(struct bfa_fcs_vport_s *vport,
6027 enum bfa_fcs_vport_event event);
6029 static struct bfa_sm_table_s vport_sm_table[] = {
6030 {BFA_SM(bfa_fcs_vport_sm_uninit), BFA_FCS_VPORT_UNINIT},
6031 {BFA_SM(bfa_fcs_vport_sm_created), BFA_FCS_VPORT_CREATED},
6032 {BFA_SM(bfa_fcs_vport_sm_offline), BFA_FCS_VPORT_OFFLINE},
6033 {BFA_SM(bfa_fcs_vport_sm_fdisc), BFA_FCS_VPORT_FDISC},
6034 {BFA_SM(bfa_fcs_vport_sm_fdisc_retry), BFA_FCS_VPORT_FDISC_RETRY},
6035 {BFA_SM(bfa_fcs_vport_sm_fdisc_rsp_wait), BFA_FCS_VPORT_FDISC_RSP_WAIT},
6036 {BFA_SM(bfa_fcs_vport_sm_online), BFA_FCS_VPORT_ONLINE},
6037 {BFA_SM(bfa_fcs_vport_sm_deleting), BFA_FCS_VPORT_DELETING},
6038 {BFA_SM(bfa_fcs_vport_sm_cleanup), BFA_FCS_VPORT_CLEANUP},
6039 {BFA_SM(bfa_fcs_vport_sm_logo), BFA_FCS_VPORT_LOGO},
6040 {BFA_SM(bfa_fcs_vport_sm_error), BFA_FCS_VPORT_ERROR}
6047 bfa_fcs_vport_sm_uninit(struct bfa_fcs_vport_s *vport,
6048 enum bfa_fcs_vport_event event)
6050 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6051 bfa_trc(__vport_fcs(vport), event);
6054 case BFA_FCS_VPORT_SM_CREATE:
6055 bfa_sm_set_state(vport, bfa_fcs_vport_sm_created);
6056 bfa_fcs_fabric_addvport(__vport_fabric(vport), vport);
6060 bfa_sm_fault(__vport_fcs(vport), event);
6065 * Created state - a start event is required to start up the state machine.
6068 bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s *vport,
6069 enum bfa_fcs_vport_event event)
6071 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6072 bfa_trc(__vport_fcs(vport), event);
6075 case BFA_FCS_VPORT_SM_START:
6076 if (bfa_sm_cmp_state(__vport_fabric(vport),
6077 bfa_fcs_fabric_sm_online)
6078 && bfa_fcs_fabric_npiv_capable(__vport_fabric(vport))) {
6079 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
6080 bfa_fcs_vport_do_fdisc(vport);
6083 * Fabric is offline or not NPIV capable, stay in
6086 vport->vport_stats.fab_no_npiv++;
6087 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
6091 case BFA_FCS_VPORT_SM_DELETE:
6092 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6093 bfa_fcs_lport_delete(&vport->lport);
6096 case BFA_FCS_VPORT_SM_ONLINE:
6097 case BFA_FCS_VPORT_SM_OFFLINE:
6099 * Ignore ONLINE/OFFLINE events from fabric
6100 * till vport is started.
6105 bfa_sm_fault(__vport_fcs(vport), event);
6110 * Offline state - awaiting ONLINE event from fabric SM.
6113 bfa_fcs_vport_sm_offline(struct bfa_fcs_vport_s *vport,
6114 enum bfa_fcs_vport_event event)
6116 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6117 bfa_trc(__vport_fcs(vport), event);
6120 case BFA_FCS_VPORT_SM_DELETE:
6121 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6122 bfa_fcs_lport_delete(&vport->lport);
6125 case BFA_FCS_VPORT_SM_ONLINE:
6126 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
6127 vport->fdisc_retries = 0;
6128 bfa_fcs_vport_do_fdisc(vport);
6131 case BFA_FCS_VPORT_SM_STOP:
6132 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6133 bfa_sm_send_event(&vport->lport, BFA_FCS_PORT_SM_STOP);
6136 case BFA_FCS_VPORT_SM_OFFLINE:
6138 * This can happen if the vport couldn't be initialzied
6139 * due the fact that the npiv was not enabled on the switch.
6140 * In that case we will put the vport in offline state.
6141 * However, the link can go down and cause the this event to
6142 * be sent when we are already offline. Ignore it.
6147 bfa_sm_fault(__vport_fcs(vport), event);
6153 * FDISC is sent and awaiting reply from fabric.
6156 bfa_fcs_vport_sm_fdisc(struct bfa_fcs_vport_s *vport,
6157 enum bfa_fcs_vport_event event)
6159 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6160 bfa_trc(__vport_fcs(vport), event);
6163 case BFA_FCS_VPORT_SM_DELETE:
6164 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc_rsp_wait);
6167 case BFA_FCS_VPORT_SM_OFFLINE:
6168 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
6169 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
6172 case BFA_FCS_VPORT_SM_RSP_OK:
6173 bfa_sm_set_state(vport, bfa_fcs_vport_sm_online);
6174 bfa_fcs_lport_online(&vport->lport);
6177 case BFA_FCS_VPORT_SM_RSP_ERROR:
6178 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc_retry);
6179 bfa_timer_start(__vport_bfa(vport), &vport->timer,
6180 bfa_fcs_vport_timeout, vport,
6181 BFA_FCS_RETRY_TIMEOUT);
6184 case BFA_FCS_VPORT_SM_RSP_FAILED:
6185 case BFA_FCS_VPORT_SM_FABRIC_MAX:
6186 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
6189 case BFA_FCS_VPORT_SM_RSP_DUP_WWN:
6190 bfa_sm_set_state(vport, bfa_fcs_vport_sm_error);
6194 bfa_sm_fault(__vport_fcs(vport), event);
6199 * FDISC attempt failed - a timer is active to retry FDISC.
6202 bfa_fcs_vport_sm_fdisc_retry(struct bfa_fcs_vport_s *vport,
6203 enum bfa_fcs_vport_event event)
6205 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6206 bfa_trc(__vport_fcs(vport), event);
6209 case BFA_FCS_VPORT_SM_DELETE:
6210 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6211 bfa_timer_stop(&vport->timer);
6212 bfa_fcs_lport_delete(&vport->lport);
6215 case BFA_FCS_VPORT_SM_OFFLINE:
6216 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
6217 bfa_timer_stop(&vport->timer);
6220 case BFA_FCS_VPORT_SM_TIMEOUT:
6221 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
6222 vport->vport_stats.fdisc_retries++;
6223 vport->fdisc_retries++;
6224 bfa_fcs_vport_do_fdisc(vport);
6228 bfa_sm_fault(__vport_fcs(vport), event);
6233 * FDISC is in progress and we got a vport delete request -
6234 * this is a wait state while we wait for fdisc response and
6235 * we will transition to the appropriate state - on rsp status.
6238 bfa_fcs_vport_sm_fdisc_rsp_wait(struct bfa_fcs_vport_s *vport,
6239 enum bfa_fcs_vport_event event)
6241 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6242 bfa_trc(__vport_fcs(vport), event);
6245 case BFA_FCS_VPORT_SM_RSP_OK:
6246 bfa_sm_set_state(vport, bfa_fcs_vport_sm_deleting);
6247 bfa_fcs_lport_delete(&vport->lport);
6250 case BFA_FCS_VPORT_SM_DELETE:
6253 case BFA_FCS_VPORT_SM_OFFLINE:
6254 case BFA_FCS_VPORT_SM_RSP_ERROR:
6255 case BFA_FCS_VPORT_SM_RSP_FAILED:
6256 case BFA_FCS_VPORT_SM_FABRIC_MAX:
6257 case BFA_FCS_VPORT_SM_RSP_DUP_WWN:
6258 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6259 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
6260 bfa_fcs_lport_delete(&vport->lport);
6264 bfa_sm_fault(__vport_fcs(vport), event);
6269 * Vport is online (FDISC is complete).
6272 bfa_fcs_vport_sm_online(struct bfa_fcs_vport_s *vport,
6273 enum bfa_fcs_vport_event event)
6275 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6276 bfa_trc(__vport_fcs(vport), event);
6279 case BFA_FCS_VPORT_SM_DELETE:
6280 bfa_sm_set_state(vport, bfa_fcs_vport_sm_deleting);
6281 bfa_fcs_lport_delete(&vport->lport);
6284 case BFA_FCS_VPORT_SM_STOP:
6285 bfa_sm_set_state(vport, bfa_fcs_vport_sm_stopping);
6286 bfa_sm_send_event(&vport->lport, BFA_FCS_PORT_SM_STOP);
6289 case BFA_FCS_VPORT_SM_OFFLINE:
6290 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
6291 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
6292 bfa_fcs_lport_offline(&vport->lport);
6296 bfa_sm_fault(__vport_fcs(vport), event);
6301 * Vport is being stopped - awaiting lport stop completion to send
6305 bfa_fcs_vport_sm_stopping(struct bfa_fcs_vport_s *vport,
6306 enum bfa_fcs_vport_event event)
6308 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6309 bfa_trc(__vport_fcs(vport), event);
6312 case BFA_FCS_VPORT_SM_STOPCOMP:
6313 bfa_sm_set_state(vport, bfa_fcs_vport_sm_logo_for_stop);
6314 bfa_fcs_vport_do_logo(vport);
6317 case BFA_FCS_VPORT_SM_OFFLINE:
6318 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6322 bfa_sm_fault(__vport_fcs(vport), event);
6327 * Vport is being deleted - awaiting lport delete completion to send
6331 bfa_fcs_vport_sm_deleting(struct bfa_fcs_vport_s *vport,
6332 enum bfa_fcs_vport_event event)
6334 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6335 bfa_trc(__vport_fcs(vport), event);
6338 case BFA_FCS_VPORT_SM_DELETE:
6341 case BFA_FCS_VPORT_SM_DELCOMP:
6342 bfa_sm_set_state(vport, bfa_fcs_vport_sm_logo);
6343 bfa_fcs_vport_do_logo(vport);
6346 case BFA_FCS_VPORT_SM_OFFLINE:
6347 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6351 bfa_sm_fault(__vport_fcs(vport), event);
6357 * This state will be set when the Vport Creation fails due
6358 * to errors like Dup WWN. In this state only operation allowed
6359 * is a Vport Delete.
6362 bfa_fcs_vport_sm_error(struct bfa_fcs_vport_s *vport,
6363 enum bfa_fcs_vport_event event)
6365 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6366 bfa_trc(__vport_fcs(vport), event);
6369 case BFA_FCS_VPORT_SM_DELETE:
6370 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6371 bfa_fcs_lport_delete(&vport->lport);
6375 bfa_trc(__vport_fcs(vport), event);
6380 * Lport cleanup is in progress since vport is being deleted. Fabric is
6381 * offline, so no LOGO is needed to complete vport deletion.
6384 bfa_fcs_vport_sm_cleanup(struct bfa_fcs_vport_s *vport,
6385 enum bfa_fcs_vport_event event)
6387 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6388 bfa_trc(__vport_fcs(vport), event);
6391 case BFA_FCS_VPORT_SM_DELCOMP:
6392 bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
6393 bfa_fcs_vport_free(vport);
6396 case BFA_FCS_VPORT_SM_STOPCOMP:
6397 bfa_sm_set_state(vport, bfa_fcs_vport_sm_created);
6400 case BFA_FCS_VPORT_SM_DELETE:
6404 bfa_sm_fault(__vport_fcs(vport), event);
6409 * LOGO is sent to fabric. Vport stop is in progress. Lport stop cleanup
6413 bfa_fcs_vport_sm_logo_for_stop(struct bfa_fcs_vport_s *vport,
6414 enum bfa_fcs_vport_event event)
6416 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6417 bfa_trc(__vport_fcs(vport), event);
6420 case BFA_FCS_VPORT_SM_OFFLINE:
6421 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
6423 * !!! fall through !!!
6426 case BFA_FCS_VPORT_SM_RSP_OK:
6427 case BFA_FCS_VPORT_SM_RSP_ERROR:
6428 bfa_sm_set_state(vport, bfa_fcs_vport_sm_created);
6432 bfa_sm_fault(__vport_fcs(vport), event);
6437 * LOGO is sent to fabric. Vport delete is in progress. Lport delete cleanup
6441 bfa_fcs_vport_sm_logo(struct bfa_fcs_vport_s *vport,
6442 enum bfa_fcs_vport_event event)
6444 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6445 bfa_trc(__vport_fcs(vport), event);
6448 case BFA_FCS_VPORT_SM_OFFLINE:
6449 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
6451 * !!! fall through !!!
6454 case BFA_FCS_VPORT_SM_RSP_OK:
6455 case BFA_FCS_VPORT_SM_RSP_ERROR:
6456 bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
6457 bfa_fcs_vport_free(vport);
6460 case BFA_FCS_VPORT_SM_DELETE:
6464 bfa_sm_fault(__vport_fcs(vport), event);
6471 * fcs_vport_private FCS virtual port private functions
6474 * Send AEN notification
6477 bfa_fcs_vport_aen_post(struct bfa_fcs_lport_s *port,
6478 enum bfa_lport_aen_event event)
6480 struct bfad_s *bfad = (struct bfad_s *)port->fabric->fcs->bfad;
6481 struct bfa_aen_entry_s *aen_entry;
6483 bfad_get_aen_entry(bfad, aen_entry);
6487 aen_entry->aen_data.lport.vf_id = port->fabric->vf_id;
6488 aen_entry->aen_data.lport.roles = port->port_cfg.roles;
6489 aen_entry->aen_data.lport.ppwwn = bfa_fcs_lport_get_pwwn(
6490 bfa_fcs_get_base_port(port->fcs));
6491 aen_entry->aen_data.lport.lpwwn = bfa_fcs_lport_get_pwwn(port);
6493 /* Send the AEN notification */
6494 bfad_im_post_vendor_event(aen_entry, bfad, ++port->fcs->fcs_aen_seq,
6495 BFA_AEN_CAT_LPORT, event);
6499 * This routine will be called to send a FDISC command.
6502 bfa_fcs_vport_do_fdisc(struct bfa_fcs_vport_s *vport)
6504 bfa_lps_fdisc(vport->lps, vport,
6505 bfa_fcport_get_maxfrsize(__vport_bfa(vport)),
6506 __vport_pwwn(vport), __vport_nwwn(vport));
6507 vport->vport_stats.fdisc_sent++;
6511 bfa_fcs_vport_fdisc_rejected(struct bfa_fcs_vport_s *vport)
6513 u8 lsrjt_rsn = vport->lps->lsrjt_rsn;
6514 u8 lsrjt_expl = vport->lps->lsrjt_expl;
6516 bfa_trc(__vport_fcs(vport), lsrjt_rsn);
6517 bfa_trc(__vport_fcs(vport), lsrjt_expl);
6519 /* For certain reason codes, we don't want to retry. */
6520 switch (vport->lps->lsrjt_expl) {
6521 case FC_LS_RJT_EXP_INV_PORT_NAME: /* by brocade */
6522 case FC_LS_RJT_EXP_INVALID_NPORT_ID: /* by Cisco */
6523 if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
6524 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6526 bfa_fcs_vport_aen_post(&vport->lport,
6527 BFA_LPORT_AEN_NPIV_DUP_WWN);
6528 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_DUP_WWN);
6532 case FC_LS_RJT_EXP_INSUFF_RES:
6534 * This means max logins per port/switch setting on the
6535 * switch was exceeded.
6537 if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
6538 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6540 bfa_fcs_vport_aen_post(&vport->lport,
6541 BFA_LPORT_AEN_NPIV_FABRIC_MAX);
6542 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_FABRIC_MAX);
6547 if (vport->fdisc_retries == 0)
6548 bfa_fcs_vport_aen_post(&vport->lport,
6549 BFA_LPORT_AEN_NPIV_UNKNOWN);
6550 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6555 * Called to send a logout to the fabric. Used when a V-Port is
6559 bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s *vport)
6561 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6563 vport->vport_stats.logo_sent++;
6564 bfa_lps_fdisclogo(vport->lps);
6569 * This routine will be called by bfa_timer on timer timeouts.
6571 * param[in] vport - pointer to bfa_fcs_vport_t.
6572 * param[out] vport_status - pointer to return vport status in
6577 * Special Considerations:
6582 bfa_fcs_vport_timeout(void *vport_arg)
6584 struct bfa_fcs_vport_s *vport = (struct bfa_fcs_vport_s *) vport_arg;
6586 vport->vport_stats.fdisc_timeouts++;
6587 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_TIMEOUT);
6591 bfa_fcs_vport_free(struct bfa_fcs_vport_s *vport)
6593 struct bfad_vport_s *vport_drv =
6594 (struct bfad_vport_s *)vport->vport_drv;
6596 bfa_fcs_fabric_delvport(__vport_fabric(vport), vport);
6597 bfa_lps_delete(vport->lps);
6599 if (vport_drv->comp_del) {
6600 complete(vport_drv->comp_del);
6605 * We queue the vport delete work to the IM work_q from here.
6606 * The memory for the bfad_vport_s is freed from the FC function
6607 * template vport_delete entry point.
6609 bfad_im_port_delete(vport_drv->drv_port.bfad, &vport_drv->drv_port);
6613 * fcs_vport_public FCS virtual port public interfaces
6617 * Online notification from fabric SM.
6620 bfa_fcs_vport_online(struct bfa_fcs_vport_s *vport)
6622 vport->vport_stats.fab_online++;
6623 if (bfa_fcs_fabric_npiv_capable(__vport_fabric(vport)))
6624 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_ONLINE);
6626 vport->vport_stats.fab_no_npiv++;
6630 * Offline notification from fabric SM.
6633 bfa_fcs_vport_offline(struct bfa_fcs_vport_s *vport)
6635 vport->vport_stats.fab_offline++;
6636 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_OFFLINE);
6640 * Cleanup notification from fabric SM on link timer expiry.
6643 bfa_fcs_vport_cleanup(struct bfa_fcs_vport_s *vport)
6645 vport->vport_stats.fab_cleanup++;
6649 * Stop notification from fabric SM. To be invoked from within FCS.
6652 bfa_fcs_vport_fcs_stop(struct bfa_fcs_vport_s *vport)
6654 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOP);
6658 * delete notification from fabric SM. To be invoked from within FCS.
6661 bfa_fcs_vport_fcs_delete(struct bfa_fcs_vport_s *vport)
6663 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELETE);
6667 * Stop completion callback from associated lport
6670 bfa_fcs_vport_stop_comp(struct bfa_fcs_vport_s *vport)
6672 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOPCOMP);
6676 * Delete completion callback from associated lport
6679 bfa_fcs_vport_delete_comp(struct bfa_fcs_vport_s *vport)
6681 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELCOMP);
6687 * fcs_vport_api Virtual port API
6691 * Use this function to instantiate a new FCS vport object. This
6692 * function will not trigger any HW initialization process (which will be
6693 * done in vport_start() call)
6695 * param[in] vport - pointer to bfa_fcs_vport_t. This space
6696 * needs to be allocated by the driver.
6697 * param[in] fcs - FCS instance
6698 * param[in] vport_cfg - vport configuration
6699 * param[in] vf_id - VF_ID if vport is created within a VF.
6700 * FC_VF_ID_NULL to specify base fabric.
6701 * param[in] vport_drv - Opaque handle back to the driver's vport
6704 * retval BFA_STATUS_OK - on success.
6705 * retval BFA_STATUS_FAILED - on failure.
6708 bfa_fcs_vport_create(struct bfa_fcs_vport_s *vport, struct bfa_fcs_s *fcs,
6709 u16 vf_id, struct bfa_lport_cfg_s *vport_cfg,
6710 struct bfad_vport_s *vport_drv)
6712 if (vport_cfg->pwwn == 0)
6713 return BFA_STATUS_INVALID_WWN;
6715 if (bfa_fcs_lport_get_pwwn(&fcs->fabric.bport) == vport_cfg->pwwn)
6716 return BFA_STATUS_VPORT_WWN_BP;
6718 if (bfa_fcs_vport_lookup(fcs, vf_id, vport_cfg->pwwn) != NULL)
6719 return BFA_STATUS_VPORT_EXISTS;
6721 if (fcs->fabric.num_vports ==
6722 bfa_lps_get_max_vport(fcs->bfa))
6723 return BFA_STATUS_VPORT_MAX;
6725 vport->lps = bfa_lps_alloc(fcs->bfa);
6727 return BFA_STATUS_VPORT_MAX;
6729 vport->vport_drv = vport_drv;
6730 vport_cfg->preboot_vp = BFA_FALSE;
6732 bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
6733 bfa_fcs_lport_attach(&vport->lport, fcs, vf_id, vport);
6734 bfa_fcs_lport_init(&vport->lport, vport_cfg);
6735 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_CREATE);
6737 return BFA_STATUS_OK;
6741 * Use this function to instantiate a new FCS PBC vport object. This
6742 * function will not trigger any HW initialization process (which will be
6743 * done in vport_start() call)
6745 * param[in] vport - pointer to bfa_fcs_vport_t. This space
6746 * needs to be allocated by the driver.
6747 * param[in] fcs - FCS instance
6748 * param[in] vport_cfg - vport configuration
6749 * param[in] vf_id - VF_ID if vport is created within a VF.
6750 * FC_VF_ID_NULL to specify base fabric.
6751 * param[in] vport_drv - Opaque handle back to the driver's vport
6754 * retval BFA_STATUS_OK - on success.
6755 * retval BFA_STATUS_FAILED - on failure.
6758 bfa_fcs_pbc_vport_create(struct bfa_fcs_vport_s *vport, struct bfa_fcs_s *fcs,
6759 u16 vf_id, struct bfa_lport_cfg_s *vport_cfg,
6760 struct bfad_vport_s *vport_drv)
6764 rc = bfa_fcs_vport_create(vport, fcs, vf_id, vport_cfg, vport_drv);
6765 vport->lport.port_cfg.preboot_vp = BFA_TRUE;
6771 * Use this function to findout if this is a pbc vport or not.
6773 * @param[in] vport - pointer to bfa_fcs_vport_t.
6778 bfa_fcs_is_pbc_vport(struct bfa_fcs_vport_s *vport)
6781 if (vport && (vport->lport.port_cfg.preboot_vp == BFA_TRUE))
6789 * Use this function initialize the vport.
6791 * @param[in] vport - pointer to bfa_fcs_vport_t.
6796 bfa_fcs_vport_start(struct bfa_fcs_vport_s *vport)
6798 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_START);
6800 return BFA_STATUS_OK;
6804 * Use this function quiese the vport object. This function will return
6805 * immediately, when the vport is actually stopped, the
6806 * bfa_drv_vport_stop_cb() will be called.
6808 * param[in] vport - pointer to bfa_fcs_vport_t.
6813 bfa_fcs_vport_stop(struct bfa_fcs_vport_s *vport)
6815 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOP);
6817 return BFA_STATUS_OK;
6821 * Use this function to delete a vport object. Fabric object should
6822 * be stopped before this function call.
6824 * !!!!!!! Donot invoke this from within FCS !!!!!!!
6826 * param[in] vport - pointer to bfa_fcs_vport_t.
6831 bfa_fcs_vport_delete(struct bfa_fcs_vport_s *vport)
6834 if (vport->lport.port_cfg.preboot_vp)
6835 return BFA_STATUS_PBC;
6837 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELETE);
6839 return BFA_STATUS_OK;
6843 * Use this function to get vport's current status info.
6845 * param[in] vport pointer to bfa_fcs_vport_t.
6846 * param[out] attr pointer to return vport attributes
6851 bfa_fcs_vport_get_attr(struct bfa_fcs_vport_s *vport,
6852 struct bfa_vport_attr_s *attr)
6854 if (vport == NULL || attr == NULL)
6857 memset(attr, 0, sizeof(struct bfa_vport_attr_s));
6859 bfa_fcs_lport_get_attr(&vport->lport, &attr->port_attr);
6860 attr->vport_state = bfa_sm_to_state(vport_sm_table, vport->sm);
6865 * Lookup a virtual port. Excludes base port from lookup.
6867 struct bfa_fcs_vport_s *
6868 bfa_fcs_vport_lookup(struct bfa_fcs_s *fcs, u16 vf_id, wwn_t vpwwn)
6870 struct bfa_fcs_vport_s *vport;
6871 struct bfa_fcs_fabric_s *fabric;
6873 bfa_trc(fcs, vf_id);
6874 bfa_trc(fcs, vpwwn);
6876 fabric = bfa_fcs_vf_lookup(fcs, vf_id);
6878 bfa_trc(fcs, vf_id);
6882 vport = bfa_fcs_fabric_vport_lookup(fabric, vpwwn);
6890 bfa_cb_lps_fdisc_comp(void *bfad, void *uarg, bfa_status_t status)
6892 struct bfa_fcs_vport_s *vport = uarg;
6894 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6895 bfa_trc(__vport_fcs(vport), status);
6900 * Initialize the V-Port fields
6902 __vport_fcid(vport) = vport->lps->lp_pid;
6903 vport->vport_stats.fdisc_accepts++;
6904 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_OK);
6907 case BFA_STATUS_INVALID_MAC:
6909 vport->vport_stats.fdisc_acc_bad++;
6910 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6914 case BFA_STATUS_EPROTOCOL:
6915 switch (vport->lps->ext_status) {
6916 case BFA_EPROTO_BAD_ACCEPT:
6917 vport->vport_stats.fdisc_acc_bad++;
6920 case BFA_EPROTO_UNKNOWN_RSP:
6921 vport->vport_stats.fdisc_unknown_rsp++;
6928 if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
6929 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6931 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_FAILED);
6935 case BFA_STATUS_ETIMER:
6936 vport->vport_stats.fdisc_timeouts++;
6937 if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
6938 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6940 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_FAILED);
6943 case BFA_STATUS_FABRIC_RJT:
6944 vport->vport_stats.fdisc_rejects++;
6945 bfa_fcs_vport_fdisc_rejected(vport);
6949 vport->vport_stats.fdisc_rsp_err++;
6950 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6958 bfa_cb_lps_fdisclogo_comp(void *bfad, void *uarg)
6960 struct bfa_fcs_vport_s *vport = uarg;
6961 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_OK);
6965 * Received clear virtual link
6968 bfa_cb_lps_cvl_event(void *bfad, void *uarg)
6970 struct bfa_fcs_vport_s *vport = uarg;
6972 /* Send an Offline followed by an ONLINE */
6973 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_OFFLINE);
6974 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_ONLINE);