1e155dd73f290343b72106c2458aa3eab31b973f
[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 /**
66  * dpci_open() - Open a control session for the specified object
67  * @mc_io:      Pointer to MC portal's I/O object
68  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
69  * @dpci_id:    DPCI unique ID
70  * @token:      Returned token; use in subsequent API calls
71  *
72  * This function can be used to open a control session for an
73  * already created object; an object may have been declared in
74  * the DPL or by calling the dpci_create() function.
75  * This function returns a unique authentication token,
76  * associated with the specific object ID and the specific MC
77  * portal; this token must be used in all subsequent commands for
78  * this specific object.
79  *
80  * Return:      '0' on Success; Error code otherwise.
81  */
82 int dpci_open(struct fsl_mc_io *mc_io,
83               uint32_t          cmd_flags,
84               int               dpci_id,
85               uint16_t          *token);
86
87 /**
88  * dpci_close() - Close the control session of the object
89  * @mc_io:      Pointer to MC portal's I/O object
90  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
91  * @token:      Token of DPCI object
92  *
93  * After this function is called, no further operations are
94  * allowed on the object without opening a new control session.
95  *
96  * Return:      '0' on Success; Error code otherwise.
97  */
98 int dpci_close(struct fsl_mc_io *mc_io,
99                uint32_t         cmd_flags,
100                uint16_t         token);
101
102 /**
103  * Enable the Order Restoration support
104  */
105 #define DPCI_OPT_HAS_OPR                                        0x000040
106
107 /**
108  * Order Point Records are shared for the entire DPCI
109  */
110 #define DPCI_OPT_OPR_SHARED                                     0x000080
111
112 /**
113  * struct dpci_cfg - Structure representing DPCI configuration
114  * @options: Any combination of the following options:
115  *              DPCI_OPT_HAS_OPR
116  *              DPCI_OPT_OPR_SHARED
117  * @num_of_priorities:  Number of receive priorities (queues) for the DPCI;
118  *                      note, that the number of transmit priorities (queues)
119  *                      is determined by the number of receive priorities of
120  *                      the peer DPCI object
121  */
122 struct dpci_cfg {
123         uint32_t options;
124         uint8_t num_of_priorities;
125 };
126
127 /**
128  * dpci_create() - Create the DPCI object.
129  * @mc_io:      Pointer to MC portal's I/O object
130  * @dprc_token: Parent container token; '0' for default container
131  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
132  * @cfg:        Configuration structure
133  * @obj_id: returned object id
134  *
135  * Create the DPCI object, allocate required resources and perform required
136  * initialization.
137  *
138  * The object can be created either by declaring it in the
139  * DPL file, or by calling this function.
140  *
141  * The function accepts an authentication token of a parent
142  * container that this object should be assigned to. The token
143  * can be '0' so the object will be assigned to the default container.
144  * The newly created object can be opened with the returned
145  * object id and using the container's associated tokens and MC portals.
146  *
147  * Return:      '0' on Success; Error code otherwise.
148  */
149 int dpci_create(struct fsl_mc_io        *mc_io,
150                 uint16_t                dprc_token,
151                 uint32_t                cmd_flags,
152                 const struct dpci_cfg   *cfg,
153                 uint32_t                *obj_id);
154
155 /**
156  * dpci_destroy() - Destroy the DPCI object and release all its resources.
157  * @mc_io:      Pointer to MC portal's I/O object
158  * @dprc_token: Parent container token; '0' for default container
159  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
160  * @object_id:  The object id; it must be a valid id within the container that
161  * created this object;
162  *
163  * The function accepts the authentication token of the parent container that
164  * created the object (not the one that currently owns the object). The object
165  * is searched within parent using the provided 'object_id'.
166  * All tokens to the object must be closed before calling destroy.
167  *
168  * Return:      '0' on Success; error code otherwise.
169  */
170 int dpci_destroy(struct fsl_mc_io       *mc_io,
171                  uint16_t               dprc_token,
172                 uint32_t                cmd_flags,
173                 uint32_t                object_id);
174
175 /**
176  * dpci_enable() - Enable the DPCI, allow sending and receiving frames.
177  * @mc_io:      Pointer to MC portal's I/O object
178  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
179  * @token:      Token of DPCI object
180  *
181  * Return:      '0' on Success; Error code otherwise.
182  */
183 int dpci_enable(struct fsl_mc_io        *mc_io,
184                 uint32_t                cmd_flags,
185                 uint16_t                token);
186
187 /**
188  * dpci_disable() - Disable the DPCI, stop sending and receiving frames.
189  * @mc_io:      Pointer to MC portal's I/O object
190  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
191  * @token:      Token of DPCI object
192  *
193  * Return:      '0' on Success; Error code otherwise.
194  */
195 int dpci_disable(struct fsl_mc_io       *mc_io,
196                  uint32_t               cmd_flags,
197                  uint16_t               token);
198
199 /**
200  * dpci_is_enabled() - Check if the DPCI is enabled.
201  * @mc_io:      Pointer to MC portal's I/O object
202  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
203  * @token:      Token of DPCI object
204  * @en:         Returns '1' if object is enabled; '0' otherwise
205  *
206  * Return:      '0' on Success; Error code otherwise.
207  */
208 int dpci_is_enabled(struct fsl_mc_io    *mc_io,
209                     uint32_t            cmd_flags,
210                     uint16_t            token,
211                     int                 *en);
212
213 /**
214  * dpci_reset() - Reset the DPCI, returns the object to initial state.
215  * @mc_io:      Pointer to MC portal's I/O object
216  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
217  * @token:      Token of DPCI object
218  *
219  * Return:      '0' on Success; Error code otherwise.
220  */
221 int dpci_reset(struct fsl_mc_io *mc_io,
222                uint32_t cmd_flags,
223                uint16_t token);
224
225 /**
226  * struct dpci_attr - Structure representing DPCI attributes
227  * @id:         DPCI object ID
228  * @num_of_priorities:  Number of receive priorities
229  */
230 struct dpci_attr {
231         int id;
232         uint8_t num_of_priorities;
233 };
234
235 /**
236  * dpci_get_attributes() - Retrieve DPCI attributes.
237  * @mc_io:      Pointer to MC portal's I/O object
238  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
239  * @token:      Token of DPCI object
240  * @attr:       Returned object's attributes
241  *
242  * Return:      '0' on Success; Error code otherwise.
243  */
244 int dpci_get_attributes(struct fsl_mc_io        *mc_io,
245                         uint32_t                cmd_flags,
246                         uint16_t                token,
247                         struct dpci_attr        *attr);
248
249 /**
250  * enum dpci_dest - DPCI destination types
251  * @DPCI_DEST_NONE:     Unassigned destination; The queue is set in parked mode
252  *                      and does not generate FQDAN notifications; user is
253  *                      expected to dequeue from the queue based on polling or
254  *                      other user-defined method
255  * @DPCI_DEST_DPIO:     The queue is set in schedule mode and generates FQDAN
256  *                      notifications to the specified DPIO; user is expected
257  *                      to dequeue from the queue only after notification is
258  *                      received
259  * @DPCI_DEST_DPCON:    The queue is set in schedule mode and does not generate
260  *                      FQDAN notifications, but is connected to the specified
261  *                      DPCON object;
262  *                      user is expected to dequeue from the DPCON channel
263  */
264 enum dpci_dest {
265         DPCI_DEST_NONE = 0,
266         DPCI_DEST_DPIO = 1,
267         DPCI_DEST_DPCON = 2
268 };
269
270 /**
271  * struct dpci_dest_cfg - Structure representing DPCI destination configuration
272  * @dest_type:  Destination type
273  * @dest_id:    Either DPIO ID or DPCON ID, depending on the destination type
274  * @priority:   Priority selection within the DPIO or DPCON channel; valid
275  *              values are 0-1 or 0-7, depending on the number of priorities
276  *              in that channel; not relevant for 'DPCI_DEST_NONE' option
277  */
278 struct dpci_dest_cfg {
279         enum dpci_dest dest_type;
280         int dest_id;
281         uint8_t priority;
282 };
283
284 /** DPCI queue modification options */
285
286 /**
287  * Select to modify the user's context associated with the queue
288  */
289 #define DPCI_QUEUE_OPT_USER_CTX         0x00000001
290
291 /**
292  * Select to modify the queue's destination
293  */
294 #define DPCI_QUEUE_OPT_DEST             0x00000002
295
296 /**
297  * struct dpci_rx_queue_cfg - Structure representing RX queue configuration
298  * @options:    Flags representing the suggested modifications to the queue;
299  *              Use any combination of 'DPCI_QUEUE_OPT_<X>' flags
300  * @user_ctx:   User context value provided in the frame descriptor of each
301  *              dequeued frame;
302  *              valid only if 'DPCI_QUEUE_OPT_USER_CTX' is contained in
303  *              'options'
304  * @dest_cfg:   Queue destination parameters;
305  *              valid only if 'DPCI_QUEUE_OPT_DEST' is contained in 'options'
306  */
307 struct dpci_rx_queue_cfg {
308         uint32_t options;
309         uint64_t user_ctx;
310         struct dpci_dest_cfg dest_cfg;
311 };
312
313 /**
314  * dpci_set_rx_queue() - Set Rx queue configuration
315  * @mc_io:      Pointer to MC portal's I/O object
316  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
317  * @token:      Token of DPCI object
318  * @priority:   Select the queue relative to number of
319  *                      priorities configured at DPCI creation; use
320  *                      DPCI_ALL_QUEUES to configure all Rx queues
321  *                      identically.
322  * @cfg:        Rx queue configuration
323  *
324  * Return:      '0' on Success; Error code otherwise.
325  */
326 int dpci_set_rx_queue(struct fsl_mc_io                  *mc_io,
327                       uint32_t                          cmd_flags,
328                       uint16_t                          token,
329                       uint8_t                           priority,
330                       const struct dpci_rx_queue_cfg    *cfg);
331
332 /**
333  * struct dpci_rx_queue_attr - Structure representing Rx queue attributes
334  * @user_ctx:   User context value provided in the frame descriptor of each
335  *              dequeued frame
336  * @dest_cfg:   Queue destination configuration
337  * @fqid:       Virtual FQID value to be used for dequeue operations
338  */
339 struct dpci_rx_queue_attr {
340         uint64_t                user_ctx;
341         struct dpci_dest_cfg    dest_cfg;
342         uint32_t                fqid;
343 };
344
345 /**
346  * dpci_get_rx_queue() - Retrieve Rx queue attributes.
347  * @mc_io:      Pointer to MC portal's I/O object
348  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
349  * @token:              Token of DPCI object
350  * @priority:           Select the queue relative to number of
351  *                      priorities configured at DPCI creation
352  * @attr:               Returned Rx queue attributes
353  *
354  * Return:      '0' on Success; Error code otherwise.
355  */
356 int dpci_get_rx_queue(struct fsl_mc_io          *mc_io,
357                       uint32_t                  cmd_flags,
358                       uint16_t                  token,
359                       uint8_t                   priority,
360                       struct dpci_rx_queue_attr *attr);
361
362 /**
363  * struct dpci_tx_queue_attr - Structure representing attributes of Tx queues
364  * @fqid:       Virtual FQID to be used for sending frames to peer DPCI;
365  *              returns 'DPCI_FQID_NOT_VALID' if a no peer is connected or if
366  *              the selected priority exceeds the number of priorities of the
367  *              peer DPCI object
368  */
369 struct dpci_tx_queue_attr {
370         uint32_t fqid;
371 };
372
373 /**
374  * dpci_get_tx_queue() - Retrieve Tx queue attributes.
375  * @mc_io:      Pointer to MC portal's I/O object
376  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
377  * @token:      Token of DPCI object
378  * @priority:   Select the queue relative to number of
379  *                              priorities of the peer DPCI object
380  * @attr:               Returned Tx queue attributes
381  *
382  * Return:      '0' on Success; Error code otherwise.
383  */
384 int dpci_get_tx_queue(struct fsl_mc_io          *mc_io,
385                       uint32_t                  cmd_flags,
386                       uint16_t                  token,
387                       uint8_t                   priority,
388                       struct dpci_tx_queue_attr *attr);
389
390 /**
391  * dpci_get_api_version() - Get communication interface API version
392  * @mc_io:  Pointer to MC portal's I/O object
393  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
394  * @major_ver:  Major version of data path communication interface API
395  * @minor_ver:  Minor version of data path communication interface API
396  *
397  * Return:  '0' on Success; Error code otherwise.
398  */
399 int dpci_get_api_version(struct fsl_mc_io       *mc_io,
400                          uint32_t               cmd_flags,
401                          uint16_t               *major_ver,
402                          uint16_t               *minor_ver);
403
404 #endif /* __FSL_DPCI_H */