// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-or-later /* * Copyright 2017 NXP */ #define pr_fmt(fmt) … #include <linux/slab.h> #include "fman_keygen.h" /* Maximum number of HW Ports */ #define FMAN_MAX_NUM_OF_HW_PORTS … /* Maximum number of KeyGen Schemes */ #define FM_KG_MAX_NUM_OF_SCHEMES … /* Number of generic KeyGen Generic Extract Command Registers */ #define FM_KG_NUM_OF_GENERIC_REGS … /* Dummy port ID */ #define DUMMY_PORT_ID … /* Select Scheme Value Register */ #define KG_SCH_DEF_USE_KGSE_DV_0 … #define KG_SCH_DEF_USE_KGSE_DV_1 … /* Registers Shifting values */ #define FM_KG_KGAR_NUM_SHIFT … #define KG_SCH_DEF_L4_PORT_SHIFT … #define KG_SCH_DEF_IP_ADDR_SHIFT … #define KG_SCH_HASH_CONFIG_SHIFT_SHIFT … /* KeyGen Registers bit field masks: */ /* Enable bit field mask for KeyGen General Configuration Register */ #define FM_KG_KGGCR_EN … /* KeyGen Global Registers bit field masks */ #define FM_KG_KGAR_GO … #define FM_KG_KGAR_READ … #define FM_KG_KGAR_WRITE … #define FM_KG_KGAR_SEL_SCHEME_ENTRY … #define FM_KG_KGAR_SCM_WSEL_UPDATE_CNT … #define FM_KG_KGAR_ERR … #define FM_KG_KGAR_SEL_CLS_PLAN_ENTRY … #define FM_KG_KGAR_SEL_PORT_ENTRY … #define FM_KG_KGAR_SEL_PORT_WSEL_SP … #define FM_KG_KGAR_SEL_PORT_WSEL_CPP … /* Error events exceptions */ #define FM_EX_KG_DOUBLE_ECC … #define FM_EX_KG_KEYSIZE_OVERFLOW … /* Scheme Registers bit field masks */ #define KG_SCH_MODE_EN … #define KG_SCH_VSP_NO_KSP_EN … #define KG_SCH_HASH_CONFIG_SYM … /* Known Protocol field codes */ #define KG_SCH_KN_PORT_ID … #define KG_SCH_KN_MACDST … #define KG_SCH_KN_MACSRC … #define KG_SCH_KN_TCI1 … #define KG_SCH_KN_TCI2 … #define KG_SCH_KN_ETYPE … #define KG_SCH_KN_PPPSID … #define KG_SCH_KN_PPPID … #define KG_SCH_KN_MPLS1 … #define KG_SCH_KN_MPLS2 … #define KG_SCH_KN_MPLS_LAST … #define KG_SCH_KN_IPSRC1 … #define KG_SCH_KN_IPDST1 … #define KG_SCH_KN_PTYPE1 … #define KG_SCH_KN_IPTOS_TC1 … #define KG_SCH_KN_IPV6FL1 … #define KG_SCH_KN_IPSRC2 … #define KG_SCH_KN_IPDST2 … #define KG_SCH_KN_PTYPE2 … #define KG_SCH_KN_IPTOS_TC2 … #define KG_SCH_KN_IPV6FL2 … #define KG_SCH_KN_GREPTYPE … #define KG_SCH_KN_IPSEC_SPI … #define KG_SCH_KN_IPSEC_NH … #define KG_SCH_KN_IPPID … #define KG_SCH_KN_L4PSRC … #define KG_SCH_KN_L4PDST … #define KG_SCH_KN_TFLG … /* NIA values */ #define NIA_ENG_BMI … #define NIA_BMI_AC_ENQ_FRAME … #define ENQUEUE_KG_DFLT_NIA … /* Hard-coded configuration: * These values are used as hard-coded values for KeyGen configuration * and they replace user selections for this hard-coded version */ /* Hash distribution shift */ #define DEFAULT_HASH_DIST_FQID_SHIFT … /* Hash shift */ #define DEFAULT_HASH_SHIFT … /* Symmetric hash usage: * Warning: * - the value for symmetric hash usage must be in accordance with hash * key defined below * - according to tests performed, spreading is not working if symmetric * hash is set on true * So ultimately symmetric hash functionality should be always disabled: */ #define DEFAULT_SYMMETRIC_HASH … /* Hash Key extraction fields: */ #define DEFAULT_HASH_KEY_EXTRACT_FIELDS … /* Default values to be used as hash key in case IPv4 or L4 (TCP, UDP) * don't exist in the frame */ /* Default IPv4 address */ #define DEFAULT_HASH_KEY_IPv4_ADDR … /* Default L4 port */ #define DEFAULT_HASH_KEY_L4_PORT … /* KeyGen Memory Mapped Registers: */ /* Scheme Configuration RAM Registers */ struct fman_kg_scheme_regs { … }; /* Port Partition Configuration Registers */ struct fman_kg_pe_regs { … }; /* General Configuration and Status Registers * Global Statistic Counters * KeyGen Global Registers */ struct fman_kg_regs { … }; /* KeyGen Scheme data */ struct keygen_scheme { … }; /* KeyGen driver data */ struct fman_keygen { … }; /* keygen_write_ar_wait * * Write Action Register with specified value, wait for GO bit field to be * idle and then read the error * * regs: KeyGen registers * fmkg_ar: Action Register value * * Return: Zero for success or error code in case of failure */ static int keygen_write_ar_wait(struct fman_kg_regs __iomem *regs, u32 fmkg_ar) { … } /* build_ar_scheme * * Build Action Register value for scheme settings * * scheme_id: Scheme ID * update_counter: update scheme counter * write: true for action to write the scheme or false for read action * * Return: AR value */ static u32 build_ar_scheme(u8 scheme_id, bool update_counter, bool write) { … } /* build_ar_bind_scheme * * Build Action Register value for port binding to schemes * * hwport_id: HW Port ID * write: true for action to write the bind or false for read action * * Return: AR value */ static u32 build_ar_bind_scheme(u8 hwport_id, bool write) { … } /* keygen_write_sp * * Write Scheme Partition Register with specified value * * regs: KeyGen Registers * sp: Scheme Partition register value * add: true to add a scheme partition or false to clear * * Return: none */ static void keygen_write_sp(struct fman_kg_regs __iomem *regs, u32 sp, bool add) { … } /* build_ar_bind_cls_plan * * Build Action Register value for Classification Plan * * hwport_id: HW Port ID * write: true for action to write the CP or false for read action * * Return: AR value */ static u32 build_ar_bind_cls_plan(u8 hwport_id, bool write) { … } /* keygen_write_cpp * * Write Classification Plan Partition Register with specified value * * regs: KeyGen Registers * cpp: CPP register value * * Return: none */ static void keygen_write_cpp(struct fman_kg_regs __iomem *regs, u32 cpp) { … } /* keygen_write_scheme * * Write all Schemes Registers with specified values * * regs: KeyGen Registers * scheme_id: Scheme ID * scheme_regs: Scheme registers values desired to be written * update_counter: update scheme counter * * Return: Zero for success or error code in case of failure */ static int keygen_write_scheme(struct fman_kg_regs __iomem *regs, u8 scheme_id, struct fman_kg_scheme_regs *scheme_regs, bool update_counter) { … } /* get_free_scheme_id * * Find the first free scheme available to be used * * keygen: KeyGen handle * scheme_id: pointer to scheme id * * Return: 0 on success, -EINVAL when the are no available free schemes */ static int get_free_scheme_id(struct fman_keygen *keygen, u8 *scheme_id) { … } /* get_scheme * * Provides the scheme for specified ID * * keygen: KeyGen handle * scheme_id: Scheme ID * * Return: handle to required scheme */ static struct keygen_scheme *get_scheme(struct fman_keygen *keygen, u8 scheme_id) { … } /* keygen_bind_port_to_schemes * * Bind the port to schemes * * keygen: KeyGen handle * scheme_id: id of the scheme to bind to * bind: true to bind the port or false to unbind it * * Return: Zero for success or error code in case of failure */ static int keygen_bind_port_to_schemes(struct fman_keygen *keygen, u8 scheme_id, bool bind) { … } /* keygen_scheme_setup * * Setup the scheme according to required configuration * * keygen: KeyGen handle * scheme_id: scheme ID * enable: true to enable scheme or false to disable it * * Return: Zero for success or error code in case of failure */ static int keygen_scheme_setup(struct fman_keygen *keygen, u8 scheme_id, bool enable) { … } /* keygen_init * * KeyGen initialization: * Initializes and enables KeyGen, allocate driver memory, setup registers, * clear port bindings, invalidate all schemes * * keygen_regs: KeyGen registers base address * * Return: Handle to KeyGen driver */ struct fman_keygen *keygen_init(struct fman_kg_regs __iomem *keygen_regs) { … } EXPORT_SYMBOL(…); /* keygen_port_hashing_init * * Initializes a port for Rx Hashing with specified configuration parameters * * keygen: KeyGen handle * hw_port_id: HW Port ID * hash_base_fqid: Hashing Base FQID used for spreading * hash_size: Hashing size * * Return: Zero for success or error code in case of failure */ int keygen_port_hashing_init(struct fman_keygen *keygen, u8 hw_port_id, u32 hash_base_fqid, u32 hash_size) { … } EXPORT_SYMBOL(…);