Commit defce4ed authored by Stephen Hemminger's avatar Stephen Hemminger

[netdrvr sk98lin] use seq_file for /proc

Replace proc_read with seq_file interface which is much cleaner.

Also, instead of searching the list of devices looking for the
name which is slow and would break if interface name changes;
store a pointer to device in the proc entry, and retrieve
it from the information saved by single_open.

Formatting and other behaviours are retained.
parent 3d93561d
...@@ -577,13 +577,7 @@ static int XmitFrameSG(SK_AC*, TX_PORT*, struct sk_buff*); ...@@ -577,13 +577,7 @@ static int XmitFrameSG(SK_AC*, TX_PORT*, struct sk_buff*);
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
static const char SK_Root_Dir_entry[] = "sk98lin"; static const char SK_Root_Dir_entry[] = "sk98lin";
static struct proc_dir_entry *pSkRootDir; static struct proc_dir_entry *pSkRootDir;
extern struct file_operations sk_proc_fops;
extern int sk_proc_read( char *buffer,
char **buffer_location,
off_t offset,
int buffer_length,
int *eof,
void *data);
#endif #endif
extern void SkDimEnableModerationIfNeeded(SK_AC *pAC); extern void SkDimEnableModerationIfNeeded(SK_AC *pAC);
...@@ -762,16 +756,11 @@ static int __init skge_probe (void) ...@@ -762,16 +756,11 @@ static int __init skge_probe (void)
} }
/* Create proc file */ /* Create proc file */
if (pSkRootDir && if (pSkRootDir
(pProcFile = create_proc_entry(dev->name, && (pProcFile = create_proc_entry(dev->name, S_IRUGO,
S_IFREG | S_IXUSR | S_IWGRP | S_IROTH,
pSkRootDir))) { pSkRootDir))) {
pProcFile->read_proc = sk_proc_read; pProcFile->proc_fops = &sk_proc_fops;
pProcFile->write_proc = NULL; pProcFile->data = dev;
pProcFile->nlink = 1;
pProcFile->size = sizeof(dev->name + 1);
pProcFile->data = (void *)pProcFile;
pProcFile->owner = THIS_MODULE;
} }
#endif #endif
...@@ -828,15 +817,10 @@ static int __init skge_probe (void) ...@@ -828,15 +817,10 @@ static int __init skge_probe (void)
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
if (pSkRootDir if (pSkRootDir
&& (pProcFile = create_proc_entry(dev->name, && (pProcFile = create_proc_entry(dev->name,
S_IFREG | S_IXUSR | S_IWGRP | S_IROTH, S_IRUGO,
pSkRootDir))) { pSkRootDir))) {
pProcFile->proc_fops = &sk_proc_fops;
pProcFile->read_proc = sk_proc_read; pProcFile->data = dev;
pProcFile->write_proc = NULL;
pProcFile->nlink = 1;
pProcFile->size = sizeof(dev->name + 1);
pProcFile->data = (void *)pProcFile;
pProcFile->owner = THIS_MODULE;
} }
#endif #endif
......
...@@ -90,101 +90,52 @@ ...@@ -90,101 +90,52 @@
******************************************************************************/ ******************************************************************************/
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include "h/skdrv1st.h" #include "h/skdrv1st.h"
#include "h/skdrv2nd.h" #include "h/skdrv2nd.h"
extern struct net_device *SkGeRootDev; #ifdef CONFIG_PROC_FS
extern struct net_device *SkGeRootDev;
int sk_proc_read(char *buffer, static int sk_seq_show(struct seq_file *seq, void *v)
char **buffer_location,
off_t offset,
int buffer_length,
int *eof,
void *data);
/*****************************************************************************
*
* sk_proc_read - print "summaries" entry
*
* Description:
* This function fills the proc entry with statistic data about
* the ethernet device.
*
*
* Returns: buffer with statistic data
*
*/
int sk_proc_read(char *buffer,
char **buffer_location,
off_t offset,
int buffer_length,
int *eof,
void *data)
{ {
int len = 0; struct net_device *dev = seq->private;
int t; DEV_NET *pNet = dev->priv;
SK_AC *pAC = pNet->pAC;
SK_PNMI_STRUCT_DATA *pPnmiStruct = &pAC->PnmiStruct;
SK_PNMI_STAT *pPnmiStat = &pPnmiStruct->Stat[0];
int unit = !(pAC->dev[0] == dev);
int i; int i;
DEV_NET *pNet;
SK_AC *pAC;
char sens_msg[50]; char sens_msg[50];
unsigned long Flags;
unsigned int Size;
struct SK_NET_DEVICE *next;
struct SK_NET_DEVICE *SkgeProcDev = SkGeRootDev;
SK_PNMI_STRUCT_DATA *pPnmiStruct;
SK_PNMI_STAT *pPnmiStat;
struct proc_dir_entry *file = (struct proc_dir_entry*) data;
while (SkgeProcDev) {
pNet = (DEV_NET*) SkgeProcDev->priv;
pAC = pNet->pAC;
next = pAC->Next;
pPnmiStruct = &pAC->PnmiStruct;
/* NetIndex in GetStruct is now required, zero is only dummy */
for (t=pAC->GIni.GIMacsFound; t > 0; t--) {
if ((pAC->GIni.GIMacsFound == 2) && pAC->RlmtNets == 1)
t--;
spin_lock_irqsave(&pAC->SlowPathLock, Flags); seq_printf(seq,
Size = SK_PNMI_STRUCT_SIZE;
SkPnmiGetStruct(pAC, pAC->IoBase,
pPnmiStruct, &Size, t-1);
spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
if (strcmp(pAC->dev[t-1]->name, file->name) == 0) {
pPnmiStat = &pPnmiStruct->Stat[0];
len = sprintf(buffer,
"\nDetailed statistic for device %s\n", "\nDetailed statistic for device %s\n",
pAC->dev[t-1]->name); dev->name);
len += sprintf(buffer + len, seq_printf(seq,
"=======================================\n"); "=======================================\n");
/* Board statistics */ /* Board statistics */
len += sprintf(buffer + len, seq_printf(seq,
"\nBoard statistics\n\n"); "\nBoard statistics\n\n");
len += sprintf(buffer + len, seq_printf(seq,
"Active Port %c\n", "Active Port %c\n",
'A' + pAC->Rlmt.Net[t-1].Port[pAC->Rlmt. 'A' + pAC->Rlmt.Net[unit].Port[pAC->Rlmt.
Net[t-1].PrefPort]->PortNumber); Net[unit].PrefPort]->PortNumber);
len += sprintf(buffer + len, seq_printf(seq,
"Preferred Port %c\n", "Preferred Port %c\n",
'A' + pAC->Rlmt.Net[t-1].Port[pAC->Rlmt. 'A' + pAC->Rlmt.Net[unit].Port[pAC->Rlmt.
Net[t-1].PrefPort]->PortNumber); Net[unit].PrefPort]->PortNumber);
len += sprintf(buffer + len, seq_printf(seq,
"Bus speed (MHz) %d\n", "Bus speed (MHz) %d\n",
pPnmiStruct->BusSpeed); pPnmiStruct->BusSpeed);
len += sprintf(buffer + len, seq_printf(seq,
"Bus width (Bit) %d\n", "Bus width (Bit) %d\n",
pPnmiStruct->BusWidth); pPnmiStruct->BusWidth);
len += sprintf(buffer + len, seq_printf(seq,
"Hardware revision v%d.%d\n", "Hardware revision v%d.%d\n",
(pAC->GIni.GIPciHwRev >> 4) & 0x0F, (pAC->GIni.GIPciHwRev >> 4) & 0x0F,
pAC->GIni.GIPciHwRev & 0x0F); pAC->GIni.GIPciHwRev & 0x0F);
...@@ -196,7 +147,7 @@ void *data) ...@@ -196,7 +147,7 @@ void *data)
case 1: case 1:
strcpy(sens_msg, pAC->I2c.SenTable[i].SenDesc); strcpy(sens_msg, pAC->I2c.SenTable[i].SenDesc);
strcat(sens_msg, " (C)"); strcat(sens_msg, " (C)");
len += sprintf(buffer + len, seq_printf(seq,
"%-25s %d.%02d\n", "%-25s %d.%02d\n",
sens_msg, sens_msg,
pAC->I2c.SenTable[i].SenValue / 10, pAC->I2c.SenTable[i].SenValue / 10,
...@@ -204,7 +155,7 @@ void *data) ...@@ -204,7 +155,7 @@ void *data)
strcpy(sens_msg, pAC->I2c.SenTable[i].SenDesc); strcpy(sens_msg, pAC->I2c.SenTable[i].SenDesc);
strcat(sens_msg, " (F)"); strcat(sens_msg, " (F)");
len += sprintf(buffer + len, seq_printf(seq,
"%-25s %d.%02d\n", "%-25s %d.%02d\n",
sens_msg, sens_msg,
((((pAC->I2c.SenTable[i].SenValue) ((((pAC->I2c.SenTable[i].SenValue)
...@@ -215,7 +166,7 @@ void *data) ...@@ -215,7 +166,7 @@ void *data)
case 2: case 2:
strcpy(sens_msg, pAC->I2c.SenTable[i].SenDesc); strcpy(sens_msg, pAC->I2c.SenTable[i].SenDesc);
strcat(sens_msg, " (V)"); strcat(sens_msg, " (V)");
len += sprintf(buffer + len, seq_printf(seq,
"%-25s %d.%03d\n", "%-25s %d.%03d\n",
sens_msg, sens_msg,
pAC->I2c.SenTable[i].SenValue / 1000, pAC->I2c.SenTable[i].SenValue / 1000,
...@@ -224,7 +175,7 @@ void *data) ...@@ -224,7 +175,7 @@ void *data)
case 3: case 3:
strcpy(sens_msg, pAC->I2c.SenTable[i].SenDesc); strcpy(sens_msg, pAC->I2c.SenTable[i].SenDesc);
strcat(sens_msg, " (rpm)"); strcat(sens_msg, " (rpm)");
len += sprintf(buffer + len, seq_printf(seq,
"%-25s %d\n", "%-25s %d\n",
sens_msg, sens_msg,
pAC->I2c.SenTable[i].SenValue); pAC->I2c.SenTable[i].SenValue);
...@@ -235,13 +186,13 @@ void *data) ...@@ -235,13 +186,13 @@ void *data)
} }
/*Receive statistics */ /*Receive statistics */
len += sprintf(buffer + len, seq_printf(seq,
"\nReceive statistics\n\n"); "\nReceive statistics\n\n");
len += sprintf(buffer + len, seq_printf(seq,
"Received bytes %Ld\n", "Received bytes %Ld\n",
(unsigned long long) pPnmiStat->StatRxOctetsOkCts); (unsigned long long) pPnmiStat->StatRxOctetsOkCts);
len += sprintf(buffer + len, seq_printf(seq,
"Received packets %Ld\n", "Received packets %Ld\n",
(unsigned long long) pPnmiStat->StatRxOkCts); (unsigned long long) pPnmiStat->StatRxOkCts);
#if 0 #if 0
...@@ -256,110 +207,110 @@ void *data) ...@@ -256,110 +207,110 @@ void *data)
pPnmiStruct->InErrorsCts = pPnmiStruct->InErrorsCts - pPnmiStruct->InErrorsCts = pPnmiStruct->InErrorsCts -
pPnmiStat->StatRxTooLongCts; pPnmiStat->StatRxTooLongCts;
len += sprintf(buffer + len, seq_printf(seq,
"Receive errors %Ld\n", "Receive errors %Ld\n",
(unsigned long long) pPnmiStruct->InErrorsCts); (unsigned long long) pPnmiStruct->InErrorsCts);
len += sprintf(buffer + len, seq_printf(seq,
"Receive dropped %Ld\n", "Receive dropped %Ld\n",
(unsigned long long) pPnmiStruct->RxNoBufCts); (unsigned long long) pPnmiStruct->RxNoBufCts);
len += sprintf(buffer + len, seq_printf(seq,
"Received multicast %Ld\n", "Received multicast %Ld\n",
(unsigned long long) pPnmiStat->StatRxMulticastOkCts); (unsigned long long) pPnmiStat->StatRxMulticastOkCts);
len += sprintf(buffer + len, seq_printf(seq,
"Receive error types\n"); "Receive error types\n");
len += sprintf(buffer + len, seq_printf(seq,
" length %Ld\n", " length %Ld\n",
(unsigned long long) pPnmiStat->StatRxRuntCts); (unsigned long long) pPnmiStat->StatRxRuntCts);
len += sprintf(buffer + len, seq_printf(seq,
" buffer overflow %Ld\n", " buffer overflow %Ld\n",
(unsigned long long) pPnmiStat->StatRxFifoOverflowCts); (unsigned long long) pPnmiStat->StatRxFifoOverflowCts);
len += sprintf(buffer + len, seq_printf(seq,
" bad crc %Ld\n", " bad crc %Ld\n",
(unsigned long long) pPnmiStat->StatRxFcsCts); (unsigned long long) pPnmiStat->StatRxFcsCts);
len += sprintf(buffer + len, seq_printf(seq,
" framing %Ld\n", " framing %Ld\n",
(unsigned long long) pPnmiStat->StatRxFramingCts); (unsigned long long) pPnmiStat->StatRxFramingCts);
len += sprintf(buffer + len, seq_printf(seq,
" missed frames %Ld\n", " missed frames %Ld\n",
(unsigned long long) pPnmiStat->StatRxMissedCts); (unsigned long long) pPnmiStat->StatRxMissedCts);
if (pNet->Mtu > 1500) if (pNet->Mtu > 1500)
pPnmiStat->StatRxTooLongCts = 0; pPnmiStat->StatRxTooLongCts = 0;
len += sprintf(buffer + len, seq_printf(seq,
" too long %Ld\n", " too long %Ld\n",
(unsigned long long) pPnmiStat->StatRxTooLongCts); (unsigned long long) pPnmiStat->StatRxTooLongCts);
len += sprintf(buffer + len, seq_printf(seq,
" carrier extension %Ld\n", " carrier extension %Ld\n",
(unsigned long long) pPnmiStat->StatRxCextCts); (unsigned long long) pPnmiStat->StatRxCextCts);
len += sprintf(buffer + len, seq_printf(seq,
" too short %Ld\n", " too short %Ld\n",
(unsigned long long) pPnmiStat->StatRxShortsCts); (unsigned long long) pPnmiStat->StatRxShortsCts);
len += sprintf(buffer + len, seq_printf(seq,
" symbol %Ld\n", " symbol %Ld\n",
(unsigned long long) pPnmiStat->StatRxSymbolCts); (unsigned long long) pPnmiStat->StatRxSymbolCts);
len += sprintf(buffer + len, seq_printf(seq,
" LLC MAC size %Ld\n", " LLC MAC size %Ld\n",
(unsigned long long) pPnmiStat->StatRxIRLengthCts); (unsigned long long) pPnmiStat->StatRxIRLengthCts);
len += sprintf(buffer + len, seq_printf(seq,
" carrier event %Ld\n", " carrier event %Ld\n",
(unsigned long long) pPnmiStat->StatRxCarrierCts); (unsigned long long) pPnmiStat->StatRxCarrierCts);
len += sprintf(buffer + len, seq_printf(seq,
" jabber %Ld\n", " jabber %Ld\n",
(unsigned long long) pPnmiStat->StatRxJabberCts); (unsigned long long) pPnmiStat->StatRxJabberCts);
/*Transmit statistics */ /*Transmit statistics */
len += sprintf(buffer + len, seq_printf(seq,
"\nTransmit statistics\n\n"); "\nTransmit statistics\n\n");
len += sprintf(buffer + len, seq_printf(seq,
"Transmited bytes %Ld\n", "Transmited bytes %Ld\n",
(unsigned long long) pPnmiStat->StatTxOctetsOkCts); (unsigned long long) pPnmiStat->StatTxOctetsOkCts);
len += sprintf(buffer + len, seq_printf(seq,
"Transmited packets %Ld\n", "Transmited packets %Ld\n",
(unsigned long long) pPnmiStat->StatTxOkCts); (unsigned long long) pPnmiStat->StatTxOkCts);
len += sprintf(buffer + len, seq_printf(seq,
"Transmit errors %Ld\n", "Transmit errors %Ld\n",
(unsigned long long) pPnmiStat->StatTxSingleCollisionCts); (unsigned long long) pPnmiStat->StatTxSingleCollisionCts);
len += sprintf(buffer + len, seq_printf(seq,
"Transmit dropped %Ld\n", "Transmit dropped %Ld\n",
(unsigned long long) pPnmiStruct->TxNoBufCts); (unsigned long long) pPnmiStruct->TxNoBufCts);
len += sprintf(buffer + len, seq_printf(seq,
"Transmit collisions %Ld\n", "Transmit collisions %Ld\n",
(unsigned long long) pPnmiStat->StatTxSingleCollisionCts); (unsigned long long) pPnmiStat->StatTxSingleCollisionCts);
len += sprintf(buffer + len, seq_printf(seq,
"Transmit error types\n"); "Transmit error types\n");
len += sprintf(buffer + len, seq_printf(seq,
" excessive collision %ld\n", " excessive collision %ld\n",
pAC->stats.tx_aborted_errors); pAC->stats.tx_aborted_errors);
len += sprintf(buffer + len, seq_printf(seq,
" carrier %Ld\n", " carrier %Ld\n",
(unsigned long long) pPnmiStat->StatTxCarrierCts); (unsigned long long) pPnmiStat->StatTxCarrierCts);
len += sprintf(buffer + len, seq_printf(seq,
" fifo underrun %Ld\n", " fifo underrun %Ld\n",
(unsigned long long) pPnmiStat->StatTxFifoUnderrunCts); (unsigned long long) pPnmiStat->StatTxFifoUnderrunCts);
len += sprintf(buffer + len, seq_printf(seq,
" heartbeat %Ld\n", " heartbeat %Ld\n",
(unsigned long long) pPnmiStat->StatTxCarrierCts); (unsigned long long) pPnmiStat->StatTxCarrierCts);
len += sprintf(buffer + len, seq_printf(seq,
" window %ld\n", " window %ld\n",
pAC->stats.tx_window_errors); pAC->stats.tx_window_errors);
}
}
SkgeProcDev = next;
}
if (offset >= len) {
*eof = 1;
return 0; return 0;
}
*buffer_location = buffer + offset;
if (buffer_length >= len - offset) {
*eof = 1;
}
return (min_t(int, buffer_length, len - offset));
} }
static int sk_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, sk_seq_show, PDE(inode)->data);
}
struct file_operations sk_proc_fops = {
.owner = THIS_MODULE,
.open = sk_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment