Skip to content

Commit 691d30b

Browse files
Subbaraya Sundeepgregkh
authored andcommitted
octeontx2: Set appropriate PF, VF masks and shifts based on silicon
[ Upstream commit 25d51eb ] Number of RVU PFs on CN20K silicon have increased to 96 from maximum of 32 that were supported on earlier silicons. Every RVU PF and VF is identified by HW using a 16bit PF_FUNC value. Due to the change in Max number of PFs in CN20K, the bit encoding of this PF_FUNC has changed. This patch handles the change by using helper functions(using silicon check) to use PF,VF masks and shifts to support both new silicon CN20K, OcteonTx series. These helper functions are used in different modules. Also moved the NIX AF register offset macros to other files which will be posted in coming patches. Signed-off-by: Subbaraya Sundeep <sbhatta@marvell.com> Signed-off-by: Sai Krishna <saikrishnag@marvell.com> Signed-off-by: Sunil Kovvuri Goutham <sgoutham@marvell.com> Link: https://patch.msgid.link/1749639716-13868-2-git-send-email-sbhatta@marvell.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Stable-dep-of: d280233 ("Octeontx2-af: Fix NIX X2P calibration failures") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent aaec542 commit 691d30b

26 files changed

+225
-203
lines changed

drivers/crypto/marvell/octeontx2/otx2_cpt_common.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
#define OTX2_CPT_MAX_VFS_NUM 128
1919
#define OTX2_CPT_RVU_FUNC_ADDR_S(blk, slot, offs) \
2020
(((blk) << 20) | ((slot) << 12) | (offs))
21-
#define OTX2_CPT_RVU_PFFUNC(pf, func) \
22-
((((pf) & RVU_PFVF_PF_MASK) << RVU_PFVF_PF_SHIFT) | \
23-
(((func) & RVU_PFVF_FUNC_MASK) << RVU_PFVF_FUNC_SHIFT))
21+
22+
#define OTX2_CPT_RVU_PFFUNC(pdev, pf, func) rvu_make_pcifunc(pdev, pf, func)
2423

2524
#define OTX2_CPT_INVALID_CRYPTO_ENG_GRP 0xFF
2625
#define OTX2_CPT_NAME_LENGTH 64

drivers/crypto/marvell/octeontx2/otx2_cptpf_mbox.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ static int send_inline_ipsec_inbound_msg(struct otx2_cptpf_dev *cptpf,
142142
memset(req, 0, sizeof(*req));
143143
req->hdr.id = MBOX_MSG_CPT_INLINE_IPSEC_CFG;
144144
req->hdr.sig = OTX2_MBOX_REQ_SIG;
145-
req->hdr.pcifunc = OTX2_CPT_RVU_PFFUNC(cptpf->pf_id, 0);
145+
req->hdr.pcifunc = OTX2_CPT_RVU_PFFUNC(cptpf->pdev, cptpf->pf_id, 0);
146146
req->dir = CPT_INLINE_INBOUND;
147147
req->slot = slot;
148148
req->sso_pf_func_ovrd = cptpf->sso_pf_func_ovrd;
@@ -184,7 +184,8 @@ static int rx_inline_ipsec_lf_cfg(struct otx2_cptpf_dev *cptpf, u8 egrp,
184184
nix_req->gen_cfg.opcode = cpt_inline_rx_opcode(pdev);
185185
nix_req->gen_cfg.param1 = req->param1;
186186
nix_req->gen_cfg.param2 = req->param2;
187-
nix_req->inst_qsel.cpt_pf_func = OTX2_CPT_RVU_PFFUNC(cptpf->pf_id, 0);
187+
nix_req->inst_qsel.cpt_pf_func =
188+
OTX2_CPT_RVU_PFFUNC(cptpf->pdev, cptpf->pf_id, 0);
188189
nix_req->inst_qsel.cpt_slot = 0;
189190
ret = otx2_cpt_send_mbox_msg(&cptpf->afpf_mbox, pdev);
190191
if (ret)
@@ -392,9 +393,8 @@ void otx2_cptpf_vfpf_mbox_handler(struct work_struct *work)
392393
msg = (struct mbox_msghdr *)(mdev->mbase + offset);
393394

394395
/* Set which VF sent this message based on mbox IRQ */
395-
msg->pcifunc = ((u16)cptpf->pf_id << RVU_PFVF_PF_SHIFT) |
396-
((vf->vf_id + 1) & RVU_PFVF_FUNC_MASK);
397-
396+
msg->pcifunc = rvu_make_pcifunc(cptpf->pdev, cptpf->pf_id,
397+
(vf->vf_id + 1));
398398
err = cptpf_handle_vf_req(cptpf, vf, msg,
399399
msg->next_msgoff - offset);
400400
/*
@@ -469,8 +469,7 @@ static void process_afpf_mbox_msg(struct otx2_cptpf_dev *cptpf,
469469

470470
switch (msg->id) {
471471
case MBOX_MSG_READY:
472-
cptpf->pf_id = (msg->pcifunc >> RVU_PFVF_PF_SHIFT) &
473-
RVU_PFVF_PF_MASK;
472+
cptpf->pf_id = rvu_get_pf(cptpf->pdev, msg->pcifunc);
474473
break;
475474
case MBOX_MSG_MSIX_OFFSET:
476475
rsp_msix = (struct msix_offset_rsp *) msg;

drivers/crypto/marvell/octeontx2/otx2_cptpf_ucode.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ static int cptx_set_ucode_base(struct otx2_cpt_eng_grp_info *eng_grp,
176176
/* Set PF number for microcode fetches */
177177
ret = otx2_cpt_write_af_reg(&cptpf->afpf_mbox, cptpf->pdev,
178178
CPT_AF_PF_FUNC,
179-
cptpf->pf_id << RVU_PFVF_PF_SHIFT, blkaddr);
179+
rvu_make_pcifunc(cptpf->pdev,
180+
cptpf->pf_id, 0),
181+
blkaddr);
180182
if (ret)
181183
return ret;
182184

drivers/crypto/marvell/octeontx2/otx2_cptvf_mbox.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ int otx2_cptvf_send_eng_grp_num_msg(struct otx2_cptvf_dev *cptvf, int eng_type)
189189
}
190190
req->hdr.id = MBOX_MSG_GET_ENG_GRP_NUM;
191191
req->hdr.sig = OTX2_MBOX_REQ_SIG;
192-
req->hdr.pcifunc = OTX2_CPT_RVU_PFFUNC(cptvf->vf_id, 0);
192+
req->hdr.pcifunc = OTX2_CPT_RVU_PFFUNC(cptvf->pdev, cptvf->vf_id, 0);
193193
req->eng_type = eng_type;
194194

195195
return otx2_cpt_send_mbox_msg(mbox, pdev);
@@ -210,7 +210,7 @@ int otx2_cptvf_send_kvf_limits_msg(struct otx2_cptvf_dev *cptvf)
210210
}
211211
req->id = MBOX_MSG_GET_KVF_LIMITS;
212212
req->sig = OTX2_MBOX_REQ_SIG;
213-
req->pcifunc = OTX2_CPT_RVU_PFFUNC(cptvf->vf_id, 0);
213+
req->pcifunc = OTX2_CPT_RVU_PFFUNC(cptvf->pdev, cptvf->vf_id, 0);
214214

215215
return otx2_cpt_send_mbox_msg(mbox, pdev);
216216
}
@@ -230,7 +230,7 @@ int otx2_cptvf_send_caps_msg(struct otx2_cptvf_dev *cptvf)
230230
}
231231
req->id = MBOX_MSG_GET_CAPS;
232232
req->sig = OTX2_MBOX_REQ_SIG;
233-
req->pcifunc = OTX2_CPT_RVU_PFFUNC(cptvf->vf_id, 0);
233+
req->pcifunc = OTX2_CPT_RVU_PFFUNC(cptvf->pdev, cptvf->vf_id, 0);
234234

235235
return otx2_cpt_send_mbox_msg(mbox, pdev);
236236
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ int mcs_add_intr_wq_entry(struct mcs *mcs, struct mcs_intr_event *event)
9797
if (pcifunc & RVU_PFVF_FUNC_MASK)
9898
pfvf = &mcs->vf[rvu_get_hwvf(rvu, pcifunc)];
9999
else
100-
pfvf = &mcs->pf[rvu_get_pf(pcifunc)];
100+
pfvf = &mcs->pf[rvu_get_pf(rvu->pdev, pcifunc)];
101101

102102
event->intr_mask &= pfvf->intr_mask;
103103

@@ -123,7 +123,7 @@ static int mcs_notify_pfvf(struct mcs_intr_event *event, struct rvu *rvu)
123123
struct mcs_intr_info *req;
124124
int pf;
125125

126-
pf = rvu_get_pf(event->pcifunc);
126+
pf = rvu_get_pf(rvu->pdev, event->pcifunc);
127127

128128
mutex_lock(&rvu->mbox_lock);
129129

@@ -193,7 +193,7 @@ int rvu_mbox_handler_mcs_intr_cfg(struct rvu *rvu,
193193
if (pcifunc & RVU_PFVF_FUNC_MASK)
194194
pfvf = &mcs->vf[rvu_get_hwvf(rvu, pcifunc)];
195195
else
196-
pfvf = &mcs->pf[rvu_get_pf(pcifunc)];
196+
pfvf = &mcs->pf[rvu_get_pf(rvu->pdev, pcifunc)];
197197

198198
mcs->pf_map[0] = pcifunc;
199199
pfvf->intr_mask = req->intr_mask;

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

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ int rvu_get_blkaddr(struct rvu *rvu, int blktype, u16 pcifunc)
294294
devnum = rvu_get_hwvf(rvu, pcifunc);
295295
} else {
296296
is_pf = true;
297-
devnum = rvu_get_pf(pcifunc);
297+
devnum = rvu_get_pf(rvu->pdev, pcifunc);
298298
}
299299

300300
/* Check if the 'pcifunc' has a NIX LF from 'BLKADDR_NIX0' or
@@ -359,7 +359,7 @@ static void rvu_update_rsrc_map(struct rvu *rvu, struct rvu_pfvf *pfvf,
359359
devnum = rvu_get_hwvf(rvu, pcifunc);
360360
} else {
361361
is_pf = true;
362-
devnum = rvu_get_pf(pcifunc);
362+
devnum = rvu_get_pf(rvu->pdev, pcifunc);
363363
}
364364

365365
block->fn_map[lf] = attach ? pcifunc : 0;
@@ -400,11 +400,6 @@ static void rvu_update_rsrc_map(struct rvu *rvu, struct rvu_pfvf *pfvf,
400400
rvu_write64(rvu, BLKADDR_RVUM, reg | (devnum << 16), num_lfs);
401401
}
402402

403-
inline int rvu_get_pf(u16 pcifunc)
404-
{
405-
return (pcifunc >> RVU_PFVF_PF_SHIFT) & RVU_PFVF_PF_MASK;
406-
}
407-
408403
void rvu_get_pf_numvfs(struct rvu *rvu, int pf, int *numvfs, int *hwvf)
409404
{
410405
u64 cfg;
@@ -422,7 +417,7 @@ int rvu_get_hwvf(struct rvu *rvu, int pcifunc)
422417
int pf, func;
423418
u64 cfg;
424419

425-
pf = rvu_get_pf(pcifunc);
420+
pf = rvu_get_pf(rvu->pdev, pcifunc);
426421
func = pcifunc & RVU_PFVF_FUNC_MASK;
427422

428423
/* Get first HWVF attached to this PF */
@@ -437,15 +432,15 @@ struct rvu_pfvf *rvu_get_pfvf(struct rvu *rvu, int pcifunc)
437432
if (pcifunc & RVU_PFVF_FUNC_MASK)
438433
return &rvu->hwvf[rvu_get_hwvf(rvu, pcifunc)];
439434
else
440-
return &rvu->pf[rvu_get_pf(pcifunc)];
435+
return &rvu->pf[rvu_get_pf(rvu->pdev, pcifunc)];
441436
}
442437

443438
static bool is_pf_func_valid(struct rvu *rvu, u16 pcifunc)
444439
{
445440
int pf, vf, nvfs;
446441
u64 cfg;
447442

448-
pf = rvu_get_pf(pcifunc);
443+
pf = rvu_get_pf(rvu->pdev, pcifunc);
449444
if (pf >= rvu->hw->total_pfs)
450445
return false;
451446

@@ -1487,7 +1482,7 @@ int rvu_get_nix_blkaddr(struct rvu *rvu, u16 pcifunc)
14871482
pf = rvu_get_pfvf(rvu, pcifunc & ~RVU_PFVF_FUNC_MASK);
14881483

14891484
/* All CGX mapped PFs are set with assigned NIX block during init */
1490-
if (is_pf_cgxmapped(rvu, rvu_get_pf(pcifunc))) {
1485+
if (is_pf_cgxmapped(rvu, rvu_get_pf(rvu->pdev, pcifunc))) {
14911486
blkaddr = pf->nix_blkaddr;
14921487
} else if (is_lbk_vf(rvu, pcifunc)) {
14931488
vf = pcifunc - 1;
@@ -1501,7 +1496,7 @@ int rvu_get_nix_blkaddr(struct rvu *rvu, u16 pcifunc)
15011496
}
15021497

15031498
/* if SDP1 then the blkaddr is NIX1 */
1504-
if (is_sdp_pfvf(pcifunc) && pf->sdp_info->node_id == 1)
1499+
if (is_sdp_pfvf(rvu, pcifunc) && pf->sdp_info->node_id == 1)
15051500
blkaddr = BLKADDR_NIX1;
15061501

15071502
switch (blkaddr) {
@@ -2006,7 +2001,7 @@ int rvu_mbox_handler_vf_flr(struct rvu *rvu, struct msg_req *req,
20062001

20072002
vf = pcifunc & RVU_PFVF_FUNC_MASK;
20082003
cfg = rvu_read64(rvu, BLKADDR_RVUM,
2009-
RVU_PRIV_PFX_CFG(rvu_get_pf(pcifunc)));
2004+
RVU_PRIV_PFX_CFG(rvu_get_pf(rvu->pdev, pcifunc)));
20102005
numvfs = (cfg >> 12) & 0xFF;
20112006

20122007
if (vf && vf <= numvfs)
@@ -2229,9 +2224,8 @@ static void __rvu_mbox_handler(struct rvu_work *mwork, int type, bool poll)
22292224
/* Set which PF/VF sent this message based on mbox IRQ */
22302225
switch (type) {
22312226
case TYPE_AFPF:
2232-
msg->pcifunc &=
2233-
~(RVU_PFVF_PF_MASK << RVU_PFVF_PF_SHIFT);
2234-
msg->pcifunc |= (devid << RVU_PFVF_PF_SHIFT);
2227+
msg->pcifunc &= rvu_pcifunc_pf_mask(rvu->pdev);
2228+
msg->pcifunc |= rvu_make_pcifunc(rvu->pdev, devid, 0);
22352229
break;
22362230
case TYPE_AFVF:
22372231
msg->pcifunc &=
@@ -2249,7 +2243,7 @@ static void __rvu_mbox_handler(struct rvu_work *mwork, int type, bool poll)
22492243
if (msg->pcifunc & RVU_PFVF_FUNC_MASK)
22502244
dev_warn(rvu->dev, "Error %d when processing message %s (0x%x) from PF%d:VF%d\n",
22512245
err, otx2_mbox_id2name(msg->id),
2252-
msg->id, rvu_get_pf(msg->pcifunc),
2246+
msg->id, rvu_get_pf(rvu->pdev, msg->pcifunc),
22532247
(msg->pcifunc & RVU_PFVF_FUNC_MASK) - 1);
22542248
else
22552249
dev_warn(rvu->dev, "Error %d when processing message %s (0x%x) from PF%d\n",
@@ -2773,7 +2767,7 @@ static void rvu_flr_handler(struct work_struct *work)
27732767

27742768
cfg = rvu_read64(rvu, BLKADDR_RVUM, RVU_PRIV_PFX_CFG(pf));
27752769
numvfs = (cfg >> 12) & 0xFF;
2776-
pcifunc = pf << RVU_PFVF_PF_SHIFT;
2770+
pcifunc = rvu_make_pcifunc(rvu->pdev, pf, 0);
27772771

27782772
for (vf = 0; vf < numvfs; vf++)
27792773
__rvu_flr_handler(rvu, (pcifunc | (vf + 1)));

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

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <linux/pci.h>
1212
#include <net/devlink.h>
13+
#include <linux/soc/marvell/silicons.h>
1314

1415
#include "rvu_struct.h"
1516
#include "rvu_devlink.h"
@@ -43,10 +44,34 @@
4344
#define MAX_CPT_BLKS 2
4445

4546
/* PF_FUNC */
46-
#define RVU_PFVF_PF_SHIFT 10
47-
#define RVU_PFVF_PF_MASK 0x3F
48-
#define RVU_PFVF_FUNC_SHIFT 0
49-
#define RVU_PFVF_FUNC_MASK 0x3FF
47+
#define RVU_OTX2_PFVF_PF_SHIFT 10
48+
#define RVU_OTX2_PFVF_PF_MASK 0x3F
49+
#define RVU_PFVF_FUNC_SHIFT 0
50+
#define RVU_PFVF_FUNC_MASK 0x3FF
51+
#define RVU_CN20K_PFVF_PF_SHIFT 9
52+
#define RVU_CN20K_PFVF_PF_MASK 0x7F
53+
54+
static inline u16 rvu_make_pcifunc(struct pci_dev *pdev, int pf, int func)
55+
{
56+
if (is_cn20k(pdev))
57+
return ((pf & RVU_CN20K_PFVF_PF_MASK) <<
58+
RVU_CN20K_PFVF_PF_SHIFT) |
59+
((func & RVU_PFVF_FUNC_MASK) <<
60+
RVU_PFVF_FUNC_SHIFT);
61+
else
62+
return ((pf & RVU_OTX2_PFVF_PF_MASK) <<
63+
RVU_OTX2_PFVF_PF_SHIFT) |
64+
((func & RVU_PFVF_FUNC_MASK) <<
65+
RVU_PFVF_FUNC_SHIFT);
66+
}
67+
68+
static inline int rvu_pcifunc_pf_mask(struct pci_dev *pdev)
69+
{
70+
if (is_cn20k(pdev))
71+
return ~(RVU_CN20K_PFVF_PF_MASK << RVU_CN20K_PFVF_PF_SHIFT);
72+
else
73+
return ~(RVU_OTX2_PFVF_PF_MASK << RVU_OTX2_PFVF_PF_SHIFT);
74+
}
5075

5176
#ifdef CONFIG_DEBUG_FS
5277
struct dump_ctx {
@@ -836,7 +861,6 @@ int rvu_alloc_rsrc_contig(struct rsrc_bmap *rsrc, int nrsrc);
836861
void rvu_free_rsrc_contig(struct rsrc_bmap *rsrc, int nrsrc, int start);
837862
bool rvu_rsrc_check_contig(struct rsrc_bmap *rsrc, int nrsrc);
838863
u16 rvu_get_rsrc_mapcount(struct rvu_pfvf *pfvf, int blkaddr);
839-
int rvu_get_pf(u16 pcifunc);
840864
struct rvu_pfvf *rvu_get_pfvf(struct rvu *rvu, int pcifunc);
841865
void rvu_get_pf_numvfs(struct rvu *rvu, int pf, int *numvfs, int *hwvf);
842866
bool is_block_implemented(struct rvu_hwinfo *hw, int blkaddr);
@@ -865,8 +889,8 @@ void rvu_aq_free(struct rvu *rvu, struct admin_queue *aq);
865889

866890
/* SDP APIs */
867891
int rvu_sdp_init(struct rvu *rvu);
868-
bool is_sdp_pfvf(u16 pcifunc);
869-
bool is_sdp_pf(u16 pcifunc);
892+
bool is_sdp_pfvf(struct rvu *rvu, u16 pcifunc);
893+
bool is_sdp_pf(struct rvu *rvu, u16 pcifunc);
870894
bool is_sdp_vf(struct rvu *rvu, u16 pcifunc);
871895

872896
static inline bool is_rep_dev(struct rvu *rvu, u16 pcifunc)
@@ -877,11 +901,21 @@ static inline bool is_rep_dev(struct rvu *rvu, u16 pcifunc)
877901
return false;
878902
}
879903

904+
static inline int rvu_get_pf(struct pci_dev *pdev, u16 pcifunc)
905+
{
906+
if (is_cn20k(pdev))
907+
return (pcifunc >> RVU_CN20K_PFVF_PF_SHIFT) &
908+
RVU_CN20K_PFVF_PF_MASK;
909+
else
910+
return (pcifunc >> RVU_OTX2_PFVF_PF_SHIFT) &
911+
RVU_OTX2_PFVF_PF_MASK;
912+
}
913+
880914
/* CGX APIs */
881915
static inline bool is_pf_cgxmapped(struct rvu *rvu, u8 pf)
882916
{
883917
return (pf >= PF_CGXMAP_BASE && pf <= rvu->cgx_mapped_pfs) &&
884-
!is_sdp_pf(pf << RVU_PFVF_PF_SHIFT);
918+
!is_sdp_pf(rvu, rvu_make_pcifunc(rvu->pdev, pf, 0));
885919
}
886920

887921
static inline void rvu_get_cgx_lmac_id(u8 map, u8 *cgx_id, u8 *lmac_id)
@@ -893,7 +927,7 @@ static inline void rvu_get_cgx_lmac_id(u8 map, u8 *cgx_id, u8 *lmac_id)
893927
static inline bool is_cgx_vf(struct rvu *rvu, u16 pcifunc)
894928
{
895929
return ((pcifunc & RVU_PFVF_FUNC_MASK) &&
896-
is_pf_cgxmapped(rvu, rvu_get_pf(pcifunc)));
930+
is_pf_cgxmapped(rvu, rvu_get_pf(rvu->pdev, pcifunc)));
897931
}
898932

899933
#define M(_name, _id, fn_name, req, rsp) \

0 commit comments

Comments
 (0)