From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 20B151E8320; Wed, 10 Dec 2025 18:56:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.67.10.101 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765392992; cv=none; b=e7nA/YO7ONpG7WZ3EmD593GTQ/7W6EeeouVVwRt2eKut/ODAbSPMwsbvfgnnFQefmMUzDE92TzDCcjBxaXfq+f3vkdY7Qkesdp/uXf1zWKkcufrZBMQKA3tFTD2D4ZlmQVYDycNb6IB+hvuUOTBoERM+mwEAjANdYRrB3p5J8Fk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765392992; c=relaxed/simple; bh=qrbbn3eV36Nw2ao+vEGVF7AYl3Qz8GtjAWg+Soyefbw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=B6bUCBJWwHpHc8ChO9ESLBL4ETQBxfYLPlkMhaqolJYI/zm8nfvB/GVNW49qa+WQ/QF+5IfUKJlUPzDrnD4s2za6Dc4Fq7CU0g7Fq0YjkHyuResNObz1pXr4SK77Dk/rNW2j3qgF5rPx3fSXCU+BiCCyMlnFXx+em2FWySxc8XQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch; spf=pass smtp.mailfrom=lunn.ch; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b=lEAROqxL; arc=none smtp.client-ip=156.67.10.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lunn.ch Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="lEAROqxL" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:From:Sender:Reply-To:Subject: Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=6IYETY9gTGhZvL1uGOVErqBQbdqL5dP9cyjhDBQlylc=; b=lEAROqxLv8AfIOKClV7r+5glYK OOuWL4J961SbYNouDqzvdzEafjmMNHj4Jiw+gik6DaiY0KN3aSVz4ObXXXoKocK9R9cKFc+bWq0ny TAeNk34FC4Hgxg6tlBBRjsomwfI8seEtpCh5VP1mIODQbJvX+iXNIxoRl6qktg2b32tw=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1vTPMD-00GZKy-5X; Wed, 10 Dec 2025 19:56:13 +0100 Date: Wed, 10 Dec 2025 19:56:13 +0100 From: Andrew Lunn To: Daniel Golle Cc: Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Simon Horman , Russell King , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Frank Wunderlich , Avinash Jayaraman , Bing tao Xu , Liang Xu , Juraj Povazanec , "Fanni (Fang-Yi) Chan" , "Benny (Ying-Tsan) Weng" , "Livia M. Rosu" , John Crispin Subject: Re: [PATCH RFC net-next 3/3] net: dsa: add basic initial driver for MxL862xx switches Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: > Imho it would be nice to introduce unlock __mdiodev_c45_* helpers in > include/linux/mdio.h, ie. > > static inline int __mdiodev_c45_read(struct mdio_device *mdiodev, int devad, > u16 regnum) > { > return __mdiobus_c45_read(mdiodev->bus, mdiodev->addr, devad, regnum); > } > > static inline int __mdiodev_c45_write(struct mdio_device *mdiodev, u32 devad, > u16 regnum, u16 val) > { > return __mdiobus_c45_write(mdiodev->bus, mdiodev->addr, devad, regnum, > val); > } https://elixir.bootlin.com/linux/v6.18/source/drivers/net/phy/mdio_bus.c#L531 > static int mxl862xx_reg_read(struct mxl862xx_priv *priv, u32 addr) > { > return __mdiodev_c45_read(priv->mdiodev, MDIO_MMD_VEND1, addr); > } > > static int mxl862xx_reg_write(struct mxl862xx_priv *priv, u32 addr, u16 data) > { > return __mdiodev_c45_write(priv->mdiodev, MDIO_MMD_VEND1, addr, data); > } > > static int mxl862xx_ctrl_read(struct mxl862xx_priv *priv) > { > return mxl862xx_reg_read(priv, MXL862XX_MMD_REG_CTRL); > } > > static int mxl862xx_busy_wait(struct mxl862xx_priv *priv) > { > int val; > > return readx_poll_timeout(mxl862xx_ctrl_read, priv, val, > !(val & CTRL_BUSY_MASK), 15, 10000); > } > > Do you agree? This part, yes. > > > + if (result < 0) { > > > + ret = result; > > > + goto out; > > > + } > > > > If i'm reading mxl862xx_send_cmd() correct, result is the value of a > > register. It seems unlikely this is a Linux error code? > > Only someone with insights into the use of error codes by the uC > firmware can really answer that. However, as also Russell pointed out, > the whole use of s16 here with negative values being interpreted as > errors is fishy here, because in the end this is also used to read > registers from external MDIO connected PHYs which may return arbitrary > 16-bit values... > Someone in MaxLinear will need to clarify here. It looks wrong, and since different architectures use different error code values, it is hard to get right. I would suggest you just return EPROTO or EIO and add a netdev_err() to print the value of result. > > > +#define MXL862XX_API_WRITE(dev, cmd, data) \ > > > + mxl862xx_api_wrap(dev, cmd, &(data), sizeof((data)), false) > > > +#define MXL862XX_API_READ(dev, cmd, data) \ > > > + mxl862xx_api_wrap(dev, cmd, &(data), sizeof((data)), true) > > > > > +/* PHY access via firmware relay */ > > > +static int mxl862xx_phy_read_mmd(struct mxl862xx_priv *priv, int port, > > > + int devadd, int reg) > > > +{ > > > + struct mdio_relay_data param = { > > > + .phy = port, > > > + .mmd = devadd, > > > + .reg = reg & 0xffff, > > > + }; > > > + int ret; > > > + > > > + ret = MXL862XX_API_READ(priv, INT_GPHY_READ, param); > > > > That looks a bit ugly, using a macro as a function name. I would > > suggest tiny functions rather than macros. The compiler should do the > > right thing. > > The thing is that the macro way allows to use MXL862XX_API_* on > arbitrary types, such as the packed structs. Using a function would > require the type of the parameter to be defined, which would result > in a lot of code duplication in this case. How many different invocations of these macros are there? For MDIO you need two. How many more are there? Andrew