1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2016-2018 Intel Corporation. 3 * Copyright(c) 2017-2018 Linaro Limited. 4 * Copyright(C) 2022 Marvell. 5 */ 6 7 #ifndef PKT_GROUP_H 8 #define PKT_GROUP_H 9 10 #define FWDSTEP 4 11 12 /* 13 * Group consecutive packets with the same destination port into one burst. 14 * To avoid extra latency this is done together with some other packet 15 * processing, but after we made a final decision about packet's destination. 16 * To do this we maintain: 17 * pnum - array of number of consecutive packets with the same dest port for 18 * each packet in the input burst. 19 * lp - pointer to the last updated element in the pnum. 20 * dlp - dest port value lp corresponds to. 21 */ 22 23 #define GRPSZ (1 << FWDSTEP) 24 #define GRPMSK (GRPSZ - 1) 25 26 #define GROUP_PORT_STEP(dlp, dcp, lp, pn, idx) do { \ 27 if (likely((dlp) == (dcp)[(idx)])) { \ 28 (lp)[0]++; \ 29 } else { \ 30 (dlp) = (dcp)[idx]; \ 31 (lp) = (pn) + (idx); \ 32 (lp)[0] = 1; \ 33 } \ 34 } while (0) 35 36 static const struct { 37 uint64_t pnum; /* prebuild 4 values for pnum[]. */ 38 int32_t idx; /* index for new last updated elemnet. */ 39 uint16_t lpv; /* add value to the last updated element. */ 40 } gptbl[GRPSZ] = { 41 { 42 /* 0: a != b, b != c, c != d, d != e */ 43 .pnum = UINT64_C(0x0001000100010001), 44 .idx = 4, 45 .lpv = 0, 46 }, 47 { 48 /* 1: a == b, b != c, c != d, d != e */ 49 .pnum = UINT64_C(0x0001000100010002), 50 .idx = 4, 51 .lpv = 1, 52 }, 53 { 54 /* 2: a != b, b == c, c != d, d != e */ 55 .pnum = UINT64_C(0x0001000100020001), 56 .idx = 4, 57 .lpv = 0, 58 }, 59 { 60 /* 3: a == b, b == c, c != d, d != e */ 61 .pnum = UINT64_C(0x0001000100020003), 62 .idx = 4, 63 .lpv = 2, 64 }, 65 { 66 /* 4: a != b, b != c, c == d, d != e */ 67 .pnum = UINT64_C(0x0001000200010001), 68 .idx = 4, 69 .lpv = 0, 70 }, 71 { 72 /* 5: a == b, b != c, c == d, d != e */ 73 .pnum = UINT64_C(0x0001000200010002), 74 .idx = 4, 75 .lpv = 1, 76 }, 77 { 78 /* 6: a != b, b == c, c == d, d != e */ 79 .pnum = UINT64_C(0x0001000200030001), 80 .idx = 4, 81 .lpv = 0, 82 }, 83 { 84 /* 7: a == b, b == c, c == d, d != e */ 85 .pnum = UINT64_C(0x0001000200030004), 86 .idx = 4, 87 .lpv = 3, 88 }, 89 { 90 /* 8: a != b, b != c, c != d, d == e */ 91 .pnum = UINT64_C(0x0002000100010001), 92 .idx = 3, 93 .lpv = 0, 94 }, 95 { 96 /* 9: a == b, b != c, c != d, d == e */ 97 .pnum = UINT64_C(0x0002000100010002), 98 .idx = 3, 99 .lpv = 1, 100 }, 101 { 102 /* 0xa: a != b, b == c, c != d, d == e */ 103 .pnum = UINT64_C(0x0002000100020001), 104 .idx = 3, 105 .lpv = 0, 106 }, 107 { 108 /* 0xb: a == b, b == c, c != d, d == e */ 109 .pnum = UINT64_C(0x0002000100020003), 110 .idx = 3, 111 .lpv = 2, 112 }, 113 { 114 /* 0xc: a != b, b != c, c == d, d == e */ 115 .pnum = UINT64_C(0x0002000300010001), 116 .idx = 2, 117 .lpv = 0, 118 }, 119 { 120 /* 0xd: a == b, b != c, c == d, d == e */ 121 .pnum = UINT64_C(0x0002000300010002), 122 .idx = 2, 123 .lpv = 1, 124 }, 125 { 126 /* 0xe: a != b, b == c, c == d, d == e */ 127 .pnum = UINT64_C(0x0002000300040001), 128 .idx = 1, 129 .lpv = 0, 130 }, 131 { 132 /* 0xf: a == b, b == c, c == d, d == e */ 133 .pnum = UINT64_C(0x0002000300040005), 134 .idx = 0, 135 .lpv = 4, 136 }, 137 }; 138 139 #endif /* PKT_GROUP_H */ 140