P4C
The P4 Compiler
Loading...
Searching...
No Matches
parde_spec.h
1
18
19#ifndef BACKENDS_TOFINO_BF_P4C_SPECS_PARDE_SPEC_H_
20#define BACKENDS_TOFINO_BF_P4C_SPECS_PARDE_SPEC_H_
21
22#include <map>
23#include <unordered_set>
24#include <vector>
25
26#include "backends/tofino/bf-p4c/ir/bitrange.h"
27#include "backends/tofino/bf-p4c/specs/gress.h"
28#include "backends/tofino/bf-p4c/specs/match_register_spec.h"
29
30using namespace P4::literals;
31
378
380 public:
383 size_t byteIngressIntrinsicMetadataSize() const { return 8; }
384
388 virtual size_t bytePhase0Size() const = 0;
389 size_t bitPhase0Size() const { return bytePhase0Size() * 8; }
390
392 size_t bitResubmitTagSize() const { return 8; }
393 size_t byteResubmitTagSize() const { return 1; }
394
396 size_t bitResubmitSize() const { return bitPhase0Size(); }
397 size_t byteResubmitSize() const { return bytePhase0Size(); }
398
401 virtual size_t byteIngressPrePacketPaddingSize() const = 0;
402 size_t bitIngressPrePacketPaddingSize() const { return byteIngressPrePacketPaddingSize() * 8; }
403
409
411 int byteInputBufferSize() const { return 32; }
412
416
420 virtual const std::map<unsigned, unsigned> &extractorSpec() const = 0;
421
423 virtual const std::vector<MatchRegisterSpec> matchRegisters() const = 0;
424
426 virtual const std::vector<MatchRegisterSpec> scratchRegisters() const = 0;
427
428 // Region in the input buffer where the specified scratch register is located.
429 virtual const nw_bitrange bitScratchRegisterRange(const MatchRegisterSpec &reg) const = 0;
430
431 // Verifies if the provided range is a valid scratch register location.
432 virtual bool byteScratchRegisterRangeValid(nw_byterange range) const = 0;
433
435 virtual int numParsers() const = 0;
436
438 virtual int numTcamRows() const = 0;
439
441 virtual unsigned maxClotsPerState() const = 0;
442
444 virtual unsigned byteMaxClotSize() const = 0;
445
447 virtual unsigned numClotsPerGress() const = 0;
448
450 virtual unsigned maxClotsLivePerGress() const = 0;
451
453 virtual unsigned byteInterClotGap() const = 0;
454
456 virtual unsigned bitMinClotPos(gress_t) const = 0;
457
459 virtual unsigned bitMaxClotPos() const = 0;
460
462 virtual size_t minParseDepth(gress_t) const { return 0; }
463
465 virtual size_t maxParseDepth(gress_t) const { return SIZE_MAX; }
466
468 virtual bool parserAllExtractorsSupportSingleByte() const = 0;
469
470 // Number of deparser consant bytes available
471 virtual unsigned numDeparserConstantBytes() const = 0;
472
473 // Number deparser checksum units each gress can support
474 virtual unsigned numDeparserChecksumUnits() const = 0;
475
476 // Number of deparser checksum units that can invert its output
477 virtual unsigned numDeparserInvertChecksumUnits() const = 0;
478
479 // Deparser chunk size in bytes
480 virtual unsigned deparserChunkSize() const = 0;
481
482 // Deparser group size in chunks
483 virtual unsigned deparserChunkGroupSize() const = 0;
484
485 // Number of chunk groups in deparser
486 virtual unsigned numDeparserChunkGroups() const = 0;
487
488 // Number of clots in a single chunk group in deparser
489 virtual unsigned numClotsPerDeparserGroup() const = 0;
490
492 virtual double clkFreq() const = 0;
493
495 virtual unsigned lineRate() const = 0;
496
498 virtual const std::vector<std::string> &mdpValidVecFields() const = 0;
499
501 virtual const std::unordered_set<std::string> &mdpValidVecFieldsSet() const = 0;
502};
503
505 public:
506 size_t bytePhase0Size() const override { return 8; }
507 size_t byteIngressPrePacketPaddingSize() const override { return 0; }
508
509 const std::map<unsigned, unsigned> &extractorSpec() const override {
510 static const std::map<unsigned, unsigned> extractorSpec = {{8, 4}, {16, 4}, {32, 4}};
511 return extractorSpec;
512 }
513
514 const std::vector<MatchRegisterSpec> matchRegisters() const override {
515 static std::vector<MatchRegisterSpec> spec;
516
517 if (spec.empty()) {
518 spec = {MatchRegisterSpec("half"_cs), MatchRegisterSpec("byte0"_cs),
519 MatchRegisterSpec("byte1"_cs)};
520 }
521
522 return spec;
523 }
524
525 const std::vector<MatchRegisterSpec> scratchRegisters() const override { return {}; }
526
527 const nw_bitrange bitScratchRegisterRange(const MatchRegisterSpec &reg) const override {
528 // Bug check while silencing unused variable warning.
529 BUG("Scratch registers not available in Tofino. Register: %1%", reg.name);
530 return nw_bitrange();
531 }
532
533 bool byteScratchRegisterRangeValid(nw_byterange) const override { return false; }
534
535 int numParsers() const override { return 18; }
536 int numTcamRows() const override { return 256; }
537
538 unsigned maxClotsPerState() const override { BUG("No CLOTs in Tofino"); }
539 unsigned byteMaxClotSize() const override { BUG("No CLOTs in Tofino"); }
540 unsigned numClotsPerGress() const override { return 0; }
541
542 unsigned maxClotsLivePerGress() const override { BUG("No CLOTs in Tofino"); }
543
544 unsigned byteInterClotGap() const override { BUG("No CLOTs in Tofino"); }
545
546 unsigned bitMinClotPos(gress_t) const override { BUG("No CLOTs in Tofino"); }
547 unsigned bitMaxClotPos() const override { BUG("No CLOTs in Tofino"); }
548
549 size_t minParseDepth(gress_t gress) const override { return gress == EGRESS ? 65 : 0; }
550
551 size_t maxParseDepth(gress_t gress) const override { return gress == EGRESS ? 160 : SIZE_MAX; }
552
553 bool parserAllExtractorsSupportSingleByte() const override { return false; }
554
555 unsigned numDeparserConstantBytes() const override { return 0; }
556 unsigned numDeparserChecksumUnits() const override { return 6; }
557 unsigned numDeparserInvertChecksumUnits() const override { return 0; }
558 unsigned deparserChunkSize() const override { return 0; }
559 unsigned deparserChunkGroupSize() const override { return 0; }
560 unsigned numDeparserChunkGroups() const override { return 0; }
561 unsigned numClotsPerDeparserGroup() const override { return 0; }
562
563 double clkFreq() const override { return 1.22; }
564 unsigned lineRate() const override { return 100; }
565
566 const std::vector<std::string> &mdpValidVecFields() const override {
567 static std::vector<std::string> vldVecFields;
568 return vldVecFields;
569 }
570
571 const std::unordered_set<std::string> &mdpValidVecFieldsSet() const override {
572 static std::unordered_set<std::string> vldVecSet;
573 return vldVecSet;
574 }
575};
576
577class JBayPardeSpec : public PardeSpec {
578 bool tof2lab44_workaround_;
579
580 public:
581 explicit JBayPardeSpec(bool tof2lab44_workaround)
582 : tof2lab44_workaround_(tof2lab44_workaround) {}
583 size_t bytePhase0Size() const override { return 16; }
584 size_t byteIngressPrePacketPaddingSize() const override { return 8; }
585
586 const std::map<unsigned, unsigned> &extractorSpec() const override {
587 static const std::map<unsigned, unsigned> extractorSpec = {{16, 20}};
588 return extractorSpec;
589 }
590
591 const std::vector<MatchRegisterSpec> matchRegisters() const override {
592 static std::vector<MatchRegisterSpec> spec;
593
594 if (spec.empty()) {
595 spec = {MatchRegisterSpec("byte0"_cs), MatchRegisterSpec("byte1"_cs),
596 MatchRegisterSpec("byte2"_cs), MatchRegisterSpec("byte3"_cs)};
597 }
598
599 return spec;
600 }
601
602 const std::vector<MatchRegisterSpec> scratchRegisters() const override {
603 static std::vector<MatchRegisterSpec> spec;
604
605 if (spec.empty()) {
606 matchRegisters(); // make sure the match registers are created first
607
608 spec = {MatchRegisterSpec("save_byte0"_cs), MatchRegisterSpec("save_byte1"_cs),
609 MatchRegisterSpec("save_byte2"_cs), MatchRegisterSpec("save_byte3"_cs)};
610 }
611
612 return spec;
613 }
614
615 const nw_bitrange bitScratchRegisterRange(const MatchRegisterSpec &reg) const override {
616 if (reg.name == "save_byte0")
617 return nw_bitrange(504, 511);
618 else if (reg.name == "save_byte1")
619 return nw_bitrange(496, 503);
620 else if (reg.name == "save_byte2")
621 return nw_bitrange(488, 495);
622 else if (reg.name == "save_byte3")
623 return nw_bitrange(480, 487);
624 else
625 BUG("Invalid scratch register %1%", reg.name);
626 return nw_bitrange();
627 }
628
629 bool byteScratchRegisterRangeValid(nw_byterange range) const override {
630 return (range.lo >= 60) && (range.hi <= 63);
631 }
632
633 // TBD
634 int numParsers() const override { return 36; }
635 int numTcamRows() const override { return 256; }
636
637 unsigned maxClotsPerState() const override { return 2; }
638
639 // Cap max size to 56 as a workaround of TF2LAB-44
640 unsigned byteMaxClotSize() const override { return tof2lab44_workaround_ ? 56 : 64; }
641
642 unsigned numClotsPerGress() const override { return 64; }
643 unsigned maxClotsLivePerGress() const override { return 16; }
644 unsigned byteInterClotGap() const override { return 3; }
645 unsigned bitMinClotPos(gress_t gress) const override {
646 return gress == EGRESS ? 28 * 8 : byteTotalIngressMetadataSize() * 8;
647 }
648 unsigned bitMaxClotPos() const override { return 384 * 8; /* 384 bytes */ }
649 bool parserAllExtractorsSupportSingleByte() const override { return true; }
650
651 unsigned numDeparserConstantBytes() const override { return 8; }
652 unsigned numDeparserChecksumUnits() const override { return 8; }
653 unsigned numDeparserInvertChecksumUnits() const override { return 4; }
654 unsigned deparserChunkSize() const override { return 8; }
655 unsigned deparserChunkGroupSize() const override { return 8; }
656 unsigned numDeparserChunkGroups() const override { return 16; }
657 unsigned numClotsPerDeparserGroup() const override { return 4; }
658
659 // FIXME: adjust to true clock rate
660 double clkFreq() const override { return 1.35; }
661 unsigned lineRate() const override { return 400; }
662
663 const std::vector<std::string> &mdpValidVecFields() const override {
664 static std::vector<std::string> vldVecFields;
665 return vldVecFields;
666 }
667
668 const std::unordered_set<std::string> &mdpValidVecFieldsSet() const override {
669 static std::unordered_set<std::string> vldVecSet;
670 return vldVecSet;
671 }
672};
673
674class JBayA0PardeSpec : public JBayPardeSpec {
675 public:
676 explicit JBayA0PardeSpec(bool tof2lab44_workaround) : JBayPardeSpec(tof2lab44_workaround) {}
677
678 unsigned numDeparserInvertChecksumUnits() const override { return 0; }
679};
680
681#endif /* BACKENDS_TOFINO_BF_P4C_SPECS_PARDE_SPEC_H_ */
unsigned lineRate() const override
Max line rate per-port (Gbps)
Definition parde_spec.h:661
unsigned byteInterClotGap() const override
The minimum number of bytes required between consecutive CLOTs.
Definition parde_spec.h:644
const std::map< unsigned, unsigned > & extractorSpec() const override
Definition parde_spec.h:586
int numParsers() const override
Total parsers supported ingress/egress.
Definition parde_spec.h:634
unsigned maxClotsPerState() const override
The maximum number of CLOTs that can be generated in each parser state.
Definition parde_spec.h:637
const std::vector< MatchRegisterSpec > matchRegisters() const override
Specifies the available match registers.
Definition parde_spec.h:591
unsigned maxClotsLivePerGress() const override
The maximum number of CLOTs that can be live for each packet in each gress.
Definition parde_spec.h:643
const std::unordered_set< std::string > & mdpValidVecFieldsSet() const override
Unused.
Definition parde_spec.h:668
double clkFreq() const override
Clock frequency.
Definition parde_spec.h:660
unsigned bitMinClotPos(gress_t gress) const override
The minimum offset a CLOT can have, in bits.
Definition parde_spec.h:645
unsigned bitMaxClotPos() const override
The maximum offset+length a CLOT can have, in bits.
Definition parde_spec.h:648
int numTcamRows() const override
Total TCAM Rows supported ingress/egress.
Definition parde_spec.h:635
size_t byteIngressPrePacketPaddingSize() const override
Definition parde_spec.h:584
const std::vector< MatchRegisterSpec > scratchRegisters() const override
Specifies the available scracth registers.
Definition parde_spec.h:602
unsigned numClotsPerGress() const override
The number of CLOTs available for allocation in each gress.
Definition parde_spec.h:642
unsigned byteMaxClotSize() const override
The maximum number of bytes a CLOT can hold.
Definition parde_spec.h:640
const std::vector< std::string > & mdpValidVecFields() const override
Unused.
Definition parde_spec.h:663
size_t bytePhase0Size() const override
Definition parde_spec.h:583
bool parserAllExtractorsSupportSingleByte() const override
Do all extractors support single-byte extracts?
Definition parde_spec.h:649
Definition match_register_spec.h:28
Definition parde_spec.h:379
virtual unsigned byteInterClotGap() const =0
The minimum number of bytes required between consecutive CLOTs.
virtual unsigned bitMaxClotPos() const =0
The maximum offset+length a CLOT can have, in bits.
virtual int numParsers() const =0
Total parsers supported ingress/egress.
virtual int numTcamRows() const =0
Total TCAM Rows supported ingress/egress.
virtual unsigned maxClotsLivePerGress() const =0
The maximum number of CLOTs that can be live for each packet in each gress.
virtual const std::vector< MatchRegisterSpec > scratchRegisters() const =0
Specifies the available scracth registers.
virtual unsigned lineRate() const =0
Max line rate per-port (Gbps)
size_t byteIngressIntrinsicMetadataSize() const
Definition parde_spec.h:383
size_t bitResubmitTagSize() const
Definition parde_spec.h:392
virtual size_t maxParseDepth(gress_t) const
The maximum parse depth for the given gress.
Definition parde_spec.h:465
virtual const std::unordered_set< std::string > & mdpValidVecFieldsSet() const =0
Unused.
virtual const std::vector< MatchRegisterSpec > matchRegisters() const =0
Specifies the available match registers.
virtual size_t minParseDepth(gress_t) const
The minimum parse depth for the given gress.
Definition parde_spec.h:462
virtual unsigned numClotsPerGress() const =0
The number of CLOTs available for allocation in each gress.
virtual const std::vector< std::string > & mdpValidVecFields() const =0
Unused.
int byteInputBufferSize() const
The size of input buffer, in bytes.
Definition parde_spec.h:411
virtual unsigned maxClotsPerState() const =0
The maximum number of CLOTs that can be generated in each parser state.
virtual unsigned bitMinClotPos(gress_t) const =0
The minimum offset a CLOT can have, in bits.
size_t bitResubmitSize() const
Definition parde_spec.h:396
virtual unsigned byteMaxClotSize() const =0
The maximum number of bytes a CLOT can hold.
virtual const std::map< unsigned, unsigned > & extractorSpec() const =0
virtual size_t bytePhase0Size() const =0
virtual size_t byteIngressPrePacketPaddingSize() const =0
nw_byterange byteInputBufferMetadataRange() const
Definition parde_spec.h:415
virtual double clkFreq() const =0
Clock frequency.
virtual bool parserAllExtractorsSupportSingleByte() const =0
Do all extractors support single-byte extracts?
size_t byteTotalIngressMetadataSize() const
Definition parde_spec.h:405
Definition parde_spec.h:504
bool parserAllExtractorsSupportSingleByte() const override
Do all extractors support single-byte extracts?
Definition parde_spec.h:553
unsigned lineRate() const override
Max line rate per-port (Gbps)
Definition parde_spec.h:564
unsigned maxClotsLivePerGress() const override
The maximum number of CLOTs that can be live for each packet in each gress.
Definition parde_spec.h:542
unsigned maxClotsPerState() const override
The maximum number of CLOTs that can be generated in each parser state.
Definition parde_spec.h:538
const std::vector< std::string > & mdpValidVecFields() const override
Unused.
Definition parde_spec.h:566
size_t bytePhase0Size() const override
Definition parde_spec.h:506
unsigned byteMaxClotSize() const override
The maximum number of bytes a CLOT can hold.
Definition parde_spec.h:539
unsigned numClotsPerGress() const override
The number of CLOTs available for allocation in each gress.
Definition parde_spec.h:540
unsigned byteInterClotGap() const override
The minimum number of bytes required between consecutive CLOTs.
Definition parde_spec.h:544
size_t byteIngressPrePacketPaddingSize() const override
Definition parde_spec.h:507
const std::map< unsigned, unsigned > & extractorSpec() const override
Definition parde_spec.h:509
size_t minParseDepth(gress_t gress) const override
The minimum parse depth for the given gress.
Definition parde_spec.h:549
double clkFreq() const override
Clock frequency.
Definition parde_spec.h:563
size_t maxParseDepth(gress_t gress) const override
The maximum parse depth for the given gress.
Definition parde_spec.h:551
const std::unordered_set< std::string > & mdpValidVecFieldsSet() const override
Unused.
Definition parde_spec.h:571
unsigned bitMinClotPos(gress_t) const override
The minimum offset a CLOT can have, in bits.
Definition parde_spec.h:546
const std::vector< MatchRegisterSpec > matchRegisters() const override
Specifies the available match registers.
Definition parde_spec.h:514
unsigned bitMaxClotPos() const override
The maximum offset+length a CLOT can have, in bits.
Definition parde_spec.h:547
int numParsers() const override
Total parsers supported ingress/egress.
Definition parde_spec.h:535
int numTcamRows() const override
Total TCAM Rows supported ingress/egress.
Definition parde_spec.h:536
const std::vector< MatchRegisterSpec > scratchRegisters() const override
Specifies the available scracth registers.
Definition parde_spec.h:525
Definition cstring.h:80
ClosedRange< RangeUnit::Bit, Endian::Network > nw_bitrange
Convenience typedefs for closed ranges in bits.
Definition lib/bitrange.h:755
ClosedRange< RangeUnit::Byte, Endian::Network > nw_byterange
Convenience typedefs for closed ranges in bytes.
Definition lib/bitrange.h:759
Definition lib/bitrange.h:158
int lo
Definition lib/bitrange.h:694
int hi
Definition lib/bitrange.h:700