Skip to content

Commit 4b5a3ab

Browse files
SruChalladavem330
authored andcommitted
octeontx2-af: Hardware configuration for inline IPsec
On OcteonTX2/CN10K SoC, the admin function (AF) is the only one with all priviliges to configure HW and alloc resources, PFs and it's VFs have to request AF via mailbox for all their needs. This patch adds new mailbox messages for CPT PFs and VFs to configure HW resources for inline-IPsec. Signed-off-by: Subbaraya Sundeep <[email protected]> Signed-off-by: Srujana Challa <[email protected]> Signed-off-by: Vidya Sagar Velumuri <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 227b964 commit 4b5a3ab

File tree

8 files changed

+367
-3
lines changed

8 files changed

+367
-3
lines changed

drivers/net/ethernet/marvell/octeontx2/af/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ enum nix_scheduler {
191191
#define NIX_CHAN_SDP_CH_START (0x700ull)
192192
#define NIX_CHAN_SDP_CHX(a) (NIX_CHAN_SDP_CH_START + (a))
193193
#define NIX_CHAN_SDP_NUM_CHANS 256
194+
#define NIX_CHAN_CPT_CH_START (0x800ull)
194195

195196
/* The mask is to extract lower 10-bits of channel number
196197
* which CPT will pass to X2P.

drivers/net/ethernet/marvell/octeontx2/af/mbox.h

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ M(CPT_LF_ALLOC, 0xA00, cpt_lf_alloc, cpt_lf_alloc_req_msg, \
186186
M(CPT_LF_FREE, 0xA01, cpt_lf_free, msg_req, msg_rsp) \
187187
M(CPT_RD_WR_REGISTER, 0xA02, cpt_rd_wr_register, cpt_rd_wr_reg_msg, \
188188
cpt_rd_wr_reg_msg) \
189+
M(CPT_INLINE_IPSEC_CFG, 0xA04, cpt_inline_ipsec_cfg, \
190+
cpt_inline_ipsec_cfg_msg, msg_rsp) \
189191
M(CPT_STATS, 0xA05, cpt_sts, cpt_sts_req, cpt_sts_rsp) \
190192
M(CPT_RXC_TIME_CFG, 0xA06, cpt_rxc_time_cfg, cpt_rxc_time_cfg_req, \
191193
msg_rsp) \
@@ -270,6 +272,10 @@ M(NIX_BP_ENABLE, 0x8016, nix_bp_enable, nix_bp_cfg_req, \
270272
nix_bp_cfg_rsp) \
271273
M(NIX_BP_DISABLE, 0x8017, nix_bp_disable, nix_bp_cfg_req, msg_rsp) \
272274
M(NIX_GET_MAC_ADDR, 0x8018, nix_get_mac_addr, msg_req, nix_get_mac_addr_rsp) \
275+
M(NIX_INLINE_IPSEC_CFG, 0x8019, nix_inline_ipsec_cfg, \
276+
nix_inline_ipsec_cfg, msg_rsp) \
277+
M(NIX_INLINE_IPSEC_LF_CFG, 0x801a, nix_inline_ipsec_lf_cfg, \
278+
nix_inline_ipsec_lf_cfg, msg_rsp) \
273279
M(NIX_CN10K_AQ_ENQ, 0x801b, nix_cn10k_aq_enq, nix_cn10k_aq_enq_req, \
274280
nix_cn10k_aq_enq_rsp) \
275281
M(NIX_GET_HW_INFO, 0x801c, nix_get_hw_info, msg_req, nix_hw_info) \
@@ -1065,6 +1071,40 @@ struct nix_bp_cfg_rsp {
10651071
u8 chan_cnt; /* Number of channel for which bpids are assigned */
10661072
};
10671073

1074+
/* Global NIX inline IPSec configuration */
1075+
struct nix_inline_ipsec_cfg {
1076+
struct mbox_msghdr hdr;
1077+
u32 cpt_credit;
1078+
struct {
1079+
u8 egrp;
1080+
u8 opcode;
1081+
u16 param1;
1082+
u16 param2;
1083+
} gen_cfg;
1084+
struct {
1085+
u16 cpt_pf_func;
1086+
u8 cpt_slot;
1087+
} inst_qsel;
1088+
u8 enable;
1089+
};
1090+
1091+
/* Per NIX LF inline IPSec configuration */
1092+
struct nix_inline_ipsec_lf_cfg {
1093+
struct mbox_msghdr hdr;
1094+
u64 sa_base_addr;
1095+
struct {
1096+
u32 tag_const;
1097+
u16 lenm1_max;
1098+
u8 sa_pow2_size;
1099+
u8 tt;
1100+
} ipsec_cfg0;
1101+
struct {
1102+
u32 sa_idx_max;
1103+
u8 sa_idx_w;
1104+
} ipsec_cfg1;
1105+
u8 enable;
1106+
};
1107+
10681108
struct nix_hw_info {
10691109
struct mbox_msghdr hdr;
10701110
u16 rsvs16;
@@ -1399,7 +1439,9 @@ enum cpt_af_status {
13991439
CPT_AF_ERR_LF_INVALID = -903,
14001440
CPT_AF_ERR_ACCESS_DENIED = -904,
14011441
CPT_AF_ERR_SSO_PF_FUNC_INVALID = -905,
1402-
CPT_AF_ERR_NIX_PF_FUNC_INVALID = -906
1442+
CPT_AF_ERR_NIX_PF_FUNC_INVALID = -906,
1443+
CPT_AF_ERR_INLINE_IPSEC_INB_ENA = -907,
1444+
CPT_AF_ERR_INLINE_IPSEC_OUT_ENA = -908
14031445
};
14041446

14051447
/* CPT mbox message formats */
@@ -1420,6 +1462,22 @@ struct cpt_lf_alloc_req_msg {
14201462
int blkaddr;
14211463
};
14221464

1465+
#define CPT_INLINE_INBOUND 0
1466+
#define CPT_INLINE_OUTBOUND 1
1467+
1468+
/* Mailbox message request format for CPT IPsec
1469+
* inline inbound and outbound configuration.
1470+
*/
1471+
struct cpt_inline_ipsec_cfg_msg {
1472+
struct mbox_msghdr hdr;
1473+
u8 enable;
1474+
u8 slot;
1475+
u8 dir;
1476+
u8 sso_pf_func_ovrd;
1477+
u16 sso_pf_func; /* inbound path SSO_PF_FUNC */
1478+
u16 nix_pf_func; /* outbound path NIX_PF_FUNC */
1479+
};
1480+
14231481
/* Mailbox message request and response format for CPT stats. */
14241482
struct cpt_sts_req {
14251483
struct mbox_msghdr hdr;

drivers/net/ethernet/marvell/octeontx2/af/rvu.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,60 @@ static int rvu_lookup_rsrc(struct rvu *rvu, struct rvu_block *block,
12871287
return (val & 0xFFF);
12881288
}
12891289

1290+
int rvu_get_blkaddr_from_slot(struct rvu *rvu, int blktype, u16 pcifunc,
1291+
u16 global_slot, u16 *slot_in_block)
1292+
{
1293+
struct rvu_pfvf *pfvf = rvu_get_pfvf(rvu, pcifunc);
1294+
int numlfs, total_lfs = 0, nr_blocks = 0;
1295+
int i, num_blkaddr[BLK_COUNT] = { 0 };
1296+
struct rvu_block *block;
1297+
int blkaddr = -ENODEV;
1298+
u16 start_slot;
1299+
1300+
if (!is_blktype_attached(pfvf, blktype))
1301+
return -ENODEV;
1302+
1303+
/* Get all the block addresses from which LFs are attached to
1304+
* the given pcifunc in num_blkaddr[].
1305+
*/
1306+
for (blkaddr = BLKADDR_RVUM; blkaddr < BLK_COUNT; blkaddr++) {
1307+
block = &rvu->hw->block[blkaddr];
1308+
if (block->type != blktype)
1309+
continue;
1310+
if (!is_block_implemented(rvu->hw, blkaddr))
1311+
continue;
1312+
1313+
numlfs = rvu_get_rsrc_mapcount(pfvf, blkaddr);
1314+
if (numlfs) {
1315+
total_lfs += numlfs;
1316+
num_blkaddr[nr_blocks] = blkaddr;
1317+
nr_blocks++;
1318+
}
1319+
}
1320+
1321+
if (global_slot >= total_lfs)
1322+
return -ENODEV;
1323+
1324+
/* Based on the given global slot number retrieve the
1325+
* correct block address out of all attached block
1326+
* addresses and slot number in that block.
1327+
*/
1328+
total_lfs = 0;
1329+
blkaddr = -ENODEV;
1330+
for (i = 0; i < nr_blocks; i++) {
1331+
numlfs = rvu_get_rsrc_mapcount(pfvf, num_blkaddr[i]);
1332+
total_lfs += numlfs;
1333+
if (global_slot < total_lfs) {
1334+
blkaddr = num_blkaddr[i];
1335+
start_slot = total_lfs - numlfs;
1336+
*slot_in_block = global_slot - start_slot;
1337+
break;
1338+
}
1339+
}
1340+
1341+
return blkaddr;
1342+
}
1343+
12901344
static void rvu_detach_block(struct rvu *rvu, int pcifunc, int blktype)
12911345
{
12921346
struct rvu_pfvf *pfvf = rvu_get_pfvf(rvu, pcifunc);

drivers/net/ethernet/marvell/octeontx2/af/rvu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,8 @@ int rvu_lf_reset(struct rvu *rvu, struct rvu_block *block, int lf);
656656
int rvu_get_blkaddr(struct rvu *rvu, int blktype, u16 pcifunc);
657657
int rvu_poll_reg(struct rvu *rvu, u64 block, u64 offset, u64 mask, bool zero);
658658
int rvu_get_num_lbk_chans(void);
659+
int rvu_get_blkaddr_from_slot(struct rvu *rvu, int blktype, u16 pcifunc,
660+
u16 global_slot, u16 *slot_in_block);
659661

660662
/* RVU HW reg validation */
661663
enum regmap_block {

drivers/net/ethernet/marvell/octeontx2/af/rvu_cn10k.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,8 @@ int rvu_set_channels_base(struct rvu *rvu)
334334
/* Out of 4096 channels start CPT from 2048 so
335335
* that MSB for CPT channels is always set
336336
*/
337-
if (cpt_chan_base <= 0x800) {
338-
hw->cpt_chan_base = 0x800;
337+
if (cpt_chan_base <= NIX_CHAN_CPT_CH_START) {
338+
hw->cpt_chan_base = NIX_CHAN_CPT_CH_START;
339339
} else {
340340
dev_err(rvu->dev,
341341
"CPT channels could not fit in the range 2048-4095\n");

drivers/net/ethernet/marvell/octeontx2/af/rvu_cpt.c

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,141 @@ int rvu_mbox_handler_cpt_lf_free(struct rvu *rvu, struct msg_req *req,
197197
return ret;
198198
}
199199

200+
static int cpt_inline_ipsec_cfg_inbound(struct rvu *rvu, int blkaddr, u8 cptlf,
201+
struct cpt_inline_ipsec_cfg_msg *req)
202+
{
203+
u16 sso_pf_func = req->sso_pf_func;
204+
u8 nix_sel;
205+
u64 val;
206+
207+
val = rvu_read64(rvu, blkaddr, CPT_AF_LFX_CTL(cptlf));
208+
if (req->enable && (val & BIT_ULL(16))) {
209+
/* IPSec inline outbound path is already enabled for a given
210+
* CPT LF, HRM states that inline inbound & outbound paths
211+
* must not be enabled at the same time for a given CPT LF
212+
*/
213+
return CPT_AF_ERR_INLINE_IPSEC_INB_ENA;
214+
}
215+
/* Check if requested 'CPTLF <=> SSOLF' mapping is valid */
216+
if (sso_pf_func && !is_pffunc_map_valid(rvu, sso_pf_func, BLKTYPE_SSO))
217+
return CPT_AF_ERR_SSO_PF_FUNC_INVALID;
218+
219+
nix_sel = (blkaddr == BLKADDR_CPT1) ? 1 : 0;
220+
/* Enable CPT LF for IPsec inline inbound operations */
221+
if (req->enable)
222+
val |= BIT_ULL(9);
223+
else
224+
val &= ~BIT_ULL(9);
225+
226+
val |= (u64)nix_sel << 8;
227+
rvu_write64(rvu, blkaddr, CPT_AF_LFX_CTL(cptlf), val);
228+
229+
if (sso_pf_func) {
230+
/* Set SSO_PF_FUNC */
231+
val = rvu_read64(rvu, blkaddr, CPT_AF_LFX_CTL2(cptlf));
232+
val |= (u64)sso_pf_func << 32;
233+
val |= (u64)req->nix_pf_func << 48;
234+
rvu_write64(rvu, blkaddr, CPT_AF_LFX_CTL2(cptlf), val);
235+
}
236+
if (req->sso_pf_func_ovrd)
237+
/* Set SSO_PF_FUNC_OVRD for inline IPSec */
238+
rvu_write64(rvu, blkaddr, CPT_AF_ECO, 0x1);
239+
240+
/* Configure the X2P Link register with the cpt base channel number and
241+
* range of channels it should propagate to X2P
242+
*/
243+
if (!is_rvu_otx2(rvu)) {
244+
val = (ilog2(NIX_CHAN_CPT_X2P_MASK + 1) << 16);
245+
val |= rvu->hw->cpt_chan_base;
246+
247+
rvu_write64(rvu, blkaddr, CPT_AF_X2PX_LINK_CFG(0), val);
248+
rvu_write64(rvu, blkaddr, CPT_AF_X2PX_LINK_CFG(1), val);
249+
}
250+
251+
return 0;
252+
}
253+
254+
static int cpt_inline_ipsec_cfg_outbound(struct rvu *rvu, int blkaddr, u8 cptlf,
255+
struct cpt_inline_ipsec_cfg_msg *req)
256+
{
257+
u16 nix_pf_func = req->nix_pf_func;
258+
int nix_blkaddr;
259+
u8 nix_sel;
260+
u64 val;
261+
262+
val = rvu_read64(rvu, blkaddr, CPT_AF_LFX_CTL(cptlf));
263+
if (req->enable && (val & BIT_ULL(9))) {
264+
/* IPSec inline inbound path is already enabled for a given
265+
* CPT LF, HRM states that inline inbound & outbound paths
266+
* must not be enabled at the same time for a given CPT LF
267+
*/
268+
return CPT_AF_ERR_INLINE_IPSEC_OUT_ENA;
269+
}
270+
271+
/* Check if requested 'CPTLF <=> NIXLF' mapping is valid */
272+
if (nix_pf_func && !is_pffunc_map_valid(rvu, nix_pf_func, BLKTYPE_NIX))
273+
return CPT_AF_ERR_NIX_PF_FUNC_INVALID;
274+
275+
/* Enable CPT LF for IPsec inline outbound operations */
276+
if (req->enable)
277+
val |= BIT_ULL(16);
278+
else
279+
val &= ~BIT_ULL(16);
280+
rvu_write64(rvu, blkaddr, CPT_AF_LFX_CTL(cptlf), val);
281+
282+
if (nix_pf_func) {
283+
/* Set NIX_PF_FUNC */
284+
val = rvu_read64(rvu, blkaddr, CPT_AF_LFX_CTL2(cptlf));
285+
val |= (u64)nix_pf_func << 48;
286+
rvu_write64(rvu, blkaddr, CPT_AF_LFX_CTL2(cptlf), val);
287+
288+
nix_blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NIX, nix_pf_func);
289+
nix_sel = (nix_blkaddr == BLKADDR_NIX0) ? 0 : 1;
290+
291+
val = rvu_read64(rvu, blkaddr, CPT_AF_LFX_CTL(cptlf));
292+
val |= (u64)nix_sel << 8;
293+
rvu_write64(rvu, blkaddr, CPT_AF_LFX_CTL(cptlf), val);
294+
}
295+
296+
return 0;
297+
}
298+
299+
int rvu_mbox_handler_cpt_inline_ipsec_cfg(struct rvu *rvu,
300+
struct cpt_inline_ipsec_cfg_msg *req,
301+
struct msg_rsp *rsp)
302+
{
303+
u16 pcifunc = req->hdr.pcifunc;
304+
struct rvu_block *block;
305+
int cptlf, blkaddr, ret;
306+
u16 actual_slot;
307+
308+
blkaddr = rvu_get_blkaddr_from_slot(rvu, BLKTYPE_CPT, pcifunc,
309+
req->slot, &actual_slot);
310+
if (blkaddr < 0)
311+
return CPT_AF_ERR_LF_INVALID;
312+
313+
block = &rvu->hw->block[blkaddr];
314+
315+
cptlf = rvu_get_lf(rvu, block, pcifunc, actual_slot);
316+
if (cptlf < 0)
317+
return CPT_AF_ERR_LF_INVALID;
318+
319+
switch (req->dir) {
320+
case CPT_INLINE_INBOUND:
321+
ret = cpt_inline_ipsec_cfg_inbound(rvu, blkaddr, cptlf, req);
322+
break;
323+
324+
case CPT_INLINE_OUTBOUND:
325+
ret = cpt_inline_ipsec_cfg_outbound(rvu, blkaddr, cptlf, req);
326+
break;
327+
328+
default:
329+
return CPT_AF_ERR_PARAM;
330+
}
331+
332+
return ret;
333+
}
334+
200335
static bool is_valid_offset(struct rvu *rvu, struct cpt_rd_wr_reg_msg *req)
201336
{
202337
u64 offset = req->reg_offset;

0 commit comments

Comments
 (0)