Skip to content

Commit

Permalink
Implementation of InternetChecksum in P4TC (#4782)
Browse files Browse the repository at this point in the history
Signed-off-by: Y <komal.jain@intel.com>
  • Loading branch information
komaljai authored Jul 8, 2024
1 parent 6edb878 commit 29c5f93
Show file tree
Hide file tree
Showing 63 changed files with 1,577 additions and 391 deletions.
39 changes: 39 additions & 0 deletions backends/tc/ebpfCodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,20 @@ void EBPFPnaParser::emitRejectState(EBPF::CodeBuilder *builder) {
builder->endOfStatement(true);
}

void EBPFPnaParser::emitDeclaration(EBPF::CodeBuilder *builder, const IR::Declaration *decl) {
if (auto di = decl->to<IR::Declaration_Instance>()) {
cstring name = di->name.name;
if (EBPFObject::getTypeName(di) == "InternetChecksum") {
auto instance = new EBPFInternetChecksumPNA(program, di, name);
checksums.emplace(name, instance);
instance->emitVariables(builder);
return;
}
}

EBPFParser::emitDeclaration(builder, decl);
}

// This code is similar to compileExtractField function in PsaStateTranslationVisitor.
// Handled TC "macaddr" annotation.
void PnaStateTranslationVisitor::compileExtractField(const IR::Expression *expr,
Expand Down Expand Up @@ -1223,6 +1237,21 @@ void IngressDeparserPNA::emit(EBPF::CodeBuilder *builder) {
builder->newline();
}

void IngressDeparserPNA::emitDeclaration(EBPF::CodeBuilder *builder, const IR::Declaration *decl) {
if (auto di = decl->to<IR::Declaration_Instance>()) {
cstring name = di->name.name;

if (EBPF::EBPFObject::getTypeName(di) == "InternetChecksum") {
auto instance = new EBPFInternetChecksumPNA(program, di, name);
checksums.emplace(name, instance);
instance->emitVariables(builder);
return;
}
}

EBPFDeparser::emitDeclaration(builder, decl);
}

// =====================ConvertToEbpfPNA=============================
const PNAEbpfGenerator *ConvertToEbpfPNA::build(const IR::ToplevelBlock *tlb) {
/*
Expand Down Expand Up @@ -2277,6 +2306,16 @@ void DeparserHdrEmitTranslatorPNA::emitField(EBPF::CodeBuilder *builder, cstring
builder->newline();
}

EBPF::EBPFHashAlgorithmPSA *EBPFHashAlgorithmTypeFactoryPNA::create(
int type, const EBPF::EBPFProgram *program, cstring name) {
if (type == EBPF::EBPFHashAlgorithmPSA::HashAlgorithm::ONES_COMPLEMENT16 ||
type == EBPF::EBPFHashAlgorithmPSA::HashAlgorithm::TARGET_DEFAULT) {
return new InternetChecksumAlgorithmPNA(program, name);
}

return nullptr;
}

void CRCChecksumAlgorithmPNA::emitUpdateMethod(EBPF::CodeBuilder *builder, int crcWidth) {
// Note that this update method is optimized for our CRC16 and CRC32, custom
// version may require other method of update. When data_size <= 64 bits,
Expand Down
6 changes: 5 additions & 1 deletion backends/tc/ebpfCodeGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class EBPFPnaParser : public EBPF::EBPFPsaParser {
const P4::TypeMap *typeMap);
void emit(EBPF::CodeBuilder *builder) override;
void emitRejectState(EBPF::CodeBuilder *) override;
void emitDeclaration(EBPF::CodeBuilder *builder, const IR::Declaration *decl);

DECLARE_TYPEINFO(EBPFPnaParser, EBPF::EBPFPsaParser);
};
Expand Down Expand Up @@ -188,6 +189,7 @@ class IngressDeparserPNA : public EBPF::EBPFDeparserPSA {
bool build() override;
void emit(EBPF::CodeBuilder *builder) override;
void emitPreDeparser(EBPF::CodeBuilder *builder) override;
void emitDeclaration(EBPF::CodeBuilder *builder, const IR::Declaration *decl);

DECLARE_TYPEINFO(IngressDeparserPNA, EBPF::EBPFDeparserPSA);
};
Expand Down Expand Up @@ -441,11 +443,13 @@ class EBPFHashAlgorithmTypeFactoryPNA : public EBPF::EBPFHashAlgorithmTypeFactor
static EBPFHashAlgorithmTypeFactoryPNA factory;
return &factory;
}

void emitGlobals(EBPF::CodeBuilder *builder) {
CRC16ChecksumAlgorithmPNA::emitGlobals(builder);
CRC32ChecksumAlgorithmPNA::emitGlobals(builder);
EBPF::InternetChecksumAlgorithm::emitGlobals(builder);
}

EBPF::EBPFHashAlgorithmPSA *create(int type, const EBPF::EBPFProgram *program, cstring name);
};

} // namespace TC
Expand Down
18 changes: 13 additions & 5 deletions backends/tc/runtime/pna.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,32 +278,40 @@ bpf_p4tc_ext_csum_crc16_clear(struct p4tc_ext_csum_params *params) __ksym;
/* Basic checksums are not implemented in DPDK */
extern u32
bpf_p4tc_ext_csum_crc32_add(struct p4tc_ext_csum_params *params,
const u32 params__sz,
const void *data, const u32 data__sz) __ksym;

extern u32
bpf_p4tc_ext_csum_crc32_get(struct p4tc_ext_csum_params *params) __ksym;
bpf_p4tc_ext_csum_crc32_get(struct p4tc_ext_csum_params *params,
const u32 params__sz) __ksym;

extern void
bpf_p4tc_ext_csum_crc32_clear(struct p4tc_ext_csum_params *params) __ksym;
bpf_p4tc_ext_csum_crc32_clear(struct p4tc_ext_csum_params *params,
const u32 params__sz) __ksym;

extern u16
bpf_p4tc_ext_csum_16bit_complement_get(struct p4tc_ext_csum_params *params) __ksym;
bpf_p4tc_ext_csum_16bit_complement_get(struct p4tc_ext_csum_params *params,
const u32 params__sz) __ksym;

/* Equivalent to PNA 16bit complement checksum (incremental checksum) */
extern __wsum
bpf_p4tc_ext_csum_16bit_complement_add(struct p4tc_ext_csum_params *params,
const u32 params__sz,
const void *data, int len) __ksym;

extern int
bpf_p4tc_ext_csum_16bit_complement_sub(struct p4tc_ext_csum_params *params,
const u32 params__sz,
const void *data, const u32 data__sz) __ksym;

extern void
bpf_p4tc_ext_csum_16bit_complement_clear(struct p4tc_ext_csum_params *params) __ksym;
bpf_p4tc_ext_csum_16bit_complement_clear(struct p4tc_ext_csum_params *params,
const u32 params__sz) __ksym;

extern void
bpf_p4tc_ext_csum_16bit_complement_set_state(struct p4tc_ext_csum_params *params,
u16 csum) __ksym;
const u32 params__sz,
u16 csum) __ksym;

/* Equivalent to PNA crc16 hash */
extern u16
Expand Down
8 changes: 5 additions & 3 deletions backends/tc/tc.def
Original file line number Diff line number Diff line change
Expand Up @@ -503,12 +503,14 @@ class TCExternInstance {

if (isNumelemns) {
tcExternInstance += "\ntc_numel " + Util::toString(numelemns);
tcExternInstance += " \\";
}
if (isTablBindable) {
tcExternInstance += " tbl_bindable";
tcExternInstance += "\ntbl_bindable";
tcExternInstance += " \\";
}
if (isConstructorKeys) {
tcExternInstance += " constructor";
tcExternInstance += "\nconstructor";
for (auto field : constructorKeys) {
tcExternInstance += field->toString();
}
Expand Down Expand Up @@ -560,7 +562,7 @@ class TCExtern {
tcExtern += " numinstances " + Util::toString(numinstances);
tcExtern += " tc_acl " + acl_permisson;
if (has_exec_method) {
tcExtern += " has_exec_method ";
tcExtern += " has_exec_method";
}
for (unsigned iter = 0; iter < numinstances; iter++) {
tcExtern += "\n\n$TC p4template create extern_inst/" + pipelineName
Expand Down
Loading

0 comments on commit 29c5f93

Please sign in to comment.