]> rtime.felk.cvut.cz Git - socketcan-devel.git/commitdiff
Add support for seq_file in Kernels >= 2.6.26.
authorhartkopp <hartkopp@030b6a49-0b11-0410-94ab-b0dab22257f2>
Mon, 31 Aug 2009 06:26:30 +0000 (06:26 +0000)
committerhartkopp <hartkopp@030b6a49-0b11-0410-94ab-b0dab22257f2>
Mon, 31 Aug 2009 06:26:30 +0000 (06:26 +0000)
Provided by Alexey Dobriyan.

http://git.kernel.org/?p=linux/kernel/git/davem/net-next-2.6.git;a=commitdiff;h=ea00b8e2223170a842bee06e0f27754ccdf2a217

git-svn-id: svn://svn.berlios.de//socketcan/trunk@1043 030b6a49-0b11-0410-94ab-b0dab22257f2

kernel/2.6/net/can/bcm.c
kernel/2.6/net/can/proc.c

index 938d60be2cdcfa7a7607e2c4576830919686da20..97078d45a72d7cfafd547a0fe72e228b29f96bc6 100644 (file)
@@ -47,6 +47,9 @@
 #include <linux/hrtimer.h>
 #include <linux/list.h>
 #include <linux/proc_fs.h>
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
+#include <linux/seq_file.h>
+#endif
 #include <linux/uio.h>
 #include <linux/net.h>
 #include <linux/netdevice.h>
@@ -160,6 +163,84 @@ static char *bcm_proc_getifname(int ifindex)
        return "???";
 }
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
+static int bcm_proc_show(struct seq_file *m, void *v)
+{
+       struct sock *sk = (struct sock *)m->private;
+       struct bcm_sock *bo = bcm_sk(sk);
+       struct bcm_op *op;
+
+       seq_printf(m, ">>> socket %p", sk->sk_socket);
+       seq_printf(m, " / sk %p", sk);
+       seq_printf(m, " / bo %p", bo);
+       seq_printf(m, " / dropped %lu", bo->dropped_usr_msgs);
+       seq_printf(m, " / bound %s", bcm_proc_getifname(bo->ifindex));
+       seq_printf(m, " <<<\n");
+
+       list_for_each_entry(op, &bo->rx_ops, list) {
+
+               unsigned long reduction;
+
+               /* print only active entries & prevent division by zero */
+               if (!op->frames_abs)
+                       continue;
+
+               seq_printf(m, "rx_op: %03X %-5s ",
+                               op->can_id, bcm_proc_getifname(op->ifindex));
+               seq_printf(m, "[%d]%c ", op->nframes,
+                               (op->flags & RX_CHECK_DLC)?'d':' ');
+               if (op->kt_ival1.tv64)
+                       seq_printf(m, "timeo=%lld ",
+                                       (long long)
+                                       ktime_to_us(op->kt_ival1));
+
+               if (op->kt_ival2.tv64)
+                       seq_printf(m, "thr=%lld ",
+                                       (long long)
+                                       ktime_to_us(op->kt_ival2));
+
+               seq_printf(m, "# recv %ld (%ld) => reduction: ",
+                               op->frames_filtered, op->frames_abs);
+
+               reduction = 100 - (op->frames_filtered * 100) / op->frames_abs;
+
+               seq_printf(m, "%s%ld%%\n",
+                               (reduction == 100)?"near ":"", reduction);
+       }
+
+       list_for_each_entry(op, &bo->tx_ops, list) {
+
+               seq_printf(m, "tx_op: %03X %s [%d] ",
+                               op->can_id, bcm_proc_getifname(op->ifindex),
+                               op->nframes);
+
+               if (op->kt_ival1.tv64)
+                       seq_printf(m, "t1=%lld ",
+                                       (long long) ktime_to_us(op->kt_ival1));
+
+               if (op->kt_ival2.tv64)
+                       seq_printf(m, "t2=%lld ",
+                                       (long long) ktime_to_us(op->kt_ival2));
+
+               seq_printf(m, "# sent %ld\n", op->frames_abs);
+       }
+       seq_putc(m, '\n');
+       return 0;
+}
+
+static int bcm_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, bcm_proc_show, PDE(inode)->data);
+}
+
+static const struct file_operations bcm_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = bcm_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+#else
 static int bcm_read_proc(char *page, char **start, off_t off,
                         int count, int *eof, void *data)
 {
@@ -250,6 +331,7 @@ static int bcm_read_proc(char *page, char **start, off_t off,
        *eof = 1;
        return len;
 }
+#endif
 
 /*
  * bcm_can_tx - send the (next) CAN frame to the appropriate CAN interface
@@ -1547,9 +1629,15 @@ static int bcm_connect(struct socket *sock, struct sockaddr *uaddr, int len,
        if (proc_dir) {
                /* unique socket address as filename */
                sprintf(bo->procname, "%p", sock);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
+               bo->bcm_proc_read = proc_create_data(bo->procname, 0644,
+                                                    proc_dir,
+                                                    &bcm_proc_fops, sk);
+#else
                bo->bcm_proc_read = create_proc_read_entry(bo->procname, 0644,
                                                           proc_dir,
                                                           bcm_read_proc, sk);
+#endif
        }
 
        return 0;
index f6f7c8213248258cbc6b9893f681b374caaf35a3..c0910d54e83be1d490091f8046b11b4546e51bec 100644 (file)
@@ -203,6 +203,241 @@ void can_stat_update(unsigned long data)
  *
  */
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
+static void can_print_rcvlist(struct seq_file *m, struct hlist_head *rx_list,
+                             struct net_device *dev)
+{
+       struct receiver *r;
+       struct hlist_node *n;
+
+       rcu_read_lock();
+       hlist_for_each_entry_rcu(r, n, rx_list, list) {
+               char *fmt = (r->can_id & CAN_EFF_FLAG)?
+                       "   %-5s  %08X  %08x  %08x  %08x  %8ld  %s\n" :
+                       "   %-5s     %03X    %08x  %08lx  %08lx  %8ld  %s\n";
+
+               seq_printf(m, fmt, DNAME(dev), r->can_id, r->mask,
+                               (unsigned long)r->func, (unsigned long)r->data,
+                               r->matches, r->ident);
+       }
+       rcu_read_unlock();
+}
+
+static void can_print_recv_banner(struct seq_file *m)
+{
+       /*
+        *                  can1.  00000000  00000000  00000000
+        *                 .......          0  tp20
+        */
+       seq_puts(m, "  device   can_id   can_mask  function"
+                       "  userdata   matches  ident\n");
+}
+
+static int can_stats_proc_show(struct seq_file *m, void *v)
+{
+       seq_putc(m, '\n');
+       seq_printf(m, " %8ld transmitted frames (TXF)\n", can_stats.tx_frames);
+       seq_printf(m, " %8ld received frames (RXF)\n", can_stats.rx_frames);
+       seq_printf(m, " %8ld matched frames (RXMF)\n", can_stats.matches);
+
+       seq_putc(m, '\n');
+
+       if (can_stattimer.function == can_stat_update) {
+               seq_printf(m, " %8ld %% total match ratio (RXMR)\n",
+                               can_stats.total_rx_match_ratio);
+
+               seq_printf(m, " %8ld frames/s total tx rate (TXR)\n",
+                               can_stats.total_tx_rate);
+               seq_printf(m, " %8ld frames/s total rx rate (RXR)\n",
+                               can_stats.total_rx_rate);
+
+               seq_putc(m, '\n');
+
+               seq_printf(m, " %8ld %% current match ratio (CRXMR)\n",
+                               can_stats.current_rx_match_ratio);
+
+               seq_printf(m, " %8ld frames/s current tx rate (CTXR)\n",
+                               can_stats.current_tx_rate);
+               seq_printf(m, " %8ld frames/s current rx rate (CRXR)\n",
+                               can_stats.current_rx_rate);
+
+               seq_putc(m, '\n');
+
+               seq_printf(m, " %8ld %% max match ratio (MRXMR)\n",
+                               can_stats.max_rx_match_ratio);
+
+               seq_printf(m, " %8ld frames/s max tx rate (MTXR)\n",
+                               can_stats.max_tx_rate);
+               seq_printf(m, " %8ld frames/s max rx rate (MRXR)\n",
+                               can_stats.max_rx_rate);
+
+               seq_putc(m, '\n');
+       }
+
+       seq_printf(m, " %8ld current receive list entries (CRCV)\n",
+                       can_pstats.rcv_entries);
+       seq_printf(m, " %8ld maximum receive list entries (MRCV)\n",
+                       can_pstats.rcv_entries_max);
+
+       if (can_pstats.stats_reset)
+               seq_printf(m, "\n %8ld statistic resets (STR)\n",
+                               can_pstats.stats_reset);
+
+       if (can_pstats.user_reset)
+               seq_printf(m, " %8ld user statistic resets (USTR)\n",
+                               can_pstats.user_reset);
+
+       seq_putc(m, '\n');
+       return 0;
+}
+
+static int can_stats_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, can_stats_proc_show, NULL);
+}
+
+static const struct file_operations can_stats_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = can_stats_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
+static int can_reset_stats_proc_show(struct seq_file *m, void *v)
+{
+       user_reset = 1;
+
+       if (can_stattimer.function == can_stat_update) {
+               seq_printf(m, "Scheduled statistic reset #%ld.\n",
+                               can_pstats.stats_reset + 1);
+
+       } else {
+               if (can_stats.jiffies_init != jiffies)
+                       can_init_stats();
+
+               seq_printf(m, "Performed statistic reset #%ld.\n",
+                               can_pstats.stats_reset);
+       }
+       return 0;
+}
+
+static int can_reset_stats_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, can_reset_stats_proc_show, NULL);
+}
+
+static const struct file_operations can_reset_stats_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = can_reset_stats_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
+static int can_version_proc_show(struct seq_file *m, void *v)
+{
+       seq_printf(m, "%s\n", CAN_VERSION_STRING);
+       return 0;
+}
+
+static int can_version_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, can_version_proc_show, NULL);
+}
+
+static const struct file_operations can_version_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = can_version_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
+static int can_rcvlist_proc_show(struct seq_file *m, void *v)
+{
+       /* double cast to prevent GCC warning */
+       int idx = (int)(long)m->private;
+       struct dev_rcv_lists *d;
+       struct hlist_node *n;
+
+       seq_printf(m, "\nreceive list '%s':\n", rx_list_name[idx]);
+
+       rcu_read_lock();
+       hlist_for_each_entry_rcu(d, n, &can_rx_dev_list, list) {
+
+               if (!hlist_empty(&d->rx[idx])) {
+                       can_print_recv_banner(m);
+                       can_print_rcvlist(m, &d->rx[idx], d->dev);
+               } else
+                       seq_printf(m, "  (%s: no entry)\n", DNAME(d->dev));
+       }
+       rcu_read_unlock();
+
+       seq_putc(m, '\n');
+       return 0;
+}
+
+static int can_rcvlist_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, can_rcvlist_proc_show, PDE(inode)->data);
+}
+
+static const struct file_operations can_rcvlist_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = can_rcvlist_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
+static int can_rcvlist_sff_proc_show(struct seq_file *m, void *v)
+{
+       struct dev_rcv_lists *d;
+       struct hlist_node *n;
+
+       /* RX_SFF */
+       seq_puts(m, "\nreceive list 'rx_sff':\n");
+
+       rcu_read_lock();
+       hlist_for_each_entry_rcu(d, n, &can_rx_dev_list, list) {
+               int i, all_empty = 1;
+               /* check wether at least one list is non-empty */
+               for (i = 0; i < 0x800; i++)
+                       if (!hlist_empty(&d->rx_sff[i])) {
+                               all_empty = 0;
+                               break;
+                       }
+
+               if (!all_empty) {
+                       can_print_recv_banner(m);
+                       for (i = 0; i < 0x800; i++) {
+                               if (!hlist_empty(&d->rx_sff[i]))
+                                       can_print_rcvlist(m, &d->rx_sff[i],
+                                                         d->dev);
+                       }
+               } else
+                       seq_printf(m, "  (%s: no entry)\n", DNAME(d->dev));
+       }
+       rcu_read_unlock();
+
+       seq_putc(m, '\n');
+       return 0;
+}
+
+static int can_rcvlist_sff_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, can_rcvlist_sff_proc_show, NULL);
+}
+
+static const struct file_operations can_rcvlist_sff_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = can_rcvlist_sff_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+#else
 static int can_print_rcvlist(char *page, int len, struct hlist_head *rx_list,
                             struct net_device *dev)
 {
@@ -443,11 +678,13 @@ static int can_proc_read_rcvlist_sff(char *page, char **start, off_t off,
        *eof = 1;
        return len;
 }
+#endif
 
 /*
  * proc utility functions
  */
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
 static struct proc_dir_entry *can_create_proc_readentry(const char *name,
                                                        mode_t mode,
                                                        read_proc_t *read_proc,
@@ -459,6 +696,7 @@ static struct proc_dir_entry *can_create_proc_readentry(const char *name,
        else
                return NULL;
 }
+#endif
 
 static void can_remove_proc_readentry(const char *name)
 {
@@ -489,6 +727,26 @@ void can_init_proc(void)
 #endif
 
        /* own procfs entries from the AF_CAN core */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
+       pde_version     = proc_create(CAN_PROC_VERSION, 0644, can_dir,
+                                     &can_version_proc_fops);
+       pde_stats       = proc_create(CAN_PROC_STATS, 0644, can_dir,
+                                     &can_stats_proc_fops);
+       pde_reset_stats = proc_create(CAN_PROC_RESET_STATS, 0644, can_dir,
+                                     &can_reset_stats_proc_fops);
+       pde_rcvlist_err = proc_create_data(CAN_PROC_RCVLIST_ERR, 0644, can_dir,
+                                          &can_rcvlist_proc_fops, (void *)RX_ERR);
+       pde_rcvlist_all = proc_create_data(CAN_PROC_RCVLIST_ALL, 0644, can_dir,
+                                          &can_rcvlist_proc_fops, (void *)RX_ALL);
+       pde_rcvlist_fil = proc_create_data(CAN_PROC_RCVLIST_FIL, 0644, can_dir,
+                                          &can_rcvlist_proc_fops, (void *)RX_FIL);
+       pde_rcvlist_inv = proc_create_data(CAN_PROC_RCVLIST_INV, 0644, can_dir,
+                                          &can_rcvlist_proc_fops, (void *)RX_INV);
+       pde_rcvlist_eff = proc_create_data(CAN_PROC_RCVLIST_EFF, 0644, can_dir,
+                                          &can_rcvlist_proc_fops, (void *)RX_EFF);
+       pde_rcvlist_sff = proc_create(CAN_PROC_RCVLIST_SFF, 0644, can_dir,
+                                     &can_rcvlist_sff_proc_fops);
+#else
        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,
@@ -507,6 +765,7 @@ void can_init_proc(void)
                                        can_proc_read_rcvlist, (void *)RX_EFF);
        pde_rcvlist_sff = can_create_proc_readentry(CAN_PROC_RCVLIST_SFF, 0644,
                                        can_proc_read_rcvlist_sff, NULL);
+#endif
 }
 
 /*