Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of InternetChecksum in P4TC #4782

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
komaljai marked this conversation as resolved.
Show resolved Hide resolved

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);
komaljai marked this conversation as resolved.
Show resolved Hide resolved

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
Loading