2 * Huawei HiNIC PCI Express Linux driver
3 * Copyright(c) 2017 Huawei Technologies Co., Ltd
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 #include <linux/kernel.h>
17 #include <linux/types.h>
18 #include <asm/byteorder.h>
20 #include "hinic_common.h"
23 * hinic_cpu_to_be32 - convert data to big endian 32 bit format
24 * @data: the data to convert
25 * @len: length of data to convert
27 void hinic_cpu_to_be32(void *data, int len)
32 len = len / sizeof(u32);
34 for (i = 0; i < len; i++) {
35 *mem = cpu_to_be32(*mem);
41 * hinic_be32_to_cpu - convert data from big endian 32 bit format
42 * @data: the data to convert
43 * @len: length of data to convert
45 void hinic_be32_to_cpu(void *data, int len)
50 len = len / sizeof(u32);
52 for (i = 0; i < len; i++) {
53 *mem = be32_to_cpu(*mem);
59 * hinic_set_sge - set dma area in scatter gather entry
60 * @sge: scatter gather entry
62 * @len: length of relevant data in the dma address
64 void hinic_set_sge(struct hinic_sge *sge, dma_addr_t addr, int len)
66 sge->hi_addr = upper_32_bits(addr);
67 sge->lo_addr = lower_32_bits(addr);
72 * hinic_sge_to_dma - get dma address from scatter gather entry
73 * @sge: scatter gather entry
75 * Return dma address of sg entry
77 dma_addr_t hinic_sge_to_dma(struct hinic_sge *sge)
79 return (dma_addr_t)((((u64)sge->hi_addr) << 32) | sge->lo_addr);