lpfc_compat.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term *
  5. * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
  6. * Copyright (C) 2004-2011 Emulex. All rights reserved. *
  7. * EMULEX and SLI are trademarks of Emulex. *
  8. * www.broadcom.com *
  9. * *
  10. * This program is free software; you can redistribute it and/or *
  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. *
  21. *******************************************************************/
  22. /*
  23. * This file provides macros to aid compilation in the Linux 2.4 kernel
  24. * over various platform architectures.
  25. */
  26. /*******************************************************************
  27. Note: HBA's SLI memory contains little-endian LW.
  28. Thus to access it from a little-endian host,
  29. memcpy_toio() and memcpy_fromio() can be used.
  30. However on a big-endian host, copy 4 bytes at a time,
  31. using writel() and readl().
  32. *******************************************************************/
  33. #include <asm/byteorder.h>
  34. #ifdef __BIG_ENDIAN
  35. static inline void
  36. lpfc_memcpy_to_slim(void __iomem *dest, void *src, unsigned int bytes)
  37. {
  38. uint32_t __iomem *dest32;
  39. uint32_t *src32;
  40. unsigned int four_bytes;
  41. dest32 = (uint32_t __iomem *) dest;
  42. src32 = (uint32_t *) src;
  43. /* write input bytes, 4 bytes at a time */
  44. for (four_bytes = bytes /4; four_bytes > 0; four_bytes--) {
  45. writel( *src32, dest32);
  46. readl(dest32); /* flush */
  47. dest32++;
  48. src32++;
  49. }
  50. return;
  51. }
  52. static inline void
  53. lpfc_memcpy_from_slim( void *dest, void __iomem *src, unsigned int bytes)
  54. {
  55. uint32_t *dest32;
  56. uint32_t __iomem *src32;
  57. unsigned int four_bytes;
  58. dest32 = (uint32_t *) dest;
  59. src32 = (uint32_t __iomem *) src;
  60. /* read input bytes, 4 bytes at a time */
  61. for (four_bytes = bytes /4; four_bytes > 0; four_bytes--) {
  62. *dest32 = readl( src32);
  63. dest32++;
  64. src32++;
  65. }
  66. return;
  67. }
  68. #else
  69. static inline void
  70. lpfc_memcpy_to_slim( void __iomem *dest, void *src, unsigned int bytes)
  71. {
  72. /* convert bytes in argument list to word count for copy function */
  73. __iowrite32_copy(dest, src, bytes / sizeof(uint32_t));
  74. }
  75. static inline void
  76. lpfc_memcpy_from_slim( void *dest, void __iomem *src, unsigned int bytes)
  77. {
  78. /* actually returns 1 byte past dest */
  79. memcpy_fromio( dest, src, bytes);
  80. }
  81. #endif /* __BIG_ENDIAN */