aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/epl/proc_fs.c
blob: f4910332d3c6e4d700597cce8fbb533c59a2dd4f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
/****************************************************************************

  (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29
      www.systec-electronic.com

  Project:      openPOWERLINK

  Description:  proc fs entry with diagnostic information under Linux

  License:

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions
    are met:

    1. Redistributions of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.

    2. Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.

    3. Neither the name of SYSTEC electronic GmbH nor the names of its
       contributors may be used to endorse or promote products derived
       from this software without prior written permission. For written
       permission, please contact info@systec-electronic.com.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
    COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    POSSIBILITY OF SUCH DAMAGE.

    Severability Clause:

        If a provision of this License is or becomes illegal, invalid or
        unenforceable in any jurisdiction, that shall not affect:
        1. the validity or enforceability in that jurisdiction of any other
           provision of this License; or
        2. the validity or enforceability in other jurisdictions of that or
           any other provision of this License.

  -------------------------------------------------------------------------

                $RCSfile: proc_fs.c,v $

                $Author: D.Krueger $

                $Revision: 1.13 $  $Date: 2008/11/07 13:55:56 $

                $State: Exp $

                Build Environment:
                    GNU

  -------------------------------------------------------------------------

  Revision History:

  2006/07/31 d.k.:   start of implementation

****************************************************************************/

#include "kernel/EplNmtk.h"
#include "user/EplNmtu.h"

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
#include "user/EplNmtMnu.h"
#endif

#include "kernel/EplDllkCal.h"

//#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/errno.h>
#include <linux/major.h>
#include <linux/version.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include <asm/atomic.h>
#include <linux/proc_fs.h>
#include <linux/spinlock.h>

#ifdef CONFIG_COLDFIRE
#include <asm/coldfire.h>
#include "fec.h"
#endif

/***************************************************************************/
/*                                                                         */
/*                                                                         */
/*          G L O B A L   D E F I N I T I O N S                            */
/*                                                                         */
/*                                                                         */
/***************************************************************************/

//---------------------------------------------------------------------------
// const defines
//---------------------------------------------------------------------------

#ifndef EPL_PROC_DEV_NAME
#define EPL_PROC_DEV_NAME    "epl"
#endif

#ifndef DBG_TRACE_POINTS
#define DBG_TRACE_POINTS    23	// # of supported debug trace points
#endif

#ifndef DBG_TRACE_VALUES
#define DBG_TRACE_VALUES    24	// # of supported debug trace values (size of circular buffer)
#endif

//---------------------------------------------------------------------------
// modul global types
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// local vars
//---------------------------------------------------------------------------

#ifdef _DBG_TRACE_POINTS_
atomic_t aatmDbgTracePoint_l[DBG_TRACE_POINTS];
DWORD adwDbgTraceValue_l[DBG_TRACE_VALUES];
DWORD dwDbgTraceValueOld_l;
unsigned int uiDbgTraceValuePos_l;
spinlock_t spinlockDbgTraceValue_l;
unsigned long ulDbTraceValueFlags_l;
#endif

//---------------------------------------------------------------------------
// local function prototypes
//---------------------------------------------------------------------------

static int EplLinProcRead(char *pcBuffer_p, char **ppcStart_p, off_t Offset_p,
			  int nBufferSize_p, int *pEof_p, void *pData_p);
static int EplLinProcWrite(struct file *file, const char __user * buffer,
			   unsigned long count, void *data);

void PUBLIC TgtDbgSignalTracePoint(BYTE bTracePointNumber_p);
void PUBLIC TgtDbgPostTraceValue(DWORD dwTraceValue_p);

EPLDLLEXPORT DWORD PUBLIC EplIdentuGetRunningRequests(void);

//=========================================================================//
//                                                                         //
//          P U B L I C   F U N C T I O N S                                //
//                                                                         //
//=========================================================================//

tEplKernel EplLinProcInit(void)
{
	struct proc_dir_entry *pProcDirEntry;
	pProcDirEntry = create_proc_entry(EPL_PROC_DEV_NAME, S_IRUGO, NULL);
	if (pProcDirEntry != NULL) {
		pProcDirEntry->read_proc = EplLinProcRead;
		pProcDirEntry->write_proc = EplLinProcWrite;
		pProcDirEntry->data = NULL;	// device number or something else

	} else {
		return kEplNoResource;
	}

#ifdef _DBG_TRACE_POINTS_
	// initialize spinlock and circular buffer position
	spin_lock_init(&spinlockDbgTraceValue_l);
	uiDbgTraceValuePos_l = 0;
	dwDbgTraceValueOld_l = 0;
#endif

	return kEplSuccessful;
}

tEplKernel EplLinProcFree(void)
{
	remove_proc_entry(EPL_PROC_DEV_NAME, NULL);

	return kEplSuccessful;
}

//---------------------------------------------------------------------------
//  Target specific event signaling (FEC Tx-/Rx-Interrupt, used by Edrv)
//---------------------------------------------------------------------------

#ifdef _DBG_TRACE_POINTS_
void PUBLIC TgtDbgSignalTracePoint(BYTE bTracePointNumber_p)
{

	if (bTracePointNumber_p >=
	    (sizeof(aatmDbgTracePoint_l) / sizeof(aatmDbgTracePoint_l[0]))) {
		goto Exit;
	}

	atomic_inc(&aatmDbgTracePoint_l[bTracePointNumber_p]);

      Exit:

	return;

}

void PUBLIC TgtDbgPostTraceValue(DWORD dwTraceValue_p)
{

	spin_lock_irqsave(&spinlockDbgTraceValue_l, ulDbTraceValueFlags_l);
	if (dwDbgTraceValueOld_l != dwTraceValue_p) {
		adwDbgTraceValue_l[uiDbgTraceValuePos_l] = dwTraceValue_p;
		uiDbgTraceValuePos_l =
		    (uiDbgTraceValuePos_l + 1) % DBG_TRACE_VALUES;
		dwDbgTraceValueOld_l = dwTraceValue_p;
	}
	spin_unlock_irqrestore(&spinlockDbgTraceValue_l, ulDbTraceValueFlags_l);

	return;

}
#endif

//---------------------------------------------------------------------------
//  Read function for PROC-FS read access
//---------------------------------------------------------------------------

static int EplLinProcRead(char *pcBuffer_p,
			  char **ppcStart_p,
			  off_t Offset_p,
			  int nBufferSize_p, int *pEof_p, void *pData_p)
{

	int nSize;
	int Eof;
	tEplDllkCalStatistics *pDllkCalStats;

	nSize = 0;
	Eof = 0;

	// count calls of this function
#ifdef _DBG_TRACE_POINTS_
	TgtDbgSignalTracePoint(0);
#endif

	//---------------------------------------------------------------
	// generate static information
	//---------------------------------------------------------------

	// ---- Driver information ----
	nSize += snprintf(pcBuffer_p + nSize, nBufferSize_p - nSize,
			  "%s    %s    (c) 2006 %s\n",
			  EPL_PRODUCT_NAME, EPL_PRODUCT_VERSION,
			  EPL_PRODUCT_MANUFACTURER);

	//---------------------------------------------------------------
	// generate process information
	//---------------------------------------------------------------

	// ---- EPL state ----
	nSize += snprintf(pcBuffer_p + nSize, nBufferSize_p - nSize,
			  "NMT state:                  0x%04X\n",
			  (WORD) EplNmtkGetNmtState());

	EplDllkCalGetStatistics(&pDllkCalStats);

	nSize += snprintf(pcBuffer_p + nSize, nBufferSize_p - nSize,
			  "CurAsyncTxGen=%lu CurAsyncTxNmt=%lu CurAsyncRx=%lu\nMaxAsyncTxGen=%lu MaxAsyncTxNmt=%lu MaxAsyncRx=%lu\n",
			  pDllkCalStats->m_ulCurTxFrameCountGen,
			  pDllkCalStats->m_ulCurTxFrameCountNmt,
			  pDllkCalStats->m_ulCurRxFrameCount,
			  pDllkCalStats->m_ulMaxTxFrameCountGen,
			  pDllkCalStats->m_ulMaxTxFrameCountNmt,
			  pDllkCalStats->m_ulMaxRxFrameCount);

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
	// fetch running IdentRequests
	nSize += snprintf(pcBuffer_p + nSize, nBufferSize_p - nSize,
			  "running IdentRequests:      0x%08lX\n",
			  EplIdentuGetRunningRequests());

	// fetch state of NmtMnu module
	{
		unsigned int uiMandatorySlaveCount;
		unsigned int uiSignalSlaveCount;
		WORD wFlags;

		EplNmtMnuGetDiagnosticInfo(&uiMandatorySlaveCount,
					   &uiSignalSlaveCount, &wFlags);

		nSize += snprintf(pcBuffer_p + nSize, nBufferSize_p - nSize,
				  "MN  MandSlaveCount: %u  SigSlaveCount: %u  Flags: 0x%X\n",
				  uiMandatorySlaveCount, uiSignalSlaveCount,
				  wFlags);

	}
#endif

	// ---- FEC state ----
#ifdef CONFIG_COLDFIRE
	{
		// Receive the base address
		unsigned long base_addr;
#if (EDRV_USED_ETH_CTRL == 0)
		// Set the base address of FEC0
		base_addr = FEC_BASE_ADDR_FEC0;
#else
		// Set the base address of FEC1
		base_addr = FEC_BASE_ADDR_FEC1;
#endif

		nSize += snprintf(pcBuffer_p + nSize, nBufferSize_p - nSize,
				  "FEC_ECR = 0x%08X FEC_EIR = 0x%08X FEC_EIMR = 0x%08X\nFEC_TCR = 0x%08X FECTFSR = 0x%08X FECRFSR = 0x%08X\n",
				  FEC_ECR(base_addr), FEC_EIR(base_addr),
				  FEC_EIMR(base_addr), FEC_TCR(base_addr),
				  FEC_FECTFSR(base_addr),
				  FEC_FECRFSR(base_addr));
	}
#endif

	// ---- DBG: TracePoints ----
#ifdef _DBG_TRACE_POINTS_
	{
		int nNum;

		nSize += snprintf(pcBuffer_p + nSize, nBufferSize_p - nSize,
				  "DbgTracePoints:\n");
		for (nNum = 0;
		     nNum < (sizeof(aatmDbgTracePoint_l) / sizeof(atomic_t));
		     nNum++) {
			nSize +=
			    snprintf(pcBuffer_p + nSize, nBufferSize_p - nSize,
				     " TracePoint[%2d]: %d\n", (int)nNum,
				     atomic_read(&aatmDbgTracePoint_l[nNum]));
		}

		nSize += snprintf(pcBuffer_p + nSize, nBufferSize_p - nSize,
				  "DbgTraceValues:\n");
		for (nNum = 0; nNum < DBG_TRACE_VALUES; nNum++) {
			if (nNum == uiDbgTraceValuePos_l) {	// next value will be stored at that position
				nSize +=
				    snprintf(pcBuffer_p + nSize,
					     nBufferSize_p - nSize, "*%08lX",
					     adwDbgTraceValue_l[nNum]);
			} else {
				nSize +=
				    snprintf(pcBuffer_p + nSize,
					     nBufferSize_p - nSize, " %08lX",
					     adwDbgTraceValue_l[nNum]);
			}
			if ((nNum & 0x00000007) == 0x00000007) {	// 8 values printed -> end of line reached
				nSize +=
				    snprintf(pcBuffer_p + nSize,
					     nBufferSize_p - nSize, "\n");
			}
		}
		if ((nNum & 0x00000007) != 0x00000007) {	// number of values printed is not a multiple of 8 -> print new line
			nSize +=
			    snprintf(pcBuffer_p + nSize, nBufferSize_p - nSize,
				     "\n");
		}
	}
#endif

	Eof = 1;
	goto Exit;

      Exit:

	*pEof_p = Eof;

	return (nSize);

}

//---------------------------------------------------------------------------
//  Write function for PROC-FS write access
//---------------------------------------------------------------------------

static int EplLinProcWrite(struct file *file, const char __user * buffer,
			   unsigned long count, void *data)
{
	char abBuffer[count + 1];
	int iErr;
	int iVal = 0;
	tEplNmtEvent NmtEvent;

	if (count > 0) {
		iErr = copy_from_user(abBuffer, buffer, count);
		if (iErr != 0) {
			return count;
		}
		abBuffer[count] = '\0';

		iErr = sscanf(abBuffer, "%i", &iVal);
	}
	if ((iVal <= 0) || (iVal > 0x2F)) {
		NmtEvent = kEplNmtEventSwReset;
	} else {
		NmtEvent = (tEplNmtEvent) iVal;
	}
	// execute specified NMT command on write access of /proc/epl
	EplNmtuNmtEvent(NmtEvent);

	return count;
}