P4C
The P4 Compiler
Loading...
Searching...
No Matches
mau_spec.h
1
18
19#ifndef BACKENDS_TOFINO_BF_P4C_SPECS_MAU_SPEC_H_
20#define BACKENDS_TOFINO_BF_P4C_SPECS_MAU_SPEC_H_
21
22#include "lib/bitrange.h"
23
24namespace P4::IR {
25namespace MAU {
26class Table;
27} // namespace MAU
28class Node;
29} // namespace P4::IR
30
31// device-specific parameters for MAU/PPU.
32
33struct StageUse {
34 static constexpr int MAX_LOGICAL_IDS = 16;
35 static constexpr int MAX_SRAMS = 80;
36 static constexpr int MAX_TCAMS = 24;
37 static constexpr int MAX_MAPRAMS = 48;
38 static constexpr int MAX_IXBAR_BYTES = 128;
39 static constexpr int MAX_TERNARY_GROUPS = 12;
40};
41
42class IMemSpec {
43 public:
44 virtual int rows() const = 0; // pure virtual
45 virtual int colors() const = 0; // pure virtual
46 virtual int color_bits() const = 0; // pure virtual
47 virtual int address_bits() const = 0;
48 virtual int map_table_entries() const = 0;
49};
50
51class TofinoIMemSpec : public IMemSpec {
52 int rows() const override;
53 int colors() const override;
54 int color_bits() const override;
55 int address_bits() const override;
56 int map_table_entries() const override;
57};
58
59class IXBarSpec {
60 public:
61 /* --- common --- */
62 virtual int ternaryBytesPerGroup() const = 0; // pure virtual
63 virtual int ternaryGroups() const = 0; // pure virtual
64
65 // the next two: support for "legacy code" [as of Nov. 10 2022] that gets these via IXBarSpec
66 virtual int tcam_rows() const = 0; // pure virtual
67 virtual int tcam_columns() const = 0; // pure virtual
68
69 /* --- Tofino[1, 2] --- */
70 virtual int byteGroups() const;
71 virtual int exactBytesPerGroup() const;
72 virtual int exactGroups() const;
73 virtual int fairModeHashBits() const;
74 virtual int gatewaySearchBytes() const;
75 virtual int hashDistBits() const;
76 virtual int hashDistExpandBits() const;
77 virtual int hashDistMaxMaskBits() const;
78 virtual int hashDistSlices() const;
79 virtual int hashDistUnits() const;
80 virtual int hashGroups() const;
81 virtual int hashIndexGroups() const;
82 virtual int hashMatrixSize() const;
83 virtual int hashParityBit() const;
84 virtual int hashSingleBits() const;
85 virtual int hashTables() const;
86 virtual int lpfInputBytes() const;
87 virtual int maxHashBits() const;
88 virtual int meterAluHashBits() const;
89 virtual int meterAluHashParityByteStart() const;
90 virtual int meterPrecolorSize() const;
91 virtual int ramLineSelectBits() const;
92 virtual int ramSelectBitStart() const;
93 virtual int repeatingConstraintSect() const;
94 virtual int resilientModeHashBits() const;
95 virtual int ternaryBytesPerBigGroup() const;
96 virtual int tofinoMeterAluByteOffset() const;
97
98 virtual int getExactOrdBase(int group) const = 0;
99 virtual int getTernaryOrdBase(int group) const = 0;
100 virtual int exactMatchTotalBytes() const = 0;
101 virtual int ternaryMatchTotalBytes() const = 0;
102 virtual int xcmpMatchTotalBytes() const = 0;
103};
104
105// TU-local constants to avoid circular dependencies between IXBarSpec subclasses
106// and their respective MauSpec subclasses, while still preserving DRY compliance.
107static constexpr int Tofino_tcam_rows = 12;
108static constexpr int Tofino_tcam_columns = 2;
109
110class MauSpec {
111 public:
112 virtual const IXBarSpec &getIXBarSpec() const = 0; // pure virtual
113 virtual const IMemSpec &getIMemSpec() const = 0; // pure virtual
114
115 // The next 4 lines: correct data for Tof.1 + Tof.2 + Tof.3; must override elsewhere for Tof.5
116 virtual int tcam_rows() const;
117 virtual int tcam_columns() const;
118 virtual int tcam_width() const;
119 virtual int tcam_depth() const;
120};
121
122class TofinoIXBarSpec : public IXBarSpec {
123 public:
124 static constexpr int EXACT_GROUPS = 8;
125 static constexpr int EXACT_BYTES_PER_GROUP = 16;
126 static constexpr int HASH_TABLES = 16;
127 static constexpr int HASH_GROUPS = 8;
128 static constexpr int HASH_INDEX_GROUPS = 4; /* groups of 10 bits for indexing */
129 static constexpr int HASH_SINGLE_BITS = 12; /* top 12 bits of hash table individually */
130 static constexpr int HASH_PARITY_BIT = 51; /* If enabled reserved parity bit position */
131 static constexpr int RAM_SELECT_BIT_START = 40;
132 static constexpr int RAM_LINE_SELECT_BITS = 10;
133 static constexpr int HASH_MATRIX_SIZE = RAM_SELECT_BIT_START + HASH_SINGLE_BITS;
134 static constexpr int HASH_DIST_SLICES = 3;
135 static constexpr int HASH_DIST_BITS = 16;
136 static constexpr int HASH_DIST_EXPAND_BITS = 7;
137 static constexpr int HASH_DIST_MAX_MASK_BITS = HASH_DIST_BITS + HASH_DIST_EXPAND_BITS;
138 static constexpr int HASH_DIST_UNITS = 2;
139 static constexpr int TOFINO_METER_ALU_BYTE_OFFSET = 8;
140 static constexpr int LPF_INPUT_BYTES = 4;
141 static constexpr int TERNARY_GROUPS = StageUse::MAX_TERNARY_GROUPS;
142 static constexpr int BYTE_GROUPS = StageUse::MAX_TERNARY_GROUPS / 2;
143 static constexpr int TERNARY_BYTES_PER_GROUP = 5;
144 static constexpr int TERNARY_BYTES_PER_BIG_GROUP = 11;
145 static constexpr int GATEWAY_SEARCH_BYTES = 4;
146 static constexpr int RESILIENT_MODE_HASH_BITS = 51;
147 static constexpr int FAIR_MODE_HASH_BITS = 14;
148 static constexpr int METER_ALU_HASH_BITS = 52;
149 static constexpr int METER_ALU_HASH_PARITY_BYTE_START = 48;
150 static constexpr int METER_PRECOLOR_SIZE = 2;
151 static constexpr int REPEATING_CONSTRAINT_SECT = 4;
152 static constexpr int MAX_HASH_BITS = 52;
153 static constexpr P4::le_bitrange SELECT_BIT_RANGE =
154 P4::le_bitrange(RAM_SELECT_BIT_START, METER_ALU_HASH_BITS - 1);
155 static constexpr P4::le_bitrange INDEX_BIT_RANGE(int group) {
156 return {group * RAM_LINE_SELECT_BITS, (group + 1) * RAM_LINE_SELECT_BITS - 1};
157 }
158 static constexpr int INDEX_RANGE_SUBGROUP(P4::le_bitrange r) {
159 return r.lo / RAM_LINE_SELECT_BITS;
160 }
161
162 TofinoIXBarSpec();
163
164 int byteGroups() const override;
165
166 int hashDistMaxMaskBits() const override;
167
168 int hashMatrixSize() const override;
169
170 int ternaryGroups() const override;
171
172 int exactBytesPerGroup() const override;
173 int exactGroups() const override;
174 int fairModeHashBits() const override;
175 int gatewaySearchBytes() const override;
176 int hashDistBits() const override;
177 int hashDistExpandBits() const override;
178 int hashDistSlices() const override;
179 int hashDistUnits() const override;
180 int hashGroups() const override;
181
182 int hashIndexGroups() const override;
183 /* groups of 10 bits for indexing */
184
185 int hashParityBit() const override;
186 /* If enabled reserved parity bit position */
187
188 int hashSingleBits() const override;
189 /* top 12 bits of hash table individually */
190
191 int hashTables() const override;
192 int lpfInputBytes() const override;
193 int maxHashBits() const override;
194 int meterAluHashBits() const override;
195 int meterAluHashParityByteStart() const override;
196 int meterPrecolorSize() const override;
197 int ramLineSelectBits() const override;
198 int ramSelectBitStart() const override;
199 int repeatingConstraintSect() const override;
200 int resilientModeHashBits() const override;
201 int ternaryBytesPerBigGroup() const override;
202 int ternaryBytesPerGroup() const override;
203 int tofinoMeterAluByteOffset() const override;
204
205 // the next two: support for "legacy code" [as of Nov. 10 2022] that gets these via IXBarSpec
206 int tcam_rows() const override;
207 int tcam_columns() const override;
208
209 int getExactOrdBase(int group) const override;
210 int getTernaryOrdBase(int group) const override;
211
212 int exactMatchTotalBytes() const override;
213 int ternaryMatchTotalBytes() const override;
214 int xcmpMatchTotalBytes() const override;
215};
216
217class TofinoMauSpec : public MauSpec {
218 const TofinoIXBarSpec ixbar_;
219 const TofinoIMemSpec imem_;
220
221 public:
222 TofinoMauSpec() = default;
223 const IXBarSpec &getIXBarSpec() const override;
224 const IMemSpec &getIMemSpec() const override;
225};
226
227class JBayMauSpec : public MauSpec {
228 const TofinoIXBarSpec ixbar_;
229 const TofinoIMemSpec imem_;
230
231 public:
232 JBayMauSpec() = default;
233 const IXBarSpec &getIXBarSpec() const override;
234 const IMemSpec &getIMemSpec() const override;
235};
236
237#endif /* BACKENDS_TOFINO_BF_P4C_SPECS_MAU_SPEC_H_ */
Definition mau_spec.h:42
Definition mau_spec.h:59
Definition mau_spec.h:110
Definition node.h:53
Definition mau_spec.h:51
Definition mau_spec.h:122
static constexpr P4::le_bitrange SELECT_BIT_RANGE
Definition mau_spec.h:153
Definition constantParsing.h:22
int lo
Definition lib/bitrange.h:694
Definition mau_spec.h:33