1232809Sjmallett/***********************license start***************
2232809Sjmallett * Copyright (c) 2003-2010  Cavium Inc. (support@cavium.com). All rights
3232809Sjmallett * reserved.
4232809Sjmallett *
5232809Sjmallett *
6232809Sjmallett * Redistribution and use in source and binary forms, with or without
7232809Sjmallett * modification, are permitted provided that the following conditions are
8232809Sjmallett * met:
9232809Sjmallett *
10232809Sjmallett *   * Redistributions of source code must retain the above copyright
11232809Sjmallett *     notice, this list of conditions and the following disclaimer.
12232809Sjmallett *
13232809Sjmallett *   * Redistributions in binary form must reproduce the above
14232809Sjmallett *     copyright notice, this list of conditions and the following
15232809Sjmallett *     disclaimer in the documentation and/or other materials provided
16232809Sjmallett *     with the distribution.
17232809Sjmallett
18232809Sjmallett *   * Neither the name of Cavium Inc. nor the names of
19232809Sjmallett *     its contributors may be used to endorse or promote products
20232809Sjmallett *     derived from this software without specific prior written
21232809Sjmallett *     permission.
22232809Sjmallett
23232809Sjmallett * This Software, including technical data, may be subject to U.S. export  control
24232809Sjmallett * laws, including the U.S. Export Administration Act and its  associated
25232809Sjmallett * regulations, and may be subject to export or import  regulations in other
26232809Sjmallett * countries.
27232809Sjmallett
28232809Sjmallett * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29232809Sjmallett * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
30232809Sjmallett * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31232809Sjmallett * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32232809Sjmallett * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33232809Sjmallett * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34232809Sjmallett * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35232809Sjmallett * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36232809Sjmallett * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR
37232809Sjmallett * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38232809Sjmallett ***********************license end**************************************/
39232809Sjmallett
40232809Sjmallett
41232809Sjmallett/**
42232809Sjmallett * @file
43232809Sjmallett *
44232809Sjmallett * Helper Functions for the Configuration Framework
45232809Sjmallett *
46232809Sjmallett * OCTEON_CN68XX introduces a flexible hw interface configuration
47232809Sjmallett * scheme. To cope with this change and the requirements of
48232809Sjmallett * configurability for other system resources, e.g., IPD/PIP pknd and
49232809Sjmallett * PKO ports and queues, a configuration framework for the SDK is
50232809Sjmallett * designed. It has two goals: first to recognize and establish the
51232809Sjmallett * default configuration and, second, to allow the user to define key
52232809Sjmallett * parameters in a high-level language.
53232809Sjmallett *
54232809Sjmallett * The helper functions query the QLM setup to help achieving the
55232809Sjmallett * first goal.
56232809Sjmallett *
57232809Sjmallett * The second goal is accomplished by generating
58232809Sjmallett * cvmx_helper_cfg_init() from a high-level lanaguage.
59232809Sjmallett *
60232809Sjmallett * <hr>$Revision: 0 $<hr>
61232809Sjmallett */
62232809Sjmallett
63232809Sjmallett#ifndef __CVMX_HELPER_CFG_H__
64232809Sjmallett#define __CVMX_HELPER_CFG_H__
65232809Sjmallett
66232809Sjmallett#define CVMX_HELPER_CFG_MAX_IFACE		9
67232809Sjmallett#define CVMX_HELPER_CFG_MAX_PKO_PORT		128
68232809Sjmallett#define CVMX_HELPER_CFG_MAX_PIP_BPID       	64
69232809Sjmallett#define CVMX_HELPER_CFG_MAX_PIP_PKND       	64
70232809Sjmallett#define CVMX_HELPER_CFG_MAX_PKO_QUEUES     	256
71232809Sjmallett#define CVMX_HELPER_CFG_MAX_PORT_PER_IFACE 	256
72232809Sjmallett
73232809Sjmallett#define CVMX_HELPER_CFG_INVALID_VALUE		-1	/* The default return
74232809Sjmallett						   	 * value upon failure
75232809Sjmallett							 */
76232809Sjmallett
77232809Sjmallett#ifdef	__cplusplus
78232809Sjmallettextern "C" {
79232809Sjmallett#endif
80232809Sjmallett
81232809Sjmallett#define cvmx_helper_cfg_assert(cond)					\
82232809Sjmallett	do {								\
83232809Sjmallett	    if (!(cond))						\
84232809Sjmallett	    {								\
85232809Sjmallett	        cvmx_dprintf("cvmx_helper_cfg_assert (%s) at %s:%d\n",	\
86232809Sjmallett		    #cond, __FILE__, __LINE__);				\
87232809Sjmallett	    }								\
88232809Sjmallett	} while (0)
89232809Sjmallett
90232809Sjmallett/*
91232809Sjmallett * Config Options
92232809Sjmallett *
93232809Sjmallett * These options have to be set via cvmx_helper_cfg_opt_set() before calling the
94232809Sjmallett * routines that set up the hw. These routines process the options and set them
95232809Sjmallett * correctly to take effect at runtime.
96232809Sjmallett */
97232809Sjmallettenum cvmx_helper_cfg_option {
98232809Sjmallett	CVMX_HELPER_CFG_OPT_USE_DWB, /*
99232809Sjmallett				      * Global option to control if
100232809Sjmallett				      * the SDK configures units (DMA,
101232809Sjmallett				      * SSO, and PKO) to send don't
102232809Sjmallett				      * write back (DWB) requests for
103232809Sjmallett				      * freed buffers. Set to 1/0 to
104232809Sjmallett				      * enable/disable DWB.
105232809Sjmallett				      *
106232809Sjmallett				      * For programs that fit inside
107232809Sjmallett				      * L2, sending DWB just causes
108232809Sjmallett				      * more L2 operations without
109232809Sjmallett				      * benefit.
110232809Sjmallett	                              */
111232809Sjmallett
112232809Sjmallett	CVMX_HELPER_CFG_OPT_MAX
113232809Sjmallett};
114232809Sjmalletttypedef enum cvmx_helper_cfg_option cvmx_helper_cfg_option_t;
115232809Sjmallett
116232809Sjmallett/*
117232809Sjmallett * @INTERNAL
118232809Sjmallett * Return configured pknd for the port
119232809Sjmallett *
120232809Sjmallett * @param interface the interface number
121232809Sjmallett * @param index the port's index number
122232809Sjmallett * @return the pknd
123232809Sjmallett */
124232809Sjmallettextern int __cvmx_helper_cfg_pknd(int interface, int index);
125232809Sjmallett
126232809Sjmallett/*
127232809Sjmallett * @INTERNAL
128232809Sjmallett * Return the configured bpid for the port
129232809Sjmallett *
130232809Sjmallett * @param interface the interface number
131232809Sjmallett * @param index the port's index number
132232809Sjmallett * @return the bpid
133232809Sjmallett */
134232809Sjmallettextern int __cvmx_helper_cfg_bpid(int interface, int index);
135232809Sjmallett
136232809Sjmallett/*
137232809Sjmallett * @INTERNAL
138232809Sjmallett * Return the configured pko_port base for the port
139232809Sjmallett *
140232809Sjmallett * @param interface the interface number
141232809Sjmallett * @param index the port's index number
142232809Sjmallett * @return the pko_port base
143232809Sjmallett */
144232809Sjmallettextern int __cvmx_helper_cfg_pko_port_base(int interface, int index);
145232809Sjmallett
146232809Sjmallett/*
147232809Sjmallett * @INTERNAL
148232809Sjmallett * Return the configured number of pko_ports for the port
149232809Sjmallett *
150232809Sjmallett * @param interface the interface number
151232809Sjmallett * @param index the port's index number
152232809Sjmallett * @return the number of pko_ports
153232809Sjmallett */
154232809Sjmallettextern int __cvmx_helper_cfg_pko_port_num(int interface, int index);
155232809Sjmallett
156232809Sjmallett/*
157232809Sjmallett * @INTERNAL
158232809Sjmallett * Return the configured pko_queue base for the pko_port
159232809Sjmallett *
160232809Sjmallett * @param pko_port
161232809Sjmallett * @return the pko_queue base
162232809Sjmallett */
163232809Sjmallettextern int __cvmx_helper_cfg_pko_queue_base(int pko_port);
164232809Sjmallett
165232809Sjmallett/*
166232809Sjmallett * @INTERNAL
167232809Sjmallett * Return the configured number of pko_queues for the pko_port
168232809Sjmallett *
169232809Sjmallett * @param pko_port
170232809Sjmallett * @return the number of pko_queues
171232809Sjmallett */
172232809Sjmallettextern int __cvmx_helper_cfg_pko_queue_num(int pko_port);
173232809Sjmallett
174232809Sjmallett/*
175232809Sjmallett * @INTERNAL
176232809Sjmallett * Return the interface the pko_port is configured for
177232809Sjmallett *
178232809Sjmallett * @param pko_port
179232809Sjmallett * @return the interface for the pko_port
180232809Sjmallett */
181232809Sjmallettextern int __cvmx_helper_cfg_pko_port_interface(int pko_port);
182232809Sjmallett
183232809Sjmallett/*
184232809Sjmallett * @INTERNAL
185232809Sjmallett * Return the index of the port the pko_port is configured for
186232809Sjmallett *
187232809Sjmallett * @param pko_port
188232809Sjmallett * @return the index of the port
189232809Sjmallett */
190232809Sjmallettextern int __cvmx_helper_cfg_pko_port_index(int pko_port);
191232809Sjmallett
192232809Sjmallett/*
193232809Sjmallett * @INTERNAL
194232809Sjmallett * Return the pko_eid of the pko_port
195232809Sjmallett *
196232809Sjmallett * @param pko_port
197232809Sjmallett * @return the pko_eid
198232809Sjmallett */
199232809Sjmallettextern int __cvmx_helper_cfg_pko_port_eid(int pko_port);
200232809Sjmallett
201232809Sjmallett/*
202232809Sjmallett * @INTERNAL
203232809Sjmallett * Return the max# of pko queues allocated.
204232809Sjmallett *
205232809Sjmallett * @return the max# of pko queues
206232809Sjmallett *
207232809Sjmallett * Note: there might be holes in the queue space depending on user
208232809Sjmallett * configuration. The function returns the highest queue's index in
209232809Sjmallett * use.
210232809Sjmallett */
211232809Sjmallettextern int __cvmx_helper_cfg_pko_max_queue(void);
212232809Sjmallett
213232809Sjmallett/*
214232809Sjmallett * @INTERNAL
215232809Sjmallett * Return the max# of PKO DMA engines allocated.
216232809Sjmallett *
217232809Sjmallett * @return the max# of DMA engines
218232809Sjmallett *
219232809Sjmallett * NOTE: the DMA engines are allocated contiguously and starting from
220232809Sjmallett * 0.
221232809Sjmallett */
222232809Sjmallettextern int __cvmx_helper_cfg_pko_max_engine(void);
223232809Sjmallett
224232809Sjmallett/*
225232809Sjmallett * Get the value set for the config option ``opt''.
226232809Sjmallett *
227232809Sjmallett * @param opt is the config option.
228232809Sjmallett * @return the value set for the option
229232809Sjmallett */
230232809Sjmallettextern uint64_t cvmx_helper_cfg_opt_get(cvmx_helper_cfg_option_t opt);
231232809Sjmallett
232232809Sjmallett/*
233232809Sjmallett * Set the value for a config option.
234232809Sjmallett *
235232809Sjmallett * @param opt is the config option.
236232809Sjmallett * @param val is the value to set for the opt.
237232809Sjmallett * @return 0 for success and -1 on error
238232809Sjmallett *
239232809Sjmallett * Note an option here is a config-time parameter and this means that
240232809Sjmallett * it has to be set before calling the corresponding setup functions
241232809Sjmallett * that actually sets the option in hw.
242232809Sjmallett */
243232809Sjmallettextern int cvmx_helper_cfg_opt_set(cvmx_helper_cfg_option_t opt, uint64_t val);
244232809Sjmallett
245232809Sjmallett/*
246232809Sjmallett * Retrieve the pko_port base given ipd_port.
247232809Sjmallett *
248232809Sjmallett * @param ipd_port is the IPD eport
249232809Sjmallett * @return the corresponding PKO port base for the physical port
250232809Sjmallett * represented by the IPD eport or CVMX_HELPER_CFG_INVALID_VALUE.
251232809Sjmallett */
252232809Sjmallettextern int cvmx_helper_cfg_ipd2pko_port_base(int ipd_port);
253232809Sjmallett
254232809Sjmallett/*
255232809Sjmallett * Retrieve the number of pko_ports given ipd_port.
256232809Sjmallett *
257232809Sjmallett * @param ipd_port is the IPD eport
258232809Sjmallett * @return the corresponding number of PKO ports for the physical port
259232809Sjmallett *  represented by IPD eport or CVMX_HELPER_CFG_INVALID_VALUE.
260232809Sjmallett */
261232809Sjmallettextern int cvmx_helper_cfg_ipd2pko_port_num(int ipd_port);
262232809Sjmallett
263232809Sjmallett/*
264232809Sjmallett * @INTERNAL
265232809Sjmallett * The init function
266232809Sjmallett *
267232809Sjmallett * @param none
268232809Sjmallett * @return 0 for success.
269232809Sjmallett *
270232809Sjmallett * Note: this function is meant to be called to set the ``configured
271232809Sjmallett * parameters,'' e.g., pknd, bpid, etc. and therefore should be before
272232809Sjmallett * any of the corresponding cvmx_helper_cfg_xxxx() functions are
273232809Sjmallett * called.
274232809Sjmallett */
275232809Sjmallett
276232809Sjmallettextern int __cvmx_helper_cfg_init(void);
277232809Sjmallett
278232809Sjmallett#ifdef	__cplusplus
279232809Sjmallett}
280232809Sjmallett#endif
281232809Sjmallett
282232809Sjmallett#endif /* __CVMX_HELPER_CFG_H__ */
283