From patchwork Tue Sep 15 18:22:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 260860 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=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 0D186C43461 for ; Tue, 15 Sep 2020 18:24:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AFBEA205F4 for ; Tue, 15 Sep 2020 18:24:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CTOr3ayY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727969AbgIOSYo (ORCPT ); Tue, 15 Sep 2020 14:24:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728033AbgIOSXb (ORCPT ); Tue, 15 Sep 2020 14:23:31 -0400 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40153C06178C for ; Tue, 15 Sep 2020 11:22:55 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id w1so4027641edr.3 for ; Tue, 15 Sep 2020 11:22:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=r4dmHhQhCwQ9a+IkrFWfHN7MHRZFD0JOIVYiWHLHOK4=; b=CTOr3ayYfuI3EuHshnimLdbGxz5vu1qtiHCbd5LyZGCSnXRC6hg0ZvuHe3scbuPt0D A+82vjnJxXZcNNa4lGwd8W67jaYZaBZZGIqsk3zfE0yeyUiKJ75GLw80FG2QcU4qSIzO 7DguK8i6qGytTb35sXF8AQl63wb9yqW/ns+r5wLDo1RnR8A1vbBtaC3xgepgvW34Co88 5801VCvNsawXCSLfuXLa7HiVsvBBCDU9UTM7EA0B66be3WU7ITJWgjFQ6HsxE4/G9Z2Y 8D5TM14vd5HulyfNA6ESLZPeNpBRrnOVmbyzcwTAi+ga1WKTfXlc/sduAKWCIikQtPIf cl3g== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=r4dmHhQhCwQ9a+IkrFWfHN7MHRZFD0JOIVYiWHLHOK4=; b=mb7Wg+J1gfrTsZwC8qKTN+ewug8gZi13NBWQWsfGMlinlAtbfc94aXFe7NAMf6WdjL QHijzxP3MbkPYaCophdwa7MRGWyiB4VJOSecKIay3jY4E+fw+ywcd6uOX4qGDlfhdBtO NbxI6aFOFBNlYShs8UXcpYFD1rm9lq3PB2sa+NxBvXCyqcRXl+rdgfvvZYd2NNhVtRe3 /Moj4adXQFwRhFnY538Ivuuds4WNW3GeeKkTHqBkfLzDf+UA9qXRo4RO2RIvC986R8jm sBpqfpZpzneVMJYnpuHOgoxVjgzY6Cep5jcWUT2UJiBULXydl5iO8OtMX4+eKEjOxEgT CRuQ== X-Gm-Message-State: AOAM532VH+WR2WIg/pZc+GQekyCiaSqOXCFsOhsEUicvAieQhr9NtYSX 0N5B+Ls+QpbjZA3F7TODYxY= X-Google-Smtp-Source: ABdhPJw2U/LWrJ7jZm+UwPg4p35h7oqE92psnpt/DDqGLrKm5PHGbEga99IviIfI9H+YpCEOVpjJsg== X-Received: by 2002:aa7:d29a:: with SMTP id w26mr23467938edq.106.1600194173992; Tue, 15 Sep 2020 11:22:53 -0700 (PDT) Received: from localhost.localdomain ([188.25.217.212]) by smtp.gmail.com with ESMTPSA id q11sm11860481eds.16.2020.09.15.11.22.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2020 11:22:53 -0700 (PDT) From: Vladimir Oltean To: davem@davemloft.net, netdev@vger.kernel.org Cc: yangbo.lu@nxp.com, xiaoliang.yang_1@nxp.com, UNGLinuxDriver@microchip.com, claudiu.manoil@nxp.com, alexandre.belloni@bootlin.com, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, kuba@kernel.org Subject: [PATCH net 4/7] net: mscc: ocelot: check for errors on memory allocation of ports Date: Tue, 15 Sep 2020 21:22:26 +0300 Message-Id: <20200915182229.69529-5-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200915182229.69529-1-olteanv@gmail.com> References: <20200915182229.69529-1-olteanv@gmail.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean Do not proceed probing if we couldn't allocate memory for the ports array, just error out. Signed-off-by: Vladimir Oltean --- drivers/net/ethernet/mscc/ocelot_vsc7514.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/ethernet/mscc/ocelot_vsc7514.c b/drivers/net/ethernet/mscc/ocelot_vsc7514.c index 65408bc994c4..99872f1b7460 100644 --- a/drivers/net/ethernet/mscc/ocelot_vsc7514.c +++ b/drivers/net/ethernet/mscc/ocelot_vsc7514.c @@ -993,6 +993,8 @@ static int mscc_ocelot_probe(struct platform_device *pdev) ocelot->ports = devm_kcalloc(&pdev->dev, ocelot->num_phys_ports, sizeof(struct ocelot_port *), GFP_KERNEL); + if (!ocelot->ports) + return -ENOMEM; ocelot->vcap_is2_keys = vsc7514_vcap_is2_keys; ocelot->vcap_is2_actions = vsc7514_vcap_is2_actions; From patchwork Tue Sep 15 18:22:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 260859 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=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 0F9C2C43461 for ; Tue, 15 Sep 2020 18:25:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B5DBB2064B for ; Tue, 15 Sep 2020 18:25:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KvgTpdc8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728034AbgIOSZU (ORCPT ); Tue, 15 Sep 2020 14:25:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727912AbgIOSXu (ORCPT ); Tue, 15 Sep 2020 14:23:50 -0400 Received: from mail-ej1-x643.google.com (mail-ej1-x643.google.com [IPv6:2a00:1450:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 768AAC061797 for ; Tue, 15 Sep 2020 11:22:56 -0700 (PDT) Received: by mail-ej1-x643.google.com with SMTP id r7so6408397ejs.11 for ; Tue, 15 Sep 2020 11:22:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eNLxoGrCqT/1fi4nginRZ1whGh9cbvf5JgI3Wa5mNBk=; b=KvgTpdc8Zu/zZgIylosbkjNw8urx2XxjO6X+Lcd/Z0lcjxTfdMREXDFjh2LIEdSk5m SwD9T8jTPG7TsPIixwfwtdvXBiA811g9yPbh7XV4TaE24BxP2mAUiQc8VW/c8/A7RsQb nP83l16RuLKh1xfRXEUQnowgTU3m541U1dpgh6RGp+/ZwWdR5iNx9oeHkzAbpRuESI3n fxWYZtwSy5876ISz9trWNh+pdS8W8bsXrxvZEEfmJi6HbmAP7wg/9Oy2DoKqFDB9/Mbc hX1BYS8pIM4n+fClzVNr+UhjMif+02WqWXBB9S+o9o6a6tMLbBdCWJjKr/txgvif92Xz EMNQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=eNLxoGrCqT/1fi4nginRZ1whGh9cbvf5JgI3Wa5mNBk=; b=E+gFsACW5rFeyJQCfe51bRD4dPiViFoQ0tLYqKkiT8ue/QrmXDmvZKGWKP66Ifuz/c GZBL0u657/ivEkY1PfoK7R1VPgDThFVY1Ly6HblOOsjpekUgo1+2JkDXUPibqfMa5Nb1 yzSSW9O0k3U+kLQuysfIF/E6cIfjtHxbTKgWkvgHBoU8uTsRS73p1y3yWgT/+iqgRZ/l QepdqJVTMqrw4Jw+UL0HFgzwxVswwfuONBciM+i0BQD1d41paCoKVZPE+Ko9Nq2ZhKFv tJ8S3+WJ5PocaPceoV5pjnhZBI515I0sPW/p7c0LspsSHBko4thE42Oq32uDcPifV9wc eC2A== X-Gm-Message-State: AOAM531D08vL0jfwfpjuwMujstdtya0XrIXPvLYhwbV62sv89Q8VmlF6 HkGMNtCqXeSZP5ei2T8bRUM= X-Google-Smtp-Source: ABdhPJw5uxe+zFsfiDGyxWqRGvIg1QlPh1f6ThffFrLTlRsmiPNzfS5gPSCkjmpkrXdWAg8WLD1zSA== X-Received: by 2002:a17:906:6993:: with SMTP id i19mr20718634ejr.26.1600194175159; Tue, 15 Sep 2020 11:22:55 -0700 (PDT) Received: from localhost.localdomain ([188.25.217.212]) by smtp.gmail.com with ESMTPSA id q11sm11860481eds.16.2020.09.15.11.22.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2020 11:22:54 -0700 (PDT) From: Vladimir Oltean To: davem@davemloft.net, netdev@vger.kernel.org Cc: yangbo.lu@nxp.com, xiaoliang.yang_1@nxp.com, UNGLinuxDriver@microchip.com, claudiu.manoil@nxp.com, alexandre.belloni@bootlin.com, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, kuba@kernel.org Subject: [PATCH net 5/7] net: mscc: ocelot: error checking when calling ocelot_init() Date: Tue, 15 Sep 2020 21:22:27 +0300 Message-Id: <20200915182229.69529-6-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200915182229.69529-1-olteanv@gmail.com> References: <20200915182229.69529-1-olteanv@gmail.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean ocelot_init() allocates memory, resets the switch and polls for a status register, things which can fail. Stop probing the driver in that case, and propagate the error result. Signed-off-by: Vladimir Oltean --- drivers/net/dsa/ocelot/felix.c | 5 ++++- drivers/net/ethernet/mscc/ocelot_vsc7514.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/ocelot/felix.c b/drivers/net/dsa/ocelot/felix.c index a1e1d3824110..f7b43f8d56ed 100644 --- a/drivers/net/dsa/ocelot/felix.c +++ b/drivers/net/dsa/ocelot/felix.c @@ -571,7 +571,10 @@ static int felix_setup(struct dsa_switch *ds) if (err) return err; - ocelot_init(ocelot); + err = ocelot_init(ocelot); + if (err) + return err; + if (ocelot->ptp) { err = ocelot_init_timestamp(ocelot, &ocelot_ptp_clock_info); if (err) { diff --git a/drivers/net/ethernet/mscc/ocelot_vsc7514.c b/drivers/net/ethernet/mscc/ocelot_vsc7514.c index 99872f1b7460..91a915d0693f 100644 --- a/drivers/net/ethernet/mscc/ocelot_vsc7514.c +++ b/drivers/net/ethernet/mscc/ocelot_vsc7514.c @@ -1000,7 +1000,10 @@ static int mscc_ocelot_probe(struct platform_device *pdev) ocelot->vcap_is2_actions = vsc7514_vcap_is2_actions; ocelot->vcap = vsc7514_vcap_props; - ocelot_init(ocelot); + err = ocelot_init(ocelot); + if (err) + return err; + if (ocelot->ptp) { err = ocelot_init_timestamp(ocelot, &ocelot_ptp_clock_info); if (err) { From patchwork Tue Sep 15 18:22:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 260858 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=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 A071EC433E2 for ; Tue, 15 Sep 2020 18:27:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6215721D91 for ; Tue, 15 Sep 2020 18:27:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NLbuQI3F" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728000AbgIOS1j (ORCPT ); Tue, 15 Sep 2020 14:27:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727876AbgIOSXu (ORCPT ); Tue, 15 Sep 2020 14:23:50 -0400 Received: from mail-ej1-x644.google.com (mail-ej1-x644.google.com [IPv6:2a00:1450:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD214C061351 for ; Tue, 15 Sep 2020 11:22:57 -0700 (PDT) Received: by mail-ej1-x644.google.com with SMTP id p9so6429939ejf.6 for ; Tue, 15 Sep 2020 11:22:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EA6Qr6VFjelBD+DslpRzCeBdHelO+UiXDpVl6fplfpY=; b=NLbuQI3F9DhXnwxYJfuW4GPQurAEgmtfulegGrHTJTDrWOMKfM9lt5662tb/7oEtTT /U11eKzNxpUvWVhBdiuCA8Shp8iCxZZPC+PfF47pixKYkhJTZBEj61AXgape6h+WM3Gz vI3qxVMu64fy3avbbX61h+m3yfD+nFHsgUThRMjAYf5f1YsVQZgkrtUNs6NeWRPx3lIN fCSTncOeIbtGhkJc7douM/GKMTIfurhP6L96c7JHZWR9r5tDB+afUBZHbx3JI3ez0vVQ uE1Z1NAFPneTNrs8QkneYex2tM4atAqMkiInp2HQDVjBxlFS2OeHctUYTRg6K/sApUWA aMTQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=EA6Qr6VFjelBD+DslpRzCeBdHelO+UiXDpVl6fplfpY=; b=ulcO8XEus4+JubTqMuW+mMeSKArnhxoax5lg+33zhbFr0084pNIRTzic5Hni5yoS+1 xLG3kZr4MF4oeSeHn6SpxXHMWNHsTuAl4tO8txLcXW77h/Q+USY1yOp/yzluOA9iG4HV NROLig/2R5TDvGOOKfZSpQnYrPyRzA5tS4f3eAdjSM5bHO3jpNX9J7CM+Ba0f/UK4kCp uF3/gMS7ANLwf6hLUQhVjiwQvpmVknyopfKvsB7ibBac42evApXCgDT+Vh6+/5klCP0b BUsJ8p1dcC28ihU/vSmaFaRdywIXxHmR1fx3pnhMs9sZRdqDuwx012So6h6fHothFAs6 TVxg== X-Gm-Message-State: AOAM533FeTcMZzbkWFFKsGKYvG83KTO4S6UcFNYYAisn/Tr0MJYokUqP 0jnH+9ID5D1iCZ2n3eTtT5A= X-Google-Smtp-Source: ABdhPJx+HaFITNyVPcN2BHBpheuukpJVbW2GOkJrm0KcGJW8i0rEAjTcR2QVu4IUnjQn+Eypt/rJyA== X-Received: by 2002:a17:906:dbf5:: with SMTP id yd21mr21051863ejb.521.1600194176351; Tue, 15 Sep 2020 11:22:56 -0700 (PDT) Received: from localhost.localdomain ([188.25.217.212]) by smtp.gmail.com with ESMTPSA id q11sm11860481eds.16.2020.09.15.11.22.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2020 11:22:55 -0700 (PDT) From: Vladimir Oltean To: davem@davemloft.net, netdev@vger.kernel.org Cc: yangbo.lu@nxp.com, xiaoliang.yang_1@nxp.com, UNGLinuxDriver@microchip.com, claudiu.manoil@nxp.com, alexandre.belloni@bootlin.com, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, kuba@kernel.org Subject: [PATCH net 6/7] net: mscc: ocelot: refactor ports parsing code into a dedicated function Date: Tue, 15 Sep 2020 21:22:28 +0300 Message-Id: <20200915182229.69529-7-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200915182229.69529-1-olteanv@gmail.com> References: <20200915182229.69529-1-olteanv@gmail.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean mscc_ocelot_probe() is already pretty large and hard to follow. So move the code for parsing ports in a separate function. This makes it easier for the next patch to just call mscc_ocelot_release_ports from the error path of mscc_ocelot_init_ports. Signed-off-by: Vladimir Oltean --- drivers/net/ethernet/mscc/ocelot_vsc7514.c | 223 +++++++++++---------- 1 file changed, 118 insertions(+), 105 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot_vsc7514.c b/drivers/net/ethernet/mscc/ocelot_vsc7514.c index 91a915d0693f..851e79e11aed 100644 --- a/drivers/net/ethernet/mscc/ocelot_vsc7514.c +++ b/drivers/net/ethernet/mscc/ocelot_vsc7514.c @@ -896,123 +896,26 @@ static struct ptp_clock_info ocelot_ptp_clock_info = { .enable = ocelot_ptp_enable, }; -static int mscc_ocelot_probe(struct platform_device *pdev) +static int mscc_ocelot_init_ports(struct platform_device *pdev) { - struct device_node *np = pdev->dev.of_node; + struct ocelot *ocelot = platform_get_drvdata(pdev); + struct device_node *np = ocelot->dev->of_node; struct device_node *ports, *portnp; - int err, irq_xtr, irq_ptp_rdy; - struct ocelot *ocelot; - struct regmap *hsio; - unsigned int i; - - struct { - enum ocelot_target id; - char *name; - u8 optional:1; - } io_target[] = { - { SYS, "sys" }, - { REW, "rew" }, - { QSYS, "qsys" }, - { ANA, "ana" }, - { QS, "qs" }, - { S2, "s2" }, - { PTP, "ptp", 1 }, - }; - - if (!np && !pdev->dev.platform_data) - return -ENODEV; - - ocelot = devm_kzalloc(&pdev->dev, sizeof(*ocelot), GFP_KERNEL); - if (!ocelot) - return -ENOMEM; - - platform_set_drvdata(pdev, ocelot); - ocelot->dev = &pdev->dev; - - for (i = 0; i < ARRAY_SIZE(io_target); i++) { - struct regmap *target; - struct resource *res; - - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, - io_target[i].name); - - target = ocelot_regmap_init(ocelot, res); - if (IS_ERR(target)) { - if (io_target[i].optional) { - ocelot->targets[io_target[i].id] = NULL; - continue; - } - return PTR_ERR(target); - } - - ocelot->targets[io_target[i].id] = target; - } - - hsio = syscon_regmap_lookup_by_compatible("mscc,ocelot-hsio"); - if (IS_ERR(hsio)) { - dev_err(&pdev->dev, "missing hsio syscon\n"); - return PTR_ERR(hsio); - } - - ocelot->targets[HSIO] = hsio; - - err = ocelot_chip_init(ocelot, &ocelot_ops); - if (err) - return err; - - irq_xtr = platform_get_irq_byname(pdev, "xtr"); - if (irq_xtr < 0) - return -ENODEV; - - err = devm_request_threaded_irq(&pdev->dev, irq_xtr, NULL, - ocelot_xtr_irq_handler, IRQF_ONESHOT, - "frame extraction", ocelot); - if (err) - return err; - - irq_ptp_rdy = platform_get_irq_byname(pdev, "ptp_rdy"); - if (irq_ptp_rdy > 0 && ocelot->targets[PTP]) { - err = devm_request_threaded_irq(&pdev->dev, irq_ptp_rdy, NULL, - ocelot_ptp_rdy_irq_handler, - IRQF_ONESHOT, "ptp ready", - ocelot); - if (err) - return err; - - /* Both the PTP interrupt and the PTP bank are available */ - ocelot->ptp = 1; - } + int err; ports = of_get_child_by_name(np, "ethernet-ports"); if (!ports) { - dev_err(&pdev->dev, "no ethernet-ports child node found\n"); + dev_err(ocelot->dev, "no ethernet-ports child node found\n"); return -ENODEV; } ocelot->num_phys_ports = of_get_child_count(ports); - ocelot->ports = devm_kcalloc(&pdev->dev, ocelot->num_phys_ports, + ocelot->ports = devm_kcalloc(ocelot->dev, ocelot->num_phys_ports, sizeof(struct ocelot_port *), GFP_KERNEL); if (!ocelot->ports) return -ENOMEM; - ocelot->vcap_is2_keys = vsc7514_vcap_is2_keys; - ocelot->vcap_is2_actions = vsc7514_vcap_is2_actions; - ocelot->vcap = vsc7514_vcap_props; - - err = ocelot_init(ocelot); - if (err) - return err; - - if (ocelot->ptp) { - err = ocelot_init_timestamp(ocelot, &ocelot_ptp_clock_info); - if (err) { - dev_err(ocelot->dev, - "Timestamp initialization failed\n"); - ocelot->ptp = 0; - } - } - /* No NPI port */ ocelot_configure_cpu(ocelot, -1, OCELOT_TAG_PREFIX_NONE, OCELOT_TAG_PREFIX_NONE); @@ -1103,14 +1006,124 @@ static int mscc_ocelot_probe(struct platform_device *pdev) priv->serdes = serdes; } +out_put_ports: + of_node_put(ports); + return err; +} + +static int mscc_ocelot_probe(struct platform_device *pdev) +{ + struct device_node *np = pdev->dev.of_node; + int err, irq_xtr, irq_ptp_rdy; + struct ocelot *ocelot; + struct regmap *hsio; + unsigned int i; + + struct { + enum ocelot_target id; + char *name; + u8 optional:1; + } io_target[] = { + { SYS, "sys" }, + { REW, "rew" }, + { QSYS, "qsys" }, + { ANA, "ana" }, + { QS, "qs" }, + { S2, "s2" }, + { PTP, "ptp", 1 }, + }; + + if (!np && !pdev->dev.platform_data) + return -ENODEV; + + ocelot = devm_kzalloc(&pdev->dev, sizeof(*ocelot), GFP_KERNEL); + if (!ocelot) + return -ENOMEM; + + platform_set_drvdata(pdev, ocelot); + ocelot->dev = &pdev->dev; + + for (i = 0; i < ARRAY_SIZE(io_target); i++) { + struct regmap *target; + struct resource *res; + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, + io_target[i].name); + + target = ocelot_regmap_init(ocelot, res); + if (IS_ERR(target)) { + if (io_target[i].optional) { + ocelot->targets[io_target[i].id] = NULL; + continue; + } + return PTR_ERR(target); + } + + ocelot->targets[io_target[i].id] = target; + } + + hsio = syscon_regmap_lookup_by_compatible("mscc,ocelot-hsio"); + if (IS_ERR(hsio)) { + dev_err(&pdev->dev, "missing hsio syscon\n"); + return PTR_ERR(hsio); + } + + ocelot->targets[HSIO] = hsio; + + err = ocelot_chip_init(ocelot, &ocelot_ops); + if (err) + return err; + + irq_xtr = platform_get_irq_byname(pdev, "xtr"); + if (irq_xtr < 0) + return -ENODEV; + + err = devm_request_threaded_irq(&pdev->dev, irq_xtr, NULL, + ocelot_xtr_irq_handler, IRQF_ONESHOT, + "frame extraction", ocelot); + if (err) + return err; + + irq_ptp_rdy = platform_get_irq_byname(pdev, "ptp_rdy"); + if (irq_ptp_rdy > 0 && ocelot->targets[PTP]) { + err = devm_request_threaded_irq(&pdev->dev, irq_ptp_rdy, NULL, + ocelot_ptp_rdy_irq_handler, + IRQF_ONESHOT, "ptp ready", + ocelot); + if (err) + return err; + + /* Both the PTP interrupt and the PTP bank are available */ + ocelot->ptp = 1; + } + + ocelot->vcap_is2_keys = vsc7514_vcap_is2_keys; + ocelot->vcap_is2_actions = vsc7514_vcap_is2_actions; + ocelot->vcap = vsc7514_vcap_props; + + err = ocelot_init(ocelot); + if (err) + return err; + + err = mscc_ocelot_init_ports(pdev); + if (err) + return err; + + if (ocelot->ptp) { + err = ocelot_init_timestamp(ocelot, &ocelot_ptp_clock_info); + if (err) { + dev_err(ocelot->dev, + "Timestamp initialization failed\n"); + ocelot->ptp = 0; + } + } + register_netdevice_notifier(&ocelot_netdevice_nb); register_switchdev_notifier(&ocelot_switchdev_nb); register_switchdev_blocking_notifier(&ocelot_switchdev_blocking_nb); dev_info(&pdev->dev, "Ocelot switch probed\n"); -out_put_ports: - of_node_put(ports); return err; }