1 // SPDX-License-Identifier: GPL-2.0-only 2 /* Copyright (C) 2024 Intel Corporation */ 3 4 #include <linux/net/intel/libie/rx.h> 5 6 /* O(1) converting i40e/ice/iavf's 8/10-bit hardware packet type to a parsed 7 * bitfield struct. 8 */ 9 10 /* A few supplementary definitions for when XDP hash types do not coincide 11 * with what can be generated from ptype definitions by means of preprocessor 12 * concatenation. 13 */ 14 #define XDP_RSS_L3_L2 XDP_RSS_TYPE_NONE 15 #define XDP_RSS_L4_NONE XDP_RSS_TYPE_NONE 16 #define XDP_RSS_L4_TIMESYNC XDP_RSS_TYPE_NONE 17 #define XDP_RSS_TYPE_L3 XDP_RSS_TYPE_NONE 18 #define XDP_RSS_TYPE_L4 XDP_RSS_L4 19 20 #define LIBIE_RX_PT(oip, ofrag, tun, tp, tefr, iprot, pl) { \ 21 .outer_ip = LIBETH_RX_PT_OUTER_##oip, \ 22 .outer_frag = LIBETH_RX_PT_##ofrag, \ 23 .tunnel_type = LIBETH_RX_PT_TUNNEL_IP_##tun, \ 24 .tunnel_end_prot = LIBETH_RX_PT_TUNNEL_END_##tp, \ 25 .tunnel_end_frag = LIBETH_RX_PT_##tefr, \ 26 .inner_prot = LIBETH_RX_PT_INNER_##iprot, \ 27 .payload_layer = LIBETH_RX_PT_PAYLOAD_##pl, \ 28 .hash_type = XDP_RSS_L3_##oip | \ 29 XDP_RSS_L4_##iprot | \ 30 XDP_RSS_TYPE_##pl, \ 31 } 32 33 #define LIBIE_RX_PT_UNUSED { } 34 35 #define __LIBIE_RX_PT_L2(iprot, pl) \ 36 LIBIE_RX_PT(L2, NOT_FRAG, NONE, NONE, NOT_FRAG, iprot, pl) 37 #define LIBIE_RX_PT_L2 __LIBIE_RX_PT_L2(NONE, L2) 38 #define LIBIE_RX_PT_TS __LIBIE_RX_PT_L2(TIMESYNC, L2) 39 #define LIBIE_RX_PT_L3 __LIBIE_RX_PT_L2(NONE, L3) 40 41 #define LIBIE_RX_PT_IP_FRAG(oip) \ 42 LIBIE_RX_PT(IPV##oip, FRAG, NONE, NONE, NOT_FRAG, NONE, L3) 43 #define LIBIE_RX_PT_IP_L3(oip, tun, teprot, tefr) \ 44 LIBIE_RX_PT(IPV##oip, NOT_FRAG, tun, teprot, tefr, NONE, L3) 45 #define LIBIE_RX_PT_IP_L4(oip, tun, teprot, iprot) \ 46 LIBIE_RX_PT(IPV##oip, NOT_FRAG, tun, teprot, NOT_FRAG, iprot, L4) 47 48 #define LIBIE_RX_PT_IP_NOF(oip, tun, ver) \ 49 LIBIE_RX_PT_IP_L3(oip, tun, ver, NOT_FRAG), \ 50 LIBIE_RX_PT_IP_L4(oip, tun, ver, UDP), \ 51 LIBIE_RX_PT_UNUSED, \ 52 LIBIE_RX_PT_IP_L4(oip, tun, ver, TCP), \ 53 LIBIE_RX_PT_IP_L4(oip, tun, ver, SCTP), \ 54 LIBIE_RX_PT_IP_L4(oip, tun, ver, ICMP) 55 56 /* IPv oip --> tun --> IPv ver */ 57 #define LIBIE_RX_PT_IP_TUN_VER(oip, tun, ver) \ 58 LIBIE_RX_PT_IP_L3(oip, tun, ver, FRAG), \ 59 LIBIE_RX_PT_IP_NOF(oip, tun, ver) 60 61 /* Non Tunneled IPv oip */ 62 #define LIBIE_RX_PT_IP_RAW(oip) \ 63 LIBIE_RX_PT_IP_FRAG(oip), \ 64 LIBIE_RX_PT_IP_NOF(oip, NONE, NONE) 65 66 /* IPv oip --> tun --> { IPv4, IPv6 } */ 67 #define LIBIE_RX_PT_IP_TUN(oip, tun) \ 68 LIBIE_RX_PT_IP_TUN_VER(oip, tun, IPV4), \ 69 LIBIE_RX_PT_IP_TUN_VER(oip, tun, IPV6) 70 71 /* IPv oip --> GRE/NAT tun --> { x, IPv4, IPv6 } */ 72 #define LIBIE_RX_PT_IP_GRE(oip, tun) \ 73 LIBIE_RX_PT_IP_L3(oip, tun, NONE, NOT_FRAG), \ 74 LIBIE_RX_PT_IP_TUN(oip, tun) 75 76 /* Non Tunneled IPv oip 77 * IPv oip --> { IPv4, IPv6 } 78 * IPv oip --> GRE/NAT --> { x, IPv4, IPv6 } 79 * IPv oip --> GRE/NAT --> MAC --> { x, IPv4, IPv6 } 80 * IPv oip --> GRE/NAT --> MAC/VLAN --> { x, IPv4, IPv6 } 81 */ 82 #define LIBIE_RX_PT_IP(oip) \ 83 LIBIE_RX_PT_IP_RAW(oip), \ 84 LIBIE_RX_PT_IP_TUN(oip, IP), \ 85 LIBIE_RX_PT_IP_GRE(oip, GRENAT), \ 86 LIBIE_RX_PT_IP_GRE(oip, GRENAT_MAC), \ 87 LIBIE_RX_PT_IP_GRE(oip, GRENAT_MAC_VLAN) 88 89 /* Lookup table mapping for O(1) parsing */ 90 const struct libeth_rx_pt libie_rx_pt_lut[LIBIE_RX_PT_NUM] = { 91 /* L2 packet types */ 92 LIBIE_RX_PT_UNUSED, 93 LIBIE_RX_PT_L2, 94 LIBIE_RX_PT_TS, 95 LIBIE_RX_PT_L2, 96 LIBIE_RX_PT_UNUSED, 97 LIBIE_RX_PT_UNUSED, 98 LIBIE_RX_PT_L2, 99 LIBIE_RX_PT_L2, 100 LIBIE_RX_PT_UNUSED, 101 LIBIE_RX_PT_UNUSED, 102 LIBIE_RX_PT_L2, 103 LIBIE_RX_PT_UNUSED, 104 105 LIBIE_RX_PT_L3, 106 LIBIE_RX_PT_L3, 107 LIBIE_RX_PT_L3, 108 LIBIE_RX_PT_L3, 109 LIBIE_RX_PT_L3, 110 LIBIE_RX_PT_L3, 111 LIBIE_RX_PT_L3, 112 LIBIE_RX_PT_L3, 113 LIBIE_RX_PT_L3, 114 LIBIE_RX_PT_L3, 115 116 LIBIE_RX_PT_IP(4), 117 LIBIE_RX_PT_IP(6), 118 }; 119 EXPORT_SYMBOL_NS_GPL(libie_rx_pt_lut, LIBIE); 120 121 MODULE_DESCRIPTION("Intel(R) Ethernet common library"); 122 MODULE_IMPORT_NS(LIBETH); 123 MODULE_LICENSE("GPL"); 124