Line data Source code
1 : #ifndef HEADER_fd_src_disco_fd_disco_base_h 2 : #define HEADER_fd_src_disco_fd_disco_base_h 3 : 4 : #include "../tango/fd_tango.h" 5 : #include "../ballet/txn/fd_txn.h" 6 : 7 : #include "../util/wksp/fd_wksp_private.h" 8 : 9 0 : #define DST_PROTO_OUTGOING (0UL) 10 0 : #define DST_PROTO_TPU_UDP (1UL) 11 0 : #define DST_PROTO_TPU_QUIC (2UL) 12 0 : #define DST_PROTO_SHRED (3UL) 13 0 : #define DST_PROTO_REPAIR (4UL) 14 0 : #define DST_PROTO_GOSSIP (5UL) 15 : 16 0 : #define POH_PKT_TYPE_MICROBLOCK (0UL) 17 0 : #define POH_PKT_TYPE_BECAME_LEADER (1UL) 18 0 : #define POH_PKT_TYPE_DONE_PACKING (2UL) 19 : #define POH_PKT_REACHED_LEADER (3UL) 20 : 21 : #define REPLAY_FLAG_FINISHED_BLOCK (0x01UL) 22 : #define REPLAY_FLAG_PACKED_MICROBLOCK (0x02UL) 23 : #define REPLAY_FLAG_MICROBLOCK (0x04UL) 24 : #define REPLAY_FLAG_CATCHING_UP (0x08UL) 25 : #define REPLAY_FLAG_INIT (0x10UL) 26 : 27 : 28 : /* FD_NET_MTU is the max full packet size, with ethernet, IP, and UDP 29 : headers that can go in or out of the net tile. 2048 is the maximum 30 : XSK entry size, so this value follows naturally. */ 31 12 : #define FD_NET_MTU (2048UL) 32 : 33 : /* FD_TPU_MTU is the max serialized byte size of a txn sent over TPU. */ 34 21 : #define FD_TPU_MTU (1232UL) 35 : 36 : /* FD_SHRED_STORE_MTU is the size of an fd_shred34_t (statically 37 : asserted in fd_shred_tile.c). */ 38 3 : #define FD_SHRED_STORE_MTU (41792UL) 39 : 40 : /* FD_TPU_DCACHE_MTU is the max size of a dcache entry */ 41 21 : #define FD_TPU_DCACHE_MTU (FD_TPU_MTU + FD_TXN_MAX_SZ + 2UL) 42 : /* The literal value of FD_TPU_DCACHE_MTU is used in some of the Rust 43 : shims, so if the value changes, this acts as a reminder to change it 44 : in the Rust code. */ 45 : FD_STATIC_ASSERT( FD_TPU_DCACHE_MTU==2086UL, tpu_dcache_mtu_check ); 46 : 47 3 : #define FD_TPU_RESOLVED_DCACHE_MTU (FD_TPU_DCACHE_MTU + (256UL*32UL) + 32UL) 48 : 49 0 : #define FD_NETMUX_SIG_MIN_HDR_SZ ( 42UL) /* The default header size, which means no vlan tags and no IP options. */ 50 : #define FD_NETMUX_SIG_IGNORE_HDR_SZ (102UL) /* Outside the allowable range, but still fits in 4 bits when compressed */ 51 : 52 : FD_PROTOTYPES_BEGIN 53 : 54 : /* hdr_sz is the total size of network headers, including eth, ip, udp. 55 : Ignored for outgoing packets. */ 56 : FD_FN_CONST static inline ulong 57 : fd_disco_netmux_sig( uint src_ip_addr, 58 : ushort src_port, 59 : uint dst_ip_addr, 60 : ulong proto, 61 0 : ulong hdr_sz ) { 62 : /* The size of an Ethernet header is 14+4k bytes, where 0<=k<=3 (?) is 63 : the number of vlan tags. The size of an IP header is 4j, where 64 : 5<=j<=15 is the size given in the header. The size of a UDP header 65 : is 8B. Thus, the total sum of these is 42+4i, where i=k+j-5, 66 : 0<=i<=13. Since bits are at a premium here, we compress the header 67 : size by just storing i. */ 68 0 : ulong hdr_sz_i = ((hdr_sz - 42UL)>>2)&0xFUL; 69 0 : ulong hash = fd_uint_hash( src_ip_addr ) + src_port; 70 : 71 : /* Currently only using 52 bits of the provided 64. */ 72 0 : return (hash<<56UL) | ((proto&0xFFUL)<<48UL) | ((hdr_sz_i&0xFUL)<<44UL) | (((ulong)dst_ip_addr)<<12UL); 73 0 : } 74 : 75 0 : FD_FN_CONST static inline ulong fd_disco_netmux_sig_hash ( ulong sig ) { return (sig>>56UL) & 0xFFUL; } 76 0 : FD_FN_CONST static inline ulong fd_disco_netmux_sig_proto ( ulong sig ) { return (sig>>48UL) & 0xFFUL; } 77 0 : FD_FN_CONST static inline uint fd_disco_netmux_sig_dst_ip( ulong sig ) { return (uint)((sig>>12UL) & 0xFFFFFFFFUL); } 78 : 79 : /* fd_disco_netmux_sig_hdr_sz extracts the total size of the Ethernet, 80 : IP, and UDP headers from the netmux signature field. The UDP payload 81 : of the packet stored in the corresponding frag begins at the returned 82 : offset. */ 83 0 : FD_FN_CONST static inline ulong fd_disco_netmux_sig_hdr_sz( ulong sig ) { return 4UL*((sig>>44UL) & 0xFUL) + 42UL; } 84 : 85 : FD_FN_CONST static inline ulong 86 : fd_disco_poh_sig( ulong slot, 87 : ulong pkt_type, 88 0 : ulong bank_tile ) { 89 : /* The high 6 bits of the low byte of the signature field is the bank 90 : idx. Banks will filter to only handle frags with their own idx. 91 : The higher 7 bytes are the slot number. Technically, the slot 92 : number is a ulong, but it won't hit 256^7 for about 10^9 years at 93 : the current rate. The lowest bits of the low byte is the packet 94 : type. */ 95 0 : return (slot << 8) | ((bank_tile & 0x3FUL) << 2) | (pkt_type & 0x3UL); 96 0 : } 97 : 98 0 : FD_FN_CONST static inline ulong fd_disco_poh_sig_pkt_type( ulong sig ) { return (sig & 0x3UL); } 99 0 : FD_FN_CONST static inline ulong fd_disco_poh_sig_slot( ulong sig ) { return (sig >> 8); } 100 0 : FD_FN_CONST static inline ulong fd_disco_poh_sig_bank_tile( ulong sig ) { return (sig >> 2) & 0x3FUL; } 101 : 102 : FD_FN_CONST static inline ulong 103 : fd_disco_bank_sig( ulong slot, 104 0 : ulong microblock_idx ) { 105 0 : return (slot << 32) | microblock_idx; 106 0 : } 107 : 108 0 : FD_FN_CONST static inline ulong fd_disco_bank_sig_slot( ulong sig ) { return (sig >> 32); } 109 0 : FD_FN_CONST static inline ulong fd_disco_bank_sig_microblock_idx( ulong sig ) { return sig & 0xFFFFFFFFUL; } 110 : 111 : FD_FN_CONST static inline ulong 112 : fd_disco_replay_sig( ulong slot, 113 0 : ulong flags ) { 114 0 : /* The low byte of the signature field is the flags for replay message. 115 0 : The higher 7 bytes are the slot number. These flags indicate the status 116 0 : of a microblock as it transits through the replay system. Technically, 117 0 : the slot number is a ulong, but it won't hit 256^7 for about 10^9 years 118 0 : at the current rate. The lowest bit of the low byte is the packet 119 0 : type. */ 120 0 : return (slot << 8) | (flags & 0xFFUL); 121 0 : } 122 : 123 0 : FD_FN_CONST static inline ulong fd_disco_replay_sig_flags( ulong sig ) { return (sig & 0xFFUL); } 124 0 : FD_FN_CONST static inline ulong fd_disco_replay_sig_slot( ulong sig ) { return (sig >> 8); } 125 : 126 : FD_FN_PURE static inline ulong 127 0 : fd_disco_compact_chunk0( void * wksp ) { 128 0 : return (((struct fd_wksp_private *)wksp)->gaddr_lo) >> FD_CHUNK_LG_SZ; 129 0 : } 130 : 131 : FD_FN_PURE static inline ulong 132 0 : fd_disco_compact_wmark( void * wksp, ulong mtu ) { 133 0 : ulong chunk_mtu = ((mtu + 2UL*FD_CHUNK_SZ-1UL) >> (1+FD_CHUNK_LG_SZ)) << 1; 134 0 : ulong wksp_hi = ((struct fd_wksp_private *)wksp)->gaddr_hi; 135 0 : return (wksp_hi >> FD_CHUNK_LG_SZ) - chunk_mtu; 136 0 : } 137 : 138 : FD_PROTOTYPES_END 139 : 140 : #endif /* HEADER_fd_src_disco_fd_disco_base_h */ 141 :