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 21 #define HAL_SET_FLD_SM(block, field, value) \ 22 (((value) << (block ## _ ## field ## _LSB)) & \ 23 (block ## _ ## field ## _MASK)) 24 25 #define HAL_SET_FLD_MS(block, field, value) \ 26 (((value) & (block ## _ ## field ## _MASK)) >> \ 27 (block ## _ ## field ## _LSB)) 28 29 #define HAL_CLR_FLD(desc, block, field) \ 30 do { \ 31 uint32_t val; \ 32 typeof(desc) desc_ = desc; \ 33 val = *((uint32_t *)((uint8_t *)(desc_) + \ 34 HAL_OFFSET(block, field))); \ 35 val &= ~(block ## _ ## field ## _MASK); \ 36 HAL_SET_FLD(desc_, block, field) = val; \ 37 } while (0) 38 39 #define HAL_GET_FLD(desc, block, field) \ 40 ((*((uint32_t *)((uint8_t *)(desc) + HAL_OFFSET(block, field))) & \ 41 (block ## _ ## field ## _MASK)) >> (block ## _ ## field ## _LSB)) 42 43 /** 44 * struct hal_flow_tuple_info - Hal Flow 5-tuple 45 * @dest_ip_127_96: Destination IP address bits 96-127 46 * @dest_ip_95_64: Destination IP address bits 64-95 47 * @dest_ip_63_32: Destination IP address bits 32-63 48 * @dest_ip_31_0: Destination IP address bits 0-31 49 * @src_ip_127_96: Source IP address bits 96-127 50 * @src_ip_95_64: Source IP address bits 64-95 51 * @src_ip_63_32: Source IP address bits 32-63 52 * @src_ip_31_0: Source IP address bits 0-31 53 * @dest_port: Destination Port 54 * @src_port: Source Port 55 * @l4_protocol: Layer-4 protocol type (TCP/UDP) 56 */ 57 struct hal_flow_tuple_info { 58 uint32_t dest_ip_127_96; 59 uint32_t dest_ip_95_64; 60 uint32_t dest_ip_63_32; 61 uint32_t dest_ip_31_0; 62 uint32_t src_ip_127_96; 63 uint32_t src_ip_95_64; 64 uint32_t src_ip_63_32; 65 uint32_t src_ip_31_0; 66 uint16_t dest_port; 67 uint16_t src_port; 68 uint16_t l4_protocol; 69 }; 70 71 /** 72 * key_bitwise_shift_left() - Bitwise left shift (in place) an array of bytes 73 * @key: Pointer to array to key bytes 74 * @len: size of array (number of key bytes) 75 * @shift: number of shift operations to be performed 76 * 77 * Return: 78 */ 79 static inline void 80 key_bitwise_shift_left(uint8_t *key, int len, int shift) 81 { 82 int i; 83 int next; 84 85 while (shift--) { 86 for (i = len - 1; i >= 0 ; i--) { 87 if (i > 0) 88 next = (key[i - 1] & 0x80 ? 1 : 0); 89 else 90 next = 0; 91 key[i] = (key[i] << 1) | next; 92 } 93 } 94 } 95 96 /** 97 * key_reverse() - Reverse the key buffer from MSB to LSB 98 * @dest: pointer to the destination key 99 * @src: pointer to the source key which should be shifted 100 * @len: size of key in bytes 101 * 102 * Return: 103 */ 104 static inline void 105 key_reverse(uint8_t *dest, uint8_t *src, int len) 106 { 107 int i, j; 108 109 for (i = 0, j = len - 1; i < len; i++, j--) 110 dest[i] = src[j]; 111 } 112 #endif /* HAL_FLOW_H */ 113