treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / net / ethernet / huawei / hinic / hinic_common.c
blob8e9b4a6c88c2c48631f72aa6da75f3b32acf67ee
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Huawei HiNIC PCI Express Linux driver
4 * Copyright(c) 2017 Huawei Technologies Co., Ltd
5 */
7 #include <linux/kernel.h>
8 #include <linux/types.h>
9 #include <asm/byteorder.h>
11 #include "hinic_common.h"
13 /**
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
17 **/
18 void hinic_cpu_to_be32(void *data, int len)
20 u32 *mem = data;
21 int i;
23 len = len / sizeof(u32);
25 for (i = 0; i < len; i++) {
26 *mem = cpu_to_be32(*mem);
27 mem++;
31 /**
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
35 **/
36 void hinic_be32_to_cpu(void *data, int len)
38 u32 *mem = data;
39 int i;
41 len = len / sizeof(u32);
43 for (i = 0; i < len; i++) {
44 *mem = be32_to_cpu(*mem);
45 mem++;
49 /**
50 * hinic_set_sge - set dma area in scatter gather entry
51 * @sge: scatter gather entry
52 * @addr: dma address
53 * @len: length of relevant data in the dma address
54 **/
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);
59 sge->len = len;
62 /**
63 * hinic_sge_to_dma - get dma address from scatter gather entry
64 * @sge: scatter gather entry
66 * Return dma address of sg entry
67 **/
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);