New upstream version 18.11-rc1
[deb_dpdk.git] / drivers / bus / fslmc / mc / fsl_dpci.h
1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
2  *
3  * Copyright 2013-2016 Freescale Semiconductor Inc.
4  *
5  */
6 #ifndef __FSL_DPCI_H
7 #define __FSL_DPCI_H
8
9 #include <fsl_dpopr.h>
10
11 /* Data Path Communication Interface API
12  * Contains initialization APIs and runtime control APIs for DPCI
13  */
14
15 struct fsl_mc_io;
16
17 /** General DPCI macros */
18
19 /**
20  * Maximum number of Tx/Rx priorities per DPCI object
21  */
22 #define DPCI_PRIO_NUM           4
23
24 /**
25  * Indicates an invalid frame queue
26  */
27 #define DPCI_FQID_NOT_VALID     (uint32_t)(-1)
28
29 /**
30  * All queues considered; see dpci_set_rx_queue()
31  */
32 #define DPCI_ALL_QUEUES         (uint8_t)(-1)
33
34 int dpci_open(struct fsl_mc_io *mc_io,
35               uint32_t cmd_flags,
36               int dpci_id,
37               uint16_t *token);
38
39 int dpci_close(struct fsl_mc_io *mc_io,
40                uint32_t cmd_flags,
41                uint16_t token);
42
43 /**
44  * Enable the Order Restoration support
45  */
46 #define DPCI_OPT_HAS_OPR                                        0x000040
47
48 /**
49  * Order Point Records are shared for the entire DPCI
50  */
51 #define DPCI_OPT_OPR_SHARED                                     0x000080
52
53 /**
54  * struct dpci_cfg - Structure representing DPCI configuration
55  * @options: Any combination of the following options:
56  *              DPCI_OPT_HAS_OPR
57  *              DPCI_OPT_OPR_SHARED
58  * @num_of_priorities:  Number of receive priorities (queues) for the DPCI;
59  *                      note, that the number of transmit priorities (queues)
60  *                      is determined by the number of receive priorities of
61  *                      the peer DPCI object
62  */
63 struct dpci_cfg {
64         uint32_t options;
65         uint8_t num_of_priorities;
66 };
67
68 int dpci_create(struct fsl_mc_io *mc_io,
69                 uint16_t dprc_token,
70                 uint32_t cmd_flags,
71                 const struct dpci_cfg *cfg,
72                 uint32_t *obj_id);
73
74 int dpci_destroy(struct fsl_mc_io *mc_io,
75                  uint16_t dprc_token,
76                  uint32_t cmd_flags,
77                  uint32_t object_id);
78
79 int dpci_enable(struct fsl_mc_io *mc_io,
80                 uint32_t cmd_flags,
81                 uint16_t token);
82
83 int dpci_disable(struct fsl_mc_io *mc_io,
84                  uint32_t cmd_flags,
85                  uint16_t token);
86
87 int dpci_is_enabled(struct fsl_mc_io *mc_io,
88                     uint32_t cmd_flags,
89                     uint16_t token,
90                     int *en);
91
92 int dpci_reset(struct fsl_mc_io *mc_io,
93                uint32_t cmd_flags,
94                uint16_t token);
95
96 /**
97  * struct dpci_attr - Structure representing DPCI attributes
98  * @id:                 DPCI object ID
99  * @num_of_priorities:  Number of receive priorities
100  */
101 struct dpci_attr {
102         int id;
103         uint8_t num_of_priorities;
104 };
105
106 int dpci_get_attributes(struct fsl_mc_io *mc_io,
107                         uint32_t cmd_flags,
108                         uint16_t token,
109                         struct dpci_attr *attr);
110
111 /**
112  * struct dpci_peer_attr - Structure representing the peer DPCI attributes
113  * @peer_id:            DPCI peer id; if no peer is connected returns (-1)
114  * @num_of_priorities:  The pper's number of receive priorities; determines the
115  *                      number of transmit priorities for the local DPCI object
116  */
117 struct dpci_peer_attr {
118         int peer_id;
119         uint8_t num_of_priorities;
120 };
121
122 int dpci_get_peer_attributes(struct fsl_mc_io *mc_io,
123                              uint32_t cmd_flags,
124                              uint16_t token,
125                              struct dpci_peer_attr *attr);
126
127 int dpci_get_link_state(struct fsl_mc_io *mc_io,
128                         uint32_t cmd_flags,
129                         uint16_t token,
130                         int *up);
131
132 /**
133  * enum dpci_dest - DPCI destination types
134  * @DPCI_DEST_NONE:     Unassigned destination; The queue is set in parked mode
135  *                      and does not generate FQDAN notifications; user is
136  *                      expected to dequeue from the queue based on polling or
137  *                      other user-defined method
138  * @DPCI_DEST_DPIO:     The queue is set in schedule mode and generates FQDAN
139  *                      notifications to the specified DPIO; user is expected
140  *                      to dequeue from the queue only after notification is
141  *                      received
142  * @DPCI_DEST_DPCON:    The queue is set in schedule mode and does not generate
143  *                      FQDAN notifications, but is connected to the specified
144  *                      DPCON object;
145  *                      user is expected to dequeue from the DPCON channel
146  */
147 enum dpci_dest {
148         DPCI_DEST_NONE = 0,
149         DPCI_DEST_DPIO = 1,
150         DPCI_DEST_DPCON = 2
151 };
152
153 /**
154  * struct dpci_dest_cfg - Structure representing DPCI destination configuration
155  * @dest_type:  Destination type
156  * @dest_id:    Either DPIO ID or DPCON ID, depending on the destination type
157  * @priority:   Priority selection within the DPIO or DPCON channel; valid
158  *              values are 0-1 or 0-7, depending on the number of priorities
159  *              in that channel; not relevant for 'DPCI_DEST_NONE' option
160  */
161 struct dpci_dest_cfg {
162         enum dpci_dest dest_type;
163         int dest_id;
164         uint8_t priority;
165 };
166
167 /** DPCI queue modification options */
168
169 /**
170  * Select to modify the user's context associated with the queue
171  */
172 #define DPCI_QUEUE_OPT_USER_CTX         0x00000001
173
174 /**
175  * Select to modify the queue's destination
176  */
177 #define DPCI_QUEUE_OPT_DEST             0x00000002
178
179 /**
180  * Set the queue to hold active mode.
181  */
182 #define DPCI_QUEUE_OPT_HOLD_ACTIVE      0x00000004
183
184 /**
185  * struct dpci_rx_queue_cfg - Structure representing RX queue configuration
186  * @options:    Flags representing the suggested modifications to the queue;
187  *              Use any combination of 'DPCI_QUEUE_OPT_<X>' flags
188  * @user_ctx:   User context value provided in the frame descriptor of each
189  *              dequeued frame;
190  *              valid only if 'DPCI_QUEUE_OPT_USER_CTX' is contained in
191  *              'options'
192  * @dest_cfg:   Queue destination parameters;
193  *              valid only if 'DPCI_QUEUE_OPT_DEST' is contained in 'options'
194  * @order_preservation_en: order preservation configuration for the rx queue
195  * valid only if 'DPCI_QUEUE_OPT_HOLD_ACTIVE' is contained in 'options'
196  */
197 struct dpci_rx_queue_cfg {
198         uint32_t options;
199         uint64_t user_ctx;
200         struct dpci_dest_cfg dest_cfg;
201         int order_preservation_en;
202 };
203
204 int dpci_set_rx_queue(struct fsl_mc_io *mc_io,
205                       uint32_t cmd_flags,
206                       uint16_t token,
207                       uint8_t priority,
208                       const struct dpci_rx_queue_cfg *cfg);
209
210 /**
211  * struct dpci_rx_queue_attr - Structure representing Rx queue attributes
212  * @user_ctx:   User context value provided in the frame descriptor of each
213  *              dequeued frame
214  * @dest_cfg:   Queue destination configuration
215  * @fqid:       Virtual FQID value to be used for dequeue operations
216  */
217 struct dpci_rx_queue_attr {
218         uint64_t user_ctx;
219         struct dpci_dest_cfg dest_cfg;
220         uint32_t fqid;
221 };
222
223 int dpci_get_rx_queue(struct fsl_mc_io *mc_io,
224                       uint32_t cmd_flags,
225                       uint16_t token,
226                       uint8_t priority,
227                       struct dpci_rx_queue_attr *attr);
228
229 /**
230  * struct dpci_tx_queue_attr - Structure representing attributes of Tx queues
231  * @fqid:       Virtual FQID to be used for sending frames to peer DPCI;
232  *              returns 'DPCI_FQID_NOT_VALID' if a no peer is connected or if
233  *              the selected priority exceeds the number of priorities of the
234  *              peer DPCI object
235  */
236 struct dpci_tx_queue_attr {
237         uint32_t fqid;
238 };
239
240 int dpci_get_tx_queue(struct fsl_mc_io *mc_io,
241                       uint32_t cmd_flags,
242                       uint16_t token,
243                       uint8_t priority,
244                       struct dpci_tx_queue_attr *attr);
245
246 int dpci_get_api_version(struct fsl_mc_io *mc_io,
247                          uint32_t cmd_flags,
248                          uint16_t *major_ver,
249                          uint16_t *minor_ver);
250
251 int dpci_set_opr(struct fsl_mc_io *mc_io,
252                  uint32_t cmd_flags,
253                  uint16_t token,
254                  uint8_t index,
255                  uint8_t options,
256                  struct opr_cfg *cfg);
257
258 int dpci_get_opr(struct fsl_mc_io *mc_io,
259                  uint32_t cmd_flags,
260                  uint16_t token,
261                  uint8_t index,
262                  struct opr_cfg *cfg,
263                  struct opr_qry *qry);
264
265 #endif /* __FSL_DPCI_H */