#define CAN_PROC_RCVLIST_EFF "rcvlist_eff"
#define CAN_PROC_RCVLIST_ERR "rcvlist_err"
-static void can_init_stats(int caller);
-
-static struct proc_dir_entry *can_create_proc_readentry(const char *name,
- mode_t mode, read_proc_t* read_proc, void *data);
-static void can_remove_proc_readentry(const char *name);
-static unsigned long calc_rate(unsigned long oldjif, unsigned long newjif,
- unsigned long count);
-
-static int can_proc_read_version(char *page, char **start, off_t off,
- int count, int *eof, void *data);
-static int can_proc_read_stats(char *page, char **start, off_t off,
- int count, int *eof, void *data);
-static int can_proc_read_reset_stats(char *page, char **start, off_t off,
- int count, int *eof, void *data);
-static int can_proc_read_rcvlist_all(char *page, char **start, off_t off,
- int count, int *eof, void *data);
-static int can_proc_read_rcvlist_fil(char *page, char **start, off_t off,
- int count, int *eof, void *data);
-static int can_proc_read_rcvlist_inv(char *page, char **start, off_t off,
- int count, int *eof, void *data);
-static int can_proc_read_rcvlist_sff(char *page, char **start, off_t off,
- int count, int *eof, void *data);
-static int can_proc_read_rcvlist_eff(char *page, char **start, off_t off,
- int count, int *eof, void *data);
-static int can_proc_read_rcvlist_err(char *page, char **start, off_t off,
- int count, int *eof, void *data);
-
static struct proc_dir_entry *can_dir = NULL;
static struct proc_dir_entry *pde_version = NULL;
static struct proc_dir_entry *pde_stats = NULL;
static struct proc_dir_entry *pde_rcvlist_eff = NULL;
static struct proc_dir_entry *pde_rcvlist_err = NULL;
-/*
- * can_init_proc - create main CAN proc directory and procfs entries
+/*
+ * af_can statistics stuff
*/
-void can_init_proc(void)
+
+static void can_init_stats(int caller)
{
- /* create /proc/net/can directory */
- can_dir = proc_mkdir(CAN_PROC_DIR, NULL);
+ memset(&stats, 0, sizeof(stats));
+ stats.jiffies_init = jiffies;
+ pstats.stats_reset++;
+}
- if (!can_dir) {
- printk(KERN_INFO "can: failed to create /proc/%s . "
- "CONFIG_PROC_FS missing?\n", CAN_PROC_DIR);
- return;
+static unsigned long calc_rate(unsigned long oldjif, unsigned long newjif,
+ unsigned long count)
+{
+ unsigned long ret = 0;
+
+ if (oldjif == newjif)
+ return 0;
+
+ /* see can_rcv() - this should NEVER happen! */
+ if (count > (ULONG_MAX / HZ)) {
+ printk(KERN_ERR "can: calc_rate: count exceeded! %ld\n",
+ count);
+ return 99999999;
}
- can_dir->owner = THIS_MODULE;
+ ret = (count * HZ) / (newjif - oldjif);
- /* own procfs entries from the AF_CAN core */
- pde_version = can_create_proc_readentry(
- CAN_PROC_VERSION, 0644, can_proc_read_version, NULL);
- pde_stats = can_create_proc_readentry(
- CAN_PROC_STATS, 0644, can_proc_read_stats, NULL);
- pde_reset_stats = can_create_proc_readentry(
- CAN_PROC_RESET_STATS, 0644, can_proc_read_reset_stats, NULL);
- pde_rcvlist_all = can_create_proc_readentry(
- CAN_PROC_RCVLIST_ALL, 0644, can_proc_read_rcvlist_all, NULL);
- pde_rcvlist_fil = can_create_proc_readentry(
- CAN_PROC_RCVLIST_FIL, 0644, can_proc_read_rcvlist_fil, NULL);
- pde_rcvlist_inv = can_create_proc_readentry(
- CAN_PROC_RCVLIST_INV, 0644, can_proc_read_rcvlist_inv, NULL);
- pde_rcvlist_sff = can_create_proc_readentry(
- CAN_PROC_RCVLIST_SFF, 0644, can_proc_read_rcvlist_sff, NULL);
- pde_rcvlist_eff = can_create_proc_readentry(
- CAN_PROC_RCVLIST_EFF, 0644, can_proc_read_rcvlist_eff, NULL);
- pde_rcvlist_err = can_create_proc_readentry(
- CAN_PROC_RCVLIST_ERR, 0644, can_proc_read_rcvlist_err, NULL);
+ return ret;
}
-/*
- * can_remove_proc - remove procfs entries and main CAN proc directory
- */
-void can_remove_proc(void)
+void can_stat_update(unsigned long data)
{
- if (pde_version)
- can_remove_proc_readentry(CAN_PROC_VERSION);
+ unsigned long j = jiffies; /* snapshot */
- if (pde_stats)
- can_remove_proc_readentry(CAN_PROC_STATS);
+ if (j < stats.jiffies_init) /* jiffies overflow */
+ can_init_stats(2);
- if (pde_reset_stats)
- can_remove_proc_readentry(CAN_PROC_RESET_STATS);
+ /* stats.rx_frames is the definitively max. statistic value */
- if (pde_rcvlist_all)
- can_remove_proc_readentry(CAN_PROC_RCVLIST_ALL);
+ /* prevent overflow in calc_rate() */
+ if (stats.rx_frames > (ULONG_MAX / HZ))
+ can_init_stats(3);
- if (pde_rcvlist_fil)
- can_remove_proc_readentry(CAN_PROC_RCVLIST_FIL);
+ /* matches overflow - very improbable */
+ if (stats.matches > (ULONG_MAX / 100))
+ can_init_stats(4);
- if (pde_rcvlist_inv)
- can_remove_proc_readentry(CAN_PROC_RCVLIST_INV);
+ /* calc total values */
+ if (stats.rx_frames)
+ stats.total_rx_match_ratio = (stats.matches * 100) /
+ stats.rx_frames;
- if (pde_rcvlist_sff)
- can_remove_proc_readentry(CAN_PROC_RCVLIST_SFF);
+ stats.total_tx_rate = calc_rate(stats.jiffies_init, j,
+ stats.tx_frames);
+ stats.total_rx_rate = calc_rate(stats.jiffies_init, j,
+ stats.rx_frames);
- if (pde_rcvlist_eff)
- can_remove_proc_readentry(CAN_PROC_RCVLIST_EFF);
+ /* calc current values */
+ if (stats.rx_frames_delta)
+ stats.current_rx_match_ratio =
+ (stats.matches_delta * 100) / stats.rx_frames_delta;
- if (pde_rcvlist_err)
- can_remove_proc_readentry(CAN_PROC_RCVLIST_ERR);
+ stats.current_tx_rate = calc_rate(0, HZ, stats.tx_frames_delta);
+ stats.current_rx_rate = calc_rate(0, HZ, stats.rx_frames_delta);
- if (can_dir)
- remove_proc_entry(CAN_PROC_DIR, NULL);
+ /* check / update maximum values */
+ if (stats.max_tx_rate < stats.current_tx_rate)
+ stats.max_tx_rate = stats.current_tx_rate;
+
+ if (stats.max_rx_rate < stats.current_rx_rate)
+ stats.max_rx_rate = stats.current_rx_rate;
+
+ if (stats.max_rx_match_ratio < stats.current_rx_match_ratio)
+ stats.max_rx_match_ratio = stats.current_rx_match_ratio;
+
+ /* clear values for 'current rate' calculation */
+ stats.tx_frames_delta = 0;
+ stats.rx_frames_delta = 0;
+ stats.matches_delta = 0;
+
+ /* restart timer */
+ stattimer.expires = jiffies + HZ; /* every second */
+ add_timer(&stattimer);
}
/*
remove_proc_entry(name, can_dir);
}
-static unsigned long calc_rate(unsigned long oldjif, unsigned long newjif,
- unsigned long count)
+/*
+ * can_init_proc - create main CAN proc directory and procfs entries
+ */
+void can_init_proc(void)
{
- unsigned long ret = 0;
-
- if (oldjif == newjif)
- return 0;
+ /* create /proc/net/can directory */
+ can_dir = proc_mkdir(CAN_PROC_DIR, NULL);
- /* see can_rcv() - this should NEVER happen! */
- if (count > (ULONG_MAX / HZ)) {
- printk(KERN_ERR "can: calc_rate: count exceeded! %ld\n",
- count);
- return 99999999;
+ if (!can_dir) {
+ printk(KERN_INFO "can: failed to create /proc/%s . "
+ "CONFIG_PROC_FS missing?\n", CAN_PROC_DIR);
+ return;
}
- ret = (count * HZ) / (newjif - oldjif);
+ can_dir->owner = THIS_MODULE;
- return ret;
+ /* own procfs entries from the AF_CAN core */
+ pde_version = can_create_proc_readentry(
+ CAN_PROC_VERSION, 0644, can_proc_read_version, NULL);
+ pde_stats = can_create_proc_readentry(
+ CAN_PROC_STATS, 0644, can_proc_read_stats, NULL);
+ pde_reset_stats = can_create_proc_readentry(
+ CAN_PROC_RESET_STATS, 0644, can_proc_read_reset_stats, NULL);
+ pde_rcvlist_all = can_create_proc_readentry(
+ CAN_PROC_RCVLIST_ALL, 0644, can_proc_read_rcvlist_all, NULL);
+ pde_rcvlist_fil = can_create_proc_readentry(
+ CAN_PROC_RCVLIST_FIL, 0644, can_proc_read_rcvlist_fil, NULL);
+ pde_rcvlist_inv = can_create_proc_readentry(
+ CAN_PROC_RCVLIST_INV, 0644, can_proc_read_rcvlist_inv, NULL);
+ pde_rcvlist_sff = can_create_proc_readentry(
+ CAN_PROC_RCVLIST_SFF, 0644, can_proc_read_rcvlist_sff, NULL);
+ pde_rcvlist_eff = can_create_proc_readentry(
+ CAN_PROC_RCVLIST_EFF, 0644, can_proc_read_rcvlist_eff, NULL);
+ pde_rcvlist_err = can_create_proc_readentry(
+ CAN_PROC_RCVLIST_ERR, 0644, can_proc_read_rcvlist_err, NULL);
}
-/*
- * af_can statistics stuff
+/*
+ * can_remove_proc - remove procfs entries and main CAN proc directory
*/
-
-static void can_init_stats(int caller)
-{
- memset(&stats, 0, sizeof(stats));
- stats.jiffies_init = jiffies;
- pstats.stats_reset++;
-}
-
-void can_stat_update(unsigned long data)
+void can_remove_proc(void)
{
- unsigned long j = jiffies; /* snapshot */
-
- if (j < stats.jiffies_init) /* jiffies overflow */
- can_init_stats(2);
-
- /* stats.rx_frames is the definitively max. statistic value */
-
- /* prevent overflow in calc_rate() */
- if (stats.rx_frames > (ULONG_MAX / HZ))
- can_init_stats(3);
-
- /* matches overflow - very improbable */
- if (stats.matches > (ULONG_MAX / 100))
- can_init_stats(4);
+ if (pde_version)
+ can_remove_proc_readentry(CAN_PROC_VERSION);
- /* calc total values */
- if (stats.rx_frames)
- stats.total_rx_match_ratio = (stats.matches * 100) /
- stats.rx_frames;
+ if (pde_stats)
+ can_remove_proc_readentry(CAN_PROC_STATS);
- stats.total_tx_rate = calc_rate(stats.jiffies_init, j,
- stats.tx_frames);
- stats.total_rx_rate = calc_rate(stats.jiffies_init, j,
- stats.rx_frames);
+ if (pde_reset_stats)
+ can_remove_proc_readentry(CAN_PROC_RESET_STATS);
- /* calc current values */
- if (stats.rx_frames_delta)
- stats.current_rx_match_ratio =
- (stats.matches_delta * 100) / stats.rx_frames_delta;
+ if (pde_rcvlist_all)
+ can_remove_proc_readentry(CAN_PROC_RCVLIST_ALL);
- stats.current_tx_rate = calc_rate(0, HZ, stats.tx_frames_delta);
- stats.current_rx_rate = calc_rate(0, HZ, stats.rx_frames_delta);
+ if (pde_rcvlist_fil)
+ can_remove_proc_readentry(CAN_PROC_RCVLIST_FIL);
- /* check / update maximum values */
- if (stats.max_tx_rate < stats.current_tx_rate)
- stats.max_tx_rate = stats.current_tx_rate;
+ if (pde_rcvlist_inv)
+ can_remove_proc_readentry(CAN_PROC_RCVLIST_INV);
- if (stats.max_rx_rate < stats.current_rx_rate)
- stats.max_rx_rate = stats.current_rx_rate;
+ if (pde_rcvlist_sff)
+ can_remove_proc_readentry(CAN_PROC_RCVLIST_SFF);
- if (stats.max_rx_match_ratio < stats.current_rx_match_ratio)
- stats.max_rx_match_ratio = stats.current_rx_match_ratio;
+ if (pde_rcvlist_eff)
+ can_remove_proc_readentry(CAN_PROC_RCVLIST_EFF);
- /* clear values for 'current rate' calculation */
- stats.tx_frames_delta = 0;
- stats.rx_frames_delta = 0;
- stats.matches_delta = 0;
+ if (pde_rcvlist_err)
+ can_remove_proc_readentry(CAN_PROC_RCVLIST_ERR);
- /* restart timer */
- stattimer.expires = jiffies + HZ; /* every second */
- add_timer(&stattimer);
+ if (can_dir)
+ remove_proc_entry(CAN_PROC_DIR, NULL);
}