Message ID | 20231120193504.5922-1-ansuelsmth@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp252734vqb; Mon, 20 Nov 2023 14:21:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IHGqIkC2UB48PKRd0Kbzz41FqGe1AS3AXgtZw4wH+paRHTIbIG7bPqmqzduKU+7y2ey/gO7 X-Received: by 2002:a05:6808:302a:b0:3b6:dc6f:2741 with SMTP id ay42-20020a056808302a00b003b6dc6f2741mr3791391oib.19.1700518899295; Mon, 20 Nov 2023 14:21:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700518899; cv=none; d=google.com; s=arc-20160816; b=hZncwSOFIgn0r+rnodHgdVORDb95LPnWecyX+qJjy2OFB165ILh4wl/EkjMHXcB7Kb ywtwn52tMB704+lFDoEG0i3tX0DNRCaHD4K17ZSe6XOls33ccN2i6JDeWD19Ox7pM9WM SZ0EIh92hEuHsSI1BWiISjeqVm/1jpPKj268jKR+IHuCqvtfqCbvF4qKAWan3XWVARlB Bxg544pvT+NPHSi1ngsvi4HZpdNduaQx0e+ZQm1vLur8K76sTBMor0jXGju4QdjeiBbR anE6lUPJGFEHIUTfovQx7sKVvjZ4cAKMmc0+IBkZGL8ljgRmrMf0HoUfwZFkNGphy+6v UhLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=+WAcz7z2EchyAwpWIM7/dxS2+rVeXdmwsl1o0TskhuM=; fh=TLP31TsvNjXfybFHjyS0ptdGep1co6SEP/v6lxPO++U=; b=QFN4QvJJQTezGBjxLeFyA5Pa9UFsQ/lae+s7OJd5bwCb8Cne7mxXu8BZjtVfD93pvX up0nKV5yo89ypomqLqXFFgwAqNqKKQmqOhd/eGt2ABuC63eMeajebK8SZOhwJNhG67aF XPsCGa5EtN4Kl6XuYymrnfAWnbkr2ygvVQOMKmnMn9iEIShrBBMCQzZhsGTD9ZucmXEp nu6OBDet9eAzj27BASI5xawNg/xj6wN45+AUgdcZZCH2OhIUN+//oBqUSGtKg5Q9rGBu UE3a4CVjVAhv+6DVwmemydfQO6AIazHh8/x0K/pM3k1JotiFwSoxwJrEp/mXnD00f/zO UL5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bSkcjujV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id l189-20020a6388c6000000b0059ccb99a2eesi9422131pgd.173.2023.11.20.14.21.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 14:21:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bSkcjujV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 645A18080E12; Mon, 20 Nov 2023 14:20:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232729AbjKTWUc (ORCPT <rfc822;heyuhang3455@gmail.com> + 27 others); Mon, 20 Nov 2023 17:20:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232733AbjKTWUM (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 20 Nov 2023 17:20:12 -0500 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E1AD12A; Mon, 20 Nov 2023 14:20:08 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-40b26d700a1so2531985e9.0; Mon, 20 Nov 2023 14:20:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700518806; x=1701123606; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=+WAcz7z2EchyAwpWIM7/dxS2+rVeXdmwsl1o0TskhuM=; b=bSkcjujVEc+Hy/rmqa/TY6sKbAeO2Dv9mO9+cjLo0Js6D8Kca4I0+KYddHK1E+/d4x f/ILLqlo4EqzWyqrWSKOTyYr6+A9tqf3fueGrYVTKWluwxrUat/XGSSGruybzJUSvH0g YCpZNJW1A/8vi18WkABgokoXHU5l49W2Wzqxwmpgi+I5fN/2teMqmWG9mzpJPutQK+4/ KMHfTwH9CX74uOIojxMbF0ftNWVw3oZL96NrE4Jls6oU6PVB8ioxOTt4LVFRdZeYSVSl PeNXM9yXEczt5KoL6wj1OFBFWgNm3JIF+xbqALh7hlv0IFeeKm1A3dY4jvFCV6DZrKZe LWdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700518806; x=1701123606; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+WAcz7z2EchyAwpWIM7/dxS2+rVeXdmwsl1o0TskhuM=; b=BMv6KvGnZwnvsctvDQw3mJbUqFWzVZ4j09fyOmXBoqw78Ljg/KEA/8TYS9lxc0/z4Q hlCKcWzJYyjjC4uQkWAbg5Igd83/qGPfp4JER6Rgy9e/T4FXSs7cfkl0sU0KQGeXhbqt IbjVP4oknPOpJewimStCv5ipYO/yXNGxmrSj4INxeQyIDoyuPTBKdnyAuULt+22GhD9L 9tivD8slOaS81SnVRHlOtLc2gw3uX76AQxuOEemjmnq+dukwIXPj4bgdb+x7C0d9lSya 3g4FQpQ0FUdSlnm7nfsTewnW4X1rlwDMUgsDUGKCkpMVJZ4+yA65nABdQsAIE6iRwMfS mU+A== X-Gm-Message-State: AOJu0YxnojhRK0tit5aMzLnikdHLFQ7nmh+Dpis3HrWKNNwLtawmpwMO SnBJinrEnrdsBOhTbjGa12w= X-Received: by 2002:a5d:688e:0:b0:317:6ea5:ab71 with SMTP id h14-20020a5d688e000000b003176ea5ab71mr5078027wru.30.1700518806281; Mon, 20 Nov 2023 14:20:06 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id f18-20020adfdb52000000b00332cbda1970sm1739089wrj.30.2023.11.20.14.20.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 14:20:05 -0800 (PST) From: Christian Marangi <ansuelsmth@gmail.com> To: Andrew Lunn <andrew@lunn.ch>, Heiner Kallweit <hkallweit1@gmail.com>, Russell King <linux@armlinux.org.uk>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Christian Marangi <ansuelsmth@gmail.com>, Robert Marko <robimarko@gmail.com>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: kernel test robot <lkp@intel.com> Subject: [net-next PATCH] net: phy: aquantia: make mailbox interface4 lsw addr mask more specific Date: Mon, 20 Nov 2023 20:35:04 +0100 Message-Id: <20231120193504.5922-1-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 20 Nov 2023 14:20:42 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783123305341709385 X-GMAIL-MSGID: 1783123305341709385 |
Series |
[net-next] net: phy: aquantia: make mailbox interface4 lsw addr mask more specific
|
|
Commit Message
Christian Marangi
Nov. 20, 2023, 7:35 p.m. UTC
It seems some arch (s390) require a more specific mask for FIELD_PREP
and doesn't like using GENMASK(15, 2) for u16 values.
Fix the compilation error by adding the additional mask for the BITS
that the PHY ignore and AND the passed addr with the real mask that the
PHY will parse for the mailbox interface 4 addr to make sure extra
values are correctly removed.
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202311210414.sEJZjlcD-lkp@intel.com/
Fixes: e93984ebc1c8 ("net: phy: aquantia: add firmware load support")
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
drivers/net/phy/aquantia/aquantia.h | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
Comments
On Mon, 20 Nov 2023 20:35:04 +0100 Christian Marangi wrote: > It seems some arch (s390) require a more specific mask for FIELD_PREP > and doesn't like using GENMASK(15, 2) for u16 values. > > Fix the compilation error by adding the additional mask for the BITS > that the PHY ignore and AND the passed addr with the real mask that the > PHY will parse for the mailbox interface 4 addr to make sure extra > values are correctly removed. Ah. Um. Pff. Erm. I'm not sure. Endianness is not my strong suit but this code: /* PHY expect addr in LE */ addr = (__force u32)cpu_to_le32(addr); /* ... use (u16)(addr) */ /* ... use (u16)(addr >> 16) */ does not make sense to me. You're operating on register values here, there is no endian. Endian only exists when you store or load from memory. IOW, this: addr = 0x12345678; print((u16)addr); print(addr >> 16); will print the same exact thing regardless of the CPU endian. Why did you put the byte swap in there?
On Tue, Nov 21, 2023 at 03:08:59PM -0800, Jakub Kicinski wrote: > On Mon, 20 Nov 2023 20:35:04 +0100 Christian Marangi wrote: > > It seems some arch (s390) require a more specific mask for FIELD_PREP > > and doesn't like using GENMASK(15, 2) for u16 values. > > > > Fix the compilation error by adding the additional mask for the BITS > > that the PHY ignore and AND the passed addr with the real mask that the > > PHY will parse for the mailbox interface 4 addr to make sure extra > > values are correctly removed. > > Ah. Um. Pff. Erm. I'm not sure. > > Endianness is not my strong suit but this code: > > /* PHY expect addr in LE */ > addr = (__force u32)cpu_to_le32(addr); > > /* ... use (u16)(addr) */ > /* ... use (u16)(addr >> 16) */ > > does not make sense to me. > > You're operating on register values here, there is no endian. > Endian only exists when you store or load from memory. IOW, this: > > addr = 0x12345678; > print((u16)addr); > print(addr >> 16); > > will print the same exact thing regardless of the CPU endian. > > Why did you put the byte swap in there? the 2 addr comes from a define #define DRAM_BASE_ADDR 0x3FFE0000 #define IRAM_BASE_ADDR 0x40000000 it wasn't clear to me if on BE these addrs gets saved differently or not. PHY wants the addr in LE. On testing by removing the cpu_to_le32 the error is correctly removed! I guess on BE the addr was actually swapped and FIELD_GET was correctly warning (and failing) as data was missing in applying the mask. If all of this makes sense, will send a followup patch that drop the cpu_to_le32 and also the other in the bottom that does cpu_to_be32 (to a __swab32 as FW is LE and mailbox calculate CRC in BE)
On Wed, 22 Nov 2023 00:32:56 +0100 Christian Marangi wrote: > the 2 addr comes from a define > > #define DRAM_BASE_ADDR 0x3FFE0000 > #define IRAM_BASE_ADDR 0x40000000 > > it wasn't clear to me if on BE these addrs gets saved differently or > not. PHY wants the addr in LE. > > On testing by removing the cpu_to_le32 the error is correctly removed! > > I guess on BE the addr was actually swapped and FIELD_GET was correctly > warning (and failing) as data was missing in applying the mask. I think so. It's the responsibility of whether underlies phy_write_mmd() to make sure the data is put on the bus in correct order (but that's still just within the u16 boundaries, splitting a constant into u16 halves is not endian dependent). > If all of this makes sense, will send a followup patch that drop the > cpu_to_le32 and also the other in the bottom that does cpu_to_be32 (to a > __swab32 as FW is LE and mailbox calculate CRC in BE) Not so sure about this one, it puts the u32 on the stack, and takes the address of it: u32 word; word = (__force u32)cpu_to_be32(word); crc = crc_ccitt_false(crc, (u8 *)&word, sizeof(word)); so the endian will matter here. My guess is that this part is correct.
On Tue, Nov 21, 2023 at 03:39:18PM -0800, Jakub Kicinski wrote: > On Wed, 22 Nov 2023 00:32:56 +0100 Christian Marangi wrote: > > the 2 addr comes from a define > > > > #define DRAM_BASE_ADDR 0x3FFE0000 > > #define IRAM_BASE_ADDR 0x40000000 > > > > it wasn't clear to me if on BE these addrs gets saved differently or > > not. PHY wants the addr in LE. > > > > On testing by removing the cpu_to_le32 the error is correctly removed! > > > > I guess on BE the addr was actually swapped and FIELD_GET was correctly > > warning (and failing) as data was missing in applying the mask. > > I think so. It's the responsibility of whether underlies > phy_write_mmd() to make sure the data is put on the bus in > correct order (but that's still just within the u16 boundaries, > splitting a constant into u16 halves is not endian dependent). > > > If all of this makes sense, will send a followup patch that drop the > > cpu_to_le32 and also the other in the bottom that does cpu_to_be32 (to a > > __swab32 as FW is LE and mailbox calculate CRC in BE) > > Not so sure about this one, it puts the u32 on the stack, and takes > the address of it: > > u32 word; > > word = (__force u32)cpu_to_be32(word); > crc = crc_ccitt_false(crc, (u8 *)&word, sizeof(word)); > > so the endian will matter here. My guess is that this part is correct. Ehhh this is problematic. Data comes from nvmem or filesystem, in theory they should not be touched/converted. nvmem_cell_read or request_firmware return pointer to u8 and it's the firmware (that is always in LE) If data is not converted and passed AS IS from what is read to the allocated data, then data should be always swapped. (this PHY is fun... it's probably BE internally but expect LE stuff in the mailbox, as it does emit BE CRC.) Any idea where I can verify if nvmem_cell_read or request_firmware makes any kind of endianess conversion on the data it does read?
On Wed, 22 Nov 2023 00:48:01 +0100 Christian Marangi wrote: > > Not so sure about this one, it puts the u32 on the stack, and takes > > the address of it: > > > > u32 word; > > > > word = (__force u32)cpu_to_be32(word); > > crc = crc_ccitt_false(crc, (u8 *)&word, sizeof(word)); > > > > so the endian will matter here. My guess is that this part is correct. Actually I'm wrong about this, you're reading and writing the data, so endian conversion happens twice. Canceling itself out. > Ehhh this is problematic. Data comes from nvmem or filesystem, in theory > they should not be touched/converted. > > nvmem_cell_read or request_firmware return pointer to u8 and it's the > firmware (that is always in LE) > > If data is not converted and passed AS IS from what is read to the > allocated data, then data should be always swapped. > (this PHY is fun... it's probably BE internally but expect LE stuff in > the mailbox, as it does emit BE CRC.) > > Any idea where I can verify if nvmem_cell_read or request_firmware makes > any kind of endianess conversion on the data it does read? The underlying storage should be byte-accessible, so neither interface should change anything about the endian. You should probably switch get_unaligned_le32() for reading it into the word variable, tho.
On Tue, Nov 21, 2023 at 03:58:12PM -0800, Jakub Kicinski wrote: > On Wed, 22 Nov 2023 00:48:01 +0100 Christian Marangi wrote: > > > Not so sure about this one, it puts the u32 on the stack, and takes > > > the address of it: > > > > > > u32 word; > > > > > > word = (__force u32)cpu_to_be32(word); > > > crc = crc_ccitt_false(crc, (u8 *)&word, sizeof(word)); > > > > > > so the endian will matter here. My guess is that this part is correct. > > Actually I'm wrong about this, you're reading and writing the data, > so endian conversion happens twice. Canceling itself out. > > > Ehhh this is problematic. Data comes from nvmem or filesystem, in theory > > they should not be touched/converted. > > > > nvmem_cell_read or request_firmware return pointer to u8 and it's the > > firmware (that is always in LE) > > > > If data is not converted and passed AS IS from what is read to the > > allocated data, then data should be always swapped. > > (this PHY is fun... it's probably BE internally but expect LE stuff in > > the mailbox, as it does emit BE CRC.) > > > > Any idea where I can verify if nvmem_cell_read or request_firmware makes > > any kind of endianess conversion on the data it does read? > > The underlying storage should be byte-accessible, so neither interface > should change anything about the endian. > > You should probably switch get_unaligned_le32() for reading it into > the word variable, tho. I don't need to read it, I need to pass the data directly from what is read to mailbox so using get_unaligned_le32 would actually make a conversion. Anyway thanks a lot for putting some extra words and make me check this further! Will send a v2 tomorrow!
On Tue, Nov 21, 2023 at 03:39:18PM -0800, Jakub Kicinski wrote: > On Wed, 22 Nov 2023 00:32:56 +0100 Christian Marangi wrote: > > the 2 addr comes from a define > > > > #define DRAM_BASE_ADDR 0x3FFE0000 > > #define IRAM_BASE_ADDR 0x40000000 > > > > it wasn't clear to me if on BE these addrs gets saved differently or > > not. PHY wants the addr in LE. > > > > On testing by removing the cpu_to_le32 the error is correctly removed! > > > > I guess on BE the addr was actually swapped and FIELD_GET was correctly > > warning (and failing) as data was missing in applying the mask. > > I think so. It's the responsibility of whether underlies > phy_write_mmd() to make sure the data is put on the bus in > correct order (but that's still just within the u16 boundaries, > splitting a constant into u16 halves is not endian dependent). MDIO bus accesses via the MDIO bus accessors are expected to produce the correct value in CPU order no matter what endian the host platform is. So if the BMCR contains the value 0x1234, then reading and then printing this register is expected to produce 0x1234 irrespective of the host CPU architecture. We do have 32-bit values split across two registers in clause 45 PHYs, namely the MMD present register pair. Another example is the PHY ID. In both cases we read the registers and apply the appropriate shift. See get_phy_c45_ids() and get_phy_c22_id(). Note that these, again, have to work independent of the CPU architecture.
diff --git a/drivers/net/phy/aquantia/aquantia.h b/drivers/net/phy/aquantia/aquantia.h index 9ed38972abdb..7685bfaf0b07 100644 --- a/drivers/net/phy/aquantia/aquantia.h +++ b/drivers/net/phy/aquantia/aquantia.h @@ -30,7 +30,10 @@ #define VEND1_GLOBAL_MAILBOX_INTERFACE3_MSW_ADDR(x) FIELD_PREP(VEND1_GLOBAL_MAILBOX_INTERFACE3_MSW_ADDR_MASK, (u16)((x) >> 16)) #define VEND1_GLOBAL_MAILBOX_INTERFACE4 0x0203 #define VEND1_GLOBAL_MAILBOX_INTERFACE4_LSW_ADDR_MASK GENMASK(15, 2) -#define VEND1_GLOBAL_MAILBOX_INTERFACE4_LSW_ADDR(x) FIELD_PREP(VEND1_GLOBAL_MAILBOX_INTERFACE4_LSW_ADDR_MASK, (u16)(x)) +#define VEND1_GLOBAL_MAILBOX_INTERFACE4_LSW_ADDR_DONT_CARE_MASK GENMASK(1, 0) +#define VEND1_GLOBAL_MAILBOX_INTERFACE4_LSW_ADDR(x) FIELD_PREP(VEND1_GLOBAL_MAILBOX_INTERFACE4_LSW_ADDR_MASK | \ + VEND1_GLOBAL_MAILBOX_INTERFACE4_LSW_ADDR_DONT_CARE_MASK, \ + (u16)((x) & VEND1_GLOBAL_MAILBOX_INTERFACE4_LSW_ADDR_MASK)) #define VEND1_GLOBAL_MAILBOX_INTERFACE5 0x0204 #define VEND1_GLOBAL_MAILBOX_INTERFACE5_MSW_DATA_MASK GENMASK(15, 0)