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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3642DC77B6E for ; Fri, 14 Apr 2023 14:19:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230115AbjDNOTd (ORCPT ); Fri, 14 Apr 2023 10:19:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229840AbjDNOTa (ORCPT ); Fri, 14 Apr 2023 10:19:30 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEB5AA24D for ; Fri, 14 Apr 2023 07:18:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681481924; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sX4uJHc1E4iUI/WZObcqqEuHDDY4tzWA7F305PZUU8s=; b=REMWvxTKWO5b0w/pxGCn/GFMYjOIRnGpwoNKtikmwScgc6PXe5oCainaZUto5B/ZOSwcwI giQ66MfUT9aXrl2ycjgzWhM/iR9kty5tQBGDVuhFtupn7Y0x4VlYSfyix+d6BagQmz8nfM jO/Gfq2GhId+SUV5OCzyZGnmXhtgEgE= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-108-Bf9ov3KlMJijzpMTTRtbTw-1; Fri, 14 Apr 2023 10:18:43 -0400 X-MC-Unique: Bf9ov3KlMJijzpMTTRtbTw-1 Received: by mail-ej1-f71.google.com with SMTP id f2-20020a170906084200b0094e971d803bso2202776ejd.7 for ; Fri, 14 Apr 2023 07:18:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681481922; x=1684073922; h=content-transfer-encoding:in-reply-to:references:to :content-language:subject:cc:user-agent:mime-version:date:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sX4uJHc1E4iUI/WZObcqqEuHDDY4tzWA7F305PZUU8s=; b=JJe2IfRVgkpSv+VST0xqip0QI8sAzzOo+0HaAFVlerX/o7JNauIHv2kt55f5ajTKLF RJOHx5iiJytMaoUUCERcgaAlABi21aGi23XTueuq8oH8T6pLng3QoNai+8pUPs2C/VbX +P9E8ukWF/OcSMaVr7bvxPyaub9mxIXVFdJUoJIWPE4/PPhTpf+oT9u7zit3nPSQY8mN CM9+S9XzFVFhVayinIOha/521TZmCPKWpZ86eeO0JI0Le+LQRUcE26sYfHT9HvT74AIl Hcbx6RapDIP126xGr3UXnTZpbCMX+DEBGSMJ0sPywlWdEtdJsrvQIvg7M3q+aWCU1NXU a9LA== X-Gm-Message-State: AAQBX9fUtQO4ixmPEnEQI5Ru2CmHfGS77zNi8FsLZSa7g0Ir5aDxZ2hg 25noEXev8Ty90nA3/VabyCdhQ5lesJMyu8Ly4lfIQDnbzr/MvsrGJHFmpPLjo5J5j9y4Z3mS/ct EYRKSR2efRzOkGRiawjrynsDk X-Received: by 2002:a17:907:7241:b0:94a:643e:9e26 with SMTP id ds1-20020a170907724100b0094a643e9e26mr5922558ejc.14.1681481922665; Fri, 14 Apr 2023 07:18:42 -0700 (PDT) X-Google-Smtp-Source: AKy350ZGanoF3DPoBXFRBQWN2exgOX9hffPn/GzhyqL5JtNnAtLoKcw780bho7MF1qA/qcnMgOnwzA== X-Received: by 2002:a17:907:7241:b0:94a:643e:9e26 with SMTP id ds1-20020a170907724100b0094a643e9e26mr5922524ejc.14.1681481922343; Fri, 14 Apr 2023 07:18:42 -0700 (PDT) Received: from [192.168.42.222] (194-45-78-10.static.kviknet.net. [194.45.78.10]) by smtp.gmail.com with ESMTPSA id p9-20020a170906838900b009497509fda3sm2503755ejx.40.2023.04.14.07.18.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 14 Apr 2023 07:18:41 -0700 (PDT) From: Jesper Dangaard Brouer X-Google-Original-From: Jesper Dangaard Brouer Message-ID: Date: Fri, 14 Apr 2023 16:18:39 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Cc: brouer@redhat.com, "intel-wired-lan@lists.osuosl.org" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "bpf@vger.kernel.org" , "xdp-hints@xdp-project.net" , "stable@vger.kernel.org" , Alexander Lobakin Subject: Re: [PATCH net v2 1/1] igc: read before write to SRRCTL register Content-Language: en-US To: David Laight , "'Song, Yoong Siang'" , Jesper Dangaard Brouer , "Brandeburg, Jesse" , "Nguyen, Anthony L" , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , "Fijalkowski, Maciej" , Vedang Patel , "Joseph, Jithu" , Andre Guedes , Stanislav Fomichev , "Keller, Jacob E" References: <20230414020915.1869456-1-yoong.siang.song@intel.com> <8214fb10-8caa-4418-8435-85b6ac27b69e@redhat.com> <4dc9ea6c77ff49138a49d7f73f7301fd@AcuMS.aculab.com> In-Reply-To: <4dc9ea6c77ff49138a49d7f73f7301fd@AcuMS.aculab.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 14/04/2023 14.32, David Laight wrote: > From: Song, Yoong Siang >> Sent: 14 April 2023 12:16 > ... >>> I have checked Foxville manual for SRRCTL (Split and Replication Receive >>> Control) register and below GENMASKs looks correct. >>> >>>> -#define IGC_SRRCTL_BSIZEPKT_SHIFT 10 /* Shift _right_ */ >>>> -#define IGC_SRRCTL_BSIZEHDRSIZE_SHIFT 2 /* Shift _left_ */ >>>> +#define IGC_SRRCTL_BSIZEPKT_MASK GENMASK(6, 0) >>>> +#define IGC_SRRCTL_BSIZEPKT_SHIFT 10 /* Shift _right_ */ >>> >>> Shift due to 1 KB resolution of BSIZEPKT (manual field BSIZEPACKET) >> >> Ya, 1K = BIT(10), so need to shift right 10 bits. > > I bet the code would be easier to read if it did 'value / 1024u'. > The object code will be (much) the same. I agree. Code becomes more readable for humans and machine code will be the same. >>>> +#define IGC_SRRCTL_BSIZEHDRSIZE_MASK GENMASK(13, 8) >>>> +#define IGC_SRRCTL_BSIZEHDRSIZE_SHIFT 2 /* Shift _left_ */ >>> >>> This shift is suspicious, but as you inherited it I guess it works. >>> I did the math, and it happens to work, knowing (from manual) value is in 64 bytes >>> resolution. >> >> It is in 64 = BIT(6) resolution, so need to shift right 6 bits. >> But it start on 8th bit, so need to shift left 8 bits. >> Thus, total = shift left 2 bits. >> >> I didnt put the explanation into the header file because it is too lengthy >> and user can know from databook. Well, users usually don't have access to the databook (Programming Interface) PDF. Personally I have it, but I had to go though a lot of red-tape to get it (under Red Hat NDA). >> >> How do you feel on the necessary of explaining the shifting logic? > > Not everyone trying to grok the code will have the manual. > Even writing (8 - 6) will help. > Or (I think) if the value is in bits 13-8 in units of 64 then just: > ((value >> 8) & 0x1f) * 64 > gcc will do a single shift right and a mask 9at some point). > You might want some defines, but if they aren't used much > just comments that refer to the names in the manual/datasheet > can be enough. > After Alexander Lobakin opened my eyes for GENMASK, FIELD_PREP and FIELD_GET, I find that easier to read and work-with these kind of register value manipulations, see[1] include/linux/bitfield.h. It will also detect if the assigned value exceeds the mask (like David code handled via mask). (thx Alex) [1] https://elixir.bootlin.com/linux/v6.3-rc6/source/include/linux/bitfield.h#L14 So, instead of: srrctl |= IGC_RX_HDR_LEN << IGC_SRRCTL_BSIZEHDRSIZE_SHIFT; I would write /* BSIZEHDR value in 64 bytes resolution */ srrctl |= FIELD_PREP(IGC_SRRCTL_BSIZEHDRSIZE_MASK, (IGC_RX_HDR_LEN / 64)); --Jesper