Skip to content

Commit 23999b3

Browse files
Geetha sowjanyadavem330
authored andcommitted
octeontx2-af: Enable or disable CGX internal loopback
Add support to enable or disable internal loopback mode in CGX. New mbox IDs CGX_INTLBK_ENABLE/DISABLE added for this. Signed-off-by: Geetha sowjanya <[email protected]> Signed-off-by: Linu Cherian <[email protected]> Signed-off-by: Sunil Goutham <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 61071a8 commit 23999b3

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,36 @@ static inline u8 cgx_get_lmac_type(struct cgx *cgx, int lmac_id)
194194
return (cfg >> CGX_LMAC_TYPE_SHIFT) & CGX_LMAC_TYPE_MASK;
195195
}
196196

197+
/* Configure CGX LMAC in internal loopback mode */
198+
int cgx_lmac_internal_loopback(void *cgxd, int lmac_id, bool enable)
199+
{
200+
struct cgx *cgx = cgxd;
201+
u8 lmac_type;
202+
u64 cfg;
203+
204+
if (!cgx || lmac_id >= cgx->lmac_count)
205+
return -ENODEV;
206+
207+
lmac_type = cgx_get_lmac_type(cgx, lmac_id);
208+
if (lmac_type == LMAC_MODE_SGMII || lmac_type == LMAC_MODE_QSGMII) {
209+
cfg = cgx_read(cgx, lmac_id, CGXX_GMP_PCS_MRX_CTL);
210+
if (enable)
211+
cfg |= CGXX_GMP_PCS_MRX_CTL_LBK;
212+
else
213+
cfg &= ~CGXX_GMP_PCS_MRX_CTL_LBK;
214+
cgx_write(cgx, lmac_id, CGXX_GMP_PCS_MRX_CTL, cfg);
215+
} else {
216+
cfg = cgx_read(cgx, lmac_id, CGXX_SPUX_CONTROL1);
217+
if (enable)
218+
cfg |= CGXX_SPUX_CONTROL1_LBK;
219+
else
220+
cfg &= ~CGXX_SPUX_CONTROL1_LBK;
221+
cgx_write(cgx, lmac_id, CGXX_SPUX_CONTROL1, cfg);
222+
}
223+
return 0;
224+
}
225+
EXPORT_SYMBOL(cgx_lmac_internal_loopback);
226+
197227
void cgx_lmac_promisc_config(int cgx_id, int lmac_id, bool enable)
198228
{
199229
struct cgx *cgx = cgx_get_pdata(cgx_id);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
#define CGXX_SCRATCH0_REG 0x1050
5151
#define CGXX_SCRATCH1_REG 0x1058
5252
#define CGX_CONST 0x2000
53+
#define CGXX_SPUX_CONTROL1 0x10000
54+
#define CGXX_SPUX_CONTROL1_LBK BIT_ULL(14)
55+
#define CGXX_GMP_PCS_MRX_CTL 0x30000
56+
#define CGXX_GMP_PCS_MRX_CTL_LBK BIT_ULL(14)
5357

5458
#define CGX_COMMAND_REG CGXX_SCRATCH1_REG
5559
#define CGX_EVENT_REG CGXX_SCRATCH0_REG
@@ -100,6 +104,7 @@ int cgx_lmac_rx_tx_enable(void *cgxd, int lmac_id, bool enable);
100104
int cgx_lmac_addr_set(u8 cgx_id, u8 lmac_id, u8 *mac_addr);
101105
u64 cgx_lmac_addr_get(u8 cgx_id, u8 lmac_id);
102106
void cgx_lmac_promisc_config(int cgx_id, int lmac_id, bool enable);
107+
int cgx_lmac_internal_loopback(void *cgxd, int lmac_id, bool enable);
103108
int cgx_get_link_info(void *cgxd, int lmac_id,
104109
struct cgx_link_user_info *linfo);
105110
#endif /* CGX_H */

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ M(CGX_PROMISC_DISABLE, 0x206, msg_req, msg_rsp) \
136136
M(CGX_START_LINKEVENTS, 0x207, msg_req, msg_rsp) \
137137
M(CGX_STOP_LINKEVENTS, 0x208, msg_req, msg_rsp) \
138138
M(CGX_GET_LINKINFO, 0x209, msg_req, cgx_link_info_msg) \
139+
M(CGX_INTLBK_ENABLE, 0x20A, msg_req, msg_rsp) \
140+
M(CGX_INTLBK_DISABLE, 0x20B, msg_req, msg_rsp) \
139141
/* NPA mbox IDs (range 0x400 - 0x5FF) */ \
140142
/* SSO/SSOW mbox IDs (range 0x600 - 0x7FF) */ \
141143
/* TIM mbox IDs (range 0x800 - 0x9FF) */ \

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,8 @@ int rvu_mbox_handler_CGX_STOP_LINKEVENTS(struct rvu *rvu, struct msg_req *req,
192192
struct msg_rsp *rsp);
193193
int rvu_mbox_handler_CGX_GET_LINKINFO(struct rvu *rvu, struct msg_req *req,
194194
struct cgx_link_info_msg *rsp);
195+
int rvu_mbox_handler_CGX_INTLBK_ENABLE(struct rvu *rvu, struct msg_req *req,
196+
struct msg_rsp *rsp);
197+
int rvu_mbox_handler_CGX_INTLBK_DISABLE(struct rvu *rvu, struct msg_req *req,
198+
struct msg_rsp *rsp);
195199
#endif /* RVU_H */

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,3 +479,34 @@ int rvu_mbox_handler_CGX_GET_LINKINFO(struct rvu *rvu, struct msg_req *req,
479479
&rsp->link_info);
480480
return err;
481481
}
482+
483+
static int rvu_cgx_config_intlbk(struct rvu *rvu, u16 pcifunc, bool en)
484+
{
485+
int pf = rvu_get_pf(pcifunc);
486+
u8 cgx_id, lmac_id;
487+
488+
/* This msg is expected only from PFs that are mapped to CGX LMACs,
489+
* if received from other PF/VF simply ACK, nothing to do.
490+
*/
491+
if ((pcifunc & RVU_PFVF_FUNC_MASK) || !is_pf_cgxmapped(rvu, pf))
492+
return -ENODEV;
493+
494+
rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id);
495+
496+
return cgx_lmac_internal_loopback(rvu_cgx_pdata(cgx_id, rvu),
497+
lmac_id, en);
498+
}
499+
500+
int rvu_mbox_handler_CGX_INTLBK_ENABLE(struct rvu *rvu, struct msg_req *req,
501+
struct msg_rsp *rsp)
502+
{
503+
rvu_cgx_config_intlbk(rvu, req->hdr.pcifunc, true);
504+
return 0;
505+
}
506+
507+
int rvu_mbox_handler_CGX_INTLBK_DISABLE(struct rvu *rvu, struct msg_req *req,
508+
struct msg_rsp *rsp)
509+
{
510+
rvu_cgx_config_intlbk(rvu, req->hdr.pcifunc, false);
511+
return 0;
512+
}

0 commit comments

Comments
 (0)