Received: by 10.223.185.116 with SMTP id b49csp3792511wrg; Mon, 19 Feb 2018 06:09:06 -0800 (PST) X-Google-Smtp-Source: AH8x225p3XWV0DQKMAFtYGMdI8ub7HI+gWVknXhEzx2TuLzTEzUIZzv4zASpYgpS5ts/K3ctNLMw X-Received: by 10.98.32.28 with SMTP id g28mr408415pfg.182.1519049346411; Mon, 19 Feb 2018 06:09:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519049346; cv=none; d=google.com; s=arc-20160816; b=TtpWMK2EYJsF6beoCLfc1x1hIMgryvu77ElrOi1CIlc4CmarQaFL5t4iWGmcffuO8w wv1VqI6JRVhgu802MvaOiElRvWnaVqwIEwABtb9skhVQ69xpuN2SI05KS+gcty/VvNXQ 8YWvlaOspG151tyfnNfv1L060pq+RObaN33fiRPFGAqzHUv3RiIFGZfGvydIMT23cjSZ /W0zdvND/CzctcdMgshOqYCFSm6lk3kFETCqQHStyHhnltKSRcd5RCqD28thteXqUZXZ h6cnwEJw2+hqZNUVBkA2wsqdmoxv0bkiY1Lcc1jVqjeUgc2VtKIe+5YGy7nPLI6IpkoC GlWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=mHT6h95Er0Fd+YNAmv5fIRt1g9c9MjycQGdoYMxpzzY=; b=Z/m0+9KJfW9i+GEmNnkFpozNWgpQ6KOhj2sC8GKakOtuoULKfSXlrF3poJxVGxSCmv GZgaUVredv6lXIArR9zoWyfqFHb7Vy6MtyWkRgW/4R21c1O2OEZbPLAyl1oc/iqwwRvo 850+oZH2oHbCs63nxEU2xv4SSTNbqthxxAGspRrF3Wb11z01GrlD4HHLLf0Dw+eMO8M4 2b8P9cdi73iioWLddJB/oMCxVwRDkQ/XjbVxC0vr+jrhVbLUATxu1Cs4jGBSb1fayw2x NunEDxils2R/Ky/Iuk5PZ2WD65J0hYgyRBhBk4eJUsxgnZi2XyNDg1fzF6gtL1DkIkjI zDaw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t199si5225232pgb.105.2018.02.19.06.08.51; Mon, 19 Feb 2018 06:09:06 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752839AbeBSOHx (ORCPT + 99 others); Mon, 19 Feb 2018 09:07:53 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:58122 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751525AbeBSOHw (ORCPT ); Mon, 19 Feb 2018 09:07:52 -0500 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w1JE6P8b097903 for ; Mon, 19 Feb 2018 09:07:52 -0500 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 2g7ym2sbe3-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 19 Feb 2018 09:07:51 -0500 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 19 Feb 2018 14:07:48 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 19 Feb 2018 14:07:45 -0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w1JE7jro46530764; Mon, 19 Feb 2018 14:07:45 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AE202A4051; Mon, 19 Feb 2018 14:00:58 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2547AA405B; Mon, 19 Feb 2018 14:00:56 +0000 (GMT) Received: from localhost.in.ibm.com (unknown [9.195.32.254]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 19 Feb 2018 14:00:55 +0000 (GMT) From: Anshuman Khandual To: linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, bart.vanassche@wdc.com, jthumshirn@suse.de, axboe@kernel.dk, chris@chris-wilson.co.uk, tvrtko.ursulin@intel.com Cc: khandual@linux.vnet.ibm.com Subject: [PATCH V3] lib/scatterlist: Add SG_CHAIN and SG_LAST macros for LSB encodings Date: Mon, 19 Feb 2018 19:37:39 +0530 X-Mailer: git-send-email 2.9.3 X-TM-AS-GCONF: 00 x-cbid: 18021914-0008-0000-0000-000004D13D01 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18021914-0009-0000-0000-00001E6448B0 Message-Id: <20180219140739.24383-1-khandual@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-02-19_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1802190176 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This replaces scatterlist->page_link LSB encodings with SG_CHAIN and SG_LAST definitions without any functional change. While here also add macro definitions SG_PAGE_BITS and SG_PAGE_MASK. Signed-off-by: Anshuman Khandual --- Changes in V3: - Changed SG_END as SG_LAST due to a build failure - Added SG_PAGE_BITS and SG_PAGE_MASK as per Tvrtko - Used BIT() macro as per Chris Changes in V2: - Changed SG_EMARK as SG_END as per Johannes and Tvrtko - Added 'UL' to the constants as per Bart include/linux/scatterlist.h | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h index 22b2131bcdcd..494b84c7f3c8 100644 --- a/include/linux/scatterlist.h +++ b/include/linux/scatterlist.h @@ -66,15 +66,20 @@ struct sg_table { #define SG_MAGIC 0x87654321 +#define SG_CHAIN BIT(0) +#define SG_LAST BIT(1) +#define SG_PAGE_BITS (SG_CHAIN | SG_LAST) +#define SG_PAGE_MASK (~SG_PAGE_BITS) + /* * We overload the LSB of the page pointer to indicate whether it's * a valid sg entry, or whether it points to the start of a new scatterlist. * Those low bits are there for everyone! (thanks mason :-) */ -#define sg_is_chain(sg) ((sg)->page_link & 0x01) -#define sg_is_last(sg) ((sg)->page_link & 0x02) +#define sg_is_chain(sg) ((sg)->page_link & SG_CHAIN) +#define sg_is_last(sg) ((sg)->page_link & SG_LAST) #define sg_chain_ptr(sg) \ - ((struct scatterlist *) ((sg)->page_link & ~0x03)) + ((struct scatterlist *) ((sg)->page_link & SG_PAGE_MASK)) /** * sg_assign_page - Assign a given page to an SG entry @@ -88,13 +93,13 @@ struct sg_table { **/ static inline void sg_assign_page(struct scatterlist *sg, struct page *page) { - unsigned long page_link = sg->page_link & 0x3; + unsigned long page_link = sg->page_link & SG_PAGE_BITS; /* * In order for the low bit stealing approach to work, pages * must be aligned at a 32-bit boundary as a minimum. */ - BUG_ON((unsigned long) page & 0x03); + BUG_ON((unsigned long) page & SG_PAGE_BITS); #ifdef CONFIG_DEBUG_SG BUG_ON(sg->sg_magic != SG_MAGIC); BUG_ON(sg_is_chain(sg)); @@ -130,7 +135,7 @@ static inline struct page *sg_page(struct scatterlist *sg) BUG_ON(sg->sg_magic != SG_MAGIC); BUG_ON(sg_is_chain(sg)); #endif - return (struct page *)((sg)->page_link & ~0x3); + return (struct page *)((sg)->page_link & SG_PAGE_MASK); } /** @@ -178,7 +183,8 @@ static inline void sg_chain(struct scatterlist *prv, unsigned int prv_nents, * Set lowest bit to indicate a link pointer, and make sure to clear * the termination bit if it happens to be set. */ - prv[prv_nents - 1].page_link = ((unsigned long) sgl | 0x01) & ~0x02; + prv[prv_nents - 1].page_link = ((unsigned long) sgl | SG_CHAIN) + & ~SG_LAST; } /** @@ -198,8 +204,8 @@ static inline void sg_mark_end(struct scatterlist *sg) /* * Set termination bit, clear potential chain bit */ - sg->page_link |= 0x02; - sg->page_link &= ~0x01; + sg->page_link |= SG_LAST; + sg->page_link &= ~SG_CHAIN; } /** @@ -215,7 +221,7 @@ static inline void sg_unmark_end(struct scatterlist *sg) #ifdef CONFIG_DEBUG_SG BUG_ON(sg->sg_magic != SG_MAGIC); #endif - sg->page_link &= ~0x02; + sg->page_link &= ~SG_LAST; } /** -- 2.11.0