From patchwork Thu Sep 5 00:36:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13791571 Received: from pv50p00im-zteg10011501.me.com (pv50p00im-zteg10011501.me.com [17.58.6.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E23DDF59 for ; Thu, 5 Sep 2024 00:36:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725496620; cv=none; b=FNXVwbt3wymX+BLsymlU/KGZ6hNpw9BF+nPuhxjXDukujM5PbfGDpECjyv9YwxgSKhLQPTtR9irwh2Gh+GNrW31sHLOcvZ7Jn+uZZ6IcO1wtLXb4SLxZDEQxRjgeSt4WLKc3RX+ngO+4jvC6lLRjoXi1IzGfb+y7bmq+U1pUWIc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725496620; c=relaxed/simple; bh=kYetPqvMLLx5+dJ9+boXwW1Wp7FG1sXnbJAiEqLwfio=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iED0owz5eWk83UnD2glvVsQcTGBQTcndJJRADoHtwNaRrfymCdobXQON8u+WKg0qQcal8Sl23FESUAbL/+nWUdlZ/Eizi5sZ9h8LC42TWIzc/Pn4ExXb8vN9fKWYu3daf7HyWUceR3D7Rl1Z1x1xWrNtnOe+9URctgTG3Ej3V0w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com; spf=pass smtp.mailfrom=icloud.com; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b=Fj8J7iJB; arc=none smtp.client-ip=17.58.6.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=icloud.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b="Fj8J7iJB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1725496618; bh=dwnwxkgqOlaxufbIkvbF6eAIvdX11aqbDyvutbqgdbI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; b=Fj8J7iJBZ/U9WYskP0XgZjPWicKKAaL6zZa7OaC5GQdOl1kBb2ExmjEx7TL/jQvYS /HWUlcx7eCAnNM1yBskad2dYH43wOAtEhgBs8nQ/kP+yvIrsQKTEE4i+jTIcVkA1Rf BUVW9RPbWTUMRiwYsjhxqnTb3jJRWvTUy27+gJd0tgPAr100K3LZ3Z/k8UKUxMKk98 enJ8SALc2g2NhasxSrLqh3vIwtMJJLB/HT9aHoEcfrCjkS+i5aPfRpiKqlX0knSJC2 NsWOuFGqKysVfpAk8G6vcQ4xB/D3f4ix2WuXj5P9wqUFubhGpjYTpLUeb9mSDbLz+L W0Drg14PcYeAg== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10011501.me.com (Postfix) with ESMTPSA id 1C7004A0351; Thu, 5 Sep 2024 00:36:50 +0000 (UTC) From: Zijun Hu Date: Thu, 05 Sep 2024 08:36:09 +0800 Subject: [PATCH v4 1/2] cxl/region: Find free cxl decoder by device_for_each_child() Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240905-const_dfc_prepare-v4-1-4180e1d5a244@quicinc.com> References: <20240905-const_dfc_prepare-v4-0-4180e1d5a244@quicinc.com> In-Reply-To: <20240905-const_dfc_prepare-v4-0-4180e1d5a244@quicinc.com> To: Davidlohr Bueso , Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Timur Tabi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Greg Kroah-Hartman Cc: Zijun Hu , linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.1 X-Proofpoint-ORIG-GUID: _rGsSFzOa5Bxjs8a0EDp2a0yhqgVB74p X-Proofpoint-GUID: _rGsSFzOa5Bxjs8a0EDp2a0yhqgVB74p X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-04_22,2024-09-04_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 bulkscore=0 mlxlogscore=999 spamscore=0 phishscore=0 suspectscore=0 malwarescore=0 adultscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2409050002 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu To prepare for constifying the following old driver core API: struct device *device_find_child(struct device *dev, void *data, int (*match)(struct device *dev, void *data)); to new: struct device *device_find_child(struct device *dev, const void *data, int (*match)(struct device *dev, const void *data)); The new API does not allow its match function (*match)() to modify caller's match data @*data, but match_free_decoder() as the old API's match function indeed modifies relevant match data, so it is not suitable for the new API any more, solved by using device_for_each_child() to implement relevant finding free cxl decoder function. By the way, this commit does not change any existing logic. Suggested-by: Ira Weiny Signed-off-by: Zijun Hu --- drivers/cxl/core/region.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 21ad5f242875..c2068e90bf2f 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -794,10 +794,15 @@ static size_t show_targetN(struct cxl_region *cxlr, char *buf, int pos) return rc; } +struct cxld_match_data { + int id; + struct device *target_device; +}; + static int match_free_decoder(struct device *dev, void *data) { + struct cxld_match_data *match_data = data; struct cxl_decoder *cxld; - int *id = data; if (!is_switch_decoder(dev)) return 0; @@ -805,17 +810,31 @@ static int match_free_decoder(struct device *dev, void *data) cxld = to_cxl_decoder(dev); /* enforce ordered allocation */ - if (cxld->id != *id) + if (cxld->id != match_data->id) return 0; - if (!cxld->region) + if (!cxld->region) { + match_data->target_device = get_device(dev); return 1; + } - (*id)++; + match_data->id++; return 0; } +/* NOTE: need to drop the reference with put_device() after use. */ +static struct device *find_free_decoder(struct device *parent) +{ + struct cxld_match_data match_data = { + .id = 0, + .target_device = NULL, + }; + + device_for_each_child(parent, &match_data, match_free_decoder); + return match_data.target_device; +} + static int match_auto_decoder(struct device *dev, void *data) { struct cxl_region_params *p = data; @@ -840,7 +859,6 @@ cxl_region_find_decoder(struct cxl_port *port, struct cxl_region *cxlr) { struct device *dev; - int id = 0; if (port == cxled_to_port(cxled)) return &cxled->cxld; @@ -849,7 +867,7 @@ cxl_region_find_decoder(struct cxl_port *port, dev = device_find_child(&port->dev, &cxlr->params, match_auto_decoder); else - dev = device_find_child(&port->dev, &id, match_free_decoder); + dev = find_free_decoder(&port->dev); if (!dev) return NULL; /* From patchwork Thu Sep 5 00:36:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13791572 X-Patchwork-Delegate: kuba@kernel.org Received: from pv50p00im-zteg10011501.me.com (pv50p00im-zteg10011501.me.com [17.58.6.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E93EA23CE for ; Thu, 5 Sep 2024 00:37:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725496630; cv=none; b=lLeYEKV4R2lU5USyFyY9hygLDK3BOMqgOhcDByVKlpduqbigWCvgMQ3lz9No2AQOQxgDHCf8kAlyAdgc6BZkx3oC5kRaebX/sSMfNLpJ9ehNDTV/kOz5w6BhLx54HewFQwB5qfnetl+isPbKPMOkxkLMM1MGbFykviWhG6ejCyM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725496630; c=relaxed/simple; bh=drjG4ZOWXJdI+ivlJh21hmoDtwnILe4lYsXLEA47HkY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PjS225u01Sy29gq5t0i7lS3MeqJwxAELmwAA2eQJGgeBws3wHTaG3Q6JYy/ADvnv8m5GpeIz6ZREvklzsnLpKPVOBN16J3QAlhYIadtKSrOA54j+ngw52+DetrC84NS7wVufdYM7tMkYg586+yALssqWmEAtN1VGkDvQPOapFJE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com; spf=pass smtp.mailfrom=icloud.com; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b=Ubtsjbr5; arc=none smtp.client-ip=17.58.6.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=icloud.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b="Ubtsjbr5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1725496628; bh=USB2vfc0jyMwYalYSpIdv6871aXzY1LF0xxOVZ5PeKw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; b=Ubtsjbr5bH+GbqvBLG23EcbIvl1jCr2cZEEd7blJwLnsbgoFwtPgq+vW2xWYqvrfb R+MQ4vl+J7Vz8EI0KoMukz1o+YewelzjUu4yzB4IciPB3YlBAobSeOIi1TT6bKeScJ NE/AIRnUpsejCHmkm6ievvmIowKVs+tThmRTWtSwnFOZVY0EQ6d4u2ND5LFQLo5N1d wQVrkG3M818mvseClX9VrZRnFhxbw9X3G+tK5kd4xeW88xlWqCNs5nmOdej6QY2Qq5 uqCDrNJ7Go1mNNhkVkHwdrJVN42kjCkmmxeqVXFITAXNTyWwbPxAiazZwogVwvAgS2 0bhmF8hMmkLSw== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10011501.me.com (Postfix) with ESMTPSA id 8CB104A017B; Thu, 5 Sep 2024 00:36:59 +0000 (UTC) From: Zijun Hu Date: Thu, 05 Sep 2024 08:36:10 +0800 Subject: [PATCH v4 2/2] net: qcom/emac: Find sgmii_ops by device_for_each_child() Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240905-const_dfc_prepare-v4-2-4180e1d5a244@quicinc.com> References: <20240905-const_dfc_prepare-v4-0-4180e1d5a244@quicinc.com> In-Reply-To: <20240905-const_dfc_prepare-v4-0-4180e1d5a244@quicinc.com> To: Davidlohr Bueso , Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Timur Tabi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Greg Kroah-Hartman Cc: Zijun Hu , linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.1 X-Proofpoint-ORIG-GUID: LdsecNXrHLlaiqKWlirkO2_BwraVm0vJ X-Proofpoint-GUID: LdsecNXrHLlaiqKWlirkO2_BwraVm0vJ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-04_22,2024-09-04_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 bulkscore=0 mlxlogscore=999 spamscore=0 phishscore=0 suspectscore=0 malwarescore=0 adultscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2409050002 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 X-Patchwork-Delegate: kuba@kernel.org From: Zijun Hu To prepare for constifying the following old driver core API: struct device *device_find_child(struct device *dev, void *data, int (*match)(struct device *dev, void *data)); to new: struct device *device_find_child(struct device *dev, const void *data, int (*match)(struct device *dev, const void *data)); The new API does not allow its match function (*match)() to modify caller's match data @*data, but emac_sgmii_acpi_match() as the old API's match function indeed modifies relevant match data, so it is not suitable for the new API any more, solved by using device_for_each_child() to implement relevant finding sgmii_ops function. By the way, this commit does not change any existing logic. Signed-off-by: Zijun Hu --- drivers/net/ethernet/qualcomm/emac/emac-sgmii.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/qualcomm/emac/emac-sgmii.c b/drivers/net/ethernet/qualcomm/emac/emac-sgmii.c index e4bc18009d08..29392c63d115 100644 --- a/drivers/net/ethernet/qualcomm/emac/emac-sgmii.c +++ b/drivers/net/ethernet/qualcomm/emac/emac-sgmii.c @@ -293,6 +293,11 @@ static struct sgmii_ops qdf2400_ops = { }; #endif +struct emac_match_data { + struct sgmii_ops **sgmii_ops; + struct device *target_device; +}; + static int emac_sgmii_acpi_match(struct device *dev, void *data) { #ifdef CONFIG_ACPI @@ -303,7 +308,7 @@ static int emac_sgmii_acpi_match(struct device *dev, void *data) {} }; const struct acpi_device_id *id = acpi_match_device(match_table, dev); - struct sgmii_ops **ops = data; + struct emac_match_data *match_data = data; if (id) { acpi_handle handle = ACPI_HANDLE(dev); @@ -324,10 +329,12 @@ static int emac_sgmii_acpi_match(struct device *dev, void *data) switch (hrv) { case 1: - *ops = &qdf2432_ops; + *match_data->sgmii_ops = &qdf2432_ops; + match_data->target_device = get_device(dev); return 1; case 2: - *ops = &qdf2400_ops; + *match_data->sgmii_ops = &qdf2400_ops; + match_data->target_device = get_device(dev); return 1; } } @@ -356,10 +363,15 @@ int emac_sgmii_config(struct platform_device *pdev, struct emac_adapter *adpt) int ret; if (has_acpi_companion(&pdev->dev)) { + struct emac_match_data match_data = { + .sgmii_ops = &phy->sgmii_ops, + .target_device = NULL, + }; struct device *dev; - dev = device_find_child(&pdev->dev, &phy->sgmii_ops, - emac_sgmii_acpi_match); + device_for_each_child(&pdev->dev, &match_data, emac_sgmii_acpi_match); + /* Need to put_device(@dev) after use */ + dev = match_data.target_device; if (!dev) { dev_warn(&pdev->dev, "cannot find internal phy node\n");