1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
3 * Copyright 2014-2016 Freescale Semiconductor Inc.
4 * Copyright 2016-2019 NXP
7 #include <linux/types.h>
8 #include <linux/fsl/mc.h>
9 #include <soc/fsl/dpaa2-io.h>
10 #include <linux/init.h>
11 #include <linux/module.h>
12 #include <linux/platform_device.h>
13 #include <linux/interrupt.h>
14 #include <linux/dma-mapping.h>
15 #include <linux/dim.h>
16 #include <linux/slab.h>
19 #include "qbman-portal.h"
22 struct dpaa2_io_desc dpio_desc;
23 struct qbman_swp_desc swp_desc;
24 struct qbman_swp *swp;
25 struct list_head node;
26 /* protect against multiple management commands */
27 spinlock_t lock_mgmt_cmd;
28 /* protect notifications list */
29 spinlock_t lock_notifications;
30 struct list_head notifications;
35 /* protect against concurrent Net DIM updates */
42 struct dpaa2_io_store {
45 struct dpaa2_dq *vaddr;
46 void *alloced_addr; /* unaligned value from kmalloc() */
47 unsigned int idx; /* position of the next-to-be-returned entry */
48 struct qbman_swp *swp; /* portal used to issue VDQCR */
49 struct device *dev; /* device used for DMA mapping */
52 /* keep a per cpu array of DPIOs for fast access */
53 static struct dpaa2_io *dpio_by_cpu[NR_CPUS];
54 static struct list_head dpio_list = LIST_HEAD_INIT(dpio_list);
55 static DEFINE_SPINLOCK(dpio_list_lock);
57 static inline struct dpaa2_io *service_select_by_cpu(struct dpaa2_io *d,
63 if (cpu != DPAA2_IO_ANY_CPU && cpu >= num_possible_cpus())
67 * If cpu == -1, choose the current cpu, with no guarantees about
68 * potentially being migrated away.
71 cpu = raw_smp_processor_id();
73 /* If a specific cpu was requested, pick it up immediately */
74 return dpio_by_cpu[cpu];
77 static inline struct dpaa2_io *service_select(struct dpaa2_io *d)
82 d = service_select_by_cpu(d, -1);
86 spin_lock(&dpio_list_lock);
87 d = list_entry(dpio_list.next, struct dpaa2_io, node);
89 list_add_tail(&d->node, &dpio_list);
90 spin_unlock(&dpio_list_lock);
96 * dpaa2_io_service_select() - return a dpaa2_io service affined to this cpu
99 * Return the affine dpaa2_io service, or NULL if there is no service affined
100 * to the specified cpu. If DPAA2_IO_ANY_CPU is used, return the next available
103 struct dpaa2_io *dpaa2_io_service_select(int cpu)
105 if (cpu == DPAA2_IO_ANY_CPU)
106 return service_select(NULL);
108 return service_select_by_cpu(NULL, cpu);
110 EXPORT_SYMBOL_GPL(dpaa2_io_service_select);
112 static void dpaa2_io_dim_work(struct work_struct *w)
114 struct dim *dim = container_of(w, struct dim, work);
115 struct dim_cq_moder moder =
116 net_dim_get_rx_moderation(dim->mode, dim->profile_ix);
117 struct dpaa2_io *d = container_of(dim, struct dpaa2_io, rx_dim);
119 dpaa2_io_set_irq_coalescing(d, moder.usec);
120 dim->state = DIM_START_MEASURE;
124 * dpaa2_io_create() - create a dpaa2_io object.
125 * @desc: the dpaa2_io descriptor
126 * @dev: the actual DPIO device
128 * Activates a "struct dpaa2_io" corresponding to the given config of an actual
131 * Return a valid dpaa2_io object for success, or NULL for failure.
133 struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc,
136 struct dpaa2_io *obj = kmalloc(sizeof(*obj), GFP_KERNEL);
137 u32 qman_256_cycles_per_ns;
142 /* check if CPU is out of range (-1 means any cpu) */
143 if (desc->cpu != DPAA2_IO_ANY_CPU && desc->cpu >= num_possible_cpus()) {
148 obj->dpio_desc = *desc;
149 obj->swp_desc.cena_bar = obj->dpio_desc.regs_cena;
150 obj->swp_desc.cinh_bar = obj->dpio_desc.regs_cinh;
151 obj->swp_desc.qman_clk = obj->dpio_desc.qman_clk;
152 obj->swp_desc.qman_version = obj->dpio_desc.qman_version;
154 /* Compute how many 256 QBMAN cycles fit into one ns. This is because
155 * the interrupt timeout period register needs to be specified in QBMAN
156 * clock cycles in increments of 256.
158 qman_256_cycles_per_ns = 256000 / (obj->swp_desc.qman_clk / 1000000);
159 obj->swp_desc.qman_256_cycles_per_ns = qman_256_cycles_per_ns;
160 obj->swp = qbman_swp_init(&obj->swp_desc);
167 INIT_LIST_HEAD(&obj->node);
168 spin_lock_init(&obj->lock_mgmt_cmd);
169 spin_lock_init(&obj->lock_notifications);
170 spin_lock_init(&obj->dim_lock);
171 INIT_LIST_HEAD(&obj->notifications);
173 /* For now only enable DQRR interrupts */
174 qbman_swp_interrupt_set_trigger(obj->swp,
175 QBMAN_SWP_INTERRUPT_DQRI);
176 qbman_swp_interrupt_clear_status(obj->swp, 0xffffffff);
177 if (obj->dpio_desc.receives_notifications)
178 qbman_swp_push_set(obj->swp, 0, 1);
180 spin_lock(&dpio_list_lock);
181 list_add_tail(&obj->node, &dpio_list);
182 if (desc->cpu >= 0 && !dpio_by_cpu[desc->cpu])
183 dpio_by_cpu[desc->cpu] = obj;
184 spin_unlock(&dpio_list_lock);
188 memset(&obj->rx_dim, 0, sizeof(obj->rx_dim));
189 INIT_WORK(&obj->rx_dim.work, dpaa2_io_dim_work);
198 * dpaa2_io_down() - release the dpaa2_io object.
199 * @d: the dpaa2_io object to be released.
201 * The "struct dpaa2_io" type can represent an individual DPIO object (as
202 * described by "struct dpaa2_io_desc") or an instance of a "DPIO service",
203 * which can be used to group/encapsulate multiple DPIO objects. In all cases,
204 * each handle obtained should be released using this function.
206 void dpaa2_io_down(struct dpaa2_io *d)
208 spin_lock(&dpio_list_lock);
209 dpio_by_cpu[d->dpio_desc.cpu] = NULL;
211 spin_unlock(&dpio_list_lock);
216 #define DPAA_POLL_MAX 32
219 * dpaa2_io_irq() - ISR for DPIO interrupts
221 * @obj: the given DPIO object.
223 * Return IRQ_HANDLED for success or IRQ_NONE if there
224 * were no pending interrupts.
226 irqreturn_t dpaa2_io_irq(struct dpaa2_io *obj)
228 const struct dpaa2_dq *dq;
230 struct qbman_swp *swp;
236 status = qbman_swp_interrupt_read_status(swp);
240 dq = qbman_swp_dqrr_next(swp);
242 if (qbman_result_is_SCN(dq)) {
243 struct dpaa2_io_notification_ctx *ctx;
246 q64 = qbman_result_SCN_ctx(dq);
247 ctx = (void *)(uintptr_t)q64;
250 pr_crit("fsl-mc-dpio: Unrecognised/ignored DQRR entry\n");
252 qbman_swp_dqrr_consume(swp, dq);
254 if (max > DPAA_POLL_MAX)
256 dq = qbman_swp_dqrr_next(swp);
259 qbman_swp_interrupt_clear_status(swp, status);
260 qbman_swp_interrupt_set_inhibit(swp, 0);
265 * dpaa2_io_get_cpu() - get the cpu associated with a given DPIO object
267 * @d: the given DPIO object.
269 * Return the cpu associated with the DPIO object
271 int dpaa2_io_get_cpu(struct dpaa2_io *d)
273 return d->dpio_desc.cpu;
275 EXPORT_SYMBOL(dpaa2_io_get_cpu);
278 * dpaa2_io_service_register() - Prepare for servicing of FQDAN or CDAN
279 * notifications on the given DPIO service.
280 * @d: the given DPIO service.
281 * @ctx: the notification context.
282 * @dev: the device that requests the register
284 * The caller should make the MC command to attach a DPAA2 object to
285 * a DPIO after this function completes successfully. In that way:
286 * (a) The DPIO service is "ready" to handle a notification arrival
287 * (which might happen before the "attach" command to MC has
288 * returned control of execution back to the caller)
289 * (b) The DPIO service can provide back to the caller the 'dpio_id' and
290 * 'qman64' parameters that it should pass along in the MC command
291 * in order for the object to be configured to produce the right
292 * notification fields to the DPIO service.
294 * Return 0 for success, or -ENODEV for failure.
296 int dpaa2_io_service_register(struct dpaa2_io *d,
297 struct dpaa2_io_notification_ctx *ctx,
300 struct device_link *link;
301 unsigned long irqflags;
303 d = service_select_by_cpu(d, ctx->desired_cpu);
307 link = device_link_add(dev, d->dev, DL_FLAG_AUTOREMOVE_CONSUMER);
311 ctx->dpio_id = d->dpio_desc.dpio_id;
312 ctx->qman64 = (u64)(uintptr_t)ctx;
313 ctx->dpio_private = d;
314 spin_lock_irqsave(&d->lock_notifications, irqflags);
315 list_add(&ctx->node, &d->notifications);
316 spin_unlock_irqrestore(&d->lock_notifications, irqflags);
318 /* Enable the generation of CDAN notifications */
320 return qbman_swp_CDAN_set_context_enable(d->swp,
325 EXPORT_SYMBOL_GPL(dpaa2_io_service_register);
328 * dpaa2_io_service_deregister - The opposite of 'register'.
329 * @service: the given DPIO service.
330 * @ctx: the notification context.
331 * @dev: the device that requests to be deregistered
333 * This function should be called only after sending the MC command to
334 * to detach the notification-producing device from the DPIO.
336 void dpaa2_io_service_deregister(struct dpaa2_io *service,
337 struct dpaa2_io_notification_ctx *ctx,
340 struct dpaa2_io *d = ctx->dpio_private;
341 unsigned long irqflags;
344 qbman_swp_CDAN_disable(d->swp, (u16)ctx->id);
346 spin_lock_irqsave(&d->lock_notifications, irqflags);
347 list_del(&ctx->node);
348 spin_unlock_irqrestore(&d->lock_notifications, irqflags);
351 EXPORT_SYMBOL_GPL(dpaa2_io_service_deregister);
354 * dpaa2_io_service_rearm() - Rearm the notification for the given DPIO service.
355 * @d: the given DPIO service.
356 * @ctx: the notification context.
358 * Once a FQDAN/CDAN has been produced, the corresponding FQ/channel is
359 * considered "disarmed". Ie. the user can issue pull dequeue operations on that
360 * traffic source for as long as it likes. Eventually it may wish to "rearm"
361 * that source to allow it to produce another FQDAN/CDAN, that's what this
364 * Return 0 for success.
366 int dpaa2_io_service_rearm(struct dpaa2_io *d,
367 struct dpaa2_io_notification_ctx *ctx)
369 unsigned long irqflags;
372 d = service_select_by_cpu(d, ctx->desired_cpu);
376 spin_lock_irqsave(&d->lock_mgmt_cmd, irqflags);
378 err = qbman_swp_CDAN_enable(d->swp, (u16)ctx->id);
380 err = qbman_swp_fq_schedule(d->swp, ctx->id);
381 spin_unlock_irqrestore(&d->lock_mgmt_cmd, irqflags);
385 EXPORT_SYMBOL_GPL(dpaa2_io_service_rearm);
388 * dpaa2_io_service_pull_fq() - pull dequeue functions from a fq.
389 * @d: the given DPIO service.
390 * @fqid: the given frame queue id.
391 * @s: the dpaa2_io_store object for the result.
393 * Return 0 for success, or error code for failure.
395 int dpaa2_io_service_pull_fq(struct dpaa2_io *d, u32 fqid,
396 struct dpaa2_io_store *s)
398 struct qbman_pull_desc pd;
401 qbman_pull_desc_clear(&pd);
402 qbman_pull_desc_set_storage(&pd, s->vaddr, s->paddr, 1);
403 qbman_pull_desc_set_numframes(&pd, (u8)s->max);
404 qbman_pull_desc_set_fq(&pd, fqid);
406 d = service_select(d);
410 err = qbman_swp_pull(d->swp, &pd);
416 EXPORT_SYMBOL(dpaa2_io_service_pull_fq);
419 * dpaa2_io_service_pull_channel() - pull dequeue functions from a channel.
420 * @d: the given DPIO service.
421 * @channelid: the given channel id.
422 * @s: the dpaa2_io_store object for the result.
424 * Return 0 for success, or error code for failure.
426 int dpaa2_io_service_pull_channel(struct dpaa2_io *d, u32 channelid,
427 struct dpaa2_io_store *s)
429 struct qbman_pull_desc pd;
432 qbman_pull_desc_clear(&pd);
433 qbman_pull_desc_set_storage(&pd, s->vaddr, s->paddr, 1);
434 qbman_pull_desc_set_numframes(&pd, (u8)s->max);
435 qbman_pull_desc_set_channel(&pd, channelid, qbman_pull_type_prio);
437 d = service_select(d);
442 err = qbman_swp_pull(d->swp, &pd);
448 EXPORT_SYMBOL_GPL(dpaa2_io_service_pull_channel);
451 * dpaa2_io_service_enqueue_fq() - Enqueue a frame to a frame queue.
452 * @d: the given DPIO service.
453 * @fqid: the given frame queue id.
454 * @fd: the frame descriptor which is enqueued.
456 * Return 0 for successful enqueue, -EBUSY if the enqueue ring is not ready,
457 * or -ENODEV if there is no dpio service.
459 int dpaa2_io_service_enqueue_fq(struct dpaa2_io *d,
461 const struct dpaa2_fd *fd)
463 struct qbman_eq_desc ed;
465 d = service_select(d);
469 qbman_eq_desc_clear(&ed);
470 qbman_eq_desc_set_no_orp(&ed, 0);
471 qbman_eq_desc_set_fq(&ed, fqid);
473 return qbman_swp_enqueue(d->swp, &ed, fd);
475 EXPORT_SYMBOL(dpaa2_io_service_enqueue_fq);
478 * dpaa2_io_service_enqueue_multiple_fq() - Enqueue multiple frames
479 * to a frame queue using one fqid.
480 * @d: the given DPIO service.
481 * @fqid: the given frame queue id.
482 * @fd: the frame descriptor which is enqueued.
483 * @nb: number of frames to be enqueud
485 * Return 0 for successful enqueue, -EBUSY if the enqueue ring is not ready,
486 * or -ENODEV if there is no dpio service.
488 int dpaa2_io_service_enqueue_multiple_fq(struct dpaa2_io *d,
490 const struct dpaa2_fd *fd,
493 struct qbman_eq_desc ed;
495 d = service_select(d);
499 qbman_eq_desc_clear(&ed);
500 qbman_eq_desc_set_no_orp(&ed, 0);
501 qbman_eq_desc_set_fq(&ed, fqid);
503 return qbman_swp_enqueue_multiple(d->swp, &ed, fd, NULL, nb);
505 EXPORT_SYMBOL(dpaa2_io_service_enqueue_multiple_fq);
508 * dpaa2_io_service_enqueue_multiple_desc_fq() - Enqueue multiple frames
509 * to different frame queue using a list of fqids.
510 * @d: the given DPIO service.
511 * @fqid: the given list of frame queue ids.
512 * @fd: the frame descriptor which is enqueued.
513 * @nb: number of frames to be enqueud
515 * Return 0 for successful enqueue, -EBUSY if the enqueue ring is not ready,
516 * or -ENODEV if there is no dpio service.
518 int dpaa2_io_service_enqueue_multiple_desc_fq(struct dpaa2_io *d,
520 const struct dpaa2_fd *fd,
523 struct qbman_eq_desc *ed;
526 ed = kcalloc(sizeof(struct qbman_eq_desc), 32, GFP_KERNEL);
530 d = service_select(d);
536 for (i = 0; i < nb; i++) {
537 qbman_eq_desc_clear(&ed[i]);
538 qbman_eq_desc_set_no_orp(&ed[i], 0);
539 qbman_eq_desc_set_fq(&ed[i], fqid[i]);
542 ret = qbman_swp_enqueue_multiple_desc(d->swp, &ed[0], fd, nb);
547 EXPORT_SYMBOL(dpaa2_io_service_enqueue_multiple_desc_fq);
550 * dpaa2_io_service_enqueue_qd() - Enqueue a frame to a QD.
551 * @d: the given DPIO service.
552 * @qdid: the given queuing destination id.
553 * @prio: the given queuing priority.
554 * @qdbin: the given queuing destination bin.
555 * @fd: the frame descriptor which is enqueued.
557 * Return 0 for successful enqueue, or -EBUSY if the enqueue ring is not ready,
558 * or -ENODEV if there is no dpio service.
560 int dpaa2_io_service_enqueue_qd(struct dpaa2_io *d,
561 u32 qdid, u8 prio, u16 qdbin,
562 const struct dpaa2_fd *fd)
564 struct qbman_eq_desc ed;
566 d = service_select(d);
570 qbman_eq_desc_clear(&ed);
571 qbman_eq_desc_set_no_orp(&ed, 0);
572 qbman_eq_desc_set_qd(&ed, qdid, qdbin, prio);
574 return qbman_swp_enqueue(d->swp, &ed, fd);
576 EXPORT_SYMBOL_GPL(dpaa2_io_service_enqueue_qd);
579 * dpaa2_io_service_release() - Release buffers to a buffer pool.
580 * @d: the given DPIO object.
581 * @bpid: the buffer pool id.
582 * @buffers: the buffers to be released.
583 * @num_buffers: the number of the buffers to be released.
585 * Return 0 for success, and negative error code for failure.
587 int dpaa2_io_service_release(struct dpaa2_io *d,
590 unsigned int num_buffers)
592 struct qbman_release_desc rd;
594 d = service_select(d);
598 qbman_release_desc_clear(&rd);
599 qbman_release_desc_set_bpid(&rd, bpid);
601 return qbman_swp_release(d->swp, &rd, buffers, num_buffers);
603 EXPORT_SYMBOL_GPL(dpaa2_io_service_release);
606 * dpaa2_io_service_acquire() - Acquire buffers from a buffer pool.
607 * @d: the given DPIO object.
608 * @bpid: the buffer pool id.
609 * @buffers: the buffer addresses for acquired buffers.
610 * @num_buffers: the expected number of the buffers to acquire.
612 * Return a negative error code if the command failed, otherwise it returns
613 * the number of buffers acquired, which may be less than the number requested.
614 * Eg. if the buffer pool is empty, this will return zero.
616 int dpaa2_io_service_acquire(struct dpaa2_io *d,
619 unsigned int num_buffers)
621 unsigned long irqflags;
624 d = service_select(d);
628 spin_lock_irqsave(&d->lock_mgmt_cmd, irqflags);
629 err = qbman_swp_acquire(d->swp, bpid, buffers, num_buffers);
630 spin_unlock_irqrestore(&d->lock_mgmt_cmd, irqflags);
634 EXPORT_SYMBOL_GPL(dpaa2_io_service_acquire);
637 * 'Stores' are reusable memory blocks for holding dequeue results, and to
638 * assist with parsing those results.
642 * dpaa2_io_store_create() - Create the dma memory storage for dequeue result.
643 * @max_frames: the maximum number of dequeued result for frames, must be <= 32.
644 * @dev: the device to allow mapping/unmapping the DMAable region.
646 * The size of the storage is "max_frames*sizeof(struct dpaa2_dq)".
647 * The 'dpaa2_io_store' returned is a DPIO service managed object.
649 * Return pointer to dpaa2_io_store struct for successfully created storage
650 * memory, or NULL on error.
652 struct dpaa2_io_store *dpaa2_io_store_create(unsigned int max_frames,
655 struct dpaa2_io_store *ret;
658 if (!max_frames || (max_frames > 32))
661 ret = kmalloc(sizeof(*ret), GFP_KERNEL);
665 ret->max = max_frames;
666 size = max_frames * sizeof(struct dpaa2_dq) + 64;
667 ret->alloced_addr = kzalloc(size, GFP_KERNEL);
668 if (!ret->alloced_addr) {
673 ret->vaddr = PTR_ALIGN(ret->alloced_addr, 64);
674 ret->paddr = dma_map_single(dev, ret->vaddr,
675 sizeof(struct dpaa2_dq) * max_frames,
677 if (dma_mapping_error(dev, ret->paddr)) {
678 kfree(ret->alloced_addr);
688 EXPORT_SYMBOL_GPL(dpaa2_io_store_create);
691 * dpaa2_io_store_destroy() - Frees the dma memory storage for dequeue
693 * @s: the storage memory to be destroyed.
695 void dpaa2_io_store_destroy(struct dpaa2_io_store *s)
697 dma_unmap_single(s->dev, s->paddr, sizeof(struct dpaa2_dq) * s->max,
699 kfree(s->alloced_addr);
702 EXPORT_SYMBOL_GPL(dpaa2_io_store_destroy);
705 * dpaa2_io_store_next() - Determine when the next dequeue result is available.
706 * @s: the dpaa2_io_store object.
707 * @is_last: indicate whether this is the last frame in the pull command.
709 * When an object driver performs dequeues to a dpaa2_io_store, this function
710 * can be used to determine when the next frame result is available. Once
711 * this function returns non-NULL, a subsequent call to it will try to find
712 * the next dequeue result.
714 * Note that if a pull-dequeue has a NULL result because the target FQ/channel
715 * was empty, then this function will also return NULL (rather than expecting
716 * the caller to always check for this. As such, "is_last" can be used to
717 * differentiate between "end-of-empty-dequeue" and "still-waiting".
719 * Return dequeue result for a valid dequeue result, or NULL for empty dequeue.
721 struct dpaa2_dq *dpaa2_io_store_next(struct dpaa2_io_store *s, int *is_last)
724 struct dpaa2_dq *ret = &s->vaddr[s->idx];
726 match = qbman_result_has_new_result(s->swp, ret);
734 if (dpaa2_dq_is_pull_complete(ret)) {
738 * If we get an empty dequeue result to terminate a zero-results
739 * vdqcr, return NULL to the caller rather than expecting him to
740 * check non-NULL results every time.
742 if (!(dpaa2_dq_flags(ret) & DPAA2_DQ_STAT_VALIDFRAME))
745 prefetch(&s->vaddr[s->idx]);
751 EXPORT_SYMBOL_GPL(dpaa2_io_store_next);
754 * dpaa2_io_query_fq_count() - Get the frame and byte count for a given fq.
755 * @d: the given DPIO object.
756 * @fqid: the id of frame queue to be queried.
757 * @fcnt: the queried frame count.
758 * @bcnt: the queried byte count.
760 * Knowing the FQ count at run-time can be useful in debugging situations.
761 * The instantaneous frame- and byte-count are hereby returned.
763 * Return 0 for a successful query, and negative error code if query fails.
765 int dpaa2_io_query_fq_count(struct dpaa2_io *d, u32 fqid,
766 u32 *fcnt, u32 *bcnt)
768 struct qbman_fq_query_np_rslt state;
769 struct qbman_swp *swp;
770 unsigned long irqflags;
773 d = service_select(d);
778 spin_lock_irqsave(&d->lock_mgmt_cmd, irqflags);
779 ret = qbman_fq_query_state(swp, fqid, &state);
780 spin_unlock_irqrestore(&d->lock_mgmt_cmd, irqflags);
783 *fcnt = qbman_fq_state_frame_count(&state);
784 *bcnt = qbman_fq_state_byte_count(&state);
788 EXPORT_SYMBOL_GPL(dpaa2_io_query_fq_count);
791 * dpaa2_io_query_bp_count() - Query the number of buffers currently in a
793 * @d: the given DPIO object.
794 * @bpid: the index of buffer pool to be queried.
795 * @num: the queried number of buffers in the buffer pool.
797 * Return 0 for a successful query, and negative error code if query fails.
799 int dpaa2_io_query_bp_count(struct dpaa2_io *d, u16 bpid, u32 *num)
801 struct qbman_bp_query_rslt state;
802 struct qbman_swp *swp;
803 unsigned long irqflags;
806 d = service_select(d);
811 spin_lock_irqsave(&d->lock_mgmt_cmd, irqflags);
812 ret = qbman_bp_query(swp, bpid, &state);
813 spin_unlock_irqrestore(&d->lock_mgmt_cmd, irqflags);
816 *num = qbman_bp_info_num_free_bufs(&state);
819 EXPORT_SYMBOL_GPL(dpaa2_io_query_bp_count);
822 * dpaa2_io_set_irq_coalescing() - Set new IRQ coalescing values
823 * @d: the given DPIO object
824 * @irq_holdoff: interrupt holdoff (timeout) period in us
826 * Return 0 for success, or negative error code on error.
828 int dpaa2_io_set_irq_coalescing(struct dpaa2_io *d, u32 irq_holdoff)
830 struct qbman_swp *swp = d->swp;
832 return qbman_swp_set_irq_coalescing(swp, swp->dqrr.dqrr_size - 1,
835 EXPORT_SYMBOL(dpaa2_io_set_irq_coalescing);
838 * dpaa2_io_get_irq_coalescing() - Get the current IRQ coalescing parameters
839 * @d: the given DPIO object
840 * @irq_holdoff: interrupt holdoff (timeout) period in us
842 void dpaa2_io_get_irq_coalescing(struct dpaa2_io *d, u32 *irq_holdoff)
844 struct qbman_swp *swp = d->swp;
846 qbman_swp_get_irq_coalescing(swp, NULL, irq_holdoff);
848 EXPORT_SYMBOL(dpaa2_io_get_irq_coalescing);
851 * dpaa2_io_set_adaptive_coalescing() - Enable/disable adaptive coalescing
852 * @d: the given DPIO object
853 * @use_adaptive_rx_coalesce: adaptive coalescing state
855 void dpaa2_io_set_adaptive_coalescing(struct dpaa2_io *d,
856 int use_adaptive_rx_coalesce)
858 d->swp->use_adaptive_rx_coalesce = use_adaptive_rx_coalesce;
860 EXPORT_SYMBOL(dpaa2_io_set_adaptive_coalescing);
863 * dpaa2_io_get_adaptive_coalescing() - Query adaptive coalescing state
864 * @d: the given DPIO object
866 * Return 1 when adaptive coalescing is enabled on the DPIO object and 0
869 int dpaa2_io_get_adaptive_coalescing(struct dpaa2_io *d)
871 return d->swp->use_adaptive_rx_coalesce;
873 EXPORT_SYMBOL(dpaa2_io_get_adaptive_coalescing);
876 * dpaa2_io_update_net_dim() - Update Net DIM
877 * @d: the given DPIO object
878 * @frames: how many frames have been dequeued by the user since the last call
879 * @bytes: how many bytes have been dequeued by the user since the last call
881 void dpaa2_io_update_net_dim(struct dpaa2_io *d, __u64 frames, __u64 bytes)
883 struct dim_sample dim_sample = {};
885 if (!d->swp->use_adaptive_rx_coalesce)
888 spin_lock(&d->dim_lock);
893 dim_update_sample(d->event_ctr, d->frames, d->bytes, &dim_sample);
894 net_dim(&d->rx_dim, dim_sample);
896 spin_unlock(&d->dim_lock);
898 EXPORT_SYMBOL(dpaa2_io_update_net_dim);