From: Nicholas Piggin <npiggin@gmail.com>
To: qemu-devel@nongnu.org
Cc: Nicholas Piggin <npiggin@gmail.com>,
Dmitry Fleytman <dmitry.fleytman@gmail.com>,
Akihiko Odaki <akihiko.odaki@daynix.com>,
Jason Wang <jasowang@redhat.com>,
Sriram Yagnaraman <sriram.yagnaraman@ericsson.com>,
Fabiano Rosas <farosas@suse.de>,
Laurent Vivier <lvivier@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: [PATCH 5/9] net/igb: Fix EITR LLI and counter fields
Date: Sat, 18 Jan 2025 03:03:01 +1000 [thread overview]
Message-ID: <20250117170306.403075-6-npiggin@gmail.com> (raw)
In-Reply-To: <20250117170306.403075-1-npiggin@gmail.com>
IGB EITR registers have counter fields which reflect the current ITR
and LLI counter values, as well as a bit to enable LLI moderation,
and a bit to write the register without modifying the counter fields.
Implement the ITR counter and log an unimp message if software tries
to enable LLI moderation. Fix the implementation of the counter ignore
bit.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
hw/net/igb_regs.h | 8 +++++--
hw/net/igb_core.c | 53 ++++++++++++++++++++++++++++++++++++++++-------
2 files changed, 51 insertions(+), 10 deletions(-)
diff --git a/hw/net/igb_regs.h b/hw/net/igb_regs.h
index 1ed5ee5039a..b612248264a 100644
--- a/hw/net/igb_regs.h
+++ b/hw/net/igb_regs.h
@@ -321,8 +321,12 @@ union e1000_adv_rx_desc {
#define E1000_EICR_TX_QUEUE3 0x00000800 /* Tx Queue 3 Interrupt */
#define E1000_EICR_OTHER 0x80000000 /* Interrupt Cause Active */
-/* Extended Interrupt Cause Set */
-/* E1000_EITR_CNT_IGNR is only for 82576 and newer */
+/* Extended Interrupt Throttle */
+/* These are only for 82576 and newer */
+#define E1000_EITR_INTERVAL 0x00007FFC
+#define E1000_EITR_LLI_EN 0x00008000
+#define E1000_EITR_LLI_CNT 0x001F0000
+#define E1000_EITR_ITR_CNT 0x7FE00000
#define E1000_EITR_CNT_IGNR 0x80000000 /* Don't reset counters on write */
#define E1000_TSYNCTXCTL_VALID 0x00000001 /* tx timestamp valid */
diff --git a/hw/net/igb_core.c b/hw/net/igb_core.c
index 94f9785749a..cdebc917d2e 100644
--- a/hw/net/igb_core.c
+++ b/hw/net/igb_core.c
@@ -140,12 +140,8 @@ static void igb_msix_notify(IGBCore *core, unsigned int cause)
}
static inline void
-igb_intrmgr_rearm_timer(IGBIntrDelayTimer *timer)
+igb_intrmgr_arm_timer(IGBIntrDelayTimer *timer, int64_t delay_ns)
{
- int64_t delay_ns =
- (int64_t)((timer->core->mac[timer->delay_reg] & 0x7FFC) >> 2) *
- timer->delay_resolution_ns;
-
trace_e1000e_irq_rearm_timer(timer->delay_reg << 2, delay_ns);
timer_mod(timer->timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + delay_ns);
@@ -153,6 +149,16 @@ igb_intrmgr_rearm_timer(IGBIntrDelayTimer *timer)
timer->running = true;
}
+static inline void
+igb_intrmgr_rearm_timer(IGBIntrDelayTimer *timer)
+{
+ uint32_t interval = (timer->core->mac[timer->delay_reg] &
+ E1000_EITR_INTERVAL) >> 2;
+ int64_t delay_ns = (int64_t)interval * timer->delay_resolution_ns;
+
+ igb_intrmgr_arm_timer(timer, delay_ns);
+}
+
static void
igb_intmgr_timer_resume(IGBIntrDelayTimer *timer)
{
@@ -2881,7 +2887,22 @@ igb_mac_swsm_read(IGBCore *core, int index)
static uint32_t
igb_mac_eitr_read(IGBCore *core, int index)
{
- return core->eitr_guest_value[index - EITR0];
+ uint32_t eitr_num = index - EITR0;
+ uint32_t val = core->mac[eitr_num];
+ IGBIntrDelayTimer *timer = &core->eitr[eitr_num];
+
+ if (timer->running) { /* ITR is enabled, get ITR counter */
+ int64_t remains = timer_expire_time_ns(timer->timer) -
+ qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
+ if (remains > 0) {
+ /* CNT is the most significant 10 of 12 bits */
+ uint32_t cnt;
+ cnt = remains / timer->delay_resolution_ns;
+ val |= ((cnt >> 2) << 21) & E1000_EITR_ITR_CNT;
+ }
+ }
+
+ return val;
}
static uint32_t igb_mac_vfmailbox_read(IGBCore *core, int index)
@@ -3047,8 +3068,24 @@ igb_set_eitr(IGBCore *core, int index, uint32_t val)
trace_igb_irq_eitr_set(eitr_num, val);
- core->eitr_guest_value[eitr_num] = val & ~E1000_EITR_CNT_IGNR;
- core->mac[index] = val & 0x7FFE;
+ if (val & E1000_EITR_LLI_EN) {
+ qemu_log_mask(LOG_UNIMP, "%s: LLI moderation not supported, ignoring\n",
+ __func__);
+ }
+
+ if (!(val & E1000_EITR_CNT_IGNR)) {
+ IGBIntrDelayTimer *timer = &core->eitr[eitr_num];
+ uint32_t itr_cnt = (val & E1000_EITR_ITR_CNT) >> 21;
+ /* CNT is the most significant 10 of 12 bits */
+ uint64_t ns = (itr_cnt << 2) * timer->delay_resolution_ns;
+
+ igb_intrmgr_arm_timer(timer, ns);
+ }
+
+ val &= E1000_EITR_INTERVAL | E1000_EITR_LLI_EN;
+
+ core->mac[index] = val;
+ core->eitr_guest_value[eitr_num] = val;
}
static void
--
2.45.2
next prev parent reply other threads:[~2025-01-17 17:03 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-17 17:02 [PATCH 0/9] hw/e1000e|igb: interrupts and qtests fixes Nicholas Piggin
2025-01-17 17:02 ` [PATCH 1/9] qtest/e1000e|igb: Clear interrupt-cause and msix pending bits after irq Nicholas Piggin
2025-01-17 17:02 ` [PATCH 2/9] net/e1000e: Permit disabling interrupt throttling Nicholas Piggin
2025-01-17 17:02 ` [PATCH 3/9] qtest/e1000e|igb: assert irqs are clear before triggering an irq Nicholas Piggin
2025-01-18 8:14 ` Akihiko Odaki
2025-01-19 9:22 ` Yan Vugenfirer
2025-01-21 4:45 ` Nicholas Piggin
2025-01-17 17:03 ` [PATCH 4/9] net/igb: Fix interrupt throttling interval calculation Nicholas Piggin
2025-01-18 8:22 ` Akihiko Odaki
2025-01-17 17:03 ` Nicholas Piggin [this message]
2025-01-18 8:37 ` [PATCH 5/9] net/igb: Fix EITR LLI and counter fields Akihiko Odaki
2025-01-17 17:03 ` [PATCH 6/9] net/e1000e|igb: Fix interrupt throttling logic Nicholas Piggin
2025-01-18 9:50 ` Akihiko Odaki
2025-01-17 17:03 ` [PATCH 7/9] qtest/e1000e|igb: Test interrupt throttling in multiple_transfers test Nicholas Piggin
2025-01-17 17:03 ` [PATCH 8/9] net/e1000e: Fix xITR minimum value Nicholas Piggin
2025-01-18 7:50 ` Akihiko Odaki
2025-01-17 17:03 ` [PATCH 9/9] hw/net/e1000e|igb: Remove xitr_guest_value logic Nicholas Piggin
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=20250117170306.403075-6-npiggin@gmail.com \
--to=npiggin@gmail.com \
--cc=akihiko.odaki@daynix.com \
--cc=dmitry.fleytman@gmail.com \
--cc=farosas@suse.de \
--cc=jasowang@redhat.com \
--cc=lvivier@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sriram.yagnaraman@ericsson.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).