From patchwork Fri Jul 21 06:00:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raju Lakkaraju X-Patchwork-Id: 123571 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp3586818vqt; Thu, 20 Jul 2023 23:06:33 -0700 (PDT) X-Google-Smtp-Source: APBJJlHS0wEfZW9FLFpAaqpQNUZZXlY7n+9o1QjbwNBXke58Np3jcOw1asJ47HeGzfG2N5pwLhlB X-Received: by 2002:a05:6870:7022:b0:1ba:2c39:18e8 with SMTP id u34-20020a056870702200b001ba2c3918e8mr1214097oae.46.1689919592959; Thu, 20 Jul 2023 23:06:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689919592; cv=none; d=google.com; s=arc-20160816; b=xmL8lAs4/yt6AIBNlrCWKVm07QkFOAs0GAISYaShJ9OKdI9L9j9NYdFojJgOdg8cY5 ayg8qg1Wk3qNRvaNZOXDunVpo97LWYj/Try5hYbqOp+VHC3f46WNjJ4c2Ml9eSUk1U82 BcLulA2Xi5R8jdh0GZohcFfGrevKOYTOo/oHpeDKQHGZo3qYKs4Av9B/6HVLiwvhnsdf LowAape+Op2wB6LUJWtz+h7oYM22E26uCrAh8qc9n4d5gh+xb9ruH+dC2la4/NHcE2Dk Fm7OmtufAqo/h7eX3iAm0tK4Ywt1yX4VVrbvsovsbrZhbFIzJhH+FFxIvknYRyjAB+Rn a80g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3hcFiO/3u4pbr6phQhQFTfsQZLoF9oplNsotsZLcddY=; fh=qv6R2IaILI1S1xEIxOZzAcF4rN0hGtVsF9kjKc0mAD0=; b=pIX1xkj97dmDX9deY00tyAPKfQzsUiavXC2RLORWjI8pH6xDGIKS6wNqOWAqVrxZKH W/Yp2Pijh5BmPMmfoZGrRss/oqHbx6erJv+LMnQjx8w13bM4pVYDBUstGKhfurJQqX3X KPAK+jDI/b4FaSo7HVXrNqvqoD8RkfZVUd2AvAnGVuHCuw4ZV9y7eA38iiCrC/n4m1hP w2RyOggeDbMSuVaDp6gKwgQ+rkl0GIKJNlYjpje27DwZauZk7dksNG7MXTwKvlA9NCqv Ng4fteg604ai0dn81r1D0F94st8gN++zNOME4VIju0qDRejb8NudnCL6QaHj6CtCrG9G n0Gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=kBqdkSsG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p15-20020a63f44f000000b00557673fdd1asi2163583pgk.313.2023.07.20.23.06.18; Thu, 20 Jul 2023 23:06:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=kBqdkSsG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229815AbjGUGAp (ORCPT + 99 others); Fri, 21 Jul 2023 02:00:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229779AbjGUGAm (ORCPT ); Fri, 21 Jul 2023 02:00:42 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38CDDE62; Thu, 20 Jul 2023 23:00:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1689919241; x=1721455241; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1ypgipcrK/g6JVBXnq3hemafU0QzkXU5hISGsnvZ/lw=; b=kBqdkSsGFIuj8nV2OOKS3jvpNZmUjOGuDTyunLF83Sp8rjWKsaGrCkLb ODFCyz7zNUYZHGCN43BoNcxhixLKpAJSLg2zlI63pzhiPybzk2IBhBz6h VyGWh6GvDY8MC8VwbJOJK3BJffcylVnkmdllC/ZT4agTzhmXMcabt4xKQ o6kWdV6J3sS6cg+xMmgUnrOr9yPx4RmcvvEVMZl/R+4lidgIoboHcgLHi fL7Bq7PCgl/5GaK9YD/ASzYXXVIvKxRBYc6vAG4nllrSMItsT35x/RTe4 54V8GeVixXVmFC/J0WMsXTz5s+VMt7XZaFGOm6jeo8au0AzdYv9M5Z1xb w==; X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="225102694" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 20 Jul 2023 23:00:39 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Thu, 20 Jul 2023 23:00:37 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2507.21 via Frontend Transport; Thu, 20 Jul 2023 23:00:34 -0700 From: Raju Lakkaraju To: CC: , , , , , , Subject: [PATCH net-next 1/7] net: lan743x: Create separate PCS power reset function Date: Fri, 21 Jul 2023 11:30:13 +0530 Message-ID: <20230721060019.2737-2-Raju.Lakkaraju@microchip.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230721060019.2737-1-Raju.Lakkaraju@microchip.com> References: <20230721060019.2737-1-Raju.Lakkaraju@microchip.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772009127100341802 X-GMAIL-MSGID: 1772009127100341802 Create separate PCS power reset function from lan743x_sgmii_config () to use as subroutine. Signed-off-by: Raju Lakkaraju --- drivers/net/ethernet/microchip/lan743x_main.c | 54 ++++++++++--------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c index a36f6369f132..dba5576a933b 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.c +++ b/drivers/net/ethernet/microchip/lan743x_main.c @@ -1145,6 +1145,34 @@ static int lan743x_pcs_seq_state(struct lan743x_adapter *adapter, u8 state) return 0; } +static int lan743x_pcs_power_reset(struct lan743x_adapter *adapter) +{ + int mii_ctl; + int ret; + + /* SGMII/1000/2500BASE-X PCS power down */ + mii_ctl = lan743x_sgmii_read(adapter, MDIO_MMD_VEND2, MII_BMCR); + if (mii_ctl < 0) + return mii_ctl; + + mii_ctl |= BMCR_PDOWN; + ret = lan743x_sgmii_write(adapter, MDIO_MMD_VEND2, MII_BMCR, mii_ctl); + if (ret < 0) + return ret; + + ret = lan743x_pcs_seq_state(adapter, PCS_POWER_STATE_DOWN); + if (ret < 0) + return ret; + + /* SGMII/1000/2500BASE-X PCS power up */ + mii_ctl &= ~BMCR_PDOWN; + ret = lan743x_sgmii_write(adapter, MDIO_MMD_VEND2, MII_BMCR, mii_ctl); + if (ret < 0) + return ret; + + return lan743x_pcs_seq_state(adapter, PCS_POWER_STATE_UP); +} + static int lan743x_sgmii_config(struct lan743x_adapter *adapter) { struct net_device *netdev = adapter->netdev; @@ -1207,31 +1235,7 @@ static int lan743x_sgmii_config(struct lan743x_adapter *adapter) netif_dbg(adapter, drv, adapter->netdev, "SGMII 1G mode enable\n"); - /* SGMII/1000/2500BASE-X PCS power down */ - mii_ctl = lan743x_sgmii_read(adapter, MDIO_MMD_VEND2, MII_BMCR); - if (mii_ctl < 0) - return mii_ctl; - - mii_ctl |= BMCR_PDOWN; - ret = lan743x_sgmii_write(adapter, MDIO_MMD_VEND2, MII_BMCR, mii_ctl); - if (ret < 0) - return ret; - - ret = lan743x_pcs_seq_state(adapter, PCS_POWER_STATE_DOWN); - if (ret < 0) - return ret; - - /* SGMII/1000/2500BASE-X PCS power up */ - mii_ctl &= ~BMCR_PDOWN; - ret = lan743x_sgmii_write(adapter, MDIO_MMD_VEND2, MII_BMCR, mii_ctl); - if (ret < 0) - return ret; - - ret = lan743x_pcs_seq_state(adapter, PCS_POWER_STATE_UP); - if (ret < 0) - return ret; - - return 0; + return lan743x_pcs_power_reset(adapter); } static void lan743x_mac_set_address(struct lan743x_adapter *adapter, From patchwork Fri Jul 21 06:00:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raju Lakkaraju X-Patchwork-Id: 123572 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp3586939vqt; Thu, 20 Jul 2023 23:06:50 -0700 (PDT) X-Google-Smtp-Source: APBJJlGy3HVByEzANuPB44NZ2W0aPTg9AejP9yI9rpAhkBmFXw5iHIOFCs3hJtIQ1jOawy4+TX39 X-Received: by 2002:a17:903:2305:b0:1b3:a928:18e7 with SMTP id d5-20020a170903230500b001b3a92818e7mr965258plh.59.1689919610144; Thu, 20 Jul 2023 23:06:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689919610; cv=none; d=google.com; s=arc-20160816; b=v7Cpat2bbSCfYDmdydmZhaHv2CRREHTvFKASP/uVCI1RsYZ20xsiJ9LA6KBuf3PAOL 6xwq2IHt20KHXks3xDR7oR4+Gb1vzKCDXEFBipugxfkaIJOkKrOtGUImFSO9KYT65ROc Lz/GSOCzXUy5uO2XgDvk1mtRNcj6tnEOmE3y4HVpJYC0xH6fSgUG2KmudkyUYN3kA3Xy ewru4C/1oqBDaAbqUNhhqeh0hYBn6123P/Z7ZdN3XtHgGPs6o7vIcbGuDjPTeCmPBvpp jhGHrI8GKWLgJeBY3HcGefAxpciHE+QmiiHAQIT16932c6/HscM0ZFmXesF2/jYrXG+p CTnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=44qbC76F4wVSaDbyUyav5Hg0S2jKVo3vaUOaNzWEGrQ=; fh=qv6R2IaILI1S1xEIxOZzAcF4rN0hGtVsF9kjKc0mAD0=; b=gen7GiBWr/tOliZvtNs+AzSwWWmSCE/d71crbpzrgAFgvbrI+00hRbDzLZI7MxoGw7 JNCCkgChvODKUwhcKIyPntTCggTXT0YiO6H/X4qxAJNMrGyIQzp7Qi3ObTxXx2ZAzRfU lvoINd+hjAHQ8T5dl41zQS2HThErs5V11m3cOyCMxd6xB5BH/Xml9R1vfzApINWYEgwJ Kcl0RwkfrNwqeNZ+6F0/65tg3oOdvI9QM4jEn7qn484pUjOHqjo1ooj48DZdtDye/yAS dGF+Wk/t1Xar7iua8GtP6C3j1MOa6p6L60J3buNHCM3Bw77qsKHBpgCpNCn/Xbdnb8KX vx1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=BSgYonXn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f14-20020a170902684e00b001b8a5d9806bsi2332404pln.21.2023.07.20.23.06.36; Thu, 20 Jul 2023 23:06:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=BSgYonXn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229823AbjGUGAr (ORCPT + 99 others); Fri, 21 Jul 2023 02:00:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229757AbjGUGAm (ORCPT ); Fri, 21 Jul 2023 02:00:42 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 527B0E65; Thu, 20 Jul 2023 23:00:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1689919241; x=1721455241; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VxSnmdIkmVO33/iPhlNVZCik+lh1SAAiutDaFIxRxR8=; b=BSgYonXnd2wjiJ5u2gSyIqT6SCxm+ZZ0G+/g1bHwKuoXuOl/YFFDFGOa I9CssQUmc3bCu7/Llhp/57g1CxvT9dn9CHIuixN2l1VN2r3GQnXEqUa1T vt4aXDjFjAJ3V9I+oSKiYJJ5pGMIYiioDXcPXEbMd/PON+anbyOluVFm2 z/fOGPLfU9JFzla4rkhdmuxdB0Kq9inGdxggoBystQY5GRjaznf8lcEtG 5SMpPZQyW9lRM6GBQ6Fpl7ErQb+L2HfNbXrp1Ved+9alisBmQaIYVMkmd SA4eBlRRHfq6KfefNwf4MVv6ecDiOMetEQjl+6WIAIIPpwSGesNYjGK/4 Q==; X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="225102709" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 20 Jul 2023 23:00:41 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Thu, 20 Jul 2023 23:00:40 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2507.21 via Frontend Transport; Thu, 20 Jul 2023 23:00:37 -0700 From: Raju Lakkaraju To: CC: , , , , , , Subject: [PATCH net-next 2/7] net: lan743x: Create separate Link Speed Duplex state function Date: Fri, 21 Jul 2023 11:30:14 +0530 Message-ID: <20230721060019.2737-3-Raju.Lakkaraju@microchip.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230721060019.2737-1-Raju.Lakkaraju@microchip.com> References: <20230721060019.2737-1-Raju.Lakkaraju@microchip.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772009144965451843 X-GMAIL-MSGID: 1772009144965451843 Create separate Link Speed Duplex (LSD) update state function from lan743x_sgmii_config () to use as subroutine. Signed-off-by: Raju Lakkaraju --- drivers/net/ethernet/microchip/lan743x_main.c | 76 +++++++++++-------- drivers/net/ethernet/microchip/lan743x_main.h | 1 + 2 files changed, 46 insertions(+), 31 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c index dba5576a933b..e8dd272a591a 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.c +++ b/drivers/net/ethernet/microchip/lan743x_main.c @@ -990,6 +990,42 @@ static int lan743x_sgmii_write(struct lan743x_adapter *adapter, return ret; } +int lan743x_lsd_update(int speed, int duplex, u8 mss) +{ + enum lan743x_sgmii_lsd lsd = POWER_DOWN; + + switch (speed) { + case SPEED_2500: + if (mss == MASTER_SLAVE_STATE_SLAVE) + lsd = LINK_2500_SLAVE; + else + lsd = LINK_2500_MASTER; + break; + case SPEED_1000: + if (mss == MASTER_SLAVE_STATE_SLAVE) + lsd = LINK_1000_SLAVE; + else + lsd = LINK_1000_MASTER; + break; + case SPEED_100: + if (duplex == DUPLEX_FULL) + lsd = LINK_100FD; + else + lsd = LINK_100HD; + break; + case SPEED_10: + if (duplex == DUPLEX_FULL) + lsd = LINK_10FD; + else + lsd = LINK_10HD; + break; + default: + return -EINVAL; + } + + return lsd; +} + static int lan743x_sgmii_mpll_set(struct lan743x_adapter *adapter, u16 baud) { @@ -1177,43 +1213,21 @@ static int lan743x_sgmii_config(struct lan743x_adapter *adapter) { struct net_device *netdev = adapter->netdev; struct phy_device *phydev = netdev->phydev; - enum lan743x_sgmii_lsd lsd = POWER_DOWN; - int mii_ctl; bool status; int ret; - switch (phydev->speed) { - case SPEED_2500: - if (phydev->master_slave_state == MASTER_SLAVE_STATE_MASTER) - lsd = LINK_2500_MASTER; - else - lsd = LINK_2500_SLAVE; - break; - case SPEED_1000: - if (phydev->master_slave_state == MASTER_SLAVE_STATE_MASTER) - lsd = LINK_1000_MASTER; - else - lsd = LINK_1000_SLAVE; - break; - case SPEED_100: - if (phydev->duplex) - lsd = LINK_100FD; - else - lsd = LINK_100HD; - break; - case SPEED_10: - if (phydev->duplex) - lsd = LINK_10FD; - else - lsd = LINK_10HD; - break; - default: + ret = lan743x_lsd_update(phydev->speed, phydev->duplex, + phydev->master_slave_state); + if (ret < 0) { netif_err(adapter, drv, adapter->netdev, - "Invalid speed %d\n", phydev->speed); - return -EINVAL; + "error %d link-speed-duplex(LSD) invalid\n", ret); + return ret; } - adapter->sgmii_lsd = lsd; + adapter->sgmii_lsd = ret; + netif_dbg(adapter, drv, adapter->netdev, + "Link Speed Duplex (lsd) : 0x%X\n", adapter->sgmii_lsd); + ret = lan743x_sgmii_aneg_update(adapter); if (ret < 0) { netif_err(adapter, drv, adapter->netdev, diff --git a/drivers/net/ethernet/microchip/lan743x_main.h b/drivers/net/ethernet/microchip/lan743x_main.h index 52609fc13ad9..0cd3fe71dfad 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.h +++ b/drivers/net/ethernet/microchip/lan743x_main.h @@ -1163,5 +1163,6 @@ void lan743x_hs_syslock_release(struct lan743x_adapter *adapter); void lan743x_mac_flow_ctrl_set_enables(struct lan743x_adapter *adapter, bool tx_enable, bool rx_enable); int lan743x_sgmii_read(struct lan743x_adapter *adapter, u8 mmd, u16 addr); +int lan743x_lsd_update(int speed, int duplex, u8 mss); #endif /* _LAN743X_H */ From patchwork Fri Jul 21 06:00:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raju Lakkaraju X-Patchwork-Id: 123584 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp7915vqg; Thu, 20 Jul 2023 23:34:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlFM2smk5Cn1QGEX/J/stzMKC7dSQN2Ub3vu4NV7DmgI0U6eT2w0jQlvIIJ+ZrUJB1Z/xFgw X-Received: by 2002:a17:906:845b:b0:997:865a:77e3 with SMTP id e27-20020a170906845b00b00997865a77e3mr824896ejy.11.1689921287901; Thu, 20 Jul 2023 23:34:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689921287; cv=none; d=google.com; s=arc-20160816; b=Cs9YIjjxqLOtaevEyp+qz2HG0cWIDuWM+ICzNtV3rpHqJdM8c4p9I8dBh5lLhOEbkP AIvrm3tw2rS7yUjlSRBl/Mxb7HhQ6sXcTfJ7RuDN2vdPqkQeC/i7WGlIZKA2Z+w+OFbO e8xRi2eQDUSqFVp7O8QJW+NoaFT53YrmSDTcJgNxl9F2O93MwHDBaNGjQ4nCnCCqtbWo Vju4ufNdNs6u4gyZ8R+2vs72uem17bhYFLR8R8dnA28PLD2amoA72DJYHnjxE5nLNSeO ylbDdBb1IjtDoAQAC8K1TclAbR7CnEca40URiY3Qjc0LsP2QXZNFtjAoIraaMeSMZ/vH Ikxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3Wj6FWZ2eQePlwJzwtPrT1FwF370uWCxqOs6c1GQoAE=; fh=qv6R2IaILI1S1xEIxOZzAcF4rN0hGtVsF9kjKc0mAD0=; b=kIWp9vS8JuEUjzhV5Umxj2QwuzZzF/yUUobnbY7wlMODlHsUKWKmA7De/E4pjWb1ot on9ai52IgxTUY7Dg+Erytpe86TGp4T88yCU4BeZYb7GHCwqcXHPKL3WVD7uh24uEHo6U dq8WWjtLK/auPNfXxhmTnKoZ1sDdlotAQaeudXRpp/SwH/zT4q68UdzSJINzFwYzBsLB PYuQ0fPPUisgOm2Y5yc0CV7fu6u+HNZDhPADzlO9kN4Sf55TYk74f+DxJpTHkiR4JZi8 LLr0+PC60uRcBN2A4UIKamBuPLGQdnNcMnRj2mOKWa4zjgApoLVK5N0iCb4MZ55Z59Cb kg4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=p6MmXsC8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l6-20020aa7c306000000b005219048500fsi1885238edq.179.2023.07.20.23.34.23; Thu, 20 Jul 2023 23:34:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=p6MmXsC8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229829AbjGUGAu (ORCPT + 99 others); Fri, 21 Jul 2023 02:00:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229818AbjGUGAp (ORCPT ); Fri, 21 Jul 2023 02:00:45 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DF30E62; Thu, 20 Jul 2023 23:00:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1689919245; x=1721455245; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pDx+xIc1pKw69N9rcGWkTVyLaxLMsH85HpuhblKYyE4=; b=p6MmXsC8fVtcYPzIIwpmdiHfoBu+92jb+l4ppVMeZXDcaiUkpiqLJaj+ 4nBkdcFewSTqQTb12vomUMXdP4DgkQ4khU2ILkHRrukHcZNguBFIO/wb5 zran0cThTWzfWMPXzfxM9QWFqirtjmIC0cDeffHSjol4euM4Y3V0v5BkJ NBryNKvi5pIBXCwbjksUXC15gFtiDzwaV1O87DVSWwnKoXcgG7EQhYldz LhXXEBPPWg/yc1WPOOKy63aQyEYMeebpj3SSafXSc4XfJkTHzy4Qnb0mQ wDFBIO51U4q/dxFqHm1MpggRzIeDyn/ZXBc2DcwiNAsksHBW4W4/Dli/K A==; X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="225102735" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 20 Jul 2023 23:00:44 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Thu, 20 Jul 2023 23:00:43 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2507.21 via Frontend Transport; Thu, 20 Jul 2023 23:00:41 -0700 From: Raju Lakkaraju To: CC: , , , , , , Subject: [PATCH net-next 3/7] net: lan743x: Add SFP support check flag Date: Fri, 21 Jul 2023 11:30:15 +0530 Message-ID: <20230721060019.2737-4-Raju.Lakkaraju@microchip.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230721060019.2737-1-Raju.Lakkaraju@microchip.com> References: <20230721060019.2737-1-Raju.Lakkaraju@microchip.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772010904515013774 X-GMAIL-MSGID: 1772010904515013774 PCI11x1x chip support the Pluggable module (SFP) depend on Board requirement. SFP support information programmed in EEPROM. Flag "is_sfp_support_en" update on "STRAP" register. Signed-off-by: Raju Lakkaraju --- drivers/net/ethernet/microchip/lan743x_main.c | 10 ++++++++++ drivers/net/ethernet/microchip/lan743x_main.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c index e8dd272a591a..822576b088a9 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.c +++ b/drivers/net/ethernet/microchip/lan743x_main.c @@ -52,6 +52,11 @@ static void pci11x1x_strap_get_status(struct lan743x_adapter *adapter) adapter->is_sgmii_en = true; else adapter->is_sgmii_en = false; + + if ((strap & STRAP_SFP_USE_EN_) && (strap & STRAP_SFP_EN_)) + adapter->is_sfp_support_en = true; + else + adapter->is_sfp_support_en = false; } else { chip_rev = lan743x_csr_read(adapter, FPGA_REV); if (chip_rev) { @@ -63,8 +68,12 @@ static void pci11x1x_strap_get_status(struct lan743x_adapter *adapter) adapter->is_sgmii_en = false; } } + netif_dbg(adapter, drv, adapter->netdev, "SGMII I/F %sable\n", adapter->is_sgmii_en ? "En" : "Dis"); + netif_dbg(adapter, drv, adapter->netdev, + "SFP support %sable\n", adapter->is_sfp_support_en ? + "En" : "Dis"); } static bool is_pci11x1x_chip(struct lan743x_adapter *adapter) @@ -3408,6 +3417,7 @@ static int lan743x_pcidev_probe(struct pci_dev *pdev, NETIF_MSG_LINK | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN | NETIF_MSG_TX_QUEUED; netdev->max_mtu = LAN743X_MAX_FRAME_SIZE; + adapter->is_sfp_support_en = false; of_get_mac_address(pdev->dev.of_node, adapter->mac_address); diff --git a/drivers/net/ethernet/microchip/lan743x_main.h b/drivers/net/ethernet/microchip/lan743x_main.h index 0cd3fe71dfad..3889bb20a524 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.h +++ b/drivers/net/ethernet/microchip/lan743x_main.h @@ -34,6 +34,8 @@ #define STRAP_READ (0x0C) #define STRAP_READ_USE_SGMII_EN_ BIT(22) +#define STRAP_SFP_USE_EN_ BIT(31) +#define STRAP_SFP_EN_ BIT(15) #define STRAP_READ_SGMII_EN_ BIT(6) #define STRAP_READ_SGMII_REFCLK_ BIT(5) #define STRAP_READ_SGMII_2_5G_ BIT(4) @@ -1038,6 +1040,7 @@ struct lan743x_adapter { u8 max_tx_channels; u8 used_tx_channels; u8 max_vector_count; + bool is_sfp_support_en; #define LAN743X_ADAPTER_FLAG_OTP BIT(0) u32 flags; From patchwork Fri Jul 21 06:00:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raju Lakkaraju X-Patchwork-Id: 123573 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp3587481vqt; Thu, 20 Jul 2023 23:08:03 -0700 (PDT) X-Google-Smtp-Source: APBJJlFCj9jLx4mx5S/9FGel/PmDHW6UB314UrF8dbfyBUWepJ36dLLfyBLhzh1tMXq3JY95zAP0 X-Received: by 2002:a17:902:ce84:b0:1b8:4607:c3d7 with SMTP id f4-20020a170902ce8400b001b84607c3d7mr1092457plg.41.1689919683148; Thu, 20 Jul 2023 23:08:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689919683; cv=none; d=google.com; s=arc-20160816; b=HaWN7CDHgjJq0cIsisBHHxCHOVKrg7N+Ln3w1vvMSlK4QghPV1ge18wC7CGUUYvVRv 77d4zDG3H4bs1tMEqv1pfoHBKCOpI7SoxwF5ZjaXPn9AEYDOSDgaxd4DTXcmS4KAnKKj tLzR/lwSzZNr6D1x1hG4UrmSDWcDPMIf0jsx6G2gMks5aKQiSDDo+p2Sp6xBpRP4SfQ1 HqeMPAeqPsOMbqZSB89mcQ+UrFslI55rAHixstcTvxzAVZPi0P9MIy4geq98enA7KvpH FABYdyrZlxCK2xGVEHj/FnQT4f94cEZ6mqCaV5Ncg41ShEfa44eMrc7DzfuDxhNo9acV Bniw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KNd527qq71/hvjyOZcNT8YTn8+6UzMX8naXIIZ/c8GU=; fh=qv6R2IaILI1S1xEIxOZzAcF4rN0hGtVsF9kjKc0mAD0=; b=Gl+YmcJosacJXyBABfJAUmcB12swNodLQS/vbOlNSkwlbL1n0EA6/u4hgGnuveHQ72 43hL9TZjkvURMmNEAR+xUWJQyrRo4WUf+2SdDr4aOoPS5Cn8pvITDgTw47jjpRUMzLj0 fHKMw5I8uim5IwO9ESXwrKQ8IjN71PVPxpzkns0luXC1PaErMl6nKBcnDjP6+yt+Zv9b FZiBBFiYVic4hO5QJXg2vFogzVSkEUg+1w7wy4yuzQ6d2mNuEIat2mKBcFjyywFMNnbL iqGyp7ZNtlgzyE2pCVCDYR7QSUezfGJbiI59xJJjdTsDS51Hse3UlYa2Ft/imXqAxbWQ UogA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=Qf0qJA8l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f14-20020a170902684e00b001b8a5d9806bsi2332404pln.21.2023.07.20.23.07.33; Thu, 20 Jul 2023 23:08:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=Qf0qJA8l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229909AbjGUGBB (ORCPT + 99 others); Fri, 21 Jul 2023 02:01:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229905AbjGUGAv (ORCPT ); Fri, 21 Jul 2023 02:00:51 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 856F62719; Thu, 20 Jul 2023 23:00:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1689919248; x=1721455248; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hQq8jx/iDqfuUs5wo0Ef4tMhA1ko59EYgPsFu80mUf0=; b=Qf0qJA8lLBiAROJe4eOnyXtkyy2/yyYw2Li1mlEpEE6MZYgioncj1PWI udK2KKKZ4SwiYXM7Eag0a5trw0Qlm1K6HqQmQOy6GXKBhYtW+kYTyE3gO R9YYTdvUZrlT5IJojxcUw25+0KRCCPsGo8CNMpmJ9RaoJkrxkSNuu/dci r/R3L1Ai9q7yI5GacN78eMMeA/xNlfiw7Dt0v2XhoXeT8lQPzf/VzwfTo kg8UUHiKGh7B4VR+OfMcvMyoU1jpGICpRHfFKdJvqhg8GGaw9Wn9+LApj /7LXILaM/kzI1yrbb3yi0RdtZySkbQp9d0k0VtTU5zDLLzQIGrZBejRRC g==; X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="225102780" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 20 Jul 2023 23:00:48 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Thu, 20 Jul 2023 23:00:47 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2507.21 via Frontend Transport; Thu, 20 Jul 2023 23:00:44 -0700 From: Raju Lakkaraju To: CC: , , , , , , Subject: [PATCH net-next 4/7] net: lan743x: Add support to software-nodes for SFP and PHYLINK Date: Fri, 21 Jul 2023 11:30:16 +0530 Message-ID: <20230721060019.2737-5-Raju.Lakkaraju@microchip.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230721060019.2737-1-Raju.Lakkaraju@microchip.com> References: <20230721060019.2737-1-Raju.Lakkaraju@microchip.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772009222045225742 X-GMAIL-MSGID: 1772009222045225742 Register software nodes and define the device properties. software-node contains following properties. - GPIO pin details - I2C bus information - SFP signals - phylink modes Signed-off-by: Raju Lakkaraju --- drivers/net/ethernet/microchip/Kconfig | 2 + drivers/net/ethernet/microchip/lan743x_main.c | 214 +++++++++++++++++- drivers/net/ethernet/microchip/lan743x_main.h | 31 +++ 3 files changed, 244 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/microchip/Kconfig b/drivers/net/ethernet/microchip/Kconfig index 329e374b9539..b1d361b412d1 100644 --- a/drivers/net/ethernet/microchip/Kconfig +++ b/drivers/net/ethernet/microchip/Kconfig @@ -49,6 +49,8 @@ config LAN743X select FIXED_PHY select CRC16 select CRC32 + select I2C_PCI1XXXX + select GP_PCI1XXXX help Support for the Microchip LAN743x PCI Express Gigabit Ethernet chip diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c index 822576b088a9..aef64747a952 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.c +++ b/drivers/net/ethernet/microchip/lan743x_main.c @@ -15,6 +15,9 @@ #include #include #include +#include +#include +#include "../../../misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.h" #include "lan743x_main.h" #include "lan743x_ethtool.h" @@ -24,6 +27,30 @@ #define MMD_ACCESS_READ_INC 3 #define PCS_POWER_STATE_DOWN 0x6 #define PCS_POWER_STATE_UP 0x4 +#define PCI1XXXX_VENDOR_ID 0x1055 +#define PCI1XXXX_BR_PERIF_ID 0xA00C +#define PCI1XXXX_PERIF_I2C_ID 0xA003 +#define PCI1XXXX_PERIF_GPIO_ID 0xA005 +#define PCI1XXXX_DEV_MASK GENMASK(7, 4) + +#define NODE_PROP(_NAME, _PROP) \ + ((const struct software_node) { \ + .name = _NAME, \ + .properties = _PROP, \ + }) + +struct pci1xxxx_i2c { + struct completion i2c_xfer_done; + bool i2c_xfer_in_progress; + struct i2c_adapter adap; + void __iomem *i2c_base; + u32 freq; + u32 flags; +}; + +struct aux_bus_device { + struct auxiliary_device_wrapper *aux_device_wrapper[2]; +}; static void pci11x1x_strap_get_status(struct lan743x_adapter *adapter) { @@ -96,6 +123,91 @@ static void lan743x_pci_cleanup(struct lan743x_adapter *adapter) pci_disable_device(adapter->pdev); } +static void *pci1xxxx_perif_drvdata_get(struct lan743x_adapter *adapter, + u16 perif_id) +{ + struct pci_dev *pdev = adapter->pdev; + struct pci_bus *perif_bus; + struct pci_dev *perif_dev; + struct pci_dev *br_dev; + struct pci_bus *br_bus; + struct pci_dev *dev; + + /* PCI11x1x devices' PCIe topology consists of a top level pcie + * switch with up to four downstream ports, some of which have + * integrated endpoints connected to them. One of the downstream ports + * has an embedded single function pcie ethernet controller which is + * handled by this driver. Another downstream port has an + * embedded multifunction pcie endpoint, with four pcie functions + * (the "peripheral controllers": I2C controller, GPIO controller, + * UART controllers, SPIcontrollers) + * The code below navigates the PCI11x1x topology + * to find (by matching its PCI device ID) the peripheral controller + * that should be paired to the embedded ethernet controller. + */ + br_dev = pci_upstream_bridge(pdev); + if (!br_dev) { + netif_err(adapter, drv, adapter->netdev, + "upstream bridge not found\n"); + return br_dev; + } + + br_bus = br_dev->bus; + list_for_each_entry(dev, &br_bus->devices, bus_list) { + if (dev->vendor == PCI1XXXX_VENDOR_ID && + (dev->device & ~PCI1XXXX_DEV_MASK) == + PCI1XXXX_BR_PERIF_ID) { + perif_bus = dev->subordinate; + list_for_each_entry(perif_dev, &perif_bus->devices, + bus_list) { + if (perif_dev->vendor == PCI1XXXX_VENDOR_ID && + (perif_dev->device & ~PCI1XXXX_DEV_MASK) == + perif_id) + return pci_get_drvdata(perif_dev); + } + } + } + + netif_err(adapter, drv, adapter->netdev, + "pci1xxxx peripheral (0x%X) device not found\n", perif_id); + + return NULL; +} + +static int pci1xxxx_i2c_adapter_get(struct lan743x_adapter *adapter) +{ + struct pci1xxxx_i2c *i2c_drvdata; + + i2c_drvdata = pci1xxxx_perif_drvdata_get(adapter, PCI1XXXX_PERIF_I2C_ID); + if (!i2c_drvdata) + return -EPROBE_DEFER; + + adapter->i2c_adap = &i2c_drvdata->adap; + snprintf(adapter->nodes->i2c_name, sizeof(adapter->nodes->i2c_name), + adapter->i2c_adap->name); + netif_dbg(adapter, drv, adapter->netdev, "Found %s\n", + adapter->i2c_adap->name); + + return 0; +} + +static int pci1xxxx_gpio_dev_get(struct lan743x_adapter *adapter) +{ + struct aux_bus_device *aux_bus; + struct device *gpio_dev; + + aux_bus = pci1xxxx_perif_drvdata_get(adapter, PCI1XXXX_PERIF_GPIO_ID); + if (!aux_bus) + return -EPROBE_DEFER; + + gpio_dev = &aux_bus->aux_device_wrapper[1]->aux_dev.dev; + snprintf(adapter->nodes->gpio_name, sizeof(adapter->nodes->gpio_name), + dev_name(gpio_dev)); + netif_dbg(adapter, drv, adapter->netdev, "Found %s\n", + adapter->nodes->gpio_name); + return 0; +} + static int lan743x_pci_init(struct lan743x_adapter *adapter, struct pci_dev *pdev) { @@ -3030,6 +3142,85 @@ static int lan743x_rx_open(struct lan743x_rx *rx) return ret; } +static int lan743x_swnodes_register(struct lan743x_adapter *adapter) +{ + struct pci_dev *pdev = adapter->pdev; + struct lan743x_sw_nodes *nodes; + struct software_node *swnodes; + int ret; + u32 id; + + nodes = kzalloc(sizeof(*nodes), GFP_KERNEL); + if (!nodes) + return -ENOMEM; + + adapter->nodes = nodes; + + ret = pci1xxxx_gpio_dev_get(adapter); + if (ret < 0) + return ret; + + ret = pci1xxxx_i2c_adapter_get(adapter); + if (ret < 0) + return ret; + + id = (pdev->bus->number << 8) | pdev->devfn; + snprintf(nodes->sfp_name, sizeof(nodes->sfp_name), + "sfp-%x", id); + snprintf(nodes->phylink_name, sizeof(nodes->phylink_name), + "mchp-pci1xxxx-phylink-%x", id); + + swnodes = nodes->swnodes; + + nodes->gpio_props[0] = PROPERTY_ENTRY_STRING("pinctrl-names", + "default"); + swnodes[SWNODE_GPIO] = NODE_PROP(nodes->gpio_name, nodes->gpio_props); + + nodes->tx_fault_ref[0] = SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_GPIO], + 46, GPIO_ACTIVE_HIGH); + nodes->tx_disable_ref[0] = SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_GPIO], + 47, GPIO_ACTIVE_HIGH); + nodes->mod_def0_ref[0] = SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_GPIO], + 51, GPIO_ACTIVE_LOW); + nodes->los_ref[0] = SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_GPIO], + 49, GPIO_ACTIVE_HIGH); + nodes->rate_select0_ref[0] = SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_GPIO], + 48, GPIO_ACTIVE_HIGH); + + nodes->i2c_props[0] = PROPERTY_ENTRY_STRING("pinctrl-names", "default"); + swnodes[SWNODE_I2C] = NODE_PROP(nodes->i2c_name, nodes->i2c_props); + nodes->i2c_ref[0] = SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_I2C]); + + nodes->sfp_props[0] = PROPERTY_ENTRY_STRING("compatible", "sff,sfp"); + nodes->sfp_props[1] = PROPERTY_ENTRY_REF_ARRAY("i2c-bus", + nodes->i2c_ref); + nodes->sfp_props[2] = PROPERTY_ENTRY_REF_ARRAY("tx-fault-gpios", + nodes->tx_fault_ref); + nodes->sfp_props[3] = PROPERTY_ENTRY_REF_ARRAY("tx-disable-gpios", + nodes->tx_disable_ref); + nodes->sfp_props[4] = PROPERTY_ENTRY_REF_ARRAY("mod-def0-gpios", + nodes->mod_def0_ref); + nodes->sfp_props[5] = PROPERTY_ENTRY_REF_ARRAY("los-gpios", + nodes->los_ref); + nodes->sfp_props[6] = PROPERTY_ENTRY_REF_ARRAY("rate-select0-gpios", + nodes->rate_select0_ref); + swnodes[SWNODE_SFP] = NODE_PROP(nodes->sfp_name, nodes->sfp_props); + nodes->sfp_ref[0] = SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_SFP]); + nodes->phylink_props[0] = PROPERTY_ENTRY_STRING("managed", + "in-band-status"); + nodes->phylink_props[1] = PROPERTY_ENTRY_REF_ARRAY("sfp", + nodes->sfp_ref); + swnodes[SWNODE_PHYLINK] = NODE_PROP(nodes->phylink_name, + nodes->phylink_props); + + nodes->group[SWNODE_GPIO] = &swnodes[SWNODE_GPIO]; + nodes->group[SWNODE_I2C] = &swnodes[SWNODE_I2C]; + nodes->group[SWNODE_SFP] = &swnodes[SWNODE_SFP]; + nodes->group[SWNODE_PHYLINK] = &swnodes[SWNODE_PHYLINK]; + + return software_node_register_node_group(nodes->group); +} + static int lan743x_netdev_close(struct net_device *netdev) { struct lan743x_adapter *adapter = netdev_priv(netdev); @@ -3233,6 +3424,14 @@ static const struct net_device_ops lan743x_netdev_ops = { static void lan743x_hardware_cleanup(struct lan743x_adapter *adapter) { + if (adapter->i2c_adap) + adapter->i2c_adap = NULL; + + if (adapter->nodes) + software_node_unregister_node_group(adapter->nodes->group); + + kfree(adapter->nodes); + lan743x_csr_write(adapter, INT_EN_CLR, 0xFFFFFFFF); } @@ -3282,9 +3481,18 @@ static int lan743x_hardware_init(struct lan743x_adapter *adapter, if (ret) return ret; - ret = lan743x_phy_init(adapter); - if (ret) - return ret; + if (adapter->is_sfp_support_en) { + ret = lan743x_swnodes_register(adapter); + if (ret) { + netdev_err(adapter->netdev, + "failed to register software nodes\n"); + return ret; + } + } else { + ret = lan743x_phy_init(adapter); + if (ret) + return ret; + } ret = lan743x_ptp_init(adapter); if (ret) diff --git a/drivers/net/ethernet/microchip/lan743x_main.h b/drivers/net/ethernet/microchip/lan743x_main.h index 3889bb20a524..7f1c5673bc61 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.h +++ b/drivers/net/ethernet/microchip/lan743x_main.h @@ -5,6 +5,7 @@ #define _LAN743X_H #include +#include #include "lan743x_ptp.h" #define DRIVER_AUTHOR "Bryan Whitehead " @@ -1008,6 +1009,34 @@ enum lan743x_sgmii_lsd { LINK_2500_SLAVE }; +enum lan743x_swnodes { + SWNODE_GPIO = 0, + SWNODE_I2C, + SWNODE_SFP, + SWNODE_PHYLINK, + SWNODE_MAX +}; + +struct lan743x_sw_nodes { + char gpio_name[32]; + char i2c_name[48]; + char sfp_name[32]; + char phylink_name[32]; + struct property_entry gpio_props[1]; + struct property_entry i2c_props[1]; + struct property_entry sfp_props[8]; + struct property_entry phylink_props[2]; + struct software_node_ref_args i2c_ref[1]; + struct software_node_ref_args tx_fault_ref[1]; + struct software_node_ref_args tx_disable_ref[1]; + struct software_node_ref_args mod_def0_ref[1]; + struct software_node_ref_args los_ref[1]; + struct software_node_ref_args rate_select0_ref[1]; + struct software_node_ref_args sfp_ref[1]; + struct software_node swnodes[SWNODE_MAX]; + const struct software_node *group[SWNODE_MAX + 1]; +}; + struct lan743x_adapter { struct net_device *netdev; struct mii_bus *mdiobus; @@ -1046,6 +1075,8 @@ struct lan743x_adapter { u32 flags; u32 hw_cfg; phy_interface_t phy_interface; + struct lan743x_sw_nodes *nodes; + struct i2c_adapter *i2c_adap; }; #define LAN743X_COMPONENT_FLAG_RX(channel) BIT(20 + (channel)) From patchwork Fri Jul 21 06:00:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raju Lakkaraju X-Patchwork-Id: 123574 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp3587822vqt; Thu, 20 Jul 2023 23:08:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlGU/OiEMx5efJATjHr6XIRalP7a27JOOr9UkgXA4Hn1quNwX7cqP1sP0iPPKjpaUu6AHp0Y X-Received: by 2002:a05:6358:3a12:b0:135:499a:382b with SMTP id g18-20020a0563583a1200b00135499a382bmr1056682rwe.7.1689919724737; Thu, 20 Jul 2023 23:08:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689919724; cv=none; d=google.com; s=arc-20160816; b=rLNHwG9ni00oTk1zYFCde1zQvdYWMNzBJtRA/I6ba2/w5mQeTLI1Ko37sQYm5S6LFL UryPtcl/ugkNkh+WPiFX7vuBZhbN9PXaFIZHQ28jcZhajnWQgDnvUXHRnAe7VP8lPROp OqMyh7Rc0WBTOhqNPP2w884tmPSaCthqhgxvw8/PXLTyMlvxB/pMEOC4Uuktlgc7BNiv dqA5cx/FMNTxRuUqmjIv9y0GAeaTZvMz/h+8N0gvLfHyhsi267QVZ0C2N1K+zNX/Xn5H v3XWTkJPKFHMXYdrW5zX64qoU+vZePWnRsDgVpOjASLkaR3Cyxq3SIAUa+WOs9aXXgx5 wEKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=z/LIelLPL3dtw01fa47slED5sEWdSEihUJRKuxouewA=; fh=qv6R2IaILI1S1xEIxOZzAcF4rN0hGtVsF9kjKc0mAD0=; b=0G6lsluTXjefY5wW96BZrIJRATX56gTIadltss80+LjkcVcTPBL2k7bo6yov46IYis gXqciG7/zvc3kLf24rQtG+H1p4uiiK2bpHh14mVEGECK0lVIVitALiEzjvu3IoudbRcr DfgYnZgl9Z5801OvCJ/HAxNSkGjmbnxNCdZJu8k/Vg7DOTtQnNb7CAMaji3KL3xNXzKa uGf+aHSUkh6lmDCa4185qkKI8YbakYwVPDBZ6Z4hzLDGMX/ImI01QJ0fI790oXWtVE3y vIXPvzLxAQWxe401LkEY/btjI1SZ2+/tifyOJb2beyAgBCOtYp+6zlhzEzWhNC0hkQmm oZ5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=FJSpIwbb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bs65-20020a632844000000b0055c8d01ad16si2237736pgb.265.2023.07.20.23.08.31; Thu, 20 Jul 2023 23:08:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=FJSpIwbb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230088AbjGUGBb (ORCPT + 99 others); Fri, 21 Jul 2023 02:01:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230053AbjGUGBP (ORCPT ); Fri, 21 Jul 2023 02:01:15 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EB833588; Thu, 20 Jul 2023 23:00:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1689919256; x=1721455256; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hsXHaUgeRKhymmmE9mLF/nwxqCUXefsE5jGEfnG1L10=; b=FJSpIwbb31/62cbTpoM/JTCCWzvjZcMDBdChTLInNvNeKmRW+Bor0ayE 1u9w32isVFdyOjCesfB7+TcsDmHhIpdsvaOewuheQ4J77BPsqpkTDhF9O knsVc6aG5TnIfDiecxvx8buLSaErC2vi3YNPHBJxblx3+UtPqpUHz3sZ1 3LjtaaYB3GMSNvSDgE5elZzMr9ibt8El5ErJwWJzLemoeFBxiGbgQRRVr wbxheqRMhyQcXkCyvTESuNTfprcTMjirwzb5OeI7/9CJnOR1popYjvX+S caVlFzWwlnrB2pDPKfZ0BSgcxYQZojLREL5npVV5JkhisP827oQBxjGrj g==; X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="221463601" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 20 Jul 2023 23:00:55 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Thu, 20 Jul 2023 23:00:50 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2507.21 via Frontend Transport; Thu, 20 Jul 2023 23:00:47 -0700 From: Raju Lakkaraju To: CC: , , , , , , Subject: [PATCH net-next 5/7] net: lan743x: Add support to the Phylink framework Date: Fri, 21 Jul 2023 11:30:17 +0530 Message-ID: <20230721060019.2737-6-Raju.Lakkaraju@microchip.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230721060019.2737-1-Raju.Lakkaraju@microchip.com> References: <20230721060019.2737-1-Raju.Lakkaraju@microchip.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772009265565248939 X-GMAIL-MSGID: 1772009265565248939 The phylink framework will be helpful in the future for boards using this controller with SFP cages. Signed-off-by: Raju Lakkaraju --- drivers/net/ethernet/microchip/Kconfig | 2 +- drivers/net/ethernet/microchip/lan743x_main.c | 314 +++++++++++++++++- drivers/net/ethernet/microchip/lan743x_main.h | 6 + 3 files changed, 314 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/microchip/Kconfig b/drivers/net/ethernet/microchip/Kconfig index b1d361b412d1..1c947e3437b7 100644 --- a/drivers/net/ethernet/microchip/Kconfig +++ b/drivers/net/ethernet/microchip/Kconfig @@ -46,7 +46,7 @@ config LAN743X tristate "LAN743x support" depends on PCI depends on PTP_1588_CLOCK_OPTIONAL - select FIXED_PHY + select PHYLINK select CRC16 select CRC32 select I2C_PCI1XXXX diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c index aef64747a952..9b6326d035a8 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.c +++ b/drivers/net/ethernet/microchip/lan743x_main.c @@ -1618,7 +1618,11 @@ static void lan743x_phy_interface_select(struct lan743x_adapter *adapter) data = lan743x_csr_read(adapter, MAC_CR); id_rev = adapter->csr.id_rev & ID_REV_ID_MASK_; - if (adapter->is_pci11x1x && adapter->is_sgmii_en) + if (adapter->is_pci11x1x && + adapter->is_sgmii_en && + adapter->is_sfp_support_en) + adapter->phy_interface = PHY_INTERFACE_MODE_2500BASEX; + else if (adapter->is_pci11x1x && adapter->is_sgmii_en) adapter->phy_interface = PHY_INTERFACE_MODE_SGMII; else if (id_rev == ID_REV_ID_LAN7430_) adapter->phy_interface = PHY_INTERFACE_MODE_GMII; @@ -1626,6 +1630,9 @@ static void lan743x_phy_interface_select(struct lan743x_adapter *adapter) adapter->phy_interface = PHY_INTERFACE_MODE_MII; else adapter->phy_interface = PHY_INTERFACE_MODE_RGMII; + + netif_dbg(adapter, drv, adapter->netdev, + "selected phy interface: 0x%X\n", adapter->phy_interface); } static int lan743x_phy_open(struct lan743x_adapter *adapter) @@ -3221,6 +3228,266 @@ static int lan743x_swnodes_register(struct lan743x_adapter *adapter) return software_node_register_node_group(nodes->group); } +static void lan743x_mac_cfg_update(struct lan743x_adapter *adapter, bool link, + int speed, const unsigned long *advertise) +{ + int mac_cr; + + mac_cr = lan743x_csr_read(adapter, MAC_CR); + mac_cr &= ~(MAC_CR_CFG_H_ | MAC_CR_CFG_L_); + if (link) { + if (speed == SPEED_2500) + mac_cr |= (MAC_CR_CFG_H_ | MAC_CR_CFG_L_); + else if (speed == SPEED_1000) + mac_cr |= (MAC_CR_CFG_H_); + else if (speed == SPEED_100) + mac_cr |= (MAC_CR_CFG_L_); + } else if (test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, advertise) || + test_bit(ETHTOOL_LINK_MODE_2500baseX_Full_BIT, advertise)) { + mac_cr |= (MAC_CR_CFG_H_ | MAC_CR_CFG_L_); + adapter->sgmii_lsd = LINK_2500_MASTER; + } else if (test_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, advertise) || + test_bit(ETHTOOL_LINK_MODE_1000baseX_Full_BIT, advertise)) { + mac_cr |= (MAC_CR_CFG_H_); + adapter->sgmii_lsd = LINK_1000_MASTER; + } else if (test_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, advertise) || + test_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT, advertise) || + test_bit(ETHTOOL_LINK_MODE_100baseFX_Full_BIT, advertise) || + test_bit(ETHTOOL_LINK_MODE_100baseFX_Half_BIT, advertise)) { + mac_cr |= (MAC_CR_CFG_L_); + adapter->sgmii_lsd = LINK_1000_MASTER; + } else { + adapter->sgmii_lsd = LINK_1000_MASTER; + } + + lan743x_csr_write(adapter, MAC_CR, mac_cr); +} + +static void lan743x_phylink_mac_config(struct phylink_config *config, + unsigned int link_an_mode, + const struct phylink_link_state *state) +{ + struct net_device *netdev = to_net_dev(config->dev); + struct lan743x_adapter *adapter = netdev_priv(netdev); + bool status; + int ret; + + lan743x_mac_cfg_update(adapter, state->link, state->speed, + state->advertising); + + if (!state->link && adapter->is_sgmii_en) { + ret = lan743x_sgmii_aneg_update(adapter); + if (ret < 0) { + netif_err(adapter, drv, adapter->netdev, + "error %d SGMII cfg failed\n", ret); + return; + } + + ret = lan743x_is_sgmii_2_5G_mode(adapter, &status); + if (ret < 0) { + netif_err(adapter, drv, adapter->netdev, + "erro %d SGMII get mode failed\n", ret); + return; + } + + if (status) + netif_dbg(adapter, drv, adapter->netdev, + "SGMII 2.5G mode enable\n"); + else + netif_dbg(adapter, drv, adapter->netdev, + "SGMII 1G mode enable\n"); + + ret = lan743x_pcs_power_reset(adapter); + if (ret < 0) { + netif_err(adapter, drv, adapter->netdev, + "error %d pcs power reset failed\n", ret); + return; + } + + phylink_mac_change(adapter->phylink, state->link); + } +} + +static void lan743x_phylink_mac_link_down(struct phylink_config *config, + unsigned int link_an_mode, + phy_interface_t interface) +{ + netif_tx_stop_all_queues(to_net_dev(config->dev)); +} + +static void lan743x_phylink_mac_link_up(struct phylink_config *config, + struct phy_device *phydev, + unsigned int link_an_mode, + phy_interface_t interface, + int speed, int duplex, + bool tx_pause, bool rx_pause) +{ + netif_tx_wake_all_queues(to_net_dev(config->dev)); +} + +static void lan743x_phylink_mac_pcs_get_state(struct phylink_config *config, + struct phylink_link_state *state) +{ + struct net_device *netdev = to_net_dev(config->dev); + struct lan743x_adapter *adapter = netdev_priv(netdev); + int intr_sts; + int wait_cnt; + bool status; + int mii_sts; + bool link; + int ret; + + wait_cnt = 0; + link = false; + while (wait_cnt++ < 10) { + mii_sts = lan743x_sgmii_read(adapter, MDIO_MMD_VEND2, MII_BMSR); + if (mii_sts < 0) { + netif_err(adapter, drv, adapter->netdev, + "erro %d MMD VEND2 MII BMSR read failed\n", + mii_sts); + return; + } + + mii_sts = lan743x_sgmii_read(adapter, MDIO_MMD_VEND2, MII_BMSR); + if (mii_sts < 0) { + netif_err(adapter, drv, adapter->netdev, + "erro %d MMD VEND2 MII BMSR read failed\n", + mii_sts); + return; + } + + if (mii_sts & SR_MII_STS_LINK_STS_) { + link = true; + break; + } + + usleep_range(1000, 2000); + } + + state->speed = SPEED_UNKNOWN; + state->duplex = DUPLEX_UNKNOWN; + if (link) { + int speed = SPEED_UNKNOWN; + int duplex = DUPLEX_UNKNOWN; + + intr_sts = lan743x_sgmii_read(adapter, MDIO_MMD_VEND2, + VR_MII_AN_INTR_STS); + if (intr_sts < 0) { + netif_err(adapter, drv, adapter->netdev, + "erro %d VR_MII_AN_INTR_STS read failed\n", + intr_sts); + return; + } + + if ((intr_sts & VR_MII_AN_INTR_STS_SPEED_MASK_) != + VR_MII_AN_INTR_STS_SPEED_MASK_) { + if (intr_sts & VR_MII_AN_INTR_STS_1000_MBPS_) + speed = SPEED_1000; + else if (intr_sts & VR_MII_AN_INTR_STS_100_MBPS_) + speed = SPEED_100; + else + speed = SPEED_10; + } + + if (intr_sts & VR_MII_AN_INTR_STS_FDX_) + duplex = DUPLEX_FULL; + else + duplex = DUPLEX_HALF; + + ret = lan743x_is_sgmii_2_5G_mode(adapter, &status); + if (ret < 0) { + netif_err(adapter, drv, adapter->netdev, + "erro %d SGMII get mode failed\n", ret); + return; + } + + if (adapter->is_sgmii_en && status) { + state->speed = SPEED_2500; + state->duplex = DUPLEX_FULL; + } else if (adapter->is_sgmii_en) { + state->speed = speed; + state->duplex = duplex; + } + } + + state->link = link; + + netif_dbg(adapter, drv, adapter->netdev, + "Link: %s, Speed:%d, %s Duplex\n", + state->link ? "Up" : "Down", + state->speed, (state->duplex == DUPLEX_FULL ? "Full" : + (state->duplex == DUPLEX_HALF ? "Half" : "Unknown"))); +} + +static const struct phylink_mac_ops lan743x_phylink_mac_ops = { + .validate = phylink_generic_validate, + .mac_config = lan743x_phylink_mac_config, + .mac_link_down = lan743x_phylink_mac_link_down, + .mac_link_up = lan743x_phylink_mac_link_up, + .mac_pcs_get_state = lan743x_phylink_mac_pcs_get_state, +}; + +static int lan743x_phylink_create(struct net_device *netdev) +{ + struct lan743x_adapter *adapter = netdev_priv(netdev); + struct fwnode_handle *fwnode; + struct phylink *phylink; + int ret; + + adapter->phylink_config.dev = &netdev->dev; + adapter->phylink_config.type = PHYLINK_NETDEV; + adapter->phylink_config.mac_managed_pm = true; + /* This driver makes use of state->speed in mac_config */ + adapter->phylink_config.legacy_pre_march2020 = true; + + adapter->phylink_config.mac_capabilities = MAC_ASYM_PAUSE | + MAC_SYM_PAUSE | MAC_10 | MAC_100 | MAC_1000FD | MAC_2500FD; + + /* Config serdes Interface */ + lan743x_phy_interface_select(adapter); + + if (adapter->is_sgmii_en) { + __set_bit(PHY_INTERFACE_MODE_SGMII, + adapter->phylink_config.supported_interfaces); + __set_bit(PHY_INTERFACE_MODE_1000BASEX, + adapter->phylink_config.supported_interfaces); + __set_bit(PHY_INTERFACE_MODE_2500BASEX, + adapter->phylink_config.supported_interfaces); + } + + fwnode = software_node_fwnode(adapter->nodes->group[SWNODE_PHYLINK]); + if (!fwnode) + return -ENODEV; + + phylink = phylink_create(&adapter->phylink_config, + fwnode, + adapter->phy_interface, + &lan743x_phylink_mac_ops); + + if (IS_ERR(phylink)) { + ret = PTR_ERR(phylink); + netdev_err(netdev, "Could not create phylink (%pe)\n", phylink); + return ret; + } + + adapter->phylink = phylink; + netdev_dbg(netdev, "lan743x phylink created"); + + return 0; +} + +static int lan743x_phylink_connect(struct lan743x_adapter *adapter) +{ + phylink_start(adapter->phylink); + + return 0; +} + +static void lan743x_phylink_close(struct lan743x_adapter *adapter) +{ + phylink_stop(adapter->phylink); +} + static int lan743x_netdev_close(struct net_device *netdev) { struct lan743x_adapter *adapter = netdev_priv(netdev); @@ -3234,7 +3501,10 @@ static int lan743x_netdev_close(struct net_device *netdev) lan743x_ptp_close(adapter); - lan743x_phy_close(adapter); + if (adapter->phylink) + lan743x_phylink_close(adapter); + else + lan743x_phy_close(adapter); lan743x_mac_close(adapter); @@ -3257,9 +3527,15 @@ static int lan743x_netdev_open(struct net_device *netdev) if (ret) goto close_intr; - ret = lan743x_phy_open(adapter); - if (ret) - goto close_mac; + if (adapter->phylink) { + ret = lan743x_phylink_connect(adapter); + if (ret) + goto close_mac; + } else { + ret = lan743x_phy_open(adapter); + if (ret) + goto close_mac; + } ret = lan743x_ptp_open(adapter); if (ret) @@ -3294,7 +3570,10 @@ static int lan743x_netdev_open(struct net_device *netdev) lan743x_ptp_close(adapter); close_phy: - lan743x_phy_close(adapter); + if (adapter->phylink) + lan743x_phylink_close(adapter); + else + lan743x_phy_close(adapter); close_mac: lan743x_mac_close(adapter); @@ -3323,10 +3602,16 @@ static netdev_tx_t lan743x_netdev_xmit_frame(struct sk_buff *skb, static int lan743x_netdev_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) { + struct lan743x_adapter *adapter = netdev_priv(netdev); + if (!netif_running(netdev)) return -EINVAL; if (cmd == SIOCSHWTSTAMP) return lan743x_ptp_ioctl(netdev, ifr, cmd); + + if (adapter->phylink) + return phylink_mii_ioctl(adapter->phylink, ifr, cmd); + return phy_mii_ioctl(netdev->phydev, ifr, cmd); } @@ -3427,6 +3712,9 @@ static void lan743x_hardware_cleanup(struct lan743x_adapter *adapter) if (adapter->i2c_adap) adapter->i2c_adap = NULL; + if (adapter->phylink) + phylink_destroy(adapter->phylink); + if (adapter->nodes) software_node_unregister_node_group(adapter->nodes->group); @@ -3650,9 +3938,21 @@ static int lan743x_pcidev_probe(struct pci_dev *pdev, adapter->netdev->features = NETIF_F_SG | NETIF_F_TSO | NETIF_F_HW_CSUM | NETIF_F_RXCSUM; adapter->netdev->hw_features = adapter->netdev->features; + /* Default Link-Speed-Duplex (LSD) state */ + adapter->sgmii_lsd = LINK_2500_MASTER; + + if (adapter->is_sfp_support_en) { + ret = lan743x_phylink_create(adapter->netdev); + if (ret) { + netif_err(adapter, probe, netdev, + "failed to setup phylink (%d)\n", ret); + goto cleanup_hardware; + } + } /* carrier off reporting is important to ethtool even BEFORE open */ - netif_carrier_off(netdev); + if (!adapter->phylink) + netif_carrier_off(netdev); ret = register_netdev(adapter->netdev); if (ret < 0) diff --git a/drivers/net/ethernet/microchip/lan743x_main.h b/drivers/net/ethernet/microchip/lan743x_main.h index 7f1c5673bc61..6b94d0e93cbb 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.h +++ b/drivers/net/ethernet/microchip/lan743x_main.h @@ -6,6 +6,7 @@ #include #include +#include #include "lan743x_ptp.h" #define DRIVER_AUTHOR "Bryan Whitehead " @@ -317,6 +318,9 @@ /* Vendor Specific SGMII MMD details */ #define SR_VSMMD_PCS_ID1 0x0004 #define SR_VSMMD_PCS_ID2 0x0005 +#define SR_MII_CTRL MII_BMCR +#define SR_MII_STS MII_BMSR +#define SR_MII_STS_LINK_STS_ BIT(2) #define SR_VSMMD_STS 0x0008 #define SR_VSMMD_CTRL 0x0009 @@ -1077,6 +1081,8 @@ struct lan743x_adapter { phy_interface_t phy_interface; struct lan743x_sw_nodes *nodes; struct i2c_adapter *i2c_adap; + struct phylink *phylink; + struct phylink_config phylink_config; }; #define LAN743X_COMPONENT_FLAG_RX(channel) BIT(20 + (channel)) From patchwork Fri Jul 21 06:00:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raju Lakkaraju X-Patchwork-Id: 123600 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp10321vqg; Thu, 20 Jul 2023 23:40:33 -0700 (PDT) X-Google-Smtp-Source: APBJJlFYMa6Ao+UubvtVqH+KYhFlWKHTELItMtU74DzG8SVXccuizaKmsxw19IjXmwUoKVmAHjWJ X-Received: by 2002:a17:906:2250:b0:977:ecff:3367 with SMTP id 16-20020a170906225000b00977ecff3367mr1055023ejr.40.1689921633102; Thu, 20 Jul 2023 23:40:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689921633; cv=none; d=google.com; s=arc-20160816; b=zOOGAFWAdbpF3x3XXpMghcJfoMpYZOcJyfUUnDd+ov/R+AVEveaY+3JdsDMze6IJA4 6Eu5FLdJDcGxVLc7bQ6K1J26ioy90juVXNSr5nBkkVfJFYmmI++dYxT232SUHXbA0Agy /c+Z6ohUxtDTWS8/3yvh7vnLfahhSExqkiOUnVdlEraKxvZBuTcGw7ZK9rpB/SbHZ2KR 8mPeakhlLE2x3NeJzll4i44K0xjs3o2XVPsZ6+pHoKleVkIn0xsX9QIO39vCEwBxWyWU VF3qQbshaJew1e7bVzKk5csxFFl216VSd7Ivh2W7uJ8x51Fjo5UrZKiEznuObUqsB8xT Z3pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PHiTZ9pzHqVBJ1YR4hHxUglPB5vWZzzVSCrV0mNZoZI=; fh=qv6R2IaILI1S1xEIxOZzAcF4rN0hGtVsF9kjKc0mAD0=; b=NmvT8zC3u+ajqEdpnLre62DfoSfaowAj2tABXpxjL7DfSf4tLUgRIbWN15GUcIf5qd QgdDhJLnnk+TZXYpyfFuB4J2zlLsqR/lE9+L/dY/jdO7hxWhyY0rdiQsW/dEhiZ4AeL0 oQseR582sGS5u03QT4sT4djt/KaokKTfra3eHrBze5YcmjHvdLPTq/p0+gvbgNGUx4aM t0gnsicirsQcGEP6SjY+/2bfWUdl+PPDiSL2QwgqeJcQ1UDKkm9F9hbktGUEkBG0As5X jXlBVnIXDARYIwEODNsG0piZJXtJtyqFmZMIHmiuWHMdQKqLn9icgq6HqmQ5dy6dLkyB iuNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b="Nm/P8HjB"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q22-20020a17090622d600b0099b488364f7si1733755eja.781.2023.07.20.23.40.09; Thu, 20 Jul 2023 23:40:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b="Nm/P8HjB"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229960AbjGUGB0 (ORCPT + 99 others); Fri, 21 Jul 2023 02:01:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229898AbjGUGBN (ORCPT ); Fri, 21 Jul 2023 02:01:13 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE9CA30FD; Thu, 20 Jul 2023 23:00:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1689919255; x=1721455255; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IJ4zMep/FrHtkrZh2iWP+xN+ImKeKg5u57KkhqSuw2I=; b=Nm/P8HjBZXokHMFAI7c4C/nHvrpR4wwyamp+axblIUMlYUjBaRcsUYEr IgbWZMhQGkmevxK/aCBhsXySycw4Y8WPNWa9lpkiCPbIxGeV2fAPGqoaE UIWeN0aHlbhwjw6H1lWoNul2WBNT2yC/oaubG+0JkFRY8cdd3q53X9RIE bo2s1RTwKvweaylpa/iKC1OWaDfkJDPrL8+3joDCvWL52wi59n5bnj1RZ qm5T0RxkycpSFgUBYfZ8JSAKvQFy6mEumLCgWkIgJJg/kLyvEHd/sMNHk w06K+BOIAiav/kk2Av01MuxoxNVI6ZGrBhwGSvdLO+3oUKmBmO9NIWCpl Q==; X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="236881402" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa1.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 20 Jul 2023 23:00:54 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Thu, 20 Jul 2023 23:00:54 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2507.21 via Frontend Transport; Thu, 20 Jul 2023 23:00:51 -0700 From: Raju Lakkaraju To: CC: , , , , , , Subject: [PATCH net-next 6/7] net: lan743x: Add support to ethtool phylink get and set settings Date: Fri, 21 Jul 2023 11:30:18 +0530 Message-ID: <20230721060019.2737-7-Raju.Lakkaraju@microchip.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230721060019.2737-1-Raju.Lakkaraju@microchip.com> References: <20230721060019.2737-1-Raju.Lakkaraju@microchip.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772011266295965210 X-GMAIL-MSGID: 1772011266295965210 Add support to ethtool phylink get/set settings for the network interface via ethtool like speed, duplex etc. Signed-off-by: Raju Lakkaraju --- .../net/ethernet/microchip/lan743x_ethtool.c | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan743x_ethtool.c b/drivers/net/ethernet/microchip/lan743x_ethtool.c index 2db5949b4c7e..3004863bebf8 100644 --- a/drivers/net/ethernet/microchip/lan743x_ethtool.c +++ b/drivers/net/ethernet/microchip/lan743x_ethtool.c @@ -1134,6 +1134,36 @@ static int lan743x_ethtool_set_eee(struct net_device *netdev, return phy_ethtool_set_eee(phydev, eee); } +static int lan743x_ethtool_set_link_ksettings(struct net_device *netdev, + const struct ethtool_link_ksettings *cmd) +{ + struct lan743x_adapter *adapter = netdev_priv(netdev); + int ret; + + if (adapter->phylink) { + ret = lan743x_lsd_update(cmd->base.speed, cmd->base.duplex, + cmd->base.master_slave_state); + if (ret < 0) + return ret; + + adapter->sgmii_lsd = ret; + return phylink_ethtool_ksettings_set(adapter->phylink, cmd); + } + + return phy_ethtool_set_link_ksettings(netdev, cmd); +} + +static int lan743x_ethtool_get_link_ksettings(struct net_device *netdev, + struct ethtool_link_ksettings *cmd) +{ + struct lan743x_adapter *adapter = netdev_priv(netdev); + + if (adapter->phylink) + return phylink_ethtool_ksettings_get(adapter->phylink, cmd); + + return phy_ethtool_get_link_ksettings(netdev, cmd); +} + #ifdef CONFIG_PM static void lan743x_ethtool_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) @@ -1400,8 +1430,8 @@ const struct ethtool_ops lan743x_ethtool_ops = { .get_ts_info = lan743x_ethtool_get_ts_info, .get_eee = lan743x_ethtool_get_eee, .set_eee = lan743x_ethtool_set_eee, - .get_link_ksettings = phy_ethtool_get_link_ksettings, - .set_link_ksettings = phy_ethtool_set_link_ksettings, + .get_link_ksettings = lan743x_ethtool_get_link_ksettings, + .set_link_ksettings = lan743x_ethtool_set_link_ksettings, .get_regs_len = lan743x_get_regs_len, .get_regs = lan743x_get_regs, .get_pauseparam = lan743x_get_pauseparam, From patchwork Fri Jul 21 06:00:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raju Lakkaraju X-Patchwork-Id: 123581 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp5292vqg; Thu, 20 Jul 2023 23:29:04 -0700 (PDT) X-Google-Smtp-Source: APBJJlEoUeEZ5FESBtaCVorlonJLuftjK6Claog6ZBEEYX8bT0fk9jv1Be0s0oLDmQPgBM07qFs/ X-Received: by 2002:ac2:55a6:0:b0:4fb:8948:2b28 with SMTP id y6-20020ac255a6000000b004fb89482b28mr520166lfg.63.1689920943992; Thu, 20 Jul 2023 23:29:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689920943; cv=none; d=google.com; s=arc-20160816; b=sdruzSzp0LC9T6Rk6L8k4KmhpIUdtVMJdCX3+4PSGcuJ4LFZnBOxO7T36d+hRThPA7 U1NKVT+w2oDn/J1su4bWgZ/XLQnos/VJmvydzcI0LxKkcqmT3B6idwRudx9TOTlIjTFk R0CDaZKXYpZV3FpRqyg1lG2SKP4N4CD8Ck958KAC6qDhOfmplStIqNoD33QemKdibx1o Xg9inf9DjipKbKq+X8hYkTTXI7ACPDS1eSbVA/NcqfOpI8C7N4Cup1wMvG7FtiX9ydeQ f0NcDakb5VRIAkXafct5IHPA0lYXPdZueDz5uoRtwJo1UsJiv+L3YtoIbmxxdDXUj1NM RnBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=p80kCnwOCIDmoxOFNe5JSeYev7M9S3l8k1ihri2Pt8I=; fh=qv6R2IaILI1S1xEIxOZzAcF4rN0hGtVsF9kjKc0mAD0=; b=HCc6rWvV6sVeqfctbH/DW9B9UvKJbR3o8IKgLGF/jPRtgDj00SoGE3Hy8VaOo/9T5G Eg8vEDUFCAXNtzcdpftWfSzH5FFliCyYeU4lUR1JM+Sb1oOwvJI6RPNKU6eS/1WgIoYw PaMOW/ZDQxb+O1Pzt39HyPgrvFX+q5UoLq41QTR/+jriQWxKsdODn/wcGnh8r+RICybQ A0DipRKjf0bxtcgne3BaQbmho/zz7yEFTLwAseFA1uJq9Od0//cSIlX1AdnKNJnf8AH4 UeJ3cPrCgWE4lh09ixh3KAeqS/nYGbVFgxJDQOhN75/dNqtHGVk5Z+/qyM07Gz5KuosL X5VQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=tLxUIX5i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z25-20020aa7cf99000000b0051e04f1bd62si1887377edx.199.2023.07.20.23.28.40; Thu, 20 Jul 2023 23:29:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=tLxUIX5i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230127AbjGUGCP (ORCPT + 99 others); Fri, 21 Jul 2023 02:02:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230106AbjGUGBi (ORCPT ); Fri, 21 Jul 2023 02:01:38 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8598E2D71; Thu, 20 Jul 2023 23:01:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1689919266; x=1721455266; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PDWlDkn/pWv4jXpv9tJcSNXd2XuUOWNjlBIyyKr9PC4=; b=tLxUIX5izNG03CH792s/eACXvt5lhEH+G7G6dfZrsbKmNRRKp18xyfM3 k1px2UeXvOZU+utrxN0Hv4qDn75kJjb3HHMXNe7q2sV8/5cVgjx+LQWIL utJ0bcsNQMFB3l4AQvk9bRjSOkfkcpzSo6ypv95JTL+84A67xzwMyhyY9 1wB6313MpSlGoiUWtfVuNyiIs20SSLqRBOfRN8zU4FJPzDo6PF3SBL3qS eCh7Z9w7Z+hbUJgrH0h65f0tQ6Mtd0cW1YIWmYsFBScVEgxw5L0d9z4RP rpaNhuwJflVEkqP8zydFq9CnQjcKWBn15wW+7uPw8f2uBhcEDUl7qtVH1 A==; X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="236881439" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa1.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 20 Jul 2023 23:00:59 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Thu, 20 Jul 2023 23:00:57 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2507.21 via Frontend Transport; Thu, 20 Jul 2023 23:00:54 -0700 From: Raju Lakkaraju To: CC: , , , , , , Subject: [PATCH net-next 7/7] net: lan743x: Register the platform device for sfp pluggable module Date: Fri, 21 Jul 2023 11:30:19 +0530 Message-ID: <20230721060019.2737-8-Raju.Lakkaraju@microchip.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230721060019.2737-1-Raju.Lakkaraju@microchip.com> References: <20230721060019.2737-1-Raju.Lakkaraju@microchip.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772010543606770764 X-GMAIL-MSGID: 1772010543606770764 Add support for SFP pluggable module as platform device handle the GPIO input and output signals and i2c bus access the SFP EEPROM data. Signed-off-by: Raju Lakkaraju --- drivers/net/ethernet/microchip/lan743x_main.c | 39 +++++++++++++++++++ drivers/net/ethernet/microchip/lan743x_main.h | 1 + 2 files changed, 40 insertions(+) diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c index 9b6326d035a8..2dd0965982fb 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.c +++ b/drivers/net/ethernet/microchip/lan743x_main.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "../../../misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.h" #include "lan743x_main.h" #include "lan743x_ethtool.h" @@ -3228,6 +3229,31 @@ static int lan743x_swnodes_register(struct lan743x_adapter *adapter) return software_node_register_node_group(nodes->group); } +static int lan743x_sfp_register(struct lan743x_adapter *adapter) +{ + struct pci_dev *pdev = adapter->pdev; + struct platform_device_info sfp_info; + struct platform_device *sfp_dev; + + memset(&sfp_info, 0, sizeof(sfp_info)); + sfp_info.parent = &adapter->pdev->dev; + sfp_info.fwnode = software_node_fwnode(adapter->nodes->group[SWNODE_SFP]); + sfp_info.name = "sfp"; + sfp_info.id = (pdev->bus->number << 8) | pdev->devfn; + sfp_dev = platform_device_register_full(&sfp_info); + if (IS_ERR(sfp_dev)) { + netif_err(adapter, drv, adapter->netdev, + "Failed to register SFP device\n"); + return PTR_ERR(sfp_dev); + } + + adapter->sfp_dev = sfp_dev; + netif_dbg(adapter, drv, adapter->netdev, + "SFP platform device registered"); + + return 0; +} + static void lan743x_mac_cfg_update(struct lan743x_adapter *adapter, bool link, int speed, const unsigned long *advertise) { @@ -3715,6 +3741,9 @@ static void lan743x_hardware_cleanup(struct lan743x_adapter *adapter) if (adapter->phylink) phylink_destroy(adapter->phylink); + if (adapter->sfp_dev) + platform_device_unregister(adapter->sfp_dev); + if (adapter->nodes) software_node_unregister_node_group(adapter->nodes->group); @@ -3942,6 +3971,16 @@ static int lan743x_pcidev_probe(struct pci_dev *pdev, adapter->sgmii_lsd = LINK_2500_MASTER; if (adapter->is_sfp_support_en) { + adapter->i2c_adap->dev.fwnode = + software_node_fwnode(adapter->nodes->group[SWNODE_I2C]); + + ret = lan743x_sfp_register(adapter); + if (ret < 0) { + netif_err(adapter, probe, netdev, + "failed to sfp register (%d)\n", ret); + goto cleanup_hardware; + } + ret = lan743x_phylink_create(adapter->netdev); if (ret) { netif_err(adapter, probe, netdev, diff --git a/drivers/net/ethernet/microchip/lan743x_main.h b/drivers/net/ethernet/microchip/lan743x_main.h index 6b94d0e93cbb..d23cf1ca888c 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.h +++ b/drivers/net/ethernet/microchip/lan743x_main.h @@ -1083,6 +1083,7 @@ struct lan743x_adapter { struct i2c_adapter *i2c_adap; struct phylink *phylink; struct phylink_config phylink_config; + struct platform_device *sfp_dev; }; #define LAN743X_COMPONENT_FLAG_RX(channel) BIT(20 + (channel))