dm thin metadata: fix __udivdi3 undefined on 32-bit
[linux/fpc-iii.git] / drivers / scsi / bfa / bfa_fcs_lport.c
blobff75ef8917551b35a61ff1e2eea41239b76b8332
1 /*
2 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
3 * All rights reserved
4 * www.brocade.com
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License (GPL) Version 2 as
10 * published by the Free Software Foundation
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
18 #include "bfad_drv.h"
19 #include "bfad_im.h"
20 #include "bfa_fcs.h"
21 #include "bfa_fcbuild.h"
22 #include "bfa_fc.h"
24 BFA_TRC_FILE(FCS, PORT);
27 * ALPA to LIXA bitmap mapping
29 * ALPA 0x00 (Word 0, Bit 30) is invalid for N_Ports. Also Word 0 Bit 31
30 * is for L_bit (login required) and is filled as ALPA 0x00 here.
32 static const u8 loop_alpa_map[] = {
33 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x0F, 0x10, /* Word 0 Bits 31..24 */
34 0x17, 0x18, 0x1B, 0x1D, 0x1E, 0x1F, 0x23, 0x25, /* Word 0 Bits 23..16 */
35 0x26, 0x27, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, /* Word 0 Bits 15..08 */
36 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x39, 0x3A, /* Word 0 Bits 07..00 */
38 0x3C, 0x43, 0x45, 0x46, 0x47, 0x49, 0x4A, 0x4B, /* Word 1 Bits 31..24 */
39 0x4C, 0x4D, 0x4E, 0x51, 0x52, 0x53, 0x54, 0x55, /* Word 1 Bits 23..16 */
40 0x56, 0x59, 0x5A, 0x5C, 0x63, 0x65, 0x66, 0x67, /* Word 1 Bits 15..08 */
41 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x71, 0x72, /* Word 1 Bits 07..00 */
43 0x73, 0x74, 0x75, 0x76, 0x79, 0x7A, 0x7C, 0x80, /* Word 2 Bits 31..24 */
44 0x81, 0x82, 0x84, 0x88, 0x8F, 0x90, 0x97, 0x98, /* Word 2 Bits 23..16 */
45 0x9B, 0x9D, 0x9E, 0x9F, 0xA3, 0xA5, 0xA6, 0xA7, /* Word 2 Bits 15..08 */
46 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xB1, 0xB2, /* Word 2 Bits 07..00 */
48 0xB3, 0xB4, 0xB5, 0xB6, 0xB9, 0xBA, 0xBC, 0xC3, /* Word 3 Bits 31..24 */
49 0xC5, 0xC6, 0xC7, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, /* Word 3 Bits 23..16 */
50 0xCE, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD9, /* Word 3 Bits 15..08 */
51 0xDA, 0xDC, 0xE0, 0xE1, 0xE2, 0xE4, 0xE8, 0xEF, /* Word 3 Bits 07..00 */
54 static void bfa_fcs_lport_send_ls_rjt(struct bfa_fcs_lport_s *port,
55 struct fchs_s *rx_fchs, u8 reason_code,
56 u8 reason_code_expl);
57 static void bfa_fcs_lport_plogi(struct bfa_fcs_lport_s *port,
58 struct fchs_s *rx_fchs, struct fc_logi_s *plogi);
59 static void bfa_fcs_lport_online_actions(struct bfa_fcs_lport_s *port);
60 static void bfa_fcs_lport_offline_actions(struct bfa_fcs_lport_s *port);
61 static void bfa_fcs_lport_unknown_init(struct bfa_fcs_lport_s *port);
62 static void bfa_fcs_lport_unknown_online(struct bfa_fcs_lport_s *port);
63 static void bfa_fcs_lport_unknown_offline(struct bfa_fcs_lport_s *port);
64 static void bfa_fcs_lport_deleted(struct bfa_fcs_lport_s *port);
65 static void bfa_fcs_lport_echo(struct bfa_fcs_lport_s *port,
66 struct fchs_s *rx_fchs,
67 struct fc_echo_s *echo, u16 len);
68 static void bfa_fcs_lport_rnid(struct bfa_fcs_lport_s *port,
69 struct fchs_s *rx_fchs,
70 struct fc_rnid_cmd_s *rnid, u16 len);
71 static void bfa_fs_port_get_gen_topo_data(struct bfa_fcs_lport_s *port,
72 struct fc_rnid_general_topology_data_s *gen_topo_data);
74 static void bfa_fcs_lport_fab_init(struct bfa_fcs_lport_s *port);
75 static void bfa_fcs_lport_fab_online(struct bfa_fcs_lport_s *port);
76 static void bfa_fcs_lport_fab_offline(struct bfa_fcs_lport_s *port);
78 static void bfa_fcs_lport_n2n_init(struct bfa_fcs_lport_s *port);
79 static void bfa_fcs_lport_n2n_online(struct bfa_fcs_lport_s *port);
80 static void bfa_fcs_lport_n2n_offline(struct bfa_fcs_lport_s *port);
82 static void bfa_fcs_lport_loop_init(struct bfa_fcs_lport_s *port);
83 static void bfa_fcs_lport_loop_online(struct bfa_fcs_lport_s *port);
84 static void bfa_fcs_lport_loop_offline(struct bfa_fcs_lport_s *port);
86 static struct {
87 void (*init) (struct bfa_fcs_lport_s *port);
88 void (*online) (struct bfa_fcs_lport_s *port);
89 void (*offline) (struct bfa_fcs_lport_s *port);
90 } __port_action[] = {
92 bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
93 bfa_fcs_lport_unknown_offline}, {
94 bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
95 bfa_fcs_lport_fab_offline}, {
96 bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
97 bfa_fcs_lport_n2n_offline}, {
98 bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
99 bfa_fcs_lport_loop_offline},
103 * fcs_port_sm FCS logical port state machine
106 enum bfa_fcs_lport_event {
107 BFA_FCS_PORT_SM_CREATE = 1,
108 BFA_FCS_PORT_SM_ONLINE = 2,
109 BFA_FCS_PORT_SM_OFFLINE = 3,
110 BFA_FCS_PORT_SM_DELETE = 4,
111 BFA_FCS_PORT_SM_DELRPORT = 5,
112 BFA_FCS_PORT_SM_STOP = 6,
115 static void bfa_fcs_lport_sm_uninit(struct bfa_fcs_lport_s *port,
116 enum bfa_fcs_lport_event event);
117 static void bfa_fcs_lport_sm_init(struct bfa_fcs_lport_s *port,
118 enum bfa_fcs_lport_event event);
119 static void bfa_fcs_lport_sm_online(struct bfa_fcs_lport_s *port,
120 enum bfa_fcs_lport_event event);
121 static void bfa_fcs_lport_sm_offline(struct bfa_fcs_lport_s *port,
122 enum bfa_fcs_lport_event event);
123 static void bfa_fcs_lport_sm_deleting(struct bfa_fcs_lport_s *port,
124 enum bfa_fcs_lport_event event);
125 static void bfa_fcs_lport_sm_stopping(struct bfa_fcs_lport_s *port,
126 enum bfa_fcs_lport_event event);
128 static void
129 bfa_fcs_lport_sm_uninit(
130 struct bfa_fcs_lport_s *port,
131 enum bfa_fcs_lport_event event)
133 bfa_trc(port->fcs, port->port_cfg.pwwn);
134 bfa_trc(port->fcs, event);
136 switch (event) {
137 case BFA_FCS_PORT_SM_CREATE:
138 bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
139 break;
141 default:
142 bfa_sm_fault(port->fcs, event);
146 static void
147 bfa_fcs_lport_sm_init(struct bfa_fcs_lport_s *port,
148 enum bfa_fcs_lport_event event)
150 bfa_trc(port->fcs, port->port_cfg.pwwn);
151 bfa_trc(port->fcs, event);
153 switch (event) {
154 case BFA_FCS_PORT_SM_ONLINE:
155 bfa_sm_set_state(port, bfa_fcs_lport_sm_online);
156 bfa_fcs_lport_online_actions(port);
157 break;
159 case BFA_FCS_PORT_SM_DELETE:
160 bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
161 bfa_fcs_lport_deleted(port);
162 break;
164 case BFA_FCS_PORT_SM_STOP:
165 /* If vport - send completion call back */
166 if (port->vport)
167 bfa_fcs_vport_stop_comp(port->vport);
168 else
169 bfa_wc_down(&(port->fabric->stop_wc));
170 break;
172 case BFA_FCS_PORT_SM_OFFLINE:
173 break;
175 default:
176 bfa_sm_fault(port->fcs, event);
180 static void
181 bfa_fcs_lport_sm_online(
182 struct bfa_fcs_lport_s *port,
183 enum bfa_fcs_lport_event event)
185 struct bfa_fcs_rport_s *rport;
186 struct list_head *qe, *qen;
188 bfa_trc(port->fcs, port->port_cfg.pwwn);
189 bfa_trc(port->fcs, event);
191 switch (event) {
192 case BFA_FCS_PORT_SM_OFFLINE:
193 bfa_sm_set_state(port, bfa_fcs_lport_sm_offline);
194 bfa_fcs_lport_offline_actions(port);
195 break;
197 case BFA_FCS_PORT_SM_STOP:
198 __port_action[port->fabric->fab_type].offline(port);
200 if (port->num_rports == 0) {
201 bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
202 /* If vport - send completion call back */
203 if (port->vport)
204 bfa_fcs_vport_stop_comp(port->vport);
205 else
206 bfa_wc_down(&(port->fabric->stop_wc));
207 } else {
208 bfa_sm_set_state(port, bfa_fcs_lport_sm_stopping);
209 list_for_each_safe(qe, qen, &port->rport_q) {
210 rport = (struct bfa_fcs_rport_s *) qe;
211 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
214 break;
216 case BFA_FCS_PORT_SM_DELETE:
218 __port_action[port->fabric->fab_type].offline(port);
220 if (port->num_rports == 0) {
221 bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
222 bfa_fcs_lport_deleted(port);
223 } else {
224 bfa_sm_set_state(port, bfa_fcs_lport_sm_deleting);
225 list_for_each_safe(qe, qen, &port->rport_q) {
226 rport = (struct bfa_fcs_rport_s *) qe;
227 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
230 break;
232 case BFA_FCS_PORT_SM_DELRPORT:
233 break;
235 default:
236 bfa_sm_fault(port->fcs, event);
240 static void
241 bfa_fcs_lport_sm_offline(
242 struct bfa_fcs_lport_s *port,
243 enum bfa_fcs_lport_event event)
245 struct bfa_fcs_rport_s *rport;
246 struct list_head *qe, *qen;
248 bfa_trc(port->fcs, port->port_cfg.pwwn);
249 bfa_trc(port->fcs, event);
251 switch (event) {
252 case BFA_FCS_PORT_SM_ONLINE:
253 bfa_sm_set_state(port, bfa_fcs_lport_sm_online);
254 bfa_fcs_lport_online_actions(port);
255 break;
257 case BFA_FCS_PORT_SM_STOP:
258 if (port->num_rports == 0) {
259 bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
260 /* If vport - send completion call back */
261 if (port->vport)
262 bfa_fcs_vport_stop_comp(port->vport);
263 else
264 bfa_wc_down(&(port->fabric->stop_wc));
265 } else {
266 bfa_sm_set_state(port, bfa_fcs_lport_sm_stopping);
267 list_for_each_safe(qe, qen, &port->rport_q) {
268 rport = (struct bfa_fcs_rport_s *) qe;
269 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
272 break;
274 case BFA_FCS_PORT_SM_DELETE:
275 if (port->num_rports == 0) {
276 bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
277 bfa_fcs_lport_deleted(port);
278 } else {
279 bfa_sm_set_state(port, bfa_fcs_lport_sm_deleting);
280 list_for_each_safe(qe, qen, &port->rport_q) {
281 rport = (struct bfa_fcs_rport_s *) qe;
282 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
285 break;
287 case BFA_FCS_PORT_SM_DELRPORT:
288 case BFA_FCS_PORT_SM_OFFLINE:
289 break;
291 default:
292 bfa_sm_fault(port->fcs, event);
296 static void
297 bfa_fcs_lport_sm_stopping(struct bfa_fcs_lport_s *port,
298 enum bfa_fcs_lport_event event)
300 bfa_trc(port->fcs, port->port_cfg.pwwn);
301 bfa_trc(port->fcs, event);
303 switch (event) {
304 case BFA_FCS_PORT_SM_DELRPORT:
305 if (port->num_rports == 0) {
306 bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
307 /* If vport - send completion call back */
308 if (port->vport)
309 bfa_fcs_vport_stop_comp(port->vport);
310 else
311 bfa_wc_down(&(port->fabric->stop_wc));
313 break;
315 default:
316 bfa_sm_fault(port->fcs, event);
320 static void
321 bfa_fcs_lport_sm_deleting(
322 struct bfa_fcs_lport_s *port,
323 enum bfa_fcs_lport_event event)
325 bfa_trc(port->fcs, port->port_cfg.pwwn);
326 bfa_trc(port->fcs, event);
328 switch (event) {
329 case BFA_FCS_PORT_SM_DELRPORT:
330 if (port->num_rports == 0) {
331 bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
332 bfa_fcs_lport_deleted(port);
334 break;
336 default:
337 bfa_sm_fault(port->fcs, event);
342 * fcs_port_pvt
346 * Send AEN notification
348 static void
349 bfa_fcs_lport_aen_post(struct bfa_fcs_lport_s *port,
350 enum bfa_lport_aen_event event)
352 struct bfad_s *bfad = (struct bfad_s *)port->fabric->fcs->bfad;
353 struct bfa_aen_entry_s *aen_entry;
355 bfad_get_aen_entry(bfad, aen_entry);
356 if (!aen_entry)
357 return;
359 aen_entry->aen_data.lport.vf_id = port->fabric->vf_id;
360 aen_entry->aen_data.lport.roles = port->port_cfg.roles;
361 aen_entry->aen_data.lport.ppwwn = bfa_fcs_lport_get_pwwn(
362 bfa_fcs_get_base_port(port->fcs));
363 aen_entry->aen_data.lport.lpwwn = bfa_fcs_lport_get_pwwn(port);
365 /* Send the AEN notification */
366 bfad_im_post_vendor_event(aen_entry, bfad, ++port->fcs->fcs_aen_seq,
367 BFA_AEN_CAT_LPORT, event);
371 * Send a LS reject
373 static void
374 bfa_fcs_lport_send_ls_rjt(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs,
375 u8 reason_code, u8 reason_code_expl)
377 struct fchs_s fchs;
378 struct bfa_fcxp_s *fcxp;
379 struct bfa_rport_s *bfa_rport = NULL;
380 int len;
382 bfa_trc(port->fcs, rx_fchs->d_id);
383 bfa_trc(port->fcs, rx_fchs->s_id);
385 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
386 if (!fcxp)
387 return;
389 len = fc_ls_rjt_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
390 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
391 rx_fchs->ox_id, reason_code, reason_code_expl);
393 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
394 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
395 FC_MAX_PDUSZ, 0);
399 * Send a FCCT Reject
401 static void
402 bfa_fcs_lport_send_fcgs_rjt(struct bfa_fcs_lport_s *port,
403 struct fchs_s *rx_fchs, u8 reason_code, u8 reason_code_expl)
405 struct fchs_s fchs;
406 struct bfa_fcxp_s *fcxp;
407 struct bfa_rport_s *bfa_rport = NULL;
408 int len;
409 struct ct_hdr_s *rx_cthdr = (struct ct_hdr_s *)(rx_fchs + 1);
410 struct ct_hdr_s *ct_hdr;
412 bfa_trc(port->fcs, rx_fchs->d_id);
413 bfa_trc(port->fcs, rx_fchs->s_id);
415 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
416 if (!fcxp)
417 return;
419 ct_hdr = bfa_fcxp_get_reqbuf(fcxp);
420 ct_hdr->gs_type = rx_cthdr->gs_type;
421 ct_hdr->gs_sub_type = rx_cthdr->gs_sub_type;
423 len = fc_gs_rjt_build(&fchs, ct_hdr, rx_fchs->s_id,
424 bfa_fcs_lport_get_fcid(port),
425 rx_fchs->ox_id, reason_code, reason_code_expl);
427 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
428 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
429 FC_MAX_PDUSZ, 0);
433 * Process incoming plogi from a remote port.
435 static void
436 bfa_fcs_lport_plogi(struct bfa_fcs_lport_s *port,
437 struct fchs_s *rx_fchs, struct fc_logi_s *plogi)
439 struct bfa_fcs_rport_s *rport;
441 bfa_trc(port->fcs, rx_fchs->d_id);
442 bfa_trc(port->fcs, rx_fchs->s_id);
445 * If min cfg mode is enabled, drop any incoming PLOGIs
447 if (__fcs_min_cfg(port->fcs)) {
448 bfa_trc(port->fcs, rx_fchs->s_id);
449 return;
452 if (fc_plogi_parse(rx_fchs) != FC_PARSE_OK) {
453 bfa_trc(port->fcs, rx_fchs->s_id);
455 * send a LS reject
457 bfa_fcs_lport_send_ls_rjt(port, rx_fchs,
458 FC_LS_RJT_RSN_PROTOCOL_ERROR,
459 FC_LS_RJT_EXP_SPARMS_ERR_OPTIONS);
460 return;
464 * Direct Attach P2P mode : verify address assigned by the r-port.
466 if ((!bfa_fcs_fabric_is_switched(port->fabric)) &&
467 (memcmp((void *)&bfa_fcs_lport_get_pwwn(port),
468 (void *)&plogi->port_name, sizeof(wwn_t)) < 0)) {
469 if (BFA_FCS_PID_IS_WKA(rx_fchs->d_id)) {
470 /* Address assigned to us cannot be a WKA */
471 bfa_fcs_lport_send_ls_rjt(port, rx_fchs,
472 FC_LS_RJT_RSN_PROTOCOL_ERROR,
473 FC_LS_RJT_EXP_INVALID_NPORT_ID);
474 return;
476 port->pid = rx_fchs->d_id;
477 bfa_lps_set_n2n_pid(port->fabric->lps, rx_fchs->d_id);
481 * First, check if we know the device by pwwn.
483 rport = bfa_fcs_lport_get_rport_by_pwwn(port, plogi->port_name);
484 if (rport) {
486 * Direct Attach P2P mode : handle address assigned by r-port.
488 if ((!bfa_fcs_fabric_is_switched(port->fabric)) &&
489 (memcmp((void *)&bfa_fcs_lport_get_pwwn(port),
490 (void *)&plogi->port_name, sizeof(wwn_t)) < 0)) {
491 port->pid = rx_fchs->d_id;
492 bfa_lps_set_n2n_pid(port->fabric->lps, rx_fchs->d_id);
493 rport->pid = rx_fchs->s_id;
495 bfa_fcs_rport_plogi(rport, rx_fchs, plogi);
496 return;
500 * Next, lookup rport by PID.
502 rport = bfa_fcs_lport_get_rport_by_pid(port, rx_fchs->s_id);
503 if (!rport) {
505 * Inbound PLOGI from a new device.
507 bfa_fcs_rport_plogi_create(port, rx_fchs, plogi);
508 return;
512 * Rport is known only by PID.
514 if (rport->pwwn) {
516 * This is a different device with the same pid. Old device
517 * disappeared. Send implicit LOGO to old device.
519 WARN_ON(rport->pwwn == plogi->port_name);
520 bfa_sm_send_event(rport, RPSM_EVENT_LOGO_IMP);
523 * Inbound PLOGI from a new device (with old PID).
525 bfa_fcs_rport_plogi_create(port, rx_fchs, plogi);
526 return;
530 * PLOGI crossing each other.
532 WARN_ON(rport->pwwn != WWN_NULL);
533 bfa_fcs_rport_plogi(rport, rx_fchs, plogi);
537 * Process incoming ECHO.
538 * Since it does not require a login, it is processed here.
540 static void
541 bfa_fcs_lport_echo(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs,
542 struct fc_echo_s *echo, u16 rx_len)
544 struct fchs_s fchs;
545 struct bfa_fcxp_s *fcxp;
546 struct bfa_rport_s *bfa_rport = NULL;
547 int len, pyld_len;
549 bfa_trc(port->fcs, rx_fchs->s_id);
550 bfa_trc(port->fcs, rx_fchs->d_id);
552 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
553 if (!fcxp)
554 return;
556 len = fc_ls_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
557 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
558 rx_fchs->ox_id);
561 * Copy the payload (if any) from the echo frame
563 pyld_len = rx_len - sizeof(struct fchs_s);
564 bfa_trc(port->fcs, rx_len);
565 bfa_trc(port->fcs, pyld_len);
567 if (pyld_len > len)
568 memcpy(((u8 *) bfa_fcxp_get_reqbuf(fcxp)) +
569 sizeof(struct fc_echo_s), (echo + 1),
570 (pyld_len - sizeof(struct fc_echo_s)));
572 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
573 BFA_FALSE, FC_CLASS_3, pyld_len, &fchs, NULL, NULL,
574 FC_MAX_PDUSZ, 0);
578 * Process incoming RNID.
579 * Since it does not require a login, it is processed here.
581 static void
582 bfa_fcs_lport_rnid(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs,
583 struct fc_rnid_cmd_s *rnid, u16 rx_len)
585 struct fc_rnid_common_id_data_s common_id_data;
586 struct fc_rnid_general_topology_data_s gen_topo_data;
587 struct fchs_s fchs;
588 struct bfa_fcxp_s *fcxp;
589 struct bfa_rport_s *bfa_rport = NULL;
590 u16 len;
591 u32 data_format;
593 bfa_trc(port->fcs, rx_fchs->s_id);
594 bfa_trc(port->fcs, rx_fchs->d_id);
595 bfa_trc(port->fcs, rx_len);
597 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
598 if (!fcxp)
599 return;
602 * Check Node Indentification Data Format
603 * We only support General Topology Discovery Format.
604 * For any other requested Data Formats, we return Common Node Id Data
605 * only, as per FC-LS.
607 bfa_trc(port->fcs, rnid->node_id_data_format);
608 if (rnid->node_id_data_format == RNID_NODEID_DATA_FORMAT_DISCOVERY) {
609 data_format = RNID_NODEID_DATA_FORMAT_DISCOVERY;
611 * Get General topology data for this port
613 bfa_fs_port_get_gen_topo_data(port, &gen_topo_data);
614 } else {
615 data_format = RNID_NODEID_DATA_FORMAT_COMMON;
619 * Copy the Node Id Info
621 common_id_data.port_name = bfa_fcs_lport_get_pwwn(port);
622 common_id_data.node_name = bfa_fcs_lport_get_nwwn(port);
624 len = fc_rnid_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
625 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
626 rx_fchs->ox_id, data_format, &common_id_data,
627 &gen_topo_data);
629 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
630 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
631 FC_MAX_PDUSZ, 0);
635 * Fill out General Topolpgy Discovery Data for RNID ELS.
637 static void
638 bfa_fs_port_get_gen_topo_data(struct bfa_fcs_lport_s *port,
639 struct fc_rnid_general_topology_data_s *gen_topo_data)
641 memset(gen_topo_data, 0,
642 sizeof(struct fc_rnid_general_topology_data_s));
644 gen_topo_data->asso_type = cpu_to_be32(RNID_ASSOCIATED_TYPE_HOST);
645 gen_topo_data->phy_port_num = 0; /* @todo */
646 gen_topo_data->num_attached_nodes = cpu_to_be32(1);
649 static void
650 bfa_fcs_lport_online_actions(struct bfa_fcs_lport_s *port)
652 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
653 char lpwwn_buf[BFA_STRING_32];
655 bfa_trc(port->fcs, port->fabric->oper_type);
657 __port_action[port->fabric->fab_type].init(port);
658 __port_action[port->fabric->fab_type].online(port);
660 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
661 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
662 "Logical port online: WWN = %s Role = %s\n",
663 lpwwn_buf, "Initiator");
664 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_ONLINE);
666 bfad->bfad_flags |= BFAD_PORT_ONLINE;
669 static void
670 bfa_fcs_lport_offline_actions(struct bfa_fcs_lport_s *port)
672 struct list_head *qe, *qen;
673 struct bfa_fcs_rport_s *rport;
674 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
675 char lpwwn_buf[BFA_STRING_32];
677 bfa_trc(port->fcs, port->fabric->oper_type);
679 __port_action[port->fabric->fab_type].offline(port);
681 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
682 if (bfa_sm_cmp_state(port->fabric,
683 bfa_fcs_fabric_sm_online) == BFA_TRUE) {
684 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
685 "Logical port lost fabric connectivity: WWN = %s Role = %s\n",
686 lpwwn_buf, "Initiator");
687 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_DISCONNECT);
688 } else {
689 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
690 "Logical port taken offline: WWN = %s Role = %s\n",
691 lpwwn_buf, "Initiator");
692 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_OFFLINE);
695 list_for_each_safe(qe, qen, &port->rport_q) {
696 rport = (struct bfa_fcs_rport_s *) qe;
697 bfa_sm_send_event(rport, RPSM_EVENT_LOGO_IMP);
701 static void
702 bfa_fcs_lport_unknown_init(struct bfa_fcs_lport_s *port)
704 WARN_ON(1);
707 static void
708 bfa_fcs_lport_unknown_online(struct bfa_fcs_lport_s *port)
710 WARN_ON(1);
713 static void
714 bfa_fcs_lport_unknown_offline(struct bfa_fcs_lport_s *port)
716 WARN_ON(1);
719 static void
720 bfa_fcs_lport_abts_acc(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs)
722 struct fchs_s fchs;
723 struct bfa_fcxp_s *fcxp;
724 int len;
726 bfa_trc(port->fcs, rx_fchs->d_id);
727 bfa_trc(port->fcs, rx_fchs->s_id);
729 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
730 if (!fcxp)
731 return;
733 len = fc_ba_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
734 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
735 rx_fchs->ox_id, 0);
737 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag,
738 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
739 FC_MAX_PDUSZ, 0);
741 static void
742 bfa_fcs_lport_deleted(struct bfa_fcs_lport_s *port)
744 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
745 char lpwwn_buf[BFA_STRING_32];
747 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
748 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
749 "Logical port deleted: WWN = %s Role = %s\n",
750 lpwwn_buf, "Initiator");
751 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_DELETE);
753 /* Base port will be deleted by the OS driver */
754 if (port->vport)
755 bfa_fcs_vport_delete_comp(port->vport);
756 else
757 bfa_wc_down(&port->fabric->wc);
762 * Unsolicited frame receive handling.
764 void
765 bfa_fcs_lport_uf_recv(struct bfa_fcs_lport_s *lport,
766 struct fchs_s *fchs, u16 len)
768 u32 pid = fchs->s_id;
769 struct bfa_fcs_rport_s *rport = NULL;
770 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
772 bfa_stats(lport, uf_recvs);
773 bfa_trc(lport->fcs, fchs->type);
775 if (!bfa_fcs_lport_is_online(lport)) {
777 * In direct attach topology, it is possible to get a PLOGI
778 * before the lport is online due to port feature
779 * (QoS/Trunk/FEC/CR), so send a rjt
781 if ((fchs->type == FC_TYPE_ELS) &&
782 (els_cmd->els_code == FC_ELS_PLOGI)) {
783 bfa_fcs_lport_send_ls_rjt(lport, fchs,
784 FC_LS_RJT_RSN_UNABLE_TO_PERF_CMD,
785 FC_LS_RJT_EXP_NO_ADDL_INFO);
786 bfa_stats(lport, plogi_rcvd);
787 } else
788 bfa_stats(lport, uf_recv_drops);
790 return;
794 * First, handle ELSs that donot require a login.
797 * Handle PLOGI first
799 if ((fchs->type == FC_TYPE_ELS) &&
800 (els_cmd->els_code == FC_ELS_PLOGI)) {
801 bfa_fcs_lport_plogi(lport, fchs, (struct fc_logi_s *) els_cmd);
802 return;
806 * Handle ECHO separately.
808 if ((fchs->type == FC_TYPE_ELS) && (els_cmd->els_code == FC_ELS_ECHO)) {
809 bfa_fcs_lport_echo(lport, fchs,
810 (struct fc_echo_s *)els_cmd, len);
811 return;
815 * Handle RNID separately.
817 if ((fchs->type == FC_TYPE_ELS) && (els_cmd->els_code == FC_ELS_RNID)) {
818 bfa_fcs_lport_rnid(lport, fchs,
819 (struct fc_rnid_cmd_s *) els_cmd, len);
820 return;
823 if (fchs->type == FC_TYPE_BLS) {
824 if ((fchs->routing == FC_RTG_BASIC_LINK) &&
825 (fchs->cat_info == FC_CAT_ABTS))
826 bfa_fcs_lport_abts_acc(lport, fchs);
827 return;
830 if (fchs->type == FC_TYPE_SERVICES) {
832 * Unhandled FC-GS frames. Send a FC-CT Reject
834 bfa_fcs_lport_send_fcgs_rjt(lport, fchs, CT_RSN_NOT_SUPP,
835 CT_NS_EXP_NOADDITIONAL);
836 return;
840 * look for a matching remote port ID
842 rport = bfa_fcs_lport_get_rport_by_pid(lport, pid);
843 if (rport) {
844 bfa_trc(rport->fcs, fchs->s_id);
845 bfa_trc(rport->fcs, fchs->d_id);
846 bfa_trc(rport->fcs, fchs->type);
848 bfa_fcs_rport_uf_recv(rport, fchs, len);
849 return;
853 * Only handles ELS frames for now.
855 if (fchs->type != FC_TYPE_ELS) {
856 bfa_trc(lport->fcs, fchs->s_id);
857 bfa_trc(lport->fcs, fchs->d_id);
858 /* ignore type FC_TYPE_FC_FSS */
859 if (fchs->type != FC_TYPE_FC_FSS)
860 bfa_sm_fault(lport->fcs, fchs->type);
861 return;
864 bfa_trc(lport->fcs, els_cmd->els_code);
865 if (els_cmd->els_code == FC_ELS_RSCN) {
866 bfa_fcs_lport_scn_process_rscn(lport, fchs, len);
867 return;
870 if (els_cmd->els_code == FC_ELS_LOGO) {
872 * @todo Handle LOGO frames received.
874 return;
877 if (els_cmd->els_code == FC_ELS_PRLI) {
879 * @todo Handle PRLI frames received.
881 return;
885 * Unhandled ELS frames. Send a LS_RJT.
887 bfa_fcs_lport_send_ls_rjt(lport, fchs, FC_LS_RJT_RSN_CMD_NOT_SUPP,
888 FC_LS_RJT_EXP_NO_ADDL_INFO);
893 * PID based Lookup for a R-Port in the Port R-Port Queue
895 struct bfa_fcs_rport_s *
896 bfa_fcs_lport_get_rport_by_pid(struct bfa_fcs_lport_s *port, u32 pid)
898 struct bfa_fcs_rport_s *rport;
899 struct list_head *qe;
901 list_for_each(qe, &port->rport_q) {
902 rport = (struct bfa_fcs_rport_s *) qe;
903 if (rport->pid == pid)
904 return rport;
907 bfa_trc(port->fcs, pid);
908 return NULL;
912 * OLD_PID based Lookup for a R-Port in the Port R-Port Queue
914 struct bfa_fcs_rport_s *
915 bfa_fcs_lport_get_rport_by_old_pid(struct bfa_fcs_lport_s *port, u32 pid)
917 struct bfa_fcs_rport_s *rport;
918 struct list_head *qe;
920 list_for_each(qe, &port->rport_q) {
921 rport = (struct bfa_fcs_rport_s *) qe;
922 if (rport->old_pid == pid)
923 return rport;
926 bfa_trc(port->fcs, pid);
927 return NULL;
931 * PWWN based Lookup for a R-Port in the Port R-Port Queue
933 struct bfa_fcs_rport_s *
934 bfa_fcs_lport_get_rport_by_pwwn(struct bfa_fcs_lport_s *port, wwn_t pwwn)
936 struct bfa_fcs_rport_s *rport;
937 struct list_head *qe;
939 list_for_each(qe, &port->rport_q) {
940 rport = (struct bfa_fcs_rport_s *) qe;
941 if (wwn_is_equal(rport->pwwn, pwwn))
942 return rport;
945 bfa_trc(port->fcs, pwwn);
946 return NULL;
950 * NWWN based Lookup for a R-Port in the Port R-Port Queue
952 struct bfa_fcs_rport_s *
953 bfa_fcs_lport_get_rport_by_nwwn(struct bfa_fcs_lport_s *port, wwn_t nwwn)
955 struct bfa_fcs_rport_s *rport;
956 struct list_head *qe;
958 list_for_each(qe, &port->rport_q) {
959 rport = (struct bfa_fcs_rport_s *) qe;
960 if (wwn_is_equal(rport->nwwn, nwwn))
961 return rport;
964 bfa_trc(port->fcs, nwwn);
965 return NULL;
969 * PWWN & PID based Lookup for a R-Port in the Port R-Port Queue
971 struct bfa_fcs_rport_s *
972 bfa_fcs_lport_get_rport_by_qualifier(struct bfa_fcs_lport_s *port,
973 wwn_t pwwn, u32 pid)
975 struct bfa_fcs_rport_s *rport;
976 struct list_head *qe;
978 list_for_each(qe, &port->rport_q) {
979 rport = (struct bfa_fcs_rport_s *) qe;
980 if (wwn_is_equal(rport->pwwn, pwwn) && rport->pid == pid)
981 return rport;
984 bfa_trc(port->fcs, pwwn);
985 return NULL;
989 * Called by rport module when new rports are discovered.
991 void
992 bfa_fcs_lport_add_rport(
993 struct bfa_fcs_lport_s *port,
994 struct bfa_fcs_rport_s *rport)
996 list_add_tail(&rport->qe, &port->rport_q);
997 port->num_rports++;
1001 * Called by rport module to when rports are deleted.
1003 void
1004 bfa_fcs_lport_del_rport(
1005 struct bfa_fcs_lport_s *port,
1006 struct bfa_fcs_rport_s *rport)
1008 WARN_ON(!bfa_q_is_on_q(&port->rport_q, rport));
1009 list_del(&rport->qe);
1010 port->num_rports--;
1012 bfa_sm_send_event(port, BFA_FCS_PORT_SM_DELRPORT);
1016 * Called by fabric for base port when fabric login is complete.
1017 * Called by vport for virtual ports when FDISC is complete.
1019 void
1020 bfa_fcs_lport_online(struct bfa_fcs_lport_s *port)
1022 bfa_sm_send_event(port, BFA_FCS_PORT_SM_ONLINE);
1026 * Called by fabric for base port when fabric goes offline.
1027 * Called by vport for virtual ports when virtual port becomes offline.
1029 void
1030 bfa_fcs_lport_offline(struct bfa_fcs_lport_s *port)
1032 bfa_sm_send_event(port, BFA_FCS_PORT_SM_OFFLINE);
1036 * Called by fabric for base port and by vport for virtual ports
1037 * when target mode driver is unloaded.
1039 void
1040 bfa_fcs_lport_stop(struct bfa_fcs_lport_s *port)
1042 bfa_sm_send_event(port, BFA_FCS_PORT_SM_STOP);
1046 * Called by fabric to delete base lport and associated resources.
1048 * Called by vport to delete lport and associated resources. Should call
1049 * bfa_fcs_vport_delete_comp() for vports on completion.
1051 void
1052 bfa_fcs_lport_delete(struct bfa_fcs_lport_s *port)
1054 bfa_sm_send_event(port, BFA_FCS_PORT_SM_DELETE);
1058 * Return TRUE if port is online, else return FALSE
1060 bfa_boolean_t
1061 bfa_fcs_lport_is_online(struct bfa_fcs_lport_s *port)
1063 return bfa_sm_cmp_state(port, bfa_fcs_lport_sm_online);
1067 * Attach time initialization of logical ports.
1069 void
1070 bfa_fcs_lport_attach(struct bfa_fcs_lport_s *lport, struct bfa_fcs_s *fcs,
1071 u16 vf_id, struct bfa_fcs_vport_s *vport)
1073 lport->fcs = fcs;
1074 lport->fabric = bfa_fcs_vf_lookup(fcs, vf_id);
1075 lport->vport = vport;
1076 lport->lp_tag = (vport) ? vport->lps->bfa_tag :
1077 lport->fabric->lps->bfa_tag;
1079 INIT_LIST_HEAD(&lport->rport_q);
1080 lport->num_rports = 0;
1084 * Logical port initialization of base or virtual port.
1085 * Called by fabric for base port or by vport for virtual ports.
1088 void
1089 bfa_fcs_lport_init(struct bfa_fcs_lport_s *lport,
1090 struct bfa_lport_cfg_s *port_cfg)
1092 struct bfa_fcs_vport_s *vport = lport->vport;
1093 struct bfad_s *bfad = (struct bfad_s *)lport->fcs->bfad;
1094 char lpwwn_buf[BFA_STRING_32];
1096 lport->port_cfg = *port_cfg;
1098 lport->bfad_port = bfa_fcb_lport_new(lport->fcs->bfad, lport,
1099 lport->port_cfg.roles,
1100 lport->fabric->vf_drv,
1101 vport ? vport->vport_drv : NULL);
1103 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(lport));
1104 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
1105 "New logical port created: WWN = %s Role = %s\n",
1106 lpwwn_buf, "Initiator");
1107 bfa_fcs_lport_aen_post(lport, BFA_LPORT_AEN_NEW);
1109 bfa_sm_set_state(lport, bfa_fcs_lport_sm_uninit);
1110 bfa_sm_send_event(lport, BFA_FCS_PORT_SM_CREATE);
1113 void
1114 bfa_fcs_lport_set_symname(struct bfa_fcs_lport_s *port,
1115 char *symname)
1117 strcpy(port->port_cfg.sym_name.symname, symname);
1119 if (bfa_sm_cmp_state(port, bfa_fcs_lport_sm_online))
1120 bfa_fcs_lport_ns_util_send_rspn_id(
1121 BFA_FCS_GET_NS_FROM_PORT(port), NULL);
1125 * fcs_lport_api
1128 void
1129 bfa_fcs_lport_get_attr(
1130 struct bfa_fcs_lport_s *port,
1131 struct bfa_lport_attr_s *port_attr)
1133 if (bfa_sm_cmp_state(port, bfa_fcs_lport_sm_online))
1134 port_attr->pid = port->pid;
1135 else
1136 port_attr->pid = 0;
1138 port_attr->port_cfg = port->port_cfg;
1140 if (port->fabric) {
1141 port_attr->port_type = port->fabric->oper_type;
1142 port_attr->loopback = bfa_sm_cmp_state(port->fabric,
1143 bfa_fcs_fabric_sm_loopback);
1144 port_attr->authfail =
1145 bfa_sm_cmp_state(port->fabric,
1146 bfa_fcs_fabric_sm_auth_failed);
1147 port_attr->fabric_name = bfa_fcs_lport_get_fabric_name(port);
1148 memcpy(port_attr->fabric_ip_addr,
1149 bfa_fcs_lport_get_fabric_ipaddr(port),
1150 BFA_FCS_FABRIC_IPADDR_SZ);
1152 if (port->vport != NULL) {
1153 port_attr->port_type = BFA_PORT_TYPE_VPORT;
1154 port_attr->fpma_mac =
1155 port->vport->lps->lp_mac;
1156 } else {
1157 port_attr->fpma_mac =
1158 port->fabric->lps->lp_mac;
1160 } else {
1161 port_attr->port_type = BFA_PORT_TYPE_UNKNOWN;
1162 port_attr->state = BFA_LPORT_UNINIT;
1167 * bfa_fcs_lport_fab port fab functions
1171 * Called by port to initialize fabric services of the base port.
1173 static void
1174 bfa_fcs_lport_fab_init(struct bfa_fcs_lport_s *port)
1176 bfa_fcs_lport_ns_init(port);
1177 bfa_fcs_lport_scn_init(port);
1178 bfa_fcs_lport_ms_init(port);
1182 * Called by port to notify transition to online state.
1184 static void
1185 bfa_fcs_lport_fab_online(struct bfa_fcs_lport_s *port)
1187 bfa_fcs_lport_ns_online(port);
1188 bfa_fcs_lport_fab_scn_online(port);
1192 * Called by port to notify transition to offline state.
1194 static void
1195 bfa_fcs_lport_fab_offline(struct bfa_fcs_lport_s *port)
1197 bfa_fcs_lport_ns_offline(port);
1198 bfa_fcs_lport_scn_offline(port);
1199 bfa_fcs_lport_ms_offline(port);
1203 * bfa_fcs_lport_n2n functions
1207 * Called by fcs/port to initialize N2N topology.
1209 static void
1210 bfa_fcs_lport_n2n_init(struct bfa_fcs_lport_s *port)
1215 * Called by fcs/port to notify transition to online state.
1217 static void
1218 bfa_fcs_lport_n2n_online(struct bfa_fcs_lport_s *port)
1220 struct bfa_fcs_lport_n2n_s *n2n_port = &port->port_topo.pn2n;
1221 struct bfa_lport_cfg_s *pcfg = &port->port_cfg;
1222 struct bfa_fcs_rport_s *rport;
1224 bfa_trc(port->fcs, pcfg->pwwn);
1227 * If our PWWN is > than that of the r-port, we have to initiate PLOGI
1228 * and assign an Address. if not, we need to wait for its PLOGI.
1230 * If our PWWN is < than that of the remote port, it will send a PLOGI
1231 * with the PIDs assigned. The rport state machine take care of this
1232 * incoming PLOGI.
1234 if (memcmp
1235 ((void *)&pcfg->pwwn, (void *)&n2n_port->rem_port_wwn,
1236 sizeof(wwn_t)) > 0) {
1237 port->pid = N2N_LOCAL_PID;
1238 bfa_lps_set_n2n_pid(port->fabric->lps, N2N_LOCAL_PID);
1240 * First, check if we know the device by pwwn.
1242 rport = bfa_fcs_lport_get_rport_by_pwwn(port,
1243 n2n_port->rem_port_wwn);
1244 if (rport) {
1245 bfa_trc(port->fcs, rport->pid);
1246 bfa_trc(port->fcs, rport->pwwn);
1247 rport->pid = N2N_REMOTE_PID;
1248 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_SEND);
1249 return;
1253 * In n2n there can be only one rport. Delete the old one
1254 * whose pid should be zero, because it is offline.
1256 if (port->num_rports > 0) {
1257 rport = bfa_fcs_lport_get_rport_by_pid(port, 0);
1258 WARN_ON(rport == NULL);
1259 if (rport) {
1260 bfa_trc(port->fcs, rport->pwwn);
1261 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
1264 bfa_fcs_rport_create(port, N2N_REMOTE_PID);
1269 * Called by fcs/port to notify transition to offline state.
1271 static void
1272 bfa_fcs_lport_n2n_offline(struct bfa_fcs_lport_s *port)
1274 struct bfa_fcs_lport_n2n_s *n2n_port = &port->port_topo.pn2n;
1276 bfa_trc(port->fcs, port->pid);
1277 port->pid = 0;
1278 n2n_port->rem_port_wwn = 0;
1279 n2n_port->reply_oxid = 0;
1282 void
1283 bfa_fcport_get_loop_attr(struct bfa_fcs_lport_s *port)
1285 int i = 0, j = 0, bit = 0, alpa_bit = 0;
1286 u8 k = 0;
1287 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(port->fcs->bfa);
1289 port->port_topo.ploop.alpabm_valid = fcport->alpabm_valid;
1290 port->pid = fcport->myalpa;
1291 port->pid = bfa_hton3b(port->pid);
1293 for (i = 0; i < (FC_ALPA_MAX / 8); i++) {
1294 for (j = 0, alpa_bit = 0; j < 8; j++, alpa_bit++) {
1295 bfa_trc(port->fcs->bfa, fcport->alpabm.alpa_bm[i]);
1296 bit = (fcport->alpabm.alpa_bm[i] & (1 << (7 - j)));
1297 if (bit) {
1298 port->port_topo.ploop.alpa_pos_map[k] =
1299 loop_alpa_map[(i * 8) + alpa_bit];
1300 k++;
1301 bfa_trc(port->fcs->bfa, k);
1302 bfa_trc(port->fcs->bfa,
1303 port->port_topo.ploop.alpa_pos_map[k]);
1307 port->port_topo.ploop.num_alpa = k;
1311 * Called by fcs/port to initialize Loop topology.
1313 static void
1314 bfa_fcs_lport_loop_init(struct bfa_fcs_lport_s *port)
1319 * Called by fcs/port to notify transition to online state.
1321 static void
1322 bfa_fcs_lport_loop_online(struct bfa_fcs_lport_s *port)
1324 u8 num_alpa = 0, alpabm_valid = 0;
1325 struct bfa_fcs_rport_s *rport;
1326 u8 *alpa_map = NULL;
1327 int i = 0;
1328 u32 pid;
1330 bfa_fcport_get_loop_attr(port);
1332 num_alpa = port->port_topo.ploop.num_alpa;
1333 alpabm_valid = port->port_topo.ploop.alpabm_valid;
1334 alpa_map = port->port_topo.ploop.alpa_pos_map;
1336 bfa_trc(port->fcs->bfa, port->pid);
1337 bfa_trc(port->fcs->bfa, num_alpa);
1338 if (alpabm_valid == 1) {
1339 for (i = 0; i < num_alpa; i++) {
1340 bfa_trc(port->fcs->bfa, alpa_map[i]);
1341 if (alpa_map[i] != bfa_hton3b(port->pid)) {
1342 pid = alpa_map[i];
1343 bfa_trc(port->fcs->bfa, pid);
1344 rport = bfa_fcs_lport_get_rport_by_pid(port,
1345 bfa_hton3b(pid));
1346 if (!rport)
1347 rport = bfa_fcs_rport_create(port,
1348 bfa_hton3b(pid));
1351 } else {
1352 for (i = 0; i < MAX_ALPA_COUNT; i++) {
1353 if (alpa_map[i] != port->pid) {
1354 pid = loop_alpa_map[i];
1355 bfa_trc(port->fcs->bfa, pid);
1356 rport = bfa_fcs_lport_get_rport_by_pid(port,
1357 bfa_hton3b(pid));
1358 if (!rport)
1359 rport = bfa_fcs_rport_create(port,
1360 bfa_hton3b(pid));
1367 * Called by fcs/port to notify transition to offline state.
1369 static void
1370 bfa_fcs_lport_loop_offline(struct bfa_fcs_lport_s *port)
1374 #define BFA_FCS_FDMI_CMD_MAX_RETRIES 2
1377 * forward declarations
1379 static void bfa_fcs_lport_fdmi_send_rhba(void *fdmi_cbarg,
1380 struct bfa_fcxp_s *fcxp_alloced);
1381 static void bfa_fcs_lport_fdmi_send_rprt(void *fdmi_cbarg,
1382 struct bfa_fcxp_s *fcxp_alloced);
1383 static void bfa_fcs_lport_fdmi_send_rpa(void *fdmi_cbarg,
1384 struct bfa_fcxp_s *fcxp_alloced);
1385 static void bfa_fcs_lport_fdmi_rhba_response(void *fcsarg,
1386 struct bfa_fcxp_s *fcxp,
1387 void *cbarg,
1388 bfa_status_t req_status,
1389 u32 rsp_len,
1390 u32 resid_len,
1391 struct fchs_s *rsp_fchs);
1392 static void bfa_fcs_lport_fdmi_rprt_response(void *fcsarg,
1393 struct bfa_fcxp_s *fcxp,
1394 void *cbarg,
1395 bfa_status_t req_status,
1396 u32 rsp_len,
1397 u32 resid_len,
1398 struct fchs_s *rsp_fchs);
1399 static void bfa_fcs_lport_fdmi_rpa_response(void *fcsarg,
1400 struct bfa_fcxp_s *fcxp,
1401 void *cbarg,
1402 bfa_status_t req_status,
1403 u32 rsp_len,
1404 u32 resid_len,
1405 struct fchs_s *rsp_fchs);
1406 static void bfa_fcs_lport_fdmi_timeout(void *arg);
1407 static u16 bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s *fdmi,
1408 u8 *pyld);
1409 static u16 bfa_fcs_lport_fdmi_build_rprt_pyld(struct bfa_fcs_lport_fdmi_s *fdmi,
1410 u8 *pyld);
1411 static u16 bfa_fcs_lport_fdmi_build_rpa_pyld(struct bfa_fcs_lport_fdmi_s *fdmi,
1412 u8 *pyld);
1413 static u16 bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s *
1414 fdmi, u8 *pyld);
1415 static void bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s *fdmi,
1416 struct bfa_fcs_fdmi_hba_attr_s *hba_attr);
1417 static void bfa_fcs_fdmi_get_portattr(struct bfa_fcs_lport_fdmi_s *fdmi,
1418 struct bfa_fcs_fdmi_port_attr_s *port_attr);
1419 u32 bfa_fcs_fdmi_convert_speed(enum bfa_port_speed pport_speed);
1422 * fcs_fdmi_sm FCS FDMI state machine
1426 * FDMI State Machine events
1428 enum port_fdmi_event {
1429 FDMISM_EVENT_PORT_ONLINE = 1,
1430 FDMISM_EVENT_PORT_OFFLINE = 2,
1431 FDMISM_EVENT_RSP_OK = 4,
1432 FDMISM_EVENT_RSP_ERROR = 5,
1433 FDMISM_EVENT_TIMEOUT = 6,
1434 FDMISM_EVENT_RHBA_SENT = 7,
1435 FDMISM_EVENT_RPRT_SENT = 8,
1436 FDMISM_EVENT_RPA_SENT = 9,
1439 static void bfa_fcs_lport_fdmi_sm_offline(struct bfa_fcs_lport_fdmi_s *fdmi,
1440 enum port_fdmi_event event);
1441 static void bfa_fcs_lport_fdmi_sm_sending_rhba(
1442 struct bfa_fcs_lport_fdmi_s *fdmi,
1443 enum port_fdmi_event event);
1444 static void bfa_fcs_lport_fdmi_sm_rhba(struct bfa_fcs_lport_fdmi_s *fdmi,
1445 enum port_fdmi_event event);
1446 static void bfa_fcs_lport_fdmi_sm_rhba_retry(
1447 struct bfa_fcs_lport_fdmi_s *fdmi,
1448 enum port_fdmi_event event);
1449 static void bfa_fcs_lport_fdmi_sm_sending_rprt(
1450 struct bfa_fcs_lport_fdmi_s *fdmi,
1451 enum port_fdmi_event event);
1452 static void bfa_fcs_lport_fdmi_sm_rprt(struct bfa_fcs_lport_fdmi_s *fdmi,
1453 enum port_fdmi_event event);
1454 static void bfa_fcs_lport_fdmi_sm_rprt_retry(
1455 struct bfa_fcs_lport_fdmi_s *fdmi,
1456 enum port_fdmi_event event);
1457 static void bfa_fcs_lport_fdmi_sm_sending_rpa(
1458 struct bfa_fcs_lport_fdmi_s *fdmi,
1459 enum port_fdmi_event event);
1460 static void bfa_fcs_lport_fdmi_sm_rpa(struct bfa_fcs_lport_fdmi_s *fdmi,
1461 enum port_fdmi_event event);
1462 static void bfa_fcs_lport_fdmi_sm_rpa_retry(
1463 struct bfa_fcs_lport_fdmi_s *fdmi,
1464 enum port_fdmi_event event);
1465 static void bfa_fcs_lport_fdmi_sm_online(struct bfa_fcs_lport_fdmi_s *fdmi,
1466 enum port_fdmi_event event);
1467 static void bfa_fcs_lport_fdmi_sm_disabled(
1468 struct bfa_fcs_lport_fdmi_s *fdmi,
1469 enum port_fdmi_event event);
1471 * Start in offline state - awaiting MS to send start.
1473 static void
1474 bfa_fcs_lport_fdmi_sm_offline(struct bfa_fcs_lport_fdmi_s *fdmi,
1475 enum port_fdmi_event event)
1477 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1479 bfa_trc(port->fcs, port->port_cfg.pwwn);
1480 bfa_trc(port->fcs, event);
1482 fdmi->retry_cnt = 0;
1484 switch (event) {
1485 case FDMISM_EVENT_PORT_ONLINE:
1486 if (port->vport) {
1488 * For Vports, register a new port.
1490 bfa_sm_set_state(fdmi,
1491 bfa_fcs_lport_fdmi_sm_sending_rprt);
1492 bfa_fcs_lport_fdmi_send_rprt(fdmi, NULL);
1493 } else {
1495 * For a base port, we should first register the HBA
1496 * attribute. The HBA attribute also contains the base
1497 * port registration.
1499 bfa_sm_set_state(fdmi,
1500 bfa_fcs_lport_fdmi_sm_sending_rhba);
1501 bfa_fcs_lport_fdmi_send_rhba(fdmi, NULL);
1503 break;
1505 case FDMISM_EVENT_PORT_OFFLINE:
1506 break;
1508 default:
1509 bfa_sm_fault(port->fcs, event);
1513 static void
1514 bfa_fcs_lport_fdmi_sm_sending_rhba(struct bfa_fcs_lport_fdmi_s *fdmi,
1515 enum port_fdmi_event event)
1517 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1519 bfa_trc(port->fcs, port->port_cfg.pwwn);
1520 bfa_trc(port->fcs, event);
1522 switch (event) {
1523 case FDMISM_EVENT_RHBA_SENT:
1524 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rhba);
1525 break;
1527 case FDMISM_EVENT_PORT_OFFLINE:
1528 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1529 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
1530 &fdmi->fcxp_wqe);
1531 break;
1533 default:
1534 bfa_sm_fault(port->fcs, event);
1538 static void
1539 bfa_fcs_lport_fdmi_sm_rhba(struct bfa_fcs_lport_fdmi_s *fdmi,
1540 enum port_fdmi_event event)
1542 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1544 bfa_trc(port->fcs, port->port_cfg.pwwn);
1545 bfa_trc(port->fcs, event);
1547 switch (event) {
1548 case FDMISM_EVENT_RSP_ERROR:
1550 * if max retries have not been reached, start timer for a
1551 * delayed retry
1553 if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
1554 bfa_sm_set_state(fdmi,
1555 bfa_fcs_lport_fdmi_sm_rhba_retry);
1556 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
1557 &fdmi->timer,
1558 bfa_fcs_lport_fdmi_timeout, fdmi,
1559 BFA_FCS_RETRY_TIMEOUT);
1560 } else {
1562 * set state to offline
1564 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1566 break;
1568 case FDMISM_EVENT_RSP_OK:
1570 * Initiate Register Port Attributes
1572 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rpa);
1573 fdmi->retry_cnt = 0;
1574 bfa_fcs_lport_fdmi_send_rpa(fdmi, NULL);
1575 break;
1577 case FDMISM_EVENT_PORT_OFFLINE:
1578 bfa_fcxp_discard(fdmi->fcxp);
1579 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1580 break;
1582 default:
1583 bfa_sm_fault(port->fcs, event);
1587 static void
1588 bfa_fcs_lport_fdmi_sm_rhba_retry(struct bfa_fcs_lport_fdmi_s *fdmi,
1589 enum port_fdmi_event event)
1591 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1593 bfa_trc(port->fcs, port->port_cfg.pwwn);
1594 bfa_trc(port->fcs, event);
1596 switch (event) {
1597 case FDMISM_EVENT_TIMEOUT:
1599 * Retry Timer Expired. Re-send
1601 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rhba);
1602 bfa_fcs_lport_fdmi_send_rhba(fdmi, NULL);
1603 break;
1605 case FDMISM_EVENT_PORT_OFFLINE:
1606 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1607 bfa_timer_stop(&fdmi->timer);
1608 break;
1610 default:
1611 bfa_sm_fault(port->fcs, event);
1616 * RPRT : Register Port
1618 static void
1619 bfa_fcs_lport_fdmi_sm_sending_rprt(struct bfa_fcs_lport_fdmi_s *fdmi,
1620 enum port_fdmi_event event)
1622 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1624 bfa_trc(port->fcs, port->port_cfg.pwwn);
1625 bfa_trc(port->fcs, event);
1627 switch (event) {
1628 case FDMISM_EVENT_RPRT_SENT:
1629 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rprt);
1630 break;
1632 case FDMISM_EVENT_PORT_OFFLINE:
1633 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1634 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
1635 &fdmi->fcxp_wqe);
1636 break;
1638 default:
1639 bfa_sm_fault(port->fcs, event);
1643 static void
1644 bfa_fcs_lport_fdmi_sm_rprt(struct bfa_fcs_lport_fdmi_s *fdmi,
1645 enum port_fdmi_event event)
1647 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1649 bfa_trc(port->fcs, port->port_cfg.pwwn);
1650 bfa_trc(port->fcs, event);
1652 switch (event) {
1653 case FDMISM_EVENT_RSP_ERROR:
1655 * if max retries have not been reached, start timer for a
1656 * delayed retry
1658 if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
1659 bfa_sm_set_state(fdmi,
1660 bfa_fcs_lport_fdmi_sm_rprt_retry);
1661 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
1662 &fdmi->timer,
1663 bfa_fcs_lport_fdmi_timeout, fdmi,
1664 BFA_FCS_RETRY_TIMEOUT);
1666 } else {
1668 * set state to offline
1670 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1671 fdmi->retry_cnt = 0;
1673 break;
1675 case FDMISM_EVENT_RSP_OK:
1676 fdmi->retry_cnt = 0;
1677 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_online);
1678 break;
1680 case FDMISM_EVENT_PORT_OFFLINE:
1681 bfa_fcxp_discard(fdmi->fcxp);
1682 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1683 break;
1685 default:
1686 bfa_sm_fault(port->fcs, event);
1690 static void
1691 bfa_fcs_lport_fdmi_sm_rprt_retry(struct bfa_fcs_lport_fdmi_s *fdmi,
1692 enum port_fdmi_event event)
1694 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1696 bfa_trc(port->fcs, port->port_cfg.pwwn);
1697 bfa_trc(port->fcs, event);
1699 switch (event) {
1700 case FDMISM_EVENT_TIMEOUT:
1702 * Retry Timer Expired. Re-send
1704 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rprt);
1705 bfa_fcs_lport_fdmi_send_rprt(fdmi, NULL);
1706 break;
1708 case FDMISM_EVENT_PORT_OFFLINE:
1709 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1710 bfa_timer_stop(&fdmi->timer);
1711 break;
1713 default:
1714 bfa_sm_fault(port->fcs, event);
1719 * Register Port Attributes
1721 static void
1722 bfa_fcs_lport_fdmi_sm_sending_rpa(struct bfa_fcs_lport_fdmi_s *fdmi,
1723 enum port_fdmi_event event)
1725 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1727 bfa_trc(port->fcs, port->port_cfg.pwwn);
1728 bfa_trc(port->fcs, event);
1730 switch (event) {
1731 case FDMISM_EVENT_RPA_SENT:
1732 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rpa);
1733 break;
1735 case FDMISM_EVENT_PORT_OFFLINE:
1736 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1737 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
1738 &fdmi->fcxp_wqe);
1739 break;
1741 default:
1742 bfa_sm_fault(port->fcs, event);
1746 static void
1747 bfa_fcs_lport_fdmi_sm_rpa(struct bfa_fcs_lport_fdmi_s *fdmi,
1748 enum port_fdmi_event event)
1750 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1752 bfa_trc(port->fcs, port->port_cfg.pwwn);
1753 bfa_trc(port->fcs, event);
1755 switch (event) {
1756 case FDMISM_EVENT_RSP_ERROR:
1758 * if max retries have not been reached, start timer for a
1759 * delayed retry
1761 if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
1762 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rpa_retry);
1763 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
1764 &fdmi->timer,
1765 bfa_fcs_lport_fdmi_timeout, fdmi,
1766 BFA_FCS_RETRY_TIMEOUT);
1767 } else {
1769 * set state to offline
1771 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1772 fdmi->retry_cnt = 0;
1774 break;
1776 case FDMISM_EVENT_RSP_OK:
1777 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_online);
1778 fdmi->retry_cnt = 0;
1779 break;
1781 case FDMISM_EVENT_PORT_OFFLINE:
1782 bfa_fcxp_discard(fdmi->fcxp);
1783 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1784 break;
1786 default:
1787 bfa_sm_fault(port->fcs, event);
1791 static void
1792 bfa_fcs_lport_fdmi_sm_rpa_retry(struct bfa_fcs_lport_fdmi_s *fdmi,
1793 enum port_fdmi_event event)
1795 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1797 bfa_trc(port->fcs, port->port_cfg.pwwn);
1798 bfa_trc(port->fcs, event);
1800 switch (event) {
1801 case FDMISM_EVENT_TIMEOUT:
1803 * Retry Timer Expired. Re-send
1805 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rpa);
1806 bfa_fcs_lport_fdmi_send_rpa(fdmi, NULL);
1807 break;
1809 case FDMISM_EVENT_PORT_OFFLINE:
1810 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1811 bfa_timer_stop(&fdmi->timer);
1812 break;
1814 default:
1815 bfa_sm_fault(port->fcs, event);
1819 static void
1820 bfa_fcs_lport_fdmi_sm_online(struct bfa_fcs_lport_fdmi_s *fdmi,
1821 enum port_fdmi_event event)
1823 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1825 bfa_trc(port->fcs, port->port_cfg.pwwn);
1826 bfa_trc(port->fcs, event);
1828 switch (event) {
1829 case FDMISM_EVENT_PORT_OFFLINE:
1830 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1831 break;
1833 default:
1834 bfa_sm_fault(port->fcs, event);
1838 * FDMI is disabled state.
1840 static void
1841 bfa_fcs_lport_fdmi_sm_disabled(struct bfa_fcs_lport_fdmi_s *fdmi,
1842 enum port_fdmi_event event)
1844 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1846 bfa_trc(port->fcs, port->port_cfg.pwwn);
1847 bfa_trc(port->fcs, event);
1849 /* No op State. It can only be enabled at Driver Init. */
1853 * RHBA : Register HBA Attributes.
1855 static void
1856 bfa_fcs_lport_fdmi_send_rhba(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1858 struct bfa_fcs_lport_fdmi_s *fdmi = fdmi_cbarg;
1859 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1860 struct fchs_s fchs;
1861 int len, attr_len;
1862 struct bfa_fcxp_s *fcxp;
1863 u8 *pyld;
1865 bfa_trc(port->fcs, port->port_cfg.pwwn);
1867 fcxp = fcxp_alloced ? fcxp_alloced :
1868 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
1869 if (!fcxp) {
1870 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
1871 bfa_fcs_lport_fdmi_send_rhba, fdmi, BFA_TRUE);
1872 return;
1874 fdmi->fcxp = fcxp;
1876 pyld = bfa_fcxp_get_reqbuf(fcxp);
1877 memset(pyld, 0, FC_MAX_PDUSZ);
1879 len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
1880 FDMI_RHBA);
1882 attr_len =
1883 bfa_fcs_lport_fdmi_build_rhba_pyld(fdmi,
1884 (u8 *) ((struct ct_hdr_s *) pyld
1885 + 1));
1887 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1888 FC_CLASS_3, (len + attr_len), &fchs,
1889 bfa_fcs_lport_fdmi_rhba_response, (void *)fdmi,
1890 FC_MAX_PDUSZ, FC_FCCT_TOV);
1892 bfa_sm_send_event(fdmi, FDMISM_EVENT_RHBA_SENT);
1895 static u16
1896 bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
1898 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1899 struct bfa_fcs_fdmi_hba_attr_s hba_attr;
1900 struct bfa_fcs_fdmi_hba_attr_s *fcs_hba_attr = &hba_attr;
1901 struct fdmi_rhba_s *rhba = (struct fdmi_rhba_s *) pyld;
1902 struct fdmi_attr_s *attr;
1903 u8 *curr_ptr;
1904 u16 len, count;
1905 u16 templen;
1908 * get hba attributes
1910 bfa_fcs_fdmi_get_hbaattr(fdmi, fcs_hba_attr);
1912 rhba->hba_id = bfa_fcs_lport_get_pwwn(port);
1913 rhba->port_list.num_ports = cpu_to_be32(1);
1914 rhba->port_list.port_entry = bfa_fcs_lport_get_pwwn(port);
1916 len = sizeof(rhba->hba_id) + sizeof(rhba->port_list);
1918 count = 0;
1919 len += sizeof(rhba->hba_attr_blk.attr_count);
1922 * fill out the invididual entries of the HBA attrib Block
1924 curr_ptr = (u8 *) &rhba->hba_attr_blk.hba_attr;
1927 * Node Name
1929 attr = (struct fdmi_attr_s *) curr_ptr;
1930 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_NODENAME);
1931 templen = sizeof(wwn_t);
1932 memcpy(attr->value, &bfa_fcs_lport_get_nwwn(port), templen);
1933 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1934 len += templen;
1935 count++;
1936 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1937 sizeof(templen));
1940 * Manufacturer
1942 attr = (struct fdmi_attr_s *) curr_ptr;
1943 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MANUFACTURER);
1944 templen = (u16) strlen(fcs_hba_attr->manufacturer);
1945 memcpy(attr->value, fcs_hba_attr->manufacturer, templen);
1946 templen = fc_roundup(templen, sizeof(u32));
1947 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1948 len += templen;
1949 count++;
1950 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1951 sizeof(templen));
1954 * Serial Number
1956 attr = (struct fdmi_attr_s *) curr_ptr;
1957 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_SERIALNUM);
1958 templen = (u16) strlen(fcs_hba_attr->serial_num);
1959 memcpy(attr->value, fcs_hba_attr->serial_num, templen);
1960 templen = fc_roundup(templen, sizeof(u32));
1961 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1962 len += templen;
1963 count++;
1964 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1965 sizeof(templen));
1968 * Model
1970 attr = (struct fdmi_attr_s *) curr_ptr;
1971 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MODEL);
1972 templen = (u16) strlen(fcs_hba_attr->model);
1973 memcpy(attr->value, fcs_hba_attr->model, templen);
1974 templen = fc_roundup(templen, sizeof(u32));
1975 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1976 len += templen;
1977 count++;
1978 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1979 sizeof(templen));
1982 * Model Desc
1984 attr = (struct fdmi_attr_s *) curr_ptr;
1985 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MODEL_DESC);
1986 templen = (u16) strlen(fcs_hba_attr->model_desc);
1987 memcpy(attr->value, fcs_hba_attr->model_desc, templen);
1988 templen = fc_roundup(templen, sizeof(u32));
1989 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1990 len += templen;
1991 count++;
1992 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1993 sizeof(templen));
1996 * H/W Version
1998 if (fcs_hba_attr->hw_version[0] != '\0') {
1999 attr = (struct fdmi_attr_s *) curr_ptr;
2000 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_HW_VERSION);
2001 templen = (u16) strlen(fcs_hba_attr->hw_version);
2002 memcpy(attr->value, fcs_hba_attr->hw_version, templen);
2003 templen = fc_roundup(templen, sizeof(u32));
2004 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2005 len += templen;
2006 count++;
2007 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2008 sizeof(templen));
2012 * Driver Version
2014 attr = (struct fdmi_attr_s *) curr_ptr;
2015 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_DRIVER_VERSION);
2016 templen = (u16) strlen(fcs_hba_attr->driver_version);
2017 memcpy(attr->value, fcs_hba_attr->driver_version, templen);
2018 templen = fc_roundup(templen, sizeof(u32));
2019 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2020 len += templen;
2021 count++;
2022 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2023 sizeof(templen));
2026 * Option Rom Version
2028 if (fcs_hba_attr->option_rom_ver[0] != '\0') {
2029 attr = (struct fdmi_attr_s *) curr_ptr;
2030 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_ROM_VERSION);
2031 templen = (u16) strlen(fcs_hba_attr->option_rom_ver);
2032 memcpy(attr->value, fcs_hba_attr->option_rom_ver, templen);
2033 templen = fc_roundup(templen, sizeof(u32));
2034 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2035 len += templen;
2036 count++;
2037 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2038 sizeof(templen));
2041 attr = (struct fdmi_attr_s *) curr_ptr;
2042 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_FW_VERSION);
2043 templen = (u16) strlen(fcs_hba_attr->fw_version);
2044 memcpy(attr->value, fcs_hba_attr->fw_version, templen);
2045 templen = fc_roundup(templen, sizeof(u32));
2046 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2047 len += templen;
2048 count++;
2049 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2050 sizeof(templen));
2053 * OS Name
2055 if (fcs_hba_attr->os_name[0] != '\0') {
2056 attr = (struct fdmi_attr_s *) curr_ptr;
2057 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_OS_NAME);
2058 templen = (u16) strlen(fcs_hba_attr->os_name);
2059 memcpy(attr->value, fcs_hba_attr->os_name, templen);
2060 templen = fc_roundup(templen, sizeof(u32));
2061 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2062 len += templen;
2063 count++;
2064 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2065 sizeof(templen));
2069 * MAX_CT_PAYLOAD
2071 attr = (struct fdmi_attr_s *) curr_ptr;
2072 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MAX_CT);
2073 templen = sizeof(fcs_hba_attr->max_ct_pyld);
2074 memcpy(attr->value, &fcs_hba_attr->max_ct_pyld, templen);
2075 templen = fc_roundup(templen, sizeof(u32));
2076 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2077 len += templen;
2078 count++;
2079 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2080 sizeof(templen));
2082 * Send extended attributes ( FOS 7.1 support )
2084 if (fdmi->retry_cnt == 0) {
2085 attr = (struct fdmi_attr_s *) curr_ptr;
2086 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_NODE_SYM_NAME);
2087 templen = sizeof(fcs_hba_attr->node_sym_name);
2088 memcpy(attr->value, &fcs_hba_attr->node_sym_name, templen);
2089 templen = fc_roundup(templen, sizeof(u32));
2090 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2091 len += templen;
2092 count++;
2093 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2094 sizeof(templen));
2096 attr = (struct fdmi_attr_s *) curr_ptr;
2097 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_VENDOR_ID);
2098 templen = sizeof(fcs_hba_attr->vendor_info);
2099 memcpy(attr->value, &fcs_hba_attr->vendor_info, templen);
2100 templen = fc_roundup(templen, sizeof(u32));
2101 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2102 len += templen;
2103 count++;
2104 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2105 sizeof(templen));
2107 attr = (struct fdmi_attr_s *) curr_ptr;
2108 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_NUM_PORTS);
2109 templen = sizeof(fcs_hba_attr->num_ports);
2110 memcpy(attr->value, &fcs_hba_attr->num_ports, templen);
2111 templen = fc_roundup(templen, sizeof(u32));
2112 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2113 len += templen;
2114 count++;
2115 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2116 sizeof(templen));
2118 attr = (struct fdmi_attr_s *) curr_ptr;
2119 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_FABRIC_NAME);
2120 templen = sizeof(fcs_hba_attr->fabric_name);
2121 memcpy(attr->value, &fcs_hba_attr->fabric_name, templen);
2122 templen = fc_roundup(templen, sizeof(u32));
2123 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2124 len += templen;
2125 count++;
2126 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2127 sizeof(templen));
2129 attr = (struct fdmi_attr_s *) curr_ptr;
2130 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_BIOS_VER);
2131 templen = sizeof(fcs_hba_attr->bios_ver);
2132 memcpy(attr->value, &fcs_hba_attr->bios_ver, templen);
2133 templen = fc_roundup(attr->len, sizeof(u32));
2134 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2135 len += templen;
2136 count++;
2137 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2138 sizeof(templen));
2142 * Update size of payload
2144 len += ((sizeof(attr->type) + sizeof(attr->len)) * count);
2146 rhba->hba_attr_blk.attr_count = cpu_to_be32(count);
2147 return len;
2150 static void
2151 bfa_fcs_lport_fdmi_rhba_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
2152 void *cbarg, bfa_status_t req_status,
2153 u32 rsp_len, u32 resid_len,
2154 struct fchs_s *rsp_fchs)
2156 struct bfa_fcs_lport_fdmi_s *fdmi =
2157 (struct bfa_fcs_lport_fdmi_s *) cbarg;
2158 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2159 struct ct_hdr_s *cthdr = NULL;
2161 bfa_trc(port->fcs, port->port_cfg.pwwn);
2164 * Sanity Checks
2166 if (req_status != BFA_STATUS_OK) {
2167 bfa_trc(port->fcs, req_status);
2168 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2169 return;
2172 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
2173 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
2175 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
2176 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
2177 return;
2180 bfa_trc(port->fcs, cthdr->reason_code);
2181 bfa_trc(port->fcs, cthdr->exp_code);
2182 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2186 * RPRT : Register Port
2188 static void
2189 bfa_fcs_lport_fdmi_send_rprt(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
2191 struct bfa_fcs_lport_fdmi_s *fdmi = fdmi_cbarg;
2192 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2193 struct fchs_s fchs;
2194 u16 len, attr_len;
2195 struct bfa_fcxp_s *fcxp;
2196 u8 *pyld;
2198 bfa_trc(port->fcs, port->port_cfg.pwwn);
2200 fcxp = fcxp_alloced ? fcxp_alloced :
2201 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
2202 if (!fcxp) {
2203 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
2204 bfa_fcs_lport_fdmi_send_rprt, fdmi, BFA_TRUE);
2205 return;
2207 fdmi->fcxp = fcxp;
2209 pyld = bfa_fcxp_get_reqbuf(fcxp);
2210 memset(pyld, 0, FC_MAX_PDUSZ);
2212 len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
2213 FDMI_RPRT);
2215 attr_len =
2216 bfa_fcs_lport_fdmi_build_rprt_pyld(fdmi,
2217 (u8 *) ((struct ct_hdr_s *) pyld
2218 + 1));
2220 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
2221 FC_CLASS_3, len + attr_len, &fchs,
2222 bfa_fcs_lport_fdmi_rprt_response, (void *)fdmi,
2223 FC_MAX_PDUSZ, FC_FCCT_TOV);
2225 bfa_sm_send_event(fdmi, FDMISM_EVENT_RPRT_SENT);
2229 * This routine builds Port Attribute Block that used in RPA, RPRT commands.
2231 static u16
2232 bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s *fdmi,
2233 u8 *pyld)
2235 struct bfa_fcs_fdmi_port_attr_s fcs_port_attr;
2236 struct fdmi_port_attr_s *port_attrib = (struct fdmi_port_attr_s *) pyld;
2237 struct fdmi_attr_s *attr;
2238 u8 *curr_ptr;
2239 u16 len;
2240 u8 count = 0;
2241 u16 templen;
2244 * get port attributes
2246 bfa_fcs_fdmi_get_portattr(fdmi, &fcs_port_attr);
2248 len = sizeof(port_attrib->attr_count);
2251 * fill out the invididual entries
2253 curr_ptr = (u8 *) &port_attrib->port_attr;
2256 * FC4 Types
2258 attr = (struct fdmi_attr_s *) curr_ptr;
2259 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_FC4_TYPES);
2260 templen = sizeof(fcs_port_attr.supp_fc4_types);
2261 memcpy(attr->value, fcs_port_attr.supp_fc4_types, templen);
2262 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2263 len += templen;
2264 ++count;
2265 attr->len =
2266 cpu_to_be16(templen + sizeof(attr->type) +
2267 sizeof(templen));
2270 * Supported Speed
2272 attr = (struct fdmi_attr_s *) curr_ptr;
2273 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_SUPP_SPEED);
2274 templen = sizeof(fcs_port_attr.supp_speed);
2275 memcpy(attr->value, &fcs_port_attr.supp_speed, templen);
2276 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2277 len += templen;
2278 ++count;
2279 attr->len =
2280 cpu_to_be16(templen + sizeof(attr->type) +
2281 sizeof(templen));
2284 * current Port Speed
2286 attr = (struct fdmi_attr_s *) curr_ptr;
2287 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_SPEED);
2288 templen = sizeof(fcs_port_attr.curr_speed);
2289 memcpy(attr->value, &fcs_port_attr.curr_speed, templen);
2290 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2291 len += templen;
2292 ++count;
2293 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2294 sizeof(templen));
2297 * max frame size
2299 attr = (struct fdmi_attr_s *) curr_ptr;
2300 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_FRAME_SIZE);
2301 templen = sizeof(fcs_port_attr.max_frm_size);
2302 memcpy(attr->value, &fcs_port_attr.max_frm_size, templen);
2303 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2304 len += templen;
2305 ++count;
2306 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2307 sizeof(templen));
2310 * OS Device Name
2312 if (fcs_port_attr.os_device_name[0] != '\0') {
2313 attr = (struct fdmi_attr_s *) curr_ptr;
2314 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_DEV_NAME);
2315 templen = (u16) strlen(fcs_port_attr.os_device_name);
2316 memcpy(attr->value, fcs_port_attr.os_device_name, templen);
2317 templen = fc_roundup(templen, sizeof(u32));
2318 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2319 len += templen;
2320 ++count;
2321 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2322 sizeof(templen));
2325 * Host Name
2327 if (fcs_port_attr.host_name[0] != '\0') {
2328 attr = (struct fdmi_attr_s *) curr_ptr;
2329 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_HOST_NAME);
2330 templen = (u16) strlen(fcs_port_attr.host_name);
2331 memcpy(attr->value, fcs_port_attr.host_name, templen);
2332 templen = fc_roundup(templen, sizeof(u32));
2333 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2334 len += templen;
2335 ++count;
2336 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2337 sizeof(templen));
2340 if (fdmi->retry_cnt == 0) {
2341 attr = (struct fdmi_attr_s *) curr_ptr;
2342 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_NODE_NAME);
2343 templen = sizeof(fcs_port_attr.node_name);
2344 memcpy(attr->value, &fcs_port_attr.node_name, templen);
2345 templen = fc_roundup(templen, sizeof(u32));
2346 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2347 len += templen;
2348 ++count;
2349 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2350 sizeof(templen));
2352 attr = (struct fdmi_attr_s *) curr_ptr;
2353 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_NAME);
2354 templen = sizeof(fcs_port_attr.port_name);
2355 memcpy(attr->value, &fcs_port_attr.port_name, templen);
2356 templen = fc_roundup(templen, sizeof(u32));
2357 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + templen;
2358 len += templen;
2359 ++count;
2360 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2361 sizeof(templen));
2363 if (fcs_port_attr.port_sym_name.symname[0] != '\0') {
2364 attr = (struct fdmi_attr_s *) curr_ptr;
2365 attr->type =
2366 cpu_to_be16(FDMI_PORT_ATTRIB_PORT_SYM_NAME);
2367 templen = sizeof(fcs_port_attr.port_sym_name);
2368 memcpy(attr->value,
2369 &fcs_port_attr.port_sym_name, templen);
2370 templen = fc_roundup(templen, sizeof(u32));
2371 curr_ptr += sizeof(attr->type) +
2372 sizeof(templen) + templen;
2373 len += templen;
2374 ++count;
2375 attr->len = cpu_to_be16(templen +
2376 sizeof(attr->type) + sizeof(templen));
2379 attr = (struct fdmi_attr_s *) curr_ptr;
2380 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_TYPE);
2381 templen = sizeof(fcs_port_attr.port_type);
2382 memcpy(attr->value, &fcs_port_attr.port_type, templen);
2383 templen = fc_roundup(templen, sizeof(u32));
2384 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2385 len += templen;
2386 ++count;
2387 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2388 sizeof(templen));
2390 attr = (struct fdmi_attr_s *) curr_ptr;
2391 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_SUPP_COS);
2392 templen = sizeof(fcs_port_attr.scos);
2393 memcpy(attr->value, &fcs_port_attr.scos, templen);
2394 templen = fc_roundup(templen, sizeof(u32));
2395 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2396 len += templen;
2397 ++count;
2398 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2399 sizeof(templen));
2401 attr = (struct fdmi_attr_s *) curr_ptr;
2402 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_FAB_NAME);
2403 templen = sizeof(fcs_port_attr.port_fabric_name);
2404 memcpy(attr->value, &fcs_port_attr.port_fabric_name, templen);
2405 templen = fc_roundup(templen, sizeof(u32));
2406 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2407 len += templen;
2408 ++count;
2409 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2410 sizeof(templen));
2412 attr = (struct fdmi_attr_s *) curr_ptr;
2413 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_FC4_TYPE);
2414 templen = sizeof(fcs_port_attr.port_act_fc4_type);
2415 memcpy(attr->value, fcs_port_attr.port_act_fc4_type,
2416 templen);
2417 templen = fc_roundup(templen, sizeof(u32));
2418 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2419 len += templen;
2420 ++count;
2421 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2422 sizeof(templen));
2424 attr = (struct fdmi_attr_s *) curr_ptr;
2425 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_STATE);
2426 templen = sizeof(fcs_port_attr.port_state);
2427 memcpy(attr->value, &fcs_port_attr.port_state, templen);
2428 templen = fc_roundup(templen, sizeof(u32));
2429 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2430 len += templen;
2431 ++count;
2432 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2433 sizeof(templen));
2435 attr = (struct fdmi_attr_s *) curr_ptr;
2436 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_NUM_RPRT);
2437 templen = sizeof(fcs_port_attr.num_ports);
2438 memcpy(attr->value, &fcs_port_attr.num_ports, templen);
2439 templen = fc_roundup(templen, sizeof(u32));
2440 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2441 len += templen;
2442 ++count;
2443 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2444 sizeof(templen));
2448 * Update size of payload
2450 port_attrib->attr_count = cpu_to_be32(count);
2451 len += ((sizeof(attr->type) + sizeof(attr->len)) * count);
2452 return len;
2455 static u16
2456 bfa_fcs_lport_fdmi_build_rprt_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
2458 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2459 struct fdmi_rprt_s *rprt = (struct fdmi_rprt_s *) pyld;
2460 u16 len;
2462 rprt->hba_id = bfa_fcs_lport_get_pwwn(bfa_fcs_get_base_port(port->fcs));
2463 rprt->port_name = bfa_fcs_lport_get_pwwn(port);
2465 len = bfa_fcs_lport_fdmi_build_portattr_block(fdmi,
2466 (u8 *) &rprt->port_attr_blk);
2468 len += sizeof(rprt->hba_id) + sizeof(rprt->port_name);
2470 return len;
2473 static void
2474 bfa_fcs_lport_fdmi_rprt_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
2475 void *cbarg, bfa_status_t req_status,
2476 u32 rsp_len, u32 resid_len,
2477 struct fchs_s *rsp_fchs)
2479 struct bfa_fcs_lport_fdmi_s *fdmi =
2480 (struct bfa_fcs_lport_fdmi_s *) cbarg;
2481 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2482 struct ct_hdr_s *cthdr = NULL;
2484 bfa_trc(port->fcs, port->port_cfg.pwwn);
2487 * Sanity Checks
2489 if (req_status != BFA_STATUS_OK) {
2490 bfa_trc(port->fcs, req_status);
2491 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2492 return;
2495 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
2496 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
2498 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
2499 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
2500 return;
2503 bfa_trc(port->fcs, cthdr->reason_code);
2504 bfa_trc(port->fcs, cthdr->exp_code);
2505 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2509 * RPA : Register Port Attributes.
2511 static void
2512 bfa_fcs_lport_fdmi_send_rpa(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
2514 struct bfa_fcs_lport_fdmi_s *fdmi = fdmi_cbarg;
2515 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2516 struct fchs_s fchs;
2517 u16 len, attr_len;
2518 struct bfa_fcxp_s *fcxp;
2519 u8 *pyld;
2521 bfa_trc(port->fcs, port->port_cfg.pwwn);
2523 fcxp = fcxp_alloced ? fcxp_alloced :
2524 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
2525 if (!fcxp) {
2526 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
2527 bfa_fcs_lport_fdmi_send_rpa, fdmi, BFA_TRUE);
2528 return;
2530 fdmi->fcxp = fcxp;
2532 pyld = bfa_fcxp_get_reqbuf(fcxp);
2533 memset(pyld, 0, FC_MAX_PDUSZ);
2535 len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
2536 FDMI_RPA);
2538 attr_len = bfa_fcs_lport_fdmi_build_rpa_pyld(fdmi,
2539 (u8 *) ((struct ct_hdr_s *) pyld + 1));
2541 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
2542 FC_CLASS_3, len + attr_len, &fchs,
2543 bfa_fcs_lport_fdmi_rpa_response, (void *)fdmi,
2544 FC_MAX_PDUSZ, FC_FCCT_TOV);
2546 bfa_sm_send_event(fdmi, FDMISM_EVENT_RPA_SENT);
2549 static u16
2550 bfa_fcs_lport_fdmi_build_rpa_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
2552 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2553 struct fdmi_rpa_s *rpa = (struct fdmi_rpa_s *) pyld;
2554 u16 len;
2556 rpa->port_name = bfa_fcs_lport_get_pwwn(port);
2558 len = bfa_fcs_lport_fdmi_build_portattr_block(fdmi,
2559 (u8 *) &rpa->port_attr_blk);
2561 len += sizeof(rpa->port_name);
2563 return len;
2566 static void
2567 bfa_fcs_lport_fdmi_rpa_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
2568 void *cbarg, bfa_status_t req_status, u32 rsp_len,
2569 u32 resid_len, struct fchs_s *rsp_fchs)
2571 struct bfa_fcs_lport_fdmi_s *fdmi =
2572 (struct bfa_fcs_lport_fdmi_s *) cbarg;
2573 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2574 struct ct_hdr_s *cthdr = NULL;
2576 bfa_trc(port->fcs, port->port_cfg.pwwn);
2579 * Sanity Checks
2581 if (req_status != BFA_STATUS_OK) {
2582 bfa_trc(port->fcs, req_status);
2583 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2584 return;
2587 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
2588 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
2590 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
2591 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
2592 return;
2595 bfa_trc(port->fcs, cthdr->reason_code);
2596 bfa_trc(port->fcs, cthdr->exp_code);
2597 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2600 static void
2601 bfa_fcs_lport_fdmi_timeout(void *arg)
2603 struct bfa_fcs_lport_fdmi_s *fdmi = (struct bfa_fcs_lport_fdmi_s *) arg;
2605 bfa_sm_send_event(fdmi, FDMISM_EVENT_TIMEOUT);
2608 static void
2609 bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s *fdmi,
2610 struct bfa_fcs_fdmi_hba_attr_s *hba_attr)
2612 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2613 struct bfa_fcs_driver_info_s *driver_info = &port->fcs->driver_info;
2614 struct bfa_fcs_fdmi_port_attr_s fcs_port_attr;
2616 memset(hba_attr, 0, sizeof(struct bfa_fcs_fdmi_hba_attr_s));
2618 bfa_ioc_get_adapter_manufacturer(&port->fcs->bfa->ioc,
2619 hba_attr->manufacturer);
2620 bfa_ioc_get_adapter_serial_num(&port->fcs->bfa->ioc,
2621 hba_attr->serial_num);
2622 bfa_ioc_get_adapter_model(&port->fcs->bfa->ioc,
2623 hba_attr->model);
2624 bfa_ioc_get_adapter_model(&port->fcs->bfa->ioc,
2625 hba_attr->model_desc);
2626 bfa_ioc_get_pci_chip_rev(&port->fcs->bfa->ioc,
2627 hba_attr->hw_version);
2628 bfa_ioc_get_adapter_optrom_ver(&port->fcs->bfa->ioc,
2629 hba_attr->option_rom_ver);
2630 bfa_ioc_get_adapter_fw_ver(&port->fcs->bfa->ioc,
2631 hba_attr->fw_version);
2633 strncpy(hba_attr->driver_version, (char *)driver_info->version,
2634 sizeof(hba_attr->driver_version));
2636 strncpy(hba_attr->os_name, driver_info->host_os_name,
2637 sizeof(hba_attr->os_name));
2640 * If there is a patch level, append it
2641 * to the os name along with a separator
2643 if (driver_info->host_os_patch[0] != '\0') {
2644 strncat(hba_attr->os_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
2645 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
2646 strncat(hba_attr->os_name, driver_info->host_os_patch,
2647 sizeof(driver_info->host_os_patch));
2650 /* Retrieve the max frame size from the port attr */
2651 bfa_fcs_fdmi_get_portattr(fdmi, &fcs_port_attr);
2652 hba_attr->max_ct_pyld = fcs_port_attr.max_frm_size;
2654 strncpy(hba_attr->node_sym_name.symname,
2655 port->port_cfg.node_sym_name.symname, BFA_SYMNAME_MAXLEN);
2656 strcpy(hba_attr->vendor_info, "BROCADE");
2657 hba_attr->num_ports =
2658 cpu_to_be32(bfa_ioc_get_nports(&port->fcs->bfa->ioc));
2659 hba_attr->fabric_name = port->fabric->lps->pr_nwwn;
2660 strncpy(hba_attr->bios_ver, hba_attr->option_rom_ver, BFA_VERSION_LEN);
2664 static void
2665 bfa_fcs_fdmi_get_portattr(struct bfa_fcs_lport_fdmi_s *fdmi,
2666 struct bfa_fcs_fdmi_port_attr_s *port_attr)
2668 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2669 struct bfa_fcs_driver_info_s *driver_info = &port->fcs->driver_info;
2670 struct bfa_port_attr_s pport_attr;
2671 struct bfa_lport_attr_s lport_attr;
2673 memset(port_attr, 0, sizeof(struct bfa_fcs_fdmi_port_attr_s));
2676 * get pport attributes from hal
2678 bfa_fcport_get_attr(port->fcs->bfa, &pport_attr);
2681 * get FC4 type Bitmask
2683 fc_get_fc4type_bitmask(FC_TYPE_FCP, port_attr->supp_fc4_types);
2686 * Supported Speeds
2688 switch (pport_attr.speed_supported) {
2689 case BFA_PORT_SPEED_16GBPS:
2690 port_attr->supp_speed =
2691 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_16G);
2692 break;
2694 case BFA_PORT_SPEED_10GBPS:
2695 port_attr->supp_speed =
2696 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_10G);
2697 break;
2699 case BFA_PORT_SPEED_8GBPS:
2700 port_attr->supp_speed =
2701 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_8G);
2702 break;
2704 case BFA_PORT_SPEED_4GBPS:
2705 port_attr->supp_speed =
2706 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_4G);
2707 break;
2709 default:
2710 bfa_sm_fault(port->fcs, pport_attr.speed_supported);
2714 * Current Speed
2716 port_attr->curr_speed = cpu_to_be32(
2717 bfa_fcs_fdmi_convert_speed(pport_attr.speed));
2720 * Max PDU Size.
2722 port_attr->max_frm_size = cpu_to_be32(pport_attr.pport_cfg.maxfrsize);
2725 * OS device Name
2727 strncpy(port_attr->os_device_name, (char *)driver_info->os_device_name,
2728 sizeof(port_attr->os_device_name));
2731 * Host name
2733 strncpy(port_attr->host_name, (char *)driver_info->host_machine_name,
2734 sizeof(port_attr->host_name));
2736 port_attr->node_name = bfa_fcs_lport_get_nwwn(port);
2737 port_attr->port_name = bfa_fcs_lport_get_pwwn(port);
2739 strncpy(port_attr->port_sym_name.symname,
2740 (char *)&bfa_fcs_lport_get_psym_name(port), BFA_SYMNAME_MAXLEN);
2741 bfa_fcs_lport_get_attr(port, &lport_attr);
2742 port_attr->port_type = cpu_to_be32(lport_attr.port_type);
2743 port_attr->scos = pport_attr.cos_supported;
2744 port_attr->port_fabric_name = port->fabric->lps->pr_nwwn;
2745 fc_get_fc4type_bitmask(FC_TYPE_FCP, port_attr->port_act_fc4_type);
2746 port_attr->port_state = cpu_to_be32(pport_attr.port_state);
2747 port_attr->num_ports = cpu_to_be32(port->num_rports);
2751 * Convert BFA speed to FDMI format.
2754 bfa_fcs_fdmi_convert_speed(bfa_port_speed_t pport_speed)
2756 u32 ret;
2758 switch (pport_speed) {
2759 case BFA_PORT_SPEED_1GBPS:
2760 case BFA_PORT_SPEED_2GBPS:
2761 ret = pport_speed;
2762 break;
2764 case BFA_PORT_SPEED_4GBPS:
2765 ret = FDMI_TRANS_SPEED_4G;
2766 break;
2768 case BFA_PORT_SPEED_8GBPS:
2769 ret = FDMI_TRANS_SPEED_8G;
2770 break;
2772 case BFA_PORT_SPEED_10GBPS:
2773 ret = FDMI_TRANS_SPEED_10G;
2774 break;
2776 case BFA_PORT_SPEED_16GBPS:
2777 ret = FDMI_TRANS_SPEED_16G;
2778 break;
2780 default:
2781 ret = FDMI_TRANS_SPEED_UNKNOWN;
2783 return ret;
2786 void
2787 bfa_fcs_lport_fdmi_init(struct bfa_fcs_lport_ms_s *ms)
2789 struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
2791 fdmi->ms = ms;
2792 if (ms->port->fcs->fdmi_enabled)
2793 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
2794 else
2795 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_disabled);
2798 void
2799 bfa_fcs_lport_fdmi_offline(struct bfa_fcs_lport_ms_s *ms)
2801 struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
2803 fdmi->ms = ms;
2804 bfa_sm_send_event(fdmi, FDMISM_EVENT_PORT_OFFLINE);
2807 void
2808 bfa_fcs_lport_fdmi_online(struct bfa_fcs_lport_ms_s *ms)
2810 struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
2812 fdmi->ms = ms;
2813 bfa_sm_send_event(fdmi, FDMISM_EVENT_PORT_ONLINE);
2816 #define BFA_FCS_MS_CMD_MAX_RETRIES 2
2819 * forward declarations
2821 static void bfa_fcs_lport_ms_send_plogi(void *ms_cbarg,
2822 struct bfa_fcxp_s *fcxp_alloced);
2823 static void bfa_fcs_lport_ms_timeout(void *arg);
2824 static void bfa_fcs_lport_ms_plogi_response(void *fcsarg,
2825 struct bfa_fcxp_s *fcxp,
2826 void *cbarg,
2827 bfa_status_t req_status,
2828 u32 rsp_len,
2829 u32 resid_len,
2830 struct fchs_s *rsp_fchs);
2832 static void bfa_fcs_lport_ms_send_gmal(void *ms_cbarg,
2833 struct bfa_fcxp_s *fcxp_alloced);
2834 static void bfa_fcs_lport_ms_gmal_response(void *fcsarg,
2835 struct bfa_fcxp_s *fcxp,
2836 void *cbarg,
2837 bfa_status_t req_status,
2838 u32 rsp_len,
2839 u32 resid_len,
2840 struct fchs_s *rsp_fchs);
2841 static void bfa_fcs_lport_ms_send_gfn(void *ms_cbarg,
2842 struct bfa_fcxp_s *fcxp_alloced);
2843 static void bfa_fcs_lport_ms_gfn_response(void *fcsarg,
2844 struct bfa_fcxp_s *fcxp,
2845 void *cbarg,
2846 bfa_status_t req_status,
2847 u32 rsp_len,
2848 u32 resid_len,
2849 struct fchs_s *rsp_fchs);
2851 * fcs_ms_sm FCS MS state machine
2855 * MS State Machine events
2857 enum port_ms_event {
2858 MSSM_EVENT_PORT_ONLINE = 1,
2859 MSSM_EVENT_PORT_OFFLINE = 2,
2860 MSSM_EVENT_RSP_OK = 3,
2861 MSSM_EVENT_RSP_ERROR = 4,
2862 MSSM_EVENT_TIMEOUT = 5,
2863 MSSM_EVENT_FCXP_SENT = 6,
2864 MSSM_EVENT_PORT_FABRIC_RSCN = 7
2867 static void bfa_fcs_lport_ms_sm_offline(struct bfa_fcs_lport_ms_s *ms,
2868 enum port_ms_event event);
2869 static void bfa_fcs_lport_ms_sm_plogi_sending(struct bfa_fcs_lport_ms_s *ms,
2870 enum port_ms_event event);
2871 static void bfa_fcs_lport_ms_sm_plogi(struct bfa_fcs_lport_ms_s *ms,
2872 enum port_ms_event event);
2873 static void bfa_fcs_lport_ms_sm_plogi_retry(struct bfa_fcs_lport_ms_s *ms,
2874 enum port_ms_event event);
2875 static void bfa_fcs_lport_ms_sm_gmal_sending(struct bfa_fcs_lport_ms_s *ms,
2876 enum port_ms_event event);
2877 static void bfa_fcs_lport_ms_sm_gmal(struct bfa_fcs_lport_ms_s *ms,
2878 enum port_ms_event event);
2879 static void bfa_fcs_lport_ms_sm_gmal_retry(struct bfa_fcs_lport_ms_s *ms,
2880 enum port_ms_event event);
2881 static void bfa_fcs_lport_ms_sm_gfn_sending(struct bfa_fcs_lport_ms_s *ms,
2882 enum port_ms_event event);
2883 static void bfa_fcs_lport_ms_sm_gfn(struct bfa_fcs_lport_ms_s *ms,
2884 enum port_ms_event event);
2885 static void bfa_fcs_lport_ms_sm_gfn_retry(struct bfa_fcs_lport_ms_s *ms,
2886 enum port_ms_event event);
2887 static void bfa_fcs_lport_ms_sm_online(struct bfa_fcs_lport_ms_s *ms,
2888 enum port_ms_event event);
2890 * Start in offline state - awaiting NS to send start.
2892 static void
2893 bfa_fcs_lport_ms_sm_offline(struct bfa_fcs_lport_ms_s *ms,
2894 enum port_ms_event event)
2896 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2897 bfa_trc(ms->port->fcs, event);
2899 switch (event) {
2900 case MSSM_EVENT_PORT_ONLINE:
2901 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi_sending);
2902 bfa_fcs_lport_ms_send_plogi(ms, NULL);
2903 break;
2905 case MSSM_EVENT_PORT_OFFLINE:
2906 break;
2908 default:
2909 bfa_sm_fault(ms->port->fcs, event);
2913 static void
2914 bfa_fcs_lport_ms_sm_plogi_sending(struct bfa_fcs_lport_ms_s *ms,
2915 enum port_ms_event event)
2917 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2918 bfa_trc(ms->port->fcs, event);
2920 switch (event) {
2921 case MSSM_EVENT_FCXP_SENT:
2922 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi);
2923 break;
2925 case MSSM_EVENT_PORT_OFFLINE:
2926 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
2927 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
2928 &ms->fcxp_wqe);
2929 break;
2931 default:
2932 bfa_sm_fault(ms->port->fcs, event);
2936 static void
2937 bfa_fcs_lport_ms_sm_plogi(struct bfa_fcs_lport_ms_s *ms,
2938 enum port_ms_event event)
2940 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2941 bfa_trc(ms->port->fcs, event);
2943 switch (event) {
2944 case MSSM_EVENT_RSP_ERROR:
2946 * Start timer for a delayed retry
2948 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi_retry);
2949 ms->port->stats.ms_retries++;
2950 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
2951 &ms->timer, bfa_fcs_lport_ms_timeout, ms,
2952 BFA_FCS_RETRY_TIMEOUT);
2953 break;
2955 case MSSM_EVENT_RSP_OK:
2957 * since plogi is done, now invoke MS related sub-modules
2959 bfa_fcs_lport_fdmi_online(ms);
2962 * if this is a Vport, go to online state.
2964 if (ms->port->vport) {
2965 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_online);
2966 break;
2970 * For a base port we need to get the
2971 * switch's IP address.
2973 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal_sending);
2974 bfa_fcs_lport_ms_send_gmal(ms, NULL);
2975 break;
2977 case MSSM_EVENT_PORT_OFFLINE:
2978 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
2979 bfa_fcxp_discard(ms->fcxp);
2980 break;
2982 default:
2983 bfa_sm_fault(ms->port->fcs, event);
2987 static void
2988 bfa_fcs_lport_ms_sm_plogi_retry(struct bfa_fcs_lport_ms_s *ms,
2989 enum port_ms_event event)
2991 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2992 bfa_trc(ms->port->fcs, event);
2994 switch (event) {
2995 case MSSM_EVENT_TIMEOUT:
2997 * Retry Timer Expired. Re-send
2999 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi_sending);
3000 bfa_fcs_lport_ms_send_plogi(ms, NULL);
3001 break;
3003 case MSSM_EVENT_PORT_OFFLINE:
3004 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3005 bfa_timer_stop(&ms->timer);
3006 break;
3008 default:
3009 bfa_sm_fault(ms->port->fcs, event);
3013 static void
3014 bfa_fcs_lport_ms_sm_online(struct bfa_fcs_lport_ms_s *ms,
3015 enum port_ms_event event)
3017 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3018 bfa_trc(ms->port->fcs, event);
3020 switch (event) {
3021 case MSSM_EVENT_PORT_OFFLINE:
3022 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3023 break;
3025 case MSSM_EVENT_PORT_FABRIC_RSCN:
3026 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
3027 ms->retry_cnt = 0;
3028 bfa_fcs_lport_ms_send_gfn(ms, NULL);
3029 break;
3031 default:
3032 bfa_sm_fault(ms->port->fcs, event);
3036 static void
3037 bfa_fcs_lport_ms_sm_gmal_sending(struct bfa_fcs_lport_ms_s *ms,
3038 enum port_ms_event event)
3040 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3041 bfa_trc(ms->port->fcs, event);
3043 switch (event) {
3044 case MSSM_EVENT_FCXP_SENT:
3045 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal);
3046 break;
3048 case MSSM_EVENT_PORT_OFFLINE:
3049 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3050 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
3051 &ms->fcxp_wqe);
3052 break;
3054 default:
3055 bfa_sm_fault(ms->port->fcs, event);
3059 static void
3060 bfa_fcs_lport_ms_sm_gmal(struct bfa_fcs_lport_ms_s *ms,
3061 enum port_ms_event event)
3063 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3064 bfa_trc(ms->port->fcs, event);
3066 switch (event) {
3067 case MSSM_EVENT_RSP_ERROR:
3069 * Start timer for a delayed retry
3071 if (ms->retry_cnt++ < BFA_FCS_MS_CMD_MAX_RETRIES) {
3072 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal_retry);
3073 ms->port->stats.ms_retries++;
3074 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
3075 &ms->timer, bfa_fcs_lport_ms_timeout, ms,
3076 BFA_FCS_RETRY_TIMEOUT);
3077 } else {
3078 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
3079 bfa_fcs_lport_ms_send_gfn(ms, NULL);
3080 ms->retry_cnt = 0;
3082 break;
3084 case MSSM_EVENT_RSP_OK:
3085 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
3086 bfa_fcs_lport_ms_send_gfn(ms, NULL);
3087 break;
3089 case MSSM_EVENT_PORT_OFFLINE:
3090 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3091 bfa_fcxp_discard(ms->fcxp);
3092 break;
3094 default:
3095 bfa_sm_fault(ms->port->fcs, event);
3099 static void
3100 bfa_fcs_lport_ms_sm_gmal_retry(struct bfa_fcs_lport_ms_s *ms,
3101 enum port_ms_event event)
3103 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3104 bfa_trc(ms->port->fcs, event);
3106 switch (event) {
3107 case MSSM_EVENT_TIMEOUT:
3109 * Retry Timer Expired. Re-send
3111 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal_sending);
3112 bfa_fcs_lport_ms_send_gmal(ms, NULL);
3113 break;
3115 case MSSM_EVENT_PORT_OFFLINE:
3116 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3117 bfa_timer_stop(&ms->timer);
3118 break;
3120 default:
3121 bfa_sm_fault(ms->port->fcs, event);
3125 * ms_pvt MS local functions
3128 static void
3129 bfa_fcs_lport_ms_send_gmal(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
3131 struct bfa_fcs_lport_ms_s *ms = ms_cbarg;
3132 bfa_fcs_lport_t *port = ms->port;
3133 struct fchs_s fchs;
3134 int len;
3135 struct bfa_fcxp_s *fcxp;
3137 bfa_trc(port->fcs, port->pid);
3139 fcxp = fcxp_alloced ? fcxp_alloced :
3140 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
3141 if (!fcxp) {
3142 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
3143 bfa_fcs_lport_ms_send_gmal, ms, BFA_TRUE);
3144 return;
3146 ms->fcxp = fcxp;
3148 len = fc_gmal_req_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
3149 bfa_fcs_lport_get_fcid(port),
3150 port->fabric->lps->pr_nwwn);
3152 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
3153 FC_CLASS_3, len, &fchs,
3154 bfa_fcs_lport_ms_gmal_response, (void *)ms,
3155 FC_MAX_PDUSZ, FC_FCCT_TOV);
3157 bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
3160 static void
3161 bfa_fcs_lport_ms_gmal_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
3162 void *cbarg, bfa_status_t req_status,
3163 u32 rsp_len, u32 resid_len,
3164 struct fchs_s *rsp_fchs)
3166 struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) cbarg;
3167 bfa_fcs_lport_t *port = ms->port;
3168 struct ct_hdr_s *cthdr = NULL;
3169 struct fcgs_gmal_resp_s *gmal_resp;
3170 struct fcgs_gmal_entry_s *gmal_entry;
3171 u32 num_entries;
3172 u8 *rsp_str;
3174 bfa_trc(port->fcs, req_status);
3175 bfa_trc(port->fcs, port->port_cfg.pwwn);
3178 * Sanity Checks
3180 if (req_status != BFA_STATUS_OK) {
3181 bfa_trc(port->fcs, req_status);
3182 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3183 return;
3186 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
3187 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
3189 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
3190 gmal_resp = (struct fcgs_gmal_resp_s *)(cthdr + 1);
3192 num_entries = be32_to_cpu(gmal_resp->ms_len);
3193 if (num_entries == 0) {
3194 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3195 return;
3198 * The response could contain multiple Entries.
3199 * Entries for SNMP interface, etc.
3200 * We look for the entry with a telnet prefix.
3201 * First "http://" entry refers to IP addr
3204 gmal_entry = (struct fcgs_gmal_entry_s *)gmal_resp->ms_ma;
3205 while (num_entries > 0) {
3206 if (strncmp(gmal_entry->prefix,
3207 CT_GMAL_RESP_PREFIX_HTTP,
3208 sizeof(gmal_entry->prefix)) == 0) {
3211 * if the IP address is terminating with a '/',
3212 * remove it.
3213 * Byte 0 consists of the length of the string.
3215 rsp_str = &(gmal_entry->prefix[0]);
3216 if (rsp_str[gmal_entry->len-1] == '/')
3217 rsp_str[gmal_entry->len-1] = 0;
3219 /* copy IP Address to fabric */
3220 strncpy(bfa_fcs_lport_get_fabric_ipaddr(port),
3221 gmal_entry->ip_addr,
3222 BFA_FCS_FABRIC_IPADDR_SZ);
3223 break;
3224 } else {
3225 --num_entries;
3226 ++gmal_entry;
3230 bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
3231 return;
3234 bfa_trc(port->fcs, cthdr->reason_code);
3235 bfa_trc(port->fcs, cthdr->exp_code);
3236 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3239 static void
3240 bfa_fcs_lport_ms_sm_gfn_sending(struct bfa_fcs_lport_ms_s *ms,
3241 enum port_ms_event event)
3243 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3244 bfa_trc(ms->port->fcs, event);
3246 switch (event) {
3247 case MSSM_EVENT_FCXP_SENT:
3248 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn);
3249 break;
3251 case MSSM_EVENT_PORT_OFFLINE:
3252 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3253 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
3254 &ms->fcxp_wqe);
3255 break;
3257 default:
3258 bfa_sm_fault(ms->port->fcs, event);
3262 static void
3263 bfa_fcs_lport_ms_sm_gfn(struct bfa_fcs_lport_ms_s *ms,
3264 enum port_ms_event event)
3266 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3267 bfa_trc(ms->port->fcs, event);
3269 switch (event) {
3270 case MSSM_EVENT_RSP_ERROR:
3272 * Start timer for a delayed retry
3274 if (ms->retry_cnt++ < BFA_FCS_MS_CMD_MAX_RETRIES) {
3275 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_retry);
3276 ms->port->stats.ms_retries++;
3277 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
3278 &ms->timer, bfa_fcs_lport_ms_timeout, ms,
3279 BFA_FCS_RETRY_TIMEOUT);
3280 } else {
3281 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_online);
3282 ms->retry_cnt = 0;
3284 break;
3286 case MSSM_EVENT_RSP_OK:
3287 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_online);
3288 break;
3290 case MSSM_EVENT_PORT_OFFLINE:
3291 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3292 bfa_fcxp_discard(ms->fcxp);
3293 break;
3295 default:
3296 bfa_sm_fault(ms->port->fcs, event);
3300 static void
3301 bfa_fcs_lport_ms_sm_gfn_retry(struct bfa_fcs_lport_ms_s *ms,
3302 enum port_ms_event event)
3304 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3305 bfa_trc(ms->port->fcs, event);
3307 switch (event) {
3308 case MSSM_EVENT_TIMEOUT:
3310 * Retry Timer Expired. Re-send
3312 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
3313 bfa_fcs_lport_ms_send_gfn(ms, NULL);
3314 break;
3316 case MSSM_EVENT_PORT_OFFLINE:
3317 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3318 bfa_timer_stop(&ms->timer);
3319 break;
3321 default:
3322 bfa_sm_fault(ms->port->fcs, event);
3326 * ms_pvt MS local functions
3329 static void
3330 bfa_fcs_lport_ms_send_gfn(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
3332 struct bfa_fcs_lport_ms_s *ms = ms_cbarg;
3333 bfa_fcs_lport_t *port = ms->port;
3334 struct fchs_s fchs;
3335 int len;
3336 struct bfa_fcxp_s *fcxp;
3338 bfa_trc(port->fcs, port->pid);
3340 fcxp = fcxp_alloced ? fcxp_alloced :
3341 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
3342 if (!fcxp) {
3343 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
3344 bfa_fcs_lport_ms_send_gfn, ms, BFA_TRUE);
3345 return;
3347 ms->fcxp = fcxp;
3349 len = fc_gfn_req_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
3350 bfa_fcs_lport_get_fcid(port),
3351 port->fabric->lps->pr_nwwn);
3353 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
3354 FC_CLASS_3, len, &fchs,
3355 bfa_fcs_lport_ms_gfn_response, (void *)ms,
3356 FC_MAX_PDUSZ, FC_FCCT_TOV);
3358 bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
3361 static void
3362 bfa_fcs_lport_ms_gfn_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
3363 void *cbarg, bfa_status_t req_status, u32 rsp_len,
3364 u32 resid_len, struct fchs_s *rsp_fchs)
3366 struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) cbarg;
3367 bfa_fcs_lport_t *port = ms->port;
3368 struct ct_hdr_s *cthdr = NULL;
3369 wwn_t *gfn_resp;
3371 bfa_trc(port->fcs, req_status);
3372 bfa_trc(port->fcs, port->port_cfg.pwwn);
3375 * Sanity Checks
3377 if (req_status != BFA_STATUS_OK) {
3378 bfa_trc(port->fcs, req_status);
3379 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3380 return;
3383 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
3384 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
3386 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
3387 gfn_resp = (wwn_t *)(cthdr + 1);
3388 /* check if it has actually changed */
3389 if ((memcmp((void *)&bfa_fcs_lport_get_fabric_name(port),
3390 gfn_resp, sizeof(wwn_t)) != 0)) {
3391 bfa_fcs_fabric_set_fabric_name(port->fabric, *gfn_resp);
3393 bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
3394 return;
3397 bfa_trc(port->fcs, cthdr->reason_code);
3398 bfa_trc(port->fcs, cthdr->exp_code);
3399 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3403 * ms_pvt MS local functions
3406 static void
3407 bfa_fcs_lport_ms_send_plogi(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
3409 struct bfa_fcs_lport_ms_s *ms = ms_cbarg;
3410 struct bfa_fcs_lport_s *port = ms->port;
3411 struct fchs_s fchs;
3412 int len;
3413 struct bfa_fcxp_s *fcxp;
3415 bfa_trc(port->fcs, port->pid);
3417 fcxp = fcxp_alloced ? fcxp_alloced :
3418 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
3419 if (!fcxp) {
3420 port->stats.ms_plogi_alloc_wait++;
3421 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
3422 bfa_fcs_lport_ms_send_plogi, ms, BFA_TRUE);
3423 return;
3425 ms->fcxp = fcxp;
3427 len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
3428 bfa_hton3b(FC_MGMT_SERVER),
3429 bfa_fcs_lport_get_fcid(port), 0,
3430 port->port_cfg.pwwn, port->port_cfg.nwwn,
3431 bfa_fcport_get_maxfrsize(port->fcs->bfa),
3432 bfa_fcport_get_rx_bbcredit(port->fcs->bfa));
3434 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
3435 FC_CLASS_3, len, &fchs,
3436 bfa_fcs_lport_ms_plogi_response, (void *)ms,
3437 FC_MAX_PDUSZ, FC_ELS_TOV);
3439 port->stats.ms_plogi_sent++;
3440 bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
3443 static void
3444 bfa_fcs_lport_ms_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
3445 void *cbarg, bfa_status_t req_status,
3446 u32 rsp_len, u32 resid_len, struct fchs_s *rsp_fchs)
3448 struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) cbarg;
3449 struct bfa_fcs_lport_s *port = ms->port;
3450 struct fc_els_cmd_s *els_cmd;
3451 struct fc_ls_rjt_s *ls_rjt;
3453 bfa_trc(port->fcs, req_status);
3454 bfa_trc(port->fcs, port->port_cfg.pwwn);
3457 * Sanity Checks
3459 if (req_status != BFA_STATUS_OK) {
3460 port->stats.ms_plogi_rsp_err++;
3461 bfa_trc(port->fcs, req_status);
3462 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3463 return;
3466 els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
3468 switch (els_cmd->els_code) {
3470 case FC_ELS_ACC:
3471 if (rsp_len < sizeof(struct fc_logi_s)) {
3472 bfa_trc(port->fcs, rsp_len);
3473 port->stats.ms_plogi_acc_err++;
3474 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3475 break;
3477 port->stats.ms_plogi_accepts++;
3478 bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
3479 break;
3481 case FC_ELS_LS_RJT:
3482 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
3484 bfa_trc(port->fcs, ls_rjt->reason_code);
3485 bfa_trc(port->fcs, ls_rjt->reason_code_expl);
3487 port->stats.ms_rejects++;
3488 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3489 break;
3491 default:
3492 port->stats.ms_plogi_unknown_rsp++;
3493 bfa_trc(port->fcs, els_cmd->els_code);
3494 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3498 static void
3499 bfa_fcs_lport_ms_timeout(void *arg)
3501 struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) arg;
3503 ms->port->stats.ms_timeouts++;
3504 bfa_sm_send_event(ms, MSSM_EVENT_TIMEOUT);
3508 void
3509 bfa_fcs_lport_ms_init(struct bfa_fcs_lport_s *port)
3511 struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
3513 ms->port = port;
3514 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3517 * Invoke init routines of sub modules.
3519 bfa_fcs_lport_fdmi_init(ms);
3522 void
3523 bfa_fcs_lport_ms_offline(struct bfa_fcs_lport_s *port)
3525 struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
3527 ms->port = port;
3528 bfa_sm_send_event(ms, MSSM_EVENT_PORT_OFFLINE);
3529 bfa_fcs_lport_fdmi_offline(ms);
3532 void
3533 bfa_fcs_lport_ms_online(struct bfa_fcs_lport_s *port)
3535 struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
3537 ms->port = port;
3538 bfa_sm_send_event(ms, MSSM_EVENT_PORT_ONLINE);
3540 void
3541 bfa_fcs_lport_ms_fabric_rscn(struct bfa_fcs_lport_s *port)
3543 struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
3545 /* todo. Handle this only when in Online state */
3546 if (bfa_sm_cmp_state(ms, bfa_fcs_lport_ms_sm_online))
3547 bfa_sm_send_event(ms, MSSM_EVENT_PORT_FABRIC_RSCN);
3551 * @page ns_sm_info VPORT NS State Machine
3553 * @section ns_sm_interactions VPORT NS State Machine Interactions
3555 * @section ns_sm VPORT NS State Machine
3556 * img ns_sm.jpg
3560 * forward declarations
3562 static void bfa_fcs_lport_ns_send_plogi(void *ns_cbarg,
3563 struct bfa_fcxp_s *fcxp_alloced);
3564 static void bfa_fcs_lport_ns_send_rspn_id(void *ns_cbarg,
3565 struct bfa_fcxp_s *fcxp_alloced);
3566 static void bfa_fcs_lport_ns_send_rft_id(void *ns_cbarg,
3567 struct bfa_fcxp_s *fcxp_alloced);
3568 static void bfa_fcs_lport_ns_send_rff_id(void *ns_cbarg,
3569 struct bfa_fcxp_s *fcxp_alloced);
3570 static void bfa_fcs_lport_ns_send_gid_ft(void *ns_cbarg,
3571 struct bfa_fcxp_s *fcxp_alloced);
3572 static void bfa_fcs_lport_ns_send_rnn_id(void *ns_cbarg,
3573 struct bfa_fcxp_s *fcxp_alloced);
3574 static void bfa_fcs_lport_ns_send_rsnn_nn(void *ns_cbarg,
3575 struct bfa_fcxp_s *fcxp_alloced);
3576 static void bfa_fcs_lport_ns_timeout(void *arg);
3577 static void bfa_fcs_lport_ns_plogi_response(void *fcsarg,
3578 struct bfa_fcxp_s *fcxp,
3579 void *cbarg,
3580 bfa_status_t req_status,
3581 u32 rsp_len,
3582 u32 resid_len,
3583 struct fchs_s *rsp_fchs);
3584 static void bfa_fcs_lport_ns_rspn_id_response(void *fcsarg,
3585 struct bfa_fcxp_s *fcxp,
3586 void *cbarg,
3587 bfa_status_t req_status,
3588 u32 rsp_len,
3589 u32 resid_len,
3590 struct fchs_s *rsp_fchs);
3591 static void bfa_fcs_lport_ns_rft_id_response(void *fcsarg,
3592 struct bfa_fcxp_s *fcxp,
3593 void *cbarg,
3594 bfa_status_t req_status,
3595 u32 rsp_len,
3596 u32 resid_len,
3597 struct fchs_s *rsp_fchs);
3598 static void bfa_fcs_lport_ns_rff_id_response(void *fcsarg,
3599 struct bfa_fcxp_s *fcxp,
3600 void *cbarg,
3601 bfa_status_t req_status,
3602 u32 rsp_len,
3603 u32 resid_len,
3604 struct fchs_s *rsp_fchs);
3605 static void bfa_fcs_lport_ns_gid_ft_response(void *fcsarg,
3606 struct bfa_fcxp_s *fcxp,
3607 void *cbarg,
3608 bfa_status_t req_status,
3609 u32 rsp_len,
3610 u32 resid_len,
3611 struct fchs_s *rsp_fchs);
3612 static void bfa_fcs_lport_ns_rnn_id_response(void *fcsarg,
3613 struct bfa_fcxp_s *fcxp,
3614 void *cbarg,
3615 bfa_status_t req_status,
3616 u32 rsp_len,
3617 u32 resid_len,
3618 struct fchs_s *rsp_fchs);
3619 static void bfa_fcs_lport_ns_rsnn_nn_response(void *fcsarg,
3620 struct bfa_fcxp_s *fcxp,
3621 void *cbarg,
3622 bfa_status_t req_status,
3623 u32 rsp_len,
3624 u32 resid_len,
3625 struct fchs_s *rsp_fchs);
3626 static void bfa_fcs_lport_ns_process_gidft_pids(
3627 struct bfa_fcs_lport_s *port,
3628 u32 *pid_buf, u32 n_pids);
3630 static void bfa_fcs_lport_ns_boot_target_disc(bfa_fcs_lport_t *port);
3632 * fcs_ns_sm FCS nameserver interface state machine
3636 * VPort NS State Machine events
3638 enum vport_ns_event {
3639 NSSM_EVENT_PORT_ONLINE = 1,
3640 NSSM_EVENT_PORT_OFFLINE = 2,
3641 NSSM_EVENT_PLOGI_SENT = 3,
3642 NSSM_EVENT_RSP_OK = 4,
3643 NSSM_EVENT_RSP_ERROR = 5,
3644 NSSM_EVENT_TIMEOUT = 6,
3645 NSSM_EVENT_NS_QUERY = 7,
3646 NSSM_EVENT_RSPNID_SENT = 8,
3647 NSSM_EVENT_RFTID_SENT = 9,
3648 NSSM_EVENT_RFFID_SENT = 10,
3649 NSSM_EVENT_GIDFT_SENT = 11,
3650 NSSM_EVENT_RNNID_SENT = 12,
3651 NSSM_EVENT_RSNN_NN_SENT = 13,
3654 static void bfa_fcs_lport_ns_sm_offline(struct bfa_fcs_lport_ns_s *ns,
3655 enum vport_ns_event event);
3656 static void bfa_fcs_lport_ns_sm_plogi_sending(struct bfa_fcs_lport_ns_s *ns,
3657 enum vport_ns_event event);
3658 static void bfa_fcs_lport_ns_sm_plogi(struct bfa_fcs_lport_ns_s *ns,
3659 enum vport_ns_event event);
3660 static void bfa_fcs_lport_ns_sm_plogi_retry(struct bfa_fcs_lport_ns_s *ns,
3661 enum vport_ns_event event);
3662 static void bfa_fcs_lport_ns_sm_sending_rspn_id(
3663 struct bfa_fcs_lport_ns_s *ns,
3664 enum vport_ns_event event);
3665 static void bfa_fcs_lport_ns_sm_rspn_id(struct bfa_fcs_lport_ns_s *ns,
3666 enum vport_ns_event event);
3667 static void bfa_fcs_lport_ns_sm_rspn_id_retry(struct bfa_fcs_lport_ns_s *ns,
3668 enum vport_ns_event event);
3669 static void bfa_fcs_lport_ns_sm_sending_rft_id(
3670 struct bfa_fcs_lport_ns_s *ns,
3671 enum vport_ns_event event);
3672 static void bfa_fcs_lport_ns_sm_rft_id_retry(struct bfa_fcs_lport_ns_s *ns,
3673 enum vport_ns_event event);
3674 static void bfa_fcs_lport_ns_sm_rft_id(struct bfa_fcs_lport_ns_s *ns,
3675 enum vport_ns_event event);
3676 static void bfa_fcs_lport_ns_sm_sending_rff_id(
3677 struct bfa_fcs_lport_ns_s *ns,
3678 enum vport_ns_event event);
3679 static void bfa_fcs_lport_ns_sm_rff_id_retry(struct bfa_fcs_lport_ns_s *ns,
3680 enum vport_ns_event event);
3681 static void bfa_fcs_lport_ns_sm_rff_id(struct bfa_fcs_lport_ns_s *ns,
3682 enum vport_ns_event event);
3683 static void bfa_fcs_lport_ns_sm_sending_gid_ft(
3684 struct bfa_fcs_lport_ns_s *ns,
3685 enum vport_ns_event event);
3686 static void bfa_fcs_lport_ns_sm_gid_ft(struct bfa_fcs_lport_ns_s *ns,
3687 enum vport_ns_event event);
3688 static void bfa_fcs_lport_ns_sm_gid_ft_retry(struct bfa_fcs_lport_ns_s *ns,
3689 enum vport_ns_event event);
3690 static void bfa_fcs_lport_ns_sm_online(struct bfa_fcs_lport_ns_s *ns,
3691 enum vport_ns_event event);
3692 static void bfa_fcs_lport_ns_sm_sending_rnn_id(
3693 struct bfa_fcs_lport_ns_s *ns,
3694 enum vport_ns_event event);
3695 static void bfa_fcs_lport_ns_sm_rnn_id(struct bfa_fcs_lport_ns_s *ns,
3696 enum vport_ns_event event);
3697 static void bfa_fcs_lport_ns_sm_rnn_id_retry(struct bfa_fcs_lport_ns_s *ns,
3698 enum vport_ns_event event);
3699 static void bfa_fcs_lport_ns_sm_sending_rsnn_nn(
3700 struct bfa_fcs_lport_ns_s *ns,
3701 enum vport_ns_event event);
3702 static void bfa_fcs_lport_ns_sm_rsnn_nn(struct bfa_fcs_lport_ns_s *ns,
3703 enum vport_ns_event event);
3704 static void bfa_fcs_lport_ns_sm_rsnn_nn_retry(
3705 struct bfa_fcs_lport_ns_s *ns,
3706 enum vport_ns_event event);
3708 * Start in offline state - awaiting linkup
3710 static void
3711 bfa_fcs_lport_ns_sm_offline(struct bfa_fcs_lport_ns_s *ns,
3712 enum vport_ns_event event)
3714 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3715 bfa_trc(ns->port->fcs, event);
3717 switch (event) {
3718 case NSSM_EVENT_PORT_ONLINE:
3719 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi_sending);
3720 bfa_fcs_lport_ns_send_plogi(ns, NULL);
3721 break;
3723 case NSSM_EVENT_PORT_OFFLINE:
3724 break;
3726 default:
3727 bfa_sm_fault(ns->port->fcs, event);
3731 static void
3732 bfa_fcs_lport_ns_sm_plogi_sending(struct bfa_fcs_lport_ns_s *ns,
3733 enum vport_ns_event event)
3735 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3736 bfa_trc(ns->port->fcs, event);
3738 switch (event) {
3739 case NSSM_EVENT_PLOGI_SENT:
3740 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi);
3741 break;
3743 case NSSM_EVENT_PORT_OFFLINE:
3744 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3745 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3746 &ns->fcxp_wqe);
3747 break;
3749 default:
3750 bfa_sm_fault(ns->port->fcs, event);
3754 static void
3755 bfa_fcs_lport_ns_sm_plogi(struct bfa_fcs_lport_ns_s *ns,
3756 enum vport_ns_event event)
3758 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3759 bfa_trc(ns->port->fcs, event);
3761 switch (event) {
3762 case NSSM_EVENT_RSP_ERROR:
3764 * Start timer for a delayed retry
3766 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi_retry);
3767 ns->port->stats.ns_retries++;
3768 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3769 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
3770 BFA_FCS_RETRY_TIMEOUT);
3771 break;
3773 case NSSM_EVENT_RSP_OK:
3774 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rnn_id);
3775 ns->num_rnnid_retries = 0;
3776 bfa_fcs_lport_ns_send_rnn_id(ns, NULL);
3777 break;
3779 case NSSM_EVENT_PORT_OFFLINE:
3780 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3781 bfa_fcxp_discard(ns->fcxp);
3782 break;
3784 default:
3785 bfa_sm_fault(ns->port->fcs, event);
3789 static void
3790 bfa_fcs_lport_ns_sm_plogi_retry(struct bfa_fcs_lport_ns_s *ns,
3791 enum vport_ns_event event)
3793 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3794 bfa_trc(ns->port->fcs, event);
3796 switch (event) {
3797 case NSSM_EVENT_TIMEOUT:
3799 * Retry Timer Expired. Re-send
3801 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi_sending);
3802 bfa_fcs_lport_ns_send_plogi(ns, NULL);
3803 break;
3805 case NSSM_EVENT_PORT_OFFLINE:
3806 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3807 bfa_timer_stop(&ns->timer);
3808 break;
3810 default:
3811 bfa_sm_fault(ns->port->fcs, event);
3815 static void
3816 bfa_fcs_lport_ns_sm_sending_rnn_id(struct bfa_fcs_lport_ns_s *ns,
3817 enum vport_ns_event event)
3819 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3820 bfa_trc(ns->port->fcs, event);
3822 switch (event) {
3823 case NSSM_EVENT_RNNID_SENT:
3824 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rnn_id);
3825 break;
3827 case NSSM_EVENT_PORT_OFFLINE:
3828 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3829 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3830 &ns->fcxp_wqe);
3831 break;
3832 default:
3833 bfa_sm_fault(ns->port->fcs, event);
3837 static void
3838 bfa_fcs_lport_ns_sm_rnn_id(struct bfa_fcs_lport_ns_s *ns,
3839 enum vport_ns_event event)
3841 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3842 bfa_trc(ns->port->fcs, event);
3844 switch (event) {
3845 case NSSM_EVENT_RSP_OK:
3846 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rsnn_nn);
3847 ns->num_rnnid_retries = 0;
3848 ns->num_rsnn_nn_retries = 0;
3849 bfa_fcs_lport_ns_send_rsnn_nn(ns, NULL);
3850 break;
3852 case NSSM_EVENT_RSP_ERROR:
3853 if (ns->num_rnnid_retries < BFA_FCS_MAX_NS_RETRIES) {
3854 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rnn_id_retry);
3855 ns->port->stats.ns_retries++;
3856 ns->num_rnnid_retries++;
3857 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3858 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
3859 BFA_FCS_RETRY_TIMEOUT);
3860 } else {
3861 bfa_sm_set_state(ns,
3862 bfa_fcs_lport_ns_sm_sending_rspn_id);
3863 bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
3865 break;
3867 case NSSM_EVENT_PORT_OFFLINE:
3868 bfa_fcxp_discard(ns->fcxp);
3869 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3870 break;
3872 default:
3873 bfa_sm_fault(ns->port->fcs, event);
3877 static void
3878 bfa_fcs_lport_ns_sm_rnn_id_retry(struct bfa_fcs_lport_ns_s *ns,
3879 enum vport_ns_event event)
3881 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3882 bfa_trc(ns->port->fcs, event);
3884 switch (event) {
3885 case NSSM_EVENT_TIMEOUT:
3886 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rnn_id);
3887 bfa_fcs_lport_ns_send_rnn_id(ns, NULL);
3888 break;
3890 case NSSM_EVENT_PORT_OFFLINE:
3891 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3892 bfa_timer_stop(&ns->timer);
3893 break;
3895 default:
3896 bfa_sm_fault(ns->port->fcs, event);
3900 static void
3901 bfa_fcs_lport_ns_sm_sending_rsnn_nn(struct bfa_fcs_lport_ns_s *ns,
3902 enum vport_ns_event event)
3904 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3905 bfa_trc(ns->port->fcs, event);
3907 switch (event) {
3908 case NSSM_EVENT_RSNN_NN_SENT:
3909 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rsnn_nn);
3910 break;
3912 case NSSM_EVENT_PORT_OFFLINE:
3913 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3914 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3915 &ns->fcxp_wqe);
3916 break;
3918 default:
3919 bfa_sm_fault(ns->port->fcs, event);
3923 static void
3924 bfa_fcs_lport_ns_sm_rsnn_nn(struct bfa_fcs_lport_ns_s *ns,
3925 enum vport_ns_event event)
3927 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3928 bfa_trc(ns->port->fcs, event);
3930 switch (event) {
3931 case NSSM_EVENT_RSP_OK:
3932 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rspn_id);
3933 ns->num_rsnn_nn_retries = 0;
3934 bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
3935 break;
3937 case NSSM_EVENT_RSP_ERROR:
3938 if (ns->num_rsnn_nn_retries < BFA_FCS_MAX_NS_RETRIES) {
3939 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rsnn_nn_retry);
3940 ns->port->stats.ns_retries++;
3941 ns->num_rsnn_nn_retries++;
3942 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3943 &ns->timer, bfa_fcs_lport_ns_timeout,
3944 ns, BFA_FCS_RETRY_TIMEOUT);
3945 } else {
3946 bfa_sm_set_state(ns,
3947 bfa_fcs_lport_ns_sm_sending_rspn_id);
3948 bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
3950 break;
3952 case NSSM_EVENT_PORT_OFFLINE:
3953 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3954 bfa_fcxp_discard(ns->fcxp);
3955 break;
3957 default:
3958 bfa_sm_fault(ns->port->fcs, event);
3962 static void
3963 bfa_fcs_lport_ns_sm_rsnn_nn_retry(struct bfa_fcs_lport_ns_s *ns,
3964 enum vport_ns_event event)
3966 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3967 bfa_trc(ns->port->fcs, event);
3969 switch (event) {
3970 case NSSM_EVENT_TIMEOUT:
3971 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rsnn_nn);
3972 bfa_fcs_lport_ns_send_rsnn_nn(ns, NULL);
3973 break;
3975 case NSSM_EVENT_PORT_OFFLINE:
3976 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3977 bfa_timer_stop(&ns->timer);
3978 break;
3980 default:
3981 bfa_sm_fault(ns->port->fcs, event);
3985 static void
3986 bfa_fcs_lport_ns_sm_sending_rspn_id(struct bfa_fcs_lport_ns_s *ns,
3987 enum vport_ns_event event)
3989 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3990 bfa_trc(ns->port->fcs, event);
3992 switch (event) {
3993 case NSSM_EVENT_RSPNID_SENT:
3994 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rspn_id);
3995 break;
3997 case NSSM_EVENT_PORT_OFFLINE:
3998 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3999 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4000 &ns->fcxp_wqe);
4001 break;
4003 default:
4004 bfa_sm_fault(ns->port->fcs, event);
4008 static void
4009 bfa_fcs_lport_ns_sm_rspn_id(struct bfa_fcs_lport_ns_s *ns,
4010 enum vport_ns_event event)
4012 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4013 bfa_trc(ns->port->fcs, event);
4015 switch (event) {
4016 case NSSM_EVENT_RSP_ERROR:
4018 * Start timer for a delayed retry
4020 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rspn_id_retry);
4021 ns->port->stats.ns_retries++;
4022 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4023 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
4024 BFA_FCS_RETRY_TIMEOUT);
4025 break;
4027 case NSSM_EVENT_RSP_OK:
4028 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rft_id);
4029 bfa_fcs_lport_ns_send_rft_id(ns, NULL);
4030 break;
4032 case NSSM_EVENT_PORT_OFFLINE:
4033 bfa_fcxp_discard(ns->fcxp);
4034 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4035 break;
4037 default:
4038 bfa_sm_fault(ns->port->fcs, event);
4042 static void
4043 bfa_fcs_lport_ns_sm_rspn_id_retry(struct bfa_fcs_lport_ns_s *ns,
4044 enum vport_ns_event event)
4046 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4047 bfa_trc(ns->port->fcs, event);
4049 switch (event) {
4050 case NSSM_EVENT_TIMEOUT:
4052 * Retry Timer Expired. Re-send
4054 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rspn_id);
4055 bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
4056 break;
4058 case NSSM_EVENT_PORT_OFFLINE:
4059 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4060 bfa_timer_stop(&ns->timer);
4061 break;
4063 default:
4064 bfa_sm_fault(ns->port->fcs, event);
4068 static void
4069 bfa_fcs_lport_ns_sm_sending_rft_id(struct bfa_fcs_lport_ns_s *ns,
4070 enum vport_ns_event event)
4072 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4073 bfa_trc(ns->port->fcs, event);
4075 switch (event) {
4076 case NSSM_EVENT_RFTID_SENT:
4077 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rft_id);
4078 break;
4080 case NSSM_EVENT_PORT_OFFLINE:
4081 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4082 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4083 &ns->fcxp_wqe);
4084 break;
4086 default:
4087 bfa_sm_fault(ns->port->fcs, event);
4091 static void
4092 bfa_fcs_lport_ns_sm_rft_id(struct bfa_fcs_lport_ns_s *ns,
4093 enum vport_ns_event event)
4095 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4096 bfa_trc(ns->port->fcs, event);
4098 switch (event) {
4099 case NSSM_EVENT_RSP_OK:
4100 /* Now move to register FC4 Features */
4101 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rff_id);
4102 bfa_fcs_lport_ns_send_rff_id(ns, NULL);
4103 break;
4105 case NSSM_EVENT_RSP_ERROR:
4107 * Start timer for a delayed retry
4109 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rft_id_retry);
4110 ns->port->stats.ns_retries++;
4111 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4112 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
4113 BFA_FCS_RETRY_TIMEOUT);
4114 break;
4116 case NSSM_EVENT_PORT_OFFLINE:
4117 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4118 bfa_fcxp_discard(ns->fcxp);
4119 break;
4121 default:
4122 bfa_sm_fault(ns->port->fcs, event);
4126 static void
4127 bfa_fcs_lport_ns_sm_rft_id_retry(struct bfa_fcs_lport_ns_s *ns,
4128 enum vport_ns_event event)
4130 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4131 bfa_trc(ns->port->fcs, event);
4133 switch (event) {
4134 case NSSM_EVENT_TIMEOUT:
4135 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rft_id);
4136 bfa_fcs_lport_ns_send_rft_id(ns, NULL);
4137 break;
4139 case NSSM_EVENT_PORT_OFFLINE:
4140 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4141 bfa_timer_stop(&ns->timer);
4142 break;
4144 default:
4145 bfa_sm_fault(ns->port->fcs, event);
4149 static void
4150 bfa_fcs_lport_ns_sm_sending_rff_id(struct bfa_fcs_lport_ns_s *ns,
4151 enum vport_ns_event event)
4153 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4154 bfa_trc(ns->port->fcs, event);
4156 switch (event) {
4157 case NSSM_EVENT_RFFID_SENT:
4158 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rff_id);
4159 break;
4161 case NSSM_EVENT_PORT_OFFLINE:
4162 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4163 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4164 &ns->fcxp_wqe);
4165 break;
4167 default:
4168 bfa_sm_fault(ns->port->fcs, event);
4172 static void
4173 bfa_fcs_lport_ns_sm_rff_id(struct bfa_fcs_lport_ns_s *ns,
4174 enum vport_ns_event event)
4176 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4177 bfa_trc(ns->port->fcs, event);
4179 switch (event) {
4180 case NSSM_EVENT_RSP_OK:
4183 * If min cfg mode is enabled, we donot initiate rport
4184 * discovery with the fabric. Instead, we will retrieve the
4185 * boot targets from HAL/FW.
4187 if (__fcs_min_cfg(ns->port->fcs)) {
4188 bfa_fcs_lport_ns_boot_target_disc(ns->port);
4189 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_online);
4190 return;
4194 * If the port role is Initiator Mode issue NS query.
4195 * If it is Target Mode, skip this and go to online.
4197 if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns->port)) {
4198 bfa_sm_set_state(ns,
4199 bfa_fcs_lport_ns_sm_sending_gid_ft);
4200 bfa_fcs_lport_ns_send_gid_ft(ns, NULL);
4203 * kick off mgmt srvr state machine
4205 bfa_fcs_lport_ms_online(ns->port);
4206 break;
4208 case NSSM_EVENT_RSP_ERROR:
4210 * Start timer for a delayed retry
4212 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rff_id_retry);
4213 ns->port->stats.ns_retries++;
4214 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4215 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
4216 BFA_FCS_RETRY_TIMEOUT);
4217 break;
4219 case NSSM_EVENT_PORT_OFFLINE:
4220 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4221 bfa_fcxp_discard(ns->fcxp);
4222 break;
4224 default:
4225 bfa_sm_fault(ns->port->fcs, event);
4229 static void
4230 bfa_fcs_lport_ns_sm_rff_id_retry(struct bfa_fcs_lport_ns_s *ns,
4231 enum vport_ns_event event)
4233 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4234 bfa_trc(ns->port->fcs, event);
4236 switch (event) {
4237 case NSSM_EVENT_TIMEOUT:
4238 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rff_id);
4239 bfa_fcs_lport_ns_send_rff_id(ns, NULL);
4240 break;
4242 case NSSM_EVENT_PORT_OFFLINE:
4243 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4244 bfa_timer_stop(&ns->timer);
4245 break;
4247 default:
4248 bfa_sm_fault(ns->port->fcs, event);
4251 static void
4252 bfa_fcs_lport_ns_sm_sending_gid_ft(struct bfa_fcs_lport_ns_s *ns,
4253 enum vport_ns_event event)
4255 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4256 bfa_trc(ns->port->fcs, event);
4258 switch (event) {
4259 case NSSM_EVENT_GIDFT_SENT:
4260 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_gid_ft);
4261 break;
4263 case NSSM_EVENT_PORT_OFFLINE:
4264 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4265 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4266 &ns->fcxp_wqe);
4267 break;
4269 default:
4270 bfa_sm_fault(ns->port->fcs, event);
4274 static void
4275 bfa_fcs_lport_ns_sm_gid_ft(struct bfa_fcs_lport_ns_s *ns,
4276 enum vport_ns_event event)
4278 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4279 bfa_trc(ns->port->fcs, event);
4281 switch (event) {
4282 case NSSM_EVENT_RSP_OK:
4283 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_online);
4284 break;
4286 case NSSM_EVENT_RSP_ERROR:
4288 * TBD: for certain reject codes, we don't need to retry
4291 * Start timer for a delayed retry
4293 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_gid_ft_retry);
4294 ns->port->stats.ns_retries++;
4295 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4296 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
4297 BFA_FCS_RETRY_TIMEOUT);
4298 break;
4300 case NSSM_EVENT_PORT_OFFLINE:
4301 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4302 bfa_fcxp_discard(ns->fcxp);
4303 break;
4305 case NSSM_EVENT_NS_QUERY:
4306 break;
4308 default:
4309 bfa_sm_fault(ns->port->fcs, event);
4313 static void
4314 bfa_fcs_lport_ns_sm_gid_ft_retry(struct bfa_fcs_lport_ns_s *ns,
4315 enum vport_ns_event event)
4317 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4318 bfa_trc(ns->port->fcs, event);
4320 switch (event) {
4321 case NSSM_EVENT_TIMEOUT:
4322 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_gid_ft);
4323 bfa_fcs_lport_ns_send_gid_ft(ns, NULL);
4324 break;
4326 case NSSM_EVENT_PORT_OFFLINE:
4327 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4328 bfa_timer_stop(&ns->timer);
4329 break;
4331 default:
4332 bfa_sm_fault(ns->port->fcs, event);
4336 static void
4337 bfa_fcs_lport_ns_sm_online(struct bfa_fcs_lport_ns_s *ns,
4338 enum vport_ns_event event)
4340 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4341 bfa_trc(ns->port->fcs, event);
4343 switch (event) {
4344 case NSSM_EVENT_PORT_OFFLINE:
4345 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4346 break;
4348 case NSSM_EVENT_NS_QUERY:
4350 * If the port role is Initiator Mode issue NS query.
4351 * If it is Target Mode, skip this and go to online.
4353 if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns->port)) {
4354 bfa_sm_set_state(ns,
4355 bfa_fcs_lport_ns_sm_sending_gid_ft);
4356 bfa_fcs_lport_ns_send_gid_ft(ns, NULL);
4358 break;
4360 default:
4361 bfa_sm_fault(ns->port->fcs, event);
4368 * ns_pvt Nameserver local functions
4371 static void
4372 bfa_fcs_lport_ns_send_plogi(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4374 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4375 struct bfa_fcs_lport_s *port = ns->port;
4376 struct fchs_s fchs;
4377 int len;
4378 struct bfa_fcxp_s *fcxp;
4380 bfa_trc(port->fcs, port->pid);
4382 fcxp = fcxp_alloced ? fcxp_alloced :
4383 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4384 if (!fcxp) {
4385 port->stats.ns_plogi_alloc_wait++;
4386 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4387 bfa_fcs_lport_ns_send_plogi, ns, BFA_TRUE);
4388 return;
4390 ns->fcxp = fcxp;
4392 len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4393 bfa_hton3b(FC_NAME_SERVER),
4394 bfa_fcs_lport_get_fcid(port), 0,
4395 port->port_cfg.pwwn, port->port_cfg.nwwn,
4396 bfa_fcport_get_maxfrsize(port->fcs->bfa),
4397 bfa_fcport_get_rx_bbcredit(port->fcs->bfa));
4399 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4400 FC_CLASS_3, len, &fchs,
4401 bfa_fcs_lport_ns_plogi_response, (void *)ns,
4402 FC_MAX_PDUSZ, FC_ELS_TOV);
4403 port->stats.ns_plogi_sent++;
4405 bfa_sm_send_event(ns, NSSM_EVENT_PLOGI_SENT);
4408 static void
4409 bfa_fcs_lport_ns_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4410 void *cbarg, bfa_status_t req_status, u32 rsp_len,
4411 u32 resid_len, struct fchs_s *rsp_fchs)
4413 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4414 struct bfa_fcs_lport_s *port = ns->port;
4415 /* struct fc_logi_s *plogi_resp; */
4416 struct fc_els_cmd_s *els_cmd;
4417 struct fc_ls_rjt_s *ls_rjt;
4419 bfa_trc(port->fcs, req_status);
4420 bfa_trc(port->fcs, port->port_cfg.pwwn);
4423 * Sanity Checks
4425 if (req_status != BFA_STATUS_OK) {
4426 bfa_trc(port->fcs, req_status);
4427 port->stats.ns_plogi_rsp_err++;
4428 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4429 return;
4432 els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
4434 switch (els_cmd->els_code) {
4436 case FC_ELS_ACC:
4437 if (rsp_len < sizeof(struct fc_logi_s)) {
4438 bfa_trc(port->fcs, rsp_len);
4439 port->stats.ns_plogi_acc_err++;
4440 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4441 break;
4443 port->stats.ns_plogi_accepts++;
4444 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4445 break;
4447 case FC_ELS_LS_RJT:
4448 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
4450 bfa_trc(port->fcs, ls_rjt->reason_code);
4451 bfa_trc(port->fcs, ls_rjt->reason_code_expl);
4453 port->stats.ns_rejects++;
4455 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4456 break;
4458 default:
4459 port->stats.ns_plogi_unknown_rsp++;
4460 bfa_trc(port->fcs, els_cmd->els_code);
4461 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4466 * Register node name for port_id
4468 static void
4469 bfa_fcs_lport_ns_send_rnn_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4471 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4472 struct bfa_fcs_lport_s *port = ns->port;
4473 struct fchs_s fchs;
4474 int len;
4475 struct bfa_fcxp_s *fcxp;
4477 bfa_trc(port->fcs, port->port_cfg.pwwn);
4479 fcxp = fcxp_alloced ? fcxp_alloced :
4480 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4481 if (!fcxp) {
4482 port->stats.ns_rnnid_alloc_wait++;
4483 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4484 bfa_fcs_lport_ns_send_rnn_id, ns, BFA_TRUE);
4485 return;
4488 ns->fcxp = fcxp;
4490 len = fc_rnnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4491 bfa_fcs_lport_get_fcid(port),
4492 bfa_fcs_lport_get_fcid(port),
4493 bfa_fcs_lport_get_nwwn(port));
4495 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4496 FC_CLASS_3, len, &fchs,
4497 bfa_fcs_lport_ns_rnn_id_response, (void *)ns,
4498 FC_MAX_PDUSZ, FC_FCCT_TOV);
4500 port->stats.ns_rnnid_sent++;
4501 bfa_sm_send_event(ns, NSSM_EVENT_RNNID_SENT);
4504 static void
4505 bfa_fcs_lport_ns_rnn_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4506 void *cbarg, bfa_status_t req_status,
4507 u32 rsp_len, u32 resid_len,
4508 struct fchs_s *rsp_fchs)
4511 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4512 struct bfa_fcs_lport_s *port = ns->port;
4513 struct ct_hdr_s *cthdr = NULL;
4515 bfa_trc(port->fcs, port->port_cfg.pwwn);
4518 * Sanity Checks
4520 if (req_status != BFA_STATUS_OK) {
4521 bfa_trc(port->fcs, req_status);
4522 port->stats.ns_rnnid_rsp_err++;
4523 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4524 return;
4527 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4528 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4530 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4531 port->stats.ns_rnnid_accepts++;
4532 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4533 return;
4536 port->stats.ns_rnnid_rejects++;
4537 bfa_trc(port->fcs, cthdr->reason_code);
4538 bfa_trc(port->fcs, cthdr->exp_code);
4539 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4543 * Register the symbolic node name for a given node name.
4545 static void
4546 bfa_fcs_lport_ns_send_rsnn_nn(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4548 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4549 struct bfa_fcs_lport_s *port = ns->port;
4550 struct fchs_s fchs;
4551 int len;
4552 struct bfa_fcxp_s *fcxp;
4553 u8 *nsymbl;
4555 bfa_trc(port->fcs, port->port_cfg.pwwn);
4557 fcxp = fcxp_alloced ? fcxp_alloced :
4558 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4559 if (!fcxp) {
4560 port->stats.ns_rsnn_nn_alloc_wait++;
4561 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4562 bfa_fcs_lport_ns_send_rsnn_nn, ns, BFA_TRUE);
4563 return;
4565 ns->fcxp = fcxp;
4567 nsymbl = (u8 *) &(bfa_fcs_lport_get_nsym_name(
4568 bfa_fcs_get_base_port(port->fcs)));
4570 len = fc_rsnn_nn_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4571 bfa_fcs_lport_get_fcid(port),
4572 bfa_fcs_lport_get_nwwn(port), nsymbl);
4574 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4575 FC_CLASS_3, len, &fchs,
4576 bfa_fcs_lport_ns_rsnn_nn_response, (void *)ns,
4577 FC_MAX_PDUSZ, FC_FCCT_TOV);
4579 port->stats.ns_rsnn_nn_sent++;
4581 bfa_sm_send_event(ns, NSSM_EVENT_RSNN_NN_SENT);
4584 static void
4585 bfa_fcs_lport_ns_rsnn_nn_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4586 void *cbarg, bfa_status_t req_status,
4587 u32 rsp_len, u32 resid_len,
4588 struct fchs_s *rsp_fchs)
4590 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4591 struct bfa_fcs_lport_s *port = ns->port;
4592 struct ct_hdr_s *cthdr = NULL;
4594 bfa_trc(port->fcs, port->port_cfg.pwwn);
4597 * Sanity Checks
4599 if (req_status != BFA_STATUS_OK) {
4600 bfa_trc(port->fcs, req_status);
4601 port->stats.ns_rsnn_nn_rsp_err++;
4602 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4603 return;
4606 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4607 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4609 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4610 port->stats.ns_rsnn_nn_accepts++;
4611 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4612 return;
4615 port->stats.ns_rsnn_nn_rejects++;
4616 bfa_trc(port->fcs, cthdr->reason_code);
4617 bfa_trc(port->fcs, cthdr->exp_code);
4618 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4622 * Register the symbolic port name.
4624 static void
4625 bfa_fcs_lport_ns_send_rspn_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4627 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4628 struct bfa_fcs_lport_s *port = ns->port;
4629 struct fchs_s fchs;
4630 int len;
4631 struct bfa_fcxp_s *fcxp;
4632 u8 symbl[256];
4633 u8 *psymbl = &symbl[0];
4635 memset(symbl, 0, sizeof(symbl));
4637 bfa_trc(port->fcs, port->port_cfg.pwwn);
4639 fcxp = fcxp_alloced ? fcxp_alloced :
4640 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4641 if (!fcxp) {
4642 port->stats.ns_rspnid_alloc_wait++;
4643 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4644 bfa_fcs_lport_ns_send_rspn_id, ns, BFA_TRUE);
4645 return;
4647 ns->fcxp = fcxp;
4650 * for V-Port, form a Port Symbolic Name
4652 if (port->vport) {
4654 * For Vports, we append the vport's port symbolic name
4655 * to that of the base port.
4658 strncpy((char *)psymbl,
4659 (char *) &
4660 (bfa_fcs_lport_get_psym_name
4661 (bfa_fcs_get_base_port(port->fcs))),
4662 strlen((char *) &
4663 bfa_fcs_lport_get_psym_name(bfa_fcs_get_base_port
4664 (port->fcs))));
4666 /* Ensure we have a null terminating string. */
4667 ((char *)psymbl)[strlen((char *) &
4668 bfa_fcs_lport_get_psym_name(bfa_fcs_get_base_port
4669 (port->fcs)))] = 0;
4670 strncat((char *)psymbl,
4671 (char *) &(bfa_fcs_lport_get_psym_name(port)),
4672 strlen((char *) &bfa_fcs_lport_get_psym_name(port)));
4673 } else {
4674 psymbl = (u8 *) &(bfa_fcs_lport_get_psym_name(port));
4677 len = fc_rspnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4678 bfa_fcs_lport_get_fcid(port), 0, psymbl);
4680 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4681 FC_CLASS_3, len, &fchs,
4682 bfa_fcs_lport_ns_rspn_id_response, (void *)ns,
4683 FC_MAX_PDUSZ, FC_FCCT_TOV);
4685 port->stats.ns_rspnid_sent++;
4687 bfa_sm_send_event(ns, NSSM_EVENT_RSPNID_SENT);
4690 static void
4691 bfa_fcs_lport_ns_rspn_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4692 void *cbarg, bfa_status_t req_status,
4693 u32 rsp_len, u32 resid_len,
4694 struct fchs_s *rsp_fchs)
4696 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4697 struct bfa_fcs_lport_s *port = ns->port;
4698 struct ct_hdr_s *cthdr = NULL;
4700 bfa_trc(port->fcs, port->port_cfg.pwwn);
4703 * Sanity Checks
4705 if (req_status != BFA_STATUS_OK) {
4706 bfa_trc(port->fcs, req_status);
4707 port->stats.ns_rspnid_rsp_err++;
4708 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4709 return;
4712 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4713 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4715 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4716 port->stats.ns_rspnid_accepts++;
4717 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4718 return;
4721 port->stats.ns_rspnid_rejects++;
4722 bfa_trc(port->fcs, cthdr->reason_code);
4723 bfa_trc(port->fcs, cthdr->exp_code);
4724 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4728 * Register FC4-Types
4730 static void
4731 bfa_fcs_lport_ns_send_rft_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4733 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4734 struct bfa_fcs_lport_s *port = ns->port;
4735 struct fchs_s fchs;
4736 int len;
4737 struct bfa_fcxp_s *fcxp;
4739 bfa_trc(port->fcs, port->port_cfg.pwwn);
4741 fcxp = fcxp_alloced ? fcxp_alloced :
4742 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4743 if (!fcxp) {
4744 port->stats.ns_rftid_alloc_wait++;
4745 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4746 bfa_fcs_lport_ns_send_rft_id, ns, BFA_TRUE);
4747 return;
4749 ns->fcxp = fcxp;
4751 len = fc_rftid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4752 bfa_fcs_lport_get_fcid(port), 0, port->port_cfg.roles);
4754 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4755 FC_CLASS_3, len, &fchs,
4756 bfa_fcs_lport_ns_rft_id_response, (void *)ns,
4757 FC_MAX_PDUSZ, FC_FCCT_TOV);
4759 port->stats.ns_rftid_sent++;
4760 bfa_sm_send_event(ns, NSSM_EVENT_RFTID_SENT);
4763 static void
4764 bfa_fcs_lport_ns_rft_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4765 void *cbarg, bfa_status_t req_status,
4766 u32 rsp_len, u32 resid_len,
4767 struct fchs_s *rsp_fchs)
4769 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4770 struct bfa_fcs_lport_s *port = ns->port;
4771 struct ct_hdr_s *cthdr = NULL;
4773 bfa_trc(port->fcs, port->port_cfg.pwwn);
4776 * Sanity Checks
4778 if (req_status != BFA_STATUS_OK) {
4779 bfa_trc(port->fcs, req_status);
4780 port->stats.ns_rftid_rsp_err++;
4781 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4782 return;
4785 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4786 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4788 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4789 port->stats.ns_rftid_accepts++;
4790 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4791 return;
4794 port->stats.ns_rftid_rejects++;
4795 bfa_trc(port->fcs, cthdr->reason_code);
4796 bfa_trc(port->fcs, cthdr->exp_code);
4797 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4801 * Register FC4-Features : Should be done after RFT_ID
4803 static void
4804 bfa_fcs_lport_ns_send_rff_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4806 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4807 struct bfa_fcs_lport_s *port = ns->port;
4808 struct fchs_s fchs;
4809 int len;
4810 struct bfa_fcxp_s *fcxp;
4811 u8 fc4_ftrs = 0;
4813 bfa_trc(port->fcs, port->port_cfg.pwwn);
4815 fcxp = fcxp_alloced ? fcxp_alloced :
4816 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4817 if (!fcxp) {
4818 port->stats.ns_rffid_alloc_wait++;
4819 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4820 bfa_fcs_lport_ns_send_rff_id, ns, BFA_TRUE);
4821 return;
4823 ns->fcxp = fcxp;
4825 if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns->port))
4826 fc4_ftrs = FC_GS_FCP_FC4_FEATURE_INITIATOR;
4828 len = fc_rffid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4829 bfa_fcs_lport_get_fcid(port), 0,
4830 FC_TYPE_FCP, fc4_ftrs);
4832 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4833 FC_CLASS_3, len, &fchs,
4834 bfa_fcs_lport_ns_rff_id_response, (void *)ns,
4835 FC_MAX_PDUSZ, FC_FCCT_TOV);
4837 port->stats.ns_rffid_sent++;
4838 bfa_sm_send_event(ns, NSSM_EVENT_RFFID_SENT);
4841 static void
4842 bfa_fcs_lport_ns_rff_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4843 void *cbarg, bfa_status_t req_status,
4844 u32 rsp_len, u32 resid_len,
4845 struct fchs_s *rsp_fchs)
4847 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4848 struct bfa_fcs_lport_s *port = ns->port;
4849 struct ct_hdr_s *cthdr = NULL;
4851 bfa_trc(port->fcs, port->port_cfg.pwwn);
4854 * Sanity Checks
4856 if (req_status != BFA_STATUS_OK) {
4857 bfa_trc(port->fcs, req_status);
4858 port->stats.ns_rffid_rsp_err++;
4859 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4860 return;
4863 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4864 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4866 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4867 port->stats.ns_rffid_accepts++;
4868 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4869 return;
4872 port->stats.ns_rffid_rejects++;
4873 bfa_trc(port->fcs, cthdr->reason_code);
4874 bfa_trc(port->fcs, cthdr->exp_code);
4876 if (cthdr->reason_code == CT_RSN_NOT_SUPP) {
4877 /* if this command is not supported, we don't retry */
4878 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4879 } else
4880 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4883 * Query Fabric for FC4-Types Devices.
4885 * TBD : Need to use a local (FCS private) response buffer, since the response
4886 * can be larger than 2K.
4888 static void
4889 bfa_fcs_lport_ns_send_gid_ft(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4891 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4892 struct bfa_fcs_lport_s *port = ns->port;
4893 struct fchs_s fchs;
4894 int len;
4895 struct bfa_fcxp_s *fcxp;
4897 bfa_trc(port->fcs, port->pid);
4899 fcxp = fcxp_alloced ? fcxp_alloced :
4900 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4901 if (!fcxp) {
4902 port->stats.ns_gidft_alloc_wait++;
4903 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4904 bfa_fcs_lport_ns_send_gid_ft, ns, BFA_TRUE);
4905 return;
4907 ns->fcxp = fcxp;
4910 * This query is only initiated for FCP initiator mode.
4912 len = fc_gid_ft_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4913 ns->port->pid, FC_TYPE_FCP);
4915 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4916 FC_CLASS_3, len, &fchs,
4917 bfa_fcs_lport_ns_gid_ft_response, (void *)ns,
4918 bfa_fcxp_get_maxrsp(port->fcs->bfa), FC_FCCT_TOV);
4920 port->stats.ns_gidft_sent++;
4922 bfa_sm_send_event(ns, NSSM_EVENT_GIDFT_SENT);
4925 static void
4926 bfa_fcs_lport_ns_gid_ft_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4927 void *cbarg, bfa_status_t req_status,
4928 u32 rsp_len, u32 resid_len,
4929 struct fchs_s *rsp_fchs)
4931 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4932 struct bfa_fcs_lport_s *port = ns->port;
4933 struct ct_hdr_s *cthdr = NULL;
4934 u32 n_pids;
4936 bfa_trc(port->fcs, port->port_cfg.pwwn);
4939 * Sanity Checks
4941 if (req_status != BFA_STATUS_OK) {
4942 bfa_trc(port->fcs, req_status);
4943 port->stats.ns_gidft_rsp_err++;
4944 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4945 return;
4948 if (resid_len != 0) {
4950 * TBD : we will need to allocate a larger buffer & retry the
4951 * command
4953 bfa_trc(port->fcs, rsp_len);
4954 bfa_trc(port->fcs, resid_len);
4955 return;
4958 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4959 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4961 switch (cthdr->cmd_rsp_code) {
4963 case CT_RSP_ACCEPT:
4965 port->stats.ns_gidft_accepts++;
4966 n_pids = (fc_get_ctresp_pyld_len(rsp_len) / sizeof(u32));
4967 bfa_trc(port->fcs, n_pids);
4968 bfa_fcs_lport_ns_process_gidft_pids(port,
4969 (u32 *) (cthdr + 1),
4970 n_pids);
4971 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4972 break;
4974 case CT_RSP_REJECT:
4977 * Check the reason code & explanation.
4978 * There may not have been any FC4 devices in the fabric
4980 port->stats.ns_gidft_rejects++;
4981 bfa_trc(port->fcs, cthdr->reason_code);
4982 bfa_trc(port->fcs, cthdr->exp_code);
4984 if ((cthdr->reason_code == CT_RSN_UNABLE_TO_PERF)
4985 && (cthdr->exp_code == CT_NS_EXP_FT_NOT_REG)) {
4987 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4988 } else {
4990 * for all other errors, retry
4992 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4994 break;
4996 default:
4997 port->stats.ns_gidft_unknown_rsp++;
4998 bfa_trc(port->fcs, cthdr->cmd_rsp_code);
4999 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
5004 * This routine will be called by bfa_timer on timer timeouts.
5006 * param[in] port - pointer to bfa_fcs_lport_t.
5008 * return
5009 * void
5011 * Special Considerations:
5013 * note
5015 static void
5016 bfa_fcs_lport_ns_timeout(void *arg)
5018 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) arg;
5020 ns->port->stats.ns_timeouts++;
5021 bfa_sm_send_event(ns, NSSM_EVENT_TIMEOUT);
5025 * Process the PID list in GID_FT response
5027 static void
5028 bfa_fcs_lport_ns_process_gidft_pids(struct bfa_fcs_lport_s *port, u32 *pid_buf,
5029 u32 n_pids)
5031 struct fcgs_gidft_resp_s *gidft_entry;
5032 struct bfa_fcs_rport_s *rport;
5033 u32 ii;
5034 struct bfa_fcs_fabric_s *fabric = port->fabric;
5035 struct bfa_fcs_vport_s *vport;
5036 struct list_head *qe;
5037 u8 found = 0;
5039 for (ii = 0; ii < n_pids; ii++) {
5040 gidft_entry = (struct fcgs_gidft_resp_s *) &pid_buf[ii];
5042 if (gidft_entry->pid == port->pid)
5043 continue;
5046 * Ignore PID if it is of base port
5047 * (Avoid vports discovering base port as remote port)
5049 if (gidft_entry->pid == fabric->bport.pid)
5050 continue;
5053 * Ignore PID if it is of vport created on the same base port
5054 * (Avoid vport discovering every other vport created on the
5055 * same port as remote port)
5057 list_for_each(qe, &fabric->vport_q) {
5058 vport = (struct bfa_fcs_vport_s *) qe;
5059 if (vport->lport.pid == gidft_entry->pid)
5060 found = 1;
5063 if (found) {
5064 found = 0;
5065 continue;
5069 * Check if this rport already exists
5071 rport = bfa_fcs_lport_get_rport_by_pid(port, gidft_entry->pid);
5072 if (rport == NULL) {
5074 * this is a new device. create rport
5076 rport = bfa_fcs_rport_create(port, gidft_entry->pid);
5077 } else {
5079 * this rport already exists
5081 bfa_fcs_rport_scn(rport);
5084 bfa_trc(port->fcs, gidft_entry->pid);
5087 * if the last entry bit is set, bail out.
5089 if (gidft_entry->last)
5090 return;
5095 * fcs_ns_public FCS nameserver public interfaces
5099 * Functions called by port/fab.
5100 * These will send relevant Events to the ns state machine.
5102 void
5103 bfa_fcs_lport_ns_init(struct bfa_fcs_lport_s *port)
5105 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
5107 ns->port = port;
5108 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
5111 void
5112 bfa_fcs_lport_ns_offline(struct bfa_fcs_lport_s *port)
5114 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
5116 ns->port = port;
5117 bfa_sm_send_event(ns, NSSM_EVENT_PORT_OFFLINE);
5120 void
5121 bfa_fcs_lport_ns_online(struct bfa_fcs_lport_s *port)
5123 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
5125 ns->port = port;
5126 bfa_sm_send_event(ns, NSSM_EVENT_PORT_ONLINE);
5129 void
5130 bfa_fcs_lport_ns_query(struct bfa_fcs_lport_s *port)
5132 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
5134 bfa_trc(port->fcs, port->pid);
5135 if (bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_online))
5136 bfa_sm_send_event(ns, NSSM_EVENT_NS_QUERY);
5139 static void
5140 bfa_fcs_lport_ns_boot_target_disc(bfa_fcs_lport_t *port)
5143 struct bfa_fcs_rport_s *rport;
5144 u8 nwwns;
5145 wwn_t wwns[BFA_PREBOOT_BOOTLUN_MAX];
5146 int ii;
5148 bfa_iocfc_get_bootwwns(port->fcs->bfa, &nwwns, wwns);
5150 for (ii = 0 ; ii < nwwns; ++ii) {
5151 rport = bfa_fcs_rport_create_by_wwn(port, wwns[ii]);
5152 WARN_ON(!rport);
5156 void
5157 bfa_fcs_lport_ns_util_send_rspn_id(void *cbarg, struct bfa_fcxp_s *fcxp_alloced)
5159 struct bfa_fcs_lport_ns_s *ns = cbarg;
5160 struct bfa_fcs_lport_s *port = ns->port;
5161 struct fchs_s fchs;
5162 struct bfa_fcxp_s *fcxp;
5163 u8 symbl[256];
5164 u8 *psymbl = &symbl[0];
5165 int len;
5167 /* Avoid sending RSPN in the following states. */
5168 if (bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_offline) ||
5169 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi_sending) ||
5170 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi) ||
5171 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi_retry) ||
5172 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_rspn_id_retry))
5173 return;
5175 memset(symbl, 0, sizeof(symbl));
5176 bfa_trc(port->fcs, port->port_cfg.pwwn);
5178 fcxp = fcxp_alloced ? fcxp_alloced :
5179 bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
5180 if (!fcxp) {
5181 port->stats.ns_rspnid_alloc_wait++;
5182 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
5183 bfa_fcs_lport_ns_util_send_rspn_id, ns, BFA_FALSE);
5184 return;
5187 ns->fcxp = fcxp;
5189 if (port->vport) {
5191 * For Vports, we append the vport's port symbolic name
5192 * to that of the base port.
5194 strncpy((char *)psymbl, (char *)&(bfa_fcs_lport_get_psym_name
5195 (bfa_fcs_get_base_port(port->fcs))),
5196 strlen((char *)&bfa_fcs_lport_get_psym_name(
5197 bfa_fcs_get_base_port(port->fcs))));
5199 /* Ensure we have a null terminating string. */
5200 ((char *)psymbl)[strlen((char *)&bfa_fcs_lport_get_psym_name(
5201 bfa_fcs_get_base_port(port->fcs)))] = 0;
5203 strncat((char *)psymbl,
5204 (char *)&(bfa_fcs_lport_get_psym_name(port)),
5205 strlen((char *)&bfa_fcs_lport_get_psym_name(port)));
5208 len = fc_rspnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
5209 bfa_fcs_lport_get_fcid(port), 0, psymbl);
5211 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
5212 FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
5214 port->stats.ns_rspnid_sent++;
5218 * FCS SCN
5221 #define FC_QOS_RSCN_EVENT 0x0c
5222 #define FC_FABRIC_NAME_RSCN_EVENT 0x0d
5225 * forward declarations
5227 static void bfa_fcs_lport_scn_send_scr(void *scn_cbarg,
5228 struct bfa_fcxp_s *fcxp_alloced);
5229 static void bfa_fcs_lport_scn_scr_response(void *fcsarg,
5230 struct bfa_fcxp_s *fcxp,
5231 void *cbarg,
5232 bfa_status_t req_status,
5233 u32 rsp_len,
5234 u32 resid_len,
5235 struct fchs_s *rsp_fchs);
5236 static void bfa_fcs_lport_scn_send_ls_acc(struct bfa_fcs_lport_s *port,
5237 struct fchs_s *rx_fchs);
5238 static void bfa_fcs_lport_scn_timeout(void *arg);
5241 * fcs_scm_sm FCS SCN state machine
5245 * VPort SCN State Machine events
5247 enum port_scn_event {
5248 SCNSM_EVENT_PORT_ONLINE = 1,
5249 SCNSM_EVENT_PORT_OFFLINE = 2,
5250 SCNSM_EVENT_RSP_OK = 3,
5251 SCNSM_EVENT_RSP_ERROR = 4,
5252 SCNSM_EVENT_TIMEOUT = 5,
5253 SCNSM_EVENT_SCR_SENT = 6,
5256 static void bfa_fcs_lport_scn_sm_offline(struct bfa_fcs_lport_scn_s *scn,
5257 enum port_scn_event event);
5258 static void bfa_fcs_lport_scn_sm_sending_scr(
5259 struct bfa_fcs_lport_scn_s *scn,
5260 enum port_scn_event event);
5261 static void bfa_fcs_lport_scn_sm_scr(struct bfa_fcs_lport_scn_s *scn,
5262 enum port_scn_event event);
5263 static void bfa_fcs_lport_scn_sm_scr_retry(struct bfa_fcs_lport_scn_s *scn,
5264 enum port_scn_event event);
5265 static void bfa_fcs_lport_scn_sm_online(struct bfa_fcs_lport_scn_s *scn,
5266 enum port_scn_event event);
5269 * Starting state - awaiting link up.
5271 static void
5272 bfa_fcs_lport_scn_sm_offline(struct bfa_fcs_lport_scn_s *scn,
5273 enum port_scn_event event)
5275 switch (event) {
5276 case SCNSM_EVENT_PORT_ONLINE:
5277 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_sending_scr);
5278 bfa_fcs_lport_scn_send_scr(scn, NULL);
5279 break;
5281 case SCNSM_EVENT_PORT_OFFLINE:
5282 break;
5284 default:
5285 bfa_sm_fault(scn->port->fcs, event);
5289 static void
5290 bfa_fcs_lport_scn_sm_sending_scr(struct bfa_fcs_lport_scn_s *scn,
5291 enum port_scn_event event)
5293 switch (event) {
5294 case SCNSM_EVENT_SCR_SENT:
5295 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_scr);
5296 break;
5298 case SCNSM_EVENT_PORT_OFFLINE:
5299 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5300 bfa_fcxp_walloc_cancel(scn->port->fcs->bfa, &scn->fcxp_wqe);
5301 break;
5303 default:
5304 bfa_sm_fault(scn->port->fcs, event);
5308 static void
5309 bfa_fcs_lport_scn_sm_scr(struct bfa_fcs_lport_scn_s *scn,
5310 enum port_scn_event event)
5312 struct bfa_fcs_lport_s *port = scn->port;
5314 switch (event) {
5315 case SCNSM_EVENT_RSP_OK:
5316 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_online);
5317 break;
5319 case SCNSM_EVENT_RSP_ERROR:
5320 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_scr_retry);
5321 bfa_timer_start(port->fcs->bfa, &scn->timer,
5322 bfa_fcs_lport_scn_timeout, scn,
5323 BFA_FCS_RETRY_TIMEOUT);
5324 break;
5326 case SCNSM_EVENT_PORT_OFFLINE:
5327 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5328 bfa_fcxp_discard(scn->fcxp);
5329 break;
5331 default:
5332 bfa_sm_fault(port->fcs, event);
5336 static void
5337 bfa_fcs_lport_scn_sm_scr_retry(struct bfa_fcs_lport_scn_s *scn,
5338 enum port_scn_event event)
5340 switch (event) {
5341 case SCNSM_EVENT_TIMEOUT:
5342 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_sending_scr);
5343 bfa_fcs_lport_scn_send_scr(scn, NULL);
5344 break;
5346 case SCNSM_EVENT_PORT_OFFLINE:
5347 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5348 bfa_timer_stop(&scn->timer);
5349 break;
5351 default:
5352 bfa_sm_fault(scn->port->fcs, event);
5356 static void
5357 bfa_fcs_lport_scn_sm_online(struct bfa_fcs_lport_scn_s *scn,
5358 enum port_scn_event event)
5360 switch (event) {
5361 case SCNSM_EVENT_PORT_OFFLINE:
5362 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5363 break;
5365 default:
5366 bfa_sm_fault(scn->port->fcs, event);
5373 * fcs_scn_private FCS SCN private functions
5377 * This routine will be called to send a SCR command.
5379 static void
5380 bfa_fcs_lport_scn_send_scr(void *scn_cbarg, struct bfa_fcxp_s *fcxp_alloced)
5382 struct bfa_fcs_lport_scn_s *scn = scn_cbarg;
5383 struct bfa_fcs_lport_s *port = scn->port;
5384 struct fchs_s fchs;
5385 int len;
5386 struct bfa_fcxp_s *fcxp;
5388 bfa_trc(port->fcs, port->pid);
5389 bfa_trc(port->fcs, port->port_cfg.pwwn);
5391 fcxp = fcxp_alloced ? fcxp_alloced :
5392 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
5393 if (!fcxp) {
5394 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &scn->fcxp_wqe,
5395 bfa_fcs_lport_scn_send_scr, scn, BFA_TRUE);
5396 return;
5398 scn->fcxp = fcxp;
5400 /* Handle VU registrations for Base port only */
5401 if ((!port->vport) && bfa_ioc_get_fcmode(&port->fcs->bfa->ioc)) {
5402 len = fc_scr_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
5403 port->fabric->lps->brcd_switch,
5404 port->pid, 0);
5405 } else {
5406 len = fc_scr_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
5407 BFA_FALSE,
5408 port->pid, 0);
5411 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
5412 FC_CLASS_3, len, &fchs,
5413 bfa_fcs_lport_scn_scr_response,
5414 (void *)scn, FC_MAX_PDUSZ, FC_ELS_TOV);
5416 bfa_sm_send_event(scn, SCNSM_EVENT_SCR_SENT);
5419 static void
5420 bfa_fcs_lport_scn_scr_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
5421 void *cbarg, bfa_status_t req_status, u32 rsp_len,
5422 u32 resid_len, struct fchs_s *rsp_fchs)
5424 struct bfa_fcs_lport_scn_s *scn = (struct bfa_fcs_lport_scn_s *) cbarg;
5425 struct bfa_fcs_lport_s *port = scn->port;
5426 struct fc_els_cmd_s *els_cmd;
5427 struct fc_ls_rjt_s *ls_rjt;
5429 bfa_trc(port->fcs, port->port_cfg.pwwn);
5432 * Sanity Checks
5434 if (req_status != BFA_STATUS_OK) {
5435 bfa_trc(port->fcs, req_status);
5436 bfa_sm_send_event(scn, SCNSM_EVENT_RSP_ERROR);
5437 return;
5440 els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
5442 switch (els_cmd->els_code) {
5444 case FC_ELS_ACC:
5445 bfa_sm_send_event(scn, SCNSM_EVENT_RSP_OK);
5446 break;
5448 case FC_ELS_LS_RJT:
5450 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
5452 bfa_trc(port->fcs, ls_rjt->reason_code);
5453 bfa_trc(port->fcs, ls_rjt->reason_code_expl);
5455 bfa_sm_send_event(scn, SCNSM_EVENT_RSP_ERROR);
5456 break;
5458 default:
5459 bfa_sm_send_event(scn, SCNSM_EVENT_RSP_ERROR);
5464 * Send a LS Accept
5466 static void
5467 bfa_fcs_lport_scn_send_ls_acc(struct bfa_fcs_lport_s *port,
5468 struct fchs_s *rx_fchs)
5470 struct fchs_s fchs;
5471 struct bfa_fcxp_s *fcxp;
5472 struct bfa_rport_s *bfa_rport = NULL;
5473 int len;
5475 bfa_trc(port->fcs, rx_fchs->s_id);
5477 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
5478 if (!fcxp)
5479 return;
5481 len = fc_ls_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
5482 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
5483 rx_fchs->ox_id);
5485 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
5486 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
5487 FC_MAX_PDUSZ, 0);
5491 * This routine will be called by bfa_timer on timer timeouts.
5493 * param[in] vport - pointer to bfa_fcs_lport_t.
5494 * param[out] vport_status - pointer to return vport status in
5496 * return
5497 * void
5499 * Special Considerations:
5501 * note
5503 static void
5504 bfa_fcs_lport_scn_timeout(void *arg)
5506 struct bfa_fcs_lport_scn_s *scn = (struct bfa_fcs_lport_scn_s *) arg;
5508 bfa_sm_send_event(scn, SCNSM_EVENT_TIMEOUT);
5514 * fcs_scn_public FCS state change notification public interfaces
5518 * Functions called by port/fab
5520 void
5521 bfa_fcs_lport_scn_init(struct bfa_fcs_lport_s *port)
5523 struct bfa_fcs_lport_scn_s *scn = BFA_FCS_GET_SCN_FROM_PORT(port);
5525 scn->port = port;
5526 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5529 void
5530 bfa_fcs_lport_scn_offline(struct bfa_fcs_lport_s *port)
5532 struct bfa_fcs_lport_scn_s *scn = BFA_FCS_GET_SCN_FROM_PORT(port);
5534 scn->port = port;
5535 bfa_sm_send_event(scn, SCNSM_EVENT_PORT_OFFLINE);
5538 void
5539 bfa_fcs_lport_fab_scn_online(struct bfa_fcs_lport_s *port)
5541 struct bfa_fcs_lport_scn_s *scn = BFA_FCS_GET_SCN_FROM_PORT(port);
5543 scn->port = port;
5544 bfa_sm_send_event(scn, SCNSM_EVENT_PORT_ONLINE);
5547 static void
5548 bfa_fcs_lport_scn_portid_rscn(struct bfa_fcs_lport_s *port, u32 rpid)
5550 struct bfa_fcs_rport_s *rport;
5551 struct bfa_fcs_fabric_s *fabric = port->fabric;
5552 struct bfa_fcs_vport_s *vport;
5553 struct list_head *qe;
5555 bfa_trc(port->fcs, rpid);
5558 * Ignore PID if it is of base port or of vports created on the
5559 * same base port. It is to avoid vports discovering base port or
5560 * other vports created on same base port as remote port
5562 if (rpid == fabric->bport.pid)
5563 return;
5565 list_for_each(qe, &fabric->vport_q) {
5566 vport = (struct bfa_fcs_vport_s *) qe;
5567 if (vport->lport.pid == rpid)
5568 return;
5571 * If this is an unknown device, then it just came online.
5572 * Otherwise let rport handle the RSCN event.
5574 rport = bfa_fcs_lport_get_rport_by_pid(port, rpid);
5575 if (!rport)
5576 rport = bfa_fcs_lport_get_rport_by_old_pid(port, rpid);
5578 if (rport == NULL) {
5580 * If min cfg mode is enabled, we donot need to
5581 * discover any new rports.
5583 if (!__fcs_min_cfg(port->fcs))
5584 rport = bfa_fcs_rport_create(port, rpid);
5585 } else
5586 bfa_fcs_rport_scn(rport);
5590 * rscn format based PID comparison
5592 #define __fc_pid_match(__c0, __c1, __fmt) \
5593 (((__fmt) == FC_RSCN_FORMAT_FABRIC) || \
5594 (((__fmt) == FC_RSCN_FORMAT_DOMAIN) && \
5595 ((__c0)[0] == (__c1)[0])) || \
5596 (((__fmt) == FC_RSCN_FORMAT_AREA) && \
5597 ((__c0)[0] == (__c1)[0]) && \
5598 ((__c0)[1] == (__c1)[1])))
5600 static void
5601 bfa_fcs_lport_scn_multiport_rscn(struct bfa_fcs_lport_s *port,
5602 enum fc_rscn_format format,
5603 u32 rscn_pid)
5605 struct bfa_fcs_rport_s *rport;
5606 struct list_head *qe, *qe_next;
5607 u8 *c0, *c1;
5609 bfa_trc(port->fcs, format);
5610 bfa_trc(port->fcs, rscn_pid);
5612 c0 = (u8 *) &rscn_pid;
5614 list_for_each_safe(qe, qe_next, &port->rport_q) {
5615 rport = (struct bfa_fcs_rport_s *) qe;
5616 c1 = (u8 *) &rport->pid;
5617 if (__fc_pid_match(c0, c1, format))
5618 bfa_fcs_rport_scn(rport);
5623 void
5624 bfa_fcs_lport_scn_process_rscn(struct bfa_fcs_lport_s *port,
5625 struct fchs_s *fchs, u32 len)
5627 struct fc_rscn_pl_s *rscn = (struct fc_rscn_pl_s *) (fchs + 1);
5628 int num_entries;
5629 u32 rscn_pid;
5630 bfa_boolean_t nsquery = BFA_FALSE, found;
5631 int i = 0, j;
5633 num_entries =
5634 (be16_to_cpu(rscn->payldlen) -
5635 sizeof(u32)) / sizeof(rscn->event[0]);
5637 bfa_trc(port->fcs, num_entries);
5639 port->stats.num_rscn++;
5641 bfa_fcs_lport_scn_send_ls_acc(port, fchs);
5643 for (i = 0; i < num_entries; i++) {
5644 rscn_pid = rscn->event[i].portid;
5646 bfa_trc(port->fcs, rscn->event[i].format);
5647 bfa_trc(port->fcs, rscn_pid);
5649 /* check for duplicate entries in the list */
5650 found = BFA_FALSE;
5651 for (j = 0; j < i; j++) {
5652 if (rscn->event[j].portid == rscn_pid) {
5653 found = BFA_TRUE;
5654 break;
5658 /* if found in down the list, pid has been already processed */
5659 if (found) {
5660 bfa_trc(port->fcs, rscn_pid);
5661 continue;
5664 switch (rscn->event[i].format) {
5665 case FC_RSCN_FORMAT_PORTID:
5666 if (rscn->event[i].qualifier == FC_QOS_RSCN_EVENT) {
5668 * Ignore this event.
5669 * f/w would have processed it
5671 bfa_trc(port->fcs, rscn_pid);
5672 } else {
5673 port->stats.num_portid_rscn++;
5674 bfa_fcs_lport_scn_portid_rscn(port, rscn_pid);
5676 break;
5678 case FC_RSCN_FORMAT_FABRIC:
5679 if (rscn->event[i].qualifier ==
5680 FC_FABRIC_NAME_RSCN_EVENT) {
5681 bfa_fcs_lport_ms_fabric_rscn(port);
5682 break;
5684 /* !!!!!!!!! Fall Through !!!!!!!!!!!!! */
5686 case FC_RSCN_FORMAT_AREA:
5687 case FC_RSCN_FORMAT_DOMAIN:
5688 nsquery = BFA_TRUE;
5689 bfa_fcs_lport_scn_multiport_rscn(port,
5690 rscn->event[i].format,
5691 rscn_pid);
5692 break;
5695 default:
5696 WARN_ON(1);
5697 nsquery = BFA_TRUE;
5702 * If any of area, domain or fabric RSCN is received, do a fresh
5703 * discovery to find new devices.
5705 if (nsquery)
5706 bfa_fcs_lport_ns_query(port);
5710 * BFA FCS port
5713 * fcs_port_api BFA FCS port API
5715 struct bfa_fcs_lport_s *
5716 bfa_fcs_get_base_port(struct bfa_fcs_s *fcs)
5718 return &fcs->fabric.bport;
5721 wwn_t
5722 bfa_fcs_lport_get_rport(struct bfa_fcs_lport_s *port, wwn_t wwn, int index,
5723 int nrports, bfa_boolean_t bwwn)
5725 struct list_head *qh, *qe;
5726 struct bfa_fcs_rport_s *rport = NULL;
5727 int i;
5728 struct bfa_fcs_s *fcs;
5730 if (port == NULL || nrports == 0)
5731 return (wwn_t) 0;
5733 fcs = port->fcs;
5734 bfa_trc(fcs, (u32) nrports);
5736 i = 0;
5737 qh = &port->rport_q;
5738 qe = bfa_q_first(qh);
5740 while ((qe != qh) && (i < nrports)) {
5741 rport = (struct bfa_fcs_rport_s *) qe;
5742 if (bfa_ntoh3b(rport->pid) > 0xFFF000) {
5743 qe = bfa_q_next(qe);
5744 bfa_trc(fcs, (u32) rport->pwwn);
5745 bfa_trc(fcs, rport->pid);
5746 bfa_trc(fcs, i);
5747 continue;
5750 if (bwwn) {
5751 if (!memcmp(&wwn, &rport->pwwn, 8))
5752 break;
5753 } else {
5754 if (i == index)
5755 break;
5758 i++;
5759 qe = bfa_q_next(qe);
5762 bfa_trc(fcs, i);
5763 if (rport)
5764 return rport->pwwn;
5765 else
5766 return (wwn_t) 0;
5769 void
5770 bfa_fcs_lport_get_rport_quals(struct bfa_fcs_lport_s *port,
5771 struct bfa_rport_qualifier_s rports[], int *nrports)
5773 struct list_head *qh, *qe;
5774 struct bfa_fcs_rport_s *rport = NULL;
5775 int i;
5776 struct bfa_fcs_s *fcs;
5778 if (port == NULL || rports == NULL || *nrports == 0)
5779 return;
5781 fcs = port->fcs;
5782 bfa_trc(fcs, (u32) *nrports);
5784 i = 0;
5785 qh = &port->rport_q;
5786 qe = bfa_q_first(qh);
5788 while ((qe != qh) && (i < *nrports)) {
5789 rport = (struct bfa_fcs_rport_s *) qe;
5790 if (bfa_ntoh3b(rport->pid) > 0xFFF000) {
5791 qe = bfa_q_next(qe);
5792 bfa_trc(fcs, (u32) rport->pwwn);
5793 bfa_trc(fcs, rport->pid);
5794 bfa_trc(fcs, i);
5795 continue;
5798 if (!rport->pwwn && !rport->pid) {
5799 qe = bfa_q_next(qe);
5800 continue;
5803 rports[i].pwwn = rport->pwwn;
5804 rports[i].pid = rport->pid;
5806 i++;
5807 qe = bfa_q_next(qe);
5810 bfa_trc(fcs, i);
5811 *nrports = i;
5815 * Iterate's through all the rport's in the given port to
5816 * determine the maximum operating speed.
5818 * !!!! To be used in TRL Functionality only !!!!
5820 bfa_port_speed_t
5821 bfa_fcs_lport_get_rport_max_speed(bfa_fcs_lport_t *port)
5823 struct list_head *qh, *qe;
5824 struct bfa_fcs_rport_s *rport = NULL;
5825 struct bfa_fcs_s *fcs;
5826 bfa_port_speed_t max_speed = 0;
5827 struct bfa_port_attr_s port_attr;
5828 bfa_port_speed_t port_speed, rport_speed;
5829 bfa_boolean_t trl_enabled = bfa_fcport_is_ratelim(port->fcs->bfa);
5832 if (port == NULL)
5833 return 0;
5835 fcs = port->fcs;
5837 /* Get Physical port's current speed */
5838 bfa_fcport_get_attr(port->fcs->bfa, &port_attr);
5839 port_speed = port_attr.speed;
5840 bfa_trc(fcs, port_speed);
5842 qh = &port->rport_q;
5843 qe = bfa_q_first(qh);
5845 while (qe != qh) {
5846 rport = (struct bfa_fcs_rport_s *) qe;
5847 if ((bfa_ntoh3b(rport->pid) > 0xFFF000) ||
5848 (bfa_fcs_rport_get_state(rport) == BFA_RPORT_OFFLINE) ||
5849 (rport->scsi_function != BFA_RPORT_TARGET)) {
5850 qe = bfa_q_next(qe);
5851 continue;
5854 rport_speed = rport->rpf.rpsc_speed;
5855 if ((trl_enabled) && (rport_speed ==
5856 BFA_PORT_SPEED_UNKNOWN)) {
5857 /* Use default ratelim speed setting */
5858 rport_speed =
5859 bfa_fcport_get_ratelim_speed(port->fcs->bfa);
5862 if (rport_speed > max_speed)
5863 max_speed = rport_speed;
5865 qe = bfa_q_next(qe);
5868 if (max_speed > port_speed)
5869 max_speed = port_speed;
5871 bfa_trc(fcs, max_speed);
5872 return max_speed;
5875 struct bfa_fcs_lport_s *
5876 bfa_fcs_lookup_port(struct bfa_fcs_s *fcs, u16 vf_id, wwn_t lpwwn)
5878 struct bfa_fcs_vport_s *vport;
5879 bfa_fcs_vf_t *vf;
5881 WARN_ON(fcs == NULL);
5883 vf = bfa_fcs_vf_lookup(fcs, vf_id);
5884 if (vf == NULL) {
5885 bfa_trc(fcs, vf_id);
5886 return NULL;
5889 if (!lpwwn || (vf->bport.port_cfg.pwwn == lpwwn))
5890 return &vf->bport;
5892 vport = bfa_fcs_fabric_vport_lookup(vf, lpwwn);
5893 if (vport)
5894 return &vport->lport;
5896 return NULL;
5900 * API corresponding to NPIV_VPORT_GETINFO.
5902 void
5903 bfa_fcs_lport_get_info(struct bfa_fcs_lport_s *port,
5904 struct bfa_lport_info_s *port_info)
5907 bfa_trc(port->fcs, port->fabric->fabric_name);
5909 if (port->vport == NULL) {
5911 * This is a Physical port
5913 port_info->port_type = BFA_LPORT_TYPE_PHYSICAL;
5916 * @todo : need to fix the state & reason
5918 port_info->port_state = 0;
5919 port_info->offline_reason = 0;
5921 port_info->port_wwn = bfa_fcs_lport_get_pwwn(port);
5922 port_info->node_wwn = bfa_fcs_lport_get_nwwn(port);
5924 port_info->max_vports_supp =
5925 bfa_lps_get_max_vport(port->fcs->bfa);
5926 port_info->num_vports_inuse =
5927 port->fabric->num_vports;
5928 port_info->max_rports_supp = BFA_FCS_MAX_RPORTS_SUPP;
5929 port_info->num_rports_inuse = port->num_rports;
5930 } else {
5932 * This is a virtual port
5934 port_info->port_type = BFA_LPORT_TYPE_VIRTUAL;
5937 * @todo : need to fix the state & reason
5939 port_info->port_state = 0;
5940 port_info->offline_reason = 0;
5942 port_info->port_wwn = bfa_fcs_lport_get_pwwn(port);
5943 port_info->node_wwn = bfa_fcs_lport_get_nwwn(port);
5947 void
5948 bfa_fcs_lport_get_stats(struct bfa_fcs_lport_s *fcs_port,
5949 struct bfa_lport_stats_s *port_stats)
5951 *port_stats = fcs_port->stats;
5954 void
5955 bfa_fcs_lport_clear_stats(struct bfa_fcs_lport_s *fcs_port)
5957 memset(&fcs_port->stats, 0, sizeof(struct bfa_lport_stats_s));
5961 * Let new loop map create missing rports
5963 void
5964 bfa_fcs_lport_lip_scn_online(struct bfa_fcs_lport_s *port)
5966 bfa_fcs_lport_loop_online(port);
5970 * FCS virtual port state machine
5973 #define __vport_fcs(__vp) ((__vp)->lport.fcs)
5974 #define __vport_pwwn(__vp) ((__vp)->lport.port_cfg.pwwn)
5975 #define __vport_nwwn(__vp) ((__vp)->lport.port_cfg.nwwn)
5976 #define __vport_bfa(__vp) ((__vp)->lport.fcs->bfa)
5977 #define __vport_fcid(__vp) ((__vp)->lport.pid)
5978 #define __vport_fabric(__vp) ((__vp)->lport.fabric)
5979 #define __vport_vfid(__vp) ((__vp)->lport.fabric->vf_id)
5981 #define BFA_FCS_VPORT_MAX_RETRIES 5
5983 * Forward declarations
5985 static void bfa_fcs_vport_do_fdisc(struct bfa_fcs_vport_s *vport);
5986 static void bfa_fcs_vport_timeout(void *vport_arg);
5987 static void bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s *vport);
5988 static void bfa_fcs_vport_free(struct bfa_fcs_vport_s *vport);
5991 * fcs_vport_sm FCS virtual port state machine
5995 * VPort State Machine events
5997 enum bfa_fcs_vport_event {
5998 BFA_FCS_VPORT_SM_CREATE = 1, /* vport create event */
5999 BFA_FCS_VPORT_SM_DELETE = 2, /* vport delete event */
6000 BFA_FCS_VPORT_SM_START = 3, /* vport start request */
6001 BFA_FCS_VPORT_SM_STOP = 4, /* stop: unsupported */
6002 BFA_FCS_VPORT_SM_ONLINE = 5, /* fabric online */
6003 BFA_FCS_VPORT_SM_OFFLINE = 6, /* fabric offline event */
6004 BFA_FCS_VPORT_SM_FRMSENT = 7, /* fdisc/logo sent events */
6005 BFA_FCS_VPORT_SM_RSP_OK = 8, /* good response */
6006 BFA_FCS_VPORT_SM_RSP_ERROR = 9, /* error/bad response */
6007 BFA_FCS_VPORT_SM_TIMEOUT = 10, /* delay timer event */
6008 BFA_FCS_VPORT_SM_DELCOMP = 11, /* lport delete completion */
6009 BFA_FCS_VPORT_SM_RSP_DUP_WWN = 12, /* Dup wnn error*/
6010 BFA_FCS_VPORT_SM_RSP_FAILED = 13, /* non-retryable failure */
6011 BFA_FCS_VPORT_SM_STOPCOMP = 14, /* vport delete completion */
6012 BFA_FCS_VPORT_SM_FABRIC_MAX = 15, /* max vports on fabric */
6015 static void bfa_fcs_vport_sm_uninit(struct bfa_fcs_vport_s *vport,
6016 enum bfa_fcs_vport_event event);
6017 static void bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s *vport,
6018 enum bfa_fcs_vport_event event);
6019 static void bfa_fcs_vport_sm_offline(struct bfa_fcs_vport_s *vport,
6020 enum bfa_fcs_vport_event event);
6021 static void bfa_fcs_vport_sm_fdisc(struct bfa_fcs_vport_s *vport,
6022 enum bfa_fcs_vport_event event);
6023 static void bfa_fcs_vport_sm_fdisc_retry(struct bfa_fcs_vport_s *vport,
6024 enum bfa_fcs_vport_event event);
6025 static void bfa_fcs_vport_sm_fdisc_rsp_wait(struct bfa_fcs_vport_s *vport,
6026 enum bfa_fcs_vport_event event);
6027 static void bfa_fcs_vport_sm_online(struct bfa_fcs_vport_s *vport,
6028 enum bfa_fcs_vport_event event);
6029 static void bfa_fcs_vport_sm_deleting(struct bfa_fcs_vport_s *vport,
6030 enum bfa_fcs_vport_event event);
6031 static void bfa_fcs_vport_sm_cleanup(struct bfa_fcs_vport_s *vport,
6032 enum bfa_fcs_vport_event event);
6033 static void bfa_fcs_vport_sm_logo(struct bfa_fcs_vport_s *vport,
6034 enum bfa_fcs_vport_event event);
6035 static void bfa_fcs_vport_sm_error(struct bfa_fcs_vport_s *vport,
6036 enum bfa_fcs_vport_event event);
6037 static void bfa_fcs_vport_sm_stopping(struct bfa_fcs_vport_s *vport,
6038 enum bfa_fcs_vport_event event);
6039 static void bfa_fcs_vport_sm_logo_for_stop(struct bfa_fcs_vport_s *vport,
6040 enum bfa_fcs_vport_event event);
6042 static struct bfa_sm_table_s vport_sm_table[] = {
6043 {BFA_SM(bfa_fcs_vport_sm_uninit), BFA_FCS_VPORT_UNINIT},
6044 {BFA_SM(bfa_fcs_vport_sm_created), BFA_FCS_VPORT_CREATED},
6045 {BFA_SM(bfa_fcs_vport_sm_offline), BFA_FCS_VPORT_OFFLINE},
6046 {BFA_SM(bfa_fcs_vport_sm_fdisc), BFA_FCS_VPORT_FDISC},
6047 {BFA_SM(bfa_fcs_vport_sm_fdisc_retry), BFA_FCS_VPORT_FDISC_RETRY},
6048 {BFA_SM(bfa_fcs_vport_sm_fdisc_rsp_wait), BFA_FCS_VPORT_FDISC_RSP_WAIT},
6049 {BFA_SM(bfa_fcs_vport_sm_online), BFA_FCS_VPORT_ONLINE},
6050 {BFA_SM(bfa_fcs_vport_sm_deleting), BFA_FCS_VPORT_DELETING},
6051 {BFA_SM(bfa_fcs_vport_sm_cleanup), BFA_FCS_VPORT_CLEANUP},
6052 {BFA_SM(bfa_fcs_vport_sm_logo), BFA_FCS_VPORT_LOGO},
6053 {BFA_SM(bfa_fcs_vport_sm_error), BFA_FCS_VPORT_ERROR}
6057 * Beginning state.
6059 static void
6060 bfa_fcs_vport_sm_uninit(struct bfa_fcs_vport_s *vport,
6061 enum bfa_fcs_vport_event event)
6063 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6064 bfa_trc(__vport_fcs(vport), event);
6066 switch (event) {
6067 case BFA_FCS_VPORT_SM_CREATE:
6068 bfa_sm_set_state(vport, bfa_fcs_vport_sm_created);
6069 bfa_fcs_fabric_addvport(__vport_fabric(vport), vport);
6070 break;
6072 default:
6073 bfa_sm_fault(__vport_fcs(vport), event);
6078 * Created state - a start event is required to start up the state machine.
6080 static void
6081 bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s *vport,
6082 enum bfa_fcs_vport_event event)
6084 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6085 bfa_trc(__vport_fcs(vport), event);
6087 switch (event) {
6088 case BFA_FCS_VPORT_SM_START:
6089 if (bfa_sm_cmp_state(__vport_fabric(vport),
6090 bfa_fcs_fabric_sm_online)
6091 && bfa_fcs_fabric_npiv_capable(__vport_fabric(vport))) {
6092 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
6093 bfa_fcs_vport_do_fdisc(vport);
6094 } else {
6096 * Fabric is offline or not NPIV capable, stay in
6097 * offline state.
6099 vport->vport_stats.fab_no_npiv++;
6100 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
6102 break;
6104 case BFA_FCS_VPORT_SM_DELETE:
6105 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6106 bfa_fcs_lport_delete(&vport->lport);
6107 break;
6109 case BFA_FCS_VPORT_SM_ONLINE:
6110 case BFA_FCS_VPORT_SM_OFFLINE:
6112 * Ignore ONLINE/OFFLINE events from fabric
6113 * till vport is started.
6115 break;
6117 default:
6118 bfa_sm_fault(__vport_fcs(vport), event);
6123 * Offline state - awaiting ONLINE event from fabric SM.
6125 static void
6126 bfa_fcs_vport_sm_offline(struct bfa_fcs_vport_s *vport,
6127 enum bfa_fcs_vport_event event)
6129 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6130 bfa_trc(__vport_fcs(vport), event);
6132 switch (event) {
6133 case BFA_FCS_VPORT_SM_DELETE:
6134 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6135 bfa_fcs_lport_delete(&vport->lport);
6136 break;
6138 case BFA_FCS_VPORT_SM_ONLINE:
6139 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
6140 vport->fdisc_retries = 0;
6141 bfa_fcs_vport_do_fdisc(vport);
6142 break;
6144 case BFA_FCS_VPORT_SM_STOP:
6145 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6146 bfa_sm_send_event(&vport->lport, BFA_FCS_PORT_SM_STOP);
6147 break;
6149 case BFA_FCS_VPORT_SM_OFFLINE:
6151 * This can happen if the vport couldn't be initialzied
6152 * due the fact that the npiv was not enabled on the switch.
6153 * In that case we will put the vport in offline state.
6154 * However, the link can go down and cause the this event to
6155 * be sent when we are already offline. Ignore it.
6157 break;
6159 default:
6160 bfa_sm_fault(__vport_fcs(vport), event);
6166 * FDISC is sent and awaiting reply from fabric.
6168 static void
6169 bfa_fcs_vport_sm_fdisc(struct bfa_fcs_vport_s *vport,
6170 enum bfa_fcs_vport_event event)
6172 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6173 bfa_trc(__vport_fcs(vport), event);
6175 switch (event) {
6176 case BFA_FCS_VPORT_SM_DELETE:
6177 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc_rsp_wait);
6178 break;
6180 case BFA_FCS_VPORT_SM_OFFLINE:
6181 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
6182 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
6183 break;
6185 case BFA_FCS_VPORT_SM_RSP_OK:
6186 bfa_sm_set_state(vport, bfa_fcs_vport_sm_online);
6187 bfa_fcs_lport_online(&vport->lport);
6188 break;
6190 case BFA_FCS_VPORT_SM_RSP_ERROR:
6191 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc_retry);
6192 bfa_timer_start(__vport_bfa(vport), &vport->timer,
6193 bfa_fcs_vport_timeout, vport,
6194 BFA_FCS_RETRY_TIMEOUT);
6195 break;
6197 case BFA_FCS_VPORT_SM_RSP_FAILED:
6198 case BFA_FCS_VPORT_SM_FABRIC_MAX:
6199 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
6200 break;
6202 case BFA_FCS_VPORT_SM_RSP_DUP_WWN:
6203 bfa_sm_set_state(vport, bfa_fcs_vport_sm_error);
6204 break;
6206 default:
6207 bfa_sm_fault(__vport_fcs(vport), event);
6212 * FDISC attempt failed - a timer is active to retry FDISC.
6214 static void
6215 bfa_fcs_vport_sm_fdisc_retry(struct bfa_fcs_vport_s *vport,
6216 enum bfa_fcs_vport_event event)
6218 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6219 bfa_trc(__vport_fcs(vport), event);
6221 switch (event) {
6222 case BFA_FCS_VPORT_SM_DELETE:
6223 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6224 bfa_timer_stop(&vport->timer);
6225 bfa_fcs_lport_delete(&vport->lport);
6226 break;
6228 case BFA_FCS_VPORT_SM_OFFLINE:
6229 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
6230 bfa_timer_stop(&vport->timer);
6231 break;
6233 case BFA_FCS_VPORT_SM_TIMEOUT:
6234 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
6235 vport->vport_stats.fdisc_retries++;
6236 vport->fdisc_retries++;
6237 bfa_fcs_vport_do_fdisc(vport);
6238 break;
6240 default:
6241 bfa_sm_fault(__vport_fcs(vport), event);
6246 * FDISC is in progress and we got a vport delete request -
6247 * this is a wait state while we wait for fdisc response and
6248 * we will transition to the appropriate state - on rsp status.
6250 static void
6251 bfa_fcs_vport_sm_fdisc_rsp_wait(struct bfa_fcs_vport_s *vport,
6252 enum bfa_fcs_vport_event event)
6254 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6255 bfa_trc(__vport_fcs(vport), event);
6257 switch (event) {
6258 case BFA_FCS_VPORT_SM_RSP_OK:
6259 bfa_sm_set_state(vport, bfa_fcs_vport_sm_deleting);
6260 bfa_fcs_lport_delete(&vport->lport);
6261 break;
6263 case BFA_FCS_VPORT_SM_DELETE:
6264 break;
6266 case BFA_FCS_VPORT_SM_OFFLINE:
6267 case BFA_FCS_VPORT_SM_RSP_ERROR:
6268 case BFA_FCS_VPORT_SM_RSP_FAILED:
6269 case BFA_FCS_VPORT_SM_FABRIC_MAX:
6270 case BFA_FCS_VPORT_SM_RSP_DUP_WWN:
6271 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6272 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
6273 bfa_fcs_lport_delete(&vport->lport);
6274 break;
6276 default:
6277 bfa_sm_fault(__vport_fcs(vport), event);
6282 * Vport is online (FDISC is complete).
6284 static void
6285 bfa_fcs_vport_sm_online(struct bfa_fcs_vport_s *vport,
6286 enum bfa_fcs_vport_event event)
6288 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6289 bfa_trc(__vport_fcs(vport), event);
6291 switch (event) {
6292 case BFA_FCS_VPORT_SM_DELETE:
6293 bfa_sm_set_state(vport, bfa_fcs_vport_sm_deleting);
6294 bfa_fcs_lport_delete(&vport->lport);
6295 break;
6297 case BFA_FCS_VPORT_SM_STOP:
6298 bfa_sm_set_state(vport, bfa_fcs_vport_sm_stopping);
6299 bfa_sm_send_event(&vport->lport, BFA_FCS_PORT_SM_STOP);
6300 break;
6302 case BFA_FCS_VPORT_SM_OFFLINE:
6303 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
6304 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
6305 bfa_fcs_lport_offline(&vport->lport);
6306 break;
6308 default:
6309 bfa_sm_fault(__vport_fcs(vport), event);
6314 * Vport is being stopped - awaiting lport stop completion to send
6315 * LOGO to fabric.
6317 static void
6318 bfa_fcs_vport_sm_stopping(struct bfa_fcs_vport_s *vport,
6319 enum bfa_fcs_vport_event event)
6321 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6322 bfa_trc(__vport_fcs(vport), event);
6324 switch (event) {
6325 case BFA_FCS_VPORT_SM_STOPCOMP:
6326 bfa_sm_set_state(vport, bfa_fcs_vport_sm_logo_for_stop);
6327 bfa_fcs_vport_do_logo(vport);
6328 break;
6330 case BFA_FCS_VPORT_SM_OFFLINE:
6331 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6332 break;
6334 default:
6335 bfa_sm_fault(__vport_fcs(vport), event);
6340 * Vport is being deleted - awaiting lport delete completion to send
6341 * LOGO to fabric.
6343 static void
6344 bfa_fcs_vport_sm_deleting(struct bfa_fcs_vport_s *vport,
6345 enum bfa_fcs_vport_event event)
6347 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6348 bfa_trc(__vport_fcs(vport), event);
6350 switch (event) {
6351 case BFA_FCS_VPORT_SM_DELETE:
6352 break;
6354 case BFA_FCS_VPORT_SM_DELCOMP:
6355 bfa_sm_set_state(vport, bfa_fcs_vport_sm_logo);
6356 bfa_fcs_vport_do_logo(vport);
6357 break;
6359 case BFA_FCS_VPORT_SM_OFFLINE:
6360 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6361 break;
6363 default:
6364 bfa_sm_fault(__vport_fcs(vport), event);
6369 * Error State.
6370 * This state will be set when the Vport Creation fails due
6371 * to errors like Dup WWN. In this state only operation allowed
6372 * is a Vport Delete.
6374 static void
6375 bfa_fcs_vport_sm_error(struct bfa_fcs_vport_s *vport,
6376 enum bfa_fcs_vport_event event)
6378 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6379 bfa_trc(__vport_fcs(vport), event);
6381 switch (event) {
6382 case BFA_FCS_VPORT_SM_DELETE:
6383 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6384 bfa_fcs_lport_delete(&vport->lport);
6385 break;
6387 default:
6388 bfa_trc(__vport_fcs(vport), event);
6393 * Lport cleanup is in progress since vport is being deleted. Fabric is
6394 * offline, so no LOGO is needed to complete vport deletion.
6396 static void
6397 bfa_fcs_vport_sm_cleanup(struct bfa_fcs_vport_s *vport,
6398 enum bfa_fcs_vport_event event)
6400 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6401 bfa_trc(__vport_fcs(vport), event);
6403 switch (event) {
6404 case BFA_FCS_VPORT_SM_DELCOMP:
6405 bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
6406 bfa_fcs_vport_free(vport);
6407 break;
6409 case BFA_FCS_VPORT_SM_STOPCOMP:
6410 bfa_sm_set_state(vport, bfa_fcs_vport_sm_created);
6411 break;
6413 case BFA_FCS_VPORT_SM_DELETE:
6414 break;
6416 default:
6417 bfa_sm_fault(__vport_fcs(vport), event);
6422 * LOGO is sent to fabric. Vport stop is in progress. Lport stop cleanup
6423 * is done.
6425 static void
6426 bfa_fcs_vport_sm_logo_for_stop(struct bfa_fcs_vport_s *vport,
6427 enum bfa_fcs_vport_event event)
6429 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6430 bfa_trc(__vport_fcs(vport), event);
6432 switch (event) {
6433 case BFA_FCS_VPORT_SM_OFFLINE:
6434 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
6436 * !!! fall through !!!
6439 case BFA_FCS_VPORT_SM_RSP_OK:
6440 case BFA_FCS_VPORT_SM_RSP_ERROR:
6441 bfa_sm_set_state(vport, bfa_fcs_vport_sm_created);
6442 break;
6444 default:
6445 bfa_sm_fault(__vport_fcs(vport), event);
6450 * LOGO is sent to fabric. Vport delete is in progress. Lport delete cleanup
6451 * is done.
6453 static void
6454 bfa_fcs_vport_sm_logo(struct bfa_fcs_vport_s *vport,
6455 enum bfa_fcs_vport_event event)
6457 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6458 bfa_trc(__vport_fcs(vport), event);
6460 switch (event) {
6461 case BFA_FCS_VPORT_SM_OFFLINE:
6462 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
6464 * !!! fall through !!!
6467 case BFA_FCS_VPORT_SM_RSP_OK:
6468 case BFA_FCS_VPORT_SM_RSP_ERROR:
6469 bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
6470 bfa_fcs_vport_free(vport);
6471 break;
6473 case BFA_FCS_VPORT_SM_DELETE:
6474 break;
6476 default:
6477 bfa_sm_fault(__vport_fcs(vport), event);
6484 * fcs_vport_private FCS virtual port private functions
6487 * Send AEN notification
6489 static void
6490 bfa_fcs_vport_aen_post(struct bfa_fcs_lport_s *port,
6491 enum bfa_lport_aen_event event)
6493 struct bfad_s *bfad = (struct bfad_s *)port->fabric->fcs->bfad;
6494 struct bfa_aen_entry_s *aen_entry;
6496 bfad_get_aen_entry(bfad, aen_entry);
6497 if (!aen_entry)
6498 return;
6500 aen_entry->aen_data.lport.vf_id = port->fabric->vf_id;
6501 aen_entry->aen_data.lport.roles = port->port_cfg.roles;
6502 aen_entry->aen_data.lport.ppwwn = bfa_fcs_lport_get_pwwn(
6503 bfa_fcs_get_base_port(port->fcs));
6504 aen_entry->aen_data.lport.lpwwn = bfa_fcs_lport_get_pwwn(port);
6506 /* Send the AEN notification */
6507 bfad_im_post_vendor_event(aen_entry, bfad, ++port->fcs->fcs_aen_seq,
6508 BFA_AEN_CAT_LPORT, event);
6512 * This routine will be called to send a FDISC command.
6514 static void
6515 bfa_fcs_vport_do_fdisc(struct bfa_fcs_vport_s *vport)
6517 bfa_lps_fdisc(vport->lps, vport,
6518 bfa_fcport_get_maxfrsize(__vport_bfa(vport)),
6519 __vport_pwwn(vport), __vport_nwwn(vport));
6520 vport->vport_stats.fdisc_sent++;
6523 static void
6524 bfa_fcs_vport_fdisc_rejected(struct bfa_fcs_vport_s *vport)
6526 u8 lsrjt_rsn = vport->lps->lsrjt_rsn;
6527 u8 lsrjt_expl = vport->lps->lsrjt_expl;
6529 bfa_trc(__vport_fcs(vport), lsrjt_rsn);
6530 bfa_trc(__vport_fcs(vport), lsrjt_expl);
6532 /* For certain reason codes, we don't want to retry. */
6533 switch (vport->lps->lsrjt_expl) {
6534 case FC_LS_RJT_EXP_INV_PORT_NAME: /* by brocade */
6535 case FC_LS_RJT_EXP_INVALID_NPORT_ID: /* by Cisco */
6536 if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
6537 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6538 else {
6539 bfa_fcs_vport_aen_post(&vport->lport,
6540 BFA_LPORT_AEN_NPIV_DUP_WWN);
6541 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_DUP_WWN);
6543 break;
6545 case FC_LS_RJT_EXP_INSUFF_RES:
6547 * This means max logins per port/switch setting on the
6548 * switch was exceeded.
6550 if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
6551 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6552 else {
6553 bfa_fcs_vport_aen_post(&vport->lport,
6554 BFA_LPORT_AEN_NPIV_FABRIC_MAX);
6555 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_FABRIC_MAX);
6557 break;
6559 default:
6560 if (vport->fdisc_retries == 0)
6561 bfa_fcs_vport_aen_post(&vport->lport,
6562 BFA_LPORT_AEN_NPIV_UNKNOWN);
6563 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6568 * Called to send a logout to the fabric. Used when a V-Port is
6569 * deleted/stopped.
6571 static void
6572 bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s *vport)
6574 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6576 vport->vport_stats.logo_sent++;
6577 bfa_lps_fdisclogo(vport->lps);
6582 * This routine will be called by bfa_timer on timer timeouts.
6584 * param[in] vport - pointer to bfa_fcs_vport_t.
6585 * param[out] vport_status - pointer to return vport status in
6587 * return
6588 * void
6590 * Special Considerations:
6592 * note
6594 static void
6595 bfa_fcs_vport_timeout(void *vport_arg)
6597 struct bfa_fcs_vport_s *vport = (struct bfa_fcs_vport_s *) vport_arg;
6599 vport->vport_stats.fdisc_timeouts++;
6600 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_TIMEOUT);
6603 static void
6604 bfa_fcs_vport_free(struct bfa_fcs_vport_s *vport)
6606 struct bfad_vport_s *vport_drv =
6607 (struct bfad_vport_s *)vport->vport_drv;
6609 bfa_fcs_fabric_delvport(__vport_fabric(vport), vport);
6610 bfa_lps_delete(vport->lps);
6612 if (vport_drv->comp_del) {
6613 complete(vport_drv->comp_del);
6614 return;
6618 * We queue the vport delete work to the IM work_q from here.
6619 * The memory for the bfad_vport_s is freed from the FC function
6620 * template vport_delete entry point.
6622 bfad_im_port_delete(vport_drv->drv_port.bfad, &vport_drv->drv_port);
6626 * fcs_vport_public FCS virtual port public interfaces
6630 * Online notification from fabric SM.
6632 void
6633 bfa_fcs_vport_online(struct bfa_fcs_vport_s *vport)
6635 vport->vport_stats.fab_online++;
6636 if (bfa_fcs_fabric_npiv_capable(__vport_fabric(vport)))
6637 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_ONLINE);
6638 else
6639 vport->vport_stats.fab_no_npiv++;
6643 * Offline notification from fabric SM.
6645 void
6646 bfa_fcs_vport_offline(struct bfa_fcs_vport_s *vport)
6648 vport->vport_stats.fab_offline++;
6649 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_OFFLINE);
6653 * Cleanup notification from fabric SM on link timer expiry.
6655 void
6656 bfa_fcs_vport_cleanup(struct bfa_fcs_vport_s *vport)
6658 vport->vport_stats.fab_cleanup++;
6662 * Stop notification from fabric SM. To be invoked from within FCS.
6664 void
6665 bfa_fcs_vport_fcs_stop(struct bfa_fcs_vport_s *vport)
6667 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOP);
6671 * delete notification from fabric SM. To be invoked from within FCS.
6673 void
6674 bfa_fcs_vport_fcs_delete(struct bfa_fcs_vport_s *vport)
6676 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELETE);
6680 * Stop completion callback from associated lport
6682 void
6683 bfa_fcs_vport_stop_comp(struct bfa_fcs_vport_s *vport)
6685 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOPCOMP);
6689 * Delete completion callback from associated lport
6691 void
6692 bfa_fcs_vport_delete_comp(struct bfa_fcs_vport_s *vport)
6694 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELCOMP);
6700 * fcs_vport_api Virtual port API
6704 * Use this function to instantiate a new FCS vport object. This
6705 * function will not trigger any HW initialization process (which will be
6706 * done in vport_start() call)
6708 * param[in] vport - pointer to bfa_fcs_vport_t. This space
6709 * needs to be allocated by the driver.
6710 * param[in] fcs - FCS instance
6711 * param[in] vport_cfg - vport configuration
6712 * param[in] vf_id - VF_ID if vport is created within a VF.
6713 * FC_VF_ID_NULL to specify base fabric.
6714 * param[in] vport_drv - Opaque handle back to the driver's vport
6715 * structure
6717 * retval BFA_STATUS_OK - on success.
6718 * retval BFA_STATUS_FAILED - on failure.
6720 bfa_status_t
6721 bfa_fcs_vport_create(struct bfa_fcs_vport_s *vport, struct bfa_fcs_s *fcs,
6722 u16 vf_id, struct bfa_lport_cfg_s *vport_cfg,
6723 struct bfad_vport_s *vport_drv)
6725 if (vport_cfg->pwwn == 0)
6726 return BFA_STATUS_INVALID_WWN;
6728 if (bfa_fcs_lport_get_pwwn(&fcs->fabric.bport) == vport_cfg->pwwn)
6729 return BFA_STATUS_VPORT_WWN_BP;
6731 if (bfa_fcs_vport_lookup(fcs, vf_id, vport_cfg->pwwn) != NULL)
6732 return BFA_STATUS_VPORT_EXISTS;
6734 if (fcs->fabric.num_vports ==
6735 bfa_lps_get_max_vport(fcs->bfa))
6736 return BFA_STATUS_VPORT_MAX;
6738 vport->lps = bfa_lps_alloc(fcs->bfa);
6739 if (!vport->lps)
6740 return BFA_STATUS_VPORT_MAX;
6742 vport->vport_drv = vport_drv;
6743 vport_cfg->preboot_vp = BFA_FALSE;
6745 bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
6746 bfa_fcs_lport_attach(&vport->lport, fcs, vf_id, vport);
6747 bfa_fcs_lport_init(&vport->lport, vport_cfg);
6748 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_CREATE);
6750 return BFA_STATUS_OK;
6754 * Use this function to instantiate a new FCS PBC vport object. This
6755 * function will not trigger any HW initialization process (which will be
6756 * done in vport_start() call)
6758 * param[in] vport - pointer to bfa_fcs_vport_t. This space
6759 * needs to be allocated by the driver.
6760 * param[in] fcs - FCS instance
6761 * param[in] vport_cfg - vport configuration
6762 * param[in] vf_id - VF_ID if vport is created within a VF.
6763 * FC_VF_ID_NULL to specify base fabric.
6764 * param[in] vport_drv - Opaque handle back to the driver's vport
6765 * structure
6767 * retval BFA_STATUS_OK - on success.
6768 * retval BFA_STATUS_FAILED - on failure.
6770 bfa_status_t
6771 bfa_fcs_pbc_vport_create(struct bfa_fcs_vport_s *vport, struct bfa_fcs_s *fcs,
6772 u16 vf_id, struct bfa_lport_cfg_s *vport_cfg,
6773 struct bfad_vport_s *vport_drv)
6775 bfa_status_t rc;
6777 rc = bfa_fcs_vport_create(vport, fcs, vf_id, vport_cfg, vport_drv);
6778 vport->lport.port_cfg.preboot_vp = BFA_TRUE;
6780 return rc;
6784 * Use this function to findout if this is a pbc vport or not.
6786 * @param[in] vport - pointer to bfa_fcs_vport_t.
6788 * @returns None
6790 bfa_boolean_t
6791 bfa_fcs_is_pbc_vport(struct bfa_fcs_vport_s *vport)
6794 if (vport && (vport->lport.port_cfg.preboot_vp == BFA_TRUE))
6795 return BFA_TRUE;
6796 else
6797 return BFA_FALSE;
6802 * Use this function initialize the vport.
6804 * @param[in] vport - pointer to bfa_fcs_vport_t.
6806 * @returns None
6808 bfa_status_t
6809 bfa_fcs_vport_start(struct bfa_fcs_vport_s *vport)
6811 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_START);
6813 return BFA_STATUS_OK;
6817 * Use this function quiese the vport object. This function will return
6818 * immediately, when the vport is actually stopped, the
6819 * bfa_drv_vport_stop_cb() will be called.
6821 * param[in] vport - pointer to bfa_fcs_vport_t.
6823 * return None
6825 bfa_status_t
6826 bfa_fcs_vport_stop(struct bfa_fcs_vport_s *vport)
6828 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOP);
6830 return BFA_STATUS_OK;
6834 * Use this function to delete a vport object. Fabric object should
6835 * be stopped before this function call.
6837 * !!!!!!! Donot invoke this from within FCS !!!!!!!
6839 * param[in] vport - pointer to bfa_fcs_vport_t.
6841 * return None
6843 bfa_status_t
6844 bfa_fcs_vport_delete(struct bfa_fcs_vport_s *vport)
6847 if (vport->lport.port_cfg.preboot_vp)
6848 return BFA_STATUS_PBC;
6850 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELETE);
6852 return BFA_STATUS_OK;
6856 * Use this function to get vport's current status info.
6858 * param[in] vport pointer to bfa_fcs_vport_t.
6859 * param[out] attr pointer to return vport attributes
6861 * return None
6863 void
6864 bfa_fcs_vport_get_attr(struct bfa_fcs_vport_s *vport,
6865 struct bfa_vport_attr_s *attr)
6867 if (vport == NULL || attr == NULL)
6868 return;
6870 memset(attr, 0, sizeof(struct bfa_vport_attr_s));
6872 bfa_fcs_lport_get_attr(&vport->lport, &attr->port_attr);
6873 attr->vport_state = bfa_sm_to_state(vport_sm_table, vport->sm);
6878 * Lookup a virtual port. Excludes base port from lookup.
6880 struct bfa_fcs_vport_s *
6881 bfa_fcs_vport_lookup(struct bfa_fcs_s *fcs, u16 vf_id, wwn_t vpwwn)
6883 struct bfa_fcs_vport_s *vport;
6884 struct bfa_fcs_fabric_s *fabric;
6886 bfa_trc(fcs, vf_id);
6887 bfa_trc(fcs, vpwwn);
6889 fabric = bfa_fcs_vf_lookup(fcs, vf_id);
6890 if (!fabric) {
6891 bfa_trc(fcs, vf_id);
6892 return NULL;
6895 vport = bfa_fcs_fabric_vport_lookup(fabric, vpwwn);
6896 return vport;
6900 * FDISC Response
6902 void
6903 bfa_cb_lps_fdisc_comp(void *bfad, void *uarg, bfa_status_t status)
6905 struct bfa_fcs_vport_s *vport = uarg;
6907 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6908 bfa_trc(__vport_fcs(vport), status);
6910 switch (status) {
6911 case BFA_STATUS_OK:
6913 * Initialize the V-Port fields
6915 __vport_fcid(vport) = vport->lps->lp_pid;
6916 vport->vport_stats.fdisc_accepts++;
6917 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_OK);
6918 break;
6920 case BFA_STATUS_INVALID_MAC:
6921 /* Only for CNA */
6922 vport->vport_stats.fdisc_acc_bad++;
6923 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6925 break;
6927 case BFA_STATUS_EPROTOCOL:
6928 switch (vport->lps->ext_status) {
6929 case BFA_EPROTO_BAD_ACCEPT:
6930 vport->vport_stats.fdisc_acc_bad++;
6931 break;
6933 case BFA_EPROTO_UNKNOWN_RSP:
6934 vport->vport_stats.fdisc_unknown_rsp++;
6935 break;
6937 default:
6938 break;
6941 if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
6942 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6943 else
6944 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_FAILED);
6946 break;
6948 case BFA_STATUS_ETIMER:
6949 vport->vport_stats.fdisc_timeouts++;
6950 if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
6951 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6952 else
6953 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_FAILED);
6954 break;
6956 case BFA_STATUS_FABRIC_RJT:
6957 vport->vport_stats.fdisc_rejects++;
6958 bfa_fcs_vport_fdisc_rejected(vport);
6959 break;
6961 default:
6962 vport->vport_stats.fdisc_rsp_err++;
6963 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6968 * LOGO response
6970 void
6971 bfa_cb_lps_fdisclogo_comp(void *bfad, void *uarg)
6973 struct bfa_fcs_vport_s *vport = uarg;
6974 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_OK);
6978 * Received clear virtual link
6980 void
6981 bfa_cb_lps_cvl_event(void *bfad, void *uarg)
6983 struct bfa_fcs_vport_s *vport = uarg;
6985 /* Send an Offline followed by an ONLINE */
6986 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_OFFLINE);
6987 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_ONLINE);