Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932413AbcCMHeK (ORCPT ); Sun, 13 Mar 2016 03:34:10 -0400 Received: from mail-db3on0068.outbound.protection.outlook.com ([157.55.234.68]:55457 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932090AbcCMHeE (ORCPT ); Sun, 13 Mar 2016 03:34:04 -0400 Authentication-Results: savoirfairelinux.com; dkim=none (message not signed) header.d=none;savoirfairelinux.com; dmarc=none action=none header.from=mellanox.com; Date: Sun, 13 Mar 2016 09:32:50 +0200 From: Ido Schimmel To: Vivien Didelot CC: , , , "David S. Miller" , Florian Fainelli , Andrew Lunn , Jiri Pirko , Kevin Smith Subject: Re: [RFC PATCH net-next 3/3] net: dsa: refine netdev event notifier Message-ID: <20160313073250.GA2955@colbert.mtl.com> References: <1457851346-26257-1-git-send-email-vivien.didelot@savoirfairelinux.com> <1457851346-26257-4-git-send-email-vivien.didelot@savoirfairelinux.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <1457851346-26257-4-git-send-email-vivien.didelot@savoirfairelinux.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Originating-IP: [193.47.165.251] X-ClientProxiedBy: VI1PR05CA0019.eurprd05.prod.outlook.com (25.162.33.157) To VI1PR05MB0992.eurprd05.prod.outlook.com (25.162.11.14) X-MS-Office365-Filtering-Correlation-Id: ff944e54-e507-4e4c-8298-08d34b11d7a9 X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB0992;2:uXWV9jaTMFSJN/GplymeCm9O6aIcrK01FtWYqFGIM4P8HuGCLoAuP1KER5Aad0yuo/OdcqTRqnYWZdxRDPcMRVWHkjG07hbrHJ4aadRHLyklYcWBCLaUue/ME5qK5yALzfzKlm7p7NTYkKfX5fPI4vIE+2ZPl5shfdU9aHSMvNNYbmSQlGg/Orf5NKHek9PU;3:gra/TnmO33EPS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td6tfbeFnP/EOnJxOdPr9LDgAObNBEuiWxMmD0DAS6C3bsbNSZZMw2trd1eRmkfqGJeCou2nIgsuEsd0moj0whu9euVWNoc8RCFLGj1WM0lt9rstz9LdWP1Y9yYEmYkxc81VKqChFQBHq3KL8869xrHOSOB+JA7HFIVSzM2mjK/u9FcBeQUFHOwvRj+0RpPTba7dmvCuv4/PHsKMHdIF1qH55u76CvOo1YOVEF5j/0SQwMsJRkayfBGIk1AuHDsvr0y+YeDIKFTsnfU0KLV4YIWAYniYatGBmX1tuuVhodowV0oLKjJ2ojJjl84SdEQ/8Vv2cWw6HRtkjxZrML2DBMq9WTj8yWnHD0SHLKkEY33uATLuWVdalQ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046);SRVR:VI1PR05MB0992;BCL:0;PCL:0;RULEID:;SRVR:VI1PR05MB0992; X-Forefront-PRVS: 0880FB6EC1 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6069001)(6009001)(24454002)(66066001)(47776003)(92566002)(54356999)(76176999)(42186005)(2950100001)(1096002)(50986999)(5004730100002)(33656002)(50466002)(76506005)(97756001)(19580395003)(86362001)(19580405001)(6116002)(110136002)(3846002)(23726003)(5008740100001)(1076002)(189998001)(83506001)(586003)(81166005)(46406003)(4326007)(2906002)(77096005)(217873001);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR05MB0992;H:localhost;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;VI1PR05MB0992;23:9CNsBrtFZKonws6nx/od8Tz7XJC1mEt0H8ZXO6sFc?= =?us-ascii?Q?Oausodc3eGRrYz8Y8HiV1AIn9F1xQcExaxYZufOUdCe+NhkjmnXTtLyKmIgl?= =?us-ascii?Q?40iUR16FncDvhUuDYYGjAMVwr7BmqC44HBIIbb4g5h+Yn88flWrWpHTSp7xf?= =?us-ascii?Q?rjGwXUTjSV7k2FmOWt7HYH2qrkIB21ATxC1mnxh0qL9OHOwvRmLUXRRwq4aP?= =?us-ascii?Q?ZqZm7ZuuMmYN/bX0tapBaNt5+QrQPkjvscnh2t8XDDCXbgJ2PveYeDvesNcA?= =?us-ascii?Q?q2q5WjtmZwRkMSaK9ezRC55xInEchNjOnSY12woQnCr9CVq55ZC70cEXpXcm?= =?us-ascii?Q?rQS7MdJSYPMqgnZ/Q3baOJnqfgZvU1hcepSFp2kmGNzcvWDAfW681fMF0qp3?= =?us-ascii?Q?Olv8434qopZ+YE5p3EQpzxbW4fW+OgiCZWmfvsb4BbWjMiopOJJRAUDCAWKf?= =?us-ascii?Q?IXp47uvf2WWmuO8eX2202DRtVDukcE7BBtmYx7ek01/tJim9fgqarHA0ui0a?= =?us-ascii?Q?GHtQxP4qZ9PrJmZpZqF/279k0YOLVJMAHSg549F2fEkrSXSpwlftBpWTz8ph?= =?us-ascii?Q?T61o1HxPFlPlsEcekHWC0hpT/SQUs/UbAphOTyPEaUM3/0+8MXfBVAt4g0nK?= =?us-ascii?Q?ekx7PG1kguhR6LqOV0iqkoXHS5aySj6hVK037JSMFo0xp0adQqF15aZSKCCp?= =?us-ascii?Q?UHWQ9upUtMNopAwYEmXPZTeql5fMu7rGcnoI5HGwfE8ezB88GWg/vXNPHDkL?= =?us-ascii?Q?0kT7FuYcVDz67XpJ5FLirb9+mgooXwWP2v/Vn3o/hoJlo0744FgZkLLYehIH?= =?us-ascii?Q?nxhWSyI53f5SMHcdcbIdMiTmnCDTmuAABsEnAtwWvEXDhBX3tgfsxKX6h1U+?= =?us-ascii?Q?ge66V+jatnp7apsMaHV0lpuox1Ymh/F8r6BJnxQfj6fnreK7pAKsEetScVZp?= =?us-ascii?Q?Jyh65GbLk0jgTNjhuWa9eHuh9920g7VkcKb3mOeRg=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB0992;5:HiycH5+ZSNIskn3Qj6aBVBK6RYKhs/fjbRHb8PcqzKoc9OcTLcXbIQxeWtpEVsPtvjTOv9K2k0+7SGnf9q6A2VVtggUjtxkSW+Fn/UCdNBRivVuJy1zqAFrVXvRrSnfPUYo5mAcQs3KsKkJY/hjL6Q==;24:wW7LGNIALphAr0XKDJG2Bj8KwADUlD8HfESB16H7QcNHBjbDvoyen9RcCxUR1eOt9QkZ8CjsOo6T8PkCqj1gZTZO27eJi8JmK1q2rva34ew= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Mar 2016 07:33:59.2234 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR05MB0992 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3171 Lines: 106 Hi Vivien, Sun, Mar 13, 2016 at 08:42:26AM IST, vivien.didelot@savoirfairelinux.com wrote: >Rework the netdev event handler, similar to what the Mellanox Spectrum >driver does, to eventually welcome NETDEV_PRECHANGEUPPER actions and use >netdev helpers, such as netif_is_bridge_master. > >Signed-off-by: Vivien Didelot >--- > net/dsa/slave.c | 55 +++++++++++++++++++++++++++++++------------------------ > 1 file changed, 31 insertions(+), 24 deletions(-) > >diff --git a/net/dsa/slave.c b/net/dsa/slave.c >index 54976c4..27f7886 100644 >--- a/net/dsa/slave.c >+++ b/net/dsa/slave.c >@@ -451,7 +451,7 @@ static int dsa_slave_bridge_port_join(struct net_device *dev, > if (ds->drv->port_bridge_join) > ret = ds->drv->port_bridge_join(ds, p->port, br); > >- return ret; >+ return ret == -EOPNOTSUPP ? 0 : ret; > } > > static void dsa_slave_bridge_port_leave(struct net_device *dev) >@@ -1139,40 +1139,47 @@ static bool dsa_slave_dev_check(struct net_device *dev) > return dev->netdev_ops == &dsa_slave_netdev_ops; > } > >-static int dsa_slave_master_changed(struct net_device *dev) >+static int dsa_slave_port_upper_event(struct net_device *dev, >+ unsigned long event, void *ptr) > { >- struct net_device *master = netdev_master_upper_dev_get(dev); >- struct dsa_slave_priv *p = netdev_priv(dev); >+ struct netdev_notifier_changeupper_info *info = ptr; >+ struct net_device *upper = info->upper_dev; > int err = 0; > >- if (master && master->rtnl_link_ops && >- !strcmp(master->rtnl_link_ops->kind, "bridge")) >- err = dsa_slave_bridge_port_join(dev, master); >- else if (dsa_port_is_bridged(p)) >- dsa_slave_bridge_port_leave(dev); >+ switch (event) { >+ case NETDEV_CHANGEUPPER: >+ if (netif_is_bridge_master(upper)) { >+ if (info->linking) >+ err = dsa_slave_bridge_port_join(dev, upper); >+ else >+ dsa_slave_bridge_port_leave(dev); >+ } > >- return err; >+ break; >+ } >+ >+ return notifier_from_errno(err); > } > >-int dsa_slave_netdevice_event(struct notifier_block *unused, >- unsigned long event, void *ptr) >+static int dsa_slave_port_event(struct net_device *dev, unsigned long event, >+ void *ptr) > { >- struct net_device *dev; >- int err = 0; >- > switch (event) { >+ case NETDEV_PRECHANGEUPPER: Why do you need this here? It seems you are always ignoring it in dsa_slave_port_upper_event()? Probably better to introduce it when you actually need it. Other than that, it looks good to me. > case NETDEV_CHANGEUPPER: >- dev = netdev_notifier_info_to_dev(ptr); >- if (!dsa_slave_dev_check(dev)) >- goto out; >+ return dsa_slave_port_upper_event(dev, event, ptr); >+ } > >- err = dsa_slave_master_changed(dev); >- if (err && err != -EOPNOTSUPP) >- netdev_warn(dev, "failed to reflect master change\n"); >+ return NOTIFY_DONE; >+} > >- break; >- } >+int dsa_slave_netdevice_event(struct notifier_block *unused, >+ unsigned long event, void *ptr) >+{ >+ struct net_device *dev = netdev_notifier_info_to_dev(ptr); >+ >+ if (dsa_slave_dev_check(dev)) >+ return dsa_slave_port_event(dev, event, ptr); > >-out: > return NOTIFY_DONE; > } >-- >2.7.2 >