Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp75241ybh; Tue, 10 Mar 2020 19:43:37 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsMB3fNiClipfgYPeiEddtRtvb0j7cHDZL53hA4IiR6SFGH8H8qYi0ZSaC1XvKRoCWWnMyD X-Received: by 2002:a05:6830:239b:: with SMTP id l27mr673558ots.278.1583894617601; Tue, 10 Mar 2020 19:43:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583894617; cv=none; d=google.com; s=arc-20160816; b=plGEXUWl5Isd+SzfXQYBgaC+ZtLL/86xEB5pd7dEE7WIgZceEoFstIPVO5JfwMvjXC dBKVOTnKGL8zMgAN61as3sewKaWyD2dL1j7DxKEPq3hKsr/pqyXdoSk/QDeJ+j2CQwkJ SHMNH6wEvw9WfF6Hxfyxn7KpPzXTobWJDw2/yaJgCs43bL8SsZYxpAWZIr9+e9Qpll3s 4ehdDhAXeyJHKbY5V16y91Uk3O0ZSgwR0vnTdB3yE8+z/E5AWpnlPnfHA2n+tOKlWKmM k39g65QosDqUUbOTHUoW/+b0OO1E8VoPBPkW5MufM7mBo97maY8cmGljvlq1fnGGsjY1 fIXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=z34hT5bULDEZ91B4ZRD0I3GVUqGPOkD4dMmDdKPzM1w=; b=pSGD40XhJ9KasJqP4wvelFBOHiqDGYpLHx8TwS+R0CsAMNW4C0Sqw5Jbg98E2LTGER 4TNVnIHunq9DrCViGyeAhCpr0gKYgNr7BwFSfuJuTlApvQOvyqfohG4B2u6HoNrhdknV CFrmKuMQ/kbOVo5KfcZBN45WUDCGozRwWrj2D9ePU2x2PytBAlwqBE+u3qot4O/gjCJc LUZTjw9YXah6MhKRQL7mL79U0pS2v7T/svZI3eJz6GV8d4wSB8vbXyYQgwdQeYSRy3m2 d+0zLIf9DFl+q3fWzoPXrMFbHJCioBRaHY5ADUQvzCxsfZYgDqGLuEa2E2TqrF/8LoPr oi2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M0ZoqeGg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p13si347657otk.75.2020.03.10.19.43.25; Tue, 10 Mar 2020 19:43:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M0ZoqeGg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728008AbgCKCmq (ORCPT + 99 others); Tue, 10 Mar 2020 22:42:46 -0400 Received: from mail-yw1-f68.google.com ([209.85.161.68]:45485 "EHLO mail-yw1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727648AbgCKCmq (ORCPT ); Tue, 10 Mar 2020 22:42:46 -0400 Received: by mail-yw1-f68.google.com with SMTP id d206so619838ywa.12 for ; Tue, 10 Mar 2020 19:42:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=z34hT5bULDEZ91B4ZRD0I3GVUqGPOkD4dMmDdKPzM1w=; b=M0ZoqeGgG+H1m7mfw/LTqZ+immbVB/GDQ11/vgSYcolxH+Bclr5pw31gNg1OfvPjhl Lcg2AmQA9PWp7+Ilgnvbi9Xnr/b/kSvym5zDEKyqNjdLcqtaPeSK8Nv43jaVoIhjRQTM xBqlSyC8FUImBaNsGoHSklolbii9rpGHRXDSF9LYLX/k9u5Zjd4saXv5EhluzJIYsxvA PwhH9biQ+OmTw3CPxCfBAt9HI2eCugdQb8KerivL+FD4kkjm99VXnJtYggu0LnAATs3T PE6PXMino1OW0mK1qDUlm3w3fqky5KSppx+ugvCuJbhAQI7ap2hXZ+0qx9qe/nbjw8el SDmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=z34hT5bULDEZ91B4ZRD0I3GVUqGPOkD4dMmDdKPzM1w=; b=F61fWLIhozaSVqUvsAS2HrnlMcmwnr6yvyRA5ffFO8Lh3+0qYBQR3KINl7B8XdLMvE 5HXldHrSfFhyELGwqVl/i8V8pHwG+8NBM7npltlSJCLZs/2A1/L/YeML2ArQWhb64zUP 4bAER1TcCFLaMb5lNlyUYzHlEKnGKK7zUs4NWlhZ6Oy+NaYr03dGWIVqxgUoy1x0FH5o rAg7Ei1Rn9tG1UKAGeTz/xjYKIKn+nt5GEDTfPY+eAa4qHVVJmKkguLg7196G55rKtB3 XQUmi1cBLj73Etox8wznd9akqU/6RRh1klbqxxipoGV2C3JxaSuu6VTdFwi6O669sBpX /oOA== X-Gm-Message-State: ANhLgQ0/2UYTZyXENtXQX/+w1joK+kOwLh6Q+5ozVF6i1R6NEigLpKfV qO9MVGcBCMuU3vI25Amot0BiUQ== X-Received: by 2002:a25:9ac5:: with SMTP id t5mr809418ybo.305.1583894564945; Tue, 10 Mar 2020 19:42:44 -0700 (PDT) Received: from presto.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id x81sm19262510ywa.96.2020.03.10.19.42.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Mar 2020 19:42:44 -0700 (PDT) From: Alex Elder To: David Miller , Jakub Kicinski Cc: Nathan Chancellor , Al Viro , Johannes Berg , Arnd Bergmann , Masahiro Yamada , Bjorn Andersson , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] bitfield.h: add FIELD_MAX() and field_max() Date: Tue, 10 Mar 2020 21:42:40 -0500 Message-Id: <20200311024240.26834-1-elder@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Define FIELD_MAX(), which supplies the maximum value that can be represented by a field value. Define field_max() as well, to go along with the lower-case forms of the field mask functions. Signed-off-by: Alex Elder Acked-by: Jakub Kicinski --- v3: Rebased on latest netdev-next/master. David, please take this into net-next as soon as possible. When the IPA code was merged the other day this prerequisite patch was not included, and as a result the IPA driver fails to build. Thank you. See: https://lkml.org/lkml/2020/3/10/1839 -Alex include/linux/bitfield.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h index 4bbb5f1c8b5b..48ea093ff04c 100644 --- a/include/linux/bitfield.h +++ b/include/linux/bitfield.h @@ -55,6 +55,19 @@ (1ULL << __bf_shf(_mask))); \ }) +/** + * FIELD_MAX() - produce the maximum value representable by a field + * @_mask: shifted mask defining the field's length and position + * + * FIELD_MAX() returns the maximum value that can be held in the field + * specified by @_mask. + */ +#define FIELD_MAX(_mask) \ + ({ \ + __BF_FIELD_CHECK(_mask, 0ULL, 0ULL, "FIELD_MAX: "); \ + (typeof(_mask))((_mask) >> __bf_shf(_mask)); \ + }) + /** * FIELD_FIT() - check if value fits in the field * @_mask: shifted mask defining the field's length and position @@ -110,6 +123,7 @@ static __always_inline u64 field_mask(u64 field) { return field / field_multiplier(field); } +#define field_max(field) ((typeof(field))field_mask(field)) #define ____MAKE_OP(type,base,to,from) \ static __always_inline __##type type##_encode_bits(base v, base field) \ { \ -- 2.20.1