blob: aacd42a261e93f6269e4db56139645fe2b98e31d [file] [log] [blame]
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 Intel Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * The full GNU General Public License is included in this distribution in
20 * the file called "COPYING".
21 *
22 * Contact Information:
23 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 *
26 ******************************************************************************/
27
28#ifndef _I40E_HMC_H_
29#define _I40E_HMC_H_
30
31#define I40E_HMC_MAX_BP_COUNT 512
32
33/* forward-declare the HW struct for the compiler */
34struct i40e_hw;
35
36#define I40E_HMC_INFO_SIGNATURE 0x484D5347 /* HMSG */
37#define I40E_HMC_PD_CNT_IN_SD 512
38#define I40E_HMC_DIRECT_BP_SIZE 0x200000 /* 2M */
39#define I40E_HMC_PAGED_BP_SIZE 4096
40#define I40E_HMC_PD_BP_BUF_ALIGNMENT 4096
41#define I40E_FIRST_VF_FPM_ID 16
42
43struct i40e_hmc_obj_info {
44 u64 base; /* base addr in FPM */
45 u32 max_cnt; /* max count available for this hmc func */
46 u32 cnt; /* count of objects driver actually wants to create */
47 u64 size; /* size in bytes of one object */
48};
49
50enum i40e_sd_entry_type {
51 I40E_SD_TYPE_INVALID = 0,
52 I40E_SD_TYPE_PAGED = 1,
53 I40E_SD_TYPE_DIRECT = 2
54};
55
56struct i40e_hmc_bp {
57 enum i40e_sd_entry_type entry_type;
58 struct i40e_dma_mem addr; /* populate to be used by hw */
59 u32 sd_pd_index;
60 u32 ref_cnt;
61};
62
63struct i40e_hmc_pd_entry {
64 struct i40e_hmc_bp bp;
65 u32 sd_index;
66 bool valid;
67};
68
69struct i40e_hmc_pd_table {
70 struct i40e_dma_mem pd_page_addr; /* populate to be used by hw */
71 struct i40e_hmc_pd_entry *pd_entry; /* [512] for sw book keeping */
72 struct i40e_virt_mem pd_entry_virt_mem; /* virt mem for pd_entry */
73
74 u32 ref_cnt;
75 u32 sd_index;
76};
77
78struct i40e_hmc_sd_entry {
79 enum i40e_sd_entry_type entry_type;
80 bool valid;
81
82 union {
83 struct i40e_hmc_pd_table pd_table;
84 struct i40e_hmc_bp bp;
85 } u;
86};
87
88struct i40e_hmc_sd_table {
89 struct i40e_virt_mem addr; /* used to track sd_entry allocations */
90 u32 sd_cnt;
91 u32 ref_cnt;
92 struct i40e_hmc_sd_entry *sd_entry; /* (sd_cnt*512) entries max */
93};
94
95struct i40e_hmc_info {
96 u32 signature;
97 /* equals to pci func num for PF and dynamically allocated for VFs */
98 u8 hmc_fn_id;
99 u16 first_sd_index; /* index of the first available SD */
100
101 /* hmc objects */
102 struct i40e_hmc_obj_info *hmc_obj;
103 struct i40e_virt_mem hmc_obj_virt_mem;
104 struct i40e_hmc_sd_table sd_table;
105};
106
107#define I40E_INC_SD_REFCNT(sd_table) ((sd_table)->ref_cnt++)
108#define I40E_INC_PD_REFCNT(pd_table) ((pd_table)->ref_cnt++)
109#define I40E_INC_BP_REFCNT(bp) ((bp)->ref_cnt++)
110
111#define I40E_DEC_SD_REFCNT(sd_table) ((sd_table)->ref_cnt--)
112#define I40E_DEC_PD_REFCNT(pd_table) ((pd_table)->ref_cnt--)
113#define I40E_DEC_BP_REFCNT(bp) ((bp)->ref_cnt--)
114
115/**
116 * I40E_SET_PF_SD_ENTRY - marks the sd entry as valid in the hardware
117 * @hw: pointer to our hw struct
118 * @pa: pointer to physical address
119 * @sd_index: segment descriptor index
120 * @hmc_fn_id: hmc function id
121 * @type: if sd entry is direct or paged
122 **/
123#define I40E_SET_PF_SD_ENTRY(hw, pa, sd_index, type) \
124{ \
125 u32 val1, val2, val3; \
126 val1 = (u32)(upper_32_bits(pa)); \
127 val2 = (u32)(pa) | (I40E_HMC_MAX_BP_COUNT << \
128 I40E_PFHMC_SDDATALOW_PMSDBPCOUNT_SHIFT) | \
129 ((((type) == I40E_SD_TYPE_PAGED) ? 0 : 1) << \
130 I40E_PFHMC_SDDATALOW_PMSDTYPE_SHIFT) | \
131 (1 << I40E_PFHMC_SDDATALOW_PMSDVALID_SHIFT); \
132 val3 = (sd_index) | (1 << I40E_PFHMC_SDCMD_PMSDWR_SHIFT); \
133 wr32((hw), I40E_PFHMC_SDDATAHIGH, val1); \
134 wr32((hw), I40E_PFHMC_SDDATALOW, val2); \
135 wr32((hw), I40E_PFHMC_SDCMD, val3); \
136}
137
138/**
139 * I40E_CLEAR_PF_SD_ENTRY - marks the sd entry as invalid in the hardware
140 * @hw: pointer to our hw struct
141 * @sd_index: segment descriptor index
142 * @hmc_fn_id: hmc function id
143 * @type: if sd entry is direct or paged
144 **/
145#define I40E_CLEAR_PF_SD_ENTRY(hw, sd_index, type) \
146{ \
147 u32 val2, val3; \
148 val2 = (I40E_HMC_MAX_BP_COUNT << \
149 I40E_PFHMC_SDDATALOW_PMSDBPCOUNT_SHIFT) | \
150 ((((type) == I40E_SD_TYPE_PAGED) ? 0 : 1) << \
151 I40E_PFHMC_SDDATALOW_PMSDTYPE_SHIFT); \
152 val3 = (sd_index) | (1 << I40E_PFHMC_SDCMD_PMSDWR_SHIFT); \
153 wr32((hw), I40E_PFHMC_SDDATAHIGH, 0); \
154 wr32((hw), I40E_PFHMC_SDDATALOW, val2); \
155 wr32((hw), I40E_PFHMC_SDCMD, val3); \
156}
157
158/**
159 * I40E_INVALIDATE_PF_HMC_PD - Invalidates the pd cache in the hardware
160 * @hw: pointer to our hw struct
161 * @sd_idx: segment descriptor index
162 * @pd_idx: page descriptor index
163 * @hmc_fn_id: hmc function id
164 **/
165#define I40E_INVALIDATE_PF_HMC_PD(hw, sd_idx, pd_idx) \
166 wr32((hw), I40E_PFHMC_PDINV, \
167 (((sd_idx) << I40E_PFHMC_PDINV_PMSDIDX_SHIFT) | \
168 ((pd_idx) << I40E_PFHMC_PDINV_PMPDIDX_SHIFT)))
169
170#define I40E_INVALIDATE_VF_HMC_PD(hw, sd_idx, pd_idx, hmc_fn_id) \
171 wr32((hw), I40E_GLHMC_VFPDINV((hmc_fn_id) - I40E_FIRST_VF_FPM_ID), \
172 (((sd_idx) << I40E_PFHMC_PDINV_PMSDIDX_SHIFT) | \
173 ((pd_idx) << I40E_PFHMC_PDINV_PMPDIDX_SHIFT)))
174
175/**
176 * I40E_FIND_SD_INDEX_LIMIT - finds segment descriptor index limit
177 * @hmc_info: pointer to the HMC configuration information structure
178 * @type: type of HMC resources we're searching
179 * @index: starting index for the object
180 * @cnt: number of objects we're trying to create
181 * @sd_idx: pointer to return index of the segment descriptor in question
182 * @sd_limit: pointer to return the maximum number of segment descriptors
183 *
184 * This function calculates the segment descriptor index and index limit
185 * for the resource defined by i40e_hmc_rsrc_type.
186 **/
187#define I40E_FIND_SD_INDEX_LIMIT(hmc_info, type, index, cnt, sd_idx, sd_limit)\
188{ \
189 u64 fpm_addr, fpm_limit; \
190 fpm_addr = (hmc_info)->hmc_obj[(type)].base + \
191 (hmc_info)->hmc_obj[(type)].size * (index); \
192 fpm_limit = fpm_addr + (hmc_info)->hmc_obj[(type)].size * (cnt);\
193 *(sd_idx) = (u32)(fpm_addr / I40E_HMC_DIRECT_BP_SIZE); \
194 *(sd_limit) = (u32)((fpm_limit - 1) / I40E_HMC_DIRECT_BP_SIZE); \
195 /* add one more to the limit to correct our range */ \
196 *(sd_limit) += 1; \
197}
198
199/**
200 * I40E_FIND_PD_INDEX_LIMIT - finds page descriptor index limit
201 * @hmc_info: pointer to the HMC configuration information struct
202 * @type: HMC resource type we're examining
203 * @idx: starting index for the object
204 * @cnt: number of objects we're trying to create
205 * @pd_index: pointer to return page descriptor index
206 * @pd_limit: pointer to return page descriptor index limit
207 *
208 * Calculates the page descriptor index and index limit for the resource
209 * defined by i40e_hmc_rsrc_type.
210 **/
211#define I40E_FIND_PD_INDEX_LIMIT(hmc_info, type, idx, cnt, pd_index, pd_limit)\
212{ \
213 u64 fpm_adr, fpm_limit; \
214 fpm_adr = (hmc_info)->hmc_obj[(type)].base + \
215 (hmc_info)->hmc_obj[(type)].size * (idx); \
216 fpm_limit = fpm_adr + (hmc_info)->hmc_obj[(type)].size * (cnt); \
217 *(pd_index) = (u32)(fpm_adr / I40E_HMC_PAGED_BP_SIZE); \
218 *(pd_limit) = (u32)((fpm_limit - 1) / I40E_HMC_PAGED_BP_SIZE); \
219 /* add one more to the limit to correct our range */ \
220 *(pd_limit) += 1; \
221}
222i40e_status i40e_add_sd_table_entry(struct i40e_hw *hw,
223 struct i40e_hmc_info *hmc_info,
224 u32 sd_index,
225 enum i40e_sd_entry_type type,
226 u64 direct_mode_sz);
227
228i40e_status i40e_add_pd_table_entry(struct i40e_hw *hw,
229 struct i40e_hmc_info *hmc_info,
230 u32 pd_index);
231i40e_status i40e_remove_pd_bp(struct i40e_hw *hw,
232 struct i40e_hmc_info *hmc_info,
233 u32 idx, bool is_pf);
234i40e_status i40e_prep_remove_sd_bp(struct i40e_hmc_info *hmc_info,
235 u32 idx);
236i40e_status i40e_remove_sd_bp_new(struct i40e_hw *hw,
237 struct i40e_hmc_info *hmc_info,
238 u32 idx, bool is_pf);
239i40e_status i40e_prep_remove_pd_page(struct i40e_hmc_info *hmc_info,
240 u32 idx);
241i40e_status i40e_remove_pd_page_new(struct i40e_hw *hw,
242 struct i40e_hmc_info *hmc_info,
243 u32 idx, bool is_pf);
244
245#endif /* _I40E_HMC_H_ */