openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

lkm.h (5364B)


      1 /*
      2  * Copyright 2017 Broadcom
      3  * 
      4  * This program is free software; you can redistribute it and/or modify
      5  * it under the terms of the GNU General Public License, version 2, as
      6  * published by the Free Software Foundation (the "GPL").
      7  * 
      8  * This program is distributed in the hope that it will be useful, but
      9  * WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     11  * General Public License version 2 (GPLv2) for more details.
     12  * 
     13  * You should have received a copy of the GNU General Public License
     14  * version 2 (GPLv2) along with this source code.
     15  */
     16 /*
     17  * $Id: lkm.h,v 1.22 Broadcom SDK $
     18  * $Copyright: (c) 2005 Broadcom Corp.
     19  * All Rights Reserved.$
     20  */
     21 
     22 #ifndef __COMMON_LINUX_KRN_LKM_H__
     23 #define __COMMON_LINUX_KRN_LKM_H__
     24 
     25 #ifndef __KERNEL__
     26 #  define __KERNEL__
     27 #endif
     28 #ifndef MODULE
     29 #  define MODULE
     30 #endif
     31 
     32 #include <linux/init.h>
     33 #include <linux/version.h>
     34 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
     35 #include <linux/config.h>
     36 #endif
     37 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)
     38 /* The version kconfig.h became available in. */
     39 #include <linux/kconfig.h>
     40 #endif
     41 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0)
     42 #if defined(INCLUDE_KNET) && LINUX_VERSION_CODE >= KERNEL_VERSION(4,0,0)
     43 #ifdef CONFIG_NF_CONNTRACK_MODULE
     44 #include <linux/netfilter.h>
     45 #endif
     46 #endif
     47 #include <linux/slab.h>
     48 #endif
     49 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39)
     50 #include <linux/smp_lock.h>
     51 #endif
     52 #include <linux/module.h>
     53 
     54 /* Helper defines for multi-version kernel  support */
     55 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
     56 #define LKM_2_4
     57 #else
     58 #define LKM_2_6
     59 #endif
     60 
     61 #include <linux/kernel.h>   /* printk() */
     62 #include <linux/fs.h>       /* everything... */
     63 #include <linux/errno.h>    /* error codes */
     64 #include <linux/types.h>    /* size_t */
     65 #include <linux/proc_fs.h>
     66 #include <linux/fcntl.h>    /* O_ACCMODE */
     67 #include <linux/pci.h>
     68 #include <linux/interrupt.h>
     69 #include <linux/stat.h>
     70 #include <linux/sched.h>
     71 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)
     72 #include <linux/sched/signal.h>
     73 #endif
     74 #include <linux/delay.h>
     75 
     76 #include <asm/io.h>
     77 #include <asm/hardirq.h>
     78 #include <asm/uaccess.h>
     79 
     80 #ifdef CONFIG_DEVFS_FS
     81 #include <linux/devfs_fs_kernel.h>
     82 #endif
     83 
     84 #define PROC_INTERFACE_KERN_VER_3_10 (LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0))
     85 
     86 /* Compatibility Macros */
     87 
     88 #ifdef LKM_2_4
     89 
     90 #include <linux/compatmac.h>
     91 #include <linux/wrapper.h>
     92 #define LKM_MOD_PARAM(n,ot,nt,d) MODULE_PARM(n,ot)
     93 #define LKM_MOD_PARAM_ARRAY(n,ot,nt,c,d) MODULE_PARM(n,ot)
     94 #define LKM_EXPORT_SYM(s)
     95 #define _free_netdev kfree
     96 
     97 #else /* LKM_2_6 */
     98 
     99 #define LKM_MOD_PARAM(n,ot,nt,d) module_param(n,nt,d)
    100 #define LKM_MOD_PARAM_ARRAY(n,ot,nt,c,d) module_param_array(n,nt,c,d)
    101 #define LKM_EXPORT_SYM(s) EXPORT_SYMBOL(s)
    102 #define _free_netdev free_netdev
    103 
    104 #endif /* LKM_2_x */
    105 
    106 #ifndef list_for_each_safe
    107 #define list_for_each_safe(l,t,i) t = 0; list_for_each((l),(i))
    108 #endif
    109 
    110 #ifndef reparent_to_init
    111 #define reparent_to_init()
    112 #endif
    113 
    114 #ifndef MODULE_LICENSE
    115 #define MODULE_LICENSE(str)
    116 #endif
    117 
    118 #ifndef EXPORT_NO_SYMBOLS
    119 #define EXPORT_NO_SYMBOLS
    120 #endif
    121 
    122 #ifndef DEFINE_SPINLOCK
    123 #define DEFINE_SPINLOCK(_lock) spinlock_t _lock = SPIN_LOCK_UNLOCKED
    124 #endif
    125 
    126 #ifndef __SPIN_LOCK_UNLOCKED
    127 #define __SPIN_LOCK_UNLOCKED(_lock) SPIN_LOCK_UNLOCKED
    128 #endif
    129 
    130 #ifndef lock_kernel
    131 #ifdef preempt_disable
    132 #define lock_kernel() preempt_disable()
    133 #else
    134 #define lock_kernel()
    135 #endif
    136 #endif
    137 
    138 #ifndef unlock_kernel
    139 #ifdef preempt_enable
    140 #define unlock_kernel() preempt_enable()
    141 #else
    142 #define unlock_kernel()
    143 #endif
    144 #endif
    145 
    146 #ifndef init_MUTEX_LOCKED
    147 #define init_MUTEX_LOCKED(_sem) sema_init(_sem, 0)
    148 #endif
    149 
    150 #ifdef CONFIG_BCM98245
    151 #define CONFIG_BMW
    152 #endif
    153 
    154 #if PROC_INTERFACE_KERN_VER_3_10
    155 #define PROC_CREATE(_entry, _name, _acc, _path, _fops)                  \
    156     do {                                                                \
    157         _entry = proc_create(_name, _acc, _path, _fops);                \
    158     } while (0)
    159 
    160 #define PROC_CREATE_DATA(_entry, _name, _acc, _path, _fops, _data)      \
    161     do {                                                                \
    162         _entry = proc_create_data(_name, _acc, _path, _fops, _data);    \
    163     } while (0)
    164 
    165 #define PROC_PDE_DATA(_node) PDE_DATA(_node)
    166 
    167 #else
    168 #define PROC_CREATE(_entry, _name, _acc, _path, _fops)                  \
    169     do {                                                                \
    170         _entry = create_proc_entry(_name, _acc, _path);                 \
    171         if (_entry) {                                                   \
    172             _entry->proc_fops = _fops;                                  \
    173         }                                                               \
    174     } while (0)
    175 
    176 #define PROC_CREATE_DATA(_entry, _name, _acc, _path, _fops, _data)      \
    177     do {                                                                \
    178         _entry = create_proc_entry(_name, _acc, _path);                 \
    179         if (_entry) {                                                   \
    180             _entry->proc_fops = _fops;                                  \
    181             _entry->data=_data;                                         \
    182         }                                                               \
    183     } while (0)
    184 
    185 #define PROC_PDE_DATA(_node) PROC_I(_node)->pde->data
    186 #endif
    187 
    188 #endif /* __COMMON_LINUX_KRN_LKM_H__ */