blob: df852c23f45cf6446d1559397bf32144ebc813dc [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";
Michal Kosiarzf34e308b2017-12-27 08:14:40 -0500281 case I40E_ERR_ADMIN_QUEUE_CRITICAL_ERROR:
282 return "I40E_ERR_ADMIN_QUEUE_CRITICAL_ERROR";
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400283 }
284
285 snprintf(hw->err_str, sizeof(hw->err_str), "%d", stat_err);
286 return hw->err_str;
287}
288
289/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000290 * i40e_debug_aq
291 * @hw: debug mask related to admin queue
Jeff Kirsher98d44382013-12-21 05:44:42 +0000292 * @mask: debug mask
293 * @desc: pointer to admin queue descriptor
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000294 * @buffer: pointer to command buffer
Shannon Nelsonf905dd62014-07-10 07:58:20 +0000295 * @buf_len: max length of buffer
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000296 *
297 * Dumps debug log about adminq command with descriptor contents.
298 **/
299void i40e_debug_aq(struct i40e_hw *hw, enum i40e_debug_mask mask, void *desc,
Shannon Nelsonf905dd62014-07-10 07:58:20 +0000300 void *buffer, u16 buf_len)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000301{
302 struct i40e_aq_desc *aq_desc = (struct i40e_aq_desc *)desc;
Heinrich Schuchardtcd956722016-05-17 22:41:33 +0200303 u16 len;
Shannon Nelson37a29732015-02-27 09:15:19 +0000304 u8 *buf = (u8 *)buffer;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000305
306 if ((!(mask & hw->debug_mask)) || (desc == NULL))
307 return;
308
Heinrich Schuchardtcd956722016-05-17 22:41:33 +0200309 len = le16_to_cpu(aq_desc->datalen);
310
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000311 i40e_debug(hw, mask,
312 "AQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000313 le16_to_cpu(aq_desc->opcode),
314 le16_to_cpu(aq_desc->flags),
315 le16_to_cpu(aq_desc->datalen),
316 le16_to_cpu(aq_desc->retval));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000317 i40e_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000318 le32_to_cpu(aq_desc->cookie_high),
319 le32_to_cpu(aq_desc->cookie_low));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000320 i40e_debug(hw, mask, "\tparam (0,1) 0x%08X 0x%08X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000321 le32_to_cpu(aq_desc->params.internal.param0),
322 le32_to_cpu(aq_desc->params.internal.param1));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000323 i40e_debug(hw, mask, "\taddr (h,l) 0x%08X 0x%08X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000324 le32_to_cpu(aq_desc->params.external.addr_high),
325 le32_to_cpu(aq_desc->params.external.addr_low));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000326
327 if ((buffer != NULL) && (aq_desc->datalen != 0)) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000328 i40e_debug(hw, mask, "AQ CMD Buffer:\n");
Shannon Nelsonf905dd62014-07-10 07:58:20 +0000329 if (buf_len < len)
330 len = buf_len;
Shannon Nelson37a29732015-02-27 09:15:19 +0000331 /* write the full 16-byte chunks */
Alan Brady773d4022016-12-12 15:44:13 -0800332 if (hw->debug_mask & mask) {
Jacob Kellerb5d55042017-07-12 05:46:09 -0400333 char prefix[27];
Alan Brady773d4022016-12-12 15:44:13 -0800334
Jacob Kellerb5d55042017-07-12 05:46:09 -0400335 snprintf(prefix, sizeof(prefix),
Alan Brady773d4022016-12-12 15:44:13 -0800336 "i40e %02x:%02x.%x: \t0x",
337 hw->bus.bus_id,
338 hw->bus.device,
339 hw->bus.func);
340
341 print_hex_dump(KERN_INFO, prefix, DUMP_PREFIX_OFFSET,
342 16, 1, buf, len, false);
343 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000344 }
345}
346
347/**
Anjali Singhai Jaine1860d82013-11-28 06:39:45 +0000348 * i40e_check_asq_alive
349 * @hw: pointer to the hw struct
350 *
351 * Returns true if Queue is enabled else false.
352 **/
353bool i40e_check_asq_alive(struct i40e_hw *hw)
354{
Kevin Scott8b833b42014-04-09 05:58:54 +0000355 if (hw->aq.asq.len)
356 return !!(rd32(hw, hw->aq.asq.len) &
357 I40E_PF_ATQLEN_ATQENABLE_MASK);
358 else
359 return false;
Anjali Singhai Jaine1860d82013-11-28 06:39:45 +0000360}
361
362/**
363 * i40e_aq_queue_shutdown
364 * @hw: pointer to the hw struct
365 * @unloading: is the driver unloading itself
366 *
367 * Tell the Firmware that we're shutting down the AdminQ and whether
368 * or not the driver is unloading as well.
369 **/
370i40e_status i40e_aq_queue_shutdown(struct i40e_hw *hw,
371 bool unloading)
372{
373 struct i40e_aq_desc desc;
374 struct i40e_aqc_queue_shutdown *cmd =
375 (struct i40e_aqc_queue_shutdown *)&desc.params.raw;
376 i40e_status status;
377
378 i40e_fill_default_direct_cmd_desc(&desc,
379 i40e_aqc_opc_queue_shutdown);
380
381 if (unloading)
382 cmd->driver_unloading = cpu_to_le32(I40E_AQ_DRIVER_UNLOADING);
383 status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
384
385 return status;
386}
387
Anjali Singhai Jaine50c8d62015-06-05 12:20:27 -0400388/**
389 * i40e_aq_get_set_rss_lut
390 * @hw: pointer to the hardware structure
391 * @vsi_id: vsi fw index
392 * @pf_lut: for PF table set true, for VSI table set false
393 * @lut: pointer to the lut buffer provided by the caller
394 * @lut_size: size of the lut buffer
395 * @set: set true to set the table, false to get the table
396 *
397 * Internal function to get or set RSS look up table
398 **/
399static i40e_status i40e_aq_get_set_rss_lut(struct i40e_hw *hw,
400 u16 vsi_id, bool pf_lut,
401 u8 *lut, u16 lut_size,
402 bool set)
403{
404 i40e_status status;
405 struct i40e_aq_desc desc;
406 struct i40e_aqc_get_set_rss_lut *cmd_resp =
407 (struct i40e_aqc_get_set_rss_lut *)&desc.params.raw;
408
409 if (set)
410 i40e_fill_default_direct_cmd_desc(&desc,
411 i40e_aqc_opc_set_rss_lut);
412 else
413 i40e_fill_default_direct_cmd_desc(&desc,
414 i40e_aqc_opc_get_rss_lut);
415
416 /* Indirect command */
417 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
418 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
419
420 cmd_resp->vsi_id =
421 cpu_to_le16((u16)((vsi_id <<
422 I40E_AQC_SET_RSS_LUT_VSI_ID_SHIFT) &
423 I40E_AQC_SET_RSS_LUT_VSI_ID_MASK));
424 cmd_resp->vsi_id |= cpu_to_le16((u16)I40E_AQC_SET_RSS_LUT_VSI_VALID);
425
426 if (pf_lut)
427 cmd_resp->flags |= cpu_to_le16((u16)
428 ((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_PF <<
429 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
430 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
431 else
432 cmd_resp->flags |= cpu_to_le16((u16)
433 ((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_VSI <<
434 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
435 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
436
Anjali Singhai Jaine50c8d62015-06-05 12:20:27 -0400437 status = i40e_asq_send_command(hw, &desc, lut, lut_size, NULL);
438
439 return status;
440}
441
442/**
443 * i40e_aq_get_rss_lut
444 * @hw: pointer to the hardware structure
445 * @vsi_id: vsi fw index
446 * @pf_lut: for PF table set true, for VSI table set false
447 * @lut: pointer to the lut buffer provided by the caller
448 * @lut_size: size of the lut buffer
449 *
450 * get the RSS lookup table, PF or VSI type
451 **/
452i40e_status i40e_aq_get_rss_lut(struct i40e_hw *hw, u16 vsi_id,
453 bool pf_lut, u8 *lut, u16 lut_size)
454{
455 return i40e_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size,
456 false);
457}
458
459/**
460 * i40e_aq_set_rss_lut
461 * @hw: pointer to the hardware structure
462 * @vsi_id: vsi fw index
463 * @pf_lut: for PF table set true, for VSI table set false
464 * @lut: pointer to the lut buffer provided by the caller
465 * @lut_size: size of the lut buffer
466 *
467 * set the RSS lookup table, PF or VSI type
468 **/
469i40e_status i40e_aq_set_rss_lut(struct i40e_hw *hw, u16 vsi_id,
470 bool pf_lut, u8 *lut, u16 lut_size)
471{
472 return i40e_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size, true);
473}
474
475/**
476 * i40e_aq_get_set_rss_key
477 * @hw: pointer to the hw struct
478 * @vsi_id: vsi fw index
479 * @key: pointer to key info struct
480 * @set: set true to set the key, false to get the key
481 *
482 * get the RSS key per VSI
483 **/
484static i40e_status i40e_aq_get_set_rss_key(struct i40e_hw *hw,
485 u16 vsi_id,
486 struct i40e_aqc_get_set_rss_key_data *key,
487 bool set)
488{
489 i40e_status status;
490 struct i40e_aq_desc desc;
491 struct i40e_aqc_get_set_rss_key *cmd_resp =
492 (struct i40e_aqc_get_set_rss_key *)&desc.params.raw;
493 u16 key_size = sizeof(struct i40e_aqc_get_set_rss_key_data);
494
495 if (set)
496 i40e_fill_default_direct_cmd_desc(&desc,
497 i40e_aqc_opc_set_rss_key);
498 else
499 i40e_fill_default_direct_cmd_desc(&desc,
500 i40e_aqc_opc_get_rss_key);
501
502 /* Indirect command */
503 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
504 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
505
506 cmd_resp->vsi_id =
507 cpu_to_le16((u16)((vsi_id <<
508 I40E_AQC_SET_RSS_KEY_VSI_ID_SHIFT) &
509 I40E_AQC_SET_RSS_KEY_VSI_ID_MASK));
510 cmd_resp->vsi_id |= cpu_to_le16((u16)I40E_AQC_SET_RSS_KEY_VSI_VALID);
Anjali Singhai Jaine50c8d62015-06-05 12:20:27 -0400511
512 status = i40e_asq_send_command(hw, &desc, key, key_size, NULL);
513
514 return status;
515}
516
517/**
518 * i40e_aq_get_rss_key
519 * @hw: pointer to the hw struct
520 * @vsi_id: vsi fw index
521 * @key: pointer to key info struct
522 *
523 **/
524i40e_status i40e_aq_get_rss_key(struct i40e_hw *hw,
525 u16 vsi_id,
526 struct i40e_aqc_get_set_rss_key_data *key)
527{
528 return i40e_aq_get_set_rss_key(hw, vsi_id, key, false);
529}
530
531/**
532 * i40e_aq_set_rss_key
533 * @hw: pointer to the hw struct
534 * @vsi_id: vsi fw index
535 * @key: pointer to key info struct
536 *
537 * set the RSS key per VSI
538 **/
539i40e_status i40e_aq_set_rss_key(struct i40e_hw *hw,
540 u16 vsi_id,
541 struct i40e_aqc_get_set_rss_key_data *key)
542{
543 return i40e_aq_get_set_rss_key(hw, vsi_id, key, true);
544}
545
Jesse Brandeburg206812b2014-02-12 01:45:33 +0000546/* The i40e_ptype_lookup table is used to convert from the 8-bit ptype in the
547 * hardware to a bit-field that can be used by SW to more easily determine the
548 * packet type.
549 *
550 * Macros are used to shorten the table lines and make this table human
551 * readable.
552 *
553 * We store the PTYPE in the top byte of the bit field - this is just so that
554 * we can check that the table doesn't have a row missing, as the index into
555 * the table should be the PTYPE.
556 *
557 * Typical work flow:
558 *
559 * IF NOT i40e_ptype_lookup[ptype].known
560 * THEN
561 * Packet is unknown
562 * ELSE IF i40e_ptype_lookup[ptype].outer_ip == I40E_RX_PTYPE_OUTER_IP
563 * Use the rest of the fields to look at the tunnels, inner protocols, etc
564 * ELSE
565 * Use the enum i40e_rx_l2_ptype to decode the packet type
566 * ENDIF
567 */
568
569/* macro to make the table lines short */
570#define I40E_PTT(PTYPE, OUTER_IP, OUTER_IP_VER, OUTER_FRAG, T, TE, TEF, I, PL)\
571 { PTYPE, \
572 1, \
573 I40E_RX_PTYPE_OUTER_##OUTER_IP, \
574 I40E_RX_PTYPE_OUTER_##OUTER_IP_VER, \
575 I40E_RX_PTYPE_##OUTER_FRAG, \
576 I40E_RX_PTYPE_TUNNEL_##T, \
577 I40E_RX_PTYPE_TUNNEL_END_##TE, \
578 I40E_RX_PTYPE_##TEF, \
579 I40E_RX_PTYPE_INNER_PROT_##I, \
580 I40E_RX_PTYPE_PAYLOAD_LAYER_##PL }
581
582#define I40E_PTT_UNUSED_ENTRY(PTYPE) \
583 { PTYPE, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
584
585/* shorter macros makes the table fit but are terse */
586#define I40E_RX_PTYPE_NOF I40E_RX_PTYPE_NOT_FRAG
587#define I40E_RX_PTYPE_FRG I40E_RX_PTYPE_FRAG
588#define I40E_RX_PTYPE_INNER_PROT_TS I40E_RX_PTYPE_INNER_PROT_TIMESYNC
589
590/* Lookup table mapping the HW PTYPE to the bit field for decoding */
591struct i40e_rx_ptype_decoded i40e_ptype_lookup[] = {
592 /* L2 Packet types */
593 I40E_PTT_UNUSED_ENTRY(0),
594 I40E_PTT(1, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
595 I40E_PTT(2, L2, NONE, NOF, NONE, NONE, NOF, TS, PAY2),
596 I40E_PTT(3, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
597 I40E_PTT_UNUSED_ENTRY(4),
598 I40E_PTT_UNUSED_ENTRY(5),
599 I40E_PTT(6, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
600 I40E_PTT(7, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
601 I40E_PTT_UNUSED_ENTRY(8),
602 I40E_PTT_UNUSED_ENTRY(9),
603 I40E_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
604 I40E_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
605 I40E_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
606 I40E_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
607 I40E_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
608 I40E_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
609 I40E_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
610 I40E_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
611 I40E_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
612 I40E_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
613 I40E_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
614 I40E_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
615
616 /* Non Tunneled IPv4 */
617 I40E_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
618 I40E_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
619 I40E_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP, PAY4),
620 I40E_PTT_UNUSED_ENTRY(25),
621 I40E_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP, PAY4),
622 I40E_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
623 I40E_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
624
625 /* IPv4 --> IPv4 */
626 I40E_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
627 I40E_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
628 I40E_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
629 I40E_PTT_UNUSED_ENTRY(32),
630 I40E_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
631 I40E_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
632 I40E_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
633
634 /* IPv4 --> IPv6 */
635 I40E_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
636 I40E_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
637 I40E_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
638 I40E_PTT_UNUSED_ENTRY(39),
639 I40E_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
640 I40E_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
641 I40E_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
642
643 /* IPv4 --> GRE/NAT */
644 I40E_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
645
646 /* IPv4 --> GRE/NAT --> IPv4 */
647 I40E_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
648 I40E_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
649 I40E_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
650 I40E_PTT_UNUSED_ENTRY(47),
651 I40E_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
652 I40E_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
653 I40E_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
654
655 /* IPv4 --> GRE/NAT --> IPv6 */
656 I40E_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
657 I40E_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
658 I40E_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
659 I40E_PTT_UNUSED_ENTRY(54),
660 I40E_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
661 I40E_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
662 I40E_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
663
664 /* IPv4 --> GRE/NAT --> MAC */
665 I40E_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
666
667 /* IPv4 --> GRE/NAT --> MAC --> IPv4 */
668 I40E_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
669 I40E_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
670 I40E_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
671 I40E_PTT_UNUSED_ENTRY(62),
672 I40E_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
673 I40E_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
674 I40E_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
675
676 /* IPv4 --> GRE/NAT -> MAC --> IPv6 */
677 I40E_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
678 I40E_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
679 I40E_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
680 I40E_PTT_UNUSED_ENTRY(69),
681 I40E_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
682 I40E_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
683 I40E_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
684
685 /* IPv4 --> GRE/NAT --> MAC/VLAN */
686 I40E_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
687
688 /* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
689 I40E_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
690 I40E_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
691 I40E_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
692 I40E_PTT_UNUSED_ENTRY(77),
693 I40E_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
694 I40E_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
695 I40E_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
696
697 /* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
698 I40E_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
699 I40E_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
700 I40E_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
701 I40E_PTT_UNUSED_ENTRY(84),
702 I40E_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
703 I40E_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
704 I40E_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
705
706 /* Non Tunneled IPv6 */
707 I40E_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
708 I40E_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
Akeem G Abodunrin73df8c92016-05-03 15:13:16 -0700709 I40E_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP, PAY4),
Jesse Brandeburg206812b2014-02-12 01:45:33 +0000710 I40E_PTT_UNUSED_ENTRY(91),
711 I40E_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP, PAY4),
712 I40E_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
713 I40E_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
714
715 /* IPv6 --> IPv4 */
716 I40E_PTT(95, IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
717 I40E_PTT(96, IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
718 I40E_PTT(97, IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
719 I40E_PTT_UNUSED_ENTRY(98),
720 I40E_PTT(99, IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
721 I40E_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
722 I40E_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
723
724 /* IPv6 --> IPv6 */
725 I40E_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
726 I40E_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
727 I40E_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
728 I40E_PTT_UNUSED_ENTRY(105),
729 I40E_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
730 I40E_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
731 I40E_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
732
733 /* IPv6 --> GRE/NAT */
734 I40E_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
735
736 /* IPv6 --> GRE/NAT -> IPv4 */
737 I40E_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
738 I40E_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
739 I40E_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
740 I40E_PTT_UNUSED_ENTRY(113),
741 I40E_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
742 I40E_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
743 I40E_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
744
745 /* IPv6 --> GRE/NAT -> IPv6 */
746 I40E_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
747 I40E_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
748 I40E_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
749 I40E_PTT_UNUSED_ENTRY(120),
750 I40E_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
751 I40E_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
752 I40E_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
753
754 /* IPv6 --> GRE/NAT -> MAC */
755 I40E_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
756
757 /* IPv6 --> GRE/NAT -> MAC -> IPv4 */
758 I40E_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
759 I40E_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
760 I40E_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
761 I40E_PTT_UNUSED_ENTRY(128),
762 I40E_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
763 I40E_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
764 I40E_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
765
766 /* IPv6 --> GRE/NAT -> MAC -> IPv6 */
767 I40E_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
768 I40E_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
769 I40E_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
770 I40E_PTT_UNUSED_ENTRY(135),
771 I40E_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
772 I40E_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
773 I40E_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
774
775 /* IPv6 --> GRE/NAT -> MAC/VLAN */
776 I40E_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
777
778 /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
779 I40E_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
780 I40E_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
781 I40E_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
782 I40E_PTT_UNUSED_ENTRY(143),
783 I40E_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
784 I40E_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
785 I40E_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
786
787 /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
788 I40E_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
789 I40E_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
790 I40E_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
791 I40E_PTT_UNUSED_ENTRY(150),
792 I40E_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
793 I40E_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
794 I40E_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
795
796 /* unused entries */
797 I40E_PTT_UNUSED_ENTRY(154),
798 I40E_PTT_UNUSED_ENTRY(155),
799 I40E_PTT_UNUSED_ENTRY(156),
800 I40E_PTT_UNUSED_ENTRY(157),
801 I40E_PTT_UNUSED_ENTRY(158),
802 I40E_PTT_UNUSED_ENTRY(159),
803
804 I40E_PTT_UNUSED_ENTRY(160),
805 I40E_PTT_UNUSED_ENTRY(161),
806 I40E_PTT_UNUSED_ENTRY(162),
807 I40E_PTT_UNUSED_ENTRY(163),
808 I40E_PTT_UNUSED_ENTRY(164),
809 I40E_PTT_UNUSED_ENTRY(165),
810 I40E_PTT_UNUSED_ENTRY(166),
811 I40E_PTT_UNUSED_ENTRY(167),
812 I40E_PTT_UNUSED_ENTRY(168),
813 I40E_PTT_UNUSED_ENTRY(169),
814
815 I40E_PTT_UNUSED_ENTRY(170),
816 I40E_PTT_UNUSED_ENTRY(171),
817 I40E_PTT_UNUSED_ENTRY(172),
818 I40E_PTT_UNUSED_ENTRY(173),
819 I40E_PTT_UNUSED_ENTRY(174),
820 I40E_PTT_UNUSED_ENTRY(175),
821 I40E_PTT_UNUSED_ENTRY(176),
822 I40E_PTT_UNUSED_ENTRY(177),
823 I40E_PTT_UNUSED_ENTRY(178),
824 I40E_PTT_UNUSED_ENTRY(179),
825
826 I40E_PTT_UNUSED_ENTRY(180),
827 I40E_PTT_UNUSED_ENTRY(181),
828 I40E_PTT_UNUSED_ENTRY(182),
829 I40E_PTT_UNUSED_ENTRY(183),
830 I40E_PTT_UNUSED_ENTRY(184),
831 I40E_PTT_UNUSED_ENTRY(185),
832 I40E_PTT_UNUSED_ENTRY(186),
833 I40E_PTT_UNUSED_ENTRY(187),
834 I40E_PTT_UNUSED_ENTRY(188),
835 I40E_PTT_UNUSED_ENTRY(189),
836
837 I40E_PTT_UNUSED_ENTRY(190),
838 I40E_PTT_UNUSED_ENTRY(191),
839 I40E_PTT_UNUSED_ENTRY(192),
840 I40E_PTT_UNUSED_ENTRY(193),
841 I40E_PTT_UNUSED_ENTRY(194),
842 I40E_PTT_UNUSED_ENTRY(195),
843 I40E_PTT_UNUSED_ENTRY(196),
844 I40E_PTT_UNUSED_ENTRY(197),
845 I40E_PTT_UNUSED_ENTRY(198),
846 I40E_PTT_UNUSED_ENTRY(199),
847
848 I40E_PTT_UNUSED_ENTRY(200),
849 I40E_PTT_UNUSED_ENTRY(201),
850 I40E_PTT_UNUSED_ENTRY(202),
851 I40E_PTT_UNUSED_ENTRY(203),
852 I40E_PTT_UNUSED_ENTRY(204),
853 I40E_PTT_UNUSED_ENTRY(205),
854 I40E_PTT_UNUSED_ENTRY(206),
855 I40E_PTT_UNUSED_ENTRY(207),
856 I40E_PTT_UNUSED_ENTRY(208),
857 I40E_PTT_UNUSED_ENTRY(209),
858
859 I40E_PTT_UNUSED_ENTRY(210),
860 I40E_PTT_UNUSED_ENTRY(211),
861 I40E_PTT_UNUSED_ENTRY(212),
862 I40E_PTT_UNUSED_ENTRY(213),
863 I40E_PTT_UNUSED_ENTRY(214),
864 I40E_PTT_UNUSED_ENTRY(215),
865 I40E_PTT_UNUSED_ENTRY(216),
866 I40E_PTT_UNUSED_ENTRY(217),
867 I40E_PTT_UNUSED_ENTRY(218),
868 I40E_PTT_UNUSED_ENTRY(219),
869
870 I40E_PTT_UNUSED_ENTRY(220),
871 I40E_PTT_UNUSED_ENTRY(221),
872 I40E_PTT_UNUSED_ENTRY(222),
873 I40E_PTT_UNUSED_ENTRY(223),
874 I40E_PTT_UNUSED_ENTRY(224),
875 I40E_PTT_UNUSED_ENTRY(225),
876 I40E_PTT_UNUSED_ENTRY(226),
877 I40E_PTT_UNUSED_ENTRY(227),
878 I40E_PTT_UNUSED_ENTRY(228),
879 I40E_PTT_UNUSED_ENTRY(229),
880
881 I40E_PTT_UNUSED_ENTRY(230),
882 I40E_PTT_UNUSED_ENTRY(231),
883 I40E_PTT_UNUSED_ENTRY(232),
884 I40E_PTT_UNUSED_ENTRY(233),
885 I40E_PTT_UNUSED_ENTRY(234),
886 I40E_PTT_UNUSED_ENTRY(235),
887 I40E_PTT_UNUSED_ENTRY(236),
888 I40E_PTT_UNUSED_ENTRY(237),
889 I40E_PTT_UNUSED_ENTRY(238),
890 I40E_PTT_UNUSED_ENTRY(239),
891
892 I40E_PTT_UNUSED_ENTRY(240),
893 I40E_PTT_UNUSED_ENTRY(241),
894 I40E_PTT_UNUSED_ENTRY(242),
895 I40E_PTT_UNUSED_ENTRY(243),
896 I40E_PTT_UNUSED_ENTRY(244),
897 I40E_PTT_UNUSED_ENTRY(245),
898 I40E_PTT_UNUSED_ENTRY(246),
899 I40E_PTT_UNUSED_ENTRY(247),
900 I40E_PTT_UNUSED_ENTRY(248),
901 I40E_PTT_UNUSED_ENTRY(249),
902
903 I40E_PTT_UNUSED_ENTRY(250),
904 I40E_PTT_UNUSED_ENTRY(251),
905 I40E_PTT_UNUSED_ENTRY(252),
906 I40E_PTT_UNUSED_ENTRY(253),
907 I40E_PTT_UNUSED_ENTRY(254),
908 I40E_PTT_UNUSED_ENTRY(255)
909};
910
Anjali Singhai Jaine1860d82013-11-28 06:39:45 +0000911/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000912 * i40e_init_shared_code - Initialize the shared code
913 * @hw: pointer to hardware structure
914 *
915 * This assigns the MAC type and PHY code and inits the NVM.
916 * Does not touch the hardware. This function must be called prior to any
917 * other function in the shared code. The i40e_hw structure should be
918 * memset to 0 prior to calling this function. The following fields in
919 * hw structure should be filled in prior to calling this function:
920 * hw_addr, back, device_id, vendor_id, subsystem_device_id,
921 * subsystem_vendor_id, and revision_id
922 **/
923i40e_status i40e_init_shared_code(struct i40e_hw *hw)
924{
925 i40e_status status = 0;
Shannon Nelson5fb11d72014-11-13 03:06:19 +0000926 u32 port, ari, func_rid;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000927
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000928 i40e_set_mac_type(hw);
929
930 switch (hw->mac.type) {
931 case I40E_MAC_XL710:
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -0400932 case I40E_MAC_X722:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000933 break;
934 default:
935 return I40E_ERR_DEVICE_NOT_SUPPORTED;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000936 }
937
Shannon Nelsonaf89d26c2013-12-11 08:17:14 +0000938 hw->phy.get_link_info = true;
939
Shannon Nelson5fb11d72014-11-13 03:06:19 +0000940 /* Determine port number and PF number*/
941 port = (rd32(hw, I40E_PFGEN_PORTNUM) & I40E_PFGEN_PORTNUM_PORT_NUM_MASK)
942 >> I40E_PFGEN_PORTNUM_PORT_NUM_SHIFT;
943 hw->port = (u8)port;
944 ari = (rd32(hw, I40E_GLPCI_CAPSUP) & I40E_GLPCI_CAPSUP_ARI_EN_MASK) >>
945 I40E_GLPCI_CAPSUP_ARI_EN_SHIFT;
946 func_rid = rd32(hw, I40E_PF_FUNC_RID);
947 if (ari)
948 hw->pf_id = (u8)(func_rid & 0xff);
Shannon Nelson5f9116a2013-12-11 08:17:13 +0000949 else
Shannon Nelson5fb11d72014-11-13 03:06:19 +0000950 hw->pf_id = (u8)(func_rid & 0x7);
Shannon Nelson5f9116a2013-12-11 08:17:13 +0000951
Anjali Singhai07f89be2015-09-24 15:26:32 -0700952 if (hw->mac.type == I40E_MAC_X722)
Jacob Keller3d72aeb2017-10-27 11:06:55 -0400953 hw->flags |= I40E_HW_FLAG_AQ_SRCTL_ACCESS_ENABLE |
954 I40E_HW_FLAG_NVM_READ_REQUIRES_LOCK;
Anjali Singhai07f89be2015-09-24 15:26:32 -0700955
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000956 status = i40e_init_nvm(hw);
957 return status;
958}
959
960/**
961 * i40e_aq_mac_address_read - Retrieve the MAC addresses
962 * @hw: pointer to the hw struct
963 * @flags: a return indicator of what addresses were added to the addr store
964 * @addrs: the requestor's mac addr store
965 * @cmd_details: pointer to command details structure or NULL
966 **/
967static i40e_status i40e_aq_mac_address_read(struct i40e_hw *hw,
968 u16 *flags,
969 struct i40e_aqc_mac_address_read_data *addrs,
970 struct i40e_asq_cmd_details *cmd_details)
971{
972 struct i40e_aq_desc desc;
973 struct i40e_aqc_mac_address_read *cmd_data =
974 (struct i40e_aqc_mac_address_read *)&desc.params.raw;
975 i40e_status status;
976
977 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_mac_address_read);
978 desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF);
979
980 status = i40e_asq_send_command(hw, &desc, addrs,
981 sizeof(*addrs), cmd_details);
982 *flags = le16_to_cpu(cmd_data->command_flags);
983
984 return status;
985}
986
987/**
988 * i40e_aq_mac_address_write - Change the MAC addresses
989 * @hw: pointer to the hw struct
990 * @flags: indicates which MAC to be written
991 * @mac_addr: address to write
992 * @cmd_details: pointer to command details structure or NULL
993 **/
994i40e_status i40e_aq_mac_address_write(struct i40e_hw *hw,
995 u16 flags, u8 *mac_addr,
996 struct i40e_asq_cmd_details *cmd_details)
997{
998 struct i40e_aq_desc desc;
999 struct i40e_aqc_mac_address_write *cmd_data =
1000 (struct i40e_aqc_mac_address_write *)&desc.params.raw;
1001 i40e_status status;
1002
1003 i40e_fill_default_direct_cmd_desc(&desc,
1004 i40e_aqc_opc_mac_address_write);
1005 cmd_data->command_flags = cpu_to_le16(flags);
Kamil Krawczyk55c29c32013-12-18 13:45:52 +00001006 cmd_data->mac_sah = cpu_to_le16((u16)mac_addr[0] << 8 | mac_addr[1]);
1007 cmd_data->mac_sal = cpu_to_le32(((u32)mac_addr[2] << 24) |
1008 ((u32)mac_addr[3] << 16) |
1009 ((u32)mac_addr[4] << 8) |
1010 mac_addr[5]);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001011
1012 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1013
1014 return status;
1015}
1016
1017/**
1018 * i40e_get_mac_addr - get MAC address
1019 * @hw: pointer to the HW structure
1020 * @mac_addr: pointer to MAC address
1021 *
1022 * Reads the adapter's MAC address from register
1023 **/
1024i40e_status i40e_get_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
1025{
1026 struct i40e_aqc_mac_address_read_data addrs;
1027 i40e_status status;
1028 u16 flags = 0;
1029
1030 status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
1031
1032 if (flags & I40E_AQC_LAN_ADDR_VALID)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001033 ether_addr_copy(mac_addr, addrs.pf_lan_mac);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001034
1035 return status;
1036}
1037
1038/**
Neerav Parikh1f224ad2014-02-12 01:45:31 +00001039 * i40e_get_port_mac_addr - get Port MAC address
1040 * @hw: pointer to the HW structure
1041 * @mac_addr: pointer to Port MAC address
1042 *
1043 * Reads the adapter's Port MAC address
1044 **/
1045i40e_status i40e_get_port_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
1046{
1047 struct i40e_aqc_mac_address_read_data addrs;
1048 i40e_status status;
1049 u16 flags = 0;
1050
1051 status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
1052 if (status)
1053 return status;
1054
1055 if (flags & I40E_AQC_PORT_ADDR_VALID)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001056 ether_addr_copy(mac_addr, addrs.port_mac);
Neerav Parikh1f224ad2014-02-12 01:45:31 +00001057 else
1058 status = I40E_ERR_INVALID_MAC_ADDR;
1059
1060 return status;
1061}
1062
1063/**
Matt Jared351499ab2014-04-23 04:50:03 +00001064 * i40e_pre_tx_queue_cfg - pre tx queue configure
1065 * @hw: pointer to the HW structure
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00001066 * @queue: target PF queue index
Matt Jared351499ab2014-04-23 04:50:03 +00001067 * @enable: state change request
1068 *
1069 * Handles hw requirement to indicate intention to enable
1070 * or disable target queue.
1071 **/
1072void i40e_pre_tx_queue_cfg(struct i40e_hw *hw, u32 queue, bool enable)
1073{
Shannon Nelsondfb699f2014-05-22 06:32:28 +00001074 u32 abs_queue_idx = hw->func_caps.base_queue + queue;
Matt Jared351499ab2014-04-23 04:50:03 +00001075 u32 reg_block = 0;
Shannon Nelsondfb699f2014-05-22 06:32:28 +00001076 u32 reg_val;
Matt Jared351499ab2014-04-23 04:50:03 +00001077
Christopher Pau24a768c2014-06-04 20:41:59 +00001078 if (abs_queue_idx >= 128) {
Matt Jared351499ab2014-04-23 04:50:03 +00001079 reg_block = abs_queue_idx / 128;
Christopher Pau24a768c2014-06-04 20:41:59 +00001080 abs_queue_idx %= 128;
1081 }
Matt Jared351499ab2014-04-23 04:50:03 +00001082
1083 reg_val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
1084 reg_val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
1085 reg_val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
1086
1087 if (enable)
1088 reg_val |= I40E_GLLAN_TXPRE_QDIS_CLEAR_QDIS_MASK;
1089 else
1090 reg_val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
1091
1092 wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), reg_val);
1093}
1094
1095/**
Kamil Krawczyk18f680c2014-12-11 07:06:31 +00001096 * i40e_read_pba_string - Reads part number string from EEPROM
1097 * @hw: pointer to hardware structure
1098 * @pba_num: stores the part number string from the EEPROM
1099 * @pba_num_size: part number string buffer length
1100 *
1101 * Reads the part number string from the EEPROM.
1102 **/
1103i40e_status i40e_read_pba_string(struct i40e_hw *hw, u8 *pba_num,
1104 u32 pba_num_size)
1105{
1106 i40e_status status = 0;
1107 u16 pba_word = 0;
1108 u16 pba_size = 0;
1109 u16 pba_ptr = 0;
1110 u16 i = 0;
1111
1112 status = i40e_read_nvm_word(hw, I40E_SR_PBA_FLAGS, &pba_word);
1113 if (status || (pba_word != 0xFAFA)) {
1114 hw_dbg(hw, "Failed to read PBA flags or flag is invalid.\n");
1115 return status;
1116 }
1117
1118 status = i40e_read_nvm_word(hw, I40E_SR_PBA_BLOCK_PTR, &pba_ptr);
1119 if (status) {
1120 hw_dbg(hw, "Failed to read PBA Block pointer.\n");
1121 return status;
1122 }
1123
1124 status = i40e_read_nvm_word(hw, pba_ptr, &pba_size);
1125 if (status) {
1126 hw_dbg(hw, "Failed to read PBA Block size.\n");
1127 return status;
1128 }
1129
1130 /* Subtract one to get PBA word count (PBA Size word is included in
1131 * total size)
1132 */
1133 pba_size--;
1134 if (pba_num_size < (((u32)pba_size * 2) + 1)) {
1135 hw_dbg(hw, "Buffer to small for PBA data.\n");
1136 return I40E_ERR_PARAM;
1137 }
1138
1139 for (i = 0; i < pba_size; i++) {
1140 status = i40e_read_nvm_word(hw, (pba_ptr + 1) + i, &pba_word);
1141 if (status) {
1142 hw_dbg(hw, "Failed to read PBA Block word %d.\n", i);
1143 return status;
1144 }
1145
1146 pba_num[(i * 2)] = (pba_word >> 8) & 0xFF;
1147 pba_num[(i * 2) + 1] = pba_word & 0xFF;
1148 }
1149 pba_num[(pba_size * 2)] = '\0';
1150
1151 return status;
1152}
1153
1154/**
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001155 * i40e_get_media_type - Gets media type
1156 * @hw: pointer to the hardware structure
1157 **/
1158static enum i40e_media_type i40e_get_media_type(struct i40e_hw *hw)
1159{
1160 enum i40e_media_type media;
1161
1162 switch (hw->phy.link_info.phy_type) {
1163 case I40E_PHY_TYPE_10GBASE_SR:
1164 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +00001165 case I40E_PHY_TYPE_1000BASE_SX:
1166 case I40E_PHY_TYPE_1000BASE_LX:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001167 case I40E_PHY_TYPE_40GBASE_SR4:
1168 case I40E_PHY_TYPE_40GBASE_LR4:
Carolyn Wyborny31232372016-11-21 13:03:48 -08001169 case I40E_PHY_TYPE_25GBASE_LR:
1170 case I40E_PHY_TYPE_25GBASE_SR:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001171 media = I40E_MEDIA_TYPE_FIBER;
1172 break;
1173 case I40E_PHY_TYPE_100BASE_TX:
1174 case I40E_PHY_TYPE_1000BASE_T:
1175 case I40E_PHY_TYPE_10GBASE_T:
1176 media = I40E_MEDIA_TYPE_BASET;
1177 break;
1178 case I40E_PHY_TYPE_10GBASE_CR1_CU:
1179 case I40E_PHY_TYPE_40GBASE_CR4_CU:
1180 case I40E_PHY_TYPE_10GBASE_CR1:
1181 case I40E_PHY_TYPE_40GBASE_CR4:
1182 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +00001183 case I40E_PHY_TYPE_40GBASE_AOC:
1184 case I40E_PHY_TYPE_10GBASE_AOC:
Carolyn Wyborny31232372016-11-21 13:03:48 -08001185 case I40E_PHY_TYPE_25GBASE_CR:
Sudheer Mogilappagari211b4c12017-10-05 14:53:39 -07001186 case I40E_PHY_TYPE_25GBASE_AOC:
1187 case I40E_PHY_TYPE_25GBASE_ACC:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001188 media = I40E_MEDIA_TYPE_DA;
1189 break;
1190 case I40E_PHY_TYPE_1000BASE_KX:
1191 case I40E_PHY_TYPE_10GBASE_KX4:
1192 case I40E_PHY_TYPE_10GBASE_KR:
1193 case I40E_PHY_TYPE_40GBASE_KR4:
Jesse Brandeburgae24b402015-03-27 00:12:09 -07001194 case I40E_PHY_TYPE_20GBASE_KR2:
Carolyn Wyborny31232372016-11-21 13:03:48 -08001195 case I40E_PHY_TYPE_25GBASE_KR:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001196 media = I40E_MEDIA_TYPE_BACKPLANE;
1197 break;
1198 case I40E_PHY_TYPE_SGMII:
1199 case I40E_PHY_TYPE_XAUI:
1200 case I40E_PHY_TYPE_XFI:
1201 case I40E_PHY_TYPE_XLAUI:
1202 case I40E_PHY_TYPE_XLPPI:
1203 default:
1204 media = I40E_MEDIA_TYPE_UNKNOWN;
1205 break;
1206 }
1207
1208 return media;
1209}
1210
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001211#define I40E_PF_RESET_WAIT_COUNT_A0 200
Akeem G Abodunrin8af580d2015-03-27 00:12:10 -07001212#define I40E_PF_RESET_WAIT_COUNT 200
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001213/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001214 * i40e_pf_reset - Reset the PF
1215 * @hw: pointer to the hardware structure
1216 *
1217 * Assuming someone else has triggered a global reset,
1218 * assure the global reset is complete and then reset the PF
1219 **/
1220i40e_status i40e_pf_reset(struct i40e_hw *hw)
1221{
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001222 u32 cnt = 0;
Shannon Nelson42794bd2013-12-11 08:17:10 +00001223 u32 cnt1 = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001224 u32 reg = 0;
1225 u32 grst_del;
1226
1227 /* Poll for Global Reset steady state in case of recent GRST.
1228 * The grst delay value is in 100ms units, and we'll wait a
1229 * couple counts longer to be sure we don't just miss the end.
1230 */
Shannon Nelsonde78fc52015-02-21 06:41:47 +00001231 grst_del = (rd32(hw, I40E_GLGEN_RSTCTL) &
1232 I40E_GLGEN_RSTCTL_GRSTDEL_MASK) >>
1233 I40E_GLGEN_RSTCTL_GRSTDEL_SHIFT;
Kevin Scott4d7cec02016-02-17 16:12:13 -08001234
1235 /* It can take upto 15 secs for GRST steady state.
1236 * Bump it to 16 secs max to be safe.
1237 */
1238 grst_del = grst_del * 20;
1239
1240 for (cnt = 0; cnt < grst_del; cnt++) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001241 reg = rd32(hw, I40E_GLGEN_RSTAT);
1242 if (!(reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK))
1243 break;
1244 msleep(100);
1245 }
1246 if (reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
1247 hw_dbg(hw, "Global reset polling failed to complete.\n");
1248 return I40E_ERR_RESET_FAILED;
1249 }
1250
Shannon Nelson42794bd2013-12-11 08:17:10 +00001251 /* Now Wait for the FW to be ready */
1252 for (cnt1 = 0; cnt1 < I40E_PF_RESET_WAIT_COUNT; cnt1++) {
1253 reg = rd32(hw, I40E_GLNVM_ULD);
1254 reg &= (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
1255 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK);
1256 if (reg == (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
1257 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK)) {
1258 hw_dbg(hw, "Core and Global modules ready %d\n", cnt1);
1259 break;
1260 }
1261 usleep_range(10000, 20000);
1262 }
1263 if (!(reg & (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
1264 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK))) {
1265 hw_dbg(hw, "wait for FW Reset complete timedout\n");
1266 hw_dbg(hw, "I40E_GLNVM_ULD = 0x%x\n", reg);
1267 return I40E_ERR_RESET_FAILED;
1268 }
1269
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001270 /* If there was a Global Reset in progress when we got here,
1271 * we don't need to do the PF Reset
1272 */
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001273 if (!cnt) {
Filip Sadowski94075bb2017-11-14 07:00:49 -05001274 u32 reg2 = 0;
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001275 if (hw->revision_id == 0)
1276 cnt = I40E_PF_RESET_WAIT_COUNT_A0;
1277 else
1278 cnt = I40E_PF_RESET_WAIT_COUNT;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001279 reg = rd32(hw, I40E_PFGEN_CTRL);
1280 wr32(hw, I40E_PFGEN_CTRL,
1281 (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001282 for (; cnt; cnt--) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001283 reg = rd32(hw, I40E_PFGEN_CTRL);
1284 if (!(reg & I40E_PFGEN_CTRL_PFSWR_MASK))
1285 break;
Filip Sadowski94075bb2017-11-14 07:00:49 -05001286 reg2 = rd32(hw, I40E_GLGEN_RSTAT);
1287 if (reg2 & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
1288 hw_dbg(hw, "Core reset upcoming. Skipping PF reset request.\n");
1289 hw_dbg(hw, "I40E_GLGEN_RSTAT = 0x%x\n", reg2);
1290 return I40E_ERR_NOT_READY;
1291 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001292 usleep_range(1000, 2000);
1293 }
1294 if (reg & I40E_PFGEN_CTRL_PFSWR_MASK) {
1295 hw_dbg(hw, "PF reset polling failed to complete.\n");
1296 return I40E_ERR_RESET_FAILED;
1297 }
1298 }
1299
1300 i40e_clear_pxe_mode(hw);
Shannon Nelson922680b2013-12-18 05:29:17 +00001301
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001302 return 0;
1303}
1304
1305/**
Shannon Nelson838d41d2014-06-04 20:41:27 +00001306 * i40e_clear_hw - clear out any left over hw state
1307 * @hw: pointer to the hw struct
1308 *
1309 * Clear queues and interrupts, typically called at init time,
1310 * but after the capabilities have been found so we know how many
1311 * queues and msix vectors have been allocated.
1312 **/
1313void i40e_clear_hw(struct i40e_hw *hw)
1314{
1315 u32 num_queues, base_queue;
1316 u32 num_pf_int;
1317 u32 num_vf_int;
1318 u32 num_vfs;
1319 u32 i, j;
1320 u32 val;
1321 u32 eol = 0x7ff;
1322
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00001323 /* get number of interrupts, queues, and VFs */
Shannon Nelson838d41d2014-06-04 20:41:27 +00001324 val = rd32(hw, I40E_GLPCI_CNF2);
1325 num_pf_int = (val & I40E_GLPCI_CNF2_MSI_X_PF_N_MASK) >>
1326 I40E_GLPCI_CNF2_MSI_X_PF_N_SHIFT;
1327 num_vf_int = (val & I40E_GLPCI_CNF2_MSI_X_VF_N_MASK) >>
1328 I40E_GLPCI_CNF2_MSI_X_VF_N_SHIFT;
1329
Shannon Nelson272cdaf22016-02-17 16:12:21 -08001330 val = rd32(hw, I40E_PFLAN_QALLOC);
Shannon Nelson838d41d2014-06-04 20:41:27 +00001331 base_queue = (val & I40E_PFLAN_QALLOC_FIRSTQ_MASK) >>
1332 I40E_PFLAN_QALLOC_FIRSTQ_SHIFT;
1333 j = (val & I40E_PFLAN_QALLOC_LASTQ_MASK) >>
1334 I40E_PFLAN_QALLOC_LASTQ_SHIFT;
1335 if (val & I40E_PFLAN_QALLOC_VALID_MASK)
1336 num_queues = (j - base_queue) + 1;
1337 else
1338 num_queues = 0;
1339
1340 val = rd32(hw, I40E_PF_VT_PFALLOC);
1341 i = (val & I40E_PF_VT_PFALLOC_FIRSTVF_MASK) >>
1342 I40E_PF_VT_PFALLOC_FIRSTVF_SHIFT;
1343 j = (val & I40E_PF_VT_PFALLOC_LASTVF_MASK) >>
1344 I40E_PF_VT_PFALLOC_LASTVF_SHIFT;
1345 if (val & I40E_PF_VT_PFALLOC_VALID_MASK)
1346 num_vfs = (j - i) + 1;
1347 else
1348 num_vfs = 0;
1349
1350 /* stop all the interrupts */
1351 wr32(hw, I40E_PFINT_ICR0_ENA, 0);
1352 val = 0x3 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT;
1353 for (i = 0; i < num_pf_int - 2; i++)
1354 wr32(hw, I40E_PFINT_DYN_CTLN(i), val);
1355
1356 /* Set the FIRSTQ_INDX field to 0x7FF in PFINT_LNKLSTx */
1357 val = eol << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
1358 wr32(hw, I40E_PFINT_LNKLST0, val);
1359 for (i = 0; i < num_pf_int - 2; i++)
1360 wr32(hw, I40E_PFINT_LNKLSTN(i), val);
1361 val = eol << I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT;
1362 for (i = 0; i < num_vfs; i++)
1363 wr32(hw, I40E_VPINT_LNKLST0(i), val);
1364 for (i = 0; i < num_vf_int - 2; i++)
1365 wr32(hw, I40E_VPINT_LNKLSTN(i), val);
1366
1367 /* warn the HW of the coming Tx disables */
1368 for (i = 0; i < num_queues; i++) {
1369 u32 abs_queue_idx = base_queue + i;
1370 u32 reg_block = 0;
1371
1372 if (abs_queue_idx >= 128) {
1373 reg_block = abs_queue_idx / 128;
1374 abs_queue_idx %= 128;
1375 }
1376
1377 val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
1378 val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
1379 val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
1380 val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
1381
1382 wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), val);
1383 }
1384 udelay(400);
1385
1386 /* stop all the queues */
1387 for (i = 0; i < num_queues; i++) {
1388 wr32(hw, I40E_QINT_TQCTL(i), 0);
1389 wr32(hw, I40E_QTX_ENA(i), 0);
1390 wr32(hw, I40E_QINT_RQCTL(i), 0);
1391 wr32(hw, I40E_QRX_ENA(i), 0);
1392 }
1393
1394 /* short wait for all queue disables to settle */
1395 udelay(50);
1396}
1397
1398/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001399 * i40e_clear_pxe_mode - clear pxe operations mode
1400 * @hw: pointer to the hw struct
1401 *
1402 * Make sure all PXE mode settings are cleared, including things
1403 * like descriptor fetch/write-back mode.
1404 **/
1405void i40e_clear_pxe_mode(struct i40e_hw *hw)
1406{
1407 u32 reg;
1408
Shannon Nelsonc9b9b0a2014-04-09 05:59:05 +00001409 if (i40e_check_asq_alive(hw))
1410 i40e_aq_clear_pxe_mode(hw, NULL);
1411
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001412 /* Clear single descriptor fetch/write-back mode */
1413 reg = rd32(hw, I40E_GLLAN_RCTL_0);
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001414
1415 if (hw->revision_id == 0) {
1416 /* As a work around clear PXE_MODE instead of setting it */
1417 wr32(hw, I40E_GLLAN_RCTL_0, (reg & (~I40E_GLLAN_RCTL_0_PXE_MODE_MASK)));
1418 } else {
1419 wr32(hw, I40E_GLLAN_RCTL_0, (reg | I40E_GLLAN_RCTL_0_PXE_MODE_MASK));
1420 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001421}
1422
1423/**
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001424 * i40e_led_is_mine - helper to find matching led
1425 * @hw: pointer to the hw struct
1426 * @idx: index into GPIO registers
1427 *
1428 * returns: 0 if no match, otherwise the value of the GPIO_CTL register
1429 */
1430static u32 i40e_led_is_mine(struct i40e_hw *hw, int idx)
1431{
1432 u32 gpio_val = 0;
1433 u32 port;
1434
1435 if (!hw->func_caps.led[idx])
1436 return 0;
1437
1438 gpio_val = rd32(hw, I40E_GLGEN_GPIO_CTL(idx));
1439 port = (gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_MASK) >>
1440 I40E_GLGEN_GPIO_CTL_PRT_NUM_SHIFT;
1441
1442 /* if PRT_NUM_NA is 1 then this LED is not port specific, OR
1443 * if it is not our port then ignore
1444 */
1445 if ((gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_NA_MASK) ||
1446 (port != hw->port))
1447 return 0;
1448
1449 return gpio_val;
1450}
1451
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001452#define I40E_COMBINED_ACTIVITY 0xA
1453#define I40E_FILTER_ACTIVITY 0xE
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001454#define I40E_LINK_ACTIVITY 0xC
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001455#define I40E_MAC_ACTIVITY 0xD
1456#define I40E_LED0 22
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001457
1458/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001459 * i40e_led_get - return current on/off mode
1460 * @hw: pointer to the hw struct
1461 *
1462 * The value returned is the 'mode' field as defined in the
1463 * GPIO register definitions: 0x0 = off, 0xf = on, and other
1464 * values are variations of possible behaviors relating to
1465 * blink, link, and wire.
1466 **/
1467u32 i40e_led_get(struct i40e_hw *hw)
1468{
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001469 u32 current_mode = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001470 u32 mode = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001471 int i;
1472
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001473 /* as per the documentation GPIO 22-29 are the LED
1474 * GPIO pins named LED0..LED7
1475 */
1476 for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
1477 u32 gpio_val = i40e_led_is_mine(hw, i);
1478
1479 if (!gpio_val)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001480 continue;
1481
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001482 /* ignore gpio LED src mode entries related to the activity
1483 * LEDs
1484 */
1485 current_mode = ((gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK)
1486 >> I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT);
1487 switch (current_mode) {
1488 case I40E_COMBINED_ACTIVITY:
1489 case I40E_FILTER_ACTIVITY:
1490 case I40E_MAC_ACTIVITY:
Michal Kuchtad95cd482017-12-18 05:17:03 -05001491 case I40E_LINK_ACTIVITY:
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001492 continue;
1493 default:
1494 break;
1495 }
1496
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001497 mode = (gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK) >>
1498 I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001499 break;
1500 }
1501
1502 return mode;
1503}
1504
1505/**
1506 * i40e_led_set - set new on/off mode
1507 * @hw: pointer to the hw struct
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001508 * @mode: 0=off, 0xf=on (else see manual for mode details)
1509 * @blink: true if the LED should blink when on, false if steady
1510 *
1511 * if this function is used to turn on the blink it should
1512 * be used to disable the blink when restoring the original state.
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001513 **/
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001514void i40e_led_set(struct i40e_hw *hw, u32 mode, bool blink)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001515{
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001516 u32 current_mode = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001517 int i;
1518
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001519 if (mode & 0xfffffff0)
1520 hw_dbg(hw, "invalid mode passed in %X\n", mode);
1521
1522 /* as per the documentation GPIO 22-29 are the LED
1523 * GPIO pins named LED0..LED7
1524 */
1525 for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
1526 u32 gpio_val = i40e_led_is_mine(hw, i);
1527
1528 if (!gpio_val)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001529 continue;
1530
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001531 /* ignore gpio LED src mode entries related to the activity
1532 * LEDs
1533 */
1534 current_mode = ((gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK)
1535 >> I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT);
1536 switch (current_mode) {
1537 case I40E_COMBINED_ACTIVITY:
1538 case I40E_FILTER_ACTIVITY:
1539 case I40E_MAC_ACTIVITY:
Michal Kuchtad95cd482017-12-18 05:17:03 -05001540 case I40E_LINK_ACTIVITY:
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001541 continue;
1542 default:
1543 break;
1544 }
1545
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001546 gpio_val &= ~I40E_GLGEN_GPIO_CTL_LED_MODE_MASK;
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001547 /* this & is a bit of paranoia, but serves as a range check */
1548 gpio_val |= ((mode << I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT) &
1549 I40E_GLGEN_GPIO_CTL_LED_MODE_MASK);
1550
Matt Jared9be00d62015-01-24 09:58:28 +00001551 if (blink)
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001552 gpio_val |= BIT(I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
Matt Jared9be00d62015-01-24 09:58:28 +00001553 else
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001554 gpio_val &= ~BIT(I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001555
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001556 wr32(hw, I40E_GLGEN_GPIO_CTL(i), gpio_val);
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001557 break;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001558 }
1559}
1560
1561/* Admin command wrappers */
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001562
1563/**
Catherine Sullivan8109e122014-06-04 08:45:24 +00001564 * i40e_aq_get_phy_capabilities
1565 * @hw: pointer to the hw struct
1566 * @abilities: structure for PHY capabilities to be filled
1567 * @qualified_modules: report Qualified Modules
1568 * @report_init: report init capabilities (active are default)
1569 * @cmd_details: pointer to command details structure or NULL
1570 *
1571 * Returns the various PHY abilities supported on the Port.
1572 **/
1573i40e_status i40e_aq_get_phy_capabilities(struct i40e_hw *hw,
1574 bool qualified_modules, bool report_init,
1575 struct i40e_aq_get_phy_abilities_resp *abilities,
1576 struct i40e_asq_cmd_details *cmd_details)
1577{
1578 struct i40e_aq_desc desc;
1579 i40e_status status;
1580 u16 abilities_size = sizeof(struct i40e_aq_get_phy_abilities_resp);
Jayaprakash Shanmugam49884102017-09-07 08:05:55 -04001581 u16 max_delay = I40E_MAX_PHY_TIMEOUT, total_delay = 0;
Catherine Sullivan8109e122014-06-04 08:45:24 +00001582
1583 if (!abilities)
1584 return I40E_ERR_PARAM;
1585
Jayaprakash Shanmugam49884102017-09-07 08:05:55 -04001586 do {
1587 i40e_fill_default_direct_cmd_desc(&desc,
1588 i40e_aqc_opc_get_phy_abilities);
Catherine Sullivan8109e122014-06-04 08:45:24 +00001589
Jayaprakash Shanmugam49884102017-09-07 08:05:55 -04001590 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
1591 if (abilities_size > I40E_AQ_LARGE_BUF)
1592 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
Catherine Sullivan8109e122014-06-04 08:45:24 +00001593
Jayaprakash Shanmugam49884102017-09-07 08:05:55 -04001594 if (qualified_modules)
1595 desc.params.external.param0 |=
Catherine Sullivan8109e122014-06-04 08:45:24 +00001596 cpu_to_le32(I40E_AQ_PHY_REPORT_QUALIFIED_MODULES);
1597
Jayaprakash Shanmugam49884102017-09-07 08:05:55 -04001598 if (report_init)
1599 desc.params.external.param0 |=
Catherine Sullivan8109e122014-06-04 08:45:24 +00001600 cpu_to_le32(I40E_AQ_PHY_REPORT_INITIAL_VALUES);
1601
Jayaprakash Shanmugam49884102017-09-07 08:05:55 -04001602 status = i40e_asq_send_command(hw, &desc, abilities,
1603 abilities_size, cmd_details);
Catherine Sullivan8109e122014-06-04 08:45:24 +00001604
Jayaprakash Shanmugam49884102017-09-07 08:05:55 -04001605 if (status)
1606 break;
1607
1608 if (hw->aq.asq_last_status == I40E_AQ_RC_EIO) {
1609 status = I40E_ERR_UNKNOWN_PHY;
1610 break;
1611 } else if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN) {
1612 usleep_range(1000, 2000);
1613 total_delay++;
1614 status = I40E_ERR_TIMEOUT;
1615 }
1616 } while ((hw->aq.asq_last_status != I40E_AQ_RC_OK) &&
1617 (total_delay < max_delay));
1618
1619 if (status)
1620 return status;
Catherine Sullivan8109e122014-06-04 08:45:24 +00001621
Carolyn Wyborny31232372016-11-21 13:03:48 -08001622 if (report_init) {
Mitch Williams22b965512017-07-14 09:27:09 -04001623 if (hw->mac.type == I40E_MAC_XL710 &&
1624 hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
Alan Brady8fdb69d2017-10-11 14:49:42 -07001625 hw->aq.api_min_ver >= I40E_MINOR_VER_GET_LINK_INFO_XL710) {
Mitch Williams22b965512017-07-14 09:27:09 -04001626 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
Alan Brady8fdb69d2017-10-11 14:49:42 -07001627 } else {
1628 hw->phy.phy_types = le32_to_cpu(abilities->phy_type);
1629 hw->phy.phy_types |=
1630 ((u64)abilities->phy_type_ext << 32);
1631 }
Carolyn Wyborny31232372016-11-21 13:03:48 -08001632 }
Kevin Scott3ac67d72015-09-03 17:18:58 -04001633
Catherine Sullivan8109e122014-06-04 08:45:24 +00001634 return status;
1635}
1636
1637/**
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001638 * i40e_aq_set_phy_config
1639 * @hw: pointer to the hw struct
1640 * @config: structure with PHY configuration to be set
1641 * @cmd_details: pointer to command details structure or NULL
1642 *
1643 * Set the various PHY configuration parameters
1644 * supported on the Port.One or more of the Set PHY config parameters may be
1645 * ignored in an MFP mode as the PF may not have the privilege to set some
1646 * of the PHY Config parameters. This status will be indicated by the
1647 * command response.
1648 **/
1649enum i40e_status_code i40e_aq_set_phy_config(struct i40e_hw *hw,
1650 struct i40e_aq_set_phy_config *config,
1651 struct i40e_asq_cmd_details *cmd_details)
1652{
1653 struct i40e_aq_desc desc;
1654 struct i40e_aq_set_phy_config *cmd =
1655 (struct i40e_aq_set_phy_config *)&desc.params.raw;
1656 enum i40e_status_code status;
1657
1658 if (!config)
1659 return I40E_ERR_PARAM;
1660
1661 i40e_fill_default_direct_cmd_desc(&desc,
1662 i40e_aqc_opc_set_phy_config);
1663
1664 *cmd = *config;
1665
1666 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1667
1668 return status;
1669}
1670
1671/**
1672 * i40e_set_fc
1673 * @hw: pointer to the hw struct
1674 *
1675 * Set the requested flow control mode using set_phy_config.
1676 **/
1677enum i40e_status_code i40e_set_fc(struct i40e_hw *hw, u8 *aq_failures,
1678 bool atomic_restart)
1679{
1680 enum i40e_fc_mode fc_mode = hw->fc.requested_mode;
1681 struct i40e_aq_get_phy_abilities_resp abilities;
1682 struct i40e_aq_set_phy_config config;
1683 enum i40e_status_code status;
1684 u8 pause_mask = 0x0;
1685
1686 *aq_failures = 0x0;
1687
1688 switch (fc_mode) {
1689 case I40E_FC_FULL:
1690 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
1691 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
1692 break;
1693 case I40E_FC_RX_PAUSE:
1694 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
1695 break;
1696 case I40E_FC_TX_PAUSE:
1697 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
1698 break;
1699 default:
1700 break;
1701 }
1702
1703 /* Get the current phy config */
1704 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
1705 NULL);
1706 if (status) {
1707 *aq_failures |= I40E_SET_FC_AQ_FAIL_GET;
1708 return status;
1709 }
1710
1711 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
1712 /* clear the old pause settings */
1713 config.abilities = abilities.abilities & ~(I40E_AQ_PHY_FLAG_PAUSE_TX) &
1714 ~(I40E_AQ_PHY_FLAG_PAUSE_RX);
1715 /* set the new abilities */
1716 config.abilities |= pause_mask;
1717 /* If the abilities have changed, then set the new config */
1718 if (config.abilities != abilities.abilities) {
1719 /* Auto restart link so settings take effect */
1720 if (atomic_restart)
1721 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
1722 /* Copy over all the old settings */
1723 config.phy_type = abilities.phy_type;
Carolyn Wyborny31232372016-11-21 13:03:48 -08001724 config.phy_type_ext = abilities.phy_type_ext;
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001725 config.link_speed = abilities.link_speed;
1726 config.eee_capability = abilities.eee_capability;
1727 config.eeer = abilities.eeer_val;
1728 config.low_power_ctrl = abilities.d3_lpan;
Carolyn Wyborny60f000a2016-11-21 13:03:49 -08001729 config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
1730 I40E_AQ_PHY_FEC_CONFIG_MASK;
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001731 status = i40e_aq_set_phy_config(hw, &config, NULL);
1732
1733 if (status)
1734 *aq_failures |= I40E_SET_FC_AQ_FAIL_SET;
1735 }
1736 /* Update the link info */
Catherine Sullivan0a862b42015-08-31 19:54:53 -04001737 status = i40e_update_link_info(hw);
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001738 if (status) {
1739 /* Wait a little bit (on 40G cards it sometimes takes a really
1740 * long time for link to come back from the atomic reset)
1741 * and try once more
1742 */
1743 msleep(1000);
Catherine Sullivan0a862b42015-08-31 19:54:53 -04001744 status = i40e_update_link_info(hw);
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001745 }
1746 if (status)
1747 *aq_failures |= I40E_SET_FC_AQ_FAIL_UPDATE;
1748
1749 return status;
1750}
1751
1752/**
Shannon Nelsonc9b9b0a2014-04-09 05:59:05 +00001753 * i40e_aq_clear_pxe_mode
1754 * @hw: pointer to the hw struct
1755 * @cmd_details: pointer to command details structure or NULL
1756 *
1757 * Tell the firmware that the driver is taking over from PXE
1758 **/
1759i40e_status i40e_aq_clear_pxe_mode(struct i40e_hw *hw,
1760 struct i40e_asq_cmd_details *cmd_details)
1761{
1762 i40e_status status;
1763 struct i40e_aq_desc desc;
1764 struct i40e_aqc_clear_pxe *cmd =
1765 (struct i40e_aqc_clear_pxe *)&desc.params.raw;
1766
1767 i40e_fill_default_direct_cmd_desc(&desc,
1768 i40e_aqc_opc_clear_pxe_mode);
1769
1770 cmd->rx_cnt = 0x2;
1771
1772 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1773
1774 wr32(hw, I40E_GLLAN_RCTL_0, 0x1);
1775
1776 return status;
1777}
1778
1779/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001780 * i40e_aq_set_link_restart_an
1781 * @hw: pointer to the hw struct
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001782 * @enable_link: if true: enable link, if false: disable link
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001783 * @cmd_details: pointer to command details structure or NULL
1784 *
1785 * Sets up the link and restarts the Auto-Negotiation over the link.
1786 **/
1787i40e_status i40e_aq_set_link_restart_an(struct i40e_hw *hw,
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001788 bool enable_link,
1789 struct i40e_asq_cmd_details *cmd_details)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001790{
1791 struct i40e_aq_desc desc;
1792 struct i40e_aqc_set_link_restart_an *cmd =
1793 (struct i40e_aqc_set_link_restart_an *)&desc.params.raw;
1794 i40e_status status;
1795
1796 i40e_fill_default_direct_cmd_desc(&desc,
1797 i40e_aqc_opc_set_link_restart_an);
1798
1799 cmd->command = I40E_AQ_PHY_RESTART_AN;
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001800 if (enable_link)
1801 cmd->command |= I40E_AQ_PHY_LINK_ENABLE;
1802 else
1803 cmd->command &= ~I40E_AQ_PHY_LINK_ENABLE;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001804
1805 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1806
1807 return status;
1808}
1809
1810/**
1811 * i40e_aq_get_link_info
1812 * @hw: pointer to the hw struct
1813 * @enable_lse: enable/disable LinkStatusEvent reporting
1814 * @link: pointer to link status structure - optional
1815 * @cmd_details: pointer to command details structure or NULL
1816 *
1817 * Returns the link status of the adapter.
1818 **/
1819i40e_status i40e_aq_get_link_info(struct i40e_hw *hw,
1820 bool enable_lse, struct i40e_link_status *link,
1821 struct i40e_asq_cmd_details *cmd_details)
1822{
1823 struct i40e_aq_desc desc;
1824 struct i40e_aqc_get_link_status *resp =
1825 (struct i40e_aqc_get_link_status *)&desc.params.raw;
1826 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
1827 i40e_status status;
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001828 bool tx_pause, rx_pause;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001829 u16 command_flags;
1830
1831 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_link_status);
1832
1833 if (enable_lse)
1834 command_flags = I40E_AQ_LSE_ENABLE;
1835 else
1836 command_flags = I40E_AQ_LSE_DISABLE;
1837 resp->command_flags = cpu_to_le16(command_flags);
1838
1839 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1840
1841 if (status)
1842 goto aq_get_link_info_exit;
1843
1844 /* save off old link status information */
Mitch Williamsc36bd4a72013-12-18 13:46:04 +00001845 hw->phy.link_info_old = *hw_link_info;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001846
1847 /* update link status */
1848 hw_link_info->phy_type = (enum i40e_aq_phy_type)resp->phy_type;
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001849 hw->phy.media_type = i40e_get_media_type(hw);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001850 hw_link_info->link_speed = (enum i40e_aq_link_speed)resp->link_speed;
1851 hw_link_info->link_info = resp->link_info;
1852 hw_link_info->an_info = resp->an_info;
Henry Tieman3e03d7c2016-12-02 12:32:57 -08001853 hw_link_info->fec_info = resp->config & (I40E_AQ_CONFIG_FEC_KR_ENA |
1854 I40E_AQ_CONFIG_FEC_RS_ENA);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001855 hw_link_info->ext_info = resp->ext_info;
Filip Sadowskid60bcc72017-08-22 06:57:43 -04001856 hw_link_info->loopback = resp->loopback & I40E_AQ_LOOPBACK_MASK;
Neerav Parikh6bb3f232014-04-01 07:11:56 +00001857 hw_link_info->max_frame_size = le16_to_cpu(resp->max_frame_size);
1858 hw_link_info->pacing = resp->config & I40E_AQ_CONFIG_PACING_MASK;
1859
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001860 /* update fc info */
1861 tx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_TX);
1862 rx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_RX);
1863 if (tx_pause & rx_pause)
1864 hw->fc.current_mode = I40E_FC_FULL;
1865 else if (tx_pause)
1866 hw->fc.current_mode = I40E_FC_TX_PAUSE;
1867 else if (rx_pause)
1868 hw->fc.current_mode = I40E_FC_RX_PAUSE;
1869 else
1870 hw->fc.current_mode = I40E_FC_NONE;
1871
Neerav Parikh6bb3f232014-04-01 07:11:56 +00001872 if (resp->config & I40E_AQ_CONFIG_CRC_ENA)
1873 hw_link_info->crc_enable = true;
1874 else
1875 hw_link_info->crc_enable = false;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001876
Filip Sadowski7ed35732016-09-14 16:24:33 -07001877 if (resp->command_flags & cpu_to_le16(I40E_AQ_LSE_IS_ENABLED))
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001878 hw_link_info->lse_enable = true;
1879 else
1880 hw_link_info->lse_enable = false;
1881
Henry Tiemane586bb62016-11-08 13:05:07 -08001882 if ((hw->mac.type == I40E_MAC_XL710) &&
1883 (hw->aq.fw_maj_ver < 4 || (hw->aq.fw_maj_ver == 4 &&
Catherine Sullivan088c4ee2015-02-26 16:14:12 +00001884 hw->aq.fw_min_ver < 40)) && hw_link_info->phy_type == 0xE)
1885 hw_link_info->phy_type = I40E_PHY_TYPE_10GBASE_SFPP_CU;
1886
Filip Sadowskid60bcc72017-08-22 06:57:43 -04001887 if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
1888 hw->aq.api_min_ver >= 7) {
1889 __le32 tmp;
1890
1891 memcpy(&tmp, resp->link_type, sizeof(tmp));
1892 hw->phy.phy_types = le32_to_cpu(tmp);
1893 hw->phy.phy_types |= ((u64)resp->link_type_ext << 32);
1894 }
1895
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001896 /* save link status information */
1897 if (link)
Jesse Brandeburgd7595a22013-09-13 08:23:22 +00001898 *link = *hw_link_info;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001899
1900 /* flag cleared so helper functions don't call AQ again */
1901 hw->phy.get_link_info = false;
1902
1903aq_get_link_info_exit:
1904 return status;
1905}
1906
1907/**
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00001908 * i40e_aq_set_phy_int_mask
1909 * @hw: pointer to the hw struct
1910 * @mask: interrupt mask to be set
1911 * @cmd_details: pointer to command details structure or NULL
1912 *
1913 * Set link interrupt mask.
1914 **/
1915i40e_status i40e_aq_set_phy_int_mask(struct i40e_hw *hw,
1916 u16 mask,
1917 struct i40e_asq_cmd_details *cmd_details)
1918{
1919 struct i40e_aq_desc desc;
1920 struct i40e_aqc_set_phy_int_mask *cmd =
1921 (struct i40e_aqc_set_phy_int_mask *)&desc.params.raw;
1922 i40e_status status;
1923
1924 i40e_fill_default_direct_cmd_desc(&desc,
1925 i40e_aqc_opc_set_phy_int_mask);
1926
1927 cmd->event_mask = cpu_to_le16(mask);
1928
1929 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1930
1931 return status;
1932}
1933
1934/**
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001935 * i40e_aq_set_phy_debug
1936 * @hw: pointer to the hw struct
1937 * @cmd_flags: debug command flags
1938 * @cmd_details: pointer to command details structure or NULL
1939 *
1940 * Reset the external PHY.
1941 **/
Jesse Brandeburg61829022016-03-10 14:59:42 -08001942i40e_status i40e_aq_set_phy_debug(struct i40e_hw *hw, u8 cmd_flags,
1943 struct i40e_asq_cmd_details *cmd_details)
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001944{
1945 struct i40e_aq_desc desc;
1946 struct i40e_aqc_set_phy_debug *cmd =
1947 (struct i40e_aqc_set_phy_debug *)&desc.params.raw;
Jesse Brandeburg61829022016-03-10 14:59:42 -08001948 i40e_status status;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001949
1950 i40e_fill_default_direct_cmd_desc(&desc,
1951 i40e_aqc_opc_set_phy_debug);
1952
1953 cmd->command_flags = cmd_flags;
1954
1955 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1956
1957 return status;
1958}
1959
1960/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001961 * i40e_aq_add_vsi
1962 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00001963 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001964 * @cmd_details: pointer to command details structure or NULL
1965 *
1966 * Add a VSI context to the hardware.
1967**/
1968i40e_status i40e_aq_add_vsi(struct i40e_hw *hw,
1969 struct i40e_vsi_context *vsi_ctx,
1970 struct i40e_asq_cmd_details *cmd_details)
1971{
1972 struct i40e_aq_desc desc;
1973 struct i40e_aqc_add_get_update_vsi *cmd =
1974 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
1975 struct i40e_aqc_add_get_update_vsi_completion *resp =
1976 (struct i40e_aqc_add_get_update_vsi_completion *)
1977 &desc.params.raw;
1978 i40e_status status;
1979
1980 i40e_fill_default_direct_cmd_desc(&desc,
1981 i40e_aqc_opc_add_vsi);
1982
1983 cmd->uplink_seid = cpu_to_le16(vsi_ctx->uplink_seid);
1984 cmd->connection_type = vsi_ctx->connection_type;
1985 cmd->vf_id = vsi_ctx->vf_num;
1986 cmd->vsi_flags = cpu_to_le16(vsi_ctx->flags);
1987
1988 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001989
1990 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
1991 sizeof(vsi_ctx->info), cmd_details);
1992
1993 if (status)
1994 goto aq_add_vsi_exit;
1995
1996 vsi_ctx->seid = le16_to_cpu(resp->seid);
1997 vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
1998 vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
1999 vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
2000
2001aq_add_vsi_exit:
2002 return status;
2003}
2004
2005/**
Mitch Williamsfb70fab2016-05-16 10:26:31 -07002006 * i40e_aq_set_default_vsi
2007 * @hw: pointer to the hw struct
2008 * @seid: vsi number
2009 * @cmd_details: pointer to command details structure or NULL
2010 **/
2011i40e_status i40e_aq_set_default_vsi(struct i40e_hw *hw,
2012 u16 seid,
2013 struct i40e_asq_cmd_details *cmd_details)
2014{
2015 struct i40e_aq_desc desc;
2016 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2017 (struct i40e_aqc_set_vsi_promiscuous_modes *)
2018 &desc.params.raw;
2019 i40e_status status;
2020
2021 i40e_fill_default_direct_cmd_desc(&desc,
2022 i40e_aqc_opc_set_vsi_promiscuous_modes);
2023
2024 cmd->promiscuous_flags = cpu_to_le16(I40E_AQC_SET_VSI_DEFAULT);
2025 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_DEFAULT);
2026 cmd->seid = cpu_to_le16(seid);
2027
2028 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2029
2030 return status;
2031}
2032
2033/**
2034 * i40e_aq_clear_default_vsi
2035 * @hw: pointer to the hw struct
2036 * @seid: vsi number
2037 * @cmd_details: pointer to command details structure or NULL
2038 **/
2039i40e_status i40e_aq_clear_default_vsi(struct i40e_hw *hw,
2040 u16 seid,
2041 struct i40e_asq_cmd_details *cmd_details)
2042{
2043 struct i40e_aq_desc desc;
2044 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2045 (struct i40e_aqc_set_vsi_promiscuous_modes *)
2046 &desc.params.raw;
2047 i40e_status status;
2048
2049 i40e_fill_default_direct_cmd_desc(&desc,
2050 i40e_aqc_opc_set_vsi_promiscuous_modes);
2051
2052 cmd->promiscuous_flags = cpu_to_le16(0);
2053 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_DEFAULT);
2054 cmd->seid = cpu_to_le16(seid);
2055
2056 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2057
2058 return status;
2059}
2060
2061/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002062 * i40e_aq_set_vsi_unicast_promiscuous
2063 * @hw: pointer to the hw struct
2064 * @seid: vsi number
2065 * @set: set unicast promiscuous enable/disable
2066 * @cmd_details: pointer to command details structure or NULL
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002067 * @rx_only_promisc: flag to decide if egress traffic gets mirrored in promisc
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002068 **/
2069i40e_status i40e_aq_set_vsi_unicast_promiscuous(struct i40e_hw *hw,
Mitch Williams885552a2013-12-21 05:44:41 +00002070 u16 seid, bool set,
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002071 struct i40e_asq_cmd_details *cmd_details,
2072 bool rx_only_promisc)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002073{
2074 struct i40e_aq_desc desc;
2075 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2076 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2077 i40e_status status;
2078 u16 flags = 0;
2079
2080 i40e_fill_default_direct_cmd_desc(&desc,
2081 i40e_aqc_opc_set_vsi_promiscuous_modes);
2082
Anjali Singhai Jain3b120082016-01-15 14:33:21 -08002083 if (set) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002084 flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002085 if (rx_only_promisc &&
2086 (((hw->aq.api_maj_ver == 1) && (hw->aq.api_min_ver >= 5)) ||
2087 (hw->aq.api_maj_ver > 1)))
Anjali Singhai Jain3b120082016-01-15 14:33:21 -08002088 flags |= I40E_AQC_SET_VSI_PROMISC_TX;
2089 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002090
2091 cmd->promiscuous_flags = cpu_to_le16(flags);
2092
2093 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
Anjali Singhai Jain3b120082016-01-15 14:33:21 -08002094 if (((hw->aq.api_maj_ver >= 1) && (hw->aq.api_min_ver >= 5)) ||
2095 (hw->aq.api_maj_ver > 1))
2096 cmd->valid_flags |= cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_TX);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002097
2098 cmd->seid = cpu_to_le16(seid);
2099 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2100
2101 return status;
2102}
2103
2104/**
2105 * i40e_aq_set_vsi_multicast_promiscuous
2106 * @hw: pointer to the hw struct
2107 * @seid: vsi number
2108 * @set: set multicast promiscuous enable/disable
2109 * @cmd_details: pointer to command details structure or NULL
2110 **/
2111i40e_status i40e_aq_set_vsi_multicast_promiscuous(struct i40e_hw *hw,
2112 u16 seid, bool set, struct i40e_asq_cmd_details *cmd_details)
2113{
2114 struct i40e_aq_desc desc;
2115 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2116 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2117 i40e_status status;
2118 u16 flags = 0;
2119
2120 i40e_fill_default_direct_cmd_desc(&desc,
2121 i40e_aqc_opc_set_vsi_promiscuous_modes);
2122
2123 if (set)
2124 flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
2125
2126 cmd->promiscuous_flags = cpu_to_le16(flags);
2127
2128 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
2129
2130 cmd->seid = cpu_to_le16(seid);
2131 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2132
2133 return status;
2134}
2135
2136/**
Greg Rose6c41a762016-04-12 08:30:50 -07002137 * i40e_aq_set_vsi_mc_promisc_on_vlan
2138 * @hw: pointer to the hw struct
2139 * @seid: vsi number
2140 * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
2141 * @vid: The VLAN tag filter - capture any multicast packet with this VLAN tag
2142 * @cmd_details: pointer to command details structure or NULL
2143 **/
2144enum i40e_status_code i40e_aq_set_vsi_mc_promisc_on_vlan(struct i40e_hw *hw,
2145 u16 seid, bool enable,
2146 u16 vid,
2147 struct i40e_asq_cmd_details *cmd_details)
2148{
2149 struct i40e_aq_desc desc;
2150 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2151 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2152 enum i40e_status_code status;
2153 u16 flags = 0;
2154
2155 i40e_fill_default_direct_cmd_desc(&desc,
2156 i40e_aqc_opc_set_vsi_promiscuous_modes);
2157
2158 if (enable)
2159 flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
2160
2161 cmd->promiscuous_flags = cpu_to_le16(flags);
2162 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
2163 cmd->seid = cpu_to_le16(seid);
2164 cmd->vlan_tag = cpu_to_le16(vid | I40E_AQC_SET_VSI_VLAN_VALID);
2165
2166 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2167
2168 return status;
2169}
2170
2171/**
2172 * i40e_aq_set_vsi_uc_promisc_on_vlan
2173 * @hw: pointer to the hw struct
2174 * @seid: vsi number
2175 * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
2176 * @vid: The VLAN tag filter - capture any unicast packet with this VLAN tag
2177 * @cmd_details: pointer to command details structure or NULL
2178 **/
2179enum i40e_status_code i40e_aq_set_vsi_uc_promisc_on_vlan(struct i40e_hw *hw,
2180 u16 seid, bool enable,
2181 u16 vid,
2182 struct i40e_asq_cmd_details *cmd_details)
2183{
2184 struct i40e_aq_desc desc;
2185 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2186 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2187 enum i40e_status_code status;
2188 u16 flags = 0;
2189
2190 i40e_fill_default_direct_cmd_desc(&desc,
2191 i40e_aqc_opc_set_vsi_promiscuous_modes);
2192
2193 if (enable)
2194 flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
2195
2196 cmd->promiscuous_flags = cpu_to_le16(flags);
2197 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
2198 cmd->seid = cpu_to_le16(seid);
2199 cmd->vlan_tag = cpu_to_le16(vid | I40E_AQC_SET_VSI_VLAN_VALID);
2200
2201 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2202
2203 return status;
2204}
2205
2206/**
Jacob Keller435c0842016-11-08 13:05:10 -08002207 * i40e_aq_set_vsi_bc_promisc_on_vlan
2208 * @hw: pointer to the hw struct
2209 * @seid: vsi number
2210 * @enable: set broadcast promiscuous enable/disable for a given VLAN
2211 * @vid: The VLAN tag filter - capture any broadcast packet with this VLAN tag
2212 * @cmd_details: pointer to command details structure or NULL
2213 **/
2214i40e_status i40e_aq_set_vsi_bc_promisc_on_vlan(struct i40e_hw *hw,
2215 u16 seid, bool enable, u16 vid,
2216 struct i40e_asq_cmd_details *cmd_details)
2217{
2218 struct i40e_aq_desc desc;
2219 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2220 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2221 i40e_status status;
2222 u16 flags = 0;
2223
2224 i40e_fill_default_direct_cmd_desc(&desc,
2225 i40e_aqc_opc_set_vsi_promiscuous_modes);
2226
2227 if (enable)
2228 flags |= I40E_AQC_SET_VSI_PROMISC_BROADCAST;
2229
2230 cmd->promiscuous_flags = cpu_to_le16(flags);
2231 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2232 cmd->seid = cpu_to_le16(seid);
2233 cmd->vlan_tag = cpu_to_le16(vid | I40E_AQC_SET_VSI_VLAN_VALID);
2234
2235 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2236
2237 return status;
2238}
2239
2240/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002241 * i40e_aq_set_vsi_broadcast
2242 * @hw: pointer to the hw struct
2243 * @seid: vsi number
2244 * @set_filter: true to set filter, false to clear filter
2245 * @cmd_details: pointer to command details structure or NULL
2246 *
2247 * Set or clear the broadcast promiscuous flag (filter) for a given VSI.
2248 **/
2249i40e_status i40e_aq_set_vsi_broadcast(struct i40e_hw *hw,
2250 u16 seid, bool set_filter,
2251 struct i40e_asq_cmd_details *cmd_details)
2252{
2253 struct i40e_aq_desc desc;
2254 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2255 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2256 i40e_status status;
2257
2258 i40e_fill_default_direct_cmd_desc(&desc,
2259 i40e_aqc_opc_set_vsi_promiscuous_modes);
2260
2261 if (set_filter)
2262 cmd->promiscuous_flags
2263 |= cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2264 else
2265 cmd->promiscuous_flags
2266 &= cpu_to_le16(~I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2267
2268 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2269 cmd->seid = cpu_to_le16(seid);
2270 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2271
2272 return status;
2273}
2274
2275/**
Kiran Patil7bd68752016-01-04 10:33:07 -08002276 * i40e_aq_set_vsi_vlan_promisc - control the VLAN promiscuous setting
2277 * @hw: pointer to the hw struct
2278 * @seid: vsi number
2279 * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
2280 * @cmd_details: pointer to command details structure or NULL
2281 **/
2282i40e_status i40e_aq_set_vsi_vlan_promisc(struct i40e_hw *hw,
2283 u16 seid, bool enable,
2284 struct i40e_asq_cmd_details *cmd_details)
2285{
2286 struct i40e_aq_desc desc;
2287 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2288 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2289 i40e_status status;
2290 u16 flags = 0;
2291
2292 i40e_fill_default_direct_cmd_desc(&desc,
2293 i40e_aqc_opc_set_vsi_promiscuous_modes);
2294 if (enable)
2295 flags |= I40E_AQC_SET_VSI_PROMISC_VLAN;
2296
2297 cmd->promiscuous_flags = cpu_to_le16(flags);
2298 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_VLAN);
2299 cmd->seid = cpu_to_le16(seid);
2300
2301 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2302
2303 return status;
2304}
2305
2306/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002307 * i40e_get_vsi_params - get VSI configuration info
2308 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00002309 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002310 * @cmd_details: pointer to command details structure or NULL
2311 **/
2312i40e_status i40e_aq_get_vsi_params(struct i40e_hw *hw,
2313 struct i40e_vsi_context *vsi_ctx,
2314 struct i40e_asq_cmd_details *cmd_details)
2315{
2316 struct i40e_aq_desc desc;
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002317 struct i40e_aqc_add_get_update_vsi *cmd =
2318 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002319 struct i40e_aqc_add_get_update_vsi_completion *resp =
2320 (struct i40e_aqc_add_get_update_vsi_completion *)
2321 &desc.params.raw;
2322 i40e_status status;
2323
2324 i40e_fill_default_direct_cmd_desc(&desc,
2325 i40e_aqc_opc_get_vsi_parameters);
2326
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002327 cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002328
2329 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002330
2331 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
2332 sizeof(vsi_ctx->info), NULL);
2333
2334 if (status)
2335 goto aq_get_vsi_params_exit;
2336
2337 vsi_ctx->seid = le16_to_cpu(resp->seid);
2338 vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
2339 vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
2340 vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
2341
2342aq_get_vsi_params_exit:
2343 return status;
2344}
2345
2346/**
2347 * i40e_aq_update_vsi_params
2348 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00002349 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002350 * @cmd_details: pointer to command details structure or NULL
2351 *
2352 * Update a VSI context.
2353 **/
2354i40e_status i40e_aq_update_vsi_params(struct i40e_hw *hw,
2355 struct i40e_vsi_context *vsi_ctx,
2356 struct i40e_asq_cmd_details *cmd_details)
2357{
2358 struct i40e_aq_desc desc;
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002359 struct i40e_aqc_add_get_update_vsi *cmd =
2360 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
Kevin Scottb6cacca2016-03-10 14:59:41 -08002361 struct i40e_aqc_add_get_update_vsi_completion *resp =
2362 (struct i40e_aqc_add_get_update_vsi_completion *)
2363 &desc.params.raw;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002364 i40e_status status;
2365
2366 i40e_fill_default_direct_cmd_desc(&desc,
2367 i40e_aqc_opc_update_vsi_parameters);
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002368 cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002369
2370 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002371
2372 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
2373 sizeof(vsi_ctx->info), cmd_details);
2374
Kevin Scottb6cacca2016-03-10 14:59:41 -08002375 vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
2376 vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
2377
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002378 return status;
2379}
2380
2381/**
2382 * i40e_aq_get_switch_config
2383 * @hw: pointer to the hardware structure
2384 * @buf: pointer to the result buffer
2385 * @buf_size: length of input buffer
2386 * @start_seid: seid to start for the report, 0 == beginning
2387 * @cmd_details: pointer to command details structure or NULL
2388 *
2389 * Fill the buf with switch configuration returned from AdminQ command
2390 **/
2391i40e_status i40e_aq_get_switch_config(struct i40e_hw *hw,
2392 struct i40e_aqc_get_switch_config_resp *buf,
2393 u16 buf_size, u16 *start_seid,
2394 struct i40e_asq_cmd_details *cmd_details)
2395{
2396 struct i40e_aq_desc desc;
2397 struct i40e_aqc_switch_seid *scfg =
2398 (struct i40e_aqc_switch_seid *)&desc.params.raw;
2399 i40e_status status;
2400
2401 i40e_fill_default_direct_cmd_desc(&desc,
2402 i40e_aqc_opc_get_switch_config);
2403 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
2404 if (buf_size > I40E_AQ_LARGE_BUF)
2405 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2406 scfg->seid = cpu_to_le16(*start_seid);
2407
2408 status = i40e_asq_send_command(hw, &desc, buf, buf_size, cmd_details);
2409 *start_seid = le16_to_cpu(scfg->seid);
2410
2411 return status;
2412}
2413
2414/**
Shannon Nelsonf3d58492016-05-03 15:13:11 -07002415 * i40e_aq_set_switch_config
2416 * @hw: pointer to the hardware structure
2417 * @flags: bit flag values to set
Jacob Keller35bea902018-03-19 09:28:04 -07002418 * @mode: cloud filter mode
Shannon Nelsonf3d58492016-05-03 15:13:11 -07002419 * @valid_flags: which bit flags to set
Amritha Nambiar5efe0c62017-10-27 02:35:45 -07002420 * @mode: cloud filter mode
Shannon Nelsonf3d58492016-05-03 15:13:11 -07002421 * @cmd_details: pointer to command details structure or NULL
2422 *
2423 * Set switch configuration bits
2424 **/
2425enum i40e_status_code i40e_aq_set_switch_config(struct i40e_hw *hw,
2426 u16 flags,
Amritha Nambiar5efe0c62017-10-27 02:35:45 -07002427 u16 valid_flags, u8 mode,
Shannon Nelsonf3d58492016-05-03 15:13:11 -07002428 struct i40e_asq_cmd_details *cmd_details)
2429{
2430 struct i40e_aq_desc desc;
2431 struct i40e_aqc_set_switch_config *scfg =
2432 (struct i40e_aqc_set_switch_config *)&desc.params.raw;
2433 enum i40e_status_code status;
2434
2435 i40e_fill_default_direct_cmd_desc(&desc,
2436 i40e_aqc_opc_set_switch_config);
2437 scfg->flags = cpu_to_le16(flags);
2438 scfg->valid_flags = cpu_to_le16(valid_flags);
Amritha Nambiar5efe0c62017-10-27 02:35:45 -07002439 scfg->mode = mode;
Scott Petersonab243ec2017-08-22 06:57:54 -04002440 if (hw->flags & I40E_HW_FLAG_802_1AD_CAPABLE) {
2441 scfg->switch_tag = cpu_to_le16(hw->switch_tag);
2442 scfg->first_tag = cpu_to_le16(hw->first_tag);
2443 scfg->second_tag = cpu_to_le16(hw->second_tag);
2444 }
Shannon Nelsonf3d58492016-05-03 15:13:11 -07002445 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2446
2447 return status;
2448}
2449
2450/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002451 * i40e_aq_get_firmware_version
2452 * @hw: pointer to the hw struct
2453 * @fw_major_version: firmware major version
2454 * @fw_minor_version: firmware minor version
Shannon Nelson7edf8102015-02-24 06:58:41 +00002455 * @fw_build: firmware build number
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002456 * @api_major_version: major queue version
2457 * @api_minor_version: minor queue version
2458 * @cmd_details: pointer to command details structure or NULL
2459 *
2460 * Get the firmware version from the admin queue commands
2461 **/
2462i40e_status i40e_aq_get_firmware_version(struct i40e_hw *hw,
2463 u16 *fw_major_version, u16 *fw_minor_version,
Shannon Nelson7edf8102015-02-24 06:58:41 +00002464 u32 *fw_build,
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002465 u16 *api_major_version, u16 *api_minor_version,
2466 struct i40e_asq_cmd_details *cmd_details)
2467{
2468 struct i40e_aq_desc desc;
2469 struct i40e_aqc_get_version *resp =
2470 (struct i40e_aqc_get_version *)&desc.params.raw;
2471 i40e_status status;
2472
2473 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_version);
2474
2475 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2476
2477 if (!status) {
Shannon Nelson7edf8102015-02-24 06:58:41 +00002478 if (fw_major_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002479 *fw_major_version = le16_to_cpu(resp->fw_major);
Shannon Nelson7edf8102015-02-24 06:58:41 +00002480 if (fw_minor_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002481 *fw_minor_version = le16_to_cpu(resp->fw_minor);
Shannon Nelson7edf8102015-02-24 06:58:41 +00002482 if (fw_build)
2483 *fw_build = le32_to_cpu(resp->fw_build);
2484 if (api_major_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002485 *api_major_version = le16_to_cpu(resp->api_major);
Shannon Nelson7edf8102015-02-24 06:58:41 +00002486 if (api_minor_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002487 *api_minor_version = le16_to_cpu(resp->api_minor);
2488 }
2489
2490 return status;
2491}
2492
2493/**
2494 * i40e_aq_send_driver_version
2495 * @hw: pointer to the hw struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002496 * @dv: driver's major, minor version
2497 * @cmd_details: pointer to command details structure or NULL
2498 *
2499 * Send the driver version to the firmware
2500 **/
2501i40e_status i40e_aq_send_driver_version(struct i40e_hw *hw,
2502 struct i40e_driver_version *dv,
2503 struct i40e_asq_cmd_details *cmd_details)
2504{
2505 struct i40e_aq_desc desc;
2506 struct i40e_aqc_driver_version *cmd =
2507 (struct i40e_aqc_driver_version *)&desc.params.raw;
2508 i40e_status status;
Kevin Scott9d2f98e2014-04-01 07:11:52 +00002509 u16 len;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002510
2511 if (dv == NULL)
2512 return I40E_ERR_PARAM;
2513
2514 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_driver_version);
2515
Kevin Scott3b38cd12015-02-06 08:52:18 +00002516 desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002517 cmd->driver_major_ver = dv->major_version;
2518 cmd->driver_minor_ver = dv->minor_version;
2519 cmd->driver_build_ver = dv->build_version;
2520 cmd->driver_subbuild_ver = dv->subbuild_version;
Shannon Nelsond2466012014-04-01 07:11:45 +00002521
2522 len = 0;
2523 while (len < sizeof(dv->driver_string) &&
2524 (dv->driver_string[len] < 0x80) &&
2525 dv->driver_string[len])
2526 len++;
2527 status = i40e_asq_send_command(hw, &desc, dv->driver_string,
2528 len, cmd_details);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002529
2530 return status;
2531}
2532
2533/**
2534 * i40e_get_link_status - get status of the HW network link
2535 * @hw: pointer to the hw struct
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002536 * @link_up: pointer to bool (true/false = linkup/linkdown)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002537 *
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002538 * Variable link_up true if link is up, false if link is down.
2539 * The variable link_up is invalid if returned value of status != 0
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002540 *
2541 * Side effect: LinkStatusEvent reporting becomes enabled
2542 **/
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002543i40e_status i40e_get_link_status(struct i40e_hw *hw, bool *link_up)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002544{
2545 i40e_status status = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002546
2547 if (hw->phy.get_link_info) {
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002548 status = i40e_update_link_info(hw);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002549
2550 if (status)
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002551 i40e_debug(hw, I40E_DEBUG_LINK, "get link failed: status %d\n",
2552 status);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002553 }
2554
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002555 *link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002556
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002557 return status;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002558}
2559
2560/**
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002561 * i40e_updatelink_status - update status of the HW network link
2562 * @hw: pointer to the hw struct
2563 **/
2564i40e_status i40e_update_link_info(struct i40e_hw *hw)
2565{
2566 struct i40e_aq_get_phy_abilities_resp abilities;
2567 i40e_status status = 0;
2568
2569 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
2570 if (status)
2571 return status;
2572
Carolyn Wybornyab425cb2016-09-27 11:28:52 -07002573 /* extra checking needed to ensure link info to user is timely */
2574 if ((hw->phy.link_info.link_info & I40E_AQ_MEDIA_AVAILABLE) &&
2575 ((hw->phy.link_info.link_info & I40E_AQ_LINK_UP) ||
2576 !(hw->phy.link_info_old.link_info & I40E_AQ_LINK_UP))) {
Carolyn Wyborny8589af72015-09-28 14:16:56 -04002577 status = i40e_aq_get_phy_capabilities(hw, false, false,
2578 &abilities, NULL);
2579 if (status)
2580 return status;
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002581
Mariusz Stachuraed601f62017-07-12 05:46:08 -04002582 hw->phy.link_info.req_fec_info =
2583 abilities.fec_cfg_curr_mod_ext_info &
2584 (I40E_AQ_REQUEST_FEC_KR | I40E_AQ_REQUEST_FEC_RS);
2585
Carolyn Wyborny8589af72015-09-28 14:16:56 -04002586 memcpy(hw->phy.link_info.module_type, &abilities.module_type,
2587 sizeof(hw->phy.link_info.module_type));
2588 }
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002589
2590 return status;
2591}
2592
2593/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002594 * i40e_aq_add_veb - Insert a VEB between the VSI and the MAC
2595 * @hw: pointer to the hw struct
2596 * @uplink_seid: the MAC or other gizmo SEID
2597 * @downlink_seid: the VSI SEID
2598 * @enabled_tc: bitmap of TCs to be enabled
2599 * @default_port: true for default port VSI, false for control port
2600 * @veb_seid: pointer to where to put the resulting VEB SEID
Shannon Nelson8a187f42016-01-13 16:51:41 -08002601 * @enable_stats: true to turn on VEB stats
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002602 * @cmd_details: pointer to command details structure or NULL
2603 *
2604 * This asks the FW to add a VEB between the uplink and downlink
2605 * elements. If the uplink SEID is 0, this will be a floating VEB.
2606 **/
2607i40e_status i40e_aq_add_veb(struct i40e_hw *hw, u16 uplink_seid,
2608 u16 downlink_seid, u8 enabled_tc,
Shannon Nelson8a187f42016-01-13 16:51:41 -08002609 bool default_port, u16 *veb_seid,
2610 bool enable_stats,
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002611 struct i40e_asq_cmd_details *cmd_details)
2612{
2613 struct i40e_aq_desc desc;
2614 struct i40e_aqc_add_veb *cmd =
2615 (struct i40e_aqc_add_veb *)&desc.params.raw;
2616 struct i40e_aqc_add_veb_completion *resp =
2617 (struct i40e_aqc_add_veb_completion *)&desc.params.raw;
2618 i40e_status status;
2619 u16 veb_flags = 0;
2620
2621 /* SEIDs need to either both be set or both be 0 for floating VEB */
2622 if (!!uplink_seid != !!downlink_seid)
2623 return I40E_ERR_PARAM;
2624
2625 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_veb);
2626
2627 cmd->uplink_seid = cpu_to_le16(uplink_seid);
2628 cmd->downlink_seid = cpu_to_le16(downlink_seid);
2629 cmd->enable_tcs = enabled_tc;
2630 if (!uplink_seid)
2631 veb_flags |= I40E_AQC_ADD_VEB_FLOATING;
2632 if (default_port)
2633 veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DEFAULT;
2634 else
2635 veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DATA;
Kevin Scotte1c51b952013-11-20 10:02:51 +00002636
Shannon Nelson8a187f42016-01-13 16:51:41 -08002637 /* reverse logic here: set the bitflag to disable the stats */
2638 if (!enable_stats)
2639 veb_flags |= I40E_AQC_ADD_VEB_ENABLE_DISABLE_STATS;
Kevin Scotte1c51b952013-11-20 10:02:51 +00002640
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002641 cmd->veb_flags = cpu_to_le16(veb_flags);
2642
2643 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2644
2645 if (!status && veb_seid)
2646 *veb_seid = le16_to_cpu(resp->veb_seid);
2647
2648 return status;
2649}
2650
2651/**
2652 * i40e_aq_get_veb_parameters - Retrieve VEB parameters
2653 * @hw: pointer to the hw struct
2654 * @veb_seid: the SEID of the VEB to query
2655 * @switch_id: the uplink switch id
Jeff Kirsher98d44382013-12-21 05:44:42 +00002656 * @floating: set to true if the VEB is floating
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002657 * @statistic_index: index of the stats counter block for this VEB
2658 * @vebs_used: number of VEB's used by function
Jeff Kirsher98d44382013-12-21 05:44:42 +00002659 * @vebs_free: total VEB's not reserved by any function
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002660 * @cmd_details: pointer to command details structure or NULL
2661 *
2662 * This retrieves the parameters for a particular VEB, specified by
2663 * uplink_seid, and returns them to the caller.
2664 **/
2665i40e_status i40e_aq_get_veb_parameters(struct i40e_hw *hw,
2666 u16 veb_seid, u16 *switch_id,
2667 bool *floating, u16 *statistic_index,
2668 u16 *vebs_used, u16 *vebs_free,
2669 struct i40e_asq_cmd_details *cmd_details)
2670{
2671 struct i40e_aq_desc desc;
2672 struct i40e_aqc_get_veb_parameters_completion *cmd_resp =
2673 (struct i40e_aqc_get_veb_parameters_completion *)
2674 &desc.params.raw;
2675 i40e_status status;
2676
2677 if (veb_seid == 0)
2678 return I40E_ERR_PARAM;
2679
2680 i40e_fill_default_direct_cmd_desc(&desc,
2681 i40e_aqc_opc_get_veb_parameters);
2682 cmd_resp->seid = cpu_to_le16(veb_seid);
2683
2684 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2685 if (status)
2686 goto get_veb_exit;
2687
2688 if (switch_id)
2689 *switch_id = le16_to_cpu(cmd_resp->switch_id);
2690 if (statistic_index)
2691 *statistic_index = le16_to_cpu(cmd_resp->statistic_index);
2692 if (vebs_used)
2693 *vebs_used = le16_to_cpu(cmd_resp->vebs_used);
2694 if (vebs_free)
2695 *vebs_free = le16_to_cpu(cmd_resp->vebs_free);
2696 if (floating) {
2697 u16 flags = le16_to_cpu(cmd_resp->veb_flags);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04002698
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002699 if (flags & I40E_AQC_ADD_VEB_FLOATING)
2700 *floating = true;
2701 else
2702 *floating = false;
2703 }
2704
2705get_veb_exit:
2706 return status;
2707}
2708
2709/**
2710 * i40e_aq_add_macvlan
2711 * @hw: pointer to the hw struct
2712 * @seid: VSI for the mac address
2713 * @mv_list: list of macvlans to be added
2714 * @count: length of the list
2715 * @cmd_details: pointer to command details structure or NULL
2716 *
2717 * Add MAC/VLAN addresses to the HW filtering
2718 **/
2719i40e_status i40e_aq_add_macvlan(struct i40e_hw *hw, u16 seid,
2720 struct i40e_aqc_add_macvlan_element_data *mv_list,
2721 u16 count, struct i40e_asq_cmd_details *cmd_details)
2722{
2723 struct i40e_aq_desc desc;
2724 struct i40e_aqc_macvlan *cmd =
2725 (struct i40e_aqc_macvlan *)&desc.params.raw;
2726 i40e_status status;
2727 u16 buf_size;
Shannon Nelson67be6eb2016-01-13 16:51:40 -08002728 int i;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002729
2730 if (count == 0 || !mv_list || !hw)
2731 return I40E_ERR_PARAM;
2732
Shannon Nelson1efc80e2015-02-27 09:18:30 +00002733 buf_size = count * sizeof(*mv_list);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002734
2735 /* prep the rest of the request */
2736 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_macvlan);
2737 cmd->num_addresses = cpu_to_le16(count);
2738 cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
2739 cmd->seid[1] = 0;
2740 cmd->seid[2] = 0;
2741
Shannon Nelson67be6eb2016-01-13 16:51:40 -08002742 for (i = 0; i < count; i++)
2743 if (is_multicast_ether_addr(mv_list[i].mac_addr))
2744 mv_list[i].flags |=
2745 cpu_to_le16(I40E_AQC_MACVLAN_ADD_USE_SHARED_MAC);
2746
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002747 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
2748 if (buf_size > I40E_AQ_LARGE_BUF)
2749 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2750
2751 status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
Shannon Nelson67be6eb2016-01-13 16:51:40 -08002752 cmd_details);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002753
2754 return status;
2755}
2756
2757/**
2758 * i40e_aq_remove_macvlan
2759 * @hw: pointer to the hw struct
2760 * @seid: VSI for the mac address
2761 * @mv_list: list of macvlans to be removed
2762 * @count: length of the list
2763 * @cmd_details: pointer to command details structure or NULL
2764 *
2765 * Remove MAC/VLAN addresses from the HW filtering
2766 **/
2767i40e_status i40e_aq_remove_macvlan(struct i40e_hw *hw, u16 seid,
2768 struct i40e_aqc_remove_macvlan_element_data *mv_list,
2769 u16 count, struct i40e_asq_cmd_details *cmd_details)
2770{
2771 struct i40e_aq_desc desc;
2772 struct i40e_aqc_macvlan *cmd =
2773 (struct i40e_aqc_macvlan *)&desc.params.raw;
2774 i40e_status status;
2775 u16 buf_size;
2776
2777 if (count == 0 || !mv_list || !hw)
2778 return I40E_ERR_PARAM;
2779
Shannon Nelson1efc80e2015-02-27 09:18:30 +00002780 buf_size = count * sizeof(*mv_list);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002781
2782 /* prep the rest of the request */
2783 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_macvlan);
2784 cmd->num_addresses = cpu_to_le16(count);
2785 cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
2786 cmd->seid[1] = 0;
2787 cmd->seid[2] = 0;
2788
2789 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
2790 if (buf_size > I40E_AQ_LARGE_BUF)
2791 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2792
2793 status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
2794 cmd_details);
2795
2796 return status;
2797}
2798
2799/**
Kiran Patil7bd68752016-01-04 10:33:07 -08002800 * i40e_mirrorrule_op - Internal helper function to add/delete mirror rule
2801 * @hw: pointer to the hw struct
2802 * @opcode: AQ opcode for add or delete mirror rule
2803 * @sw_seid: Switch SEID (to which rule refers)
2804 * @rule_type: Rule Type (ingress/egress/VLAN)
2805 * @id: Destination VSI SEID or Rule ID
2806 * @count: length of the list
2807 * @mr_list: list of mirrored VSI SEIDs or VLAN IDs
2808 * @cmd_details: pointer to command details structure or NULL
2809 * @rule_id: Rule ID returned from FW
2810 * @rule_used: Number of rules used in internal switch
2811 * @rule_free: Number of rules free in internal switch
2812 *
2813 * Add/Delete a mirror rule to a specific switch. Mirror rules are supported for
2814 * VEBs/VEPA elements only
2815 **/
2816static i40e_status i40e_mirrorrule_op(struct i40e_hw *hw,
2817 u16 opcode, u16 sw_seid, u16 rule_type, u16 id,
2818 u16 count, __le16 *mr_list,
2819 struct i40e_asq_cmd_details *cmd_details,
2820 u16 *rule_id, u16 *rules_used, u16 *rules_free)
2821{
2822 struct i40e_aq_desc desc;
2823 struct i40e_aqc_add_delete_mirror_rule *cmd =
2824 (struct i40e_aqc_add_delete_mirror_rule *)&desc.params.raw;
2825 struct i40e_aqc_add_delete_mirror_rule_completion *resp =
2826 (struct i40e_aqc_add_delete_mirror_rule_completion *)&desc.params.raw;
2827 i40e_status status;
2828 u16 buf_size;
2829
2830 buf_size = count * sizeof(*mr_list);
2831
2832 /* prep the rest of the request */
2833 i40e_fill_default_direct_cmd_desc(&desc, opcode);
2834 cmd->seid = cpu_to_le16(sw_seid);
2835 cmd->rule_type = cpu_to_le16(rule_type &
2836 I40E_AQC_MIRROR_RULE_TYPE_MASK);
2837 cmd->num_entries = cpu_to_le16(count);
2838 /* Dest VSI for add, rule_id for delete */
2839 cmd->destination = cpu_to_le16(id);
2840 if (mr_list) {
2841 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
2842 I40E_AQ_FLAG_RD));
2843 if (buf_size > I40E_AQ_LARGE_BUF)
2844 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2845 }
2846
2847 status = i40e_asq_send_command(hw, &desc, mr_list, buf_size,
2848 cmd_details);
2849 if (!status ||
2850 hw->aq.asq_last_status == I40E_AQ_RC_ENOSPC) {
2851 if (rule_id)
2852 *rule_id = le16_to_cpu(resp->rule_id);
2853 if (rules_used)
2854 *rules_used = le16_to_cpu(resp->mirror_rules_used);
2855 if (rules_free)
2856 *rules_free = le16_to_cpu(resp->mirror_rules_free);
2857 }
2858 return status;
2859}
2860
2861/**
2862 * i40e_aq_add_mirrorrule - add a mirror rule
2863 * @hw: pointer to the hw struct
2864 * @sw_seid: Switch SEID (to which rule refers)
2865 * @rule_type: Rule Type (ingress/egress/VLAN)
2866 * @dest_vsi: SEID of VSI to which packets will be mirrored
2867 * @count: length of the list
2868 * @mr_list: list of mirrored VSI SEIDs or VLAN IDs
2869 * @cmd_details: pointer to command details structure or NULL
2870 * @rule_id: Rule ID returned from FW
2871 * @rule_used: Number of rules used in internal switch
2872 * @rule_free: Number of rules free in internal switch
2873 *
2874 * Add mirror rule. Mirror rules are supported for VEBs or VEPA elements only
2875 **/
2876i40e_status i40e_aq_add_mirrorrule(struct i40e_hw *hw, u16 sw_seid,
2877 u16 rule_type, u16 dest_vsi, u16 count, __le16 *mr_list,
2878 struct i40e_asq_cmd_details *cmd_details,
2879 u16 *rule_id, u16 *rules_used, u16 *rules_free)
2880{
2881 if (!(rule_type == I40E_AQC_MIRROR_RULE_TYPE_ALL_INGRESS ||
2882 rule_type == I40E_AQC_MIRROR_RULE_TYPE_ALL_EGRESS)) {
2883 if (count == 0 || !mr_list)
2884 return I40E_ERR_PARAM;
2885 }
2886
2887 return i40e_mirrorrule_op(hw, i40e_aqc_opc_add_mirror_rule, sw_seid,
2888 rule_type, dest_vsi, count, mr_list,
2889 cmd_details, rule_id, rules_used, rules_free);
2890}
2891
2892/**
2893 * i40e_aq_delete_mirrorrule - delete a mirror rule
2894 * @hw: pointer to the hw struct
2895 * @sw_seid: Switch SEID (to which rule refers)
2896 * @rule_type: Rule Type (ingress/egress/VLAN)
2897 * @count: length of the list
2898 * @rule_id: Rule ID that is returned in the receive desc as part of
2899 * add_mirrorrule.
2900 * @mr_list: list of mirrored VLAN IDs to be removed
2901 * @cmd_details: pointer to command details structure or NULL
2902 * @rule_used: Number of rules used in internal switch
2903 * @rule_free: Number of rules free in internal switch
2904 *
2905 * Delete a mirror rule. Mirror rules are supported for VEBs/VEPA elements only
2906 **/
2907i40e_status i40e_aq_delete_mirrorrule(struct i40e_hw *hw, u16 sw_seid,
2908 u16 rule_type, u16 rule_id, u16 count, __le16 *mr_list,
2909 struct i40e_asq_cmd_details *cmd_details,
2910 u16 *rules_used, u16 *rules_free)
2911{
2912 /* Rule ID has to be valid except rule_type: INGRESS VLAN mirroring */
Greg Rosedb077272016-04-12 08:30:48 -07002913 if (rule_type == I40E_AQC_MIRROR_RULE_TYPE_VLAN) {
Kiran Patil7bd68752016-01-04 10:33:07 -08002914 /* count and mr_list shall be valid for rule_type INGRESS VLAN
2915 * mirroring. For other rule_type, count and rule_type should
2916 * not matter.
2917 */
2918 if (count == 0 || !mr_list)
2919 return I40E_ERR_PARAM;
2920 }
2921
2922 return i40e_mirrorrule_op(hw, i40e_aqc_opc_delete_mirror_rule, sw_seid,
2923 rule_type, rule_id, count, mr_list,
2924 cmd_details, NULL, rules_used, rules_free);
2925}
2926
2927/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002928 * i40e_aq_send_msg_to_vf
2929 * @hw: pointer to the hardware structure
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00002930 * @vfid: VF id to send msg
Jeff Kirsher98d44382013-12-21 05:44:42 +00002931 * @v_opcode: opcodes for VF-PF communication
2932 * @v_retval: return error code
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002933 * @msg: pointer to the msg buffer
2934 * @msglen: msg length
2935 * @cmd_details: pointer to command details
2936 *
2937 * send msg to vf
2938 **/
2939i40e_status i40e_aq_send_msg_to_vf(struct i40e_hw *hw, u16 vfid,
2940 u32 v_opcode, u32 v_retval, u8 *msg, u16 msglen,
2941 struct i40e_asq_cmd_details *cmd_details)
2942{
2943 struct i40e_aq_desc desc;
2944 struct i40e_aqc_pf_vf_message *cmd =
2945 (struct i40e_aqc_pf_vf_message *)&desc.params.raw;
2946 i40e_status status;
2947
2948 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_vf);
2949 cmd->id = cpu_to_le32(vfid);
2950 desc.cookie_high = cpu_to_le32(v_opcode);
2951 desc.cookie_low = cpu_to_le32(v_retval);
2952 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_SI);
2953 if (msglen) {
2954 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
2955 I40E_AQ_FLAG_RD));
2956 if (msglen > I40E_AQ_LARGE_BUF)
2957 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2958 desc.datalen = cpu_to_le16(msglen);
2959 }
2960 status = i40e_asq_send_command(hw, &desc, msg, msglen, cmd_details);
2961
2962 return status;
2963}
2964
2965/**
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002966 * i40e_aq_debug_read_register
2967 * @hw: pointer to the hw struct
2968 * @reg_addr: register address
2969 * @reg_val: register value
2970 * @cmd_details: pointer to command details structure or NULL
2971 *
2972 * Read the register using the admin queue commands
2973 **/
2974i40e_status i40e_aq_debug_read_register(struct i40e_hw *hw,
Jesse Brandeburg7b115dd2015-02-27 09:15:23 +00002975 u32 reg_addr, u64 *reg_val,
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002976 struct i40e_asq_cmd_details *cmd_details)
2977{
2978 struct i40e_aq_desc desc;
2979 struct i40e_aqc_debug_reg_read_write *cmd_resp =
2980 (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
2981 i40e_status status;
2982
2983 if (reg_val == NULL)
2984 return I40E_ERR_PARAM;
2985
Jesse Brandeburg7b115dd2015-02-27 09:15:23 +00002986 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_read_reg);
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002987
2988 cmd_resp->address = cpu_to_le32(reg_addr);
2989
2990 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2991
2992 if (!status) {
Jesse Brandeburg7b115dd2015-02-27 09:15:23 +00002993 *reg_val = ((u64)le32_to_cpu(cmd_resp->value_high) << 32) |
2994 (u64)le32_to_cpu(cmd_resp->value_low);
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002995 }
2996
2997 return status;
2998}
2999
3000/**
Shannon Nelson53db45c2014-08-01 13:27:05 -07003001 * i40e_aq_debug_write_register
3002 * @hw: pointer to the hw struct
3003 * @reg_addr: register address
3004 * @reg_val: register value
3005 * @cmd_details: pointer to command details structure or NULL
3006 *
3007 * Write to a register using the admin queue commands
3008 **/
3009i40e_status i40e_aq_debug_write_register(struct i40e_hw *hw,
3010 u32 reg_addr, u64 reg_val,
3011 struct i40e_asq_cmd_details *cmd_details)
3012{
3013 struct i40e_aq_desc desc;
3014 struct i40e_aqc_debug_reg_read_write *cmd =
3015 (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
3016 i40e_status status;
3017
3018 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_write_reg);
3019
3020 cmd->address = cpu_to_le32(reg_addr);
3021 cmd->value_high = cpu_to_le32((u32)(reg_val >> 32));
3022 cmd->value_low = cpu_to_le32((u32)(reg_val & 0xFFFFFFFF));
3023
3024 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3025
3026 return status;
3027}
3028
3029/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003030 * i40e_aq_request_resource
3031 * @hw: pointer to the hw struct
3032 * @resource: resource id
3033 * @access: access type
3034 * @sdp_number: resource number
3035 * @timeout: the maximum time in ms that the driver may hold the resource
3036 * @cmd_details: pointer to command details structure or NULL
3037 *
3038 * requests common resource using the admin queue commands
3039 **/
3040i40e_status i40e_aq_request_resource(struct i40e_hw *hw,
3041 enum i40e_aq_resources_ids resource,
3042 enum i40e_aq_resource_access_type access,
3043 u8 sdp_number, u64 *timeout,
3044 struct i40e_asq_cmd_details *cmd_details)
3045{
3046 struct i40e_aq_desc desc;
3047 struct i40e_aqc_request_resource *cmd_resp =
3048 (struct i40e_aqc_request_resource *)&desc.params.raw;
3049 i40e_status status;
3050
3051 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_request_resource);
3052
3053 cmd_resp->resource_id = cpu_to_le16(resource);
3054 cmd_resp->access_type = cpu_to_le16(access);
3055 cmd_resp->resource_number = cpu_to_le32(sdp_number);
3056
3057 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3058 /* The completion specifies the maximum time in ms that the driver
3059 * may hold the resource in the Timeout field.
3060 * If the resource is held by someone else, the command completes with
3061 * busy return value and the timeout field indicates the maximum time
3062 * the current owner of the resource has to free it.
3063 */
3064 if (!status || hw->aq.asq_last_status == I40E_AQ_RC_EBUSY)
3065 *timeout = le32_to_cpu(cmd_resp->timeout);
3066
3067 return status;
3068}
3069
3070/**
3071 * i40e_aq_release_resource
3072 * @hw: pointer to the hw struct
3073 * @resource: resource id
3074 * @sdp_number: resource number
3075 * @cmd_details: pointer to command details structure or NULL
3076 *
3077 * release common resource using the admin queue commands
3078 **/
3079i40e_status i40e_aq_release_resource(struct i40e_hw *hw,
3080 enum i40e_aq_resources_ids resource,
3081 u8 sdp_number,
3082 struct i40e_asq_cmd_details *cmd_details)
3083{
3084 struct i40e_aq_desc desc;
3085 struct i40e_aqc_request_resource *cmd =
3086 (struct i40e_aqc_request_resource *)&desc.params.raw;
3087 i40e_status status;
3088
3089 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_release_resource);
3090
3091 cmd->resource_id = cpu_to_le16(resource);
3092 cmd->resource_number = cpu_to_le32(sdp_number);
3093
3094 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3095
3096 return status;
3097}
3098
3099/**
3100 * i40e_aq_read_nvm
3101 * @hw: pointer to the hw struct
3102 * @module_pointer: module pointer location in words from the NVM beginning
3103 * @offset: byte offset from the module beginning
3104 * @length: length of the section to be read (in bytes from the offset)
3105 * @data: command buffer (size [bytes] = length)
3106 * @last_command: tells if this is the last command in a series
3107 * @cmd_details: pointer to command details structure or NULL
3108 *
3109 * Read the NVM using the admin queue commands
3110 **/
3111i40e_status i40e_aq_read_nvm(struct i40e_hw *hw, u8 module_pointer,
3112 u32 offset, u16 length, void *data,
3113 bool last_command,
3114 struct i40e_asq_cmd_details *cmd_details)
3115{
3116 struct i40e_aq_desc desc;
3117 struct i40e_aqc_nvm_update *cmd =
3118 (struct i40e_aqc_nvm_update *)&desc.params.raw;
3119 i40e_status status;
3120
3121 /* In offset the highest byte must be zeroed. */
3122 if (offset & 0xFF000000) {
3123 status = I40E_ERR_PARAM;
3124 goto i40e_aq_read_nvm_exit;
3125 }
3126
3127 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_read);
3128
3129 /* If this is the last command in a series, set the proper flag. */
3130 if (last_command)
3131 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
3132 cmd->module_pointer = module_pointer;
3133 cmd->offset = cpu_to_le32(offset);
3134 cmd->length = cpu_to_le16(length);
3135
3136 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3137 if (length > I40E_AQ_LARGE_BUF)
3138 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3139
3140 status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
3141
3142i40e_aq_read_nvm_exit:
3143 return status;
3144}
3145
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003146/**
3147 * i40e_aq_erase_nvm
3148 * @hw: pointer to the hw struct
3149 * @module_pointer: module pointer location in words from the NVM beginning
3150 * @offset: offset in the module (expressed in 4 KB from module's beginning)
3151 * @length: length of the section to be erased (expressed in 4 KB)
3152 * @last_command: tells if this is the last command in a series
3153 * @cmd_details: pointer to command details structure or NULL
3154 *
3155 * Erase the NVM sector using the admin queue commands
3156 **/
3157i40e_status i40e_aq_erase_nvm(struct i40e_hw *hw, u8 module_pointer,
3158 u32 offset, u16 length, bool last_command,
3159 struct i40e_asq_cmd_details *cmd_details)
3160{
3161 struct i40e_aq_desc desc;
3162 struct i40e_aqc_nvm_update *cmd =
3163 (struct i40e_aqc_nvm_update *)&desc.params.raw;
3164 i40e_status status;
3165
3166 /* In offset the highest byte must be zeroed. */
3167 if (offset & 0xFF000000) {
3168 status = I40E_ERR_PARAM;
3169 goto i40e_aq_erase_nvm_exit;
3170 }
3171
3172 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_erase);
3173
3174 /* If this is the last command in a series, set the proper flag. */
3175 if (last_command)
3176 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
3177 cmd->module_pointer = module_pointer;
3178 cmd->offset = cpu_to_le32(offset);
3179 cmd->length = cpu_to_le16(length);
3180
3181 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3182
3183i40e_aq_erase_nvm_exit:
3184 return status;
3185}
3186
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003187/**
3188 * i40e_parse_discover_capabilities
3189 * @hw: pointer to the hw struct
3190 * @buff: pointer to a buffer containing device/function capability records
3191 * @cap_count: number of capability records in the list
3192 * @list_type_opc: type of capabilities list to parse
3193 *
3194 * Parse the device/function capabilities list.
3195 **/
3196static void i40e_parse_discover_capabilities(struct i40e_hw *hw, void *buff,
3197 u32 cap_count,
3198 enum i40e_admin_queue_opc list_type_opc)
3199{
3200 struct i40e_aqc_list_capabilities_element_resp *cap;
Shannon Nelson9fee9db2014-12-11 07:06:30 +00003201 u32 valid_functions, num_functions;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003202 u32 number, logical_id, phys_id;
3203 struct i40e_hw_capabilities *p;
Mariusz Stachurabc2a3a62018-03-08 14:52:10 -08003204 u16 id, ocp_cfg_word0;
3205 i40e_status status;
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003206 u8 major_rev;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003207 u32 i = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003208
3209 cap = (struct i40e_aqc_list_capabilities_element_resp *) buff;
3210
3211 if (list_type_opc == i40e_aqc_opc_list_dev_capabilities)
Joe Perchesb58f2f72014-03-25 04:30:32 +00003212 p = &hw->dev_caps;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003213 else if (list_type_opc == i40e_aqc_opc_list_func_capabilities)
Joe Perchesb58f2f72014-03-25 04:30:32 +00003214 p = &hw->func_caps;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003215 else
3216 return;
3217
3218 for (i = 0; i < cap_count; i++, cap++) {
3219 id = le16_to_cpu(cap->id);
3220 number = le32_to_cpu(cap->number);
3221 logical_id = le32_to_cpu(cap->logical_id);
3222 phys_id = le32_to_cpu(cap->phys_id);
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003223 major_rev = cap->major_rev;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003224
3225 switch (id) {
Shannon Nelson406e7342015-12-10 11:38:49 -08003226 case I40E_AQ_CAP_ID_SWITCH_MODE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003227 p->switch_mode = number;
3228 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003229 case I40E_AQ_CAP_ID_MNG_MODE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003230 p->management_mode = number;
Piotr Raczynski64f5ead2016-10-25 16:08:53 -07003231 if (major_rev > 1) {
3232 p->mng_protocols_over_mctp = logical_id;
3233 i40e_debug(hw, I40E_DEBUG_INIT,
3234 "HW Capability: Protocols over MCTP = %d\n",
3235 p->mng_protocols_over_mctp);
3236 } else {
3237 p->mng_protocols_over_mctp = 0;
3238 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003239 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003240 case I40E_AQ_CAP_ID_NPAR_ACTIVE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003241 p->npar_enable = number;
3242 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003243 case I40E_AQ_CAP_ID_OS2BMC_CAP:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003244 p->os2bmc = number;
3245 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003246 case I40E_AQ_CAP_ID_FUNCTIONS_VALID:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003247 p->valid_functions = number;
3248 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003249 case I40E_AQ_CAP_ID_SRIOV:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003250 if (number == 1)
3251 p->sr_iov_1_1 = true;
3252 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003253 case I40E_AQ_CAP_ID_VF:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003254 p->num_vfs = number;
3255 p->vf_base_id = logical_id;
3256 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003257 case I40E_AQ_CAP_ID_VMDQ:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003258 if (number == 1)
3259 p->vmdq = true;
3260 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003261 case I40E_AQ_CAP_ID_8021QBG:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003262 if (number == 1)
3263 p->evb_802_1_qbg = true;
3264 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003265 case I40E_AQ_CAP_ID_8021QBR:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003266 if (number == 1)
3267 p->evb_802_1_qbh = true;
3268 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003269 case I40E_AQ_CAP_ID_VSI:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003270 p->num_vsis = number;
3271 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003272 case I40E_AQ_CAP_ID_DCB:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003273 if (number == 1) {
3274 p->dcb = true;
3275 p->enabled_tcmap = logical_id;
3276 p->maxtc = phys_id;
3277 }
3278 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003279 case I40E_AQ_CAP_ID_FCOE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003280 if (number == 1)
3281 p->fcoe = true;
3282 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003283 case I40E_AQ_CAP_ID_ISCSI:
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00003284 if (number == 1)
3285 p->iscsi = true;
3286 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003287 case I40E_AQ_CAP_ID_RSS:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003288 p->rss = true;
Carolyn Wybornye157ea32014-06-03 23:50:22 +00003289 p->rss_table_size = number;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003290 p->rss_table_entry_width = logical_id;
3291 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003292 case I40E_AQ_CAP_ID_RXQ:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003293 p->num_rx_qp = number;
3294 p->base_queue = phys_id;
3295 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003296 case I40E_AQ_CAP_ID_TXQ:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003297 p->num_tx_qp = number;
3298 p->base_queue = phys_id;
3299 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003300 case I40E_AQ_CAP_ID_MSIX:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003301 p->num_msix_vectors = number;
Deepthi Kavalur453e16e2016-04-01 03:56:01 -07003302 i40e_debug(hw, I40E_DEBUG_INIT,
3303 "HW Capability: MSIX vector count = %d\n",
3304 p->num_msix_vectors);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003305 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003306 case I40E_AQ_CAP_ID_VF_MSIX:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003307 p->num_msix_vectors_vf = number;
3308 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003309 case I40E_AQ_CAP_ID_FLEX10:
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003310 if (major_rev == 1) {
3311 if (number == 1) {
3312 p->flex10_enable = true;
3313 p->flex10_capable = true;
3314 }
3315 } else {
3316 /* Capability revision >= 2 */
3317 if (number & 1)
3318 p->flex10_enable = true;
3319 if (number & 2)
3320 p->flex10_capable = true;
3321 }
3322 p->flex10_mode = logical_id;
3323 p->flex10_status = phys_id;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003324 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003325 case I40E_AQ_CAP_ID_CEM:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003326 if (number == 1)
3327 p->mgmt_cem = true;
3328 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003329 case I40E_AQ_CAP_ID_IWARP:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003330 if (number == 1)
3331 p->iwarp = true;
3332 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003333 case I40E_AQ_CAP_ID_LED:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003334 if (phys_id < I40E_HW_CAP_MAX_GPIO)
3335 p->led[phys_id] = true;
3336 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003337 case I40E_AQ_CAP_ID_SDP:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003338 if (phys_id < I40E_HW_CAP_MAX_GPIO)
3339 p->sdp[phys_id] = true;
3340 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003341 case I40E_AQ_CAP_ID_MDIO:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003342 if (number == 1) {
3343 p->mdio_port_num = phys_id;
3344 p->mdio_port_mode = logical_id;
3345 }
3346 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003347 case I40E_AQ_CAP_ID_1588:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003348 if (number == 1)
3349 p->ieee_1588 = true;
3350 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003351 case I40E_AQ_CAP_ID_FLOW_DIRECTOR:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003352 p->fd = true;
3353 p->fd_filters_guaranteed = number;
3354 p->fd_filters_best_effort = logical_id;
3355 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003356 case I40E_AQ_CAP_ID_WSR_PROT:
Kevin Scott73b23402015-04-07 19:45:38 -04003357 p->wr_csr_prot = (u64)number;
3358 p->wr_csr_prot |= (u64)logical_id << 32;
3359 break;
Michal Kosiarz68a1c5a2016-04-12 08:30:46 -07003360 case I40E_AQ_CAP_ID_NVM_MGMT:
3361 if (number & I40E_NVM_MGMT_SEC_REV_DISABLED)
3362 p->sec_rev_disabled = true;
3363 if (number & I40E_NVM_MGMT_UPDATE_DISABLED)
3364 p->update_disabled = true;
3365 break;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003366 default:
3367 break;
3368 }
3369 }
3370
Vasu Devf18ae102015-04-07 19:45:36 -04003371 if (p->fcoe)
3372 i40e_debug(hw, I40E_DEBUG_ALL, "device is FCoE capable\n");
3373
Vasu Dev566bb852014-04-09 05:59:06 +00003374 /* Software override ensuring FCoE is disabled if npar or mfp
3375 * mode because it is not supported in these modes.
3376 */
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003377 if (p->npar_enable || p->flex10_enable)
Vasu Dev566bb852014-04-09 05:59:06 +00003378 p->fcoe = false;
3379
Shannon Nelson9fee9db2014-12-11 07:06:30 +00003380 /* count the enabled ports (aka the "not disabled" ports) */
3381 hw->num_ports = 0;
3382 for (i = 0; i < 4; i++) {
3383 u32 port_cfg_reg = I40E_PRTGEN_CNF + (4 * i);
3384 u64 port_cfg = 0;
3385
3386 /* use AQ read to get the physical register offset instead
3387 * of the port relative offset
3388 */
3389 i40e_aq_debug_read_register(hw, port_cfg_reg, &port_cfg, NULL);
3390 if (!(port_cfg & I40E_PRTGEN_CNF_PORT_DIS_MASK))
3391 hw->num_ports++;
3392 }
3393
Mariusz Stachurabc2a3a62018-03-08 14:52:10 -08003394 /* OCP cards case: if a mezz is removed the Ethernet port is at
3395 * disabled state in PRTGEN_CNF register. Additional NVM read is
3396 * needed in order to check if we are dealing with OCP card.
3397 * Those cards have 4 PFs at minimum, so using PRTGEN_CNF for counting
3398 * physical ports results in wrong partition id calculation and thus
3399 * not supporting WoL.
3400 */
3401 if (hw->mac.type == I40E_MAC_X722) {
3402 if (!i40e_acquire_nvm(hw, I40E_RESOURCE_READ)) {
3403 status = i40e_aq_read_nvm(hw, I40E_SR_EMP_MODULE_PTR,
3404 2 * I40E_SR_OCP_CFG_WORD0,
3405 sizeof(ocp_cfg_word0),
3406 &ocp_cfg_word0, true, NULL);
3407 if (!status &&
3408 (ocp_cfg_word0 & I40E_SR_OCP_ENABLED))
3409 hw->num_ports = 4;
3410 i40e_release_nvm(hw);
3411 }
3412 }
3413
Shannon Nelson9fee9db2014-12-11 07:06:30 +00003414 valid_functions = p->valid_functions;
3415 num_functions = 0;
3416 while (valid_functions) {
3417 if (valid_functions & 1)
3418 num_functions++;
3419 valid_functions >>= 1;
3420 }
3421
3422 /* partition id is 1-based, and functions are evenly spread
3423 * across the ports as partitions
3424 */
Michal Kosiarz999b3152016-10-11 15:26:56 -07003425 if (hw->num_ports != 0) {
3426 hw->partition_id = (hw->pf_id / hw->num_ports) + 1;
3427 hw->num_partitions = num_functions / hw->num_ports;
3428 }
Shannon Nelson9fee9db2014-12-11 07:06:30 +00003429
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003430 /* additional HW specific goodies that might
3431 * someday be HW version specific
3432 */
3433 p->rx_buf_chain_len = I40E_MAX_CHAINED_RX_BUFFERS;
3434}
3435
3436/**
3437 * i40e_aq_discover_capabilities
3438 * @hw: pointer to the hw struct
3439 * @buff: a virtual buffer to hold the capabilities
3440 * @buff_size: Size of the virtual buffer
3441 * @data_size: Size of the returned data, or buff size needed if AQ err==ENOMEM
3442 * @list_type_opc: capabilities type to discover - pass in the command opcode
3443 * @cmd_details: pointer to command details structure or NULL
3444 *
3445 * Get the device capabilities descriptions from the firmware
3446 **/
3447i40e_status i40e_aq_discover_capabilities(struct i40e_hw *hw,
3448 void *buff, u16 buff_size, u16 *data_size,
3449 enum i40e_admin_queue_opc list_type_opc,
3450 struct i40e_asq_cmd_details *cmd_details)
3451{
3452 struct i40e_aqc_list_capabilites *cmd;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003453 struct i40e_aq_desc desc;
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08003454 i40e_status status = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003455
3456 cmd = (struct i40e_aqc_list_capabilites *)&desc.params.raw;
3457
3458 if (list_type_opc != i40e_aqc_opc_list_func_capabilities &&
3459 list_type_opc != i40e_aqc_opc_list_dev_capabilities) {
3460 status = I40E_ERR_PARAM;
3461 goto exit;
3462 }
3463
3464 i40e_fill_default_direct_cmd_desc(&desc, list_type_opc);
3465
3466 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3467 if (buff_size > I40E_AQ_LARGE_BUF)
3468 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3469
3470 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3471 *data_size = le16_to_cpu(desc.datalen);
3472
3473 if (status)
3474 goto exit;
3475
3476 i40e_parse_discover_capabilities(hw, buff, le32_to_cpu(cmd->count),
3477 list_type_opc);
3478
3479exit:
3480 return status;
3481}
3482
3483/**
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003484 * i40e_aq_update_nvm
3485 * @hw: pointer to the hw struct
3486 * @module_pointer: module pointer location in words from the NVM beginning
3487 * @offset: byte offset from the module beginning
3488 * @length: length of the section to be written (in bytes from the offset)
3489 * @data: command buffer (size [bytes] = length)
3490 * @last_command: tells if this is the last command in a series
Pawel Jablonskie3a5d6e2017-12-18 05:14:44 -05003491 * @preservation_flags: Preservation mode flags
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003492 * @cmd_details: pointer to command details structure or NULL
3493 *
3494 * Update the NVM using the admin queue commands
3495 **/
3496i40e_status i40e_aq_update_nvm(struct i40e_hw *hw, u8 module_pointer,
3497 u32 offset, u16 length, void *data,
Pawel Jablonskie3a5d6e2017-12-18 05:14:44 -05003498 bool last_command, u8 preservation_flags,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003499 struct i40e_asq_cmd_details *cmd_details)
3500{
3501 struct i40e_aq_desc desc;
3502 struct i40e_aqc_nvm_update *cmd =
3503 (struct i40e_aqc_nvm_update *)&desc.params.raw;
3504 i40e_status status;
3505
3506 /* In offset the highest byte must be zeroed. */
3507 if (offset & 0xFF000000) {
3508 status = I40E_ERR_PARAM;
3509 goto i40e_aq_update_nvm_exit;
3510 }
3511
3512 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_update);
3513
3514 /* If this is the last command in a series, set the proper flag. */
3515 if (last_command)
3516 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
Pawel Jablonskie3a5d6e2017-12-18 05:14:44 -05003517 if (hw->mac.type == I40E_MAC_X722) {
3518 if (preservation_flags == I40E_NVM_PRESERVATION_FLAGS_SELECTED)
3519 cmd->command_flags |=
3520 (I40E_AQ_NVM_PRESERVATION_FLAGS_SELECTED <<
3521 I40E_AQ_NVM_PRESERVATION_FLAGS_SHIFT);
3522 else if (preservation_flags == I40E_NVM_PRESERVATION_FLAGS_ALL)
3523 cmd->command_flags |=
3524 (I40E_AQ_NVM_PRESERVATION_FLAGS_ALL <<
3525 I40E_AQ_NVM_PRESERVATION_FLAGS_SHIFT);
3526 }
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003527 cmd->module_pointer = module_pointer;
3528 cmd->offset = cpu_to_le32(offset);
3529 cmd->length = cpu_to_le16(length);
3530
3531 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
3532 if (length > I40E_AQ_LARGE_BUF)
3533 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3534
3535 status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
3536
3537i40e_aq_update_nvm_exit:
3538 return status;
3539}
3540
3541/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003542 * i40e_aq_get_lldp_mib
3543 * @hw: pointer to the hw struct
3544 * @bridge_type: type of bridge requested
3545 * @mib_type: Local, Remote or both Local and Remote MIBs
3546 * @buff: pointer to a user supplied buffer to store the MIB block
3547 * @buff_size: size of the buffer (in bytes)
3548 * @local_len : length of the returned Local LLDP MIB
3549 * @remote_len: length of the returned Remote LLDP MIB
3550 * @cmd_details: pointer to command details structure or NULL
3551 *
3552 * Requests the complete LLDP MIB (entire packet).
3553 **/
3554i40e_status i40e_aq_get_lldp_mib(struct i40e_hw *hw, u8 bridge_type,
3555 u8 mib_type, void *buff, u16 buff_size,
3556 u16 *local_len, u16 *remote_len,
3557 struct i40e_asq_cmd_details *cmd_details)
3558{
3559 struct i40e_aq_desc desc;
3560 struct i40e_aqc_lldp_get_mib *cmd =
3561 (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
3562 struct i40e_aqc_lldp_get_mib *resp =
3563 (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
3564 i40e_status status;
3565
3566 if (buff_size == 0 || !buff)
3567 return I40E_ERR_PARAM;
3568
3569 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_get_mib);
3570 /* Indirect Command */
3571 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3572
3573 cmd->type = mib_type & I40E_AQ_LLDP_MIB_TYPE_MASK;
3574 cmd->type |= ((bridge_type << I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) &
3575 I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
3576
3577 desc.datalen = cpu_to_le16(buff_size);
3578
3579 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3580 if (buff_size > I40E_AQ_LARGE_BUF)
3581 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3582
3583 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3584 if (!status) {
3585 if (local_len != NULL)
3586 *local_len = le16_to_cpu(resp->local_len);
3587 if (remote_len != NULL)
3588 *remote_len = le16_to_cpu(resp->remote_len);
3589 }
3590
3591 return status;
3592}
3593
3594/**
3595 * i40e_aq_cfg_lldp_mib_change_event
3596 * @hw: pointer to the hw struct
3597 * @enable_update: Enable or Disable event posting
3598 * @cmd_details: pointer to command details structure or NULL
3599 *
3600 * Enable or Disable posting of an event on ARQ when LLDP MIB
3601 * associated with the interface changes
3602 **/
3603i40e_status i40e_aq_cfg_lldp_mib_change_event(struct i40e_hw *hw,
3604 bool enable_update,
3605 struct i40e_asq_cmd_details *cmd_details)
3606{
3607 struct i40e_aq_desc desc;
3608 struct i40e_aqc_lldp_update_mib *cmd =
3609 (struct i40e_aqc_lldp_update_mib *)&desc.params.raw;
3610 i40e_status status;
3611
3612 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_update_mib);
3613
3614 if (!enable_update)
3615 cmd->command |= I40E_AQ_LLDP_MIB_UPDATE_DISABLE;
3616
3617 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3618
3619 return status;
3620}
3621
3622/**
3623 * i40e_aq_stop_lldp
3624 * @hw: pointer to the hw struct
3625 * @shutdown_agent: True if LLDP Agent needs to be Shutdown
3626 * @cmd_details: pointer to command details structure or NULL
3627 *
3628 * Stop or Shutdown the embedded LLDP Agent
3629 **/
3630i40e_status i40e_aq_stop_lldp(struct i40e_hw *hw, bool shutdown_agent,
3631 struct i40e_asq_cmd_details *cmd_details)
3632{
3633 struct i40e_aq_desc desc;
3634 struct i40e_aqc_lldp_stop *cmd =
3635 (struct i40e_aqc_lldp_stop *)&desc.params.raw;
3636 i40e_status status;
3637
3638 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_stop);
3639
3640 if (shutdown_agent)
3641 cmd->command |= I40E_AQ_LLDP_AGENT_SHUTDOWN;
3642
3643 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3644
3645 return status;
3646}
3647
3648/**
3649 * i40e_aq_start_lldp
3650 * @hw: pointer to the hw struct
3651 * @cmd_details: pointer to command details structure or NULL
3652 *
3653 * Start the embedded LLDP Agent on all ports.
3654 **/
3655i40e_status i40e_aq_start_lldp(struct i40e_hw *hw,
3656 struct i40e_asq_cmd_details *cmd_details)
3657{
3658 struct i40e_aq_desc desc;
3659 struct i40e_aqc_lldp_start *cmd =
3660 (struct i40e_aqc_lldp_start *)&desc.params.raw;
3661 i40e_status status;
3662
3663 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_start);
3664
3665 cmd->command = I40E_AQ_LLDP_AGENT_START;
Upasana Menonb6a02a62017-12-27 08:17:07 -05003666 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003667
Upasana Menonb6a02a62017-12-27 08:17:07 -05003668 return status;
3669}
3670
3671/**
3672 * i40e_aq_set_dcb_parameters
3673 * @hw: pointer to the hw struct
3674 * @cmd_details: pointer to command details structure or NULL
3675 * @dcb_enable: True if DCB configuration needs to be applied
3676 *
3677 **/
3678enum i40e_status_code
3679i40e_aq_set_dcb_parameters(struct i40e_hw *hw, bool dcb_enable,
3680 struct i40e_asq_cmd_details *cmd_details)
3681{
3682 struct i40e_aq_desc desc;
3683 struct i40e_aqc_set_dcb_parameters *cmd =
3684 (struct i40e_aqc_set_dcb_parameters *)&desc.params.raw;
3685 i40e_status status;
3686
3687 i40e_fill_default_direct_cmd_desc(&desc,
3688 i40e_aqc_opc_set_dcb_parameters);
3689
3690 if (dcb_enable) {
3691 cmd->valid_flags = I40E_DCB_VALID;
3692 cmd->command = I40E_AQ_DCB_SET_AGENT;
3693 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003694 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3695
3696 return status;
3697}
3698
3699/**
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00003700 * i40e_aq_get_cee_dcb_config
3701 * @hw: pointer to the hw struct
3702 * @buff: response buffer that stores CEE operational configuration
3703 * @buff_size: size of the buffer passed
3704 * @cmd_details: pointer to command details structure or NULL
3705 *
3706 * Get CEE DCBX mode operational configuration from firmware
3707 **/
3708i40e_status i40e_aq_get_cee_dcb_config(struct i40e_hw *hw,
3709 void *buff, u16 buff_size,
3710 struct i40e_asq_cmd_details *cmd_details)
3711{
3712 struct i40e_aq_desc desc;
3713 i40e_status status;
3714
3715 if (buff_size == 0 || !buff)
3716 return I40E_ERR_PARAM;
3717
3718 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_cee_dcb_cfg);
3719
3720 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3721 status = i40e_asq_send_command(hw, &desc, (void *)buff, buff_size,
3722 cmd_details);
3723
3724 return status;
3725}
3726
3727/**
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003728 * i40e_aq_add_udp_tunnel
3729 * @hw: pointer to the hw struct
Jacob Keller15d23b42017-06-07 05:43:04 -04003730 * @udp_port: the UDP port to add in Host byte order
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003731 * @header_len: length of the tunneling header length in DWords
3732 * @protocol_index: protocol index type
Jeff Kirsher98d44382013-12-21 05:44:42 +00003733 * @filter_index: pointer to filter index
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003734 * @cmd_details: pointer to command details structure or NULL
Jacob Keller15d23b42017-06-07 05:43:04 -04003735 *
3736 * Note: Firmware expects the udp_port value to be in Little Endian format,
3737 * and this function will call cpu_to_le16 to convert from Host byte order to
3738 * Little Endian order.
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003739 **/
3740i40e_status i40e_aq_add_udp_tunnel(struct i40e_hw *hw,
Kevin Scottf4f94b92014-04-05 07:46:10 +00003741 u16 udp_port, u8 protocol_index,
3742 u8 *filter_index,
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003743 struct i40e_asq_cmd_details *cmd_details)
3744{
3745 struct i40e_aq_desc desc;
3746 struct i40e_aqc_add_udp_tunnel *cmd =
3747 (struct i40e_aqc_add_udp_tunnel *)&desc.params.raw;
3748 struct i40e_aqc_del_udp_tunnel_completion *resp =
3749 (struct i40e_aqc_del_udp_tunnel_completion *)&desc.params.raw;
3750 i40e_status status;
3751
3752 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_udp_tunnel);
3753
3754 cmd->udp_port = cpu_to_le16(udp_port);
Shannon Nelson981b7542013-12-11 08:17:11 +00003755 cmd->protocol_type = protocol_index;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003756
3757 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3758
Shannon Nelson65d13462015-02-21 06:45:28 +00003759 if (!status && filter_index)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003760 *filter_index = resp->index;
3761
3762 return status;
3763}
3764
3765/**
3766 * i40e_aq_del_udp_tunnel
3767 * @hw: pointer to the hw struct
3768 * @index: filter index
3769 * @cmd_details: pointer to command details structure or NULL
3770 **/
3771i40e_status i40e_aq_del_udp_tunnel(struct i40e_hw *hw, u8 index,
3772 struct i40e_asq_cmd_details *cmd_details)
3773{
3774 struct i40e_aq_desc desc;
3775 struct i40e_aqc_remove_udp_tunnel *cmd =
3776 (struct i40e_aqc_remove_udp_tunnel *)&desc.params.raw;
3777 i40e_status status;
3778
3779 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_del_udp_tunnel);
3780
3781 cmd->index = index;
3782
3783 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3784
3785 return status;
3786}
3787
3788/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003789 * i40e_aq_delete_element - Delete switch element
3790 * @hw: pointer to the hw struct
3791 * @seid: the SEID to delete from the switch
3792 * @cmd_details: pointer to command details structure or NULL
3793 *
3794 * This deletes a switch element from the switch.
3795 **/
3796i40e_status i40e_aq_delete_element(struct i40e_hw *hw, u16 seid,
3797 struct i40e_asq_cmd_details *cmd_details)
3798{
3799 struct i40e_aq_desc desc;
3800 struct i40e_aqc_switch_seid *cmd =
3801 (struct i40e_aqc_switch_seid *)&desc.params.raw;
3802 i40e_status status;
3803
3804 if (seid == 0)
3805 return I40E_ERR_PARAM;
3806
3807 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_delete_element);
3808
3809 cmd->seid = cpu_to_le16(seid);
3810
3811 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3812
3813 return status;
3814}
3815
3816/**
Neerav Parikhafb3ff02014-01-17 15:36:36 -08003817 * i40e_aq_dcb_updated - DCB Updated Command
3818 * @hw: pointer to the hw struct
3819 * @cmd_details: pointer to command details structure or NULL
3820 *
3821 * EMP will return when the shared RPB settings have been
3822 * recomputed and modified. The retval field in the descriptor
3823 * will be set to 0 when RPB is modified.
3824 **/
3825i40e_status i40e_aq_dcb_updated(struct i40e_hw *hw,
3826 struct i40e_asq_cmd_details *cmd_details)
3827{
3828 struct i40e_aq_desc desc;
3829 i40e_status status;
3830
3831 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_dcb_updated);
3832
3833 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3834
3835 return status;
3836}
3837
3838/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003839 * i40e_aq_tx_sched_cmd - generic Tx scheduler AQ command handler
3840 * @hw: pointer to the hw struct
3841 * @seid: seid for the physical port/switching component/vsi
3842 * @buff: Indirect buffer to hold data parameters and response
3843 * @buff_size: Indirect buffer size
3844 * @opcode: Tx scheduler AQ command opcode
3845 * @cmd_details: pointer to command details structure or NULL
3846 *
3847 * Generic command handler for Tx scheduler AQ commands
3848 **/
3849static i40e_status i40e_aq_tx_sched_cmd(struct i40e_hw *hw, u16 seid,
3850 void *buff, u16 buff_size,
3851 enum i40e_admin_queue_opc opcode,
3852 struct i40e_asq_cmd_details *cmd_details)
3853{
3854 struct i40e_aq_desc desc;
3855 struct i40e_aqc_tx_sched_ind *cmd =
3856 (struct i40e_aqc_tx_sched_ind *)&desc.params.raw;
3857 i40e_status status;
3858 bool cmd_param_flag = false;
3859
3860 switch (opcode) {
3861 case i40e_aqc_opc_configure_vsi_ets_sla_bw_limit:
3862 case i40e_aqc_opc_configure_vsi_tc_bw:
3863 case i40e_aqc_opc_enable_switching_comp_ets:
3864 case i40e_aqc_opc_modify_switching_comp_ets:
3865 case i40e_aqc_opc_disable_switching_comp_ets:
3866 case i40e_aqc_opc_configure_switching_comp_ets_bw_limit:
3867 case i40e_aqc_opc_configure_switching_comp_bw_config:
3868 cmd_param_flag = true;
3869 break;
3870 case i40e_aqc_opc_query_vsi_bw_config:
3871 case i40e_aqc_opc_query_vsi_ets_sla_config:
3872 case i40e_aqc_opc_query_switching_comp_ets_config:
3873 case i40e_aqc_opc_query_port_ets_config:
3874 case i40e_aqc_opc_query_switching_comp_bw_config:
3875 cmd_param_flag = false;
3876 break;
3877 default:
3878 return I40E_ERR_PARAM;
3879 }
3880
3881 i40e_fill_default_direct_cmd_desc(&desc, opcode);
3882
3883 /* Indirect command */
3884 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3885 if (cmd_param_flag)
3886 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
3887 if (buff_size > I40E_AQ_LARGE_BUF)
3888 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3889
3890 desc.datalen = cpu_to_le16(buff_size);
3891
3892 cmd->vsi_seid = cpu_to_le16(seid);
3893
3894 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3895
3896 return status;
3897}
3898
3899/**
Mitch Williams6b192892014-03-06 09:02:29 +00003900 * i40e_aq_config_vsi_bw_limit - Configure VSI BW Limit
3901 * @hw: pointer to the hw struct
3902 * @seid: VSI seid
3903 * @credit: BW limit credits (0 = disabled)
3904 * @max_credit: Max BW limit credits
3905 * @cmd_details: pointer to command details structure or NULL
3906 **/
3907i40e_status i40e_aq_config_vsi_bw_limit(struct i40e_hw *hw,
3908 u16 seid, u16 credit, u8 max_credit,
3909 struct i40e_asq_cmd_details *cmd_details)
3910{
3911 struct i40e_aq_desc desc;
3912 struct i40e_aqc_configure_vsi_bw_limit *cmd =
3913 (struct i40e_aqc_configure_vsi_bw_limit *)&desc.params.raw;
3914 i40e_status status;
3915
3916 i40e_fill_default_direct_cmd_desc(&desc,
3917 i40e_aqc_opc_configure_vsi_bw_limit);
3918
3919 cmd->vsi_seid = cpu_to_le16(seid);
3920 cmd->credit = cpu_to_le16(credit);
3921 cmd->max_credit = max_credit;
3922
3923 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3924
3925 return status;
3926}
3927
3928/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003929 * i40e_aq_config_vsi_tc_bw - Config VSI BW Allocation per TC
3930 * @hw: pointer to the hw struct
3931 * @seid: VSI seid
3932 * @bw_data: Buffer holding enabled TCs, relative TC BW limit/credits
3933 * @cmd_details: pointer to command details structure or NULL
3934 **/
3935i40e_status i40e_aq_config_vsi_tc_bw(struct i40e_hw *hw,
3936 u16 seid,
3937 struct i40e_aqc_configure_vsi_tc_bw_data *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_configure_vsi_tc_bw,
3942 cmd_details);
3943}
3944
3945/**
Neerav Parikhafb3ff02014-01-17 15:36:36 -08003946 * i40e_aq_config_switch_comp_ets - Enable/Disable/Modify ETS on the port
3947 * @hw: pointer to the hw struct
3948 * @seid: seid of the switching component connected to Physical Port
3949 * @ets_data: Buffer holding ETS parameters
3950 * @cmd_details: pointer to command details structure or NULL
3951 **/
3952i40e_status i40e_aq_config_switch_comp_ets(struct i40e_hw *hw,
3953 u16 seid,
3954 struct i40e_aqc_configure_switching_comp_ets_data *ets_data,
3955 enum i40e_admin_queue_opc opcode,
3956 struct i40e_asq_cmd_details *cmd_details)
3957{
3958 return i40e_aq_tx_sched_cmd(hw, seid, (void *)ets_data,
3959 sizeof(*ets_data), opcode, cmd_details);
3960}
3961
3962/**
3963 * i40e_aq_config_switch_comp_bw_config - Config Switch comp BW Alloc per TC
3964 * @hw: pointer to the hw struct
3965 * @seid: seid of the switching component
3966 * @bw_data: Buffer holding enabled TCs, relative/absolute TC BW limit/credits
3967 * @cmd_details: pointer to command details structure or NULL
3968 **/
3969i40e_status i40e_aq_config_switch_comp_bw_config(struct i40e_hw *hw,
3970 u16 seid,
3971 struct i40e_aqc_configure_switching_comp_bw_config_data *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_configure_switching_comp_bw_config,
3976 cmd_details);
3977}
3978
3979/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003980 * i40e_aq_query_vsi_bw_config - Query VSI BW configuration
3981 * @hw: pointer to the hw struct
3982 * @seid: seid of the VSI
3983 * @bw_data: Buffer to hold VSI BW configuration
3984 * @cmd_details: pointer to command details structure or NULL
3985 **/
3986i40e_status i40e_aq_query_vsi_bw_config(struct i40e_hw *hw,
3987 u16 seid,
3988 struct i40e_aqc_query_vsi_bw_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_vsi_bw_config,
3993 cmd_details);
3994}
3995
3996/**
3997 * i40e_aq_query_vsi_ets_sla_config - Query VSI BW configuration per TC
3998 * @hw: pointer to the hw struct
3999 * @seid: seid of the VSI
4000 * @bw_data: Buffer to hold VSI BW configuration per TC
4001 * @cmd_details: pointer to command details structure or NULL
4002 **/
4003i40e_status i40e_aq_query_vsi_ets_sla_config(struct i40e_hw *hw,
4004 u16 seid,
4005 struct i40e_aqc_query_vsi_ets_sla_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_vsi_ets_sla_config,
4010 cmd_details);
4011}
4012
4013/**
4014 * i40e_aq_query_switch_comp_ets_config - Query Switch comp BW config per TC
4015 * @hw: pointer to the hw struct
4016 * @seid: seid of the switching component
4017 * @bw_data: Buffer to hold switching component's per TC BW config
4018 * @cmd_details: pointer to command details structure or NULL
4019 **/
4020i40e_status i40e_aq_query_switch_comp_ets_config(struct i40e_hw *hw,
4021 u16 seid,
4022 struct i40e_aqc_query_switching_comp_ets_config_resp *bw_data,
4023 struct i40e_asq_cmd_details *cmd_details)
4024{
4025 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
4026 i40e_aqc_opc_query_switching_comp_ets_config,
4027 cmd_details);
4028}
4029
4030/**
4031 * i40e_aq_query_port_ets_config - Query Physical Port ETS configuration
4032 * @hw: pointer to the hw struct
4033 * @seid: seid of the VSI or switching component connected to Physical Port
4034 * @bw_data: Buffer to hold current ETS configuration for the Physical Port
4035 * @cmd_details: pointer to command details structure or NULL
4036 **/
4037i40e_status i40e_aq_query_port_ets_config(struct i40e_hw *hw,
4038 u16 seid,
4039 struct i40e_aqc_query_port_ets_config_resp *bw_data,
4040 struct i40e_asq_cmd_details *cmd_details)
4041{
4042 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
4043 i40e_aqc_opc_query_port_ets_config,
4044 cmd_details);
4045}
4046
4047/**
4048 * i40e_aq_query_switch_comp_bw_config - Query Switch comp BW configuration
4049 * @hw: pointer to the hw struct
4050 * @seid: seid of the switching component
4051 * @bw_data: Buffer to hold switching component's BW configuration
4052 * @cmd_details: pointer to command details structure or NULL
4053 **/
4054i40e_status i40e_aq_query_switch_comp_bw_config(struct i40e_hw *hw,
4055 u16 seid,
4056 struct i40e_aqc_query_switching_comp_bw_config_resp *bw_data,
4057 struct i40e_asq_cmd_details *cmd_details)
4058{
4059 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
4060 i40e_aqc_opc_query_switching_comp_bw_config,
4061 cmd_details);
4062}
4063
4064/**
4065 * i40e_validate_filter_settings
4066 * @hw: pointer to the hardware structure
4067 * @settings: Filter control settings
4068 *
4069 * Check and validate the filter control settings passed.
4070 * The function checks for the valid filter/context sizes being
4071 * passed for FCoE and PE.
4072 *
4073 * Returns 0 if the values passed are valid and within
4074 * range else returns an error.
4075 **/
4076static i40e_status i40e_validate_filter_settings(struct i40e_hw *hw,
4077 struct i40e_filter_control_settings *settings)
4078{
4079 u32 fcoe_cntx_size, fcoe_filt_size;
4080 u32 pe_cntx_size, pe_filt_size;
Anjali Singhai Jain467d7292014-05-10 04:49:02 +00004081 u32 fcoe_fmax;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00004082 u32 val;
4083
4084 /* Validate FCoE settings passed */
4085 switch (settings->fcoe_filt_num) {
4086 case I40E_HASH_FILTER_SIZE_1K:
4087 case I40E_HASH_FILTER_SIZE_2K:
4088 case I40E_HASH_FILTER_SIZE_4K:
4089 case I40E_HASH_FILTER_SIZE_8K:
4090 case I40E_HASH_FILTER_SIZE_16K:
4091 case I40E_HASH_FILTER_SIZE_32K:
4092 fcoe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
4093 fcoe_filt_size <<= (u32)settings->fcoe_filt_num;
4094 break;
4095 default:
4096 return I40E_ERR_PARAM;
4097 }
4098
4099 switch (settings->fcoe_cntx_num) {
4100 case I40E_DMA_CNTX_SIZE_512:
4101 case I40E_DMA_CNTX_SIZE_1K:
4102 case I40E_DMA_CNTX_SIZE_2K:
4103 case I40E_DMA_CNTX_SIZE_4K:
4104 fcoe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
4105 fcoe_cntx_size <<= (u32)settings->fcoe_cntx_num;
4106 break;
4107 default:
4108 return I40E_ERR_PARAM;
4109 }
4110
4111 /* Validate PE settings passed */
4112 switch (settings->pe_filt_num) {
4113 case I40E_HASH_FILTER_SIZE_1K:
4114 case I40E_HASH_FILTER_SIZE_2K:
4115 case I40E_HASH_FILTER_SIZE_4K:
4116 case I40E_HASH_FILTER_SIZE_8K:
4117 case I40E_HASH_FILTER_SIZE_16K:
4118 case I40E_HASH_FILTER_SIZE_32K:
4119 case I40E_HASH_FILTER_SIZE_64K:
4120 case I40E_HASH_FILTER_SIZE_128K:
4121 case I40E_HASH_FILTER_SIZE_256K:
4122 case I40E_HASH_FILTER_SIZE_512K:
4123 case I40E_HASH_FILTER_SIZE_1M:
4124 pe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
4125 pe_filt_size <<= (u32)settings->pe_filt_num;
4126 break;
4127 default:
4128 return I40E_ERR_PARAM;
4129 }
4130
4131 switch (settings->pe_cntx_num) {
4132 case I40E_DMA_CNTX_SIZE_512:
4133 case I40E_DMA_CNTX_SIZE_1K:
4134 case I40E_DMA_CNTX_SIZE_2K:
4135 case I40E_DMA_CNTX_SIZE_4K:
4136 case I40E_DMA_CNTX_SIZE_8K:
4137 case I40E_DMA_CNTX_SIZE_16K:
4138 case I40E_DMA_CNTX_SIZE_32K:
4139 case I40E_DMA_CNTX_SIZE_64K:
4140 case I40E_DMA_CNTX_SIZE_128K:
4141 case I40E_DMA_CNTX_SIZE_256K:
4142 pe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
4143 pe_cntx_size <<= (u32)settings->pe_cntx_num;
4144 break;
4145 default:
4146 return I40E_ERR_PARAM;
4147 }
4148
4149 /* FCHSIZE + FCDSIZE should not be greater than PMFCOEFMAX */
4150 val = rd32(hw, I40E_GLHMC_FCOEFMAX);
4151 fcoe_fmax = (val & I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_MASK)
4152 >> I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_SHIFT;
4153 if (fcoe_filt_size + fcoe_cntx_size > fcoe_fmax)
4154 return I40E_ERR_INVALID_SIZE;
4155
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00004156 return 0;
4157}
4158
4159/**
4160 * i40e_set_filter_control
4161 * @hw: pointer to the hardware structure
4162 * @settings: Filter control settings
4163 *
4164 * Set the Queue Filters for PE/FCoE and enable filters required
4165 * for a single PF. It is expected that these settings are programmed
4166 * at the driver initialization time.
4167 **/
4168i40e_status i40e_set_filter_control(struct i40e_hw *hw,
4169 struct i40e_filter_control_settings *settings)
4170{
4171 i40e_status ret = 0;
4172 u32 hash_lut_size = 0;
4173 u32 val;
4174
4175 if (!settings)
4176 return I40E_ERR_PARAM;
4177
4178 /* Validate the input settings */
4179 ret = i40e_validate_filter_settings(hw, settings);
4180 if (ret)
4181 return ret;
4182
4183 /* Read the PF Queue Filter control register */
Shannon Nelsonf6581372016-02-17 16:12:20 -08004184 val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00004185
4186 /* Program required PE hash buckets for the PF */
4187 val &= ~I40E_PFQF_CTL_0_PEHSIZE_MASK;
4188 val |= ((u32)settings->pe_filt_num << I40E_PFQF_CTL_0_PEHSIZE_SHIFT) &
4189 I40E_PFQF_CTL_0_PEHSIZE_MASK;
4190 /* Program required PE contexts for the PF */
4191 val &= ~I40E_PFQF_CTL_0_PEDSIZE_MASK;
4192 val |= ((u32)settings->pe_cntx_num << I40E_PFQF_CTL_0_PEDSIZE_SHIFT) &
4193 I40E_PFQF_CTL_0_PEDSIZE_MASK;
4194
4195 /* Program required FCoE hash buckets for the PF */
4196 val &= ~I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
4197 val |= ((u32)settings->fcoe_filt_num <<
4198 I40E_PFQF_CTL_0_PFFCHSIZE_SHIFT) &
4199 I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
4200 /* Program required FCoE DDP contexts for the PF */
4201 val &= ~I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
4202 val |= ((u32)settings->fcoe_cntx_num <<
4203 I40E_PFQF_CTL_0_PFFCDSIZE_SHIFT) &
4204 I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
4205
4206 /* Program Hash LUT size for the PF */
4207 val &= ~I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
4208 if (settings->hash_lut_size == I40E_HASH_LUT_SIZE_512)
4209 hash_lut_size = 1;
4210 val |= (hash_lut_size << I40E_PFQF_CTL_0_HASHLUTSIZE_SHIFT) &
4211 I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
4212
4213 /* Enable FDIR, Ethertype and MACVLAN filters for PF and VFs */
4214 if (settings->enable_fdir)
4215 val |= I40E_PFQF_CTL_0_FD_ENA_MASK;
4216 if (settings->enable_ethtype)
4217 val |= I40E_PFQF_CTL_0_ETYPE_ENA_MASK;
4218 if (settings->enable_macvlan)
4219 val |= I40E_PFQF_CTL_0_MACVLAN_ENA_MASK;
4220
Shannon Nelsonf6581372016-02-17 16:12:20 -08004221 i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, val);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00004222
4223 return 0;
4224}
Neerav Parikhafb3ff02014-01-17 15:36:36 -08004225
4226/**
4227 * i40e_aq_add_rem_control_packet_filter - Add or Remove Control Packet Filter
4228 * @hw: pointer to the hw struct
4229 * @mac_addr: MAC address to use in the filter
4230 * @ethtype: Ethertype to use in the filter
4231 * @flags: Flags that needs to be applied to the filter
4232 * @vsi_seid: seid of the control VSI
4233 * @queue: VSI queue number to send the packet to
4234 * @is_add: Add control packet filter if True else remove
4235 * @stats: Structure to hold information on control filter counts
4236 * @cmd_details: pointer to command details structure or NULL
4237 *
4238 * This command will Add or Remove control packet filter for a control VSI.
4239 * In return it will update the total number of perfect filter count in
4240 * the stats member.
4241 **/
4242i40e_status i40e_aq_add_rem_control_packet_filter(struct i40e_hw *hw,
4243 u8 *mac_addr, u16 ethtype, u16 flags,
4244 u16 vsi_seid, u16 queue, bool is_add,
4245 struct i40e_control_filter_stats *stats,
4246 struct i40e_asq_cmd_details *cmd_details)
4247{
4248 struct i40e_aq_desc desc;
4249 struct i40e_aqc_add_remove_control_packet_filter *cmd =
4250 (struct i40e_aqc_add_remove_control_packet_filter *)
4251 &desc.params.raw;
4252 struct i40e_aqc_add_remove_control_packet_filter_completion *resp =
4253 (struct i40e_aqc_add_remove_control_packet_filter_completion *)
4254 &desc.params.raw;
4255 i40e_status status;
4256
4257 if (vsi_seid == 0)
4258 return I40E_ERR_PARAM;
4259
4260 if (is_add) {
4261 i40e_fill_default_direct_cmd_desc(&desc,
4262 i40e_aqc_opc_add_control_packet_filter);
4263 cmd->queue = cpu_to_le16(queue);
4264 } else {
4265 i40e_fill_default_direct_cmd_desc(&desc,
4266 i40e_aqc_opc_remove_control_packet_filter);
4267 }
4268
4269 if (mac_addr)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04004270 ether_addr_copy(cmd->mac, mac_addr);
Neerav Parikhafb3ff02014-01-17 15:36:36 -08004271
4272 cmd->etype = cpu_to_le16(ethtype);
4273 cmd->flags = cpu_to_le16(flags);
4274 cmd->seid = cpu_to_le16(vsi_seid);
4275
4276 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4277
4278 if (!status && stats) {
4279 stats->mac_etype_used = le16_to_cpu(resp->mac_etype_used);
4280 stats->etype_used = le16_to_cpu(resp->etype_used);
4281 stats->mac_etype_free = le16_to_cpu(resp->mac_etype_free);
4282 stats->etype_free = le16_to_cpu(resp->etype_free);
4283 }
4284
4285 return status;
4286}
4287
Catherine Sullivand4dfb812013-11-28 06:39:21 +00004288/**
Anjali Singhai Jaine7358f52015-10-01 14:37:34 -04004289 * i40e_add_filter_to_drop_tx_flow_control_frames- filter to drop flow control
4290 * @hw: pointer to the hw struct
4291 * @seid: VSI seid to add ethertype filter from
4292 **/
4293#define I40E_FLOW_CONTROL_ETHTYPE 0x8808
4294void i40e_add_filter_to_drop_tx_flow_control_frames(struct i40e_hw *hw,
4295 u16 seid)
4296{
4297 u16 flag = I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC |
4298 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP |
4299 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX;
4300 u16 ethtype = I40E_FLOW_CONTROL_ETHTYPE;
4301 i40e_status status;
4302
4303 status = i40e_aq_add_rem_control_packet_filter(hw, NULL, ethtype, flag,
4304 seid, 0, true, NULL,
4305 NULL);
4306 if (status)
4307 hw_dbg(hw, "Ethtype Filter Add failed: Error pruning Tx flow control frames\n");
4308}
4309
4310/**
Greg Rosef4492db2015-02-06 08:52:12 +00004311 * i40e_aq_alternate_read
4312 * @hw: pointer to the hardware structure
4313 * @reg_addr0: address of first dword to be read
4314 * @reg_val0: pointer for data read from 'reg_addr0'
4315 * @reg_addr1: address of second dword to be read
4316 * @reg_val1: pointer for data read from 'reg_addr1'
4317 *
4318 * Read one or two dwords from alternate structure. Fields are indicated
4319 * by 'reg_addr0' and 'reg_addr1' register numbers. If 'reg_val1' pointer
4320 * is not passed then only register at 'reg_addr0' is read.
4321 *
4322 **/
Shannon Nelson37a29732015-02-27 09:15:19 +00004323static i40e_status i40e_aq_alternate_read(struct i40e_hw *hw,
4324 u32 reg_addr0, u32 *reg_val0,
4325 u32 reg_addr1, u32 *reg_val1)
Greg Rosef4492db2015-02-06 08:52:12 +00004326{
4327 struct i40e_aq_desc desc;
4328 struct i40e_aqc_alternate_write *cmd_resp =
4329 (struct i40e_aqc_alternate_write *)&desc.params.raw;
4330 i40e_status status;
4331
4332 if (!reg_val0)
4333 return I40E_ERR_PARAM;
4334
4335 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_alternate_read);
4336 cmd_resp->address0 = cpu_to_le32(reg_addr0);
4337 cmd_resp->address1 = cpu_to_le32(reg_addr1);
4338
4339 status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
4340
4341 if (!status) {
4342 *reg_val0 = le32_to_cpu(cmd_resp->data0);
4343
4344 if (reg_val1)
4345 *reg_val1 = le32_to_cpu(cmd_resp->data1);
4346 }
4347
4348 return status;
4349}
4350
4351/**
Neerav Parikh2fd75f32014-11-12 00:18:20 +00004352 * i40e_aq_resume_port_tx
4353 * @hw: pointer to the hardware structure
4354 * @cmd_details: pointer to command details structure or NULL
4355 *
4356 * Resume port's Tx traffic
4357 **/
4358i40e_status i40e_aq_resume_port_tx(struct i40e_hw *hw,
4359 struct i40e_asq_cmd_details *cmd_details)
4360{
4361 struct i40e_aq_desc desc;
4362 i40e_status status;
4363
4364 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_resume_port_tx);
4365
4366 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4367
4368 return status;
4369}
4370
4371/**
Catherine Sullivand4dfb812013-11-28 06:39:21 +00004372 * i40e_set_pci_config_data - store PCI bus info
4373 * @hw: pointer to hardware structure
4374 * @link_status: the link status word from PCI config space
4375 *
4376 * Stores the PCI bus info (speed, width, type) within the i40e_hw structure
4377 **/
4378void i40e_set_pci_config_data(struct i40e_hw *hw, u16 link_status)
4379{
4380 hw->bus.type = i40e_bus_type_pci_express;
4381
4382 switch (link_status & PCI_EXP_LNKSTA_NLW) {
4383 case PCI_EXP_LNKSTA_NLW_X1:
4384 hw->bus.width = i40e_bus_width_pcie_x1;
4385 break;
4386 case PCI_EXP_LNKSTA_NLW_X2:
4387 hw->bus.width = i40e_bus_width_pcie_x2;
4388 break;
4389 case PCI_EXP_LNKSTA_NLW_X4:
4390 hw->bus.width = i40e_bus_width_pcie_x4;
4391 break;
4392 case PCI_EXP_LNKSTA_NLW_X8:
4393 hw->bus.width = i40e_bus_width_pcie_x8;
4394 break;
4395 default:
4396 hw->bus.width = i40e_bus_width_unknown;
4397 break;
4398 }
4399
4400 switch (link_status & PCI_EXP_LNKSTA_CLS) {
4401 case PCI_EXP_LNKSTA_CLS_2_5GB:
4402 hw->bus.speed = i40e_bus_speed_2500;
4403 break;
4404 case PCI_EXP_LNKSTA_CLS_5_0GB:
4405 hw->bus.speed = i40e_bus_speed_5000;
4406 break;
4407 case PCI_EXP_LNKSTA_CLS_8_0GB:
4408 hw->bus.speed = i40e_bus_speed_8000;
4409 break;
4410 default:
4411 hw->bus.speed = i40e_bus_speed_unknown;
4412 break;
4413 }
4414}
Greg Rosef4492db2015-02-06 08:52:12 +00004415
4416/**
Jesse Brandeburg3169c322015-04-07 19:45:37 -04004417 * i40e_aq_debug_dump
4418 * @hw: pointer to the hardware structure
4419 * @cluster_id: specific cluster to dump
4420 * @table_id: table id within cluster
4421 * @start_index: index of line in the block to read
4422 * @buff_size: dump buffer size
4423 * @buff: dump buffer
4424 * @ret_buff_size: actual buffer size returned
4425 * @ret_next_table: next block to read
4426 * @ret_next_index: next index to read
4427 *
4428 * Dump internal FW/HW data for debug purposes.
4429 *
4430 **/
4431i40e_status i40e_aq_debug_dump(struct i40e_hw *hw, u8 cluster_id,
4432 u8 table_id, u32 start_index, u16 buff_size,
4433 void *buff, u16 *ret_buff_size,
4434 u8 *ret_next_table, u32 *ret_next_index,
4435 struct i40e_asq_cmd_details *cmd_details)
4436{
4437 struct i40e_aq_desc desc;
4438 struct i40e_aqc_debug_dump_internals *cmd =
4439 (struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
4440 struct i40e_aqc_debug_dump_internals *resp =
4441 (struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
4442 i40e_status status;
4443
4444 if (buff_size == 0 || !buff)
4445 return I40E_ERR_PARAM;
4446
4447 i40e_fill_default_direct_cmd_desc(&desc,
4448 i40e_aqc_opc_debug_dump_internals);
4449 /* Indirect Command */
4450 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
4451 if (buff_size > I40E_AQ_LARGE_BUF)
4452 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
4453
4454 cmd->cluster_id = cluster_id;
4455 cmd->table_id = table_id;
4456 cmd->idx = cpu_to_le32(start_index);
4457
4458 desc.datalen = cpu_to_le16(buff_size);
4459
4460 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
4461 if (!status) {
4462 if (ret_buff_size)
4463 *ret_buff_size = le16_to_cpu(desc.datalen);
4464 if (ret_next_table)
4465 *ret_next_table = resp->table_id;
4466 if (ret_next_index)
4467 *ret_next_index = le32_to_cpu(resp->idx);
4468 }
4469
4470 return status;
4471}
4472
4473/**
Greg Rosef4492db2015-02-06 08:52:12 +00004474 * i40e_read_bw_from_alt_ram
4475 * @hw: pointer to the hardware structure
4476 * @max_bw: pointer for max_bw read
4477 * @min_bw: pointer for min_bw read
4478 * @min_valid: pointer for bool that is true if min_bw is a valid value
4479 * @max_valid: pointer for bool that is true if max_bw is a valid value
4480 *
4481 * Read bw from the alternate ram for the given pf
4482 **/
4483i40e_status i40e_read_bw_from_alt_ram(struct i40e_hw *hw,
4484 u32 *max_bw, u32 *min_bw,
4485 bool *min_valid, bool *max_valid)
4486{
4487 i40e_status status;
4488 u32 max_bw_addr, min_bw_addr;
4489
4490 /* Calculate the address of the min/max bw registers */
4491 max_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
4492 I40E_ALT_STRUCT_MAX_BW_OFFSET +
4493 (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
4494 min_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
4495 I40E_ALT_STRUCT_MIN_BW_OFFSET +
4496 (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
4497
4498 /* Read the bandwidths from alt ram */
4499 status = i40e_aq_alternate_read(hw, max_bw_addr, max_bw,
4500 min_bw_addr, min_bw);
4501
4502 if (*min_bw & I40E_ALT_BW_VALID_MASK)
4503 *min_valid = true;
4504 else
4505 *min_valid = false;
4506
4507 if (*max_bw & I40E_ALT_BW_VALID_MASK)
4508 *max_valid = true;
4509 else
4510 *max_valid = false;
4511
4512 return status;
4513}
4514
4515/**
4516 * i40e_aq_configure_partition_bw
4517 * @hw: pointer to the hardware structure
4518 * @bw_data: Buffer holding valid pfs and bw limits
4519 * @cmd_details: pointer to command details
4520 *
4521 * Configure partitions guaranteed/max bw
4522 **/
4523i40e_status i40e_aq_configure_partition_bw(struct i40e_hw *hw,
4524 struct i40e_aqc_configure_partition_bw_data *bw_data,
4525 struct i40e_asq_cmd_details *cmd_details)
4526{
4527 i40e_status status;
4528 struct i40e_aq_desc desc;
4529 u16 bwd_size = sizeof(*bw_data);
4530
4531 i40e_fill_default_direct_cmd_desc(&desc,
4532 i40e_aqc_opc_configure_partition_bw);
4533
4534 /* Indirect command */
4535 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
4536 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
4537
4538 if (bwd_size > I40E_AQ_LARGE_BUF)
4539 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
4540
4541 desc.datalen = cpu_to_le16(bwd_size);
4542
4543 status = i40e_asq_send_command(hw, &desc, bw_data, bwd_size,
4544 cmd_details);
4545
4546 return status;
4547}
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004548
4549/**
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004550 * i40e_read_phy_register_clause22
4551 * @hw: pointer to the HW structure
4552 * @reg: register address in the page
4553 * @phy_adr: PHY address on MDIO interface
4554 * @value: PHY register value
4555 *
4556 * Reads specified PHY register value
4557 **/
4558i40e_status i40e_read_phy_register_clause22(struct i40e_hw *hw,
4559 u16 reg, u8 phy_addr, u16 *value)
4560{
4561 i40e_status status = I40E_ERR_TIMEOUT;
4562 u8 port_num = (u8)hw->func_caps.mdio_port_num;
4563 u32 command = 0;
4564 u16 retry = 1000;
4565
4566 command = (reg << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4567 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
4568 (I40E_MDIO_CLAUSE22_OPCODE_READ_MASK) |
4569 (I40E_MDIO_CLAUSE22_STCODE_MASK) |
4570 (I40E_GLGEN_MSCA_MDICMD_MASK);
4571 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4572 do {
4573 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4574 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4575 status = 0;
4576 break;
4577 }
4578 udelay(10);
4579 retry--;
4580 } while (retry);
4581
4582 if (status) {
4583 i40e_debug(hw, I40E_DEBUG_PHY,
4584 "PHY: Can't write command to external PHY.\n");
Henry Tieman27e5f252016-11-08 13:05:06 -08004585 } else {
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004586 command = rd32(hw, I40E_GLGEN_MSRWD(port_num));
4587 *value = (command & I40E_GLGEN_MSRWD_MDIRDDATA_MASK) >>
4588 I40E_GLGEN_MSRWD_MDIRDDATA_SHIFT;
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004589 }
4590
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004591 return status;
4592}
4593
4594/**
4595 * i40e_write_phy_register_clause22
4596 * @hw: pointer to the HW structure
4597 * @reg: register address in the page
4598 * @phy_adr: PHY address on MDIO interface
4599 * @value: PHY register value
4600 *
4601 * Writes specified PHY register value
4602 **/
4603i40e_status i40e_write_phy_register_clause22(struct i40e_hw *hw,
4604 u16 reg, u8 phy_addr, u16 value)
4605{
4606 i40e_status status = I40E_ERR_TIMEOUT;
4607 u8 port_num = (u8)hw->func_caps.mdio_port_num;
4608 u32 command = 0;
4609 u16 retry = 1000;
4610
4611 command = value << I40E_GLGEN_MSRWD_MDIWRDATA_SHIFT;
4612 wr32(hw, I40E_GLGEN_MSRWD(port_num), command);
4613
4614 command = (reg << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4615 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
4616 (I40E_MDIO_CLAUSE22_OPCODE_WRITE_MASK) |
4617 (I40E_MDIO_CLAUSE22_STCODE_MASK) |
4618 (I40E_GLGEN_MSCA_MDICMD_MASK);
4619
4620 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4621 do {
4622 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4623 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4624 status = 0;
4625 break;
4626 }
4627 udelay(10);
4628 retry--;
4629 } while (retry);
4630
4631 return status;
4632}
4633
4634/**
4635 * i40e_read_phy_register_clause45
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004636 * @hw: pointer to the HW structure
4637 * @page: registers page number
4638 * @reg: register address in the page
4639 * @phy_adr: PHY address on MDIO interface
4640 * @value: PHY register value
4641 *
4642 * Reads specified PHY register value
4643 **/
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004644i40e_status i40e_read_phy_register_clause45(struct i40e_hw *hw,
4645 u8 page, u16 reg, u8 phy_addr, u16 *value)
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004646{
4647 i40e_status status = I40E_ERR_TIMEOUT;
4648 u32 command = 0;
4649 u16 retry = 1000;
4650 u8 port_num = hw->func_caps.mdio_port_num;
4651
4652 command = (reg << I40E_GLGEN_MSCA_MDIADD_SHIFT) |
4653 (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4654 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004655 (I40E_MDIO_CLAUSE45_OPCODE_ADDRESS_MASK) |
4656 (I40E_MDIO_CLAUSE45_STCODE_MASK) |
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004657 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4658 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4659 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4660 do {
4661 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4662 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4663 status = 0;
4664 break;
4665 }
4666 usleep_range(10, 20);
4667 retry--;
4668 } while (retry);
4669
4670 if (status) {
4671 i40e_debug(hw, I40E_DEBUG_PHY,
4672 "PHY: Can't write command to external PHY.\n");
4673 goto phy_read_end;
4674 }
4675
4676 command = (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_READ_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 status = I40E_ERR_TIMEOUT;
4683 retry = 1000;
4684 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4685 do {
4686 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4687 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4688 status = 0;
4689 break;
4690 }
4691 usleep_range(10, 20);
4692 retry--;
4693 } while (retry);
4694
4695 if (!status) {
4696 command = rd32(hw, I40E_GLGEN_MSRWD(port_num));
4697 *value = (command & I40E_GLGEN_MSRWD_MDIRDDATA_MASK) >>
4698 I40E_GLGEN_MSRWD_MDIRDDATA_SHIFT;
4699 } else {
4700 i40e_debug(hw, I40E_DEBUG_PHY,
4701 "PHY: Can't read register value from external PHY.\n");
4702 }
4703
4704phy_read_end:
4705 return status;
4706}
4707
4708/**
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004709 * i40e_write_phy_register_clause45
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004710 * @hw: pointer to the HW structure
4711 * @page: registers page number
4712 * @reg: register address in the page
4713 * @phy_adr: PHY address on MDIO interface
4714 * @value: PHY register value
4715 *
4716 * Writes value to specified PHY register
4717 **/
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004718i40e_status i40e_write_phy_register_clause45(struct i40e_hw *hw,
4719 u8 page, u16 reg, u8 phy_addr, u16 value)
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004720{
4721 i40e_status status = I40E_ERR_TIMEOUT;
4722 u32 command = 0;
4723 u16 retry = 1000;
4724 u8 port_num = hw->func_caps.mdio_port_num;
4725
4726 command = (reg << I40E_GLGEN_MSCA_MDIADD_SHIFT) |
4727 (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4728 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004729 (I40E_MDIO_CLAUSE45_OPCODE_ADDRESS_MASK) |
4730 (I40E_MDIO_CLAUSE45_STCODE_MASK) |
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004731 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4732 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4733 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4734 do {
4735 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4736 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4737 status = 0;
4738 break;
4739 }
4740 usleep_range(10, 20);
4741 retry--;
4742 } while (retry);
4743 if (status) {
4744 i40e_debug(hw, I40E_DEBUG_PHY,
4745 "PHY: Can't write command to external PHY.\n");
4746 goto phy_write_end;
4747 }
4748
4749 command = value << I40E_GLGEN_MSRWD_MDIWRDATA_SHIFT;
4750 wr32(hw, I40E_GLGEN_MSRWD(port_num), command);
4751
4752 command = (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4753 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004754 (I40E_MDIO_CLAUSE45_OPCODE_WRITE_MASK) |
4755 (I40E_MDIO_CLAUSE45_STCODE_MASK) |
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004756 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4757 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4758 status = I40E_ERR_TIMEOUT;
4759 retry = 1000;
4760 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4761 do {
4762 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4763 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4764 status = 0;
4765 break;
4766 }
4767 usleep_range(10, 20);
4768 retry--;
4769 } while (retry);
4770
4771phy_write_end:
4772 return status;
4773}
4774
4775/**
Michal Kosiarzf62ba912016-11-21 13:03:50 -08004776 * i40e_write_phy_register
4777 * @hw: pointer to the HW structure
4778 * @page: registers page number
4779 * @reg: register address in the page
4780 * @phy_adr: PHY address on MDIO interface
4781 * @value: PHY register value
4782 *
4783 * Writes value to specified PHY register
4784 **/
4785i40e_status i40e_write_phy_register(struct i40e_hw *hw,
4786 u8 page, u16 reg, u8 phy_addr, u16 value)
4787{
4788 i40e_status status;
4789
4790 switch (hw->device_id) {
4791 case I40E_DEV_ID_1G_BASE_T_X722:
4792 status = i40e_write_phy_register_clause22(hw, reg, phy_addr,
4793 value);
4794 break;
4795 case I40E_DEV_ID_10G_BASE_T:
4796 case I40E_DEV_ID_10G_BASE_T4:
4797 case I40E_DEV_ID_10G_BASE_T_X722:
4798 case I40E_DEV_ID_25G_B:
4799 case I40E_DEV_ID_25G_SFP28:
4800 status = i40e_write_phy_register_clause45(hw, page, reg,
4801 phy_addr, value);
4802 break;
4803 default:
4804 status = I40E_ERR_UNKNOWN_PHY;
4805 break;
4806 }
4807
4808 return status;
4809}
4810
4811/**
4812 * i40e_read_phy_register
4813 * @hw: pointer to the HW structure
4814 * @page: registers page number
4815 * @reg: register address in the page
4816 * @phy_adr: PHY address on MDIO interface
4817 * @value: PHY register value
4818 *
4819 * Reads specified PHY register value
4820 **/
4821i40e_status i40e_read_phy_register(struct i40e_hw *hw,
4822 u8 page, u16 reg, u8 phy_addr, u16 *value)
4823{
4824 i40e_status status;
4825
4826 switch (hw->device_id) {
4827 case I40E_DEV_ID_1G_BASE_T_X722:
4828 status = i40e_read_phy_register_clause22(hw, reg, phy_addr,
4829 value);
4830 break;
4831 case I40E_DEV_ID_10G_BASE_T:
4832 case I40E_DEV_ID_10G_BASE_T4:
4833 case I40E_DEV_ID_10G_BASE_T_X722:
4834 case I40E_DEV_ID_25G_B:
4835 case I40E_DEV_ID_25G_SFP28:
4836 status = i40e_read_phy_register_clause45(hw, page, reg,
4837 phy_addr, value);
4838 break;
4839 default:
4840 status = I40E_ERR_UNKNOWN_PHY;
4841 break;
4842 }
4843
4844 return status;
4845}
4846
4847/**
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004848 * i40e_get_phy_address
4849 * @hw: pointer to the HW structure
4850 * @dev_num: PHY port num that address we want
4851 * @phy_addr: Returned PHY address
4852 *
4853 * Gets PHY address for current port
4854 **/
4855u8 i40e_get_phy_address(struct i40e_hw *hw, u8 dev_num)
4856{
4857 u8 port_num = hw->func_caps.mdio_port_num;
4858 u32 reg_val = rd32(hw, I40E_GLGEN_MDIO_I2C_SEL(port_num));
4859
4860 return (u8)(reg_val >> ((dev_num + 1) * 5)) & 0x1f;
4861}
4862
4863/**
4864 * i40e_blink_phy_led
4865 * @hw: pointer to the HW structure
4866 * @time: time how long led will blinks in secs
4867 * @interval: gap between LED on and off in msecs
4868 *
4869 * Blinks PHY link LED
4870 **/
4871i40e_status i40e_blink_phy_link_led(struct i40e_hw *hw,
4872 u32 time, u32 interval)
4873{
4874 i40e_status status = 0;
4875 u32 i;
4876 u16 led_ctl;
4877 u16 gpio_led_port;
4878 u16 led_reg;
4879 u16 led_addr = I40E_PHY_LED_PROV_REG_1;
4880 u8 phy_addr = 0;
4881 u8 port_num;
4882
4883 i = rd32(hw, I40E_PFGEN_PORTNUM);
4884 port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
4885 phy_addr = i40e_get_phy_address(hw, port_num);
4886
4887 for (gpio_led_port = 0; gpio_led_port < 3; gpio_led_port++,
4888 led_addr++) {
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004889 status = i40e_read_phy_register_clause45(hw,
4890 I40E_PHY_COM_REG_PAGE,
4891 led_addr, phy_addr,
4892 &led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004893 if (status)
4894 goto phy_blinking_end;
4895 led_ctl = led_reg;
4896 if (led_reg & I40E_PHY_LED_LINK_MODE_MASK) {
4897 led_reg = 0;
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004898 status = i40e_write_phy_register_clause45(hw,
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004899 I40E_PHY_COM_REG_PAGE,
4900 led_addr, phy_addr,
4901 led_reg);
4902 if (status)
4903 goto phy_blinking_end;
4904 break;
4905 }
4906 }
4907
4908 if (time > 0 && interval > 0) {
4909 for (i = 0; i < time * 1000; i += interval) {
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004910 status = i40e_read_phy_register_clause45(hw,
4911 I40E_PHY_COM_REG_PAGE,
4912 led_addr, phy_addr, &led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004913 if (status)
4914 goto restore_config;
4915 if (led_reg & I40E_PHY_LED_MANUAL_ON)
4916 led_reg = 0;
4917 else
4918 led_reg = I40E_PHY_LED_MANUAL_ON;
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004919 status = i40e_write_phy_register_clause45(hw,
4920 I40E_PHY_COM_REG_PAGE,
4921 led_addr, phy_addr, led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004922 if (status)
4923 goto restore_config;
4924 msleep(interval);
4925 }
4926 }
4927
4928restore_config:
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004929 status = i40e_write_phy_register_clause45(hw,
4930 I40E_PHY_COM_REG_PAGE,
4931 led_addr, phy_addr, led_ctl);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004932
4933phy_blinking_end:
4934 return status;
4935}
4936
4937/**
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04004938 * i40e_led_get_reg - read LED register
4939 * @hw: pointer to the HW structure
4940 * @led_addr: LED register address
4941 * @reg_val: read register value
4942 **/
4943static enum i40e_status_code i40e_led_get_reg(struct i40e_hw *hw, u16 led_addr,
4944 u32 *reg_val)
4945{
4946 enum i40e_status_code status;
4947 u8 phy_addr = 0;
4948 u8 port_num;
4949 u32 i;
4950
4951 *reg_val = 0;
4952 if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) {
4953 status =
4954 i40e_aq_get_phy_register(hw,
4955 I40E_AQ_PHY_REG_ACCESS_EXTERNAL,
4956 I40E_PHY_COM_REG_PAGE,
4957 I40E_PHY_LED_PROV_REG_1,
4958 reg_val, NULL);
4959 } else {
4960 i = rd32(hw, I40E_PFGEN_PORTNUM);
4961 port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
4962 phy_addr = i40e_get_phy_address(hw, port_num);
4963 status = i40e_read_phy_register_clause45(hw,
4964 I40E_PHY_COM_REG_PAGE,
4965 led_addr, phy_addr,
4966 (u16 *)reg_val);
4967 }
4968 return status;
4969}
4970
4971/**
4972 * i40e_led_set_reg - write LED register
4973 * @hw: pointer to the HW structure
4974 * @led_addr: LED register address
4975 * @reg_val: register value to write
4976 **/
4977static enum i40e_status_code i40e_led_set_reg(struct i40e_hw *hw, u16 led_addr,
4978 u32 reg_val)
4979{
4980 enum i40e_status_code status;
4981 u8 phy_addr = 0;
4982 u8 port_num;
4983 u32 i;
4984
4985 if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) {
4986 status =
4987 i40e_aq_set_phy_register(hw,
4988 I40E_AQ_PHY_REG_ACCESS_EXTERNAL,
4989 I40E_PHY_COM_REG_PAGE,
4990 I40E_PHY_LED_PROV_REG_1,
4991 reg_val, NULL);
4992 } else {
4993 i = rd32(hw, I40E_PFGEN_PORTNUM);
4994 port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
4995 phy_addr = i40e_get_phy_address(hw, port_num);
4996 status = i40e_write_phy_register_clause45(hw,
4997 I40E_PHY_COM_REG_PAGE,
4998 led_addr, phy_addr,
4999 (u16)reg_val);
5000 }
5001
5002 return status;
5003}
5004
5005/**
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005006 * i40e_led_get_phy - return current on/off mode
5007 * @hw: pointer to the hw struct
5008 * @led_addr: address of led register to use
5009 * @val: original value of register to use
5010 *
5011 **/
5012i40e_status i40e_led_get_phy(struct i40e_hw *hw, u16 *led_addr,
5013 u16 *val)
5014{
5015 i40e_status status = 0;
5016 u16 gpio_led_port;
5017 u8 phy_addr = 0;
5018 u16 reg_val;
5019 u16 temp_addr;
5020 u8 port_num;
5021 u32 i;
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005022 u32 reg_val_aq;
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005023
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005024 if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) {
5025 status =
5026 i40e_aq_get_phy_register(hw,
5027 I40E_AQ_PHY_REG_ACCESS_EXTERNAL,
5028 I40E_PHY_COM_REG_PAGE,
5029 I40E_PHY_LED_PROV_REG_1,
5030 &reg_val_aq, NULL);
5031 if (status == I40E_SUCCESS)
5032 *val = (u16)reg_val_aq;
5033 return status;
5034 }
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005035 temp_addr = I40E_PHY_LED_PROV_REG_1;
5036 i = rd32(hw, I40E_PFGEN_PORTNUM);
5037 port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
5038 phy_addr = i40e_get_phy_address(hw, port_num);
5039
5040 for (gpio_led_port = 0; gpio_led_port < 3; gpio_led_port++,
5041 temp_addr++) {
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07005042 status = i40e_read_phy_register_clause45(hw,
5043 I40E_PHY_COM_REG_PAGE,
5044 temp_addr, phy_addr,
5045 &reg_val);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005046 if (status)
5047 return status;
5048 *val = reg_val;
5049 if (reg_val & I40E_PHY_LED_LINK_MODE_MASK) {
5050 *led_addr = temp_addr;
5051 break;
5052 }
5053 }
5054 return status;
5055}
5056
5057/**
5058 * i40e_led_set_phy
5059 * @hw: pointer to the HW structure
5060 * @on: true or false
5061 * @mode: original val plus bit for set or ignore
5062 * Set led's on or off when controlled by the PHY
5063 *
5064 **/
5065i40e_status i40e_led_set_phy(struct i40e_hw *hw, bool on,
5066 u16 led_addr, u32 mode)
5067{
5068 i40e_status status = 0;
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005069 u32 led_ctl = 0;
5070 u32 led_reg = 0;
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005071
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005072 status = i40e_led_get_reg(hw, led_addr, &led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005073 if (status)
5074 return status;
5075 led_ctl = led_reg;
5076 if (led_reg & I40E_PHY_LED_LINK_MODE_MASK) {
5077 led_reg = 0;
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005078 status = i40e_led_set_reg(hw, led_addr, led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005079 if (status)
5080 return status;
5081 }
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005082 status = i40e_led_get_reg(hw, led_addr, &led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005083 if (status)
5084 goto restore_config;
5085 if (on)
5086 led_reg = I40E_PHY_LED_MANUAL_ON;
5087 else
5088 led_reg = 0;
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005089
5090 status = i40e_led_set_reg(hw, led_addr, led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005091 if (status)
5092 goto restore_config;
5093 if (mode & I40E_PHY_LED_MODE_ORIG) {
5094 led_ctl = (mode & I40E_PHY_LED_MODE_MASK);
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005095 status = i40e_led_set_reg(hw, led_addr, led_ctl);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005096 }
5097 return status;
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005098
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005099restore_config:
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005100 status = i40e_led_set_reg(hw, led_addr, led_ctl);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005101 return status;
5102}
Shannon Nelsonf6581372016-02-17 16:12:20 -08005103
5104/**
5105 * i40e_aq_rx_ctl_read_register - use FW to read from an Rx control register
5106 * @hw: pointer to the hw struct
5107 * @reg_addr: register address
5108 * @reg_val: ptr to register value
5109 * @cmd_details: pointer to command details structure or NULL
5110 *
5111 * Use the firmware to read the Rx control register,
5112 * especially useful if the Rx unit is under heavy pressure
5113 **/
5114i40e_status i40e_aq_rx_ctl_read_register(struct i40e_hw *hw,
5115 u32 reg_addr, u32 *reg_val,
5116 struct i40e_asq_cmd_details *cmd_details)
5117{
5118 struct i40e_aq_desc desc;
5119 struct i40e_aqc_rx_ctl_reg_read_write *cmd_resp =
5120 (struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
5121 i40e_status status;
5122
5123 if (!reg_val)
5124 return I40E_ERR_PARAM;
5125
5126 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_rx_ctl_reg_read);
5127
5128 cmd_resp->address = cpu_to_le32(reg_addr);
5129
5130 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5131
5132 if (status == 0)
5133 *reg_val = le32_to_cpu(cmd_resp->value);
5134
5135 return status;
5136}
5137
5138/**
5139 * i40e_read_rx_ctl - read from an Rx control register
5140 * @hw: pointer to the hw struct
5141 * @reg_addr: register address
5142 **/
5143u32 i40e_read_rx_ctl(struct i40e_hw *hw, u32 reg_addr)
5144{
5145 i40e_status status = 0;
5146 bool use_register;
5147 int retry = 5;
5148 u32 val = 0;
5149
Paul M Stillwell Jr60303082017-03-10 12:22:02 -08005150 use_register = (((hw->aq.api_maj_ver == 1) &&
5151 (hw->aq.api_min_ver < 5)) ||
5152 (hw->mac.type == I40E_MAC_X722));
Shannon Nelsonf6581372016-02-17 16:12:20 -08005153 if (!use_register) {
5154do_retry:
5155 status = i40e_aq_rx_ctl_read_register(hw, reg_addr, &val, NULL);
5156 if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
5157 usleep_range(1000, 2000);
5158 retry--;
5159 goto do_retry;
5160 }
5161 }
5162
5163 /* if the AQ access failed, try the old-fashioned way */
5164 if (status || use_register)
5165 val = rd32(hw, reg_addr);
5166
5167 return val;
5168}
5169
5170/**
5171 * i40e_aq_rx_ctl_write_register
5172 * @hw: pointer to the hw struct
5173 * @reg_addr: register address
5174 * @reg_val: register value
5175 * @cmd_details: pointer to command details structure or NULL
5176 *
5177 * Use the firmware to write to an Rx control register,
5178 * especially useful if the Rx unit is under heavy pressure
5179 **/
5180i40e_status i40e_aq_rx_ctl_write_register(struct i40e_hw *hw,
5181 u32 reg_addr, u32 reg_val,
5182 struct i40e_asq_cmd_details *cmd_details)
5183{
5184 struct i40e_aq_desc desc;
5185 struct i40e_aqc_rx_ctl_reg_read_write *cmd =
5186 (struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
5187 i40e_status status;
5188
5189 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_rx_ctl_reg_write);
5190
5191 cmd->address = cpu_to_le32(reg_addr);
5192 cmd->value = cpu_to_le32(reg_val);
5193
5194 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5195
5196 return status;
5197}
5198
5199/**
5200 * i40e_write_rx_ctl - write to an Rx control register
5201 * @hw: pointer to the hw struct
5202 * @reg_addr: register address
5203 * @reg_val: register value
5204 **/
5205void i40e_write_rx_ctl(struct i40e_hw *hw, u32 reg_addr, u32 reg_val)
5206{
5207 i40e_status status = 0;
5208 bool use_register;
5209 int retry = 5;
5210
Paul M Stillwell Jr60303082017-03-10 12:22:02 -08005211 use_register = (((hw->aq.api_maj_ver == 1) &&
5212 (hw->aq.api_min_ver < 5)) ||
5213 (hw->mac.type == I40E_MAC_X722));
Shannon Nelsonf6581372016-02-17 16:12:20 -08005214 if (!use_register) {
5215do_retry:
5216 status = i40e_aq_rx_ctl_write_register(hw, reg_addr,
5217 reg_val, NULL);
5218 if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
5219 usleep_range(1000, 2000);
5220 retry--;
5221 goto do_retry;
5222 }
5223 }
5224
5225 /* if the AQ access failed, try the old-fashioned way */
5226 if (status || use_register)
5227 wr32(hw, reg_addr, reg_val);
5228}
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005229
5230/**
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04005231 * i40e_aq_set_phy_register
5232 * @hw: pointer to the hw struct
5233 * @phy_select: select which phy should be accessed
5234 * @dev_addr: PHY device address
5235 * @reg_addr: PHY register address
5236 * @reg_val: new register value
5237 * @cmd_details: pointer to command details structure or NULL
5238 *
5239 * Write the external PHY register.
5240 **/
5241i40e_status i40e_aq_set_phy_register(struct i40e_hw *hw,
5242 u8 phy_select, u8 dev_addr,
5243 u32 reg_addr, u32 reg_val,
5244 struct i40e_asq_cmd_details *cmd_details)
5245{
5246 struct i40e_aq_desc desc;
5247 struct i40e_aqc_phy_register_access *cmd =
5248 (struct i40e_aqc_phy_register_access *)&desc.params.raw;
5249 i40e_status status;
5250
5251 i40e_fill_default_direct_cmd_desc(&desc,
5252 i40e_aqc_opc_set_phy_register);
5253
5254 cmd->phy_interface = phy_select;
5255 cmd->dev_address = dev_addr;
5256 cmd->reg_address = cpu_to_le32(reg_addr);
5257 cmd->reg_value = cpu_to_le32(reg_val);
5258
5259 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5260
5261 return status;
5262}
5263
5264/**
5265 * i40e_aq_get_phy_register
5266 * @hw: pointer to the hw struct
5267 * @phy_select: select which phy should be accessed
5268 * @dev_addr: PHY device address
5269 * @reg_addr: PHY register address
5270 * @reg_val: read register value
5271 * @cmd_details: pointer to command details structure or NULL
5272 *
5273 * Read the external PHY register.
5274 **/
5275i40e_status i40e_aq_get_phy_register(struct i40e_hw *hw,
5276 u8 phy_select, u8 dev_addr,
5277 u32 reg_addr, u32 *reg_val,
5278 struct i40e_asq_cmd_details *cmd_details)
5279{
5280 struct i40e_aq_desc desc;
5281 struct i40e_aqc_phy_register_access *cmd =
5282 (struct i40e_aqc_phy_register_access *)&desc.params.raw;
5283 i40e_status status;
5284
5285 i40e_fill_default_direct_cmd_desc(&desc,
5286 i40e_aqc_opc_get_phy_register);
5287
5288 cmd->phy_interface = phy_select;
5289 cmd->dev_address = dev_addr;
5290 cmd->reg_address = cpu_to_le32(reg_addr);
5291
5292 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5293 if (!status)
5294 *reg_val = le32_to_cpu(cmd->reg_value);
5295
5296 return status;
5297}
5298
5299/**
Jingjing Wu329e5982017-11-14 07:00:47 -05005300 * i40e_aq_write_ddp - Write dynamic device personalization (ddp)
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005301 * @hw: pointer to the hw struct
5302 * @buff: command buffer (size in bytes = buff_size)
5303 * @buff_size: buffer size in bytes
5304 * @track_id: package tracking id
5305 * @error_offset: returns error offset
5306 * @error_info: returns error information
5307 * @cmd_details: pointer to command details structure or NULL
5308 **/
5309enum
Jingjing Wu329e5982017-11-14 07:00:47 -05005310i40e_status_code i40e_aq_write_ddp(struct i40e_hw *hw, void *buff,
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005311 u16 buff_size, u32 track_id,
5312 u32 *error_offset, u32 *error_info,
5313 struct i40e_asq_cmd_details *cmd_details)
5314{
5315 struct i40e_aq_desc desc;
5316 struct i40e_aqc_write_personalization_profile *cmd =
5317 (struct i40e_aqc_write_personalization_profile *)
5318 &desc.params.raw;
Jingjing Wu329e5982017-11-14 07:00:47 -05005319 struct i40e_aqc_write_ddp_resp *resp;
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005320 i40e_status status;
5321
5322 i40e_fill_default_direct_cmd_desc(&desc,
5323 i40e_aqc_opc_write_personalization_profile);
5324
5325 desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
5326 if (buff_size > I40E_AQ_LARGE_BUF)
5327 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
5328
5329 desc.datalen = cpu_to_le16(buff_size);
5330
5331 cmd->profile_track_id = cpu_to_le32(track_id);
5332
5333 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
5334 if (!status) {
Jingjing Wu329e5982017-11-14 07:00:47 -05005335 resp = (struct i40e_aqc_write_ddp_resp *)&desc.params.raw;
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005336 if (error_offset)
5337 *error_offset = le32_to_cpu(resp->error_offset);
5338 if (error_info)
5339 *error_info = le32_to_cpu(resp->error_info);
5340 }
5341
5342 return status;
5343}
5344
5345/**
Jingjing Wu329e5982017-11-14 07:00:47 -05005346 * i40e_aq_get_ddp_list - Read dynamic device personalization (ddp)
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005347 * @hw: pointer to the hw struct
5348 * @buff: command buffer (size in bytes = buff_size)
5349 * @buff_size: buffer size in bytes
5350 * @cmd_details: pointer to command details structure or NULL
5351 **/
5352enum
Jingjing Wu329e5982017-11-14 07:00:47 -05005353i40e_status_code i40e_aq_get_ddp_list(struct i40e_hw *hw, void *buff,
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005354 u16 buff_size, u8 flags,
5355 struct i40e_asq_cmd_details *cmd_details)
5356{
5357 struct i40e_aq_desc desc;
5358 struct i40e_aqc_get_applied_profiles *cmd =
5359 (struct i40e_aqc_get_applied_profiles *)&desc.params.raw;
5360 i40e_status status;
5361
5362 i40e_fill_default_direct_cmd_desc(&desc,
5363 i40e_aqc_opc_get_personalization_profile_list);
5364
5365 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
5366 if (buff_size > I40E_AQ_LARGE_BUF)
5367 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
5368 desc.datalen = cpu_to_le16(buff_size);
5369
5370 cmd->flags = flags;
5371
5372 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
5373
5374 return status;
5375}
5376
5377/**
5378 * i40e_find_segment_in_package
5379 * @segment_type: the segment type to search for (i.e., SEGMENT_TYPE_I40E)
5380 * @pkg_hdr: pointer to the package header to be searched
5381 *
5382 * This function searches a package file for a particular segment type. On
5383 * success it returns a pointer to the segment header, otherwise it will
5384 * return NULL.
5385 **/
5386struct i40e_generic_seg_header *
5387i40e_find_segment_in_package(u32 segment_type,
5388 struct i40e_package_header *pkg_hdr)
5389{
5390 struct i40e_generic_seg_header *segment;
5391 u32 i;
5392
5393 /* Search all package segments for the requested segment type */
5394 for (i = 0; i < pkg_hdr->segment_count; i++) {
5395 segment =
5396 (struct i40e_generic_seg_header *)((u8 *)pkg_hdr +
5397 pkg_hdr->segment_offset[i]);
5398
5399 if (segment->type == segment_type)
5400 return segment;
5401 }
5402
5403 return NULL;
5404}
5405
5406/**
5407 * i40e_write_profile
5408 * @hw: pointer to the hardware structure
5409 * @profile: pointer to the profile segment of the package to be downloaded
5410 * @track_id: package tracking id
5411 *
5412 * Handles the download of a complete package.
5413 */
5414enum i40e_status_code
5415i40e_write_profile(struct i40e_hw *hw, struct i40e_profile_segment *profile,
5416 u32 track_id)
5417{
5418 i40e_status status = 0;
5419 struct i40e_section_table *sec_tbl;
5420 struct i40e_profile_section_header *sec = NULL;
5421 u32 dev_cnt;
5422 u32 vendor_dev_id;
5423 u32 *nvm;
5424 u32 section_size = 0;
5425 u32 offset = 0, info = 0;
5426 u32 i;
5427
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005428 dev_cnt = profile->device_table_count;
5429
5430 for (i = 0; i < dev_cnt; i++) {
5431 vendor_dev_id = profile->device_table[i].vendor_dev_id;
5432 if ((vendor_dev_id >> 16) == PCI_VENDOR_ID_INTEL)
5433 if (hw->device_id == (vendor_dev_id & 0xFFFF))
5434 break;
5435 }
5436 if (i == dev_cnt) {
Jingjing Wu329e5982017-11-14 07:00:47 -05005437 i40e_debug(hw, I40E_DEBUG_PACKAGE, "Device doesn't support DDP");
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005438 return I40E_ERR_DEVICE_NOT_SUPPORTED;
5439 }
5440
5441 nvm = (u32 *)&profile->device_table[dev_cnt];
5442 sec_tbl = (struct i40e_section_table *)&nvm[nvm[0] + 1];
5443
5444 for (i = 0; i < sec_tbl->section_count; i++) {
5445 sec = (struct i40e_profile_section_header *)((u8 *)profile +
5446 sec_tbl->section_offset[i]);
5447
5448 /* Skip 'AQ', 'note' and 'name' sections */
5449 if (sec->section.type != SECTION_TYPE_MMIO)
5450 continue;
5451
5452 section_size = sec->section.size +
5453 sizeof(struct i40e_profile_section_header);
5454
5455 /* Write profile */
Jingjing Wu329e5982017-11-14 07:00:47 -05005456 status = i40e_aq_write_ddp(hw, (void *)sec, (u16)section_size,
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005457 track_id, &offset, &info, NULL);
5458 if (status) {
5459 i40e_debug(hw, I40E_DEBUG_PACKAGE,
5460 "Failed to write profile: offset %d, info %d",
5461 offset, info);
5462 break;
5463 }
5464 }
5465 return status;
5466}
5467
5468/**
5469 * i40e_add_pinfo_to_list
5470 * @hw: pointer to the hardware structure
5471 * @profile: pointer to the profile segment of the package
5472 * @profile_info_sec: buffer for information section
5473 * @track_id: package tracking id
5474 *
5475 * Register a profile to the list of loaded profiles.
5476 */
5477enum i40e_status_code
5478i40e_add_pinfo_to_list(struct i40e_hw *hw,
5479 struct i40e_profile_segment *profile,
5480 u8 *profile_info_sec, u32 track_id)
5481{
5482 i40e_status status = 0;
5483 struct i40e_profile_section_header *sec = NULL;
5484 struct i40e_profile_info *pinfo;
5485 u32 offset = 0, info = 0;
5486
5487 sec = (struct i40e_profile_section_header *)profile_info_sec;
5488 sec->tbl_size = 1;
5489 sec->data_end = sizeof(struct i40e_profile_section_header) +
5490 sizeof(struct i40e_profile_info);
5491 sec->section.type = SECTION_TYPE_INFO;
5492 sec->section.offset = sizeof(struct i40e_profile_section_header);
5493 sec->section.size = sizeof(struct i40e_profile_info);
5494 pinfo = (struct i40e_profile_info *)(profile_info_sec +
5495 sec->section.offset);
5496 pinfo->track_id = track_id;
5497 pinfo->version = profile->version;
Jingjing Wu329e5982017-11-14 07:00:47 -05005498 pinfo->op = I40E_DDP_ADD_TRACKID;
5499 memcpy(pinfo->name, profile->name, I40E_DDP_NAME_SIZE);
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005500
Jingjing Wu329e5982017-11-14 07:00:47 -05005501 status = i40e_aq_write_ddp(hw, (void *)sec, sec->data_end,
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005502 track_id, &offset, &info, NULL);
Amritha Nambiar2f4b4112017-10-27 02:36:01 -07005503
5504 return status;
5505}
5506
5507/**
5508 * i40e_aq_add_cloud_filters
5509 * @hw: pointer to the hardware structure
5510 * @seid: VSI seid to add cloud filters from
5511 * @filters: Buffer which contains the filters to be added
5512 * @filter_count: number of filters contained in the buffer
5513 *
5514 * Set the cloud filters for a given VSI. The contents of the
5515 * i40e_aqc_cloud_filters_element_data are filled in by the caller
5516 * of the function.
5517 *
5518 **/
5519enum i40e_status_code
5520i40e_aq_add_cloud_filters(struct i40e_hw *hw, u16 seid,
5521 struct i40e_aqc_cloud_filters_element_data *filters,
5522 u8 filter_count)
5523{
5524 struct i40e_aq_desc desc;
5525 struct i40e_aqc_add_remove_cloud_filters *cmd =
5526 (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
5527 enum i40e_status_code status;
5528 u16 buff_len;
5529
5530 i40e_fill_default_direct_cmd_desc(&desc,
5531 i40e_aqc_opc_add_cloud_filters);
5532
5533 buff_len = filter_count * sizeof(*filters);
5534 desc.datalen = cpu_to_le16(buff_len);
5535 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
5536 cmd->num_filters = filter_count;
5537 cmd->seid = cpu_to_le16(seid);
5538
5539 status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
5540
5541 return status;
5542}
5543
5544/**
5545 * i40e_aq_add_cloud_filters_bb
5546 * @hw: pointer to the hardware structure
5547 * @seid: VSI seid to add cloud filters from
5548 * @filters: Buffer which contains the filters in big buffer to be added
5549 * @filter_count: number of filters contained in the buffer
5550 *
5551 * Set the big buffer cloud filters for a given VSI. The contents of the
5552 * i40e_aqc_cloud_filters_element_bb are filled in by the caller of the
5553 * function.
5554 *
5555 **/
5556i40e_status
5557i40e_aq_add_cloud_filters_bb(struct i40e_hw *hw, u16 seid,
5558 struct i40e_aqc_cloud_filters_element_bb *filters,
5559 u8 filter_count)
5560{
5561 struct i40e_aq_desc desc;
5562 struct i40e_aqc_add_remove_cloud_filters *cmd =
5563 (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
5564 i40e_status status;
5565 u16 buff_len;
5566 int i;
5567
5568 i40e_fill_default_direct_cmd_desc(&desc,
5569 i40e_aqc_opc_add_cloud_filters);
5570
5571 buff_len = filter_count * sizeof(*filters);
5572 desc.datalen = cpu_to_le16(buff_len);
5573 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
5574 cmd->num_filters = filter_count;
5575 cmd->seid = cpu_to_le16(seid);
5576 cmd->big_buffer_flag = I40E_AQC_ADD_CLOUD_CMD_BB;
5577
5578 for (i = 0; i < filter_count; i++) {
5579 u16 tnl_type;
5580 u32 ti;
5581
5582 tnl_type = (le16_to_cpu(filters[i].element.flags) &
5583 I40E_AQC_ADD_CLOUD_TNL_TYPE_MASK) >>
5584 I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT;
5585
5586 /* Due to hardware eccentricities, the VNI for Geneve is shifted
5587 * one more byte further than normally used for Tenant ID in
5588 * other tunnel types.
5589 */
5590 if (tnl_type == I40E_AQC_ADD_CLOUD_TNL_TYPE_GENEVE) {
5591 ti = le32_to_cpu(filters[i].element.tenant_id);
5592 filters[i].element.tenant_id = cpu_to_le32(ti << 8);
5593 }
5594 }
5595
5596 status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
5597
5598 return status;
5599}
5600
5601/**
5602 * i40e_aq_rem_cloud_filters
5603 * @hw: pointer to the hardware structure
5604 * @seid: VSI seid to remove cloud filters from
5605 * @filters: Buffer which contains the filters to be removed
5606 * @filter_count: number of filters contained in the buffer
5607 *
5608 * Remove the cloud filters for a given VSI. The contents of the
5609 * i40e_aqc_cloud_filters_element_data are filled in by the caller
5610 * of the function.
5611 *
5612 **/
5613enum i40e_status_code
5614i40e_aq_rem_cloud_filters(struct i40e_hw *hw, u16 seid,
5615 struct i40e_aqc_cloud_filters_element_data *filters,
5616 u8 filter_count)
5617{
5618 struct i40e_aq_desc desc;
5619 struct i40e_aqc_add_remove_cloud_filters *cmd =
5620 (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
5621 enum i40e_status_code status;
5622 u16 buff_len;
5623
5624 i40e_fill_default_direct_cmd_desc(&desc,
5625 i40e_aqc_opc_remove_cloud_filters);
5626
5627 buff_len = filter_count * sizeof(*filters);
5628 desc.datalen = cpu_to_le16(buff_len);
5629 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
5630 cmd->num_filters = filter_count;
5631 cmd->seid = cpu_to_le16(seid);
5632
5633 status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
5634
5635 return status;
5636}
5637
5638/**
5639 * i40e_aq_rem_cloud_filters_bb
5640 * @hw: pointer to the hardware structure
5641 * @seid: VSI seid to remove cloud filters from
5642 * @filters: Buffer which contains the filters in big buffer to be removed
5643 * @filter_count: number of filters contained in the buffer
5644 *
5645 * Remove the big buffer cloud filters for a given VSI. The contents of the
5646 * i40e_aqc_cloud_filters_element_bb are filled in by the caller of the
5647 * function.
5648 *
5649 **/
5650i40e_status
5651i40e_aq_rem_cloud_filters_bb(struct i40e_hw *hw, u16 seid,
5652 struct i40e_aqc_cloud_filters_element_bb *filters,
5653 u8 filter_count)
5654{
5655 struct i40e_aq_desc desc;
5656 struct i40e_aqc_add_remove_cloud_filters *cmd =
5657 (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
5658 i40e_status status;
5659 u16 buff_len;
5660 int i;
5661
5662 i40e_fill_default_direct_cmd_desc(&desc,
5663 i40e_aqc_opc_remove_cloud_filters);
5664
5665 buff_len = filter_count * sizeof(*filters);
5666 desc.datalen = cpu_to_le16(buff_len);
5667 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
5668 cmd->num_filters = filter_count;
5669 cmd->seid = cpu_to_le16(seid);
5670 cmd->big_buffer_flag = I40E_AQC_ADD_CLOUD_CMD_BB;
5671
5672 for (i = 0; i < filter_count; i++) {
5673 u16 tnl_type;
5674 u32 ti;
5675
5676 tnl_type = (le16_to_cpu(filters[i].element.flags) &
5677 I40E_AQC_ADD_CLOUD_TNL_TYPE_MASK) >>
5678 I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT;
5679
5680 /* Due to hardware eccentricities, the VNI for Geneve is shifted
5681 * one more byte further than normally used for Tenant ID in
5682 * other tunnel types.
5683 */
5684 if (tnl_type == I40E_AQC_ADD_CLOUD_TNL_TYPE_GENEVE) {
5685 ti = le32_to_cpu(filters[i].element.tenant_id);
5686 filters[i].element.tenant_id = cpu_to_le32(ti << 8);
5687 }
5688 }
5689
5690 status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
5691
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005692 return status;
5693}