Received: by 10.213.65.68 with SMTP id h4csp365956imn; Tue, 13 Mar 2018 06:56:34 -0700 (PDT) X-Google-Smtp-Source: AG47ELsV+GLp8IsfOKdz8vTW66YUsJRouuUG2W5BlupJDUxer8o2f4D/KCIUZbZmIfQU1Q8F/+jW X-Received: by 10.98.34.75 with SMTP id i72mr686772pfi.165.1520949393967; Tue, 13 Mar 2018 06:56:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520949393; cv=none; d=google.com; s=arc-20160816; b=L2MDypD2GT6gAJzVheiXMD7AhQG2wR0drlE8t9vacybZ0GHVHciiaOVFRwkA5KofBj mRk5foPPUnfukUWUbIiUdoITAKgmSpQYwaWSotCHT2h/lYqVv7YJz5dzUgKsgssA19iQ dpsN+F5FGpGVwOi5lfzzMbCR+b9mleNJJLWTEXRN4sKCAV3Z+oh/zVjL0uhH1op5Xrz3 zH0b6srMNN2dd3VkzWAq/xzroPzf5LJ6C7gPqf5t+/aFRnjLlCZywipI9RYxSU0vn32u uvj7ErW/WKEp2QEOROBV49ZtvBsJHrNPXPAjr1LC9FTeJrHAaDutjs8ezLRSKLHfgQSz Uf9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:arc-authentication-results; bh=kmuaddcYBqOwWZkVR2oLK5ymFW3dHArcOW8K3OtyrGo=; b=xKRXeodYxjLlV8+mS3VKxubBx15j9a023DLzZd9Pa+5u9ZsmnfdxqXDrbItZU/okx+ vt9EnuF8X9LP05SBgA17R6khjyCmyDmVJc3Qtaib+ocqaMCYs9qoBHn5fc6ao+vHyBfI cGKcXjqzDIBmFOgExGxKWwrR9DJnX/0sn4xSnqgy4vKmgkdHg/o2GtYCVHdh+7s5oMlU q06ZIg9dGceXhhfPweIQKbrNgFMFUWmIIzRZMyAlqHHL3ACA5j1OI7yUkNzPHBH5hA0T zsiBmr8mM186sONFTi6/cVhVuuMPV4IBxbLZfQ3rvMB04uZeVwXA300YKSNYINyyZ//H hEiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector1 header.b=kWQGZj58; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t186si162104pgt.130.2018.03.13.06.56.19; Tue, 13 Mar 2018 06:56:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector1 header.b=kWQGZj58; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932768AbeCMNyy (ORCPT + 99 others); Tue, 13 Mar 2018 09:54:54 -0400 Received: from mail-he1eur01on0082.outbound.protection.outlook.com ([104.47.0.82]:52000 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752963AbeCMNwV (ORCPT ); Tue, 13 Mar 2018 09:52:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=kmuaddcYBqOwWZkVR2oLK5ymFW3dHArcOW8K3OtyrGo=; b=kWQGZj58Z6ptfLJbcZMlqk6gI8KM5tiRWtkR5M7soAQvIsYErt73pI7qlZkcZjcwxmTULZ/WgT1HVQXhi96uuFgCqI106e+UL++TBTj/0CogneCuATNwIme1Jt272djRra59XnD6M6vU2/WLUWo3EGnOvxoGvwDJe283Sz+BhAA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=razvan.stefanescu@nxp.com; Received: from rhuath.am.freescale.net (192.88.168.1) by DB3PR04MB0747.eurprd04.prod.outlook.com (2a01:111:e400:9440::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.567.14; Tue, 13 Mar 2018 13:52:12 +0000 From: Razvan Stefanescu To: gregkh@linuxfoundation.org Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, agraf@suse.de, arnd@arndb.de, alexandru.marginean@nxp.com, ruxandra.radulescu@nxp.com, ioana.ciornei@nxp.com, laurentiu.tudor@nxp.com, stuyoder@gmail.com Subject: [PATCH v5 2/6] staging: fsl-dpaa2/ethsw: Add Freescale DPAA2 Ethernet Switch driver Date: Tue, 13 Mar 2018 08:51:52 -0500 Message-Id: <20180313135156.3322-3-razvan.stefanescu@nxp.com> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20180313135156.3322-1-razvan.stefanescu@nxp.com> References: <20180313135156.3322-1-razvan.stefanescu@nxp.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [192.88.168.1] X-ClientProxiedBy: DM3PR12CA0069.namprd12.prod.outlook.com (2603:10b6:0:57::13) To DB3PR04MB0747.eurprd04.prod.outlook.com (2a01:111:e400:9440::15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 52627985-3767-47b4-3f58-08d588e9a09a X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020);SRVR:DB3PR04MB0747; X-Microsoft-Exchange-Diagnostics: 1;DB3PR04MB0747;3:yJEAQNcxrXtKesu1RJRmRg1+AOermd/VFtCHlH+VrHP0LwzPAaczpVWGrkhld3iDl1txqT0WwDn6iNjklAbHJHMPn2KmjbbwuJhOwBlFB417fJFsNHQ0IKgSRqrZqupMSLl7KUCuoEbVk/vAo54mDkh6+kiv3egww95+qN+orodtqf0NAK68Y/TREad5fkoAZSqJUeBLiPWdSoRKqnRIJmqirx8FyeQzszWvgbutFag7Qs1Tj3uqD2xPmlt2v6GN;25:Rpq/SmpuBJizA+ofrEVDBhEvAOT/OeENwvCp6hM/e4BzjkZ6MlhvFdFdINJC6xgxh69R3TwFQCsdeYB2fmVQKCJEZcvFVZonfg3e6poX2yvTzA3oXv/BwHTKbF4HtB10jt4JkL1yfeHsugKi65xNChxfWi9ckc4yv1oD/D1lyP4vxCyO3U400BdO0eR2DM5hgKq0NZwUW8wscUAd4Uqj0waqFK+GckmdT23EIgdMqgOOJy8dNcfBdUn1X7rIcmfi427WJqEz11zNXKXMYJRQETZbM6Pdll+gHrOZGmQqr9l63HMnWmQTkPUBAKH1xkZ4E9nw5BzrSPCtfvewwfEDYQ==;31:/vNOZ4wRe71MZz6fvjFPtnNxY8uziFebaPm5oUEk5wpxLWtC+nVlT1pBMq/cdsb+Us1SFLQAQsmaQ3dm+iAU7PVUogS2h0z0hjESj0DlrutWC1BqfN6QF8FSLInf4LkR/40Hqw+afRxE4hBDd2qS3T0BjKcM2tPMRsJW4ZxgDhqjGfHF2Yfs28Hsz3Oe8gneYh4hBFd9/pRuWjjsSdzs0ildlCxPNMdXuyd/srMzBgg= X-MS-TrafficTypeDiagnostic: DB3PR04MB0747: X-LD-Processed: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635,ExtAddr X-Microsoft-Exchange-Diagnostics: 1;DB3PR04MB0747;20:36ZqdnhlJp3sFiA+9/CsLBjHV0JTFb/Fiuj+90DLI0ITIHMkdFUxSMR2IwhIBqDPoJqKo7FHgPsvD42ed8xe21rumtc5xVw746DW1pYj6XVeb5aJy8WAQIrfeHjAgXkQj+eEvbthTDe+7YZ25dwnPJDajX+yPpBb8v8wX2T4F7a7m5UGB8WGFj1M865fPy1c2PxQvzmEhuUUfsevLP2++w3WMsX2xBFbwN/3wYOi35cHxnbjtArCRST0bfgVlQhtqs0sMGZhbOWYraCy0B9Fx9mjuV5Kt/+oiowAoBU0r+ITcRYkGWg0Hp/Weg0CE/DWk6AyRmF/DrMYizeDxrVWh/r1m9CyPbRVIOyjNJGwchIY1mNWKF7x8LdJHlBmVOqTN36dkw8QzCDCVe62k03Ec45IuSS6L8vx9BloMOTlL2IE03Dnq+vPr3+6VXgPB5ZTK20C27Il0/syKRu2WkrQ6gmigPv9sdR4CcQIij6ZR7eCo/aPNQsL9x5tTCyHiybm;4:2DQ5RBCoglLaJ9C37LZLYDa0IJTcaKTaCyWBBL3UTpBnlSayIEjPdqBepsWLug9AWUtHTYFlOvKeLD121EcXm23kDda00K4/3lp0trs4KPDv17mczmlScEhnVAsVFZaBO94DIanmyoIZyYOMWEAMtbXic3O6TIoY8Ax0ILcxQlN3VoIOXnigTPxpVb4srUw9Bhz43ipJ0r5spZXHT+cwwANemvyvg1HRFW5HG210HpwtyezrNwX04mplyXWq5YNFNRyqRGuJQYvmDeyUDjuu24cXfk5hXjyRy2nUVsW/gNSsFDTIiy301jc+BTPkznHMXdGAHHFXIiQ1beDR8vf+QLnijKMS/5UUL76zZlQPki0= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197)(788757137089); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3231221)(944501244)(52105095)(3002001)(6055026)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011);SRVR:DB3PR04MB0747;BCL:0;PCL:0;RULEID:;SRVR:DB3PR04MB0747; X-Forefront-PRVS: 0610D16BBE X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(376002)(39380400002)(366004)(39860400002)(346002)(396003)(51234002)(54534003)(189003)(199004)(1076002)(16526019)(186003)(6916009)(5660300001)(478600001)(50466002)(48376002)(3846002)(6116002)(8676002)(47776003)(6666003)(26005)(2906002)(7736002)(81156014)(2950100002)(66066001)(81166006)(6506007)(59450400001)(305945005)(76176011)(386003)(25786009)(50226002)(52116002)(86362001)(8936002)(316002)(16586007)(39060400002)(36756003)(53946003)(51416003)(106356001)(68736007)(6486002)(53936002)(2351001)(2361001)(4326008)(6512007)(97736004)(105586002)(2004002)(579004)(309714004);DIR:OUT;SFP:1101;SCL:1;SRVR:DB3PR04MB0747;H:rhuath.am.freescale.net;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DB3PR04MB0747;23:ud/CgtBy/ya9nO9monk9nqlrvc6EsXDoJ/bdxMCFn?= =?us-ascii?Q?OKTV1rte+GdyYlwqHvbtTHjcwlMdGhTJ3Qa38s4pI7XPF7ZeTxbaoWDFXQaE?= =?us-ascii?Q?TK+3oHe7YUntRhBJosRRfiN2qKlaH2c1Bc3GQ4XP/uA+rfgAt1Vr+/ECCxE5?= =?us-ascii?Q?Des506wVCPgC2KIKCGIrmbqHCp8KG2oR8DtuO/vCNxxk21cz0KkZ0wNgfFPj?= =?us-ascii?Q?7Z8Zul0AowVq/SQHyrUvZ5NiIFVVX2gUSm+CnJANVuMStfbRWwsF07H6P9dF?= =?us-ascii?Q?VSBjWZMgsh4GifrhJ6ENOnTY6IB0NTZe8iLCBsffOvuIn5/1bKlbSTkZb+cg?= =?us-ascii?Q?F1bJI9HdYPGOydNcxhjFMY2wrP/Yfnj5Z0n25t3+JcYzEcxNcHlu8rilocUv?= =?us-ascii?Q?kDkGb4tirPAb8Fc3vZTUmPDHjDBs79ZK+dBh/LorIsUuX7w57OagMxBpHrSr?= =?us-ascii?Q?wOnqbxZVJt8BHTsBpVnX0iZHtaTI/r3t4Jj7BXEDDPPN+7e08VQJcSlQHeGd?= =?us-ascii?Q?QyTWNwpBsz88TwD7RVyGNQLvQBn0LciNDwRxCuxT9lYqFf7bumDMRUkn33mg?= =?us-ascii?Q?cp2pz0zYbGNBheKBhjYvNEfEnpbIcUgLo+Qe40w81kgRlQf5Z3H3IrUjRdxY?= =?us-ascii?Q?CVMUEI8Fp1XjLXGWbNPVvVUAVnDEejjVV9Nl3yLLZzE0bNSq4b+sJmMD5yuC?= =?us-ascii?Q?BLSNKVKdqUX054g930FY1/Rocpmk8fQfSFLc5buNuZkdZbUKm9tE4Avx809K?= =?us-ascii?Q?I2vHtdNhJ2N7N/FCb4A2wUe/4m0084zu5pXVw9QL2zL4lTGaFIhDzAz56lw5?= =?us-ascii?Q?7+91c4CdVakKcXSzeotkK/T01sQOTN9gMsmMqrM/ZO+f/AlCU5cGPX8mPKF3?= =?us-ascii?Q?cVfaeKnnybgp/LK4/HpyjIlSK6mT0XAwEqHi7bnMKpBV5MOGADqlzRjOSw0z?= =?us-ascii?Q?1Bhl37kJomwBo9CpER5Y+RtBn80CI2MuU80Lnsun/X07LfTItgjRFbnhoMgK?= =?us-ascii?Q?AQNYJWnW0wq/gXKuAB6yczMz3iUbZ5cSg9rgnXO9PGlebQRTi8dCDRbZusvc?= =?us-ascii?Q?VZbBUOAXXGT6Livg+6LE+m4vgItU1jjXIcVKYNRRYL5ZwL9p6U0npt7toPpC?= =?us-ascii?Q?LnqNnRXzbFDccs8bgyfEDoSJV2fycIU6ncg9UMmTC+ctJvjb1slIGCRnYThY?= =?us-ascii?Q?kr68Lzgu1531Gctr8/my+IgnrYSofSVobf5hqY5K4xKq+I9y/PkOpTBGT1jX?= =?us-ascii?Q?zsJ6r6RkXBs7KynayEMb3a6FEesgkhfWqcyZCVEB93TwfcUqOeMKWucA3iSV?= =?us-ascii?Q?KLqXdRfixeSs/aF4lBZ+NTQ7areq4ArE0KrOPn0fPCA?= X-Microsoft-Antispam-Message-Info: j/2tLiNcQ2+s6QeJRDUXRCWq4I3NMp6o8R7+vMyovQWxt3lJbop1lT1Z7J9PObHwOEYUoMY+6yul0t/eeyMMO1v7TjUbnsuuPClZIRuA1cmdt3pDYkLximnhPTT7a4H16KMZN8gM9yIb9kcpIH36WVbvJ1KweYAx42o/79kS6xiES0ztpmKw67aGFJUIeH1u X-Microsoft-Exchange-Diagnostics: 1;DB3PR04MB0747;6:3GEzQuqEPlSRkjrXVAnRZ8tQDLNPprinSCFW65L1bsNCr75DUe5g95a6d690yRmOyCdZExoOjCiSYwamuYtAk2JGlH8rF5Q5epOyYO7YDvOC3rqJiXA7ffDuJfESzYfz+Hqer4sMx28rvgUA0xUmAXlBil3SsaaPe8R/W85yC35jdKPSW4XfMbNx872M7wGPFJj6DqqQkV1dDoDZ2TIHBgz+U7brhCc5whVOx5TibVJxjJj2Bxzno+gsmyrV28nLzjs8jlSQDVCKcbCqk46Zz+/p2C0Q3JkxY+HDdL6iP4JcGM+hn/4Fu/vEBW0SQRJNWcdSzJ7afmaYB8wXtYNjdpaxSjNhRRIwzmX5GKAEGsY=;5:sIxHaiMfp4fT2LwKtGlaDLH2x/zlEB1xPUBCdW2OiZtWKRz1jOe3qiQU9PJpsPr1M+g61BcZ8UyeC16VwLX73pq4CqkY+3AxYWRLaOCLYS81UyK5G1ymcw/vsfozlQGrvxaRG7GZu0onbrMrhpKV+tft+QIv/cnfLsMslr/srrc=;24:aPVnjuh8y6vjT2B251uhanmFEb2Yr0tlHQshm6WgSv2AZLWs+ft9Q4C1/tuXifBLgWM2ONdEYeeXTHQP93DkMxLCJJzzkSewAkf2+GjeLo4=;7:ukf6kJUEIjuBAL3cBrls7an3OR/+RQ9r40UqYgFMTJnb3g/qkNfDxuG+k8UUFTgVaSgFRACM3m2YSV99Kw3jQoAjkaZhrOXZOfqTaA2KdZH7Yh3d6kyH3LK8vYascg+P2j7aZ4pBLV/JixXhPwymN9vpEQChaWek+RrtSeGhGfjG/CE8dfiZvGsH5iL08zrKrXB4ZfmlgRkUveZYNLXLr+3lntc+sTz0GRE63DvE6fx8wh+UxPvCGtTyvYAL2LeS SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Mar 2018 13:52:12.1794 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 52627985-3767-47b4-3f58-08d588e9a09a X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR04MB0747 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce the DPAA2 Ethernet Switch driver, which manages Datapath Switch (DPSW) objects discovered on the MC bus. Suggested-by: Alexandru Marginean Signed-off-by: Razvan Stefanescu --- Changelog: v2: - fix PVID cleanup in ethsw_port_add_vlan() - rename err2 to ret in ethsw_port_add/del_vlan() - avoid duplicate code in ethsw_probe() - move destroy_workqueue to ethsw_takedown() - have a function for unregistering notifiers - above changes implement review comments for v1 from Bogdan P. v3: - no changes v4: - adjust to moving MC-bus out of staging - support adding/deleting multicast entries to/from FDB - selectively discard benign MC errors for calling add/delete fdb entries multiple times to avoid spamming console with stack traces - refactor setting TCI to avoid code duplication - clean probe code error path v5: - replace ethsw_irq0_handler() with NULL - do not allow adding ports of the same switch to multiple bridge devices drivers/staging/fsl-dpaa2/ethsw/Makefile | 2 +- drivers/staging/fsl-dpaa2/ethsw/ethsw.c | 1531 ++++++++++++++++++++++++++++++ drivers/staging/fsl-dpaa2/ethsw/ethsw.h | 89 ++ 3 files changed, 1621 insertions(+), 1 deletion(-) create mode 100644 drivers/staging/fsl-dpaa2/ethsw/ethsw.c create mode 100644 drivers/staging/fsl-dpaa2/ethsw/ethsw.h diff --git a/drivers/staging/fsl-dpaa2/ethsw/Makefile b/drivers/staging/fsl-dpaa2/ethsw/Makefile index db137f7..a6d72d1 100644 --- a/drivers/staging/fsl-dpaa2/ethsw/Makefile +++ b/drivers/staging/fsl-dpaa2/ethsw/Makefile @@ -4,4 +4,4 @@ obj-$(CONFIG_FSL_DPAA2_ETHSW) += dpaa2-ethsw.o -dpaa2-ethsw-objs := dpsw.o +dpaa2-ethsw-objs := ethsw.o dpsw.o diff --git a/drivers/staging/fsl-dpaa2/ethsw/ethsw.c b/drivers/staging/fsl-dpaa2/ethsw/ethsw.c new file mode 100644 index 0000000..2127037 --- /dev/null +++ b/drivers/staging/fsl-dpaa2/ethsw/ethsw.c @@ -0,0 +1,1531 @@ +/* Copyright 2014-2016 Freescale Semiconductor Inc. + * Copyright 2017-2018 NXP + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the above-listed copyright holders nor the + * names of any contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * + * ALTERNATIVELY, this software may be distributed under the terms of the + * GNU General Public License ("GPL") as published by the Free Software + * Foundation, either version 2 of that License or (at your option) any + * later version. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#include +#include +#include +#include + +#include + +#include "ethsw.h" + +static struct workqueue_struct *ethsw_owq; + +/* Minimal supported DPSW version */ +#define DPSW_MIN_VER_MAJOR 8 +#define DPSW_MIN_VER_MINOR 0 + +#define DEFAULT_VLAN_ID 1 + +static int ethsw_add_vlan(struct ethsw_core *ethsw, u16 vid) +{ + int err; + + struct dpsw_vlan_cfg vcfg = { + .fdb_id = 0, + }; + + if (ethsw->vlans[vid]) { + dev_err(ethsw->dev, "VLAN already configured\n"); + return -EEXIST; + } + + err = dpsw_vlan_add(ethsw->mc_io, 0, + ethsw->dpsw_handle, vid, &vcfg); + if (err) { + dev_err(ethsw->dev, "dpsw_vlan_add err %d\n", err); + return err; + } + ethsw->vlans[vid] = ETHSW_VLAN_MEMBER; + + return 0; +} + +static int ethsw_port_set_tci(struct ethsw_port_priv *port_priv, + struct dpsw_tci_cfg *tci_cfg) +{ + struct ethsw_core *ethsw = port_priv->ethsw_data; + struct net_device *netdev = port_priv->netdev; + bool is_oper; + int err, ret; + + /* Interface needs to be down to change PVID */ + is_oper = netif_oper_up(netdev); + if (is_oper) { + err = dpsw_if_disable(ethsw->mc_io, 0, + ethsw->dpsw_handle, + port_priv->idx); + if (err) { + netdev_err(netdev, "dpsw_if_disable err %d\n", err); + return err; + } + } + + err = dpsw_if_set_tci(ethsw->mc_io, 0, ethsw->dpsw_handle, + port_priv->idx, tci_cfg); + if (err) { + netdev_err(netdev, "dpsw_if_set_tci err %d\n", err); + goto set_tci_error; + } + + /* Delete previous PVID info and mark the new one */ + if (port_priv->pvid) + port_priv->vlans[port_priv->pvid] &= ~ETHSW_VLAN_PVID; + port_priv->vlans[tci_cfg->vlan_id] |= ETHSW_VLAN_PVID; + port_priv->pvid = tci_cfg->vlan_id; + +set_tci_error: + if (is_oper) { + ret = dpsw_if_enable(ethsw->mc_io, 0, + ethsw->dpsw_handle, + port_priv->idx); + if (ret) { + netdev_err(netdev, "dpsw_if_enable err %d\n", ret); + return ret; + } + } + + return err; +} + +static int ethsw_port_add_vlan(struct ethsw_port_priv *port_priv, + u16 vid, u16 flags) +{ + struct ethsw_core *ethsw = port_priv->ethsw_data; + struct net_device *netdev = port_priv->netdev; + struct dpsw_vlan_if_cfg vcfg; + int err; + + if (port_priv->vlans[vid]) { + netdev_warn(netdev, "VLAN %d already configured\n", vid); + return -EEXIST; + } + + vcfg.num_ifs = 1; + vcfg.if_id[0] = port_priv->idx; + err = dpsw_vlan_add_if(ethsw->mc_io, 0, ethsw->dpsw_handle, vid, &vcfg); + if (err) { + netdev_err(netdev, "dpsw_vlan_add_if err %d\n", err); + return err; + } + + port_priv->vlans[vid] = ETHSW_VLAN_MEMBER; + + if (flags & BRIDGE_VLAN_INFO_UNTAGGED) { + err = dpsw_vlan_add_if_untagged(ethsw->mc_io, 0, + ethsw->dpsw_handle, + vid, &vcfg); + if (err) { + netdev_err(netdev, + "dpsw_vlan_add_if_untagged err %d\n", err); + return err; + } + port_priv->vlans[vid] |= ETHSW_VLAN_UNTAGGED; + } + + if (flags & BRIDGE_VLAN_INFO_PVID) { + struct dpsw_tci_cfg tci_cfg = { + .pcp = 0, + .dei = 0, + .vlan_id = vid, + }; + + err = ethsw_port_set_tci(port_priv, &tci_cfg); + if (err) + return err; + } + + return 0; +} + +static int ethsw_set_learning(struct ethsw_core *ethsw, u8 flag) +{ + enum dpsw_fdb_learning_mode learn_mode; + int err; + + if (flag) + learn_mode = DPSW_FDB_LEARNING_MODE_HW; + else + learn_mode = DPSW_FDB_LEARNING_MODE_DIS; + + err = dpsw_fdb_set_learning_mode(ethsw->mc_io, 0, ethsw->dpsw_handle, 0, + learn_mode); + if (err) { + dev_err(ethsw->dev, "dpsw_fdb_set_learning_mode err %d\n", err); + return err; + } + ethsw->learning = !!flag; + + return 0; +} + +static int ethsw_port_set_flood(struct ethsw_port_priv *port_priv, u8 flag) +{ + int err; + + err = dpsw_if_set_flooding(port_priv->ethsw_data->mc_io, 0, + port_priv->ethsw_data->dpsw_handle, + port_priv->idx, flag); + if (err) { + netdev_err(port_priv->netdev, + "dpsw_fdb_set_learning_mode err %d\n", err); + return err; + } + port_priv->flood = !!flag; + + return 0; +} + +static int ethsw_port_set_stp_state(struct ethsw_port_priv *port_priv, u8 state) +{ + struct dpsw_stp_cfg stp_cfg = { + .vlan_id = DEFAULT_VLAN_ID, + .state = state, + }; + int err; + + if (!netif_oper_up(port_priv->netdev) || state == port_priv->stp_state) + return 0; /* Nothing to do */ + + err = dpsw_if_set_stp(port_priv->ethsw_data->mc_io, 0, + port_priv->ethsw_data->dpsw_handle, + port_priv->idx, &stp_cfg); + if (err) { + netdev_err(port_priv->netdev, + "dpsw_if_set_stp err %d\n", err); + return err; + } + + port_priv->stp_state = state; + + return 0; +} + +static int ethsw_dellink_switch(struct ethsw_core *ethsw, u16 vid) +{ + struct ethsw_port_priv *ppriv_local = NULL; + int i, err; + + if (!ethsw->vlans[vid]) + return -ENOENT; + + err = dpsw_vlan_remove(ethsw->mc_io, 0, ethsw->dpsw_handle, vid); + if (err) { + dev_err(ethsw->dev, "dpsw_vlan_remove err %d\n", err); + return err; + } + ethsw->vlans[vid] = 0; + + for (i = 0; i < ethsw->sw_attr.num_ifs; i++) { + ppriv_local = ethsw->ports[i]; + ppriv_local->vlans[vid] = 0; + } + + return 0; +} + +static int ethsw_port_fdb_add_uc(struct ethsw_port_priv *port_priv, + const unsigned char *addr) +{ + struct dpsw_fdb_unicast_cfg entry = {0}; + int err; + + entry.if_egress = port_priv->idx; + entry.type = DPSW_FDB_ENTRY_STATIC; + ether_addr_copy(entry.mac_addr, addr); + + err = dpsw_fdb_add_unicast(port_priv->ethsw_data->mc_io, 0, + port_priv->ethsw_data->dpsw_handle, + 0, &entry); + if (err) + netdev_err(port_priv->netdev, + "dpsw_fdb_add_unicast err %d\n", err); + return err; +} + +static int ethsw_port_fdb_del_uc(struct ethsw_port_priv *port_priv, + const unsigned char *addr) +{ + struct dpsw_fdb_unicast_cfg entry = {0}; + int err; + + entry.if_egress = port_priv->idx; + entry.type = DPSW_FDB_ENTRY_STATIC; + ether_addr_copy(entry.mac_addr, addr); + + err = dpsw_fdb_remove_unicast(port_priv->ethsw_data->mc_io, 0, + port_priv->ethsw_data->dpsw_handle, + 0, &entry); + /* Silently discard error for calling multiple times the del command */ + if (err && err != -ENXIO) + netdev_err(port_priv->netdev, + "dpsw_fdb_remove_unicast err %d\n", err); + return err; +} + +static int ethsw_port_fdb_add_mc(struct ethsw_port_priv *port_priv, + const unsigned char *addr) +{ + struct dpsw_fdb_multicast_cfg entry = {0}; + int err; + + ether_addr_copy(entry.mac_addr, addr); + entry.type = DPSW_FDB_ENTRY_STATIC; + entry.num_ifs = 1; + entry.if_id[0] = port_priv->idx; + + err = dpsw_fdb_add_multicast(port_priv->ethsw_data->mc_io, 0, + port_priv->ethsw_data->dpsw_handle, + 0, &entry); + /* Silently discard error for calling multiple times the add command */ + if (err && err != -ENXIO) + netdev_err(port_priv->netdev, "dpsw_fdb_add_multicast err %d\n", + err); + return err; +} + +static int ethsw_port_fdb_del_mc(struct ethsw_port_priv *port_priv, + const unsigned char *addr) +{ + struct dpsw_fdb_multicast_cfg entry = {0}; + int err; + + ether_addr_copy(entry.mac_addr, addr); + entry.type = DPSW_FDB_ENTRY_STATIC; + entry.num_ifs = 1; + entry.if_id[0] = port_priv->idx; + + err = dpsw_fdb_remove_multicast(port_priv->ethsw_data->mc_io, 0, + port_priv->ethsw_data->dpsw_handle, + 0, &entry); + /* Silently discard error for calling multiple times the del command */ + if (err && err != -ENAVAIL) + netdev_err(port_priv->netdev, + "dpsw_fdb_remove_multicast err %d\n", err); + return err; +} + +static void port_get_stats(struct net_device *netdev, + struct rtnl_link_stats64 *stats) +{ + struct ethsw_port_priv *port_priv = netdev_priv(netdev); + u64 tmp; + int err; + + err = dpsw_if_get_counter(port_priv->ethsw_data->mc_io, 0, + port_priv->ethsw_data->dpsw_handle, + port_priv->idx, + DPSW_CNT_ING_FRAME, &stats->rx_packets); + if (err) + goto error; + + err = dpsw_if_get_counter(port_priv->ethsw_data->mc_io, 0, + port_priv->ethsw_data->dpsw_handle, + port_priv->idx, + DPSW_CNT_EGR_FRAME, &stats->tx_packets); + if (err) + goto error; + + err = dpsw_if_get_counter(port_priv->ethsw_data->mc_io, 0, + port_priv->ethsw_data->dpsw_handle, + port_priv->idx, + DPSW_CNT_ING_BYTE, &stats->rx_bytes); + if (err) + goto error; + + err = dpsw_if_get_counter(port_priv->ethsw_data->mc_io, 0, + port_priv->ethsw_data->dpsw_handle, + port_priv->idx, + DPSW_CNT_EGR_BYTE, &stats->tx_bytes); + if (err) + goto error; + + err = dpsw_if_get_counter(port_priv->ethsw_data->mc_io, 0, + port_priv->ethsw_data->dpsw_handle, + port_priv->idx, + DPSW_CNT_ING_FRAME_DISCARD, + &stats->rx_dropped); + if (err) + goto error; + + err = dpsw_if_get_counter(port_priv->ethsw_data->mc_io, 0, + port_priv->ethsw_data->dpsw_handle, + port_priv->idx, + DPSW_CNT_ING_FLTR_FRAME, + &tmp); + if (err) + goto error; + stats->rx_dropped += tmp; + + err = dpsw_if_get_counter(port_priv->ethsw_data->mc_io, 0, + port_priv->ethsw_data->dpsw_handle, + port_priv->idx, + DPSW_CNT_EGR_FRAME_DISCARD, + &stats->tx_dropped); + if (err) + goto error; + + return; + +error: + netdev_err(netdev, "dpsw_if_get_counter err %d\n", err); +} + +static bool port_has_offload_stats(const struct net_device *netdev, + int attr_id) +{ + return (attr_id == IFLA_OFFLOAD_XSTATS_CPU_HIT); +} + +static int port_get_offload_stats(int attr_id, + const struct net_device *netdev, + void *sp) +{ + switch (attr_id) { + case IFLA_OFFLOAD_XSTATS_CPU_HIT: + port_get_stats((struct net_device *)netdev, sp); + return 0; + } + + return -EINVAL; +} + +static int port_change_mtu(struct net_device *netdev, int mtu) +{ + struct ethsw_port_priv *port_priv = netdev_priv(netdev); + int err; + + err = dpsw_if_set_max_frame_length(port_priv->ethsw_data->mc_io, + 0, + port_priv->ethsw_data->dpsw_handle, + port_priv->idx, + (u16)ETHSW_L2_MAX_FRM(mtu)); + if (err) { + netdev_err(netdev, + "dpsw_if_set_max_frame_length() err %d\n", err); + return err; + } + + netdev->mtu = mtu; + return 0; +} + +static int port_carrier_state_sync(struct net_device *netdev) +{ + struct ethsw_port_priv *port_priv = netdev_priv(netdev); + struct dpsw_link_state state; + int err; + + err = dpsw_if_get_link_state(port_priv->ethsw_data->mc_io, 0, + port_priv->ethsw_data->dpsw_handle, + port_priv->idx, &state); + if (err) { + netdev_err(netdev, "dpsw_if_get_link_state() err %d\n", err); + return err; + } + + WARN_ONCE(state.up > 1, "Garbage read into link_state"); + + if (state.up != port_priv->link_state) { + if (state.up) + netif_carrier_on(netdev); + else + netif_carrier_off(netdev); + port_priv->link_state = state.up; + } + return 0; +} + +static int port_open(struct net_device *netdev) +{ + struct ethsw_port_priv *port_priv = netdev_priv(netdev); + int err; + + /* No need to allow Tx as control interface is disabled */ + netif_tx_stop_all_queues(netdev); + + err = dpsw_if_enable(port_priv->ethsw_data->mc_io, 0, + port_priv->ethsw_data->dpsw_handle, + port_priv->idx); + if (err) { + netdev_err(netdev, "dpsw_if_enable err %d\n", err); + return err; + } + + /* sync carrier state */ + err = port_carrier_state_sync(netdev); + if (err) { + netdev_err(netdev, + "port_carrier_state_sync err %d\n", err); + goto err_carrier_sync; + } + + return 0; + +err_carrier_sync: + dpsw_if_disable(port_priv->ethsw_data->mc_io, 0, + port_priv->ethsw_data->dpsw_handle, + port_priv->idx); + return err; +} + +static int port_stop(struct net_device *netdev) +{ + struct ethsw_port_priv *port_priv = netdev_priv(netdev); + int err; + + err = dpsw_if_disable(port_priv->ethsw_data->mc_io, 0, + port_priv->ethsw_data->dpsw_handle, + port_priv->idx); + if (err) { + netdev_err(netdev, "dpsw_if_disable err %d\n", err); + return err; + } + + return 0; +} + +static netdev_tx_t port_dropframe(struct sk_buff *skb, + struct net_device *netdev) +{ + /* we don't support I/O for now, drop the frame */ + dev_kfree_skb_any(skb); + + return NETDEV_TX_OK; +} + +static const struct net_device_ops ethsw_port_ops = { + .ndo_open = port_open, + .ndo_stop = port_stop, + + .ndo_set_mac_address = eth_mac_addr, + .ndo_change_mtu = port_change_mtu, + .ndo_has_offload_stats = port_has_offload_stats, + .ndo_get_offload_stats = port_get_offload_stats, + + .ndo_start_xmit = port_dropframe, +}; + +static void ethsw_links_state_update(struct ethsw_core *ethsw) +{ + int i; + + for (i = 0; i < ethsw->sw_attr.num_ifs; i++) + port_carrier_state_sync(ethsw->ports[i]->netdev); +} + +static irqreturn_t ethsw_irq0_handler_thread(int irq_num, void *arg) +{ + struct device *dev = (struct device *)arg; + struct ethsw_core *ethsw = dev_get_drvdata(dev); + + /* Mask the events and the if_id reserved bits to be cleared on read */ + u32 status = DPSW_IRQ_EVENT_LINK_CHANGED | 0xFFFF0000; + int err; + + err = dpsw_get_irq_status(ethsw->mc_io, 0, ethsw->dpsw_handle, + DPSW_IRQ_INDEX_IF, &status); + if (err) { + dev_err(dev, "Can't get irq status (err %d)", err); + + err = dpsw_clear_irq_status(ethsw->mc_io, 0, ethsw->dpsw_handle, + DPSW_IRQ_INDEX_IF, 0xFFFFFFFF); + if (err) + dev_err(dev, "Can't clear irq status (err %d)", err); + goto out; + } + + if (status & DPSW_IRQ_EVENT_LINK_CHANGED) + ethsw_links_state_update(ethsw); + +out: + return IRQ_HANDLED; +} + +static int ethsw_setup_irqs(struct fsl_mc_device *sw_dev) +{ + struct device *dev = &sw_dev->dev; + struct ethsw_core *ethsw = dev_get_drvdata(dev); + u32 mask = DPSW_IRQ_EVENT_LINK_CHANGED; + struct fsl_mc_device_irq *irq; + int err; + + err = fsl_mc_allocate_irqs(sw_dev); + if (err) { + dev_err(dev, "MC irqs allocation failed\n"); + return err; + } + + if (WARN_ON(sw_dev->obj_desc.irq_count != DPSW_IRQ_NUM)) { + err = -EINVAL; + goto free_irq; + } + + err = dpsw_set_irq_enable(ethsw->mc_io, 0, ethsw->dpsw_handle, + DPSW_IRQ_INDEX_IF, 0); + if (err) { + dev_err(dev, "dpsw_set_irq_enable err %d\n", err); + goto free_irq; + } + + irq = sw_dev->irqs[DPSW_IRQ_INDEX_IF]; + + err = devm_request_threaded_irq(dev, irq->msi_desc->irq, + NULL, + ethsw_irq0_handler_thread, + IRQF_NO_SUSPEND | IRQF_ONESHOT, + dev_name(dev), dev); + if (err) { + dev_err(dev, "devm_request_threaded_irq(): %d", err); + goto free_irq; + } + + err = dpsw_set_irq_mask(ethsw->mc_io, 0, ethsw->dpsw_handle, + DPSW_IRQ_INDEX_IF, mask); + if (err) { + dev_err(dev, "dpsw_set_irq_mask(): %d", err); + goto free_devm_irq; + } + + err = dpsw_set_irq_enable(ethsw->mc_io, 0, ethsw->dpsw_handle, + DPSW_IRQ_INDEX_IF, 1); + if (err) { + dev_err(dev, "dpsw_set_irq_enable(): %d", err); + goto free_devm_irq; + } + + return 0; + +free_devm_irq: + devm_free_irq(dev, irq->msi_desc->irq, dev); +free_irq: + fsl_mc_free_irqs(sw_dev); + return err; +} + +static void ethsw_teardown_irqs(struct fsl_mc_device *sw_dev) +{ + struct device *dev = &sw_dev->dev; + struct ethsw_core *ethsw = dev_get_drvdata(dev); + struct fsl_mc_device_irq *irq; + int err; + + irq = sw_dev->irqs[DPSW_IRQ_INDEX_IF]; + err = dpsw_set_irq_enable(ethsw->mc_io, 0, ethsw->dpsw_handle, + DPSW_IRQ_INDEX_IF, 0); + if (err) + dev_err(dev, "dpsw_set_irq_enable err %d\n", err); + + fsl_mc_free_irqs(sw_dev); +} + +static int swdev_port_attr_get(struct net_device *netdev, + struct switchdev_attr *attr) +{ + struct ethsw_port_priv *port_priv = netdev_priv(netdev); + + switch (attr->id) { + case SWITCHDEV_ATTR_ID_PORT_PARENT_ID: + attr->u.ppid.id_len = 1; + attr->u.ppid.id[0] = port_priv->ethsw_data->dev_id; + break; + case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS: + attr->u.brport_flags = + (port_priv->ethsw_data->learning ? BR_LEARNING : 0) | + (port_priv->flood ? BR_FLOOD : 0); + break; + case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS_SUPPORT: + attr->u.brport_flags_support = BR_LEARNING | BR_FLOOD; + break; + default: + return -EOPNOTSUPP; + } + + return 0; +} + +static int port_attr_stp_state_set(struct net_device *netdev, + struct switchdev_trans *trans, + u8 state) +{ + struct ethsw_port_priv *port_priv = netdev_priv(netdev); + + if (switchdev_trans_ph_prepare(trans)) + return 0; + + return ethsw_port_set_stp_state(port_priv, state); +} + +static int port_attr_br_flags_set(struct net_device *netdev, + struct switchdev_trans *trans, + unsigned long flags) +{ + struct ethsw_port_priv *port_priv = netdev_priv(netdev); + int err = 0; + + if (switchdev_trans_ph_prepare(trans)) + return 0; + + /* Learning is enabled per switch */ + err = ethsw_set_learning(port_priv->ethsw_data, flags & BR_LEARNING); + if (err) + goto exit; + + err = ethsw_port_set_flood(port_priv, flags & BR_FLOOD); + +exit: + return err; +} + +static int swdev_port_attr_set(struct net_device *netdev, + const struct switchdev_attr *attr, + struct switchdev_trans *trans) +{ + int err = 0; + + switch (attr->id) { + case SWITCHDEV_ATTR_ID_PORT_STP_STATE: + err = port_attr_stp_state_set(netdev, trans, + attr->u.stp_state); + break; + case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS: + err = port_attr_br_flags_set(netdev, trans, + attr->u.brport_flags); + break; + case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING: + /* VLANs are supported by default */ + break; + default: + err = -EOPNOTSUPP; + break; + } + + return err; +} + +static int port_vlans_add(struct net_device *netdev, + const struct switchdev_obj_port_vlan *vlan, + struct switchdev_trans *trans) +{ + struct ethsw_port_priv *port_priv = netdev_priv(netdev); + int vid, err; + + if (switchdev_trans_ph_prepare(trans)) + return 0; + + for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) { + if (!port_priv->ethsw_data->vlans[vid]) { + /* this is a new VLAN */ + err = ethsw_add_vlan(port_priv->ethsw_data, vid); + if (err) + return err; + + port_priv->ethsw_data->vlans[vid] |= ETHSW_VLAN_GLOBAL; + } + err = ethsw_port_add_vlan(port_priv, vid, vlan->flags); + if (err) + break; + } + + return err; +} + +static int port_lookup_address(struct net_device *netdev, int is_uc, + const unsigned char *addr) +{ + struct netdev_hw_addr_list *list = (is_uc) ? &netdev->uc : &netdev->mc; + struct netdev_hw_addr *ha; + + netif_addr_lock_bh(netdev); + list_for_each_entry(ha, &list->list, list) { + if (ether_addr_equal(ha->addr, addr)) { + netif_addr_unlock_bh(netdev); + return 1; + } + } + netif_addr_unlock_bh(netdev); + return 0; +} + +static int port_mdb_add(struct net_device *netdev, + const struct switchdev_obj_port_mdb *mdb, + struct switchdev_trans *trans) +{ + struct ethsw_port_priv *port_priv = netdev_priv(netdev); + int err; + + if (switchdev_trans_ph_prepare(trans)) + return 0; + + /* Check if address is already set on this port */ + if (port_lookup_address(netdev, 0, mdb->addr)) + return -EEXIST; + + err = ethsw_port_fdb_add_mc(port_priv, mdb->addr); + if (err) + return err; + + err = dev_mc_add(netdev, mdb->addr); + if (err) { + netdev_err(netdev, "dev_mc_add err %d\n", err); + ethsw_port_fdb_del_mc(port_priv, mdb->addr); + } + + return err; +} + +static int swdev_port_obj_add(struct net_device *netdev, + const struct switchdev_obj *obj, + struct switchdev_trans *trans) +{ + int err; + + switch (obj->id) { + case SWITCHDEV_OBJ_ID_PORT_VLAN: + err = port_vlans_add(netdev, + SWITCHDEV_OBJ_PORT_VLAN(obj), + trans); + break; + case SWITCHDEV_OBJ_ID_PORT_MDB: + err = port_mdb_add(netdev, + SWITCHDEV_OBJ_PORT_MDB(obj), + trans); + break; + default: + err = -EOPNOTSUPP; + break; + } + + return err; +} + +static int ethsw_port_del_vlan(struct ethsw_port_priv *port_priv, u16 vid) +{ + struct ethsw_core *ethsw = port_priv->ethsw_data; + struct net_device *netdev = port_priv->netdev; + struct dpsw_vlan_if_cfg vcfg; + int i, err; + + if (!port_priv->vlans[vid]) + return -ENOENT; + + if (port_priv->vlans[vid] & ETHSW_VLAN_PVID) { + struct dpsw_tci_cfg tci_cfg = { 0 }; + + err = ethsw_port_set_tci(port_priv, &tci_cfg); + if (err) + return err; + } + + vcfg.num_ifs = 1; + vcfg.if_id[0] = port_priv->idx; + if (port_priv->vlans[vid] & ETHSW_VLAN_UNTAGGED) { + err = dpsw_vlan_remove_if_untagged(ethsw->mc_io, 0, + ethsw->dpsw_handle, + vid, &vcfg); + if (err) { + netdev_err(netdev, + "dpsw_vlan_remove_if_untagged err %d\n", + err); + } + port_priv->vlans[vid] &= ~ETHSW_VLAN_UNTAGGED; + } + + if (port_priv->vlans[vid] & ETHSW_VLAN_MEMBER) { + err = dpsw_vlan_remove_if(ethsw->mc_io, 0, ethsw->dpsw_handle, + vid, &vcfg); + if (err) { + netdev_err(netdev, + "dpsw_vlan_remove_if err %d\n", err); + return err; + } + port_priv->vlans[vid] &= ~ETHSW_VLAN_MEMBER; + + /* Delete VLAN from switch if it is no longer configured on + * any port + */ + for (i = 0; i < ethsw->sw_attr.num_ifs; i++) + if (ethsw->ports[i]->vlans[vid] & ETHSW_VLAN_MEMBER) + return 0; /* Found a port member in VID */ + + ethsw->vlans[vid] &= ~ETHSW_VLAN_GLOBAL; + + err = ethsw_dellink_switch(ethsw, vid); + if (err) + return err; + } + + return 0; +} + +static int port_vlans_del(struct net_device *netdev, + const struct switchdev_obj_port_vlan *vlan) +{ + struct ethsw_port_priv *port_priv = netdev_priv(netdev); + int vid, err; + + for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) { + err = ethsw_port_del_vlan(port_priv, vid); + if (err) + break; + } + + return err; +} + +static int port_mdb_del(struct net_device *netdev, + const struct switchdev_obj_port_mdb *mdb) +{ + struct ethsw_port_priv *port_priv = netdev_priv(netdev); + int err; + + if (!port_lookup_address(netdev, 0, mdb->addr)) + return -ENOENT; + + err = ethsw_port_fdb_del_mc(port_priv, mdb->addr); + if (err) + return err; + + err = dev_mc_del(netdev, mdb->addr); + if (err) { + netdev_err(netdev, "dev_mc_del err %d\n", err); + return err; + } + + return err; +} + +static int swdev_port_obj_del(struct net_device *netdev, + const struct switchdev_obj *obj) +{ + int err; + + switch (obj->id) { + case SWITCHDEV_OBJ_ID_PORT_VLAN: + err = port_vlans_del(netdev, SWITCHDEV_OBJ_PORT_VLAN(obj)); + break; + case SWITCHDEV_OBJ_ID_PORT_MDB: + err = port_mdb_del(netdev, SWITCHDEV_OBJ_PORT_MDB(obj)); + break; + default: + err = -EOPNOTSUPP; + break; + } + return err; +} + +static const struct switchdev_ops ethsw_port_switchdev_ops = { + .switchdev_port_attr_get = swdev_port_attr_get, + .switchdev_port_attr_set = swdev_port_attr_set, + .switchdev_port_obj_add = swdev_port_obj_add, + .switchdev_port_obj_del = swdev_port_obj_del, +}; + +/* For the moment, only flood setting needs to be updated */ +static int port_bridge_join(struct net_device *netdev, + struct net_device *upper_dev) +{ + struct ethsw_port_priv *port_priv = netdev_priv(netdev); + struct ethsw_core *ethsw = port_priv->ethsw_data; + int i, err; + + for (i = 0; i < ethsw->sw_attr.num_ifs; i++) + if (ethsw->ports[i]->bridge_dev && + (ethsw->ports[i]->bridge_dev != upper_dev)) { + netdev_err(netdev, + "Another switch port is connected to %s\n", + ethsw->ports[i]->bridge_dev->name); + return -EINVAL; + } + + /* Enable flooding */ + err = ethsw_port_set_flood(port_priv, 1); + if (!err) + port_priv->bridge_dev = upper_dev; + + return err; +} + +static int port_bridge_leave(struct net_device *netdev) +{ + struct ethsw_port_priv *port_priv = netdev_priv(netdev); + int err; + + /* Disable flooding */ + err = ethsw_port_set_flood(port_priv, 0); + if (!err) + port_priv->bridge_dev = NULL; + + return err; +} + +static int port_netdevice_event(struct notifier_block *unused, + unsigned long event, void *ptr) +{ + struct net_device *netdev = netdev_notifier_info_to_dev(ptr); + struct netdev_notifier_changeupper_info *info = ptr; + struct net_device *upper_dev; + int err = 0; + + if (netdev->netdev_ops != ðsw_port_ops) + return NOTIFY_DONE; + + /* Handle just upper dev link/unlink for the moment */ + if (event == NETDEV_CHANGEUPPER) { + upper_dev = info->upper_dev; + if (netif_is_bridge_master(upper_dev)) { + if (info->linking) + err = port_bridge_join(netdev, upper_dev); + else + err = port_bridge_leave(netdev); + } + } + + return notifier_from_errno(err); +} + +static struct notifier_block port_nb __read_mostly = { + .notifier_call = port_netdevice_event, +}; + +struct ethsw_switchdev_event_work { + struct work_struct work; + struct switchdev_notifier_fdb_info fdb_info; + struct net_device *dev; + unsigned long event; +}; + +static void ethsw_switchdev_event_work(struct work_struct *work) +{ + struct ethsw_switchdev_event_work *switchdev_work = + container_of(work, struct ethsw_switchdev_event_work, work); + struct net_device *dev = switchdev_work->dev; + struct switchdev_notifier_fdb_info *fdb_info; + struct ethsw_port_priv *port_priv; + + rtnl_lock(); + port_priv = netdev_priv(dev); + fdb_info = &switchdev_work->fdb_info; + + switch (switchdev_work->event) { + case SWITCHDEV_FDB_ADD_TO_DEVICE: + if (is_unicast_ether_addr(fdb_info->addr)) + ethsw_port_fdb_add_uc(netdev_priv(dev), fdb_info->addr); + else + ethsw_port_fdb_add_mc(netdev_priv(dev), fdb_info->addr); + break; + case SWITCHDEV_FDB_DEL_TO_DEVICE: + if (is_unicast_ether_addr(fdb_info->addr)) + ethsw_port_fdb_del_uc(netdev_priv(dev), fdb_info->addr); + else + ethsw_port_fdb_del_mc(netdev_priv(dev), fdb_info->addr); + break; + } + + rtnl_unlock(); + kfree(switchdev_work->fdb_info.addr); + kfree(switchdev_work); + dev_put(dev); +} + +/* Called under rcu_read_lock() */ +static int port_switchdev_event(struct notifier_block *unused, + unsigned long event, void *ptr) +{ + struct net_device *dev = switchdev_notifier_info_to_dev(ptr); + struct ethsw_switchdev_event_work *switchdev_work; + struct switchdev_notifier_fdb_info *fdb_info = ptr; + + switchdev_work = kzalloc(sizeof(*switchdev_work), GFP_ATOMIC); + if (!switchdev_work) + return NOTIFY_BAD; + + INIT_WORK(&switchdev_work->work, ethsw_switchdev_event_work); + switchdev_work->dev = dev; + switchdev_work->event = event; + + switch (event) { + case SWITCHDEV_FDB_ADD_TO_DEVICE: + case SWITCHDEV_FDB_DEL_TO_DEVICE: + memcpy(&switchdev_work->fdb_info, ptr, + sizeof(switchdev_work->fdb_info)); + switchdev_work->fdb_info.addr = kzalloc(ETH_ALEN, GFP_ATOMIC); + if (!switchdev_work->fdb_info.addr) + goto err_addr_alloc; + + ether_addr_copy((u8 *)switchdev_work->fdb_info.addr, + fdb_info->addr); + + /* Take a reference on the device to avoid being freed. */ + dev_hold(dev); + break; + default: + return NOTIFY_DONE; + } + + queue_work(ethsw_owq, &switchdev_work->work); + + return NOTIFY_DONE; + +err_addr_alloc: + kfree(switchdev_work); + return NOTIFY_BAD; +} + +static struct notifier_block port_switchdev_nb = { + .notifier_call = port_switchdev_event, +}; + +static int ethsw_register_notifier(struct device *dev) +{ + int err; + + err = register_netdevice_notifier(&port_nb); + if (err) { + dev_err(dev, "Failed to register netdev notifier\n"); + return err; + } + + err = register_switchdev_notifier(&port_switchdev_nb); + if (err) { + dev_err(dev, "Failed to register switchdev notifier\n"); + goto err_switchdev_nb; + } + + return 0; + +err_switchdev_nb: + unregister_netdevice_notifier(&port_nb); + return err; +} + +static int ethsw_open(struct ethsw_core *ethsw) +{ + struct ethsw_port_priv *port_priv = NULL; + int i, err; + + err = dpsw_enable(ethsw->mc_io, 0, ethsw->dpsw_handle); + if (err) { + dev_err(ethsw->dev, "dpsw_enable err %d\n", err); + return err; + } + + for (i = 0; i < ethsw->sw_attr.num_ifs; i++) { + port_priv = ethsw->ports[i]; + err = dev_open(port_priv->netdev); + if (err) { + netdev_err(port_priv->netdev, "dev_open err %d\n", err); + return err; + } + } + + return 0; +} + +static int ethsw_stop(struct ethsw_core *ethsw) +{ + struct ethsw_port_priv *port_priv = NULL; + int i, err; + + for (i = 0; i < ethsw->sw_attr.num_ifs; i++) { + port_priv = ethsw->ports[i]; + dev_close(port_priv->netdev); + } + + err = dpsw_disable(ethsw->mc_io, 0, ethsw->dpsw_handle); + if (err) { + dev_err(ethsw->dev, "dpsw_disable err %d\n", err); + return err; + } + + return 0; +} + +static int ethsw_init(struct fsl_mc_device *sw_dev) +{ + struct device *dev = &sw_dev->dev; + struct ethsw_core *ethsw = dev_get_drvdata(dev); + u16 version_major, version_minor, i; + struct dpsw_stp_cfg stp_cfg; + int err; + + ethsw->dev_id = sw_dev->obj_desc.id; + + err = dpsw_open(ethsw->mc_io, 0, ethsw->dev_id, ðsw->dpsw_handle); + if (err) { + dev_err(dev, "dpsw_open err %d\n", err); + return err; + } + + err = dpsw_get_attributes(ethsw->mc_io, 0, ethsw->dpsw_handle, + ðsw->sw_attr); + if (err) { + dev_err(dev, "dpsw_get_attributes err %d\n", err); + goto err_close; + } + + err = dpsw_get_api_version(ethsw->mc_io, 0, + &version_major, + &version_minor); + if (err) { + dev_err(dev, "dpsw_get_api_version err %d\n", err); + goto err_close; + } + + /* Minimum supported DPSW version check */ + if (version_major < DPSW_MIN_VER_MAJOR || + (version_major == DPSW_MIN_VER_MAJOR && + version_minor < DPSW_MIN_VER_MINOR)) { + dev_err(dev, "DPSW version %d:%d not supported. Use %d.%d or greater.\n", + version_major, + version_minor, + DPSW_MIN_VER_MAJOR, DPSW_MIN_VER_MINOR); + err = -ENOTSUPP; + goto err_close; + } + + err = dpsw_reset(ethsw->mc_io, 0, ethsw->dpsw_handle); + if (err) { + dev_err(dev, "dpsw_reset err %d\n", err); + goto err_close; + } + + err = dpsw_fdb_set_learning_mode(ethsw->mc_io, 0, ethsw->dpsw_handle, 0, + DPSW_FDB_LEARNING_MODE_HW); + if (err) { + dev_err(dev, "dpsw_fdb_set_learning_mode err %d\n", err); + goto err_close; + } + + stp_cfg.vlan_id = DEFAULT_VLAN_ID; + stp_cfg.state = DPSW_STP_STATE_FORWARDING; + + for (i = 0; i < ethsw->sw_attr.num_ifs; i++) { + err = dpsw_if_set_stp(ethsw->mc_io, 0, ethsw->dpsw_handle, i, + &stp_cfg); + if (err) { + dev_err(dev, "dpsw_if_set_stp err %d for port %d\n", + err, i); + goto err_close; + } + + err = dpsw_if_set_broadcast(ethsw->mc_io, 0, + ethsw->dpsw_handle, i, 1); + if (err) { + dev_err(dev, + "dpsw_if_set_broadcast err %d for port %d\n", + err, i); + goto err_close; + } + } + + ethsw_owq = alloc_ordered_workqueue("%s_ordered", WQ_MEM_RECLAIM, + "ethsw"); + if (!ethsw_owq) { + err = -ENOMEM; + goto err_close; + } + + err = ethsw_register_notifier(dev); + if (err) + goto err_destroy_ordered_workqueue; + + return 0; + +err_destroy_ordered_workqueue: + destroy_workqueue(ethsw_owq); + +err_close: + dpsw_close(ethsw->mc_io, 0, ethsw->dpsw_handle); + return err; +} + +static int ethsw_port_init(struct ethsw_port_priv *port_priv, u16 port) +{ + const char def_mcast[ETH_ALEN] = {0x01, 0x00, 0x5e, 0x00, 0x00, 0x01}; + struct net_device *netdev = port_priv->netdev; + struct ethsw_core *ethsw = port_priv->ethsw_data; + struct dpsw_tci_cfg tci_cfg = {0}; + struct dpsw_vlan_if_cfg vcfg; + int err; + + /* Switch starts with all ports configured to VLAN 1. Need to + * remove this setting to allow configuration at bridge join + */ + vcfg.num_ifs = 1; + vcfg.if_id[0] = port_priv->idx; + + err = dpsw_vlan_remove_if_untagged(ethsw->mc_io, 0, ethsw->dpsw_handle, + DEFAULT_VLAN_ID, &vcfg); + if (err) { + netdev_err(netdev, "dpsw_vlan_remove_if_untagged err %d\n", + err); + return err; + } + + err = ethsw_port_set_tci(port_priv, &tci_cfg); + if (err) + return err; + + err = dpsw_vlan_remove_if(ethsw->mc_io, 0, ethsw->dpsw_handle, + DEFAULT_VLAN_ID, &vcfg); + if (err) { + netdev_err(netdev, "dpsw_vlan_remove_if err %d\n", err); + return err; + } + + err = ethsw_port_fdb_add_mc(port_priv, def_mcast); + + return err; +} + +static void ethsw_unregister_notifier(struct device *dev) +{ + int err; + + err = unregister_switchdev_notifier(&port_switchdev_nb); + if (err) + dev_err(dev, + "Failed to unregister switchdev notifier (%d)\n", err); + + err = unregister_netdevice_notifier(&port_nb); + if (err) + dev_err(dev, + "Failed to unregister netdev notifier (%d)\n", err); +} + +static void ethsw_takedown(struct fsl_mc_device *sw_dev) +{ + struct device *dev = &sw_dev->dev; + struct ethsw_core *ethsw = dev_get_drvdata(dev); + int err; + + ethsw_unregister_notifier(dev); + + err = dpsw_close(ethsw->mc_io, 0, ethsw->dpsw_handle); + if (err) + dev_warn(dev, "dpsw_close err %d\n", err); +} + +static int ethsw_remove(struct fsl_mc_device *sw_dev) +{ + struct ethsw_port_priv *port_priv; + struct ethsw_core *ethsw; + struct device *dev; + int i; + + dev = &sw_dev->dev; + ethsw = dev_get_drvdata(dev); + + ethsw_teardown_irqs(sw_dev); + + destroy_workqueue(ethsw_owq); + + rtnl_lock(); + ethsw_stop(ethsw); + rtnl_unlock(); + + for (i = 0; i < ethsw->sw_attr.num_ifs; i++) { + port_priv = ethsw->ports[i]; + unregister_netdev(port_priv->netdev); + free_netdev(port_priv->netdev); + } + kfree(ethsw->ports); + + ethsw_takedown(sw_dev); + fsl_mc_portal_free(ethsw->mc_io); + + kfree(ethsw); + + dev_set_drvdata(dev, NULL); + + return 0; +} + +static int ethsw_probe_port(struct ethsw_core *ethsw, u16 port_idx) +{ + struct ethsw_port_priv *port_priv; + struct device *dev = ethsw->dev; + struct net_device *port_netdev; + int err; + + port_netdev = alloc_etherdev(sizeof(struct ethsw_port_priv)); + if (!port_netdev) { + dev_err(dev, "alloc_etherdev error\n"); + return -ENOMEM; + } + + port_priv = netdev_priv(port_netdev); + port_priv->netdev = port_netdev; + port_priv->ethsw_data = ethsw; + + port_priv->idx = port_idx; + port_priv->stp_state = BR_STATE_FORWARDING; + + /* Flooding is implicitly enabled */ + port_priv->flood = true; + + SET_NETDEV_DEV(port_netdev, dev); + port_netdev->netdev_ops = ðsw_port_ops; + port_netdev->switchdev_ops = ðsw_port_switchdev_ops; + + /* Set MTU limits */ + port_netdev->min_mtu = ETH_MIN_MTU; + port_netdev->max_mtu = ETHSW_MAX_FRAME_LENGTH; + + err = register_netdev(port_netdev); + if (err < 0) { + dev_err(dev, "register_netdev error %d\n", err); + free_netdev(port_netdev); + return err; + } + + ethsw->ports[port_idx] = port_priv; + + return ethsw_port_init(port_priv, port_idx); +} + +static int ethsw_probe(struct fsl_mc_device *sw_dev) +{ + struct device *dev = &sw_dev->dev; + struct ethsw_core *ethsw; + int i, err; + + /* Allocate switch core*/ + ethsw = kzalloc(sizeof(*ethsw), GFP_KERNEL); + + if (!ethsw) + return -ENOMEM; + + ethsw->dev = dev; + dev_set_drvdata(dev, ethsw); + + err = fsl_mc_portal_allocate(sw_dev, 0, ðsw->mc_io); + if (err) { + if (err == -ENXIO) + err = -EPROBE_DEFER; + else + dev_err(dev, "fsl_mc_portal_allocate err %d\n", err); + goto err_free_drvdata; + } + + err = ethsw_init(sw_dev); + if (err) + goto err_free_cmdport; + + /* DEFAULT_VLAN_ID is implicitly configured on the switch */ + ethsw->vlans[DEFAULT_VLAN_ID] = ETHSW_VLAN_MEMBER; + + /* Learning is implicitly enabled */ + ethsw->learning = true; + + ethsw->ports = kcalloc(ethsw->sw_attr.num_ifs, sizeof(*ethsw->ports), + GFP_KERNEL); + if (!(ethsw->ports)) { + err = -ENOMEM; + goto err_takedown; + } + + for (i = 0; i < ethsw->sw_attr.num_ifs; i++) { + err = ethsw_probe_port(ethsw, i); + if (err) + goto err_free_ports; + } + + /* Switch starts up enabled */ + rtnl_lock(); + err = ethsw_open(ethsw); + rtnl_unlock(); + if (err) + goto err_free_ports; + + /* Setup IRQs */ + err = ethsw_setup_irqs(sw_dev); + if (err) + goto err_stop; + + dev_info(dev, "probed %d port switch\n", ethsw->sw_attr.num_ifs); + return 0; + +err_stop: + rtnl_lock(); + ethsw_stop(ethsw); + rtnl_unlock(); + +err_free_ports: + /* Cleanup registered ports only */ + for (i--; i >= 0; i--) { + unregister_netdev(ethsw->ports[i]->netdev); + free_netdev(ethsw->ports[i]->netdev); + } + kfree(ethsw->ports); + +err_takedown: + ethsw_takedown(sw_dev); + +err_free_cmdport: + fsl_mc_portal_free(ethsw->mc_io); + +err_free_drvdata: + kfree(ethsw); + dev_set_drvdata(dev, NULL); + + return err; +} + +static const struct fsl_mc_device_id ethsw_match_id_table[] = { + { + .vendor = FSL_MC_VENDOR_FREESCALE, + .obj_type = "dpsw", + }, + { .vendor = 0x0 } +}; +MODULE_DEVICE_TABLE(fslmc, ethsw_match_id_table); + +static struct fsl_mc_driver eth_sw_drv = { + .driver = { + .name = KBUILD_MODNAME, + .owner = THIS_MODULE, + }, + .probe = ethsw_probe, + .remove = ethsw_remove, + .match_id_table = ethsw_match_id_table +}; + +module_fsl_mc_driver(eth_sw_drv); + +MODULE_LICENSE("Dual BSD/GPL"); +MODULE_DESCRIPTION("DPAA2 Ethernet Switch Driver"); diff --git a/drivers/staging/fsl-dpaa2/ethsw/ethsw.h b/drivers/staging/fsl-dpaa2/ethsw/ethsw.h new file mode 100644 index 0000000..e4d5ac8 --- /dev/null +++ b/drivers/staging/fsl-dpaa2/ethsw/ethsw.h @@ -0,0 +1,89 @@ +/* Copyright 2014-2017 Freescale Semiconductor Inc. + * Copyright 2017-2018 NXP + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the above-listed copyright holders nor the + * names of any contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * + * ALTERNATIVELY, this software may be distributed under the terms of the + * GNU General Public License ("GPL") as published by the Free Software + * Foundation, either version 2 of that License or (at your option) any + * later version. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __ETHSW_H +#define __ETHSW_H + +#include +#include +#include +#include +#include +#include +#include + +#include "dpsw.h" + +/* Number of IRQs supported */ +#define DPSW_IRQ_NUM 2 + +#define ETHSW_VLAN_MEMBER 1 +#define ETHSW_VLAN_UNTAGGED 2 +#define ETHSW_VLAN_PVID 4 +#define ETHSW_VLAN_GLOBAL 8 + +/* Maximum Frame Length supported by HW (currently 10k) */ +#define DPAA2_MFL (10 * 1024) +#define ETHSW_MAX_FRAME_LENGTH (DPAA2_MFL - VLAN_ETH_HLEN - ETH_FCS_LEN) +#define ETHSW_L2_MAX_FRM(mtu) ((mtu) + VLAN_ETH_HLEN + ETH_FCS_LEN) + +struct ethsw_core; + +/* Per port private data */ +struct ethsw_port_priv { + struct net_device *netdev; + u16 idx; + struct ethsw_core *ethsw_data; + u8 link_state; + u8 stp_state; + bool flood; + + u8 vlans[VLAN_VID_MASK + 1]; + u16 pvid; + struct net_device *bridge_dev; +}; + +/* Switch data */ +struct ethsw_core { + struct device *dev; + struct fsl_mc_io *mc_io; + u16 dpsw_handle; + struct dpsw_attr sw_attr; + int dev_id; + struct ethsw_port_priv **ports; + + u8 vlans[VLAN_VID_MASK + 1]; + bool learning; +}; + +#endif /* __ETHSW_H */ -- 1.9.1