/* This software is covered by the GNU GENERAL PUBLIC LICENSE (GPL). */
/* Any Device - Driver - Linux */
/* $Workfile: proc.c $ */
/* $Revision: 2 $ */
/* $Date: 10/27/07 10:36a $ */
/* $Log: /NEW SOURCESAFE DATABASE/SDK/PLX/gsc/common/driver/linux/proc.c $
 * 
 * 2     10/27/07 10:36a Dnewbold
 * Additional driver porting updates.
 *
 * 1     5/10/06 1:02p Dnewbold
*/

#include "main.h"



/******************************************************************************
*
*	Function:	proc_read
*
*	Purpose:
*
*		Implement the read service for the module's /proc file system entry.
*		Read the documentation on this service for details, as we ignore some
*		arguments according to our needs and the documentation.
*
*	Arguments:
*
*		page	The data produced is put here.
*
*		start	Records pointer to where the data in "page" begins.
*
*		offset	The offset into the file where we're to begin.
*
*		count	The limit to the amount of data we can produce.
*
*		eof		Set this flag when we hit EOF.
*
*		data	A private data item that we may use, but don't.
*
*	Returned:
*
*		int		The number of characters written.
*
******************************************************************************/

int proc_read(
	char*	page,
	char**	start,
	off_t	offset,
	int		count,
	int*	eof,
	void*	data)
{
#define	_PROC_MSG_SIZE	128

#if PAGE_SIZE < _PROC_MSG_SIZE
	#error	"/proc file size may be too big."
#endif

	int	i;

	MOD_INC_USE_COUNT;
	i	= sprintf(	page,
					"version: %s\n"
					"built: %s\n"
					"boards: %d\n",
					DRV_GSC_FILE_VERSION_STR,
					global.built,
					global.dev_qty);
	page[i]	= 0;
	i		= strlen(page) + 1;

	if (i >= PAGE_SIZE)
	{
		printk(	"<1>/proc/%s is larger than PAGE_SIZE\n",
				DRV_DEV_DEVICE_NAME_LOWER);
	}

	i--;
	eof[0]	= 1;
	MOD_DEC_USE_COUNT;
	return(i);
}



/******************************************************************************
*
*	Function:	proc_start
*
*	Purpose:
*
*		initialize use of the /proc file system.
*
*	Arguments:
*
*		None.
*
*	Returned:
*
*		0		All went well.
*		>0		The number of errors seen.
*
******************************************************************************/

int proc_start(void)
{
	int						errs;
	struct proc_dir_entry*	proc;

	if (global.dev_qty)
	{
		proc	= create_proc_entry(DRV_DEV_DEVICE_NAME_LOWER, S_IRUGO, NULL);

		if (proc)
		{
			errs				= 0;
			global.proc_enabled	= 1;
			proc->read_proc		= proc_read;
			PROC_GET_INFO(proc, proc_get_info);
		}
		else
		{
			errs	= 1;
			printk(	"<1>%s: create_proc_entry() failure.\n",
					DRV_DEV_DEVICE_NAME_LOWER);
		}
	}
	else
	{
		errs	= 0;
	}

	return(errs);
}



/******************************************************************************
*
*	Function:	proc_stop
*
*	Purpose:
*
*		Stop use of the /proc file system.
*
*	Arguments:
*
*		None.
*
*	Returned:
*
*		None.
*
******************************************************************************/

void proc_stop(void)
{
	if (global.proc_enabled)
	{
		remove_proc_entry(DRV_DEV_DEVICE_NAME_LOWER, NULL);
		global.proc_enabled	= 0;
	}
}



