2 * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License (GPL) Version 2 as
10 * published by the Free Software Foundation
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
18 #include <bfa_os_inc.h>
19 #include <cs/bfa_plog.h>
20 #include <cs/bfa_debug.h>
23 plkd_validate_logrec(struct bfa_plog_rec_s
*pl_rec
)
25 if ((pl_rec
->log_type
!= BFA_PL_LOG_TYPE_INT
)
26 && (pl_rec
->log_type
!= BFA_PL_LOG_TYPE_STRING
))
29 if ((pl_rec
->log_type
!= BFA_PL_LOG_TYPE_INT
)
30 && (pl_rec
->log_num_ints
> BFA_PL_INT_LOG_SZ
))
37 bfa_plog_add(struct bfa_plog_s
*plog
, struct bfa_plog_rec_s
*pl_rec
)
40 struct bfa_plog_rec_s
*pl_recp
;
42 if (plog
->plog_enabled
== 0)
45 if (plkd_validate_logrec(pl_rec
)) {
52 pl_recp
= &(plog
->plog_recs
[tail
]);
54 bfa_os_memcpy(pl_recp
, pl_rec
, sizeof(struct bfa_plog_rec_s
));
56 pl_recp
->tv
= BFA_TRC_TS(plog
);
57 BFA_PL_LOG_REC_INCR(plog
->tail
);
59 if (plog
->head
== plog
->tail
)
60 BFA_PL_LOG_REC_INCR(plog
->head
);
64 bfa_plog_init(struct bfa_plog_s
*plog
)
66 bfa_os_memset((char *)plog
, 0, sizeof(struct bfa_plog_s
));
68 bfa_os_memcpy(plog
->plog_sig
, BFA_PL_SIG_STR
, BFA_PL_SIG_LEN
);
69 plog
->head
= plog
->tail
= 0;
70 plog
->plog_enabled
= 1;
74 bfa_plog_str(struct bfa_plog_s
*plog
, enum bfa_plog_mid mid
,
75 enum bfa_plog_eid event
,
76 u16 misc
, char *log_str
)
78 struct bfa_plog_rec_s lp
;
80 if (plog
->plog_enabled
) {
81 bfa_os_memset(&lp
, 0, sizeof(struct bfa_plog_rec_s
));
84 lp
.log_type
= BFA_PL_LOG_TYPE_STRING
;
86 strncpy(lp
.log_entry
.string_log
, log_str
,
87 BFA_PL_STRING_LOG_SZ
- 1);
88 lp
.log_entry
.string_log
[BFA_PL_STRING_LOG_SZ
- 1] = '\0';
89 bfa_plog_add(plog
, &lp
);
94 bfa_plog_intarr(struct bfa_plog_s
*plog
, enum bfa_plog_mid mid
,
95 enum bfa_plog_eid event
,
96 u16 misc
, u32
*intarr
, u32 num_ints
)
98 struct bfa_plog_rec_s lp
;
101 if (num_ints
> BFA_PL_INT_LOG_SZ
)
102 num_ints
= BFA_PL_INT_LOG_SZ
;
104 if (plog
->plog_enabled
) {
105 bfa_os_memset(&lp
, 0, sizeof(struct bfa_plog_rec_s
));
108 lp
.log_type
= BFA_PL_LOG_TYPE_INT
;
111 for (i
= 0; i
< num_ints
; i
++)
112 bfa_os_assign(lp
.log_entry
.int_log
[i
],
115 lp
.log_num_ints
= (u8
) num_ints
;
117 bfa_plog_add(plog
, &lp
);
122 bfa_plog_fchdr(struct bfa_plog_s
*plog
, enum bfa_plog_mid mid
,
123 enum bfa_plog_eid event
,
124 u16 misc
, struct fchs_s
*fchdr
)
126 struct bfa_plog_rec_s lp
;
127 u32
*tmp_int
= (u32
*) fchdr
;
128 u32 ints
[BFA_PL_INT_LOG_SZ
];
130 if (plog
->plog_enabled
) {
131 bfa_os_memset(&lp
, 0, sizeof(struct bfa_plog_rec_s
));
133 ints
[0] = tmp_int
[0];
134 ints
[1] = tmp_int
[1];
135 ints
[2] = tmp_int
[4];
137 bfa_plog_intarr(plog
, mid
, event
, misc
, ints
, 3);
142 bfa_plog_fchdr_and_pl(struct bfa_plog_s
*plog
, enum bfa_plog_mid mid
,
143 enum bfa_plog_eid event
, u16 misc
, struct fchs_s
*fchdr
,
146 struct bfa_plog_rec_s lp
;
147 u32
*tmp_int
= (u32
*) fchdr
;
148 u32 ints
[BFA_PL_INT_LOG_SZ
];
150 if (plog
->plog_enabled
) {
151 bfa_os_memset(&lp
, 0, sizeof(struct bfa_plog_rec_s
));
153 ints
[0] = tmp_int
[0];
154 ints
[1] = tmp_int
[1];
155 ints
[2] = tmp_int
[4];
158 bfa_plog_intarr(plog
, mid
, event
, misc
, ints
, 4);
163 bfa_plog_clear(struct bfa_plog_s
*plog
)
165 plog
->head
= plog
->tail
= 0;
169 bfa_plog_enable(struct bfa_plog_s
*plog
)
171 plog
->plog_enabled
= 1;
175 bfa_plog_disable(struct bfa_plog_s
*plog
)
177 plog
->plog_enabled
= 0;
181 bfa_plog_get_setting(struct bfa_plog_s
*plog
)
183 return (bfa_boolean_t
)plog
->plog_enabled
;