162306a36Sopenharmony_ci/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright 2014-2016 Freescale Semiconductor Inc.
462306a36Sopenharmony_ci * Copyright 2017-2019 NXP
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci#ifndef __FSL_DPAA2_IO_H
862306a36Sopenharmony_ci#define __FSL_DPAA2_IO_H
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include <linux/types.h>
1162306a36Sopenharmony_ci#include <linux/cpumask.h>
1262306a36Sopenharmony_ci#include <linux/irqreturn.h>
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci#include "dpaa2-fd.h"
1562306a36Sopenharmony_ci#include "dpaa2-global.h"
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_cistruct dpaa2_io;
1862306a36Sopenharmony_cistruct dpaa2_io_store;
1962306a36Sopenharmony_cistruct device;
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci/**
2262306a36Sopenharmony_ci * DOC: DPIO Service
2362306a36Sopenharmony_ci *
2462306a36Sopenharmony_ci * The DPIO service provides APIs for users to interact with the datapath
2562306a36Sopenharmony_ci * by enqueueing and dequeing frame descriptors.
2662306a36Sopenharmony_ci *
2762306a36Sopenharmony_ci * The following set of APIs can be used to enqueue and dequeue frames
2862306a36Sopenharmony_ci * as well as producing notification callbacks when data is available
2962306a36Sopenharmony_ci * for dequeue.
3062306a36Sopenharmony_ci */
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#define DPAA2_IO_ANY_CPU	-1
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci/**
3562306a36Sopenharmony_ci * struct dpaa2_io_desc - The DPIO descriptor
3662306a36Sopenharmony_ci * @receives_notifications: Use notificaton mode. Non-zero if the DPIO
3762306a36Sopenharmony_ci *                  has a channel.
3862306a36Sopenharmony_ci * @has_8prio:      Set to non-zero for channel with 8 priority WQs.  Ignored
3962306a36Sopenharmony_ci *                  unless receives_notification is TRUE.
4062306a36Sopenharmony_ci * @cpu:            The cpu index that at least interrupt handlers will
4162306a36Sopenharmony_ci *                  execute on.
4262306a36Sopenharmony_ci * @stash_affinity: The stash affinity for this portal favour 'cpu'
4362306a36Sopenharmony_ci * @regs_cena:      The cache enabled regs.
4462306a36Sopenharmony_ci * @regs_cinh:      The cache inhibited regs
4562306a36Sopenharmony_ci * @dpio_id:        The dpio index
4662306a36Sopenharmony_ci * @qman_version:   The qman version
4762306a36Sopenharmony_ci * @qman_clk:       The qman clock frequency in Hz
4862306a36Sopenharmony_ci *
4962306a36Sopenharmony_ci * Describes the attributes and features of the DPIO object.
5062306a36Sopenharmony_ci */
5162306a36Sopenharmony_cistruct dpaa2_io_desc {
5262306a36Sopenharmony_ci	int receives_notifications;
5362306a36Sopenharmony_ci	int has_8prio;
5462306a36Sopenharmony_ci	int cpu;
5562306a36Sopenharmony_ci	void *regs_cena;
5662306a36Sopenharmony_ci	void __iomem *regs_cinh;
5762306a36Sopenharmony_ci	int dpio_id;
5862306a36Sopenharmony_ci	u32 qman_version;
5962306a36Sopenharmony_ci	u32 qman_clk;
6062306a36Sopenharmony_ci};
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_cistruct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc,
6362306a36Sopenharmony_ci				 struct device *dev);
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_civoid dpaa2_io_down(struct dpaa2_io *d);
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ciirqreturn_t dpaa2_io_irq(struct dpaa2_io *obj);
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_cistruct dpaa2_io *dpaa2_io_service_select(int cpu);
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci/**
7262306a36Sopenharmony_ci * struct dpaa2_io_notification_ctx - The DPIO notification context structure
7362306a36Sopenharmony_ci * @cb:           The callback to be invoked when the notification arrives
7462306a36Sopenharmony_ci * @is_cdan:      Zero for FQDAN, non-zero for CDAN
7562306a36Sopenharmony_ci * @id:           FQID or channel ID, needed for rearm
7662306a36Sopenharmony_ci * @desired_cpu:  The cpu on which the notifications will show up. Use
7762306a36Sopenharmony_ci *                DPAA2_IO_ANY_CPU if don't care
7862306a36Sopenharmony_ci * @dpio_id:      The dpio index
7962306a36Sopenharmony_ci * @qman64:       The 64-bit context value shows up in the FQDAN/CDAN.
8062306a36Sopenharmony_ci * @node:         The list node
8162306a36Sopenharmony_ci * @dpio_private: The dpio object internal to dpio_service
8262306a36Sopenharmony_ci *
8362306a36Sopenharmony_ci * Used when a FQDAN/CDAN registration is made by drivers.
8462306a36Sopenharmony_ci */
8562306a36Sopenharmony_cistruct dpaa2_io_notification_ctx {
8662306a36Sopenharmony_ci	void (*cb)(struct dpaa2_io_notification_ctx *ctx);
8762306a36Sopenharmony_ci	int is_cdan;
8862306a36Sopenharmony_ci	u32 id;
8962306a36Sopenharmony_ci	int desired_cpu;
9062306a36Sopenharmony_ci	int dpio_id;
9162306a36Sopenharmony_ci	u64 qman64;
9262306a36Sopenharmony_ci	struct list_head node;
9362306a36Sopenharmony_ci	void *dpio_private;
9462306a36Sopenharmony_ci};
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ciint dpaa2_io_get_cpu(struct dpaa2_io *d);
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ciint dpaa2_io_service_register(struct dpaa2_io *service,
9962306a36Sopenharmony_ci			      struct dpaa2_io_notification_ctx *ctx,
10062306a36Sopenharmony_ci			      struct device *dev);
10162306a36Sopenharmony_civoid dpaa2_io_service_deregister(struct dpaa2_io *service,
10262306a36Sopenharmony_ci				 struct dpaa2_io_notification_ctx *ctx,
10362306a36Sopenharmony_ci				 struct device *dev);
10462306a36Sopenharmony_ciint dpaa2_io_service_rearm(struct dpaa2_io *service,
10562306a36Sopenharmony_ci			   struct dpaa2_io_notification_ctx *ctx);
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ciint dpaa2_io_service_pull_fq(struct dpaa2_io *d, u32 fqid,
10862306a36Sopenharmony_ci			     struct dpaa2_io_store *s);
10962306a36Sopenharmony_ciint dpaa2_io_service_pull_channel(struct dpaa2_io *d, u32 channelid,
11062306a36Sopenharmony_ci				  struct dpaa2_io_store *s);
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ciint dpaa2_io_service_enqueue_fq(struct dpaa2_io *d, u32 fqid,
11362306a36Sopenharmony_ci				const struct dpaa2_fd *fd);
11462306a36Sopenharmony_ciint dpaa2_io_service_enqueue_multiple_fq(struct dpaa2_io *d, u32 fqid,
11562306a36Sopenharmony_ci				const struct dpaa2_fd *fd, int number_of_frame);
11662306a36Sopenharmony_ciint dpaa2_io_service_enqueue_multiple_desc_fq(struct dpaa2_io *d, u32 *fqid,
11762306a36Sopenharmony_ci				const struct dpaa2_fd *fd, int number_of_frame);
11862306a36Sopenharmony_ciint dpaa2_io_service_enqueue_qd(struct dpaa2_io *d, u32 qdid, u8 prio,
11962306a36Sopenharmony_ci				u16 qdbin, const struct dpaa2_fd *fd);
12062306a36Sopenharmony_ciint dpaa2_io_service_release(struct dpaa2_io *d, u16 bpid,
12162306a36Sopenharmony_ci			     const u64 *buffers, unsigned int num_buffers);
12262306a36Sopenharmony_ciint dpaa2_io_service_acquire(struct dpaa2_io *d, u16 bpid,
12362306a36Sopenharmony_ci			     u64 *buffers, unsigned int num_buffers);
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_cistruct dpaa2_io_store *dpaa2_io_store_create(unsigned int max_frames,
12662306a36Sopenharmony_ci					     struct device *dev);
12762306a36Sopenharmony_civoid dpaa2_io_store_destroy(struct dpaa2_io_store *s);
12862306a36Sopenharmony_cistruct dpaa2_dq *dpaa2_io_store_next(struct dpaa2_io_store *s, int *is_last);
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ciint dpaa2_io_query_fq_count(struct dpaa2_io *d, u32 fqid,
13162306a36Sopenharmony_ci			    u32 *fcnt, u32 *bcnt);
13262306a36Sopenharmony_ciint dpaa2_io_query_bp_count(struct dpaa2_io *d, u16 bpid,
13362306a36Sopenharmony_ci			    u32 *num);
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ciint dpaa2_io_set_irq_coalescing(struct dpaa2_io *d, u32 irq_holdoff);
13662306a36Sopenharmony_civoid dpaa2_io_get_irq_coalescing(struct dpaa2_io *d, u32 *irq_holdoff);
13762306a36Sopenharmony_civoid dpaa2_io_set_adaptive_coalescing(struct dpaa2_io *d,
13862306a36Sopenharmony_ci				      int use_adaptive_rx_coalesce);
13962306a36Sopenharmony_ciint dpaa2_io_get_adaptive_coalescing(struct dpaa2_io *d);
14062306a36Sopenharmony_civoid dpaa2_io_update_net_dim(struct dpaa2_io *d, __u64 frames, __u64 bytes);
14162306a36Sopenharmony_ci#endif /* __FSL_DPAA2_IO_H */
142