drm/virtio: Don't return error if virtio-gpu PCI dev is not found
[drm/drm-misc.git] / drivers / scsi / bfa / bfa_fcs_lport.c
blob9a85f417018f99ac2f87f19eb1ea5c8a4e8d61a2
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
4 * Copyright (c) 2014- QLogic Corporation.
5 * All rights reserved
6 * www.qlogic.com
8 * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
9 */
11 #include "bfad_drv.h"
12 #include "bfad_im.h"
13 #include "bfa_fcs.h"
14 #include "bfa_fcbuild.h"
15 #include "bfa_fc.h"
17 BFA_TRC_FILE(FCS, PORT);
20 * ALPA to LIXA bitmap mapping
22 * ALPA 0x00 (Word 0, Bit 30) is invalid for N_Ports. Also Word 0 Bit 31
23 * is for L_bit (login required) and is filled as ALPA 0x00 here.
25 static const u8 loop_alpa_map[] = {
26 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x0F, 0x10, /* Word 0 Bits 31..24 */
27 0x17, 0x18, 0x1B, 0x1D, 0x1E, 0x1F, 0x23, 0x25, /* Word 0 Bits 23..16 */
28 0x26, 0x27, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, /* Word 0 Bits 15..08 */
29 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x39, 0x3A, /* Word 0 Bits 07..00 */
31 0x3C, 0x43, 0x45, 0x46, 0x47, 0x49, 0x4A, 0x4B, /* Word 1 Bits 31..24 */
32 0x4C, 0x4D, 0x4E, 0x51, 0x52, 0x53, 0x54, 0x55, /* Word 1 Bits 23..16 */
33 0x56, 0x59, 0x5A, 0x5C, 0x63, 0x65, 0x66, 0x67, /* Word 1 Bits 15..08 */
34 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x71, 0x72, /* Word 1 Bits 07..00 */
36 0x73, 0x74, 0x75, 0x76, 0x79, 0x7A, 0x7C, 0x80, /* Word 2 Bits 31..24 */
37 0x81, 0x82, 0x84, 0x88, 0x8F, 0x90, 0x97, 0x98, /* Word 2 Bits 23..16 */
38 0x9B, 0x9D, 0x9E, 0x9F, 0xA3, 0xA5, 0xA6, 0xA7, /* Word 2 Bits 15..08 */
39 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xB1, 0xB2, /* Word 2 Bits 07..00 */
41 0xB3, 0xB4, 0xB5, 0xB6, 0xB9, 0xBA, 0xBC, 0xC3, /* Word 3 Bits 31..24 */
42 0xC5, 0xC6, 0xC7, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, /* Word 3 Bits 23..16 */
43 0xCE, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD9, /* Word 3 Bits 15..08 */
44 0xDA, 0xDC, 0xE0, 0xE1, 0xE2, 0xE4, 0xE8, 0xEF, /* Word 3 Bits 07..00 */
47 static void bfa_fcs_lport_send_ls_rjt(struct bfa_fcs_lport_s *port,
48 struct fchs_s *rx_fchs, u8 reason_code,
49 u8 reason_code_expl);
50 static void bfa_fcs_lport_plogi(struct bfa_fcs_lport_s *port,
51 struct fchs_s *rx_fchs, struct fc_logi_s *plogi);
52 static void bfa_fcs_lport_online_actions(struct bfa_fcs_lport_s *port);
53 static void bfa_fcs_lport_offline_actions(struct bfa_fcs_lport_s *port);
54 static void bfa_fcs_lport_unknown_init(struct bfa_fcs_lport_s *port);
55 static void bfa_fcs_lport_unknown_online(struct bfa_fcs_lport_s *port);
56 static void bfa_fcs_lport_unknown_offline(struct bfa_fcs_lport_s *port);
57 static void bfa_fcs_lport_deleted(struct bfa_fcs_lport_s *port);
58 static void bfa_fcs_lport_echo(struct bfa_fcs_lport_s *port,
59 struct fchs_s *rx_fchs,
60 struct fc_echo_s *echo, u16 len);
61 static void bfa_fcs_lport_rnid(struct bfa_fcs_lport_s *port,
62 struct fchs_s *rx_fchs,
63 struct fc_rnid_cmd_s *rnid, u16 len);
64 static void bfa_fs_port_get_gen_topo_data(struct bfa_fcs_lport_s *port,
65 struct fc_rnid_general_topology_data_s *gen_topo_data);
67 static void bfa_fcs_lport_fab_init(struct bfa_fcs_lport_s *port);
68 static void bfa_fcs_lport_fab_online(struct bfa_fcs_lport_s *port);
69 static void bfa_fcs_lport_fab_offline(struct bfa_fcs_lport_s *port);
71 static void bfa_fcs_lport_n2n_init(struct bfa_fcs_lport_s *port);
72 static void bfa_fcs_lport_n2n_online(struct bfa_fcs_lport_s *port);
73 static void bfa_fcs_lport_n2n_offline(struct bfa_fcs_lport_s *port);
75 static void bfa_fcs_lport_loop_init(struct bfa_fcs_lport_s *port);
76 static void bfa_fcs_lport_loop_online(struct bfa_fcs_lport_s *port);
77 static void bfa_fcs_lport_loop_offline(struct bfa_fcs_lport_s *port);
79 static struct {
80 void (*init) (struct bfa_fcs_lport_s *port);
81 void (*online) (struct bfa_fcs_lport_s *port);
82 void (*offline) (struct bfa_fcs_lport_s *port);
83 } __port_action[] = {
84 [BFA_FCS_FABRIC_UNKNOWN] = {
85 .init = bfa_fcs_lport_unknown_init,
86 .online = bfa_fcs_lport_unknown_online,
87 .offline = bfa_fcs_lport_unknown_offline
89 [BFA_FCS_FABRIC_SWITCHED] = {
90 .init = bfa_fcs_lport_fab_init,
91 .online = bfa_fcs_lport_fab_online,
92 .offline = bfa_fcs_lport_fab_offline
94 [BFA_FCS_FABRIC_N2N] = {
95 .init = bfa_fcs_lport_n2n_init,
96 .online = bfa_fcs_lport_n2n_online,
97 .offline = bfa_fcs_lport_n2n_offline
99 [BFA_FCS_FABRIC_LOOP] = {
100 .init = bfa_fcs_lport_loop_init,
101 .online = bfa_fcs_lport_loop_online,
102 .offline = bfa_fcs_lport_loop_offline
106 static void bfa_fcs_lport_sm_uninit(struct bfa_fcs_lport_s *port,
107 enum bfa_fcs_lport_event event);
108 static void bfa_fcs_lport_sm_init(struct bfa_fcs_lport_s *port,
109 enum bfa_fcs_lport_event event);
110 static void bfa_fcs_lport_sm_online(struct bfa_fcs_lport_s *port,
111 enum bfa_fcs_lport_event event);
112 static void bfa_fcs_lport_sm_offline(struct bfa_fcs_lport_s *port,
113 enum bfa_fcs_lport_event event);
114 static void bfa_fcs_lport_sm_deleting(struct bfa_fcs_lport_s *port,
115 enum bfa_fcs_lport_event event);
116 static void bfa_fcs_lport_sm_stopping(struct bfa_fcs_lport_s *port,
117 enum bfa_fcs_lport_event event);
119 static void
120 bfa_fcs_lport_sm_uninit(
121 struct bfa_fcs_lport_s *port,
122 enum bfa_fcs_lport_event event)
124 bfa_trc(port->fcs, port->port_cfg.pwwn);
125 bfa_trc(port->fcs, event);
127 switch (event) {
128 case BFA_FCS_PORT_SM_CREATE:
129 bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
130 break;
132 default:
133 bfa_sm_fault(port->fcs, event);
137 static void
138 bfa_fcs_lport_sm_init(struct bfa_fcs_lport_s *port,
139 enum bfa_fcs_lport_event event)
141 bfa_trc(port->fcs, port->port_cfg.pwwn);
142 bfa_trc(port->fcs, event);
144 switch (event) {
145 case BFA_FCS_PORT_SM_ONLINE:
146 bfa_sm_set_state(port, bfa_fcs_lport_sm_online);
147 bfa_fcs_lport_online_actions(port);
148 break;
150 case BFA_FCS_PORT_SM_DELETE:
151 bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
152 bfa_fcs_lport_deleted(port);
153 break;
155 case BFA_FCS_PORT_SM_STOP:
156 /* If vport - send completion call back */
157 if (port->vport)
158 bfa_fcs_vport_stop_comp(port->vport);
159 else
160 bfa_wc_down(&(port->fabric->stop_wc));
161 break;
163 case BFA_FCS_PORT_SM_OFFLINE:
164 break;
166 default:
167 bfa_sm_fault(port->fcs, event);
171 static void
172 bfa_fcs_lport_sm_online(
173 struct bfa_fcs_lport_s *port,
174 enum bfa_fcs_lport_event event)
176 struct bfa_fcs_rport_s *rport;
177 struct list_head *qe, *qen;
179 bfa_trc(port->fcs, port->port_cfg.pwwn);
180 bfa_trc(port->fcs, event);
182 switch (event) {
183 case BFA_FCS_PORT_SM_OFFLINE:
184 bfa_sm_set_state(port, bfa_fcs_lport_sm_offline);
185 bfa_fcs_lport_offline_actions(port);
186 break;
188 case BFA_FCS_PORT_SM_STOP:
189 __port_action[port->fabric->fab_type].offline(port);
191 if (port->num_rports == 0) {
192 bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
193 /* If vport - send completion call back */
194 if (port->vport)
195 bfa_fcs_vport_stop_comp(port->vport);
196 else
197 bfa_wc_down(&(port->fabric->stop_wc));
198 } else {
199 bfa_sm_set_state(port, bfa_fcs_lport_sm_stopping);
200 list_for_each_safe(qe, qen, &port->rport_q) {
201 rport = (struct bfa_fcs_rport_s *) qe;
202 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
205 break;
207 case BFA_FCS_PORT_SM_DELETE:
209 __port_action[port->fabric->fab_type].offline(port);
211 if (port->num_rports == 0) {
212 bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
213 bfa_fcs_lport_deleted(port);
214 } else {
215 bfa_sm_set_state(port, bfa_fcs_lport_sm_deleting);
216 list_for_each_safe(qe, qen, &port->rport_q) {
217 rport = (struct bfa_fcs_rport_s *) qe;
218 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
221 break;
223 case BFA_FCS_PORT_SM_DELRPORT:
224 break;
226 default:
227 bfa_sm_fault(port->fcs, event);
231 static void
232 bfa_fcs_lport_sm_offline(
233 struct bfa_fcs_lport_s *port,
234 enum bfa_fcs_lport_event event)
236 struct bfa_fcs_rport_s *rport;
237 struct list_head *qe, *qen;
239 bfa_trc(port->fcs, port->port_cfg.pwwn);
240 bfa_trc(port->fcs, event);
242 switch (event) {
243 case BFA_FCS_PORT_SM_ONLINE:
244 bfa_sm_set_state(port, bfa_fcs_lport_sm_online);
245 bfa_fcs_lport_online_actions(port);
246 break;
248 case BFA_FCS_PORT_SM_STOP:
249 if (port->num_rports == 0) {
250 bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
251 /* If vport - send completion call back */
252 if (port->vport)
253 bfa_fcs_vport_stop_comp(port->vport);
254 else
255 bfa_wc_down(&(port->fabric->stop_wc));
256 } else {
257 bfa_sm_set_state(port, bfa_fcs_lport_sm_stopping);
258 list_for_each_safe(qe, qen, &port->rport_q) {
259 rport = (struct bfa_fcs_rport_s *) qe;
260 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
263 break;
265 case BFA_FCS_PORT_SM_DELETE:
266 if (port->num_rports == 0) {
267 bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
268 bfa_fcs_lport_deleted(port);
269 } else {
270 bfa_sm_set_state(port, bfa_fcs_lport_sm_deleting);
271 list_for_each_safe(qe, qen, &port->rport_q) {
272 rport = (struct bfa_fcs_rport_s *) qe;
273 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
276 break;
278 case BFA_FCS_PORT_SM_DELRPORT:
279 case BFA_FCS_PORT_SM_OFFLINE:
280 break;
282 default:
283 bfa_sm_fault(port->fcs, event);
287 static void
288 bfa_fcs_lport_sm_stopping(struct bfa_fcs_lport_s *port,
289 enum bfa_fcs_lport_event event)
291 bfa_trc(port->fcs, port->port_cfg.pwwn);
292 bfa_trc(port->fcs, event);
294 switch (event) {
295 case BFA_FCS_PORT_SM_DELRPORT:
296 if (port->num_rports == 0) {
297 bfa_sm_set_state(port, bfa_fcs_lport_sm_init);
298 /* If vport - send completion call back */
299 if (port->vport)
300 bfa_fcs_vport_stop_comp(port->vport);
301 else
302 bfa_wc_down(&(port->fabric->stop_wc));
304 break;
306 default:
307 bfa_sm_fault(port->fcs, event);
311 static void
312 bfa_fcs_lport_sm_deleting(
313 struct bfa_fcs_lport_s *port,
314 enum bfa_fcs_lport_event event)
316 bfa_trc(port->fcs, port->port_cfg.pwwn);
317 bfa_trc(port->fcs, event);
319 switch (event) {
320 case BFA_FCS_PORT_SM_DELRPORT:
321 if (port->num_rports == 0) {
322 bfa_sm_set_state(port, bfa_fcs_lport_sm_uninit);
323 bfa_fcs_lport_deleted(port);
325 break;
327 default:
328 bfa_sm_fault(port->fcs, event);
333 * fcs_port_pvt
337 * Send AEN notification
339 static void
340 bfa_fcs_lport_aen_post(struct bfa_fcs_lport_s *port,
341 enum bfa_lport_aen_event event)
343 struct bfad_s *bfad = (struct bfad_s *)port->fabric->fcs->bfad;
344 struct bfa_aen_entry_s *aen_entry;
346 bfad_get_aen_entry(bfad, aen_entry);
347 if (!aen_entry)
348 return;
350 aen_entry->aen_data.lport.vf_id = port->fabric->vf_id;
351 aen_entry->aen_data.lport.roles = port->port_cfg.roles;
352 aen_entry->aen_data.lport.ppwwn = bfa_fcs_lport_get_pwwn(
353 bfa_fcs_get_base_port(port->fcs));
354 aen_entry->aen_data.lport.lpwwn = bfa_fcs_lport_get_pwwn(port);
356 /* Send the AEN notification */
357 bfad_im_post_vendor_event(aen_entry, bfad, ++port->fcs->fcs_aen_seq,
358 BFA_AEN_CAT_LPORT, event);
362 * Send a LS reject
364 static void
365 bfa_fcs_lport_send_ls_rjt(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs,
366 u8 reason_code, u8 reason_code_expl)
368 struct fchs_s fchs;
369 struct bfa_fcxp_s *fcxp;
370 struct bfa_rport_s *bfa_rport = NULL;
371 int len;
373 bfa_trc(port->fcs, rx_fchs->d_id);
374 bfa_trc(port->fcs, rx_fchs->s_id);
376 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
377 if (!fcxp)
378 return;
380 len = fc_ls_rjt_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
381 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
382 rx_fchs->ox_id, reason_code, reason_code_expl);
384 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
385 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
386 FC_MAX_PDUSZ, 0);
390 * Send a FCCT Reject
392 static void
393 bfa_fcs_lport_send_fcgs_rjt(struct bfa_fcs_lport_s *port,
394 struct fchs_s *rx_fchs, u8 reason_code, u8 reason_code_expl)
396 struct fchs_s fchs;
397 struct bfa_fcxp_s *fcxp;
398 struct bfa_rport_s *bfa_rport = NULL;
399 int len;
400 struct ct_hdr_s *rx_cthdr = (struct ct_hdr_s *)(rx_fchs + 1);
401 struct ct_hdr_s *ct_hdr;
403 bfa_trc(port->fcs, rx_fchs->d_id);
404 bfa_trc(port->fcs, rx_fchs->s_id);
406 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
407 if (!fcxp)
408 return;
410 ct_hdr = bfa_fcxp_get_reqbuf(fcxp);
411 ct_hdr->gs_type = rx_cthdr->gs_type;
412 ct_hdr->gs_sub_type = rx_cthdr->gs_sub_type;
414 len = fc_gs_rjt_build(&fchs, ct_hdr, rx_fchs->s_id,
415 bfa_fcs_lport_get_fcid(port),
416 rx_fchs->ox_id, reason_code, reason_code_expl);
418 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
419 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
420 FC_MAX_PDUSZ, 0);
424 * Process incoming plogi from a remote port.
426 static void
427 bfa_fcs_lport_plogi(struct bfa_fcs_lport_s *port,
428 struct fchs_s *rx_fchs, struct fc_logi_s *plogi)
430 struct bfa_fcs_rport_s *rport;
432 bfa_trc(port->fcs, rx_fchs->d_id);
433 bfa_trc(port->fcs, rx_fchs->s_id);
436 * If min cfg mode is enabled, drop any incoming PLOGIs
438 if (__fcs_min_cfg(port->fcs)) {
439 bfa_trc(port->fcs, rx_fchs->s_id);
440 return;
443 if (fc_plogi_parse(rx_fchs) != FC_PARSE_OK) {
444 bfa_trc(port->fcs, rx_fchs->s_id);
446 * send a LS reject
448 bfa_fcs_lport_send_ls_rjt(port, rx_fchs,
449 FC_LS_RJT_RSN_PROTOCOL_ERROR,
450 FC_LS_RJT_EXP_SPARMS_ERR_OPTIONS);
451 return;
455 * Direct Attach P2P mode : verify address assigned by the r-port.
457 if ((!bfa_fcs_fabric_is_switched(port->fabric)) &&
458 (memcmp((void *)&bfa_fcs_lport_get_pwwn(port),
459 (void *)&plogi->port_name, sizeof(wwn_t)) < 0)) {
460 if (BFA_FCS_PID_IS_WKA(rx_fchs->d_id)) {
461 /* Address assigned to us cannot be a WKA */
462 bfa_fcs_lport_send_ls_rjt(port, rx_fchs,
463 FC_LS_RJT_RSN_PROTOCOL_ERROR,
464 FC_LS_RJT_EXP_INVALID_NPORT_ID);
465 return;
467 port->pid = rx_fchs->d_id;
468 bfa_lps_set_n2n_pid(port->fabric->lps, rx_fchs->d_id);
472 * First, check if we know the device by pwwn.
474 rport = bfa_fcs_lport_get_rport_by_pwwn(port, plogi->port_name);
475 if (rport) {
477 * Direct Attach P2P mode : handle address assigned by r-port.
479 if ((!bfa_fcs_fabric_is_switched(port->fabric)) &&
480 (memcmp((void *)&bfa_fcs_lport_get_pwwn(port),
481 (void *)&plogi->port_name, sizeof(wwn_t)) < 0)) {
482 port->pid = rx_fchs->d_id;
483 bfa_lps_set_n2n_pid(port->fabric->lps, rx_fchs->d_id);
484 rport->pid = rx_fchs->s_id;
486 bfa_fcs_rport_plogi(rport, rx_fchs, plogi);
487 return;
491 * Next, lookup rport by PID.
493 rport = bfa_fcs_lport_get_rport_by_pid(port, rx_fchs->s_id);
494 if (!rport) {
496 * Inbound PLOGI from a new device.
498 bfa_fcs_rport_plogi_create(port, rx_fchs, plogi);
499 return;
503 * Rport is known only by PID.
505 if (rport->pwwn) {
507 * This is a different device with the same pid. Old device
508 * disappeared. Send implicit LOGO to old device.
510 WARN_ON(rport->pwwn == plogi->port_name);
511 bfa_sm_send_event(rport, RPSM_EVENT_LOGO_IMP);
514 * Inbound PLOGI from a new device (with old PID).
516 bfa_fcs_rport_plogi_create(port, rx_fchs, plogi);
517 return;
521 * PLOGI crossing each other.
523 WARN_ON(rport->pwwn != WWN_NULL);
524 bfa_fcs_rport_plogi(rport, rx_fchs, plogi);
528 * Process incoming ECHO.
529 * Since it does not require a login, it is processed here.
531 static void
532 bfa_fcs_lport_echo(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs,
533 struct fc_echo_s *echo, u16 rx_len)
535 struct fchs_s fchs;
536 struct bfa_fcxp_s *fcxp;
537 struct bfa_rport_s *bfa_rport = NULL;
538 int len, pyld_len;
540 bfa_trc(port->fcs, rx_fchs->s_id);
541 bfa_trc(port->fcs, rx_fchs->d_id);
543 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
544 if (!fcxp)
545 return;
547 len = fc_ls_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
548 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
549 rx_fchs->ox_id);
552 * Copy the payload (if any) from the echo frame
554 pyld_len = rx_len - sizeof(struct fchs_s);
555 bfa_trc(port->fcs, rx_len);
556 bfa_trc(port->fcs, pyld_len);
558 if (pyld_len > len)
559 memcpy(((u8 *) bfa_fcxp_get_reqbuf(fcxp)) +
560 sizeof(struct fc_echo_s), (echo + 1),
561 (pyld_len - sizeof(struct fc_echo_s)));
563 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
564 BFA_FALSE, FC_CLASS_3, pyld_len, &fchs, NULL, NULL,
565 FC_MAX_PDUSZ, 0);
569 * Process incoming RNID.
570 * Since it does not require a login, it is processed here.
572 static void
573 bfa_fcs_lport_rnid(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs,
574 struct fc_rnid_cmd_s *rnid, u16 rx_len)
576 struct fc_rnid_common_id_data_s common_id_data;
577 struct fc_rnid_general_topology_data_s gen_topo_data;
578 struct fchs_s fchs;
579 struct bfa_fcxp_s *fcxp;
580 struct bfa_rport_s *bfa_rport = NULL;
581 u16 len;
582 u32 data_format;
584 bfa_trc(port->fcs, rx_fchs->s_id);
585 bfa_trc(port->fcs, rx_fchs->d_id);
586 bfa_trc(port->fcs, rx_len);
588 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
589 if (!fcxp)
590 return;
593 * Check Node Indentification Data Format
594 * We only support General Topology Discovery Format.
595 * For any other requested Data Formats, we return Common Node Id Data
596 * only, as per FC-LS.
598 bfa_trc(port->fcs, rnid->node_id_data_format);
599 if (rnid->node_id_data_format == RNID_NODEID_DATA_FORMAT_DISCOVERY) {
600 data_format = RNID_NODEID_DATA_FORMAT_DISCOVERY;
602 * Get General topology data for this port
604 bfa_fs_port_get_gen_topo_data(port, &gen_topo_data);
605 } else {
606 data_format = RNID_NODEID_DATA_FORMAT_COMMON;
610 * Copy the Node Id Info
612 common_id_data.port_name = bfa_fcs_lport_get_pwwn(port);
613 common_id_data.node_name = bfa_fcs_lport_get_nwwn(port);
615 len = fc_rnid_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
616 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
617 rx_fchs->ox_id, data_format, &common_id_data,
618 &gen_topo_data);
620 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
621 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
622 FC_MAX_PDUSZ, 0);
626 * Fill out General Topolpgy Discovery Data for RNID ELS.
628 static void
629 bfa_fs_port_get_gen_topo_data(struct bfa_fcs_lport_s *port,
630 struct fc_rnid_general_topology_data_s *gen_topo_data)
632 memset(gen_topo_data, 0,
633 sizeof(struct fc_rnid_general_topology_data_s));
635 gen_topo_data->asso_type = cpu_to_be32(RNID_ASSOCIATED_TYPE_HOST);
636 gen_topo_data->phy_port_num = 0; /* @todo */
637 gen_topo_data->num_attached_nodes = cpu_to_be32(1);
640 static void
641 bfa_fcs_lport_online_actions(struct bfa_fcs_lport_s *port)
643 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
644 char lpwwn_buf[BFA_STRING_32];
646 bfa_trc(port->fcs, port->fabric->oper_type);
648 __port_action[port->fabric->fab_type].init(port);
649 __port_action[port->fabric->fab_type].online(port);
651 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
652 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
653 "Logical port online: WWN = %s Role = %s\n",
654 lpwwn_buf, "Initiator");
655 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_ONLINE);
657 bfad->bfad_flags |= BFAD_PORT_ONLINE;
660 static void
661 bfa_fcs_lport_offline_actions(struct bfa_fcs_lport_s *port)
663 struct list_head *qe, *qen;
664 struct bfa_fcs_rport_s *rport;
665 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
666 char lpwwn_buf[BFA_STRING_32];
668 bfa_trc(port->fcs, port->fabric->oper_type);
670 __port_action[port->fabric->fab_type].offline(port);
672 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
673 if (bfa_sm_cmp_state(port->fabric,
674 bfa_fcs_fabric_sm_online) == BFA_TRUE) {
675 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
676 "Logical port lost fabric connectivity: WWN = %s Role = %s\n",
677 lpwwn_buf, "Initiator");
678 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_DISCONNECT);
679 } else {
680 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
681 "Logical port taken offline: WWN = %s Role = %s\n",
682 lpwwn_buf, "Initiator");
683 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_OFFLINE);
686 list_for_each_safe(qe, qen, &port->rport_q) {
687 rport = (struct bfa_fcs_rport_s *) qe;
688 bfa_sm_send_event(rport, RPSM_EVENT_LOGO_IMP);
692 static void
693 bfa_fcs_lport_unknown_init(struct bfa_fcs_lport_s *port)
695 WARN_ON(1);
698 static void
699 bfa_fcs_lport_unknown_online(struct bfa_fcs_lport_s *port)
701 WARN_ON(1);
704 static void
705 bfa_fcs_lport_unknown_offline(struct bfa_fcs_lport_s *port)
707 WARN_ON(1);
710 static void
711 bfa_fcs_lport_abts_acc(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs)
713 struct fchs_s fchs;
714 struct bfa_fcxp_s *fcxp;
715 int len;
717 bfa_trc(port->fcs, rx_fchs->d_id);
718 bfa_trc(port->fcs, rx_fchs->s_id);
720 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
721 if (!fcxp)
722 return;
724 len = fc_ba_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
725 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
726 rx_fchs->ox_id, 0);
728 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag,
729 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
730 FC_MAX_PDUSZ, 0);
732 static void
733 bfa_fcs_lport_deleted(struct bfa_fcs_lport_s *port)
735 struct bfad_s *bfad = (struct bfad_s *)port->fcs->bfad;
736 char lpwwn_buf[BFA_STRING_32];
738 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
739 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
740 "Logical port deleted: WWN = %s Role = %s\n",
741 lpwwn_buf, "Initiator");
742 bfa_fcs_lport_aen_post(port, BFA_LPORT_AEN_DELETE);
744 /* Base port will be deleted by the OS driver */
745 if (port->vport)
746 bfa_fcs_vport_delete_comp(port->vport);
747 else
748 bfa_wc_down(&port->fabric->wc);
753 * Unsolicited frame receive handling.
755 void
756 bfa_fcs_lport_uf_recv(struct bfa_fcs_lport_s *lport,
757 struct fchs_s *fchs, u16 len)
759 u32 pid = fchs->s_id;
760 struct bfa_fcs_rport_s *rport = NULL;
761 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
763 bfa_stats(lport, uf_recvs);
764 bfa_trc(lport->fcs, fchs->type);
766 if (!bfa_fcs_lport_is_online(lport)) {
768 * In direct attach topology, it is possible to get a PLOGI
769 * before the lport is online due to port feature
770 * (QoS/Trunk/FEC/CR), so send a rjt
772 if ((fchs->type == FC_TYPE_ELS) &&
773 (els_cmd->els_code == FC_ELS_PLOGI)) {
774 bfa_fcs_lport_send_ls_rjt(lport, fchs,
775 FC_LS_RJT_RSN_UNABLE_TO_PERF_CMD,
776 FC_LS_RJT_EXP_NO_ADDL_INFO);
777 bfa_stats(lport, plogi_rcvd);
778 } else
779 bfa_stats(lport, uf_recv_drops);
781 return;
785 * First, handle ELSs that donot require a login.
788 * Handle PLOGI first
790 if ((fchs->type == FC_TYPE_ELS) &&
791 (els_cmd->els_code == FC_ELS_PLOGI)) {
792 bfa_fcs_lport_plogi(lport, fchs, (struct fc_logi_s *) els_cmd);
793 return;
797 * Handle ECHO separately.
799 if ((fchs->type == FC_TYPE_ELS) && (els_cmd->els_code == FC_ELS_ECHO)) {
800 bfa_fcs_lport_echo(lport, fchs,
801 (struct fc_echo_s *)els_cmd, len);
802 return;
806 * Handle RNID separately.
808 if ((fchs->type == FC_TYPE_ELS) && (els_cmd->els_code == FC_ELS_RNID)) {
809 bfa_fcs_lport_rnid(lport, fchs,
810 (struct fc_rnid_cmd_s *) els_cmd, len);
811 return;
814 if (fchs->type == FC_TYPE_BLS) {
815 if ((fchs->routing == FC_RTG_BASIC_LINK) &&
816 (fchs->cat_info == FC_CAT_ABTS))
817 bfa_fcs_lport_abts_acc(lport, fchs);
818 return;
821 if (fchs->type == FC_TYPE_SERVICES) {
823 * Unhandled FC-GS frames. Send a FC-CT Reject
825 bfa_fcs_lport_send_fcgs_rjt(lport, fchs, CT_RSN_NOT_SUPP,
826 CT_NS_EXP_NOADDITIONAL);
827 return;
831 * look for a matching remote port ID
833 rport = bfa_fcs_lport_get_rport_by_pid(lport, pid);
834 if (rport) {
835 bfa_trc(rport->fcs, fchs->s_id);
836 bfa_trc(rport->fcs, fchs->d_id);
837 bfa_trc(rport->fcs, fchs->type);
839 bfa_fcs_rport_uf_recv(rport, fchs, len);
840 return;
844 * Only handles ELS frames for now.
846 if (fchs->type != FC_TYPE_ELS) {
847 bfa_trc(lport->fcs, fchs->s_id);
848 bfa_trc(lport->fcs, fchs->d_id);
849 /* ignore type FC_TYPE_FC_FSS */
850 if (fchs->type != FC_TYPE_FC_FSS)
851 bfa_sm_fault(lport->fcs, fchs->type);
852 return;
855 bfa_trc(lport->fcs, els_cmd->els_code);
856 if (els_cmd->els_code == FC_ELS_RSCN) {
857 bfa_fcs_lport_scn_process_rscn(lport, fchs, len);
858 return;
861 if (els_cmd->els_code == FC_ELS_LOGO) {
863 * @todo Handle LOGO frames received.
865 return;
868 if (els_cmd->els_code == FC_ELS_PRLI) {
870 * @todo Handle PRLI frames received.
872 return;
876 * Unhandled ELS frames. Send a LS_RJT.
878 bfa_fcs_lport_send_ls_rjt(lport, fchs, FC_LS_RJT_RSN_CMD_NOT_SUPP,
879 FC_LS_RJT_EXP_NO_ADDL_INFO);
884 * PID based Lookup for a R-Port in the Port R-Port Queue
886 struct bfa_fcs_rport_s *
887 bfa_fcs_lport_get_rport_by_pid(struct bfa_fcs_lport_s *port, u32 pid)
889 struct bfa_fcs_rport_s *rport;
890 struct list_head *qe;
892 list_for_each(qe, &port->rport_q) {
893 rport = (struct bfa_fcs_rport_s *) qe;
894 if (rport->pid == pid)
895 return rport;
898 bfa_trc(port->fcs, pid);
899 return NULL;
903 * OLD_PID based Lookup for a R-Port in the Port R-Port Queue
905 struct bfa_fcs_rport_s *
906 bfa_fcs_lport_get_rport_by_old_pid(struct bfa_fcs_lport_s *port, u32 pid)
908 struct bfa_fcs_rport_s *rport;
909 struct list_head *qe;
911 list_for_each(qe, &port->rport_q) {
912 rport = (struct bfa_fcs_rport_s *) qe;
913 if (rport->old_pid == pid)
914 return rport;
917 bfa_trc(port->fcs, pid);
918 return NULL;
922 * PWWN based Lookup for a R-Port in the Port R-Port Queue
924 struct bfa_fcs_rport_s *
925 bfa_fcs_lport_get_rport_by_pwwn(struct bfa_fcs_lport_s *port, wwn_t pwwn)
927 struct bfa_fcs_rport_s *rport;
928 struct list_head *qe;
930 list_for_each(qe, &port->rport_q) {
931 rport = (struct bfa_fcs_rport_s *) qe;
932 if (wwn_is_equal(rport->pwwn, pwwn))
933 return rport;
936 bfa_trc(port->fcs, pwwn);
937 return NULL;
941 * PWWN & PID based Lookup for a R-Port in the Port R-Port Queue
943 struct bfa_fcs_rport_s *
944 bfa_fcs_lport_get_rport_by_qualifier(struct bfa_fcs_lport_s *port,
945 wwn_t pwwn, u32 pid)
947 struct bfa_fcs_rport_s *rport;
948 struct list_head *qe;
950 list_for_each(qe, &port->rport_q) {
951 rport = (struct bfa_fcs_rport_s *) qe;
952 if (wwn_is_equal(rport->pwwn, pwwn) && rport->pid == pid)
953 return rport;
956 bfa_trc(port->fcs, pwwn);
957 return NULL;
961 * Called by rport module when new rports are discovered.
963 void
964 bfa_fcs_lport_add_rport(
965 struct bfa_fcs_lport_s *port,
966 struct bfa_fcs_rport_s *rport)
968 list_add_tail(&rport->qe, &port->rport_q);
969 port->num_rports++;
973 * Called by rport module to when rports are deleted.
975 void
976 bfa_fcs_lport_del_rport(
977 struct bfa_fcs_lport_s *port,
978 struct bfa_fcs_rport_s *rport)
980 WARN_ON(!bfa_q_is_on_q(&port->rport_q, rport));
981 list_del(&rport->qe);
982 port->num_rports--;
984 bfa_sm_send_event(port, BFA_FCS_PORT_SM_DELRPORT);
988 * Called by fabric for base port when fabric login is complete.
989 * Called by vport for virtual ports when FDISC is complete.
991 void
992 bfa_fcs_lport_online(struct bfa_fcs_lport_s *port)
994 bfa_sm_send_event(port, BFA_FCS_PORT_SM_ONLINE);
998 * Called by fabric for base port when fabric goes offline.
999 * Called by vport for virtual ports when virtual port becomes offline.
1001 void
1002 bfa_fcs_lport_offline(struct bfa_fcs_lport_s *port)
1004 bfa_sm_send_event(port, BFA_FCS_PORT_SM_OFFLINE);
1008 * Called by fabric for base port and by vport for virtual ports
1009 * when target mode driver is unloaded.
1011 void
1012 bfa_fcs_lport_stop(struct bfa_fcs_lport_s *port)
1014 bfa_sm_send_event(port, BFA_FCS_PORT_SM_STOP);
1018 * Called by fabric to delete base lport and associated resources.
1020 * Called by vport to delete lport and associated resources. Should call
1021 * bfa_fcs_vport_delete_comp() for vports on completion.
1023 void
1024 bfa_fcs_lport_delete(struct bfa_fcs_lport_s *port)
1026 bfa_sm_send_event(port, BFA_FCS_PORT_SM_DELETE);
1030 * Return TRUE if port is online, else return FALSE
1032 bfa_boolean_t
1033 bfa_fcs_lport_is_online(struct bfa_fcs_lport_s *port)
1035 return bfa_sm_cmp_state(port, bfa_fcs_lport_sm_online);
1039 * Attach time initialization of logical ports.
1041 void
1042 bfa_fcs_lport_attach(struct bfa_fcs_lport_s *lport, struct bfa_fcs_s *fcs,
1043 u16 vf_id, struct bfa_fcs_vport_s *vport)
1045 lport->fcs = fcs;
1046 lport->fabric = bfa_fcs_vf_lookup(fcs, vf_id);
1047 lport->vport = vport;
1048 lport->lp_tag = (vport) ? vport->lps->bfa_tag :
1049 lport->fabric->lps->bfa_tag;
1051 INIT_LIST_HEAD(&lport->rport_q);
1052 lport->num_rports = 0;
1056 * Logical port initialization of base or virtual port.
1057 * Called by fabric for base port or by vport for virtual ports.
1060 void
1061 bfa_fcs_lport_init(struct bfa_fcs_lport_s *lport,
1062 struct bfa_lport_cfg_s *port_cfg)
1064 struct bfa_fcs_vport_s *vport = lport->vport;
1065 struct bfad_s *bfad = (struct bfad_s *)lport->fcs->bfad;
1066 char lpwwn_buf[BFA_STRING_32];
1068 lport->port_cfg = *port_cfg;
1070 lport->bfad_port = bfa_fcb_lport_new(lport->fcs->bfad, lport,
1071 lport->port_cfg.roles,
1072 lport->fabric->vf_drv,
1073 vport ? vport->vport_drv : NULL);
1075 wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(lport));
1076 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
1077 "New logical port created: WWN = %s Role = %s\n",
1078 lpwwn_buf, "Initiator");
1079 bfa_fcs_lport_aen_post(lport, BFA_LPORT_AEN_NEW);
1081 bfa_sm_set_state(lport, bfa_fcs_lport_sm_uninit);
1082 bfa_sm_send_event(lport, BFA_FCS_PORT_SM_CREATE);
1085 void
1086 bfa_fcs_lport_set_symname(struct bfa_fcs_lport_s *port,
1087 char *symname)
1089 strcpy(port->port_cfg.sym_name.symname, symname);
1091 if (bfa_sm_cmp_state(port, bfa_fcs_lport_sm_online))
1092 bfa_fcs_lport_ns_util_send_rspn_id(
1093 BFA_FCS_GET_NS_FROM_PORT(port), NULL);
1097 * fcs_lport_api
1100 void
1101 bfa_fcs_lport_get_attr(
1102 struct bfa_fcs_lport_s *port,
1103 struct bfa_lport_attr_s *port_attr)
1105 if (bfa_sm_cmp_state(port, bfa_fcs_lport_sm_online))
1106 port_attr->pid = port->pid;
1107 else
1108 port_attr->pid = 0;
1110 port_attr->port_cfg = port->port_cfg;
1112 if (port->fabric) {
1113 port_attr->port_type = port->fabric->oper_type;
1114 port_attr->loopback = bfa_sm_cmp_state(port->fabric,
1115 bfa_fcs_fabric_sm_loopback);
1116 port_attr->authfail =
1117 bfa_sm_cmp_state(port->fabric,
1118 bfa_fcs_fabric_sm_auth_failed);
1119 port_attr->fabric_name = bfa_fcs_lport_get_fabric_name(port);
1120 memcpy(port_attr->fabric_ip_addr,
1121 bfa_fcs_lport_get_fabric_ipaddr(port),
1122 BFA_FCS_FABRIC_IPADDR_SZ);
1124 if (port->vport != NULL) {
1125 port_attr->port_type = BFA_PORT_TYPE_VPORT;
1126 port_attr->fpma_mac =
1127 port->vport->lps->lp_mac;
1128 } else {
1129 port_attr->fpma_mac =
1130 port->fabric->lps->lp_mac;
1132 } else {
1133 port_attr->port_type = BFA_PORT_TYPE_UNKNOWN;
1134 port_attr->state = BFA_LPORT_UNINIT;
1139 * bfa_fcs_lport_fab port fab functions
1143 * Called by port to initialize fabric services of the base port.
1145 static void
1146 bfa_fcs_lport_fab_init(struct bfa_fcs_lport_s *port)
1148 bfa_fcs_lport_ns_init(port);
1149 bfa_fcs_lport_scn_init(port);
1150 bfa_fcs_lport_ms_init(port);
1154 * Called by port to notify transition to online state.
1156 static void
1157 bfa_fcs_lport_fab_online(struct bfa_fcs_lport_s *port)
1159 bfa_fcs_lport_ns_online(port);
1160 bfa_fcs_lport_fab_scn_online(port);
1164 * Called by port to notify transition to offline state.
1166 static void
1167 bfa_fcs_lport_fab_offline(struct bfa_fcs_lport_s *port)
1169 bfa_fcs_lport_ns_offline(port);
1170 bfa_fcs_lport_scn_offline(port);
1171 bfa_fcs_lport_ms_offline(port);
1175 * bfa_fcs_lport_n2n functions
1179 * Called by fcs/port to initialize N2N topology.
1181 static void
1182 bfa_fcs_lport_n2n_init(struct bfa_fcs_lport_s *port)
1187 * Called by fcs/port to notify transition to online state.
1189 static void
1190 bfa_fcs_lport_n2n_online(struct bfa_fcs_lport_s *port)
1192 struct bfa_fcs_lport_n2n_s *n2n_port = &port->port_topo.pn2n;
1193 struct bfa_lport_cfg_s *pcfg = &port->port_cfg;
1194 struct bfa_fcs_rport_s *rport;
1196 bfa_trc(port->fcs, pcfg->pwwn);
1199 * If our PWWN is > than that of the r-port, we have to initiate PLOGI
1200 * and assign an Address. if not, we need to wait for its PLOGI.
1202 * If our PWWN is < than that of the remote port, it will send a PLOGI
1203 * with the PIDs assigned. The rport state machine take care of this
1204 * incoming PLOGI.
1206 if (memcmp
1207 ((void *)&pcfg->pwwn, (void *)&n2n_port->rem_port_wwn,
1208 sizeof(wwn_t)) > 0) {
1209 port->pid = N2N_LOCAL_PID;
1210 bfa_lps_set_n2n_pid(port->fabric->lps, N2N_LOCAL_PID);
1212 * First, check if we know the device by pwwn.
1214 rport = bfa_fcs_lport_get_rport_by_pwwn(port,
1215 n2n_port->rem_port_wwn);
1216 if (rport) {
1217 bfa_trc(port->fcs, rport->pid);
1218 bfa_trc(port->fcs, rport->pwwn);
1219 rport->pid = N2N_REMOTE_PID;
1220 bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_SEND);
1221 return;
1225 * In n2n there can be only one rport. Delete the old one
1226 * whose pid should be zero, because it is offline.
1228 if (port->num_rports > 0) {
1229 rport = bfa_fcs_lport_get_rport_by_pid(port, 0);
1230 WARN_ON(rport == NULL);
1231 if (rport) {
1232 bfa_trc(port->fcs, rport->pwwn);
1233 bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
1236 bfa_fcs_rport_create(port, N2N_REMOTE_PID);
1241 * Called by fcs/port to notify transition to offline state.
1243 static void
1244 bfa_fcs_lport_n2n_offline(struct bfa_fcs_lport_s *port)
1246 struct bfa_fcs_lport_n2n_s *n2n_port = &port->port_topo.pn2n;
1248 bfa_trc(port->fcs, port->pid);
1249 port->pid = 0;
1250 n2n_port->rem_port_wwn = 0;
1251 n2n_port->reply_oxid = 0;
1254 static void
1255 bfa_fcport_get_loop_attr(struct bfa_fcs_lport_s *port)
1257 int i = 0, j = 0, bit = 0, alpa_bit = 0;
1258 u8 k = 0;
1259 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(port->fcs->bfa);
1261 port->port_topo.ploop.alpabm_valid = fcport->alpabm_valid;
1262 port->pid = fcport->myalpa;
1263 port->pid = bfa_hton3b(port->pid);
1265 for (i = 0; i < (FC_ALPA_MAX / 8); i++) {
1266 for (j = 0, alpa_bit = 0; j < 8; j++, alpa_bit++) {
1267 bfa_trc(port->fcs->bfa, fcport->alpabm.alpa_bm[i]);
1268 bit = (fcport->alpabm.alpa_bm[i] & (1 << (7 - j)));
1269 if (bit) {
1270 port->port_topo.ploop.alpa_pos_map[k] =
1271 loop_alpa_map[(i * 8) + alpa_bit];
1272 k++;
1273 bfa_trc(port->fcs->bfa, k);
1274 bfa_trc(port->fcs->bfa,
1275 port->port_topo.ploop.alpa_pos_map[k]);
1279 port->port_topo.ploop.num_alpa = k;
1283 * Called by fcs/port to initialize Loop topology.
1285 static void
1286 bfa_fcs_lport_loop_init(struct bfa_fcs_lport_s *port)
1291 * Called by fcs/port to notify transition to online state.
1293 static void
1294 bfa_fcs_lport_loop_online(struct bfa_fcs_lport_s *port)
1296 u8 num_alpa = 0, alpabm_valid = 0;
1297 struct bfa_fcs_rport_s *rport;
1298 u8 *alpa_map = NULL;
1299 int i = 0;
1300 u32 pid;
1302 bfa_fcport_get_loop_attr(port);
1304 num_alpa = port->port_topo.ploop.num_alpa;
1305 alpabm_valid = port->port_topo.ploop.alpabm_valid;
1306 alpa_map = port->port_topo.ploop.alpa_pos_map;
1308 bfa_trc(port->fcs->bfa, port->pid);
1309 bfa_trc(port->fcs->bfa, num_alpa);
1310 if (alpabm_valid == 1) {
1311 for (i = 0; i < num_alpa; i++) {
1312 bfa_trc(port->fcs->bfa, alpa_map[i]);
1313 if (alpa_map[i] != bfa_hton3b(port->pid)) {
1314 pid = alpa_map[i];
1315 bfa_trc(port->fcs->bfa, pid);
1316 rport = bfa_fcs_lport_get_rport_by_pid(port,
1317 bfa_hton3b(pid));
1318 if (!rport)
1319 rport = bfa_fcs_rport_create(port,
1320 bfa_hton3b(pid));
1323 } else {
1324 for (i = 0; i < MAX_ALPA_COUNT; i++) {
1325 if (alpa_map[i] != port->pid) {
1326 pid = loop_alpa_map[i];
1327 bfa_trc(port->fcs->bfa, pid);
1328 rport = bfa_fcs_lport_get_rport_by_pid(port,
1329 bfa_hton3b(pid));
1330 if (!rport)
1331 rport = bfa_fcs_rport_create(port,
1332 bfa_hton3b(pid));
1339 * Called by fcs/port to notify transition to offline state.
1341 static void
1342 bfa_fcs_lport_loop_offline(struct bfa_fcs_lport_s *port)
1346 #define BFA_FCS_FDMI_CMD_MAX_RETRIES 2
1349 * forward declarations
1351 static void bfa_fcs_lport_fdmi_send_rhba(void *fdmi_cbarg,
1352 struct bfa_fcxp_s *fcxp_alloced);
1353 static void bfa_fcs_lport_fdmi_send_rprt(void *fdmi_cbarg,
1354 struct bfa_fcxp_s *fcxp_alloced);
1355 static void bfa_fcs_lport_fdmi_send_rpa(void *fdmi_cbarg,
1356 struct bfa_fcxp_s *fcxp_alloced);
1357 static void bfa_fcs_lport_fdmi_rhba_response(void *fcsarg,
1358 struct bfa_fcxp_s *fcxp,
1359 void *cbarg,
1360 bfa_status_t req_status,
1361 u32 rsp_len,
1362 u32 resid_len,
1363 struct fchs_s *rsp_fchs);
1364 static void bfa_fcs_lport_fdmi_rprt_response(void *fcsarg,
1365 struct bfa_fcxp_s *fcxp,
1366 void *cbarg,
1367 bfa_status_t req_status,
1368 u32 rsp_len,
1369 u32 resid_len,
1370 struct fchs_s *rsp_fchs);
1371 static void bfa_fcs_lport_fdmi_rpa_response(void *fcsarg,
1372 struct bfa_fcxp_s *fcxp,
1373 void *cbarg,
1374 bfa_status_t req_status,
1375 u32 rsp_len,
1376 u32 resid_len,
1377 struct fchs_s *rsp_fchs);
1378 static void bfa_fcs_lport_fdmi_timeout(void *arg);
1379 static int bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s *fdmi,
1380 u8 *pyld);
1381 static u16 bfa_fcs_lport_fdmi_build_rprt_pyld(struct bfa_fcs_lport_fdmi_s *fdmi,
1382 u8 *pyld);
1383 static u16 bfa_fcs_lport_fdmi_build_rpa_pyld(struct bfa_fcs_lport_fdmi_s *fdmi,
1384 u8 *pyld);
1385 static u16 bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s *
1386 fdmi, u8 *pyld);
1387 static void bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s *fdmi,
1388 struct bfa_fcs_fdmi_hba_attr_s *hba_attr);
1389 static void bfa_fcs_fdmi_get_portattr(struct bfa_fcs_lport_fdmi_s *fdmi,
1390 struct bfa_fcs_fdmi_port_attr_s *port_attr);
1391 u32 bfa_fcs_fdmi_convert_speed(enum bfa_port_speed pport_speed);
1394 * fcs_fdmi_sm FCS FDMI state machine
1397 static void bfa_fcs_lport_fdmi_sm_offline(struct bfa_fcs_lport_fdmi_s *fdmi,
1398 enum port_fdmi_event event);
1399 static void bfa_fcs_lport_fdmi_sm_sending_rhba(
1400 struct bfa_fcs_lport_fdmi_s *fdmi,
1401 enum port_fdmi_event event);
1402 static void bfa_fcs_lport_fdmi_sm_rhba(struct bfa_fcs_lport_fdmi_s *fdmi,
1403 enum port_fdmi_event event);
1404 static void bfa_fcs_lport_fdmi_sm_rhba_retry(
1405 struct bfa_fcs_lport_fdmi_s *fdmi,
1406 enum port_fdmi_event event);
1407 static void bfa_fcs_lport_fdmi_sm_sending_rprt(
1408 struct bfa_fcs_lport_fdmi_s *fdmi,
1409 enum port_fdmi_event event);
1410 static void bfa_fcs_lport_fdmi_sm_rprt(struct bfa_fcs_lport_fdmi_s *fdmi,
1411 enum port_fdmi_event event);
1412 static void bfa_fcs_lport_fdmi_sm_rprt_retry(
1413 struct bfa_fcs_lport_fdmi_s *fdmi,
1414 enum port_fdmi_event event);
1415 static void bfa_fcs_lport_fdmi_sm_sending_rpa(
1416 struct bfa_fcs_lport_fdmi_s *fdmi,
1417 enum port_fdmi_event event);
1418 static void bfa_fcs_lport_fdmi_sm_rpa(struct bfa_fcs_lport_fdmi_s *fdmi,
1419 enum port_fdmi_event event);
1420 static void bfa_fcs_lport_fdmi_sm_rpa_retry(
1421 struct bfa_fcs_lport_fdmi_s *fdmi,
1422 enum port_fdmi_event event);
1423 static void bfa_fcs_lport_fdmi_sm_online(struct bfa_fcs_lport_fdmi_s *fdmi,
1424 enum port_fdmi_event event);
1425 static void bfa_fcs_lport_fdmi_sm_disabled(
1426 struct bfa_fcs_lport_fdmi_s *fdmi,
1427 enum port_fdmi_event event);
1429 * Start in offline state - awaiting MS to send start.
1431 static void
1432 bfa_fcs_lport_fdmi_sm_offline(struct bfa_fcs_lport_fdmi_s *fdmi,
1433 enum port_fdmi_event event)
1435 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1437 bfa_trc(port->fcs, port->port_cfg.pwwn);
1438 bfa_trc(port->fcs, event);
1440 fdmi->retry_cnt = 0;
1442 switch (event) {
1443 case FDMISM_EVENT_PORT_ONLINE:
1444 if (port->vport) {
1446 * For Vports, register a new port.
1448 bfa_sm_set_state(fdmi,
1449 bfa_fcs_lport_fdmi_sm_sending_rprt);
1450 bfa_fcs_lport_fdmi_send_rprt(fdmi, NULL);
1451 } else {
1453 * For a base port, we should first register the HBA
1454 * attribute. The HBA attribute also contains the base
1455 * port registration.
1457 bfa_sm_set_state(fdmi,
1458 bfa_fcs_lport_fdmi_sm_sending_rhba);
1459 bfa_fcs_lport_fdmi_send_rhba(fdmi, NULL);
1461 break;
1463 case FDMISM_EVENT_PORT_OFFLINE:
1464 break;
1466 default:
1467 bfa_sm_fault(port->fcs, event);
1471 static void
1472 bfa_fcs_lport_fdmi_sm_sending_rhba(struct bfa_fcs_lport_fdmi_s *fdmi,
1473 enum port_fdmi_event event)
1475 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1477 bfa_trc(port->fcs, port->port_cfg.pwwn);
1478 bfa_trc(port->fcs, event);
1480 switch (event) {
1481 case FDMISM_EVENT_RHBA_SENT:
1482 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rhba);
1483 break;
1485 case FDMISM_EVENT_PORT_OFFLINE:
1486 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1487 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
1488 &fdmi->fcxp_wqe);
1489 break;
1491 default:
1492 bfa_sm_fault(port->fcs, event);
1496 static void
1497 bfa_fcs_lport_fdmi_sm_rhba(struct bfa_fcs_lport_fdmi_s *fdmi,
1498 enum port_fdmi_event event)
1500 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1502 bfa_trc(port->fcs, port->port_cfg.pwwn);
1503 bfa_trc(port->fcs, event);
1505 switch (event) {
1506 case FDMISM_EVENT_RSP_ERROR:
1508 * if max retries have not been reached, start timer for a
1509 * delayed retry
1511 if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
1512 bfa_sm_set_state(fdmi,
1513 bfa_fcs_lport_fdmi_sm_rhba_retry);
1514 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
1515 &fdmi->timer,
1516 bfa_fcs_lport_fdmi_timeout, fdmi,
1517 BFA_FCS_RETRY_TIMEOUT);
1518 } else {
1520 * set state to offline
1522 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1524 break;
1526 case FDMISM_EVENT_RSP_OK:
1528 * Initiate Register Port Attributes
1530 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rpa);
1531 fdmi->retry_cnt = 0;
1532 bfa_fcs_lport_fdmi_send_rpa(fdmi, NULL);
1533 break;
1535 case FDMISM_EVENT_PORT_OFFLINE:
1536 bfa_fcxp_discard(fdmi->fcxp);
1537 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1538 break;
1540 default:
1541 bfa_sm_fault(port->fcs, event);
1545 static void
1546 bfa_fcs_lport_fdmi_sm_rhba_retry(struct bfa_fcs_lport_fdmi_s *fdmi,
1547 enum port_fdmi_event event)
1549 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1551 bfa_trc(port->fcs, port->port_cfg.pwwn);
1552 bfa_trc(port->fcs, event);
1554 switch (event) {
1555 case FDMISM_EVENT_TIMEOUT:
1557 * Retry Timer Expired. Re-send
1559 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rhba);
1560 bfa_fcs_lport_fdmi_send_rhba(fdmi, NULL);
1561 break;
1563 case FDMISM_EVENT_PORT_OFFLINE:
1564 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1565 bfa_timer_stop(&fdmi->timer);
1566 break;
1568 default:
1569 bfa_sm_fault(port->fcs, event);
1574 * RPRT : Register Port
1576 static void
1577 bfa_fcs_lport_fdmi_sm_sending_rprt(struct bfa_fcs_lport_fdmi_s *fdmi,
1578 enum port_fdmi_event event)
1580 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1582 bfa_trc(port->fcs, port->port_cfg.pwwn);
1583 bfa_trc(port->fcs, event);
1585 switch (event) {
1586 case FDMISM_EVENT_RPRT_SENT:
1587 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rprt);
1588 break;
1590 case FDMISM_EVENT_PORT_OFFLINE:
1591 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1592 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
1593 &fdmi->fcxp_wqe);
1594 break;
1596 default:
1597 bfa_sm_fault(port->fcs, event);
1601 static void
1602 bfa_fcs_lport_fdmi_sm_rprt(struct bfa_fcs_lport_fdmi_s *fdmi,
1603 enum port_fdmi_event event)
1605 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1607 bfa_trc(port->fcs, port->port_cfg.pwwn);
1608 bfa_trc(port->fcs, event);
1610 switch (event) {
1611 case FDMISM_EVENT_RSP_ERROR:
1613 * if max retries have not been reached, start timer for a
1614 * delayed retry
1616 if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
1617 bfa_sm_set_state(fdmi,
1618 bfa_fcs_lport_fdmi_sm_rprt_retry);
1619 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
1620 &fdmi->timer,
1621 bfa_fcs_lport_fdmi_timeout, fdmi,
1622 BFA_FCS_RETRY_TIMEOUT);
1624 } else {
1626 * set state to offline
1628 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1629 fdmi->retry_cnt = 0;
1631 break;
1633 case FDMISM_EVENT_RSP_OK:
1634 fdmi->retry_cnt = 0;
1635 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_online);
1636 break;
1638 case FDMISM_EVENT_PORT_OFFLINE:
1639 bfa_fcxp_discard(fdmi->fcxp);
1640 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1641 break;
1643 default:
1644 bfa_sm_fault(port->fcs, event);
1648 static void
1649 bfa_fcs_lport_fdmi_sm_rprt_retry(struct bfa_fcs_lport_fdmi_s *fdmi,
1650 enum port_fdmi_event event)
1652 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1654 bfa_trc(port->fcs, port->port_cfg.pwwn);
1655 bfa_trc(port->fcs, event);
1657 switch (event) {
1658 case FDMISM_EVENT_TIMEOUT:
1660 * Retry Timer Expired. Re-send
1662 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rprt);
1663 bfa_fcs_lport_fdmi_send_rprt(fdmi, NULL);
1664 break;
1666 case FDMISM_EVENT_PORT_OFFLINE:
1667 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1668 bfa_timer_stop(&fdmi->timer);
1669 break;
1671 default:
1672 bfa_sm_fault(port->fcs, event);
1677 * Register Port Attributes
1679 static void
1680 bfa_fcs_lport_fdmi_sm_sending_rpa(struct bfa_fcs_lport_fdmi_s *fdmi,
1681 enum port_fdmi_event event)
1683 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1685 bfa_trc(port->fcs, port->port_cfg.pwwn);
1686 bfa_trc(port->fcs, event);
1688 switch (event) {
1689 case FDMISM_EVENT_RPA_SENT:
1690 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rpa);
1691 break;
1693 case FDMISM_EVENT_PORT_OFFLINE:
1694 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1695 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
1696 &fdmi->fcxp_wqe);
1697 break;
1699 default:
1700 bfa_sm_fault(port->fcs, event);
1704 static void
1705 bfa_fcs_lport_fdmi_sm_rpa(struct bfa_fcs_lport_fdmi_s *fdmi,
1706 enum port_fdmi_event event)
1708 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1710 bfa_trc(port->fcs, port->port_cfg.pwwn);
1711 bfa_trc(port->fcs, event);
1713 switch (event) {
1714 case FDMISM_EVENT_RSP_ERROR:
1716 * if max retries have not been reached, start timer for a
1717 * delayed retry
1719 if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
1720 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_rpa_retry);
1721 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
1722 &fdmi->timer,
1723 bfa_fcs_lport_fdmi_timeout, fdmi,
1724 BFA_FCS_RETRY_TIMEOUT);
1725 } else {
1727 * set state to offline
1729 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1730 fdmi->retry_cnt = 0;
1732 break;
1734 case FDMISM_EVENT_RSP_OK:
1735 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_online);
1736 fdmi->retry_cnt = 0;
1737 break;
1739 case FDMISM_EVENT_PORT_OFFLINE:
1740 bfa_fcxp_discard(fdmi->fcxp);
1741 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1742 break;
1744 default:
1745 bfa_sm_fault(port->fcs, event);
1749 static void
1750 bfa_fcs_lport_fdmi_sm_rpa_retry(struct bfa_fcs_lport_fdmi_s *fdmi,
1751 enum port_fdmi_event event)
1753 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1755 bfa_trc(port->fcs, port->port_cfg.pwwn);
1756 bfa_trc(port->fcs, event);
1758 switch (event) {
1759 case FDMISM_EVENT_TIMEOUT:
1761 * Retry Timer Expired. Re-send
1763 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_sending_rpa);
1764 bfa_fcs_lport_fdmi_send_rpa(fdmi, NULL);
1765 break;
1767 case FDMISM_EVENT_PORT_OFFLINE:
1768 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1769 bfa_timer_stop(&fdmi->timer);
1770 break;
1772 default:
1773 bfa_sm_fault(port->fcs, event);
1777 static void
1778 bfa_fcs_lport_fdmi_sm_online(struct bfa_fcs_lport_fdmi_s *fdmi,
1779 enum port_fdmi_event event)
1781 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1783 bfa_trc(port->fcs, port->port_cfg.pwwn);
1784 bfa_trc(port->fcs, event);
1786 switch (event) {
1787 case FDMISM_EVENT_PORT_OFFLINE:
1788 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
1789 break;
1791 default:
1792 bfa_sm_fault(port->fcs, event);
1796 * FDMI is disabled state.
1798 static void
1799 bfa_fcs_lport_fdmi_sm_disabled(struct bfa_fcs_lport_fdmi_s *fdmi,
1800 enum port_fdmi_event event)
1802 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1804 bfa_trc(port->fcs, port->port_cfg.pwwn);
1805 bfa_trc(port->fcs, event);
1807 /* No op State. It can only be enabled at Driver Init. */
1811 * RHBA : Register HBA Attributes.
1813 static void
1814 bfa_fcs_lport_fdmi_send_rhba(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
1816 struct bfa_fcs_lport_fdmi_s *fdmi = fdmi_cbarg;
1817 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1818 struct fchs_s fchs;
1819 int len, attr_len;
1820 struct bfa_fcxp_s *fcxp;
1821 u8 *pyld;
1823 bfa_trc(port->fcs, port->port_cfg.pwwn);
1825 fcxp = fcxp_alloced ? fcxp_alloced :
1826 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
1827 if (!fcxp) {
1828 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
1829 bfa_fcs_lport_fdmi_send_rhba, fdmi, BFA_TRUE);
1830 return;
1832 fdmi->fcxp = fcxp;
1834 pyld = bfa_fcxp_get_reqbuf(fcxp);
1835 memset(pyld, 0, FC_MAX_PDUSZ);
1837 len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
1838 FDMI_RHBA);
1840 attr_len =
1841 bfa_fcs_lport_fdmi_build_rhba_pyld(fdmi,
1842 (u8 *) ((struct ct_hdr_s *) pyld
1843 + 1));
1844 if (attr_len < 0)
1845 return;
1847 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
1848 FC_CLASS_3, (len + attr_len), &fchs,
1849 bfa_fcs_lport_fdmi_rhba_response, (void *)fdmi,
1850 FC_MAX_PDUSZ, FC_FCCT_TOV);
1852 bfa_sm_send_event(fdmi, FDMISM_EVENT_RHBA_SENT);
1855 static int
1856 bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
1858 struct bfa_fcs_lport_s *port = fdmi->ms->port;
1859 struct bfa_fcs_fdmi_hba_attr_s *fcs_hba_attr;
1860 struct fdmi_rhba_s *rhba = (struct fdmi_rhba_s *) pyld;
1861 struct fdmi_attr_s *attr;
1862 int len;
1863 u8 *curr_ptr;
1864 u16 templen, count;
1866 fcs_hba_attr = kzalloc(sizeof(*fcs_hba_attr), GFP_KERNEL);
1867 if (!fcs_hba_attr)
1868 return -ENOMEM;
1871 * get hba attributes
1873 bfa_fcs_fdmi_get_hbaattr(fdmi, fcs_hba_attr);
1875 rhba->hba_id = bfa_fcs_lport_get_pwwn(port);
1876 rhba->port_list.num_ports = cpu_to_be32(1);
1877 rhba->port_list.port_entry = bfa_fcs_lport_get_pwwn(port);
1879 len = sizeof(rhba->hba_id) + sizeof(rhba->port_list);
1881 count = 0;
1882 len += sizeof(rhba->hba_attr_blk.attr_count);
1885 * fill out the invididual entries of the HBA attrib Block
1887 curr_ptr = (u8 *) &rhba->hba_attr_blk.hba_attr;
1890 * Node Name
1892 attr = (struct fdmi_attr_s *) curr_ptr;
1893 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_NODENAME);
1894 templen = sizeof(wwn_t);
1895 memcpy(attr->value, &bfa_fcs_lport_get_nwwn(port), templen);
1896 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1897 len += templen;
1898 count++;
1899 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1900 sizeof(templen));
1903 * Manufacturer
1905 attr = (struct fdmi_attr_s *) curr_ptr;
1906 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MANUFACTURER);
1907 templen = (u16) strlen(fcs_hba_attr->manufacturer);
1908 memcpy(attr->value, fcs_hba_attr->manufacturer, templen);
1909 templen = fc_roundup(templen, sizeof(u32));
1910 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1911 len += templen;
1912 count++;
1913 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1914 sizeof(templen));
1917 * Serial Number
1919 attr = (struct fdmi_attr_s *) curr_ptr;
1920 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_SERIALNUM);
1921 templen = (u16) strlen(fcs_hba_attr->serial_num);
1922 memcpy(attr->value, fcs_hba_attr->serial_num, templen);
1923 templen = fc_roundup(templen, sizeof(u32));
1924 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1925 len += templen;
1926 count++;
1927 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1928 sizeof(templen));
1931 * Model
1933 attr = (struct fdmi_attr_s *) curr_ptr;
1934 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MODEL);
1935 templen = (u16) strlen(fcs_hba_attr->model);
1936 memcpy(attr->value, fcs_hba_attr->model, templen);
1937 templen = fc_roundup(templen, sizeof(u32));
1938 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1939 len += templen;
1940 count++;
1941 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1942 sizeof(templen));
1945 * Model Desc
1947 attr = (struct fdmi_attr_s *) curr_ptr;
1948 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MODEL_DESC);
1949 templen = (u16) strlen(fcs_hba_attr->model_desc);
1950 memcpy(attr->value, fcs_hba_attr->model_desc, templen);
1951 templen = fc_roundup(templen, sizeof(u32));
1952 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1953 len += templen;
1954 count++;
1955 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1956 sizeof(templen));
1959 * H/W Version
1961 if (fcs_hba_attr->hw_version[0] != '\0') {
1962 attr = (struct fdmi_attr_s *) curr_ptr;
1963 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_HW_VERSION);
1964 templen = (u16) strlen(fcs_hba_attr->hw_version);
1965 memcpy(attr->value, fcs_hba_attr->hw_version, templen);
1966 templen = fc_roundup(templen, sizeof(u32));
1967 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1968 len += templen;
1969 count++;
1970 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1971 sizeof(templen));
1975 * Driver Version
1977 attr = (struct fdmi_attr_s *) curr_ptr;
1978 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_DRIVER_VERSION);
1979 templen = (u16) strlen(fcs_hba_attr->driver_version);
1980 memcpy(attr->value, fcs_hba_attr->driver_version, templen);
1981 templen = fc_roundup(templen, sizeof(u32));
1982 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1983 len += templen;
1984 count++;
1985 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
1986 sizeof(templen));
1989 * Option Rom Version
1991 if (fcs_hba_attr->option_rom_ver[0] != '\0') {
1992 attr = (struct fdmi_attr_s *) curr_ptr;
1993 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_ROM_VERSION);
1994 templen = (u16) strlen(fcs_hba_attr->option_rom_ver);
1995 memcpy(attr->value, fcs_hba_attr->option_rom_ver, templen);
1996 templen = fc_roundup(templen, sizeof(u32));
1997 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
1998 len += templen;
1999 count++;
2000 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2001 sizeof(templen));
2004 attr = (struct fdmi_attr_s *) curr_ptr;
2005 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_FW_VERSION);
2006 templen = (u16) strlen(fcs_hba_attr->fw_version);
2007 memcpy(attr->value, fcs_hba_attr->fw_version, templen);
2008 templen = fc_roundup(templen, sizeof(u32));
2009 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2010 len += templen;
2011 count++;
2012 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2013 sizeof(templen));
2016 * OS Name
2018 if (fcs_hba_attr->os_name[0] != '\0') {
2019 attr = (struct fdmi_attr_s *) curr_ptr;
2020 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_OS_NAME);
2021 templen = (u16) strlen(fcs_hba_attr->os_name);
2022 memcpy(attr->value, fcs_hba_attr->os_name, templen);
2023 templen = fc_roundup(templen, sizeof(u32));
2024 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2025 len += templen;
2026 count++;
2027 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2028 sizeof(templen));
2032 * MAX_CT_PAYLOAD
2034 attr = (struct fdmi_attr_s *) curr_ptr;
2035 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_MAX_CT);
2036 templen = sizeof(fcs_hba_attr->max_ct_pyld);
2037 memcpy(attr->value, &fcs_hba_attr->max_ct_pyld, templen);
2038 templen = fc_roundup(templen, sizeof(u32));
2039 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2040 len += templen;
2041 count++;
2042 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2043 sizeof(templen));
2045 * Send extended attributes ( FOS 7.1 support )
2047 if (fdmi->retry_cnt == 0) {
2048 attr = (struct fdmi_attr_s *) curr_ptr;
2049 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_NODE_SYM_NAME);
2050 templen = sizeof(fcs_hba_attr->node_sym_name);
2051 memcpy(attr->value, &fcs_hba_attr->node_sym_name, templen);
2052 templen = fc_roundup(templen, sizeof(u32));
2053 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2054 len += templen;
2055 count++;
2056 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2057 sizeof(templen));
2059 attr = (struct fdmi_attr_s *) curr_ptr;
2060 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_VENDOR_ID);
2061 templen = sizeof(fcs_hba_attr->vendor_info);
2062 memcpy(attr->value, &fcs_hba_attr->vendor_info, templen);
2063 templen = fc_roundup(templen, sizeof(u32));
2064 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2065 len += templen;
2066 count++;
2067 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2068 sizeof(templen));
2070 attr = (struct fdmi_attr_s *) curr_ptr;
2071 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_NUM_PORTS);
2072 templen = sizeof(fcs_hba_attr->num_ports);
2073 memcpy(attr->value, &fcs_hba_attr->num_ports, templen);
2074 templen = fc_roundup(templen, sizeof(u32));
2075 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2076 len += templen;
2077 count++;
2078 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2079 sizeof(templen));
2081 attr = (struct fdmi_attr_s *) curr_ptr;
2082 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_FABRIC_NAME);
2083 templen = sizeof(fcs_hba_attr->fabric_name);
2084 memcpy(attr->value, &fcs_hba_attr->fabric_name, templen);
2085 templen = fc_roundup(templen, sizeof(u32));
2086 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2087 len += templen;
2088 count++;
2089 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2090 sizeof(templen));
2092 attr = (struct fdmi_attr_s *) curr_ptr;
2093 attr->type = cpu_to_be16(FDMI_HBA_ATTRIB_BIOS_VER);
2094 templen = sizeof(fcs_hba_attr->bios_ver);
2095 memcpy(attr->value, &fcs_hba_attr->bios_ver, templen);
2096 templen = fc_roundup(attr->len, sizeof(u32));
2097 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2098 len += templen;
2099 count++;
2100 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2101 sizeof(templen));
2105 * Update size of payload
2107 len += ((sizeof(attr->type) + sizeof(attr->len)) * count);
2109 rhba->hba_attr_blk.attr_count = cpu_to_be32(count);
2111 kfree(fcs_hba_attr);
2113 return len;
2116 static void
2117 bfa_fcs_lport_fdmi_rhba_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
2118 void *cbarg, bfa_status_t req_status,
2119 u32 rsp_len, u32 resid_len,
2120 struct fchs_s *rsp_fchs)
2122 struct bfa_fcs_lport_fdmi_s *fdmi =
2123 (struct bfa_fcs_lport_fdmi_s *) cbarg;
2124 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2125 struct ct_hdr_s *cthdr = NULL;
2127 bfa_trc(port->fcs, port->port_cfg.pwwn);
2130 * Sanity Checks
2132 if (req_status != BFA_STATUS_OK) {
2133 bfa_trc(port->fcs, req_status);
2134 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2135 return;
2138 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
2139 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
2141 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
2142 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
2143 return;
2146 bfa_trc(port->fcs, cthdr->reason_code);
2147 bfa_trc(port->fcs, cthdr->exp_code);
2148 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2152 * RPRT : Register Port
2154 static void
2155 bfa_fcs_lport_fdmi_send_rprt(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
2157 struct bfa_fcs_lport_fdmi_s *fdmi = fdmi_cbarg;
2158 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2159 struct fchs_s fchs;
2160 u16 len, attr_len;
2161 struct bfa_fcxp_s *fcxp;
2162 u8 *pyld;
2164 bfa_trc(port->fcs, port->port_cfg.pwwn);
2166 fcxp = fcxp_alloced ? fcxp_alloced :
2167 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
2168 if (!fcxp) {
2169 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
2170 bfa_fcs_lport_fdmi_send_rprt, fdmi, BFA_TRUE);
2171 return;
2173 fdmi->fcxp = fcxp;
2175 pyld = bfa_fcxp_get_reqbuf(fcxp);
2176 memset(pyld, 0, FC_MAX_PDUSZ);
2178 len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
2179 FDMI_RPRT);
2181 attr_len =
2182 bfa_fcs_lport_fdmi_build_rprt_pyld(fdmi,
2183 (u8 *) ((struct ct_hdr_s *) pyld
2184 + 1));
2186 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
2187 FC_CLASS_3, len + attr_len, &fchs,
2188 bfa_fcs_lport_fdmi_rprt_response, (void *)fdmi,
2189 FC_MAX_PDUSZ, FC_FCCT_TOV);
2191 bfa_sm_send_event(fdmi, FDMISM_EVENT_RPRT_SENT);
2195 * This routine builds Port Attribute Block that used in RPA, RPRT commands.
2197 static u16
2198 bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s *fdmi,
2199 u8 *pyld)
2201 struct bfa_fcs_fdmi_port_attr_s fcs_port_attr;
2202 struct fdmi_port_attr_s *port_attrib = (struct fdmi_port_attr_s *) pyld;
2203 struct fdmi_attr_s *attr;
2204 u8 *curr_ptr;
2205 u16 len;
2206 u8 count = 0;
2207 u16 templen;
2210 * get port attributes
2212 bfa_fcs_fdmi_get_portattr(fdmi, &fcs_port_attr);
2214 len = sizeof(port_attrib->attr_count);
2217 * fill out the invididual entries
2219 curr_ptr = (u8 *) &port_attrib->port_attr;
2222 * FC4 Types
2224 attr = (struct fdmi_attr_s *) curr_ptr;
2225 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_FC4_TYPES);
2226 templen = sizeof(fcs_port_attr.supp_fc4_types);
2227 memcpy(attr->value, fcs_port_attr.supp_fc4_types, templen);
2228 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2229 len += templen;
2230 ++count;
2231 attr->len =
2232 cpu_to_be16(templen + sizeof(attr->type) +
2233 sizeof(templen));
2236 * Supported Speed
2238 attr = (struct fdmi_attr_s *) curr_ptr;
2239 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_SUPP_SPEED);
2240 templen = sizeof(fcs_port_attr.supp_speed);
2241 memcpy(attr->value, &fcs_port_attr.supp_speed, templen);
2242 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2243 len += templen;
2244 ++count;
2245 attr->len =
2246 cpu_to_be16(templen + sizeof(attr->type) +
2247 sizeof(templen));
2250 * current Port Speed
2252 attr = (struct fdmi_attr_s *) curr_ptr;
2253 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_SPEED);
2254 templen = sizeof(fcs_port_attr.curr_speed);
2255 memcpy(attr->value, &fcs_port_attr.curr_speed, templen);
2256 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2257 len += templen;
2258 ++count;
2259 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2260 sizeof(templen));
2263 * max frame size
2265 attr = (struct fdmi_attr_s *) curr_ptr;
2266 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_FRAME_SIZE);
2267 templen = sizeof(fcs_port_attr.max_frm_size);
2268 memcpy(attr->value, &fcs_port_attr.max_frm_size, templen);
2269 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2270 len += templen;
2271 ++count;
2272 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2273 sizeof(templen));
2276 * OS Device Name
2278 if (fcs_port_attr.os_device_name[0] != '\0') {
2279 attr = (struct fdmi_attr_s *) curr_ptr;
2280 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_DEV_NAME);
2281 templen = (u16) strlen(fcs_port_attr.os_device_name);
2282 memcpy(attr->value, fcs_port_attr.os_device_name, templen);
2283 templen = fc_roundup(templen, sizeof(u32));
2284 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2285 len += templen;
2286 ++count;
2287 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2288 sizeof(templen));
2291 * Host Name
2293 if (fcs_port_attr.host_name[0] != '\0') {
2294 attr = (struct fdmi_attr_s *) curr_ptr;
2295 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_HOST_NAME);
2296 templen = (u16) strlen(fcs_port_attr.host_name);
2297 memcpy(attr->value, fcs_port_attr.host_name, templen);
2298 templen = fc_roundup(templen, sizeof(u32));
2299 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2300 len += templen;
2301 ++count;
2302 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2303 sizeof(templen));
2306 if (fdmi->retry_cnt == 0) {
2307 attr = (struct fdmi_attr_s *) curr_ptr;
2308 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_NODE_NAME);
2309 templen = sizeof(fcs_port_attr.node_name);
2310 memcpy(attr->value, &fcs_port_attr.node_name, templen);
2311 templen = fc_roundup(templen, sizeof(u32));
2312 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2313 len += templen;
2314 ++count;
2315 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2316 sizeof(templen));
2318 attr = (struct fdmi_attr_s *) curr_ptr;
2319 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_NAME);
2320 templen = sizeof(fcs_port_attr.port_name);
2321 memcpy(attr->value, &fcs_port_attr.port_name, templen);
2322 templen = fc_roundup(templen, sizeof(u32));
2323 curr_ptr += sizeof(attr->type) + sizeof(attr->len) + templen;
2324 len += templen;
2325 ++count;
2326 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2327 sizeof(templen));
2329 if (fcs_port_attr.port_sym_name.symname[0] != '\0') {
2330 attr = (struct fdmi_attr_s *) curr_ptr;
2331 attr->type =
2332 cpu_to_be16(FDMI_PORT_ATTRIB_PORT_SYM_NAME);
2333 templen = sizeof(fcs_port_attr.port_sym_name);
2334 memcpy(attr->value,
2335 &fcs_port_attr.port_sym_name, templen);
2336 templen = fc_roundup(templen, sizeof(u32));
2337 curr_ptr += sizeof(attr->type) +
2338 sizeof(templen) + templen;
2339 len += templen;
2340 ++count;
2341 attr->len = cpu_to_be16(templen +
2342 sizeof(attr->type) + sizeof(templen));
2345 attr = (struct fdmi_attr_s *) curr_ptr;
2346 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_TYPE);
2347 templen = sizeof(fcs_port_attr.port_type);
2348 memcpy(attr->value, &fcs_port_attr.port_type, templen);
2349 templen = fc_roundup(templen, sizeof(u32));
2350 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2351 len += templen;
2352 ++count;
2353 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2354 sizeof(templen));
2356 attr = (struct fdmi_attr_s *) curr_ptr;
2357 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_SUPP_COS);
2358 templen = sizeof(fcs_port_attr.scos);
2359 memcpy(attr->value, &fcs_port_attr.scos, templen);
2360 templen = fc_roundup(templen, sizeof(u32));
2361 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2362 len += templen;
2363 ++count;
2364 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2365 sizeof(templen));
2367 attr = (struct fdmi_attr_s *) curr_ptr;
2368 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_FAB_NAME);
2369 templen = sizeof(fcs_port_attr.port_fabric_name);
2370 memcpy(attr->value, &fcs_port_attr.port_fabric_name, templen);
2371 templen = fc_roundup(templen, sizeof(u32));
2372 curr_ptr += sizeof(attr->type) + sizeof(templen) + templen;
2373 len += templen;
2374 ++count;
2375 attr->len = cpu_to_be16(templen + sizeof(attr->type) +
2376 sizeof(templen));
2378 attr = (struct fdmi_attr_s *) curr_ptr;
2379 attr->type = cpu_to_be16(FDMI_PORT_ATTRIB_PORT_FC4_TYPE);
2380 templen = sizeof(fcs_port_attr.port_act_fc4_type);
2381 memcpy(attr->value, fcs_port_attr.port_act_fc4_type,
2382 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_PORT_STATE);
2392 templen = sizeof(fcs_port_attr.port_state);
2393 memcpy(attr->value, &fcs_port_attr.port_state, 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_NUM_RPRT);
2403 templen = sizeof(fcs_port_attr.num_ports);
2404 memcpy(attr->value, &fcs_port_attr.num_ports, 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));
2414 * Update size of payload
2416 port_attrib->attr_count = cpu_to_be32(count);
2417 len += ((sizeof(attr->type) + sizeof(attr->len)) * count);
2418 return len;
2421 static u16
2422 bfa_fcs_lport_fdmi_build_rprt_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
2424 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2425 struct fdmi_rprt_s *rprt = (struct fdmi_rprt_s *) pyld;
2426 u16 len;
2428 rprt->hba_id = bfa_fcs_lport_get_pwwn(bfa_fcs_get_base_port(port->fcs));
2429 rprt->port_name = bfa_fcs_lport_get_pwwn(port);
2431 len = bfa_fcs_lport_fdmi_build_portattr_block(fdmi,
2432 (u8 *) &rprt->port_attr_blk);
2434 len += sizeof(rprt->hba_id) + sizeof(rprt->port_name);
2436 return len;
2439 static void
2440 bfa_fcs_lport_fdmi_rprt_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
2441 void *cbarg, bfa_status_t req_status,
2442 u32 rsp_len, u32 resid_len,
2443 struct fchs_s *rsp_fchs)
2445 struct bfa_fcs_lport_fdmi_s *fdmi =
2446 (struct bfa_fcs_lport_fdmi_s *) cbarg;
2447 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2448 struct ct_hdr_s *cthdr = NULL;
2450 bfa_trc(port->fcs, port->port_cfg.pwwn);
2453 * Sanity Checks
2455 if (req_status != BFA_STATUS_OK) {
2456 bfa_trc(port->fcs, req_status);
2457 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2458 return;
2461 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
2462 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
2464 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
2465 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
2466 return;
2469 bfa_trc(port->fcs, cthdr->reason_code);
2470 bfa_trc(port->fcs, cthdr->exp_code);
2471 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2475 * RPA : Register Port Attributes.
2477 static void
2478 bfa_fcs_lport_fdmi_send_rpa(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
2480 struct bfa_fcs_lport_fdmi_s *fdmi = fdmi_cbarg;
2481 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2482 struct fchs_s fchs;
2483 u16 len, attr_len;
2484 struct bfa_fcxp_s *fcxp;
2485 u8 *pyld;
2487 bfa_trc(port->fcs, port->port_cfg.pwwn);
2489 fcxp = fcxp_alloced ? fcxp_alloced :
2490 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
2491 if (!fcxp) {
2492 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
2493 bfa_fcs_lport_fdmi_send_rpa, fdmi, BFA_TRUE);
2494 return;
2496 fdmi->fcxp = fcxp;
2498 pyld = bfa_fcxp_get_reqbuf(fcxp);
2499 memset(pyld, 0, FC_MAX_PDUSZ);
2501 len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_lport_get_fcid(port),
2502 FDMI_RPA);
2504 attr_len = bfa_fcs_lport_fdmi_build_rpa_pyld(fdmi,
2505 (u8 *) ((struct ct_hdr_s *) pyld + 1));
2507 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
2508 FC_CLASS_3, len + attr_len, &fchs,
2509 bfa_fcs_lport_fdmi_rpa_response, (void *)fdmi,
2510 FC_MAX_PDUSZ, FC_FCCT_TOV);
2512 bfa_sm_send_event(fdmi, FDMISM_EVENT_RPA_SENT);
2515 static u16
2516 bfa_fcs_lport_fdmi_build_rpa_pyld(struct bfa_fcs_lport_fdmi_s *fdmi, u8 *pyld)
2518 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2519 struct fdmi_rpa_s *rpa = (struct fdmi_rpa_s *) pyld;
2520 u16 len;
2522 rpa->port_name = bfa_fcs_lport_get_pwwn(port);
2524 len = bfa_fcs_lport_fdmi_build_portattr_block(fdmi,
2525 (u8 *) &rpa->port_attr_blk);
2527 len += sizeof(rpa->port_name);
2529 return len;
2532 static void
2533 bfa_fcs_lport_fdmi_rpa_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
2534 void *cbarg, bfa_status_t req_status, u32 rsp_len,
2535 u32 resid_len, struct fchs_s *rsp_fchs)
2537 struct bfa_fcs_lport_fdmi_s *fdmi =
2538 (struct bfa_fcs_lport_fdmi_s *) cbarg;
2539 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2540 struct ct_hdr_s *cthdr = NULL;
2542 bfa_trc(port->fcs, port->port_cfg.pwwn);
2545 * Sanity Checks
2547 if (req_status != BFA_STATUS_OK) {
2548 bfa_trc(port->fcs, req_status);
2549 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2550 return;
2553 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
2554 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
2556 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
2557 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
2558 return;
2561 bfa_trc(port->fcs, cthdr->reason_code);
2562 bfa_trc(port->fcs, cthdr->exp_code);
2563 bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
2566 static void
2567 bfa_fcs_lport_fdmi_timeout(void *arg)
2569 struct bfa_fcs_lport_fdmi_s *fdmi = (struct bfa_fcs_lport_fdmi_s *) arg;
2571 bfa_sm_send_event(fdmi, FDMISM_EVENT_TIMEOUT);
2574 static void
2575 bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s *fdmi,
2576 struct bfa_fcs_fdmi_hba_attr_s *hba_attr)
2578 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2579 struct bfa_fcs_driver_info_s *driver_info = &port->fcs->driver_info;
2580 struct bfa_fcs_fdmi_port_attr_s fcs_port_attr;
2582 memset(hba_attr, 0, sizeof(struct bfa_fcs_fdmi_hba_attr_s));
2584 bfa_ioc_get_adapter_manufacturer(&port->fcs->bfa->ioc,
2585 hba_attr->manufacturer);
2586 bfa_ioc_get_adapter_serial_num(&port->fcs->bfa->ioc,
2587 hba_attr->serial_num);
2588 bfa_ioc_get_adapter_model(&port->fcs->bfa->ioc,
2589 hba_attr->model);
2590 bfa_ioc_get_adapter_model(&port->fcs->bfa->ioc,
2591 hba_attr->model_desc);
2592 bfa_ioc_get_pci_chip_rev(&port->fcs->bfa->ioc,
2593 hba_attr->hw_version);
2594 bfa_ioc_get_adapter_optrom_ver(&port->fcs->bfa->ioc,
2595 hba_attr->option_rom_ver);
2596 bfa_ioc_get_adapter_fw_ver(&port->fcs->bfa->ioc,
2597 hba_attr->fw_version);
2599 strscpy(hba_attr->driver_version, (char *)driver_info->version,
2600 sizeof(hba_attr->driver_version));
2602 strscpy(hba_attr->os_name, driver_info->host_os_name,
2603 sizeof(hba_attr->os_name));
2606 * If there is a patch level, append it
2607 * to the os name along with a separator
2609 if (driver_info->host_os_patch[0] != '\0') {
2610 strlcat(hba_attr->os_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
2611 sizeof(hba_attr->os_name));
2612 strlcat(hba_attr->os_name, driver_info->host_os_patch,
2613 sizeof(hba_attr->os_name));
2616 /* Retrieve the max frame size from the port attr */
2617 bfa_fcs_fdmi_get_portattr(fdmi, &fcs_port_attr);
2618 hba_attr->max_ct_pyld = fcs_port_attr.max_frm_size;
2620 strscpy(hba_attr->node_sym_name.symname,
2621 port->port_cfg.node_sym_name.symname, BFA_SYMNAME_MAXLEN);
2622 strcpy(hba_attr->vendor_info, "QLogic");
2623 hba_attr->num_ports =
2624 cpu_to_be32(bfa_ioc_get_nports(&port->fcs->bfa->ioc));
2625 hba_attr->fabric_name = port->fabric->lps->pr_nwwn;
2626 strscpy(hba_attr->bios_ver, hba_attr->option_rom_ver, BFA_VERSION_LEN);
2630 static void
2631 bfa_fcs_fdmi_get_portattr(struct bfa_fcs_lport_fdmi_s *fdmi,
2632 struct bfa_fcs_fdmi_port_attr_s *port_attr)
2634 struct bfa_fcs_lport_s *port = fdmi->ms->port;
2635 struct bfa_fcs_driver_info_s *driver_info = &port->fcs->driver_info;
2636 struct bfa_port_attr_s pport_attr;
2637 struct bfa_lport_attr_s lport_attr;
2639 memset(port_attr, 0, sizeof(struct bfa_fcs_fdmi_port_attr_s));
2642 * get pport attributes from hal
2644 bfa_fcport_get_attr(port->fcs->bfa, &pport_attr);
2647 * get FC4 type Bitmask
2649 fc_get_fc4type_bitmask(FC_TYPE_FCP, port_attr->supp_fc4_types);
2652 * Supported Speeds
2654 switch (pport_attr.speed_supported) {
2655 case BFA_PORT_SPEED_16GBPS:
2656 port_attr->supp_speed =
2657 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_16G);
2658 break;
2660 case BFA_PORT_SPEED_10GBPS:
2661 port_attr->supp_speed =
2662 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_10G);
2663 break;
2665 case BFA_PORT_SPEED_8GBPS:
2666 port_attr->supp_speed =
2667 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_8G);
2668 break;
2670 case BFA_PORT_SPEED_4GBPS:
2671 port_attr->supp_speed =
2672 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_4G);
2673 break;
2675 default:
2676 bfa_sm_fault(port->fcs, pport_attr.speed_supported);
2680 * Current Speed
2682 port_attr->curr_speed = cpu_to_be32(
2683 bfa_fcs_fdmi_convert_speed(pport_attr.speed));
2686 * Max PDU Size.
2688 port_attr->max_frm_size = cpu_to_be32(pport_attr.pport_cfg.maxfrsize);
2691 * OS device Name
2693 strscpy(port_attr->os_device_name, driver_info->os_device_name,
2694 sizeof(port_attr->os_device_name));
2697 * Host name
2699 strscpy(port_attr->host_name, driver_info->host_machine_name,
2700 sizeof(port_attr->host_name));
2702 port_attr->node_name = bfa_fcs_lport_get_nwwn(port);
2703 port_attr->port_name = bfa_fcs_lport_get_pwwn(port);
2705 strscpy(port_attr->port_sym_name.symname,
2706 bfa_fcs_lport_get_psym_name(port).symname, BFA_SYMNAME_MAXLEN);
2707 bfa_fcs_lport_get_attr(port, &lport_attr);
2708 port_attr->port_type = cpu_to_be32(lport_attr.port_type);
2709 port_attr->scos = pport_attr.cos_supported;
2710 port_attr->port_fabric_name = port->fabric->lps->pr_nwwn;
2711 fc_get_fc4type_bitmask(FC_TYPE_FCP, port_attr->port_act_fc4_type);
2712 port_attr->port_state = cpu_to_be32(pport_attr.port_state);
2713 port_attr->num_ports = cpu_to_be32(port->num_rports);
2717 * Convert BFA speed to FDMI format.
2720 bfa_fcs_fdmi_convert_speed(bfa_port_speed_t pport_speed)
2722 u32 ret;
2724 switch (pport_speed) {
2725 case BFA_PORT_SPEED_1GBPS:
2726 case BFA_PORT_SPEED_2GBPS:
2727 ret = pport_speed;
2728 break;
2730 case BFA_PORT_SPEED_4GBPS:
2731 ret = FDMI_TRANS_SPEED_4G;
2732 break;
2734 case BFA_PORT_SPEED_8GBPS:
2735 ret = FDMI_TRANS_SPEED_8G;
2736 break;
2738 case BFA_PORT_SPEED_10GBPS:
2739 ret = FDMI_TRANS_SPEED_10G;
2740 break;
2742 case BFA_PORT_SPEED_16GBPS:
2743 ret = FDMI_TRANS_SPEED_16G;
2744 break;
2746 default:
2747 ret = FDMI_TRANS_SPEED_UNKNOWN;
2749 return ret;
2752 void
2753 bfa_fcs_lport_fdmi_init(struct bfa_fcs_lport_ms_s *ms)
2755 struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
2757 fdmi->ms = ms;
2758 if (ms->port->fcs->fdmi_enabled)
2759 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_offline);
2760 else
2761 bfa_sm_set_state(fdmi, bfa_fcs_lport_fdmi_sm_disabled);
2764 void
2765 bfa_fcs_lport_fdmi_offline(struct bfa_fcs_lport_ms_s *ms)
2767 struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
2769 fdmi->ms = ms;
2770 bfa_sm_send_event(fdmi, FDMISM_EVENT_PORT_OFFLINE);
2773 void
2774 bfa_fcs_lport_fdmi_online(struct bfa_fcs_lport_ms_s *ms)
2776 struct bfa_fcs_lport_fdmi_s *fdmi = &ms->fdmi;
2778 fdmi->ms = ms;
2779 bfa_sm_send_event(fdmi, FDMISM_EVENT_PORT_ONLINE);
2782 #define BFA_FCS_MS_CMD_MAX_RETRIES 2
2785 * forward declarations
2787 static void bfa_fcs_lport_ms_send_plogi(void *ms_cbarg,
2788 struct bfa_fcxp_s *fcxp_alloced);
2789 static void bfa_fcs_lport_ms_timeout(void *arg);
2790 static void bfa_fcs_lport_ms_plogi_response(void *fcsarg,
2791 struct bfa_fcxp_s *fcxp,
2792 void *cbarg,
2793 bfa_status_t req_status,
2794 u32 rsp_len,
2795 u32 resid_len,
2796 struct fchs_s *rsp_fchs);
2798 static void bfa_fcs_lport_ms_send_gmal(void *ms_cbarg,
2799 struct bfa_fcxp_s *fcxp_alloced);
2800 static void bfa_fcs_lport_ms_gmal_response(void *fcsarg,
2801 struct bfa_fcxp_s *fcxp,
2802 void *cbarg,
2803 bfa_status_t req_status,
2804 u32 rsp_len,
2805 u32 resid_len,
2806 struct fchs_s *rsp_fchs);
2807 static void bfa_fcs_lport_ms_send_gfn(void *ms_cbarg,
2808 struct bfa_fcxp_s *fcxp_alloced);
2809 static void bfa_fcs_lport_ms_gfn_response(void *fcsarg,
2810 struct bfa_fcxp_s *fcxp,
2811 void *cbarg,
2812 bfa_status_t req_status,
2813 u32 rsp_len,
2814 u32 resid_len,
2815 struct fchs_s *rsp_fchs);
2817 * fcs_ms_sm FCS MS state machine
2820 static void bfa_fcs_lport_ms_sm_offline(struct bfa_fcs_lport_ms_s *ms,
2821 enum port_ms_event event);
2822 static void bfa_fcs_lport_ms_sm_plogi_sending(struct bfa_fcs_lport_ms_s *ms,
2823 enum port_ms_event event);
2824 static void bfa_fcs_lport_ms_sm_plogi(struct bfa_fcs_lport_ms_s *ms,
2825 enum port_ms_event event);
2826 static void bfa_fcs_lport_ms_sm_plogi_retry(struct bfa_fcs_lport_ms_s *ms,
2827 enum port_ms_event event);
2828 static void bfa_fcs_lport_ms_sm_gmal_sending(struct bfa_fcs_lport_ms_s *ms,
2829 enum port_ms_event event);
2830 static void bfa_fcs_lport_ms_sm_gmal(struct bfa_fcs_lport_ms_s *ms,
2831 enum port_ms_event event);
2832 static void bfa_fcs_lport_ms_sm_gmal_retry(struct bfa_fcs_lport_ms_s *ms,
2833 enum port_ms_event event);
2834 static void bfa_fcs_lport_ms_sm_gfn_sending(struct bfa_fcs_lport_ms_s *ms,
2835 enum port_ms_event event);
2836 static void bfa_fcs_lport_ms_sm_gfn(struct bfa_fcs_lport_ms_s *ms,
2837 enum port_ms_event event);
2838 static void bfa_fcs_lport_ms_sm_gfn_retry(struct bfa_fcs_lport_ms_s *ms,
2839 enum port_ms_event event);
2840 static void bfa_fcs_lport_ms_sm_online(struct bfa_fcs_lport_ms_s *ms,
2841 enum port_ms_event event);
2843 * Start in offline state - awaiting NS to send start.
2845 static void
2846 bfa_fcs_lport_ms_sm_offline(struct bfa_fcs_lport_ms_s *ms,
2847 enum port_ms_event event)
2849 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2850 bfa_trc(ms->port->fcs, event);
2852 switch (event) {
2853 case MSSM_EVENT_PORT_ONLINE:
2854 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi_sending);
2855 bfa_fcs_lport_ms_send_plogi(ms, NULL);
2856 break;
2858 case MSSM_EVENT_PORT_OFFLINE:
2859 break;
2861 default:
2862 bfa_sm_fault(ms->port->fcs, event);
2866 static void
2867 bfa_fcs_lport_ms_sm_plogi_sending(struct bfa_fcs_lport_ms_s *ms,
2868 enum port_ms_event event)
2870 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2871 bfa_trc(ms->port->fcs, event);
2873 switch (event) {
2874 case MSSM_EVENT_FCXP_SENT:
2875 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi);
2876 break;
2878 case MSSM_EVENT_PORT_OFFLINE:
2879 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
2880 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
2881 &ms->fcxp_wqe);
2882 break;
2884 default:
2885 bfa_sm_fault(ms->port->fcs, event);
2889 static void
2890 bfa_fcs_lport_ms_sm_plogi(struct bfa_fcs_lport_ms_s *ms,
2891 enum port_ms_event event)
2893 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2894 bfa_trc(ms->port->fcs, event);
2896 switch (event) {
2897 case MSSM_EVENT_RSP_ERROR:
2899 * Start timer for a delayed retry
2901 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi_retry);
2902 ms->port->stats.ms_retries++;
2903 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
2904 &ms->timer, bfa_fcs_lport_ms_timeout, ms,
2905 BFA_FCS_RETRY_TIMEOUT);
2906 break;
2908 case MSSM_EVENT_RSP_OK:
2910 * since plogi is done, now invoke MS related sub-modules
2912 bfa_fcs_lport_fdmi_online(ms);
2915 * if this is a Vport, go to online state.
2917 if (ms->port->vport) {
2918 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_online);
2919 break;
2923 * For a base port we need to get the
2924 * switch's IP address.
2926 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal_sending);
2927 bfa_fcs_lport_ms_send_gmal(ms, NULL);
2928 break;
2930 case MSSM_EVENT_PORT_OFFLINE:
2931 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
2932 bfa_fcxp_discard(ms->fcxp);
2933 break;
2935 default:
2936 bfa_sm_fault(ms->port->fcs, event);
2940 static void
2941 bfa_fcs_lport_ms_sm_plogi_retry(struct bfa_fcs_lport_ms_s *ms,
2942 enum port_ms_event event)
2944 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2945 bfa_trc(ms->port->fcs, event);
2947 switch (event) {
2948 case MSSM_EVENT_TIMEOUT:
2950 * Retry Timer Expired. Re-send
2952 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_plogi_sending);
2953 bfa_fcs_lport_ms_send_plogi(ms, NULL);
2954 break;
2956 case MSSM_EVENT_PORT_OFFLINE:
2957 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
2958 bfa_timer_stop(&ms->timer);
2959 break;
2961 default:
2962 bfa_sm_fault(ms->port->fcs, event);
2966 static void
2967 bfa_fcs_lport_ms_sm_online(struct bfa_fcs_lport_ms_s *ms,
2968 enum port_ms_event event)
2970 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2971 bfa_trc(ms->port->fcs, event);
2973 switch (event) {
2974 case MSSM_EVENT_PORT_OFFLINE:
2975 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
2976 break;
2978 case MSSM_EVENT_PORT_FABRIC_RSCN:
2979 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
2980 ms->retry_cnt = 0;
2981 bfa_fcs_lport_ms_send_gfn(ms, NULL);
2982 break;
2984 default:
2985 bfa_sm_fault(ms->port->fcs, event);
2989 static void
2990 bfa_fcs_lport_ms_sm_gmal_sending(struct bfa_fcs_lport_ms_s *ms,
2991 enum port_ms_event event)
2993 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
2994 bfa_trc(ms->port->fcs, event);
2996 switch (event) {
2997 case MSSM_EVENT_FCXP_SENT:
2998 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal);
2999 break;
3001 case MSSM_EVENT_PORT_OFFLINE:
3002 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3003 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
3004 &ms->fcxp_wqe);
3005 break;
3007 default:
3008 bfa_sm_fault(ms->port->fcs, event);
3012 static void
3013 bfa_fcs_lport_ms_sm_gmal(struct bfa_fcs_lport_ms_s *ms,
3014 enum port_ms_event event)
3016 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3017 bfa_trc(ms->port->fcs, event);
3019 switch (event) {
3020 case MSSM_EVENT_RSP_ERROR:
3022 * Start timer for a delayed retry
3024 if (ms->retry_cnt++ < BFA_FCS_MS_CMD_MAX_RETRIES) {
3025 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal_retry);
3026 ms->port->stats.ms_retries++;
3027 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
3028 &ms->timer, bfa_fcs_lport_ms_timeout, ms,
3029 BFA_FCS_RETRY_TIMEOUT);
3030 } else {
3031 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
3032 bfa_fcs_lport_ms_send_gfn(ms, NULL);
3033 ms->retry_cnt = 0;
3035 break;
3037 case MSSM_EVENT_RSP_OK:
3038 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
3039 bfa_fcs_lport_ms_send_gfn(ms, NULL);
3040 break;
3042 case MSSM_EVENT_PORT_OFFLINE:
3043 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3044 bfa_fcxp_discard(ms->fcxp);
3045 break;
3047 default:
3048 bfa_sm_fault(ms->port->fcs, event);
3052 static void
3053 bfa_fcs_lport_ms_sm_gmal_retry(struct bfa_fcs_lport_ms_s *ms,
3054 enum port_ms_event event)
3056 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3057 bfa_trc(ms->port->fcs, event);
3059 switch (event) {
3060 case MSSM_EVENT_TIMEOUT:
3062 * Retry Timer Expired. Re-send
3064 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gmal_sending);
3065 bfa_fcs_lport_ms_send_gmal(ms, NULL);
3066 break;
3068 case MSSM_EVENT_PORT_OFFLINE:
3069 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3070 bfa_timer_stop(&ms->timer);
3071 break;
3073 default:
3074 bfa_sm_fault(ms->port->fcs, event);
3078 * ms_pvt MS local functions
3081 static void
3082 bfa_fcs_lport_ms_send_gmal(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
3084 struct bfa_fcs_lport_ms_s *ms = ms_cbarg;
3085 bfa_fcs_lport_t *port = ms->port;
3086 struct fchs_s fchs;
3087 int len;
3088 struct bfa_fcxp_s *fcxp;
3090 bfa_trc(port->fcs, port->pid);
3092 fcxp = fcxp_alloced ? fcxp_alloced :
3093 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
3094 if (!fcxp) {
3095 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
3096 bfa_fcs_lport_ms_send_gmal, ms, BFA_TRUE);
3097 return;
3099 ms->fcxp = fcxp;
3101 len = fc_gmal_req_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
3102 bfa_fcs_lport_get_fcid(port),
3103 port->fabric->lps->pr_nwwn);
3105 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
3106 FC_CLASS_3, len, &fchs,
3107 bfa_fcs_lport_ms_gmal_response, (void *)ms,
3108 FC_MAX_PDUSZ, FC_FCCT_TOV);
3110 bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
3113 static void
3114 bfa_fcs_lport_ms_gmal_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
3115 void *cbarg, bfa_status_t req_status,
3116 u32 rsp_len, u32 resid_len,
3117 struct fchs_s *rsp_fchs)
3119 struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) cbarg;
3120 bfa_fcs_lport_t *port = ms->port;
3121 struct ct_hdr_s *cthdr = NULL;
3122 struct fcgs_gmal_resp_s *gmal_resp;
3123 struct fcgs_gmal_entry_s *gmal_entry;
3124 u32 num_entries;
3125 u8 *rsp_str;
3127 bfa_trc(port->fcs, req_status);
3128 bfa_trc(port->fcs, port->port_cfg.pwwn);
3131 * Sanity Checks
3133 if (req_status != BFA_STATUS_OK) {
3134 bfa_trc(port->fcs, req_status);
3135 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3136 return;
3139 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
3140 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
3142 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
3143 gmal_resp = (struct fcgs_gmal_resp_s *)(cthdr + 1);
3145 num_entries = be32_to_cpu(gmal_resp->ms_len);
3146 if (num_entries == 0) {
3147 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3148 return;
3151 * The response could contain multiple Entries.
3152 * Entries for SNMP interface, etc.
3153 * We look for the entry with a telnet prefix.
3154 * First "http://" entry refers to IP addr
3157 gmal_entry = (struct fcgs_gmal_entry_s *)gmal_resp->ms_ma;
3158 while (num_entries > 0) {
3159 if (strncmp(gmal_entry->prefix,
3160 CT_GMAL_RESP_PREFIX_HTTP,
3161 sizeof(gmal_entry->prefix)) == 0) {
3164 * if the IP address is terminating with a '/',
3165 * remove it.
3166 * Byte 0 consists of the length of the string.
3168 rsp_str = &(gmal_entry->prefix[0]);
3169 if (rsp_str[gmal_entry->len-1] == '/')
3170 rsp_str[gmal_entry->len-1] = 0;
3172 /* copy IP Address to fabric */
3173 strscpy(bfa_fcs_lport_get_fabric_ipaddr(port),
3174 gmal_entry->ip_addr,
3175 BFA_FCS_FABRIC_IPADDR_SZ);
3176 break;
3177 } else {
3178 --num_entries;
3179 ++gmal_entry;
3183 bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
3184 return;
3187 bfa_trc(port->fcs, cthdr->reason_code);
3188 bfa_trc(port->fcs, cthdr->exp_code);
3189 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3192 static void
3193 bfa_fcs_lport_ms_sm_gfn_sending(struct bfa_fcs_lport_ms_s *ms,
3194 enum port_ms_event event)
3196 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3197 bfa_trc(ms->port->fcs, event);
3199 switch (event) {
3200 case MSSM_EVENT_FCXP_SENT:
3201 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn);
3202 break;
3204 case MSSM_EVENT_PORT_OFFLINE:
3205 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3206 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
3207 &ms->fcxp_wqe);
3208 break;
3210 default:
3211 bfa_sm_fault(ms->port->fcs, event);
3215 static void
3216 bfa_fcs_lport_ms_sm_gfn(struct bfa_fcs_lport_ms_s *ms,
3217 enum port_ms_event event)
3219 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3220 bfa_trc(ms->port->fcs, event);
3222 switch (event) {
3223 case MSSM_EVENT_RSP_ERROR:
3225 * Start timer for a delayed retry
3227 if (ms->retry_cnt++ < BFA_FCS_MS_CMD_MAX_RETRIES) {
3228 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_retry);
3229 ms->port->stats.ms_retries++;
3230 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
3231 &ms->timer, bfa_fcs_lport_ms_timeout, ms,
3232 BFA_FCS_RETRY_TIMEOUT);
3233 } else {
3234 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_online);
3235 ms->retry_cnt = 0;
3237 break;
3239 case MSSM_EVENT_RSP_OK:
3240 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_online);
3241 break;
3243 case MSSM_EVENT_PORT_OFFLINE:
3244 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3245 bfa_fcxp_discard(ms->fcxp);
3246 break;
3248 default:
3249 bfa_sm_fault(ms->port->fcs, event);
3253 static void
3254 bfa_fcs_lport_ms_sm_gfn_retry(struct bfa_fcs_lport_ms_s *ms,
3255 enum port_ms_event event)
3257 bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
3258 bfa_trc(ms->port->fcs, event);
3260 switch (event) {
3261 case MSSM_EVENT_TIMEOUT:
3263 * Retry Timer Expired. Re-send
3265 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_gfn_sending);
3266 bfa_fcs_lport_ms_send_gfn(ms, NULL);
3267 break;
3269 case MSSM_EVENT_PORT_OFFLINE:
3270 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3271 bfa_timer_stop(&ms->timer);
3272 break;
3274 default:
3275 bfa_sm_fault(ms->port->fcs, event);
3279 * ms_pvt MS local functions
3282 static void
3283 bfa_fcs_lport_ms_send_gfn(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
3285 struct bfa_fcs_lport_ms_s *ms = ms_cbarg;
3286 bfa_fcs_lport_t *port = ms->port;
3287 struct fchs_s fchs;
3288 int len;
3289 struct bfa_fcxp_s *fcxp;
3291 bfa_trc(port->fcs, port->pid);
3293 fcxp = fcxp_alloced ? fcxp_alloced :
3294 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
3295 if (!fcxp) {
3296 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
3297 bfa_fcs_lport_ms_send_gfn, ms, BFA_TRUE);
3298 return;
3300 ms->fcxp = fcxp;
3302 len = fc_gfn_req_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
3303 bfa_fcs_lport_get_fcid(port),
3304 port->fabric->lps->pr_nwwn);
3306 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
3307 FC_CLASS_3, len, &fchs,
3308 bfa_fcs_lport_ms_gfn_response, (void *)ms,
3309 FC_MAX_PDUSZ, FC_FCCT_TOV);
3311 bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
3314 static void
3315 bfa_fcs_lport_ms_gfn_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
3316 void *cbarg, bfa_status_t req_status, u32 rsp_len,
3317 u32 resid_len, struct fchs_s *rsp_fchs)
3319 struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) cbarg;
3320 bfa_fcs_lport_t *port = ms->port;
3321 struct ct_hdr_s *cthdr = NULL;
3322 wwn_t *gfn_resp;
3324 bfa_trc(port->fcs, req_status);
3325 bfa_trc(port->fcs, port->port_cfg.pwwn);
3328 * Sanity Checks
3330 if (req_status != BFA_STATUS_OK) {
3331 bfa_trc(port->fcs, req_status);
3332 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3333 return;
3336 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
3337 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
3339 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
3340 gfn_resp = (wwn_t *)(cthdr + 1);
3341 /* check if it has actually changed */
3342 if ((memcmp((void *)&bfa_fcs_lport_get_fabric_name(port),
3343 gfn_resp, sizeof(wwn_t)) != 0)) {
3344 bfa_fcs_fabric_set_fabric_name(port->fabric, *gfn_resp);
3346 bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
3347 return;
3350 bfa_trc(port->fcs, cthdr->reason_code);
3351 bfa_trc(port->fcs, cthdr->exp_code);
3352 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3356 * ms_pvt MS local functions
3359 static void
3360 bfa_fcs_lport_ms_send_plogi(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
3362 struct bfa_fcs_lport_ms_s *ms = ms_cbarg;
3363 struct bfa_fcs_lport_s *port = ms->port;
3364 struct fchs_s fchs;
3365 int len;
3366 struct bfa_fcxp_s *fcxp;
3368 bfa_trc(port->fcs, port->pid);
3370 fcxp = fcxp_alloced ? fcxp_alloced :
3371 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
3372 if (!fcxp) {
3373 port->stats.ms_plogi_alloc_wait++;
3374 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
3375 bfa_fcs_lport_ms_send_plogi, ms, BFA_TRUE);
3376 return;
3378 ms->fcxp = fcxp;
3380 len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
3381 bfa_hton3b(FC_MGMT_SERVER),
3382 bfa_fcs_lport_get_fcid(port), 0,
3383 port->port_cfg.pwwn, port->port_cfg.nwwn,
3384 bfa_fcport_get_maxfrsize(port->fcs->bfa),
3385 bfa_fcport_get_rx_bbcredit(port->fcs->bfa));
3387 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
3388 FC_CLASS_3, len, &fchs,
3389 bfa_fcs_lport_ms_plogi_response, (void *)ms,
3390 FC_MAX_PDUSZ, FC_ELS_TOV);
3392 port->stats.ms_plogi_sent++;
3393 bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
3396 static void
3397 bfa_fcs_lport_ms_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
3398 void *cbarg, bfa_status_t req_status,
3399 u32 rsp_len, u32 resid_len, struct fchs_s *rsp_fchs)
3401 struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) cbarg;
3402 struct bfa_fcs_lport_s *port = ms->port;
3403 struct fc_els_cmd_s *els_cmd;
3404 struct fc_ls_rjt_s *ls_rjt;
3406 bfa_trc(port->fcs, req_status);
3407 bfa_trc(port->fcs, port->port_cfg.pwwn);
3410 * Sanity Checks
3412 if (req_status != BFA_STATUS_OK) {
3413 port->stats.ms_plogi_rsp_err++;
3414 bfa_trc(port->fcs, req_status);
3415 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3416 return;
3419 els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
3421 switch (els_cmd->els_code) {
3423 case FC_ELS_ACC:
3424 if (rsp_len < sizeof(struct fc_logi_s)) {
3425 bfa_trc(port->fcs, rsp_len);
3426 port->stats.ms_plogi_acc_err++;
3427 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3428 break;
3430 port->stats.ms_plogi_accepts++;
3431 bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
3432 break;
3434 case FC_ELS_LS_RJT:
3435 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
3437 bfa_trc(port->fcs, ls_rjt->reason_code);
3438 bfa_trc(port->fcs, ls_rjt->reason_code_expl);
3440 port->stats.ms_rejects++;
3441 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3442 break;
3444 default:
3445 port->stats.ms_plogi_unknown_rsp++;
3446 bfa_trc(port->fcs, els_cmd->els_code);
3447 bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
3451 static void
3452 bfa_fcs_lport_ms_timeout(void *arg)
3454 struct bfa_fcs_lport_ms_s *ms = (struct bfa_fcs_lport_ms_s *) arg;
3456 ms->port->stats.ms_timeouts++;
3457 bfa_sm_send_event(ms, MSSM_EVENT_TIMEOUT);
3461 void
3462 bfa_fcs_lport_ms_init(struct bfa_fcs_lport_s *port)
3464 struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
3466 ms->port = port;
3467 bfa_sm_set_state(ms, bfa_fcs_lport_ms_sm_offline);
3470 * Invoke init routines of sub modules.
3472 bfa_fcs_lport_fdmi_init(ms);
3475 void
3476 bfa_fcs_lport_ms_offline(struct bfa_fcs_lport_s *port)
3478 struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
3480 ms->port = port;
3481 bfa_sm_send_event(ms, MSSM_EVENT_PORT_OFFLINE);
3482 bfa_fcs_lport_fdmi_offline(ms);
3485 void
3486 bfa_fcs_lport_ms_online(struct bfa_fcs_lport_s *port)
3488 struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
3490 ms->port = port;
3491 bfa_sm_send_event(ms, MSSM_EVENT_PORT_ONLINE);
3493 void
3494 bfa_fcs_lport_ms_fabric_rscn(struct bfa_fcs_lport_s *port)
3496 struct bfa_fcs_lport_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
3498 /* todo. Handle this only when in Online state */
3499 if (bfa_sm_cmp_state(ms, bfa_fcs_lport_ms_sm_online))
3500 bfa_sm_send_event(ms, MSSM_EVENT_PORT_FABRIC_RSCN);
3504 * @page ns_sm_info VPORT NS State Machine
3506 * @section ns_sm_interactions VPORT NS State Machine Interactions
3508 * @section ns_sm VPORT NS State Machine
3509 * img ns_sm.jpg
3513 * forward declarations
3515 static void bfa_fcs_lport_ns_send_plogi(void *ns_cbarg,
3516 struct bfa_fcxp_s *fcxp_alloced);
3517 static void bfa_fcs_lport_ns_send_rspn_id(void *ns_cbarg,
3518 struct bfa_fcxp_s *fcxp_alloced);
3519 static void bfa_fcs_lport_ns_send_rft_id(void *ns_cbarg,
3520 struct bfa_fcxp_s *fcxp_alloced);
3521 static void bfa_fcs_lport_ns_send_rff_id(void *ns_cbarg,
3522 struct bfa_fcxp_s *fcxp_alloced);
3523 static void bfa_fcs_lport_ns_send_gid_ft(void *ns_cbarg,
3524 struct bfa_fcxp_s *fcxp_alloced);
3525 static void bfa_fcs_lport_ns_send_rnn_id(void *ns_cbarg,
3526 struct bfa_fcxp_s *fcxp_alloced);
3527 static void bfa_fcs_lport_ns_send_rsnn_nn(void *ns_cbarg,
3528 struct bfa_fcxp_s *fcxp_alloced);
3529 static void bfa_fcs_lport_ns_timeout(void *arg);
3530 static void bfa_fcs_lport_ns_plogi_response(void *fcsarg,
3531 struct bfa_fcxp_s *fcxp,
3532 void *cbarg,
3533 bfa_status_t req_status,
3534 u32 rsp_len,
3535 u32 resid_len,
3536 struct fchs_s *rsp_fchs);
3537 static void bfa_fcs_lport_ns_rspn_id_response(void *fcsarg,
3538 struct bfa_fcxp_s *fcxp,
3539 void *cbarg,
3540 bfa_status_t req_status,
3541 u32 rsp_len,
3542 u32 resid_len,
3543 struct fchs_s *rsp_fchs);
3544 static void bfa_fcs_lport_ns_rft_id_response(void *fcsarg,
3545 struct bfa_fcxp_s *fcxp,
3546 void *cbarg,
3547 bfa_status_t req_status,
3548 u32 rsp_len,
3549 u32 resid_len,
3550 struct fchs_s *rsp_fchs);
3551 static void bfa_fcs_lport_ns_rff_id_response(void *fcsarg,
3552 struct bfa_fcxp_s *fcxp,
3553 void *cbarg,
3554 bfa_status_t req_status,
3555 u32 rsp_len,
3556 u32 resid_len,
3557 struct fchs_s *rsp_fchs);
3558 static void bfa_fcs_lport_ns_gid_ft_response(void *fcsarg,
3559 struct bfa_fcxp_s *fcxp,
3560 void *cbarg,
3561 bfa_status_t req_status,
3562 u32 rsp_len,
3563 u32 resid_len,
3564 struct fchs_s *rsp_fchs);
3565 static void bfa_fcs_lport_ns_rnn_id_response(void *fcsarg,
3566 struct bfa_fcxp_s *fcxp,
3567 void *cbarg,
3568 bfa_status_t req_status,
3569 u32 rsp_len,
3570 u32 resid_len,
3571 struct fchs_s *rsp_fchs);
3572 static void bfa_fcs_lport_ns_rsnn_nn_response(void *fcsarg,
3573 struct bfa_fcxp_s *fcxp,
3574 void *cbarg,
3575 bfa_status_t req_status,
3576 u32 rsp_len,
3577 u32 resid_len,
3578 struct fchs_s *rsp_fchs);
3579 static void bfa_fcs_lport_ns_process_gidft_pids(
3580 struct bfa_fcs_lport_s *port,
3581 u32 *pid_buf, u32 n_pids);
3583 static void bfa_fcs_lport_ns_boot_target_disc(bfa_fcs_lport_t *port);
3585 * fcs_ns_sm FCS nameserver interface state machine
3588 static void bfa_fcs_lport_ns_sm_offline(struct bfa_fcs_lport_ns_s *ns,
3589 enum vport_ns_event event);
3590 static void bfa_fcs_lport_ns_sm_plogi_sending(struct bfa_fcs_lport_ns_s *ns,
3591 enum vport_ns_event event);
3592 static void bfa_fcs_lport_ns_sm_plogi(struct bfa_fcs_lport_ns_s *ns,
3593 enum vport_ns_event event);
3594 static void bfa_fcs_lport_ns_sm_plogi_retry(struct bfa_fcs_lport_ns_s *ns,
3595 enum vport_ns_event event);
3596 static void bfa_fcs_lport_ns_sm_sending_rspn_id(
3597 struct bfa_fcs_lport_ns_s *ns,
3598 enum vport_ns_event event);
3599 static void bfa_fcs_lport_ns_sm_rspn_id(struct bfa_fcs_lport_ns_s *ns,
3600 enum vport_ns_event event);
3601 static void bfa_fcs_lport_ns_sm_rspn_id_retry(struct bfa_fcs_lport_ns_s *ns,
3602 enum vport_ns_event event);
3603 static void bfa_fcs_lport_ns_sm_sending_rft_id(
3604 struct bfa_fcs_lport_ns_s *ns,
3605 enum vport_ns_event event);
3606 static void bfa_fcs_lport_ns_sm_rft_id_retry(struct bfa_fcs_lport_ns_s *ns,
3607 enum vport_ns_event event);
3608 static void bfa_fcs_lport_ns_sm_rft_id(struct bfa_fcs_lport_ns_s *ns,
3609 enum vport_ns_event event);
3610 static void bfa_fcs_lport_ns_sm_sending_rff_id(
3611 struct bfa_fcs_lport_ns_s *ns,
3612 enum vport_ns_event event);
3613 static void bfa_fcs_lport_ns_sm_rff_id_retry(struct bfa_fcs_lport_ns_s *ns,
3614 enum vport_ns_event event);
3615 static void bfa_fcs_lport_ns_sm_rff_id(struct bfa_fcs_lport_ns_s *ns,
3616 enum vport_ns_event event);
3617 static void bfa_fcs_lport_ns_sm_sending_gid_ft(
3618 struct bfa_fcs_lport_ns_s *ns,
3619 enum vport_ns_event event);
3620 static void bfa_fcs_lport_ns_sm_gid_ft(struct bfa_fcs_lport_ns_s *ns,
3621 enum vport_ns_event event);
3622 static void bfa_fcs_lport_ns_sm_gid_ft_retry(struct bfa_fcs_lport_ns_s *ns,
3623 enum vport_ns_event event);
3624 static void bfa_fcs_lport_ns_sm_online(struct bfa_fcs_lport_ns_s *ns,
3625 enum vport_ns_event event);
3626 static void bfa_fcs_lport_ns_sm_sending_rnn_id(
3627 struct bfa_fcs_lport_ns_s *ns,
3628 enum vport_ns_event event);
3629 static void bfa_fcs_lport_ns_sm_rnn_id(struct bfa_fcs_lport_ns_s *ns,
3630 enum vport_ns_event event);
3631 static void bfa_fcs_lport_ns_sm_rnn_id_retry(struct bfa_fcs_lport_ns_s *ns,
3632 enum vport_ns_event event);
3633 static void bfa_fcs_lport_ns_sm_sending_rsnn_nn(
3634 struct bfa_fcs_lport_ns_s *ns,
3635 enum vport_ns_event event);
3636 static void bfa_fcs_lport_ns_sm_rsnn_nn(struct bfa_fcs_lport_ns_s *ns,
3637 enum vport_ns_event event);
3638 static void bfa_fcs_lport_ns_sm_rsnn_nn_retry(
3639 struct bfa_fcs_lport_ns_s *ns,
3640 enum vport_ns_event event);
3642 * Start in offline state - awaiting linkup
3644 static void
3645 bfa_fcs_lport_ns_sm_offline(struct bfa_fcs_lport_ns_s *ns,
3646 enum vport_ns_event event)
3648 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3649 bfa_trc(ns->port->fcs, event);
3651 switch (event) {
3652 case NSSM_EVENT_PORT_ONLINE:
3653 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi_sending);
3654 bfa_fcs_lport_ns_send_plogi(ns, NULL);
3655 break;
3657 case NSSM_EVENT_PORT_OFFLINE:
3658 break;
3660 default:
3661 bfa_sm_fault(ns->port->fcs, event);
3665 static void
3666 bfa_fcs_lport_ns_sm_plogi_sending(struct bfa_fcs_lport_ns_s *ns,
3667 enum vport_ns_event event)
3669 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3670 bfa_trc(ns->port->fcs, event);
3672 switch (event) {
3673 case NSSM_EVENT_PLOGI_SENT:
3674 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi);
3675 break;
3677 case NSSM_EVENT_PORT_OFFLINE:
3678 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3679 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3680 &ns->fcxp_wqe);
3681 break;
3683 default:
3684 bfa_sm_fault(ns->port->fcs, event);
3688 static void
3689 bfa_fcs_lport_ns_sm_plogi(struct bfa_fcs_lport_ns_s *ns,
3690 enum vport_ns_event event)
3692 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3693 bfa_trc(ns->port->fcs, event);
3695 switch (event) {
3696 case NSSM_EVENT_RSP_ERROR:
3698 * Start timer for a delayed retry
3700 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi_retry);
3701 ns->port->stats.ns_retries++;
3702 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3703 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
3704 BFA_FCS_RETRY_TIMEOUT);
3705 break;
3707 case NSSM_EVENT_RSP_OK:
3708 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rnn_id);
3709 ns->num_rnnid_retries = 0;
3710 bfa_fcs_lport_ns_send_rnn_id(ns, NULL);
3711 break;
3713 case NSSM_EVENT_PORT_OFFLINE:
3714 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3715 bfa_fcxp_discard(ns->fcxp);
3716 break;
3718 default:
3719 bfa_sm_fault(ns->port->fcs, event);
3723 static void
3724 bfa_fcs_lport_ns_sm_plogi_retry(struct bfa_fcs_lport_ns_s *ns,
3725 enum vport_ns_event event)
3727 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3728 bfa_trc(ns->port->fcs, event);
3730 switch (event) {
3731 case NSSM_EVENT_TIMEOUT:
3733 * Retry Timer Expired. Re-send
3735 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_plogi_sending);
3736 bfa_fcs_lport_ns_send_plogi(ns, NULL);
3737 break;
3739 case NSSM_EVENT_PORT_OFFLINE:
3740 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3741 bfa_timer_stop(&ns->timer);
3742 break;
3744 default:
3745 bfa_sm_fault(ns->port->fcs, event);
3749 static void
3750 bfa_fcs_lport_ns_sm_sending_rnn_id(struct bfa_fcs_lport_ns_s *ns,
3751 enum vport_ns_event event)
3753 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3754 bfa_trc(ns->port->fcs, event);
3756 switch (event) {
3757 case NSSM_EVENT_RNNID_SENT:
3758 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rnn_id);
3759 break;
3761 case NSSM_EVENT_PORT_OFFLINE:
3762 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3763 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3764 &ns->fcxp_wqe);
3765 break;
3766 default:
3767 bfa_sm_fault(ns->port->fcs, event);
3771 static void
3772 bfa_fcs_lport_ns_sm_rnn_id(struct bfa_fcs_lport_ns_s *ns,
3773 enum vport_ns_event event)
3775 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3776 bfa_trc(ns->port->fcs, event);
3778 switch (event) {
3779 case NSSM_EVENT_RSP_OK:
3780 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rsnn_nn);
3781 ns->num_rnnid_retries = 0;
3782 ns->num_rsnn_nn_retries = 0;
3783 bfa_fcs_lport_ns_send_rsnn_nn(ns, NULL);
3784 break;
3786 case NSSM_EVENT_RSP_ERROR:
3787 if (ns->num_rnnid_retries < BFA_FCS_MAX_NS_RETRIES) {
3788 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rnn_id_retry);
3789 ns->port->stats.ns_retries++;
3790 ns->num_rnnid_retries++;
3791 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3792 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
3793 BFA_FCS_RETRY_TIMEOUT);
3794 } else {
3795 bfa_sm_set_state(ns,
3796 bfa_fcs_lport_ns_sm_sending_rspn_id);
3797 bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
3799 break;
3801 case NSSM_EVENT_PORT_OFFLINE:
3802 bfa_fcxp_discard(ns->fcxp);
3803 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3804 break;
3806 default:
3807 bfa_sm_fault(ns->port->fcs, event);
3811 static void
3812 bfa_fcs_lport_ns_sm_rnn_id_retry(struct bfa_fcs_lport_ns_s *ns,
3813 enum vport_ns_event event)
3815 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3816 bfa_trc(ns->port->fcs, event);
3818 switch (event) {
3819 case NSSM_EVENT_TIMEOUT:
3820 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rnn_id);
3821 bfa_fcs_lport_ns_send_rnn_id(ns, NULL);
3822 break;
3824 case NSSM_EVENT_PORT_OFFLINE:
3825 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3826 bfa_timer_stop(&ns->timer);
3827 break;
3829 default:
3830 bfa_sm_fault(ns->port->fcs, event);
3834 static void
3835 bfa_fcs_lport_ns_sm_sending_rsnn_nn(struct bfa_fcs_lport_ns_s *ns,
3836 enum vport_ns_event event)
3838 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3839 bfa_trc(ns->port->fcs, event);
3841 switch (event) {
3842 case NSSM_EVENT_RSNN_NN_SENT:
3843 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rsnn_nn);
3844 break;
3846 case NSSM_EVENT_PORT_OFFLINE:
3847 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3848 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3849 &ns->fcxp_wqe);
3850 break;
3852 default:
3853 bfa_sm_fault(ns->port->fcs, event);
3857 static void
3858 bfa_fcs_lport_ns_sm_rsnn_nn(struct bfa_fcs_lport_ns_s *ns,
3859 enum vport_ns_event event)
3861 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3862 bfa_trc(ns->port->fcs, event);
3864 switch (event) {
3865 case NSSM_EVENT_RSP_OK:
3866 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rspn_id);
3867 ns->num_rsnn_nn_retries = 0;
3868 bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
3869 break;
3871 case NSSM_EVENT_RSP_ERROR:
3872 if (ns->num_rsnn_nn_retries < BFA_FCS_MAX_NS_RETRIES) {
3873 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rsnn_nn_retry);
3874 ns->port->stats.ns_retries++;
3875 ns->num_rsnn_nn_retries++;
3876 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3877 &ns->timer, bfa_fcs_lport_ns_timeout,
3878 ns, BFA_FCS_RETRY_TIMEOUT);
3879 } else {
3880 bfa_sm_set_state(ns,
3881 bfa_fcs_lport_ns_sm_sending_rspn_id);
3882 bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
3884 break;
3886 case NSSM_EVENT_PORT_OFFLINE:
3887 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3888 bfa_fcxp_discard(ns->fcxp);
3889 break;
3891 default:
3892 bfa_sm_fault(ns->port->fcs, event);
3896 static void
3897 bfa_fcs_lport_ns_sm_rsnn_nn_retry(struct bfa_fcs_lport_ns_s *ns,
3898 enum vport_ns_event event)
3900 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3901 bfa_trc(ns->port->fcs, event);
3903 switch (event) {
3904 case NSSM_EVENT_TIMEOUT:
3905 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rsnn_nn);
3906 bfa_fcs_lport_ns_send_rsnn_nn(ns, NULL);
3907 break;
3909 case NSSM_EVENT_PORT_OFFLINE:
3910 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3911 bfa_timer_stop(&ns->timer);
3912 break;
3914 default:
3915 bfa_sm_fault(ns->port->fcs, event);
3919 static void
3920 bfa_fcs_lport_ns_sm_sending_rspn_id(struct bfa_fcs_lport_ns_s *ns,
3921 enum vport_ns_event event)
3923 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3924 bfa_trc(ns->port->fcs, event);
3926 switch (event) {
3927 case NSSM_EVENT_RSPNID_SENT:
3928 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rspn_id);
3929 break;
3931 case NSSM_EVENT_PORT_OFFLINE:
3932 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3933 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3934 &ns->fcxp_wqe);
3935 break;
3937 default:
3938 bfa_sm_fault(ns->port->fcs, event);
3942 static void
3943 bfa_fcs_lport_ns_sm_rspn_id(struct bfa_fcs_lport_ns_s *ns,
3944 enum vport_ns_event event)
3946 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3947 bfa_trc(ns->port->fcs, event);
3949 switch (event) {
3950 case NSSM_EVENT_RSP_ERROR:
3952 * Start timer for a delayed retry
3954 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rspn_id_retry);
3955 ns->port->stats.ns_retries++;
3956 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
3957 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
3958 BFA_FCS_RETRY_TIMEOUT);
3959 break;
3961 case NSSM_EVENT_RSP_OK:
3962 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rft_id);
3963 bfa_fcs_lport_ns_send_rft_id(ns, NULL);
3964 break;
3966 case NSSM_EVENT_PORT_OFFLINE:
3967 bfa_fcxp_discard(ns->fcxp);
3968 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3969 break;
3971 default:
3972 bfa_sm_fault(ns->port->fcs, event);
3976 static void
3977 bfa_fcs_lport_ns_sm_rspn_id_retry(struct bfa_fcs_lport_ns_s *ns,
3978 enum vport_ns_event event)
3980 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
3981 bfa_trc(ns->port->fcs, event);
3983 switch (event) {
3984 case NSSM_EVENT_TIMEOUT:
3986 * Retry Timer Expired. Re-send
3988 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rspn_id);
3989 bfa_fcs_lport_ns_send_rspn_id(ns, NULL);
3990 break;
3992 case NSSM_EVENT_PORT_OFFLINE:
3993 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
3994 bfa_timer_stop(&ns->timer);
3995 break;
3997 default:
3998 bfa_sm_fault(ns->port->fcs, event);
4002 static void
4003 bfa_fcs_lport_ns_sm_sending_rft_id(struct bfa_fcs_lport_ns_s *ns,
4004 enum vport_ns_event event)
4006 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4007 bfa_trc(ns->port->fcs, event);
4009 switch (event) {
4010 case NSSM_EVENT_RFTID_SENT:
4011 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rft_id);
4012 break;
4014 case NSSM_EVENT_PORT_OFFLINE:
4015 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4016 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4017 &ns->fcxp_wqe);
4018 break;
4020 default:
4021 bfa_sm_fault(ns->port->fcs, event);
4025 static void
4026 bfa_fcs_lport_ns_sm_rft_id(struct bfa_fcs_lport_ns_s *ns,
4027 enum vport_ns_event event)
4029 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4030 bfa_trc(ns->port->fcs, event);
4032 switch (event) {
4033 case NSSM_EVENT_RSP_OK:
4034 /* Now move to register FC4 Features */
4035 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rff_id);
4036 bfa_fcs_lport_ns_send_rff_id(ns, NULL);
4037 break;
4039 case NSSM_EVENT_RSP_ERROR:
4041 * Start timer for a delayed retry
4043 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rft_id_retry);
4044 ns->port->stats.ns_retries++;
4045 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4046 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
4047 BFA_FCS_RETRY_TIMEOUT);
4048 break;
4050 case NSSM_EVENT_PORT_OFFLINE:
4051 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4052 bfa_fcxp_discard(ns->fcxp);
4053 break;
4055 default:
4056 bfa_sm_fault(ns->port->fcs, event);
4060 static void
4061 bfa_fcs_lport_ns_sm_rft_id_retry(struct bfa_fcs_lport_ns_s *ns,
4062 enum vport_ns_event event)
4064 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4065 bfa_trc(ns->port->fcs, event);
4067 switch (event) {
4068 case NSSM_EVENT_TIMEOUT:
4069 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rft_id);
4070 bfa_fcs_lport_ns_send_rft_id(ns, NULL);
4071 break;
4073 case NSSM_EVENT_PORT_OFFLINE:
4074 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4075 bfa_timer_stop(&ns->timer);
4076 break;
4078 default:
4079 bfa_sm_fault(ns->port->fcs, event);
4083 static void
4084 bfa_fcs_lport_ns_sm_sending_rff_id(struct bfa_fcs_lport_ns_s *ns,
4085 enum vport_ns_event event)
4087 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4088 bfa_trc(ns->port->fcs, event);
4090 switch (event) {
4091 case NSSM_EVENT_RFFID_SENT:
4092 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rff_id);
4093 break;
4095 case NSSM_EVENT_PORT_OFFLINE:
4096 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4097 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4098 &ns->fcxp_wqe);
4099 break;
4101 default:
4102 bfa_sm_fault(ns->port->fcs, event);
4106 static void
4107 bfa_fcs_lport_ns_sm_rff_id(struct bfa_fcs_lport_ns_s *ns,
4108 enum vport_ns_event event)
4110 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4111 bfa_trc(ns->port->fcs, event);
4113 switch (event) {
4114 case NSSM_EVENT_RSP_OK:
4117 * If min cfg mode is enabled, we donot initiate rport
4118 * discovery with the fabric. Instead, we will retrieve the
4119 * boot targets from HAL/FW.
4121 if (__fcs_min_cfg(ns->port->fcs)) {
4122 bfa_fcs_lport_ns_boot_target_disc(ns->port);
4123 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_online);
4124 return;
4128 * If the port role is Initiator Mode issue NS query.
4129 * If it is Target Mode, skip this and go to online.
4131 if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns->port)) {
4132 bfa_sm_set_state(ns,
4133 bfa_fcs_lport_ns_sm_sending_gid_ft);
4134 bfa_fcs_lport_ns_send_gid_ft(ns, NULL);
4137 * kick off mgmt srvr state machine
4139 bfa_fcs_lport_ms_online(ns->port);
4140 break;
4142 case NSSM_EVENT_RSP_ERROR:
4144 * Start timer for a delayed retry
4146 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_rff_id_retry);
4147 ns->port->stats.ns_retries++;
4148 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4149 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
4150 BFA_FCS_RETRY_TIMEOUT);
4151 break;
4153 case NSSM_EVENT_PORT_OFFLINE:
4154 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4155 bfa_fcxp_discard(ns->fcxp);
4156 break;
4158 default:
4159 bfa_sm_fault(ns->port->fcs, event);
4163 static void
4164 bfa_fcs_lport_ns_sm_rff_id_retry(struct bfa_fcs_lport_ns_s *ns,
4165 enum vport_ns_event event)
4167 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4168 bfa_trc(ns->port->fcs, event);
4170 switch (event) {
4171 case NSSM_EVENT_TIMEOUT:
4172 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_rff_id);
4173 bfa_fcs_lport_ns_send_rff_id(ns, NULL);
4174 break;
4176 case NSSM_EVENT_PORT_OFFLINE:
4177 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4178 bfa_timer_stop(&ns->timer);
4179 break;
4181 default:
4182 bfa_sm_fault(ns->port->fcs, event);
4185 static void
4186 bfa_fcs_lport_ns_sm_sending_gid_ft(struct bfa_fcs_lport_ns_s *ns,
4187 enum vport_ns_event event)
4189 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4190 bfa_trc(ns->port->fcs, event);
4192 switch (event) {
4193 case NSSM_EVENT_GIDFT_SENT:
4194 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_gid_ft);
4195 break;
4197 case NSSM_EVENT_PORT_OFFLINE:
4198 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4199 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4200 &ns->fcxp_wqe);
4201 break;
4203 default:
4204 bfa_sm_fault(ns->port->fcs, event);
4208 static void
4209 bfa_fcs_lport_ns_sm_gid_ft(struct bfa_fcs_lport_ns_s *ns,
4210 enum vport_ns_event event)
4212 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4213 bfa_trc(ns->port->fcs, event);
4215 switch (event) {
4216 case NSSM_EVENT_RSP_OK:
4217 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_online);
4218 break;
4220 case NSSM_EVENT_RSP_ERROR:
4222 * TBD: for certain reject codes, we don't need to retry
4225 * Start timer for a delayed retry
4227 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_gid_ft_retry);
4228 ns->port->stats.ns_retries++;
4229 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns->port),
4230 &ns->timer, bfa_fcs_lport_ns_timeout, ns,
4231 BFA_FCS_RETRY_TIMEOUT);
4232 break;
4234 case NSSM_EVENT_PORT_OFFLINE:
4235 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4236 bfa_fcxp_discard(ns->fcxp);
4237 break;
4239 case NSSM_EVENT_NS_QUERY:
4240 break;
4242 default:
4243 bfa_sm_fault(ns->port->fcs, event);
4247 static void
4248 bfa_fcs_lport_ns_sm_gid_ft_retry(struct bfa_fcs_lport_ns_s *ns,
4249 enum vport_ns_event event)
4251 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4252 bfa_trc(ns->port->fcs, event);
4254 switch (event) {
4255 case NSSM_EVENT_TIMEOUT:
4256 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_sending_gid_ft);
4257 bfa_fcs_lport_ns_send_gid_ft(ns, NULL);
4258 break;
4260 case NSSM_EVENT_PORT_OFFLINE:
4261 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4262 bfa_timer_stop(&ns->timer);
4263 break;
4265 default:
4266 bfa_sm_fault(ns->port->fcs, event);
4270 static void
4271 bfa_fcs_lport_ns_sm_online(struct bfa_fcs_lport_ns_s *ns,
4272 enum vport_ns_event event)
4274 bfa_trc(ns->port->fcs, ns->port->port_cfg.pwwn);
4275 bfa_trc(ns->port->fcs, event);
4277 switch (event) {
4278 case NSSM_EVENT_PORT_OFFLINE:
4279 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
4280 break;
4282 case NSSM_EVENT_NS_QUERY:
4284 * If the port role is Initiator Mode issue NS query.
4285 * If it is Target Mode, skip this and go to online.
4287 if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns->port)) {
4288 bfa_sm_set_state(ns,
4289 bfa_fcs_lport_ns_sm_sending_gid_ft);
4290 bfa_fcs_lport_ns_send_gid_ft(ns, NULL);
4292 break;
4294 default:
4295 bfa_sm_fault(ns->port->fcs, event);
4302 * ns_pvt Nameserver local functions
4305 static void
4306 bfa_fcs_lport_ns_send_plogi(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4308 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4309 struct bfa_fcs_lport_s *port = ns->port;
4310 struct fchs_s fchs;
4311 int len;
4312 struct bfa_fcxp_s *fcxp;
4314 bfa_trc(port->fcs, port->pid);
4316 fcxp = fcxp_alloced ? fcxp_alloced :
4317 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4318 if (!fcxp) {
4319 port->stats.ns_plogi_alloc_wait++;
4320 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4321 bfa_fcs_lport_ns_send_plogi, ns, BFA_TRUE);
4322 return;
4324 ns->fcxp = fcxp;
4326 len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4327 bfa_hton3b(FC_NAME_SERVER),
4328 bfa_fcs_lport_get_fcid(port), 0,
4329 port->port_cfg.pwwn, port->port_cfg.nwwn,
4330 bfa_fcport_get_maxfrsize(port->fcs->bfa),
4331 bfa_fcport_get_rx_bbcredit(port->fcs->bfa));
4333 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4334 FC_CLASS_3, len, &fchs,
4335 bfa_fcs_lport_ns_plogi_response, (void *)ns,
4336 FC_MAX_PDUSZ, FC_ELS_TOV);
4337 port->stats.ns_plogi_sent++;
4339 bfa_sm_send_event(ns, NSSM_EVENT_PLOGI_SENT);
4342 static void
4343 bfa_fcs_lport_ns_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4344 void *cbarg, bfa_status_t req_status, u32 rsp_len,
4345 u32 resid_len, struct fchs_s *rsp_fchs)
4347 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4348 struct bfa_fcs_lport_s *port = ns->port;
4349 /* struct fc_logi_s *plogi_resp; */
4350 struct fc_els_cmd_s *els_cmd;
4351 struct fc_ls_rjt_s *ls_rjt;
4353 bfa_trc(port->fcs, req_status);
4354 bfa_trc(port->fcs, port->port_cfg.pwwn);
4357 * Sanity Checks
4359 if (req_status != BFA_STATUS_OK) {
4360 bfa_trc(port->fcs, req_status);
4361 port->stats.ns_plogi_rsp_err++;
4362 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4363 return;
4366 els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
4368 switch (els_cmd->els_code) {
4370 case FC_ELS_ACC:
4371 if (rsp_len < sizeof(struct fc_logi_s)) {
4372 bfa_trc(port->fcs, rsp_len);
4373 port->stats.ns_plogi_acc_err++;
4374 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4375 break;
4377 port->stats.ns_plogi_accepts++;
4378 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4379 break;
4381 case FC_ELS_LS_RJT:
4382 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
4384 bfa_trc(port->fcs, ls_rjt->reason_code);
4385 bfa_trc(port->fcs, ls_rjt->reason_code_expl);
4387 port->stats.ns_rejects++;
4389 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4390 break;
4392 default:
4393 port->stats.ns_plogi_unknown_rsp++;
4394 bfa_trc(port->fcs, els_cmd->els_code);
4395 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4400 * Register node name for port_id
4402 static void
4403 bfa_fcs_lport_ns_send_rnn_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4405 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4406 struct bfa_fcs_lport_s *port = ns->port;
4407 struct fchs_s fchs;
4408 int len;
4409 struct bfa_fcxp_s *fcxp;
4411 bfa_trc(port->fcs, port->port_cfg.pwwn);
4413 fcxp = fcxp_alloced ? fcxp_alloced :
4414 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4415 if (!fcxp) {
4416 port->stats.ns_rnnid_alloc_wait++;
4417 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4418 bfa_fcs_lport_ns_send_rnn_id, ns, BFA_TRUE);
4419 return;
4422 ns->fcxp = fcxp;
4424 len = fc_rnnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4425 bfa_fcs_lport_get_fcid(port),
4426 bfa_fcs_lport_get_fcid(port),
4427 bfa_fcs_lport_get_nwwn(port));
4429 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4430 FC_CLASS_3, len, &fchs,
4431 bfa_fcs_lport_ns_rnn_id_response, (void *)ns,
4432 FC_MAX_PDUSZ, FC_FCCT_TOV);
4434 port->stats.ns_rnnid_sent++;
4435 bfa_sm_send_event(ns, NSSM_EVENT_RNNID_SENT);
4438 static void
4439 bfa_fcs_lport_ns_rnn_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4440 void *cbarg, bfa_status_t req_status,
4441 u32 rsp_len, u32 resid_len,
4442 struct fchs_s *rsp_fchs)
4445 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4446 struct bfa_fcs_lport_s *port = ns->port;
4447 struct ct_hdr_s *cthdr = NULL;
4449 bfa_trc(port->fcs, port->port_cfg.pwwn);
4452 * Sanity Checks
4454 if (req_status != BFA_STATUS_OK) {
4455 bfa_trc(port->fcs, req_status);
4456 port->stats.ns_rnnid_rsp_err++;
4457 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4458 return;
4461 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4462 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4464 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4465 port->stats.ns_rnnid_accepts++;
4466 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4467 return;
4470 port->stats.ns_rnnid_rejects++;
4471 bfa_trc(port->fcs, cthdr->reason_code);
4472 bfa_trc(port->fcs, cthdr->exp_code);
4473 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4477 * Register the symbolic node name for a given node name.
4479 static void
4480 bfa_fcs_lport_ns_send_rsnn_nn(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4482 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4483 struct bfa_fcs_lport_s *port = ns->port;
4484 struct fchs_s fchs;
4485 int len;
4486 struct bfa_fcxp_s *fcxp;
4487 u8 *nsymbl;
4489 bfa_trc(port->fcs, port->port_cfg.pwwn);
4491 fcxp = fcxp_alloced ? fcxp_alloced :
4492 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4493 if (!fcxp) {
4494 port->stats.ns_rsnn_nn_alloc_wait++;
4495 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4496 bfa_fcs_lport_ns_send_rsnn_nn, ns, BFA_TRUE);
4497 return;
4499 ns->fcxp = fcxp;
4501 nsymbl = (u8 *) &(bfa_fcs_lport_get_nsym_name(
4502 bfa_fcs_get_base_port(port->fcs)));
4504 len = fc_rsnn_nn_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4505 bfa_fcs_lport_get_fcid(port),
4506 bfa_fcs_lport_get_nwwn(port), nsymbl);
4508 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4509 FC_CLASS_3, len, &fchs,
4510 bfa_fcs_lport_ns_rsnn_nn_response, (void *)ns,
4511 FC_MAX_PDUSZ, FC_FCCT_TOV);
4513 port->stats.ns_rsnn_nn_sent++;
4515 bfa_sm_send_event(ns, NSSM_EVENT_RSNN_NN_SENT);
4518 static void
4519 bfa_fcs_lport_ns_rsnn_nn_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4520 void *cbarg, bfa_status_t req_status,
4521 u32 rsp_len, u32 resid_len,
4522 struct fchs_s *rsp_fchs)
4524 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4525 struct bfa_fcs_lport_s *port = ns->port;
4526 struct ct_hdr_s *cthdr = NULL;
4528 bfa_trc(port->fcs, port->port_cfg.pwwn);
4531 * Sanity Checks
4533 if (req_status != BFA_STATUS_OK) {
4534 bfa_trc(port->fcs, req_status);
4535 port->stats.ns_rsnn_nn_rsp_err++;
4536 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4537 return;
4540 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4541 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4543 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4544 port->stats.ns_rsnn_nn_accepts++;
4545 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4546 return;
4549 port->stats.ns_rsnn_nn_rejects++;
4550 bfa_trc(port->fcs, cthdr->reason_code);
4551 bfa_trc(port->fcs, cthdr->exp_code);
4552 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4556 * Register the symbolic port name.
4558 static void
4559 bfa_fcs_lport_ns_send_rspn_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4561 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4562 struct bfa_fcs_lport_s *port = ns->port;
4563 struct fchs_s fchs;
4564 int len;
4565 struct bfa_fcxp_s *fcxp;
4566 u8 symbl[256];
4567 u8 *psymbl = &symbl[0];
4569 memset(symbl, 0, sizeof(symbl));
4571 bfa_trc(port->fcs, port->port_cfg.pwwn);
4573 fcxp = fcxp_alloced ? fcxp_alloced :
4574 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4575 if (!fcxp) {
4576 port->stats.ns_rspnid_alloc_wait++;
4577 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4578 bfa_fcs_lport_ns_send_rspn_id, ns, BFA_TRUE);
4579 return;
4581 ns->fcxp = fcxp;
4584 * for V-Port, form a Port Symbolic Name
4586 if (port->vport) {
4588 * For Vports, we append the vport's port symbolic name
4589 * to that of the base port.
4592 strscpy(symbl,
4593 (char *)&(bfa_fcs_lport_get_psym_name
4594 (bfa_fcs_get_base_port(port->fcs))),
4595 sizeof(symbl));
4597 strlcat(symbl, (char *)&(bfa_fcs_lport_get_psym_name(port)),
4598 sizeof(symbl));
4599 } else {
4600 psymbl = (u8 *) &(bfa_fcs_lport_get_psym_name(port));
4603 len = fc_rspnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4604 bfa_fcs_lport_get_fcid(port), 0, psymbl);
4606 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4607 FC_CLASS_3, len, &fchs,
4608 bfa_fcs_lport_ns_rspn_id_response, (void *)ns,
4609 FC_MAX_PDUSZ, FC_FCCT_TOV);
4611 port->stats.ns_rspnid_sent++;
4613 bfa_sm_send_event(ns, NSSM_EVENT_RSPNID_SENT);
4616 static void
4617 bfa_fcs_lport_ns_rspn_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4618 void *cbarg, bfa_status_t req_status,
4619 u32 rsp_len, u32 resid_len,
4620 struct fchs_s *rsp_fchs)
4622 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4623 struct bfa_fcs_lport_s *port = ns->port;
4624 struct ct_hdr_s *cthdr = NULL;
4626 bfa_trc(port->fcs, port->port_cfg.pwwn);
4629 * Sanity Checks
4631 if (req_status != BFA_STATUS_OK) {
4632 bfa_trc(port->fcs, req_status);
4633 port->stats.ns_rspnid_rsp_err++;
4634 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4635 return;
4638 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4639 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4641 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4642 port->stats.ns_rspnid_accepts++;
4643 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4644 return;
4647 port->stats.ns_rspnid_rejects++;
4648 bfa_trc(port->fcs, cthdr->reason_code);
4649 bfa_trc(port->fcs, cthdr->exp_code);
4650 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4654 * Register FC4-Types
4656 static void
4657 bfa_fcs_lport_ns_send_rft_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4659 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4660 struct bfa_fcs_lport_s *port = ns->port;
4661 struct fchs_s fchs;
4662 int len;
4663 struct bfa_fcxp_s *fcxp;
4665 bfa_trc(port->fcs, port->port_cfg.pwwn);
4667 fcxp = fcxp_alloced ? fcxp_alloced :
4668 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4669 if (!fcxp) {
4670 port->stats.ns_rftid_alloc_wait++;
4671 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4672 bfa_fcs_lport_ns_send_rft_id, ns, BFA_TRUE);
4673 return;
4675 ns->fcxp = fcxp;
4677 len = fc_rftid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4678 bfa_fcs_lport_get_fcid(port), 0, port->port_cfg.roles);
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_rft_id_response, (void *)ns,
4683 FC_MAX_PDUSZ, FC_FCCT_TOV);
4685 port->stats.ns_rftid_sent++;
4686 bfa_sm_send_event(ns, NSSM_EVENT_RFTID_SENT);
4689 static void
4690 bfa_fcs_lport_ns_rft_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4691 void *cbarg, bfa_status_t req_status,
4692 u32 rsp_len, u32 resid_len,
4693 struct fchs_s *rsp_fchs)
4695 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4696 struct bfa_fcs_lport_s *port = ns->port;
4697 struct ct_hdr_s *cthdr = NULL;
4699 bfa_trc(port->fcs, port->port_cfg.pwwn);
4702 * Sanity Checks
4704 if (req_status != BFA_STATUS_OK) {
4705 bfa_trc(port->fcs, req_status);
4706 port->stats.ns_rftid_rsp_err++;
4707 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4708 return;
4711 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4712 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4714 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4715 port->stats.ns_rftid_accepts++;
4716 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4717 return;
4720 port->stats.ns_rftid_rejects++;
4721 bfa_trc(port->fcs, cthdr->reason_code);
4722 bfa_trc(port->fcs, cthdr->exp_code);
4723 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4727 * Register FC4-Features : Should be done after RFT_ID
4729 static void
4730 bfa_fcs_lport_ns_send_rff_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4732 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4733 struct bfa_fcs_lport_s *port = ns->port;
4734 struct fchs_s fchs;
4735 int len;
4736 struct bfa_fcxp_s *fcxp;
4737 u8 fc4_ftrs = 0;
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_rffid_alloc_wait++;
4745 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4746 bfa_fcs_lport_ns_send_rff_id, ns, BFA_TRUE);
4747 return;
4749 ns->fcxp = fcxp;
4751 if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns->port))
4752 fc4_ftrs = FC_GS_FCP_FC4_FEATURE_INITIATOR;
4754 len = fc_rffid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4755 bfa_fcs_lport_get_fcid(port), 0,
4756 FC_TYPE_FCP, fc4_ftrs);
4758 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4759 FC_CLASS_3, len, &fchs,
4760 bfa_fcs_lport_ns_rff_id_response, (void *)ns,
4761 FC_MAX_PDUSZ, FC_FCCT_TOV);
4763 port->stats.ns_rffid_sent++;
4764 bfa_sm_send_event(ns, NSSM_EVENT_RFFID_SENT);
4767 static void
4768 bfa_fcs_lport_ns_rff_id_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4769 void *cbarg, bfa_status_t req_status,
4770 u32 rsp_len, u32 resid_len,
4771 struct fchs_s *rsp_fchs)
4773 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4774 struct bfa_fcs_lport_s *port = ns->port;
4775 struct ct_hdr_s *cthdr = NULL;
4777 bfa_trc(port->fcs, port->port_cfg.pwwn);
4780 * Sanity Checks
4782 if (req_status != BFA_STATUS_OK) {
4783 bfa_trc(port->fcs, req_status);
4784 port->stats.ns_rffid_rsp_err++;
4785 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4786 return;
4789 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4790 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4792 if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
4793 port->stats.ns_rffid_accepts++;
4794 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4795 return;
4798 port->stats.ns_rffid_rejects++;
4799 bfa_trc(port->fcs, cthdr->reason_code);
4800 bfa_trc(port->fcs, cthdr->exp_code);
4802 if (cthdr->reason_code == CT_RSN_NOT_SUPP) {
4803 /* if this command is not supported, we don't retry */
4804 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4805 } else
4806 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4809 * Query Fabric for FC4-Types Devices.
4811 * TBD : Need to use a local (FCS private) response buffer, since the response
4812 * can be larger than 2K.
4814 static void
4815 bfa_fcs_lport_ns_send_gid_ft(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
4817 struct bfa_fcs_lport_ns_s *ns = ns_cbarg;
4818 struct bfa_fcs_lport_s *port = ns->port;
4819 struct fchs_s fchs;
4820 int len;
4821 struct bfa_fcxp_s *fcxp;
4823 bfa_trc(port->fcs, port->pid);
4825 fcxp = fcxp_alloced ? fcxp_alloced :
4826 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
4827 if (!fcxp) {
4828 port->stats.ns_gidft_alloc_wait++;
4829 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
4830 bfa_fcs_lport_ns_send_gid_ft, ns, BFA_TRUE);
4831 return;
4833 ns->fcxp = fcxp;
4836 * This query is only initiated for FCP initiator mode.
4838 len = fc_gid_ft_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
4839 ns->port->pid, FC_TYPE_FCP);
4841 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
4842 FC_CLASS_3, len, &fchs,
4843 bfa_fcs_lport_ns_gid_ft_response, (void *)ns,
4844 bfa_fcxp_get_maxrsp(port->fcs->bfa), FC_FCCT_TOV);
4846 port->stats.ns_gidft_sent++;
4848 bfa_sm_send_event(ns, NSSM_EVENT_GIDFT_SENT);
4851 static void
4852 bfa_fcs_lport_ns_gid_ft_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
4853 void *cbarg, bfa_status_t req_status,
4854 u32 rsp_len, u32 resid_len,
4855 struct fchs_s *rsp_fchs)
4857 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) cbarg;
4858 struct bfa_fcs_lport_s *port = ns->port;
4859 struct ct_hdr_s *cthdr = NULL;
4860 u32 n_pids;
4862 bfa_trc(port->fcs, port->port_cfg.pwwn);
4865 * Sanity Checks
4867 if (req_status != BFA_STATUS_OK) {
4868 bfa_trc(port->fcs, req_status);
4869 port->stats.ns_gidft_rsp_err++;
4870 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4871 return;
4874 if (resid_len != 0) {
4876 * TBD : we will need to allocate a larger buffer & retry the
4877 * command
4879 bfa_trc(port->fcs, rsp_len);
4880 bfa_trc(port->fcs, resid_len);
4881 return;
4884 cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
4885 cthdr->cmd_rsp_code = be16_to_cpu(cthdr->cmd_rsp_code);
4887 switch (cthdr->cmd_rsp_code) {
4889 case CT_RSP_ACCEPT:
4891 port->stats.ns_gidft_accepts++;
4892 n_pids = (fc_get_ctresp_pyld_len(rsp_len) / sizeof(u32));
4893 bfa_trc(port->fcs, n_pids);
4894 bfa_fcs_lport_ns_process_gidft_pids(port,
4895 (u32 *) (cthdr + 1),
4896 n_pids);
4897 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4898 break;
4900 case CT_RSP_REJECT:
4903 * Check the reason code & explanation.
4904 * There may not have been any FC4 devices in the fabric
4906 port->stats.ns_gidft_rejects++;
4907 bfa_trc(port->fcs, cthdr->reason_code);
4908 bfa_trc(port->fcs, cthdr->exp_code);
4910 if ((cthdr->reason_code == CT_RSN_UNABLE_TO_PERF)
4911 && (cthdr->exp_code == CT_NS_EXP_FT_NOT_REG)) {
4913 bfa_sm_send_event(ns, NSSM_EVENT_RSP_OK);
4914 } else {
4916 * for all other errors, retry
4918 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4920 break;
4922 default:
4923 port->stats.ns_gidft_unknown_rsp++;
4924 bfa_trc(port->fcs, cthdr->cmd_rsp_code);
4925 bfa_sm_send_event(ns, NSSM_EVENT_RSP_ERROR);
4930 * This routine will be called by bfa_timer on timer timeouts.
4932 * param[in] port - pointer to bfa_fcs_lport_t.
4934 * return
4935 * void
4937 * Special Considerations:
4939 * note
4941 static void
4942 bfa_fcs_lport_ns_timeout(void *arg)
4944 struct bfa_fcs_lport_ns_s *ns = (struct bfa_fcs_lport_ns_s *) arg;
4946 ns->port->stats.ns_timeouts++;
4947 bfa_sm_send_event(ns, NSSM_EVENT_TIMEOUT);
4951 * Process the PID list in GID_FT response
4953 static void
4954 bfa_fcs_lport_ns_process_gidft_pids(struct bfa_fcs_lport_s *port, u32 *pid_buf,
4955 u32 n_pids)
4957 struct fcgs_gidft_resp_s *gidft_entry;
4958 struct bfa_fcs_rport_s *rport;
4959 u32 ii;
4960 struct bfa_fcs_fabric_s *fabric = port->fabric;
4961 struct bfa_fcs_vport_s *vport;
4962 struct list_head *qe;
4963 u8 found = 0;
4965 for (ii = 0; ii < n_pids; ii++) {
4966 gidft_entry = (struct fcgs_gidft_resp_s *) &pid_buf[ii];
4968 if (gidft_entry->pid == port->pid)
4969 continue;
4972 * Ignore PID if it is of base port
4973 * (Avoid vports discovering base port as remote port)
4975 if (gidft_entry->pid == fabric->bport.pid)
4976 continue;
4979 * Ignore PID if it is of vport created on the same base port
4980 * (Avoid vport discovering every other vport created on the
4981 * same port as remote port)
4983 list_for_each(qe, &fabric->vport_q) {
4984 vport = (struct bfa_fcs_vport_s *) qe;
4985 if (vport->lport.pid == gidft_entry->pid)
4986 found = 1;
4989 if (found) {
4990 found = 0;
4991 continue;
4995 * Check if this rport already exists
4997 rport = bfa_fcs_lport_get_rport_by_pid(port, gidft_entry->pid);
4998 if (rport == NULL) {
5000 * this is a new device. create rport
5002 rport = bfa_fcs_rport_create(port, gidft_entry->pid);
5003 } else {
5005 * this rport already exists
5007 bfa_fcs_rport_scn(rport);
5010 bfa_trc(port->fcs, gidft_entry->pid);
5013 * if the last entry bit is set, bail out.
5015 if (gidft_entry->last)
5016 return;
5021 * fcs_ns_public FCS nameserver public interfaces
5025 * Functions called by port/fab.
5026 * These will send relevant Events to the ns state machine.
5028 void
5029 bfa_fcs_lport_ns_init(struct bfa_fcs_lport_s *port)
5031 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
5033 ns->port = port;
5034 bfa_sm_set_state(ns, bfa_fcs_lport_ns_sm_offline);
5037 void
5038 bfa_fcs_lport_ns_offline(struct bfa_fcs_lport_s *port)
5040 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
5042 ns->port = port;
5043 bfa_sm_send_event(ns, NSSM_EVENT_PORT_OFFLINE);
5046 void
5047 bfa_fcs_lport_ns_online(struct bfa_fcs_lport_s *port)
5049 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
5051 ns->port = port;
5052 bfa_sm_send_event(ns, NSSM_EVENT_PORT_ONLINE);
5055 void
5056 bfa_fcs_lport_ns_query(struct bfa_fcs_lport_s *port)
5058 struct bfa_fcs_lport_ns_s *ns = BFA_FCS_GET_NS_FROM_PORT(port);
5060 bfa_trc(port->fcs, port->pid);
5061 if (bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_online))
5062 bfa_sm_send_event(ns, NSSM_EVENT_NS_QUERY);
5065 static void
5066 bfa_fcs_lport_ns_boot_target_disc(bfa_fcs_lport_t *port)
5069 struct bfa_fcs_rport_s *rport;
5070 u8 nwwns;
5071 wwn_t wwns[BFA_PREBOOT_BOOTLUN_MAX];
5072 int ii;
5074 bfa_iocfc_get_bootwwns(port->fcs->bfa, &nwwns, wwns);
5076 for (ii = 0 ; ii < nwwns; ++ii) {
5077 rport = bfa_fcs_rport_create_by_wwn(port, wwns[ii]);
5078 WARN_ON(!rport);
5082 void
5083 bfa_fcs_lport_ns_util_send_rspn_id(void *cbarg, struct bfa_fcxp_s *fcxp_alloced)
5085 struct bfa_fcs_lport_ns_s *ns = cbarg;
5086 struct bfa_fcs_lport_s *port = ns->port;
5087 struct fchs_s fchs;
5088 struct bfa_fcxp_s *fcxp;
5089 u8 symbl[256];
5090 int len;
5092 /* Avoid sending RSPN in the following states. */
5093 if (bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_offline) ||
5094 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi_sending) ||
5095 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi) ||
5096 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_plogi_retry) ||
5097 bfa_sm_cmp_state(ns, bfa_fcs_lport_ns_sm_rspn_id_retry))
5098 return;
5100 memset(symbl, 0, sizeof(symbl));
5101 bfa_trc(port->fcs, port->port_cfg.pwwn);
5103 fcxp = fcxp_alloced ? fcxp_alloced :
5104 bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
5105 if (!fcxp) {
5106 port->stats.ns_rspnid_alloc_wait++;
5107 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &ns->fcxp_wqe,
5108 bfa_fcs_lport_ns_util_send_rspn_id, ns, BFA_FALSE);
5109 return;
5112 ns->fcxp = fcxp;
5114 if (port->vport) {
5116 * For Vports, we append the vport's port symbolic name
5117 * to that of the base port.
5119 strscpy(symbl, (char *)&(bfa_fcs_lport_get_psym_name
5120 (bfa_fcs_get_base_port(port->fcs))),
5121 sizeof(symbl));
5123 strlcat(symbl,
5124 (char *)&(bfa_fcs_lport_get_psym_name(port)),
5125 sizeof(symbl));
5128 len = fc_rspnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
5129 bfa_fcs_lport_get_fcid(port), 0, symbl);
5131 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
5132 FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
5134 port->stats.ns_rspnid_sent++;
5138 * FCS SCN
5141 #define FC_QOS_RSCN_EVENT 0x0c
5142 #define FC_FABRIC_NAME_RSCN_EVENT 0x0d
5145 * forward declarations
5147 static void bfa_fcs_lport_scn_send_scr(void *scn_cbarg,
5148 struct bfa_fcxp_s *fcxp_alloced);
5149 static void bfa_fcs_lport_scn_scr_response(void *fcsarg,
5150 struct bfa_fcxp_s *fcxp,
5151 void *cbarg,
5152 bfa_status_t req_status,
5153 u32 rsp_len,
5154 u32 resid_len,
5155 struct fchs_s *rsp_fchs);
5156 static void bfa_fcs_lport_scn_send_ls_acc(struct bfa_fcs_lport_s *port,
5157 struct fchs_s *rx_fchs);
5158 static void bfa_fcs_lport_scn_timeout(void *arg);
5161 * fcs_scm_sm FCS SCN state machine
5164 static void bfa_fcs_lport_scn_sm_offline(struct bfa_fcs_lport_scn_s *scn,
5165 enum port_scn_event event);
5166 static void bfa_fcs_lport_scn_sm_sending_scr(
5167 struct bfa_fcs_lport_scn_s *scn,
5168 enum port_scn_event event);
5169 static void bfa_fcs_lport_scn_sm_scr(struct bfa_fcs_lport_scn_s *scn,
5170 enum port_scn_event event);
5171 static void bfa_fcs_lport_scn_sm_scr_retry(struct bfa_fcs_lport_scn_s *scn,
5172 enum port_scn_event event);
5173 static void bfa_fcs_lport_scn_sm_online(struct bfa_fcs_lport_scn_s *scn,
5174 enum port_scn_event event);
5177 * Starting state - awaiting link up.
5179 static void
5180 bfa_fcs_lport_scn_sm_offline(struct bfa_fcs_lport_scn_s *scn,
5181 enum port_scn_event event)
5183 switch (event) {
5184 case SCNSM_EVENT_PORT_ONLINE:
5185 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_sending_scr);
5186 bfa_fcs_lport_scn_send_scr(scn, NULL);
5187 break;
5189 case SCNSM_EVENT_PORT_OFFLINE:
5190 break;
5192 default:
5193 bfa_sm_fault(scn->port->fcs, event);
5197 static void
5198 bfa_fcs_lport_scn_sm_sending_scr(struct bfa_fcs_lport_scn_s *scn,
5199 enum port_scn_event event)
5201 switch (event) {
5202 case SCNSM_EVENT_SCR_SENT:
5203 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_scr);
5204 break;
5206 case SCNSM_EVENT_PORT_OFFLINE:
5207 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5208 bfa_fcxp_walloc_cancel(scn->port->fcs->bfa, &scn->fcxp_wqe);
5209 break;
5211 default:
5212 bfa_sm_fault(scn->port->fcs, event);
5216 static void
5217 bfa_fcs_lport_scn_sm_scr(struct bfa_fcs_lport_scn_s *scn,
5218 enum port_scn_event event)
5220 struct bfa_fcs_lport_s *port = scn->port;
5222 switch (event) {
5223 case SCNSM_EVENT_RSP_OK:
5224 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_online);
5225 break;
5227 case SCNSM_EVENT_RSP_ERROR:
5228 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_scr_retry);
5229 bfa_timer_start(port->fcs->bfa, &scn->timer,
5230 bfa_fcs_lport_scn_timeout, scn,
5231 BFA_FCS_RETRY_TIMEOUT);
5232 break;
5234 case SCNSM_EVENT_PORT_OFFLINE:
5235 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5236 bfa_fcxp_discard(scn->fcxp);
5237 break;
5239 default:
5240 bfa_sm_fault(port->fcs, event);
5244 static void
5245 bfa_fcs_lport_scn_sm_scr_retry(struct bfa_fcs_lport_scn_s *scn,
5246 enum port_scn_event event)
5248 switch (event) {
5249 case SCNSM_EVENT_TIMEOUT:
5250 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_sending_scr);
5251 bfa_fcs_lport_scn_send_scr(scn, NULL);
5252 break;
5254 case SCNSM_EVENT_PORT_OFFLINE:
5255 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5256 bfa_timer_stop(&scn->timer);
5257 break;
5259 default:
5260 bfa_sm_fault(scn->port->fcs, event);
5264 static void
5265 bfa_fcs_lport_scn_sm_online(struct bfa_fcs_lport_scn_s *scn,
5266 enum port_scn_event event)
5268 switch (event) {
5269 case SCNSM_EVENT_PORT_OFFLINE:
5270 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5271 break;
5273 default:
5274 bfa_sm_fault(scn->port->fcs, event);
5281 * fcs_scn_private FCS SCN private functions
5285 * This routine will be called to send a SCR command.
5287 static void
5288 bfa_fcs_lport_scn_send_scr(void *scn_cbarg, struct bfa_fcxp_s *fcxp_alloced)
5290 struct bfa_fcs_lport_scn_s *scn = scn_cbarg;
5291 struct bfa_fcs_lport_s *port = scn->port;
5292 struct fchs_s fchs;
5293 int len;
5294 struct bfa_fcxp_s *fcxp;
5296 bfa_trc(port->fcs, port->pid);
5297 bfa_trc(port->fcs, port->port_cfg.pwwn);
5299 fcxp = fcxp_alloced ? fcxp_alloced :
5300 bfa_fcs_fcxp_alloc(port->fcs, BFA_TRUE);
5301 if (!fcxp) {
5302 bfa_fcs_fcxp_alloc_wait(port->fcs->bfa, &scn->fcxp_wqe,
5303 bfa_fcs_lport_scn_send_scr, scn, BFA_TRUE);
5304 return;
5306 scn->fcxp = fcxp;
5308 /* Handle VU registrations for Base port only */
5309 if ((!port->vport) && bfa_ioc_get_fcmode(&port->fcs->bfa->ioc)) {
5310 len = fc_scr_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
5311 port->fabric->lps->brcd_switch,
5312 port->pid, 0);
5313 } else {
5314 len = fc_scr_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
5315 BFA_FALSE,
5316 port->pid, 0);
5319 bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
5320 FC_CLASS_3, len, &fchs,
5321 bfa_fcs_lport_scn_scr_response,
5322 (void *)scn, FC_MAX_PDUSZ, FC_ELS_TOV);
5324 bfa_sm_send_event(scn, SCNSM_EVENT_SCR_SENT);
5327 static void
5328 bfa_fcs_lport_scn_scr_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
5329 void *cbarg, bfa_status_t req_status, u32 rsp_len,
5330 u32 resid_len, struct fchs_s *rsp_fchs)
5332 struct bfa_fcs_lport_scn_s *scn = (struct bfa_fcs_lport_scn_s *) cbarg;
5333 struct bfa_fcs_lport_s *port = scn->port;
5334 struct fc_els_cmd_s *els_cmd;
5335 struct fc_ls_rjt_s *ls_rjt;
5337 bfa_trc(port->fcs, port->port_cfg.pwwn);
5340 * Sanity Checks
5342 if (req_status != BFA_STATUS_OK) {
5343 bfa_trc(port->fcs, req_status);
5344 bfa_sm_send_event(scn, SCNSM_EVENT_RSP_ERROR);
5345 return;
5348 els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
5350 switch (els_cmd->els_code) {
5352 case FC_ELS_ACC:
5353 bfa_sm_send_event(scn, SCNSM_EVENT_RSP_OK);
5354 break;
5356 case FC_ELS_LS_RJT:
5358 ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
5360 bfa_trc(port->fcs, ls_rjt->reason_code);
5361 bfa_trc(port->fcs, ls_rjt->reason_code_expl);
5363 bfa_sm_send_event(scn, SCNSM_EVENT_RSP_ERROR);
5364 break;
5366 default:
5367 bfa_sm_send_event(scn, SCNSM_EVENT_RSP_ERROR);
5372 * Send a LS Accept
5374 static void
5375 bfa_fcs_lport_scn_send_ls_acc(struct bfa_fcs_lport_s *port,
5376 struct fchs_s *rx_fchs)
5378 struct fchs_s fchs;
5379 struct bfa_fcxp_s *fcxp;
5380 struct bfa_rport_s *bfa_rport = NULL;
5381 int len;
5383 bfa_trc(port->fcs, rx_fchs->s_id);
5385 fcxp = bfa_fcs_fcxp_alloc(port->fcs, BFA_FALSE);
5386 if (!fcxp)
5387 return;
5389 len = fc_ls_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
5390 rx_fchs->s_id, bfa_fcs_lport_get_fcid(port),
5391 rx_fchs->ox_id);
5393 bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
5394 BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
5395 FC_MAX_PDUSZ, 0);
5399 * This routine will be called by bfa_timer on timer timeouts.
5401 * param[in] vport - pointer to bfa_fcs_lport_t.
5402 * param[out] vport_status - pointer to return vport status in
5404 * return
5405 * void
5407 * Special Considerations:
5409 * note
5411 static void
5412 bfa_fcs_lport_scn_timeout(void *arg)
5414 struct bfa_fcs_lport_scn_s *scn = (struct bfa_fcs_lport_scn_s *) arg;
5416 bfa_sm_send_event(scn, SCNSM_EVENT_TIMEOUT);
5422 * fcs_scn_public FCS state change notification public interfaces
5426 * Functions called by port/fab
5428 void
5429 bfa_fcs_lport_scn_init(struct bfa_fcs_lport_s *port)
5431 struct bfa_fcs_lport_scn_s *scn = BFA_FCS_GET_SCN_FROM_PORT(port);
5433 scn->port = port;
5434 bfa_sm_set_state(scn, bfa_fcs_lport_scn_sm_offline);
5437 void
5438 bfa_fcs_lport_scn_offline(struct bfa_fcs_lport_s *port)
5440 struct bfa_fcs_lport_scn_s *scn = BFA_FCS_GET_SCN_FROM_PORT(port);
5442 scn->port = port;
5443 bfa_sm_send_event(scn, SCNSM_EVENT_PORT_OFFLINE);
5446 void
5447 bfa_fcs_lport_fab_scn_online(struct bfa_fcs_lport_s *port)
5449 struct bfa_fcs_lport_scn_s *scn = BFA_FCS_GET_SCN_FROM_PORT(port);
5451 scn->port = port;
5452 bfa_sm_send_event(scn, SCNSM_EVENT_PORT_ONLINE);
5455 static void
5456 bfa_fcs_lport_scn_portid_rscn(struct bfa_fcs_lport_s *port, u32 rpid)
5458 struct bfa_fcs_rport_s *rport;
5459 struct bfa_fcs_fabric_s *fabric = port->fabric;
5460 struct bfa_fcs_vport_s *vport;
5461 struct list_head *qe;
5463 bfa_trc(port->fcs, rpid);
5466 * Ignore PID if it is of base port or of vports created on the
5467 * same base port. It is to avoid vports discovering base port or
5468 * other vports created on same base port as remote port
5470 if (rpid == fabric->bport.pid)
5471 return;
5473 list_for_each(qe, &fabric->vport_q) {
5474 vport = (struct bfa_fcs_vport_s *) qe;
5475 if (vport->lport.pid == rpid)
5476 return;
5479 * If this is an unknown device, then it just came online.
5480 * Otherwise let rport handle the RSCN event.
5482 rport = bfa_fcs_lport_get_rport_by_pid(port, rpid);
5483 if (!rport)
5484 rport = bfa_fcs_lport_get_rport_by_old_pid(port, rpid);
5486 if (rport == NULL) {
5488 * If min cfg mode is enabled, we donot need to
5489 * discover any new rports.
5491 if (!__fcs_min_cfg(port->fcs))
5492 rport = bfa_fcs_rport_create(port, rpid);
5493 } else
5494 bfa_fcs_rport_scn(rport);
5498 * rscn format based PID comparison
5500 #define __fc_pid_match(__c0, __c1, __fmt) \
5501 (((__fmt) == FC_RSCN_FORMAT_FABRIC) || \
5502 (((__fmt) == FC_RSCN_FORMAT_DOMAIN) && \
5503 ((__c0)[0] == (__c1)[0])) || \
5504 (((__fmt) == FC_RSCN_FORMAT_AREA) && \
5505 ((__c0)[0] == (__c1)[0]) && \
5506 ((__c0)[1] == (__c1)[1])))
5508 static void
5509 bfa_fcs_lport_scn_multiport_rscn(struct bfa_fcs_lport_s *port,
5510 enum fc_rscn_format format,
5511 u32 rscn_pid)
5513 struct bfa_fcs_rport_s *rport;
5514 struct list_head *qe, *qe_next;
5515 u8 *c0, *c1;
5517 bfa_trc(port->fcs, format);
5518 bfa_trc(port->fcs, rscn_pid);
5520 c0 = (u8 *) &rscn_pid;
5522 list_for_each_safe(qe, qe_next, &port->rport_q) {
5523 rport = (struct bfa_fcs_rport_s *) qe;
5524 c1 = (u8 *) &rport->pid;
5525 if (__fc_pid_match(c0, c1, format))
5526 bfa_fcs_rport_scn(rport);
5531 void
5532 bfa_fcs_lport_scn_process_rscn(struct bfa_fcs_lport_s *port,
5533 struct fchs_s *fchs, u32 len)
5535 struct fc_rscn_pl_s *rscn = (struct fc_rscn_pl_s *) (fchs + 1);
5536 int num_entries;
5537 u32 rscn_pid;
5538 bfa_boolean_t nsquery = BFA_FALSE, found;
5539 int i = 0, j;
5541 num_entries =
5542 (be16_to_cpu(rscn->payldlen) -
5543 sizeof(u32)) / sizeof(rscn->event[0]);
5545 bfa_trc(port->fcs, num_entries);
5547 port->stats.num_rscn++;
5549 bfa_fcs_lport_scn_send_ls_acc(port, fchs);
5551 for (i = 0; i < num_entries; i++) {
5552 rscn_pid = rscn->event[i].portid;
5554 bfa_trc(port->fcs, rscn->event[i].format);
5555 bfa_trc(port->fcs, rscn_pid);
5557 /* check for duplicate entries in the list */
5558 found = BFA_FALSE;
5559 for (j = 0; j < i; j++) {
5560 if (rscn->event[j].portid == rscn_pid) {
5561 found = BFA_TRUE;
5562 break;
5566 /* if found in down the list, pid has been already processed */
5567 if (found) {
5568 bfa_trc(port->fcs, rscn_pid);
5569 continue;
5572 switch (rscn->event[i].format) {
5573 case FC_RSCN_FORMAT_PORTID:
5574 if (rscn->event[i].qualifier == FC_QOS_RSCN_EVENT) {
5576 * Ignore this event.
5577 * f/w would have processed it
5579 bfa_trc(port->fcs, rscn_pid);
5580 } else {
5581 port->stats.num_portid_rscn++;
5582 bfa_fcs_lport_scn_portid_rscn(port, rscn_pid);
5584 break;
5586 case FC_RSCN_FORMAT_FABRIC:
5587 if (rscn->event[i].qualifier ==
5588 FC_FABRIC_NAME_RSCN_EVENT) {
5589 bfa_fcs_lport_ms_fabric_rscn(port);
5590 break;
5592 fallthrough;
5594 case FC_RSCN_FORMAT_AREA:
5595 case FC_RSCN_FORMAT_DOMAIN:
5596 nsquery = BFA_TRUE;
5597 bfa_fcs_lport_scn_multiport_rscn(port,
5598 rscn->event[i].format,
5599 rscn_pid);
5600 break;
5603 default:
5604 WARN_ON(1);
5605 nsquery = BFA_TRUE;
5610 * If any of area, domain or fabric RSCN is received, do a fresh
5611 * discovery to find new devices.
5613 if (nsquery)
5614 bfa_fcs_lport_ns_query(port);
5618 * BFA FCS port
5621 * fcs_port_api BFA FCS port API
5623 struct bfa_fcs_lport_s *
5624 bfa_fcs_get_base_port(struct bfa_fcs_s *fcs)
5626 return &fcs->fabric.bport;
5629 void
5630 bfa_fcs_lport_get_rport_quals(struct bfa_fcs_lport_s *port,
5631 struct bfa_rport_qualifier_s rports[], int *nrports)
5633 struct list_head *qh, *qe;
5634 struct bfa_fcs_rport_s *rport = NULL;
5635 int i;
5636 struct bfa_fcs_s *fcs;
5638 if (port == NULL || rports == NULL || *nrports == 0)
5639 return;
5641 fcs = port->fcs;
5642 bfa_trc(fcs, (u32) *nrports);
5644 i = 0;
5645 qh = &port->rport_q;
5646 qe = bfa_q_first(qh);
5648 while ((qe != qh) && (i < *nrports)) {
5649 rport = (struct bfa_fcs_rport_s *) qe;
5650 if (bfa_ntoh3b(rport->pid) > 0xFFF000) {
5651 qe = bfa_q_next(qe);
5652 bfa_trc(fcs, (u32) rport->pwwn);
5653 bfa_trc(fcs, rport->pid);
5654 bfa_trc(fcs, i);
5655 continue;
5658 if (!rport->pwwn && !rport->pid) {
5659 qe = bfa_q_next(qe);
5660 continue;
5663 rports[i].pwwn = rport->pwwn;
5664 rports[i].pid = rport->pid;
5666 i++;
5667 qe = bfa_q_next(qe);
5670 bfa_trc(fcs, i);
5671 *nrports = i;
5675 * Iterate's through all the rport's in the given port to
5676 * determine the maximum operating speed.
5678 * !!!! To be used in TRL Functionality only !!!!
5680 bfa_port_speed_t
5681 bfa_fcs_lport_get_rport_max_speed(bfa_fcs_lport_t *port)
5683 struct list_head *qh, *qe;
5684 struct bfa_fcs_rport_s *rport = NULL;
5685 struct bfa_fcs_s *fcs;
5686 bfa_port_speed_t max_speed = 0;
5687 struct bfa_port_attr_s port_attr;
5688 bfa_port_speed_t port_speed, rport_speed;
5689 bfa_boolean_t trl_enabled;
5691 if (port == NULL)
5692 return 0;
5694 fcs = port->fcs;
5695 trl_enabled = bfa_fcport_is_ratelim(port->fcs->bfa);
5697 /* Get Physical port's current speed */
5698 bfa_fcport_get_attr(port->fcs->bfa, &port_attr);
5699 port_speed = port_attr.speed;
5700 bfa_trc(fcs, port_speed);
5702 qh = &port->rport_q;
5703 qe = bfa_q_first(qh);
5705 while (qe != qh) {
5706 rport = (struct bfa_fcs_rport_s *) qe;
5707 if ((bfa_ntoh3b(rport->pid) > 0xFFF000) ||
5708 (bfa_fcs_rport_get_state(rport) == BFA_RPORT_OFFLINE) ||
5709 (rport->scsi_function != BFA_RPORT_TARGET)) {
5710 qe = bfa_q_next(qe);
5711 continue;
5714 rport_speed = rport->rpf.rpsc_speed;
5715 if ((trl_enabled) && (rport_speed ==
5716 BFA_PORT_SPEED_UNKNOWN)) {
5717 /* Use default ratelim speed setting */
5718 rport_speed =
5719 bfa_fcport_get_ratelim_speed(port->fcs->bfa);
5722 if (rport_speed > max_speed)
5723 max_speed = rport_speed;
5725 qe = bfa_q_next(qe);
5728 if (max_speed > port_speed)
5729 max_speed = port_speed;
5731 bfa_trc(fcs, max_speed);
5732 return max_speed;
5735 struct bfa_fcs_lport_s *
5736 bfa_fcs_lookup_port(struct bfa_fcs_s *fcs, u16 vf_id, wwn_t lpwwn)
5738 struct bfa_fcs_vport_s *vport;
5739 bfa_fcs_vf_t *vf;
5741 WARN_ON(fcs == NULL);
5743 vf = bfa_fcs_vf_lookup(fcs, vf_id);
5744 if (vf == NULL) {
5745 bfa_trc(fcs, vf_id);
5746 return NULL;
5749 if (!lpwwn || (vf->bport.port_cfg.pwwn == lpwwn))
5750 return &vf->bport;
5752 vport = bfa_fcs_fabric_vport_lookup(vf, lpwwn);
5753 if (vport)
5754 return &vport->lport;
5756 return NULL;
5759 void
5760 bfa_fcs_lport_get_stats(struct bfa_fcs_lport_s *fcs_port,
5761 struct bfa_lport_stats_s *port_stats)
5763 *port_stats = fcs_port->stats;
5766 void
5767 bfa_fcs_lport_clear_stats(struct bfa_fcs_lport_s *fcs_port)
5769 memset(&fcs_port->stats, 0, sizeof(struct bfa_lport_stats_s));
5773 * Let new loop map create missing rports
5775 void
5776 bfa_fcs_lport_lip_scn_online(struct bfa_fcs_lport_s *port)
5778 bfa_fcs_lport_loop_online(port);
5782 * FCS virtual port state machine
5785 #define __vport_fcs(__vp) ((__vp)->lport.fcs)
5786 #define __vport_pwwn(__vp) ((__vp)->lport.port_cfg.pwwn)
5787 #define __vport_nwwn(__vp) ((__vp)->lport.port_cfg.nwwn)
5788 #define __vport_bfa(__vp) ((__vp)->lport.fcs->bfa)
5789 #define __vport_fcid(__vp) ((__vp)->lport.pid)
5790 #define __vport_fabric(__vp) ((__vp)->lport.fabric)
5791 #define __vport_vfid(__vp) ((__vp)->lport.fabric->vf_id)
5793 #define BFA_FCS_VPORT_MAX_RETRIES 5
5795 * Forward declarations
5797 static void bfa_fcs_vport_do_fdisc(struct bfa_fcs_vport_s *vport);
5798 static void bfa_fcs_vport_timeout(void *vport_arg);
5799 static void bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s *vport);
5800 static void bfa_fcs_vport_free(struct bfa_fcs_vport_s *vport);
5803 * fcs_vport_sm FCS virtual port state machine
5806 static void bfa_fcs_vport_sm_uninit(struct bfa_fcs_vport_s *vport,
5807 enum bfa_fcs_vport_event event);
5808 static void bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s *vport,
5809 enum bfa_fcs_vport_event event);
5810 static void bfa_fcs_vport_sm_offline(struct bfa_fcs_vport_s *vport,
5811 enum bfa_fcs_vport_event event);
5812 static void bfa_fcs_vport_sm_fdisc(struct bfa_fcs_vport_s *vport,
5813 enum bfa_fcs_vport_event event);
5814 static void bfa_fcs_vport_sm_fdisc_retry(struct bfa_fcs_vport_s *vport,
5815 enum bfa_fcs_vport_event event);
5816 static void bfa_fcs_vport_sm_fdisc_rsp_wait(struct bfa_fcs_vport_s *vport,
5817 enum bfa_fcs_vport_event event);
5818 static void bfa_fcs_vport_sm_online(struct bfa_fcs_vport_s *vport,
5819 enum bfa_fcs_vport_event event);
5820 static void bfa_fcs_vport_sm_deleting(struct bfa_fcs_vport_s *vport,
5821 enum bfa_fcs_vport_event event);
5822 static void bfa_fcs_vport_sm_cleanup(struct bfa_fcs_vport_s *vport,
5823 enum bfa_fcs_vport_event event);
5824 static void bfa_fcs_vport_sm_logo(struct bfa_fcs_vport_s *vport,
5825 enum bfa_fcs_vport_event event);
5826 static void bfa_fcs_vport_sm_error(struct bfa_fcs_vport_s *vport,
5827 enum bfa_fcs_vport_event event);
5828 static void bfa_fcs_vport_sm_stopping(struct bfa_fcs_vport_s *vport,
5829 enum bfa_fcs_vport_event event);
5830 static void bfa_fcs_vport_sm_logo_for_stop(struct bfa_fcs_vport_s *vport,
5831 enum bfa_fcs_vport_event event);
5833 struct bfa_fcs_vport_sm_table_s {
5834 bfa_fcs_vport_sm_t sm; /* state machine function */
5835 enum bfa_vport_state state; /* state machine encoding */
5836 char *name; /* state name for display */
5839 static inline enum bfa_vport_state
5840 bfa_vport_sm_to_state(struct bfa_fcs_vport_sm_table_s *smt, bfa_fcs_vport_sm_t sm)
5842 int i = 0;
5844 while (smt[i].sm && smt[i].sm != sm)
5845 i++;
5846 return smt[i].state;
5849 static struct bfa_fcs_vport_sm_table_s vport_sm_table[] = {
5850 {BFA_SM(bfa_fcs_vport_sm_uninit), BFA_FCS_VPORT_UNINIT},
5851 {BFA_SM(bfa_fcs_vport_sm_created), BFA_FCS_VPORT_CREATED},
5852 {BFA_SM(bfa_fcs_vport_sm_offline), BFA_FCS_VPORT_OFFLINE},
5853 {BFA_SM(bfa_fcs_vport_sm_fdisc), BFA_FCS_VPORT_FDISC},
5854 {BFA_SM(bfa_fcs_vport_sm_fdisc_retry), BFA_FCS_VPORT_FDISC_RETRY},
5855 {BFA_SM(bfa_fcs_vport_sm_fdisc_rsp_wait), BFA_FCS_VPORT_FDISC_RSP_WAIT},
5856 {BFA_SM(bfa_fcs_vport_sm_online), BFA_FCS_VPORT_ONLINE},
5857 {BFA_SM(bfa_fcs_vport_sm_deleting), BFA_FCS_VPORT_DELETING},
5858 {BFA_SM(bfa_fcs_vport_sm_cleanup), BFA_FCS_VPORT_CLEANUP},
5859 {BFA_SM(bfa_fcs_vport_sm_logo), BFA_FCS_VPORT_LOGO},
5860 {BFA_SM(bfa_fcs_vport_sm_error), BFA_FCS_VPORT_ERROR}
5864 * Beginning state.
5866 static void
5867 bfa_fcs_vport_sm_uninit(struct bfa_fcs_vport_s *vport,
5868 enum bfa_fcs_vport_event event)
5870 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
5871 bfa_trc(__vport_fcs(vport), event);
5873 switch (event) {
5874 case BFA_FCS_VPORT_SM_CREATE:
5875 bfa_sm_set_state(vport, bfa_fcs_vport_sm_created);
5876 bfa_fcs_fabric_addvport(__vport_fabric(vport), vport);
5877 break;
5879 default:
5880 bfa_sm_fault(__vport_fcs(vport), event);
5885 * Created state - a start event is required to start up the state machine.
5887 static void
5888 bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s *vport,
5889 enum bfa_fcs_vport_event event)
5891 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
5892 bfa_trc(__vport_fcs(vport), event);
5894 switch (event) {
5895 case BFA_FCS_VPORT_SM_START:
5896 if (bfa_sm_cmp_state(__vport_fabric(vport),
5897 bfa_fcs_fabric_sm_online)
5898 && bfa_fcs_fabric_npiv_capable(__vport_fabric(vport))) {
5899 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
5900 bfa_fcs_vport_do_fdisc(vport);
5901 } else {
5903 * Fabric is offline or not NPIV capable, stay in
5904 * offline state.
5906 vport->vport_stats.fab_no_npiv++;
5907 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
5909 break;
5911 case BFA_FCS_VPORT_SM_DELETE:
5912 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
5913 bfa_fcs_lport_delete(&vport->lport);
5914 break;
5916 case BFA_FCS_VPORT_SM_ONLINE:
5917 case BFA_FCS_VPORT_SM_OFFLINE:
5919 * Ignore ONLINE/OFFLINE events from fabric
5920 * till vport is started.
5922 break;
5924 default:
5925 bfa_sm_fault(__vport_fcs(vport), event);
5930 * Offline state - awaiting ONLINE event from fabric SM.
5932 static void
5933 bfa_fcs_vport_sm_offline(struct bfa_fcs_vport_s *vport,
5934 enum bfa_fcs_vport_event event)
5936 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
5937 bfa_trc(__vport_fcs(vport), event);
5939 switch (event) {
5940 case BFA_FCS_VPORT_SM_DELETE:
5941 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
5942 bfa_fcs_lport_delete(&vport->lport);
5943 break;
5945 case BFA_FCS_VPORT_SM_ONLINE:
5946 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
5947 vport->fdisc_retries = 0;
5948 bfa_fcs_vport_do_fdisc(vport);
5949 break;
5951 case BFA_FCS_VPORT_SM_STOP:
5952 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
5953 bfa_sm_send_event(&vport->lport, BFA_FCS_PORT_SM_STOP);
5954 break;
5956 case BFA_FCS_VPORT_SM_OFFLINE:
5958 * This can happen if the vport couldn't be initialzied
5959 * due the fact that the npiv was not enabled on the switch.
5960 * In that case we will put the vport in offline state.
5961 * However, the link can go down and cause the this event to
5962 * be sent when we are already offline. Ignore it.
5964 break;
5966 default:
5967 bfa_sm_fault(__vport_fcs(vport), event);
5973 * FDISC is sent and awaiting reply from fabric.
5975 static void
5976 bfa_fcs_vport_sm_fdisc(struct bfa_fcs_vport_s *vport,
5977 enum bfa_fcs_vport_event event)
5979 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
5980 bfa_trc(__vport_fcs(vport), event);
5982 switch (event) {
5983 case BFA_FCS_VPORT_SM_DELETE:
5984 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc_rsp_wait);
5985 break;
5987 case BFA_FCS_VPORT_SM_OFFLINE:
5988 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
5989 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
5990 break;
5992 case BFA_FCS_VPORT_SM_RSP_OK:
5993 bfa_sm_set_state(vport, bfa_fcs_vport_sm_online);
5994 bfa_fcs_lport_online(&vport->lport);
5995 break;
5997 case BFA_FCS_VPORT_SM_RSP_ERROR:
5998 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc_retry);
5999 bfa_timer_start(__vport_bfa(vport), &vport->timer,
6000 bfa_fcs_vport_timeout, vport,
6001 BFA_FCS_RETRY_TIMEOUT);
6002 break;
6004 case BFA_FCS_VPORT_SM_RSP_FAILED:
6005 case BFA_FCS_VPORT_SM_FABRIC_MAX:
6006 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
6007 break;
6009 case BFA_FCS_VPORT_SM_RSP_DUP_WWN:
6010 bfa_sm_set_state(vport, bfa_fcs_vport_sm_error);
6011 break;
6013 default:
6014 bfa_sm_fault(__vport_fcs(vport), event);
6019 * FDISC attempt failed - a timer is active to retry FDISC.
6021 static void
6022 bfa_fcs_vport_sm_fdisc_retry(struct bfa_fcs_vport_s *vport,
6023 enum bfa_fcs_vport_event event)
6025 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6026 bfa_trc(__vport_fcs(vport), event);
6028 switch (event) {
6029 case BFA_FCS_VPORT_SM_DELETE:
6030 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6031 bfa_timer_stop(&vport->timer);
6032 bfa_fcs_lport_delete(&vport->lport);
6033 break;
6035 case BFA_FCS_VPORT_SM_OFFLINE:
6036 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
6037 bfa_timer_stop(&vport->timer);
6038 break;
6040 case BFA_FCS_VPORT_SM_TIMEOUT:
6041 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
6042 vport->vport_stats.fdisc_retries++;
6043 vport->fdisc_retries++;
6044 bfa_fcs_vport_do_fdisc(vport);
6045 break;
6047 default:
6048 bfa_sm_fault(__vport_fcs(vport), event);
6053 * FDISC is in progress and we got a vport delete request -
6054 * this is a wait state while we wait for fdisc response and
6055 * we will transition to the appropriate state - on rsp status.
6057 static void
6058 bfa_fcs_vport_sm_fdisc_rsp_wait(struct bfa_fcs_vport_s *vport,
6059 enum bfa_fcs_vport_event event)
6061 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6062 bfa_trc(__vport_fcs(vport), event);
6064 switch (event) {
6065 case BFA_FCS_VPORT_SM_RSP_OK:
6066 bfa_sm_set_state(vport, bfa_fcs_vport_sm_deleting);
6067 bfa_fcs_lport_delete(&vport->lport);
6068 break;
6070 case BFA_FCS_VPORT_SM_DELETE:
6071 break;
6073 case BFA_FCS_VPORT_SM_OFFLINE:
6074 case BFA_FCS_VPORT_SM_RSP_ERROR:
6075 case BFA_FCS_VPORT_SM_RSP_FAILED:
6076 case BFA_FCS_VPORT_SM_FABRIC_MAX:
6077 case BFA_FCS_VPORT_SM_RSP_DUP_WWN:
6078 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6079 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
6080 bfa_fcs_lport_delete(&vport->lport);
6081 break;
6083 default:
6084 bfa_sm_fault(__vport_fcs(vport), event);
6089 * Vport is online (FDISC is complete).
6091 static void
6092 bfa_fcs_vport_sm_online(struct bfa_fcs_vport_s *vport,
6093 enum bfa_fcs_vport_event event)
6095 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6096 bfa_trc(__vport_fcs(vport), event);
6098 switch (event) {
6099 case BFA_FCS_VPORT_SM_DELETE:
6100 bfa_sm_set_state(vport, bfa_fcs_vport_sm_deleting);
6101 bfa_fcs_lport_delete(&vport->lport);
6102 break;
6104 case BFA_FCS_VPORT_SM_STOP:
6105 bfa_sm_set_state(vport, bfa_fcs_vport_sm_stopping);
6106 bfa_sm_send_event(&vport->lport, BFA_FCS_PORT_SM_STOP);
6107 break;
6109 case BFA_FCS_VPORT_SM_OFFLINE:
6110 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
6111 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
6112 bfa_fcs_lport_offline(&vport->lport);
6113 break;
6115 default:
6116 bfa_sm_fault(__vport_fcs(vport), event);
6121 * Vport is being stopped - awaiting lport stop completion to send
6122 * LOGO to fabric.
6124 static void
6125 bfa_fcs_vport_sm_stopping(struct bfa_fcs_vport_s *vport,
6126 enum bfa_fcs_vport_event event)
6128 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6129 bfa_trc(__vport_fcs(vport), event);
6131 switch (event) {
6132 case BFA_FCS_VPORT_SM_STOPCOMP:
6133 bfa_sm_set_state(vport, bfa_fcs_vport_sm_logo_for_stop);
6134 bfa_fcs_vport_do_logo(vport);
6135 break;
6137 case BFA_FCS_VPORT_SM_OFFLINE:
6138 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6139 break;
6141 default:
6142 bfa_sm_fault(__vport_fcs(vport), event);
6147 * Vport is being deleted - awaiting lport delete completion to send
6148 * LOGO to fabric.
6150 static void
6151 bfa_fcs_vport_sm_deleting(struct bfa_fcs_vport_s *vport,
6152 enum bfa_fcs_vport_event event)
6154 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6155 bfa_trc(__vport_fcs(vport), event);
6157 switch (event) {
6158 case BFA_FCS_VPORT_SM_DELETE:
6159 break;
6161 case BFA_FCS_VPORT_SM_DELCOMP:
6162 bfa_sm_set_state(vport, bfa_fcs_vport_sm_logo);
6163 bfa_fcs_vport_do_logo(vport);
6164 break;
6166 case BFA_FCS_VPORT_SM_OFFLINE:
6167 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6168 break;
6170 default:
6171 bfa_sm_fault(__vport_fcs(vport), event);
6176 * Error State.
6177 * This state will be set when the Vport Creation fails due
6178 * to errors like Dup WWN. In this state only operation allowed
6179 * is a Vport Delete.
6181 static void
6182 bfa_fcs_vport_sm_error(struct bfa_fcs_vport_s *vport,
6183 enum bfa_fcs_vport_event event)
6185 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6186 bfa_trc(__vport_fcs(vport), event);
6188 switch (event) {
6189 case BFA_FCS_VPORT_SM_DELETE:
6190 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
6191 bfa_fcs_lport_delete(&vport->lport);
6192 break;
6194 default:
6195 bfa_trc(__vport_fcs(vport), event);
6200 * Lport cleanup is in progress since vport is being deleted. Fabric is
6201 * offline, so no LOGO is needed to complete vport deletion.
6203 static void
6204 bfa_fcs_vport_sm_cleanup(struct bfa_fcs_vport_s *vport,
6205 enum bfa_fcs_vport_event event)
6207 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6208 bfa_trc(__vport_fcs(vport), event);
6210 switch (event) {
6211 case BFA_FCS_VPORT_SM_DELCOMP:
6212 bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
6213 bfa_fcs_vport_free(vport);
6214 break;
6216 case BFA_FCS_VPORT_SM_STOPCOMP:
6217 bfa_sm_set_state(vport, bfa_fcs_vport_sm_created);
6218 break;
6220 case BFA_FCS_VPORT_SM_DELETE:
6221 break;
6223 default:
6224 bfa_sm_fault(__vport_fcs(vport), event);
6229 * LOGO is sent to fabric. Vport stop is in progress. Lport stop cleanup
6230 * is done.
6232 static void
6233 bfa_fcs_vport_sm_logo_for_stop(struct bfa_fcs_vport_s *vport,
6234 enum bfa_fcs_vport_event event)
6236 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6237 bfa_trc(__vport_fcs(vport), event);
6239 switch (event) {
6240 case BFA_FCS_VPORT_SM_OFFLINE:
6241 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
6242 fallthrough;
6244 case BFA_FCS_VPORT_SM_RSP_OK:
6245 case BFA_FCS_VPORT_SM_RSP_ERROR:
6246 bfa_sm_set_state(vport, bfa_fcs_vport_sm_created);
6247 break;
6249 default:
6250 bfa_sm_fault(__vport_fcs(vport), event);
6255 * LOGO is sent to fabric. Vport delete is in progress. Lport delete cleanup
6256 * is done.
6258 static void
6259 bfa_fcs_vport_sm_logo(struct bfa_fcs_vport_s *vport,
6260 enum bfa_fcs_vport_event event)
6262 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6263 bfa_trc(__vport_fcs(vport), event);
6265 switch (event) {
6266 case BFA_FCS_VPORT_SM_OFFLINE:
6267 bfa_sm_send_event(vport->lps, BFA_LPS_SM_OFFLINE);
6268 fallthrough;
6270 case BFA_FCS_VPORT_SM_RSP_OK:
6271 case BFA_FCS_VPORT_SM_RSP_ERROR:
6272 bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
6273 bfa_fcs_vport_free(vport);
6274 break;
6276 case BFA_FCS_VPORT_SM_DELETE:
6277 break;
6279 default:
6280 bfa_sm_fault(__vport_fcs(vport), event);
6287 * fcs_vport_private FCS virtual port private functions
6290 * Send AEN notification
6292 static void
6293 bfa_fcs_vport_aen_post(struct bfa_fcs_lport_s *port,
6294 enum bfa_lport_aen_event event)
6296 struct bfad_s *bfad = (struct bfad_s *)port->fabric->fcs->bfad;
6297 struct bfa_aen_entry_s *aen_entry;
6299 bfad_get_aen_entry(bfad, aen_entry);
6300 if (!aen_entry)
6301 return;
6303 aen_entry->aen_data.lport.vf_id = port->fabric->vf_id;
6304 aen_entry->aen_data.lport.roles = port->port_cfg.roles;
6305 aen_entry->aen_data.lport.ppwwn = bfa_fcs_lport_get_pwwn(
6306 bfa_fcs_get_base_port(port->fcs));
6307 aen_entry->aen_data.lport.lpwwn = bfa_fcs_lport_get_pwwn(port);
6309 /* Send the AEN notification */
6310 bfad_im_post_vendor_event(aen_entry, bfad, ++port->fcs->fcs_aen_seq,
6311 BFA_AEN_CAT_LPORT, event);
6315 * This routine will be called to send a FDISC command.
6317 static void
6318 bfa_fcs_vport_do_fdisc(struct bfa_fcs_vport_s *vport)
6320 bfa_lps_fdisc(vport->lps, vport,
6321 bfa_fcport_get_maxfrsize(__vport_bfa(vport)),
6322 __vport_pwwn(vport), __vport_nwwn(vport));
6323 vport->vport_stats.fdisc_sent++;
6326 static void
6327 bfa_fcs_vport_fdisc_rejected(struct bfa_fcs_vport_s *vport)
6329 u8 lsrjt_rsn = vport->lps->lsrjt_rsn;
6330 u8 lsrjt_expl = vport->lps->lsrjt_expl;
6332 bfa_trc(__vport_fcs(vport), lsrjt_rsn);
6333 bfa_trc(__vport_fcs(vport), lsrjt_expl);
6335 /* For certain reason codes, we don't want to retry. */
6336 switch (vport->lps->lsrjt_expl) {
6337 case FC_LS_RJT_EXP_INV_PORT_NAME: /* by brocade */
6338 case FC_LS_RJT_EXP_INVALID_NPORT_ID: /* by Cisco */
6339 if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
6340 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6341 else {
6342 bfa_fcs_vport_aen_post(&vport->lport,
6343 BFA_LPORT_AEN_NPIV_DUP_WWN);
6344 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_DUP_WWN);
6346 break;
6348 case FC_LS_RJT_EXP_INSUFF_RES:
6350 * This means max logins per port/switch setting on the
6351 * switch was exceeded.
6353 if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
6354 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6355 else {
6356 bfa_fcs_vport_aen_post(&vport->lport,
6357 BFA_LPORT_AEN_NPIV_FABRIC_MAX);
6358 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_FABRIC_MAX);
6360 break;
6362 default:
6363 if (vport->fdisc_retries == 0)
6364 bfa_fcs_vport_aen_post(&vport->lport,
6365 BFA_LPORT_AEN_NPIV_UNKNOWN);
6366 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6371 * Called to send a logout to the fabric. Used when a V-Port is
6372 * deleted/stopped.
6374 static void
6375 bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s *vport)
6377 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6379 vport->vport_stats.logo_sent++;
6380 bfa_lps_fdisclogo(vport->lps);
6385 * This routine will be called by bfa_timer on timer timeouts.
6387 * param[in] vport - pointer to bfa_fcs_vport_t.
6388 * param[out] vport_status - pointer to return vport status in
6390 * return
6391 * void
6393 * Special Considerations:
6395 * note
6397 static void
6398 bfa_fcs_vport_timeout(void *vport_arg)
6400 struct bfa_fcs_vport_s *vport = (struct bfa_fcs_vport_s *) vport_arg;
6402 vport->vport_stats.fdisc_timeouts++;
6403 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_TIMEOUT);
6406 static void
6407 bfa_fcs_vport_free(struct bfa_fcs_vport_s *vport)
6409 struct bfad_vport_s *vport_drv =
6410 (struct bfad_vport_s *)vport->vport_drv;
6412 bfa_fcs_fabric_delvport(__vport_fabric(vport), vport);
6413 bfa_lps_delete(vport->lps);
6415 if (vport_drv->comp_del) {
6416 complete(vport_drv->comp_del);
6417 return;
6421 * We queue the vport delete work to the IM work_q from here.
6422 * The memory for the bfad_vport_s is freed from the FC function
6423 * template vport_delete entry point.
6425 bfad_im_port_delete(vport_drv->drv_port.bfad, &vport_drv->drv_port);
6429 * fcs_vport_public FCS virtual port public interfaces
6433 * Online notification from fabric SM.
6435 void
6436 bfa_fcs_vport_online(struct bfa_fcs_vport_s *vport)
6438 vport->vport_stats.fab_online++;
6439 if (bfa_fcs_fabric_npiv_capable(__vport_fabric(vport)))
6440 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_ONLINE);
6441 else
6442 vport->vport_stats.fab_no_npiv++;
6446 * Offline notification from fabric SM.
6448 void
6449 bfa_fcs_vport_offline(struct bfa_fcs_vport_s *vport)
6451 vport->vport_stats.fab_offline++;
6452 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_OFFLINE);
6456 * Stop notification from fabric SM. To be invoked from within FCS.
6458 void
6459 bfa_fcs_vport_fcs_stop(struct bfa_fcs_vport_s *vport)
6461 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOP);
6465 * delete notification from fabric SM. To be invoked from within FCS.
6467 void
6468 bfa_fcs_vport_fcs_delete(struct bfa_fcs_vport_s *vport)
6470 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELETE);
6474 * Stop completion callback from associated lport
6476 void
6477 bfa_fcs_vport_stop_comp(struct bfa_fcs_vport_s *vport)
6479 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOPCOMP);
6483 * Delete completion callback from associated lport
6485 void
6486 bfa_fcs_vport_delete_comp(struct bfa_fcs_vport_s *vport)
6488 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELCOMP);
6494 * fcs_vport_api Virtual port API
6498 * Use this function to instantiate a new FCS vport object. This
6499 * function will not trigger any HW initialization process (which will be
6500 * done in vport_start() call)
6502 * param[in] vport - pointer to bfa_fcs_vport_t. This space
6503 * needs to be allocated by the driver.
6504 * param[in] fcs - FCS instance
6505 * param[in] vport_cfg - vport configuration
6506 * param[in] vf_id - VF_ID if vport is created within a VF.
6507 * FC_VF_ID_NULL to specify base fabric.
6508 * param[in] vport_drv - Opaque handle back to the driver's vport
6509 * structure
6511 * retval BFA_STATUS_OK - on success.
6512 * retval BFA_STATUS_FAILED - on failure.
6514 bfa_status_t
6515 bfa_fcs_vport_create(struct bfa_fcs_vport_s *vport, struct bfa_fcs_s *fcs,
6516 u16 vf_id, struct bfa_lport_cfg_s *vport_cfg,
6517 struct bfad_vport_s *vport_drv)
6519 if (vport_cfg->pwwn == 0)
6520 return BFA_STATUS_INVALID_WWN;
6522 if (bfa_fcs_lport_get_pwwn(&fcs->fabric.bport) == vport_cfg->pwwn)
6523 return BFA_STATUS_VPORT_WWN_BP;
6525 if (bfa_fcs_vport_lookup(fcs, vf_id, vport_cfg->pwwn) != NULL)
6526 return BFA_STATUS_VPORT_EXISTS;
6528 if (fcs->fabric.num_vports ==
6529 bfa_lps_get_max_vport(fcs->bfa))
6530 return BFA_STATUS_VPORT_MAX;
6532 vport->lps = bfa_lps_alloc(fcs->bfa);
6533 if (!vport->lps)
6534 return BFA_STATUS_VPORT_MAX;
6536 vport->vport_drv = vport_drv;
6537 vport_cfg->preboot_vp = BFA_FALSE;
6539 bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
6540 bfa_fcs_lport_attach(&vport->lport, fcs, vf_id, vport);
6541 bfa_fcs_lport_init(&vport->lport, vport_cfg);
6542 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_CREATE);
6544 return BFA_STATUS_OK;
6548 * Use this function to instantiate a new FCS PBC vport object. This
6549 * function will not trigger any HW initialization process (which will be
6550 * done in vport_start() call)
6552 * param[in] vport - pointer to bfa_fcs_vport_t. This space
6553 * needs to be allocated by the driver.
6554 * param[in] fcs - FCS instance
6555 * param[in] vport_cfg - vport configuration
6556 * param[in] vf_id - VF_ID if vport is created within a VF.
6557 * FC_VF_ID_NULL to specify base fabric.
6558 * param[in] vport_drv - Opaque handle back to the driver's vport
6559 * structure
6561 * retval BFA_STATUS_OK - on success.
6562 * retval BFA_STATUS_FAILED - on failure.
6564 bfa_status_t
6565 bfa_fcs_pbc_vport_create(struct bfa_fcs_vport_s *vport, struct bfa_fcs_s *fcs,
6566 u16 vf_id, struct bfa_lport_cfg_s *vport_cfg,
6567 struct bfad_vport_s *vport_drv)
6569 bfa_status_t rc;
6571 rc = bfa_fcs_vport_create(vport, fcs, vf_id, vport_cfg, vport_drv);
6572 vport->lport.port_cfg.preboot_vp = BFA_TRUE;
6574 return rc;
6578 * Use this function initialize the vport.
6580 * @param[in] vport - pointer to bfa_fcs_vport_t.
6582 * @returns None
6584 bfa_status_t
6585 bfa_fcs_vport_start(struct bfa_fcs_vport_s *vport)
6587 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_START);
6589 return BFA_STATUS_OK;
6593 * Use this function quiese the vport object. This function will return
6594 * immediately, when the vport is actually stopped, the
6595 * bfa_drv_vport_stop_cb() will be called.
6597 * param[in] vport - pointer to bfa_fcs_vport_t.
6599 * return None
6601 bfa_status_t
6602 bfa_fcs_vport_stop(struct bfa_fcs_vport_s *vport)
6604 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOP);
6606 return BFA_STATUS_OK;
6610 * Use this function to delete a vport object. Fabric object should
6611 * be stopped before this function call.
6613 * !!!!!!! Donot invoke this from within FCS !!!!!!!
6615 * param[in] vport - pointer to bfa_fcs_vport_t.
6617 * return None
6619 bfa_status_t
6620 bfa_fcs_vport_delete(struct bfa_fcs_vport_s *vport)
6623 if (vport->lport.port_cfg.preboot_vp)
6624 return BFA_STATUS_PBC;
6626 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELETE);
6628 return BFA_STATUS_OK;
6632 * Use this function to get vport's current status info.
6634 * param[in] vport pointer to bfa_fcs_vport_t.
6635 * param[out] attr pointer to return vport attributes
6637 * return None
6639 void
6640 bfa_fcs_vport_get_attr(struct bfa_fcs_vport_s *vport,
6641 struct bfa_vport_attr_s *attr)
6643 if (vport == NULL || attr == NULL)
6644 return;
6646 memset(attr, 0, sizeof(struct bfa_vport_attr_s));
6648 bfa_fcs_lport_get_attr(&vport->lport, &attr->port_attr);
6649 attr->vport_state = bfa_vport_sm_to_state(vport_sm_table, vport->sm);
6654 * Lookup a virtual port. Excludes base port from lookup.
6656 struct bfa_fcs_vport_s *
6657 bfa_fcs_vport_lookup(struct bfa_fcs_s *fcs, u16 vf_id, wwn_t vpwwn)
6659 struct bfa_fcs_vport_s *vport;
6660 struct bfa_fcs_fabric_s *fabric;
6662 bfa_trc(fcs, vf_id);
6663 bfa_trc(fcs, vpwwn);
6665 fabric = bfa_fcs_vf_lookup(fcs, vf_id);
6666 if (!fabric) {
6667 bfa_trc(fcs, vf_id);
6668 return NULL;
6671 vport = bfa_fcs_fabric_vport_lookup(fabric, vpwwn);
6672 return vport;
6676 * FDISC Response
6678 void
6679 bfa_cb_lps_fdisc_comp(void *bfad, void *uarg, bfa_status_t status)
6681 struct bfa_fcs_vport_s *vport = uarg;
6683 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
6684 bfa_trc(__vport_fcs(vport), status);
6686 switch (status) {
6687 case BFA_STATUS_OK:
6689 * Initialize the V-Port fields
6691 __vport_fcid(vport) = vport->lps->lp_pid;
6692 vport->vport_stats.fdisc_accepts++;
6693 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_OK);
6694 break;
6696 case BFA_STATUS_INVALID_MAC:
6697 /* Only for CNA */
6698 vport->vport_stats.fdisc_acc_bad++;
6699 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6701 break;
6703 case BFA_STATUS_EPROTOCOL:
6704 switch (vport->lps->ext_status) {
6705 case BFA_EPROTO_BAD_ACCEPT:
6706 vport->vport_stats.fdisc_acc_bad++;
6707 break;
6709 case BFA_EPROTO_UNKNOWN_RSP:
6710 vport->vport_stats.fdisc_unknown_rsp++;
6711 break;
6713 default:
6714 break;
6717 if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
6718 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6719 else
6720 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_FAILED);
6722 break;
6724 case BFA_STATUS_ETIMER:
6725 vport->vport_stats.fdisc_timeouts++;
6726 if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
6727 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6728 else
6729 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_FAILED);
6730 break;
6732 case BFA_STATUS_FABRIC_RJT:
6733 vport->vport_stats.fdisc_rejects++;
6734 bfa_fcs_vport_fdisc_rejected(vport);
6735 break;
6737 default:
6738 vport->vport_stats.fdisc_rsp_err++;
6739 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
6744 * LOGO response
6746 void
6747 bfa_cb_lps_fdisclogo_comp(void *bfad, void *uarg)
6749 struct bfa_fcs_vport_s *vport = uarg;
6750 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_OK);
6754 * Received clear virtual link
6756 void
6757 bfa_cb_lps_cvl_event(void *bfad, void *uarg)
6759 struct bfa_fcs_vport_s *vport = uarg;
6761 /* Send an Offline followed by an ONLINE */
6762 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_OFFLINE);
6763 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_ONLINE);