linux/drivers/net/ethernet/mscc/ocelot_ace.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: (GPL-2.0 OR MIT) */
   2/* Microsemi Ocelot Switch driver
   3 * Copyright (c) 2019 Microsemi Corporation
   4 */
   5
   6#ifndef _MSCC_OCELOT_ACE_H_
   7#define _MSCC_OCELOT_ACE_H_
   8
   9#include "ocelot.h"
  10#include <net/sch_generic.h>
  11#include <net/pkt_cls.h>
  12
  13struct ocelot_ipv4 {
  14        u8 addr[4];
  15};
  16
  17enum ocelot_vcap_bit {
  18        OCELOT_VCAP_BIT_ANY,
  19        OCELOT_VCAP_BIT_0,
  20        OCELOT_VCAP_BIT_1
  21};
  22
  23struct ocelot_vcap_u8 {
  24        u8 value[1];
  25        u8 mask[1];
  26};
  27
  28struct ocelot_vcap_u16 {
  29        u8 value[2];
  30        u8 mask[2];
  31};
  32
  33struct ocelot_vcap_u24 {
  34        u8 value[3];
  35        u8 mask[3];
  36};
  37
  38struct ocelot_vcap_u32 {
  39        u8 value[4];
  40        u8 mask[4];
  41};
  42
  43struct ocelot_vcap_u40 {
  44        u8 value[5];
  45        u8 mask[5];
  46};
  47
  48struct ocelot_vcap_u48 {
  49        u8 value[6];
  50        u8 mask[6];
  51};
  52
  53struct ocelot_vcap_u64 {
  54        u8 value[8];
  55        u8 mask[8];
  56};
  57
  58struct ocelot_vcap_u128 {
  59        u8 value[16];
  60        u8 mask[16];
  61};
  62
  63struct ocelot_vcap_vid {
  64        u16 value;
  65        u16 mask;
  66};
  67
  68struct ocelot_vcap_ipv4 {
  69        struct ocelot_ipv4 value;
  70        struct ocelot_ipv4 mask;
  71};
  72
  73struct ocelot_vcap_udp_tcp {
  74        u16 value;
  75        u16 mask;
  76};
  77
  78enum ocelot_ace_type {
  79        OCELOT_ACE_TYPE_ANY,
  80        OCELOT_ACE_TYPE_ETYPE,
  81        OCELOT_ACE_TYPE_LLC,
  82        OCELOT_ACE_TYPE_SNAP,
  83        OCELOT_ACE_TYPE_ARP,
  84        OCELOT_ACE_TYPE_IPV4,
  85        OCELOT_ACE_TYPE_IPV6
  86};
  87
  88struct ocelot_ace_vlan {
  89        struct ocelot_vcap_vid vid;    /* VLAN ID (12 bit) */
  90        struct ocelot_vcap_u8  pcp;    /* PCP (3 bit) */
  91        enum ocelot_vcap_bit dei;    /* DEI */
  92        enum ocelot_vcap_bit tagged; /* Tagged/untagged frame */
  93};
  94
  95struct ocelot_ace_frame_etype {
  96        struct ocelot_vcap_u48 dmac;
  97        struct ocelot_vcap_u48 smac;
  98        struct ocelot_vcap_u16 etype;
  99        struct ocelot_vcap_u16 data; /* MAC data */
 100};
 101
 102struct ocelot_ace_frame_llc {
 103        struct ocelot_vcap_u48 dmac;
 104        struct ocelot_vcap_u48 smac;
 105
 106        /* LLC header: DSAP at byte 0, SSAP at byte 1, Control at byte 2 */
 107        struct ocelot_vcap_u32 llc;
 108};
 109
 110struct ocelot_ace_frame_snap {
 111        struct ocelot_vcap_u48 dmac;
 112        struct ocelot_vcap_u48 smac;
 113
 114        /* SNAP header: Organization Code at byte 0, Type at byte 3 */
 115        struct ocelot_vcap_u40 snap;
 116};
 117
 118struct ocelot_ace_frame_arp {
 119        struct ocelot_vcap_u48 smac;
 120        enum ocelot_vcap_bit arp;       /* Opcode ARP/RARP */
 121        enum ocelot_vcap_bit req;       /* Opcode request/reply */
 122        enum ocelot_vcap_bit unknown;    /* Opcode unknown */
 123        enum ocelot_vcap_bit smac_match; /* Sender MAC matches SMAC */
 124        enum ocelot_vcap_bit dmac_match; /* Target MAC matches DMAC */
 125
 126        /**< Protocol addr. length 4, hardware length 6 */
 127        enum ocelot_vcap_bit length;
 128
 129        enum ocelot_vcap_bit ip;       /* Protocol address type IP */
 130        enum  ocelot_vcap_bit ethernet; /* Hardware address type Ethernet */
 131        struct ocelot_vcap_ipv4 sip;     /* Sender IP address */
 132        struct ocelot_vcap_ipv4 dip;     /* Target IP address */
 133};
 134
 135struct ocelot_ace_frame_ipv4 {
 136        enum ocelot_vcap_bit ttl;      /* TTL zero */
 137        enum ocelot_vcap_bit fragment; /* Fragment */
 138        enum ocelot_vcap_bit options;  /* Header options */
 139        struct ocelot_vcap_u8 ds;
 140        struct ocelot_vcap_u8 proto;      /* Protocol */
 141        struct ocelot_vcap_ipv4 sip;      /* Source IP address */
 142        struct ocelot_vcap_ipv4 dip;      /* Destination IP address */
 143        struct ocelot_vcap_u48 data;      /* Not UDP/TCP: IP data */
 144        struct ocelot_vcap_udp_tcp sport; /* UDP/TCP: Source port */
 145        struct ocelot_vcap_udp_tcp dport; /* UDP/TCP: Destination port */
 146        enum ocelot_vcap_bit tcp_fin;
 147        enum ocelot_vcap_bit tcp_syn;
 148        enum ocelot_vcap_bit tcp_rst;
 149        enum ocelot_vcap_bit tcp_psh;
 150        enum ocelot_vcap_bit tcp_ack;
 151        enum ocelot_vcap_bit tcp_urg;
 152        enum ocelot_vcap_bit sip_eq_dip;     /* SIP equals DIP  */
 153        enum ocelot_vcap_bit sport_eq_dport; /* SPORT equals DPORT  */
 154        enum ocelot_vcap_bit seq_zero;       /* TCP sequence number is zero */
 155};
 156
 157struct ocelot_ace_frame_ipv6 {
 158        struct ocelot_vcap_u8 proto; /* IPv6 protocol */
 159        struct ocelot_vcap_u128 sip; /* IPv6 source (byte 0-7 ignored) */
 160        enum ocelot_vcap_bit ttl;  /* TTL zero */
 161        struct ocelot_vcap_u8 ds;
 162        struct ocelot_vcap_u48 data; /* Not UDP/TCP: IP data */
 163        struct ocelot_vcap_udp_tcp sport;
 164        struct ocelot_vcap_udp_tcp dport;
 165        enum ocelot_vcap_bit tcp_fin;
 166        enum ocelot_vcap_bit tcp_syn;
 167        enum ocelot_vcap_bit tcp_rst;
 168        enum ocelot_vcap_bit tcp_psh;
 169        enum ocelot_vcap_bit tcp_ack;
 170        enum ocelot_vcap_bit tcp_urg;
 171        enum ocelot_vcap_bit sip_eq_dip;     /* SIP equals DIP  */
 172        enum ocelot_vcap_bit sport_eq_dport; /* SPORT equals DPORT  */
 173        enum ocelot_vcap_bit seq_zero;       /* TCP sequence number is zero */
 174};
 175
 176enum ocelot_ace_action {
 177        OCELOT_ACL_ACTION_DROP,
 178        OCELOT_ACL_ACTION_TRAP,
 179};
 180
 181struct ocelot_ace_stats {
 182        u64 bytes;
 183        u64 pkts;
 184        u64 used;
 185};
 186
 187struct ocelot_ace_rule {
 188        struct list_head list;
 189        struct ocelot_port *port;
 190
 191        u16 prio;
 192        u32 id;
 193
 194        enum ocelot_ace_action action;
 195        struct ocelot_ace_stats stats;
 196        int chip_port;
 197
 198        enum ocelot_vcap_bit dmac_mc;
 199        enum ocelot_vcap_bit dmac_bc;
 200        struct ocelot_ace_vlan vlan;
 201
 202        enum ocelot_ace_type type;
 203        union {
 204                /* ocelot_ACE_TYPE_ANY: No specific fields */
 205                struct ocelot_ace_frame_etype etype;
 206                struct ocelot_ace_frame_llc llc;
 207                struct ocelot_ace_frame_snap snap;
 208                struct ocelot_ace_frame_arp arp;
 209                struct ocelot_ace_frame_ipv4 ipv4;
 210                struct ocelot_ace_frame_ipv6 ipv6;
 211        } frame;
 212};
 213
 214struct ocelot_acl_block {
 215        struct list_head rules;
 216        struct ocelot *ocelot;
 217        int count;
 218};
 219
 220int ocelot_ace_rule_offload_add(struct ocelot_ace_rule *rule);
 221int ocelot_ace_rule_offload_del(struct ocelot_ace_rule *rule);
 222int ocelot_ace_rule_stats_update(struct ocelot_ace_rule *rule);
 223
 224int ocelot_ace_init(struct ocelot *ocelot);
 225void ocelot_ace_deinit(void);
 226
 227int ocelot_setup_tc_block_flower_bind(struct ocelot_port *port,
 228                                      struct flow_block_offload *f);
 229void ocelot_setup_tc_block_flower_unbind(struct ocelot_port *port,
 230                                         struct flow_block_offload *f);
 231
 232#endif /* _MSCC_OCELOT_ACE_H_ */
 233