From patchwork Thu Jan 27 17:30:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raju Lakkaraju - I30499 X-Patchwork-Id: 12727134 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F3C5C433F5 for ; Thu, 27 Jan 2022 17:31:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240561AbiA0RbF (ORCPT ); Thu, 27 Jan 2022 12:31:05 -0500 Received: from esa.microchip.iphmx.com ([68.232.154.123]:57213 "EHLO esa.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238232AbiA0RbF (ORCPT ); Thu, 27 Jan 2022 12:31:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1643304664; x=1674840664; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=F8/6AyDwHbuCM2xmbOtVCusdSb7+rM42lQXfetuf4KQ=; b=ipbaIzNVeH6npJQoMfxxRCSywmXqwV5b4PKWuxZT8wxjDBBE30cgTgmw 5ATTe58zrIoZeRzbV4AmuBD79RaNjSVX9+EstIzextdX+2mIFurBkr9iz uj6lUZXW556uM1JxUha1d5lK356on/JnYEZhFRNIqdxRcc/P/1l1KFvVJ yM9ANkOIMIWB5PdsZ6ATjP+Fy9IKQtXideKS/U9i3M1EiM74WBpnGBx38 Kfmpm3/LylKBghTDFi2JETbUNX98/yuO6RvtDctUOpSUCSvtl55k1xBa1 Mkp1rix5/RFt/Uea0SxzWdj7UnWMP6u0bdwaSH5kPwteB6PNN/QM4ip85 g==; IronPort-SDR: pz9BU9mivLsF95UlfUjMhsw4jKuJckBWrJzk6KCXsOg1AWiAt+T6qsMIP531dtR7ltWMPmIwVS WdSeVVNvG4zQk9OyitW5IPzjy/8yVeO8znq29AgUMMcJEfUpC5VmDsg5DCozb90YhgviUQkaTb 9m0XBPSq27f6cPmLvqPq6hvNPqqMK+CCg8CutAJopAnHUF98NIqWGxnv1VEqlKz7JMOfnwiGB3 g/CWJlEUYRR9HPsLHrGhkrmE6XDz+b74XxoYI3ISdCTFyWpZankMi3ij78u+UXUKsjhcQz9B5+ +E68rifpe0AGBt3mcyJpfuYg X-IronPort-AV: E=Sophos;i="5.88,321,1635231600"; d="scan'208";a="83901346" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 27 Jan 2022 10:31:04 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) 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.2375.17; Thu, 27 Jan 2022 10:31:04 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Thu, 27 Jan 2022 10:31:02 -0700 From: Raju Lakkaraju To: CC: , , Subject: [PATCH net-next 1/5] net: lan743x: Add PCI1A011/PCI1A041 chip driver Date: Thu, 27 Jan 2022 23:00:51 +0530 Message-ID: <20220127173055.308918-2-Raju.Lakkaraju@microchip.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220127173055.308918-1-Raju.Lakkaraju@microchip.com> References: <20220127173055.308918-1-Raju.Lakkaraju@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org PCI1A011/PCI1A041 chip is enhancement of Ethernet LAN743x chip family. Signed-off-by: Raju Lakkaraju --- drivers/net/ethernet/microchip/lan743x_main.c | 6 ++++++ drivers/net/ethernet/microchip/lan743x_main.h | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c index 8c6390d95158..49eeff8757e5 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.c +++ b/drivers/net/ethernet/microchip/lan743x_main.c @@ -2758,6 +2758,10 @@ static int lan743x_mdiobus_init(struct lan743x_adapter *adapter) if ((adapter->csr.id_rev & ID_REV_ID_MASK_) == ID_REV_ID_LAN7430_) /* LAN7430 uses internal phy at address 1 */ adapter->mdiobus->phy_mask = ~(u32)BIT(1); + else if (((adapter->csr.id_rev & ID_REV_ID_MASK_) == ID_REV_ID_PCIA011_) || + ((adapter->csr.id_rev & ID_REV_ID_MASK_) == ID_REV_ID_PCIA041_)) + /* PCIA011/PCIA041 uses internal phy at address 1 */ + adapter->mdiobus->phy_mask = ~(u32)BIT(1); /* register mdiobus */ ret = mdiobus_register(adapter->mdiobus); @@ -3056,6 +3060,8 @@ static const struct dev_pm_ops lan743x_pm_ops = { static const struct pci_device_id lan743x_pcidev_tbl[] = { { PCI_DEVICE(PCI_VENDOR_ID_SMSC, PCI_DEVICE_ID_SMSC_LAN7430) }, { PCI_DEVICE(PCI_VENDOR_ID_SMSC, PCI_DEVICE_ID_SMSC_LAN7431) }, + { PCI_DEVICE(PCI_VENDOR_ID_SMSC, PCI_DEVICE_ID_SMSC_PCIA011) }, + { PCI_DEVICE(PCI_VENDOR_ID_SMSC, PCI_DEVICE_ID_SMSC_PCIA041) }, { 0, } }; diff --git a/drivers/net/ethernet/microchip/lan743x_main.h b/drivers/net/ethernet/microchip/lan743x_main.h index aaf7aaeaba0c..a9d722f719f9 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.h +++ b/drivers/net/ethernet/microchip/lan743x_main.h @@ -16,8 +16,12 @@ #define ID_REV_ID_MASK_ (0xFFFF0000) #define ID_REV_ID_LAN7430_ (0x74300000) #define ID_REV_ID_LAN7431_ (0x74310000) -#define ID_REV_IS_VALID_CHIP_ID_(id_rev) \ - (((id_rev) & 0xFFF00000) == 0x74300000) +#define ID_REV_ID_PCIA011_ (0xA0110000) // PCI11010 +#define ID_REV_ID_PCIA041_ (0xA0410000) // PCI11414 +#define ID_REV_IS_VALID_CHIP_ID_(id_rev) \ + ((((id_rev) & 0xFFF00000) == 0x74300000) || \ + (((id_rev) & 0xFFF00000) == 0xA0100000) || \ + (((id_rev) & 0xFFF00000) == 0xA0400000)) #define ID_REV_CHIP_REV_MASK_ (0x0000FFFF) #define ID_REV_CHIP_REV_A0_ (0x00000000) #define ID_REV_CHIP_REV_B0_ (0x00000010) @@ -559,6 +563,8 @@ struct lan743x_adapter; #define PCI_VENDOR_ID_SMSC PCI_VENDOR_ID_EFAR #define PCI_DEVICE_ID_SMSC_LAN7430 (0x7430) #define PCI_DEVICE_ID_SMSC_LAN7431 (0x7431) +#define PCI_DEVICE_ID_SMSC_PCIA011 (0xA011) +#define PCI_DEVICE_ID_SMSC_PCIA041 (0xA041) #define PCI_CONFIG_LENGTH (0x1000) From patchwork Thu Jan 27 17:30:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raju Lakkaraju - I30499 X-Patchwork-Id: 12727135 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94E4BC433F5 for ; Thu, 27 Jan 2022 17:31:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243509AbiA0RbI (ORCPT ); Thu, 27 Jan 2022 12:31:08 -0500 Received: from esa.microchip.iphmx.com ([68.232.154.123]:32122 "EHLO esa.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241602AbiA0RbH (ORCPT ); Thu, 27 Jan 2022 12:31:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1643304667; x=1674840667; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XvwmIP89LS3O/UopTr9pAPqkBncFWKxPM5cMEZS0mhY=; b=mAmIIlJ6FDKI1GBldKctFYVN2YWXP9ZoAUhIpET1hORuUIGUmrg8d6ow ZhNpPrAvibCMHy8MIV8Abjk8eHCSWJce/A5XiAf0niTtHqqlrDPmSa3VV glSea23tJ9VoEcl/8q9py70KNGdaA3lVC9UAqcX0yyNzc2rjLN8fnolDK lNWbFKeucUHxgcBniim8J6/lVzx4Z5d22yWrU3FqNDP50rlsKrgcFmTqz lc/CCxKhhOwvjALam23sszK2ptQxe5kYXGMibH5Vr1zg9o2mGo8tmR6UN PX3tmzqKZ+gwR7lPLdnrkVre10jcI3UaHeYP5Nhfy2Xn5tgEesRJkfUkY w==; IronPort-SDR: wMYHqoiHhZlXkl6O+sqJ3PTbhx8AEaDr4moRwQiwjQ4oHJ9I2VQgjlY0YWStWRWS4kd17jXYp2 YskfnK/g1jt7y8Sa6tbwhqFWsceLtaFB9On7btcf5nMwi8/cjimAJiFwXWOrKlqLe2Gc8Lm5dp tgPVNPVTRpYDURV37t5LEvg4s0yUGg0ugEkJyYBpWhKbA6TNK90YYwywRgqE4rb07dtFZW3ChU /u/UFA3O2vVlVAXo2Bni3/hUBRxLf1H+W+0n+FScg9UvEvY/CyiyA2A9W81x6xUcwpjEROEXLK C5591adnU0V+eUqEftxv5atU X-IronPort-AV: E=Sophos;i="5.88,321,1635231600"; d="scan'208";a="144113622" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 27 Jan 2022 10:31:06 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) 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.2375.17; Thu, 27 Jan 2022 10:31:07 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Thu, 27 Jan 2022 10:31:04 -0700 From: Raju Lakkaraju To: CC: , , Subject: [PATCH net-next 2/5] net: lan743x: Add Tx 4 Queue enhancements Date: Thu, 27 Jan 2022 23:00:52 +0530 Message-ID: <20220127173055.308918-3-Raju.Lakkaraju@microchip.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220127173055.308918-1-Raju.Lakkaraju@microchip.com> References: <20220127173055.308918-1-Raju.Lakkaraju@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org PCI1A011/PCI1A041 chip support the 4 Tx Queues Signed-off-by: Raju Lakkaraju --- drivers/net/ethernet/microchip/lan743x_main.c | 85 +++++++++++++++---- drivers/net/ethernet/microchip/lan743x_main.h | 10 ++- drivers/net/ethernet/microchip/lan743x_ptp.c | 8 +- 3 files changed, 80 insertions(+), 23 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c index 49eeff8757e5..ce97c8ce8b1c 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.c +++ b/drivers/net/ethernet/microchip/lan743x_main.c @@ -18,6 +18,18 @@ #include "lan743x_main.h" #include "lan743x_ethtool.h" +static bool is_pcia0x1_chip(struct lan743x_adapter *adapter) +{ + struct lan743x_csr *csr = &adapter->csr; + u32 id_rev = csr->id_rev; + + if (((id_rev & 0xFFFF0000) == ID_REV_ID_PCIA011_) || + ((id_rev & 0xFFFF0000) == ID_REV_ID_PCIA041_)) { + return true; + } + return false; +} + static void lan743x_pci_cleanup(struct lan743x_adapter *adapter) { pci_release_selected_regions(adapter->pdev, @@ -250,7 +262,7 @@ static void lan743x_intr_shared_isr(void *context, u32 int_sts, u32 flags) } } if (int_sts & INT_BIT_ALL_TX_) { - for (channel = 0; channel < LAN743X_USED_TX_CHANNELS; + for (channel = 0; channel < adapter->max_used_tx_channels; channel++) { u32 int_bit = INT_BIT_DMA_TX_(channel); @@ -447,6 +459,7 @@ static int lan743x_intr_open(struct lan743x_adapter *adapter) { struct msix_entry msix_entries[LAN743X_MAX_VECTOR_COUNT]; struct lan743x_intr *intr = &adapter->intr; + unsigned int max_used_tx_channels; u32 int_vec_en_auto_clr = 0; u32 int_vec_map0 = 0; u32 int_vec_map1 = 0; @@ -461,9 +474,10 @@ static int lan743x_intr_open(struct lan743x_adapter *adapter) sizeof(struct msix_entry) * LAN743X_MAX_VECTOR_COUNT); for (index = 0; index < LAN743X_MAX_VECTOR_COUNT; index++) msix_entries[index].entry = index; + max_used_tx_channels = adapter->max_used_tx_channels; ret = pci_enable_msix_range(adapter->pdev, msix_entries, 1, - 1 + LAN743X_USED_TX_CHANNELS + + 1 + max_used_tx_channels + LAN743X_USED_RX_CHANNELS); if (ret > 0) { @@ -570,8 +584,8 @@ static int lan743x_intr_open(struct lan743x_adapter *adapter) if (intr->number_of_vectors > 1) { int number_of_tx_vectors = intr->number_of_vectors - 1; - if (number_of_tx_vectors > LAN743X_USED_TX_CHANNELS) - number_of_tx_vectors = LAN743X_USED_TX_CHANNELS; + if (number_of_tx_vectors > max_used_tx_channels) + number_of_tx_vectors = max_used_tx_channels; flags = LAN743X_VECTOR_FLAG_SOURCE_STATUS_READ | LAN743X_VECTOR_FLAG_SOURCE_STATUS_W2C | LAN743X_VECTOR_FLAG_SOURCE_ENABLE_CHECK | @@ -609,9 +623,9 @@ static int lan743x_intr_open(struct lan743x_adapter *adapter) INT_VEC_EN_(vector)); } } - if ((intr->number_of_vectors - LAN743X_USED_TX_CHANNELS) > 1) { + if ((intr->number_of_vectors - max_used_tx_channels) > 1) { int number_of_rx_vectors = intr->number_of_vectors - - LAN743X_USED_TX_CHANNELS - 1; + max_used_tx_channels - 1; if (number_of_rx_vectors > LAN743X_USED_RX_CHANNELS) number_of_rx_vectors = LAN743X_USED_RX_CHANNELS; @@ -2489,9 +2503,12 @@ static int lan743x_rx_open(struct lan743x_rx *rx) static int lan743x_netdev_close(struct net_device *netdev) { struct lan743x_adapter *adapter = netdev_priv(netdev); + unsigned int max_used_tx_channels; int index; - lan743x_tx_close(&adapter->tx[0]); + max_used_tx_channels = adapter->max_used_tx_channels; + for (index = 0; index < max_used_tx_channels; index++) + lan743x_tx_close(&adapter->tx[index]); for (index = 0; index < LAN743X_USED_RX_CHANNELS; index++) lan743x_rx_close(&adapter->rx[index]); @@ -2537,12 +2554,19 @@ static int lan743x_netdev_open(struct net_device *netdev) goto close_rx; } - ret = lan743x_tx_open(&adapter->tx[0]); - if (ret) - goto close_rx; - + for (index = 0; index < adapter->max_used_tx_channels; index++) { + ret = lan743x_tx_open(&adapter->tx[index]); + if (ret) + goto close_tx; + } return 0; +close_tx: + for (index = 0; index < adapter->max_used_tx_channels; index++) { + if (adapter->tx[index].ring_cpu_ptr) + lan743x_tx_close(&adapter->tx[index]); + } + close_rx: for (index = 0; index < LAN743X_USED_RX_CHANNELS; index++) { if (adapter->rx[index].ring_cpu_ptr) @@ -2569,8 +2593,12 @@ static netdev_tx_t lan743x_netdev_xmit_frame(struct sk_buff *skb, struct net_device *netdev) { struct lan743x_adapter *adapter = netdev_priv(netdev); + u8 ch = 0; + + if (adapter->is_pcia0x1) + ch = skb->queue_mapping % PCIA0X1_MAX_TX_CHANNELS; - return lan743x_tx_xmit_frame(&adapter->tx[0], skb); + return lan743x_tx_xmit_frame(&adapter->tx[ch], skb); } static int lan743x_netdev_ioctl(struct net_device *netdev, @@ -2701,6 +2729,15 @@ static int lan743x_hardware_init(struct lan743x_adapter *adapter, int index; int ret; + adapter->is_pcia0x1 = is_pcia0x1_chip(adapter); + if (adapter->is_pcia0x1) { + adapter->max_tx_channels = PCIA0X1_MAX_TX_CHANNELS; + adapter->max_used_tx_channels = PCIA0X1_USED_TX_CHANNELS; + } else { + adapter->max_tx_channels = LAN743X_MAX_TX_CHANNELS; + adapter->max_used_tx_channels = LAN743X_USED_TX_CHANNELS; + } + adapter->intr.irq = adapter->pdev->irq; lan743x_csr_write(adapter, INT_EN_CLR, 0xFFFFFFFF); @@ -2731,10 +2768,13 @@ static int lan743x_hardware_init(struct lan743x_adapter *adapter, adapter->rx[index].channel_number = index; } - tx = &adapter->tx[0]; - tx->adapter = adapter; - tx->channel_number = 0; - spin_lock_init(&tx->ring_lock); + for (index = 0; index < adapter->max_used_tx_channels; index++) { + tx = &adapter->tx[index]; + tx->adapter = adapter; + tx->channel_number = index; + spin_lock_init(&tx->ring_lock); + } + return 0; } @@ -2790,8 +2830,17 @@ static int lan743x_pcidev_probe(struct pci_dev *pdev, struct net_device *netdev = NULL; int ret = -ENODEV; - netdev = devm_alloc_etherdev(&pdev->dev, - sizeof(struct lan743x_adapter)); + if ((id->device == (ID_REV_ID_PCIA011_ >> 16)) || + (id->device == (ID_REV_ID_PCIA041_ >> 16))) { + netdev = devm_alloc_etherdev_mqs(&pdev->dev, + sizeof(struct lan743x_adapter), + PCIA0X1_MAX_TX_CHANNELS, + LAN743X_MAX_RX_CHANNELS); + } else { + netdev = devm_alloc_etherdev(&pdev->dev, + sizeof(struct lan743x_adapter)); + } + if (!netdev) goto return_error; diff --git a/drivers/net/ethernet/microchip/lan743x_main.h b/drivers/net/ethernet/microchip/lan743x_main.h index a9d722f719f9..d7b1b5e44518 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.h +++ b/drivers/net/ethernet/microchip/lan743x_main.h @@ -545,10 +545,12 @@ #define LAN743X_MAX_RX_CHANNELS (4) #define LAN743X_MAX_TX_CHANNELS (1) +#define PCIA0X1_MAX_TX_CHANNELS (4) struct lan743x_adapter; #define LAN743X_USED_RX_CHANNELS (4) #define LAN743X_USED_TX_CHANNELS (1) +#define PCIA0X1_USED_TX_CHANNELS (4) #define LAN743X_INT_MOD (400) #if (LAN743X_USED_RX_CHANNELS > LAN743X_MAX_RX_CHANNELS) @@ -557,6 +559,9 @@ struct lan743x_adapter; #if (LAN743X_USED_TX_CHANNELS > LAN743X_MAX_TX_CHANNELS) #error Invalid LAN743X_USED_TX_CHANNELS #endif +#if (PCIA0X1_USED_TX_CHANNELS > PCIA0X1_MAX_TX_CHANNELS) +#error Invalid PCIA0X1_USED_TX_CHANNELS +#endif /* PCI */ /* SMSC acquired EFAR late 1990's, MCHP acquired SMSC 2012 */ @@ -727,8 +732,11 @@ struct lan743x_adapter { u8 mac_address[ETH_ALEN]; struct lan743x_phy phy; - struct lan743x_tx tx[LAN743X_MAX_TX_CHANNELS]; + struct lan743x_tx tx[PCIA0X1_MAX_TX_CHANNELS]; struct lan743x_rx rx[LAN743X_MAX_RX_CHANNELS]; + bool is_pcia0x1; + u8 max_tx_channels; + u8 max_used_tx_channels; #define LAN743X_ADAPTER_FLAG_OTP BIT(0) u32 flags; diff --git a/drivers/net/ethernet/microchip/lan743x_ptp.c b/drivers/net/ethernet/microchip/lan743x_ptp.c index 8b7a8d879083..e0e8bc352134 100644 --- a/drivers/net/ethernet/microchip/lan743x_ptp.c +++ b/drivers/net/ethernet/microchip/lan743x_ptp.c @@ -1307,21 +1307,21 @@ int lan743x_ptp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) switch (config.tx_type) { case HWTSTAMP_TX_OFF: - for (index = 0; index < LAN743X_MAX_TX_CHANNELS; - index++) + for (index = 0; index < adapter->max_tx_channels; + index++) lan743x_tx_set_timestamping_mode(&adapter->tx[index], false, false); lan743x_ptp_set_sync_ts_insert(adapter, false); break; case HWTSTAMP_TX_ON: - for (index = 0; index < LAN743X_MAX_TX_CHANNELS; + for (index = 0; index < adapter->max_tx_channels; index++) lan743x_tx_set_timestamping_mode(&adapter->tx[index], true, false); lan743x_ptp_set_sync_ts_insert(adapter, false); break; case HWTSTAMP_TX_ONESTEP_SYNC: - for (index = 0; index < LAN743X_MAX_TX_CHANNELS; + for (index = 0; index < adapter->max_tx_channels; index++) lan743x_tx_set_timestamping_mode(&adapter->tx[index], true, true); From patchwork Thu Jan 27 17:30:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raju Lakkaraju - I30499 X-Patchwork-Id: 12727136 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B162C433EF for ; Thu, 27 Jan 2022 17:31:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241602AbiA0RbM (ORCPT ); Thu, 27 Jan 2022 12:31:12 -0500 Received: from esa.microchip.iphmx.com ([68.232.154.123]:57213 "EHLO esa.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244590AbiA0RbK (ORCPT ); Thu, 27 Jan 2022 12:31:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1643304670; x=1674840670; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cpRZx4IhilKUxpJCI7B+EuOwwo+7TJWxSBDt/W0BKgg=; b=w0Vd01bhD20BKUexsA7kKmTO8loFpGJ1OBlIH1ZLsySYxUlucwpVn8UT DaqBUxUKGlO03OTgPwsIS8Xo1uIivRM4E+xoxadR5YjOw41ptCWXaQVfb Gm3wF7W27Fb8DSWR9ZdIKGDiZbIdwBh6qxPdMqlvSgpduw7DchUSLZxY/ K1Bvkxgi3RxeWxUfZ7Rwhs/q/5gsXP8cJZF+3uADWmhRzq8QIbkTosO6Z OGs+gTxlXI3+OJUtZaNHbIVc8uWHMXyrouaQVQpy2El1zI7Dp6p+MqF/a qA2EDlJ46FUO1fGJILi/2pzm8i1reaGY4LT8wVyt8lq+2CPr+5r9dJOjY w==; IronPort-SDR: zlqQ+i5xDQ8FnkDqLr4manO2VBo3p6Ex3/Ed7nZ2311ExjsFRrBc6o7uYfS3k+fhs8XqdjXx5I F82wcDmHM/vKWB/J6bJ9i2+kr8Ip8+wvf6IvSgTXt9yLWfwpuVsKdsoYOTg95T2h3uRVT1ez6Z 8KE5pWX4x71GN7v8gXr+ajycy5W7zJqJoextV+IhN9iwM943vd0lyimfhGMSG2JL0AboLlGxOv U29xiYDjbGWzeed3hAVINYgO9XR+eYzs85UNMCzv/WNKCcX5fJPHVyEEpou+je8ZByhq2dN5fJ smkNMWCryBuJKIUzJmAvQFR0 X-IronPort-AV: E=Sophos;i="5.88,321,1635231600"; d="scan'208";a="83901379" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 27 Jan 2022 10:31:09 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) 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.2375.17; Thu, 27 Jan 2022 10:31:09 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Thu, 27 Jan 2022 10:31:07 -0700 From: Raju Lakkaraju To: CC: , , Subject: [PATCH net-next 3/5] net: lan743x: Add MSI-X interrupts increased from 8 to 16 and Interrupt De-assertion timers increased from 8 to 16 Date: Thu, 27 Jan 2022 23:00:53 +0530 Message-ID: <20220127173055.308918-4-Raju.Lakkaraju@microchip.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220127173055.308918-1-Raju.Lakkaraju@microchip.com> References: <20220127173055.308918-1-Raju.Lakkaraju@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org PCI1A011/PCI1A041 support upto 16 MSI-X interrupts and 16 De-assertion timers Signed-off-by: Raju Lakkaraju --- drivers/net/ethernet/microchip/lan743x_main.c | 37 +++++++++++++++---- drivers/net/ethernet/microchip/lan743x_main.h | 6 ++- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c index ce97c8ce8b1c..daba17b0ad6c 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.c +++ b/drivers/net/ethernet/microchip/lan743x_main.c @@ -422,7 +422,7 @@ static u32 lan743x_intr_get_vector_flags(struct lan743x_adapter *adapter, { int index; - for (index = 0; index < LAN743X_MAX_VECTOR_COUNT; index++) { + for (index = 0; index < adapter->max_vector_counter; index++) { if (adapter->intr.vector_list[index].int_mask & int_mask) return adapter->intr.vector_list[index].flags; } @@ -435,9 +435,12 @@ static void lan743x_intr_close(struct lan743x_adapter *adapter) int index = 0; lan743x_csr_write(adapter, INT_EN_CLR, INT_BIT_MAS_); - lan743x_csr_write(adapter, INT_VEC_EN_CLR, 0x000000FF); + if (adapter->is_pcia0x1) + lan743x_csr_write(adapter, INT_VEC_EN_CLR, 0x0000FFFF); + else + lan743x_csr_write(adapter, INT_VEC_EN_CLR, 0x000000FF); - for (index = 0; index < LAN743X_MAX_VECTOR_COUNT; index++) { + for (index = 0; index < intr->number_of_vectors; index++) { if (intr->flags & INTR_FLAG_IRQ_REQUESTED(index)) { lan743x_intr_unregister_isr(adapter, index); intr->flags &= ~INTR_FLAG_IRQ_REQUESTED(index); @@ -457,10 +460,11 @@ static void lan743x_intr_close(struct lan743x_adapter *adapter) static int lan743x_intr_open(struct lan743x_adapter *adapter) { - struct msix_entry msix_entries[LAN743X_MAX_VECTOR_COUNT]; + struct msix_entry msix_entries[PCIA0X1_MAX_VECTOR_COUNT]; struct lan743x_intr *intr = &adapter->intr; unsigned int max_used_tx_channels; u32 int_vec_en_auto_clr = 0; + u8 max_vector_counter; u32 int_vec_map0 = 0; u32 int_vec_map1 = 0; int ret = -ENODEV; @@ -470,9 +474,10 @@ static int lan743x_intr_open(struct lan743x_adapter *adapter) intr->number_of_vectors = 0; /* Try to set up MSIX interrupts */ + max_vector_counter = adapter->max_vector_counter; memset(&msix_entries[0], 0, - sizeof(struct msix_entry) * LAN743X_MAX_VECTOR_COUNT); - for (index = 0; index < LAN743X_MAX_VECTOR_COUNT; index++) + sizeof(struct msix_entry) * max_vector_counter); + for (index = 0; index < max_vector_counter; index++) msix_entries[index].entry = index; max_used_tx_channels = adapter->max_used_tx_channels; ret = pci_enable_msix_range(adapter->pdev, @@ -561,7 +566,21 @@ static int lan743x_intr_open(struct lan743x_adapter *adapter) lan743x_csr_write(adapter, INT_VEC_EN_SET, INT_VEC_EN_(0)); - if (!(adapter->csr.flags & LAN743X_CSR_FLAG_IS_A0)) { + if (adapter->is_pcia0x1) { + lan743x_csr_write(adapter, INT_MOD_CFG0, LAN743X_INT_MOD); + lan743x_csr_write(adapter, INT_MOD_CFG1, LAN743X_INT_MOD); + lan743x_csr_write(adapter, INT_MOD_CFG2, LAN743X_INT_MOD); + lan743x_csr_write(adapter, INT_MOD_CFG3, LAN743X_INT_MOD); + lan743x_csr_write(adapter, INT_MOD_CFG4, LAN743X_INT_MOD); + lan743x_csr_write(adapter, INT_MOD_CFG5, LAN743X_INT_MOD); + lan743x_csr_write(adapter, INT_MOD_CFG6, LAN743X_INT_MOD); + lan743x_csr_write(adapter, INT_MOD_CFG7, LAN743X_INT_MOD); + lan743x_csr_write(adapter, INT_MOD_CFG8, LAN743X_INT_MOD); + lan743x_csr_write(adapter, INT_MOD_CFG9, LAN743X_INT_MOD); + lan743x_csr_write(adapter, INT_MOD_MAP0, 0x00008765); + lan743x_csr_write(adapter, INT_MOD_MAP1, 0x00004321); + lan743x_csr_write(adapter, INT_MOD_MAP2, 0x00FFFFFF); + } else if (!(adapter->csr.flags & LAN743X_CSR_FLAG_IS_A0)) { lan743x_csr_write(adapter, INT_MOD_CFG0, LAN743X_INT_MOD); lan743x_csr_write(adapter, INT_MOD_CFG1, LAN743X_INT_MOD); lan743x_csr_write(adapter, INT_MOD_CFG2, LAN743X_INT_MOD); @@ -646,7 +665,7 @@ static int lan743x_intr_open(struct lan743x_adapter *adapter) LAN743X_VECTOR_FLAG_SOURCE_STATUS_AUTO_CLEAR; } for (index = 0; index < number_of_rx_vectors; index++) { - int vector = index + 1 + LAN743X_USED_TX_CHANNELS; + int vector = index + 1 + max_used_tx_channels; u32 int_bit = INT_BIT_DMA_RX_(index); /* map RX interrupt to vector */ @@ -2733,9 +2752,11 @@ static int lan743x_hardware_init(struct lan743x_adapter *adapter, if (adapter->is_pcia0x1) { adapter->max_tx_channels = PCIA0X1_MAX_TX_CHANNELS; adapter->max_used_tx_channels = PCIA0X1_USED_TX_CHANNELS; + adapter->max_vector_counter = PCIA0X1_MAX_VECTOR_COUNT; } else { adapter->max_tx_channels = LAN743X_MAX_TX_CHANNELS; adapter->max_used_tx_channels = LAN743X_USED_TX_CHANNELS; + adapter->max_vector_counter = LAN743X_MAX_VECTOR_COUNT; } adapter->intr.irq = adapter->pdev->irq; diff --git a/drivers/net/ethernet/microchip/lan743x_main.h b/drivers/net/ethernet/microchip/lan743x_main.h index d7b1b5e44518..9c6bb8be2013 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.h +++ b/drivers/net/ethernet/microchip/lan743x_main.h @@ -265,6 +265,8 @@ #define INT_MOD_CFG5 (0x7D4) #define INT_MOD_CFG6 (0x7D8) #define INT_MOD_CFG7 (0x7DC) +#define INT_MOD_CFG8 (0x7E0) +#define INT_MOD_CFG9 (0x7E4) #define PTP_CMD_CTL (0x0A00) #define PTP_CMD_CTL_PTP_CLK_STP_NSEC_ BIT(6) @@ -618,13 +620,14 @@ struct lan743x_vector { }; #define LAN743X_MAX_VECTOR_COUNT (8) +#define PCIA0X1_MAX_VECTOR_COUNT (16) struct lan743x_intr { int flags; unsigned int irq; - struct lan743x_vector vector_list[LAN743X_MAX_VECTOR_COUNT]; + struct lan743x_vector vector_list[PCIA0X1_MAX_VECTOR_COUNT]; int number_of_vectors; bool using_vectors; @@ -737,6 +740,7 @@ struct lan743x_adapter { bool is_pcia0x1; u8 max_tx_channels; u8 max_used_tx_channels; + u8 max_vector_counter; #define LAN743X_ADAPTER_FLAG_OTP BIT(0) u32 flags; From patchwork Thu Jan 27 17:30:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raju Lakkaraju - I30499 X-Patchwork-Id: 12727137 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E9B0C433FE for ; Thu, 27 Jan 2022 17:31:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244616AbiA0RbO (ORCPT ); Thu, 27 Jan 2022 12:31:14 -0500 Received: from esa.microchip.iphmx.com ([68.232.154.123]:57213 "EHLO esa.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244611AbiA0RbN (ORCPT ); Thu, 27 Jan 2022 12:31:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1643304673; x=1674840673; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pN3+MinvIjr5kdsH+qO83RbSDc0aHM1KbiRnud+JJgU=; b=sHuG5mqrLFJ5Nkz4npKRyQvjIuIC9gNLKPaE5vyCTp5SnFvhYsRXDiTy 6bGwXRsp87PRm5wDwGmOY8oIUpWZ5n9MvQGf0AoTZb2H7TViveQVElhWt AJjWof7HWPyss7jEslY3oh0xCxc67hcan15P4k0y9NKjBWY4lt+aAMtkS 9o31S5jUEiDWoA3g9HOPSXJGpBUKLfeJBISoGnd7js1zx5MxZPi8TGJdG DyYgFZZw4W4jFXVQUclKm+8zzWTouo8jCYzT7d7s7fx1qYxi4iq/l39Nf jIPuptbM3JaHRk+NnEkWYisEe/5lGm92XFRZUzkPNQYQHnBDCxxRB3wTE A==; IronPort-SDR: AmwDSJ1+FEOO9h3KkZKKMARe5A4CHPd+hBN4RCeGnBOJCH9eNO/Qs1wfnS9Mk1PmIjTyeeTFx8 UFeb8TjrvYWnYjSQbLL7G0uNCunTEwveg7hx6RnS8oKfZIW9SkrjHRqF7RJDIx2Q4xweyPasNs DDlmh85KdAnCsaXAhqSlWNA62SBM79nP9O+0RSlobwszR025/bCnovWPOry8WVyWhffsSM/ull A5xJNyblO1z1hz9Sa7d6yTX/Z1zAiT1eKZpjxxLrVh35KXyCI5F6JA7cuY2Xpwbne5Wep+jAYf VMcSWTsn3Uk5X3V8yGOYuV5Z X-IronPort-AV: E=Sophos;i="5.88,321,1635231600"; d="scan'208";a="83901397" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 27 Jan 2022 10:31:13 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) 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.2375.17; Thu, 27 Jan 2022 10:31:12 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Thu, 27 Jan 2022 10:31:10 -0700 From: Raju Lakkaraju To: CC: , , Subject: [PATCH net-next 4/5] net: lan743x: Add support of selection between SGMII and GMII Interface Date: Thu, 27 Jan 2022 23:00:54 +0530 Message-ID: <20220127173055.308918-5-Raju.Lakkaraju@microchip.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220127173055.308918-1-Raju.Lakkaraju@microchip.com> References: <20220127173055.308918-1-Raju.Lakkaraju@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org PCI1A011/PCI1A041 chip suuport SGMII interface Signed-off-by: Raju Lakkaraju --- drivers/net/ethernet/microchip/lan743x_main.c | 39 +++++++++++++++++++ drivers/net/ethernet/microchip/lan743x_main.h | 15 +++++++ 2 files changed, 54 insertions(+) diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c index daba17b0ad6c..6f6655eb6438 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.c +++ b/drivers/net/ethernet/microchip/lan743x_main.c @@ -2801,6 +2801,8 @@ static int lan743x_hardware_init(struct lan743x_adapter *adapter, static int lan743x_mdiobus_init(struct lan743x_adapter *adapter) { + u32 sgmii_ctl; + u32 chip_ver; int ret; adapter->mdiobus = devm_mdiobus_alloc(&adapter->pdev->dev); @@ -2809,6 +2811,43 @@ static int lan743x_mdiobus_init(struct lan743x_adapter *adapter) goto return_error; } + /* GPY211 Interface enable */ + chip_ver = lan743x_csr_read(adapter, FPGA_REV); + if (chip_ver) { + netif_info(adapter, drv, adapter->netdev, + "FPGA Image version: 0x%08X\n", chip_ver); + if (chip_ver & FPGA_SGMII_OP) { + sgmii_ctl = lan743x_csr_read(adapter, SGMII_CTL); + sgmii_ctl |= SGMII_CTL_SGMII_ENABLE_; + sgmii_ctl &= ~SGMII_CTL_SGMII_POWER_DN_; + lan743x_csr_write(adapter, SGMII_CTL, sgmii_ctl); + netif_info(adapter, drv, adapter->netdev, "SGMII operation\n"); + } else { + sgmii_ctl = lan743x_csr_read(adapter, SGMII_CTL); + sgmii_ctl &= ~SGMII_CTL_SGMII_ENABLE_; + sgmii_ctl |= SGMII_CTL_SGMII_POWER_DN_; + lan743x_csr_write(adapter, SGMII_CTL, sgmii_ctl); + netif_info(adapter, drv, adapter->netdev, "GMII operation\n"); + } + } else { + chip_ver = lan743x_csr_read(adapter, STRAP_READ); + netif_info(adapter, drv, adapter->netdev, + "ASIC Image version: 0x%08X\n", chip_ver); + if (chip_ver & STRAP_READ_SGMII_EN_) { + sgmii_ctl = lan743x_csr_read(adapter, SGMII_CTL); + sgmii_ctl |= SGMII_CTL_SGMII_ENABLE_; + sgmii_ctl &= ~SGMII_CTL_SGMII_POWER_DN_; + lan743x_csr_write(adapter, SGMII_CTL, sgmii_ctl); + netif_info(adapter, drv, adapter->netdev, "SGMII operation\n"); + } else { + sgmii_ctl = lan743x_csr_read(adapter, SGMII_CTL); + sgmii_ctl &= ~SGMII_CTL_SGMII_ENABLE_; + sgmii_ctl |= SGMII_CTL_SGMII_POWER_DN_; + lan743x_csr_write(adapter, SGMII_CTL, sgmii_ctl); + netif_info(adapter, drv, adapter->netdev, "GMII operation\n"); + } + } + adapter->mdiobus->priv = (void *)adapter; adapter->mdiobus->read = lan743x_mdiobus_read; adapter->mdiobus->write = lan743x_mdiobus_write; diff --git a/drivers/net/ethernet/microchip/lan743x_main.h b/drivers/net/ethernet/microchip/lan743x_main.h index 9c6bb8be2013..233555dd5464 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.h +++ b/drivers/net/ethernet/microchip/lan743x_main.h @@ -29,6 +29,16 @@ #define FPGA_REV (0x04) #define FPGA_REV_GET_MINOR_(fpga_rev) (((fpga_rev) >> 8) & 0x000000FF) #define FPGA_REV_GET_MAJOR_(fpga_rev) ((fpga_rev) & 0x000000FF) +#define FPGA_SGMII_OP BIT(24) + +#define STRAP_READ (0x0C) +#define STRAP_READ_SGMII_EN_ BIT(6) +#define STRAP_READ_SGMII_REFCLK_ BIT(5) +#define STRAP_READ_SGMII_2_5G_ BIT(4) +#define STRAP_READ_BASE_X_ BIT(3) +#define STRAP_READ_RGMII_TXC_DELAY_EN_ BIT(2) +#define STRAP_READ_RGMII_RXC_DELAY_EN_ BIT(1) +#define STRAP_READ_ADV_PM_DISABLE_ BIT(0) #define HW_CFG (0x010) #define HW_CFG_RELOAD_TYPE_ALL_ (0x00000FC0) @@ -218,6 +228,11 @@ #define MAC_WUCSR2 (0x600) +#define SGMII_CTL (0x728) +#define SGMII_CTL_SGMII_ENABLE_ BIT(31) +#define SGMII_CTL_LINK_STATUS_SOURCE_ BIT(8) +#define SGMII_CTL_SGMII_POWER_DN_ BIT(1) + #define INT_STS (0x780) #define INT_BIT_DMA_RX_(channel) BIT(24 + (channel)) #define INT_BIT_ALL_RX_ (0x0F000000) From patchwork Thu Jan 27 17:30:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raju Lakkaraju - I30499 X-Patchwork-Id: 12727138 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CC52C433F5 for ; Thu, 27 Jan 2022 17:31:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244611AbiA0Rbg (ORCPT ); Thu, 27 Jan 2022 12:31:36 -0500 Received: from esa.microchip.iphmx.com ([68.232.154.123]:32171 "EHLO esa.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240239AbiA0Rbf (ORCPT ); Thu, 27 Jan 2022 12:31:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1643304695; x=1674840695; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1tgw1M+S1Cj1d45rPu0CDjghKMmBCide0loK8LZc/NE=; b=wtRFzkbDdElUGNPjaWFHMLDOWBfoso2neqa6rjLw50+MItNFGbG2jpQT L3UqowHfn7iS997xEFBWb2sh4n2YzIJouaxAreNAwI0i6RF/YckW+i+ck UElDRF9MgGhYgQGewQwnDAzVisaj8Qqwt9gqSI3YkRRGgyokOqmz5+7eK 2m+FRaEO7VbuGc8ksuuzQ7gRD40uB3lHlLnK8xfHEWWveiPMkXvZRUTud hgmugX+6HOnNK6J9T1oaTJo+ENnQKlo3m2e14eGxAFjPXp0QnQ/NZ/8VF rnCbyLL8AmvEgZEpMFDPUIRvmZEWSJiKhgBTCF/xcxUIqJkpDVRzybuoA Q==; IronPort-SDR: iIn0nE/+WFL5eirbUPAdun+97+2jyLQwzML0uxhBT3NagVtr67zCEZBlMBkb2crs0d3CA1iCwv Mj9hnhVmACnJsQWODbq35HNptQB1kQalt3z2lfaJhlESnCCDk/7cDI0JmP/FTrS6oRM1O5G9ht 9dE6E/XN/slFi9WfoS1hdHTDT+7WzZjxx+Nnz2WE+6Ff32sBBERNBEV7x8GbFrwdjWguD01kUQ a4dmr4fKL/i4N2DnDldpi2XDoPdDmfbqjmkr5Gc8Py+RcOT15gOstSlpsWsJu0p8P2AA8h8okG rrxBYNdQ90ary85YRZ1z9xPO X-IronPort-AV: E=Sophos;i="5.88,321,1635231600"; d="scan'208";a="144113671" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 27 Jan 2022 10:31:15 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) 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.2375.17; Thu, 27 Jan 2022 10:31:15 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Thu, 27 Jan 2022 10:31:13 -0700 From: Raju Lakkaraju To: CC: , , Subject: [PATCH net-next 5/5] net: lan743x: Add Clause-45 MDIO access Date: Thu, 27 Jan 2022 23:00:55 +0530 Message-ID: <20220127173055.308918-6-Raju.Lakkaraju@microchip.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220127173055.308918-1-Raju.Lakkaraju@microchip.com> References: <20220127173055.308918-1-Raju.Lakkaraju@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org PCI1A011/PCI1A041 chip support the MDIO Clause-45 access Signed-off-by: Raju Lakkaraju --- drivers/net/ethernet/microchip/lan743x_main.c | 110 +++++++++++++++++- drivers/net/ethernet/microchip/lan743x_main.h | 16 +++ 2 files changed, 123 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c index 6f6655eb6438..98d346aaf627 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.c +++ b/drivers/net/ethernet/microchip/lan743x_main.c @@ -793,6 +793,95 @@ static int lan743x_mdiobus_write(struct mii_bus *bus, return ret; } +static u32 lan743x_mac_mmd_access(int id, int index, int op, u8 freq) +{ + u16 dev_addr; + u32 ret; + + dev_addr = (index >> 16) & 0x1f; + ret = (id << MAC_MII_ACC_PHY_ADDR_SHIFT_) & + MAC_MII_ACC_PHY_ADDR_MASK_; + ret |= (dev_addr << MAC_MII_ACC_MIIMMD_SHIFT_) & + MAC_MII_ACC_MIIMMD_MASK_; + if (freq) + ret |= (freq << MAC_MII_ACC_MDC_CYCLE_SHIFT_) & + MAC_MII_ACC_MDC_CYCLE_MASK_; + if (op == 1) + ret |= MAC_MII_ACC_MIICMD_WRITE_; + else if (op == 2) + ret |= MAC_MII_ACC_MIICMD_READ_; + else if (op == 3) + ret |= MAC_MII_ACC_MIICMD_READ_INC_; + else + ret |= MAC_MII_ACC_MIICMD_ADDR_; + ret |= (MAC_MII_ACC_MII_BUSY_ | MAC_MII_ACC_MIICL45_); + + return ret; +} + +static int lan743x_mdiobus_c45_read(struct mii_bus *bus, int phy_id, int index) +{ + struct lan743x_adapter *adapter = bus->priv; + u32 mmd_access; + int ret; + + /* comfirm MII not busy */ + ret = lan743x_mac_mii_wait_till_not_busy(adapter); + if (ret < 0) + return ret; + if (index & MII_ADDR_C45) { + /* Load Register Address */ + lan743x_csr_write(adapter, MAC_MII_DATA, (u32)(index & 0xffff)); + mmd_access = lan743x_mac_mmd_access(phy_id, index, 0, 0); + lan743x_csr_write(adapter, MAC_MII_ACC, mmd_access); + ret = lan743x_mac_mii_wait_till_not_busy(adapter); + if (ret < 0) + return ret; + /* Read Data */ + mmd_access = lan743x_mac_mmd_access(phy_id, index, 2, 0); + lan743x_csr_write(adapter, MAC_MII_ACC, mmd_access); + ret = lan743x_mac_mii_wait_till_not_busy(adapter); + if (ret < 0) + return ret; + ret = lan743x_csr_read(adapter, MAC_MII_DATA); + return (int)(ret & 0xFFFF); + } + + ret = lan743x_mdiobus_read(bus, phy_id, index); + return ret; +} + +static int lan743x_mdiobus_c45_write(struct mii_bus *bus, + int phy_id, int index, u16 regval) +{ + struct lan743x_adapter *adapter = bus->priv; + u32 mmd_access; + int ret; + + /* confirm MII not busy */ + ret = lan743x_mac_mii_wait_till_not_busy(adapter); + if (ret < 0) + return ret; + if (index & MII_ADDR_C45) { + /* Load Register Address */ + lan743x_csr_write(adapter, MAC_MII_DATA, (u32)(index & 0xffff)); + mmd_access = lan743x_mac_mmd_access(phy_id, index, 0, 0); + lan743x_csr_write(adapter, MAC_MII_ACC, mmd_access); + ret = lan743x_mac_mii_wait_till_not_busy(adapter); + if (ret < 0) + return ret; + /* Write Data */ + lan743x_csr_write(adapter, MAC_MII_DATA, (u32)regval); + mmd_access = lan743x_mac_mmd_access(phy_id, index, 1, 0); + lan743x_csr_write(adapter, MAC_MII_ACC, mmd_access); + ret = lan743x_mac_mii_wait_till_not_busy(adapter); + } else { + ret = lan743x_mdiobus_write(bus, phy_id, index, regval); + } + + return ret; +} + static void lan743x_mac_set_address(struct lan743x_adapter *adapter, u8 *addr) { @@ -1053,6 +1142,9 @@ static int lan743x_phy_open(struct lan743x_adapter *adapter) PHY_INTERFACE_MODE_GMII); if (ret) goto return_error; + + if (adapter->mdiobus->probe_capabilities == MDIOBUS_C45) + phydev->c45_ids.devices_in_package &= ~BIT(0); } /* MAC doesn't support 1000T Half */ @@ -2822,12 +2914,14 @@ static int lan743x_mdiobus_init(struct lan743x_adapter *adapter) sgmii_ctl &= ~SGMII_CTL_SGMII_POWER_DN_; lan743x_csr_write(adapter, SGMII_CTL, sgmii_ctl); netif_info(adapter, drv, adapter->netdev, "SGMII operation\n"); + adapter->mdiobus->probe_capabilities = MDIOBUS_C22_C45; } else { sgmii_ctl = lan743x_csr_read(adapter, SGMII_CTL); sgmii_ctl &= ~SGMII_CTL_SGMII_ENABLE_; sgmii_ctl |= SGMII_CTL_SGMII_POWER_DN_; lan743x_csr_write(adapter, SGMII_CTL, sgmii_ctl); netif_info(adapter, drv, adapter->netdev, "GMII operation\n"); + adapter->mdiobus->probe_capabilities = MDIOBUS_C22; } } else { chip_ver = lan743x_csr_read(adapter, STRAP_READ); @@ -2839,19 +2933,29 @@ static int lan743x_mdiobus_init(struct lan743x_adapter *adapter) sgmii_ctl &= ~SGMII_CTL_SGMII_POWER_DN_; lan743x_csr_write(adapter, SGMII_CTL, sgmii_ctl); netif_info(adapter, drv, adapter->netdev, "SGMII operation\n"); + adapter->mdiobus->probe_capabilities = MDIOBUS_C22_C45; } else { sgmii_ctl = lan743x_csr_read(adapter, SGMII_CTL); sgmii_ctl &= ~SGMII_CTL_SGMII_ENABLE_; sgmii_ctl |= SGMII_CTL_SGMII_POWER_DN_; lan743x_csr_write(adapter, SGMII_CTL, sgmii_ctl); netif_info(adapter, drv, adapter->netdev, "GMII operation\n"); + adapter->mdiobus->probe_capabilities = MDIOBUS_C22; } } adapter->mdiobus->priv = (void *)adapter; - adapter->mdiobus->read = lan743x_mdiobus_read; - adapter->mdiobus->write = lan743x_mdiobus_write; - adapter->mdiobus->name = "lan743x-mdiobus"; + if (adapter->mdiobus->probe_capabilities == MDIOBUS_C45 || + adapter->mdiobus->probe_capabilities == MDIOBUS_C22_C45) { + adapter->mdiobus->read = lan743x_mdiobus_c45_read; + adapter->mdiobus->write = lan743x_mdiobus_c45_write; + adapter->mdiobus->name = "lan743x-mdiobus-c45"; + } else { + adapter->mdiobus->read = lan743x_mdiobus_read; + adapter->mdiobus->write = lan743x_mdiobus_write; + adapter->mdiobus->name = "lan743x-mdiobus"; + } + snprintf(adapter->mdiobus->id, MII_BUS_ID_SIZE, "pci-%s", pci_name(adapter->pdev)); diff --git a/drivers/net/ethernet/microchip/lan743x_main.h b/drivers/net/ethernet/microchip/lan743x_main.h index 233555dd5464..12facf905eaa 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.h +++ b/drivers/net/ethernet/microchip/lan743x_main.h @@ -149,6 +149,13 @@ #define MAC_RX_ADDRL (0x11C) #define MAC_MII_ACC (0x120) +#define MAC_MII_ACC_MDC_CYCLE_SHIFT_ (16) +#define MAC_MII_ACC_MDC_CYCLE_MASK_ (0x00070000) +#define MAC_MII_ACC_MDC_CYCLE_2_5MHZ_ (0) +#define MAC_MII_ACC_MDC_CYCLE_5MHZ_ (1) +#define MAC_MII_ACC_MDC_CYCLE_12_5MHZ_ (2) +#define MAC_MII_ACC_MDC_CYCLE_25MHZ_ (3) +#define MAC_MII_ACC_MDC_CYCLE_1_25MHZ_ (4) #define MAC_MII_ACC_PHY_ADDR_SHIFT_ (11) #define MAC_MII_ACC_PHY_ADDR_MASK_ (0x0000F800) #define MAC_MII_ACC_MIIRINDA_SHIFT_ (6) @@ -157,6 +164,15 @@ #define MAC_MII_ACC_MII_WRITE_ (0x00000002) #define MAC_MII_ACC_MII_BUSY_ BIT(0) +#define MAC_MII_ACC_MIIMMD_SHIFT_ (6) +#define MAC_MII_ACC_MIIMMD_MASK_ (0x000007C0) +#define MAC_MII_ACC_MIICL45_ BIT(3) +#define MAC_MII_ACC_MIICMD_MASK_ (0x00000006) +#define MAC_MII_ACC_MIICMD_ADDR_ (0x00000000) +#define MAC_MII_ACC_MIICMD_WRITE_ (0x00000002) +#define MAC_MII_ACC_MIICMD_READ_ (0x00000004) +#define MAC_MII_ACC_MIICMD_READ_INC_ (0x00000006) + #define MAC_MII_DATA (0x124) #define MAC_EEE_TX_LPI_REQ_DLY_CNT (0x130)