]> rtime.felk.cvut.cz Git - socketcan-devel.git/commitdiff
Cleaned up the #ifdef KERNEL_VERSION hell:
authorhartkopp <hartkopp@030b6a49-0b11-0410-94ab-b0dab22257f2>
Mon, 22 Dec 2008 08:15:01 +0000 (08:15 +0000)
committerhartkopp <hartkopp@030b6a49-0b11-0410-94ab-b0dab22257f2>
Mon, 22 Dec 2008 08:15:01 +0000 (08:15 +0000)
bcm.c now supports Kernels 2.6.22+
bcm-prior-2-6-22.c now supports kernels below 2.6.22

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

kernel/2.6/net/can/bcm-prior-2-6-22.c
kernel/2.6/net/can/bcm.c

index 647734a49a98fb87192c4bd7edb37405c2768b43..d42823b0e7b7e63d78d01897ad2cdf47f6a74eac 100644 (file)
@@ -44,9 +44,6 @@
 #include <linux/module.h>
 #include <linux/version.h>
 #include <linux/init.h>
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-#include <linux/hrtimer.h>
-#endif
 #include <linux/list.h>
 #include <linux/proc_fs.h>
 #include <linux/uio.h>
 #include <linux/can/core.h>
 #include <linux/can/bcm.h>
 #include <net/sock.h>
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
-#include <net/net_namespace.h>
-#endif
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
 #include "compat.h"
-#endif
 
 #include <linux/can/version.h> /* for RCSID. Removed by mkpatch script */
 RCSID("$Id$");
@@ -100,14 +92,9 @@ struct bcm_op {
        int flags;
        unsigned long frames_abs, frames_filtered;
        struct timeval ival1, ival2;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-       struct hrtimer timer, thrtimer;
-       ktime_t rx_stamp, kt_ival1, kt_ival2, kt_lastmsg;
-#else
        struct timer_list timer, thrtimer;
        struct timeval rx_stamp;
        unsigned long j_ival1, j_ival2, j_lastmsg;
-#endif
        int rx_ifindex;
        int count;
        int nframes;
@@ -151,7 +138,6 @@ static inline struct bcm_sock *bcm_sk(const struct sock *sk)
 #define OPSIZ sizeof(struct bcm_op)
 #define MHSIZ sizeof(struct bcm_msg_head)
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
 /*
  * rounded_tv2jif - calculate jiffies from timeval including optional up
  * @tv: pointer to timeval
@@ -184,7 +170,6 @@ static unsigned long rounded_tv2jif(const struct timeval *tv)
 
        return jif + sec * HZ;
 }
-#endif
 
 /*
  * procfs functions
@@ -236,19 +221,6 @@ static int bcm_read_proc(char *page, char **start, off_t off,
                len += snprintf(page + len, PAGE_SIZE - len, "[%d]%c ",
                                op->nframes,
                                (op->flags & RX_CHECK_DLC)?'d':' ');
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-               if (op->kt_ival1.tv64)
-                       len += snprintf(page + len, PAGE_SIZE - len,
-                                       "timeo=%lld ",
-                                       (long long)
-                                       ktime_to_us(op->kt_ival1));
-
-               if (op->kt_ival2.tv64)
-                       len += snprintf(page + len, PAGE_SIZE - len,
-                                       "thr=%lld ",
-                                       (long long)
-                                       ktime_to_us(op->kt_ival2));
-#else
                if (op->j_ival1)
                        len += snprintf(page + len, PAGE_SIZE - len,
                                        "timeo=%ld ", op->j_ival1);
@@ -256,7 +228,6 @@ static int bcm_read_proc(char *page, char **start, off_t off,
                if (op->j_ival2)
                        len += snprintf(page + len, PAGE_SIZE - len,
                                        "thr=%ld ", op->j_ival2);
-#endif
 
                len += snprintf(page + len, PAGE_SIZE - len,
                                "# recv %ld (%ld) => reduction: ",
@@ -281,15 +252,6 @@ static int bcm_read_proc(char *page, char **start, off_t off,
                                op->can_id, bcm_proc_getifname(op->ifindex),
                                op->nframes);
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-               if (op->kt_ival1.tv64)
-                       len += snprintf(page + len, PAGE_SIZE - len, "t1=%lld ",
-                                       (long long) ktime_to_us(op->kt_ival1));
-
-               if (op->kt_ival2.tv64)
-                       len += snprintf(page + len, PAGE_SIZE - len, "t2=%lld ",
-                                       (long long) ktime_to_us(op->kt_ival2));
-#else
                if (op->j_ival1)
                        len += snprintf(page + len, PAGE_SIZE - len, "t1=%ld ",
                                        op->j_ival1);
@@ -297,7 +259,6 @@ static int bcm_read_proc(char *page, char **start, off_t off,
                if (op->j_ival2)
                        len += snprintf(page + len, PAGE_SIZE - len, "t2=%ld ",
                                        op->j_ival2);
-#endif
 
                len += snprintf(page + len, PAGE_SIZE - len, "# sent %ld\n",
                                op->frames_abs);
@@ -379,11 +340,7 @@ static void bcm_send_to_user(struct bcm_op *op, struct bcm_msg_head *head,
 
        if (head->nframes) {
                /* can_frames starting here */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-               firstframe = (struct can_frame *)skb_tail_pointer(skb);
-#else
                firstframe = (struct can_frame *)skb->tail;
-#endif
 
                memcpy(skb_put(skb, datalen), frames, datalen);
 
@@ -399,11 +356,7 @@ static void bcm_send_to_user(struct bcm_op *op, struct bcm_msg_head *head,
 
        if (has_timestamp) {
                /* restore rx timestamp */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-               skb->tstamp = op->rx_stamp;
-#else
                skb_set_timestamp(skb, &op->rx_stamp);
-#endif
        }
 
        /*
@@ -432,20 +385,11 @@ static void bcm_send_to_user(struct bcm_op *op, struct bcm_msg_head *head,
 /*
  * bcm_tx_timeout_handler - performes cyclic CAN frame transmissions
  */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-static enum hrtimer_restart bcm_tx_timeout_handler(struct hrtimer *hrtimer)
-{
-       struct bcm_op *op = container_of(hrtimer, struct bcm_op, timer);
-       enum hrtimer_restart ret = HRTIMER_NORESTART;
-
-       if (op->kt_ival1.tv64 && (op->count > 0)) {
-#else
 static void bcm_tx_timeout_handler(unsigned long data)
 {
        struct bcm_op *op = (struct bcm_op *)data;
 
        if (op->j_ival1 && (op->count > 0)) {
-#endif
 
                op->count--;
                if (!op->count && (op->flags & TX_COUNTEVT)) {
@@ -464,26 +408,6 @@ static void bcm_tx_timeout_handler(unsigned long data)
                }
        }
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-       if (op->kt_ival1.tv64 && (op->count > 0)) {
-
-               /* send (next) frame */
-               bcm_can_tx(op);
-               hrtimer_forward(hrtimer, ktime_get(), op->kt_ival1);
-               ret = HRTIMER_RESTART;
-
-       } else {
-               if (op->kt_ival2.tv64) {
-
-                       /* send (next) frame */
-                       bcm_can_tx(op);
-                       hrtimer_forward(hrtimer, ktime_get(), op->kt_ival2);
-                       ret = HRTIMER_RESTART;
-               }
-       }
-
-       return ret;
-#else
        if (op->j_ival1 && (op->count > 0)) {
 
                /* send (next) frame */
@@ -500,7 +424,6 @@ static void bcm_tx_timeout_handler(unsigned long data)
        }
 
        return;
-#endif
 }
 
 /*
@@ -510,9 +433,7 @@ static void bcm_rx_changed(struct bcm_op *op, struct can_frame *data)
 {
        struct bcm_msg_head head;
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
        op->j_lastmsg = jiffies;
-#endif
 
        /* update statistics */
        op->frames_filtered++;
@@ -532,19 +453,6 @@ static void bcm_rx_changed(struct bcm_op *op, struct can_frame *data)
        bcm_send_to_user(op, &head, data, 1);
 }
 
-#if LINUX_VERSION_CODE == KERNEL_VERSION(2,6,25)
-/* is part of linux/hrtimer.h since 2.6.26 */
-static inline int hrtimer_callback_running(struct hrtimer *timer)
-{
-       return timer->state & HRTIMER_STATE_CALLBACK;
-}
-#endif
-#if LINUX_VERSION_CODE == KERNEL_VERSION(2,6,22)
-static inline s64 ktime_us_delta(const ktime_t later, const ktime_t earlier)
-{
-       return ktime_to_us(ktime_sub(later, earlier));
-}
-#endif
 /*
  * bcm_rx_update_and_send - process a detected relevant receive content change
  *                          1. update the last received data
@@ -554,46 +462,6 @@ static void bcm_rx_update_and_send(struct bcm_op *op,
                                   struct can_frame *lastdata,
                                   struct can_frame *rxdata)
 {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-       memcpy(lastdata, rxdata, CFSIZ);
-
-       /* mark as used */
-       lastdata->can_dlc |= RX_RECV;
-
-       /* throtteling mode inactive OR data update already on the run ? */
-       if (!op->kt_ival2.tv64 || hrtimer_callback_running(&op->thrtimer)) {
-               /* send RX_CHANGED to the user immediately */
-               bcm_rx_changed(op, rxdata);
-               return;
-       }
-
-       if (hrtimer_active(&op->thrtimer)) {
-               /* mark as 'throttled' */
-               lastdata->can_dlc |= RX_THR;
-               return;
-       }
-
-       if (!op->kt_lastmsg.tv64) {
-               /* send first RX_CHANGED to the user immediately */
-               bcm_rx_changed(op, rxdata);
-               op->kt_lastmsg = ktime_get();
-               return;
-       }
-
-       if (ktime_us_delta(ktime_get(), op->kt_lastmsg) <
-           ktime_to_us(op->kt_ival2)) {
-               /* mark as 'throttled' and start timer */
-               lastdata->can_dlc |= RX_THR;
-               hrtimer_start(&op->thrtimer,
-                             ktime_add(op->kt_lastmsg, op->kt_ival2),
-                             HRTIMER_MODE_ABS);
-               return;
-       }
-
-       /* the gap was that big, that throttling was not needed here */
-       bcm_rx_changed(op, rxdata);
-       op->kt_lastmsg = ktime_get();
-#else
        unsigned long nexttx = op->j_lastmsg + op->j_ival2;
 
        memcpy(lastdata, rxdata, CFSIZ);
@@ -618,7 +486,6 @@ static void bcm_rx_update_and_send(struct bcm_op *op,
                /* send RX_CHANGED to the user immediately */
                bcm_rx_changed(op, rxdata);
        }
-#endif
 }
 
 /*
@@ -666,27 +533,16 @@ static void bcm_rx_starttimer(struct bcm_op *op)
        if (op->flags & RX_NO_AUTOTIMER)
                return;
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-       if (op->kt_ival1.tv64)
-               hrtimer_start(&op->timer, op->kt_ival1, HRTIMER_MODE_REL);
-#else
        if (op->j_ival1)
                mod_timer(&op->timer, jiffies + op->j_ival1);
-#endif
 }
 
 /*
  * bcm_rx_timeout_handler - when the (cyclic) CAN frame receiption timed out
  */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-static enum hrtimer_restart bcm_rx_timeout_handler(struct hrtimer *hrtimer)
-{
-       struct bcm_op *op = container_of(hrtimer, struct bcm_op, timer);
-#else
 static void bcm_rx_timeout_handler(unsigned long data)
 {
        struct bcm_op *op = (struct bcm_op *)data;
-#endif
        struct bcm_msg_head msg_head;
 
        msg_head.opcode  = RX_TIMEOUT;
@@ -706,10 +562,6 @@ static void bcm_rx_timeout_handler(unsigned long data)
                /* clear received can_frames to indicate 'nothing received' */
                memset(op->last_frames, 0, op->nframes * CFSIZ);
        }
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-
-       return HRTIMER_NORESTART;
-#endif
 }
 
 /*
@@ -748,21 +600,6 @@ static int bcm_rx_thr_flush(struct bcm_op *op)
  * bcm_rx_thr_handler - the time for blocked content updates is over now:
  *                      Check for throttled data and send it to the userspace
  */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-static enum hrtimer_restart bcm_rx_thr_handler(struct hrtimer *hrtimer)
-{
-       struct bcm_op *op = container_of(hrtimer, struct bcm_op, thrtimer);
-
-       if (bcm_rx_thr_flush(op)) {
-               hrtimer_forward(hrtimer, ktime_get(), op->kt_ival2);
-               return HRTIMER_RESTART;
-       } else {
-               /* rearm throttle handling */
-               op->kt_lastmsg = ktime_set(0, 0);
-               return HRTIMER_NORESTART;
-       }
-}
-#else
 static void bcm_rx_thr_handler(unsigned long data)
 {
        struct bcm_op *op = (struct bcm_op *)data;
@@ -774,7 +611,6 @@ static void bcm_rx_thr_handler(unsigned long data)
                op->thrtimer.expires = 0;
        }
 }
-#endif
 
 /*
  * bcm_rx_handler - handle a CAN frame receiption
@@ -786,20 +622,12 @@ static void bcm_rx_handler(struct sk_buff *skb, void *data)
        int i;
 
        /* disable timeout */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-       hrtimer_cancel(&op->timer);
-#else
        del_timer(&op->timer);
-#endif
 
        if (skb->len == sizeof(rxframe)) {
                memcpy(&rxframe, skb->data, sizeof(rxframe));
                /* save rx timestamp */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-               op->rx_stamp = skb->tstamp;
-#else
                skb_get_timestamp(skb, &op->rx_stamp);
-#endif
                /* save originator for recvfrom() */
                op->rx_ifindex = skb->dev->ifindex;
                /* update statistics */
@@ -872,13 +700,8 @@ static struct bcm_op *bcm_find_op(struct list_head *ops, canid_t can_id,
 
 static void bcm_remove_op(struct bcm_op *op)
 {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-       hrtimer_cancel(&op->timer);
-       hrtimer_cancel(&op->thrtimer);
-#else
        del_timer(&op->timer);
        del_timer(&op->thrtimer);
-#endif
 
        if ((op->frames) && (op->frames != &op->sframe))
                kfree(op->frames);
@@ -1087,19 +910,11 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
                op->ifindex = ifindex;
 
                /* initialize uninitialized (kzalloc) structure */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-               hrtimer_init(&op->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
-               op->timer.function = bcm_tx_timeout_handler;
-
-               /* currently unused in tx_ops */
-               hrtimer_init(&op->thrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
-#else
                setup_timer(&op->timer, bcm_tx_timeout_handler,
                            (unsigned long)op);
 
                /* currently unused in tx_ops */
                init_timer(&op->thrtimer);
-#endif
 
                /* add this bcm_op to the list of the tx_ops */
                list_add(&op->list, &bo->tx_ops);
@@ -1121,35 +936,6 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
                op->currframe = 0;
        }
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-       if (op->flags & SETTIMER) {
-               /* set timer values */
-               op->count = msg_head->count;
-               op->ival1 = msg_head->ival1;
-               op->ival2 = msg_head->ival2;
-               op->kt_ival1 = timeval_to_ktime(msg_head->ival1);
-               op->kt_ival2 = timeval_to_ktime(msg_head->ival2);
-
-               /* disable an active timer due to zero values? */
-               if (!op->kt_ival1.tv64 && !op->kt_ival2.tv64)
-                       hrtimer_cancel(&op->timer);
-       }
-
-       if ((op->flags & STARTTIMER) &&
-           ((op->kt_ival1.tv64 && op->count) || op->kt_ival2.tv64)) {
-
-               /* spec: send can_frame when starting timer */
-               op->flags |= TX_ANNOUNCE;
-
-               if (op->kt_ival1.tv64 && (op->count > 0)) {
-                       /* op->count-- is done in bcm_tx_timeout_handler */
-                       hrtimer_start(&op->timer, op->kt_ival1,
-                                     HRTIMER_MODE_REL);
-               } else
-                       hrtimer_start(&op->timer, op->kt_ival2,
-                                     HRTIMER_MODE_REL);
-       }
-#else
        if (op->flags & SETTIMER) {
                /* set timer values */
                op->count = msg_head->count;
@@ -1175,7 +961,6 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
                } else
                        mod_timer(&op->timer, jiffies + op->j_ival2);
        }
-#endif
 
        if (op->flags & TX_ANNOUNCE)
                bcm_can_tx(op);
@@ -1286,13 +1071,6 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
                op->ifindex = ifindex;
 
                /* initialize uninitialized (kzalloc) structure */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-               hrtimer_init(&op->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
-               op->timer.function = bcm_rx_timeout_handler;
-
-               hrtimer_init(&op->thrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
-               op->thrtimer.function = bcm_rx_thr_handler;
-#else
                setup_timer(&op->timer, bcm_rx_timeout_handler,
                            (unsigned long)op);
 
@@ -1302,7 +1080,6 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
 
                /* mark disabled timer */
                op->thrtimer.expires = 0;
-#endif
 
                /* add this bcm_op to the list of the rx_ops */
                list_add(&op->list, &bo->rx_ops);
@@ -1318,13 +1095,8 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
        if (op->flags & RX_RTR_FRAME) {
 
                /* no timers in RTR-mode */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-               hrtimer_cancel(&op->thrtimer);
-               hrtimer_cancel(&op->timer);
-#else
                del_timer(&op->thrtimer);
                del_timer(&op->timer);
-#endif
 
                /*
                 * funny feature in RX(!)_SETUP only for RTR-mode:
@@ -1336,32 +1108,6 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
                        op->frames[0].can_id = op->can_id & ~CAN_RTR_FLAG;
 
        } else {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-               if (op->flags & SETTIMER) {
-
-                       /* set timer value */
-                       op->ival1 = msg_head->ival1;
-                       op->ival2 = msg_head->ival2;
-                       op->kt_ival1 = timeval_to_ktime(msg_head->ival1);
-                       op->kt_ival2 = timeval_to_ktime(msg_head->ival2);
-
-                       /* disable an active timer due to zero value? */
-                       if (!op->kt_ival1.tv64)
-                               hrtimer_cancel(&op->timer);
-
-                       /*
-                        * In any case cancel the throttle timer, flush
-                        * potentially blocked msgs and reset throttle handling
-                        */
-                       op->kt_lastmsg = ktime_set(0, 0);
-                       hrtimer_cancel(&op->thrtimer);
-                       bcm_rx_thr_flush(op);
-               }
-
-               if ((op->flags & STARTTIMER) && op->kt_ival1.tv64)
-                       hrtimer_start(&op->timer, op->kt_ival1,
-                                     HRTIMER_MODE_REL);
-#else
                if (op->flags & SETTIMER) {
 
                        /* set timer value */
@@ -1385,7 +1131,6 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
 
                if ((op->flags & STARTTIMER) && op->j_ival1)
                        mod_timer(&op->timer, jiffies + op->j_ival1);
-#endif
        }
 
        /* now we can register for can_ids, if we added a new bcm_op */
@@ -1586,14 +1331,6 @@ static int bcm_notifier(struct notifier_block *nb, unsigned long msg,
        struct bcm_op *op;
        int notify_enodev = 0;
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
-       if (!net_eq(dev_net(dev), &init_net))
-               return NOTIFY_DONE;
-#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
-       if (dev->nd_net != &init_net)
-               return NOTIFY_DONE;
-#endif
-
        if (dev->type != ARPHRD_CAN)
                return NOTIFY_DONE;
 
@@ -1862,11 +1599,7 @@ static int __init bcm_module_init(void)
        }
 
        /* create /proc/net/can-bcm directory */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
-       proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
-#else
        proc_dir = proc_mkdir("can-bcm", proc_net);
-#endif
 
        if (proc_dir)
                proc_dir->owner = THIS_MODULE;
@@ -1879,11 +1612,7 @@ static void __exit bcm_module_exit(void)
        can_proto_unregister(&bcm_can_proto);
 
        if (proc_dir)
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
-               proc_net_remove(&init_net, "can-bcm");
-#else
                proc_net_remove("can-bcm");
-#endif
 }
 
 module_init(bcm_module_init);
index 647734a49a98fb87192c4bd7edb37405c2768b43..88ace425c03cbc3dce506cc2428b5f4e291b71c3 100644 (file)
@@ -44,9 +44,7 @@
 #include <linux/module.h>
 #include <linux/version.h>
 #include <linux/init.h>
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
 #include <linux/hrtimer.h>
-#endif
 #include <linux/list.h>
 #include <linux/proc_fs.h>
 #include <linux/uio.h>
@@ -100,14 +98,8 @@ struct bcm_op {
        int flags;
        unsigned long frames_abs, frames_filtered;
        struct timeval ival1, ival2;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
        struct hrtimer timer, thrtimer;
        ktime_t rx_stamp, kt_ival1, kt_ival2, kt_lastmsg;
-#else
-       struct timer_list timer, thrtimer;
-       struct timeval rx_stamp;
-       unsigned long j_ival1, j_ival2, j_lastmsg;
-#endif
        int rx_ifindex;
        int count;
        int nframes;
@@ -123,11 +115,7 @@ struct bcm_op {
 static struct proc_dir_entry *proc_dir;
 
 struct bcm_sock {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
        struct sock sk;
-#else
-       struct sock *sk;
-#endif
        int bound;
        int ifindex;
        struct notifier_block notifier;
@@ -140,52 +128,13 @@ struct bcm_sock {
 
 static inline struct bcm_sock *bcm_sk(const struct sock *sk)
 {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
        return (struct bcm_sock *)sk;
-#else
-       return (struct bcm_sock *)sk->sk_protinfo;
-#endif
 }
 
 #define CFSIZ sizeof(struct can_frame)
 #define OPSIZ sizeof(struct bcm_op)
 #define MHSIZ sizeof(struct bcm_msg_head)
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
-/*
- * rounded_tv2jif - calculate jiffies from timeval including optional up
- * @tv: pointer to timeval
- *
- * Description:
- * Unlike timeval_to_jiffies() provided in include/linux/jiffies.h, this
- * function is intentionally more relaxed on precise timer ticks to get
- * exact one jiffy for requested 1000us on a 1000HZ machine.
- * This code is to be removed when upgrading to kernel hrtimer.
- *
- * Return:
- *  calculated jiffies (max: ULONG_MAX)
- */
-static unsigned long rounded_tv2jif(const struct timeval *tv)
-{
-       unsigned long sec  = tv->tv_sec;
-       unsigned long usec = tv->tv_usec;
-       unsigned long jif;
-
-       if (sec > ULONG_MAX / HZ)
-               return ULONG_MAX;
-
-       /* round up to get at least the requested time */
-       usec += 1000000 / HZ - 1;
-
-       jif  = usec / (1000000 / HZ);
-
-       if (sec * HZ > ULONG_MAX - jif)
-               return ULONG_MAX;
-
-       return jif + sec * HZ;
-}
-#endif
-
 /*
  * procfs functions
  */
@@ -236,7 +185,6 @@ static int bcm_read_proc(char *page, char **start, off_t off,
                len += snprintf(page + len, PAGE_SIZE - len, "[%d]%c ",
                                op->nframes,
                                (op->flags & RX_CHECK_DLC)?'d':' ');
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
                if (op->kt_ival1.tv64)
                        len += snprintf(page + len, PAGE_SIZE - len,
                                        "timeo=%lld ",
@@ -248,15 +196,6 @@ static int bcm_read_proc(char *page, char **start, off_t off,
                                        "thr=%lld ",
                                        (long long)
                                        ktime_to_us(op->kt_ival2));
-#else
-               if (op->j_ival1)
-                       len += snprintf(page + len, PAGE_SIZE - len,
-                                       "timeo=%ld ", op->j_ival1);
-
-               if (op->j_ival2)
-                       len += snprintf(page + len, PAGE_SIZE - len,
-                                       "thr=%ld ", op->j_ival2);
-#endif
 
                len += snprintf(page + len, PAGE_SIZE - len,
                                "# recv %ld (%ld) => reduction: ",
@@ -281,7 +220,6 @@ static int bcm_read_proc(char *page, char **start, off_t off,
                                op->can_id, bcm_proc_getifname(op->ifindex),
                                op->nframes);
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
                if (op->kt_ival1.tv64)
                        len += snprintf(page + len, PAGE_SIZE - len, "t1=%lld ",
                                        (long long) ktime_to_us(op->kt_ival1));
@@ -289,15 +227,6 @@ static int bcm_read_proc(char *page, char **start, off_t off,
                if (op->kt_ival2.tv64)
                        len += snprintf(page + len, PAGE_SIZE - len, "t2=%lld ",
                                        (long long) ktime_to_us(op->kt_ival2));
-#else
-               if (op->j_ival1)
-                       len += snprintf(page + len, PAGE_SIZE - len, "t1=%ld ",
-                                       op->j_ival1);
-
-               if (op->j_ival2)
-                       len += snprintf(page + len, PAGE_SIZE - len, "t2=%ld ",
-                                       op->j_ival2);
-#endif
 
                len += snprintf(page + len, PAGE_SIZE - len, "# sent %ld\n",
                                op->frames_abs);
@@ -379,11 +308,7 @@ static void bcm_send_to_user(struct bcm_op *op, struct bcm_msg_head *head,
 
        if (head->nframes) {
                /* can_frames starting here */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
                firstframe = (struct can_frame *)skb_tail_pointer(skb);
-#else
-               firstframe = (struct can_frame *)skb->tail;
-#endif
 
                memcpy(skb_put(skb, datalen), frames, datalen);
 
@@ -399,11 +324,7 @@ static void bcm_send_to_user(struct bcm_op *op, struct bcm_msg_head *head,
 
        if (has_timestamp) {
                /* restore rx timestamp */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
                skb->tstamp = op->rx_stamp;
-#else
-               skb_set_timestamp(skb, &op->rx_stamp);
-#endif
        }
 
        /*
@@ -432,20 +353,12 @@ static void bcm_send_to_user(struct bcm_op *op, struct bcm_msg_head *head,
 /*
  * bcm_tx_timeout_handler - performes cyclic CAN frame transmissions
  */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
 static enum hrtimer_restart bcm_tx_timeout_handler(struct hrtimer *hrtimer)
 {
        struct bcm_op *op = container_of(hrtimer, struct bcm_op, timer);
        enum hrtimer_restart ret = HRTIMER_NORESTART;
 
        if (op->kt_ival1.tv64 && (op->count > 0)) {
-#else
-static void bcm_tx_timeout_handler(unsigned long data)
-{
-       struct bcm_op *op = (struct bcm_op *)data;
-
-       if (op->j_ival1 && (op->count > 0)) {
-#endif
 
                op->count--;
                if (!op->count && (op->flags & TX_COUNTEVT)) {
@@ -464,7 +377,6 @@ static void bcm_tx_timeout_handler(unsigned long data)
                }
        }
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
        if (op->kt_ival1.tv64 && (op->count > 0)) {
 
                /* send (next) frame */
@@ -483,24 +395,6 @@ static void bcm_tx_timeout_handler(unsigned long data)
        }
 
        return ret;
-#else
-       if (op->j_ival1 && (op->count > 0)) {
-
-               /* send (next) frame */
-               bcm_can_tx(op);
-               mod_timer(&op->timer, jiffies + op->j_ival1);
-
-       } else {
-               if (op->j_ival2) {
-
-                       /* send (next) frame */
-                       bcm_can_tx(op);
-                       mod_timer(&op->timer, jiffies + op->j_ival2);
-               }
-       }
-
-       return;
-#endif
 }
 
 /*
@@ -510,10 +404,6 @@ static void bcm_rx_changed(struct bcm_op *op, struct can_frame *data)
 {
        struct bcm_msg_head head;
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
-       op->j_lastmsg = jiffies;
-#endif
-
        /* update statistics */
        op->frames_filtered++;
 
@@ -554,7 +444,6 @@ static void bcm_rx_update_and_send(struct bcm_op *op,
                                   struct can_frame *lastdata,
                                   struct can_frame *rxdata)
 {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
        memcpy(lastdata, rxdata, CFSIZ);
 
        /* mark as used */
@@ -593,32 +482,6 @@ static void bcm_rx_update_and_send(struct bcm_op *op,
        /* the gap was that big, that throttling was not needed here */
        bcm_rx_changed(op, rxdata);
        op->kt_lastmsg = ktime_get();
-#else
-       unsigned long nexttx = op->j_lastmsg + op->j_ival2;
-
-       memcpy(lastdata, rxdata, CFSIZ);
-
-       /* mark as used */
-       lastdata->can_dlc |= RX_RECV;
-
-       /* throttle bcm_rx_changed ? */
-       if ((op->thrtimer.expires) ||
-           ((op->j_ival2) && (nexttx > jiffies))) {
-               /* we are already waiting OR we have to start waiting */
-
-               /* mark as 'throttled' */
-               lastdata->can_dlc |= RX_THR;
-
-               if (!(op->thrtimer.expires)) {
-                       /* start the timer only the first time */
-                       mod_timer(&op->thrtimer, nexttx);
-               }
-
-       } else {
-               /* send RX_CHANGED to the user immediately */
-               bcm_rx_changed(op, rxdata);
-       }
-#endif
 }
 
 /*
@@ -666,27 +529,16 @@ static void bcm_rx_starttimer(struct bcm_op *op)
        if (op->flags & RX_NO_AUTOTIMER)
                return;
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
        if (op->kt_ival1.tv64)
                hrtimer_start(&op->timer, op->kt_ival1, HRTIMER_MODE_REL);
-#else
-       if (op->j_ival1)
-               mod_timer(&op->timer, jiffies + op->j_ival1);
-#endif
 }
 
 /*
  * bcm_rx_timeout_handler - when the (cyclic) CAN frame receiption timed out
  */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
 static enum hrtimer_restart bcm_rx_timeout_handler(struct hrtimer *hrtimer)
 {
        struct bcm_op *op = container_of(hrtimer, struct bcm_op, timer);
-#else
-static void bcm_rx_timeout_handler(unsigned long data)
-{
-       struct bcm_op *op = (struct bcm_op *)data;
-#endif
        struct bcm_msg_head msg_head;
 
        msg_head.opcode  = RX_TIMEOUT;
@@ -706,10 +558,8 @@ static void bcm_rx_timeout_handler(unsigned long data)
                /* clear received can_frames to indicate 'nothing received' */
                memset(op->last_frames, 0, op->nframes * CFSIZ);
        }
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
 
        return HRTIMER_NORESTART;
-#endif
 }
 
 /*
@@ -748,7 +598,6 @@ static int bcm_rx_thr_flush(struct bcm_op *op)
  * bcm_rx_thr_handler - the time for blocked content updates is over now:
  *                      Check for throttled data and send it to the userspace
  */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
 static enum hrtimer_restart bcm_rx_thr_handler(struct hrtimer *hrtimer)
 {
        struct bcm_op *op = container_of(hrtimer, struct bcm_op, thrtimer);
@@ -762,19 +611,6 @@ static enum hrtimer_restart bcm_rx_thr_handler(struct hrtimer *hrtimer)
                return HRTIMER_NORESTART;
        }
 }
-#else
-static void bcm_rx_thr_handler(unsigned long data)
-{
-       struct bcm_op *op = (struct bcm_op *)data;
-
-       if (bcm_rx_thr_flush(op))
-               mod_timer(&op->thrtimer, jiffies + op->j_ival2);
-       else {
-               /* mark disabled / consumed timer */
-               op->thrtimer.expires = 0;
-       }
-}
-#endif
 
 /*
  * bcm_rx_handler - handle a CAN frame receiption
@@ -786,20 +622,12 @@ static void bcm_rx_handler(struct sk_buff *skb, void *data)
        int i;
 
        /* disable timeout */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
        hrtimer_cancel(&op->timer);
-#else
-       del_timer(&op->timer);
-#endif
 
        if (skb->len == sizeof(rxframe)) {
                memcpy(&rxframe, skb->data, sizeof(rxframe));
                /* save rx timestamp */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
                op->rx_stamp = skb->tstamp;
-#else
-               skb_get_timestamp(skb, &op->rx_stamp);
-#endif
                /* save originator for recvfrom() */
                op->rx_ifindex = skb->dev->ifindex;
                /* update statistics */
@@ -872,13 +700,8 @@ static struct bcm_op *bcm_find_op(struct list_head *ops, canid_t can_id,
 
 static void bcm_remove_op(struct bcm_op *op)
 {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
        hrtimer_cancel(&op->timer);
        hrtimer_cancel(&op->thrtimer);
-#else
-       del_timer(&op->timer);
-       del_timer(&op->thrtimer);
-#endif
 
        if ((op->frames) && (op->frames != &op->sframe))
                kfree(op->frames);
@@ -1087,19 +910,11 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
                op->ifindex = ifindex;
 
                /* initialize uninitialized (kzalloc) structure */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
                hrtimer_init(&op->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
                op->timer.function = bcm_tx_timeout_handler;
 
                /* currently unused in tx_ops */
                hrtimer_init(&op->thrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
-#else
-               setup_timer(&op->timer, bcm_tx_timeout_handler,
-                           (unsigned long)op);
-
-               /* currently unused in tx_ops */
-               init_timer(&op->thrtimer);
-#endif
 
                /* add this bcm_op to the list of the tx_ops */
                list_add(&op->list, &bo->tx_ops);
@@ -1121,7 +936,6 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
                op->currframe = 0;
        }
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
        if (op->flags & SETTIMER) {
                /* set timer values */
                op->count = msg_head->count;
@@ -1149,33 +963,6 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
                        hrtimer_start(&op->timer, op->kt_ival2,
                                      HRTIMER_MODE_REL);
        }
-#else
-       if (op->flags & SETTIMER) {
-               /* set timer values */
-               op->count = msg_head->count;
-               op->ival1 = msg_head->ival1;
-               op->ival2 = msg_head->ival2;
-               op->j_ival1 = rounded_tv2jif(&msg_head->ival1);
-               op->j_ival2 = rounded_tv2jif(&msg_head->ival2);
-
-               /* disable an active timer due to zero values? */
-               if (!op->j_ival1 && !op->j_ival2)
-                       del_timer(&op->timer);
-       }
-
-       if ((op->flags & STARTTIMER) &&
-           ((op->j_ival1 && op->count) || op->j_ival2)) {
-
-               /* spec: send can_frame when starting timer */
-               op->flags |= TX_ANNOUNCE;
-
-               if (op->j_ival1 && (op->count > 0)) {
-                       /* op->count-- is done in bcm_tx_timeout_handler */
-                       mod_timer(&op->timer, jiffies + op->j_ival1);
-               } else
-                       mod_timer(&op->timer, jiffies + op->j_ival2);
-       }
-#endif
 
        if (op->flags & TX_ANNOUNCE)
                bcm_can_tx(op);
@@ -1286,23 +1073,11 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
                op->ifindex = ifindex;
 
                /* initialize uninitialized (kzalloc) structure */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
                hrtimer_init(&op->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
                op->timer.function = bcm_rx_timeout_handler;
 
                hrtimer_init(&op->thrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
                op->thrtimer.function = bcm_rx_thr_handler;
-#else
-               setup_timer(&op->timer, bcm_rx_timeout_handler,
-                           (unsigned long)op);
-
-               /* init throttle timer for RX_CHANGED */
-               setup_timer(&op->thrtimer, bcm_rx_thr_handler,
-                           (unsigned long)op);
-
-               /* mark disabled timer */
-               op->thrtimer.expires = 0;
-#endif
 
                /* add this bcm_op to the list of the rx_ops */
                list_add(&op->list, &bo->rx_ops);
@@ -1318,13 +1093,8 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
        if (op->flags & RX_RTR_FRAME) {
 
                /* no timers in RTR-mode */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
                hrtimer_cancel(&op->thrtimer);
                hrtimer_cancel(&op->timer);
-#else
-               del_timer(&op->thrtimer);
-               del_timer(&op->timer);
-#endif
 
                /*
                 * funny feature in RX(!)_SETUP only for RTR-mode:
@@ -1336,7 +1106,6 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
                        op->frames[0].can_id = op->can_id & ~CAN_RTR_FLAG;
 
        } else {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
                if (op->flags & SETTIMER) {
 
                        /* set timer value */
@@ -1361,31 +1130,6 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
                if ((op->flags & STARTTIMER) && op->kt_ival1.tv64)
                        hrtimer_start(&op->timer, op->kt_ival1,
                                      HRTIMER_MODE_REL);
-#else
-               if (op->flags & SETTIMER) {
-
-                       /* set timer value */
-                       op->ival1 = msg_head->ival1;
-                       op->ival2 = msg_head->ival2;
-                       op->j_ival1 = rounded_tv2jif(&msg_head->ival1);
-                       op->j_ival2 = rounded_tv2jif(&msg_head->ival2);
-
-                       /* disable an active timer due to zero value? */
-                       if (!op->j_ival1)
-                               del_timer(&op->timer);
-
-                       /*
-                        * In any case cancel the throttle timer, flush
-                        * potentially blocked msgs and reset throttle handling
-                        */
-                       del_timer(&op->thrtimer);
-                       bcm_rx_thr_flush(op);
-                       op->thrtimer.expires = 0;
-               }
-
-               if ((op->flags & STARTTIMER) && op->j_ival1)
-                       mod_timer(&op->timer, jiffies + op->j_ival1);
-#endif
        }
 
        /* now we can register for can_ids, if we added a new bcm_op */
@@ -1578,11 +1322,7 @@ static int bcm_notifier(struct notifier_block *nb, unsigned long msg,
 {
        struct net_device *dev = (struct net_device *)data;
        struct bcm_sock *bo = container_of(nb, struct bcm_sock, notifier);
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
        struct sock *sk = &bo->sk;
-#else
-       struct sock *sk = bo->sk;
-#endif
        struct bcm_op *op;
        int notify_enodev = 0;
 
@@ -1641,9 +1381,6 @@ static int bcm_init(struct sock *sk)
 {
        struct bcm_sock *bo = bcm_sk(sk);
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12)
-       bo->sk               = sk;
-#endif
        bo->bound            = 0;
        bo->ifindex          = 0;
        bo->dropped_usr_msgs = 0;
@@ -1822,7 +1559,6 @@ static struct proto_ops bcm_ops __read_mostly = {
        .sendpage      = sock_no_sendpage,
 };
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
 static struct proto bcm_proto __read_mostly = {
        .name       = "CAN_BCM",
        .owner      = THIS_MODULE,
@@ -1837,17 +1573,6 @@ static struct can_proto bcm_can_proto __read_mostly = {
        .ops        = &bcm_ops,
        .prot       = &bcm_proto,
 };
-#else
-static struct can_proto bcm_can_proto __read_mostly = {
-       .type       = SOCK_DGRAM,
-       .protocol   = CAN_BCM,
-       .capability = -1,
-       .ops        = &bcm_ops,
-       .owner      = THIS_MODULE,
-       .obj_size   = sizeof(struct bcm_sock),
-       .init       = bcm_init,
-};
-#endif
 
 static int __init bcm_module_init(void)
 {