Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp4922026imc; Mon, 25 Feb 2019 13:42:03 -0800 (PST) X-Google-Smtp-Source: AHgI3Iaw55PHoLYvmC2jr5P02wKAwIIctx9uxhYnbt2+/aUdOqF7kgl8vt0u5NbG15R//yoa3Q/6 X-Received: by 2002:a17:902:7293:: with SMTP id d19mr21712601pll.29.1551130923897; Mon, 25 Feb 2019 13:42:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551130923; cv=none; d=google.com; s=arc-20160816; b=PBjcNKlQnj1xZP/9wa+/M+/9rYeLfkMlAV8/vOiKgbFVL5IMsCkTBGJ5la0HFXeo/S FsFBiJGnZBlHItadurkPHLahiAPHn4Ee8klRIkn8xbFYGZ78b0F41uBSHZVUjP7yNSBm JigN0PyPdSE2WxR5M/58CIDKYcozBzvNlkd6TmLAsDF8qSBTBr5TLat+RvF+XIEZIbog XkCYd6OMV9ehxmXdgk9FJKoLJqrmM8Ior+CcNhGpC+pmrnEhN1mMRxzz8nIyc8tzHuml XgZHwn+4/2DsKoDrtBmV4ORHSFUTIZsYEAaaf3adHbwhbrMKg0Rgb9F3+tL/7AksbAKc tQTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5kTTUR+nuOkiIbu3lTwWks9GUHQY+zN4SupFEEqElJg=; b=NtlOh2jVny1VOJwoqnNiUfhYCxMLIHr/LEfbmzjEiPnrb4XVDgmb4HJRMux3zKGzrX xoAxuuY+i+qHu65zem96oHqnp1T2VEVJNn+tvvDFhRhfGgGWN49SZGKlQqv/VulBR6IM ZiHlEfDDbdnPKOfMQv/en2BzW2OfZXF+00374fEwcNrqkSpGfUcicdN1WUTi43WpJ3Jr wAOdGPHOrm4uCbqQvIJwT5IT+I83cq77OcnB7qFQva5dP/+2XjWS/EX2IHrRXbiBT7gW VZX8tX0VxyeEFVebJlxpljkYM3+itMKhNFGXENGbVtDVHeNy2wmQTUi7F78We6OgZLiZ Z86Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=r4uFim7w; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 91si10642759pla.89.2019.02.25.13.41.48; Mon, 25 Feb 2019 13:42:03 -0800 (PST) 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=@kernel.org header.s=default header.b=r4uFim7w; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732623AbfBYVea (ORCPT + 99 others); Mon, 25 Feb 2019 16:34:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:40648 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732825AbfBYVe1 (ORCPT ); Mon, 25 Feb 2019 16:34:27 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3279420578; Mon, 25 Feb 2019 21:34:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551130466; bh=1YGSI7wifnqowOGzMX4WNV859+/oOBpylCtuQ8wGqMk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r4uFim7wCK7qHon6CDXV3SY/qWCGgI1aiR43vc5CyTmmSVpgUzNiHKwsR/3pzSVC1 TdiqxNI9u3LJz8ltQjB0aX1d3RMCa6/EeC6m2vOPJetj2U5LwYqNabS2pcbBmdht/t 6W1fPLsovEoynNJD3d7ax+pX+65mso2KchsWf9eA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Russell King , "David S. Miller" Subject: [PATCH 4.20 129/183] net: sfp: do not probe SFP module before were attached Date: Mon, 25 Feb 2019 22:11:42 +0100 Message-Id: <20190225195116.455060281@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190225195054.748060397@linuxfoundation.org> References: <20190225195054.748060397@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Russell King [ Upstream commit b5bfc21af5cb3d53f9cee0ef82eaa43762a90f81 ] When we probe a SFP module, we expect to be able to call the upstream device's module_insert() function so that the upstream link can be configured. However, when the upstream device is delayed, we currently may end up probing the module before the upstream device is available, and lose the module_insert() call. Avoid this by holding off probing the module until the SFP bus is properly connected to both the SFP socket driver and the upstream driver. Signed-off-by: Russell King Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/phy/sfp-bus.c | 2 ++ drivers/net/phy/sfp.c | 30 +++++++++++++++++++++--------- drivers/net/phy/sfp.h | 2 ++ 3 files changed, 25 insertions(+), 9 deletions(-) --- a/drivers/net/phy/sfp-bus.c +++ b/drivers/net/phy/sfp-bus.c @@ -347,6 +347,7 @@ static int sfp_register_bus(struct sfp_b return ret; } } + bus->socket_ops->attach(bus->sfp); if (bus->started) bus->socket_ops->start(bus->sfp); bus->netdev->sfp_bus = bus; @@ -362,6 +363,7 @@ static void sfp_unregister_bus(struct sf if (bus->registered) { if (bus->started) bus->socket_ops->stop(bus->sfp); + bus->socket_ops->detach(bus->sfp); if (bus->phydev && ops && ops->disconnect_phy) ops->disconnect_phy(bus->upstream); } --- a/drivers/net/phy/sfp.c +++ b/drivers/net/phy/sfp.c @@ -184,6 +184,7 @@ struct sfp { struct gpio_desc *gpio[GPIO_MAX]; + bool attached; unsigned int state; struct delayed_work poll; struct delayed_work timeout; @@ -1475,7 +1476,7 @@ static void sfp_sm_event(struct sfp *sfp */ switch (sfp->sm_mod_state) { default: - if (event == SFP_E_INSERT) { + if (event == SFP_E_INSERT && sfp->attached) { sfp_module_tx_disable(sfp); sfp_sm_ins_next(sfp, SFP_MOD_PROBE, T_PROBE_INIT); } @@ -1607,6 +1608,19 @@ static void sfp_sm_event(struct sfp *sfp mutex_unlock(&sfp->sm_mutex); } +static void sfp_attach(struct sfp *sfp) +{ + sfp->attached = true; + if (sfp->state & SFP_F_PRESENT) + sfp_sm_event(sfp, SFP_E_INSERT); +} + +static void sfp_detach(struct sfp *sfp) +{ + sfp->attached = false; + sfp_sm_event(sfp, SFP_E_REMOVE); +} + static void sfp_start(struct sfp *sfp) { sfp_sm_event(sfp, SFP_E_DEV_UP); @@ -1667,6 +1681,8 @@ static int sfp_module_eeprom(struct sfp } static const struct sfp_socket_ops sfp_module_ops = { + .attach = sfp_attach, + .detach = sfp_detach, .start = sfp_start, .stop = sfp_stop, .module_info = sfp_module_info, @@ -1834,10 +1850,6 @@ static int sfp_probe(struct platform_dev dev_info(sfp->dev, "Host maximum power %u.%uW\n", sfp->max_power_mW / 1000, (sfp->max_power_mW / 100) % 10); - sfp->sfp_bus = sfp_register_socket(sfp->dev, sfp, &sfp_module_ops); - if (!sfp->sfp_bus) - return -ENOMEM; - /* Get the initial state, and always signal TX disable, * since the network interface will not be up. */ @@ -1848,10 +1860,6 @@ static int sfp_probe(struct platform_dev sfp->state |= SFP_F_RATE_SELECT; sfp_set_state(sfp, sfp->state); sfp_module_tx_disable(sfp); - rtnl_lock(); - if (sfp->state & SFP_F_PRESENT) - sfp_sm_event(sfp, SFP_E_INSERT); - rtnl_unlock(); for (i = 0; i < GPIO_MAX; i++) { if (gpio_flags[i] != GPIOD_IN || !sfp->gpio[i]) @@ -1884,6 +1892,10 @@ static int sfp_probe(struct platform_dev dev_warn(sfp->dev, "No tx_disable pin: SFP modules will always be emitting.\n"); + sfp->sfp_bus = sfp_register_socket(sfp->dev, sfp, &sfp_module_ops); + if (!sfp->sfp_bus) + return -ENOMEM; + return 0; } --- a/drivers/net/phy/sfp.h +++ b/drivers/net/phy/sfp.h @@ -7,6 +7,8 @@ struct sfp; struct sfp_socket_ops { + void (*attach)(struct sfp *sfp); + void (*detach)(struct sfp *sfp); void (*start)(struct sfp *sfp); void (*stop)(struct sfp *sfp); int (*module_info)(struct sfp *sfp, struct ethtool_modinfo *modinfo);