blob: 7346d8850c8e80b0e3c45a7ba6b038462121c4cc [file] [log] [blame]
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Shannon Nelson67be6eb2016-01-13 16:51:40 -08004 * Copyright(c) 2013 - 2016 Intel Corporation.
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +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 *
Greg Rosedc641b72013-12-18 13:45:51 +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/>.
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +000017 *
18 * 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 Brandeburg55cdfd42017-05-11 11:23:10 -070030#include <linux/avf/virtchnl.h>
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +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 **/
39static i40e_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:
Mitch Williams5960d332014-09-13 07:40:47 +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:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +000058 hw->mac.type = I40E_MAC_XL710;
59 break;
Anjali Singhai Jain35dae512015-12-22 14:25:03 -080060 case I40E_DEV_ID_KX_X722:
61 case I40E_DEV_ID_QSFP_X722:
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -040062 case I40E_DEV_ID_SFP_X722:
63 case I40E_DEV_ID_1G_BASE_T_X722:
64 case I40E_DEV_ID_10G_BASE_T_X722:
Catherine Sullivand6bf58c2016-03-18 12:18:08 -070065 case I40E_DEV_ID_SFP_I_X722:
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -040066 hw->mac.type = I40E_MAC_X722;
67 break;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +000068 default:
69 hw->mac.type = I40E_MAC_GENERIC;
70 break;
71 }
72 } else {
73 status = I40E_ERR_DEVICE_NOT_SUPPORTED;
74 }
75
76 hw_dbg(hw, "i40e_set_mac_type found mac: %d, returns: %d\n",
77 hw->mac.type, status);
78 return status;
79}
80
81/**
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040082 * i40e_aq_str - convert AQ err code to a string
83 * @hw: pointer to the HW structure
84 * @aq_err: the AQ error code to convert
85 **/
Jingjing Wu4e68adfe2015-09-28 14:12:31 -040086const char *i40e_aq_str(struct i40e_hw *hw, enum i40e_admin_queue_err aq_err)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040087{
88 switch (aq_err) {
89 case I40E_AQ_RC_OK:
90 return "OK";
91 case I40E_AQ_RC_EPERM:
92 return "I40E_AQ_RC_EPERM";
93 case I40E_AQ_RC_ENOENT:
94 return "I40E_AQ_RC_ENOENT";
95 case I40E_AQ_RC_ESRCH:
96 return "I40E_AQ_RC_ESRCH";
97 case I40E_AQ_RC_EINTR:
98 return "I40E_AQ_RC_EINTR";
99 case I40E_AQ_RC_EIO:
100 return "I40E_AQ_RC_EIO";
101 case I40E_AQ_RC_ENXIO:
102 return "I40E_AQ_RC_ENXIO";
103 case I40E_AQ_RC_E2BIG:
104 return "I40E_AQ_RC_E2BIG";
105 case I40E_AQ_RC_EAGAIN:
106 return "I40E_AQ_RC_EAGAIN";
107 case I40E_AQ_RC_ENOMEM:
108 return "I40E_AQ_RC_ENOMEM";
109 case I40E_AQ_RC_EACCES:
110 return "I40E_AQ_RC_EACCES";
111 case I40E_AQ_RC_EFAULT:
112 return "I40E_AQ_RC_EFAULT";
113 case I40E_AQ_RC_EBUSY:
114 return "I40E_AQ_RC_EBUSY";
115 case I40E_AQ_RC_EEXIST:
116 return "I40E_AQ_RC_EEXIST";
117 case I40E_AQ_RC_EINVAL:
118 return "I40E_AQ_RC_EINVAL";
119 case I40E_AQ_RC_ENOTTY:
120 return "I40E_AQ_RC_ENOTTY";
121 case I40E_AQ_RC_ENOSPC:
122 return "I40E_AQ_RC_ENOSPC";
123 case I40E_AQ_RC_ENOSYS:
124 return "I40E_AQ_RC_ENOSYS";
125 case I40E_AQ_RC_ERANGE:
126 return "I40E_AQ_RC_ERANGE";
127 case I40E_AQ_RC_EFLUSHED:
128 return "I40E_AQ_RC_EFLUSHED";
129 case I40E_AQ_RC_BAD_ADDR:
130 return "I40E_AQ_RC_BAD_ADDR";
131 case I40E_AQ_RC_EMODE:
132 return "I40E_AQ_RC_EMODE";
133 case I40E_AQ_RC_EFBIG:
134 return "I40E_AQ_RC_EFBIG";
135 }
136
137 snprintf(hw->err_str, sizeof(hw->err_str), "%d", aq_err);
138 return hw->err_str;
139}
140
141/**
142 * i40e_stat_str - convert status err code to a string
143 * @hw: pointer to the HW structure
144 * @stat_err: the status error code to convert
145 **/
Jingjing Wu4e68adfe2015-09-28 14:12:31 -0400146const char *i40e_stat_str(struct i40e_hw *hw, i40e_status stat_err)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400147{
148 switch (stat_err) {
149 case 0:
150 return "OK";
151 case I40E_ERR_NVM:
152 return "I40E_ERR_NVM";
153 case I40E_ERR_NVM_CHECKSUM:
154 return "I40E_ERR_NVM_CHECKSUM";
155 case I40E_ERR_PHY:
156 return "I40E_ERR_PHY";
157 case I40E_ERR_CONFIG:
158 return "I40E_ERR_CONFIG";
159 case I40E_ERR_PARAM:
160 return "I40E_ERR_PARAM";
161 case I40E_ERR_MAC_TYPE:
162 return "I40E_ERR_MAC_TYPE";
163 case I40E_ERR_UNKNOWN_PHY:
164 return "I40E_ERR_UNKNOWN_PHY";
165 case I40E_ERR_LINK_SETUP:
166 return "I40E_ERR_LINK_SETUP";
167 case I40E_ERR_ADAPTER_STOPPED:
168 return "I40E_ERR_ADAPTER_STOPPED";
169 case I40E_ERR_INVALID_MAC_ADDR:
170 return "I40E_ERR_INVALID_MAC_ADDR";
171 case I40E_ERR_DEVICE_NOT_SUPPORTED:
172 return "I40E_ERR_DEVICE_NOT_SUPPORTED";
173 case I40E_ERR_MASTER_REQUESTS_PENDING:
174 return "I40E_ERR_MASTER_REQUESTS_PENDING";
175 case I40E_ERR_INVALID_LINK_SETTINGS:
176 return "I40E_ERR_INVALID_LINK_SETTINGS";
177 case I40E_ERR_AUTONEG_NOT_COMPLETE:
178 return "I40E_ERR_AUTONEG_NOT_COMPLETE";
179 case I40E_ERR_RESET_FAILED:
180 return "I40E_ERR_RESET_FAILED";
181 case I40E_ERR_SWFW_SYNC:
182 return "I40E_ERR_SWFW_SYNC";
183 case I40E_ERR_NO_AVAILABLE_VSI:
184 return "I40E_ERR_NO_AVAILABLE_VSI";
185 case I40E_ERR_NO_MEMORY:
186 return "I40E_ERR_NO_MEMORY";
187 case I40E_ERR_BAD_PTR:
188 return "I40E_ERR_BAD_PTR";
189 case I40E_ERR_RING_FULL:
190 return "I40E_ERR_RING_FULL";
191 case I40E_ERR_INVALID_PD_ID:
192 return "I40E_ERR_INVALID_PD_ID";
193 case I40E_ERR_INVALID_QP_ID:
194 return "I40E_ERR_INVALID_QP_ID";
195 case I40E_ERR_INVALID_CQ_ID:
196 return "I40E_ERR_INVALID_CQ_ID";
197 case I40E_ERR_INVALID_CEQ_ID:
198 return "I40E_ERR_INVALID_CEQ_ID";
199 case I40E_ERR_INVALID_AEQ_ID:
200 return "I40E_ERR_INVALID_AEQ_ID";
201 case I40E_ERR_INVALID_SIZE:
202 return "I40E_ERR_INVALID_SIZE";
203 case I40E_ERR_INVALID_ARP_INDEX:
204 return "I40E_ERR_INVALID_ARP_INDEX";
205 case I40E_ERR_INVALID_FPM_FUNC_ID:
206 return "I40E_ERR_INVALID_FPM_FUNC_ID";
207 case I40E_ERR_QP_INVALID_MSG_SIZE:
208 return "I40E_ERR_QP_INVALID_MSG_SIZE";
209 case I40E_ERR_QP_TOOMANY_WRS_POSTED:
210 return "I40E_ERR_QP_TOOMANY_WRS_POSTED";
211 case I40E_ERR_INVALID_FRAG_COUNT:
212 return "I40E_ERR_INVALID_FRAG_COUNT";
213 case I40E_ERR_QUEUE_EMPTY:
214 return "I40E_ERR_QUEUE_EMPTY";
215 case I40E_ERR_INVALID_ALIGNMENT:
216 return "I40E_ERR_INVALID_ALIGNMENT";
217 case I40E_ERR_FLUSHED_QUEUE:
218 return "I40E_ERR_FLUSHED_QUEUE";
219 case I40E_ERR_INVALID_PUSH_PAGE_INDEX:
220 return "I40E_ERR_INVALID_PUSH_PAGE_INDEX";
221 case I40E_ERR_INVALID_IMM_DATA_SIZE:
222 return "I40E_ERR_INVALID_IMM_DATA_SIZE";
223 case I40E_ERR_TIMEOUT:
224 return "I40E_ERR_TIMEOUT";
225 case I40E_ERR_OPCODE_MISMATCH:
226 return "I40E_ERR_OPCODE_MISMATCH";
227 case I40E_ERR_CQP_COMPL_ERROR:
228 return "I40E_ERR_CQP_COMPL_ERROR";
229 case I40E_ERR_INVALID_VF_ID:
230 return "I40E_ERR_INVALID_VF_ID";
231 case I40E_ERR_INVALID_HMCFN_ID:
232 return "I40E_ERR_INVALID_HMCFN_ID";
233 case I40E_ERR_BACKING_PAGE_ERROR:
234 return "I40E_ERR_BACKING_PAGE_ERROR";
235 case I40E_ERR_NO_PBLCHUNKS_AVAILABLE:
236 return "I40E_ERR_NO_PBLCHUNKS_AVAILABLE";
237 case I40E_ERR_INVALID_PBLE_INDEX:
238 return "I40E_ERR_INVALID_PBLE_INDEX";
239 case I40E_ERR_INVALID_SD_INDEX:
240 return "I40E_ERR_INVALID_SD_INDEX";
241 case I40E_ERR_INVALID_PAGE_DESC_INDEX:
242 return "I40E_ERR_INVALID_PAGE_DESC_INDEX";
243 case I40E_ERR_INVALID_SD_TYPE:
244 return "I40E_ERR_INVALID_SD_TYPE";
245 case I40E_ERR_MEMCPY_FAILED:
246 return "I40E_ERR_MEMCPY_FAILED";
247 case I40E_ERR_INVALID_HMC_OBJ_INDEX:
248 return "I40E_ERR_INVALID_HMC_OBJ_INDEX";
249 case I40E_ERR_INVALID_HMC_OBJ_COUNT:
250 return "I40E_ERR_INVALID_HMC_OBJ_COUNT";
251 case I40E_ERR_INVALID_SRQ_ARM_LIMIT:
252 return "I40E_ERR_INVALID_SRQ_ARM_LIMIT";
253 case I40E_ERR_SRQ_ENABLED:
254 return "I40E_ERR_SRQ_ENABLED";
255 case I40E_ERR_ADMIN_QUEUE_ERROR:
256 return "I40E_ERR_ADMIN_QUEUE_ERROR";
257 case I40E_ERR_ADMIN_QUEUE_TIMEOUT:
258 return "I40E_ERR_ADMIN_QUEUE_TIMEOUT";
259 case I40E_ERR_BUF_TOO_SHORT:
260 return "I40E_ERR_BUF_TOO_SHORT";
261 case I40E_ERR_ADMIN_QUEUE_FULL:
262 return "I40E_ERR_ADMIN_QUEUE_FULL";
263 case I40E_ERR_ADMIN_QUEUE_NO_WORK:
264 return "I40E_ERR_ADMIN_QUEUE_NO_WORK";
265 case I40E_ERR_BAD_IWARP_CQE:
266 return "I40E_ERR_BAD_IWARP_CQE";
267 case I40E_ERR_NVM_BLANK_MODE:
268 return "I40E_ERR_NVM_BLANK_MODE";
269 case I40E_ERR_NOT_IMPLEMENTED:
270 return "I40E_ERR_NOT_IMPLEMENTED";
271 case I40E_ERR_PE_DOORBELL_NOT_ENABLED:
272 return "I40E_ERR_PE_DOORBELL_NOT_ENABLED";
273 case I40E_ERR_DIAG_TEST_FAILED:
274 return "I40E_ERR_DIAG_TEST_FAILED";
275 case I40E_ERR_NOT_READY:
276 return "I40E_ERR_NOT_READY";
277 case I40E_NOT_SUPPORTED:
278 return "I40E_NOT_SUPPORTED";
279 case I40E_ERR_FIRMWARE_API_VERSION:
280 return "I40E_ERR_FIRMWARE_API_VERSION";
281 }
282
283 snprintf(hw->err_str, sizeof(hw->err_str), "%d", stat_err);
284 return hw->err_str;
285}
286
287/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000288 * i40e_debug_aq
289 * @hw: debug mask related to admin queue
Jeff Kirsher98d44382013-12-21 05:44:42 +0000290 * @mask: debug mask
291 * @desc: pointer to admin queue descriptor
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000292 * @buffer: pointer to command buffer
Shannon Nelsonf905dd62014-07-10 07:58:20 +0000293 * @buf_len: max length of buffer
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000294 *
295 * Dumps debug log about adminq command with descriptor contents.
296 **/
297void i40e_debug_aq(struct i40e_hw *hw, enum i40e_debug_mask mask, void *desc,
Shannon Nelsonf905dd62014-07-10 07:58:20 +0000298 void *buffer, u16 buf_len)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000299{
300 struct i40e_aq_desc *aq_desc = (struct i40e_aq_desc *)desc;
Heinrich Schuchardtcd956722016-05-17 22:41:33 +0200301 u16 len;
Shannon Nelson37a29732015-02-27 09:15:19 +0000302 u8 *buf = (u8 *)buffer;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000303
304 if ((!(mask & hw->debug_mask)) || (desc == NULL))
305 return;
306
Heinrich Schuchardtcd956722016-05-17 22:41:33 +0200307 len = le16_to_cpu(aq_desc->datalen);
308
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000309 i40e_debug(hw, mask,
310 "AQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000311 le16_to_cpu(aq_desc->opcode),
312 le16_to_cpu(aq_desc->flags),
313 le16_to_cpu(aq_desc->datalen),
314 le16_to_cpu(aq_desc->retval));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000315 i40e_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000316 le32_to_cpu(aq_desc->cookie_high),
317 le32_to_cpu(aq_desc->cookie_low));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000318 i40e_debug(hw, mask, "\tparam (0,1) 0x%08X 0x%08X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000319 le32_to_cpu(aq_desc->params.internal.param0),
320 le32_to_cpu(aq_desc->params.internal.param1));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000321 i40e_debug(hw, mask, "\taddr (h,l) 0x%08X 0x%08X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000322 le32_to_cpu(aq_desc->params.external.addr_high),
323 le32_to_cpu(aq_desc->params.external.addr_low));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000324
325 if ((buffer != NULL) && (aq_desc->datalen != 0)) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000326 i40e_debug(hw, mask, "AQ CMD Buffer:\n");
Shannon Nelsonf905dd62014-07-10 07:58:20 +0000327 if (buf_len < len)
328 len = buf_len;
Shannon Nelson37a29732015-02-27 09:15:19 +0000329 /* write the full 16-byte chunks */
Alan Brady773d4022016-12-12 15:44:13 -0800330 if (hw->debug_mask & mask) {
Jacob Kellerb5d55042017-07-12 05:46:09 -0400331 char prefix[27];
Alan Brady773d4022016-12-12 15:44:13 -0800332
Jacob Kellerb5d55042017-07-12 05:46:09 -0400333 snprintf(prefix, sizeof(prefix),
Alan Brady773d4022016-12-12 15:44:13 -0800334 "i40e %02x:%02x.%x: \t0x",
335 hw->bus.bus_id,
336 hw->bus.device,
337 hw->bus.func);
338
339 print_hex_dump(KERN_INFO, prefix, DUMP_PREFIX_OFFSET,
340 16, 1, buf, len, false);
341 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000342 }
343}
344
345/**
Anjali Singhai Jaine1860d82013-11-28 06:39:45 +0000346 * i40e_check_asq_alive
347 * @hw: pointer to the hw struct
348 *
349 * Returns true if Queue is enabled else false.
350 **/
351bool i40e_check_asq_alive(struct i40e_hw *hw)
352{
Kevin Scott8b833b42014-04-09 05:58:54 +0000353 if (hw->aq.asq.len)
354 return !!(rd32(hw, hw->aq.asq.len) &
355 I40E_PF_ATQLEN_ATQENABLE_MASK);
356 else
357 return false;
Anjali Singhai Jaine1860d82013-11-28 06:39:45 +0000358}
359
360/**
361 * i40e_aq_queue_shutdown
362 * @hw: pointer to the hw struct
363 * @unloading: is the driver unloading itself
364 *
365 * Tell the Firmware that we're shutting down the AdminQ and whether
366 * or not the driver is unloading as well.
367 **/
368i40e_status i40e_aq_queue_shutdown(struct i40e_hw *hw,
369 bool unloading)
370{
371 struct i40e_aq_desc desc;
372 struct i40e_aqc_queue_shutdown *cmd =
373 (struct i40e_aqc_queue_shutdown *)&desc.params.raw;
374 i40e_status status;
375
376 i40e_fill_default_direct_cmd_desc(&desc,
377 i40e_aqc_opc_queue_shutdown);
378
379 if (unloading)
380 cmd->driver_unloading = cpu_to_le32(I40E_AQ_DRIVER_UNLOADING);
381 status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
382
383 return status;
384}
385
Anjali Singhai Jaine50c8d62015-06-05 12:20:27 -0400386/**
387 * i40e_aq_get_set_rss_lut
388 * @hw: pointer to the hardware structure
389 * @vsi_id: vsi fw index
390 * @pf_lut: for PF table set true, for VSI table set false
391 * @lut: pointer to the lut buffer provided by the caller
392 * @lut_size: size of the lut buffer
393 * @set: set true to set the table, false to get the table
394 *
395 * Internal function to get or set RSS look up table
396 **/
397static i40e_status i40e_aq_get_set_rss_lut(struct i40e_hw *hw,
398 u16 vsi_id, bool pf_lut,
399 u8 *lut, u16 lut_size,
400 bool set)
401{
402 i40e_status status;
403 struct i40e_aq_desc desc;
404 struct i40e_aqc_get_set_rss_lut *cmd_resp =
405 (struct i40e_aqc_get_set_rss_lut *)&desc.params.raw;
406
407 if (set)
408 i40e_fill_default_direct_cmd_desc(&desc,
409 i40e_aqc_opc_set_rss_lut);
410 else
411 i40e_fill_default_direct_cmd_desc(&desc,
412 i40e_aqc_opc_get_rss_lut);
413
414 /* Indirect command */
415 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
416 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
417
418 cmd_resp->vsi_id =
419 cpu_to_le16((u16)((vsi_id <<
420 I40E_AQC_SET_RSS_LUT_VSI_ID_SHIFT) &
421 I40E_AQC_SET_RSS_LUT_VSI_ID_MASK));
422 cmd_resp->vsi_id |= cpu_to_le16((u16)I40E_AQC_SET_RSS_LUT_VSI_VALID);
423
424 if (pf_lut)
425 cmd_resp->flags |= cpu_to_le16((u16)
426 ((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_PF <<
427 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
428 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
429 else
430 cmd_resp->flags |= cpu_to_le16((u16)
431 ((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_VSI <<
432 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
433 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
434
Anjali Singhai Jaine50c8d62015-06-05 12:20:27 -0400435 status = i40e_asq_send_command(hw, &desc, lut, lut_size, NULL);
436
437 return status;
438}
439
440/**
441 * i40e_aq_get_rss_lut
442 * @hw: pointer to the hardware structure
443 * @vsi_id: vsi fw index
444 * @pf_lut: for PF table set true, for VSI table set false
445 * @lut: pointer to the lut buffer provided by the caller
446 * @lut_size: size of the lut buffer
447 *
448 * get the RSS lookup table, PF or VSI type
449 **/
450i40e_status i40e_aq_get_rss_lut(struct i40e_hw *hw, u16 vsi_id,
451 bool pf_lut, u8 *lut, u16 lut_size)
452{
453 return i40e_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size,
454 false);
455}
456
457/**
458 * i40e_aq_set_rss_lut
459 * @hw: pointer to the hardware structure
460 * @vsi_id: vsi fw index
461 * @pf_lut: for PF table set true, for VSI table set false
462 * @lut: pointer to the lut buffer provided by the caller
463 * @lut_size: size of the lut buffer
464 *
465 * set the RSS lookup table, PF or VSI type
466 **/
467i40e_status i40e_aq_set_rss_lut(struct i40e_hw *hw, u16 vsi_id,
468 bool pf_lut, u8 *lut, u16 lut_size)
469{
470 return i40e_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size, true);
471}
472
473/**
474 * i40e_aq_get_set_rss_key
475 * @hw: pointer to the hw struct
476 * @vsi_id: vsi fw index
477 * @key: pointer to key info struct
478 * @set: set true to set the key, false to get the key
479 *
480 * get the RSS key per VSI
481 **/
482static i40e_status i40e_aq_get_set_rss_key(struct i40e_hw *hw,
483 u16 vsi_id,
484 struct i40e_aqc_get_set_rss_key_data *key,
485 bool set)
486{
487 i40e_status status;
488 struct i40e_aq_desc desc;
489 struct i40e_aqc_get_set_rss_key *cmd_resp =
490 (struct i40e_aqc_get_set_rss_key *)&desc.params.raw;
491 u16 key_size = sizeof(struct i40e_aqc_get_set_rss_key_data);
492
493 if (set)
494 i40e_fill_default_direct_cmd_desc(&desc,
495 i40e_aqc_opc_set_rss_key);
496 else
497 i40e_fill_default_direct_cmd_desc(&desc,
498 i40e_aqc_opc_get_rss_key);
499
500 /* Indirect command */
501 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
502 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
503
504 cmd_resp->vsi_id =
505 cpu_to_le16((u16)((vsi_id <<
506 I40E_AQC_SET_RSS_KEY_VSI_ID_SHIFT) &
507 I40E_AQC_SET_RSS_KEY_VSI_ID_MASK));
508 cmd_resp->vsi_id |= cpu_to_le16((u16)I40E_AQC_SET_RSS_KEY_VSI_VALID);
Anjali Singhai Jaine50c8d62015-06-05 12:20:27 -0400509
510 status = i40e_asq_send_command(hw, &desc, key, key_size, NULL);
511
512 return status;
513}
514
515/**
516 * i40e_aq_get_rss_key
517 * @hw: pointer to the hw struct
518 * @vsi_id: vsi fw index
519 * @key: pointer to key info struct
520 *
521 **/
522i40e_status i40e_aq_get_rss_key(struct i40e_hw *hw,
523 u16 vsi_id,
524 struct i40e_aqc_get_set_rss_key_data *key)
525{
526 return i40e_aq_get_set_rss_key(hw, vsi_id, key, false);
527}
528
529/**
530 * i40e_aq_set_rss_key
531 * @hw: pointer to the hw struct
532 * @vsi_id: vsi fw index
533 * @key: pointer to key info struct
534 *
535 * set the RSS key per VSI
536 **/
537i40e_status i40e_aq_set_rss_key(struct i40e_hw *hw,
538 u16 vsi_id,
539 struct i40e_aqc_get_set_rss_key_data *key)
540{
541 return i40e_aq_get_set_rss_key(hw, vsi_id, key, true);
542}
543
Jesse Brandeburg206812b2014-02-12 01:45:33 +0000544/* The i40e_ptype_lookup table is used to convert from the 8-bit ptype in the
545 * hardware to a bit-field that can be used by SW to more easily determine the
546 * packet type.
547 *
548 * Macros are used to shorten the table lines and make this table human
549 * readable.
550 *
551 * We store the PTYPE in the top byte of the bit field - this is just so that
552 * we can check that the table doesn't have a row missing, as the index into
553 * the table should be the PTYPE.
554 *
555 * Typical work flow:
556 *
557 * IF NOT i40e_ptype_lookup[ptype].known
558 * THEN
559 * Packet is unknown
560 * ELSE IF i40e_ptype_lookup[ptype].outer_ip == I40E_RX_PTYPE_OUTER_IP
561 * Use the rest of the fields to look at the tunnels, inner protocols, etc
562 * ELSE
563 * Use the enum i40e_rx_l2_ptype to decode the packet type
564 * ENDIF
565 */
566
567/* macro to make the table lines short */
568#define I40E_PTT(PTYPE, OUTER_IP, OUTER_IP_VER, OUTER_FRAG, T, TE, TEF, I, PL)\
569 { PTYPE, \
570 1, \
571 I40E_RX_PTYPE_OUTER_##OUTER_IP, \
572 I40E_RX_PTYPE_OUTER_##OUTER_IP_VER, \
573 I40E_RX_PTYPE_##OUTER_FRAG, \
574 I40E_RX_PTYPE_TUNNEL_##T, \
575 I40E_RX_PTYPE_TUNNEL_END_##TE, \
576 I40E_RX_PTYPE_##TEF, \
577 I40E_RX_PTYPE_INNER_PROT_##I, \
578 I40E_RX_PTYPE_PAYLOAD_LAYER_##PL }
579
580#define I40E_PTT_UNUSED_ENTRY(PTYPE) \
581 { PTYPE, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
582
583/* shorter macros makes the table fit but are terse */
584#define I40E_RX_PTYPE_NOF I40E_RX_PTYPE_NOT_FRAG
585#define I40E_RX_PTYPE_FRG I40E_RX_PTYPE_FRAG
586#define I40E_RX_PTYPE_INNER_PROT_TS I40E_RX_PTYPE_INNER_PROT_TIMESYNC
587
588/* Lookup table mapping the HW PTYPE to the bit field for decoding */
589struct i40e_rx_ptype_decoded i40e_ptype_lookup[] = {
590 /* L2 Packet types */
591 I40E_PTT_UNUSED_ENTRY(0),
592 I40E_PTT(1, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
593 I40E_PTT(2, L2, NONE, NOF, NONE, NONE, NOF, TS, PAY2),
594 I40E_PTT(3, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
595 I40E_PTT_UNUSED_ENTRY(4),
596 I40E_PTT_UNUSED_ENTRY(5),
597 I40E_PTT(6, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
598 I40E_PTT(7, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
599 I40E_PTT_UNUSED_ENTRY(8),
600 I40E_PTT_UNUSED_ENTRY(9),
601 I40E_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
602 I40E_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
603 I40E_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
604 I40E_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
605 I40E_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
606 I40E_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
607 I40E_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
608 I40E_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
609 I40E_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
610 I40E_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
611 I40E_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
612 I40E_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
613
614 /* Non Tunneled IPv4 */
615 I40E_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
616 I40E_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
617 I40E_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP, PAY4),
618 I40E_PTT_UNUSED_ENTRY(25),
619 I40E_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP, PAY4),
620 I40E_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
621 I40E_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
622
623 /* IPv4 --> IPv4 */
624 I40E_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
625 I40E_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
626 I40E_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
627 I40E_PTT_UNUSED_ENTRY(32),
628 I40E_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
629 I40E_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
630 I40E_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
631
632 /* IPv4 --> IPv6 */
633 I40E_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
634 I40E_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
635 I40E_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
636 I40E_PTT_UNUSED_ENTRY(39),
637 I40E_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
638 I40E_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
639 I40E_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
640
641 /* IPv4 --> GRE/NAT */
642 I40E_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
643
644 /* IPv4 --> GRE/NAT --> IPv4 */
645 I40E_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
646 I40E_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
647 I40E_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
648 I40E_PTT_UNUSED_ENTRY(47),
649 I40E_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
650 I40E_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
651 I40E_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
652
653 /* IPv4 --> GRE/NAT --> IPv6 */
654 I40E_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
655 I40E_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
656 I40E_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
657 I40E_PTT_UNUSED_ENTRY(54),
658 I40E_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
659 I40E_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
660 I40E_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
661
662 /* IPv4 --> GRE/NAT --> MAC */
663 I40E_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
664
665 /* IPv4 --> GRE/NAT --> MAC --> IPv4 */
666 I40E_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
667 I40E_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
668 I40E_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
669 I40E_PTT_UNUSED_ENTRY(62),
670 I40E_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
671 I40E_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
672 I40E_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
673
674 /* IPv4 --> GRE/NAT -> MAC --> IPv6 */
675 I40E_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
676 I40E_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
677 I40E_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
678 I40E_PTT_UNUSED_ENTRY(69),
679 I40E_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
680 I40E_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
681 I40E_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
682
683 /* IPv4 --> GRE/NAT --> MAC/VLAN */
684 I40E_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
685
686 /* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
687 I40E_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
688 I40E_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
689 I40E_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
690 I40E_PTT_UNUSED_ENTRY(77),
691 I40E_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
692 I40E_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
693 I40E_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
694
695 /* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
696 I40E_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
697 I40E_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
698 I40E_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
699 I40E_PTT_UNUSED_ENTRY(84),
700 I40E_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
701 I40E_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
702 I40E_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
703
704 /* Non Tunneled IPv6 */
705 I40E_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
706 I40E_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
Akeem G Abodunrin73df8c92016-05-03 15:13:16 -0700707 I40E_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP, PAY4),
Jesse Brandeburg206812b2014-02-12 01:45:33 +0000708 I40E_PTT_UNUSED_ENTRY(91),
709 I40E_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP, PAY4),
710 I40E_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
711 I40E_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
712
713 /* IPv6 --> IPv4 */
714 I40E_PTT(95, IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
715 I40E_PTT(96, IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
716 I40E_PTT(97, IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
717 I40E_PTT_UNUSED_ENTRY(98),
718 I40E_PTT(99, IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
719 I40E_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
720 I40E_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
721
722 /* IPv6 --> IPv6 */
723 I40E_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
724 I40E_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
725 I40E_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
726 I40E_PTT_UNUSED_ENTRY(105),
727 I40E_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
728 I40E_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
729 I40E_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
730
731 /* IPv6 --> GRE/NAT */
732 I40E_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
733
734 /* IPv6 --> GRE/NAT -> IPv4 */
735 I40E_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
736 I40E_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
737 I40E_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
738 I40E_PTT_UNUSED_ENTRY(113),
739 I40E_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
740 I40E_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
741 I40E_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
742
743 /* IPv6 --> GRE/NAT -> IPv6 */
744 I40E_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
745 I40E_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
746 I40E_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
747 I40E_PTT_UNUSED_ENTRY(120),
748 I40E_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
749 I40E_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
750 I40E_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
751
752 /* IPv6 --> GRE/NAT -> MAC */
753 I40E_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
754
755 /* IPv6 --> GRE/NAT -> MAC -> IPv4 */
756 I40E_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
757 I40E_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
758 I40E_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
759 I40E_PTT_UNUSED_ENTRY(128),
760 I40E_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
761 I40E_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
762 I40E_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
763
764 /* IPv6 --> GRE/NAT -> MAC -> IPv6 */
765 I40E_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
766 I40E_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
767 I40E_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
768 I40E_PTT_UNUSED_ENTRY(135),
769 I40E_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
770 I40E_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
771 I40E_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
772
773 /* IPv6 --> GRE/NAT -> MAC/VLAN */
774 I40E_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
775
776 /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
777 I40E_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
778 I40E_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
779 I40E_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
780 I40E_PTT_UNUSED_ENTRY(143),
781 I40E_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
782 I40E_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
783 I40E_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
784
785 /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
786 I40E_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
787 I40E_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
788 I40E_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
789 I40E_PTT_UNUSED_ENTRY(150),
790 I40E_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
791 I40E_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
792 I40E_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
793
794 /* unused entries */
795 I40E_PTT_UNUSED_ENTRY(154),
796 I40E_PTT_UNUSED_ENTRY(155),
797 I40E_PTT_UNUSED_ENTRY(156),
798 I40E_PTT_UNUSED_ENTRY(157),
799 I40E_PTT_UNUSED_ENTRY(158),
800 I40E_PTT_UNUSED_ENTRY(159),
801
802 I40E_PTT_UNUSED_ENTRY(160),
803 I40E_PTT_UNUSED_ENTRY(161),
804 I40E_PTT_UNUSED_ENTRY(162),
805 I40E_PTT_UNUSED_ENTRY(163),
806 I40E_PTT_UNUSED_ENTRY(164),
807 I40E_PTT_UNUSED_ENTRY(165),
808 I40E_PTT_UNUSED_ENTRY(166),
809 I40E_PTT_UNUSED_ENTRY(167),
810 I40E_PTT_UNUSED_ENTRY(168),
811 I40E_PTT_UNUSED_ENTRY(169),
812
813 I40E_PTT_UNUSED_ENTRY(170),
814 I40E_PTT_UNUSED_ENTRY(171),
815 I40E_PTT_UNUSED_ENTRY(172),
816 I40E_PTT_UNUSED_ENTRY(173),
817 I40E_PTT_UNUSED_ENTRY(174),
818 I40E_PTT_UNUSED_ENTRY(175),
819 I40E_PTT_UNUSED_ENTRY(176),
820 I40E_PTT_UNUSED_ENTRY(177),
821 I40E_PTT_UNUSED_ENTRY(178),
822 I40E_PTT_UNUSED_ENTRY(179),
823
824 I40E_PTT_UNUSED_ENTRY(180),
825 I40E_PTT_UNUSED_ENTRY(181),
826 I40E_PTT_UNUSED_ENTRY(182),
827 I40E_PTT_UNUSED_ENTRY(183),
828 I40E_PTT_UNUSED_ENTRY(184),
829 I40E_PTT_UNUSED_ENTRY(185),
830 I40E_PTT_UNUSED_ENTRY(186),
831 I40E_PTT_UNUSED_ENTRY(187),
832 I40E_PTT_UNUSED_ENTRY(188),
833 I40E_PTT_UNUSED_ENTRY(189),
834
835 I40E_PTT_UNUSED_ENTRY(190),
836 I40E_PTT_UNUSED_ENTRY(191),
837 I40E_PTT_UNUSED_ENTRY(192),
838 I40E_PTT_UNUSED_ENTRY(193),
839 I40E_PTT_UNUSED_ENTRY(194),
840 I40E_PTT_UNUSED_ENTRY(195),
841 I40E_PTT_UNUSED_ENTRY(196),
842 I40E_PTT_UNUSED_ENTRY(197),
843 I40E_PTT_UNUSED_ENTRY(198),
844 I40E_PTT_UNUSED_ENTRY(199),
845
846 I40E_PTT_UNUSED_ENTRY(200),
847 I40E_PTT_UNUSED_ENTRY(201),
848 I40E_PTT_UNUSED_ENTRY(202),
849 I40E_PTT_UNUSED_ENTRY(203),
850 I40E_PTT_UNUSED_ENTRY(204),
851 I40E_PTT_UNUSED_ENTRY(205),
852 I40E_PTT_UNUSED_ENTRY(206),
853 I40E_PTT_UNUSED_ENTRY(207),
854 I40E_PTT_UNUSED_ENTRY(208),
855 I40E_PTT_UNUSED_ENTRY(209),
856
857 I40E_PTT_UNUSED_ENTRY(210),
858 I40E_PTT_UNUSED_ENTRY(211),
859 I40E_PTT_UNUSED_ENTRY(212),
860 I40E_PTT_UNUSED_ENTRY(213),
861 I40E_PTT_UNUSED_ENTRY(214),
862 I40E_PTT_UNUSED_ENTRY(215),
863 I40E_PTT_UNUSED_ENTRY(216),
864 I40E_PTT_UNUSED_ENTRY(217),
865 I40E_PTT_UNUSED_ENTRY(218),
866 I40E_PTT_UNUSED_ENTRY(219),
867
868 I40E_PTT_UNUSED_ENTRY(220),
869 I40E_PTT_UNUSED_ENTRY(221),
870 I40E_PTT_UNUSED_ENTRY(222),
871 I40E_PTT_UNUSED_ENTRY(223),
872 I40E_PTT_UNUSED_ENTRY(224),
873 I40E_PTT_UNUSED_ENTRY(225),
874 I40E_PTT_UNUSED_ENTRY(226),
875 I40E_PTT_UNUSED_ENTRY(227),
876 I40E_PTT_UNUSED_ENTRY(228),
877 I40E_PTT_UNUSED_ENTRY(229),
878
879 I40E_PTT_UNUSED_ENTRY(230),
880 I40E_PTT_UNUSED_ENTRY(231),
881 I40E_PTT_UNUSED_ENTRY(232),
882 I40E_PTT_UNUSED_ENTRY(233),
883 I40E_PTT_UNUSED_ENTRY(234),
884 I40E_PTT_UNUSED_ENTRY(235),
885 I40E_PTT_UNUSED_ENTRY(236),
886 I40E_PTT_UNUSED_ENTRY(237),
887 I40E_PTT_UNUSED_ENTRY(238),
888 I40E_PTT_UNUSED_ENTRY(239),
889
890 I40E_PTT_UNUSED_ENTRY(240),
891 I40E_PTT_UNUSED_ENTRY(241),
892 I40E_PTT_UNUSED_ENTRY(242),
893 I40E_PTT_UNUSED_ENTRY(243),
894 I40E_PTT_UNUSED_ENTRY(244),
895 I40E_PTT_UNUSED_ENTRY(245),
896 I40E_PTT_UNUSED_ENTRY(246),
897 I40E_PTT_UNUSED_ENTRY(247),
898 I40E_PTT_UNUSED_ENTRY(248),
899 I40E_PTT_UNUSED_ENTRY(249),
900
901 I40E_PTT_UNUSED_ENTRY(250),
902 I40E_PTT_UNUSED_ENTRY(251),
903 I40E_PTT_UNUSED_ENTRY(252),
904 I40E_PTT_UNUSED_ENTRY(253),
905 I40E_PTT_UNUSED_ENTRY(254),
906 I40E_PTT_UNUSED_ENTRY(255)
907};
908
Anjali Singhai Jaine1860d82013-11-28 06:39:45 +0000909/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000910 * i40e_init_shared_code - Initialize the shared code
911 * @hw: pointer to hardware structure
912 *
913 * This assigns the MAC type and PHY code and inits the NVM.
914 * Does not touch the hardware. This function must be called prior to any
915 * other function in the shared code. The i40e_hw structure should be
916 * memset to 0 prior to calling this function. The following fields in
917 * hw structure should be filled in prior to calling this function:
918 * hw_addr, back, device_id, vendor_id, subsystem_device_id,
919 * subsystem_vendor_id, and revision_id
920 **/
921i40e_status i40e_init_shared_code(struct i40e_hw *hw)
922{
923 i40e_status status = 0;
Shannon Nelson5fb11d72014-11-13 03:06:19 +0000924 u32 port, ari, func_rid;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000925
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000926 i40e_set_mac_type(hw);
927
928 switch (hw->mac.type) {
929 case I40E_MAC_XL710:
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -0400930 case I40E_MAC_X722:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000931 break;
932 default:
933 return I40E_ERR_DEVICE_NOT_SUPPORTED;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000934 }
935
Shannon Nelsonaf89d26c2013-12-11 08:17:14 +0000936 hw->phy.get_link_info = true;
937
Shannon Nelson5fb11d72014-11-13 03:06:19 +0000938 /* Determine port number and PF number*/
939 port = (rd32(hw, I40E_PFGEN_PORTNUM) & I40E_PFGEN_PORTNUM_PORT_NUM_MASK)
940 >> I40E_PFGEN_PORTNUM_PORT_NUM_SHIFT;
941 hw->port = (u8)port;
942 ari = (rd32(hw, I40E_GLPCI_CAPSUP) & I40E_GLPCI_CAPSUP_ARI_EN_MASK) >>
943 I40E_GLPCI_CAPSUP_ARI_EN_SHIFT;
944 func_rid = rd32(hw, I40E_PF_FUNC_RID);
945 if (ari)
946 hw->pf_id = (u8)(func_rid & 0xff);
Shannon Nelson5f9116a2013-12-11 08:17:13 +0000947 else
Shannon Nelson5fb11d72014-11-13 03:06:19 +0000948 hw->pf_id = (u8)(func_rid & 0x7);
Shannon Nelson5f9116a2013-12-11 08:17:13 +0000949
Anjali Singhai07f89be2015-09-24 15:26:32 -0700950 if (hw->mac.type == I40E_MAC_X722)
951 hw->flags |= I40E_HW_FLAG_AQ_SRCTL_ACCESS_ENABLE;
952
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000953 status = i40e_init_nvm(hw);
954 return status;
955}
956
957/**
958 * i40e_aq_mac_address_read - Retrieve the MAC addresses
959 * @hw: pointer to the hw struct
960 * @flags: a return indicator of what addresses were added to the addr store
961 * @addrs: the requestor's mac addr store
962 * @cmd_details: pointer to command details structure or NULL
963 **/
964static i40e_status i40e_aq_mac_address_read(struct i40e_hw *hw,
965 u16 *flags,
966 struct i40e_aqc_mac_address_read_data *addrs,
967 struct i40e_asq_cmd_details *cmd_details)
968{
969 struct i40e_aq_desc desc;
970 struct i40e_aqc_mac_address_read *cmd_data =
971 (struct i40e_aqc_mac_address_read *)&desc.params.raw;
972 i40e_status status;
973
974 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_mac_address_read);
975 desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF);
976
977 status = i40e_asq_send_command(hw, &desc, addrs,
978 sizeof(*addrs), cmd_details);
979 *flags = le16_to_cpu(cmd_data->command_flags);
980
981 return status;
982}
983
984/**
985 * i40e_aq_mac_address_write - Change the MAC addresses
986 * @hw: pointer to the hw struct
987 * @flags: indicates which MAC to be written
988 * @mac_addr: address to write
989 * @cmd_details: pointer to command details structure or NULL
990 **/
991i40e_status i40e_aq_mac_address_write(struct i40e_hw *hw,
992 u16 flags, u8 *mac_addr,
993 struct i40e_asq_cmd_details *cmd_details)
994{
995 struct i40e_aq_desc desc;
996 struct i40e_aqc_mac_address_write *cmd_data =
997 (struct i40e_aqc_mac_address_write *)&desc.params.raw;
998 i40e_status status;
999
1000 i40e_fill_default_direct_cmd_desc(&desc,
1001 i40e_aqc_opc_mac_address_write);
1002 cmd_data->command_flags = cpu_to_le16(flags);
Kamil Krawczyk55c29c32013-12-18 13:45:52 +00001003 cmd_data->mac_sah = cpu_to_le16((u16)mac_addr[0] << 8 | mac_addr[1]);
1004 cmd_data->mac_sal = cpu_to_le32(((u32)mac_addr[2] << 24) |
1005 ((u32)mac_addr[3] << 16) |
1006 ((u32)mac_addr[4] << 8) |
1007 mac_addr[5]);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001008
1009 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1010
1011 return status;
1012}
1013
1014/**
1015 * i40e_get_mac_addr - get MAC address
1016 * @hw: pointer to the HW structure
1017 * @mac_addr: pointer to MAC address
1018 *
1019 * Reads the adapter's MAC address from register
1020 **/
1021i40e_status i40e_get_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
1022{
1023 struct i40e_aqc_mac_address_read_data addrs;
1024 i40e_status status;
1025 u16 flags = 0;
1026
1027 status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
1028
1029 if (flags & I40E_AQC_LAN_ADDR_VALID)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001030 ether_addr_copy(mac_addr, addrs.pf_lan_mac);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001031
1032 return status;
1033}
1034
1035/**
Neerav Parikh1f224ad2014-02-12 01:45:31 +00001036 * i40e_get_port_mac_addr - get Port MAC address
1037 * @hw: pointer to the HW structure
1038 * @mac_addr: pointer to Port MAC address
1039 *
1040 * Reads the adapter's Port MAC address
1041 **/
1042i40e_status i40e_get_port_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
1043{
1044 struct i40e_aqc_mac_address_read_data addrs;
1045 i40e_status status;
1046 u16 flags = 0;
1047
1048 status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
1049 if (status)
1050 return status;
1051
1052 if (flags & I40E_AQC_PORT_ADDR_VALID)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001053 ether_addr_copy(mac_addr, addrs.port_mac);
Neerav Parikh1f224ad2014-02-12 01:45:31 +00001054 else
1055 status = I40E_ERR_INVALID_MAC_ADDR;
1056
1057 return status;
1058}
1059
1060/**
Matt Jared351499ab2014-04-23 04:50:03 +00001061 * i40e_pre_tx_queue_cfg - pre tx queue configure
1062 * @hw: pointer to the HW structure
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00001063 * @queue: target PF queue index
Matt Jared351499ab2014-04-23 04:50:03 +00001064 * @enable: state change request
1065 *
1066 * Handles hw requirement to indicate intention to enable
1067 * or disable target queue.
1068 **/
1069void i40e_pre_tx_queue_cfg(struct i40e_hw *hw, u32 queue, bool enable)
1070{
Shannon Nelsondfb699f2014-05-22 06:32:28 +00001071 u32 abs_queue_idx = hw->func_caps.base_queue + queue;
Matt Jared351499ab2014-04-23 04:50:03 +00001072 u32 reg_block = 0;
Shannon Nelsondfb699f2014-05-22 06:32:28 +00001073 u32 reg_val;
Matt Jared351499ab2014-04-23 04:50:03 +00001074
Christopher Pau24a768c2014-06-04 20:41:59 +00001075 if (abs_queue_idx >= 128) {
Matt Jared351499ab2014-04-23 04:50:03 +00001076 reg_block = abs_queue_idx / 128;
Christopher Pau24a768c2014-06-04 20:41:59 +00001077 abs_queue_idx %= 128;
1078 }
Matt Jared351499ab2014-04-23 04:50:03 +00001079
1080 reg_val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
1081 reg_val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
1082 reg_val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
1083
1084 if (enable)
1085 reg_val |= I40E_GLLAN_TXPRE_QDIS_CLEAR_QDIS_MASK;
1086 else
1087 reg_val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
1088
1089 wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), reg_val);
1090}
1091
1092/**
Kamil Krawczyk18f680c2014-12-11 07:06:31 +00001093 * i40e_read_pba_string - Reads part number string from EEPROM
1094 * @hw: pointer to hardware structure
1095 * @pba_num: stores the part number string from the EEPROM
1096 * @pba_num_size: part number string buffer length
1097 *
1098 * Reads the part number string from the EEPROM.
1099 **/
1100i40e_status i40e_read_pba_string(struct i40e_hw *hw, u8 *pba_num,
1101 u32 pba_num_size)
1102{
1103 i40e_status status = 0;
1104 u16 pba_word = 0;
1105 u16 pba_size = 0;
1106 u16 pba_ptr = 0;
1107 u16 i = 0;
1108
1109 status = i40e_read_nvm_word(hw, I40E_SR_PBA_FLAGS, &pba_word);
1110 if (status || (pba_word != 0xFAFA)) {
1111 hw_dbg(hw, "Failed to read PBA flags or flag is invalid.\n");
1112 return status;
1113 }
1114
1115 status = i40e_read_nvm_word(hw, I40E_SR_PBA_BLOCK_PTR, &pba_ptr);
1116 if (status) {
1117 hw_dbg(hw, "Failed to read PBA Block pointer.\n");
1118 return status;
1119 }
1120
1121 status = i40e_read_nvm_word(hw, pba_ptr, &pba_size);
1122 if (status) {
1123 hw_dbg(hw, "Failed to read PBA Block size.\n");
1124 return status;
1125 }
1126
1127 /* Subtract one to get PBA word count (PBA Size word is included in
1128 * total size)
1129 */
1130 pba_size--;
1131 if (pba_num_size < (((u32)pba_size * 2) + 1)) {
1132 hw_dbg(hw, "Buffer to small for PBA data.\n");
1133 return I40E_ERR_PARAM;
1134 }
1135
1136 for (i = 0; i < pba_size; i++) {
1137 status = i40e_read_nvm_word(hw, (pba_ptr + 1) + i, &pba_word);
1138 if (status) {
1139 hw_dbg(hw, "Failed to read PBA Block word %d.\n", i);
1140 return status;
1141 }
1142
1143 pba_num[(i * 2)] = (pba_word >> 8) & 0xFF;
1144 pba_num[(i * 2) + 1] = pba_word & 0xFF;
1145 }
1146 pba_num[(pba_size * 2)] = '\0';
1147
1148 return status;
1149}
1150
1151/**
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001152 * i40e_get_media_type - Gets media type
1153 * @hw: pointer to the hardware structure
1154 **/
1155static enum i40e_media_type i40e_get_media_type(struct i40e_hw *hw)
1156{
1157 enum i40e_media_type media;
1158
1159 switch (hw->phy.link_info.phy_type) {
1160 case I40E_PHY_TYPE_10GBASE_SR:
1161 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +00001162 case I40E_PHY_TYPE_1000BASE_SX:
1163 case I40E_PHY_TYPE_1000BASE_LX:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001164 case I40E_PHY_TYPE_40GBASE_SR4:
1165 case I40E_PHY_TYPE_40GBASE_LR4:
Carolyn Wyborny31232372016-11-21 13:03:48 -08001166 case I40E_PHY_TYPE_25GBASE_LR:
1167 case I40E_PHY_TYPE_25GBASE_SR:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001168 media = I40E_MEDIA_TYPE_FIBER;
1169 break;
1170 case I40E_PHY_TYPE_100BASE_TX:
1171 case I40E_PHY_TYPE_1000BASE_T:
1172 case I40E_PHY_TYPE_10GBASE_T:
1173 media = I40E_MEDIA_TYPE_BASET;
1174 break;
1175 case I40E_PHY_TYPE_10GBASE_CR1_CU:
1176 case I40E_PHY_TYPE_40GBASE_CR4_CU:
1177 case I40E_PHY_TYPE_10GBASE_CR1:
1178 case I40E_PHY_TYPE_40GBASE_CR4:
1179 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +00001180 case I40E_PHY_TYPE_40GBASE_AOC:
1181 case I40E_PHY_TYPE_10GBASE_AOC:
Carolyn Wyborny31232372016-11-21 13:03:48 -08001182 case I40E_PHY_TYPE_25GBASE_CR:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001183 media = I40E_MEDIA_TYPE_DA;
1184 break;
1185 case I40E_PHY_TYPE_1000BASE_KX:
1186 case I40E_PHY_TYPE_10GBASE_KX4:
1187 case I40E_PHY_TYPE_10GBASE_KR:
1188 case I40E_PHY_TYPE_40GBASE_KR4:
Jesse Brandeburgae24b402015-03-27 00:12:09 -07001189 case I40E_PHY_TYPE_20GBASE_KR2:
Carolyn Wyborny31232372016-11-21 13:03:48 -08001190 case I40E_PHY_TYPE_25GBASE_KR:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001191 media = I40E_MEDIA_TYPE_BACKPLANE;
1192 break;
1193 case I40E_PHY_TYPE_SGMII:
1194 case I40E_PHY_TYPE_XAUI:
1195 case I40E_PHY_TYPE_XFI:
1196 case I40E_PHY_TYPE_XLAUI:
1197 case I40E_PHY_TYPE_XLPPI:
1198 default:
1199 media = I40E_MEDIA_TYPE_UNKNOWN;
1200 break;
1201 }
1202
1203 return media;
1204}
1205
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001206#define I40E_PF_RESET_WAIT_COUNT_A0 200
Akeem G Abodunrin8af580d2015-03-27 00:12:10 -07001207#define I40E_PF_RESET_WAIT_COUNT 200
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001208/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001209 * i40e_pf_reset - Reset the PF
1210 * @hw: pointer to the hardware structure
1211 *
1212 * Assuming someone else has triggered a global reset,
1213 * assure the global reset is complete and then reset the PF
1214 **/
1215i40e_status i40e_pf_reset(struct i40e_hw *hw)
1216{
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001217 u32 cnt = 0;
Shannon Nelson42794bd2013-12-11 08:17:10 +00001218 u32 cnt1 = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001219 u32 reg = 0;
1220 u32 grst_del;
1221
1222 /* Poll for Global Reset steady state in case of recent GRST.
1223 * The grst delay value is in 100ms units, and we'll wait a
1224 * couple counts longer to be sure we don't just miss the end.
1225 */
Shannon Nelsonde78fc52015-02-21 06:41:47 +00001226 grst_del = (rd32(hw, I40E_GLGEN_RSTCTL) &
1227 I40E_GLGEN_RSTCTL_GRSTDEL_MASK) >>
1228 I40E_GLGEN_RSTCTL_GRSTDEL_SHIFT;
Kevin Scott4d7cec02016-02-17 16:12:13 -08001229
1230 /* It can take upto 15 secs for GRST steady state.
1231 * Bump it to 16 secs max to be safe.
1232 */
1233 grst_del = grst_del * 20;
1234
1235 for (cnt = 0; cnt < grst_del; cnt++) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001236 reg = rd32(hw, I40E_GLGEN_RSTAT);
1237 if (!(reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK))
1238 break;
1239 msleep(100);
1240 }
1241 if (reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
1242 hw_dbg(hw, "Global reset polling failed to complete.\n");
1243 return I40E_ERR_RESET_FAILED;
1244 }
1245
Shannon Nelson42794bd2013-12-11 08:17:10 +00001246 /* Now Wait for the FW to be ready */
1247 for (cnt1 = 0; cnt1 < I40E_PF_RESET_WAIT_COUNT; cnt1++) {
1248 reg = rd32(hw, I40E_GLNVM_ULD);
1249 reg &= (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
1250 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK);
1251 if (reg == (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
1252 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK)) {
1253 hw_dbg(hw, "Core and Global modules ready %d\n", cnt1);
1254 break;
1255 }
1256 usleep_range(10000, 20000);
1257 }
1258 if (!(reg & (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
1259 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK))) {
1260 hw_dbg(hw, "wait for FW Reset complete timedout\n");
1261 hw_dbg(hw, "I40E_GLNVM_ULD = 0x%x\n", reg);
1262 return I40E_ERR_RESET_FAILED;
1263 }
1264
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001265 /* If there was a Global Reset in progress when we got here,
1266 * we don't need to do the PF Reset
1267 */
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001268 if (!cnt) {
1269 if (hw->revision_id == 0)
1270 cnt = I40E_PF_RESET_WAIT_COUNT_A0;
1271 else
1272 cnt = I40E_PF_RESET_WAIT_COUNT;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001273 reg = rd32(hw, I40E_PFGEN_CTRL);
1274 wr32(hw, I40E_PFGEN_CTRL,
1275 (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001276 for (; cnt; cnt--) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001277 reg = rd32(hw, I40E_PFGEN_CTRL);
1278 if (!(reg & I40E_PFGEN_CTRL_PFSWR_MASK))
1279 break;
1280 usleep_range(1000, 2000);
1281 }
1282 if (reg & I40E_PFGEN_CTRL_PFSWR_MASK) {
1283 hw_dbg(hw, "PF reset polling failed to complete.\n");
1284 return I40E_ERR_RESET_FAILED;
1285 }
1286 }
1287
1288 i40e_clear_pxe_mode(hw);
Shannon Nelson922680b2013-12-18 05:29:17 +00001289
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001290 return 0;
1291}
1292
1293/**
Shannon Nelson838d41d2014-06-04 20:41:27 +00001294 * i40e_clear_hw - clear out any left over hw state
1295 * @hw: pointer to the hw struct
1296 *
1297 * Clear queues and interrupts, typically called at init time,
1298 * but after the capabilities have been found so we know how many
1299 * queues and msix vectors have been allocated.
1300 **/
1301void i40e_clear_hw(struct i40e_hw *hw)
1302{
1303 u32 num_queues, base_queue;
1304 u32 num_pf_int;
1305 u32 num_vf_int;
1306 u32 num_vfs;
1307 u32 i, j;
1308 u32 val;
1309 u32 eol = 0x7ff;
1310
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00001311 /* get number of interrupts, queues, and VFs */
Shannon Nelson838d41d2014-06-04 20:41:27 +00001312 val = rd32(hw, I40E_GLPCI_CNF2);
1313 num_pf_int = (val & I40E_GLPCI_CNF2_MSI_X_PF_N_MASK) >>
1314 I40E_GLPCI_CNF2_MSI_X_PF_N_SHIFT;
1315 num_vf_int = (val & I40E_GLPCI_CNF2_MSI_X_VF_N_MASK) >>
1316 I40E_GLPCI_CNF2_MSI_X_VF_N_SHIFT;
1317
Shannon Nelson272cdaf22016-02-17 16:12:21 -08001318 val = rd32(hw, I40E_PFLAN_QALLOC);
Shannon Nelson838d41d2014-06-04 20:41:27 +00001319 base_queue = (val & I40E_PFLAN_QALLOC_FIRSTQ_MASK) >>
1320 I40E_PFLAN_QALLOC_FIRSTQ_SHIFT;
1321 j = (val & I40E_PFLAN_QALLOC_LASTQ_MASK) >>
1322 I40E_PFLAN_QALLOC_LASTQ_SHIFT;
1323 if (val & I40E_PFLAN_QALLOC_VALID_MASK)
1324 num_queues = (j - base_queue) + 1;
1325 else
1326 num_queues = 0;
1327
1328 val = rd32(hw, I40E_PF_VT_PFALLOC);
1329 i = (val & I40E_PF_VT_PFALLOC_FIRSTVF_MASK) >>
1330 I40E_PF_VT_PFALLOC_FIRSTVF_SHIFT;
1331 j = (val & I40E_PF_VT_PFALLOC_LASTVF_MASK) >>
1332 I40E_PF_VT_PFALLOC_LASTVF_SHIFT;
1333 if (val & I40E_PF_VT_PFALLOC_VALID_MASK)
1334 num_vfs = (j - i) + 1;
1335 else
1336 num_vfs = 0;
1337
1338 /* stop all the interrupts */
1339 wr32(hw, I40E_PFINT_ICR0_ENA, 0);
1340 val = 0x3 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT;
1341 for (i = 0; i < num_pf_int - 2; i++)
1342 wr32(hw, I40E_PFINT_DYN_CTLN(i), val);
1343
1344 /* Set the FIRSTQ_INDX field to 0x7FF in PFINT_LNKLSTx */
1345 val = eol << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
1346 wr32(hw, I40E_PFINT_LNKLST0, val);
1347 for (i = 0; i < num_pf_int - 2; i++)
1348 wr32(hw, I40E_PFINT_LNKLSTN(i), val);
1349 val = eol << I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT;
1350 for (i = 0; i < num_vfs; i++)
1351 wr32(hw, I40E_VPINT_LNKLST0(i), val);
1352 for (i = 0; i < num_vf_int - 2; i++)
1353 wr32(hw, I40E_VPINT_LNKLSTN(i), val);
1354
1355 /* warn the HW of the coming Tx disables */
1356 for (i = 0; i < num_queues; i++) {
1357 u32 abs_queue_idx = base_queue + i;
1358 u32 reg_block = 0;
1359
1360 if (abs_queue_idx >= 128) {
1361 reg_block = abs_queue_idx / 128;
1362 abs_queue_idx %= 128;
1363 }
1364
1365 val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
1366 val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
1367 val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
1368 val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
1369
1370 wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), val);
1371 }
1372 udelay(400);
1373
1374 /* stop all the queues */
1375 for (i = 0; i < num_queues; i++) {
1376 wr32(hw, I40E_QINT_TQCTL(i), 0);
1377 wr32(hw, I40E_QTX_ENA(i), 0);
1378 wr32(hw, I40E_QINT_RQCTL(i), 0);
1379 wr32(hw, I40E_QRX_ENA(i), 0);
1380 }
1381
1382 /* short wait for all queue disables to settle */
1383 udelay(50);
1384}
1385
1386/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001387 * i40e_clear_pxe_mode - clear pxe operations mode
1388 * @hw: pointer to the hw struct
1389 *
1390 * Make sure all PXE mode settings are cleared, including things
1391 * like descriptor fetch/write-back mode.
1392 **/
1393void i40e_clear_pxe_mode(struct i40e_hw *hw)
1394{
1395 u32 reg;
1396
Shannon Nelsonc9b9b0a2014-04-09 05:59:05 +00001397 if (i40e_check_asq_alive(hw))
1398 i40e_aq_clear_pxe_mode(hw, NULL);
1399
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001400 /* Clear single descriptor fetch/write-back mode */
1401 reg = rd32(hw, I40E_GLLAN_RCTL_0);
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001402
1403 if (hw->revision_id == 0) {
1404 /* As a work around clear PXE_MODE instead of setting it */
1405 wr32(hw, I40E_GLLAN_RCTL_0, (reg & (~I40E_GLLAN_RCTL_0_PXE_MODE_MASK)));
1406 } else {
1407 wr32(hw, I40E_GLLAN_RCTL_0, (reg | I40E_GLLAN_RCTL_0_PXE_MODE_MASK));
1408 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001409}
1410
1411/**
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001412 * i40e_led_is_mine - helper to find matching led
1413 * @hw: pointer to the hw struct
1414 * @idx: index into GPIO registers
1415 *
1416 * returns: 0 if no match, otherwise the value of the GPIO_CTL register
1417 */
1418static u32 i40e_led_is_mine(struct i40e_hw *hw, int idx)
1419{
1420 u32 gpio_val = 0;
1421 u32 port;
1422
1423 if (!hw->func_caps.led[idx])
1424 return 0;
1425
1426 gpio_val = rd32(hw, I40E_GLGEN_GPIO_CTL(idx));
1427 port = (gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_MASK) >>
1428 I40E_GLGEN_GPIO_CTL_PRT_NUM_SHIFT;
1429
1430 /* if PRT_NUM_NA is 1 then this LED is not port specific, OR
1431 * if it is not our port then ignore
1432 */
1433 if ((gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_NA_MASK) ||
1434 (port != hw->port))
1435 return 0;
1436
1437 return gpio_val;
1438}
1439
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001440#define I40E_COMBINED_ACTIVITY 0xA
1441#define I40E_FILTER_ACTIVITY 0xE
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001442#define I40E_LINK_ACTIVITY 0xC
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001443#define I40E_MAC_ACTIVITY 0xD
1444#define I40E_LED0 22
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001445
1446/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001447 * i40e_led_get - return current on/off mode
1448 * @hw: pointer to the hw struct
1449 *
1450 * The value returned is the 'mode' field as defined in the
1451 * GPIO register definitions: 0x0 = off, 0xf = on, and other
1452 * values are variations of possible behaviors relating to
1453 * blink, link, and wire.
1454 **/
1455u32 i40e_led_get(struct i40e_hw *hw)
1456{
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001457 u32 current_mode = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001458 u32 mode = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001459 int i;
1460
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001461 /* as per the documentation GPIO 22-29 are the LED
1462 * GPIO pins named LED0..LED7
1463 */
1464 for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
1465 u32 gpio_val = i40e_led_is_mine(hw, i);
1466
1467 if (!gpio_val)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001468 continue;
1469
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001470 /* ignore gpio LED src mode entries related to the activity
1471 * LEDs
1472 */
1473 current_mode = ((gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK)
1474 >> I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT);
1475 switch (current_mode) {
1476 case I40E_COMBINED_ACTIVITY:
1477 case I40E_FILTER_ACTIVITY:
1478 case I40E_MAC_ACTIVITY:
1479 continue;
1480 default:
1481 break;
1482 }
1483
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001484 mode = (gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK) >>
1485 I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001486 break;
1487 }
1488
1489 return mode;
1490}
1491
1492/**
1493 * i40e_led_set - set new on/off mode
1494 * @hw: pointer to the hw struct
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001495 * @mode: 0=off, 0xf=on (else see manual for mode details)
1496 * @blink: true if the LED should blink when on, false if steady
1497 *
1498 * if this function is used to turn on the blink it should
1499 * be used to disable the blink when restoring the original state.
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001500 **/
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001501void i40e_led_set(struct i40e_hw *hw, u32 mode, bool blink)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001502{
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001503 u32 current_mode = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001504 int i;
1505
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001506 if (mode & 0xfffffff0)
1507 hw_dbg(hw, "invalid mode passed in %X\n", mode);
1508
1509 /* as per the documentation GPIO 22-29 are the LED
1510 * GPIO pins named LED0..LED7
1511 */
1512 for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
1513 u32 gpio_val = i40e_led_is_mine(hw, i);
1514
1515 if (!gpio_val)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001516 continue;
1517
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001518 /* ignore gpio LED src mode entries related to the activity
1519 * LEDs
1520 */
1521 current_mode = ((gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK)
1522 >> I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT);
1523 switch (current_mode) {
1524 case I40E_COMBINED_ACTIVITY:
1525 case I40E_FILTER_ACTIVITY:
1526 case I40E_MAC_ACTIVITY:
1527 continue;
1528 default:
1529 break;
1530 }
1531
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001532 gpio_val &= ~I40E_GLGEN_GPIO_CTL_LED_MODE_MASK;
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001533 /* this & is a bit of paranoia, but serves as a range check */
1534 gpio_val |= ((mode << I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT) &
1535 I40E_GLGEN_GPIO_CTL_LED_MODE_MASK);
1536
1537 if (mode == I40E_LINK_ACTIVITY)
1538 blink = false;
1539
Matt Jared9be00d62015-01-24 09:58:28 +00001540 if (blink)
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001541 gpio_val |= BIT(I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
Matt Jared9be00d62015-01-24 09:58:28 +00001542 else
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001543 gpio_val &= ~BIT(I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001544
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001545 wr32(hw, I40E_GLGEN_GPIO_CTL(i), gpio_val);
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001546 break;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001547 }
1548}
1549
1550/* Admin command wrappers */
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001551
1552/**
Catherine Sullivan8109e122014-06-04 08:45:24 +00001553 * i40e_aq_get_phy_capabilities
1554 * @hw: pointer to the hw struct
1555 * @abilities: structure for PHY capabilities to be filled
1556 * @qualified_modules: report Qualified Modules
1557 * @report_init: report init capabilities (active are default)
1558 * @cmd_details: pointer to command details structure or NULL
1559 *
1560 * Returns the various PHY abilities supported on the Port.
1561 **/
1562i40e_status i40e_aq_get_phy_capabilities(struct i40e_hw *hw,
1563 bool qualified_modules, bool report_init,
1564 struct i40e_aq_get_phy_abilities_resp *abilities,
1565 struct i40e_asq_cmd_details *cmd_details)
1566{
1567 struct i40e_aq_desc desc;
1568 i40e_status status;
1569 u16 abilities_size = sizeof(struct i40e_aq_get_phy_abilities_resp);
1570
1571 if (!abilities)
1572 return I40E_ERR_PARAM;
1573
1574 i40e_fill_default_direct_cmd_desc(&desc,
1575 i40e_aqc_opc_get_phy_abilities);
1576
1577 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
1578 if (abilities_size > I40E_AQ_LARGE_BUF)
1579 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
1580
1581 if (qualified_modules)
1582 desc.params.external.param0 |=
1583 cpu_to_le32(I40E_AQ_PHY_REPORT_QUALIFIED_MODULES);
1584
1585 if (report_init)
1586 desc.params.external.param0 |=
1587 cpu_to_le32(I40E_AQ_PHY_REPORT_INITIAL_VALUES);
1588
1589 status = i40e_asq_send_command(hw, &desc, abilities, abilities_size,
1590 cmd_details);
1591
1592 if (hw->aq.asq_last_status == I40E_AQ_RC_EIO)
1593 status = I40E_ERR_UNKNOWN_PHY;
1594
Carolyn Wyborny31232372016-11-21 13:03:48 -08001595 if (report_init) {
Mitch Williams22b965512017-07-14 09:27:09 -04001596 if (hw->mac.type == I40E_MAC_XL710 &&
1597 hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
1598 hw->aq.api_min_ver >= I40E_MINOR_VER_GET_LINK_INFO_XL710)
1599 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
Carolyn Wyborny31232372016-11-21 13:03:48 -08001600 }
Kevin Scott3ac67d72015-09-03 17:18:58 -04001601
Catherine Sullivan8109e122014-06-04 08:45:24 +00001602 return status;
1603}
1604
1605/**
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001606 * i40e_aq_set_phy_config
1607 * @hw: pointer to the hw struct
1608 * @config: structure with PHY configuration to be set
1609 * @cmd_details: pointer to command details structure or NULL
1610 *
1611 * Set the various PHY configuration parameters
1612 * supported on the Port.One or more of the Set PHY config parameters may be
1613 * ignored in an MFP mode as the PF may not have the privilege to set some
1614 * of the PHY Config parameters. This status will be indicated by the
1615 * command response.
1616 **/
1617enum i40e_status_code i40e_aq_set_phy_config(struct i40e_hw *hw,
1618 struct i40e_aq_set_phy_config *config,
1619 struct i40e_asq_cmd_details *cmd_details)
1620{
1621 struct i40e_aq_desc desc;
1622 struct i40e_aq_set_phy_config *cmd =
1623 (struct i40e_aq_set_phy_config *)&desc.params.raw;
1624 enum i40e_status_code status;
1625
1626 if (!config)
1627 return I40E_ERR_PARAM;
1628
1629 i40e_fill_default_direct_cmd_desc(&desc,
1630 i40e_aqc_opc_set_phy_config);
1631
1632 *cmd = *config;
1633
1634 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1635
1636 return status;
1637}
1638
1639/**
1640 * i40e_set_fc
1641 * @hw: pointer to the hw struct
1642 *
1643 * Set the requested flow control mode using set_phy_config.
1644 **/
1645enum i40e_status_code i40e_set_fc(struct i40e_hw *hw, u8 *aq_failures,
1646 bool atomic_restart)
1647{
1648 enum i40e_fc_mode fc_mode = hw->fc.requested_mode;
1649 struct i40e_aq_get_phy_abilities_resp abilities;
1650 struct i40e_aq_set_phy_config config;
1651 enum i40e_status_code status;
1652 u8 pause_mask = 0x0;
1653
1654 *aq_failures = 0x0;
1655
1656 switch (fc_mode) {
1657 case I40E_FC_FULL:
1658 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
1659 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
1660 break;
1661 case I40E_FC_RX_PAUSE:
1662 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
1663 break;
1664 case I40E_FC_TX_PAUSE:
1665 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
1666 break;
1667 default:
1668 break;
1669 }
1670
1671 /* Get the current phy config */
1672 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
1673 NULL);
1674 if (status) {
1675 *aq_failures |= I40E_SET_FC_AQ_FAIL_GET;
1676 return status;
1677 }
1678
1679 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
1680 /* clear the old pause settings */
1681 config.abilities = abilities.abilities & ~(I40E_AQ_PHY_FLAG_PAUSE_TX) &
1682 ~(I40E_AQ_PHY_FLAG_PAUSE_RX);
1683 /* set the new abilities */
1684 config.abilities |= pause_mask;
1685 /* If the abilities have changed, then set the new config */
1686 if (config.abilities != abilities.abilities) {
1687 /* Auto restart link so settings take effect */
1688 if (atomic_restart)
1689 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
1690 /* Copy over all the old settings */
1691 config.phy_type = abilities.phy_type;
Carolyn Wyborny31232372016-11-21 13:03:48 -08001692 config.phy_type_ext = abilities.phy_type_ext;
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001693 config.link_speed = abilities.link_speed;
1694 config.eee_capability = abilities.eee_capability;
1695 config.eeer = abilities.eeer_val;
1696 config.low_power_ctrl = abilities.d3_lpan;
Carolyn Wyborny60f000a2016-11-21 13:03:49 -08001697 config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
1698 I40E_AQ_PHY_FEC_CONFIG_MASK;
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001699 status = i40e_aq_set_phy_config(hw, &config, NULL);
1700
1701 if (status)
1702 *aq_failures |= I40E_SET_FC_AQ_FAIL_SET;
1703 }
1704 /* Update the link info */
Catherine Sullivan0a862b42015-08-31 19:54:53 -04001705 status = i40e_update_link_info(hw);
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001706 if (status) {
1707 /* Wait a little bit (on 40G cards it sometimes takes a really
1708 * long time for link to come back from the atomic reset)
1709 * and try once more
1710 */
1711 msleep(1000);
Catherine Sullivan0a862b42015-08-31 19:54:53 -04001712 status = i40e_update_link_info(hw);
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001713 }
1714 if (status)
1715 *aq_failures |= I40E_SET_FC_AQ_FAIL_UPDATE;
1716
1717 return status;
1718}
1719
1720/**
Shannon Nelsonc9b9b0a2014-04-09 05:59:05 +00001721 * i40e_aq_clear_pxe_mode
1722 * @hw: pointer to the hw struct
1723 * @cmd_details: pointer to command details structure or NULL
1724 *
1725 * Tell the firmware that the driver is taking over from PXE
1726 **/
1727i40e_status i40e_aq_clear_pxe_mode(struct i40e_hw *hw,
1728 struct i40e_asq_cmd_details *cmd_details)
1729{
1730 i40e_status status;
1731 struct i40e_aq_desc desc;
1732 struct i40e_aqc_clear_pxe *cmd =
1733 (struct i40e_aqc_clear_pxe *)&desc.params.raw;
1734
1735 i40e_fill_default_direct_cmd_desc(&desc,
1736 i40e_aqc_opc_clear_pxe_mode);
1737
1738 cmd->rx_cnt = 0x2;
1739
1740 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1741
1742 wr32(hw, I40E_GLLAN_RCTL_0, 0x1);
1743
1744 return status;
1745}
1746
1747/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001748 * i40e_aq_set_link_restart_an
1749 * @hw: pointer to the hw struct
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001750 * @enable_link: if true: enable link, if false: disable link
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001751 * @cmd_details: pointer to command details structure or NULL
1752 *
1753 * Sets up the link and restarts the Auto-Negotiation over the link.
1754 **/
1755i40e_status i40e_aq_set_link_restart_an(struct i40e_hw *hw,
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001756 bool enable_link,
1757 struct i40e_asq_cmd_details *cmd_details)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001758{
1759 struct i40e_aq_desc desc;
1760 struct i40e_aqc_set_link_restart_an *cmd =
1761 (struct i40e_aqc_set_link_restart_an *)&desc.params.raw;
1762 i40e_status status;
1763
1764 i40e_fill_default_direct_cmd_desc(&desc,
1765 i40e_aqc_opc_set_link_restart_an);
1766
1767 cmd->command = I40E_AQ_PHY_RESTART_AN;
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001768 if (enable_link)
1769 cmd->command |= I40E_AQ_PHY_LINK_ENABLE;
1770 else
1771 cmd->command &= ~I40E_AQ_PHY_LINK_ENABLE;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001772
1773 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1774
1775 return status;
1776}
1777
1778/**
1779 * i40e_aq_get_link_info
1780 * @hw: pointer to the hw struct
1781 * @enable_lse: enable/disable LinkStatusEvent reporting
1782 * @link: pointer to link status structure - optional
1783 * @cmd_details: pointer to command details structure or NULL
1784 *
1785 * Returns the link status of the adapter.
1786 **/
1787i40e_status i40e_aq_get_link_info(struct i40e_hw *hw,
1788 bool enable_lse, struct i40e_link_status *link,
1789 struct i40e_asq_cmd_details *cmd_details)
1790{
1791 struct i40e_aq_desc desc;
1792 struct i40e_aqc_get_link_status *resp =
1793 (struct i40e_aqc_get_link_status *)&desc.params.raw;
1794 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
1795 i40e_status status;
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001796 bool tx_pause, rx_pause;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001797 u16 command_flags;
1798
1799 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_link_status);
1800
1801 if (enable_lse)
1802 command_flags = I40E_AQ_LSE_ENABLE;
1803 else
1804 command_flags = I40E_AQ_LSE_DISABLE;
1805 resp->command_flags = cpu_to_le16(command_flags);
1806
1807 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1808
1809 if (status)
1810 goto aq_get_link_info_exit;
1811
1812 /* save off old link status information */
Mitch Williamsc36bd4a72013-12-18 13:46:04 +00001813 hw->phy.link_info_old = *hw_link_info;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001814
1815 /* update link status */
1816 hw_link_info->phy_type = (enum i40e_aq_phy_type)resp->phy_type;
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001817 hw->phy.media_type = i40e_get_media_type(hw);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001818 hw_link_info->link_speed = (enum i40e_aq_link_speed)resp->link_speed;
1819 hw_link_info->link_info = resp->link_info;
1820 hw_link_info->an_info = resp->an_info;
Henry Tieman3e03d7c2016-12-02 12:32:57 -08001821 hw_link_info->fec_info = resp->config & (I40E_AQ_CONFIG_FEC_KR_ENA |
1822 I40E_AQ_CONFIG_FEC_RS_ENA);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001823 hw_link_info->ext_info = resp->ext_info;
Kamil Krawczyk639dc372013-11-20 10:03:07 +00001824 hw_link_info->loopback = resp->loopback;
Neerav Parikh6bb3f232014-04-01 07:11:56 +00001825 hw_link_info->max_frame_size = le16_to_cpu(resp->max_frame_size);
1826 hw_link_info->pacing = resp->config & I40E_AQ_CONFIG_PACING_MASK;
1827
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001828 /* update fc info */
1829 tx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_TX);
1830 rx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_RX);
1831 if (tx_pause & rx_pause)
1832 hw->fc.current_mode = I40E_FC_FULL;
1833 else if (tx_pause)
1834 hw->fc.current_mode = I40E_FC_TX_PAUSE;
1835 else if (rx_pause)
1836 hw->fc.current_mode = I40E_FC_RX_PAUSE;
1837 else
1838 hw->fc.current_mode = I40E_FC_NONE;
1839
Neerav Parikh6bb3f232014-04-01 07:11:56 +00001840 if (resp->config & I40E_AQ_CONFIG_CRC_ENA)
1841 hw_link_info->crc_enable = true;
1842 else
1843 hw_link_info->crc_enable = false;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001844
Filip Sadowski7ed35732016-09-14 16:24:33 -07001845 if (resp->command_flags & cpu_to_le16(I40E_AQ_LSE_IS_ENABLED))
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001846 hw_link_info->lse_enable = true;
1847 else
1848 hw_link_info->lse_enable = false;
1849
Henry Tiemane586bb62016-11-08 13:05:07 -08001850 if ((hw->mac.type == I40E_MAC_XL710) &&
1851 (hw->aq.fw_maj_ver < 4 || (hw->aq.fw_maj_ver == 4 &&
Catherine Sullivan088c4ee2015-02-26 16:14:12 +00001852 hw->aq.fw_min_ver < 40)) && hw_link_info->phy_type == 0xE)
1853 hw_link_info->phy_type = I40E_PHY_TYPE_10GBASE_SFPP_CU;
1854
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001855 /* save link status information */
1856 if (link)
Jesse Brandeburgd7595a22013-09-13 08:23:22 +00001857 *link = *hw_link_info;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001858
1859 /* flag cleared so helper functions don't call AQ again */
1860 hw->phy.get_link_info = false;
1861
1862aq_get_link_info_exit:
1863 return status;
1864}
1865
1866/**
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00001867 * i40e_aq_set_phy_int_mask
1868 * @hw: pointer to the hw struct
1869 * @mask: interrupt mask to be set
1870 * @cmd_details: pointer to command details structure or NULL
1871 *
1872 * Set link interrupt mask.
1873 **/
1874i40e_status i40e_aq_set_phy_int_mask(struct i40e_hw *hw,
1875 u16 mask,
1876 struct i40e_asq_cmd_details *cmd_details)
1877{
1878 struct i40e_aq_desc desc;
1879 struct i40e_aqc_set_phy_int_mask *cmd =
1880 (struct i40e_aqc_set_phy_int_mask *)&desc.params.raw;
1881 i40e_status status;
1882
1883 i40e_fill_default_direct_cmd_desc(&desc,
1884 i40e_aqc_opc_set_phy_int_mask);
1885
1886 cmd->event_mask = cpu_to_le16(mask);
1887
1888 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1889
1890 return status;
1891}
1892
1893/**
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001894 * i40e_aq_set_phy_debug
1895 * @hw: pointer to the hw struct
1896 * @cmd_flags: debug command flags
1897 * @cmd_details: pointer to command details structure or NULL
1898 *
1899 * Reset the external PHY.
1900 **/
Jesse Brandeburg61829022016-03-10 14:59:42 -08001901i40e_status i40e_aq_set_phy_debug(struct i40e_hw *hw, u8 cmd_flags,
1902 struct i40e_asq_cmd_details *cmd_details)
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001903{
1904 struct i40e_aq_desc desc;
1905 struct i40e_aqc_set_phy_debug *cmd =
1906 (struct i40e_aqc_set_phy_debug *)&desc.params.raw;
Jesse Brandeburg61829022016-03-10 14:59:42 -08001907 i40e_status status;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001908
1909 i40e_fill_default_direct_cmd_desc(&desc,
1910 i40e_aqc_opc_set_phy_debug);
1911
1912 cmd->command_flags = cmd_flags;
1913
1914 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1915
1916 return status;
1917}
1918
1919/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001920 * i40e_aq_add_vsi
1921 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00001922 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001923 * @cmd_details: pointer to command details structure or NULL
1924 *
1925 * Add a VSI context to the hardware.
1926**/
1927i40e_status i40e_aq_add_vsi(struct i40e_hw *hw,
1928 struct i40e_vsi_context *vsi_ctx,
1929 struct i40e_asq_cmd_details *cmd_details)
1930{
1931 struct i40e_aq_desc desc;
1932 struct i40e_aqc_add_get_update_vsi *cmd =
1933 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
1934 struct i40e_aqc_add_get_update_vsi_completion *resp =
1935 (struct i40e_aqc_add_get_update_vsi_completion *)
1936 &desc.params.raw;
1937 i40e_status status;
1938
1939 i40e_fill_default_direct_cmd_desc(&desc,
1940 i40e_aqc_opc_add_vsi);
1941
1942 cmd->uplink_seid = cpu_to_le16(vsi_ctx->uplink_seid);
1943 cmd->connection_type = vsi_ctx->connection_type;
1944 cmd->vf_id = vsi_ctx->vf_num;
1945 cmd->vsi_flags = cpu_to_le16(vsi_ctx->flags);
1946
1947 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001948
1949 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
1950 sizeof(vsi_ctx->info), cmd_details);
1951
1952 if (status)
1953 goto aq_add_vsi_exit;
1954
1955 vsi_ctx->seid = le16_to_cpu(resp->seid);
1956 vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
1957 vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
1958 vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
1959
1960aq_add_vsi_exit:
1961 return status;
1962}
1963
1964/**
Mitch Williamsfb70fab2016-05-16 10:26:31 -07001965 * i40e_aq_set_default_vsi
1966 * @hw: pointer to the hw struct
1967 * @seid: vsi number
1968 * @cmd_details: pointer to command details structure or NULL
1969 **/
1970i40e_status i40e_aq_set_default_vsi(struct i40e_hw *hw,
1971 u16 seid,
1972 struct i40e_asq_cmd_details *cmd_details)
1973{
1974 struct i40e_aq_desc desc;
1975 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
1976 (struct i40e_aqc_set_vsi_promiscuous_modes *)
1977 &desc.params.raw;
1978 i40e_status status;
1979
1980 i40e_fill_default_direct_cmd_desc(&desc,
1981 i40e_aqc_opc_set_vsi_promiscuous_modes);
1982
1983 cmd->promiscuous_flags = cpu_to_le16(I40E_AQC_SET_VSI_DEFAULT);
1984 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_DEFAULT);
1985 cmd->seid = cpu_to_le16(seid);
1986
1987 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1988
1989 return status;
1990}
1991
1992/**
1993 * i40e_aq_clear_default_vsi
1994 * @hw: pointer to the hw struct
1995 * @seid: vsi number
1996 * @cmd_details: pointer to command details structure or NULL
1997 **/
1998i40e_status i40e_aq_clear_default_vsi(struct i40e_hw *hw,
1999 u16 seid,
2000 struct i40e_asq_cmd_details *cmd_details)
2001{
2002 struct i40e_aq_desc desc;
2003 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2004 (struct i40e_aqc_set_vsi_promiscuous_modes *)
2005 &desc.params.raw;
2006 i40e_status status;
2007
2008 i40e_fill_default_direct_cmd_desc(&desc,
2009 i40e_aqc_opc_set_vsi_promiscuous_modes);
2010
2011 cmd->promiscuous_flags = cpu_to_le16(0);
2012 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_DEFAULT);
2013 cmd->seid = cpu_to_le16(seid);
2014
2015 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2016
2017 return status;
2018}
2019
2020/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002021 * i40e_aq_set_vsi_unicast_promiscuous
2022 * @hw: pointer to the hw struct
2023 * @seid: vsi number
2024 * @set: set unicast promiscuous enable/disable
2025 * @cmd_details: pointer to command details structure or NULL
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002026 * @rx_only_promisc: flag to decide if egress traffic gets mirrored in promisc
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002027 **/
2028i40e_status i40e_aq_set_vsi_unicast_promiscuous(struct i40e_hw *hw,
Mitch Williams885552a2013-12-21 05:44:41 +00002029 u16 seid, bool set,
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002030 struct i40e_asq_cmd_details *cmd_details,
2031 bool rx_only_promisc)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002032{
2033 struct i40e_aq_desc desc;
2034 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2035 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2036 i40e_status status;
2037 u16 flags = 0;
2038
2039 i40e_fill_default_direct_cmd_desc(&desc,
2040 i40e_aqc_opc_set_vsi_promiscuous_modes);
2041
Anjali Singhai Jain3b120082016-01-15 14:33:21 -08002042 if (set) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002043 flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002044 if (rx_only_promisc &&
2045 (((hw->aq.api_maj_ver == 1) && (hw->aq.api_min_ver >= 5)) ||
2046 (hw->aq.api_maj_ver > 1)))
Anjali Singhai Jain3b120082016-01-15 14:33:21 -08002047 flags |= I40E_AQC_SET_VSI_PROMISC_TX;
2048 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002049
2050 cmd->promiscuous_flags = cpu_to_le16(flags);
2051
2052 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
Anjali Singhai Jain3b120082016-01-15 14:33:21 -08002053 if (((hw->aq.api_maj_ver >= 1) && (hw->aq.api_min_ver >= 5)) ||
2054 (hw->aq.api_maj_ver > 1))
2055 cmd->valid_flags |= cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_TX);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002056
2057 cmd->seid = cpu_to_le16(seid);
2058 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2059
2060 return status;
2061}
2062
2063/**
2064 * i40e_aq_set_vsi_multicast_promiscuous
2065 * @hw: pointer to the hw struct
2066 * @seid: vsi number
2067 * @set: set multicast promiscuous enable/disable
2068 * @cmd_details: pointer to command details structure or NULL
2069 **/
2070i40e_status i40e_aq_set_vsi_multicast_promiscuous(struct i40e_hw *hw,
2071 u16 seid, bool set, struct i40e_asq_cmd_details *cmd_details)
2072{
2073 struct i40e_aq_desc desc;
2074 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2075 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2076 i40e_status status;
2077 u16 flags = 0;
2078
2079 i40e_fill_default_direct_cmd_desc(&desc,
2080 i40e_aqc_opc_set_vsi_promiscuous_modes);
2081
2082 if (set)
2083 flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
2084
2085 cmd->promiscuous_flags = cpu_to_le16(flags);
2086
2087 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
2088
2089 cmd->seid = cpu_to_le16(seid);
2090 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2091
2092 return status;
2093}
2094
2095/**
Greg Rose6c41a762016-04-12 08:30:50 -07002096 * i40e_aq_set_vsi_mc_promisc_on_vlan
2097 * @hw: pointer to the hw struct
2098 * @seid: vsi number
2099 * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
2100 * @vid: The VLAN tag filter - capture any multicast packet with this VLAN tag
2101 * @cmd_details: pointer to command details structure or NULL
2102 **/
2103enum i40e_status_code i40e_aq_set_vsi_mc_promisc_on_vlan(struct i40e_hw *hw,
2104 u16 seid, bool enable,
2105 u16 vid,
2106 struct i40e_asq_cmd_details *cmd_details)
2107{
2108 struct i40e_aq_desc desc;
2109 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2110 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2111 enum i40e_status_code status;
2112 u16 flags = 0;
2113
2114 i40e_fill_default_direct_cmd_desc(&desc,
2115 i40e_aqc_opc_set_vsi_promiscuous_modes);
2116
2117 if (enable)
2118 flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
2119
2120 cmd->promiscuous_flags = cpu_to_le16(flags);
2121 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
2122 cmd->seid = cpu_to_le16(seid);
2123 cmd->vlan_tag = cpu_to_le16(vid | I40E_AQC_SET_VSI_VLAN_VALID);
2124
2125 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2126
2127 return status;
2128}
2129
2130/**
2131 * i40e_aq_set_vsi_uc_promisc_on_vlan
2132 * @hw: pointer to the hw struct
2133 * @seid: vsi number
2134 * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
2135 * @vid: The VLAN tag filter - capture any unicast packet with this VLAN tag
2136 * @cmd_details: pointer to command details structure or NULL
2137 **/
2138enum i40e_status_code i40e_aq_set_vsi_uc_promisc_on_vlan(struct i40e_hw *hw,
2139 u16 seid, bool enable,
2140 u16 vid,
2141 struct i40e_asq_cmd_details *cmd_details)
2142{
2143 struct i40e_aq_desc desc;
2144 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2145 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2146 enum i40e_status_code status;
2147 u16 flags = 0;
2148
2149 i40e_fill_default_direct_cmd_desc(&desc,
2150 i40e_aqc_opc_set_vsi_promiscuous_modes);
2151
2152 if (enable)
2153 flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
2154
2155 cmd->promiscuous_flags = cpu_to_le16(flags);
2156 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
2157 cmd->seid = cpu_to_le16(seid);
2158 cmd->vlan_tag = cpu_to_le16(vid | I40E_AQC_SET_VSI_VLAN_VALID);
2159
2160 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2161
2162 return status;
2163}
2164
2165/**
Jacob Keller435c0842016-11-08 13:05:10 -08002166 * i40e_aq_set_vsi_bc_promisc_on_vlan
2167 * @hw: pointer to the hw struct
2168 * @seid: vsi number
2169 * @enable: set broadcast promiscuous enable/disable for a given VLAN
2170 * @vid: The VLAN tag filter - capture any broadcast packet with this VLAN tag
2171 * @cmd_details: pointer to command details structure or NULL
2172 **/
2173i40e_status i40e_aq_set_vsi_bc_promisc_on_vlan(struct i40e_hw *hw,
2174 u16 seid, bool enable, u16 vid,
2175 struct i40e_asq_cmd_details *cmd_details)
2176{
2177 struct i40e_aq_desc desc;
2178 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2179 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2180 i40e_status status;
2181 u16 flags = 0;
2182
2183 i40e_fill_default_direct_cmd_desc(&desc,
2184 i40e_aqc_opc_set_vsi_promiscuous_modes);
2185
2186 if (enable)
2187 flags |= I40E_AQC_SET_VSI_PROMISC_BROADCAST;
2188
2189 cmd->promiscuous_flags = cpu_to_le16(flags);
2190 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2191 cmd->seid = cpu_to_le16(seid);
2192 cmd->vlan_tag = cpu_to_le16(vid | I40E_AQC_SET_VSI_VLAN_VALID);
2193
2194 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2195
2196 return status;
2197}
2198
2199/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002200 * i40e_aq_set_vsi_broadcast
2201 * @hw: pointer to the hw struct
2202 * @seid: vsi number
2203 * @set_filter: true to set filter, false to clear filter
2204 * @cmd_details: pointer to command details structure or NULL
2205 *
2206 * Set or clear the broadcast promiscuous flag (filter) for a given VSI.
2207 **/
2208i40e_status i40e_aq_set_vsi_broadcast(struct i40e_hw *hw,
2209 u16 seid, bool set_filter,
2210 struct i40e_asq_cmd_details *cmd_details)
2211{
2212 struct i40e_aq_desc desc;
2213 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2214 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2215 i40e_status status;
2216
2217 i40e_fill_default_direct_cmd_desc(&desc,
2218 i40e_aqc_opc_set_vsi_promiscuous_modes);
2219
2220 if (set_filter)
2221 cmd->promiscuous_flags
2222 |= cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2223 else
2224 cmd->promiscuous_flags
2225 &= cpu_to_le16(~I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2226
2227 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2228 cmd->seid = cpu_to_le16(seid);
2229 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2230
2231 return status;
2232}
2233
2234/**
Kiran Patil7bd68752016-01-04 10:33:07 -08002235 * i40e_aq_set_vsi_vlan_promisc - control the VLAN promiscuous setting
2236 * @hw: pointer to the hw struct
2237 * @seid: vsi number
2238 * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
2239 * @cmd_details: pointer to command details structure or NULL
2240 **/
2241i40e_status i40e_aq_set_vsi_vlan_promisc(struct i40e_hw *hw,
2242 u16 seid, bool enable,
2243 struct i40e_asq_cmd_details *cmd_details)
2244{
2245 struct i40e_aq_desc desc;
2246 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2247 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2248 i40e_status status;
2249 u16 flags = 0;
2250
2251 i40e_fill_default_direct_cmd_desc(&desc,
2252 i40e_aqc_opc_set_vsi_promiscuous_modes);
2253 if (enable)
2254 flags |= I40E_AQC_SET_VSI_PROMISC_VLAN;
2255
2256 cmd->promiscuous_flags = cpu_to_le16(flags);
2257 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_VLAN);
2258 cmd->seid = cpu_to_le16(seid);
2259
2260 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2261
2262 return status;
2263}
2264
2265/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002266 * i40e_get_vsi_params - get VSI configuration info
2267 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00002268 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002269 * @cmd_details: pointer to command details structure or NULL
2270 **/
2271i40e_status i40e_aq_get_vsi_params(struct i40e_hw *hw,
2272 struct i40e_vsi_context *vsi_ctx,
2273 struct i40e_asq_cmd_details *cmd_details)
2274{
2275 struct i40e_aq_desc desc;
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002276 struct i40e_aqc_add_get_update_vsi *cmd =
2277 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002278 struct i40e_aqc_add_get_update_vsi_completion *resp =
2279 (struct i40e_aqc_add_get_update_vsi_completion *)
2280 &desc.params.raw;
2281 i40e_status status;
2282
2283 i40e_fill_default_direct_cmd_desc(&desc,
2284 i40e_aqc_opc_get_vsi_parameters);
2285
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002286 cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002287
2288 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002289
2290 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
2291 sizeof(vsi_ctx->info), NULL);
2292
2293 if (status)
2294 goto aq_get_vsi_params_exit;
2295
2296 vsi_ctx->seid = le16_to_cpu(resp->seid);
2297 vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
2298 vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
2299 vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
2300
2301aq_get_vsi_params_exit:
2302 return status;
2303}
2304
2305/**
2306 * i40e_aq_update_vsi_params
2307 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00002308 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002309 * @cmd_details: pointer to command details structure or NULL
2310 *
2311 * Update a VSI context.
2312 **/
2313i40e_status i40e_aq_update_vsi_params(struct i40e_hw *hw,
2314 struct i40e_vsi_context *vsi_ctx,
2315 struct i40e_asq_cmd_details *cmd_details)
2316{
2317 struct i40e_aq_desc desc;
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002318 struct i40e_aqc_add_get_update_vsi *cmd =
2319 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
Kevin Scottb6cacca2016-03-10 14:59:41 -08002320 struct i40e_aqc_add_get_update_vsi_completion *resp =
2321 (struct i40e_aqc_add_get_update_vsi_completion *)
2322 &desc.params.raw;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002323 i40e_status status;
2324
2325 i40e_fill_default_direct_cmd_desc(&desc,
2326 i40e_aqc_opc_update_vsi_parameters);
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002327 cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002328
2329 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002330
2331 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
2332 sizeof(vsi_ctx->info), cmd_details);
2333
Kevin Scottb6cacca2016-03-10 14:59:41 -08002334 vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
2335 vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
2336
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002337 return status;
2338}
2339
2340/**
2341 * i40e_aq_get_switch_config
2342 * @hw: pointer to the hardware structure
2343 * @buf: pointer to the result buffer
2344 * @buf_size: length of input buffer
2345 * @start_seid: seid to start for the report, 0 == beginning
2346 * @cmd_details: pointer to command details structure or NULL
2347 *
2348 * Fill the buf with switch configuration returned from AdminQ command
2349 **/
2350i40e_status i40e_aq_get_switch_config(struct i40e_hw *hw,
2351 struct i40e_aqc_get_switch_config_resp *buf,
2352 u16 buf_size, u16 *start_seid,
2353 struct i40e_asq_cmd_details *cmd_details)
2354{
2355 struct i40e_aq_desc desc;
2356 struct i40e_aqc_switch_seid *scfg =
2357 (struct i40e_aqc_switch_seid *)&desc.params.raw;
2358 i40e_status status;
2359
2360 i40e_fill_default_direct_cmd_desc(&desc,
2361 i40e_aqc_opc_get_switch_config);
2362 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
2363 if (buf_size > I40E_AQ_LARGE_BUF)
2364 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2365 scfg->seid = cpu_to_le16(*start_seid);
2366
2367 status = i40e_asq_send_command(hw, &desc, buf, buf_size, cmd_details);
2368 *start_seid = le16_to_cpu(scfg->seid);
2369
2370 return status;
2371}
2372
2373/**
Shannon Nelsonf3d58492016-05-03 15:13:11 -07002374 * i40e_aq_set_switch_config
2375 * @hw: pointer to the hardware structure
2376 * @flags: bit flag values to set
2377 * @valid_flags: which bit flags to set
2378 * @cmd_details: pointer to command details structure or NULL
2379 *
2380 * Set switch configuration bits
2381 **/
2382enum i40e_status_code i40e_aq_set_switch_config(struct i40e_hw *hw,
2383 u16 flags,
2384 u16 valid_flags,
2385 struct i40e_asq_cmd_details *cmd_details)
2386{
2387 struct i40e_aq_desc desc;
2388 struct i40e_aqc_set_switch_config *scfg =
2389 (struct i40e_aqc_set_switch_config *)&desc.params.raw;
2390 enum i40e_status_code status;
2391
2392 i40e_fill_default_direct_cmd_desc(&desc,
2393 i40e_aqc_opc_set_switch_config);
2394 scfg->flags = cpu_to_le16(flags);
2395 scfg->valid_flags = cpu_to_le16(valid_flags);
2396
2397 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2398
2399 return status;
2400}
2401
2402/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002403 * i40e_aq_get_firmware_version
2404 * @hw: pointer to the hw struct
2405 * @fw_major_version: firmware major version
2406 * @fw_minor_version: firmware minor version
Shannon Nelson7edf8102015-02-24 06:58:41 +00002407 * @fw_build: firmware build number
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002408 * @api_major_version: major queue version
2409 * @api_minor_version: minor queue version
2410 * @cmd_details: pointer to command details structure or NULL
2411 *
2412 * Get the firmware version from the admin queue commands
2413 **/
2414i40e_status i40e_aq_get_firmware_version(struct i40e_hw *hw,
2415 u16 *fw_major_version, u16 *fw_minor_version,
Shannon Nelson7edf8102015-02-24 06:58:41 +00002416 u32 *fw_build,
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002417 u16 *api_major_version, u16 *api_minor_version,
2418 struct i40e_asq_cmd_details *cmd_details)
2419{
2420 struct i40e_aq_desc desc;
2421 struct i40e_aqc_get_version *resp =
2422 (struct i40e_aqc_get_version *)&desc.params.raw;
2423 i40e_status status;
2424
2425 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_version);
2426
2427 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2428
2429 if (!status) {
Shannon Nelson7edf8102015-02-24 06:58:41 +00002430 if (fw_major_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002431 *fw_major_version = le16_to_cpu(resp->fw_major);
Shannon Nelson7edf8102015-02-24 06:58:41 +00002432 if (fw_minor_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002433 *fw_minor_version = le16_to_cpu(resp->fw_minor);
Shannon Nelson7edf8102015-02-24 06:58:41 +00002434 if (fw_build)
2435 *fw_build = le32_to_cpu(resp->fw_build);
2436 if (api_major_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002437 *api_major_version = le16_to_cpu(resp->api_major);
Shannon Nelson7edf8102015-02-24 06:58:41 +00002438 if (api_minor_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002439 *api_minor_version = le16_to_cpu(resp->api_minor);
2440 }
2441
2442 return status;
2443}
2444
2445/**
2446 * i40e_aq_send_driver_version
2447 * @hw: pointer to the hw struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002448 * @dv: driver's major, minor version
2449 * @cmd_details: pointer to command details structure or NULL
2450 *
2451 * Send the driver version to the firmware
2452 **/
2453i40e_status i40e_aq_send_driver_version(struct i40e_hw *hw,
2454 struct i40e_driver_version *dv,
2455 struct i40e_asq_cmd_details *cmd_details)
2456{
2457 struct i40e_aq_desc desc;
2458 struct i40e_aqc_driver_version *cmd =
2459 (struct i40e_aqc_driver_version *)&desc.params.raw;
2460 i40e_status status;
Kevin Scott9d2f98e2014-04-01 07:11:52 +00002461 u16 len;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002462
2463 if (dv == NULL)
2464 return I40E_ERR_PARAM;
2465
2466 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_driver_version);
2467
Kevin Scott3b38cd12015-02-06 08:52:18 +00002468 desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002469 cmd->driver_major_ver = dv->major_version;
2470 cmd->driver_minor_ver = dv->minor_version;
2471 cmd->driver_build_ver = dv->build_version;
2472 cmd->driver_subbuild_ver = dv->subbuild_version;
Shannon Nelsond2466012014-04-01 07:11:45 +00002473
2474 len = 0;
2475 while (len < sizeof(dv->driver_string) &&
2476 (dv->driver_string[len] < 0x80) &&
2477 dv->driver_string[len])
2478 len++;
2479 status = i40e_asq_send_command(hw, &desc, dv->driver_string,
2480 len, cmd_details);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002481
2482 return status;
2483}
2484
2485/**
2486 * i40e_get_link_status - get status of the HW network link
2487 * @hw: pointer to the hw struct
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002488 * @link_up: pointer to bool (true/false = linkup/linkdown)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002489 *
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002490 * Variable link_up true if link is up, false if link is down.
2491 * The variable link_up is invalid if returned value of status != 0
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002492 *
2493 * Side effect: LinkStatusEvent reporting becomes enabled
2494 **/
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002495i40e_status i40e_get_link_status(struct i40e_hw *hw, bool *link_up)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002496{
2497 i40e_status status = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002498
2499 if (hw->phy.get_link_info) {
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002500 status = i40e_update_link_info(hw);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002501
2502 if (status)
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002503 i40e_debug(hw, I40E_DEBUG_LINK, "get link failed: status %d\n",
2504 status);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002505 }
2506
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002507 *link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002508
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002509 return status;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002510}
2511
2512/**
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002513 * i40e_updatelink_status - update status of the HW network link
2514 * @hw: pointer to the hw struct
2515 **/
2516i40e_status i40e_update_link_info(struct i40e_hw *hw)
2517{
2518 struct i40e_aq_get_phy_abilities_resp abilities;
2519 i40e_status status = 0;
2520
2521 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
2522 if (status)
2523 return status;
2524
Carolyn Wybornyab425cb2016-09-27 11:28:52 -07002525 /* extra checking needed to ensure link info to user is timely */
2526 if ((hw->phy.link_info.link_info & I40E_AQ_MEDIA_AVAILABLE) &&
2527 ((hw->phy.link_info.link_info & I40E_AQ_LINK_UP) ||
2528 !(hw->phy.link_info_old.link_info & I40E_AQ_LINK_UP))) {
Carolyn Wyborny8589af72015-09-28 14:16:56 -04002529 status = i40e_aq_get_phy_capabilities(hw, false, false,
2530 &abilities, NULL);
2531 if (status)
2532 return status;
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002533
Mariusz Stachuraed601f62017-07-12 05:46:08 -04002534 hw->phy.link_info.req_fec_info =
2535 abilities.fec_cfg_curr_mod_ext_info &
2536 (I40E_AQ_REQUEST_FEC_KR | I40E_AQ_REQUEST_FEC_RS);
2537
Carolyn Wyborny8589af72015-09-28 14:16:56 -04002538 memcpy(hw->phy.link_info.module_type, &abilities.module_type,
2539 sizeof(hw->phy.link_info.module_type));
2540 }
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002541
2542 return status;
2543}
2544
2545/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002546 * i40e_aq_add_veb - Insert a VEB between the VSI and the MAC
2547 * @hw: pointer to the hw struct
2548 * @uplink_seid: the MAC or other gizmo SEID
2549 * @downlink_seid: the VSI SEID
2550 * @enabled_tc: bitmap of TCs to be enabled
2551 * @default_port: true for default port VSI, false for control port
2552 * @veb_seid: pointer to where to put the resulting VEB SEID
Shannon Nelson8a187f42016-01-13 16:51:41 -08002553 * @enable_stats: true to turn on VEB stats
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002554 * @cmd_details: pointer to command details structure or NULL
2555 *
2556 * This asks the FW to add a VEB between the uplink and downlink
2557 * elements. If the uplink SEID is 0, this will be a floating VEB.
2558 **/
2559i40e_status i40e_aq_add_veb(struct i40e_hw *hw, u16 uplink_seid,
2560 u16 downlink_seid, u8 enabled_tc,
Shannon Nelson8a187f42016-01-13 16:51:41 -08002561 bool default_port, u16 *veb_seid,
2562 bool enable_stats,
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002563 struct i40e_asq_cmd_details *cmd_details)
2564{
2565 struct i40e_aq_desc desc;
2566 struct i40e_aqc_add_veb *cmd =
2567 (struct i40e_aqc_add_veb *)&desc.params.raw;
2568 struct i40e_aqc_add_veb_completion *resp =
2569 (struct i40e_aqc_add_veb_completion *)&desc.params.raw;
2570 i40e_status status;
2571 u16 veb_flags = 0;
2572
2573 /* SEIDs need to either both be set or both be 0 for floating VEB */
2574 if (!!uplink_seid != !!downlink_seid)
2575 return I40E_ERR_PARAM;
2576
2577 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_veb);
2578
2579 cmd->uplink_seid = cpu_to_le16(uplink_seid);
2580 cmd->downlink_seid = cpu_to_le16(downlink_seid);
2581 cmd->enable_tcs = enabled_tc;
2582 if (!uplink_seid)
2583 veb_flags |= I40E_AQC_ADD_VEB_FLOATING;
2584 if (default_port)
2585 veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DEFAULT;
2586 else
2587 veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DATA;
Kevin Scotte1c51b952013-11-20 10:02:51 +00002588
Shannon Nelson8a187f42016-01-13 16:51:41 -08002589 /* reverse logic here: set the bitflag to disable the stats */
2590 if (!enable_stats)
2591 veb_flags |= I40E_AQC_ADD_VEB_ENABLE_DISABLE_STATS;
Kevin Scotte1c51b952013-11-20 10:02:51 +00002592
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002593 cmd->veb_flags = cpu_to_le16(veb_flags);
2594
2595 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2596
2597 if (!status && veb_seid)
2598 *veb_seid = le16_to_cpu(resp->veb_seid);
2599
2600 return status;
2601}
2602
2603/**
2604 * i40e_aq_get_veb_parameters - Retrieve VEB parameters
2605 * @hw: pointer to the hw struct
2606 * @veb_seid: the SEID of the VEB to query
2607 * @switch_id: the uplink switch id
Jeff Kirsher98d44382013-12-21 05:44:42 +00002608 * @floating: set to true if the VEB is floating
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002609 * @statistic_index: index of the stats counter block for this VEB
2610 * @vebs_used: number of VEB's used by function
Jeff Kirsher98d44382013-12-21 05:44:42 +00002611 * @vebs_free: total VEB's not reserved by any function
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002612 * @cmd_details: pointer to command details structure or NULL
2613 *
2614 * This retrieves the parameters for a particular VEB, specified by
2615 * uplink_seid, and returns them to the caller.
2616 **/
2617i40e_status i40e_aq_get_veb_parameters(struct i40e_hw *hw,
2618 u16 veb_seid, u16 *switch_id,
2619 bool *floating, u16 *statistic_index,
2620 u16 *vebs_used, u16 *vebs_free,
2621 struct i40e_asq_cmd_details *cmd_details)
2622{
2623 struct i40e_aq_desc desc;
2624 struct i40e_aqc_get_veb_parameters_completion *cmd_resp =
2625 (struct i40e_aqc_get_veb_parameters_completion *)
2626 &desc.params.raw;
2627 i40e_status status;
2628
2629 if (veb_seid == 0)
2630 return I40E_ERR_PARAM;
2631
2632 i40e_fill_default_direct_cmd_desc(&desc,
2633 i40e_aqc_opc_get_veb_parameters);
2634 cmd_resp->seid = cpu_to_le16(veb_seid);
2635
2636 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2637 if (status)
2638 goto get_veb_exit;
2639
2640 if (switch_id)
2641 *switch_id = le16_to_cpu(cmd_resp->switch_id);
2642 if (statistic_index)
2643 *statistic_index = le16_to_cpu(cmd_resp->statistic_index);
2644 if (vebs_used)
2645 *vebs_used = le16_to_cpu(cmd_resp->vebs_used);
2646 if (vebs_free)
2647 *vebs_free = le16_to_cpu(cmd_resp->vebs_free);
2648 if (floating) {
2649 u16 flags = le16_to_cpu(cmd_resp->veb_flags);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04002650
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002651 if (flags & I40E_AQC_ADD_VEB_FLOATING)
2652 *floating = true;
2653 else
2654 *floating = false;
2655 }
2656
2657get_veb_exit:
2658 return status;
2659}
2660
2661/**
2662 * i40e_aq_add_macvlan
2663 * @hw: pointer to the hw struct
2664 * @seid: VSI for the mac address
2665 * @mv_list: list of macvlans to be added
2666 * @count: length of the list
2667 * @cmd_details: pointer to command details structure or NULL
2668 *
2669 * Add MAC/VLAN addresses to the HW filtering
2670 **/
2671i40e_status i40e_aq_add_macvlan(struct i40e_hw *hw, u16 seid,
2672 struct i40e_aqc_add_macvlan_element_data *mv_list,
2673 u16 count, struct i40e_asq_cmd_details *cmd_details)
2674{
2675 struct i40e_aq_desc desc;
2676 struct i40e_aqc_macvlan *cmd =
2677 (struct i40e_aqc_macvlan *)&desc.params.raw;
2678 i40e_status status;
2679 u16 buf_size;
Shannon Nelson67be6eb2016-01-13 16:51:40 -08002680 int i;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002681
2682 if (count == 0 || !mv_list || !hw)
2683 return I40E_ERR_PARAM;
2684
Shannon Nelson1efc80e2015-02-27 09:18:30 +00002685 buf_size = count * sizeof(*mv_list);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002686
2687 /* prep the rest of the request */
2688 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_macvlan);
2689 cmd->num_addresses = cpu_to_le16(count);
2690 cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
2691 cmd->seid[1] = 0;
2692 cmd->seid[2] = 0;
2693
Shannon Nelson67be6eb2016-01-13 16:51:40 -08002694 for (i = 0; i < count; i++)
2695 if (is_multicast_ether_addr(mv_list[i].mac_addr))
2696 mv_list[i].flags |=
2697 cpu_to_le16(I40E_AQC_MACVLAN_ADD_USE_SHARED_MAC);
2698
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002699 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
2700 if (buf_size > I40E_AQ_LARGE_BUF)
2701 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2702
2703 status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
Shannon Nelson67be6eb2016-01-13 16:51:40 -08002704 cmd_details);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002705
2706 return status;
2707}
2708
2709/**
2710 * i40e_aq_remove_macvlan
2711 * @hw: pointer to the hw struct
2712 * @seid: VSI for the mac address
2713 * @mv_list: list of macvlans to be removed
2714 * @count: length of the list
2715 * @cmd_details: pointer to command details structure or NULL
2716 *
2717 * Remove MAC/VLAN addresses from the HW filtering
2718 **/
2719i40e_status i40e_aq_remove_macvlan(struct i40e_hw *hw, u16 seid,
2720 struct i40e_aqc_remove_macvlan_element_data *mv_list,
2721 u16 count, struct i40e_asq_cmd_details *cmd_details)
2722{
2723 struct i40e_aq_desc desc;
2724 struct i40e_aqc_macvlan *cmd =
2725 (struct i40e_aqc_macvlan *)&desc.params.raw;
2726 i40e_status status;
2727 u16 buf_size;
2728
2729 if (count == 0 || !mv_list || !hw)
2730 return I40E_ERR_PARAM;
2731
Shannon Nelson1efc80e2015-02-27 09:18:30 +00002732 buf_size = count * sizeof(*mv_list);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002733
2734 /* prep the rest of the request */
2735 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_macvlan);
2736 cmd->num_addresses = cpu_to_le16(count);
2737 cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
2738 cmd->seid[1] = 0;
2739 cmd->seid[2] = 0;
2740
2741 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
2742 if (buf_size > I40E_AQ_LARGE_BUF)
2743 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2744
2745 status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
2746 cmd_details);
2747
2748 return status;
2749}
2750
2751/**
Kiran Patil7bd68752016-01-04 10:33:07 -08002752 * i40e_mirrorrule_op - Internal helper function to add/delete mirror rule
2753 * @hw: pointer to the hw struct
2754 * @opcode: AQ opcode for add or delete mirror rule
2755 * @sw_seid: Switch SEID (to which rule refers)
2756 * @rule_type: Rule Type (ingress/egress/VLAN)
2757 * @id: Destination VSI SEID or Rule ID
2758 * @count: length of the list
2759 * @mr_list: list of mirrored VSI SEIDs or VLAN IDs
2760 * @cmd_details: pointer to command details structure or NULL
2761 * @rule_id: Rule ID returned from FW
2762 * @rule_used: Number of rules used in internal switch
2763 * @rule_free: Number of rules free in internal switch
2764 *
2765 * Add/Delete a mirror rule to a specific switch. Mirror rules are supported for
2766 * VEBs/VEPA elements only
2767 **/
2768static i40e_status i40e_mirrorrule_op(struct i40e_hw *hw,
2769 u16 opcode, u16 sw_seid, u16 rule_type, u16 id,
2770 u16 count, __le16 *mr_list,
2771 struct i40e_asq_cmd_details *cmd_details,
2772 u16 *rule_id, u16 *rules_used, u16 *rules_free)
2773{
2774 struct i40e_aq_desc desc;
2775 struct i40e_aqc_add_delete_mirror_rule *cmd =
2776 (struct i40e_aqc_add_delete_mirror_rule *)&desc.params.raw;
2777 struct i40e_aqc_add_delete_mirror_rule_completion *resp =
2778 (struct i40e_aqc_add_delete_mirror_rule_completion *)&desc.params.raw;
2779 i40e_status status;
2780 u16 buf_size;
2781
2782 buf_size = count * sizeof(*mr_list);
2783
2784 /* prep the rest of the request */
2785 i40e_fill_default_direct_cmd_desc(&desc, opcode);
2786 cmd->seid = cpu_to_le16(sw_seid);
2787 cmd->rule_type = cpu_to_le16(rule_type &
2788 I40E_AQC_MIRROR_RULE_TYPE_MASK);
2789 cmd->num_entries = cpu_to_le16(count);
2790 /* Dest VSI for add, rule_id for delete */
2791 cmd->destination = cpu_to_le16(id);
2792 if (mr_list) {
2793 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
2794 I40E_AQ_FLAG_RD));
2795 if (buf_size > I40E_AQ_LARGE_BUF)
2796 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2797 }
2798
2799 status = i40e_asq_send_command(hw, &desc, mr_list, buf_size,
2800 cmd_details);
2801 if (!status ||
2802 hw->aq.asq_last_status == I40E_AQ_RC_ENOSPC) {
2803 if (rule_id)
2804 *rule_id = le16_to_cpu(resp->rule_id);
2805 if (rules_used)
2806 *rules_used = le16_to_cpu(resp->mirror_rules_used);
2807 if (rules_free)
2808 *rules_free = le16_to_cpu(resp->mirror_rules_free);
2809 }
2810 return status;
2811}
2812
2813/**
2814 * i40e_aq_add_mirrorrule - add a mirror rule
2815 * @hw: pointer to the hw struct
2816 * @sw_seid: Switch SEID (to which rule refers)
2817 * @rule_type: Rule Type (ingress/egress/VLAN)
2818 * @dest_vsi: SEID of VSI to which packets will be mirrored
2819 * @count: length of the list
2820 * @mr_list: list of mirrored VSI SEIDs or VLAN IDs
2821 * @cmd_details: pointer to command details structure or NULL
2822 * @rule_id: Rule ID returned from FW
2823 * @rule_used: Number of rules used in internal switch
2824 * @rule_free: Number of rules free in internal switch
2825 *
2826 * Add mirror rule. Mirror rules are supported for VEBs or VEPA elements only
2827 **/
2828i40e_status i40e_aq_add_mirrorrule(struct i40e_hw *hw, u16 sw_seid,
2829 u16 rule_type, u16 dest_vsi, u16 count, __le16 *mr_list,
2830 struct i40e_asq_cmd_details *cmd_details,
2831 u16 *rule_id, u16 *rules_used, u16 *rules_free)
2832{
2833 if (!(rule_type == I40E_AQC_MIRROR_RULE_TYPE_ALL_INGRESS ||
2834 rule_type == I40E_AQC_MIRROR_RULE_TYPE_ALL_EGRESS)) {
2835 if (count == 0 || !mr_list)
2836 return I40E_ERR_PARAM;
2837 }
2838
2839 return i40e_mirrorrule_op(hw, i40e_aqc_opc_add_mirror_rule, sw_seid,
2840 rule_type, dest_vsi, count, mr_list,
2841 cmd_details, rule_id, rules_used, rules_free);
2842}
2843
2844/**
2845 * i40e_aq_delete_mirrorrule - delete a mirror rule
2846 * @hw: pointer to the hw struct
2847 * @sw_seid: Switch SEID (to which rule refers)
2848 * @rule_type: Rule Type (ingress/egress/VLAN)
2849 * @count: length of the list
2850 * @rule_id: Rule ID that is returned in the receive desc as part of
2851 * add_mirrorrule.
2852 * @mr_list: list of mirrored VLAN IDs to be removed
2853 * @cmd_details: pointer to command details structure or NULL
2854 * @rule_used: Number of rules used in internal switch
2855 * @rule_free: Number of rules free in internal switch
2856 *
2857 * Delete a mirror rule. Mirror rules are supported for VEBs/VEPA elements only
2858 **/
2859i40e_status i40e_aq_delete_mirrorrule(struct i40e_hw *hw, u16 sw_seid,
2860 u16 rule_type, u16 rule_id, u16 count, __le16 *mr_list,
2861 struct i40e_asq_cmd_details *cmd_details,
2862 u16 *rules_used, u16 *rules_free)
2863{
2864 /* Rule ID has to be valid except rule_type: INGRESS VLAN mirroring */
Greg Rosedb077272016-04-12 08:30:48 -07002865 if (rule_type == I40E_AQC_MIRROR_RULE_TYPE_VLAN) {
Kiran Patil7bd68752016-01-04 10:33:07 -08002866 /* count and mr_list shall be valid for rule_type INGRESS VLAN
2867 * mirroring. For other rule_type, count and rule_type should
2868 * not matter.
2869 */
2870 if (count == 0 || !mr_list)
2871 return I40E_ERR_PARAM;
2872 }
2873
2874 return i40e_mirrorrule_op(hw, i40e_aqc_opc_delete_mirror_rule, sw_seid,
2875 rule_type, rule_id, count, mr_list,
2876 cmd_details, NULL, rules_used, rules_free);
2877}
2878
2879/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002880 * i40e_aq_send_msg_to_vf
2881 * @hw: pointer to the hardware structure
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00002882 * @vfid: VF id to send msg
Jeff Kirsher98d44382013-12-21 05:44:42 +00002883 * @v_opcode: opcodes for VF-PF communication
2884 * @v_retval: return error code
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002885 * @msg: pointer to the msg buffer
2886 * @msglen: msg length
2887 * @cmd_details: pointer to command details
2888 *
2889 * send msg to vf
2890 **/
2891i40e_status i40e_aq_send_msg_to_vf(struct i40e_hw *hw, u16 vfid,
2892 u32 v_opcode, u32 v_retval, u8 *msg, u16 msglen,
2893 struct i40e_asq_cmd_details *cmd_details)
2894{
2895 struct i40e_aq_desc desc;
2896 struct i40e_aqc_pf_vf_message *cmd =
2897 (struct i40e_aqc_pf_vf_message *)&desc.params.raw;
2898 i40e_status status;
2899
2900 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_vf);
2901 cmd->id = cpu_to_le32(vfid);
2902 desc.cookie_high = cpu_to_le32(v_opcode);
2903 desc.cookie_low = cpu_to_le32(v_retval);
2904 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_SI);
2905 if (msglen) {
2906 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
2907 I40E_AQ_FLAG_RD));
2908 if (msglen > I40E_AQ_LARGE_BUF)
2909 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2910 desc.datalen = cpu_to_le16(msglen);
2911 }
2912 status = i40e_asq_send_command(hw, &desc, msg, msglen, cmd_details);
2913
2914 return status;
2915}
2916
2917/**
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002918 * i40e_aq_debug_read_register
2919 * @hw: pointer to the hw struct
2920 * @reg_addr: register address
2921 * @reg_val: register value
2922 * @cmd_details: pointer to command details structure or NULL
2923 *
2924 * Read the register using the admin queue commands
2925 **/
2926i40e_status i40e_aq_debug_read_register(struct i40e_hw *hw,
Jesse Brandeburg7b115dd2015-02-27 09:15:23 +00002927 u32 reg_addr, u64 *reg_val,
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002928 struct i40e_asq_cmd_details *cmd_details)
2929{
2930 struct i40e_aq_desc desc;
2931 struct i40e_aqc_debug_reg_read_write *cmd_resp =
2932 (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
2933 i40e_status status;
2934
2935 if (reg_val == NULL)
2936 return I40E_ERR_PARAM;
2937
Jesse Brandeburg7b115dd2015-02-27 09:15:23 +00002938 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_read_reg);
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002939
2940 cmd_resp->address = cpu_to_le32(reg_addr);
2941
2942 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2943
2944 if (!status) {
Jesse Brandeburg7b115dd2015-02-27 09:15:23 +00002945 *reg_val = ((u64)le32_to_cpu(cmd_resp->value_high) << 32) |
2946 (u64)le32_to_cpu(cmd_resp->value_low);
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002947 }
2948
2949 return status;
2950}
2951
2952/**
Shannon Nelson53db45c2014-08-01 13:27:05 -07002953 * i40e_aq_debug_write_register
2954 * @hw: pointer to the hw struct
2955 * @reg_addr: register address
2956 * @reg_val: register value
2957 * @cmd_details: pointer to command details structure or NULL
2958 *
2959 * Write to a register using the admin queue commands
2960 **/
2961i40e_status i40e_aq_debug_write_register(struct i40e_hw *hw,
2962 u32 reg_addr, u64 reg_val,
2963 struct i40e_asq_cmd_details *cmd_details)
2964{
2965 struct i40e_aq_desc desc;
2966 struct i40e_aqc_debug_reg_read_write *cmd =
2967 (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
2968 i40e_status status;
2969
2970 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_write_reg);
2971
2972 cmd->address = cpu_to_le32(reg_addr);
2973 cmd->value_high = cpu_to_le32((u32)(reg_val >> 32));
2974 cmd->value_low = cpu_to_le32((u32)(reg_val & 0xFFFFFFFF));
2975
2976 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2977
2978 return status;
2979}
2980
2981/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002982 * i40e_aq_request_resource
2983 * @hw: pointer to the hw struct
2984 * @resource: resource id
2985 * @access: access type
2986 * @sdp_number: resource number
2987 * @timeout: the maximum time in ms that the driver may hold the resource
2988 * @cmd_details: pointer to command details structure or NULL
2989 *
2990 * requests common resource using the admin queue commands
2991 **/
2992i40e_status i40e_aq_request_resource(struct i40e_hw *hw,
2993 enum i40e_aq_resources_ids resource,
2994 enum i40e_aq_resource_access_type access,
2995 u8 sdp_number, u64 *timeout,
2996 struct i40e_asq_cmd_details *cmd_details)
2997{
2998 struct i40e_aq_desc desc;
2999 struct i40e_aqc_request_resource *cmd_resp =
3000 (struct i40e_aqc_request_resource *)&desc.params.raw;
3001 i40e_status status;
3002
3003 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_request_resource);
3004
3005 cmd_resp->resource_id = cpu_to_le16(resource);
3006 cmd_resp->access_type = cpu_to_le16(access);
3007 cmd_resp->resource_number = cpu_to_le32(sdp_number);
3008
3009 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3010 /* The completion specifies the maximum time in ms that the driver
3011 * may hold the resource in the Timeout field.
3012 * If the resource is held by someone else, the command completes with
3013 * busy return value and the timeout field indicates the maximum time
3014 * the current owner of the resource has to free it.
3015 */
3016 if (!status || hw->aq.asq_last_status == I40E_AQ_RC_EBUSY)
3017 *timeout = le32_to_cpu(cmd_resp->timeout);
3018
3019 return status;
3020}
3021
3022/**
3023 * i40e_aq_release_resource
3024 * @hw: pointer to the hw struct
3025 * @resource: resource id
3026 * @sdp_number: resource number
3027 * @cmd_details: pointer to command details structure or NULL
3028 *
3029 * release common resource using the admin queue commands
3030 **/
3031i40e_status i40e_aq_release_resource(struct i40e_hw *hw,
3032 enum i40e_aq_resources_ids resource,
3033 u8 sdp_number,
3034 struct i40e_asq_cmd_details *cmd_details)
3035{
3036 struct i40e_aq_desc desc;
3037 struct i40e_aqc_request_resource *cmd =
3038 (struct i40e_aqc_request_resource *)&desc.params.raw;
3039 i40e_status status;
3040
3041 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_release_resource);
3042
3043 cmd->resource_id = cpu_to_le16(resource);
3044 cmd->resource_number = cpu_to_le32(sdp_number);
3045
3046 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3047
3048 return status;
3049}
3050
3051/**
3052 * i40e_aq_read_nvm
3053 * @hw: pointer to the hw struct
3054 * @module_pointer: module pointer location in words from the NVM beginning
3055 * @offset: byte offset from the module beginning
3056 * @length: length of the section to be read (in bytes from the offset)
3057 * @data: command buffer (size [bytes] = length)
3058 * @last_command: tells if this is the last command in a series
3059 * @cmd_details: pointer to command details structure or NULL
3060 *
3061 * Read the NVM using the admin queue commands
3062 **/
3063i40e_status i40e_aq_read_nvm(struct i40e_hw *hw, u8 module_pointer,
3064 u32 offset, u16 length, void *data,
3065 bool last_command,
3066 struct i40e_asq_cmd_details *cmd_details)
3067{
3068 struct i40e_aq_desc desc;
3069 struct i40e_aqc_nvm_update *cmd =
3070 (struct i40e_aqc_nvm_update *)&desc.params.raw;
3071 i40e_status status;
3072
3073 /* In offset the highest byte must be zeroed. */
3074 if (offset & 0xFF000000) {
3075 status = I40E_ERR_PARAM;
3076 goto i40e_aq_read_nvm_exit;
3077 }
3078
3079 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_read);
3080
3081 /* If this is the last command in a series, set the proper flag. */
3082 if (last_command)
3083 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
3084 cmd->module_pointer = module_pointer;
3085 cmd->offset = cpu_to_le32(offset);
3086 cmd->length = cpu_to_le16(length);
3087
3088 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3089 if (length > I40E_AQ_LARGE_BUF)
3090 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3091
3092 status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
3093
3094i40e_aq_read_nvm_exit:
3095 return status;
3096}
3097
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003098/**
3099 * i40e_aq_erase_nvm
3100 * @hw: pointer to the hw struct
3101 * @module_pointer: module pointer location in words from the NVM beginning
3102 * @offset: offset in the module (expressed in 4 KB from module's beginning)
3103 * @length: length of the section to be erased (expressed in 4 KB)
3104 * @last_command: tells if this is the last command in a series
3105 * @cmd_details: pointer to command details structure or NULL
3106 *
3107 * Erase the NVM sector using the admin queue commands
3108 **/
3109i40e_status i40e_aq_erase_nvm(struct i40e_hw *hw, u8 module_pointer,
3110 u32 offset, u16 length, bool last_command,
3111 struct i40e_asq_cmd_details *cmd_details)
3112{
3113 struct i40e_aq_desc desc;
3114 struct i40e_aqc_nvm_update *cmd =
3115 (struct i40e_aqc_nvm_update *)&desc.params.raw;
3116 i40e_status status;
3117
3118 /* In offset the highest byte must be zeroed. */
3119 if (offset & 0xFF000000) {
3120 status = I40E_ERR_PARAM;
3121 goto i40e_aq_erase_nvm_exit;
3122 }
3123
3124 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_erase);
3125
3126 /* If this is the last command in a series, set the proper flag. */
3127 if (last_command)
3128 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
3129 cmd->module_pointer = module_pointer;
3130 cmd->offset = cpu_to_le32(offset);
3131 cmd->length = cpu_to_le16(length);
3132
3133 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3134
3135i40e_aq_erase_nvm_exit:
3136 return status;
3137}
3138
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003139/**
3140 * i40e_parse_discover_capabilities
3141 * @hw: pointer to the hw struct
3142 * @buff: pointer to a buffer containing device/function capability records
3143 * @cap_count: number of capability records in the list
3144 * @list_type_opc: type of capabilities list to parse
3145 *
3146 * Parse the device/function capabilities list.
3147 **/
3148static void i40e_parse_discover_capabilities(struct i40e_hw *hw, void *buff,
3149 u32 cap_count,
3150 enum i40e_admin_queue_opc list_type_opc)
3151{
3152 struct i40e_aqc_list_capabilities_element_resp *cap;
Shannon Nelson9fee9db2014-12-11 07:06:30 +00003153 u32 valid_functions, num_functions;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003154 u32 number, logical_id, phys_id;
3155 struct i40e_hw_capabilities *p;
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003156 u8 major_rev;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003157 u32 i = 0;
3158 u16 id;
3159
3160 cap = (struct i40e_aqc_list_capabilities_element_resp *) buff;
3161
3162 if (list_type_opc == i40e_aqc_opc_list_dev_capabilities)
Joe Perchesb58f2f72014-03-25 04:30:32 +00003163 p = &hw->dev_caps;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003164 else if (list_type_opc == i40e_aqc_opc_list_func_capabilities)
Joe Perchesb58f2f72014-03-25 04:30:32 +00003165 p = &hw->func_caps;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003166 else
3167 return;
3168
3169 for (i = 0; i < cap_count; i++, cap++) {
3170 id = le16_to_cpu(cap->id);
3171 number = le32_to_cpu(cap->number);
3172 logical_id = le32_to_cpu(cap->logical_id);
3173 phys_id = le32_to_cpu(cap->phys_id);
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003174 major_rev = cap->major_rev;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003175
3176 switch (id) {
Shannon Nelson406e7342015-12-10 11:38:49 -08003177 case I40E_AQ_CAP_ID_SWITCH_MODE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003178 p->switch_mode = number;
3179 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003180 case I40E_AQ_CAP_ID_MNG_MODE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003181 p->management_mode = number;
Piotr Raczynski64f5ead2016-10-25 16:08:53 -07003182 if (major_rev > 1) {
3183 p->mng_protocols_over_mctp = logical_id;
3184 i40e_debug(hw, I40E_DEBUG_INIT,
3185 "HW Capability: Protocols over MCTP = %d\n",
3186 p->mng_protocols_over_mctp);
3187 } else {
3188 p->mng_protocols_over_mctp = 0;
3189 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003190 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003191 case I40E_AQ_CAP_ID_NPAR_ACTIVE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003192 p->npar_enable = number;
3193 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003194 case I40E_AQ_CAP_ID_OS2BMC_CAP:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003195 p->os2bmc = number;
3196 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003197 case I40E_AQ_CAP_ID_FUNCTIONS_VALID:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003198 p->valid_functions = number;
3199 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003200 case I40E_AQ_CAP_ID_SRIOV:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003201 if (number == 1)
3202 p->sr_iov_1_1 = true;
3203 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003204 case I40E_AQ_CAP_ID_VF:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003205 p->num_vfs = number;
3206 p->vf_base_id = logical_id;
3207 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003208 case I40E_AQ_CAP_ID_VMDQ:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003209 if (number == 1)
3210 p->vmdq = true;
3211 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003212 case I40E_AQ_CAP_ID_8021QBG:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003213 if (number == 1)
3214 p->evb_802_1_qbg = true;
3215 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003216 case I40E_AQ_CAP_ID_8021QBR:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003217 if (number == 1)
3218 p->evb_802_1_qbh = true;
3219 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003220 case I40E_AQ_CAP_ID_VSI:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003221 p->num_vsis = number;
3222 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003223 case I40E_AQ_CAP_ID_DCB:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003224 if (number == 1) {
3225 p->dcb = true;
3226 p->enabled_tcmap = logical_id;
3227 p->maxtc = phys_id;
3228 }
3229 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003230 case I40E_AQ_CAP_ID_FCOE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003231 if (number == 1)
3232 p->fcoe = true;
3233 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003234 case I40E_AQ_CAP_ID_ISCSI:
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00003235 if (number == 1)
3236 p->iscsi = true;
3237 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003238 case I40E_AQ_CAP_ID_RSS:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003239 p->rss = true;
Carolyn Wybornye157ea32014-06-03 23:50:22 +00003240 p->rss_table_size = number;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003241 p->rss_table_entry_width = logical_id;
3242 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003243 case I40E_AQ_CAP_ID_RXQ:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003244 p->num_rx_qp = number;
3245 p->base_queue = phys_id;
3246 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003247 case I40E_AQ_CAP_ID_TXQ:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003248 p->num_tx_qp = number;
3249 p->base_queue = phys_id;
3250 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003251 case I40E_AQ_CAP_ID_MSIX:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003252 p->num_msix_vectors = number;
Deepthi Kavalur453e16e2016-04-01 03:56:01 -07003253 i40e_debug(hw, I40E_DEBUG_INIT,
3254 "HW Capability: MSIX vector count = %d\n",
3255 p->num_msix_vectors);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003256 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003257 case I40E_AQ_CAP_ID_VF_MSIX:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003258 p->num_msix_vectors_vf = number;
3259 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003260 case I40E_AQ_CAP_ID_FLEX10:
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003261 if (major_rev == 1) {
3262 if (number == 1) {
3263 p->flex10_enable = true;
3264 p->flex10_capable = true;
3265 }
3266 } else {
3267 /* Capability revision >= 2 */
3268 if (number & 1)
3269 p->flex10_enable = true;
3270 if (number & 2)
3271 p->flex10_capable = true;
3272 }
3273 p->flex10_mode = logical_id;
3274 p->flex10_status = phys_id;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003275 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003276 case I40E_AQ_CAP_ID_CEM:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003277 if (number == 1)
3278 p->mgmt_cem = true;
3279 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003280 case I40E_AQ_CAP_ID_IWARP:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003281 if (number == 1)
3282 p->iwarp = true;
3283 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003284 case I40E_AQ_CAP_ID_LED:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003285 if (phys_id < I40E_HW_CAP_MAX_GPIO)
3286 p->led[phys_id] = true;
3287 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003288 case I40E_AQ_CAP_ID_SDP:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003289 if (phys_id < I40E_HW_CAP_MAX_GPIO)
3290 p->sdp[phys_id] = true;
3291 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003292 case I40E_AQ_CAP_ID_MDIO:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003293 if (number == 1) {
3294 p->mdio_port_num = phys_id;
3295 p->mdio_port_mode = logical_id;
3296 }
3297 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003298 case I40E_AQ_CAP_ID_1588:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003299 if (number == 1)
3300 p->ieee_1588 = true;
3301 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003302 case I40E_AQ_CAP_ID_FLOW_DIRECTOR:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003303 p->fd = true;
3304 p->fd_filters_guaranteed = number;
3305 p->fd_filters_best_effort = logical_id;
3306 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003307 case I40E_AQ_CAP_ID_WSR_PROT:
Kevin Scott73b23402015-04-07 19:45:38 -04003308 p->wr_csr_prot = (u64)number;
3309 p->wr_csr_prot |= (u64)logical_id << 32;
3310 break;
Michal Kosiarz68a1c5a2016-04-12 08:30:46 -07003311 case I40E_AQ_CAP_ID_NVM_MGMT:
3312 if (number & I40E_NVM_MGMT_SEC_REV_DISABLED)
3313 p->sec_rev_disabled = true;
3314 if (number & I40E_NVM_MGMT_UPDATE_DISABLED)
3315 p->update_disabled = true;
3316 break;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003317 default:
3318 break;
3319 }
3320 }
3321
Vasu Devf18ae102015-04-07 19:45:36 -04003322 if (p->fcoe)
3323 i40e_debug(hw, I40E_DEBUG_ALL, "device is FCoE capable\n");
3324
Vasu Dev566bb852014-04-09 05:59:06 +00003325 /* Software override ensuring FCoE is disabled if npar or mfp
3326 * mode because it is not supported in these modes.
3327 */
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003328 if (p->npar_enable || p->flex10_enable)
Vasu Dev566bb852014-04-09 05:59:06 +00003329 p->fcoe = false;
3330
Shannon Nelson9fee9db2014-12-11 07:06:30 +00003331 /* count the enabled ports (aka the "not disabled" ports) */
3332 hw->num_ports = 0;
3333 for (i = 0; i < 4; i++) {
3334 u32 port_cfg_reg = I40E_PRTGEN_CNF + (4 * i);
3335 u64 port_cfg = 0;
3336
3337 /* use AQ read to get the physical register offset instead
3338 * of the port relative offset
3339 */
3340 i40e_aq_debug_read_register(hw, port_cfg_reg, &port_cfg, NULL);
3341 if (!(port_cfg & I40E_PRTGEN_CNF_PORT_DIS_MASK))
3342 hw->num_ports++;
3343 }
3344
3345 valid_functions = p->valid_functions;
3346 num_functions = 0;
3347 while (valid_functions) {
3348 if (valid_functions & 1)
3349 num_functions++;
3350 valid_functions >>= 1;
3351 }
3352
3353 /* partition id is 1-based, and functions are evenly spread
3354 * across the ports as partitions
3355 */
Michal Kosiarz999b3152016-10-11 15:26:56 -07003356 if (hw->num_ports != 0) {
3357 hw->partition_id = (hw->pf_id / hw->num_ports) + 1;
3358 hw->num_partitions = num_functions / hw->num_ports;
3359 }
Shannon Nelson9fee9db2014-12-11 07:06:30 +00003360
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003361 /* additional HW specific goodies that might
3362 * someday be HW version specific
3363 */
3364 p->rx_buf_chain_len = I40E_MAX_CHAINED_RX_BUFFERS;
3365}
3366
3367/**
3368 * i40e_aq_discover_capabilities
3369 * @hw: pointer to the hw struct
3370 * @buff: a virtual buffer to hold the capabilities
3371 * @buff_size: Size of the virtual buffer
3372 * @data_size: Size of the returned data, or buff size needed if AQ err==ENOMEM
3373 * @list_type_opc: capabilities type to discover - pass in the command opcode
3374 * @cmd_details: pointer to command details structure or NULL
3375 *
3376 * Get the device capabilities descriptions from the firmware
3377 **/
3378i40e_status i40e_aq_discover_capabilities(struct i40e_hw *hw,
3379 void *buff, u16 buff_size, u16 *data_size,
3380 enum i40e_admin_queue_opc list_type_opc,
3381 struct i40e_asq_cmd_details *cmd_details)
3382{
3383 struct i40e_aqc_list_capabilites *cmd;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003384 struct i40e_aq_desc desc;
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08003385 i40e_status status = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003386
3387 cmd = (struct i40e_aqc_list_capabilites *)&desc.params.raw;
3388
3389 if (list_type_opc != i40e_aqc_opc_list_func_capabilities &&
3390 list_type_opc != i40e_aqc_opc_list_dev_capabilities) {
3391 status = I40E_ERR_PARAM;
3392 goto exit;
3393 }
3394
3395 i40e_fill_default_direct_cmd_desc(&desc, list_type_opc);
3396
3397 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3398 if (buff_size > I40E_AQ_LARGE_BUF)
3399 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3400
3401 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3402 *data_size = le16_to_cpu(desc.datalen);
3403
3404 if (status)
3405 goto exit;
3406
3407 i40e_parse_discover_capabilities(hw, buff, le32_to_cpu(cmd->count),
3408 list_type_opc);
3409
3410exit:
3411 return status;
3412}
3413
3414/**
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003415 * i40e_aq_update_nvm
3416 * @hw: pointer to the hw struct
3417 * @module_pointer: module pointer location in words from the NVM beginning
3418 * @offset: byte offset from the module beginning
3419 * @length: length of the section to be written (in bytes from the offset)
3420 * @data: command buffer (size [bytes] = length)
3421 * @last_command: tells if this is the last command in a series
3422 * @cmd_details: pointer to command details structure or NULL
3423 *
3424 * Update the NVM using the admin queue commands
3425 **/
3426i40e_status i40e_aq_update_nvm(struct i40e_hw *hw, u8 module_pointer,
3427 u32 offset, u16 length, void *data,
3428 bool last_command,
3429 struct i40e_asq_cmd_details *cmd_details)
3430{
3431 struct i40e_aq_desc desc;
3432 struct i40e_aqc_nvm_update *cmd =
3433 (struct i40e_aqc_nvm_update *)&desc.params.raw;
3434 i40e_status status;
3435
3436 /* In offset the highest byte must be zeroed. */
3437 if (offset & 0xFF000000) {
3438 status = I40E_ERR_PARAM;
3439 goto i40e_aq_update_nvm_exit;
3440 }
3441
3442 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_update);
3443
3444 /* If this is the last command in a series, set the proper flag. */
3445 if (last_command)
3446 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
3447 cmd->module_pointer = module_pointer;
3448 cmd->offset = cpu_to_le32(offset);
3449 cmd->length = cpu_to_le16(length);
3450
3451 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
3452 if (length > I40E_AQ_LARGE_BUF)
3453 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3454
3455 status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
3456
3457i40e_aq_update_nvm_exit:
3458 return status;
3459}
3460
3461/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003462 * i40e_aq_get_lldp_mib
3463 * @hw: pointer to the hw struct
3464 * @bridge_type: type of bridge requested
3465 * @mib_type: Local, Remote or both Local and Remote MIBs
3466 * @buff: pointer to a user supplied buffer to store the MIB block
3467 * @buff_size: size of the buffer (in bytes)
3468 * @local_len : length of the returned Local LLDP MIB
3469 * @remote_len: length of the returned Remote LLDP MIB
3470 * @cmd_details: pointer to command details structure or NULL
3471 *
3472 * Requests the complete LLDP MIB (entire packet).
3473 **/
3474i40e_status i40e_aq_get_lldp_mib(struct i40e_hw *hw, u8 bridge_type,
3475 u8 mib_type, void *buff, u16 buff_size,
3476 u16 *local_len, u16 *remote_len,
3477 struct i40e_asq_cmd_details *cmd_details)
3478{
3479 struct i40e_aq_desc desc;
3480 struct i40e_aqc_lldp_get_mib *cmd =
3481 (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
3482 struct i40e_aqc_lldp_get_mib *resp =
3483 (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
3484 i40e_status status;
3485
3486 if (buff_size == 0 || !buff)
3487 return I40E_ERR_PARAM;
3488
3489 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_get_mib);
3490 /* Indirect Command */
3491 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3492
3493 cmd->type = mib_type & I40E_AQ_LLDP_MIB_TYPE_MASK;
3494 cmd->type |= ((bridge_type << I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) &
3495 I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
3496
3497 desc.datalen = cpu_to_le16(buff_size);
3498
3499 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3500 if (buff_size > I40E_AQ_LARGE_BUF)
3501 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3502
3503 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3504 if (!status) {
3505 if (local_len != NULL)
3506 *local_len = le16_to_cpu(resp->local_len);
3507 if (remote_len != NULL)
3508 *remote_len = le16_to_cpu(resp->remote_len);
3509 }
3510
3511 return status;
3512}
3513
3514/**
3515 * i40e_aq_cfg_lldp_mib_change_event
3516 * @hw: pointer to the hw struct
3517 * @enable_update: Enable or Disable event posting
3518 * @cmd_details: pointer to command details structure or NULL
3519 *
3520 * Enable or Disable posting of an event on ARQ when LLDP MIB
3521 * associated with the interface changes
3522 **/
3523i40e_status i40e_aq_cfg_lldp_mib_change_event(struct i40e_hw *hw,
3524 bool enable_update,
3525 struct i40e_asq_cmd_details *cmd_details)
3526{
3527 struct i40e_aq_desc desc;
3528 struct i40e_aqc_lldp_update_mib *cmd =
3529 (struct i40e_aqc_lldp_update_mib *)&desc.params.raw;
3530 i40e_status status;
3531
3532 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_update_mib);
3533
3534 if (!enable_update)
3535 cmd->command |= I40E_AQ_LLDP_MIB_UPDATE_DISABLE;
3536
3537 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3538
3539 return status;
3540}
3541
3542/**
3543 * i40e_aq_stop_lldp
3544 * @hw: pointer to the hw struct
3545 * @shutdown_agent: True if LLDP Agent needs to be Shutdown
3546 * @cmd_details: pointer to command details structure or NULL
3547 *
3548 * Stop or Shutdown the embedded LLDP Agent
3549 **/
3550i40e_status i40e_aq_stop_lldp(struct i40e_hw *hw, bool shutdown_agent,
3551 struct i40e_asq_cmd_details *cmd_details)
3552{
3553 struct i40e_aq_desc desc;
3554 struct i40e_aqc_lldp_stop *cmd =
3555 (struct i40e_aqc_lldp_stop *)&desc.params.raw;
3556 i40e_status status;
3557
3558 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_stop);
3559
3560 if (shutdown_agent)
3561 cmd->command |= I40E_AQ_LLDP_AGENT_SHUTDOWN;
3562
3563 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3564
3565 return status;
3566}
3567
3568/**
3569 * i40e_aq_start_lldp
3570 * @hw: pointer to the hw struct
3571 * @cmd_details: pointer to command details structure or NULL
3572 *
3573 * Start the embedded LLDP Agent on all ports.
3574 **/
3575i40e_status i40e_aq_start_lldp(struct i40e_hw *hw,
3576 struct i40e_asq_cmd_details *cmd_details)
3577{
3578 struct i40e_aq_desc desc;
3579 struct i40e_aqc_lldp_start *cmd =
3580 (struct i40e_aqc_lldp_start *)&desc.params.raw;
3581 i40e_status status;
3582
3583 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_start);
3584
3585 cmd->command = I40E_AQ_LLDP_AGENT_START;
3586
3587 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3588
3589 return status;
3590}
3591
3592/**
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00003593 * i40e_aq_get_cee_dcb_config
3594 * @hw: pointer to the hw struct
3595 * @buff: response buffer that stores CEE operational configuration
3596 * @buff_size: size of the buffer passed
3597 * @cmd_details: pointer to command details structure or NULL
3598 *
3599 * Get CEE DCBX mode operational configuration from firmware
3600 **/
3601i40e_status i40e_aq_get_cee_dcb_config(struct i40e_hw *hw,
3602 void *buff, u16 buff_size,
3603 struct i40e_asq_cmd_details *cmd_details)
3604{
3605 struct i40e_aq_desc desc;
3606 i40e_status status;
3607
3608 if (buff_size == 0 || !buff)
3609 return I40E_ERR_PARAM;
3610
3611 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_cee_dcb_cfg);
3612
3613 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3614 status = i40e_asq_send_command(hw, &desc, (void *)buff, buff_size,
3615 cmd_details);
3616
3617 return status;
3618}
3619
3620/**
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003621 * i40e_aq_add_udp_tunnel
3622 * @hw: pointer to the hw struct
Jacob Keller15d23b42017-06-07 05:43:04 -04003623 * @udp_port: the UDP port to add in Host byte order
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003624 * @header_len: length of the tunneling header length in DWords
3625 * @protocol_index: protocol index type
Jeff Kirsher98d44382013-12-21 05:44:42 +00003626 * @filter_index: pointer to filter index
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003627 * @cmd_details: pointer to command details structure or NULL
Jacob Keller15d23b42017-06-07 05:43:04 -04003628 *
3629 * Note: Firmware expects the udp_port value to be in Little Endian format,
3630 * and this function will call cpu_to_le16 to convert from Host byte order to
3631 * Little Endian order.
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003632 **/
3633i40e_status i40e_aq_add_udp_tunnel(struct i40e_hw *hw,
Kevin Scottf4f94b92014-04-05 07:46:10 +00003634 u16 udp_port, u8 protocol_index,
3635 u8 *filter_index,
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003636 struct i40e_asq_cmd_details *cmd_details)
3637{
3638 struct i40e_aq_desc desc;
3639 struct i40e_aqc_add_udp_tunnel *cmd =
3640 (struct i40e_aqc_add_udp_tunnel *)&desc.params.raw;
3641 struct i40e_aqc_del_udp_tunnel_completion *resp =
3642 (struct i40e_aqc_del_udp_tunnel_completion *)&desc.params.raw;
3643 i40e_status status;
3644
3645 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_udp_tunnel);
3646
3647 cmd->udp_port = cpu_to_le16(udp_port);
Shannon Nelson981b7542013-12-11 08:17:11 +00003648 cmd->protocol_type = protocol_index;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003649
3650 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3651
Shannon Nelson65d13462015-02-21 06:45:28 +00003652 if (!status && filter_index)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003653 *filter_index = resp->index;
3654
3655 return status;
3656}
3657
3658/**
3659 * i40e_aq_del_udp_tunnel
3660 * @hw: pointer to the hw struct
3661 * @index: filter index
3662 * @cmd_details: pointer to command details structure or NULL
3663 **/
3664i40e_status i40e_aq_del_udp_tunnel(struct i40e_hw *hw, u8 index,
3665 struct i40e_asq_cmd_details *cmd_details)
3666{
3667 struct i40e_aq_desc desc;
3668 struct i40e_aqc_remove_udp_tunnel *cmd =
3669 (struct i40e_aqc_remove_udp_tunnel *)&desc.params.raw;
3670 i40e_status status;
3671
3672 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_del_udp_tunnel);
3673
3674 cmd->index = index;
3675
3676 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3677
3678 return status;
3679}
3680
3681/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003682 * i40e_aq_delete_element - Delete switch element
3683 * @hw: pointer to the hw struct
3684 * @seid: the SEID to delete from the switch
3685 * @cmd_details: pointer to command details structure or NULL
3686 *
3687 * This deletes a switch element from the switch.
3688 **/
3689i40e_status i40e_aq_delete_element(struct i40e_hw *hw, u16 seid,
3690 struct i40e_asq_cmd_details *cmd_details)
3691{
3692 struct i40e_aq_desc desc;
3693 struct i40e_aqc_switch_seid *cmd =
3694 (struct i40e_aqc_switch_seid *)&desc.params.raw;
3695 i40e_status status;
3696
3697 if (seid == 0)
3698 return I40E_ERR_PARAM;
3699
3700 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_delete_element);
3701
3702 cmd->seid = cpu_to_le16(seid);
3703
3704 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3705
3706 return status;
3707}
3708
3709/**
Neerav Parikhafb3ff02014-01-17 15:36:36 -08003710 * i40e_aq_dcb_updated - DCB Updated Command
3711 * @hw: pointer to the hw struct
3712 * @cmd_details: pointer to command details structure or NULL
3713 *
3714 * EMP will return when the shared RPB settings have been
3715 * recomputed and modified. The retval field in the descriptor
3716 * will be set to 0 when RPB is modified.
3717 **/
3718i40e_status i40e_aq_dcb_updated(struct i40e_hw *hw,
3719 struct i40e_asq_cmd_details *cmd_details)
3720{
3721 struct i40e_aq_desc desc;
3722 i40e_status status;
3723
3724 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_dcb_updated);
3725
3726 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3727
3728 return status;
3729}
3730
3731/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003732 * i40e_aq_tx_sched_cmd - generic Tx scheduler AQ command handler
3733 * @hw: pointer to the hw struct
3734 * @seid: seid for the physical port/switching component/vsi
3735 * @buff: Indirect buffer to hold data parameters and response
3736 * @buff_size: Indirect buffer size
3737 * @opcode: Tx scheduler AQ command opcode
3738 * @cmd_details: pointer to command details structure or NULL
3739 *
3740 * Generic command handler for Tx scheduler AQ commands
3741 **/
3742static i40e_status i40e_aq_tx_sched_cmd(struct i40e_hw *hw, u16 seid,
3743 void *buff, u16 buff_size,
3744 enum i40e_admin_queue_opc opcode,
3745 struct i40e_asq_cmd_details *cmd_details)
3746{
3747 struct i40e_aq_desc desc;
3748 struct i40e_aqc_tx_sched_ind *cmd =
3749 (struct i40e_aqc_tx_sched_ind *)&desc.params.raw;
3750 i40e_status status;
3751 bool cmd_param_flag = false;
3752
3753 switch (opcode) {
3754 case i40e_aqc_opc_configure_vsi_ets_sla_bw_limit:
3755 case i40e_aqc_opc_configure_vsi_tc_bw:
3756 case i40e_aqc_opc_enable_switching_comp_ets:
3757 case i40e_aqc_opc_modify_switching_comp_ets:
3758 case i40e_aqc_opc_disable_switching_comp_ets:
3759 case i40e_aqc_opc_configure_switching_comp_ets_bw_limit:
3760 case i40e_aqc_opc_configure_switching_comp_bw_config:
3761 cmd_param_flag = true;
3762 break;
3763 case i40e_aqc_opc_query_vsi_bw_config:
3764 case i40e_aqc_opc_query_vsi_ets_sla_config:
3765 case i40e_aqc_opc_query_switching_comp_ets_config:
3766 case i40e_aqc_opc_query_port_ets_config:
3767 case i40e_aqc_opc_query_switching_comp_bw_config:
3768 cmd_param_flag = false;
3769 break;
3770 default:
3771 return I40E_ERR_PARAM;
3772 }
3773
3774 i40e_fill_default_direct_cmd_desc(&desc, opcode);
3775
3776 /* Indirect command */
3777 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3778 if (cmd_param_flag)
3779 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
3780 if (buff_size > I40E_AQ_LARGE_BUF)
3781 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3782
3783 desc.datalen = cpu_to_le16(buff_size);
3784
3785 cmd->vsi_seid = cpu_to_le16(seid);
3786
3787 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3788
3789 return status;
3790}
3791
3792/**
Mitch Williams6b192892014-03-06 09:02:29 +00003793 * i40e_aq_config_vsi_bw_limit - Configure VSI BW Limit
3794 * @hw: pointer to the hw struct
3795 * @seid: VSI seid
3796 * @credit: BW limit credits (0 = disabled)
3797 * @max_credit: Max BW limit credits
3798 * @cmd_details: pointer to command details structure or NULL
3799 **/
3800i40e_status i40e_aq_config_vsi_bw_limit(struct i40e_hw *hw,
3801 u16 seid, u16 credit, u8 max_credit,
3802 struct i40e_asq_cmd_details *cmd_details)
3803{
3804 struct i40e_aq_desc desc;
3805 struct i40e_aqc_configure_vsi_bw_limit *cmd =
3806 (struct i40e_aqc_configure_vsi_bw_limit *)&desc.params.raw;
3807 i40e_status status;
3808
3809 i40e_fill_default_direct_cmd_desc(&desc,
3810 i40e_aqc_opc_configure_vsi_bw_limit);
3811
3812 cmd->vsi_seid = cpu_to_le16(seid);
3813 cmd->credit = cpu_to_le16(credit);
3814 cmd->max_credit = max_credit;
3815
3816 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3817
3818 return status;
3819}
3820
3821/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003822 * i40e_aq_config_vsi_tc_bw - Config VSI BW Allocation per TC
3823 * @hw: pointer to the hw struct
3824 * @seid: VSI seid
3825 * @bw_data: Buffer holding enabled TCs, relative TC BW limit/credits
3826 * @cmd_details: pointer to command details structure or NULL
3827 **/
3828i40e_status i40e_aq_config_vsi_tc_bw(struct i40e_hw *hw,
3829 u16 seid,
3830 struct i40e_aqc_configure_vsi_tc_bw_data *bw_data,
3831 struct i40e_asq_cmd_details *cmd_details)
3832{
3833 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3834 i40e_aqc_opc_configure_vsi_tc_bw,
3835 cmd_details);
3836}
3837
3838/**
Neerav Parikhafb3ff02014-01-17 15:36:36 -08003839 * i40e_aq_config_switch_comp_ets - Enable/Disable/Modify ETS on the port
3840 * @hw: pointer to the hw struct
3841 * @seid: seid of the switching component connected to Physical Port
3842 * @ets_data: Buffer holding ETS parameters
3843 * @cmd_details: pointer to command details structure or NULL
3844 **/
3845i40e_status i40e_aq_config_switch_comp_ets(struct i40e_hw *hw,
3846 u16 seid,
3847 struct i40e_aqc_configure_switching_comp_ets_data *ets_data,
3848 enum i40e_admin_queue_opc opcode,
3849 struct i40e_asq_cmd_details *cmd_details)
3850{
3851 return i40e_aq_tx_sched_cmd(hw, seid, (void *)ets_data,
3852 sizeof(*ets_data), opcode, cmd_details);
3853}
3854
3855/**
3856 * i40e_aq_config_switch_comp_bw_config - Config Switch comp BW Alloc per TC
3857 * @hw: pointer to the hw struct
3858 * @seid: seid of the switching component
3859 * @bw_data: Buffer holding enabled TCs, relative/absolute TC BW limit/credits
3860 * @cmd_details: pointer to command details structure or NULL
3861 **/
3862i40e_status i40e_aq_config_switch_comp_bw_config(struct i40e_hw *hw,
3863 u16 seid,
3864 struct i40e_aqc_configure_switching_comp_bw_config_data *bw_data,
3865 struct i40e_asq_cmd_details *cmd_details)
3866{
3867 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3868 i40e_aqc_opc_configure_switching_comp_bw_config,
3869 cmd_details);
3870}
3871
3872/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003873 * i40e_aq_query_vsi_bw_config - Query VSI BW configuration
3874 * @hw: pointer to the hw struct
3875 * @seid: seid of the VSI
3876 * @bw_data: Buffer to hold VSI BW configuration
3877 * @cmd_details: pointer to command details structure or NULL
3878 **/
3879i40e_status i40e_aq_query_vsi_bw_config(struct i40e_hw *hw,
3880 u16 seid,
3881 struct i40e_aqc_query_vsi_bw_config_resp *bw_data,
3882 struct i40e_asq_cmd_details *cmd_details)
3883{
3884 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3885 i40e_aqc_opc_query_vsi_bw_config,
3886 cmd_details);
3887}
3888
3889/**
3890 * i40e_aq_query_vsi_ets_sla_config - Query VSI BW configuration per TC
3891 * @hw: pointer to the hw struct
3892 * @seid: seid of the VSI
3893 * @bw_data: Buffer to hold VSI BW configuration per TC
3894 * @cmd_details: pointer to command details structure or NULL
3895 **/
3896i40e_status i40e_aq_query_vsi_ets_sla_config(struct i40e_hw *hw,
3897 u16 seid,
3898 struct i40e_aqc_query_vsi_ets_sla_config_resp *bw_data,
3899 struct i40e_asq_cmd_details *cmd_details)
3900{
3901 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3902 i40e_aqc_opc_query_vsi_ets_sla_config,
3903 cmd_details);
3904}
3905
3906/**
3907 * i40e_aq_query_switch_comp_ets_config - Query Switch comp BW config per TC
3908 * @hw: pointer to the hw struct
3909 * @seid: seid of the switching component
3910 * @bw_data: Buffer to hold switching component's per TC BW config
3911 * @cmd_details: pointer to command details structure or NULL
3912 **/
3913i40e_status i40e_aq_query_switch_comp_ets_config(struct i40e_hw *hw,
3914 u16 seid,
3915 struct i40e_aqc_query_switching_comp_ets_config_resp *bw_data,
3916 struct i40e_asq_cmd_details *cmd_details)
3917{
3918 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3919 i40e_aqc_opc_query_switching_comp_ets_config,
3920 cmd_details);
3921}
3922
3923/**
3924 * i40e_aq_query_port_ets_config - Query Physical Port ETS configuration
3925 * @hw: pointer to the hw struct
3926 * @seid: seid of the VSI or switching component connected to Physical Port
3927 * @bw_data: Buffer to hold current ETS configuration for the Physical Port
3928 * @cmd_details: pointer to command details structure or NULL
3929 **/
3930i40e_status i40e_aq_query_port_ets_config(struct i40e_hw *hw,
3931 u16 seid,
3932 struct i40e_aqc_query_port_ets_config_resp *bw_data,
3933 struct i40e_asq_cmd_details *cmd_details)
3934{
3935 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3936 i40e_aqc_opc_query_port_ets_config,
3937 cmd_details);
3938}
3939
3940/**
3941 * i40e_aq_query_switch_comp_bw_config - Query Switch comp BW configuration
3942 * @hw: pointer to the hw struct
3943 * @seid: seid of the switching component
3944 * @bw_data: Buffer to hold switching component's BW configuration
3945 * @cmd_details: pointer to command details structure or NULL
3946 **/
3947i40e_status i40e_aq_query_switch_comp_bw_config(struct i40e_hw *hw,
3948 u16 seid,
3949 struct i40e_aqc_query_switching_comp_bw_config_resp *bw_data,
3950 struct i40e_asq_cmd_details *cmd_details)
3951{
3952 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3953 i40e_aqc_opc_query_switching_comp_bw_config,
3954 cmd_details);
3955}
3956
3957/**
3958 * i40e_validate_filter_settings
3959 * @hw: pointer to the hardware structure
3960 * @settings: Filter control settings
3961 *
3962 * Check and validate the filter control settings passed.
3963 * The function checks for the valid filter/context sizes being
3964 * passed for FCoE and PE.
3965 *
3966 * Returns 0 if the values passed are valid and within
3967 * range else returns an error.
3968 **/
3969static i40e_status i40e_validate_filter_settings(struct i40e_hw *hw,
3970 struct i40e_filter_control_settings *settings)
3971{
3972 u32 fcoe_cntx_size, fcoe_filt_size;
3973 u32 pe_cntx_size, pe_filt_size;
Anjali Singhai Jain467d7292014-05-10 04:49:02 +00003974 u32 fcoe_fmax;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003975 u32 val;
3976
3977 /* Validate FCoE settings passed */
3978 switch (settings->fcoe_filt_num) {
3979 case I40E_HASH_FILTER_SIZE_1K:
3980 case I40E_HASH_FILTER_SIZE_2K:
3981 case I40E_HASH_FILTER_SIZE_4K:
3982 case I40E_HASH_FILTER_SIZE_8K:
3983 case I40E_HASH_FILTER_SIZE_16K:
3984 case I40E_HASH_FILTER_SIZE_32K:
3985 fcoe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
3986 fcoe_filt_size <<= (u32)settings->fcoe_filt_num;
3987 break;
3988 default:
3989 return I40E_ERR_PARAM;
3990 }
3991
3992 switch (settings->fcoe_cntx_num) {
3993 case I40E_DMA_CNTX_SIZE_512:
3994 case I40E_DMA_CNTX_SIZE_1K:
3995 case I40E_DMA_CNTX_SIZE_2K:
3996 case I40E_DMA_CNTX_SIZE_4K:
3997 fcoe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
3998 fcoe_cntx_size <<= (u32)settings->fcoe_cntx_num;
3999 break;
4000 default:
4001 return I40E_ERR_PARAM;
4002 }
4003
4004 /* Validate PE settings passed */
4005 switch (settings->pe_filt_num) {
4006 case I40E_HASH_FILTER_SIZE_1K:
4007 case I40E_HASH_FILTER_SIZE_2K:
4008 case I40E_HASH_FILTER_SIZE_4K:
4009 case I40E_HASH_FILTER_SIZE_8K:
4010 case I40E_HASH_FILTER_SIZE_16K:
4011 case I40E_HASH_FILTER_SIZE_32K:
4012 case I40E_HASH_FILTER_SIZE_64K:
4013 case I40E_HASH_FILTER_SIZE_128K:
4014 case I40E_HASH_FILTER_SIZE_256K:
4015 case I40E_HASH_FILTER_SIZE_512K:
4016 case I40E_HASH_FILTER_SIZE_1M:
4017 pe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
4018 pe_filt_size <<= (u32)settings->pe_filt_num;
4019 break;
4020 default:
4021 return I40E_ERR_PARAM;
4022 }
4023
4024 switch (settings->pe_cntx_num) {
4025 case I40E_DMA_CNTX_SIZE_512:
4026 case I40E_DMA_CNTX_SIZE_1K:
4027 case I40E_DMA_CNTX_SIZE_2K:
4028 case I40E_DMA_CNTX_SIZE_4K:
4029 case I40E_DMA_CNTX_SIZE_8K:
4030 case I40E_DMA_CNTX_SIZE_16K:
4031 case I40E_DMA_CNTX_SIZE_32K:
4032 case I40E_DMA_CNTX_SIZE_64K:
4033 case I40E_DMA_CNTX_SIZE_128K:
4034 case I40E_DMA_CNTX_SIZE_256K:
4035 pe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
4036 pe_cntx_size <<= (u32)settings->pe_cntx_num;
4037 break;
4038 default:
4039 return I40E_ERR_PARAM;
4040 }
4041
4042 /* FCHSIZE + FCDSIZE should not be greater than PMFCOEFMAX */
4043 val = rd32(hw, I40E_GLHMC_FCOEFMAX);
4044 fcoe_fmax = (val & I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_MASK)
4045 >> I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_SHIFT;
4046 if (fcoe_filt_size + fcoe_cntx_size > fcoe_fmax)
4047 return I40E_ERR_INVALID_SIZE;
4048
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00004049 return 0;
4050}
4051
4052/**
4053 * i40e_set_filter_control
4054 * @hw: pointer to the hardware structure
4055 * @settings: Filter control settings
4056 *
4057 * Set the Queue Filters for PE/FCoE and enable filters required
4058 * for a single PF. It is expected that these settings are programmed
4059 * at the driver initialization time.
4060 **/
4061i40e_status i40e_set_filter_control(struct i40e_hw *hw,
4062 struct i40e_filter_control_settings *settings)
4063{
4064 i40e_status ret = 0;
4065 u32 hash_lut_size = 0;
4066 u32 val;
4067
4068 if (!settings)
4069 return I40E_ERR_PARAM;
4070
4071 /* Validate the input settings */
4072 ret = i40e_validate_filter_settings(hw, settings);
4073 if (ret)
4074 return ret;
4075
4076 /* Read the PF Queue Filter control register */
Shannon Nelsonf6581372016-02-17 16:12:20 -08004077 val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00004078
4079 /* Program required PE hash buckets for the PF */
4080 val &= ~I40E_PFQF_CTL_0_PEHSIZE_MASK;
4081 val |= ((u32)settings->pe_filt_num << I40E_PFQF_CTL_0_PEHSIZE_SHIFT) &
4082 I40E_PFQF_CTL_0_PEHSIZE_MASK;
4083 /* Program required PE contexts for the PF */
4084 val &= ~I40E_PFQF_CTL_0_PEDSIZE_MASK;
4085 val |= ((u32)settings->pe_cntx_num << I40E_PFQF_CTL_0_PEDSIZE_SHIFT) &
4086 I40E_PFQF_CTL_0_PEDSIZE_MASK;
4087
4088 /* Program required FCoE hash buckets for the PF */
4089 val &= ~I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
4090 val |= ((u32)settings->fcoe_filt_num <<
4091 I40E_PFQF_CTL_0_PFFCHSIZE_SHIFT) &
4092 I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
4093 /* Program required FCoE DDP contexts for the PF */
4094 val &= ~I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
4095 val |= ((u32)settings->fcoe_cntx_num <<
4096 I40E_PFQF_CTL_0_PFFCDSIZE_SHIFT) &
4097 I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
4098
4099 /* Program Hash LUT size for the PF */
4100 val &= ~I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
4101 if (settings->hash_lut_size == I40E_HASH_LUT_SIZE_512)
4102 hash_lut_size = 1;
4103 val |= (hash_lut_size << I40E_PFQF_CTL_0_HASHLUTSIZE_SHIFT) &
4104 I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
4105
4106 /* Enable FDIR, Ethertype and MACVLAN filters for PF and VFs */
4107 if (settings->enable_fdir)
4108 val |= I40E_PFQF_CTL_0_FD_ENA_MASK;
4109 if (settings->enable_ethtype)
4110 val |= I40E_PFQF_CTL_0_ETYPE_ENA_MASK;
4111 if (settings->enable_macvlan)
4112 val |= I40E_PFQF_CTL_0_MACVLAN_ENA_MASK;
4113
Shannon Nelsonf6581372016-02-17 16:12:20 -08004114 i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, val);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00004115
4116 return 0;
4117}
Neerav Parikhafb3ff02014-01-17 15:36:36 -08004118
4119/**
4120 * i40e_aq_add_rem_control_packet_filter - Add or Remove Control Packet Filter
4121 * @hw: pointer to the hw struct
4122 * @mac_addr: MAC address to use in the filter
4123 * @ethtype: Ethertype to use in the filter
4124 * @flags: Flags that needs to be applied to the filter
4125 * @vsi_seid: seid of the control VSI
4126 * @queue: VSI queue number to send the packet to
4127 * @is_add: Add control packet filter if True else remove
4128 * @stats: Structure to hold information on control filter counts
4129 * @cmd_details: pointer to command details structure or NULL
4130 *
4131 * This command will Add or Remove control packet filter for a control VSI.
4132 * In return it will update the total number of perfect filter count in
4133 * the stats member.
4134 **/
4135i40e_status i40e_aq_add_rem_control_packet_filter(struct i40e_hw *hw,
4136 u8 *mac_addr, u16 ethtype, u16 flags,
4137 u16 vsi_seid, u16 queue, bool is_add,
4138 struct i40e_control_filter_stats *stats,
4139 struct i40e_asq_cmd_details *cmd_details)
4140{
4141 struct i40e_aq_desc desc;
4142 struct i40e_aqc_add_remove_control_packet_filter *cmd =
4143 (struct i40e_aqc_add_remove_control_packet_filter *)
4144 &desc.params.raw;
4145 struct i40e_aqc_add_remove_control_packet_filter_completion *resp =
4146 (struct i40e_aqc_add_remove_control_packet_filter_completion *)
4147 &desc.params.raw;
4148 i40e_status status;
4149
4150 if (vsi_seid == 0)
4151 return I40E_ERR_PARAM;
4152
4153 if (is_add) {
4154 i40e_fill_default_direct_cmd_desc(&desc,
4155 i40e_aqc_opc_add_control_packet_filter);
4156 cmd->queue = cpu_to_le16(queue);
4157 } else {
4158 i40e_fill_default_direct_cmd_desc(&desc,
4159 i40e_aqc_opc_remove_control_packet_filter);
4160 }
4161
4162 if (mac_addr)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04004163 ether_addr_copy(cmd->mac, mac_addr);
Neerav Parikhafb3ff02014-01-17 15:36:36 -08004164
4165 cmd->etype = cpu_to_le16(ethtype);
4166 cmd->flags = cpu_to_le16(flags);
4167 cmd->seid = cpu_to_le16(vsi_seid);
4168
4169 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4170
4171 if (!status && stats) {
4172 stats->mac_etype_used = le16_to_cpu(resp->mac_etype_used);
4173 stats->etype_used = le16_to_cpu(resp->etype_used);
4174 stats->mac_etype_free = le16_to_cpu(resp->mac_etype_free);
4175 stats->etype_free = le16_to_cpu(resp->etype_free);
4176 }
4177
4178 return status;
4179}
4180
Catherine Sullivand4dfb812013-11-28 06:39:21 +00004181/**
Anjali Singhai Jaine7358f52015-10-01 14:37:34 -04004182 * i40e_add_filter_to_drop_tx_flow_control_frames- filter to drop flow control
4183 * @hw: pointer to the hw struct
4184 * @seid: VSI seid to add ethertype filter from
4185 **/
4186#define I40E_FLOW_CONTROL_ETHTYPE 0x8808
4187void i40e_add_filter_to_drop_tx_flow_control_frames(struct i40e_hw *hw,
4188 u16 seid)
4189{
4190 u16 flag = I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC |
4191 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP |
4192 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX;
4193 u16 ethtype = I40E_FLOW_CONTROL_ETHTYPE;
4194 i40e_status status;
4195
4196 status = i40e_aq_add_rem_control_packet_filter(hw, NULL, ethtype, flag,
4197 seid, 0, true, NULL,
4198 NULL);
4199 if (status)
4200 hw_dbg(hw, "Ethtype Filter Add failed: Error pruning Tx flow control frames\n");
4201}
4202
4203/**
Greg Rosef4492db2015-02-06 08:52:12 +00004204 * i40e_aq_alternate_read
4205 * @hw: pointer to the hardware structure
4206 * @reg_addr0: address of first dword to be read
4207 * @reg_val0: pointer for data read from 'reg_addr0'
4208 * @reg_addr1: address of second dword to be read
4209 * @reg_val1: pointer for data read from 'reg_addr1'
4210 *
4211 * Read one or two dwords from alternate structure. Fields are indicated
4212 * by 'reg_addr0' and 'reg_addr1' register numbers. If 'reg_val1' pointer
4213 * is not passed then only register at 'reg_addr0' is read.
4214 *
4215 **/
Shannon Nelson37a29732015-02-27 09:15:19 +00004216static i40e_status i40e_aq_alternate_read(struct i40e_hw *hw,
4217 u32 reg_addr0, u32 *reg_val0,
4218 u32 reg_addr1, u32 *reg_val1)
Greg Rosef4492db2015-02-06 08:52:12 +00004219{
4220 struct i40e_aq_desc desc;
4221 struct i40e_aqc_alternate_write *cmd_resp =
4222 (struct i40e_aqc_alternate_write *)&desc.params.raw;
4223 i40e_status status;
4224
4225 if (!reg_val0)
4226 return I40E_ERR_PARAM;
4227
4228 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_alternate_read);
4229 cmd_resp->address0 = cpu_to_le32(reg_addr0);
4230 cmd_resp->address1 = cpu_to_le32(reg_addr1);
4231
4232 status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
4233
4234 if (!status) {
4235 *reg_val0 = le32_to_cpu(cmd_resp->data0);
4236
4237 if (reg_val1)
4238 *reg_val1 = le32_to_cpu(cmd_resp->data1);
4239 }
4240
4241 return status;
4242}
4243
4244/**
Neerav Parikh2fd75f32014-11-12 00:18:20 +00004245 * i40e_aq_resume_port_tx
4246 * @hw: pointer to the hardware structure
4247 * @cmd_details: pointer to command details structure or NULL
4248 *
4249 * Resume port's Tx traffic
4250 **/
4251i40e_status i40e_aq_resume_port_tx(struct i40e_hw *hw,
4252 struct i40e_asq_cmd_details *cmd_details)
4253{
4254 struct i40e_aq_desc desc;
4255 i40e_status status;
4256
4257 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_resume_port_tx);
4258
4259 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4260
4261 return status;
4262}
4263
4264/**
Catherine Sullivand4dfb812013-11-28 06:39:21 +00004265 * i40e_set_pci_config_data - store PCI bus info
4266 * @hw: pointer to hardware structure
4267 * @link_status: the link status word from PCI config space
4268 *
4269 * Stores the PCI bus info (speed, width, type) within the i40e_hw structure
4270 **/
4271void i40e_set_pci_config_data(struct i40e_hw *hw, u16 link_status)
4272{
4273 hw->bus.type = i40e_bus_type_pci_express;
4274
4275 switch (link_status & PCI_EXP_LNKSTA_NLW) {
4276 case PCI_EXP_LNKSTA_NLW_X1:
4277 hw->bus.width = i40e_bus_width_pcie_x1;
4278 break;
4279 case PCI_EXP_LNKSTA_NLW_X2:
4280 hw->bus.width = i40e_bus_width_pcie_x2;
4281 break;
4282 case PCI_EXP_LNKSTA_NLW_X4:
4283 hw->bus.width = i40e_bus_width_pcie_x4;
4284 break;
4285 case PCI_EXP_LNKSTA_NLW_X8:
4286 hw->bus.width = i40e_bus_width_pcie_x8;
4287 break;
4288 default:
4289 hw->bus.width = i40e_bus_width_unknown;
4290 break;
4291 }
4292
4293 switch (link_status & PCI_EXP_LNKSTA_CLS) {
4294 case PCI_EXP_LNKSTA_CLS_2_5GB:
4295 hw->bus.speed = i40e_bus_speed_2500;
4296 break;
4297 case PCI_EXP_LNKSTA_CLS_5_0GB:
4298 hw->bus.speed = i40e_bus_speed_5000;
4299 break;
4300 case PCI_EXP_LNKSTA_CLS_8_0GB:
4301 hw->bus.speed = i40e_bus_speed_8000;
4302 break;
4303 default:
4304 hw->bus.speed = i40e_bus_speed_unknown;
4305 break;
4306 }
4307}
Greg Rosef4492db2015-02-06 08:52:12 +00004308
4309/**
Jesse Brandeburg3169c322015-04-07 19:45:37 -04004310 * i40e_aq_debug_dump
4311 * @hw: pointer to the hardware structure
4312 * @cluster_id: specific cluster to dump
4313 * @table_id: table id within cluster
4314 * @start_index: index of line in the block to read
4315 * @buff_size: dump buffer size
4316 * @buff: dump buffer
4317 * @ret_buff_size: actual buffer size returned
4318 * @ret_next_table: next block to read
4319 * @ret_next_index: next index to read
4320 *
4321 * Dump internal FW/HW data for debug purposes.
4322 *
4323 **/
4324i40e_status i40e_aq_debug_dump(struct i40e_hw *hw, u8 cluster_id,
4325 u8 table_id, u32 start_index, u16 buff_size,
4326 void *buff, u16 *ret_buff_size,
4327 u8 *ret_next_table, u32 *ret_next_index,
4328 struct i40e_asq_cmd_details *cmd_details)
4329{
4330 struct i40e_aq_desc desc;
4331 struct i40e_aqc_debug_dump_internals *cmd =
4332 (struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
4333 struct i40e_aqc_debug_dump_internals *resp =
4334 (struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
4335 i40e_status status;
4336
4337 if (buff_size == 0 || !buff)
4338 return I40E_ERR_PARAM;
4339
4340 i40e_fill_default_direct_cmd_desc(&desc,
4341 i40e_aqc_opc_debug_dump_internals);
4342 /* Indirect Command */
4343 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
4344 if (buff_size > I40E_AQ_LARGE_BUF)
4345 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
4346
4347 cmd->cluster_id = cluster_id;
4348 cmd->table_id = table_id;
4349 cmd->idx = cpu_to_le32(start_index);
4350
4351 desc.datalen = cpu_to_le16(buff_size);
4352
4353 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
4354 if (!status) {
4355 if (ret_buff_size)
4356 *ret_buff_size = le16_to_cpu(desc.datalen);
4357 if (ret_next_table)
4358 *ret_next_table = resp->table_id;
4359 if (ret_next_index)
4360 *ret_next_index = le32_to_cpu(resp->idx);
4361 }
4362
4363 return status;
4364}
4365
4366/**
Greg Rosef4492db2015-02-06 08:52:12 +00004367 * i40e_read_bw_from_alt_ram
4368 * @hw: pointer to the hardware structure
4369 * @max_bw: pointer for max_bw read
4370 * @min_bw: pointer for min_bw read
4371 * @min_valid: pointer for bool that is true if min_bw is a valid value
4372 * @max_valid: pointer for bool that is true if max_bw is a valid value
4373 *
4374 * Read bw from the alternate ram for the given pf
4375 **/
4376i40e_status i40e_read_bw_from_alt_ram(struct i40e_hw *hw,
4377 u32 *max_bw, u32 *min_bw,
4378 bool *min_valid, bool *max_valid)
4379{
4380 i40e_status status;
4381 u32 max_bw_addr, min_bw_addr;
4382
4383 /* Calculate the address of the min/max bw registers */
4384 max_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
4385 I40E_ALT_STRUCT_MAX_BW_OFFSET +
4386 (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
4387 min_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
4388 I40E_ALT_STRUCT_MIN_BW_OFFSET +
4389 (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
4390
4391 /* Read the bandwidths from alt ram */
4392 status = i40e_aq_alternate_read(hw, max_bw_addr, max_bw,
4393 min_bw_addr, min_bw);
4394
4395 if (*min_bw & I40E_ALT_BW_VALID_MASK)
4396 *min_valid = true;
4397 else
4398 *min_valid = false;
4399
4400 if (*max_bw & I40E_ALT_BW_VALID_MASK)
4401 *max_valid = true;
4402 else
4403 *max_valid = false;
4404
4405 return status;
4406}
4407
4408/**
4409 * i40e_aq_configure_partition_bw
4410 * @hw: pointer to the hardware structure
4411 * @bw_data: Buffer holding valid pfs and bw limits
4412 * @cmd_details: pointer to command details
4413 *
4414 * Configure partitions guaranteed/max bw
4415 **/
4416i40e_status i40e_aq_configure_partition_bw(struct i40e_hw *hw,
4417 struct i40e_aqc_configure_partition_bw_data *bw_data,
4418 struct i40e_asq_cmd_details *cmd_details)
4419{
4420 i40e_status status;
4421 struct i40e_aq_desc desc;
4422 u16 bwd_size = sizeof(*bw_data);
4423
4424 i40e_fill_default_direct_cmd_desc(&desc,
4425 i40e_aqc_opc_configure_partition_bw);
4426
4427 /* Indirect command */
4428 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
4429 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
4430
4431 if (bwd_size > I40E_AQ_LARGE_BUF)
4432 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
4433
4434 desc.datalen = cpu_to_le16(bwd_size);
4435
4436 status = i40e_asq_send_command(hw, &desc, bw_data, bwd_size,
4437 cmd_details);
4438
4439 return status;
4440}
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004441
4442/**
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004443 * i40e_read_phy_register_clause22
4444 * @hw: pointer to the HW structure
4445 * @reg: register address in the page
4446 * @phy_adr: PHY address on MDIO interface
4447 * @value: PHY register value
4448 *
4449 * Reads specified PHY register value
4450 **/
4451i40e_status i40e_read_phy_register_clause22(struct i40e_hw *hw,
4452 u16 reg, u8 phy_addr, u16 *value)
4453{
4454 i40e_status status = I40E_ERR_TIMEOUT;
4455 u8 port_num = (u8)hw->func_caps.mdio_port_num;
4456 u32 command = 0;
4457 u16 retry = 1000;
4458
4459 command = (reg << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4460 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
4461 (I40E_MDIO_CLAUSE22_OPCODE_READ_MASK) |
4462 (I40E_MDIO_CLAUSE22_STCODE_MASK) |
4463 (I40E_GLGEN_MSCA_MDICMD_MASK);
4464 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4465 do {
4466 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4467 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4468 status = 0;
4469 break;
4470 }
4471 udelay(10);
4472 retry--;
4473 } while (retry);
4474
4475 if (status) {
4476 i40e_debug(hw, I40E_DEBUG_PHY,
4477 "PHY: Can't write command to external PHY.\n");
Henry Tieman27e5f252016-11-08 13:05:06 -08004478 } else {
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004479 command = rd32(hw, I40E_GLGEN_MSRWD(port_num));
4480 *value = (command & I40E_GLGEN_MSRWD_MDIRDDATA_MASK) >>
4481 I40E_GLGEN_MSRWD_MDIRDDATA_SHIFT;
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004482 }
4483
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004484 return status;
4485}
4486
4487/**
4488 * i40e_write_phy_register_clause22
4489 * @hw: pointer to the HW structure
4490 * @reg: register address in the page
4491 * @phy_adr: PHY address on MDIO interface
4492 * @value: PHY register value
4493 *
4494 * Writes specified PHY register value
4495 **/
4496i40e_status i40e_write_phy_register_clause22(struct i40e_hw *hw,
4497 u16 reg, u8 phy_addr, u16 value)
4498{
4499 i40e_status status = I40E_ERR_TIMEOUT;
4500 u8 port_num = (u8)hw->func_caps.mdio_port_num;
4501 u32 command = 0;
4502 u16 retry = 1000;
4503
4504 command = value << I40E_GLGEN_MSRWD_MDIWRDATA_SHIFT;
4505 wr32(hw, I40E_GLGEN_MSRWD(port_num), command);
4506
4507 command = (reg << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4508 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
4509 (I40E_MDIO_CLAUSE22_OPCODE_WRITE_MASK) |
4510 (I40E_MDIO_CLAUSE22_STCODE_MASK) |
4511 (I40E_GLGEN_MSCA_MDICMD_MASK);
4512
4513 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4514 do {
4515 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4516 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4517 status = 0;
4518 break;
4519 }
4520 udelay(10);
4521 retry--;
4522 } while (retry);
4523
4524 return status;
4525}
4526
4527/**
4528 * i40e_read_phy_register_clause45
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004529 * @hw: pointer to the HW structure
4530 * @page: registers page number
4531 * @reg: register address in the page
4532 * @phy_adr: PHY address on MDIO interface
4533 * @value: PHY register value
4534 *
4535 * Reads specified PHY register value
4536 **/
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004537i40e_status i40e_read_phy_register_clause45(struct i40e_hw *hw,
4538 u8 page, u16 reg, u8 phy_addr, u16 *value)
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004539{
4540 i40e_status status = I40E_ERR_TIMEOUT;
4541 u32 command = 0;
4542 u16 retry = 1000;
4543 u8 port_num = hw->func_caps.mdio_port_num;
4544
4545 command = (reg << I40E_GLGEN_MSCA_MDIADD_SHIFT) |
4546 (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4547 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004548 (I40E_MDIO_CLAUSE45_OPCODE_ADDRESS_MASK) |
4549 (I40E_MDIO_CLAUSE45_STCODE_MASK) |
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004550 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4551 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4552 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4553 do {
4554 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4555 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4556 status = 0;
4557 break;
4558 }
4559 usleep_range(10, 20);
4560 retry--;
4561 } while (retry);
4562
4563 if (status) {
4564 i40e_debug(hw, I40E_DEBUG_PHY,
4565 "PHY: Can't write command to external PHY.\n");
4566 goto phy_read_end;
4567 }
4568
4569 command = (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4570 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004571 (I40E_MDIO_CLAUSE45_OPCODE_READ_MASK) |
4572 (I40E_MDIO_CLAUSE45_STCODE_MASK) |
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004573 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4574 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4575 status = I40E_ERR_TIMEOUT;
4576 retry = 1000;
4577 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4578 do {
4579 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4580 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4581 status = 0;
4582 break;
4583 }
4584 usleep_range(10, 20);
4585 retry--;
4586 } while (retry);
4587
4588 if (!status) {
4589 command = rd32(hw, I40E_GLGEN_MSRWD(port_num));
4590 *value = (command & I40E_GLGEN_MSRWD_MDIRDDATA_MASK) >>
4591 I40E_GLGEN_MSRWD_MDIRDDATA_SHIFT;
4592 } else {
4593 i40e_debug(hw, I40E_DEBUG_PHY,
4594 "PHY: Can't read register value from external PHY.\n");
4595 }
4596
4597phy_read_end:
4598 return status;
4599}
4600
4601/**
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004602 * i40e_write_phy_register_clause45
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004603 * @hw: pointer to the HW structure
4604 * @page: registers page number
4605 * @reg: register address in the page
4606 * @phy_adr: PHY address on MDIO interface
4607 * @value: PHY register value
4608 *
4609 * Writes value to specified PHY register
4610 **/
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004611i40e_status i40e_write_phy_register_clause45(struct i40e_hw *hw,
4612 u8 page, u16 reg, u8 phy_addr, u16 value)
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004613{
4614 i40e_status status = I40E_ERR_TIMEOUT;
4615 u32 command = 0;
4616 u16 retry = 1000;
4617 u8 port_num = hw->func_caps.mdio_port_num;
4618
4619 command = (reg << I40E_GLGEN_MSCA_MDIADD_SHIFT) |
4620 (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4621 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004622 (I40E_MDIO_CLAUSE45_OPCODE_ADDRESS_MASK) |
4623 (I40E_MDIO_CLAUSE45_STCODE_MASK) |
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004624 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4625 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4626 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4627 do {
4628 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4629 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4630 status = 0;
4631 break;
4632 }
4633 usleep_range(10, 20);
4634 retry--;
4635 } while (retry);
4636 if (status) {
4637 i40e_debug(hw, I40E_DEBUG_PHY,
4638 "PHY: Can't write command to external PHY.\n");
4639 goto phy_write_end;
4640 }
4641
4642 command = value << I40E_GLGEN_MSRWD_MDIWRDATA_SHIFT;
4643 wr32(hw, I40E_GLGEN_MSRWD(port_num), command);
4644
4645 command = (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4646 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004647 (I40E_MDIO_CLAUSE45_OPCODE_WRITE_MASK) |
4648 (I40E_MDIO_CLAUSE45_STCODE_MASK) |
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004649 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4650 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4651 status = I40E_ERR_TIMEOUT;
4652 retry = 1000;
4653 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4654 do {
4655 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4656 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4657 status = 0;
4658 break;
4659 }
4660 usleep_range(10, 20);
4661 retry--;
4662 } while (retry);
4663
4664phy_write_end:
4665 return status;
4666}
4667
4668/**
Michal Kosiarzf62ba912016-11-21 13:03:50 -08004669 * i40e_write_phy_register
4670 * @hw: pointer to the HW structure
4671 * @page: registers page number
4672 * @reg: register address in the page
4673 * @phy_adr: PHY address on MDIO interface
4674 * @value: PHY register value
4675 *
4676 * Writes value to specified PHY register
4677 **/
4678i40e_status i40e_write_phy_register(struct i40e_hw *hw,
4679 u8 page, u16 reg, u8 phy_addr, u16 value)
4680{
4681 i40e_status status;
4682
4683 switch (hw->device_id) {
4684 case I40E_DEV_ID_1G_BASE_T_X722:
4685 status = i40e_write_phy_register_clause22(hw, reg, phy_addr,
4686 value);
4687 break;
4688 case I40E_DEV_ID_10G_BASE_T:
4689 case I40E_DEV_ID_10G_BASE_T4:
4690 case I40E_DEV_ID_10G_BASE_T_X722:
4691 case I40E_DEV_ID_25G_B:
4692 case I40E_DEV_ID_25G_SFP28:
4693 status = i40e_write_phy_register_clause45(hw, page, reg,
4694 phy_addr, value);
4695 break;
4696 default:
4697 status = I40E_ERR_UNKNOWN_PHY;
4698 break;
4699 }
4700
4701 return status;
4702}
4703
4704/**
4705 * i40e_read_phy_register
4706 * @hw: pointer to the HW structure
4707 * @page: registers page number
4708 * @reg: register address in the page
4709 * @phy_adr: PHY address on MDIO interface
4710 * @value: PHY register value
4711 *
4712 * Reads specified PHY register value
4713 **/
4714i40e_status i40e_read_phy_register(struct i40e_hw *hw,
4715 u8 page, u16 reg, u8 phy_addr, u16 *value)
4716{
4717 i40e_status status;
4718
4719 switch (hw->device_id) {
4720 case I40E_DEV_ID_1G_BASE_T_X722:
4721 status = i40e_read_phy_register_clause22(hw, reg, phy_addr,
4722 value);
4723 break;
4724 case I40E_DEV_ID_10G_BASE_T:
4725 case I40E_DEV_ID_10G_BASE_T4:
4726 case I40E_DEV_ID_10G_BASE_T_X722:
4727 case I40E_DEV_ID_25G_B:
4728 case I40E_DEV_ID_25G_SFP28:
4729 status = i40e_read_phy_register_clause45(hw, page, reg,
4730 phy_addr, value);
4731 break;
4732 default:
4733 status = I40E_ERR_UNKNOWN_PHY;
4734 break;
4735 }
4736
4737 return status;
4738}
4739
4740/**
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004741 * i40e_get_phy_address
4742 * @hw: pointer to the HW structure
4743 * @dev_num: PHY port num that address we want
4744 * @phy_addr: Returned PHY address
4745 *
4746 * Gets PHY address for current port
4747 **/
4748u8 i40e_get_phy_address(struct i40e_hw *hw, u8 dev_num)
4749{
4750 u8 port_num = hw->func_caps.mdio_port_num;
4751 u32 reg_val = rd32(hw, I40E_GLGEN_MDIO_I2C_SEL(port_num));
4752
4753 return (u8)(reg_val >> ((dev_num + 1) * 5)) & 0x1f;
4754}
4755
4756/**
4757 * i40e_blink_phy_led
4758 * @hw: pointer to the HW structure
4759 * @time: time how long led will blinks in secs
4760 * @interval: gap between LED on and off in msecs
4761 *
4762 * Blinks PHY link LED
4763 **/
4764i40e_status i40e_blink_phy_link_led(struct i40e_hw *hw,
4765 u32 time, u32 interval)
4766{
4767 i40e_status status = 0;
4768 u32 i;
4769 u16 led_ctl;
4770 u16 gpio_led_port;
4771 u16 led_reg;
4772 u16 led_addr = I40E_PHY_LED_PROV_REG_1;
4773 u8 phy_addr = 0;
4774 u8 port_num;
4775
4776 i = rd32(hw, I40E_PFGEN_PORTNUM);
4777 port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
4778 phy_addr = i40e_get_phy_address(hw, port_num);
4779
4780 for (gpio_led_port = 0; gpio_led_port < 3; gpio_led_port++,
4781 led_addr++) {
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004782 status = i40e_read_phy_register_clause45(hw,
4783 I40E_PHY_COM_REG_PAGE,
4784 led_addr, phy_addr,
4785 &led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004786 if (status)
4787 goto phy_blinking_end;
4788 led_ctl = led_reg;
4789 if (led_reg & I40E_PHY_LED_LINK_MODE_MASK) {
4790 led_reg = 0;
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004791 status = i40e_write_phy_register_clause45(hw,
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004792 I40E_PHY_COM_REG_PAGE,
4793 led_addr, phy_addr,
4794 led_reg);
4795 if (status)
4796 goto phy_blinking_end;
4797 break;
4798 }
4799 }
4800
4801 if (time > 0 && interval > 0) {
4802 for (i = 0; i < time * 1000; i += interval) {
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004803 status = i40e_read_phy_register_clause45(hw,
4804 I40E_PHY_COM_REG_PAGE,
4805 led_addr, phy_addr, &led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004806 if (status)
4807 goto restore_config;
4808 if (led_reg & I40E_PHY_LED_MANUAL_ON)
4809 led_reg = 0;
4810 else
4811 led_reg = I40E_PHY_LED_MANUAL_ON;
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004812 status = i40e_write_phy_register_clause45(hw,
4813 I40E_PHY_COM_REG_PAGE,
4814 led_addr, phy_addr, led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004815 if (status)
4816 goto restore_config;
4817 msleep(interval);
4818 }
4819 }
4820
4821restore_config:
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004822 status = i40e_write_phy_register_clause45(hw,
4823 I40E_PHY_COM_REG_PAGE,
4824 led_addr, phy_addr, led_ctl);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004825
4826phy_blinking_end:
4827 return status;
4828}
4829
4830/**
4831 * i40e_led_get_phy - return current on/off mode
4832 * @hw: pointer to the hw struct
4833 * @led_addr: address of led register to use
4834 * @val: original value of register to use
4835 *
4836 **/
4837i40e_status i40e_led_get_phy(struct i40e_hw *hw, u16 *led_addr,
4838 u16 *val)
4839{
4840 i40e_status status = 0;
4841 u16 gpio_led_port;
4842 u8 phy_addr = 0;
4843 u16 reg_val;
4844 u16 temp_addr;
4845 u8 port_num;
4846 u32 i;
4847
4848 temp_addr = I40E_PHY_LED_PROV_REG_1;
4849 i = rd32(hw, I40E_PFGEN_PORTNUM);
4850 port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
4851 phy_addr = i40e_get_phy_address(hw, port_num);
4852
4853 for (gpio_led_port = 0; gpio_led_port < 3; gpio_led_port++,
4854 temp_addr++) {
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004855 status = i40e_read_phy_register_clause45(hw,
4856 I40E_PHY_COM_REG_PAGE,
4857 temp_addr, phy_addr,
4858 &reg_val);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004859 if (status)
4860 return status;
4861 *val = reg_val;
4862 if (reg_val & I40E_PHY_LED_LINK_MODE_MASK) {
4863 *led_addr = temp_addr;
4864 break;
4865 }
4866 }
4867 return status;
4868}
4869
4870/**
4871 * i40e_led_set_phy
4872 * @hw: pointer to the HW structure
4873 * @on: true or false
4874 * @mode: original val plus bit for set or ignore
4875 * Set led's on or off when controlled by the PHY
4876 *
4877 **/
4878i40e_status i40e_led_set_phy(struct i40e_hw *hw, bool on,
4879 u16 led_addr, u32 mode)
4880{
4881 i40e_status status = 0;
4882 u16 led_ctl = 0;
4883 u16 led_reg = 0;
4884 u8 phy_addr = 0;
4885 u8 port_num;
4886 u32 i;
4887
4888 i = rd32(hw, I40E_PFGEN_PORTNUM);
4889 port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
4890 phy_addr = i40e_get_phy_address(hw, port_num);
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004891 status = i40e_read_phy_register_clause45(hw, I40E_PHY_COM_REG_PAGE,
4892 led_addr, phy_addr, &led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004893 if (status)
4894 return status;
4895 led_ctl = led_reg;
4896 if (led_reg & I40E_PHY_LED_LINK_MODE_MASK) {
4897 led_reg = 0;
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004898 status = i40e_write_phy_register_clause45(hw,
4899 I40E_PHY_COM_REG_PAGE,
4900 led_addr, phy_addr,
4901 led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004902 if (status)
4903 return status;
4904 }
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004905 status = i40e_read_phy_register_clause45(hw, I40E_PHY_COM_REG_PAGE,
4906 led_addr, phy_addr, &led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004907 if (status)
4908 goto restore_config;
4909 if (on)
4910 led_reg = I40E_PHY_LED_MANUAL_ON;
4911 else
4912 led_reg = 0;
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004913 status = i40e_write_phy_register_clause45(hw, I40E_PHY_COM_REG_PAGE,
4914 led_addr, phy_addr, led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004915 if (status)
4916 goto restore_config;
4917 if (mode & I40E_PHY_LED_MODE_ORIG) {
4918 led_ctl = (mode & I40E_PHY_LED_MODE_MASK);
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004919 status = i40e_write_phy_register_clause45(hw,
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004920 I40E_PHY_COM_REG_PAGE,
4921 led_addr, phy_addr, led_ctl);
4922 }
4923 return status;
4924restore_config:
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004925 status = i40e_write_phy_register_clause45(hw, I40E_PHY_COM_REG_PAGE,
4926 led_addr, phy_addr, led_ctl);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004927 return status;
4928}
Shannon Nelsonf6581372016-02-17 16:12:20 -08004929
4930/**
4931 * i40e_aq_rx_ctl_read_register - use FW to read from an Rx control register
4932 * @hw: pointer to the hw struct
4933 * @reg_addr: register address
4934 * @reg_val: ptr to register value
4935 * @cmd_details: pointer to command details structure or NULL
4936 *
4937 * Use the firmware to read the Rx control register,
4938 * especially useful if the Rx unit is under heavy pressure
4939 **/
4940i40e_status i40e_aq_rx_ctl_read_register(struct i40e_hw *hw,
4941 u32 reg_addr, u32 *reg_val,
4942 struct i40e_asq_cmd_details *cmd_details)
4943{
4944 struct i40e_aq_desc desc;
4945 struct i40e_aqc_rx_ctl_reg_read_write *cmd_resp =
4946 (struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
4947 i40e_status status;
4948
4949 if (!reg_val)
4950 return I40E_ERR_PARAM;
4951
4952 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_rx_ctl_reg_read);
4953
4954 cmd_resp->address = cpu_to_le32(reg_addr);
4955
4956 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4957
4958 if (status == 0)
4959 *reg_val = le32_to_cpu(cmd_resp->value);
4960
4961 return status;
4962}
4963
4964/**
4965 * i40e_read_rx_ctl - read from an Rx control register
4966 * @hw: pointer to the hw struct
4967 * @reg_addr: register address
4968 **/
4969u32 i40e_read_rx_ctl(struct i40e_hw *hw, u32 reg_addr)
4970{
4971 i40e_status status = 0;
4972 bool use_register;
4973 int retry = 5;
4974 u32 val = 0;
4975
Paul M Stillwell Jr60303082017-03-10 12:22:02 -08004976 use_register = (((hw->aq.api_maj_ver == 1) &&
4977 (hw->aq.api_min_ver < 5)) ||
4978 (hw->mac.type == I40E_MAC_X722));
Shannon Nelsonf6581372016-02-17 16:12:20 -08004979 if (!use_register) {
4980do_retry:
4981 status = i40e_aq_rx_ctl_read_register(hw, reg_addr, &val, NULL);
4982 if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
4983 usleep_range(1000, 2000);
4984 retry--;
4985 goto do_retry;
4986 }
4987 }
4988
4989 /* if the AQ access failed, try the old-fashioned way */
4990 if (status || use_register)
4991 val = rd32(hw, reg_addr);
4992
4993 return val;
4994}
4995
4996/**
4997 * i40e_aq_rx_ctl_write_register
4998 * @hw: pointer to the hw struct
4999 * @reg_addr: register address
5000 * @reg_val: register value
5001 * @cmd_details: pointer to command details structure or NULL
5002 *
5003 * Use the firmware to write to an Rx control register,
5004 * especially useful if the Rx unit is under heavy pressure
5005 **/
5006i40e_status i40e_aq_rx_ctl_write_register(struct i40e_hw *hw,
5007 u32 reg_addr, u32 reg_val,
5008 struct i40e_asq_cmd_details *cmd_details)
5009{
5010 struct i40e_aq_desc desc;
5011 struct i40e_aqc_rx_ctl_reg_read_write *cmd =
5012 (struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
5013 i40e_status status;
5014
5015 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_rx_ctl_reg_write);
5016
5017 cmd->address = cpu_to_le32(reg_addr);
5018 cmd->value = cpu_to_le32(reg_val);
5019
5020 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5021
5022 return status;
5023}
5024
5025/**
5026 * i40e_write_rx_ctl - write to an Rx control register
5027 * @hw: pointer to the hw struct
5028 * @reg_addr: register address
5029 * @reg_val: register value
5030 **/
5031void i40e_write_rx_ctl(struct i40e_hw *hw, u32 reg_addr, u32 reg_val)
5032{
5033 i40e_status status = 0;
5034 bool use_register;
5035 int retry = 5;
5036
Paul M Stillwell Jr60303082017-03-10 12:22:02 -08005037 use_register = (((hw->aq.api_maj_ver == 1) &&
5038 (hw->aq.api_min_ver < 5)) ||
5039 (hw->mac.type == I40E_MAC_X722));
Shannon Nelsonf6581372016-02-17 16:12:20 -08005040 if (!use_register) {
5041do_retry:
5042 status = i40e_aq_rx_ctl_write_register(hw, reg_addr,
5043 reg_val, NULL);
5044 if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
5045 usleep_range(1000, 2000);
5046 retry--;
5047 goto do_retry;
5048 }
5049 }
5050
5051 /* if the AQ access failed, try the old-fashioned way */
5052 if (status || use_register)
5053 wr32(hw, reg_addr, reg_val);
5054}
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005055
5056/**
5057 * i40e_aq_write_ppp - Write pipeline personalization profile (ppp)
5058 * @hw: pointer to the hw struct
5059 * @buff: command buffer (size in bytes = buff_size)
5060 * @buff_size: buffer size in bytes
5061 * @track_id: package tracking id
5062 * @error_offset: returns error offset
5063 * @error_info: returns error information
5064 * @cmd_details: pointer to command details structure or NULL
5065 **/
5066enum
5067i40e_status_code i40e_aq_write_ppp(struct i40e_hw *hw, void *buff,
5068 u16 buff_size, u32 track_id,
5069 u32 *error_offset, u32 *error_info,
5070 struct i40e_asq_cmd_details *cmd_details)
5071{
5072 struct i40e_aq_desc desc;
5073 struct i40e_aqc_write_personalization_profile *cmd =
5074 (struct i40e_aqc_write_personalization_profile *)
5075 &desc.params.raw;
5076 struct i40e_aqc_write_ppp_resp *resp;
5077 i40e_status status;
5078
5079 i40e_fill_default_direct_cmd_desc(&desc,
5080 i40e_aqc_opc_write_personalization_profile);
5081
5082 desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
5083 if (buff_size > I40E_AQ_LARGE_BUF)
5084 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
5085
5086 desc.datalen = cpu_to_le16(buff_size);
5087
5088 cmd->profile_track_id = cpu_to_le32(track_id);
5089
5090 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
5091 if (!status) {
5092 resp = (struct i40e_aqc_write_ppp_resp *)&desc.params.raw;
5093 if (error_offset)
5094 *error_offset = le32_to_cpu(resp->error_offset);
5095 if (error_info)
5096 *error_info = le32_to_cpu(resp->error_info);
5097 }
5098
5099 return status;
5100}
5101
5102/**
5103 * i40e_aq_get_ppp_list - Read pipeline personalization profile (ppp)
5104 * @hw: pointer to the hw struct
5105 * @buff: command buffer (size in bytes = buff_size)
5106 * @buff_size: buffer size in bytes
5107 * @cmd_details: pointer to command details structure or NULL
5108 **/
5109enum
5110i40e_status_code i40e_aq_get_ppp_list(struct i40e_hw *hw, void *buff,
5111 u16 buff_size, u8 flags,
5112 struct i40e_asq_cmd_details *cmd_details)
5113{
5114 struct i40e_aq_desc desc;
5115 struct i40e_aqc_get_applied_profiles *cmd =
5116 (struct i40e_aqc_get_applied_profiles *)&desc.params.raw;
5117 i40e_status status;
5118
5119 i40e_fill_default_direct_cmd_desc(&desc,
5120 i40e_aqc_opc_get_personalization_profile_list);
5121
5122 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
5123 if (buff_size > I40E_AQ_LARGE_BUF)
5124 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
5125 desc.datalen = cpu_to_le16(buff_size);
5126
5127 cmd->flags = flags;
5128
5129 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
5130
5131 return status;
5132}
5133
5134/**
5135 * i40e_find_segment_in_package
5136 * @segment_type: the segment type to search for (i.e., SEGMENT_TYPE_I40E)
5137 * @pkg_hdr: pointer to the package header to be searched
5138 *
5139 * This function searches a package file for a particular segment type. On
5140 * success it returns a pointer to the segment header, otherwise it will
5141 * return NULL.
5142 **/
5143struct i40e_generic_seg_header *
5144i40e_find_segment_in_package(u32 segment_type,
5145 struct i40e_package_header *pkg_hdr)
5146{
5147 struct i40e_generic_seg_header *segment;
5148 u32 i;
5149
5150 /* Search all package segments for the requested segment type */
5151 for (i = 0; i < pkg_hdr->segment_count; i++) {
5152 segment =
5153 (struct i40e_generic_seg_header *)((u8 *)pkg_hdr +
5154 pkg_hdr->segment_offset[i]);
5155
5156 if (segment->type == segment_type)
5157 return segment;
5158 }
5159
5160 return NULL;
5161}
5162
5163/**
5164 * i40e_write_profile
5165 * @hw: pointer to the hardware structure
5166 * @profile: pointer to the profile segment of the package to be downloaded
5167 * @track_id: package tracking id
5168 *
5169 * Handles the download of a complete package.
5170 */
5171enum i40e_status_code
5172i40e_write_profile(struct i40e_hw *hw, struct i40e_profile_segment *profile,
5173 u32 track_id)
5174{
5175 i40e_status status = 0;
5176 struct i40e_section_table *sec_tbl;
5177 struct i40e_profile_section_header *sec = NULL;
5178 u32 dev_cnt;
5179 u32 vendor_dev_id;
5180 u32 *nvm;
5181 u32 section_size = 0;
5182 u32 offset = 0, info = 0;
5183 u32 i;
5184
5185 if (!track_id) {
5186 i40e_debug(hw, I40E_DEBUG_PACKAGE, "Track_id can't be 0.");
5187 return I40E_NOT_SUPPORTED;
5188 }
5189
5190 dev_cnt = profile->device_table_count;
5191
5192 for (i = 0; i < dev_cnt; i++) {
5193 vendor_dev_id = profile->device_table[i].vendor_dev_id;
5194 if ((vendor_dev_id >> 16) == PCI_VENDOR_ID_INTEL)
5195 if (hw->device_id == (vendor_dev_id & 0xFFFF))
5196 break;
5197 }
5198 if (i == dev_cnt) {
5199 i40e_debug(hw, I40E_DEBUG_PACKAGE, "Device doesn't support PPP");
5200 return I40E_ERR_DEVICE_NOT_SUPPORTED;
5201 }
5202
5203 nvm = (u32 *)&profile->device_table[dev_cnt];
5204 sec_tbl = (struct i40e_section_table *)&nvm[nvm[0] + 1];
5205
5206 for (i = 0; i < sec_tbl->section_count; i++) {
5207 sec = (struct i40e_profile_section_header *)((u8 *)profile +
5208 sec_tbl->section_offset[i]);
5209
5210 /* Skip 'AQ', 'note' and 'name' sections */
5211 if (sec->section.type != SECTION_TYPE_MMIO)
5212 continue;
5213
5214 section_size = sec->section.size +
5215 sizeof(struct i40e_profile_section_header);
5216
5217 /* Write profile */
5218 status = i40e_aq_write_ppp(hw, (void *)sec, (u16)section_size,
5219 track_id, &offset, &info, NULL);
5220 if (status) {
5221 i40e_debug(hw, I40E_DEBUG_PACKAGE,
5222 "Failed to write profile: offset %d, info %d",
5223 offset, info);
5224 break;
5225 }
5226 }
5227 return status;
5228}
5229
5230/**
5231 * i40e_add_pinfo_to_list
5232 * @hw: pointer to the hardware structure
5233 * @profile: pointer to the profile segment of the package
5234 * @profile_info_sec: buffer for information section
5235 * @track_id: package tracking id
5236 *
5237 * Register a profile to the list of loaded profiles.
5238 */
5239enum i40e_status_code
5240i40e_add_pinfo_to_list(struct i40e_hw *hw,
5241 struct i40e_profile_segment *profile,
5242 u8 *profile_info_sec, u32 track_id)
5243{
5244 i40e_status status = 0;
5245 struct i40e_profile_section_header *sec = NULL;
5246 struct i40e_profile_info *pinfo;
5247 u32 offset = 0, info = 0;
5248
5249 sec = (struct i40e_profile_section_header *)profile_info_sec;
5250 sec->tbl_size = 1;
5251 sec->data_end = sizeof(struct i40e_profile_section_header) +
5252 sizeof(struct i40e_profile_info);
5253 sec->section.type = SECTION_TYPE_INFO;
5254 sec->section.offset = sizeof(struct i40e_profile_section_header);
5255 sec->section.size = sizeof(struct i40e_profile_info);
5256 pinfo = (struct i40e_profile_info *)(profile_info_sec +
5257 sec->section.offset);
5258 pinfo->track_id = track_id;
5259 pinfo->version = profile->version;
5260 pinfo->op = I40E_PPP_ADD_TRACKID;
5261 memcpy(pinfo->name, profile->name, I40E_PPP_NAME_SIZE);
5262
5263 status = i40e_aq_write_ppp(hw, (void *)sec, sec->data_end,
5264 track_id, &offset, &info, NULL);
5265 return status;
5266}