]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/contrib/octeon-sdk/cvmx-helper-util.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / contrib / octeon-sdk / cvmx-helper-util.h
1 /***********************license start***************
2  * Copyright (c) 2003-2010  Cavium Inc. (support@cavium.com). All rights
3  * reserved.
4  *
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  *   * Redistributions of source code must retain the above copyright
11  *     notice, this list of conditions and the following disclaimer.
12  *
13  *   * Redistributions in binary form must reproduce the above
14  *     copyright notice, this list of conditions and the following
15  *     disclaimer in the documentation and/or other materials provided
16  *     with the distribution.
17
18  *   * Neither the name of Cavium Inc. nor the names of
19  *     its contributors may be used to endorse or promote products
20  *     derived from this software without specific prior written
21  *     permission.
22
23  * This Software, including technical data, may be subject to U.S. export  control
24  * laws, including the U.S. Export Administration Act and its  associated
25  * regulations, and may be subject to export or import  regulations in other
26  * countries.
27
28  * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29  * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
30  * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31  * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32  * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33  * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34  * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35  * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36  * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR
37  * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38  ***********************license end**************************************/
39
40
41
42
43
44
45
46 /**
47  * @file
48  *
49  * Small helper utilities.
50  *
51  * <hr>$Revision: 70030 $<hr>
52  */
53
54 #ifndef __CVMX_HELPER_UTIL_H__
55 #define __CVMX_HELPER_UTIL_H__
56
57 #include "cvmx.h"
58 #include "cvmx-mio-defs.h"
59
60 #ifdef CVMX_ENABLE_HELPER_FUNCTIONS
61
62 typedef char cvmx_pknd_t;
63 typedef char cvmx_bpid_t;
64
65 #define CVMX_INVALID_PKND       ((cvmx_pknd_t) -1)
66 #define CVMX_INVALID_BPID       ((cvmx_bpid_t) -1)
67 #define CVMX_MAX_PKND           ((cvmx_pknd_t) 64)
68 #define CVMX_MAX_BPID           ((cvmx_bpid_t) 64)
69
70 #define CVMX_HELPER_MAX_IFACE           9
71
72 /**
73  * Convert a interface mode into a human readable string
74  *
75  * @param mode   Mode to convert
76  *
77  * @return String
78  */
79 extern const char *cvmx_helper_interface_mode_to_string(cvmx_helper_interface_mode_t mode);
80
81 /**
82  * Debug routine to dump the packet structure to the console
83  *
84  * @param work   Work queue entry containing the packet to dump
85  * @return
86  */
87 extern int cvmx_helper_dump_packet(cvmx_wqe_t *work);
88
89 /**
90  * Setup Random Early Drop on a specific input queue
91  *
92  * @param queue  Input queue to setup RED on (0-7)
93  * @param pass_thresh
94  *               Packets will begin slowly dropping when there are less than
95  *               this many packet buffers free in FPA 0.
96  * @param drop_thresh
97  *               All incomming packets will be dropped when there are less
98  *               than this many free packet buffers in FPA 0.
99  * @return Zero on success. Negative on failure
100  */
101 extern int cvmx_helper_setup_red_queue(int queue, int pass_thresh, int drop_thresh);
102
103 /**
104  * Setup Random Early Drop to automatically begin dropping packets.
105  *
106  * @param pass_thresh
107  *               Packets will begin slowly dropping when there are less than
108  *               this many packet buffers free in FPA 0.
109  * @param drop_thresh
110  *               All incomming packets will be dropped when there are less
111  *               than this many free packet buffers in FPA 0.
112  * @return Zero on success. Negative on failure
113  */
114 extern int cvmx_helper_setup_red(int pass_thresh, int drop_thresh);
115
116
117 /**
118  * Get the version of the CVMX libraries.
119  *
120  * @return Version string. Note this buffer is allocated statically
121  *         and will be shared by all callers.
122  */
123 extern const char *cvmx_helper_get_version(void);
124
125
126 /**
127  * @INTERNAL
128  * Setup the common GMX settings that determine the number of
129  * ports. These setting apply to almost all configurations of all
130  * chips.
131  *
132  * @param interface Interface to configure
133  * @param num_ports Number of ports on the interface
134  *
135  * @return Zero on success, negative on failure
136  */
137 extern int __cvmx_helper_setup_gmx(int interface, int num_ports);
138
139 /**
140  * @INTERNAL
141  * Get the number of ipd_ports on an interface.
142  *
143  * @param interface
144  *
145  * @return the number of ipd_ports on the interface and -1 for error.
146  */
147 extern int __cvmx_helper_get_num_ipd_ports(int interface);
148
149 /**
150  * @INTERNAL
151  * Get the number of pko_ports on an interface.
152  *
153  * @param interface
154  *
155  * @return the number of pko_ports on the interface.
156  */
157 extern int __cvmx_helper_get_num_pko_ports(int interface);
158
159 /*
160  * @INTERNAL
161  *
162  * @param interface
163  * @param port
164  * @param link_info
165  *
166  * @return 0 for success and -1 for failure
167  */
168 extern int __cvmx_helper_set_link_info(int interface, int port,
169     cvmx_helper_link_info_t link_info);
170
171 /**
172  * @INTERNAL
173  *
174  * @param interface
175  * @param port
176  *
177  * @return valid link_info on success or -1 on failure
178  */
179 extern cvmx_helper_link_info_t __cvmx_helper_get_link_info(int interface,
180     int port);
181
182 enum cvmx_pko_padding {
183         CVMX_PKO_PADDING_NONE = 0,
184         CVMX_PKO_PADDING_60 = 1,
185 };
186
187 /**
188  * @INTERNAL
189  *
190  * @param interface
191  * @param num_ipd_ports is the number of ipd_ports on the interface
192  * @param has_fcs indicates if PKO does FCS for the ports on this
193  * @param pad The padding that PKO should apply.
194  * interface.
195  *
196  * @return 0 for success and -1 for failure
197  */
198 extern int __cvmx_helper_init_interface(int interface, int num_ipd_ports, int has_fcs, enum cvmx_pko_padding pad);
199
200 /**
201  * @INTERNAL
202  *
203  * @param interface
204  *
205  * @return 0 if PKO does not do FCS and 1 otherwise.
206  */
207 extern int __cvmx_helper_get_has_fcs(int interface);
208
209
210 extern enum cvmx_pko_padding __cvmx_helper_get_pko_padding(int interface);
211
212 /**
213  * Returns the IPD port number for a port on the given
214  * interface.
215  *
216  * @param interface Interface to use
217  * @param port      Port on the interface
218  *
219  * @return IPD port number
220  */
221 extern int cvmx_helper_get_ipd_port(int interface, int port);
222
223 /**
224  * Returns the PKO port number for a port on the given interface,
225  * This is the base pko_port for o68 and ipd_port for older models.
226  *
227  * @param interface Interface to use
228  * @param port      Port on the interface
229  *
230  * @return PKO port number and -1 on error.
231  */
232 extern int cvmx_helper_get_pko_port(int interface, int port);
233
234 /**
235  * Returns the IPD/PKO port number for the first port on the given
236  * interface.
237  *
238  * @param interface Interface to use
239  *
240  * @return IPD/PKO port number
241  */
242 static inline int cvmx_helper_get_first_ipd_port(int interface)
243 {
244     return (cvmx_helper_get_ipd_port (interface, 0));
245 }
246
247 /**
248  * Returns the IPD/PKO port number for the last port on the given
249  * interface.
250  *
251  * @param interface Interface to use
252  *
253  * @return IPD/PKO port number
254  */
255 static inline int cvmx_helper_get_last_ipd_port (int interface)
256 {
257     return (cvmx_helper_get_first_ipd_port (interface) +
258             cvmx_helper_ports_on_interface (interface) - 1);
259 }
260
261
262 /**
263  * Free the packet buffers contained in a work queue entry.
264  * The work queue entry is not freed.
265  *
266  * @param work   Work queue entry with packet to free
267  */
268 static inline void cvmx_helper_free_packet_data(cvmx_wqe_t *work)
269 {
270     uint64_t        number_buffers;
271     cvmx_buf_ptr_t  buffer_ptr;
272     cvmx_buf_ptr_t  next_buffer_ptr;
273     uint64_t        start_of_buffer;
274
275     number_buffers = work->word2.s.bufs;
276     if (number_buffers == 0)
277         return;
278     buffer_ptr = work->packet_ptr;
279
280     /* Since the number of buffers is not zero, we know this is not a dynamic
281         short packet. We need to check if it is a packet received with
282         IPD_CTL_STATUS[NO_WPTR]. If this is true, we need to free all buffers
283         except for the first one. The caller doesn't expect their WQE pointer
284         to be freed */
285     start_of_buffer = ((buffer_ptr.s.addr >> 7) - buffer_ptr.s.back) << 7;
286     if (cvmx_ptr_to_phys(work) == start_of_buffer)
287     {
288         next_buffer_ptr = *(cvmx_buf_ptr_t*)cvmx_phys_to_ptr(buffer_ptr.s.addr - 8);
289         buffer_ptr = next_buffer_ptr;
290         number_buffers--;
291     }
292
293     while (number_buffers--)
294     {
295         /* Remember the back pointer is in cache lines, not 64bit words */
296         start_of_buffer = ((buffer_ptr.s.addr >> 7) - buffer_ptr.s.back) << 7;
297         /* Read pointer to next buffer before we free the current buffer. */
298         next_buffer_ptr = *(cvmx_buf_ptr_t*)cvmx_phys_to_ptr(buffer_ptr.s.addr - 8);
299         cvmx_fpa_free(cvmx_phys_to_ptr(start_of_buffer), buffer_ptr.s.pool, 0);
300         buffer_ptr = next_buffer_ptr;
301     }
302 }
303
304 #endif /* CVMX_ENABLE_HELPER_FUNCTIONS */
305
306 /**
307  * Returns the interface number for an IPD/PKO port number.
308  *
309  * @param ipd_port IPD/PKO port number
310  *
311  * @return Interface number
312  */
313 extern int cvmx_helper_get_interface_num(int ipd_port);
314
315 /**
316  * Returns the interface index number for an IPD/PKO port
317  * number.
318  *
319  * @param ipd_port IPD/PKO port number
320  *
321  * @return Interface index number
322  */
323 extern int cvmx_helper_get_interface_index_num(int ipd_port);
324
325 /**
326  * Get port kind for a given port in an interface.
327  *
328  * @param interface  Interface
329  * @param port       index of the port in the interface
330  *
331  * @return port kind on sucicess  and -1 on failure
332  */
333 extern int cvmx_helper_get_pknd(int interface, int port);
334
335 /**
336  * Get bpid for a given port in an interface.
337  *
338  * @param interface  Interface
339  * @param port       index of the port in the interface
340  *
341  * @return port kind on sucicess  and -1 on failure
342  */
343 extern int cvmx_helper_get_bpid(int interface, int port);
344
345
346 /**
347  * Internal functions.
348  */
349 extern int __cvmx_helper_post_init_interfaces(void);
350 extern void __cvmx_helper_shutdown_interfaces(void);
351
352 extern void cvmx_helper_show_stats(int port);
353
354 #endif  /* __CVMX_HELPER_H__ */