Skip to content

Commit 5f21226

Browse files
Hariprasad Kelamkuba-moo
authored andcommitted
Octeontx2-pf: ethtool: support multi advertise mode
Current implementation considers only first advertise mode and passes the same to firmware to process. This patch extends code such that user can advertise multiple modes on the given interface. Below are high level changes: 1. Remove unnecessary speed/duplex/autoneg validation as its already verified as part of "set_link_ksettings" 2. Since scratch csr framework designed to support single mode at a time, use "shared firmware data" for multi mode support. Signed-off-by: Hariprasad Kelam <hkelam@marvell.com> Link: https://patch.msgid.link/20250625092107.9746-4-hkelam@marvell.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent ad97e72 commit 5f21226

File tree

5 files changed

+48
-31
lines changed

5 files changed

+48
-31
lines changed

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

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,15 +1185,10 @@ static void set_mod_args(struct cgx_set_link_mode_args *args,
11851185
int mode_baseidx;
11861186
u8 cgx_mode;
11871187

1188-
/* Fill default values incase of user did not pass
1189-
* valid parameters
1190-
*/
1191-
if (args->duplex == DUPLEX_UNKNOWN)
1192-
args->duplex = duplex;
1193-
if (args->speed == SPEED_UNKNOWN)
1194-
args->speed = speed;
1195-
if (args->an == AUTONEG_UNKNOWN)
1196-
args->an = autoneg;
1188+
if (args->multimode) {
1189+
args->mode |= mode;
1190+
return;
1191+
}
11971192

11981193
/* Derive mode_base_idx and mode fields based
11991194
* on cgx_mode value
@@ -1494,18 +1489,29 @@ int cgx_get_fwdata_base(u64 *base)
14941489
}
14951490

14961491
int cgx_set_link_mode(void *cgxd, struct cgx_set_link_mode_args args,
1492+
struct cgx_lmac_fwdata_s *linkmodes,
14971493
int cgx_id, int lmac_id)
14981494
{
14991495
struct cgx *cgx = cgxd;
15001496
u64 req = 0, resp;
1497+
u8 bit;
15011498

15021499
if (!cgx)
15031500
return -ENODEV;
15041501

1505-
if (args.mode)
1506-
otx2_map_ethtool_link_modes(args.mode, &args);
1507-
if (!args.speed && args.duplex && !args.an)
1508-
return -EINVAL;
1502+
for_each_set_bit(bit, args.advertising,
1503+
__ETHTOOL_LINK_MODE_MASK_NBITS)
1504+
otx2_map_ethtool_link_modes(bit, &args);
1505+
1506+
if (args.multimode) {
1507+
if (linkmodes->advertised_link_modes_own != CGX_CMD_OWN_NS)
1508+
return -EBUSY;
1509+
1510+
linkmodes->advertised_link_modes = args.mode;
1511+
/* Update ownership */
1512+
linkmodes->advertised_link_modes_own = CGX_CMD_OWN_FIRMWARE;
1513+
args.mode = GENMASK_ULL(41, 0);
1514+
}
15091515

15101516
req = FIELD_SET(CMDREG_ID, CGX_CMD_MODE_CHANGE, req);
15111517
req = FIELD_SET(CMDMODECHANGE_SPEED,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ int cgx_set_fec(u64 fec, int cgx_id, int lmac_id);
171171
int cgx_get_fec_stats(void *cgxd, int lmac_id, struct cgx_fec_stats_rsp *rsp);
172172
int cgx_get_phy_fec_stats(void *cgxd, int lmac_id);
173173
int cgx_set_link_mode(void *cgxd, struct cgx_set_link_mode_args args,
174+
struct cgx_lmac_fwdata_s *linkmodes,
174175
int cgx_id, int lmac_id);
175176
u64 cgx_features_get(void *cgxd);
176177
struct mac_ops *get_mac_ops(void *cgxd);

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

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

1111
#include <linux/etherdevice.h>
1212
#include <linux/sizes.h>
13+
#include <linux/ethtool.h>
1314

1415
#include "rvu_struct.h"
1516
#include "common.h"
@@ -658,7 +659,8 @@ struct cgx_lmac_fwdata_s {
658659
u64 supported_link_modes;
659660
/* only applicable if AN is supported */
660661
u64 advertised_fec;
661-
u64 advertised_link_modes;
662+
u64 advertised_link_modes_own:1; /* CGX_CMD_OWN */
663+
u64 advertised_link_modes:63;
662664
/* Only applicable if SFP/QSFP slot is present */
663665
struct sfp_eeprom_s sfp_eeprom;
664666
struct phy_s phy;
@@ -676,11 +678,12 @@ struct cgx_set_link_mode_args {
676678
u8 duplex;
677679
u8 an;
678680
u8 mode_baseidx;
681+
u8 multimode;
679682
u64 mode;
683+
__ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
680684
};
681685

682686
struct cgx_set_link_mode_req {
683-
#define AUTONEG_UNKNOWN 0xff
684687
struct mbox_msghdr hdr;
685688
struct cgx_set_link_mode_args args;
686689
};

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,7 @@ int rvu_mbox_handler_cgx_set_link_mode(struct rvu *rvu,
12231223
struct cgx_set_link_mode_rsp *rsp)
12241224
{
12251225
int pf = rvu_get_pf(rvu->pdev, req->hdr.pcifunc);
1226+
struct cgx_lmac_fwdata_s *linkmodes;
12261227
u8 cgx_idx, lmac;
12271228
void *cgxd;
12281229

@@ -1231,7 +1232,13 @@ int rvu_mbox_handler_cgx_set_link_mode(struct rvu *rvu,
12311232

12321233
rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_idx, &lmac);
12331234
cgxd = rvu_cgx_pdata(cgx_idx, rvu);
1234-
rsp->status = cgx_set_link_mode(cgxd, req->args, cgx_idx, lmac);
1235+
if (rvu->hw->lmac_per_cgx == CGX_LMACS_USX)
1236+
linkmodes = &rvu->fwdata->cgx_fw_data_usx[cgx_idx][lmac];
1237+
else
1238+
linkmodes = &rvu->fwdata->cgx_fw_data[cgx_idx][lmac];
1239+
1240+
rsp->status = cgx_set_link_mode(cgxd, req->args, linkmodes,
1241+
cgx_idx, lmac);
12351242
return 0;
12361243
}
12371244

drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,23 +1212,10 @@ static int otx2_get_link_ksettings(struct net_device *netdev,
12121212
return 0;
12131213
}
12141214

1215-
static void otx2_get_advertised_mode(const struct ethtool_link_ksettings *cmd,
1216-
u64 *mode)
1217-
{
1218-
u32 bit_pos;
1219-
1220-
/* Firmware does not support requesting multiple advertised modes
1221-
* return first set bit
1222-
*/
1223-
bit_pos = find_first_bit(cmd->link_modes.advertising,
1224-
__ETHTOOL_LINK_MODE_MASK_NBITS);
1225-
if (bit_pos != __ETHTOOL_LINK_MODE_MASK_NBITS)
1226-
*mode = bit_pos;
1227-
}
1228-
12291215
static int otx2_set_link_ksettings(struct net_device *netdev,
12301216
const struct ethtool_link_ksettings *cmd)
12311217
{
1218+
__ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
12321219
struct otx2_nic *pf = netdev_priv(netdev);
12331220
struct ethtool_link_ksettings cur_ks;
12341221
struct cgx_set_link_mode_req *req;
@@ -1265,7 +1252,20 @@ static int otx2_set_link_ksettings(struct net_device *netdev,
12651252
*/
12661253
req->args.duplex = cmd->base.duplex ^ 0x1;
12671254
req->args.an = cmd->base.autoneg;
1268-
otx2_get_advertised_mode(cmd, &req->args.mode);
1255+
/* Mask unsupported modes and send message to AF */
1256+
linkmode_set_bit(ETHTOOL_LINK_MODE_FEC_NONE_BIT, mask);
1257+
linkmode_set_bit(ETHTOOL_LINK_MODE_FEC_BASER_BIT, mask);
1258+
linkmode_set_bit(ETHTOOL_LINK_MODE_FEC_RS_BIT, mask);
1259+
1260+
linkmode_copy(req->args.advertising,
1261+
cmd->link_modes.advertising);
1262+
linkmode_andnot(req->args.advertising,
1263+
req->args.advertising, mask);
1264+
1265+
/* inform AF that we need parse this differently */
1266+
if (bitmap_weight(req->args.advertising,
1267+
__ETHTOOL_LINK_MODE_MASK_NBITS) >= 2)
1268+
req->args.multimode = true;
12691269

12701270
err = otx2_sync_mbox_msg(&pf->mbox);
12711271
end:

0 commit comments

Comments
 (0)