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
);
35 * LPS related definitions
37 #define BFA_LPS_MIN_LPORTS (1)
38 #define BFA_LPS_MAX_LPORTS (256)
41 * Maximum Vports supported per physical port or vf.
43 #define BFA_LPS_MAX_VPORTS_SUPP_CB 255
44 #define BFA_LPS_MAX_VPORTS_SUPP_CT 190
48 * FC PORT related definitions
51 * The port is considered disabled if corresponding physical port or IOC are
54 #define BFA_PORT_IS_DISABLED(bfa) \
55 ((bfa_fcport_is_disabled(bfa) == BFA_TRUE) || \
56 (bfa_ioc_is_disabled(&bfa->ioc) == BFA_TRUE))
59 * BFA port state machine events
61 enum bfa_fcport_sm_event
{
62 BFA_FCPORT_SM_START
= 1, /* start port state machine */
63 BFA_FCPORT_SM_STOP
= 2, /* stop port state machine */
64 BFA_FCPORT_SM_ENABLE
= 3, /* enable port */
65 BFA_FCPORT_SM_DISABLE
= 4, /* disable port state machine */
66 BFA_FCPORT_SM_FWRSP
= 5, /* firmware enable/disable rsp */
67 BFA_FCPORT_SM_LINKUP
= 6, /* firmware linkup event */
68 BFA_FCPORT_SM_LINKDOWN
= 7, /* firmware linkup down */
69 BFA_FCPORT_SM_QRESUME
= 8, /* CQ space available */
70 BFA_FCPORT_SM_HWFAIL
= 9, /* IOC h/w failure */
71 BFA_FCPORT_SM_DPORTENABLE
= 10, /* enable dport */
72 BFA_FCPORT_SM_DPORTDISABLE
= 11,/* disable dport */
73 BFA_FCPORT_SM_FAA_MISCONFIG
= 12, /* FAA misconfiguratin */
74 BFA_FCPORT_SM_DDPORTENABLE
= 13, /* enable ddport */
75 BFA_FCPORT_SM_DDPORTDISABLE
= 14, /* disable ddport */
79 * BFA port link notification state machine events
82 enum bfa_fcport_ln_sm_event
{
83 BFA_FCPORT_LN_SM_LINKUP
= 1, /* linkup event */
84 BFA_FCPORT_LN_SM_LINKDOWN
= 2, /* linkdown event */
85 BFA_FCPORT_LN_SM_NOTIFICATION
= 3 /* done notification */
89 * RPORT related definitions
91 #define bfa_rport_offline_cb(__rp) do { \
92 if ((__rp)->bfa->fcs) \
93 bfa_cb_rport_offline((__rp)->rport_drv); \
95 bfa_cb_queue((__rp)->bfa, &(__rp)->hcb_qe, \
96 __bfa_cb_rport_offline, (__rp)); \
100 #define bfa_rport_online_cb(__rp) do { \
101 if ((__rp)->bfa->fcs) \
102 bfa_cb_rport_online((__rp)->rport_drv); \
104 bfa_cb_queue((__rp)->bfa, &(__rp)->hcb_qe, \
105 __bfa_cb_rport_online, (__rp)); \
110 * forward declarations FCXP related functions
112 static void __bfa_fcxp_send_cbfn(void *cbarg
, bfa_boolean_t complete
);
113 static void hal_fcxp_rx_plog(struct bfa_s
*bfa
, struct bfa_fcxp_s
*fcxp
,
114 struct bfi_fcxp_send_rsp_s
*fcxp_rsp
);
115 static void hal_fcxp_tx_plog(struct bfa_s
*bfa
, u32 reqlen
,
116 struct bfa_fcxp_s
*fcxp
, struct fchs_s
*fchs
);
117 static void bfa_fcxp_qresume(void *cbarg
);
118 static void bfa_fcxp_queue(struct bfa_fcxp_s
*fcxp
,
119 struct bfi_fcxp_send_req_s
*send_req
);
122 * forward declarations for LPS functions
124 static void bfa_lps_meminfo(struct bfa_iocfc_cfg_s
*cfg
,
125 struct bfa_meminfo_s
*minfo
, struct bfa_s
*bfa
);
126 static void bfa_lps_attach(struct bfa_s
*bfa
, void *bfad
,
127 struct bfa_iocfc_cfg_s
*cfg
,
128 struct bfa_pcidev_s
*pcidev
);
129 static void bfa_lps_detach(struct bfa_s
*bfa
);
130 static void bfa_lps_start(struct bfa_s
*bfa
);
131 static void bfa_lps_stop(struct bfa_s
*bfa
);
132 static void bfa_lps_iocdisable(struct bfa_s
*bfa
);
133 static void bfa_lps_login_rsp(struct bfa_s
*bfa
,
134 struct bfi_lps_login_rsp_s
*rsp
);
135 static void bfa_lps_no_res(struct bfa_lps_s
*first_lps
, u8 count
);
136 static void bfa_lps_logout_rsp(struct bfa_s
*bfa
,
137 struct bfi_lps_logout_rsp_s
*rsp
);
138 static void bfa_lps_reqq_resume(void *lps_arg
);
139 static void bfa_lps_free(struct bfa_lps_s
*lps
);
140 static void bfa_lps_send_login(struct bfa_lps_s
*lps
);
141 static void bfa_lps_send_logout(struct bfa_lps_s
*lps
);
142 static void bfa_lps_send_set_n2n_pid(struct bfa_lps_s
*lps
);
143 static void bfa_lps_login_comp(struct bfa_lps_s
*lps
);
144 static void bfa_lps_logout_comp(struct bfa_lps_s
*lps
);
145 static void bfa_lps_cvl_event(struct bfa_lps_s
*lps
);
148 * forward declaration for LPS state machine
150 static void bfa_lps_sm_init(struct bfa_lps_s
*lps
, enum bfa_lps_event event
);
151 static void bfa_lps_sm_login(struct bfa_lps_s
*lps
, enum bfa_lps_event event
);
152 static void bfa_lps_sm_loginwait(struct bfa_lps_s
*lps
, enum bfa_lps_event
154 static void bfa_lps_sm_online(struct bfa_lps_s
*lps
, enum bfa_lps_event event
);
155 static void bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s
*lps
,
156 enum bfa_lps_event event
);
157 static void bfa_lps_sm_logout(struct bfa_lps_s
*lps
, enum bfa_lps_event event
);
158 static void bfa_lps_sm_logowait(struct bfa_lps_s
*lps
, enum bfa_lps_event
162 * forward declaration for FC Port functions
164 static bfa_boolean_t
bfa_fcport_send_enable(struct bfa_fcport_s
*fcport
);
165 static bfa_boolean_t
bfa_fcport_send_disable(struct bfa_fcport_s
*fcport
);
166 static void bfa_fcport_update_linkinfo(struct bfa_fcport_s
*fcport
);
167 static void bfa_fcport_reset_linkinfo(struct bfa_fcport_s
*fcport
);
168 static void bfa_fcport_set_wwns(struct bfa_fcport_s
*fcport
);
169 static void __bfa_cb_fcport_event(void *cbarg
, bfa_boolean_t complete
);
170 static void bfa_fcport_scn(struct bfa_fcport_s
*fcport
,
171 enum bfa_port_linkstate event
, bfa_boolean_t trunk
);
172 static void bfa_fcport_queue_cb(struct bfa_fcport_ln_s
*ln
,
173 enum bfa_port_linkstate event
);
174 static void __bfa_cb_fcport_stats_clr(void *cbarg
, bfa_boolean_t complete
);
175 static void bfa_fcport_stats_get_timeout(void *cbarg
);
176 static void bfa_fcport_stats_clr_timeout(void *cbarg
);
177 static void bfa_trunk_iocdisable(struct bfa_s
*bfa
);
180 * forward declaration for FC PORT state machine
182 static void bfa_fcport_sm_uninit(struct bfa_fcport_s
*fcport
,
183 enum bfa_fcport_sm_event event
);
184 static void bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s
*fcport
,
185 enum bfa_fcport_sm_event event
);
186 static void bfa_fcport_sm_enabling(struct bfa_fcport_s
*fcport
,
187 enum bfa_fcport_sm_event event
);
188 static void bfa_fcport_sm_linkdown(struct bfa_fcport_s
*fcport
,
189 enum bfa_fcport_sm_event event
);
190 static void bfa_fcport_sm_linkup(struct bfa_fcport_s
*fcport
,
191 enum bfa_fcport_sm_event event
);
192 static void bfa_fcport_sm_disabling(struct bfa_fcport_s
*fcport
,
193 enum bfa_fcport_sm_event event
);
194 static void bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s
*fcport
,
195 enum bfa_fcport_sm_event event
);
196 static void bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s
*fcport
,
197 enum bfa_fcport_sm_event event
);
198 static void bfa_fcport_sm_disabled(struct bfa_fcport_s
*fcport
,
199 enum bfa_fcport_sm_event event
);
200 static void bfa_fcport_sm_stopped(struct bfa_fcport_s
*fcport
,
201 enum bfa_fcport_sm_event event
);
202 static void bfa_fcport_sm_iocdown(struct bfa_fcport_s
*fcport
,
203 enum bfa_fcport_sm_event event
);
204 static void bfa_fcport_sm_iocfail(struct bfa_fcport_s
*fcport
,
205 enum bfa_fcport_sm_event event
);
206 static void bfa_fcport_sm_dport(struct bfa_fcport_s
*fcport
,
207 enum bfa_fcport_sm_event event
);
208 static void bfa_fcport_sm_ddport(struct bfa_fcport_s
*fcport
,
209 enum bfa_fcport_sm_event event
);
210 static void bfa_fcport_sm_faa_misconfig(struct bfa_fcport_s
*fcport
,
211 enum bfa_fcport_sm_event event
);
213 static void bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s
*ln
,
214 enum bfa_fcport_ln_sm_event event
);
215 static void bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s
*ln
,
216 enum bfa_fcport_ln_sm_event event
);
217 static void bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s
*ln
,
218 enum bfa_fcport_ln_sm_event event
);
219 static void bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s
*ln
,
220 enum bfa_fcport_ln_sm_event event
);
221 static void bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s
*ln
,
222 enum bfa_fcport_ln_sm_event event
);
223 static void bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s
*ln
,
224 enum bfa_fcport_ln_sm_event event
);
225 static void bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s
*ln
,
226 enum bfa_fcport_ln_sm_event event
);
228 static struct bfa_sm_table_s hal_port_sm_table
[] = {
229 {BFA_SM(bfa_fcport_sm_uninit
), BFA_PORT_ST_UNINIT
},
230 {BFA_SM(bfa_fcport_sm_enabling_qwait
), BFA_PORT_ST_ENABLING_QWAIT
},
231 {BFA_SM(bfa_fcport_sm_enabling
), BFA_PORT_ST_ENABLING
},
232 {BFA_SM(bfa_fcport_sm_linkdown
), BFA_PORT_ST_LINKDOWN
},
233 {BFA_SM(bfa_fcport_sm_linkup
), BFA_PORT_ST_LINKUP
},
234 {BFA_SM(bfa_fcport_sm_disabling_qwait
), BFA_PORT_ST_DISABLING_QWAIT
},
235 {BFA_SM(bfa_fcport_sm_toggling_qwait
), BFA_PORT_ST_TOGGLING_QWAIT
},
236 {BFA_SM(bfa_fcport_sm_disabling
), BFA_PORT_ST_DISABLING
},
237 {BFA_SM(bfa_fcport_sm_disabled
), BFA_PORT_ST_DISABLED
},
238 {BFA_SM(bfa_fcport_sm_stopped
), BFA_PORT_ST_STOPPED
},
239 {BFA_SM(bfa_fcport_sm_iocdown
), BFA_PORT_ST_IOCDOWN
},
240 {BFA_SM(bfa_fcport_sm_iocfail
), BFA_PORT_ST_IOCDOWN
},
241 {BFA_SM(bfa_fcport_sm_dport
), BFA_PORT_ST_DPORT
},
242 {BFA_SM(bfa_fcport_sm_ddport
), BFA_PORT_ST_DDPORT
},
243 {BFA_SM(bfa_fcport_sm_faa_misconfig
), BFA_PORT_ST_FAA_MISCONFIG
},
248 * forward declaration for RPORT related functions
250 static struct bfa_rport_s
*bfa_rport_alloc(struct bfa_rport_mod_s
*rp_mod
);
251 static void bfa_rport_free(struct bfa_rport_s
*rport
);
252 static bfa_boolean_t
bfa_rport_send_fwcreate(struct bfa_rport_s
*rp
);
253 static bfa_boolean_t
bfa_rport_send_fwdelete(struct bfa_rport_s
*rp
);
254 static bfa_boolean_t
bfa_rport_send_fwspeed(struct bfa_rport_s
*rp
);
255 static void __bfa_cb_rport_online(void *cbarg
,
256 bfa_boolean_t complete
);
257 static void __bfa_cb_rport_offline(void *cbarg
,
258 bfa_boolean_t complete
);
261 * forward declaration for RPORT state machine
263 static void bfa_rport_sm_uninit(struct bfa_rport_s
*rp
,
264 enum bfa_rport_event event
);
265 static void bfa_rport_sm_created(struct bfa_rport_s
*rp
,
266 enum bfa_rport_event event
);
267 static void bfa_rport_sm_fwcreate(struct bfa_rport_s
*rp
,
268 enum bfa_rport_event event
);
269 static void bfa_rport_sm_online(struct bfa_rport_s
*rp
,
270 enum bfa_rport_event event
);
271 static void bfa_rport_sm_fwdelete(struct bfa_rport_s
*rp
,
272 enum bfa_rport_event event
);
273 static void bfa_rport_sm_offline(struct bfa_rport_s
*rp
,
274 enum bfa_rport_event event
);
275 static void bfa_rport_sm_deleting(struct bfa_rport_s
*rp
,
276 enum bfa_rport_event event
);
277 static void bfa_rport_sm_offline_pending(struct bfa_rport_s
*rp
,
278 enum bfa_rport_event event
);
279 static void bfa_rport_sm_delete_pending(struct bfa_rport_s
*rp
,
280 enum bfa_rport_event event
);
281 static void bfa_rport_sm_iocdisable(struct bfa_rport_s
*rp
,
282 enum bfa_rport_event event
);
283 static void bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s
*rp
,
284 enum bfa_rport_event event
);
285 static void bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s
*rp
,
286 enum bfa_rport_event event
);
287 static void bfa_rport_sm_deleting_qfull(struct bfa_rport_s
*rp
,
288 enum bfa_rport_event event
);
291 * PLOG related definitions
294 plkd_validate_logrec(struct bfa_plog_rec_s
*pl_rec
)
296 if ((pl_rec
->log_type
!= BFA_PL_LOG_TYPE_INT
) &&
297 (pl_rec
->log_type
!= BFA_PL_LOG_TYPE_STRING
))
300 if ((pl_rec
->log_type
!= BFA_PL_LOG_TYPE_INT
) &&
301 (pl_rec
->log_num_ints
> BFA_PL_INT_LOG_SZ
))
308 bfa_get_log_time(void)
312 do_gettimeofday(&tv
);
314 /* We are interested in seconds only. */
315 system_time
= tv
.tv_sec
;
320 bfa_plog_add(struct bfa_plog_s
*plog
, struct bfa_plog_rec_s
*pl_rec
)
323 struct bfa_plog_rec_s
*pl_recp
;
325 if (plog
->plog_enabled
== 0)
328 if (plkd_validate_logrec(pl_rec
)) {
335 pl_recp
= &(plog
->plog_recs
[tail
]);
337 memcpy(pl_recp
, pl_rec
, sizeof(struct bfa_plog_rec_s
));
339 pl_recp
->tv
= bfa_get_log_time();
340 BFA_PL_LOG_REC_INCR(plog
->tail
);
342 if (plog
->head
== plog
->tail
)
343 BFA_PL_LOG_REC_INCR(plog
->head
);
347 bfa_plog_init(struct bfa_plog_s
*plog
)
349 memset((char *)plog
, 0, sizeof(struct bfa_plog_s
));
351 memcpy(plog
->plog_sig
, BFA_PL_SIG_STR
, BFA_PL_SIG_LEN
);
352 plog
->head
= plog
->tail
= 0;
353 plog
->plog_enabled
= 1;
357 bfa_plog_str(struct bfa_plog_s
*plog
, enum bfa_plog_mid mid
,
358 enum bfa_plog_eid event
,
359 u16 misc
, char *log_str
)
361 struct bfa_plog_rec_s lp
;
363 if (plog
->plog_enabled
) {
364 memset(&lp
, 0, sizeof(struct bfa_plog_rec_s
));
367 lp
.log_type
= BFA_PL_LOG_TYPE_STRING
;
369 strncpy(lp
.log_entry
.string_log
, log_str
,
370 BFA_PL_STRING_LOG_SZ
- 1);
371 lp
.log_entry
.string_log
[BFA_PL_STRING_LOG_SZ
- 1] = '\0';
372 bfa_plog_add(plog
, &lp
);
377 bfa_plog_intarr(struct bfa_plog_s
*plog
, enum bfa_plog_mid mid
,
378 enum bfa_plog_eid event
,
379 u16 misc
, u32
*intarr
, u32 num_ints
)
381 struct bfa_plog_rec_s lp
;
384 if (num_ints
> BFA_PL_INT_LOG_SZ
)
385 num_ints
= BFA_PL_INT_LOG_SZ
;
387 if (plog
->plog_enabled
) {
388 memset(&lp
, 0, sizeof(struct bfa_plog_rec_s
));
391 lp
.log_type
= BFA_PL_LOG_TYPE_INT
;
394 for (i
= 0; i
< num_ints
; i
++)
395 lp
.log_entry
.int_log
[i
] = intarr
[i
];
397 lp
.log_num_ints
= (u8
) num_ints
;
399 bfa_plog_add(plog
, &lp
);
404 bfa_plog_fchdr(struct bfa_plog_s
*plog
, enum bfa_plog_mid mid
,
405 enum bfa_plog_eid event
,
406 u16 misc
, struct fchs_s
*fchdr
)
408 struct bfa_plog_rec_s lp
;
409 u32
*tmp_int
= (u32
*) fchdr
;
410 u32 ints
[BFA_PL_INT_LOG_SZ
];
412 if (plog
->plog_enabled
) {
413 memset(&lp
, 0, sizeof(struct bfa_plog_rec_s
));
415 ints
[0] = tmp_int
[0];
416 ints
[1] = tmp_int
[1];
417 ints
[2] = tmp_int
[4];
419 bfa_plog_intarr(plog
, mid
, event
, misc
, ints
, 3);
424 bfa_plog_fchdr_and_pl(struct bfa_plog_s
*plog
, enum bfa_plog_mid mid
,
425 enum bfa_plog_eid event
, u16 misc
, struct fchs_s
*fchdr
,
428 struct bfa_plog_rec_s lp
;
429 u32
*tmp_int
= (u32
*) fchdr
;
430 u32 ints
[BFA_PL_INT_LOG_SZ
];
432 if (plog
->plog_enabled
) {
433 memset(&lp
, 0, sizeof(struct bfa_plog_rec_s
));
435 ints
[0] = tmp_int
[0];
436 ints
[1] = tmp_int
[1];
437 ints
[2] = tmp_int
[4];
440 bfa_plog_intarr(plog
, mid
, event
, misc
, ints
, 4);
446 * fcxp_pvt BFA FCXP private functions
450 claim_fcxps_mem(struct bfa_fcxp_mod_s
*mod
)
453 struct bfa_fcxp_s
*fcxp
;
455 fcxp
= (struct bfa_fcxp_s
*) bfa_mem_kva_curp(mod
);
456 memset(fcxp
, 0, sizeof(struct bfa_fcxp_s
) * mod
->num_fcxps
);
458 INIT_LIST_HEAD(&mod
->fcxp_req_free_q
);
459 INIT_LIST_HEAD(&mod
->fcxp_rsp_free_q
);
460 INIT_LIST_HEAD(&mod
->fcxp_active_q
);
461 INIT_LIST_HEAD(&mod
->fcxp_req_unused_q
);
462 INIT_LIST_HEAD(&mod
->fcxp_rsp_unused_q
);
464 mod
->fcxp_list
= fcxp
;
466 for (i
= 0; i
< mod
->num_fcxps
; i
++) {
467 fcxp
->fcxp_mod
= mod
;
470 if (i
< (mod
->num_fcxps
/ 2)) {
471 list_add_tail(&fcxp
->qe
, &mod
->fcxp_req_free_q
);
472 fcxp
->req_rsp
= BFA_TRUE
;
474 list_add_tail(&fcxp
->qe
, &mod
->fcxp_rsp_free_q
);
475 fcxp
->req_rsp
= BFA_FALSE
;
478 bfa_reqq_winit(&fcxp
->reqq_wqe
, bfa_fcxp_qresume
, fcxp
);
479 fcxp
->reqq_waiting
= BFA_FALSE
;
484 bfa_mem_kva_curp(mod
) = (void *)fcxp
;
488 bfa_fcxp_meminfo(struct bfa_iocfc_cfg_s
*cfg
, struct bfa_meminfo_s
*minfo
,
491 struct bfa_fcxp_mod_s
*fcxp_mod
= BFA_FCXP_MOD(bfa
);
492 struct bfa_mem_kva_s
*fcxp_kva
= BFA_MEM_FCXP_KVA(bfa
);
493 struct bfa_mem_dma_s
*seg_ptr
;
494 u16 nsegs
, idx
, per_seg_fcxp
;
495 u16 num_fcxps
= cfg
->fwcfg
.num_fcxp_reqs
;
501 if (cfg
->drvcfg
.min_cfg
)
502 per_fcxp_sz
= 2 * BFA_FCXP_MAX_IBUF_SZ
;
504 per_fcxp_sz
= BFA_FCXP_MAX_IBUF_SZ
+ BFA_FCXP_MAX_LBUF_SZ
;
507 nsegs
= BFI_MEM_DMA_NSEGS(num_fcxps
, per_fcxp_sz
);
508 per_seg_fcxp
= BFI_MEM_NREQS_SEG(per_fcxp_sz
);
510 bfa_mem_dma_seg_iter(fcxp_mod
, seg_ptr
, nsegs
, idx
) {
511 if (num_fcxps
>= per_seg_fcxp
) {
512 num_fcxps
-= per_seg_fcxp
;
513 bfa_mem_dma_setup(minfo
, seg_ptr
,
514 per_seg_fcxp
* per_fcxp_sz
);
516 bfa_mem_dma_setup(minfo
, seg_ptr
,
517 num_fcxps
* per_fcxp_sz
);
521 bfa_mem_kva_setup(minfo
, fcxp_kva
,
522 cfg
->fwcfg
.num_fcxp_reqs
* sizeof(struct bfa_fcxp_s
));
526 bfa_fcxp_attach(struct bfa_s
*bfa
, void *bfad
, struct bfa_iocfc_cfg_s
*cfg
,
527 struct bfa_pcidev_s
*pcidev
)
529 struct bfa_fcxp_mod_s
*mod
= BFA_FCXP_MOD(bfa
);
532 mod
->num_fcxps
= cfg
->fwcfg
.num_fcxp_reqs
;
535 * Initialize FCXP request and response payload sizes.
537 mod
->req_pld_sz
= mod
->rsp_pld_sz
= BFA_FCXP_MAX_IBUF_SZ
;
538 if (!cfg
->drvcfg
.min_cfg
)
539 mod
->rsp_pld_sz
= BFA_FCXP_MAX_LBUF_SZ
;
541 INIT_LIST_HEAD(&mod
->req_wait_q
);
542 INIT_LIST_HEAD(&mod
->rsp_wait_q
);
544 claim_fcxps_mem(mod
);
548 bfa_fcxp_detach(struct bfa_s
*bfa
)
553 bfa_fcxp_start(struct bfa_s
*bfa
)
558 bfa_fcxp_stop(struct bfa_s
*bfa
)
563 bfa_fcxp_iocdisable(struct bfa_s
*bfa
)
565 struct bfa_fcxp_mod_s
*mod
= BFA_FCXP_MOD(bfa
);
566 struct bfa_fcxp_s
*fcxp
;
567 struct list_head
*qe
, *qen
;
569 /* Enqueue unused fcxp resources to free_q */
570 list_splice_tail_init(&mod
->fcxp_req_unused_q
, &mod
->fcxp_req_free_q
);
571 list_splice_tail_init(&mod
->fcxp_rsp_unused_q
, &mod
->fcxp_rsp_free_q
);
573 list_for_each_safe(qe
, qen
, &mod
->fcxp_active_q
) {
574 fcxp
= (struct bfa_fcxp_s
*) qe
;
575 if (fcxp
->caller
== NULL
) {
576 fcxp
->send_cbfn(fcxp
->caller
, fcxp
, fcxp
->send_cbarg
,
577 BFA_STATUS_IOC_FAILURE
, 0, 0, NULL
);
580 fcxp
->rsp_status
= BFA_STATUS_IOC_FAILURE
;
581 bfa_cb_queue(bfa
, &fcxp
->hcb_qe
,
582 __bfa_fcxp_send_cbfn
, fcxp
);
587 static struct bfa_fcxp_s
*
588 bfa_fcxp_get(struct bfa_fcxp_mod_s
*fm
, bfa_boolean_t req
)
590 struct bfa_fcxp_s
*fcxp
;
593 bfa_q_deq(&fm
->fcxp_req_free_q
, &fcxp
);
595 bfa_q_deq(&fm
->fcxp_rsp_free_q
, &fcxp
);
598 list_add_tail(&fcxp
->qe
, &fm
->fcxp_active_q
);
604 bfa_fcxp_init_reqrsp(struct bfa_fcxp_s
*fcxp
,
608 bfa_fcxp_get_sgaddr_t
*r_sga_cbfn
,
609 bfa_fcxp_get_sglen_t
*r_sglen_cbfn
,
610 struct list_head
*r_sgpg_q
,
612 bfa_fcxp_get_sgaddr_t sga_cbfn
,
613 bfa_fcxp_get_sglen_t sglen_cbfn
)
616 WARN_ON(bfa
== NULL
);
618 bfa_trc(bfa
, fcxp
->fcxp_tag
);
623 WARN_ON(*sga_cbfn
== NULL
);
624 WARN_ON(*sglen_cbfn
== NULL
);
627 *r_sga_cbfn
= sga_cbfn
;
628 *r_sglen_cbfn
= sglen_cbfn
;
633 * alloc required sgpgs
635 if (n_sgles
> BFI_SGE_INLINE
)
642 bfa_fcxp_init(struct bfa_fcxp_s
*fcxp
,
643 void *caller
, struct bfa_s
*bfa
, int nreq_sgles
,
644 int nrsp_sgles
, bfa_fcxp_get_sgaddr_t req_sga_cbfn
,
645 bfa_fcxp_get_sglen_t req_sglen_cbfn
,
646 bfa_fcxp_get_sgaddr_t rsp_sga_cbfn
,
647 bfa_fcxp_get_sglen_t rsp_sglen_cbfn
)
650 WARN_ON(bfa
== NULL
);
652 bfa_trc(bfa
, fcxp
->fcxp_tag
);
654 fcxp
->caller
= caller
;
656 bfa_fcxp_init_reqrsp(fcxp
, bfa
,
657 &fcxp
->use_ireqbuf
, &fcxp
->nreq_sgles
, &fcxp
->req_sga_cbfn
,
658 &fcxp
->req_sglen_cbfn
, &fcxp
->req_sgpg_q
,
659 nreq_sgles
, req_sga_cbfn
, req_sglen_cbfn
);
661 bfa_fcxp_init_reqrsp(fcxp
, bfa
,
662 &fcxp
->use_irspbuf
, &fcxp
->nrsp_sgles
, &fcxp
->rsp_sga_cbfn
,
663 &fcxp
->rsp_sglen_cbfn
, &fcxp
->rsp_sgpg_q
,
664 nrsp_sgles
, rsp_sga_cbfn
, rsp_sglen_cbfn
);
669 bfa_fcxp_put(struct bfa_fcxp_s
*fcxp
)
671 struct bfa_fcxp_mod_s
*mod
= fcxp
->fcxp_mod
;
672 struct bfa_fcxp_wqe_s
*wqe
;
675 bfa_q_deq(&mod
->req_wait_q
, &wqe
);
677 bfa_q_deq(&mod
->rsp_wait_q
, &wqe
);
680 bfa_trc(mod
->bfa
, fcxp
->fcxp_tag
);
682 bfa_fcxp_init(fcxp
, wqe
->caller
, wqe
->bfa
, wqe
->nreq_sgles
,
683 wqe
->nrsp_sgles
, wqe
->req_sga_cbfn
,
684 wqe
->req_sglen_cbfn
, wqe
->rsp_sga_cbfn
,
685 wqe
->rsp_sglen_cbfn
);
687 wqe
->alloc_cbfn(wqe
->alloc_cbarg
, fcxp
);
691 WARN_ON(!bfa_q_is_on_q(&mod
->fcxp_active_q
, fcxp
));
695 list_add_tail(&fcxp
->qe
, &mod
->fcxp_req_free_q
);
697 list_add_tail(&fcxp
->qe
, &mod
->fcxp_rsp_free_q
);
701 bfa_fcxp_null_comp(void *bfad_fcxp
, struct bfa_fcxp_s
*fcxp
, void *cbarg
,
702 bfa_status_t req_status
, u32 rsp_len
,
703 u32 resid_len
, struct fchs_s
*rsp_fchs
)
705 /* discarded fcxp completion */
709 __bfa_fcxp_send_cbfn(void *cbarg
, bfa_boolean_t complete
)
711 struct bfa_fcxp_s
*fcxp
= cbarg
;
714 fcxp
->send_cbfn(fcxp
->caller
, fcxp
, fcxp
->send_cbarg
,
715 fcxp
->rsp_status
, fcxp
->rsp_len
,
716 fcxp
->residue_len
, &fcxp
->rsp_fchs
);
723 hal_fcxp_send_comp(struct bfa_s
*bfa
, struct bfi_fcxp_send_rsp_s
*fcxp_rsp
)
725 struct bfa_fcxp_mod_s
*mod
= BFA_FCXP_MOD(bfa
);
726 struct bfa_fcxp_s
*fcxp
;
727 u16 fcxp_tag
= be16_to_cpu(fcxp_rsp
->fcxp_tag
);
729 bfa_trc(bfa
, fcxp_tag
);
731 fcxp_rsp
->rsp_len
= be32_to_cpu(fcxp_rsp
->rsp_len
);
734 * @todo f/w should not set residue to non-0 when everything
737 if (fcxp_rsp
->req_status
== BFA_STATUS_OK
)
738 fcxp_rsp
->residue_len
= 0;
740 fcxp_rsp
->residue_len
= be32_to_cpu(fcxp_rsp
->residue_len
);
742 fcxp
= BFA_FCXP_FROM_TAG(mod
, fcxp_tag
);
744 WARN_ON(fcxp
->send_cbfn
== NULL
);
746 hal_fcxp_rx_plog(mod
->bfa
, fcxp
, fcxp_rsp
);
748 if (fcxp
->send_cbfn
!= NULL
) {
749 bfa_trc(mod
->bfa
, (NULL
== fcxp
->caller
));
750 if (fcxp
->caller
== NULL
) {
751 fcxp
->send_cbfn(fcxp
->caller
, fcxp
, fcxp
->send_cbarg
,
752 fcxp_rsp
->req_status
, fcxp_rsp
->rsp_len
,
753 fcxp_rsp
->residue_len
, &fcxp_rsp
->fchs
);
755 * fcxp automatically freed on return from the callback
759 fcxp
->rsp_status
= fcxp_rsp
->req_status
;
760 fcxp
->rsp_len
= fcxp_rsp
->rsp_len
;
761 fcxp
->residue_len
= fcxp_rsp
->residue_len
;
762 fcxp
->rsp_fchs
= fcxp_rsp
->fchs
;
764 bfa_cb_queue(bfa
, &fcxp
->hcb_qe
,
765 __bfa_fcxp_send_cbfn
, fcxp
);
768 bfa_trc(bfa
, (NULL
== fcxp
->send_cbfn
));
773 hal_fcxp_tx_plog(struct bfa_s
*bfa
, u32 reqlen
, struct bfa_fcxp_s
*fcxp
,
780 if (fcxp
->use_ireqbuf
) {
782 *((u32
*) BFA_FCXP_REQ_PLD(fcxp
));
784 bfa_plog_fchdr_and_pl(bfa
->plog
, BFA_PL_MID_HAL_FCXP
,
786 reqlen
+ sizeof(struct fchs_s
), fchs
,
789 bfa_plog_fchdr(bfa
->plog
, BFA_PL_MID_HAL_FCXP
,
791 reqlen
+ sizeof(struct fchs_s
),
795 bfa_plog_fchdr(bfa
->plog
, BFA_PL_MID_HAL_FCXP
, BFA_PL_EID_TX
,
796 reqlen
+ sizeof(struct fchs_s
), fchs
);
801 hal_fcxp_rx_plog(struct bfa_s
*bfa
, struct bfa_fcxp_s
*fcxp
,
802 struct bfi_fcxp_send_rsp_s
*fcxp_rsp
)
804 if (fcxp_rsp
->rsp_len
> 0) {
805 if (fcxp
->use_irspbuf
) {
807 *((u32
*) BFA_FCXP_RSP_PLD(fcxp
));
809 bfa_plog_fchdr_and_pl(bfa
->plog
, BFA_PL_MID_HAL_FCXP
,
811 (u16
) fcxp_rsp
->rsp_len
,
812 &fcxp_rsp
->fchs
, pld_w0
);
814 bfa_plog_fchdr(bfa
->plog
, BFA_PL_MID_HAL_FCXP
,
816 (u16
) fcxp_rsp
->rsp_len
,
820 bfa_plog_fchdr(bfa
->plog
, BFA_PL_MID_HAL_FCXP
, BFA_PL_EID_RX
,
821 (u16
) fcxp_rsp
->rsp_len
, &fcxp_rsp
->fchs
);
826 * Handler to resume sending fcxp when space in available in cpe queue.
829 bfa_fcxp_qresume(void *cbarg
)
831 struct bfa_fcxp_s
*fcxp
= cbarg
;
832 struct bfa_s
*bfa
= fcxp
->fcxp_mod
->bfa
;
833 struct bfi_fcxp_send_req_s
*send_req
;
835 fcxp
->reqq_waiting
= BFA_FALSE
;
836 send_req
= bfa_reqq_next(bfa
, BFA_REQQ_FCXP
);
837 bfa_fcxp_queue(fcxp
, send_req
);
841 * Queue fcxp send request to foimrware.
844 bfa_fcxp_queue(struct bfa_fcxp_s
*fcxp
, struct bfi_fcxp_send_req_s
*send_req
)
846 struct bfa_s
*bfa
= fcxp
->fcxp_mod
->bfa
;
847 struct bfa_fcxp_req_info_s
*reqi
= &fcxp
->req_info
;
848 struct bfa_fcxp_rsp_info_s
*rspi
= &fcxp
->rsp_info
;
849 struct bfa_rport_s
*rport
= reqi
->bfa_rport
;
851 bfi_h2i_set(send_req
->mh
, BFI_MC_FCXP
, BFI_FCXP_H2I_SEND_REQ
,
854 send_req
->fcxp_tag
= cpu_to_be16(fcxp
->fcxp_tag
);
856 send_req
->rport_fw_hndl
= rport
->fw_handle
;
857 send_req
->max_frmsz
= cpu_to_be16(rport
->rport_info
.max_frmsz
);
858 if (send_req
->max_frmsz
== 0)
859 send_req
->max_frmsz
= cpu_to_be16(FC_MAX_PDUSZ
);
861 send_req
->rport_fw_hndl
= 0;
862 send_req
->max_frmsz
= cpu_to_be16(FC_MAX_PDUSZ
);
865 send_req
->vf_id
= cpu_to_be16(reqi
->vf_id
);
866 send_req
->lp_fwtag
= bfa_lps_get_fwtag(bfa
, reqi
->lp_tag
);
867 send_req
->class = reqi
->class;
868 send_req
->rsp_timeout
= rspi
->rsp_timeout
;
869 send_req
->cts
= reqi
->cts
;
870 send_req
->fchs
= reqi
->fchs
;
872 send_req
->req_len
= cpu_to_be32(reqi
->req_tot_len
);
873 send_req
->rsp_maxlen
= cpu_to_be32(rspi
->rsp_maxlen
);
878 if (fcxp
->use_ireqbuf
== 1) {
879 bfa_alen_set(&send_req
->req_alen
, reqi
->req_tot_len
,
880 BFA_FCXP_REQ_PLD_PA(fcxp
));
882 if (fcxp
->nreq_sgles
> 0) {
883 WARN_ON(fcxp
->nreq_sgles
!= 1);
884 bfa_alen_set(&send_req
->req_alen
, reqi
->req_tot_len
,
885 fcxp
->req_sga_cbfn(fcxp
->caller
, 0));
887 WARN_ON(reqi
->req_tot_len
!= 0);
888 bfa_alen_set(&send_req
->rsp_alen
, 0, 0);
895 if (fcxp
->use_irspbuf
== 1) {
896 WARN_ON(rspi
->rsp_maxlen
> BFA_FCXP_MAX_LBUF_SZ
);
898 bfa_alen_set(&send_req
->rsp_alen
, rspi
->rsp_maxlen
,
899 BFA_FCXP_RSP_PLD_PA(fcxp
));
901 if (fcxp
->nrsp_sgles
> 0) {
902 WARN_ON(fcxp
->nrsp_sgles
!= 1);
903 bfa_alen_set(&send_req
->rsp_alen
, rspi
->rsp_maxlen
,
904 fcxp
->rsp_sga_cbfn(fcxp
->caller
, 0));
907 WARN_ON(rspi
->rsp_maxlen
!= 0);
908 bfa_alen_set(&send_req
->rsp_alen
, 0, 0);
912 hal_fcxp_tx_plog(bfa
, reqi
->req_tot_len
, fcxp
, &reqi
->fchs
);
914 bfa_reqq_produce(bfa
, BFA_REQQ_FCXP
, send_req
->mh
);
916 bfa_trc(bfa
, bfa_reqq_pi(bfa
, BFA_REQQ_FCXP
));
917 bfa_trc(bfa
, bfa_reqq_ci(bfa
, BFA_REQQ_FCXP
));
921 * Allocate an FCXP instance to send a response or to send a request
922 * that has a response. Request/response buffers are allocated by caller.
924 * @param[in] bfa BFA bfa instance
925 * @param[in] nreq_sgles Number of SG elements required for request
926 * buffer. 0, if fcxp internal buffers are used.
927 * Use bfa_fcxp_get_reqbuf() to get the
928 * internal req buffer.
929 * @param[in] req_sgles SG elements describing request buffer. Will be
930 * copied in by BFA and hence can be freed on
931 * return from this function.
932 * @param[in] get_req_sga function ptr to be called to get a request SG
933 * Address (given the sge index).
934 * @param[in] get_req_sglen function ptr to be called to get a request SG
935 * len (given the sge index).
936 * @param[in] get_rsp_sga function ptr to be called to get a response SG
937 * Address (given the sge index).
938 * @param[in] get_rsp_sglen function ptr to be called to get a response SG
939 * len (given the sge index).
940 * @param[in] req Allocated FCXP is used to send req or rsp?
941 * request - BFA_TRUE, response - BFA_FALSE
943 * @return FCXP instance. NULL on failure.
946 bfa_fcxp_req_rsp_alloc(void *caller
, struct bfa_s
*bfa
, int nreq_sgles
,
947 int nrsp_sgles
, bfa_fcxp_get_sgaddr_t req_sga_cbfn
,
948 bfa_fcxp_get_sglen_t req_sglen_cbfn
,
949 bfa_fcxp_get_sgaddr_t rsp_sga_cbfn
,
950 bfa_fcxp_get_sglen_t rsp_sglen_cbfn
, bfa_boolean_t req
)
952 struct bfa_fcxp_s
*fcxp
= NULL
;
954 WARN_ON(bfa
== NULL
);
956 fcxp
= bfa_fcxp_get(BFA_FCXP_MOD(bfa
), req
);
960 bfa_trc(bfa
, fcxp
->fcxp_tag
);
962 bfa_fcxp_init(fcxp
, caller
, bfa
, nreq_sgles
, nrsp_sgles
, req_sga_cbfn
,
963 req_sglen_cbfn
, rsp_sga_cbfn
, rsp_sglen_cbfn
);
969 * Get the internal request buffer pointer
971 * @param[in] fcxp BFA fcxp pointer
973 * @return pointer to the internal request buffer
976 bfa_fcxp_get_reqbuf(struct bfa_fcxp_s
*fcxp
)
978 struct bfa_fcxp_mod_s
*mod
= fcxp
->fcxp_mod
;
981 WARN_ON(fcxp
->use_ireqbuf
!= 1);
982 reqbuf
= bfa_mem_get_dmabuf_kva(mod
, fcxp
->fcxp_tag
,
983 mod
->req_pld_sz
+ mod
->rsp_pld_sz
);
988 bfa_fcxp_get_reqbufsz(struct bfa_fcxp_s
*fcxp
)
990 struct bfa_fcxp_mod_s
*mod
= fcxp
->fcxp_mod
;
992 return mod
->req_pld_sz
;
996 * Get the internal response buffer pointer
998 * @param[in] fcxp BFA fcxp pointer
1000 * @return pointer to the internal request buffer
1003 bfa_fcxp_get_rspbuf(struct bfa_fcxp_s
*fcxp
)
1005 struct bfa_fcxp_mod_s
*mod
= fcxp
->fcxp_mod
;
1008 WARN_ON(fcxp
->use_irspbuf
!= 1);
1010 fcxp_buf
= bfa_mem_get_dmabuf_kva(mod
, fcxp
->fcxp_tag
,
1011 mod
->req_pld_sz
+ mod
->rsp_pld_sz
);
1013 /* fcxp_buf = req_buf + rsp_buf :- add req_buf_sz to get to rsp_buf */
1014 return ((u8
*) fcxp_buf
) + mod
->req_pld_sz
;
1020 * @param[in] fcxp BFA fcxp pointer
1025 bfa_fcxp_free(struct bfa_fcxp_s
*fcxp
)
1027 struct bfa_fcxp_mod_s
*mod
= fcxp
->fcxp_mod
;
1029 WARN_ON(fcxp
== NULL
);
1030 bfa_trc(mod
->bfa
, fcxp
->fcxp_tag
);
1035 * Send a FCXP request
1037 * @param[in] fcxp BFA fcxp pointer
1038 * @param[in] rport BFA rport pointer. Could be left NULL for WKA rports
1039 * @param[in] vf_id virtual Fabric ID
1040 * @param[in] lp_tag lport tag
1041 * @param[in] cts use Continuous sequence
1042 * @param[in] cos fc Class of Service
1043 * @param[in] reqlen request length, does not include FCHS length
1044 * @param[in] fchs fc Header Pointer. The header content will be copied
1047 * @param[in] cbfn call back function to be called on receiving
1049 * @param[in] cbarg arg for cbfn
1050 * @param[in] rsp_timeout
1053 * @return bfa_status_t
1056 bfa_fcxp_send(struct bfa_fcxp_s
*fcxp
, struct bfa_rport_s
*rport
,
1057 u16 vf_id
, u8 lp_tag
, bfa_boolean_t cts
, enum fc_cos cos
,
1058 u32 reqlen
, struct fchs_s
*fchs
, bfa_cb_fcxp_send_t cbfn
,
1059 void *cbarg
, u32 rsp_maxlen
, u8 rsp_timeout
)
1061 struct bfa_s
*bfa
= fcxp
->fcxp_mod
->bfa
;
1062 struct bfa_fcxp_req_info_s
*reqi
= &fcxp
->req_info
;
1063 struct bfa_fcxp_rsp_info_s
*rspi
= &fcxp
->rsp_info
;
1064 struct bfi_fcxp_send_req_s
*send_req
;
1066 bfa_trc(bfa
, fcxp
->fcxp_tag
);
1069 * setup request/response info
1071 reqi
->bfa_rport
= rport
;
1072 reqi
->vf_id
= vf_id
;
1073 reqi
->lp_tag
= lp_tag
;
1075 rspi
->rsp_timeout
= rsp_timeout
;
1078 reqi
->req_tot_len
= reqlen
;
1079 rspi
->rsp_maxlen
= rsp_maxlen
;
1080 fcxp
->send_cbfn
= cbfn
? cbfn
: bfa_fcxp_null_comp
;
1081 fcxp
->send_cbarg
= cbarg
;
1084 * If no room in CPE queue, wait for space in request queue
1086 send_req
= bfa_reqq_next(bfa
, BFA_REQQ_FCXP
);
1088 bfa_trc(bfa
, fcxp
->fcxp_tag
);
1089 fcxp
->reqq_waiting
= BFA_TRUE
;
1090 bfa_reqq_wait(bfa
, BFA_REQQ_FCXP
, &fcxp
->reqq_wqe
);
1094 bfa_fcxp_queue(fcxp
, send_req
);
1100 * @param[in] fcxp BFA fcxp pointer
1105 bfa_fcxp_abort(struct bfa_fcxp_s
*fcxp
)
1107 bfa_trc(fcxp
->fcxp_mod
->bfa
, fcxp
->fcxp_tag
);
1109 return BFA_STATUS_OK
;
1113 bfa_fcxp_req_rsp_alloc_wait(struct bfa_s
*bfa
, struct bfa_fcxp_wqe_s
*wqe
,
1114 bfa_fcxp_alloc_cbfn_t alloc_cbfn
, void *alloc_cbarg
,
1115 void *caller
, int nreq_sgles
,
1116 int nrsp_sgles
, bfa_fcxp_get_sgaddr_t req_sga_cbfn
,
1117 bfa_fcxp_get_sglen_t req_sglen_cbfn
,
1118 bfa_fcxp_get_sgaddr_t rsp_sga_cbfn
,
1119 bfa_fcxp_get_sglen_t rsp_sglen_cbfn
, bfa_boolean_t req
)
1121 struct bfa_fcxp_mod_s
*mod
= BFA_FCXP_MOD(bfa
);
1124 WARN_ON(!list_empty(&mod
->fcxp_req_free_q
));
1126 WARN_ON(!list_empty(&mod
->fcxp_rsp_free_q
));
1128 wqe
->alloc_cbfn
= alloc_cbfn
;
1129 wqe
->alloc_cbarg
= alloc_cbarg
;
1130 wqe
->caller
= caller
;
1132 wqe
->nreq_sgles
= nreq_sgles
;
1133 wqe
->nrsp_sgles
= nrsp_sgles
;
1134 wqe
->req_sga_cbfn
= req_sga_cbfn
;
1135 wqe
->req_sglen_cbfn
= req_sglen_cbfn
;
1136 wqe
->rsp_sga_cbfn
= rsp_sga_cbfn
;
1137 wqe
->rsp_sglen_cbfn
= rsp_sglen_cbfn
;
1140 list_add_tail(&wqe
->qe
, &mod
->req_wait_q
);
1142 list_add_tail(&wqe
->qe
, &mod
->rsp_wait_q
);
1146 bfa_fcxp_walloc_cancel(struct bfa_s
*bfa
, struct bfa_fcxp_wqe_s
*wqe
)
1148 struct bfa_fcxp_mod_s
*mod
= BFA_FCXP_MOD(bfa
);
1150 WARN_ON(!bfa_q_is_on_q(&mod
->req_wait_q
, wqe
) ||
1151 !bfa_q_is_on_q(&mod
->rsp_wait_q
, wqe
));
1156 bfa_fcxp_discard(struct bfa_fcxp_s
*fcxp
)
1159 * If waiting for room in request queue, cancel reqq wait
1162 if (fcxp
->reqq_waiting
) {
1163 fcxp
->reqq_waiting
= BFA_FALSE
;
1164 bfa_reqq_wcancel(&fcxp
->reqq_wqe
);
1165 bfa_fcxp_free(fcxp
);
1169 fcxp
->send_cbfn
= bfa_fcxp_null_comp
;
1173 bfa_fcxp_isr(struct bfa_s
*bfa
, struct bfi_msg_s
*msg
)
1175 switch (msg
->mhdr
.msg_id
) {
1176 case BFI_FCXP_I2H_SEND_RSP
:
1177 hal_fcxp_send_comp(bfa
, (struct bfi_fcxp_send_rsp_s
*) msg
);
1181 bfa_trc(bfa
, msg
->mhdr
.msg_id
);
1187 bfa_fcxp_get_maxrsp(struct bfa_s
*bfa
)
1189 struct bfa_fcxp_mod_s
*mod
= BFA_FCXP_MOD(bfa
);
1191 return mod
->rsp_pld_sz
;
1195 bfa_fcxp_res_recfg(struct bfa_s
*bfa
, u16 num_fcxp_fw
)
1197 struct bfa_fcxp_mod_s
*mod
= BFA_FCXP_MOD(bfa
);
1198 struct list_head
*qe
;
1201 for (i
= 0; i
< (mod
->num_fcxps
- num_fcxp_fw
); i
++) {
1202 if (i
< ((mod
->num_fcxps
- num_fcxp_fw
) / 2)) {
1203 bfa_q_deq_tail(&mod
->fcxp_req_free_q
, &qe
);
1204 list_add_tail(qe
, &mod
->fcxp_req_unused_q
);
1206 bfa_q_deq_tail(&mod
->fcxp_rsp_free_q
, &qe
);
1207 list_add_tail(qe
, &mod
->fcxp_rsp_unused_q
);
1213 * BFA LPS state machine functions
1217 * Init state -- no login
1220 bfa_lps_sm_init(struct bfa_lps_s
*lps
, enum bfa_lps_event event
)
1222 bfa_trc(lps
->bfa
, lps
->bfa_tag
);
1223 bfa_trc(lps
->bfa
, event
);
1226 case BFA_LPS_SM_LOGIN
:
1227 if (bfa_reqq_full(lps
->bfa
, lps
->reqq
)) {
1228 bfa_sm_set_state(lps
, bfa_lps_sm_loginwait
);
1229 bfa_reqq_wait(lps
->bfa
, lps
->reqq
, &lps
->wqe
);
1231 bfa_sm_set_state(lps
, bfa_lps_sm_login
);
1232 bfa_lps_send_login(lps
);
1236 bfa_plog_str(lps
->bfa
->plog
, BFA_PL_MID_LPS
,
1237 BFA_PL_EID_LOGIN
, 0, "FDISC Request");
1239 bfa_plog_str(lps
->bfa
->plog
, BFA_PL_MID_LPS
,
1240 BFA_PL_EID_LOGIN
, 0, "FLOGI Request");
1243 case BFA_LPS_SM_LOGOUT
:
1244 bfa_lps_logout_comp(lps
);
1247 case BFA_LPS_SM_DELETE
:
1251 case BFA_LPS_SM_RX_CVL
:
1252 case BFA_LPS_SM_OFFLINE
:
1255 case BFA_LPS_SM_FWRSP
:
1257 * Could happen when fabric detects loopback and discards
1258 * the lps request. Fw will eventually sent out the timeout
1262 case BFA_LPS_SM_SET_N2N_PID
:
1264 * When topology is set to loop, bfa_lps_set_n2n_pid() sends
1265 * this event. Ignore this event.
1270 bfa_sm_fault(lps
->bfa
, event
);
1275 * login is in progress -- awaiting response from firmware
1278 bfa_lps_sm_login(struct bfa_lps_s
*lps
, enum bfa_lps_event event
)
1280 bfa_trc(lps
->bfa
, lps
->bfa_tag
);
1281 bfa_trc(lps
->bfa
, event
);
1284 case BFA_LPS_SM_FWRSP
:
1285 if (lps
->status
== BFA_STATUS_OK
) {
1286 bfa_sm_set_state(lps
, bfa_lps_sm_online
);
1288 bfa_plog_str(lps
->bfa
->plog
, BFA_PL_MID_LPS
,
1289 BFA_PL_EID_LOGIN
, 0, "FDISC Accept");
1291 bfa_plog_str(lps
->bfa
->plog
, BFA_PL_MID_LPS
,
1292 BFA_PL_EID_LOGIN
, 0, "FLOGI Accept");
1293 /* If N2N, send the assigned PID to FW */
1294 bfa_trc(lps
->bfa
, lps
->fport
);
1295 bfa_trc(lps
->bfa
, lps
->lp_pid
);
1297 if (!lps
->fport
&& lps
->lp_pid
)
1298 bfa_sm_send_event(lps
, BFA_LPS_SM_SET_N2N_PID
);
1300 bfa_sm_set_state(lps
, bfa_lps_sm_init
);
1302 bfa_plog_str(lps
->bfa
->plog
, BFA_PL_MID_LPS
,
1303 BFA_PL_EID_LOGIN
, 0,
1304 "FDISC Fail (RJT or timeout)");
1306 bfa_plog_str(lps
->bfa
->plog
, BFA_PL_MID_LPS
,
1307 BFA_PL_EID_LOGIN
, 0,
1308 "FLOGI Fail (RJT or timeout)");
1310 bfa_lps_login_comp(lps
);
1313 case BFA_LPS_SM_OFFLINE
:
1314 case BFA_LPS_SM_DELETE
:
1315 bfa_sm_set_state(lps
, bfa_lps_sm_init
);
1318 case BFA_LPS_SM_SET_N2N_PID
:
1319 bfa_trc(lps
->bfa
, lps
->fport
);
1320 bfa_trc(lps
->bfa
, lps
->lp_pid
);
1324 bfa_sm_fault(lps
->bfa
, event
);
1329 * login pending - awaiting space in request queue
1332 bfa_lps_sm_loginwait(struct bfa_lps_s
*lps
, enum bfa_lps_event event
)
1334 bfa_trc(lps
->bfa
, lps
->bfa_tag
);
1335 bfa_trc(lps
->bfa
, event
);
1338 case BFA_LPS_SM_RESUME
:
1339 bfa_sm_set_state(lps
, bfa_lps_sm_login
);
1340 bfa_lps_send_login(lps
);
1343 case BFA_LPS_SM_OFFLINE
:
1344 case BFA_LPS_SM_DELETE
:
1345 bfa_sm_set_state(lps
, bfa_lps_sm_init
);
1346 bfa_reqq_wcancel(&lps
->wqe
);
1349 case BFA_LPS_SM_RX_CVL
:
1351 * Login was not even sent out; so when getting out
1352 * of this state, it will appear like a login retry
1353 * after Clear virtual link
1358 bfa_sm_fault(lps
->bfa
, event
);
1366 bfa_lps_sm_online(struct bfa_lps_s
*lps
, enum bfa_lps_event event
)
1368 bfa_trc(lps
->bfa
, lps
->bfa_tag
);
1369 bfa_trc(lps
->bfa
, event
);
1372 case BFA_LPS_SM_LOGOUT
:
1373 if (bfa_reqq_full(lps
->bfa
, lps
->reqq
)) {
1374 bfa_sm_set_state(lps
, bfa_lps_sm_logowait
);
1375 bfa_reqq_wait(lps
->bfa
, lps
->reqq
, &lps
->wqe
);
1377 bfa_sm_set_state(lps
, bfa_lps_sm_logout
);
1378 bfa_lps_send_logout(lps
);
1380 bfa_plog_str(lps
->bfa
->plog
, BFA_PL_MID_LPS
,
1381 BFA_PL_EID_LOGO
, 0, "Logout");
1384 case BFA_LPS_SM_RX_CVL
:
1385 bfa_sm_set_state(lps
, bfa_lps_sm_init
);
1387 /* Let the vport module know about this event */
1388 bfa_lps_cvl_event(lps
);
1389 bfa_plog_str(lps
->bfa
->plog
, BFA_PL_MID_LPS
,
1390 BFA_PL_EID_FIP_FCF_CVL
, 0, "FCF Clear Virt. Link Rx");
1393 case BFA_LPS_SM_SET_N2N_PID
:
1394 if (bfa_reqq_full(lps
->bfa
, lps
->reqq
)) {
1395 bfa_sm_set_state(lps
, bfa_lps_sm_online_n2n_pid_wait
);
1396 bfa_reqq_wait(lps
->bfa
, lps
->reqq
, &lps
->wqe
);
1398 bfa_lps_send_set_n2n_pid(lps
);
1401 case BFA_LPS_SM_OFFLINE
:
1402 case BFA_LPS_SM_DELETE
:
1403 bfa_sm_set_state(lps
, bfa_lps_sm_init
);
1407 bfa_sm_fault(lps
->bfa
, event
);
1415 bfa_lps_sm_online_n2n_pid_wait(struct bfa_lps_s
*lps
, enum bfa_lps_event event
)
1417 bfa_trc(lps
->bfa
, lps
->bfa_tag
);
1418 bfa_trc(lps
->bfa
, event
);
1421 case BFA_LPS_SM_RESUME
:
1422 bfa_sm_set_state(lps
, bfa_lps_sm_online
);
1423 bfa_lps_send_set_n2n_pid(lps
);
1426 case BFA_LPS_SM_LOGOUT
:
1427 bfa_sm_set_state(lps
, bfa_lps_sm_logowait
);
1428 bfa_plog_str(lps
->bfa
->plog
, BFA_PL_MID_LPS
,
1429 BFA_PL_EID_LOGO
, 0, "Logout");
1432 case BFA_LPS_SM_RX_CVL
:
1433 bfa_sm_set_state(lps
, bfa_lps_sm_init
);
1434 bfa_reqq_wcancel(&lps
->wqe
);
1436 /* Let the vport module know about this event */
1437 bfa_lps_cvl_event(lps
);
1438 bfa_plog_str(lps
->bfa
->plog
, BFA_PL_MID_LPS
,
1439 BFA_PL_EID_FIP_FCF_CVL
, 0, "FCF Clear Virt. Link Rx");
1442 case BFA_LPS_SM_OFFLINE
:
1443 case BFA_LPS_SM_DELETE
:
1444 bfa_sm_set_state(lps
, bfa_lps_sm_init
);
1445 bfa_reqq_wcancel(&lps
->wqe
);
1449 bfa_sm_fault(lps
->bfa
, event
);
1454 * logout in progress - awaiting firmware response
1457 bfa_lps_sm_logout(struct bfa_lps_s
*lps
, enum bfa_lps_event event
)
1459 bfa_trc(lps
->bfa
, lps
->bfa_tag
);
1460 bfa_trc(lps
->bfa
, event
);
1463 case BFA_LPS_SM_FWRSP
:
1464 case BFA_LPS_SM_OFFLINE
:
1465 bfa_sm_set_state(lps
, bfa_lps_sm_init
);
1466 bfa_lps_logout_comp(lps
);
1469 case BFA_LPS_SM_DELETE
:
1470 bfa_sm_set_state(lps
, bfa_lps_sm_init
);
1474 bfa_sm_fault(lps
->bfa
, event
);
1479 * logout pending -- awaiting space in request queue
1482 bfa_lps_sm_logowait(struct bfa_lps_s
*lps
, enum bfa_lps_event event
)
1484 bfa_trc(lps
->bfa
, lps
->bfa_tag
);
1485 bfa_trc(lps
->bfa
, event
);
1488 case BFA_LPS_SM_RESUME
:
1489 bfa_sm_set_state(lps
, bfa_lps_sm_logout
);
1490 bfa_lps_send_logout(lps
);
1493 case BFA_LPS_SM_OFFLINE
:
1494 case BFA_LPS_SM_DELETE
:
1495 bfa_sm_set_state(lps
, bfa_lps_sm_init
);
1496 bfa_reqq_wcancel(&lps
->wqe
);
1500 bfa_sm_fault(lps
->bfa
, event
);
1507 * lps_pvt BFA LPS private functions
1511 * return memory requirement
1514 bfa_lps_meminfo(struct bfa_iocfc_cfg_s
*cfg
, struct bfa_meminfo_s
*minfo
,
1517 struct bfa_mem_kva_s
*lps_kva
= BFA_MEM_LPS_KVA(bfa
);
1519 if (cfg
->drvcfg
.min_cfg
)
1520 bfa_mem_kva_setup(minfo
, lps_kva
,
1521 sizeof(struct bfa_lps_s
) * BFA_LPS_MIN_LPORTS
);
1523 bfa_mem_kva_setup(minfo
, lps_kva
,
1524 sizeof(struct bfa_lps_s
) * BFA_LPS_MAX_LPORTS
);
1528 * bfa module attach at initialization time
1531 bfa_lps_attach(struct bfa_s
*bfa
, void *bfad
, struct bfa_iocfc_cfg_s
*cfg
,
1532 struct bfa_pcidev_s
*pcidev
)
1534 struct bfa_lps_mod_s
*mod
= BFA_LPS_MOD(bfa
);
1535 struct bfa_lps_s
*lps
;
1538 mod
->num_lps
= BFA_LPS_MAX_LPORTS
;
1539 if (cfg
->drvcfg
.min_cfg
)
1540 mod
->num_lps
= BFA_LPS_MIN_LPORTS
;
1542 mod
->num_lps
= BFA_LPS_MAX_LPORTS
;
1543 mod
->lps_arr
= lps
= (struct bfa_lps_s
*) bfa_mem_kva_curp(mod
);
1545 bfa_mem_kva_curp(mod
) += mod
->num_lps
* sizeof(struct bfa_lps_s
);
1547 INIT_LIST_HEAD(&mod
->lps_free_q
);
1548 INIT_LIST_HEAD(&mod
->lps_active_q
);
1549 INIT_LIST_HEAD(&mod
->lps_login_q
);
1551 for (i
= 0; i
< mod
->num_lps
; i
++, lps
++) {
1553 lps
->bfa_tag
= (u8
) i
;
1554 lps
->reqq
= BFA_REQQ_LPS
;
1555 bfa_reqq_winit(&lps
->wqe
, bfa_lps_reqq_resume
, lps
);
1556 list_add_tail(&lps
->qe
, &mod
->lps_free_q
);
1561 bfa_lps_detach(struct bfa_s
*bfa
)
1566 bfa_lps_start(struct bfa_s
*bfa
)
1571 bfa_lps_stop(struct bfa_s
*bfa
)
1576 * IOC in disabled state -- consider all lps offline
1579 bfa_lps_iocdisable(struct bfa_s
*bfa
)
1581 struct bfa_lps_mod_s
*mod
= BFA_LPS_MOD(bfa
);
1582 struct bfa_lps_s
*lps
;
1583 struct list_head
*qe
, *qen
;
1585 list_for_each_safe(qe
, qen
, &mod
->lps_active_q
) {
1586 lps
= (struct bfa_lps_s
*) qe
;
1587 bfa_sm_send_event(lps
, BFA_LPS_SM_OFFLINE
);
1589 list_for_each_safe(qe
, qen
, &mod
->lps_login_q
) {
1590 lps
= (struct bfa_lps_s
*) qe
;
1591 bfa_sm_send_event(lps
, BFA_LPS_SM_OFFLINE
);
1593 list_splice_tail_init(&mod
->lps_login_q
, &mod
->lps_active_q
);
1597 * Firmware login response
1600 bfa_lps_login_rsp(struct bfa_s
*bfa
, struct bfi_lps_login_rsp_s
*rsp
)
1602 struct bfa_lps_mod_s
*mod
= BFA_LPS_MOD(bfa
);
1603 struct bfa_lps_s
*lps
;
1605 WARN_ON(rsp
->bfa_tag
>= mod
->num_lps
);
1606 lps
= BFA_LPS_FROM_TAG(mod
, rsp
->bfa_tag
);
1608 lps
->status
= rsp
->status
;
1609 switch (rsp
->status
) {
1611 lps
->fw_tag
= rsp
->fw_tag
;
1612 lps
->fport
= rsp
->f_port
;
1614 lps
->lp_pid
= rsp
->lp_pid
;
1615 lps
->npiv_en
= rsp
->npiv_en
;
1616 lps
->pr_bbcred
= be16_to_cpu(rsp
->bb_credit
);
1617 lps
->pr_pwwn
= rsp
->port_name
;
1618 lps
->pr_nwwn
= rsp
->node_name
;
1619 lps
->auth_req
= rsp
->auth_req
;
1620 lps
->lp_mac
= rsp
->lp_mac
;
1621 lps
->brcd_switch
= rsp
->brcd_switch
;
1622 lps
->fcf_mac
= rsp
->fcf_mac
;
1626 case BFA_STATUS_FABRIC_RJT
:
1627 lps
->lsrjt_rsn
= rsp
->lsrjt_rsn
;
1628 lps
->lsrjt_expl
= rsp
->lsrjt_expl
;
1632 case BFA_STATUS_EPROTOCOL
:
1633 lps
->ext_status
= rsp
->ext_status
;
1637 case BFA_STATUS_VPORT_MAX
:
1638 if (rsp
->ext_status
)
1639 bfa_lps_no_res(lps
, rsp
->ext_status
);
1643 /* Nothing to do with other status */
1648 list_add_tail(&lps
->qe
, &mod
->lps_active_q
);
1649 bfa_sm_send_event(lps
, BFA_LPS_SM_FWRSP
);
1653 bfa_lps_no_res(struct bfa_lps_s
*first_lps
, u8 count
)
1655 struct bfa_s
*bfa
= first_lps
->bfa
;
1656 struct bfa_lps_mod_s
*mod
= BFA_LPS_MOD(bfa
);
1657 struct list_head
*qe
, *qe_next
;
1658 struct bfa_lps_s
*lps
;
1660 bfa_trc(bfa
, count
);
1662 qe
= bfa_q_next(first_lps
);
1664 while (count
&& qe
) {
1665 qe_next
= bfa_q_next(qe
);
1666 lps
= (struct bfa_lps_s
*)qe
;
1667 bfa_trc(bfa
, lps
->bfa_tag
);
1668 lps
->status
= first_lps
->status
;
1670 list_add_tail(&lps
->qe
, &mod
->lps_active_q
);
1671 bfa_sm_send_event(lps
, BFA_LPS_SM_FWRSP
);
1678 * Firmware logout response
1681 bfa_lps_logout_rsp(struct bfa_s
*bfa
, struct bfi_lps_logout_rsp_s
*rsp
)
1683 struct bfa_lps_mod_s
*mod
= BFA_LPS_MOD(bfa
);
1684 struct bfa_lps_s
*lps
;
1686 WARN_ON(rsp
->bfa_tag
>= mod
->num_lps
);
1687 lps
= BFA_LPS_FROM_TAG(mod
, rsp
->bfa_tag
);
1689 bfa_sm_send_event(lps
, BFA_LPS_SM_FWRSP
);
1693 * Firmware received a Clear virtual link request (for FCoE)
1696 bfa_lps_rx_cvl_event(struct bfa_s
*bfa
, struct bfi_lps_cvl_event_s
*cvl
)
1698 struct bfa_lps_mod_s
*mod
= BFA_LPS_MOD(bfa
);
1699 struct bfa_lps_s
*lps
;
1701 lps
= BFA_LPS_FROM_TAG(mod
, cvl
->bfa_tag
);
1703 bfa_sm_send_event(lps
, BFA_LPS_SM_RX_CVL
);
1707 * Space is available in request queue, resume queueing request to firmware.
1710 bfa_lps_reqq_resume(void *lps_arg
)
1712 struct bfa_lps_s
*lps
= lps_arg
;
1714 bfa_sm_send_event(lps
, BFA_LPS_SM_RESUME
);
1718 * lps is freed -- triggered by vport delete
1721 bfa_lps_free(struct bfa_lps_s
*lps
)
1723 struct bfa_lps_mod_s
*mod
= BFA_LPS_MOD(lps
->bfa
);
1727 list_add_tail(&lps
->qe
, &mod
->lps_free_q
);
1731 * send login request to firmware
1734 bfa_lps_send_login(struct bfa_lps_s
*lps
)
1736 struct bfa_lps_mod_s
*mod
= BFA_LPS_MOD(lps
->bfa
);
1737 struct bfi_lps_login_req_s
*m
;
1739 m
= bfa_reqq_next(lps
->bfa
, lps
->reqq
);
1742 bfi_h2i_set(m
->mh
, BFI_MC_LPS
, BFI_LPS_H2I_LOGIN_REQ
,
1743 bfa_fn_lpu(lps
->bfa
));
1745 m
->bfa_tag
= lps
->bfa_tag
;
1746 m
->alpa
= lps
->alpa
;
1747 m
->pdu_size
= cpu_to_be16(lps
->pdusz
);
1748 m
->pwwn
= lps
->pwwn
;
1749 m
->nwwn
= lps
->nwwn
;
1750 m
->fdisc
= lps
->fdisc
;
1751 m
->auth_en
= lps
->auth_en
;
1753 bfa_reqq_produce(lps
->bfa
, lps
->reqq
, m
->mh
);
1755 list_add_tail(&lps
->qe
, &mod
->lps_login_q
);
1759 * send logout request to firmware
1762 bfa_lps_send_logout(struct bfa_lps_s
*lps
)
1764 struct bfi_lps_logout_req_s
*m
;
1766 m
= bfa_reqq_next(lps
->bfa
, lps
->reqq
);
1769 bfi_h2i_set(m
->mh
, BFI_MC_LPS
, BFI_LPS_H2I_LOGOUT_REQ
,
1770 bfa_fn_lpu(lps
->bfa
));
1772 m
->fw_tag
= lps
->fw_tag
;
1773 m
->port_name
= lps
->pwwn
;
1774 bfa_reqq_produce(lps
->bfa
, lps
->reqq
, m
->mh
);
1778 * send n2n pid set request to firmware
1781 bfa_lps_send_set_n2n_pid(struct bfa_lps_s
*lps
)
1783 struct bfi_lps_n2n_pid_req_s
*m
;
1785 m
= bfa_reqq_next(lps
->bfa
, lps
->reqq
);
1788 bfi_h2i_set(m
->mh
, BFI_MC_LPS
, BFI_LPS_H2I_N2N_PID_REQ
,
1789 bfa_fn_lpu(lps
->bfa
));
1791 m
->fw_tag
= lps
->fw_tag
;
1792 m
->lp_pid
= lps
->lp_pid
;
1793 bfa_reqq_produce(lps
->bfa
, lps
->reqq
, m
->mh
);
1797 * Indirect login completion handler for non-fcs
1800 bfa_lps_login_comp_cb(void *arg
, bfa_boolean_t complete
)
1802 struct bfa_lps_s
*lps
= arg
;
1808 bfa_cb_lps_fdisc_comp(lps
->bfa
->bfad
, lps
->uarg
, lps
->status
);
1810 bfa_cb_lps_flogi_comp(lps
->bfa
->bfad
, lps
->uarg
, lps
->status
);
1814 * Login completion handler -- direct call for fcs, queue for others
1817 bfa_lps_login_comp(struct bfa_lps_s
*lps
)
1819 if (!lps
->bfa
->fcs
) {
1820 bfa_cb_queue(lps
->bfa
, &lps
->hcb_qe
, bfa_lps_login_comp_cb
,
1826 bfa_cb_lps_fdisc_comp(lps
->bfa
->bfad
, lps
->uarg
, lps
->status
);
1828 bfa_cb_lps_flogi_comp(lps
->bfa
->bfad
, lps
->uarg
, lps
->status
);
1832 * Indirect logout completion handler for non-fcs
1835 bfa_lps_logout_comp_cb(void *arg
, bfa_boolean_t complete
)
1837 struct bfa_lps_s
*lps
= arg
;
1843 bfa_cb_lps_fdisclogo_comp(lps
->bfa
->bfad
, lps
->uarg
);
1845 bfa_cb_lps_flogo_comp(lps
->bfa
->bfad
, lps
->uarg
);
1849 * Logout completion handler -- direct call for fcs, queue for others
1852 bfa_lps_logout_comp(struct bfa_lps_s
*lps
)
1854 if (!lps
->bfa
->fcs
) {
1855 bfa_cb_queue(lps
->bfa
, &lps
->hcb_qe
, bfa_lps_logout_comp_cb
,
1860 bfa_cb_lps_fdisclogo_comp(lps
->bfa
->bfad
, lps
->uarg
);
1864 * Clear virtual link completion handler for non-fcs
1867 bfa_lps_cvl_event_cb(void *arg
, bfa_boolean_t complete
)
1869 struct bfa_lps_s
*lps
= arg
;
1874 /* Clear virtual link to base port will result in link down */
1876 bfa_cb_lps_cvl_event(lps
->bfa
->bfad
, lps
->uarg
);
1880 * Received Clear virtual link event --direct call for fcs,
1884 bfa_lps_cvl_event(struct bfa_lps_s
*lps
)
1886 if (!lps
->bfa
->fcs
) {
1887 bfa_cb_queue(lps
->bfa
, &lps
->hcb_qe
, bfa_lps_cvl_event_cb
,
1892 /* Clear virtual link to base port will result in link down */
1894 bfa_cb_lps_cvl_event(lps
->bfa
->bfad
, lps
->uarg
);
1900 * lps_public BFA LPS public functions
1904 bfa_lps_get_max_vport(struct bfa_s
*bfa
)
1906 if (bfa_ioc_devid(&bfa
->ioc
) == BFA_PCI_DEVICE_ID_CT
)
1907 return BFA_LPS_MAX_VPORTS_SUPP_CT
;
1909 return BFA_LPS_MAX_VPORTS_SUPP_CB
;
1913 * Allocate a lport srvice tag.
1916 bfa_lps_alloc(struct bfa_s
*bfa
)
1918 struct bfa_lps_mod_s
*mod
= BFA_LPS_MOD(bfa
);
1919 struct bfa_lps_s
*lps
= NULL
;
1921 bfa_q_deq(&mod
->lps_free_q
, &lps
);
1926 list_add_tail(&lps
->qe
, &mod
->lps_active_q
);
1928 bfa_sm_set_state(lps
, bfa_lps_sm_init
);
1933 * Free lport service tag. This can be called anytime after an alloc.
1934 * No need to wait for any pending login/logout completions.
1937 bfa_lps_delete(struct bfa_lps_s
*lps
)
1939 bfa_sm_send_event(lps
, BFA_LPS_SM_DELETE
);
1943 * Initiate a lport login.
1946 bfa_lps_flogi(struct bfa_lps_s
*lps
, void *uarg
, u8 alpa
, u16 pdusz
,
1947 wwn_t pwwn
, wwn_t nwwn
, bfa_boolean_t auth_en
)
1954 lps
->fdisc
= BFA_FALSE
;
1955 lps
->auth_en
= auth_en
;
1956 bfa_sm_send_event(lps
, BFA_LPS_SM_LOGIN
);
1960 * Initiate a lport fdisc login.
1963 bfa_lps_fdisc(struct bfa_lps_s
*lps
, void *uarg
, u16 pdusz
, wwn_t pwwn
,
1971 lps
->fdisc
= BFA_TRUE
;
1972 lps
->auth_en
= BFA_FALSE
;
1973 bfa_sm_send_event(lps
, BFA_LPS_SM_LOGIN
);
1978 * Initiate a lport FDSIC logout.
1981 bfa_lps_fdisclogo(struct bfa_lps_s
*lps
)
1983 bfa_sm_send_event(lps
, BFA_LPS_SM_LOGOUT
);
1987 bfa_lps_get_fwtag(struct bfa_s
*bfa
, u8 lp_tag
)
1989 struct bfa_lps_mod_s
*mod
= BFA_LPS_MOD(bfa
);
1991 return BFA_LPS_FROM_TAG(mod
, lp_tag
)->fw_tag
;
1995 * Return lport services tag given the pid
1998 bfa_lps_get_tag_from_pid(struct bfa_s
*bfa
, u32 pid
)
2000 struct bfa_lps_mod_s
*mod
= BFA_LPS_MOD(bfa
);
2001 struct bfa_lps_s
*lps
;
2004 for (i
= 0, lps
= mod
->lps_arr
; i
< mod
->num_lps
; i
++, lps
++) {
2005 if (lps
->lp_pid
== pid
)
2006 return lps
->bfa_tag
;
2009 /* Return base port tag anyway */
2015 * return port id assigned to the base lport
2018 bfa_lps_get_base_pid(struct bfa_s
*bfa
)
2020 struct bfa_lps_mod_s
*mod
= BFA_LPS_MOD(bfa
);
2022 return BFA_LPS_FROM_TAG(mod
, 0)->lp_pid
;
2026 * Set PID in case of n2n (which is assigned during PLOGI)
2029 bfa_lps_set_n2n_pid(struct bfa_lps_s
*lps
, uint32_t n2n_pid
)
2031 bfa_trc(lps
->bfa
, lps
->bfa_tag
);
2032 bfa_trc(lps
->bfa
, n2n_pid
);
2034 lps
->lp_pid
= n2n_pid
;
2035 bfa_sm_send_event(lps
, BFA_LPS_SM_SET_N2N_PID
);
2039 * LPS firmware message class handler.
2042 bfa_lps_isr(struct bfa_s
*bfa
, struct bfi_msg_s
*m
)
2044 union bfi_lps_i2h_msg_u msg
;
2046 bfa_trc(bfa
, m
->mhdr
.msg_id
);
2049 switch (m
->mhdr
.msg_id
) {
2050 case BFI_LPS_I2H_LOGIN_RSP
:
2051 bfa_lps_login_rsp(bfa
, msg
.login_rsp
);
2054 case BFI_LPS_I2H_LOGOUT_RSP
:
2055 bfa_lps_logout_rsp(bfa
, msg
.logout_rsp
);
2058 case BFI_LPS_I2H_CVL_EVENT
:
2059 bfa_lps_rx_cvl_event(bfa
, msg
.cvl_event
);
2063 bfa_trc(bfa
, m
->mhdr
.msg_id
);
2069 bfa_fcport_aen_post(struct bfa_fcport_s
*fcport
, enum bfa_port_aen_event event
)
2071 struct bfad_s
*bfad
= (struct bfad_s
*)fcport
->bfa
->bfad
;
2072 struct bfa_aen_entry_s
*aen_entry
;
2074 bfad_get_aen_entry(bfad
, aen_entry
);
2078 aen_entry
->aen_data
.port
.ioc_type
= bfa_get_type(fcport
->bfa
);
2079 aen_entry
->aen_data
.port
.pwwn
= fcport
->pwwn
;
2081 /* Send the AEN notification */
2082 bfad_im_post_vendor_event(aen_entry
, bfad
, ++fcport
->bfa
->bfa_aen_seq
,
2083 BFA_AEN_CAT_PORT
, event
);
2087 * FC PORT state machine functions
2090 bfa_fcport_sm_uninit(struct bfa_fcport_s
*fcport
,
2091 enum bfa_fcport_sm_event event
)
2093 bfa_trc(fcport
->bfa
, event
);
2096 case BFA_FCPORT_SM_START
:
2098 * Start event after IOC is configured and BFA is started.
2100 fcport
->use_flash_cfg
= BFA_TRUE
;
2102 if (bfa_fcport_send_enable(fcport
)) {
2103 bfa_trc(fcport
->bfa
, BFA_TRUE
);
2104 bfa_sm_set_state(fcport
, bfa_fcport_sm_enabling
);
2106 bfa_trc(fcport
->bfa
, BFA_FALSE
);
2107 bfa_sm_set_state(fcport
,
2108 bfa_fcport_sm_enabling_qwait
);
2112 case BFA_FCPORT_SM_ENABLE
:
2114 * Port is persistently configured to be in enabled state. Do
2115 * not change state. Port enabling is done when START event is
2120 case BFA_FCPORT_SM_DISABLE
:
2122 * If a port is persistently configured to be disabled, the
2123 * first event will a port disable request.
2125 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabled
);
2128 case BFA_FCPORT_SM_HWFAIL
:
2129 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocdown
);
2133 bfa_sm_fault(fcport
->bfa
, event
);
2138 bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s
*fcport
,
2139 enum bfa_fcport_sm_event event
)
2141 char pwwn_buf
[BFA_STRING_32
];
2142 struct bfad_s
*bfad
= (struct bfad_s
*)fcport
->bfa
->bfad
;
2143 bfa_trc(fcport
->bfa
, event
);
2146 case BFA_FCPORT_SM_QRESUME
:
2147 bfa_sm_set_state(fcport
, bfa_fcport_sm_enabling
);
2148 bfa_fcport_send_enable(fcport
);
2151 case BFA_FCPORT_SM_STOP
:
2152 bfa_reqq_wcancel(&fcport
->reqq_wait
);
2153 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
2156 case BFA_FCPORT_SM_ENABLE
:
2158 * Already enable is in progress.
2162 case BFA_FCPORT_SM_DISABLE
:
2164 * Just send disable request to firmware when room becomes
2165 * available in request queue.
2167 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabled
);
2168 bfa_reqq_wcancel(&fcport
->reqq_wait
);
2169 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
2170 BFA_PL_EID_PORT_DISABLE
, 0, "Port Disable");
2171 wwn2str(pwwn_buf
, fcport
->pwwn
);
2172 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
,
2173 "Base port disabled: WWN = %s\n", pwwn_buf
);
2174 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISABLE
);
2177 case BFA_FCPORT_SM_LINKUP
:
2178 case BFA_FCPORT_SM_LINKDOWN
:
2180 * Possible to get link events when doing back-to-back
2185 case BFA_FCPORT_SM_HWFAIL
:
2186 bfa_reqq_wcancel(&fcport
->reqq_wait
);
2187 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocdown
);
2190 case BFA_FCPORT_SM_FAA_MISCONFIG
:
2191 bfa_fcport_reset_linkinfo(fcport
);
2192 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISCONNECT
);
2193 bfa_sm_set_state(fcport
, bfa_fcport_sm_faa_misconfig
);
2197 bfa_sm_fault(fcport
->bfa
, event
);
2202 bfa_fcport_sm_enabling(struct bfa_fcport_s
*fcport
,
2203 enum bfa_fcport_sm_event event
)
2205 char pwwn_buf
[BFA_STRING_32
];
2206 struct bfad_s
*bfad
= (struct bfad_s
*)fcport
->bfa
->bfad
;
2207 bfa_trc(fcport
->bfa
, event
);
2210 case BFA_FCPORT_SM_FWRSP
:
2211 case BFA_FCPORT_SM_LINKDOWN
:
2212 bfa_sm_set_state(fcport
, bfa_fcport_sm_linkdown
);
2215 case BFA_FCPORT_SM_LINKUP
:
2216 bfa_fcport_update_linkinfo(fcport
);
2217 bfa_sm_set_state(fcport
, bfa_fcport_sm_linkup
);
2219 WARN_ON(!fcport
->event_cbfn
);
2220 bfa_fcport_scn(fcport
, BFA_PORT_LINKUP
, BFA_FALSE
);
2223 case BFA_FCPORT_SM_ENABLE
:
2225 * Already being enabled.
2229 case BFA_FCPORT_SM_DISABLE
:
2230 if (bfa_fcport_send_disable(fcport
))
2231 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabling
);
2233 bfa_sm_set_state(fcport
,
2234 bfa_fcport_sm_disabling_qwait
);
2236 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
2237 BFA_PL_EID_PORT_DISABLE
, 0, "Port Disable");
2238 wwn2str(pwwn_buf
, fcport
->pwwn
);
2239 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
,
2240 "Base port disabled: WWN = %s\n", pwwn_buf
);
2241 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISABLE
);
2244 case BFA_FCPORT_SM_STOP
:
2245 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
2248 case BFA_FCPORT_SM_HWFAIL
:
2249 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocdown
);
2252 case BFA_FCPORT_SM_FAA_MISCONFIG
:
2253 bfa_fcport_reset_linkinfo(fcport
);
2254 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISCONNECT
);
2255 bfa_sm_set_state(fcport
, bfa_fcport_sm_faa_misconfig
);
2259 bfa_sm_fault(fcport
->bfa
, event
);
2264 bfa_fcport_sm_linkdown(struct bfa_fcport_s
*fcport
,
2265 enum bfa_fcport_sm_event event
)
2267 struct bfi_fcport_event_s
*pevent
= fcport
->event_arg
.i2hmsg
.event
;
2268 char pwwn_buf
[BFA_STRING_32
];
2269 struct bfad_s
*bfad
= (struct bfad_s
*)fcport
->bfa
->bfad
;
2271 bfa_trc(fcport
->bfa
, event
);
2274 case BFA_FCPORT_SM_LINKUP
:
2275 bfa_fcport_update_linkinfo(fcport
);
2276 bfa_sm_set_state(fcport
, bfa_fcport_sm_linkup
);
2277 WARN_ON(!fcport
->event_cbfn
);
2278 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
2279 BFA_PL_EID_PORT_ST_CHANGE
, 0, "Port Linkup");
2280 if (!bfa_ioc_get_fcmode(&fcport
->bfa
->ioc
)) {
2282 bfa_trc(fcport
->bfa
,
2283 pevent
->link_state
.attr
.vc_fcf
.fcf
.fipenabled
);
2284 bfa_trc(fcport
->bfa
,
2285 pevent
->link_state
.attr
.vc_fcf
.fcf
.fipfailed
);
2287 if (pevent
->link_state
.attr
.vc_fcf
.fcf
.fipfailed
)
2288 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
2289 BFA_PL_EID_FIP_FCF_DISC
, 0,
2290 "FIP FCF Discovery Failed");
2292 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
2293 BFA_PL_EID_FIP_FCF_DISC
, 0,
2294 "FIP FCF Discovered");
2297 bfa_fcport_scn(fcport
, BFA_PORT_LINKUP
, BFA_FALSE
);
2298 wwn2str(pwwn_buf
, fcport
->pwwn
);
2299 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
,
2300 "Base port online: WWN = %s\n", pwwn_buf
);
2301 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_ONLINE
);
2303 /* If QoS is enabled and it is not online, send AEN */
2304 if (fcport
->cfg
.qos_enabled
&&
2305 fcport
->qos_attr
.state
!= BFA_QOS_ONLINE
)
2306 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_QOS_NEG
);
2309 case BFA_FCPORT_SM_LINKDOWN
:
2311 * Possible to get link down event.
2315 case BFA_FCPORT_SM_ENABLE
:
2321 case BFA_FCPORT_SM_DISABLE
:
2322 if (bfa_fcport_send_disable(fcport
))
2323 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabling
);
2325 bfa_sm_set_state(fcport
,
2326 bfa_fcport_sm_disabling_qwait
);
2328 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
2329 BFA_PL_EID_PORT_DISABLE
, 0, "Port Disable");
2330 wwn2str(pwwn_buf
, fcport
->pwwn
);
2331 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
,
2332 "Base port disabled: WWN = %s\n", pwwn_buf
);
2333 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISABLE
);
2336 case BFA_FCPORT_SM_STOP
:
2337 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
2340 case BFA_FCPORT_SM_HWFAIL
:
2341 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocdown
);
2344 case BFA_FCPORT_SM_FAA_MISCONFIG
:
2345 bfa_fcport_reset_linkinfo(fcport
);
2346 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISCONNECT
);
2347 bfa_sm_set_state(fcport
, bfa_fcport_sm_faa_misconfig
);
2351 bfa_sm_fault(fcport
->bfa
, event
);
2356 bfa_fcport_sm_linkup(struct bfa_fcport_s
*fcport
,
2357 enum bfa_fcport_sm_event event
)
2359 char pwwn_buf
[BFA_STRING_32
];
2360 struct bfad_s
*bfad
= (struct bfad_s
*)fcport
->bfa
->bfad
;
2362 bfa_trc(fcport
->bfa
, event
);
2365 case BFA_FCPORT_SM_ENABLE
:
2371 case BFA_FCPORT_SM_DISABLE
:
2372 if (bfa_fcport_send_disable(fcport
))
2373 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabling
);
2375 bfa_sm_set_state(fcport
,
2376 bfa_fcport_sm_disabling_qwait
);
2378 bfa_fcport_reset_linkinfo(fcport
);
2379 bfa_fcport_scn(fcport
, BFA_PORT_LINKDOWN
, BFA_FALSE
);
2380 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
2381 BFA_PL_EID_PORT_DISABLE
, 0, "Port Disable");
2382 wwn2str(pwwn_buf
, fcport
->pwwn
);
2383 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
,
2384 "Base port offline: WWN = %s\n", pwwn_buf
);
2385 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_OFFLINE
);
2386 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
,
2387 "Base port disabled: WWN = %s\n", pwwn_buf
);
2388 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISABLE
);
2391 case BFA_FCPORT_SM_LINKDOWN
:
2392 bfa_sm_set_state(fcport
, bfa_fcport_sm_linkdown
);
2393 bfa_fcport_reset_linkinfo(fcport
);
2394 bfa_fcport_scn(fcport
, BFA_PORT_LINKDOWN
, BFA_FALSE
);
2395 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
2396 BFA_PL_EID_PORT_ST_CHANGE
, 0, "Port Linkdown");
2397 wwn2str(pwwn_buf
, fcport
->pwwn
);
2398 if (BFA_PORT_IS_DISABLED(fcport
->bfa
)) {
2399 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
,
2400 "Base port offline: WWN = %s\n", pwwn_buf
);
2401 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_OFFLINE
);
2403 BFA_LOG(KERN_ERR
, bfad
, bfa_log_level
,
2404 "Base port (WWN = %s) "
2405 "lost fabric connectivity\n", pwwn_buf
);
2406 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISCONNECT
);
2410 case BFA_FCPORT_SM_STOP
:
2411 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
2412 bfa_fcport_reset_linkinfo(fcport
);
2413 wwn2str(pwwn_buf
, fcport
->pwwn
);
2414 if (BFA_PORT_IS_DISABLED(fcport
->bfa
)) {
2415 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
,
2416 "Base port offline: WWN = %s\n", pwwn_buf
);
2417 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_OFFLINE
);
2419 BFA_LOG(KERN_ERR
, bfad
, bfa_log_level
,
2420 "Base port (WWN = %s) "
2421 "lost fabric connectivity\n", pwwn_buf
);
2422 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISCONNECT
);
2426 case BFA_FCPORT_SM_HWFAIL
:
2427 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocdown
);
2428 bfa_fcport_reset_linkinfo(fcport
);
2429 bfa_fcport_scn(fcport
, BFA_PORT_LINKDOWN
, BFA_FALSE
);
2430 wwn2str(pwwn_buf
, fcport
->pwwn
);
2431 if (BFA_PORT_IS_DISABLED(fcport
->bfa
)) {
2432 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
,
2433 "Base port offline: WWN = %s\n", pwwn_buf
);
2434 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_OFFLINE
);
2436 BFA_LOG(KERN_ERR
, bfad
, bfa_log_level
,
2437 "Base port (WWN = %s) "
2438 "lost fabric connectivity\n", pwwn_buf
);
2439 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISCONNECT
);
2443 case BFA_FCPORT_SM_FAA_MISCONFIG
:
2444 bfa_fcport_reset_linkinfo(fcport
);
2445 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISCONNECT
);
2446 bfa_sm_set_state(fcport
, bfa_fcport_sm_faa_misconfig
);
2450 bfa_sm_fault(fcport
->bfa
, event
);
2455 bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s
*fcport
,
2456 enum bfa_fcport_sm_event event
)
2458 bfa_trc(fcport
->bfa
, event
);
2461 case BFA_FCPORT_SM_QRESUME
:
2462 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabling
);
2463 bfa_fcport_send_disable(fcport
);
2466 case BFA_FCPORT_SM_STOP
:
2467 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
2468 bfa_reqq_wcancel(&fcport
->reqq_wait
);
2471 case BFA_FCPORT_SM_ENABLE
:
2472 bfa_sm_set_state(fcport
, bfa_fcport_sm_toggling_qwait
);
2475 case BFA_FCPORT_SM_DISABLE
:
2477 * Already being disabled.
2481 case BFA_FCPORT_SM_LINKUP
:
2482 case BFA_FCPORT_SM_LINKDOWN
:
2484 * Possible to get link events when doing back-to-back
2489 case BFA_FCPORT_SM_HWFAIL
:
2490 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocfail
);
2491 bfa_reqq_wcancel(&fcport
->reqq_wait
);
2494 case BFA_FCPORT_SM_FAA_MISCONFIG
:
2495 bfa_fcport_reset_linkinfo(fcport
);
2496 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISCONNECT
);
2497 bfa_sm_set_state(fcport
, bfa_fcport_sm_faa_misconfig
);
2501 bfa_sm_fault(fcport
->bfa
, event
);
2506 bfa_fcport_sm_toggling_qwait(struct bfa_fcport_s
*fcport
,
2507 enum bfa_fcport_sm_event event
)
2509 bfa_trc(fcport
->bfa
, event
);
2512 case BFA_FCPORT_SM_QRESUME
:
2513 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabling
);
2514 bfa_fcport_send_disable(fcport
);
2515 if (bfa_fcport_send_enable(fcport
))
2516 bfa_sm_set_state(fcport
, bfa_fcport_sm_enabling
);
2518 bfa_sm_set_state(fcport
,
2519 bfa_fcport_sm_enabling_qwait
);
2522 case BFA_FCPORT_SM_STOP
:
2523 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
2524 bfa_reqq_wcancel(&fcport
->reqq_wait
);
2527 case BFA_FCPORT_SM_ENABLE
:
2530 case BFA_FCPORT_SM_DISABLE
:
2531 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabling_qwait
);
2534 case BFA_FCPORT_SM_LINKUP
:
2535 case BFA_FCPORT_SM_LINKDOWN
:
2537 * Possible to get link events when doing back-to-back
2542 case BFA_FCPORT_SM_HWFAIL
:
2543 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocfail
);
2544 bfa_reqq_wcancel(&fcport
->reqq_wait
);
2548 bfa_sm_fault(fcport
->bfa
, event
);
2553 bfa_fcport_sm_disabling(struct bfa_fcport_s
*fcport
,
2554 enum bfa_fcport_sm_event event
)
2556 char pwwn_buf
[BFA_STRING_32
];
2557 struct bfad_s
*bfad
= (struct bfad_s
*)fcport
->bfa
->bfad
;
2558 bfa_trc(fcport
->bfa
, event
);
2561 case BFA_FCPORT_SM_FWRSP
:
2562 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabled
);
2565 case BFA_FCPORT_SM_DISABLE
:
2567 * Already being disabled.
2571 case BFA_FCPORT_SM_ENABLE
:
2572 if (bfa_fcport_send_enable(fcport
))
2573 bfa_sm_set_state(fcport
, bfa_fcport_sm_enabling
);
2575 bfa_sm_set_state(fcport
,
2576 bfa_fcport_sm_enabling_qwait
);
2578 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
2579 BFA_PL_EID_PORT_ENABLE
, 0, "Port Enable");
2580 wwn2str(pwwn_buf
, fcport
->pwwn
);
2581 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
,
2582 "Base port enabled: WWN = %s\n", pwwn_buf
);
2583 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_ENABLE
);
2586 case BFA_FCPORT_SM_STOP
:
2587 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
2590 case BFA_FCPORT_SM_LINKUP
:
2591 case BFA_FCPORT_SM_LINKDOWN
:
2593 * Possible to get link events when doing back-to-back
2598 case BFA_FCPORT_SM_HWFAIL
:
2599 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocfail
);
2603 bfa_sm_fault(fcport
->bfa
, event
);
2608 bfa_fcport_sm_disabled(struct bfa_fcport_s
*fcport
,
2609 enum bfa_fcport_sm_event event
)
2611 char pwwn_buf
[BFA_STRING_32
];
2612 struct bfad_s
*bfad
= (struct bfad_s
*)fcport
->bfa
->bfad
;
2613 bfa_trc(fcport
->bfa
, event
);
2616 case BFA_FCPORT_SM_START
:
2618 * Ignore start event for a port that is disabled.
2622 case BFA_FCPORT_SM_STOP
:
2623 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
2626 case BFA_FCPORT_SM_ENABLE
:
2627 if (bfa_fcport_send_enable(fcport
))
2628 bfa_sm_set_state(fcport
, bfa_fcport_sm_enabling
);
2630 bfa_sm_set_state(fcport
,
2631 bfa_fcport_sm_enabling_qwait
);
2633 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
2634 BFA_PL_EID_PORT_ENABLE
, 0, "Port Enable");
2635 wwn2str(pwwn_buf
, fcport
->pwwn
);
2636 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
,
2637 "Base port enabled: WWN = %s\n", pwwn_buf
);
2638 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_ENABLE
);
2641 case BFA_FCPORT_SM_DISABLE
:
2647 case BFA_FCPORT_SM_HWFAIL
:
2648 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocfail
);
2651 case BFA_FCPORT_SM_DPORTENABLE
:
2652 bfa_sm_set_state(fcport
, bfa_fcport_sm_dport
);
2655 case BFA_FCPORT_SM_DDPORTENABLE
:
2656 bfa_sm_set_state(fcport
, bfa_fcport_sm_ddport
);
2660 bfa_sm_fault(fcport
->bfa
, event
);
2665 bfa_fcport_sm_stopped(struct bfa_fcport_s
*fcport
,
2666 enum bfa_fcport_sm_event event
)
2668 bfa_trc(fcport
->bfa
, event
);
2671 case BFA_FCPORT_SM_START
:
2672 if (bfa_fcport_send_enable(fcport
))
2673 bfa_sm_set_state(fcport
, bfa_fcport_sm_enabling
);
2675 bfa_sm_set_state(fcport
,
2676 bfa_fcport_sm_enabling_qwait
);
2681 * Ignore all other events.
2688 * Port is enabled. IOC is down/failed.
2691 bfa_fcport_sm_iocdown(struct bfa_fcport_s
*fcport
,
2692 enum bfa_fcport_sm_event event
)
2694 bfa_trc(fcport
->bfa
, event
);
2697 case BFA_FCPORT_SM_START
:
2698 if (bfa_fcport_send_enable(fcport
))
2699 bfa_sm_set_state(fcport
, bfa_fcport_sm_enabling
);
2701 bfa_sm_set_state(fcport
,
2702 bfa_fcport_sm_enabling_qwait
);
2707 * Ignore all events.
2714 * Port is disabled. IOC is down/failed.
2717 bfa_fcport_sm_iocfail(struct bfa_fcport_s
*fcport
,
2718 enum bfa_fcport_sm_event event
)
2720 bfa_trc(fcport
->bfa
, event
);
2723 case BFA_FCPORT_SM_START
:
2724 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabled
);
2727 case BFA_FCPORT_SM_ENABLE
:
2728 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocdown
);
2733 * Ignore all events.
2740 bfa_fcport_sm_dport(struct bfa_fcport_s
*fcport
, enum bfa_fcport_sm_event event
)
2742 bfa_trc(fcport
->bfa
, event
);
2745 case BFA_FCPORT_SM_DPORTENABLE
:
2746 case BFA_FCPORT_SM_DISABLE
:
2747 case BFA_FCPORT_SM_ENABLE
:
2748 case BFA_FCPORT_SM_START
:
2750 * Ignore event for a port that is dport
2754 case BFA_FCPORT_SM_STOP
:
2755 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
2758 case BFA_FCPORT_SM_HWFAIL
:
2759 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocfail
);
2762 case BFA_FCPORT_SM_DPORTDISABLE
:
2763 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabled
);
2767 bfa_sm_fault(fcport
->bfa
, event
);
2772 bfa_fcport_sm_ddport(struct bfa_fcport_s
*fcport
,
2773 enum bfa_fcport_sm_event event
)
2775 bfa_trc(fcport
->bfa
, event
);
2778 case BFA_FCPORT_SM_DISABLE
:
2779 case BFA_FCPORT_SM_DDPORTDISABLE
:
2780 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabled
);
2783 case BFA_FCPORT_SM_DPORTENABLE
:
2784 case BFA_FCPORT_SM_DPORTDISABLE
:
2785 case BFA_FCPORT_SM_ENABLE
:
2786 case BFA_FCPORT_SM_START
:
2788 * Ignore event for a port that is ddport
2792 case BFA_FCPORT_SM_STOP
:
2793 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
2796 case BFA_FCPORT_SM_HWFAIL
:
2797 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocfail
);
2801 bfa_sm_fault(fcport
->bfa
, event
);
2806 bfa_fcport_sm_faa_misconfig(struct bfa_fcport_s
*fcport
,
2807 enum bfa_fcport_sm_event event
)
2809 bfa_trc(fcport
->bfa
, event
);
2812 case BFA_FCPORT_SM_DPORTENABLE
:
2813 case BFA_FCPORT_SM_ENABLE
:
2814 case BFA_FCPORT_SM_START
:
2816 * Ignore event for a port as there is FAA misconfig
2820 case BFA_FCPORT_SM_DISABLE
:
2821 if (bfa_fcport_send_disable(fcport
))
2822 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabling
);
2824 bfa_sm_set_state(fcport
, bfa_fcport_sm_disabling_qwait
);
2826 bfa_fcport_reset_linkinfo(fcport
);
2827 bfa_fcport_scn(fcport
, BFA_PORT_LINKDOWN
, BFA_FALSE
);
2828 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
2829 BFA_PL_EID_PORT_DISABLE
, 0, "Port Disable");
2830 bfa_fcport_aen_post(fcport
, BFA_PORT_AEN_DISABLE
);
2833 case BFA_FCPORT_SM_STOP
:
2834 bfa_sm_set_state(fcport
, bfa_fcport_sm_stopped
);
2837 case BFA_FCPORT_SM_HWFAIL
:
2838 bfa_fcport_reset_linkinfo(fcport
);
2839 bfa_fcport_scn(fcport
, BFA_PORT_LINKDOWN
, BFA_FALSE
);
2840 bfa_sm_set_state(fcport
, bfa_fcport_sm_iocdown
);
2844 bfa_sm_fault(fcport
->bfa
, event
);
2849 * Link state is down
2852 bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s
*ln
,
2853 enum bfa_fcport_ln_sm_event event
)
2855 bfa_trc(ln
->fcport
->bfa
, event
);
2858 case BFA_FCPORT_LN_SM_LINKUP
:
2859 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_up_nf
);
2860 bfa_fcport_queue_cb(ln
, BFA_PORT_LINKUP
);
2864 bfa_sm_fault(ln
->fcport
->bfa
, event
);
2869 * Link state is waiting for down notification
2872 bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s
*ln
,
2873 enum bfa_fcport_ln_sm_event event
)
2875 bfa_trc(ln
->fcport
->bfa
, event
);
2878 case BFA_FCPORT_LN_SM_LINKUP
:
2879 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_dn_up_nf
);
2882 case BFA_FCPORT_LN_SM_NOTIFICATION
:
2883 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_dn
);
2887 bfa_sm_fault(ln
->fcport
->bfa
, event
);
2892 * Link state is waiting for down notification and there is a pending up
2895 bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s
*ln
,
2896 enum bfa_fcport_ln_sm_event event
)
2898 bfa_trc(ln
->fcport
->bfa
, event
);
2901 case BFA_FCPORT_LN_SM_LINKDOWN
:
2902 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_dn_nf
);
2905 case BFA_FCPORT_LN_SM_NOTIFICATION
:
2906 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_up_nf
);
2907 bfa_fcport_queue_cb(ln
, BFA_PORT_LINKUP
);
2911 bfa_sm_fault(ln
->fcport
->bfa
, event
);
2919 bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s
*ln
,
2920 enum bfa_fcport_ln_sm_event event
)
2922 bfa_trc(ln
->fcport
->bfa
, event
);
2925 case BFA_FCPORT_LN_SM_LINKDOWN
:
2926 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_dn_nf
);
2927 bfa_fcport_queue_cb(ln
, BFA_PORT_LINKDOWN
);
2931 bfa_sm_fault(ln
->fcport
->bfa
, event
);
2936 * Link state is waiting for up notification
2939 bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s
*ln
,
2940 enum bfa_fcport_ln_sm_event event
)
2942 bfa_trc(ln
->fcport
->bfa
, event
);
2945 case BFA_FCPORT_LN_SM_LINKDOWN
:
2946 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_up_dn_nf
);
2949 case BFA_FCPORT_LN_SM_NOTIFICATION
:
2950 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_up
);
2954 bfa_sm_fault(ln
->fcport
->bfa
, event
);
2959 * Link state is waiting for up notification and there is a pending down
2962 bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s
*ln
,
2963 enum bfa_fcport_ln_sm_event event
)
2965 bfa_trc(ln
->fcport
->bfa
, event
);
2968 case BFA_FCPORT_LN_SM_LINKUP
:
2969 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_up_dn_up_nf
);
2972 case BFA_FCPORT_LN_SM_NOTIFICATION
:
2973 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_dn_nf
);
2974 bfa_fcport_queue_cb(ln
, BFA_PORT_LINKDOWN
);
2978 bfa_sm_fault(ln
->fcport
->bfa
, event
);
2983 * Link state is waiting for up notification and there are pending down and up
2986 bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s
*ln
,
2987 enum bfa_fcport_ln_sm_event event
)
2989 bfa_trc(ln
->fcport
->bfa
, event
);
2992 case BFA_FCPORT_LN_SM_LINKDOWN
:
2993 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_up_dn_nf
);
2996 case BFA_FCPORT_LN_SM_NOTIFICATION
:
2997 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_dn_up_nf
);
2998 bfa_fcport_queue_cb(ln
, BFA_PORT_LINKDOWN
);
3002 bfa_sm_fault(ln
->fcport
->bfa
, event
);
3007 __bfa_cb_fcport_event(void *cbarg
, bfa_boolean_t complete
)
3009 struct bfa_fcport_ln_s
*ln
= cbarg
;
3012 ln
->fcport
->event_cbfn(ln
->fcport
->event_cbarg
, ln
->ln_event
);
3014 bfa_sm_send_event(ln
, BFA_FCPORT_LN_SM_NOTIFICATION
);
3018 * Send SCN notification to upper layers.
3019 * trunk - false if caller is fcport to ignore fcport event in trunked mode
3022 bfa_fcport_scn(struct bfa_fcport_s
*fcport
, enum bfa_port_linkstate event
,
3023 bfa_boolean_t trunk
)
3025 if (fcport
->cfg
.trunked
&& !trunk
)
3029 case BFA_PORT_LINKUP
:
3030 bfa_sm_send_event(&fcport
->ln
, BFA_FCPORT_LN_SM_LINKUP
);
3032 case BFA_PORT_LINKDOWN
:
3033 bfa_sm_send_event(&fcport
->ln
, BFA_FCPORT_LN_SM_LINKDOWN
);
3041 bfa_fcport_queue_cb(struct bfa_fcport_ln_s
*ln
, enum bfa_port_linkstate event
)
3043 struct bfa_fcport_s
*fcport
= ln
->fcport
;
3045 if (fcport
->bfa
->fcs
) {
3046 fcport
->event_cbfn(fcport
->event_cbarg
, event
);
3047 bfa_sm_send_event(ln
, BFA_FCPORT_LN_SM_NOTIFICATION
);
3049 ln
->ln_event
= event
;
3050 bfa_cb_queue(fcport
->bfa
, &ln
->ln_qe
,
3051 __bfa_cb_fcport_event
, ln
);
3055 #define FCPORT_STATS_DMA_SZ (BFA_ROUNDUP(sizeof(union bfa_fcport_stats_u), \
3059 bfa_fcport_meminfo(struct bfa_iocfc_cfg_s
*cfg
, struct bfa_meminfo_s
*minfo
,
3062 struct bfa_mem_dma_s
*fcport_dma
= BFA_MEM_FCPORT_DMA(bfa
);
3064 bfa_mem_dma_setup(minfo
, fcport_dma
, FCPORT_STATS_DMA_SZ
);
3068 bfa_fcport_qresume(void *cbarg
)
3070 struct bfa_fcport_s
*fcport
= cbarg
;
3072 bfa_sm_send_event(fcport
, BFA_FCPORT_SM_QRESUME
);
3076 bfa_fcport_mem_claim(struct bfa_fcport_s
*fcport
)
3078 struct bfa_mem_dma_s
*fcport_dma
= &fcport
->fcport_dma
;
3080 fcport
->stats_kva
= bfa_mem_dma_virt(fcport_dma
);
3081 fcport
->stats_pa
= bfa_mem_dma_phys(fcport_dma
);
3082 fcport
->stats
= (union bfa_fcport_stats_u
*)
3083 bfa_mem_dma_virt(fcport_dma
);
3087 * Memory initialization.
3090 bfa_fcport_attach(struct bfa_s
*bfa
, void *bfad
, struct bfa_iocfc_cfg_s
*cfg
,
3091 struct bfa_pcidev_s
*pcidev
)
3093 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3094 struct bfa_port_cfg_s
*port_cfg
= &fcport
->cfg
;
3095 struct bfa_fcport_ln_s
*ln
= &fcport
->ln
;
3099 ln
->fcport
= fcport
;
3101 bfa_fcport_mem_claim(fcport
);
3103 bfa_sm_set_state(fcport
, bfa_fcport_sm_uninit
);
3104 bfa_sm_set_state(ln
, bfa_fcport_ln_sm_dn
);
3107 * initialize time stamp for stats reset
3109 do_gettimeofday(&tv
);
3110 fcport
->stats_reset_time
= tv
.tv_sec
;
3111 fcport
->stats_dma_ready
= BFA_FALSE
;
3114 * initialize and set default configuration
3116 port_cfg
->topology
= BFA_PORT_TOPOLOGY_P2P
;
3117 port_cfg
->speed
= BFA_PORT_SPEED_AUTO
;
3118 port_cfg
->trunked
= BFA_FALSE
;
3119 port_cfg
->maxfrsize
= 0;
3121 port_cfg
->trl_def_speed
= BFA_PORT_SPEED_1GBPS
;
3122 port_cfg
->qos_bw
.high
= BFA_QOS_BW_HIGH
;
3123 port_cfg
->qos_bw
.med
= BFA_QOS_BW_MED
;
3124 port_cfg
->qos_bw
.low
= BFA_QOS_BW_LOW
;
3126 fcport
->fec_state
= BFA_FEC_OFFLINE
;
3128 INIT_LIST_HEAD(&fcport
->stats_pending_q
);
3129 INIT_LIST_HEAD(&fcport
->statsclr_pending_q
);
3131 bfa_reqq_winit(&fcport
->reqq_wait
, bfa_fcport_qresume
, fcport
);
3135 bfa_fcport_detach(struct bfa_s
*bfa
)
3140 * Called when IOC is ready.
3143 bfa_fcport_start(struct bfa_s
*bfa
)
3145 bfa_sm_send_event(BFA_FCPORT_MOD(bfa
), BFA_FCPORT_SM_START
);
3149 * Called before IOC is stopped.
3152 bfa_fcport_stop(struct bfa_s
*bfa
)
3154 bfa_sm_send_event(BFA_FCPORT_MOD(bfa
), BFA_FCPORT_SM_STOP
);
3155 bfa_trunk_iocdisable(bfa
);
3159 * Called when IOC failure is detected.
3162 bfa_fcport_iocdisable(struct bfa_s
*bfa
)
3164 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3166 bfa_sm_send_event(fcport
, BFA_FCPORT_SM_HWFAIL
);
3167 bfa_trunk_iocdisable(bfa
);
3171 * Update loop info in fcport for SCN online
3174 bfa_fcport_update_loop_info(struct bfa_fcport_s
*fcport
,
3175 struct bfa_fcport_loop_info_s
*loop_info
)
3177 fcport
->myalpa
= loop_info
->myalpa
;
3178 fcport
->alpabm_valid
=
3179 loop_info
->alpabm_val
;
3180 memcpy(fcport
->alpabm
.alpa_bm
,
3181 loop_info
->alpabm
.alpa_bm
,
3182 sizeof(struct fc_alpabm_s
));
3186 bfa_fcport_update_linkinfo(struct bfa_fcport_s
*fcport
)
3188 struct bfi_fcport_event_s
*pevent
= fcport
->event_arg
.i2hmsg
.event
;
3189 struct bfa_fcport_trunk_s
*trunk
= &fcport
->trunk
;
3191 fcport
->speed
= pevent
->link_state
.speed
;
3192 fcport
->topology
= pevent
->link_state
.topology
;
3194 if (fcport
->topology
== BFA_PORT_TOPOLOGY_LOOP
) {
3195 bfa_fcport_update_loop_info(fcport
,
3196 &pevent
->link_state
.attr
.loop_info
);
3201 fcport
->qos_attr
= pevent
->link_state
.qos_attr
;
3202 fcport
->qos_vc_attr
= pevent
->link_state
.attr
.vc_fcf
.qos_vc_attr
;
3204 if (fcport
->cfg
.bb_cr_enabled
)
3205 fcport
->bbcr_attr
= pevent
->link_state
.attr
.bbcr_attr
;
3207 fcport
->fec_state
= pevent
->link_state
.fec_state
;
3210 * update trunk state if applicable
3212 if (!fcport
->cfg
.trunked
)
3213 trunk
->attr
.state
= BFA_TRUNK_DISABLED
;
3215 /* update FCoE specific */
3217 be16_to_cpu(pevent
->link_state
.attr
.vc_fcf
.fcf
.vlan
);
3219 bfa_trc(fcport
->bfa
, fcport
->speed
);
3220 bfa_trc(fcport
->bfa
, fcport
->topology
);
3224 bfa_fcport_reset_linkinfo(struct bfa_fcport_s
*fcport
)
3226 fcport
->speed
= BFA_PORT_SPEED_UNKNOWN
;
3227 fcport
->topology
= BFA_PORT_TOPOLOGY_NONE
;
3228 fcport
->fec_state
= BFA_FEC_OFFLINE
;
3232 * Send port enable message to firmware.
3234 static bfa_boolean_t
3235 bfa_fcport_send_enable(struct bfa_fcport_s
*fcport
)
3237 struct bfi_fcport_enable_req_s
*m
;
3240 * Increment message tag before queue check, so that responses to old
3241 * requests are discarded.
3246 * check for room in queue to send request now
3248 m
= bfa_reqq_next(fcport
->bfa
, BFA_REQQ_PORT
);
3250 bfa_reqq_wait(fcport
->bfa
, BFA_REQQ_PORT
,
3251 &fcport
->reqq_wait
);
3255 bfi_h2i_set(m
->mh
, BFI_MC_FCPORT
, BFI_FCPORT_H2I_ENABLE_REQ
,
3256 bfa_fn_lpu(fcport
->bfa
));
3257 m
->nwwn
= fcport
->nwwn
;
3258 m
->pwwn
= fcport
->pwwn
;
3259 m
->port_cfg
= fcport
->cfg
;
3260 m
->msgtag
= fcport
->msgtag
;
3261 m
->port_cfg
.maxfrsize
= cpu_to_be16(fcport
->cfg
.maxfrsize
);
3262 m
->use_flash_cfg
= fcport
->use_flash_cfg
;
3263 bfa_dma_be_addr_set(m
->stats_dma_addr
, fcport
->stats_pa
);
3264 bfa_trc(fcport
->bfa
, m
->stats_dma_addr
.a32
.addr_lo
);
3265 bfa_trc(fcport
->bfa
, m
->stats_dma_addr
.a32
.addr_hi
);
3268 * queue I/O message to firmware
3270 bfa_reqq_produce(fcport
->bfa
, BFA_REQQ_PORT
, m
->mh
);
3275 * Send port disable message to firmware.
3277 static bfa_boolean_t
3278 bfa_fcport_send_disable(struct bfa_fcport_s
*fcport
)
3280 struct bfi_fcport_req_s
*m
;
3283 * Increment message tag before queue check, so that responses to old
3284 * requests are discarded.
3289 * check for room in queue to send request now
3291 m
= bfa_reqq_next(fcport
->bfa
, BFA_REQQ_PORT
);
3293 bfa_reqq_wait(fcport
->bfa
, BFA_REQQ_PORT
,
3294 &fcport
->reqq_wait
);
3298 bfi_h2i_set(m
->mh
, BFI_MC_FCPORT
, BFI_FCPORT_H2I_DISABLE_REQ
,
3299 bfa_fn_lpu(fcport
->bfa
));
3300 m
->msgtag
= fcport
->msgtag
;
3303 * queue I/O message to firmware
3305 bfa_reqq_produce(fcport
->bfa
, BFA_REQQ_PORT
, m
->mh
);
3311 bfa_fcport_set_wwns(struct bfa_fcport_s
*fcport
)
3313 fcport
->pwwn
= fcport
->bfa
->ioc
.attr
->pwwn
;
3314 fcport
->nwwn
= fcport
->bfa
->ioc
.attr
->nwwn
;
3316 bfa_trc(fcport
->bfa
, fcport
->pwwn
);
3317 bfa_trc(fcport
->bfa
, fcport
->nwwn
);
3321 bfa_fcport_qos_stats_swap(struct bfa_qos_stats_s
*d
,
3322 struct bfa_qos_stats_s
*s
)
3324 u32
*dip
= (u32
*) d
;
3325 __be32
*sip
= (__be32
*) s
;
3328 /* Now swap the 32 bit fields */
3329 for (i
= 0; i
< (sizeof(struct bfa_qos_stats_s
)/sizeof(u32
)); ++i
)
3330 dip
[i
] = be32_to_cpu(sip
[i
]);
3334 bfa_fcport_fcoe_stats_swap(struct bfa_fcoe_stats_s
*d
,
3335 struct bfa_fcoe_stats_s
*s
)
3337 u32
*dip
= (u32
*) d
;
3338 __be32
*sip
= (__be32
*) s
;
3341 for (i
= 0; i
< ((sizeof(struct bfa_fcoe_stats_s
))/sizeof(u32
));
3344 dip
[i
] = be32_to_cpu(sip
[i
]);
3345 dip
[i
+ 1] = be32_to_cpu(sip
[i
+ 1]);
3347 dip
[i
] = be32_to_cpu(sip
[i
+ 1]);
3348 dip
[i
+ 1] = be32_to_cpu(sip
[i
]);
3354 __bfa_cb_fcport_stats_get(void *cbarg
, bfa_boolean_t complete
)
3356 struct bfa_fcport_s
*fcport
= (struct bfa_fcport_s
*)cbarg
;
3357 struct bfa_cb_pending_q_s
*cb
;
3358 struct list_head
*qe
, *qen
;
3359 union bfa_fcport_stats_u
*ret
;
3363 if (fcport
->stats_status
== BFA_STATUS_OK
)
3364 do_gettimeofday(&tv
);
3366 list_for_each_safe(qe
, qen
, &fcport
->stats_pending_q
) {
3367 bfa_q_deq(&fcport
->stats_pending_q
, &qe
);
3368 cb
= (struct bfa_cb_pending_q_s
*)qe
;
3369 if (fcport
->stats_status
== BFA_STATUS_OK
) {
3370 ret
= (union bfa_fcport_stats_u
*)cb
->data
;
3371 /* Swap FC QoS or FCoE stats */
3372 if (bfa_ioc_get_fcmode(&fcport
->bfa
->ioc
))
3373 bfa_fcport_qos_stats_swap(&ret
->fcqos
,
3374 &fcport
->stats
->fcqos
);
3376 bfa_fcport_fcoe_stats_swap(&ret
->fcoe
,
3377 &fcport
->stats
->fcoe
);
3378 ret
->fcoe
.secs_reset
=
3379 tv
.tv_sec
- fcport
->stats_reset_time
;
3382 bfa_cb_queue_status(fcport
->bfa
, &cb
->hcb_qe
,
3383 fcport
->stats_status
);
3385 fcport
->stats_status
= BFA_STATUS_OK
;
3387 INIT_LIST_HEAD(&fcport
->stats_pending_q
);
3388 fcport
->stats_status
= BFA_STATUS_OK
;
3393 bfa_fcport_stats_get_timeout(void *cbarg
)
3395 struct bfa_fcport_s
*fcport
= (struct bfa_fcport_s
*) cbarg
;
3397 bfa_trc(fcport
->bfa
, fcport
->stats_qfull
);
3399 if (fcport
->stats_qfull
) {
3400 bfa_reqq_wcancel(&fcport
->stats_reqq_wait
);
3401 fcport
->stats_qfull
= BFA_FALSE
;
3404 fcport
->stats_status
= BFA_STATUS_ETIMER
;
3405 __bfa_cb_fcport_stats_get(fcport
, BFA_TRUE
);
3409 bfa_fcport_send_stats_get(void *cbarg
)
3411 struct bfa_fcport_s
*fcport
= (struct bfa_fcport_s
*) cbarg
;
3412 struct bfi_fcport_req_s
*msg
;
3414 msg
= bfa_reqq_next(fcport
->bfa
, BFA_REQQ_PORT
);
3417 fcport
->stats_qfull
= BFA_TRUE
;
3418 bfa_reqq_winit(&fcport
->stats_reqq_wait
,
3419 bfa_fcport_send_stats_get
, fcport
);
3420 bfa_reqq_wait(fcport
->bfa
, BFA_REQQ_PORT
,
3421 &fcport
->stats_reqq_wait
);
3424 fcport
->stats_qfull
= BFA_FALSE
;
3426 memset(msg
, 0, sizeof(struct bfi_fcport_req_s
));
3427 bfi_h2i_set(msg
->mh
, BFI_MC_FCPORT
, BFI_FCPORT_H2I_STATS_GET_REQ
,
3428 bfa_fn_lpu(fcport
->bfa
));
3429 bfa_reqq_produce(fcport
->bfa
, BFA_REQQ_PORT
, msg
->mh
);
3433 __bfa_cb_fcport_stats_clr(void *cbarg
, bfa_boolean_t complete
)
3435 struct bfa_fcport_s
*fcport
= (struct bfa_fcport_s
*) cbarg
;
3436 struct bfa_cb_pending_q_s
*cb
;
3437 struct list_head
*qe
, *qen
;
3443 * re-initialize time stamp for stats reset
3445 do_gettimeofday(&tv
);
3446 fcport
->stats_reset_time
= tv
.tv_sec
;
3447 list_for_each_safe(qe
, qen
, &fcport
->statsclr_pending_q
) {
3448 bfa_q_deq(&fcport
->statsclr_pending_q
, &qe
);
3449 cb
= (struct bfa_cb_pending_q_s
*)qe
;
3450 bfa_cb_queue_status(fcport
->bfa
, &cb
->hcb_qe
,
3451 fcport
->stats_status
);
3453 fcport
->stats_status
= BFA_STATUS_OK
;
3455 INIT_LIST_HEAD(&fcport
->statsclr_pending_q
);
3456 fcport
->stats_status
= BFA_STATUS_OK
;
3461 bfa_fcport_stats_clr_timeout(void *cbarg
)
3463 struct bfa_fcport_s
*fcport
= (struct bfa_fcport_s
*) cbarg
;
3465 bfa_trc(fcport
->bfa
, fcport
->stats_qfull
);
3467 if (fcport
->stats_qfull
) {
3468 bfa_reqq_wcancel(&fcport
->stats_reqq_wait
);
3469 fcport
->stats_qfull
= BFA_FALSE
;
3472 fcport
->stats_status
= BFA_STATUS_ETIMER
;
3473 __bfa_cb_fcport_stats_clr(fcport
, BFA_TRUE
);
3477 bfa_fcport_send_stats_clear(void *cbarg
)
3479 struct bfa_fcport_s
*fcport
= (struct bfa_fcport_s
*) cbarg
;
3480 struct bfi_fcport_req_s
*msg
;
3482 msg
= bfa_reqq_next(fcport
->bfa
, BFA_REQQ_PORT
);
3485 fcport
->stats_qfull
= BFA_TRUE
;
3486 bfa_reqq_winit(&fcport
->stats_reqq_wait
,
3487 bfa_fcport_send_stats_clear
, fcport
);
3488 bfa_reqq_wait(fcport
->bfa
, BFA_REQQ_PORT
,
3489 &fcport
->stats_reqq_wait
);
3492 fcport
->stats_qfull
= BFA_FALSE
;
3494 memset(msg
, 0, sizeof(struct bfi_fcport_req_s
));
3495 bfi_h2i_set(msg
->mh
, BFI_MC_FCPORT
, BFI_FCPORT_H2I_STATS_CLEAR_REQ
,
3496 bfa_fn_lpu(fcport
->bfa
));
3497 bfa_reqq_produce(fcport
->bfa
, BFA_REQQ_PORT
, msg
->mh
);
3501 * Handle trunk SCN event from firmware.
3504 bfa_trunk_scn(struct bfa_fcport_s
*fcport
, struct bfi_fcport_trunk_scn_s
*scn
)
3506 struct bfa_fcport_trunk_s
*trunk
= &fcport
->trunk
;
3507 struct bfi_fcport_trunk_link_s
*tlink
;
3508 struct bfa_trunk_link_attr_s
*lattr
;
3509 enum bfa_trunk_state state_prev
;
3513 bfa_trc(fcport
->bfa
, fcport
->cfg
.trunked
);
3514 WARN_ON(scn
->trunk_state
!= BFA_TRUNK_ONLINE
&&
3515 scn
->trunk_state
!= BFA_TRUNK_OFFLINE
);
3517 bfa_trc(fcport
->bfa
, trunk
->attr
.state
);
3518 bfa_trc(fcport
->bfa
, scn
->trunk_state
);
3519 bfa_trc(fcport
->bfa
, scn
->trunk_speed
);
3522 * Save off new state for trunk attribute query
3524 state_prev
= trunk
->attr
.state
;
3525 if (fcport
->cfg
.trunked
&& (trunk
->attr
.state
!= BFA_TRUNK_DISABLED
))
3526 trunk
->attr
.state
= scn
->trunk_state
;
3527 trunk
->attr
.speed
= scn
->trunk_speed
;
3528 for (i
= 0; i
< BFA_TRUNK_MAX_PORTS
; i
++) {
3529 lattr
= &trunk
->attr
.link_attr
[i
];
3530 tlink
= &scn
->tlink
[i
];
3532 lattr
->link_state
= tlink
->state
;
3533 lattr
->trunk_wwn
= tlink
->trunk_wwn
;
3534 lattr
->fctl
= tlink
->fctl
;
3535 lattr
->speed
= tlink
->speed
;
3536 lattr
->deskew
= be32_to_cpu(tlink
->deskew
);
3538 if (tlink
->state
== BFA_TRUNK_LINK_STATE_UP
) {
3539 fcport
->speed
= tlink
->speed
;
3540 fcport
->topology
= BFA_PORT_TOPOLOGY_P2P
;
3544 bfa_trc(fcport
->bfa
, lattr
->link_state
);
3545 bfa_trc(fcport
->bfa
, lattr
->trunk_wwn
);
3546 bfa_trc(fcport
->bfa
, lattr
->fctl
);
3547 bfa_trc(fcport
->bfa
, lattr
->speed
);
3548 bfa_trc(fcport
->bfa
, lattr
->deskew
);
3553 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
3554 BFA_PL_EID_TRUNK_SCN
, 0, "Trunk up(0,1)");
3557 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
3558 BFA_PL_EID_TRUNK_SCN
, 0, "Trunk up(-,1)");
3561 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
3562 BFA_PL_EID_TRUNK_SCN
, 0, "Trunk up(0,-)");
3565 bfa_plog_str(fcport
->bfa
->plog
, BFA_PL_MID_HAL
,
3566 BFA_PL_EID_TRUNK_SCN
, 0, "Trunk down");
3570 * Notify upper layers if trunk state changed.
3572 if ((state_prev
!= trunk
->attr
.state
) ||
3573 (scn
->trunk_state
== BFA_TRUNK_OFFLINE
)) {
3574 bfa_fcport_scn(fcport
, (scn
->trunk_state
== BFA_TRUNK_ONLINE
) ?
3575 BFA_PORT_LINKUP
: BFA_PORT_LINKDOWN
, BFA_TRUE
);
3580 bfa_trunk_iocdisable(struct bfa_s
*bfa
)
3582 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3586 * In trunked mode, notify upper layers that link is down
3588 if (fcport
->cfg
.trunked
) {
3589 if (fcport
->trunk
.attr
.state
== BFA_TRUNK_ONLINE
)
3590 bfa_fcport_scn(fcport
, BFA_PORT_LINKDOWN
, BFA_TRUE
);
3592 fcport
->trunk
.attr
.state
= BFA_TRUNK_OFFLINE
;
3593 fcport
->trunk
.attr
.speed
= BFA_PORT_SPEED_UNKNOWN
;
3594 for (i
= 0; i
< BFA_TRUNK_MAX_PORTS
; i
++) {
3595 fcport
->trunk
.attr
.link_attr
[i
].trunk_wwn
= 0;
3596 fcport
->trunk
.attr
.link_attr
[i
].fctl
=
3597 BFA_TRUNK_LINK_FCTL_NORMAL
;
3598 fcport
->trunk
.attr
.link_attr
[i
].link_state
=
3599 BFA_TRUNK_LINK_STATE_DN_LINKDN
;
3600 fcport
->trunk
.attr
.link_attr
[i
].speed
=
3601 BFA_PORT_SPEED_UNKNOWN
;
3602 fcport
->trunk
.attr
.link_attr
[i
].deskew
= 0;
3608 * Called to initialize port attributes
3611 bfa_fcport_init(struct bfa_s
*bfa
)
3613 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3616 * Initialize port attributes from IOC hardware data.
3618 bfa_fcport_set_wwns(fcport
);
3619 if (fcport
->cfg
.maxfrsize
== 0)
3620 fcport
->cfg
.maxfrsize
= bfa_ioc_maxfrsize(&bfa
->ioc
);
3621 fcport
->cfg
.rx_bbcredit
= bfa_ioc_rx_bbcredit(&bfa
->ioc
);
3622 fcport
->speed_sup
= bfa_ioc_speed_sup(&bfa
->ioc
);
3624 if (bfa_fcport_is_pbcdisabled(bfa
))
3625 bfa
->modules
.port
.pbc_disabled
= BFA_TRUE
;
3627 WARN_ON(!fcport
->cfg
.maxfrsize
);
3628 WARN_ON(!fcport
->cfg
.rx_bbcredit
);
3629 WARN_ON(!fcport
->speed_sup
);
3633 * Firmware message handler.
3636 bfa_fcport_isr(struct bfa_s
*bfa
, struct bfi_msg_s
*msg
)
3638 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3639 union bfi_fcport_i2h_msg_u i2hmsg
;
3642 fcport
->event_arg
.i2hmsg
= i2hmsg
;
3644 bfa_trc(bfa
, msg
->mhdr
.msg_id
);
3645 bfa_trc(bfa
, bfa_sm_to_state(hal_port_sm_table
, fcport
->sm
));
3647 switch (msg
->mhdr
.msg_id
) {
3648 case BFI_FCPORT_I2H_ENABLE_RSP
:
3649 if (fcport
->msgtag
== i2hmsg
.penable_rsp
->msgtag
) {
3651 fcport
->stats_dma_ready
= BFA_TRUE
;
3652 if (fcport
->use_flash_cfg
) {
3653 fcport
->cfg
= i2hmsg
.penable_rsp
->port_cfg
;
3654 fcport
->cfg
.maxfrsize
=
3655 cpu_to_be16(fcport
->cfg
.maxfrsize
);
3656 fcport
->cfg
.path_tov
=
3657 cpu_to_be16(fcport
->cfg
.path_tov
);
3658 fcport
->cfg
.q_depth
=
3659 cpu_to_be16(fcport
->cfg
.q_depth
);
3661 if (fcport
->cfg
.trunked
)
3662 fcport
->trunk
.attr
.state
=
3665 fcport
->trunk
.attr
.state
=
3667 fcport
->qos_attr
.qos_bw
=
3668 i2hmsg
.penable_rsp
->port_cfg
.qos_bw
;
3669 fcport
->use_flash_cfg
= BFA_FALSE
;
3672 if (fcport
->cfg
.qos_enabled
)
3673 fcport
->qos_attr
.state
= BFA_QOS_OFFLINE
;
3675 fcport
->qos_attr
.state
= BFA_QOS_DISABLED
;
3677 fcport
->qos_attr
.qos_bw_op
=
3678 i2hmsg
.penable_rsp
->port_cfg
.qos_bw
;
3680 if (fcport
->cfg
.bb_cr_enabled
)
3681 fcport
->bbcr_attr
.state
= BFA_BBCR_OFFLINE
;
3683 fcport
->bbcr_attr
.state
= BFA_BBCR_DISABLED
;
3685 bfa_sm_send_event(fcport
, BFA_FCPORT_SM_FWRSP
);
3689 case BFI_FCPORT_I2H_DISABLE_RSP
:
3690 if (fcport
->msgtag
== i2hmsg
.penable_rsp
->msgtag
)
3691 bfa_sm_send_event(fcport
, BFA_FCPORT_SM_FWRSP
);
3694 case BFI_FCPORT_I2H_EVENT
:
3695 if (fcport
->cfg
.bb_cr_enabled
)
3696 fcport
->bbcr_attr
.state
= BFA_BBCR_OFFLINE
;
3698 fcport
->bbcr_attr
.state
= BFA_BBCR_DISABLED
;
3700 if (i2hmsg
.event
->link_state
.linkstate
== BFA_PORT_LINKUP
)
3701 bfa_sm_send_event(fcport
, BFA_FCPORT_SM_LINKUP
);
3703 if (i2hmsg
.event
->link_state
.linkstate_rsn
==
3704 BFA_PORT_LINKSTATE_RSN_FAA_MISCONFIG
)
3705 bfa_sm_send_event(fcport
,
3706 BFA_FCPORT_SM_FAA_MISCONFIG
);
3708 bfa_sm_send_event(fcport
,
3709 BFA_FCPORT_SM_LINKDOWN
);
3711 fcport
->qos_attr
.qos_bw_op
=
3712 i2hmsg
.event
->link_state
.qos_attr
.qos_bw_op
;
3715 case BFI_FCPORT_I2H_TRUNK_SCN
:
3716 bfa_trunk_scn(fcport
, i2hmsg
.trunk_scn
);
3719 case BFI_FCPORT_I2H_STATS_GET_RSP
:
3721 * check for timer pop before processing the rsp
3723 if (list_empty(&fcport
->stats_pending_q
) ||
3724 (fcport
->stats_status
== BFA_STATUS_ETIMER
))
3727 bfa_timer_stop(&fcport
->timer
);
3728 fcport
->stats_status
= i2hmsg
.pstatsget_rsp
->status
;
3729 __bfa_cb_fcport_stats_get(fcport
, BFA_TRUE
);
3732 case BFI_FCPORT_I2H_STATS_CLEAR_RSP
:
3734 * check for timer pop before processing the rsp
3736 if (list_empty(&fcport
->statsclr_pending_q
) ||
3737 (fcport
->stats_status
== BFA_STATUS_ETIMER
))
3740 bfa_timer_stop(&fcport
->timer
);
3741 fcport
->stats_status
= BFA_STATUS_OK
;
3742 __bfa_cb_fcport_stats_clr(fcport
, BFA_TRUE
);
3745 case BFI_FCPORT_I2H_ENABLE_AEN
:
3746 bfa_sm_send_event(fcport
, BFA_FCPORT_SM_ENABLE
);
3749 case BFI_FCPORT_I2H_DISABLE_AEN
:
3750 bfa_sm_send_event(fcport
, BFA_FCPORT_SM_DISABLE
);
3760 * Registered callback for port events.
3763 bfa_fcport_event_register(struct bfa_s
*bfa
,
3764 void (*cbfn
) (void *cbarg
,
3765 enum bfa_port_linkstate event
),
3768 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3770 fcport
->event_cbfn
= cbfn
;
3771 fcport
->event_cbarg
= cbarg
;
3775 bfa_fcport_enable(struct bfa_s
*bfa
)
3777 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3779 if (bfa_fcport_is_pbcdisabled(bfa
))
3780 return BFA_STATUS_PBC
;
3782 if (bfa_ioc_is_disabled(&bfa
->ioc
))
3783 return BFA_STATUS_IOC_DISABLED
;
3785 if (fcport
->diag_busy
)
3786 return BFA_STATUS_DIAG_BUSY
;
3788 bfa_sm_send_event(BFA_FCPORT_MOD(bfa
), BFA_FCPORT_SM_ENABLE
);
3789 return BFA_STATUS_OK
;
3793 bfa_fcport_disable(struct bfa_s
*bfa
)
3795 if (bfa_fcport_is_pbcdisabled(bfa
))
3796 return BFA_STATUS_PBC
;
3798 if (bfa_ioc_is_disabled(&bfa
->ioc
))
3799 return BFA_STATUS_IOC_DISABLED
;
3801 bfa_sm_send_event(BFA_FCPORT_MOD(bfa
), BFA_FCPORT_SM_DISABLE
);
3802 return BFA_STATUS_OK
;
3805 /* If PBC is disabled on port, return error */
3807 bfa_fcport_is_pbcdisabled(struct bfa_s
*bfa
)
3809 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3810 struct bfa_iocfc_s
*iocfc
= &bfa
->iocfc
;
3811 struct bfi_iocfc_cfgrsp_s
*cfgrsp
= iocfc
->cfgrsp
;
3813 if (cfgrsp
->pbc_cfg
.port_enabled
== BFI_PBC_PORT_DISABLED
) {
3814 bfa_trc(bfa
, fcport
->pwwn
);
3815 return BFA_STATUS_PBC
;
3817 return BFA_STATUS_OK
;
3821 * Configure port speed.
3824 bfa_fcport_cfg_speed(struct bfa_s
*bfa
, enum bfa_port_speed speed
)
3826 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3828 bfa_trc(bfa
, speed
);
3830 if (fcport
->cfg
.trunked
== BFA_TRUE
)
3831 return BFA_STATUS_TRUNK_ENABLED
;
3832 if ((fcport
->cfg
.topology
== BFA_PORT_TOPOLOGY_LOOP
) &&
3833 (speed
== BFA_PORT_SPEED_16GBPS
))
3834 return BFA_STATUS_UNSUPP_SPEED
;
3835 if ((speed
!= BFA_PORT_SPEED_AUTO
) && (speed
> fcport
->speed_sup
)) {
3836 bfa_trc(bfa
, fcport
->speed_sup
);
3837 return BFA_STATUS_UNSUPP_SPEED
;
3840 /* Port speed entered needs to be checked */
3841 if (bfa_ioc_get_type(&fcport
->bfa
->ioc
) == BFA_IOC_TYPE_FC
) {
3842 /* For CT2, 1G is not supported */
3843 if ((speed
== BFA_PORT_SPEED_1GBPS
) &&
3844 (bfa_asic_id_ct2(bfa
->ioc
.pcidev
.device_id
)))
3845 return BFA_STATUS_UNSUPP_SPEED
;
3847 /* Already checked for Auto Speed and Max Speed supp */
3848 if (!(speed
== BFA_PORT_SPEED_1GBPS
||
3849 speed
== BFA_PORT_SPEED_2GBPS
||
3850 speed
== BFA_PORT_SPEED_4GBPS
||
3851 speed
== BFA_PORT_SPEED_8GBPS
||
3852 speed
== BFA_PORT_SPEED_16GBPS
||
3853 speed
== BFA_PORT_SPEED_AUTO
))
3854 return BFA_STATUS_UNSUPP_SPEED
;
3856 if (speed
!= BFA_PORT_SPEED_10GBPS
)
3857 return BFA_STATUS_UNSUPP_SPEED
;
3860 fcport
->cfg
.speed
= speed
;
3862 return BFA_STATUS_OK
;
3866 * Get current speed.
3869 bfa_fcport_get_speed(struct bfa_s
*bfa
)
3871 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3873 return fcport
->speed
;
3877 * Configure port topology.
3880 bfa_fcport_cfg_topology(struct bfa_s
*bfa
, enum bfa_port_topology topology
)
3882 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3884 bfa_trc(bfa
, topology
);
3885 bfa_trc(bfa
, fcport
->cfg
.topology
);
3888 case BFA_PORT_TOPOLOGY_P2P
:
3891 case BFA_PORT_TOPOLOGY_LOOP
:
3892 if ((bfa_fcport_is_qos_enabled(bfa
) != BFA_FALSE
) ||
3893 (fcport
->qos_attr
.state
!= BFA_QOS_DISABLED
))
3894 return BFA_STATUS_ERROR_QOS_ENABLED
;
3895 if (fcport
->cfg
.ratelimit
!= BFA_FALSE
)
3896 return BFA_STATUS_ERROR_TRL_ENABLED
;
3897 if ((bfa_fcport_is_trunk_enabled(bfa
) != BFA_FALSE
) ||
3898 (fcport
->trunk
.attr
.state
!= BFA_TRUNK_DISABLED
))
3899 return BFA_STATUS_ERROR_TRUNK_ENABLED
;
3900 if ((bfa_fcport_get_speed(bfa
) == BFA_PORT_SPEED_16GBPS
) ||
3901 (fcport
->cfg
.speed
== BFA_PORT_SPEED_16GBPS
))
3902 return BFA_STATUS_UNSUPP_SPEED
;
3903 if (bfa_mfg_is_mezz(bfa
->ioc
.attr
->card_type
))
3904 return BFA_STATUS_LOOP_UNSUPP_MEZZ
;
3905 if (bfa_fcport_is_dport(bfa
) != BFA_FALSE
)
3906 return BFA_STATUS_DPORT_ERR
;
3907 if (bfa_fcport_is_ddport(bfa
) != BFA_FALSE
)
3908 return BFA_STATUS_DPORT_ERR
;
3911 case BFA_PORT_TOPOLOGY_AUTO
:
3915 return BFA_STATUS_EINVAL
;
3918 fcport
->cfg
.topology
= topology
;
3919 return BFA_STATUS_OK
;
3923 * Get current topology.
3925 enum bfa_port_topology
3926 bfa_fcport_get_topology(struct bfa_s
*bfa
)
3928 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3930 return fcport
->topology
;
3934 * Get config topology.
3936 enum bfa_port_topology
3937 bfa_fcport_get_cfg_topology(struct bfa_s
*bfa
)
3939 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3941 return fcport
->cfg
.topology
;
3945 bfa_fcport_cfg_hardalpa(struct bfa_s
*bfa
, u8 alpa
)
3947 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3950 bfa_trc(bfa
, fcport
->cfg
.cfg_hardalpa
);
3951 bfa_trc(bfa
, fcport
->cfg
.hardalpa
);
3953 fcport
->cfg
.cfg_hardalpa
= BFA_TRUE
;
3954 fcport
->cfg
.hardalpa
= alpa
;
3956 return BFA_STATUS_OK
;
3960 bfa_fcport_clr_hardalpa(struct bfa_s
*bfa
)
3962 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3964 bfa_trc(bfa
, fcport
->cfg
.cfg_hardalpa
);
3965 bfa_trc(bfa
, fcport
->cfg
.hardalpa
);
3967 fcport
->cfg
.cfg_hardalpa
= BFA_FALSE
;
3968 return BFA_STATUS_OK
;
3972 bfa_fcport_get_hardalpa(struct bfa_s
*bfa
, u8
*alpa
)
3974 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3976 *alpa
= fcport
->cfg
.hardalpa
;
3977 return fcport
->cfg
.cfg_hardalpa
;
3981 bfa_fcport_get_myalpa(struct bfa_s
*bfa
)
3983 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3985 return fcport
->myalpa
;
3989 bfa_fcport_cfg_maxfrsize(struct bfa_s
*bfa
, u16 maxfrsize
)
3991 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
3993 bfa_trc(bfa
, maxfrsize
);
3994 bfa_trc(bfa
, fcport
->cfg
.maxfrsize
);
3997 if ((maxfrsize
> FC_MAX_PDUSZ
) || (maxfrsize
< FC_MIN_PDUSZ
))
3998 return BFA_STATUS_INVLD_DFSZ
;
4000 /* power of 2, if not the max frame size of 2112 */
4001 if ((maxfrsize
!= FC_MAX_PDUSZ
) && (maxfrsize
& (maxfrsize
- 1)))
4002 return BFA_STATUS_INVLD_DFSZ
;
4004 fcport
->cfg
.maxfrsize
= maxfrsize
;
4005 return BFA_STATUS_OK
;
4009 bfa_fcport_get_maxfrsize(struct bfa_s
*bfa
)
4011 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4013 return fcport
->cfg
.maxfrsize
;
4017 bfa_fcport_get_rx_bbcredit(struct bfa_s
*bfa
)
4019 if (bfa_fcport_get_topology(bfa
) != BFA_PORT_TOPOLOGY_LOOP
)
4020 return (BFA_FCPORT_MOD(bfa
))->cfg
.rx_bbcredit
;
4027 bfa_fcport_set_tx_bbcredit(struct bfa_s
*bfa
, u16 tx_bbcredit
)
4029 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4031 fcport
->cfg
.tx_bbcredit
= (u8
)tx_bbcredit
;
4035 * Get port attributes.
4039 bfa_fcport_get_wwn(struct bfa_s
*bfa
, bfa_boolean_t node
)
4041 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4043 return fcport
->nwwn
;
4045 return fcport
->pwwn
;
4049 bfa_fcport_get_attr(struct bfa_s
*bfa
, struct bfa_port_attr_s
*attr
)
4051 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4053 memset(attr
, 0, sizeof(struct bfa_port_attr_s
));
4055 attr
->nwwn
= fcport
->nwwn
;
4056 attr
->pwwn
= fcport
->pwwn
;
4058 attr
->factorypwwn
= bfa
->ioc
.attr
->mfg_pwwn
;
4059 attr
->factorynwwn
= bfa
->ioc
.attr
->mfg_nwwn
;
4061 memcpy(&attr
->pport_cfg
, &fcport
->cfg
,
4062 sizeof(struct bfa_port_cfg_s
));
4063 /* speed attributes */
4064 attr
->pport_cfg
.speed
= fcport
->cfg
.speed
;
4065 attr
->speed_supported
= fcport
->speed_sup
;
4066 attr
->speed
= fcport
->speed
;
4067 attr
->cos_supported
= FC_CLASS_3
;
4069 /* topology attributes */
4070 attr
->pport_cfg
.topology
= fcport
->cfg
.topology
;
4071 attr
->topology
= fcport
->topology
;
4072 attr
->pport_cfg
.trunked
= fcport
->cfg
.trunked
;
4074 /* beacon attributes */
4075 attr
->beacon
= fcport
->beacon
;
4076 attr
->link_e2e_beacon
= fcport
->link_e2e_beacon
;
4078 attr
->pport_cfg
.path_tov
= bfa_fcpim_path_tov_get(bfa
);
4079 attr
->pport_cfg
.q_depth
= bfa_fcpim_qdepth_get(bfa
);
4080 attr
->port_state
= bfa_sm_to_state(hal_port_sm_table
, fcport
->sm
);
4082 attr
->fec_state
= fcport
->fec_state
;
4084 /* PBC Disabled State */
4085 if (bfa_fcport_is_pbcdisabled(bfa
))
4086 attr
->port_state
= BFA_PORT_ST_PREBOOT_DISABLED
;
4088 if (bfa_ioc_is_disabled(&fcport
->bfa
->ioc
))
4089 attr
->port_state
= BFA_PORT_ST_IOCDIS
;
4090 else if (bfa_ioc_fw_mismatch(&fcport
->bfa
->ioc
))
4091 attr
->port_state
= BFA_PORT_ST_FWMISMATCH
;
4095 attr
->fcoe_vlan
= fcport
->fcoe_vlan
;
4098 #define BFA_FCPORT_STATS_TOV 1000
4101 * Fetch port statistics (FCQoS or FCoE).
4104 bfa_fcport_get_stats(struct bfa_s
*bfa
, struct bfa_cb_pending_q_s
*cb
)
4106 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4108 if (!bfa_iocfc_is_operational(bfa
) ||
4109 !fcport
->stats_dma_ready
)
4110 return BFA_STATUS_IOC_NON_OP
;
4112 if (!list_empty(&fcport
->statsclr_pending_q
))
4113 return BFA_STATUS_DEVBUSY
;
4115 if (list_empty(&fcport
->stats_pending_q
)) {
4116 list_add_tail(&cb
->hcb_qe
.qe
, &fcport
->stats_pending_q
);
4117 bfa_fcport_send_stats_get(fcport
);
4118 bfa_timer_start(bfa
, &fcport
->timer
,
4119 bfa_fcport_stats_get_timeout
,
4120 fcport
, BFA_FCPORT_STATS_TOV
);
4122 list_add_tail(&cb
->hcb_qe
.qe
, &fcport
->stats_pending_q
);
4124 return BFA_STATUS_OK
;
4128 * Reset port statistics (FCQoS or FCoE).
4131 bfa_fcport_clear_stats(struct bfa_s
*bfa
, struct bfa_cb_pending_q_s
*cb
)
4133 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4135 if (!bfa_iocfc_is_operational(bfa
) ||
4136 !fcport
->stats_dma_ready
)
4137 return BFA_STATUS_IOC_NON_OP
;
4139 if (!list_empty(&fcport
->stats_pending_q
))
4140 return BFA_STATUS_DEVBUSY
;
4142 if (list_empty(&fcport
->statsclr_pending_q
)) {
4143 list_add_tail(&cb
->hcb_qe
.qe
, &fcport
->statsclr_pending_q
);
4144 bfa_fcport_send_stats_clear(fcport
);
4145 bfa_timer_start(bfa
, &fcport
->timer
,
4146 bfa_fcport_stats_clr_timeout
,
4147 fcport
, BFA_FCPORT_STATS_TOV
);
4149 list_add_tail(&cb
->hcb_qe
.qe
, &fcport
->statsclr_pending_q
);
4151 return BFA_STATUS_OK
;
4155 * Fetch port attributes.
4158 bfa_fcport_is_disabled(struct bfa_s
*bfa
)
4160 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4162 return bfa_sm_to_state(hal_port_sm_table
, fcport
->sm
) ==
4163 BFA_PORT_ST_DISABLED
;
4168 bfa_fcport_is_dport(struct bfa_s
*bfa
)
4170 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4172 return (bfa_sm_to_state(hal_port_sm_table
, fcport
->sm
) ==
4177 bfa_fcport_is_ddport(struct bfa_s
*bfa
)
4179 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4181 return (bfa_sm_to_state(hal_port_sm_table
, fcport
->sm
) ==
4182 BFA_PORT_ST_DDPORT
);
4186 bfa_fcport_set_qos_bw(struct bfa_s
*bfa
, struct bfa_qos_bw_s
*qos_bw
)
4188 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4189 enum bfa_ioc_type_e ioc_type
= bfa_get_type(bfa
);
4191 bfa_trc(bfa
, ioc_type
);
4193 if ((qos_bw
->high
== 0) || (qos_bw
->med
== 0) || (qos_bw
->low
== 0))
4194 return BFA_STATUS_QOS_BW_INVALID
;
4196 if ((qos_bw
->high
+ qos_bw
->med
+ qos_bw
->low
) != 100)
4197 return BFA_STATUS_QOS_BW_INVALID
;
4199 if ((qos_bw
->med
> qos_bw
->high
) || (qos_bw
->low
> qos_bw
->med
) ||
4200 (qos_bw
->low
> qos_bw
->high
))
4201 return BFA_STATUS_QOS_BW_INVALID
;
4203 if ((ioc_type
== BFA_IOC_TYPE_FC
) &&
4204 (fcport
->cfg
.topology
!= BFA_PORT_TOPOLOGY_LOOP
))
4205 fcport
->cfg
.qos_bw
= *qos_bw
;
4207 return BFA_STATUS_OK
;
4211 bfa_fcport_is_ratelim(struct bfa_s
*bfa
)
4213 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4215 return fcport
->cfg
.ratelimit
? BFA_TRUE
: BFA_FALSE
;
4220 * Enable/Disable FAA feature in port config
4223 bfa_fcport_cfg_faa(struct bfa_s
*bfa
, u8 state
)
4225 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4227 bfa_trc(bfa
, state
);
4228 fcport
->cfg
.faa_state
= state
;
4232 * Get default minimum ratelim speed
4235 bfa_fcport_get_ratelim_speed(struct bfa_s
*bfa
)
4237 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4239 bfa_trc(bfa
, fcport
->cfg
.trl_def_speed
);
4240 return fcport
->cfg
.trl_def_speed
;
4245 bfa_fcport_beacon(void *dev
, bfa_boolean_t beacon
,
4246 bfa_boolean_t link_e2e_beacon
)
4248 struct bfa_s
*bfa
= dev
;
4249 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4251 bfa_trc(bfa
, beacon
);
4252 bfa_trc(bfa
, link_e2e_beacon
);
4253 bfa_trc(bfa
, fcport
->beacon
);
4254 bfa_trc(bfa
, fcport
->link_e2e_beacon
);
4256 fcport
->beacon
= beacon
;
4257 fcport
->link_e2e_beacon
= link_e2e_beacon
;
4261 bfa_fcport_is_linkup(struct bfa_s
*bfa
)
4263 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4265 return (!fcport
->cfg
.trunked
&&
4266 bfa_sm_cmp_state(fcport
, bfa_fcport_sm_linkup
)) ||
4267 (fcport
->cfg
.trunked
&&
4268 fcport
->trunk
.attr
.state
== BFA_TRUNK_ONLINE
);
4272 bfa_fcport_is_qos_enabled(struct bfa_s
*bfa
)
4274 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4276 return fcport
->cfg
.qos_enabled
;
4280 bfa_fcport_is_trunk_enabled(struct bfa_s
*bfa
)
4282 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4284 return fcport
->cfg
.trunked
;
4288 bfa_fcport_cfg_bbcr(struct bfa_s
*bfa
, bfa_boolean_t on_off
, u8 bb_scn
)
4290 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4292 bfa_trc(bfa
, on_off
);
4294 if (bfa_ioc_get_type(&fcport
->bfa
->ioc
) != BFA_IOC_TYPE_FC
)
4295 return BFA_STATUS_BBCR_FC_ONLY
;
4297 if (bfa_mfg_is_mezz(bfa
->ioc
.attr
->card_type
) &&
4298 (bfa
->ioc
.attr
->card_type
!= BFA_MFG_TYPE_CHINOOK
))
4299 return BFA_STATUS_CMD_NOTSUPP_MEZZ
;
4302 if (fcport
->cfg
.topology
== BFA_PORT_TOPOLOGY_LOOP
)
4303 return BFA_STATUS_TOPOLOGY_LOOP
;
4305 if (fcport
->cfg
.qos_enabled
)
4306 return BFA_STATUS_ERROR_QOS_ENABLED
;
4308 if (fcport
->cfg
.trunked
)
4309 return BFA_STATUS_TRUNK_ENABLED
;
4311 if ((fcport
->cfg
.speed
!= BFA_PORT_SPEED_AUTO
) &&
4312 (fcport
->cfg
.speed
< bfa_ioc_speed_sup(&bfa
->ioc
)))
4313 return BFA_STATUS_ERR_BBCR_SPEED_UNSUPPORT
;
4315 if (bfa_ioc_speed_sup(&bfa
->ioc
) < BFA_PORT_SPEED_8GBPS
)
4316 return BFA_STATUS_FEATURE_NOT_SUPPORTED
;
4318 if (fcport
->cfg
.bb_cr_enabled
) {
4319 if (bb_scn
!= fcport
->cfg
.bb_scn
)
4320 return BFA_STATUS_BBCR_CFG_NO_CHANGE
;
4322 return BFA_STATUS_NO_CHANGE
;
4325 if ((bb_scn
== 0) || (bb_scn
> BFA_BB_SCN_MAX
))
4326 bb_scn
= BFA_BB_SCN_DEF
;
4328 fcport
->cfg
.bb_cr_enabled
= on_off
;
4329 fcport
->cfg
.bb_scn
= bb_scn
;
4331 if (!fcport
->cfg
.bb_cr_enabled
)
4332 return BFA_STATUS_NO_CHANGE
;
4334 fcport
->cfg
.bb_cr_enabled
= on_off
;
4335 fcport
->cfg
.bb_scn
= 0;
4338 return BFA_STATUS_OK
;
4342 bfa_fcport_get_bbcr_attr(struct bfa_s
*bfa
,
4343 struct bfa_bbcr_attr_s
*bbcr_attr
)
4345 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(bfa
);
4347 if (bfa_ioc_get_type(&fcport
->bfa
->ioc
) != BFA_IOC_TYPE_FC
)
4348 return BFA_STATUS_BBCR_FC_ONLY
;
4350 if (fcport
->cfg
.topology
== BFA_PORT_TOPOLOGY_LOOP
)
4351 return BFA_STATUS_TOPOLOGY_LOOP
;
4353 *bbcr_attr
= fcport
->bbcr_attr
;
4355 return BFA_STATUS_OK
;
4359 bfa_fcport_dportenable(struct bfa_s
*bfa
)
4362 * Assume caller check for port is in disable state
4364 bfa_sm_send_event(BFA_FCPORT_MOD(bfa
), BFA_FCPORT_SM_DPORTENABLE
);
4365 bfa_port_set_dportenabled(&bfa
->modules
.port
, BFA_TRUE
);
4369 bfa_fcport_dportdisable(struct bfa_s
*bfa
)
4372 * Assume caller check for port is in disable state
4374 bfa_sm_send_event(BFA_FCPORT_MOD(bfa
), BFA_FCPORT_SM_DPORTDISABLE
);
4375 bfa_port_set_dportenabled(&bfa
->modules
.port
, BFA_FALSE
);
4379 bfa_fcport_ddportenable(struct bfa_s
*bfa
)
4382 * Assume caller check for port is in disable state
4384 bfa_sm_send_event(BFA_FCPORT_MOD(bfa
), BFA_FCPORT_SM_DDPORTENABLE
);
4388 bfa_fcport_ddportdisable(struct bfa_s
*bfa
)
4391 * Assume caller check for port is in disable state
4393 bfa_sm_send_event(BFA_FCPORT_MOD(bfa
), BFA_FCPORT_SM_DDPORTDISABLE
);
4397 * Rport State machine functions
4400 * Beginning state, only online event expected.
4403 bfa_rport_sm_uninit(struct bfa_rport_s
*rp
, enum bfa_rport_event event
)
4405 bfa_trc(rp
->bfa
, rp
->rport_tag
);
4406 bfa_trc(rp
->bfa
, event
);
4409 case BFA_RPORT_SM_CREATE
:
4410 bfa_stats(rp
, sm_un_cr
);
4411 bfa_sm_set_state(rp
, bfa_rport_sm_created
);
4415 bfa_stats(rp
, sm_un_unexp
);
4416 bfa_sm_fault(rp
->bfa
, event
);
4421 bfa_rport_sm_created(struct bfa_rport_s
*rp
, enum bfa_rport_event event
)
4423 bfa_trc(rp
->bfa
, rp
->rport_tag
);
4424 bfa_trc(rp
->bfa
, event
);
4427 case BFA_RPORT_SM_ONLINE
:
4428 bfa_stats(rp
, sm_cr_on
);
4429 if (bfa_rport_send_fwcreate(rp
))
4430 bfa_sm_set_state(rp
, bfa_rport_sm_fwcreate
);
4432 bfa_sm_set_state(rp
, bfa_rport_sm_fwcreate_qfull
);
4435 case BFA_RPORT_SM_DELETE
:
4436 bfa_stats(rp
, sm_cr_del
);
4437 bfa_sm_set_state(rp
, bfa_rport_sm_uninit
);
4441 case BFA_RPORT_SM_HWFAIL
:
4442 bfa_stats(rp
, sm_cr_hwf
);
4443 bfa_sm_set_state(rp
, bfa_rport_sm_iocdisable
);
4447 bfa_stats(rp
, sm_cr_unexp
);
4448 bfa_sm_fault(rp
->bfa
, event
);
4453 * Waiting for rport create response from firmware.
4456 bfa_rport_sm_fwcreate(struct bfa_rport_s
*rp
, enum bfa_rport_event event
)
4458 bfa_trc(rp
->bfa
, rp
->rport_tag
);
4459 bfa_trc(rp
->bfa
, event
);
4462 case BFA_RPORT_SM_FWRSP
:
4463 bfa_stats(rp
, sm_fwc_rsp
);
4464 bfa_sm_set_state(rp
, bfa_rport_sm_online
);
4465 bfa_rport_online_cb(rp
);
4468 case BFA_RPORT_SM_DELETE
:
4469 bfa_stats(rp
, sm_fwc_del
);
4470 bfa_sm_set_state(rp
, bfa_rport_sm_delete_pending
);
4473 case BFA_RPORT_SM_OFFLINE
:
4474 bfa_stats(rp
, sm_fwc_off
);
4475 bfa_sm_set_state(rp
, bfa_rport_sm_offline_pending
);
4478 case BFA_RPORT_SM_HWFAIL
:
4479 bfa_stats(rp
, sm_fwc_hwf
);
4480 bfa_sm_set_state(rp
, bfa_rport_sm_iocdisable
);
4484 bfa_stats(rp
, sm_fwc_unexp
);
4485 bfa_sm_fault(rp
->bfa
, event
);
4490 * Request queue is full, awaiting queue resume to send create request.
4493 bfa_rport_sm_fwcreate_qfull(struct bfa_rport_s
*rp
, enum bfa_rport_event event
)
4495 bfa_trc(rp
->bfa
, rp
->rport_tag
);
4496 bfa_trc(rp
->bfa
, event
);
4499 case BFA_RPORT_SM_QRESUME
:
4500 bfa_sm_set_state(rp
, bfa_rport_sm_fwcreate
);
4501 bfa_rport_send_fwcreate(rp
);
4504 case BFA_RPORT_SM_DELETE
:
4505 bfa_stats(rp
, sm_fwc_del
);
4506 bfa_sm_set_state(rp
, bfa_rport_sm_uninit
);
4507 bfa_reqq_wcancel(&rp
->reqq_wait
);
4511 case BFA_RPORT_SM_OFFLINE
:
4512 bfa_stats(rp
, sm_fwc_off
);
4513 bfa_sm_set_state(rp
, bfa_rport_sm_offline
);
4514 bfa_reqq_wcancel(&rp
->reqq_wait
);
4515 bfa_rport_offline_cb(rp
);
4518 case BFA_RPORT_SM_HWFAIL
:
4519 bfa_stats(rp
, sm_fwc_hwf
);
4520 bfa_sm_set_state(rp
, bfa_rport_sm_iocdisable
);
4521 bfa_reqq_wcancel(&rp
->reqq_wait
);
4525 bfa_stats(rp
, sm_fwc_unexp
);
4526 bfa_sm_fault(rp
->bfa
, event
);
4531 * Online state - normal parking state.
4534 bfa_rport_sm_online(struct bfa_rport_s
*rp
, enum bfa_rport_event event
)
4536 struct bfi_rport_qos_scn_s
*qos_scn
;
4538 bfa_trc(rp
->bfa
, rp
->rport_tag
);
4539 bfa_trc(rp
->bfa
, event
);
4542 case BFA_RPORT_SM_OFFLINE
:
4543 bfa_stats(rp
, sm_on_off
);
4544 if (bfa_rport_send_fwdelete(rp
))
4545 bfa_sm_set_state(rp
, bfa_rport_sm_fwdelete
);
4547 bfa_sm_set_state(rp
, bfa_rport_sm_fwdelete_qfull
);
4550 case BFA_RPORT_SM_DELETE
:
4551 bfa_stats(rp
, sm_on_del
);
4552 if (bfa_rport_send_fwdelete(rp
))
4553 bfa_sm_set_state(rp
, bfa_rport_sm_deleting
);
4555 bfa_sm_set_state(rp
, bfa_rport_sm_deleting_qfull
);
4558 case BFA_RPORT_SM_HWFAIL
:
4559 bfa_stats(rp
, sm_on_hwf
);
4560 bfa_sm_set_state(rp
, bfa_rport_sm_iocdisable
);
4563 case BFA_RPORT_SM_SET_SPEED
:
4564 bfa_rport_send_fwspeed(rp
);
4567 case BFA_RPORT_SM_QOS_SCN
:
4568 qos_scn
= (struct bfi_rport_qos_scn_s
*) rp
->event_arg
.fw_msg
;
4569 rp
->qos_attr
= qos_scn
->new_qos_attr
;
4570 bfa_trc(rp
->bfa
, qos_scn
->old_qos_attr
.qos_flow_id
);
4571 bfa_trc(rp
->bfa
, qos_scn
->new_qos_attr
.qos_flow_id
);
4572 bfa_trc(rp
->bfa
, qos_scn
->old_qos_attr
.qos_priority
);
4573 bfa_trc(rp
->bfa
, qos_scn
->new_qos_attr
.qos_priority
);
4575 qos_scn
->old_qos_attr
.qos_flow_id
=
4576 be32_to_cpu(qos_scn
->old_qos_attr
.qos_flow_id
);
4577 qos_scn
->new_qos_attr
.qos_flow_id
=
4578 be32_to_cpu(qos_scn
->new_qos_attr
.qos_flow_id
);
4580 if (qos_scn
->old_qos_attr
.qos_flow_id
!=
4581 qos_scn
->new_qos_attr
.qos_flow_id
)
4582 bfa_cb_rport_qos_scn_flowid(rp
->rport_drv
,
4583 qos_scn
->old_qos_attr
,
4584 qos_scn
->new_qos_attr
);
4585 if (qos_scn
->old_qos_attr
.qos_priority
!=
4586 qos_scn
->new_qos_attr
.qos_priority
)
4587 bfa_cb_rport_qos_scn_prio(rp
->rport_drv
,
4588 qos_scn
->old_qos_attr
,
4589 qos_scn
->new_qos_attr
);
4593 bfa_stats(rp
, sm_on_unexp
);
4594 bfa_sm_fault(rp
->bfa
, event
);
4599 * Firmware rport is being deleted - awaiting f/w response.
4602 bfa_rport_sm_fwdelete(struct bfa_rport_s
*rp
, enum bfa_rport_event event
)
4604 bfa_trc(rp
->bfa
, rp
->rport_tag
);
4605 bfa_trc(rp
->bfa
, event
);
4608 case BFA_RPORT_SM_FWRSP
:
4609 bfa_stats(rp
, sm_fwd_rsp
);
4610 bfa_sm_set_state(rp
, bfa_rport_sm_offline
);
4611 bfa_rport_offline_cb(rp
);
4614 case BFA_RPORT_SM_DELETE
:
4615 bfa_stats(rp
, sm_fwd_del
);
4616 bfa_sm_set_state(rp
, bfa_rport_sm_deleting
);
4619 case BFA_RPORT_SM_HWFAIL
:
4620 bfa_stats(rp
, sm_fwd_hwf
);
4621 bfa_sm_set_state(rp
, bfa_rport_sm_iocdisable
);
4622 bfa_rport_offline_cb(rp
);
4626 bfa_stats(rp
, sm_fwd_unexp
);
4627 bfa_sm_fault(rp
->bfa
, event
);
4632 bfa_rport_sm_fwdelete_qfull(struct bfa_rport_s
*rp
, enum bfa_rport_event event
)
4634 bfa_trc(rp
->bfa
, rp
->rport_tag
);
4635 bfa_trc(rp
->bfa
, event
);
4638 case BFA_RPORT_SM_QRESUME
:
4639 bfa_sm_set_state(rp
, bfa_rport_sm_fwdelete
);
4640 bfa_rport_send_fwdelete(rp
);
4643 case BFA_RPORT_SM_DELETE
:
4644 bfa_stats(rp
, sm_fwd_del
);
4645 bfa_sm_set_state(rp
, bfa_rport_sm_deleting_qfull
);
4648 case BFA_RPORT_SM_HWFAIL
:
4649 bfa_stats(rp
, sm_fwd_hwf
);
4650 bfa_sm_set_state(rp
, bfa_rport_sm_iocdisable
);
4651 bfa_reqq_wcancel(&rp
->reqq_wait
);
4652 bfa_rport_offline_cb(rp
);
4656 bfa_stats(rp
, sm_fwd_unexp
);
4657 bfa_sm_fault(rp
->bfa
, event
);
4665 bfa_rport_sm_offline(struct bfa_rport_s
*rp
, enum bfa_rport_event event
)
4667 bfa_trc(rp
->bfa
, rp
->rport_tag
);
4668 bfa_trc(rp
->bfa
, event
);
4671 case BFA_RPORT_SM_DELETE
:
4672 bfa_stats(rp
, sm_off_del
);
4673 bfa_sm_set_state(rp
, bfa_rport_sm_uninit
);
4677 case BFA_RPORT_SM_ONLINE
:
4678 bfa_stats(rp
, sm_off_on
);
4679 if (bfa_rport_send_fwcreate(rp
))
4680 bfa_sm_set_state(rp
, bfa_rport_sm_fwcreate
);
4682 bfa_sm_set_state(rp
, bfa_rport_sm_fwcreate_qfull
);
4685 case BFA_RPORT_SM_HWFAIL
:
4686 bfa_stats(rp
, sm_off_hwf
);
4687 bfa_sm_set_state(rp
, bfa_rport_sm_iocdisable
);
4690 case BFA_RPORT_SM_OFFLINE
:
4691 bfa_rport_offline_cb(rp
);
4695 bfa_stats(rp
, sm_off_unexp
);
4696 bfa_sm_fault(rp
->bfa
, event
);
4701 * Rport is deleted, waiting for firmware response to delete.
4704 bfa_rport_sm_deleting(struct bfa_rport_s
*rp
, enum bfa_rport_event event
)
4706 bfa_trc(rp
->bfa
, rp
->rport_tag
);
4707 bfa_trc(rp
->bfa
, event
);
4710 case BFA_RPORT_SM_FWRSP
:
4711 bfa_stats(rp
, sm_del_fwrsp
);
4712 bfa_sm_set_state(rp
, bfa_rport_sm_uninit
);
4716 case BFA_RPORT_SM_HWFAIL
:
4717 bfa_stats(rp
, sm_del_hwf
);
4718 bfa_sm_set_state(rp
, bfa_rport_sm_uninit
);
4723 bfa_sm_fault(rp
->bfa
, event
);
4728 bfa_rport_sm_deleting_qfull(struct bfa_rport_s
*rp
, enum bfa_rport_event event
)
4730 bfa_trc(rp
->bfa
, rp
->rport_tag
);
4731 bfa_trc(rp
->bfa
, event
);
4734 case BFA_RPORT_SM_QRESUME
:
4735 bfa_stats(rp
, sm_del_fwrsp
);
4736 bfa_sm_set_state(rp
, bfa_rport_sm_deleting
);
4737 bfa_rport_send_fwdelete(rp
);
4740 case BFA_RPORT_SM_HWFAIL
:
4741 bfa_stats(rp
, sm_del_hwf
);
4742 bfa_sm_set_state(rp
, bfa_rport_sm_uninit
);
4743 bfa_reqq_wcancel(&rp
->reqq_wait
);
4748 bfa_sm_fault(rp
->bfa
, event
);
4753 * Waiting for rport create response from firmware. A delete is pending.
4756 bfa_rport_sm_delete_pending(struct bfa_rport_s
*rp
,
4757 enum bfa_rport_event event
)
4759 bfa_trc(rp
->bfa
, rp
->rport_tag
);
4760 bfa_trc(rp
->bfa
, event
);
4763 case BFA_RPORT_SM_FWRSP
:
4764 bfa_stats(rp
, sm_delp_fwrsp
);
4765 if (bfa_rport_send_fwdelete(rp
))
4766 bfa_sm_set_state(rp
, bfa_rport_sm_deleting
);
4768 bfa_sm_set_state(rp
, bfa_rport_sm_deleting_qfull
);
4771 case BFA_RPORT_SM_HWFAIL
:
4772 bfa_stats(rp
, sm_delp_hwf
);
4773 bfa_sm_set_state(rp
, bfa_rport_sm_uninit
);
4778 bfa_stats(rp
, sm_delp_unexp
);
4779 bfa_sm_fault(rp
->bfa
, event
);
4784 * Waiting for rport create response from firmware. Rport offline is pending.
4787 bfa_rport_sm_offline_pending(struct bfa_rport_s
*rp
,
4788 enum bfa_rport_event event
)
4790 bfa_trc(rp
->bfa
, rp
->rport_tag
);
4791 bfa_trc(rp
->bfa
, event
);
4794 case BFA_RPORT_SM_FWRSP
:
4795 bfa_stats(rp
, sm_offp_fwrsp
);
4796 if (bfa_rport_send_fwdelete(rp
))
4797 bfa_sm_set_state(rp
, bfa_rport_sm_fwdelete
);
4799 bfa_sm_set_state(rp
, bfa_rport_sm_fwdelete_qfull
);
4802 case BFA_RPORT_SM_DELETE
:
4803 bfa_stats(rp
, sm_offp_del
);
4804 bfa_sm_set_state(rp
, bfa_rport_sm_delete_pending
);
4807 case BFA_RPORT_SM_HWFAIL
:
4808 bfa_stats(rp
, sm_offp_hwf
);
4809 bfa_sm_set_state(rp
, bfa_rport_sm_iocdisable
);
4810 bfa_rport_offline_cb(rp
);
4814 bfa_stats(rp
, sm_offp_unexp
);
4815 bfa_sm_fault(rp
->bfa
, event
);
4823 bfa_rport_sm_iocdisable(struct bfa_rport_s
*rp
, enum bfa_rport_event event
)
4825 bfa_trc(rp
->bfa
, rp
->rport_tag
);
4826 bfa_trc(rp
->bfa
, event
);
4829 case BFA_RPORT_SM_OFFLINE
:
4830 bfa_stats(rp
, sm_iocd_off
);
4831 bfa_rport_offline_cb(rp
);
4834 case BFA_RPORT_SM_DELETE
:
4835 bfa_stats(rp
, sm_iocd_del
);
4836 bfa_sm_set_state(rp
, bfa_rport_sm_uninit
);
4840 case BFA_RPORT_SM_ONLINE
:
4841 bfa_stats(rp
, sm_iocd_on
);
4842 if (bfa_rport_send_fwcreate(rp
))
4843 bfa_sm_set_state(rp
, bfa_rport_sm_fwcreate
);
4845 bfa_sm_set_state(rp
, bfa_rport_sm_fwcreate_qfull
);
4848 case BFA_RPORT_SM_HWFAIL
:
4852 bfa_stats(rp
, sm_iocd_unexp
);
4853 bfa_sm_fault(rp
->bfa
, event
);
4860 * bfa_rport_private BFA rport private functions
4864 __bfa_cb_rport_online(void *cbarg
, bfa_boolean_t complete
)
4866 struct bfa_rport_s
*rp
= cbarg
;
4869 bfa_cb_rport_online(rp
->rport_drv
);
4873 __bfa_cb_rport_offline(void *cbarg
, bfa_boolean_t complete
)
4875 struct bfa_rport_s
*rp
= cbarg
;
4878 bfa_cb_rport_offline(rp
->rport_drv
);
4882 bfa_rport_qresume(void *cbarg
)
4884 struct bfa_rport_s
*rp
= cbarg
;
4886 bfa_sm_send_event(rp
, BFA_RPORT_SM_QRESUME
);
4890 bfa_rport_meminfo(struct bfa_iocfc_cfg_s
*cfg
, struct bfa_meminfo_s
*minfo
,
4893 struct bfa_mem_kva_s
*rport_kva
= BFA_MEM_RPORT_KVA(bfa
);
4895 if (cfg
->fwcfg
.num_rports
< BFA_RPORT_MIN
)
4896 cfg
->fwcfg
.num_rports
= BFA_RPORT_MIN
;
4899 bfa_mem_kva_setup(minfo
, rport_kva
,
4900 cfg
->fwcfg
.num_rports
* sizeof(struct bfa_rport_s
));
4904 bfa_rport_attach(struct bfa_s
*bfa
, void *bfad
, struct bfa_iocfc_cfg_s
*cfg
,
4905 struct bfa_pcidev_s
*pcidev
)
4907 struct bfa_rport_mod_s
*mod
= BFA_RPORT_MOD(bfa
);
4908 struct bfa_rport_s
*rp
;
4911 INIT_LIST_HEAD(&mod
->rp_free_q
);
4912 INIT_LIST_HEAD(&mod
->rp_active_q
);
4913 INIT_LIST_HEAD(&mod
->rp_unused_q
);
4915 rp
= (struct bfa_rport_s
*) bfa_mem_kva_curp(mod
);
4917 mod
->num_rports
= cfg
->fwcfg
.num_rports
;
4919 WARN_ON(!mod
->num_rports
||
4920 (mod
->num_rports
& (mod
->num_rports
- 1)));
4922 for (i
= 0; i
< mod
->num_rports
; i
++, rp
++) {
4923 memset(rp
, 0, sizeof(struct bfa_rport_s
));
4926 bfa_sm_set_state(rp
, bfa_rport_sm_uninit
);
4932 list_add_tail(&rp
->qe
, &mod
->rp_free_q
);
4934 bfa_reqq_winit(&rp
->reqq_wait
, bfa_rport_qresume
, rp
);
4940 bfa_mem_kva_curp(mod
) = (u8
*) rp
;
4944 bfa_rport_detach(struct bfa_s
*bfa
)
4949 bfa_rport_start(struct bfa_s
*bfa
)
4954 bfa_rport_stop(struct bfa_s
*bfa
)
4959 bfa_rport_iocdisable(struct bfa_s
*bfa
)
4961 struct bfa_rport_mod_s
*mod
= BFA_RPORT_MOD(bfa
);
4962 struct bfa_rport_s
*rport
;
4963 struct list_head
*qe
, *qen
;
4965 /* Enqueue unused rport resources to free_q */
4966 list_splice_tail_init(&mod
->rp_unused_q
, &mod
->rp_free_q
);
4968 list_for_each_safe(qe
, qen
, &mod
->rp_active_q
) {
4969 rport
= (struct bfa_rport_s
*) qe
;
4970 bfa_sm_send_event(rport
, BFA_RPORT_SM_HWFAIL
);
4974 static struct bfa_rport_s
*
4975 bfa_rport_alloc(struct bfa_rport_mod_s
*mod
)
4977 struct bfa_rport_s
*rport
;
4979 bfa_q_deq(&mod
->rp_free_q
, &rport
);
4981 list_add_tail(&rport
->qe
, &mod
->rp_active_q
);
4987 bfa_rport_free(struct bfa_rport_s
*rport
)
4989 struct bfa_rport_mod_s
*mod
= BFA_RPORT_MOD(rport
->bfa
);
4991 WARN_ON(!bfa_q_is_on_q(&mod
->rp_active_q
, rport
));
4992 list_del(&rport
->qe
);
4993 list_add_tail(&rport
->qe
, &mod
->rp_free_q
);
4996 static bfa_boolean_t
4997 bfa_rport_send_fwcreate(struct bfa_rport_s
*rp
)
4999 struct bfi_rport_create_req_s
*m
;
5002 * check for room in queue to send request now
5004 m
= bfa_reqq_next(rp
->bfa
, BFA_REQQ_RPORT
);
5006 bfa_reqq_wait(rp
->bfa
, BFA_REQQ_RPORT
, &rp
->reqq_wait
);
5010 bfi_h2i_set(m
->mh
, BFI_MC_RPORT
, BFI_RPORT_H2I_CREATE_REQ
,
5011 bfa_fn_lpu(rp
->bfa
));
5012 m
->bfa_handle
= rp
->rport_tag
;
5013 m
->max_frmsz
= cpu_to_be16(rp
->rport_info
.max_frmsz
);
5014 m
->pid
= rp
->rport_info
.pid
;
5015 m
->lp_fwtag
= bfa_lps_get_fwtag(rp
->bfa
, (u8
)rp
->rport_info
.lp_tag
);
5016 m
->local_pid
= rp
->rport_info
.local_pid
;
5017 m
->fc_class
= rp
->rport_info
.fc_class
;
5018 m
->vf_en
= rp
->rport_info
.vf_en
;
5019 m
->vf_id
= rp
->rport_info
.vf_id
;
5020 m
->cisc
= rp
->rport_info
.cisc
;
5023 * queue I/O message to firmware
5025 bfa_reqq_produce(rp
->bfa
, BFA_REQQ_RPORT
, m
->mh
);
5029 static bfa_boolean_t
5030 bfa_rport_send_fwdelete(struct bfa_rport_s
*rp
)
5032 struct bfi_rport_delete_req_s
*m
;
5035 * check for room in queue to send request now
5037 m
= bfa_reqq_next(rp
->bfa
, BFA_REQQ_RPORT
);
5039 bfa_reqq_wait(rp
->bfa
, BFA_REQQ_RPORT
, &rp
->reqq_wait
);
5043 bfi_h2i_set(m
->mh
, BFI_MC_RPORT
, BFI_RPORT_H2I_DELETE_REQ
,
5044 bfa_fn_lpu(rp
->bfa
));
5045 m
->fw_handle
= rp
->fw_handle
;
5048 * queue I/O message to firmware
5050 bfa_reqq_produce(rp
->bfa
, BFA_REQQ_RPORT
, m
->mh
);
5054 static bfa_boolean_t
5055 bfa_rport_send_fwspeed(struct bfa_rport_s
*rp
)
5057 struct bfa_rport_speed_req_s
*m
;
5060 * check for room in queue to send request now
5062 m
= bfa_reqq_next(rp
->bfa
, BFA_REQQ_RPORT
);
5064 bfa_trc(rp
->bfa
, rp
->rport_info
.speed
);
5068 bfi_h2i_set(m
->mh
, BFI_MC_RPORT
, BFI_RPORT_H2I_SET_SPEED_REQ
,
5069 bfa_fn_lpu(rp
->bfa
));
5070 m
->fw_handle
= rp
->fw_handle
;
5071 m
->speed
= (u8
)rp
->rport_info
.speed
;
5074 * queue I/O message to firmware
5076 bfa_reqq_produce(rp
->bfa
, BFA_REQQ_RPORT
, m
->mh
);
5087 * Rport interrupt processing.
5090 bfa_rport_isr(struct bfa_s
*bfa
, struct bfi_msg_s
*m
)
5092 union bfi_rport_i2h_msg_u msg
;
5093 struct bfa_rport_s
*rp
;
5095 bfa_trc(bfa
, m
->mhdr
.msg_id
);
5099 switch (m
->mhdr
.msg_id
) {
5100 case BFI_RPORT_I2H_CREATE_RSP
:
5101 rp
= BFA_RPORT_FROM_TAG(bfa
, msg
.create_rsp
->bfa_handle
);
5102 rp
->fw_handle
= msg
.create_rsp
->fw_handle
;
5103 rp
->qos_attr
= msg
.create_rsp
->qos_attr
;
5104 bfa_rport_set_lunmask(bfa
, rp
);
5105 WARN_ON(msg
.create_rsp
->status
!= BFA_STATUS_OK
);
5106 bfa_sm_send_event(rp
, BFA_RPORT_SM_FWRSP
);
5109 case BFI_RPORT_I2H_DELETE_RSP
:
5110 rp
= BFA_RPORT_FROM_TAG(bfa
, msg
.delete_rsp
->bfa_handle
);
5111 WARN_ON(msg
.delete_rsp
->status
!= BFA_STATUS_OK
);
5112 bfa_rport_unset_lunmask(bfa
, rp
);
5113 bfa_sm_send_event(rp
, BFA_RPORT_SM_FWRSP
);
5116 case BFI_RPORT_I2H_QOS_SCN
:
5117 rp
= BFA_RPORT_FROM_TAG(bfa
, msg
.qos_scn_evt
->bfa_handle
);
5118 rp
->event_arg
.fw_msg
= msg
.qos_scn_evt
;
5119 bfa_sm_send_event(rp
, BFA_RPORT_SM_QOS_SCN
);
5122 case BFI_RPORT_I2H_LIP_SCN_ONLINE
:
5123 bfa_fcport_update_loop_info(BFA_FCPORT_MOD(bfa
),
5124 &msg
.lip_scn
->loop_info
);
5125 bfa_cb_rport_scn_online(bfa
);
5128 case BFI_RPORT_I2H_LIP_SCN_OFFLINE
:
5129 bfa_cb_rport_scn_offline(bfa
);
5132 case BFI_RPORT_I2H_NO_DEV
:
5133 rp
= BFA_RPORT_FROM_TAG(bfa
, msg
.lip_scn
->bfa_handle
);
5134 bfa_cb_rport_scn_no_dev(rp
->rport_drv
);
5138 bfa_trc(bfa
, m
->mhdr
.msg_id
);
5144 bfa_rport_res_recfg(struct bfa_s
*bfa
, u16 num_rport_fw
)
5146 struct bfa_rport_mod_s
*mod
= BFA_RPORT_MOD(bfa
);
5147 struct list_head
*qe
;
5150 for (i
= 0; i
< (mod
->num_rports
- num_rport_fw
); i
++) {
5151 bfa_q_deq_tail(&mod
->rp_free_q
, &qe
);
5152 list_add_tail(qe
, &mod
->rp_unused_q
);
5160 struct bfa_rport_s
*
5161 bfa_rport_create(struct bfa_s
*bfa
, void *rport_drv
)
5163 struct bfa_rport_s
*rp
;
5165 rp
= bfa_rport_alloc(BFA_RPORT_MOD(bfa
));
5171 rp
->rport_drv
= rport_drv
;
5172 memset(&rp
->stats
, 0, sizeof(rp
->stats
));
5174 WARN_ON(!bfa_sm_cmp_state(rp
, bfa_rport_sm_uninit
));
5175 bfa_sm_send_event(rp
, BFA_RPORT_SM_CREATE
);
5181 bfa_rport_online(struct bfa_rport_s
*rport
, struct bfa_rport_info_s
*rport_info
)
5183 WARN_ON(rport_info
->max_frmsz
== 0);
5186 * Some JBODs are seen to be not setting PDU size correctly in PLOGI
5187 * responses. Default to minimum size.
5189 if (rport_info
->max_frmsz
== 0) {
5190 bfa_trc(rport
->bfa
, rport
->rport_tag
);
5191 rport_info
->max_frmsz
= FC_MIN_PDUSZ
;
5194 rport
->rport_info
= *rport_info
;
5195 bfa_sm_send_event(rport
, BFA_RPORT_SM_ONLINE
);
5199 bfa_rport_speed(struct bfa_rport_s
*rport
, enum bfa_port_speed speed
)
5201 WARN_ON(speed
== 0);
5202 WARN_ON(speed
== BFA_PORT_SPEED_AUTO
);
5205 rport
->rport_info
.speed
= speed
;
5206 bfa_sm_send_event(rport
, BFA_RPORT_SM_SET_SPEED
);
5210 /* Set Rport LUN Mask */
5212 bfa_rport_set_lunmask(struct bfa_s
*bfa
, struct bfa_rport_s
*rp
)
5214 struct bfa_lps_mod_s
*lps_mod
= BFA_LPS_MOD(bfa
);
5215 wwn_t lp_wwn
, rp_wwn
;
5216 u8 lp_tag
= (u8
)rp
->rport_info
.lp_tag
;
5218 rp_wwn
= ((struct bfa_fcs_rport_s
*)rp
->rport_drv
)->pwwn
;
5219 lp_wwn
= (BFA_LPS_FROM_TAG(lps_mod
, rp
->rport_info
.lp_tag
))->pwwn
;
5221 BFA_LPS_FROM_TAG(lps_mod
, rp
->rport_info
.lp_tag
)->lun_mask
=
5222 rp
->lun_mask
= BFA_TRUE
;
5223 bfa_fcpim_lunmask_rp_update(bfa
, lp_wwn
, rp_wwn
, rp
->rport_tag
, lp_tag
);
5226 /* Unset Rport LUN mask */
5228 bfa_rport_unset_lunmask(struct bfa_s
*bfa
, struct bfa_rport_s
*rp
)
5230 struct bfa_lps_mod_s
*lps_mod
= BFA_LPS_MOD(bfa
);
5231 wwn_t lp_wwn
, rp_wwn
;
5233 rp_wwn
= ((struct bfa_fcs_rport_s
*)rp
->rport_drv
)->pwwn
;
5234 lp_wwn
= (BFA_LPS_FROM_TAG(lps_mod
, rp
->rport_info
.lp_tag
))->pwwn
;
5236 BFA_LPS_FROM_TAG(lps_mod
, rp
->rport_info
.lp_tag
)->lun_mask
=
5237 rp
->lun_mask
= BFA_FALSE
;
5238 bfa_fcpim_lunmask_rp_update(bfa
, lp_wwn
, rp_wwn
,
5239 BFA_RPORT_TAG_INVALID
, BFA_LP_TAG_INVALID
);
5243 * SGPG related functions
5247 * Compute and return memory needed by FCP(im) module.
5250 bfa_sgpg_meminfo(struct bfa_iocfc_cfg_s
*cfg
, struct bfa_meminfo_s
*minfo
,
5253 struct bfa_sgpg_mod_s
*sgpg_mod
= BFA_SGPG_MOD(bfa
);
5254 struct bfa_mem_kva_s
*sgpg_kva
= BFA_MEM_SGPG_KVA(bfa
);
5255 struct bfa_mem_dma_s
*seg_ptr
;
5256 u16 nsegs
, idx
, per_seg_sgpg
, num_sgpg
;
5257 u32 sgpg_sz
= sizeof(struct bfi_sgpg_s
);
5259 if (cfg
->drvcfg
.num_sgpgs
< BFA_SGPG_MIN
)
5260 cfg
->drvcfg
.num_sgpgs
= BFA_SGPG_MIN
;
5261 else if (cfg
->drvcfg
.num_sgpgs
> BFA_SGPG_MAX
)
5262 cfg
->drvcfg
.num_sgpgs
= BFA_SGPG_MAX
;
5264 num_sgpg
= cfg
->drvcfg
.num_sgpgs
;
5266 nsegs
= BFI_MEM_DMA_NSEGS(num_sgpg
, sgpg_sz
);
5267 per_seg_sgpg
= BFI_MEM_NREQS_SEG(sgpg_sz
);
5269 bfa_mem_dma_seg_iter(sgpg_mod
, seg_ptr
, nsegs
, idx
) {
5270 if (num_sgpg
>= per_seg_sgpg
) {
5271 num_sgpg
-= per_seg_sgpg
;
5272 bfa_mem_dma_setup(minfo
, seg_ptr
,
5273 per_seg_sgpg
* sgpg_sz
);
5275 bfa_mem_dma_setup(minfo
, seg_ptr
,
5276 num_sgpg
* sgpg_sz
);
5280 bfa_mem_kva_setup(minfo
, sgpg_kva
,
5281 cfg
->drvcfg
.num_sgpgs
* sizeof(struct bfa_sgpg_s
));
5285 bfa_sgpg_attach(struct bfa_s
*bfa
, void *bfad
, struct bfa_iocfc_cfg_s
*cfg
,
5286 struct bfa_pcidev_s
*pcidev
)
5288 struct bfa_sgpg_mod_s
*mod
= BFA_SGPG_MOD(bfa
);
5289 struct bfa_sgpg_s
*hsgpg
;
5290 struct bfi_sgpg_s
*sgpg
;
5292 struct bfa_mem_dma_s
*seg_ptr
;
5293 u32 sgpg_sz
= sizeof(struct bfi_sgpg_s
);
5294 u16 i
, idx
, nsegs
, per_seg_sgpg
, num_sgpg
;
5298 union bfi_addr_u addr
;
5299 } sgpg_pa
, sgpg_pa_tmp
;
5301 INIT_LIST_HEAD(&mod
->sgpg_q
);
5302 INIT_LIST_HEAD(&mod
->sgpg_wait_q
);
5304 bfa_trc(bfa
, cfg
->drvcfg
.num_sgpgs
);
5306 mod
->free_sgpgs
= mod
->num_sgpgs
= cfg
->drvcfg
.num_sgpgs
;
5308 num_sgpg
= cfg
->drvcfg
.num_sgpgs
;
5309 nsegs
= BFI_MEM_DMA_NSEGS(num_sgpg
, sgpg_sz
);
5311 /* dma/kva mem claim */
5312 hsgpg
= (struct bfa_sgpg_s
*) bfa_mem_kva_curp(mod
);
5314 bfa_mem_dma_seg_iter(mod
, seg_ptr
, nsegs
, idx
) {
5316 if (!bfa_mem_dma_virt(seg_ptr
))
5319 align_len
= BFA_SGPG_ROUNDUP(bfa_mem_dma_phys(seg_ptr
)) -
5320 bfa_mem_dma_phys(seg_ptr
);
5322 sgpg
= (struct bfi_sgpg_s
*)
5323 (((u8
*) bfa_mem_dma_virt(seg_ptr
)) + align_len
);
5324 sgpg_pa
.pa
= bfa_mem_dma_phys(seg_ptr
) + align_len
;
5325 WARN_ON(sgpg_pa
.pa
& (sgpg_sz
- 1));
5327 per_seg_sgpg
= (seg_ptr
->mem_len
- (u32
)align_len
) / sgpg_sz
;
5329 for (i
= 0; num_sgpg
> 0 && i
< per_seg_sgpg
; i
++, num_sgpg
--) {
5330 memset(hsgpg
, 0, sizeof(*hsgpg
));
5331 memset(sgpg
, 0, sizeof(*sgpg
));
5334 sgpg_pa_tmp
.pa
= bfa_sgaddr_le(sgpg_pa
.pa
);
5335 hsgpg
->sgpg_pa
= sgpg_pa_tmp
.addr
;
5336 list_add_tail(&hsgpg
->qe
, &mod
->sgpg_q
);
5340 sgpg_pa
.pa
+= sgpg_sz
;
5344 bfa_mem_kva_curp(mod
) = (u8
*) hsgpg
;
5348 bfa_sgpg_detach(struct bfa_s
*bfa
)
5353 bfa_sgpg_start(struct bfa_s
*bfa
)
5358 bfa_sgpg_stop(struct bfa_s
*bfa
)
5363 bfa_sgpg_iocdisable(struct bfa_s
*bfa
)
5368 bfa_sgpg_malloc(struct bfa_s
*bfa
, struct list_head
*sgpg_q
, int nsgpgs
)
5370 struct bfa_sgpg_mod_s
*mod
= BFA_SGPG_MOD(bfa
);
5371 struct bfa_sgpg_s
*hsgpg
;
5374 if (mod
->free_sgpgs
< nsgpgs
)
5375 return BFA_STATUS_ENOMEM
;
5377 for (i
= 0; i
< nsgpgs
; i
++) {
5378 bfa_q_deq(&mod
->sgpg_q
, &hsgpg
);
5380 list_add_tail(&hsgpg
->qe
, sgpg_q
);
5383 mod
->free_sgpgs
-= nsgpgs
;
5384 return BFA_STATUS_OK
;
5388 bfa_sgpg_mfree(struct bfa_s
*bfa
, struct list_head
*sgpg_q
, int nsgpg
)
5390 struct bfa_sgpg_mod_s
*mod
= BFA_SGPG_MOD(bfa
);
5391 struct bfa_sgpg_wqe_s
*wqe
;
5393 mod
->free_sgpgs
+= nsgpg
;
5394 WARN_ON(mod
->free_sgpgs
> mod
->num_sgpgs
);
5396 list_splice_tail_init(sgpg_q
, &mod
->sgpg_q
);
5398 if (list_empty(&mod
->sgpg_wait_q
))
5402 * satisfy as many waiting requests as possible
5405 wqe
= bfa_q_first(&mod
->sgpg_wait_q
);
5406 if (mod
->free_sgpgs
< wqe
->nsgpg
)
5407 nsgpg
= mod
->free_sgpgs
;
5410 bfa_sgpg_malloc(bfa
, &wqe
->sgpg_q
, nsgpg
);
5411 wqe
->nsgpg
-= nsgpg
;
5412 if (wqe
->nsgpg
== 0) {
5414 wqe
->cbfn(wqe
->cbarg
);
5416 } while (mod
->free_sgpgs
&& !list_empty(&mod
->sgpg_wait_q
));
5420 bfa_sgpg_wait(struct bfa_s
*bfa
, struct bfa_sgpg_wqe_s
*wqe
, int nsgpg
)
5422 struct bfa_sgpg_mod_s
*mod
= BFA_SGPG_MOD(bfa
);
5424 WARN_ON(nsgpg
<= 0);
5425 WARN_ON(nsgpg
<= mod
->free_sgpgs
);
5427 wqe
->nsgpg_total
= wqe
->nsgpg
= nsgpg
;
5430 * allocate any left to this one first
5432 if (mod
->free_sgpgs
) {
5434 * no one else is waiting for SGPG
5436 WARN_ON(!list_empty(&mod
->sgpg_wait_q
));
5437 list_splice_tail_init(&mod
->sgpg_q
, &wqe
->sgpg_q
);
5438 wqe
->nsgpg
-= mod
->free_sgpgs
;
5439 mod
->free_sgpgs
= 0;
5442 list_add_tail(&wqe
->qe
, &mod
->sgpg_wait_q
);
5446 bfa_sgpg_wcancel(struct bfa_s
*bfa
, struct bfa_sgpg_wqe_s
*wqe
)
5448 struct bfa_sgpg_mod_s
*mod
= BFA_SGPG_MOD(bfa
);
5450 WARN_ON(!bfa_q_is_on_q(&mod
->sgpg_wait_q
, wqe
));
5453 if (wqe
->nsgpg_total
!= wqe
->nsgpg
)
5454 bfa_sgpg_mfree(bfa
, &wqe
->sgpg_q
,
5455 wqe
->nsgpg_total
- wqe
->nsgpg
);
5459 bfa_sgpg_winit(struct bfa_sgpg_wqe_s
*wqe
, void (*cbfn
) (void *cbarg
),
5462 INIT_LIST_HEAD(&wqe
->sgpg_q
);
5468 * UF related functions
5471 *****************************************************************************
5472 * Internal functions
5473 *****************************************************************************
5476 __bfa_cb_uf_recv(void *cbarg
, bfa_boolean_t complete
)
5478 struct bfa_uf_s
*uf
= cbarg
;
5479 struct bfa_uf_mod_s
*ufm
= BFA_UF_MOD(uf
->bfa
);
5482 ufm
->ufrecv(ufm
->cbarg
, uf
);
5486 claim_uf_post_msgs(struct bfa_uf_mod_s
*ufm
)
5488 struct bfi_uf_buf_post_s
*uf_bp_msg
;
5492 ufm
->uf_buf_posts
= (struct bfi_uf_buf_post_s
*) bfa_mem_kva_curp(ufm
);
5493 uf_bp_msg
= ufm
->uf_buf_posts
;
5495 for (i
= 0, uf_bp_msg
= ufm
->uf_buf_posts
; i
< ufm
->num_ufs
;
5497 memset(uf_bp_msg
, 0, sizeof(struct bfi_uf_buf_post_s
));
5499 uf_bp_msg
->buf_tag
= i
;
5500 buf_len
= sizeof(struct bfa_uf_buf_s
);
5501 uf_bp_msg
->buf_len
= cpu_to_be16(buf_len
);
5502 bfi_h2i_set(uf_bp_msg
->mh
, BFI_MC_UF
, BFI_UF_H2I_BUF_POST
,
5503 bfa_fn_lpu(ufm
->bfa
));
5504 bfa_alen_set(&uf_bp_msg
->alen
, buf_len
, ufm_pbs_pa(ufm
, i
));
5508 * advance pointer beyond consumed memory
5510 bfa_mem_kva_curp(ufm
) = (u8
*) uf_bp_msg
;
5514 claim_ufs(struct bfa_uf_mod_s
*ufm
)
5517 struct bfa_uf_s
*uf
;
5520 * Claim block of memory for UF list
5522 ufm
->uf_list
= (struct bfa_uf_s
*) bfa_mem_kva_curp(ufm
);
5525 * Initialize UFs and queue it in UF free queue
5527 for (i
= 0, uf
= ufm
->uf_list
; i
< ufm
->num_ufs
; i
++, uf
++) {
5528 memset(uf
, 0, sizeof(struct bfa_uf_s
));
5531 uf
->pb_len
= BFA_PER_UF_DMA_SZ
;
5532 uf
->buf_kva
= bfa_mem_get_dmabuf_kva(ufm
, i
, BFA_PER_UF_DMA_SZ
);
5533 uf
->buf_pa
= ufm_pbs_pa(ufm
, i
);
5534 list_add_tail(&uf
->qe
, &ufm
->uf_free_q
);
5538 * advance memory pointer
5540 bfa_mem_kva_curp(ufm
) = (u8
*) uf
;
5544 uf_mem_claim(struct bfa_uf_mod_s
*ufm
)
5547 claim_uf_post_msgs(ufm
);
5551 bfa_uf_meminfo(struct bfa_iocfc_cfg_s
*cfg
, struct bfa_meminfo_s
*minfo
,
5554 struct bfa_uf_mod_s
*ufm
= BFA_UF_MOD(bfa
);
5555 struct bfa_mem_kva_s
*uf_kva
= BFA_MEM_UF_KVA(bfa
);
5556 u32 num_ufs
= cfg
->fwcfg
.num_uf_bufs
;
5557 struct bfa_mem_dma_s
*seg_ptr
;
5558 u16 nsegs
, idx
, per_seg_uf
= 0;
5560 nsegs
= BFI_MEM_DMA_NSEGS(num_ufs
, BFA_PER_UF_DMA_SZ
);
5561 per_seg_uf
= BFI_MEM_NREQS_SEG(BFA_PER_UF_DMA_SZ
);
5563 bfa_mem_dma_seg_iter(ufm
, seg_ptr
, nsegs
, idx
) {
5564 if (num_ufs
>= per_seg_uf
) {
5565 num_ufs
-= per_seg_uf
;
5566 bfa_mem_dma_setup(minfo
, seg_ptr
,
5567 per_seg_uf
* BFA_PER_UF_DMA_SZ
);
5569 bfa_mem_dma_setup(minfo
, seg_ptr
,
5570 num_ufs
* BFA_PER_UF_DMA_SZ
);
5574 bfa_mem_kva_setup(minfo
, uf_kva
, cfg
->fwcfg
.num_uf_bufs
*
5575 (sizeof(struct bfa_uf_s
) + sizeof(struct bfi_uf_buf_post_s
)));
5579 bfa_uf_attach(struct bfa_s
*bfa
, void *bfad
, struct bfa_iocfc_cfg_s
*cfg
,
5580 struct bfa_pcidev_s
*pcidev
)
5582 struct bfa_uf_mod_s
*ufm
= BFA_UF_MOD(bfa
);
5585 ufm
->num_ufs
= cfg
->fwcfg
.num_uf_bufs
;
5586 INIT_LIST_HEAD(&ufm
->uf_free_q
);
5587 INIT_LIST_HEAD(&ufm
->uf_posted_q
);
5588 INIT_LIST_HEAD(&ufm
->uf_unused_q
);
5594 bfa_uf_detach(struct bfa_s
*bfa
)
5598 static struct bfa_uf_s
*
5599 bfa_uf_get(struct bfa_uf_mod_s
*uf_mod
)
5601 struct bfa_uf_s
*uf
;
5603 bfa_q_deq(&uf_mod
->uf_free_q
, &uf
);
5608 bfa_uf_put(struct bfa_uf_mod_s
*uf_mod
, struct bfa_uf_s
*uf
)
5610 list_add_tail(&uf
->qe
, &uf_mod
->uf_free_q
);
5614 bfa_uf_post(struct bfa_uf_mod_s
*ufm
, struct bfa_uf_s
*uf
)
5616 struct bfi_uf_buf_post_s
*uf_post_msg
;
5618 uf_post_msg
= bfa_reqq_next(ufm
->bfa
, BFA_REQQ_FCXP
);
5620 return BFA_STATUS_FAILED
;
5622 memcpy(uf_post_msg
, &ufm
->uf_buf_posts
[uf
->uf_tag
],
5623 sizeof(struct bfi_uf_buf_post_s
));
5624 bfa_reqq_produce(ufm
->bfa
, BFA_REQQ_FCXP
, uf_post_msg
->mh
);
5626 bfa_trc(ufm
->bfa
, uf
->uf_tag
);
5628 list_add_tail(&uf
->qe
, &ufm
->uf_posted_q
);
5629 return BFA_STATUS_OK
;
5633 bfa_uf_post_all(struct bfa_uf_mod_s
*uf_mod
)
5635 struct bfa_uf_s
*uf
;
5637 while ((uf
= bfa_uf_get(uf_mod
)) != NULL
) {
5638 if (bfa_uf_post(uf_mod
, uf
) != BFA_STATUS_OK
)
5644 uf_recv(struct bfa_s
*bfa
, struct bfi_uf_frm_rcvd_s
*m
)
5646 struct bfa_uf_mod_s
*ufm
= BFA_UF_MOD(bfa
);
5647 u16 uf_tag
= m
->buf_tag
;
5648 struct bfa_uf_s
*uf
= &ufm
->uf_list
[uf_tag
];
5649 struct bfa_uf_buf_s
*uf_buf
;
5651 struct fchs_s
*fchs
;
5653 uf_buf
= (struct bfa_uf_buf_s
*)
5654 bfa_mem_get_dmabuf_kva(ufm
, uf_tag
, uf
->pb_len
);
5655 buf
= &uf_buf
->d
[0];
5657 m
->frm_len
= be16_to_cpu(m
->frm_len
);
5658 m
->xfr_len
= be16_to_cpu(m
->xfr_len
);
5660 fchs
= (struct fchs_s
*)uf_buf
;
5662 list_del(&uf
->qe
); /* dequeue from posted queue */
5665 uf
->data_len
= m
->xfr_len
;
5667 WARN_ON(uf
->data_len
< sizeof(struct fchs_s
));
5669 if (uf
->data_len
== sizeof(struct fchs_s
)) {
5670 bfa_plog_fchdr(bfa
->plog
, BFA_PL_MID_HAL_UF
, BFA_PL_EID_RX
,
5671 uf
->data_len
, (struct fchs_s
*)buf
);
5673 u32 pld_w0
= *((u32
*) (buf
+ sizeof(struct fchs_s
)));
5674 bfa_plog_fchdr_and_pl(bfa
->plog
, BFA_PL_MID_HAL_UF
,
5675 BFA_PL_EID_RX
, uf
->data_len
,
5676 (struct fchs_s
*)buf
, pld_w0
);
5680 __bfa_cb_uf_recv(uf
, BFA_TRUE
);
5682 bfa_cb_queue(bfa
, &uf
->hcb_qe
, __bfa_cb_uf_recv
, uf
);
5686 bfa_uf_stop(struct bfa_s
*bfa
)
5691 bfa_uf_iocdisable(struct bfa_s
*bfa
)
5693 struct bfa_uf_mod_s
*ufm
= BFA_UF_MOD(bfa
);
5694 struct bfa_uf_s
*uf
;
5695 struct list_head
*qe
, *qen
;
5697 /* Enqueue unused uf resources to free_q */
5698 list_splice_tail_init(&ufm
->uf_unused_q
, &ufm
->uf_free_q
);
5700 list_for_each_safe(qe
, qen
, &ufm
->uf_posted_q
) {
5701 uf
= (struct bfa_uf_s
*) qe
;
5703 bfa_uf_put(ufm
, uf
);
5708 bfa_uf_start(struct bfa_s
*bfa
)
5710 bfa_uf_post_all(BFA_UF_MOD(bfa
));
5714 * Register handler for all unsolicted receive frames.
5716 * @param[in] bfa BFA instance
5717 * @param[in] ufrecv receive handler function
5718 * @param[in] cbarg receive handler arg
5721 bfa_uf_recv_register(struct bfa_s
*bfa
, bfa_cb_uf_recv_t ufrecv
, void *cbarg
)
5723 struct bfa_uf_mod_s
*ufm
= BFA_UF_MOD(bfa
);
5725 ufm
->ufrecv
= ufrecv
;
5730 * Free an unsolicited frame back to BFA.
5732 * @param[in] uf unsolicited frame to be freed
5737 bfa_uf_free(struct bfa_uf_s
*uf
)
5739 bfa_uf_put(BFA_UF_MOD(uf
->bfa
), uf
);
5740 bfa_uf_post_all(BFA_UF_MOD(uf
->bfa
));
5746 * uf_pub BFA uf module public functions
5749 bfa_uf_isr(struct bfa_s
*bfa
, struct bfi_msg_s
*msg
)
5751 bfa_trc(bfa
, msg
->mhdr
.msg_id
);
5753 switch (msg
->mhdr
.msg_id
) {
5754 case BFI_UF_I2H_FRM_RCVD
:
5755 uf_recv(bfa
, (struct bfi_uf_frm_rcvd_s
*) msg
);
5759 bfa_trc(bfa
, msg
->mhdr
.msg_id
);
5765 bfa_uf_res_recfg(struct bfa_s
*bfa
, u16 num_uf_fw
)
5767 struct bfa_uf_mod_s
*mod
= BFA_UF_MOD(bfa
);
5768 struct list_head
*qe
;
5771 for (i
= 0; i
< (mod
->num_ufs
- num_uf_fw
); i
++) {
5772 bfa_q_deq_tail(&mod
->uf_free_q
, &qe
);
5773 list_add_tail(qe
, &mod
->uf_unused_q
);
5778 * Dport forward declaration
5781 enum bfa_dport_test_state_e
{
5782 BFA_DPORT_ST_DISABLED
= 0, /*!< dport is disabled */
5783 BFA_DPORT_ST_INP
= 1, /*!< test in progress */
5784 BFA_DPORT_ST_COMP
= 2, /*!< test complete successfully */
5785 BFA_DPORT_ST_NO_SFP
= 3, /*!< sfp is not present */
5786 BFA_DPORT_ST_NOTSTART
= 4, /*!< test not start dport is enabled */
5790 * BFA DPORT state machine events
5792 enum bfa_dport_sm_event
{
5793 BFA_DPORT_SM_ENABLE
= 1, /* dport enable event */
5794 BFA_DPORT_SM_DISABLE
= 2, /* dport disable event */
5795 BFA_DPORT_SM_FWRSP
= 3, /* fw enable/disable rsp */
5796 BFA_DPORT_SM_QRESUME
= 4, /* CQ space available */
5797 BFA_DPORT_SM_HWFAIL
= 5, /* IOC h/w failure */
5798 BFA_DPORT_SM_START
= 6, /* re-start dport test */
5799 BFA_DPORT_SM_REQFAIL
= 7, /* request failure */
5800 BFA_DPORT_SM_SCN
= 8, /* state change notify frm fw */
5803 static void bfa_dport_sm_disabled(struct bfa_dport_s
*dport
,
5804 enum bfa_dport_sm_event event
);
5805 static void bfa_dport_sm_enabling_qwait(struct bfa_dport_s
*dport
,
5806 enum bfa_dport_sm_event event
);
5807 static void bfa_dport_sm_enabling(struct bfa_dport_s
*dport
,
5808 enum bfa_dport_sm_event event
);
5809 static void bfa_dport_sm_enabled(struct bfa_dport_s
*dport
,
5810 enum bfa_dport_sm_event event
);
5811 static void bfa_dport_sm_disabling_qwait(struct bfa_dport_s
*dport
,
5812 enum bfa_dport_sm_event event
);
5813 static void bfa_dport_sm_disabling(struct bfa_dport_s
*dport
,
5814 enum bfa_dport_sm_event event
);
5815 static void bfa_dport_sm_starting_qwait(struct bfa_dport_s
*dport
,
5816 enum bfa_dport_sm_event event
);
5817 static void bfa_dport_sm_starting(struct bfa_dport_s
*dport
,
5818 enum bfa_dport_sm_event event
);
5819 static void bfa_dport_sm_dynamic_disabling(struct bfa_dport_s
*dport
,
5820 enum bfa_dport_sm_event event
);
5821 static void bfa_dport_sm_dynamic_disabling_qwait(struct bfa_dport_s
*dport
,
5822 enum bfa_dport_sm_event event
);
5823 static void bfa_dport_qresume(void *cbarg
);
5824 static void bfa_dport_req_comp(struct bfa_dport_s
*dport
,
5825 struct bfi_diag_dport_rsp_s
*msg
);
5826 static void bfa_dport_scn(struct bfa_dport_s
*dport
,
5827 struct bfi_diag_dport_scn_s
*msg
);
5832 #define BFA_DIAG_QTEST_TOV 1000 /* msec */
5835 * Set port status to busy
5838 bfa_fcdiag_set_busy_status(struct bfa_fcdiag_s
*fcdiag
)
5840 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(fcdiag
->bfa
);
5842 if (fcdiag
->lb
.lock
)
5843 fcport
->diag_busy
= BFA_TRUE
;
5845 fcport
->diag_busy
= BFA_FALSE
;
5849 bfa_fcdiag_meminfo(struct bfa_iocfc_cfg_s
*cfg
, struct bfa_meminfo_s
*meminfo
,
5855 bfa_fcdiag_attach(struct bfa_s
*bfa
, void *bfad
, struct bfa_iocfc_cfg_s
*cfg
,
5856 struct bfa_pcidev_s
*pcidev
)
5858 struct bfa_fcdiag_s
*fcdiag
= BFA_FCDIAG_MOD(bfa
);
5859 struct bfa_dport_s
*dport
= &fcdiag
->dport
;
5862 fcdiag
->trcmod
= bfa
->trcmod
;
5863 /* The common DIAG attach bfa_diag_attach() will do all memory claim */
5865 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
5866 bfa_reqq_winit(&dport
->reqq_wait
, bfa_dport_qresume
, dport
);
5868 dport
->cbarg
= NULL
;
5869 dport
->test_state
= BFA_DPORT_ST_DISABLED
;
5870 memset(&dport
->result
, 0, sizeof(struct bfa_diag_dport_result_s
));
5874 bfa_fcdiag_iocdisable(struct bfa_s
*bfa
)
5876 struct bfa_fcdiag_s
*fcdiag
= BFA_FCDIAG_MOD(bfa
);
5877 struct bfa_dport_s
*dport
= &fcdiag
->dport
;
5879 bfa_trc(fcdiag
, fcdiag
->lb
.lock
);
5880 if (fcdiag
->lb
.lock
) {
5881 fcdiag
->lb
.status
= BFA_STATUS_IOC_FAILURE
;
5882 fcdiag
->lb
.cbfn(fcdiag
->lb
.cbarg
, fcdiag
->lb
.status
);
5883 fcdiag
->lb
.lock
= 0;
5884 bfa_fcdiag_set_busy_status(fcdiag
);
5887 bfa_sm_send_event(dport
, BFA_DPORT_SM_HWFAIL
);
5891 bfa_fcdiag_detach(struct bfa_s
*bfa
)
5896 bfa_fcdiag_start(struct bfa_s
*bfa
)
5901 bfa_fcdiag_stop(struct bfa_s
*bfa
)
5906 bfa_fcdiag_queuetest_timeout(void *cbarg
)
5908 struct bfa_fcdiag_s
*fcdiag
= cbarg
;
5909 struct bfa_diag_qtest_result_s
*res
= fcdiag
->qtest
.result
;
5911 bfa_trc(fcdiag
, fcdiag
->qtest
.all
);
5912 bfa_trc(fcdiag
, fcdiag
->qtest
.count
);
5914 fcdiag
->qtest
.timer_active
= 0;
5916 res
->status
= BFA_STATUS_ETIMER
;
5917 res
->count
= QTEST_CNT_DEFAULT
- fcdiag
->qtest
.count
;
5918 if (fcdiag
->qtest
.all
)
5919 res
->queue
= fcdiag
->qtest
.all
;
5921 bfa_trc(fcdiag
, BFA_STATUS_ETIMER
);
5922 fcdiag
->qtest
.status
= BFA_STATUS_ETIMER
;
5923 fcdiag
->qtest
.cbfn(fcdiag
->qtest
.cbarg
, fcdiag
->qtest
.status
);
5924 fcdiag
->qtest
.lock
= 0;
5928 bfa_fcdiag_queuetest_send(struct bfa_fcdiag_s
*fcdiag
)
5931 struct bfi_diag_qtest_req_s
*req
;
5933 req
= bfa_reqq_next(fcdiag
->bfa
, fcdiag
->qtest
.queue
);
5935 return BFA_STATUS_DEVBUSY
;
5937 /* build host command */
5938 bfi_h2i_set(req
->mh
, BFI_MC_DIAG
, BFI_DIAG_H2I_QTEST
,
5939 bfa_fn_lpu(fcdiag
->bfa
));
5941 for (i
= 0; i
< BFI_LMSG_PL_WSZ
; i
++)
5942 req
->data
[i
] = QTEST_PAT_DEFAULT
;
5944 bfa_trc(fcdiag
, fcdiag
->qtest
.queue
);
5945 /* ring door bell */
5946 bfa_reqq_produce(fcdiag
->bfa
, fcdiag
->qtest
.queue
, req
->mh
);
5947 return BFA_STATUS_OK
;
5951 bfa_fcdiag_queuetest_comp(struct bfa_fcdiag_s
*fcdiag
,
5952 bfi_diag_qtest_rsp_t
*rsp
)
5954 struct bfa_diag_qtest_result_s
*res
= fcdiag
->qtest
.result
;
5955 bfa_status_t status
= BFA_STATUS_OK
;
5958 /* Check timer, should still be active */
5959 if (!fcdiag
->qtest
.timer_active
) {
5960 bfa_trc(fcdiag
, fcdiag
->qtest
.timer_active
);
5965 fcdiag
->qtest
.count
--;
5968 for (i
= 0; i
< BFI_LMSG_PL_WSZ
; i
++) {
5969 if (rsp
->data
[i
] != ~(QTEST_PAT_DEFAULT
)) {
5970 res
->status
= BFA_STATUS_DATACORRUPTED
;
5975 if (res
->status
== BFA_STATUS_OK
) {
5976 if (fcdiag
->qtest
.count
> 0) {
5977 status
= bfa_fcdiag_queuetest_send(fcdiag
);
5978 if (status
== BFA_STATUS_OK
)
5981 res
->status
= status
;
5982 } else if (fcdiag
->qtest
.all
> 0 &&
5983 fcdiag
->qtest
.queue
< (BFI_IOC_MAX_CQS
- 1)) {
5984 fcdiag
->qtest
.count
= QTEST_CNT_DEFAULT
;
5985 fcdiag
->qtest
.queue
++;
5986 status
= bfa_fcdiag_queuetest_send(fcdiag
);
5987 if (status
== BFA_STATUS_OK
)
5990 res
->status
= status
;
5994 /* Stop timer when we comp all queue */
5995 if (fcdiag
->qtest
.timer_active
) {
5996 bfa_timer_stop(&fcdiag
->qtest
.timer
);
5997 fcdiag
->qtest
.timer_active
= 0;
5999 res
->queue
= fcdiag
->qtest
.queue
;
6000 res
->count
= QTEST_CNT_DEFAULT
- fcdiag
->qtest
.count
;
6001 bfa_trc(fcdiag
, res
->count
);
6002 bfa_trc(fcdiag
, res
->status
);
6003 fcdiag
->qtest
.status
= res
->status
;
6004 fcdiag
->qtest
.cbfn(fcdiag
->qtest
.cbarg
, fcdiag
->qtest
.status
);
6005 fcdiag
->qtest
.lock
= 0;
6009 bfa_fcdiag_loopback_comp(struct bfa_fcdiag_s
*fcdiag
,
6010 struct bfi_diag_lb_rsp_s
*rsp
)
6012 struct bfa_diag_loopback_result_s
*res
= fcdiag
->lb
.result
;
6014 res
->numtxmfrm
= be32_to_cpu(rsp
->res
.numtxmfrm
);
6015 res
->numosffrm
= be32_to_cpu(rsp
->res
.numosffrm
);
6016 res
->numrcvfrm
= be32_to_cpu(rsp
->res
.numrcvfrm
);
6017 res
->badfrminf
= be32_to_cpu(rsp
->res
.badfrminf
);
6018 res
->badfrmnum
= be32_to_cpu(rsp
->res
.badfrmnum
);
6019 res
->status
= rsp
->res
.status
;
6020 fcdiag
->lb
.status
= rsp
->res
.status
;
6021 bfa_trc(fcdiag
, fcdiag
->lb
.status
);
6022 fcdiag
->lb
.cbfn(fcdiag
->lb
.cbarg
, fcdiag
->lb
.status
);
6023 fcdiag
->lb
.lock
= 0;
6024 bfa_fcdiag_set_busy_status(fcdiag
);
6028 bfa_fcdiag_loopback_send(struct bfa_fcdiag_s
*fcdiag
,
6029 struct bfa_diag_loopback_s
*loopback
)
6031 struct bfi_diag_lb_req_s
*lb_req
;
6033 lb_req
= bfa_reqq_next(fcdiag
->bfa
, BFA_REQQ_DIAG
);
6035 return BFA_STATUS_DEVBUSY
;
6037 /* build host command */
6038 bfi_h2i_set(lb_req
->mh
, BFI_MC_DIAG
, BFI_DIAG_H2I_LOOPBACK
,
6039 bfa_fn_lpu(fcdiag
->bfa
));
6041 lb_req
->lb_mode
= loopback
->lb_mode
;
6042 lb_req
->speed
= loopback
->speed
;
6043 lb_req
->loopcnt
= loopback
->loopcnt
;
6044 lb_req
->pattern
= loopback
->pattern
;
6046 /* ring door bell */
6047 bfa_reqq_produce(fcdiag
->bfa
, BFA_REQQ_DIAG
, lb_req
->mh
);
6049 bfa_trc(fcdiag
, loopback
->lb_mode
);
6050 bfa_trc(fcdiag
, loopback
->speed
);
6051 bfa_trc(fcdiag
, loopback
->loopcnt
);
6052 bfa_trc(fcdiag
, loopback
->pattern
);
6053 return BFA_STATUS_OK
;
6057 * cpe/rme intr handler
6060 bfa_fcdiag_intr(struct bfa_s
*bfa
, struct bfi_msg_s
*msg
)
6062 struct bfa_fcdiag_s
*fcdiag
= BFA_FCDIAG_MOD(bfa
);
6064 switch (msg
->mhdr
.msg_id
) {
6065 case BFI_DIAG_I2H_LOOPBACK
:
6066 bfa_fcdiag_loopback_comp(fcdiag
,
6067 (struct bfi_diag_lb_rsp_s
*) msg
);
6069 case BFI_DIAG_I2H_QTEST
:
6070 bfa_fcdiag_queuetest_comp(fcdiag
, (bfi_diag_qtest_rsp_t
*)msg
);
6072 case BFI_DIAG_I2H_DPORT
:
6073 bfa_dport_req_comp(&fcdiag
->dport
,
6074 (struct bfi_diag_dport_rsp_s
*)msg
);
6076 case BFI_DIAG_I2H_DPORT_SCN
:
6077 bfa_dport_scn(&fcdiag
->dport
,
6078 (struct bfi_diag_dport_scn_s
*)msg
);
6081 bfa_trc(fcdiag
, msg
->mhdr
.msg_id
);
6089 * @param[in] *bfa - bfa data struct
6090 * @param[in] opmode - port operation mode
6091 * @param[in] speed - port speed
6092 * @param[in] lpcnt - loop count
6093 * @param[in] pat - pattern to build packet
6094 * @param[in] *result - pt to bfa_diag_loopback_result_t data struct
6095 * @param[in] cbfn - callback function
6096 * @param[in] cbarg - callback functioin arg
6101 bfa_fcdiag_loopback(struct bfa_s
*bfa
, enum bfa_port_opmode opmode
,
6102 enum bfa_port_speed speed
, u32 lpcnt
, u32 pat
,
6103 struct bfa_diag_loopback_result_s
*result
, bfa_cb_diag_t cbfn
,
6106 struct bfa_diag_loopback_s loopback
;
6107 struct bfa_port_attr_s attr
;
6108 bfa_status_t status
;
6109 struct bfa_fcdiag_s
*fcdiag
= BFA_FCDIAG_MOD(bfa
);
6111 if (!bfa_iocfc_is_operational(bfa
))
6112 return BFA_STATUS_IOC_NON_OP
;
6114 /* if port is PBC disabled, return error */
6115 if (bfa_fcport_is_pbcdisabled(bfa
)) {
6116 bfa_trc(fcdiag
, BFA_STATUS_PBC
);
6117 return BFA_STATUS_PBC
;
6120 if (bfa_fcport_is_disabled(bfa
) == BFA_FALSE
) {
6121 bfa_trc(fcdiag
, opmode
);
6122 return BFA_STATUS_PORT_NOT_DISABLED
;
6126 * Check if input speed is supported by the port mode
6128 if (bfa_ioc_get_type(&bfa
->ioc
) == BFA_IOC_TYPE_FC
) {
6129 if (!(speed
== BFA_PORT_SPEED_1GBPS
||
6130 speed
== BFA_PORT_SPEED_2GBPS
||
6131 speed
== BFA_PORT_SPEED_4GBPS
||
6132 speed
== BFA_PORT_SPEED_8GBPS
||
6133 speed
== BFA_PORT_SPEED_16GBPS
||
6134 speed
== BFA_PORT_SPEED_AUTO
)) {
6135 bfa_trc(fcdiag
, speed
);
6136 return BFA_STATUS_UNSUPP_SPEED
;
6138 bfa_fcport_get_attr(bfa
, &attr
);
6139 bfa_trc(fcdiag
, attr
.speed_supported
);
6140 if (speed
> attr
.speed_supported
)
6141 return BFA_STATUS_UNSUPP_SPEED
;
6143 if (speed
!= BFA_PORT_SPEED_10GBPS
) {
6144 bfa_trc(fcdiag
, speed
);
6145 return BFA_STATUS_UNSUPP_SPEED
;
6150 * For CT2, 1G is not supported
6152 if ((speed
== BFA_PORT_SPEED_1GBPS
) &&
6153 (bfa_asic_id_ct2(bfa
->ioc
.pcidev
.device_id
))) {
6154 bfa_trc(fcdiag
, speed
);
6155 return BFA_STATUS_UNSUPP_SPEED
;
6158 /* For Mezz card, port speed entered needs to be checked */
6159 if (bfa_mfg_is_mezz(bfa
->ioc
.attr
->card_type
)) {
6160 if (bfa_ioc_get_type(&bfa
->ioc
) == BFA_IOC_TYPE_FC
) {
6161 if (!(speed
== BFA_PORT_SPEED_1GBPS
||
6162 speed
== BFA_PORT_SPEED_2GBPS
||
6163 speed
== BFA_PORT_SPEED_4GBPS
||
6164 speed
== BFA_PORT_SPEED_8GBPS
||
6165 speed
== BFA_PORT_SPEED_16GBPS
||
6166 speed
== BFA_PORT_SPEED_AUTO
))
6167 return BFA_STATUS_UNSUPP_SPEED
;
6169 if (speed
!= BFA_PORT_SPEED_10GBPS
)
6170 return BFA_STATUS_UNSUPP_SPEED
;
6173 /* check to see if fcport is dport */
6174 if (bfa_fcport_is_dport(bfa
)) {
6175 bfa_trc(fcdiag
, fcdiag
->lb
.lock
);
6176 return BFA_STATUS_DPORT_ENABLED
;
6178 /* check to see if there is another destructive diag cmd running */
6179 if (fcdiag
->lb
.lock
) {
6180 bfa_trc(fcdiag
, fcdiag
->lb
.lock
);
6181 return BFA_STATUS_DEVBUSY
;
6184 fcdiag
->lb
.lock
= 1;
6185 loopback
.lb_mode
= opmode
;
6186 loopback
.speed
= speed
;
6187 loopback
.loopcnt
= lpcnt
;
6188 loopback
.pattern
= pat
;
6189 fcdiag
->lb
.result
= result
;
6190 fcdiag
->lb
.cbfn
= cbfn
;
6191 fcdiag
->lb
.cbarg
= cbarg
;
6192 memset(result
, 0, sizeof(struct bfa_diag_loopback_result_s
));
6193 bfa_fcdiag_set_busy_status(fcdiag
);
6195 /* Send msg to fw */
6196 status
= bfa_fcdiag_loopback_send(fcdiag
, &loopback
);
6201 * DIAG queue test command
6203 * @param[in] *bfa - bfa data struct
6204 * @param[in] force - 1: don't do ioc op checking
6205 * @param[in] queue - queue no. to test
6206 * @param[in] *result - pt to bfa_diag_qtest_result_t data struct
6207 * @param[in] cbfn - callback function
6208 * @param[in] *cbarg - callback functioin arg
6213 bfa_fcdiag_queuetest(struct bfa_s
*bfa
, u32 force
, u32 queue
,
6214 struct bfa_diag_qtest_result_s
*result
, bfa_cb_diag_t cbfn
,
6217 struct bfa_fcdiag_s
*fcdiag
= BFA_FCDIAG_MOD(bfa
);
6218 bfa_status_t status
;
6219 bfa_trc(fcdiag
, force
);
6220 bfa_trc(fcdiag
, queue
);
6222 if (!force
&& !bfa_iocfc_is_operational(bfa
))
6223 return BFA_STATUS_IOC_NON_OP
;
6225 /* check to see if there is another destructive diag cmd running */
6226 if (fcdiag
->qtest
.lock
) {
6227 bfa_trc(fcdiag
, fcdiag
->qtest
.lock
);
6228 return BFA_STATUS_DEVBUSY
;
6231 /* Initialization */
6232 fcdiag
->qtest
.lock
= 1;
6233 fcdiag
->qtest
.cbfn
= cbfn
;
6234 fcdiag
->qtest
.cbarg
= cbarg
;
6235 fcdiag
->qtest
.result
= result
;
6236 fcdiag
->qtest
.count
= QTEST_CNT_DEFAULT
;
6238 /* Init test results */
6239 fcdiag
->qtest
.result
->status
= BFA_STATUS_OK
;
6240 fcdiag
->qtest
.result
->count
= 0;
6243 if (queue
< BFI_IOC_MAX_CQS
) {
6244 fcdiag
->qtest
.result
->queue
= (u8
)queue
;
6245 fcdiag
->qtest
.queue
= (u8
)queue
;
6246 fcdiag
->qtest
.all
= 0;
6248 fcdiag
->qtest
.result
->queue
= 0;
6249 fcdiag
->qtest
.queue
= 0;
6250 fcdiag
->qtest
.all
= 1;
6252 status
= bfa_fcdiag_queuetest_send(fcdiag
);
6255 if (status
== BFA_STATUS_OK
) {
6256 bfa_timer_start(bfa
, &fcdiag
->qtest
.timer
,
6257 bfa_fcdiag_queuetest_timeout
, fcdiag
,
6258 BFA_DIAG_QTEST_TOV
);
6259 fcdiag
->qtest
.timer_active
= 1;
6265 * DIAG PLB is running
6267 * @param[in] *bfa - bfa data struct
6272 bfa_fcdiag_lb_is_running(struct bfa_s
*bfa
)
6274 struct bfa_fcdiag_s
*fcdiag
= BFA_FCDIAG_MOD(bfa
);
6275 return fcdiag
->lb
.lock
? BFA_STATUS_DIAG_BUSY
: BFA_STATUS_OK
;
6281 #define bfa_dport_result_start(__dport, __mode) do { \
6282 (__dport)->result.start_time = bfa_get_log_time(); \
6283 (__dport)->result.status = DPORT_TEST_ST_INPRG; \
6284 (__dport)->result.mode = (__mode); \
6285 (__dport)->result.rp_pwwn = (__dport)->rp_pwwn; \
6286 (__dport)->result.rp_nwwn = (__dport)->rp_nwwn; \
6287 (__dport)->result.lpcnt = (__dport)->lpcnt; \
6290 static bfa_boolean_t
bfa_dport_send_req(struct bfa_dport_s
*dport
,
6291 enum bfi_dport_req req
);
6293 bfa_cb_fcdiag_dport(struct bfa_dport_s
*dport
, bfa_status_t bfa_status
)
6295 if (dport
->cbfn
!= NULL
) {
6296 dport
->cbfn(dport
->cbarg
, bfa_status
);
6298 dport
->cbarg
= NULL
;
6303 bfa_dport_sm_disabled(struct bfa_dport_s
*dport
, enum bfa_dport_sm_event event
)
6305 bfa_trc(dport
->bfa
, event
);
6308 case BFA_DPORT_SM_ENABLE
:
6309 bfa_fcport_dportenable(dport
->bfa
);
6310 if (bfa_dport_send_req(dport
, BFI_DPORT_ENABLE
))
6311 bfa_sm_set_state(dport
, bfa_dport_sm_enabling
);
6313 bfa_sm_set_state(dport
, bfa_dport_sm_enabling_qwait
);
6316 case BFA_DPORT_SM_DISABLE
:
6317 /* Already disabled */
6320 case BFA_DPORT_SM_HWFAIL
:
6324 case BFA_DPORT_SM_SCN
:
6325 if (dport
->i2hmsg
.scn
.state
== BFI_DPORT_SCN_DDPORT_ENABLE
) {
6326 bfa_fcport_ddportenable(dport
->bfa
);
6327 dport
->dynamic
= BFA_TRUE
;
6328 dport
->test_state
= BFA_DPORT_ST_NOTSTART
;
6329 bfa_sm_set_state(dport
, bfa_dport_sm_enabled
);
6331 bfa_trc(dport
->bfa
, dport
->i2hmsg
.scn
.state
);
6337 bfa_sm_fault(dport
->bfa
, event
);
6342 bfa_dport_sm_enabling_qwait(struct bfa_dport_s
*dport
,
6343 enum bfa_dport_sm_event event
)
6345 bfa_trc(dport
->bfa
, event
);
6348 case BFA_DPORT_SM_QRESUME
:
6349 bfa_sm_set_state(dport
, bfa_dport_sm_enabling
);
6350 bfa_dport_send_req(dport
, BFI_DPORT_ENABLE
);
6353 case BFA_DPORT_SM_HWFAIL
:
6354 bfa_reqq_wcancel(&dport
->reqq_wait
);
6355 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
6356 bfa_cb_fcdiag_dport(dport
, BFA_STATUS_FAILED
);
6360 bfa_sm_fault(dport
->bfa
, event
);
6365 bfa_dport_sm_enabling(struct bfa_dport_s
*dport
, enum bfa_dport_sm_event event
)
6367 bfa_trc(dport
->bfa
, event
);
6370 case BFA_DPORT_SM_FWRSP
:
6371 memset(&dport
->result
, 0,
6372 sizeof(struct bfa_diag_dport_result_s
));
6373 if (dport
->i2hmsg
.rsp
.status
== BFA_STATUS_DPORT_INV_SFP
) {
6374 dport
->test_state
= BFA_DPORT_ST_NO_SFP
;
6376 dport
->test_state
= BFA_DPORT_ST_INP
;
6377 bfa_dport_result_start(dport
, BFA_DPORT_OPMODE_AUTO
);
6379 bfa_sm_set_state(dport
, bfa_dport_sm_enabled
);
6382 case BFA_DPORT_SM_REQFAIL
:
6383 dport
->test_state
= BFA_DPORT_ST_DISABLED
;
6384 bfa_fcport_dportdisable(dport
->bfa
);
6385 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
6388 case BFA_DPORT_SM_HWFAIL
:
6389 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
6390 bfa_cb_fcdiag_dport(dport
, BFA_STATUS_FAILED
);
6394 bfa_sm_fault(dport
->bfa
, event
);
6399 bfa_dport_sm_enabled(struct bfa_dport_s
*dport
, enum bfa_dport_sm_event event
)
6401 bfa_trc(dport
->bfa
, event
);
6404 case BFA_DPORT_SM_START
:
6405 if (bfa_dport_send_req(dport
, BFI_DPORT_START
))
6406 bfa_sm_set_state(dport
, bfa_dport_sm_starting
);
6408 bfa_sm_set_state(dport
, bfa_dport_sm_starting_qwait
);
6411 case BFA_DPORT_SM_DISABLE
:
6412 bfa_fcport_dportdisable(dport
->bfa
);
6413 if (bfa_dport_send_req(dport
, BFI_DPORT_DISABLE
))
6414 bfa_sm_set_state(dport
, bfa_dport_sm_disabling
);
6416 bfa_sm_set_state(dport
, bfa_dport_sm_disabling_qwait
);
6419 case BFA_DPORT_SM_HWFAIL
:
6420 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
6423 case BFA_DPORT_SM_SCN
:
6424 switch (dport
->i2hmsg
.scn
.state
) {
6425 case BFI_DPORT_SCN_TESTCOMP
:
6426 dport
->test_state
= BFA_DPORT_ST_COMP
;
6429 case BFI_DPORT_SCN_TESTSTART
:
6430 dport
->test_state
= BFA_DPORT_ST_INP
;
6433 case BFI_DPORT_SCN_TESTSKIP
:
6434 case BFI_DPORT_SCN_SUBTESTSTART
:
6435 /* no state change */
6438 case BFI_DPORT_SCN_SFP_REMOVED
:
6439 dport
->test_state
= BFA_DPORT_ST_NO_SFP
;
6442 case BFI_DPORT_SCN_DDPORT_DISABLE
:
6443 bfa_fcport_ddportdisable(dport
->bfa
);
6445 if (bfa_dport_send_req(dport
, BFI_DPORT_DYN_DISABLE
))
6446 bfa_sm_set_state(dport
,
6447 bfa_dport_sm_dynamic_disabling
);
6449 bfa_sm_set_state(dport
,
6450 bfa_dport_sm_dynamic_disabling_qwait
);
6453 case BFI_DPORT_SCN_FCPORT_DISABLE
:
6454 bfa_fcport_ddportdisable(dport
->bfa
);
6456 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
6457 dport
->dynamic
= BFA_FALSE
;
6461 bfa_trc(dport
->bfa
, dport
->i2hmsg
.scn
.state
);
6462 bfa_sm_fault(dport
->bfa
, event
);
6466 bfa_sm_fault(dport
->bfa
, event
);
6471 bfa_dport_sm_disabling_qwait(struct bfa_dport_s
*dport
,
6472 enum bfa_dport_sm_event event
)
6474 bfa_trc(dport
->bfa
, event
);
6477 case BFA_DPORT_SM_QRESUME
:
6478 bfa_sm_set_state(dport
, bfa_dport_sm_disabling
);
6479 bfa_dport_send_req(dport
, BFI_DPORT_DISABLE
);
6482 case BFA_DPORT_SM_HWFAIL
:
6483 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
6484 bfa_reqq_wcancel(&dport
->reqq_wait
);
6485 bfa_cb_fcdiag_dport(dport
, BFA_STATUS_OK
);
6488 case BFA_DPORT_SM_SCN
:
6493 bfa_sm_fault(dport
->bfa
, event
);
6498 bfa_dport_sm_disabling(struct bfa_dport_s
*dport
, enum bfa_dport_sm_event event
)
6500 bfa_trc(dport
->bfa
, event
);
6503 case BFA_DPORT_SM_FWRSP
:
6504 dport
->test_state
= BFA_DPORT_ST_DISABLED
;
6505 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
6508 case BFA_DPORT_SM_HWFAIL
:
6509 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
6510 bfa_cb_fcdiag_dport(dport
, BFA_STATUS_OK
);
6513 case BFA_DPORT_SM_SCN
:
6514 /* no state change */
6518 bfa_sm_fault(dport
->bfa
, event
);
6523 bfa_dport_sm_starting_qwait(struct bfa_dport_s
*dport
,
6524 enum bfa_dport_sm_event event
)
6526 bfa_trc(dport
->bfa
, event
);
6529 case BFA_DPORT_SM_QRESUME
:
6530 bfa_sm_set_state(dport
, bfa_dport_sm_starting
);
6531 bfa_dport_send_req(dport
, BFI_DPORT_START
);
6534 case BFA_DPORT_SM_HWFAIL
:
6535 bfa_reqq_wcancel(&dport
->reqq_wait
);
6536 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
6537 bfa_cb_fcdiag_dport(dport
, BFA_STATUS_FAILED
);
6541 bfa_sm_fault(dport
->bfa
, event
);
6546 bfa_dport_sm_starting(struct bfa_dport_s
*dport
, enum bfa_dport_sm_event event
)
6548 bfa_trc(dport
->bfa
, event
);
6551 case BFA_DPORT_SM_FWRSP
:
6552 memset(&dport
->result
, 0,
6553 sizeof(struct bfa_diag_dport_result_s
));
6554 if (dport
->i2hmsg
.rsp
.status
== BFA_STATUS_DPORT_INV_SFP
) {
6555 dport
->test_state
= BFA_DPORT_ST_NO_SFP
;
6557 dport
->test_state
= BFA_DPORT_ST_INP
;
6558 bfa_dport_result_start(dport
, BFA_DPORT_OPMODE_MANU
);
6562 case BFA_DPORT_SM_REQFAIL
:
6563 bfa_sm_set_state(dport
, bfa_dport_sm_enabled
);
6566 case BFA_DPORT_SM_HWFAIL
:
6567 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
6568 bfa_cb_fcdiag_dport(dport
, BFA_STATUS_FAILED
);
6572 bfa_sm_fault(dport
->bfa
, event
);
6577 bfa_dport_sm_dynamic_disabling(struct bfa_dport_s
*dport
,
6578 enum bfa_dport_sm_event event
)
6580 bfa_trc(dport
->bfa
, event
);
6583 case BFA_DPORT_SM_SCN
:
6584 switch (dport
->i2hmsg
.scn
.state
) {
6585 case BFI_DPORT_SCN_DDPORT_DISABLED
:
6586 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
6587 dport
->dynamic
= BFA_FALSE
;
6588 bfa_fcport_enable(dport
->bfa
);
6592 bfa_trc(dport
->bfa
, dport
->i2hmsg
.scn
.state
);
6593 bfa_sm_fault(dport
->bfa
, event
);
6598 case BFA_DPORT_SM_HWFAIL
:
6599 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
6600 bfa_cb_fcdiag_dport(dport
, BFA_STATUS_OK
);
6604 bfa_sm_fault(dport
->bfa
, event
);
6609 bfa_dport_sm_dynamic_disabling_qwait(struct bfa_dport_s
*dport
,
6610 enum bfa_dport_sm_event event
)
6612 bfa_trc(dport
->bfa
, event
);
6615 case BFA_DPORT_SM_QRESUME
:
6616 bfa_sm_set_state(dport
, bfa_dport_sm_dynamic_disabling
);
6617 bfa_dport_send_req(dport
, BFI_DPORT_DYN_DISABLE
);
6620 case BFA_DPORT_SM_HWFAIL
:
6621 bfa_sm_set_state(dport
, bfa_dport_sm_disabled
);
6622 bfa_reqq_wcancel(&dport
->reqq_wait
);
6623 bfa_cb_fcdiag_dport(dport
, BFA_STATUS_OK
);
6626 case BFA_DPORT_SM_SCN
:
6631 bfa_sm_fault(dport
->bfa
, event
);
6635 static bfa_boolean_t
6636 bfa_dport_send_req(struct bfa_dport_s
*dport
, enum bfi_dport_req req
)
6638 struct bfi_diag_dport_req_s
*m
;
6641 * check for room in queue to send request now
6643 m
= bfa_reqq_next(dport
->bfa
, BFA_REQQ_DIAG
);
6645 bfa_reqq_wait(dport
->bfa
, BFA_REQQ_PORT
, &dport
->reqq_wait
);
6649 bfi_h2i_set(m
->mh
, BFI_MC_DIAG
, BFI_DIAG_H2I_DPORT
,
6650 bfa_fn_lpu(dport
->bfa
));
6652 if ((req
== BFI_DPORT_ENABLE
) || (req
== BFI_DPORT_START
)) {
6653 m
->lpcnt
= cpu_to_be32(dport
->lpcnt
);
6654 m
->payload
= cpu_to_be32(dport
->payload
);
6658 * queue I/O message to firmware
6660 bfa_reqq_produce(dport
->bfa
, BFA_REQQ_DIAG
, m
->mh
);
6666 bfa_dport_qresume(void *cbarg
)
6668 struct bfa_dport_s
*dport
= cbarg
;
6670 bfa_sm_send_event(dport
, BFA_DPORT_SM_QRESUME
);
6674 bfa_dport_req_comp(struct bfa_dport_s
*dport
, struct bfi_diag_dport_rsp_s
*msg
)
6676 msg
->status
= cpu_to_be32(msg
->status
);
6677 dport
->i2hmsg
.rsp
.status
= msg
->status
;
6678 dport
->rp_pwwn
= msg
->pwwn
;
6679 dport
->rp_nwwn
= msg
->nwwn
;
6681 if ((msg
->status
== BFA_STATUS_OK
) ||
6682 (msg
->status
== BFA_STATUS_DPORT_NO_SFP
)) {
6683 bfa_trc(dport
->bfa
, msg
->status
);
6684 bfa_trc(dport
->bfa
, dport
->rp_pwwn
);
6685 bfa_trc(dport
->bfa
, dport
->rp_nwwn
);
6686 bfa_sm_send_event(dport
, BFA_DPORT_SM_FWRSP
);
6689 bfa_trc(dport
->bfa
, msg
->status
);
6690 bfa_sm_send_event(dport
, BFA_DPORT_SM_REQFAIL
);
6692 bfa_cb_fcdiag_dport(dport
, msg
->status
);
6695 static bfa_boolean_t
6696 bfa_dport_is_sending_req(struct bfa_dport_s
*dport
)
6698 if (bfa_sm_cmp_state(dport
, bfa_dport_sm_enabling
) ||
6699 bfa_sm_cmp_state(dport
, bfa_dport_sm_enabling_qwait
) ||
6700 bfa_sm_cmp_state(dport
, bfa_dport_sm_disabling
) ||
6701 bfa_sm_cmp_state(dport
, bfa_dport_sm_disabling_qwait
) ||
6702 bfa_sm_cmp_state(dport
, bfa_dport_sm_starting
) ||
6703 bfa_sm_cmp_state(dport
, bfa_dport_sm_starting_qwait
)) {
6711 bfa_dport_scn(struct bfa_dport_s
*dport
, struct bfi_diag_dport_scn_s
*msg
)
6714 uint8_t subtesttype
;
6716 bfa_trc(dport
->bfa
, msg
->state
);
6717 dport
->i2hmsg
.scn
.state
= msg
->state
;
6719 switch (dport
->i2hmsg
.scn
.state
) {
6720 case BFI_DPORT_SCN_TESTCOMP
:
6721 dport
->result
.end_time
= bfa_get_log_time();
6722 bfa_trc(dport
->bfa
, dport
->result
.end_time
);
6724 dport
->result
.status
= msg
->info
.testcomp
.status
;
6725 bfa_trc(dport
->bfa
, dport
->result
.status
);
6727 dport
->result
.roundtrip_latency
=
6728 cpu_to_be32(msg
->info
.testcomp
.latency
);
6729 dport
->result
.est_cable_distance
=
6730 cpu_to_be32(msg
->info
.testcomp
.distance
);
6731 dport
->result
.buffer_required
=
6732 be16_to_cpu(msg
->info
.testcomp
.numbuffer
);
6734 dport
->result
.frmsz
= be16_to_cpu(msg
->info
.testcomp
.frm_sz
);
6735 dport
->result
.speed
= msg
->info
.testcomp
.speed
;
6737 bfa_trc(dport
->bfa
, dport
->result
.roundtrip_latency
);
6738 bfa_trc(dport
->bfa
, dport
->result
.est_cable_distance
);
6739 bfa_trc(dport
->bfa
, dport
->result
.buffer_required
);
6740 bfa_trc(dport
->bfa
, dport
->result
.frmsz
);
6741 bfa_trc(dport
->bfa
, dport
->result
.speed
);
6743 for (i
= DPORT_TEST_ELOOP
; i
< DPORT_TEST_MAX
; i
++) {
6744 dport
->result
.subtest
[i
].status
=
6745 msg
->info
.testcomp
.subtest_status
[i
];
6746 bfa_trc(dport
->bfa
, dport
->result
.subtest
[i
].status
);
6750 case BFI_DPORT_SCN_TESTSKIP
:
6751 case BFI_DPORT_SCN_DDPORT_ENABLE
:
6752 memset(&dport
->result
, 0,
6753 sizeof(struct bfa_diag_dport_result_s
));
6756 case BFI_DPORT_SCN_TESTSTART
:
6757 memset(&dport
->result
, 0,
6758 sizeof(struct bfa_diag_dport_result_s
));
6759 dport
->rp_pwwn
= msg
->info
.teststart
.pwwn
;
6760 dport
->rp_nwwn
= msg
->info
.teststart
.nwwn
;
6761 dport
->lpcnt
= cpu_to_be32(msg
->info
.teststart
.numfrm
);
6762 bfa_dport_result_start(dport
, msg
->info
.teststart
.mode
);
6765 case BFI_DPORT_SCN_SUBTESTSTART
:
6766 subtesttype
= msg
->info
.teststart
.type
;
6767 dport
->result
.subtest
[subtesttype
].start_time
=
6769 dport
->result
.subtest
[subtesttype
].status
=
6770 DPORT_TEST_ST_INPRG
;
6772 bfa_trc(dport
->bfa
, subtesttype
);
6774 dport
->result
.subtest
[subtesttype
].start_time
);
6777 case BFI_DPORT_SCN_SFP_REMOVED
:
6778 case BFI_DPORT_SCN_DDPORT_DISABLED
:
6779 case BFI_DPORT_SCN_DDPORT_DISABLE
:
6780 case BFI_DPORT_SCN_FCPORT_DISABLE
:
6781 dport
->result
.status
= DPORT_TEST_ST_IDLE
;
6785 bfa_sm_fault(dport
->bfa
, msg
->state
);
6788 bfa_sm_send_event(dport
, BFA_DPORT_SM_SCN
);
6794 * @param[in] *bfa - bfa data struct
6797 bfa_dport_enable(struct bfa_s
*bfa
, u32 lpcnt
, u32 pat
,
6798 bfa_cb_diag_t cbfn
, void *cbarg
)
6800 struct bfa_fcdiag_s
*fcdiag
= BFA_FCDIAG_MOD(bfa
);
6801 struct bfa_dport_s
*dport
= &fcdiag
->dport
;
6804 * Dport is not support in MEZZ card
6806 if (bfa_mfg_is_mezz(dport
->bfa
->ioc
.attr
->card_type
)) {
6807 bfa_trc(dport
->bfa
, BFA_STATUS_PBC
);
6808 return BFA_STATUS_CMD_NOTSUPP_MEZZ
;
6812 * Dport is supported in CT2 or above
6814 if (!(bfa_asic_id_ct2(dport
->bfa
->ioc
.pcidev
.device_id
))) {
6815 bfa_trc(dport
->bfa
, dport
->bfa
->ioc
.pcidev
.device_id
);
6816 return BFA_STATUS_FEATURE_NOT_SUPPORTED
;
6820 * Check to see if IOC is down
6822 if (!bfa_iocfc_is_operational(bfa
))
6823 return BFA_STATUS_IOC_NON_OP
;
6825 /* if port is PBC disabled, return error */
6826 if (bfa_fcport_is_pbcdisabled(bfa
)) {
6827 bfa_trc(dport
->bfa
, BFA_STATUS_PBC
);
6828 return BFA_STATUS_PBC
;
6832 * Check if port mode is FC port
6834 if (bfa_ioc_get_type(&bfa
->ioc
) != BFA_IOC_TYPE_FC
) {
6835 bfa_trc(dport
->bfa
, bfa_ioc_get_type(&bfa
->ioc
));
6836 return BFA_STATUS_CMD_NOTSUPP_CNA
;
6840 * Check if port is in LOOP mode
6842 if ((bfa_fcport_get_cfg_topology(bfa
) == BFA_PORT_TOPOLOGY_LOOP
) ||
6843 (bfa_fcport_get_topology(bfa
) == BFA_PORT_TOPOLOGY_LOOP
)) {
6844 bfa_trc(dport
->bfa
, 0);
6845 return BFA_STATUS_TOPOLOGY_LOOP
;
6849 * Check if port is TRUNK mode
6851 if (bfa_fcport_is_trunk_enabled(bfa
)) {
6852 bfa_trc(dport
->bfa
, 0);
6853 return BFA_STATUS_ERROR_TRUNK_ENABLED
;
6857 * Check if diag loopback is running
6859 if (bfa_fcdiag_lb_is_running(bfa
)) {
6860 bfa_trc(dport
->bfa
, 0);
6861 return BFA_STATUS_DIAG_BUSY
;
6865 * Check to see if port is disable or in dport state
6867 if ((bfa_fcport_is_disabled(bfa
) == BFA_FALSE
) &&
6868 (bfa_fcport_is_dport(bfa
) == BFA_FALSE
)) {
6869 bfa_trc(dport
->bfa
, 0);
6870 return BFA_STATUS_PORT_NOT_DISABLED
;
6874 * Check if dport is in dynamic mode
6877 return BFA_STATUS_DDPORT_ERR
;
6880 * Check if dport is busy
6882 if (bfa_dport_is_sending_req(dport
))
6883 return BFA_STATUS_DEVBUSY
;
6886 * Check if dport is already enabled
6888 if (bfa_sm_cmp_state(dport
, bfa_dport_sm_enabled
)) {
6889 bfa_trc(dport
->bfa
, 0);
6890 return BFA_STATUS_DPORT_ENABLED
;
6893 bfa_trc(dport
->bfa
, lpcnt
);
6894 bfa_trc(dport
->bfa
, pat
);
6895 dport
->lpcnt
= (lpcnt
) ? lpcnt
: DPORT_ENABLE_LOOPCNT_DEFAULT
;
6896 dport
->payload
= (pat
) ? pat
: LB_PATTERN_DEFAULT
;
6898 dport
->cbarg
= cbarg
;
6900 bfa_sm_send_event(dport
, BFA_DPORT_SM_ENABLE
);
6901 return BFA_STATUS_OK
;
6907 * @param[in] *bfa - bfa data struct
6910 bfa_dport_disable(struct bfa_s
*bfa
, bfa_cb_diag_t cbfn
, void *cbarg
)
6912 struct bfa_fcdiag_s
*fcdiag
= BFA_FCDIAG_MOD(bfa
);
6913 struct bfa_dport_s
*dport
= &fcdiag
->dport
;
6915 if (bfa_ioc_is_disabled(&bfa
->ioc
))
6916 return BFA_STATUS_IOC_DISABLED
;
6918 /* if port is PBC disabled, return error */
6919 if (bfa_fcport_is_pbcdisabled(bfa
)) {
6920 bfa_trc(dport
->bfa
, BFA_STATUS_PBC
);
6921 return BFA_STATUS_PBC
;
6925 * Check if dport is in dynamic mode
6927 if (dport
->dynamic
) {
6928 return BFA_STATUS_DDPORT_ERR
;
6932 * Check to see if port is disable or in dport state
6934 if ((bfa_fcport_is_disabled(bfa
) == BFA_FALSE
) &&
6935 (bfa_fcport_is_dport(bfa
) == BFA_FALSE
)) {
6936 bfa_trc(dport
->bfa
, 0);
6937 return BFA_STATUS_PORT_NOT_DISABLED
;
6941 * Check if dport is busy
6943 if (bfa_dport_is_sending_req(dport
))
6944 return BFA_STATUS_DEVBUSY
;
6947 * Check if dport is already disabled
6949 if (bfa_sm_cmp_state(dport
, bfa_dport_sm_disabled
)) {
6950 bfa_trc(dport
->bfa
, 0);
6951 return BFA_STATUS_DPORT_DISABLED
;
6955 dport
->cbarg
= cbarg
;
6957 bfa_sm_send_event(dport
, BFA_DPORT_SM_DISABLE
);
6958 return BFA_STATUS_OK
;
6962 * Dport start -- restart dport test
6964 * @param[in] *bfa - bfa data struct
6967 bfa_dport_start(struct bfa_s
*bfa
, u32 lpcnt
, u32 pat
,
6968 bfa_cb_diag_t cbfn
, void *cbarg
)
6970 struct bfa_fcdiag_s
*fcdiag
= BFA_FCDIAG_MOD(bfa
);
6971 struct bfa_dport_s
*dport
= &fcdiag
->dport
;
6974 * Check to see if IOC is down
6976 if (!bfa_iocfc_is_operational(bfa
))
6977 return BFA_STATUS_IOC_NON_OP
;
6980 * Check if dport is in dynamic mode
6983 return BFA_STATUS_DDPORT_ERR
;
6986 * Check if dport is busy
6988 if (bfa_dport_is_sending_req(dport
))
6989 return BFA_STATUS_DEVBUSY
;
6992 * Check if dport is in enabled state.
6993 * Test can only be restart when previous test has completed
6995 if (!bfa_sm_cmp_state(dport
, bfa_dport_sm_enabled
)) {
6996 bfa_trc(dport
->bfa
, 0);
6997 return BFA_STATUS_DPORT_DISABLED
;
7000 if (dport
->test_state
== BFA_DPORT_ST_NO_SFP
)
7001 return BFA_STATUS_DPORT_INV_SFP
;
7003 if (dport
->test_state
== BFA_DPORT_ST_INP
)
7004 return BFA_STATUS_DEVBUSY
;
7006 WARN_ON(dport
->test_state
!= BFA_DPORT_ST_COMP
);
7009 bfa_trc(dport
->bfa
, lpcnt
);
7010 bfa_trc(dport
->bfa
, pat
);
7012 dport
->lpcnt
= (lpcnt
) ? lpcnt
: DPORT_ENABLE_LOOPCNT_DEFAULT
;
7013 dport
->payload
= (pat
) ? pat
: LB_PATTERN_DEFAULT
;
7016 dport
->cbarg
= cbarg
;
7018 bfa_sm_send_event(dport
, BFA_DPORT_SM_START
);
7019 return BFA_STATUS_OK
;
7023 * Dport show -- return dport test result
7025 * @param[in] *bfa - bfa data struct
7028 bfa_dport_show(struct bfa_s
*bfa
, struct bfa_diag_dport_result_s
*result
)
7030 struct bfa_fcdiag_s
*fcdiag
= BFA_FCDIAG_MOD(bfa
);
7031 struct bfa_dport_s
*dport
= &fcdiag
->dport
;
7034 * Check to see if IOC is down
7036 if (!bfa_iocfc_is_operational(bfa
))
7037 return BFA_STATUS_IOC_NON_OP
;
7040 * Check if dport is busy
7042 if (bfa_dport_is_sending_req(dport
))
7043 return BFA_STATUS_DEVBUSY
;
7046 * Check if dport is in enabled state.
7048 if (!bfa_sm_cmp_state(dport
, bfa_dport_sm_enabled
)) {
7049 bfa_trc(dport
->bfa
, 0);
7050 return BFA_STATUS_DPORT_DISABLED
;
7055 * Check if there is SFP
7057 if (dport
->test_state
== BFA_DPORT_ST_NO_SFP
)
7058 return BFA_STATUS_DPORT_INV_SFP
;
7060 memcpy(result
, &dport
->result
, sizeof(struct bfa_diag_dport_result_s
));
7062 return BFA_STATUS_OK
;