| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * This file is part of the Emulex Linux Device Driver for * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3 | * Fibre Channel Host Bus Adapters. * |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 4 | * Copyright (C) 2017 Broadcom. All Rights Reserved. The term * |
| 5 | * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. * |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 6 | * Copyright (C) 2004-2011 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * EMULEX and SLI are trademarks of Emulex. * |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 8 | * www.broadcom.com * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9 | * * |
| 10 | * This program is free software; you can redistribute it and/or * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 11 | * modify it under the terms of version 2 of the GNU General * |
| 12 | * Public License as published by the Free Software Foundation. * |
| 13 | * This program is distributed in the hope that it will be useful. * |
| 14 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 15 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 17 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 18 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 19 | * more details, a copy of which can be found in the file COPYING * |
| 20 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 21 | *******************************************************************/ |
| 22 | |
| 23 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 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 | *******************************************************************/ |
Olaf Hering | 44456d3 | 2005-07-27 11:45:17 -0700 | [diff] [blame] | 35 | #include <asm/byteorder.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 36 | |
Olaf Hering | 44456d3 | 2005-07-27 11:45:17 -0700 | [diff] [blame] | 37 | #ifdef __BIG_ENDIAN |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 38 | |
| 39 | static inline void |
| 40 | lpfc_memcpy_to_slim(void __iomem *dest, void *src, unsigned int bytes) |
| 41 | { |
| 42 | uint32_t __iomem *dest32; |
| 43 | uint32_t *src32; |
| 44 | unsigned int four_bytes; |
| 45 | |
| 46 | |
| 47 | dest32 = (uint32_t __iomem *) dest; |
| 48 | src32 = (uint32_t *) src; |
| 49 | |
| 50 | /* write input bytes, 4 bytes at a time */ |
| 51 | for (four_bytes = bytes /4; four_bytes > 0; four_bytes--) { |
| 52 | writel( *src32, dest32); |
| 53 | readl(dest32); /* flush */ |
| 54 | dest32++; |
| 55 | src32++; |
| 56 | } |
| 57 | |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | static inline void |
| 62 | lpfc_memcpy_from_slim( void *dest, void __iomem *src, unsigned int bytes) |
| 63 | { |
| 64 | uint32_t *dest32; |
| 65 | uint32_t __iomem *src32; |
| 66 | unsigned int four_bytes; |
| 67 | |
| 68 | |
| 69 | dest32 = (uint32_t *) dest; |
| 70 | src32 = (uint32_t __iomem *) src; |
| 71 | |
| 72 | /* read input bytes, 4 bytes at a time */ |
| 73 | for (four_bytes = bytes /4; four_bytes > 0; four_bytes--) { |
| 74 | *dest32 = readl( src32); |
| 75 | dest32++; |
| 76 | src32++; |
| 77 | } |
| 78 | |
| 79 | return; |
| 80 | } |
| 81 | |
| 82 | #else |
| 83 | |
| 84 | static inline void |
| 85 | lpfc_memcpy_to_slim( void __iomem *dest, void *src, unsigned int bytes) |
| 86 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 87 | /* convert bytes in argument list to word count for copy function */ |
| 88 | __iowrite32_copy(dest, src, bytes / sizeof(uint32_t)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | static inline void |
| 92 | lpfc_memcpy_from_slim( void *dest, void __iomem *src, unsigned int bytes) |
| 93 | { |
| 94 | /* actually returns 1 byte past dest */ |
| 95 | memcpy_fromio( dest, src, bytes); |
| 96 | } |
| 97 | |
| 98 | #endif /* __BIG_ENDIAN */ |