Message ID | 20230414020915.1869456-1-yoong.siang.song@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp76694vqo; Thu, 13 Apr 2023 19:19:03 -0700 (PDT) X-Google-Smtp-Source: AKy350a6glM6/9a3RcCgUg4Sz38BZYX3fzXFFAlo4Fs17XK6QusuRwuymc+BMmjm/Qkg7vvT73d7 X-Received: by 2002:a05:6a00:995:b0:633:5c46:5a68 with SMTP id u21-20020a056a00099500b006335c465a68mr6585649pfg.10.1681438743513; Thu, 13 Apr 2023 19:19:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681438743; cv=none; d=google.com; s=arc-20160816; b=UtJQAFtBDpoY+9il3lAmrRjEkIoWiP08fLqi+JLl4okxNRTjT5ngdKOyb3pyqA/dj4 k0zH5XkvJIs22w4tzJrDAFGRvIlZBf3LerJvffx93+L/k3La6nxbaRlOBHbG8KIVQPhB etJyJEQceMv3FX7j5Z8YozdU7yY4xPXgi4R8mpK1KPQbt+ALed3HGgJO3WeVIA1KB+Jp oo45VP0Pi3aUOE3Pt5R1vAdLfITvxXsN2zJrW4hCYOYFgQZUGmX1lTeR5H8qYC/kNW0p I+P+9kuKPL2KWbRp+kuzCTiCZvRa+qpMMJAx0SOtKsC5nASb2lrdg+Qo7knnyWUW4gAm rwpQ== 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=dr4hzk2watELk9gT8m+R3Lt0A+sLblZNjGtNTe9aGto=; b=PASOwZSoZHQnIx1LNAKQfYZORlaCryJAKEjQfgTBRAM+DjPPRPWFERUVoUAGPIlCqg 2hYpDY2MZ6IxPwkaKvf9URa7eeE9bllj1eDeBES2f3rD6CNlmioQjld+fB+hQJJdum08 xSNEJuKLV/SbiMoXqTHoY00WcV3Z5ihc0iaoYU+W1D6V5J3EGpX2s+3HSX4/JSUP6zq9 uT/nTfJPRFEOFkPpQPQUjRfgpmIKE2G+51XMVMykILKnJMI/s58jsu4Z4LXxC8oAbfWW 49n8YiQRxV1deMxJtX96o/tNNe7lu08wAbljdJEvX6Agg7xpTW68OTGjlJRk94Rns1U/ Wy5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IwmEk92Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u126-20020a627984000000b006303ebae0eesi3285548pfc.378.2023.04.13.19.18.43; Thu, 13 Apr 2023 19:19:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IwmEk92Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229784AbjDNCKA (ORCPT <rfc822;peter110.wang@gmail.com> + 99 others); Thu, 13 Apr 2023 22:10:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229577AbjDNCJ6 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 13 Apr 2023 22:09:58 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 965132D4A; Thu, 13 Apr 2023 19:09:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681438197; x=1712974197; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=V6yxTKpwndzirxcebJgSFtOtxmxSXQn9YpBYMRBfZ4M=; b=IwmEk92YKmlopoiubdxsDjVO5YVj8uqSre6G7rLEt9+f9p7e2Sf5w3FE 8JigK0pHLHdTMWgoTTrnFqoG1BrZrPhSEIeCL4meE+Y+m71/a0Bb8aiZj oeEUQ5MbDTkQazeGt7kKnx4ZVGFWJwmcL39tOw87jkOqLfcSHboDhCVVg WfS7L+OpJ0q/E0hgxTfLj3y6mY9fZAwPn5WTCBIIH3LKb7eIdaOb/0u5f o0fcVRuD6KdC91ro0gULGfX1uOS/VRkpTNE8QWq2MGdXZT6XPpwFP9Jgo 94ssCv5U6njevTYfLDapt2tzEzO7xkNNbdAIQNQL55Swd8tk+OvvOge0+ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10679"; a="333124446" X-IronPort-AV: E=Sophos;i="5.99,195,1677571200"; d="scan'208";a="333124446" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2023 19:09:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10679"; a="779019528" X-IronPort-AV: E=Sophos;i="5.99,195,1677571200"; d="scan'208";a="779019528" Received: from p12ill20yoongsia.png.intel.com ([10.88.227.28]) by FMSMGA003.fm.intel.com with ESMTP; 13 Apr 2023 19:09:51 -0700 From: Song Yoong Siang <yoong.siang.song@intel.com> To: Jesse Brandeburg <jesse.brandeburg@intel.com>, Tony Nguyen <anthony.l.nguyen@intel.com>, "David S . Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Alexei Starovoitov <ast@kernel.org>, Daniel Borkmann <daniel@iogearbox.net>, Jesper Dangaard Brouer <hawk@kernel.org>, John Fastabend <john.fastabend@gmail.com>, Maciej Fijalkowski <maciej.fijalkowski@intel.com>, Vedang Patel <vedang.patel@intel.com>, Jithu Joseph <jithu.joseph@intel.com>, Andre Guedes <andre.guedes@intel.com>, Jesper Dangaard Brouer <brouer@redhat.com>, Stanislav Fomichev <sdf@google.com>, Jacob Keller <jacob.e.keller@intel.com> Cc: 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, Song Yoong Siang <yoong.siang.song@intel.com> Subject: [PATCH net v2 1/1] igc: read before write to SRRCTL register Date: Fri, 14 Apr 2023 10:09:15 +0800 Message-Id: <20230414020915.1869456-1-yoong.siang.song@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.4 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763075071541574863?= X-GMAIL-MSGID: =?utf-8?q?1763116311937510539?= |
Series |
[net,v2,1/1] igc: read before write to SRRCTL register
|
|
Commit Message
Song Yoong Siang
April 14, 2023, 2:09 a.m. UTC
igc_configure_rx_ring() function will be called as part of XDP program setup. If Rx hardware timestamp is enabled prio to XDP program setup, this timestamp enablement will be overwritten when buffer size is written into SRRCTL register. Thus, this commit read the register value before write to SRRCTL register. This commit is tested by using xdp_hw_metadata bpf selftest tool. The tool enables Rx hardware timestamp and then attach XDP program to igc driver. It will display hardware timestamp of UDP packet with port number 9092. Below are detail of test steps and results. Command on DUT: sudo ./xdp_hw_metadata <interface name> Command on Link Partner: echo -n skb | nc -u -q1 <destination IPv4 addr> 9092 Result before this patch: skb hwtstamp is not found! Result after this patch: found skb hwtstamp = 1677800973.642836757 Optionally, read PHC to confirm the values obtained are almost the same: Command: sudo ./testptp -d /dev/ptp0 -g Result: clock time: 1677800973.913598978 or Fri Mar 3 07:49:33 2023 Fixes: fc9df2a0b520 ("igc: Enable RX via AF_XDP zero-copy") Cc: <stable@vger.kernel.org> # 5.14+ Signed-off-by: Song Yoong Siang <yoong.siang.song@intel.com> Reviewed-by: Jacob Keller <jacob.e.keller@intel.com> --- v2 changelog: - Fix indention --- drivers/net/ethernet/intel/igc/igc_base.h | 7 +++++-- drivers/net/ethernet/intel/igc/igc_main.c | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-)
Comments
On 14/04/2023 04.09, Song Yoong Siang wrote: > igc_configure_rx_ring() function will be called as part of XDP program > setup. If Rx hardware timestamp is enabled prio to XDP program setup, > this timestamp enablement will be overwritten when buffer size is > written into SRRCTL register. > > Thus, this commit read the register value before write to SRRCTL > register. This commit is tested by using xdp_hw_metadata bpf selftest > tool. The tool enables Rx hardware timestamp and then attach XDP program > to igc driver. It will display hardware timestamp of UDP packet with > port number 9092. Below are detail of test steps and results. > > Command on DUT: > sudo ./xdp_hw_metadata <interface name> > > Command on Link Partner: > echo -n skb | nc -u -q1 <destination IPv4 addr> 9092 > > Result before this patch: > skb hwtstamp is not found! > > Result after this patch: > found skb hwtstamp = 1677800973.642836757 > > Optionally, read PHC to confirm the values obtained are almost the same: > Command: > sudo ./testptp -d /dev/ptp0 -g > Result: > clock time: 1677800973.913598978 or Fri Mar 3 07:49:33 2023 > > Fixes: fc9df2a0b520 ("igc: Enable RX via AF_XDP zero-copy") > Cc: <stable@vger.kernel.org> # 5.14+ > Signed-off-by: Song Yoong Siang <yoong.siang.song@intel.com> > Reviewed-by: Jacob Keller <jacob.e.keller@intel.com> > --- Reviewed-by: Jesper Dangaard Brouer <brouer@redhat.com> > v2 changelog: > - Fix indention > --- > drivers/net/ethernet/intel/igc/igc_base.h | 7 +++++-- > drivers/net/ethernet/intel/igc/igc_main.c | 5 ++++- > 2 files changed, 9 insertions(+), 3 deletions(-) > > diff --git a/drivers/net/ethernet/intel/igc/igc_base.h b/drivers/net/ethernet/intel/igc/igc_base.h > index 7a992befca24..b95007d51d13 100644 > --- a/drivers/net/ethernet/intel/igc/igc_base.h > +++ b/drivers/net/ethernet/intel/igc/igc_base.h > @@ -87,8 +87,11 @@ union igc_adv_rx_desc { > #define IGC_RXDCTL_SWFLUSH 0x04000000 /* Receive Software Flush */ > > /* SRRCTL bit definitions */ 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) > +#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. > +#define IGC_SRRCTL_DESCTYPE_MASK GENMASK(27, 25) > #define IGC_SRRCTL_DESCTYPE_ADV_ONEBUF 0x02000000 Given you have started using GENMASK(), then I would have updated IGC_SRRCTL_DESCTYPE_ADV_ONEBUF to be expressed like: #define IGC_SRRCTL_DESCTYPE_ADV_ONEBUF FIELD_PREP(IGC_SRRCTL_DESCTYPE_MASK, 0x1) Making it easier to see code is selecting: 001b = Advanced descriptor one buffer. And not (as I first though): 010b = Advanced descriptor header splitting. > #endif /* _IGC_BASE_H */ > diff --git a/drivers/net/ethernet/intel/igc/igc_main.c b/drivers/net/ethernet/intel/igc/igc_main.c > index 25fc6c65209b..88fac08d8a14 100644 > --- a/drivers/net/ethernet/intel/igc/igc_main.c > +++ b/drivers/net/ethernet/intel/igc/igc_main.c > @@ -641,7 +641,10 @@ static void igc_configure_rx_ring(struct igc_adapter *adapter, > else > buf_size = IGC_RXBUFFER_2048; > > - srrctl = IGC_RX_HDR_LEN << IGC_SRRCTL_BSIZEHDRSIZE_SHIFT; > + srrctl = rd32(IGC_SRRCTL(reg_idx)); > + srrctl &= ~(IGC_SRRCTL_BSIZEPKT_MASK | IGC_SRRCTL_BSIZEHDRSIZE_MASK | > + IGC_SRRCTL_DESCTYPE_MASK); > + srrctl |= IGC_RX_HDR_LEN << IGC_SRRCTL_BSIZEHDRSIZE_SHIFT; > srrctl |= buf_size >> IGC_SRRCTL_BSIZEPKT_SHIFT; > srrctl |= IGC_SRRCTL_DESCTYPE_ADV_ONEBUF; >
On Friday, April 14, 2023 5:50 PM, Jesper Dangaard Brouer <jbrouer@redhat.com> wrote: >On 14/04/2023 04.09, Song Yoong Siang wrote: >> igc_configure_rx_ring() function will be called as part of XDP program >> setup. If Rx hardware timestamp is enabled prio to XDP program setup, >> this timestamp enablement will be overwritten when buffer size is >> written into SRRCTL register. >> >> Thus, this commit read the register value before write to SRRCTL >> register. This commit is tested by using xdp_hw_metadata bpf selftest >> tool. The tool enables Rx hardware timestamp and then attach XDP >> program to igc driver. It will display hardware timestamp of UDP >> packet with port number 9092. Below are detail of test steps and results. >> >> Command on DUT: >> sudo ./xdp_hw_metadata <interface name> >> >> Command on Link Partner: >> echo -n skb | nc -u -q1 <destination IPv4 addr> 9092 >> >> Result before this patch: >> skb hwtstamp is not found! >> >> Result after this patch: >> found skb hwtstamp = 1677800973.642836757 >> >> Optionally, read PHC to confirm the values obtained are almost the same: >> Command: >> sudo ./testptp -d /dev/ptp0 -g >> Result: >> clock time: 1677800973.913598978 or Fri Mar 3 07:49:33 2023 >> >> Fixes: fc9df2a0b520 ("igc: Enable RX via AF_XDP zero-copy") >> Cc: <stable@vger.kernel.org> # 5.14+ >> Signed-off-by: Song Yoong Siang <yoong.siang.song@intel.com> >> Reviewed-by: Jacob Keller <jacob.e.keller@intel.com> >> --- > >Reviewed-by: Jesper Dangaard Brouer <brouer@redhat.com> > >> v2 changelog: >> - Fix indention >> --- >> drivers/net/ethernet/intel/igc/igc_base.h | 7 +++++-- >> drivers/net/ethernet/intel/igc/igc_main.c | 5 ++++- >> 2 files changed, 9 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/net/ethernet/intel/igc/igc_base.h >> b/drivers/net/ethernet/intel/igc/igc_base.h >> index 7a992befca24..b95007d51d13 100644 >> --- a/drivers/net/ethernet/intel/igc/igc_base.h >> +++ b/drivers/net/ethernet/intel/igc/igc_base.h >> @@ -87,8 +87,11 @@ union igc_adv_rx_desc { >> #define IGC_RXDCTL_SWFLUSH 0x04000000 /* Receive >Software Flush */ >> >> /* SRRCTL bit definitions */ > >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. > >> +#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 dint put the explanation into the header file because it is too lengthy and user can know from databook. How do you feel on the necessary of explaining the shifting logic? > >> +#define IGC_SRRCTL_DESCTYPE_MASK GENMASK(27, 25) >> #define IGC_SRRCTL_DESCTYPE_ADV_ONEBUF 0x02000000 > >Given you have started using GENMASK(), then I would have updated >IGC_SRRCTL_DESCTYPE_ADV_ONEBUF to be expressed like: > > #define IGC_SRRCTL_DESCTYPE_ADV_ONEBUF FIELD_PREP(IGC_SRRCTL_DESCTYPE_MASK, 0x1) > >Making it easier to see code is selecting: > 001b = Advanced descriptor one buffer. > >And not (as I first though): > 010b = Advanced descriptor header splitting. > You are right. Using FIELD_PREP() make the code clearer. Thanks for your suggestion. I will submit v3 for it. > >> #endif /* _IGC_BASE_H */ >> diff --git a/drivers/net/ethernet/intel/igc/igc_main.c >> b/drivers/net/ethernet/intel/igc/igc_main.c >> index 25fc6c65209b..88fac08d8a14 100644 >> --- a/drivers/net/ethernet/intel/igc/igc_main.c >> +++ b/drivers/net/ethernet/intel/igc/igc_main.c >> @@ -641,7 +641,10 @@ static void igc_configure_rx_ring(struct igc_adapter >*adapter, >> else >> buf_size = IGC_RXBUFFER_2048; >> >> - srrctl = IGC_RX_HDR_LEN << IGC_SRRCTL_BSIZEHDRSIZE_SHIFT; >> + srrctl = rd32(IGC_SRRCTL(reg_idx)); >> + srrctl &= ~(IGC_SRRCTL_BSIZEPKT_MASK | >IGC_SRRCTL_BSIZEHDRSIZE_MASK | >> + IGC_SRRCTL_DESCTYPE_MASK); >> + srrctl |= IGC_RX_HDR_LEN << IGC_SRRCTL_BSIZEHDRSIZE_SHIFT; >> srrctl |= buf_size >> IGC_SRRCTL_BSIZEPKT_SHIFT; >> srrctl |= IGC_SRRCTL_DESCTYPE_ADV_ONEBUF; >>
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. > >> +#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 dint put the explanation into the header file because it is too lengthy > and user can know from databook. > > 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. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
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
On Friday, April 14, 2023 10:19 PM, Jesper Dangaard Brouer <jbrouer@redhat.com> wrote: >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 Thanks David and Jesper for the comments. I agree to make the code more human readable. Will refactor the code and send out v3 for review. Thanks & Regards Siang
diff --git a/drivers/net/ethernet/intel/igc/igc_base.h b/drivers/net/ethernet/intel/igc/igc_base.h index 7a992befca24..b95007d51d13 100644 --- a/drivers/net/ethernet/intel/igc/igc_base.h +++ b/drivers/net/ethernet/intel/igc/igc_base.h @@ -87,8 +87,11 @@ union igc_adv_rx_desc { #define IGC_RXDCTL_SWFLUSH 0x04000000 /* Receive Software Flush */ /* SRRCTL bit definitions */ -#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_ */ +#define IGC_SRRCTL_BSIZEHDRSIZE_MASK GENMASK(13, 8) +#define IGC_SRRCTL_BSIZEHDRSIZE_SHIFT 2 /* Shift _left_ */ +#define IGC_SRRCTL_DESCTYPE_MASK GENMASK(27, 25) #define IGC_SRRCTL_DESCTYPE_ADV_ONEBUF 0x02000000 #endif /* _IGC_BASE_H */ diff --git a/drivers/net/ethernet/intel/igc/igc_main.c b/drivers/net/ethernet/intel/igc/igc_main.c index 25fc6c65209b..88fac08d8a14 100644 --- a/drivers/net/ethernet/intel/igc/igc_main.c +++ b/drivers/net/ethernet/intel/igc/igc_main.c @@ -641,7 +641,10 @@ static void igc_configure_rx_ring(struct igc_adapter *adapter, else buf_size = IGC_RXBUFFER_2048; - srrctl = IGC_RX_HDR_LEN << IGC_SRRCTL_BSIZEHDRSIZE_SHIFT; + srrctl = rd32(IGC_SRRCTL(reg_idx)); + srrctl &= ~(IGC_SRRCTL_BSIZEPKT_MASK | IGC_SRRCTL_BSIZEHDRSIZE_MASK | + IGC_SRRCTL_DESCTYPE_MASK); + srrctl |= IGC_RX_HDR_LEN << IGC_SRRCTL_BSIZEHDRSIZE_SHIFT; srrctl |= buf_size >> IGC_SRRCTL_BSIZEPKT_SHIFT; srrctl |= IGC_SRRCTL_DESCTYPE_ADV_ONEBUF;