GNU Linux-libre 4.14.290-gnu1
[releases.git] / drivers / staging / fsl-mc / include / dpaa2-io.h
1 /*
2  * Copyright 2014-2016 Freescale Semiconductor Inc.
3  * Copyright NXP
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *     * Redistributions of source code must retain the above copyright
8  *       notice, this list of conditions and the following disclaimer.
9  *     * Redistributions in binary form must reproduce the above copyright
10  *       notice, this list of conditions and the following disclaimer in the
11  *       documentation and/or other materials provided with the distribution.
12  *     * Neither the name of Freescale Semiconductor nor the
13  *       names of its contributors may be used to endorse or promote products
14  *       derived from this software without specific prior written permission.
15  *
16  * ALTERNATIVELY, this software may be distributed under the terms of the
17  * GNU General Public License ("GPL") as published by the Free Software
18  * Foundation, either version 2 of that License or (at your option) any
19  * later version.
20  *
21  * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
22  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24  * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
25  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 #ifndef __FSL_DPAA2_IO_H
33 #define __FSL_DPAA2_IO_H
34
35 #include <linux/types.h>
36 #include <linux/cpumask.h>
37 #include <linux/irqreturn.h>
38
39 #include "dpaa2-fd.h"
40 #include "dpaa2-global.h"
41
42 struct dpaa2_io;
43 struct dpaa2_io_store;
44 struct device;
45
46 /**
47  * DOC: DPIO Service
48  *
49  * The DPIO service provides APIs for users to interact with the datapath
50  * by enqueueing and dequeing frame descriptors.
51  *
52  * The following set of APIs can be used to enqueue and dequeue frames
53  * as well as producing notification callbacks when data is available
54  * for dequeue.
55  */
56
57 #define DPAA2_IO_ANY_CPU        -1
58
59 /**
60  * struct dpaa2_io_desc - The DPIO descriptor
61  * @receives_notifications: Use notificaton mode. Non-zero if the DPIO
62  *                  has a channel.
63  * @has_8prio:      Set to non-zero for channel with 8 priority WQs.  Ignored
64  *                  unless receives_notification is TRUE.
65  * @cpu:            The cpu index that at least interrupt handlers will
66  *                  execute on.
67  * @stash_affinity: The stash affinity for this portal favour 'cpu'
68  * @regs_cena:      The cache enabled regs.
69  * @regs_cinh:      The cache inhibited regs
70  * @dpio_id:        The dpio index
71  * @qman_version:   The qman version
72  *
73  * Describes the attributes and features of the DPIO object.
74  */
75 struct dpaa2_io_desc {
76         int receives_notifications;
77         int has_8prio;
78         int cpu;
79         void *regs_cena;
80         void *regs_cinh;
81         int dpio_id;
82         u32 qman_version;
83 };
84
85 struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc);
86
87 void dpaa2_io_down(struct dpaa2_io *d);
88
89 irqreturn_t dpaa2_io_irq(struct dpaa2_io *obj);
90
91 /**
92  * struct dpaa2_io_notification_ctx - The DPIO notification context structure
93  * @cb:           The callback to be invoked when the notification arrives
94  * @is_cdan:      Zero for FQDAN, non-zero for CDAN
95  * @id:           FQID or channel ID, needed for rearm
96  * @desired_cpu:  The cpu on which the notifications will show up. Use
97  *                DPAA2_IO_ANY_CPU if don't care
98  * @dpio_id:      The dpio index
99  * @qman64:       The 64-bit context value shows up in the FQDAN/CDAN.
100  * @node:         The list node
101  * @dpio_private: The dpio object internal to dpio_service
102  *
103  * Used when a FQDAN/CDAN registration is made by drivers.
104  */
105 struct dpaa2_io_notification_ctx {
106         void (*cb)(struct dpaa2_io_notification_ctx *);
107         int is_cdan;
108         u32 id;
109         int desired_cpu;
110         int dpio_id;
111         u64 qman64;
112         struct list_head node;
113         void *dpio_private;
114 };
115
116 int dpaa2_io_service_register(struct dpaa2_io *service,
117                               struct dpaa2_io_notification_ctx *ctx);
118 void dpaa2_io_service_deregister(struct dpaa2_io *service,
119                                  struct dpaa2_io_notification_ctx *ctx);
120 int dpaa2_io_service_rearm(struct dpaa2_io *service,
121                            struct dpaa2_io_notification_ctx *ctx);
122
123 int dpaa2_io_service_pull_fq(struct dpaa2_io *d, u32 fqid,
124                              struct dpaa2_io_store *s);
125 int dpaa2_io_service_pull_channel(struct dpaa2_io *d, u32 channelid,
126                                   struct dpaa2_io_store *s);
127
128 int dpaa2_io_service_enqueue_fq(struct dpaa2_io *d, u32 fqid,
129                                 const struct dpaa2_fd *fd);
130 int dpaa2_io_service_enqueue_qd(struct dpaa2_io *d, u32 qdid, u8 prio,
131                                 u16 qdbin, const struct dpaa2_fd *fd);
132 int dpaa2_io_service_release(struct dpaa2_io *d, u32 bpid,
133                              const u64 *buffers, unsigned int num_buffers);
134 int dpaa2_io_service_acquire(struct dpaa2_io *d, u32 bpid,
135                              u64 *buffers, unsigned int num_buffers);
136
137 struct dpaa2_io_store *dpaa2_io_store_create(unsigned int max_frames,
138                                              struct device *dev);
139 void dpaa2_io_store_destroy(struct dpaa2_io_store *s);
140 struct dpaa2_dq *dpaa2_io_store_next(struct dpaa2_io_store *s, int *is_last);
141
142 #endif /* __FSL_DPAA2_IO_H */