linux-bk/drivers/message/fusion/linux_compat.h
<<
>>
Prefs
   1/* drivers/message/fusion/linux_compat.h */
   2
   3#ifndef FUSION_LINUX_COMPAT_H
   4#define FUSION_LINUX_COMPAT_H
   5/*{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
   6
   7#include <linux/version.h>
   8#include <linux/config.h>
   9#include <linux/kernel.h>
  10#include <linux/pci.h>
  11
  12/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  13
  14#ifndef rwlock_init
  15#define rwlock_init(x) do { *(x) = RW_LOCK_UNLOCKED; } while(0)
  16#endif
  17
  18#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
  19#define SET_NICE(current,x)     do {(current)->nice = (x);} while (0)
  20#else
  21#define SET_NICE(current,x)
  22#endif
  23
  24#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
  25#define pci_enable_device(pdev) (0)
  26#define SCSI_DATA_UNKNOWN       0
  27#define SCSI_DATA_WRITE         1
  28#define SCSI_DATA_READ          2
  29#define SCSI_DATA_NONE          3
  30#endif
  31
  32
  33#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,4)
  34#define pci_set_dma_mask(pdev, mask)    (0)
  35#define scsi_set_pci_device(sh, pdev)   (0)
  36#endif
  37
  38#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
  39#       if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18)
  40                typedef unsigned int dma_addr_t;
  41#       endif
  42#else
  43#       if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,42)
  44                typedef unsigned int dma_addr_t;
  45#       endif
  46#endif
  47
  48#if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18)
  49/*{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  50
  51/* This block snipped from lk-2.2.18/include/linux/init.h { */
  52/*
  53 * Used for initialization calls..
  54 */
  55typedef int (*initcall_t)(void);
  56typedef void (*exitcall_t)(void);
  57
  58#define __init_call     __attribute__ ((unused,__section__ (".initcall.init")))
  59#define __exit_call     __attribute__ ((unused,__section__ (".exitcall.exit")))
  60
  61extern initcall_t __initcall_start, __initcall_end;
  62
  63#define __initcall(fn)                                                          \
  64        static initcall_t __initcall_##fn __init_call = fn
  65#define __exitcall(fn)                                                          \
  66        static exitcall_t __exitcall_##fn __exit_call = fn
  67
  68#ifdef MODULE
  69/* These macros create a dummy inline: gcc 2.9x does not count alias
  70 as usage, hence the `unused function' warning when __init functions
  71 are declared static. We use the dummy __*_module_inline functions
  72 both to kill the warning and check the type of the init/cleanup
  73 function. */
  74typedef int (*__init_module_func_t)(void);
  75typedef void (*__cleanup_module_func_t)(void);
  76#define module_init(x) \
  77        int init_module(void) __attribute__((alias(#x))); \
  78        static inline __init_module_func_t __init_module_inline(void) \
  79        { return x; }
  80#define module_exit(x) \
  81        void cleanup_module(void) __attribute__((alias(#x))); \
  82        static inline __cleanup_module_func_t __cleanup_module_inline(void) \
  83        { return x; }
  84
  85#else
  86#define module_init(x)  __initcall(x);
  87#define module_exit(x)  __exitcall(x);
  88#endif
  89/* } block snipped from lk-2.2.18/include/linux/init.h */
  90
  91/* This block snipped from lk-2.2.18/include/linux/sched.h { */
  92/*
  93 * Used prior to schedule_timeout calls..
  94 */
  95#define __set_current_state(state_value)        do { current->state = state_value; } while (0)
  96#ifdef __SMP__
  97#define set_current_state(state_value)          do { __set_current_state(state_value); mb(); } while (0)
  98#else
  99#define set_current_state(state_value)          __set_current_state(state_value)
 100#endif
 101/* } block snipped from lk-2.2.18/include/linux/sched.h */
 102
 103/* procfs compat stuff... */
 104#define proc_mkdir(x,y)                 create_proc_entry(x, S_IFDIR, y)
 105
 106/* MUTEX compat stuff... */
 107#define DECLARE_MUTEX(name)             struct semaphore name=MUTEX
 108#define DECLARE_MUTEX_LOCKED(name)      struct semaphore name=MUTEX_LOCKED
 109#define init_MUTEX(x)                   *(x)=MUTEX
 110#define init_MUTEX_LOCKED(x)            *(x)=MUTEX_LOCKED
 111
 112/* Wait queues. */
 113#define DECLARE_WAIT_QUEUE_HEAD(name)   \
 114        struct wait_queue * (name) = NULL
 115#define DECLARE_WAITQUEUE(name, task)   \
 116        struct wait_queue (name) = { (task), NULL }
 117
 118#if defined(__sparc__) && defined(__sparc_v9__)
 119/* The sparc64 ioremap implementation is wrong in 2.2.x,
 120 * but fixing it would break all of the drivers which
 121 * workaround it.  Fixed in 2.3.x onward. -DaveM
 122 */
 123#define ARCH_IOREMAP(base)      ((unsigned long) (base))
 124#else
 125#define ARCH_IOREMAP(base)      ioremap(base)
 126#endif
 127
 128/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 129#else           /* LINUX_VERSION_CODE must be >= KERNEL_VERSION(2,2,18) */
 130
 131/* No ioremap bugs in >2.3.x kernels. */
 132#define ARCH_IOREMAP(base)      ioremap(base)
 133
 134/*}-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 135#endif          /* LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18) */
 136
 137
 138/*
 139 * Inclined to use:
 140 *   #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,10)
 141 * here, but MODULE_LICENSE defined in 2.4.9-6 and 2.4.9-13
 142 * breaks the rule:-(
 143 */
 144#ifndef MODULE_LICENSE
 145#define MODULE_LICENSE(license)
 146#endif
 147
 148
 149/* PCI/driver subsystem { */
 150#ifndef pci_for_each_dev
 151#define pci_for_each_dev(dev)           for((dev)=pci_devices; (dev)!=NULL; (dev)=(dev)->next)
 152#define pci_peek_next_dev(dev)          ((dev)->next ? (dev)->next : NULL)
 153#define DEVICE_COUNT_RESOURCE           6
 154#define PCI_BASEADDR_FLAGS(idx)         base_address[idx]
 155#define PCI_BASEADDR_START(idx)         base_address[idx] & ~0xFUL
 156/*
 157 * We have to keep track of the original value using
 158 * a temporary, and not by just sticking pdev->base_address[x]
 159 * back.  pdev->base_address[x] is an opaque cookie that can
 160 * be used by the PCI implementation on a given Linux port
 161 * for any purpose. -DaveM
 162 */
 163#define PCI_BASEADDR_SIZE(__pdev, __idx) \
 164({      unsigned int size, tmp; \
 165        pci_read_config_dword(__pdev, PCI_BASE_ADDRESS_0 + (4*(__idx)), &tmp); \
 166        pci_write_config_dword(__pdev, PCI_BASE_ADDRESS_0 + (4*(__idx)), 0xffffffff); \
 167        pci_read_config_dword(__pdev, PCI_BASE_ADDRESS_0 + (4*(__idx)), &size); \
 168        pci_write_config_dword(__pdev, PCI_BASE_ADDRESS_0 + (4*(__idx)), tmp); \
 169        (4 - size); \
 170})
 171#else
 172#define pci_peek_next_dev(dev)          ((dev) != pci_dev_g(&pci_devices) ? pci_dev_g((dev)->global_list.next) : NULL)
 173#define PCI_BASEADDR_FLAGS(idx)         resource[idx].flags
 174#define PCI_BASEADDR_START(idx)         resource[idx].start
 175#define PCI_BASEADDR_SIZE(dev,idx)      (dev)->resource[idx].end - (dev)->resource[idx].start + 1
 176#endif          /* } ifndef pci_for_each_dev */
 177
 178
 179/* Compatability for the 2.3.x PCI DMA API. */
 180#ifndef PCI_DMA_BIDIRECTIONAL
 181/*{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 182
 183#define PCI_DMA_BIDIRECTIONAL   0
 184#define PCI_DMA_TODEVICE        1
 185#define PCI_DMA_FROMDEVICE      2
 186#define PCI_DMA_NONE            3
 187
 188#ifdef __KERNEL__
 189#include <asm/page.h>
 190/* Pure 2^n version of get_order */
 191static __inline__ int __get_order(unsigned long size)
 192{
 193        int order;
 194
 195        size = (size-1) >> (PAGE_SHIFT-1);
 196        order = -1;
 197        do {
 198                size >>= 1;
 199                order++;
 200        } while (size);
 201        return order;
 202}
 203#endif
 204
 205#define pci_alloc_consistent(hwdev, size, dma_handle) \
 206({      void *__ret = (void *)__get_free_pages(GFP_ATOMIC, __get_order(size)); \
 207        if (__ret != NULL) { \
 208                memset(__ret, 0, size); \
 209                *(dma_handle) = virt_to_bus(__ret); \
 210        } \
 211        __ret; \
 212})
 213
 214#define pci_free_consistent(hwdev, size, vaddr, dma_handle) \
 215        free_pages((unsigned long)vaddr, __get_order(size))
 216
 217#define pci_map_single(hwdev, ptr, size, direction) \
 218        virt_to_bus(ptr);
 219
 220#define pci_unmap_single(hwdev, dma_addr, size, direction) \
 221        do { /* Nothing to do */ } while (0)
 222
 223#define pci_map_sg(hwdev, sg, nents, direction) (nents)
 224#define pci_unmap_sg(hwdev, sg, nents, direction) \
 225        do { /* Nothing to do */ } while(0)
 226
 227#define sg_dma_address(sg)      (virt_to_bus((sg)->address))
 228#define sg_dma_len(sg)          ((sg)->length)
 229
 230/*}-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 231#endif /* PCI_DMA_BIDIRECTIONAL */
 232
 233/*
 234 *  With the new command queuing code in the SCSI mid-layer we no longer have
 235 *  to hold the io_request_lock spin lock when calling the scsi_done routine.
 236 *  For now we only do this with the 2.5.1 kernel or newer.
 237 */
 238#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,1)
 239        #define MPT_HOST_LOCK(flags)
 240        #define MPT_HOST_UNLOCK(flags)
 241#else
 242        #define MPT_HOST_LOCK(flags) \
 243                spin_lock_irqsave(&io_request_lock, flags)
 244        #define MPT_HOST_UNLOCK(flags) \
 245                spin_unlock_irqrestore(&io_request_lock, flags)
 246#endif
 247
 248/*
 249 *  We use our new error handling code if the kernel version is 2.4.18 or newer.
 250 */
 251#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,18)
 252        #define MPT_SCSI_USE_NEW_EH
 253#endif
 254
 255#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,41)
 256#define mpt_work_struct work_struct
 257#define MPT_INIT_WORK(_task, _func, _data) INIT_WORK(_task, _func, _data)
 258#else
 259#define mpt_work_struct tq_struct
 260#define MPT_INIT_WORK(_task, _func, _data) \
 261({      (_task)->sync = 0; \
 262        (_task)->routine = (_func); \
 263        (_task)->data = (void *) (_data); \
 264})
 265#endif
 266
 267#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,28)
 268#define mptscsih_sync_irq(_irq) synchronize_irq(_irq)
 269#else
 270#define mptscsih_sync_irq(_irq) synchronize_irq()
 271#endif
 272
 273
 274
 275/*}-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 276#endif /* _LINUX_COMPAT_H */
 277
 278
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.