vserver 2.0 rc7
[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.32 2005/01/25 17:51:45EST 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 /*******************************************************************
29 Note: HBA's SLI memory contains little-endian LW.
30 Thus to access it from a little-endian host,
31 memcpy_toio() and memcpy_fromio() can be used.
32 However on a big-endian host, copy 4 bytes at a time,
33 using writel() and readl().
34  *******************************************************************/
35
36 #if __BIG_ENDIAN
37
38 static inline void
39 lpfc_memcpy_to_slim(void __iomem *dest, void *src, unsigned int bytes)
40 {
41         uint32_t __iomem *dest32;
42         uint32_t *src32;
43         unsigned int four_bytes;
44
45
46         dest32  = (uint32_t __iomem *) dest;
47         src32  = (uint32_t *) src;
48
49         /* write input bytes, 4 bytes at a time */
50         for (four_bytes = bytes /4; four_bytes > 0; four_bytes--) {
51                 writel( *src32, dest32);
52                 readl(dest32); /* flush */
53                 dest32++;
54                 src32++;
55         }
56
57         return;
58 }
59
60 static inline void
61 lpfc_memcpy_from_slim( void *dest, void __iomem *src, unsigned int bytes)
62 {
63         uint32_t *dest32;
64         uint32_t __iomem *src32;
65         unsigned int four_bytes;
66
67
68         dest32  = (uint32_t *) dest;
69         src32  = (uint32_t __iomem *) src;
70
71         /* read input bytes, 4 bytes at a time */
72         for (four_bytes = bytes /4; four_bytes > 0; four_bytes--) {
73                 *dest32 = readl( src32);
74                 dest32++;
75                 src32++;
76         }
77
78         return;
79 }
80
81 #else
82
83 static inline void
84 lpfc_memcpy_to_slim( void __iomem *dest, void *src, unsigned int bytes)
85 {
86         /* actually returns 1 byte past dest */
87         memcpy_toio( dest, src, bytes);
88 }
89
90 static inline void
91 lpfc_memcpy_from_slim( void *dest, void __iomem *src, unsigned int bytes)
92 {
93         /* actually returns 1 byte past dest */
94         memcpy_fromio( dest, src, bytes);
95 }
96
97 #endif  /* __BIG_ENDIAN */