482 lines · c
1/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */2/* Copyright 2013-2015 Freescale Semiconductor Inc.3 */4#ifndef __FSL_DPKG_H_5#define __FSL_DPKG_H_6 7#include <linux/types.h>8 9/* Data Path Key Generator API10 * Contains initialization APIs and runtime APIs for the Key Generator11 */12 13/** Key Generator properties */14 15/**16 * DPKG_NUM_OF_MASKS - Number of masks per key extraction17 */18#define DPKG_NUM_OF_MASKS 419 20/**21 * DPKG_MAX_NUM_OF_EXTRACTS - Number of extractions per key profile22 */23#define DPKG_MAX_NUM_OF_EXTRACTS 1024 25/**26 * enum dpkg_extract_from_hdr_type - Selecting extraction by header types27 * @DPKG_FROM_HDR: Extract selected bytes from header, by offset28 * @DPKG_FROM_FIELD: Extract selected bytes from header, by offset from field29 * @DPKG_FULL_FIELD: Extract a full field30 */31enum dpkg_extract_from_hdr_type {32 DPKG_FROM_HDR = 0,33 DPKG_FROM_FIELD = 1,34 DPKG_FULL_FIELD = 235};36 37/**38 * enum dpkg_extract_type - Enumeration for selecting extraction type39 * @DPKG_EXTRACT_FROM_HDR: Extract from the header40 * @DPKG_EXTRACT_FROM_DATA: Extract from data not in specific header41 * @DPKG_EXTRACT_FROM_PARSE: Extract from parser-result;42 * e.g. can be used to extract header existence;43 * please refer to 'Parse Result definition' section in the parser BG44 */45enum dpkg_extract_type {46 DPKG_EXTRACT_FROM_HDR = 0,47 DPKG_EXTRACT_FROM_DATA = 1,48 DPKG_EXTRACT_FROM_PARSE = 349};50 51/**52 * struct dpkg_mask - A structure for defining a single extraction mask53 * @mask: Byte mask for the extracted content54 * @offset: Offset within the extracted content55 */56struct dpkg_mask {57 u8 mask;58 u8 offset;59};60 61/* Protocol fields */62 63/* Ethernet fields */64#define NH_FLD_ETH_DA BIT(0)65#define NH_FLD_ETH_SA BIT(1)66#define NH_FLD_ETH_LENGTH BIT(2)67#define NH_FLD_ETH_TYPE BIT(3)68#define NH_FLD_ETH_FINAL_CKSUM BIT(4)69#define NH_FLD_ETH_PADDING BIT(5)70#define NH_FLD_ETH_ALL_FIELDS (BIT(6) - 1)71 72/* VLAN fields */73#define NH_FLD_VLAN_VPRI BIT(0)74#define NH_FLD_VLAN_CFI BIT(1)75#define NH_FLD_VLAN_VID BIT(2)76#define NH_FLD_VLAN_LENGTH BIT(3)77#define NH_FLD_VLAN_TYPE BIT(4)78#define NH_FLD_VLAN_ALL_FIELDS (BIT(5) - 1)79 80#define NH_FLD_VLAN_TCI (NH_FLD_VLAN_VPRI | \81 NH_FLD_VLAN_CFI | \82 NH_FLD_VLAN_VID)83 84/* IP (generic) fields */85#define NH_FLD_IP_VER BIT(0)86#define NH_FLD_IP_DSCP BIT(2)87#define NH_FLD_IP_ECN BIT(3)88#define NH_FLD_IP_PROTO BIT(4)89#define NH_FLD_IP_SRC BIT(5)90#define NH_FLD_IP_DST BIT(6)91#define NH_FLD_IP_TOS_TC BIT(7)92#define NH_FLD_IP_ID BIT(8)93#define NH_FLD_IP_ALL_FIELDS (BIT(9) - 1)94 95/* IPV4 fields */96#define NH_FLD_IPV4_VER BIT(0)97#define NH_FLD_IPV4_HDR_LEN BIT(1)98#define NH_FLD_IPV4_TOS BIT(2)99#define NH_FLD_IPV4_TOTAL_LEN BIT(3)100#define NH_FLD_IPV4_ID BIT(4)101#define NH_FLD_IPV4_FLAG_D BIT(5)102#define NH_FLD_IPV4_FLAG_M BIT(6)103#define NH_FLD_IPV4_OFFSET BIT(7)104#define NH_FLD_IPV4_TTL BIT(8)105#define NH_FLD_IPV4_PROTO BIT(9)106#define NH_FLD_IPV4_CKSUM BIT(10)107#define NH_FLD_IPV4_SRC_IP BIT(11)108#define NH_FLD_IPV4_DST_IP BIT(12)109#define NH_FLD_IPV4_OPTS BIT(13)110#define NH_FLD_IPV4_OPTS_COUNT BIT(14)111#define NH_FLD_IPV4_ALL_FIELDS (BIT(15) - 1)112 113/* IPV6 fields */114#define NH_FLD_IPV6_VER BIT(0)115#define NH_FLD_IPV6_TC BIT(1)116#define NH_FLD_IPV6_SRC_IP BIT(2)117#define NH_FLD_IPV6_DST_IP BIT(3)118#define NH_FLD_IPV6_NEXT_HDR BIT(4)119#define NH_FLD_IPV6_FL BIT(5)120#define NH_FLD_IPV6_HOP_LIMIT BIT(6)121#define NH_FLD_IPV6_ID BIT(7)122#define NH_FLD_IPV6_ALL_FIELDS (BIT(8) - 1)123 124/* ICMP fields */125#define NH_FLD_ICMP_TYPE BIT(0)126#define NH_FLD_ICMP_CODE BIT(1)127#define NH_FLD_ICMP_CKSUM BIT(2)128#define NH_FLD_ICMP_ID BIT(3)129#define NH_FLD_ICMP_SQ_NUM BIT(4)130#define NH_FLD_ICMP_ALL_FIELDS (BIT(5) - 1)131 132/* IGMP fields */133#define NH_FLD_IGMP_VERSION BIT(0)134#define NH_FLD_IGMP_TYPE BIT(1)135#define NH_FLD_IGMP_CKSUM BIT(2)136#define NH_FLD_IGMP_DATA BIT(3)137#define NH_FLD_IGMP_ALL_FIELDS (BIT(4) - 1)138 139/* TCP fields */140#define NH_FLD_TCP_PORT_SRC BIT(0)141#define NH_FLD_TCP_PORT_DST BIT(1)142#define NH_FLD_TCP_SEQ BIT(2)143#define NH_FLD_TCP_ACK BIT(3)144#define NH_FLD_TCP_OFFSET BIT(4)145#define NH_FLD_TCP_FLAGS BIT(5)146#define NH_FLD_TCP_WINDOW BIT(6)147#define NH_FLD_TCP_CKSUM BIT(7)148#define NH_FLD_TCP_URGPTR BIT(8)149#define NH_FLD_TCP_OPTS BIT(9)150#define NH_FLD_TCP_OPTS_COUNT BIT(10)151#define NH_FLD_TCP_ALL_FIELDS (BIT(11) - 1)152 153/* UDP fields */154#define NH_FLD_UDP_PORT_SRC BIT(0)155#define NH_FLD_UDP_PORT_DST BIT(1)156#define NH_FLD_UDP_LEN BIT(2)157#define NH_FLD_UDP_CKSUM BIT(3)158#define NH_FLD_UDP_ALL_FIELDS (BIT(4) - 1)159 160/* UDP-lite fields */161#define NH_FLD_UDP_LITE_PORT_SRC BIT(0)162#define NH_FLD_UDP_LITE_PORT_DST BIT(1)163#define NH_FLD_UDP_LITE_ALL_FIELDS (BIT(2) - 1)164 165/* UDP-encap-ESP fields */166#define NH_FLD_UDP_ENC_ESP_PORT_SRC BIT(0)167#define NH_FLD_UDP_ENC_ESP_PORT_DST BIT(1)168#define NH_FLD_UDP_ENC_ESP_LEN BIT(2)169#define NH_FLD_UDP_ENC_ESP_CKSUM BIT(3)170#define NH_FLD_UDP_ENC_ESP_SPI BIT(4)171#define NH_FLD_UDP_ENC_ESP_SEQUENCE_NUM BIT(5)172#define NH_FLD_UDP_ENC_ESP_ALL_FIELDS (BIT(6) - 1)173 174/* SCTP fields */175#define NH_FLD_SCTP_PORT_SRC BIT(0)176#define NH_FLD_SCTP_PORT_DST BIT(1)177#define NH_FLD_SCTP_VER_TAG BIT(2)178#define NH_FLD_SCTP_CKSUM BIT(3)179#define NH_FLD_SCTP_ALL_FIELDS (BIT(4) - 1)180 181/* DCCP fields */182#define NH_FLD_DCCP_PORT_SRC BIT(0)183#define NH_FLD_DCCP_PORT_DST BIT(1)184#define NH_FLD_DCCP_ALL_FIELDS (BIT(2) - 1)185 186/* IPHC fields */187#define NH_FLD_IPHC_CID BIT(0)188#define NH_FLD_IPHC_CID_TYPE BIT(1)189#define NH_FLD_IPHC_HCINDEX BIT(2)190#define NH_FLD_IPHC_GEN BIT(3)191#define NH_FLD_IPHC_D_BIT BIT(4)192#define NH_FLD_IPHC_ALL_FIELDS (BIT(5) - 1)193 194/* SCTP fields */195#define NH_FLD_SCTP_CHUNK_DATA_TYPE BIT(0)196#define NH_FLD_SCTP_CHUNK_DATA_FLAGS BIT(1)197#define NH_FLD_SCTP_CHUNK_DATA_LENGTH BIT(2)198#define NH_FLD_SCTP_CHUNK_DATA_TSN BIT(3)199#define NH_FLD_SCTP_CHUNK_DATA_STREAM_ID BIT(4)200#define NH_FLD_SCTP_CHUNK_DATA_STREAM_SQN BIT(5)201#define NH_FLD_SCTP_CHUNK_DATA_PAYLOAD_PID BIT(6)202#define NH_FLD_SCTP_CHUNK_DATA_UNORDERED BIT(7)203#define NH_FLD_SCTP_CHUNK_DATA_BEGGINING BIT(8)204#define NH_FLD_SCTP_CHUNK_DATA_END BIT(9)205#define NH_FLD_SCTP_CHUNK_DATA_ALL_FIELDS (BIT(10) - 1)206 207/* L2TPV2 fields */208#define NH_FLD_L2TPV2_TYPE_BIT BIT(0)209#define NH_FLD_L2TPV2_LENGTH_BIT BIT(1)210#define NH_FLD_L2TPV2_SEQUENCE_BIT BIT(2)211#define NH_FLD_L2TPV2_OFFSET_BIT BIT(3)212#define NH_FLD_L2TPV2_PRIORITY_BIT BIT(4)213#define NH_FLD_L2TPV2_VERSION BIT(5)214#define NH_FLD_L2TPV2_LEN BIT(6)215#define NH_FLD_L2TPV2_TUNNEL_ID BIT(7)216#define NH_FLD_L2TPV2_SESSION_ID BIT(8)217#define NH_FLD_L2TPV2_NS BIT(9)218#define NH_FLD_L2TPV2_NR BIT(10)219#define NH_FLD_L2TPV2_OFFSET_SIZE BIT(11)220#define NH_FLD_L2TPV2_FIRST_BYTE BIT(12)221#define NH_FLD_L2TPV2_ALL_FIELDS (BIT(13) - 1)222 223/* L2TPV3 fields */224#define NH_FLD_L2TPV3_CTRL_TYPE_BIT BIT(0)225#define NH_FLD_L2TPV3_CTRL_LENGTH_BIT BIT(1)226#define NH_FLD_L2TPV3_CTRL_SEQUENCE_BIT BIT(2)227#define NH_FLD_L2TPV3_CTRL_VERSION BIT(3)228#define NH_FLD_L2TPV3_CTRL_LENGTH BIT(4)229#define NH_FLD_L2TPV3_CTRL_CONTROL BIT(5)230#define NH_FLD_L2TPV3_CTRL_SENT BIT(6)231#define NH_FLD_L2TPV3_CTRL_RECV BIT(7)232#define NH_FLD_L2TPV3_CTRL_FIRST_BYTE BIT(8)233#define NH_FLD_L2TPV3_CTRL_ALL_FIELDS (BIT(9) - 1)234 235#define NH_FLD_L2TPV3_SESS_TYPE_BIT BIT(0)236#define NH_FLD_L2TPV3_SESS_VERSION BIT(1)237#define NH_FLD_L2TPV3_SESS_ID BIT(2)238#define NH_FLD_L2TPV3_SESS_COOKIE BIT(3)239#define NH_FLD_L2TPV3_SESS_ALL_FIELDS (BIT(4) - 1)240 241/* PPP fields */242#define NH_FLD_PPP_PID BIT(0)243#define NH_FLD_PPP_COMPRESSED BIT(1)244#define NH_FLD_PPP_ALL_FIELDS (BIT(2) - 1)245 246/* PPPoE fields */247#define NH_FLD_PPPOE_VER BIT(0)248#define NH_FLD_PPPOE_TYPE BIT(1)249#define NH_FLD_PPPOE_CODE BIT(2)250#define NH_FLD_PPPOE_SID BIT(3)251#define NH_FLD_PPPOE_LEN BIT(4)252#define NH_FLD_PPPOE_SESSION BIT(5)253#define NH_FLD_PPPOE_PID BIT(6)254#define NH_FLD_PPPOE_ALL_FIELDS (BIT(7) - 1)255 256/* PPP-Mux fields */257#define NH_FLD_PPPMUX_PID BIT(0)258#define NH_FLD_PPPMUX_CKSUM BIT(1)259#define NH_FLD_PPPMUX_COMPRESSED BIT(2)260#define NH_FLD_PPPMUX_ALL_FIELDS (BIT(3) - 1)261 262/* PPP-Mux sub-frame fields */263#define NH_FLD_PPPMUX_SUBFRM_PFF BIT(0)264#define NH_FLD_PPPMUX_SUBFRM_LXT BIT(1)265#define NH_FLD_PPPMUX_SUBFRM_LEN BIT(2)266#define NH_FLD_PPPMUX_SUBFRM_PID BIT(3)267#define NH_FLD_PPPMUX_SUBFRM_USE_PID BIT(4)268#define NH_FLD_PPPMUX_SUBFRM_ALL_FIELDS (BIT(5) - 1)269 270/* LLC fields */271#define NH_FLD_LLC_DSAP BIT(0)272#define NH_FLD_LLC_SSAP BIT(1)273#define NH_FLD_LLC_CTRL BIT(2)274#define NH_FLD_LLC_ALL_FIELDS (BIT(3) - 1)275 276/* NLPID fields */277#define NH_FLD_NLPID_NLPID BIT(0)278#define NH_FLD_NLPID_ALL_FIELDS (BIT(1) - 1)279 280/* SNAP fields */281#define NH_FLD_SNAP_OUI BIT(0)282#define NH_FLD_SNAP_PID BIT(1)283#define NH_FLD_SNAP_ALL_FIELDS (BIT(2) - 1)284 285/* LLC SNAP fields */286#define NH_FLD_LLC_SNAP_TYPE BIT(0)287#define NH_FLD_LLC_SNAP_ALL_FIELDS (BIT(1) - 1)288 289/* ARP fields */290#define NH_FLD_ARP_HTYPE BIT(0)291#define NH_FLD_ARP_PTYPE BIT(1)292#define NH_FLD_ARP_HLEN BIT(2)293#define NH_FLD_ARP_PLEN BIT(3)294#define NH_FLD_ARP_OPER BIT(4)295#define NH_FLD_ARP_SHA BIT(5)296#define NH_FLD_ARP_SPA BIT(6)297#define NH_FLD_ARP_THA BIT(7)298#define NH_FLD_ARP_TPA BIT(8)299#define NH_FLD_ARP_ALL_FIELDS (BIT(9) - 1)300 301/* RFC2684 fields */302#define NH_FLD_RFC2684_LLC BIT(0)303#define NH_FLD_RFC2684_NLPID BIT(1)304#define NH_FLD_RFC2684_OUI BIT(2)305#define NH_FLD_RFC2684_PID BIT(3)306#define NH_FLD_RFC2684_VPN_OUI BIT(4)307#define NH_FLD_RFC2684_VPN_IDX BIT(5)308#define NH_FLD_RFC2684_ALL_FIELDS (BIT(6) - 1)309 310/* User defined fields */311#define NH_FLD_USER_DEFINED_SRCPORT BIT(0)312#define NH_FLD_USER_DEFINED_PCDID BIT(1)313#define NH_FLD_USER_DEFINED_ALL_FIELDS (BIT(2) - 1)314 315/* Payload fields */316#define NH_FLD_PAYLOAD_BUFFER BIT(0)317#define NH_FLD_PAYLOAD_SIZE BIT(1)318#define NH_FLD_MAX_FRM_SIZE BIT(2)319#define NH_FLD_MIN_FRM_SIZE BIT(3)320#define NH_FLD_PAYLOAD_TYPE BIT(4)321#define NH_FLD_FRAME_SIZE BIT(5)322#define NH_FLD_PAYLOAD_ALL_FIELDS (BIT(6) - 1)323 324/* GRE fields */325#define NH_FLD_GRE_TYPE BIT(0)326#define NH_FLD_GRE_ALL_FIELDS (BIT(1) - 1)327 328/* MINENCAP fields */329#define NH_FLD_MINENCAP_SRC_IP BIT(0)330#define NH_FLD_MINENCAP_DST_IP BIT(1)331#define NH_FLD_MINENCAP_TYPE BIT(2)332#define NH_FLD_MINENCAP_ALL_FIELDS (BIT(3) - 1)333 334/* IPSEC AH fields */335#define NH_FLD_IPSEC_AH_SPI BIT(0)336#define NH_FLD_IPSEC_AH_NH BIT(1)337#define NH_FLD_IPSEC_AH_ALL_FIELDS (BIT(2) - 1)338 339/* IPSEC ESP fields */340#define NH_FLD_IPSEC_ESP_SPI BIT(0)341#define NH_FLD_IPSEC_ESP_SEQUENCE_NUM BIT(1)342#define NH_FLD_IPSEC_ESP_ALL_FIELDS (BIT(2) - 1)343 344/* MPLS fields */345#define NH_FLD_MPLS_LABEL_STACK BIT(0)346#define NH_FLD_MPLS_LABEL_STACK_ALL_FIELDS (BIT(1) - 1)347 348/* MACSEC fields */349#define NH_FLD_MACSEC_SECTAG BIT(0)350#define NH_FLD_MACSEC_ALL_FIELDS (BIT(1) - 1)351 352/* GTP fields */353#define NH_FLD_GTP_TEID BIT(0)354 355/* Supported protocols */356enum net_prot {357 NET_PROT_NONE = 0,358 NET_PROT_PAYLOAD,359 NET_PROT_ETH,360 NET_PROT_VLAN,361 NET_PROT_IPV4,362 NET_PROT_IPV6,363 NET_PROT_IP,364 NET_PROT_TCP,365 NET_PROT_UDP,366 NET_PROT_UDP_LITE,367 NET_PROT_IPHC,368 NET_PROT_SCTP,369 NET_PROT_SCTP_CHUNK_DATA,370 NET_PROT_PPPOE,371 NET_PROT_PPP,372 NET_PROT_PPPMUX,373 NET_PROT_PPPMUX_SUBFRM,374 NET_PROT_L2TPV2,375 NET_PROT_L2TPV3_CTRL,376 NET_PROT_L2TPV3_SESS,377 NET_PROT_LLC,378 NET_PROT_LLC_SNAP,379 NET_PROT_NLPID,380 NET_PROT_SNAP,381 NET_PROT_MPLS,382 NET_PROT_IPSEC_AH,383 NET_PROT_IPSEC_ESP,384 NET_PROT_UDP_ENC_ESP, /* RFC 3948 */385 NET_PROT_MACSEC,386 NET_PROT_GRE,387 NET_PROT_MINENCAP,388 NET_PROT_DCCP,389 NET_PROT_ICMP,390 NET_PROT_IGMP,391 NET_PROT_ARP,392 NET_PROT_CAPWAP_DATA,393 NET_PROT_CAPWAP_CTRL,394 NET_PROT_RFC2684,395 NET_PROT_ICMPV6,396 NET_PROT_FCOE,397 NET_PROT_FIP,398 NET_PROT_ISCSI,399 NET_PROT_GTP,400 NET_PROT_USER_DEFINED_L2,401 NET_PROT_USER_DEFINED_L3,402 NET_PROT_USER_DEFINED_L4,403 NET_PROT_USER_DEFINED_L5,404 NET_PROT_USER_DEFINED_SHIM1,405 NET_PROT_USER_DEFINED_SHIM2,406 407 NET_PROT_DUMMY_LAST408};409 410/**411 * struct dpkg_extract - A structure for defining a single extraction412 * @type: Determines how the union below is interpreted:413 * DPKG_EXTRACT_FROM_HDR: selects 'from_hdr';414 * DPKG_EXTRACT_FROM_DATA: selects 'from_data';415 * DPKG_EXTRACT_FROM_PARSE: selects 'from_parse'416 * @extract: Selects extraction method417 * @extract.from_hdr: Used when 'type = DPKG_EXTRACT_FROM_HDR'418 * @extract.from_data: Used when 'type = DPKG_EXTRACT_FROM_DATA'419 * @extract.from_parse: Used when 'type = DPKG_EXTRACT_FROM_PARSE'420 * @extract.from_hdr.prot: Any of the supported headers421 * @extract.from_hdr.type: Defines the type of header extraction:422 * DPKG_FROM_HDR: use size & offset below;423 * DPKG_FROM_FIELD: use field, size and offset below;424 * DPKG_FULL_FIELD: use field below425 * @extract.from_hdr.field: One of the supported fields (NH_FLD_)426 * @extract.from_hdr.size: Size in bytes427 * @extract.from_hdr.offset: Byte offset428 * @extract.from_hdr.hdr_index: Clear for cases not listed below;429 * Used for protocols that may have more than a single430 * header, 0 indicates an outer header;431 * Supported protocols (possible values):432 * NET_PROT_VLAN (0, HDR_INDEX_LAST);433 * NET_PROT_MPLS (0, 1, HDR_INDEX_LAST);434 * NET_PROT_IP(0, HDR_INDEX_LAST);435 * NET_PROT_IPv4(0, HDR_INDEX_LAST);436 * NET_PROT_IPv6(0, HDR_INDEX_LAST);437 * @extract.from_data.size: Size in bytes438 * @extract.from_data.offset: Byte offset439 * @extract.from_parse.size: Size in bytes440 * @extract.from_parse.offset: Byte offset441 * @num_of_byte_masks: Defines the number of valid entries in the array below;442 * This is also the number of bytes to be used as masks443 * @masks: Masks parameters444 */445struct dpkg_extract {446 enum dpkg_extract_type type;447 union {448 struct {449 enum net_prot prot;450 enum dpkg_extract_from_hdr_type type;451 u32 field;452 u8 size;453 u8 offset;454 u8 hdr_index;455 } from_hdr;456 struct {457 u8 size;458 u8 offset;459 } from_data;460 struct {461 u8 size;462 u8 offset;463 } from_parse;464 } extract;465 466 u8 num_of_byte_masks;467 struct dpkg_mask masks[DPKG_NUM_OF_MASKS];468};469 470/**471 * struct dpkg_profile_cfg - A structure for defining a full Key Generation472 * profile (rule)473 * @num_extracts: Defines the number of valid entries in the array below474 * @extracts: Array of required extractions475 */476struct dpkg_profile_cfg {477 u8 num_extracts;478 struct dpkg_extract extracts[DPKG_MAX_NUM_OF_EXTRACTS];479};480 481#endif /* __FSL_DPKG_H_ */482