blob: 1dd1938f594f533d0bbc807af284ee062dad854a [file] [log] [blame]
Greg Rosed358aa92013-12-21 06:13:11 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
Jesse Brandeburgb8316072014-04-05 07:46:11 +00004 * Copyright(c) 2013 - 2014 Intel Corporation.
Greg Rosed358aa92013-12-21 06:13:11 +00005 *
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 *
Jesse Brandeburgb8316072014-04-05 07:46:11 +000015 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
Greg Rosed358aa92013-12-21 06:13:11 +000018 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
27#include "i40e_type.h"
28#include "i40e_adminq.h"
29#include "i40e_prototype.h"
Jesse Brandeburg681bdf82017-05-11 11:23:09 -070030#include <linux/avf/virtchnl.h>
Greg Rosed358aa92013-12-21 06:13:11 +000031
32/**
33 * i40e_set_mac_type - Sets MAC type
34 * @hw: pointer to the HW structure
35 *
36 * This function sets the mac type of the adapter based on the
37 * vendor ID and device ID stored in the hw structure.
38 **/
39i40e_status i40e_set_mac_type(struct i40e_hw *hw)
40{
41 i40e_status status = 0;
42
43 if (hw->vendor_id == PCI_VENDOR_ID_INTEL) {
44 switch (hw->device_id) {
Shannon Nelsonab600852014-01-17 15:36:39 -080045 case I40E_DEV_ID_SFP_XL710:
Shannon Nelsonab600852014-01-17 15:36:39 -080046 case I40E_DEV_ID_QEMU:
Shannon Nelsonab600852014-01-17 15:36:39 -080047 case I40E_DEV_ID_KX_B:
48 case I40E_DEV_ID_KX_C:
Shannon Nelsonab600852014-01-17 15:36:39 -080049 case I40E_DEV_ID_QSFP_A:
50 case I40E_DEV_ID_QSFP_B:
51 case I40E_DEV_ID_QSFP_C:
Paul M Stillwell Jr1ac1e762014-10-17 03:14:44 +000052 case I40E_DEV_ID_10G_BASE_T:
Shannon Nelsonbc5166b92015-08-26 15:14:10 -040053 case I40E_DEV_ID_10G_BASE_T4:
Jesse Brandeburgae24b402015-03-27 00:12:09 -070054 case I40E_DEV_ID_20G_KR2:
Shannon Nelson48a3b512015-07-23 16:54:39 -040055 case I40E_DEV_ID_20G_KR2_A:
Carolyn Wyborny31232372016-11-21 13:03:48 -080056 case I40E_DEV_ID_25G_B:
57 case I40E_DEV_ID_25G_SFP28:
Greg Rosed358aa92013-12-21 06:13:11 +000058 hw->mac.type = I40E_MAC_XL710;
59 break;
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -040060 case I40E_DEV_ID_SFP_X722:
61 case I40E_DEV_ID_1G_BASE_T_X722:
62 case I40E_DEV_ID_10G_BASE_T_X722:
Catherine Sullivand6bf58c2016-03-18 12:18:08 -070063 case I40E_DEV_ID_SFP_I_X722:
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -040064 hw->mac.type = I40E_MAC_X722;
65 break;
66 case I40E_DEV_ID_X722_VF:
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -040067 hw->mac.type = I40E_MAC_X722_VF;
68 break;
Shannon Nelsonab600852014-01-17 15:36:39 -080069 case I40E_DEV_ID_VF:
70 case I40E_DEV_ID_VF_HV:
Preethi Banalaabf709a2017-05-11 11:23:20 -070071 case I40E_DEV_ID_ADAPTIVE_VF:
Greg Rosed358aa92013-12-21 06:13:11 +000072 hw->mac.type = I40E_MAC_VF;
73 break;
74 default:
75 hw->mac.type = I40E_MAC_GENERIC;
76 break;
77 }
78 } else {
79 status = I40E_ERR_DEVICE_NOT_SUPPORTED;
80 }
81
82 hw_dbg(hw, "i40e_set_mac_type found mac: %d, returns: %d\n",
83 hw->mac.type, status);
84 return status;
85}
86
87/**
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040088 * i40evf_aq_str - convert AQ err code to a string
89 * @hw: pointer to the HW structure
90 * @aq_err: the AQ error code to convert
91 **/
Jingjing Wu4e68adfe2015-09-28 14:12:31 -040092const char *i40evf_aq_str(struct i40e_hw *hw, enum i40e_admin_queue_err aq_err)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040093{
94 switch (aq_err) {
95 case I40E_AQ_RC_OK:
96 return "OK";
97 case I40E_AQ_RC_EPERM:
98 return "I40E_AQ_RC_EPERM";
99 case I40E_AQ_RC_ENOENT:
100 return "I40E_AQ_RC_ENOENT";
101 case I40E_AQ_RC_ESRCH:
102 return "I40E_AQ_RC_ESRCH";
103 case I40E_AQ_RC_EINTR:
104 return "I40E_AQ_RC_EINTR";
105 case I40E_AQ_RC_EIO:
106 return "I40E_AQ_RC_EIO";
107 case I40E_AQ_RC_ENXIO:
108 return "I40E_AQ_RC_ENXIO";
109 case I40E_AQ_RC_E2BIG:
110 return "I40E_AQ_RC_E2BIG";
111 case I40E_AQ_RC_EAGAIN:
112 return "I40E_AQ_RC_EAGAIN";
113 case I40E_AQ_RC_ENOMEM:
114 return "I40E_AQ_RC_ENOMEM";
115 case I40E_AQ_RC_EACCES:
116 return "I40E_AQ_RC_EACCES";
117 case I40E_AQ_RC_EFAULT:
118 return "I40E_AQ_RC_EFAULT";
119 case I40E_AQ_RC_EBUSY:
120 return "I40E_AQ_RC_EBUSY";
121 case I40E_AQ_RC_EEXIST:
122 return "I40E_AQ_RC_EEXIST";
123 case I40E_AQ_RC_EINVAL:
124 return "I40E_AQ_RC_EINVAL";
125 case I40E_AQ_RC_ENOTTY:
126 return "I40E_AQ_RC_ENOTTY";
127 case I40E_AQ_RC_ENOSPC:
128 return "I40E_AQ_RC_ENOSPC";
129 case I40E_AQ_RC_ENOSYS:
130 return "I40E_AQ_RC_ENOSYS";
131 case I40E_AQ_RC_ERANGE:
132 return "I40E_AQ_RC_ERANGE";
133 case I40E_AQ_RC_EFLUSHED:
134 return "I40E_AQ_RC_EFLUSHED";
135 case I40E_AQ_RC_BAD_ADDR:
136 return "I40E_AQ_RC_BAD_ADDR";
137 case I40E_AQ_RC_EMODE:
138 return "I40E_AQ_RC_EMODE";
139 case I40E_AQ_RC_EFBIG:
140 return "I40E_AQ_RC_EFBIG";
141 }
142
143 snprintf(hw->err_str, sizeof(hw->err_str), "%d", aq_err);
144 return hw->err_str;
145}
146
147/**
148 * i40evf_stat_str - convert status err code to a string
149 * @hw: pointer to the HW structure
150 * @stat_err: the status error code to convert
151 **/
Jingjing Wu4e68adfe2015-09-28 14:12:31 -0400152const char *i40evf_stat_str(struct i40e_hw *hw, i40e_status stat_err)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400153{
154 switch (stat_err) {
155 case 0:
156 return "OK";
157 case I40E_ERR_NVM:
158 return "I40E_ERR_NVM";
159 case I40E_ERR_NVM_CHECKSUM:
160 return "I40E_ERR_NVM_CHECKSUM";
161 case I40E_ERR_PHY:
162 return "I40E_ERR_PHY";
163 case I40E_ERR_CONFIG:
164 return "I40E_ERR_CONFIG";
165 case I40E_ERR_PARAM:
166 return "I40E_ERR_PARAM";
167 case I40E_ERR_MAC_TYPE:
168 return "I40E_ERR_MAC_TYPE";
169 case I40E_ERR_UNKNOWN_PHY:
170 return "I40E_ERR_UNKNOWN_PHY";
171 case I40E_ERR_LINK_SETUP:
172 return "I40E_ERR_LINK_SETUP";
173 case I40E_ERR_ADAPTER_STOPPED:
174 return "I40E_ERR_ADAPTER_STOPPED";
175 case I40E_ERR_INVALID_MAC_ADDR:
176 return "I40E_ERR_INVALID_MAC_ADDR";
177 case I40E_ERR_DEVICE_NOT_SUPPORTED:
178 return "I40E_ERR_DEVICE_NOT_SUPPORTED";
179 case I40E_ERR_MASTER_REQUESTS_PENDING:
180 return "I40E_ERR_MASTER_REQUESTS_PENDING";
181 case I40E_ERR_INVALID_LINK_SETTINGS:
182 return "I40E_ERR_INVALID_LINK_SETTINGS";
183 case I40E_ERR_AUTONEG_NOT_COMPLETE:
184 return "I40E_ERR_AUTONEG_NOT_COMPLETE";
185 case I40E_ERR_RESET_FAILED:
186 return "I40E_ERR_RESET_FAILED";
187 case I40E_ERR_SWFW_SYNC:
188 return "I40E_ERR_SWFW_SYNC";
189 case I40E_ERR_NO_AVAILABLE_VSI:
190 return "I40E_ERR_NO_AVAILABLE_VSI";
191 case I40E_ERR_NO_MEMORY:
192 return "I40E_ERR_NO_MEMORY";
193 case I40E_ERR_BAD_PTR:
194 return "I40E_ERR_BAD_PTR";
195 case I40E_ERR_RING_FULL:
196 return "I40E_ERR_RING_FULL";
197 case I40E_ERR_INVALID_PD_ID:
198 return "I40E_ERR_INVALID_PD_ID";
199 case I40E_ERR_INVALID_QP_ID:
200 return "I40E_ERR_INVALID_QP_ID";
201 case I40E_ERR_INVALID_CQ_ID:
202 return "I40E_ERR_INVALID_CQ_ID";
203 case I40E_ERR_INVALID_CEQ_ID:
204 return "I40E_ERR_INVALID_CEQ_ID";
205 case I40E_ERR_INVALID_AEQ_ID:
206 return "I40E_ERR_INVALID_AEQ_ID";
207 case I40E_ERR_INVALID_SIZE:
208 return "I40E_ERR_INVALID_SIZE";
209 case I40E_ERR_INVALID_ARP_INDEX:
210 return "I40E_ERR_INVALID_ARP_INDEX";
211 case I40E_ERR_INVALID_FPM_FUNC_ID:
212 return "I40E_ERR_INVALID_FPM_FUNC_ID";
213 case I40E_ERR_QP_INVALID_MSG_SIZE:
214 return "I40E_ERR_QP_INVALID_MSG_SIZE";
215 case I40E_ERR_QP_TOOMANY_WRS_POSTED:
216 return "I40E_ERR_QP_TOOMANY_WRS_POSTED";
217 case I40E_ERR_INVALID_FRAG_COUNT:
218 return "I40E_ERR_INVALID_FRAG_COUNT";
219 case I40E_ERR_QUEUE_EMPTY:
220 return "I40E_ERR_QUEUE_EMPTY";
221 case I40E_ERR_INVALID_ALIGNMENT:
222 return "I40E_ERR_INVALID_ALIGNMENT";
223 case I40E_ERR_FLUSHED_QUEUE:
224 return "I40E_ERR_FLUSHED_QUEUE";
225 case I40E_ERR_INVALID_PUSH_PAGE_INDEX:
226 return "I40E_ERR_INVALID_PUSH_PAGE_INDEX";
227 case I40E_ERR_INVALID_IMM_DATA_SIZE:
228 return "I40E_ERR_INVALID_IMM_DATA_SIZE";
229 case I40E_ERR_TIMEOUT:
230 return "I40E_ERR_TIMEOUT";
231 case I40E_ERR_OPCODE_MISMATCH:
232 return "I40E_ERR_OPCODE_MISMATCH";
233 case I40E_ERR_CQP_COMPL_ERROR:
234 return "I40E_ERR_CQP_COMPL_ERROR";
235 case I40E_ERR_INVALID_VF_ID:
236 return "I40E_ERR_INVALID_VF_ID";
237 case I40E_ERR_INVALID_HMCFN_ID:
238 return "I40E_ERR_INVALID_HMCFN_ID";
239 case I40E_ERR_BACKING_PAGE_ERROR:
240 return "I40E_ERR_BACKING_PAGE_ERROR";
241 case I40E_ERR_NO_PBLCHUNKS_AVAILABLE:
242 return "I40E_ERR_NO_PBLCHUNKS_AVAILABLE";
243 case I40E_ERR_INVALID_PBLE_INDEX:
244 return "I40E_ERR_INVALID_PBLE_INDEX";
245 case I40E_ERR_INVALID_SD_INDEX:
246 return "I40E_ERR_INVALID_SD_INDEX";
247 case I40E_ERR_INVALID_PAGE_DESC_INDEX:
248 return "I40E_ERR_INVALID_PAGE_DESC_INDEX";
249 case I40E_ERR_INVALID_SD_TYPE:
250 return "I40E_ERR_INVALID_SD_TYPE";
251 case I40E_ERR_MEMCPY_FAILED:
252 return "I40E_ERR_MEMCPY_FAILED";
253 case I40E_ERR_INVALID_HMC_OBJ_INDEX:
254 return "I40E_ERR_INVALID_HMC_OBJ_INDEX";
255 case I40E_ERR_INVALID_HMC_OBJ_COUNT:
256 return "I40E_ERR_INVALID_HMC_OBJ_COUNT";
257 case I40E_ERR_INVALID_SRQ_ARM_LIMIT:
258 return "I40E_ERR_INVALID_SRQ_ARM_LIMIT";
259 case I40E_ERR_SRQ_ENABLED:
260 return "I40E_ERR_SRQ_ENABLED";
261 case I40E_ERR_ADMIN_QUEUE_ERROR:
262 return "I40E_ERR_ADMIN_QUEUE_ERROR";
263 case I40E_ERR_ADMIN_QUEUE_TIMEOUT:
264 return "I40E_ERR_ADMIN_QUEUE_TIMEOUT";
265 case I40E_ERR_BUF_TOO_SHORT:
266 return "I40E_ERR_BUF_TOO_SHORT";
267 case I40E_ERR_ADMIN_QUEUE_FULL:
268 return "I40E_ERR_ADMIN_QUEUE_FULL";
269 case I40E_ERR_ADMIN_QUEUE_NO_WORK:
270 return "I40E_ERR_ADMIN_QUEUE_NO_WORK";
271 case I40E_ERR_BAD_IWARP_CQE:
272 return "I40E_ERR_BAD_IWARP_CQE";
273 case I40E_ERR_NVM_BLANK_MODE:
274 return "I40E_ERR_NVM_BLANK_MODE";
275 case I40E_ERR_NOT_IMPLEMENTED:
276 return "I40E_ERR_NOT_IMPLEMENTED";
277 case I40E_ERR_PE_DOORBELL_NOT_ENABLED:
278 return "I40E_ERR_PE_DOORBELL_NOT_ENABLED";
279 case I40E_ERR_DIAG_TEST_FAILED:
280 return "I40E_ERR_DIAG_TEST_FAILED";
281 case I40E_ERR_NOT_READY:
282 return "I40E_ERR_NOT_READY";
283 case I40E_NOT_SUPPORTED:
284 return "I40E_NOT_SUPPORTED";
285 case I40E_ERR_FIRMWARE_API_VERSION:
286 return "I40E_ERR_FIRMWARE_API_VERSION";
287 }
288
289 snprintf(hw->err_str, sizeof(hw->err_str), "%d", stat_err);
290 return hw->err_str;
291}
292
293/**
Greg Rosed358aa92013-12-21 06:13:11 +0000294 * i40evf_debug_aq
295 * @hw: debug mask related to admin queue
296 * @mask: debug mask
297 * @desc: pointer to admin queue descriptor
298 * @buffer: pointer to command buffer
Shannon Nelsonf905dd62014-07-10 07:58:20 +0000299 * @buf_len: max length of buffer
Greg Rosed358aa92013-12-21 06:13:11 +0000300 *
301 * Dumps debug log about adminq command with descriptor contents.
302 **/
303void i40evf_debug_aq(struct i40e_hw *hw, enum i40e_debug_mask mask, void *desc,
Shannon Nelsonf905dd62014-07-10 07:58:20 +0000304 void *buffer, u16 buf_len)
Greg Rosed358aa92013-12-21 06:13:11 +0000305{
306 struct i40e_aq_desc *aq_desc = (struct i40e_aq_desc *)desc;
Shannon Nelson37a29732015-02-27 09:15:19 +0000307 u8 *buf = (u8 *)buffer;
Greg Rosed358aa92013-12-21 06:13:11 +0000308
309 if ((!(mask & hw->debug_mask)) || (desc == NULL))
310 return;
311
312 i40e_debug(hw, mask,
313 "AQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000314 le16_to_cpu(aq_desc->opcode),
315 le16_to_cpu(aq_desc->flags),
316 le16_to_cpu(aq_desc->datalen),
317 le16_to_cpu(aq_desc->retval));
Greg Rosed358aa92013-12-21 06:13:11 +0000318 i40e_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000319 le32_to_cpu(aq_desc->cookie_high),
320 le32_to_cpu(aq_desc->cookie_low));
Greg Rosed358aa92013-12-21 06:13:11 +0000321 i40e_debug(hw, mask, "\tparam (0,1) 0x%08X 0x%08X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000322 le32_to_cpu(aq_desc->params.internal.param0),
323 le32_to_cpu(aq_desc->params.internal.param1));
Greg Rosed358aa92013-12-21 06:13:11 +0000324 i40e_debug(hw, mask, "\taddr (h,l) 0x%08X 0x%08X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000325 le32_to_cpu(aq_desc->params.external.addr_high),
326 le32_to_cpu(aq_desc->params.external.addr_low));
Greg Rosed358aa92013-12-21 06:13:11 +0000327
328 if ((buffer != NULL) && (aq_desc->datalen != 0)) {
Colin Ian Kingff918912016-08-28 18:41:01 +0100329 u16 len = le16_to_cpu(aq_desc->datalen);
330
Greg Rosed358aa92013-12-21 06:13:11 +0000331 i40e_debug(hw, mask, "AQ CMD Buffer:\n");
Shannon Nelsonf905dd62014-07-10 07:58:20 +0000332 if (buf_len < len)
333 len = buf_len;
Shannon Nelson37a29732015-02-27 09:15:19 +0000334 /* write the full 16-byte chunks */
Alan Brady773d4022016-12-12 15:44:13 -0800335 if (hw->debug_mask & mask) {
336 char prefix[20];
337
338 snprintf(prefix, 20,
339 "i40evf %02x:%02x.%x: \t0x",
340 hw->bus.bus_id,
341 hw->bus.device,
342 hw->bus.func);
343
344 print_hex_dump(KERN_INFO, prefix, DUMP_PREFIX_OFFSET,
345 16, 1, buf, len, false);
346 }
Greg Rosed358aa92013-12-21 06:13:11 +0000347 }
348}
349
350/**
351 * i40evf_check_asq_alive
352 * @hw: pointer to the hw struct
353 *
354 * Returns true if Queue is enabled else false.
355 **/
356bool i40evf_check_asq_alive(struct i40e_hw *hw)
357{
Kevin Scott8b833b42014-04-09 05:58:54 +0000358 if (hw->aq.asq.len)
359 return !!(rd32(hw, hw->aq.asq.len) &
Anjali Singhai Jaine02a7f82015-07-10 19:36:06 -0400360 I40E_VF_ATQLEN1_ATQENABLE_MASK);
Kevin Scott8b833b42014-04-09 05:58:54 +0000361 else
362 return false;
Greg Rosed358aa92013-12-21 06:13:11 +0000363}
364
365/**
366 * i40evf_aq_queue_shutdown
367 * @hw: pointer to the hw struct
368 * @unloading: is the driver unloading itself
369 *
370 * Tell the Firmware that we're shutting down the AdminQ and whether
371 * or not the driver is unloading as well.
372 **/
373i40e_status i40evf_aq_queue_shutdown(struct i40e_hw *hw,
374 bool unloading)
375{
376 struct i40e_aq_desc desc;
377 struct i40e_aqc_queue_shutdown *cmd =
378 (struct i40e_aqc_queue_shutdown *)&desc.params.raw;
379 i40e_status status;
380
381 i40evf_fill_default_direct_cmd_desc(&desc,
382 i40e_aqc_opc_queue_shutdown);
383
384 if (unloading)
385 cmd->driver_unloading = cpu_to_le32(I40E_AQ_DRIVER_UNLOADING);
386 status = i40evf_asq_send_command(hw, &desc, NULL, 0, NULL);
387
388 return status;
389}
390
Anjali Singhai Jaine50c8d62015-06-05 12:20:27 -0400391/**
392 * i40e_aq_get_set_rss_lut
393 * @hw: pointer to the hardware structure
394 * @vsi_id: vsi fw index
395 * @pf_lut: for PF table set true, for VSI table set false
396 * @lut: pointer to the lut buffer provided by the caller
397 * @lut_size: size of the lut buffer
398 * @set: set true to set the table, false to get the table
399 *
400 * Internal function to get or set RSS look up table
401 **/
402static i40e_status i40e_aq_get_set_rss_lut(struct i40e_hw *hw,
403 u16 vsi_id, bool pf_lut,
404 u8 *lut, u16 lut_size,
405 bool set)
406{
407 i40e_status status;
408 struct i40e_aq_desc desc;
409 struct i40e_aqc_get_set_rss_lut *cmd_resp =
410 (struct i40e_aqc_get_set_rss_lut *)&desc.params.raw;
411
412 if (set)
413 i40evf_fill_default_direct_cmd_desc(&desc,
414 i40e_aqc_opc_set_rss_lut);
415 else
416 i40evf_fill_default_direct_cmd_desc(&desc,
417 i40e_aqc_opc_get_rss_lut);
418
419 /* Indirect command */
420 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
421 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
422
423 cmd_resp->vsi_id =
424 cpu_to_le16((u16)((vsi_id <<
425 I40E_AQC_SET_RSS_LUT_VSI_ID_SHIFT) &
426 I40E_AQC_SET_RSS_LUT_VSI_ID_MASK));
427 cmd_resp->vsi_id |= cpu_to_le16((u16)I40E_AQC_SET_RSS_LUT_VSI_VALID);
428
429 if (pf_lut)
430 cmd_resp->flags |= cpu_to_le16((u16)
431 ((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_PF <<
432 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
433 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
434 else
435 cmd_resp->flags |= cpu_to_le16((u16)
436 ((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_VSI <<
437 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
438 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
439
Anjali Singhai Jaine50c8d62015-06-05 12:20:27 -0400440 status = i40evf_asq_send_command(hw, &desc, lut, lut_size, NULL);
441
442 return status;
443}
444
445/**
446 * i40evf_aq_get_rss_lut
447 * @hw: pointer to the hardware structure
448 * @vsi_id: vsi fw index
449 * @pf_lut: for PF table set true, for VSI table set false
450 * @lut: pointer to the lut buffer provided by the caller
451 * @lut_size: size of the lut buffer
452 *
453 * get the RSS lookup table, PF or VSI type
454 **/
455i40e_status i40evf_aq_get_rss_lut(struct i40e_hw *hw, u16 vsi_id,
456 bool pf_lut, u8 *lut, u16 lut_size)
457{
458 return i40e_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size,
459 false);
460}
461
462/**
463 * i40evf_aq_set_rss_lut
464 * @hw: pointer to the hardware structure
465 * @vsi_id: vsi fw index
466 * @pf_lut: for PF table set true, for VSI table set false
467 * @lut: pointer to the lut buffer provided by the caller
468 * @lut_size: size of the lut buffer
469 *
470 * set the RSS lookup table, PF or VSI type
471 **/
472i40e_status i40evf_aq_set_rss_lut(struct i40e_hw *hw, u16 vsi_id,
473 bool pf_lut, u8 *lut, u16 lut_size)
474{
475 return i40e_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size, true);
476}
477
478/**
479 * i40e_aq_get_set_rss_key
480 * @hw: pointer to the hw struct
481 * @vsi_id: vsi fw index
482 * @key: pointer to key info struct
483 * @set: set true to set the key, false to get the key
484 *
485 * get the RSS key per VSI
486 **/
487static i40e_status i40e_aq_get_set_rss_key(struct i40e_hw *hw,
488 u16 vsi_id,
489 struct i40e_aqc_get_set_rss_key_data *key,
490 bool set)
491{
492 i40e_status status;
493 struct i40e_aq_desc desc;
494 struct i40e_aqc_get_set_rss_key *cmd_resp =
495 (struct i40e_aqc_get_set_rss_key *)&desc.params.raw;
496 u16 key_size = sizeof(struct i40e_aqc_get_set_rss_key_data);
497
498 if (set)
499 i40evf_fill_default_direct_cmd_desc(&desc,
500 i40e_aqc_opc_set_rss_key);
501 else
502 i40evf_fill_default_direct_cmd_desc(&desc,
503 i40e_aqc_opc_get_rss_key);
504
505 /* Indirect command */
506 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
507 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
508
509 cmd_resp->vsi_id =
510 cpu_to_le16((u16)((vsi_id <<
511 I40E_AQC_SET_RSS_KEY_VSI_ID_SHIFT) &
512 I40E_AQC_SET_RSS_KEY_VSI_ID_MASK));
513 cmd_resp->vsi_id |= cpu_to_le16((u16)I40E_AQC_SET_RSS_KEY_VSI_VALID);
Anjali Singhai Jaine50c8d62015-06-05 12:20:27 -0400514
515 status = i40evf_asq_send_command(hw, &desc, key, key_size, NULL);
516
517 return status;
518}
519
520/**
521 * i40evf_aq_get_rss_key
522 * @hw: pointer to the hw struct
523 * @vsi_id: vsi fw index
524 * @key: pointer to key info struct
525 *
526 **/
527i40e_status i40evf_aq_get_rss_key(struct i40e_hw *hw,
528 u16 vsi_id,
529 struct i40e_aqc_get_set_rss_key_data *key)
530{
531 return i40e_aq_get_set_rss_key(hw, vsi_id, key, false);
532}
533
534/**
535 * i40evf_aq_set_rss_key
536 * @hw: pointer to the hw struct
537 * @vsi_id: vsi fw index
538 * @key: pointer to key info struct
539 *
540 * set the RSS key per VSI
541 **/
542i40e_status i40evf_aq_set_rss_key(struct i40e_hw *hw,
543 u16 vsi_id,
544 struct i40e_aqc_get_set_rss_key_data *key)
545{
546 return i40e_aq_get_set_rss_key(hw, vsi_id, key, true);
547}
548
Greg Rosed358aa92013-12-21 06:13:11 +0000549
Eric W Biederman37a622c2014-03-18 00:26:50 -0700550/* The i40evf_ptype_lookup table is used to convert from the 8-bit ptype in the
Jesse Brandeburg206812b2014-02-12 01:45:33 +0000551 * hardware to a bit-field that can be used by SW to more easily determine the
552 * packet type.
553 *
554 * Macros are used to shorten the table lines and make this table human
555 * readable.
556 *
557 * We store the PTYPE in the top byte of the bit field - this is just so that
558 * we can check that the table doesn't have a row missing, as the index into
559 * the table should be the PTYPE.
560 *
561 * Typical work flow:
562 *
Eric W Biederman37a622c2014-03-18 00:26:50 -0700563 * IF NOT i40evf_ptype_lookup[ptype].known
Jesse Brandeburg206812b2014-02-12 01:45:33 +0000564 * THEN
565 * Packet is unknown
Eric W Biederman37a622c2014-03-18 00:26:50 -0700566 * ELSE IF i40evf_ptype_lookup[ptype].outer_ip == I40E_RX_PTYPE_OUTER_IP
Jesse Brandeburg206812b2014-02-12 01:45:33 +0000567 * Use the rest of the fields to look at the tunnels, inner protocols, etc
568 * ELSE
569 * Use the enum i40e_rx_l2_ptype to decode the packet type
570 * ENDIF
571 */
572
573/* macro to make the table lines short */
574#define I40E_PTT(PTYPE, OUTER_IP, OUTER_IP_VER, OUTER_FRAG, T, TE, TEF, I, PL)\
575 { PTYPE, \
576 1, \
577 I40E_RX_PTYPE_OUTER_##OUTER_IP, \
578 I40E_RX_PTYPE_OUTER_##OUTER_IP_VER, \
579 I40E_RX_PTYPE_##OUTER_FRAG, \
580 I40E_RX_PTYPE_TUNNEL_##T, \
581 I40E_RX_PTYPE_TUNNEL_END_##TE, \
582 I40E_RX_PTYPE_##TEF, \
583 I40E_RX_PTYPE_INNER_PROT_##I, \
584 I40E_RX_PTYPE_PAYLOAD_LAYER_##PL }
585
586#define I40E_PTT_UNUSED_ENTRY(PTYPE) \
587 { PTYPE, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
588
589/* shorter macros makes the table fit but are terse */
590#define I40E_RX_PTYPE_NOF I40E_RX_PTYPE_NOT_FRAG
591#define I40E_RX_PTYPE_FRG I40E_RX_PTYPE_FRAG
592#define I40E_RX_PTYPE_INNER_PROT_TS I40E_RX_PTYPE_INNER_PROT_TIMESYNC
593
594/* Lookup table mapping the HW PTYPE to the bit field for decoding */
Eric W Biederman37a622c2014-03-18 00:26:50 -0700595struct i40e_rx_ptype_decoded i40evf_ptype_lookup[] = {
Jesse Brandeburg206812b2014-02-12 01:45:33 +0000596 /* L2 Packet types */
597 I40E_PTT_UNUSED_ENTRY(0),
598 I40E_PTT(1, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
599 I40E_PTT(2, L2, NONE, NOF, NONE, NONE, NOF, TS, PAY2),
600 I40E_PTT(3, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
601 I40E_PTT_UNUSED_ENTRY(4),
602 I40E_PTT_UNUSED_ENTRY(5),
603 I40E_PTT(6, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
604 I40E_PTT(7, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
605 I40E_PTT_UNUSED_ENTRY(8),
606 I40E_PTT_UNUSED_ENTRY(9),
607 I40E_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
608 I40E_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
609 I40E_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
610 I40E_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
611 I40E_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
612 I40E_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
613 I40E_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
614 I40E_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
615 I40E_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
616 I40E_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
617 I40E_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
618 I40E_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
619
620 /* Non Tunneled IPv4 */
621 I40E_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
622 I40E_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
623 I40E_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP, PAY4),
624 I40E_PTT_UNUSED_ENTRY(25),
625 I40E_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP, PAY4),
626 I40E_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
627 I40E_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
628
629 /* IPv4 --> IPv4 */
630 I40E_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
631 I40E_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
632 I40E_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
633 I40E_PTT_UNUSED_ENTRY(32),
634 I40E_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
635 I40E_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
636 I40E_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
637
638 /* IPv4 --> IPv6 */
639 I40E_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
640 I40E_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
641 I40E_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
642 I40E_PTT_UNUSED_ENTRY(39),
643 I40E_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
644 I40E_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
645 I40E_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
646
647 /* IPv4 --> GRE/NAT */
648 I40E_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
649
650 /* IPv4 --> GRE/NAT --> IPv4 */
651 I40E_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
652 I40E_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
653 I40E_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
654 I40E_PTT_UNUSED_ENTRY(47),
655 I40E_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
656 I40E_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
657 I40E_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
658
659 /* IPv4 --> GRE/NAT --> IPv6 */
660 I40E_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
661 I40E_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
662 I40E_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
663 I40E_PTT_UNUSED_ENTRY(54),
664 I40E_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
665 I40E_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
666 I40E_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
667
668 /* IPv4 --> GRE/NAT --> MAC */
669 I40E_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
670
671 /* IPv4 --> GRE/NAT --> MAC --> IPv4 */
672 I40E_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
673 I40E_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
674 I40E_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
675 I40E_PTT_UNUSED_ENTRY(62),
676 I40E_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
677 I40E_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
678 I40E_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
679
680 /* IPv4 --> GRE/NAT -> MAC --> IPv6 */
681 I40E_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
682 I40E_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
683 I40E_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
684 I40E_PTT_UNUSED_ENTRY(69),
685 I40E_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
686 I40E_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
687 I40E_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
688
689 /* IPv4 --> GRE/NAT --> MAC/VLAN */
690 I40E_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
691
692 /* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
693 I40E_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
694 I40E_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
695 I40E_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
696 I40E_PTT_UNUSED_ENTRY(77),
697 I40E_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
698 I40E_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
699 I40E_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
700
701 /* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
702 I40E_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
703 I40E_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
704 I40E_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
705 I40E_PTT_UNUSED_ENTRY(84),
706 I40E_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
707 I40E_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
708 I40E_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
709
710 /* Non Tunneled IPv6 */
711 I40E_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
712 I40E_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
713 I40E_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP, PAY3),
714 I40E_PTT_UNUSED_ENTRY(91),
715 I40E_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP, PAY4),
716 I40E_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
717 I40E_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
718
719 /* IPv6 --> IPv4 */
720 I40E_PTT(95, IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
721 I40E_PTT(96, IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
722 I40E_PTT(97, IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
723 I40E_PTT_UNUSED_ENTRY(98),
724 I40E_PTT(99, IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
725 I40E_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
726 I40E_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
727
728 /* IPv6 --> IPv6 */
729 I40E_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
730 I40E_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
731 I40E_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
732 I40E_PTT_UNUSED_ENTRY(105),
733 I40E_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
734 I40E_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
735 I40E_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
736
737 /* IPv6 --> GRE/NAT */
738 I40E_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
739
740 /* IPv6 --> GRE/NAT -> IPv4 */
741 I40E_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
742 I40E_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
743 I40E_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
744 I40E_PTT_UNUSED_ENTRY(113),
745 I40E_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
746 I40E_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
747 I40E_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
748
749 /* IPv6 --> GRE/NAT -> IPv6 */
750 I40E_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
751 I40E_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
752 I40E_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
753 I40E_PTT_UNUSED_ENTRY(120),
754 I40E_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
755 I40E_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
756 I40E_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
757
758 /* IPv6 --> GRE/NAT -> MAC */
759 I40E_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
760
761 /* IPv6 --> GRE/NAT -> MAC -> IPv4 */
762 I40E_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
763 I40E_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
764 I40E_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
765 I40E_PTT_UNUSED_ENTRY(128),
766 I40E_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
767 I40E_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
768 I40E_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
769
770 /* IPv6 --> GRE/NAT -> MAC -> IPv6 */
771 I40E_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
772 I40E_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
773 I40E_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
774 I40E_PTT_UNUSED_ENTRY(135),
775 I40E_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
776 I40E_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
777 I40E_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
778
779 /* IPv6 --> GRE/NAT -> MAC/VLAN */
780 I40E_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
781
782 /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
783 I40E_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
784 I40E_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
785 I40E_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
786 I40E_PTT_UNUSED_ENTRY(143),
787 I40E_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
788 I40E_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
789 I40E_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
790
791 /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
792 I40E_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
793 I40E_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
794 I40E_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
795 I40E_PTT_UNUSED_ENTRY(150),
796 I40E_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
797 I40E_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
798 I40E_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
799
800 /* unused entries */
801 I40E_PTT_UNUSED_ENTRY(154),
802 I40E_PTT_UNUSED_ENTRY(155),
803 I40E_PTT_UNUSED_ENTRY(156),
804 I40E_PTT_UNUSED_ENTRY(157),
805 I40E_PTT_UNUSED_ENTRY(158),
806 I40E_PTT_UNUSED_ENTRY(159),
807
808 I40E_PTT_UNUSED_ENTRY(160),
809 I40E_PTT_UNUSED_ENTRY(161),
810 I40E_PTT_UNUSED_ENTRY(162),
811 I40E_PTT_UNUSED_ENTRY(163),
812 I40E_PTT_UNUSED_ENTRY(164),
813 I40E_PTT_UNUSED_ENTRY(165),
814 I40E_PTT_UNUSED_ENTRY(166),
815 I40E_PTT_UNUSED_ENTRY(167),
816 I40E_PTT_UNUSED_ENTRY(168),
817 I40E_PTT_UNUSED_ENTRY(169),
818
819 I40E_PTT_UNUSED_ENTRY(170),
820 I40E_PTT_UNUSED_ENTRY(171),
821 I40E_PTT_UNUSED_ENTRY(172),
822 I40E_PTT_UNUSED_ENTRY(173),
823 I40E_PTT_UNUSED_ENTRY(174),
824 I40E_PTT_UNUSED_ENTRY(175),
825 I40E_PTT_UNUSED_ENTRY(176),
826 I40E_PTT_UNUSED_ENTRY(177),
827 I40E_PTT_UNUSED_ENTRY(178),
828 I40E_PTT_UNUSED_ENTRY(179),
829
830 I40E_PTT_UNUSED_ENTRY(180),
831 I40E_PTT_UNUSED_ENTRY(181),
832 I40E_PTT_UNUSED_ENTRY(182),
833 I40E_PTT_UNUSED_ENTRY(183),
834 I40E_PTT_UNUSED_ENTRY(184),
835 I40E_PTT_UNUSED_ENTRY(185),
836 I40E_PTT_UNUSED_ENTRY(186),
837 I40E_PTT_UNUSED_ENTRY(187),
838 I40E_PTT_UNUSED_ENTRY(188),
839 I40E_PTT_UNUSED_ENTRY(189),
840
841 I40E_PTT_UNUSED_ENTRY(190),
842 I40E_PTT_UNUSED_ENTRY(191),
843 I40E_PTT_UNUSED_ENTRY(192),
844 I40E_PTT_UNUSED_ENTRY(193),
845 I40E_PTT_UNUSED_ENTRY(194),
846 I40E_PTT_UNUSED_ENTRY(195),
847 I40E_PTT_UNUSED_ENTRY(196),
848 I40E_PTT_UNUSED_ENTRY(197),
849 I40E_PTT_UNUSED_ENTRY(198),
850 I40E_PTT_UNUSED_ENTRY(199),
851
852 I40E_PTT_UNUSED_ENTRY(200),
853 I40E_PTT_UNUSED_ENTRY(201),
854 I40E_PTT_UNUSED_ENTRY(202),
855 I40E_PTT_UNUSED_ENTRY(203),
856 I40E_PTT_UNUSED_ENTRY(204),
857 I40E_PTT_UNUSED_ENTRY(205),
858 I40E_PTT_UNUSED_ENTRY(206),
859 I40E_PTT_UNUSED_ENTRY(207),
860 I40E_PTT_UNUSED_ENTRY(208),
861 I40E_PTT_UNUSED_ENTRY(209),
862
863 I40E_PTT_UNUSED_ENTRY(210),
864 I40E_PTT_UNUSED_ENTRY(211),
865 I40E_PTT_UNUSED_ENTRY(212),
866 I40E_PTT_UNUSED_ENTRY(213),
867 I40E_PTT_UNUSED_ENTRY(214),
868 I40E_PTT_UNUSED_ENTRY(215),
869 I40E_PTT_UNUSED_ENTRY(216),
870 I40E_PTT_UNUSED_ENTRY(217),
871 I40E_PTT_UNUSED_ENTRY(218),
872 I40E_PTT_UNUSED_ENTRY(219),
873
874 I40E_PTT_UNUSED_ENTRY(220),
875 I40E_PTT_UNUSED_ENTRY(221),
876 I40E_PTT_UNUSED_ENTRY(222),
877 I40E_PTT_UNUSED_ENTRY(223),
878 I40E_PTT_UNUSED_ENTRY(224),
879 I40E_PTT_UNUSED_ENTRY(225),
880 I40E_PTT_UNUSED_ENTRY(226),
881 I40E_PTT_UNUSED_ENTRY(227),
882 I40E_PTT_UNUSED_ENTRY(228),
883 I40E_PTT_UNUSED_ENTRY(229),
884
885 I40E_PTT_UNUSED_ENTRY(230),
886 I40E_PTT_UNUSED_ENTRY(231),
887 I40E_PTT_UNUSED_ENTRY(232),
888 I40E_PTT_UNUSED_ENTRY(233),
889 I40E_PTT_UNUSED_ENTRY(234),
890 I40E_PTT_UNUSED_ENTRY(235),
891 I40E_PTT_UNUSED_ENTRY(236),
892 I40E_PTT_UNUSED_ENTRY(237),
893 I40E_PTT_UNUSED_ENTRY(238),
894 I40E_PTT_UNUSED_ENTRY(239),
895
896 I40E_PTT_UNUSED_ENTRY(240),
897 I40E_PTT_UNUSED_ENTRY(241),
898 I40E_PTT_UNUSED_ENTRY(242),
899 I40E_PTT_UNUSED_ENTRY(243),
900 I40E_PTT_UNUSED_ENTRY(244),
901 I40E_PTT_UNUSED_ENTRY(245),
902 I40E_PTT_UNUSED_ENTRY(246),
903 I40E_PTT_UNUSED_ENTRY(247),
904 I40E_PTT_UNUSED_ENTRY(248),
905 I40E_PTT_UNUSED_ENTRY(249),
906
907 I40E_PTT_UNUSED_ENTRY(250),
908 I40E_PTT_UNUSED_ENTRY(251),
909 I40E_PTT_UNUSED_ENTRY(252),
910 I40E_PTT_UNUSED_ENTRY(253),
911 I40E_PTT_UNUSED_ENTRY(254),
912 I40E_PTT_UNUSED_ENTRY(255)
913};
914
Greg Rosed358aa92013-12-21 06:13:11 +0000915/**
Shannon Nelsonf6581372016-02-17 16:12:20 -0800916 * i40evf_aq_rx_ctl_read_register - use FW to read from an Rx control register
917 * @hw: pointer to the hw struct
918 * @reg_addr: register address
919 * @reg_val: ptr to register value
920 * @cmd_details: pointer to command details structure or NULL
921 *
922 * Use the firmware to read the Rx control register,
923 * especially useful if the Rx unit is under heavy pressure
924 **/
925i40e_status i40evf_aq_rx_ctl_read_register(struct i40e_hw *hw,
926 u32 reg_addr, u32 *reg_val,
927 struct i40e_asq_cmd_details *cmd_details)
928{
929 struct i40e_aq_desc desc;
930 struct i40e_aqc_rx_ctl_reg_read_write *cmd_resp =
931 (struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
932 i40e_status status;
933
934 if (!reg_val)
935 return I40E_ERR_PARAM;
936
937 i40evf_fill_default_direct_cmd_desc(&desc,
938 i40e_aqc_opc_rx_ctl_reg_read);
939
940 cmd_resp->address = cpu_to_le32(reg_addr);
941
942 status = i40evf_asq_send_command(hw, &desc, NULL, 0, cmd_details);
943
944 if (status == 0)
945 *reg_val = le32_to_cpu(cmd_resp->value);
946
947 return status;
948}
949
950/**
951 * i40evf_read_rx_ctl - read from an Rx control register
952 * @hw: pointer to the hw struct
953 * @reg_addr: register address
954 **/
955u32 i40evf_read_rx_ctl(struct i40e_hw *hw, u32 reg_addr)
956{
957 i40e_status status = 0;
958 bool use_register;
959 int retry = 5;
960 u32 val = 0;
961
Paul M Stillwell Jr60303082017-03-10 12:22:02 -0800962 use_register = (((hw->aq.api_maj_ver == 1) &&
963 (hw->aq.api_min_ver < 5)) ||
964 (hw->mac.type == I40E_MAC_X722));
Shannon Nelsonf6581372016-02-17 16:12:20 -0800965 if (!use_register) {
966do_retry:
967 status = i40evf_aq_rx_ctl_read_register(hw, reg_addr,
968 &val, NULL);
969 if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
970 usleep_range(1000, 2000);
971 retry--;
972 goto do_retry;
973 }
974 }
975
976 /* if the AQ access failed, try the old-fashioned way */
977 if (status || use_register)
978 val = rd32(hw, reg_addr);
979
980 return val;
981}
982
983/**
984 * i40evf_aq_rx_ctl_write_register
985 * @hw: pointer to the hw struct
986 * @reg_addr: register address
987 * @reg_val: register value
988 * @cmd_details: pointer to command details structure or NULL
989 *
990 * Use the firmware to write to an Rx control register,
991 * especially useful if the Rx unit is under heavy pressure
992 **/
993i40e_status i40evf_aq_rx_ctl_write_register(struct i40e_hw *hw,
994 u32 reg_addr, u32 reg_val,
995 struct i40e_asq_cmd_details *cmd_details)
996{
997 struct i40e_aq_desc desc;
998 struct i40e_aqc_rx_ctl_reg_read_write *cmd =
999 (struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
1000 i40e_status status;
1001
1002 i40evf_fill_default_direct_cmd_desc(&desc,
1003 i40e_aqc_opc_rx_ctl_reg_write);
1004
1005 cmd->address = cpu_to_le32(reg_addr);
1006 cmd->value = cpu_to_le32(reg_val);
1007
1008 status = i40evf_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1009
1010 return status;
1011}
1012
1013/**
1014 * i40evf_write_rx_ctl - write to an Rx control register
1015 * @hw: pointer to the hw struct
1016 * @reg_addr: register address
1017 * @reg_val: register value
1018 **/
1019void i40evf_write_rx_ctl(struct i40e_hw *hw, u32 reg_addr, u32 reg_val)
1020{
1021 i40e_status status = 0;
1022 bool use_register;
1023 int retry = 5;
1024
Paul M Stillwell Jr60303082017-03-10 12:22:02 -08001025 use_register = (((hw->aq.api_maj_ver == 1) &&
1026 (hw->aq.api_min_ver < 5)) ||
1027 (hw->mac.type == I40E_MAC_X722));
Shannon Nelsonf6581372016-02-17 16:12:20 -08001028 if (!use_register) {
1029do_retry:
1030 status = i40evf_aq_rx_ctl_write_register(hw, reg_addr,
1031 reg_val, NULL);
1032 if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
1033 usleep_range(1000, 2000);
1034 retry--;
1035 goto do_retry;
1036 }
1037 }
1038
1039 /* if the AQ access failed, try the old-fashioned way */
1040 if (status || use_register)
1041 wr32(hw, reg_addr, reg_val);
1042}
1043
1044/**
Greg Rosed358aa92013-12-21 06:13:11 +00001045 * i40e_aq_send_msg_to_pf
1046 * @hw: pointer to the hardware structure
1047 * @v_opcode: opcodes for VF-PF communication
1048 * @v_retval: return error code
1049 * @msg: pointer to the msg buffer
1050 * @msglen: msg length
1051 * @cmd_details: pointer to command details
1052 *
1053 * Send message to PF driver using admin queue. By default, this message
1054 * is sent asynchronously, i.e. i40evf_asq_send_command() does not wait for
1055 * completion before returning.
1056 **/
1057i40e_status i40e_aq_send_msg_to_pf(struct i40e_hw *hw,
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001058 enum virtchnl_ops v_opcode,
Greg Rosed358aa92013-12-21 06:13:11 +00001059 i40e_status v_retval,
1060 u8 *msg, u16 msglen,
1061 struct i40e_asq_cmd_details *cmd_details)
1062{
1063 struct i40e_aq_desc desc;
Mitch Williams4334edf2014-06-04 08:45:16 +00001064 struct i40e_asq_cmd_details details;
Greg Rosed358aa92013-12-21 06:13:11 +00001065 i40e_status status;
1066
1067 i40evf_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_pf);
1068 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_SI);
1069 desc.cookie_high = cpu_to_le32(v_opcode);
1070 desc.cookie_low = cpu_to_le32(v_retval);
1071 if (msglen) {
1072 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF
1073 | I40E_AQ_FLAG_RD));
1074 if (msglen > I40E_AQ_LARGE_BUF)
1075 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
1076 desc.datalen = cpu_to_le16(msglen);
1077 }
1078 if (!cmd_details) {
Greg Rosed358aa92013-12-21 06:13:11 +00001079 memset(&details, 0, sizeof(details));
1080 details.async = true;
1081 cmd_details = &details;
1082 }
Joe Perchesb58f2f72014-03-25 04:30:32 +00001083 status = i40evf_asq_send_command(hw, &desc, msg, msglen, cmd_details);
Greg Rosed358aa92013-12-21 06:13:11 +00001084 return status;
1085}
1086
1087/**
1088 * i40e_vf_parse_hw_config
1089 * @hw: pointer to the hardware structure
1090 * @msg: pointer to the virtual channel VF resource structure
1091 *
1092 * Given a VF resource message from the PF, populate the hw struct
1093 * with appropriate information.
1094 **/
1095void i40e_vf_parse_hw_config(struct i40e_hw *hw,
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001096 struct virtchnl_vf_resource *msg)
Greg Rosed358aa92013-12-21 06:13:11 +00001097{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001098 struct virtchnl_vsi_resource *vsi_res;
Greg Rosed358aa92013-12-21 06:13:11 +00001099 int i;
1100
1101 vsi_res = &msg->vsi_res[0];
1102
1103 hw->dev_caps.num_vsis = msg->num_vsis;
1104 hw->dev_caps.num_rx_qp = msg->num_queue_pairs;
1105 hw->dev_caps.num_tx_qp = msg->num_queue_pairs;
1106 hw->dev_caps.num_msix_vectors_vf = msg->max_vectors;
1107 hw->dev_caps.dcb = msg->vf_offload_flags &
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001108 VIRTCHNL_VF_OFFLOAD_L2;
Jesse Brandeburg9d683222017-04-28 16:53:17 -07001109 hw->dev_caps.fcoe = 0;
Greg Rosed358aa92013-12-21 06:13:11 +00001110 for (i = 0; i < msg->num_vsis; i++) {
Jesse Brandeburgff3f4cc2017-05-11 11:23:16 -07001111 if (vsi_res->vsi_type == VIRTCHNL_VSI_SRIOV) {
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001112 ether_addr_copy(hw->mac.perm_addr,
1113 vsi_res->default_mac_addr);
1114 ether_addr_copy(hw->mac.addr,
1115 vsi_res->default_mac_addr);
Greg Rosed358aa92013-12-21 06:13:11 +00001116 }
1117 vsi_res++;
1118 }
1119}
1120
1121/**
1122 * i40e_vf_reset
1123 * @hw: pointer to the hardware structure
1124 *
1125 * Send a VF_RESET message to the PF. Does not wait for response from PF
1126 * as none will be forthcoming. Immediately after calling this function,
1127 * the admin queue should be shut down and (optionally) reinitialized.
1128 **/
1129i40e_status i40e_vf_reset(struct i40e_hw *hw)
1130{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001131 return i40e_aq_send_msg_to_pf(hw, VIRTCHNL_OP_RESET_VF,
Greg Rosed358aa92013-12-21 06:13:11 +00001132 0, NULL, 0, NULL);
1133}
Jingjing Wu1d5c9602017-04-13 04:45:45 -04001134
1135/**
1136 * i40evf_aq_write_ppp - Write pipeline personalization profile (ppp)
1137 * @hw: pointer to the hw struct
1138 * @buff: command buffer (size in bytes = buff_size)
1139 * @buff_size: buffer size in bytes
1140 * @track_id: package tracking id
1141 * @error_offset: returns error offset
1142 * @error_info: returns error information
1143 * @cmd_details: pointer to command details structure or NULL
1144 **/
1145enum
1146i40e_status_code i40evf_aq_write_ppp(struct i40e_hw *hw, void *buff,
1147 u16 buff_size, u32 track_id,
1148 u32 *error_offset, u32 *error_info,
1149 struct i40e_asq_cmd_details *cmd_details)
1150{
1151 struct i40e_aq_desc desc;
1152 struct i40e_aqc_write_personalization_profile *cmd =
1153 (struct i40e_aqc_write_personalization_profile *)
1154 &desc.params.raw;
1155 struct i40e_aqc_write_ppp_resp *resp;
1156 i40e_status status;
1157
1158 i40evf_fill_default_direct_cmd_desc(&desc,
1159 i40e_aqc_opc_write_personalization_profile);
1160
1161 desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
1162 if (buff_size > I40E_AQ_LARGE_BUF)
1163 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
1164
1165 desc.datalen = cpu_to_le16(buff_size);
1166
1167 cmd->profile_track_id = cpu_to_le32(track_id);
1168
1169 status = i40evf_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
1170 if (!status) {
1171 resp = (struct i40e_aqc_write_ppp_resp *)&desc.params.raw;
1172 if (error_offset)
1173 *error_offset = le32_to_cpu(resp->error_offset);
1174 if (error_info)
1175 *error_info = le32_to_cpu(resp->error_info);
1176 }
1177
1178 return status;
1179}
1180
1181/**
1182 * i40evf_aq_get_ppp_list - Read pipeline personalization profile (ppp)
1183 * @hw: pointer to the hw struct
1184 * @buff: command buffer (size in bytes = buff_size)
1185 * @buff_size: buffer size in bytes
1186 * @cmd_details: pointer to command details structure or NULL
1187 **/
1188enum
1189i40e_status_code i40evf_aq_get_ppp_list(struct i40e_hw *hw, void *buff,
1190 u16 buff_size, u8 flags,
1191 struct i40e_asq_cmd_details *cmd_details)
1192{
1193 struct i40e_aq_desc desc;
1194 struct i40e_aqc_get_applied_profiles *cmd =
1195 (struct i40e_aqc_get_applied_profiles *)&desc.params.raw;
1196 i40e_status status;
1197
1198 i40evf_fill_default_direct_cmd_desc(&desc,
1199 i40e_aqc_opc_get_personalization_profile_list);
1200
1201 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
1202 if (buff_size > I40E_AQ_LARGE_BUF)
1203 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
1204 desc.datalen = cpu_to_le16(buff_size);
1205
1206 cmd->flags = flags;
1207
1208 status = i40evf_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
1209
1210 return status;
1211}
1212
1213/**
1214 * i40evf_find_segment_in_package
1215 * @segment_type: the segment type to search for (i.e., SEGMENT_TYPE_I40E)
1216 * @pkg_hdr: pointer to the package header to be searched
1217 *
1218 * This function searches a package file for a particular segment type. On
1219 * success it returns a pointer to the segment header, otherwise it will
1220 * return NULL.
1221 **/
1222struct i40e_generic_seg_header *
1223i40evf_find_segment_in_package(u32 segment_type,
1224 struct i40e_package_header *pkg_hdr)
1225{
1226 struct i40e_generic_seg_header *segment;
1227 u32 i;
1228
1229 /* Search all package segments for the requested segment type */
1230 for (i = 0; i < pkg_hdr->segment_count; i++) {
1231 segment =
1232 (struct i40e_generic_seg_header *)((u8 *)pkg_hdr +
1233 pkg_hdr->segment_offset[i]);
1234
1235 if (segment->type == segment_type)
1236 return segment;
1237 }
1238
1239 return NULL;
1240}
1241
1242/**
1243 * i40evf_write_profile
1244 * @hw: pointer to the hardware structure
1245 * @profile: pointer to the profile segment of the package to be downloaded
1246 * @track_id: package tracking id
1247 *
1248 * Handles the download of a complete package.
1249 */
1250enum i40e_status_code
1251i40evf_write_profile(struct i40e_hw *hw, struct i40e_profile_segment *profile,
1252 u32 track_id)
1253{
1254 i40e_status status = 0;
1255 struct i40e_section_table *sec_tbl;
1256 struct i40e_profile_section_header *sec = NULL;
1257 u32 dev_cnt;
1258 u32 vendor_dev_id;
1259 u32 *nvm;
1260 u32 section_size = 0;
1261 u32 offset = 0, info = 0;
1262 u32 i;
1263
1264 if (!track_id) {
1265 i40e_debug(hw, I40E_DEBUG_PACKAGE, "Track_id can't be 0.");
1266 return I40E_NOT_SUPPORTED;
1267 }
1268
1269 dev_cnt = profile->device_table_count;
1270
1271 for (i = 0; i < dev_cnt; i++) {
1272 vendor_dev_id = profile->device_table[i].vendor_dev_id;
1273 if ((vendor_dev_id >> 16) == PCI_VENDOR_ID_INTEL)
1274 if (hw->device_id == (vendor_dev_id & 0xFFFF))
1275 break;
1276 }
1277 if (i == dev_cnt) {
1278 i40e_debug(hw, I40E_DEBUG_PACKAGE, "Device doesn't support PPP");
1279 return I40E_ERR_DEVICE_NOT_SUPPORTED;
1280 }
1281
1282 nvm = (u32 *)&profile->device_table[dev_cnt];
1283 sec_tbl = (struct i40e_section_table *)&nvm[nvm[0] + 1];
1284
1285 for (i = 0; i < sec_tbl->section_count; i++) {
1286 sec = (struct i40e_profile_section_header *)((u8 *)profile +
1287 sec_tbl->section_offset[i]);
1288
1289 /* Skip 'AQ', 'note' and 'name' sections */
1290 if (sec->section.type != SECTION_TYPE_MMIO)
1291 continue;
1292
1293 section_size = sec->section.size +
1294 sizeof(struct i40e_profile_section_header);
1295
1296 /* Write profile */
1297 status = i40evf_aq_write_ppp(hw, (void *)sec, (u16)section_size,
1298 track_id, &offset, &info, NULL);
1299 if (status) {
1300 i40e_debug(hw, I40E_DEBUG_PACKAGE,
1301 "Failed to write profile: offset %d, info %d",
1302 offset, info);
1303 break;
1304 }
1305 }
1306 return status;
1307}
1308
1309/**
1310 * i40evf_add_pinfo_to_list
1311 * @hw: pointer to the hardware structure
1312 * @profile: pointer to the profile segment of the package
1313 * @profile_info_sec: buffer for information section
1314 * @track_id: package tracking id
1315 *
1316 * Register a profile to the list of loaded profiles.
1317 */
1318enum i40e_status_code
1319i40evf_add_pinfo_to_list(struct i40e_hw *hw,
1320 struct i40e_profile_segment *profile,
1321 u8 *profile_info_sec, u32 track_id)
1322{
1323 i40e_status status = 0;
1324 struct i40e_profile_section_header *sec = NULL;
1325 struct i40e_profile_info *pinfo;
1326 u32 offset = 0, info = 0;
1327
1328 sec = (struct i40e_profile_section_header *)profile_info_sec;
1329 sec->tbl_size = 1;
1330 sec->data_end = sizeof(struct i40e_profile_section_header) +
1331 sizeof(struct i40e_profile_info);
1332 sec->section.type = SECTION_TYPE_INFO;
1333 sec->section.offset = sizeof(struct i40e_profile_section_header);
1334 sec->section.size = sizeof(struct i40e_profile_info);
1335 pinfo = (struct i40e_profile_info *)(profile_info_sec +
1336 sec->section.offset);
1337 pinfo->track_id = track_id;
1338 pinfo->version = profile->version;
1339 pinfo->op = I40E_PPP_ADD_TRACKID;
1340 memcpy(pinfo->name, profile->name, I40E_PPP_NAME_SIZE);
1341
1342 status = i40evf_aq_write_ppp(hw, (void *)sec, sec->data_end,
1343 track_id, &offset, &info, NULL);
1344 return status;
1345}