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=-8.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_MUTT autolearn=ham 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 4C6D3C282C0 for ; Wed, 23 Jan 2019 21:32:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1A37A218A1 for ; Wed, 23 Jan 2019 21:32:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="SHrceQdh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726843AbfAWVcg (ORCPT ); Wed, 23 Jan 2019 16:32:36 -0500 Received: from vps0.lunn.ch ([185.16.172.187]:53220 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726352AbfAWVcf (ORCPT ); Wed, 23 Jan 2019 16:32:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Transfer-Encoding:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=BEV4PLdWTxd4VA07+taETmEZwntpRCEirJTTs0i4J+4=; b=SHrceQdhDEJXcQVMWar6CbesIokII3KCEvMgCJrfdvrol+8sDbHe96MUyz4nMgyhLP6bZQzgMnh+8zibO8NsHXz1hg5DTrfWvm5MY3mcJ+6dU2+CeohycK1gdR4cu+wvhEqSrbgu9KbaCxT8hTlGPcxgoCHBc/To3sotzLUg+SI=; Received: from andrew by vps0.lunn.ch with local (Exim 4.84_2) (envelope-from ) id 1gmQ8L-0004er-Uq; Wed, 23 Jan 2019 22:32:29 +0100 Date: Wed, 23 Jan 2019 22:32:29 +0100 From: Andrew Lunn To: =?iso-8859-1?Q?Ren=E9?= van Dorst Cc: Florian Fainelli , Heiner Kallweit , "David S. Miller" , netdev@vger.kernel.org Subject: Re: [PATCH] sfp: sfp_read: split-up request when hw rx buffer is too small. Message-ID: <20190123213229.GA17772@lunn.ch> References: <20190123212046.13020-1-opensource@vdorst.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190123212046.13020-1-opensource@vdorst.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Wed, Jan 23, 2019 at 10:20:46PM +0100, René van Dorst wrote: > Without this patch sfp code retries to read the full struct sfp_eeprom_id > id out of the SFP eeprom. Sizeof(id) is 96 bytes. > My i2c hardware, Mediatek mt7621, has a rx buffer of 64 bytes. > So sfp_read gets -NOSUPPORTED back on his turn return -EAGAIN. > Same issue is with the SFP_EXT_STATUS data which is 92 bytes. > > By split-up the request in multiple smaller requests with a max size of i2c > max_read_len, we can readout the SFP module successfully. > > Tested with MT7621 and two Fiberstore modules SFP-GB-GE-T and SFP-GE-BX. > > Signed-off-by: René van Dorst > --- > drivers/net/phy/sfp.c | 23 ++++++++++++++++++++++- > 1 file changed, 22 insertions(+), 1 deletion(-) > > diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c > index fd8bb998ae52..1352a19571cd 100644 > --- a/drivers/net/phy/sfp.c > +++ b/drivers/net/phy/sfp.c > @@ -367,7 +367,28 @@ static void sfp_set_state(struct sfp *sfp, unsigned int state) > > static int sfp_read(struct sfp *sfp, bool a2, u8 addr, void *buf, size_t len) > { > - return sfp->read(sfp, a2, addr, buf, len); > + const struct i2c_adapter_quirks *q = sfp->i2c->quirks; > + int ret; > + size_t rx_bytes = 0; > + > + /* Many i2c hw have limited rx buffers, split-up request when needed. */ > + while ((q->max_read_len) && (len > q->max_read_len)) { > + ret = sfp->read(sfp, a2, addr, buf, q->max_read_len); Hi René I think you want to pass MIN(len, q->max_read_len) to read(). > + if (ret < 0) > + return ret; > + rx_bytes += ret; > + addr += q->max_read_len; > + buf += q->max_read_len; > + len -= q->max_read_len; I would prefer you add ret, not q->max_read_len. There is a danger it returned less bytes than you asked for. > + } > + > + ret = sfp->read(sfp, a2, addr, buf, len); > + if (ret < 0) > + return ret; > + > + rx_bytes += ret; > + > + return rx_bytes; > } > > static int sfp_write(struct sfp *sfp, bool a2, u8 addr, void *buf, size_t len) Doesn't write need the same handling? Thanks Andrew