From: Stephen Hemminger <stephen-OTpzqLSitTUnbdJkjeBofR2eb7JE58TQ@public.gmane.org>
To: Ouyang Changchun
<changchun.ouyang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Cc: dev-VfR2kkLFssw@public.gmane.org,
Stephen Hemminger
<shemming-43mecJUBy8ZBDgjK7y7TUQ@public.gmane.org>
Subject: [RFC 04/10] virtio: add support for Link State interrupt
Date: Mon, 25 Aug 2014 19:07:50 -0700 [thread overview]
Message-ID: <20140826020843.806847742@networkplumber.org> (raw)
In-Reply-To: 20140826020746.062748014@networkplumber.org
[-- Attachment #1: virtio-lsc.patch --]
[-- Type: text/plain, Size: 5874 bytes --]
Virtio has link state interrupt which can be used.
Signed-off-by: Stephen Hemminger <shemming-43mecJUBy8ZBDgjK7y7TUQ@public.gmane.org>
---
lib/librte_pmd_virtio/virtio_ethdev.c | 78 ++++++++++++++++++++++++++--------
lib/librte_pmd_virtio/virtio_pci.c | 22 +++++++++
lib/librte_pmd_virtio/virtio_pci.h | 4 +
3 files changed, 86 insertions(+), 18 deletions(-)
--- a/lib/librte_pmd_virtio/virtio_ethdev.c 2014-08-25 19:00:06.342530488 -0700
+++ b/lib/librte_pmd_virtio/virtio_ethdev.c 2014-08-25 19:00:06.342530488 -0700
@@ -757,6 +757,34 @@ static int virtio_resource_init(struct r
#endif
/*
+ * Process Virtio Config changed interrupt and call the callback
+ * if link state changed.
+ */
+static void
+virtio_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
+ void *param)
+{
+ struct rte_eth_dev *dev = param;
+ struct virtio_hw *hw =
+ VIRTIO_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+ uint8_t isr;
+
+ /* Read interrupt status which clears interrupt */
+ isr = vtpci_isr(hw);
+ PMD_DRV_LOG(INFO, "interrupt status = %#x", isr);
+
+ if (rte_intr_enable(&dev->pci_dev->intr_handle) < 0)
+ PMD_DRV_LOG(ERR, "interrupt enable failed");
+
+ if (isr & VIRTIO_PCI_ISR_CONFIG) {
+ if (virtio_dev_link_update(dev, 0) == 0)
+ _rte_eth_dev_callback_process(dev,
+ RTE_ETH_EVENT_INTR_LSC);
+ }
+
+}
+
+/*
* This function is based on probe() function in virtio_pci.c
* It returns 0 on success.
*/
@@ -886,6 +914,10 @@ eth_virtio_dev_init(__rte_unused struct
PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x",
eth_dev->data->port_id, pci_dev->id.vendor_id,
pci_dev->id.device_id);
+
+ /* Setup interrupt callback */
+ rte_intr_callback_register(&pci_dev->intr_handle,
+ virtio_interrupt_handler, eth_dev);
return 0;
}
@@ -893,7 +925,7 @@ static struct eth_driver rte_virtio_pmd
{
.name = "rte_virtio_pmd",
.id_table = pci_id_virtio_map,
- .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
+ .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
},
.eth_dev_init = eth_virtio_dev_init,
.dev_private_size = sizeof(struct virtio_adapter),
@@ -933,6 +965,9 @@ static int
virtio_dev_configure(struct rte_eth_dev *dev)
{
const struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
+ struct virtio_hw *hw =
+ VIRTIO_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+ int ret;
PMD_INIT_LOG(DEBUG, "configure");
@@ -941,7 +976,11 @@ virtio_dev_configure(struct rte_eth_dev
return (-EINVAL);
}
- return 0;
+ ret = vtpci_irq_config(hw, 0);
+ if (ret != 0)
+ PMD_DRV_LOG(ERR, "failed to set config vector");
+
+ return ret;
}
@@ -949,7 +988,6 @@ static int
virtio_dev_start(struct rte_eth_dev *dev)
{
uint16_t nb_queues, i;
- uint16_t status;
struct virtio_hw *hw =
VIRTIO_DEV_PRIVATE_TO_HW(dev->data->dev_private);
@@ -964,18 +1002,22 @@ virtio_dev_start(struct rte_eth_dev *dev
/* Do final configuration before rx/tx engine starts */
virtio_dev_rxtx_start(dev);
- /* Check VIRTIO_NET_F_STATUS for link status*/
- if (vtpci_with_feature(hw, VIRTIO_NET_F_STATUS)) {
- vtpci_read_dev_config(hw,
- offsetof(struct virtio_net_config, status),
- &status, sizeof(status));
- if ((status & VIRTIO_NET_S_LINK_UP) == 0)
- PMD_INIT_LOG(ERR, "Port: %d Link is DOWN",
- dev->data->port_id);
- else
- PMD_INIT_LOG(DEBUG, "Port: %d Link is UP",
- dev->data->port_id);
+ /* check if lsc interrupt feature is enabled */
+ if (dev->data->dev_conf.intr_conf.lsc) {
+ if (!vtpci_with_feature(hw, VIRTIO_NET_F_STATUS)) {
+ PMD_DRV_LOG(ERR, "link status not supported by host");
+ return -ENOTSUP;
+ }
+
+ if (rte_intr_enable(&dev->pci_dev->intr_handle) < 0) {
+ PMD_DRV_LOG(ERR, "interrupt enable failed");
+ return -EIO;
+ }
}
+
+ /* Initialize Link state */
+ virtio_dev_link_update(dev, 0);
+
vtpci_reinit_complete(hw);
/*Notify the backend
@@ -1057,6 +1099,7 @@ virtio_dev_stop(struct rte_eth_dev *dev)
VIRTIO_DEV_PRIVATE_TO_HW(dev->data->dev_private);
/* reset the NIC */
+ vtpci_irq_config(hw, 0);
vtpci_reset(hw);
virtio_dev_free_mbufs(dev);
}
@@ -1073,6 +1116,7 @@ virtio_dev_link_update(struct rte_eth_de
old = link;
link.link_duplex = FULL_DUPLEX;
link.link_speed = SPEED_10G;
+
if (vtpci_with_feature(hw, VIRTIO_NET_F_STATUS)) {
PMD_INIT_LOG(DEBUG, "Get link status from hw");
vtpci_read_dev_config(hw,
@@ -1091,10 +1135,8 @@ virtio_dev_link_update(struct rte_eth_de
link.link_status = 1; /* Link up */
}
virtio_dev_atomic_write_link_status(dev, &link);
- if (old.link_status == link.link_status)
- return -1;
- /*changed*/
- return 0;
+
+ return (old.link_status == link.link_status) ? -1 : 0;
}
static void
--- a/lib/librte_pmd_virtio/virtio_pci.c 2014-08-25 19:00:06.342530488 -0700
+++ b/lib/librte_pmd_virtio/virtio_pci.c 2014-08-25 19:00:06.342530488 -0700
@@ -127,3 +127,25 @@ vtpci_set_status(struct virtio_hw *hw, u
VIRTIO_WRITE_REG_1(hw, VIRTIO_PCI_STATUS, status);
}
+
+uint8_t
+vtpci_isr(struct virtio_hw *hw)
+{
+
+ return VIRTIO_READ_REG_1(hw, VIRTIO_PCI_ISR);
+}
+
+
+/* Enable one vector (0) for Link State Intrerrupt */
+int
+vtpci_irq_config(struct virtio_hw *hw, uint16_t vec)
+{
+ VIRTIO_WRITE_REG_2(hw, VIRTIO_MSI_CONFIG_VECTOR, vec);
+ vec = VIRTIO_READ_REG_2(hw, VIRTIO_MSI_CONFIG_VECTOR);
+ if (vec == VIRTIO_MSI_NO_VECTOR) {
+ PMD_DRV_LOG(ERR, "failed to set config vector");
+ return -EBUSY;
+ }
+
+ return 0;
+}
--- a/lib/librte_pmd_virtio/virtio_pci.h 2014-08-25 19:00:06.342530488 -0700
+++ b/lib/librte_pmd_virtio/virtio_pci.h 2014-08-25 19:00:06.342530488 -0700
@@ -263,4 +263,8 @@ void vtpci_write_dev_config(struct virti
void vtpci_read_dev_config(struct virtio_hw *, uint64_t, void *, int);
+uint8_t vtpci_isr(struct virtio_hw *);
+
+int vtpci_irq_config(struct virtio_hw *, uint16_t);
+
#endif /* _VIRTIO_PCI_H_ */
next prev parent reply other threads:[~2014-08-26 2:07 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-26 2:07 [RFC 00/10] virtio patches Stephen Hemminger
2014-08-26 2:07 ` [RFC 01/10] virtio: rearrange resource initialization Stephen Hemminger
[not found] ` <20140826020837.898427212-OTpzqLSitTUnbdJkjeBofR2eb7JE58TQ@public.gmane.org>
2014-08-26 7:14 ` Ouyang, Changchun
2014-08-26 2:07 ` [RFC 02/10] virtio: use weak barriers Stephen Hemminger
2014-08-26 2:07 ` [RFC 03/10] virtio: allow starting with link down Stephen Hemminger
2014-08-26 2:07 ` Stephen Hemminger [this message]
2014-08-26 2:07 ` [RFC 05/10] ether: add soft vlan encap/decap functions Stephen Hemminger
2014-08-26 2:07 ` [RFC 06/10] virtio: use software vlan stripping Stephen Hemminger
[not found] ` <20140826020848.386074683-OTpzqLSitTUnbdJkjeBofR2eb7JE58TQ@public.gmane.org>
2014-08-26 8:37 ` Ouyang, Changchun
[not found] ` <F52918179C57134FAEC9EA62FA2F96251183B285-E2R4CRU6q/6iAffOGbnezLfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2014-08-26 16:24 ` Stephen Hemminger
2014-08-27 5:42 ` Ouyang, Changchun
[not found] ` <F52918179C57134FAEC9EA62FA2F96251183B79C-E2R4CRU6q/6iAffOGbnezLfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2014-08-27 18:04 ` Stephen Hemminger
2014-08-26 2:07 ` [RFC 07/10] virtio: remove unnecessary adapter structure Stephen Hemminger
[not found] ` <20140826020851.474452281-OTpzqLSitTUnbdJkjeBofR2eb7JE58TQ@public.gmane.org>
2014-08-26 6:43 ` Ouyang, Changchun
2014-08-26 2:07 ` [RFC 08/10] virtio: remove redundant vq_alignment Stephen Hemminger
[not found] ` <20140826020853.851222673-OTpzqLSitTUnbdJkjeBofR2eb7JE58TQ@public.gmane.org>
2014-08-26 8:41 ` Ouyang, Changchun
2014-08-26 2:07 ` [RFC 09/10] virtio: fix how states are handled during initialization Stephen Hemminger
2014-08-26 2:07 ` [RFC 10/10] virtio: add support for promiscious and multicast Stephen Hemminger
[not found] ` <20140826020858.448904783-OTpzqLSitTUnbdJkjeBofR2eb7JE58TQ@public.gmane.org>
2014-08-26 6:55 ` Ouyang, Changchun
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=20140826020843.806847742@networkplumber.org \
--to=stephen-otpzqlsittunbdjkjebofr2eb7je58tq@public.gmane.org \
--cc=changchun.ouyang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=dev-VfR2kkLFssw@public.gmane.org \
--cc=shemming-43mecJUBy8ZBDgjK7y7TUQ@public.gmane.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.