1/*-
2 * Copyright (c) 2002-2007 Neterion, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD$
27 */
28
29#include "xge_log.h"
30
31/**
32 * xge_print_hwstats
33 * Prints/logs hardware statistics
34 *
35 * @hw_stats Hardware statistics
36 * @device_id Device ID
37 */
38void
39xge_print_hwstats(void *hw_stats, unsigned short device_id)
40{
41	int index = 0, count = 0;
42
43	count = XGE_COUNT_STATS -
44	    ((device_id == DEVICE_ID_XFRAME_II) ? 0 : XGE_COUNT_EXTENDED_STATS);
45
46	fdAll = fopen("stats.log", "w+");
47	if(!fdAll)
48	    goto _exit;
49
50	XGE_PRINT_HEADER_STATS(fdAll);
51	for(index = 0; index < count ; index++) {
52	    switch(statsInfo[index].type) {
53	        case 2:
54	            statsInfo[index].value =
55	                *((u16 *)((unsigned char *)hw_stats +
56	                GET_OFFSET_STATS(index)));
57	            break;
58	        case 4:
59	            statsInfo[index].value =
60	                *((u32 *)((unsigned char *) hw_stats +
61	                GET_OFFSET_STATS(index)));
62	            break;
63	        case 8:
64	            statsInfo[index].value =
65	                *((u64 *)((unsigned char *)hw_stats +
66	                GET_OFFSET_STATS(index)));
67	            break;
68	    }
69
70	    XGE_PRINT_STATS(fdAll,(const char *) statsInfo[index].name,
71	        statsInfo[index].value);
72	}
73	XGE_PRINT_LINE(fdAll);
74	fclose(fdAll);
75_exit:
76	return;
77}
78
79/**
80 * xge_print_pciconf
81 * Prints/logs PCI configuration space
82 *
83 * @pci_conf PCI Configuration
84 */
85void
86xge_print_pciconf(void * pci_conf)
87{
88	int index = 0;
89
90	fdAll = fopen("pciconf.log", "w+");
91	if(!fdAll)
92	    goto _exit;
93
94	XGE_PRINT_HEADER_PCICONF(fdAll);
95	for(index = 0; index < XGE_COUNT_PCICONF; index++) {
96	    pciconfInfo[index].value = *((u16 *)((unsigned char *)pci_conf +
97	        GET_OFFSET_PCICONF(index)));
98	    XGE_PRINT_PCICONF(fdAll,(const char *) pciconfInfo[index].name,
99	        GET_OFFSET_PCICONF(index), pciconfInfo[index].value);
100	}
101
102	XGE_PRINT_LINE(fdAll);
103	fclose(fdAll);
104
105_exit:
106	return;
107}
108
109/**
110 * xge_print_devconf
111 * Prints/logs Device Configuration
112 *
113 * @dev_conf Device Configuration
114 */
115void
116xge_print_devconf(void * dev_conf)
117{
118	int index = 0;
119
120	fdAll = fopen("devconf.log", "w+");
121	if(!fdAll)
122	    goto _exit;
123
124	XGE_PRINT_HEADER_DEVCONF(fdAll);
125
126	for(index = 0; index < XGE_COUNT_DEVCONF; index++) {
127	    devconfInfo[index].value = *((u32 *)((unsigned char *)dev_conf +
128	        (index * (sizeof(int)))));
129	    XGE_PRINT_DEVCONF(fdAll,(const char *) devconfInfo[index].name,
130	        devconfInfo[index].value);
131	}
132
133	XGE_PRINT_LINE(fdAll);
134	fclose( fdAll );
135
136_exit:
137	return;
138}
139
140/**
141 * xge_print_registers
142 * Prints/logs Register values
143 *
144 * @registers Register values
145 */
146void
147xge_print_registers(void * registers)
148{
149	int index = 0;
150
151	fdAll = fopen("reginfo.log", "w+");
152	if(!fdAll)
153	    goto _exit;
154
155	XGE_PRINT_HEADER_REGS(fdAll);
156
157	for(index = 0; index < XGE_COUNT_REGS; index++) {
158	    regInfo[index].value = *((u64 *)((unsigned char *)registers +
159	        regInfo[index].offset));
160	    XGE_PRINT_REGS(fdAll,(const char *) regInfo[index].name,
161	        regInfo[index].offset, regInfo[index].value);
162	}
163
164	XGE_PRINT_LINE(fdAll);
165	fclose(fdAll);
166_exit:
167	return;
168}
169
170/**
171 * xge_print_register
172 * Prints/logs a register value
173 *
174 * @offset Offset of the register
175 * @temp???
176 */
177void
178xge_print_register(u64 offset, u64 value)
179{
180	int index = 0;
181
182	fdAll = fopen("readreg.log", "w+");
183	if(!fdAll)
184	    goto _exit;
185
186	XGE_PRINT_READ_HEADER_REGS(fdAll);
187	regInfo[index].offset = offset;
188	regInfo[index].value  = value;
189	printf("0x%.8X\t0x%.16llX\n", regInfo[index].offset,
190	    regInfo[index].value);
191	XGE_PRINT_LINE(fdAll);
192	fclose(fdAll);
193
194_exit:
195	return;
196}
197
198/**
199 * xge_print_devstats
200 * Prints Device Statistics
201 *
202 * @dev_stats Device Statistics
203 */
204void
205xge_print_devstats(void *dev_stats)
206{
207	int index = 0;
208
209	fdAll = fopen("intrstats.log", "w+");
210	if(!fdAll)
211	    goto _exit;
212
213	XGE_PRINT_HEADER_STATS(fdAll);
214	for(index = 0; index < XGE_COUNT_INTRSTAT; index++) {
215	    intrInfo[index].value = *((u32 *)((unsigned char *)dev_stats +
216	        (index * (sizeof(u32)))));
217	    XGE_PRINT_STATS(fdAll,(const char *) intrInfo[index].name,
218	        intrInfo[index].value);
219	}
220
221	XGE_PRINT_LINE(fdAll);
222	fclose(fdAll);
223_exit:
224	return;
225}
226
227/**
228 * xge_print_swstats
229 * Prints/logs Software Statistics
230 *
231 * @sw_stats Software statistics
232 */
233void
234xge_print_swstats(void * sw_stats)
235{
236	int index = 0;
237
238	fdAll = fopen("tcodestats.log", "w+");
239	if(!fdAll)
240	    goto _exit;
241
242	XGE_PRINT_HEADER_STATS(fdAll);
243	for(index = 0; index < XGE_COUNT_SWSTAT; index++) {
244	    if(!(tcodeInfo[index].flag)) {
245	        switch(tcodeInfo[index].type) {
246	            case 2:
247	                tcodeInfo[index].value =
248	                    *((u16 *)((unsigned char *)sw_stats +
249	                    (index * (sizeof(u16)))));
250	                break;
251	            case 4:
252	                tcodeInfo[index].value =
253	                    *((u32 *)((unsigned char *)sw_stats +
254	                    (index * (sizeof(u32)))));
255	                break;
256	        }
257	        XGE_PRINT_STATS(fdAll,(const char *) tcodeInfo[index].name,
258	            tcodeInfo[index].value);
259	    }
260	}
261
262	XGE_PRINT_LINE(fdAll);
263	fclose(fdAll);
264
265_exit:
266	return;
267}
268
269/**
270 * xge_print_drv_version
271 * Prints/logs driver version
272 *
273 * @version Driver version
274 */
275void
276xge_print_drv_version(char *version)
277{
278	fdAll = fopen("driverinfo.log", "w+");
279	if(!fdAll)
280	    goto _exit;
281
282	XGE_PRINT_LINE(fdAll);
283	printf("Driver Version: %s\n", version);
284	XGE_PRINT_LINE(fdAll);
285	fclose(fdAll);
286
287_exit:
288	return;
289}
290
291/**
292 * xge_print_drvstats
293 * Prints/logs Driver Statistics
294 *
295 * @driver_stats Driver Statistics
296 */
297void
298xge_print_drvstats(void * driver_stats)
299{
300	int index = 0;
301
302	fdAll = fopen("driver_stats.log", "w+");
303	if(!fdAll)
304	    goto _exit;
305
306	XGE_PRINT_HEADER_STATS(fdAll);
307
308	for(index = 0; index < XGE_COUNT_DRIVERSTATS; index++) {
309	    driverInfo[index].value = *((u64 *)((unsigned char *)driver_stats +
310	        (index * (sizeof(u64)))));
311	    XGE_PRINT_STATS(fdAll,(const char *) driverInfo[index].name,
312	        driverInfo[index].value);
313	}
314
315	XGE_PRINT_LINE(fdAll);
316	fclose( fdAll );
317
318_exit:
319	return;
320}
321
322