hinic_common.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Huawei HiNIC PCI Express Linux driver
  3. * Copyright(c) 2017 Huawei Technologies Co., Ltd
  4. *
  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.
  8. *
  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
  12. * for more details.
  13. *
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/types.h>
  17. #include <asm/byteorder.h>
  18. #include "hinic_common.h"
  19. /**
  20. * hinic_cpu_to_be32 - convert data to big endian 32 bit format
  21. * @data: the data to convert
  22. * @len: length of data to convert
  23. **/
  24. void hinic_cpu_to_be32(void *data, int len)
  25. {
  26. u32 *mem = data;
  27. int i;
  28. len = len / sizeof(u32);
  29. for (i = 0; i < len; i++) {
  30. *mem = cpu_to_be32(*mem);
  31. mem++;
  32. }
  33. }
  34. /**
  35. * hinic_be32_to_cpu - convert data from big endian 32 bit format
  36. * @data: the data to convert
  37. * @len: length of data to convert
  38. **/
  39. void hinic_be32_to_cpu(void *data, int len)
  40. {
  41. u32 *mem = data;
  42. int i;
  43. len = len / sizeof(u32);
  44. for (i = 0; i < len; i++) {
  45. *mem = be32_to_cpu(*mem);
  46. mem++;
  47. }
  48. }
  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)
  56. {
  57. sge->hi_addr = upper_32_bits(addr);
  58. sge->lo_addr = lower_32_bits(addr);
  59. sge->len = len;
  60. }
  61. /**
  62. * hinic_sge_to_dma - get dma address from scatter gather entry
  63. * @sge: scatter gather entry
  64. *
  65. * Return dma address of sg entry
  66. **/
  67. dma_addr_t hinic_sge_to_dma(struct hinic_sge *sge)
  68. {
  69. return (dma_addr_t)((((u64)sge->hi_addr) << 32) | sge->lo_addr);
  70. }