"tests/pipelines/vscode:/vscode.git/clone" did not exist on "2b04ec2ff7270d2044410378b04d85a194fa3d4a"
Commit e18f4b7b authored by Antoine Kaufmann's avatar Antoine Kaufmann
Browse files

i40e_bm: add missing files

parent ba194a11
#pragma once
#include <stdint.h>
namespace headers {
/******************************************************************************/
/* Ethernet */
#define ETH_ADDR_LEN 6
#define ETH_TYPE_IP 0x0800
#define ETH_TYPE_ARP 0x0806
struct eth_addr {
uint8_t addr[ETH_ADDR_LEN];
} __attribute__ ((packed));
struct eth_hdr {
struct eth_addr dest;
struct eth_addr src;
uint16_t type;
} __attribute__ ((packed));
/******************************************************************************/
/* IPv4 */
#define IPH_V(hdr) ((hdr)->_v_hl >> 4)
#define IPH_HL(hdr) ((hdr)->_v_hl & 0x0f)
#define IPH_TOS(hdr) ((hdr)->_tos)
#define IPH_ECN(hdr) ((hdr)->_tos & 0x3)
#define IPH_VHL_SET(hdr, v, hl) (hdr)->_v_hl = (((v) << 4) | (hl))
#define IPH_TOS_SET(hdr, tos) (hdr)->_tos = (tos)
#define IPH_ECN_SET(hdr, e) (hdr)->_tos = ((hdr)->_tos & 0xffc) | (e)
#define IP_HLEN 20
#define IP_PROTO_IP 0
#define IP_PROTO_ICMP 1
#define IP_PROTO_IGMP 2
#define IP_PROTO_IPENCAP 4
#define IP_PROTO_UDP 17
#define IP_PROTO_UDPLITE 136
#define IP_PROTO_TCP 6
#define IP_PROTO_DCCP 33
#define IP_ECN_NONE 0x0
#define IP_ECN_ECT0 0x2
#define IP_ECN_ECT1 0x1
#define IP_ECN_CE 0x3
struct ip_hdr {
/* version / header length */
uint8_t _v_hl;
/* type of service */
uint8_t _tos;
/* total length */
uint16_t len;
/* identification */
uint16_t id;
/* fragment offset field */
uint16_t offset;
/* time to live */
uint8_t ttl;
/* protocol*/
uint8_t proto;
/* checksum */
uint16_t chksum;
/* source and destination IP addresses */
uint32_t src;
uint32_t dest;
} __attribute__ ((packed));
/******************************************************************************/
/* ARP */
#define ARP_OPER_REQUEST 1
#define ARP_OPER_REPLY 2
#define ARP_HTYPE_ETHERNET 1
#define ARP_PTYPE_IPV4 0x0800
struct arp_hdr {
uint16_t htype;
uint16_t ptype;
uint8_t hlen;
uint8_t plen;
uint16_t oper;
struct eth_addr sha;
uint32_t spa;
struct eth_addr tha;
uint32_t tpa;
} __attribute__((packed));
/******************************************************************************/
/* TCP */
#define TCP_FIN 0x01U
#define TCP_SYN 0x02U
#define TCP_RST 0x04U
#define TCP_PSH 0x08U
#define TCP_ACK 0x10U
#define TCP_URG 0x20U
#define TCP_ECE 0x40U
#define TCP_CWR 0x80U
#define TCP_NS 0x100U
#define TCP_FLAGS 0x1ffU
/* Length of the TCP header, excluding options. */
#define TCP_HLEN 20
#define TCPH_HDRLEN(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) >> 12)
#define TCPH_FLAGS(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) & TCP_FLAGS)
#define TCPH_HDRLEN_SET(phdr, len) (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | TCPH_FLAGS(phdr))
#define TCPH_FLAGS_SET(phdr, flags) (phdr)->_hdrlen_rsvd_flags = (((phdr)->_hdrlen_rsvd_flags & PP_HTONS((uint16_t)(~(uint16_t)(TCP_FLAGS)))) | htons(flags))
#define TCPH_HDRLEN_FLAGS_SET(phdr, len, flags) (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | (flags))
#define TCPH_SET_FLAG(phdr, flags ) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags | htons(flags))
#define TCPH_UNSET_FLAG(phdr, flags) (phdr)->_hdrlen_rsvd_flags = htons(ntohs((phdr)->_hdrlen_rsvd_flags) | (TCPH_FLAGS(phdr) & ~(flags)) )
#define TCP_TCPLEN(seg) ((seg)->len + ((TCPH_FLAGS((seg)->tcphdr) & (TCP_FIN | TCP_SYN)) != 0))
struct tcp_hdr {
uint16_t src;
uint16_t dest;
uint32_t seqno;
uint32_t ackno;
uint16_t _hdrlen_rsvd_flags;
uint16_t wnd;
uint16_t chksum;
uint16_t urgp;
} __attribute__((packed));
/******************************************************************************/
/* UDP */
struct udp_hdr {
uint16_t src;
uint16_t dest;
uint16_t len;
uint16_t chksum;
} __attribute__((packed));
/******************************************************************************/
/* whole packets */
struct pkt_arp {
struct eth_hdr eth;
struct arp_hdr arp;
} __attribute__ ((packed));
struct pkt_ip {
struct eth_hdr eth;
struct ip_hdr ip;
} __attribute__ ((packed));
struct pkt_tcp {
struct eth_hdr eth;
struct ip_hdr ip;
struct tcp_hdr tcp;
} __attribute__ ((packed));
struct pkt_udp {
struct eth_hdr eth;
struct ip_hdr ip;
struct udp_hdr udp;
} __attribute__ ((packed));
} // namespace headers
#include "i40e_bm.h"
using namespace i40e;
rss_key_cache::rss_key_cache(const uint32_t (&key_)[key_len / 4])
: key(key_)
{
cache_dirty = true;
}
void rss_key_cache::build()
{
const uint8_t *k = reinterpret_cast<const uint8_t *> (&key);
uint32_t result = (((uint32_t)k[0]) << 24) |
(((uint32_t)k[1]) << 16) |
(((uint32_t)k[2]) << 8) |
((uint32_t)k[3]);
uint32_t idx = 32;
size_t i;
for (i = 0; i < cache_len; i++, idx++) {
uint8_t shift = (idx % 8);
uint32_t bit;
cache[i] = result;
bit = ((k[idx / 8] << shift) & 0x80) ? 1 : 0;
result = ((result << 1) | bit);
}
cache_dirty = false;
}
void rss_key_cache::set_dirty()
{
cache_dirty = true;
}
uint32_t rss_key_cache::hash_ipv4(uint32_t sip, uint32_t dip, uint16_t sp,
uint16_t dp)
{
static const uint32_t MSB32 = 0x80000000;
static const uint32_t MSB16 = 0x8000;
uint32_t res = 0;
int i;
if (cache_dirty)
build();
for (i = 0; i < 32; i++) {
if (sip & MSB32)
res ^= cache[i];
sip <<= 1;
}
for (i = 0; i < 32; i++) {
if (dip & MSB32)
res ^= cache[32+i];
dip <<= 1;
}
for (i = 0; i < 16; i++) {
if (sp & MSB16)
res ^= cache[64+i];
sp <<= 1;
}
for (i = 0; i < 16; i++) {
if (dp & MSB16)
res ^= cache[80+i];
dp <<= 1;
}
return res;
}
#if 0
int main(int argc, char *argv[])
{
static const uint8_t key[] = {
0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2,
0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0,
0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4,
0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c,
0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
};
uint32_t kregs[13];
key_cache kc(kregs);
memcpy(kregs, key, sizeof(key));
kc.set_dirty();
printf("%x\n", kc.hash_ipv4(0x420995bb, 0xa18e6450, 2794, 1766));
printf("%x\n", kc.hash_ipv4(0x420995bb, 0xa18e6450, 0, 0));
return 0;
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment