Skip to content

Commit 3ad3f8f

Browse files
Hariprasad Kelamdavem330
authored andcommitted
octeontx2-af: cn10k: MAC internal loopback support
MAC on CN10K silicon support loopback for selftest or debug purposes. This patch does necessary configuration to loopback packets upon receiving request from LMAC mapped RVU PF's netdev via mailbox. Also MAC (CGX) on OcteonTx2 silicon variants and MAC (RPM) on OcteonTx3 CN10K are different and loopback needs to be configured differently. Upper layer interface between RVU AF and PF netdev is kept same. Based on silicon variant appropriate fn() pointer is called to config the MAC. Signed-off-by: Hariprasad Kelam <[email protected]> Signed-off-by: Geetha sowjanya <[email protected]> Signed-off-by: Sunil Goutham <[email protected]> Reported-by: kernel test robot <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ce7a6c3 commit 3ad3f8f

File tree

6 files changed

+61
-6
lines changed

6 files changed

+61
-6
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,9 @@ int cgx_set_pkind(void *cgxd, u8 lmac_id, int pkind)
229229
return 0;
230230
}
231231

232-
static inline u8 cgx_get_lmac_type(struct cgx *cgx, int lmac_id)
232+
static u8 cgx_get_lmac_type(void *cgxd, int lmac_id)
233233
{
234+
struct cgx *cgx = cgxd;
234235
u64 cfg;
235236

236237
cfg = cgx_read(cgx, lmac_id, CGXX_CMRX_CFG);
@@ -247,7 +248,7 @@ int cgx_lmac_internal_loopback(void *cgxd, int lmac_id, bool enable)
247248
if (!is_lmac_valid(cgx, lmac_id))
248249
return -ENODEV;
249250

250-
lmac_type = cgx_get_lmac_type(cgx, lmac_id);
251+
lmac_type = cgx->mac_ops->get_lmac_type(cgx, lmac_id);
251252
if (lmac_type == LMAC_MODE_SGMII || lmac_type == LMAC_MODE_QSGMII) {
252253
cfg = cgx_read(cgx, lmac_id, CGXX_GMP_PCS_MRX_CTL);
253254
if (enable)
@@ -1302,6 +1303,8 @@ static struct mac_ops cgx_mac_ops = {
13021303
.rx_stats_cnt = 9,
13031304
.tx_stats_cnt = 18,
13041305
.get_nr_lmacs = cgx_get_nr_lmacs,
1306+
.get_lmac_type = cgx_get_lmac_type,
1307+
.mac_lmac_intl_lbk = cgx_lmac_internal_loopback,
13051308
.mac_get_rx_stats = cgx_get_rx_stats,
13061309
.mac_get_tx_stats = cgx_get_tx_stats,
13071310
.mac_enadis_rx_pause_fwding = cgx_lmac_enadis_rx_pause_fwding,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ enum cgx_cmd_own {
204204
* CGX_STAT_SUCCESS
205205
*/
206206
#define RESP_FWD_BASE GENMASK_ULL(56, 9)
207+
#define RESP_LINKSTAT_LMAC_TYPE GENMASK_ULL(35, 28)
207208

208209
/* Response to cmd ID - CGX_CMD_LINK_BRING_UP/DOWN, event ID CGX_EVT_LINK_CHANGE
209210
* status can be either CGX_STAT_FAIL or CGX_STAT_SUCCESS

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ struct mac_ops {
7070
* number of setbits in lmac_exist tells number of lmacs
7171
*/
7272
int (*get_nr_lmacs)(void *cgx);
73-
73+
u8 (*get_lmac_type)(void *cgx, int lmac_id);
74+
int (*mac_lmac_intl_lbk)(void *cgx, int lmac_id,
75+
bool enable);
7476
/* Register Stats related functions */
7577
int (*mac_get_rx_stats)(void *cgx, int lmac_id,
7678
int idx, u64 *rx_stat);

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ static struct mac_ops rpm_mac_ops = {
2121
.rx_stats_cnt = 43,
2222
.tx_stats_cnt = 34,
2323
.get_nr_lmacs = rpm_get_nr_lmacs,
24+
.get_lmac_type = rpm_get_lmac_type,
25+
.mac_lmac_intl_lbk = rpm_lmac_internal_loopback,
2426
.mac_get_rx_stats = rpm_get_rx_stats,
2527
.mac_get_tx_stats = rpm_get_tx_stats,
2628
.mac_enadis_rx_pause_fwding = rpm_lmac_enadis_rx_pause_fwding,
@@ -226,3 +228,45 @@ int rpm_get_tx_stats(void *rpmd, int lmac_id, int idx, u64 *tx_stat)
226228
mutex_unlock(&rpm->lock);
227229
return 0;
228230
}
231+
232+
u8 rpm_get_lmac_type(void *rpmd, int lmac_id)
233+
{
234+
rpm_t *rpm = rpmd;
235+
u64 req = 0, resp;
236+
int err;
237+
238+
req = FIELD_SET(CMDREG_ID, CGX_CMD_GET_LINK_STS, req);
239+
err = cgx_fwi_cmd_generic(req, &resp, rpm, 0);
240+
if (!err)
241+
return FIELD_GET(RESP_LINKSTAT_LMAC_TYPE, resp);
242+
return err;
243+
}
244+
245+
int rpm_lmac_internal_loopback(void *rpmd, int lmac_id, bool enable)
246+
{
247+
rpm_t *rpm = rpmd;
248+
u8 lmac_type;
249+
u64 cfg;
250+
251+
if (!rpm || lmac_id >= rpm->lmac_count)
252+
return -ENODEV;
253+
lmac_type = rpm->mac_ops->get_lmac_type(rpm, lmac_id);
254+
if (lmac_type == LMAC_MODE_100G_R) {
255+
cfg = rpm_read(rpm, lmac_id, RPMX_MTI_PCS100X_CONTROL1);
256+
257+
if (enable)
258+
cfg |= RPMX_MTI_PCS_LBK;
259+
else
260+
cfg &= ~RPMX_MTI_PCS_LBK;
261+
rpm_write(rpm, lmac_id, RPMX_MTI_PCS100X_CONTROL1, cfg);
262+
} else {
263+
cfg = rpm_read(rpm, lmac_id, RPMX_MTI_LPCSX_CONTROL1);
264+
if (enable)
265+
cfg |= RPMX_MTI_PCS_LBK;
266+
else
267+
cfg &= ~RPMX_MTI_PCS_LBK;
268+
rpm_write(rpm, lmac_id, RPMX_MTI_LPCSX_CONTROL1, cfg);
269+
}
270+
271+
return 0;
272+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#define RPMX_CMRX_SW_INT_W1S 0x188
1919
#define RPMX_CMRX_SW_INT_ENA_W1S 0x198
2020
#define RPMX_CMRX_LINK_CFG 0x1070
21+
#define RPMX_MTI_PCS100X_CONTROL1 0x20000
22+
#define RPMX_MTI_LPCSX_CONTROL1 0x30000
23+
#define RPMX_MTI_PCS_LBK BIT_ULL(14)
2124
#define RPMX_MTI_LPCSX_CONTROL(id) (0x30000 | ((id) * 0x100))
2225

2326
#define RPMX_CMRX_LINK_RANGE_MASK GENMASK_ULL(19, 16)
@@ -41,6 +44,8 @@
4144

4245
/* Function Declarations */
4346
int rpm_get_nr_lmacs(void *rpmd);
47+
u8 rpm_get_lmac_type(void *rpmd, int lmac_id);
48+
int rpm_lmac_internal_loopback(void *rpmd, int lmac_id, bool enable);
4449
void rpm_lmac_enadis_rx_pause_fwding(void *rpmd, int lmac_id, bool enable);
4550
int rpm_lmac_get_pause_frm_status(void *cgxd, int lmac_id, u8 *tx_pause,
4651
u8 *rx_pause);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -722,15 +722,15 @@ u32 rvu_cgx_get_fifolen(struct rvu *rvu)
722722

723723
static int rvu_cgx_config_intlbk(struct rvu *rvu, u16 pcifunc, bool en)
724724
{
725-
int pf = rvu_get_pf(pcifunc);
725+
struct mac_ops *mac_ops;
726726
u8 cgx_id, lmac_id;
727727

728728
if (!is_cgx_config_permitted(rvu, pcifunc))
729729
return -EPERM;
730730

731-
rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id);
731+
mac_ops = get_mac_ops(rvu_cgx_pdata(cgx_id, rvu));
732732

733-
return cgx_lmac_internal_loopback(rvu_cgx_pdata(cgx_id, rvu),
733+
return mac_ops->mac_lmac_intl_lbk(rvu_cgx_pdata(cgx_id, rvu),
734734
lmac_id, en);
735735
}
736736

0 commit comments

Comments
 (0)