u32 old, new;
if (ring->irq > 0) {
- u32 step, shift, ivr, misc;
+ u32 step, shift, ivr, misc, itr;
void __iomem *ivr_base;
int auto_clear_bit;
int index;
if (active)
ivr |= ring->vector << shift;
iowrite32(ivr, ivr_base + step);
+
+ /* Throttling is specified in 256ns increments */
+ itr = DIV_ROUND_UP(ring->interval_nsec, 256);
+ itr &= REG_INT_THROTTLING_RATE_INTERVAL_MASK;
+ iowrite32(itr, ring->nhi->iobase + REG_INT_THROTTLING_RATE +
+ ring->vector * 4);
}
old = ioread32(ring->nhi->iobase + reg);
}
EXPORT_SYMBOL_GPL(tb_ring_free);
+/**
+ * tb_ring_throttling() - Configure throttling for ring interrupt
+ * @ring: Ring to configure
+ * @interval_nsec: Interval counter for moderation (in ns), %0 disables
+ *
+ * Enables or disables ring interrupt throttling. The ring must be
+ * stopped for this to be called. Granularity is 256 ns.
+ *
+ * Return: %0 on success, negative errno otherwise.
+ */
+int tb_ring_throttling(struct tb_ring *ring, unsigned int interval_nsec)
+{
+ guard(spinlock_irqsave)(&ring->lock);
+ if (WARN_ON_ONCE(ring->running))
+ return -EBUSY;
+ ring->interval_nsec = interval_nsec;
+ return 0;
+}
+EXPORT_SYMBOL_GPL(tb_ring_throttling);
+
/**
* nhi_mailbox_cmd() - Send a command through NHI mailbox
* @nhi: Pointer to the NHI structure
return __nhi_suspend_noirq(dev, wakeup);
}
-static void nhi_enable_int_throttling(struct tb_nhi *nhi)
-{
- /* Throttling is specified in 256ns increments */
- u32 throttle = DIV_ROUND_UP(128 * NSEC_PER_USEC, 256);
- unsigned int i;
-
- /*
- * Configure interrupt throttling for all vectors even if we
- * only use few.
- */
- for (i = 0; i < MSIX_MAX_VECS; i++) {
- u32 reg = REG_INT_THROTTLING_RATE + i * 4;
- iowrite32(throttle, nhi->iobase + reg);
- }
-}
-
static int nhi_resume_noirq(struct device *dev)
{
struct pci_dev *pdev = to_pci_dev(dev);
*/
if (!pci_device_is_present(pdev)) {
nhi->going_away = true;
- } else {
- if (nhi->ops && nhi->ops->resume_noirq) {
- ret = nhi->ops->resume_noirq(nhi);
- if (ret)
- return ret;
- }
- nhi_enable_int_throttling(tb->nhi);
+ } else if (nhi->ops && nhi->ops->resume_noirq) {
+ ret = nhi->ops->resume_noirq(nhi);
+ if (ret)
+ return ret;
}
return tb_domain_resume_noirq(tb);
return ret;
}
- nhi_enable_int_throttling(nhi);
return tb_domain_runtime_resume(tb);
}
/* In case someone left them on. */
nhi_disable_interrupts(nhi);
- nhi_enable_int_throttling(nhi);
-
ida_init(&nhi->msix_ida);
/*
* @start_poll: Called when ring interrupt is triggered to start
* polling. Passing %NULL keeps the ring in interrupt mode.
* @poll_data: Data passed to @start_poll
+ * @interval_nsec: Interval counter if interrupt throttling is to be
+ * used with this ring (in ns)
*/
struct tb_ring {
spinlock_t lock;
u16 eof_mask;
void (*start_poll)(void *data);
void *poll_data;
+ unsigned int interval_nsec;
};
/* Leave ring interrupt enabled on suspend */
struct ring_frame *tb_ring_poll(struct tb_ring *ring);
void tb_ring_poll_complete(struct tb_ring *ring);
+int tb_ring_throttling(struct tb_ring *ring, unsigned int interval_nsec);
+
/**
* tb_ring_dma_device() - Return device used for DMA mapping
* @ring: Ring whose DMA device is retrieved