#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>
+#include <linux/seq_file.h>
#include <linux/string.h>
#include <linux/vmalloc.h>
#include <linux/netdevice.h>
#define FT1000_PROC "ft1000"
#define MAX_FILE_LEN 255
-#define PUTM_TO_PAGE(len, page, args...) \
- len += snprintf(page+len, PAGE_SIZE - len, args)
-
-#define PUTX_TO_PAGE(len, page, message, size, var) \
- len += snprintf(page+len, PAGE_SIZE - len, message); \
+#define seq_putx(m, message, size, var) \
+ seq_printf(m, message); \
for(i = 0; i < (size - 1); i++) { \
- len += snprintf(page+len, PAGE_SIZE - len, "%02x:", var[i]); \
+ seq_printf(m, "%02x:", var[i]); \
} \
- len += snprintf(page+len, PAGE_SIZE - len, "%02x\n", var[i])
+ seq_printf(m, "%02x\n", var[i])
-#define PUTD_TO_PAGE(len, page, message, size, var) \
- len += snprintf(page+len, PAGE_SIZE - len, message); \
+#define seq_putd(m, message, size, var) \
+ seq_printf(m, message); \
for(i = 0; i < (size - 1); i++) { \
- len += snprintf(page+len, PAGE_SIZE - len, "%d.", var[i]); \
+ seq_printf(m, "%d.", var[i]); \
} \
- len += snprintf(page+len, PAGE_SIZE - len, "%d\n", var[i])
+ seq_printf(m, "%d\n", var[i])
-static int ft1000ReadProc(char *page, char **start, off_t off,
- int count, int *eof, void *data)
+static int ft1000ReadProc(struct seq_file *m, void *v)
{
- struct net_device *dev;
- int len;
- int i;
- struct ft1000_info *info;
- char *status[] = {
+ static const char *status[] = {
"Idle (Disconnect)", "Searching", "Active (Connected)",
"Waiting for L2", "Sleep", "No Coverage", "", ""
};
- char *signal[] = { "", "*", "**", "***", "****" };
+ static const char *signal[] = { "", "*", "**", "***", "****" };
+
+ struct net_device *dev = m->private;
+ struct ft1000_info *info = netdev_priv(dev);
+ int i;
int strength;
int quality;
struct timeval tv;
time_t delta;
- dev = (struct net_device *)data;
- info = netdev_priv(dev);
-
- if (off > 0) {
- *eof = 1;
- return 0;
- }
-
- /* Wrap-around */
-
if (info->AsicID == ELECTRABUZZ_ID) {
if (info->ProgConStat != 0xFF) {
info->LedStat =
ft1000_read_dpram(dev, FT1000_DSP_LED);
info->ConStat =
- ft1000_read_dpram(dev,
- FT1000_DSP_CON_STATE);
+ ft1000_read_dpram(dev, FT1000_DSP_CON_STATE);
} else {
info->ConStat = 0xf;
}
} else {
if (info->ProgConStat != 0xFF) {
info->LedStat =
- ntohs(ft1000_read_dpram_mag_16
- (dev, FT1000_MAG_DSP_LED,
- FT1000_MAG_DSP_LED_INDX));
+ ntohs(ft1000_read_dpram_mag_16(
+ dev, FT1000_MAG_DSP_LED,
+ FT1000_MAG_DSP_LED_INDX));
info->ConStat =
- ntohs(ft1000_read_dpram_mag_16
- (dev, FT1000_MAG_DSP_CON_STATE,
- FT1000_MAG_DSP_CON_STATE_INDX));
+ ntohs(ft1000_read_dpram_mag_16(
+ dev, FT1000_MAG_DSP_CON_STATE,
+ FT1000_MAG_DSP_CON_STATE_INDX));
} else {
info->ConStat = 0xf;
}
}
do_gettimeofday(&tv);
- delta = (tv.tv_sec - info->ConTm);
- len = 0;
- PUTM_TO_PAGE(len, page, "Connection Time: %02ld:%02ld:%02ld\n",
+ delta = tv.tv_sec - info->ConTm;
+ seq_printf(m, "Connection Time: %02ld:%02ld:%02ld\n",
((delta / 3600) % 24), ((delta / 60) % 60), (delta % 60));
- PUTM_TO_PAGE(len, page, "Connection Time[s]: %ld\n", delta);
- PUTM_TO_PAGE(len, page, "Asic ID: %s\n",
- (info->AsicID) ==
+ seq_printf(m, "Connection Time[s]: %ld\n", delta);
+ seq_printf(m, "Asic ID: %s\n",
+ info->AsicID ==
ELECTRABUZZ_ID ? "ELECTRABUZZ ASIC" : "MAGNEMITE ASIC");
- PUTX_TO_PAGE(len, page, "SKU: ", SKUSZ, info->Sku);
- PUTX_TO_PAGE(len, page, "EUI64: ", EUISZ, info->eui64);
- PUTD_TO_PAGE(len, page, "DSP version number: ", DSPVERSZ, info->DspVer);
- PUTX_TO_PAGE(len, page, "Hardware Serial Number: ", HWSERNUMSZ,
- info->HwSerNum);
- PUTX_TO_PAGE(len, page, "Caliberation Version: ", CALVERSZ,
- info->RfCalVer);
- PUTD_TO_PAGE(len, page, "Caliberation Date: ", CALDATESZ,
- info->RfCalDate);
- PUTM_TO_PAGE(len, page, "Media State: %s\n",
+ seq_putx(m, "SKU: ", SKUSZ, info->Sku);
+ seq_putx(m, "EUI64: ", EUISZ, info->eui64);
+ seq_putd(m, "DSP version number: ", DSPVERSZ, info->DspVer);
+ seq_putx(m, "Hardware Serial Number: ", HWSERNUMSZ, info->HwSerNum);
+ seq_putx(m, "Caliberation Version: ", CALVERSZ, info->RfCalVer);
+ seq_putd(m, "Caliberation Date: ", CALDATESZ, info->RfCalDate);
+ seq_printf(m, "Media State: %s\n",
(info->mediastate) ? "link" : "no link");
- PUTM_TO_PAGE(len, page, "Connection Status: %s\n",
- status[((info->ConStat) & 0x7)]);
- PUTM_TO_PAGE(len, page, "RX packets: %ld\n", info->stats.rx_packets);
- PUTM_TO_PAGE(len, page, "TX packets: %ld\n", info->stats.tx_packets);
- PUTM_TO_PAGE(len, page, "RX bytes: %ld\n", info->stats.rx_bytes);
- PUTM_TO_PAGE(len, page, "TX bytes: %ld\n", info->stats.tx_bytes);
- PUTM_TO_PAGE(len, page, "Signal Strength: %s\n", signal[strength]);
- PUTM_TO_PAGE(len, page, "Signal Quality: %s\n", signal[quality]);
- return len;
+ seq_printf(m, "Connection Status: %s\n", status[info->ConStat & 0x7]);
+ seq_printf(m, "RX packets: %ld\n", info->stats.rx_packets);
+ seq_printf(m, "TX packets: %ld\n", info->stats.tx_packets);
+ seq_printf(m, "RX bytes: %ld\n", info->stats.rx_bytes);
+ seq_printf(m, "TX bytes: %ld\n", info->stats.tx_bytes);
+ seq_printf(m, "Signal Strength: %s\n", signal[strength]);
+ seq_printf(m, "Signal Quality: %s\n", signal[quality]);
+ return 0;
+}
+
+/*
+ * seq_file wrappers for procfile show routines.
+ */
+static int ft1000_proc_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, ft1000ReadProc, PDE_DATA(inode));
}
+static const struct file_operations ft1000_proc_fops = {
+ .open = ft1000_proc_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = seq_release,
+};
+
static int ft1000NotifyProc(struct notifier_block *this, unsigned long event,
void *ptr)
{
switch (event) {
case NETDEV_CHANGENAME:
remove_proc_entry(info->netdevname, info->ft1000_proc_dir);
- create_proc_read_entry(dev->name, 0644, info->ft1000_proc_dir,
- ft1000ReadProc, dev);
+ proc_create_data(dev->name, 0644, info->ft1000_proc_dir,
+ &ft1000_proc_fops, dev);
snprintf(info->netdevname, IFNAMSIZ, "%s", dev->name);
break;
}
info = netdev_priv(dev);
info->ft1000_proc_dir = proc_mkdir(FT1000_PROC, init_net.proc_net);
- create_proc_read_entry(dev->name, 0644, info->ft1000_proc_dir,
- ft1000ReadProc, dev);
+
+ proc_create_data(dev->name, 0644, info->ft1000_proc_dir,
+ &ft1000_proc_fops, dev);
+
snprintf(info->netdevname, IFNAMSIZ, "%s", dev->name);
register_netdevice_notifier(&ft1000_netdev_notifier);
}
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>
+#include <linux/seq_file.h>
#include <linux/netdevice.h>
#define FT1000_PROC_DIR "ft1000"
-#define PUTM_TO_PAGE(len,page,args...) \
- len += snprintf(page+len, PAGE_SIZE - len, args)
+#define seq_putx(m, message, size, var) \
+ seq_printf(m, message); \
+ for(i = 0; i < (size - 1); i++) \
+ seq_printf(m, "%02x:", var[i]); \
+ seq_printf(m, "%02x\n", var[i])
-#define PUTX_TO_PAGE(len,page,message,size,var) \
- len += snprintf(page+len, PAGE_SIZE - len, message); \
- for (i = 0; i < (size - 1); i++) {\
- len += snprintf(page+len, PAGE_SIZE - len, "%02x:", var[i]); \
- } \
- len += snprintf(page+len, PAGE_SIZE - len, "%02x\n", var[i])
-
-#define PUTD_TO_PAGE(len,page,message,size,var) \
- len += snprintf(page+len, PAGE_SIZE - len, message); \
- for (i = 0; i < (size - 1); i++) {\
- len += snprintf(page+len, PAGE_SIZE - len, "%d.", var[i]); \
- } \
- len += snprintf(page+len, PAGE_SIZE - len, "%d\n", var[i])
+#define seq_putd(m, message, size, var) \
+ seq_printf(m, message); \
+ for(i = 0; i < (size - 1); i++) \
+ seq_printf(m, "%d.", var[i]); \
+ seq_printf(m, "%d\n", var[i])
#define FTNET_PROC init_net.proc_net
u8 *buffer, u8 highlow);
-static int
-ft1000ReadProc(char *page, char **start, off_t off, int count, int *eof,
- void *data)
+static int ft1000ReadProc(struct seq_file *m, void *v)
{
- struct net_device *dev;
- int len;
- int i;
- unsigned short ledStat;
- unsigned short conStat;
-
- struct ft1000_info *info;
-
- char *status[] = {
+ static const char *status[] = {
"Idle (Disconnect)",
"Searching",
"Active (Connected)",
"",
"",
};
+ static const char *signal[] = { "", "*", "**", "***", "****" };
- char *signal[] = { "", "*", "**", "***", "****" };
+ struct net_device *dev = m->private;
+ struct ft1000_info *info = netdev_priv(dev);
+ int i;
+ unsigned short ledStat;
+ unsigned short conStat;
int strength;
int quality;
struct timeval tv;
time_t delta;
- dev = (struct net_device *) data;
- info = netdev_priv(dev);
-
- if (off > 0) {
- *eof = 1;
- return 0;
- }
-
-
if (info->ProgConStat != 0xFF) {
ft1000_read_dpram16(info->priv, FT1000_MAG_DSP_LED,
(u8 *)&ledStat, FT1000_MAG_DSP_LED_INDX);
quality = 0;
}
- len = 0;
- PUTM_TO_PAGE(len, page, "Connection Time: %02ld:%02ld:%02ld\n",
+ seq_printf(m, "Connection Time: %02ld:%02ld:%02ld\n",
((delta / 3600) % 24), ((delta / 60) % 60), (delta % 60));
- PUTM_TO_PAGE(len, page, "Connection Time[s]: %ld\n", delta);
- PUTM_TO_PAGE(len, page, "Asic ID: %s\n",
- (info->AsicID) ==
- ELECTRABUZZ_ID ? "ELECTRABUZZ ASIC" : "MAGNEMITE ASIC");
- PUTX_TO_PAGE(len, page, "SKU: ", SKUSZ, info->Sku);
- PUTX_TO_PAGE(len, page, "EUI64: ", EUISZ, info->eui64);
- PUTD_TO_PAGE(len, page, "DSP version number: ", DSPVERSZ, info->DspVer);
- PUTX_TO_PAGE(len, page, "Hardware Serial Number: ", HWSERNUMSZ,
- info->HwSerNum);
- PUTX_TO_PAGE(len, page, "Caliberation Version: ", CALVERSZ,
- info->RfCalVer);
- PUTD_TO_PAGE(len, page, "Caliberation Date: ", CALDATESZ,
- info->RfCalDate);
- PUTM_TO_PAGE(len, page, "Media State: %s\n",
- (info->mediastate) ? "link" : "no link");
- PUTM_TO_PAGE(len, page, "Connection Status: %s\n",
- status[((info->ConStat) & 0x7)]);
- PUTM_TO_PAGE(len, page, "RX packets: %ld\n", info->stats.rx_packets);
- PUTM_TO_PAGE(len, page, "TX packets: %ld\n", info->stats.tx_packets);
- PUTM_TO_PAGE(len, page, "RX bytes: %ld\n", info->stats.rx_bytes);
- PUTM_TO_PAGE(len, page, "TX bytes: %ld\n", info->stats.tx_bytes);
- PUTM_TO_PAGE(len, page, "Signal Strength: %s\n", signal[strength]);
- PUTM_TO_PAGE(len, page, "Signal Quality: %s\n", signal[quality]);
-
- return len;
+ seq_printf(m, "Connection Time[s]: %ld\n", delta);
+ seq_printf(m, "Asic ID: %s\n",
+ (info->AsicID) == ELECTRABUZZ_ID ? "ELECTRABUZZ ASIC" : "MAGNEMITE ASIC");
+ seq_putx(m, "SKU: ", SKUSZ, info->Sku);
+ seq_putx(m, "EUI64: ", EUISZ, info->eui64);
+ seq_putd(m, "DSP version number: ", DSPVERSZ, info->DspVer);
+ seq_putx(m, "Hardware Serial Number: ", HWSERNUMSZ, info->HwSerNum);
+ seq_putx(m, "Caliberation Version: ", CALVERSZ, info->RfCalVer);
+ seq_putd(m, "Caliberation Date: ", CALDATESZ, info->RfCalDate);
+ seq_printf(m, "Media State: %s\n", (info->mediastate) ? "link" : "no link");
+ seq_printf(m, "Connection Status: %s\n", status[info->ConStat & 0x7]);
+ seq_printf(m, "RX packets: %ld\n", info->stats.rx_packets);
+ seq_printf(m, "TX packets: %ld\n", info->stats.tx_packets);
+ seq_printf(m, "RX bytes: %ld\n", info->stats.rx_bytes);
+ seq_printf(m, "TX bytes: %ld\n", info->stats.tx_bytes);
+ seq_printf(m, "Signal Strength: %s\n", signal[strength]);
+ seq_printf(m, "Signal Quality: %s\n", signal[quality]);
+ return 0;
+}
+
+/*
+ * seq_file wrappers for procfile show routines.
+ */
+static int ft1000_proc_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, ft1000ReadProc, PDE_DATA(inode));
}
+static const struct file_operations ft1000_proc_fops = {
+ .open = ft1000_proc_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = seq_release,
+};
+
static int
ft1000NotifyProc(struct notifier_block *this, unsigned long event, void *ptr)
{
switch (event) {
case NETDEV_CHANGENAME:
remove_proc_entry(info->netdevname, info->ft1000_proc_dir);
- ft1000_proc_file = create_proc_read_entry(dev->name, 0644,
- info->ft1000_proc_dir,
- ft1000ReadProc, dev);
+ ft1000_proc_file =
+ proc_create_data(dev->name, 0644, info->ft1000_proc_dir,
+ &ft1000_proc_fops, dev);
snprintf(info->netdevname, IFNAMSIZ, "%s", dev->name);
break;
}
}
ft1000_proc_file =
- create_proc_read_entry(dev->name, 0644,
- info->ft1000_proc_dir, ft1000ReadProc, dev);
+ proc_create_data(dev->name, 0644, info->ft1000_proc_dir,
+ &ft1000_proc_fops, dev);
- if (ft1000_proc_file == NULL) {
+ if (!ft1000_proc_file) {
printk(KERN_WARNING "Unable to create /proc entry.\n");
goto fail_entry;
}