upload tizen1.0 source
[kernel/linux-2.6.36.git] / drivers / scsi / bfa / plog.c
1 /*
2  * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
3  * All rights reserved
4  * www.brocade.com
5  *
6  * Linux driver for Brocade Fibre Channel Host Bus Adapter.
7  *
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
11  *
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.
16  */
17
18 #include <bfa_os_inc.h>
19 #include <cs/bfa_plog.h>
20 #include <cs/bfa_debug.h>
21
22 static int
23 plkd_validate_logrec(struct bfa_plog_rec_s *pl_rec)
24 {
25         if ((pl_rec->log_type != BFA_PL_LOG_TYPE_INT)
26             && (pl_rec->log_type != BFA_PL_LOG_TYPE_STRING))
27                 return 1;
28
29         if ((pl_rec->log_type != BFA_PL_LOG_TYPE_INT)
30             && (pl_rec->log_num_ints > BFA_PL_INT_LOG_SZ))
31                 return 1;
32
33         return 0;
34 }
35
36 static void
37 bfa_plog_add(struct bfa_plog_s *plog, struct bfa_plog_rec_s *pl_rec)
38 {
39         u16        tail;
40         struct bfa_plog_rec_s *pl_recp;
41
42         if (plog->plog_enabled == 0)
43                 return;
44
45         if (plkd_validate_logrec(pl_rec)) {
46                 bfa_assert(0);
47                 return;
48         }
49
50         tail = plog->tail;
51
52         pl_recp = &(plog->plog_recs[tail]);
53
54         bfa_os_memcpy(pl_recp, pl_rec, sizeof(struct bfa_plog_rec_s));
55
56         pl_recp->tv = BFA_TRC_TS(plog);
57         BFA_PL_LOG_REC_INCR(plog->tail);
58
59         if (plog->head == plog->tail)
60                 BFA_PL_LOG_REC_INCR(plog->head);
61 }
62
63 void
64 bfa_plog_init(struct bfa_plog_s *plog)
65 {
66         bfa_os_memset((char *)plog, 0, sizeof(struct bfa_plog_s));
67
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;
71 }
72
73 void
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)
77 {
78         struct bfa_plog_rec_s  lp;
79
80         if (plog->plog_enabled) {
81                 bfa_os_memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
82                 lp.mid = mid;
83                 lp.eid = event;
84                 lp.log_type = BFA_PL_LOG_TYPE_STRING;
85                 lp.misc = misc;
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);
90         }
91 }
92
93 void
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)
97 {
98         struct bfa_plog_rec_s  lp;
99         u32        i;
100
101         if (num_ints > BFA_PL_INT_LOG_SZ)
102                 num_ints = BFA_PL_INT_LOG_SZ;
103
104         if (plog->plog_enabled) {
105                 bfa_os_memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
106                 lp.mid = mid;
107                 lp.eid = event;
108                 lp.log_type = BFA_PL_LOG_TYPE_INT;
109                 lp.misc = misc;
110
111                 for (i = 0; i < num_ints; i++)
112                         bfa_os_assign(lp.log_entry.int_log[i],
113                                         intarr[i]);
114
115                 lp.log_num_ints = (u8) num_ints;
116
117                 bfa_plog_add(plog, &lp);
118         }
119 }
120
121 void
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)
125 {
126         struct bfa_plog_rec_s  lp;
127         u32       *tmp_int = (u32 *) fchdr;
128         u32        ints[BFA_PL_INT_LOG_SZ];
129
130         if (plog->plog_enabled) {
131                 bfa_os_memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
132
133                 ints[0] = tmp_int[0];
134                 ints[1] = tmp_int[1];
135                 ints[2] = tmp_int[4];
136
137                 bfa_plog_intarr(plog, mid, event, misc, ints, 3);
138         }
139 }
140
141 void
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,
144                       u32 pld_w0)
145 {
146         struct bfa_plog_rec_s  lp;
147         u32       *tmp_int = (u32 *) fchdr;
148         u32        ints[BFA_PL_INT_LOG_SZ];
149
150         if (plog->plog_enabled) {
151                 bfa_os_memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
152
153                 ints[0] = tmp_int[0];
154                 ints[1] = tmp_int[1];
155                 ints[2] = tmp_int[4];
156                 ints[3] = pld_w0;
157
158                 bfa_plog_intarr(plog, mid, event, misc, ints, 4);
159         }
160 }
161
162 void
163 bfa_plog_clear(struct bfa_plog_s *plog)
164 {
165         plog->head = plog->tail = 0;
166 }
167
168 void
169 bfa_plog_enable(struct bfa_plog_s *plog)
170 {
171         plog->plog_enabled = 1;
172 }
173
174 void
175 bfa_plog_disable(struct bfa_plog_s *plog)
176 {
177         plog->plog_enabled = 0;
178 }
179
180 bfa_boolean_t
181 bfa_plog_get_setting(struct bfa_plog_s *plog)
182 {
183         return (bfa_boolean_t)plog->plog_enabled;
184 }