1 // SPDX-License-Identifier: GPL-2.0-only
3 * Huawei HiNIC PCI Express Linux driver
4 * Copyright(c) 2017 Huawei Technologies Co., Ltd
7 #include <linux/kernel.h>
8 #include <linux/types.h>
9 #include <asm/byteorder.h>
11 #include "hinic_common.h"
14 * hinic_cpu_to_be32 - convert data to big endian 32 bit format
15 * @data: the data to convert
16 * @len: length of data to convert
18 void hinic_cpu_to_be32(void *data, int len)
23 len = len / sizeof(u32);
25 for (i = 0; i < len; i++) {
26 *mem = cpu_to_be32(*mem);
32 * hinic_be32_to_cpu - convert data from big endian 32 bit format
33 * @data: the data to convert
34 * @len: length of data to convert
36 void hinic_be32_to_cpu(void *data, int len)
41 len = len / sizeof(u32);
43 for (i = 0; i < len; i++) {
44 *mem = be32_to_cpu(*mem);
50 * hinic_set_sge - set dma area in scatter gather entry
51 * @sge: scatter gather entry
53 * @len: length of relevant data in the dma address
55 void hinic_set_sge(struct hinic_sge *sge, dma_addr_t addr, int len)
57 sge->hi_addr = upper_32_bits(addr);
58 sge->lo_addr = lower_32_bits(addr);
63 * hinic_sge_to_dma - get dma address from scatter gather entry
64 * @sge: scatter gather entry
66 * Return dma address of sg entry
68 dma_addr_t hinic_sge_to_dma(struct hinic_sge *sge)
70 return (dma_addr_t)((((u64)sge->hi_addr) << 32) | sge->lo_addr);