Re: [Patch v2 net-next 6/7] octeontx2-pf: ethtool physical link status
Hi Andrew Lunn, > -Original Message- > From: Andrew Lunn > Sent: Wednesday, January 27, 2021 7:22 PM > To: Hariprasad Kelam > Cc: net...@vger.kernel.org; linux-kernel@vger.kernel.org; > da...@davemloft.net; k...@kernel.org; Sunil Kovvuri Goutham > ; Linu Cherian ; > Geethasowjanya Akula ; Jerin Jacob Kollanukkaran > ; Subbaraya Sundeep Bhatta ; > Christina Jacob > Subject: [EXT] Re: [Patch v2 net-next 6/7] octeontx2-pf: ethtool physical link > status > > > +static void otx2_get_link_mode_info(u64 index, int mode, > > + struct ethtool_link_ksettings > > + *link_ksettings) > > +{ > > + u64 ethtool_link_mode = 0; > > + int bit_position = 0; > > + u64 link_modes = 0; > > + > > + /* CGX link modes to Ethtool link mode mapping */ > > + const int cgx_link_mode[29] = {0, /* SGMII Mode */ > > + ETHTOOL_LINK_MODE_1000baseX_Full_BIT, > > + ETHTOOL_LINK_MODE_1baseT_Full_BIT, > > + ETHTOOL_LINK_MODE_1baseSR_Full_BIT, > > + ETHTOOL_LINK_MODE_1baseLR_Full_BIT, > > + ETHTOOL_LINK_MODE_1baseKR_Full_BIT, > > + OTX2_RESERVED_ETHTOOL_LINK_MODE, > > + ETHTOOL_LINK_MODE_25000baseSR_Full_BIT, > > + OTX2_RESERVED_ETHTOOL_LINK_MODE, > > + OTX2_RESERVED_ETHTOOL_LINK_MODE, > > + ETHTOOL_LINK_MODE_25000baseCR_Full_BIT, > > + ETHTOOL_LINK_MODE_25000baseKR_Full_BIT, > > + ETHTOOL_LINK_MODE_4baseSR4_Full_BIT, > > + ETHTOOL_LINK_MODE_4baseLR4_Full_BIT, > > + ETHTOOL_LINK_MODE_4baseCR4_Full_BIT, > > + ETHTOOL_LINK_MODE_4baseKR4_Full_BIT, > > + OTX2_RESERVED_ETHTOOL_LINK_MODE, > > + ETHTOOL_LINK_MODE_5baseSR_Full_BIT, > > + OTX2_RESERVED_ETHTOOL_LINK_MODE, > > + ETHTOOL_LINK_MODE_5baseLR_ER_FR_Full_BIT, > > + ETHTOOL_LINK_MODE_5baseCR_Full_BIT, > > + ETHTOOL_LINK_MODE_5baseKR_Full_BIT, > > + OTX2_RESERVED_ETHTOOL_LINK_MODE, > > + ETHTOOL_LINK_MODE_10baseSR4_Full_BIT, > > + ETHTOOL_LINK_MODE_10baseLR4_ER4_Full_BIT, > > + ETHTOOL_LINK_MODE_10baseCR4_Full_BIT, > > + ETHTOOL_LINK_MODE_10baseKR4_Full_BIT > > + }; > > + > > + link_modes = index & OTX2_ETHTOOL_SUPPORTED_MODES; > > + > > + for (bit_position = 0; link_modes; bit_position++, link_modes >>= 1) { > > + if (!(link_modes & 1)) > > + continue; > > + > > + if (bit_position == 0) > > + ethtool_link_mode = 0x3F; > > + > > + if (cgx_link_mode[bit_position]) > > + ethtool_link_mode |= 1ULL << > cgx_link_mode[bit_position]; > > + > > + if (mode) > > + *link_ksettings->link_modes.advertising |= > > + ethtool_link_mode; > > + else > > + *link_ksettings->link_modes.supported |= > > + ethtool_link_mode; > > You should not be derefererncing these bitmask like this. Use the helpers, > ethtool_link_ksettings_add_link_mode(). You cannot assume these a ULL, > they are not. > > Please review all the patches. There are too many levels of obfustication for > me to easily follow the code, bit it looks like you have other bitwise > operations which might be operating on kernel bitmaps, and you are not > using the helpers. > I will fix this in next version. > > > + } > > +} > > + > > +static int otx2_get_link_ksettings(struct net_device *netdev, > > + struct ethtool_link_ksettings *cmd) { > > + struct otx2_nic *pfvf = netdev_priv(netdev); > > + struct cgx_fw_data *rsp = NULL; > > + u32 supported = 0; > > + > > + cmd->base.duplex = pfvf->linfo.full_duplex; > > + cmd->base.speed = pfvf->linfo.speed; > > + cmd->base.autoneg = pfvf->linfo.an; > > + > > + rsp = otx2_get_fwdata(pfvf); > > + if (IS_ERR(rsp)) > > + return PTR_ERR(rsp); > > + > > + if (rsp->fwdata.supported_an) > > + supported |= SUPPORTED_Autoneg; > > + ethtool_convert_legacy_u32_to_link_mode(cmd- > >link_modes.supported, > > + supported); > > Why use the legacy stuff when you can directly set the bit using the helpers. > Don't the word legacy actually suggest you should not be using it in new > code? > > Andrew Agreed. Will fix this in next version. Thanks, Hariprasad k
Re: [Patch v2 net-next 6/7] octeontx2-pf: ethtool physical link status
> +static void otx2_get_link_mode_info(u64 index, int mode, > + struct ethtool_link_ksettings > + *link_ksettings) > +{ > + u64 ethtool_link_mode = 0; > + int bit_position = 0; > + u64 link_modes = 0; > + > + /* CGX link modes to Ethtool link mode mapping */ > + const int cgx_link_mode[29] = {0, /* SGMII Mode */ > + ETHTOOL_LINK_MODE_1000baseX_Full_BIT, > + ETHTOOL_LINK_MODE_1baseT_Full_BIT, > + ETHTOOL_LINK_MODE_1baseSR_Full_BIT, > + ETHTOOL_LINK_MODE_1baseLR_Full_BIT, > + ETHTOOL_LINK_MODE_1baseKR_Full_BIT, > + OTX2_RESERVED_ETHTOOL_LINK_MODE, > + ETHTOOL_LINK_MODE_25000baseSR_Full_BIT, > + OTX2_RESERVED_ETHTOOL_LINK_MODE, > + OTX2_RESERVED_ETHTOOL_LINK_MODE, > + ETHTOOL_LINK_MODE_25000baseCR_Full_BIT, > + ETHTOOL_LINK_MODE_25000baseKR_Full_BIT, > + ETHTOOL_LINK_MODE_4baseSR4_Full_BIT, > + ETHTOOL_LINK_MODE_4baseLR4_Full_BIT, > + ETHTOOL_LINK_MODE_4baseCR4_Full_BIT, > + ETHTOOL_LINK_MODE_4baseKR4_Full_BIT, > + OTX2_RESERVED_ETHTOOL_LINK_MODE, > + ETHTOOL_LINK_MODE_5baseSR_Full_BIT, > + OTX2_RESERVED_ETHTOOL_LINK_MODE, > + ETHTOOL_LINK_MODE_5baseLR_ER_FR_Full_BIT, > + ETHTOOL_LINK_MODE_5baseCR_Full_BIT, > + ETHTOOL_LINK_MODE_5baseKR_Full_BIT, > + OTX2_RESERVED_ETHTOOL_LINK_MODE, > + ETHTOOL_LINK_MODE_10baseSR4_Full_BIT, > + ETHTOOL_LINK_MODE_10baseLR4_ER4_Full_BIT, > + ETHTOOL_LINK_MODE_10baseCR4_Full_BIT, > + ETHTOOL_LINK_MODE_10baseKR4_Full_BIT > + }; > + > + link_modes = index & OTX2_ETHTOOL_SUPPORTED_MODES; > + > + for (bit_position = 0; link_modes; bit_position++, link_modes >>= 1) { > + if (!(link_modes & 1)) > + continue; > + > + if (bit_position == 0) > + ethtool_link_mode = 0x3F; > + > + if (cgx_link_mode[bit_position]) > + ethtool_link_mode |= 1ULL << > cgx_link_mode[bit_position]; > + > + if (mode) > + *link_ksettings->link_modes.advertising |= > + ethtool_link_mode; > + else > + *link_ksettings->link_modes.supported |= > + ethtool_link_mode; You should not be derefererncing these bitmask like this. Use the helpers, ethtool_link_ksettings_add_link_mode(). You cannot assume these a ULL, they are not. Please review all the patches. There are too many levels of obfustication for me to easily follow the code, bit it looks like you have other bitwise operations which might be operating on kernel bitmaps, and you are not using the helpers. > + } > +} > + > +static int otx2_get_link_ksettings(struct net_device *netdev, > +struct ethtool_link_ksettings *cmd) > +{ > + struct otx2_nic *pfvf = netdev_priv(netdev); > + struct cgx_fw_data *rsp = NULL; > + u32 supported = 0; > + > + cmd->base.duplex = pfvf->linfo.full_duplex; > + cmd->base.speed = pfvf->linfo.speed; > + cmd->base.autoneg = pfvf->linfo.an; > + > + rsp = otx2_get_fwdata(pfvf); > + if (IS_ERR(rsp)) > + return PTR_ERR(rsp); > + > + if (rsp->fwdata.supported_an) > + supported |= SUPPORTED_Autoneg; > + ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, > + supported); Why use the legacy stuff when you can directly set the bit using the helpers. Don't the word legacy actually suggest you should not be using it in new code? Andrew
[Patch v2 net-next 6/7] octeontx2-pf: ethtool physical link status
From: Christina Jacob Register get_link_ksettings callback to get link status information from the driver. As virtual function (vf) shares same physical link same API is used for both the drivers and for loop back drivers simply returns the fixed values as its does not have physical link. ethtool eth3 Settings for eth3: Supported ports: [ ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Half 1000baseT/Full 1baseKR/Full 1000baseX/Full Supports auto-negotiation: No Supported FEC modes: BaseR RS Advertised link modes: Not reported Advertised pause frame use: No Advertised auto-negotiation: No Advertised FEC modes: None ethtool lbk0 Settings for lbk0: Speed: 10Mb/s Duplex: Full Signed-off-by: Christina Jacob Signed-off-by: Sunil Goutham Signed-off-by: Hariprasad Kelam --- .../ethernet/marvell/octeontx2/nic/otx2_ethtool.c | 159 + 1 file changed, 159 insertions(+) diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c index e5b1a57..b99f4bb 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c @@ -32,6 +32,8 @@ struct otx2_stat { .index = offsetof(struct otx2_dev_stats, stat) / sizeof(u64), \ } +#define OTX2_ETHTOOL_SUPPORTED_MODES 0x638CCBF //11000111000110011001011 +#define OTX2_RESERVED_ETHTOOL_LINK_MODE0 static const struct otx2_stat otx2_dev_stats[] = { OTX2_DEV_STAT(rx_ucast_frames), OTX2_DEV_STAT(rx_bcast_frames), @@ -1034,6 +1036,148 @@ static int otx2_set_fecparam(struct net_device *netdev, return err; } +static void otx2_get_fec_info(u64 index, int mode, struct ethtool_link_ksettings + *link_ksettings) +{ + switch (index) { + case OTX2_FEC_NONE: + if (mode) + ethtool_link_ksettings_add_link_mode(link_ksettings, +advertising, +FEC_NONE); + else + ethtool_link_ksettings_add_link_mode(link_ksettings, +supported, +FEC_NONE); + break; + case OTX2_FEC_BASER: + if (mode) + ethtool_link_ksettings_add_link_mode(link_ksettings, +advertising, +FEC_BASER); + else + ethtool_link_ksettings_add_link_mode(link_ksettings, +supported, +FEC_BASER); + break; + case OTX2_FEC_RS: + if (mode) + ethtool_link_ksettings_add_link_mode(link_ksettings, +advertising, +FEC_RS); + else + ethtool_link_ksettings_add_link_mode(link_ksettings, +supported, +FEC_RS); + break; + case OTX2_FEC_BASER | OTX2_FEC_RS: + if (mode) { + ethtool_link_ksettings_add_link_mode(link_ksettings, +advertising, +FEC_BASER); + ethtool_link_ksettings_add_link_mode(link_ksettings, +advertising, +FEC_RS); + } else { + ethtool_link_ksettings_add_link_mode(link_ksettings, +supported, +FEC_BASER); + ethtool_link_ksettings_add_link_mode(link_ksettings, +supported, +FEC_RS); + } + + break; + } +} + +static void otx2_get_link_mode_info(u64 index, int mode, + struct ethtool_link_ksettings + *link_ksettings) +{ + u64 ethtool_link_mode = 0; + int bit_position = 0; +