openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

bregex.h (30448B)


      1 /*
      2  * 
      3  * 
      4  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      5  * 
      6  * Copyright 2007-2020 Broadcom Inc. All rights reserved.
      7  *
      8  */
      9 
     10 #ifndef __BCM_BREGEX_H__
     11 #define __BCM_BREGEX_H__
     12 
     13 #if defined(INCLUDE_REGEX)
     14 
     15 #include <bcm/types.h>
     16 #include <bcm/field.h>
     17 
     18 #ifndef BCM_HIDE_DISPATCHABLE
     19 
     20 /* Initialize BCM regex module. */
     21 extern int bcm_regex_init(
     22     int unit);
     23 
     24 #endif /* BCM_HIDE_DISPATCHABLE */
     25 
     26 /* Regex Configuration structure. */
     27 typedef struct bcm_regex_config_s {
     28     uint32 flags;                   /* Flags for Regex configuration. */
     29     int max_flows;                  /* maximum number of flows to be tracked. */
     30     int payload_depth;              /* Maximum payload length to be inspected. */
     31     int inspect_num_pkt;            /* maximum number of packets to be inspected
     32                                        per flow. */
     33     int inactivity_timeout_usec;    /* Inactivity timeout. */
     34     bcm_mac_t dst_mac;              /* Destination MAC address */
     35     bcm_mac_t src_mac;              /* Source MAC address */
     36     uint16 ethertype;               /* EtherType */
     37     uint32 report_flags;            /* Bitmap of report types enabled. */
     38     uint32 report_buffer_size;      /* The number of entries which the report
     39                                        buffer can hold. */
     40 } bcm_regex_config_t;
     41 
     42 #define BCM_REGEX_CONFIG_ENABLE             0x0001     /* Enable Regex feature */
     43 #define BCM_REGEX_CONFIG_TCP_SESSION_DETECT 0x0002     /* Enable TCP session
     44                                                           termination */
     45 #define BCM_REGEX_CONFIG_IP4                0x0004     /* Enable tracking on
     46                                                           IPv4 packets */
     47 #define BCM_REGEX_CONFIG_IP6                0x0008     /* Enable tracking on
     48                                                           IPv6 packets */
     49 #define BCM_REGEX_CONFIG_AGING              0x0010     /* Enable aging on
     50                                                           tracked flows */
     51 #define BCM_REGEX_COUNTER_ENABLE            0x0020     /* Enable counter and
     52                                                           statistics */
     53 #define BCM_REGEX_PER_DIRECTION_COUNTER_ENABLE 0x0040     /* Enable counter and
     54                                                           statistics per
     55                                                           direction */
     56 #define BCM_REGEX_USE_POLICY_ID             0x0080     /* Use only actions in
     57                                                           the referenced policy */
     58 
     59 #define BCM_REGEX_REPORT_NEW        0x0001     /* Enable report generation for
     60                                                   new flows */
     61 #define BCM_REGEX_REPORT_MATCHED    0x0002     /* Enable report generation for
     62                                                   flows that matched pattern */
     63 #define BCM_REGEX_REPORT_END        0x0004     /* Enable report generation when
     64                                                   flow is retired */
     65 #define BCM_REGEX_REPORT_ALL        0x0008     /* Enable generation of all
     66                                                   reports */
     67 
     68 /*  bcm_regex_config_t_init */
     69 extern void bcm_regex_config_t_init(
     70     bcm_regex_config_t *config);
     71 
     72 #ifndef BCM_HIDE_DISPATCHABLE
     73 
     74 /*  Set configuration for Regex module. */
     75 extern int bcm_regex_config_set(
     76     int unit, 
     77     bcm_regex_config_t *config);
     78 
     79 /*  Get configuration for Regex module. */
     80 extern int bcm_regex_config_get(
     81     int unit, 
     82     bcm_regex_config_t *config);
     83 
     84 /* Add a range of L4 ports to be excluded from flow tracking. */
     85 extern int bcm_regex_exclude_add(
     86     int unit, 
     87     uint8 protocol, 
     88     uint16 l4_start, 
     89     uint16 l4_end);
     90 
     91 /* Delete L4 ports range excluded from flow tracking. */
     92 extern int bcm_regex_exclude_delete(
     93     int unit, 
     94     uint8 protocol, 
     95     uint16 l4_start, 
     96     uint16 l4_end);
     97 
     98 /* Delete all L4 ports excluded from flow tracking. */
     99 extern int bcm_regex_exclude_delete_all(
    100     int unit);
    101 
    102 /* Delete L4 ports range excluded from flow tracking. */
    103 extern int bcm_regex_exclude_get(
    104     int unit, 
    105     int array_size, 
    106     uint8 *protocol, 
    107     uint16 *l4low, 
    108     uint16 *l4high, 
    109     int *array_count);
    110 
    111 #endif /* BCM_HIDE_DISPATCHABLE */
    112 
    113 /* bcm_regex_engine_t */
    114 typedef int bcm_regex_engine_t;
    115 
    116 /* Regex Engine Configuration structure. */
    117 typedef struct bcm_regex_engine_config_s {
    118     uint32 flags;   /* Flags for Regex configuration. */
    119 } bcm_regex_engine_config_t;
    120 
    121 #define BCM_REGEX_ENGINE_CONFIG_MULTI_PACKET 0x0001     /* Match pattern across
    122                                                           packet boundary */
    123 
    124 /*  bcm_regex_engine_config_t_init */
    125 extern void bcm_regex_engine_config_t_init(
    126     bcm_regex_engine_config_t *config);
    127 
    128 #ifndef BCM_HIDE_DISPATCHABLE
    129 
    130 /* Create regex engine. */
    131 extern int bcm_regex_engine_create(
    132     int unit, 
    133     bcm_regex_engine_config_t *config, 
    134     bcm_regex_engine_t *engid);
    135 
    136 /* destroy regex engine. */
    137 extern int bcm_regex_engine_destroy(
    138     int unit, 
    139     bcm_regex_engine_t engid);
    140 
    141 #endif /* BCM_HIDE_DISPATCHABLE */
    142 
    143 /*  Prototype for regex engine traverse callback. */
    144 typedef int (*bcm_regex_engine_traverse_cb)(
    145     int unit, 
    146     bcm_regex_engine_t engine, 
    147     bcm_regex_engine_config_t *config, 
    148     void *user_data);
    149 
    150 #ifndef BCM_HIDE_DISPATCHABLE
    151 
    152 /* Traverse regex engines. */
    153 extern int bcm_regex_engine_traverse(
    154     int unit, 
    155     bcm_regex_engine_traverse_cb cb, 
    156     void *user_data);
    157 
    158 /* Get regex engine configuration. */
    159 extern int bcm_regex_engine_get(
    160     int unit, 
    161     bcm_regex_engine_t engid, 
    162     bcm_regex_engine_config_t *config);
    163 
    164 #endif /* BCM_HIDE_DISPATCHABLE */
    165 
    166 #define BCM_REGEX_MAX_PATTERN_SIZE  256        
    167 
    168 /* Policy identifier */
    169 typedef int bcm_regex_policy_t;
    170 
    171 /* Regex Configuration structure. */
    172 typedef struct bcm_regex_match_s {
    173     uint32 flags;                       /* Flags for Regex match. */
    174     int match_id;                       /* User specified match object
    175                                            identifier */
    176     char pattern[BCM_REGEX_MAX_PATTERN_SIZE]; /* Regex Pattern. */
    177     int sequence;                       /* first packet (0), any packet
    178                                            (non-zero). */
    179     int payload_length_max;             /* Check payload length of the match
    180                                            packet is less than this. */
    181     int payload_length_min;             /* Check payload length of the match
    182                                            packet is greater than this. */
    183     uint16 l4_src_port_low;             /* L4 port value to qualify source port
    184                                            range. */
    185     uint16 l4_src_port_high;            /* L4 port value to qualify source port
    186                                            range. */
    187     uint16 l4_dst_port_low;             /* L4 port value to qualify destination
    188                                            port range. */
    189     uint16 l4_dst_port_high;            /* L4 port value to qualify destination
    190                                            port range. */
    191     uint16 priority;                    /* priority for match. */
    192     int provides;                       /* Identifier of this match object in
    193                                            link list */
    194     int requires;                       /* Identifier of the next match object
    195                                            in chain */
    196     int inactivity_timeout_usec;        /* timeout value in microsec */
    197     uint32 action_flags;                /* action flags for Regex match. */
    198     int new_int_pri;                    /* Assign new internal priority to
    199                                            packets */
    200     int new_dscp;                       /* reassign DSCP value */
    201     int new_pkt_pri;                    /* reassign new .1x priority */
    202     int policer_id;                     /* meter using the specified policer id */
    203     int sig_id;                         /* The signature ID assigned by the SDK */
    204     bcm_regex_policy_t policy_id;       /* The ID of the policy to be used if
    205                                            BCM_REGEX_USE_POLICY_ID is
    206                                            configured. */
    207 } bcm_regex_match_t;
    208 
    209 /*  bcm_regex_engine_config_t_init */
    210 extern void bcm_regex_match_t_init(
    211     bcm_regex_match_t *match);
    212 
    213 #ifndef BCM_HIDE_DISPATCHABLE
    214 
    215 /* check Regex match objects. */
    216 extern int bcm_regex_match_check(
    217     int unit, 
    218     bcm_regex_match_t *matches, 
    219     int count, 
    220     int *metric);
    221 
    222 /* Add Regex match objects to engine. */
    223 extern int bcm_regex_match_set(
    224     int unit, 
    225     bcm_regex_engine_t engid, 
    226     bcm_regex_match_t *matches, 
    227     int count);
    228 
    229 #endif /* BCM_HIDE_DISPATCHABLE */
    230 
    231 #define BCM_REGEX_MATCH_TO_SERVER           0x00000001 
    232 #define BCM_REGEX_MATCH_TO_CLIENT           0x00000002 
    233 #define BCM_REGEX_MATCH_MULTI_FLOW          0x00000004 /* HTTP Persistent Flow */
    234 #define BCM_REGEX_MATCH_CASE_INSENSITIVE    0x00000008 
    235 #define BCM_REGEX_MATCH_L4_SRC_PORT         0x00000010 
    236 #define BCM_REGEX_MATCH_L4_DST_PORT         0x00000020 
    237 #define BCM_REGEX_MATCH_PKT_SEQUENCE        0x00000040 /* Qualify match only if
    238                                                           packets are received
    239                                                           without error in
    240                                                           sequence */
    241 #define BCM_REGEX_MATCH_SIG_ID_RETURN       0x00000080 /* Set if the hardware
    242                                                           signature ID
    243                                                           corresponding to the
    244                                                           Match ID is to be
    245                                                           returned */
    246 
    247 #define BCM_REGEX_MATCH_ACTION_IGNORE       0x00000001 /* Deprecated, use
    248                                                           separate policy API */
    249 #define BCM_REGEX_MATCH_ACTION_DROP         0x00000002 /* Deprecated, use
    250                                                           separate policy API */
    251 #define BCM_REGEX_MATCH_ACTION_COPY_TO_CPU  0x00000004 /* Deprecated, use
    252                                                           separate policy API */
    253 #define BCM_REGEX_MATCH_ACTION_INT_PRI      0x00000008 /* Deprecated, use
    254                                                           separate policy API */
    255 #define BCM_REGEX_MATCH_ACTION_DSCP         0x00000010 /* Deprecated, use
    256                                                           separate policy API */
    257 #define BCM_REGEX_MATCH_ACTION_PKT_PRI      0x00000020 /* Deprecated, use
    258                                                           separate policy API */
    259 #define BCM_REGEX_MATCH_ACTION_NON_POLICY_ACTIONS 0x0000003F /* Used to check for
    260                                                           deprecated actions */
    261 #define BCM_REGEX_MATCH_ACTION_NOTIFY_HEADER_ONLY 0x00000040 
    262 #define BCM_REGEX_MATCH_ACTION_NOTIFY_COPY_TO_CPU 0x00000080 
    263 
    264 /* Flow Tracker's Flow End Reasons. */
    265 typedef enum bcm_regex_flow_end_reason_e {
    266     bcmRegexFlowEndReasonFirst = 0,     /* Beginning of Flow End Reason */
    267     bcmRegexFlowEndReasonTcpAgeout = 0, /* Flow session ended because of age out */
    268     bcmRegexFlowEndReasonTcpFINr = 1,   /* Flow session ended because TCP FIN
    269                                            received in reverse direction */
    270     bcmRegexFlowEndReasonTcpFINf = 2,   /* Flow session ended because TCP FIN
    271                                            received in forward direction */
    272     bcmRegexFlowEndReasonTcpReset = 3,  /* Flow session ended because TCP RESET
    273                                            received in either direction */
    274     bcmRegexFlowEndReasonCount = 3      /* End of list */
    275 } bcm_regex_flow_end_reason_t;
    276 
    277 /* Regex report structure. */
    278 typedef struct bcm_regex_report_s {
    279     int match_id;                       /* Match identifier. */
    280     uint32 flags;                       /* flags. */
    281     bcm_ip_t sip;                       /* Source IPV4 address. */
    282     bcm_ip_t dip;                       /* destination IPV4 address. */
    283     bcm_ip6_t sip6;                     /* Source IPV6 address. */
    284     uint8 protocol;                     /* IP protocol */
    285     bcm_regex_flow_end_reason_t flow_end_reason; /* FT flow end reason */
    286     bcm_ip6_t dip6;                     /* destination IPV6 address. */
    287     uint32 dst_port;                    /* L4 dst port. */
    288     uint32 src_port;                    /* L4 src port */
    289     uint32 match_flags;                 /* match flags. */
    290     uint64 packet_count;                /* Packet count. */
    291     uint64 byte_count;                  /* byte count. */
    292     uint64 packet_count_to_server;      /* Packet count to server. */
    293     uint64 byte_count_to_server;        /* byte count to server . */
    294     uint64 packet_count_to_client;      /* Packet count to client. */
    295     uint64 byte_count_to_client;        /* byte count to client . */
    296     uint32 start_timestamp;             /* Session start timestamp (10ms
    297                                            granularity) */
    298     uint32 last_timestamp;              /* Session last packet timestamp (10ms
    299                                            granularity). */
    300     uint32 refresh_timestamp;           /* Session refresh packet timestamp
    301                                            (10ms granularity). */
    302 } bcm_regex_report_t;
    303 
    304 /*  bcm_regex_engine_config_t_init */
    305 extern void bcm_regex_report_t_init(
    306     bcm_regex_report_t *match);
    307 
    308 /*  Prototype for user provided report callback. */
    309 typedef void (*bcm_regex_report_cb)(
    310     int unit, 
    311     bcm_regex_report_t *report, 
    312     void *user_data);
    313 
    314 #ifndef BCM_HIDE_DISPATCHABLE
    315 
    316 /* register user provided callback for regex report. */
    317 extern int bcm_regex_report_register(
    318     int unit, 
    319     uint32 reports, 
    320     bcm_regex_report_cb callback, 
    321     void *user_data);
    322 
    323 /* Unregister user provided callback for regex report. */
    324 extern int bcm_regex_report_unregister(
    325     int unit, 
    326     uint32 reports, 
    327     bcm_regex_report_cb callback, 
    328     void *user_data);
    329 
    330 /* Return user-provided Match ID for a created signature ID. */
    331 extern int bcm_regex_get_match_id(
    332     int unit, 
    333     int signature_id, 
    334     int *match_id);
    335 
    336 /* Return hardware Signature ID for a user provided Match ID. */
    337 extern int bcm_regex_get_sig_id(
    338     int unit, 
    339     int match_id, 
    340     int *signature_id);
    341 
    342 #endif /* BCM_HIDE_DISPATCHABLE */
    343 
    344 /* Regex engine info structure. */
    345 typedef struct bcm_regex_engine_info_s {
    346     int size;       /* Static size of largest memory that a single engine (or
    347                        SME) can use. */
    348     int free_size;  /* Available free memory on the specified engine, or on all
    349                        engines. */
    350 } bcm_regex_engine_info_t;
    351 
    352 #define BCM_REGEX_ENGINE_ALL    -1         
    353 
    354 #ifndef BCM_HIDE_DISPATCHABLE
    355 
    356 /* Return information about the Signature Matching Engine. */
    357 extern int bcm_regex_engine_info_get(
    358     int unit, 
    359     int engine_id, 
    360     bcm_regex_engine_info_t *regex_engine_info);
    361 
    362 #endif /* BCM_HIDE_DISPATCHABLE */
    363 
    364 /* Regex session info structure. */
    365 typedef struct bcm_regex_info_s {
    366     int session_size;           /* Static size of entire Flow Tracker session
    367                                    table. */
    368     int session_free_size_ipv4; /* Total free memory for IPv4 sessions available
    369                                    in the FT. */
    370     int session_free_size_ipv6; /* Total free memory for IPv6 sessions available
    371                                    in the FT. */
    372     int policy_size;            /* Static size of entire Flow Tracker policy
    373                                    table. */
    374     int policy_free_size;       /* Total free size of Flow Tracker policy table. */
    375 } bcm_regex_info_t;
    376 
    377 #ifndef BCM_HIDE_DISPATCHABLE
    378 
    379 /* Return various info about the Flow Tracker Session and Policy tables. */
    380 extern int bcm_regex_info_get(
    381     int unit, 
    382     bcm_regex_info_t *regex_info);
    383 
    384 #endif /* BCM_HIDE_DISPATCHABLE */
    385 
    386 /* Flow Tracker global statistics. */
    387 typedef enum bcm_regex_stat_e {
    388     bcmStatRegexSessionFirst = 0,       /* Beginning of Session part of list */
    389     bcmStatRegexSessionEntriesInUse = 0, /* 32-bit counter, Current number of
    390                                            session entries in use */
    391     bcmStatRegexSessionFlowsCreated = 1, /* 32-bit counter, Cumulative number of
    392                                            flows created in flow tracker session
    393                                            table */
    394     bcmStatRegexSessionMaxFlowsInUse = 2, /* 32-bit counter, Maximum number of
    395                                            flows in use, high watermark */
    396     bcmStatRegexSessionFlowsMissedTCP = 3, /* 32-bit counter, Cumulative number of
    397                                            TCP flows that could not be inserted
    398                                            because of bucket full */
    399     bcmStatRegexSessionFlowsMissedUDP = 4, /* 32-bit counter, Cumulative number of
    400                                            UDP flows that could not be inserted
    401                                            because of bucket full */
    402     bcmStatRegexSessionCmdWaitTimeouts = 5, /* 32-bit counter, Number of flows for
    403                                            which no results packet was received */
    404     bcmStatRegexSessionUnusedResults = 6, /* 32-bit counter, Number of results
    405                                            packets that were ignored */
    406     bcmStatRegexSessionSuppressedActions = 7, /* 32-bit counter, Number of flows
    407                                            created where actions inhibited by
    408                                            VFP */
    409     bcmStatRegexSessionTcpSynData = 8,  /* 32-bit counter, Number of flows
    410                                            created with TCP SYN data */
    411     bcmStatRegexSessionL4Invalid = 9,   /* 32-bit counter, Number of packets
    412                                            seen where L4 offset/length could not
    413                                            be determined */
    414     bcmStatRegexSessionL4PortsExcluded = 10, /* 32-bit counter, Number of flows not
    415                                            created because of L4Port Table
    416                                            exclusion */
    417     bcmStatRegexSessionLast = 10,       /* End of Session part of list */
    418     bcmStatRegexSigMatchFirst = 21,     /* Beginning of SigMatch part of list */
    419     bcmStatRegexSigMatchPacketsReceived = 21, /* 32-bit counter, Number of packets
    420                                            received by the Signature Match for
    421                                            inspection */
    422     bcmStatRegexSigMatchPacketsSent = 22, /* 32-bit counter, Number of packets
    423                                            sent by Signature Match for reporting
    424                                            to the Flow Tracker */
    425     bcmStatRegexSigMatchPacketsDropped = 23, /* 32-bit counter, Total number of
    426                                            packets dropped without match
    427                                            processing */
    428     bcmStatRegexSigMatchBytesMatched = 24, /* 32-bit counter, Number of L4 payload
    429                                            bytes processed by the regex engines */
    430     bcmStatRegexSigMatchMatchedFlows = 25, /* 32-bit counter, Number of flows that
    431                                            were successfully matched */
    432     bcmStatRegexSigMatchUnmatchedFlows = 26, /* 32-bit counter, Number of flows that
    433                                            were not successfully matches */
    434     bcmStatRegexSigMatchTotalMatch = 27, /* 32-bit counter, Number of matches
    435                                            successfully detected by the Regex
    436                                            engines (includes unreported matches) */
    437     bcmStatRegexSigMatchCrossSigFlags = 28, /* 32-bit counter, Number of updates to
    438                                            cross-signature flags */
    439     bcmStatRegexSigMatchFragmentsReceived = 29, /* 32-bit counter, Number of fragmented
    440                                            packets received */
    441     bcmStatRegexSigMatchInPacketError = 30, /* 32-bit counter, Number of packets
    442                                            dropped for incorrect framing signals
    443                                            (SOP, EOP) or error signal asserted
    444                                            anywhere in the packet */
    445     bcmStatRegexSigMatchFlowTrackerError = 31, /* 32-bit counter, Number of packets
    446                                            dropped because the FT indicated an
    447                                            error in a queued packet before EOP */
    448     bcmStatRegexSigMatchPacketLengthError = 32, /* 32-bit counter, Number of packets
    449                                            dropped because of a length error */
    450     bcmStatRegexSigMatchL4ChecksumError = 33, /* 32-bit counter, Number of packets
    451                                            dropped because of an invalid L4
    452                                            (TCP/UDP) checksum */
    453     bcmStatRegexSigMatchFlowDonePacketDrop = 34, /* 32-bit counter, Number of flows that
    454                                            encountered an invalid Flow Table
    455                                            entry error */
    456     bcmStatRegexSigMatchFlowTimestampError = 35, /* 32-bit counter, Number of packets
    457                                            with timestamp errors -- the first
    458                                            packet of the current flow was lost */
    459     bcmStatRegexSigMatchFlowPacketNumError = 36, /* 32-bit counter, Number of flows that
    460                                            encountered an FT packet number
    461                                            mismatch */
    462     bcmStatRegexSigMatchECCError = 37,  /* 32-bit counter, Number of
    463                                            uncorrectable ECC errors detected */
    464     bcmStatRegexSigMatchLast = 37,      /* End of SigMatch part of list */
    465     bcmStatRegexLast = 37,              /* End of list */
    466     bcmStatRegexCount = 27              /* Number of unique enums in the list */
    467 } bcm_regex_stat_t;
    468 
    469 #ifndef BCM_HIDE_DISPATCHABLE
    470 
    471 /* Retrieve a specified regex Flow Tracker statistic. */
    472 extern int bcm_regex_stat_get(
    473     int unit, 
    474     bcm_regex_stat_t type, 
    475     uint64 *val);
    476 
    477 /* Set a specified regex Flow Tracker statistic. */
    478 extern int bcm_regex_stat_set(
    479     int unit, 
    480     bcm_regex_stat_t type, 
    481     uint64 val);
    482 
    483 #endif /* BCM_HIDE_DISPATCHABLE */
    484 
    485 #define BCM_REGEX_POLICY_WITH_ID    0x0001     /* Create policy with supplied ID */
    486 
    487 #ifndef BCM_HIDE_DISPATCHABLE
    488 
    489 /* Create a blank regex policy. */
    490 extern int bcm_regex_policy_create(
    491     int unit, 
    492     int flags, 
    493     bcm_regex_policy_t *policy);
    494 
    495 /* Destroy a regex policy. This deallocates memory only. */
    496 extern int bcm_regex_policy_destroy(
    497     int unit, 
    498     bcm_regex_policy_t policy);
    499 
    500 /* Destroy all regex policy entries. */
    501 extern int bcm_regex_policy_destroy_all(
    502     int unit);
    503 
    504 /* Install a regex policy into the hardware tables. */
    505 extern int bcm_regex_policy_install(
    506     int unit, 
    507     bcm_regex_policy_t policy);
    508 
    509 /* Remove a regex policy from the hardware tables. */
    510 extern int bcm_regex_policy_remove(
    511     int unit, 
    512     bcm_regex_policy_t policy);
    513 
    514 /* Add an action to a regex policy. */
    515 extern int bcm_regex_policy_action_add(
    516     int unit, 
    517     bcm_regex_policy_t policy, 
    518     bcm_field_action_t action, 
    519     uint32 param0, 
    520     uint32 param1);
    521 
    522 /* Add an action to a policy. */
    523 extern int bcm_regex_policy_action_mac_add(
    524     int unit, 
    525     bcm_regex_policy_t policy, 
    526     bcm_field_action_t action, 
    527     bcm_mac_t mac);
    528 
    529 /* Add an action to a regex policy. */
    530 extern int bcm_regex_policy_action_ports_add(
    531     int unit, 
    532     bcm_regex_policy_t policy, 
    533     bcm_field_action_t action, 
    534     bcm_pbmp_t pbmp);
    535 
    536 /* Delete an action from a regex policy. */
    537 extern int bcm_regex_policy_action_delete(
    538     int unit, 
    539     bcm_regex_policy_t policy, 
    540     bcm_field_action_t action, 
    541     uint32 param0, 
    542     uint32 param1);
    543 
    544 /* 
    545  * Retrieve the parameters for an action previously added to a regex
    546  * policy.
    547  */
    548 extern int bcm_regex_policy_action_get(
    549     int unit, 
    550     bcm_regex_policy_t policy, 
    551     bcm_field_action_t action, 
    552     uint32 *param0, 
    553     uint32 *param1);
    554 
    555 /* 
    556  * Retrieve the parameters for an action previously added to a regex
    557  * policy.
    558  */
    559 extern int bcm_regex_policy_action_mac_get(
    560     int unit, 
    561     bcm_regex_policy_t policy, 
    562     bcm_field_action_t action, 
    563     bcm_mac_t *mac);
    564 
    565 /* 
    566  * Retrieve the parameters for an action previously added to a regex
    567  * policy.
    568  */
    569 extern int bcm_regex_policy_action_ports_get(
    570     int unit, 
    571     bcm_regex_policy_t policy, 
    572     bcm_field_action_t action, 
    573     bcm_pbmp_t *pbmp);
    574 
    575 /* 
    576  * Remove an action from a regex_policy.  Same as
    577  * bcm_regex_policy_action_delete for actions without parameters.
    578  */
    579 extern int bcm_regex_policy_action_remove(
    580     int unit, 
    581     bcm_regex_policy_t policy, 
    582     bcm_field_action_t action);
    583 
    584 /* Remove all actions from a regex_policy. */
    585 extern int bcm_regex_policy_action_remove_all(
    586     int unit, 
    587     bcm_regex_policy_t policy);
    588 
    589 /* Attach a policer to a regex policy. */
    590 extern int bcm_regex_policy_policer_attach(
    591     int unit, 
    592     bcm_regex_policy_t policy, 
    593     int level, 
    594     bcm_policer_t policer_id);
    595 
    596 /* Detach a policer from a regex policy. */
    597 extern int bcm_regex_policy_policer_detach(
    598     int unit, 
    599     bcm_regex_policy_t policy, 
    600     int level);
    601 
    602 /* Detach all policers from a regex policy. */
    603 extern int bcm_regex_policy_policer_detach_all(
    604     int unit, 
    605     bcm_regex_policy_t policy);
    606 
    607 /* Get the policer(s) attached to a regex policy. */
    608 extern int bcm_regex_policy_policer_get(
    609     int unit, 
    610     bcm_regex_policy_t policy, 
    611     int level, 
    612     bcm_policer_t *policer_id);
    613 
    614 #endif /* BCM_HIDE_DISPATCHABLE */
    615 
    616 #define BCM_REGEX_STAT_WITH_ID  0x0001     /* Create stat with supplied ID */
    617 
    618 #ifndef BCM_HIDE_DISPATCHABLE
    619 
    620 /* Create stat collection entity. */
    621 extern int bcm_regex_stat_create(
    622     int unit, 
    623     int flags, 
    624     int nstat, 
    625     bcm_field_stat_t *stat_arr, 
    626     int *stat_id);
    627 
    628 /* Create stat collection entity. */
    629 extern int bcm_regex_stat_destroy(
    630     int unit, 
    631     int stat_id);
    632 
    633 /* Attach statistics entity to Regex policy. */
    634 extern int bcm_regex_policy_stat_attach(
    635     int unit, 
    636     bcm_regex_policy_t policy, 
    637     int stat_id);
    638 
    639 /* Detach statistics entity from Regex policy. */
    640 extern int bcm_regex_policy_stat_detach(
    641     int unit, 
    642     bcm_regex_policy_t policy, 
    643     int stat_id);
    644 
    645 /* Get 64 bit counter value for specific statistic type. */
    646 extern int bcm_regex_policy_stat_get(
    647     int unit, 
    648     bcm_regex_policy_t policy, 
    649     int *stat_id);
    650 
    651 #endif /* BCM_HIDE_DISPATCHABLE */
    652 
    653 #define BCM_REGEX_SESSION_KEY_IPV6      0x0001     /* Key is IPv6.  If not set,
    654                                                       key is IPV4. */
    655 #define BCM_REGEX_SESSION_KEY_REPLACE   0x0002     /* If key found in table when
    656                                                       adding, replace entry. */
    657 
    658 /* Regex session key structure. */
    659 typedef struct bcm_regex_session_key_s {
    660     int flags;          /* REGEX_SESSION_KEY_xxx flags */
    661     bcm_ip_t sip;       /* Source IPV4 address. */
    662     bcm_ip_t dip;       /* Destination IPV4 address. */
    663     bcm_ip6_t sip6;     /* Source IPV6 address. */
    664     bcm_ip6_t dip6;     /* Destination IPV6 address. */
    665     uint32 dst_port;    /* L4 destination port */
    666     uint32 src_port;    /* L4 source port */
    667     uint8 protocol;     /* IP protocol. */
    668 } bcm_regex_session_key_t;
    669 
    670 #define BCM_REGEX_SESSION_STATIC    0x0001     /* Will either convert an
    671                                                   existing dynamic session to
    672                                                   static or create a new static
    673                                                   session. If this flag is not
    674                                                   set, the session is assumed to
    675                                                   be dynamic and will only be
    676                                                   updated if it already exists. */
    677 
    678 /* Regex Configuration structure. */
    679 typedef struct bcm_regex_session_s {
    680     int flags;                  /* REGEX_SESSION_xxx flags */
    681     bcm_regex_policy_t policy;  /* The policy to apply to this flow. */
    682     uint32 inactivity_timeout;  /* Units are usec. */
    683     uint32 timestamp;           /* Output - session entry's timestamp. */
    684 } bcm_regex_session_t;
    685 
    686 /* Initialize regex session key structure. */
    687 extern void bcm_regex_session_key_t_init(
    688     bcm_regex_session_key_t *session_key);
    689 
    690 /* Initialize regex session structure. */
    691 extern void bcm_regex_session_t_init(
    692     bcm_regex_session_t *session);
    693 
    694 #ifndef BCM_HIDE_DISPATCHABLE
    695 
    696 /* 
    697  * Adds or updates a session entry. Flags param for future use, values
    698  * 0x1-0x8 reserved.
    699  */
    700 extern int bcm_regex_session_add(
    701     int unit, 
    702     int flags, 
    703     bcm_regex_session_key_t *key, 
    704     bcm_regex_session_t *session);
    705 
    706 /* Updates the policy ID in a session entry. */
    707 extern int bcm_regex_session_policy_update(
    708     int unit, 
    709     int flags, 
    710     int flow_index, 
    711     bcm_regex_policy_t policy);
    712 
    713 /* Deletes an entry from the regex session table. */
    714 extern int bcm_regex_session_delete(
    715     int unit, 
    716     bcm_regex_session_key_t *key);
    717 
    718 /* Returns the session data (if any). Flags param for future use. */
    719 extern int bcm_regex_session_get(
    720     int unit, 
    721     int flags, 
    722     bcm_regex_session_key_t *key, 
    723     bcm_regex_session_t *session);
    724 
    725 #endif /* BCM_HIDE_DISPATCHABLE */
    726 
    727 #define BCM_REGEX_SESSION_TRAVERSE_ALL  0x0001     /* If set, all sessions are
    728                                                       traversed.  Otherwise only
    729                                                       static sessions are
    730                                                       traversed. */
    731 
    732 /*  Prototype for regex session traverse callback. */
    733 typedef int (*bcm_regex_session_traverse_cb)(
    734     int unit, 
    735     bcm_regex_session_key_t *session_key, 
    736     bcm_regex_session_t *session_data, 
    737     void *user_data);
    738 
    739 #ifndef BCM_HIDE_DISPATCHABLE
    740 
    741 /* Traverse regex sessions. */
    742 extern int bcm_regex_session_traverse(
    743     int unit, 
    744     int flags, 
    745     bcm_regex_session_traverse_cb cb, 
    746     void *user_data);
    747 
    748 /* Deletes all the entries from the regex session table. */
    749 extern int bcm_regex_session_delete_all(
    750     int unit);
    751 
    752 #endif /* defined(INCLUDE_REGEX) */
    753 
    754 #endif /* BCM_HIDE_DISPATCHABLE */
    755 
    756 #endif /* __BCM_BREGEX_H__ */