1*14b24e2bSVaishali Kulkarni /*
2*14b24e2bSVaishali Kulkarni * CDDL HEADER START
3*14b24e2bSVaishali Kulkarni *
4*14b24e2bSVaishali Kulkarni * The contents of this file are subject to the terms of the
5*14b24e2bSVaishali Kulkarni * Common Development and Distribution License, v.1,  (the "License").
6*14b24e2bSVaishali Kulkarni * You may not use this file except in compliance with the License.
7*14b24e2bSVaishali Kulkarni *
8*14b24e2bSVaishali Kulkarni * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*14b24e2bSVaishali Kulkarni * or http://opensource.org/licenses/CDDL-1.0.
10*14b24e2bSVaishali Kulkarni * See the License for the specific language governing permissions
11*14b24e2bSVaishali Kulkarni * and limitations under the License.
12*14b24e2bSVaishali Kulkarni *
13*14b24e2bSVaishali Kulkarni * When distributing Covered Code, include this CDDL HEADER in each
14*14b24e2bSVaishali Kulkarni * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*14b24e2bSVaishali Kulkarni * If applicable, add the following below this CDDL HEADER, with the
16*14b24e2bSVaishali Kulkarni * fields enclosed by brackets "[]" replaced with your own identifying
17*14b24e2bSVaishali Kulkarni * information: Portions Copyright [yyyy] [name of copyright owner]
18*14b24e2bSVaishali Kulkarni *
19*14b24e2bSVaishali Kulkarni * CDDL HEADER END
20*14b24e2bSVaishali Kulkarni */
21*14b24e2bSVaishali Kulkarni 
22*14b24e2bSVaishali Kulkarni /*
23*14b24e2bSVaishali Kulkarni * Copyright 2014-2017 Cavium, Inc.
24*14b24e2bSVaishali Kulkarni * The contents of this file are subject to the terms of the Common Development
25*14b24e2bSVaishali Kulkarni * and Distribution License, v.1,  (the "License").
26*14b24e2bSVaishali Kulkarni 
27*14b24e2bSVaishali Kulkarni * You may not use this file except in compliance with the License.
28*14b24e2bSVaishali Kulkarni 
29*14b24e2bSVaishali Kulkarni * You can obtain a copy of the License at available
30*14b24e2bSVaishali Kulkarni * at http://opensource.org/licenses/CDDL-1.0
31*14b24e2bSVaishali Kulkarni 
32*14b24e2bSVaishali Kulkarni * See the License for the specific language governing permissions and
33*14b24e2bSVaishali Kulkarni * limitations under the License.
34*14b24e2bSVaishali Kulkarni */
35*14b24e2bSVaishali Kulkarni 
36*14b24e2bSVaishali Kulkarni #ifndef __ECORE_INT_H__
37*14b24e2bSVaishali Kulkarni #define __ECORE_INT_H__
38*14b24e2bSVaishali Kulkarni 
39*14b24e2bSVaishali Kulkarni #include "ecore.h"
40*14b24e2bSVaishali Kulkarni #include "ecore_int_api.h"
41*14b24e2bSVaishali Kulkarni 
42*14b24e2bSVaishali Kulkarni #define ECORE_CAU_DEF_RX_TIMER_RES 0
43*14b24e2bSVaishali Kulkarni #define ECORE_CAU_DEF_TX_TIMER_RES 0
44*14b24e2bSVaishali Kulkarni 
45*14b24e2bSVaishali Kulkarni #define ECORE_SB_ATT_IDX	0x0001
46*14b24e2bSVaishali Kulkarni #define ECORE_SB_EVENT_MASK	0x0003
47*14b24e2bSVaishali Kulkarni 
48*14b24e2bSVaishali Kulkarni #define SB_ALIGNED_SIZE(p_hwfn)					\
49*14b24e2bSVaishali Kulkarni 	ALIGNED_TYPE_SIZE(struct status_block, p_hwfn)
50*14b24e2bSVaishali Kulkarni 
51*14b24e2bSVaishali Kulkarni #define ECORE_SB_INVALID_IDX	0xffff
52*14b24e2bSVaishali Kulkarni 
53*14b24e2bSVaishali Kulkarni struct ecore_igu_block
54*14b24e2bSVaishali Kulkarni {
55*14b24e2bSVaishali Kulkarni 	u8	status;
56*14b24e2bSVaishali Kulkarni #define ECORE_IGU_STATUS_FREE	0x01
57*14b24e2bSVaishali Kulkarni #define ECORE_IGU_STATUS_VALID	0x02
58*14b24e2bSVaishali Kulkarni #define ECORE_IGU_STATUS_PF	0x04
59*14b24e2bSVaishali Kulkarni #define ECORE_IGU_STATUS_DSB	0x08
60*14b24e2bSVaishali Kulkarni 
61*14b24e2bSVaishali Kulkarni 	u8	vector_number;
62*14b24e2bSVaishali Kulkarni 	u8	function_id;
63*14b24e2bSVaishali Kulkarni 	u8      is_pf;
64*14b24e2bSVaishali Kulkarni 
65*14b24e2bSVaishali Kulkarni 	/* Index inside IGU [meant for back reference] */
66*14b24e2bSVaishali Kulkarni 	u16 igu_sb_id;
67*14b24e2bSVaishali Kulkarni 
68*14b24e2bSVaishali Kulkarni 	struct ecore_sb_info *sb_info;
69*14b24e2bSVaishali Kulkarni };
70*14b24e2bSVaishali Kulkarni 
71*14b24e2bSVaishali Kulkarni struct ecore_igu_info
72*14b24e2bSVaishali Kulkarni {
73*14b24e2bSVaishali Kulkarni 	struct ecore_igu_block entry[MAX_TOT_SB_PER_PATH];
74*14b24e2bSVaishali Kulkarni 	u16 igu_dsb_id;
75*14b24e2bSVaishali Kulkarni 
76*14b24e2bSVaishali Kulkarni 	/* The numbers can shift when using APIs to switch SBs between PF and
77*14b24e2bSVaishali Kulkarni 	 * VF.
78*14b24e2bSVaishali Kulkarni 	 */
79*14b24e2bSVaishali Kulkarni 	struct ecore_sb_cnt_info usage;
80*14b24e2bSVaishali Kulkarni 
81*14b24e2bSVaishali Kulkarni 	/* Determine whether we can shift SBs between VFs and PFs */
82*14b24e2bSVaishali Kulkarni 	bool b_allow_pf_vf_change;
83*14b24e2bSVaishali Kulkarni };
84*14b24e2bSVaishali Kulkarni 
85*14b24e2bSVaishali Kulkarni /**
86*14b24e2bSVaishali Kulkarni  * @brief - Make sure the IGU CAM reflects the resources provided by MFW
87*14b24e2bSVaishali Kulkarni  *
88*14b24e2bSVaishali Kulkarni  * @param p_hwfn
89*14b24e2bSVaishali Kulkarni  * @param p_ptt
90*14b24e2bSVaishali Kulkarni  */
91*14b24e2bSVaishali Kulkarni int ecore_int_igu_reset_cam(struct ecore_hwfn *p_hwfn,
92*14b24e2bSVaishali Kulkarni 			    struct ecore_ptt *p_ptt);
93*14b24e2bSVaishali Kulkarni 
94*14b24e2bSVaishali Kulkarni /**
95*14b24e2bSVaishali Kulkarni  * @brief - Make sure IGU CAM reflects the default resources once again,
96*14b24e2bSVaishali Kulkarni  *          starting with a 'dirty' SW database.
97*14b24e2bSVaishali Kulkarni  * @param p_hwfn
98*14b24e2bSVaishali Kulkarni  * @param p_ptt
99*14b24e2bSVaishali Kulkarni  */
100*14b24e2bSVaishali Kulkarni int ecore_int_igu_reset_cam_default(struct ecore_hwfn *p_hwfn,
101*14b24e2bSVaishali Kulkarni 				    struct ecore_ptt *p_ptt);
102*14b24e2bSVaishali Kulkarni 
103*14b24e2bSVaishali Kulkarni /**
104*14b24e2bSVaishali Kulkarni  * @brief Translate the weakly-defined client sb-id into an IGU sb-id
105*14b24e2bSVaishali Kulkarni  *
106*14b24e2bSVaishali Kulkarni  * @param p_hwfn
107*14b24e2bSVaishali Kulkarni  * @param sb_id - user provided sb_id
108*14b24e2bSVaishali Kulkarni  *
109*14b24e2bSVaishali Kulkarni  * @return an index inside IGU CAM where the SB resides
110*14b24e2bSVaishali Kulkarni  */
111*14b24e2bSVaishali Kulkarni u16 ecore_get_igu_sb_id(struct ecore_hwfn *p_hwfn, u16 sb_id);
112*14b24e2bSVaishali Kulkarni 
113*14b24e2bSVaishali Kulkarni /**
114*14b24e2bSVaishali Kulkarni  * @brief return a pointer to an unused valid SB
115*14b24e2bSVaishali Kulkarni  *
116*14b24e2bSVaishali Kulkarni  * @param p_hwfn
117*14b24e2bSVaishali Kulkarni  * @param b_is_pf - true iff we want a SB belonging to a PF
118*14b24e2bSVaishali Kulkarni  *
119*14b24e2bSVaishali Kulkarni  * @return point to an igu_block, OSAL_NULL if none is available
120*14b24e2bSVaishali Kulkarni  */
121*14b24e2bSVaishali Kulkarni struct ecore_igu_block *
122*14b24e2bSVaishali Kulkarni ecore_get_igu_free_sb(struct ecore_hwfn *p_hwfn, bool b_is_pf);
123*14b24e2bSVaishali Kulkarni 
124*14b24e2bSVaishali Kulkarni /* TODO Names of function may change... */
125*14b24e2bSVaishali Kulkarni void ecore_int_igu_init_pure_rt(struct ecore_hwfn	*p_hwfn,
126*14b24e2bSVaishali Kulkarni 				 struct ecore_ptt	*p_ptt,
127*14b24e2bSVaishali Kulkarni 				 bool			b_set,
128*14b24e2bSVaishali Kulkarni 				 bool			b_slowpath);
129*14b24e2bSVaishali Kulkarni 
130*14b24e2bSVaishali Kulkarni void ecore_int_igu_init_rt(struct ecore_hwfn		*p_hwfn);
131*14b24e2bSVaishali Kulkarni 
132*14b24e2bSVaishali Kulkarni /**
133*14b24e2bSVaishali Kulkarni  * @brief ecore_int_igu_read_cam - Reads the IGU CAM.
134*14b24e2bSVaishali Kulkarni  *	This function needs to be called during hardware
135*14b24e2bSVaishali Kulkarni  *	prepare. It reads the info from igu cam to know which
136*14b24e2bSVaishali Kulkarni  *	status block is the default / base status block etc.
137*14b24e2bSVaishali Kulkarni  *
138*14b24e2bSVaishali Kulkarni  * @param p_hwfn
139*14b24e2bSVaishali Kulkarni  * @param p_ptt
140*14b24e2bSVaishali Kulkarni  *
141*14b24e2bSVaishali Kulkarni  * @return enum _ecore_status_t
142*14b24e2bSVaishali Kulkarni  */
143*14b24e2bSVaishali Kulkarni enum _ecore_status_t ecore_int_igu_read_cam(struct ecore_hwfn	*p_hwfn,
144*14b24e2bSVaishali Kulkarni 					    struct ecore_ptt	*p_ptt);
145*14b24e2bSVaishali Kulkarni 
146*14b24e2bSVaishali Kulkarni typedef enum _ecore_status_t(*ecore_int_comp_cb_t)(struct ecore_hwfn *p_hwfn,
147*14b24e2bSVaishali Kulkarni 						   void *cookie);
148*14b24e2bSVaishali Kulkarni /**
149*14b24e2bSVaishali Kulkarni  * @brief ecore_int_register_cb - Register callback func for
150*14b24e2bSVaishali Kulkarni  *      slowhwfn statusblock.
151*14b24e2bSVaishali Kulkarni  *
152*14b24e2bSVaishali Kulkarni  *	Every protocol that uses the slowhwfn status block
153*14b24e2bSVaishali Kulkarni  *	should register a callback function that will be called
154*14b24e2bSVaishali Kulkarni  *	once there is an update of the sp status block.
155*14b24e2bSVaishali Kulkarni  *
156*14b24e2bSVaishali Kulkarni  * @param p_hwfn
157*14b24e2bSVaishali Kulkarni  * @param comp_cb - function to be called when there is an
158*14b24e2bSVaishali Kulkarni  *                  interrupt on the sp sb
159*14b24e2bSVaishali Kulkarni  *
160*14b24e2bSVaishali Kulkarni  * @param cookie  - passed to the callback function
161*14b24e2bSVaishali Kulkarni  * @param sb_idx  - OUT parameter which gives the chosen index
162*14b24e2bSVaishali Kulkarni  *                  for this protocol.
163*14b24e2bSVaishali Kulkarni  * @param p_fw_cons  - pointer to the actual address of the
164*14b24e2bSVaishali Kulkarni  *                     consumer for this protocol.
165*14b24e2bSVaishali Kulkarni  *
166*14b24e2bSVaishali Kulkarni  * @return enum _ecore_status_t
167*14b24e2bSVaishali Kulkarni  */
168*14b24e2bSVaishali Kulkarni enum _ecore_status_t ecore_int_register_cb(struct ecore_hwfn    *p_hwfn,
169*14b24e2bSVaishali Kulkarni 					   ecore_int_comp_cb_t  comp_cb,
170*14b24e2bSVaishali Kulkarni 					   void                 *cookie,
171*14b24e2bSVaishali Kulkarni 					   u8                   *sb_idx,
172*14b24e2bSVaishali Kulkarni 					   __le16               **p_fw_cons);
173*14b24e2bSVaishali Kulkarni /**
174*14b24e2bSVaishali Kulkarni  * @brief ecore_int_unregister_cb - Unregisters callback
175*14b24e2bSVaishali Kulkarni  *      function from sp sb.
176*14b24e2bSVaishali Kulkarni  *      Partner of ecore_int_register_cb -> should be called
177*14b24e2bSVaishali Kulkarni  *      when no longer required.
178*14b24e2bSVaishali Kulkarni  *
179*14b24e2bSVaishali Kulkarni  * @param p_hwfn
180*14b24e2bSVaishali Kulkarni  * @param pi
181*14b24e2bSVaishali Kulkarni  *
182*14b24e2bSVaishali Kulkarni  * @return enum _ecore_status_t
183*14b24e2bSVaishali Kulkarni  */
184*14b24e2bSVaishali Kulkarni enum _ecore_status_t ecore_int_unregister_cb(struct ecore_hwfn *p_hwfn,
185*14b24e2bSVaishali Kulkarni 					     u8 pi);
186*14b24e2bSVaishali Kulkarni 
187*14b24e2bSVaishali Kulkarni /**
188*14b24e2bSVaishali Kulkarni  * @brief ecore_int_get_sp_sb_id - Get the slowhwfn sb id.
189*14b24e2bSVaishali Kulkarni  *
190*14b24e2bSVaishali Kulkarni  * @param p_hwfn
191*14b24e2bSVaishali Kulkarni  *
192*14b24e2bSVaishali Kulkarni  * @return u16
193*14b24e2bSVaishali Kulkarni  */
194*14b24e2bSVaishali Kulkarni u16 ecore_int_get_sp_sb_id(struct ecore_hwfn *p_hwfn);
195*14b24e2bSVaishali Kulkarni 
196*14b24e2bSVaishali Kulkarni /**
197*14b24e2bSVaishali Kulkarni  * @brief Status block cleanup. Should be called for each status
198*14b24e2bSVaishali Kulkarni  *        block that will be used -> both PF / VF
199*14b24e2bSVaishali Kulkarni  *
200*14b24e2bSVaishali Kulkarni  * @param p_hwfn
201*14b24e2bSVaishali Kulkarni  * @param p_ptt
202*14b24e2bSVaishali Kulkarni  * @param sb_id		- igu status block id
203*14b24e2bSVaishali Kulkarni  * @param opaque	- opaque fid of the sb owner.
204*14b24e2bSVaishali Kulkarni  * @param cleanup_set	- set(1) / clear(0)
205*14b24e2bSVaishali Kulkarni  */
206*14b24e2bSVaishali Kulkarni void ecore_int_igu_init_pure_rt_single(struct ecore_hwfn	*p_hwfn,
207*14b24e2bSVaishali Kulkarni 				       struct ecore_ptt		*p_ptt,
208*14b24e2bSVaishali Kulkarni 				       u16			sb_id,
209*14b24e2bSVaishali Kulkarni 				       u16			opaque,
210*14b24e2bSVaishali Kulkarni 				       bool			b_set);
211*14b24e2bSVaishali Kulkarni 
212*14b24e2bSVaishali Kulkarni /**
213*14b24e2bSVaishali Kulkarni  * @brief ecore_int_cau_conf - configure cau for a given status
214*14b24e2bSVaishali Kulkarni  *        block
215*14b24e2bSVaishali Kulkarni  *
216*14b24e2bSVaishali Kulkarni  * @param p_hwfn
217*14b24e2bSVaishali Kulkarni  * @param ptt
218*14b24e2bSVaishali Kulkarni  * @param sb_phys
219*14b24e2bSVaishali Kulkarni  * @param igu_sb_id
220*14b24e2bSVaishali Kulkarni  * @param vf_number
221*14b24e2bSVaishali Kulkarni  * @param vf_valid
222*14b24e2bSVaishali Kulkarni  */
223*14b24e2bSVaishali Kulkarni void ecore_int_cau_conf_sb(struct ecore_hwfn	*p_hwfn,
224*14b24e2bSVaishali Kulkarni 			   struct ecore_ptt	*p_ptt,
225*14b24e2bSVaishali Kulkarni 			   dma_addr_t		sb_phys,
226*14b24e2bSVaishali Kulkarni 			   u16			igu_sb_id,
227*14b24e2bSVaishali Kulkarni 			   u16			vf_number,
228*14b24e2bSVaishali Kulkarni 			   u8			vf_valid);
229*14b24e2bSVaishali Kulkarni 
230*14b24e2bSVaishali Kulkarni /**
231*14b24e2bSVaishali Kulkarni * @brief ecore_int_alloc
232*14b24e2bSVaishali Kulkarni *
233*14b24e2bSVaishali Kulkarni * @param p_hwfn
234*14b24e2bSVaishali Kulkarni  * @param p_ptt
235*14b24e2bSVaishali Kulkarni *
236*14b24e2bSVaishali Kulkarni * @return enum _ecore_status_t
237*14b24e2bSVaishali Kulkarni */
238*14b24e2bSVaishali Kulkarni enum _ecore_status_t ecore_int_alloc(struct ecore_hwfn	*p_hwfn,
239*14b24e2bSVaishali Kulkarni 				     struct ecore_ptt	*p_ptt);
240*14b24e2bSVaishali Kulkarni 
241*14b24e2bSVaishali Kulkarni /**
242*14b24e2bSVaishali Kulkarni * @brief ecore_int_free
243*14b24e2bSVaishali Kulkarni *
244*14b24e2bSVaishali Kulkarni * @param p_hwfn
245*14b24e2bSVaishali Kulkarni */
246*14b24e2bSVaishali Kulkarni void ecore_int_free(struct ecore_hwfn *p_hwfn);
247*14b24e2bSVaishali Kulkarni 
248*14b24e2bSVaishali Kulkarni /**
249*14b24e2bSVaishali Kulkarni * @brief ecore_int_setup
250*14b24e2bSVaishali Kulkarni *
251*14b24e2bSVaishali Kulkarni * @param p_hwfn
252*14b24e2bSVaishali Kulkarni * @param p_ptt
253*14b24e2bSVaishali Kulkarni */
254*14b24e2bSVaishali Kulkarni void ecore_int_setup(struct ecore_hwfn	*p_hwfn,
255*14b24e2bSVaishali Kulkarni 		     struct ecore_ptt	*p_ptt);
256*14b24e2bSVaishali Kulkarni 
257*14b24e2bSVaishali Kulkarni /**
258*14b24e2bSVaishali Kulkarni  * @brief - Enable Interrupt & Attention for hw function
259*14b24e2bSVaishali Kulkarni  *
260*14b24e2bSVaishali Kulkarni  * @param p_hwfn
261*14b24e2bSVaishali Kulkarni  * @param p_ptt
262*14b24e2bSVaishali Kulkarni  * @param int_mode
263*14b24e2bSVaishali Kulkarni  *
264*14b24e2bSVaishali Kulkarni * @return enum _ecore_status_t
265*14b24e2bSVaishali Kulkarni  */
266*14b24e2bSVaishali Kulkarni enum _ecore_status_t ecore_int_igu_enable(struct ecore_hwfn *p_hwfn,
267*14b24e2bSVaishali Kulkarni 					  struct ecore_ptt *p_ptt,
268*14b24e2bSVaishali Kulkarni 					  enum ecore_int_mode int_mode);
269*14b24e2bSVaishali Kulkarni 
270*14b24e2bSVaishali Kulkarni /**
271*14b24e2bSVaishali Kulkarni  * @brief - Initialize CAU status block entry
272*14b24e2bSVaishali Kulkarni  *
273*14b24e2bSVaishali Kulkarni  * @param p_hwfn
274*14b24e2bSVaishali Kulkarni  * @param p_sb_entry
275*14b24e2bSVaishali Kulkarni  * @param pf_id
276*14b24e2bSVaishali Kulkarni  * @param vf_number
277*14b24e2bSVaishali Kulkarni  * @param vf_valid
278*14b24e2bSVaishali Kulkarni  */
279*14b24e2bSVaishali Kulkarni void ecore_init_cau_sb_entry(struct ecore_hwfn *p_hwfn,
280*14b24e2bSVaishali Kulkarni 			     struct cau_sb_entry *p_sb_entry, u8 pf_id,
281*14b24e2bSVaishali Kulkarni 			     u16 vf_number, u8 vf_valid);
282*14b24e2bSVaishali Kulkarni 
283*14b24e2bSVaishali Kulkarni enum _ecore_status_t ecore_int_set_timer_res(struct ecore_hwfn *p_hwfn,
284*14b24e2bSVaishali Kulkarni 					     struct ecore_ptt *p_ptt,
285*14b24e2bSVaishali Kulkarni 					     u8 timer_res, u16 sb_id, bool tx);
286*14b24e2bSVaishali Kulkarni #ifndef ASIC_ONLY
287*14b24e2bSVaishali Kulkarni #define ECORE_MAPPING_MEMORY_SIZE(dev) \
288*14b24e2bSVaishali Kulkarni 	((CHIP_REV_IS_SLOW(dev) && (!(dev)->b_is_emul_full)) ? \
289*14b24e2bSVaishali Kulkarni 	 136 : NUM_OF_SBS(dev))
290*14b24e2bSVaishali Kulkarni #else
291*14b24e2bSVaishali Kulkarni #define ECORE_MAPPING_MEMORY_SIZE(dev) NUM_OF_SBS(dev)
292*14b24e2bSVaishali Kulkarni #endif
293*14b24e2bSVaishali Kulkarni 
294*14b24e2bSVaishali Kulkarni #endif /* __ECORE_INT_H__ */
295*14b24e2bSVaishali Kulkarni