From patchwork Wed Jan 21 05:50:51 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Harrison X-Patchwork-Id: 19592 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id 321ACDDED9 for ; Wed, 21 Jan 2009 16:51:24 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753005AbZAUFvR (ORCPT ); Wed, 21 Jan 2009 00:51:17 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753015AbZAUFvO (ORCPT ); Wed, 21 Jan 2009 00:51:14 -0500 Received: from wf-out-1314.google.com ([209.85.200.173]:23543 "EHLO wf-out-1314.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752750AbZAUFvC (ORCPT ); Wed, 21 Jan 2009 00:51:02 -0500 Received: by wf-out-1314.google.com with SMTP id 27so4192305wfd.4 for ; Tue, 20 Jan 2009 21:51:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:subject:from:to:cc :content-type:date:message-id:mime-version:x-mailer :content-transfer-encoding; bh=+tBQ6s/TtuH+h6VO/LF6qNPFP/+R3GVLkY73e3SHAOQ=; b=D4F1DhnG3G96ukQRxN5+BcTD8Py2OLB9Z0kUuAcc3LEMUTKbyQERmemLhjyzVuoEuj Ifnysdshlpuzm5rbtf+rDpsRQQGgZsK1bNcvUqkrfyTu/z4G3o9Gz49FbmuL3ikiPLSk +oHSrHm+khZKotIPX2XZIljbJvmP7wu5pU38s= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:cc:content-type:date:message-id:mime-version :x-mailer:content-transfer-encoding; b=J8PdibPzLvklhEypDZUz3gE2Jp1FNQhDunMtH/Jc3TO/bnItSg5So7CRr5emKgFsFm t9xa1M9q7lAQ1n0tpNMXcQ4YOvtAjDjuwegVRAqV7WgNFx73lsg46I+Ki90PNcRawz+I sMrPu89w2BzvuekGnDBFzlXG9CYBSBOIofrGw= Received: by 10.142.238.4 with SMTP id l4mr2492150wfh.98.1232517062269; Tue, 20 Jan 2009 21:51:02 -0800 (PST) Received: from ?192.168.1.101? (216-19-190-48.dyn.novuscom.net [216.19.190.48]) by mx.google.com with ESMTPS id 30sm11320489wfg.5.2009.01.20.21.51.01 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 20 Jan 2009 21:51:01 -0800 (PST) Subject: [PATCH 9/9] bnx2x: annotate nvram dword reading/writing From: Harvey Harrison To: Eilon Greenstein Cc: linux-netdev Date: Tue, 20 Jan 2009 21:50:51 -0800 Message-Id: <1232517051.9701.27.camel@brick> Mime-Version: 1.0 X-Mailer: Evolution 2.24.3 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org I believe this exposed an endian bug as the shifting of bytes from the data buffer was done in cpu-order, then masked into a be32 and the combined value was then converted to cpu-order, this does all the masking in be-byteorder and passes a cpu-ordered value to the write routine. Signed-off-by: Harvey Harrison --- drivers/net/bnx2x_main.c | 17 +++++++---------- 1 files changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/net/bnx2x_main.c b/drivers/net/bnx2x_main.c index 5e5e008..d0b0f6e 100644 --- a/drivers/net/bnx2x_main.c +++ b/drivers/net/bnx2x_main.c @@ -8011,7 +8011,7 @@ static void bnx2x_disable_nvram_access(struct bnx2x *bp) MCPR_NVM_ACCESS_ENABLE_WR_EN))); } -static int bnx2x_nvram_read_dword(struct bnx2x *bp, u32 offset, u32 *ret_val, +static int bnx2x_nvram_read_dword(struct bnx2x *bp, u32 offset, __be32 *ret_val, u32 cmd_flags) { int count, i, rc; @@ -8047,8 +8047,7 @@ static int bnx2x_nvram_read_dword(struct bnx2x *bp, u32 offset, u32 *ret_val, /* we read nvram data in cpu order * but ethtool sees it as an array of bytes * converting to big-endian will do the work */ - val = cpu_to_be32(val); - *ret_val = val; + *ret_val = cpu_to_be32(val); rc = 0; break; } @@ -8062,7 +8061,7 @@ static int bnx2x_nvram_read(struct bnx2x *bp, u32 offset, u8 *ret_buf, { int rc; u32 cmd_flags; - u32 val; + __be32 val; if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) { DP(BNX2X_MSG_NVM, @@ -8181,7 +8180,7 @@ static int bnx2x_nvram_write1(struct bnx2x *bp, u32 offset, u8 *data_buf, int rc; u32 cmd_flags; u32 align_offset; - u32 val; + __be32 val; if (offset + buf_size > bp->common.flash_size) { DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +" @@ -8203,14 +8202,12 @@ static int bnx2x_nvram_write1(struct bnx2x *bp, u32 offset, u8 *data_buf, rc = bnx2x_nvram_read_dword(bp, align_offset, &val, cmd_flags); if (rc == 0) { - val &= ~(0xff << BYTE_OFFSET(offset)); - val |= (*data_buf << BYTE_OFFSET(offset)); - /* nvram data is returned as an array of bytes * convert it back to cpu order */ - val = be32_to_cpu(val); + val &= ~cpu_to_be32(0xff << (8 * (offset & 0x03))); + val |= cpu_to_be32(*data_buf << (8 * (offset & 0x03))); - rc = bnx2x_nvram_write_dword(bp, align_offset, val, + rc = bnx2x_nvram_write_dword(bp, align_offset, be32_to_cpu(val), cmd_flags); }