xref: /OK3568_Linux_fs/kernel/arch/mips/include/asm/octeon/cvmx-helper-util.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /***********************license start***************
2*4882a593Smuzhiyun  * Author: Cavium Networks
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Contact: support@caviumnetworks.com
5*4882a593Smuzhiyun  * This file is part of the OCTEON SDK
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Copyright (c) 2003-2008 Cavium Networks
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * This file is free software; you can redistribute it and/or modify
10*4882a593Smuzhiyun  * it under the terms of the GNU General Public License, Version 2, as
11*4882a593Smuzhiyun  * published by the Free Software Foundation.
12*4882a593Smuzhiyun  *
13*4882a593Smuzhiyun  * This file is distributed in the hope that it will be useful, but
14*4882a593Smuzhiyun  * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15*4882a593Smuzhiyun  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16*4882a593Smuzhiyun  * NONINFRINGEMENT.  See the GNU General Public License for more
17*4882a593Smuzhiyun  * details.
18*4882a593Smuzhiyun  *
19*4882a593Smuzhiyun  * You should have received a copy of the GNU General Public License
20*4882a593Smuzhiyun  * along with this file; if not, write to the Free Software
21*4882a593Smuzhiyun  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22*4882a593Smuzhiyun  * or visit http://www.gnu.org/licenses/.
23*4882a593Smuzhiyun  *
24*4882a593Smuzhiyun  * This file may also be available under a different license from Cavium.
25*4882a593Smuzhiyun  * Contact Cavium Networks for more information
26*4882a593Smuzhiyun  ***********************license end**************************************/
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun /*
29*4882a593Smuzhiyun  *
30*4882a593Smuzhiyun  * Small helper utilities.
31*4882a593Smuzhiyun  *
32*4882a593Smuzhiyun  */
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun #ifndef __CVMX_HELPER_UTIL_H__
35*4882a593Smuzhiyun #define __CVMX_HELPER_UTIL_H__
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun /**
38*4882a593Smuzhiyun  * Convert a interface mode into a human readable string
39*4882a593Smuzhiyun  *
40*4882a593Smuzhiyun  * @mode:   Mode to convert
41*4882a593Smuzhiyun  *
42*4882a593Smuzhiyun  * Returns String
43*4882a593Smuzhiyun  */
44*4882a593Smuzhiyun extern const char
45*4882a593Smuzhiyun     *cvmx_helper_interface_mode_to_string(cvmx_helper_interface_mode_t mode);
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun /**
48*4882a593Smuzhiyun  * Setup Random Early Drop to automatically begin dropping packets.
49*4882a593Smuzhiyun  *
50*4882a593Smuzhiyun  * @pass_thresh:
51*4882a593Smuzhiyun  *		 Packets will begin slowly dropping when there are less than
52*4882a593Smuzhiyun  *		 this many packet buffers free in FPA 0.
53*4882a593Smuzhiyun  * @drop_thresh:
54*4882a593Smuzhiyun  *		 All incoming packets will be dropped when there are less
55*4882a593Smuzhiyun  *		 than this many free packet buffers in FPA 0.
56*4882a593Smuzhiyun  * Returns Zero on success. Negative on failure
57*4882a593Smuzhiyun  */
58*4882a593Smuzhiyun extern int cvmx_helper_setup_red(int pass_thresh, int drop_thresh);
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun /**
61*4882a593Smuzhiyun  * Get the version of the CVMX libraries.
62*4882a593Smuzhiyun  *
63*4882a593Smuzhiyun  * Returns Version string. Note this buffer is allocated statically
64*4882a593Smuzhiyun  *	   and will be shared by all callers.
65*4882a593Smuzhiyun  */
66*4882a593Smuzhiyun extern const char *cvmx_helper_get_version(void);
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun /**
69*4882a593Smuzhiyun  * Setup the common GMX settings that determine the number of
70*4882a593Smuzhiyun  * ports. These setting apply to almost all configurations of all
71*4882a593Smuzhiyun  * chips.
72*4882a593Smuzhiyun  *
73*4882a593Smuzhiyun  * @interface: Interface to configure
74*4882a593Smuzhiyun  * @num_ports: Number of ports on the interface
75*4882a593Smuzhiyun  *
76*4882a593Smuzhiyun  * Returns Zero on success, negative on failure
77*4882a593Smuzhiyun  */
78*4882a593Smuzhiyun extern int __cvmx_helper_setup_gmx(int interface, int num_ports);
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun /**
81*4882a593Smuzhiyun  * Returns the IPD/PKO port number for a port on the given
82*4882a593Smuzhiyun  * interface.
83*4882a593Smuzhiyun  *
84*4882a593Smuzhiyun  * @interface: Interface to use
85*4882a593Smuzhiyun  * @port:      Port on the interface
86*4882a593Smuzhiyun  *
87*4882a593Smuzhiyun  * Returns IPD/PKO port number
88*4882a593Smuzhiyun  */
89*4882a593Smuzhiyun extern int cvmx_helper_get_ipd_port(int interface, int port);
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun /**
92*4882a593Smuzhiyun  * Returns the IPD/PKO port number for the first port on the given
93*4882a593Smuzhiyun  * interface.
94*4882a593Smuzhiyun  *
95*4882a593Smuzhiyun  * @interface: Interface to use
96*4882a593Smuzhiyun  *
97*4882a593Smuzhiyun  * Returns IPD/PKO port number
98*4882a593Smuzhiyun  */
cvmx_helper_get_first_ipd_port(int interface)99*4882a593Smuzhiyun static inline int cvmx_helper_get_first_ipd_port(int interface)
100*4882a593Smuzhiyun {
101*4882a593Smuzhiyun 	return cvmx_helper_get_ipd_port(interface, 0);
102*4882a593Smuzhiyun }
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun /**
105*4882a593Smuzhiyun  * Returns the IPD/PKO port number for the last port on the given
106*4882a593Smuzhiyun  * interface.
107*4882a593Smuzhiyun  *
108*4882a593Smuzhiyun  * @interface: Interface to use
109*4882a593Smuzhiyun  *
110*4882a593Smuzhiyun  * Returns IPD/PKO port number
111*4882a593Smuzhiyun  */
cvmx_helper_get_last_ipd_port(int interface)112*4882a593Smuzhiyun static inline int cvmx_helper_get_last_ipd_port(int interface)
113*4882a593Smuzhiyun {
114*4882a593Smuzhiyun 	extern int cvmx_helper_ports_on_interface(int interface);
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun 	return cvmx_helper_get_first_ipd_port(interface) +
117*4882a593Smuzhiyun 	       cvmx_helper_ports_on_interface(interface) - 1;
118*4882a593Smuzhiyun }
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun /**
121*4882a593Smuzhiyun  * Free the packet buffers contained in a work queue entry.
122*4882a593Smuzhiyun  * The work queue entry is not freed.
123*4882a593Smuzhiyun  *
124*4882a593Smuzhiyun  * @work:   Work queue entry with packet to free
125*4882a593Smuzhiyun  */
cvmx_helper_free_packet_data(struct cvmx_wqe * work)126*4882a593Smuzhiyun static inline void cvmx_helper_free_packet_data(struct cvmx_wqe *work)
127*4882a593Smuzhiyun {
128*4882a593Smuzhiyun 	uint64_t number_buffers;
129*4882a593Smuzhiyun 	union cvmx_buf_ptr buffer_ptr;
130*4882a593Smuzhiyun 	union cvmx_buf_ptr next_buffer_ptr;
131*4882a593Smuzhiyun 	uint64_t start_of_buffer;
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun 	number_buffers = work->word2.s.bufs;
134*4882a593Smuzhiyun 	if (number_buffers == 0)
135*4882a593Smuzhiyun 		return;
136*4882a593Smuzhiyun 	buffer_ptr = work->packet_ptr;
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun 	/*
139*4882a593Smuzhiyun 	 * Since the number of buffers is not zero, we know this is
140*4882a593Smuzhiyun 	 * not a dynamic short packet. We need to check if it is a
141*4882a593Smuzhiyun 	 * packet received with IPD_CTL_STATUS[NO_WPTR]. If this is
142*4882a593Smuzhiyun 	 * true, we need to free all buffers except for the first
143*4882a593Smuzhiyun 	 * one. The caller doesn't expect their WQE pointer to be
144*4882a593Smuzhiyun 	 * freed
145*4882a593Smuzhiyun 	 */
146*4882a593Smuzhiyun 	start_of_buffer = ((buffer_ptr.s.addr >> 7) - buffer_ptr.s.back) << 7;
147*4882a593Smuzhiyun 	if (cvmx_ptr_to_phys(work) == start_of_buffer) {
148*4882a593Smuzhiyun 		next_buffer_ptr =
149*4882a593Smuzhiyun 		    *(union cvmx_buf_ptr *) cvmx_phys_to_ptr(buffer_ptr.s.addr - 8);
150*4882a593Smuzhiyun 		buffer_ptr = next_buffer_ptr;
151*4882a593Smuzhiyun 		number_buffers--;
152*4882a593Smuzhiyun 	}
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun 	while (number_buffers--) {
155*4882a593Smuzhiyun 		/*
156*4882a593Smuzhiyun 		 * Remember the back pointer is in cache lines, not
157*4882a593Smuzhiyun 		 * 64bit words
158*4882a593Smuzhiyun 		 */
159*4882a593Smuzhiyun 		start_of_buffer =
160*4882a593Smuzhiyun 		    ((buffer_ptr.s.addr >> 7) - buffer_ptr.s.back) << 7;
161*4882a593Smuzhiyun 		/*
162*4882a593Smuzhiyun 		 * Read pointer to next buffer before we free the
163*4882a593Smuzhiyun 		 * current buffer.
164*4882a593Smuzhiyun 		 */
165*4882a593Smuzhiyun 		next_buffer_ptr =
166*4882a593Smuzhiyun 		    *(union cvmx_buf_ptr *) cvmx_phys_to_ptr(buffer_ptr.s.addr - 8);
167*4882a593Smuzhiyun 		cvmx_fpa_free(cvmx_phys_to_ptr(start_of_buffer),
168*4882a593Smuzhiyun 			      buffer_ptr.s.pool, 0);
169*4882a593Smuzhiyun 		buffer_ptr = next_buffer_ptr;
170*4882a593Smuzhiyun 	}
171*4882a593Smuzhiyun }
172*4882a593Smuzhiyun 
173*4882a593Smuzhiyun /**
174*4882a593Smuzhiyun  * Returns the interface number for an IPD/PKO port number.
175*4882a593Smuzhiyun  *
176*4882a593Smuzhiyun  * @ipd_port: IPD/PKO port number
177*4882a593Smuzhiyun  *
178*4882a593Smuzhiyun  * Returns Interface number
179*4882a593Smuzhiyun  */
180*4882a593Smuzhiyun extern int cvmx_helper_get_interface_num(int ipd_port);
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun /**
183*4882a593Smuzhiyun  * Returns the interface index number for an IPD/PKO port
184*4882a593Smuzhiyun  * number.
185*4882a593Smuzhiyun  *
186*4882a593Smuzhiyun  * @ipd_port: IPD/PKO port number
187*4882a593Smuzhiyun  *
188*4882a593Smuzhiyun  * Returns Interface index number
189*4882a593Smuzhiyun  */
190*4882a593Smuzhiyun extern int cvmx_helper_get_interface_index_num(int ipd_port);
191*4882a593Smuzhiyun 
192*4882a593Smuzhiyun #endif /* __CVMX_HELPER_H__ */
193