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 D0FBDC77B6E for ; Fri, 14 Apr 2023 14:19:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229579AbjDNOT3 (ORCPT ); Fri, 14 Apr 2023 10:19:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229804AbjDNOT3 (ORCPT ); Fri, 14 Apr 2023 10:19:29 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6D48A262 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=1681481925; 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=WjtV6vZ5IsECtSF9Rad7AejqERNrFJHaWDg4MxPjslCkLwysRL1fZehBSkw1eZx/FZygJ/ 5fQwzA0U/eplBOt6z3chkwL3JxR1lx6J5OFiPPWmMKFgcguyBbsjQ/29M7+4VTvUCZZrup PqlVxeIdtQJWVxoN6JqgF6y9iIyG33E= 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-627-zDL_akYtMcicTXiXL1VoXA-1; Fri, 14 Apr 2023 10:18:44 -0400 X-MC-Unique: zDL_akYtMcicTXiXL1VoXA-1 Received: by mail-ej1-f71.google.com with SMTP id ud12-20020a170907c60c00b0093c44a07ad1so6757428ejc.2 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=DBoeeReJ56aewtHG9dRWynvOBZSqT8Dp6dYy8n0fis7mv0/cxSyvIoUWzKFEXFg4vQ 8swXc+mtKc7au/4hz2JDO6LvLKBU/IagG0n9G9KiqxYKrvVYL1hjASoxRVCm256r1Hg8 c/seOZGfTYAvPYUVbSSaPprUP+6w5JKGq7+rL6MjV5hBzf5h2bm9j/m5gVk3VqRS/gqs kS7S1NAmDje+s11tCyw45lHbHkw6cwlLBbQQLbGmFeHVMwYYK9GX9sLHj6g3RJ0qHOZV 2/rgve3MmApojP96tObwN69kbsmzrVXP2Ej/QfboNsEjdLpRu8xkQ6Dy4kqt4K6mbWJv Ri2w== X-Gm-Message-State: AAQBX9e4U/3Tbhv5J2JCrwiL1lKt9yG5fdqzyyRmWu/JVFZxitTCfZEH bRFVt8qckhI7cuT9x19Md+PInxr9HU+VebPMy6cXEiCjlxg6nJVHeiOTb/c12m/4GGcmE16r/q+ MBh5wolb0fy3b9T6QmoWE X-Received: by 2002:a17:907:7241:b0:94a:643e:9e26 with SMTP id ds1-20020a170907724100b0094a643e9e26mr5922543ejc.14.1681481922652; 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: bpf@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