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