2 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
3 * Copyright (c) 2014- QLogic Corporation.
7 * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License (GPL) Version 2 as
11 * published by the Free Software Foundation
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
23 #include "bfa_modules.h"
25 BFA_TRC_FILE(HAL
, FCXP
);
28 * LPS related definitions
30 #define BFA_LPS_MIN_LPORTS (1)
31 #define BFA_LPS_MAX_LPORTS (256)
34 * Maximum Vports supported per physical port or vf.
36 #define BFA_LPS_MAX_VPORTS_SUPP_CB 255
37 #define BFA_LPS_MAX_VPORTS_SUPP_CT 190
41 * FC PORT related definitions
44 * The port is considered disabled if corresponding physical port or IOC are
47 #define BFA_PORT_IS_DISABLED(bfa) \
48 ((bfa_fcport_is_disabled(bfa) == BFA_TRUE) || \
49 (bfa_ioc_is_disabled(&bfa->ioc) == BFA_TRUE))
52 * BFA port state machine events
54 enum bfa_fcport_sm_event
{
55 BFA_FCPORT_SM_START
= 1, /* start port state machine */
56 BFA_FCPORT_SM_STOP
= 2, /* stop port state machine */
57 BFA_FCPORT_SM_ENABLE
= 3, /* enable port */
58 BFA_FCPORT_SM_DISABLE
= 4, /* disable port state machine */
59 BFA_FCPORT_SM_FWRSP
= 5, /* firmware enable/disable rsp */
60 BFA_FCPORT_SM_LINKUP
= 6, /* firmware linkup event */
61 BFA_FCPORT_SM_LINKDOWN
= 7, /* firmware linkup down */
62 BFA_FCPORT_SM_QRESUME
= 8, /* CQ space available */
63 BFA_FCPORT_SM_HWFAIL
= 9, /* IOC h/w failure */
64 BFA_FCPORT_SM_DPORTENABLE
= 10, /* enable dport */
65 BFA_FCPORT_SM_DPORTDISABLE
= 11,/* disable dport */
66 BFA_FCPORT_SM_FAA_MISCONFIG
= 12, /* FAA misconfiguratin */
67 BFA_FCPORT_SM_DDPORTENABLE
= 13, /* enable ddport */
68 BFA_FCPORT_SM_DDPORTDISABLE
= 14, /* disable ddport */
72 * BFA port link notification state machine events
75 enum bfa_fcport_ln_sm_event
{
76 BFA_FCPORT_LN_SM_LINKUP
= 1, /* linkup event */
77 BFA_FCPORT_LN_SM_LINKDOWN
= 2, /* linkdown event */
78 BFA_FCPORT_LN_SM_NOTIFICATION
= 3 /* done notification */
82 * RPORT related definitions
84 #define bfa_rport_offline_cb(__rp) do { \
85 if ((__rp)->bfa->fcs) \
86 bfa_cb_rport_offline((__rp)->rport_drv); \
88 bfa_cb_queue((__rp)->bfa, &(__rp)->hcb_qe, \
89 __bfa_cb_rport_offline, (__rp)); \
93 #define bfa_rport_online_cb(__rp) do { \
94 if ((__rp)->bfa->fcs) \
95 bfa_cb_rport_online((__rp)->rport_drv); \
97 bfa_cb_queue((__rp)->bfa, &(__rp)->hcb_qe, \
98 __bfa_cb_rport_online, (__rp)); \
103 * forward declarations FCXP related functions
105 static void __bfa_fcxp_send_cbfn(void *cbarg
, bfa_boolean_t complete
);
106 static void hal_fcxp_rx_plog(struct bfa_s
*bfa
, struct bfa_fcxp_s
*fcxp
,
107 struct bfi_fcxp_send_rsp_s
*fcxp_rsp
);
108 static void hal_fcxp_tx_plog(struct bfa_s
*bfa
, u32 reqlen
,
109 struct bfa_fcxp_s
*fcxp
, struct fchs_s
*fchs
);
110 static void bfa_fcxp_qresume(void *cbarg
);
111 static void bfa_fcxp_queue(struct bfa_fcxp_s
*fcxp
,
112 struct bfi_fcxp_send_req_s
*send_req
);
115 * forward declarations for LPS functions
117 static void bfa_lps_login_rsp(struct bfa_s
*bfa
,
118 struct bfi_lps_login_rsp_s
*rsp
);
119 static void bfa_lps_no_res(struct bfa_lps_s
*first_lps
, u8 count
);
120 static void bfa_lps_logout_rsp(struct bfa_s
*bfa
,
121 struct bfi_lps_logout_rsp_s
*rsp
);
122 static void bfa_lps_reqq_resume(void *lps_arg
);
123 static void bfa_lps_free(struct bfa_lps_s
*lps
);
124 static void bfa_lps_send_login(struct bfa_lps_s
*lps
);
125 static void bfa_lps_send_logout(struct bfa_lps_s
*lps
);
126 static void bfa_lps_send_set_n2n_pid(struct bfa_lps_s
*lps
);
127 static void bfa_lps_login_comp(struct bfa_lps_s
*lps
);
128 static void bfa_lps_logout_comp(struct bfa_lps_s
*lps
);
129 static void bfa_lps_cvl_event(struct bfa_lps_s
*lps
);
132 * forward declaration for LPS state machine
134 static void bfa_lps_sm_init(struct bfa_lps_s
*lps
, enum bfa_lps_event event
);
135 static void bfa_lps_sm_login(struct bfa_lps_s
*lps
, enum bfa_lps_event event
);
136 static void bfa_lps_sm_loginwait(struct bfa_lps_s
*lps
, enum bfa_lps_event
138 static void bfa_lps_sm_online(struct bfa_lps_s
*lps
, enum bfa_lps_event event
);
139 static void bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s
*lps
,
140 enum bfa_lps_event event
);
141 static void bfa_lps_sm_logout(struct bfa_lps_s
*lps
, enum bfa_lps_event event
);
142 static void bfa_lps_sm_logowait(struct bfa_lps_s
*lps
, enum bfa_lps_event
146 * forward declaration for FC Port functions
148 static bfa_boolean_t
bfa_fcport_send_enable(struct bfa_fcport_s
*fcport
);
149 static bfa_boolean_t
bfa_fcport_send_disable(struct bfa_fcport_s
*fcport
);
150 static void bfa_fcport_update_linkinfo(struct bfa_fcport_s
*fcport
);
151 static void bfa_fcport_reset_linkinfo(struct bfa_fcport_s
*fcport
);
152 static void bfa_fcport_set_wwns(struct bfa_fcport_s
*fcport
);
153 static void __bfa_cb_fcport_event(void *cbarg
, bfa_boolean_t complete
);
154 static void bfa_fcport_scn(struct bfa_fcport_s
*fcport
,
155 enum bfa_port_linkstate event
, bfa_boolean_t trunk
);
156 static void bfa_fcport_queue_cb(struct bfa_fcport_ln_s
*ln
,
157 enum bfa_port_linkstate event
);
158 static void __bfa_cb_fcport_stats_clr(void *cbarg
, bfa_boolean_t complete
);
159 static void bfa_fcport_stats_get_timeout(void *cbarg
);
160 static void bfa_fcport_stats_clr_timeout(void *cbarg
);
161 static void bfa_trunk_iocdisable(struct bfa_s
*bfa
);
164 * forward declaration for FC PORT state machine
166 static void bfa_fcport_sm_uninit(struct bfa_fcport_s
*fcport
,
167 enum bfa_fcport_sm_event event
);
168 static void bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s
*fcport
,
169 enum bfa_fcport_sm_event event
);
170 static void bfa_fcport_sm_enabling(struct bfa_fcport_s
*fcport
,
171 enum bfa_fcport_sm_event event
);
172 static void bfa_fcport_sm_linkdown(struct bfa_fcport_s
*fcport
,
173 enum bfa_fcport_sm_event event
);
174 static void bfa_fcport_sm_linkup(struct bfa_fcport_s
*fcport
,
175 enum bfa_fcport_sm_event event
);
176 static void bfa_fcport_sm_disabling(struct bfa_fcport_s
*fcport
,
177 enum bfa_fcport_sm_event event
);
178 static void bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s
*fcport
,
179 enum bfa_fcport_sm_event event
);
180 static void bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s
*fcport
,
181 enum bfa_fcport_sm_event event
);
182 static void bfa_fcport_sm_disabled(struct bfa_fcport_s
*fcport
,
183 enum bfa_fcport_sm_event event
);
184 static void bfa_fcport_sm_stopped(struct bfa_fcport_s
*fcport
,
185 enum bfa_fcport_sm_event event
);
186 static void bfa_fcport_sm_iocdown(struct bfa_fcport_s
*fcport
,
187 enum bfa_fcport_sm_event event
);
188 static void bfa_fcport_sm_iocfail(struct bfa_fcport_s
*fcport
,
189 enum bfa_fcport_sm_event event
);
190 static void bfa_fcport_sm_dport(struct bfa_fcport_s
*fcport
,
191 enum bfa_fcport_sm_event event
);
192 static void bfa_fcport_sm_ddport(struct bfa_fcport_s
*fcport
,
193 enum bfa_fcport_sm_event event
);
194 static void bfa_fcport_sm_faa_misconfig(struct bfa_fcport_s
*fcport
,
195 enum bfa_fcport_sm_event event
);
197 static void bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s
*ln
,
198 enum bfa_fcport_ln_sm_event event
);
199 static void bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s
*ln
,
200 enum bfa_fcport_ln_sm_event event
);
201 static void bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s
*ln
,
202 enum bfa_fcport_ln_sm_event event
);
203 static void bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s
*ln
,
204 enum bfa_fcport_ln_sm_event event
);
205 static void bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s
*ln
,
206 enum bfa_fcport_ln_sm_event event
);
207 static void bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s
*ln
,
208 enum bfa_fcport_ln_sm_event event
);
209 static void bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s
*ln
,
210 enum bfa_fcport_ln_sm_event event
);
212 static struct bfa_sm_table_s hal_port_sm_table
[] = {
213 {BFA_SM(bfa_fcport_sm_uninit
), BFA_PORT_ST_UNINIT
},
214 {BFA_SM(bfa_fcport_sm_enabling_qwait
), BFA_PORT_ST_ENABLING_QWAIT
},
215 {BFA_SM(bfa_fcport_sm_enabling
), BFA_PORT_ST_ENABLING
},
216 {BFA_SM(bfa_fcport_sm_linkdown
), BFA_PORT_ST_LINKDOWN
},
217 {BFA_SM(bfa_fcport_sm_linkup
), BFA_PORT_ST_LINKUP
},
218 {BFA_SM(bfa_fcport_sm_disabling_qwait
), BFA_PORT_ST_DISABLING_QWAIT
},
219 {BFA_SM(bfa_fcport_sm_toggling_qwait
), BFA_PORT_ST_TOGGLING_QWAIT
},
220 {BFA_SM(bfa_fcport_sm_disabling
), BFA_PORT_ST_DISABLING
},
221 {BFA_SM(bfa_fcport_sm_disabled
), BFA_PORT_ST_DISABLED
},
222 {BFA_SM(bfa_fcport_sm_stopped
), BFA_PORT_ST_STOPPED
},
223 {BFA_SM(bfa_fcport_sm_iocdown
), BFA_PORT_ST_IOCDOWN
},
224 {BFA_SM(bfa_fcport_sm_iocfail
), BFA_PORT_ST_IOCDOWN
},
225 {BFA_SM(bfa_fcport_sm_dport
), BFA_PORT_ST_DPORT
},
226 {BFA_SM(bfa_fcport_sm_ddport
), BFA_PORT_ST_DDPORT
},
227 {BFA_SM(bfa_fcport_sm_faa_misconfig
), BFA_PORT_ST_FAA_MISCONFIG
},
232 * forward declaration for RPORT related functions
234 static struct bfa_rport_s
*bfa_rport_alloc(struct bfa_rport_mod_s
*rp_mod
);
235 static void bfa_rport_free(struct bfa_rport_s
*rport
);
236 static bfa_boolean_t
bfa_rport_send_fwcreate(struct bfa_rport_s
*rp
);
237 static bfa_boolean_t
bfa_rport_send_fwdelete(struct bfa_rport_s
*rp
);
238 static bfa_boolean_t
bfa_rport_send_fwspeed(struct bfa_rport_s
*rp
);
239 static void __bfa_cb_rport_online(void *cbarg
,
240 bfa_boolean_t complete
);
241 static void __bfa_cb_rport_offline(void *cbarg
,
242 bfa_boolean_t complete
);
245 * forward declaration for RPORT state machine
247 static void bfa_rport_sm_uninit(struct bfa_rport_s
*rp
,
248 enum bfa_rport_event event
);
249 static void bfa_rport_sm_created(struct bfa_rport_s
*rp
,
250 enum bfa_rport_event event
);
251 static void bfa_rport_sm_fwcreate(struct bfa_rport_s
*rp
,
252 enum bfa_rport_event event
);
253 static void bfa_rport_sm_online(struct bfa_rport_s
*rp
,
254 enum bfa_rport_event event
);
255 static void bfa_rport_sm_fwdelete(struct bfa_rport_s
*rp
,
256 enum bfa_rport_event event
);
257 static void bfa_rport_sm_offline(struct bfa_rport_s
*rp
,
258 enum bfa_rport_event event
);
259 static void bfa_rport_sm_deleting(struct bfa_rport_s
*rp
,
260 enum bfa_rport_event event
);
261 static void bfa_rport_sm_offline_pending(struct bfa_rport_s
*rp
,
262 enum bfa_rport_event event
);
263 static void bfa_rport_sm_delete_pending(struct bfa_rport_s
*rp
,
264 enum bfa_rport_event event
);
265 static void bfa_rport_sm_iocdisable(struct bfa_rport_s
*rp
,
266 enum bfa_rport_event event
);
267 static void bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s
*rp
,
268 enum bfa_rport_event event
);
269 static void bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s
*rp
,
270 enum bfa_rport_event event
);
271 static void bfa_rport_sm_deleting_qfull(struct bfa_rport_s
*rp
,
272 enum bfa_rport_event event
);
275 * PLOG related definitions
278 plkd_validate_logrec(struct bfa_plog_rec_s
*pl_rec
)
280 if ((pl_rec
->log_type
!= BFA_PL_LOG_TYPE_INT
) &&
281 (pl_rec
->log_type
!= BFA_PL_LOG_TYPE_STRING
))
284 if ((pl_rec
->log_type
!= BFA_PL_LOG_TYPE_INT
) &&
285 (pl_rec
->log_num_ints
> BFA_PL_INT_LOG_SZ
))
292 bfa_plog_add(struct bfa_plog_s
*plog
, struct bfa_plog_rec_s
*pl_rec
)
295 struct bfa_plog_rec_s
*pl_recp
;
297 if (plog
->plog_enabled
== 0)
300 if (plkd_validate_logrec(pl_rec
)) {
307 pl_recp
= &(plog
->plog_recs
[tail
]);
309 memcpy(pl_recp
, pl_rec
, sizeof(struct bfa_plog_rec_s
));
311 pl_recp
->tv
= ktime_get_real_seconds();
312 BFA_PL_LOG_REC_INCR(plog
->tail
);
314 if (plog
->head
== plog
->tail
)
315 BFA_PL_LOG_REC_INCR(plog
->head
);
319 bfa_plog_init(struct bfa_plog_s
*plog
)
321 memset((char *)plog
, 0, sizeof(struct bfa_plog_s
));
323 memcpy(plog
->plog_sig
, BFA_PL_SIG_STR
, BFA_PL_SIG_LEN
);
324 plog
->head
= plog
->tail
= 0;
325 plog
->plog_enabled
= 1;
329 bfa_plog_str(struct bfa_plog_s
*plog
, enum bfa_plog_mid mid
,
330 enum bfa_plog_eid event
,
331 u16 misc
, char *log_str
)
333 struct bfa_plog_rec_s lp
;
335 if (plog
->plog_enabled
) {
336 memset(&lp
, 0, sizeof(struct bfa_plog_rec_s
));
339 lp
.log_type
= BFA_PL_LOG_TYPE_STRING
;
341 strlcpy(lp
.log_entry
.string_log
, log_str
,
342 BFA_PL_STRING_LOG_SZ
);
343 lp
.log_entry
.string_log
[BFA_PL_STRING_LOG_SZ
- 1] = '\0';
344 bfa_plog_add(plog
, &lp
);
349 bfa_plog_intarr(struct bfa_plog_s
*plog
, enum bfa_plog_mid mid
,
350 enum bfa_plog_eid event
,
351 u16 misc
, u32
*intarr
, u32 num_ints
)
353 struct bfa_plog_rec_s lp
;
356 if (num_ints
> BFA_PL_INT_LOG_SZ
)
357 num_ints
= BFA_PL_INT_LOG_SZ
;
359 if (plog
->plog_enabled
) {
360 memset(&lp
, 0, sizeof(struct bfa_plog_rec_s
));
363 lp
.log_type
= BFA_PL_LOG_TYPE_INT
;
366 for (i
= 0; i
< num_ints
; i
++)
367 lp
.log_entry
.int_log
[i
] = intarr
[i
];
369 lp
.log_num_ints
= (u8
) num_ints
;
371 bfa_plog_add(plog
, &lp
);
376 bfa_plog_fchdr(struct bfa_plog_s
*plog
, enum bfa_plog_mid mid
,
377 enum bfa_plog_eid event
,
378 u16 misc
, struct fchs_s
*fchdr
)
380 struct bfa_plog_rec_s lp
;
381 u32
*tmp_int
= (u32
*) fchdr
;
382 u32 ints
[BFA_PL_INT_LOG_SZ
];
384 if (plog
->plog_enabled
) {
385 memset(&lp
, 0, sizeof(struct bfa_plog_rec_s
));
387 ints
[0] = tmp_int
[0];
388 ints
[1] = tmp_int
[1];
389 ints
[2] = tmp_int
[4];
391 bfa_plog_intarr(plog
, mid
, event
, misc
, ints
, 3);
396 bfa_plog_fchdr_and_pl(struct bfa_plog_s
*plog
, enum bfa_plog_mid mid
,
397 enum bfa_plog_eid event
, u16 misc
, struct fchs_s
*fchdr
,
400 struct bfa_plog_rec_s lp
;
401 u32
*tmp_int
= (u32
*) fchdr
;
402 u32 ints
[BFA_PL_INT_LOG_SZ
];
404 if (plog
->plog_enabled
) {
405 memset(&lp
, 0, sizeof(struct bfa_plog_rec_s
));
407 ints
[0] = tmp_int
[0];
408 ints
[1] = tmp_int
[1];
409 ints
[2] = tmp_int
[4];
412 bfa_plog_intarr(plog
, mid
, event
, misc
, ints
, 4);
418 * fcxp_pvt BFA FCXP private functions
422 claim_fcxps_mem(struct bfa_fcxp_mod_s
*mod
)
425 struct bfa_fcxp_s
*fcxp
;
427 fcxp
= (struct bfa_fcxp_s
*) bfa_mem_kva_curp(mod
);
428 memset(fcxp
, 0, sizeof(struct bfa_fcxp_s
) * mod
->num_fcxps
);
430 INIT_LIST_HEAD(&mod
->fcxp_req_free_q
);
431 INIT_LIST_HEAD(&mod
->fcxp_rsp_free_q
);
432 INIT_LIST_HEAD(&mod
->fcxp_active_q
);
433 INIT_LIST_HEAD(&mod
->fcxp_req_unused_q
);
434 INIT_LIST_HEAD(&mod
->fcxp_rsp_unused_q
);
436 mod
->fcxp_list
= fcxp
;
438 for (i
= 0; i
< mod
->num_fcxps
; i
++) {
439 fcxp
->fcxp_mod
= mod
;
442 if (i
< (mod
->num_fcxps
/ 2)) {
443 list_add_tail(&fcxp
->qe
, &mod
->fcxp_req_free_q
);
444 fcxp
->req_rsp
= BFA_TRUE
;
446 list_add_tail(&fcxp
->qe
, &mod
->fcxp_rsp_free_q
);
447 fcxp
->req_rsp
= BFA_FALSE
;
450 bfa_reqq_winit(&fcxp
->reqq_wqe
, bfa_fcxp_qresume
, fcxp
);
451 fcxp
->reqq_waiting
= BFA_FALSE
;
456 bfa_mem_kva_curp(mod
) = (void *)fcxp
;
460 bfa_fcxp_meminfo(struct bfa_iocfc_cfg_s
*cfg
, struct bfa_meminfo_s
*minfo
,
463 struct bfa_fcxp_mod_s
*fcxp_mod
= BFA_FCXP_MOD(bfa
);
464 struct bfa_mem_kva_s
*fcxp_kva
= BFA_MEM_FCXP_KVA(bfa
);
465 struct bfa_mem_dma_s
*seg_ptr
;
466 u16 nsegs
, idx
, per_seg_fcxp
;
467 u16 num_fcxps
= cfg
->fwcfg
.num_fcxp_reqs
;
473 if (cfg
->drvcfg
.min_cfg
)
474 per_fcxp_sz
= 2 * BFA_FCXP_MAX_IBUF_SZ
;
476 per_fcxp_sz
= BFA_FCXP_MAX_IBUF_SZ
+ BFA_FCXP_MAX_LBUF_SZ
;
479 nsegs
= BFI_MEM_DMA_NSEGS(num_fcxps
, per_fcxp_sz
);
480 per_seg_fcxp
= BFI_MEM_NREQS_SEG(per_fcxp_sz
);
482 bfa_mem_dma_seg_iter(fcxp_mod
, seg_ptr
, nsegs
, idx
) {
483 if (num_fcxps
>= per_seg_fcxp
) {
484 num_fcxps
-= per_seg_fcxp
;
485 bfa_mem_dma_setup(minfo
, seg_ptr
,
486 per_seg_fcxp
* per_fcxp_sz
);
488 bfa_mem_dma_setup(minfo
, seg_ptr
,
489 num_fcxps
* per_fcxp_sz
);
493 bfa_mem_kva_setup(minfo
, fcxp_kva
,
494 cfg
->fwcfg
.num_fcxp_reqs
* sizeof(struct bfa_fcxp_s
));
498 bfa_fcxp_attach(struct bfa_s
*bfa
, void *bfad
, struct bfa_iocfc_cfg_s
*cfg
,
499 struct bfa_pcidev_s
*pcidev
)
501 struct bfa_fcxp_mod_s
*mod
= BFA_FCXP_MOD(bfa
);
504 mod
->num_fcxps
= cfg
->fwcfg
.num_fcxp_reqs
;
507 * Initialize FCXP request and response payload sizes.
509 mod
->req_pld_sz
= mod
->rsp_pld_sz
= BFA_FCXP_MAX_IBUF_SZ
;
510 if (!cfg
->drvcfg
.min_cfg
)
511 mod
->rsp_pld_sz
= BFA_FCXP_MAX_LBUF_SZ
;
513 INIT_LIST_HEAD(&mod
->req_wait_q
);
514 INIT_LIST_HEAD(&mod
->rsp_wait_q
);
516 claim_fcxps_mem(mod
);
520 bfa_fcxp_iocdisable(struct bfa_s
*bfa
)
522 struct bfa_fcxp_mod_s
*mod
= BFA_FCXP_MOD(bfa
);
523 struct bfa_fcxp_s
*fcxp
;
524 struct list_head
*qe
, *qen
;
526 /* Enqueue unused fcxp resources to free_q */
527 list_splice_tail_init(&mod
->fcxp_req_unused_q
, &mod
->fcxp_req_free_q
);
528 list_splice_tail_init(&mod
->fcxp_rsp_unused_q
, &mod
->fcxp_rsp_free_q
);
530 list_for_each_safe(qe
, qen
, &mod
->fcxp_active_q
) {
531 fcxp
= (struct bfa_fcxp_s
*) qe
;
532 if (fcxp
->caller
== NULL
) {
533 fcxp
->send_cbfn(fcxp
->caller
, fcxp
, fcxp
->send_cbarg
,
534 BFA_STATUS_IOC_FAILURE
, 0, 0, NULL
);
537 fcxp
->rsp_status
= BFA_STATUS_IOC_FAILURE
;
538 bfa_cb_queue(bfa
, &fcxp
->hcb_qe
,
539 __bfa_fcxp_send_cbfn
, fcxp
);
544 static struct bfa_fcxp_s
*
545 bfa_fcxp_get(struct bfa_fcxp_mod_s
*fm
, bfa_boolean_t req
)
547 struct bfa_fcxp_s
*fcxp
;
550 bfa_q_deq(&fm
->fcxp_req_free_q
, &fcxp
);
552 bfa_q_deq(&fm
->fcxp_rsp_free_q
, &fcxp
);
555 list_add_tail(&fcxp
->qe
, &fm
->fcxp_active_q
);
561 bfa_fcxp_init_reqrsp(struct bfa_fcxp_s
*fcxp
,
565 bfa_fcxp_get_sgaddr_t
*r_sga_cbfn
,
566 bfa_fcxp_get_sglen_t
*r_sglen_cbfn
,
567 struct list_head
*r_sgpg_q
,
569 bfa_fcxp_get_sgaddr_t sga_cbfn
,
570 bfa_fcxp_get_sglen_t sglen_cbfn
)
573 WARN_ON(bfa
== NULL
);
575 bfa_trc(bfa
, fcxp
->fcxp_tag
);
580 WARN_ON(*sga_cbfn
== NULL
);
581 WARN_ON(*sglen_cbfn
== NULL
);
584 *r_sga_cbfn
= sga_cbfn
;
585 *r_sglen_cbfn
= sglen_cbfn
;
590 * alloc required sgpgs
592 if (n_sgles
> BFI_SGE_INLINE
)
599 bfa_fcxp_init(struct bfa_fcxp_s
*fcxp
,
600 void *caller
, struct bfa_s
*bfa
, int nreq_sgles
,
601 int nrsp_sgles
, bfa_fcxp_get_sgaddr_t req_sga_cbfn
,
602 bfa_fcxp_get_sglen_t req_sglen_cbfn
,
603 bfa_fcxp_get_sgaddr_t rsp_sga_cbfn
,
604 bfa_fcxp_get_sglen_t rsp_sglen_cbfn
)
607 WARN_ON(bfa
== NULL
);
609 bfa_trc(bfa
, fcxp
->fcxp_tag
);
611 fcxp
->caller
= caller
;
613 bfa_fcxp_init_reqrsp(fcxp
, bfa
,
614 &fcxp
->use_ireqbuf
, &fcxp
->nreq_sgles
, &fcxp
->req_sga_cbfn
,
615 &fcxp
->req_sglen_cbfn
, &fcxp
->req_sgpg_q
,
616 nreq_sgles
, req_sga_cbfn
, req_sglen_cbfn
);
618 bfa_fcxp_init_reqrsp(fcxp
, bfa
,
619 &fcxp
->use_irspbuf
, &fcxp
->nrsp_sgles
, &fcxp
->rsp_sga_cbfn
,
620 &fcxp
->rsp_sglen_cbfn
, &fcxp
->rsp_sgpg_q
,
621 nrsp_sgles
, rsp_sga_cbfn
, rsp_sglen_cbfn
);
626 bfa_fcxp_put(struct bfa_fcxp_s
*fcxp
)
628 struct bfa_fcxp_mod_s
*mod
= fcxp
->fcxp_mod
;
629 struct bfa_fcxp_wqe_s
*wqe
;
632 bfa_q_deq(&mod
->req_wait_q
, &wqe
);
634 bfa_q_deq(&mod
->rsp_wait_q
, &wqe
);
637 bfa_trc(mod
->bfa
, fcxp
->fcxp_tag
);
639 bfa_fcxp_init(fcxp
, wqe
->caller
, wqe
->bfa
, wqe
->nreq_sgles
,
640 wqe
->nrsp_sgles
, wqe
->req_sga_cbfn
,
641 wqe
->req_sglen_cbfn
, wqe
->rsp_sga_cbfn
,
642 wqe
->rsp_sglen_cbfn
);
644 wqe
->alloc_cbfn(wqe
->alloc_cbarg
, fcxp
);
648 WARN_ON(!bfa_q_is_on_q(&mod
->fcxp_active_q
, fcxp
));
652 list_add_tail(&fcxp
->qe
, &mod
->fcxp_req_free_q
);
654 list_add_tail(&fcxp
->qe
, &mod
->fcxp_rsp_free_q
);
658 bfa_fcxp_null_comp(void *bfad_fcxp
, struct bfa_fcxp_s
*fcxp
, void *cbarg
,
659 bfa_status_t req_status
, u32 rsp_len
,
660 u32 resid_len
, struct fchs_s
*rsp_fchs
)
662 /* discarded fcxp completion */
666 __bfa_fcxp_send_cbfn(void *cbarg
, bfa_boolean_t complete
)
668 struct bfa_fcxp_s
*fcxp
= cbarg
;
671 fcxp
->send_cbfn(fcxp
->caller
, fcxp
, fcxp
->send_cbarg
,
672 fcxp
->rsp_status
, fcxp
->rsp_len
,
673 fcxp
->residue_len
, &fcxp
->rsp_fchs
);
680 hal_fcxp_send_comp(struct bfa_s
*bfa
, struct bfi_fcxp_send_rsp_s
*fcxp_rsp
)
682 struct bfa_fcxp_mod_s
*mod
= BFA_FCXP_MOD(bfa
);
683 struct bfa_fcxp_s
*fcxp
;
684 u16 fcxp_tag
= be16_to_cpu(fcxp_rsp
->fcxp_tag
);
686 bfa_trc(bfa
, fcxp_tag
);
688 fcxp_rsp
->rsp_len
= be32_to_cpu(fcxp_rsp
->rsp_len
);
691 * @todo f/w should not set residue to non-0 when everything
694 if (fcxp_rsp
->req_status
== BFA_STATUS_OK
)
695 fcxp_rsp
->residue_len
= 0;
697 fcxp_rsp
->residue_len
= be32_to_cpu(fcxp_rsp
->residue_len
);
699 fcxp
= BFA_FCXP_FROM_TAG(mod
, fcxp_tag
);
701 WARN_ON(fcxp
->send_cbfn
== NULL
);
703 hal_fcxp_rx_plog(mod
->bfa
, fcxp
, fcxp_rsp
);
705 if (fcxp
->send_cbfn
!= NULL
) {
706 bfa_trc(mod
->bfa
, (NULL
== fcxp
->caller
));
707 if (fcxp
->caller
== NULL
) {
708 fcxp
->send_cbfn(fcxp
->caller
, fcxp
, fcxp
->send_cbarg
,
709 fcxp_rsp
->req_status
, fcxp_rsp
->rsp_len
,
710 fcxp_rsp
->residue_len
, &fcxp_rsp
->fchs
);
712 * fcxp automatically freed on return from the callback
716 fcxp
->rsp_status
= fcxp_rsp
->req_status
;
717 fcxp
->rsp_len
= fcxp_rsp
->rsp_len
;
718 fcxp
->residue_len
= fcxp_rsp
->residue_len
;
719 fcxp
->rsp_fchs
= fcxp_rsp
->fchs
;
721 bfa_cb_queue(bfa
, &fcxp
->hcb_qe
,
722 __bfa_fcxp_send_cbfn
, fcxp
);
725 bfa_trc(bfa
, (NULL
== fcxp
->send_cbfn
));
730 hal_fcxp_tx_plog(struct bfa_s
*bfa
, u32 reqlen
, struct bfa_fcxp_s
*fcxp
,
737 if (fcxp
->use_ireqbuf
) {
739 *((u32
*) BFA_FCXP_REQ_PLD(fcxp
));
741 bfa_plog_fchdr_and_pl(bfa
->plog
, BFA_PL_MID_HAL_FCXP
,
743 reqlen
+ sizeof(struct fchs_s
), fchs
,
746 bfa_plog_fchdr(bfa
->plog
, BFA_PL_MID_HAL_FCXP
,
748 reqlen
+ sizeof(struct fchs_s
),
752 bfa_plog_fchdr(bfa
->plog
, BFA_PL_MID_HAL_FCXP
, BFA_PL_EID_TX
,
753 reqlen
+ sizeof(struct fchs_s
), fchs
);
758 hal_fcxp_rx_plog(struct bfa_s
*bfa
, struct bfa_fcxp_s
*fcxp
,
759 struct bfi_fcxp_send_rsp_s
*fcxp_rsp
)
761 if (fcxp_rsp
->rsp_len
> 0) {
762 if (fcxp
->use_irspbuf
) {
764 *((u32
*) BFA_FCXP_RSP_PLD(fcxp
));
766 bfa_plog_fchdr_and_pl(bfa
->plog
, BFA_PL_MID_HAL_FCXP
,
768 (u16
) fcxp_rsp
->rsp_len
,
769 &fcxp_rsp
->fchs
, pld_w0
);
771 bfa_plog_fchdr(bfa
->plog
, BFA_PL_MID_HAL_FCXP
,
773 (u16
) fcxp_rsp
->rsp_len
,
777 bfa_plog_fchdr(bfa
->plog
, BFA_PL_MID_HAL_FCXP
, BFA_PL_EID_RX
,
778 (u16
) fcxp_rsp
->rsp_len
, &fcxp_rsp
->fchs
);
783 * Handler to resume sending fcxp when space in available in cpe queue.
786 bfa_fcxp_qresume(void *cbarg
)
788 struct bfa_fcxp_s
*fcxp
= cbarg
;
789 struct bfa_s
*bfa
= fcxp
->fcxp_mod
->bfa
;
790 struct bfi_fcxp_send_req_s
*send_req
;
792 fcxp
->reqq_waiting
= BFA_FALSE
;
793 send_req
= bfa_reqq_next(bfa
, BFA_REQQ_FCXP
);
794 bfa_fcxp_queue(fcxp
, send_req
);
798 * Queue fcxp send request to foimrware.
801 bfa_fcxp_queue(struct bfa_fcxp_s
*fcxp
, struct bfi_fcxp_send_req_s
*send_req
)
803 struct bfa_s
*bfa
= fcxp
->fcxp_mod
->bfa
;
804 struct bfa_fcxp_req_info_s
*reqi
= &fcxp
->req_info
;
805 struct bfa_fcxp_rsp_info_s
*rspi
= &fcxp
->rsp_info
;
806 struct bfa_rport_s
*rport
= reqi
->bfa_rport
;
808 bfi_h2i_set(send_req
->mh
, BFI_MC_FCXP
, BFI_FCXP_H2I_SEND_REQ
,
811 send_req
->fcxp_tag
= cpu_to_be16(fcxp
->fcxp_tag
);
813 send_req
->rport_fw_hndl
= rport
->fw_handle
;
814 send_req
->max_frmsz
= cpu_to_be16(rport
->rport_info
.max_frmsz
);
815 if (send_req
->max_frmsz
== 0)
816 send_req
->max_frmsz
= cpu_to_be16(FC_MAX_PDUSZ
);
818 send_req
->rport_fw_hndl
= 0;
819 send_req
->max_frmsz
= cpu_to_be16(FC_MAX_PDUSZ
);
822 send_req
->vf_id
= cpu_to_be16(reqi
->vf_id
);
823 send_req
->lp_fwtag
= bfa_lps_get_fwtag(bfa
, reqi
->lp_tag
);
824 send_req
->class = reqi
->class;
825 send_req
->rsp_timeout
= rspi
->rsp_timeout
;
826 send_req
->cts
= reqi
->cts
;
827 send_req
->fchs
= reqi
->fchs
;
829 send_req
->req_len
= cpu_to_be32(reqi
->req_tot_len
);
830 send_req
->rsp_maxlen
= cpu_to_be32(rspi
->rsp_maxlen
);
835 if (fcxp
->use_ireqbuf
== 1) {
836 bfa_alen_set(&send_req
->req_alen
, reqi
->req_tot_len
,
837 BFA_FCXP_REQ_PLD_PA(fcxp
));
839 if (fcxp
->nreq_sgles
> 0) {
840 WARN_ON(fcxp
->nreq_sgles
!= 1);
841 bfa_alen_set(&send_req
->req_alen
, reqi
->req_tot_len
,
842 fcxp
->req_sga_cbfn(fcxp
->caller
, 0));
844 WARN_ON(reqi
->req_tot_len
!= 0);
845 bfa_alen_set(&send_req
->rsp_alen
, 0, 0);
852 if (fcxp
->use_irspbuf
== 1) {
853 WARN_ON(rspi
->rsp_maxlen
> BFA_FCXP_MAX_LBUF_SZ
);
855 bfa_alen_set(&send_req
->rsp_alen
, rspi
->rsp_maxlen
,
856 BFA_FCXP_RSP_PLD_PA(fcxp
));
858 if (fcxp
->nrsp_sgles
> 0) {
859 WARN_ON(fcxp
->nrsp_sgles
!= 1);
860 bfa_alen_set(&send_req
->rsp_alen
, rspi
->rsp_maxlen
,
861 fcxp
->rsp_sga_cbfn(fcxp
->caller
, 0));
864 WARN_ON(rspi
->rsp_maxlen
!= 0);
865 bfa_alen_set(&send_req
->rsp_alen
, 0, 0);
869 hal_fcxp_tx_plog(bfa
, reqi
->req_tot_len
, fcxp
, &reqi
->fchs
);
871 bfa_reqq_produce(bfa
, BFA_REQQ_FCXP
, send_req
->mh
);
873 bfa_trc(bfa
, bfa_reqq_pi(bfa
, BFA_REQQ_FCXP
));
874 bfa_trc(bfa
, bfa_reqq_ci(bfa
, BFA_REQQ_FCXP
));
878 * Allocate an FCXP instance to send a response or to send a request
879 * that has a response. Request/response buffers are allocated by caller.
881 * @param[in] bfa BFA bfa instance
882 * @param[in] nreq_sgles Number of SG elements required for request
883 * buffer. 0, if fcxp internal buffers are used.
884 * Use bfa_fcxp_get_reqbuf() to get the
885 * internal req buffer.
886 * @param[in] req_sgles SG elements describing request buffer. Will be
887 * copied in by BFA and hence can be freed on
888 * return from this function.
889 * @param[in] get_req_sga function ptr to be called to get a request SG
890 * Address (given the sge index).
891 * @param[in] get_req_sglen function ptr to be called to get a request SG
892 * len (given the sge index).
893 * @param[in] get_rsp_sga function ptr to be called to get a response SG
894 * Address (given the sge index).
895 * @param[in] get_rsp_sglen function ptr to be called to get a response SG
896 * len (given the sge index).
897 * @param[in] req Allocated FCXP is used to send req or rsp?
898 * request - BFA_TRUE, response - BFA_FALSE
900 * @return FCXP instance. NULL on failure.
903 bfa_fcxp_req_rsp_alloc(void *caller
, struct bfa_s
*bfa
, int nreq_sgles
,
904 int nrsp_sgles
, bfa_fcxp_get_sgaddr_t req_sga_cbfn
,
905 bfa_fcxp_get_sglen_t req_sglen_cbfn
,
906 bfa_fcxp_get_sgaddr_t rsp_sga_cbfn
,
907 bfa_fcxp_get_sglen_t rsp_sglen_cbfn
, bfa_boolean_t req
)
909 struct bfa_fcxp_s
*fcxp
= NULL
;
911 WARN_ON(bfa
== NULL
);
913 fcxp
= bfa_fcxp_get(BFA_FCXP_MOD(bfa
), req
);
917 bfa_trc(bfa
, fcxp
->fcxp_tag
);
919 bfa_fcxp_init(fcxp
, caller
, bfa
, nreq_sgles
, nrsp_sgles
, req_sga_cbfn
,
920 req_sglen_cbfn
, rsp_sga_cbfn
, rsp_sglen_cbfn
);
926 * Get the internal request buffer pointer
928 * @param[in] fcxp BFA fcxp pointer
930 * @return pointer to the internal request buffer
933 bfa_fcxp_get_reqbuf(struct bfa_fcxp_s
*fcxp
)
935 struct bfa_fcxp_mod_s
*mod
= fcxp
->fcxp_mod
;
938 WARN_ON(fcxp
->use_ireqbuf
!= 1);
939 reqbuf
= bfa_mem_get_dmabuf_kva(mod
, fcxp
->fcxp_tag
,
940 mod
->req_pld_sz
+ mod
->rsp_pld_sz
);
945 bfa_fcxp_get_reqbufsz(struct bfa_fcxp_s
*fcxp
)
947 struct bfa_fcxp_mod_s
*mod
= fcxp
->fcxp_mod
;
949 return mod
->req_pld_sz
;
953 * Get the internal response buffer pointer
955 * @param[in] fcxp BFA fcxp pointer
957 * @return pointer to the internal request buffer
960 bfa_fcxp_get_rspbuf(struct bfa_fcxp_s
*fcxp
)
962 struct bfa_fcxp_mod_s
*mod
= fcxp
->fcxp_mod
;
965 WARN_ON(fcxp
->use_irspbuf
!= 1);
967 fcxp_buf
= bfa_mem_get_dmabuf_kva(mod
, fcxp
->fcxp_tag
,
968 mod
->req_pld_sz
+ mod
->rsp_pld_sz
);
970 /* fcxp_buf = req_buf + rsp_buf :- add req_buf_sz to get to rsp_buf */
971 return ((u8
*) fcxp_buf
) + mod
->req_pld_sz
;
977 * @param[in] fcxp BFA fcxp pointer
982 bfa_fcxp_free(struct bfa_fcxp_s
*fcxp
)
984 struct bfa_fcxp_mod_s
*mod
= fcxp
->fcxp_mod
;
986 WARN_ON(fcxp
== NULL
);
987 bfa_trc(mod
->bfa
, fcxp
->fcxp_tag
);
992 * Send a FCXP request
994 * @param[in] fcxp BFA fcxp pointer
995 * @param[in] rport BFA rport pointer. Could be left NULL for WKA rports
996 * @param[in] vf_id virtual Fabric ID
997 * @param[in] lp_tag lport tag
998 * @param[in] cts use Continuous sequence
999 * @param[in] cos fc Class of Service
1000 * @param[in] reqlen request length, does not include FCHS length
1001 * @param[in] fchs fc Header Pointer. The header content will be copied
1004 * @param[in] cbfn call back function to be called on receiving
1006 * @param[in] cbarg arg for cbfn
1007 * @param[in] rsp_timeout
1010 * @return bfa_status_t
1013 bfa_fcxp_send(struct bfa_fcxp_s
*fcxp
, struct bfa_rport_s
*rport
,
1014 u16 vf_id
, u8 lp_tag
, bfa_boolean_t cts
, enum fc_cos cos
,
1015 u32 reqlen
, struct fchs_s
*fchs
, bfa_cb_fcxp_send_t cbfn
,
1016 void *cbarg
, u32 rsp_maxlen
, u8 rsp_timeout
)
1018 struct bfa_s
*bfa
= fcxp
->fcxp_mod
->bfa
;
1019 struct bfa_fcxp_req_info_s
*reqi
= &fcxp
->req_info
;
1020 struct bfa_fcxp_rsp_info_s
*rspi
= &fcxp
->rsp_info
;
1021 struct bfi_fcxp_send_req_s
*send_req
;
1023 bfa_trc(bfa
, fcxp
->fcxp_tag
);
1026 * setup request/response info
1028 reqi
->bfa_rport
= rport
;
1029 reqi
->vf_id
= vf_id
;
1030 reqi
->lp_tag
= lp_tag
;
1032 rspi
->rsp_timeout
= rsp_timeout
;
1035 reqi
->req_tot_len
= reqlen
;
1036 rspi
->rsp_maxlen
= rsp_maxlen
;
1037 fcxp
->send_cbfn
= cbfn
? cbfn
: bfa_fcxp_null_comp
;
1038 fcxp
->send_cbarg
= cbarg
;
1041 * If no room in CPE queue, wait for space in request queue
1043 send_req
= bfa_reqq_next(bfa
, BFA_REQQ_FCXP
);
1045 bfa_trc(bfa
, fcxp
->fcxp_tag
);
1046 fcxp
->reqq_waiting
= BFA_TRUE
;
1047 bfa_reqq_wait(bfa
, BFA_REQQ_FCXP
, &fcxp
->reqq_wqe
);
1051 bfa_fcxp_queue(fcxp
, send_req
);
1057 * @param[in] fcxp BFA fcxp pointer
1062 bfa_fcxp_abort(struct bfa_fcxp_s
*fcxp
)
1064 bfa_trc(fcxp
->fcxp_mod
->bfa
, fcxp
->fcxp_tag
);
1066 return BFA_STATUS_OK
;
1070 bfa_fcxp_req_rsp_alloc_wait(struct bfa_s
*bfa
, struct bfa_fcxp_wqe_s
*wqe
,
1071 bfa_fcxp_alloc_cbfn_t alloc_cbfn
, void *alloc_cbarg
,
1072 void *caller
, int nreq_sgles
,
1073 int nrsp_sgles
, bfa_fcxp_get_sgaddr_t req_sga_cbfn
,
1074 bfa_fcxp_get_sglen_t req_sglen_cbfn
,
1075 bfa_fcxp_get_sgaddr_t rsp_sga_cbfn
,
1076 bfa_fcxp_get_sglen_t rsp_sglen_cbfn
, bfa_boolean_t req
)
1078 struct bfa_fcxp_mod_s
*mod
= BFA_FCXP_MOD(bfa
);
1081 WARN_ON(!list_empty(&mod
->fcxp_req_free_q
));
1083 WARN_ON(!list_empty(&mod
->fcxp_rsp_free_q
));
1085 wqe
->alloc_cbfn
= alloc_cbfn
;
1086 wqe
->alloc_cbarg
= alloc_cbarg
;
1087 wqe
->caller
= caller
;
1089 wqe
->nreq_sgles
= nreq_sgles
;
1090 wqe
->nrsp_sgles
= nrsp_sgles
;
1091 wqe
->req_sga_cbfn
= req_sga_cbfn
;
1092 wqe
->req_sglen_cbfn
= req_sglen_cbfn
;
1093 wqe
->rsp_sga_cbfn
= rsp_sga_cbfn
;
1094 wqe
->rsp_sglen_cbfn
= rsp_sglen_cbfn
;
1097 list_add_tail(&wqe
->qe
, &mod
->req_wait_q
);
1099 list_add_tail(&wqe
->qe
, &mod
->rsp_wait_q
);
1103 bfa_fcxp_walloc_cancel(struct bfa_s
*bfa
, struct bfa_fcxp_wqe_s
*wqe
)
1105 struct bfa_fcxp_mod_s
*mod
= BFA_FCXP_MOD(bfa
);
1107 WARN_ON(!bfa_q_is_on_q(&mod
->req_wait_q
, wqe
) ||
1108 !bfa_q_is_on_q(&mod
->rsp_wait_q
, wqe
));
1113 bfa_fcxp_discard(struct bfa_fcxp_s
*fcxp
)
1116 * If waiting for room in request queue, cancel reqq wait
1119 if (fcxp
->reqq_waiting
) {
1120 fcxp
->reqq_waiting
= BFA_FALSE
;
1121 bfa_reqq_wcancel(&fcxp
->reqq_wqe
);
1122 bfa_fcxp_free(fcxp
);
1126 fcxp
->send_cbfn
= bfa_fcxp_null_comp
;
1130 bfa_fcxp_isr(struct bfa_s
*bfa
, struct bfi_msg_s
*msg
)
1132 switch (msg
->mhdr
.msg_id
) {
1133 case BFI_FCXP_I2H_SEND_RSP
:
1134 hal_fcxp_send_comp(bfa
, (struct bfi_fcxp_send_rsp_s
*) msg
);
1138 bfa_trc(bfa
, msg
->mhdr
.msg_id
);
1144 bfa_fcxp_get_maxrsp(struct bfa_s
*bfa
)
1146 struct bfa_fcxp_mod_s
*mod
= BFA_FCXP_MOD(bfa
);
1148 return mod
->rsp_pld_sz
;
1152 bfa_fcxp_res_recfg(struct bfa_s
*bfa
, u16 num_fcxp_fw
)
1154 struct bfa_fcxp_mod_s
*mod
= BFA_FCXP_MOD(bfa
);
1155 struct list_head
*qe
;
1158 for (i
= 0; i
< (mod
->num_fcxps
- num_fcxp_fw
); i
++) {
1159 if (i
< ((mod
->num_fcxps
- num_fcxp_fw
) / 2)) {
1160 bfa_q_deq_tail(&mod
->fcxp_req_free_q
, &qe
);
1161 list_add_tail(qe
, &mod
->fcxp_req_unused_q
);
1163 bfa_q_deq_tail(&mod
->fcxp_rsp_free_q
, &qe
);
1164 list_add_tail(qe
, &mod
->fcxp_rsp_unused_q
);
1170 * BFA LPS state machine functions
1174 * Init state -- no login
1177 bfa_lps_sm_init(struct bfa_lps_s
*lps
, enum bfa_lps_event event
)
1179 bfa_trc(lps
->bfa
, lps
->bfa_tag
);
1180 bfa_trc(lps
->bfa
, event
);
1183 case BFA_LPS_SM_LOGIN
:
1184 if (bfa_reqq_full(lps
->bfa
, lps
->reqq
)) {
1185 bfa_sm_set_state(lps
, bfa_lps_sm_loginwait
);
1186 bfa_reqq_wait(lps
->bfa
, lps
->reqq
, &lps
->wqe
);
1188 bfa_sm_set_state(lps
, bfa_lps_sm_login
);
1189 bfa_lps_send_login(lps
);
1193 bfa_plog_str(lps
->bfa
->plog
, BFA_PL_MID_LPS
,
1194 BFA_PL_EID_LOGIN
, 0, "FDISC Request");
1196 bfa_plog_str(lps
->bfa
->plog
, BFA_PL_MID_LPS
,
1197 BFA_PL_EID_LOGIN
, 0, "FLOGI Request");
1200 case BFA_LPS_SM_LOGOUT
:
1201 bfa_lps_logout_comp(lps
);
1204 case BFA_LPS_SM_DELETE
:
1208 case BFA_LPS_SM_RX_CVL
:
1209 case BFA_LPS_SM_OFFLINE
:
1212 case BFA_LPS_SM_FWRSP
:
1214 * Could happen when fabric detects loopback and discards
1215 * the lps request. Fw will eventually sent out the timeout
1219 case BFA_LPS_SM_SET_N2N_PID
:
1221 * When topology is set to loop, bfa_lps_set_n2n_pid() sends
1222 * this event. Ignore this event.
1227 bfa_sm_fault(lps
->bfa
, event
);
1232 * login is in progress -- awaiting response from firmware
1235 bfa_lps_sm_login(struct bfa_lps_s
*lps
, enum bfa_lps_event event
)
1237 bfa_trc(lps
->bfa
, lps
->bfa_tag
);
1238 bfa_trc(lps
->bfa
, event
);
1241 case BFA_LPS_SM_FWRSP
:
1242 if (lps
->status
== BFA_STATUS_OK
) {
1243 bfa_sm_set_state(lps
, bfa_lps_sm_online
);
1245 bfa_plog_str(lps
->bfa
->plog
, BFA_PL_MID_LPS
,
1246 BFA_PL_EID_LOGIN
, 0, "FDISC Accept");
1248 bfa_plog_str(lps
->bfa
->plog
, BFA_PL_MID_LPS
,
1249 BFA_PL_EID_LOGIN
, 0, "FLOGI Accept");
1250 /* If N2N, send the assigned PID to FW */
1251 bfa_trc(lps
->bfa
, lps
->fport
);
1252 bfa_trc(lps
->bfa
, lps
->lp_pid
);
1254 if (!lps
->fport
&& lps
->lp_pid
)
1255 bfa_sm_send_event(lps
, BFA_LPS_SM_SET_N2N_PID
);
1257 bfa_sm_set_state(lps
, bfa_lps_sm_init
);
1259 bfa_plog_str(lps
->bfa
->plog
, BFA_PL_MID_LPS
,
1260 BFA_PL_EID_LOGIN
, 0,
1261 "FDISC Fail (RJT or timeout)");
1263 bfa_plog_str(lps
->bfa
->plog
, BFA_PL_MID_LPS
,
1264 BFA_PL_EID_LOGIN
, 0,
1265 "FLOGI Fail (RJT or timeout)");
1267 bfa_lps_login_comp(lps
);
1270 case BFA_LPS_SM_OFFLINE
:
1271 case BFA_LPS_SM_DELETE
:
1272 bfa_sm_set_state(lps
, bfa_lps_sm_init
);
1275 case BFA_LPS_SM_SET_N2N_PID
:
1276 bfa_trc(lps
->bfa
, lps
->fport
);
1277 bfa_trc(lps
->bfa
, lps
->lp_pid
);
1281 bfa_sm_fault(lps
->bfa
, event
);
1286 * login pending - awaiting space in request queue
1289 bfa_lps_sm_loginwait(struct bfa_lps_s
*lps
, enum bfa_lps_event event
)
1291 bfa_trc(lps
->bfa
, lps
->bfa_tag
);
1292 bfa_trc(lps
->bfa
, event
);
1295 case BFA_LPS_SM_RESUME
:
1296 bfa_sm_set_state(lps
, bfa_lps_sm_login
);
1297 bfa_lps_send_login(lps
);
1300 case BFA_LPS_SM_OFFLINE
:
1301 case BFA_LPS_SM_DELETE
:
1302 bfa_sm_set_state(lps
, bfa_lps_sm_init
);
1303 bfa_reqq_wcancel(&lps
->wqe
);
1306 case BFA_LPS_SM_RX_CVL
:
1308 * Login was not even sent out; so when getting out
1309 * of this state, it will appear like a login retry
1310 * after Clear virtual link
1315 bfa_sm_fault(lps
->bfa
, event
);
1323 bfa_lps_sm_online(struct bfa_lps_s
*lps
, enum bfa_lps_event event
)
1325 bfa_trc(lps
->bfa
, lps
->bfa_tag
);
1326 bfa_trc(lps
->bfa
, event
);
1329 case BFA_LPS_SM_LOGOUT
:
1330 if (bfa_reqq_full(lps
->bfa
, lps
->reqq
)) {
1331 bfa_sm_set_state(lps
, bfa_lps_sm_logowait
);
1332 bfa_reqq_wait(lps
->bfa
, lps
->reqq
, &lps
->wqe
);
1334 bfa_sm_set_state(lps
, bfa_lps_sm_logout
);
1335 bfa_lps_send_logout(lps
);
1337 bfa_plog_str(lps
->bfa
->plog
, BFA_PL_MID_LPS
,
1338 BFA_PL_EID_LOGO
, 0, "Logout");
1341 case BFA_LPS_SM_RX_CVL
:
1342 bfa_sm_set_state(lps
, bfa_lps_sm_init
);
1344 /* Let the vport module know about this event */
1345 bfa_lps_cvl_event(lps
);
1346 bfa_plog_str(lps
->bfa
->plog
, BFA_PL_MID_LPS
,
1347 BFA_PL_EID_FIP_FCF_CVL
, 0, "FCF Clear Virt. Link Rx");
1350 case BFA_LPS_SM_SET_N2N_PID
:
1351 if (bfa_reqq_full(lps
->bfa
, lps
->reqq
)) {
1352 bfa_sm_set_state(lps
, bfa_lps_sm_online_n2n_pid_wait
);
1353 bfa_reqq_wait(lps
->bfa
, lps
->reqq
, &lps
->wqe
);
1355 bfa_lps_send_set_n2n_pid(lps
);
1358 case BFA_LPS_SM_OFFLINE
:
1359 case BFA_LPS_SM_DELETE
:
1360 bfa_sm_set_state(lps
, bfa_lps_sm_init
);
1364 bfa_sm_fault(lps
->bfa
, event
);
1372 bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s
*lps
, enum bfa_lps_event event
)
1374 bfa_trc(lps
->bfa
, lps
->bfa_tag
);
1375 bfa_trc(lps
->bfa
, event
);
1378 case BFA_LPS_SM_RESUME
:
1379 bfa_sm_set_state(lps
, bfa_lps_sm_online
);
1380 bfa_lps_send_set_n2n_pid(lps
);
1383 case BFA_LPS_SM_LOGOUT
:
1384 bfa_sm_set_state(lps
, bfa_lps_sm_logowait
);
1385 bfa_plog_str(lps
->bfa
->plog
, BFA_PL_MID_LPS
,
1386 BFA_PL_EID_LOGO
, 0, "Logout");
1389 case BFA_LPS_SM_RX_CVL
:
1390 bfa_sm_set_state(lps
, bfa_lps_sm_init
);
1391 bfa_reqq_wcancel(&lps
->wqe
);
1393 /* Let the vport module know about this event */
1394 bfa_lps_cvl_event(lps
);
1395 bfa_plog_str(lps
->bfa
->plog
, BFA_PL_MID_LPS
,
1396 BFA_PL_EID_FIP_FCF_CVL
, 0, "FCF Clear Virt. Link Rx");
1399 case BFA_LPS_SM_OFFLINE
:
1400 case BFA_LPS_SM_DELETE
:
1401 bfa_sm_set_state(lps
, bfa_lps_sm_init
);
1402 bfa_reqq_wcancel(&lps
->wqe
);
1406 bfa_sm_fault(lps
->bfa
, event
);
1411 * logout in progress - awaiting firmware response
1414 bfa_lps_sm_logout(struct bfa_lps_s
*lps
, enum bfa_lps_event event
)
1416 bfa_trc(lps
->bfa
, lps
->bfa_tag
);
1417 bfa_trc(lps
->bfa
, event
);
1420 case BFA_LPS_SM_FWRSP
:
1421 case BFA_LPS_SM_OFFLINE
:
1422 bfa_sm_set_state(lps
, bfa_lps_sm_init
);
1423 bfa_lps_logout_comp(lps
);
1426 case BFA_LPS_SM_DELETE
:
1427 bfa_sm_set_state(lps
, bfa_lps_sm_init
);
1431 bfa_sm_fault(lps
->bfa
, event
);
1436 * logout pending -- awaiting space in request queue
1439 bfa_lps_sm_logowait(struct bfa_lps_s
*lps
, enum bfa_lps_event event
)
1441 bfa_trc(lps
->bfa
, lps
->bfa_tag
);
1442 bfa_trc(lps
->bfa
, event
);
1445 case BFA_LPS_SM_RESUME
:
1446 bfa_sm_set_state(lps
, bfa_lps_sm_logout
);
1447 bfa_lps_send_logout(lps
);
1450 case BFA_LPS_SM_OFFLINE
:
1451 case BFA_LPS_SM_DELETE
:
1452 bfa_sm_set_state(lps
, bfa_lps_sm_init
);
1453 bfa_reqq_wcancel(&lps
->wqe
);
1457 bfa_sm_fault(lps
->bfa
, event
);
1464 * lps_pvt BFA LPS private functions
1468 * return memory requirement
1471 bfa_lps_meminfo(struct bfa_iocfc_cfg_s
*cfg
, struct bfa_meminfo_s
*minfo
,
1474 struct bfa_mem_kva_s
*lps_kva
= BFA_MEM_LPS_KVA(bfa
);
1476 if (cfg
->drvcfg
.min_cfg
)
1477 bfa_mem_kva_setup(minfo
, lps_kva
,
1478 sizeof(struct bfa_lps_s
) * BFA_LPS_MIN_LPORTS
);
1480 bfa_mem_kva_setup(minfo
, lps_kva
,
1481 sizeof(struct bfa_lps_s
) * BFA_LPS_MAX_LPORTS
);
1485 * bfa module attach at initialization time
1488 bfa_lps_attach(struct bfa_s
*bfa
, void *bfad
, struct bfa_iocfc_cfg_s
*cfg
,
1489 struct bfa_pcidev_s
*pcidev
)
1491 struct bfa_lps_mod_s
*mod
= BFA_LPS_MOD(bfa
);
1492 struct bfa_lps_s
*lps
;
1495 mod
->num_lps
= BFA_LPS_MAX_LPORTS
;
1496 if (cfg
->drvcfg
.min_cfg
)
1497 mod
->num_lps
= BFA_LPS_MIN_LPORTS
;
1499 mod
->num_lps
= BFA_LPS_MAX_LPORTS
;
1500 mod
->lps_arr
= lps
= (struct bfa_lps_s
*) bfa_mem_kva_curp(mod
);
1502 bfa_mem_kva_curp(mod
) += mod
->num_lps
* sizeof(struct bfa_lps_s
);
1504 INIT_LIST_HEAD(&mod
->lps_free_q
);
1505 INIT_LIST_HEAD(&mod
->lps_active_q
);
1506 INIT_LIST_HEAD(&mod
->lps_login_q
);
1508 for (i
= 0; i
< mod
->num_lps
; i
++, lps
++) {
1510 lps
->bfa_tag
= (u8
) i
;
1511 lps
->reqq
= BFA_REQQ_LPS
;
1512 bfa_reqq_winit(&lps
->wqe
, bfa_lps_reqq_resume
, lps
);
1513 list_add_tail(&lps
->qe
, &mod
->lps_free_q
);
1518 * IOC in disabled state -- consider all lps offline
1521 bfa_lps_iocdisable(struct bfa_s
*bfa
)
1523 struct bfa_lps_mod_s
*mod
= BFA_LPS_MOD(bfa
);
1524 struct bfa_lps_s
*lps
;
1525 struct list_head
*qe
, *qen
;
1527 list_for_each_safe(qe
, qen
, &mod
->lps_active_q
) {
1528 lps
= (struct bfa_lps_s
*) qe
;
1529 bfa_sm_send_event(lps
, BFA_LPS_SM_OFFLINE
);
1531 list_for_each_safe(qe
, qen
, &mod
->lps_login_q
) {
1532 lps
= (struct bfa_lps_s
*) qe
;
1533 bfa_sm_send_event(lps
, BFA_LPS_SM_OFFLINE
);
1535 list_splice_tail_init(&mod
->lps_login_q
, &mod
->lps_active_q
);
1539 * Firmware login response
1542 bfa_lps_login_rsp(struct bfa_s
*bfa
, struct bfi_lps_login_rsp_s
*rsp
)
1544 struct bfa_lps_mod_s
*mod
= BFA_LPS_MOD(bfa
);
1545 struct bfa_lps_s
*lps
;
1547 WARN_ON(rsp
->bfa_tag
>= mod
->num_lps
);
1548 lps
= BFA_LPS_FROM_TAG(mod
, rsp
->bfa_tag
);
1550 lps
->status
= rsp
->status
;
1551 switch (rsp
->status
) {
1553 lps
->fw_tag
= rsp
->fw_tag
;
1554 lps
->fport
= rsp
->f_port
;
1556 lps
->lp_pid
= rsp
->lp_pid
;
1557 lps
->npiv_en
= rsp
->npiv_en
;
1558 lps
->pr_bbcred
= be16_to_cpu(rsp
->bb_credit
);
1559 lps
->pr_pwwn
= rsp
->port_name
;
1560 lps
->pr_nwwn
= rsp
->node_name
;
1561 lps
->auth_req
= rsp
->auth_req
;
1562 lps
->lp_mac
= rsp
->lp_mac
;
1563 lps
->brcd_switch
= rsp
->brcd_switch
;
1564 lps
->fcf_mac
= rsp
->fcf_mac
;
1568 case BFA_STATUS_FABRIC_RJT
:
1569 lps
->lsrjt_rsn
= rsp
->lsrjt_rsn
;
1570 lps
->lsrjt_expl
= rsp
->lsrjt_expl
;
1574 case BFA_STATUS_EPROTOCOL
:
1575 lps
->ext_status
= rsp
->ext_status
;
1579 case BFA_STATUS_VPORT_MAX
:
1580 if (rsp
->ext_status
)
1581 bfa_lps_no_res(lps
, rsp
->ext_status
);
1585 /* Nothing to do with other status */
1590 list_add_tail(&lps
->qe
, &mod
->lps_active_q
);
1591 bfa_sm_send_event(lps
, BFA_LPS_SM_FWRSP
);
1595 bfa_lps_no_res(struct bfa_lps_s
*first_lps
, u8 count
)
1597 struct bfa_s
*bfa
= first_lps
->bfa
;
1598 struct bfa_lps_mod_s
*mod
= BFA_LPS_MOD(bfa
);
1599 struct list_head
*qe
, *qe_next
;
1600 struct bfa_lps_s
*lps
;
1602 bfa_trc(bfa
, count
);
1604 qe
= bfa_q_next(first_lps
);
1606 while (count
&& qe
) {
1607 qe_next
= bfa_q_next(qe
);
1608 lps
= (struct bfa_lps_s
*)qe
;
1609 bfa_trc(bfa
, lps
->bfa_tag
);
1610 lps
->status
= first_lps
->status
;
1612 list_add_tail(&lps
->qe
, &mod
->lps_active_q
);
1613 bfa_sm_send_event(lps
, BFA_LPS_SM_FWRSP
);
1620 * Firmware logout response
1623 bfa_lps_logout_rsp(struct bfa_s
*bfa
, struct bfi_lps_logout_rsp_s
*rsp
)
1625 struct bfa_lps_mod_s
*mod
= BFA_LPS_MOD(bfa
);
1626 struct bfa_lps_s
*lps
;
1628 WARN_ON(rsp
->bfa_tag
>= mod
->num_lps
);
1629 lps
= BFA_LPS_FROM_TAG(mod
, rsp
->bfa_tag
);
1631 bfa_sm_send_event(lps
, BFA_LPS_SM_FWRSP
);
1635 * Firmware received a Clear virtual link request (for FCoE)
1638 bfa_lps_rx_cvl_event(struct bfa_s
*bfa
, struct bfi_lps_cvl_event_s
*cvl
)
1640 struct bfa_lps_mod_s
*mod
= BFA_LPS_MOD(bfa
);
1641 struct bfa_lps_s
*lps
;
1643 lps
= BFA_LPS_FROM_TAG(mod
, cvl
->bfa_tag
);
1645 bfa_sm_send_event(lps
, BFA_LPS_SM_RX_CVL
);
1649 * Space is available in request queue, resume queueing request to firmware.
1652 bfa_lps_reqq_resume(void *lps_arg
)
1654 struct bfa_lps_s
*lps
= lps_arg
;
1656 bfa_sm_send_event(lps
, BFA_LPS_SM_RESUME
);
1660 * lps is freed -- triggered by vport delete
1663 bfa_lps_free(struct bfa_lps_s
*lps
)
1665 struct bfa_lps_mod_s
*mod
= BFA_LPS_MOD(lps
->bfa
);
1669 list_add_tail(&lps
->qe
, &mod
->lps_free_q
);
1673 * send login request to firmware
1676 bfa_lps_send_login(struct bfa_lps_s
*lps
)
1678 struct bfa_lps_mod_s
*mod
= BFA_LPS_MOD(lps
->bfa
);
1679 struct bfi_lps_login_req_s
*m
;
1681 m
= bfa_reqq_next(lps
->bfa
, lps
->reqq
);
1684 bfi_h2i_set(m
->mh
, BFI_MC_LPS
, BFI_LPS_H2I_LOGIN_REQ
,
1685 bfa_fn_lpu(lps
->bfa
));
1687 m
->bfa_tag
= lps
->bfa_tag
;
1688 m
->alpa
= lps
->alpa
;
1689 m
->pdu_size
= cpu_to_be16(lps
->pdusz
);
1690 m
->pwwn
= lps
->pwwn
;
1691 m
->nwwn
= lps
->nwwn
;
1692 m
->fdisc
= lps
->fdisc
;
1693 m
->auth_en
= lps
->auth_en
;
1695 bfa_reqq_produce(lps
->bfa
, lps
->reqq
, m
->mh
);
1697 list_add_tail(&lps
->qe
, &mod
->lps_login_q
);
1701 * send logout request to firmware
1704 bfa_lps_send_logout(struct bfa_lps_s
*lps
)
1706 struct bfi_lps_logout_req_s
*m
;
1708 m
= bfa_reqq_next(lps
->bfa
, lps
->reqq
);
1711 bfi_h2i_set(m
->mh
, BFI_MC_LPS
, BFI_LPS_H2I_LOGOUT_REQ
,
1712 bfa_fn_lpu(lps
->bfa
));
1714 m
->fw_tag
= lps
->fw_tag
;
1715 m
->port_name
= lps
->pwwn
;
1716 bfa_reqq_produce(lps
->bfa
, lps
->reqq
, m
->mh
);
1720 * send n2n pid set request to firmware
1723 bfa_lps_send_set_n2n_pid(struct bfa_lps_s
*lps
)
1725 struct bfi_lps_n2n_pid_req_s
*m
;
1727 m
= bfa_reqq_next(lps
->bfa
, lps
->reqq
);
1730 bfi_h2i_set(m
->mh
, BFI_MC_LPS
, BFI_LPS_H2I_N2N_PID_REQ
,
1731 bfa_fn_lpu(lps
->bfa
));
1733 m
->fw_tag
= lps
->fw_tag
;
1734 m
->lp_pid
= lps
->lp_pid
;
1735 bfa_reqq_produce(lps
->bfa
, lps
->reqq
, m
->mh
);
1739 * Indirect login completion handler for non-fcs
1742 bfa_lps_login_comp_cb(void *arg
, bfa_boolean_t complete
)
1744 struct bfa_lps_s
*lps
= arg
;
1750 bfa_cb_lps_fdisc_comp(lps
->bfa
->bfad
, lps
->uarg
, lps
->status
);
1752 bfa_cb_lps_flogi_comp(lps
->bfa
->bfad
, lps
->uarg
, lps
->status
);
1756 * Login completion handler -- direct call for fcs, queue for others
1759 bfa_lps_login_comp(struct bfa_lps_s
*lps
)
1761 if (!lps
->bfa
->fcs
) {
1762 bfa_cb_queue(lps
->bfa
, &lps
->hcb_qe
, bfa_lps_login_comp_cb
,
1768 bfa_cb_lps_fdisc_comp(lps
->bfa
->bfad
, lps
->uarg
, lps
->status
);
1770 bfa_cb_lps_flogi_comp(lps
->bfa
->bfad
, lps
->uarg
, lps
->status
);
1774 * Indirect logout completion handler for non-fcs
1777 bfa_lps_logout_comp_cb(void *arg
, bfa_boolean_t complete
)
1779 struct bfa_lps_s
*lps
= arg
;
1785 bfa_cb_lps_fdisclogo_comp(lps
->bfa
->bfad
, lps
->uarg
);
1787 bfa_cb_lps_flogo_comp(lps
->bfa
->bfad
, lps
->uarg
);
1791 * Logout completion handler -- direct call for fcs, queue for others
1794 bfa_lps_logout_comp(struct bfa_lps_s
*lps
)
1796 if (!lps
->bfa
->fcs
) {
1797 bfa_cb_queue(lps
->bfa
, &lps
->hcb_qe
, bfa_lps_logout_comp_cb
,
1802 bfa_cb_lps_fdisclogo_comp(lps
->bfa
->bfad
, lps
->uarg
);
1806 * Clear virtual link completion handler for non-fcs
1809 bfa_lps_cvl_event_cb(void *arg
, bfa_boolean_t complete
)
1811 struct bfa_lps_s
*lps
= arg
;
1816 /* Clear virtual link to base port will result in link down */
1818 bfa_cb_lps_cvl_event(lps
->bfa
->bfad
, lps
->uarg
);
1822 * Received Clear virtual link event --direct call for fcs,
1826 bfa_lps_cvl_event(struct bfa_lps_s
*lps
)
1828 if (!lps
->bfa
->fcs
) {
1829 bfa_cb_queue(lps
->bfa
, &lps
->hcb_qe
, bfa_lps_cvl_event_cb
,
1834 /* Clear virtual link to base port will result in link down */
1836 bfa_cb_lps_cvl_event(lps
->bfa
->bfad
, lps
->uarg
);
1842 * lps_public BFA LPS public functions
1846 bfa_lps_get_max_vport(struct bfa_s
*bfa
)
1848 if (bfa_ioc_devid(&bfa
->ioc
) == BFA_PCI_DEVICE_ID_CT
)
1849 return BFA_LPS_MAX_VPORTS_SUPP_CT
;
1851 return BFA_LPS_MAX_VPORTS_SUPP_CB
;
1855 * Allocate a lport srvice tag.
1858 bfa_lps_alloc(struct bfa_s
*bfa
)
1860 struct bfa_lps_mod_s
*mod
= BFA_LPS_MOD(bfa
);
1861 struct bfa_lps_s
*lps
= NULL
;
1863 bfa_q_deq(&mod
->lps_free_q
, &lps
);
1868 list_add_tail(&lps
->qe
, &mod
->lps_active_q
);
1870 bfa_sm_set_state(lps
, bfa_lps_sm_init
);
1875 * Free lport service tag. This can be called anytime after an alloc.
1876 * No need to wait for any pending login/logout completions.
1879 bfa_lps_delete(struct bfa_lps_s
*lps
)
1881 bfa_sm_send_event(lps
, BFA_LPS_SM_DELETE
);
1885 * Initiate a lport login.
1888 bfa_lps_flogi(struct bfa_lps_s
*lps
, void *uarg
, u8 alpa
, u16 pdusz
,
1889 wwn_t pwwn
, wwn_t nwwn
, bfa_boolean_t auth_en
)
1896 lps
->fdisc
= BFA_FALSE
;
1897 lps
->auth_en
= auth_en
;
1898 bfa_sm_send_event(lps
, BFA_LPS_SM_LOGIN
);
1902 * Initiate a lport fdisc login.
1905 bfa_lps_fdisc(struct bfa_lps_s
*lps
, void *uarg
, u16 pdusz
, wwn_t pwwn
,
1913 lps
->fdisc
= BFA_TRUE
;
1914 lps
->auth_en
= BFA_FALSE
;
1915 bfa_sm_send_event(lps
, BFA_LPS_SM_LOGIN
);
1920 * Initiate a lport FDSIC logout.
1923 bfa_lps_fdisclogo(struct bfa_lps_s
*lps
)
1925 bfa_sm_send_event(lps
, BFA_LPS_SM_LOGOUT
);
1929 bfa_lps_get_fwtag(struct bfa_s
*bfa
, u8 lp_tag
)
1931 struct bfa_lps_mod_s
*mod
= BFA_LPS_MOD(bfa
);
1933 return BFA_LPS_FROM_TAG(mod
, lp_tag
)->fw_tag
;
1937 * Return lport services tag given the pid
1940 bfa_lps_get_tag_from_pid(struct bfa_s
*bfa
, u32 pid
)
1942 struct bfa_lps_mod_s
*mod
= BFA_LPS_MOD(bfa
);
1943 struct bfa_lps_s
*lps
;
1946 for (i
= 0, lps
= mod
->lps_arr
; i
< mod
->num_lps
; i
++, lps
++) {
1947 if (lps
->lp_pid
== pid
)
1948 return lps
->bfa_tag
;
1951 /* Return base port tag anyway */
1957 * return port id assigned to the base lport
1960 bfa_lps_get_base_pid(struct bfa_s
*bfa
)
1962 struct bfa_lps_mod_s
*mod
= BFA_LPS_MOD(bfa
);
1964 return BFA_LPS_FROM_TAG(mod
, 0)->lp_pid
;
1968 * Set PID in case of n2n (which is assigned during PLOGI)
1971 bfa_lps_set_n2n_pid(struct bfa_lps_s
*lps
, uint32_t n2n_pid
)
1973 bfa_trc(lps
->bfa
, lps
->bfa_tag
);
1974 bfa_trc(lps
->bfa
, n2n_pid
);
1976 lps
->lp_pid
= n2n_pid
;
1977 bfa_sm_send_event(lps
, BFA_LPS_SM_SET_N2N_PID
);
1981 * LPS firmware message class handler.
1984 bfa_lps_isr(struct bfa_s
*bfa
, struct bfi_msg_s
*m
)
1986 union bfi_lps_i2h_msg_u msg
;
1988 bfa_trc(bfa
, m
->mhdr
.msg_id
);
1991 switch (m
->mhdr
.msg_id
) {
1992 case BFI_LPS_I2H_LOGIN_RSP
:
1993 bfa_lps_login_rsp(bfa
, msg
.login_rsp
);
1996 case BFI_LPS_I2H_LOGOUT_RSP
:
1997 bfa_lps_logout_rsp(bfa
, msg
.logout_rsp
);
2000 case BFI_LPS_I2H_CVL_EVENT
:
2001 bfa_lps_rx_cvl_event(bfa
, msg
.cvl_event
);
2005 bfa_trc(bfa
, m
->mhdr
.msg_id
);
2011 bfa_fcport_aen_post(struct bfa_fcport_s
*fcport
, enum bfa_port_aen_event event
)
2013 struct bfad_s
*bfad
= (struct bfad_s
*)fcport
->bfa
->bfad
;
2014 struct bfa_aen_entry_s
*aen_entry
;
2016 bfad_get_aen_entry(bfad
, aen_entry
);
2020 aen_entry
->aen_data
.port
.ioc_type
= bfa_get_type(fcport
->bfa
);
2021 aen_entry
->aen_data
.port
.pwwn
= fcport
->pwwn
;
2023 /* Send the AEN notification */
2024 bfad_im_post_vendor_event(aen_entry
, bfad
, ++fcport
->bfa
->bfa_aen_seq
,
2025 BFA_AEN_CAT_PORT
, event
);
2029 * FC PORT state machine functions
2032 bfa_fcport_sm_uninit(struct bfa_fcport_s
*fcport
,
2033 enum bfa_fcport_sm_event event
)
2035 bfa_trc(fcport
->bfa
, event
);
2038 case BFA_FCPORT_SM_START
:
2040 * Start event after IOC is configured and BFA is started.
2042 fcport
->use_flash_cfg
= BFA_TRUE
;
2044 if (bfa_fcport_send_enable(fcport
)) {
2045 bfa_trc(fcport
->bfa
, BFA_TRUE
);
2046 bfa_sm_set_state(fcport
, bfa_fcport_sm_enabling
);
2048 bfa_trc(fcport
->bfa
, BFA_FALSE
);
2049 bfa_sm_set_state(fcport
,
2050 bfa_fcport_sm_enabling_qwait
);
2054 case BFA_FCPORT_SM_ENABLE
:
2056 * Port is persistently configured to be in enabled state. Do
2057 * not change state. Port enabling is done when START event is
2062 case BFA_FCPORT_SM_DISABLE
:
2064 * If a port is persistently configured to be disabled, the
2065 * first event will a port disable request.
2067 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabled
);
2070 case BFA_FCPORT_SM_HWFAIL
:
2071 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocdown
);
2075 bfa_sm_fault(fcport
->bfa
, event
);
2080 bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s
*fcport
,
2081 enum bfa_fcport_sm_event event
)
2083 char pwwn_buf
[BFA_STRING_32
];
2084 struct bfad_s
*bfad
= (struct bfad_s
*)fcport
->bfa
->bfad
;
2085 bfa_trc(fcport
->bfa
, event
);
2088 case BFA_FCPORT_SM_QRESUME
:
2089 bfa_sm_set_state(fcport
, bfa_fcport_sm_enabling
);
2090 bfa_fcport_send_enable(fcport
);
2093 case BFA_FCPORT_SM_STOP
:
2094 bfa_reqq_wcancel(&fcport
->reqq_wait
);
2095 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
2098 case BFA_FCPORT_SM_ENABLE
:
2100 * Already enable is in progress.
2104 case BFA_FCPORT_SM_DISABLE
:
2106 * Just send disable request to firmware when room becomes
2107 * available in request queue.
2109 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabled
);
2110 bfa_reqq_wcancel(&fcport
->reqq_wait
);
2111 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
2112 BFA_PL_EID_PORT_DISABLE
, 0, "Port Disable");
2113 wwn2str(pwwn_buf
, fcport
->pwwn
);
2114 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
,
2115 "Base port disabled: WWN = %s\n", pwwn_buf
);
2116 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISABLE
);
2119 case BFA_FCPORT_SM_LINKUP
:
2120 case BFA_FCPORT_SM_LINKDOWN
:
2122 * Possible to get link events when doing back-to-back
2127 case BFA_FCPORT_SM_HWFAIL
:
2128 bfa_reqq_wcancel(&fcport
->reqq_wait
);
2129 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocdown
);
2132 case BFA_FCPORT_SM_FAA_MISCONFIG
:
2133 bfa_fcport_reset_linkinfo(fcport
);
2134 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISCONNECT
);
2135 bfa_sm_set_state(fcport
, bfa_fcport_sm_faa_misconfig
);
2139 bfa_sm_fault(fcport
->bfa
, event
);
2144 bfa_fcport_sm_enabling(struct bfa_fcport_s
*fcport
,
2145 enum bfa_fcport_sm_event event
)
2147 char pwwn_buf
[BFA_STRING_32
];
2148 struct bfad_s
*bfad
= (struct bfad_s
*)fcport
->bfa
->bfad
;
2149 bfa_trc(fcport
->bfa
, event
);
2152 case BFA_FCPORT_SM_FWRSP
:
2153 case BFA_FCPORT_SM_LINKDOWN
:
2154 bfa_sm_set_state(fcport
, bfa_fcport_sm_linkdown
);
2157 case BFA_FCPORT_SM_LINKUP
:
2158 bfa_fcport_update_linkinfo(fcport
);
2159 bfa_sm_set_state(fcport
, bfa_fcport_sm_linkup
);
2161 WARN_ON(!fcport
->event_cbfn
);
2162 bfa_fcport_scn(fcport
, BFA_PORT_LINKUP
, BFA_FALSE
);
2165 case BFA_FCPORT_SM_ENABLE
:
2167 * Already being enabled.
2171 case BFA_FCPORT_SM_DISABLE
:
2172 if (bfa_fcport_send_disable(fcport
))
2173 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabling
);
2175 bfa_sm_set_state(fcport
,
2176 bfa_fcport_sm_disabling_qwait
);
2178 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
2179 BFA_PL_EID_PORT_DISABLE
, 0, "Port Disable");
2180 wwn2str(pwwn_buf
, fcport
->pwwn
);
2181 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
,
2182 "Base port disabled: WWN = %s\n", pwwn_buf
);
2183 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISABLE
);
2186 case BFA_FCPORT_SM_STOP
:
2187 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
2190 case BFA_FCPORT_SM_HWFAIL
:
2191 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocdown
);
2194 case BFA_FCPORT_SM_FAA_MISCONFIG
:
2195 bfa_fcport_reset_linkinfo(fcport
);
2196 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISCONNECT
);
2197 bfa_sm_set_state(fcport
, bfa_fcport_sm_faa_misconfig
);
2201 bfa_sm_fault(fcport
->bfa
, event
);
2206 bfa_fcport_sm_linkdown(struct bfa_fcport_s
*fcport
,
2207 enum bfa_fcport_sm_event event
)
2209 struct bfi_fcport_event_s
*pevent
= fcport
->event_arg
.i2hmsg
.event
;
2210 char pwwn_buf
[BFA_STRING_32
];
2211 struct bfad_s
*bfad
= (struct bfad_s
*)fcport
->bfa
->bfad
;
2213 bfa_trc(fcport
->bfa
, event
);
2216 case BFA_FCPORT_SM_LINKUP
:
2217 bfa_fcport_update_linkinfo(fcport
);
2218 bfa_sm_set_state(fcport
, bfa_fcport_sm_linkup
);
2219 WARN_ON(!fcport
->event_cbfn
);
2220 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
2221 BFA_PL_EID_PORT_ST_CHANGE
, 0, "Port Linkup");
2222 if (!bfa_ioc_get_fcmode(&fcport
->bfa
->ioc
)) {
2224 bfa_trc(fcport
->bfa
,
2225 pevent
->link_state
.attr
.vc_fcf
.fcf
.fipenabled
);
2226 bfa_trc(fcport
->bfa
,
2227 pevent
->link_state
.attr
.vc_fcf
.fcf
.fipfailed
);
2229 if (pevent
->link_state
.attr
.vc_fcf
.fcf
.fipfailed
)
2230 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
2231 BFA_PL_EID_FIP_FCF_DISC
, 0,
2232 "FIP FCF Discovery Failed");
2234 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
2235 BFA_PL_EID_FIP_FCF_DISC
, 0,
2236 "FIP FCF Discovered");
2239 bfa_fcport_scn(fcport
, BFA_PORT_LINKUP
, BFA_FALSE
);
2240 wwn2str(pwwn_buf
, fcport
->pwwn
);
2241 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
,
2242 "Base port online: WWN = %s\n", pwwn_buf
);
2243 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_ONLINE
);
2245 /* If QoS is enabled and it is not online, send AEN */
2246 if (fcport
->cfg
.qos_enabled
&&
2247 fcport
->qos_attr
.state
!= BFA_QOS_ONLINE
)
2248 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_QOS_NEG
);
2251 case BFA_FCPORT_SM_LINKDOWN
:
2253 * Possible to get link down event.
2257 case BFA_FCPORT_SM_ENABLE
:
2263 case BFA_FCPORT_SM_DISABLE
:
2264 if (bfa_fcport_send_disable(fcport
))
2265 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabling
);
2267 bfa_sm_set_state(fcport
,
2268 bfa_fcport_sm_disabling_qwait
);
2270 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
2271 BFA_PL_EID_PORT_DISABLE
, 0, "Port Disable");
2272 wwn2str(pwwn_buf
, fcport
->pwwn
);
2273 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
,
2274 "Base port disabled: WWN = %s\n", pwwn_buf
);
2275 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISABLE
);
2278 case BFA_FCPORT_SM_STOP
:
2279 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
2282 case BFA_FCPORT_SM_HWFAIL
:
2283 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocdown
);
2286 case BFA_FCPORT_SM_FAA_MISCONFIG
:
2287 bfa_fcport_reset_linkinfo(fcport
);
2288 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISCONNECT
);
2289 bfa_sm_set_state(fcport
, bfa_fcport_sm_faa_misconfig
);
2293 bfa_sm_fault(fcport
->bfa
, event
);
2298 bfa_fcport_sm_linkup(struct bfa_fcport_s
*fcport
,
2299 enum bfa_fcport_sm_event event
)
2301 char pwwn_buf
[BFA_STRING_32
];
2302 struct bfad_s
*bfad
= (struct bfad_s
*)fcport
->bfa
->bfad
;
2304 bfa_trc(fcport
->bfa
, event
);
2307 case BFA_FCPORT_SM_ENABLE
:
2313 case BFA_FCPORT_SM_DISABLE
:
2314 if (bfa_fcport_send_disable(fcport
))
2315 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabling
);
2317 bfa_sm_set_state(fcport
,
2318 bfa_fcport_sm_disabling_qwait
);
2320 bfa_fcport_reset_linkinfo(fcport
);
2321 bfa_fcport_scn(fcport
, BFA_PORT_LINKDOWN
, BFA_FALSE
);
2322 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
2323 BFA_PL_EID_PORT_DISABLE
, 0, "Port Disable");
2324 wwn2str(pwwn_buf
, fcport
->pwwn
);
2325 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
,
2326 "Base port offline: WWN = %s\n", pwwn_buf
);
2327 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_OFFLINE
);
2328 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
,
2329 "Base port disabled: WWN = %s\n", pwwn_buf
);
2330 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISABLE
);
2333 case BFA_FCPORT_SM_LINKDOWN
:
2334 bfa_sm_set_state(fcport
, bfa_fcport_sm_linkdown
);
2335 bfa_fcport_reset_linkinfo(fcport
);
2336 bfa_fcport_scn(fcport
, BFA_PORT_LINKDOWN
, BFA_FALSE
);
2337 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
2338 BFA_PL_EID_PORT_ST_CHANGE
, 0, "Port Linkdown");
2339 wwn2str(pwwn_buf
, fcport
->pwwn
);
2340 if (BFA_PORT_IS_DISABLED(fcport
->bfa
)) {
2341 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
,
2342 "Base port offline: WWN = %s\n", pwwn_buf
);
2343 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_OFFLINE
);
2345 BFA_LOG(KERN_ERR
, bfad
, bfa_log_level
,
2346 "Base port (WWN = %s) "
2347 "lost fabric connectivity\n", pwwn_buf
);
2348 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISCONNECT
);
2352 case BFA_FCPORT_SM_STOP
:
2353 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
2354 bfa_fcport_reset_linkinfo(fcport
);
2355 wwn2str(pwwn_buf
, fcport
->pwwn
);
2356 if (BFA_PORT_IS_DISABLED(fcport
->bfa
)) {
2357 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
,
2358 "Base port offline: WWN = %s\n", pwwn_buf
);
2359 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_OFFLINE
);
2361 BFA_LOG(KERN_ERR
, bfad
, bfa_log_level
,
2362 "Base port (WWN = %s) "
2363 "lost fabric connectivity\n", pwwn_buf
);
2364 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISCONNECT
);
2368 case BFA_FCPORT_SM_HWFAIL
:
2369 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocdown
);
2370 bfa_fcport_reset_linkinfo(fcport
);
2371 bfa_fcport_scn(fcport
, BFA_PORT_LINKDOWN
, BFA_FALSE
);
2372 wwn2str(pwwn_buf
, fcport
->pwwn
);
2373 if (BFA_PORT_IS_DISABLED(fcport
->bfa
)) {
2374 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
,
2375 "Base port offline: WWN = %s\n", pwwn_buf
);
2376 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_OFFLINE
);
2378 BFA_LOG(KERN_ERR
, bfad
, bfa_log_level
,
2379 "Base port (WWN = %s) "
2380 "lost fabric connectivity\n", pwwn_buf
);
2381 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISCONNECT
);
2385 case BFA_FCPORT_SM_FAA_MISCONFIG
:
2386 bfa_fcport_reset_linkinfo(fcport
);
2387 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISCONNECT
);
2388 bfa_sm_set_state(fcport
, bfa_fcport_sm_faa_misconfig
);
2392 bfa_sm_fault(fcport
->bfa
, event
);
2397 bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s
*fcport
,
2398 enum bfa_fcport_sm_event event
)
2400 bfa_trc(fcport
->bfa
, event
);
2403 case BFA_FCPORT_SM_QRESUME
:
2404 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabling
);
2405 bfa_fcport_send_disable(fcport
);
2408 case BFA_FCPORT_SM_STOP
:
2409 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
2410 bfa_reqq_wcancel(&fcport
->reqq_wait
);
2413 case BFA_FCPORT_SM_ENABLE
:
2414 bfa_sm_set_state(fcport
, bfa_fcport_sm_toggling_qwait
);
2417 case BFA_FCPORT_SM_DISABLE
:
2419 * Already being disabled.
2423 case BFA_FCPORT_SM_LINKUP
:
2424 case BFA_FCPORT_SM_LINKDOWN
:
2426 * Possible to get link events when doing back-to-back
2431 case BFA_FCPORT_SM_HWFAIL
:
2432 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocfail
);
2433 bfa_reqq_wcancel(&fcport
->reqq_wait
);
2436 case BFA_FCPORT_SM_FAA_MISCONFIG
:
2437 bfa_fcport_reset_linkinfo(fcport
);
2438 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISCONNECT
);
2439 bfa_sm_set_state(fcport
, bfa_fcport_sm_faa_misconfig
);
2443 bfa_sm_fault(fcport
->bfa
, event
);
2448 bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s
*fcport
,
2449 enum bfa_fcport_sm_event event
)
2451 bfa_trc(fcport
->bfa
, event
);
2454 case BFA_FCPORT_SM_QRESUME
:
2455 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabling
);
2456 bfa_fcport_send_disable(fcport
);
2457 if (bfa_fcport_send_enable(fcport
))
2458 bfa_sm_set_state(fcport
, bfa_fcport_sm_enabling
);
2460 bfa_sm_set_state(fcport
,
2461 bfa_fcport_sm_enabling_qwait
);
2464 case BFA_FCPORT_SM_STOP
:
2465 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
2466 bfa_reqq_wcancel(&fcport
->reqq_wait
);
2469 case BFA_FCPORT_SM_ENABLE
:
2472 case BFA_FCPORT_SM_DISABLE
:
2473 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabling_qwait
);
2476 case BFA_FCPORT_SM_LINKUP
:
2477 case BFA_FCPORT_SM_LINKDOWN
:
2479 * Possible to get link events when doing back-to-back
2484 case BFA_FCPORT_SM_HWFAIL
:
2485 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocfail
);
2486 bfa_reqq_wcancel(&fcport
->reqq_wait
);
2490 bfa_sm_fault(fcport
->bfa
, event
);
2495 bfa_fcport_sm_disabling(struct bfa_fcport_s
*fcport
,
2496 enum bfa_fcport_sm_event event
)
2498 char pwwn_buf
[BFA_STRING_32
];
2499 struct bfad_s
*bfad
= (struct bfad_s
*)fcport
->bfa
->bfad
;
2500 bfa_trc(fcport
->bfa
, event
);
2503 case BFA_FCPORT_SM_FWRSP
:
2504 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabled
);
2507 case BFA_FCPORT_SM_DISABLE
:
2509 * Already being disabled.
2513 case BFA_FCPORT_SM_ENABLE
:
2514 if (bfa_fcport_send_enable(fcport
))
2515 bfa_sm_set_state(fcport
, bfa_fcport_sm_enabling
);
2517 bfa_sm_set_state(fcport
,
2518 bfa_fcport_sm_enabling_qwait
);
2520 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
2521 BFA_PL_EID_PORT_ENABLE
, 0, "Port Enable");
2522 wwn2str(pwwn_buf
, fcport
->pwwn
);
2523 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
,
2524 "Base port enabled: WWN = %s\n", pwwn_buf
);
2525 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_ENABLE
);
2528 case BFA_FCPORT_SM_STOP
:
2529 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
2532 case BFA_FCPORT_SM_LINKUP
:
2533 case BFA_FCPORT_SM_LINKDOWN
:
2535 * Possible to get link events when doing back-to-back
2540 case BFA_FCPORT_SM_HWFAIL
:
2541 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocfail
);
2545 bfa_sm_fault(fcport
->bfa
, event
);
2550 bfa_fcport_sm_disabled(struct bfa_fcport_s
*fcport
,
2551 enum bfa_fcport_sm_event event
)
2553 char pwwn_buf
[BFA_STRING_32
];
2554 struct bfad_s
*bfad
= (struct bfad_s
*)fcport
->bfa
->bfad
;
2555 bfa_trc(fcport
->bfa
, event
);
2558 case BFA_FCPORT_SM_START
:
2560 * Ignore start event for a port that is disabled.
2564 case BFA_FCPORT_SM_STOP
:
2565 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
2568 case BFA_FCPORT_SM_ENABLE
:
2569 if (bfa_fcport_send_enable(fcport
))
2570 bfa_sm_set_state(fcport
, bfa_fcport_sm_enabling
);
2572 bfa_sm_set_state(fcport
,
2573 bfa_fcport_sm_enabling_qwait
);
2575 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
2576 BFA_PL_EID_PORT_ENABLE
, 0, "Port Enable");
2577 wwn2str(pwwn_buf
, fcport
->pwwn
);
2578 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
,
2579 "Base port enabled: WWN = %s\n", pwwn_buf
);
2580 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_ENABLE
);
2583 case BFA_FCPORT_SM_DISABLE
:
2589 case BFA_FCPORT_SM_HWFAIL
:
2590 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocfail
);
2593 case BFA_FCPORT_SM_DPORTENABLE
:
2594 bfa_sm_set_state(fcport
, bfa_fcport_sm_dport
);
2597 case BFA_FCPORT_SM_DDPORTENABLE
:
2598 bfa_sm_set_state(fcport
, bfa_fcport_sm_ddport
);
2602 bfa_sm_fault(fcport
->bfa
, event
);
2607 bfa_fcport_sm_stopped(struct bfa_fcport_s
*fcport
,
2608 enum bfa_fcport_sm_event event
)
2610 bfa_trc(fcport
->bfa
, event
);
2613 case BFA_FCPORT_SM_START
:
2614 if (bfa_fcport_send_enable(fcport
))
2615 bfa_sm_set_state(fcport
, bfa_fcport_sm_enabling
);
2617 bfa_sm_set_state(fcport
,
2618 bfa_fcport_sm_enabling_qwait
);
2623 * Ignore all other events.
2630 * Port is enabled. IOC is down/failed.
2633 bfa_fcport_sm_iocdown(struct bfa_fcport_s
*fcport
,
2634 enum bfa_fcport_sm_event event
)
2636 bfa_trc(fcport
->bfa
, event
);
2639 case BFA_FCPORT_SM_START
:
2640 if (bfa_fcport_send_enable(fcport
))
2641 bfa_sm_set_state(fcport
, bfa_fcport_sm_enabling
);
2643 bfa_sm_set_state(fcport
,
2644 bfa_fcport_sm_enabling_qwait
);
2649 * Ignore all events.
2656 * Port is disabled. IOC is down/failed.
2659 bfa_fcport_sm_iocfail(struct bfa_fcport_s
*fcport
,
2660 enum bfa_fcport_sm_event event
)
2662 bfa_trc(fcport
->bfa
, event
);
2665 case BFA_FCPORT_SM_START
:
2666 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabled
);
2669 case BFA_FCPORT_SM_ENABLE
:
2670 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocdown
);
2675 * Ignore all events.
2682 bfa_fcport_sm_dport(struct bfa_fcport_s
*fcport
, enum bfa_fcport_sm_event event
)
2684 bfa_trc(fcport
->bfa
, event
);
2687 case BFA_FCPORT_SM_DPORTENABLE
:
2688 case BFA_FCPORT_SM_DISABLE
:
2689 case BFA_FCPORT_SM_ENABLE
:
2690 case BFA_FCPORT_SM_START
:
2692 * Ignore event for a port that is dport
2696 case BFA_FCPORT_SM_STOP
:
2697 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
2700 case BFA_FCPORT_SM_HWFAIL
:
2701 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocfail
);
2704 case BFA_FCPORT_SM_DPORTDISABLE
:
2705 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabled
);
2709 bfa_sm_fault(fcport
->bfa
, event
);
2714 bfa_fcport_sm_ddport(struct bfa_fcport_s
*fcport
,
2715 enum bfa_fcport_sm_event event
)
2717 bfa_trc(fcport
->bfa
, event
);
2720 case BFA_FCPORT_SM_DISABLE
:
2721 case BFA_FCPORT_SM_DDPORTDISABLE
:
2722 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabled
);
2725 case BFA_FCPORT_SM_DPORTENABLE
:
2726 case BFA_FCPORT_SM_DPORTDISABLE
:
2727 case BFA_FCPORT_SM_ENABLE
:
2728 case BFA_FCPORT_SM_START
:
2730 * Ignore event for a port that is ddport
2734 case BFA_FCPORT_SM_STOP
:
2735 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
2738 case BFA_FCPORT_SM_HWFAIL
:
2739 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocfail
);
2743 bfa_sm_fault(fcport
->bfa
, event
);
2748 bfa_fcport_sm_faa_misconfig(struct bfa_fcport_s
*fcport
,
2749 enum bfa_fcport_sm_event event
)
2751 bfa_trc(fcport
->bfa
, event
);
2754 case BFA_FCPORT_SM_DPORTENABLE
:
2755 case BFA_FCPORT_SM_ENABLE
:
2756 case BFA_FCPORT_SM_START
:
2758 * Ignore event for a port as there is FAA misconfig
2762 case BFA_FCPORT_SM_DISABLE
:
2763 if (bfa_fcport_send_disable(fcport
))
2764 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabling
);
2766 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabling_qwait
);
2768 bfa_fcport_reset_linkinfo(fcport
);
2769 bfa_fcport_scn(fcport
, BFA_PORT_LINKDOWN
, BFA_FALSE
);
2770 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
2771 BFA_PL_EID_PORT_DISABLE
, 0, "Port Disable");
2772 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISABLE
);
2775 case BFA_FCPORT_SM_STOP
:
2776 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
2779 case BFA_FCPORT_SM_HWFAIL
:
2780 bfa_fcport_reset_linkinfo(fcport
);
2781 bfa_fcport_scn(fcport
, BFA_PORT_LINKDOWN
, BFA_FALSE
);
2782 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocdown
);
2786 bfa_sm_fault(fcport
->bfa
, event
);
2791 * Link state is down
2794 bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s
*ln
,
2795 enum bfa_fcport_ln_sm_event event
)
2797 bfa_trc(ln
->fcport
->bfa
, event
);
2800 case BFA_FCPORT_LN_SM_LINKUP
:
2801 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_up_nf
);
2802 bfa_fcport_queue_cb(ln
, BFA_PORT_LINKUP
);
2806 bfa_sm_fault(ln
->fcport
->bfa
, event
);
2811 * Link state is waiting for down notification
2814 bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s
*ln
,
2815 enum bfa_fcport_ln_sm_event event
)
2817 bfa_trc(ln
->fcport
->bfa
, event
);
2820 case BFA_FCPORT_LN_SM_LINKUP
:
2821 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_dn_up_nf
);
2824 case BFA_FCPORT_LN_SM_NOTIFICATION
:
2825 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_dn
);
2829 bfa_sm_fault(ln
->fcport
->bfa
, event
);
2834 * Link state is waiting for down notification and there is a pending up
2837 bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s
*ln
,
2838 enum bfa_fcport_ln_sm_event event
)
2840 bfa_trc(ln
->fcport
->bfa
, event
);
2843 case BFA_FCPORT_LN_SM_LINKDOWN
:
2844 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_dn_nf
);
2847 case BFA_FCPORT_LN_SM_NOTIFICATION
:
2848 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_up_nf
);
2849 bfa_fcport_queue_cb(ln
, BFA_PORT_LINKUP
);
2853 bfa_sm_fault(ln
->fcport
->bfa
, event
);
2861 bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s
*ln
,
2862 enum bfa_fcport_ln_sm_event event
)
2864 bfa_trc(ln
->fcport
->bfa
, event
);
2867 case BFA_FCPORT_LN_SM_LINKDOWN
:
2868 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_dn_nf
);
2869 bfa_fcport_queue_cb(ln
, BFA_PORT_LINKDOWN
);
2873 bfa_sm_fault(ln
->fcport
->bfa
, event
);
2878 * Link state is waiting for up notification
2881 bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s
*ln
,
2882 enum bfa_fcport_ln_sm_event event
)
2884 bfa_trc(ln
->fcport
->bfa
, event
);
2887 case BFA_FCPORT_LN_SM_LINKDOWN
:
2888 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_up_dn_nf
);
2891 case BFA_FCPORT_LN_SM_NOTIFICATION
:
2892 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_up
);
2896 bfa_sm_fault(ln
->fcport
->bfa
, event
);
2901 * Link state is waiting for up notification and there is a pending down
2904 bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s
*ln
,
2905 enum bfa_fcport_ln_sm_event event
)
2907 bfa_trc(ln
->fcport
->bfa
, event
);
2910 case BFA_FCPORT_LN_SM_LINKUP
:
2911 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_up_dn_up_nf
);
2914 case BFA_FCPORT_LN_SM_NOTIFICATION
:
2915 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_dn_nf
);
2916 bfa_fcport_queue_cb(ln
, BFA_PORT_LINKDOWN
);
2920 bfa_sm_fault(ln
->fcport
->bfa
, event
);
2925 * Link state is waiting for up notification and there are pending down and up
2928 bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s
*ln
,
2929 enum bfa_fcport_ln_sm_event event
)
2931 bfa_trc(ln
->fcport
->bfa
, event
);
2934 case BFA_FCPORT_LN_SM_LINKDOWN
:
2935 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_up_dn_nf
);
2938 case BFA_FCPORT_LN_SM_NOTIFICATION
:
2939 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_dn_up_nf
);
2940 bfa_fcport_queue_cb(ln
, BFA_PORT_LINKDOWN
);
2944 bfa_sm_fault(ln
->fcport
->bfa
, event
);
2949 __bfa_cb_fcport_event(void *cbarg
, bfa_boolean_t complete
)
2951 struct bfa_fcport_ln_s
*ln
= cbarg
;
2954 ln
->fcport
->event_cbfn(ln
->fcport
->event_cbarg
, ln
->ln_event
);
2956 bfa_sm_send_event(ln
, BFA_FCPORT_LN_SM_NOTIFICATION
);
2960 * Send SCN notification to upper layers.
2961 * trunk - false if caller is fcport to ignore fcport event in trunked mode
2964 bfa_fcport_scn(struct bfa_fcport_s
*fcport
, enum bfa_port_linkstate event
,
2965 bfa_boolean_t trunk
)
2967 if (fcport
->cfg
.trunked
&& !trunk
)
2971 case BFA_PORT_LINKUP
:
2972 bfa_sm_send_event(&fcport
->ln
, BFA_FCPORT_LN_SM_LINKUP
);
2974 case BFA_PORT_LINKDOWN
:
2975 bfa_sm_send_event(&fcport
->ln
, BFA_FCPORT_LN_SM_LINKDOWN
);
2983 bfa_fcport_queue_cb(struct bfa_fcport_ln_s
*ln
, enum bfa_port_linkstate event
)
2985 struct bfa_fcport_s
*fcport
= ln
->fcport
;
2987 if (fcport
->bfa
->fcs
) {
2988 fcport
->event_cbfn(fcport
->event_cbarg
, event
);
2989 bfa_sm_send_event(ln
, BFA_FCPORT_LN_SM_NOTIFICATION
);
2991 ln
->ln_event
= event
;
2992 bfa_cb_queue(fcport
->bfa
, &ln
->ln_qe
,
2993 __bfa_cb_fcport_event
, ln
);
2997 #define FCPORT_STATS_DMA_SZ (BFA_ROUNDUP(sizeof(union bfa_fcport_stats_u), \
3001 bfa_fcport_meminfo(struct bfa_iocfc_cfg_s
*cfg
, struct bfa_meminfo_s
*minfo
,
3004 struct bfa_mem_dma_s
*fcport_dma
= BFA_MEM_FCPORT_DMA(bfa
);
3006 bfa_mem_dma_setup(minfo
, fcport_dma
, FCPORT_STATS_DMA_SZ
);
3010 bfa_fcport_qresume(void *cbarg
)
3012 struct bfa_fcport_s
*fcport
= cbarg
;
3014 bfa_sm_send_event(fcport
, BFA_FCPORT_SM_QRESUME
);
3018 bfa_fcport_mem_claim(struct bfa_fcport_s
*fcport
)
3020 struct bfa_mem_dma_s
*fcport_dma
= &fcport
->fcport_dma
;
3022 fcport
->stats_kva
= bfa_mem_dma_virt(fcport_dma
);
3023 fcport
->stats_pa
= bfa_mem_dma_phys(fcport_dma
);
3024 fcport
->stats
= (union bfa_fcport_stats_u
*)
3025 bfa_mem_dma_virt(fcport_dma
);
3029 * Memory initialization.
3032 bfa_fcport_attach(struct bfa_s
*bfa
, void *bfad
, struct bfa_iocfc_cfg_s
*cfg
,
3033 struct bfa_pcidev_s
*pcidev
)
3035 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3036 struct bfa_port_cfg_s
*port_cfg
= &fcport
->cfg
;
3037 struct bfa_fcport_ln_s
*ln
= &fcport
->ln
;
3040 ln
->fcport
= fcport
;
3042 bfa_fcport_mem_claim(fcport
);
3044 bfa_sm_set_state(fcport
, bfa_fcport_sm_uninit
);
3045 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_dn
);
3048 * initialize time stamp for stats reset
3050 fcport
->stats_reset_time
= ktime_get_seconds();
3051 fcport
->stats_dma_ready
= BFA_FALSE
;
3054 * initialize and set default configuration
3056 port_cfg
->topology
= BFA_PORT_TOPOLOGY_P2P
;
3057 port_cfg
->speed
= BFA_PORT_SPEED_AUTO
;
3058 port_cfg
->trunked
= BFA_FALSE
;
3059 port_cfg
->maxfrsize
= 0;
3061 port_cfg
->trl_def_speed
= BFA_PORT_SPEED_1GBPS
;
3062 port_cfg
->qos_bw
.high
= BFA_QOS_BW_HIGH
;
3063 port_cfg
->qos_bw
.med
= BFA_QOS_BW_MED
;
3064 port_cfg
->qos_bw
.low
= BFA_QOS_BW_LOW
;
3066 fcport
->fec_state
= BFA_FEC_OFFLINE
;
3068 INIT_LIST_HEAD(&fcport
->stats_pending_q
);
3069 INIT_LIST_HEAD(&fcport
->statsclr_pending_q
);
3071 bfa_reqq_winit(&fcport
->reqq_wait
, bfa_fcport_qresume
, fcport
);
3075 bfa_fcport_start(struct bfa_s
*bfa
)
3077 bfa_sm_send_event(BFA_FCPORT_MOD(bfa
), BFA_FCPORT_SM_START
);
3081 * Called when IOC failure is detected.
3084 bfa_fcport_iocdisable(struct bfa_s
*bfa
)
3086 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3088 bfa_sm_send_event(fcport
, BFA_FCPORT_SM_HWFAIL
);
3089 bfa_trunk_iocdisable(bfa
);
3093 * Update loop info in fcport for SCN online
3096 bfa_fcport_update_loop_info(struct bfa_fcport_s
*fcport
,
3097 struct bfa_fcport_loop_info_s
*loop_info
)
3099 fcport
->myalpa
= loop_info
->myalpa
;
3100 fcport
->alpabm_valid
=
3101 loop_info
->alpabm_val
;
3102 memcpy(fcport
->alpabm
.alpa_bm
,
3103 loop_info
->alpabm
.alpa_bm
,
3104 sizeof(struct fc_alpabm_s
));
3108 bfa_fcport_update_linkinfo(struct bfa_fcport_s
*fcport
)
3110 struct bfi_fcport_event_s
*pevent
= fcport
->event_arg
.i2hmsg
.event
;
3111 struct bfa_fcport_trunk_s
*trunk
= &fcport
->trunk
;
3113 fcport
->speed
= pevent
->link_state
.speed
;
3114 fcport
->topology
= pevent
->link_state
.topology
;
3116 if (fcport
->topology
== BFA_PORT_TOPOLOGY_LOOP
) {
3117 bfa_fcport_update_loop_info(fcport
,
3118 &pevent
->link_state
.attr
.loop_info
);
3123 fcport
->qos_attr
= pevent
->link_state
.qos_attr
;
3124 fcport
->qos_vc_attr
= pevent
->link_state
.attr
.vc_fcf
.qos_vc_attr
;
3126 if (fcport
->cfg
.bb_cr_enabled
)
3127 fcport
->bbcr_attr
= pevent
->link_state
.attr
.bbcr_attr
;
3129 fcport
->fec_state
= pevent
->link_state
.fec_state
;
3132 * update trunk state if applicable
3134 if (!fcport
->cfg
.trunked
)
3135 trunk
->attr
.state
= BFA_TRUNK_DISABLED
;
3137 /* update FCoE specific */
3139 be16_to_cpu(pevent
->link_state
.attr
.vc_fcf
.fcf
.vlan
);
3141 bfa_trc(fcport
->bfa
, fcport
->speed
);
3142 bfa_trc(fcport
->bfa
, fcport
->topology
);
3146 bfa_fcport_reset_linkinfo(struct bfa_fcport_s
*fcport
)
3148 fcport
->speed
= BFA_PORT_SPEED_UNKNOWN
;
3149 fcport
->topology
= BFA_PORT_TOPOLOGY_NONE
;
3150 fcport
->fec_state
= BFA_FEC_OFFLINE
;
3154 * Send port enable message to firmware.
3156 static bfa_boolean_t
3157 bfa_fcport_send_enable(struct bfa_fcport_s
*fcport
)
3159 struct bfi_fcport_enable_req_s
*m
;
3162 * Increment message tag before queue check, so that responses to old
3163 * requests are discarded.
3168 * check for room in queue to send request now
3170 m
= bfa_reqq_next(fcport
->bfa
, BFA_REQQ_PORT
);
3172 bfa_reqq_wait(fcport
->bfa
, BFA_REQQ_PORT
,
3173 &fcport
->reqq_wait
);
3177 bfi_h2i_set(m
->mh
, BFI_MC_FCPORT
, BFI_FCPORT_H2I_ENABLE_REQ
,
3178 bfa_fn_lpu(fcport
->bfa
));
3179 m
->nwwn
= fcport
->nwwn
;
3180 m
->pwwn
= fcport
->pwwn
;
3181 m
->port_cfg
= fcport
->cfg
;
3182 m
->msgtag
= fcport
->msgtag
;
3183 m
->port_cfg
.maxfrsize
= cpu_to_be16(fcport
->cfg
.maxfrsize
);
3184 m
->use_flash_cfg
= fcport
->use_flash_cfg
;
3185 bfa_dma_be_addr_set(m
->stats_dma_addr
, fcport
->stats_pa
);
3186 bfa_trc(fcport
->bfa
, m
->stats_dma_addr
.a32
.addr_lo
);
3187 bfa_trc(fcport
->bfa
, m
->stats_dma_addr
.a32
.addr_hi
);
3190 * queue I/O message to firmware
3192 bfa_reqq_produce(fcport
->bfa
, BFA_REQQ_PORT
, m
->mh
);
3197 * Send port disable message to firmware.
3199 static bfa_boolean_t
3200 bfa_fcport_send_disable(struct bfa_fcport_s
*fcport
)
3202 struct bfi_fcport_req_s
*m
;
3205 * Increment message tag before queue check, so that responses to old
3206 * requests are discarded.
3211 * check for room in queue to send request now
3213 m
= bfa_reqq_next(fcport
->bfa
, BFA_REQQ_PORT
);
3215 bfa_reqq_wait(fcport
->bfa
, BFA_REQQ_PORT
,
3216 &fcport
->reqq_wait
);
3220 bfi_h2i_set(m
->mh
, BFI_MC_FCPORT
, BFI_FCPORT_H2I_DISABLE_REQ
,
3221 bfa_fn_lpu(fcport
->bfa
));
3222 m
->msgtag
= fcport
->msgtag
;
3225 * queue I/O message to firmware
3227 bfa_reqq_produce(fcport
->bfa
, BFA_REQQ_PORT
, m
->mh
);
3233 bfa_fcport_set_wwns(struct bfa_fcport_s
*fcport
)
3235 fcport
->pwwn
= fcport
->bfa
->ioc
.attr
->pwwn
;
3236 fcport
->nwwn
= fcport
->bfa
->ioc
.attr
->nwwn
;
3238 bfa_trc(fcport
->bfa
, fcport
->pwwn
);
3239 bfa_trc(fcport
->bfa
, fcport
->nwwn
);
3243 bfa_fcport_qos_stats_swap(struct bfa_qos_stats_s
*d
,
3244 struct bfa_qos_stats_s
*s
)
3246 u32
*dip
= (u32
*) d
;
3247 __be32
*sip
= (__be32
*) s
;
3250 /* Now swap the 32 bit fields */
3251 for (i
= 0; i
< (sizeof(struct bfa_qos_stats_s
)/sizeof(u32
)); ++i
)
3252 dip
[i
] = be32_to_cpu(sip
[i
]);
3256 bfa_fcport_fcoe_stats_swap(struct bfa_fcoe_stats_s
*d
,
3257 struct bfa_fcoe_stats_s
*s
)
3259 u32
*dip
= (u32
*) d
;
3260 __be32
*sip
= (__be32
*) s
;
3263 for (i
= 0; i
< ((sizeof(struct bfa_fcoe_stats_s
))/sizeof(u32
));
3266 dip
[i
] = be32_to_cpu(sip
[i
]);
3267 dip
[i
+ 1] = be32_to_cpu(sip
[i
+ 1]);
3269 dip
[i
] = be32_to_cpu(sip
[i
+ 1]);
3270 dip
[i
+ 1] = be32_to_cpu(sip
[i
]);
3276 __bfa_cb_fcport_stats_get(void *cbarg
, bfa_boolean_t complete
)
3278 struct bfa_fcport_s
*fcport
= (struct bfa_fcport_s
*)cbarg
;
3279 struct bfa_cb_pending_q_s
*cb
;
3280 struct list_head
*qe
, *qen
;
3281 union bfa_fcport_stats_u
*ret
;
3284 time64_t time
= ktime_get_seconds();
3286 list_for_each_safe(qe
, qen
, &fcport
->stats_pending_q
) {
3287 bfa_q_deq(&fcport
->stats_pending_q
, &qe
);
3288 cb
= (struct bfa_cb_pending_q_s
*)qe
;
3289 if (fcport
->stats_status
== BFA_STATUS_OK
) {
3290 ret
= (union bfa_fcport_stats_u
*)cb
->data
;
3291 /* Swap FC QoS or FCoE stats */
3292 if (bfa_ioc_get_fcmode(&fcport
->bfa
->ioc
))
3293 bfa_fcport_qos_stats_swap(&ret
->fcqos
,
3294 &fcport
->stats
->fcqos
);
3296 bfa_fcport_fcoe_stats_swap(&ret
->fcoe
,
3297 &fcport
->stats
->fcoe
);
3298 ret
->fcoe
.secs_reset
=
3299 time
- fcport
->stats_reset_time
;
3302 bfa_cb_queue_status(fcport
->bfa
, &cb
->hcb_qe
,
3303 fcport
->stats_status
);
3305 fcport
->stats_status
= BFA_STATUS_OK
;
3307 INIT_LIST_HEAD(&fcport
->stats_pending_q
);
3308 fcport
->stats_status
= BFA_STATUS_OK
;
3313 bfa_fcport_stats_get_timeout(void *cbarg
)
3315 struct bfa_fcport_s
*fcport
= (struct bfa_fcport_s
*) cbarg
;
3317 bfa_trc(fcport
->bfa
, fcport
->stats_qfull
);
3319 if (fcport
->stats_qfull
) {
3320 bfa_reqq_wcancel(&fcport
->stats_reqq_wait
);
3321 fcport
->stats_qfull
= BFA_FALSE
;
3324 fcport
->stats_status
= BFA_STATUS_ETIMER
;
3325 __bfa_cb_fcport_stats_get(fcport
, BFA_TRUE
);
3329 bfa_fcport_send_stats_get(void *cbarg
)
3331 struct bfa_fcport_s
*fcport
= (struct bfa_fcport_s
*) cbarg
;
3332 struct bfi_fcport_req_s
*msg
;
3334 msg
= bfa_reqq_next(fcport
->bfa
, BFA_REQQ_PORT
);
3337 fcport
->stats_qfull
= BFA_TRUE
;
3338 bfa_reqq_winit(&fcport
->stats_reqq_wait
,
3339 bfa_fcport_send_stats_get
, fcport
);
3340 bfa_reqq_wait(fcport
->bfa
, BFA_REQQ_PORT
,
3341 &fcport
->stats_reqq_wait
);
3344 fcport
->stats_qfull
= BFA_FALSE
;
3346 memset(msg
, 0, sizeof(struct bfi_fcport_req_s
));
3347 bfi_h2i_set(msg
->mh
, BFI_MC_FCPORT
, BFI_FCPORT_H2I_STATS_GET_REQ
,
3348 bfa_fn_lpu(fcport
->bfa
));
3349 bfa_reqq_produce(fcport
->bfa
, BFA_REQQ_PORT
, msg
->mh
);
3353 __bfa_cb_fcport_stats_clr(void *cbarg
, bfa_boolean_t complete
)
3355 struct bfa_fcport_s
*fcport
= (struct bfa_fcport_s
*) cbarg
;
3356 struct bfa_cb_pending_q_s
*cb
;
3357 struct list_head
*qe
, *qen
;
3361 * re-initialize time stamp for stats reset
3363 fcport
->stats_reset_time
= ktime_get_seconds();
3364 list_for_each_safe(qe
, qen
, &fcport
->statsclr_pending_q
) {
3365 bfa_q_deq(&fcport
->statsclr_pending_q
, &qe
);
3366 cb
= (struct bfa_cb_pending_q_s
*)qe
;
3367 bfa_cb_queue_status(fcport
->bfa
, &cb
->hcb_qe
,
3368 fcport
->stats_status
);
3370 fcport
->stats_status
= BFA_STATUS_OK
;
3372 INIT_LIST_HEAD(&fcport
->statsclr_pending_q
);
3373 fcport
->stats_status
= BFA_STATUS_OK
;
3378 bfa_fcport_stats_clr_timeout(void *cbarg
)
3380 struct bfa_fcport_s
*fcport
= (struct bfa_fcport_s
*) cbarg
;
3382 bfa_trc(fcport
->bfa
, fcport
->stats_qfull
);
3384 if (fcport
->stats_qfull
) {
3385 bfa_reqq_wcancel(&fcport
->stats_reqq_wait
);
3386 fcport
->stats_qfull
= BFA_FALSE
;
3389 fcport
->stats_status
= BFA_STATUS_ETIMER
;
3390 __bfa_cb_fcport_stats_clr(fcport
, BFA_TRUE
);
3394 bfa_fcport_send_stats_clear(void *cbarg
)
3396 struct bfa_fcport_s
*fcport
= (struct bfa_fcport_s
*) cbarg
;
3397 struct bfi_fcport_req_s
*msg
;
3399 msg
= bfa_reqq_next(fcport
->bfa
, BFA_REQQ_PORT
);
3402 fcport
->stats_qfull
= BFA_TRUE
;
3403 bfa_reqq_winit(&fcport
->stats_reqq_wait
,
3404 bfa_fcport_send_stats_clear
, fcport
);
3405 bfa_reqq_wait(fcport
->bfa
, BFA_REQQ_PORT
,
3406 &fcport
->stats_reqq_wait
);
3409 fcport
->stats_qfull
= BFA_FALSE
;
3411 memset(msg
, 0, sizeof(struct bfi_fcport_req_s
));
3412 bfi_h2i_set(msg
->mh
, BFI_MC_FCPORT
, BFI_FCPORT_H2I_STATS_CLEAR_REQ
,
3413 bfa_fn_lpu(fcport
->bfa
));
3414 bfa_reqq_produce(fcport
->bfa
, BFA_REQQ_PORT
, msg
->mh
);
3418 * Handle trunk SCN event from firmware.
3421 bfa_trunk_scn(struct bfa_fcport_s
*fcport
, struct bfi_fcport_trunk_scn_s
*scn
)
3423 struct bfa_fcport_trunk_s
*trunk
= &fcport
->trunk
;
3424 struct bfi_fcport_trunk_link_s
*tlink
;
3425 struct bfa_trunk_link_attr_s
*lattr
;
3426 enum bfa_trunk_state state_prev
;
3430 bfa_trc(fcport
->bfa
, fcport
->cfg
.trunked
);
3431 WARN_ON(scn
->trunk_state
!= BFA_TRUNK_ONLINE
&&
3432 scn
->trunk_state
!= BFA_TRUNK_OFFLINE
);
3434 bfa_trc(fcport
->bfa
, trunk
->attr
.state
);
3435 bfa_trc(fcport
->bfa
, scn
->trunk_state
);
3436 bfa_trc(fcport
->bfa
, scn
->trunk_speed
);
3439 * Save off new state for trunk attribute query
3441 state_prev
= trunk
->attr
.state
;
3442 if (fcport
->cfg
.trunked
&& (trunk
->attr
.state
!= BFA_TRUNK_DISABLED
))
3443 trunk
->attr
.state
= scn
->trunk_state
;
3444 trunk
->attr
.speed
= scn
->trunk_speed
;
3445 for (i
= 0; i
< BFA_TRUNK_MAX_PORTS
; i
++) {
3446 lattr
= &trunk
->attr
.link_attr
[i
];
3447 tlink
= &scn
->tlink
[i
];
3449 lattr
->link_state
= tlink
->state
;
3450 lattr
->trunk_wwn
= tlink
->trunk_wwn
;
3451 lattr
->fctl
= tlink
->fctl
;
3452 lattr
->speed
= tlink
->speed
;
3453 lattr
->deskew
= be32_to_cpu(tlink
->deskew
);
3455 if (tlink
->state
== BFA_TRUNK_LINK_STATE_UP
) {
3456 fcport
->speed
= tlink
->speed
;
3457 fcport
->topology
= BFA_PORT_TOPOLOGY_P2P
;
3461 bfa_trc(fcport
->bfa
, lattr
->link_state
);
3462 bfa_trc(fcport
->bfa
, lattr
->trunk_wwn
);
3463 bfa_trc(fcport
->bfa
, lattr
->fctl
);
3464 bfa_trc(fcport
->bfa
, lattr
->speed
);
3465 bfa_trc(fcport
->bfa
, lattr
->deskew
);
3470 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
3471 BFA_PL_EID_TRUNK_SCN
, 0, "Trunk up(0,1)");
3474 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
3475 BFA_PL_EID_TRUNK_SCN
, 0, "Trunk up(-,1)");
3478 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
3479 BFA_PL_EID_TRUNK_SCN
, 0, "Trunk up(0,-)");
3482 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
3483 BFA_PL_EID_TRUNK_SCN
, 0, "Trunk down");
3487 * Notify upper layers if trunk state changed.
3489 if ((state_prev
!= trunk
->attr
.state
) ||
3490 (scn
->trunk_state
== BFA_TRUNK_OFFLINE
)) {
3491 bfa_fcport_scn(fcport
, (scn
->trunk_state
== BFA_TRUNK_ONLINE
) ?
3492 BFA_PORT_LINKUP
: BFA_PORT_LINKDOWN
, BFA_TRUE
);
3497 bfa_trunk_iocdisable(struct bfa_s
*bfa
)
3499 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3503 * In trunked mode, notify upper layers that link is down
3505 if (fcport
->cfg
.trunked
) {
3506 if (fcport
->trunk
.attr
.state
== BFA_TRUNK_ONLINE
)
3507 bfa_fcport_scn(fcport
, BFA_PORT_LINKDOWN
, BFA_TRUE
);
3509 fcport
->trunk
.attr
.state
= BFA_TRUNK_OFFLINE
;
3510 fcport
->trunk
.attr
.speed
= BFA_PORT_SPEED_UNKNOWN
;
3511 for (i
= 0; i
< BFA_TRUNK_MAX_PORTS
; i
++) {
3512 fcport
->trunk
.attr
.link_attr
[i
].trunk_wwn
= 0;
3513 fcport
->trunk
.attr
.link_attr
[i
].fctl
=
3514 BFA_TRUNK_LINK_FCTL_NORMAL
;
3515 fcport
->trunk
.attr
.link_attr
[i
].link_state
=
3516 BFA_TRUNK_LINK_STATE_DN_LINKDN
;
3517 fcport
->trunk
.attr
.link_attr
[i
].speed
=
3518 BFA_PORT_SPEED_UNKNOWN
;
3519 fcport
->trunk
.attr
.link_attr
[i
].deskew
= 0;
3525 * Called to initialize port attributes
3528 bfa_fcport_init(struct bfa_s
*bfa
)
3530 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3533 * Initialize port attributes from IOC hardware data.
3535 bfa_fcport_set_wwns(fcport
);
3536 if (fcport
->cfg
.maxfrsize
== 0)
3537 fcport
->cfg
.maxfrsize
= bfa_ioc_maxfrsize(&bfa
->ioc
);
3538 fcport
->cfg
.rx_bbcredit
= bfa_ioc_rx_bbcredit(&bfa
->ioc
);
3539 fcport
->speed_sup
= bfa_ioc_speed_sup(&bfa
->ioc
);
3541 if (bfa_fcport_is_pbcdisabled(bfa
))
3542 bfa
->modules
.port
.pbc_disabled
= BFA_TRUE
;
3544 WARN_ON(!fcport
->cfg
.maxfrsize
);
3545 WARN_ON(!fcport
->cfg
.rx_bbcredit
);
3546 WARN_ON(!fcport
->speed_sup
);
3550 * Firmware message handler.
3553 bfa_fcport_isr(struct bfa_s
*bfa
, struct bfi_msg_s
*msg
)
3555 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3556 union bfi_fcport_i2h_msg_u i2hmsg
;
3559 fcport
->event_arg
.i2hmsg
= i2hmsg
;
3561 bfa_trc(bfa
, msg
->mhdr
.msg_id
);
3562 bfa_trc(bfa
, bfa_sm_to_state(hal_port_sm_table
, fcport
->sm
));
3564 switch (msg
->mhdr
.msg_id
) {
3565 case BFI_FCPORT_I2H_ENABLE_RSP
:
3566 if (fcport
->msgtag
== i2hmsg
.penable_rsp
->msgtag
) {
3568 fcport
->stats_dma_ready
= BFA_TRUE
;
3569 if (fcport
->use_flash_cfg
) {
3570 fcport
->cfg
= i2hmsg
.penable_rsp
->port_cfg
;
3571 fcport
->cfg
.maxfrsize
=
3572 cpu_to_be16(fcport
->cfg
.maxfrsize
);
3573 fcport
->cfg
.path_tov
=
3574 cpu_to_be16(fcport
->cfg
.path_tov
);
3575 fcport
->cfg
.q_depth
=
3576 cpu_to_be16(fcport
->cfg
.q_depth
);
3578 if (fcport
->cfg
.trunked
)
3579 fcport
->trunk
.attr
.state
=
3582 fcport
->trunk
.attr
.state
=
3584 fcport
->qos_attr
.qos_bw
=
3585 i2hmsg
.penable_rsp
->port_cfg
.qos_bw
;
3586 fcport
->use_flash_cfg
= BFA_FALSE
;
3589 if (fcport
->cfg
.qos_enabled
)
3590 fcport
->qos_attr
.state
= BFA_QOS_OFFLINE
;
3592 fcport
->qos_attr
.state
= BFA_QOS_DISABLED
;
3594 fcport
->qos_attr
.qos_bw_op
=
3595 i2hmsg
.penable_rsp
->port_cfg
.qos_bw
;
3597 if (fcport
->cfg
.bb_cr_enabled
)
3598 fcport
->bbcr_attr
.state
= BFA_BBCR_OFFLINE
;
3600 fcport
->bbcr_attr
.state
= BFA_BBCR_DISABLED
;
3602 bfa_sm_send_event(fcport
, BFA_FCPORT_SM_FWRSP
);
3606 case BFI_FCPORT_I2H_DISABLE_RSP
:
3607 if (fcport
->msgtag
== i2hmsg
.penable_rsp
->msgtag
)
3608 bfa_sm_send_event(fcport
, BFA_FCPORT_SM_FWRSP
);
3611 case BFI_FCPORT_I2H_EVENT
:
3612 if (fcport
->cfg
.bb_cr_enabled
)
3613 fcport
->bbcr_attr
.state
= BFA_BBCR_OFFLINE
;
3615 fcport
->bbcr_attr
.state
= BFA_BBCR_DISABLED
;
3617 if (i2hmsg
.event
->link_state
.linkstate
== BFA_PORT_LINKUP
)
3618 bfa_sm_send_event(fcport
, BFA_FCPORT_SM_LINKUP
);
3620 if (i2hmsg
.event
->link_state
.linkstate_rsn
==
3621 BFA_PORT_LINKSTATE_RSN_FAA_MISCONFIG
)
3622 bfa_sm_send_event(fcport
,
3623 BFA_FCPORT_SM_FAA_MISCONFIG
);
3625 bfa_sm_send_event(fcport
,
3626 BFA_FCPORT_SM_LINKDOWN
);
3628 fcport
->qos_attr
.qos_bw_op
=
3629 i2hmsg
.event
->link_state
.qos_attr
.qos_bw_op
;
3632 case BFI_FCPORT_I2H_TRUNK_SCN
:
3633 bfa_trunk_scn(fcport
, i2hmsg
.trunk_scn
);
3636 case BFI_FCPORT_I2H_STATS_GET_RSP
:
3638 * check for timer pop before processing the rsp
3640 if (list_empty(&fcport
->stats_pending_q
) ||
3641 (fcport
->stats_status
== BFA_STATUS_ETIMER
))
3644 bfa_timer_stop(&fcport
->timer
);
3645 fcport
->stats_status
= i2hmsg
.pstatsget_rsp
->status
;
3646 __bfa_cb_fcport_stats_get(fcport
, BFA_TRUE
);
3649 case BFI_FCPORT_I2H_STATS_CLEAR_RSP
:
3651 * check for timer pop before processing the rsp
3653 if (list_empty(&fcport
->statsclr_pending_q
) ||
3654 (fcport
->stats_status
== BFA_STATUS_ETIMER
))
3657 bfa_timer_stop(&fcport
->timer
);
3658 fcport
->stats_status
= BFA_STATUS_OK
;
3659 __bfa_cb_fcport_stats_clr(fcport
, BFA_TRUE
);
3662 case BFI_FCPORT_I2H_ENABLE_AEN
:
3663 bfa_sm_send_event(fcport
, BFA_FCPORT_SM_ENABLE
);
3666 case BFI_FCPORT_I2H_DISABLE_AEN
:
3667 bfa_sm_send_event(fcport
, BFA_FCPORT_SM_DISABLE
);
3677 * Registered callback for port events.
3680 bfa_fcport_event_register(struct bfa_s
*bfa
,
3681 void (*cbfn
) (void *cbarg
,
3682 enum bfa_port_linkstate event
),
3685 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3687 fcport
->event_cbfn
= cbfn
;
3688 fcport
->event_cbarg
= cbarg
;
3692 bfa_fcport_enable(struct bfa_s
*bfa
)
3694 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3696 if (bfa_fcport_is_pbcdisabled(bfa
))
3697 return BFA_STATUS_PBC
;
3699 if (bfa_ioc_is_disabled(&bfa
->ioc
))
3700 return BFA_STATUS_IOC_DISABLED
;
3702 if (fcport
->diag_busy
)
3703 return BFA_STATUS_DIAG_BUSY
;
3705 bfa_sm_send_event(BFA_FCPORT_MOD(bfa
), BFA_FCPORT_SM_ENABLE
);
3706 return BFA_STATUS_OK
;
3710 bfa_fcport_disable(struct bfa_s
*bfa
)
3712 if (bfa_fcport_is_pbcdisabled(bfa
))
3713 return BFA_STATUS_PBC
;
3715 if (bfa_ioc_is_disabled(&bfa
->ioc
))
3716 return BFA_STATUS_IOC_DISABLED
;
3718 bfa_sm_send_event(BFA_FCPORT_MOD(bfa
), BFA_FCPORT_SM_DISABLE
);
3719 return BFA_STATUS_OK
;
3722 /* If PBC is disabled on port, return error */
3724 bfa_fcport_is_pbcdisabled(struct bfa_s
*bfa
)
3726 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3727 struct bfa_iocfc_s
*iocfc
= &bfa
->iocfc
;
3728 struct bfi_iocfc_cfgrsp_s
*cfgrsp
= iocfc
->cfgrsp
;
3730 if (cfgrsp
->pbc_cfg
.port_enabled
== BFI_PBC_PORT_DISABLED
) {
3731 bfa_trc(bfa
, fcport
->pwwn
);
3732 return BFA_STATUS_PBC
;
3734 return BFA_STATUS_OK
;
3738 * Configure port speed.
3741 bfa_fcport_cfg_speed(struct bfa_s
*bfa
, enum bfa_port_speed speed
)
3743 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3745 bfa_trc(bfa
, speed
);
3747 if (fcport
->cfg
.trunked
== BFA_TRUE
)
3748 return BFA_STATUS_TRUNK_ENABLED
;
3749 if ((fcport
->cfg
.topology
== BFA_PORT_TOPOLOGY_LOOP
) &&
3750 (speed
== BFA_PORT_SPEED_16GBPS
))
3751 return BFA_STATUS_UNSUPP_SPEED
;
3752 if ((speed
!= BFA_PORT_SPEED_AUTO
) && (speed
> fcport
->speed_sup
)) {
3753 bfa_trc(bfa
, fcport
->speed_sup
);
3754 return BFA_STATUS_UNSUPP_SPEED
;
3757 /* Port speed entered needs to be checked */
3758 if (bfa_ioc_get_type(&fcport
->bfa
->ioc
) == BFA_IOC_TYPE_FC
) {
3759 /* For CT2, 1G is not supported */
3760 if ((speed
== BFA_PORT_SPEED_1GBPS
) &&
3761 (bfa_asic_id_ct2(bfa
->ioc
.pcidev
.device_id
)))
3762 return BFA_STATUS_UNSUPP_SPEED
;
3764 /* Already checked for Auto Speed and Max Speed supp */
3765 if (!(speed
== BFA_PORT_SPEED_1GBPS
||
3766 speed
== BFA_PORT_SPEED_2GBPS
||
3767 speed
== BFA_PORT_SPEED_4GBPS
||
3768 speed
== BFA_PORT_SPEED_8GBPS
||
3769 speed
== BFA_PORT_SPEED_16GBPS
||
3770 speed
== BFA_PORT_SPEED_AUTO
))
3771 return BFA_STATUS_UNSUPP_SPEED
;
3773 if (speed
!= BFA_PORT_SPEED_10GBPS
)
3774 return BFA_STATUS_UNSUPP_SPEED
;
3777 fcport
->cfg
.speed
= speed
;
3779 return BFA_STATUS_OK
;
3783 * Get current speed.
3786 bfa_fcport_get_speed(struct bfa_s
*bfa
)
3788 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3790 return fcport
->speed
;
3794 * Configure port topology.
3797 bfa_fcport_cfg_topology(struct bfa_s
*bfa
, enum bfa_port_topology topology
)
3799 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3801 bfa_trc(bfa
, topology
);
3802 bfa_trc(bfa
, fcport
->cfg
.topology
);
3805 case BFA_PORT_TOPOLOGY_P2P
:
3808 case BFA_PORT_TOPOLOGY_LOOP
:
3809 if ((bfa_fcport_is_qos_enabled(bfa
) != BFA_FALSE
) ||
3810 (fcport
->qos_attr
.state
!= BFA_QOS_DISABLED
))
3811 return BFA_STATUS_ERROR_QOS_ENABLED
;
3812 if (fcport
->cfg
.ratelimit
!= BFA_FALSE
)
3813 return BFA_STATUS_ERROR_TRL_ENABLED
;
3814 if ((bfa_fcport_is_trunk_enabled(bfa
) != BFA_FALSE
) ||
3815 (fcport
->trunk
.attr
.state
!= BFA_TRUNK_DISABLED
))
3816 return BFA_STATUS_ERROR_TRUNK_ENABLED
;
3817 if ((bfa_fcport_get_speed(bfa
) == BFA_PORT_SPEED_16GBPS
) ||
3818 (fcport
->cfg
.speed
== BFA_PORT_SPEED_16GBPS
))
3819 return BFA_STATUS_UNSUPP_SPEED
;
3820 if (bfa_mfg_is_mezz(bfa
->ioc
.attr
->card_type
))
3821 return BFA_STATUS_LOOP_UNSUPP_MEZZ
;
3822 if (bfa_fcport_is_dport(bfa
) != BFA_FALSE
)
3823 return BFA_STATUS_DPORT_ERR
;
3824 if (bfa_fcport_is_ddport(bfa
) != BFA_FALSE
)
3825 return BFA_STATUS_DPORT_ERR
;
3828 case BFA_PORT_TOPOLOGY_AUTO
:
3832 return BFA_STATUS_EINVAL
;
3835 fcport
->cfg
.topology
= topology
;
3836 return BFA_STATUS_OK
;
3840 * Get current topology.
3842 enum bfa_port_topology
3843 bfa_fcport_get_topology(struct bfa_s
*bfa
)
3845 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3847 return fcport
->topology
;
3851 * Get config topology.
3853 enum bfa_port_topology
3854 bfa_fcport_get_cfg_topology(struct bfa_s
*bfa
)
3856 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3858 return fcport
->cfg
.topology
;
3862 bfa_fcport_cfg_hardalpa(struct bfa_s
*bfa
, u8 alpa
)
3864 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3867 bfa_trc(bfa
, fcport
->cfg
.cfg_hardalpa
);
3868 bfa_trc(bfa
, fcport
->cfg
.hardalpa
);
3870 fcport
->cfg
.cfg_hardalpa
= BFA_TRUE
;
3871 fcport
->cfg
.hardalpa
= alpa
;
3873 return BFA_STATUS_OK
;
3877 bfa_fcport_clr_hardalpa(struct bfa_s
*bfa
)
3879 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3881 bfa_trc(bfa
, fcport
->cfg
.cfg_hardalpa
);
3882 bfa_trc(bfa
, fcport
->cfg
.hardalpa
);
3884 fcport
->cfg
.cfg_hardalpa
= BFA_FALSE
;
3885 return BFA_STATUS_OK
;
3889 bfa_fcport_get_hardalpa(struct bfa_s
*bfa
, u8
*alpa
)
3891 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3893 *alpa
= fcport
->cfg
.hardalpa
;
3894 return fcport
->cfg
.cfg_hardalpa
;
3898 bfa_fcport_get_myalpa(struct bfa_s
*bfa
)
3900 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3902 return fcport
->myalpa
;
3906 bfa_fcport_cfg_maxfrsize(struct bfa_s
*bfa
, u16 maxfrsize
)
3908 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3910 bfa_trc(bfa
, maxfrsize
);
3911 bfa_trc(bfa
, fcport
->cfg
.maxfrsize
);
3914 if ((maxfrsize
> FC_MAX_PDUSZ
) || (maxfrsize
< FC_MIN_PDUSZ
))
3915 return BFA_STATUS_INVLD_DFSZ
;
3917 /* power of 2, if not the max frame size of 2112 */
3918 if ((maxfrsize
!= FC_MAX_PDUSZ
) && (maxfrsize
& (maxfrsize
- 1)))
3919 return BFA_STATUS_INVLD_DFSZ
;
3921 fcport
->cfg
.maxfrsize
= maxfrsize
;
3922 return BFA_STATUS_OK
;
3926 bfa_fcport_get_maxfrsize(struct bfa_s
*bfa
)
3928 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3930 return fcport
->cfg
.maxfrsize
;
3934 bfa_fcport_get_rx_bbcredit(struct bfa_s
*bfa
)
3936 if (bfa_fcport_get_topology(bfa
) != BFA_PORT_TOPOLOGY_LOOP
)
3937 return (BFA_FCPORT_MOD(bfa
))->cfg
.rx_bbcredit
;
3944 bfa_fcport_set_tx_bbcredit(struct bfa_s
*bfa
, u16 tx_bbcredit
)
3946 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3948 fcport
->cfg
.tx_bbcredit
= (u8
)tx_bbcredit
;
3952 * Get port attributes.
3956 bfa_fcport_get_wwn(struct bfa_s
*bfa
, bfa_boolean_t node
)
3958 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3960 return fcport
->nwwn
;
3962 return fcport
->pwwn
;
3966 bfa_fcport_get_attr(struct bfa_s
*bfa
, struct bfa_port_attr_s
*attr
)
3968 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3970 memset(attr
, 0, sizeof(struct bfa_port_attr_s
));
3972 attr
->nwwn
= fcport
->nwwn
;
3973 attr
->pwwn
= fcport
->pwwn
;
3975 attr
->factorypwwn
= bfa
->ioc
.attr
->mfg_pwwn
;
3976 attr
->factorynwwn
= bfa
->ioc
.attr
->mfg_nwwn
;
3978 memcpy(&attr
->pport_cfg
, &fcport
->cfg
,
3979 sizeof(struct bfa_port_cfg_s
));
3980 /* speed attributes */
3981 attr
->pport_cfg
.speed
= fcport
->cfg
.speed
;
3982 attr
->speed_supported
= fcport
->speed_sup
;
3983 attr
->speed
= fcport
->speed
;
3984 attr
->cos_supported
= FC_CLASS_3
;
3986 /* topology attributes */
3987 attr
->pport_cfg
.topology
= fcport
->cfg
.topology
;
3988 attr
->topology
= fcport
->topology
;
3989 attr
->pport_cfg
.trunked
= fcport
->cfg
.trunked
;
3991 /* beacon attributes */
3992 attr
->beacon
= fcport
->beacon
;
3993 attr
->link_e2e_beacon
= fcport
->link_e2e_beacon
;
3995 attr
->pport_cfg
.path_tov
= bfa_fcpim_path_tov_get(bfa
);
3996 attr
->pport_cfg
.q_depth
= bfa_fcpim_qdepth_get(bfa
);
3997 attr
->port_state
= bfa_sm_to_state(hal_port_sm_table
, fcport
->sm
);
3999 attr
->fec_state
= fcport
->fec_state
;
4001 /* PBC Disabled State */
4002 if (bfa_fcport_is_pbcdisabled(bfa
))
4003 attr
->port_state
= BFA_PORT_ST_PREBOOT_DISABLED
;
4005 if (bfa_ioc_is_disabled(&fcport
->bfa
->ioc
))
4006 attr
->port_state
= BFA_PORT_ST_IOCDIS
;
4007 else if (bfa_ioc_fw_mismatch(&fcport
->bfa
->ioc
))
4008 attr
->port_state
= BFA_PORT_ST_FWMISMATCH
;
4012 attr
->fcoe_vlan
= fcport
->fcoe_vlan
;
4015 #define BFA_FCPORT_STATS_TOV 1000
4018 * Fetch port statistics (FCQoS or FCoE).
4021 bfa_fcport_get_stats(struct bfa_s
*bfa
, struct bfa_cb_pending_q_s
*cb
)
4023 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4025 if (!bfa_iocfc_is_operational(bfa
) ||
4026 !fcport
->stats_dma_ready
)
4027 return BFA_STATUS_IOC_NON_OP
;
4029 if (!list_empty(&fcport
->statsclr_pending_q
))
4030 return BFA_STATUS_DEVBUSY
;
4032 if (list_empty(&fcport
->stats_pending_q
)) {
4033 list_add_tail(&cb
->hcb_qe
.qe
, &fcport
->stats_pending_q
);
4034 bfa_fcport_send_stats_get(fcport
);
4035 bfa_timer_start(bfa
, &fcport
->timer
,
4036 bfa_fcport_stats_get_timeout
,
4037 fcport
, BFA_FCPORT_STATS_TOV
);
4039 list_add_tail(&cb
->hcb_qe
.qe
, &fcport
->stats_pending_q
);
4041 return BFA_STATUS_OK
;
4045 * Reset port statistics (FCQoS or FCoE).
4048 bfa_fcport_clear_stats(struct bfa_s
*bfa
, struct bfa_cb_pending_q_s
*cb
)
4050 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4052 if (!bfa_iocfc_is_operational(bfa
) ||
4053 !fcport
->stats_dma_ready
)
4054 return BFA_STATUS_IOC_NON_OP
;
4056 if (!list_empty(&fcport
->stats_pending_q
))
4057 return BFA_STATUS_DEVBUSY
;
4059 if (list_empty(&fcport
->statsclr_pending_q
)) {
4060 list_add_tail(&cb
->hcb_qe
.qe
, &fcport
->statsclr_pending_q
);
4061 bfa_fcport_send_stats_clear(fcport
);
4062 bfa_timer_start(bfa
, &fcport
->timer
,
4063 bfa_fcport_stats_clr_timeout
,
4064 fcport
, BFA_FCPORT_STATS_TOV
);
4066 list_add_tail(&cb
->hcb_qe
.qe
, &fcport
->statsclr_pending_q
);
4068 return BFA_STATUS_OK
;
4072 * Fetch port attributes.
4075 bfa_fcport_is_disabled(struct bfa_s
*bfa
)
4077 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4079 return bfa_sm_to_state(hal_port_sm_table
, fcport
->sm
) ==
4080 BFA_PORT_ST_DISABLED
;
4085 bfa_fcport_is_dport(struct bfa_s
*bfa
)
4087 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4089 return (bfa_sm_to_state(hal_port_sm_table
, fcport
->sm
) ==
4094 bfa_fcport_is_ddport(struct bfa_s
*bfa
)
4096 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4098 return (bfa_sm_to_state(hal_port_sm_table
, fcport
->sm
) ==
4099 BFA_PORT_ST_DDPORT
);
4103 bfa_fcport_set_qos_bw(struct bfa_s
*bfa
, struct bfa_qos_bw_s
*qos_bw
)
4105 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4106 enum bfa_ioc_type_e ioc_type
= bfa_get_type(bfa
);
4108 bfa_trc(bfa
, ioc_type
);
4110 if ((qos_bw
->high
== 0) || (qos_bw
->med
== 0) || (qos_bw
->low
== 0))
4111 return BFA_STATUS_QOS_BW_INVALID
;
4113 if ((qos_bw
->high
+ qos_bw
->med
+ qos_bw
->low
) != 100)
4114 return BFA_STATUS_QOS_BW_INVALID
;
4116 if ((qos_bw
->med
> qos_bw
->high
) || (qos_bw
->low
> qos_bw
->med
) ||
4117 (qos_bw
->low
> qos_bw
->high
))
4118 return BFA_STATUS_QOS_BW_INVALID
;
4120 if ((ioc_type
== BFA_IOC_TYPE_FC
) &&
4121 (fcport
->cfg
.topology
!= BFA_PORT_TOPOLOGY_LOOP
))
4122 fcport
->cfg
.qos_bw
= *qos_bw
;
4124 return BFA_STATUS_OK
;
4128 bfa_fcport_is_ratelim(struct bfa_s
*bfa
)
4130 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4132 return fcport
->cfg
.ratelimit
? BFA_TRUE
: BFA_FALSE
;
4137 * Enable/Disable FAA feature in port config
4140 bfa_fcport_cfg_faa(struct bfa_s
*bfa
, u8 state
)
4142 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4144 bfa_trc(bfa
, state
);
4145 fcport
->cfg
.faa_state
= state
;
4149 * Get default minimum ratelim speed
4152 bfa_fcport_get_ratelim_speed(struct bfa_s
*bfa
)
4154 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4156 bfa_trc(bfa
, fcport
->cfg
.trl_def_speed
);
4157 return fcport
->cfg
.trl_def_speed
;
4162 bfa_fcport_beacon(void *dev
, bfa_boolean_t beacon
,
4163 bfa_boolean_t link_e2e_beacon
)
4165 struct bfa_s
*bfa
= dev
;
4166 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4168 bfa_trc(bfa
, beacon
);
4169 bfa_trc(bfa
, link_e2e_beacon
);
4170 bfa_trc(bfa
, fcport
->beacon
);
4171 bfa_trc(bfa
, fcport
->link_e2e_beacon
);
4173 fcport
->beacon
= beacon
;
4174 fcport
->link_e2e_beacon
= link_e2e_beacon
;
4178 bfa_fcport_is_linkup(struct bfa_s
*bfa
)
4180 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4182 return (!fcport
->cfg
.trunked
&&
4183 bfa_sm_cmp_state(fcport
, bfa_fcport_sm_linkup
)) ||
4184 (fcport
->cfg
.trunked
&&
4185 fcport
->trunk
.attr
.state
== BFA_TRUNK_ONLINE
);
4189 bfa_fcport_is_qos_enabled(struct bfa_s
*bfa
)
4191 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4193 return fcport
->cfg
.qos_enabled
;
4197 bfa_fcport_is_trunk_enabled(struct bfa_s
*bfa
)
4199 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4201 return fcport
->cfg
.trunked
;
4205 bfa_fcport_cfg_bbcr(struct bfa_s
*bfa
, bfa_boolean_t on_off
, u8 bb_scn
)
4207 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4209 bfa_trc(bfa
, on_off
);
4211 if (bfa_ioc_get_type(&fcport
->bfa
->ioc
) != BFA_IOC_TYPE_FC
)
4212 return BFA_STATUS_BBCR_FC_ONLY
;
4214 if (bfa_mfg_is_mezz(bfa
->ioc
.attr
->card_type
) &&
4215 (bfa
->ioc
.attr
->card_type
!= BFA_MFG_TYPE_CHINOOK
))
4216 return BFA_STATUS_CMD_NOTSUPP_MEZZ
;
4219 if (fcport
->cfg
.topology
== BFA_PORT_TOPOLOGY_LOOP
)
4220 return BFA_STATUS_TOPOLOGY_LOOP
;
4222 if (fcport
->cfg
.qos_enabled
)
4223 return BFA_STATUS_ERROR_QOS_ENABLED
;
4225 if (fcport
->cfg
.trunked
)
4226 return BFA_STATUS_TRUNK_ENABLED
;
4228 if ((fcport
->cfg
.speed
!= BFA_PORT_SPEED_AUTO
) &&
4229 (fcport
->cfg
.speed
< bfa_ioc_speed_sup(&bfa
->ioc
)))
4230 return BFA_STATUS_ERR_BBCR_SPEED_UNSUPPORT
;
4232 if (bfa_ioc_speed_sup(&bfa
->ioc
) < BFA_PORT_SPEED_8GBPS
)
4233 return BFA_STATUS_FEATURE_NOT_SUPPORTED
;
4235 if (fcport
->cfg
.bb_cr_enabled
) {
4236 if (bb_scn
!= fcport
->cfg
.bb_scn
)
4237 return BFA_STATUS_BBCR_CFG_NO_CHANGE
;
4239 return BFA_STATUS_NO_CHANGE
;
4242 if ((bb_scn
== 0) || (bb_scn
> BFA_BB_SCN_MAX
))
4243 bb_scn
= BFA_BB_SCN_DEF
;
4245 fcport
->cfg
.bb_cr_enabled
= on_off
;
4246 fcport
->cfg
.bb_scn
= bb_scn
;
4248 if (!fcport
->cfg
.bb_cr_enabled
)
4249 return BFA_STATUS_NO_CHANGE
;
4251 fcport
->cfg
.bb_cr_enabled
= on_off
;
4252 fcport
->cfg
.bb_scn
= 0;
4255 return BFA_STATUS_OK
;
4259 bfa_fcport_get_bbcr_attr(struct bfa_s
*bfa
,
4260 struct bfa_bbcr_attr_s
*bbcr_attr
)
4262 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4264 if (bfa_ioc_get_type(&fcport
->bfa
->ioc
) != BFA_IOC_TYPE_FC
)
4265 return BFA_STATUS_BBCR_FC_ONLY
;
4267 if (fcport
->cfg
.topology
== BFA_PORT_TOPOLOGY_LOOP
)
4268 return BFA_STATUS_TOPOLOGY_LOOP
;
4270 *bbcr_attr
= fcport
->bbcr_attr
;
4272 return BFA_STATUS_OK
;
4276 bfa_fcport_dportenable(struct bfa_s
*bfa
)
4279 * Assume caller check for port is in disable state
4281 bfa_sm_send_event(BFA_FCPORT_MOD(bfa
), BFA_FCPORT_SM_DPORTENABLE
);
4282 bfa_port_set_dportenabled(&bfa
->modules
.port
, BFA_TRUE
);
4286 bfa_fcport_dportdisable(struct bfa_s
*bfa
)
4289 * Assume caller check for port is in disable state
4291 bfa_sm_send_event(BFA_FCPORT_MOD(bfa
), BFA_FCPORT_SM_DPORTDISABLE
);
4292 bfa_port_set_dportenabled(&bfa
->modules
.port
, BFA_FALSE
);
4296 bfa_fcport_ddportenable(struct bfa_s
*bfa
)
4299 * Assume caller check for port is in disable state
4301 bfa_sm_send_event(BFA_FCPORT_MOD(bfa
), BFA_FCPORT_SM_DDPORTENABLE
);
4305 bfa_fcport_ddportdisable(struct bfa_s
*bfa
)
4308 * Assume caller check for port is in disable state
4310 bfa_sm_send_event(BFA_FCPORT_MOD(bfa
), BFA_FCPORT_SM_DDPORTDISABLE
);
4314 * Rport State machine functions
4317 * Beginning state, only online event expected.
4320 bfa_rport_sm_uninit(struct bfa_rport_s
*rp
, enum bfa_rport_event event
)
4322 bfa_trc(rp
->bfa
, rp
->rport_tag
);
4323 bfa_trc(rp
->bfa
, event
);
4326 case BFA_RPORT_SM_CREATE
:
4327 bfa_stats(rp
, sm_un_cr
);
4328 bfa_sm_set_state(rp
, bfa_rport_sm_created
);
4332 bfa_stats(rp
, sm_un_unexp
);
4333 bfa_sm_fault(rp
->bfa
, event
);
4338 bfa_rport_sm_created(struct bfa_rport_s
*rp
, enum bfa_rport_event event
)
4340 bfa_trc(rp
->bfa
, rp
->rport_tag
);
4341 bfa_trc(rp
->bfa
, event
);
4344 case BFA_RPORT_SM_ONLINE
:
4345 bfa_stats(rp
, sm_cr_on
);
4346 if (bfa_rport_send_fwcreate(rp
))
4347 bfa_sm_set_state(rp
, bfa_rport_sm_fwcreate
);
4349 bfa_sm_set_state(rp
, bfa_rport_sm_fwcreate_qfull
);
4352 case BFA_RPORT_SM_DELETE
:
4353 bfa_stats(rp
, sm_cr_del
);
4354 bfa_sm_set_state(rp
, bfa_rport_sm_uninit
);
4358 case BFA_RPORT_SM_HWFAIL
:
4359 bfa_stats(rp
, sm_cr_hwf
);
4360 bfa_sm_set_state(rp
, bfa_rport_sm_iocdisable
);
4364 bfa_stats(rp
, sm_cr_unexp
);
4365 bfa_sm_fault(rp
->bfa
, event
);
4370 * Waiting for rport create response from firmware.
4373 bfa_rport_sm_fwcreate(struct bfa_rport_s
*rp
, enum bfa_rport_event event
)
4375 bfa_trc(rp
->bfa
, rp
->rport_tag
);
4376 bfa_trc(rp
->bfa
, event
);
4379 case BFA_RPORT_SM_FWRSP
:
4380 bfa_stats(rp
, sm_fwc_rsp
);
4381 bfa_sm_set_state(rp
, bfa_rport_sm_online
);
4382 bfa_rport_online_cb(rp
);
4385 case BFA_RPORT_SM_DELETE
:
4386 bfa_stats(rp
, sm_fwc_del
);
4387 bfa_sm_set_state(rp
, bfa_rport_sm_delete_pending
);
4390 case BFA_RPORT_SM_OFFLINE
:
4391 bfa_stats(rp
, sm_fwc_off
);
4392 bfa_sm_set_state(rp
, bfa_rport_sm_offline_pending
);
4395 case BFA_RPORT_SM_HWFAIL
:
4396 bfa_stats(rp
, sm_fwc_hwf
);
4397 bfa_sm_set_state(rp
, bfa_rport_sm_iocdisable
);
4401 bfa_stats(rp
, sm_fwc_unexp
);
4402 bfa_sm_fault(rp
->bfa
, event
);
4407 * Request queue is full, awaiting queue resume to send create request.
4410 bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s
*rp
, enum bfa_rport_event event
)
4412 bfa_trc(rp
->bfa
, rp
->rport_tag
);
4413 bfa_trc(rp
->bfa
, event
);
4416 case BFA_RPORT_SM_QRESUME
:
4417 bfa_sm_set_state(rp
, bfa_rport_sm_fwcreate
);
4418 bfa_rport_send_fwcreate(rp
);
4421 case BFA_RPORT_SM_DELETE
:
4422 bfa_stats(rp
, sm_fwc_del
);
4423 bfa_sm_set_state(rp
, bfa_rport_sm_uninit
);
4424 bfa_reqq_wcancel(&rp
->reqq_wait
);
4428 case BFA_RPORT_SM_OFFLINE
:
4429 bfa_stats(rp
, sm_fwc_off
);
4430 bfa_sm_set_state(rp
, bfa_rport_sm_offline
);
4431 bfa_reqq_wcancel(&rp
->reqq_wait
);
4432 bfa_rport_offline_cb(rp
);
4435 case BFA_RPORT_SM_HWFAIL
:
4436 bfa_stats(rp
, sm_fwc_hwf
);
4437 bfa_sm_set_state(rp
, bfa_rport_sm_iocdisable
);
4438 bfa_reqq_wcancel(&rp
->reqq_wait
);
4442 bfa_stats(rp
, sm_fwc_unexp
);
4443 bfa_sm_fault(rp
->bfa
, event
);
4448 * Online state - normal parking state.
4451 bfa_rport_sm_online(struct bfa_rport_s
*rp
, enum bfa_rport_event event
)
4453 struct bfi_rport_qos_scn_s
*qos_scn
;
4455 bfa_trc(rp
->bfa
, rp
->rport_tag
);
4456 bfa_trc(rp
->bfa
, event
);
4459 case BFA_RPORT_SM_OFFLINE
:
4460 bfa_stats(rp
, sm_on_off
);
4461 if (bfa_rport_send_fwdelete(rp
))
4462 bfa_sm_set_state(rp
, bfa_rport_sm_fwdelete
);
4464 bfa_sm_set_state(rp
, bfa_rport_sm_fwdelete_qfull
);
4467 case BFA_RPORT_SM_DELETE
:
4468 bfa_stats(rp
, sm_on_del
);
4469 if (bfa_rport_send_fwdelete(rp
))
4470 bfa_sm_set_state(rp
, bfa_rport_sm_deleting
);
4472 bfa_sm_set_state(rp
, bfa_rport_sm_deleting_qfull
);
4475 case BFA_RPORT_SM_HWFAIL
:
4476 bfa_stats(rp
, sm_on_hwf
);
4477 bfa_sm_set_state(rp
, bfa_rport_sm_iocdisable
);
4480 case BFA_RPORT_SM_SET_SPEED
:
4481 bfa_rport_send_fwspeed(rp
);
4484 case BFA_RPORT_SM_QOS_SCN
:
4485 qos_scn
= (struct bfi_rport_qos_scn_s
*) rp
->event_arg
.fw_msg
;
4486 rp
->qos_attr
= qos_scn
->new_qos_attr
;
4487 bfa_trc(rp
->bfa
, qos_scn
->old_qos_attr
.qos_flow_id
);
4488 bfa_trc(rp
->bfa
, qos_scn
->new_qos_attr
.qos_flow_id
);
4489 bfa_trc(rp
->bfa
, qos_scn
->old_qos_attr
.qos_priority
);
4490 bfa_trc(rp
->bfa
, qos_scn
->new_qos_attr
.qos_priority
);
4492 qos_scn
->old_qos_attr
.qos_flow_id
=
4493 be32_to_cpu(qos_scn
->old_qos_attr
.qos_flow_id
);
4494 qos_scn
->new_qos_attr
.qos_flow_id
=
4495 be32_to_cpu(qos_scn
->new_qos_attr
.qos_flow_id
);
4497 if (qos_scn
->old_qos_attr
.qos_flow_id
!=
4498 qos_scn
->new_qos_attr
.qos_flow_id
)
4499 bfa_cb_rport_qos_scn_flowid(rp
->rport_drv
,
4500 qos_scn
->old_qos_attr
,
4501 qos_scn
->new_qos_attr
);
4502 if (qos_scn
->old_qos_attr
.qos_priority
!=
4503 qos_scn
->new_qos_attr
.qos_priority
)
4504 bfa_cb_rport_qos_scn_prio(rp
->rport_drv
,
4505 qos_scn
->old_qos_attr
,
4506 qos_scn
->new_qos_attr
);
4510 bfa_stats(rp
, sm_on_unexp
);
4511 bfa_sm_fault(rp
->bfa
, event
);
4516 * Firmware rport is being deleted - awaiting f/w response.
4519 bfa_rport_sm_fwdelete(struct bfa_rport_s
*rp
, enum bfa_rport_event event
)
4521 bfa_trc(rp
->bfa
, rp
->rport_tag
);
4522 bfa_trc(rp
->bfa
, event
);
4525 case BFA_RPORT_SM_FWRSP
:
4526 bfa_stats(rp
, sm_fwd_rsp
);
4527 bfa_sm_set_state(rp
, bfa_rport_sm_offline
);
4528 bfa_rport_offline_cb(rp
);
4531 case BFA_RPORT_SM_DELETE
:
4532 bfa_stats(rp
, sm_fwd_del
);
4533 bfa_sm_set_state(rp
, bfa_rport_sm_deleting
);
4536 case BFA_RPORT_SM_HWFAIL
:
4537 bfa_stats(rp
, sm_fwd_hwf
);
4538 bfa_sm_set_state(rp
, bfa_rport_sm_iocdisable
);
4539 bfa_rport_offline_cb(rp
);
4543 bfa_stats(rp
, sm_fwd_unexp
);
4544 bfa_sm_fault(rp
->bfa
, event
);
4549 bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s
*rp
, enum bfa_rport_event event
)
4551 bfa_trc(rp
->bfa
, rp
->rport_tag
);
4552 bfa_trc(rp
->bfa
, event
);
4555 case BFA_RPORT_SM_QRESUME
:
4556 bfa_sm_set_state(rp
, bfa_rport_sm_fwdelete
);
4557 bfa_rport_send_fwdelete(rp
);
4560 case BFA_RPORT_SM_DELETE
:
4561 bfa_stats(rp
, sm_fwd_del
);
4562 bfa_sm_set_state(rp
, bfa_rport_sm_deleting_qfull
);
4565 case BFA_RPORT_SM_HWFAIL
:
4566 bfa_stats(rp
, sm_fwd_hwf
);
4567 bfa_sm_set_state(rp
, bfa_rport_sm_iocdisable
);
4568 bfa_reqq_wcancel(&rp
->reqq_wait
);
4569 bfa_rport_offline_cb(rp
);
4573 bfa_stats(rp
, sm_fwd_unexp
);
4574 bfa_sm_fault(rp
->bfa
, event
);
4582 bfa_rport_sm_offline(struct bfa_rport_s
*rp
, enum bfa_rport_event event
)
4584 bfa_trc(rp
->bfa
, rp
->rport_tag
);
4585 bfa_trc(rp
->bfa
, event
);
4588 case BFA_RPORT_SM_DELETE
:
4589 bfa_stats(rp
, sm_off_del
);
4590 bfa_sm_set_state(rp
, bfa_rport_sm_uninit
);
4594 case BFA_RPORT_SM_ONLINE
:
4595 bfa_stats(rp
, sm_off_on
);
4596 if (bfa_rport_send_fwcreate(rp
))
4597 bfa_sm_set_state(rp
, bfa_rport_sm_fwcreate
);
4599 bfa_sm_set_state(rp
, bfa_rport_sm_fwcreate_qfull
);
4602 case BFA_RPORT_SM_HWFAIL
:
4603 bfa_stats(rp
, sm_off_hwf
);
4604 bfa_sm_set_state(rp
, bfa_rport_sm_iocdisable
);
4607 case BFA_RPORT_SM_OFFLINE
:
4608 bfa_rport_offline_cb(rp
);
4612 bfa_stats(rp
, sm_off_unexp
);
4613 bfa_sm_fault(rp
->bfa
, event
);
4618 * Rport is deleted, waiting for firmware response to delete.
4621 bfa_rport_sm_deleting(struct bfa_rport_s
*rp
, enum bfa_rport_event event
)
4623 bfa_trc(rp
->bfa
, rp
->rport_tag
);
4624 bfa_trc(rp
->bfa
, event
);
4627 case BFA_RPORT_SM_FWRSP
:
4628 bfa_stats(rp
, sm_del_fwrsp
);
4629 bfa_sm_set_state(rp
, bfa_rport_sm_uninit
);
4633 case BFA_RPORT_SM_HWFAIL
:
4634 bfa_stats(rp
, sm_del_hwf
);
4635 bfa_sm_set_state(rp
, bfa_rport_sm_uninit
);
4640 bfa_sm_fault(rp
->bfa
, event
);
4645 bfa_rport_sm_deleting_qfull(struct bfa_rport_s
*rp
, enum bfa_rport_event event
)
4647 bfa_trc(rp
->bfa
, rp
->rport_tag
);
4648 bfa_trc(rp
->bfa
, event
);
4651 case BFA_RPORT_SM_QRESUME
:
4652 bfa_stats(rp
, sm_del_fwrsp
);
4653 bfa_sm_set_state(rp
, bfa_rport_sm_deleting
);
4654 bfa_rport_send_fwdelete(rp
);
4657 case BFA_RPORT_SM_HWFAIL
:
4658 bfa_stats(rp
, sm_del_hwf
);
4659 bfa_sm_set_state(rp
, bfa_rport_sm_uninit
);
4660 bfa_reqq_wcancel(&rp
->reqq_wait
);
4665 bfa_sm_fault(rp
->bfa
, event
);
4670 * Waiting for rport create response from firmware. A delete is pending.
4673 bfa_rport_sm_delete_pending(struct bfa_rport_s
*rp
,
4674 enum bfa_rport_event event
)
4676 bfa_trc(rp
->bfa
, rp
->rport_tag
);
4677 bfa_trc(rp
->bfa
, event
);
4680 case BFA_RPORT_SM_FWRSP
:
4681 bfa_stats(rp
, sm_delp_fwrsp
);
4682 if (bfa_rport_send_fwdelete(rp
))
4683 bfa_sm_set_state(rp
, bfa_rport_sm_deleting
);
4685 bfa_sm_set_state(rp
, bfa_rport_sm_deleting_qfull
);
4688 case BFA_RPORT_SM_HWFAIL
:
4689 bfa_stats(rp
, sm_delp_hwf
);
4690 bfa_sm_set_state(rp
, bfa_rport_sm_uninit
);
4695 bfa_stats(rp
, sm_delp_unexp
);
4696 bfa_sm_fault(rp
->bfa
, event
);
4701 * Waiting for rport create response from firmware. Rport offline is pending.
4704 bfa_rport_sm_offline_pending(struct bfa_rport_s
*rp
,
4705 enum bfa_rport_event event
)
4707 bfa_trc(rp
->bfa
, rp
->rport_tag
);
4708 bfa_trc(rp
->bfa
, event
);
4711 case BFA_RPORT_SM_FWRSP
:
4712 bfa_stats(rp
, sm_offp_fwrsp
);
4713 if (bfa_rport_send_fwdelete(rp
))
4714 bfa_sm_set_state(rp
, bfa_rport_sm_fwdelete
);
4716 bfa_sm_set_state(rp
, bfa_rport_sm_fwdelete_qfull
);
4719 case BFA_RPORT_SM_DELETE
:
4720 bfa_stats(rp
, sm_offp_del
);
4721 bfa_sm_set_state(rp
, bfa_rport_sm_delete_pending
);
4724 case BFA_RPORT_SM_HWFAIL
:
4725 bfa_stats(rp
, sm_offp_hwf
);
4726 bfa_sm_set_state(rp
, bfa_rport_sm_iocdisable
);
4727 bfa_rport_offline_cb(rp
);
4731 bfa_stats(rp
, sm_offp_unexp
);
4732 bfa_sm_fault(rp
->bfa
, event
);
4740 bfa_rport_sm_iocdisable(struct bfa_rport_s
*rp
, enum bfa_rport_event event
)
4742 bfa_trc(rp
->bfa
, rp
->rport_tag
);
4743 bfa_trc(rp
->bfa
, event
);
4746 case BFA_RPORT_SM_OFFLINE
:
4747 bfa_stats(rp
, sm_iocd_off
);
4748 bfa_rport_offline_cb(rp
);
4751 case BFA_RPORT_SM_DELETE
:
4752 bfa_stats(rp
, sm_iocd_del
);
4753 bfa_sm_set_state(rp
, bfa_rport_sm_uninit
);
4757 case BFA_RPORT_SM_ONLINE
:
4758 bfa_stats(rp
, sm_iocd_on
);
4759 if (bfa_rport_send_fwcreate(rp
))
4760 bfa_sm_set_state(rp
, bfa_rport_sm_fwcreate
);
4762 bfa_sm_set_state(rp
, bfa_rport_sm_fwcreate_qfull
);
4765 case BFA_RPORT_SM_HWFAIL
:
4769 bfa_stats(rp
, sm_iocd_unexp
);
4770 bfa_sm_fault(rp
->bfa
, event
);
4777 * bfa_rport_private BFA rport private functions
4781 __bfa_cb_rport_online(void *cbarg
, bfa_boolean_t complete
)
4783 struct bfa_rport_s
*rp
= cbarg
;
4786 bfa_cb_rport_online(rp
->rport_drv
);
4790 __bfa_cb_rport_offline(void *cbarg
, bfa_boolean_t complete
)
4792 struct bfa_rport_s
*rp
= cbarg
;
4795 bfa_cb_rport_offline(rp
->rport_drv
);
4799 bfa_rport_qresume(void *cbarg
)
4801 struct bfa_rport_s
*rp
= cbarg
;
4803 bfa_sm_send_event(rp
, BFA_RPORT_SM_QRESUME
);
4807 bfa_rport_meminfo(struct bfa_iocfc_cfg_s
*cfg
, struct bfa_meminfo_s
*minfo
,
4810 struct bfa_mem_kva_s
*rport_kva
= BFA_MEM_RPORT_KVA(bfa
);
4812 if (cfg
->fwcfg
.num_rports
< BFA_RPORT_MIN
)
4813 cfg
->fwcfg
.num_rports
= BFA_RPORT_MIN
;
4816 bfa_mem_kva_setup(minfo
, rport_kva
,
4817 cfg
->fwcfg
.num_rports
* sizeof(struct bfa_rport_s
));
4821 bfa_rport_attach(struct bfa_s
*bfa
, void *bfad
, struct bfa_iocfc_cfg_s
*cfg
,
4822 struct bfa_pcidev_s
*pcidev
)
4824 struct bfa_rport_mod_s
*mod
= BFA_RPORT_MOD(bfa
);
4825 struct bfa_rport_s
*rp
;
4828 INIT_LIST_HEAD(&mod
->rp_free_q
);
4829 INIT_LIST_HEAD(&mod
->rp_active_q
);
4830 INIT_LIST_HEAD(&mod
->rp_unused_q
);
4832 rp
= (struct bfa_rport_s
*) bfa_mem_kva_curp(mod
);
4834 mod
->num_rports
= cfg
->fwcfg
.num_rports
;
4836 WARN_ON(!mod
->num_rports
||
4837 (mod
->num_rports
& (mod
->num_rports
- 1)));
4839 for (i
= 0; i
< mod
->num_rports
; i
++, rp
++) {
4840 memset(rp
, 0, sizeof(struct bfa_rport_s
));
4843 bfa_sm_set_state(rp
, bfa_rport_sm_uninit
);
4849 list_add_tail(&rp
->qe
, &mod
->rp_free_q
);
4851 bfa_reqq_winit(&rp
->reqq_wait
, bfa_rport_qresume
, rp
);
4857 bfa_mem_kva_curp(mod
) = (u8
*) rp
;
4861 bfa_rport_iocdisable(struct bfa_s
*bfa
)
4863 struct bfa_rport_mod_s
*mod
= BFA_RPORT_MOD(bfa
);
4864 struct bfa_rport_s
*rport
;
4865 struct list_head
*qe
, *qen
;
4867 /* Enqueue unused rport resources to free_q */
4868 list_splice_tail_init(&mod
->rp_unused_q
, &mod
->rp_free_q
);
4870 list_for_each_safe(qe
, qen
, &mod
->rp_active_q
) {
4871 rport
= (struct bfa_rport_s
*) qe
;
4872 bfa_sm_send_event(rport
, BFA_RPORT_SM_HWFAIL
);
4876 static struct bfa_rport_s
*
4877 bfa_rport_alloc(struct bfa_rport_mod_s
*mod
)
4879 struct bfa_rport_s
*rport
;
4881 bfa_q_deq(&mod
->rp_free_q
, &rport
);
4883 list_add_tail(&rport
->qe
, &mod
->rp_active_q
);
4889 bfa_rport_free(struct bfa_rport_s
*rport
)
4891 struct bfa_rport_mod_s
*mod
= BFA_RPORT_MOD(rport
->bfa
);
4893 WARN_ON(!bfa_q_is_on_q(&mod
->rp_active_q
, rport
));
4894 list_del(&rport
->qe
);
4895 list_add_tail(&rport
->qe
, &mod
->rp_free_q
);
4898 static bfa_boolean_t
4899 bfa_rport_send_fwcreate(struct bfa_rport_s
*rp
)
4901 struct bfi_rport_create_req_s
*m
;
4904 * check for room in queue to send request now
4906 m
= bfa_reqq_next(rp
->bfa
, BFA_REQQ_RPORT
);
4908 bfa_reqq_wait(rp
->bfa
, BFA_REQQ_RPORT
, &rp
->reqq_wait
);
4912 bfi_h2i_set(m
->mh
, BFI_MC_RPORT
, BFI_RPORT_H2I_CREATE_REQ
,
4913 bfa_fn_lpu(rp
->bfa
));
4914 m
->bfa_handle
= rp
->rport_tag
;
4915 m
->max_frmsz
= cpu_to_be16(rp
->rport_info
.max_frmsz
);
4916 m
->pid
= rp
->rport_info
.pid
;
4917 m
->lp_fwtag
= bfa_lps_get_fwtag(rp
->bfa
, (u8
)rp
->rport_info
.lp_tag
);
4918 m
->local_pid
= rp
->rport_info
.local_pid
;
4919 m
->fc_class
= rp
->rport_info
.fc_class
;
4920 m
->vf_en
= rp
->rport_info
.vf_en
;
4921 m
->vf_id
= rp
->rport_info
.vf_id
;
4922 m
->cisc
= rp
->rport_info
.cisc
;
4925 * queue I/O message to firmware
4927 bfa_reqq_produce(rp
->bfa
, BFA_REQQ_RPORT
, m
->mh
);
4931 static bfa_boolean_t
4932 bfa_rport_send_fwdelete(struct bfa_rport_s
*rp
)
4934 struct bfi_rport_delete_req_s
*m
;
4937 * check for room in queue to send request now
4939 m
= bfa_reqq_next(rp
->bfa
, BFA_REQQ_RPORT
);
4941 bfa_reqq_wait(rp
->bfa
, BFA_REQQ_RPORT
, &rp
->reqq_wait
);
4945 bfi_h2i_set(m
->mh
, BFI_MC_RPORT
, BFI_RPORT_H2I_DELETE_REQ
,
4946 bfa_fn_lpu(rp
->bfa
));
4947 m
->fw_handle
= rp
->fw_handle
;
4950 * queue I/O message to firmware
4952 bfa_reqq_produce(rp
->bfa
, BFA_REQQ_RPORT
, m
->mh
);
4956 static bfa_boolean_t
4957 bfa_rport_send_fwspeed(struct bfa_rport_s
*rp
)
4959 struct bfa_rport_speed_req_s
*m
;
4962 * check for room in queue to send request now
4964 m
= bfa_reqq_next(rp
->bfa
, BFA_REQQ_RPORT
);
4966 bfa_trc(rp
->bfa
, rp
->rport_info
.speed
);
4970 bfi_h2i_set(m
->mh
, BFI_MC_RPORT
, BFI_RPORT_H2I_SET_SPEED_REQ
,
4971 bfa_fn_lpu(rp
->bfa
));
4972 m
->fw_handle
= rp
->fw_handle
;
4973 m
->speed
= (u8
)rp
->rport_info
.speed
;
4976 * queue I/O message to firmware
4978 bfa_reqq_produce(rp
->bfa
, BFA_REQQ_RPORT
, m
->mh
);
4989 * Rport interrupt processing.
4992 bfa_rport_isr(struct bfa_s
*bfa
, struct bfi_msg_s
*m
)
4994 union bfi_rport_i2h_msg_u msg
;
4995 struct bfa_rport_s
*rp
;
4997 bfa_trc(bfa
, m
->mhdr
.msg_id
);
5001 switch (m
->mhdr
.msg_id
) {
5002 case BFI_RPORT_I2H_CREATE_RSP
:
5003 rp
= BFA_RPORT_FROM_TAG(bfa
, msg
.create_rsp
->bfa_handle
);
5004 rp
->fw_handle
= msg
.create_rsp
->fw_handle
;
5005 rp
->qos_attr
= msg
.create_rsp
->qos_attr
;
5006 bfa_rport_set_lunmask(bfa
, rp
);
5007 WARN_ON(msg
.create_rsp
->status
!= BFA_STATUS_OK
);
5008 bfa_sm_send_event(rp
, BFA_RPORT_SM_FWRSP
);
5011 case BFI_RPORT_I2H_DELETE_RSP
:
5012 rp
= BFA_RPORT_FROM_TAG(bfa
, msg
.delete_rsp
->bfa_handle
);
5013 WARN_ON(msg
.delete_rsp
->status
!= BFA_STATUS_OK
);
5014 bfa_rport_unset_lunmask(bfa
, rp
);
5015 bfa_sm_send_event(rp
, BFA_RPORT_SM_FWRSP
);
5018 case BFI_RPORT_I2H_QOS_SCN
:
5019 rp
= BFA_RPORT_FROM_TAG(bfa
, msg
.qos_scn_evt
->bfa_handle
);
5020 rp
->event_arg
.fw_msg
= msg
.qos_scn_evt
;
5021 bfa_sm_send_event(rp
, BFA_RPORT_SM_QOS_SCN
);
5024 case BFI_RPORT_I2H_LIP_SCN_ONLINE
:
5025 bfa_fcport_update_loop_info(BFA_FCPORT_MOD(bfa
),
5026 &msg
.lip_scn
->loop_info
);
5027 bfa_cb_rport_scn_online(bfa
);
5030 case BFI_RPORT_I2H_LIP_SCN_OFFLINE
:
5031 bfa_cb_rport_scn_offline(bfa
);
5034 case BFI_RPORT_I2H_NO_DEV
:
5035 rp
= BFA_RPORT_FROM_TAG(bfa
, msg
.lip_scn
->bfa_handle
);
5036 bfa_cb_rport_scn_no_dev(rp
->rport_drv
);
5040 bfa_trc(bfa
, m
->mhdr
.msg_id
);
5046 bfa_rport_res_recfg(struct bfa_s
*bfa
, u16 num_rport_fw
)
5048 struct bfa_rport_mod_s
*mod
= BFA_RPORT_MOD(bfa
);
5049 struct list_head
*qe
;
5052 for (i
= 0; i
< (mod
->num_rports
- num_rport_fw
); i
++) {
5053 bfa_q_deq_tail(&mod
->rp_free_q
, &qe
);
5054 list_add_tail(qe
, &mod
->rp_unused_q
);
5062 struct bfa_rport_s
*
5063 bfa_rport_create(struct bfa_s
*bfa
, void *rport_drv
)
5065 struct bfa_rport_s
*rp
;
5067 rp
= bfa_rport_alloc(BFA_RPORT_MOD(bfa
));
5073 rp
->rport_drv
= rport_drv
;
5074 memset(&rp
->stats
, 0, sizeof(rp
->stats
));
5076 WARN_ON(!bfa_sm_cmp_state(rp
, bfa_rport_sm_uninit
));
5077 bfa_sm_send_event(rp
, BFA_RPORT_SM_CREATE
);
5083 bfa_rport_online(struct bfa_rport_s
*rport
, struct bfa_rport_info_s
*rport_info
)
5085 WARN_ON(rport_info
->max_frmsz
== 0);
5088 * Some JBODs are seen to be not setting PDU size correctly in PLOGI
5089 * responses. Default to minimum size.
5091 if (rport_info
->max_frmsz
== 0) {
5092 bfa_trc(rport
->bfa
, rport
->rport_tag
);
5093 rport_info
->max_frmsz
= FC_MIN_PDUSZ
;
5096 rport
->rport_info
= *rport_info
;
5097 bfa_sm_send_event(rport
, BFA_RPORT_SM_ONLINE
);
5101 bfa_rport_speed(struct bfa_rport_s
*rport
, enum bfa_port_speed speed
)
5103 WARN_ON(speed
== 0);
5104 WARN_ON(speed
== BFA_PORT_SPEED_AUTO
);
5107 rport
->rport_info
.speed
= speed
;
5108 bfa_sm_send_event(rport
, BFA_RPORT_SM_SET_SPEED
);
5112 /* Set Rport LUN Mask */
5114 bfa_rport_set_lunmask(struct bfa_s
*bfa
, struct bfa_rport_s
*rp
)
5116 struct bfa_lps_mod_s
*lps_mod
= BFA_LPS_MOD(bfa
);
5117 wwn_t lp_wwn
, rp_wwn
;
5118 u8 lp_tag
= (u8
)rp
->rport_info
.lp_tag
;
5120 rp_wwn
= ((struct bfa_fcs_rport_s
*)rp
->rport_drv
)->pwwn
;
5121 lp_wwn
= (BFA_LPS_FROM_TAG(lps_mod
, rp
->rport_info
.lp_tag
))->pwwn
;
5123 BFA_LPS_FROM_TAG(lps_mod
, rp
->rport_info
.lp_tag
)->lun_mask
=
5124 rp
->lun_mask
= BFA_TRUE
;
5125 bfa_fcpim_lunmask_rp_update(bfa
, lp_wwn
, rp_wwn
, rp
->rport_tag
, lp_tag
);
5128 /* Unset Rport LUN mask */
5130 bfa_rport_unset_lunmask(struct bfa_s
*bfa
, struct bfa_rport_s
*rp
)
5132 struct bfa_lps_mod_s
*lps_mod
= BFA_LPS_MOD(bfa
);
5133 wwn_t lp_wwn
, rp_wwn
;
5135 rp_wwn
= ((struct bfa_fcs_rport_s
*)rp
->rport_drv
)->pwwn
;
5136 lp_wwn
= (BFA_LPS_FROM_TAG(lps_mod
, rp
->rport_info
.lp_tag
))->pwwn
;
5138 BFA_LPS_FROM_TAG(lps_mod
, rp
->rport_info
.lp_tag
)->lun_mask
=
5139 rp
->lun_mask
= BFA_FALSE
;
5140 bfa_fcpim_lunmask_rp_update(bfa
, lp_wwn
, rp_wwn
,
5141 BFA_RPORT_TAG_INVALID
, BFA_LP_TAG_INVALID
);
5145 * SGPG related functions
5149 * Compute and return memory needed by FCP(im) module.
5152 bfa_sgpg_meminfo(struct bfa_iocfc_cfg_s
*cfg
, struct bfa_meminfo_s
*minfo
,
5155 struct bfa_sgpg_mod_s
*sgpg_mod
= BFA_SGPG_MOD(bfa
);
5156 struct bfa_mem_kva_s
*sgpg_kva
= BFA_MEM_SGPG_KVA(bfa
);
5157 struct bfa_mem_dma_s
*seg_ptr
;
5158 u16 nsegs
, idx
, per_seg_sgpg
, num_sgpg
;
5159 u32 sgpg_sz
= sizeof(struct bfi_sgpg_s
);
5161 if (cfg
->drvcfg
.num_sgpgs
< BFA_SGPG_MIN
)
5162 cfg
->drvcfg
.num_sgpgs
= BFA_SGPG_MIN
;
5163 else if (cfg
->drvcfg
.num_sgpgs
> BFA_SGPG_MAX
)
5164 cfg
->drvcfg
.num_sgpgs
= BFA_SGPG_MAX
;
5166 num_sgpg
= cfg
->drvcfg
.num_sgpgs
;
5168 nsegs
= BFI_MEM_DMA_NSEGS(num_sgpg
, sgpg_sz
);
5169 per_seg_sgpg
= BFI_MEM_NREQS_SEG(sgpg_sz
);
5171 bfa_mem_dma_seg_iter(sgpg_mod
, seg_ptr
, nsegs
, idx
) {
5172 if (num_sgpg
>= per_seg_sgpg
) {
5173 num_sgpg
-= per_seg_sgpg
;
5174 bfa_mem_dma_setup(minfo
, seg_ptr
,
5175 per_seg_sgpg
* sgpg_sz
);
5177 bfa_mem_dma_setup(minfo
, seg_ptr
,
5178 num_sgpg
* sgpg_sz
);
5182 bfa_mem_kva_setup(minfo
, sgpg_kva
,
5183 cfg
->drvcfg
.num_sgpgs
* sizeof(struct bfa_sgpg_s
));
5187 bfa_sgpg_attach(struct bfa_s
*bfa
, void *bfad
, struct bfa_iocfc_cfg_s
*cfg
,
5188 struct bfa_pcidev_s
*pcidev
)
5190 struct bfa_sgpg_mod_s
*mod
= BFA_SGPG_MOD(bfa
);
5191 struct bfa_sgpg_s
*hsgpg
;
5192 struct bfi_sgpg_s
*sgpg
;
5194 struct bfa_mem_dma_s
*seg_ptr
;
5195 u32 sgpg_sz
= sizeof(struct bfi_sgpg_s
);
5196 u16 i
, idx
, nsegs
, per_seg_sgpg
, num_sgpg
;
5200 union bfi_addr_u addr
;
5201 } sgpg_pa
, sgpg_pa_tmp
;
5203 INIT_LIST_HEAD(&mod
->sgpg_q
);
5204 INIT_LIST_HEAD(&mod
->sgpg_wait_q
);
5206 bfa_trc(bfa
, cfg
->drvcfg
.num_sgpgs
);
5208 mod
->free_sgpgs
= mod
->num_sgpgs
= cfg
->drvcfg
.num_sgpgs
;
5210 num_sgpg
= cfg
->drvcfg
.num_sgpgs
;
5211 nsegs
= BFI_MEM_DMA_NSEGS(num_sgpg
, sgpg_sz
);
5213 /* dma/kva mem claim */
5214 hsgpg
= (struct bfa_sgpg_s
*) bfa_mem_kva_curp(mod
);
5216 bfa_mem_dma_seg_iter(mod
, seg_ptr
, nsegs
, idx
) {
5218 if (!bfa_mem_dma_virt(seg_ptr
))
5221 align_len
= BFA_SGPG_ROUNDUP(bfa_mem_dma_phys(seg_ptr
)) -
5222 bfa_mem_dma_phys(seg_ptr
);
5224 sgpg
= (struct bfi_sgpg_s
*)
5225 (((u8
*) bfa_mem_dma_virt(seg_ptr
)) + align_len
);
5226 sgpg_pa
.pa
= bfa_mem_dma_phys(seg_ptr
) + align_len
;
5227 WARN_ON(sgpg_pa
.pa
& (sgpg_sz
- 1));
5229 per_seg_sgpg
= (seg_ptr
->mem_len
- (u32
)align_len
) / sgpg_sz
;
5231 for (i
= 0; num_sgpg
> 0 && i
< per_seg_sgpg
; i
++, num_sgpg
--) {
5232 memset(hsgpg
, 0, sizeof(*hsgpg
));
5233 memset(sgpg
, 0, sizeof(*sgpg
));
5236 sgpg_pa_tmp
.pa
= bfa_sgaddr_le(sgpg_pa
.pa
);
5237 hsgpg
->sgpg_pa
= sgpg_pa_tmp
.addr
;
5238 list_add_tail(&hsgpg
->qe
, &mod
->sgpg_q
);
5242 sgpg_pa
.pa
+= sgpg_sz
;
5246 bfa_mem_kva_curp(mod
) = (u8
*) hsgpg
;
5250 bfa_sgpg_malloc(struct bfa_s
*bfa
, struct list_head
*sgpg_q
, int nsgpgs
)
5252 struct bfa_sgpg_mod_s
*mod
= BFA_SGPG_MOD(bfa
);
5253 struct bfa_sgpg_s
*hsgpg
;
5256 if (mod
->free_sgpgs
< nsgpgs
)
5257 return BFA_STATUS_ENOMEM
;
5259 for (i
= 0; i
< nsgpgs
; i
++) {
5260 bfa_q_deq(&mod
->sgpg_q
, &hsgpg
);
5262 list_add_tail(&hsgpg
->qe
, sgpg_q
);
5265 mod
->free_sgpgs
-= nsgpgs
;
5266 return BFA_STATUS_OK
;
5270 bfa_sgpg_mfree(struct bfa_s
*bfa
, struct list_head
*sgpg_q
, int nsgpg
)
5272 struct bfa_sgpg_mod_s
*mod
= BFA_SGPG_MOD(bfa
);
5273 struct bfa_sgpg_wqe_s
*wqe
;
5275 mod
->free_sgpgs
+= nsgpg
;
5276 WARN_ON(mod
->free_sgpgs
> mod
->num_sgpgs
);
5278 list_splice_tail_init(sgpg_q
, &mod
->sgpg_q
);
5280 if (list_empty(&mod
->sgpg_wait_q
))
5284 * satisfy as many waiting requests as possible
5287 wqe
= bfa_q_first(&mod
->sgpg_wait_q
);
5288 if (mod
->free_sgpgs
< wqe
->nsgpg
)
5289 nsgpg
= mod
->free_sgpgs
;
5292 bfa_sgpg_malloc(bfa
, &wqe
->sgpg_q
, nsgpg
);
5293 wqe
->nsgpg
-= nsgpg
;
5294 if (wqe
->nsgpg
== 0) {
5296 wqe
->cbfn(wqe
->cbarg
);
5298 } while (mod
->free_sgpgs
&& !list_empty(&mod
->sgpg_wait_q
));
5302 bfa_sgpg_wait(struct bfa_s
*bfa
, struct bfa_sgpg_wqe_s
*wqe
, int nsgpg
)
5304 struct bfa_sgpg_mod_s
*mod
= BFA_SGPG_MOD(bfa
);
5306 WARN_ON(nsgpg
<= 0);
5307 WARN_ON(nsgpg
<= mod
->free_sgpgs
);
5309 wqe
->nsgpg_total
= wqe
->nsgpg
= nsgpg
;
5312 * allocate any left to this one first
5314 if (mod
->free_sgpgs
) {
5316 * no one else is waiting for SGPG
5318 WARN_ON(!list_empty(&mod
->sgpg_wait_q
));
5319 list_splice_tail_init(&mod
->sgpg_q
, &wqe
->sgpg_q
);
5320 wqe
->nsgpg
-= mod
->free_sgpgs
;
5321 mod
->free_sgpgs
= 0;
5324 list_add_tail(&wqe
->qe
, &mod
->sgpg_wait_q
);
5328 bfa_sgpg_wcancel(struct bfa_s
*bfa
, struct bfa_sgpg_wqe_s
*wqe
)
5330 struct bfa_sgpg_mod_s
*mod
= BFA_SGPG_MOD(bfa
);
5332 WARN_ON(!bfa_q_is_on_q(&mod
->sgpg_wait_q
, wqe
));
5335 if (wqe
->nsgpg_total
!= wqe
->nsgpg
)
5336 bfa_sgpg_mfree(bfa
, &wqe
->sgpg_q
,
5337 wqe
->nsgpg_total
- wqe
->nsgpg
);
5341 bfa_sgpg_winit(struct bfa_sgpg_wqe_s
*wqe
, void (*cbfn
) (void *cbarg
),
5344 INIT_LIST_HEAD(&wqe
->sgpg_q
);
5350 * UF related functions
5353 *****************************************************************************
5354 * Internal functions
5355 *****************************************************************************
5358 __bfa_cb_uf_recv(void *cbarg
, bfa_boolean_t complete
)
5360 struct bfa_uf_s
*uf
= cbarg
;
5361 struct bfa_uf_mod_s
*ufm
= BFA_UF_MOD(uf
->bfa
);
5364 ufm
->ufrecv(ufm
->cbarg
, uf
);
5368 claim_uf_post_msgs(struct bfa_uf_mod_s
*ufm
)
5370 struct bfi_uf_buf_post_s
*uf_bp_msg
;
5374 ufm
->uf_buf_posts
= (struct bfi_uf_buf_post_s
*) bfa_mem_kva_curp(ufm
);
5375 uf_bp_msg
= ufm
->uf_buf_posts
;
5377 for (i
= 0, uf_bp_msg
= ufm
->uf_buf_posts
; i
< ufm
->num_ufs
;
5379 memset(uf_bp_msg
, 0, sizeof(struct bfi_uf_buf_post_s
));
5381 uf_bp_msg
->buf_tag
= i
;
5382 buf_len
= sizeof(struct bfa_uf_buf_s
);
5383 uf_bp_msg
->buf_len
= cpu_to_be16(buf_len
);
5384 bfi_h2i_set(uf_bp_msg
->mh
, BFI_MC_UF
, BFI_UF_H2I_BUF_POST
,
5385 bfa_fn_lpu(ufm
->bfa
));
5386 bfa_alen_set(&uf_bp_msg
->alen
, buf_len
, ufm_pbs_pa(ufm
, i
));
5390 * advance pointer beyond consumed memory
5392 bfa_mem_kva_curp(ufm
) = (u8
*) uf_bp_msg
;
5396 claim_ufs(struct bfa_uf_mod_s
*ufm
)
5399 struct bfa_uf_s
*uf
;
5402 * Claim block of memory for UF list
5404 ufm
->uf_list
= (struct bfa_uf_s
*) bfa_mem_kva_curp(ufm
);
5407 * Initialize UFs and queue it in UF free queue
5409 for (i
= 0, uf
= ufm
->uf_list
; i
< ufm
->num_ufs
; i
++, uf
++) {
5410 memset(uf
, 0, sizeof(struct bfa_uf_s
));
5413 uf
->pb_len
= BFA_PER_UF_DMA_SZ
;
5414 uf
->buf_kva
= bfa_mem_get_dmabuf_kva(ufm
, i
, BFA_PER_UF_DMA_SZ
);
5415 uf
->buf_pa
= ufm_pbs_pa(ufm
, i
);
5416 list_add_tail(&uf
->qe
, &ufm
->uf_free_q
);
5420 * advance memory pointer
5422 bfa_mem_kva_curp(ufm
) = (u8
*) uf
;
5426 uf_mem_claim(struct bfa_uf_mod_s
*ufm
)
5429 claim_uf_post_msgs(ufm
);
5433 bfa_uf_meminfo(struct bfa_iocfc_cfg_s
*cfg
, struct bfa_meminfo_s
*minfo
,
5436 struct bfa_uf_mod_s
*ufm
= BFA_UF_MOD(bfa
);
5437 struct bfa_mem_kva_s
*uf_kva
= BFA_MEM_UF_KVA(bfa
);
5438 u32 num_ufs
= cfg
->fwcfg
.num_uf_bufs
;
5439 struct bfa_mem_dma_s
*seg_ptr
;
5440 u16 nsegs
, idx
, per_seg_uf
= 0;
5442 nsegs
= BFI_MEM_DMA_NSEGS(num_ufs
, BFA_PER_UF_DMA_SZ
);
5443 per_seg_uf
= BFI_MEM_NREQS_SEG(BFA_PER_UF_DMA_SZ
);
5445 bfa_mem_dma_seg_iter(ufm
, seg_ptr
, nsegs
, idx
) {
5446 if (num_ufs
>= per_seg_uf
) {
5447 num_ufs
-= per_seg_uf
;
5448 bfa_mem_dma_setup(minfo
, seg_ptr
,
5449 per_seg_uf
* BFA_PER_UF_DMA_SZ
);
5451 bfa_mem_dma_setup(minfo
, seg_ptr
,
5452 num_ufs
* BFA_PER_UF_DMA_SZ
);
5456 bfa_mem_kva_setup(minfo
, uf_kva
, cfg
->fwcfg
.num_uf_bufs
*
5457 (sizeof(struct bfa_uf_s
) + sizeof(struct bfi_uf_buf_post_s
)));
5461 bfa_uf_attach(struct bfa_s
*bfa
, void *bfad
, struct bfa_iocfc_cfg_s
*cfg
,
5462 struct bfa_pcidev_s
*pcidev
)
5464 struct bfa_uf_mod_s
*ufm
= BFA_UF_MOD(bfa
);
5467 ufm
->num_ufs
= cfg
->fwcfg
.num_uf_bufs
;
5468 INIT_LIST_HEAD(&ufm
->uf_free_q
);
5469 INIT_LIST_HEAD(&ufm
->uf_posted_q
);
5470 INIT_LIST_HEAD(&ufm
->uf_unused_q
);
5475 static struct bfa_uf_s
*
5476 bfa_uf_get(struct bfa_uf_mod_s
*uf_mod
)
5478 struct bfa_uf_s
*uf
;
5480 bfa_q_deq(&uf_mod
->uf_free_q
, &uf
);
5485 bfa_uf_put(struct bfa_uf_mod_s
*uf_mod
, struct bfa_uf_s
*uf
)
5487 list_add_tail(&uf
->qe
, &uf_mod
->uf_free_q
);
5491 bfa_uf_post(struct bfa_uf_mod_s
*ufm
, struct bfa_uf_s
*uf
)
5493 struct bfi_uf_buf_post_s
*uf_post_msg
;
5495 uf_post_msg
= bfa_reqq_next(ufm
->bfa
, BFA_REQQ_FCXP
);
5497 return BFA_STATUS_FAILED
;
5499 memcpy(uf_post_msg
, &ufm
->uf_buf_posts
[uf
->uf_tag
],
5500 sizeof(struct bfi_uf_buf_post_s
));
5501 bfa_reqq_produce(ufm
->bfa
, BFA_REQQ_FCXP
, uf_post_msg
->mh
);
5503 bfa_trc(ufm
->bfa
, uf
->uf_tag
);
5505 list_add_tail(&uf
->qe
, &ufm
->uf_posted_q
);
5506 return BFA_STATUS_OK
;
5510 bfa_uf_post_all(struct bfa_uf_mod_s
*uf_mod
)
5512 struct bfa_uf_s
*uf
;
5514 while ((uf
= bfa_uf_get(uf_mod
)) != NULL
) {
5515 if (bfa_uf_post(uf_mod
, uf
) != BFA_STATUS_OK
)
5521 uf_recv(struct bfa_s
*bfa
, struct bfi_uf_frm_rcvd_s
*m
)
5523 struct bfa_uf_mod_s
*ufm
= BFA_UF_MOD(bfa
);
5524 u16 uf_tag
= m
->buf_tag
;
5525 struct bfa_uf_s
*uf
= &ufm
->uf_list
[uf_tag
];
5526 struct bfa_uf_buf_s
*uf_buf
;
5528 struct fchs_s
*fchs
;
5530 uf_buf
= (struct bfa_uf_buf_s
*)
5531 bfa_mem_get_dmabuf_kva(ufm
, uf_tag
, uf
->pb_len
);
5532 buf
= &uf_buf
->d
[0];
5534 m
->frm_len
= be16_to_cpu(m
->frm_len
);
5535 m
->xfr_len
= be16_to_cpu(m
->xfr_len
);
5537 fchs
= (struct fchs_s
*)uf_buf
;
5539 list_del(&uf
->qe
); /* dequeue from posted queue */
5542 uf
->data_len
= m
->xfr_len
;
5544 WARN_ON(uf
->data_len
< sizeof(struct fchs_s
));
5546 if (uf
->data_len
== sizeof(struct fchs_s
)) {
5547 bfa_plog_fchdr(bfa
->plog
, BFA_PL_MID_HAL_UF
, BFA_PL_EID_RX
,
5548 uf
->data_len
, (struct fchs_s
*)buf
);
5550 u32 pld_w0
= *((u32
*) (buf
+ sizeof(struct fchs_s
)));
5551 bfa_plog_fchdr_and_pl(bfa
->plog
, BFA_PL_MID_HAL_UF
,
5552 BFA_PL_EID_RX
, uf
->data_len
,
5553 (struct fchs_s
*)buf
, pld_w0
);
5557 __bfa_cb_uf_recv(uf
, BFA_TRUE
);
5559 bfa_cb_queue(bfa
, &uf
->hcb_qe
, __bfa_cb_uf_recv
, uf
);
5563 bfa_uf_iocdisable(struct bfa_s
*bfa
)
5565 struct bfa_uf_mod_s
*ufm
= BFA_UF_MOD(bfa
);
5566 struct bfa_uf_s
*uf
;
5567 struct list_head
*qe
, *qen
;
5569 /* Enqueue unused uf resources to free_q */
5570 list_splice_tail_init(&ufm
->uf_unused_q
, &ufm
->uf_free_q
);
5572 list_for_each_safe(qe
, qen
, &ufm
->uf_posted_q
) {
5573 uf
= (struct bfa_uf_s
*) qe
;
5575 bfa_uf_put(ufm
, uf
);
5580 bfa_uf_start(struct bfa_s
*bfa
)
5582 bfa_uf_post_all(BFA_UF_MOD(bfa
));
5586 * Register handler for all unsolicted receive frames.
5588 * @param[in] bfa BFA instance
5589 * @param[in] ufrecv receive handler function
5590 * @param[in] cbarg receive handler arg
5593 bfa_uf_recv_register(struct bfa_s
*bfa
, bfa_cb_uf_recv_t ufrecv
, void *cbarg
)
5595 struct bfa_uf_mod_s
*ufm
= BFA_UF_MOD(bfa
);
5597 ufm
->ufrecv
= ufrecv
;
5602 * Free an unsolicited frame back to BFA.
5604 * @param[in] uf unsolicited frame to be freed
5609 bfa_uf_free(struct bfa_uf_s
*uf
)
5611 bfa_uf_put(BFA_UF_MOD(uf
->bfa
), uf
);
5612 bfa_uf_post_all(BFA_UF_MOD(uf
->bfa
));
5618 * uf_pub BFA uf module public functions
5621 bfa_uf_isr(struct bfa_s
*bfa
, struct bfi_msg_s
*msg
)
5623 bfa_trc(bfa
, msg
->mhdr
.msg_id
);
5625 switch (msg
->mhdr
.msg_id
) {
5626 case BFI_UF_I2H_FRM_RCVD
:
5627 uf_recv(bfa
, (struct bfi_uf_frm_rcvd_s
*) msg
);
5631 bfa_trc(bfa
, msg
->mhdr
.msg_id
);
5637 bfa_uf_res_recfg(struct bfa_s
*bfa
, u16 num_uf_fw
)
5639 struct bfa_uf_mod_s
*mod
= BFA_UF_MOD(bfa
);
5640 struct list_head
*qe
;
5643 for (i
= 0; i
< (mod
->num_ufs
- num_uf_fw
); i
++) {
5644 bfa_q_deq_tail(&mod
->uf_free_q
, &qe
);
5645 list_add_tail(qe
, &mod
->uf_unused_q
);
5650 * Dport forward declaration
5653 enum bfa_dport_test_state_e
{
5654 BFA_DPORT_ST_DISABLED
= 0, /*!< dport is disabled */
5655 BFA_DPORT_ST_INP
= 1, /*!< test in progress */
5656 BFA_DPORT_ST_COMP
= 2, /*!< test complete successfully */
5657 BFA_DPORT_ST_NO_SFP
= 3, /*!< sfp is not present */
5658 BFA_DPORT_ST_NOTSTART
= 4, /*!< test not start dport is enabled */
5662 * BFA DPORT state machine events
5664 enum bfa_dport_sm_event
{
5665 BFA_DPORT_SM_ENABLE
= 1, /* dport enable event */
5666 BFA_DPORT_SM_DISABLE
= 2, /* dport disable event */
5667 BFA_DPORT_SM_FWRSP
= 3, /* fw enable/disable rsp */
5668 BFA_DPORT_SM_QRESUME
= 4, /* CQ space available */
5669 BFA_DPORT_SM_HWFAIL
= 5, /* IOC h/w failure */
5670 BFA_DPORT_SM_START
= 6, /* re-start dport test */
5671 BFA_DPORT_SM_REQFAIL
= 7, /* request failure */
5672 BFA_DPORT_SM_SCN
= 8, /* state change notify frm fw */
5675 static void bfa_dport_sm_disabled(struct bfa_dport_s
*dport
,
5676 enum bfa_dport_sm_event event
);
5677 static void bfa_dport_sm_enabling_qwait(struct bfa_dport_s
*dport
,
5678 enum bfa_dport_sm_event event
);
5679 static void bfa_dport_sm_enabling(struct bfa_dport_s
*dport
,
5680 enum bfa_dport_sm_event event
);
5681 static void bfa_dport_sm_enabled(struct bfa_dport_s
*dport
,
5682 enum bfa_dport_sm_event event
);
5683 static void bfa_dport_sm_disabling_qwait(struct bfa_dport_s
*dport
,
5684 enum bfa_dport_sm_event event
);
5685 static void bfa_dport_sm_disabling(struct bfa_dport_s
*dport
,
5686 enum bfa_dport_sm_event event
);
5687 static void bfa_dport_sm_starting_qwait(struct bfa_dport_s
*dport
,
5688 enum bfa_dport_sm_event event
);
5689 static void bfa_dport_sm_starting(struct bfa_dport_s
*dport
,
5690 enum bfa_dport_sm_event event
);
5691 static void bfa_dport_sm_dynamic_disabling(struct bfa_dport_s
*dport
,
5692 enum bfa_dport_sm_event event
);
5693 static void bfa_dport_sm_dynamic_disabling_qwait(struct bfa_dport_s
*dport
,
5694 enum bfa_dport_sm_event event
);
5695 static void bfa_dport_qresume(void *cbarg
);
5696 static void bfa_dport_req_comp(struct bfa_dport_s
*dport
,
5697 struct bfi_diag_dport_rsp_s
*msg
);
5698 static void bfa_dport_scn(struct bfa_dport_s
*dport
,
5699 struct bfi_diag_dport_scn_s
*msg
);
5704 #define BFA_DIAG_QTEST_TOV 1000 /* msec */
5707 * Set port status to busy
5710 bfa_fcdiag_set_busy_status(struct bfa_fcdiag_s
*fcdiag
)
5712 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(fcdiag
->bfa
);
5714 if (fcdiag
->lb
.lock
)
5715 fcport
->diag_busy
= BFA_TRUE
;
5717 fcport
->diag_busy
= BFA_FALSE
;
5721 bfa_fcdiag_attach(struct bfa_s
*bfa
, void *bfad
, struct bfa_iocfc_cfg_s
*cfg
,
5722 struct bfa_pcidev_s
*pcidev
)
5724 struct bfa_fcdiag_s
*fcdiag
= BFA_FCDIAG_MOD(bfa
);
5725 struct bfa_dport_s
*dport
= &fcdiag
->dport
;
5728 fcdiag
->trcmod
= bfa
->trcmod
;
5729 /* The common DIAG attach bfa_diag_attach() will do all memory claim */
5731 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
5732 bfa_reqq_winit(&dport
->reqq_wait
, bfa_dport_qresume
, dport
);
5734 dport
->cbarg
= NULL
;
5735 dport
->test_state
= BFA_DPORT_ST_DISABLED
;
5736 memset(&dport
->result
, 0, sizeof(struct bfa_diag_dport_result_s
));
5740 bfa_fcdiag_iocdisable(struct bfa_s
*bfa
)
5742 struct bfa_fcdiag_s
*fcdiag
= BFA_FCDIAG_MOD(bfa
);
5743 struct bfa_dport_s
*dport
= &fcdiag
->dport
;
5745 bfa_trc(fcdiag
, fcdiag
->lb
.lock
);
5746 if (fcdiag
->lb
.lock
) {
5747 fcdiag
->lb
.status
= BFA_STATUS_IOC_FAILURE
;
5748 fcdiag
->lb
.cbfn(fcdiag
->lb
.cbarg
, fcdiag
->lb
.status
);
5749 fcdiag
->lb
.lock
= 0;
5750 bfa_fcdiag_set_busy_status(fcdiag
);
5753 bfa_sm_send_event(dport
, BFA_DPORT_SM_HWFAIL
);
5757 bfa_fcdiag_queuetest_timeout(void *cbarg
)
5759 struct bfa_fcdiag_s
*fcdiag
= cbarg
;
5760 struct bfa_diag_qtest_result_s
*res
= fcdiag
->qtest
.result
;
5762 bfa_trc(fcdiag
, fcdiag
->qtest
.all
);
5763 bfa_trc(fcdiag
, fcdiag
->qtest
.count
);
5765 fcdiag
->qtest
.timer_active
= 0;
5767 res
->status
= BFA_STATUS_ETIMER
;
5768 res
->count
= QTEST_CNT_DEFAULT
- fcdiag
->qtest
.count
;
5769 if (fcdiag
->qtest
.all
)
5770 res
->queue
= fcdiag
->qtest
.all
;
5772 bfa_trc(fcdiag
, BFA_STATUS_ETIMER
);
5773 fcdiag
->qtest
.status
= BFA_STATUS_ETIMER
;
5774 fcdiag
->qtest
.cbfn(fcdiag
->qtest
.cbarg
, fcdiag
->qtest
.status
);
5775 fcdiag
->qtest
.lock
= 0;
5779 bfa_fcdiag_queuetest_send(struct bfa_fcdiag_s
*fcdiag
)
5782 struct bfi_diag_qtest_req_s
*req
;
5784 req
= bfa_reqq_next(fcdiag
->bfa
, fcdiag
->qtest
.queue
);
5786 return BFA_STATUS_DEVBUSY
;
5788 /* build host command */
5789 bfi_h2i_set(req
->mh
, BFI_MC_DIAG
, BFI_DIAG_H2I_QTEST
,
5790 bfa_fn_lpu(fcdiag
->bfa
));
5792 for (i
= 0; i
< BFI_LMSG_PL_WSZ
; i
++)
5793 req
->data
[i
] = QTEST_PAT_DEFAULT
;
5795 bfa_trc(fcdiag
, fcdiag
->qtest
.queue
);
5796 /* ring door bell */
5797 bfa_reqq_produce(fcdiag
->bfa
, fcdiag
->qtest
.queue
, req
->mh
);
5798 return BFA_STATUS_OK
;
5802 bfa_fcdiag_queuetest_comp(struct bfa_fcdiag_s
*fcdiag
,
5803 bfi_diag_qtest_rsp_t
*rsp
)
5805 struct bfa_diag_qtest_result_s
*res
= fcdiag
->qtest
.result
;
5806 bfa_status_t status
= BFA_STATUS_OK
;
5809 /* Check timer, should still be active */
5810 if (!fcdiag
->qtest
.timer_active
) {
5811 bfa_trc(fcdiag
, fcdiag
->qtest
.timer_active
);
5816 fcdiag
->qtest
.count
--;
5819 for (i
= 0; i
< BFI_LMSG_PL_WSZ
; i
++) {
5820 if (rsp
->data
[i
] != ~(QTEST_PAT_DEFAULT
)) {
5821 res
->status
= BFA_STATUS_DATACORRUPTED
;
5826 if (res
->status
== BFA_STATUS_OK
) {
5827 if (fcdiag
->qtest
.count
> 0) {
5828 status
= bfa_fcdiag_queuetest_send(fcdiag
);
5829 if (status
== BFA_STATUS_OK
)
5832 res
->status
= status
;
5833 } else if (fcdiag
->qtest
.all
> 0 &&
5834 fcdiag
->qtest
.queue
< (BFI_IOC_MAX_CQS
- 1)) {
5835 fcdiag
->qtest
.count
= QTEST_CNT_DEFAULT
;
5836 fcdiag
->qtest
.queue
++;
5837 status
= bfa_fcdiag_queuetest_send(fcdiag
);
5838 if (status
== BFA_STATUS_OK
)
5841 res
->status
= status
;
5845 /* Stop timer when we comp all queue */
5846 if (fcdiag
->qtest
.timer_active
) {
5847 bfa_timer_stop(&fcdiag
->qtest
.timer
);
5848 fcdiag
->qtest
.timer_active
= 0;
5850 res
->queue
= fcdiag
->qtest
.queue
;
5851 res
->count
= QTEST_CNT_DEFAULT
- fcdiag
->qtest
.count
;
5852 bfa_trc(fcdiag
, res
->count
);
5853 bfa_trc(fcdiag
, res
->status
);
5854 fcdiag
->qtest
.status
= res
->status
;
5855 fcdiag
->qtest
.cbfn(fcdiag
->qtest
.cbarg
, fcdiag
->qtest
.status
);
5856 fcdiag
->qtest
.lock
= 0;
5860 bfa_fcdiag_loopback_comp(struct bfa_fcdiag_s
*fcdiag
,
5861 struct bfi_diag_lb_rsp_s
*rsp
)
5863 struct bfa_diag_loopback_result_s
*res
= fcdiag
->lb
.result
;
5865 res
->numtxmfrm
= be32_to_cpu(rsp
->res
.numtxmfrm
);
5866 res
->numosffrm
= be32_to_cpu(rsp
->res
.numosffrm
);
5867 res
->numrcvfrm
= be32_to_cpu(rsp
->res
.numrcvfrm
);
5868 res
->badfrminf
= be32_to_cpu(rsp
->res
.badfrminf
);
5869 res
->badfrmnum
= be32_to_cpu(rsp
->res
.badfrmnum
);
5870 res
->status
= rsp
->res
.status
;
5871 fcdiag
->lb
.status
= rsp
->res
.status
;
5872 bfa_trc(fcdiag
, fcdiag
->lb
.status
);
5873 fcdiag
->lb
.cbfn(fcdiag
->lb
.cbarg
, fcdiag
->lb
.status
);
5874 fcdiag
->lb
.lock
= 0;
5875 bfa_fcdiag_set_busy_status(fcdiag
);
5879 bfa_fcdiag_loopback_send(struct bfa_fcdiag_s
*fcdiag
,
5880 struct bfa_diag_loopback_s
*loopback
)
5882 struct bfi_diag_lb_req_s
*lb_req
;
5884 lb_req
= bfa_reqq_next(fcdiag
->bfa
, BFA_REQQ_DIAG
);
5886 return BFA_STATUS_DEVBUSY
;
5888 /* build host command */
5889 bfi_h2i_set(lb_req
->mh
, BFI_MC_DIAG
, BFI_DIAG_H2I_LOOPBACK
,
5890 bfa_fn_lpu(fcdiag
->bfa
));
5892 lb_req
->lb_mode
= loopback
->lb_mode
;
5893 lb_req
->speed
= loopback
->speed
;
5894 lb_req
->loopcnt
= loopback
->loopcnt
;
5895 lb_req
->pattern
= loopback
->pattern
;
5897 /* ring door bell */
5898 bfa_reqq_produce(fcdiag
->bfa
, BFA_REQQ_DIAG
, lb_req
->mh
);
5900 bfa_trc(fcdiag
, loopback
->lb_mode
);
5901 bfa_trc(fcdiag
, loopback
->speed
);
5902 bfa_trc(fcdiag
, loopback
->loopcnt
);
5903 bfa_trc(fcdiag
, loopback
->pattern
);
5904 return BFA_STATUS_OK
;
5908 * cpe/rme intr handler
5911 bfa_fcdiag_intr(struct bfa_s
*bfa
, struct bfi_msg_s
*msg
)
5913 struct bfa_fcdiag_s
*fcdiag
= BFA_FCDIAG_MOD(bfa
);
5915 switch (msg
->mhdr
.msg_id
) {
5916 case BFI_DIAG_I2H_LOOPBACK
:
5917 bfa_fcdiag_loopback_comp(fcdiag
,
5918 (struct bfi_diag_lb_rsp_s
*) msg
);
5920 case BFI_DIAG_I2H_QTEST
:
5921 bfa_fcdiag_queuetest_comp(fcdiag
, (bfi_diag_qtest_rsp_t
*)msg
);
5923 case BFI_DIAG_I2H_DPORT
:
5924 bfa_dport_req_comp(&fcdiag
->dport
,
5925 (struct bfi_diag_dport_rsp_s
*)msg
);
5927 case BFI_DIAG_I2H_DPORT_SCN
:
5928 bfa_dport_scn(&fcdiag
->dport
,
5929 (struct bfi_diag_dport_scn_s
*)msg
);
5932 bfa_trc(fcdiag
, msg
->mhdr
.msg_id
);
5940 * @param[in] *bfa - bfa data struct
5941 * @param[in] opmode - port operation mode
5942 * @param[in] speed - port speed
5943 * @param[in] lpcnt - loop count
5944 * @param[in] pat - pattern to build packet
5945 * @param[in] *result - pt to bfa_diag_loopback_result_t data struct
5946 * @param[in] cbfn - callback function
5947 * @param[in] cbarg - callback functioin arg
5952 bfa_fcdiag_loopback(struct bfa_s
*bfa
, enum bfa_port_opmode opmode
,
5953 enum bfa_port_speed speed
, u32 lpcnt
, u32 pat
,
5954 struct bfa_diag_loopback_result_s
*result
, bfa_cb_diag_t cbfn
,
5957 struct bfa_diag_loopback_s loopback
;
5958 struct bfa_port_attr_s attr
;
5959 bfa_status_t status
;
5960 struct bfa_fcdiag_s
*fcdiag
= BFA_FCDIAG_MOD(bfa
);
5962 if (!bfa_iocfc_is_operational(bfa
))
5963 return BFA_STATUS_IOC_NON_OP
;
5965 /* if port is PBC disabled, return error */
5966 if (bfa_fcport_is_pbcdisabled(bfa
)) {
5967 bfa_trc(fcdiag
, BFA_STATUS_PBC
);
5968 return BFA_STATUS_PBC
;
5971 if (bfa_fcport_is_disabled(bfa
) == BFA_FALSE
) {
5972 bfa_trc(fcdiag
, opmode
);
5973 return BFA_STATUS_PORT_NOT_DISABLED
;
5977 * Check if input speed is supported by the port mode
5979 if (bfa_ioc_get_type(&bfa
->ioc
) == BFA_IOC_TYPE_FC
) {
5980 if (!(speed
== BFA_PORT_SPEED_1GBPS
||
5981 speed
== BFA_PORT_SPEED_2GBPS
||
5982 speed
== BFA_PORT_SPEED_4GBPS
||
5983 speed
== BFA_PORT_SPEED_8GBPS
||
5984 speed
== BFA_PORT_SPEED_16GBPS
||
5985 speed
== BFA_PORT_SPEED_AUTO
)) {
5986 bfa_trc(fcdiag
, speed
);
5987 return BFA_STATUS_UNSUPP_SPEED
;
5989 bfa_fcport_get_attr(bfa
, &attr
);
5990 bfa_trc(fcdiag
, attr
.speed_supported
);
5991 if (speed
> attr
.speed_supported
)
5992 return BFA_STATUS_UNSUPP_SPEED
;
5994 if (speed
!= BFA_PORT_SPEED_10GBPS
) {
5995 bfa_trc(fcdiag
, speed
);
5996 return BFA_STATUS_UNSUPP_SPEED
;
6001 * For CT2, 1G is not supported
6003 if ((speed
== BFA_PORT_SPEED_1GBPS
) &&
6004 (bfa_asic_id_ct2(bfa
->ioc
.pcidev
.device_id
))) {
6005 bfa_trc(fcdiag
, speed
);
6006 return BFA_STATUS_UNSUPP_SPEED
;
6009 /* For Mezz card, port speed entered needs to be checked */
6010 if (bfa_mfg_is_mezz(bfa
->ioc
.attr
->card_type
)) {
6011 if (bfa_ioc_get_type(&bfa
->ioc
) == BFA_IOC_TYPE_FC
) {
6012 if (!(speed
== BFA_PORT_SPEED_1GBPS
||
6013 speed
== BFA_PORT_SPEED_2GBPS
||
6014 speed
== BFA_PORT_SPEED_4GBPS
||
6015 speed
== BFA_PORT_SPEED_8GBPS
||
6016 speed
== BFA_PORT_SPEED_16GBPS
||
6017 speed
== BFA_PORT_SPEED_AUTO
))
6018 return BFA_STATUS_UNSUPP_SPEED
;
6020 if (speed
!= BFA_PORT_SPEED_10GBPS
)
6021 return BFA_STATUS_UNSUPP_SPEED
;
6024 /* check to see if fcport is dport */
6025 if (bfa_fcport_is_dport(bfa
)) {
6026 bfa_trc(fcdiag
, fcdiag
->lb
.lock
);
6027 return BFA_STATUS_DPORT_ENABLED
;
6029 /* check to see if there is another destructive diag cmd running */
6030 if (fcdiag
->lb
.lock
) {
6031 bfa_trc(fcdiag
, fcdiag
->lb
.lock
);
6032 return BFA_STATUS_DEVBUSY
;
6035 fcdiag
->lb
.lock
= 1;
6036 loopback
.lb_mode
= opmode
;
6037 loopback
.speed
= speed
;
6038 loopback
.loopcnt
= lpcnt
;
6039 loopback
.pattern
= pat
;
6040 fcdiag
->lb
.result
= result
;
6041 fcdiag
->lb
.cbfn
= cbfn
;
6042 fcdiag
->lb
.cbarg
= cbarg
;
6043 memset(result
, 0, sizeof(struct bfa_diag_loopback_result_s
));
6044 bfa_fcdiag_set_busy_status(fcdiag
);
6046 /* Send msg to fw */
6047 status
= bfa_fcdiag_loopback_send(fcdiag
, &loopback
);
6052 * DIAG queue test command
6054 * @param[in] *bfa - bfa data struct
6055 * @param[in] force - 1: don't do ioc op checking
6056 * @param[in] queue - queue no. to test
6057 * @param[in] *result - pt to bfa_diag_qtest_result_t data struct
6058 * @param[in] cbfn - callback function
6059 * @param[in] *cbarg - callback functioin arg
6064 bfa_fcdiag_queuetest(struct bfa_s
*bfa
, u32 force
, u32 queue
,
6065 struct bfa_diag_qtest_result_s
*result
, bfa_cb_diag_t cbfn
,
6068 struct bfa_fcdiag_s
*fcdiag
= BFA_FCDIAG_MOD(bfa
);
6069 bfa_status_t status
;
6070 bfa_trc(fcdiag
, force
);
6071 bfa_trc(fcdiag
, queue
);
6073 if (!force
&& !bfa_iocfc_is_operational(bfa
))
6074 return BFA_STATUS_IOC_NON_OP
;
6076 /* check to see if there is another destructive diag cmd running */
6077 if (fcdiag
->qtest
.lock
) {
6078 bfa_trc(fcdiag
, fcdiag
->qtest
.lock
);
6079 return BFA_STATUS_DEVBUSY
;
6082 /* Initialization */
6083 fcdiag
->qtest
.lock
= 1;
6084 fcdiag
->qtest
.cbfn
= cbfn
;
6085 fcdiag
->qtest
.cbarg
= cbarg
;
6086 fcdiag
->qtest
.result
= result
;
6087 fcdiag
->qtest
.count
= QTEST_CNT_DEFAULT
;
6089 /* Init test results */
6090 fcdiag
->qtest
.result
->status
= BFA_STATUS_OK
;
6091 fcdiag
->qtest
.result
->count
= 0;
6094 if (queue
< BFI_IOC_MAX_CQS
) {
6095 fcdiag
->qtest
.result
->queue
= (u8
)queue
;
6096 fcdiag
->qtest
.queue
= (u8
)queue
;
6097 fcdiag
->qtest
.all
= 0;
6099 fcdiag
->qtest
.result
->queue
= 0;
6100 fcdiag
->qtest
.queue
= 0;
6101 fcdiag
->qtest
.all
= 1;
6103 status
= bfa_fcdiag_queuetest_send(fcdiag
);
6106 if (status
== BFA_STATUS_OK
) {
6107 bfa_timer_start(bfa
, &fcdiag
->qtest
.timer
,
6108 bfa_fcdiag_queuetest_timeout
, fcdiag
,
6109 BFA_DIAG_QTEST_TOV
);
6110 fcdiag
->qtest
.timer_active
= 1;
6116 * DIAG PLB is running
6118 * @param[in] *bfa - bfa data struct
6123 bfa_fcdiag_lb_is_running(struct bfa_s
*bfa
)
6125 struct bfa_fcdiag_s
*fcdiag
= BFA_FCDIAG_MOD(bfa
);
6126 return fcdiag
->lb
.lock
? BFA_STATUS_DIAG_BUSY
: BFA_STATUS_OK
;
6132 #define bfa_dport_result_start(__dport, __mode) do { \
6133 (__dport)->result.start_time = ktime_get_real_seconds(); \
6134 (__dport)->result.status = DPORT_TEST_ST_INPRG; \
6135 (__dport)->result.mode = (__mode); \
6136 (__dport)->result.rp_pwwn = (__dport)->rp_pwwn; \
6137 (__dport)->result.rp_nwwn = (__dport)->rp_nwwn; \
6138 (__dport)->result.lpcnt = (__dport)->lpcnt; \
6141 static bfa_boolean_t
bfa_dport_send_req(struct bfa_dport_s
*dport
,
6142 enum bfi_dport_req req
);
6144 bfa_cb_fcdiag_dport(struct bfa_dport_s
*dport
, bfa_status_t bfa_status
)
6146 if (dport
->cbfn
!= NULL
) {
6147 dport
->cbfn(dport
->cbarg
, bfa_status
);
6149 dport
->cbarg
= NULL
;
6154 bfa_dport_sm_disabled(struct bfa_dport_s
*dport
, enum bfa_dport_sm_event event
)
6156 bfa_trc(dport
->bfa
, event
);
6159 case BFA_DPORT_SM_ENABLE
:
6160 bfa_fcport_dportenable(dport
->bfa
);
6161 if (bfa_dport_send_req(dport
, BFI_DPORT_ENABLE
))
6162 bfa_sm_set_state(dport
, bfa_dport_sm_enabling
);
6164 bfa_sm_set_state(dport
, bfa_dport_sm_enabling_qwait
);
6167 case BFA_DPORT_SM_DISABLE
:
6168 /* Already disabled */
6171 case BFA_DPORT_SM_HWFAIL
:
6175 case BFA_DPORT_SM_SCN
:
6176 if (dport
->i2hmsg
.scn
.state
== BFI_DPORT_SCN_DDPORT_ENABLE
) {
6177 bfa_fcport_ddportenable(dport
->bfa
);
6178 dport
->dynamic
= BFA_TRUE
;
6179 dport
->test_state
= BFA_DPORT_ST_NOTSTART
;
6180 bfa_sm_set_state(dport
, bfa_dport_sm_enabled
);
6182 bfa_trc(dport
->bfa
, dport
->i2hmsg
.scn
.state
);
6188 bfa_sm_fault(dport
->bfa
, event
);
6193 bfa_dport_sm_enabling_qwait(struct bfa_dport_s
*dport
,
6194 enum bfa_dport_sm_event event
)
6196 bfa_trc(dport
->bfa
, event
);
6199 case BFA_DPORT_SM_QRESUME
:
6200 bfa_sm_set_state(dport
, bfa_dport_sm_enabling
);
6201 bfa_dport_send_req(dport
, BFI_DPORT_ENABLE
);
6204 case BFA_DPORT_SM_HWFAIL
:
6205 bfa_reqq_wcancel(&dport
->reqq_wait
);
6206 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
6207 bfa_cb_fcdiag_dport(dport
, BFA_STATUS_FAILED
);
6211 bfa_sm_fault(dport
->bfa
, event
);
6216 bfa_dport_sm_enabling(struct bfa_dport_s
*dport
, enum bfa_dport_sm_event event
)
6218 bfa_trc(dport
->bfa
, event
);
6221 case BFA_DPORT_SM_FWRSP
:
6222 memset(&dport
->result
, 0,
6223 sizeof(struct bfa_diag_dport_result_s
));
6224 if (dport
->i2hmsg
.rsp
.status
== BFA_STATUS_DPORT_INV_SFP
) {
6225 dport
->test_state
= BFA_DPORT_ST_NO_SFP
;
6227 dport
->test_state
= BFA_DPORT_ST_INP
;
6228 bfa_dport_result_start(dport
, BFA_DPORT_OPMODE_AUTO
);
6230 bfa_sm_set_state(dport
, bfa_dport_sm_enabled
);
6233 case BFA_DPORT_SM_REQFAIL
:
6234 dport
->test_state
= BFA_DPORT_ST_DISABLED
;
6235 bfa_fcport_dportdisable(dport
->bfa
);
6236 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
6239 case BFA_DPORT_SM_HWFAIL
:
6240 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
6241 bfa_cb_fcdiag_dport(dport
, BFA_STATUS_FAILED
);
6245 bfa_sm_fault(dport
->bfa
, event
);
6250 bfa_dport_sm_enabled(struct bfa_dport_s
*dport
, enum bfa_dport_sm_event event
)
6252 bfa_trc(dport
->bfa
, event
);
6255 case BFA_DPORT_SM_START
:
6256 if (bfa_dport_send_req(dport
, BFI_DPORT_START
))
6257 bfa_sm_set_state(dport
, bfa_dport_sm_starting
);
6259 bfa_sm_set_state(dport
, bfa_dport_sm_starting_qwait
);
6262 case BFA_DPORT_SM_DISABLE
:
6263 bfa_fcport_dportdisable(dport
->bfa
);
6264 if (bfa_dport_send_req(dport
, BFI_DPORT_DISABLE
))
6265 bfa_sm_set_state(dport
, bfa_dport_sm_disabling
);
6267 bfa_sm_set_state(dport
, bfa_dport_sm_disabling_qwait
);
6270 case BFA_DPORT_SM_HWFAIL
:
6271 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
6274 case BFA_DPORT_SM_SCN
:
6275 switch (dport
->i2hmsg
.scn
.state
) {
6276 case BFI_DPORT_SCN_TESTCOMP
:
6277 dport
->test_state
= BFA_DPORT_ST_COMP
;
6280 case BFI_DPORT_SCN_TESTSTART
:
6281 dport
->test_state
= BFA_DPORT_ST_INP
;
6284 case BFI_DPORT_SCN_TESTSKIP
:
6285 case BFI_DPORT_SCN_SUBTESTSTART
:
6286 /* no state change */
6289 case BFI_DPORT_SCN_SFP_REMOVED
:
6290 dport
->test_state
= BFA_DPORT_ST_NO_SFP
;
6293 case BFI_DPORT_SCN_DDPORT_DISABLE
:
6294 bfa_fcport_ddportdisable(dport
->bfa
);
6296 if (bfa_dport_send_req(dport
, BFI_DPORT_DYN_DISABLE
))
6297 bfa_sm_set_state(dport
,
6298 bfa_dport_sm_dynamic_disabling
);
6300 bfa_sm_set_state(dport
,
6301 bfa_dport_sm_dynamic_disabling_qwait
);
6304 case BFI_DPORT_SCN_FCPORT_DISABLE
:
6305 bfa_fcport_ddportdisable(dport
->bfa
);
6307 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
6308 dport
->dynamic
= BFA_FALSE
;
6312 bfa_trc(dport
->bfa
, dport
->i2hmsg
.scn
.state
);
6313 bfa_sm_fault(dport
->bfa
, event
);
6317 bfa_sm_fault(dport
->bfa
, event
);
6322 bfa_dport_sm_disabling_qwait(struct bfa_dport_s
*dport
,
6323 enum bfa_dport_sm_event event
)
6325 bfa_trc(dport
->bfa
, event
);
6328 case BFA_DPORT_SM_QRESUME
:
6329 bfa_sm_set_state(dport
, bfa_dport_sm_disabling
);
6330 bfa_dport_send_req(dport
, BFI_DPORT_DISABLE
);
6333 case BFA_DPORT_SM_HWFAIL
:
6334 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
6335 bfa_reqq_wcancel(&dport
->reqq_wait
);
6336 bfa_cb_fcdiag_dport(dport
, BFA_STATUS_OK
);
6339 case BFA_DPORT_SM_SCN
:
6344 bfa_sm_fault(dport
->bfa
, event
);
6349 bfa_dport_sm_disabling(struct bfa_dport_s
*dport
, enum bfa_dport_sm_event event
)
6351 bfa_trc(dport
->bfa
, event
);
6354 case BFA_DPORT_SM_FWRSP
:
6355 dport
->test_state
= BFA_DPORT_ST_DISABLED
;
6356 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
6359 case BFA_DPORT_SM_HWFAIL
:
6360 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
6361 bfa_cb_fcdiag_dport(dport
, BFA_STATUS_OK
);
6364 case BFA_DPORT_SM_SCN
:
6365 /* no state change */
6369 bfa_sm_fault(dport
->bfa
, event
);
6374 bfa_dport_sm_starting_qwait(struct bfa_dport_s
*dport
,
6375 enum bfa_dport_sm_event event
)
6377 bfa_trc(dport
->bfa
, event
);
6380 case BFA_DPORT_SM_QRESUME
:
6381 bfa_sm_set_state(dport
, bfa_dport_sm_starting
);
6382 bfa_dport_send_req(dport
, BFI_DPORT_START
);
6385 case BFA_DPORT_SM_HWFAIL
:
6386 bfa_reqq_wcancel(&dport
->reqq_wait
);
6387 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
6388 bfa_cb_fcdiag_dport(dport
, BFA_STATUS_FAILED
);
6392 bfa_sm_fault(dport
->bfa
, event
);
6397 bfa_dport_sm_starting(struct bfa_dport_s
*dport
, enum bfa_dport_sm_event event
)
6399 bfa_trc(dport
->bfa
, event
);
6402 case BFA_DPORT_SM_FWRSP
:
6403 memset(&dport
->result
, 0,
6404 sizeof(struct bfa_diag_dport_result_s
));
6405 if (dport
->i2hmsg
.rsp
.status
== BFA_STATUS_DPORT_INV_SFP
) {
6406 dport
->test_state
= BFA_DPORT_ST_NO_SFP
;
6408 dport
->test_state
= BFA_DPORT_ST_INP
;
6409 bfa_dport_result_start(dport
, BFA_DPORT_OPMODE_MANU
);
6413 case BFA_DPORT_SM_REQFAIL
:
6414 bfa_sm_set_state(dport
, bfa_dport_sm_enabled
);
6417 case BFA_DPORT_SM_HWFAIL
:
6418 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
6419 bfa_cb_fcdiag_dport(dport
, BFA_STATUS_FAILED
);
6423 bfa_sm_fault(dport
->bfa
, event
);
6428 bfa_dport_sm_dynamic_disabling(struct bfa_dport_s
*dport
,
6429 enum bfa_dport_sm_event event
)
6431 bfa_trc(dport
->bfa
, event
);
6434 case BFA_DPORT_SM_SCN
:
6435 switch (dport
->i2hmsg
.scn
.state
) {
6436 case BFI_DPORT_SCN_DDPORT_DISABLED
:
6437 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
6438 dport
->dynamic
= BFA_FALSE
;
6439 bfa_fcport_enable(dport
->bfa
);
6443 bfa_trc(dport
->bfa
, dport
->i2hmsg
.scn
.state
);
6444 bfa_sm_fault(dport
->bfa
, event
);
6449 case BFA_DPORT_SM_HWFAIL
:
6450 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
6451 bfa_cb_fcdiag_dport(dport
, BFA_STATUS_OK
);
6455 bfa_sm_fault(dport
->bfa
, event
);
6460 bfa_dport_sm_dynamic_disabling_qwait(struct bfa_dport_s
*dport
,
6461 enum bfa_dport_sm_event event
)
6463 bfa_trc(dport
->bfa
, event
);
6466 case BFA_DPORT_SM_QRESUME
:
6467 bfa_sm_set_state(dport
, bfa_dport_sm_dynamic_disabling
);
6468 bfa_dport_send_req(dport
, BFI_DPORT_DYN_DISABLE
);
6471 case BFA_DPORT_SM_HWFAIL
:
6472 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
6473 bfa_reqq_wcancel(&dport
->reqq_wait
);
6474 bfa_cb_fcdiag_dport(dport
, BFA_STATUS_OK
);
6477 case BFA_DPORT_SM_SCN
:
6482 bfa_sm_fault(dport
->bfa
, event
);
6486 static bfa_boolean_t
6487 bfa_dport_send_req(struct bfa_dport_s
*dport
, enum bfi_dport_req req
)
6489 struct bfi_diag_dport_req_s
*m
;
6492 * check for room in queue to send request now
6494 m
= bfa_reqq_next(dport
->bfa
, BFA_REQQ_DIAG
);
6496 bfa_reqq_wait(dport
->bfa
, BFA_REQQ_PORT
, &dport
->reqq_wait
);
6500 bfi_h2i_set(m
->mh
, BFI_MC_DIAG
, BFI_DIAG_H2I_DPORT
,
6501 bfa_fn_lpu(dport
->bfa
));
6503 if ((req
== BFI_DPORT_ENABLE
) || (req
== BFI_DPORT_START
)) {
6504 m
->lpcnt
= cpu_to_be32(dport
->lpcnt
);
6505 m
->payload
= cpu_to_be32(dport
->payload
);
6509 * queue I/O message to firmware
6511 bfa_reqq_produce(dport
->bfa
, BFA_REQQ_DIAG
, m
->mh
);
6517 bfa_dport_qresume(void *cbarg
)
6519 struct bfa_dport_s
*dport
= cbarg
;
6521 bfa_sm_send_event(dport
, BFA_DPORT_SM_QRESUME
);
6525 bfa_dport_req_comp(struct bfa_dport_s
*dport
, struct bfi_diag_dport_rsp_s
*msg
)
6527 msg
->status
= cpu_to_be32(msg
->status
);
6528 dport
->i2hmsg
.rsp
.status
= msg
->status
;
6529 dport
->rp_pwwn
= msg
->pwwn
;
6530 dport
->rp_nwwn
= msg
->nwwn
;
6532 if ((msg
->status
== BFA_STATUS_OK
) ||
6533 (msg
->status
== BFA_STATUS_DPORT_NO_SFP
)) {
6534 bfa_trc(dport
->bfa
, msg
->status
);
6535 bfa_trc(dport
->bfa
, dport
->rp_pwwn
);
6536 bfa_trc(dport
->bfa
, dport
->rp_nwwn
);
6537 bfa_sm_send_event(dport
, BFA_DPORT_SM_FWRSP
);
6540 bfa_trc(dport
->bfa
, msg
->status
);
6541 bfa_sm_send_event(dport
, BFA_DPORT_SM_REQFAIL
);
6543 bfa_cb_fcdiag_dport(dport
, msg
->status
);
6546 static bfa_boolean_t
6547 bfa_dport_is_sending_req(struct bfa_dport_s
*dport
)
6549 if (bfa_sm_cmp_state(dport
, bfa_dport_sm_enabling
) ||
6550 bfa_sm_cmp_state(dport
, bfa_dport_sm_enabling_qwait
) ||
6551 bfa_sm_cmp_state(dport
, bfa_dport_sm_disabling
) ||
6552 bfa_sm_cmp_state(dport
, bfa_dport_sm_disabling_qwait
) ||
6553 bfa_sm_cmp_state(dport
, bfa_dport_sm_starting
) ||
6554 bfa_sm_cmp_state(dport
, bfa_dport_sm_starting_qwait
)) {
6562 bfa_dport_scn(struct bfa_dport_s
*dport
, struct bfi_diag_dport_scn_s
*msg
)
6565 uint8_t subtesttype
;
6567 bfa_trc(dport
->bfa
, msg
->state
);
6568 dport
->i2hmsg
.scn
.state
= msg
->state
;
6570 switch (dport
->i2hmsg
.scn
.state
) {
6571 case BFI_DPORT_SCN_TESTCOMP
:
6572 dport
->result
.end_time
= ktime_get_real_seconds();
6573 bfa_trc(dport
->bfa
, dport
->result
.end_time
);
6575 dport
->result
.status
= msg
->info
.testcomp
.status
;
6576 bfa_trc(dport
->bfa
, dport
->result
.status
);
6578 dport
->result
.roundtrip_latency
=
6579 cpu_to_be32(msg
->info
.testcomp
.latency
);
6580 dport
->result
.est_cable_distance
=
6581 cpu_to_be32(msg
->info
.testcomp
.distance
);
6582 dport
->result
.buffer_required
=
6583 be16_to_cpu(msg
->info
.testcomp
.numbuffer
);
6585 dport
->result
.frmsz
= be16_to_cpu(msg
->info
.testcomp
.frm_sz
);
6586 dport
->result
.speed
= msg
->info
.testcomp
.speed
;
6588 bfa_trc(dport
->bfa
, dport
->result
.roundtrip_latency
);
6589 bfa_trc(dport
->bfa
, dport
->result
.est_cable_distance
);
6590 bfa_trc(dport
->bfa
, dport
->result
.buffer_required
);
6591 bfa_trc(dport
->bfa
, dport
->result
.frmsz
);
6592 bfa_trc(dport
->bfa
, dport
->result
.speed
);
6594 for (i
= DPORT_TEST_ELOOP
; i
< DPORT_TEST_MAX
; i
++) {
6595 dport
->result
.subtest
[i
].status
=
6596 msg
->info
.testcomp
.subtest_status
[i
];
6597 bfa_trc(dport
->bfa
, dport
->result
.subtest
[i
].status
);
6601 case BFI_DPORT_SCN_TESTSKIP
:
6602 case BFI_DPORT_SCN_DDPORT_ENABLE
:
6603 memset(&dport
->result
, 0,
6604 sizeof(struct bfa_diag_dport_result_s
));
6607 case BFI_DPORT_SCN_TESTSTART
:
6608 memset(&dport
->result
, 0,
6609 sizeof(struct bfa_diag_dport_result_s
));
6610 dport
->rp_pwwn
= msg
->info
.teststart
.pwwn
;
6611 dport
->rp_nwwn
= msg
->info
.teststart
.nwwn
;
6612 dport
->lpcnt
= cpu_to_be32(msg
->info
.teststart
.numfrm
);
6613 bfa_dport_result_start(dport
, msg
->info
.teststart
.mode
);
6616 case BFI_DPORT_SCN_SUBTESTSTART
:
6617 subtesttype
= msg
->info
.teststart
.type
;
6618 dport
->result
.subtest
[subtesttype
].start_time
=
6619 ktime_get_real_seconds();
6620 dport
->result
.subtest
[subtesttype
].status
=
6621 DPORT_TEST_ST_INPRG
;
6623 bfa_trc(dport
->bfa
, subtesttype
);
6625 dport
->result
.subtest
[subtesttype
].start_time
);
6628 case BFI_DPORT_SCN_SFP_REMOVED
:
6629 case BFI_DPORT_SCN_DDPORT_DISABLED
:
6630 case BFI_DPORT_SCN_DDPORT_DISABLE
:
6631 case BFI_DPORT_SCN_FCPORT_DISABLE
:
6632 dport
->result
.status
= DPORT_TEST_ST_IDLE
;
6636 bfa_sm_fault(dport
->bfa
, msg
->state
);
6639 bfa_sm_send_event(dport
, BFA_DPORT_SM_SCN
);
6645 * @param[in] *bfa - bfa data struct
6648 bfa_dport_enable(struct bfa_s
*bfa
, u32 lpcnt
, u32 pat
,
6649 bfa_cb_diag_t cbfn
, void *cbarg
)
6651 struct bfa_fcdiag_s
*fcdiag
= BFA_FCDIAG_MOD(bfa
);
6652 struct bfa_dport_s
*dport
= &fcdiag
->dport
;
6655 * Dport is not support in MEZZ card
6657 if (bfa_mfg_is_mezz(dport
->bfa
->ioc
.attr
->card_type
)) {
6658 bfa_trc(dport
->bfa
, BFA_STATUS_PBC
);
6659 return BFA_STATUS_CMD_NOTSUPP_MEZZ
;
6663 * Dport is supported in CT2 or above
6665 if (!(bfa_asic_id_ct2(dport
->bfa
->ioc
.pcidev
.device_id
))) {
6666 bfa_trc(dport
->bfa
, dport
->bfa
->ioc
.pcidev
.device_id
);
6667 return BFA_STATUS_FEATURE_NOT_SUPPORTED
;
6671 * Check to see if IOC is down
6673 if (!bfa_iocfc_is_operational(bfa
))
6674 return BFA_STATUS_IOC_NON_OP
;
6676 /* if port is PBC disabled, return error */
6677 if (bfa_fcport_is_pbcdisabled(bfa
)) {
6678 bfa_trc(dport
->bfa
, BFA_STATUS_PBC
);
6679 return BFA_STATUS_PBC
;
6683 * Check if port mode is FC port
6685 if (bfa_ioc_get_type(&bfa
->ioc
) != BFA_IOC_TYPE_FC
) {
6686 bfa_trc(dport
->bfa
, bfa_ioc_get_type(&bfa
->ioc
));
6687 return BFA_STATUS_CMD_NOTSUPP_CNA
;
6691 * Check if port is in LOOP mode
6693 if ((bfa_fcport_get_cfg_topology(bfa
) == BFA_PORT_TOPOLOGY_LOOP
) ||
6694 (bfa_fcport_get_topology(bfa
) == BFA_PORT_TOPOLOGY_LOOP
)) {
6695 bfa_trc(dport
->bfa
, 0);
6696 return BFA_STATUS_TOPOLOGY_LOOP
;
6700 * Check if port is TRUNK mode
6702 if (bfa_fcport_is_trunk_enabled(bfa
)) {
6703 bfa_trc(dport
->bfa
, 0);
6704 return BFA_STATUS_ERROR_TRUNK_ENABLED
;
6708 * Check if diag loopback is running
6710 if (bfa_fcdiag_lb_is_running(bfa
)) {
6711 bfa_trc(dport
->bfa
, 0);
6712 return BFA_STATUS_DIAG_BUSY
;
6716 * Check to see if port is disable or in dport state
6718 if ((bfa_fcport_is_disabled(bfa
) == BFA_FALSE
) &&
6719 (bfa_fcport_is_dport(bfa
) == BFA_FALSE
)) {
6720 bfa_trc(dport
->bfa
, 0);
6721 return BFA_STATUS_PORT_NOT_DISABLED
;
6725 * Check if dport is in dynamic mode
6728 return BFA_STATUS_DDPORT_ERR
;
6731 * Check if dport is busy
6733 if (bfa_dport_is_sending_req(dport
))
6734 return BFA_STATUS_DEVBUSY
;
6737 * Check if dport is already enabled
6739 if (bfa_sm_cmp_state(dport
, bfa_dport_sm_enabled
)) {
6740 bfa_trc(dport
->bfa
, 0);
6741 return BFA_STATUS_DPORT_ENABLED
;
6744 bfa_trc(dport
->bfa
, lpcnt
);
6745 bfa_trc(dport
->bfa
, pat
);
6746 dport
->lpcnt
= (lpcnt
) ? lpcnt
: DPORT_ENABLE_LOOPCNT_DEFAULT
;
6747 dport
->payload
= (pat
) ? pat
: LB_PATTERN_DEFAULT
;
6749 dport
->cbarg
= cbarg
;
6751 bfa_sm_send_event(dport
, BFA_DPORT_SM_ENABLE
);
6752 return BFA_STATUS_OK
;
6758 * @param[in] *bfa - bfa data struct
6761 bfa_dport_disable(struct bfa_s
*bfa
, bfa_cb_diag_t cbfn
, void *cbarg
)
6763 struct bfa_fcdiag_s
*fcdiag
= BFA_FCDIAG_MOD(bfa
);
6764 struct bfa_dport_s
*dport
= &fcdiag
->dport
;
6766 if (bfa_ioc_is_disabled(&bfa
->ioc
))
6767 return BFA_STATUS_IOC_DISABLED
;
6769 /* if port is PBC disabled, return error */
6770 if (bfa_fcport_is_pbcdisabled(bfa
)) {
6771 bfa_trc(dport
->bfa
, BFA_STATUS_PBC
);
6772 return BFA_STATUS_PBC
;
6776 * Check if dport is in dynamic mode
6778 if (dport
->dynamic
) {
6779 return BFA_STATUS_DDPORT_ERR
;
6783 * Check to see if port is disable or in dport state
6785 if ((bfa_fcport_is_disabled(bfa
) == BFA_FALSE
) &&
6786 (bfa_fcport_is_dport(bfa
) == BFA_FALSE
)) {
6787 bfa_trc(dport
->bfa
, 0);
6788 return BFA_STATUS_PORT_NOT_DISABLED
;
6792 * Check if dport is busy
6794 if (bfa_dport_is_sending_req(dport
))
6795 return BFA_STATUS_DEVBUSY
;
6798 * Check if dport is already disabled
6800 if (bfa_sm_cmp_state(dport
, bfa_dport_sm_disabled
)) {
6801 bfa_trc(dport
->bfa
, 0);
6802 return BFA_STATUS_DPORT_DISABLED
;
6806 dport
->cbarg
= cbarg
;
6808 bfa_sm_send_event(dport
, BFA_DPORT_SM_DISABLE
);
6809 return BFA_STATUS_OK
;
6813 * Dport start -- restart dport test
6815 * @param[in] *bfa - bfa data struct
6818 bfa_dport_start(struct bfa_s
*bfa
, u32 lpcnt
, u32 pat
,
6819 bfa_cb_diag_t cbfn
, void *cbarg
)
6821 struct bfa_fcdiag_s
*fcdiag
= BFA_FCDIAG_MOD(bfa
);
6822 struct bfa_dport_s
*dport
= &fcdiag
->dport
;
6825 * Check to see if IOC is down
6827 if (!bfa_iocfc_is_operational(bfa
))
6828 return BFA_STATUS_IOC_NON_OP
;
6831 * Check if dport is in dynamic mode
6834 return BFA_STATUS_DDPORT_ERR
;
6837 * Check if dport is busy
6839 if (bfa_dport_is_sending_req(dport
))
6840 return BFA_STATUS_DEVBUSY
;
6843 * Check if dport is in enabled state.
6844 * Test can only be restart when previous test has completed
6846 if (!bfa_sm_cmp_state(dport
, bfa_dport_sm_enabled
)) {
6847 bfa_trc(dport
->bfa
, 0);
6848 return BFA_STATUS_DPORT_DISABLED
;
6851 if (dport
->test_state
== BFA_DPORT_ST_NO_SFP
)
6852 return BFA_STATUS_DPORT_INV_SFP
;
6854 if (dport
->test_state
== BFA_DPORT_ST_INP
)
6855 return BFA_STATUS_DEVBUSY
;
6857 WARN_ON(dport
->test_state
!= BFA_DPORT_ST_COMP
);
6860 bfa_trc(dport
->bfa
, lpcnt
);
6861 bfa_trc(dport
->bfa
, pat
);
6863 dport
->lpcnt
= (lpcnt
) ? lpcnt
: DPORT_ENABLE_LOOPCNT_DEFAULT
;
6864 dport
->payload
= (pat
) ? pat
: LB_PATTERN_DEFAULT
;
6867 dport
->cbarg
= cbarg
;
6869 bfa_sm_send_event(dport
, BFA_DPORT_SM_START
);
6870 return BFA_STATUS_OK
;
6874 * Dport show -- return dport test result
6876 * @param[in] *bfa - bfa data struct
6879 bfa_dport_show(struct bfa_s
*bfa
, struct bfa_diag_dport_result_s
*result
)
6881 struct bfa_fcdiag_s
*fcdiag
= BFA_FCDIAG_MOD(bfa
);
6882 struct bfa_dport_s
*dport
= &fcdiag
->dport
;
6885 * Check to see if IOC is down
6887 if (!bfa_iocfc_is_operational(bfa
))
6888 return BFA_STATUS_IOC_NON_OP
;
6891 * Check if dport is busy
6893 if (bfa_dport_is_sending_req(dport
))
6894 return BFA_STATUS_DEVBUSY
;
6897 * Check if dport is in enabled state.
6899 if (!bfa_sm_cmp_state(dport
, bfa_dport_sm_enabled
)) {
6900 bfa_trc(dport
->bfa
, 0);
6901 return BFA_STATUS_DPORT_DISABLED
;
6906 * Check if there is SFP
6908 if (dport
->test_state
== BFA_DPORT_ST_NO_SFP
)
6909 return BFA_STATUS_DPORT_INV_SFP
;
6911 memcpy(result
, &dport
->result
, sizeof(struct bfa_diag_dport_result_s
));
6913 return BFA_STATUS_OK
;