blob: 242c4c789e8d9f94ebc3688a1e86744a22895354 [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
2418 * @valid_flags: which bit flags to set
Amritha Nambiar5efe0c62017-10-27 02:35:45 -07002419 * @mode: cloud filter mode
Shannon Nelsonf3d58492016-05-03 15:13:11 -07002420 * @cmd_details: pointer to command details structure or NULL
2421 *
2422 * Set switch configuration bits
2423 **/
2424enum i40e_status_code i40e_aq_set_switch_config(struct i40e_hw *hw,
2425 u16 flags,
Amritha Nambiar5efe0c62017-10-27 02:35:45 -07002426 u16 valid_flags, u8 mode,
Shannon Nelsonf3d58492016-05-03 15:13:11 -07002427 struct i40e_asq_cmd_details *cmd_details)
2428{
2429 struct i40e_aq_desc desc;
2430 struct i40e_aqc_set_switch_config *scfg =
2431 (struct i40e_aqc_set_switch_config *)&desc.params.raw;
2432 enum i40e_status_code status;
2433
2434 i40e_fill_default_direct_cmd_desc(&desc,
2435 i40e_aqc_opc_set_switch_config);
2436 scfg->flags = cpu_to_le16(flags);
2437 scfg->valid_flags = cpu_to_le16(valid_flags);
Amritha Nambiar5efe0c62017-10-27 02:35:45 -07002438 scfg->mode = mode;
Scott Petersonab243ec2017-08-22 06:57:54 -04002439 if (hw->flags & I40E_HW_FLAG_802_1AD_CAPABLE) {
2440 scfg->switch_tag = cpu_to_le16(hw->switch_tag);
2441 scfg->first_tag = cpu_to_le16(hw->first_tag);
2442 scfg->second_tag = cpu_to_le16(hw->second_tag);
2443 }
Shannon Nelsonf3d58492016-05-03 15:13:11 -07002444 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2445
2446 return status;
2447}
2448
2449/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002450 * i40e_aq_get_firmware_version
2451 * @hw: pointer to the hw struct
2452 * @fw_major_version: firmware major version
2453 * @fw_minor_version: firmware minor version
Shannon Nelson7edf8102015-02-24 06:58:41 +00002454 * @fw_build: firmware build number
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002455 * @api_major_version: major queue version
2456 * @api_minor_version: minor queue version
2457 * @cmd_details: pointer to command details structure or NULL
2458 *
2459 * Get the firmware version from the admin queue commands
2460 **/
2461i40e_status i40e_aq_get_firmware_version(struct i40e_hw *hw,
2462 u16 *fw_major_version, u16 *fw_minor_version,
Shannon Nelson7edf8102015-02-24 06:58:41 +00002463 u32 *fw_build,
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002464 u16 *api_major_version, u16 *api_minor_version,
2465 struct i40e_asq_cmd_details *cmd_details)
2466{
2467 struct i40e_aq_desc desc;
2468 struct i40e_aqc_get_version *resp =
2469 (struct i40e_aqc_get_version *)&desc.params.raw;
2470 i40e_status status;
2471
2472 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_version);
2473
2474 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2475
2476 if (!status) {
Shannon Nelson7edf8102015-02-24 06:58:41 +00002477 if (fw_major_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002478 *fw_major_version = le16_to_cpu(resp->fw_major);
Shannon Nelson7edf8102015-02-24 06:58:41 +00002479 if (fw_minor_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002480 *fw_minor_version = le16_to_cpu(resp->fw_minor);
Shannon Nelson7edf8102015-02-24 06:58:41 +00002481 if (fw_build)
2482 *fw_build = le32_to_cpu(resp->fw_build);
2483 if (api_major_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002484 *api_major_version = le16_to_cpu(resp->api_major);
Shannon Nelson7edf8102015-02-24 06:58:41 +00002485 if (api_minor_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002486 *api_minor_version = le16_to_cpu(resp->api_minor);
2487 }
2488
2489 return status;
2490}
2491
2492/**
2493 * i40e_aq_send_driver_version
2494 * @hw: pointer to the hw struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002495 * @dv: driver's major, minor version
2496 * @cmd_details: pointer to command details structure or NULL
2497 *
2498 * Send the driver version to the firmware
2499 **/
2500i40e_status i40e_aq_send_driver_version(struct i40e_hw *hw,
2501 struct i40e_driver_version *dv,
2502 struct i40e_asq_cmd_details *cmd_details)
2503{
2504 struct i40e_aq_desc desc;
2505 struct i40e_aqc_driver_version *cmd =
2506 (struct i40e_aqc_driver_version *)&desc.params.raw;
2507 i40e_status status;
Kevin Scott9d2f98e2014-04-01 07:11:52 +00002508 u16 len;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002509
2510 if (dv == NULL)
2511 return I40E_ERR_PARAM;
2512
2513 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_driver_version);
2514
Kevin Scott3b38cd12015-02-06 08:52:18 +00002515 desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002516 cmd->driver_major_ver = dv->major_version;
2517 cmd->driver_minor_ver = dv->minor_version;
2518 cmd->driver_build_ver = dv->build_version;
2519 cmd->driver_subbuild_ver = dv->subbuild_version;
Shannon Nelsond2466012014-04-01 07:11:45 +00002520
2521 len = 0;
2522 while (len < sizeof(dv->driver_string) &&
2523 (dv->driver_string[len] < 0x80) &&
2524 dv->driver_string[len])
2525 len++;
2526 status = i40e_asq_send_command(hw, &desc, dv->driver_string,
2527 len, cmd_details);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002528
2529 return status;
2530}
2531
2532/**
2533 * i40e_get_link_status - get status of the HW network link
2534 * @hw: pointer to the hw struct
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002535 * @link_up: pointer to bool (true/false = linkup/linkdown)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002536 *
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002537 * Variable link_up true if link is up, false if link is down.
2538 * The variable link_up is invalid if returned value of status != 0
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002539 *
2540 * Side effect: LinkStatusEvent reporting becomes enabled
2541 **/
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002542i40e_status i40e_get_link_status(struct i40e_hw *hw, bool *link_up)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002543{
2544 i40e_status status = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002545
2546 if (hw->phy.get_link_info) {
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002547 status = i40e_update_link_info(hw);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002548
2549 if (status)
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002550 i40e_debug(hw, I40E_DEBUG_LINK, "get link failed: status %d\n",
2551 status);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002552 }
2553
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002554 *link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002555
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002556 return status;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002557}
2558
2559/**
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002560 * i40e_updatelink_status - update status of the HW network link
2561 * @hw: pointer to the hw struct
2562 **/
2563i40e_status i40e_update_link_info(struct i40e_hw *hw)
2564{
2565 struct i40e_aq_get_phy_abilities_resp abilities;
2566 i40e_status status = 0;
2567
2568 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
2569 if (status)
2570 return status;
2571
Carolyn Wybornyab425cb2016-09-27 11:28:52 -07002572 /* extra checking needed to ensure link info to user is timely */
2573 if ((hw->phy.link_info.link_info & I40E_AQ_MEDIA_AVAILABLE) &&
2574 ((hw->phy.link_info.link_info & I40E_AQ_LINK_UP) ||
2575 !(hw->phy.link_info_old.link_info & I40E_AQ_LINK_UP))) {
Carolyn Wyborny8589af72015-09-28 14:16:56 -04002576 status = i40e_aq_get_phy_capabilities(hw, false, false,
2577 &abilities, NULL);
2578 if (status)
2579 return status;
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002580
Mariusz Stachuraed601f62017-07-12 05:46:08 -04002581 hw->phy.link_info.req_fec_info =
2582 abilities.fec_cfg_curr_mod_ext_info &
2583 (I40E_AQ_REQUEST_FEC_KR | I40E_AQ_REQUEST_FEC_RS);
2584
Carolyn Wyborny8589af72015-09-28 14:16:56 -04002585 memcpy(hw->phy.link_info.module_type, &abilities.module_type,
2586 sizeof(hw->phy.link_info.module_type));
2587 }
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002588
2589 return status;
2590}
2591
2592/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002593 * i40e_aq_add_veb - Insert a VEB between the VSI and the MAC
2594 * @hw: pointer to the hw struct
2595 * @uplink_seid: the MAC or other gizmo SEID
2596 * @downlink_seid: the VSI SEID
2597 * @enabled_tc: bitmap of TCs to be enabled
2598 * @default_port: true for default port VSI, false for control port
2599 * @veb_seid: pointer to where to put the resulting VEB SEID
Shannon Nelson8a187f42016-01-13 16:51:41 -08002600 * @enable_stats: true to turn on VEB stats
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002601 * @cmd_details: pointer to command details structure or NULL
2602 *
2603 * This asks the FW to add a VEB between the uplink and downlink
2604 * elements. If the uplink SEID is 0, this will be a floating VEB.
2605 **/
2606i40e_status i40e_aq_add_veb(struct i40e_hw *hw, u16 uplink_seid,
2607 u16 downlink_seid, u8 enabled_tc,
Shannon Nelson8a187f42016-01-13 16:51:41 -08002608 bool default_port, u16 *veb_seid,
2609 bool enable_stats,
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002610 struct i40e_asq_cmd_details *cmd_details)
2611{
2612 struct i40e_aq_desc desc;
2613 struct i40e_aqc_add_veb *cmd =
2614 (struct i40e_aqc_add_veb *)&desc.params.raw;
2615 struct i40e_aqc_add_veb_completion *resp =
2616 (struct i40e_aqc_add_veb_completion *)&desc.params.raw;
2617 i40e_status status;
2618 u16 veb_flags = 0;
2619
2620 /* SEIDs need to either both be set or both be 0 for floating VEB */
2621 if (!!uplink_seid != !!downlink_seid)
2622 return I40E_ERR_PARAM;
2623
2624 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_veb);
2625
2626 cmd->uplink_seid = cpu_to_le16(uplink_seid);
2627 cmd->downlink_seid = cpu_to_le16(downlink_seid);
2628 cmd->enable_tcs = enabled_tc;
2629 if (!uplink_seid)
2630 veb_flags |= I40E_AQC_ADD_VEB_FLOATING;
2631 if (default_port)
2632 veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DEFAULT;
2633 else
2634 veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DATA;
Kevin Scotte1c51b952013-11-20 10:02:51 +00002635
Shannon Nelson8a187f42016-01-13 16:51:41 -08002636 /* reverse logic here: set the bitflag to disable the stats */
2637 if (!enable_stats)
2638 veb_flags |= I40E_AQC_ADD_VEB_ENABLE_DISABLE_STATS;
Kevin Scotte1c51b952013-11-20 10:02:51 +00002639
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002640 cmd->veb_flags = cpu_to_le16(veb_flags);
2641
2642 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2643
2644 if (!status && veb_seid)
2645 *veb_seid = le16_to_cpu(resp->veb_seid);
2646
2647 return status;
2648}
2649
2650/**
2651 * i40e_aq_get_veb_parameters - Retrieve VEB parameters
2652 * @hw: pointer to the hw struct
2653 * @veb_seid: the SEID of the VEB to query
2654 * @switch_id: the uplink switch id
Jeff Kirsher98d44382013-12-21 05:44:42 +00002655 * @floating: set to true if the VEB is floating
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002656 * @statistic_index: index of the stats counter block for this VEB
2657 * @vebs_used: number of VEB's used by function
Jeff Kirsher98d44382013-12-21 05:44:42 +00002658 * @vebs_free: total VEB's not reserved by any function
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002659 * @cmd_details: pointer to command details structure or NULL
2660 *
2661 * This retrieves the parameters for a particular VEB, specified by
2662 * uplink_seid, and returns them to the caller.
2663 **/
2664i40e_status i40e_aq_get_veb_parameters(struct i40e_hw *hw,
2665 u16 veb_seid, u16 *switch_id,
2666 bool *floating, u16 *statistic_index,
2667 u16 *vebs_used, u16 *vebs_free,
2668 struct i40e_asq_cmd_details *cmd_details)
2669{
2670 struct i40e_aq_desc desc;
2671 struct i40e_aqc_get_veb_parameters_completion *cmd_resp =
2672 (struct i40e_aqc_get_veb_parameters_completion *)
2673 &desc.params.raw;
2674 i40e_status status;
2675
2676 if (veb_seid == 0)
2677 return I40E_ERR_PARAM;
2678
2679 i40e_fill_default_direct_cmd_desc(&desc,
2680 i40e_aqc_opc_get_veb_parameters);
2681 cmd_resp->seid = cpu_to_le16(veb_seid);
2682
2683 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2684 if (status)
2685 goto get_veb_exit;
2686
2687 if (switch_id)
2688 *switch_id = le16_to_cpu(cmd_resp->switch_id);
2689 if (statistic_index)
2690 *statistic_index = le16_to_cpu(cmd_resp->statistic_index);
2691 if (vebs_used)
2692 *vebs_used = le16_to_cpu(cmd_resp->vebs_used);
2693 if (vebs_free)
2694 *vebs_free = le16_to_cpu(cmd_resp->vebs_free);
2695 if (floating) {
2696 u16 flags = le16_to_cpu(cmd_resp->veb_flags);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04002697
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002698 if (flags & I40E_AQC_ADD_VEB_FLOATING)
2699 *floating = true;
2700 else
2701 *floating = false;
2702 }
2703
2704get_veb_exit:
2705 return status;
2706}
2707
2708/**
2709 * i40e_aq_add_macvlan
2710 * @hw: pointer to the hw struct
2711 * @seid: VSI for the mac address
2712 * @mv_list: list of macvlans to be added
2713 * @count: length of the list
2714 * @cmd_details: pointer to command details structure or NULL
2715 *
2716 * Add MAC/VLAN addresses to the HW filtering
2717 **/
2718i40e_status i40e_aq_add_macvlan(struct i40e_hw *hw, u16 seid,
2719 struct i40e_aqc_add_macvlan_element_data *mv_list,
2720 u16 count, struct i40e_asq_cmd_details *cmd_details)
2721{
2722 struct i40e_aq_desc desc;
2723 struct i40e_aqc_macvlan *cmd =
2724 (struct i40e_aqc_macvlan *)&desc.params.raw;
2725 i40e_status status;
2726 u16 buf_size;
Shannon Nelson67be6eb2016-01-13 16:51:40 -08002727 int i;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002728
2729 if (count == 0 || !mv_list || !hw)
2730 return I40E_ERR_PARAM;
2731
Shannon Nelson1efc80e2015-02-27 09:18:30 +00002732 buf_size = count * sizeof(*mv_list);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002733
2734 /* prep the rest of the request */
2735 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_macvlan);
2736 cmd->num_addresses = cpu_to_le16(count);
2737 cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
2738 cmd->seid[1] = 0;
2739 cmd->seid[2] = 0;
2740
Shannon Nelson67be6eb2016-01-13 16:51:40 -08002741 for (i = 0; i < count; i++)
2742 if (is_multicast_ether_addr(mv_list[i].mac_addr))
2743 mv_list[i].flags |=
2744 cpu_to_le16(I40E_AQC_MACVLAN_ADD_USE_SHARED_MAC);
2745
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002746 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
2747 if (buf_size > I40E_AQ_LARGE_BUF)
2748 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2749
2750 status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
Shannon Nelson67be6eb2016-01-13 16:51:40 -08002751 cmd_details);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002752
2753 return status;
2754}
2755
2756/**
2757 * i40e_aq_remove_macvlan
2758 * @hw: pointer to the hw struct
2759 * @seid: VSI for the mac address
2760 * @mv_list: list of macvlans to be removed
2761 * @count: length of the list
2762 * @cmd_details: pointer to command details structure or NULL
2763 *
2764 * Remove MAC/VLAN addresses from the HW filtering
2765 **/
2766i40e_status i40e_aq_remove_macvlan(struct i40e_hw *hw, u16 seid,
2767 struct i40e_aqc_remove_macvlan_element_data *mv_list,
2768 u16 count, struct i40e_asq_cmd_details *cmd_details)
2769{
2770 struct i40e_aq_desc desc;
2771 struct i40e_aqc_macvlan *cmd =
2772 (struct i40e_aqc_macvlan *)&desc.params.raw;
2773 i40e_status status;
2774 u16 buf_size;
2775
2776 if (count == 0 || !mv_list || !hw)
2777 return I40E_ERR_PARAM;
2778
Shannon Nelson1efc80e2015-02-27 09:18:30 +00002779 buf_size = count * sizeof(*mv_list);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002780
2781 /* prep the rest of the request */
2782 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_macvlan);
2783 cmd->num_addresses = cpu_to_le16(count);
2784 cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
2785 cmd->seid[1] = 0;
2786 cmd->seid[2] = 0;
2787
2788 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
2789 if (buf_size > I40E_AQ_LARGE_BUF)
2790 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2791
2792 status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
2793 cmd_details);
2794
2795 return status;
2796}
2797
2798/**
Kiran Patil7bd68752016-01-04 10:33:07 -08002799 * i40e_mirrorrule_op - Internal helper function to add/delete mirror rule
2800 * @hw: pointer to the hw struct
2801 * @opcode: AQ opcode for add or delete mirror rule
2802 * @sw_seid: Switch SEID (to which rule refers)
2803 * @rule_type: Rule Type (ingress/egress/VLAN)
2804 * @id: Destination VSI SEID or Rule ID
2805 * @count: length of the list
2806 * @mr_list: list of mirrored VSI SEIDs or VLAN IDs
2807 * @cmd_details: pointer to command details structure or NULL
2808 * @rule_id: Rule ID returned from FW
2809 * @rule_used: Number of rules used in internal switch
2810 * @rule_free: Number of rules free in internal switch
2811 *
2812 * Add/Delete a mirror rule to a specific switch. Mirror rules are supported for
2813 * VEBs/VEPA elements only
2814 **/
2815static i40e_status i40e_mirrorrule_op(struct i40e_hw *hw,
2816 u16 opcode, u16 sw_seid, u16 rule_type, u16 id,
2817 u16 count, __le16 *mr_list,
2818 struct i40e_asq_cmd_details *cmd_details,
2819 u16 *rule_id, u16 *rules_used, u16 *rules_free)
2820{
2821 struct i40e_aq_desc desc;
2822 struct i40e_aqc_add_delete_mirror_rule *cmd =
2823 (struct i40e_aqc_add_delete_mirror_rule *)&desc.params.raw;
2824 struct i40e_aqc_add_delete_mirror_rule_completion *resp =
2825 (struct i40e_aqc_add_delete_mirror_rule_completion *)&desc.params.raw;
2826 i40e_status status;
2827 u16 buf_size;
2828
2829 buf_size = count * sizeof(*mr_list);
2830
2831 /* prep the rest of the request */
2832 i40e_fill_default_direct_cmd_desc(&desc, opcode);
2833 cmd->seid = cpu_to_le16(sw_seid);
2834 cmd->rule_type = cpu_to_le16(rule_type &
2835 I40E_AQC_MIRROR_RULE_TYPE_MASK);
2836 cmd->num_entries = cpu_to_le16(count);
2837 /* Dest VSI for add, rule_id for delete */
2838 cmd->destination = cpu_to_le16(id);
2839 if (mr_list) {
2840 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
2841 I40E_AQ_FLAG_RD));
2842 if (buf_size > I40E_AQ_LARGE_BUF)
2843 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2844 }
2845
2846 status = i40e_asq_send_command(hw, &desc, mr_list, buf_size,
2847 cmd_details);
2848 if (!status ||
2849 hw->aq.asq_last_status == I40E_AQ_RC_ENOSPC) {
2850 if (rule_id)
2851 *rule_id = le16_to_cpu(resp->rule_id);
2852 if (rules_used)
2853 *rules_used = le16_to_cpu(resp->mirror_rules_used);
2854 if (rules_free)
2855 *rules_free = le16_to_cpu(resp->mirror_rules_free);
2856 }
2857 return status;
2858}
2859
2860/**
2861 * i40e_aq_add_mirrorrule - add a mirror rule
2862 * @hw: pointer to the hw struct
2863 * @sw_seid: Switch SEID (to which rule refers)
2864 * @rule_type: Rule Type (ingress/egress/VLAN)
2865 * @dest_vsi: SEID of VSI to which packets will be mirrored
2866 * @count: length of the list
2867 * @mr_list: list of mirrored VSI SEIDs or VLAN IDs
2868 * @cmd_details: pointer to command details structure or NULL
2869 * @rule_id: Rule ID returned from FW
2870 * @rule_used: Number of rules used in internal switch
2871 * @rule_free: Number of rules free in internal switch
2872 *
2873 * Add mirror rule. Mirror rules are supported for VEBs or VEPA elements only
2874 **/
2875i40e_status i40e_aq_add_mirrorrule(struct i40e_hw *hw, u16 sw_seid,
2876 u16 rule_type, u16 dest_vsi, u16 count, __le16 *mr_list,
2877 struct i40e_asq_cmd_details *cmd_details,
2878 u16 *rule_id, u16 *rules_used, u16 *rules_free)
2879{
2880 if (!(rule_type == I40E_AQC_MIRROR_RULE_TYPE_ALL_INGRESS ||
2881 rule_type == I40E_AQC_MIRROR_RULE_TYPE_ALL_EGRESS)) {
2882 if (count == 0 || !mr_list)
2883 return I40E_ERR_PARAM;
2884 }
2885
2886 return i40e_mirrorrule_op(hw, i40e_aqc_opc_add_mirror_rule, sw_seid,
2887 rule_type, dest_vsi, count, mr_list,
2888 cmd_details, rule_id, rules_used, rules_free);
2889}
2890
2891/**
2892 * i40e_aq_delete_mirrorrule - delete a mirror rule
2893 * @hw: pointer to the hw struct
2894 * @sw_seid: Switch SEID (to which rule refers)
2895 * @rule_type: Rule Type (ingress/egress/VLAN)
2896 * @count: length of the list
2897 * @rule_id: Rule ID that is returned in the receive desc as part of
2898 * add_mirrorrule.
2899 * @mr_list: list of mirrored VLAN IDs to be removed
2900 * @cmd_details: pointer to command details structure or NULL
2901 * @rule_used: Number of rules used in internal switch
2902 * @rule_free: Number of rules free in internal switch
2903 *
2904 * Delete a mirror rule. Mirror rules are supported for VEBs/VEPA elements only
2905 **/
2906i40e_status i40e_aq_delete_mirrorrule(struct i40e_hw *hw, u16 sw_seid,
2907 u16 rule_type, u16 rule_id, u16 count, __le16 *mr_list,
2908 struct i40e_asq_cmd_details *cmd_details,
2909 u16 *rules_used, u16 *rules_free)
2910{
2911 /* Rule ID has to be valid except rule_type: INGRESS VLAN mirroring */
Greg Rosedb077272016-04-12 08:30:48 -07002912 if (rule_type == I40E_AQC_MIRROR_RULE_TYPE_VLAN) {
Kiran Patil7bd68752016-01-04 10:33:07 -08002913 /* count and mr_list shall be valid for rule_type INGRESS VLAN
2914 * mirroring. For other rule_type, count and rule_type should
2915 * not matter.
2916 */
2917 if (count == 0 || !mr_list)
2918 return I40E_ERR_PARAM;
2919 }
2920
2921 return i40e_mirrorrule_op(hw, i40e_aqc_opc_delete_mirror_rule, sw_seid,
2922 rule_type, rule_id, count, mr_list,
2923 cmd_details, NULL, rules_used, rules_free);
2924}
2925
2926/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002927 * i40e_aq_send_msg_to_vf
2928 * @hw: pointer to the hardware structure
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00002929 * @vfid: VF id to send msg
Jeff Kirsher98d44382013-12-21 05:44:42 +00002930 * @v_opcode: opcodes for VF-PF communication
2931 * @v_retval: return error code
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002932 * @msg: pointer to the msg buffer
2933 * @msglen: msg length
2934 * @cmd_details: pointer to command details
2935 *
2936 * send msg to vf
2937 **/
2938i40e_status i40e_aq_send_msg_to_vf(struct i40e_hw *hw, u16 vfid,
2939 u32 v_opcode, u32 v_retval, u8 *msg, u16 msglen,
2940 struct i40e_asq_cmd_details *cmd_details)
2941{
2942 struct i40e_aq_desc desc;
2943 struct i40e_aqc_pf_vf_message *cmd =
2944 (struct i40e_aqc_pf_vf_message *)&desc.params.raw;
2945 i40e_status status;
2946
2947 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_vf);
2948 cmd->id = cpu_to_le32(vfid);
2949 desc.cookie_high = cpu_to_le32(v_opcode);
2950 desc.cookie_low = cpu_to_le32(v_retval);
2951 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_SI);
2952 if (msglen) {
2953 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
2954 I40E_AQ_FLAG_RD));
2955 if (msglen > I40E_AQ_LARGE_BUF)
2956 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2957 desc.datalen = cpu_to_le16(msglen);
2958 }
2959 status = i40e_asq_send_command(hw, &desc, msg, msglen, cmd_details);
2960
2961 return status;
2962}
2963
2964/**
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002965 * i40e_aq_debug_read_register
2966 * @hw: pointer to the hw struct
2967 * @reg_addr: register address
2968 * @reg_val: register value
2969 * @cmd_details: pointer to command details structure or NULL
2970 *
2971 * Read the register using the admin queue commands
2972 **/
2973i40e_status i40e_aq_debug_read_register(struct i40e_hw *hw,
Jesse Brandeburg7b115dd2015-02-27 09:15:23 +00002974 u32 reg_addr, u64 *reg_val,
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002975 struct i40e_asq_cmd_details *cmd_details)
2976{
2977 struct i40e_aq_desc desc;
2978 struct i40e_aqc_debug_reg_read_write *cmd_resp =
2979 (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
2980 i40e_status status;
2981
2982 if (reg_val == NULL)
2983 return I40E_ERR_PARAM;
2984
Jesse Brandeburg7b115dd2015-02-27 09:15:23 +00002985 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_read_reg);
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002986
2987 cmd_resp->address = cpu_to_le32(reg_addr);
2988
2989 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2990
2991 if (!status) {
Jesse Brandeburg7b115dd2015-02-27 09:15:23 +00002992 *reg_val = ((u64)le32_to_cpu(cmd_resp->value_high) << 32) |
2993 (u64)le32_to_cpu(cmd_resp->value_low);
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002994 }
2995
2996 return status;
2997}
2998
2999/**
Shannon Nelson53db45c2014-08-01 13:27:05 -07003000 * i40e_aq_debug_write_register
3001 * @hw: pointer to the hw struct
3002 * @reg_addr: register address
3003 * @reg_val: register value
3004 * @cmd_details: pointer to command details structure or NULL
3005 *
3006 * Write to a register using the admin queue commands
3007 **/
3008i40e_status i40e_aq_debug_write_register(struct i40e_hw *hw,
3009 u32 reg_addr, u64 reg_val,
3010 struct i40e_asq_cmd_details *cmd_details)
3011{
3012 struct i40e_aq_desc desc;
3013 struct i40e_aqc_debug_reg_read_write *cmd =
3014 (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
3015 i40e_status status;
3016
3017 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_write_reg);
3018
3019 cmd->address = cpu_to_le32(reg_addr);
3020 cmd->value_high = cpu_to_le32((u32)(reg_val >> 32));
3021 cmd->value_low = cpu_to_le32((u32)(reg_val & 0xFFFFFFFF));
3022
3023 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3024
3025 return status;
3026}
3027
3028/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003029 * i40e_aq_request_resource
3030 * @hw: pointer to the hw struct
3031 * @resource: resource id
3032 * @access: access type
3033 * @sdp_number: resource number
3034 * @timeout: the maximum time in ms that the driver may hold the resource
3035 * @cmd_details: pointer to command details structure or NULL
3036 *
3037 * requests common resource using the admin queue commands
3038 **/
3039i40e_status i40e_aq_request_resource(struct i40e_hw *hw,
3040 enum i40e_aq_resources_ids resource,
3041 enum i40e_aq_resource_access_type access,
3042 u8 sdp_number, u64 *timeout,
3043 struct i40e_asq_cmd_details *cmd_details)
3044{
3045 struct i40e_aq_desc desc;
3046 struct i40e_aqc_request_resource *cmd_resp =
3047 (struct i40e_aqc_request_resource *)&desc.params.raw;
3048 i40e_status status;
3049
3050 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_request_resource);
3051
3052 cmd_resp->resource_id = cpu_to_le16(resource);
3053 cmd_resp->access_type = cpu_to_le16(access);
3054 cmd_resp->resource_number = cpu_to_le32(sdp_number);
3055
3056 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3057 /* The completion specifies the maximum time in ms that the driver
3058 * may hold the resource in the Timeout field.
3059 * If the resource is held by someone else, the command completes with
3060 * busy return value and the timeout field indicates the maximum time
3061 * the current owner of the resource has to free it.
3062 */
3063 if (!status || hw->aq.asq_last_status == I40E_AQ_RC_EBUSY)
3064 *timeout = le32_to_cpu(cmd_resp->timeout);
3065
3066 return status;
3067}
3068
3069/**
3070 * i40e_aq_release_resource
3071 * @hw: pointer to the hw struct
3072 * @resource: resource id
3073 * @sdp_number: resource number
3074 * @cmd_details: pointer to command details structure or NULL
3075 *
3076 * release common resource using the admin queue commands
3077 **/
3078i40e_status i40e_aq_release_resource(struct i40e_hw *hw,
3079 enum i40e_aq_resources_ids resource,
3080 u8 sdp_number,
3081 struct i40e_asq_cmd_details *cmd_details)
3082{
3083 struct i40e_aq_desc desc;
3084 struct i40e_aqc_request_resource *cmd =
3085 (struct i40e_aqc_request_resource *)&desc.params.raw;
3086 i40e_status status;
3087
3088 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_release_resource);
3089
3090 cmd->resource_id = cpu_to_le16(resource);
3091 cmd->resource_number = cpu_to_le32(sdp_number);
3092
3093 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3094
3095 return status;
3096}
3097
3098/**
3099 * i40e_aq_read_nvm
3100 * @hw: pointer to the hw struct
3101 * @module_pointer: module pointer location in words from the NVM beginning
3102 * @offset: byte offset from the module beginning
3103 * @length: length of the section to be read (in bytes from the offset)
3104 * @data: command buffer (size [bytes] = length)
3105 * @last_command: tells if this is the last command in a series
3106 * @cmd_details: pointer to command details structure or NULL
3107 *
3108 * Read the NVM using the admin queue commands
3109 **/
3110i40e_status i40e_aq_read_nvm(struct i40e_hw *hw, u8 module_pointer,
3111 u32 offset, u16 length, void *data,
3112 bool last_command,
3113 struct i40e_asq_cmd_details *cmd_details)
3114{
3115 struct i40e_aq_desc desc;
3116 struct i40e_aqc_nvm_update *cmd =
3117 (struct i40e_aqc_nvm_update *)&desc.params.raw;
3118 i40e_status status;
3119
3120 /* In offset the highest byte must be zeroed. */
3121 if (offset & 0xFF000000) {
3122 status = I40E_ERR_PARAM;
3123 goto i40e_aq_read_nvm_exit;
3124 }
3125
3126 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_read);
3127
3128 /* If this is the last command in a series, set the proper flag. */
3129 if (last_command)
3130 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
3131 cmd->module_pointer = module_pointer;
3132 cmd->offset = cpu_to_le32(offset);
3133 cmd->length = cpu_to_le16(length);
3134
3135 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3136 if (length > I40E_AQ_LARGE_BUF)
3137 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3138
3139 status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
3140
3141i40e_aq_read_nvm_exit:
3142 return status;
3143}
3144
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003145/**
3146 * i40e_aq_erase_nvm
3147 * @hw: pointer to the hw struct
3148 * @module_pointer: module pointer location in words from the NVM beginning
3149 * @offset: offset in the module (expressed in 4 KB from module's beginning)
3150 * @length: length of the section to be erased (expressed in 4 KB)
3151 * @last_command: tells if this is the last command in a series
3152 * @cmd_details: pointer to command details structure or NULL
3153 *
3154 * Erase the NVM sector using the admin queue commands
3155 **/
3156i40e_status i40e_aq_erase_nvm(struct i40e_hw *hw, u8 module_pointer,
3157 u32 offset, u16 length, bool last_command,
3158 struct i40e_asq_cmd_details *cmd_details)
3159{
3160 struct i40e_aq_desc desc;
3161 struct i40e_aqc_nvm_update *cmd =
3162 (struct i40e_aqc_nvm_update *)&desc.params.raw;
3163 i40e_status status;
3164
3165 /* In offset the highest byte must be zeroed. */
3166 if (offset & 0xFF000000) {
3167 status = I40E_ERR_PARAM;
3168 goto i40e_aq_erase_nvm_exit;
3169 }
3170
3171 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_erase);
3172
3173 /* If this is the last command in a series, set the proper flag. */
3174 if (last_command)
3175 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
3176 cmd->module_pointer = module_pointer;
3177 cmd->offset = cpu_to_le32(offset);
3178 cmd->length = cpu_to_le16(length);
3179
3180 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3181
3182i40e_aq_erase_nvm_exit:
3183 return status;
3184}
3185
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003186/**
3187 * i40e_parse_discover_capabilities
3188 * @hw: pointer to the hw struct
3189 * @buff: pointer to a buffer containing device/function capability records
3190 * @cap_count: number of capability records in the list
3191 * @list_type_opc: type of capabilities list to parse
3192 *
3193 * Parse the device/function capabilities list.
3194 **/
3195static void i40e_parse_discover_capabilities(struct i40e_hw *hw, void *buff,
3196 u32 cap_count,
3197 enum i40e_admin_queue_opc list_type_opc)
3198{
3199 struct i40e_aqc_list_capabilities_element_resp *cap;
Shannon Nelson9fee9db2014-12-11 07:06:30 +00003200 u32 valid_functions, num_functions;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003201 u32 number, logical_id, phys_id;
3202 struct i40e_hw_capabilities *p;
Mariusz Stachurabc2a3a62018-03-08 14:52:10 -08003203 u16 id, ocp_cfg_word0;
3204 i40e_status status;
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003205 u8 major_rev;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003206 u32 i = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003207
3208 cap = (struct i40e_aqc_list_capabilities_element_resp *) buff;
3209
3210 if (list_type_opc == i40e_aqc_opc_list_dev_capabilities)
Joe Perchesb58f2f72014-03-25 04:30:32 +00003211 p = &hw->dev_caps;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003212 else if (list_type_opc == i40e_aqc_opc_list_func_capabilities)
Joe Perchesb58f2f72014-03-25 04:30:32 +00003213 p = &hw->func_caps;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003214 else
3215 return;
3216
3217 for (i = 0; i < cap_count; i++, cap++) {
3218 id = le16_to_cpu(cap->id);
3219 number = le32_to_cpu(cap->number);
3220 logical_id = le32_to_cpu(cap->logical_id);
3221 phys_id = le32_to_cpu(cap->phys_id);
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003222 major_rev = cap->major_rev;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003223
3224 switch (id) {
Shannon Nelson406e7342015-12-10 11:38:49 -08003225 case I40E_AQ_CAP_ID_SWITCH_MODE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003226 p->switch_mode = number;
3227 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003228 case I40E_AQ_CAP_ID_MNG_MODE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003229 p->management_mode = number;
Piotr Raczynski64f5ead2016-10-25 16:08:53 -07003230 if (major_rev > 1) {
3231 p->mng_protocols_over_mctp = logical_id;
3232 i40e_debug(hw, I40E_DEBUG_INIT,
3233 "HW Capability: Protocols over MCTP = %d\n",
3234 p->mng_protocols_over_mctp);
3235 } else {
3236 p->mng_protocols_over_mctp = 0;
3237 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003238 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003239 case I40E_AQ_CAP_ID_NPAR_ACTIVE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003240 p->npar_enable = number;
3241 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003242 case I40E_AQ_CAP_ID_OS2BMC_CAP:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003243 p->os2bmc = number;
3244 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003245 case I40E_AQ_CAP_ID_FUNCTIONS_VALID:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003246 p->valid_functions = number;
3247 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003248 case I40E_AQ_CAP_ID_SRIOV:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003249 if (number == 1)
3250 p->sr_iov_1_1 = true;
3251 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003252 case I40E_AQ_CAP_ID_VF:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003253 p->num_vfs = number;
3254 p->vf_base_id = logical_id;
3255 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003256 case I40E_AQ_CAP_ID_VMDQ:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003257 if (number == 1)
3258 p->vmdq = true;
3259 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003260 case I40E_AQ_CAP_ID_8021QBG:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003261 if (number == 1)
3262 p->evb_802_1_qbg = true;
3263 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003264 case I40E_AQ_CAP_ID_8021QBR:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003265 if (number == 1)
3266 p->evb_802_1_qbh = true;
3267 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003268 case I40E_AQ_CAP_ID_VSI:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003269 p->num_vsis = number;
3270 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003271 case I40E_AQ_CAP_ID_DCB:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003272 if (number == 1) {
3273 p->dcb = true;
3274 p->enabled_tcmap = logical_id;
3275 p->maxtc = phys_id;
3276 }
3277 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003278 case I40E_AQ_CAP_ID_FCOE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003279 if (number == 1)
3280 p->fcoe = true;
3281 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003282 case I40E_AQ_CAP_ID_ISCSI:
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00003283 if (number == 1)
3284 p->iscsi = true;
3285 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003286 case I40E_AQ_CAP_ID_RSS:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003287 p->rss = true;
Carolyn Wybornye157ea32014-06-03 23:50:22 +00003288 p->rss_table_size = number;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003289 p->rss_table_entry_width = logical_id;
3290 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003291 case I40E_AQ_CAP_ID_RXQ:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003292 p->num_rx_qp = number;
3293 p->base_queue = phys_id;
3294 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003295 case I40E_AQ_CAP_ID_TXQ:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003296 p->num_tx_qp = number;
3297 p->base_queue = phys_id;
3298 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003299 case I40E_AQ_CAP_ID_MSIX:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003300 p->num_msix_vectors = number;
Deepthi Kavalur453e16e2016-04-01 03:56:01 -07003301 i40e_debug(hw, I40E_DEBUG_INIT,
3302 "HW Capability: MSIX vector count = %d\n",
3303 p->num_msix_vectors);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003304 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003305 case I40E_AQ_CAP_ID_VF_MSIX:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003306 p->num_msix_vectors_vf = number;
3307 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003308 case I40E_AQ_CAP_ID_FLEX10:
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003309 if (major_rev == 1) {
3310 if (number == 1) {
3311 p->flex10_enable = true;
3312 p->flex10_capable = true;
3313 }
3314 } else {
3315 /* Capability revision >= 2 */
3316 if (number & 1)
3317 p->flex10_enable = true;
3318 if (number & 2)
3319 p->flex10_capable = true;
3320 }
3321 p->flex10_mode = logical_id;
3322 p->flex10_status = phys_id;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003323 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003324 case I40E_AQ_CAP_ID_CEM:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003325 if (number == 1)
3326 p->mgmt_cem = true;
3327 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003328 case I40E_AQ_CAP_ID_IWARP:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003329 if (number == 1)
3330 p->iwarp = true;
3331 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003332 case I40E_AQ_CAP_ID_LED:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003333 if (phys_id < I40E_HW_CAP_MAX_GPIO)
3334 p->led[phys_id] = true;
3335 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003336 case I40E_AQ_CAP_ID_SDP:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003337 if (phys_id < I40E_HW_CAP_MAX_GPIO)
3338 p->sdp[phys_id] = true;
3339 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003340 case I40E_AQ_CAP_ID_MDIO:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003341 if (number == 1) {
3342 p->mdio_port_num = phys_id;
3343 p->mdio_port_mode = logical_id;
3344 }
3345 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003346 case I40E_AQ_CAP_ID_1588:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003347 if (number == 1)
3348 p->ieee_1588 = true;
3349 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003350 case I40E_AQ_CAP_ID_FLOW_DIRECTOR:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003351 p->fd = true;
3352 p->fd_filters_guaranteed = number;
3353 p->fd_filters_best_effort = logical_id;
3354 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003355 case I40E_AQ_CAP_ID_WSR_PROT:
Kevin Scott73b23402015-04-07 19:45:38 -04003356 p->wr_csr_prot = (u64)number;
3357 p->wr_csr_prot |= (u64)logical_id << 32;
3358 break;
Michal Kosiarz68a1c5a2016-04-12 08:30:46 -07003359 case I40E_AQ_CAP_ID_NVM_MGMT:
3360 if (number & I40E_NVM_MGMT_SEC_REV_DISABLED)
3361 p->sec_rev_disabled = true;
3362 if (number & I40E_NVM_MGMT_UPDATE_DISABLED)
3363 p->update_disabled = true;
3364 break;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003365 default:
3366 break;
3367 }
3368 }
3369
Vasu Devf18ae102015-04-07 19:45:36 -04003370 if (p->fcoe)
3371 i40e_debug(hw, I40E_DEBUG_ALL, "device is FCoE capable\n");
3372
Vasu Dev566bb852014-04-09 05:59:06 +00003373 /* Software override ensuring FCoE is disabled if npar or mfp
3374 * mode because it is not supported in these modes.
3375 */
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003376 if (p->npar_enable || p->flex10_enable)
Vasu Dev566bb852014-04-09 05:59:06 +00003377 p->fcoe = false;
3378
Shannon Nelson9fee9db2014-12-11 07:06:30 +00003379 /* count the enabled ports (aka the "not disabled" ports) */
3380 hw->num_ports = 0;
3381 for (i = 0; i < 4; i++) {
3382 u32 port_cfg_reg = I40E_PRTGEN_CNF + (4 * i);
3383 u64 port_cfg = 0;
3384
3385 /* use AQ read to get the physical register offset instead
3386 * of the port relative offset
3387 */
3388 i40e_aq_debug_read_register(hw, port_cfg_reg, &port_cfg, NULL);
3389 if (!(port_cfg & I40E_PRTGEN_CNF_PORT_DIS_MASK))
3390 hw->num_ports++;
3391 }
3392
Mariusz Stachurabc2a3a62018-03-08 14:52:10 -08003393 /* OCP cards case: if a mezz is removed the Ethernet port is at
3394 * disabled state in PRTGEN_CNF register. Additional NVM read is
3395 * needed in order to check if we are dealing with OCP card.
3396 * Those cards have 4 PFs at minimum, so using PRTGEN_CNF for counting
3397 * physical ports results in wrong partition id calculation and thus
3398 * not supporting WoL.
3399 */
3400 if (hw->mac.type == I40E_MAC_X722) {
3401 if (!i40e_acquire_nvm(hw, I40E_RESOURCE_READ)) {
3402 status = i40e_aq_read_nvm(hw, I40E_SR_EMP_MODULE_PTR,
3403 2 * I40E_SR_OCP_CFG_WORD0,
3404 sizeof(ocp_cfg_word0),
3405 &ocp_cfg_word0, true, NULL);
3406 if (!status &&
3407 (ocp_cfg_word0 & I40E_SR_OCP_ENABLED))
3408 hw->num_ports = 4;
3409 i40e_release_nvm(hw);
3410 }
3411 }
3412
Shannon Nelson9fee9db2014-12-11 07:06:30 +00003413 valid_functions = p->valid_functions;
3414 num_functions = 0;
3415 while (valid_functions) {
3416 if (valid_functions & 1)
3417 num_functions++;
3418 valid_functions >>= 1;
3419 }
3420
3421 /* partition id is 1-based, and functions are evenly spread
3422 * across the ports as partitions
3423 */
Michal Kosiarz999b3152016-10-11 15:26:56 -07003424 if (hw->num_ports != 0) {
3425 hw->partition_id = (hw->pf_id / hw->num_ports) + 1;
3426 hw->num_partitions = num_functions / hw->num_ports;
3427 }
Shannon Nelson9fee9db2014-12-11 07:06:30 +00003428
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003429 /* additional HW specific goodies that might
3430 * someday be HW version specific
3431 */
3432 p->rx_buf_chain_len = I40E_MAX_CHAINED_RX_BUFFERS;
3433}
3434
3435/**
3436 * i40e_aq_discover_capabilities
3437 * @hw: pointer to the hw struct
3438 * @buff: a virtual buffer to hold the capabilities
3439 * @buff_size: Size of the virtual buffer
3440 * @data_size: Size of the returned data, or buff size needed if AQ err==ENOMEM
3441 * @list_type_opc: capabilities type to discover - pass in the command opcode
3442 * @cmd_details: pointer to command details structure or NULL
3443 *
3444 * Get the device capabilities descriptions from the firmware
3445 **/
3446i40e_status i40e_aq_discover_capabilities(struct i40e_hw *hw,
3447 void *buff, u16 buff_size, u16 *data_size,
3448 enum i40e_admin_queue_opc list_type_opc,
3449 struct i40e_asq_cmd_details *cmd_details)
3450{
3451 struct i40e_aqc_list_capabilites *cmd;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003452 struct i40e_aq_desc desc;
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08003453 i40e_status status = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003454
3455 cmd = (struct i40e_aqc_list_capabilites *)&desc.params.raw;
3456
3457 if (list_type_opc != i40e_aqc_opc_list_func_capabilities &&
3458 list_type_opc != i40e_aqc_opc_list_dev_capabilities) {
3459 status = I40E_ERR_PARAM;
3460 goto exit;
3461 }
3462
3463 i40e_fill_default_direct_cmd_desc(&desc, list_type_opc);
3464
3465 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3466 if (buff_size > I40E_AQ_LARGE_BUF)
3467 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3468
3469 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3470 *data_size = le16_to_cpu(desc.datalen);
3471
3472 if (status)
3473 goto exit;
3474
3475 i40e_parse_discover_capabilities(hw, buff, le32_to_cpu(cmd->count),
3476 list_type_opc);
3477
3478exit:
3479 return status;
3480}
3481
3482/**
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003483 * i40e_aq_update_nvm
3484 * @hw: pointer to the hw struct
3485 * @module_pointer: module pointer location in words from the NVM beginning
3486 * @offset: byte offset from the module beginning
3487 * @length: length of the section to be written (in bytes from the offset)
3488 * @data: command buffer (size [bytes] = length)
3489 * @last_command: tells if this is the last command in a series
Pawel Jablonskie3a5d6e2017-12-18 05:14:44 -05003490 * @preservation_flags: Preservation mode flags
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003491 * @cmd_details: pointer to command details structure or NULL
3492 *
3493 * Update the NVM using the admin queue commands
3494 **/
3495i40e_status i40e_aq_update_nvm(struct i40e_hw *hw, u8 module_pointer,
3496 u32 offset, u16 length, void *data,
Pawel Jablonskie3a5d6e2017-12-18 05:14:44 -05003497 bool last_command, u8 preservation_flags,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003498 struct i40e_asq_cmd_details *cmd_details)
3499{
3500 struct i40e_aq_desc desc;
3501 struct i40e_aqc_nvm_update *cmd =
3502 (struct i40e_aqc_nvm_update *)&desc.params.raw;
3503 i40e_status status;
3504
3505 /* In offset the highest byte must be zeroed. */
3506 if (offset & 0xFF000000) {
3507 status = I40E_ERR_PARAM;
3508 goto i40e_aq_update_nvm_exit;
3509 }
3510
3511 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_update);
3512
3513 /* If this is the last command in a series, set the proper flag. */
3514 if (last_command)
3515 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
Pawel Jablonskie3a5d6e2017-12-18 05:14:44 -05003516 if (hw->mac.type == I40E_MAC_X722) {
3517 if (preservation_flags == I40E_NVM_PRESERVATION_FLAGS_SELECTED)
3518 cmd->command_flags |=
3519 (I40E_AQ_NVM_PRESERVATION_FLAGS_SELECTED <<
3520 I40E_AQ_NVM_PRESERVATION_FLAGS_SHIFT);
3521 else if (preservation_flags == I40E_NVM_PRESERVATION_FLAGS_ALL)
3522 cmd->command_flags |=
3523 (I40E_AQ_NVM_PRESERVATION_FLAGS_ALL <<
3524 I40E_AQ_NVM_PRESERVATION_FLAGS_SHIFT);
3525 }
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003526 cmd->module_pointer = module_pointer;
3527 cmd->offset = cpu_to_le32(offset);
3528 cmd->length = cpu_to_le16(length);
3529
3530 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
3531 if (length > I40E_AQ_LARGE_BUF)
3532 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3533
3534 status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
3535
3536i40e_aq_update_nvm_exit:
3537 return status;
3538}
3539
3540/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003541 * i40e_aq_get_lldp_mib
3542 * @hw: pointer to the hw struct
3543 * @bridge_type: type of bridge requested
3544 * @mib_type: Local, Remote or both Local and Remote MIBs
3545 * @buff: pointer to a user supplied buffer to store the MIB block
3546 * @buff_size: size of the buffer (in bytes)
3547 * @local_len : length of the returned Local LLDP MIB
3548 * @remote_len: length of the returned Remote LLDP MIB
3549 * @cmd_details: pointer to command details structure or NULL
3550 *
3551 * Requests the complete LLDP MIB (entire packet).
3552 **/
3553i40e_status i40e_aq_get_lldp_mib(struct i40e_hw *hw, u8 bridge_type,
3554 u8 mib_type, void *buff, u16 buff_size,
3555 u16 *local_len, u16 *remote_len,
3556 struct i40e_asq_cmd_details *cmd_details)
3557{
3558 struct i40e_aq_desc desc;
3559 struct i40e_aqc_lldp_get_mib *cmd =
3560 (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
3561 struct i40e_aqc_lldp_get_mib *resp =
3562 (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
3563 i40e_status status;
3564
3565 if (buff_size == 0 || !buff)
3566 return I40E_ERR_PARAM;
3567
3568 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_get_mib);
3569 /* Indirect Command */
3570 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3571
3572 cmd->type = mib_type & I40E_AQ_LLDP_MIB_TYPE_MASK;
3573 cmd->type |= ((bridge_type << I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) &
3574 I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
3575
3576 desc.datalen = cpu_to_le16(buff_size);
3577
3578 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3579 if (buff_size > I40E_AQ_LARGE_BUF)
3580 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3581
3582 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3583 if (!status) {
3584 if (local_len != NULL)
3585 *local_len = le16_to_cpu(resp->local_len);
3586 if (remote_len != NULL)
3587 *remote_len = le16_to_cpu(resp->remote_len);
3588 }
3589
3590 return status;
3591}
3592
3593/**
3594 * i40e_aq_cfg_lldp_mib_change_event
3595 * @hw: pointer to the hw struct
3596 * @enable_update: Enable or Disable event posting
3597 * @cmd_details: pointer to command details structure or NULL
3598 *
3599 * Enable or Disable posting of an event on ARQ when LLDP MIB
3600 * associated with the interface changes
3601 **/
3602i40e_status i40e_aq_cfg_lldp_mib_change_event(struct i40e_hw *hw,
3603 bool enable_update,
3604 struct i40e_asq_cmd_details *cmd_details)
3605{
3606 struct i40e_aq_desc desc;
3607 struct i40e_aqc_lldp_update_mib *cmd =
3608 (struct i40e_aqc_lldp_update_mib *)&desc.params.raw;
3609 i40e_status status;
3610
3611 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_update_mib);
3612
3613 if (!enable_update)
3614 cmd->command |= I40E_AQ_LLDP_MIB_UPDATE_DISABLE;
3615
3616 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3617
3618 return status;
3619}
3620
3621/**
3622 * i40e_aq_stop_lldp
3623 * @hw: pointer to the hw struct
3624 * @shutdown_agent: True if LLDP Agent needs to be Shutdown
3625 * @cmd_details: pointer to command details structure or NULL
3626 *
3627 * Stop or Shutdown the embedded LLDP Agent
3628 **/
3629i40e_status i40e_aq_stop_lldp(struct i40e_hw *hw, bool shutdown_agent,
3630 struct i40e_asq_cmd_details *cmd_details)
3631{
3632 struct i40e_aq_desc desc;
3633 struct i40e_aqc_lldp_stop *cmd =
3634 (struct i40e_aqc_lldp_stop *)&desc.params.raw;
3635 i40e_status status;
3636
3637 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_stop);
3638
3639 if (shutdown_agent)
3640 cmd->command |= I40E_AQ_LLDP_AGENT_SHUTDOWN;
3641
3642 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3643
3644 return status;
3645}
3646
3647/**
3648 * i40e_aq_start_lldp
3649 * @hw: pointer to the hw struct
3650 * @cmd_details: pointer to command details structure or NULL
3651 *
3652 * Start the embedded LLDP Agent on all ports.
3653 **/
3654i40e_status i40e_aq_start_lldp(struct i40e_hw *hw,
3655 struct i40e_asq_cmd_details *cmd_details)
3656{
3657 struct i40e_aq_desc desc;
3658 struct i40e_aqc_lldp_start *cmd =
3659 (struct i40e_aqc_lldp_start *)&desc.params.raw;
3660 i40e_status status;
3661
3662 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_start);
3663
3664 cmd->command = I40E_AQ_LLDP_AGENT_START;
Upasana Menonb6a02a62017-12-27 08:17:07 -05003665 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003666
Upasana Menonb6a02a62017-12-27 08:17:07 -05003667 return status;
3668}
3669
3670/**
3671 * i40e_aq_set_dcb_parameters
3672 * @hw: pointer to the hw struct
3673 * @cmd_details: pointer to command details structure or NULL
3674 * @dcb_enable: True if DCB configuration needs to be applied
3675 *
3676 **/
3677enum i40e_status_code
3678i40e_aq_set_dcb_parameters(struct i40e_hw *hw, bool dcb_enable,
3679 struct i40e_asq_cmd_details *cmd_details)
3680{
3681 struct i40e_aq_desc desc;
3682 struct i40e_aqc_set_dcb_parameters *cmd =
3683 (struct i40e_aqc_set_dcb_parameters *)&desc.params.raw;
3684 i40e_status status;
3685
3686 i40e_fill_default_direct_cmd_desc(&desc,
3687 i40e_aqc_opc_set_dcb_parameters);
3688
3689 if (dcb_enable) {
3690 cmd->valid_flags = I40E_DCB_VALID;
3691 cmd->command = I40E_AQ_DCB_SET_AGENT;
3692 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003693 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3694
3695 return status;
3696}
3697
3698/**
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00003699 * i40e_aq_get_cee_dcb_config
3700 * @hw: pointer to the hw struct
3701 * @buff: response buffer that stores CEE operational configuration
3702 * @buff_size: size of the buffer passed
3703 * @cmd_details: pointer to command details structure or NULL
3704 *
3705 * Get CEE DCBX mode operational configuration from firmware
3706 **/
3707i40e_status i40e_aq_get_cee_dcb_config(struct i40e_hw *hw,
3708 void *buff, u16 buff_size,
3709 struct i40e_asq_cmd_details *cmd_details)
3710{
3711 struct i40e_aq_desc desc;
3712 i40e_status status;
3713
3714 if (buff_size == 0 || !buff)
3715 return I40E_ERR_PARAM;
3716
3717 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_cee_dcb_cfg);
3718
3719 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3720 status = i40e_asq_send_command(hw, &desc, (void *)buff, buff_size,
3721 cmd_details);
3722
3723 return status;
3724}
3725
3726/**
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003727 * i40e_aq_add_udp_tunnel
3728 * @hw: pointer to the hw struct
Jacob Keller15d23b42017-06-07 05:43:04 -04003729 * @udp_port: the UDP port to add in Host byte order
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003730 * @header_len: length of the tunneling header length in DWords
3731 * @protocol_index: protocol index type
Jeff Kirsher98d44382013-12-21 05:44:42 +00003732 * @filter_index: pointer to filter index
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003733 * @cmd_details: pointer to command details structure or NULL
Jacob Keller15d23b42017-06-07 05:43:04 -04003734 *
3735 * Note: Firmware expects the udp_port value to be in Little Endian format,
3736 * and this function will call cpu_to_le16 to convert from Host byte order to
3737 * Little Endian order.
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003738 **/
3739i40e_status i40e_aq_add_udp_tunnel(struct i40e_hw *hw,
Kevin Scottf4f94b92014-04-05 07:46:10 +00003740 u16 udp_port, u8 protocol_index,
3741 u8 *filter_index,
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003742 struct i40e_asq_cmd_details *cmd_details)
3743{
3744 struct i40e_aq_desc desc;
3745 struct i40e_aqc_add_udp_tunnel *cmd =
3746 (struct i40e_aqc_add_udp_tunnel *)&desc.params.raw;
3747 struct i40e_aqc_del_udp_tunnel_completion *resp =
3748 (struct i40e_aqc_del_udp_tunnel_completion *)&desc.params.raw;
3749 i40e_status status;
3750
3751 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_udp_tunnel);
3752
3753 cmd->udp_port = cpu_to_le16(udp_port);
Shannon Nelson981b7542013-12-11 08:17:11 +00003754 cmd->protocol_type = protocol_index;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003755
3756 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3757
Shannon Nelson65d13462015-02-21 06:45:28 +00003758 if (!status && filter_index)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003759 *filter_index = resp->index;
3760
3761 return status;
3762}
3763
3764/**
3765 * i40e_aq_del_udp_tunnel
3766 * @hw: pointer to the hw struct
3767 * @index: filter index
3768 * @cmd_details: pointer to command details structure or NULL
3769 **/
3770i40e_status i40e_aq_del_udp_tunnel(struct i40e_hw *hw, u8 index,
3771 struct i40e_asq_cmd_details *cmd_details)
3772{
3773 struct i40e_aq_desc desc;
3774 struct i40e_aqc_remove_udp_tunnel *cmd =
3775 (struct i40e_aqc_remove_udp_tunnel *)&desc.params.raw;
3776 i40e_status status;
3777
3778 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_del_udp_tunnel);
3779
3780 cmd->index = index;
3781
3782 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3783
3784 return status;
3785}
3786
3787/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003788 * i40e_aq_delete_element - Delete switch element
3789 * @hw: pointer to the hw struct
3790 * @seid: the SEID to delete from the switch
3791 * @cmd_details: pointer to command details structure or NULL
3792 *
3793 * This deletes a switch element from the switch.
3794 **/
3795i40e_status i40e_aq_delete_element(struct i40e_hw *hw, u16 seid,
3796 struct i40e_asq_cmd_details *cmd_details)
3797{
3798 struct i40e_aq_desc desc;
3799 struct i40e_aqc_switch_seid *cmd =
3800 (struct i40e_aqc_switch_seid *)&desc.params.raw;
3801 i40e_status status;
3802
3803 if (seid == 0)
3804 return I40E_ERR_PARAM;
3805
3806 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_delete_element);
3807
3808 cmd->seid = cpu_to_le16(seid);
3809
3810 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3811
3812 return status;
3813}
3814
3815/**
Neerav Parikhafb3ff02014-01-17 15:36:36 -08003816 * i40e_aq_dcb_updated - DCB Updated Command
3817 * @hw: pointer to the hw struct
3818 * @cmd_details: pointer to command details structure or NULL
3819 *
3820 * EMP will return when the shared RPB settings have been
3821 * recomputed and modified. The retval field in the descriptor
3822 * will be set to 0 when RPB is modified.
3823 **/
3824i40e_status i40e_aq_dcb_updated(struct i40e_hw *hw,
3825 struct i40e_asq_cmd_details *cmd_details)
3826{
3827 struct i40e_aq_desc desc;
3828 i40e_status status;
3829
3830 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_dcb_updated);
3831
3832 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3833
3834 return status;
3835}
3836
3837/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003838 * i40e_aq_tx_sched_cmd - generic Tx scheduler AQ command handler
3839 * @hw: pointer to the hw struct
3840 * @seid: seid for the physical port/switching component/vsi
3841 * @buff: Indirect buffer to hold data parameters and response
3842 * @buff_size: Indirect buffer size
3843 * @opcode: Tx scheduler AQ command opcode
3844 * @cmd_details: pointer to command details structure or NULL
3845 *
3846 * Generic command handler for Tx scheduler AQ commands
3847 **/
3848static i40e_status i40e_aq_tx_sched_cmd(struct i40e_hw *hw, u16 seid,
3849 void *buff, u16 buff_size,
3850 enum i40e_admin_queue_opc opcode,
3851 struct i40e_asq_cmd_details *cmd_details)
3852{
3853 struct i40e_aq_desc desc;
3854 struct i40e_aqc_tx_sched_ind *cmd =
3855 (struct i40e_aqc_tx_sched_ind *)&desc.params.raw;
3856 i40e_status status;
3857 bool cmd_param_flag = false;
3858
3859 switch (opcode) {
3860 case i40e_aqc_opc_configure_vsi_ets_sla_bw_limit:
3861 case i40e_aqc_opc_configure_vsi_tc_bw:
3862 case i40e_aqc_opc_enable_switching_comp_ets:
3863 case i40e_aqc_opc_modify_switching_comp_ets:
3864 case i40e_aqc_opc_disable_switching_comp_ets:
3865 case i40e_aqc_opc_configure_switching_comp_ets_bw_limit:
3866 case i40e_aqc_opc_configure_switching_comp_bw_config:
3867 cmd_param_flag = true;
3868 break;
3869 case i40e_aqc_opc_query_vsi_bw_config:
3870 case i40e_aqc_opc_query_vsi_ets_sla_config:
3871 case i40e_aqc_opc_query_switching_comp_ets_config:
3872 case i40e_aqc_opc_query_port_ets_config:
3873 case i40e_aqc_opc_query_switching_comp_bw_config:
3874 cmd_param_flag = false;
3875 break;
3876 default:
3877 return I40E_ERR_PARAM;
3878 }
3879
3880 i40e_fill_default_direct_cmd_desc(&desc, opcode);
3881
3882 /* Indirect command */
3883 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3884 if (cmd_param_flag)
3885 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
3886 if (buff_size > I40E_AQ_LARGE_BUF)
3887 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3888
3889 desc.datalen = cpu_to_le16(buff_size);
3890
3891 cmd->vsi_seid = cpu_to_le16(seid);
3892
3893 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3894
3895 return status;
3896}
3897
3898/**
Mitch Williams6b192892014-03-06 09:02:29 +00003899 * i40e_aq_config_vsi_bw_limit - Configure VSI BW Limit
3900 * @hw: pointer to the hw struct
3901 * @seid: VSI seid
3902 * @credit: BW limit credits (0 = disabled)
3903 * @max_credit: Max BW limit credits
3904 * @cmd_details: pointer to command details structure or NULL
3905 **/
3906i40e_status i40e_aq_config_vsi_bw_limit(struct i40e_hw *hw,
3907 u16 seid, u16 credit, u8 max_credit,
3908 struct i40e_asq_cmd_details *cmd_details)
3909{
3910 struct i40e_aq_desc desc;
3911 struct i40e_aqc_configure_vsi_bw_limit *cmd =
3912 (struct i40e_aqc_configure_vsi_bw_limit *)&desc.params.raw;
3913 i40e_status status;
3914
3915 i40e_fill_default_direct_cmd_desc(&desc,
3916 i40e_aqc_opc_configure_vsi_bw_limit);
3917
3918 cmd->vsi_seid = cpu_to_le16(seid);
3919 cmd->credit = cpu_to_le16(credit);
3920 cmd->max_credit = max_credit;
3921
3922 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3923
3924 return status;
3925}
3926
3927/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003928 * i40e_aq_config_vsi_tc_bw - Config VSI BW Allocation per TC
3929 * @hw: pointer to the hw struct
3930 * @seid: VSI seid
3931 * @bw_data: Buffer holding enabled TCs, relative TC BW limit/credits
3932 * @cmd_details: pointer to command details structure or NULL
3933 **/
3934i40e_status i40e_aq_config_vsi_tc_bw(struct i40e_hw *hw,
3935 u16 seid,
3936 struct i40e_aqc_configure_vsi_tc_bw_data *bw_data,
3937 struct i40e_asq_cmd_details *cmd_details)
3938{
3939 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3940 i40e_aqc_opc_configure_vsi_tc_bw,
3941 cmd_details);
3942}
3943
3944/**
Neerav Parikhafb3ff02014-01-17 15:36:36 -08003945 * i40e_aq_config_switch_comp_ets - Enable/Disable/Modify ETS on the port
3946 * @hw: pointer to the hw struct
3947 * @seid: seid of the switching component connected to Physical Port
3948 * @ets_data: Buffer holding ETS parameters
3949 * @cmd_details: pointer to command details structure or NULL
3950 **/
3951i40e_status i40e_aq_config_switch_comp_ets(struct i40e_hw *hw,
3952 u16 seid,
3953 struct i40e_aqc_configure_switching_comp_ets_data *ets_data,
3954 enum i40e_admin_queue_opc opcode,
3955 struct i40e_asq_cmd_details *cmd_details)
3956{
3957 return i40e_aq_tx_sched_cmd(hw, seid, (void *)ets_data,
3958 sizeof(*ets_data), opcode, cmd_details);
3959}
3960
3961/**
3962 * i40e_aq_config_switch_comp_bw_config - Config Switch comp BW Alloc per TC
3963 * @hw: pointer to the hw struct
3964 * @seid: seid of the switching component
3965 * @bw_data: Buffer holding enabled TCs, relative/absolute TC BW limit/credits
3966 * @cmd_details: pointer to command details structure or NULL
3967 **/
3968i40e_status i40e_aq_config_switch_comp_bw_config(struct i40e_hw *hw,
3969 u16 seid,
3970 struct i40e_aqc_configure_switching_comp_bw_config_data *bw_data,
3971 struct i40e_asq_cmd_details *cmd_details)
3972{
3973 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3974 i40e_aqc_opc_configure_switching_comp_bw_config,
3975 cmd_details);
3976}
3977
3978/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003979 * i40e_aq_query_vsi_bw_config - Query VSI BW configuration
3980 * @hw: pointer to the hw struct
3981 * @seid: seid of the VSI
3982 * @bw_data: Buffer to hold VSI BW configuration
3983 * @cmd_details: pointer to command details structure or NULL
3984 **/
3985i40e_status i40e_aq_query_vsi_bw_config(struct i40e_hw *hw,
3986 u16 seid,
3987 struct i40e_aqc_query_vsi_bw_config_resp *bw_data,
3988 struct i40e_asq_cmd_details *cmd_details)
3989{
3990 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3991 i40e_aqc_opc_query_vsi_bw_config,
3992 cmd_details);
3993}
3994
3995/**
3996 * i40e_aq_query_vsi_ets_sla_config - Query VSI BW configuration per TC
3997 * @hw: pointer to the hw struct
3998 * @seid: seid of the VSI
3999 * @bw_data: Buffer to hold VSI BW configuration per TC
4000 * @cmd_details: pointer to command details structure or NULL
4001 **/
4002i40e_status i40e_aq_query_vsi_ets_sla_config(struct i40e_hw *hw,
4003 u16 seid,
4004 struct i40e_aqc_query_vsi_ets_sla_config_resp *bw_data,
4005 struct i40e_asq_cmd_details *cmd_details)
4006{
4007 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
4008 i40e_aqc_opc_query_vsi_ets_sla_config,
4009 cmd_details);
4010}
4011
4012/**
4013 * i40e_aq_query_switch_comp_ets_config - Query Switch comp BW config per TC
4014 * @hw: pointer to the hw struct
4015 * @seid: seid of the switching component
4016 * @bw_data: Buffer to hold switching component's per TC BW config
4017 * @cmd_details: pointer to command details structure or NULL
4018 **/
4019i40e_status i40e_aq_query_switch_comp_ets_config(struct i40e_hw *hw,
4020 u16 seid,
4021 struct i40e_aqc_query_switching_comp_ets_config_resp *bw_data,
4022 struct i40e_asq_cmd_details *cmd_details)
4023{
4024 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
4025 i40e_aqc_opc_query_switching_comp_ets_config,
4026 cmd_details);
4027}
4028
4029/**
4030 * i40e_aq_query_port_ets_config - Query Physical Port ETS configuration
4031 * @hw: pointer to the hw struct
4032 * @seid: seid of the VSI or switching component connected to Physical Port
4033 * @bw_data: Buffer to hold current ETS configuration for the Physical Port
4034 * @cmd_details: pointer to command details structure or NULL
4035 **/
4036i40e_status i40e_aq_query_port_ets_config(struct i40e_hw *hw,
4037 u16 seid,
4038 struct i40e_aqc_query_port_ets_config_resp *bw_data,
4039 struct i40e_asq_cmd_details *cmd_details)
4040{
4041 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
4042 i40e_aqc_opc_query_port_ets_config,
4043 cmd_details);
4044}
4045
4046/**
4047 * i40e_aq_query_switch_comp_bw_config - Query Switch comp BW configuration
4048 * @hw: pointer to the hw struct
4049 * @seid: seid of the switching component
4050 * @bw_data: Buffer to hold switching component's BW configuration
4051 * @cmd_details: pointer to command details structure or NULL
4052 **/
4053i40e_status i40e_aq_query_switch_comp_bw_config(struct i40e_hw *hw,
4054 u16 seid,
4055 struct i40e_aqc_query_switching_comp_bw_config_resp *bw_data,
4056 struct i40e_asq_cmd_details *cmd_details)
4057{
4058 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
4059 i40e_aqc_opc_query_switching_comp_bw_config,
4060 cmd_details);
4061}
4062
4063/**
4064 * i40e_validate_filter_settings
4065 * @hw: pointer to the hardware structure
4066 * @settings: Filter control settings
4067 *
4068 * Check and validate the filter control settings passed.
4069 * The function checks for the valid filter/context sizes being
4070 * passed for FCoE and PE.
4071 *
4072 * Returns 0 if the values passed are valid and within
4073 * range else returns an error.
4074 **/
4075static i40e_status i40e_validate_filter_settings(struct i40e_hw *hw,
4076 struct i40e_filter_control_settings *settings)
4077{
4078 u32 fcoe_cntx_size, fcoe_filt_size;
4079 u32 pe_cntx_size, pe_filt_size;
Anjali Singhai Jain467d7292014-05-10 04:49:02 +00004080 u32 fcoe_fmax;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00004081 u32 val;
4082
4083 /* Validate FCoE settings passed */
4084 switch (settings->fcoe_filt_num) {
4085 case I40E_HASH_FILTER_SIZE_1K:
4086 case I40E_HASH_FILTER_SIZE_2K:
4087 case I40E_HASH_FILTER_SIZE_4K:
4088 case I40E_HASH_FILTER_SIZE_8K:
4089 case I40E_HASH_FILTER_SIZE_16K:
4090 case I40E_HASH_FILTER_SIZE_32K:
4091 fcoe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
4092 fcoe_filt_size <<= (u32)settings->fcoe_filt_num;
4093 break;
4094 default:
4095 return I40E_ERR_PARAM;
4096 }
4097
4098 switch (settings->fcoe_cntx_num) {
4099 case I40E_DMA_CNTX_SIZE_512:
4100 case I40E_DMA_CNTX_SIZE_1K:
4101 case I40E_DMA_CNTX_SIZE_2K:
4102 case I40E_DMA_CNTX_SIZE_4K:
4103 fcoe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
4104 fcoe_cntx_size <<= (u32)settings->fcoe_cntx_num;
4105 break;
4106 default:
4107 return I40E_ERR_PARAM;
4108 }
4109
4110 /* Validate PE settings passed */
4111 switch (settings->pe_filt_num) {
4112 case I40E_HASH_FILTER_SIZE_1K:
4113 case I40E_HASH_FILTER_SIZE_2K:
4114 case I40E_HASH_FILTER_SIZE_4K:
4115 case I40E_HASH_FILTER_SIZE_8K:
4116 case I40E_HASH_FILTER_SIZE_16K:
4117 case I40E_HASH_FILTER_SIZE_32K:
4118 case I40E_HASH_FILTER_SIZE_64K:
4119 case I40E_HASH_FILTER_SIZE_128K:
4120 case I40E_HASH_FILTER_SIZE_256K:
4121 case I40E_HASH_FILTER_SIZE_512K:
4122 case I40E_HASH_FILTER_SIZE_1M:
4123 pe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
4124 pe_filt_size <<= (u32)settings->pe_filt_num;
4125 break;
4126 default:
4127 return I40E_ERR_PARAM;
4128 }
4129
4130 switch (settings->pe_cntx_num) {
4131 case I40E_DMA_CNTX_SIZE_512:
4132 case I40E_DMA_CNTX_SIZE_1K:
4133 case I40E_DMA_CNTX_SIZE_2K:
4134 case I40E_DMA_CNTX_SIZE_4K:
4135 case I40E_DMA_CNTX_SIZE_8K:
4136 case I40E_DMA_CNTX_SIZE_16K:
4137 case I40E_DMA_CNTX_SIZE_32K:
4138 case I40E_DMA_CNTX_SIZE_64K:
4139 case I40E_DMA_CNTX_SIZE_128K:
4140 case I40E_DMA_CNTX_SIZE_256K:
4141 pe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
4142 pe_cntx_size <<= (u32)settings->pe_cntx_num;
4143 break;
4144 default:
4145 return I40E_ERR_PARAM;
4146 }
4147
4148 /* FCHSIZE + FCDSIZE should not be greater than PMFCOEFMAX */
4149 val = rd32(hw, I40E_GLHMC_FCOEFMAX);
4150 fcoe_fmax = (val & I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_MASK)
4151 >> I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_SHIFT;
4152 if (fcoe_filt_size + fcoe_cntx_size > fcoe_fmax)
4153 return I40E_ERR_INVALID_SIZE;
4154
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00004155 return 0;
4156}
4157
4158/**
4159 * i40e_set_filter_control
4160 * @hw: pointer to the hardware structure
4161 * @settings: Filter control settings
4162 *
4163 * Set the Queue Filters for PE/FCoE and enable filters required
4164 * for a single PF. It is expected that these settings are programmed
4165 * at the driver initialization time.
4166 **/
4167i40e_status i40e_set_filter_control(struct i40e_hw *hw,
4168 struct i40e_filter_control_settings *settings)
4169{
4170 i40e_status ret = 0;
4171 u32 hash_lut_size = 0;
4172 u32 val;
4173
4174 if (!settings)
4175 return I40E_ERR_PARAM;
4176
4177 /* Validate the input settings */
4178 ret = i40e_validate_filter_settings(hw, settings);
4179 if (ret)
4180 return ret;
4181
4182 /* Read the PF Queue Filter control register */
Shannon Nelsonf6581372016-02-17 16:12:20 -08004183 val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00004184
4185 /* Program required PE hash buckets for the PF */
4186 val &= ~I40E_PFQF_CTL_0_PEHSIZE_MASK;
4187 val |= ((u32)settings->pe_filt_num << I40E_PFQF_CTL_0_PEHSIZE_SHIFT) &
4188 I40E_PFQF_CTL_0_PEHSIZE_MASK;
4189 /* Program required PE contexts for the PF */
4190 val &= ~I40E_PFQF_CTL_0_PEDSIZE_MASK;
4191 val |= ((u32)settings->pe_cntx_num << I40E_PFQF_CTL_0_PEDSIZE_SHIFT) &
4192 I40E_PFQF_CTL_0_PEDSIZE_MASK;
4193
4194 /* Program required FCoE hash buckets for the PF */
4195 val &= ~I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
4196 val |= ((u32)settings->fcoe_filt_num <<
4197 I40E_PFQF_CTL_0_PFFCHSIZE_SHIFT) &
4198 I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
4199 /* Program required FCoE DDP contexts for the PF */
4200 val &= ~I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
4201 val |= ((u32)settings->fcoe_cntx_num <<
4202 I40E_PFQF_CTL_0_PFFCDSIZE_SHIFT) &
4203 I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
4204
4205 /* Program Hash LUT size for the PF */
4206 val &= ~I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
4207 if (settings->hash_lut_size == I40E_HASH_LUT_SIZE_512)
4208 hash_lut_size = 1;
4209 val |= (hash_lut_size << I40E_PFQF_CTL_0_HASHLUTSIZE_SHIFT) &
4210 I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
4211
4212 /* Enable FDIR, Ethertype and MACVLAN filters for PF and VFs */
4213 if (settings->enable_fdir)
4214 val |= I40E_PFQF_CTL_0_FD_ENA_MASK;
4215 if (settings->enable_ethtype)
4216 val |= I40E_PFQF_CTL_0_ETYPE_ENA_MASK;
4217 if (settings->enable_macvlan)
4218 val |= I40E_PFQF_CTL_0_MACVLAN_ENA_MASK;
4219
Shannon Nelsonf6581372016-02-17 16:12:20 -08004220 i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, val);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00004221
4222 return 0;
4223}
Neerav Parikhafb3ff02014-01-17 15:36:36 -08004224
4225/**
4226 * i40e_aq_add_rem_control_packet_filter - Add or Remove Control Packet Filter
4227 * @hw: pointer to the hw struct
4228 * @mac_addr: MAC address to use in the filter
4229 * @ethtype: Ethertype to use in the filter
4230 * @flags: Flags that needs to be applied to the filter
4231 * @vsi_seid: seid of the control VSI
4232 * @queue: VSI queue number to send the packet to
4233 * @is_add: Add control packet filter if True else remove
4234 * @stats: Structure to hold information on control filter counts
4235 * @cmd_details: pointer to command details structure or NULL
4236 *
4237 * This command will Add or Remove control packet filter for a control VSI.
4238 * In return it will update the total number of perfect filter count in
4239 * the stats member.
4240 **/
4241i40e_status i40e_aq_add_rem_control_packet_filter(struct i40e_hw *hw,
4242 u8 *mac_addr, u16 ethtype, u16 flags,
4243 u16 vsi_seid, u16 queue, bool is_add,
4244 struct i40e_control_filter_stats *stats,
4245 struct i40e_asq_cmd_details *cmd_details)
4246{
4247 struct i40e_aq_desc desc;
4248 struct i40e_aqc_add_remove_control_packet_filter *cmd =
4249 (struct i40e_aqc_add_remove_control_packet_filter *)
4250 &desc.params.raw;
4251 struct i40e_aqc_add_remove_control_packet_filter_completion *resp =
4252 (struct i40e_aqc_add_remove_control_packet_filter_completion *)
4253 &desc.params.raw;
4254 i40e_status status;
4255
4256 if (vsi_seid == 0)
4257 return I40E_ERR_PARAM;
4258
4259 if (is_add) {
4260 i40e_fill_default_direct_cmd_desc(&desc,
4261 i40e_aqc_opc_add_control_packet_filter);
4262 cmd->queue = cpu_to_le16(queue);
4263 } else {
4264 i40e_fill_default_direct_cmd_desc(&desc,
4265 i40e_aqc_opc_remove_control_packet_filter);
4266 }
4267
4268 if (mac_addr)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04004269 ether_addr_copy(cmd->mac, mac_addr);
Neerav Parikhafb3ff02014-01-17 15:36:36 -08004270
4271 cmd->etype = cpu_to_le16(ethtype);
4272 cmd->flags = cpu_to_le16(flags);
4273 cmd->seid = cpu_to_le16(vsi_seid);
4274
4275 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4276
4277 if (!status && stats) {
4278 stats->mac_etype_used = le16_to_cpu(resp->mac_etype_used);
4279 stats->etype_used = le16_to_cpu(resp->etype_used);
4280 stats->mac_etype_free = le16_to_cpu(resp->mac_etype_free);
4281 stats->etype_free = le16_to_cpu(resp->etype_free);
4282 }
4283
4284 return status;
4285}
4286
Catherine Sullivand4dfb812013-11-28 06:39:21 +00004287/**
Anjali Singhai Jaine7358f52015-10-01 14:37:34 -04004288 * i40e_add_filter_to_drop_tx_flow_control_frames- filter to drop flow control
4289 * @hw: pointer to the hw struct
4290 * @seid: VSI seid to add ethertype filter from
4291 **/
4292#define I40E_FLOW_CONTROL_ETHTYPE 0x8808
4293void i40e_add_filter_to_drop_tx_flow_control_frames(struct i40e_hw *hw,
4294 u16 seid)
4295{
4296 u16 flag = I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC |
4297 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP |
4298 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX;
4299 u16 ethtype = I40E_FLOW_CONTROL_ETHTYPE;
4300 i40e_status status;
4301
4302 status = i40e_aq_add_rem_control_packet_filter(hw, NULL, ethtype, flag,
4303 seid, 0, true, NULL,
4304 NULL);
4305 if (status)
4306 hw_dbg(hw, "Ethtype Filter Add failed: Error pruning Tx flow control frames\n");
4307}
4308
4309/**
Greg Rosef4492db2015-02-06 08:52:12 +00004310 * i40e_aq_alternate_read
4311 * @hw: pointer to the hardware structure
4312 * @reg_addr0: address of first dword to be read
4313 * @reg_val0: pointer for data read from 'reg_addr0'
4314 * @reg_addr1: address of second dword to be read
4315 * @reg_val1: pointer for data read from 'reg_addr1'
4316 *
4317 * Read one or two dwords from alternate structure. Fields are indicated
4318 * by 'reg_addr0' and 'reg_addr1' register numbers. If 'reg_val1' pointer
4319 * is not passed then only register at 'reg_addr0' is read.
4320 *
4321 **/
Shannon Nelson37a29732015-02-27 09:15:19 +00004322static i40e_status i40e_aq_alternate_read(struct i40e_hw *hw,
4323 u32 reg_addr0, u32 *reg_val0,
4324 u32 reg_addr1, u32 *reg_val1)
Greg Rosef4492db2015-02-06 08:52:12 +00004325{
4326 struct i40e_aq_desc desc;
4327 struct i40e_aqc_alternate_write *cmd_resp =
4328 (struct i40e_aqc_alternate_write *)&desc.params.raw;
4329 i40e_status status;
4330
4331 if (!reg_val0)
4332 return I40E_ERR_PARAM;
4333
4334 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_alternate_read);
4335 cmd_resp->address0 = cpu_to_le32(reg_addr0);
4336 cmd_resp->address1 = cpu_to_le32(reg_addr1);
4337
4338 status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
4339
4340 if (!status) {
4341 *reg_val0 = le32_to_cpu(cmd_resp->data0);
4342
4343 if (reg_val1)
4344 *reg_val1 = le32_to_cpu(cmd_resp->data1);
4345 }
4346
4347 return status;
4348}
4349
4350/**
Neerav Parikh2fd75f32014-11-12 00:18:20 +00004351 * i40e_aq_resume_port_tx
4352 * @hw: pointer to the hardware structure
4353 * @cmd_details: pointer to command details structure or NULL
4354 *
4355 * Resume port's Tx traffic
4356 **/
4357i40e_status i40e_aq_resume_port_tx(struct i40e_hw *hw,
4358 struct i40e_asq_cmd_details *cmd_details)
4359{
4360 struct i40e_aq_desc desc;
4361 i40e_status status;
4362
4363 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_resume_port_tx);
4364
4365 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4366
4367 return status;
4368}
4369
4370/**
Catherine Sullivand4dfb812013-11-28 06:39:21 +00004371 * i40e_set_pci_config_data - store PCI bus info
4372 * @hw: pointer to hardware structure
4373 * @link_status: the link status word from PCI config space
4374 *
4375 * Stores the PCI bus info (speed, width, type) within the i40e_hw structure
4376 **/
4377void i40e_set_pci_config_data(struct i40e_hw *hw, u16 link_status)
4378{
4379 hw->bus.type = i40e_bus_type_pci_express;
4380
4381 switch (link_status & PCI_EXP_LNKSTA_NLW) {
4382 case PCI_EXP_LNKSTA_NLW_X1:
4383 hw->bus.width = i40e_bus_width_pcie_x1;
4384 break;
4385 case PCI_EXP_LNKSTA_NLW_X2:
4386 hw->bus.width = i40e_bus_width_pcie_x2;
4387 break;
4388 case PCI_EXP_LNKSTA_NLW_X4:
4389 hw->bus.width = i40e_bus_width_pcie_x4;
4390 break;
4391 case PCI_EXP_LNKSTA_NLW_X8:
4392 hw->bus.width = i40e_bus_width_pcie_x8;
4393 break;
4394 default:
4395 hw->bus.width = i40e_bus_width_unknown;
4396 break;
4397 }
4398
4399 switch (link_status & PCI_EXP_LNKSTA_CLS) {
4400 case PCI_EXP_LNKSTA_CLS_2_5GB:
4401 hw->bus.speed = i40e_bus_speed_2500;
4402 break;
4403 case PCI_EXP_LNKSTA_CLS_5_0GB:
4404 hw->bus.speed = i40e_bus_speed_5000;
4405 break;
4406 case PCI_EXP_LNKSTA_CLS_8_0GB:
4407 hw->bus.speed = i40e_bus_speed_8000;
4408 break;
4409 default:
4410 hw->bus.speed = i40e_bus_speed_unknown;
4411 break;
4412 }
4413}
Greg Rosef4492db2015-02-06 08:52:12 +00004414
4415/**
Jesse Brandeburg3169c322015-04-07 19:45:37 -04004416 * i40e_aq_debug_dump
4417 * @hw: pointer to the hardware structure
4418 * @cluster_id: specific cluster to dump
4419 * @table_id: table id within cluster
4420 * @start_index: index of line in the block to read
4421 * @buff_size: dump buffer size
4422 * @buff: dump buffer
4423 * @ret_buff_size: actual buffer size returned
4424 * @ret_next_table: next block to read
4425 * @ret_next_index: next index to read
4426 *
4427 * Dump internal FW/HW data for debug purposes.
4428 *
4429 **/
4430i40e_status i40e_aq_debug_dump(struct i40e_hw *hw, u8 cluster_id,
4431 u8 table_id, u32 start_index, u16 buff_size,
4432 void *buff, u16 *ret_buff_size,
4433 u8 *ret_next_table, u32 *ret_next_index,
4434 struct i40e_asq_cmd_details *cmd_details)
4435{
4436 struct i40e_aq_desc desc;
4437 struct i40e_aqc_debug_dump_internals *cmd =
4438 (struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
4439 struct i40e_aqc_debug_dump_internals *resp =
4440 (struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
4441 i40e_status status;
4442
4443 if (buff_size == 0 || !buff)
4444 return I40E_ERR_PARAM;
4445
4446 i40e_fill_default_direct_cmd_desc(&desc,
4447 i40e_aqc_opc_debug_dump_internals);
4448 /* Indirect Command */
4449 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
4450 if (buff_size > I40E_AQ_LARGE_BUF)
4451 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
4452
4453 cmd->cluster_id = cluster_id;
4454 cmd->table_id = table_id;
4455 cmd->idx = cpu_to_le32(start_index);
4456
4457 desc.datalen = cpu_to_le16(buff_size);
4458
4459 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
4460 if (!status) {
4461 if (ret_buff_size)
4462 *ret_buff_size = le16_to_cpu(desc.datalen);
4463 if (ret_next_table)
4464 *ret_next_table = resp->table_id;
4465 if (ret_next_index)
4466 *ret_next_index = le32_to_cpu(resp->idx);
4467 }
4468
4469 return status;
4470}
4471
4472/**
Greg Rosef4492db2015-02-06 08:52:12 +00004473 * i40e_read_bw_from_alt_ram
4474 * @hw: pointer to the hardware structure
4475 * @max_bw: pointer for max_bw read
4476 * @min_bw: pointer for min_bw read
4477 * @min_valid: pointer for bool that is true if min_bw is a valid value
4478 * @max_valid: pointer for bool that is true if max_bw is a valid value
4479 *
4480 * Read bw from the alternate ram for the given pf
4481 **/
4482i40e_status i40e_read_bw_from_alt_ram(struct i40e_hw *hw,
4483 u32 *max_bw, u32 *min_bw,
4484 bool *min_valid, bool *max_valid)
4485{
4486 i40e_status status;
4487 u32 max_bw_addr, min_bw_addr;
4488
4489 /* Calculate the address of the min/max bw registers */
4490 max_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
4491 I40E_ALT_STRUCT_MAX_BW_OFFSET +
4492 (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
4493 min_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
4494 I40E_ALT_STRUCT_MIN_BW_OFFSET +
4495 (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
4496
4497 /* Read the bandwidths from alt ram */
4498 status = i40e_aq_alternate_read(hw, max_bw_addr, max_bw,
4499 min_bw_addr, min_bw);
4500
4501 if (*min_bw & I40E_ALT_BW_VALID_MASK)
4502 *min_valid = true;
4503 else
4504 *min_valid = false;
4505
4506 if (*max_bw & I40E_ALT_BW_VALID_MASK)
4507 *max_valid = true;
4508 else
4509 *max_valid = false;
4510
4511 return status;
4512}
4513
4514/**
4515 * i40e_aq_configure_partition_bw
4516 * @hw: pointer to the hardware structure
4517 * @bw_data: Buffer holding valid pfs and bw limits
4518 * @cmd_details: pointer to command details
4519 *
4520 * Configure partitions guaranteed/max bw
4521 **/
4522i40e_status i40e_aq_configure_partition_bw(struct i40e_hw *hw,
4523 struct i40e_aqc_configure_partition_bw_data *bw_data,
4524 struct i40e_asq_cmd_details *cmd_details)
4525{
4526 i40e_status status;
4527 struct i40e_aq_desc desc;
4528 u16 bwd_size = sizeof(*bw_data);
4529
4530 i40e_fill_default_direct_cmd_desc(&desc,
4531 i40e_aqc_opc_configure_partition_bw);
4532
4533 /* Indirect command */
4534 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
4535 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
4536
4537 if (bwd_size > I40E_AQ_LARGE_BUF)
4538 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
4539
4540 desc.datalen = cpu_to_le16(bwd_size);
4541
4542 status = i40e_asq_send_command(hw, &desc, bw_data, bwd_size,
4543 cmd_details);
4544
4545 return status;
4546}
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004547
4548/**
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004549 * i40e_read_phy_register_clause22
4550 * @hw: pointer to the HW structure
4551 * @reg: register address in the page
4552 * @phy_adr: PHY address on MDIO interface
4553 * @value: PHY register value
4554 *
4555 * Reads specified PHY register value
4556 **/
4557i40e_status i40e_read_phy_register_clause22(struct i40e_hw *hw,
4558 u16 reg, u8 phy_addr, u16 *value)
4559{
4560 i40e_status status = I40E_ERR_TIMEOUT;
4561 u8 port_num = (u8)hw->func_caps.mdio_port_num;
4562 u32 command = 0;
4563 u16 retry = 1000;
4564
4565 command = (reg << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4566 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
4567 (I40E_MDIO_CLAUSE22_OPCODE_READ_MASK) |
4568 (I40E_MDIO_CLAUSE22_STCODE_MASK) |
4569 (I40E_GLGEN_MSCA_MDICMD_MASK);
4570 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4571 do {
4572 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4573 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4574 status = 0;
4575 break;
4576 }
4577 udelay(10);
4578 retry--;
4579 } while (retry);
4580
4581 if (status) {
4582 i40e_debug(hw, I40E_DEBUG_PHY,
4583 "PHY: Can't write command to external PHY.\n");
Henry Tieman27e5f252016-11-08 13:05:06 -08004584 } else {
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004585 command = rd32(hw, I40E_GLGEN_MSRWD(port_num));
4586 *value = (command & I40E_GLGEN_MSRWD_MDIRDDATA_MASK) >>
4587 I40E_GLGEN_MSRWD_MDIRDDATA_SHIFT;
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004588 }
4589
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004590 return status;
4591}
4592
4593/**
4594 * i40e_write_phy_register_clause22
4595 * @hw: pointer to the HW structure
4596 * @reg: register address in the page
4597 * @phy_adr: PHY address on MDIO interface
4598 * @value: PHY register value
4599 *
4600 * Writes specified PHY register value
4601 **/
4602i40e_status i40e_write_phy_register_clause22(struct i40e_hw *hw,
4603 u16 reg, u8 phy_addr, u16 value)
4604{
4605 i40e_status status = I40E_ERR_TIMEOUT;
4606 u8 port_num = (u8)hw->func_caps.mdio_port_num;
4607 u32 command = 0;
4608 u16 retry = 1000;
4609
4610 command = value << I40E_GLGEN_MSRWD_MDIWRDATA_SHIFT;
4611 wr32(hw, I40E_GLGEN_MSRWD(port_num), command);
4612
4613 command = (reg << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4614 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
4615 (I40E_MDIO_CLAUSE22_OPCODE_WRITE_MASK) |
4616 (I40E_MDIO_CLAUSE22_STCODE_MASK) |
4617 (I40E_GLGEN_MSCA_MDICMD_MASK);
4618
4619 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4620 do {
4621 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4622 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4623 status = 0;
4624 break;
4625 }
4626 udelay(10);
4627 retry--;
4628 } while (retry);
4629
4630 return status;
4631}
4632
4633/**
4634 * i40e_read_phy_register_clause45
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004635 * @hw: pointer to the HW structure
4636 * @page: registers page number
4637 * @reg: register address in the page
4638 * @phy_adr: PHY address on MDIO interface
4639 * @value: PHY register value
4640 *
4641 * Reads specified PHY register value
4642 **/
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004643i40e_status i40e_read_phy_register_clause45(struct i40e_hw *hw,
4644 u8 page, u16 reg, u8 phy_addr, u16 *value)
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004645{
4646 i40e_status status = I40E_ERR_TIMEOUT;
4647 u32 command = 0;
4648 u16 retry = 1000;
4649 u8 port_num = hw->func_caps.mdio_port_num;
4650
4651 command = (reg << I40E_GLGEN_MSCA_MDIADD_SHIFT) |
4652 (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4653 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004654 (I40E_MDIO_CLAUSE45_OPCODE_ADDRESS_MASK) |
4655 (I40E_MDIO_CLAUSE45_STCODE_MASK) |
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004656 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4657 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4658 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4659 do {
4660 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4661 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4662 status = 0;
4663 break;
4664 }
4665 usleep_range(10, 20);
4666 retry--;
4667 } while (retry);
4668
4669 if (status) {
4670 i40e_debug(hw, I40E_DEBUG_PHY,
4671 "PHY: Can't write command to external PHY.\n");
4672 goto phy_read_end;
4673 }
4674
4675 command = (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4676 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004677 (I40E_MDIO_CLAUSE45_OPCODE_READ_MASK) |
4678 (I40E_MDIO_CLAUSE45_STCODE_MASK) |
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004679 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4680 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4681 status = I40E_ERR_TIMEOUT;
4682 retry = 1000;
4683 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4684 do {
4685 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4686 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4687 status = 0;
4688 break;
4689 }
4690 usleep_range(10, 20);
4691 retry--;
4692 } while (retry);
4693
4694 if (!status) {
4695 command = rd32(hw, I40E_GLGEN_MSRWD(port_num));
4696 *value = (command & I40E_GLGEN_MSRWD_MDIRDDATA_MASK) >>
4697 I40E_GLGEN_MSRWD_MDIRDDATA_SHIFT;
4698 } else {
4699 i40e_debug(hw, I40E_DEBUG_PHY,
4700 "PHY: Can't read register value from external PHY.\n");
4701 }
4702
4703phy_read_end:
4704 return status;
4705}
4706
4707/**
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004708 * i40e_write_phy_register_clause45
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004709 * @hw: pointer to the HW structure
4710 * @page: registers page number
4711 * @reg: register address in the page
4712 * @phy_adr: PHY address on MDIO interface
4713 * @value: PHY register value
4714 *
4715 * Writes value to specified PHY register
4716 **/
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004717i40e_status i40e_write_phy_register_clause45(struct i40e_hw *hw,
4718 u8 page, u16 reg, u8 phy_addr, u16 value)
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004719{
4720 i40e_status status = I40E_ERR_TIMEOUT;
4721 u32 command = 0;
4722 u16 retry = 1000;
4723 u8 port_num = hw->func_caps.mdio_port_num;
4724
4725 command = (reg << I40E_GLGEN_MSCA_MDIADD_SHIFT) |
4726 (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4727 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004728 (I40E_MDIO_CLAUSE45_OPCODE_ADDRESS_MASK) |
4729 (I40E_MDIO_CLAUSE45_STCODE_MASK) |
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004730 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4731 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4732 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4733 do {
4734 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4735 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4736 status = 0;
4737 break;
4738 }
4739 usleep_range(10, 20);
4740 retry--;
4741 } while (retry);
4742 if (status) {
4743 i40e_debug(hw, I40E_DEBUG_PHY,
4744 "PHY: Can't write command to external PHY.\n");
4745 goto phy_write_end;
4746 }
4747
4748 command = value << I40E_GLGEN_MSRWD_MDIWRDATA_SHIFT;
4749 wr32(hw, I40E_GLGEN_MSRWD(port_num), command);
4750
4751 command = (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4752 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004753 (I40E_MDIO_CLAUSE45_OPCODE_WRITE_MASK) |
4754 (I40E_MDIO_CLAUSE45_STCODE_MASK) |
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004755 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4756 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4757 status = I40E_ERR_TIMEOUT;
4758 retry = 1000;
4759 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4760 do {
4761 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4762 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4763 status = 0;
4764 break;
4765 }
4766 usleep_range(10, 20);
4767 retry--;
4768 } while (retry);
4769
4770phy_write_end:
4771 return status;
4772}
4773
4774/**
Michal Kosiarzf62ba912016-11-21 13:03:50 -08004775 * i40e_write_phy_register
4776 * @hw: pointer to the HW structure
4777 * @page: registers page number
4778 * @reg: register address in the page
4779 * @phy_adr: PHY address on MDIO interface
4780 * @value: PHY register value
4781 *
4782 * Writes value to specified PHY register
4783 **/
4784i40e_status i40e_write_phy_register(struct i40e_hw *hw,
4785 u8 page, u16 reg, u8 phy_addr, u16 value)
4786{
4787 i40e_status status;
4788
4789 switch (hw->device_id) {
4790 case I40E_DEV_ID_1G_BASE_T_X722:
4791 status = i40e_write_phy_register_clause22(hw, reg, phy_addr,
4792 value);
4793 break;
4794 case I40E_DEV_ID_10G_BASE_T:
4795 case I40E_DEV_ID_10G_BASE_T4:
4796 case I40E_DEV_ID_10G_BASE_T_X722:
4797 case I40E_DEV_ID_25G_B:
4798 case I40E_DEV_ID_25G_SFP28:
4799 status = i40e_write_phy_register_clause45(hw, page, reg,
4800 phy_addr, value);
4801 break;
4802 default:
4803 status = I40E_ERR_UNKNOWN_PHY;
4804 break;
4805 }
4806
4807 return status;
4808}
4809
4810/**
4811 * i40e_read_phy_register
4812 * @hw: pointer to the HW structure
4813 * @page: registers page number
4814 * @reg: register address in the page
4815 * @phy_adr: PHY address on MDIO interface
4816 * @value: PHY register value
4817 *
4818 * Reads specified PHY register value
4819 **/
4820i40e_status i40e_read_phy_register(struct i40e_hw *hw,
4821 u8 page, u16 reg, u8 phy_addr, u16 *value)
4822{
4823 i40e_status status;
4824
4825 switch (hw->device_id) {
4826 case I40E_DEV_ID_1G_BASE_T_X722:
4827 status = i40e_read_phy_register_clause22(hw, reg, phy_addr,
4828 value);
4829 break;
4830 case I40E_DEV_ID_10G_BASE_T:
4831 case I40E_DEV_ID_10G_BASE_T4:
4832 case I40E_DEV_ID_10G_BASE_T_X722:
4833 case I40E_DEV_ID_25G_B:
4834 case I40E_DEV_ID_25G_SFP28:
4835 status = i40e_read_phy_register_clause45(hw, page, reg,
4836 phy_addr, value);
4837 break;
4838 default:
4839 status = I40E_ERR_UNKNOWN_PHY;
4840 break;
4841 }
4842
4843 return status;
4844}
4845
4846/**
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004847 * i40e_get_phy_address
4848 * @hw: pointer to the HW structure
4849 * @dev_num: PHY port num that address we want
4850 * @phy_addr: Returned PHY address
4851 *
4852 * Gets PHY address for current port
4853 **/
4854u8 i40e_get_phy_address(struct i40e_hw *hw, u8 dev_num)
4855{
4856 u8 port_num = hw->func_caps.mdio_port_num;
4857 u32 reg_val = rd32(hw, I40E_GLGEN_MDIO_I2C_SEL(port_num));
4858
4859 return (u8)(reg_val >> ((dev_num + 1) * 5)) & 0x1f;
4860}
4861
4862/**
4863 * i40e_blink_phy_led
4864 * @hw: pointer to the HW structure
4865 * @time: time how long led will blinks in secs
4866 * @interval: gap between LED on and off in msecs
4867 *
4868 * Blinks PHY link LED
4869 **/
4870i40e_status i40e_blink_phy_link_led(struct i40e_hw *hw,
4871 u32 time, u32 interval)
4872{
4873 i40e_status status = 0;
4874 u32 i;
4875 u16 led_ctl;
4876 u16 gpio_led_port;
4877 u16 led_reg;
4878 u16 led_addr = I40E_PHY_LED_PROV_REG_1;
4879 u8 phy_addr = 0;
4880 u8 port_num;
4881
4882 i = rd32(hw, I40E_PFGEN_PORTNUM);
4883 port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
4884 phy_addr = i40e_get_phy_address(hw, port_num);
4885
4886 for (gpio_led_port = 0; gpio_led_port < 3; gpio_led_port++,
4887 led_addr++) {
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004888 status = i40e_read_phy_register_clause45(hw,
4889 I40E_PHY_COM_REG_PAGE,
4890 led_addr, phy_addr,
4891 &led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004892 if (status)
4893 goto phy_blinking_end;
4894 led_ctl = led_reg;
4895 if (led_reg & I40E_PHY_LED_LINK_MODE_MASK) {
4896 led_reg = 0;
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004897 status = i40e_write_phy_register_clause45(hw,
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004898 I40E_PHY_COM_REG_PAGE,
4899 led_addr, phy_addr,
4900 led_reg);
4901 if (status)
4902 goto phy_blinking_end;
4903 break;
4904 }
4905 }
4906
4907 if (time > 0 && interval > 0) {
4908 for (i = 0; i < time * 1000; i += interval) {
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004909 status = i40e_read_phy_register_clause45(hw,
4910 I40E_PHY_COM_REG_PAGE,
4911 led_addr, phy_addr, &led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004912 if (status)
4913 goto restore_config;
4914 if (led_reg & I40E_PHY_LED_MANUAL_ON)
4915 led_reg = 0;
4916 else
4917 led_reg = I40E_PHY_LED_MANUAL_ON;
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004918 status = i40e_write_phy_register_clause45(hw,
4919 I40E_PHY_COM_REG_PAGE,
4920 led_addr, phy_addr, led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004921 if (status)
4922 goto restore_config;
4923 msleep(interval);
4924 }
4925 }
4926
4927restore_config:
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004928 status = i40e_write_phy_register_clause45(hw,
4929 I40E_PHY_COM_REG_PAGE,
4930 led_addr, phy_addr, led_ctl);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004931
4932phy_blinking_end:
4933 return status;
4934}
4935
4936/**
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04004937 * i40e_led_get_reg - read LED register
4938 * @hw: pointer to the HW structure
4939 * @led_addr: LED register address
4940 * @reg_val: read register value
4941 **/
4942static enum i40e_status_code i40e_led_get_reg(struct i40e_hw *hw, u16 led_addr,
4943 u32 *reg_val)
4944{
4945 enum i40e_status_code status;
4946 u8 phy_addr = 0;
4947 u8 port_num;
4948 u32 i;
4949
4950 *reg_val = 0;
4951 if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) {
4952 status =
4953 i40e_aq_get_phy_register(hw,
4954 I40E_AQ_PHY_REG_ACCESS_EXTERNAL,
4955 I40E_PHY_COM_REG_PAGE,
4956 I40E_PHY_LED_PROV_REG_1,
4957 reg_val, NULL);
4958 } else {
4959 i = rd32(hw, I40E_PFGEN_PORTNUM);
4960 port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
4961 phy_addr = i40e_get_phy_address(hw, port_num);
4962 status = i40e_read_phy_register_clause45(hw,
4963 I40E_PHY_COM_REG_PAGE,
4964 led_addr, phy_addr,
4965 (u16 *)reg_val);
4966 }
4967 return status;
4968}
4969
4970/**
4971 * i40e_led_set_reg - write LED register
4972 * @hw: pointer to the HW structure
4973 * @led_addr: LED register address
4974 * @reg_val: register value to write
4975 **/
4976static enum i40e_status_code i40e_led_set_reg(struct i40e_hw *hw, u16 led_addr,
4977 u32 reg_val)
4978{
4979 enum i40e_status_code status;
4980 u8 phy_addr = 0;
4981 u8 port_num;
4982 u32 i;
4983
4984 if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) {
4985 status =
4986 i40e_aq_set_phy_register(hw,
4987 I40E_AQ_PHY_REG_ACCESS_EXTERNAL,
4988 I40E_PHY_COM_REG_PAGE,
4989 I40E_PHY_LED_PROV_REG_1,
4990 reg_val, NULL);
4991 } else {
4992 i = rd32(hw, I40E_PFGEN_PORTNUM);
4993 port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
4994 phy_addr = i40e_get_phy_address(hw, port_num);
4995 status = i40e_write_phy_register_clause45(hw,
4996 I40E_PHY_COM_REG_PAGE,
4997 led_addr, phy_addr,
4998 (u16)reg_val);
4999 }
5000
5001 return status;
5002}
5003
5004/**
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005005 * i40e_led_get_phy - return current on/off mode
5006 * @hw: pointer to the hw struct
5007 * @led_addr: address of led register to use
5008 * @val: original value of register to use
5009 *
5010 **/
5011i40e_status i40e_led_get_phy(struct i40e_hw *hw, u16 *led_addr,
5012 u16 *val)
5013{
5014 i40e_status status = 0;
5015 u16 gpio_led_port;
5016 u8 phy_addr = 0;
5017 u16 reg_val;
5018 u16 temp_addr;
5019 u8 port_num;
5020 u32 i;
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005021 u32 reg_val_aq;
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005022
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005023 if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) {
5024 status =
5025 i40e_aq_get_phy_register(hw,
5026 I40E_AQ_PHY_REG_ACCESS_EXTERNAL,
5027 I40E_PHY_COM_REG_PAGE,
5028 I40E_PHY_LED_PROV_REG_1,
5029 &reg_val_aq, NULL);
5030 if (status == I40E_SUCCESS)
5031 *val = (u16)reg_val_aq;
5032 return status;
5033 }
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005034 temp_addr = I40E_PHY_LED_PROV_REG_1;
5035 i = rd32(hw, I40E_PFGEN_PORTNUM);
5036 port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
5037 phy_addr = i40e_get_phy_address(hw, port_num);
5038
5039 for (gpio_led_port = 0; gpio_led_port < 3; gpio_led_port++,
5040 temp_addr++) {
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07005041 status = i40e_read_phy_register_clause45(hw,
5042 I40E_PHY_COM_REG_PAGE,
5043 temp_addr, phy_addr,
5044 &reg_val);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005045 if (status)
5046 return status;
5047 *val = reg_val;
5048 if (reg_val & I40E_PHY_LED_LINK_MODE_MASK) {
5049 *led_addr = temp_addr;
5050 break;
5051 }
5052 }
5053 return status;
5054}
5055
5056/**
5057 * i40e_led_set_phy
5058 * @hw: pointer to the HW structure
5059 * @on: true or false
5060 * @mode: original val plus bit for set or ignore
5061 * Set led's on or off when controlled by the PHY
5062 *
5063 **/
5064i40e_status i40e_led_set_phy(struct i40e_hw *hw, bool on,
5065 u16 led_addr, u32 mode)
5066{
5067 i40e_status status = 0;
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005068 u32 led_ctl = 0;
5069 u32 led_reg = 0;
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005070
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005071 status = i40e_led_get_reg(hw, led_addr, &led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005072 if (status)
5073 return status;
5074 led_ctl = led_reg;
5075 if (led_reg & I40E_PHY_LED_LINK_MODE_MASK) {
5076 led_reg = 0;
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005077 status = i40e_led_set_reg(hw, led_addr, led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005078 if (status)
5079 return status;
5080 }
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005081 status = i40e_led_get_reg(hw, led_addr, &led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005082 if (status)
5083 goto restore_config;
5084 if (on)
5085 led_reg = I40E_PHY_LED_MANUAL_ON;
5086 else
5087 led_reg = 0;
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005088
5089 status = i40e_led_set_reg(hw, led_addr, led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005090 if (status)
5091 goto restore_config;
5092 if (mode & I40E_PHY_LED_MODE_ORIG) {
5093 led_ctl = (mode & I40E_PHY_LED_MODE_MASK);
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005094 status = i40e_led_set_reg(hw, led_addr, led_ctl);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005095 }
5096 return status;
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005097
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005098restore_config:
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005099 status = i40e_led_set_reg(hw, led_addr, led_ctl);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005100 return status;
5101}
Shannon Nelsonf6581372016-02-17 16:12:20 -08005102
5103/**
5104 * i40e_aq_rx_ctl_read_register - use FW to read from an Rx control register
5105 * @hw: pointer to the hw struct
5106 * @reg_addr: register address
5107 * @reg_val: ptr to register value
5108 * @cmd_details: pointer to command details structure or NULL
5109 *
5110 * Use the firmware to read the Rx control register,
5111 * especially useful if the Rx unit is under heavy pressure
5112 **/
5113i40e_status i40e_aq_rx_ctl_read_register(struct i40e_hw *hw,
5114 u32 reg_addr, u32 *reg_val,
5115 struct i40e_asq_cmd_details *cmd_details)
5116{
5117 struct i40e_aq_desc desc;
5118 struct i40e_aqc_rx_ctl_reg_read_write *cmd_resp =
5119 (struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
5120 i40e_status status;
5121
5122 if (!reg_val)
5123 return I40E_ERR_PARAM;
5124
5125 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_rx_ctl_reg_read);
5126
5127 cmd_resp->address = cpu_to_le32(reg_addr);
5128
5129 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5130
5131 if (status == 0)
5132 *reg_val = le32_to_cpu(cmd_resp->value);
5133
5134 return status;
5135}
5136
5137/**
5138 * i40e_read_rx_ctl - read from an Rx control register
5139 * @hw: pointer to the hw struct
5140 * @reg_addr: register address
5141 **/
5142u32 i40e_read_rx_ctl(struct i40e_hw *hw, u32 reg_addr)
5143{
5144 i40e_status status = 0;
5145 bool use_register;
5146 int retry = 5;
5147 u32 val = 0;
5148
Paul M Stillwell Jr60303082017-03-10 12:22:02 -08005149 use_register = (((hw->aq.api_maj_ver == 1) &&
5150 (hw->aq.api_min_ver < 5)) ||
5151 (hw->mac.type == I40E_MAC_X722));
Shannon Nelsonf6581372016-02-17 16:12:20 -08005152 if (!use_register) {
5153do_retry:
5154 status = i40e_aq_rx_ctl_read_register(hw, reg_addr, &val, NULL);
5155 if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
5156 usleep_range(1000, 2000);
5157 retry--;
5158 goto do_retry;
5159 }
5160 }
5161
5162 /* if the AQ access failed, try the old-fashioned way */
5163 if (status || use_register)
5164 val = rd32(hw, reg_addr);
5165
5166 return val;
5167}
5168
5169/**
5170 * i40e_aq_rx_ctl_write_register
5171 * @hw: pointer to the hw struct
5172 * @reg_addr: register address
5173 * @reg_val: register value
5174 * @cmd_details: pointer to command details structure or NULL
5175 *
5176 * Use the firmware to write to an Rx control register,
5177 * especially useful if the Rx unit is under heavy pressure
5178 **/
5179i40e_status i40e_aq_rx_ctl_write_register(struct i40e_hw *hw,
5180 u32 reg_addr, u32 reg_val,
5181 struct i40e_asq_cmd_details *cmd_details)
5182{
5183 struct i40e_aq_desc desc;
5184 struct i40e_aqc_rx_ctl_reg_read_write *cmd =
5185 (struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
5186 i40e_status status;
5187
5188 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_rx_ctl_reg_write);
5189
5190 cmd->address = cpu_to_le32(reg_addr);
5191 cmd->value = cpu_to_le32(reg_val);
5192
5193 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5194
5195 return status;
5196}
5197
5198/**
5199 * i40e_write_rx_ctl - write to an Rx control register
5200 * @hw: pointer to the hw struct
5201 * @reg_addr: register address
5202 * @reg_val: register value
5203 **/
5204void i40e_write_rx_ctl(struct i40e_hw *hw, u32 reg_addr, u32 reg_val)
5205{
5206 i40e_status status = 0;
5207 bool use_register;
5208 int retry = 5;
5209
Paul M Stillwell Jr60303082017-03-10 12:22:02 -08005210 use_register = (((hw->aq.api_maj_ver == 1) &&
5211 (hw->aq.api_min_ver < 5)) ||
5212 (hw->mac.type == I40E_MAC_X722));
Shannon Nelsonf6581372016-02-17 16:12:20 -08005213 if (!use_register) {
5214do_retry:
5215 status = i40e_aq_rx_ctl_write_register(hw, reg_addr,
5216 reg_val, NULL);
5217 if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
5218 usleep_range(1000, 2000);
5219 retry--;
5220 goto do_retry;
5221 }
5222 }
5223
5224 /* if the AQ access failed, try the old-fashioned way */
5225 if (status || use_register)
5226 wr32(hw, reg_addr, reg_val);
5227}
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005228
5229/**
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04005230 * i40e_aq_set_phy_register
5231 * @hw: pointer to the hw struct
5232 * @phy_select: select which phy should be accessed
5233 * @dev_addr: PHY device address
5234 * @reg_addr: PHY register address
5235 * @reg_val: new register value
5236 * @cmd_details: pointer to command details structure or NULL
5237 *
5238 * Write the external PHY register.
5239 **/
5240i40e_status i40e_aq_set_phy_register(struct i40e_hw *hw,
5241 u8 phy_select, u8 dev_addr,
5242 u32 reg_addr, u32 reg_val,
5243 struct i40e_asq_cmd_details *cmd_details)
5244{
5245 struct i40e_aq_desc desc;
5246 struct i40e_aqc_phy_register_access *cmd =
5247 (struct i40e_aqc_phy_register_access *)&desc.params.raw;
5248 i40e_status status;
5249
5250 i40e_fill_default_direct_cmd_desc(&desc,
5251 i40e_aqc_opc_set_phy_register);
5252
5253 cmd->phy_interface = phy_select;
5254 cmd->dev_address = dev_addr;
5255 cmd->reg_address = cpu_to_le32(reg_addr);
5256 cmd->reg_value = cpu_to_le32(reg_val);
5257
5258 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5259
5260 return status;
5261}
5262
5263/**
5264 * i40e_aq_get_phy_register
5265 * @hw: pointer to the hw struct
5266 * @phy_select: select which phy should be accessed
5267 * @dev_addr: PHY device address
5268 * @reg_addr: PHY register address
5269 * @reg_val: read register value
5270 * @cmd_details: pointer to command details structure or NULL
5271 *
5272 * Read the external PHY register.
5273 **/
5274i40e_status i40e_aq_get_phy_register(struct i40e_hw *hw,
5275 u8 phy_select, u8 dev_addr,
5276 u32 reg_addr, u32 *reg_val,
5277 struct i40e_asq_cmd_details *cmd_details)
5278{
5279 struct i40e_aq_desc desc;
5280 struct i40e_aqc_phy_register_access *cmd =
5281 (struct i40e_aqc_phy_register_access *)&desc.params.raw;
5282 i40e_status status;
5283
5284 i40e_fill_default_direct_cmd_desc(&desc,
5285 i40e_aqc_opc_get_phy_register);
5286
5287 cmd->phy_interface = phy_select;
5288 cmd->dev_address = dev_addr;
5289 cmd->reg_address = cpu_to_le32(reg_addr);
5290
5291 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5292 if (!status)
5293 *reg_val = le32_to_cpu(cmd->reg_value);
5294
5295 return status;
5296}
5297
5298/**
Jingjing Wu329e5982017-11-14 07:00:47 -05005299 * i40e_aq_write_ddp - Write dynamic device personalization (ddp)
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005300 * @hw: pointer to the hw struct
5301 * @buff: command buffer (size in bytes = buff_size)
5302 * @buff_size: buffer size in bytes
5303 * @track_id: package tracking id
5304 * @error_offset: returns error offset
5305 * @error_info: returns error information
5306 * @cmd_details: pointer to command details structure or NULL
5307 **/
5308enum
Jingjing Wu329e5982017-11-14 07:00:47 -05005309i40e_status_code i40e_aq_write_ddp(struct i40e_hw *hw, void *buff,
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005310 u16 buff_size, u32 track_id,
5311 u32 *error_offset, u32 *error_info,
5312 struct i40e_asq_cmd_details *cmd_details)
5313{
5314 struct i40e_aq_desc desc;
5315 struct i40e_aqc_write_personalization_profile *cmd =
5316 (struct i40e_aqc_write_personalization_profile *)
5317 &desc.params.raw;
Jingjing Wu329e5982017-11-14 07:00:47 -05005318 struct i40e_aqc_write_ddp_resp *resp;
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005319 i40e_status status;
5320
5321 i40e_fill_default_direct_cmd_desc(&desc,
5322 i40e_aqc_opc_write_personalization_profile);
5323
5324 desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
5325 if (buff_size > I40E_AQ_LARGE_BUF)
5326 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
5327
5328 desc.datalen = cpu_to_le16(buff_size);
5329
5330 cmd->profile_track_id = cpu_to_le32(track_id);
5331
5332 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
5333 if (!status) {
Jingjing Wu329e5982017-11-14 07:00:47 -05005334 resp = (struct i40e_aqc_write_ddp_resp *)&desc.params.raw;
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005335 if (error_offset)
5336 *error_offset = le32_to_cpu(resp->error_offset);
5337 if (error_info)
5338 *error_info = le32_to_cpu(resp->error_info);
5339 }
5340
5341 return status;
5342}
5343
5344/**
Jingjing Wu329e5982017-11-14 07:00:47 -05005345 * i40e_aq_get_ddp_list - Read dynamic device personalization (ddp)
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005346 * @hw: pointer to the hw struct
5347 * @buff: command buffer (size in bytes = buff_size)
5348 * @buff_size: buffer size in bytes
5349 * @cmd_details: pointer to command details structure or NULL
5350 **/
5351enum
Jingjing Wu329e5982017-11-14 07:00:47 -05005352i40e_status_code i40e_aq_get_ddp_list(struct i40e_hw *hw, void *buff,
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005353 u16 buff_size, u8 flags,
5354 struct i40e_asq_cmd_details *cmd_details)
5355{
5356 struct i40e_aq_desc desc;
5357 struct i40e_aqc_get_applied_profiles *cmd =
5358 (struct i40e_aqc_get_applied_profiles *)&desc.params.raw;
5359 i40e_status status;
5360
5361 i40e_fill_default_direct_cmd_desc(&desc,
5362 i40e_aqc_opc_get_personalization_profile_list);
5363
5364 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
5365 if (buff_size > I40E_AQ_LARGE_BUF)
5366 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
5367 desc.datalen = cpu_to_le16(buff_size);
5368
5369 cmd->flags = flags;
5370
5371 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
5372
5373 return status;
5374}
5375
5376/**
5377 * i40e_find_segment_in_package
5378 * @segment_type: the segment type to search for (i.e., SEGMENT_TYPE_I40E)
5379 * @pkg_hdr: pointer to the package header to be searched
5380 *
5381 * This function searches a package file for a particular segment type. On
5382 * success it returns a pointer to the segment header, otherwise it will
5383 * return NULL.
5384 **/
5385struct i40e_generic_seg_header *
5386i40e_find_segment_in_package(u32 segment_type,
5387 struct i40e_package_header *pkg_hdr)
5388{
5389 struct i40e_generic_seg_header *segment;
5390 u32 i;
5391
5392 /* Search all package segments for the requested segment type */
5393 for (i = 0; i < pkg_hdr->segment_count; i++) {
5394 segment =
5395 (struct i40e_generic_seg_header *)((u8 *)pkg_hdr +
5396 pkg_hdr->segment_offset[i]);
5397
5398 if (segment->type == segment_type)
5399 return segment;
5400 }
5401
5402 return NULL;
5403}
5404
5405/**
5406 * i40e_write_profile
5407 * @hw: pointer to the hardware structure
5408 * @profile: pointer to the profile segment of the package to be downloaded
5409 * @track_id: package tracking id
5410 *
5411 * Handles the download of a complete package.
5412 */
5413enum i40e_status_code
5414i40e_write_profile(struct i40e_hw *hw, struct i40e_profile_segment *profile,
5415 u32 track_id)
5416{
5417 i40e_status status = 0;
5418 struct i40e_section_table *sec_tbl;
5419 struct i40e_profile_section_header *sec = NULL;
5420 u32 dev_cnt;
5421 u32 vendor_dev_id;
5422 u32 *nvm;
5423 u32 section_size = 0;
5424 u32 offset = 0, info = 0;
5425 u32 i;
5426
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005427 dev_cnt = profile->device_table_count;
5428
5429 for (i = 0; i < dev_cnt; i++) {
5430 vendor_dev_id = profile->device_table[i].vendor_dev_id;
5431 if ((vendor_dev_id >> 16) == PCI_VENDOR_ID_INTEL)
5432 if (hw->device_id == (vendor_dev_id & 0xFFFF))
5433 break;
5434 }
5435 if (i == dev_cnt) {
Jingjing Wu329e5982017-11-14 07:00:47 -05005436 i40e_debug(hw, I40E_DEBUG_PACKAGE, "Device doesn't support DDP");
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005437 return I40E_ERR_DEVICE_NOT_SUPPORTED;
5438 }
5439
5440 nvm = (u32 *)&profile->device_table[dev_cnt];
5441 sec_tbl = (struct i40e_section_table *)&nvm[nvm[0] + 1];
5442
5443 for (i = 0; i < sec_tbl->section_count; i++) {
5444 sec = (struct i40e_profile_section_header *)((u8 *)profile +
5445 sec_tbl->section_offset[i]);
5446
5447 /* Skip 'AQ', 'note' and 'name' sections */
5448 if (sec->section.type != SECTION_TYPE_MMIO)
5449 continue;
5450
5451 section_size = sec->section.size +
5452 sizeof(struct i40e_profile_section_header);
5453
5454 /* Write profile */
Jingjing Wu329e5982017-11-14 07:00:47 -05005455 status = i40e_aq_write_ddp(hw, (void *)sec, (u16)section_size,
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005456 track_id, &offset, &info, NULL);
5457 if (status) {
5458 i40e_debug(hw, I40E_DEBUG_PACKAGE,
5459 "Failed to write profile: offset %d, info %d",
5460 offset, info);
5461 break;
5462 }
5463 }
5464 return status;
5465}
5466
5467/**
5468 * i40e_add_pinfo_to_list
5469 * @hw: pointer to the hardware structure
5470 * @profile: pointer to the profile segment of the package
5471 * @profile_info_sec: buffer for information section
5472 * @track_id: package tracking id
5473 *
5474 * Register a profile to the list of loaded profiles.
5475 */
5476enum i40e_status_code
5477i40e_add_pinfo_to_list(struct i40e_hw *hw,
5478 struct i40e_profile_segment *profile,
5479 u8 *profile_info_sec, u32 track_id)
5480{
5481 i40e_status status = 0;
5482 struct i40e_profile_section_header *sec = NULL;
5483 struct i40e_profile_info *pinfo;
5484 u32 offset = 0, info = 0;
5485
5486 sec = (struct i40e_profile_section_header *)profile_info_sec;
5487 sec->tbl_size = 1;
5488 sec->data_end = sizeof(struct i40e_profile_section_header) +
5489 sizeof(struct i40e_profile_info);
5490 sec->section.type = SECTION_TYPE_INFO;
5491 sec->section.offset = sizeof(struct i40e_profile_section_header);
5492 sec->section.size = sizeof(struct i40e_profile_info);
5493 pinfo = (struct i40e_profile_info *)(profile_info_sec +
5494 sec->section.offset);
5495 pinfo->track_id = track_id;
5496 pinfo->version = profile->version;
Jingjing Wu329e5982017-11-14 07:00:47 -05005497 pinfo->op = I40E_DDP_ADD_TRACKID;
5498 memcpy(pinfo->name, profile->name, I40E_DDP_NAME_SIZE);
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005499
Jingjing Wu329e5982017-11-14 07:00:47 -05005500 status = i40e_aq_write_ddp(hw, (void *)sec, sec->data_end,
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005501 track_id, &offset, &info, NULL);
Amritha Nambiar2f4b4112017-10-27 02:36:01 -07005502
5503 return status;
5504}
5505
5506/**
5507 * i40e_aq_add_cloud_filters
5508 * @hw: pointer to the hardware structure
5509 * @seid: VSI seid to add cloud filters from
5510 * @filters: Buffer which contains the filters to be added
5511 * @filter_count: number of filters contained in the buffer
5512 *
5513 * Set the cloud filters for a given VSI. The contents of the
5514 * i40e_aqc_cloud_filters_element_data are filled in by the caller
5515 * of the function.
5516 *
5517 **/
5518enum i40e_status_code
5519i40e_aq_add_cloud_filters(struct i40e_hw *hw, u16 seid,
5520 struct i40e_aqc_cloud_filters_element_data *filters,
5521 u8 filter_count)
5522{
5523 struct i40e_aq_desc desc;
5524 struct i40e_aqc_add_remove_cloud_filters *cmd =
5525 (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
5526 enum i40e_status_code status;
5527 u16 buff_len;
5528
5529 i40e_fill_default_direct_cmd_desc(&desc,
5530 i40e_aqc_opc_add_cloud_filters);
5531
5532 buff_len = filter_count * sizeof(*filters);
5533 desc.datalen = cpu_to_le16(buff_len);
5534 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
5535 cmd->num_filters = filter_count;
5536 cmd->seid = cpu_to_le16(seid);
5537
5538 status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
5539
5540 return status;
5541}
5542
5543/**
5544 * i40e_aq_add_cloud_filters_bb
5545 * @hw: pointer to the hardware structure
5546 * @seid: VSI seid to add cloud filters from
5547 * @filters: Buffer which contains the filters in big buffer to be added
5548 * @filter_count: number of filters contained in the buffer
5549 *
5550 * Set the big buffer cloud filters for a given VSI. The contents of the
5551 * i40e_aqc_cloud_filters_element_bb are filled in by the caller of the
5552 * function.
5553 *
5554 **/
5555i40e_status
5556i40e_aq_add_cloud_filters_bb(struct i40e_hw *hw, u16 seid,
5557 struct i40e_aqc_cloud_filters_element_bb *filters,
5558 u8 filter_count)
5559{
5560 struct i40e_aq_desc desc;
5561 struct i40e_aqc_add_remove_cloud_filters *cmd =
5562 (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
5563 i40e_status status;
5564 u16 buff_len;
5565 int i;
5566
5567 i40e_fill_default_direct_cmd_desc(&desc,
5568 i40e_aqc_opc_add_cloud_filters);
5569
5570 buff_len = filter_count * sizeof(*filters);
5571 desc.datalen = cpu_to_le16(buff_len);
5572 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
5573 cmd->num_filters = filter_count;
5574 cmd->seid = cpu_to_le16(seid);
5575 cmd->big_buffer_flag = I40E_AQC_ADD_CLOUD_CMD_BB;
5576
5577 for (i = 0; i < filter_count; i++) {
5578 u16 tnl_type;
5579 u32 ti;
5580
5581 tnl_type = (le16_to_cpu(filters[i].element.flags) &
5582 I40E_AQC_ADD_CLOUD_TNL_TYPE_MASK) >>
5583 I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT;
5584
5585 /* Due to hardware eccentricities, the VNI for Geneve is shifted
5586 * one more byte further than normally used for Tenant ID in
5587 * other tunnel types.
5588 */
5589 if (tnl_type == I40E_AQC_ADD_CLOUD_TNL_TYPE_GENEVE) {
5590 ti = le32_to_cpu(filters[i].element.tenant_id);
5591 filters[i].element.tenant_id = cpu_to_le32(ti << 8);
5592 }
5593 }
5594
5595 status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
5596
5597 return status;
5598}
5599
5600/**
5601 * i40e_aq_rem_cloud_filters
5602 * @hw: pointer to the hardware structure
5603 * @seid: VSI seid to remove cloud filters from
5604 * @filters: Buffer which contains the filters to be removed
5605 * @filter_count: number of filters contained in the buffer
5606 *
5607 * Remove the cloud filters for a given VSI. The contents of the
5608 * i40e_aqc_cloud_filters_element_data are filled in by the caller
5609 * of the function.
5610 *
5611 **/
5612enum i40e_status_code
5613i40e_aq_rem_cloud_filters(struct i40e_hw *hw, u16 seid,
5614 struct i40e_aqc_cloud_filters_element_data *filters,
5615 u8 filter_count)
5616{
5617 struct i40e_aq_desc desc;
5618 struct i40e_aqc_add_remove_cloud_filters *cmd =
5619 (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
5620 enum i40e_status_code status;
5621 u16 buff_len;
5622
5623 i40e_fill_default_direct_cmd_desc(&desc,
5624 i40e_aqc_opc_remove_cloud_filters);
5625
5626 buff_len = filter_count * sizeof(*filters);
5627 desc.datalen = cpu_to_le16(buff_len);
5628 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
5629 cmd->num_filters = filter_count;
5630 cmd->seid = cpu_to_le16(seid);
5631
5632 status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
5633
5634 return status;
5635}
5636
5637/**
5638 * i40e_aq_rem_cloud_filters_bb
5639 * @hw: pointer to the hardware structure
5640 * @seid: VSI seid to remove cloud filters from
5641 * @filters: Buffer which contains the filters in big buffer to be removed
5642 * @filter_count: number of filters contained in the buffer
5643 *
5644 * Remove the big buffer cloud filters for a given VSI. The contents of the
5645 * i40e_aqc_cloud_filters_element_bb are filled in by the caller of the
5646 * function.
5647 *
5648 **/
5649i40e_status
5650i40e_aq_rem_cloud_filters_bb(struct i40e_hw *hw, u16 seid,
5651 struct i40e_aqc_cloud_filters_element_bb *filters,
5652 u8 filter_count)
5653{
5654 struct i40e_aq_desc desc;
5655 struct i40e_aqc_add_remove_cloud_filters *cmd =
5656 (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
5657 i40e_status status;
5658 u16 buff_len;
5659 int i;
5660
5661 i40e_fill_default_direct_cmd_desc(&desc,
5662 i40e_aqc_opc_remove_cloud_filters);
5663
5664 buff_len = filter_count * sizeof(*filters);
5665 desc.datalen = cpu_to_le16(buff_len);
5666 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
5667 cmd->num_filters = filter_count;
5668 cmd->seid = cpu_to_le16(seid);
5669 cmd->big_buffer_flag = I40E_AQC_ADD_CLOUD_CMD_BB;
5670
5671 for (i = 0; i < filter_count; i++) {
5672 u16 tnl_type;
5673 u32 ti;
5674
5675 tnl_type = (le16_to_cpu(filters[i].element.flags) &
5676 I40E_AQC_ADD_CLOUD_TNL_TYPE_MASK) >>
5677 I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT;
5678
5679 /* Due to hardware eccentricities, the VNI for Geneve is shifted
5680 * one more byte further than normally used for Tenant ID in
5681 * other tunnel types.
5682 */
5683 if (tnl_type == I40E_AQC_ADD_CLOUD_TNL_TYPE_GENEVE) {
5684 ti = le32_to_cpu(filters[i].element.tenant_id);
5685 filters[i].element.tenant_id = cpu_to_le32(ti << 8);
5686 }
5687 }
5688
5689 status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
5690
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005691 return status;
5692}