FILE
cn10k_ipsec.h
File preview with syntax highlighting.
linux-6.19.14/drivers/net/ethernet/marvell/octeontx2/nic/cn10k_ipsec.h
1/* SPDX-License-Identifier: GPL-2.0 */ 2/* Marvell IPSEC offload driver 3 * 4 * Copyright (C) 2024 Marvell. 5 */ 6 7#ifndef CN10K_IPSEC_H 8#define CN10K_IPSEC_H 9 10#include <linux/types.h> 11 12DECLARE_STATIC_KEY_FALSE(cn10k_ipsec_sa_enabled); 13 14/* CPT instruction size in bytes */ 15#define CN10K_CPT_INST_SIZE 64 16 17/* CPT instruction (CPT_INST_S) queue length */ 18#define CN10K_CPT_INST_QLEN 8200 19 20/* CPT instruction queue size passed to HW is in units of 21 * 40*CPT_INST_S messages. 22 */ 23#define CN10K_CPT_SIZE_DIV40 (CN10K_CPT_INST_QLEN / 40) 24 25/* CPT needs 320 free entries */ 26#define CN10K_CPT_INST_QLEN_EXTRA_BYTES (320 * CN10K_CPT_INST_SIZE) 27#define CN10K_CPT_EXTRA_SIZE_DIV40 (320 / 40) 28 29/* CPT instruction queue length in bytes */ 30#define CN10K_CPT_INST_QLEN_BYTES \ 31 ((CN10K_CPT_SIZE_DIV40 * 40 * CN10K_CPT_INST_SIZE) + \ 32 CN10K_CPT_INST_QLEN_EXTRA_BYTES) 33 34/* CPT instruction group queue length in bytes */ 35#define CN10K_CPT_INST_GRP_QLEN_BYTES \ 36 ((CN10K_CPT_SIZE_DIV40 + CN10K_CPT_EXTRA_SIZE_DIV40) * 16) 37 38/* CPT FC length in bytes */ 39#define CN10K_CPT_Q_FC_LEN 128 40 41/* Default CPT engine group for ipsec offload */ 42#define CN10K_DEF_CPT_IPSEC_EGRP 1 43 44/* CN10K CPT LF registers */ 45#define CPT_LFBASE (BLKTYPE_CPT << RVU_FUNC_BLKADDR_SHIFT) 46#define CN10K_CPT_LF_CTL (CPT_LFBASE | 0x10) 47#define CN10K_CPT_LF_INPROG (CPT_LFBASE | 0x40) 48#define CN10K_CPT_LF_Q_BASE (CPT_LFBASE | 0xf0) 49#define CN10K_CPT_LF_Q_SIZE (CPT_LFBASE | 0x100) 50#define CN10K_CPT_LF_Q_INST_PTR (CPT_LFBASE | 0x110) 51#define CN10K_CPT_LF_Q_GRP_PTR (CPT_LFBASE | 0x120) 52#define CN10K_CPT_LF_NQX(a) (CPT_LFBASE | 0x400 | (a) << 3) 53#define CN10K_CPT_LF_CTX_FLUSH (CPT_LFBASE | 0x510) 54 55/* IPSEC Instruction opcodes */ 56#define CN10K_IPSEC_MAJOR_OP_WRITE_SA 0x01UL 57#define CN10K_IPSEC_MINOR_OP_WRITE_SA 0x09UL 58#define CN10K_IPSEC_MAJOR_OP_OUTB_IPSEC 0x2AUL 59 60enum cn10k_cpt_comp_e { 61 CN10K_CPT_COMP_E_NOTDONE = 0x00, 62 CN10K_CPT_COMP_E_GOOD = 0x01, 63 CN10K_CPT_COMP_E_FAULT = 0x02, 64 CN10K_CPT_COMP_E_HWERR = 0x04, 65 CN10K_CPT_COMP_E_INSTERR = 0x05, 66 CN10K_CPT_COMP_E_WARN = 0x06, 67 CN10K_CPT_COMP_E_MASK = 0x3F 68}; 69 70struct cn10k_cpt_inst_queue { 71 u8 *vaddr; 72 u8 *real_vaddr; 73 dma_addr_t dma_addr; 74 dma_addr_t real_dma_addr; 75 u32 size; 76}; 77 78enum cn10k_cpt_hw_state_e { 79 CN10K_CPT_HW_UNAVAILABLE, 80 CN10K_CPT_HW_AVAILABLE, 81 CN10K_CPT_HW_IN_USE 82}; 83 84struct cn10k_ipsec { 85 /* Outbound CPT */ 86 u64 io_addr; 87 atomic_t cpt_state; 88 struct cn10k_cpt_inst_queue iq; 89 90 /* SA info */ 91 u32 sa_size; 92 u32 outb_sa_count; 93 struct work_struct sa_work; 94 struct workqueue_struct *sa_workq; 95}; 96 97/* CN10K IPSEC Security Association (SA) */ 98/* SA direction */ 99#define CN10K_IPSEC_SA_DIR_INB 0 100#define CN10K_IPSEC_SA_DIR_OUTB 1 101/* SA protocol */ 102#define CN10K_IPSEC_SA_IPSEC_PROTO_AH 0 103#define CN10K_IPSEC_SA_IPSEC_PROTO_ESP 1 104/* SA Encryption Type */ 105#define CN10K_IPSEC_SA_ENCAP_TYPE_AES_GCM 5 106/* SA IPSEC mode Transport/Tunnel */ 107#define CN10K_IPSEC_SA_IPSEC_MODE_TRANSPORT 0 108#define CN10K_IPSEC_SA_IPSEC_MODE_TUNNEL 1 109/* SA AES Key Length */ 110#define CN10K_IPSEC_SA_AES_KEY_LEN_128 1 111#define CN10K_IPSEC_SA_AES_KEY_LEN_192 2 112#define CN10K_IPSEC_SA_AES_KEY_LEN_256 3 113/* IV Source */ 114#define CN10K_IPSEC_SA_IV_SRC_COUNTER 0 115#define CN10K_IPSEC_SA_IV_SRC_PACKET 3 116 117struct cn10k_tx_sa_s { 118 u64 esn_en : 1; /* W0 */ 119 u64 rsvd_w0_1_8 : 8; 120 u64 hw_ctx_off : 7; 121 u64 ctx_id : 16; 122 u64 rsvd_w0_32_47 : 16; 123 u64 ctx_push_size : 7; 124 u64 rsvd_w0_55 : 1; 125 u64 ctx_hdr_size : 2; 126 u64 aop_valid : 1; 127 u64 rsvd_w0_59 : 1; 128 u64 ctx_size : 4; 129 u64 w1; /* W1 */ 130 u64 sa_valid : 1; /* W2 */ 131 u64 sa_dir : 1; 132 u64 rsvd_w2_2_3 : 2; 133 u64 ipsec_mode : 1; 134 u64 ipsec_protocol : 1; 135 u64 aes_key_len : 2; 136 u64 enc_type : 3; 137 u64 rsvd_w2_11_19 : 9; 138 u64 iv_src : 2; 139 u64 rsvd_w2_22_31 : 10; 140 u64 rsvd_w2_32_63 : 32; 141 u64 w3; /* W3 */ 142 u8 cipher_key[32]; /* W4 - W7 */ 143 u32 rsvd_w8_0_31; /* W8 : IV */ 144 u32 iv_gcm_salt; 145 u64 rsvd_w9_w30[22]; /* W9 - W30 */ 146 u64 hw_ctx[6]; /* W31 - W36 */ 147}; 148 149/* CPT instruction parameter-1 */ 150#define CN10K_IPSEC_INST_PARAM1_DIS_L4_CSUM 0x1 151#define CN10K_IPSEC_INST_PARAM1_DIS_L3_CSUM 0x2 152#define CN10K_IPSEC_INST_PARAM1_CRYPTO_MODE 0x20 153#define CN10K_IPSEC_INST_PARAM1_IV_OFFSET_SHIFT 8 154 155/* CPT instruction parameter-2 */ 156#define CN10K_IPSEC_INST_PARAM2_ENC_DATA_OFFSET_SHIFT 0 157#define CN10K_IPSEC_INST_PARAM2_AUTH_DATA_OFFSET_SHIFT 8 158 159/* CPT Instruction Structure */ 160struct cpt_inst_s { 161 u64 nixtxl : 3; /* W0 */ 162 u64 doneint : 1; 163 u64 rsvd_w0_4_15 : 12; 164 u64 dat_offset : 8; 165 u64 ext_param1 : 8; 166 u64 nixtx_offset : 20; 167 u64 rsvd_w0_52_63 : 12; 168 u64 res_addr; /* W1 */ 169 u64 tag : 32; /* W2 */ 170 u64 tt : 2; 171 u64 grp : 10; 172 u64 rsvd_w2_44_47 : 4; 173 u64 rvu_pf_func : 16; 174 u64 qord : 1; /* W3 */ 175 u64 rsvd_w3_1_2 : 2; 176 u64 wqe_ptr : 61; 177 u64 dlen : 16; /* W4 */ 178 u64 param2 : 16; 179 u64 param1 : 16; 180 u64 opcode_major : 8; 181 u64 opcode_minor : 8; 182 u64 dptr; /* W5 */ 183 u64 rptr; /* W6 */ 184 u64 cptr : 60; /* W7 */ 185 u64 ctx_val : 1; 186 u64 egrp : 3; 187}; 188 189/* CPT Instruction Result Structure */ 190struct cpt_res_s { 191 u64 compcode : 7; /* W0 */ 192 u64 doneint : 1; 193 u64 uc_compcode : 8; 194 u64 uc_info : 48; 195 u64 esn; /* W1 */ 196}; 197 198/* CPT SG structure */ 199struct cpt_sg_s { 200 u64 seg1_size : 16; 201 u64 seg2_size : 16; 202 u64 seg3_size : 16; 203 u64 segs : 2; 204 u64 rsvd_63_50 : 14; 205}; 206 207/* CPT LF_INPROG Register */ 208#define CPT_LF_INPROG_INFLIGHT GENMASK_ULL(8, 0) 209#define CPT_LF_INPROG_GRB_CNT GENMASK_ULL(39, 32) 210#define CPT_LF_INPROG_GWB_CNT GENMASK_ULL(47, 40) 211 212/* CPT LF_Q_GRP_PTR Register */ 213#define CPT_LF_Q_GRP_PTR_DQ_PTR GENMASK_ULL(14, 0) 214#define CPT_LF_Q_GRP_PTR_NQ_PTR GENMASK_ULL(46, 32) 215 216/* CPT LF_Q_SIZE Register */ 217#define CPT_LF_Q_BASE_ADDR GENMASK_ULL(52, 7) 218 219/* CPT LF_Q_SIZE Register */ 220#define CPT_LF_Q_SIZE_DIV40 GENMASK_ULL(14, 0) 221 222/* CPT LF CTX Flush Register */ 223#define CPT_LF_CTX_FLUSH_CPTR GENMASK_ULL(45, 0) 224 225#ifdef CONFIG_XFRM_OFFLOAD 226int cn10k_ipsec_init(struct net_device *netdev); 227void cn10k_ipsec_clean(struct otx2_nic *pf); 228int cn10k_ipsec_ethtool_init(struct net_device *netdev, bool enable); 229bool otx2_sqe_add_sg_ipsec(struct otx2_nic *pfvf, struct otx2_snd_queue *sq, 230 struct sk_buff *skb, int num_segs, int *offset); 231bool cn10k_ipsec_transmit(struct otx2_nic *pf, struct netdev_queue *txq, 232 struct otx2_snd_queue *sq, struct sk_buff *skb, 233 int num_segs, int size); 234#else 235static inline __maybe_unused int cn10k_ipsec_init(struct net_device *netdev) 236{ 237 return 0; 238} 239 240static inline __maybe_unused void cn10k_ipsec_clean(struct otx2_nic *pf) 241{ 242} 243 244static inline __maybe_unused 245int cn10k_ipsec_ethtool_init(struct net_device *netdev, bool enable) 246{ 247 return 0; 248} 249 250static inline bool __maybe_unused 251otx2_sqe_add_sg_ipsec(struct otx2_nic *pfvf, struct otx2_snd_queue *sq, 252 struct sk_buff *skb, int num_segs, int *offset) 253{ 254 return true; 255} 256 257static inline bool __maybe_unused 258cn10k_ipsec_transmit(struct otx2_nic *pf, struct netdev_queue *txq, 259 struct otx2_snd_queue *sq, struct sk_buff *skb, 260 int num_segs, int size) 261{ 262 return true; 263} 264#endif 265#endif // CN10K_IPSEC_H
~/
Read-only file preview.