From patchwork Fri Jun 17 20:32:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 12886008 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1A8D1C433EF for ; Fri, 17 Jun 2022 20:40:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4zx5tLYnq7nq+fy7BIPadGrw61W8YgNa5vo1lx9r3Vk=; b=qHz3L9mlB2cbif 6JMirjDf4Ok0yQ3o7RmekwRxoNxoGByfucGcKfua2x/vXH1y1Vro32oWKpPUskspV9P2o05qqywc2 FGXkKK/HtlG+AdDdsAVmEU9NM9FzoAzmq1mVJ9Bfwoycn7coLK9hFVdPtD0jvEM7GR6H0DbzbZkHW MRIV5llvlqWyh2HlHpXTmmcrocRPdBdlybL+Mpt5lB6ExE1hfhcoa7M2VvRUivBgYOxsDVLUrpIKI RfAnWaBlu71dogcYHCYgyfH2uyYO777hkBmghtwjJrHfYZDcRiYgNRWuNrJBtTCcqXKee5jLiEsRy DHm8U1Bp7OP++jLr8XaQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o2IkL-008zSB-SZ; Fri, 17 Jun 2022 20:39:14 +0000 Received: from mail-am6eur05on2061c.outbound.protection.outlook.com ([2a01:111:f400:7e1b::61c] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o2IfM-008xKA-KB for linux-arm-kernel@lists.infradead.org; Fri, 17 Jun 2022 20:34:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Tf3CT2LnzQXLFx+jJMmCP58GtrLUYGxYX3zATrYEX1sGHPDn0WFyjYQbUYobBEDDIbbGOxkeOowYAlrdVdDd4LCvm63ommpv2SUmqy7UCiDetH5lh+FVh8gT194evfR+qMVAKnzeSBIhn5n+N8H0bDHxwFYBwLZRIyoHWbARK4HjDOKwv8naS466bIlnznqfuhYTu6EfrUAwuoN/VBYblwUhAcDVhB9UPD7cxeuewlIjr0fs4q0CYoVwu3DaWTAUpBwbZul7i+0hbJb3B8+OqNdcPpBUvCwMqr99A7+GRu4ySFzbkpm4PCcjTDcmm8mFVIkzPPr/AVM3MWWr1PnV0w== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=d+y16VQC1oW/rdss5dl3TAPZohiMfyoZswy9Xv/m09Q=; b=Cwb41M+tce6FoQ34OR+Ni588l1lKs+g16pVmmWV03M4HWbuVoyB+t5pOPQ6bRr0mipAbIm5iFTtXpeM/NMwIruyx/DPDgis4+64w9NB+iGD6F3i4dbbS7GiqGUf0Vmnc+S4c0qSc9q6w8zFMW97qEPIbkn9Q7JAOh1em1SIrfLp1kgsPEX64LChGll8BJI1egLdxPFaMVMA5omVqu6Jzim7MQZF7mGI4mJmhvkxZFmq/0S5lKxvlYbnbjRCS4+BxWJ629FVPBNRcxK6I/6XFzv7Vx2fDmYrRczSjgfbFhtU7ZmANVpWJ3h3UpNnj/Tsf5dKSW11DClTbXOFH4trnXg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=seco.com; dmarc=pass action=none header.from=seco.com; dkim=pass header.d=seco.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seco.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=d+y16VQC1oW/rdss5dl3TAPZohiMfyoZswy9Xv/m09Q=; b=le+aPe0CG0/xF3atici8ab+hPFKTjTCqd+3sOwOxV8cMhtRWj9dcS+xMd3uV36Vrd91qthNM19mA0h8UN3jLVwI2WyIiEPavip6gGGT5uIqpS6n5YJbHAd8/hebyEqGxPPsxfiH0y1HH05EBC6+Q1pW/3tDxzvEUxxMwTSFF76jp9HOMnwx6fiNLJy68DMy8ckI2B35nRDcl03ankd1vHDxQ8YuxCUwDQRjYXKY7l2zBbUFQJs53EC/s7cLjESq9a9OcMwXoxGA/bMTL9AcQuYcL/1X8PTl1wmVGbf1h6DBGZy71io0mfTitv733gyasrX8HaR2Bumj7uFV9AdDPow== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=seco.com; Received: from VI1PR03MB4973.eurprd03.prod.outlook.com (2603:10a6:803:c5::12) by DBAPR03MB6438.eurprd03.prod.outlook.com (2603:10a6:10:19f::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.16; Fri, 17 Jun 2022 20:33:53 +0000 Received: from VI1PR03MB4973.eurprd03.prod.outlook.com ([fe80::d18f:e481:f1fa:3e8d]) by VI1PR03MB4973.eurprd03.prod.outlook.com ([fe80::d18f:e481:f1fa:3e8d%7]) with mapi id 15.20.5353.016; Fri, 17 Jun 2022 20:33:53 +0000 From: Sean Anderson To: "David S . Miller" , Jakub Kicinski , Madalin Bucur , netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Paolo Abeni , Russell King , Eric Dumazet , Sean Anderson Subject: [PATCH net-next 09/28] net: fman: Store initialization function in match data Date: Fri, 17 Jun 2022 16:32:53 -0400 Message-Id: <20220617203312.3799646-10-sean.anderson@seco.com> X-Mailer: git-send-email 2.35.1.1320.gc452695387.dirty In-Reply-To: <20220617203312.3799646-1-sean.anderson@seco.com> References: <20220617203312.3799646-1-sean.anderson@seco.com> X-ClientProxiedBy: BL1PR13CA0384.namprd13.prod.outlook.com (2603:10b6:208:2c0::29) To VI1PR03MB4973.eurprd03.prod.outlook.com (2603:10a6:803:c5::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b0906e91-5fcd-447b-1231-08da50a0b16e X-MS-TrafficTypeDiagnostic: DBAPR03MB6438:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZpuNVrQMROfBBfdlzypehIFXxx3lH1CVdStaxPCjtGvSWZAZ516rnj0Rtop9tYPf9aoEE1jGEqTtpglszOrUbUGsR6SYwDmC3yJ7JN04cr/I03w9VpeRCzdZaNem9t516Trq9ekyHsJr9xmUBNmcrPzjrW4/pBiPPUWXFmf65tzxpNyJC7Aq7ob3AdvG1RcRnN+0tY9Nc74bwKnih9ep9fR0Sw4+TMQsovj7tc4iGYK+BYjG2A5STCfJ/Jr5a0f+G7Tnj6U5wt/sFhP3j61U9zpUYLQmXeUHgH+kolsW2zoTg0TarqyR8S+YZ02+zsY2Rmbqbxlz2arFcMBGE71yA0VnBGWjxEdlu/F1qdjKCvzDk4L4irJQckIht3CfXVW/vil07sLCdPnTm7BpIM6RV5lcCqmoA20kyfh0wZhpoACxxpx4mnSWrRs9MRLPAwj6b0FLmqTYTl4MyMuwT3K7BbMSI6+Fry3PmdKnYPePAjde+nFK0irjjgg4u0RLg+/apL+46M3JCTY0lP3+ASwgrSVvQMOhvbIB5MDFIXPHfe4WSYVQkCqPhrKbwGkKgutguOsRtvlDVnb4VnI6/f17hg4uMx/aYIM+sLb8NV7P0PfF/C0ZI8kQh6JzwNjUX1YwpB7BjDjLPSjNSHJ7k5EjuubSPLKtY+os55/iR7ZYvXLLJYzQ42hpXBJ7MCpLDMp4kcbSTtxRpKhFQgFdjtZtlQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB4973.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(366004)(54906003)(498600001)(8936002)(110136005)(6486002)(52116002)(2906002)(6506007)(4326008)(26005)(83380400001)(66476007)(66556008)(8676002)(316002)(1076003)(36756003)(30864003)(66946007)(38100700002)(107886003)(38350700002)(44832011)(86362001)(2616005)(5660300002)(6512007)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: zxP/GWQSLPsNt/WIxXJ6KU0DZXKSkOj3Izyk1NeEb7Kq49dWEnM/CqT2XJLVP2236AMxnhIE3lRvna1fLyYwFW/bmnpbaJLQFV3Hdzr63UZV0CNA0+87FngPRId2bKeQhFsGVTni6TMkynrAoftVqhhUjMHGuggfeog2YeoYtwEtCZgujjpbQWfj9HKNIz2LzMCOaxH+VND/ORjMx/FB+Bl6WO+3e/PlWzVmhB8/Pw5pQegILxeEN7H0G2CVtXgmic2n29ANaGHUCOAiutJYHlJgk/qhJqDS/gFf1QCvfL2/c3e87gaTBYiW/9+WgUr6d9MZVLDZdz5I/frUIXsDTX1/1lh1R7CSniYe8VXQkYN71KtD/OGl0rx6btknbF74pFrNxQDZ+S7AVx7XiFi+mMS4riiO26iUkqB2YG+PvlvoTxWFdrv0XGYSxx1I04nDy7pY1qzko8gzNiQTDt7t/Jf+8D4dBexjJOlBi1XTJwSXwKVrJ+Q7ICrSAS1GPnu9gaL15YupdC3X2N1CHnyXEmmeXa0sKLfYoD0ypVUoJSxxnNSD3yjJbD0Pyhl7DVMW34PkFGjCho8Hb2BifCTV+tsWoHnSjrJZmVB1lxMNVGNNDUi1xhWTbVCAfqhOh3trnSaQ9ycPBKOoR8DtNiwrjZ7mYcCAgktvuWGp3qBJwyCfB5YQ5skYiXVHdfIV2V7aRpuiE4B2eSc8W9Vj3mWGpLgqr/TDWW4ONCh6VvurRXkDLHB1i+9o7Fxar5bWO77LX0J4n59Mmj4VM6Fc+KvG4Uf7cTq+qfxlEAgGi7qZVNhNcbnPnjgRug2jAcLDdP3OIhfAE16+rR5qDWh/lJ2IoF8ch+WmBFlqJqOsxtiNNkz9l7yxbCTNCdkDmelSc9zeS3QtfsCpnDtWXinc6PEFP6rvc/4aw3srta1BM2unG4i1r3qb4cVExUYw2PDuRdSf7+oId04SdiwyU75hoVlBPq5GRcLoxREkd+JAdapr+wIgcnYKjAHym/zPLpHPV+QSJT21P4NsxkinHNFAKAbRp1uM6HOJCo1zIZlfX2hOLX+46T6TIUvV6v45v1IQnhxNeJTFdEsGPhxiVyDWlFblJyFRHeQKpya3STdFABf/s+XZDA5oJAt8tj2NG+mR+frKeFWk+QEIBp5JuzbBQ82ldVqWFlyEJx0ytAknq3Im5PGIMzg969lTSFidOg72fkAIl+B4eQX129tPMPEnaPuqTrn44B9rxqqC1NiQK0ExHIkGCjxuCwvV4MXAst5aoIUnCWtLczmr0S8hYYuXOdOpPC/IXBH94h2hNEVZ17IoGeYXLkFQLFz1SHasRmzhKcQSNvggZ5+E9lCbYCRw9ACxiQp+s59JnUZnnm+aeTkuCNQz3ryGvwDgG78++Ys65wqcBHSss1iG6V4nlUGvMRAoRkFgljATNG5aK+Z4eKdIQtgqGmCinxWyAqJ2L8Zie67mK3gKK780/7H3drlcJ1ZMILDFvC/6QcYIEluLd5mBqEtM6lAXx4t9L8ceSo2aWip0mULYZD4PtzGOQx2fOU5vMZvJTBdjDUzwivbMSVO1/5zDQkVky6YlAASzVaMPzVajC4xzf4Vi4038MFSLqhDB4pydlSsVuofo6QOb63Nu9klzqxIez6+5vHpgXSTMHaxYcJlecPaV59CvDHqLgRJdqCr0le0fycuxCSySTtwWAmeD99DAAWhiLfGI/Z5aqfdNwWBG2+qdnDrMAPCHaCLqbQOfu85BO+W2onT2OgINgzg= X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-Network-Message-Id: b0906e91-5fcd-447b-1231-08da50a0b16e X-MS-Exchange-CrossTenant-AuthSource: VI1PR03MB4973.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2022 20:33:53.0460 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bebe97c3-6438-442e-ade3-ff17aa50e733 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ihEAMcUx5FeVfqdWP9TrIZHyCTegKGisKc17ZKCkEb41f7e7mRWSEjzNvsLXVhoLgIQqohSEVdZrx/B/rtim6w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR03MB6438 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220617_133404_735535_1C3599C6 X-CRM114-Status: GOOD ( 13.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Instead of re-matching the compatible string in order to determine the init function, just store it in the match data. This also move the setting of the rest of the functions into init as well. To ensure everything compiles correctly, we move them to the bottom of the file. Signed-off-by: Sean Anderson --- drivers/net/ethernet/freescale/fman/mac.c | 356 ++++++++++------------ drivers/net/ethernet/freescale/fman/mac.h | 1 - 2 files changed, 165 insertions(+), 192 deletions(-) diff --git a/drivers/net/ethernet/freescale/fman/mac.c b/drivers/net/ethernet/freescale/fman/mac.c index 0af6f6c49284..8dd6a5b12922 100644 --- a/drivers/net/ethernet/freescale/fman/mac.c +++ b/drivers/net/ethernet/freescale/fman/mac.c @@ -88,159 +88,6 @@ static int set_fman_mac_params(struct mac_device *mac_dev, return 0; } -static int tgec_initialization(struct mac_device *mac_dev, - struct device_node *mac_node) -{ - int err; - struct mac_priv_s *priv; - struct fman_mac_params params; - u32 version; - - priv = mac_dev->priv; - - err = set_fman_mac_params(mac_dev, ¶ms); - if (err) - goto _return; - - mac_dev->fman_mac = tgec_config(¶ms); - if (!mac_dev->fman_mac) { - err = -EINVAL; - goto _return; - } - - err = tgec_cfg_max_frame_len(mac_dev->fman_mac, fman_get_max_frm()); - if (err < 0) - goto _return_fm_mac_free; - - err = tgec_init(mac_dev->fman_mac); - if (err < 0) - goto _return_fm_mac_free; - - /* For 10G MAC, disable Tx ECC exception */ - err = mac_dev->set_exception(mac_dev->fman_mac, - FM_MAC_EX_10G_TX_ECC_ER, false); - if (err < 0) - goto _return_fm_mac_free; - - err = tgec_get_version(mac_dev->fman_mac, &version); - if (err < 0) - goto _return_fm_mac_free; - - dev_info(priv->dev, "FMan XGEC version: 0x%08x\n", version); - - goto _return; - -_return_fm_mac_free: - tgec_free(mac_dev->fman_mac); - -_return: - return err; -} - -static int dtsec_initialization(struct mac_device *mac_dev, - struct device_node *mac_node) -{ - int err; - struct mac_priv_s *priv; - struct fman_mac_params params; - u32 version; - - priv = mac_dev->priv; - - err = set_fman_mac_params(mac_dev, ¶ms); - if (err) - goto _return; - params.internal_phy_node = of_parse_phandle(mac_node, "tbi-handle", 0); - - mac_dev->fman_mac = dtsec_config(¶ms); - if (!mac_dev->fman_mac) { - err = -EINVAL; - goto _return; - } - - err = dtsec_cfg_max_frame_len(mac_dev->fman_mac, fman_get_max_frm()); - if (err < 0) - goto _return_fm_mac_free; - - err = dtsec_cfg_pad_and_crc(mac_dev->fman_mac, true); - if (err < 0) - goto _return_fm_mac_free; - - err = dtsec_init(mac_dev->fman_mac); - if (err < 0) - goto _return_fm_mac_free; - - /* For 1G MAC, disable by default the MIB counters overflow interrupt */ - err = mac_dev->set_exception(mac_dev->fman_mac, - FM_MAC_EX_1G_RX_MIB_CNT_OVFL, false); - if (err < 0) - goto _return_fm_mac_free; - - err = dtsec_get_version(mac_dev->fman_mac, &version); - if (err < 0) - goto _return_fm_mac_free; - - dev_info(priv->dev, "FMan dTSEC version: 0x%08x\n", version); - - goto _return; - -_return_fm_mac_free: - dtsec_free(mac_dev->fman_mac); - -_return: - return err; -} - -static int memac_initialization(struct mac_device *mac_dev, - struct device_node *mac_node) -{ - int err; - struct mac_priv_s *priv; - struct fman_mac_params params; - - priv = mac_dev->priv; - - err = set_fman_mac_params(mac_dev, ¶ms); - if (err) - goto _return; - params.internal_phy_node = of_parse_phandle(mac_node, "pcsphy-handle", 0); - - if (priv->max_speed == SPEED_10000) - params.phy_if = PHY_INTERFACE_MODE_XGMII; - - mac_dev->fman_mac = memac_config(¶ms); - if (!mac_dev->fman_mac) { - err = -EINVAL; - goto _return; - } - - err = memac_cfg_max_frame_len(mac_dev->fman_mac, fman_get_max_frm()); - if (err < 0) - goto _return_fm_mac_free; - - err = memac_cfg_reset_on_init(mac_dev->fman_mac, true); - if (err < 0) - goto _return_fm_mac_free; - - err = memac_cfg_fixed_link(mac_dev->fman_mac, priv->fixed_link); - if (err < 0) - goto _return_fm_mac_free; - - err = memac_init(mac_dev->fman_mac); - if (err < 0) - goto _return_fm_mac_free; - - dev_info(priv->dev, "FMan MEMAC\n"); - - goto _return; - -_return_fm_mac_free: - memac_free(mac_dev->fman_mac); - -_return: - return err; -} - static int set_multi(struct net_device *net_dev, struct mac_device *mac_dev) { struct mac_priv_s *priv; @@ -418,27 +265,15 @@ static void adjust_link_memac(struct mac_device *mac_dev) err); } -static void setup_dtsec(struct mac_device *mac_dev) +static int tgec_initialization(struct mac_device *mac_dev, + struct device_node *mac_node) { - mac_dev->init = dtsec_initialization; - mac_dev->set_promisc = dtsec_set_promiscuous; - mac_dev->change_addr = dtsec_modify_mac_address; - mac_dev->add_hash_mac_addr = dtsec_add_hash_mac_address; - mac_dev->remove_hash_mac_addr = dtsec_del_hash_mac_address; - mac_dev->set_tx_pause = dtsec_set_tx_pause_frames; - mac_dev->set_rx_pause = dtsec_accept_rx_pause_frames; - mac_dev->set_exception = dtsec_set_exception; - mac_dev->set_allmulti = dtsec_set_allmulti; - mac_dev->set_tstamp = dtsec_set_tstamp; - mac_dev->set_multi = set_multi; - mac_dev->adjust_link = adjust_link_dtsec; - mac_dev->enable = dtsec_enable; - mac_dev->disable = dtsec_disable; -} + int err; + struct mac_priv_s *priv; + struct fman_mac_params params; + u32 version; -static void setup_tgec(struct mac_device *mac_dev) -{ - mac_dev->init = tgec_initialization; + priv = mac_dev->priv; mac_dev->set_promisc = tgec_set_promiscuous; mac_dev->change_addr = tgec_modify_mac_address; mac_dev->add_hash_mac_addr = tgec_add_hash_mac_address; @@ -452,11 +287,121 @@ static void setup_tgec(struct mac_device *mac_dev) mac_dev->adjust_link = adjust_link_void; mac_dev->enable = tgec_enable; mac_dev->disable = tgec_disable; + + err = set_fman_mac_params(mac_dev, ¶ms); + if (err) + goto _return; + + mac_dev->fman_mac = tgec_config(¶ms); + if (!mac_dev->fman_mac) { + err = -EINVAL; + goto _return; + } + + err = tgec_cfg_max_frame_len(mac_dev->fman_mac, fman_get_max_frm()); + if (err < 0) + goto _return_fm_mac_free; + + err = tgec_init(mac_dev->fman_mac); + if (err < 0) + goto _return_fm_mac_free; + + /* For 10G MAC, disable Tx ECC exception */ + err = mac_dev->set_exception(mac_dev->fman_mac, + FM_MAC_EX_10G_TX_ECC_ER, false); + if (err < 0) + goto _return_fm_mac_free; + + err = tgec_get_version(mac_dev->fman_mac, &version); + if (err < 0) + goto _return_fm_mac_free; + + dev_info(priv->dev, "FMan XGEC version: 0x%08x\n", version); + + goto _return; + +_return_fm_mac_free: + tgec_free(mac_dev->fman_mac); + +_return: + return err; +} + +static int dtsec_initialization(struct mac_device *mac_dev, + struct device_node *mac_node) +{ + int err; + struct mac_priv_s *priv; + struct fman_mac_params params; + u32 version; + + priv = mac_dev->priv; + mac_dev->set_promisc = dtsec_set_promiscuous; + mac_dev->change_addr = dtsec_modify_mac_address; + mac_dev->add_hash_mac_addr = dtsec_add_hash_mac_address; + mac_dev->remove_hash_mac_addr = dtsec_del_hash_mac_address; + mac_dev->set_tx_pause = dtsec_set_tx_pause_frames; + mac_dev->set_rx_pause = dtsec_accept_rx_pause_frames; + mac_dev->set_exception = dtsec_set_exception; + mac_dev->set_allmulti = dtsec_set_allmulti; + mac_dev->set_tstamp = dtsec_set_tstamp; + mac_dev->set_multi = set_multi; + mac_dev->adjust_link = adjust_link_dtsec; + mac_dev->enable = dtsec_enable; + mac_dev->disable = dtsec_disable; + + err = set_fman_mac_params(mac_dev, ¶ms); + if (err) + goto _return; + params.internal_phy_node = of_parse_phandle(mac_node, "tbi-handle", 0); + + mac_dev->fman_mac = dtsec_config(¶ms); + if (!mac_dev->fman_mac) { + err = -EINVAL; + goto _return; + } + + err = dtsec_cfg_max_frame_len(mac_dev->fman_mac, fman_get_max_frm()); + if (err < 0) + goto _return_fm_mac_free; + + err = dtsec_cfg_pad_and_crc(mac_dev->fman_mac, true); + if (err < 0) + goto _return_fm_mac_free; + + err = dtsec_init(mac_dev->fman_mac); + if (err < 0) + goto _return_fm_mac_free; + + /* For 1G MAC, disable by default the MIB counters overflow interrupt */ + err = mac_dev->set_exception(mac_dev->fman_mac, + FM_MAC_EX_1G_RX_MIB_CNT_OVFL, false); + if (err < 0) + goto _return_fm_mac_free; + + err = dtsec_get_version(mac_dev->fman_mac, &version); + if (err < 0) + goto _return_fm_mac_free; + + dev_info(priv->dev, "FMan dTSEC version: 0x%08x\n", version); + + goto _return; + +_return_fm_mac_free: + dtsec_free(mac_dev->fman_mac); + +_return: + return err; } -static void setup_memac(struct mac_device *mac_dev) +static int memac_initialization(struct mac_device *mac_dev, + struct device_node *mac_node) { - mac_dev->init = memac_initialization; + int err; + struct mac_priv_s *priv; + struct fman_mac_params params; + + priv = mac_dev->priv; mac_dev->set_promisc = memac_set_promiscuous; mac_dev->change_addr = memac_modify_mac_address; mac_dev->add_hash_mac_addr = memac_add_hash_mac_address; @@ -470,6 +415,46 @@ static void setup_memac(struct mac_device *mac_dev) mac_dev->adjust_link = adjust_link_memac; mac_dev->enable = memac_enable; mac_dev->disable = memac_disable; + + err = set_fman_mac_params(mac_dev, ¶ms); + if (err) + goto _return; + params.internal_phy_node = of_parse_phandle(mac_node, "pcsphy-handle", 0); + + if (priv->max_speed == SPEED_10000) + params.phy_if = PHY_INTERFACE_MODE_XGMII; + + mac_dev->fman_mac = memac_config(¶ms); + if (!mac_dev->fman_mac) { + err = -EINVAL; + goto _return; + } + + err = memac_cfg_max_frame_len(mac_dev->fman_mac, fman_get_max_frm()); + if (err < 0) + goto _return_fm_mac_free; + + err = memac_cfg_reset_on_init(mac_dev->fman_mac, true); + if (err < 0) + goto _return_fm_mac_free; + + err = memac_cfg_fixed_link(mac_dev->fman_mac, priv->fixed_link); + if (err < 0) + goto _return_fm_mac_free; + + err = memac_init(mac_dev->fman_mac); + if (err < 0) + goto _return_fm_mac_free; + + dev_info(priv->dev, "FMan MEMAC\n"); + + goto _return; + +_return_fm_mac_free: + memac_free(mac_dev->fman_mac); + +_return: + return err; } #define DTSEC_SUPPORTED \ @@ -546,9 +531,9 @@ static struct platform_device *dpaa_eth_add_device(int fman_id, } static const struct of_device_id mac_match[] = { - { .compatible = "fsl,fman-dtsec" }, - { .compatible = "fsl,fman-xgec" }, - { .compatible = "fsl,fman-memac" }, + { .compatible = "fsl,fman-dtsec", .data = dtsec_initialization }, + { .compatible = "fsl,fman-xgec", .data = tgec_initialization }, + { .compatible = "fsl,fman-memac", .data = memac_initialization }, {} }; MODULE_DEVICE_TABLE(of, mac_match); @@ -556,6 +541,7 @@ MODULE_DEVICE_TABLE(of, mac_match); static int mac_probe(struct platform_device *_of_dev) { int err, i, nph; + int (*init)(struct mac_device *mac_dev, struct device_node *mac_node); struct device *dev; struct device_node *mac_node, *dev_node; struct mac_device *mac_dev; @@ -568,6 +554,7 @@ static int mac_probe(struct platform_device *_of_dev) dev = &_of_dev->dev; mac_node = dev->of_node; + init = of_device_get_match_data(dev); mac_dev = devm_kzalloc(dev, sizeof(*mac_dev), GFP_KERNEL); if (!mac_dev) { @@ -584,19 +571,6 @@ static int mac_probe(struct platform_device *_of_dev) mac_dev->priv = priv; priv->dev = dev; - if (of_device_is_compatible(mac_node, "fsl,fman-dtsec")) { - setup_dtsec(mac_dev); - } else if (of_device_is_compatible(mac_node, "fsl,fman-xgec")) { - setup_tgec(mac_dev); - } else if (of_device_is_compatible(mac_node, "fsl,fman-memac")) { - setup_memac(mac_dev); - } else { - dev_err(dev, "MAC node (%pOF) contains unsupported MAC\n", - mac_node); - err = -EINVAL; - goto _return; - } - INIT_LIST_HEAD(&priv->mc_addr_list); /* Get the FM node */ @@ -782,7 +756,7 @@ static int mac_probe(struct platform_device *_of_dev) put_device(&phy->mdio.dev); } - err = mac_dev->init(mac_dev, mac_node); + err = init(mac_dev, mac_node); if (err < 0) { dev_err(dev, "mac_dev->init() = %d\n", err); of_node_put(mac_dev->phy_node); diff --git a/drivers/net/ethernet/freescale/fman/mac.h b/drivers/net/ethernet/freescale/fman/mac.h index e4329c7d5001..fed3835a8473 100644 --- a/drivers/net/ethernet/freescale/fman/mac.h +++ b/drivers/net/ethernet/freescale/fman/mac.h @@ -35,7 +35,6 @@ struct mac_device { bool promisc; bool allmulti; - int (*init)(struct mac_device *mac_dev, struct device_node *mac_node); int (*enable)(struct fman_mac *mac_dev); int (*disable)(struct fman_mac *mac_dev); void (*adjust_link)(struct mac_device *mac_dev);