hal_flow.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright (c) 2019 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #ifndef __HAL_FLOW_H
  19. #define __HAL_FLOW_H
  20. #define HAL_SET_FLD_SM(block, field, value) \
  21. (((value) << (block ## _ ## field ## _LSB)) & \
  22. (block ## _ ## field ## _MASK))
  23. #define HAL_SET_FLD_MS(block, field, value) \
  24. (((value) & (block ## _ ## field ## _MASK)) >> \
  25. (block ## _ ## field ## _LSB))
  26. #define HAL_CLR_FLD(desc, block, field) \
  27. do { \
  28. uint32_t val; \
  29. typeof(desc) desc_ = desc; \
  30. val = *((uint32_t *)((uint8_t *)(desc_) + \
  31. HAL_OFFSET(block, field))); \
  32. val &= ~(block ## _ ## field ## _MASK); \
  33. HAL_SET_FLD(desc_, block, field) = val; \
  34. } while (0)
  35. #define HAL_GET_FLD(desc, block, field) \
  36. ((*((uint32_t *)((uint8_t *)(desc) + HAL_OFFSET(block, field))) & \
  37. (block ## _ ## field ## _MASK)) >> (block ## _ ## field ## _LSB))
  38. /**
  39. * struct hal_flow_tuple_info - Hal Flow 5-tuple
  40. * @dest_ip_127_96: Destination IP address bits 96-127
  41. * @dest_ip_95_64: Destination IP address bits 64-95
  42. * @dest_ip_63_32: Destination IP address bits 32-63
  43. * @dest_ip_31_0: Destination IP address bits 0-31
  44. * @src_ip_127_96: Source IP address bits 96-127
  45. * @src_ip_95_64: Source IP address bits 64-95
  46. * @src_ip_63_32: Source IP address bits 32-63
  47. * @src_ip_31_0: Source IP address bits 0-31
  48. * @dest_port: Destination Port
  49. * @src_port: Source Port
  50. * @l4_protocol: Layer-4 protocol type (TCP/UDP)
  51. */
  52. struct hal_flow_tuple_info {
  53. uint32_t dest_ip_127_96;
  54. uint32_t dest_ip_95_64;
  55. uint32_t dest_ip_63_32;
  56. uint32_t dest_ip_31_0;
  57. uint32_t src_ip_127_96;
  58. uint32_t src_ip_95_64;
  59. uint32_t src_ip_63_32;
  60. uint32_t src_ip_31_0;
  61. uint16_t dest_port;
  62. uint16_t src_port;
  63. uint16_t l4_protocol;
  64. };
  65. /**
  66. * key_bitwise_shift_left() - Bitwise left shift (in place) an array of bytes
  67. * @key: Pointer to array to key bytes
  68. * @len: size of array (number of key bytes)
  69. * @shift: number of shift operations to be performed
  70. *
  71. * Return:
  72. */
  73. static inline void
  74. key_bitwise_shift_left(uint8_t *key, int len, int shift)
  75. {
  76. int i;
  77. int next;
  78. while (shift--) {
  79. for (i = len - 1; i >= 0 ; i--) {
  80. if (i > 0)
  81. next = (key[i - 1] & 0x80 ? 1 : 0);
  82. else
  83. next = 0;
  84. key[i] = (key[i] << 1) | next;
  85. }
  86. }
  87. }
  88. /**
  89. * key_reverse() - Reverse the key buffer from MSB to LSB
  90. * @dest: pointer to the destination key
  91. * @src: pointer to the source key which should be shifted
  92. * @len: size of key in bytes
  93. *
  94. * Return:
  95. */
  96. static inline void
  97. key_reverse(uint8_t *dest, uint8_t *src, int len)
  98. {
  99. int i, j;
  100. for (i = 0, j = len - 1; i < len; i++, j--)
  101. dest[i] = src[j];
  102. }
  103. #endif /* HAL_FLOW_H */