162306a36Sopenharmony_ci/*******************************************************************
262306a36Sopenharmony_ci * This file is part of the Emulex Linux Device Driver for         *
362306a36Sopenharmony_ci * Fibre Channel Host Bus Adapters.                                *
462306a36Sopenharmony_ci * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term *
562306a36Sopenharmony_ci * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.     *
662306a36Sopenharmony_ci * Copyright (C) 2004-2011 Emulex.  All rights reserved.           *
762306a36Sopenharmony_ci * EMULEX and SLI are trademarks of Emulex.                        *
862306a36Sopenharmony_ci * www.broadcom.com                                                *
962306a36Sopenharmony_ci *                                                                 *
1062306a36Sopenharmony_ci * This program is free software; you can redistribute it and/or   *
1162306a36Sopenharmony_ci * modify it under the terms of version 2 of the GNU General       *
1262306a36Sopenharmony_ci * Public License as published by the Free Software Foundation.    *
1362306a36Sopenharmony_ci * This program is distributed in the hope that it will be useful. *
1462306a36Sopenharmony_ci * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
1562306a36Sopenharmony_ci * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
1662306a36Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
1762306a36Sopenharmony_ci * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
1862306a36Sopenharmony_ci * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
1962306a36Sopenharmony_ci * more details, a copy of which can be found in the file COPYING  *
2062306a36Sopenharmony_ci * included with this package.                                     *
2162306a36Sopenharmony_ci *******************************************************************/
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci/*
2462306a36Sopenharmony_ci * This file provides macros to aid compilation in the Linux 2.4 kernel
2562306a36Sopenharmony_ci * over various platform architectures.
2662306a36Sopenharmony_ci */
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci/*******************************************************************
2962306a36Sopenharmony_ciNote: HBA's SLI memory contains little-endian LW.
3062306a36Sopenharmony_ciThus to access it from a little-endian host,
3162306a36Sopenharmony_cimemcpy_toio() and memcpy_fromio() can be used.
3262306a36Sopenharmony_ciHowever on a big-endian host, copy 4 bytes at a time,
3362306a36Sopenharmony_ciusing writel() and readl().
3462306a36Sopenharmony_ci *******************************************************************/
3562306a36Sopenharmony_ci#include <asm/byteorder.h>
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci#ifdef __BIG_ENDIAN
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_cistatic inline void
4062306a36Sopenharmony_cilpfc_memcpy_to_slim(void __iomem *dest, void *src, unsigned int bytes)
4162306a36Sopenharmony_ci{
4262306a36Sopenharmony_ci	uint32_t __iomem *dest32;
4362306a36Sopenharmony_ci	uint32_t *src32;
4462306a36Sopenharmony_ci	unsigned int four_bytes;
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci	dest32  = (uint32_t __iomem *) dest;
4862306a36Sopenharmony_ci	src32  = (uint32_t *) src;
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci	/* write input bytes, 4 bytes at a time */
5162306a36Sopenharmony_ci	for (four_bytes = bytes /4; four_bytes > 0; four_bytes--) {
5262306a36Sopenharmony_ci		writel( *src32, dest32);
5362306a36Sopenharmony_ci		readl(dest32); /* flush */
5462306a36Sopenharmony_ci		dest32++;
5562306a36Sopenharmony_ci		src32++;
5662306a36Sopenharmony_ci	}
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci	return;
5962306a36Sopenharmony_ci}
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_cistatic inline void
6262306a36Sopenharmony_cilpfc_memcpy_from_slim( void *dest, void __iomem *src, unsigned int bytes)
6362306a36Sopenharmony_ci{
6462306a36Sopenharmony_ci	uint32_t *dest32;
6562306a36Sopenharmony_ci	uint32_t __iomem *src32;
6662306a36Sopenharmony_ci	unsigned int four_bytes;
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci	dest32  = (uint32_t *) dest;
7062306a36Sopenharmony_ci	src32  = (uint32_t __iomem *) src;
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci	/* read input bytes, 4 bytes at a time */
7362306a36Sopenharmony_ci	for (four_bytes = bytes /4; four_bytes > 0; four_bytes--) {
7462306a36Sopenharmony_ci		*dest32 = readl( src32);
7562306a36Sopenharmony_ci		dest32++;
7662306a36Sopenharmony_ci		src32++;
7762306a36Sopenharmony_ci	}
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci	return;
8062306a36Sopenharmony_ci}
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci#else
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_cistatic inline void
8562306a36Sopenharmony_cilpfc_memcpy_to_slim( void __iomem *dest, void *src, unsigned int bytes)
8662306a36Sopenharmony_ci{
8762306a36Sopenharmony_ci	/* convert bytes in argument list to word count for copy function */
8862306a36Sopenharmony_ci	__iowrite32_copy(dest, src, bytes / sizeof(uint32_t));
8962306a36Sopenharmony_ci}
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_cistatic inline void
9262306a36Sopenharmony_cilpfc_memcpy_from_slim( void *dest, void __iomem *src, unsigned int bytes)
9362306a36Sopenharmony_ci{
9462306a36Sopenharmony_ci	/* actually returns 1 byte past dest */
9562306a36Sopenharmony_ci	memcpy_fromio( dest, src, bytes);
9662306a36Sopenharmony_ci}
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ci#endif	/* __BIG_ENDIAN */
99