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=-2.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS, 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 CD8F4C31680 for ; Mon, 21 Jan 2019 18:26:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9E68020879 for ; Mon, 21 Jan 2019 18:26:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="Bcu4edAr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727665AbfAUS0e (ORCPT ); Mon, 21 Jan 2019 13:26:34 -0500 Received: from vps0.lunn.ch ([185.16.172.187]:50777 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726265AbfAUS0e (ORCPT ); Mon, 21 Jan 2019 13:26:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=+Fcna7QwPohCL2maAgm+R49SLapIjW7bGsPuNqCBRBo=; b=Bcu4edArFYIhDJnHj96lPkRgTmMHQm07ovC6zbAzgo+XPAfLscDSiihm//OsyZMV4DliivjMcCE8J7QneGQgLQnR/NABI5rzjYEfxuCXfdKyY5p0QNYy3hQIlUw9HmugP/JFL6dEnPXEkP5gYvJZEbBr+OXEiatp16VkwHoGE5E=; Received: from andrew by vps0.lunn.ch with local (Exim 4.84_2) (envelope-from ) id 1gleHG-0004Md-SW; Mon, 21 Jan 2019 19:26:30 +0100 Date: Mon, 21 Jan 2019 19:26:30 +0100 From: Andrew Lunn To: Bryan Whitehead Cc: davem@davemloft.net, netdev@vger.kernel.org, UNGLinuxDriver@microchip.com Subject: Re: [PATCH v1 net-next] lan743x: Provide Read/Write Access to on chip OTP Message-ID: <20190121182630.GB16212@lunn.ch> References: <1547848493-16985-1-git-send-email-Bryan.Whitehead@microchip.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1547848493-16985-1-git-send-email-Bryan.Whitehead@microchip.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 > +static int lan743x_otp_write(struct lan743x_adapter *adapter, u32 offset, > + u32 length, u8 *data) > +{ > + int ret; > + int i; > + > + ret = lan743x_otp_power_up(adapter); > + if (ret < 0) > + return ret; > + > + ret = lan743x_otp_wait_till_not_busy(adapter); > + if (ret < 0) > + return ret; > + > /* set to BYTE program mode */ > lan743x_csr_write(adapter, OTP_PRGM_MODE, OTP_PRGM_MODE_BYTE_); > > for (i = 0; i < length; i++) { I think you now need to verify length. It might be possible to change from EEPROM to OTP after lan743x_ethtool_get_eeprom_len() has been called, so you have been asked to write EEPROM length into the OTP. The same is also true for read. > - lan743x_csr_write(adapter, OTP_ADDR1, > - ((offset + i) >> 8) & > - OTP_ADDR1_15_11_MASK_); > - lan743x_csr_write(adapter, OTP_ADDR2, > - ((offset + i) & > - OTP_ADDR2_10_3_MASK_)); > + lan743x_otp_set_address(adapter, offset + i); > + > lan743x_csr_write(adapter, OTP_PRGM_DATA, data[i]); > lan743x_csr_write(adapter, OTP_TST_CMD, OTP_TST_CMD_PRGVRFY_); > lan743x_csr_write(adapter, OTP_CMD_GO, OTP_CMD_GO_GO_); > > - timeout = jiffies + HZ; > - do { > - udelay(1); > - buf = lan743x_csr_read(adapter, OTP_STATUS); > - if (time_after(jiffies, timeout)) { > - netif_warn(adapter, drv, adapter->netdev, > - "Timeout on OTP_STATUS completion\n"); > - return -EIO; > - } > - } while (buf & OTP_STATUS_BUSY_); > + ret = lan743x_otp_wait_till_not_busy(adapter); > + if (ret < 0) > + return ret; > } > > + lan743x_otp_power_down(adapter); > + > return 0; > } > > static int lan743x_ethtool_set_eeprom(struct net_device *netdev, > @@ -224,17 +306,18 @@ static int lan743x_ethtool_set_eeprom(struct net_device *netdev, > struct lan743x_adapter *adapter = netdev_priv(netdev); > int ret = -EINVAL; > > - if (ee->magic == LAN743X_EEPROM_MAGIC) > - ret = lan743x_eeprom_write(adapter, ee->offset, ee->len, > - data); > - /* Beware! OTP is One Time Programming ONLY! > - * So do some strict condition check before messing up > - */ > - else if ((ee->magic == LAN743X_OTP_MAGIC) && > - (ee->offset == 0) && > - (ee->len == MAX_EEPROM_SIZE) && > - (data[0] == OTP_INDICATOR_1)) > - ret = lan743x_otp_write(adapter, ee->offset, ee->len, data); > + if (adapter->flags & LAN743X_ADAPTER_FLAG_OTP) { > + /* Beware! OTP is One Time Programming ONLY! */ > + if (ee->magic == LAN743X_OTP_MAGIC) { > + ret = lan743x_otp_write(adapter, ee->offset, > + ee->len, data); > + } > + } else { > + if (ee->magic == LAN743X_EEPROM_MAGIC) { > + ret = lan743x_eeprom_write(adapter, ee->offset, > + ee->len, data); > + } > + } This is breaking backwards compatibility. I think you need to respect the magic value, independent of how adapter->flags. Andrew