From patchwork Wed Oct 7 09:48:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Manoil X-Patchwork-Id: 11820243 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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,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 282F3C4363C for ; Wed, 7 Oct 2020 09:48:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AA4F0212CC for ; Wed, 7 Oct 2020 09:48:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="sUox4t/r" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727569AbgJGJsn (ORCPT ); Wed, 7 Oct 2020 05:48:43 -0400 Received: from mail-eopbgr80048.outbound.protection.outlook.com ([40.107.8.48]:16619 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727514AbgJGJsm (ORCPT ); Wed, 7 Oct 2020 05:48:42 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NJXu4RgQYgfoW/7oLEI9bAF3mTtDRVfyvLx+wEvc3mZEeVgn+YkReDdzbTtzsauhFXNBYaL9yU2m8KoLAtJ4X8Q/EsqKEposaWV3V0fUivI7theALj/Cg/tQ37XgIbJZUJAbJoyqgMO5H/XJsgpJnIp8xzqr2nhzIRzyqiJ6RT28YFHFOuIQA4mqqa2txJH4KxXSCJjWgls4G8rUqXxxVzi04opAuXCSwRsQk3EZ/f/qrAXYKsQqs/5arAzs3PKyKUHlGdwd4BgE7/TF3o7K6NhcIA+G3CybiESlq398p3XK22JLkiUfXSn3/x8rBiW/59vPmuJ4ZrfkxaQtwTXLLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xGJCkhXIM1xsgJiHNUKhk/0xJLNnurhsgvKORSyN7vk=; b=QmjxRyx4QEUddzKV/F637kKH9V48Dvc3XHRGo903pZ/FDuC+/MmflqNwoiLoizcWjEraTpjKd1iVreCFFOb5sV0x4faOTpyxtSa30PTxPmloy6mbCV2RaGC8P8HngNV+5l3HUWmLaBc2u8af3zhpZmlxL79JwjTRY/fexoK1zg5lP4eBrFEQTSP/j/BiH9P5+n2txwwCa7yKyEsuwCtZS+is7ECoA+VGD464upFL33TXLKJRQ1KjEuIl1hwJwpgOYeW2HUiruX0YlysOnLyli+Z/0FEoK5sSllhQNK9Z3A3AEu3Jke2JnK/R2uZ278npiG5RaPrOu9fo4znzZaduQw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xGJCkhXIM1xsgJiHNUKhk/0xJLNnurhsgvKORSyN7vk=; b=sUox4t/r/rdJkIgbtIeg0hl2F1XZPSbFw4iSFV6x0FRONTk0hx+1Cyzj2xuRFxzYQrUIpCUsN8fpUie6qZ2z2cL2CC1yx5tWwYERPkymQRMwA6AJ8KupSfXm1ipXRqsVQtJBDpvL1eWk2pbPyWTje/ASv1djWKW0kn+pFUMMOwQ= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6754.eurprd04.prod.outlook.com (2603:10a6:208:170::28) by AM0PR04MB7169.eurprd04.prod.outlook.com (2603:10a6:208:19a::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3433.35; Wed, 7 Oct 2020 09:48:37 +0000 Received: from AM0PR04MB6754.eurprd04.prod.outlook.com ([fe80::21b9:fda3:719f:f37b]) by AM0PR04MB6754.eurprd04.prod.outlook.com ([fe80::21b9:fda3:719f:f37b%3]) with mapi id 15.20.3455.022; Wed, 7 Oct 2020 09:48:37 +0000 From: Claudiu Manoil To: netdev@vger.kernel.org Cc: "David S . Miller" , Jakub Kicinski , Russell King , Vladimir Oltean , Ioana Ciornei Subject: [PATCH net-next v2 1/4] enetc: Clean up MAC and link configuration Date: Wed, 7 Oct 2020 12:48:20 +0300 Message-Id: <20201007094823.6960-2-claudiu.manoil@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201007094823.6960-1-claudiu.manoil@nxp.com> References: <20201007094823.6960-1-claudiu.manoil@nxp.com> X-Originating-IP: [83.217.231.2] X-ClientProxiedBy: AM0PR03CA0013.eurprd03.prod.outlook.com (2603:10a6:208:14::26) To AM0PR04MB6754.eurprd04.prod.outlook.com (2603:10a6:208:170::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from lsv15141.swis.ro-buh01.nxp.com (83.217.231.2) by AM0PR03CA0013.eurprd03.prod.outlook.com (2603:10a6:208:14::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3455.21 via Frontend Transport; Wed, 7 Oct 2020 09:48:36 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 83a2d57e-18d4-4e2e-d2b1-08d86aa629e9 X-MS-TrafficTypeDiagnostic: AM0PR04MB7169: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2331; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /5Og+9fm/xsWcee+jY1QV43d4zaVqvATwduVrH6J8ItTAjVtZAdM9oFtay2thA5gz1L7ACH5KJUV6Ny6evXL8yV/jtDniChieMA0Q6ubdBFaELKpDqdK3Vx3gw5Wvuhc0zkACItVOohaFir0W5wJfLM5lO0oEc8Nf0pj+vA/BLAjU2FIKe6AHLbihOSi4Otp5sPwtja79uwi/E8wPB4hiEVq+zaeNnHm6QJLS28YqsnRpX1DhGStO2o7O17pBwlIVWYZiYBaSAQukEkFkx59NmKN3BPkc0AOzUTfDaduXIFtZ2GmCD0WGbHteIr5FhXibK4lqm+2bjvvKguXuV95lw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6754.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(366004)(376002)(136003)(346002)(39860400002)(478600001)(186003)(83380400001)(8936002)(26005)(6486002)(16526019)(6916009)(44832011)(36756003)(8676002)(86362001)(2906002)(316002)(1076003)(5660300002)(6666004)(4326008)(54906003)(66556008)(66476007)(66946007)(52116002)(2616005)(956004)(7696005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Kfe5zFqMx6k7rrZzBJczGnWW53GTiAibL+VvFpPmJDKk5LWD7F/WBkhtuqLJ5oqdIvyqP2hRDOAv3mmm4RfMePRCK/65gCWQFmCD9w6B4UomyxK74DvxPrq34PXAFR45pDg1s9BKnqjxL3Tk11mtsUUCuXcukqlUGy/dYho1fu/SzKX88zmrRzOFTcJJMRbWYB9DTg4YPxI/fPHuqe8ZRpPkAE6sJQD6N+Mtfh4eYrOJsow/Bx9naUqeP5TjyZckCdwjRLChzlaJa/DmfLzbECSlNrwxXFk9COwXICbU5otTKIAivYAhnANDR1Myzib5t1AGQD81Hj6R8R4memYI50icBkUY5rRD/10U3sOBA6RhQakJ0Fojqq6hhFChMeuWVvwAiYsSWlWtDcvrGgjveU/VvGSRSLxPoBX+8McEgICxpUUd2qugOwyHTfRe5Tq4bfvUF0ETAORyzMzpw5CrgkIPZH9ZTOKLFim98rQ9UmnlQCS4WFbvu8WTYQAUu7rGgjj897x2IO0OiWIfdtwXtCc00zq7k9C2iAFdYJrivZMglL9EqxPVAp/7EozENPjctYImeLEgzwq2NEDW7nI5fPfulII2qsBySjyAXpVxDzavp+37S4K57mhDK+VXSRoMwHrqwqDH/Cz7gwSf/I2uYA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 83a2d57e-18d4-4e2e-d2b1-08d86aa629e9 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6754.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2020 09:48:37.5299 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: TiuZA0vQa0GoJ83vWoqAXZvkdO7Px6KtiygugQx1ACPw9r/37/qz3jUu6D+s1NfouHazuIio823uy0k8u54RpA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB7169 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Decouple level MAC configuration based on phy interface type from general port configuration. Group together MAC and link configuration code. Decouple external mdio bus creation from interface type parsing. No longer return an (unhandled) error code when phy_node not found, use phy_node to indicate whether the port has a phy or not. No longer fall-through when serdes configuration fails for the link modes that require internal link configuration. Signed-off-by: Claudiu Manoil Reviewed-by: Ioana Ciornei --- v2: none .../net/ethernet/freescale/enetc/enetc_pf.c | 115 ++++++++++-------- 1 file changed, 67 insertions(+), 48 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c b/drivers/net/ethernet/freescale/enetc/enetc_pf.c index 177334f0adb1..64596731c1c9 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c @@ -482,8 +482,7 @@ static void enetc_port_si_configure(struct enetc_si *si) enetc_port_wr(hw, ENETC_PSIVLANFMR, ENETC_PSIVLANFMR_VS); } -static void enetc_configure_port_mac(struct enetc_hw *hw, - phy_interface_t phy_mode) +static void enetc_configure_port_mac(struct enetc_hw *hw) { enetc_port_wr(hw, ENETC_PM0_MAXFRM, ENETC_SET_MAXFRM(ENETC_RX_MAXFRM_SIZE)); @@ -492,12 +491,16 @@ static void enetc_configure_port_mac(struct enetc_hw *hw, enetc_port_wr(hw, ENETC_PTXMBAR, 2 * ENETC_MAC_MAXFRM_SIZE); enetc_port_wr(hw, ENETC_PM0_CMD_CFG, ENETC_PM0_CMD_PHY_TX_EN | - ENETC_PM0_CMD_TXP | ENETC_PM0_PROMISC | - ENETC_PM0_TX_EN | ENETC_PM0_RX_EN); + ENETC_PM0_CMD_TXP | ENETC_PM0_PROMISC); enetc_port_wr(hw, ENETC_PM1_CMD_CFG, ENETC_PM0_CMD_PHY_TX_EN | - ENETC_PM0_CMD_TXP | ENETC_PM0_PROMISC | - ENETC_PM0_TX_EN | ENETC_PM0_RX_EN); + ENETC_PM0_CMD_TXP | ENETC_PM0_PROMISC); +} + +static void enetc_mac_config(struct enetc_hw *hw, phy_interface_t phy_mode) +{ + u32 val; + /* set auto-speed for RGMII */ if (enetc_port_rd(hw, ENETC_PM0_IF_MODE) & ENETC_PMO_IFM_RG || phy_interface_mode_is_rgmii(phy_mode)) @@ -505,6 +508,14 @@ static void enetc_configure_port_mac(struct enetc_hw *hw, if (phy_mode == PHY_INTERFACE_MODE_USXGMII) enetc_port_wr(hw, ENETC_PM0_IF_MODE, ENETC_PM0_IFM_XGMII); + + /* enable Rx and Tx */ + val = enetc_port_rd(hw, ENETC_PM0_CMD_CFG); + enetc_port_wr(hw, ENETC_PM0_CMD_CFG, + val | ENETC_PM0_TX_EN | ENETC_PM0_RX_EN); + + enetc_port_wr(hw, ENETC_PM1_CMD_CFG, + val | ENETC_PM0_TX_EN | ENETC_PM0_RX_EN); } static void enetc_configure_port_pmac(struct enetc_hw *hw) @@ -527,7 +538,7 @@ static void enetc_configure_port(struct enetc_pf *pf) enetc_configure_port_pmac(hw); - enetc_configure_port_mac(hw, pf->if_mode); + enetc_configure_port_mac(hw); enetc_port_si_configure(pf->si); @@ -733,11 +744,10 @@ static void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev, enetc_get_primary_mac_addr(&si->hw, ndev->dev_addr); } -static int enetc_mdio_probe(struct enetc_pf *pf) +static int enetc_mdio_probe(struct enetc_pf *pf, struct device_node *np) { struct device *dev = &pf->si->pdev->dev; struct enetc_mdio_priv *mdio_priv; - struct device_node *np; struct mii_bus *bus; int err; @@ -754,26 +764,36 @@ static int enetc_mdio_probe(struct enetc_pf *pf) mdio_priv->mdio_base = ENETC_EMDIO_BASE; snprintf(bus->id, MII_BUS_ID_SIZE, "%s", dev_name(dev)); - np = of_get_child_by_name(dev->of_node, "mdio"); - if (!np) { - dev_err(dev, "MDIO node missing\n"); - return -EINVAL; - } - err = of_mdiobus_register(bus, np); if (err) { - of_node_put(np); dev_err(dev, "cannot register MDIO bus\n"); return err; } - of_node_put(np); pf->mdio = bus; return 0; } -static void enetc_mdio_remove(struct enetc_pf *pf) +static int enetc_mdiobus_create(struct enetc_pf *pf) +{ + struct device *dev = &pf->si->pdev->dev; + struct device_node *mdio_np; + int err; + + mdio_np = of_get_child_by_name(dev->of_node, "mdio"); + if (mdio_np) { + err = enetc_mdio_probe(pf, mdio_np); + + of_node_put(mdio_np); + if (err) + return err; + } + + return 0; +} + +static void enetc_mdiobus_destroy(struct enetc_pf *pf) { if (pf->mdio) mdiobus_unregister(pf->mdio); @@ -783,14 +803,13 @@ static int enetc_of_get_phy(struct enetc_pf *pf) { struct device *dev = &pf->si->pdev->dev; struct device_node *np = dev->of_node; - struct device_node *mdio_np; int err; pf->phy_node = of_parse_phandle(np, "phy-handle", 0); if (!pf->phy_node) { if (!of_phy_is_fixed_link(np)) { - dev_err(dev, "PHY not specified\n"); - return -ENODEV; + dev_dbg(dev, "PHY not specified\n"); + return 0; } err = of_phy_register_fixed_link(np); @@ -802,24 +821,12 @@ static int enetc_of_get_phy(struct enetc_pf *pf) pf->phy_node = of_node_get(np); } - mdio_np = of_get_child_by_name(np, "mdio"); - if (mdio_np) { - of_node_put(mdio_np); - err = enetc_mdio_probe(pf); - if (err) { - of_node_put(pf->phy_node); - return err; - } - } - err = of_get_phy_mode(np, &pf->if_mode); if (err) { dev_err(dev, "missing phy type\n"); of_node_put(pf->phy_node); if (of_phy_is_fixed_link(np)) of_phy_deregister_fixed_link(np); - else - enetc_mdio_remove(pf); return -EINVAL; } @@ -1004,10 +1011,6 @@ static int enetc_pf_probe(struct pci_dev *pdev, pf->si = si; pf->total_vfs = pci_sriov_get_totalvfs(pdev); - err = enetc_of_get_phy(pf); - if (err) - dev_warn(&pdev->dev, "Fallback to PHY-less operation\n"); - enetc_configure_port(pf); enetc_get_si_caps(si); @@ -1022,8 +1025,6 @@ static int enetc_pf_probe(struct pci_dev *pdev, enetc_pf_netdev_setup(si, ndev, &enetc_ndev_ops); priv = netdev_priv(ndev); - priv->phy_node = pf->phy_node; - priv->if_mode = pf->if_mode; enetc_init_si_rings_params(priv); @@ -1039,9 +1040,24 @@ static int enetc_pf_probe(struct pci_dev *pdev, goto err_alloc_msix; } - err = enetc_configure_serdes(priv); + err = enetc_of_get_phy(pf); if (err) - dev_warn(&pdev->dev, "Attempted SerDes config but failed\n"); + goto err_of_get_phy; + + if (pf->phy_node) { + priv->phy_node = pf->phy_node; + priv->if_mode = pf->if_mode; + + err = enetc_mdiobus_create(pf); + if (err) + goto err_mdiobus_create; + + err = enetc_configure_serdes(priv); + if (err) + goto err_configure_serdes; + + enetc_mac_config(&pf->si->hw, pf->if_mode); + } err = register_netdev(ndev); if (err) @@ -1053,6 +1069,11 @@ static int enetc_pf_probe(struct pci_dev *pdev, err_reg_netdev: enetc_teardown_serdes(priv); +err_configure_serdes: + enetc_mdiobus_destroy(pf); +err_mdiobus_create: + enetc_of_put_phy(pf); +err_of_get_phy: enetc_free_msix(priv); err_alloc_msix: enetc_free_si_resources(priv); @@ -1060,8 +1081,6 @@ static int enetc_pf_probe(struct pci_dev *pdev, si->ndev = NULL; free_netdev(ndev); err_alloc_netdev: - enetc_mdio_remove(pf); - enetc_of_put_phy(pf); err_map_pf_space: enetc_pci_remove(pdev); @@ -1074,16 +1093,16 @@ static void enetc_pf_remove(struct pci_dev *pdev) struct enetc_pf *pf = enetc_si_priv(si); struct enetc_ndev_priv *priv; + priv = netdev_priv(si->ndev); + enetc_teardown_serdes(priv); + enetc_mdiobus_destroy(pf); + enetc_of_put_phy(pf); + if (pf->num_vfs) enetc_sriov_configure(pdev, 0); - priv = netdev_priv(si->ndev); unregister_netdev(si->ndev); - enetc_teardown_serdes(priv); - enetc_mdio_remove(pf); - enetc_of_put_phy(pf); - enetc_free_msix(priv); enetc_free_si_resources(priv);