New upstream version 17.11-rc3
[deb_dpdk.git] / drivers / bus / fslmc / mc / fsl_dpci.h
1 /*-
2  * This file is provided under a dual BSD/GPLv2 license. When using or
3  * redistributing this file, you may do so under either license.
4  *
5  *   BSD LICENSE
6  *
7  * Copyright 2013-2016 Freescale Semiconductor Inc.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  * * Neither the name of the above-listed copyright holders nor the
17  * names of any contributors may be used to endorse or promote products
18  * derived from this software without specific prior written permission.
19  *
20  *   GPL LICENSE SUMMARY
21  *
22  * ALTERNATIVELY, this software may be distributed under the terms of the
23  * GNU General Public License ("GPL") as published by the Free Software
24  * Foundation, either version 2 of that License or (at your option) any
25  * later version.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
31  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGE.
38  */
39 #ifndef __FSL_DPCI_H
40 #define __FSL_DPCI_H
41
42 /* Data Path Communication Interface API
43  * Contains initialization APIs and runtime control APIs for DPCI
44  */
45
46 struct fsl_mc_io;
47
48 /** General DPCI macros */
49
50 /**
51  * Maximum number of Tx/Rx priorities per DPCI object
52  */
53 #define DPCI_PRIO_NUM           2
54
55 /**
56  * Indicates an invalid frame queue
57  */
58 #define DPCI_FQID_NOT_VALID     (uint32_t)(-1)
59
60 /**
61  * All queues considered; see dpci_set_rx_queue()
62  */
63 #define DPCI_ALL_QUEUES         (uint8_t)(-1)
64
65 int dpci_open(struct fsl_mc_io *mc_io,
66               uint32_t cmd_flags,
67               int dpci_id,
68               uint16_t *token);
69
70 int dpci_close(struct fsl_mc_io *mc_io,
71                uint32_t cmd_flags,
72                uint16_t token);
73
74 /**
75  * Enable the Order Restoration support
76  */
77 #define DPCI_OPT_HAS_OPR                                        0x000040
78
79 /**
80  * Order Point Records are shared for the entire DPCI
81  */
82 #define DPCI_OPT_OPR_SHARED                                     0x000080
83
84 /**
85  * struct dpci_cfg - Structure representing DPCI configuration
86  * @options: Any combination of the following options:
87  *              DPCI_OPT_HAS_OPR
88  *              DPCI_OPT_OPR_SHARED
89  * @num_of_priorities:  Number of receive priorities (queues) for the DPCI;
90  *                      note, that the number of transmit priorities (queues)
91  *                      is determined by the number of receive priorities of
92  *                      the peer DPCI object
93  */
94 struct dpci_cfg {
95         uint32_t options;
96         uint8_t num_of_priorities;
97 };
98
99 int dpci_create(struct fsl_mc_io *mc_io,
100                 uint16_t dprc_token,
101                 uint32_t cmd_flags,
102                 const struct dpci_cfg *cfg,
103                 uint32_t *obj_id);
104
105 int dpci_destroy(struct fsl_mc_io *mc_io,
106                  uint16_t dprc_token,
107                  uint32_t cmd_flags,
108                  uint32_t object_id);
109
110 int dpci_enable(struct fsl_mc_io *mc_io,
111                 uint32_t cmd_flags,
112                 uint16_t token);
113
114 int dpci_disable(struct fsl_mc_io *mc_io,
115                  uint32_t cmd_flags,
116                  uint16_t token);
117
118 int dpci_is_enabled(struct fsl_mc_io *mc_io,
119                     uint32_t cmd_flags,
120                     uint16_t token,
121                     int *en);
122
123 int dpci_reset(struct fsl_mc_io *mc_io,
124                uint32_t cmd_flags,
125                uint16_t token);
126
127 /**
128  * struct dpci_attr - Structure representing DPCI attributes
129  * @id:                 DPCI object ID
130  * @num_of_priorities:  Number of receive priorities
131  */
132 struct dpci_attr {
133         int id;
134         uint8_t num_of_priorities;
135 };
136
137 int dpci_get_attributes(struct fsl_mc_io *mc_io,
138                         uint32_t cmd_flags,
139                         uint16_t token,
140                         struct dpci_attr *attr);
141
142 /**
143  * enum dpci_dest - DPCI destination types
144  * @DPCI_DEST_NONE:     Unassigned destination; The queue is set in parked mode
145  *                      and does not generate FQDAN notifications; user is
146  *                      expected to dequeue from the queue based on polling or
147  *                      other user-defined method
148  * @DPCI_DEST_DPIO:     The queue is set in schedule mode and generates FQDAN
149  *                      notifications to the specified DPIO; user is expected
150  *                      to dequeue from the queue only after notification is
151  *                      received
152  * @DPCI_DEST_DPCON:    The queue is set in schedule mode and does not generate
153  *                      FQDAN notifications, but is connected to the specified
154  *                      DPCON object;
155  *                      user is expected to dequeue from the DPCON channel
156  */
157 enum dpci_dest {
158         DPCI_DEST_NONE = 0,
159         DPCI_DEST_DPIO = 1,
160         DPCI_DEST_DPCON = 2
161 };
162
163 /**
164  * struct dpci_dest_cfg - Structure representing DPCI destination configuration
165  * @dest_type:  Destination type
166  * @dest_id:    Either DPIO ID or DPCON ID, depending on the destination type
167  * @priority:   Priority selection within the DPIO or DPCON channel; valid
168  *              values are 0-1 or 0-7, depending on the number of priorities
169  *              in that channel; not relevant for 'DPCI_DEST_NONE' option
170  */
171 struct dpci_dest_cfg {
172         enum dpci_dest dest_type;
173         int dest_id;
174         uint8_t priority;
175 };
176
177 /** DPCI queue modification options */
178
179 /**
180  * Select to modify the user's context associated with the queue
181  */
182 #define DPCI_QUEUE_OPT_USER_CTX         0x00000001
183
184 /**
185  * Select to modify the queue's destination
186  */
187 #define DPCI_QUEUE_OPT_DEST             0x00000002
188
189 /**
190  * struct dpci_rx_queue_cfg - Structure representing RX queue configuration
191  * @options:    Flags representing the suggested modifications to the queue;
192  *              Use any combination of 'DPCI_QUEUE_OPT_<X>' flags
193  * @user_ctx:   User context value provided in the frame descriptor of each
194  *              dequeued frame;
195  *              valid only if 'DPCI_QUEUE_OPT_USER_CTX' is contained in
196  *              'options'
197  * @dest_cfg:   Queue destination parameters;
198  *              valid only if 'DPCI_QUEUE_OPT_DEST' is contained in 'options'
199  */
200 struct dpci_rx_queue_cfg {
201         uint32_t options;
202         uint64_t user_ctx;
203         struct dpci_dest_cfg dest_cfg;
204 };
205
206 int dpci_set_rx_queue(struct fsl_mc_io *mc_io,
207                       uint32_t cmd_flags,
208                       uint16_t token,
209                       uint8_t priority,
210                       const struct dpci_rx_queue_cfg *cfg);
211
212 /**
213  * struct dpci_rx_queue_attr - Structure representing Rx queue attributes
214  * @user_ctx:   User context value provided in the frame descriptor of each
215  *              dequeued frame
216  * @dest_cfg:   Queue destination configuration
217  * @fqid:       Virtual FQID value to be used for dequeue operations
218  */
219 struct dpci_rx_queue_attr {
220         uint64_t user_ctx;
221         struct dpci_dest_cfg dest_cfg;
222         uint32_t fqid;
223 };
224
225 int dpci_get_rx_queue(struct fsl_mc_io *mc_io,
226                       uint32_t cmd_flags,
227                       uint16_t token,
228                       uint8_t priority,
229                       struct dpci_rx_queue_attr *attr);
230
231 /**
232  * struct dpci_tx_queue_attr - Structure representing attributes of Tx queues
233  * @fqid:       Virtual FQID to be used for sending frames to peer DPCI;
234  *              returns 'DPCI_FQID_NOT_VALID' if a no peer is connected or if
235  *              the selected priority exceeds the number of priorities of the
236  *              peer DPCI object
237  */
238 struct dpci_tx_queue_attr {
239         uint32_t fqid;
240 };
241
242 int dpci_get_tx_queue(struct fsl_mc_io *mc_io,
243                       uint32_t cmd_flags,
244                       uint16_t token,
245                       uint8_t priority,
246                       struct dpci_tx_queue_attr *attr);
247
248 int dpci_get_api_version(struct fsl_mc_io *mc_io,
249                          uint32_t cmd_flags,
250                          uint16_t *major_ver,
251                          uint16_t *minor_ver);
252
253 #endif /* __FSL_DPCI_H */