]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/contrib/octeon-sdk/cvmx-helper-util.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sys / contrib / octeon-sdk / cvmx-helper-util.h
1 /***********************license start***************
2  * Copyright (c) 2003-2010  Cavium Networks (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 Networks 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  NETWORKS 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: 49448 $<hr>
52  */
53
54 #ifndef __CVMX_HELPER_UTIL_H__
55 #define __CVMX_HELPER_UTIL_H__
56
57
58 #ifdef CVMX_ENABLE_HELPER_FUNCTIONS
59
60 /**
61  * Convert a interface mode into a human readable string
62  *
63  * @param mode   Mode to convert
64  *
65  * @return String
66  */
67 extern const char *cvmx_helper_interface_mode_to_string(cvmx_helper_interface_mode_t mode);
68
69 /**
70  * Debug routine to dump the packet structure to the console
71  *
72  * @param work   Work queue entry containing the packet to dump
73  * @return
74  */
75 extern int cvmx_helper_dump_packet(cvmx_wqe_t *work);
76
77 /**
78  * Setup Random Early Drop on a specific input queue
79  *
80  * @param queue  Input queue to setup RED on (0-7)
81  * @param pass_thresh
82  *               Packets will begin slowly dropping when there are less than
83  *               this many packet buffers free in FPA 0.
84  * @param drop_thresh
85  *               All incomming packets will be dropped when there are less
86  *               than this many free packet buffers in FPA 0.
87  * @return Zero on success. Negative on failure
88  */
89 extern int cvmx_helper_setup_red_queue(int queue, int pass_thresh, int drop_thresh);
90
91 /**
92  * Setup Random Early Drop to automatically begin dropping packets.
93  *
94  * @param pass_thresh
95  *               Packets will begin slowly dropping when there are less than
96  *               this many packet buffers free in FPA 0.
97  * @param drop_thresh
98  *               All incomming packets will be dropped when there are less
99  *               than this many free packet buffers in FPA 0.
100  * @return Zero on success. Negative on failure
101  */
102 extern int cvmx_helper_setup_red(int pass_thresh, int drop_thresh);
103
104
105 /**
106  * Get the version of the CVMX libraries.
107  *
108  * @return Version string. Note this buffer is allocated statically
109  *         and will be shared by all callers.
110  */
111 extern const char *cvmx_helper_get_version(void);
112
113
114 /**
115  * @INTERNAL
116  * Setup the common GMX settings that determine the number of
117  * ports. These setting apply to almost all configurations of all
118  * chips.
119  *
120  * @param interface Interface to configure
121  * @param num_ports Number of ports on the interface
122  *
123  * @return Zero on success, negative on failure
124  */
125 extern int __cvmx_helper_setup_gmx(int interface, int num_ports);
126
127 /**
128  * Returns the IPD/PKO port number for a port on the given
129  * interface.
130  *
131  * @param interface Interface to use
132  * @param port      Port on the interface
133  *
134  * @return IPD/PKO port number
135  */
136 extern int cvmx_helper_get_ipd_port(int interface, int port);
137
138
139 /**
140  * Returns the IPD/PKO port number for the first port on the given
141  * interface.
142  *
143  * @param interface Interface to use
144  *
145  * @return IPD/PKO port number
146  */
147 static inline int cvmx_helper_get_first_ipd_port(int interface)
148 {
149     return (cvmx_helper_get_ipd_port (interface, 0));
150 }
151
152 /**
153  * Returns the IPD/PKO port number for the last port on the given
154  * interface.
155  *
156  * @param interface Interface to use
157  *
158  * @return IPD/PKO port number
159  */
160 static inline int cvmx_helper_get_last_ipd_port (int interface)
161 {
162     return (cvmx_helper_get_first_ipd_port (interface) +
163             cvmx_helper_ports_on_interface (interface) - 1);
164 }
165
166
167 /**
168  * Free the packet buffers contained in a work queue entry.
169  * The work queue entry is not freed.
170  *
171  * @param work   Work queue entry with packet to free
172  */
173 static inline void cvmx_helper_free_packet_data(cvmx_wqe_t *work)
174 {
175     uint64_t        number_buffers;
176     cvmx_buf_ptr_t  buffer_ptr;
177     cvmx_buf_ptr_t  next_buffer_ptr;
178     uint64_t        start_of_buffer;
179
180     number_buffers = work->word2.s.bufs;
181     if (number_buffers == 0)
182         return;
183     buffer_ptr = work->packet_ptr;
184
185     /* Since the number of buffers is not zero, we know this is not a dynamic
186         short packet. We need to check if it is a packet received with
187         IPD_CTL_STATUS[NO_WPTR]. If this is true, we need to free all buffers
188         except for the first one. The caller doesn't expect their WQE pointer
189         to be freed */
190     start_of_buffer = ((buffer_ptr.s.addr >> 7) - buffer_ptr.s.back) << 7;
191     if (cvmx_ptr_to_phys(work) == start_of_buffer)
192     {
193         next_buffer_ptr = *(cvmx_buf_ptr_t*)cvmx_phys_to_ptr(buffer_ptr.s.addr - 8);
194         buffer_ptr = next_buffer_ptr;
195         number_buffers--;
196     }
197
198     while (number_buffers--)
199     {
200         /* Remember the back pointer is in cache lines, not 64bit words */
201         start_of_buffer = ((buffer_ptr.s.addr >> 7) - buffer_ptr.s.back) << 7;
202         /* Read pointer to next buffer before we free the current buffer. */
203         next_buffer_ptr = *(cvmx_buf_ptr_t*)cvmx_phys_to_ptr(buffer_ptr.s.addr - 8);
204         cvmx_fpa_free(cvmx_phys_to_ptr(start_of_buffer), buffer_ptr.s.pool, 0);
205         buffer_ptr = next_buffer_ptr;
206     }
207 }
208
209 #endif /* CVMX_ENABLE_HELPER_FUNCTIONS */
210
211 /**
212  * Returns the interface number for an IPD/PKO port number.
213  *
214  * @param ipd_port IPD/PKO port number
215  *
216  * @return Interface number
217  */
218 extern int cvmx_helper_get_interface_num(int ipd_port);
219
220
221 /**
222  * Returns the interface index number for an IPD/PKO port
223  * number.
224  *
225  * @param ipd_port IPD/PKO port number
226  *
227  * @return Interface index number
228  */
229 extern int cvmx_helper_get_interface_index_num(int ipd_port);
230
231 #endif  /* __CVMX_HELPER_H__ */