2 * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License (GPL) Version 2 as
10 * published by the Free Software Foundation
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
20 #include <bfi/bfi_pport.h>
21 #include <bfi/bfi_pbc.h>
22 #include <cs/bfa_debug.h>
23 #include <aen/bfa_aen.h>
24 #include <cs/bfa_plog.h>
25 #include <aen/bfa_aen_port.h>
27 BFA_TRC_FILE(HAL
, FCPORT
);
31 * The port is considered disabled if corresponding physical port or IOC are
34 #define BFA_PORT_IS_DISABLED(bfa) \
35 ((bfa_fcport_is_disabled(bfa) == BFA_TRUE) || \
36 (bfa_ioc_is_disabled(&bfa->ioc) == BFA_TRUE))
39 * forward declarations
41 static bfa_boolean_t
bfa_fcport_send_enable(struct bfa_fcport_s
*fcport
);
42 static bfa_boolean_t
bfa_fcport_send_disable(struct bfa_fcport_s
*fcport
);
43 static void bfa_fcport_update_linkinfo(struct bfa_fcport_s
*fcport
);
44 static void bfa_fcport_reset_linkinfo(struct bfa_fcport_s
*fcport
);
45 static void bfa_fcport_set_wwns(struct bfa_fcport_s
*fcport
);
46 static void __bfa_cb_fcport_event(void *cbarg
, bfa_boolean_t complete
);
47 static void bfa_fcport_callback(struct bfa_fcport_s
*fcport
,
48 enum bfa_pport_linkstate event
);
49 static void bfa_fcport_queue_cb(struct bfa_fcport_ln_s
*ln
,
50 enum bfa_pport_linkstate event
);
51 static void __bfa_cb_fcport_stats_clr(void *cbarg
, bfa_boolean_t complete
);
52 static void bfa_fcport_stats_get_timeout(void *cbarg
);
53 static void bfa_fcport_stats_clr_timeout(void *cbarg
);
60 * BFA port state machine events
62 enum bfa_fcport_sm_event
{
63 BFA_FCPORT_SM_START
= 1, /* start port state machine */
64 BFA_FCPORT_SM_STOP
= 2, /* stop port state machine */
65 BFA_FCPORT_SM_ENABLE
= 3, /* enable port */
66 BFA_FCPORT_SM_DISABLE
= 4, /* disable port state machine */
67 BFA_FCPORT_SM_FWRSP
= 5, /* firmware enable/disable rsp */
68 BFA_FCPORT_SM_LINKUP
= 6, /* firmware linkup event */
69 BFA_FCPORT_SM_LINKDOWN
= 7, /* firmware linkup down */
70 BFA_FCPORT_SM_QRESUME
= 8, /* CQ space available */
71 BFA_FCPORT_SM_HWFAIL
= 9, /* IOC h/w failure */
75 * BFA port link notification state machine events
78 enum bfa_fcport_ln_sm_event
{
79 BFA_FCPORT_LN_SM_LINKUP
= 1, /* linkup event */
80 BFA_FCPORT_LN_SM_LINKDOWN
= 2, /* linkdown event */
81 BFA_FCPORT_LN_SM_NOTIFICATION
= 3 /* done notification */
84 static void bfa_fcport_sm_uninit(struct bfa_fcport_s
*fcport
,
85 enum bfa_fcport_sm_event event
);
86 static void bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s
*fcport
,
87 enum bfa_fcport_sm_event event
);
88 static void bfa_fcport_sm_enabling(struct bfa_fcport_s
*fcport
,
89 enum bfa_fcport_sm_event event
);
90 static void bfa_fcport_sm_linkdown(struct bfa_fcport_s
*fcport
,
91 enum bfa_fcport_sm_event event
);
92 static void bfa_fcport_sm_linkup(struct bfa_fcport_s
*fcport
,
93 enum bfa_fcport_sm_event event
);
94 static void bfa_fcport_sm_disabling(struct bfa_fcport_s
*fcport
,
95 enum bfa_fcport_sm_event event
);
96 static void bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s
*fcport
,
97 enum bfa_fcport_sm_event event
);
98 static void bfa_fcport_sm_disabled(struct bfa_fcport_s
*fcport
,
99 enum bfa_fcport_sm_event event
);
100 static void bfa_fcport_sm_stopped(struct bfa_fcport_s
*fcport
,
101 enum bfa_fcport_sm_event event
);
102 static void bfa_fcport_sm_iocdown(struct bfa_fcport_s
*fcport
,
103 enum bfa_fcport_sm_event event
);
104 static void bfa_fcport_sm_iocfail(struct bfa_fcport_s
*fcport
,
105 enum bfa_fcport_sm_event event
);
107 static void bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s
*ln
,
108 enum bfa_fcport_ln_sm_event event
);
109 static void bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s
*ln
,
110 enum bfa_fcport_ln_sm_event event
);
111 static void bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s
*ln
,
112 enum bfa_fcport_ln_sm_event event
);
113 static void bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s
*ln
,
114 enum bfa_fcport_ln_sm_event event
);
115 static void bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s
*ln
,
116 enum bfa_fcport_ln_sm_event event
);
117 static void bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s
*ln
,
118 enum bfa_fcport_ln_sm_event event
);
119 static void bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s
*ln
,
120 enum bfa_fcport_ln_sm_event event
);
122 static struct bfa_sm_table_s hal_pport_sm_table
[] = {
123 {BFA_SM(bfa_fcport_sm_uninit
), BFA_PPORT_ST_UNINIT
},
124 {BFA_SM(bfa_fcport_sm_enabling_qwait
), BFA_PPORT_ST_ENABLING_QWAIT
},
125 {BFA_SM(bfa_fcport_sm_enabling
), BFA_PPORT_ST_ENABLING
},
126 {BFA_SM(bfa_fcport_sm_linkdown
), BFA_PPORT_ST_LINKDOWN
},
127 {BFA_SM(bfa_fcport_sm_linkup
), BFA_PPORT_ST_LINKUP
},
128 {BFA_SM(bfa_fcport_sm_disabling_qwait
), BFA_PPORT_ST_DISABLING_QWAIT
},
129 {BFA_SM(bfa_fcport_sm_disabling
), BFA_PPORT_ST_DISABLING
},
130 {BFA_SM(bfa_fcport_sm_disabled
), BFA_PPORT_ST_DISABLED
},
131 {BFA_SM(bfa_fcport_sm_stopped
), BFA_PPORT_ST_STOPPED
},
132 {BFA_SM(bfa_fcport_sm_iocdown
), BFA_PPORT_ST_IOCDOWN
},
133 {BFA_SM(bfa_fcport_sm_iocfail
), BFA_PPORT_ST_IOCDOWN
},
137 bfa_fcport_aen_post(struct bfa_fcport_s
*fcport
, enum bfa_port_aen_event event
)
139 union bfa_aen_data_u aen_data
;
140 struct bfa_log_mod_s
*logmod
= fcport
->bfa
->logm
;
141 wwn_t pwwn
= fcport
->pwwn
;
142 char pwwn_ptr
[BFA_STRING_32
];
144 memset(&aen_data
, 0, sizeof(aen_data
));
145 wwn2str(pwwn_ptr
, pwwn
);
146 bfa_log(logmod
, BFA_LOG_CREATE_ID(BFA_AEN_CAT_PORT
, event
), pwwn_ptr
);
148 aen_data
.port
.ioc_type
= bfa_get_type(fcport
->bfa
);
149 aen_data
.port
.pwwn
= pwwn
;
153 bfa_fcport_sm_uninit(struct bfa_fcport_s
*fcport
,
154 enum bfa_fcport_sm_event event
)
156 bfa_trc(fcport
->bfa
, event
);
159 case BFA_FCPORT_SM_START
:
161 * Start event after IOC is configured and BFA is started.
163 if (bfa_fcport_send_enable(fcport
))
164 bfa_sm_set_state(fcport
, bfa_fcport_sm_enabling
);
166 bfa_sm_set_state(fcport
, bfa_fcport_sm_enabling_qwait
);
169 case BFA_FCPORT_SM_ENABLE
:
171 * Port is persistently configured to be in enabled state. Do
172 * not change state. Port enabling is done when START event is
177 case BFA_FCPORT_SM_DISABLE
:
179 * If a port is persistently configured to be disabled, the
180 * first event will a port disable request.
182 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabled
);
185 case BFA_FCPORT_SM_HWFAIL
:
186 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocdown
);
190 bfa_sm_fault(fcport
->bfa
, event
);
195 bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s
*fcport
,
196 enum bfa_fcport_sm_event event
)
198 bfa_trc(fcport
->bfa
, event
);
201 case BFA_FCPORT_SM_QRESUME
:
202 bfa_sm_set_state(fcport
, bfa_fcport_sm_enabling
);
203 bfa_fcport_send_enable(fcport
);
206 case BFA_FCPORT_SM_STOP
:
207 bfa_reqq_wcancel(&fcport
->reqq_wait
);
208 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
211 case BFA_FCPORT_SM_ENABLE
:
213 * Already enable is in progress.
217 case BFA_FCPORT_SM_DISABLE
:
219 * Just send disable request to firmware when room becomes
220 * available in request queue.
222 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabled
);
223 bfa_reqq_wcancel(&fcport
->reqq_wait
);
224 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
225 BFA_PL_EID_PORT_DISABLE
, 0, "Port Disable");
226 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISABLE
);
229 case BFA_FCPORT_SM_LINKUP
:
230 case BFA_FCPORT_SM_LINKDOWN
:
232 * Possible to get link events when doing back-to-back
237 case BFA_FCPORT_SM_HWFAIL
:
238 bfa_reqq_wcancel(&fcport
->reqq_wait
);
239 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocdown
);
243 bfa_sm_fault(fcport
->bfa
, event
);
248 bfa_fcport_sm_enabling(struct bfa_fcport_s
*fcport
,
249 enum bfa_fcport_sm_event event
)
251 bfa_trc(fcport
->bfa
, event
);
254 case BFA_FCPORT_SM_FWRSP
:
255 case BFA_FCPORT_SM_LINKDOWN
:
256 bfa_sm_set_state(fcport
, bfa_fcport_sm_linkdown
);
259 case BFA_FCPORT_SM_LINKUP
:
260 bfa_fcport_update_linkinfo(fcport
);
261 bfa_sm_set_state(fcport
, bfa_fcport_sm_linkup
);
263 bfa_assert(fcport
->event_cbfn
);
264 bfa_fcport_callback(fcport
, BFA_PPORT_LINKUP
);
267 case BFA_FCPORT_SM_ENABLE
:
269 * Already being enabled.
273 case BFA_FCPORT_SM_DISABLE
:
274 if (bfa_fcport_send_disable(fcport
))
275 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabling
);
277 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabling_qwait
);
279 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
280 BFA_PL_EID_PORT_DISABLE
, 0, "Port Disable");
281 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISABLE
);
284 case BFA_FCPORT_SM_STOP
:
285 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
288 case BFA_FCPORT_SM_HWFAIL
:
289 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocdown
);
293 bfa_sm_fault(fcport
->bfa
, event
);
298 bfa_fcport_sm_linkdown(struct bfa_fcport_s
*fcport
,
299 enum bfa_fcport_sm_event event
)
301 struct bfi_fcport_event_s
*pevent
= fcport
->event_arg
.i2hmsg
.event
;
302 bfa_trc(fcport
->bfa
, event
);
305 case BFA_FCPORT_SM_LINKUP
:
306 bfa_fcport_update_linkinfo(fcport
);
307 bfa_sm_set_state(fcport
, bfa_fcport_sm_linkup
);
308 bfa_assert(fcport
->event_cbfn
);
309 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
310 BFA_PL_EID_PORT_ST_CHANGE
, 0, "Port Linkup");
312 if (!bfa_ioc_get_fcmode(&fcport
->bfa
->ioc
)) {
315 pevent
->link_state
.vc_fcf
.fcf
.fipenabled
);
317 pevent
->link_state
.vc_fcf
.fcf
.fipfailed
);
319 if (pevent
->link_state
.vc_fcf
.fcf
.fipfailed
)
320 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
321 BFA_PL_EID_FIP_FCF_DISC
, 0,
322 "FIP FCF Discovery Failed");
324 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
325 BFA_PL_EID_FIP_FCF_DISC
, 0,
326 "FIP FCF Discovered");
329 bfa_fcport_callback(fcport
, BFA_PPORT_LINKUP
);
330 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_ONLINE
);
332 * If QoS is enabled and it is not online,
333 * Send a separate event.
335 if ((fcport
->cfg
.qos_enabled
)
336 && (bfa_os_ntohl(fcport
->qos_attr
.state
) != BFA_QOS_ONLINE
))
337 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_QOS_NEG
);
341 case BFA_FCPORT_SM_LINKDOWN
:
343 * Possible to get link down event.
347 case BFA_FCPORT_SM_ENABLE
:
353 case BFA_FCPORT_SM_DISABLE
:
354 if (bfa_fcport_send_disable(fcport
))
355 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabling
);
357 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabling_qwait
);
359 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
360 BFA_PL_EID_PORT_DISABLE
, 0, "Port Disable");
361 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISABLE
);
364 case BFA_FCPORT_SM_STOP
:
365 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
368 case BFA_FCPORT_SM_HWFAIL
:
369 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocdown
);
373 bfa_sm_fault(fcport
->bfa
, event
);
378 bfa_fcport_sm_linkup(struct bfa_fcport_s
*fcport
,
379 enum bfa_fcport_sm_event event
)
381 bfa_trc(fcport
->bfa
, event
);
384 case BFA_FCPORT_SM_ENABLE
:
390 case BFA_FCPORT_SM_DISABLE
:
391 if (bfa_fcport_send_disable(fcport
))
392 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabling
);
394 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabling_qwait
);
396 bfa_fcport_reset_linkinfo(fcport
);
397 bfa_fcport_callback(fcport
, BFA_PPORT_LINKDOWN
);
398 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
399 BFA_PL_EID_PORT_DISABLE
, 0, "Port Disable");
400 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_OFFLINE
);
401 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISABLE
);
404 case BFA_FCPORT_SM_LINKDOWN
:
405 bfa_sm_set_state(fcport
, bfa_fcport_sm_linkdown
);
406 bfa_fcport_reset_linkinfo(fcport
);
407 bfa_fcport_callback(fcport
, BFA_PPORT_LINKDOWN
);
408 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
409 BFA_PL_EID_PORT_ST_CHANGE
, 0, "Port Linkdown");
410 if (BFA_PORT_IS_DISABLED(fcport
->bfa
))
411 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_OFFLINE
);
413 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISCONNECT
);
416 case BFA_FCPORT_SM_STOP
:
417 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
418 bfa_fcport_reset_linkinfo(fcport
);
419 if (BFA_PORT_IS_DISABLED(fcport
->bfa
))
420 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_OFFLINE
);
422 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISCONNECT
);
425 case BFA_FCPORT_SM_HWFAIL
:
426 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocdown
);
427 bfa_fcport_reset_linkinfo(fcport
);
428 bfa_fcport_callback(fcport
, BFA_PPORT_LINKDOWN
);
429 if (BFA_PORT_IS_DISABLED(fcport
->bfa
))
430 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_OFFLINE
);
432 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISCONNECT
);
436 bfa_sm_fault(fcport
->bfa
, event
);
441 bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s
*fcport
,
442 enum bfa_fcport_sm_event event
)
444 bfa_trc(fcport
->bfa
, event
);
447 case BFA_FCPORT_SM_QRESUME
:
448 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabling
);
449 bfa_fcport_send_disable(fcport
);
452 case BFA_FCPORT_SM_STOP
:
453 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
454 bfa_reqq_wcancel(&fcport
->reqq_wait
);
457 case BFA_FCPORT_SM_DISABLE
:
459 * Already being disabled.
463 case BFA_FCPORT_SM_LINKUP
:
464 case BFA_FCPORT_SM_LINKDOWN
:
466 * Possible to get link events when doing back-to-back
471 case BFA_FCPORT_SM_HWFAIL
:
472 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocfail
);
473 bfa_reqq_wcancel(&fcport
->reqq_wait
);
477 bfa_sm_fault(fcport
->bfa
, event
);
482 bfa_fcport_sm_disabling(struct bfa_fcport_s
*fcport
,
483 enum bfa_fcport_sm_event event
)
485 bfa_trc(fcport
->bfa
, event
);
488 case BFA_FCPORT_SM_FWRSP
:
489 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabled
);
492 case BFA_FCPORT_SM_DISABLE
:
494 * Already being disabled.
498 case BFA_FCPORT_SM_ENABLE
:
499 if (bfa_fcport_send_enable(fcport
))
500 bfa_sm_set_state(fcport
, bfa_fcport_sm_enabling
);
502 bfa_sm_set_state(fcport
, bfa_fcport_sm_enabling_qwait
);
504 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
505 BFA_PL_EID_PORT_ENABLE
, 0, "Port Enable");
506 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_ENABLE
);
509 case BFA_FCPORT_SM_STOP
:
510 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
513 case BFA_FCPORT_SM_LINKUP
:
514 case BFA_FCPORT_SM_LINKDOWN
:
516 * Possible to get link events when doing back-to-back
521 case BFA_FCPORT_SM_HWFAIL
:
522 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocfail
);
526 bfa_sm_fault(fcport
->bfa
, event
);
531 bfa_fcport_sm_disabled(struct bfa_fcport_s
*fcport
,
532 enum bfa_fcport_sm_event event
)
534 bfa_trc(fcport
->bfa
, event
);
537 case BFA_FCPORT_SM_START
:
539 * Ignore start event for a port that is disabled.
543 case BFA_FCPORT_SM_STOP
:
544 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
547 case BFA_FCPORT_SM_ENABLE
:
548 if (bfa_fcport_send_enable(fcport
))
549 bfa_sm_set_state(fcport
, bfa_fcport_sm_enabling
);
551 bfa_sm_set_state(fcport
, bfa_fcport_sm_enabling_qwait
);
553 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
554 BFA_PL_EID_PORT_ENABLE
, 0, "Port Enable");
555 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_ENABLE
);
558 case BFA_FCPORT_SM_DISABLE
:
564 case BFA_FCPORT_SM_HWFAIL
:
565 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocfail
);
569 bfa_sm_fault(fcport
->bfa
, event
);
574 bfa_fcport_sm_stopped(struct bfa_fcport_s
*fcport
,
575 enum bfa_fcport_sm_event event
)
577 bfa_trc(fcport
->bfa
, event
);
580 case BFA_FCPORT_SM_START
:
581 if (bfa_fcport_send_enable(fcport
))
582 bfa_sm_set_state(fcport
, bfa_fcport_sm_enabling
);
584 bfa_sm_set_state(fcport
, bfa_fcport_sm_enabling_qwait
);
589 * Ignore all other events.
596 * Port is enabled. IOC is down/failed.
599 bfa_fcport_sm_iocdown(struct bfa_fcport_s
*fcport
,
600 enum bfa_fcport_sm_event event
)
602 bfa_trc(fcport
->bfa
, event
);
605 case BFA_FCPORT_SM_START
:
606 if (bfa_fcport_send_enable(fcport
))
607 bfa_sm_set_state(fcport
, bfa_fcport_sm_enabling
);
609 bfa_sm_set_state(fcport
, bfa_fcport_sm_enabling_qwait
);
621 * Port is disabled. IOC is down/failed.
624 bfa_fcport_sm_iocfail(struct bfa_fcport_s
*fcport
,
625 enum bfa_fcport_sm_event event
)
627 bfa_trc(fcport
->bfa
, event
);
630 case BFA_FCPORT_SM_START
:
631 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabled
);
634 case BFA_FCPORT_SM_ENABLE
:
635 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocdown
);
650 bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s
*ln
,
651 enum bfa_fcport_ln_sm_event event
)
653 bfa_trc(ln
->fcport
->bfa
, event
);
656 case BFA_FCPORT_LN_SM_LINKUP
:
657 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_up_nf
);
658 bfa_fcport_queue_cb(ln
, BFA_PPORT_LINKUP
);
662 bfa_sm_fault(ln
->fcport
->bfa
, event
);
667 * Link state is waiting for down notification
670 bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s
*ln
,
671 enum bfa_fcport_ln_sm_event event
)
673 bfa_trc(ln
->fcport
->bfa
, event
);
676 case BFA_FCPORT_LN_SM_LINKUP
:
677 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_dn_up_nf
);
680 case BFA_FCPORT_LN_SM_NOTIFICATION
:
681 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_dn
);
685 bfa_sm_fault(ln
->fcport
->bfa
, event
);
690 * Link state is waiting for down notification and there is a pending up
693 bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s
*ln
,
694 enum bfa_fcport_ln_sm_event event
)
696 bfa_trc(ln
->fcport
->bfa
, event
);
699 case BFA_FCPORT_LN_SM_LINKDOWN
:
700 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_dn_nf
);
703 case BFA_FCPORT_LN_SM_NOTIFICATION
:
704 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_up_nf
);
705 bfa_fcport_queue_cb(ln
, BFA_PPORT_LINKUP
);
709 bfa_sm_fault(ln
->fcport
->bfa
, event
);
717 bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s
*ln
,
718 enum bfa_fcport_ln_sm_event event
)
720 bfa_trc(ln
->fcport
->bfa
, event
);
723 case BFA_FCPORT_LN_SM_LINKDOWN
:
724 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_dn_nf
);
725 bfa_fcport_queue_cb(ln
, BFA_PPORT_LINKDOWN
);
729 bfa_sm_fault(ln
->fcport
->bfa
, event
);
734 * Link state is waiting for up notification
737 bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s
*ln
,
738 enum bfa_fcport_ln_sm_event event
)
740 bfa_trc(ln
->fcport
->bfa
, event
);
743 case BFA_FCPORT_LN_SM_LINKDOWN
:
744 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_up_dn_nf
);
747 case BFA_FCPORT_LN_SM_NOTIFICATION
:
748 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_up
);
752 bfa_sm_fault(ln
->fcport
->bfa
, event
);
757 * Link state is waiting for up notification and there is a pending down
760 bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s
*ln
,
761 enum bfa_fcport_ln_sm_event event
)
763 bfa_trc(ln
->fcport
->bfa
, event
);
766 case BFA_FCPORT_LN_SM_LINKUP
:
767 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_up_dn_up_nf
);
770 case BFA_FCPORT_LN_SM_NOTIFICATION
:
771 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_dn_nf
);
772 bfa_fcport_queue_cb(ln
, BFA_PPORT_LINKDOWN
);
776 bfa_sm_fault(ln
->fcport
->bfa
, event
);
781 * Link state is waiting for up notification and there are pending down and up
784 bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s
*ln
,
785 enum bfa_fcport_ln_sm_event event
)
787 bfa_trc(ln
->fcport
->bfa
, event
);
790 case BFA_FCPORT_LN_SM_LINKDOWN
:
791 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_up_dn_nf
);
794 case BFA_FCPORT_LN_SM_NOTIFICATION
:
795 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_dn_up_nf
);
796 bfa_fcport_queue_cb(ln
, BFA_PPORT_LINKDOWN
);
800 bfa_sm_fault(ln
->fcport
->bfa
, event
);
809 __bfa_cb_fcport_event(void *cbarg
, bfa_boolean_t complete
)
811 struct bfa_fcport_ln_s
*ln
= cbarg
;
814 ln
->fcport
->event_cbfn(ln
->fcport
->event_cbarg
, ln
->ln_event
);
816 bfa_sm_send_event(ln
, BFA_FCPORT_LN_SM_NOTIFICATION
);
820 bfa_fcport_callback(struct bfa_fcport_s
*fcport
, enum bfa_pport_linkstate event
)
822 if (fcport
->bfa
->fcs
) {
823 fcport
->event_cbfn(fcport
->event_cbarg
, event
);
828 case BFA_PPORT_LINKUP
:
829 bfa_sm_send_event(&fcport
->ln
, BFA_FCPORT_LN_SM_LINKUP
);
831 case BFA_PPORT_LINKDOWN
:
832 bfa_sm_send_event(&fcport
->ln
, BFA_FCPORT_LN_SM_LINKDOWN
);
840 bfa_fcport_queue_cb(struct bfa_fcport_ln_s
*ln
, enum bfa_pport_linkstate event
)
842 ln
->ln_event
= event
;
843 bfa_cb_queue(ln
->fcport
->bfa
, &ln
->ln_qe
, __bfa_cb_fcport_event
, ln
);
846 #define FCPORT_STATS_DMA_SZ (BFA_ROUNDUP(sizeof(union bfa_fcport_stats_u), \
850 bfa_fcport_meminfo(struct bfa_iocfc_cfg_s
*cfg
, u32
*ndm_len
,
853 *dm_len
+= FCPORT_STATS_DMA_SZ
;
857 bfa_fcport_qresume(void *cbarg
)
859 struct bfa_fcport_s
*fcport
= cbarg
;
861 bfa_sm_send_event(fcport
, BFA_FCPORT_SM_QRESUME
);
865 bfa_fcport_mem_claim(struct bfa_fcport_s
*fcport
, struct bfa_meminfo_s
*meminfo
)
870 dm_kva
= bfa_meminfo_dma_virt(meminfo
);
871 dm_pa
= bfa_meminfo_dma_phys(meminfo
);
873 fcport
->stats_kva
= dm_kva
;
874 fcport
->stats_pa
= dm_pa
;
875 fcport
->stats
= (union bfa_fcport_stats_u
*)dm_kva
;
877 dm_kva
+= FCPORT_STATS_DMA_SZ
;
878 dm_pa
+= FCPORT_STATS_DMA_SZ
;
880 bfa_meminfo_dma_virt(meminfo
) = dm_kva
;
881 bfa_meminfo_dma_phys(meminfo
) = dm_pa
;
885 * Memory initialization.
888 bfa_fcport_attach(struct bfa_s
*bfa
, void *bfad
, struct bfa_iocfc_cfg_s
*cfg
,
889 struct bfa_meminfo_s
*meminfo
, struct bfa_pcidev_s
*pcidev
)
891 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
892 struct bfa_pport_cfg_s
*port_cfg
= &fcport
->cfg
;
893 struct bfa_fcport_ln_s
*ln
= &fcport
->ln
;
894 struct bfa_timeval_s tv
;
896 bfa_os_memset(fcport
, 0, sizeof(struct bfa_fcport_s
));
900 bfa_fcport_mem_claim(fcport
, meminfo
);
902 bfa_sm_set_state(fcport
, bfa_fcport_sm_uninit
);
903 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_dn
);
906 * initialize time stamp for stats reset
908 bfa_os_gettimeofday(&tv
);
909 fcport
->stats_reset_time
= tv
.tv_sec
;
912 * initialize and set default configuration
914 port_cfg
->topology
= BFA_PPORT_TOPOLOGY_P2P
;
915 port_cfg
->speed
= BFA_PPORT_SPEED_AUTO
;
916 port_cfg
->trunked
= BFA_FALSE
;
917 port_cfg
->maxfrsize
= 0;
919 port_cfg
->trl_def_speed
= BFA_PPORT_SPEED_1GBPS
;
921 bfa_reqq_winit(&fcport
->reqq_wait
, bfa_fcport_qresume
, fcport
);
925 bfa_fcport_detach(struct bfa_s
*bfa
)
930 * Called when IOC is ready.
933 bfa_fcport_start(struct bfa_s
*bfa
)
935 bfa_sm_send_event(BFA_FCPORT_MOD(bfa
), BFA_FCPORT_SM_START
);
939 * Called before IOC is stopped.
942 bfa_fcport_stop(struct bfa_s
*bfa
)
944 bfa_sm_send_event(BFA_FCPORT_MOD(bfa
), BFA_FCPORT_SM_STOP
);
948 * Called when IOC failure is detected.
951 bfa_fcport_iocdisable(struct bfa_s
*bfa
)
953 bfa_sm_send_event(BFA_FCPORT_MOD(bfa
), BFA_FCPORT_SM_HWFAIL
);
957 bfa_fcport_update_linkinfo(struct bfa_fcport_s
*fcport
)
959 struct bfi_fcport_event_s
*pevent
= fcport
->event_arg
.i2hmsg
.event
;
961 fcport
->speed
= pevent
->link_state
.speed
;
962 fcport
->topology
= pevent
->link_state
.topology
;
964 if (fcport
->topology
== BFA_PPORT_TOPOLOGY_LOOP
)
970 bfa_os_assign(fcport
->qos_attr
, pevent
->link_state
.qos_attr
);
971 bfa_os_assign(fcport
->qos_vc_attr
,
972 pevent
->link_state
.vc_fcf
.qos_vc_attr
);
975 bfa_trc(fcport
->bfa
, fcport
->speed
);
976 bfa_trc(fcport
->bfa
, fcport
->topology
);
980 bfa_fcport_reset_linkinfo(struct bfa_fcport_s
*fcport
)
982 fcport
->speed
= BFA_PPORT_SPEED_UNKNOWN
;
983 fcport
->topology
= BFA_PPORT_TOPOLOGY_NONE
;
987 * Send port enable message to firmware.
990 bfa_fcport_send_enable(struct bfa_fcport_s
*fcport
)
992 struct bfi_fcport_enable_req_s
*m
;
995 * Increment message tag before queue check, so that responses to old
996 * requests are discarded.
1001 * check for room in queue to send request now
1003 m
= bfa_reqq_next(fcport
->bfa
, BFA_REQQ_PORT
);
1005 bfa_reqq_wait(fcport
->bfa
, BFA_REQQ_PORT
,
1006 &fcport
->reqq_wait
);
1010 bfi_h2i_set(m
->mh
, BFI_MC_FCPORT
, BFI_FCPORT_H2I_ENABLE_REQ
,
1011 bfa_lpuid(fcport
->bfa
));
1012 m
->nwwn
= fcport
->nwwn
;
1013 m
->pwwn
= fcport
->pwwn
;
1014 m
->port_cfg
= fcport
->cfg
;
1015 m
->msgtag
= fcport
->msgtag
;
1016 m
->port_cfg
.maxfrsize
= bfa_os_htons(fcport
->cfg
.maxfrsize
);
1017 bfa_dma_be_addr_set(m
->stats_dma_addr
, fcport
->stats_pa
);
1018 bfa_trc(fcport
->bfa
, m
->stats_dma_addr
.a32
.addr_lo
);
1019 bfa_trc(fcport
->bfa
, m
->stats_dma_addr
.a32
.addr_hi
);
1022 * queue I/O message to firmware
1024 bfa_reqq_produce(fcport
->bfa
, BFA_REQQ_PORT
);
1029 * Send port disable message to firmware.
1031 static bfa_boolean_t
1032 bfa_fcport_send_disable(struct bfa_fcport_s
*fcport
)
1034 struct bfi_fcport_req_s
*m
;
1037 * Increment message tag before queue check, so that responses to old
1038 * requests are discarded.
1043 * check for room in queue to send request now
1045 m
= bfa_reqq_next(fcport
->bfa
, BFA_REQQ_PORT
);
1047 bfa_reqq_wait(fcport
->bfa
, BFA_REQQ_PORT
,
1048 &fcport
->reqq_wait
);
1052 bfi_h2i_set(m
->mh
, BFI_MC_FCPORT
, BFI_FCPORT_H2I_DISABLE_REQ
,
1053 bfa_lpuid(fcport
->bfa
));
1054 m
->msgtag
= fcport
->msgtag
;
1057 * queue I/O message to firmware
1059 bfa_reqq_produce(fcport
->bfa
, BFA_REQQ_PORT
);
1065 bfa_fcport_set_wwns(struct bfa_fcport_s
*fcport
)
1067 fcport
->pwwn
= bfa_ioc_get_pwwn(&fcport
->bfa
->ioc
);
1068 fcport
->nwwn
= bfa_ioc_get_nwwn(&fcport
->bfa
->ioc
);
1070 bfa_trc(fcport
->bfa
, fcport
->pwwn
);
1071 bfa_trc(fcport
->bfa
, fcport
->nwwn
);
1075 bfa_fcport_send_txcredit(void *port_cbarg
)
1078 struct bfa_fcport_s
*fcport
= port_cbarg
;
1079 struct bfi_fcport_set_svc_params_req_s
*m
;
1082 * check for room in queue to send request now
1084 m
= bfa_reqq_next(fcport
->bfa
, BFA_REQQ_PORT
);
1086 bfa_trc(fcport
->bfa
, fcport
->cfg
.tx_bbcredit
);
1090 bfi_h2i_set(m
->mh
, BFI_MC_FCPORT
, BFI_FCPORT_H2I_SET_SVC_PARAMS_REQ
,
1091 bfa_lpuid(fcport
->bfa
));
1092 m
->tx_bbcredit
= bfa_os_htons((u16
) fcport
->cfg
.tx_bbcredit
);
1095 * queue I/O message to firmware
1097 bfa_reqq_produce(fcport
->bfa
, BFA_REQQ_PORT
);
1101 bfa_fcport_qos_stats_swap(struct bfa_qos_stats_s
*d
,
1102 struct bfa_qos_stats_s
*s
)
1104 u32
*dip
= (u32
*) d
;
1105 u32
*sip
= (u32
*) s
;
1108 /* Now swap the 32 bit fields */
1109 for (i
= 0; i
< (sizeof(struct bfa_qos_stats_s
)/sizeof(u32
)); ++i
)
1110 dip
[i
] = bfa_os_ntohl(sip
[i
]);
1114 bfa_fcport_fcoe_stats_swap(struct bfa_fcoe_stats_s
*d
,
1115 struct bfa_fcoe_stats_s
*s
)
1117 u32
*dip
= (u32
*) d
;
1118 u32
*sip
= (u32
*) s
;
1121 for (i
= 0; i
< ((sizeof(struct bfa_fcoe_stats_s
))/sizeof(u32
));
1124 dip
[i
] = bfa_os_ntohl(sip
[i
]);
1125 dip
[i
+ 1] = bfa_os_ntohl(sip
[i
+ 1]);
1127 dip
[i
] = bfa_os_ntohl(sip
[i
+ 1]);
1128 dip
[i
+ 1] = bfa_os_ntohl(sip
[i
]);
1134 __bfa_cb_fcport_stats_get(void *cbarg
, bfa_boolean_t complete
)
1136 struct bfa_fcport_s
*fcport
= cbarg
;
1139 if (fcport
->stats_status
== BFA_STATUS_OK
) {
1140 struct bfa_timeval_s tv
;
1142 /* Swap FC QoS or FCoE stats */
1143 if (bfa_ioc_get_fcmode(&fcport
->bfa
->ioc
)) {
1144 bfa_fcport_qos_stats_swap(
1145 &fcport
->stats_ret
->fcqos
,
1146 &fcport
->stats
->fcqos
);
1148 bfa_fcport_fcoe_stats_swap(
1149 &fcport
->stats_ret
->fcoe
,
1150 &fcport
->stats
->fcoe
);
1152 bfa_os_gettimeofday(&tv
);
1153 fcport
->stats_ret
->fcoe
.secs_reset
=
1154 tv
.tv_sec
- fcport
->stats_reset_time
;
1157 fcport
->stats_cbfn(fcport
->stats_cbarg
, fcport
->stats_status
);
1159 fcport
->stats_busy
= BFA_FALSE
;
1160 fcport
->stats_status
= BFA_STATUS_OK
;
1165 bfa_fcport_stats_get_timeout(void *cbarg
)
1167 struct bfa_fcport_s
*fcport
= (struct bfa_fcport_s
*) cbarg
;
1169 bfa_trc(fcport
->bfa
, fcport
->stats_qfull
);
1171 if (fcport
->stats_qfull
) {
1172 bfa_reqq_wcancel(&fcport
->stats_reqq_wait
);
1173 fcport
->stats_qfull
= BFA_FALSE
;
1176 fcport
->stats_status
= BFA_STATUS_ETIMER
;
1177 bfa_cb_queue(fcport
->bfa
, &fcport
->hcb_qe
, __bfa_cb_fcport_stats_get
,
1182 bfa_fcport_send_stats_get(void *cbarg
)
1184 struct bfa_fcport_s
*fcport
= (struct bfa_fcport_s
*) cbarg
;
1185 struct bfi_fcport_req_s
*msg
;
1187 msg
= bfa_reqq_next(fcport
->bfa
, BFA_REQQ_PORT
);
1190 fcport
->stats_qfull
= BFA_TRUE
;
1191 bfa_reqq_winit(&fcport
->stats_reqq_wait
,
1192 bfa_fcport_send_stats_get
, fcport
);
1193 bfa_reqq_wait(fcport
->bfa
, BFA_REQQ_PORT
,
1194 &fcport
->stats_reqq_wait
);
1197 fcport
->stats_qfull
= BFA_FALSE
;
1199 bfa_os_memset(msg
, 0, sizeof(struct bfi_fcport_req_s
));
1200 bfi_h2i_set(msg
->mh
, BFI_MC_FCPORT
, BFI_FCPORT_H2I_STATS_GET_REQ
,
1201 bfa_lpuid(fcport
->bfa
));
1202 bfa_reqq_produce(fcport
->bfa
, BFA_REQQ_PORT
);
1206 __bfa_cb_fcport_stats_clr(void *cbarg
, bfa_boolean_t complete
)
1208 struct bfa_fcport_s
*fcport
= cbarg
;
1211 struct bfa_timeval_s tv
;
1214 * re-initialize time stamp for stats reset
1216 bfa_os_gettimeofday(&tv
);
1217 fcport
->stats_reset_time
= tv
.tv_sec
;
1219 fcport
->stats_cbfn(fcport
->stats_cbarg
, fcport
->stats_status
);
1221 fcport
->stats_busy
= BFA_FALSE
;
1222 fcport
->stats_status
= BFA_STATUS_OK
;
1227 bfa_fcport_stats_clr_timeout(void *cbarg
)
1229 struct bfa_fcport_s
*fcport
= (struct bfa_fcport_s
*) cbarg
;
1231 bfa_trc(fcport
->bfa
, fcport
->stats_qfull
);
1233 if (fcport
->stats_qfull
) {
1234 bfa_reqq_wcancel(&fcport
->stats_reqq_wait
);
1235 fcport
->stats_qfull
= BFA_FALSE
;
1238 fcport
->stats_status
= BFA_STATUS_ETIMER
;
1239 bfa_cb_queue(fcport
->bfa
, &fcport
->hcb_qe
,
1240 __bfa_cb_fcport_stats_clr
, fcport
);
1244 bfa_fcport_send_stats_clear(void *cbarg
)
1246 struct bfa_fcport_s
*fcport
= (struct bfa_fcport_s
*) cbarg
;
1247 struct bfi_fcport_req_s
*msg
;
1249 msg
= bfa_reqq_next(fcport
->bfa
, BFA_REQQ_PORT
);
1252 fcport
->stats_qfull
= BFA_TRUE
;
1253 bfa_reqq_winit(&fcport
->stats_reqq_wait
,
1254 bfa_fcport_send_stats_clear
, fcport
);
1255 bfa_reqq_wait(fcport
->bfa
, BFA_REQQ_PORT
,
1256 &fcport
->stats_reqq_wait
);
1259 fcport
->stats_qfull
= BFA_FALSE
;
1261 bfa_os_memset(msg
, 0, sizeof(struct bfi_fcport_req_s
));
1262 bfi_h2i_set(msg
->mh
, BFI_MC_FCPORT
, BFI_FCPORT_H2I_STATS_CLEAR_REQ
,
1263 bfa_lpuid(fcport
->bfa
));
1264 bfa_reqq_produce(fcport
->bfa
, BFA_REQQ_PORT
);
1272 * Called to initialize port attributes
1275 bfa_fcport_init(struct bfa_s
*bfa
)
1277 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1280 * Initialize port attributes from IOC hardware data.
1282 bfa_fcport_set_wwns(fcport
);
1283 if (fcport
->cfg
.maxfrsize
== 0)
1284 fcport
->cfg
.maxfrsize
= bfa_ioc_maxfrsize(&bfa
->ioc
);
1285 fcport
->cfg
.rx_bbcredit
= bfa_ioc_rx_bbcredit(&bfa
->ioc
);
1286 fcport
->speed_sup
= bfa_ioc_speed_sup(&bfa
->ioc
);
1288 bfa_assert(fcport
->cfg
.maxfrsize
);
1289 bfa_assert(fcport
->cfg
.rx_bbcredit
);
1290 bfa_assert(fcport
->speed_sup
);
1295 * Firmware message handler.
1298 bfa_fcport_isr(struct bfa_s
*bfa
, struct bfi_msg_s
*msg
)
1300 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1301 union bfi_fcport_i2h_msg_u i2hmsg
;
1304 fcport
->event_arg
.i2hmsg
= i2hmsg
;
1306 switch (msg
->mhdr
.msg_id
) {
1307 case BFI_FCPORT_I2H_ENABLE_RSP
:
1308 if (fcport
->msgtag
== i2hmsg
.penable_rsp
->msgtag
)
1309 bfa_sm_send_event(fcport
, BFA_FCPORT_SM_FWRSP
);
1312 case BFI_FCPORT_I2H_DISABLE_RSP
:
1313 if (fcport
->msgtag
== i2hmsg
.pdisable_rsp
->msgtag
)
1314 bfa_sm_send_event(fcport
, BFA_FCPORT_SM_FWRSP
);
1317 case BFI_FCPORT_I2H_EVENT
:
1318 switch (i2hmsg
.event
->link_state
.linkstate
) {
1319 case BFA_PPORT_LINKUP
:
1320 bfa_sm_send_event(fcport
, BFA_FCPORT_SM_LINKUP
);
1322 case BFA_PPORT_LINKDOWN
:
1323 bfa_sm_send_event(fcport
, BFA_FCPORT_SM_LINKDOWN
);
1325 case BFA_PPORT_TRUNK_LINKDOWN
:
1326 /** todo: event notification */
1331 case BFI_FCPORT_I2H_STATS_GET_RSP
:
1333 * check for timer pop before processing the rsp
1335 if (fcport
->stats_busy
== BFA_FALSE
||
1336 fcport
->stats_status
== BFA_STATUS_ETIMER
)
1339 bfa_timer_stop(&fcport
->timer
);
1340 fcport
->stats_status
= i2hmsg
.pstatsget_rsp
->status
;
1341 bfa_cb_queue(fcport
->bfa
, &fcport
->hcb_qe
,
1342 __bfa_cb_fcport_stats_get
, fcport
);
1345 case BFI_FCPORT_I2H_STATS_CLEAR_RSP
:
1347 * check for timer pop before processing the rsp
1349 if (fcport
->stats_busy
== BFA_FALSE
||
1350 fcport
->stats_status
== BFA_STATUS_ETIMER
)
1353 bfa_timer_stop(&fcport
->timer
);
1354 fcport
->stats_status
= BFA_STATUS_OK
;
1355 bfa_cb_queue(fcport
->bfa
, &fcport
->hcb_qe
,
1356 __bfa_cb_fcport_stats_clr
, fcport
);
1370 * Registered callback for port events.
1373 bfa_fcport_event_register(struct bfa_s
*bfa
,
1374 void (*cbfn
) (void *cbarg
, bfa_pport_event_t event
),
1377 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1379 fcport
->event_cbfn
= cbfn
;
1380 fcport
->event_cbarg
= cbarg
;
1384 bfa_fcport_enable(struct bfa_s
*bfa
)
1386 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1387 struct bfa_iocfc_s
*iocfc
= &bfa
->iocfc
;
1388 struct bfi_iocfc_cfgrsp_s
*cfgrsp
= iocfc
->cfgrsp
;
1390 /* if port is PBC disabled, return error */
1391 if (cfgrsp
->pbc_cfg
.port_enabled
== BFI_PBC_PORT_DISABLED
) {
1392 bfa_trc(bfa
, fcport
->pwwn
);
1393 return BFA_STATUS_PBC
;
1396 if (bfa_ioc_is_disabled(&bfa
->ioc
))
1397 return BFA_STATUS_IOC_DISABLED
;
1399 if (fcport
->diag_busy
)
1400 return BFA_STATUS_DIAG_BUSY
;
1401 else if (bfa_sm_cmp_state
1402 (BFA_FCPORT_MOD(bfa
), bfa_fcport_sm_disabling_qwait
))
1403 return BFA_STATUS_DEVBUSY
;
1405 bfa_sm_send_event(BFA_FCPORT_MOD(bfa
), BFA_FCPORT_SM_ENABLE
);
1406 return BFA_STATUS_OK
;
1410 bfa_fcport_disable(struct bfa_s
*bfa
)
1412 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1413 struct bfa_iocfc_s
*iocfc
= &bfa
->iocfc
;
1414 struct bfi_iocfc_cfgrsp_s
*cfgrsp
= iocfc
->cfgrsp
;
1416 /* if port is PBC disabled, return error */
1417 if (cfgrsp
->pbc_cfg
.port_enabled
== BFI_PBC_PORT_DISABLED
) {
1418 bfa_trc(bfa
, fcport
->pwwn
);
1419 return BFA_STATUS_PBC
;
1422 bfa_sm_send_event(BFA_FCPORT_MOD(bfa
), BFA_FCPORT_SM_DISABLE
);
1423 return BFA_STATUS_OK
;
1427 * Configure port speed.
1430 bfa_fcport_cfg_speed(struct bfa_s
*bfa
, enum bfa_pport_speed speed
)
1432 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1434 bfa_trc(bfa
, speed
);
1436 if ((speed
!= BFA_PPORT_SPEED_AUTO
) && (speed
> fcport
->speed_sup
)) {
1437 bfa_trc(bfa
, fcport
->speed_sup
);
1438 return BFA_STATUS_UNSUPP_SPEED
;
1441 fcport
->cfg
.speed
= speed
;
1443 return BFA_STATUS_OK
;
1447 * Get current speed.
1449 enum bfa_pport_speed
1450 bfa_fcport_get_speed(struct bfa_s
*bfa
)
1452 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1454 return fcport
->speed
;
1458 * Configure port topology.
1461 bfa_fcport_cfg_topology(struct bfa_s
*bfa
, enum bfa_pport_topology topology
)
1463 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1465 bfa_trc(bfa
, topology
);
1466 bfa_trc(bfa
, fcport
->cfg
.topology
);
1469 case BFA_PPORT_TOPOLOGY_P2P
:
1470 case BFA_PPORT_TOPOLOGY_LOOP
:
1471 case BFA_PPORT_TOPOLOGY_AUTO
:
1475 return BFA_STATUS_EINVAL
;
1478 fcport
->cfg
.topology
= topology
;
1479 return BFA_STATUS_OK
;
1483 * Get current topology.
1485 enum bfa_pport_topology
1486 bfa_fcport_get_topology(struct bfa_s
*bfa
)
1488 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1490 return fcport
->topology
;
1494 bfa_fcport_cfg_hardalpa(struct bfa_s
*bfa
, u8 alpa
)
1496 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1499 bfa_trc(bfa
, fcport
->cfg
.cfg_hardalpa
);
1500 bfa_trc(bfa
, fcport
->cfg
.hardalpa
);
1502 fcport
->cfg
.cfg_hardalpa
= BFA_TRUE
;
1503 fcport
->cfg
.hardalpa
= alpa
;
1505 return BFA_STATUS_OK
;
1509 bfa_fcport_clr_hardalpa(struct bfa_s
*bfa
)
1511 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1513 bfa_trc(bfa
, fcport
->cfg
.cfg_hardalpa
);
1514 bfa_trc(bfa
, fcport
->cfg
.hardalpa
);
1516 fcport
->cfg
.cfg_hardalpa
= BFA_FALSE
;
1517 return BFA_STATUS_OK
;
1521 bfa_fcport_get_hardalpa(struct bfa_s
*bfa
, u8
*alpa
)
1523 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1525 *alpa
= fcport
->cfg
.hardalpa
;
1526 return fcport
->cfg
.cfg_hardalpa
;
1530 bfa_fcport_get_myalpa(struct bfa_s
*bfa
)
1532 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1534 return fcport
->myalpa
;
1538 bfa_fcport_cfg_maxfrsize(struct bfa_s
*bfa
, u16 maxfrsize
)
1540 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1542 bfa_trc(bfa
, maxfrsize
);
1543 bfa_trc(bfa
, fcport
->cfg
.maxfrsize
);
1548 if ((maxfrsize
> FC_MAX_PDUSZ
) || (maxfrsize
< FC_MIN_PDUSZ
))
1549 return BFA_STATUS_INVLD_DFSZ
;
1552 * power of 2, if not the max frame size of 2112
1554 if ((maxfrsize
!= FC_MAX_PDUSZ
) && (maxfrsize
& (maxfrsize
- 1)))
1555 return BFA_STATUS_INVLD_DFSZ
;
1557 fcport
->cfg
.maxfrsize
= maxfrsize
;
1558 return BFA_STATUS_OK
;
1562 bfa_fcport_get_maxfrsize(struct bfa_s
*bfa
)
1564 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1566 return fcport
->cfg
.maxfrsize
;
1570 bfa_fcport_mypid(struct bfa_s
*bfa
)
1572 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1574 return fcport
->mypid
;
1578 bfa_fcport_get_rx_bbcredit(struct bfa_s
*bfa
)
1580 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1582 return fcport
->cfg
.rx_bbcredit
;
1586 bfa_fcport_set_tx_bbcredit(struct bfa_s
*bfa
, u16 tx_bbcredit
)
1588 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1590 fcport
->cfg
.tx_bbcredit
= (u8
) tx_bbcredit
;
1591 bfa_fcport_send_txcredit(fcport
);
1595 * Get port attributes.
1599 bfa_fcport_get_wwn(struct bfa_s
*bfa
, bfa_boolean_t node
)
1601 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1603 return fcport
->nwwn
;
1605 return fcport
->pwwn
;
1609 bfa_fcport_get_attr(struct bfa_s
*bfa
, struct bfa_pport_attr_s
*attr
)
1611 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1612 struct bfa_iocfc_s
*iocfc
= &bfa
->iocfc
;
1613 struct bfi_iocfc_cfgrsp_s
*cfgrsp
= iocfc
->cfgrsp
;
1615 bfa_os_memset(attr
, 0, sizeof(struct bfa_pport_attr_s
));
1617 attr
->nwwn
= fcport
->nwwn
;
1618 attr
->pwwn
= fcport
->pwwn
;
1620 attr
->factorypwwn
= bfa_ioc_get_mfg_pwwn(&bfa
->ioc
);
1621 attr
->factorynwwn
= bfa_ioc_get_mfg_nwwn(&bfa
->ioc
);
1623 bfa_os_memcpy(&attr
->pport_cfg
, &fcport
->cfg
,
1624 sizeof(struct bfa_pport_cfg_s
));
1628 attr
->pport_cfg
.speed
= fcport
->cfg
.speed
;
1629 attr
->speed_supported
= fcport
->speed_sup
;
1630 attr
->speed
= fcport
->speed
;
1631 attr
->cos_supported
= FC_CLASS_3
;
1634 * topology attributes
1636 attr
->pport_cfg
.topology
= fcport
->cfg
.topology
;
1637 attr
->topology
= fcport
->topology
;
1642 attr
->beacon
= fcport
->beacon
;
1643 attr
->link_e2e_beacon
= fcport
->link_e2e_beacon
;
1644 attr
->plog_enabled
= bfa_plog_get_setting(fcport
->bfa
->plog
);
1646 attr
->pport_cfg
.path_tov
= bfa_fcpim_path_tov_get(bfa
);
1647 attr
->pport_cfg
.q_depth
= bfa_fcpim_qdepth_get(bfa
);
1649 /* PBC Disabled State */
1650 if (cfgrsp
->pbc_cfg
.port_enabled
== BFI_PBC_PORT_DISABLED
)
1651 attr
->port_state
= BFA_PPORT_ST_PREBOOT_DISABLED
;
1653 attr
->port_state
= bfa_sm_to_state(
1654 hal_pport_sm_table
, fcport
->sm
);
1655 if (bfa_ioc_is_disabled(&fcport
->bfa
->ioc
))
1656 attr
->port_state
= BFA_PPORT_ST_IOCDIS
;
1657 else if (bfa_ioc_fw_mismatch(&fcport
->bfa
->ioc
))
1658 attr
->port_state
= BFA_PPORT_ST_FWMISMATCH
;
1662 #define BFA_FCPORT_STATS_TOV 1000
1665 * Fetch port attributes (FCQoS or FCoE).
1668 bfa_fcport_get_stats(struct bfa_s
*bfa
, union bfa_fcport_stats_u
*stats
,
1669 bfa_cb_pport_t cbfn
, void *cbarg
)
1671 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1673 if (fcport
->stats_busy
) {
1674 bfa_trc(bfa
, fcport
->stats_busy
);
1675 return BFA_STATUS_DEVBUSY
;
1678 fcport
->stats_busy
= BFA_TRUE
;
1679 fcport
->stats_ret
= stats
;
1680 fcport
->stats_cbfn
= cbfn
;
1681 fcport
->stats_cbarg
= cbarg
;
1683 bfa_fcport_send_stats_get(fcport
);
1685 bfa_timer_start(bfa
, &fcport
->timer
, bfa_fcport_stats_get_timeout
,
1686 fcport
, BFA_FCPORT_STATS_TOV
);
1687 return BFA_STATUS_OK
;
1691 * Reset port statistics (FCQoS or FCoE).
1694 bfa_fcport_clear_stats(struct bfa_s
*bfa
, bfa_cb_pport_t cbfn
, void *cbarg
)
1696 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1698 if (fcport
->stats_busy
) {
1699 bfa_trc(bfa
, fcport
->stats_busy
);
1700 return BFA_STATUS_DEVBUSY
;
1703 fcport
->stats_busy
= BFA_TRUE
;
1704 fcport
->stats_cbfn
= cbfn
;
1705 fcport
->stats_cbarg
= cbarg
;
1707 bfa_fcport_send_stats_clear(fcport
);
1709 bfa_timer_start(bfa
, &fcport
->timer
, bfa_fcport_stats_clr_timeout
,
1710 fcport
, BFA_FCPORT_STATS_TOV
);
1711 return BFA_STATUS_OK
;
1715 * Fetch FCQoS port statistics
1718 bfa_fcport_get_qos_stats(struct bfa_s
*bfa
, union bfa_fcport_stats_u
*stats
,
1719 bfa_cb_pport_t cbfn
, void *cbarg
)
1721 /* Meaningful only for FC mode */
1722 bfa_assert(bfa_ioc_get_fcmode(&bfa
->ioc
));
1724 return bfa_fcport_get_stats(bfa
, stats
, cbfn
, cbarg
);
1728 * Reset FCoE port statistics
1731 bfa_fcport_clear_qos_stats(struct bfa_s
*bfa
, bfa_cb_pport_t cbfn
, void *cbarg
)
1733 /* Meaningful only for FC mode */
1734 bfa_assert(bfa_ioc_get_fcmode(&bfa
->ioc
));
1736 return bfa_fcport_clear_stats(bfa
, cbfn
, cbarg
);
1740 * Fetch FCQoS port statistics
1743 bfa_fcport_get_fcoe_stats(struct bfa_s
*bfa
, union bfa_fcport_stats_u
*stats
,
1744 bfa_cb_pport_t cbfn
, void *cbarg
)
1746 /* Meaningful only for FCoE mode */
1747 bfa_assert(!bfa_ioc_get_fcmode(&bfa
->ioc
));
1749 return bfa_fcport_get_stats(bfa
, stats
, cbfn
, cbarg
);
1753 * Reset FCoE port statistics
1756 bfa_fcport_clear_fcoe_stats(struct bfa_s
*bfa
, bfa_cb_pport_t cbfn
, void *cbarg
)
1758 /* Meaningful only for FCoE mode */
1759 bfa_assert(!bfa_ioc_get_fcmode(&bfa
->ioc
));
1761 return bfa_fcport_clear_stats(bfa
, cbfn
, cbarg
);
1765 bfa_fcport_trunk_enable(struct bfa_s
*bfa
, u8 bitmap
)
1767 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1769 bfa_trc(bfa
, bitmap
);
1770 bfa_trc(bfa
, fcport
->cfg
.trunked
);
1771 bfa_trc(bfa
, fcport
->cfg
.trunk_ports
);
1773 if (!bitmap
|| (bitmap
& (bitmap
- 1)))
1774 return BFA_STATUS_EINVAL
;
1776 fcport
->cfg
.trunked
= BFA_TRUE
;
1777 fcport
->cfg
.trunk_ports
= bitmap
;
1779 return BFA_STATUS_OK
;
1783 bfa_fcport_qos_get_attr(struct bfa_s
*bfa
, struct bfa_qos_attr_s
*qos_attr
)
1785 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1787 qos_attr
->state
= bfa_os_ntohl(fcport
->qos_attr
.state
);
1788 qos_attr
->total_bb_cr
= bfa_os_ntohl(fcport
->qos_attr
.total_bb_cr
);
1792 bfa_fcport_qos_get_vc_attr(struct bfa_s
*bfa
,
1793 struct bfa_qos_vc_attr_s
*qos_vc_attr
)
1795 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1796 struct bfa_qos_vc_attr_s
*bfa_vc_attr
= &fcport
->qos_vc_attr
;
1799 qos_vc_attr
->total_vc_count
= bfa_os_ntohs(bfa_vc_attr
->total_vc_count
);
1800 qos_vc_attr
->shared_credit
= bfa_os_ntohs(bfa_vc_attr
->shared_credit
);
1801 qos_vc_attr
->elp_opmode_flags
=
1802 bfa_os_ntohl(bfa_vc_attr
->elp_opmode_flags
);
1805 * Individual VC info
1807 while (i
< qos_vc_attr
->total_vc_count
) {
1808 qos_vc_attr
->vc_info
[i
].vc_credit
=
1809 bfa_vc_attr
->vc_info
[i
].vc_credit
;
1810 qos_vc_attr
->vc_info
[i
].borrow_credit
=
1811 bfa_vc_attr
->vc_info
[i
].borrow_credit
;
1812 qos_vc_attr
->vc_info
[i
].priority
=
1813 bfa_vc_attr
->vc_info
[i
].priority
;
1819 * Fetch port attributes.
1822 bfa_fcport_trunk_disable(struct bfa_s
*bfa
)
1824 return BFA_STATUS_OK
;
1828 bfa_fcport_trunk_query(struct bfa_s
*bfa
, u32
*bitmap
)
1830 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1832 *bitmap
= fcport
->cfg
.trunk_ports
;
1833 return fcport
->cfg
.trunked
;
1837 bfa_fcport_is_disabled(struct bfa_s
*bfa
)
1839 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1841 return bfa_sm_to_state(hal_pport_sm_table
, fcport
->sm
) ==
1842 BFA_PPORT_ST_DISABLED
;
1847 bfa_fcport_is_ratelim(struct bfa_s
*bfa
)
1849 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1851 return fcport
->cfg
.ratelimit
? BFA_TRUE
: BFA_FALSE
;
1856 bfa_fcport_cfg_qos(struct bfa_s
*bfa
, bfa_boolean_t on_off
)
1858 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1859 enum bfa_ioc_type_e ioc_type
= bfa_get_type(bfa
);
1861 bfa_trc(bfa
, on_off
);
1862 bfa_trc(bfa
, fcport
->cfg
.qos_enabled
);
1864 bfa_trc(bfa
, ioc_type
);
1866 if (ioc_type
== BFA_IOC_TYPE_FC
) {
1867 fcport
->cfg
.qos_enabled
= on_off
;
1869 * Notify fcpim of the change in QoS state
1871 bfa_fcpim_update_ioredirect(bfa
);
1876 bfa_fcport_cfg_ratelim(struct bfa_s
*bfa
, bfa_boolean_t on_off
)
1878 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1880 bfa_trc(bfa
, on_off
);
1881 bfa_trc(bfa
, fcport
->cfg
.ratelimit
);
1883 fcport
->cfg
.ratelimit
= on_off
;
1884 if (fcport
->cfg
.trl_def_speed
== BFA_PPORT_SPEED_UNKNOWN
)
1885 fcport
->cfg
.trl_def_speed
= BFA_PPORT_SPEED_1GBPS
;
1889 * Configure default minimum ratelim speed
1892 bfa_fcport_cfg_ratelim_speed(struct bfa_s
*bfa
, enum bfa_pport_speed speed
)
1894 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1896 bfa_trc(bfa
, speed
);
1899 * Auto and speeds greater than the supported speed, are invalid
1901 if ((speed
== BFA_PPORT_SPEED_AUTO
) || (speed
> fcport
->speed_sup
)) {
1902 bfa_trc(bfa
, fcport
->speed_sup
);
1903 return BFA_STATUS_UNSUPP_SPEED
;
1906 fcport
->cfg
.trl_def_speed
= speed
;
1908 return BFA_STATUS_OK
;
1912 * Get default minimum ratelim speed
1914 enum bfa_pport_speed
1915 bfa_fcport_get_ratelim_speed(struct bfa_s
*bfa
)
1917 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1919 bfa_trc(bfa
, fcport
->cfg
.trl_def_speed
);
1920 return fcport
->cfg
.trl_def_speed
;
1925 bfa_fcport_busy(struct bfa_s
*bfa
, bfa_boolean_t status
)
1927 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1929 bfa_trc(bfa
, status
);
1930 bfa_trc(bfa
, fcport
->diag_busy
);
1932 fcport
->diag_busy
= status
;
1936 bfa_fcport_beacon(struct bfa_s
*bfa
, bfa_boolean_t beacon
,
1937 bfa_boolean_t link_e2e_beacon
)
1939 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1941 bfa_trc(bfa
, beacon
);
1942 bfa_trc(bfa
, link_e2e_beacon
);
1943 bfa_trc(bfa
, fcport
->beacon
);
1944 bfa_trc(bfa
, fcport
->link_e2e_beacon
);
1946 fcport
->beacon
= beacon
;
1947 fcport
->link_e2e_beacon
= link_e2e_beacon
;
1951 bfa_fcport_is_linkup(struct bfa_s
*bfa
)
1953 return bfa_sm_cmp_state(BFA_FCPORT_MOD(bfa
), bfa_fcport_sm_linkup
);
1957 bfa_fcport_is_qos_enabled(struct bfa_s
*bfa
)
1959 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
1961 return fcport
->cfg
.qos_enabled
;