blob: 34e86f55b2c064f6464e82c942b1e60d0dd2511c [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"
30#include "i40e_virtchnl.h"
31
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:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +000056 hw->mac.type = I40E_MAC_XL710;
57 break;
Anjali Singhai Jain35dae512015-12-22 14:25:03 -080058 case I40E_DEV_ID_KX_X722:
59 case I40E_DEV_ID_QSFP_X722:
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -040060 case I40E_DEV_ID_SFP_X722:
61 case I40E_DEV_ID_1G_BASE_T_X722:
62 case I40E_DEV_ID_10G_BASE_T_X722:
Catherine Sullivand6bf58c2016-03-18 12:18:08 -070063 case I40E_DEV_ID_SFP_I_X722:
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -040064 hw->mac.type = I40E_MAC_X722;
65 break;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +000066 default:
67 hw->mac.type = I40E_MAC_GENERIC;
68 break;
69 }
70 } else {
71 status = I40E_ERR_DEVICE_NOT_SUPPORTED;
72 }
73
74 hw_dbg(hw, "i40e_set_mac_type found mac: %d, returns: %d\n",
75 hw->mac.type, status);
76 return status;
77}
78
79/**
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040080 * i40e_aq_str - convert AQ err code to a string
81 * @hw: pointer to the HW structure
82 * @aq_err: the AQ error code to convert
83 **/
Jingjing Wu4e68adfe2015-09-28 14:12:31 -040084const char *i40e_aq_str(struct i40e_hw *hw, enum i40e_admin_queue_err aq_err)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040085{
86 switch (aq_err) {
87 case I40E_AQ_RC_OK:
88 return "OK";
89 case I40E_AQ_RC_EPERM:
90 return "I40E_AQ_RC_EPERM";
91 case I40E_AQ_RC_ENOENT:
92 return "I40E_AQ_RC_ENOENT";
93 case I40E_AQ_RC_ESRCH:
94 return "I40E_AQ_RC_ESRCH";
95 case I40E_AQ_RC_EINTR:
96 return "I40E_AQ_RC_EINTR";
97 case I40E_AQ_RC_EIO:
98 return "I40E_AQ_RC_EIO";
99 case I40E_AQ_RC_ENXIO:
100 return "I40E_AQ_RC_ENXIO";
101 case I40E_AQ_RC_E2BIG:
102 return "I40E_AQ_RC_E2BIG";
103 case I40E_AQ_RC_EAGAIN:
104 return "I40E_AQ_RC_EAGAIN";
105 case I40E_AQ_RC_ENOMEM:
106 return "I40E_AQ_RC_ENOMEM";
107 case I40E_AQ_RC_EACCES:
108 return "I40E_AQ_RC_EACCES";
109 case I40E_AQ_RC_EFAULT:
110 return "I40E_AQ_RC_EFAULT";
111 case I40E_AQ_RC_EBUSY:
112 return "I40E_AQ_RC_EBUSY";
113 case I40E_AQ_RC_EEXIST:
114 return "I40E_AQ_RC_EEXIST";
115 case I40E_AQ_RC_EINVAL:
116 return "I40E_AQ_RC_EINVAL";
117 case I40E_AQ_RC_ENOTTY:
118 return "I40E_AQ_RC_ENOTTY";
119 case I40E_AQ_RC_ENOSPC:
120 return "I40E_AQ_RC_ENOSPC";
121 case I40E_AQ_RC_ENOSYS:
122 return "I40E_AQ_RC_ENOSYS";
123 case I40E_AQ_RC_ERANGE:
124 return "I40E_AQ_RC_ERANGE";
125 case I40E_AQ_RC_EFLUSHED:
126 return "I40E_AQ_RC_EFLUSHED";
127 case I40E_AQ_RC_BAD_ADDR:
128 return "I40E_AQ_RC_BAD_ADDR";
129 case I40E_AQ_RC_EMODE:
130 return "I40E_AQ_RC_EMODE";
131 case I40E_AQ_RC_EFBIG:
132 return "I40E_AQ_RC_EFBIG";
133 }
134
135 snprintf(hw->err_str, sizeof(hw->err_str), "%d", aq_err);
136 return hw->err_str;
137}
138
139/**
140 * i40e_stat_str - convert status err code to a string
141 * @hw: pointer to the HW structure
142 * @stat_err: the status error code to convert
143 **/
Jingjing Wu4e68adfe2015-09-28 14:12:31 -0400144const char *i40e_stat_str(struct i40e_hw *hw, i40e_status stat_err)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400145{
146 switch (stat_err) {
147 case 0:
148 return "OK";
149 case I40E_ERR_NVM:
150 return "I40E_ERR_NVM";
151 case I40E_ERR_NVM_CHECKSUM:
152 return "I40E_ERR_NVM_CHECKSUM";
153 case I40E_ERR_PHY:
154 return "I40E_ERR_PHY";
155 case I40E_ERR_CONFIG:
156 return "I40E_ERR_CONFIG";
157 case I40E_ERR_PARAM:
158 return "I40E_ERR_PARAM";
159 case I40E_ERR_MAC_TYPE:
160 return "I40E_ERR_MAC_TYPE";
161 case I40E_ERR_UNKNOWN_PHY:
162 return "I40E_ERR_UNKNOWN_PHY";
163 case I40E_ERR_LINK_SETUP:
164 return "I40E_ERR_LINK_SETUP";
165 case I40E_ERR_ADAPTER_STOPPED:
166 return "I40E_ERR_ADAPTER_STOPPED";
167 case I40E_ERR_INVALID_MAC_ADDR:
168 return "I40E_ERR_INVALID_MAC_ADDR";
169 case I40E_ERR_DEVICE_NOT_SUPPORTED:
170 return "I40E_ERR_DEVICE_NOT_SUPPORTED";
171 case I40E_ERR_MASTER_REQUESTS_PENDING:
172 return "I40E_ERR_MASTER_REQUESTS_PENDING";
173 case I40E_ERR_INVALID_LINK_SETTINGS:
174 return "I40E_ERR_INVALID_LINK_SETTINGS";
175 case I40E_ERR_AUTONEG_NOT_COMPLETE:
176 return "I40E_ERR_AUTONEG_NOT_COMPLETE";
177 case I40E_ERR_RESET_FAILED:
178 return "I40E_ERR_RESET_FAILED";
179 case I40E_ERR_SWFW_SYNC:
180 return "I40E_ERR_SWFW_SYNC";
181 case I40E_ERR_NO_AVAILABLE_VSI:
182 return "I40E_ERR_NO_AVAILABLE_VSI";
183 case I40E_ERR_NO_MEMORY:
184 return "I40E_ERR_NO_MEMORY";
185 case I40E_ERR_BAD_PTR:
186 return "I40E_ERR_BAD_PTR";
187 case I40E_ERR_RING_FULL:
188 return "I40E_ERR_RING_FULL";
189 case I40E_ERR_INVALID_PD_ID:
190 return "I40E_ERR_INVALID_PD_ID";
191 case I40E_ERR_INVALID_QP_ID:
192 return "I40E_ERR_INVALID_QP_ID";
193 case I40E_ERR_INVALID_CQ_ID:
194 return "I40E_ERR_INVALID_CQ_ID";
195 case I40E_ERR_INVALID_CEQ_ID:
196 return "I40E_ERR_INVALID_CEQ_ID";
197 case I40E_ERR_INVALID_AEQ_ID:
198 return "I40E_ERR_INVALID_AEQ_ID";
199 case I40E_ERR_INVALID_SIZE:
200 return "I40E_ERR_INVALID_SIZE";
201 case I40E_ERR_INVALID_ARP_INDEX:
202 return "I40E_ERR_INVALID_ARP_INDEX";
203 case I40E_ERR_INVALID_FPM_FUNC_ID:
204 return "I40E_ERR_INVALID_FPM_FUNC_ID";
205 case I40E_ERR_QP_INVALID_MSG_SIZE:
206 return "I40E_ERR_QP_INVALID_MSG_SIZE";
207 case I40E_ERR_QP_TOOMANY_WRS_POSTED:
208 return "I40E_ERR_QP_TOOMANY_WRS_POSTED";
209 case I40E_ERR_INVALID_FRAG_COUNT:
210 return "I40E_ERR_INVALID_FRAG_COUNT";
211 case I40E_ERR_QUEUE_EMPTY:
212 return "I40E_ERR_QUEUE_EMPTY";
213 case I40E_ERR_INVALID_ALIGNMENT:
214 return "I40E_ERR_INVALID_ALIGNMENT";
215 case I40E_ERR_FLUSHED_QUEUE:
216 return "I40E_ERR_FLUSHED_QUEUE";
217 case I40E_ERR_INVALID_PUSH_PAGE_INDEX:
218 return "I40E_ERR_INVALID_PUSH_PAGE_INDEX";
219 case I40E_ERR_INVALID_IMM_DATA_SIZE:
220 return "I40E_ERR_INVALID_IMM_DATA_SIZE";
221 case I40E_ERR_TIMEOUT:
222 return "I40E_ERR_TIMEOUT";
223 case I40E_ERR_OPCODE_MISMATCH:
224 return "I40E_ERR_OPCODE_MISMATCH";
225 case I40E_ERR_CQP_COMPL_ERROR:
226 return "I40E_ERR_CQP_COMPL_ERROR";
227 case I40E_ERR_INVALID_VF_ID:
228 return "I40E_ERR_INVALID_VF_ID";
229 case I40E_ERR_INVALID_HMCFN_ID:
230 return "I40E_ERR_INVALID_HMCFN_ID";
231 case I40E_ERR_BACKING_PAGE_ERROR:
232 return "I40E_ERR_BACKING_PAGE_ERROR";
233 case I40E_ERR_NO_PBLCHUNKS_AVAILABLE:
234 return "I40E_ERR_NO_PBLCHUNKS_AVAILABLE";
235 case I40E_ERR_INVALID_PBLE_INDEX:
236 return "I40E_ERR_INVALID_PBLE_INDEX";
237 case I40E_ERR_INVALID_SD_INDEX:
238 return "I40E_ERR_INVALID_SD_INDEX";
239 case I40E_ERR_INVALID_PAGE_DESC_INDEX:
240 return "I40E_ERR_INVALID_PAGE_DESC_INDEX";
241 case I40E_ERR_INVALID_SD_TYPE:
242 return "I40E_ERR_INVALID_SD_TYPE";
243 case I40E_ERR_MEMCPY_FAILED:
244 return "I40E_ERR_MEMCPY_FAILED";
245 case I40E_ERR_INVALID_HMC_OBJ_INDEX:
246 return "I40E_ERR_INVALID_HMC_OBJ_INDEX";
247 case I40E_ERR_INVALID_HMC_OBJ_COUNT:
248 return "I40E_ERR_INVALID_HMC_OBJ_COUNT";
249 case I40E_ERR_INVALID_SRQ_ARM_LIMIT:
250 return "I40E_ERR_INVALID_SRQ_ARM_LIMIT";
251 case I40E_ERR_SRQ_ENABLED:
252 return "I40E_ERR_SRQ_ENABLED";
253 case I40E_ERR_ADMIN_QUEUE_ERROR:
254 return "I40E_ERR_ADMIN_QUEUE_ERROR";
255 case I40E_ERR_ADMIN_QUEUE_TIMEOUT:
256 return "I40E_ERR_ADMIN_QUEUE_TIMEOUT";
257 case I40E_ERR_BUF_TOO_SHORT:
258 return "I40E_ERR_BUF_TOO_SHORT";
259 case I40E_ERR_ADMIN_QUEUE_FULL:
260 return "I40E_ERR_ADMIN_QUEUE_FULL";
261 case I40E_ERR_ADMIN_QUEUE_NO_WORK:
262 return "I40E_ERR_ADMIN_QUEUE_NO_WORK";
263 case I40E_ERR_BAD_IWARP_CQE:
264 return "I40E_ERR_BAD_IWARP_CQE";
265 case I40E_ERR_NVM_BLANK_MODE:
266 return "I40E_ERR_NVM_BLANK_MODE";
267 case I40E_ERR_NOT_IMPLEMENTED:
268 return "I40E_ERR_NOT_IMPLEMENTED";
269 case I40E_ERR_PE_DOORBELL_NOT_ENABLED:
270 return "I40E_ERR_PE_DOORBELL_NOT_ENABLED";
271 case I40E_ERR_DIAG_TEST_FAILED:
272 return "I40E_ERR_DIAG_TEST_FAILED";
273 case I40E_ERR_NOT_READY:
274 return "I40E_ERR_NOT_READY";
275 case I40E_NOT_SUPPORTED:
276 return "I40E_NOT_SUPPORTED";
277 case I40E_ERR_FIRMWARE_API_VERSION:
278 return "I40E_ERR_FIRMWARE_API_VERSION";
279 }
280
281 snprintf(hw->err_str, sizeof(hw->err_str), "%d", stat_err);
282 return hw->err_str;
283}
284
285/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000286 * i40e_debug_aq
287 * @hw: debug mask related to admin queue
Jeff Kirsher98d44382013-12-21 05:44:42 +0000288 * @mask: debug mask
289 * @desc: pointer to admin queue descriptor
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000290 * @buffer: pointer to command buffer
Shannon Nelsonf905dd62014-07-10 07:58:20 +0000291 * @buf_len: max length of buffer
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000292 *
293 * Dumps debug log about adminq command with descriptor contents.
294 **/
295void i40e_debug_aq(struct i40e_hw *hw, enum i40e_debug_mask mask, void *desc,
Shannon Nelsonf905dd62014-07-10 07:58:20 +0000296 void *buffer, u16 buf_len)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000297{
298 struct i40e_aq_desc *aq_desc = (struct i40e_aq_desc *)desc;
Shannon Nelsonf905dd62014-07-10 07:58:20 +0000299 u16 len = le16_to_cpu(aq_desc->datalen);
Shannon Nelson37a29732015-02-27 09:15:19 +0000300 u8 *buf = (u8 *)buffer;
301 u16 i = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000302
303 if ((!(mask & hw->debug_mask)) || (desc == NULL))
304 return;
305
306 i40e_debug(hw, mask,
307 "AQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000308 le16_to_cpu(aq_desc->opcode),
309 le16_to_cpu(aq_desc->flags),
310 le16_to_cpu(aq_desc->datalen),
311 le16_to_cpu(aq_desc->retval));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000312 i40e_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000313 le32_to_cpu(aq_desc->cookie_high),
314 le32_to_cpu(aq_desc->cookie_low));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000315 i40e_debug(hw, mask, "\tparam (0,1) 0x%08X 0x%08X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000316 le32_to_cpu(aq_desc->params.internal.param0),
317 le32_to_cpu(aq_desc->params.internal.param1));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000318 i40e_debug(hw, mask, "\taddr (h,l) 0x%08X 0x%08X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000319 le32_to_cpu(aq_desc->params.external.addr_high),
320 le32_to_cpu(aq_desc->params.external.addr_low));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000321
322 if ((buffer != NULL) && (aq_desc->datalen != 0)) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000323 i40e_debug(hw, mask, "AQ CMD Buffer:\n");
Shannon Nelsonf905dd62014-07-10 07:58:20 +0000324 if (buf_len < len)
325 len = buf_len;
Shannon Nelson37a29732015-02-27 09:15:19 +0000326 /* write the full 16-byte chunks */
327 for (i = 0; i < (len - 16); i += 16)
Andy Shevchenkoa3524e92015-10-02 12:18:16 +0300328 i40e_debug(hw, mask, "\t0x%04X %16ph\n", i, buf + i);
Shannon Nelson37a29732015-02-27 09:15:19 +0000329 /* write whatever's left over without overrunning the buffer */
Andy Shevchenkoa3524e92015-10-02 12:18:16 +0300330 if (i < len)
331 i40e_debug(hw, mask, "\t0x%04X %*ph\n",
332 i, len - i, buf + i);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000333 }
334}
335
336/**
Anjali Singhai Jaine1860d82013-11-28 06:39:45 +0000337 * i40e_check_asq_alive
338 * @hw: pointer to the hw struct
339 *
340 * Returns true if Queue is enabled else false.
341 **/
342bool i40e_check_asq_alive(struct i40e_hw *hw)
343{
Kevin Scott8b833b42014-04-09 05:58:54 +0000344 if (hw->aq.asq.len)
345 return !!(rd32(hw, hw->aq.asq.len) &
346 I40E_PF_ATQLEN_ATQENABLE_MASK);
347 else
348 return false;
Anjali Singhai Jaine1860d82013-11-28 06:39:45 +0000349}
350
351/**
352 * i40e_aq_queue_shutdown
353 * @hw: pointer to the hw struct
354 * @unloading: is the driver unloading itself
355 *
356 * Tell the Firmware that we're shutting down the AdminQ and whether
357 * or not the driver is unloading as well.
358 **/
359i40e_status i40e_aq_queue_shutdown(struct i40e_hw *hw,
360 bool unloading)
361{
362 struct i40e_aq_desc desc;
363 struct i40e_aqc_queue_shutdown *cmd =
364 (struct i40e_aqc_queue_shutdown *)&desc.params.raw;
365 i40e_status status;
366
367 i40e_fill_default_direct_cmd_desc(&desc,
368 i40e_aqc_opc_queue_shutdown);
369
370 if (unloading)
371 cmd->driver_unloading = cpu_to_le32(I40E_AQ_DRIVER_UNLOADING);
372 status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
373
374 return status;
375}
376
Anjali Singhai Jaine50c8d62015-06-05 12:20:27 -0400377/**
378 * i40e_aq_get_set_rss_lut
379 * @hw: pointer to the hardware structure
380 * @vsi_id: vsi fw index
381 * @pf_lut: for PF table set true, for VSI table set false
382 * @lut: pointer to the lut buffer provided by the caller
383 * @lut_size: size of the lut buffer
384 * @set: set true to set the table, false to get the table
385 *
386 * Internal function to get or set RSS look up table
387 **/
388static i40e_status i40e_aq_get_set_rss_lut(struct i40e_hw *hw,
389 u16 vsi_id, bool pf_lut,
390 u8 *lut, u16 lut_size,
391 bool set)
392{
393 i40e_status status;
394 struct i40e_aq_desc desc;
395 struct i40e_aqc_get_set_rss_lut *cmd_resp =
396 (struct i40e_aqc_get_set_rss_lut *)&desc.params.raw;
397
398 if (set)
399 i40e_fill_default_direct_cmd_desc(&desc,
400 i40e_aqc_opc_set_rss_lut);
401 else
402 i40e_fill_default_direct_cmd_desc(&desc,
403 i40e_aqc_opc_get_rss_lut);
404
405 /* Indirect command */
406 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
407 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
408
409 cmd_resp->vsi_id =
410 cpu_to_le16((u16)((vsi_id <<
411 I40E_AQC_SET_RSS_LUT_VSI_ID_SHIFT) &
412 I40E_AQC_SET_RSS_LUT_VSI_ID_MASK));
413 cmd_resp->vsi_id |= cpu_to_le16((u16)I40E_AQC_SET_RSS_LUT_VSI_VALID);
414
415 if (pf_lut)
416 cmd_resp->flags |= cpu_to_le16((u16)
417 ((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_PF <<
418 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
419 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
420 else
421 cmd_resp->flags |= cpu_to_le16((u16)
422 ((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_VSI <<
423 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
424 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
425
Anjali Singhai Jaine50c8d62015-06-05 12:20:27 -0400426 status = i40e_asq_send_command(hw, &desc, lut, lut_size, NULL);
427
428 return status;
429}
430
431/**
432 * i40e_aq_get_rss_lut
433 * @hw: pointer to the hardware structure
434 * @vsi_id: vsi fw index
435 * @pf_lut: for PF table set true, for VSI table set false
436 * @lut: pointer to the lut buffer provided by the caller
437 * @lut_size: size of the lut buffer
438 *
439 * get the RSS lookup table, PF or VSI type
440 **/
441i40e_status i40e_aq_get_rss_lut(struct i40e_hw *hw, u16 vsi_id,
442 bool pf_lut, u8 *lut, u16 lut_size)
443{
444 return i40e_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size,
445 false);
446}
447
448/**
449 * i40e_aq_set_rss_lut
450 * @hw: pointer to the hardware structure
451 * @vsi_id: vsi fw index
452 * @pf_lut: for PF table set true, for VSI table set false
453 * @lut: pointer to the lut buffer provided by the caller
454 * @lut_size: size of the lut buffer
455 *
456 * set the RSS lookup table, PF or VSI type
457 **/
458i40e_status i40e_aq_set_rss_lut(struct i40e_hw *hw, u16 vsi_id,
459 bool pf_lut, u8 *lut, u16 lut_size)
460{
461 return i40e_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size, true);
462}
463
464/**
465 * i40e_aq_get_set_rss_key
466 * @hw: pointer to the hw struct
467 * @vsi_id: vsi fw index
468 * @key: pointer to key info struct
469 * @set: set true to set the key, false to get the key
470 *
471 * get the RSS key per VSI
472 **/
473static i40e_status i40e_aq_get_set_rss_key(struct i40e_hw *hw,
474 u16 vsi_id,
475 struct i40e_aqc_get_set_rss_key_data *key,
476 bool set)
477{
478 i40e_status status;
479 struct i40e_aq_desc desc;
480 struct i40e_aqc_get_set_rss_key *cmd_resp =
481 (struct i40e_aqc_get_set_rss_key *)&desc.params.raw;
482 u16 key_size = sizeof(struct i40e_aqc_get_set_rss_key_data);
483
484 if (set)
485 i40e_fill_default_direct_cmd_desc(&desc,
486 i40e_aqc_opc_set_rss_key);
487 else
488 i40e_fill_default_direct_cmd_desc(&desc,
489 i40e_aqc_opc_get_rss_key);
490
491 /* Indirect command */
492 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
493 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
494
495 cmd_resp->vsi_id =
496 cpu_to_le16((u16)((vsi_id <<
497 I40E_AQC_SET_RSS_KEY_VSI_ID_SHIFT) &
498 I40E_AQC_SET_RSS_KEY_VSI_ID_MASK));
499 cmd_resp->vsi_id |= cpu_to_le16((u16)I40E_AQC_SET_RSS_KEY_VSI_VALID);
Anjali Singhai Jaine50c8d62015-06-05 12:20:27 -0400500
501 status = i40e_asq_send_command(hw, &desc, key, key_size, NULL);
502
503 return status;
504}
505
506/**
507 * i40e_aq_get_rss_key
508 * @hw: pointer to the hw struct
509 * @vsi_id: vsi fw index
510 * @key: pointer to key info struct
511 *
512 **/
513i40e_status i40e_aq_get_rss_key(struct i40e_hw *hw,
514 u16 vsi_id,
515 struct i40e_aqc_get_set_rss_key_data *key)
516{
517 return i40e_aq_get_set_rss_key(hw, vsi_id, key, false);
518}
519
520/**
521 * i40e_aq_set_rss_key
522 * @hw: pointer to the hw struct
523 * @vsi_id: vsi fw index
524 * @key: pointer to key info struct
525 *
526 * set the RSS key per VSI
527 **/
528i40e_status i40e_aq_set_rss_key(struct i40e_hw *hw,
529 u16 vsi_id,
530 struct i40e_aqc_get_set_rss_key_data *key)
531{
532 return i40e_aq_get_set_rss_key(hw, vsi_id, key, true);
533}
534
Jesse Brandeburg206812b2014-02-12 01:45:33 +0000535/* The i40e_ptype_lookup table is used to convert from the 8-bit ptype in the
536 * hardware to a bit-field that can be used by SW to more easily determine the
537 * packet type.
538 *
539 * Macros are used to shorten the table lines and make this table human
540 * readable.
541 *
542 * We store the PTYPE in the top byte of the bit field - this is just so that
543 * we can check that the table doesn't have a row missing, as the index into
544 * the table should be the PTYPE.
545 *
546 * Typical work flow:
547 *
548 * IF NOT i40e_ptype_lookup[ptype].known
549 * THEN
550 * Packet is unknown
551 * ELSE IF i40e_ptype_lookup[ptype].outer_ip == I40E_RX_PTYPE_OUTER_IP
552 * Use the rest of the fields to look at the tunnels, inner protocols, etc
553 * ELSE
554 * Use the enum i40e_rx_l2_ptype to decode the packet type
555 * ENDIF
556 */
557
558/* macro to make the table lines short */
559#define I40E_PTT(PTYPE, OUTER_IP, OUTER_IP_VER, OUTER_FRAG, T, TE, TEF, I, PL)\
560 { PTYPE, \
561 1, \
562 I40E_RX_PTYPE_OUTER_##OUTER_IP, \
563 I40E_RX_PTYPE_OUTER_##OUTER_IP_VER, \
564 I40E_RX_PTYPE_##OUTER_FRAG, \
565 I40E_RX_PTYPE_TUNNEL_##T, \
566 I40E_RX_PTYPE_TUNNEL_END_##TE, \
567 I40E_RX_PTYPE_##TEF, \
568 I40E_RX_PTYPE_INNER_PROT_##I, \
569 I40E_RX_PTYPE_PAYLOAD_LAYER_##PL }
570
571#define I40E_PTT_UNUSED_ENTRY(PTYPE) \
572 { PTYPE, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
573
574/* shorter macros makes the table fit but are terse */
575#define I40E_RX_PTYPE_NOF I40E_RX_PTYPE_NOT_FRAG
576#define I40E_RX_PTYPE_FRG I40E_RX_PTYPE_FRAG
577#define I40E_RX_PTYPE_INNER_PROT_TS I40E_RX_PTYPE_INNER_PROT_TIMESYNC
578
579/* Lookup table mapping the HW PTYPE to the bit field for decoding */
580struct i40e_rx_ptype_decoded i40e_ptype_lookup[] = {
581 /* L2 Packet types */
582 I40E_PTT_UNUSED_ENTRY(0),
583 I40E_PTT(1, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
584 I40E_PTT(2, L2, NONE, NOF, NONE, NONE, NOF, TS, PAY2),
585 I40E_PTT(3, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
586 I40E_PTT_UNUSED_ENTRY(4),
587 I40E_PTT_UNUSED_ENTRY(5),
588 I40E_PTT(6, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
589 I40E_PTT(7, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
590 I40E_PTT_UNUSED_ENTRY(8),
591 I40E_PTT_UNUSED_ENTRY(9),
592 I40E_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
593 I40E_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
594 I40E_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
595 I40E_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
596 I40E_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
597 I40E_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
598 I40E_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
599 I40E_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
600 I40E_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
601 I40E_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
602 I40E_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
603 I40E_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
604
605 /* Non Tunneled IPv4 */
606 I40E_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
607 I40E_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
608 I40E_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP, PAY4),
609 I40E_PTT_UNUSED_ENTRY(25),
610 I40E_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP, PAY4),
611 I40E_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
612 I40E_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
613
614 /* IPv4 --> IPv4 */
615 I40E_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
616 I40E_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
617 I40E_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
618 I40E_PTT_UNUSED_ENTRY(32),
619 I40E_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
620 I40E_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
621 I40E_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
622
623 /* IPv4 --> IPv6 */
624 I40E_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
625 I40E_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
626 I40E_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
627 I40E_PTT_UNUSED_ENTRY(39),
628 I40E_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
629 I40E_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
630 I40E_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
631
632 /* IPv4 --> GRE/NAT */
633 I40E_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
634
635 /* IPv4 --> GRE/NAT --> IPv4 */
636 I40E_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
637 I40E_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
638 I40E_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
639 I40E_PTT_UNUSED_ENTRY(47),
640 I40E_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
641 I40E_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
642 I40E_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
643
644 /* IPv4 --> GRE/NAT --> IPv6 */
645 I40E_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
646 I40E_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
647 I40E_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
648 I40E_PTT_UNUSED_ENTRY(54),
649 I40E_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
650 I40E_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
651 I40E_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
652
653 /* IPv4 --> GRE/NAT --> MAC */
654 I40E_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
655
656 /* IPv4 --> GRE/NAT --> MAC --> IPv4 */
657 I40E_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
658 I40E_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
659 I40E_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
660 I40E_PTT_UNUSED_ENTRY(62),
661 I40E_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
662 I40E_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
663 I40E_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
664
665 /* IPv4 --> GRE/NAT -> MAC --> IPv6 */
666 I40E_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
667 I40E_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
668 I40E_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
669 I40E_PTT_UNUSED_ENTRY(69),
670 I40E_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
671 I40E_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
672 I40E_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
673
674 /* IPv4 --> GRE/NAT --> MAC/VLAN */
675 I40E_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
676
677 /* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
678 I40E_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
679 I40E_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
680 I40E_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
681 I40E_PTT_UNUSED_ENTRY(77),
682 I40E_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
683 I40E_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
684 I40E_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
685
686 /* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
687 I40E_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
688 I40E_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
689 I40E_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
690 I40E_PTT_UNUSED_ENTRY(84),
691 I40E_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
692 I40E_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
693 I40E_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
694
695 /* Non Tunneled IPv6 */
696 I40E_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
697 I40E_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
698 I40E_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP, PAY3),
699 I40E_PTT_UNUSED_ENTRY(91),
700 I40E_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP, PAY4),
701 I40E_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
702 I40E_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
703
704 /* IPv6 --> IPv4 */
705 I40E_PTT(95, IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
706 I40E_PTT(96, IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
707 I40E_PTT(97, IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
708 I40E_PTT_UNUSED_ENTRY(98),
709 I40E_PTT(99, IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
710 I40E_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
711 I40E_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
712
713 /* IPv6 --> IPv6 */
714 I40E_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
715 I40E_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
716 I40E_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
717 I40E_PTT_UNUSED_ENTRY(105),
718 I40E_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
719 I40E_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
720 I40E_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
721
722 /* IPv6 --> GRE/NAT */
723 I40E_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
724
725 /* IPv6 --> GRE/NAT -> IPv4 */
726 I40E_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
727 I40E_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
728 I40E_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
729 I40E_PTT_UNUSED_ENTRY(113),
730 I40E_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
731 I40E_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
732 I40E_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
733
734 /* IPv6 --> GRE/NAT -> IPv6 */
735 I40E_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
736 I40E_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
737 I40E_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
738 I40E_PTT_UNUSED_ENTRY(120),
739 I40E_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
740 I40E_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
741 I40E_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
742
743 /* IPv6 --> GRE/NAT -> MAC */
744 I40E_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
745
746 /* IPv6 --> GRE/NAT -> MAC -> IPv4 */
747 I40E_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
748 I40E_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
749 I40E_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
750 I40E_PTT_UNUSED_ENTRY(128),
751 I40E_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
752 I40E_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
753 I40E_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
754
755 /* IPv6 --> GRE/NAT -> MAC -> IPv6 */
756 I40E_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
757 I40E_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
758 I40E_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
759 I40E_PTT_UNUSED_ENTRY(135),
760 I40E_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
761 I40E_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
762 I40E_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
763
764 /* IPv6 --> GRE/NAT -> MAC/VLAN */
765 I40E_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
766
767 /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
768 I40E_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
769 I40E_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
770 I40E_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
771 I40E_PTT_UNUSED_ENTRY(143),
772 I40E_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
773 I40E_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
774 I40E_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
775
776 /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
777 I40E_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
778 I40E_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
779 I40E_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
780 I40E_PTT_UNUSED_ENTRY(150),
781 I40E_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
782 I40E_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
783 I40E_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
784
785 /* unused entries */
786 I40E_PTT_UNUSED_ENTRY(154),
787 I40E_PTT_UNUSED_ENTRY(155),
788 I40E_PTT_UNUSED_ENTRY(156),
789 I40E_PTT_UNUSED_ENTRY(157),
790 I40E_PTT_UNUSED_ENTRY(158),
791 I40E_PTT_UNUSED_ENTRY(159),
792
793 I40E_PTT_UNUSED_ENTRY(160),
794 I40E_PTT_UNUSED_ENTRY(161),
795 I40E_PTT_UNUSED_ENTRY(162),
796 I40E_PTT_UNUSED_ENTRY(163),
797 I40E_PTT_UNUSED_ENTRY(164),
798 I40E_PTT_UNUSED_ENTRY(165),
799 I40E_PTT_UNUSED_ENTRY(166),
800 I40E_PTT_UNUSED_ENTRY(167),
801 I40E_PTT_UNUSED_ENTRY(168),
802 I40E_PTT_UNUSED_ENTRY(169),
803
804 I40E_PTT_UNUSED_ENTRY(170),
805 I40E_PTT_UNUSED_ENTRY(171),
806 I40E_PTT_UNUSED_ENTRY(172),
807 I40E_PTT_UNUSED_ENTRY(173),
808 I40E_PTT_UNUSED_ENTRY(174),
809 I40E_PTT_UNUSED_ENTRY(175),
810 I40E_PTT_UNUSED_ENTRY(176),
811 I40E_PTT_UNUSED_ENTRY(177),
812 I40E_PTT_UNUSED_ENTRY(178),
813 I40E_PTT_UNUSED_ENTRY(179),
814
815 I40E_PTT_UNUSED_ENTRY(180),
816 I40E_PTT_UNUSED_ENTRY(181),
817 I40E_PTT_UNUSED_ENTRY(182),
818 I40E_PTT_UNUSED_ENTRY(183),
819 I40E_PTT_UNUSED_ENTRY(184),
820 I40E_PTT_UNUSED_ENTRY(185),
821 I40E_PTT_UNUSED_ENTRY(186),
822 I40E_PTT_UNUSED_ENTRY(187),
823 I40E_PTT_UNUSED_ENTRY(188),
824 I40E_PTT_UNUSED_ENTRY(189),
825
826 I40E_PTT_UNUSED_ENTRY(190),
827 I40E_PTT_UNUSED_ENTRY(191),
828 I40E_PTT_UNUSED_ENTRY(192),
829 I40E_PTT_UNUSED_ENTRY(193),
830 I40E_PTT_UNUSED_ENTRY(194),
831 I40E_PTT_UNUSED_ENTRY(195),
832 I40E_PTT_UNUSED_ENTRY(196),
833 I40E_PTT_UNUSED_ENTRY(197),
834 I40E_PTT_UNUSED_ENTRY(198),
835 I40E_PTT_UNUSED_ENTRY(199),
836
837 I40E_PTT_UNUSED_ENTRY(200),
838 I40E_PTT_UNUSED_ENTRY(201),
839 I40E_PTT_UNUSED_ENTRY(202),
840 I40E_PTT_UNUSED_ENTRY(203),
841 I40E_PTT_UNUSED_ENTRY(204),
842 I40E_PTT_UNUSED_ENTRY(205),
843 I40E_PTT_UNUSED_ENTRY(206),
844 I40E_PTT_UNUSED_ENTRY(207),
845 I40E_PTT_UNUSED_ENTRY(208),
846 I40E_PTT_UNUSED_ENTRY(209),
847
848 I40E_PTT_UNUSED_ENTRY(210),
849 I40E_PTT_UNUSED_ENTRY(211),
850 I40E_PTT_UNUSED_ENTRY(212),
851 I40E_PTT_UNUSED_ENTRY(213),
852 I40E_PTT_UNUSED_ENTRY(214),
853 I40E_PTT_UNUSED_ENTRY(215),
854 I40E_PTT_UNUSED_ENTRY(216),
855 I40E_PTT_UNUSED_ENTRY(217),
856 I40E_PTT_UNUSED_ENTRY(218),
857 I40E_PTT_UNUSED_ENTRY(219),
858
859 I40E_PTT_UNUSED_ENTRY(220),
860 I40E_PTT_UNUSED_ENTRY(221),
861 I40E_PTT_UNUSED_ENTRY(222),
862 I40E_PTT_UNUSED_ENTRY(223),
863 I40E_PTT_UNUSED_ENTRY(224),
864 I40E_PTT_UNUSED_ENTRY(225),
865 I40E_PTT_UNUSED_ENTRY(226),
866 I40E_PTT_UNUSED_ENTRY(227),
867 I40E_PTT_UNUSED_ENTRY(228),
868 I40E_PTT_UNUSED_ENTRY(229),
869
870 I40E_PTT_UNUSED_ENTRY(230),
871 I40E_PTT_UNUSED_ENTRY(231),
872 I40E_PTT_UNUSED_ENTRY(232),
873 I40E_PTT_UNUSED_ENTRY(233),
874 I40E_PTT_UNUSED_ENTRY(234),
875 I40E_PTT_UNUSED_ENTRY(235),
876 I40E_PTT_UNUSED_ENTRY(236),
877 I40E_PTT_UNUSED_ENTRY(237),
878 I40E_PTT_UNUSED_ENTRY(238),
879 I40E_PTT_UNUSED_ENTRY(239),
880
881 I40E_PTT_UNUSED_ENTRY(240),
882 I40E_PTT_UNUSED_ENTRY(241),
883 I40E_PTT_UNUSED_ENTRY(242),
884 I40E_PTT_UNUSED_ENTRY(243),
885 I40E_PTT_UNUSED_ENTRY(244),
886 I40E_PTT_UNUSED_ENTRY(245),
887 I40E_PTT_UNUSED_ENTRY(246),
888 I40E_PTT_UNUSED_ENTRY(247),
889 I40E_PTT_UNUSED_ENTRY(248),
890 I40E_PTT_UNUSED_ENTRY(249),
891
892 I40E_PTT_UNUSED_ENTRY(250),
893 I40E_PTT_UNUSED_ENTRY(251),
894 I40E_PTT_UNUSED_ENTRY(252),
895 I40E_PTT_UNUSED_ENTRY(253),
896 I40E_PTT_UNUSED_ENTRY(254),
897 I40E_PTT_UNUSED_ENTRY(255)
898};
899
Anjali Singhai Jaine1860d82013-11-28 06:39:45 +0000900/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000901 * i40e_init_shared_code - Initialize the shared code
902 * @hw: pointer to hardware structure
903 *
904 * This assigns the MAC type and PHY code and inits the NVM.
905 * Does not touch the hardware. This function must be called prior to any
906 * other function in the shared code. The i40e_hw structure should be
907 * memset to 0 prior to calling this function. The following fields in
908 * hw structure should be filled in prior to calling this function:
909 * hw_addr, back, device_id, vendor_id, subsystem_device_id,
910 * subsystem_vendor_id, and revision_id
911 **/
912i40e_status i40e_init_shared_code(struct i40e_hw *hw)
913{
914 i40e_status status = 0;
Shannon Nelson5fb11d72014-11-13 03:06:19 +0000915 u32 port, ari, func_rid;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000916
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000917 i40e_set_mac_type(hw);
918
919 switch (hw->mac.type) {
920 case I40E_MAC_XL710:
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -0400921 case I40E_MAC_X722:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000922 break;
923 default:
924 return I40E_ERR_DEVICE_NOT_SUPPORTED;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000925 }
926
Shannon Nelsonaf89d26c2013-12-11 08:17:14 +0000927 hw->phy.get_link_info = true;
928
Shannon Nelson5fb11d72014-11-13 03:06:19 +0000929 /* Determine port number and PF number*/
930 port = (rd32(hw, I40E_PFGEN_PORTNUM) & I40E_PFGEN_PORTNUM_PORT_NUM_MASK)
931 >> I40E_PFGEN_PORTNUM_PORT_NUM_SHIFT;
932 hw->port = (u8)port;
933 ari = (rd32(hw, I40E_GLPCI_CAPSUP) & I40E_GLPCI_CAPSUP_ARI_EN_MASK) >>
934 I40E_GLPCI_CAPSUP_ARI_EN_SHIFT;
935 func_rid = rd32(hw, I40E_PF_FUNC_RID);
936 if (ari)
937 hw->pf_id = (u8)(func_rid & 0xff);
Shannon Nelson5f9116a2013-12-11 08:17:13 +0000938 else
Shannon Nelson5fb11d72014-11-13 03:06:19 +0000939 hw->pf_id = (u8)(func_rid & 0x7);
Shannon Nelson5f9116a2013-12-11 08:17:13 +0000940
Anjali Singhai07f89be2015-09-24 15:26:32 -0700941 if (hw->mac.type == I40E_MAC_X722)
942 hw->flags |= I40E_HW_FLAG_AQ_SRCTL_ACCESS_ENABLE;
943
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000944 status = i40e_init_nvm(hw);
945 return status;
946}
947
948/**
949 * i40e_aq_mac_address_read - Retrieve the MAC addresses
950 * @hw: pointer to the hw struct
951 * @flags: a return indicator of what addresses were added to the addr store
952 * @addrs: the requestor's mac addr store
953 * @cmd_details: pointer to command details structure or NULL
954 **/
955static i40e_status i40e_aq_mac_address_read(struct i40e_hw *hw,
956 u16 *flags,
957 struct i40e_aqc_mac_address_read_data *addrs,
958 struct i40e_asq_cmd_details *cmd_details)
959{
960 struct i40e_aq_desc desc;
961 struct i40e_aqc_mac_address_read *cmd_data =
962 (struct i40e_aqc_mac_address_read *)&desc.params.raw;
963 i40e_status status;
964
965 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_mac_address_read);
966 desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF);
967
968 status = i40e_asq_send_command(hw, &desc, addrs,
969 sizeof(*addrs), cmd_details);
970 *flags = le16_to_cpu(cmd_data->command_flags);
971
972 return status;
973}
974
975/**
976 * i40e_aq_mac_address_write - Change the MAC addresses
977 * @hw: pointer to the hw struct
978 * @flags: indicates which MAC to be written
979 * @mac_addr: address to write
980 * @cmd_details: pointer to command details structure or NULL
981 **/
982i40e_status i40e_aq_mac_address_write(struct i40e_hw *hw,
983 u16 flags, u8 *mac_addr,
984 struct i40e_asq_cmd_details *cmd_details)
985{
986 struct i40e_aq_desc desc;
987 struct i40e_aqc_mac_address_write *cmd_data =
988 (struct i40e_aqc_mac_address_write *)&desc.params.raw;
989 i40e_status status;
990
991 i40e_fill_default_direct_cmd_desc(&desc,
992 i40e_aqc_opc_mac_address_write);
993 cmd_data->command_flags = cpu_to_le16(flags);
Kamil Krawczyk55c29c32013-12-18 13:45:52 +0000994 cmd_data->mac_sah = cpu_to_le16((u16)mac_addr[0] << 8 | mac_addr[1]);
995 cmd_data->mac_sal = cpu_to_le32(((u32)mac_addr[2] << 24) |
996 ((u32)mac_addr[3] << 16) |
997 ((u32)mac_addr[4] << 8) |
998 mac_addr[5]);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000999
1000 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1001
1002 return status;
1003}
1004
1005/**
1006 * i40e_get_mac_addr - get MAC address
1007 * @hw: pointer to the HW structure
1008 * @mac_addr: pointer to MAC address
1009 *
1010 * Reads the adapter's MAC address from register
1011 **/
1012i40e_status i40e_get_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
1013{
1014 struct i40e_aqc_mac_address_read_data addrs;
1015 i40e_status status;
1016 u16 flags = 0;
1017
1018 status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
1019
1020 if (flags & I40E_AQC_LAN_ADDR_VALID)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001021 ether_addr_copy(mac_addr, addrs.pf_lan_mac);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001022
1023 return status;
1024}
1025
1026/**
Neerav Parikh1f224ad2014-02-12 01:45:31 +00001027 * i40e_get_port_mac_addr - get Port MAC address
1028 * @hw: pointer to the HW structure
1029 * @mac_addr: pointer to Port MAC address
1030 *
1031 * Reads the adapter's Port MAC address
1032 **/
1033i40e_status i40e_get_port_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
1034{
1035 struct i40e_aqc_mac_address_read_data addrs;
1036 i40e_status status;
1037 u16 flags = 0;
1038
1039 status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
1040 if (status)
1041 return status;
1042
1043 if (flags & I40E_AQC_PORT_ADDR_VALID)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001044 ether_addr_copy(mac_addr, addrs.port_mac);
Neerav Parikh1f224ad2014-02-12 01:45:31 +00001045 else
1046 status = I40E_ERR_INVALID_MAC_ADDR;
1047
1048 return status;
1049}
1050
1051/**
Matt Jared351499ab2014-04-23 04:50:03 +00001052 * i40e_pre_tx_queue_cfg - pre tx queue configure
1053 * @hw: pointer to the HW structure
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00001054 * @queue: target PF queue index
Matt Jared351499ab2014-04-23 04:50:03 +00001055 * @enable: state change request
1056 *
1057 * Handles hw requirement to indicate intention to enable
1058 * or disable target queue.
1059 **/
1060void i40e_pre_tx_queue_cfg(struct i40e_hw *hw, u32 queue, bool enable)
1061{
Shannon Nelsondfb699f2014-05-22 06:32:28 +00001062 u32 abs_queue_idx = hw->func_caps.base_queue + queue;
Matt Jared351499ab2014-04-23 04:50:03 +00001063 u32 reg_block = 0;
Shannon Nelsondfb699f2014-05-22 06:32:28 +00001064 u32 reg_val;
Matt Jared351499ab2014-04-23 04:50:03 +00001065
Christopher Pau24a768c2014-06-04 20:41:59 +00001066 if (abs_queue_idx >= 128) {
Matt Jared351499ab2014-04-23 04:50:03 +00001067 reg_block = abs_queue_idx / 128;
Christopher Pau24a768c2014-06-04 20:41:59 +00001068 abs_queue_idx %= 128;
1069 }
Matt Jared351499ab2014-04-23 04:50:03 +00001070
1071 reg_val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
1072 reg_val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
1073 reg_val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
1074
1075 if (enable)
1076 reg_val |= I40E_GLLAN_TXPRE_QDIS_CLEAR_QDIS_MASK;
1077 else
1078 reg_val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
1079
1080 wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), reg_val);
1081}
Vasu Dev38e00432014-08-01 13:27:03 -07001082#ifdef I40E_FCOE
1083
1084/**
1085 * i40e_get_san_mac_addr - get SAN MAC address
1086 * @hw: pointer to the HW structure
1087 * @mac_addr: pointer to SAN MAC address
1088 *
1089 * Reads the adapter's SAN MAC address from NVM
1090 **/
1091i40e_status i40e_get_san_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
1092{
1093 struct i40e_aqc_mac_address_read_data addrs;
1094 i40e_status status;
1095 u16 flags = 0;
1096
1097 status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
1098 if (status)
1099 return status;
1100
1101 if (flags & I40E_AQC_SAN_ADDR_VALID)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001102 ether_addr_copy(mac_addr, addrs.pf_san_mac);
Vasu Dev38e00432014-08-01 13:27:03 -07001103 else
1104 status = I40E_ERR_INVALID_MAC_ADDR;
1105
1106 return status;
1107}
1108#endif
Matt Jared351499ab2014-04-23 04:50:03 +00001109
1110/**
Kamil Krawczyk18f680c2014-12-11 07:06:31 +00001111 * i40e_read_pba_string - Reads part number string from EEPROM
1112 * @hw: pointer to hardware structure
1113 * @pba_num: stores the part number string from the EEPROM
1114 * @pba_num_size: part number string buffer length
1115 *
1116 * Reads the part number string from the EEPROM.
1117 **/
1118i40e_status i40e_read_pba_string(struct i40e_hw *hw, u8 *pba_num,
1119 u32 pba_num_size)
1120{
1121 i40e_status status = 0;
1122 u16 pba_word = 0;
1123 u16 pba_size = 0;
1124 u16 pba_ptr = 0;
1125 u16 i = 0;
1126
1127 status = i40e_read_nvm_word(hw, I40E_SR_PBA_FLAGS, &pba_word);
1128 if (status || (pba_word != 0xFAFA)) {
1129 hw_dbg(hw, "Failed to read PBA flags or flag is invalid.\n");
1130 return status;
1131 }
1132
1133 status = i40e_read_nvm_word(hw, I40E_SR_PBA_BLOCK_PTR, &pba_ptr);
1134 if (status) {
1135 hw_dbg(hw, "Failed to read PBA Block pointer.\n");
1136 return status;
1137 }
1138
1139 status = i40e_read_nvm_word(hw, pba_ptr, &pba_size);
1140 if (status) {
1141 hw_dbg(hw, "Failed to read PBA Block size.\n");
1142 return status;
1143 }
1144
1145 /* Subtract one to get PBA word count (PBA Size word is included in
1146 * total size)
1147 */
1148 pba_size--;
1149 if (pba_num_size < (((u32)pba_size * 2) + 1)) {
1150 hw_dbg(hw, "Buffer to small for PBA data.\n");
1151 return I40E_ERR_PARAM;
1152 }
1153
1154 for (i = 0; i < pba_size; i++) {
1155 status = i40e_read_nvm_word(hw, (pba_ptr + 1) + i, &pba_word);
1156 if (status) {
1157 hw_dbg(hw, "Failed to read PBA Block word %d.\n", i);
1158 return status;
1159 }
1160
1161 pba_num[(i * 2)] = (pba_word >> 8) & 0xFF;
1162 pba_num[(i * 2) + 1] = pba_word & 0xFF;
1163 }
1164 pba_num[(pba_size * 2)] = '\0';
1165
1166 return status;
1167}
1168
1169/**
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001170 * i40e_get_media_type - Gets media type
1171 * @hw: pointer to the hardware structure
1172 **/
1173static enum i40e_media_type i40e_get_media_type(struct i40e_hw *hw)
1174{
1175 enum i40e_media_type media;
1176
1177 switch (hw->phy.link_info.phy_type) {
1178 case I40E_PHY_TYPE_10GBASE_SR:
1179 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +00001180 case I40E_PHY_TYPE_1000BASE_SX:
1181 case I40E_PHY_TYPE_1000BASE_LX:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001182 case I40E_PHY_TYPE_40GBASE_SR4:
1183 case I40E_PHY_TYPE_40GBASE_LR4:
1184 media = I40E_MEDIA_TYPE_FIBER;
1185 break;
1186 case I40E_PHY_TYPE_100BASE_TX:
1187 case I40E_PHY_TYPE_1000BASE_T:
1188 case I40E_PHY_TYPE_10GBASE_T:
1189 media = I40E_MEDIA_TYPE_BASET;
1190 break;
1191 case I40E_PHY_TYPE_10GBASE_CR1_CU:
1192 case I40E_PHY_TYPE_40GBASE_CR4_CU:
1193 case I40E_PHY_TYPE_10GBASE_CR1:
1194 case I40E_PHY_TYPE_40GBASE_CR4:
1195 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +00001196 case I40E_PHY_TYPE_40GBASE_AOC:
1197 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001198 media = I40E_MEDIA_TYPE_DA;
1199 break;
1200 case I40E_PHY_TYPE_1000BASE_KX:
1201 case I40E_PHY_TYPE_10GBASE_KX4:
1202 case I40E_PHY_TYPE_10GBASE_KR:
1203 case I40E_PHY_TYPE_40GBASE_KR4:
Jesse Brandeburgae24b402015-03-27 00:12:09 -07001204 case I40E_PHY_TYPE_20GBASE_KR2:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001205 media = I40E_MEDIA_TYPE_BACKPLANE;
1206 break;
1207 case I40E_PHY_TYPE_SGMII:
1208 case I40E_PHY_TYPE_XAUI:
1209 case I40E_PHY_TYPE_XFI:
1210 case I40E_PHY_TYPE_XLAUI:
1211 case I40E_PHY_TYPE_XLPPI:
1212 default:
1213 media = I40E_MEDIA_TYPE_UNKNOWN;
1214 break;
1215 }
1216
1217 return media;
1218}
1219
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001220#define I40E_PF_RESET_WAIT_COUNT_A0 200
Akeem G Abodunrin8af580d2015-03-27 00:12:10 -07001221#define I40E_PF_RESET_WAIT_COUNT 200
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001222/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001223 * i40e_pf_reset - Reset the PF
1224 * @hw: pointer to the hardware structure
1225 *
1226 * Assuming someone else has triggered a global reset,
1227 * assure the global reset is complete and then reset the PF
1228 **/
1229i40e_status i40e_pf_reset(struct i40e_hw *hw)
1230{
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001231 u32 cnt = 0;
Shannon Nelson42794bd2013-12-11 08:17:10 +00001232 u32 cnt1 = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001233 u32 reg = 0;
1234 u32 grst_del;
1235
1236 /* Poll for Global Reset steady state in case of recent GRST.
1237 * The grst delay value is in 100ms units, and we'll wait a
1238 * couple counts longer to be sure we don't just miss the end.
1239 */
Shannon Nelsonde78fc52015-02-21 06:41:47 +00001240 grst_del = (rd32(hw, I40E_GLGEN_RSTCTL) &
1241 I40E_GLGEN_RSTCTL_GRSTDEL_MASK) >>
1242 I40E_GLGEN_RSTCTL_GRSTDEL_SHIFT;
Kevin Scott4d7cec02016-02-17 16:12:13 -08001243
1244 /* It can take upto 15 secs for GRST steady state.
1245 * Bump it to 16 secs max to be safe.
1246 */
1247 grst_del = grst_del * 20;
1248
1249 for (cnt = 0; cnt < grst_del; cnt++) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001250 reg = rd32(hw, I40E_GLGEN_RSTAT);
1251 if (!(reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK))
1252 break;
1253 msleep(100);
1254 }
1255 if (reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
1256 hw_dbg(hw, "Global reset polling failed to complete.\n");
1257 return I40E_ERR_RESET_FAILED;
1258 }
1259
Shannon Nelson42794bd2013-12-11 08:17:10 +00001260 /* Now Wait for the FW to be ready */
1261 for (cnt1 = 0; cnt1 < I40E_PF_RESET_WAIT_COUNT; cnt1++) {
1262 reg = rd32(hw, I40E_GLNVM_ULD);
1263 reg &= (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
1264 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK);
1265 if (reg == (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
1266 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK)) {
1267 hw_dbg(hw, "Core and Global modules ready %d\n", cnt1);
1268 break;
1269 }
1270 usleep_range(10000, 20000);
1271 }
1272 if (!(reg & (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
1273 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK))) {
1274 hw_dbg(hw, "wait for FW Reset complete timedout\n");
1275 hw_dbg(hw, "I40E_GLNVM_ULD = 0x%x\n", reg);
1276 return I40E_ERR_RESET_FAILED;
1277 }
1278
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001279 /* If there was a Global Reset in progress when we got here,
1280 * we don't need to do the PF Reset
1281 */
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001282 if (!cnt) {
1283 if (hw->revision_id == 0)
1284 cnt = I40E_PF_RESET_WAIT_COUNT_A0;
1285 else
1286 cnt = I40E_PF_RESET_WAIT_COUNT;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001287 reg = rd32(hw, I40E_PFGEN_CTRL);
1288 wr32(hw, I40E_PFGEN_CTRL,
1289 (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001290 for (; cnt; cnt--) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001291 reg = rd32(hw, I40E_PFGEN_CTRL);
1292 if (!(reg & I40E_PFGEN_CTRL_PFSWR_MASK))
1293 break;
1294 usleep_range(1000, 2000);
1295 }
1296 if (reg & I40E_PFGEN_CTRL_PFSWR_MASK) {
1297 hw_dbg(hw, "PF reset polling failed to complete.\n");
1298 return I40E_ERR_RESET_FAILED;
1299 }
1300 }
1301
1302 i40e_clear_pxe_mode(hw);
Shannon Nelson922680b2013-12-18 05:29:17 +00001303
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001304 return 0;
1305}
1306
1307/**
Shannon Nelson838d41d2014-06-04 20:41:27 +00001308 * i40e_clear_hw - clear out any left over hw state
1309 * @hw: pointer to the hw struct
1310 *
1311 * Clear queues and interrupts, typically called at init time,
1312 * but after the capabilities have been found so we know how many
1313 * queues and msix vectors have been allocated.
1314 **/
1315void i40e_clear_hw(struct i40e_hw *hw)
1316{
1317 u32 num_queues, base_queue;
1318 u32 num_pf_int;
1319 u32 num_vf_int;
1320 u32 num_vfs;
1321 u32 i, j;
1322 u32 val;
1323 u32 eol = 0x7ff;
1324
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00001325 /* get number of interrupts, queues, and VFs */
Shannon Nelson838d41d2014-06-04 20:41:27 +00001326 val = rd32(hw, I40E_GLPCI_CNF2);
1327 num_pf_int = (val & I40E_GLPCI_CNF2_MSI_X_PF_N_MASK) >>
1328 I40E_GLPCI_CNF2_MSI_X_PF_N_SHIFT;
1329 num_vf_int = (val & I40E_GLPCI_CNF2_MSI_X_VF_N_MASK) >>
1330 I40E_GLPCI_CNF2_MSI_X_VF_N_SHIFT;
1331
Shannon Nelson272cdaf22016-02-17 16:12:21 -08001332 val = rd32(hw, I40E_PFLAN_QALLOC);
Shannon Nelson838d41d2014-06-04 20:41:27 +00001333 base_queue = (val & I40E_PFLAN_QALLOC_FIRSTQ_MASK) >>
1334 I40E_PFLAN_QALLOC_FIRSTQ_SHIFT;
1335 j = (val & I40E_PFLAN_QALLOC_LASTQ_MASK) >>
1336 I40E_PFLAN_QALLOC_LASTQ_SHIFT;
1337 if (val & I40E_PFLAN_QALLOC_VALID_MASK)
1338 num_queues = (j - base_queue) + 1;
1339 else
1340 num_queues = 0;
1341
1342 val = rd32(hw, I40E_PF_VT_PFALLOC);
1343 i = (val & I40E_PF_VT_PFALLOC_FIRSTVF_MASK) >>
1344 I40E_PF_VT_PFALLOC_FIRSTVF_SHIFT;
1345 j = (val & I40E_PF_VT_PFALLOC_LASTVF_MASK) >>
1346 I40E_PF_VT_PFALLOC_LASTVF_SHIFT;
1347 if (val & I40E_PF_VT_PFALLOC_VALID_MASK)
1348 num_vfs = (j - i) + 1;
1349 else
1350 num_vfs = 0;
1351
1352 /* stop all the interrupts */
1353 wr32(hw, I40E_PFINT_ICR0_ENA, 0);
1354 val = 0x3 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT;
1355 for (i = 0; i < num_pf_int - 2; i++)
1356 wr32(hw, I40E_PFINT_DYN_CTLN(i), val);
1357
1358 /* Set the FIRSTQ_INDX field to 0x7FF in PFINT_LNKLSTx */
1359 val = eol << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
1360 wr32(hw, I40E_PFINT_LNKLST0, val);
1361 for (i = 0; i < num_pf_int - 2; i++)
1362 wr32(hw, I40E_PFINT_LNKLSTN(i), val);
1363 val = eol << I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT;
1364 for (i = 0; i < num_vfs; i++)
1365 wr32(hw, I40E_VPINT_LNKLST0(i), val);
1366 for (i = 0; i < num_vf_int - 2; i++)
1367 wr32(hw, I40E_VPINT_LNKLSTN(i), val);
1368
1369 /* warn the HW of the coming Tx disables */
1370 for (i = 0; i < num_queues; i++) {
1371 u32 abs_queue_idx = base_queue + i;
1372 u32 reg_block = 0;
1373
1374 if (abs_queue_idx >= 128) {
1375 reg_block = abs_queue_idx / 128;
1376 abs_queue_idx %= 128;
1377 }
1378
1379 val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
1380 val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
1381 val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
1382 val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
1383
1384 wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), val);
1385 }
1386 udelay(400);
1387
1388 /* stop all the queues */
1389 for (i = 0; i < num_queues; i++) {
1390 wr32(hw, I40E_QINT_TQCTL(i), 0);
1391 wr32(hw, I40E_QTX_ENA(i), 0);
1392 wr32(hw, I40E_QINT_RQCTL(i), 0);
1393 wr32(hw, I40E_QRX_ENA(i), 0);
1394 }
1395
1396 /* short wait for all queue disables to settle */
1397 udelay(50);
1398}
1399
1400/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001401 * i40e_clear_pxe_mode - clear pxe operations mode
1402 * @hw: pointer to the hw struct
1403 *
1404 * Make sure all PXE mode settings are cleared, including things
1405 * like descriptor fetch/write-back mode.
1406 **/
1407void i40e_clear_pxe_mode(struct i40e_hw *hw)
1408{
1409 u32 reg;
1410
Shannon Nelsonc9b9b0a2014-04-09 05:59:05 +00001411 if (i40e_check_asq_alive(hw))
1412 i40e_aq_clear_pxe_mode(hw, NULL);
1413
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001414 /* Clear single descriptor fetch/write-back mode */
1415 reg = rd32(hw, I40E_GLLAN_RCTL_0);
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001416
1417 if (hw->revision_id == 0) {
1418 /* As a work around clear PXE_MODE instead of setting it */
1419 wr32(hw, I40E_GLLAN_RCTL_0, (reg & (~I40E_GLLAN_RCTL_0_PXE_MODE_MASK)));
1420 } else {
1421 wr32(hw, I40E_GLLAN_RCTL_0, (reg | I40E_GLLAN_RCTL_0_PXE_MODE_MASK));
1422 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001423}
1424
1425/**
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001426 * i40e_led_is_mine - helper to find matching led
1427 * @hw: pointer to the hw struct
1428 * @idx: index into GPIO registers
1429 *
1430 * returns: 0 if no match, otherwise the value of the GPIO_CTL register
1431 */
1432static u32 i40e_led_is_mine(struct i40e_hw *hw, int idx)
1433{
1434 u32 gpio_val = 0;
1435 u32 port;
1436
1437 if (!hw->func_caps.led[idx])
1438 return 0;
1439
1440 gpio_val = rd32(hw, I40E_GLGEN_GPIO_CTL(idx));
1441 port = (gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_MASK) >>
1442 I40E_GLGEN_GPIO_CTL_PRT_NUM_SHIFT;
1443
1444 /* if PRT_NUM_NA is 1 then this LED is not port specific, OR
1445 * if it is not our port then ignore
1446 */
1447 if ((gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_NA_MASK) ||
1448 (port != hw->port))
1449 return 0;
1450
1451 return gpio_val;
1452}
1453
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001454#define I40E_COMBINED_ACTIVITY 0xA
1455#define I40E_FILTER_ACTIVITY 0xE
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001456#define I40E_LINK_ACTIVITY 0xC
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001457#define I40E_MAC_ACTIVITY 0xD
1458#define I40E_LED0 22
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001459
1460/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001461 * i40e_led_get - return current on/off mode
1462 * @hw: pointer to the hw struct
1463 *
1464 * The value returned is the 'mode' field as defined in the
1465 * GPIO register definitions: 0x0 = off, 0xf = on, and other
1466 * values are variations of possible behaviors relating to
1467 * blink, link, and wire.
1468 **/
1469u32 i40e_led_get(struct i40e_hw *hw)
1470{
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001471 u32 current_mode = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001472 u32 mode = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001473 int i;
1474
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001475 /* as per the documentation GPIO 22-29 are the LED
1476 * GPIO pins named LED0..LED7
1477 */
1478 for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
1479 u32 gpio_val = i40e_led_is_mine(hw, i);
1480
1481 if (!gpio_val)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001482 continue;
1483
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001484 /* ignore gpio LED src mode entries related to the activity
1485 * LEDs
1486 */
1487 current_mode = ((gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK)
1488 >> I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT);
1489 switch (current_mode) {
1490 case I40E_COMBINED_ACTIVITY:
1491 case I40E_FILTER_ACTIVITY:
1492 case I40E_MAC_ACTIVITY:
1493 continue;
1494 default:
1495 break;
1496 }
1497
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001498 mode = (gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK) >>
1499 I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001500 break;
1501 }
1502
1503 return mode;
1504}
1505
1506/**
1507 * i40e_led_set - set new on/off mode
1508 * @hw: pointer to the hw struct
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001509 * @mode: 0=off, 0xf=on (else see manual for mode details)
1510 * @blink: true if the LED should blink when on, false if steady
1511 *
1512 * if this function is used to turn on the blink it should
1513 * be used to disable the blink when restoring the original state.
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001514 **/
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001515void i40e_led_set(struct i40e_hw *hw, u32 mode, bool blink)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001516{
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001517 u32 current_mode = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001518 int i;
1519
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001520 if (mode & 0xfffffff0)
1521 hw_dbg(hw, "invalid mode passed in %X\n", mode);
1522
1523 /* as per the documentation GPIO 22-29 are the LED
1524 * GPIO pins named LED0..LED7
1525 */
1526 for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
1527 u32 gpio_val = i40e_led_is_mine(hw, i);
1528
1529 if (!gpio_val)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001530 continue;
1531
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001532 /* ignore gpio LED src mode entries related to the activity
1533 * LEDs
1534 */
1535 current_mode = ((gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK)
1536 >> I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT);
1537 switch (current_mode) {
1538 case I40E_COMBINED_ACTIVITY:
1539 case I40E_FILTER_ACTIVITY:
1540 case I40E_MAC_ACTIVITY:
1541 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
1551 if (mode == I40E_LINK_ACTIVITY)
1552 blink = false;
1553
Matt Jared9be00d62015-01-24 09:58:28 +00001554 if (blink)
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001555 gpio_val |= BIT(I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
Matt Jared9be00d62015-01-24 09:58:28 +00001556 else
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001557 gpio_val &= ~BIT(I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001558
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001559 wr32(hw, I40E_GLGEN_GPIO_CTL(i), gpio_val);
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001560 break;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001561 }
1562}
1563
1564/* Admin command wrappers */
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001565
1566/**
Catherine Sullivan8109e122014-06-04 08:45:24 +00001567 * i40e_aq_get_phy_capabilities
1568 * @hw: pointer to the hw struct
1569 * @abilities: structure for PHY capabilities to be filled
1570 * @qualified_modules: report Qualified Modules
1571 * @report_init: report init capabilities (active are default)
1572 * @cmd_details: pointer to command details structure or NULL
1573 *
1574 * Returns the various PHY abilities supported on the Port.
1575 **/
1576i40e_status i40e_aq_get_phy_capabilities(struct i40e_hw *hw,
1577 bool qualified_modules, bool report_init,
1578 struct i40e_aq_get_phy_abilities_resp *abilities,
1579 struct i40e_asq_cmd_details *cmd_details)
1580{
1581 struct i40e_aq_desc desc;
1582 i40e_status status;
1583 u16 abilities_size = sizeof(struct i40e_aq_get_phy_abilities_resp);
1584
1585 if (!abilities)
1586 return I40E_ERR_PARAM;
1587
1588 i40e_fill_default_direct_cmd_desc(&desc,
1589 i40e_aqc_opc_get_phy_abilities);
1590
1591 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
1592 if (abilities_size > I40E_AQ_LARGE_BUF)
1593 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
1594
1595 if (qualified_modules)
1596 desc.params.external.param0 |=
1597 cpu_to_le32(I40E_AQ_PHY_REPORT_QUALIFIED_MODULES);
1598
1599 if (report_init)
1600 desc.params.external.param0 |=
1601 cpu_to_le32(I40E_AQ_PHY_REPORT_INITIAL_VALUES);
1602
1603 status = i40e_asq_send_command(hw, &desc, abilities, abilities_size,
1604 cmd_details);
1605
1606 if (hw->aq.asq_last_status == I40E_AQ_RC_EIO)
1607 status = I40E_ERR_UNKNOWN_PHY;
1608
Kevin Scott3ac67d72015-09-03 17:18:58 -04001609 if (report_init)
1610 hw->phy.phy_types = le32_to_cpu(abilities->phy_type);
1611
Catherine Sullivan8109e122014-06-04 08:45:24 +00001612 return status;
1613}
1614
1615/**
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001616 * i40e_aq_set_phy_config
1617 * @hw: pointer to the hw struct
1618 * @config: structure with PHY configuration to be set
1619 * @cmd_details: pointer to command details structure or NULL
1620 *
1621 * Set the various PHY configuration parameters
1622 * supported on the Port.One or more of the Set PHY config parameters may be
1623 * ignored in an MFP mode as the PF may not have the privilege to set some
1624 * of the PHY Config parameters. This status will be indicated by the
1625 * command response.
1626 **/
1627enum i40e_status_code i40e_aq_set_phy_config(struct i40e_hw *hw,
1628 struct i40e_aq_set_phy_config *config,
1629 struct i40e_asq_cmd_details *cmd_details)
1630{
1631 struct i40e_aq_desc desc;
1632 struct i40e_aq_set_phy_config *cmd =
1633 (struct i40e_aq_set_phy_config *)&desc.params.raw;
1634 enum i40e_status_code status;
1635
1636 if (!config)
1637 return I40E_ERR_PARAM;
1638
1639 i40e_fill_default_direct_cmd_desc(&desc,
1640 i40e_aqc_opc_set_phy_config);
1641
1642 *cmd = *config;
1643
1644 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1645
1646 return status;
1647}
1648
1649/**
1650 * i40e_set_fc
1651 * @hw: pointer to the hw struct
1652 *
1653 * Set the requested flow control mode using set_phy_config.
1654 **/
1655enum i40e_status_code i40e_set_fc(struct i40e_hw *hw, u8 *aq_failures,
1656 bool atomic_restart)
1657{
1658 enum i40e_fc_mode fc_mode = hw->fc.requested_mode;
1659 struct i40e_aq_get_phy_abilities_resp abilities;
1660 struct i40e_aq_set_phy_config config;
1661 enum i40e_status_code status;
1662 u8 pause_mask = 0x0;
1663
1664 *aq_failures = 0x0;
1665
1666 switch (fc_mode) {
1667 case I40E_FC_FULL:
1668 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
1669 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
1670 break;
1671 case I40E_FC_RX_PAUSE:
1672 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
1673 break;
1674 case I40E_FC_TX_PAUSE:
1675 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
1676 break;
1677 default:
1678 break;
1679 }
1680
1681 /* Get the current phy config */
1682 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
1683 NULL);
1684 if (status) {
1685 *aq_failures |= I40E_SET_FC_AQ_FAIL_GET;
1686 return status;
1687 }
1688
1689 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
1690 /* clear the old pause settings */
1691 config.abilities = abilities.abilities & ~(I40E_AQ_PHY_FLAG_PAUSE_TX) &
1692 ~(I40E_AQ_PHY_FLAG_PAUSE_RX);
1693 /* set the new abilities */
1694 config.abilities |= pause_mask;
1695 /* If the abilities have changed, then set the new config */
1696 if (config.abilities != abilities.abilities) {
1697 /* Auto restart link so settings take effect */
1698 if (atomic_restart)
1699 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
1700 /* Copy over all the old settings */
1701 config.phy_type = abilities.phy_type;
1702 config.link_speed = abilities.link_speed;
1703 config.eee_capability = abilities.eee_capability;
1704 config.eeer = abilities.eeer_val;
1705 config.low_power_ctrl = abilities.d3_lpan;
1706 status = i40e_aq_set_phy_config(hw, &config, NULL);
1707
1708 if (status)
1709 *aq_failures |= I40E_SET_FC_AQ_FAIL_SET;
1710 }
1711 /* Update the link info */
Catherine Sullivan0a862b42015-08-31 19:54:53 -04001712 status = i40e_update_link_info(hw);
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001713 if (status) {
1714 /* Wait a little bit (on 40G cards it sometimes takes a really
1715 * long time for link to come back from the atomic reset)
1716 * and try once more
1717 */
1718 msleep(1000);
Catherine Sullivan0a862b42015-08-31 19:54:53 -04001719 status = i40e_update_link_info(hw);
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001720 }
1721 if (status)
1722 *aq_failures |= I40E_SET_FC_AQ_FAIL_UPDATE;
1723
1724 return status;
1725}
1726
1727/**
Shannon Nelsonc9b9b0a2014-04-09 05:59:05 +00001728 * i40e_aq_clear_pxe_mode
1729 * @hw: pointer to the hw struct
1730 * @cmd_details: pointer to command details structure or NULL
1731 *
1732 * Tell the firmware that the driver is taking over from PXE
1733 **/
1734i40e_status i40e_aq_clear_pxe_mode(struct i40e_hw *hw,
1735 struct i40e_asq_cmd_details *cmd_details)
1736{
1737 i40e_status status;
1738 struct i40e_aq_desc desc;
1739 struct i40e_aqc_clear_pxe *cmd =
1740 (struct i40e_aqc_clear_pxe *)&desc.params.raw;
1741
1742 i40e_fill_default_direct_cmd_desc(&desc,
1743 i40e_aqc_opc_clear_pxe_mode);
1744
1745 cmd->rx_cnt = 0x2;
1746
1747 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1748
1749 wr32(hw, I40E_GLLAN_RCTL_0, 0x1);
1750
1751 return status;
1752}
1753
1754/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001755 * i40e_aq_set_link_restart_an
1756 * @hw: pointer to the hw struct
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001757 * @enable_link: if true: enable link, if false: disable link
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001758 * @cmd_details: pointer to command details structure or NULL
1759 *
1760 * Sets up the link and restarts the Auto-Negotiation over the link.
1761 **/
1762i40e_status i40e_aq_set_link_restart_an(struct i40e_hw *hw,
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001763 bool enable_link,
1764 struct i40e_asq_cmd_details *cmd_details)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001765{
1766 struct i40e_aq_desc desc;
1767 struct i40e_aqc_set_link_restart_an *cmd =
1768 (struct i40e_aqc_set_link_restart_an *)&desc.params.raw;
1769 i40e_status status;
1770
1771 i40e_fill_default_direct_cmd_desc(&desc,
1772 i40e_aqc_opc_set_link_restart_an);
1773
1774 cmd->command = I40E_AQ_PHY_RESTART_AN;
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001775 if (enable_link)
1776 cmd->command |= I40E_AQ_PHY_LINK_ENABLE;
1777 else
1778 cmd->command &= ~I40E_AQ_PHY_LINK_ENABLE;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001779
1780 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1781
1782 return status;
1783}
1784
1785/**
1786 * i40e_aq_get_link_info
1787 * @hw: pointer to the hw struct
1788 * @enable_lse: enable/disable LinkStatusEvent reporting
1789 * @link: pointer to link status structure - optional
1790 * @cmd_details: pointer to command details structure or NULL
1791 *
1792 * Returns the link status of the adapter.
1793 **/
1794i40e_status i40e_aq_get_link_info(struct i40e_hw *hw,
1795 bool enable_lse, struct i40e_link_status *link,
1796 struct i40e_asq_cmd_details *cmd_details)
1797{
1798 struct i40e_aq_desc desc;
1799 struct i40e_aqc_get_link_status *resp =
1800 (struct i40e_aqc_get_link_status *)&desc.params.raw;
1801 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
1802 i40e_status status;
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001803 bool tx_pause, rx_pause;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001804 u16 command_flags;
1805
1806 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_link_status);
1807
1808 if (enable_lse)
1809 command_flags = I40E_AQ_LSE_ENABLE;
1810 else
1811 command_flags = I40E_AQ_LSE_DISABLE;
1812 resp->command_flags = cpu_to_le16(command_flags);
1813
1814 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1815
1816 if (status)
1817 goto aq_get_link_info_exit;
1818
1819 /* save off old link status information */
Mitch Williamsc36bd4a72013-12-18 13:46:04 +00001820 hw->phy.link_info_old = *hw_link_info;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001821
1822 /* update link status */
1823 hw_link_info->phy_type = (enum i40e_aq_phy_type)resp->phy_type;
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001824 hw->phy.media_type = i40e_get_media_type(hw);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001825 hw_link_info->link_speed = (enum i40e_aq_link_speed)resp->link_speed;
1826 hw_link_info->link_info = resp->link_info;
1827 hw_link_info->an_info = resp->an_info;
1828 hw_link_info->ext_info = resp->ext_info;
Kamil Krawczyk639dc372013-11-20 10:03:07 +00001829 hw_link_info->loopback = resp->loopback;
Neerav Parikh6bb3f232014-04-01 07:11:56 +00001830 hw_link_info->max_frame_size = le16_to_cpu(resp->max_frame_size);
1831 hw_link_info->pacing = resp->config & I40E_AQ_CONFIG_PACING_MASK;
1832
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001833 /* update fc info */
1834 tx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_TX);
1835 rx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_RX);
1836 if (tx_pause & rx_pause)
1837 hw->fc.current_mode = I40E_FC_FULL;
1838 else if (tx_pause)
1839 hw->fc.current_mode = I40E_FC_TX_PAUSE;
1840 else if (rx_pause)
1841 hw->fc.current_mode = I40E_FC_RX_PAUSE;
1842 else
1843 hw->fc.current_mode = I40E_FC_NONE;
1844
Neerav Parikh6bb3f232014-04-01 07:11:56 +00001845 if (resp->config & I40E_AQ_CONFIG_CRC_ENA)
1846 hw_link_info->crc_enable = true;
1847 else
1848 hw_link_info->crc_enable = false;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001849
1850 if (resp->command_flags & cpu_to_le16(I40E_AQ_LSE_ENABLE))
1851 hw_link_info->lse_enable = true;
1852 else
1853 hw_link_info->lse_enable = false;
1854
Catherine Sullivan088c4ee2015-02-26 16:14:12 +00001855 if ((hw->aq.fw_maj_ver < 4 || (hw->aq.fw_maj_ver == 4 &&
1856 hw->aq.fw_min_ver < 40)) && hw_link_info->phy_type == 0xE)
1857 hw_link_info->phy_type = I40E_PHY_TYPE_10GBASE_SFPP_CU;
1858
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001859 /* save link status information */
1860 if (link)
Jesse Brandeburgd7595a22013-09-13 08:23:22 +00001861 *link = *hw_link_info;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001862
1863 /* flag cleared so helper functions don't call AQ again */
1864 hw->phy.get_link_info = false;
1865
1866aq_get_link_info_exit:
1867 return status;
1868}
1869
1870/**
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00001871 * i40e_aq_set_phy_int_mask
1872 * @hw: pointer to the hw struct
1873 * @mask: interrupt mask to be set
1874 * @cmd_details: pointer to command details structure or NULL
1875 *
1876 * Set link interrupt mask.
1877 **/
1878i40e_status i40e_aq_set_phy_int_mask(struct i40e_hw *hw,
1879 u16 mask,
1880 struct i40e_asq_cmd_details *cmd_details)
1881{
1882 struct i40e_aq_desc desc;
1883 struct i40e_aqc_set_phy_int_mask *cmd =
1884 (struct i40e_aqc_set_phy_int_mask *)&desc.params.raw;
1885 i40e_status status;
1886
1887 i40e_fill_default_direct_cmd_desc(&desc,
1888 i40e_aqc_opc_set_phy_int_mask);
1889
1890 cmd->event_mask = cpu_to_le16(mask);
1891
1892 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1893
1894 return status;
1895}
1896
1897/**
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001898 * i40e_aq_set_phy_debug
1899 * @hw: pointer to the hw struct
1900 * @cmd_flags: debug command flags
1901 * @cmd_details: pointer to command details structure or NULL
1902 *
1903 * Reset the external PHY.
1904 **/
Jesse Brandeburg61829022016-03-10 14:59:42 -08001905i40e_status i40e_aq_set_phy_debug(struct i40e_hw *hw, u8 cmd_flags,
1906 struct i40e_asq_cmd_details *cmd_details)
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001907{
1908 struct i40e_aq_desc desc;
1909 struct i40e_aqc_set_phy_debug *cmd =
1910 (struct i40e_aqc_set_phy_debug *)&desc.params.raw;
Jesse Brandeburg61829022016-03-10 14:59:42 -08001911 i40e_status status;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001912
1913 i40e_fill_default_direct_cmd_desc(&desc,
1914 i40e_aqc_opc_set_phy_debug);
1915
1916 cmd->command_flags = cmd_flags;
1917
1918 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1919
1920 return status;
1921}
1922
1923/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001924 * i40e_aq_add_vsi
1925 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00001926 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001927 * @cmd_details: pointer to command details structure or NULL
1928 *
1929 * Add a VSI context to the hardware.
1930**/
1931i40e_status i40e_aq_add_vsi(struct i40e_hw *hw,
1932 struct i40e_vsi_context *vsi_ctx,
1933 struct i40e_asq_cmd_details *cmd_details)
1934{
1935 struct i40e_aq_desc desc;
1936 struct i40e_aqc_add_get_update_vsi *cmd =
1937 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
1938 struct i40e_aqc_add_get_update_vsi_completion *resp =
1939 (struct i40e_aqc_add_get_update_vsi_completion *)
1940 &desc.params.raw;
1941 i40e_status status;
1942
1943 i40e_fill_default_direct_cmd_desc(&desc,
1944 i40e_aqc_opc_add_vsi);
1945
1946 cmd->uplink_seid = cpu_to_le16(vsi_ctx->uplink_seid);
1947 cmd->connection_type = vsi_ctx->connection_type;
1948 cmd->vf_id = vsi_ctx->vf_num;
1949 cmd->vsi_flags = cpu_to_le16(vsi_ctx->flags);
1950
1951 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001952
1953 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
1954 sizeof(vsi_ctx->info), cmd_details);
1955
1956 if (status)
1957 goto aq_add_vsi_exit;
1958
1959 vsi_ctx->seid = le16_to_cpu(resp->seid);
1960 vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
1961 vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
1962 vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
1963
1964aq_add_vsi_exit:
1965 return status;
1966}
1967
1968/**
1969 * i40e_aq_set_vsi_unicast_promiscuous
1970 * @hw: pointer to the hw struct
1971 * @seid: vsi number
1972 * @set: set unicast promiscuous enable/disable
1973 * @cmd_details: pointer to command details structure or NULL
1974 **/
1975i40e_status i40e_aq_set_vsi_unicast_promiscuous(struct i40e_hw *hw,
Mitch Williams885552a2013-12-21 05:44:41 +00001976 u16 seid, bool set,
1977 struct i40e_asq_cmd_details *cmd_details)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001978{
1979 struct i40e_aq_desc desc;
1980 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
1981 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
1982 i40e_status status;
1983 u16 flags = 0;
1984
1985 i40e_fill_default_direct_cmd_desc(&desc,
1986 i40e_aqc_opc_set_vsi_promiscuous_modes);
1987
Anjali Singhai Jain3b120082016-01-15 14:33:21 -08001988 if (set) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001989 flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
Anjali Singhai Jain3b120082016-01-15 14:33:21 -08001990 if (((hw->aq.api_maj_ver == 1) && (hw->aq.api_min_ver >= 5)) ||
1991 (hw->aq.api_maj_ver > 1))
1992 flags |= I40E_AQC_SET_VSI_PROMISC_TX;
1993 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001994
1995 cmd->promiscuous_flags = cpu_to_le16(flags);
1996
1997 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
Anjali Singhai Jain3b120082016-01-15 14:33:21 -08001998 if (((hw->aq.api_maj_ver >= 1) && (hw->aq.api_min_ver >= 5)) ||
1999 (hw->aq.api_maj_ver > 1))
2000 cmd->valid_flags |= cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_TX);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002001
2002 cmd->seid = cpu_to_le16(seid);
2003 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2004
2005 return status;
2006}
2007
2008/**
2009 * i40e_aq_set_vsi_multicast_promiscuous
2010 * @hw: pointer to the hw struct
2011 * @seid: vsi number
2012 * @set: set multicast promiscuous enable/disable
2013 * @cmd_details: pointer to command details structure or NULL
2014 **/
2015i40e_status i40e_aq_set_vsi_multicast_promiscuous(struct i40e_hw *hw,
2016 u16 seid, bool set, struct i40e_asq_cmd_details *cmd_details)
2017{
2018 struct i40e_aq_desc desc;
2019 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2020 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2021 i40e_status status;
2022 u16 flags = 0;
2023
2024 i40e_fill_default_direct_cmd_desc(&desc,
2025 i40e_aqc_opc_set_vsi_promiscuous_modes);
2026
2027 if (set)
2028 flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
2029
2030 cmd->promiscuous_flags = cpu_to_le16(flags);
2031
2032 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
2033
2034 cmd->seid = cpu_to_le16(seid);
2035 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2036
2037 return status;
2038}
2039
2040/**
2041 * i40e_aq_set_vsi_broadcast
2042 * @hw: pointer to the hw struct
2043 * @seid: vsi number
2044 * @set_filter: true to set filter, false to clear filter
2045 * @cmd_details: pointer to command details structure or NULL
2046 *
2047 * Set or clear the broadcast promiscuous flag (filter) for a given VSI.
2048 **/
2049i40e_status i40e_aq_set_vsi_broadcast(struct i40e_hw *hw,
2050 u16 seid, bool set_filter,
2051 struct i40e_asq_cmd_details *cmd_details)
2052{
2053 struct i40e_aq_desc desc;
2054 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2055 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2056 i40e_status status;
2057
2058 i40e_fill_default_direct_cmd_desc(&desc,
2059 i40e_aqc_opc_set_vsi_promiscuous_modes);
2060
2061 if (set_filter)
2062 cmd->promiscuous_flags
2063 |= cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2064 else
2065 cmd->promiscuous_flags
2066 &= cpu_to_le16(~I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2067
2068 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2069 cmd->seid = cpu_to_le16(seid);
2070 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2071
2072 return status;
2073}
2074
2075/**
Kiran Patil7bd68752016-01-04 10:33:07 -08002076 * i40e_aq_set_vsi_vlan_promisc - control the VLAN promiscuous setting
2077 * @hw: pointer to the hw struct
2078 * @seid: vsi number
2079 * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
2080 * @cmd_details: pointer to command details structure or NULL
2081 **/
2082i40e_status i40e_aq_set_vsi_vlan_promisc(struct i40e_hw *hw,
2083 u16 seid, bool enable,
2084 struct i40e_asq_cmd_details *cmd_details)
2085{
2086 struct i40e_aq_desc desc;
2087 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2088 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2089 i40e_status status;
2090 u16 flags = 0;
2091
2092 i40e_fill_default_direct_cmd_desc(&desc,
2093 i40e_aqc_opc_set_vsi_promiscuous_modes);
2094 if (enable)
2095 flags |= I40E_AQC_SET_VSI_PROMISC_VLAN;
2096
2097 cmd->promiscuous_flags = cpu_to_le16(flags);
2098 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_VLAN);
2099 cmd->seid = cpu_to_le16(seid);
2100
2101 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2102
2103 return status;
2104}
2105
2106/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002107 * i40e_get_vsi_params - get VSI configuration info
2108 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00002109 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002110 * @cmd_details: pointer to command details structure or NULL
2111 **/
2112i40e_status i40e_aq_get_vsi_params(struct i40e_hw *hw,
2113 struct i40e_vsi_context *vsi_ctx,
2114 struct i40e_asq_cmd_details *cmd_details)
2115{
2116 struct i40e_aq_desc desc;
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002117 struct i40e_aqc_add_get_update_vsi *cmd =
2118 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002119 struct i40e_aqc_add_get_update_vsi_completion *resp =
2120 (struct i40e_aqc_add_get_update_vsi_completion *)
2121 &desc.params.raw;
2122 i40e_status status;
2123
2124 i40e_fill_default_direct_cmd_desc(&desc,
2125 i40e_aqc_opc_get_vsi_parameters);
2126
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002127 cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002128
2129 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002130
2131 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
2132 sizeof(vsi_ctx->info), NULL);
2133
2134 if (status)
2135 goto aq_get_vsi_params_exit;
2136
2137 vsi_ctx->seid = le16_to_cpu(resp->seid);
2138 vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
2139 vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
2140 vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
2141
2142aq_get_vsi_params_exit:
2143 return status;
2144}
2145
2146/**
2147 * i40e_aq_update_vsi_params
2148 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00002149 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002150 * @cmd_details: pointer to command details structure or NULL
2151 *
2152 * Update a VSI context.
2153 **/
2154i40e_status i40e_aq_update_vsi_params(struct i40e_hw *hw,
2155 struct i40e_vsi_context *vsi_ctx,
2156 struct i40e_asq_cmd_details *cmd_details)
2157{
2158 struct i40e_aq_desc desc;
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002159 struct i40e_aqc_add_get_update_vsi *cmd =
2160 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
Kevin Scottb6cacca2016-03-10 14:59:41 -08002161 struct i40e_aqc_add_get_update_vsi_completion *resp =
2162 (struct i40e_aqc_add_get_update_vsi_completion *)
2163 &desc.params.raw;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002164 i40e_status status;
2165
2166 i40e_fill_default_direct_cmd_desc(&desc,
2167 i40e_aqc_opc_update_vsi_parameters);
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002168 cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002169
2170 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002171
2172 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
2173 sizeof(vsi_ctx->info), cmd_details);
2174
Kevin Scottb6cacca2016-03-10 14:59:41 -08002175 vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
2176 vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
2177
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002178 return status;
2179}
2180
2181/**
2182 * i40e_aq_get_switch_config
2183 * @hw: pointer to the hardware structure
2184 * @buf: pointer to the result buffer
2185 * @buf_size: length of input buffer
2186 * @start_seid: seid to start for the report, 0 == beginning
2187 * @cmd_details: pointer to command details structure or NULL
2188 *
2189 * Fill the buf with switch configuration returned from AdminQ command
2190 **/
2191i40e_status i40e_aq_get_switch_config(struct i40e_hw *hw,
2192 struct i40e_aqc_get_switch_config_resp *buf,
2193 u16 buf_size, u16 *start_seid,
2194 struct i40e_asq_cmd_details *cmd_details)
2195{
2196 struct i40e_aq_desc desc;
2197 struct i40e_aqc_switch_seid *scfg =
2198 (struct i40e_aqc_switch_seid *)&desc.params.raw;
2199 i40e_status status;
2200
2201 i40e_fill_default_direct_cmd_desc(&desc,
2202 i40e_aqc_opc_get_switch_config);
2203 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
2204 if (buf_size > I40E_AQ_LARGE_BUF)
2205 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2206 scfg->seid = cpu_to_le16(*start_seid);
2207
2208 status = i40e_asq_send_command(hw, &desc, buf, buf_size, cmd_details);
2209 *start_seid = le16_to_cpu(scfg->seid);
2210
2211 return status;
2212}
2213
2214/**
2215 * i40e_aq_get_firmware_version
2216 * @hw: pointer to the hw struct
2217 * @fw_major_version: firmware major version
2218 * @fw_minor_version: firmware minor version
Shannon Nelson7edf8102015-02-24 06:58:41 +00002219 * @fw_build: firmware build number
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002220 * @api_major_version: major queue version
2221 * @api_minor_version: minor queue version
2222 * @cmd_details: pointer to command details structure or NULL
2223 *
2224 * Get the firmware version from the admin queue commands
2225 **/
2226i40e_status i40e_aq_get_firmware_version(struct i40e_hw *hw,
2227 u16 *fw_major_version, u16 *fw_minor_version,
Shannon Nelson7edf8102015-02-24 06:58:41 +00002228 u32 *fw_build,
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002229 u16 *api_major_version, u16 *api_minor_version,
2230 struct i40e_asq_cmd_details *cmd_details)
2231{
2232 struct i40e_aq_desc desc;
2233 struct i40e_aqc_get_version *resp =
2234 (struct i40e_aqc_get_version *)&desc.params.raw;
2235 i40e_status status;
2236
2237 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_version);
2238
2239 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2240
2241 if (!status) {
Shannon Nelson7edf8102015-02-24 06:58:41 +00002242 if (fw_major_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002243 *fw_major_version = le16_to_cpu(resp->fw_major);
Shannon Nelson7edf8102015-02-24 06:58:41 +00002244 if (fw_minor_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002245 *fw_minor_version = le16_to_cpu(resp->fw_minor);
Shannon Nelson7edf8102015-02-24 06:58:41 +00002246 if (fw_build)
2247 *fw_build = le32_to_cpu(resp->fw_build);
2248 if (api_major_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002249 *api_major_version = le16_to_cpu(resp->api_major);
Shannon Nelson7edf8102015-02-24 06:58:41 +00002250 if (api_minor_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002251 *api_minor_version = le16_to_cpu(resp->api_minor);
2252 }
2253
2254 return status;
2255}
2256
2257/**
2258 * i40e_aq_send_driver_version
2259 * @hw: pointer to the hw struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002260 * @dv: driver's major, minor version
2261 * @cmd_details: pointer to command details structure or NULL
2262 *
2263 * Send the driver version to the firmware
2264 **/
2265i40e_status i40e_aq_send_driver_version(struct i40e_hw *hw,
2266 struct i40e_driver_version *dv,
2267 struct i40e_asq_cmd_details *cmd_details)
2268{
2269 struct i40e_aq_desc desc;
2270 struct i40e_aqc_driver_version *cmd =
2271 (struct i40e_aqc_driver_version *)&desc.params.raw;
2272 i40e_status status;
Kevin Scott9d2f98e2014-04-01 07:11:52 +00002273 u16 len;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002274
2275 if (dv == NULL)
2276 return I40E_ERR_PARAM;
2277
2278 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_driver_version);
2279
Kevin Scott3b38cd12015-02-06 08:52:18 +00002280 desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002281 cmd->driver_major_ver = dv->major_version;
2282 cmd->driver_minor_ver = dv->minor_version;
2283 cmd->driver_build_ver = dv->build_version;
2284 cmd->driver_subbuild_ver = dv->subbuild_version;
Shannon Nelsond2466012014-04-01 07:11:45 +00002285
2286 len = 0;
2287 while (len < sizeof(dv->driver_string) &&
2288 (dv->driver_string[len] < 0x80) &&
2289 dv->driver_string[len])
2290 len++;
2291 status = i40e_asq_send_command(hw, &desc, dv->driver_string,
2292 len, cmd_details);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002293
2294 return status;
2295}
2296
2297/**
2298 * i40e_get_link_status - get status of the HW network link
2299 * @hw: pointer to the hw struct
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002300 * @link_up: pointer to bool (true/false = linkup/linkdown)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002301 *
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002302 * Variable link_up true if link is up, false if link is down.
2303 * The variable link_up is invalid if returned value of status != 0
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002304 *
2305 * Side effect: LinkStatusEvent reporting becomes enabled
2306 **/
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002307i40e_status i40e_get_link_status(struct i40e_hw *hw, bool *link_up)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002308{
2309 i40e_status status = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002310
2311 if (hw->phy.get_link_info) {
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002312 status = i40e_update_link_info(hw);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002313
2314 if (status)
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002315 i40e_debug(hw, I40E_DEBUG_LINK, "get link failed: status %d\n",
2316 status);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002317 }
2318
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002319 *link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002320
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002321 return status;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002322}
2323
2324/**
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002325 * i40e_updatelink_status - update status of the HW network link
2326 * @hw: pointer to the hw struct
2327 **/
2328i40e_status i40e_update_link_info(struct i40e_hw *hw)
2329{
2330 struct i40e_aq_get_phy_abilities_resp abilities;
2331 i40e_status status = 0;
2332
2333 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
2334 if (status)
2335 return status;
2336
Carolyn Wyborny8589af72015-09-28 14:16:56 -04002337 if (hw->phy.link_info.link_info & I40E_AQ_MEDIA_AVAILABLE) {
2338 status = i40e_aq_get_phy_capabilities(hw, false, false,
2339 &abilities, NULL);
2340 if (status)
2341 return status;
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002342
Carolyn Wyborny8589af72015-09-28 14:16:56 -04002343 memcpy(hw->phy.link_info.module_type, &abilities.module_type,
2344 sizeof(hw->phy.link_info.module_type));
2345 }
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002346
2347 return status;
2348}
2349
2350/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002351 * i40e_aq_add_veb - Insert a VEB between the VSI and the MAC
2352 * @hw: pointer to the hw struct
2353 * @uplink_seid: the MAC or other gizmo SEID
2354 * @downlink_seid: the VSI SEID
2355 * @enabled_tc: bitmap of TCs to be enabled
2356 * @default_port: true for default port VSI, false for control port
2357 * @veb_seid: pointer to where to put the resulting VEB SEID
Shannon Nelson8a187f42016-01-13 16:51:41 -08002358 * @enable_stats: true to turn on VEB stats
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002359 * @cmd_details: pointer to command details structure or NULL
2360 *
2361 * This asks the FW to add a VEB between the uplink and downlink
2362 * elements. If the uplink SEID is 0, this will be a floating VEB.
2363 **/
2364i40e_status i40e_aq_add_veb(struct i40e_hw *hw, u16 uplink_seid,
2365 u16 downlink_seid, u8 enabled_tc,
Shannon Nelson8a187f42016-01-13 16:51:41 -08002366 bool default_port, u16 *veb_seid,
2367 bool enable_stats,
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002368 struct i40e_asq_cmd_details *cmd_details)
2369{
2370 struct i40e_aq_desc desc;
2371 struct i40e_aqc_add_veb *cmd =
2372 (struct i40e_aqc_add_veb *)&desc.params.raw;
2373 struct i40e_aqc_add_veb_completion *resp =
2374 (struct i40e_aqc_add_veb_completion *)&desc.params.raw;
2375 i40e_status status;
2376 u16 veb_flags = 0;
2377
2378 /* SEIDs need to either both be set or both be 0 for floating VEB */
2379 if (!!uplink_seid != !!downlink_seid)
2380 return I40E_ERR_PARAM;
2381
2382 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_veb);
2383
2384 cmd->uplink_seid = cpu_to_le16(uplink_seid);
2385 cmd->downlink_seid = cpu_to_le16(downlink_seid);
2386 cmd->enable_tcs = enabled_tc;
2387 if (!uplink_seid)
2388 veb_flags |= I40E_AQC_ADD_VEB_FLOATING;
2389 if (default_port)
2390 veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DEFAULT;
2391 else
2392 veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DATA;
Kevin Scotte1c51b952013-11-20 10:02:51 +00002393
Shannon Nelson8a187f42016-01-13 16:51:41 -08002394 /* reverse logic here: set the bitflag to disable the stats */
2395 if (!enable_stats)
2396 veb_flags |= I40E_AQC_ADD_VEB_ENABLE_DISABLE_STATS;
Kevin Scotte1c51b952013-11-20 10:02:51 +00002397
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002398 cmd->veb_flags = cpu_to_le16(veb_flags);
2399
2400 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2401
2402 if (!status && veb_seid)
2403 *veb_seid = le16_to_cpu(resp->veb_seid);
2404
2405 return status;
2406}
2407
2408/**
2409 * i40e_aq_get_veb_parameters - Retrieve VEB parameters
2410 * @hw: pointer to the hw struct
2411 * @veb_seid: the SEID of the VEB to query
2412 * @switch_id: the uplink switch id
Jeff Kirsher98d44382013-12-21 05:44:42 +00002413 * @floating: set to true if the VEB is floating
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002414 * @statistic_index: index of the stats counter block for this VEB
2415 * @vebs_used: number of VEB's used by function
Jeff Kirsher98d44382013-12-21 05:44:42 +00002416 * @vebs_free: total VEB's not reserved by any function
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002417 * @cmd_details: pointer to command details structure or NULL
2418 *
2419 * This retrieves the parameters for a particular VEB, specified by
2420 * uplink_seid, and returns them to the caller.
2421 **/
2422i40e_status i40e_aq_get_veb_parameters(struct i40e_hw *hw,
2423 u16 veb_seid, u16 *switch_id,
2424 bool *floating, u16 *statistic_index,
2425 u16 *vebs_used, u16 *vebs_free,
2426 struct i40e_asq_cmd_details *cmd_details)
2427{
2428 struct i40e_aq_desc desc;
2429 struct i40e_aqc_get_veb_parameters_completion *cmd_resp =
2430 (struct i40e_aqc_get_veb_parameters_completion *)
2431 &desc.params.raw;
2432 i40e_status status;
2433
2434 if (veb_seid == 0)
2435 return I40E_ERR_PARAM;
2436
2437 i40e_fill_default_direct_cmd_desc(&desc,
2438 i40e_aqc_opc_get_veb_parameters);
2439 cmd_resp->seid = cpu_to_le16(veb_seid);
2440
2441 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2442 if (status)
2443 goto get_veb_exit;
2444
2445 if (switch_id)
2446 *switch_id = le16_to_cpu(cmd_resp->switch_id);
2447 if (statistic_index)
2448 *statistic_index = le16_to_cpu(cmd_resp->statistic_index);
2449 if (vebs_used)
2450 *vebs_used = le16_to_cpu(cmd_resp->vebs_used);
2451 if (vebs_free)
2452 *vebs_free = le16_to_cpu(cmd_resp->vebs_free);
2453 if (floating) {
2454 u16 flags = le16_to_cpu(cmd_resp->veb_flags);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04002455
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002456 if (flags & I40E_AQC_ADD_VEB_FLOATING)
2457 *floating = true;
2458 else
2459 *floating = false;
2460 }
2461
2462get_veb_exit:
2463 return status;
2464}
2465
2466/**
2467 * i40e_aq_add_macvlan
2468 * @hw: pointer to the hw struct
2469 * @seid: VSI for the mac address
2470 * @mv_list: list of macvlans to be added
2471 * @count: length of the list
2472 * @cmd_details: pointer to command details structure or NULL
2473 *
2474 * Add MAC/VLAN addresses to the HW filtering
2475 **/
2476i40e_status i40e_aq_add_macvlan(struct i40e_hw *hw, u16 seid,
2477 struct i40e_aqc_add_macvlan_element_data *mv_list,
2478 u16 count, struct i40e_asq_cmd_details *cmd_details)
2479{
2480 struct i40e_aq_desc desc;
2481 struct i40e_aqc_macvlan *cmd =
2482 (struct i40e_aqc_macvlan *)&desc.params.raw;
2483 i40e_status status;
2484 u16 buf_size;
Shannon Nelson67be6eb2016-01-13 16:51:40 -08002485 int i;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002486
2487 if (count == 0 || !mv_list || !hw)
2488 return I40E_ERR_PARAM;
2489
Shannon Nelson1efc80e2015-02-27 09:18:30 +00002490 buf_size = count * sizeof(*mv_list);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002491
2492 /* prep the rest of the request */
2493 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_macvlan);
2494 cmd->num_addresses = cpu_to_le16(count);
2495 cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
2496 cmd->seid[1] = 0;
2497 cmd->seid[2] = 0;
2498
Shannon Nelson67be6eb2016-01-13 16:51:40 -08002499 for (i = 0; i < count; i++)
2500 if (is_multicast_ether_addr(mv_list[i].mac_addr))
2501 mv_list[i].flags |=
2502 cpu_to_le16(I40E_AQC_MACVLAN_ADD_USE_SHARED_MAC);
2503
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002504 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
2505 if (buf_size > I40E_AQ_LARGE_BUF)
2506 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2507
2508 status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
Shannon Nelson67be6eb2016-01-13 16:51:40 -08002509 cmd_details);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002510
2511 return status;
2512}
2513
2514/**
2515 * i40e_aq_remove_macvlan
2516 * @hw: pointer to the hw struct
2517 * @seid: VSI for the mac address
2518 * @mv_list: list of macvlans to be removed
2519 * @count: length of the list
2520 * @cmd_details: pointer to command details structure or NULL
2521 *
2522 * Remove MAC/VLAN addresses from the HW filtering
2523 **/
2524i40e_status i40e_aq_remove_macvlan(struct i40e_hw *hw, u16 seid,
2525 struct i40e_aqc_remove_macvlan_element_data *mv_list,
2526 u16 count, struct i40e_asq_cmd_details *cmd_details)
2527{
2528 struct i40e_aq_desc desc;
2529 struct i40e_aqc_macvlan *cmd =
2530 (struct i40e_aqc_macvlan *)&desc.params.raw;
2531 i40e_status status;
2532 u16 buf_size;
2533
2534 if (count == 0 || !mv_list || !hw)
2535 return I40E_ERR_PARAM;
2536
Shannon Nelson1efc80e2015-02-27 09:18:30 +00002537 buf_size = count * sizeof(*mv_list);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002538
2539 /* prep the rest of the request */
2540 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_macvlan);
2541 cmd->num_addresses = cpu_to_le16(count);
2542 cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
2543 cmd->seid[1] = 0;
2544 cmd->seid[2] = 0;
2545
2546 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
2547 if (buf_size > I40E_AQ_LARGE_BUF)
2548 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2549
2550 status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
2551 cmd_details);
2552
2553 return status;
2554}
2555
2556/**
Kiran Patil7bd68752016-01-04 10:33:07 -08002557 * i40e_mirrorrule_op - Internal helper function to add/delete mirror rule
2558 * @hw: pointer to the hw struct
2559 * @opcode: AQ opcode for add or delete mirror rule
2560 * @sw_seid: Switch SEID (to which rule refers)
2561 * @rule_type: Rule Type (ingress/egress/VLAN)
2562 * @id: Destination VSI SEID or Rule ID
2563 * @count: length of the list
2564 * @mr_list: list of mirrored VSI SEIDs or VLAN IDs
2565 * @cmd_details: pointer to command details structure or NULL
2566 * @rule_id: Rule ID returned from FW
2567 * @rule_used: Number of rules used in internal switch
2568 * @rule_free: Number of rules free in internal switch
2569 *
2570 * Add/Delete a mirror rule to a specific switch. Mirror rules are supported for
2571 * VEBs/VEPA elements only
2572 **/
2573static i40e_status i40e_mirrorrule_op(struct i40e_hw *hw,
2574 u16 opcode, u16 sw_seid, u16 rule_type, u16 id,
2575 u16 count, __le16 *mr_list,
2576 struct i40e_asq_cmd_details *cmd_details,
2577 u16 *rule_id, u16 *rules_used, u16 *rules_free)
2578{
2579 struct i40e_aq_desc desc;
2580 struct i40e_aqc_add_delete_mirror_rule *cmd =
2581 (struct i40e_aqc_add_delete_mirror_rule *)&desc.params.raw;
2582 struct i40e_aqc_add_delete_mirror_rule_completion *resp =
2583 (struct i40e_aqc_add_delete_mirror_rule_completion *)&desc.params.raw;
2584 i40e_status status;
2585 u16 buf_size;
2586
2587 buf_size = count * sizeof(*mr_list);
2588
2589 /* prep the rest of the request */
2590 i40e_fill_default_direct_cmd_desc(&desc, opcode);
2591 cmd->seid = cpu_to_le16(sw_seid);
2592 cmd->rule_type = cpu_to_le16(rule_type &
2593 I40E_AQC_MIRROR_RULE_TYPE_MASK);
2594 cmd->num_entries = cpu_to_le16(count);
2595 /* Dest VSI for add, rule_id for delete */
2596 cmd->destination = cpu_to_le16(id);
2597 if (mr_list) {
2598 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
2599 I40E_AQ_FLAG_RD));
2600 if (buf_size > I40E_AQ_LARGE_BUF)
2601 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2602 }
2603
2604 status = i40e_asq_send_command(hw, &desc, mr_list, buf_size,
2605 cmd_details);
2606 if (!status ||
2607 hw->aq.asq_last_status == I40E_AQ_RC_ENOSPC) {
2608 if (rule_id)
2609 *rule_id = le16_to_cpu(resp->rule_id);
2610 if (rules_used)
2611 *rules_used = le16_to_cpu(resp->mirror_rules_used);
2612 if (rules_free)
2613 *rules_free = le16_to_cpu(resp->mirror_rules_free);
2614 }
2615 return status;
2616}
2617
2618/**
2619 * i40e_aq_add_mirrorrule - add a mirror rule
2620 * @hw: pointer to the hw struct
2621 * @sw_seid: Switch SEID (to which rule refers)
2622 * @rule_type: Rule Type (ingress/egress/VLAN)
2623 * @dest_vsi: SEID of VSI to which packets will be mirrored
2624 * @count: length of the list
2625 * @mr_list: list of mirrored VSI SEIDs or VLAN IDs
2626 * @cmd_details: pointer to command details structure or NULL
2627 * @rule_id: Rule ID returned from FW
2628 * @rule_used: Number of rules used in internal switch
2629 * @rule_free: Number of rules free in internal switch
2630 *
2631 * Add mirror rule. Mirror rules are supported for VEBs or VEPA elements only
2632 **/
2633i40e_status i40e_aq_add_mirrorrule(struct i40e_hw *hw, u16 sw_seid,
2634 u16 rule_type, u16 dest_vsi, u16 count, __le16 *mr_list,
2635 struct i40e_asq_cmd_details *cmd_details,
2636 u16 *rule_id, u16 *rules_used, u16 *rules_free)
2637{
2638 if (!(rule_type == I40E_AQC_MIRROR_RULE_TYPE_ALL_INGRESS ||
2639 rule_type == I40E_AQC_MIRROR_RULE_TYPE_ALL_EGRESS)) {
2640 if (count == 0 || !mr_list)
2641 return I40E_ERR_PARAM;
2642 }
2643
2644 return i40e_mirrorrule_op(hw, i40e_aqc_opc_add_mirror_rule, sw_seid,
2645 rule_type, dest_vsi, count, mr_list,
2646 cmd_details, rule_id, rules_used, rules_free);
2647}
2648
2649/**
2650 * i40e_aq_delete_mirrorrule - delete a mirror rule
2651 * @hw: pointer to the hw struct
2652 * @sw_seid: Switch SEID (to which rule refers)
2653 * @rule_type: Rule Type (ingress/egress/VLAN)
2654 * @count: length of the list
2655 * @rule_id: Rule ID that is returned in the receive desc as part of
2656 * add_mirrorrule.
2657 * @mr_list: list of mirrored VLAN IDs to be removed
2658 * @cmd_details: pointer to command details structure or NULL
2659 * @rule_used: Number of rules used in internal switch
2660 * @rule_free: Number of rules free in internal switch
2661 *
2662 * Delete a mirror rule. Mirror rules are supported for VEBs/VEPA elements only
2663 **/
2664i40e_status i40e_aq_delete_mirrorrule(struct i40e_hw *hw, u16 sw_seid,
2665 u16 rule_type, u16 rule_id, u16 count, __le16 *mr_list,
2666 struct i40e_asq_cmd_details *cmd_details,
2667 u16 *rules_used, u16 *rules_free)
2668{
2669 /* Rule ID has to be valid except rule_type: INGRESS VLAN mirroring */
2670 if (rule_type != I40E_AQC_MIRROR_RULE_TYPE_VLAN) {
2671 if (!rule_id)
2672 return I40E_ERR_PARAM;
2673 } else {
2674 /* count and mr_list shall be valid for rule_type INGRESS VLAN
2675 * mirroring. For other rule_type, count and rule_type should
2676 * not matter.
2677 */
2678 if (count == 0 || !mr_list)
2679 return I40E_ERR_PARAM;
2680 }
2681
2682 return i40e_mirrorrule_op(hw, i40e_aqc_opc_delete_mirror_rule, sw_seid,
2683 rule_type, rule_id, count, mr_list,
2684 cmd_details, NULL, rules_used, rules_free);
2685}
2686
2687/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002688 * i40e_aq_send_msg_to_vf
2689 * @hw: pointer to the hardware structure
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00002690 * @vfid: VF id to send msg
Jeff Kirsher98d44382013-12-21 05:44:42 +00002691 * @v_opcode: opcodes for VF-PF communication
2692 * @v_retval: return error code
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002693 * @msg: pointer to the msg buffer
2694 * @msglen: msg length
2695 * @cmd_details: pointer to command details
2696 *
2697 * send msg to vf
2698 **/
2699i40e_status i40e_aq_send_msg_to_vf(struct i40e_hw *hw, u16 vfid,
2700 u32 v_opcode, u32 v_retval, u8 *msg, u16 msglen,
2701 struct i40e_asq_cmd_details *cmd_details)
2702{
2703 struct i40e_aq_desc desc;
2704 struct i40e_aqc_pf_vf_message *cmd =
2705 (struct i40e_aqc_pf_vf_message *)&desc.params.raw;
2706 i40e_status status;
2707
2708 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_vf);
2709 cmd->id = cpu_to_le32(vfid);
2710 desc.cookie_high = cpu_to_le32(v_opcode);
2711 desc.cookie_low = cpu_to_le32(v_retval);
2712 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_SI);
2713 if (msglen) {
2714 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
2715 I40E_AQ_FLAG_RD));
2716 if (msglen > I40E_AQ_LARGE_BUF)
2717 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2718 desc.datalen = cpu_to_le16(msglen);
2719 }
2720 status = i40e_asq_send_command(hw, &desc, msg, msglen, cmd_details);
2721
2722 return status;
2723}
2724
2725/**
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002726 * i40e_aq_debug_read_register
2727 * @hw: pointer to the hw struct
2728 * @reg_addr: register address
2729 * @reg_val: register value
2730 * @cmd_details: pointer to command details structure or NULL
2731 *
2732 * Read the register using the admin queue commands
2733 **/
2734i40e_status i40e_aq_debug_read_register(struct i40e_hw *hw,
Jesse Brandeburg7b115dd2015-02-27 09:15:23 +00002735 u32 reg_addr, u64 *reg_val,
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002736 struct i40e_asq_cmd_details *cmd_details)
2737{
2738 struct i40e_aq_desc desc;
2739 struct i40e_aqc_debug_reg_read_write *cmd_resp =
2740 (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
2741 i40e_status status;
2742
2743 if (reg_val == NULL)
2744 return I40E_ERR_PARAM;
2745
Jesse Brandeburg7b115dd2015-02-27 09:15:23 +00002746 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_read_reg);
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002747
2748 cmd_resp->address = cpu_to_le32(reg_addr);
2749
2750 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2751
2752 if (!status) {
Jesse Brandeburg7b115dd2015-02-27 09:15:23 +00002753 *reg_val = ((u64)le32_to_cpu(cmd_resp->value_high) << 32) |
2754 (u64)le32_to_cpu(cmd_resp->value_low);
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002755 }
2756
2757 return status;
2758}
2759
2760/**
Shannon Nelson53db45c2014-08-01 13:27:05 -07002761 * i40e_aq_debug_write_register
2762 * @hw: pointer to the hw struct
2763 * @reg_addr: register address
2764 * @reg_val: register value
2765 * @cmd_details: pointer to command details structure or NULL
2766 *
2767 * Write to a register using the admin queue commands
2768 **/
2769i40e_status i40e_aq_debug_write_register(struct i40e_hw *hw,
2770 u32 reg_addr, u64 reg_val,
2771 struct i40e_asq_cmd_details *cmd_details)
2772{
2773 struct i40e_aq_desc desc;
2774 struct i40e_aqc_debug_reg_read_write *cmd =
2775 (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
2776 i40e_status status;
2777
2778 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_write_reg);
2779
2780 cmd->address = cpu_to_le32(reg_addr);
2781 cmd->value_high = cpu_to_le32((u32)(reg_val >> 32));
2782 cmd->value_low = cpu_to_le32((u32)(reg_val & 0xFFFFFFFF));
2783
2784 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2785
2786 return status;
2787}
2788
2789/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002790 * i40e_aq_set_hmc_resource_profile
2791 * @hw: pointer to the hw struct
2792 * @profile: type of profile the HMC is to be set as
2793 * @pe_vf_enabled_count: the number of PE enabled VFs the system has
2794 * @cmd_details: pointer to command details structure or NULL
2795 *
2796 * set the HMC profile of the device.
2797 **/
2798i40e_status i40e_aq_set_hmc_resource_profile(struct i40e_hw *hw,
2799 enum i40e_aq_hmc_profile profile,
2800 u8 pe_vf_enabled_count,
2801 struct i40e_asq_cmd_details *cmd_details)
2802{
2803 struct i40e_aq_desc desc;
2804 struct i40e_aq_get_set_hmc_resource_profile *cmd =
2805 (struct i40e_aq_get_set_hmc_resource_profile *)&desc.params.raw;
2806 i40e_status status;
2807
2808 i40e_fill_default_direct_cmd_desc(&desc,
2809 i40e_aqc_opc_set_hmc_resource_profile);
2810
2811 cmd->pm_profile = (u8)profile;
2812 cmd->pe_vf_enabled = pe_vf_enabled_count;
2813
2814 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2815
2816 return status;
2817}
2818
2819/**
2820 * i40e_aq_request_resource
2821 * @hw: pointer to the hw struct
2822 * @resource: resource id
2823 * @access: access type
2824 * @sdp_number: resource number
2825 * @timeout: the maximum time in ms that the driver may hold the resource
2826 * @cmd_details: pointer to command details structure or NULL
2827 *
2828 * requests common resource using the admin queue commands
2829 **/
2830i40e_status i40e_aq_request_resource(struct i40e_hw *hw,
2831 enum i40e_aq_resources_ids resource,
2832 enum i40e_aq_resource_access_type access,
2833 u8 sdp_number, u64 *timeout,
2834 struct i40e_asq_cmd_details *cmd_details)
2835{
2836 struct i40e_aq_desc desc;
2837 struct i40e_aqc_request_resource *cmd_resp =
2838 (struct i40e_aqc_request_resource *)&desc.params.raw;
2839 i40e_status status;
2840
2841 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_request_resource);
2842
2843 cmd_resp->resource_id = cpu_to_le16(resource);
2844 cmd_resp->access_type = cpu_to_le16(access);
2845 cmd_resp->resource_number = cpu_to_le32(sdp_number);
2846
2847 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2848 /* The completion specifies the maximum time in ms that the driver
2849 * may hold the resource in the Timeout field.
2850 * If the resource is held by someone else, the command completes with
2851 * busy return value and the timeout field indicates the maximum time
2852 * the current owner of the resource has to free it.
2853 */
2854 if (!status || hw->aq.asq_last_status == I40E_AQ_RC_EBUSY)
2855 *timeout = le32_to_cpu(cmd_resp->timeout);
2856
2857 return status;
2858}
2859
2860/**
2861 * i40e_aq_release_resource
2862 * @hw: pointer to the hw struct
2863 * @resource: resource id
2864 * @sdp_number: resource number
2865 * @cmd_details: pointer to command details structure or NULL
2866 *
2867 * release common resource using the admin queue commands
2868 **/
2869i40e_status i40e_aq_release_resource(struct i40e_hw *hw,
2870 enum i40e_aq_resources_ids resource,
2871 u8 sdp_number,
2872 struct i40e_asq_cmd_details *cmd_details)
2873{
2874 struct i40e_aq_desc desc;
2875 struct i40e_aqc_request_resource *cmd =
2876 (struct i40e_aqc_request_resource *)&desc.params.raw;
2877 i40e_status status;
2878
2879 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_release_resource);
2880
2881 cmd->resource_id = cpu_to_le16(resource);
2882 cmd->resource_number = cpu_to_le32(sdp_number);
2883
2884 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2885
2886 return status;
2887}
2888
2889/**
2890 * i40e_aq_read_nvm
2891 * @hw: pointer to the hw struct
2892 * @module_pointer: module pointer location in words from the NVM beginning
2893 * @offset: byte offset from the module beginning
2894 * @length: length of the section to be read (in bytes from the offset)
2895 * @data: command buffer (size [bytes] = length)
2896 * @last_command: tells if this is the last command in a series
2897 * @cmd_details: pointer to command details structure or NULL
2898 *
2899 * Read the NVM using the admin queue commands
2900 **/
2901i40e_status i40e_aq_read_nvm(struct i40e_hw *hw, u8 module_pointer,
2902 u32 offset, u16 length, void *data,
2903 bool last_command,
2904 struct i40e_asq_cmd_details *cmd_details)
2905{
2906 struct i40e_aq_desc desc;
2907 struct i40e_aqc_nvm_update *cmd =
2908 (struct i40e_aqc_nvm_update *)&desc.params.raw;
2909 i40e_status status;
2910
2911 /* In offset the highest byte must be zeroed. */
2912 if (offset & 0xFF000000) {
2913 status = I40E_ERR_PARAM;
2914 goto i40e_aq_read_nvm_exit;
2915 }
2916
2917 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_read);
2918
2919 /* If this is the last command in a series, set the proper flag. */
2920 if (last_command)
2921 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
2922 cmd->module_pointer = module_pointer;
2923 cmd->offset = cpu_to_le32(offset);
2924 cmd->length = cpu_to_le16(length);
2925
2926 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
2927 if (length > I40E_AQ_LARGE_BUF)
2928 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2929
2930 status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
2931
2932i40e_aq_read_nvm_exit:
2933 return status;
2934}
2935
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002936/**
2937 * i40e_aq_erase_nvm
2938 * @hw: pointer to the hw struct
2939 * @module_pointer: module pointer location in words from the NVM beginning
2940 * @offset: offset in the module (expressed in 4 KB from module's beginning)
2941 * @length: length of the section to be erased (expressed in 4 KB)
2942 * @last_command: tells if this is the last command in a series
2943 * @cmd_details: pointer to command details structure or NULL
2944 *
2945 * Erase the NVM sector using the admin queue commands
2946 **/
2947i40e_status i40e_aq_erase_nvm(struct i40e_hw *hw, u8 module_pointer,
2948 u32 offset, u16 length, bool last_command,
2949 struct i40e_asq_cmd_details *cmd_details)
2950{
2951 struct i40e_aq_desc desc;
2952 struct i40e_aqc_nvm_update *cmd =
2953 (struct i40e_aqc_nvm_update *)&desc.params.raw;
2954 i40e_status status;
2955
2956 /* In offset the highest byte must be zeroed. */
2957 if (offset & 0xFF000000) {
2958 status = I40E_ERR_PARAM;
2959 goto i40e_aq_erase_nvm_exit;
2960 }
2961
2962 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_erase);
2963
2964 /* If this is the last command in a series, set the proper flag. */
2965 if (last_command)
2966 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
2967 cmd->module_pointer = module_pointer;
2968 cmd->offset = cpu_to_le32(offset);
2969 cmd->length = cpu_to_le16(length);
2970
2971 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2972
2973i40e_aq_erase_nvm_exit:
2974 return status;
2975}
2976
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002977/**
2978 * i40e_parse_discover_capabilities
2979 * @hw: pointer to the hw struct
2980 * @buff: pointer to a buffer containing device/function capability records
2981 * @cap_count: number of capability records in the list
2982 * @list_type_opc: type of capabilities list to parse
2983 *
2984 * Parse the device/function capabilities list.
2985 **/
2986static void i40e_parse_discover_capabilities(struct i40e_hw *hw, void *buff,
2987 u32 cap_count,
2988 enum i40e_admin_queue_opc list_type_opc)
2989{
2990 struct i40e_aqc_list_capabilities_element_resp *cap;
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002991 u32 valid_functions, num_functions;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002992 u32 number, logical_id, phys_id;
2993 struct i40e_hw_capabilities *p;
Pawel Orlowskic78b9532015-04-22 19:34:06 -04002994 u8 major_rev;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002995 u32 i = 0;
2996 u16 id;
2997
2998 cap = (struct i40e_aqc_list_capabilities_element_resp *) buff;
2999
3000 if (list_type_opc == i40e_aqc_opc_list_dev_capabilities)
Joe Perchesb58f2f72014-03-25 04:30:32 +00003001 p = &hw->dev_caps;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003002 else if (list_type_opc == i40e_aqc_opc_list_func_capabilities)
Joe Perchesb58f2f72014-03-25 04:30:32 +00003003 p = &hw->func_caps;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003004 else
3005 return;
3006
3007 for (i = 0; i < cap_count; i++, cap++) {
3008 id = le16_to_cpu(cap->id);
3009 number = le32_to_cpu(cap->number);
3010 logical_id = le32_to_cpu(cap->logical_id);
3011 phys_id = le32_to_cpu(cap->phys_id);
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003012 major_rev = cap->major_rev;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003013
3014 switch (id) {
Shannon Nelson406e7342015-12-10 11:38:49 -08003015 case I40E_AQ_CAP_ID_SWITCH_MODE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003016 p->switch_mode = number;
3017 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003018 case I40E_AQ_CAP_ID_MNG_MODE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003019 p->management_mode = number;
3020 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003021 case I40E_AQ_CAP_ID_NPAR_ACTIVE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003022 p->npar_enable = number;
3023 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003024 case I40E_AQ_CAP_ID_OS2BMC_CAP:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003025 p->os2bmc = number;
3026 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003027 case I40E_AQ_CAP_ID_FUNCTIONS_VALID:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003028 p->valid_functions = number;
3029 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003030 case I40E_AQ_CAP_ID_SRIOV:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003031 if (number == 1)
3032 p->sr_iov_1_1 = true;
3033 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003034 case I40E_AQ_CAP_ID_VF:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003035 p->num_vfs = number;
3036 p->vf_base_id = logical_id;
3037 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003038 case I40E_AQ_CAP_ID_VMDQ:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003039 if (number == 1)
3040 p->vmdq = true;
3041 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003042 case I40E_AQ_CAP_ID_8021QBG:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003043 if (number == 1)
3044 p->evb_802_1_qbg = true;
3045 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003046 case I40E_AQ_CAP_ID_8021QBR:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003047 if (number == 1)
3048 p->evb_802_1_qbh = true;
3049 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003050 case I40E_AQ_CAP_ID_VSI:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003051 p->num_vsis = number;
3052 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003053 case I40E_AQ_CAP_ID_DCB:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003054 if (number == 1) {
3055 p->dcb = true;
3056 p->enabled_tcmap = logical_id;
3057 p->maxtc = phys_id;
3058 }
3059 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003060 case I40E_AQ_CAP_ID_FCOE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003061 if (number == 1)
3062 p->fcoe = true;
3063 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003064 case I40E_AQ_CAP_ID_ISCSI:
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00003065 if (number == 1)
3066 p->iscsi = true;
3067 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003068 case I40E_AQ_CAP_ID_RSS:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003069 p->rss = true;
Carolyn Wybornye157ea32014-06-03 23:50:22 +00003070 p->rss_table_size = number;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003071 p->rss_table_entry_width = logical_id;
3072 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003073 case I40E_AQ_CAP_ID_RXQ:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003074 p->num_rx_qp = number;
3075 p->base_queue = phys_id;
3076 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003077 case I40E_AQ_CAP_ID_TXQ:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003078 p->num_tx_qp = number;
3079 p->base_queue = phys_id;
3080 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003081 case I40E_AQ_CAP_ID_MSIX:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003082 p->num_msix_vectors = number;
Deepthi Kavalur453e16e2016-04-01 03:56:01 -07003083 i40e_debug(hw, I40E_DEBUG_INIT,
3084 "HW Capability: MSIX vector count = %d\n",
3085 p->num_msix_vectors);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003086 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003087 case I40E_AQ_CAP_ID_VF_MSIX:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003088 p->num_msix_vectors_vf = number;
3089 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003090 case I40E_AQ_CAP_ID_FLEX10:
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003091 if (major_rev == 1) {
3092 if (number == 1) {
3093 p->flex10_enable = true;
3094 p->flex10_capable = true;
3095 }
3096 } else {
3097 /* Capability revision >= 2 */
3098 if (number & 1)
3099 p->flex10_enable = true;
3100 if (number & 2)
3101 p->flex10_capable = true;
3102 }
3103 p->flex10_mode = logical_id;
3104 p->flex10_status = phys_id;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003105 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003106 case I40E_AQ_CAP_ID_CEM:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003107 if (number == 1)
3108 p->mgmt_cem = true;
3109 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003110 case I40E_AQ_CAP_ID_IWARP:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003111 if (number == 1)
3112 p->iwarp = true;
3113 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003114 case I40E_AQ_CAP_ID_LED:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003115 if (phys_id < I40E_HW_CAP_MAX_GPIO)
3116 p->led[phys_id] = true;
3117 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003118 case I40E_AQ_CAP_ID_SDP:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003119 if (phys_id < I40E_HW_CAP_MAX_GPIO)
3120 p->sdp[phys_id] = true;
3121 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003122 case I40E_AQ_CAP_ID_MDIO:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003123 if (number == 1) {
3124 p->mdio_port_num = phys_id;
3125 p->mdio_port_mode = logical_id;
3126 }
3127 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003128 case I40E_AQ_CAP_ID_1588:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003129 if (number == 1)
3130 p->ieee_1588 = true;
3131 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003132 case I40E_AQ_CAP_ID_FLOW_DIRECTOR:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003133 p->fd = true;
3134 p->fd_filters_guaranteed = number;
3135 p->fd_filters_best_effort = logical_id;
3136 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003137 case I40E_AQ_CAP_ID_WSR_PROT:
Kevin Scott73b23402015-04-07 19:45:38 -04003138 p->wr_csr_prot = (u64)number;
3139 p->wr_csr_prot |= (u64)logical_id << 32;
3140 break;
Michal Kosiarz68a1c5a2016-04-12 08:30:46 -07003141 case I40E_AQ_CAP_ID_NVM_MGMT:
3142 if (number & I40E_NVM_MGMT_SEC_REV_DISABLED)
3143 p->sec_rev_disabled = true;
3144 if (number & I40E_NVM_MGMT_UPDATE_DISABLED)
3145 p->update_disabled = true;
3146 break;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003147 default:
3148 break;
3149 }
3150 }
3151
Vasu Devf18ae102015-04-07 19:45:36 -04003152 if (p->fcoe)
3153 i40e_debug(hw, I40E_DEBUG_ALL, "device is FCoE capable\n");
3154
Vasu Dev566bb852014-04-09 05:59:06 +00003155 /* Software override ensuring FCoE is disabled if npar or mfp
3156 * mode because it is not supported in these modes.
3157 */
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003158 if (p->npar_enable || p->flex10_enable)
Vasu Dev566bb852014-04-09 05:59:06 +00003159 p->fcoe = false;
3160
Shannon Nelson9fee9db2014-12-11 07:06:30 +00003161 /* count the enabled ports (aka the "not disabled" ports) */
3162 hw->num_ports = 0;
3163 for (i = 0; i < 4; i++) {
3164 u32 port_cfg_reg = I40E_PRTGEN_CNF + (4 * i);
3165 u64 port_cfg = 0;
3166
3167 /* use AQ read to get the physical register offset instead
3168 * of the port relative offset
3169 */
3170 i40e_aq_debug_read_register(hw, port_cfg_reg, &port_cfg, NULL);
3171 if (!(port_cfg & I40E_PRTGEN_CNF_PORT_DIS_MASK))
3172 hw->num_ports++;
3173 }
3174
3175 valid_functions = p->valid_functions;
3176 num_functions = 0;
3177 while (valid_functions) {
3178 if (valid_functions & 1)
3179 num_functions++;
3180 valid_functions >>= 1;
3181 }
3182
3183 /* partition id is 1-based, and functions are evenly spread
3184 * across the ports as partitions
3185 */
3186 hw->partition_id = (hw->pf_id / hw->num_ports) + 1;
3187 hw->num_partitions = num_functions / hw->num_ports;
3188
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003189 /* additional HW specific goodies that might
3190 * someday be HW version specific
3191 */
3192 p->rx_buf_chain_len = I40E_MAX_CHAINED_RX_BUFFERS;
3193}
3194
3195/**
3196 * i40e_aq_discover_capabilities
3197 * @hw: pointer to the hw struct
3198 * @buff: a virtual buffer to hold the capabilities
3199 * @buff_size: Size of the virtual buffer
3200 * @data_size: Size of the returned data, or buff size needed if AQ err==ENOMEM
3201 * @list_type_opc: capabilities type to discover - pass in the command opcode
3202 * @cmd_details: pointer to command details structure or NULL
3203 *
3204 * Get the device capabilities descriptions from the firmware
3205 **/
3206i40e_status i40e_aq_discover_capabilities(struct i40e_hw *hw,
3207 void *buff, u16 buff_size, u16 *data_size,
3208 enum i40e_admin_queue_opc list_type_opc,
3209 struct i40e_asq_cmd_details *cmd_details)
3210{
3211 struct i40e_aqc_list_capabilites *cmd;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003212 struct i40e_aq_desc desc;
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08003213 i40e_status status = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003214
3215 cmd = (struct i40e_aqc_list_capabilites *)&desc.params.raw;
3216
3217 if (list_type_opc != i40e_aqc_opc_list_func_capabilities &&
3218 list_type_opc != i40e_aqc_opc_list_dev_capabilities) {
3219 status = I40E_ERR_PARAM;
3220 goto exit;
3221 }
3222
3223 i40e_fill_default_direct_cmd_desc(&desc, list_type_opc);
3224
3225 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3226 if (buff_size > I40E_AQ_LARGE_BUF)
3227 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3228
3229 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3230 *data_size = le16_to_cpu(desc.datalen);
3231
3232 if (status)
3233 goto exit;
3234
3235 i40e_parse_discover_capabilities(hw, buff, le32_to_cpu(cmd->count),
3236 list_type_opc);
3237
3238exit:
3239 return status;
3240}
3241
3242/**
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003243 * i40e_aq_update_nvm
3244 * @hw: pointer to the hw struct
3245 * @module_pointer: module pointer location in words from the NVM beginning
3246 * @offset: byte offset from the module beginning
3247 * @length: length of the section to be written (in bytes from the offset)
3248 * @data: command buffer (size [bytes] = length)
3249 * @last_command: tells if this is the last command in a series
3250 * @cmd_details: pointer to command details structure or NULL
3251 *
3252 * Update the NVM using the admin queue commands
3253 **/
3254i40e_status i40e_aq_update_nvm(struct i40e_hw *hw, u8 module_pointer,
3255 u32 offset, u16 length, void *data,
3256 bool last_command,
3257 struct i40e_asq_cmd_details *cmd_details)
3258{
3259 struct i40e_aq_desc desc;
3260 struct i40e_aqc_nvm_update *cmd =
3261 (struct i40e_aqc_nvm_update *)&desc.params.raw;
3262 i40e_status status;
3263
3264 /* In offset the highest byte must be zeroed. */
3265 if (offset & 0xFF000000) {
3266 status = I40E_ERR_PARAM;
3267 goto i40e_aq_update_nvm_exit;
3268 }
3269
3270 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_update);
3271
3272 /* If this is the last command in a series, set the proper flag. */
3273 if (last_command)
3274 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
3275 cmd->module_pointer = module_pointer;
3276 cmd->offset = cpu_to_le32(offset);
3277 cmd->length = cpu_to_le16(length);
3278
3279 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
3280 if (length > I40E_AQ_LARGE_BUF)
3281 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3282
3283 status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
3284
3285i40e_aq_update_nvm_exit:
3286 return status;
3287}
3288
3289/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003290 * i40e_aq_get_lldp_mib
3291 * @hw: pointer to the hw struct
3292 * @bridge_type: type of bridge requested
3293 * @mib_type: Local, Remote or both Local and Remote MIBs
3294 * @buff: pointer to a user supplied buffer to store the MIB block
3295 * @buff_size: size of the buffer (in bytes)
3296 * @local_len : length of the returned Local LLDP MIB
3297 * @remote_len: length of the returned Remote LLDP MIB
3298 * @cmd_details: pointer to command details structure or NULL
3299 *
3300 * Requests the complete LLDP MIB (entire packet).
3301 **/
3302i40e_status i40e_aq_get_lldp_mib(struct i40e_hw *hw, u8 bridge_type,
3303 u8 mib_type, void *buff, u16 buff_size,
3304 u16 *local_len, u16 *remote_len,
3305 struct i40e_asq_cmd_details *cmd_details)
3306{
3307 struct i40e_aq_desc desc;
3308 struct i40e_aqc_lldp_get_mib *cmd =
3309 (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
3310 struct i40e_aqc_lldp_get_mib *resp =
3311 (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
3312 i40e_status status;
3313
3314 if (buff_size == 0 || !buff)
3315 return I40E_ERR_PARAM;
3316
3317 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_get_mib);
3318 /* Indirect Command */
3319 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3320
3321 cmd->type = mib_type & I40E_AQ_LLDP_MIB_TYPE_MASK;
3322 cmd->type |= ((bridge_type << I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) &
3323 I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
3324
3325 desc.datalen = cpu_to_le16(buff_size);
3326
3327 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3328 if (buff_size > I40E_AQ_LARGE_BUF)
3329 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3330
3331 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3332 if (!status) {
3333 if (local_len != NULL)
3334 *local_len = le16_to_cpu(resp->local_len);
3335 if (remote_len != NULL)
3336 *remote_len = le16_to_cpu(resp->remote_len);
3337 }
3338
3339 return status;
3340}
3341
3342/**
3343 * i40e_aq_cfg_lldp_mib_change_event
3344 * @hw: pointer to the hw struct
3345 * @enable_update: Enable or Disable event posting
3346 * @cmd_details: pointer to command details structure or NULL
3347 *
3348 * Enable or Disable posting of an event on ARQ when LLDP MIB
3349 * associated with the interface changes
3350 **/
3351i40e_status i40e_aq_cfg_lldp_mib_change_event(struct i40e_hw *hw,
3352 bool enable_update,
3353 struct i40e_asq_cmd_details *cmd_details)
3354{
3355 struct i40e_aq_desc desc;
3356 struct i40e_aqc_lldp_update_mib *cmd =
3357 (struct i40e_aqc_lldp_update_mib *)&desc.params.raw;
3358 i40e_status status;
3359
3360 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_update_mib);
3361
3362 if (!enable_update)
3363 cmd->command |= I40E_AQ_LLDP_MIB_UPDATE_DISABLE;
3364
3365 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3366
3367 return status;
3368}
3369
3370/**
3371 * i40e_aq_stop_lldp
3372 * @hw: pointer to the hw struct
3373 * @shutdown_agent: True if LLDP Agent needs to be Shutdown
3374 * @cmd_details: pointer to command details structure or NULL
3375 *
3376 * Stop or Shutdown the embedded LLDP Agent
3377 **/
3378i40e_status i40e_aq_stop_lldp(struct i40e_hw *hw, bool shutdown_agent,
3379 struct i40e_asq_cmd_details *cmd_details)
3380{
3381 struct i40e_aq_desc desc;
3382 struct i40e_aqc_lldp_stop *cmd =
3383 (struct i40e_aqc_lldp_stop *)&desc.params.raw;
3384 i40e_status status;
3385
3386 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_stop);
3387
3388 if (shutdown_agent)
3389 cmd->command |= I40E_AQ_LLDP_AGENT_SHUTDOWN;
3390
3391 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3392
3393 return status;
3394}
3395
3396/**
3397 * i40e_aq_start_lldp
3398 * @hw: pointer to the hw struct
3399 * @cmd_details: pointer to command details structure or NULL
3400 *
3401 * Start the embedded LLDP Agent on all ports.
3402 **/
3403i40e_status i40e_aq_start_lldp(struct i40e_hw *hw,
3404 struct i40e_asq_cmd_details *cmd_details)
3405{
3406 struct i40e_aq_desc desc;
3407 struct i40e_aqc_lldp_start *cmd =
3408 (struct i40e_aqc_lldp_start *)&desc.params.raw;
3409 i40e_status status;
3410
3411 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_start);
3412
3413 cmd->command = I40E_AQ_LLDP_AGENT_START;
3414
3415 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3416
3417 return status;
3418}
3419
3420/**
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00003421 * i40e_aq_get_cee_dcb_config
3422 * @hw: pointer to the hw struct
3423 * @buff: response buffer that stores CEE operational configuration
3424 * @buff_size: size of the buffer passed
3425 * @cmd_details: pointer to command details structure or NULL
3426 *
3427 * Get CEE DCBX mode operational configuration from firmware
3428 **/
3429i40e_status i40e_aq_get_cee_dcb_config(struct i40e_hw *hw,
3430 void *buff, u16 buff_size,
3431 struct i40e_asq_cmd_details *cmd_details)
3432{
3433 struct i40e_aq_desc desc;
3434 i40e_status status;
3435
3436 if (buff_size == 0 || !buff)
3437 return I40E_ERR_PARAM;
3438
3439 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_cee_dcb_cfg);
3440
3441 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3442 status = i40e_asq_send_command(hw, &desc, (void *)buff, buff_size,
3443 cmd_details);
3444
3445 return status;
3446}
3447
3448/**
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003449 * i40e_aq_add_udp_tunnel
3450 * @hw: pointer to the hw struct
3451 * @udp_port: the UDP port to add
3452 * @header_len: length of the tunneling header length in DWords
3453 * @protocol_index: protocol index type
Jeff Kirsher98d44382013-12-21 05:44:42 +00003454 * @filter_index: pointer to filter index
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003455 * @cmd_details: pointer to command details structure or NULL
3456 **/
3457i40e_status i40e_aq_add_udp_tunnel(struct i40e_hw *hw,
Kevin Scottf4f94b92014-04-05 07:46:10 +00003458 u16 udp_port, u8 protocol_index,
3459 u8 *filter_index,
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003460 struct i40e_asq_cmd_details *cmd_details)
3461{
3462 struct i40e_aq_desc desc;
3463 struct i40e_aqc_add_udp_tunnel *cmd =
3464 (struct i40e_aqc_add_udp_tunnel *)&desc.params.raw;
3465 struct i40e_aqc_del_udp_tunnel_completion *resp =
3466 (struct i40e_aqc_del_udp_tunnel_completion *)&desc.params.raw;
3467 i40e_status status;
3468
3469 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_udp_tunnel);
3470
3471 cmd->udp_port = cpu_to_le16(udp_port);
Shannon Nelson981b7542013-12-11 08:17:11 +00003472 cmd->protocol_type = protocol_index;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003473
3474 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3475
Shannon Nelson65d13462015-02-21 06:45:28 +00003476 if (!status && filter_index)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003477 *filter_index = resp->index;
3478
3479 return status;
3480}
3481
3482/**
3483 * i40e_aq_del_udp_tunnel
3484 * @hw: pointer to the hw struct
3485 * @index: filter index
3486 * @cmd_details: pointer to command details structure or NULL
3487 **/
3488i40e_status i40e_aq_del_udp_tunnel(struct i40e_hw *hw, u8 index,
3489 struct i40e_asq_cmd_details *cmd_details)
3490{
3491 struct i40e_aq_desc desc;
3492 struct i40e_aqc_remove_udp_tunnel *cmd =
3493 (struct i40e_aqc_remove_udp_tunnel *)&desc.params.raw;
3494 i40e_status status;
3495
3496 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_del_udp_tunnel);
3497
3498 cmd->index = index;
3499
3500 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3501
3502 return status;
3503}
3504
3505/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003506 * i40e_aq_delete_element - Delete switch element
3507 * @hw: pointer to the hw struct
3508 * @seid: the SEID to delete from the switch
3509 * @cmd_details: pointer to command details structure or NULL
3510 *
3511 * This deletes a switch element from the switch.
3512 **/
3513i40e_status i40e_aq_delete_element(struct i40e_hw *hw, u16 seid,
3514 struct i40e_asq_cmd_details *cmd_details)
3515{
3516 struct i40e_aq_desc desc;
3517 struct i40e_aqc_switch_seid *cmd =
3518 (struct i40e_aqc_switch_seid *)&desc.params.raw;
3519 i40e_status status;
3520
3521 if (seid == 0)
3522 return I40E_ERR_PARAM;
3523
3524 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_delete_element);
3525
3526 cmd->seid = cpu_to_le16(seid);
3527
3528 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3529
3530 return status;
3531}
3532
3533/**
Neerav Parikhafb3ff02014-01-17 15:36:36 -08003534 * i40e_aq_dcb_updated - DCB Updated Command
3535 * @hw: pointer to the hw struct
3536 * @cmd_details: pointer to command details structure or NULL
3537 *
3538 * EMP will return when the shared RPB settings have been
3539 * recomputed and modified. The retval field in the descriptor
3540 * will be set to 0 when RPB is modified.
3541 **/
3542i40e_status i40e_aq_dcb_updated(struct i40e_hw *hw,
3543 struct i40e_asq_cmd_details *cmd_details)
3544{
3545 struct i40e_aq_desc desc;
3546 i40e_status status;
3547
3548 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_dcb_updated);
3549
3550 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3551
3552 return status;
3553}
3554
3555/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003556 * i40e_aq_tx_sched_cmd - generic Tx scheduler AQ command handler
3557 * @hw: pointer to the hw struct
3558 * @seid: seid for the physical port/switching component/vsi
3559 * @buff: Indirect buffer to hold data parameters and response
3560 * @buff_size: Indirect buffer size
3561 * @opcode: Tx scheduler AQ command opcode
3562 * @cmd_details: pointer to command details structure or NULL
3563 *
3564 * Generic command handler for Tx scheduler AQ commands
3565 **/
3566static i40e_status i40e_aq_tx_sched_cmd(struct i40e_hw *hw, u16 seid,
3567 void *buff, u16 buff_size,
3568 enum i40e_admin_queue_opc opcode,
3569 struct i40e_asq_cmd_details *cmd_details)
3570{
3571 struct i40e_aq_desc desc;
3572 struct i40e_aqc_tx_sched_ind *cmd =
3573 (struct i40e_aqc_tx_sched_ind *)&desc.params.raw;
3574 i40e_status status;
3575 bool cmd_param_flag = false;
3576
3577 switch (opcode) {
3578 case i40e_aqc_opc_configure_vsi_ets_sla_bw_limit:
3579 case i40e_aqc_opc_configure_vsi_tc_bw:
3580 case i40e_aqc_opc_enable_switching_comp_ets:
3581 case i40e_aqc_opc_modify_switching_comp_ets:
3582 case i40e_aqc_opc_disable_switching_comp_ets:
3583 case i40e_aqc_opc_configure_switching_comp_ets_bw_limit:
3584 case i40e_aqc_opc_configure_switching_comp_bw_config:
3585 cmd_param_flag = true;
3586 break;
3587 case i40e_aqc_opc_query_vsi_bw_config:
3588 case i40e_aqc_opc_query_vsi_ets_sla_config:
3589 case i40e_aqc_opc_query_switching_comp_ets_config:
3590 case i40e_aqc_opc_query_port_ets_config:
3591 case i40e_aqc_opc_query_switching_comp_bw_config:
3592 cmd_param_flag = false;
3593 break;
3594 default:
3595 return I40E_ERR_PARAM;
3596 }
3597
3598 i40e_fill_default_direct_cmd_desc(&desc, opcode);
3599
3600 /* Indirect command */
3601 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3602 if (cmd_param_flag)
3603 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
3604 if (buff_size > I40E_AQ_LARGE_BUF)
3605 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3606
3607 desc.datalen = cpu_to_le16(buff_size);
3608
3609 cmd->vsi_seid = cpu_to_le16(seid);
3610
3611 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3612
3613 return status;
3614}
3615
3616/**
Mitch Williams6b192892014-03-06 09:02:29 +00003617 * i40e_aq_config_vsi_bw_limit - Configure VSI BW Limit
3618 * @hw: pointer to the hw struct
3619 * @seid: VSI seid
3620 * @credit: BW limit credits (0 = disabled)
3621 * @max_credit: Max BW limit credits
3622 * @cmd_details: pointer to command details structure or NULL
3623 **/
3624i40e_status i40e_aq_config_vsi_bw_limit(struct i40e_hw *hw,
3625 u16 seid, u16 credit, u8 max_credit,
3626 struct i40e_asq_cmd_details *cmd_details)
3627{
3628 struct i40e_aq_desc desc;
3629 struct i40e_aqc_configure_vsi_bw_limit *cmd =
3630 (struct i40e_aqc_configure_vsi_bw_limit *)&desc.params.raw;
3631 i40e_status status;
3632
3633 i40e_fill_default_direct_cmd_desc(&desc,
3634 i40e_aqc_opc_configure_vsi_bw_limit);
3635
3636 cmd->vsi_seid = cpu_to_le16(seid);
3637 cmd->credit = cpu_to_le16(credit);
3638 cmd->max_credit = max_credit;
3639
3640 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3641
3642 return status;
3643}
3644
3645/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003646 * i40e_aq_config_vsi_tc_bw - Config VSI BW Allocation per TC
3647 * @hw: pointer to the hw struct
3648 * @seid: VSI seid
3649 * @bw_data: Buffer holding enabled TCs, relative TC BW limit/credits
3650 * @cmd_details: pointer to command details structure or NULL
3651 **/
3652i40e_status i40e_aq_config_vsi_tc_bw(struct i40e_hw *hw,
3653 u16 seid,
3654 struct i40e_aqc_configure_vsi_tc_bw_data *bw_data,
3655 struct i40e_asq_cmd_details *cmd_details)
3656{
3657 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3658 i40e_aqc_opc_configure_vsi_tc_bw,
3659 cmd_details);
3660}
3661
3662/**
Neerav Parikhafb3ff02014-01-17 15:36:36 -08003663 * i40e_aq_config_switch_comp_ets - Enable/Disable/Modify ETS on the port
3664 * @hw: pointer to the hw struct
3665 * @seid: seid of the switching component connected to Physical Port
3666 * @ets_data: Buffer holding ETS parameters
3667 * @cmd_details: pointer to command details structure or NULL
3668 **/
3669i40e_status i40e_aq_config_switch_comp_ets(struct i40e_hw *hw,
3670 u16 seid,
3671 struct i40e_aqc_configure_switching_comp_ets_data *ets_data,
3672 enum i40e_admin_queue_opc opcode,
3673 struct i40e_asq_cmd_details *cmd_details)
3674{
3675 return i40e_aq_tx_sched_cmd(hw, seid, (void *)ets_data,
3676 sizeof(*ets_data), opcode, cmd_details);
3677}
3678
3679/**
3680 * i40e_aq_config_switch_comp_bw_config - Config Switch comp BW Alloc per TC
3681 * @hw: pointer to the hw struct
3682 * @seid: seid of the switching component
3683 * @bw_data: Buffer holding enabled TCs, relative/absolute TC BW limit/credits
3684 * @cmd_details: pointer to command details structure or NULL
3685 **/
3686i40e_status i40e_aq_config_switch_comp_bw_config(struct i40e_hw *hw,
3687 u16 seid,
3688 struct i40e_aqc_configure_switching_comp_bw_config_data *bw_data,
3689 struct i40e_asq_cmd_details *cmd_details)
3690{
3691 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3692 i40e_aqc_opc_configure_switching_comp_bw_config,
3693 cmd_details);
3694}
3695
3696/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003697 * i40e_aq_query_vsi_bw_config - Query VSI BW configuration
3698 * @hw: pointer to the hw struct
3699 * @seid: seid of the VSI
3700 * @bw_data: Buffer to hold VSI BW configuration
3701 * @cmd_details: pointer to command details structure or NULL
3702 **/
3703i40e_status i40e_aq_query_vsi_bw_config(struct i40e_hw *hw,
3704 u16 seid,
3705 struct i40e_aqc_query_vsi_bw_config_resp *bw_data,
3706 struct i40e_asq_cmd_details *cmd_details)
3707{
3708 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3709 i40e_aqc_opc_query_vsi_bw_config,
3710 cmd_details);
3711}
3712
3713/**
3714 * i40e_aq_query_vsi_ets_sla_config - Query VSI BW configuration per TC
3715 * @hw: pointer to the hw struct
3716 * @seid: seid of the VSI
3717 * @bw_data: Buffer to hold VSI BW configuration per TC
3718 * @cmd_details: pointer to command details structure or NULL
3719 **/
3720i40e_status i40e_aq_query_vsi_ets_sla_config(struct i40e_hw *hw,
3721 u16 seid,
3722 struct i40e_aqc_query_vsi_ets_sla_config_resp *bw_data,
3723 struct i40e_asq_cmd_details *cmd_details)
3724{
3725 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3726 i40e_aqc_opc_query_vsi_ets_sla_config,
3727 cmd_details);
3728}
3729
3730/**
3731 * i40e_aq_query_switch_comp_ets_config - Query Switch comp BW config per TC
3732 * @hw: pointer to the hw struct
3733 * @seid: seid of the switching component
3734 * @bw_data: Buffer to hold switching component's per TC BW config
3735 * @cmd_details: pointer to command details structure or NULL
3736 **/
3737i40e_status i40e_aq_query_switch_comp_ets_config(struct i40e_hw *hw,
3738 u16 seid,
3739 struct i40e_aqc_query_switching_comp_ets_config_resp *bw_data,
3740 struct i40e_asq_cmd_details *cmd_details)
3741{
3742 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3743 i40e_aqc_opc_query_switching_comp_ets_config,
3744 cmd_details);
3745}
3746
3747/**
3748 * i40e_aq_query_port_ets_config - Query Physical Port ETS configuration
3749 * @hw: pointer to the hw struct
3750 * @seid: seid of the VSI or switching component connected to Physical Port
3751 * @bw_data: Buffer to hold current ETS configuration for the Physical Port
3752 * @cmd_details: pointer to command details structure or NULL
3753 **/
3754i40e_status i40e_aq_query_port_ets_config(struct i40e_hw *hw,
3755 u16 seid,
3756 struct i40e_aqc_query_port_ets_config_resp *bw_data,
3757 struct i40e_asq_cmd_details *cmd_details)
3758{
3759 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3760 i40e_aqc_opc_query_port_ets_config,
3761 cmd_details);
3762}
3763
3764/**
3765 * i40e_aq_query_switch_comp_bw_config - Query Switch comp BW configuration
3766 * @hw: pointer to the hw struct
3767 * @seid: seid of the switching component
3768 * @bw_data: Buffer to hold switching component's BW configuration
3769 * @cmd_details: pointer to command details structure or NULL
3770 **/
3771i40e_status i40e_aq_query_switch_comp_bw_config(struct i40e_hw *hw,
3772 u16 seid,
3773 struct i40e_aqc_query_switching_comp_bw_config_resp *bw_data,
3774 struct i40e_asq_cmd_details *cmd_details)
3775{
3776 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3777 i40e_aqc_opc_query_switching_comp_bw_config,
3778 cmd_details);
3779}
3780
3781/**
3782 * i40e_validate_filter_settings
3783 * @hw: pointer to the hardware structure
3784 * @settings: Filter control settings
3785 *
3786 * Check and validate the filter control settings passed.
3787 * The function checks for the valid filter/context sizes being
3788 * passed for FCoE and PE.
3789 *
3790 * Returns 0 if the values passed are valid and within
3791 * range else returns an error.
3792 **/
3793static i40e_status i40e_validate_filter_settings(struct i40e_hw *hw,
3794 struct i40e_filter_control_settings *settings)
3795{
3796 u32 fcoe_cntx_size, fcoe_filt_size;
3797 u32 pe_cntx_size, pe_filt_size;
Anjali Singhai Jain467d7292014-05-10 04:49:02 +00003798 u32 fcoe_fmax;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003799 u32 val;
3800
3801 /* Validate FCoE settings passed */
3802 switch (settings->fcoe_filt_num) {
3803 case I40E_HASH_FILTER_SIZE_1K:
3804 case I40E_HASH_FILTER_SIZE_2K:
3805 case I40E_HASH_FILTER_SIZE_4K:
3806 case I40E_HASH_FILTER_SIZE_8K:
3807 case I40E_HASH_FILTER_SIZE_16K:
3808 case I40E_HASH_FILTER_SIZE_32K:
3809 fcoe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
3810 fcoe_filt_size <<= (u32)settings->fcoe_filt_num;
3811 break;
3812 default:
3813 return I40E_ERR_PARAM;
3814 }
3815
3816 switch (settings->fcoe_cntx_num) {
3817 case I40E_DMA_CNTX_SIZE_512:
3818 case I40E_DMA_CNTX_SIZE_1K:
3819 case I40E_DMA_CNTX_SIZE_2K:
3820 case I40E_DMA_CNTX_SIZE_4K:
3821 fcoe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
3822 fcoe_cntx_size <<= (u32)settings->fcoe_cntx_num;
3823 break;
3824 default:
3825 return I40E_ERR_PARAM;
3826 }
3827
3828 /* Validate PE settings passed */
3829 switch (settings->pe_filt_num) {
3830 case I40E_HASH_FILTER_SIZE_1K:
3831 case I40E_HASH_FILTER_SIZE_2K:
3832 case I40E_HASH_FILTER_SIZE_4K:
3833 case I40E_HASH_FILTER_SIZE_8K:
3834 case I40E_HASH_FILTER_SIZE_16K:
3835 case I40E_HASH_FILTER_SIZE_32K:
3836 case I40E_HASH_FILTER_SIZE_64K:
3837 case I40E_HASH_FILTER_SIZE_128K:
3838 case I40E_HASH_FILTER_SIZE_256K:
3839 case I40E_HASH_FILTER_SIZE_512K:
3840 case I40E_HASH_FILTER_SIZE_1M:
3841 pe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
3842 pe_filt_size <<= (u32)settings->pe_filt_num;
3843 break;
3844 default:
3845 return I40E_ERR_PARAM;
3846 }
3847
3848 switch (settings->pe_cntx_num) {
3849 case I40E_DMA_CNTX_SIZE_512:
3850 case I40E_DMA_CNTX_SIZE_1K:
3851 case I40E_DMA_CNTX_SIZE_2K:
3852 case I40E_DMA_CNTX_SIZE_4K:
3853 case I40E_DMA_CNTX_SIZE_8K:
3854 case I40E_DMA_CNTX_SIZE_16K:
3855 case I40E_DMA_CNTX_SIZE_32K:
3856 case I40E_DMA_CNTX_SIZE_64K:
3857 case I40E_DMA_CNTX_SIZE_128K:
3858 case I40E_DMA_CNTX_SIZE_256K:
3859 pe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
3860 pe_cntx_size <<= (u32)settings->pe_cntx_num;
3861 break;
3862 default:
3863 return I40E_ERR_PARAM;
3864 }
3865
3866 /* FCHSIZE + FCDSIZE should not be greater than PMFCOEFMAX */
3867 val = rd32(hw, I40E_GLHMC_FCOEFMAX);
3868 fcoe_fmax = (val & I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_MASK)
3869 >> I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_SHIFT;
3870 if (fcoe_filt_size + fcoe_cntx_size > fcoe_fmax)
3871 return I40E_ERR_INVALID_SIZE;
3872
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003873 return 0;
3874}
3875
3876/**
3877 * i40e_set_filter_control
3878 * @hw: pointer to the hardware structure
3879 * @settings: Filter control settings
3880 *
3881 * Set the Queue Filters for PE/FCoE and enable filters required
3882 * for a single PF. It is expected that these settings are programmed
3883 * at the driver initialization time.
3884 **/
3885i40e_status i40e_set_filter_control(struct i40e_hw *hw,
3886 struct i40e_filter_control_settings *settings)
3887{
3888 i40e_status ret = 0;
3889 u32 hash_lut_size = 0;
3890 u32 val;
3891
3892 if (!settings)
3893 return I40E_ERR_PARAM;
3894
3895 /* Validate the input settings */
3896 ret = i40e_validate_filter_settings(hw, settings);
3897 if (ret)
3898 return ret;
3899
3900 /* Read the PF Queue Filter control register */
Shannon Nelsonf6581372016-02-17 16:12:20 -08003901 val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003902
3903 /* Program required PE hash buckets for the PF */
3904 val &= ~I40E_PFQF_CTL_0_PEHSIZE_MASK;
3905 val |= ((u32)settings->pe_filt_num << I40E_PFQF_CTL_0_PEHSIZE_SHIFT) &
3906 I40E_PFQF_CTL_0_PEHSIZE_MASK;
3907 /* Program required PE contexts for the PF */
3908 val &= ~I40E_PFQF_CTL_0_PEDSIZE_MASK;
3909 val |= ((u32)settings->pe_cntx_num << I40E_PFQF_CTL_0_PEDSIZE_SHIFT) &
3910 I40E_PFQF_CTL_0_PEDSIZE_MASK;
3911
3912 /* Program required FCoE hash buckets for the PF */
3913 val &= ~I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
3914 val |= ((u32)settings->fcoe_filt_num <<
3915 I40E_PFQF_CTL_0_PFFCHSIZE_SHIFT) &
3916 I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
3917 /* Program required FCoE DDP contexts for the PF */
3918 val &= ~I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
3919 val |= ((u32)settings->fcoe_cntx_num <<
3920 I40E_PFQF_CTL_0_PFFCDSIZE_SHIFT) &
3921 I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
3922
3923 /* Program Hash LUT size for the PF */
3924 val &= ~I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
3925 if (settings->hash_lut_size == I40E_HASH_LUT_SIZE_512)
3926 hash_lut_size = 1;
3927 val |= (hash_lut_size << I40E_PFQF_CTL_0_HASHLUTSIZE_SHIFT) &
3928 I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
3929
3930 /* Enable FDIR, Ethertype and MACVLAN filters for PF and VFs */
3931 if (settings->enable_fdir)
3932 val |= I40E_PFQF_CTL_0_FD_ENA_MASK;
3933 if (settings->enable_ethtype)
3934 val |= I40E_PFQF_CTL_0_ETYPE_ENA_MASK;
3935 if (settings->enable_macvlan)
3936 val |= I40E_PFQF_CTL_0_MACVLAN_ENA_MASK;
3937
Shannon Nelsonf6581372016-02-17 16:12:20 -08003938 i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, val);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003939
3940 return 0;
3941}
Neerav Parikhafb3ff02014-01-17 15:36:36 -08003942
3943/**
3944 * i40e_aq_add_rem_control_packet_filter - Add or Remove Control Packet Filter
3945 * @hw: pointer to the hw struct
3946 * @mac_addr: MAC address to use in the filter
3947 * @ethtype: Ethertype to use in the filter
3948 * @flags: Flags that needs to be applied to the filter
3949 * @vsi_seid: seid of the control VSI
3950 * @queue: VSI queue number to send the packet to
3951 * @is_add: Add control packet filter if True else remove
3952 * @stats: Structure to hold information on control filter counts
3953 * @cmd_details: pointer to command details structure or NULL
3954 *
3955 * This command will Add or Remove control packet filter for a control VSI.
3956 * In return it will update the total number of perfect filter count in
3957 * the stats member.
3958 **/
3959i40e_status i40e_aq_add_rem_control_packet_filter(struct i40e_hw *hw,
3960 u8 *mac_addr, u16 ethtype, u16 flags,
3961 u16 vsi_seid, u16 queue, bool is_add,
3962 struct i40e_control_filter_stats *stats,
3963 struct i40e_asq_cmd_details *cmd_details)
3964{
3965 struct i40e_aq_desc desc;
3966 struct i40e_aqc_add_remove_control_packet_filter *cmd =
3967 (struct i40e_aqc_add_remove_control_packet_filter *)
3968 &desc.params.raw;
3969 struct i40e_aqc_add_remove_control_packet_filter_completion *resp =
3970 (struct i40e_aqc_add_remove_control_packet_filter_completion *)
3971 &desc.params.raw;
3972 i40e_status status;
3973
3974 if (vsi_seid == 0)
3975 return I40E_ERR_PARAM;
3976
3977 if (is_add) {
3978 i40e_fill_default_direct_cmd_desc(&desc,
3979 i40e_aqc_opc_add_control_packet_filter);
3980 cmd->queue = cpu_to_le16(queue);
3981 } else {
3982 i40e_fill_default_direct_cmd_desc(&desc,
3983 i40e_aqc_opc_remove_control_packet_filter);
3984 }
3985
3986 if (mac_addr)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04003987 ether_addr_copy(cmd->mac, mac_addr);
Neerav Parikhafb3ff02014-01-17 15:36:36 -08003988
3989 cmd->etype = cpu_to_le16(ethtype);
3990 cmd->flags = cpu_to_le16(flags);
3991 cmd->seid = cpu_to_le16(vsi_seid);
3992
3993 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3994
3995 if (!status && stats) {
3996 stats->mac_etype_used = le16_to_cpu(resp->mac_etype_used);
3997 stats->etype_used = le16_to_cpu(resp->etype_used);
3998 stats->mac_etype_free = le16_to_cpu(resp->mac_etype_free);
3999 stats->etype_free = le16_to_cpu(resp->etype_free);
4000 }
4001
4002 return status;
4003}
4004
Catherine Sullivand4dfb812013-11-28 06:39:21 +00004005/**
Anjali Singhai Jaine7358f52015-10-01 14:37:34 -04004006 * i40e_add_filter_to_drop_tx_flow_control_frames- filter to drop flow control
4007 * @hw: pointer to the hw struct
4008 * @seid: VSI seid to add ethertype filter from
4009 **/
4010#define I40E_FLOW_CONTROL_ETHTYPE 0x8808
4011void i40e_add_filter_to_drop_tx_flow_control_frames(struct i40e_hw *hw,
4012 u16 seid)
4013{
4014 u16 flag = I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC |
4015 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP |
4016 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX;
4017 u16 ethtype = I40E_FLOW_CONTROL_ETHTYPE;
4018 i40e_status status;
4019
4020 status = i40e_aq_add_rem_control_packet_filter(hw, NULL, ethtype, flag,
4021 seid, 0, true, NULL,
4022 NULL);
4023 if (status)
4024 hw_dbg(hw, "Ethtype Filter Add failed: Error pruning Tx flow control frames\n");
4025}
4026
4027/**
Greg Rosef4492db2015-02-06 08:52:12 +00004028 * i40e_aq_alternate_read
4029 * @hw: pointer to the hardware structure
4030 * @reg_addr0: address of first dword to be read
4031 * @reg_val0: pointer for data read from 'reg_addr0'
4032 * @reg_addr1: address of second dword to be read
4033 * @reg_val1: pointer for data read from 'reg_addr1'
4034 *
4035 * Read one or two dwords from alternate structure. Fields are indicated
4036 * by 'reg_addr0' and 'reg_addr1' register numbers. If 'reg_val1' pointer
4037 * is not passed then only register at 'reg_addr0' is read.
4038 *
4039 **/
Shannon Nelson37a29732015-02-27 09:15:19 +00004040static i40e_status i40e_aq_alternate_read(struct i40e_hw *hw,
4041 u32 reg_addr0, u32 *reg_val0,
4042 u32 reg_addr1, u32 *reg_val1)
Greg Rosef4492db2015-02-06 08:52:12 +00004043{
4044 struct i40e_aq_desc desc;
4045 struct i40e_aqc_alternate_write *cmd_resp =
4046 (struct i40e_aqc_alternate_write *)&desc.params.raw;
4047 i40e_status status;
4048
4049 if (!reg_val0)
4050 return I40E_ERR_PARAM;
4051
4052 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_alternate_read);
4053 cmd_resp->address0 = cpu_to_le32(reg_addr0);
4054 cmd_resp->address1 = cpu_to_le32(reg_addr1);
4055
4056 status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
4057
4058 if (!status) {
4059 *reg_val0 = le32_to_cpu(cmd_resp->data0);
4060
4061 if (reg_val1)
4062 *reg_val1 = le32_to_cpu(cmd_resp->data1);
4063 }
4064
4065 return status;
4066}
4067
4068/**
Neerav Parikh2fd75f32014-11-12 00:18:20 +00004069 * i40e_aq_resume_port_tx
4070 * @hw: pointer to the hardware structure
4071 * @cmd_details: pointer to command details structure or NULL
4072 *
4073 * Resume port's Tx traffic
4074 **/
4075i40e_status i40e_aq_resume_port_tx(struct i40e_hw *hw,
4076 struct i40e_asq_cmd_details *cmd_details)
4077{
4078 struct i40e_aq_desc desc;
4079 i40e_status status;
4080
4081 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_resume_port_tx);
4082
4083 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4084
4085 return status;
4086}
4087
4088/**
Catherine Sullivand4dfb812013-11-28 06:39:21 +00004089 * i40e_set_pci_config_data - store PCI bus info
4090 * @hw: pointer to hardware structure
4091 * @link_status: the link status word from PCI config space
4092 *
4093 * Stores the PCI bus info (speed, width, type) within the i40e_hw structure
4094 **/
4095void i40e_set_pci_config_data(struct i40e_hw *hw, u16 link_status)
4096{
4097 hw->bus.type = i40e_bus_type_pci_express;
4098
4099 switch (link_status & PCI_EXP_LNKSTA_NLW) {
4100 case PCI_EXP_LNKSTA_NLW_X1:
4101 hw->bus.width = i40e_bus_width_pcie_x1;
4102 break;
4103 case PCI_EXP_LNKSTA_NLW_X2:
4104 hw->bus.width = i40e_bus_width_pcie_x2;
4105 break;
4106 case PCI_EXP_LNKSTA_NLW_X4:
4107 hw->bus.width = i40e_bus_width_pcie_x4;
4108 break;
4109 case PCI_EXP_LNKSTA_NLW_X8:
4110 hw->bus.width = i40e_bus_width_pcie_x8;
4111 break;
4112 default:
4113 hw->bus.width = i40e_bus_width_unknown;
4114 break;
4115 }
4116
4117 switch (link_status & PCI_EXP_LNKSTA_CLS) {
4118 case PCI_EXP_LNKSTA_CLS_2_5GB:
4119 hw->bus.speed = i40e_bus_speed_2500;
4120 break;
4121 case PCI_EXP_LNKSTA_CLS_5_0GB:
4122 hw->bus.speed = i40e_bus_speed_5000;
4123 break;
4124 case PCI_EXP_LNKSTA_CLS_8_0GB:
4125 hw->bus.speed = i40e_bus_speed_8000;
4126 break;
4127 default:
4128 hw->bus.speed = i40e_bus_speed_unknown;
4129 break;
4130 }
4131}
Greg Rosef4492db2015-02-06 08:52:12 +00004132
4133/**
Jesse Brandeburg3169c322015-04-07 19:45:37 -04004134 * i40e_aq_debug_dump
4135 * @hw: pointer to the hardware structure
4136 * @cluster_id: specific cluster to dump
4137 * @table_id: table id within cluster
4138 * @start_index: index of line in the block to read
4139 * @buff_size: dump buffer size
4140 * @buff: dump buffer
4141 * @ret_buff_size: actual buffer size returned
4142 * @ret_next_table: next block to read
4143 * @ret_next_index: next index to read
4144 *
4145 * Dump internal FW/HW data for debug purposes.
4146 *
4147 **/
4148i40e_status i40e_aq_debug_dump(struct i40e_hw *hw, u8 cluster_id,
4149 u8 table_id, u32 start_index, u16 buff_size,
4150 void *buff, u16 *ret_buff_size,
4151 u8 *ret_next_table, u32 *ret_next_index,
4152 struct i40e_asq_cmd_details *cmd_details)
4153{
4154 struct i40e_aq_desc desc;
4155 struct i40e_aqc_debug_dump_internals *cmd =
4156 (struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
4157 struct i40e_aqc_debug_dump_internals *resp =
4158 (struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
4159 i40e_status status;
4160
4161 if (buff_size == 0 || !buff)
4162 return I40E_ERR_PARAM;
4163
4164 i40e_fill_default_direct_cmd_desc(&desc,
4165 i40e_aqc_opc_debug_dump_internals);
4166 /* Indirect Command */
4167 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
4168 if (buff_size > I40E_AQ_LARGE_BUF)
4169 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
4170
4171 cmd->cluster_id = cluster_id;
4172 cmd->table_id = table_id;
4173 cmd->idx = cpu_to_le32(start_index);
4174
4175 desc.datalen = cpu_to_le16(buff_size);
4176
4177 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
4178 if (!status) {
4179 if (ret_buff_size)
4180 *ret_buff_size = le16_to_cpu(desc.datalen);
4181 if (ret_next_table)
4182 *ret_next_table = resp->table_id;
4183 if (ret_next_index)
4184 *ret_next_index = le32_to_cpu(resp->idx);
4185 }
4186
4187 return status;
4188}
4189
4190/**
Greg Rosef4492db2015-02-06 08:52:12 +00004191 * i40e_read_bw_from_alt_ram
4192 * @hw: pointer to the hardware structure
4193 * @max_bw: pointer for max_bw read
4194 * @min_bw: pointer for min_bw read
4195 * @min_valid: pointer for bool that is true if min_bw is a valid value
4196 * @max_valid: pointer for bool that is true if max_bw is a valid value
4197 *
4198 * Read bw from the alternate ram for the given pf
4199 **/
4200i40e_status i40e_read_bw_from_alt_ram(struct i40e_hw *hw,
4201 u32 *max_bw, u32 *min_bw,
4202 bool *min_valid, bool *max_valid)
4203{
4204 i40e_status status;
4205 u32 max_bw_addr, min_bw_addr;
4206
4207 /* Calculate the address of the min/max bw registers */
4208 max_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
4209 I40E_ALT_STRUCT_MAX_BW_OFFSET +
4210 (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
4211 min_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
4212 I40E_ALT_STRUCT_MIN_BW_OFFSET +
4213 (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
4214
4215 /* Read the bandwidths from alt ram */
4216 status = i40e_aq_alternate_read(hw, max_bw_addr, max_bw,
4217 min_bw_addr, min_bw);
4218
4219 if (*min_bw & I40E_ALT_BW_VALID_MASK)
4220 *min_valid = true;
4221 else
4222 *min_valid = false;
4223
4224 if (*max_bw & I40E_ALT_BW_VALID_MASK)
4225 *max_valid = true;
4226 else
4227 *max_valid = false;
4228
4229 return status;
4230}
4231
4232/**
4233 * i40e_aq_configure_partition_bw
4234 * @hw: pointer to the hardware structure
4235 * @bw_data: Buffer holding valid pfs and bw limits
4236 * @cmd_details: pointer to command details
4237 *
4238 * Configure partitions guaranteed/max bw
4239 **/
4240i40e_status i40e_aq_configure_partition_bw(struct i40e_hw *hw,
4241 struct i40e_aqc_configure_partition_bw_data *bw_data,
4242 struct i40e_asq_cmd_details *cmd_details)
4243{
4244 i40e_status status;
4245 struct i40e_aq_desc desc;
4246 u16 bwd_size = sizeof(*bw_data);
4247
4248 i40e_fill_default_direct_cmd_desc(&desc,
4249 i40e_aqc_opc_configure_partition_bw);
4250
4251 /* Indirect command */
4252 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
4253 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
4254
4255 if (bwd_size > I40E_AQ_LARGE_BUF)
4256 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
4257
4258 desc.datalen = cpu_to_le16(bwd_size);
4259
4260 status = i40e_asq_send_command(hw, &desc, bw_data, bwd_size,
4261 cmd_details);
4262
4263 return status;
4264}
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004265
4266/**
4267 * i40e_read_phy_register
4268 * @hw: pointer to the HW structure
4269 * @page: registers page number
4270 * @reg: register address in the page
4271 * @phy_adr: PHY address on MDIO interface
4272 * @value: PHY register value
4273 *
4274 * Reads specified PHY register value
4275 **/
4276i40e_status i40e_read_phy_register(struct i40e_hw *hw,
4277 u8 page, u16 reg, u8 phy_addr,
4278 u16 *value)
4279{
4280 i40e_status status = I40E_ERR_TIMEOUT;
4281 u32 command = 0;
4282 u16 retry = 1000;
4283 u8 port_num = hw->func_caps.mdio_port_num;
4284
4285 command = (reg << I40E_GLGEN_MSCA_MDIADD_SHIFT) |
4286 (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4287 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
4288 (I40E_MDIO_OPCODE_ADDRESS) |
4289 (I40E_MDIO_STCODE) |
4290 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4291 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4292 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4293 do {
4294 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4295 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4296 status = 0;
4297 break;
4298 }
4299 usleep_range(10, 20);
4300 retry--;
4301 } while (retry);
4302
4303 if (status) {
4304 i40e_debug(hw, I40E_DEBUG_PHY,
4305 "PHY: Can't write command to external PHY.\n");
4306 goto phy_read_end;
4307 }
4308
4309 command = (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4310 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
4311 (I40E_MDIO_OPCODE_READ) |
4312 (I40E_MDIO_STCODE) |
4313 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4314 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4315 status = I40E_ERR_TIMEOUT;
4316 retry = 1000;
4317 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4318 do {
4319 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4320 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4321 status = 0;
4322 break;
4323 }
4324 usleep_range(10, 20);
4325 retry--;
4326 } while (retry);
4327
4328 if (!status) {
4329 command = rd32(hw, I40E_GLGEN_MSRWD(port_num));
4330 *value = (command & I40E_GLGEN_MSRWD_MDIRDDATA_MASK) >>
4331 I40E_GLGEN_MSRWD_MDIRDDATA_SHIFT;
4332 } else {
4333 i40e_debug(hw, I40E_DEBUG_PHY,
4334 "PHY: Can't read register value from external PHY.\n");
4335 }
4336
4337phy_read_end:
4338 return status;
4339}
4340
4341/**
4342 * i40e_write_phy_register
4343 * @hw: pointer to the HW structure
4344 * @page: registers page number
4345 * @reg: register address in the page
4346 * @phy_adr: PHY address on MDIO interface
4347 * @value: PHY register value
4348 *
4349 * Writes value to specified PHY register
4350 **/
4351i40e_status i40e_write_phy_register(struct i40e_hw *hw,
4352 u8 page, u16 reg, u8 phy_addr,
4353 u16 value)
4354{
4355 i40e_status status = I40E_ERR_TIMEOUT;
4356 u32 command = 0;
4357 u16 retry = 1000;
4358 u8 port_num = hw->func_caps.mdio_port_num;
4359
4360 command = (reg << I40E_GLGEN_MSCA_MDIADD_SHIFT) |
4361 (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4362 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
4363 (I40E_MDIO_OPCODE_ADDRESS) |
4364 (I40E_MDIO_STCODE) |
4365 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4366 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4367 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4368 do {
4369 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4370 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4371 status = 0;
4372 break;
4373 }
4374 usleep_range(10, 20);
4375 retry--;
4376 } while (retry);
4377 if (status) {
4378 i40e_debug(hw, I40E_DEBUG_PHY,
4379 "PHY: Can't write command to external PHY.\n");
4380 goto phy_write_end;
4381 }
4382
4383 command = value << I40E_GLGEN_MSRWD_MDIWRDATA_SHIFT;
4384 wr32(hw, I40E_GLGEN_MSRWD(port_num), command);
4385
4386 command = (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4387 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
4388 (I40E_MDIO_OPCODE_WRITE) |
4389 (I40E_MDIO_STCODE) |
4390 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4391 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4392 status = I40E_ERR_TIMEOUT;
4393 retry = 1000;
4394 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4395 do {
4396 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4397 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4398 status = 0;
4399 break;
4400 }
4401 usleep_range(10, 20);
4402 retry--;
4403 } while (retry);
4404
4405phy_write_end:
4406 return status;
4407}
4408
4409/**
4410 * i40e_get_phy_address
4411 * @hw: pointer to the HW structure
4412 * @dev_num: PHY port num that address we want
4413 * @phy_addr: Returned PHY address
4414 *
4415 * Gets PHY address for current port
4416 **/
4417u8 i40e_get_phy_address(struct i40e_hw *hw, u8 dev_num)
4418{
4419 u8 port_num = hw->func_caps.mdio_port_num;
4420 u32 reg_val = rd32(hw, I40E_GLGEN_MDIO_I2C_SEL(port_num));
4421
4422 return (u8)(reg_val >> ((dev_num + 1) * 5)) & 0x1f;
4423}
4424
4425/**
4426 * i40e_blink_phy_led
4427 * @hw: pointer to the HW structure
4428 * @time: time how long led will blinks in secs
4429 * @interval: gap between LED on and off in msecs
4430 *
4431 * Blinks PHY link LED
4432 **/
4433i40e_status i40e_blink_phy_link_led(struct i40e_hw *hw,
4434 u32 time, u32 interval)
4435{
4436 i40e_status status = 0;
4437 u32 i;
4438 u16 led_ctl;
4439 u16 gpio_led_port;
4440 u16 led_reg;
4441 u16 led_addr = I40E_PHY_LED_PROV_REG_1;
4442 u8 phy_addr = 0;
4443 u8 port_num;
4444
4445 i = rd32(hw, I40E_PFGEN_PORTNUM);
4446 port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
4447 phy_addr = i40e_get_phy_address(hw, port_num);
4448
4449 for (gpio_led_port = 0; gpio_led_port < 3; gpio_led_port++,
4450 led_addr++) {
4451 status = i40e_read_phy_register(hw, I40E_PHY_COM_REG_PAGE,
4452 led_addr, phy_addr, &led_reg);
4453 if (status)
4454 goto phy_blinking_end;
4455 led_ctl = led_reg;
4456 if (led_reg & I40E_PHY_LED_LINK_MODE_MASK) {
4457 led_reg = 0;
4458 status = i40e_write_phy_register(hw,
4459 I40E_PHY_COM_REG_PAGE,
4460 led_addr, phy_addr,
4461 led_reg);
4462 if (status)
4463 goto phy_blinking_end;
4464 break;
4465 }
4466 }
4467
4468 if (time > 0 && interval > 0) {
4469 for (i = 0; i < time * 1000; i += interval) {
4470 status = i40e_read_phy_register(hw,
4471 I40E_PHY_COM_REG_PAGE,
4472 led_addr, phy_addr,
4473 &led_reg);
4474 if (status)
4475 goto restore_config;
4476 if (led_reg & I40E_PHY_LED_MANUAL_ON)
4477 led_reg = 0;
4478 else
4479 led_reg = I40E_PHY_LED_MANUAL_ON;
4480 status = i40e_write_phy_register(hw,
4481 I40E_PHY_COM_REG_PAGE,
4482 led_addr, phy_addr,
4483 led_reg);
4484 if (status)
4485 goto restore_config;
4486 msleep(interval);
4487 }
4488 }
4489
4490restore_config:
4491 status = i40e_write_phy_register(hw, I40E_PHY_COM_REG_PAGE, led_addr,
4492 phy_addr, led_ctl);
4493
4494phy_blinking_end:
4495 return status;
4496}
4497
4498/**
4499 * i40e_led_get_phy - return current on/off mode
4500 * @hw: pointer to the hw struct
4501 * @led_addr: address of led register to use
4502 * @val: original value of register to use
4503 *
4504 **/
4505i40e_status i40e_led_get_phy(struct i40e_hw *hw, u16 *led_addr,
4506 u16 *val)
4507{
4508 i40e_status status = 0;
4509 u16 gpio_led_port;
4510 u8 phy_addr = 0;
4511 u16 reg_val;
4512 u16 temp_addr;
4513 u8 port_num;
4514 u32 i;
4515
4516 temp_addr = I40E_PHY_LED_PROV_REG_1;
4517 i = rd32(hw, I40E_PFGEN_PORTNUM);
4518 port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
4519 phy_addr = i40e_get_phy_address(hw, port_num);
4520
4521 for (gpio_led_port = 0; gpio_led_port < 3; gpio_led_port++,
4522 temp_addr++) {
4523 status = i40e_read_phy_register(hw, I40E_PHY_COM_REG_PAGE,
4524 temp_addr, phy_addr, &reg_val);
4525 if (status)
4526 return status;
4527 *val = reg_val;
4528 if (reg_val & I40E_PHY_LED_LINK_MODE_MASK) {
4529 *led_addr = temp_addr;
4530 break;
4531 }
4532 }
4533 return status;
4534}
4535
4536/**
4537 * i40e_led_set_phy
4538 * @hw: pointer to the HW structure
4539 * @on: true or false
4540 * @mode: original val plus bit for set or ignore
4541 * Set led's on or off when controlled by the PHY
4542 *
4543 **/
4544i40e_status i40e_led_set_phy(struct i40e_hw *hw, bool on,
4545 u16 led_addr, u32 mode)
4546{
4547 i40e_status status = 0;
4548 u16 led_ctl = 0;
4549 u16 led_reg = 0;
4550 u8 phy_addr = 0;
4551 u8 port_num;
4552 u32 i;
4553
4554 i = rd32(hw, I40E_PFGEN_PORTNUM);
4555 port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
4556 phy_addr = i40e_get_phy_address(hw, port_num);
4557
4558 status = i40e_read_phy_register(hw, I40E_PHY_COM_REG_PAGE, led_addr,
4559 phy_addr, &led_reg);
4560 if (status)
4561 return status;
4562 led_ctl = led_reg;
4563 if (led_reg & I40E_PHY_LED_LINK_MODE_MASK) {
4564 led_reg = 0;
4565 status = i40e_write_phy_register(hw, I40E_PHY_COM_REG_PAGE,
4566 led_addr, phy_addr, led_reg);
4567 if (status)
4568 return status;
4569 }
4570 status = i40e_read_phy_register(hw, I40E_PHY_COM_REG_PAGE,
4571 led_addr, phy_addr, &led_reg);
4572 if (status)
4573 goto restore_config;
4574 if (on)
4575 led_reg = I40E_PHY_LED_MANUAL_ON;
4576 else
4577 led_reg = 0;
4578 status = i40e_write_phy_register(hw, I40E_PHY_COM_REG_PAGE,
4579 led_addr, phy_addr, led_reg);
4580 if (status)
4581 goto restore_config;
4582 if (mode & I40E_PHY_LED_MODE_ORIG) {
4583 led_ctl = (mode & I40E_PHY_LED_MODE_MASK);
4584 status = i40e_write_phy_register(hw,
4585 I40E_PHY_COM_REG_PAGE,
4586 led_addr, phy_addr, led_ctl);
4587 }
4588 return status;
4589restore_config:
4590 status = i40e_write_phy_register(hw, I40E_PHY_COM_REG_PAGE, led_addr,
4591 phy_addr, led_ctl);
4592 return status;
4593}
Shannon Nelsonf6581372016-02-17 16:12:20 -08004594
4595/**
4596 * i40e_aq_rx_ctl_read_register - use FW to read from an Rx control register
4597 * @hw: pointer to the hw struct
4598 * @reg_addr: register address
4599 * @reg_val: ptr to register value
4600 * @cmd_details: pointer to command details structure or NULL
4601 *
4602 * Use the firmware to read the Rx control register,
4603 * especially useful if the Rx unit is under heavy pressure
4604 **/
4605i40e_status i40e_aq_rx_ctl_read_register(struct i40e_hw *hw,
4606 u32 reg_addr, u32 *reg_val,
4607 struct i40e_asq_cmd_details *cmd_details)
4608{
4609 struct i40e_aq_desc desc;
4610 struct i40e_aqc_rx_ctl_reg_read_write *cmd_resp =
4611 (struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
4612 i40e_status status;
4613
4614 if (!reg_val)
4615 return I40E_ERR_PARAM;
4616
4617 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_rx_ctl_reg_read);
4618
4619 cmd_resp->address = cpu_to_le32(reg_addr);
4620
4621 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4622
4623 if (status == 0)
4624 *reg_val = le32_to_cpu(cmd_resp->value);
4625
4626 return status;
4627}
4628
4629/**
4630 * i40e_read_rx_ctl - read from an Rx control register
4631 * @hw: pointer to the hw struct
4632 * @reg_addr: register address
4633 **/
4634u32 i40e_read_rx_ctl(struct i40e_hw *hw, u32 reg_addr)
4635{
4636 i40e_status status = 0;
4637 bool use_register;
4638 int retry = 5;
4639 u32 val = 0;
4640
4641 use_register = (hw->aq.api_maj_ver == 1) && (hw->aq.api_min_ver < 5);
4642 if (!use_register) {
4643do_retry:
4644 status = i40e_aq_rx_ctl_read_register(hw, reg_addr, &val, NULL);
4645 if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
4646 usleep_range(1000, 2000);
4647 retry--;
4648 goto do_retry;
4649 }
4650 }
4651
4652 /* if the AQ access failed, try the old-fashioned way */
4653 if (status || use_register)
4654 val = rd32(hw, reg_addr);
4655
4656 return val;
4657}
4658
4659/**
4660 * i40e_aq_rx_ctl_write_register
4661 * @hw: pointer to the hw struct
4662 * @reg_addr: register address
4663 * @reg_val: register value
4664 * @cmd_details: pointer to command details structure or NULL
4665 *
4666 * Use the firmware to write to an Rx control register,
4667 * especially useful if the Rx unit is under heavy pressure
4668 **/
4669i40e_status i40e_aq_rx_ctl_write_register(struct i40e_hw *hw,
4670 u32 reg_addr, u32 reg_val,
4671 struct i40e_asq_cmd_details *cmd_details)
4672{
4673 struct i40e_aq_desc desc;
4674 struct i40e_aqc_rx_ctl_reg_read_write *cmd =
4675 (struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
4676 i40e_status status;
4677
4678 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_rx_ctl_reg_write);
4679
4680 cmd->address = cpu_to_le32(reg_addr);
4681 cmd->value = cpu_to_le32(reg_val);
4682
4683 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4684
4685 return status;
4686}
4687
4688/**
4689 * i40e_write_rx_ctl - write to an Rx control register
4690 * @hw: pointer to the hw struct
4691 * @reg_addr: register address
4692 * @reg_val: register value
4693 **/
4694void i40e_write_rx_ctl(struct i40e_hw *hw, u32 reg_addr, u32 reg_val)
4695{
4696 i40e_status status = 0;
4697 bool use_register;
4698 int retry = 5;
4699
4700 use_register = (hw->aq.api_maj_ver == 1) && (hw->aq.api_min_ver < 5);
4701 if (!use_register) {
4702do_retry:
4703 status = i40e_aq_rx_ctl_write_register(hw, reg_addr,
4704 reg_val, NULL);
4705 if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
4706 usleep_range(1000, 2000);
4707 retry--;
4708 goto do_retry;
4709 }
4710 }
4711
4712 /* if the AQ access failed, try the old-fashioned way */
4713 if (status || use_register)
4714 wr32(hw, reg_addr, reg_val);
4715}