From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66221C433DB for ; Sat, 20 Feb 2021 16:28:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2BFDB64ED7 for ; Sat, 20 Feb 2021 16:28:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229914AbhBTQ2d (ORCPT ); Sat, 20 Feb 2021 11:28:33 -0500 Received: from vps0.lunn.ch ([185.16.172.187]:50712 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229784AbhBTQ20 (ORCPT ); Sat, 20 Feb 2021 11:28:26 -0500 Received: from andrew by vps0.lunn.ch with local (Exim 4.94) (envelope-from ) id 1lDV6W-007XT5-Nm; Sat, 20 Feb 2021 17:27:36 +0100 Date: Sat, 20 Feb 2021 17:27:36 +0100 From: Andrew Lunn To: Ivan Bornyakov Cc: netdev@vger.kernel.org, system@metrotek.ru, hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, kuba@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] net: phy: add Marvell 88X2222 transceiver support Message-ID: References: <20210201192250.gclztkomtsihczz6@dhcp-179.ddg> <20210220094621.tl6fawj7c5hjrp6s@dhcp-179.ddg> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210220094621.tl6fawj7c5hjrp6s@dhcp-179.ddg> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Ivan > +static int sfp_module_insert(void *_priv, const struct sfp_eeprom_id *id) > +{ > + struct phy_device *phydev = _priv; > + struct device *dev = &phydev->mdio.dev; > + struct mv2222_data *priv = phydev->priv; > + phy_interface_t sfp_interface; Reverse Christmas tree please. Which means you will need to move some of the assignments to the body of the function. Please also drop the _ from _priv. > + > + __ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_supported) = { 0, }; > + > + sfp_parse_support(phydev->sfp_bus, id, sfp_supported); > + sfp_interface = sfp_select_interface(phydev->sfp_bus, sfp_supported); > + > + dev_info(dev, "%s SFP module inserted", phy_modes(sfp_interface)); > + > + switch (sfp_interface) { > + case PHY_INTERFACE_MODE_10GBASER: > + phydev->speed = SPEED_10000; > + phy_write_mmd(phydev, MDIO_MMD_VEND2, MV_PCS_CONFIG, > + MV_PCS_HOST_XAUI | MV_PCS_LINE_10GBR); > + break; > + case PHY_INTERFACE_MODE_1000BASEX: > + phydev->speed = SPEED_1000; > + phy_write_mmd(phydev, MDIO_MMD_VEND2, MV_PCS_CONFIG, > + MV_PCS_HOST_XAUI | MV_PCS_LINE_1GBX_AN); > + break; > + case PHY_INTERFACE_MODE_SGMII: > + phydev->speed = SPEED_1000; SPEED_UNKNOWN might be better here, until auto negotiation has completed and you then know if it is 10/100/1G. > + phy_write_mmd(phydev, MDIO_MMD_VEND2, MV_PCS_CONFIG, > + MV_PCS_HOST_XAUI | MV_PCS_LINE_SGMII_AN); > + phy_modify_mmd(phydev, MDIO_MMD_PCS, MV_1GBX_CTRL, > + BMCR_SPEED1000 | BMCR_SPEED100, BMCR_SPEED1000); > + break; > + default: > + dev_err(dev, "Incompatible SFP module inserted\n"); > + > + return -EINVAL; > + } > + > + linkmode_and(phydev->supported, priv->supported, sfp_supported); > + priv->line_interface = sfp_interface; > + > + return mv2222_soft_reset(phydev); > +} > + > +static void sfp_module_remove(void *_priv) > +{ > + struct phy_device *phydev = _priv; > + struct mv2222_data *priv = phydev->priv; More reverse christmass tree. > + > + priv->line_interface = PHY_INTERFACE_MODE_NA; > + linkmode_copy(phydev->supported, priv->supported); > +} > + > +static int mv2222_config_aneg(struct phy_device *phydev) > +{ > + /* Try 10G first */ > + if (mv2222_is_10g_capable(phydev)) { > + phydev->speed = SPEED_10000; > + mv2222_update_interface(phydev); > + > + ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MV_10GBR_STAT_RT); > + if (ret < 0) > + return ret; > + > + if (ret & MDIO_STAT1_LSTATUS) { > + phydev->autoneg = AUTONEG_DISABLE; > + > + return mv2222_disable_aneg(phydev); > + } > + > + /* 10G link was not established, switch back to 1G > + * and proceed with true autonegotiation */ > + phydev->speed = SPEED_1000; > + mv2222_update_interface(phydev); So you are assuming the cable is plugged in and the peer is ready to go? Try 10G once, and then fall back to 1G? This does not seem very reliable, and likely to cause confusion. It works sometimes, not others. I'm not sure this is a good idea. > +static void mv2222_remove(struct phy_device *phydev) > +{ > + struct device *dev = &phydev->mdio.dev; > + struct mv2222_data *priv = phydev->priv; > + > + if (priv) > + devm_kfree(dev, priv); Why can devm_kfree(). The point of devm_ is that it frees itself. Andrew