DPDK patches and discussions
 help / color / mirror / Atom feed
From: Igor Russkikh <igor.russkikh@aquantia.com>
To: dev@dpdk.org
Cc: pavel.belous@aquantia.com, Nadezhda.Krupnina@aquantia.com,
	igor.russkikh@aquantia.com, Simon.Edelhaus@aquantia.com,
	Corey Melton <comelton@cisco.com>,
	Ashish Kumar <ashishk2@cisco.com>
Subject: [dpdk-dev] [PATCH 09/21] net/atlantic: link status and interrupt management
Date: Fri,  7 Sep 2018 18:21:47 +0300	[thread overview]
Message-ID: <1536333719-32155-10-git-send-email-igor.russkikh@aquantia.com> (raw)
In-Reply-To: <1536333719-32155-1-git-send-email-igor.russkikh@aquantia.com>

From: Pavel Belous <pavel.belous@aquantia.com>

Implement link interrupt, link info, link polling

Signed-off-by: Igor Russkikh <igor.russkikh@aquantia.com>
---
 drivers/net/atlantic/atl_ethdev.c | 255 ++++++++++++++++++++++++++++++++++++++
 drivers/net/atlantic/atl_ethdev.h |  10 ++
 2 files changed, 265 insertions(+)

diff --git a/drivers/net/atlantic/atl_ethdev.c b/drivers/net/atlantic/atl_ethdev.c
index 78438174e..6dda8280a 100644
--- a/drivers/net/atlantic/atl_ethdev.c
+++ b/drivers/net/atlantic/atl_ethdev.c
@@ -49,8 +49,11 @@ static int eth_atl_dev_uninit(struct rte_eth_dev *eth_dev);
 static int  atl_dev_configure(struct rte_eth_dev *dev);
 static int  atl_dev_start(struct rte_eth_dev *dev);
 static void atl_dev_stop(struct rte_eth_dev *dev);
+static int  atl_dev_set_link_up(struct rte_eth_dev *dev);
+static int  atl_dev_set_link_down(struct rte_eth_dev *dev);
 static void atl_dev_close(struct rte_eth_dev *dev);
 static int  atl_dev_reset(struct rte_eth_dev *dev);
+static int  atl_dev_link_update(struct rte_eth_dev *dev, int wait);
 
 static int atl_dev_queue_stats_mapping_set(struct rte_eth_dev *eth_dev,
 					     uint16_t queue_id,
@@ -63,6 +66,15 @@ static void atl_dev_info_get(struct rte_eth_dev *dev,
 
 static const uint32_t *atl_dev_supported_ptypes_get(struct rte_eth_dev *dev);
 
+/* Interrupts */
+static int atl_dev_rxq_interrupt_setup(struct rte_eth_dev *dev);
+static int atl_dev_lsc_interrupt_setup(struct rte_eth_dev *dev, uint8_t on);
+static int atl_dev_interrupt_get_status(struct rte_eth_dev *dev);
+static int atl_dev_interrupt_action(struct rte_eth_dev *dev,
+				    struct rte_intr_handle *handle);
+static void atl_dev_interrupt_handler(void *param);
+
+
 static int eth_atl_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 	struct rte_pci_device *pci_dev);
 static int eth_atl_pci_remove(struct rte_pci_device *pci_dev);
@@ -125,10 +137,66 @@ static const struct eth_dev_ops atl_eth_dev_ops = {
 	.dev_configure	      = atl_dev_configure,
 	.dev_start	      = atl_dev_start,
 	.dev_stop	      = atl_dev_stop,
+	.dev_set_link_up      = atl_dev_set_link_up,
+	.dev_set_link_down    = atl_dev_set_link_down,
 	.dev_close	      = atl_dev_close,
 	.dev_reset	      = atl_dev_reset,
+	/* Link */
+	.link_update	      = atl_dev_link_update,
 };
 
+/**
+ * Atomically reads the link status information from global
+ * structure rte_eth_dev.
+ *
+ * @param dev
+ *   - Pointer to the structure rte_eth_dev to read from.
+ *   - Pointer to the buffer to be saved with the link status.
+ *
+ * @return
+ *   - On success, zero.
+ *   - On failure, negative value.
+ */
+static inline int
+rte_atl_dev_atomic_read_link_status(struct rte_eth_dev *dev,
+				struct rte_eth_link *link)
+{
+	struct rte_eth_link *dst = link;
+	struct rte_eth_link *src = &(dev->data->dev_link);
+
+	if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
+					*(uint64_t *)src) == 0)
+		return -1;
+
+	return 0;
+}
+
+/**
+ * Atomically writes the link status information into global
+ * structure rte_eth_dev.
+ *
+ * @param dev
+ *   - Pointer to the structure rte_eth_dev to read from.
+ *   - Pointer to the buffer to be saved with the link status.
+ *
+ * @return
+ *   - On success, zero.
+ *   - On failure, negative value.
+ */
+static inline int
+rte_atl_dev_atomic_write_link_status(struct rte_eth_dev *dev,
+				struct rte_eth_link *link)
+{
+	struct rte_eth_link *dst = &(dev->data->dev_link);
+	struct rte_eth_link *src = link;
+
+	if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
+					*(uint64_t *)src) == 0)
+		return -1;
+
+	return 0;
+}
+
 static inline int32_t
 atl_reset_hw(struct aq_hw_s *hw)
 {
@@ -383,6 +451,38 @@ atl_dev_start(struct rte_eth_dev *dev)
 		}
 	}
 
+
+	err = hw->aq_fw_ops->update_link_status(hw);
+
+	if (err) {
+		goto error;
+	}
+
+	dev->data->dev_link.link_status = hw->aq_link_status.mbps != 0;
+
+	link_speeds = &dev->data->dev_conf.link_speeds;
+
+	speed = 0x0;
+
+	if (*link_speeds == ETH_LINK_SPEED_AUTONEG) {
+		speed = hw->aq_nic_cfg->link_speed_msk;
+	} else {
+		if (*link_speeds & ETH_LINK_SPEED_10G)
+			speed |= AQ_NIC_RATE_10G;
+		if (*link_speeds & ETH_LINK_SPEED_5G)
+			speed |= AQ_NIC_RATE_5G;
+		if (*link_speeds & ETH_LINK_SPEED_1G)
+			speed |= AQ_NIC_RATE_1G;
+		if (*link_speeds & ETH_LINK_SPEED_2_5G)
+			speed |=  AQ_NIC_RATE_2G5;
+		if (*link_speeds & ETH_LINK_SPEED_100M)
+			speed |= AQ_NIC_RATE_100M;
+	}
+
+	err = hw->aq_fw_ops->set_link_speed(hw, speed);
+	if (err)
+		goto error;
+
 	if (rte_intr_allow_others(intr_handle)) {
 		/* check if lsc interrupt is enabled */
 		if (dev->data->dev_conf.intr_conf.lsc != 0)
@@ -460,6 +560,28 @@ atl_dev_stop(struct rte_eth_dev *dev)
 }
 
 /*
+ * Set device link up: enable tx.
+ */
+static int
+atl_dev_set_link_up(struct rte_eth_dev *dev)
+{
+	struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+	return hw->aq_fw_ops->set_link_speed(hw, hw->aq_nic_cfg->link_speed_msk);
+}
+
+/*
+ * Set device link down: disable tx.
+ */
+static int
+atl_dev_set_link_down(struct rte_eth_dev *dev)
+{
+	struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+
+	return hw->aq_fw_ops->set_link_speed(hw, 0);
+}
+
+/*
  * Reset and stop device.
  */
 static void
@@ -490,6 +612,139 @@ atl_dev_reset(struct rte_eth_dev *dev)
 }
 
 
+/* return 0 means link status changed, -1 means not changed */
+static int
+atl_dev_link_update(struct rte_eth_dev *dev, int wait __rte_unused)
+{
+	struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	struct atl_interrupt *intr = ATL_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
+	struct rte_eth_link link, old;
+	int err = 0;
+
+	link.link_status = ETH_LINK_DOWN;
+	link.link_speed = 0;
+	link.link_duplex = ETH_LINK_FULL_DUPLEX;
+	link.link_autoneg = hw->is_autoneg ? ETH_LINK_AUTONEG : ETH_LINK_FIXED;
+	memset(&old, 0, sizeof(old));
+
+	/* load old link status */
+	rte_atl_dev_atomic_read_link_status(dev, &old);
+
+	/* read current link status */
+	err = hw->aq_fw_ops->update_link_status(hw);
+
+	if (err)
+		return 0;
+
+	if (hw->aq_link_status.mbps == 0) {
+		/* write default (down) link status */
+		rte_atl_dev_atomic_write_link_status(dev, &link);
+		if (link.link_status == old.link_status)
+			return -1;
+		return 0;
+	}
+
+	intr->flags &= ~ATL_FLAG_NEED_LINK_CONFIG;
+
+	link.link_status = ETH_LINK_UP;
+	link.link_duplex = ETH_LINK_FULL_DUPLEX;
+	link.link_speed = hw->aq_link_status.mbps;
+
+	rte_atl_dev_atomic_write_link_status(dev, &link);
+
+	if (link.link_status == old.link_status)
+		return -1;
+
+	return 0;
+}
+
+/**
+ * It clears the interrupt causes and enables the interrupt.
+ * It will be called once only during nic initialized.
+ *
+ * @param dev
+ *  Pointer to struct rte_eth_dev.
+ * @param on
+ *  Enable or Disable.
+ *
+ * @return
+ *  - On success, zero.
+ *  - On failure, a negative value.
+ */
+
+static int
+atl_dev_lsc_interrupt_setup(struct rte_eth_dev *dev, uint8_t on __rte_unused)
+{
+	atl_dev_link_status_print(dev);
+	return 0;
+}
+
+static int
+atl_dev_rxq_interrupt_setup(struct rte_eth_dev *dev __rte_unused)
+{
+	return 0;
+}
+
+
+static int
+atl_dev_interrupt_get_status(struct rte_eth_dev *dev)
+{
+	struct atl_interrupt *intr = ATL_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
+	struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	u64 cause = 0;
+
+	hw_atl_b0_hw_irq_read(hw, &cause);
+
+	atl_disable_intr(hw);
+	intr->flags = cause & BIT(ATL_IRQ_CAUSE_LINK) ? ATL_FLAG_NEED_LINK_UPDATE : 0;
+
+	return 0;
+}
+
+/**
+ * It gets and then prints the link status.
+ *
+ * @param dev
+ *  Pointer to struct rte_eth_dev.
+ *
+ * @return
+ *  - On success, zero.
+ *  - On failure, a negative value.
+ */
+static void
+atl_dev_link_status_print(struct rte_eth_dev *dev)
+{
+	struct rte_eth_link link;
+
+	memset(&link, 0, sizeof(link));
+	rte_atl_dev_atomic_read_link_status(dev, &link);
+	if (link.link_status) {
+		PMD_DRV_LOG(INFO, "Port %d: Link Up - speed %u Mbps - %s",
+					(int)(dev->data->port_id),
+					(unsigned)link.link_speed,
+			link.link_duplex == ETH_LINK_FULL_DUPLEX ?
+					"full-duplex" : "half-duplex");
+	} else {
+		PMD_DRV_LOG(INFO, " Port %d: Link Down",
+				(int)(dev->data->port_id));
+	}
+
+
+#ifdef DEBUG
+{
+	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
+
+	PMD_DRV_LOG(DEBUG, "PCI Address: " PCI_PRI_FMT,
+				pci_dev->addr.domain,
+				pci_dev->addr.bus,
+				pci_dev->addr.devid,
+				pci_dev->addr.function);
+}
+#endif
+
+	PMD_DRV_LOG(INFO, "Link speed:%d", link.link_speed);
+}
+
 /*
  * It executes link_update after knowing an interrupt occurred.
  *
diff --git a/drivers/net/atlantic/atl_ethdev.h b/drivers/net/atlantic/atl_ethdev.h
index 0018fa898..5b9fc63c6 100644
--- a/drivers/net/atlantic/atl_ethdev.h
+++ b/drivers/net/atlantic/atl_ethdev.h
@@ -22,9 +22,19 @@
 struct atl_adapter {
 	struct aq_hw_s             hw;
 	struct aq_hw_cfg_s         hw_cfg;
+	struct atl_interrupt       intr;
 };
 
 #define ATL_DEV_TO_ADAPTER(dev) \
 	((struct atl_adapter *)(dev)->data->dev_private)
 
+#define ATL_DEV_PRIVATE_TO_HW(adapter) \
+	(&((struct atl_adapter *)adapter)->hw)
+
+#define ATL_DEV_PRIVATE_TO_INTR(adapter) \
+	(&((struct atl_adapter *)adapter)->intr)
+
+#define ATL_DEV_PRIVATE_TO_CFG(adapter) \
+	(&((struct atl_adapter *)adapter)->hw_cfg)
+
 #endif /* _ATLANTIC_ETHDEV_H_ */
-- 
2.13.3.windows.1

  parent reply	other threads:[~2018-09-07 15:23 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-07 15:21 [dpdk-dev] [PATCH 00/21] net/atlantic: Aquantia aQtion 10G NIC Family DPDK PMD driver Igor Russkikh
2018-09-07 15:21 ` [dpdk-dev] [PATCH 01/21] net/atlantic: atlantic PMD driver skeleton Igor Russkikh
2018-09-11 17:02   ` Stephen Hemminger
2018-09-12 11:49     ` Igor Russkikh
2018-09-07 15:21 ` [dpdk-dev] [PATCH 02/21] net/atlantic: documentation and rel notes Igor Russkikh
2018-09-07 15:21 ` [dpdk-dev] [PATCH 03/21] net/atlantic: logging macroes and some typedefs Igor Russkikh
2018-09-07 15:21 ` [dpdk-dev] [PATCH 04/21] net/atlantic: hw_atl register declarations Igor Russkikh
2018-09-11 17:04   ` Stephen Hemminger
2018-09-07 15:21 ` [dpdk-dev] [PATCH 05/21] net/atlantic: b0 hardware layer main logic Igor Russkikh
2018-09-11 17:04   ` Stephen Hemminger
2018-09-11 17:05   ` Stephen Hemminger
2018-09-07 15:21 ` [dpdk-dev] [PATCH 06/21] net/atlantic: firmware operations layer Igor Russkikh
2018-09-07 15:21 ` [dpdk-dev] [PATCH 07/21] net/atlantic: hardware register access routines Igor Russkikh
2018-09-24  6:29   ` Hemant
2018-09-24  9:00     ` Igor Russkikh
2018-09-07 15:21 ` [dpdk-dev] [PATCH 08/21] net/atlantic: rte device start, stop, initial configuration Igor Russkikh
2018-09-07 15:21 ` Igor Russkikh [this message]
2018-09-07 15:21 ` [dpdk-dev] [PATCH 10/21] net/atlantic: add hw adapter structures and defines Igor Russkikh
2018-09-07 15:21 ` [dpdk-dev] [PATCH 11/21] net/atlantic: RSS and RETA manipulation API Igor Russkikh
2018-09-07 15:21 ` [dpdk-dev] [PATCH 12/21] net/atlantic: flow control configuration Igor Russkikh
2018-09-07 15:21 ` [dpdk-dev] [PATCH 13/21] net/atlantic: MAC address manipulations Igor Russkikh
2018-09-07 15:21 ` [dpdk-dev] [PATCH 14/21] net/atlantic: eeprom and register manipulation routines Igor Russkikh
2018-09-07 15:21 ` [dpdk-dev] [PATCH 15/21] net/atlantic: LED control DPDK and private APIs Igor Russkikh
2018-09-07 15:21 ` [dpdk-dev] [PATCH 16/21] net/atlantic: promisc and allmulti configuration Igor Russkikh
2018-09-07 15:21 ` [dpdk-dev] [PATCH 17/21] net/atlantic: device statistics, xstats Igor Russkikh
2018-09-11 17:06   ` Stephen Hemminger
2018-09-07 15:21 ` [dpdk-dev] [PATCH 18/21] net/atlantic: VLAN filters and offloads Igor Russkikh
2018-09-07 15:21 ` [dpdk-dev] [PATCH 19/21] net/atlantic: device MTU and statuses Igor Russkikh
2018-09-07 15:21 ` [dpdk-dev] [PATCH 20/21] net/atlantic: RX side structures and implementation Igor Russkikh
2018-09-07 15:21 ` [dpdk-dev] [PATCH 21/21] net/atlantic: TX " Igor Russkikh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1536333719-32155-10-git-send-email-igor.russkikh@aquantia.com \
    --to=igor.russkikh@aquantia.com \
    --cc=Nadezhda.Krupnina@aquantia.com \
    --cc=Simon.Edelhaus@aquantia.com \
    --cc=ashishk2@cisco.com \
    --cc=comelton@cisco.com \
    --cc=dev@dpdk.org \
    --cc=pavel.belous@aquantia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).