// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2023 Pengutronix, Oleksij Rempel <kernel@pengutronix.de>
/* Access Control List (ACL) structure:
*
* There are multiple groups of registers involved in ACL configuration:
*
* - Matching Rules: These registers define the criteria for matching incoming
* packets based on their header information (Layer 2 MAC, Layer 3 IP, or
* Layer 4 TCP/UDP). Different register settings are used depending on the
* matching rule mode (MD) and the Enable (ENB) settings.
*
* - Action Rules: These registers define how the ACL should modify the packet's
* priority, VLAN tag priority, and forwarding map once a matching rule has
* been triggered. The settings vary depending on whether the matching rule is
* in Count Mode (MD = 01 and ENB = 00) or not.
*
* - Processing Rules: These registers control the overall behavior of the ACL,
* such as selecting which matching rule to apply first, enabling/disabling
* specific rules, or specifying actions for matched packets.
*
* ACL Structure:
* +----------------------+
* +----------------------+ | (optional) |
* | Matching Rules | | Matching Rules |
* | (Layer 2, 3, 4) | | (Layer 2, 3, 4) |
* +----------------------+ +----------------------+
* | |
* \___________________________/
* v
* +----------------------+
* | Processing Rules |
* | (action idx, |
* | matching rule set) |
* +----------------------+
* |
* v
* +----------------------+
* | Action Rules |
* | (Modify Priority, |
* | Forwarding Map, |
* | VLAN tag, etc) |
* +----------------------+
*/
#include <linux/bitops.h>
#include "ksz9477.h"
#include "ksz9477_reg.h"
#include "ksz_common.h"
#define KSZ9477_PORT_ACL_0 0x600
enum ksz9477_acl_port_access {
KSZ9477_ACL_PORT_ACCESS_0 = 0x00,
KSZ9477_ACL_PORT_ACCESS_1 = 0x01,
KSZ9477_ACL_PORT_ACCESS_2 = 0x02,
KSZ9477_ACL_PORT_ACCESS_3 = 0x03,
KSZ9477_ACL_PORT_ACCESS_4 = 0x04,
KSZ9477_ACL_PORT_ACCESS_5 = 0x05,
KSZ9477_ACL_PORT_ACCESS_6 = 0x06,
KSZ9477_ACL_PORT_ACCESS_7 = 0x07,
KSZ9477_ACL_PORT_ACCESS_8 = 0x08,
KSZ9477_ACL_PORT_ACCESS_9 = 0x09,
KSZ9477_ACL_PORT_ACCESS_A = 0x0A,
KSZ9477_ACL_PORT_ACCESS_B = 0x0B,
KSZ9477_ACL_PORT_ACCESS_C = 0x0C,
KSZ9477_ACL_PORT_ACCESS_D = 0x0D,
KSZ9477_ACL_PORT_ACCESS_E = 0x0E,
KSZ9477_ACL_PORT_ACCESS_F = 0x0F,
KSZ9477_ACL_PORT_ACCESS_10 = 0x10,
KSZ9477_ACL_PORT_ACCESS_11 = 0x11
};
#define KSZ9477_ACL_MD_MASK GENMASK(5, 4)
#define KSZ9477_ACL_MD_DISABLE 0
#define KSZ9477_ACL_MD_L2_MAC 1
#define KSZ9477_ACL_MD_L3_IP 2
#define KSZ9477_ACL_MD_L4_TCP_UDP 3
#define KSZ9477_ACL_ENB_MASK GENMASK(3, 2)
#define KSZ9477_ACL_ENB_L2_COUNTER 0
#define KSZ9477_ACL_ENB_L2_TYPE 1
#define KSZ9477_ACL_ENB_L2_MAC 2
#define KSZ9477_ACL_ENB_L2_MAC_TYPE 3
/* only IPv4 src or dst can be used with mask */
#define KSZ9477_ACL_ENB_L3_IPV4_ADDR_MASK 1
/* only IPv4 src and dst can be used without mask */