blob: ee6052ecd2158e19dbc62eaa0150e816e725a0b7 [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)
Jacob Keller3d72aeb2017-10-27 11:06:55 -0400951 hw->flags |= I40E_HW_FLAG_AQ_SRCTL_ACCESS_ENABLE |
952 I40E_HW_FLAG_NVM_READ_REQUIRES_LOCK;
Anjali Singhai07f89be2015-09-24 15:26:32 -0700953
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000954 status = i40e_init_nvm(hw);
955 return status;
956}
957
958/**
959 * i40e_aq_mac_address_read - Retrieve the MAC addresses
960 * @hw: pointer to the hw struct
961 * @flags: a return indicator of what addresses were added to the addr store
962 * @addrs: the requestor's mac addr store
963 * @cmd_details: pointer to command details structure or NULL
964 **/
965static i40e_status i40e_aq_mac_address_read(struct i40e_hw *hw,
966 u16 *flags,
967 struct i40e_aqc_mac_address_read_data *addrs,
968 struct i40e_asq_cmd_details *cmd_details)
969{
970 struct i40e_aq_desc desc;
971 struct i40e_aqc_mac_address_read *cmd_data =
972 (struct i40e_aqc_mac_address_read *)&desc.params.raw;
973 i40e_status status;
974
975 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_mac_address_read);
976 desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF);
977
978 status = i40e_asq_send_command(hw, &desc, addrs,
979 sizeof(*addrs), cmd_details);
980 *flags = le16_to_cpu(cmd_data->command_flags);
981
982 return status;
983}
984
985/**
986 * i40e_aq_mac_address_write - Change the MAC addresses
987 * @hw: pointer to the hw struct
988 * @flags: indicates which MAC to be written
989 * @mac_addr: address to write
990 * @cmd_details: pointer to command details structure or NULL
991 **/
992i40e_status i40e_aq_mac_address_write(struct i40e_hw *hw,
993 u16 flags, u8 *mac_addr,
994 struct i40e_asq_cmd_details *cmd_details)
995{
996 struct i40e_aq_desc desc;
997 struct i40e_aqc_mac_address_write *cmd_data =
998 (struct i40e_aqc_mac_address_write *)&desc.params.raw;
999 i40e_status status;
1000
1001 i40e_fill_default_direct_cmd_desc(&desc,
1002 i40e_aqc_opc_mac_address_write);
1003 cmd_data->command_flags = cpu_to_le16(flags);
Kamil Krawczyk55c29c32013-12-18 13:45:52 +00001004 cmd_data->mac_sah = cpu_to_le16((u16)mac_addr[0] << 8 | mac_addr[1]);
1005 cmd_data->mac_sal = cpu_to_le32(((u32)mac_addr[2] << 24) |
1006 ((u32)mac_addr[3] << 16) |
1007 ((u32)mac_addr[4] << 8) |
1008 mac_addr[5]);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001009
1010 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1011
1012 return status;
1013}
1014
1015/**
1016 * i40e_get_mac_addr - get MAC address
1017 * @hw: pointer to the HW structure
1018 * @mac_addr: pointer to MAC address
1019 *
1020 * Reads the adapter's MAC address from register
1021 **/
1022i40e_status i40e_get_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
1023{
1024 struct i40e_aqc_mac_address_read_data addrs;
1025 i40e_status status;
1026 u16 flags = 0;
1027
1028 status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
1029
1030 if (flags & I40E_AQC_LAN_ADDR_VALID)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001031 ether_addr_copy(mac_addr, addrs.pf_lan_mac);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001032
1033 return status;
1034}
1035
1036/**
Neerav Parikh1f224ad2014-02-12 01:45:31 +00001037 * i40e_get_port_mac_addr - get Port MAC address
1038 * @hw: pointer to the HW structure
1039 * @mac_addr: pointer to Port MAC address
1040 *
1041 * Reads the adapter's Port MAC address
1042 **/
1043i40e_status i40e_get_port_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
1044{
1045 struct i40e_aqc_mac_address_read_data addrs;
1046 i40e_status status;
1047 u16 flags = 0;
1048
1049 status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
1050 if (status)
1051 return status;
1052
1053 if (flags & I40E_AQC_PORT_ADDR_VALID)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001054 ether_addr_copy(mac_addr, addrs.port_mac);
Neerav Parikh1f224ad2014-02-12 01:45:31 +00001055 else
1056 status = I40E_ERR_INVALID_MAC_ADDR;
1057
1058 return status;
1059}
1060
1061/**
Matt Jared351499ab2014-04-23 04:50:03 +00001062 * i40e_pre_tx_queue_cfg - pre tx queue configure
1063 * @hw: pointer to the HW structure
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00001064 * @queue: target PF queue index
Matt Jared351499ab2014-04-23 04:50:03 +00001065 * @enable: state change request
1066 *
1067 * Handles hw requirement to indicate intention to enable
1068 * or disable target queue.
1069 **/
1070void i40e_pre_tx_queue_cfg(struct i40e_hw *hw, u32 queue, bool enable)
1071{
Shannon Nelsondfb699f2014-05-22 06:32:28 +00001072 u32 abs_queue_idx = hw->func_caps.base_queue + queue;
Matt Jared351499ab2014-04-23 04:50:03 +00001073 u32 reg_block = 0;
Shannon Nelsondfb699f2014-05-22 06:32:28 +00001074 u32 reg_val;
Matt Jared351499ab2014-04-23 04:50:03 +00001075
Christopher Pau24a768c2014-06-04 20:41:59 +00001076 if (abs_queue_idx >= 128) {
Matt Jared351499ab2014-04-23 04:50:03 +00001077 reg_block = abs_queue_idx / 128;
Christopher Pau24a768c2014-06-04 20:41:59 +00001078 abs_queue_idx %= 128;
1079 }
Matt Jared351499ab2014-04-23 04:50:03 +00001080
1081 reg_val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
1082 reg_val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
1083 reg_val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
1084
1085 if (enable)
1086 reg_val |= I40E_GLLAN_TXPRE_QDIS_CLEAR_QDIS_MASK;
1087 else
1088 reg_val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
1089
1090 wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), reg_val);
1091}
1092
1093/**
Kamil Krawczyk18f680c2014-12-11 07:06:31 +00001094 * i40e_read_pba_string - Reads part number string from EEPROM
1095 * @hw: pointer to hardware structure
1096 * @pba_num: stores the part number string from the EEPROM
1097 * @pba_num_size: part number string buffer length
1098 *
1099 * Reads the part number string from the EEPROM.
1100 **/
1101i40e_status i40e_read_pba_string(struct i40e_hw *hw, u8 *pba_num,
1102 u32 pba_num_size)
1103{
1104 i40e_status status = 0;
1105 u16 pba_word = 0;
1106 u16 pba_size = 0;
1107 u16 pba_ptr = 0;
1108 u16 i = 0;
1109
1110 status = i40e_read_nvm_word(hw, I40E_SR_PBA_FLAGS, &pba_word);
1111 if (status || (pba_word != 0xFAFA)) {
1112 hw_dbg(hw, "Failed to read PBA flags or flag is invalid.\n");
1113 return status;
1114 }
1115
1116 status = i40e_read_nvm_word(hw, I40E_SR_PBA_BLOCK_PTR, &pba_ptr);
1117 if (status) {
1118 hw_dbg(hw, "Failed to read PBA Block pointer.\n");
1119 return status;
1120 }
1121
1122 status = i40e_read_nvm_word(hw, pba_ptr, &pba_size);
1123 if (status) {
1124 hw_dbg(hw, "Failed to read PBA Block size.\n");
1125 return status;
1126 }
1127
1128 /* Subtract one to get PBA word count (PBA Size word is included in
1129 * total size)
1130 */
1131 pba_size--;
1132 if (pba_num_size < (((u32)pba_size * 2) + 1)) {
1133 hw_dbg(hw, "Buffer to small for PBA data.\n");
1134 return I40E_ERR_PARAM;
1135 }
1136
1137 for (i = 0; i < pba_size; i++) {
1138 status = i40e_read_nvm_word(hw, (pba_ptr + 1) + i, &pba_word);
1139 if (status) {
1140 hw_dbg(hw, "Failed to read PBA Block word %d.\n", i);
1141 return status;
1142 }
1143
1144 pba_num[(i * 2)] = (pba_word >> 8) & 0xFF;
1145 pba_num[(i * 2) + 1] = pba_word & 0xFF;
1146 }
1147 pba_num[(pba_size * 2)] = '\0';
1148
1149 return status;
1150}
1151
1152/**
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001153 * i40e_get_media_type - Gets media type
1154 * @hw: pointer to the hardware structure
1155 **/
1156static enum i40e_media_type i40e_get_media_type(struct i40e_hw *hw)
1157{
1158 enum i40e_media_type media;
1159
1160 switch (hw->phy.link_info.phy_type) {
1161 case I40E_PHY_TYPE_10GBASE_SR:
1162 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +00001163 case I40E_PHY_TYPE_1000BASE_SX:
1164 case I40E_PHY_TYPE_1000BASE_LX:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001165 case I40E_PHY_TYPE_40GBASE_SR4:
1166 case I40E_PHY_TYPE_40GBASE_LR4:
Carolyn Wyborny31232372016-11-21 13:03:48 -08001167 case I40E_PHY_TYPE_25GBASE_LR:
1168 case I40E_PHY_TYPE_25GBASE_SR:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001169 media = I40E_MEDIA_TYPE_FIBER;
1170 break;
1171 case I40E_PHY_TYPE_100BASE_TX:
1172 case I40E_PHY_TYPE_1000BASE_T:
1173 case I40E_PHY_TYPE_10GBASE_T:
1174 media = I40E_MEDIA_TYPE_BASET;
1175 break;
1176 case I40E_PHY_TYPE_10GBASE_CR1_CU:
1177 case I40E_PHY_TYPE_40GBASE_CR4_CU:
1178 case I40E_PHY_TYPE_10GBASE_CR1:
1179 case I40E_PHY_TYPE_40GBASE_CR4:
1180 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +00001181 case I40E_PHY_TYPE_40GBASE_AOC:
1182 case I40E_PHY_TYPE_10GBASE_AOC:
Carolyn Wyborny31232372016-11-21 13:03:48 -08001183 case I40E_PHY_TYPE_25GBASE_CR:
Sudheer Mogilappagari211b4c12017-10-05 14:53:39 -07001184 case I40E_PHY_TYPE_25GBASE_AOC:
1185 case I40E_PHY_TYPE_25GBASE_ACC:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001186 media = I40E_MEDIA_TYPE_DA;
1187 break;
1188 case I40E_PHY_TYPE_1000BASE_KX:
1189 case I40E_PHY_TYPE_10GBASE_KX4:
1190 case I40E_PHY_TYPE_10GBASE_KR:
1191 case I40E_PHY_TYPE_40GBASE_KR4:
Jesse Brandeburgae24b402015-03-27 00:12:09 -07001192 case I40E_PHY_TYPE_20GBASE_KR2:
Carolyn Wyborny31232372016-11-21 13:03:48 -08001193 case I40E_PHY_TYPE_25GBASE_KR:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001194 media = I40E_MEDIA_TYPE_BACKPLANE;
1195 break;
1196 case I40E_PHY_TYPE_SGMII:
1197 case I40E_PHY_TYPE_XAUI:
1198 case I40E_PHY_TYPE_XFI:
1199 case I40E_PHY_TYPE_XLAUI:
1200 case I40E_PHY_TYPE_XLPPI:
1201 default:
1202 media = I40E_MEDIA_TYPE_UNKNOWN;
1203 break;
1204 }
1205
1206 return media;
1207}
1208
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001209#define I40E_PF_RESET_WAIT_COUNT_A0 200
Akeem G Abodunrin8af580d2015-03-27 00:12:10 -07001210#define I40E_PF_RESET_WAIT_COUNT 200
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001211/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001212 * i40e_pf_reset - Reset the PF
1213 * @hw: pointer to the hardware structure
1214 *
1215 * Assuming someone else has triggered a global reset,
1216 * assure the global reset is complete and then reset the PF
1217 **/
1218i40e_status i40e_pf_reset(struct i40e_hw *hw)
1219{
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001220 u32 cnt = 0;
Shannon Nelson42794bd2013-12-11 08:17:10 +00001221 u32 cnt1 = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001222 u32 reg = 0;
1223 u32 grst_del;
1224
1225 /* Poll for Global Reset steady state in case of recent GRST.
1226 * The grst delay value is in 100ms units, and we'll wait a
1227 * couple counts longer to be sure we don't just miss the end.
1228 */
Shannon Nelsonde78fc52015-02-21 06:41:47 +00001229 grst_del = (rd32(hw, I40E_GLGEN_RSTCTL) &
1230 I40E_GLGEN_RSTCTL_GRSTDEL_MASK) >>
1231 I40E_GLGEN_RSTCTL_GRSTDEL_SHIFT;
Kevin Scott4d7cec02016-02-17 16:12:13 -08001232
1233 /* It can take upto 15 secs for GRST steady state.
1234 * Bump it to 16 secs max to be safe.
1235 */
1236 grst_del = grst_del * 20;
1237
1238 for (cnt = 0; cnt < grst_del; cnt++) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001239 reg = rd32(hw, I40E_GLGEN_RSTAT);
1240 if (!(reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK))
1241 break;
1242 msleep(100);
1243 }
1244 if (reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
1245 hw_dbg(hw, "Global reset polling failed to complete.\n");
1246 return I40E_ERR_RESET_FAILED;
1247 }
1248
Shannon Nelson42794bd2013-12-11 08:17:10 +00001249 /* Now Wait for the FW to be ready */
1250 for (cnt1 = 0; cnt1 < I40E_PF_RESET_WAIT_COUNT; cnt1++) {
1251 reg = rd32(hw, I40E_GLNVM_ULD);
1252 reg &= (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
1253 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK);
1254 if (reg == (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
1255 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK)) {
1256 hw_dbg(hw, "Core and Global modules ready %d\n", cnt1);
1257 break;
1258 }
1259 usleep_range(10000, 20000);
1260 }
1261 if (!(reg & (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
1262 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK))) {
1263 hw_dbg(hw, "wait for FW Reset complete timedout\n");
1264 hw_dbg(hw, "I40E_GLNVM_ULD = 0x%x\n", reg);
1265 return I40E_ERR_RESET_FAILED;
1266 }
1267
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001268 /* If there was a Global Reset in progress when we got here,
1269 * we don't need to do the PF Reset
1270 */
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001271 if (!cnt) {
Filip Sadowski94075bb2017-11-14 07:00:49 -05001272 u32 reg2 = 0;
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001273 if (hw->revision_id == 0)
1274 cnt = I40E_PF_RESET_WAIT_COUNT_A0;
1275 else
1276 cnt = I40E_PF_RESET_WAIT_COUNT;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001277 reg = rd32(hw, I40E_PFGEN_CTRL);
1278 wr32(hw, I40E_PFGEN_CTRL,
1279 (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001280 for (; cnt; cnt--) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001281 reg = rd32(hw, I40E_PFGEN_CTRL);
1282 if (!(reg & I40E_PFGEN_CTRL_PFSWR_MASK))
1283 break;
Filip Sadowski94075bb2017-11-14 07:00:49 -05001284 reg2 = rd32(hw, I40E_GLGEN_RSTAT);
1285 if (reg2 & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
1286 hw_dbg(hw, "Core reset upcoming. Skipping PF reset request.\n");
1287 hw_dbg(hw, "I40E_GLGEN_RSTAT = 0x%x\n", reg2);
1288 return I40E_ERR_NOT_READY;
1289 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001290 usleep_range(1000, 2000);
1291 }
1292 if (reg & I40E_PFGEN_CTRL_PFSWR_MASK) {
1293 hw_dbg(hw, "PF reset polling failed to complete.\n");
1294 return I40E_ERR_RESET_FAILED;
1295 }
1296 }
1297
1298 i40e_clear_pxe_mode(hw);
Shannon Nelson922680b2013-12-18 05:29:17 +00001299
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001300 return 0;
1301}
1302
1303/**
Shannon Nelson838d41d2014-06-04 20:41:27 +00001304 * i40e_clear_hw - clear out any left over hw state
1305 * @hw: pointer to the hw struct
1306 *
1307 * Clear queues and interrupts, typically called at init time,
1308 * but after the capabilities have been found so we know how many
1309 * queues and msix vectors have been allocated.
1310 **/
1311void i40e_clear_hw(struct i40e_hw *hw)
1312{
1313 u32 num_queues, base_queue;
1314 u32 num_pf_int;
1315 u32 num_vf_int;
1316 u32 num_vfs;
1317 u32 i, j;
1318 u32 val;
1319 u32 eol = 0x7ff;
1320
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00001321 /* get number of interrupts, queues, and VFs */
Shannon Nelson838d41d2014-06-04 20:41:27 +00001322 val = rd32(hw, I40E_GLPCI_CNF2);
1323 num_pf_int = (val & I40E_GLPCI_CNF2_MSI_X_PF_N_MASK) >>
1324 I40E_GLPCI_CNF2_MSI_X_PF_N_SHIFT;
1325 num_vf_int = (val & I40E_GLPCI_CNF2_MSI_X_VF_N_MASK) >>
1326 I40E_GLPCI_CNF2_MSI_X_VF_N_SHIFT;
1327
Shannon Nelson272cdaf22016-02-17 16:12:21 -08001328 val = rd32(hw, I40E_PFLAN_QALLOC);
Shannon Nelson838d41d2014-06-04 20:41:27 +00001329 base_queue = (val & I40E_PFLAN_QALLOC_FIRSTQ_MASK) >>
1330 I40E_PFLAN_QALLOC_FIRSTQ_SHIFT;
1331 j = (val & I40E_PFLAN_QALLOC_LASTQ_MASK) >>
1332 I40E_PFLAN_QALLOC_LASTQ_SHIFT;
1333 if (val & I40E_PFLAN_QALLOC_VALID_MASK)
1334 num_queues = (j - base_queue) + 1;
1335 else
1336 num_queues = 0;
1337
1338 val = rd32(hw, I40E_PF_VT_PFALLOC);
1339 i = (val & I40E_PF_VT_PFALLOC_FIRSTVF_MASK) >>
1340 I40E_PF_VT_PFALLOC_FIRSTVF_SHIFT;
1341 j = (val & I40E_PF_VT_PFALLOC_LASTVF_MASK) >>
1342 I40E_PF_VT_PFALLOC_LASTVF_SHIFT;
1343 if (val & I40E_PF_VT_PFALLOC_VALID_MASK)
1344 num_vfs = (j - i) + 1;
1345 else
1346 num_vfs = 0;
1347
1348 /* stop all the interrupts */
1349 wr32(hw, I40E_PFINT_ICR0_ENA, 0);
1350 val = 0x3 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT;
1351 for (i = 0; i < num_pf_int - 2; i++)
1352 wr32(hw, I40E_PFINT_DYN_CTLN(i), val);
1353
1354 /* Set the FIRSTQ_INDX field to 0x7FF in PFINT_LNKLSTx */
1355 val = eol << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
1356 wr32(hw, I40E_PFINT_LNKLST0, val);
1357 for (i = 0; i < num_pf_int - 2; i++)
1358 wr32(hw, I40E_PFINT_LNKLSTN(i), val);
1359 val = eol << I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT;
1360 for (i = 0; i < num_vfs; i++)
1361 wr32(hw, I40E_VPINT_LNKLST0(i), val);
1362 for (i = 0; i < num_vf_int - 2; i++)
1363 wr32(hw, I40E_VPINT_LNKLSTN(i), val);
1364
1365 /* warn the HW of the coming Tx disables */
1366 for (i = 0; i < num_queues; i++) {
1367 u32 abs_queue_idx = base_queue + i;
1368 u32 reg_block = 0;
1369
1370 if (abs_queue_idx >= 128) {
1371 reg_block = abs_queue_idx / 128;
1372 abs_queue_idx %= 128;
1373 }
1374
1375 val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
1376 val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
1377 val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
1378 val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
1379
1380 wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), val);
1381 }
1382 udelay(400);
1383
1384 /* stop all the queues */
1385 for (i = 0; i < num_queues; i++) {
1386 wr32(hw, I40E_QINT_TQCTL(i), 0);
1387 wr32(hw, I40E_QTX_ENA(i), 0);
1388 wr32(hw, I40E_QINT_RQCTL(i), 0);
1389 wr32(hw, I40E_QRX_ENA(i), 0);
1390 }
1391
1392 /* short wait for all queue disables to settle */
1393 udelay(50);
1394}
1395
1396/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001397 * i40e_clear_pxe_mode - clear pxe operations mode
1398 * @hw: pointer to the hw struct
1399 *
1400 * Make sure all PXE mode settings are cleared, including things
1401 * like descriptor fetch/write-back mode.
1402 **/
1403void i40e_clear_pxe_mode(struct i40e_hw *hw)
1404{
1405 u32 reg;
1406
Shannon Nelsonc9b9b0a2014-04-09 05:59:05 +00001407 if (i40e_check_asq_alive(hw))
1408 i40e_aq_clear_pxe_mode(hw, NULL);
1409
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001410 /* Clear single descriptor fetch/write-back mode */
1411 reg = rd32(hw, I40E_GLLAN_RCTL_0);
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001412
1413 if (hw->revision_id == 0) {
1414 /* As a work around clear PXE_MODE instead of setting it */
1415 wr32(hw, I40E_GLLAN_RCTL_0, (reg & (~I40E_GLLAN_RCTL_0_PXE_MODE_MASK)));
1416 } else {
1417 wr32(hw, I40E_GLLAN_RCTL_0, (reg | I40E_GLLAN_RCTL_0_PXE_MODE_MASK));
1418 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001419}
1420
1421/**
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001422 * i40e_led_is_mine - helper to find matching led
1423 * @hw: pointer to the hw struct
1424 * @idx: index into GPIO registers
1425 *
1426 * returns: 0 if no match, otherwise the value of the GPIO_CTL register
1427 */
1428static u32 i40e_led_is_mine(struct i40e_hw *hw, int idx)
1429{
1430 u32 gpio_val = 0;
1431 u32 port;
1432
1433 if (!hw->func_caps.led[idx])
1434 return 0;
1435
1436 gpio_val = rd32(hw, I40E_GLGEN_GPIO_CTL(idx));
1437 port = (gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_MASK) >>
1438 I40E_GLGEN_GPIO_CTL_PRT_NUM_SHIFT;
1439
1440 /* if PRT_NUM_NA is 1 then this LED is not port specific, OR
1441 * if it is not our port then ignore
1442 */
1443 if ((gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_NA_MASK) ||
1444 (port != hw->port))
1445 return 0;
1446
1447 return gpio_val;
1448}
1449
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001450#define I40E_COMBINED_ACTIVITY 0xA
1451#define I40E_FILTER_ACTIVITY 0xE
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001452#define I40E_LINK_ACTIVITY 0xC
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001453#define I40E_MAC_ACTIVITY 0xD
1454#define I40E_LED0 22
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001455
1456/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001457 * i40e_led_get - return current on/off mode
1458 * @hw: pointer to the hw struct
1459 *
1460 * The value returned is the 'mode' field as defined in the
1461 * GPIO register definitions: 0x0 = off, 0xf = on, and other
1462 * values are variations of possible behaviors relating to
1463 * blink, link, and wire.
1464 **/
1465u32 i40e_led_get(struct i40e_hw *hw)
1466{
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001467 u32 current_mode = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001468 u32 mode = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001469 int i;
1470
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001471 /* as per the documentation GPIO 22-29 are the LED
1472 * GPIO pins named LED0..LED7
1473 */
1474 for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
1475 u32 gpio_val = i40e_led_is_mine(hw, i);
1476
1477 if (!gpio_val)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001478 continue;
1479
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001480 /* ignore gpio LED src mode entries related to the activity
1481 * LEDs
1482 */
1483 current_mode = ((gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK)
1484 >> I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT);
1485 switch (current_mode) {
1486 case I40E_COMBINED_ACTIVITY:
1487 case I40E_FILTER_ACTIVITY:
1488 case I40E_MAC_ACTIVITY:
Michal Kuchtad95cd482017-12-18 05:17:03 -05001489 case I40E_LINK_ACTIVITY:
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001490 continue;
1491 default:
1492 break;
1493 }
1494
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001495 mode = (gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK) >>
1496 I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001497 break;
1498 }
1499
1500 return mode;
1501}
1502
1503/**
1504 * i40e_led_set - set new on/off mode
1505 * @hw: pointer to the hw struct
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001506 * @mode: 0=off, 0xf=on (else see manual for mode details)
1507 * @blink: true if the LED should blink when on, false if steady
1508 *
1509 * if this function is used to turn on the blink it should
1510 * be used to disable the blink when restoring the original state.
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001511 **/
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001512void i40e_led_set(struct i40e_hw *hw, u32 mode, bool blink)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001513{
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001514 u32 current_mode = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001515 int i;
1516
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001517 if (mode & 0xfffffff0)
1518 hw_dbg(hw, "invalid mode passed in %X\n", mode);
1519
1520 /* as per the documentation GPIO 22-29 are the LED
1521 * GPIO pins named LED0..LED7
1522 */
1523 for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
1524 u32 gpio_val = i40e_led_is_mine(hw, i);
1525
1526 if (!gpio_val)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001527 continue;
1528
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001529 /* ignore gpio LED src mode entries related to the activity
1530 * LEDs
1531 */
1532 current_mode = ((gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK)
1533 >> I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT);
1534 switch (current_mode) {
1535 case I40E_COMBINED_ACTIVITY:
1536 case I40E_FILTER_ACTIVITY:
1537 case I40E_MAC_ACTIVITY:
Michal Kuchtad95cd482017-12-18 05:17:03 -05001538 case I40E_LINK_ACTIVITY:
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001539 continue;
1540 default:
1541 break;
1542 }
1543
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001544 gpio_val &= ~I40E_GLGEN_GPIO_CTL_LED_MODE_MASK;
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001545 /* this & is a bit of paranoia, but serves as a range check */
1546 gpio_val |= ((mode << I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT) &
1547 I40E_GLGEN_GPIO_CTL_LED_MODE_MASK);
1548
Matt Jared9be00d62015-01-24 09:58:28 +00001549 if (blink)
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001550 gpio_val |= BIT(I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
Matt Jared9be00d62015-01-24 09:58:28 +00001551 else
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001552 gpio_val &= ~BIT(I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001553
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001554 wr32(hw, I40E_GLGEN_GPIO_CTL(i), gpio_val);
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001555 break;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001556 }
1557}
1558
1559/* Admin command wrappers */
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001560
1561/**
Catherine Sullivan8109e122014-06-04 08:45:24 +00001562 * i40e_aq_get_phy_capabilities
1563 * @hw: pointer to the hw struct
1564 * @abilities: structure for PHY capabilities to be filled
1565 * @qualified_modules: report Qualified Modules
1566 * @report_init: report init capabilities (active are default)
1567 * @cmd_details: pointer to command details structure or NULL
1568 *
1569 * Returns the various PHY abilities supported on the Port.
1570 **/
1571i40e_status i40e_aq_get_phy_capabilities(struct i40e_hw *hw,
1572 bool qualified_modules, bool report_init,
1573 struct i40e_aq_get_phy_abilities_resp *abilities,
1574 struct i40e_asq_cmd_details *cmd_details)
1575{
1576 struct i40e_aq_desc desc;
1577 i40e_status status;
1578 u16 abilities_size = sizeof(struct i40e_aq_get_phy_abilities_resp);
Jayaprakash Shanmugam49884102017-09-07 08:05:55 -04001579 u16 max_delay = I40E_MAX_PHY_TIMEOUT, total_delay = 0;
Catherine Sullivan8109e122014-06-04 08:45:24 +00001580
1581 if (!abilities)
1582 return I40E_ERR_PARAM;
1583
Jayaprakash Shanmugam49884102017-09-07 08:05:55 -04001584 do {
1585 i40e_fill_default_direct_cmd_desc(&desc,
1586 i40e_aqc_opc_get_phy_abilities);
Catherine Sullivan8109e122014-06-04 08:45:24 +00001587
Jayaprakash Shanmugam49884102017-09-07 08:05:55 -04001588 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
1589 if (abilities_size > I40E_AQ_LARGE_BUF)
1590 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
Catherine Sullivan8109e122014-06-04 08:45:24 +00001591
Jayaprakash Shanmugam49884102017-09-07 08:05:55 -04001592 if (qualified_modules)
1593 desc.params.external.param0 |=
Catherine Sullivan8109e122014-06-04 08:45:24 +00001594 cpu_to_le32(I40E_AQ_PHY_REPORT_QUALIFIED_MODULES);
1595
Jayaprakash Shanmugam49884102017-09-07 08:05:55 -04001596 if (report_init)
1597 desc.params.external.param0 |=
Catherine Sullivan8109e122014-06-04 08:45:24 +00001598 cpu_to_le32(I40E_AQ_PHY_REPORT_INITIAL_VALUES);
1599
Jayaprakash Shanmugam49884102017-09-07 08:05:55 -04001600 status = i40e_asq_send_command(hw, &desc, abilities,
1601 abilities_size, cmd_details);
Catherine Sullivan8109e122014-06-04 08:45:24 +00001602
Jayaprakash Shanmugam49884102017-09-07 08:05:55 -04001603 if (status)
1604 break;
1605
1606 if (hw->aq.asq_last_status == I40E_AQ_RC_EIO) {
1607 status = I40E_ERR_UNKNOWN_PHY;
1608 break;
1609 } else if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN) {
1610 usleep_range(1000, 2000);
1611 total_delay++;
1612 status = I40E_ERR_TIMEOUT;
1613 }
1614 } while ((hw->aq.asq_last_status != I40E_AQ_RC_OK) &&
1615 (total_delay < max_delay));
1616
1617 if (status)
1618 return status;
Catherine Sullivan8109e122014-06-04 08:45:24 +00001619
Carolyn Wyborny31232372016-11-21 13:03:48 -08001620 if (report_init) {
Mitch Williams22b965512017-07-14 09:27:09 -04001621 if (hw->mac.type == I40E_MAC_XL710 &&
1622 hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
Alan Brady8fdb69d2017-10-11 14:49:42 -07001623 hw->aq.api_min_ver >= I40E_MINOR_VER_GET_LINK_INFO_XL710) {
Mitch Williams22b965512017-07-14 09:27:09 -04001624 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
Alan Brady8fdb69d2017-10-11 14:49:42 -07001625 } else {
1626 hw->phy.phy_types = le32_to_cpu(abilities->phy_type);
1627 hw->phy.phy_types |=
1628 ((u64)abilities->phy_type_ext << 32);
1629 }
Carolyn Wyborny31232372016-11-21 13:03:48 -08001630 }
Kevin Scott3ac67d72015-09-03 17:18:58 -04001631
Catherine Sullivan8109e122014-06-04 08:45:24 +00001632 return status;
1633}
1634
1635/**
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001636 * i40e_aq_set_phy_config
1637 * @hw: pointer to the hw struct
1638 * @config: structure with PHY configuration to be set
1639 * @cmd_details: pointer to command details structure or NULL
1640 *
1641 * Set the various PHY configuration parameters
1642 * supported on the Port.One or more of the Set PHY config parameters may be
1643 * ignored in an MFP mode as the PF may not have the privilege to set some
1644 * of the PHY Config parameters. This status will be indicated by the
1645 * command response.
1646 **/
1647enum i40e_status_code i40e_aq_set_phy_config(struct i40e_hw *hw,
1648 struct i40e_aq_set_phy_config *config,
1649 struct i40e_asq_cmd_details *cmd_details)
1650{
1651 struct i40e_aq_desc desc;
1652 struct i40e_aq_set_phy_config *cmd =
1653 (struct i40e_aq_set_phy_config *)&desc.params.raw;
1654 enum i40e_status_code status;
1655
1656 if (!config)
1657 return I40E_ERR_PARAM;
1658
1659 i40e_fill_default_direct_cmd_desc(&desc,
1660 i40e_aqc_opc_set_phy_config);
1661
1662 *cmd = *config;
1663
1664 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1665
1666 return status;
1667}
1668
1669/**
1670 * i40e_set_fc
1671 * @hw: pointer to the hw struct
1672 *
1673 * Set the requested flow control mode using set_phy_config.
1674 **/
1675enum i40e_status_code i40e_set_fc(struct i40e_hw *hw, u8 *aq_failures,
1676 bool atomic_restart)
1677{
1678 enum i40e_fc_mode fc_mode = hw->fc.requested_mode;
1679 struct i40e_aq_get_phy_abilities_resp abilities;
1680 struct i40e_aq_set_phy_config config;
1681 enum i40e_status_code status;
1682 u8 pause_mask = 0x0;
1683
1684 *aq_failures = 0x0;
1685
1686 switch (fc_mode) {
1687 case I40E_FC_FULL:
1688 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
1689 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
1690 break;
1691 case I40E_FC_RX_PAUSE:
1692 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
1693 break;
1694 case I40E_FC_TX_PAUSE:
1695 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
1696 break;
1697 default:
1698 break;
1699 }
1700
1701 /* Get the current phy config */
1702 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
1703 NULL);
1704 if (status) {
1705 *aq_failures |= I40E_SET_FC_AQ_FAIL_GET;
1706 return status;
1707 }
1708
1709 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
1710 /* clear the old pause settings */
1711 config.abilities = abilities.abilities & ~(I40E_AQ_PHY_FLAG_PAUSE_TX) &
1712 ~(I40E_AQ_PHY_FLAG_PAUSE_RX);
1713 /* set the new abilities */
1714 config.abilities |= pause_mask;
1715 /* If the abilities have changed, then set the new config */
1716 if (config.abilities != abilities.abilities) {
1717 /* Auto restart link so settings take effect */
1718 if (atomic_restart)
1719 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
1720 /* Copy over all the old settings */
1721 config.phy_type = abilities.phy_type;
Carolyn Wyborny31232372016-11-21 13:03:48 -08001722 config.phy_type_ext = abilities.phy_type_ext;
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001723 config.link_speed = abilities.link_speed;
1724 config.eee_capability = abilities.eee_capability;
1725 config.eeer = abilities.eeer_val;
1726 config.low_power_ctrl = abilities.d3_lpan;
Carolyn Wyborny60f000a2016-11-21 13:03:49 -08001727 config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
1728 I40E_AQ_PHY_FEC_CONFIG_MASK;
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001729 status = i40e_aq_set_phy_config(hw, &config, NULL);
1730
1731 if (status)
1732 *aq_failures |= I40E_SET_FC_AQ_FAIL_SET;
1733 }
1734 /* Update the link info */
Catherine Sullivan0a862b42015-08-31 19:54:53 -04001735 status = i40e_update_link_info(hw);
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001736 if (status) {
1737 /* Wait a little bit (on 40G cards it sometimes takes a really
1738 * long time for link to come back from the atomic reset)
1739 * and try once more
1740 */
1741 msleep(1000);
Catherine Sullivan0a862b42015-08-31 19:54:53 -04001742 status = i40e_update_link_info(hw);
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001743 }
1744 if (status)
1745 *aq_failures |= I40E_SET_FC_AQ_FAIL_UPDATE;
1746
1747 return status;
1748}
1749
1750/**
Shannon Nelsonc9b9b0a2014-04-09 05:59:05 +00001751 * i40e_aq_clear_pxe_mode
1752 * @hw: pointer to the hw struct
1753 * @cmd_details: pointer to command details structure or NULL
1754 *
1755 * Tell the firmware that the driver is taking over from PXE
1756 **/
1757i40e_status i40e_aq_clear_pxe_mode(struct i40e_hw *hw,
1758 struct i40e_asq_cmd_details *cmd_details)
1759{
1760 i40e_status status;
1761 struct i40e_aq_desc desc;
1762 struct i40e_aqc_clear_pxe *cmd =
1763 (struct i40e_aqc_clear_pxe *)&desc.params.raw;
1764
1765 i40e_fill_default_direct_cmd_desc(&desc,
1766 i40e_aqc_opc_clear_pxe_mode);
1767
1768 cmd->rx_cnt = 0x2;
1769
1770 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1771
1772 wr32(hw, I40E_GLLAN_RCTL_0, 0x1);
1773
1774 return status;
1775}
1776
1777/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001778 * i40e_aq_set_link_restart_an
1779 * @hw: pointer to the hw struct
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001780 * @enable_link: if true: enable link, if false: disable link
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001781 * @cmd_details: pointer to command details structure or NULL
1782 *
1783 * Sets up the link and restarts the Auto-Negotiation over the link.
1784 **/
1785i40e_status i40e_aq_set_link_restart_an(struct i40e_hw *hw,
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001786 bool enable_link,
1787 struct i40e_asq_cmd_details *cmd_details)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001788{
1789 struct i40e_aq_desc desc;
1790 struct i40e_aqc_set_link_restart_an *cmd =
1791 (struct i40e_aqc_set_link_restart_an *)&desc.params.raw;
1792 i40e_status status;
1793
1794 i40e_fill_default_direct_cmd_desc(&desc,
1795 i40e_aqc_opc_set_link_restart_an);
1796
1797 cmd->command = I40E_AQ_PHY_RESTART_AN;
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001798 if (enable_link)
1799 cmd->command |= I40E_AQ_PHY_LINK_ENABLE;
1800 else
1801 cmd->command &= ~I40E_AQ_PHY_LINK_ENABLE;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001802
1803 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1804
1805 return status;
1806}
1807
1808/**
1809 * i40e_aq_get_link_info
1810 * @hw: pointer to the hw struct
1811 * @enable_lse: enable/disable LinkStatusEvent reporting
1812 * @link: pointer to link status structure - optional
1813 * @cmd_details: pointer to command details structure or NULL
1814 *
1815 * Returns the link status of the adapter.
1816 **/
1817i40e_status i40e_aq_get_link_info(struct i40e_hw *hw,
1818 bool enable_lse, struct i40e_link_status *link,
1819 struct i40e_asq_cmd_details *cmd_details)
1820{
1821 struct i40e_aq_desc desc;
1822 struct i40e_aqc_get_link_status *resp =
1823 (struct i40e_aqc_get_link_status *)&desc.params.raw;
1824 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
1825 i40e_status status;
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001826 bool tx_pause, rx_pause;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001827 u16 command_flags;
1828
1829 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_link_status);
1830
1831 if (enable_lse)
1832 command_flags = I40E_AQ_LSE_ENABLE;
1833 else
1834 command_flags = I40E_AQ_LSE_DISABLE;
1835 resp->command_flags = cpu_to_le16(command_flags);
1836
1837 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1838
1839 if (status)
1840 goto aq_get_link_info_exit;
1841
1842 /* save off old link status information */
Mitch Williamsc36bd4a72013-12-18 13:46:04 +00001843 hw->phy.link_info_old = *hw_link_info;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001844
1845 /* update link status */
1846 hw_link_info->phy_type = (enum i40e_aq_phy_type)resp->phy_type;
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001847 hw->phy.media_type = i40e_get_media_type(hw);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001848 hw_link_info->link_speed = (enum i40e_aq_link_speed)resp->link_speed;
1849 hw_link_info->link_info = resp->link_info;
1850 hw_link_info->an_info = resp->an_info;
Henry Tieman3e03d7c2016-12-02 12:32:57 -08001851 hw_link_info->fec_info = resp->config & (I40E_AQ_CONFIG_FEC_KR_ENA |
1852 I40E_AQ_CONFIG_FEC_RS_ENA);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001853 hw_link_info->ext_info = resp->ext_info;
Filip Sadowskid60bcc72017-08-22 06:57:43 -04001854 hw_link_info->loopback = resp->loopback & I40E_AQ_LOOPBACK_MASK;
Neerav Parikh6bb3f232014-04-01 07:11:56 +00001855 hw_link_info->max_frame_size = le16_to_cpu(resp->max_frame_size);
1856 hw_link_info->pacing = resp->config & I40E_AQ_CONFIG_PACING_MASK;
1857
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001858 /* update fc info */
1859 tx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_TX);
1860 rx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_RX);
1861 if (tx_pause & rx_pause)
1862 hw->fc.current_mode = I40E_FC_FULL;
1863 else if (tx_pause)
1864 hw->fc.current_mode = I40E_FC_TX_PAUSE;
1865 else if (rx_pause)
1866 hw->fc.current_mode = I40E_FC_RX_PAUSE;
1867 else
1868 hw->fc.current_mode = I40E_FC_NONE;
1869
Neerav Parikh6bb3f232014-04-01 07:11:56 +00001870 if (resp->config & I40E_AQ_CONFIG_CRC_ENA)
1871 hw_link_info->crc_enable = true;
1872 else
1873 hw_link_info->crc_enable = false;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001874
Filip Sadowski7ed35732016-09-14 16:24:33 -07001875 if (resp->command_flags & cpu_to_le16(I40E_AQ_LSE_IS_ENABLED))
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001876 hw_link_info->lse_enable = true;
1877 else
1878 hw_link_info->lse_enable = false;
1879
Henry Tiemane586bb62016-11-08 13:05:07 -08001880 if ((hw->mac.type == I40E_MAC_XL710) &&
1881 (hw->aq.fw_maj_ver < 4 || (hw->aq.fw_maj_ver == 4 &&
Catherine Sullivan088c4ee2015-02-26 16:14:12 +00001882 hw->aq.fw_min_ver < 40)) && hw_link_info->phy_type == 0xE)
1883 hw_link_info->phy_type = I40E_PHY_TYPE_10GBASE_SFPP_CU;
1884
Filip Sadowskid60bcc72017-08-22 06:57:43 -04001885 if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
1886 hw->aq.api_min_ver >= 7) {
1887 __le32 tmp;
1888
1889 memcpy(&tmp, resp->link_type, sizeof(tmp));
1890 hw->phy.phy_types = le32_to_cpu(tmp);
1891 hw->phy.phy_types |= ((u64)resp->link_type_ext << 32);
1892 }
1893
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001894 /* save link status information */
1895 if (link)
Jesse Brandeburgd7595a22013-09-13 08:23:22 +00001896 *link = *hw_link_info;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001897
1898 /* flag cleared so helper functions don't call AQ again */
1899 hw->phy.get_link_info = false;
1900
1901aq_get_link_info_exit:
1902 return status;
1903}
1904
1905/**
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00001906 * i40e_aq_set_phy_int_mask
1907 * @hw: pointer to the hw struct
1908 * @mask: interrupt mask to be set
1909 * @cmd_details: pointer to command details structure or NULL
1910 *
1911 * Set link interrupt mask.
1912 **/
1913i40e_status i40e_aq_set_phy_int_mask(struct i40e_hw *hw,
1914 u16 mask,
1915 struct i40e_asq_cmd_details *cmd_details)
1916{
1917 struct i40e_aq_desc desc;
1918 struct i40e_aqc_set_phy_int_mask *cmd =
1919 (struct i40e_aqc_set_phy_int_mask *)&desc.params.raw;
1920 i40e_status status;
1921
1922 i40e_fill_default_direct_cmd_desc(&desc,
1923 i40e_aqc_opc_set_phy_int_mask);
1924
1925 cmd->event_mask = cpu_to_le16(mask);
1926
1927 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1928
1929 return status;
1930}
1931
1932/**
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001933 * i40e_aq_set_phy_debug
1934 * @hw: pointer to the hw struct
1935 * @cmd_flags: debug command flags
1936 * @cmd_details: pointer to command details structure or NULL
1937 *
1938 * Reset the external PHY.
1939 **/
Jesse Brandeburg61829022016-03-10 14:59:42 -08001940i40e_status i40e_aq_set_phy_debug(struct i40e_hw *hw, u8 cmd_flags,
1941 struct i40e_asq_cmd_details *cmd_details)
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001942{
1943 struct i40e_aq_desc desc;
1944 struct i40e_aqc_set_phy_debug *cmd =
1945 (struct i40e_aqc_set_phy_debug *)&desc.params.raw;
Jesse Brandeburg61829022016-03-10 14:59:42 -08001946 i40e_status status;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001947
1948 i40e_fill_default_direct_cmd_desc(&desc,
1949 i40e_aqc_opc_set_phy_debug);
1950
1951 cmd->command_flags = cmd_flags;
1952
1953 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1954
1955 return status;
1956}
1957
1958/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001959 * i40e_aq_add_vsi
1960 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00001961 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001962 * @cmd_details: pointer to command details structure or NULL
1963 *
1964 * Add a VSI context to the hardware.
1965**/
1966i40e_status i40e_aq_add_vsi(struct i40e_hw *hw,
1967 struct i40e_vsi_context *vsi_ctx,
1968 struct i40e_asq_cmd_details *cmd_details)
1969{
1970 struct i40e_aq_desc desc;
1971 struct i40e_aqc_add_get_update_vsi *cmd =
1972 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
1973 struct i40e_aqc_add_get_update_vsi_completion *resp =
1974 (struct i40e_aqc_add_get_update_vsi_completion *)
1975 &desc.params.raw;
1976 i40e_status status;
1977
1978 i40e_fill_default_direct_cmd_desc(&desc,
1979 i40e_aqc_opc_add_vsi);
1980
1981 cmd->uplink_seid = cpu_to_le16(vsi_ctx->uplink_seid);
1982 cmd->connection_type = vsi_ctx->connection_type;
1983 cmd->vf_id = vsi_ctx->vf_num;
1984 cmd->vsi_flags = cpu_to_le16(vsi_ctx->flags);
1985
1986 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001987
1988 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
1989 sizeof(vsi_ctx->info), cmd_details);
1990
1991 if (status)
1992 goto aq_add_vsi_exit;
1993
1994 vsi_ctx->seid = le16_to_cpu(resp->seid);
1995 vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
1996 vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
1997 vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
1998
1999aq_add_vsi_exit:
2000 return status;
2001}
2002
2003/**
Mitch Williamsfb70fab2016-05-16 10:26:31 -07002004 * i40e_aq_set_default_vsi
2005 * @hw: pointer to the hw struct
2006 * @seid: vsi number
2007 * @cmd_details: pointer to command details structure or NULL
2008 **/
2009i40e_status i40e_aq_set_default_vsi(struct i40e_hw *hw,
2010 u16 seid,
2011 struct i40e_asq_cmd_details *cmd_details)
2012{
2013 struct i40e_aq_desc desc;
2014 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2015 (struct i40e_aqc_set_vsi_promiscuous_modes *)
2016 &desc.params.raw;
2017 i40e_status status;
2018
2019 i40e_fill_default_direct_cmd_desc(&desc,
2020 i40e_aqc_opc_set_vsi_promiscuous_modes);
2021
2022 cmd->promiscuous_flags = cpu_to_le16(I40E_AQC_SET_VSI_DEFAULT);
2023 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_DEFAULT);
2024 cmd->seid = cpu_to_le16(seid);
2025
2026 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2027
2028 return status;
2029}
2030
2031/**
2032 * i40e_aq_clear_default_vsi
2033 * @hw: pointer to the hw struct
2034 * @seid: vsi number
2035 * @cmd_details: pointer to command details structure or NULL
2036 **/
2037i40e_status i40e_aq_clear_default_vsi(struct i40e_hw *hw,
2038 u16 seid,
2039 struct i40e_asq_cmd_details *cmd_details)
2040{
2041 struct i40e_aq_desc desc;
2042 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2043 (struct i40e_aqc_set_vsi_promiscuous_modes *)
2044 &desc.params.raw;
2045 i40e_status status;
2046
2047 i40e_fill_default_direct_cmd_desc(&desc,
2048 i40e_aqc_opc_set_vsi_promiscuous_modes);
2049
2050 cmd->promiscuous_flags = cpu_to_le16(0);
2051 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_DEFAULT);
2052 cmd->seid = cpu_to_le16(seid);
2053
2054 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2055
2056 return status;
2057}
2058
2059/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002060 * i40e_aq_set_vsi_unicast_promiscuous
2061 * @hw: pointer to the hw struct
2062 * @seid: vsi number
2063 * @set: set unicast promiscuous enable/disable
2064 * @cmd_details: pointer to command details structure or NULL
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002065 * @rx_only_promisc: flag to decide if egress traffic gets mirrored in promisc
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002066 **/
2067i40e_status i40e_aq_set_vsi_unicast_promiscuous(struct i40e_hw *hw,
Mitch Williams885552a2013-12-21 05:44:41 +00002068 u16 seid, bool set,
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002069 struct i40e_asq_cmd_details *cmd_details,
2070 bool rx_only_promisc)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002071{
2072 struct i40e_aq_desc desc;
2073 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2074 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2075 i40e_status status;
2076 u16 flags = 0;
2077
2078 i40e_fill_default_direct_cmd_desc(&desc,
2079 i40e_aqc_opc_set_vsi_promiscuous_modes);
2080
Anjali Singhai Jain3b120082016-01-15 14:33:21 -08002081 if (set) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002082 flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002083 if (rx_only_promisc &&
2084 (((hw->aq.api_maj_ver == 1) && (hw->aq.api_min_ver >= 5)) ||
2085 (hw->aq.api_maj_ver > 1)))
Anjali Singhai Jain3b120082016-01-15 14:33:21 -08002086 flags |= I40E_AQC_SET_VSI_PROMISC_TX;
2087 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002088
2089 cmd->promiscuous_flags = cpu_to_le16(flags);
2090
2091 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
Anjali Singhai Jain3b120082016-01-15 14:33:21 -08002092 if (((hw->aq.api_maj_ver >= 1) && (hw->aq.api_min_ver >= 5)) ||
2093 (hw->aq.api_maj_ver > 1))
2094 cmd->valid_flags |= cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_TX);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002095
2096 cmd->seid = cpu_to_le16(seid);
2097 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2098
2099 return status;
2100}
2101
2102/**
2103 * i40e_aq_set_vsi_multicast_promiscuous
2104 * @hw: pointer to the hw struct
2105 * @seid: vsi number
2106 * @set: set multicast promiscuous enable/disable
2107 * @cmd_details: pointer to command details structure or NULL
2108 **/
2109i40e_status i40e_aq_set_vsi_multicast_promiscuous(struct i40e_hw *hw,
2110 u16 seid, bool set, struct i40e_asq_cmd_details *cmd_details)
2111{
2112 struct i40e_aq_desc desc;
2113 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2114 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2115 i40e_status status;
2116 u16 flags = 0;
2117
2118 i40e_fill_default_direct_cmd_desc(&desc,
2119 i40e_aqc_opc_set_vsi_promiscuous_modes);
2120
2121 if (set)
2122 flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
2123
2124 cmd->promiscuous_flags = cpu_to_le16(flags);
2125
2126 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
2127
2128 cmd->seid = cpu_to_le16(seid);
2129 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2130
2131 return status;
2132}
2133
2134/**
Greg Rose6c41a762016-04-12 08:30:50 -07002135 * i40e_aq_set_vsi_mc_promisc_on_vlan
2136 * @hw: pointer to the hw struct
2137 * @seid: vsi number
2138 * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
2139 * @vid: The VLAN tag filter - capture any multicast packet with this VLAN tag
2140 * @cmd_details: pointer to command details structure or NULL
2141 **/
2142enum i40e_status_code i40e_aq_set_vsi_mc_promisc_on_vlan(struct i40e_hw *hw,
2143 u16 seid, bool enable,
2144 u16 vid,
2145 struct i40e_asq_cmd_details *cmd_details)
2146{
2147 struct i40e_aq_desc desc;
2148 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2149 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2150 enum i40e_status_code status;
2151 u16 flags = 0;
2152
2153 i40e_fill_default_direct_cmd_desc(&desc,
2154 i40e_aqc_opc_set_vsi_promiscuous_modes);
2155
2156 if (enable)
2157 flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
2158
2159 cmd->promiscuous_flags = cpu_to_le16(flags);
2160 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
2161 cmd->seid = cpu_to_le16(seid);
2162 cmd->vlan_tag = cpu_to_le16(vid | I40E_AQC_SET_VSI_VLAN_VALID);
2163
2164 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2165
2166 return status;
2167}
2168
2169/**
2170 * i40e_aq_set_vsi_uc_promisc_on_vlan
2171 * @hw: pointer to the hw struct
2172 * @seid: vsi number
2173 * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
2174 * @vid: The VLAN tag filter - capture any unicast packet with this VLAN tag
2175 * @cmd_details: pointer to command details structure or NULL
2176 **/
2177enum i40e_status_code i40e_aq_set_vsi_uc_promisc_on_vlan(struct i40e_hw *hw,
2178 u16 seid, bool enable,
2179 u16 vid,
2180 struct i40e_asq_cmd_details *cmd_details)
2181{
2182 struct i40e_aq_desc desc;
2183 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2184 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2185 enum i40e_status_code status;
2186 u16 flags = 0;
2187
2188 i40e_fill_default_direct_cmd_desc(&desc,
2189 i40e_aqc_opc_set_vsi_promiscuous_modes);
2190
2191 if (enable)
2192 flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
2193
2194 cmd->promiscuous_flags = cpu_to_le16(flags);
2195 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
2196 cmd->seid = cpu_to_le16(seid);
2197 cmd->vlan_tag = cpu_to_le16(vid | I40E_AQC_SET_VSI_VLAN_VALID);
2198
2199 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2200
2201 return status;
2202}
2203
2204/**
Jacob Keller435c0842016-11-08 13:05:10 -08002205 * i40e_aq_set_vsi_bc_promisc_on_vlan
2206 * @hw: pointer to the hw struct
2207 * @seid: vsi number
2208 * @enable: set broadcast promiscuous enable/disable for a given VLAN
2209 * @vid: The VLAN tag filter - capture any broadcast packet with this VLAN tag
2210 * @cmd_details: pointer to command details structure or NULL
2211 **/
2212i40e_status i40e_aq_set_vsi_bc_promisc_on_vlan(struct i40e_hw *hw,
2213 u16 seid, bool enable, u16 vid,
2214 struct i40e_asq_cmd_details *cmd_details)
2215{
2216 struct i40e_aq_desc desc;
2217 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2218 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2219 i40e_status status;
2220 u16 flags = 0;
2221
2222 i40e_fill_default_direct_cmd_desc(&desc,
2223 i40e_aqc_opc_set_vsi_promiscuous_modes);
2224
2225 if (enable)
2226 flags |= I40E_AQC_SET_VSI_PROMISC_BROADCAST;
2227
2228 cmd->promiscuous_flags = cpu_to_le16(flags);
2229 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2230 cmd->seid = cpu_to_le16(seid);
2231 cmd->vlan_tag = cpu_to_le16(vid | I40E_AQC_SET_VSI_VLAN_VALID);
2232
2233 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2234
2235 return status;
2236}
2237
2238/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002239 * i40e_aq_set_vsi_broadcast
2240 * @hw: pointer to the hw struct
2241 * @seid: vsi number
2242 * @set_filter: true to set filter, false to clear filter
2243 * @cmd_details: pointer to command details structure or NULL
2244 *
2245 * Set or clear the broadcast promiscuous flag (filter) for a given VSI.
2246 **/
2247i40e_status i40e_aq_set_vsi_broadcast(struct i40e_hw *hw,
2248 u16 seid, bool set_filter,
2249 struct i40e_asq_cmd_details *cmd_details)
2250{
2251 struct i40e_aq_desc desc;
2252 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2253 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2254 i40e_status status;
2255
2256 i40e_fill_default_direct_cmd_desc(&desc,
2257 i40e_aqc_opc_set_vsi_promiscuous_modes);
2258
2259 if (set_filter)
2260 cmd->promiscuous_flags
2261 |= cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2262 else
2263 cmd->promiscuous_flags
2264 &= cpu_to_le16(~I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2265
2266 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2267 cmd->seid = cpu_to_le16(seid);
2268 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2269
2270 return status;
2271}
2272
2273/**
Kiran Patil7bd68752016-01-04 10:33:07 -08002274 * i40e_aq_set_vsi_vlan_promisc - control the VLAN promiscuous setting
2275 * @hw: pointer to the hw struct
2276 * @seid: vsi number
2277 * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
2278 * @cmd_details: pointer to command details structure or NULL
2279 **/
2280i40e_status i40e_aq_set_vsi_vlan_promisc(struct i40e_hw *hw,
2281 u16 seid, bool enable,
2282 struct i40e_asq_cmd_details *cmd_details)
2283{
2284 struct i40e_aq_desc desc;
2285 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2286 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2287 i40e_status status;
2288 u16 flags = 0;
2289
2290 i40e_fill_default_direct_cmd_desc(&desc,
2291 i40e_aqc_opc_set_vsi_promiscuous_modes);
2292 if (enable)
2293 flags |= I40E_AQC_SET_VSI_PROMISC_VLAN;
2294
2295 cmd->promiscuous_flags = cpu_to_le16(flags);
2296 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_VLAN);
2297 cmd->seid = cpu_to_le16(seid);
2298
2299 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2300
2301 return status;
2302}
2303
2304/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002305 * i40e_get_vsi_params - get VSI configuration info
2306 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00002307 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002308 * @cmd_details: pointer to command details structure or NULL
2309 **/
2310i40e_status i40e_aq_get_vsi_params(struct i40e_hw *hw,
2311 struct i40e_vsi_context *vsi_ctx,
2312 struct i40e_asq_cmd_details *cmd_details)
2313{
2314 struct i40e_aq_desc desc;
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002315 struct i40e_aqc_add_get_update_vsi *cmd =
2316 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002317 struct i40e_aqc_add_get_update_vsi_completion *resp =
2318 (struct i40e_aqc_add_get_update_vsi_completion *)
2319 &desc.params.raw;
2320 i40e_status status;
2321
2322 i40e_fill_default_direct_cmd_desc(&desc,
2323 i40e_aqc_opc_get_vsi_parameters);
2324
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002325 cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002326
2327 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002328
2329 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
2330 sizeof(vsi_ctx->info), NULL);
2331
2332 if (status)
2333 goto aq_get_vsi_params_exit;
2334
2335 vsi_ctx->seid = le16_to_cpu(resp->seid);
2336 vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
2337 vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
2338 vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
2339
2340aq_get_vsi_params_exit:
2341 return status;
2342}
2343
2344/**
2345 * i40e_aq_update_vsi_params
2346 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00002347 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002348 * @cmd_details: pointer to command details structure or NULL
2349 *
2350 * Update a VSI context.
2351 **/
2352i40e_status i40e_aq_update_vsi_params(struct i40e_hw *hw,
2353 struct i40e_vsi_context *vsi_ctx,
2354 struct i40e_asq_cmd_details *cmd_details)
2355{
2356 struct i40e_aq_desc desc;
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002357 struct i40e_aqc_add_get_update_vsi *cmd =
2358 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
Kevin Scottb6cacca2016-03-10 14:59:41 -08002359 struct i40e_aqc_add_get_update_vsi_completion *resp =
2360 (struct i40e_aqc_add_get_update_vsi_completion *)
2361 &desc.params.raw;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002362 i40e_status status;
2363
2364 i40e_fill_default_direct_cmd_desc(&desc,
2365 i40e_aqc_opc_update_vsi_parameters);
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002366 cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002367
2368 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002369
2370 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
2371 sizeof(vsi_ctx->info), cmd_details);
2372
Kevin Scottb6cacca2016-03-10 14:59:41 -08002373 vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
2374 vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
2375
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002376 return status;
2377}
2378
2379/**
2380 * i40e_aq_get_switch_config
2381 * @hw: pointer to the hardware structure
2382 * @buf: pointer to the result buffer
2383 * @buf_size: length of input buffer
2384 * @start_seid: seid to start for the report, 0 == beginning
2385 * @cmd_details: pointer to command details structure or NULL
2386 *
2387 * Fill the buf with switch configuration returned from AdminQ command
2388 **/
2389i40e_status i40e_aq_get_switch_config(struct i40e_hw *hw,
2390 struct i40e_aqc_get_switch_config_resp *buf,
2391 u16 buf_size, u16 *start_seid,
2392 struct i40e_asq_cmd_details *cmd_details)
2393{
2394 struct i40e_aq_desc desc;
2395 struct i40e_aqc_switch_seid *scfg =
2396 (struct i40e_aqc_switch_seid *)&desc.params.raw;
2397 i40e_status status;
2398
2399 i40e_fill_default_direct_cmd_desc(&desc,
2400 i40e_aqc_opc_get_switch_config);
2401 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
2402 if (buf_size > I40E_AQ_LARGE_BUF)
2403 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2404 scfg->seid = cpu_to_le16(*start_seid);
2405
2406 status = i40e_asq_send_command(hw, &desc, buf, buf_size, cmd_details);
2407 *start_seid = le16_to_cpu(scfg->seid);
2408
2409 return status;
2410}
2411
2412/**
Shannon Nelsonf3d58492016-05-03 15:13:11 -07002413 * i40e_aq_set_switch_config
2414 * @hw: pointer to the hardware structure
2415 * @flags: bit flag values to set
2416 * @valid_flags: which bit flags to set
Amritha Nambiar5efe0c62017-10-27 02:35:45 -07002417 * @mode: cloud filter mode
Shannon Nelsonf3d58492016-05-03 15:13:11 -07002418 * @cmd_details: pointer to command details structure or NULL
2419 *
2420 * Set switch configuration bits
2421 **/
2422enum i40e_status_code i40e_aq_set_switch_config(struct i40e_hw *hw,
2423 u16 flags,
Amritha Nambiar5efe0c62017-10-27 02:35:45 -07002424 u16 valid_flags, u8 mode,
Shannon Nelsonf3d58492016-05-03 15:13:11 -07002425 struct i40e_asq_cmd_details *cmd_details)
2426{
2427 struct i40e_aq_desc desc;
2428 struct i40e_aqc_set_switch_config *scfg =
2429 (struct i40e_aqc_set_switch_config *)&desc.params.raw;
2430 enum i40e_status_code status;
2431
2432 i40e_fill_default_direct_cmd_desc(&desc,
2433 i40e_aqc_opc_set_switch_config);
2434 scfg->flags = cpu_to_le16(flags);
2435 scfg->valid_flags = cpu_to_le16(valid_flags);
Amritha Nambiar5efe0c62017-10-27 02:35:45 -07002436 scfg->mode = mode;
Scott Petersonab243ec2017-08-22 06:57:54 -04002437 if (hw->flags & I40E_HW_FLAG_802_1AD_CAPABLE) {
2438 scfg->switch_tag = cpu_to_le16(hw->switch_tag);
2439 scfg->first_tag = cpu_to_le16(hw->first_tag);
2440 scfg->second_tag = cpu_to_le16(hw->second_tag);
2441 }
Shannon Nelsonf3d58492016-05-03 15:13:11 -07002442 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2443
2444 return status;
2445}
2446
2447/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002448 * i40e_aq_get_firmware_version
2449 * @hw: pointer to the hw struct
2450 * @fw_major_version: firmware major version
2451 * @fw_minor_version: firmware minor version
Shannon Nelson7edf8102015-02-24 06:58:41 +00002452 * @fw_build: firmware build number
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002453 * @api_major_version: major queue version
2454 * @api_minor_version: minor queue version
2455 * @cmd_details: pointer to command details structure or NULL
2456 *
2457 * Get the firmware version from the admin queue commands
2458 **/
2459i40e_status i40e_aq_get_firmware_version(struct i40e_hw *hw,
2460 u16 *fw_major_version, u16 *fw_minor_version,
Shannon Nelson7edf8102015-02-24 06:58:41 +00002461 u32 *fw_build,
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002462 u16 *api_major_version, u16 *api_minor_version,
2463 struct i40e_asq_cmd_details *cmd_details)
2464{
2465 struct i40e_aq_desc desc;
2466 struct i40e_aqc_get_version *resp =
2467 (struct i40e_aqc_get_version *)&desc.params.raw;
2468 i40e_status status;
2469
2470 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_version);
2471
2472 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2473
2474 if (!status) {
Shannon Nelson7edf8102015-02-24 06:58:41 +00002475 if (fw_major_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002476 *fw_major_version = le16_to_cpu(resp->fw_major);
Shannon Nelson7edf8102015-02-24 06:58:41 +00002477 if (fw_minor_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002478 *fw_minor_version = le16_to_cpu(resp->fw_minor);
Shannon Nelson7edf8102015-02-24 06:58:41 +00002479 if (fw_build)
2480 *fw_build = le32_to_cpu(resp->fw_build);
2481 if (api_major_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002482 *api_major_version = le16_to_cpu(resp->api_major);
Shannon Nelson7edf8102015-02-24 06:58:41 +00002483 if (api_minor_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002484 *api_minor_version = le16_to_cpu(resp->api_minor);
2485 }
2486
2487 return status;
2488}
2489
2490/**
2491 * i40e_aq_send_driver_version
2492 * @hw: pointer to the hw struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002493 * @dv: driver's major, minor version
2494 * @cmd_details: pointer to command details structure or NULL
2495 *
2496 * Send the driver version to the firmware
2497 **/
2498i40e_status i40e_aq_send_driver_version(struct i40e_hw *hw,
2499 struct i40e_driver_version *dv,
2500 struct i40e_asq_cmd_details *cmd_details)
2501{
2502 struct i40e_aq_desc desc;
2503 struct i40e_aqc_driver_version *cmd =
2504 (struct i40e_aqc_driver_version *)&desc.params.raw;
2505 i40e_status status;
Kevin Scott9d2f98e2014-04-01 07:11:52 +00002506 u16 len;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002507
2508 if (dv == NULL)
2509 return I40E_ERR_PARAM;
2510
2511 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_driver_version);
2512
Kevin Scott3b38cd12015-02-06 08:52:18 +00002513 desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002514 cmd->driver_major_ver = dv->major_version;
2515 cmd->driver_minor_ver = dv->minor_version;
2516 cmd->driver_build_ver = dv->build_version;
2517 cmd->driver_subbuild_ver = dv->subbuild_version;
Shannon Nelsond2466012014-04-01 07:11:45 +00002518
2519 len = 0;
2520 while (len < sizeof(dv->driver_string) &&
2521 (dv->driver_string[len] < 0x80) &&
2522 dv->driver_string[len])
2523 len++;
2524 status = i40e_asq_send_command(hw, &desc, dv->driver_string,
2525 len, cmd_details);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002526
2527 return status;
2528}
2529
2530/**
2531 * i40e_get_link_status - get status of the HW network link
2532 * @hw: pointer to the hw struct
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002533 * @link_up: pointer to bool (true/false = linkup/linkdown)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002534 *
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002535 * Variable link_up true if link is up, false if link is down.
2536 * The variable link_up is invalid if returned value of status != 0
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002537 *
2538 * Side effect: LinkStatusEvent reporting becomes enabled
2539 **/
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002540i40e_status i40e_get_link_status(struct i40e_hw *hw, bool *link_up)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002541{
2542 i40e_status status = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002543
2544 if (hw->phy.get_link_info) {
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002545 status = i40e_update_link_info(hw);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002546
2547 if (status)
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002548 i40e_debug(hw, I40E_DEBUG_LINK, "get link failed: status %d\n",
2549 status);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002550 }
2551
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002552 *link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002553
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002554 return status;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002555}
2556
2557/**
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002558 * i40e_updatelink_status - update status of the HW network link
2559 * @hw: pointer to the hw struct
2560 **/
2561i40e_status i40e_update_link_info(struct i40e_hw *hw)
2562{
2563 struct i40e_aq_get_phy_abilities_resp abilities;
2564 i40e_status status = 0;
2565
2566 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
2567 if (status)
2568 return status;
2569
Carolyn Wybornyab425cb2016-09-27 11:28:52 -07002570 /* extra checking needed to ensure link info to user is timely */
2571 if ((hw->phy.link_info.link_info & I40E_AQ_MEDIA_AVAILABLE) &&
2572 ((hw->phy.link_info.link_info & I40E_AQ_LINK_UP) ||
2573 !(hw->phy.link_info_old.link_info & I40E_AQ_LINK_UP))) {
Carolyn Wyborny8589af72015-09-28 14:16:56 -04002574 status = i40e_aq_get_phy_capabilities(hw, false, false,
2575 &abilities, NULL);
2576 if (status)
2577 return status;
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002578
Mariusz Stachuraed601f62017-07-12 05:46:08 -04002579 hw->phy.link_info.req_fec_info =
2580 abilities.fec_cfg_curr_mod_ext_info &
2581 (I40E_AQ_REQUEST_FEC_KR | I40E_AQ_REQUEST_FEC_RS);
2582
Carolyn Wyborny8589af72015-09-28 14:16:56 -04002583 memcpy(hw->phy.link_info.module_type, &abilities.module_type,
2584 sizeof(hw->phy.link_info.module_type));
2585 }
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002586
2587 return status;
2588}
2589
2590/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002591 * i40e_aq_add_veb - Insert a VEB between the VSI and the MAC
2592 * @hw: pointer to the hw struct
2593 * @uplink_seid: the MAC or other gizmo SEID
2594 * @downlink_seid: the VSI SEID
2595 * @enabled_tc: bitmap of TCs to be enabled
2596 * @default_port: true for default port VSI, false for control port
2597 * @veb_seid: pointer to where to put the resulting VEB SEID
Shannon Nelson8a187f42016-01-13 16:51:41 -08002598 * @enable_stats: true to turn on VEB stats
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002599 * @cmd_details: pointer to command details structure or NULL
2600 *
2601 * This asks the FW to add a VEB between the uplink and downlink
2602 * elements. If the uplink SEID is 0, this will be a floating VEB.
2603 **/
2604i40e_status i40e_aq_add_veb(struct i40e_hw *hw, u16 uplink_seid,
2605 u16 downlink_seid, u8 enabled_tc,
Shannon Nelson8a187f42016-01-13 16:51:41 -08002606 bool default_port, u16 *veb_seid,
2607 bool enable_stats,
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002608 struct i40e_asq_cmd_details *cmd_details)
2609{
2610 struct i40e_aq_desc desc;
2611 struct i40e_aqc_add_veb *cmd =
2612 (struct i40e_aqc_add_veb *)&desc.params.raw;
2613 struct i40e_aqc_add_veb_completion *resp =
2614 (struct i40e_aqc_add_veb_completion *)&desc.params.raw;
2615 i40e_status status;
2616 u16 veb_flags = 0;
2617
2618 /* SEIDs need to either both be set or both be 0 for floating VEB */
2619 if (!!uplink_seid != !!downlink_seid)
2620 return I40E_ERR_PARAM;
2621
2622 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_veb);
2623
2624 cmd->uplink_seid = cpu_to_le16(uplink_seid);
2625 cmd->downlink_seid = cpu_to_le16(downlink_seid);
2626 cmd->enable_tcs = enabled_tc;
2627 if (!uplink_seid)
2628 veb_flags |= I40E_AQC_ADD_VEB_FLOATING;
2629 if (default_port)
2630 veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DEFAULT;
2631 else
2632 veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DATA;
Kevin Scotte1c51b952013-11-20 10:02:51 +00002633
Shannon Nelson8a187f42016-01-13 16:51:41 -08002634 /* reverse logic here: set the bitflag to disable the stats */
2635 if (!enable_stats)
2636 veb_flags |= I40E_AQC_ADD_VEB_ENABLE_DISABLE_STATS;
Kevin Scotte1c51b952013-11-20 10:02:51 +00002637
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002638 cmd->veb_flags = cpu_to_le16(veb_flags);
2639
2640 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2641
2642 if (!status && veb_seid)
2643 *veb_seid = le16_to_cpu(resp->veb_seid);
2644
2645 return status;
2646}
2647
2648/**
2649 * i40e_aq_get_veb_parameters - Retrieve VEB parameters
2650 * @hw: pointer to the hw struct
2651 * @veb_seid: the SEID of the VEB to query
2652 * @switch_id: the uplink switch id
Jeff Kirsher98d44382013-12-21 05:44:42 +00002653 * @floating: set to true if the VEB is floating
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002654 * @statistic_index: index of the stats counter block for this VEB
2655 * @vebs_used: number of VEB's used by function
Jeff Kirsher98d44382013-12-21 05:44:42 +00002656 * @vebs_free: total VEB's not reserved by any function
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002657 * @cmd_details: pointer to command details structure or NULL
2658 *
2659 * This retrieves the parameters for a particular VEB, specified by
2660 * uplink_seid, and returns them to the caller.
2661 **/
2662i40e_status i40e_aq_get_veb_parameters(struct i40e_hw *hw,
2663 u16 veb_seid, u16 *switch_id,
2664 bool *floating, u16 *statistic_index,
2665 u16 *vebs_used, u16 *vebs_free,
2666 struct i40e_asq_cmd_details *cmd_details)
2667{
2668 struct i40e_aq_desc desc;
2669 struct i40e_aqc_get_veb_parameters_completion *cmd_resp =
2670 (struct i40e_aqc_get_veb_parameters_completion *)
2671 &desc.params.raw;
2672 i40e_status status;
2673
2674 if (veb_seid == 0)
2675 return I40E_ERR_PARAM;
2676
2677 i40e_fill_default_direct_cmd_desc(&desc,
2678 i40e_aqc_opc_get_veb_parameters);
2679 cmd_resp->seid = cpu_to_le16(veb_seid);
2680
2681 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2682 if (status)
2683 goto get_veb_exit;
2684
2685 if (switch_id)
2686 *switch_id = le16_to_cpu(cmd_resp->switch_id);
2687 if (statistic_index)
2688 *statistic_index = le16_to_cpu(cmd_resp->statistic_index);
2689 if (vebs_used)
2690 *vebs_used = le16_to_cpu(cmd_resp->vebs_used);
2691 if (vebs_free)
2692 *vebs_free = le16_to_cpu(cmd_resp->vebs_free);
2693 if (floating) {
2694 u16 flags = le16_to_cpu(cmd_resp->veb_flags);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04002695
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002696 if (flags & I40E_AQC_ADD_VEB_FLOATING)
2697 *floating = true;
2698 else
2699 *floating = false;
2700 }
2701
2702get_veb_exit:
2703 return status;
2704}
2705
2706/**
2707 * i40e_aq_add_macvlan
2708 * @hw: pointer to the hw struct
2709 * @seid: VSI for the mac address
2710 * @mv_list: list of macvlans to be added
2711 * @count: length of the list
2712 * @cmd_details: pointer to command details structure or NULL
2713 *
2714 * Add MAC/VLAN addresses to the HW filtering
2715 **/
2716i40e_status i40e_aq_add_macvlan(struct i40e_hw *hw, u16 seid,
2717 struct i40e_aqc_add_macvlan_element_data *mv_list,
2718 u16 count, struct i40e_asq_cmd_details *cmd_details)
2719{
2720 struct i40e_aq_desc desc;
2721 struct i40e_aqc_macvlan *cmd =
2722 (struct i40e_aqc_macvlan *)&desc.params.raw;
2723 i40e_status status;
2724 u16 buf_size;
Shannon Nelson67be6eb2016-01-13 16:51:40 -08002725 int i;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002726
2727 if (count == 0 || !mv_list || !hw)
2728 return I40E_ERR_PARAM;
2729
Shannon Nelson1efc80e2015-02-27 09:18:30 +00002730 buf_size = count * sizeof(*mv_list);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002731
2732 /* prep the rest of the request */
2733 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_macvlan);
2734 cmd->num_addresses = cpu_to_le16(count);
2735 cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
2736 cmd->seid[1] = 0;
2737 cmd->seid[2] = 0;
2738
Shannon Nelson67be6eb2016-01-13 16:51:40 -08002739 for (i = 0; i < count; i++)
2740 if (is_multicast_ether_addr(mv_list[i].mac_addr))
2741 mv_list[i].flags |=
2742 cpu_to_le16(I40E_AQC_MACVLAN_ADD_USE_SHARED_MAC);
2743
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002744 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
2745 if (buf_size > I40E_AQ_LARGE_BUF)
2746 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2747
2748 status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
Shannon Nelson67be6eb2016-01-13 16:51:40 -08002749 cmd_details);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002750
2751 return status;
2752}
2753
2754/**
2755 * i40e_aq_remove_macvlan
2756 * @hw: pointer to the hw struct
2757 * @seid: VSI for the mac address
2758 * @mv_list: list of macvlans to be removed
2759 * @count: length of the list
2760 * @cmd_details: pointer to command details structure or NULL
2761 *
2762 * Remove MAC/VLAN addresses from the HW filtering
2763 **/
2764i40e_status i40e_aq_remove_macvlan(struct i40e_hw *hw, u16 seid,
2765 struct i40e_aqc_remove_macvlan_element_data *mv_list,
2766 u16 count, struct i40e_asq_cmd_details *cmd_details)
2767{
2768 struct i40e_aq_desc desc;
2769 struct i40e_aqc_macvlan *cmd =
2770 (struct i40e_aqc_macvlan *)&desc.params.raw;
2771 i40e_status status;
2772 u16 buf_size;
2773
2774 if (count == 0 || !mv_list || !hw)
2775 return I40E_ERR_PARAM;
2776
Shannon Nelson1efc80e2015-02-27 09:18:30 +00002777 buf_size = count * sizeof(*mv_list);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002778
2779 /* prep the rest of the request */
2780 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_macvlan);
2781 cmd->num_addresses = cpu_to_le16(count);
2782 cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
2783 cmd->seid[1] = 0;
2784 cmd->seid[2] = 0;
2785
2786 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
2787 if (buf_size > I40E_AQ_LARGE_BUF)
2788 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2789
2790 status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
2791 cmd_details);
2792
2793 return status;
2794}
2795
2796/**
Kiran Patil7bd68752016-01-04 10:33:07 -08002797 * i40e_mirrorrule_op - Internal helper function to add/delete mirror rule
2798 * @hw: pointer to the hw struct
2799 * @opcode: AQ opcode for add or delete mirror rule
2800 * @sw_seid: Switch SEID (to which rule refers)
2801 * @rule_type: Rule Type (ingress/egress/VLAN)
2802 * @id: Destination VSI SEID or Rule ID
2803 * @count: length of the list
2804 * @mr_list: list of mirrored VSI SEIDs or VLAN IDs
2805 * @cmd_details: pointer to command details structure or NULL
2806 * @rule_id: Rule ID returned from FW
2807 * @rule_used: Number of rules used in internal switch
2808 * @rule_free: Number of rules free in internal switch
2809 *
2810 * Add/Delete a mirror rule to a specific switch. Mirror rules are supported for
2811 * VEBs/VEPA elements only
2812 **/
2813static i40e_status i40e_mirrorrule_op(struct i40e_hw *hw,
2814 u16 opcode, u16 sw_seid, u16 rule_type, u16 id,
2815 u16 count, __le16 *mr_list,
2816 struct i40e_asq_cmd_details *cmd_details,
2817 u16 *rule_id, u16 *rules_used, u16 *rules_free)
2818{
2819 struct i40e_aq_desc desc;
2820 struct i40e_aqc_add_delete_mirror_rule *cmd =
2821 (struct i40e_aqc_add_delete_mirror_rule *)&desc.params.raw;
2822 struct i40e_aqc_add_delete_mirror_rule_completion *resp =
2823 (struct i40e_aqc_add_delete_mirror_rule_completion *)&desc.params.raw;
2824 i40e_status status;
2825 u16 buf_size;
2826
2827 buf_size = count * sizeof(*mr_list);
2828
2829 /* prep the rest of the request */
2830 i40e_fill_default_direct_cmd_desc(&desc, opcode);
2831 cmd->seid = cpu_to_le16(sw_seid);
2832 cmd->rule_type = cpu_to_le16(rule_type &
2833 I40E_AQC_MIRROR_RULE_TYPE_MASK);
2834 cmd->num_entries = cpu_to_le16(count);
2835 /* Dest VSI for add, rule_id for delete */
2836 cmd->destination = cpu_to_le16(id);
2837 if (mr_list) {
2838 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
2839 I40E_AQ_FLAG_RD));
2840 if (buf_size > I40E_AQ_LARGE_BUF)
2841 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2842 }
2843
2844 status = i40e_asq_send_command(hw, &desc, mr_list, buf_size,
2845 cmd_details);
2846 if (!status ||
2847 hw->aq.asq_last_status == I40E_AQ_RC_ENOSPC) {
2848 if (rule_id)
2849 *rule_id = le16_to_cpu(resp->rule_id);
2850 if (rules_used)
2851 *rules_used = le16_to_cpu(resp->mirror_rules_used);
2852 if (rules_free)
2853 *rules_free = le16_to_cpu(resp->mirror_rules_free);
2854 }
2855 return status;
2856}
2857
2858/**
2859 * i40e_aq_add_mirrorrule - add a mirror rule
2860 * @hw: pointer to the hw struct
2861 * @sw_seid: Switch SEID (to which rule refers)
2862 * @rule_type: Rule Type (ingress/egress/VLAN)
2863 * @dest_vsi: SEID of VSI to which packets will be mirrored
2864 * @count: length of the list
2865 * @mr_list: list of mirrored VSI SEIDs or VLAN IDs
2866 * @cmd_details: pointer to command details structure or NULL
2867 * @rule_id: Rule ID returned from FW
2868 * @rule_used: Number of rules used in internal switch
2869 * @rule_free: Number of rules free in internal switch
2870 *
2871 * Add mirror rule. Mirror rules are supported for VEBs or VEPA elements only
2872 **/
2873i40e_status i40e_aq_add_mirrorrule(struct i40e_hw *hw, u16 sw_seid,
2874 u16 rule_type, u16 dest_vsi, u16 count, __le16 *mr_list,
2875 struct i40e_asq_cmd_details *cmd_details,
2876 u16 *rule_id, u16 *rules_used, u16 *rules_free)
2877{
2878 if (!(rule_type == I40E_AQC_MIRROR_RULE_TYPE_ALL_INGRESS ||
2879 rule_type == I40E_AQC_MIRROR_RULE_TYPE_ALL_EGRESS)) {
2880 if (count == 0 || !mr_list)
2881 return I40E_ERR_PARAM;
2882 }
2883
2884 return i40e_mirrorrule_op(hw, i40e_aqc_opc_add_mirror_rule, sw_seid,
2885 rule_type, dest_vsi, count, mr_list,
2886 cmd_details, rule_id, rules_used, rules_free);
2887}
2888
2889/**
2890 * i40e_aq_delete_mirrorrule - delete a mirror rule
2891 * @hw: pointer to the hw struct
2892 * @sw_seid: Switch SEID (to which rule refers)
2893 * @rule_type: Rule Type (ingress/egress/VLAN)
2894 * @count: length of the list
2895 * @rule_id: Rule ID that is returned in the receive desc as part of
2896 * add_mirrorrule.
2897 * @mr_list: list of mirrored VLAN IDs to be removed
2898 * @cmd_details: pointer to command details structure or NULL
2899 * @rule_used: Number of rules used in internal switch
2900 * @rule_free: Number of rules free in internal switch
2901 *
2902 * Delete a mirror rule. Mirror rules are supported for VEBs/VEPA elements only
2903 **/
2904i40e_status i40e_aq_delete_mirrorrule(struct i40e_hw *hw, u16 sw_seid,
2905 u16 rule_type, u16 rule_id, u16 count, __le16 *mr_list,
2906 struct i40e_asq_cmd_details *cmd_details,
2907 u16 *rules_used, u16 *rules_free)
2908{
2909 /* Rule ID has to be valid except rule_type: INGRESS VLAN mirroring */
Greg Rosedb077272016-04-12 08:30:48 -07002910 if (rule_type == I40E_AQC_MIRROR_RULE_TYPE_VLAN) {
Kiran Patil7bd68752016-01-04 10:33:07 -08002911 /* count and mr_list shall be valid for rule_type INGRESS VLAN
2912 * mirroring. For other rule_type, count and rule_type should
2913 * not matter.
2914 */
2915 if (count == 0 || !mr_list)
2916 return I40E_ERR_PARAM;
2917 }
2918
2919 return i40e_mirrorrule_op(hw, i40e_aqc_opc_delete_mirror_rule, sw_seid,
2920 rule_type, rule_id, count, mr_list,
2921 cmd_details, NULL, rules_used, rules_free);
2922}
2923
2924/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002925 * i40e_aq_send_msg_to_vf
2926 * @hw: pointer to the hardware structure
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00002927 * @vfid: VF id to send msg
Jeff Kirsher98d44382013-12-21 05:44:42 +00002928 * @v_opcode: opcodes for VF-PF communication
2929 * @v_retval: return error code
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002930 * @msg: pointer to the msg buffer
2931 * @msglen: msg length
2932 * @cmd_details: pointer to command details
2933 *
2934 * send msg to vf
2935 **/
2936i40e_status i40e_aq_send_msg_to_vf(struct i40e_hw *hw, u16 vfid,
2937 u32 v_opcode, u32 v_retval, u8 *msg, u16 msglen,
2938 struct i40e_asq_cmd_details *cmd_details)
2939{
2940 struct i40e_aq_desc desc;
2941 struct i40e_aqc_pf_vf_message *cmd =
2942 (struct i40e_aqc_pf_vf_message *)&desc.params.raw;
2943 i40e_status status;
2944
2945 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_vf);
2946 cmd->id = cpu_to_le32(vfid);
2947 desc.cookie_high = cpu_to_le32(v_opcode);
2948 desc.cookie_low = cpu_to_le32(v_retval);
2949 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_SI);
2950 if (msglen) {
2951 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
2952 I40E_AQ_FLAG_RD));
2953 if (msglen > I40E_AQ_LARGE_BUF)
2954 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2955 desc.datalen = cpu_to_le16(msglen);
2956 }
2957 status = i40e_asq_send_command(hw, &desc, msg, msglen, cmd_details);
2958
2959 return status;
2960}
2961
2962/**
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002963 * i40e_aq_debug_read_register
2964 * @hw: pointer to the hw struct
2965 * @reg_addr: register address
2966 * @reg_val: register value
2967 * @cmd_details: pointer to command details structure or NULL
2968 *
2969 * Read the register using the admin queue commands
2970 **/
2971i40e_status i40e_aq_debug_read_register(struct i40e_hw *hw,
Jesse Brandeburg7b115dd2015-02-27 09:15:23 +00002972 u32 reg_addr, u64 *reg_val,
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002973 struct i40e_asq_cmd_details *cmd_details)
2974{
2975 struct i40e_aq_desc desc;
2976 struct i40e_aqc_debug_reg_read_write *cmd_resp =
2977 (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
2978 i40e_status status;
2979
2980 if (reg_val == NULL)
2981 return I40E_ERR_PARAM;
2982
Jesse Brandeburg7b115dd2015-02-27 09:15:23 +00002983 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_read_reg);
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002984
2985 cmd_resp->address = cpu_to_le32(reg_addr);
2986
2987 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2988
2989 if (!status) {
Jesse Brandeburg7b115dd2015-02-27 09:15:23 +00002990 *reg_val = ((u64)le32_to_cpu(cmd_resp->value_high) << 32) |
2991 (u64)le32_to_cpu(cmd_resp->value_low);
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002992 }
2993
2994 return status;
2995}
2996
2997/**
Shannon Nelson53db45c2014-08-01 13:27:05 -07002998 * i40e_aq_debug_write_register
2999 * @hw: pointer to the hw struct
3000 * @reg_addr: register address
3001 * @reg_val: register value
3002 * @cmd_details: pointer to command details structure or NULL
3003 *
3004 * Write to a register using the admin queue commands
3005 **/
3006i40e_status i40e_aq_debug_write_register(struct i40e_hw *hw,
3007 u32 reg_addr, u64 reg_val,
3008 struct i40e_asq_cmd_details *cmd_details)
3009{
3010 struct i40e_aq_desc desc;
3011 struct i40e_aqc_debug_reg_read_write *cmd =
3012 (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
3013 i40e_status status;
3014
3015 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_write_reg);
3016
3017 cmd->address = cpu_to_le32(reg_addr);
3018 cmd->value_high = cpu_to_le32((u32)(reg_val >> 32));
3019 cmd->value_low = cpu_to_le32((u32)(reg_val & 0xFFFFFFFF));
3020
3021 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3022
3023 return status;
3024}
3025
3026/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003027 * i40e_aq_request_resource
3028 * @hw: pointer to the hw struct
3029 * @resource: resource id
3030 * @access: access type
3031 * @sdp_number: resource number
3032 * @timeout: the maximum time in ms that the driver may hold the resource
3033 * @cmd_details: pointer to command details structure or NULL
3034 *
3035 * requests common resource using the admin queue commands
3036 **/
3037i40e_status i40e_aq_request_resource(struct i40e_hw *hw,
3038 enum i40e_aq_resources_ids resource,
3039 enum i40e_aq_resource_access_type access,
3040 u8 sdp_number, u64 *timeout,
3041 struct i40e_asq_cmd_details *cmd_details)
3042{
3043 struct i40e_aq_desc desc;
3044 struct i40e_aqc_request_resource *cmd_resp =
3045 (struct i40e_aqc_request_resource *)&desc.params.raw;
3046 i40e_status status;
3047
3048 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_request_resource);
3049
3050 cmd_resp->resource_id = cpu_to_le16(resource);
3051 cmd_resp->access_type = cpu_to_le16(access);
3052 cmd_resp->resource_number = cpu_to_le32(sdp_number);
3053
3054 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3055 /* The completion specifies the maximum time in ms that the driver
3056 * may hold the resource in the Timeout field.
3057 * If the resource is held by someone else, the command completes with
3058 * busy return value and the timeout field indicates the maximum time
3059 * the current owner of the resource has to free it.
3060 */
3061 if (!status || hw->aq.asq_last_status == I40E_AQ_RC_EBUSY)
3062 *timeout = le32_to_cpu(cmd_resp->timeout);
3063
3064 return status;
3065}
3066
3067/**
3068 * i40e_aq_release_resource
3069 * @hw: pointer to the hw struct
3070 * @resource: resource id
3071 * @sdp_number: resource number
3072 * @cmd_details: pointer to command details structure or NULL
3073 *
3074 * release common resource using the admin queue commands
3075 **/
3076i40e_status i40e_aq_release_resource(struct i40e_hw *hw,
3077 enum i40e_aq_resources_ids resource,
3078 u8 sdp_number,
3079 struct i40e_asq_cmd_details *cmd_details)
3080{
3081 struct i40e_aq_desc desc;
3082 struct i40e_aqc_request_resource *cmd =
3083 (struct i40e_aqc_request_resource *)&desc.params.raw;
3084 i40e_status status;
3085
3086 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_release_resource);
3087
3088 cmd->resource_id = cpu_to_le16(resource);
3089 cmd->resource_number = cpu_to_le32(sdp_number);
3090
3091 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3092
3093 return status;
3094}
3095
3096/**
3097 * i40e_aq_read_nvm
3098 * @hw: pointer to the hw struct
3099 * @module_pointer: module pointer location in words from the NVM beginning
3100 * @offset: byte offset from the module beginning
3101 * @length: length of the section to be read (in bytes from the offset)
3102 * @data: command buffer (size [bytes] = length)
3103 * @last_command: tells if this is the last command in a series
3104 * @cmd_details: pointer to command details structure or NULL
3105 *
3106 * Read the NVM using the admin queue commands
3107 **/
3108i40e_status i40e_aq_read_nvm(struct i40e_hw *hw, u8 module_pointer,
3109 u32 offset, u16 length, void *data,
3110 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_read_nvm_exit;
3122 }
3123
3124 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_read);
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 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3134 if (length > I40E_AQ_LARGE_BUF)
3135 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3136
3137 status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
3138
3139i40e_aq_read_nvm_exit:
3140 return status;
3141}
3142
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003143/**
3144 * i40e_aq_erase_nvm
3145 * @hw: pointer to the hw struct
3146 * @module_pointer: module pointer location in words from the NVM beginning
3147 * @offset: offset in the module (expressed in 4 KB from module's beginning)
3148 * @length: length of the section to be erased (expressed in 4 KB)
3149 * @last_command: tells if this is the last command in a series
3150 * @cmd_details: pointer to command details structure or NULL
3151 *
3152 * Erase the NVM sector using the admin queue commands
3153 **/
3154i40e_status i40e_aq_erase_nvm(struct i40e_hw *hw, u8 module_pointer,
3155 u32 offset, u16 length, bool last_command,
3156 struct i40e_asq_cmd_details *cmd_details)
3157{
3158 struct i40e_aq_desc desc;
3159 struct i40e_aqc_nvm_update *cmd =
3160 (struct i40e_aqc_nvm_update *)&desc.params.raw;
3161 i40e_status status;
3162
3163 /* In offset the highest byte must be zeroed. */
3164 if (offset & 0xFF000000) {
3165 status = I40E_ERR_PARAM;
3166 goto i40e_aq_erase_nvm_exit;
3167 }
3168
3169 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_erase);
3170
3171 /* If this is the last command in a series, set the proper flag. */
3172 if (last_command)
3173 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
3174 cmd->module_pointer = module_pointer;
3175 cmd->offset = cpu_to_le32(offset);
3176 cmd->length = cpu_to_le16(length);
3177
3178 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3179
3180i40e_aq_erase_nvm_exit:
3181 return status;
3182}
3183
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003184/**
3185 * i40e_parse_discover_capabilities
3186 * @hw: pointer to the hw struct
3187 * @buff: pointer to a buffer containing device/function capability records
3188 * @cap_count: number of capability records in the list
3189 * @list_type_opc: type of capabilities list to parse
3190 *
3191 * Parse the device/function capabilities list.
3192 **/
3193static void i40e_parse_discover_capabilities(struct i40e_hw *hw, void *buff,
3194 u32 cap_count,
3195 enum i40e_admin_queue_opc list_type_opc)
3196{
3197 struct i40e_aqc_list_capabilities_element_resp *cap;
Shannon Nelson9fee9db2014-12-11 07:06:30 +00003198 u32 valid_functions, num_functions;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003199 u32 number, logical_id, phys_id;
3200 struct i40e_hw_capabilities *p;
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003201 u8 major_rev;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003202 u32 i = 0;
3203 u16 id;
3204
3205 cap = (struct i40e_aqc_list_capabilities_element_resp *) buff;
3206
3207 if (list_type_opc == i40e_aqc_opc_list_dev_capabilities)
Joe Perchesb58f2f72014-03-25 04:30:32 +00003208 p = &hw->dev_caps;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003209 else if (list_type_opc == i40e_aqc_opc_list_func_capabilities)
Joe Perchesb58f2f72014-03-25 04:30:32 +00003210 p = &hw->func_caps;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003211 else
3212 return;
3213
3214 for (i = 0; i < cap_count; i++, cap++) {
3215 id = le16_to_cpu(cap->id);
3216 number = le32_to_cpu(cap->number);
3217 logical_id = le32_to_cpu(cap->logical_id);
3218 phys_id = le32_to_cpu(cap->phys_id);
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003219 major_rev = cap->major_rev;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003220
3221 switch (id) {
Shannon Nelson406e7342015-12-10 11:38:49 -08003222 case I40E_AQ_CAP_ID_SWITCH_MODE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003223 p->switch_mode = number;
3224 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003225 case I40E_AQ_CAP_ID_MNG_MODE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003226 p->management_mode = number;
Piotr Raczynski64f5ead2016-10-25 16:08:53 -07003227 if (major_rev > 1) {
3228 p->mng_protocols_over_mctp = logical_id;
3229 i40e_debug(hw, I40E_DEBUG_INIT,
3230 "HW Capability: Protocols over MCTP = %d\n",
3231 p->mng_protocols_over_mctp);
3232 } else {
3233 p->mng_protocols_over_mctp = 0;
3234 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003235 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003236 case I40E_AQ_CAP_ID_NPAR_ACTIVE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003237 p->npar_enable = number;
3238 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003239 case I40E_AQ_CAP_ID_OS2BMC_CAP:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003240 p->os2bmc = number;
3241 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003242 case I40E_AQ_CAP_ID_FUNCTIONS_VALID:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003243 p->valid_functions = number;
3244 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003245 case I40E_AQ_CAP_ID_SRIOV:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003246 if (number == 1)
3247 p->sr_iov_1_1 = true;
3248 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003249 case I40E_AQ_CAP_ID_VF:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003250 p->num_vfs = number;
3251 p->vf_base_id = logical_id;
3252 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003253 case I40E_AQ_CAP_ID_VMDQ:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003254 if (number == 1)
3255 p->vmdq = true;
3256 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003257 case I40E_AQ_CAP_ID_8021QBG:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003258 if (number == 1)
3259 p->evb_802_1_qbg = true;
3260 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003261 case I40E_AQ_CAP_ID_8021QBR:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003262 if (number == 1)
3263 p->evb_802_1_qbh = true;
3264 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003265 case I40E_AQ_CAP_ID_VSI:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003266 p->num_vsis = number;
3267 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003268 case I40E_AQ_CAP_ID_DCB:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003269 if (number == 1) {
3270 p->dcb = true;
3271 p->enabled_tcmap = logical_id;
3272 p->maxtc = phys_id;
3273 }
3274 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003275 case I40E_AQ_CAP_ID_FCOE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003276 if (number == 1)
3277 p->fcoe = true;
3278 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003279 case I40E_AQ_CAP_ID_ISCSI:
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00003280 if (number == 1)
3281 p->iscsi = true;
3282 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003283 case I40E_AQ_CAP_ID_RSS:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003284 p->rss = true;
Carolyn Wybornye157ea32014-06-03 23:50:22 +00003285 p->rss_table_size = number;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003286 p->rss_table_entry_width = logical_id;
3287 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003288 case I40E_AQ_CAP_ID_RXQ:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003289 p->num_rx_qp = number;
3290 p->base_queue = phys_id;
3291 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003292 case I40E_AQ_CAP_ID_TXQ:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003293 p->num_tx_qp = number;
3294 p->base_queue = phys_id;
3295 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003296 case I40E_AQ_CAP_ID_MSIX:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003297 p->num_msix_vectors = number;
Deepthi Kavalur453e16e2016-04-01 03:56:01 -07003298 i40e_debug(hw, I40E_DEBUG_INIT,
3299 "HW Capability: MSIX vector count = %d\n",
3300 p->num_msix_vectors);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003301 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003302 case I40E_AQ_CAP_ID_VF_MSIX:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003303 p->num_msix_vectors_vf = number;
3304 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003305 case I40E_AQ_CAP_ID_FLEX10:
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003306 if (major_rev == 1) {
3307 if (number == 1) {
3308 p->flex10_enable = true;
3309 p->flex10_capable = true;
3310 }
3311 } else {
3312 /* Capability revision >= 2 */
3313 if (number & 1)
3314 p->flex10_enable = true;
3315 if (number & 2)
3316 p->flex10_capable = true;
3317 }
3318 p->flex10_mode = logical_id;
3319 p->flex10_status = phys_id;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003320 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003321 case I40E_AQ_CAP_ID_CEM:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003322 if (number == 1)
3323 p->mgmt_cem = true;
3324 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003325 case I40E_AQ_CAP_ID_IWARP:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003326 if (number == 1)
3327 p->iwarp = true;
3328 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003329 case I40E_AQ_CAP_ID_LED:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003330 if (phys_id < I40E_HW_CAP_MAX_GPIO)
3331 p->led[phys_id] = true;
3332 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003333 case I40E_AQ_CAP_ID_SDP:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003334 if (phys_id < I40E_HW_CAP_MAX_GPIO)
3335 p->sdp[phys_id] = true;
3336 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003337 case I40E_AQ_CAP_ID_MDIO:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003338 if (number == 1) {
3339 p->mdio_port_num = phys_id;
3340 p->mdio_port_mode = logical_id;
3341 }
3342 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003343 case I40E_AQ_CAP_ID_1588:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003344 if (number == 1)
3345 p->ieee_1588 = true;
3346 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003347 case I40E_AQ_CAP_ID_FLOW_DIRECTOR:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003348 p->fd = true;
3349 p->fd_filters_guaranteed = number;
3350 p->fd_filters_best_effort = logical_id;
3351 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003352 case I40E_AQ_CAP_ID_WSR_PROT:
Kevin Scott73b23402015-04-07 19:45:38 -04003353 p->wr_csr_prot = (u64)number;
3354 p->wr_csr_prot |= (u64)logical_id << 32;
3355 break;
Michal Kosiarz68a1c5a2016-04-12 08:30:46 -07003356 case I40E_AQ_CAP_ID_NVM_MGMT:
3357 if (number & I40E_NVM_MGMT_SEC_REV_DISABLED)
3358 p->sec_rev_disabled = true;
3359 if (number & I40E_NVM_MGMT_UPDATE_DISABLED)
3360 p->update_disabled = true;
3361 break;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003362 default:
3363 break;
3364 }
3365 }
3366
Vasu Devf18ae102015-04-07 19:45:36 -04003367 if (p->fcoe)
3368 i40e_debug(hw, I40E_DEBUG_ALL, "device is FCoE capable\n");
3369
Vasu Dev566bb852014-04-09 05:59:06 +00003370 /* Software override ensuring FCoE is disabled if npar or mfp
3371 * mode because it is not supported in these modes.
3372 */
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003373 if (p->npar_enable || p->flex10_enable)
Vasu Dev566bb852014-04-09 05:59:06 +00003374 p->fcoe = false;
3375
Shannon Nelson9fee9db2014-12-11 07:06:30 +00003376 /* count the enabled ports (aka the "not disabled" ports) */
3377 hw->num_ports = 0;
3378 for (i = 0; i < 4; i++) {
3379 u32 port_cfg_reg = I40E_PRTGEN_CNF + (4 * i);
3380 u64 port_cfg = 0;
3381
3382 /* use AQ read to get the physical register offset instead
3383 * of the port relative offset
3384 */
3385 i40e_aq_debug_read_register(hw, port_cfg_reg, &port_cfg, NULL);
3386 if (!(port_cfg & I40E_PRTGEN_CNF_PORT_DIS_MASK))
3387 hw->num_ports++;
3388 }
3389
3390 valid_functions = p->valid_functions;
3391 num_functions = 0;
3392 while (valid_functions) {
3393 if (valid_functions & 1)
3394 num_functions++;
3395 valid_functions >>= 1;
3396 }
3397
3398 /* partition id is 1-based, and functions are evenly spread
3399 * across the ports as partitions
3400 */
Michal Kosiarz999b3152016-10-11 15:26:56 -07003401 if (hw->num_ports != 0) {
3402 hw->partition_id = (hw->pf_id / hw->num_ports) + 1;
3403 hw->num_partitions = num_functions / hw->num_ports;
3404 }
Shannon Nelson9fee9db2014-12-11 07:06:30 +00003405
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003406 /* additional HW specific goodies that might
3407 * someday be HW version specific
3408 */
3409 p->rx_buf_chain_len = I40E_MAX_CHAINED_RX_BUFFERS;
3410}
3411
3412/**
3413 * i40e_aq_discover_capabilities
3414 * @hw: pointer to the hw struct
3415 * @buff: a virtual buffer to hold the capabilities
3416 * @buff_size: Size of the virtual buffer
3417 * @data_size: Size of the returned data, or buff size needed if AQ err==ENOMEM
3418 * @list_type_opc: capabilities type to discover - pass in the command opcode
3419 * @cmd_details: pointer to command details structure or NULL
3420 *
3421 * Get the device capabilities descriptions from the firmware
3422 **/
3423i40e_status i40e_aq_discover_capabilities(struct i40e_hw *hw,
3424 void *buff, u16 buff_size, u16 *data_size,
3425 enum i40e_admin_queue_opc list_type_opc,
3426 struct i40e_asq_cmd_details *cmd_details)
3427{
3428 struct i40e_aqc_list_capabilites *cmd;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003429 struct i40e_aq_desc desc;
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08003430 i40e_status status = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003431
3432 cmd = (struct i40e_aqc_list_capabilites *)&desc.params.raw;
3433
3434 if (list_type_opc != i40e_aqc_opc_list_func_capabilities &&
3435 list_type_opc != i40e_aqc_opc_list_dev_capabilities) {
3436 status = I40E_ERR_PARAM;
3437 goto exit;
3438 }
3439
3440 i40e_fill_default_direct_cmd_desc(&desc, list_type_opc);
3441
3442 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3443 if (buff_size > I40E_AQ_LARGE_BUF)
3444 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3445
3446 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3447 *data_size = le16_to_cpu(desc.datalen);
3448
3449 if (status)
3450 goto exit;
3451
3452 i40e_parse_discover_capabilities(hw, buff, le32_to_cpu(cmd->count),
3453 list_type_opc);
3454
3455exit:
3456 return status;
3457}
3458
3459/**
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003460 * i40e_aq_update_nvm
3461 * @hw: pointer to the hw struct
3462 * @module_pointer: module pointer location in words from the NVM beginning
3463 * @offset: byte offset from the module beginning
3464 * @length: length of the section to be written (in bytes from the offset)
3465 * @data: command buffer (size [bytes] = length)
3466 * @last_command: tells if this is the last command in a series
Pawel Jablonskie3a5d6e2017-12-18 05:14:44 -05003467 * @preservation_flags: Preservation mode flags
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003468 * @cmd_details: pointer to command details structure or NULL
3469 *
3470 * Update the NVM using the admin queue commands
3471 **/
3472i40e_status i40e_aq_update_nvm(struct i40e_hw *hw, u8 module_pointer,
3473 u32 offset, u16 length, void *data,
Pawel Jablonskie3a5d6e2017-12-18 05:14:44 -05003474 bool last_command, u8 preservation_flags,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003475 struct i40e_asq_cmd_details *cmd_details)
3476{
3477 struct i40e_aq_desc desc;
3478 struct i40e_aqc_nvm_update *cmd =
3479 (struct i40e_aqc_nvm_update *)&desc.params.raw;
3480 i40e_status status;
3481
3482 /* In offset the highest byte must be zeroed. */
3483 if (offset & 0xFF000000) {
3484 status = I40E_ERR_PARAM;
3485 goto i40e_aq_update_nvm_exit;
3486 }
3487
3488 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_update);
3489
3490 /* If this is the last command in a series, set the proper flag. */
3491 if (last_command)
3492 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
Pawel Jablonskie3a5d6e2017-12-18 05:14:44 -05003493 if (hw->mac.type == I40E_MAC_X722) {
3494 if (preservation_flags == I40E_NVM_PRESERVATION_FLAGS_SELECTED)
3495 cmd->command_flags |=
3496 (I40E_AQ_NVM_PRESERVATION_FLAGS_SELECTED <<
3497 I40E_AQ_NVM_PRESERVATION_FLAGS_SHIFT);
3498 else if (preservation_flags == I40E_NVM_PRESERVATION_FLAGS_ALL)
3499 cmd->command_flags |=
3500 (I40E_AQ_NVM_PRESERVATION_FLAGS_ALL <<
3501 I40E_AQ_NVM_PRESERVATION_FLAGS_SHIFT);
3502 }
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003503 cmd->module_pointer = module_pointer;
3504 cmd->offset = cpu_to_le32(offset);
3505 cmd->length = cpu_to_le16(length);
3506
3507 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
3508 if (length > I40E_AQ_LARGE_BUF)
3509 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3510
3511 status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
3512
3513i40e_aq_update_nvm_exit:
3514 return status;
3515}
3516
3517/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003518 * i40e_aq_get_lldp_mib
3519 * @hw: pointer to the hw struct
3520 * @bridge_type: type of bridge requested
3521 * @mib_type: Local, Remote or both Local and Remote MIBs
3522 * @buff: pointer to a user supplied buffer to store the MIB block
3523 * @buff_size: size of the buffer (in bytes)
3524 * @local_len : length of the returned Local LLDP MIB
3525 * @remote_len: length of the returned Remote LLDP MIB
3526 * @cmd_details: pointer to command details structure or NULL
3527 *
3528 * Requests the complete LLDP MIB (entire packet).
3529 **/
3530i40e_status i40e_aq_get_lldp_mib(struct i40e_hw *hw, u8 bridge_type,
3531 u8 mib_type, void *buff, u16 buff_size,
3532 u16 *local_len, u16 *remote_len,
3533 struct i40e_asq_cmd_details *cmd_details)
3534{
3535 struct i40e_aq_desc desc;
3536 struct i40e_aqc_lldp_get_mib *cmd =
3537 (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
3538 struct i40e_aqc_lldp_get_mib *resp =
3539 (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
3540 i40e_status status;
3541
3542 if (buff_size == 0 || !buff)
3543 return I40E_ERR_PARAM;
3544
3545 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_get_mib);
3546 /* Indirect Command */
3547 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3548
3549 cmd->type = mib_type & I40E_AQ_LLDP_MIB_TYPE_MASK;
3550 cmd->type |= ((bridge_type << I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) &
3551 I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
3552
3553 desc.datalen = cpu_to_le16(buff_size);
3554
3555 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3556 if (buff_size > I40E_AQ_LARGE_BUF)
3557 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3558
3559 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3560 if (!status) {
3561 if (local_len != NULL)
3562 *local_len = le16_to_cpu(resp->local_len);
3563 if (remote_len != NULL)
3564 *remote_len = le16_to_cpu(resp->remote_len);
3565 }
3566
3567 return status;
3568}
3569
3570/**
3571 * i40e_aq_cfg_lldp_mib_change_event
3572 * @hw: pointer to the hw struct
3573 * @enable_update: Enable or Disable event posting
3574 * @cmd_details: pointer to command details structure or NULL
3575 *
3576 * Enable or Disable posting of an event on ARQ when LLDP MIB
3577 * associated with the interface changes
3578 **/
3579i40e_status i40e_aq_cfg_lldp_mib_change_event(struct i40e_hw *hw,
3580 bool enable_update,
3581 struct i40e_asq_cmd_details *cmd_details)
3582{
3583 struct i40e_aq_desc desc;
3584 struct i40e_aqc_lldp_update_mib *cmd =
3585 (struct i40e_aqc_lldp_update_mib *)&desc.params.raw;
3586 i40e_status status;
3587
3588 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_update_mib);
3589
3590 if (!enable_update)
3591 cmd->command |= I40E_AQ_LLDP_MIB_UPDATE_DISABLE;
3592
3593 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3594
3595 return status;
3596}
3597
3598/**
3599 * i40e_aq_stop_lldp
3600 * @hw: pointer to the hw struct
3601 * @shutdown_agent: True if LLDP Agent needs to be Shutdown
3602 * @cmd_details: pointer to command details structure or NULL
3603 *
3604 * Stop or Shutdown the embedded LLDP Agent
3605 **/
3606i40e_status i40e_aq_stop_lldp(struct i40e_hw *hw, bool shutdown_agent,
3607 struct i40e_asq_cmd_details *cmd_details)
3608{
3609 struct i40e_aq_desc desc;
3610 struct i40e_aqc_lldp_stop *cmd =
3611 (struct i40e_aqc_lldp_stop *)&desc.params.raw;
3612 i40e_status status;
3613
3614 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_stop);
3615
3616 if (shutdown_agent)
3617 cmd->command |= I40E_AQ_LLDP_AGENT_SHUTDOWN;
3618
3619 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3620
3621 return status;
3622}
3623
3624/**
3625 * i40e_aq_start_lldp
3626 * @hw: pointer to the hw struct
3627 * @cmd_details: pointer to command details structure or NULL
3628 *
3629 * Start the embedded LLDP Agent on all ports.
3630 **/
3631i40e_status i40e_aq_start_lldp(struct i40e_hw *hw,
3632 struct i40e_asq_cmd_details *cmd_details)
3633{
3634 struct i40e_aq_desc desc;
3635 struct i40e_aqc_lldp_start *cmd =
3636 (struct i40e_aqc_lldp_start *)&desc.params.raw;
3637 i40e_status status;
3638
3639 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_start);
3640
3641 cmd->command = I40E_AQ_LLDP_AGENT_START;
3642
3643 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3644
3645 return status;
3646}
3647
3648/**
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00003649 * i40e_aq_get_cee_dcb_config
3650 * @hw: pointer to the hw struct
3651 * @buff: response buffer that stores CEE operational configuration
3652 * @buff_size: size of the buffer passed
3653 * @cmd_details: pointer to command details structure or NULL
3654 *
3655 * Get CEE DCBX mode operational configuration from firmware
3656 **/
3657i40e_status i40e_aq_get_cee_dcb_config(struct i40e_hw *hw,
3658 void *buff, u16 buff_size,
3659 struct i40e_asq_cmd_details *cmd_details)
3660{
3661 struct i40e_aq_desc desc;
3662 i40e_status status;
3663
3664 if (buff_size == 0 || !buff)
3665 return I40E_ERR_PARAM;
3666
3667 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_cee_dcb_cfg);
3668
3669 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3670 status = i40e_asq_send_command(hw, &desc, (void *)buff, buff_size,
3671 cmd_details);
3672
3673 return status;
3674}
3675
3676/**
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003677 * i40e_aq_add_udp_tunnel
3678 * @hw: pointer to the hw struct
Jacob Keller15d23b42017-06-07 05:43:04 -04003679 * @udp_port: the UDP port to add in Host byte order
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003680 * @header_len: length of the tunneling header length in DWords
3681 * @protocol_index: protocol index type
Jeff Kirsher98d44382013-12-21 05:44:42 +00003682 * @filter_index: pointer to filter index
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003683 * @cmd_details: pointer to command details structure or NULL
Jacob Keller15d23b42017-06-07 05:43:04 -04003684 *
3685 * Note: Firmware expects the udp_port value to be in Little Endian format,
3686 * and this function will call cpu_to_le16 to convert from Host byte order to
3687 * Little Endian order.
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003688 **/
3689i40e_status i40e_aq_add_udp_tunnel(struct i40e_hw *hw,
Kevin Scottf4f94b92014-04-05 07:46:10 +00003690 u16 udp_port, u8 protocol_index,
3691 u8 *filter_index,
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003692 struct i40e_asq_cmd_details *cmd_details)
3693{
3694 struct i40e_aq_desc desc;
3695 struct i40e_aqc_add_udp_tunnel *cmd =
3696 (struct i40e_aqc_add_udp_tunnel *)&desc.params.raw;
3697 struct i40e_aqc_del_udp_tunnel_completion *resp =
3698 (struct i40e_aqc_del_udp_tunnel_completion *)&desc.params.raw;
3699 i40e_status status;
3700
3701 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_udp_tunnel);
3702
3703 cmd->udp_port = cpu_to_le16(udp_port);
Shannon Nelson981b7542013-12-11 08:17:11 +00003704 cmd->protocol_type = protocol_index;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003705
3706 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3707
Shannon Nelson65d13462015-02-21 06:45:28 +00003708 if (!status && filter_index)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003709 *filter_index = resp->index;
3710
3711 return status;
3712}
3713
3714/**
3715 * i40e_aq_del_udp_tunnel
3716 * @hw: pointer to the hw struct
3717 * @index: filter index
3718 * @cmd_details: pointer to command details structure or NULL
3719 **/
3720i40e_status i40e_aq_del_udp_tunnel(struct i40e_hw *hw, u8 index,
3721 struct i40e_asq_cmd_details *cmd_details)
3722{
3723 struct i40e_aq_desc desc;
3724 struct i40e_aqc_remove_udp_tunnel *cmd =
3725 (struct i40e_aqc_remove_udp_tunnel *)&desc.params.raw;
3726 i40e_status status;
3727
3728 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_del_udp_tunnel);
3729
3730 cmd->index = index;
3731
3732 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3733
3734 return status;
3735}
3736
3737/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003738 * i40e_aq_delete_element - Delete switch element
3739 * @hw: pointer to the hw struct
3740 * @seid: the SEID to delete from the switch
3741 * @cmd_details: pointer to command details structure or NULL
3742 *
3743 * This deletes a switch element from the switch.
3744 **/
3745i40e_status i40e_aq_delete_element(struct i40e_hw *hw, u16 seid,
3746 struct i40e_asq_cmd_details *cmd_details)
3747{
3748 struct i40e_aq_desc desc;
3749 struct i40e_aqc_switch_seid *cmd =
3750 (struct i40e_aqc_switch_seid *)&desc.params.raw;
3751 i40e_status status;
3752
3753 if (seid == 0)
3754 return I40E_ERR_PARAM;
3755
3756 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_delete_element);
3757
3758 cmd->seid = cpu_to_le16(seid);
3759
3760 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3761
3762 return status;
3763}
3764
3765/**
Neerav Parikhafb3ff02014-01-17 15:36:36 -08003766 * i40e_aq_dcb_updated - DCB Updated Command
3767 * @hw: pointer to the hw struct
3768 * @cmd_details: pointer to command details structure or NULL
3769 *
3770 * EMP will return when the shared RPB settings have been
3771 * recomputed and modified. The retval field in the descriptor
3772 * will be set to 0 when RPB is modified.
3773 **/
3774i40e_status i40e_aq_dcb_updated(struct i40e_hw *hw,
3775 struct i40e_asq_cmd_details *cmd_details)
3776{
3777 struct i40e_aq_desc desc;
3778 i40e_status status;
3779
3780 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_dcb_updated);
3781
3782 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3783
3784 return status;
3785}
3786
3787/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003788 * i40e_aq_tx_sched_cmd - generic Tx scheduler AQ command handler
3789 * @hw: pointer to the hw struct
3790 * @seid: seid for the physical port/switching component/vsi
3791 * @buff: Indirect buffer to hold data parameters and response
3792 * @buff_size: Indirect buffer size
3793 * @opcode: Tx scheduler AQ command opcode
3794 * @cmd_details: pointer to command details structure or NULL
3795 *
3796 * Generic command handler for Tx scheduler AQ commands
3797 **/
3798static i40e_status i40e_aq_tx_sched_cmd(struct i40e_hw *hw, u16 seid,
3799 void *buff, u16 buff_size,
3800 enum i40e_admin_queue_opc opcode,
3801 struct i40e_asq_cmd_details *cmd_details)
3802{
3803 struct i40e_aq_desc desc;
3804 struct i40e_aqc_tx_sched_ind *cmd =
3805 (struct i40e_aqc_tx_sched_ind *)&desc.params.raw;
3806 i40e_status status;
3807 bool cmd_param_flag = false;
3808
3809 switch (opcode) {
3810 case i40e_aqc_opc_configure_vsi_ets_sla_bw_limit:
3811 case i40e_aqc_opc_configure_vsi_tc_bw:
3812 case i40e_aqc_opc_enable_switching_comp_ets:
3813 case i40e_aqc_opc_modify_switching_comp_ets:
3814 case i40e_aqc_opc_disable_switching_comp_ets:
3815 case i40e_aqc_opc_configure_switching_comp_ets_bw_limit:
3816 case i40e_aqc_opc_configure_switching_comp_bw_config:
3817 cmd_param_flag = true;
3818 break;
3819 case i40e_aqc_opc_query_vsi_bw_config:
3820 case i40e_aqc_opc_query_vsi_ets_sla_config:
3821 case i40e_aqc_opc_query_switching_comp_ets_config:
3822 case i40e_aqc_opc_query_port_ets_config:
3823 case i40e_aqc_opc_query_switching_comp_bw_config:
3824 cmd_param_flag = false;
3825 break;
3826 default:
3827 return I40E_ERR_PARAM;
3828 }
3829
3830 i40e_fill_default_direct_cmd_desc(&desc, opcode);
3831
3832 /* Indirect command */
3833 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3834 if (cmd_param_flag)
3835 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
3836 if (buff_size > I40E_AQ_LARGE_BUF)
3837 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3838
3839 desc.datalen = cpu_to_le16(buff_size);
3840
3841 cmd->vsi_seid = cpu_to_le16(seid);
3842
3843 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3844
3845 return status;
3846}
3847
3848/**
Mitch Williams6b192892014-03-06 09:02:29 +00003849 * i40e_aq_config_vsi_bw_limit - Configure VSI BW Limit
3850 * @hw: pointer to the hw struct
3851 * @seid: VSI seid
3852 * @credit: BW limit credits (0 = disabled)
3853 * @max_credit: Max BW limit credits
3854 * @cmd_details: pointer to command details structure or NULL
3855 **/
3856i40e_status i40e_aq_config_vsi_bw_limit(struct i40e_hw *hw,
3857 u16 seid, u16 credit, u8 max_credit,
3858 struct i40e_asq_cmd_details *cmd_details)
3859{
3860 struct i40e_aq_desc desc;
3861 struct i40e_aqc_configure_vsi_bw_limit *cmd =
3862 (struct i40e_aqc_configure_vsi_bw_limit *)&desc.params.raw;
3863 i40e_status status;
3864
3865 i40e_fill_default_direct_cmd_desc(&desc,
3866 i40e_aqc_opc_configure_vsi_bw_limit);
3867
3868 cmd->vsi_seid = cpu_to_le16(seid);
3869 cmd->credit = cpu_to_le16(credit);
3870 cmd->max_credit = max_credit;
3871
3872 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3873
3874 return status;
3875}
3876
3877/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003878 * i40e_aq_config_vsi_tc_bw - Config VSI BW Allocation per TC
3879 * @hw: pointer to the hw struct
3880 * @seid: VSI seid
3881 * @bw_data: Buffer holding enabled TCs, relative TC BW limit/credits
3882 * @cmd_details: pointer to command details structure or NULL
3883 **/
3884i40e_status i40e_aq_config_vsi_tc_bw(struct i40e_hw *hw,
3885 u16 seid,
3886 struct i40e_aqc_configure_vsi_tc_bw_data *bw_data,
3887 struct i40e_asq_cmd_details *cmd_details)
3888{
3889 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3890 i40e_aqc_opc_configure_vsi_tc_bw,
3891 cmd_details);
3892}
3893
3894/**
Neerav Parikhafb3ff02014-01-17 15:36:36 -08003895 * i40e_aq_config_switch_comp_ets - Enable/Disable/Modify ETS on the port
3896 * @hw: pointer to the hw struct
3897 * @seid: seid of the switching component connected to Physical Port
3898 * @ets_data: Buffer holding ETS parameters
3899 * @cmd_details: pointer to command details structure or NULL
3900 **/
3901i40e_status i40e_aq_config_switch_comp_ets(struct i40e_hw *hw,
3902 u16 seid,
3903 struct i40e_aqc_configure_switching_comp_ets_data *ets_data,
3904 enum i40e_admin_queue_opc opcode,
3905 struct i40e_asq_cmd_details *cmd_details)
3906{
3907 return i40e_aq_tx_sched_cmd(hw, seid, (void *)ets_data,
3908 sizeof(*ets_data), opcode, cmd_details);
3909}
3910
3911/**
3912 * i40e_aq_config_switch_comp_bw_config - Config Switch comp BW Alloc per TC
3913 * @hw: pointer to the hw struct
3914 * @seid: seid of the switching component
3915 * @bw_data: Buffer holding enabled TCs, relative/absolute TC BW limit/credits
3916 * @cmd_details: pointer to command details structure or NULL
3917 **/
3918i40e_status i40e_aq_config_switch_comp_bw_config(struct i40e_hw *hw,
3919 u16 seid,
3920 struct i40e_aqc_configure_switching_comp_bw_config_data *bw_data,
3921 struct i40e_asq_cmd_details *cmd_details)
3922{
3923 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3924 i40e_aqc_opc_configure_switching_comp_bw_config,
3925 cmd_details);
3926}
3927
3928/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003929 * i40e_aq_query_vsi_bw_config - Query VSI BW configuration
3930 * @hw: pointer to the hw struct
3931 * @seid: seid of the VSI
3932 * @bw_data: Buffer to hold VSI BW configuration
3933 * @cmd_details: pointer to command details structure or NULL
3934 **/
3935i40e_status i40e_aq_query_vsi_bw_config(struct i40e_hw *hw,
3936 u16 seid,
3937 struct i40e_aqc_query_vsi_bw_config_resp *bw_data,
3938 struct i40e_asq_cmd_details *cmd_details)
3939{
3940 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3941 i40e_aqc_opc_query_vsi_bw_config,
3942 cmd_details);
3943}
3944
3945/**
3946 * i40e_aq_query_vsi_ets_sla_config - Query VSI BW configuration per TC
3947 * @hw: pointer to the hw struct
3948 * @seid: seid of the VSI
3949 * @bw_data: Buffer to hold VSI BW configuration per TC
3950 * @cmd_details: pointer to command details structure or NULL
3951 **/
3952i40e_status i40e_aq_query_vsi_ets_sla_config(struct i40e_hw *hw,
3953 u16 seid,
3954 struct i40e_aqc_query_vsi_ets_sla_config_resp *bw_data,
3955 struct i40e_asq_cmd_details *cmd_details)
3956{
3957 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3958 i40e_aqc_opc_query_vsi_ets_sla_config,
3959 cmd_details);
3960}
3961
3962/**
3963 * i40e_aq_query_switch_comp_ets_config - Query Switch comp BW config per TC
3964 * @hw: pointer to the hw struct
3965 * @seid: seid of the switching component
3966 * @bw_data: Buffer to hold switching component's per TC BW config
3967 * @cmd_details: pointer to command details structure or NULL
3968 **/
3969i40e_status i40e_aq_query_switch_comp_ets_config(struct i40e_hw *hw,
3970 u16 seid,
3971 struct i40e_aqc_query_switching_comp_ets_config_resp *bw_data,
3972 struct i40e_asq_cmd_details *cmd_details)
3973{
3974 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3975 i40e_aqc_opc_query_switching_comp_ets_config,
3976 cmd_details);
3977}
3978
3979/**
3980 * i40e_aq_query_port_ets_config - Query Physical Port ETS configuration
3981 * @hw: pointer to the hw struct
3982 * @seid: seid of the VSI or switching component connected to Physical Port
3983 * @bw_data: Buffer to hold current ETS configuration for the Physical Port
3984 * @cmd_details: pointer to command details structure or NULL
3985 **/
3986i40e_status i40e_aq_query_port_ets_config(struct i40e_hw *hw,
3987 u16 seid,
3988 struct i40e_aqc_query_port_ets_config_resp *bw_data,
3989 struct i40e_asq_cmd_details *cmd_details)
3990{
3991 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3992 i40e_aqc_opc_query_port_ets_config,
3993 cmd_details);
3994}
3995
3996/**
3997 * i40e_aq_query_switch_comp_bw_config - Query Switch comp BW configuration
3998 * @hw: pointer to the hw struct
3999 * @seid: seid of the switching component
4000 * @bw_data: Buffer to hold switching component's BW configuration
4001 * @cmd_details: pointer to command details structure or NULL
4002 **/
4003i40e_status i40e_aq_query_switch_comp_bw_config(struct i40e_hw *hw,
4004 u16 seid,
4005 struct i40e_aqc_query_switching_comp_bw_config_resp *bw_data,
4006 struct i40e_asq_cmd_details *cmd_details)
4007{
4008 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
4009 i40e_aqc_opc_query_switching_comp_bw_config,
4010 cmd_details);
4011}
4012
4013/**
4014 * i40e_validate_filter_settings
4015 * @hw: pointer to the hardware structure
4016 * @settings: Filter control settings
4017 *
4018 * Check and validate the filter control settings passed.
4019 * The function checks for the valid filter/context sizes being
4020 * passed for FCoE and PE.
4021 *
4022 * Returns 0 if the values passed are valid and within
4023 * range else returns an error.
4024 **/
4025static i40e_status i40e_validate_filter_settings(struct i40e_hw *hw,
4026 struct i40e_filter_control_settings *settings)
4027{
4028 u32 fcoe_cntx_size, fcoe_filt_size;
4029 u32 pe_cntx_size, pe_filt_size;
Anjali Singhai Jain467d7292014-05-10 04:49:02 +00004030 u32 fcoe_fmax;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00004031 u32 val;
4032
4033 /* Validate FCoE settings passed */
4034 switch (settings->fcoe_filt_num) {
4035 case I40E_HASH_FILTER_SIZE_1K:
4036 case I40E_HASH_FILTER_SIZE_2K:
4037 case I40E_HASH_FILTER_SIZE_4K:
4038 case I40E_HASH_FILTER_SIZE_8K:
4039 case I40E_HASH_FILTER_SIZE_16K:
4040 case I40E_HASH_FILTER_SIZE_32K:
4041 fcoe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
4042 fcoe_filt_size <<= (u32)settings->fcoe_filt_num;
4043 break;
4044 default:
4045 return I40E_ERR_PARAM;
4046 }
4047
4048 switch (settings->fcoe_cntx_num) {
4049 case I40E_DMA_CNTX_SIZE_512:
4050 case I40E_DMA_CNTX_SIZE_1K:
4051 case I40E_DMA_CNTX_SIZE_2K:
4052 case I40E_DMA_CNTX_SIZE_4K:
4053 fcoe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
4054 fcoe_cntx_size <<= (u32)settings->fcoe_cntx_num;
4055 break;
4056 default:
4057 return I40E_ERR_PARAM;
4058 }
4059
4060 /* Validate PE settings passed */
4061 switch (settings->pe_filt_num) {
4062 case I40E_HASH_FILTER_SIZE_1K:
4063 case I40E_HASH_FILTER_SIZE_2K:
4064 case I40E_HASH_FILTER_SIZE_4K:
4065 case I40E_HASH_FILTER_SIZE_8K:
4066 case I40E_HASH_FILTER_SIZE_16K:
4067 case I40E_HASH_FILTER_SIZE_32K:
4068 case I40E_HASH_FILTER_SIZE_64K:
4069 case I40E_HASH_FILTER_SIZE_128K:
4070 case I40E_HASH_FILTER_SIZE_256K:
4071 case I40E_HASH_FILTER_SIZE_512K:
4072 case I40E_HASH_FILTER_SIZE_1M:
4073 pe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
4074 pe_filt_size <<= (u32)settings->pe_filt_num;
4075 break;
4076 default:
4077 return I40E_ERR_PARAM;
4078 }
4079
4080 switch (settings->pe_cntx_num) {
4081 case I40E_DMA_CNTX_SIZE_512:
4082 case I40E_DMA_CNTX_SIZE_1K:
4083 case I40E_DMA_CNTX_SIZE_2K:
4084 case I40E_DMA_CNTX_SIZE_4K:
4085 case I40E_DMA_CNTX_SIZE_8K:
4086 case I40E_DMA_CNTX_SIZE_16K:
4087 case I40E_DMA_CNTX_SIZE_32K:
4088 case I40E_DMA_CNTX_SIZE_64K:
4089 case I40E_DMA_CNTX_SIZE_128K:
4090 case I40E_DMA_CNTX_SIZE_256K:
4091 pe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
4092 pe_cntx_size <<= (u32)settings->pe_cntx_num;
4093 break;
4094 default:
4095 return I40E_ERR_PARAM;
4096 }
4097
4098 /* FCHSIZE + FCDSIZE should not be greater than PMFCOEFMAX */
4099 val = rd32(hw, I40E_GLHMC_FCOEFMAX);
4100 fcoe_fmax = (val & I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_MASK)
4101 >> I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_SHIFT;
4102 if (fcoe_filt_size + fcoe_cntx_size > fcoe_fmax)
4103 return I40E_ERR_INVALID_SIZE;
4104
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00004105 return 0;
4106}
4107
4108/**
4109 * i40e_set_filter_control
4110 * @hw: pointer to the hardware structure
4111 * @settings: Filter control settings
4112 *
4113 * Set the Queue Filters for PE/FCoE and enable filters required
4114 * for a single PF. It is expected that these settings are programmed
4115 * at the driver initialization time.
4116 **/
4117i40e_status i40e_set_filter_control(struct i40e_hw *hw,
4118 struct i40e_filter_control_settings *settings)
4119{
4120 i40e_status ret = 0;
4121 u32 hash_lut_size = 0;
4122 u32 val;
4123
4124 if (!settings)
4125 return I40E_ERR_PARAM;
4126
4127 /* Validate the input settings */
4128 ret = i40e_validate_filter_settings(hw, settings);
4129 if (ret)
4130 return ret;
4131
4132 /* Read the PF Queue Filter control register */
Shannon Nelsonf6581372016-02-17 16:12:20 -08004133 val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00004134
4135 /* Program required PE hash buckets for the PF */
4136 val &= ~I40E_PFQF_CTL_0_PEHSIZE_MASK;
4137 val |= ((u32)settings->pe_filt_num << I40E_PFQF_CTL_0_PEHSIZE_SHIFT) &
4138 I40E_PFQF_CTL_0_PEHSIZE_MASK;
4139 /* Program required PE contexts for the PF */
4140 val &= ~I40E_PFQF_CTL_0_PEDSIZE_MASK;
4141 val |= ((u32)settings->pe_cntx_num << I40E_PFQF_CTL_0_PEDSIZE_SHIFT) &
4142 I40E_PFQF_CTL_0_PEDSIZE_MASK;
4143
4144 /* Program required FCoE hash buckets for the PF */
4145 val &= ~I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
4146 val |= ((u32)settings->fcoe_filt_num <<
4147 I40E_PFQF_CTL_0_PFFCHSIZE_SHIFT) &
4148 I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
4149 /* Program required FCoE DDP contexts for the PF */
4150 val &= ~I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
4151 val |= ((u32)settings->fcoe_cntx_num <<
4152 I40E_PFQF_CTL_0_PFFCDSIZE_SHIFT) &
4153 I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
4154
4155 /* Program Hash LUT size for the PF */
4156 val &= ~I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
4157 if (settings->hash_lut_size == I40E_HASH_LUT_SIZE_512)
4158 hash_lut_size = 1;
4159 val |= (hash_lut_size << I40E_PFQF_CTL_0_HASHLUTSIZE_SHIFT) &
4160 I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
4161
4162 /* Enable FDIR, Ethertype and MACVLAN filters for PF and VFs */
4163 if (settings->enable_fdir)
4164 val |= I40E_PFQF_CTL_0_FD_ENA_MASK;
4165 if (settings->enable_ethtype)
4166 val |= I40E_PFQF_CTL_0_ETYPE_ENA_MASK;
4167 if (settings->enable_macvlan)
4168 val |= I40E_PFQF_CTL_0_MACVLAN_ENA_MASK;
4169
Shannon Nelsonf6581372016-02-17 16:12:20 -08004170 i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, val);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00004171
4172 return 0;
4173}
Neerav Parikhafb3ff02014-01-17 15:36:36 -08004174
4175/**
4176 * i40e_aq_add_rem_control_packet_filter - Add or Remove Control Packet Filter
4177 * @hw: pointer to the hw struct
4178 * @mac_addr: MAC address to use in the filter
4179 * @ethtype: Ethertype to use in the filter
4180 * @flags: Flags that needs to be applied to the filter
4181 * @vsi_seid: seid of the control VSI
4182 * @queue: VSI queue number to send the packet to
4183 * @is_add: Add control packet filter if True else remove
4184 * @stats: Structure to hold information on control filter counts
4185 * @cmd_details: pointer to command details structure or NULL
4186 *
4187 * This command will Add or Remove control packet filter for a control VSI.
4188 * In return it will update the total number of perfect filter count in
4189 * the stats member.
4190 **/
4191i40e_status i40e_aq_add_rem_control_packet_filter(struct i40e_hw *hw,
4192 u8 *mac_addr, u16 ethtype, u16 flags,
4193 u16 vsi_seid, u16 queue, bool is_add,
4194 struct i40e_control_filter_stats *stats,
4195 struct i40e_asq_cmd_details *cmd_details)
4196{
4197 struct i40e_aq_desc desc;
4198 struct i40e_aqc_add_remove_control_packet_filter *cmd =
4199 (struct i40e_aqc_add_remove_control_packet_filter *)
4200 &desc.params.raw;
4201 struct i40e_aqc_add_remove_control_packet_filter_completion *resp =
4202 (struct i40e_aqc_add_remove_control_packet_filter_completion *)
4203 &desc.params.raw;
4204 i40e_status status;
4205
4206 if (vsi_seid == 0)
4207 return I40E_ERR_PARAM;
4208
4209 if (is_add) {
4210 i40e_fill_default_direct_cmd_desc(&desc,
4211 i40e_aqc_opc_add_control_packet_filter);
4212 cmd->queue = cpu_to_le16(queue);
4213 } else {
4214 i40e_fill_default_direct_cmd_desc(&desc,
4215 i40e_aqc_opc_remove_control_packet_filter);
4216 }
4217
4218 if (mac_addr)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04004219 ether_addr_copy(cmd->mac, mac_addr);
Neerav Parikhafb3ff02014-01-17 15:36:36 -08004220
4221 cmd->etype = cpu_to_le16(ethtype);
4222 cmd->flags = cpu_to_le16(flags);
4223 cmd->seid = cpu_to_le16(vsi_seid);
4224
4225 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4226
4227 if (!status && stats) {
4228 stats->mac_etype_used = le16_to_cpu(resp->mac_etype_used);
4229 stats->etype_used = le16_to_cpu(resp->etype_used);
4230 stats->mac_etype_free = le16_to_cpu(resp->mac_etype_free);
4231 stats->etype_free = le16_to_cpu(resp->etype_free);
4232 }
4233
4234 return status;
4235}
4236
Catherine Sullivand4dfb812013-11-28 06:39:21 +00004237/**
Anjali Singhai Jaine7358f52015-10-01 14:37:34 -04004238 * i40e_add_filter_to_drop_tx_flow_control_frames- filter to drop flow control
4239 * @hw: pointer to the hw struct
4240 * @seid: VSI seid to add ethertype filter from
4241 **/
4242#define I40E_FLOW_CONTROL_ETHTYPE 0x8808
4243void i40e_add_filter_to_drop_tx_flow_control_frames(struct i40e_hw *hw,
4244 u16 seid)
4245{
4246 u16 flag = I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC |
4247 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP |
4248 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX;
4249 u16 ethtype = I40E_FLOW_CONTROL_ETHTYPE;
4250 i40e_status status;
4251
4252 status = i40e_aq_add_rem_control_packet_filter(hw, NULL, ethtype, flag,
4253 seid, 0, true, NULL,
4254 NULL);
4255 if (status)
4256 hw_dbg(hw, "Ethtype Filter Add failed: Error pruning Tx flow control frames\n");
4257}
4258
4259/**
Greg Rosef4492db2015-02-06 08:52:12 +00004260 * i40e_aq_alternate_read
4261 * @hw: pointer to the hardware structure
4262 * @reg_addr0: address of first dword to be read
4263 * @reg_val0: pointer for data read from 'reg_addr0'
4264 * @reg_addr1: address of second dword to be read
4265 * @reg_val1: pointer for data read from 'reg_addr1'
4266 *
4267 * Read one or two dwords from alternate structure. Fields are indicated
4268 * by 'reg_addr0' and 'reg_addr1' register numbers. If 'reg_val1' pointer
4269 * is not passed then only register at 'reg_addr0' is read.
4270 *
4271 **/
Shannon Nelson37a29732015-02-27 09:15:19 +00004272static i40e_status i40e_aq_alternate_read(struct i40e_hw *hw,
4273 u32 reg_addr0, u32 *reg_val0,
4274 u32 reg_addr1, u32 *reg_val1)
Greg Rosef4492db2015-02-06 08:52:12 +00004275{
4276 struct i40e_aq_desc desc;
4277 struct i40e_aqc_alternate_write *cmd_resp =
4278 (struct i40e_aqc_alternate_write *)&desc.params.raw;
4279 i40e_status status;
4280
4281 if (!reg_val0)
4282 return I40E_ERR_PARAM;
4283
4284 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_alternate_read);
4285 cmd_resp->address0 = cpu_to_le32(reg_addr0);
4286 cmd_resp->address1 = cpu_to_le32(reg_addr1);
4287
4288 status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
4289
4290 if (!status) {
4291 *reg_val0 = le32_to_cpu(cmd_resp->data0);
4292
4293 if (reg_val1)
4294 *reg_val1 = le32_to_cpu(cmd_resp->data1);
4295 }
4296
4297 return status;
4298}
4299
4300/**
Neerav Parikh2fd75f32014-11-12 00:18:20 +00004301 * i40e_aq_resume_port_tx
4302 * @hw: pointer to the hardware structure
4303 * @cmd_details: pointer to command details structure or NULL
4304 *
4305 * Resume port's Tx traffic
4306 **/
4307i40e_status i40e_aq_resume_port_tx(struct i40e_hw *hw,
4308 struct i40e_asq_cmd_details *cmd_details)
4309{
4310 struct i40e_aq_desc desc;
4311 i40e_status status;
4312
4313 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_resume_port_tx);
4314
4315 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4316
4317 return status;
4318}
4319
4320/**
Catherine Sullivand4dfb812013-11-28 06:39:21 +00004321 * i40e_set_pci_config_data - store PCI bus info
4322 * @hw: pointer to hardware structure
4323 * @link_status: the link status word from PCI config space
4324 *
4325 * Stores the PCI bus info (speed, width, type) within the i40e_hw structure
4326 **/
4327void i40e_set_pci_config_data(struct i40e_hw *hw, u16 link_status)
4328{
4329 hw->bus.type = i40e_bus_type_pci_express;
4330
4331 switch (link_status & PCI_EXP_LNKSTA_NLW) {
4332 case PCI_EXP_LNKSTA_NLW_X1:
4333 hw->bus.width = i40e_bus_width_pcie_x1;
4334 break;
4335 case PCI_EXP_LNKSTA_NLW_X2:
4336 hw->bus.width = i40e_bus_width_pcie_x2;
4337 break;
4338 case PCI_EXP_LNKSTA_NLW_X4:
4339 hw->bus.width = i40e_bus_width_pcie_x4;
4340 break;
4341 case PCI_EXP_LNKSTA_NLW_X8:
4342 hw->bus.width = i40e_bus_width_pcie_x8;
4343 break;
4344 default:
4345 hw->bus.width = i40e_bus_width_unknown;
4346 break;
4347 }
4348
4349 switch (link_status & PCI_EXP_LNKSTA_CLS) {
4350 case PCI_EXP_LNKSTA_CLS_2_5GB:
4351 hw->bus.speed = i40e_bus_speed_2500;
4352 break;
4353 case PCI_EXP_LNKSTA_CLS_5_0GB:
4354 hw->bus.speed = i40e_bus_speed_5000;
4355 break;
4356 case PCI_EXP_LNKSTA_CLS_8_0GB:
4357 hw->bus.speed = i40e_bus_speed_8000;
4358 break;
4359 default:
4360 hw->bus.speed = i40e_bus_speed_unknown;
4361 break;
4362 }
4363}
Greg Rosef4492db2015-02-06 08:52:12 +00004364
4365/**
Jesse Brandeburg3169c322015-04-07 19:45:37 -04004366 * i40e_aq_debug_dump
4367 * @hw: pointer to the hardware structure
4368 * @cluster_id: specific cluster to dump
4369 * @table_id: table id within cluster
4370 * @start_index: index of line in the block to read
4371 * @buff_size: dump buffer size
4372 * @buff: dump buffer
4373 * @ret_buff_size: actual buffer size returned
4374 * @ret_next_table: next block to read
4375 * @ret_next_index: next index to read
4376 *
4377 * Dump internal FW/HW data for debug purposes.
4378 *
4379 **/
4380i40e_status i40e_aq_debug_dump(struct i40e_hw *hw, u8 cluster_id,
4381 u8 table_id, u32 start_index, u16 buff_size,
4382 void *buff, u16 *ret_buff_size,
4383 u8 *ret_next_table, u32 *ret_next_index,
4384 struct i40e_asq_cmd_details *cmd_details)
4385{
4386 struct i40e_aq_desc desc;
4387 struct i40e_aqc_debug_dump_internals *cmd =
4388 (struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
4389 struct i40e_aqc_debug_dump_internals *resp =
4390 (struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
4391 i40e_status status;
4392
4393 if (buff_size == 0 || !buff)
4394 return I40E_ERR_PARAM;
4395
4396 i40e_fill_default_direct_cmd_desc(&desc,
4397 i40e_aqc_opc_debug_dump_internals);
4398 /* Indirect Command */
4399 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
4400 if (buff_size > I40E_AQ_LARGE_BUF)
4401 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
4402
4403 cmd->cluster_id = cluster_id;
4404 cmd->table_id = table_id;
4405 cmd->idx = cpu_to_le32(start_index);
4406
4407 desc.datalen = cpu_to_le16(buff_size);
4408
4409 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
4410 if (!status) {
4411 if (ret_buff_size)
4412 *ret_buff_size = le16_to_cpu(desc.datalen);
4413 if (ret_next_table)
4414 *ret_next_table = resp->table_id;
4415 if (ret_next_index)
4416 *ret_next_index = le32_to_cpu(resp->idx);
4417 }
4418
4419 return status;
4420}
4421
4422/**
Greg Rosef4492db2015-02-06 08:52:12 +00004423 * i40e_read_bw_from_alt_ram
4424 * @hw: pointer to the hardware structure
4425 * @max_bw: pointer for max_bw read
4426 * @min_bw: pointer for min_bw read
4427 * @min_valid: pointer for bool that is true if min_bw is a valid value
4428 * @max_valid: pointer for bool that is true if max_bw is a valid value
4429 *
4430 * Read bw from the alternate ram for the given pf
4431 **/
4432i40e_status i40e_read_bw_from_alt_ram(struct i40e_hw *hw,
4433 u32 *max_bw, u32 *min_bw,
4434 bool *min_valid, bool *max_valid)
4435{
4436 i40e_status status;
4437 u32 max_bw_addr, min_bw_addr;
4438
4439 /* Calculate the address of the min/max bw registers */
4440 max_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
4441 I40E_ALT_STRUCT_MAX_BW_OFFSET +
4442 (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
4443 min_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
4444 I40E_ALT_STRUCT_MIN_BW_OFFSET +
4445 (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
4446
4447 /* Read the bandwidths from alt ram */
4448 status = i40e_aq_alternate_read(hw, max_bw_addr, max_bw,
4449 min_bw_addr, min_bw);
4450
4451 if (*min_bw & I40E_ALT_BW_VALID_MASK)
4452 *min_valid = true;
4453 else
4454 *min_valid = false;
4455
4456 if (*max_bw & I40E_ALT_BW_VALID_MASK)
4457 *max_valid = true;
4458 else
4459 *max_valid = false;
4460
4461 return status;
4462}
4463
4464/**
4465 * i40e_aq_configure_partition_bw
4466 * @hw: pointer to the hardware structure
4467 * @bw_data: Buffer holding valid pfs and bw limits
4468 * @cmd_details: pointer to command details
4469 *
4470 * Configure partitions guaranteed/max bw
4471 **/
4472i40e_status i40e_aq_configure_partition_bw(struct i40e_hw *hw,
4473 struct i40e_aqc_configure_partition_bw_data *bw_data,
4474 struct i40e_asq_cmd_details *cmd_details)
4475{
4476 i40e_status status;
4477 struct i40e_aq_desc desc;
4478 u16 bwd_size = sizeof(*bw_data);
4479
4480 i40e_fill_default_direct_cmd_desc(&desc,
4481 i40e_aqc_opc_configure_partition_bw);
4482
4483 /* Indirect command */
4484 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
4485 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
4486
4487 if (bwd_size > I40E_AQ_LARGE_BUF)
4488 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
4489
4490 desc.datalen = cpu_to_le16(bwd_size);
4491
4492 status = i40e_asq_send_command(hw, &desc, bw_data, bwd_size,
4493 cmd_details);
4494
4495 return status;
4496}
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004497
4498/**
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004499 * i40e_read_phy_register_clause22
4500 * @hw: pointer to the HW structure
4501 * @reg: register address in the page
4502 * @phy_adr: PHY address on MDIO interface
4503 * @value: PHY register value
4504 *
4505 * Reads specified PHY register value
4506 **/
4507i40e_status i40e_read_phy_register_clause22(struct i40e_hw *hw,
4508 u16 reg, u8 phy_addr, u16 *value)
4509{
4510 i40e_status status = I40E_ERR_TIMEOUT;
4511 u8 port_num = (u8)hw->func_caps.mdio_port_num;
4512 u32 command = 0;
4513 u16 retry = 1000;
4514
4515 command = (reg << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4516 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
4517 (I40E_MDIO_CLAUSE22_OPCODE_READ_MASK) |
4518 (I40E_MDIO_CLAUSE22_STCODE_MASK) |
4519 (I40E_GLGEN_MSCA_MDICMD_MASK);
4520 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4521 do {
4522 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4523 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4524 status = 0;
4525 break;
4526 }
4527 udelay(10);
4528 retry--;
4529 } while (retry);
4530
4531 if (status) {
4532 i40e_debug(hw, I40E_DEBUG_PHY,
4533 "PHY: Can't write command to external PHY.\n");
Henry Tieman27e5f252016-11-08 13:05:06 -08004534 } else {
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004535 command = rd32(hw, I40E_GLGEN_MSRWD(port_num));
4536 *value = (command & I40E_GLGEN_MSRWD_MDIRDDATA_MASK) >>
4537 I40E_GLGEN_MSRWD_MDIRDDATA_SHIFT;
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004538 }
4539
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004540 return status;
4541}
4542
4543/**
4544 * i40e_write_phy_register_clause22
4545 * @hw: pointer to the HW structure
4546 * @reg: register address in the page
4547 * @phy_adr: PHY address on MDIO interface
4548 * @value: PHY register value
4549 *
4550 * Writes specified PHY register value
4551 **/
4552i40e_status i40e_write_phy_register_clause22(struct i40e_hw *hw,
4553 u16 reg, u8 phy_addr, u16 value)
4554{
4555 i40e_status status = I40E_ERR_TIMEOUT;
4556 u8 port_num = (u8)hw->func_caps.mdio_port_num;
4557 u32 command = 0;
4558 u16 retry = 1000;
4559
4560 command = value << I40E_GLGEN_MSRWD_MDIWRDATA_SHIFT;
4561 wr32(hw, I40E_GLGEN_MSRWD(port_num), command);
4562
4563 command = (reg << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4564 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
4565 (I40E_MDIO_CLAUSE22_OPCODE_WRITE_MASK) |
4566 (I40E_MDIO_CLAUSE22_STCODE_MASK) |
4567 (I40E_GLGEN_MSCA_MDICMD_MASK);
4568
4569 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4570 do {
4571 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4572 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4573 status = 0;
4574 break;
4575 }
4576 udelay(10);
4577 retry--;
4578 } while (retry);
4579
4580 return status;
4581}
4582
4583/**
4584 * i40e_read_phy_register_clause45
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004585 * @hw: pointer to the HW structure
4586 * @page: registers page number
4587 * @reg: register address in the page
4588 * @phy_adr: PHY address on MDIO interface
4589 * @value: PHY register value
4590 *
4591 * Reads specified PHY register value
4592 **/
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004593i40e_status i40e_read_phy_register_clause45(struct i40e_hw *hw,
4594 u8 page, u16 reg, u8 phy_addr, u16 *value)
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004595{
4596 i40e_status status = I40E_ERR_TIMEOUT;
4597 u32 command = 0;
4598 u16 retry = 1000;
4599 u8 port_num = hw->func_caps.mdio_port_num;
4600
4601 command = (reg << I40E_GLGEN_MSCA_MDIADD_SHIFT) |
4602 (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4603 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004604 (I40E_MDIO_CLAUSE45_OPCODE_ADDRESS_MASK) |
4605 (I40E_MDIO_CLAUSE45_STCODE_MASK) |
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004606 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4607 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4608 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4609 do {
4610 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4611 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4612 status = 0;
4613 break;
4614 }
4615 usleep_range(10, 20);
4616 retry--;
4617 } while (retry);
4618
4619 if (status) {
4620 i40e_debug(hw, I40E_DEBUG_PHY,
4621 "PHY: Can't write command to external PHY.\n");
4622 goto phy_read_end;
4623 }
4624
4625 command = (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4626 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004627 (I40E_MDIO_CLAUSE45_OPCODE_READ_MASK) |
4628 (I40E_MDIO_CLAUSE45_STCODE_MASK) |
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004629 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4630 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4631 status = I40E_ERR_TIMEOUT;
4632 retry = 1000;
4633 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4634 do {
4635 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4636 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4637 status = 0;
4638 break;
4639 }
4640 usleep_range(10, 20);
4641 retry--;
4642 } while (retry);
4643
4644 if (!status) {
4645 command = rd32(hw, I40E_GLGEN_MSRWD(port_num));
4646 *value = (command & I40E_GLGEN_MSRWD_MDIRDDATA_MASK) >>
4647 I40E_GLGEN_MSRWD_MDIRDDATA_SHIFT;
4648 } else {
4649 i40e_debug(hw, I40E_DEBUG_PHY,
4650 "PHY: Can't read register value from external PHY.\n");
4651 }
4652
4653phy_read_end:
4654 return status;
4655}
4656
4657/**
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004658 * i40e_write_phy_register_clause45
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004659 * @hw: pointer to the HW structure
4660 * @page: registers page number
4661 * @reg: register address in the page
4662 * @phy_adr: PHY address on MDIO interface
4663 * @value: PHY register value
4664 *
4665 * Writes value to specified PHY register
4666 **/
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004667i40e_status i40e_write_phy_register_clause45(struct i40e_hw *hw,
4668 u8 page, u16 reg, u8 phy_addr, u16 value)
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004669{
4670 i40e_status status = I40E_ERR_TIMEOUT;
4671 u32 command = 0;
4672 u16 retry = 1000;
4673 u8 port_num = hw->func_caps.mdio_port_num;
4674
4675 command = (reg << I40E_GLGEN_MSCA_MDIADD_SHIFT) |
4676 (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4677 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004678 (I40E_MDIO_CLAUSE45_OPCODE_ADDRESS_MASK) |
4679 (I40E_MDIO_CLAUSE45_STCODE_MASK) |
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004680 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4681 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4682 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4683 do {
4684 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4685 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4686 status = 0;
4687 break;
4688 }
4689 usleep_range(10, 20);
4690 retry--;
4691 } while (retry);
4692 if (status) {
4693 i40e_debug(hw, I40E_DEBUG_PHY,
4694 "PHY: Can't write command to external PHY.\n");
4695 goto phy_write_end;
4696 }
4697
4698 command = value << I40E_GLGEN_MSRWD_MDIWRDATA_SHIFT;
4699 wr32(hw, I40E_GLGEN_MSRWD(port_num), command);
4700
4701 command = (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4702 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004703 (I40E_MDIO_CLAUSE45_OPCODE_WRITE_MASK) |
4704 (I40E_MDIO_CLAUSE45_STCODE_MASK) |
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004705 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4706 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4707 status = I40E_ERR_TIMEOUT;
4708 retry = 1000;
4709 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4710 do {
4711 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4712 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4713 status = 0;
4714 break;
4715 }
4716 usleep_range(10, 20);
4717 retry--;
4718 } while (retry);
4719
4720phy_write_end:
4721 return status;
4722}
4723
4724/**
Michal Kosiarzf62ba912016-11-21 13:03:50 -08004725 * i40e_write_phy_register
4726 * @hw: pointer to the HW structure
4727 * @page: registers page number
4728 * @reg: register address in the page
4729 * @phy_adr: PHY address on MDIO interface
4730 * @value: PHY register value
4731 *
4732 * Writes value to specified PHY register
4733 **/
4734i40e_status i40e_write_phy_register(struct i40e_hw *hw,
4735 u8 page, u16 reg, u8 phy_addr, u16 value)
4736{
4737 i40e_status status;
4738
4739 switch (hw->device_id) {
4740 case I40E_DEV_ID_1G_BASE_T_X722:
4741 status = i40e_write_phy_register_clause22(hw, reg, phy_addr,
4742 value);
4743 break;
4744 case I40E_DEV_ID_10G_BASE_T:
4745 case I40E_DEV_ID_10G_BASE_T4:
4746 case I40E_DEV_ID_10G_BASE_T_X722:
4747 case I40E_DEV_ID_25G_B:
4748 case I40E_DEV_ID_25G_SFP28:
4749 status = i40e_write_phy_register_clause45(hw, page, reg,
4750 phy_addr, value);
4751 break;
4752 default:
4753 status = I40E_ERR_UNKNOWN_PHY;
4754 break;
4755 }
4756
4757 return status;
4758}
4759
4760/**
4761 * i40e_read_phy_register
4762 * @hw: pointer to the HW structure
4763 * @page: registers page number
4764 * @reg: register address in the page
4765 * @phy_adr: PHY address on MDIO interface
4766 * @value: PHY register value
4767 *
4768 * Reads specified PHY register value
4769 **/
4770i40e_status i40e_read_phy_register(struct i40e_hw *hw,
4771 u8 page, u16 reg, u8 phy_addr, u16 *value)
4772{
4773 i40e_status status;
4774
4775 switch (hw->device_id) {
4776 case I40E_DEV_ID_1G_BASE_T_X722:
4777 status = i40e_read_phy_register_clause22(hw, reg, phy_addr,
4778 value);
4779 break;
4780 case I40E_DEV_ID_10G_BASE_T:
4781 case I40E_DEV_ID_10G_BASE_T4:
4782 case I40E_DEV_ID_10G_BASE_T_X722:
4783 case I40E_DEV_ID_25G_B:
4784 case I40E_DEV_ID_25G_SFP28:
4785 status = i40e_read_phy_register_clause45(hw, page, reg,
4786 phy_addr, value);
4787 break;
4788 default:
4789 status = I40E_ERR_UNKNOWN_PHY;
4790 break;
4791 }
4792
4793 return status;
4794}
4795
4796/**
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004797 * i40e_get_phy_address
4798 * @hw: pointer to the HW structure
4799 * @dev_num: PHY port num that address we want
4800 * @phy_addr: Returned PHY address
4801 *
4802 * Gets PHY address for current port
4803 **/
4804u8 i40e_get_phy_address(struct i40e_hw *hw, u8 dev_num)
4805{
4806 u8 port_num = hw->func_caps.mdio_port_num;
4807 u32 reg_val = rd32(hw, I40E_GLGEN_MDIO_I2C_SEL(port_num));
4808
4809 return (u8)(reg_val >> ((dev_num + 1) * 5)) & 0x1f;
4810}
4811
4812/**
4813 * i40e_blink_phy_led
4814 * @hw: pointer to the HW structure
4815 * @time: time how long led will blinks in secs
4816 * @interval: gap between LED on and off in msecs
4817 *
4818 * Blinks PHY link LED
4819 **/
4820i40e_status i40e_blink_phy_link_led(struct i40e_hw *hw,
4821 u32 time, u32 interval)
4822{
4823 i40e_status status = 0;
4824 u32 i;
4825 u16 led_ctl;
4826 u16 gpio_led_port;
4827 u16 led_reg;
4828 u16 led_addr = I40E_PHY_LED_PROV_REG_1;
4829 u8 phy_addr = 0;
4830 u8 port_num;
4831
4832 i = rd32(hw, I40E_PFGEN_PORTNUM);
4833 port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
4834 phy_addr = i40e_get_phy_address(hw, port_num);
4835
4836 for (gpio_led_port = 0; gpio_led_port < 3; gpio_led_port++,
4837 led_addr++) {
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004838 status = i40e_read_phy_register_clause45(hw,
4839 I40E_PHY_COM_REG_PAGE,
4840 led_addr, phy_addr,
4841 &led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004842 if (status)
4843 goto phy_blinking_end;
4844 led_ctl = led_reg;
4845 if (led_reg & I40E_PHY_LED_LINK_MODE_MASK) {
4846 led_reg = 0;
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004847 status = i40e_write_phy_register_clause45(hw,
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004848 I40E_PHY_COM_REG_PAGE,
4849 led_addr, phy_addr,
4850 led_reg);
4851 if (status)
4852 goto phy_blinking_end;
4853 break;
4854 }
4855 }
4856
4857 if (time > 0 && interval > 0) {
4858 for (i = 0; i < time * 1000; i += interval) {
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004859 status = i40e_read_phy_register_clause45(hw,
4860 I40E_PHY_COM_REG_PAGE,
4861 led_addr, phy_addr, &led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004862 if (status)
4863 goto restore_config;
4864 if (led_reg & I40E_PHY_LED_MANUAL_ON)
4865 led_reg = 0;
4866 else
4867 led_reg = I40E_PHY_LED_MANUAL_ON;
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004868 status = i40e_write_phy_register_clause45(hw,
4869 I40E_PHY_COM_REG_PAGE,
4870 led_addr, phy_addr, led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004871 if (status)
4872 goto restore_config;
4873 msleep(interval);
4874 }
4875 }
4876
4877restore_config:
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004878 status = i40e_write_phy_register_clause45(hw,
4879 I40E_PHY_COM_REG_PAGE,
4880 led_addr, phy_addr, led_ctl);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004881
4882phy_blinking_end:
4883 return status;
4884}
4885
4886/**
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04004887 * i40e_led_get_reg - read LED register
4888 * @hw: pointer to the HW structure
4889 * @led_addr: LED register address
4890 * @reg_val: read register value
4891 **/
4892static enum i40e_status_code i40e_led_get_reg(struct i40e_hw *hw, u16 led_addr,
4893 u32 *reg_val)
4894{
4895 enum i40e_status_code status;
4896 u8 phy_addr = 0;
4897 u8 port_num;
4898 u32 i;
4899
4900 *reg_val = 0;
4901 if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) {
4902 status =
4903 i40e_aq_get_phy_register(hw,
4904 I40E_AQ_PHY_REG_ACCESS_EXTERNAL,
4905 I40E_PHY_COM_REG_PAGE,
4906 I40E_PHY_LED_PROV_REG_1,
4907 reg_val, NULL);
4908 } else {
4909 i = rd32(hw, I40E_PFGEN_PORTNUM);
4910 port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
4911 phy_addr = i40e_get_phy_address(hw, port_num);
4912 status = i40e_read_phy_register_clause45(hw,
4913 I40E_PHY_COM_REG_PAGE,
4914 led_addr, phy_addr,
4915 (u16 *)reg_val);
4916 }
4917 return status;
4918}
4919
4920/**
4921 * i40e_led_set_reg - write LED register
4922 * @hw: pointer to the HW structure
4923 * @led_addr: LED register address
4924 * @reg_val: register value to write
4925 **/
4926static enum i40e_status_code i40e_led_set_reg(struct i40e_hw *hw, u16 led_addr,
4927 u32 reg_val)
4928{
4929 enum i40e_status_code status;
4930 u8 phy_addr = 0;
4931 u8 port_num;
4932 u32 i;
4933
4934 if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) {
4935 status =
4936 i40e_aq_set_phy_register(hw,
4937 I40E_AQ_PHY_REG_ACCESS_EXTERNAL,
4938 I40E_PHY_COM_REG_PAGE,
4939 I40E_PHY_LED_PROV_REG_1,
4940 reg_val, NULL);
4941 } else {
4942 i = rd32(hw, I40E_PFGEN_PORTNUM);
4943 port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
4944 phy_addr = i40e_get_phy_address(hw, port_num);
4945 status = i40e_write_phy_register_clause45(hw,
4946 I40E_PHY_COM_REG_PAGE,
4947 led_addr, phy_addr,
4948 (u16)reg_val);
4949 }
4950
4951 return status;
4952}
4953
4954/**
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004955 * i40e_led_get_phy - return current on/off mode
4956 * @hw: pointer to the hw struct
4957 * @led_addr: address of led register to use
4958 * @val: original value of register to use
4959 *
4960 **/
4961i40e_status i40e_led_get_phy(struct i40e_hw *hw, u16 *led_addr,
4962 u16 *val)
4963{
4964 i40e_status status = 0;
4965 u16 gpio_led_port;
4966 u8 phy_addr = 0;
4967 u16 reg_val;
4968 u16 temp_addr;
4969 u8 port_num;
4970 u32 i;
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04004971 u32 reg_val_aq;
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004972
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04004973 if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) {
4974 status =
4975 i40e_aq_get_phy_register(hw,
4976 I40E_AQ_PHY_REG_ACCESS_EXTERNAL,
4977 I40E_PHY_COM_REG_PAGE,
4978 I40E_PHY_LED_PROV_REG_1,
4979 &reg_val_aq, NULL);
4980 if (status == I40E_SUCCESS)
4981 *val = (u16)reg_val_aq;
4982 return status;
4983 }
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004984 temp_addr = I40E_PHY_LED_PROV_REG_1;
4985 i = rd32(hw, I40E_PFGEN_PORTNUM);
4986 port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
4987 phy_addr = i40e_get_phy_address(hw, port_num);
4988
4989 for (gpio_led_port = 0; gpio_led_port < 3; gpio_led_port++,
4990 temp_addr++) {
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004991 status = i40e_read_phy_register_clause45(hw,
4992 I40E_PHY_COM_REG_PAGE,
4993 temp_addr, phy_addr,
4994 &reg_val);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004995 if (status)
4996 return status;
4997 *val = reg_val;
4998 if (reg_val & I40E_PHY_LED_LINK_MODE_MASK) {
4999 *led_addr = temp_addr;
5000 break;
5001 }
5002 }
5003 return status;
5004}
5005
5006/**
5007 * i40e_led_set_phy
5008 * @hw: pointer to the HW structure
5009 * @on: true or false
5010 * @mode: original val plus bit for set or ignore
5011 * Set led's on or off when controlled by the PHY
5012 *
5013 **/
5014i40e_status i40e_led_set_phy(struct i40e_hw *hw, bool on,
5015 u16 led_addr, u32 mode)
5016{
5017 i40e_status status = 0;
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005018 u32 led_ctl = 0;
5019 u32 led_reg = 0;
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005020
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005021 status = i40e_led_get_reg(hw, led_addr, &led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005022 if (status)
5023 return status;
5024 led_ctl = led_reg;
5025 if (led_reg & I40E_PHY_LED_LINK_MODE_MASK) {
5026 led_reg = 0;
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005027 status = i40e_led_set_reg(hw, led_addr, led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005028 if (status)
5029 return status;
5030 }
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005031 status = i40e_led_get_reg(hw, led_addr, &led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005032 if (status)
5033 goto restore_config;
5034 if (on)
5035 led_reg = I40E_PHY_LED_MANUAL_ON;
5036 else
5037 led_reg = 0;
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005038
5039 status = i40e_led_set_reg(hw, led_addr, led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005040 if (status)
5041 goto restore_config;
5042 if (mode & I40E_PHY_LED_MODE_ORIG) {
5043 led_ctl = (mode & I40E_PHY_LED_MODE_MASK);
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005044 status = i40e_led_set_reg(hw, led_addr, led_ctl);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005045 }
5046 return status;
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005047
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005048restore_config:
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005049 status = i40e_led_set_reg(hw, led_addr, led_ctl);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005050 return status;
5051}
Shannon Nelsonf6581372016-02-17 16:12:20 -08005052
5053/**
5054 * i40e_aq_rx_ctl_read_register - use FW to read from an Rx control register
5055 * @hw: pointer to the hw struct
5056 * @reg_addr: register address
5057 * @reg_val: ptr to register value
5058 * @cmd_details: pointer to command details structure or NULL
5059 *
5060 * Use the firmware to read the Rx control register,
5061 * especially useful if the Rx unit is under heavy pressure
5062 **/
5063i40e_status i40e_aq_rx_ctl_read_register(struct i40e_hw *hw,
5064 u32 reg_addr, u32 *reg_val,
5065 struct i40e_asq_cmd_details *cmd_details)
5066{
5067 struct i40e_aq_desc desc;
5068 struct i40e_aqc_rx_ctl_reg_read_write *cmd_resp =
5069 (struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
5070 i40e_status status;
5071
5072 if (!reg_val)
5073 return I40E_ERR_PARAM;
5074
5075 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_rx_ctl_reg_read);
5076
5077 cmd_resp->address = cpu_to_le32(reg_addr);
5078
5079 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5080
5081 if (status == 0)
5082 *reg_val = le32_to_cpu(cmd_resp->value);
5083
5084 return status;
5085}
5086
5087/**
5088 * i40e_read_rx_ctl - read from an Rx control register
5089 * @hw: pointer to the hw struct
5090 * @reg_addr: register address
5091 **/
5092u32 i40e_read_rx_ctl(struct i40e_hw *hw, u32 reg_addr)
5093{
5094 i40e_status status = 0;
5095 bool use_register;
5096 int retry = 5;
5097 u32 val = 0;
5098
Paul M Stillwell Jr60303082017-03-10 12:22:02 -08005099 use_register = (((hw->aq.api_maj_ver == 1) &&
5100 (hw->aq.api_min_ver < 5)) ||
5101 (hw->mac.type == I40E_MAC_X722));
Shannon Nelsonf6581372016-02-17 16:12:20 -08005102 if (!use_register) {
5103do_retry:
5104 status = i40e_aq_rx_ctl_read_register(hw, reg_addr, &val, NULL);
5105 if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
5106 usleep_range(1000, 2000);
5107 retry--;
5108 goto do_retry;
5109 }
5110 }
5111
5112 /* if the AQ access failed, try the old-fashioned way */
5113 if (status || use_register)
5114 val = rd32(hw, reg_addr);
5115
5116 return val;
5117}
5118
5119/**
5120 * i40e_aq_rx_ctl_write_register
5121 * @hw: pointer to the hw struct
5122 * @reg_addr: register address
5123 * @reg_val: register value
5124 * @cmd_details: pointer to command details structure or NULL
5125 *
5126 * Use the firmware to write to an Rx control register,
5127 * especially useful if the Rx unit is under heavy pressure
5128 **/
5129i40e_status i40e_aq_rx_ctl_write_register(struct i40e_hw *hw,
5130 u32 reg_addr, u32 reg_val,
5131 struct i40e_asq_cmd_details *cmd_details)
5132{
5133 struct i40e_aq_desc desc;
5134 struct i40e_aqc_rx_ctl_reg_read_write *cmd =
5135 (struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
5136 i40e_status status;
5137
5138 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_rx_ctl_reg_write);
5139
5140 cmd->address = cpu_to_le32(reg_addr);
5141 cmd->value = cpu_to_le32(reg_val);
5142
5143 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5144
5145 return status;
5146}
5147
5148/**
5149 * i40e_write_rx_ctl - write to an Rx control register
5150 * @hw: pointer to the hw struct
5151 * @reg_addr: register address
5152 * @reg_val: register value
5153 **/
5154void i40e_write_rx_ctl(struct i40e_hw *hw, u32 reg_addr, u32 reg_val)
5155{
5156 i40e_status status = 0;
5157 bool use_register;
5158 int retry = 5;
5159
Paul M Stillwell Jr60303082017-03-10 12:22:02 -08005160 use_register = (((hw->aq.api_maj_ver == 1) &&
5161 (hw->aq.api_min_ver < 5)) ||
5162 (hw->mac.type == I40E_MAC_X722));
Shannon Nelsonf6581372016-02-17 16:12:20 -08005163 if (!use_register) {
5164do_retry:
5165 status = i40e_aq_rx_ctl_write_register(hw, reg_addr,
5166 reg_val, NULL);
5167 if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
5168 usleep_range(1000, 2000);
5169 retry--;
5170 goto do_retry;
5171 }
5172 }
5173
5174 /* if the AQ access failed, try the old-fashioned way */
5175 if (status || use_register)
5176 wr32(hw, reg_addr, reg_val);
5177}
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005178
5179/**
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04005180 * i40e_aq_set_phy_register
5181 * @hw: pointer to the hw struct
5182 * @phy_select: select which phy should be accessed
5183 * @dev_addr: PHY device address
5184 * @reg_addr: PHY register address
5185 * @reg_val: new register value
5186 * @cmd_details: pointer to command details structure or NULL
5187 *
5188 * Write the external PHY register.
5189 **/
5190i40e_status i40e_aq_set_phy_register(struct i40e_hw *hw,
5191 u8 phy_select, u8 dev_addr,
5192 u32 reg_addr, u32 reg_val,
5193 struct i40e_asq_cmd_details *cmd_details)
5194{
5195 struct i40e_aq_desc desc;
5196 struct i40e_aqc_phy_register_access *cmd =
5197 (struct i40e_aqc_phy_register_access *)&desc.params.raw;
5198 i40e_status status;
5199
5200 i40e_fill_default_direct_cmd_desc(&desc,
5201 i40e_aqc_opc_set_phy_register);
5202
5203 cmd->phy_interface = phy_select;
5204 cmd->dev_address = dev_addr;
5205 cmd->reg_address = cpu_to_le32(reg_addr);
5206 cmd->reg_value = cpu_to_le32(reg_val);
5207
5208 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5209
5210 return status;
5211}
5212
5213/**
5214 * i40e_aq_get_phy_register
5215 * @hw: pointer to the hw struct
5216 * @phy_select: select which phy should be accessed
5217 * @dev_addr: PHY device address
5218 * @reg_addr: PHY register address
5219 * @reg_val: read register value
5220 * @cmd_details: pointer to command details structure or NULL
5221 *
5222 * Read the external PHY register.
5223 **/
5224i40e_status i40e_aq_get_phy_register(struct i40e_hw *hw,
5225 u8 phy_select, u8 dev_addr,
5226 u32 reg_addr, u32 *reg_val,
5227 struct i40e_asq_cmd_details *cmd_details)
5228{
5229 struct i40e_aq_desc desc;
5230 struct i40e_aqc_phy_register_access *cmd =
5231 (struct i40e_aqc_phy_register_access *)&desc.params.raw;
5232 i40e_status status;
5233
5234 i40e_fill_default_direct_cmd_desc(&desc,
5235 i40e_aqc_opc_get_phy_register);
5236
5237 cmd->phy_interface = phy_select;
5238 cmd->dev_address = dev_addr;
5239 cmd->reg_address = cpu_to_le32(reg_addr);
5240
5241 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5242 if (!status)
5243 *reg_val = le32_to_cpu(cmd->reg_value);
5244
5245 return status;
5246}
5247
5248/**
Jingjing Wu329e5982017-11-14 07:00:47 -05005249 * i40e_aq_write_ddp - Write dynamic device personalization (ddp)
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005250 * @hw: pointer to the hw struct
5251 * @buff: command buffer (size in bytes = buff_size)
5252 * @buff_size: buffer size in bytes
5253 * @track_id: package tracking id
5254 * @error_offset: returns error offset
5255 * @error_info: returns error information
5256 * @cmd_details: pointer to command details structure or NULL
5257 **/
5258enum
Jingjing Wu329e5982017-11-14 07:00:47 -05005259i40e_status_code i40e_aq_write_ddp(struct i40e_hw *hw, void *buff,
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005260 u16 buff_size, u32 track_id,
5261 u32 *error_offset, u32 *error_info,
5262 struct i40e_asq_cmd_details *cmd_details)
5263{
5264 struct i40e_aq_desc desc;
5265 struct i40e_aqc_write_personalization_profile *cmd =
5266 (struct i40e_aqc_write_personalization_profile *)
5267 &desc.params.raw;
Jingjing Wu329e5982017-11-14 07:00:47 -05005268 struct i40e_aqc_write_ddp_resp *resp;
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005269 i40e_status status;
5270
5271 i40e_fill_default_direct_cmd_desc(&desc,
5272 i40e_aqc_opc_write_personalization_profile);
5273
5274 desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
5275 if (buff_size > I40E_AQ_LARGE_BUF)
5276 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
5277
5278 desc.datalen = cpu_to_le16(buff_size);
5279
5280 cmd->profile_track_id = cpu_to_le32(track_id);
5281
5282 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
5283 if (!status) {
Jingjing Wu329e5982017-11-14 07:00:47 -05005284 resp = (struct i40e_aqc_write_ddp_resp *)&desc.params.raw;
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005285 if (error_offset)
5286 *error_offset = le32_to_cpu(resp->error_offset);
5287 if (error_info)
5288 *error_info = le32_to_cpu(resp->error_info);
5289 }
5290
5291 return status;
5292}
5293
5294/**
Jingjing Wu329e5982017-11-14 07:00:47 -05005295 * i40e_aq_get_ddp_list - Read dynamic device personalization (ddp)
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005296 * @hw: pointer to the hw struct
5297 * @buff: command buffer (size in bytes = buff_size)
5298 * @buff_size: buffer size in bytes
5299 * @cmd_details: pointer to command details structure or NULL
5300 **/
5301enum
Jingjing Wu329e5982017-11-14 07:00:47 -05005302i40e_status_code i40e_aq_get_ddp_list(struct i40e_hw *hw, void *buff,
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005303 u16 buff_size, u8 flags,
5304 struct i40e_asq_cmd_details *cmd_details)
5305{
5306 struct i40e_aq_desc desc;
5307 struct i40e_aqc_get_applied_profiles *cmd =
5308 (struct i40e_aqc_get_applied_profiles *)&desc.params.raw;
5309 i40e_status status;
5310
5311 i40e_fill_default_direct_cmd_desc(&desc,
5312 i40e_aqc_opc_get_personalization_profile_list);
5313
5314 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
5315 if (buff_size > I40E_AQ_LARGE_BUF)
5316 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
5317 desc.datalen = cpu_to_le16(buff_size);
5318
5319 cmd->flags = flags;
5320
5321 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
5322
5323 return status;
5324}
5325
5326/**
5327 * i40e_find_segment_in_package
5328 * @segment_type: the segment type to search for (i.e., SEGMENT_TYPE_I40E)
5329 * @pkg_hdr: pointer to the package header to be searched
5330 *
5331 * This function searches a package file for a particular segment type. On
5332 * success it returns a pointer to the segment header, otherwise it will
5333 * return NULL.
5334 **/
5335struct i40e_generic_seg_header *
5336i40e_find_segment_in_package(u32 segment_type,
5337 struct i40e_package_header *pkg_hdr)
5338{
5339 struct i40e_generic_seg_header *segment;
5340 u32 i;
5341
5342 /* Search all package segments for the requested segment type */
5343 for (i = 0; i < pkg_hdr->segment_count; i++) {
5344 segment =
5345 (struct i40e_generic_seg_header *)((u8 *)pkg_hdr +
5346 pkg_hdr->segment_offset[i]);
5347
5348 if (segment->type == segment_type)
5349 return segment;
5350 }
5351
5352 return NULL;
5353}
5354
5355/**
5356 * i40e_write_profile
5357 * @hw: pointer to the hardware structure
5358 * @profile: pointer to the profile segment of the package to be downloaded
5359 * @track_id: package tracking id
5360 *
5361 * Handles the download of a complete package.
5362 */
5363enum i40e_status_code
5364i40e_write_profile(struct i40e_hw *hw, struct i40e_profile_segment *profile,
5365 u32 track_id)
5366{
5367 i40e_status status = 0;
5368 struct i40e_section_table *sec_tbl;
5369 struct i40e_profile_section_header *sec = NULL;
5370 u32 dev_cnt;
5371 u32 vendor_dev_id;
5372 u32 *nvm;
5373 u32 section_size = 0;
5374 u32 offset = 0, info = 0;
5375 u32 i;
5376
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005377 dev_cnt = profile->device_table_count;
5378
5379 for (i = 0; i < dev_cnt; i++) {
5380 vendor_dev_id = profile->device_table[i].vendor_dev_id;
5381 if ((vendor_dev_id >> 16) == PCI_VENDOR_ID_INTEL)
5382 if (hw->device_id == (vendor_dev_id & 0xFFFF))
5383 break;
5384 }
5385 if (i == dev_cnt) {
Jingjing Wu329e5982017-11-14 07:00:47 -05005386 i40e_debug(hw, I40E_DEBUG_PACKAGE, "Device doesn't support DDP");
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005387 return I40E_ERR_DEVICE_NOT_SUPPORTED;
5388 }
5389
5390 nvm = (u32 *)&profile->device_table[dev_cnt];
5391 sec_tbl = (struct i40e_section_table *)&nvm[nvm[0] + 1];
5392
5393 for (i = 0; i < sec_tbl->section_count; i++) {
5394 sec = (struct i40e_profile_section_header *)((u8 *)profile +
5395 sec_tbl->section_offset[i]);
5396
5397 /* Skip 'AQ', 'note' and 'name' sections */
5398 if (sec->section.type != SECTION_TYPE_MMIO)
5399 continue;
5400
5401 section_size = sec->section.size +
5402 sizeof(struct i40e_profile_section_header);
5403
5404 /* Write profile */
Jingjing Wu329e5982017-11-14 07:00:47 -05005405 status = i40e_aq_write_ddp(hw, (void *)sec, (u16)section_size,
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005406 track_id, &offset, &info, NULL);
5407 if (status) {
5408 i40e_debug(hw, I40E_DEBUG_PACKAGE,
5409 "Failed to write profile: offset %d, info %d",
5410 offset, info);
5411 break;
5412 }
5413 }
5414 return status;
5415}
5416
5417/**
5418 * i40e_add_pinfo_to_list
5419 * @hw: pointer to the hardware structure
5420 * @profile: pointer to the profile segment of the package
5421 * @profile_info_sec: buffer for information section
5422 * @track_id: package tracking id
5423 *
5424 * Register a profile to the list of loaded profiles.
5425 */
5426enum i40e_status_code
5427i40e_add_pinfo_to_list(struct i40e_hw *hw,
5428 struct i40e_profile_segment *profile,
5429 u8 *profile_info_sec, u32 track_id)
5430{
5431 i40e_status status = 0;
5432 struct i40e_profile_section_header *sec = NULL;
5433 struct i40e_profile_info *pinfo;
5434 u32 offset = 0, info = 0;
5435
5436 sec = (struct i40e_profile_section_header *)profile_info_sec;
5437 sec->tbl_size = 1;
5438 sec->data_end = sizeof(struct i40e_profile_section_header) +
5439 sizeof(struct i40e_profile_info);
5440 sec->section.type = SECTION_TYPE_INFO;
5441 sec->section.offset = sizeof(struct i40e_profile_section_header);
5442 sec->section.size = sizeof(struct i40e_profile_info);
5443 pinfo = (struct i40e_profile_info *)(profile_info_sec +
5444 sec->section.offset);
5445 pinfo->track_id = track_id;
5446 pinfo->version = profile->version;
Jingjing Wu329e5982017-11-14 07:00:47 -05005447 pinfo->op = I40E_DDP_ADD_TRACKID;
5448 memcpy(pinfo->name, profile->name, I40E_DDP_NAME_SIZE);
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005449
Jingjing Wu329e5982017-11-14 07:00:47 -05005450 status = i40e_aq_write_ddp(hw, (void *)sec, sec->data_end,
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005451 track_id, &offset, &info, NULL);
Amritha Nambiar2f4b4112017-10-27 02:36:01 -07005452
5453 return status;
5454}
5455
5456/**
5457 * i40e_aq_add_cloud_filters
5458 * @hw: pointer to the hardware structure
5459 * @seid: VSI seid to add cloud filters from
5460 * @filters: Buffer which contains the filters to be added
5461 * @filter_count: number of filters contained in the buffer
5462 *
5463 * Set the cloud filters for a given VSI. The contents of the
5464 * i40e_aqc_cloud_filters_element_data are filled in by the caller
5465 * of the function.
5466 *
5467 **/
5468enum i40e_status_code
5469i40e_aq_add_cloud_filters(struct i40e_hw *hw, u16 seid,
5470 struct i40e_aqc_cloud_filters_element_data *filters,
5471 u8 filter_count)
5472{
5473 struct i40e_aq_desc desc;
5474 struct i40e_aqc_add_remove_cloud_filters *cmd =
5475 (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
5476 enum i40e_status_code status;
5477 u16 buff_len;
5478
5479 i40e_fill_default_direct_cmd_desc(&desc,
5480 i40e_aqc_opc_add_cloud_filters);
5481
5482 buff_len = filter_count * sizeof(*filters);
5483 desc.datalen = cpu_to_le16(buff_len);
5484 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
5485 cmd->num_filters = filter_count;
5486 cmd->seid = cpu_to_le16(seid);
5487
5488 status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
5489
5490 return status;
5491}
5492
5493/**
5494 * i40e_aq_add_cloud_filters_bb
5495 * @hw: pointer to the hardware structure
5496 * @seid: VSI seid to add cloud filters from
5497 * @filters: Buffer which contains the filters in big buffer to be added
5498 * @filter_count: number of filters contained in the buffer
5499 *
5500 * Set the big buffer cloud filters for a given VSI. The contents of the
5501 * i40e_aqc_cloud_filters_element_bb are filled in by the caller of the
5502 * function.
5503 *
5504 **/
5505i40e_status
5506i40e_aq_add_cloud_filters_bb(struct i40e_hw *hw, u16 seid,
5507 struct i40e_aqc_cloud_filters_element_bb *filters,
5508 u8 filter_count)
5509{
5510 struct i40e_aq_desc desc;
5511 struct i40e_aqc_add_remove_cloud_filters *cmd =
5512 (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
5513 i40e_status status;
5514 u16 buff_len;
5515 int i;
5516
5517 i40e_fill_default_direct_cmd_desc(&desc,
5518 i40e_aqc_opc_add_cloud_filters);
5519
5520 buff_len = filter_count * sizeof(*filters);
5521 desc.datalen = cpu_to_le16(buff_len);
5522 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
5523 cmd->num_filters = filter_count;
5524 cmd->seid = cpu_to_le16(seid);
5525 cmd->big_buffer_flag = I40E_AQC_ADD_CLOUD_CMD_BB;
5526
5527 for (i = 0; i < filter_count; i++) {
5528 u16 tnl_type;
5529 u32 ti;
5530
5531 tnl_type = (le16_to_cpu(filters[i].element.flags) &
5532 I40E_AQC_ADD_CLOUD_TNL_TYPE_MASK) >>
5533 I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT;
5534
5535 /* Due to hardware eccentricities, the VNI for Geneve is shifted
5536 * one more byte further than normally used for Tenant ID in
5537 * other tunnel types.
5538 */
5539 if (tnl_type == I40E_AQC_ADD_CLOUD_TNL_TYPE_GENEVE) {
5540 ti = le32_to_cpu(filters[i].element.tenant_id);
5541 filters[i].element.tenant_id = cpu_to_le32(ti << 8);
5542 }
5543 }
5544
5545 status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
5546
5547 return status;
5548}
5549
5550/**
5551 * i40e_aq_rem_cloud_filters
5552 * @hw: pointer to the hardware structure
5553 * @seid: VSI seid to remove cloud filters from
5554 * @filters: Buffer which contains the filters to be removed
5555 * @filter_count: number of filters contained in the buffer
5556 *
5557 * Remove the cloud filters for a given VSI. The contents of the
5558 * i40e_aqc_cloud_filters_element_data are filled in by the caller
5559 * of the function.
5560 *
5561 **/
5562enum i40e_status_code
5563i40e_aq_rem_cloud_filters(struct i40e_hw *hw, u16 seid,
5564 struct i40e_aqc_cloud_filters_element_data *filters,
5565 u8 filter_count)
5566{
5567 struct i40e_aq_desc desc;
5568 struct i40e_aqc_add_remove_cloud_filters *cmd =
5569 (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
5570 enum i40e_status_code status;
5571 u16 buff_len;
5572
5573 i40e_fill_default_direct_cmd_desc(&desc,
5574 i40e_aqc_opc_remove_cloud_filters);
5575
5576 buff_len = filter_count * sizeof(*filters);
5577 desc.datalen = cpu_to_le16(buff_len);
5578 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
5579 cmd->num_filters = filter_count;
5580 cmd->seid = cpu_to_le16(seid);
5581
5582 status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
5583
5584 return status;
5585}
5586
5587/**
5588 * i40e_aq_rem_cloud_filters_bb
5589 * @hw: pointer to the hardware structure
5590 * @seid: VSI seid to remove cloud filters from
5591 * @filters: Buffer which contains the filters in big buffer to be removed
5592 * @filter_count: number of filters contained in the buffer
5593 *
5594 * Remove the big buffer cloud filters for a given VSI. The contents of the
5595 * i40e_aqc_cloud_filters_element_bb are filled in by the caller of the
5596 * function.
5597 *
5598 **/
5599i40e_status
5600i40e_aq_rem_cloud_filters_bb(struct i40e_hw *hw, u16 seid,
5601 struct i40e_aqc_cloud_filters_element_bb *filters,
5602 u8 filter_count)
5603{
5604 struct i40e_aq_desc desc;
5605 struct i40e_aqc_add_remove_cloud_filters *cmd =
5606 (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
5607 i40e_status status;
5608 u16 buff_len;
5609 int i;
5610
5611 i40e_fill_default_direct_cmd_desc(&desc,
5612 i40e_aqc_opc_remove_cloud_filters);
5613
5614 buff_len = filter_count * sizeof(*filters);
5615 desc.datalen = cpu_to_le16(buff_len);
5616 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
5617 cmd->num_filters = filter_count;
5618 cmd->seid = cpu_to_le16(seid);
5619 cmd->big_buffer_flag = I40E_AQC_ADD_CLOUD_CMD_BB;
5620
5621 for (i = 0; i < filter_count; i++) {
5622 u16 tnl_type;
5623 u32 ti;
5624
5625 tnl_type = (le16_to_cpu(filters[i].element.flags) &
5626 I40E_AQC_ADD_CLOUD_TNL_TYPE_MASK) >>
5627 I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT;
5628
5629 /* Due to hardware eccentricities, the VNI for Geneve is shifted
5630 * one more byte further than normally used for Tenant ID in
5631 * other tunnel types.
5632 */
5633 if (tnl_type == I40E_AQC_ADD_CLOUD_TNL_TYPE_GENEVE) {
5634 ti = le32_to_cpu(filters[i].element.tenant_id);
5635 filters[i].element.tenant_id = cpu_to_le32(ti << 8);
5636 }
5637 }
5638
5639 status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
5640
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005641 return status;
5642}