From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mail.toke.dk (Postfix) with ESMTPS id 4C81B9FE016 for ; Fri, 14 Apr 2023 16:18:45 +0200 (CEST) Authentication-Results: mail.toke.dk; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=REMWvxTK 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-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-287-Jwp5vHaSNnuLMLBFp74KVg-1; Fri, 14 Apr 2023 10:18:43 -0400 X-MC-Unique: Jwp5vHaSNnuLMLBFp74KVg-1 Received: by mail-ej1-f69.google.com with SMTP id ue7-20020a170907c68700b009339c9c32ffso6793525ejc.5 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=hq9YNKUbzSSBDDlxLtb2fP9IL+g22raIs4ijQp2NGM91ATNRrhMLQ3/xhDBBASon6N 6d0nC3euDueEmEUQqQr9gCF+fqLXvaenibSDpf/tj2bzMUWP69jMUEMw3UdeiW7gC2WU ET2SZVULzkbsFPm25xFoGd9uArGaxc3iPxPpJ/w9144BPbUBH8MpFSZNufbUEkouJ3+Q 8ODG/eRf/nzTZPLCLw8nX6MI+2Jen7hZ4L9puFK7D/wUhGnOvzEXxe/dE8gnFcmDlmiE oUVBMNsMXRpd83/Z1Ig/jGBm4967RQqfP5aGFkhR7HT+RHo1F6lvo8Q5e7+YdhKUmNEi yQIQ== X-Gm-Message-State: AAQBX9fYxvjxc5n+1GThmU4EoEhO+8wl0h4PqhDU2IzVLbxOOin42BmN 5rpq4LbjfRkKSz2xd36einzwWEBdmw9uahXD+URuvJW0n2ATOnZaqXVNVr+g6HaT1tLef3z6WTB o6+55kT+mxd81Mk3Tp9Jf X-Received: by 2002:a17:907:7241:b0:94a:643e:9e26 with SMTP id ds1-20020a170907724100b0094a643e9e26mr5922569ejc.14.1681481922681; 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 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> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: MRM6GUPZCPGI3PD5IMHBM2LRQ5MFA2RL X-Message-ID-Hash: MRM6GUPZCPGI3PD5IMHBM2LRQ5MFA2RL X-MailFrom: jbrouer@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header 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 X-Mailman-Version: 3.3.8 Precedence: list Subject: [xdp-hints] Re: [PATCH net v2 1/1] igc: read before write to SRRCTL register List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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