From patchwork Fri Dec 28 11:14:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Klaus Kudielka X-Patchwork-Id: 10744425 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3522791E for ; Fri, 28 Dec 2018 11:15:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2546C28BBD for ; Fri, 28 Dec 2018 11:15:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1684F28BE2; Fri, 28 Dec 2018 11:15:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7781F28BBD for ; Fri, 28 Dec 2018 11:15:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Date:Message-ID:Subject:From:To: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=yrNXjanqBq2OJM59TUTMt7ehOtQsMPov9QLjjRrVgbc=; b=F1jpOL31lyNQ/nuMfoj+PdlM5a px45bAYOU3U1Er7aV4OTjrcBK2akOZPREmaf5+MZkMDtTgAj9hIY9nDU90wVCUvCYszokrgZTyo+T E6FkqrqlL+SMjdpSk+u1+QTHstnBuQex+pqFgmlLXqnC8wGQYxaWGbTgdWzmNTW4fQCpgAtL3L2+p +H+iZmVthH66XB7YKUWxUchm1BFjsvvxAdOMY1LaxlSbu0Mrfve31YQZ7k9UC81DUmsHIBIF7apMp R7dgarQDv62ke4sqMD+XmfZXTAkfU9mSiagZxD6kSNhmODjDag/eJHavwAvUIJrMdX+z84tXPVyP4 iNJBBsjw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gcq6x-0001CE-JC; Fri, 28 Dec 2018 11:15:27 +0000 Received: from mail-ed1-x543.google.com ([2a00:1450:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gcq6f-0008JE-QB for linux-arm-kernel@lists.infradead.org; Fri, 28 Dec 2018 11:15:12 +0000 Received: by mail-ed1-x543.google.com with SMTP id o10so17258171edt.13 for ; Fri, 28 Dec 2018 03:14:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding:content-language; bh=/+ZefrT6mPMsbOv0JVrKOYuJlv4IAFghLMge1EfhaH0=; b=sYEdK5zJGzFOd2AZBXszK76zWrG/W1737r1iwI1AOQYxQ4AwSWaas1vxoKEPZKHjrI fJn6qUV9TXfrgAexmci8SlwouTPICq/54FnwQigrWJTAPmRh1wNEPKMy7ybnilWVJX9f 1jmN9mN4UJH2wAuk/ObbqLLFh+Zzs3MCCUzID+i9DeWv106/II8O250i2iLMAJSK3mjs DJn1LlLVaVZncvmkauv2C0yhkPHd7PPSsTrU1XUWSwCSRBoVddQGFd0ueCJAu2pty24p bZ+vad+9qUbLiSCaAqpzo3HWcoEqljcNUdhWuCD8vTWUZRU2t1Aw0jWicXmeyuGR4Ce8 ZEGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding:content-language; bh=/+ZefrT6mPMsbOv0JVrKOYuJlv4IAFghLMge1EfhaH0=; b=Hoq5ba/I19XXJyJH3npdNqIdHL4X2BFYzoP0vlXQggaofPjHKo5JYWPMXxLQTDhtvg 8T8kl0NswtW1zL7hg9fEhIBblxZNznffLAfkMAwBClLZY6s7/br/pUNEJ0Bok3nIuFDk 8PHD/kE45bZP8b4EHKZG+BtEgQm8JN1U7WSaAgInxlm3KMvt1949nFmWoDAZ3ScvemZv yxirCXanWnBjjrJaCYYpy5MA4Z0pDBFd0Z55iArpHIxUcS8PfCh0e9bi0DseY28itOrv TvgPFxD0xWrG77AYmq2u+389VDKNOF2P163sjKB3J5adImzqUuvSb4fCq+m2dI3mFYey 7+eQ== X-Gm-Message-State: AA+aEWZCgwJqPxN9a+a9P8TnuuVa/OezEKAI31B4IZT+koOxmlqvFW/p YXzl1RbKjsCMm0DVCHg9/us= X-Google-Smtp-Source: AFSGD/VnbFz7WoY7Mej3s8g0NAuXy/2+wT4QwPPMR2Eeq/ziiL8pA/QweM2jRfZRStWLpP6Wj0AduA== X-Received: by 2002:aa7:c55a:: with SMTP id s26mr21555886edr.132.1545995697545; Fri, 28 Dec 2018 03:14:57 -0800 (PST) Received: from ?IPv6:2a02:168:6806:0:8dcd:a40e:9df5:dbc0? ([2a02:168:6806:0:8dcd:a40e:9df5:dbc0]) by smtp.gmail.com with ESMTPSA id d7-v6sm6761816ejx.68.2018.12.28.03.14.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Dec 2018 03:14:56 -0800 (PST) To: linux-arm-kernel@lists.infradead.org From: Klaus Kudielka Subject: [RFC] phylink: support for devices with MAC sharing SFP cage & PHY (e.g. Turris Omnia)? Message-ID: <252d7259-057d-d312-f440-612360703708@gmail.com> Date: Fri, 28 Dec 2018 12:14:55 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181228_031510_115935_D971D66F X-CRM114-Status: GOOD ( 19.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tomas Hlavacek , uwe@kleine-koenig.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Hello, I own a Turris Omnia, which has basic support included in the Linux kernel (armada-385-turris-omnia.dts). Apart from the 88E1514 PHY specified for eth2, the device also features an SFP cage, which uses the same SGMII of the Armada 385 SoC, using a 2:1 multiplexer driven by the MOD_DEF0 signal. Details can be found on page 5 of https://doc.turris.cz/doc/_media/rtrom01-schema.pdf. As far as I understand the situation, phylink does not support such an architecture at the moment, which is the reason why the SFP cage was never specified in the Turris Omnia's DTS. Questions: - Is anybody already working on a solution? - If not, would something like the patch below be acceptable? - Any other suggestions, how to get this supported? Summary of the patch below, whis is based on device tree published by Tomas (and my interpretation of phylink.c): I'm specifying *both* the SFP cage and the PHY in the node of the eth2 MAC. In phylink_of_connect, if SFP module is already present: Ignore any PHY specified by the devicetree. After SFP removal, restore the original (device tree based) configuration, which was determined by phylink_create et al. (I don't think that this would harm the generic use case) With this, "hot" insertion and removal work, as long as the network interface is down. I tested this successfully on my Turris Omnia, on a relatively recent openwrt-master (4.14 kernel). SFP module is a TP-LINK TL-SM321B. "Hot" insertion/removal in the "up" state would require more work. I am sorry, the patch below is against the 4.14 (openwrt) kernel, but you get the basic idea. --- a/arch/arm/boot/dts/armada-385-turris-omnia.dts +++ b/arch/arm/boot/dts/armada-385-turris-omnia.dts @@ -115,6 +115,16 @@              };          };      }; + +    sfp: sfp { +        compatible = "sff,sfp"; +        i2c-bus = <&i2csfp>; +        tx-fault-gpios = <&pcawan 0 GPIO_ACTIVE_HIGH>; +        tx-disable-gpios = <&pcawan 1 GPIO_ACTIVE_HIGH>; +        rate-select0-gpios = <&pcawan 2 GPIO_ACTIVE_HIGH>; +        los-gpios = <&pcawan 3 GPIO_ACTIVE_HIGH>; +        mod-def0-gpios = <&pcawan 4 GPIO_ACTIVE_LOW>; +    };  };  /* Connected to 88E6176 switch, port 6 */ @@ -148,6 +158,7 @@      status = "okay";      phy-mode = "sgmii";      phy = <&phy1>; +    sfp = <&sfp>;  };  &i2c0 { @@ -210,7 +221,7 @@              /* routed to PCIe2 connector (CN62A) */          }; -        i2c@4 { +        i2csfp: i2c@4 {              #address-cells = <1>;              #size-cells = <0>;              reg = <4>; --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -58,6 +58,12 @@ struct phylink {      bool mac_link_dropped;      struct sfp_bus *sfp_bus; + +    /* Things to remember across a module insertion/removal cycle */ +    u8 default_an_mode; +    u8 default_port; +    struct phylink_link_state default_config; +    bool sfp_module_present;  };  static inline void linkmode_zero(unsigned long *dst) @@ -680,6 +686,10 @@ int phylink_of_phy_connect(struct phylin      if (pl->link_an_mode == MLO_AN_FIXED)          return 0; +    /* If SFP module present, we do not need a separate PHY */ +    if (pl->sfp_module_present) +        return 0; +      phy_node = of_parse_phandle(dn, "phy-handle", 0);      if (!phy_node)          phy_node = of_parse_phandle(dn, "phy", 0); @@ -1371,6 +1381,11 @@ static int phylink_sfp_module_insert(voi      if (mode == MLO_AN_8023Z && pl->phydev)          return -EINVAL; +    pl->default_an_mode = pl->link_an_mode; +    pl->default_port = pl->link_port; +    pl->default_config = pl->link_config; +    pl->sfp_module_present = true; +      changed = !bitmap_equal(pl->supported, support,                  __ETHTOOL_LINK_MODE_MASK_NBITS);      if (changed) { @@ -1399,6 +1414,16 @@ static int phylink_sfp_module_insert(voi      return ret;  } +static void phylink_sfp_module_remove(void *upstream) +{ +    struct phylink *pl = upstream; + +    pl->link_an_mode = pl->default_an_mode; +    pl->link_port = pl->default_port; +    pl->link_config = pl->default_config; +    pl->sfp_module_present = false; +} +  static void phylink_sfp_link_down(void *upstream)  {      struct phylink *pl = upstream; @@ -1432,6 +1457,7 @@ static void phylink_sfp_disconnect_phy(v  static const struct sfp_upstream_ops sfp_phylink_ops = {      .module_insert = phylink_sfp_module_insert, +    .module_remove = phylink_sfp_module_remove,      .link_up = phylink_sfp_link_up,      .link_down = phylink_sfp_link_down,      .connect_phy = phylink_sfp_connect_phy,