This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / drivers / scsi / lpfc / lpfc_compat.h
1 /*******************************************************************
2  * This file is part of the Emulex Linux Device Driver for         *
3  * Enterprise Fibre Channel Host Bus Adapters.                     *
4  * Refer to the README file included with this package for         *
5  * driver version and adapter support.                             *
6  * Copyright (C) 2004 Emulex Corporation.                          *
7  * www.emulex.com                                                  *
8  *                                                                 *
9  * This program is free software; you can redistribute it and/or   *
10  * modify it under the terms of the GNU General Public License     *
11  * as published by the Free Software Foundation; either version 2  *
12  * of the License, or (at your option) any later version.          *
13  *                                                                 *
14  * This program is distributed in the hope that it will be useful, *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of  *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   *
17  * GNU General Public License for more details, a copy of which    *
18  * can be found in the file COPYING included with this package.    *
19  *******************************************************************/
20
21 /*
22  * $Id: lpfc_compat.h 1.28 2004/11/09 14:49:24EST sf_support Exp  $
23  *
24  * This file provides macros to aid compilation in the Linux 2.4 kernel
25  * over various platform architectures.
26  */
27
28 #ifndef _H_LPFC_COMPAT
29 #define  _H_LPFC_COMPAT
30
31
32 /*******************************************************************
33 Note: HBA's SLI memory contains little-endian LW.
34 Thus to access it from a little-endian host,
35 memcpy_toio() and memcpy_fromio() can be used.
36 However on a big-endian host, copy 4 bytes at a time,
37 using writel() and readl().
38  *******************************************************************/
39
40 #if __BIG_ENDIAN
41
42 static inline void
43 lpfc_memcpy_to_slim( void *dest, void *src, unsigned int bytes)
44 {
45         uint32_t *dest32;
46         uint32_t *src32;
47         unsigned int four_bytes;
48
49
50         dest32  = (uint32_t *) dest;
51         src32  = (uint32_t *) src;
52
53         /* write input bytes, 4 bytes at a time */
54         for (four_bytes = bytes /4; four_bytes > 0; four_bytes--) {
55                 writel( *src32, dest32);
56                 readl(dest32); /* flush */
57                 dest32++;
58                 src32++;
59         }
60
61         return;
62 }
63
64 static inline void
65 lpfc_memcpy_from_slim( void *dest, void *src, unsigned int bytes)
66 {
67         uint32_t *dest32;
68         uint32_t *src32;
69         unsigned int four_bytes;
70
71
72         dest32  = (uint32_t *) dest;
73         src32  = (uint32_t *) src;
74
75         /* read input bytes, 4 bytes at a time */
76         for (four_bytes = bytes /4; four_bytes > 0; four_bytes--) {
77                 *dest32 = readl( src32);
78                 dest32++;
79                 src32++;
80         }
81
82         return;
83 }
84
85 #else
86
87 static inline void
88 lpfc_memcpy_to_slim( void *dest, void *src, unsigned int bytes)
89 {
90         /* actually returns 1 byte past dest */
91         memcpy_toio( dest, src, bytes);
92 }
93
94 static inline void
95 lpfc_memcpy_from_slim( void *dest, void *src, unsigned int bytes)
96 {
97         /* actually returns 1 byte past dest */
98         memcpy_fromio( dest, src, bytes);
99 }
100
101 #endif /* __BIG_ENDIAN */
102
103 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,6)
104 #define msleep(x) do { \
105                         set_current_state(TASK_UNINTERRUPTIBLE); \
106                         schedule_timeout((x)); \
107                 } while (0);
108 /* Provide local msecs_to_jiffies call for earlier kernels */
109 static inline unsigned long msecs_to_jiffies(const unsigned int m)
110 {
111 #if HZ <= 1000 && !(1000 % HZ)
112         return (m + (1000 / HZ) - 1) / (1000 / HZ);
113 #elif HZ > 1000 && !(HZ % 1000)
114         return m * (HZ / 1000);
115 #else
116         return (m * HZ + 999) / 1000;
117 #endif
118 }
119 #endif
120 #endif                          /*  _H_LPFC_COMPAT */