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 X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6BC19C5DF60 for ; Thu, 7 Nov 2019 18:19:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 28298214D8 for ; Thu, 7 Nov 2019 18:19:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 28298214D8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B1AC76B0003; Thu, 7 Nov 2019 13:19:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ACC566B0005; Thu, 7 Nov 2019 13:19:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 994086B0007; Thu, 7 Nov 2019 13:19:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0025.hostedemail.com [216.40.44.25]) by kanga.kvack.org (Postfix) with ESMTP id 850AE6B0003 for ; Thu, 7 Nov 2019 13:19:16 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 0C2EB181AEF0B for ; Thu, 7 Nov 2019 18:19:16 +0000 (UTC) X-FDA: 76130293512.20.bat79_6de7989324d27 X-HE-Tag: bat79_6de7989324d27 X-Filterd-Recvd-Size: 7447 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf13.hostedemail.com (Postfix) with ESMTP for ; Thu, 7 Nov 2019 18:19:15 +0000 (UTC) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id xA7I7kth024883 for ; Thu, 7 Nov 2019 13:19:14 -0500 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0a-001b2d01.pphosted.com with ESMTP id 2w4np3fx48-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 07 Nov 2019 13:19:13 -0500 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 7 Nov 2019 18:19:10 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp04.uk.ibm.com (192.168.101.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 7 Nov 2019 18:19:02 -0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id xA7IJ1dU44105970 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Nov 2019 18:19:01 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1E2024C046; Thu, 7 Nov 2019 18:19:01 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 04D9F4C044; Thu, 7 Nov 2019 18:19:00 +0000 (GMT) Received: from pic2.home (unknown [9.145.15.120]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 7 Nov 2019 18:18:59 +0000 (GMT) Subject: Re: [PATCH 07/10] ocxl: Save the device serial number in ocxl_fn To: "Alastair D'Silva" , alastair@d-silva.org Cc: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Andrew Donnellan , Arnd Bergmann , Greg Kroah-Hartman , Dan Williams , Vishal Verma , Dave Jiang , Keith Busch , Ira Weiny , Krzysztof Kozlowski , Anton Blanchard , Madhavan Srinivasan , Thomas Gleixner , Mahesh Salgaonkar , Vasant Hegde , Hari Bathini , =?UTF-8?Q?C=c3=a9dric_Le_Goater?= , David Gibson , Greg Kurz , Masahiro Yamada , Nicholas Piggin , Andrew Morton , David Hildenbrand , Oscar Salvador , Michal Hocko , Pavel Tatashin , Wei Yang , Qian Cai , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org, linux-mm@kvack.org References: <20191025044721.16617-1-alastair@au1.ibm.com> <20191025044721.16617-8-alastair@au1.ibm.com> From: Frederic Barrat Date: Thu, 7 Nov 2019 19:18:59 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1 MIME-Version: 1.0 In-Reply-To: <20191025044721.16617-8-alastair@au1.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-TM-AS-GCONF: 00 x-cbid: 19110718-0016-0000-0000-000002C1AD4F X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19110718-0017-0000-0000-000033233106 Message-Id: <11327e5f-bc88-620e-f119-495eb7d4b02f@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-11-07_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=772 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1910280000 definitions=main-1911070167 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Le 25/10/2019 =C3=A0 06:47, Alastair D'Silva a =C3=A9crit=C2=A0: > From: Alastair D'Silva >=20 > This patch retrieves the serial number of the card and makes it availab= le > to consumers of the ocxl driver via the ocxl_fn struct. >=20 > Signed-off-by: Alastair D'Silva > --- Acked-by: Frederic Barrat > drivers/misc/ocxl/config.c | 46 +++++++++++++++++++++++++++++++++++++= + > include/misc/ocxl.h | 1 + > 2 files changed, 47 insertions(+) >=20 > diff --git a/drivers/misc/ocxl/config.c b/drivers/misc/ocxl/config.c > index fb0c3b6f8312..a9203c309365 100644 > --- a/drivers/misc/ocxl/config.c > +++ b/drivers/misc/ocxl/config.c > @@ -71,6 +71,51 @@ static int find_dvsec_afu_ctrl(struct pci_dev *dev, = u8 afu_idx) > return 0; > } > =20 > +/** > + * Find a related PCI device (function 0) > + * @device: PCI device to match > + * > + * Returns a pointer to the related device, or null if not found > + */ > +static struct pci_dev *get_function_0(struct pci_dev *dev) > +{ > + unsigned int devfn =3D PCI_DEVFN(PCI_SLOT(dev->devfn), 0); // Look fo= r function 0 > + > + return pci_get_domain_bus_and_slot(pci_domain_nr(dev->bus), > + dev->bus->number, devfn); > +} > + > +static void read_serial(struct pci_dev *dev, struct ocxl_fn_config *fn= ) > +{ > + u32 low, high; > + int pos; > + > + pos =3D pci_find_ext_capability(dev, PCI_EXT_CAP_ID_DSN); > + if (pos) { > + pci_read_config_dword(dev, pos + 0x04, &low); > + pci_read_config_dword(dev, pos + 0x08, &high); > + > + fn->serial =3D low | ((u64)high) << 32; > + > + return; > + } > + > + if (PCI_FUNC(dev->devfn) !=3D 0) { > + struct pci_dev *related =3D get_function_0(dev); > + > + if (!related) { > + fn->serial =3D 0; > + return; > + } > + > + read_serial(related, fn); > + pci_dev_put(related); > + return; > + } > + > + fn->serial =3D 0; > +} > + > static void read_pasid(struct pci_dev *dev, struct ocxl_fn_config *fn= ) > { > u16 val; > @@ -208,6 +253,7 @@ int ocxl_config_read_function(struct pci_dev *dev, = struct ocxl_fn_config *fn) > int rc; > =20 > read_pasid(dev, fn); > + read_serial(dev, fn); > =20 > rc =3D read_dvsec_tl(dev, fn); > if (rc) { > diff --git a/include/misc/ocxl.h b/include/misc/ocxl.h > index 6f7c02f0d5e3..9843051c3c5b 100644 > --- a/include/misc/ocxl.h > +++ b/include/misc/ocxl.h > @@ -46,6 +46,7 @@ struct ocxl_fn_config { > int dvsec_afu_info_pos; /* offset of the AFU information DVSEC */ > s8 max_pasid_log; > s8 max_afu_index; > + u64 serial; > }; > =20 > enum ocxl_endian { >=20