From patchwork Thu Nov 30 19:57:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 843176 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="jKHlHAdf"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynp9f6WQ2z9s72 for ; Fri, 1 Dec 2017 06:58:14 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751757AbdK3T6N (ORCPT ); Thu, 30 Nov 2017 14:58:13 -0500 Received: from mail-qk0-f196.google.com ([209.85.220.196]:36021 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751779AbdK3T54 (ORCPT ); Thu, 30 Nov 2017 14:57:56 -0500 Received: by mail-qk0-f196.google.com with SMTP id t187so10443572qkh.3 for ; Thu, 30 Nov 2017 11:57:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fEjJ6RF1KiF7WrxE2822BjYlYZttOEtXGAvoGxBVxRU=; b=jKHlHAdfxxFDLz266P674ZMcSEuL9I3U4vQ+ad/PqredlNxWLkHGlr0g9k2eveMHLf 1sdMTwQIQOhx6Nvr7g+hlVznJew9McUa8dNWHY/BpBx+pZJA2bWf0GUUqdzCT9N5Wdjm hAUC1maCSScSZ5Z9EU+ElwVZdGJ+8zvkHQWY4WsVGZLsPQQeFNdBvrQC03c2kSpElze7 u2DCt3BbPgoMkoq6CxVeWhpketqd1lq7j2xgzfTOjNcnYJw+ykMmcQWEwapoito1ElUr jhqjbFQO4NEv67eYAugIWnVL6Ryhnjqnu5jbbiMiG6uOc+KYCZYvY/IRcreZqGXTmmb7 Fl7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fEjJ6RF1KiF7WrxE2822BjYlYZttOEtXGAvoGxBVxRU=; b=gEWnvD18Um5h8hiFnJZRketPRHGRJPNSGOj+UTkQfy95Dk1wATOnQO4JiZphVwJm3q 2wYQdD+KAbWma2MeD5XFed/2Hg/clw+PIB4YDgdfEqG5Cq9nd7fMARFoA0sJ8+p/wHzK ixmvZH5bkuxiwNzCDr6/tqQbKtrpniKBxYg1L4d4XYebguS7xrGwN5TsLM3zAV8K7VPv mz+XWWJYzyYy35r+fYcp4hTdBqZmEz0RmdfQdLjsfVG2j+4/sIbeENVBBveoMRs/a/Xo ih+R9jyWOKt7XkxEaxtin1+rf4IuGdMHHkrlqETjfpRu5RV3Xgv5XJmVBsYAXxIrvETN EcCQ== X-Gm-Message-State: AKGB3mITt9Wh/43N7k4Q1l5BydJRHffpjIqjG4MOWgtIuyHR/T9gjOqV xWGy04bjJHcykDJ5AuXNkphi3ntJ X-Google-Smtp-Source: AGs4zMY3waS7i+KbF2v4/oWw/FeaFAeifWC6xRJ54Z0SpJnGckpSHAE0GOWnqL6yo2Bus47bAKvGWg== X-Received: by 10.55.22.221 with SMTP id 90mr4290421qkw.284.1512071875656; Thu, 30 Nov 2017 11:57:55 -0800 (PST) Received: from stb-bld-03.irv.broadcom.com ([192.19.255.250]) by smtp.gmail.com with ESMTPSA id x52sm3491554qta.26.2017.11.30.11.57.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Nov 2017 11:57:54 -0800 (PST) From: Florian Fainelli To: netdev@vger.kernel.org Cc: davem@davemloft.net, andrew@lunn.ch, rmk+kernel@armlinux.org.uk, vivien.didelot@savoirfairelinux.com, Florian Fainelli Subject: [PATCH net-next 4/5] net: phy: phylink: Allow setting a custom link state callback Date: Thu, 30 Nov 2017 11:57:43 -0800 Message-Id: <20171130195744.17743-5-f.fainelli@gmail.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171130195744.17743-1-f.fainelli@gmail.com> References: <20171130195744.17743-1-f.fainelli@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org phylink_get_fixed_state() currently consults an optional "link_gpio" GPIO descriptor, expand this mechanism to allow specifying a custom callback. This is necessary to support out of band link notifcation (e.g: from an interrupt within a MMIO register). Signed-off-by: Florian Fainelli --- drivers/net/phy/phylink.c | 26 ++++++++++++++++++++++++-- include/linux/phylink.h | 3 +++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index a41f0a224512..0a8fd9aa1a19 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -50,6 +50,8 @@ struct phylink { /* The link configuration settings */ struct phylink_link_state link_config; struct gpio_desc *link_gpio; + void (*get_fixed_state)(struct net_device *dev, + struct phylink_link_state *s); struct mutex state_mutex; struct phylink_link_state phy_state; @@ -339,12 +341,14 @@ static int phylink_get_mac_state(struct phylink *pl, struct phylink_link_state * } /* The fixed state is... fixed except for the link state, - * which may be determined by a GPIO. + * which may be determined by a GPIO or a callback. */ static void phylink_get_fixed_state(struct phylink *pl, struct phylink_link_state *state) { *state = pl->link_config; - if (pl->link_gpio) + if (pl->get_fixed_state) + pl->get_fixed_state(pl->netdev, state); + else if (pl->link_gpio) state->link = !!gpiod_get_value(pl->link_gpio); } @@ -737,6 +741,24 @@ void phylink_disconnect_phy(struct phylink *pl) } EXPORT_SYMBOL_GPL(phylink_disconnect_phy); +int phylink_fixed_state_cb(struct phylink *pl, + void (*cb)(struct net_device *dev, + struct phylink_link_state *state)) +{ + /* It does not make sense to let the link be overriden unless we use + * MLO_AN_FIXED + */ + if (pl->link_an_mode != MLO_AN_FIXED) + return -EINVAL; + + mutex_lock(&pl->state_mutex); + pl->get_fixed_state = cb; + mutex_unlock(&pl->state_mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(phylink_fixed_state_cb); + void phylink_mac_change(struct phylink *pl, bool up) { if (!up) diff --git a/include/linux/phylink.h b/include/linux/phylink.h index 875717a4e873..d505ea321eb5 100644 --- a/include/linux/phylink.h +++ b/include/linux/phylink.h @@ -107,6 +107,9 @@ void phylink_destroy(struct phylink *); int phylink_connect_phy(struct phylink *, struct phy_device *); int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags); void phylink_disconnect_phy(struct phylink *); +int phylink_fixed_state_cb(struct phylink *, + void (*cb)(struct net_device *dev, + struct phylink_link_state *)); void phylink_mac_change(struct phylink *, bool up);