Return-Path: Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=eajames@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 45JS4j4NZfzDqLH for ; Wed, 5 Jun 2019 08:57:56 +1000 (AEST) Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x54MveFn059840 for ; Tue, 4 Jun 2019 18:57:52 -0400 Received: from e11.ny.us.ibm.com (e11.ny.us.ibm.com [129.33.205.201]) by mx0a-001b2d01.pphosted.com with ESMTP id 2sww65jrtv-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 04 Jun 2019 18:57:51 -0400 Received: from localhost by e11.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 4 Jun 2019 23:57:39 +0100 Received: from b01cxnp22035.gho.pok.ibm.com (9.57.198.25) by e11.ny.us.ibm.com (146.89.104.198) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 4 Jun 2019 23:57:36 +0100 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x54MvZhZ43909164 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 4 Jun 2019 22:57:35 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 88365112062; Tue, 4 Jun 2019 22:57:35 +0000 (GMT) Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 36877112066; Tue, 4 Jun 2019 22:57:35 +0000 (GMT) Received: from [9.80.207.240] (unknown [9.80.207.240]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP; Tue, 4 Jun 2019 22:57:35 +0000 (GMT) Subject: Re: [PATCH] i2c: fsi: Create busses for all ports To: Oliver Cc: OpenBMC Maillist , linux-i2c@vger.kernel.org, Eddie James References: <20190603055714.7203-1-oohall@gmail.com> From: Eddie James Date: Tue, 4 Jun 2019 17:57:34 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-TM-AS-GCONF: 00 x-cbid: 19060422-2213-0000-0000-0000039A2072 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00011216; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000286; SDB=6.01213312; UDB=6.00637692; IPR=6.00994378; MB=3.00027185; MTD=3.00000008; XFM=3.00000015; UTC=2019-06-04 22:57:37 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19060422-2214-0000-0000-00005EB5FF43 Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-06-04_15:, , 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=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906040145 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Jun 2019 22:57:58 -0000 On 6/4/19 1:14 AM, Oliver wrote: > On Tue, Jun 4, 2019 at 12:15 AM Eddie James wrote: >> >> On 6/3/19 12:57 AM, Oliver O'Halloran wrote: >>> Currently we only create an I2C bus for the ports listed in the >>> device-tree for that master. There's no real reason for this since >>> we can discover the number of ports the master supports by looking >>> at the port_max field of the status register. >>> >>> This patch re-works the bus add logic so that we always create buses >>> for each port, unless the bus is marked as unavailable in the DT. This >>> is useful since it ensures that all the buses provided by the CFAM I2C >>> master are accessible to debug tools. >>> >>> Cc: Eddie James >>> Signed-off-by: Oliver O'Halloran >>> --- >>> drivers/i2c/busses/i2c-fsi.c | 30 +++++++++++++++++++++++++----- >>> 1 file changed, 25 insertions(+), 5 deletions(-) >>> >>> diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c >>> index 1e2be2219a60..59a76c6e31ad 100644 >>> --- a/drivers/i2c/busses/i2c-fsi.c >>> +++ b/drivers/i2c/busses/i2c-fsi.c >>> @@ -658,13 +658,27 @@ static const struct i2c_algorithm fsi_i2c_algorithm = { >>> .functionality = fsi_i2c_functionality, >>> }; >>> >>> +static device_node *fsi_i2c_find_port_of_node(struct device_node *master, >>> + int port) > Turns out I had a pile of compile fixes staged but not committed so > this patch is totally broken. Oops. > >>> +{ >>> + struct device_node *np; >>> + >>> + for_each_child_of_node(fsi, np) { >>> + rc = of_property_read_u32(np, "reg", &port_no); >>> + if (!rc && port_no == port) >>> + return np; >>> + } >>> + >>> + return NULL; >>> +} >>> + >>> static int fsi_i2c_probe(struct device *dev) >>> { >>> struct fsi_i2c_master *i2c; >>> struct fsi_i2c_port *port; >>> struct device_node *np; >>> + u32 port_no, ports, stat; >>> int rc; >>> - u32 port_no; >>> >>> i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL); >>> if (!i2c) >>> @@ -678,10 +692,16 @@ static int fsi_i2c_probe(struct device *dev) >>> if (rc) >>> return rc; >>> >>> - /* Add adapter for each i2c port of the master. */ >>> - for_each_available_child_of_node(dev->of_node, np) { >>> - rc = of_property_read_u32(np, "reg", &port_no); >>> - if (rc || port_no > USHRT_MAX) >>> + rc = fsi_i2c_read_reg(i2c->fsi, I2C_FSI_STAT, &state); >>> + if (rc) >>> + return rc; >>> + >>> + ports = FIELD_GET(I2C_STAT_MAX_PORT, stat); >>> + dev_dbg(dev, "I2C master has %d ports\n", ports); >> >> Thanks for the patch Oliver. This looks great except some older CFAM >> types don't report the max port number, in which case this would not >> probe up any ports. So we probably need a fallback to dts if the max >> ports is 0. > Hmm, The oldest CFAM spec I could find was v1.2 which is from the p6 > era and it includes the MAX_PORT field. When I was checking the spec I > noticed that I mis-interpreted the meaning of MAX_PORT. It's actually > the largest value you can write into the port field of the mode > register rather than the number of ports the master supports. So zero > is a valid value for MAX_PORT that you would see if the master only > has one port. Yep, now that I look at the specs too, that is correct. > > Do you know if the old masters only had one port? If not, do you know > what version (from the ext status reg) of the master doesn't support > the max_port field? I used to have some more up-to-date specs but I can't seem to find them... I think I see what's going on. Some versions of the CFAM have the max port, or "upper threshold for ports" at bits 16-19, while others have that information at 9-15 or 12-15... I'm not sure we can reliably determine where/what that number will be. I'm open to suggestions! Thanks, Eddie > > >> Thanks, >> >> Eddie >> >> >>> + >>> + for (port_no = 0; port_no < ports; port_no++) { >>> + np = fsi_i2c_find_port_of_node(dev.of_node, port_no); >>> + if (np && !of_device_is_available(np)) >>> continue; >>> >>> port = kzalloc(sizeof(*port), GFP_KERNEL);