blob: eb2d1530d3316db8e0364fe9645e24f9604eb05a [file] [log] [blame]
Jeff Kirsherae06c702018-03-22 10:08:48 -07001// SPDX-License-Identifier: GPL-2.0
Jeff Kirsher51dce242018-04-26 08:08:09 -07002/* Copyright(c) 2013 - 2018 Intel Corporation. */
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003
4#include "i40e_type.h"
5#include "i40e_adminq.h"
6#include "i40e_prototype.h"
Jesse Brandeburg55cdfd42017-05-11 11:23:10 -07007#include <linux/avf/virtchnl.h>
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00008
9/**
10 * i40e_set_mac_type - Sets MAC type
11 * @hw: pointer to the HW structure
12 *
13 * This function sets the mac type of the adapter based on the
14 * vendor ID and device ID stored in the hw structure.
15 **/
16static i40e_status i40e_set_mac_type(struct i40e_hw *hw)
17{
18 i40e_status status = 0;
19
20 if (hw->vendor_id == PCI_VENDOR_ID_INTEL) {
21 switch (hw->device_id) {
Shannon Nelsonab600852014-01-17 15:36:39 -080022 case I40E_DEV_ID_SFP_XL710:
Shannon Nelsonab600852014-01-17 15:36:39 -080023 case I40E_DEV_ID_QEMU:
Shannon Nelsonab600852014-01-17 15:36:39 -080024 case I40E_DEV_ID_KX_B:
25 case I40E_DEV_ID_KX_C:
Shannon Nelsonab600852014-01-17 15:36:39 -080026 case I40E_DEV_ID_QSFP_A:
27 case I40E_DEV_ID_QSFP_B:
28 case I40E_DEV_ID_QSFP_C:
Mitch Williams5960d332014-09-13 07:40:47 +000029 case I40E_DEV_ID_10G_BASE_T:
Shannon Nelsonbc5166b92015-08-26 15:14:10 -040030 case I40E_DEV_ID_10G_BASE_T4:
Jesse Brandeburgae24b402015-03-27 00:12:09 -070031 case I40E_DEV_ID_20G_KR2:
Shannon Nelson48a3b512015-07-23 16:54:39 -040032 case I40E_DEV_ID_20G_KR2_A:
Carolyn Wyborny31232372016-11-21 13:03:48 -080033 case I40E_DEV_ID_25G_B:
34 case I40E_DEV_ID_25G_SFP28:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +000035 hw->mac.type = I40E_MAC_XL710;
36 break;
Anjali Singhai Jain35dae512015-12-22 14:25:03 -080037 case I40E_DEV_ID_KX_X722:
38 case I40E_DEV_ID_QSFP_X722:
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -040039 case I40E_DEV_ID_SFP_X722:
40 case I40E_DEV_ID_1G_BASE_T_X722:
41 case I40E_DEV_ID_10G_BASE_T_X722:
Catherine Sullivand6bf58c2016-03-18 12:18:08 -070042 case I40E_DEV_ID_SFP_I_X722:
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -040043 hw->mac.type = I40E_MAC_X722;
44 break;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +000045 default:
46 hw->mac.type = I40E_MAC_GENERIC;
47 break;
48 }
49 } else {
50 status = I40E_ERR_DEVICE_NOT_SUPPORTED;
51 }
52
53 hw_dbg(hw, "i40e_set_mac_type found mac: %d, returns: %d\n",
54 hw->mac.type, status);
55 return status;
56}
57
58/**
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040059 * i40e_aq_str - convert AQ err code to a string
60 * @hw: pointer to the HW structure
61 * @aq_err: the AQ error code to convert
62 **/
Jingjing Wu4e68adfe2015-09-28 14:12:31 -040063const char *i40e_aq_str(struct i40e_hw *hw, enum i40e_admin_queue_err aq_err)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040064{
65 switch (aq_err) {
66 case I40E_AQ_RC_OK:
67 return "OK";
68 case I40E_AQ_RC_EPERM:
69 return "I40E_AQ_RC_EPERM";
70 case I40E_AQ_RC_ENOENT:
71 return "I40E_AQ_RC_ENOENT";
72 case I40E_AQ_RC_ESRCH:
73 return "I40E_AQ_RC_ESRCH";
74 case I40E_AQ_RC_EINTR:
75 return "I40E_AQ_RC_EINTR";
76 case I40E_AQ_RC_EIO:
77 return "I40E_AQ_RC_EIO";
78 case I40E_AQ_RC_ENXIO:
79 return "I40E_AQ_RC_ENXIO";
80 case I40E_AQ_RC_E2BIG:
81 return "I40E_AQ_RC_E2BIG";
82 case I40E_AQ_RC_EAGAIN:
83 return "I40E_AQ_RC_EAGAIN";
84 case I40E_AQ_RC_ENOMEM:
85 return "I40E_AQ_RC_ENOMEM";
86 case I40E_AQ_RC_EACCES:
87 return "I40E_AQ_RC_EACCES";
88 case I40E_AQ_RC_EFAULT:
89 return "I40E_AQ_RC_EFAULT";
90 case I40E_AQ_RC_EBUSY:
91 return "I40E_AQ_RC_EBUSY";
92 case I40E_AQ_RC_EEXIST:
93 return "I40E_AQ_RC_EEXIST";
94 case I40E_AQ_RC_EINVAL:
95 return "I40E_AQ_RC_EINVAL";
96 case I40E_AQ_RC_ENOTTY:
97 return "I40E_AQ_RC_ENOTTY";
98 case I40E_AQ_RC_ENOSPC:
99 return "I40E_AQ_RC_ENOSPC";
100 case I40E_AQ_RC_ENOSYS:
101 return "I40E_AQ_RC_ENOSYS";
102 case I40E_AQ_RC_ERANGE:
103 return "I40E_AQ_RC_ERANGE";
104 case I40E_AQ_RC_EFLUSHED:
105 return "I40E_AQ_RC_EFLUSHED";
106 case I40E_AQ_RC_BAD_ADDR:
107 return "I40E_AQ_RC_BAD_ADDR";
108 case I40E_AQ_RC_EMODE:
109 return "I40E_AQ_RC_EMODE";
110 case I40E_AQ_RC_EFBIG:
111 return "I40E_AQ_RC_EFBIG";
112 }
113
114 snprintf(hw->err_str, sizeof(hw->err_str), "%d", aq_err);
115 return hw->err_str;
116}
117
118/**
119 * i40e_stat_str - convert status err code to a string
120 * @hw: pointer to the HW structure
121 * @stat_err: the status error code to convert
122 **/
Jingjing Wu4e68adfe2015-09-28 14:12:31 -0400123const char *i40e_stat_str(struct i40e_hw *hw, i40e_status stat_err)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400124{
125 switch (stat_err) {
126 case 0:
127 return "OK";
128 case I40E_ERR_NVM:
129 return "I40E_ERR_NVM";
130 case I40E_ERR_NVM_CHECKSUM:
131 return "I40E_ERR_NVM_CHECKSUM";
132 case I40E_ERR_PHY:
133 return "I40E_ERR_PHY";
134 case I40E_ERR_CONFIG:
135 return "I40E_ERR_CONFIG";
136 case I40E_ERR_PARAM:
137 return "I40E_ERR_PARAM";
138 case I40E_ERR_MAC_TYPE:
139 return "I40E_ERR_MAC_TYPE";
140 case I40E_ERR_UNKNOWN_PHY:
141 return "I40E_ERR_UNKNOWN_PHY";
142 case I40E_ERR_LINK_SETUP:
143 return "I40E_ERR_LINK_SETUP";
144 case I40E_ERR_ADAPTER_STOPPED:
145 return "I40E_ERR_ADAPTER_STOPPED";
146 case I40E_ERR_INVALID_MAC_ADDR:
147 return "I40E_ERR_INVALID_MAC_ADDR";
148 case I40E_ERR_DEVICE_NOT_SUPPORTED:
149 return "I40E_ERR_DEVICE_NOT_SUPPORTED";
150 case I40E_ERR_MASTER_REQUESTS_PENDING:
151 return "I40E_ERR_MASTER_REQUESTS_PENDING";
152 case I40E_ERR_INVALID_LINK_SETTINGS:
153 return "I40E_ERR_INVALID_LINK_SETTINGS";
154 case I40E_ERR_AUTONEG_NOT_COMPLETE:
155 return "I40E_ERR_AUTONEG_NOT_COMPLETE";
156 case I40E_ERR_RESET_FAILED:
157 return "I40E_ERR_RESET_FAILED";
158 case I40E_ERR_SWFW_SYNC:
159 return "I40E_ERR_SWFW_SYNC";
160 case I40E_ERR_NO_AVAILABLE_VSI:
161 return "I40E_ERR_NO_AVAILABLE_VSI";
162 case I40E_ERR_NO_MEMORY:
163 return "I40E_ERR_NO_MEMORY";
164 case I40E_ERR_BAD_PTR:
165 return "I40E_ERR_BAD_PTR";
166 case I40E_ERR_RING_FULL:
167 return "I40E_ERR_RING_FULL";
168 case I40E_ERR_INVALID_PD_ID:
169 return "I40E_ERR_INVALID_PD_ID";
170 case I40E_ERR_INVALID_QP_ID:
171 return "I40E_ERR_INVALID_QP_ID";
172 case I40E_ERR_INVALID_CQ_ID:
173 return "I40E_ERR_INVALID_CQ_ID";
174 case I40E_ERR_INVALID_CEQ_ID:
175 return "I40E_ERR_INVALID_CEQ_ID";
176 case I40E_ERR_INVALID_AEQ_ID:
177 return "I40E_ERR_INVALID_AEQ_ID";
178 case I40E_ERR_INVALID_SIZE:
179 return "I40E_ERR_INVALID_SIZE";
180 case I40E_ERR_INVALID_ARP_INDEX:
181 return "I40E_ERR_INVALID_ARP_INDEX";
182 case I40E_ERR_INVALID_FPM_FUNC_ID:
183 return "I40E_ERR_INVALID_FPM_FUNC_ID";
184 case I40E_ERR_QP_INVALID_MSG_SIZE:
185 return "I40E_ERR_QP_INVALID_MSG_SIZE";
186 case I40E_ERR_QP_TOOMANY_WRS_POSTED:
187 return "I40E_ERR_QP_TOOMANY_WRS_POSTED";
188 case I40E_ERR_INVALID_FRAG_COUNT:
189 return "I40E_ERR_INVALID_FRAG_COUNT";
190 case I40E_ERR_QUEUE_EMPTY:
191 return "I40E_ERR_QUEUE_EMPTY";
192 case I40E_ERR_INVALID_ALIGNMENT:
193 return "I40E_ERR_INVALID_ALIGNMENT";
194 case I40E_ERR_FLUSHED_QUEUE:
195 return "I40E_ERR_FLUSHED_QUEUE";
196 case I40E_ERR_INVALID_PUSH_PAGE_INDEX:
197 return "I40E_ERR_INVALID_PUSH_PAGE_INDEX";
198 case I40E_ERR_INVALID_IMM_DATA_SIZE:
199 return "I40E_ERR_INVALID_IMM_DATA_SIZE";
200 case I40E_ERR_TIMEOUT:
201 return "I40E_ERR_TIMEOUT";
202 case I40E_ERR_OPCODE_MISMATCH:
203 return "I40E_ERR_OPCODE_MISMATCH";
204 case I40E_ERR_CQP_COMPL_ERROR:
205 return "I40E_ERR_CQP_COMPL_ERROR";
206 case I40E_ERR_INVALID_VF_ID:
207 return "I40E_ERR_INVALID_VF_ID";
208 case I40E_ERR_INVALID_HMCFN_ID:
209 return "I40E_ERR_INVALID_HMCFN_ID";
210 case I40E_ERR_BACKING_PAGE_ERROR:
211 return "I40E_ERR_BACKING_PAGE_ERROR";
212 case I40E_ERR_NO_PBLCHUNKS_AVAILABLE:
213 return "I40E_ERR_NO_PBLCHUNKS_AVAILABLE";
214 case I40E_ERR_INVALID_PBLE_INDEX:
215 return "I40E_ERR_INVALID_PBLE_INDEX";
216 case I40E_ERR_INVALID_SD_INDEX:
217 return "I40E_ERR_INVALID_SD_INDEX";
218 case I40E_ERR_INVALID_PAGE_DESC_INDEX:
219 return "I40E_ERR_INVALID_PAGE_DESC_INDEX";
220 case I40E_ERR_INVALID_SD_TYPE:
221 return "I40E_ERR_INVALID_SD_TYPE";
222 case I40E_ERR_MEMCPY_FAILED:
223 return "I40E_ERR_MEMCPY_FAILED";
224 case I40E_ERR_INVALID_HMC_OBJ_INDEX:
225 return "I40E_ERR_INVALID_HMC_OBJ_INDEX";
226 case I40E_ERR_INVALID_HMC_OBJ_COUNT:
227 return "I40E_ERR_INVALID_HMC_OBJ_COUNT";
228 case I40E_ERR_INVALID_SRQ_ARM_LIMIT:
229 return "I40E_ERR_INVALID_SRQ_ARM_LIMIT";
230 case I40E_ERR_SRQ_ENABLED:
231 return "I40E_ERR_SRQ_ENABLED";
232 case I40E_ERR_ADMIN_QUEUE_ERROR:
233 return "I40E_ERR_ADMIN_QUEUE_ERROR";
234 case I40E_ERR_ADMIN_QUEUE_TIMEOUT:
235 return "I40E_ERR_ADMIN_QUEUE_TIMEOUT";
236 case I40E_ERR_BUF_TOO_SHORT:
237 return "I40E_ERR_BUF_TOO_SHORT";
238 case I40E_ERR_ADMIN_QUEUE_FULL:
239 return "I40E_ERR_ADMIN_QUEUE_FULL";
240 case I40E_ERR_ADMIN_QUEUE_NO_WORK:
241 return "I40E_ERR_ADMIN_QUEUE_NO_WORK";
242 case I40E_ERR_BAD_IWARP_CQE:
243 return "I40E_ERR_BAD_IWARP_CQE";
244 case I40E_ERR_NVM_BLANK_MODE:
245 return "I40E_ERR_NVM_BLANK_MODE";
246 case I40E_ERR_NOT_IMPLEMENTED:
247 return "I40E_ERR_NOT_IMPLEMENTED";
248 case I40E_ERR_PE_DOORBELL_NOT_ENABLED:
249 return "I40E_ERR_PE_DOORBELL_NOT_ENABLED";
250 case I40E_ERR_DIAG_TEST_FAILED:
251 return "I40E_ERR_DIAG_TEST_FAILED";
252 case I40E_ERR_NOT_READY:
253 return "I40E_ERR_NOT_READY";
254 case I40E_NOT_SUPPORTED:
255 return "I40E_NOT_SUPPORTED";
256 case I40E_ERR_FIRMWARE_API_VERSION:
257 return "I40E_ERR_FIRMWARE_API_VERSION";
Michal Kosiarzf34e308b2017-12-27 08:14:40 -0500258 case I40E_ERR_ADMIN_QUEUE_CRITICAL_ERROR:
259 return "I40E_ERR_ADMIN_QUEUE_CRITICAL_ERROR";
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400260 }
261
262 snprintf(hw->err_str, sizeof(hw->err_str), "%d", stat_err);
263 return hw->err_str;
264}
265
266/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000267 * i40e_debug_aq
268 * @hw: debug mask related to admin queue
Jeff Kirsher98d44382013-12-21 05:44:42 +0000269 * @mask: debug mask
270 * @desc: pointer to admin queue descriptor
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000271 * @buffer: pointer to command buffer
Shannon Nelsonf905dd62014-07-10 07:58:20 +0000272 * @buf_len: max length of buffer
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000273 *
274 * Dumps debug log about adminq command with descriptor contents.
275 **/
276void i40e_debug_aq(struct i40e_hw *hw, enum i40e_debug_mask mask, void *desc,
Shannon Nelsonf905dd62014-07-10 07:58:20 +0000277 void *buffer, u16 buf_len)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000278{
279 struct i40e_aq_desc *aq_desc = (struct i40e_aq_desc *)desc;
Heinrich Schuchardtcd956722016-05-17 22:41:33 +0200280 u16 len;
Shannon Nelson37a29732015-02-27 09:15:19 +0000281 u8 *buf = (u8 *)buffer;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000282
283 if ((!(mask & hw->debug_mask)) || (desc == NULL))
284 return;
285
Heinrich Schuchardtcd956722016-05-17 22:41:33 +0200286 len = le16_to_cpu(aq_desc->datalen);
287
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000288 i40e_debug(hw, mask,
289 "AQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000290 le16_to_cpu(aq_desc->opcode),
291 le16_to_cpu(aq_desc->flags),
292 le16_to_cpu(aq_desc->datalen),
293 le16_to_cpu(aq_desc->retval));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000294 i40e_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000295 le32_to_cpu(aq_desc->cookie_high),
296 le32_to_cpu(aq_desc->cookie_low));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000297 i40e_debug(hw, mask, "\tparam (0,1) 0x%08X 0x%08X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000298 le32_to_cpu(aq_desc->params.internal.param0),
299 le32_to_cpu(aq_desc->params.internal.param1));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000300 i40e_debug(hw, mask, "\taddr (h,l) 0x%08X 0x%08X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000301 le32_to_cpu(aq_desc->params.external.addr_high),
302 le32_to_cpu(aq_desc->params.external.addr_low));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000303
304 if ((buffer != NULL) && (aq_desc->datalen != 0)) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000305 i40e_debug(hw, mask, "AQ CMD Buffer:\n");
Shannon Nelsonf905dd62014-07-10 07:58:20 +0000306 if (buf_len < len)
307 len = buf_len;
Shannon Nelson37a29732015-02-27 09:15:19 +0000308 /* write the full 16-byte chunks */
Alan Brady773d4022016-12-12 15:44:13 -0800309 if (hw->debug_mask & mask) {
Jacob Kellerb5d55042017-07-12 05:46:09 -0400310 char prefix[27];
Alan Brady773d4022016-12-12 15:44:13 -0800311
Jacob Kellerb5d55042017-07-12 05:46:09 -0400312 snprintf(prefix, sizeof(prefix),
Alan Brady773d4022016-12-12 15:44:13 -0800313 "i40e %02x:%02x.%x: \t0x",
314 hw->bus.bus_id,
315 hw->bus.device,
316 hw->bus.func);
317
318 print_hex_dump(KERN_INFO, prefix, DUMP_PREFIX_OFFSET,
319 16, 1, buf, len, false);
320 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000321 }
322}
323
324/**
Anjali Singhai Jaine1860d82013-11-28 06:39:45 +0000325 * i40e_check_asq_alive
326 * @hw: pointer to the hw struct
327 *
328 * Returns true if Queue is enabled else false.
329 **/
330bool i40e_check_asq_alive(struct i40e_hw *hw)
331{
Kevin Scott8b833b42014-04-09 05:58:54 +0000332 if (hw->aq.asq.len)
333 return !!(rd32(hw, hw->aq.asq.len) &
334 I40E_PF_ATQLEN_ATQENABLE_MASK);
335 else
336 return false;
Anjali Singhai Jaine1860d82013-11-28 06:39:45 +0000337}
338
339/**
340 * i40e_aq_queue_shutdown
341 * @hw: pointer to the hw struct
342 * @unloading: is the driver unloading itself
343 *
344 * Tell the Firmware that we're shutting down the AdminQ and whether
345 * or not the driver is unloading as well.
346 **/
347i40e_status i40e_aq_queue_shutdown(struct i40e_hw *hw,
348 bool unloading)
349{
350 struct i40e_aq_desc desc;
351 struct i40e_aqc_queue_shutdown *cmd =
352 (struct i40e_aqc_queue_shutdown *)&desc.params.raw;
353 i40e_status status;
354
355 i40e_fill_default_direct_cmd_desc(&desc,
356 i40e_aqc_opc_queue_shutdown);
357
358 if (unloading)
359 cmd->driver_unloading = cpu_to_le32(I40E_AQ_DRIVER_UNLOADING);
360 status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
361
362 return status;
363}
364
Anjali Singhai Jaine50c8d62015-06-05 12:20:27 -0400365/**
366 * i40e_aq_get_set_rss_lut
367 * @hw: pointer to the hardware structure
368 * @vsi_id: vsi fw index
369 * @pf_lut: for PF table set true, for VSI table set false
370 * @lut: pointer to the lut buffer provided by the caller
371 * @lut_size: size of the lut buffer
372 * @set: set true to set the table, false to get the table
373 *
374 * Internal function to get or set RSS look up table
375 **/
376static i40e_status i40e_aq_get_set_rss_lut(struct i40e_hw *hw,
377 u16 vsi_id, bool pf_lut,
378 u8 *lut, u16 lut_size,
379 bool set)
380{
381 i40e_status status;
382 struct i40e_aq_desc desc;
383 struct i40e_aqc_get_set_rss_lut *cmd_resp =
384 (struct i40e_aqc_get_set_rss_lut *)&desc.params.raw;
385
386 if (set)
387 i40e_fill_default_direct_cmd_desc(&desc,
388 i40e_aqc_opc_set_rss_lut);
389 else
390 i40e_fill_default_direct_cmd_desc(&desc,
391 i40e_aqc_opc_get_rss_lut);
392
393 /* Indirect command */
394 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
395 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
396
397 cmd_resp->vsi_id =
398 cpu_to_le16((u16)((vsi_id <<
399 I40E_AQC_SET_RSS_LUT_VSI_ID_SHIFT) &
400 I40E_AQC_SET_RSS_LUT_VSI_ID_MASK));
401 cmd_resp->vsi_id |= cpu_to_le16((u16)I40E_AQC_SET_RSS_LUT_VSI_VALID);
402
403 if (pf_lut)
404 cmd_resp->flags |= cpu_to_le16((u16)
405 ((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_PF <<
406 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
407 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
408 else
409 cmd_resp->flags |= cpu_to_le16((u16)
410 ((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_VSI <<
411 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
412 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
413
Anjali Singhai Jaine50c8d62015-06-05 12:20:27 -0400414 status = i40e_asq_send_command(hw, &desc, lut, lut_size, NULL);
415
416 return status;
417}
418
419/**
420 * i40e_aq_get_rss_lut
421 * @hw: pointer to the hardware structure
422 * @vsi_id: vsi fw index
423 * @pf_lut: for PF table set true, for VSI table set false
424 * @lut: pointer to the lut buffer provided by the caller
425 * @lut_size: size of the lut buffer
426 *
427 * get the RSS lookup table, PF or VSI type
428 **/
429i40e_status i40e_aq_get_rss_lut(struct i40e_hw *hw, u16 vsi_id,
430 bool pf_lut, u8 *lut, u16 lut_size)
431{
432 return i40e_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size,
433 false);
434}
435
436/**
437 * i40e_aq_set_rss_lut
438 * @hw: pointer to the hardware structure
439 * @vsi_id: vsi fw index
440 * @pf_lut: for PF table set true, for VSI table set false
441 * @lut: pointer to the lut buffer provided by the caller
442 * @lut_size: size of the lut buffer
443 *
444 * set the RSS lookup table, PF or VSI type
445 **/
446i40e_status i40e_aq_set_rss_lut(struct i40e_hw *hw, u16 vsi_id,
447 bool pf_lut, u8 *lut, u16 lut_size)
448{
449 return i40e_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size, true);
450}
451
452/**
453 * i40e_aq_get_set_rss_key
454 * @hw: pointer to the hw struct
455 * @vsi_id: vsi fw index
456 * @key: pointer to key info struct
457 * @set: set true to set the key, false to get the key
458 *
459 * get the RSS key per VSI
460 **/
461static i40e_status i40e_aq_get_set_rss_key(struct i40e_hw *hw,
462 u16 vsi_id,
463 struct i40e_aqc_get_set_rss_key_data *key,
464 bool set)
465{
466 i40e_status status;
467 struct i40e_aq_desc desc;
468 struct i40e_aqc_get_set_rss_key *cmd_resp =
469 (struct i40e_aqc_get_set_rss_key *)&desc.params.raw;
470 u16 key_size = sizeof(struct i40e_aqc_get_set_rss_key_data);
471
472 if (set)
473 i40e_fill_default_direct_cmd_desc(&desc,
474 i40e_aqc_opc_set_rss_key);
475 else
476 i40e_fill_default_direct_cmd_desc(&desc,
477 i40e_aqc_opc_get_rss_key);
478
479 /* Indirect command */
480 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
481 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
482
483 cmd_resp->vsi_id =
484 cpu_to_le16((u16)((vsi_id <<
485 I40E_AQC_SET_RSS_KEY_VSI_ID_SHIFT) &
486 I40E_AQC_SET_RSS_KEY_VSI_ID_MASK));
487 cmd_resp->vsi_id |= cpu_to_le16((u16)I40E_AQC_SET_RSS_KEY_VSI_VALID);
Anjali Singhai Jaine50c8d62015-06-05 12:20:27 -0400488
489 status = i40e_asq_send_command(hw, &desc, key, key_size, NULL);
490
491 return status;
492}
493
494/**
495 * i40e_aq_get_rss_key
496 * @hw: pointer to the hw struct
497 * @vsi_id: vsi fw index
498 * @key: pointer to key info struct
499 *
500 **/
501i40e_status i40e_aq_get_rss_key(struct i40e_hw *hw,
502 u16 vsi_id,
503 struct i40e_aqc_get_set_rss_key_data *key)
504{
505 return i40e_aq_get_set_rss_key(hw, vsi_id, key, false);
506}
507
508/**
509 * i40e_aq_set_rss_key
510 * @hw: pointer to the hw struct
511 * @vsi_id: vsi fw index
512 * @key: pointer to key info struct
513 *
514 * set the RSS key per VSI
515 **/
516i40e_status i40e_aq_set_rss_key(struct i40e_hw *hw,
517 u16 vsi_id,
518 struct i40e_aqc_get_set_rss_key_data *key)
519{
520 return i40e_aq_get_set_rss_key(hw, vsi_id, key, true);
521}
522
Jesse Brandeburg206812b2014-02-12 01:45:33 +0000523/* The i40e_ptype_lookup table is used to convert from the 8-bit ptype in the
524 * hardware to a bit-field that can be used by SW to more easily determine the
525 * packet type.
526 *
527 * Macros are used to shorten the table lines and make this table human
528 * readable.
529 *
530 * We store the PTYPE in the top byte of the bit field - this is just so that
531 * we can check that the table doesn't have a row missing, as the index into
532 * the table should be the PTYPE.
533 *
534 * Typical work flow:
535 *
536 * IF NOT i40e_ptype_lookup[ptype].known
537 * THEN
538 * Packet is unknown
539 * ELSE IF i40e_ptype_lookup[ptype].outer_ip == I40E_RX_PTYPE_OUTER_IP
540 * Use the rest of the fields to look at the tunnels, inner protocols, etc
541 * ELSE
542 * Use the enum i40e_rx_l2_ptype to decode the packet type
543 * ENDIF
544 */
545
546/* macro to make the table lines short */
547#define I40E_PTT(PTYPE, OUTER_IP, OUTER_IP_VER, OUTER_FRAG, T, TE, TEF, I, PL)\
548 { PTYPE, \
549 1, \
550 I40E_RX_PTYPE_OUTER_##OUTER_IP, \
551 I40E_RX_PTYPE_OUTER_##OUTER_IP_VER, \
552 I40E_RX_PTYPE_##OUTER_FRAG, \
553 I40E_RX_PTYPE_TUNNEL_##T, \
554 I40E_RX_PTYPE_TUNNEL_END_##TE, \
555 I40E_RX_PTYPE_##TEF, \
556 I40E_RX_PTYPE_INNER_PROT_##I, \
557 I40E_RX_PTYPE_PAYLOAD_LAYER_##PL }
558
559#define I40E_PTT_UNUSED_ENTRY(PTYPE) \
560 { PTYPE, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
561
562/* shorter macros makes the table fit but are terse */
563#define I40E_RX_PTYPE_NOF I40E_RX_PTYPE_NOT_FRAG
564#define I40E_RX_PTYPE_FRG I40E_RX_PTYPE_FRAG
565#define I40E_RX_PTYPE_INNER_PROT_TS I40E_RX_PTYPE_INNER_PROT_TIMESYNC
566
567/* Lookup table mapping the HW PTYPE to the bit field for decoding */
568struct i40e_rx_ptype_decoded i40e_ptype_lookup[] = {
569 /* L2 Packet types */
570 I40E_PTT_UNUSED_ENTRY(0),
571 I40E_PTT(1, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
572 I40E_PTT(2, L2, NONE, NOF, NONE, NONE, NOF, TS, PAY2),
573 I40E_PTT(3, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
574 I40E_PTT_UNUSED_ENTRY(4),
575 I40E_PTT_UNUSED_ENTRY(5),
576 I40E_PTT(6, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
577 I40E_PTT(7, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
578 I40E_PTT_UNUSED_ENTRY(8),
579 I40E_PTT_UNUSED_ENTRY(9),
580 I40E_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
581 I40E_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
582 I40E_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
583 I40E_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
584 I40E_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
585 I40E_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
586 I40E_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
587 I40E_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
588 I40E_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
589 I40E_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
590 I40E_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
591 I40E_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
592
593 /* Non Tunneled IPv4 */
594 I40E_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
595 I40E_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
596 I40E_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP, PAY4),
597 I40E_PTT_UNUSED_ENTRY(25),
598 I40E_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP, PAY4),
599 I40E_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
600 I40E_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
601
602 /* IPv4 --> IPv4 */
603 I40E_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
604 I40E_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
605 I40E_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
606 I40E_PTT_UNUSED_ENTRY(32),
607 I40E_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
608 I40E_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
609 I40E_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
610
611 /* IPv4 --> IPv6 */
612 I40E_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
613 I40E_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
614 I40E_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
615 I40E_PTT_UNUSED_ENTRY(39),
616 I40E_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
617 I40E_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
618 I40E_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
619
620 /* IPv4 --> GRE/NAT */
621 I40E_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
622
623 /* IPv4 --> GRE/NAT --> IPv4 */
624 I40E_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
625 I40E_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
626 I40E_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
627 I40E_PTT_UNUSED_ENTRY(47),
628 I40E_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
629 I40E_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
630 I40E_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
631
632 /* IPv4 --> GRE/NAT --> IPv6 */
633 I40E_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
634 I40E_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
635 I40E_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
636 I40E_PTT_UNUSED_ENTRY(54),
637 I40E_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
638 I40E_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
639 I40E_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
640
641 /* IPv4 --> GRE/NAT --> MAC */
642 I40E_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
643
644 /* IPv4 --> GRE/NAT --> MAC --> IPv4 */
645 I40E_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
646 I40E_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
647 I40E_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
648 I40E_PTT_UNUSED_ENTRY(62),
649 I40E_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
650 I40E_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
651 I40E_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
652
653 /* IPv4 --> GRE/NAT -> MAC --> IPv6 */
654 I40E_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
655 I40E_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
656 I40E_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
657 I40E_PTT_UNUSED_ENTRY(69),
658 I40E_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
659 I40E_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
660 I40E_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
661
662 /* IPv4 --> GRE/NAT --> MAC/VLAN */
663 I40E_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
664
665 /* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
666 I40E_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
667 I40E_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
668 I40E_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
669 I40E_PTT_UNUSED_ENTRY(77),
670 I40E_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
671 I40E_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
672 I40E_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
673
674 /* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
675 I40E_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
676 I40E_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
677 I40E_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
678 I40E_PTT_UNUSED_ENTRY(84),
679 I40E_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
680 I40E_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
681 I40E_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
682
683 /* Non Tunneled IPv6 */
684 I40E_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
685 I40E_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
Akeem G Abodunrin73df8c92016-05-03 15:13:16 -0700686 I40E_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP, PAY4),
Jesse Brandeburg206812b2014-02-12 01:45:33 +0000687 I40E_PTT_UNUSED_ENTRY(91),
688 I40E_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP, PAY4),
689 I40E_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
690 I40E_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
691
692 /* IPv6 --> IPv4 */
693 I40E_PTT(95, IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
694 I40E_PTT(96, IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
695 I40E_PTT(97, IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
696 I40E_PTT_UNUSED_ENTRY(98),
697 I40E_PTT(99, IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
698 I40E_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
699 I40E_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
700
701 /* IPv6 --> IPv6 */
702 I40E_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
703 I40E_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
704 I40E_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
705 I40E_PTT_UNUSED_ENTRY(105),
706 I40E_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
707 I40E_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
708 I40E_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
709
710 /* IPv6 --> GRE/NAT */
711 I40E_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
712
713 /* IPv6 --> GRE/NAT -> IPv4 */
714 I40E_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
715 I40E_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
716 I40E_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
717 I40E_PTT_UNUSED_ENTRY(113),
718 I40E_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
719 I40E_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
720 I40E_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
721
722 /* IPv6 --> GRE/NAT -> IPv6 */
723 I40E_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
724 I40E_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
725 I40E_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
726 I40E_PTT_UNUSED_ENTRY(120),
727 I40E_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
728 I40E_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
729 I40E_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
730
731 /* IPv6 --> GRE/NAT -> MAC */
732 I40E_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
733
734 /* IPv6 --> GRE/NAT -> MAC -> IPv4 */
735 I40E_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
736 I40E_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
737 I40E_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
738 I40E_PTT_UNUSED_ENTRY(128),
739 I40E_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
740 I40E_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
741 I40E_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
742
743 /* IPv6 --> GRE/NAT -> MAC -> IPv6 */
744 I40E_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
745 I40E_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
746 I40E_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
747 I40E_PTT_UNUSED_ENTRY(135),
748 I40E_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
749 I40E_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
750 I40E_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
751
752 /* IPv6 --> GRE/NAT -> MAC/VLAN */
753 I40E_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
754
755 /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
756 I40E_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
757 I40E_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
758 I40E_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
759 I40E_PTT_UNUSED_ENTRY(143),
760 I40E_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
761 I40E_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
762 I40E_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
763
764 /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
765 I40E_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
766 I40E_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
767 I40E_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
768 I40E_PTT_UNUSED_ENTRY(150),
769 I40E_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
770 I40E_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
771 I40E_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
772
773 /* unused entries */
774 I40E_PTT_UNUSED_ENTRY(154),
775 I40E_PTT_UNUSED_ENTRY(155),
776 I40E_PTT_UNUSED_ENTRY(156),
777 I40E_PTT_UNUSED_ENTRY(157),
778 I40E_PTT_UNUSED_ENTRY(158),
779 I40E_PTT_UNUSED_ENTRY(159),
780
781 I40E_PTT_UNUSED_ENTRY(160),
782 I40E_PTT_UNUSED_ENTRY(161),
783 I40E_PTT_UNUSED_ENTRY(162),
784 I40E_PTT_UNUSED_ENTRY(163),
785 I40E_PTT_UNUSED_ENTRY(164),
786 I40E_PTT_UNUSED_ENTRY(165),
787 I40E_PTT_UNUSED_ENTRY(166),
788 I40E_PTT_UNUSED_ENTRY(167),
789 I40E_PTT_UNUSED_ENTRY(168),
790 I40E_PTT_UNUSED_ENTRY(169),
791
792 I40E_PTT_UNUSED_ENTRY(170),
793 I40E_PTT_UNUSED_ENTRY(171),
794 I40E_PTT_UNUSED_ENTRY(172),
795 I40E_PTT_UNUSED_ENTRY(173),
796 I40E_PTT_UNUSED_ENTRY(174),
797 I40E_PTT_UNUSED_ENTRY(175),
798 I40E_PTT_UNUSED_ENTRY(176),
799 I40E_PTT_UNUSED_ENTRY(177),
800 I40E_PTT_UNUSED_ENTRY(178),
801 I40E_PTT_UNUSED_ENTRY(179),
802
803 I40E_PTT_UNUSED_ENTRY(180),
804 I40E_PTT_UNUSED_ENTRY(181),
805 I40E_PTT_UNUSED_ENTRY(182),
806 I40E_PTT_UNUSED_ENTRY(183),
807 I40E_PTT_UNUSED_ENTRY(184),
808 I40E_PTT_UNUSED_ENTRY(185),
809 I40E_PTT_UNUSED_ENTRY(186),
810 I40E_PTT_UNUSED_ENTRY(187),
811 I40E_PTT_UNUSED_ENTRY(188),
812 I40E_PTT_UNUSED_ENTRY(189),
813
814 I40E_PTT_UNUSED_ENTRY(190),
815 I40E_PTT_UNUSED_ENTRY(191),
816 I40E_PTT_UNUSED_ENTRY(192),
817 I40E_PTT_UNUSED_ENTRY(193),
818 I40E_PTT_UNUSED_ENTRY(194),
819 I40E_PTT_UNUSED_ENTRY(195),
820 I40E_PTT_UNUSED_ENTRY(196),
821 I40E_PTT_UNUSED_ENTRY(197),
822 I40E_PTT_UNUSED_ENTRY(198),
823 I40E_PTT_UNUSED_ENTRY(199),
824
825 I40E_PTT_UNUSED_ENTRY(200),
826 I40E_PTT_UNUSED_ENTRY(201),
827 I40E_PTT_UNUSED_ENTRY(202),
828 I40E_PTT_UNUSED_ENTRY(203),
829 I40E_PTT_UNUSED_ENTRY(204),
830 I40E_PTT_UNUSED_ENTRY(205),
831 I40E_PTT_UNUSED_ENTRY(206),
832 I40E_PTT_UNUSED_ENTRY(207),
833 I40E_PTT_UNUSED_ENTRY(208),
834 I40E_PTT_UNUSED_ENTRY(209),
835
836 I40E_PTT_UNUSED_ENTRY(210),
837 I40E_PTT_UNUSED_ENTRY(211),
838 I40E_PTT_UNUSED_ENTRY(212),
839 I40E_PTT_UNUSED_ENTRY(213),
840 I40E_PTT_UNUSED_ENTRY(214),
841 I40E_PTT_UNUSED_ENTRY(215),
842 I40E_PTT_UNUSED_ENTRY(216),
843 I40E_PTT_UNUSED_ENTRY(217),
844 I40E_PTT_UNUSED_ENTRY(218),
845 I40E_PTT_UNUSED_ENTRY(219),
846
847 I40E_PTT_UNUSED_ENTRY(220),
848 I40E_PTT_UNUSED_ENTRY(221),
849 I40E_PTT_UNUSED_ENTRY(222),
850 I40E_PTT_UNUSED_ENTRY(223),
851 I40E_PTT_UNUSED_ENTRY(224),
852 I40E_PTT_UNUSED_ENTRY(225),
853 I40E_PTT_UNUSED_ENTRY(226),
854 I40E_PTT_UNUSED_ENTRY(227),
855 I40E_PTT_UNUSED_ENTRY(228),
856 I40E_PTT_UNUSED_ENTRY(229),
857
858 I40E_PTT_UNUSED_ENTRY(230),
859 I40E_PTT_UNUSED_ENTRY(231),
860 I40E_PTT_UNUSED_ENTRY(232),
861 I40E_PTT_UNUSED_ENTRY(233),
862 I40E_PTT_UNUSED_ENTRY(234),
863 I40E_PTT_UNUSED_ENTRY(235),
864 I40E_PTT_UNUSED_ENTRY(236),
865 I40E_PTT_UNUSED_ENTRY(237),
866 I40E_PTT_UNUSED_ENTRY(238),
867 I40E_PTT_UNUSED_ENTRY(239),
868
869 I40E_PTT_UNUSED_ENTRY(240),
870 I40E_PTT_UNUSED_ENTRY(241),
871 I40E_PTT_UNUSED_ENTRY(242),
872 I40E_PTT_UNUSED_ENTRY(243),
873 I40E_PTT_UNUSED_ENTRY(244),
874 I40E_PTT_UNUSED_ENTRY(245),
875 I40E_PTT_UNUSED_ENTRY(246),
876 I40E_PTT_UNUSED_ENTRY(247),
877 I40E_PTT_UNUSED_ENTRY(248),
878 I40E_PTT_UNUSED_ENTRY(249),
879
880 I40E_PTT_UNUSED_ENTRY(250),
881 I40E_PTT_UNUSED_ENTRY(251),
882 I40E_PTT_UNUSED_ENTRY(252),
883 I40E_PTT_UNUSED_ENTRY(253),
884 I40E_PTT_UNUSED_ENTRY(254),
885 I40E_PTT_UNUSED_ENTRY(255)
886};
887
Anjali Singhai Jaine1860d82013-11-28 06:39:45 +0000888/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000889 * i40e_init_shared_code - Initialize the shared code
890 * @hw: pointer to hardware structure
891 *
892 * This assigns the MAC type and PHY code and inits the NVM.
893 * Does not touch the hardware. This function must be called prior to any
894 * other function in the shared code. The i40e_hw structure should be
895 * memset to 0 prior to calling this function. The following fields in
896 * hw structure should be filled in prior to calling this function:
897 * hw_addr, back, device_id, vendor_id, subsystem_device_id,
898 * subsystem_vendor_id, and revision_id
899 **/
900i40e_status i40e_init_shared_code(struct i40e_hw *hw)
901{
902 i40e_status status = 0;
Shannon Nelson5fb11d72014-11-13 03:06:19 +0000903 u32 port, ari, func_rid;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000904
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000905 i40e_set_mac_type(hw);
906
907 switch (hw->mac.type) {
908 case I40E_MAC_XL710:
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -0400909 case I40E_MAC_X722:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000910 break;
911 default:
912 return I40E_ERR_DEVICE_NOT_SUPPORTED;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000913 }
914
Shannon Nelsonaf89d26c2013-12-11 08:17:14 +0000915 hw->phy.get_link_info = true;
916
Shannon Nelson5fb11d72014-11-13 03:06:19 +0000917 /* Determine port number and PF number*/
918 port = (rd32(hw, I40E_PFGEN_PORTNUM) & I40E_PFGEN_PORTNUM_PORT_NUM_MASK)
919 >> I40E_PFGEN_PORTNUM_PORT_NUM_SHIFT;
920 hw->port = (u8)port;
921 ari = (rd32(hw, I40E_GLPCI_CAPSUP) & I40E_GLPCI_CAPSUP_ARI_EN_MASK) >>
922 I40E_GLPCI_CAPSUP_ARI_EN_SHIFT;
923 func_rid = rd32(hw, I40E_PF_FUNC_RID);
924 if (ari)
925 hw->pf_id = (u8)(func_rid & 0xff);
Shannon Nelson5f9116a2013-12-11 08:17:13 +0000926 else
Shannon Nelson5fb11d72014-11-13 03:06:19 +0000927 hw->pf_id = (u8)(func_rid & 0x7);
Shannon Nelson5f9116a2013-12-11 08:17:13 +0000928
Anjali Singhai07f89be2015-09-24 15:26:32 -0700929 if (hw->mac.type == I40E_MAC_X722)
Jacob Keller3d72aeb2017-10-27 11:06:55 -0400930 hw->flags |= I40E_HW_FLAG_AQ_SRCTL_ACCESS_ENABLE |
931 I40E_HW_FLAG_NVM_READ_REQUIRES_LOCK;
Anjali Singhai07f89be2015-09-24 15:26:32 -0700932
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000933 status = i40e_init_nvm(hw);
934 return status;
935}
936
937/**
938 * i40e_aq_mac_address_read - Retrieve the MAC addresses
939 * @hw: pointer to the hw struct
940 * @flags: a return indicator of what addresses were added to the addr store
941 * @addrs: the requestor's mac addr store
942 * @cmd_details: pointer to command details structure or NULL
943 **/
944static i40e_status i40e_aq_mac_address_read(struct i40e_hw *hw,
945 u16 *flags,
946 struct i40e_aqc_mac_address_read_data *addrs,
947 struct i40e_asq_cmd_details *cmd_details)
948{
949 struct i40e_aq_desc desc;
950 struct i40e_aqc_mac_address_read *cmd_data =
951 (struct i40e_aqc_mac_address_read *)&desc.params.raw;
952 i40e_status status;
953
954 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_mac_address_read);
955 desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF);
956
957 status = i40e_asq_send_command(hw, &desc, addrs,
958 sizeof(*addrs), cmd_details);
959 *flags = le16_to_cpu(cmd_data->command_flags);
960
961 return status;
962}
963
964/**
965 * i40e_aq_mac_address_write - Change the MAC addresses
966 * @hw: pointer to the hw struct
967 * @flags: indicates which MAC to be written
968 * @mac_addr: address to write
969 * @cmd_details: pointer to command details structure or NULL
970 **/
971i40e_status i40e_aq_mac_address_write(struct i40e_hw *hw,
972 u16 flags, u8 *mac_addr,
973 struct i40e_asq_cmd_details *cmd_details)
974{
975 struct i40e_aq_desc desc;
976 struct i40e_aqc_mac_address_write *cmd_data =
977 (struct i40e_aqc_mac_address_write *)&desc.params.raw;
978 i40e_status status;
979
980 i40e_fill_default_direct_cmd_desc(&desc,
981 i40e_aqc_opc_mac_address_write);
982 cmd_data->command_flags = cpu_to_le16(flags);
Kamil Krawczyk55c29c32013-12-18 13:45:52 +0000983 cmd_data->mac_sah = cpu_to_le16((u16)mac_addr[0] << 8 | mac_addr[1]);
984 cmd_data->mac_sal = cpu_to_le32(((u32)mac_addr[2] << 24) |
985 ((u32)mac_addr[3] << 16) |
986 ((u32)mac_addr[4] << 8) |
987 mac_addr[5]);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000988
989 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
990
991 return status;
992}
993
994/**
995 * i40e_get_mac_addr - get MAC address
996 * @hw: pointer to the HW structure
997 * @mac_addr: pointer to MAC address
998 *
999 * Reads the adapter's MAC address from register
1000 **/
1001i40e_status i40e_get_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
1002{
1003 struct i40e_aqc_mac_address_read_data addrs;
1004 i40e_status status;
1005 u16 flags = 0;
1006
1007 status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
1008
1009 if (flags & I40E_AQC_LAN_ADDR_VALID)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001010 ether_addr_copy(mac_addr, addrs.pf_lan_mac);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001011
1012 return status;
1013}
1014
1015/**
Neerav Parikh1f224ad2014-02-12 01:45:31 +00001016 * i40e_get_port_mac_addr - get Port MAC address
1017 * @hw: pointer to the HW structure
1018 * @mac_addr: pointer to Port MAC address
1019 *
1020 * Reads the adapter's Port MAC address
1021 **/
1022i40e_status i40e_get_port_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
1023{
1024 struct i40e_aqc_mac_address_read_data addrs;
1025 i40e_status status;
1026 u16 flags = 0;
1027
1028 status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
1029 if (status)
1030 return status;
1031
1032 if (flags & I40E_AQC_PORT_ADDR_VALID)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001033 ether_addr_copy(mac_addr, addrs.port_mac);
Neerav Parikh1f224ad2014-02-12 01:45:31 +00001034 else
1035 status = I40E_ERR_INVALID_MAC_ADDR;
1036
1037 return status;
1038}
1039
1040/**
Matt Jared351499ab2014-04-23 04:50:03 +00001041 * i40e_pre_tx_queue_cfg - pre tx queue configure
1042 * @hw: pointer to the HW structure
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00001043 * @queue: target PF queue index
Matt Jared351499ab2014-04-23 04:50:03 +00001044 * @enable: state change request
1045 *
1046 * Handles hw requirement to indicate intention to enable
1047 * or disable target queue.
1048 **/
1049void i40e_pre_tx_queue_cfg(struct i40e_hw *hw, u32 queue, bool enable)
1050{
Shannon Nelsondfb699f2014-05-22 06:32:28 +00001051 u32 abs_queue_idx = hw->func_caps.base_queue + queue;
Matt Jared351499ab2014-04-23 04:50:03 +00001052 u32 reg_block = 0;
Shannon Nelsondfb699f2014-05-22 06:32:28 +00001053 u32 reg_val;
Matt Jared351499ab2014-04-23 04:50:03 +00001054
Christopher Pau24a768c2014-06-04 20:41:59 +00001055 if (abs_queue_idx >= 128) {
Matt Jared351499ab2014-04-23 04:50:03 +00001056 reg_block = abs_queue_idx / 128;
Christopher Pau24a768c2014-06-04 20:41:59 +00001057 abs_queue_idx %= 128;
1058 }
Matt Jared351499ab2014-04-23 04:50:03 +00001059
1060 reg_val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
1061 reg_val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
1062 reg_val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
1063
1064 if (enable)
1065 reg_val |= I40E_GLLAN_TXPRE_QDIS_CLEAR_QDIS_MASK;
1066 else
1067 reg_val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
1068
1069 wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), reg_val);
1070}
1071
1072/**
Kamil Krawczyk18f680c2014-12-11 07:06:31 +00001073 * i40e_read_pba_string - Reads part number string from EEPROM
1074 * @hw: pointer to hardware structure
1075 * @pba_num: stores the part number string from the EEPROM
1076 * @pba_num_size: part number string buffer length
1077 *
1078 * Reads the part number string from the EEPROM.
1079 **/
1080i40e_status i40e_read_pba_string(struct i40e_hw *hw, u8 *pba_num,
1081 u32 pba_num_size)
1082{
1083 i40e_status status = 0;
1084 u16 pba_word = 0;
1085 u16 pba_size = 0;
1086 u16 pba_ptr = 0;
1087 u16 i = 0;
1088
1089 status = i40e_read_nvm_word(hw, I40E_SR_PBA_FLAGS, &pba_word);
1090 if (status || (pba_word != 0xFAFA)) {
1091 hw_dbg(hw, "Failed to read PBA flags or flag is invalid.\n");
1092 return status;
1093 }
1094
1095 status = i40e_read_nvm_word(hw, I40E_SR_PBA_BLOCK_PTR, &pba_ptr);
1096 if (status) {
1097 hw_dbg(hw, "Failed to read PBA Block pointer.\n");
1098 return status;
1099 }
1100
1101 status = i40e_read_nvm_word(hw, pba_ptr, &pba_size);
1102 if (status) {
1103 hw_dbg(hw, "Failed to read PBA Block size.\n");
1104 return status;
1105 }
1106
1107 /* Subtract one to get PBA word count (PBA Size word is included in
1108 * total size)
1109 */
1110 pba_size--;
1111 if (pba_num_size < (((u32)pba_size * 2) + 1)) {
1112 hw_dbg(hw, "Buffer to small for PBA data.\n");
1113 return I40E_ERR_PARAM;
1114 }
1115
1116 for (i = 0; i < pba_size; i++) {
1117 status = i40e_read_nvm_word(hw, (pba_ptr + 1) + i, &pba_word);
1118 if (status) {
1119 hw_dbg(hw, "Failed to read PBA Block word %d.\n", i);
1120 return status;
1121 }
1122
1123 pba_num[(i * 2)] = (pba_word >> 8) & 0xFF;
1124 pba_num[(i * 2) + 1] = pba_word & 0xFF;
1125 }
1126 pba_num[(pba_size * 2)] = '\0';
1127
1128 return status;
1129}
1130
1131/**
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001132 * i40e_get_media_type - Gets media type
1133 * @hw: pointer to the hardware structure
1134 **/
1135static enum i40e_media_type i40e_get_media_type(struct i40e_hw *hw)
1136{
1137 enum i40e_media_type media;
1138
1139 switch (hw->phy.link_info.phy_type) {
1140 case I40E_PHY_TYPE_10GBASE_SR:
1141 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +00001142 case I40E_PHY_TYPE_1000BASE_SX:
1143 case I40E_PHY_TYPE_1000BASE_LX:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001144 case I40E_PHY_TYPE_40GBASE_SR4:
1145 case I40E_PHY_TYPE_40GBASE_LR4:
Carolyn Wyborny31232372016-11-21 13:03:48 -08001146 case I40E_PHY_TYPE_25GBASE_LR:
1147 case I40E_PHY_TYPE_25GBASE_SR:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001148 media = I40E_MEDIA_TYPE_FIBER;
1149 break;
1150 case I40E_PHY_TYPE_100BASE_TX:
1151 case I40E_PHY_TYPE_1000BASE_T:
1152 case I40E_PHY_TYPE_10GBASE_T:
1153 media = I40E_MEDIA_TYPE_BASET;
1154 break;
1155 case I40E_PHY_TYPE_10GBASE_CR1_CU:
1156 case I40E_PHY_TYPE_40GBASE_CR4_CU:
1157 case I40E_PHY_TYPE_10GBASE_CR1:
1158 case I40E_PHY_TYPE_40GBASE_CR4:
1159 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +00001160 case I40E_PHY_TYPE_40GBASE_AOC:
1161 case I40E_PHY_TYPE_10GBASE_AOC:
Carolyn Wyborny31232372016-11-21 13:03:48 -08001162 case I40E_PHY_TYPE_25GBASE_CR:
Sudheer Mogilappagari211b4c12017-10-05 14:53:39 -07001163 case I40E_PHY_TYPE_25GBASE_AOC:
1164 case I40E_PHY_TYPE_25GBASE_ACC:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001165 media = I40E_MEDIA_TYPE_DA;
1166 break;
1167 case I40E_PHY_TYPE_1000BASE_KX:
1168 case I40E_PHY_TYPE_10GBASE_KX4:
1169 case I40E_PHY_TYPE_10GBASE_KR:
1170 case I40E_PHY_TYPE_40GBASE_KR4:
Jesse Brandeburgae24b402015-03-27 00:12:09 -07001171 case I40E_PHY_TYPE_20GBASE_KR2:
Carolyn Wyborny31232372016-11-21 13:03:48 -08001172 case I40E_PHY_TYPE_25GBASE_KR:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001173 media = I40E_MEDIA_TYPE_BACKPLANE;
1174 break;
1175 case I40E_PHY_TYPE_SGMII:
1176 case I40E_PHY_TYPE_XAUI:
1177 case I40E_PHY_TYPE_XFI:
1178 case I40E_PHY_TYPE_XLAUI:
1179 case I40E_PHY_TYPE_XLPPI:
1180 default:
1181 media = I40E_MEDIA_TYPE_UNKNOWN;
1182 break;
1183 }
1184
1185 return media;
1186}
1187
Paweł Jabłoński12d80bc2018-03-19 09:28:04 -07001188/**
1189 * i40e_poll_globr - Poll for Global Reset completion
1190 * @hw: pointer to the hardware structure
1191 * @retry_limit: how many times to retry before failure
1192 **/
1193static i40e_status i40e_poll_globr(struct i40e_hw *hw,
1194 u32 retry_limit)
1195{
1196 u32 cnt, reg = 0;
1197
1198 for (cnt = 0; cnt < retry_limit; cnt++) {
1199 reg = rd32(hw, I40E_GLGEN_RSTAT);
1200 if (!(reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK))
1201 return 0;
1202 msleep(100);
1203 }
1204
1205 hw_dbg(hw, "Global reset failed.\n");
1206 hw_dbg(hw, "I40E_GLGEN_RSTAT = 0x%x\n", reg);
1207
1208 return I40E_ERR_RESET_FAILED;
1209}
1210
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001211#define I40E_PF_RESET_WAIT_COUNT_A0 200
Akeem G Abodunrin8af580d2015-03-27 00:12:10 -07001212#define I40E_PF_RESET_WAIT_COUNT 200
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001213/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001214 * i40e_pf_reset - Reset the PF
1215 * @hw: pointer to the hardware structure
1216 *
1217 * Assuming someone else has triggered a global reset,
1218 * assure the global reset is complete and then reset the PF
1219 **/
1220i40e_status i40e_pf_reset(struct i40e_hw *hw)
1221{
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001222 u32 cnt = 0;
Shannon Nelson42794bd2013-12-11 08:17:10 +00001223 u32 cnt1 = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001224 u32 reg = 0;
1225 u32 grst_del;
1226
1227 /* Poll for Global Reset steady state in case of recent GRST.
1228 * The grst delay value is in 100ms units, and we'll wait a
1229 * couple counts longer to be sure we don't just miss the end.
1230 */
Shannon Nelsonde78fc52015-02-21 06:41:47 +00001231 grst_del = (rd32(hw, I40E_GLGEN_RSTCTL) &
1232 I40E_GLGEN_RSTCTL_GRSTDEL_MASK) >>
1233 I40E_GLGEN_RSTCTL_GRSTDEL_SHIFT;
Kevin Scott4d7cec02016-02-17 16:12:13 -08001234
1235 /* It can take upto 15 secs for GRST steady state.
1236 * Bump it to 16 secs max to be safe.
1237 */
1238 grst_del = grst_del * 20;
1239
1240 for (cnt = 0; cnt < grst_del; cnt++) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001241 reg = rd32(hw, I40E_GLGEN_RSTAT);
1242 if (!(reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK))
1243 break;
1244 msleep(100);
1245 }
1246 if (reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
1247 hw_dbg(hw, "Global reset polling failed to complete.\n");
1248 return I40E_ERR_RESET_FAILED;
1249 }
1250
Shannon Nelson42794bd2013-12-11 08:17:10 +00001251 /* Now Wait for the FW to be ready */
1252 for (cnt1 = 0; cnt1 < I40E_PF_RESET_WAIT_COUNT; cnt1++) {
1253 reg = rd32(hw, I40E_GLNVM_ULD);
1254 reg &= (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
1255 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK);
1256 if (reg == (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
1257 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK)) {
1258 hw_dbg(hw, "Core and Global modules ready %d\n", cnt1);
1259 break;
1260 }
1261 usleep_range(10000, 20000);
1262 }
1263 if (!(reg & (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
1264 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK))) {
1265 hw_dbg(hw, "wait for FW Reset complete timedout\n");
1266 hw_dbg(hw, "I40E_GLNVM_ULD = 0x%x\n", reg);
1267 return I40E_ERR_RESET_FAILED;
1268 }
1269
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001270 /* If there was a Global Reset in progress when we got here,
1271 * we don't need to do the PF Reset
1272 */
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001273 if (!cnt) {
Filip Sadowski94075bb2017-11-14 07:00:49 -05001274 u32 reg2 = 0;
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001275 if (hw->revision_id == 0)
1276 cnt = I40E_PF_RESET_WAIT_COUNT_A0;
1277 else
1278 cnt = I40E_PF_RESET_WAIT_COUNT;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001279 reg = rd32(hw, I40E_PFGEN_CTRL);
1280 wr32(hw, I40E_PFGEN_CTRL,
1281 (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001282 for (; cnt; cnt--) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001283 reg = rd32(hw, I40E_PFGEN_CTRL);
1284 if (!(reg & I40E_PFGEN_CTRL_PFSWR_MASK))
1285 break;
Filip Sadowski94075bb2017-11-14 07:00:49 -05001286 reg2 = rd32(hw, I40E_GLGEN_RSTAT);
Paweł Jabłoński12d80bc2018-03-19 09:28:04 -07001287 if (reg2 & I40E_GLGEN_RSTAT_DEVSTATE_MASK)
1288 break;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001289 usleep_range(1000, 2000);
1290 }
Paweł Jabłoński12d80bc2018-03-19 09:28:04 -07001291 if (reg2 & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
1292 if (i40e_poll_globr(hw, grst_del))
1293 return I40E_ERR_RESET_FAILED;
1294 } else if (reg & I40E_PFGEN_CTRL_PFSWR_MASK) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001295 hw_dbg(hw, "PF reset polling failed to complete.\n");
1296 return I40E_ERR_RESET_FAILED;
1297 }
1298 }
1299
1300 i40e_clear_pxe_mode(hw);
Shannon Nelson922680b2013-12-18 05:29:17 +00001301
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001302 return 0;
1303}
1304
1305/**
Shannon Nelson838d41d2014-06-04 20:41:27 +00001306 * i40e_clear_hw - clear out any left over hw state
1307 * @hw: pointer to the hw struct
1308 *
1309 * Clear queues and interrupts, typically called at init time,
1310 * but after the capabilities have been found so we know how many
1311 * queues and msix vectors have been allocated.
1312 **/
1313void i40e_clear_hw(struct i40e_hw *hw)
1314{
1315 u32 num_queues, base_queue;
1316 u32 num_pf_int;
1317 u32 num_vf_int;
1318 u32 num_vfs;
1319 u32 i, j;
1320 u32 val;
1321 u32 eol = 0x7ff;
1322
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00001323 /* get number of interrupts, queues, and VFs */
Shannon Nelson838d41d2014-06-04 20:41:27 +00001324 val = rd32(hw, I40E_GLPCI_CNF2);
1325 num_pf_int = (val & I40E_GLPCI_CNF2_MSI_X_PF_N_MASK) >>
1326 I40E_GLPCI_CNF2_MSI_X_PF_N_SHIFT;
1327 num_vf_int = (val & I40E_GLPCI_CNF2_MSI_X_VF_N_MASK) >>
1328 I40E_GLPCI_CNF2_MSI_X_VF_N_SHIFT;
1329
Shannon Nelson272cdaf22016-02-17 16:12:21 -08001330 val = rd32(hw, I40E_PFLAN_QALLOC);
Shannon Nelson838d41d2014-06-04 20:41:27 +00001331 base_queue = (val & I40E_PFLAN_QALLOC_FIRSTQ_MASK) >>
1332 I40E_PFLAN_QALLOC_FIRSTQ_SHIFT;
1333 j = (val & I40E_PFLAN_QALLOC_LASTQ_MASK) >>
1334 I40E_PFLAN_QALLOC_LASTQ_SHIFT;
1335 if (val & I40E_PFLAN_QALLOC_VALID_MASK)
1336 num_queues = (j - base_queue) + 1;
1337 else
1338 num_queues = 0;
1339
1340 val = rd32(hw, I40E_PF_VT_PFALLOC);
1341 i = (val & I40E_PF_VT_PFALLOC_FIRSTVF_MASK) >>
1342 I40E_PF_VT_PFALLOC_FIRSTVF_SHIFT;
1343 j = (val & I40E_PF_VT_PFALLOC_LASTVF_MASK) >>
1344 I40E_PF_VT_PFALLOC_LASTVF_SHIFT;
1345 if (val & I40E_PF_VT_PFALLOC_VALID_MASK)
1346 num_vfs = (j - i) + 1;
1347 else
1348 num_vfs = 0;
1349
1350 /* stop all the interrupts */
1351 wr32(hw, I40E_PFINT_ICR0_ENA, 0);
1352 val = 0x3 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT;
1353 for (i = 0; i < num_pf_int - 2; i++)
1354 wr32(hw, I40E_PFINT_DYN_CTLN(i), val);
1355
1356 /* Set the FIRSTQ_INDX field to 0x7FF in PFINT_LNKLSTx */
1357 val = eol << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
1358 wr32(hw, I40E_PFINT_LNKLST0, val);
1359 for (i = 0; i < num_pf_int - 2; i++)
1360 wr32(hw, I40E_PFINT_LNKLSTN(i), val);
1361 val = eol << I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT;
1362 for (i = 0; i < num_vfs; i++)
1363 wr32(hw, I40E_VPINT_LNKLST0(i), val);
1364 for (i = 0; i < num_vf_int - 2; i++)
1365 wr32(hw, I40E_VPINT_LNKLSTN(i), val);
1366
1367 /* warn the HW of the coming Tx disables */
1368 for (i = 0; i < num_queues; i++) {
1369 u32 abs_queue_idx = base_queue + i;
1370 u32 reg_block = 0;
1371
1372 if (abs_queue_idx >= 128) {
1373 reg_block = abs_queue_idx / 128;
1374 abs_queue_idx %= 128;
1375 }
1376
1377 val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
1378 val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
1379 val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
1380 val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
1381
1382 wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), val);
1383 }
1384 udelay(400);
1385
1386 /* stop all the queues */
1387 for (i = 0; i < num_queues; i++) {
1388 wr32(hw, I40E_QINT_TQCTL(i), 0);
1389 wr32(hw, I40E_QTX_ENA(i), 0);
1390 wr32(hw, I40E_QINT_RQCTL(i), 0);
1391 wr32(hw, I40E_QRX_ENA(i), 0);
1392 }
1393
1394 /* short wait for all queue disables to settle */
1395 udelay(50);
1396}
1397
1398/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001399 * i40e_clear_pxe_mode - clear pxe operations mode
1400 * @hw: pointer to the hw struct
1401 *
1402 * Make sure all PXE mode settings are cleared, including things
1403 * like descriptor fetch/write-back mode.
1404 **/
1405void i40e_clear_pxe_mode(struct i40e_hw *hw)
1406{
1407 u32 reg;
1408
Shannon Nelsonc9b9b0a2014-04-09 05:59:05 +00001409 if (i40e_check_asq_alive(hw))
1410 i40e_aq_clear_pxe_mode(hw, NULL);
1411
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001412 /* Clear single descriptor fetch/write-back mode */
1413 reg = rd32(hw, I40E_GLLAN_RCTL_0);
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001414
1415 if (hw->revision_id == 0) {
1416 /* As a work around clear PXE_MODE instead of setting it */
1417 wr32(hw, I40E_GLLAN_RCTL_0, (reg & (~I40E_GLLAN_RCTL_0_PXE_MODE_MASK)));
1418 } else {
1419 wr32(hw, I40E_GLLAN_RCTL_0, (reg | I40E_GLLAN_RCTL_0_PXE_MODE_MASK));
1420 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001421}
1422
1423/**
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001424 * i40e_led_is_mine - helper to find matching led
1425 * @hw: pointer to the hw struct
1426 * @idx: index into GPIO registers
1427 *
1428 * returns: 0 if no match, otherwise the value of the GPIO_CTL register
1429 */
1430static u32 i40e_led_is_mine(struct i40e_hw *hw, int idx)
1431{
1432 u32 gpio_val = 0;
1433 u32 port;
1434
1435 if (!hw->func_caps.led[idx])
1436 return 0;
1437
1438 gpio_val = rd32(hw, I40E_GLGEN_GPIO_CTL(idx));
1439 port = (gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_MASK) >>
1440 I40E_GLGEN_GPIO_CTL_PRT_NUM_SHIFT;
1441
1442 /* if PRT_NUM_NA is 1 then this LED is not port specific, OR
1443 * if it is not our port then ignore
1444 */
1445 if ((gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_NA_MASK) ||
1446 (port != hw->port))
1447 return 0;
1448
1449 return gpio_val;
1450}
1451
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001452#define I40E_COMBINED_ACTIVITY 0xA
1453#define I40E_FILTER_ACTIVITY 0xE
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001454#define I40E_LINK_ACTIVITY 0xC
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001455#define I40E_MAC_ACTIVITY 0xD
1456#define I40E_LED0 22
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001457
1458/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001459 * i40e_led_get - return current on/off mode
1460 * @hw: pointer to the hw struct
1461 *
1462 * The value returned is the 'mode' field as defined in the
1463 * GPIO register definitions: 0x0 = off, 0xf = on, and other
1464 * values are variations of possible behaviors relating to
1465 * blink, link, and wire.
1466 **/
1467u32 i40e_led_get(struct i40e_hw *hw)
1468{
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001469 u32 current_mode = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001470 u32 mode = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001471 int i;
1472
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001473 /* as per the documentation GPIO 22-29 are the LED
1474 * GPIO pins named LED0..LED7
1475 */
1476 for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
1477 u32 gpio_val = i40e_led_is_mine(hw, i);
1478
1479 if (!gpio_val)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001480 continue;
1481
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001482 /* ignore gpio LED src mode entries related to the activity
1483 * LEDs
1484 */
1485 current_mode = ((gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK)
1486 >> I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT);
1487 switch (current_mode) {
1488 case I40E_COMBINED_ACTIVITY:
1489 case I40E_FILTER_ACTIVITY:
1490 case I40E_MAC_ACTIVITY:
Michal Kuchtad95cd482017-12-18 05:17:03 -05001491 case I40E_LINK_ACTIVITY:
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001492 continue;
1493 default:
1494 break;
1495 }
1496
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001497 mode = (gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK) >>
1498 I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001499 break;
1500 }
1501
1502 return mode;
1503}
1504
1505/**
1506 * i40e_led_set - set new on/off mode
1507 * @hw: pointer to the hw struct
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001508 * @mode: 0=off, 0xf=on (else see manual for mode details)
1509 * @blink: true if the LED should blink when on, false if steady
1510 *
1511 * if this function is used to turn on the blink it should
1512 * be used to disable the blink when restoring the original state.
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001513 **/
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001514void i40e_led_set(struct i40e_hw *hw, u32 mode, bool blink)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001515{
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001516 u32 current_mode = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001517 int i;
1518
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001519 if (mode & 0xfffffff0)
1520 hw_dbg(hw, "invalid mode passed in %X\n", mode);
1521
1522 /* as per the documentation GPIO 22-29 are the LED
1523 * GPIO pins named LED0..LED7
1524 */
1525 for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
1526 u32 gpio_val = i40e_led_is_mine(hw, i);
1527
1528 if (!gpio_val)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001529 continue;
1530
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001531 /* ignore gpio LED src mode entries related to the activity
1532 * LEDs
1533 */
1534 current_mode = ((gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK)
1535 >> I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT);
1536 switch (current_mode) {
1537 case I40E_COMBINED_ACTIVITY:
1538 case I40E_FILTER_ACTIVITY:
1539 case I40E_MAC_ACTIVITY:
Michal Kuchtad95cd482017-12-18 05:17:03 -05001540 case I40E_LINK_ACTIVITY:
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001541 continue;
1542 default:
1543 break;
1544 }
1545
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001546 gpio_val &= ~I40E_GLGEN_GPIO_CTL_LED_MODE_MASK;
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001547 /* this & is a bit of paranoia, but serves as a range check */
1548 gpio_val |= ((mode << I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT) &
1549 I40E_GLGEN_GPIO_CTL_LED_MODE_MASK);
1550
Matt Jared9be00d62015-01-24 09:58:28 +00001551 if (blink)
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001552 gpio_val |= BIT(I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
Matt Jared9be00d62015-01-24 09:58:28 +00001553 else
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001554 gpio_val &= ~BIT(I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001555
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001556 wr32(hw, I40E_GLGEN_GPIO_CTL(i), gpio_val);
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001557 break;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001558 }
1559}
1560
1561/* Admin command wrappers */
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001562
1563/**
Catherine Sullivan8109e122014-06-04 08:45:24 +00001564 * i40e_aq_get_phy_capabilities
1565 * @hw: pointer to the hw struct
1566 * @abilities: structure for PHY capabilities to be filled
1567 * @qualified_modules: report Qualified Modules
1568 * @report_init: report init capabilities (active are default)
1569 * @cmd_details: pointer to command details structure or NULL
1570 *
1571 * Returns the various PHY abilities supported on the Port.
1572 **/
1573i40e_status i40e_aq_get_phy_capabilities(struct i40e_hw *hw,
1574 bool qualified_modules, bool report_init,
1575 struct i40e_aq_get_phy_abilities_resp *abilities,
1576 struct i40e_asq_cmd_details *cmd_details)
1577{
1578 struct i40e_aq_desc desc;
1579 i40e_status status;
1580 u16 abilities_size = sizeof(struct i40e_aq_get_phy_abilities_resp);
Jayaprakash Shanmugam49884102017-09-07 08:05:55 -04001581 u16 max_delay = I40E_MAX_PHY_TIMEOUT, total_delay = 0;
Catherine Sullivan8109e122014-06-04 08:45:24 +00001582
1583 if (!abilities)
1584 return I40E_ERR_PARAM;
1585
Jayaprakash Shanmugam49884102017-09-07 08:05:55 -04001586 do {
1587 i40e_fill_default_direct_cmd_desc(&desc,
1588 i40e_aqc_opc_get_phy_abilities);
Catherine Sullivan8109e122014-06-04 08:45:24 +00001589
Jayaprakash Shanmugam49884102017-09-07 08:05:55 -04001590 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
1591 if (abilities_size > I40E_AQ_LARGE_BUF)
1592 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
Catherine Sullivan8109e122014-06-04 08:45:24 +00001593
Jayaprakash Shanmugam49884102017-09-07 08:05:55 -04001594 if (qualified_modules)
1595 desc.params.external.param0 |=
Catherine Sullivan8109e122014-06-04 08:45:24 +00001596 cpu_to_le32(I40E_AQ_PHY_REPORT_QUALIFIED_MODULES);
1597
Jayaprakash Shanmugam49884102017-09-07 08:05:55 -04001598 if (report_init)
1599 desc.params.external.param0 |=
Catherine Sullivan8109e122014-06-04 08:45:24 +00001600 cpu_to_le32(I40E_AQ_PHY_REPORT_INITIAL_VALUES);
1601
Jayaprakash Shanmugam49884102017-09-07 08:05:55 -04001602 status = i40e_asq_send_command(hw, &desc, abilities,
1603 abilities_size, cmd_details);
Catherine Sullivan8109e122014-06-04 08:45:24 +00001604
Jayaprakash Shanmugam49884102017-09-07 08:05:55 -04001605 if (status)
1606 break;
1607
1608 if (hw->aq.asq_last_status == I40E_AQ_RC_EIO) {
1609 status = I40E_ERR_UNKNOWN_PHY;
1610 break;
1611 } else if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN) {
1612 usleep_range(1000, 2000);
1613 total_delay++;
1614 status = I40E_ERR_TIMEOUT;
1615 }
1616 } while ((hw->aq.asq_last_status != I40E_AQ_RC_OK) &&
1617 (total_delay < max_delay));
1618
1619 if (status)
1620 return status;
Catherine Sullivan8109e122014-06-04 08:45:24 +00001621
Carolyn Wyborny31232372016-11-21 13:03:48 -08001622 if (report_init) {
Mitch Williams22b965512017-07-14 09:27:09 -04001623 if (hw->mac.type == I40E_MAC_XL710 &&
1624 hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
Alan Brady8fdb69d2017-10-11 14:49:42 -07001625 hw->aq.api_min_ver >= I40E_MINOR_VER_GET_LINK_INFO_XL710) {
Mitch Williams22b965512017-07-14 09:27:09 -04001626 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
Alan Brady8fdb69d2017-10-11 14:49:42 -07001627 } else {
1628 hw->phy.phy_types = le32_to_cpu(abilities->phy_type);
1629 hw->phy.phy_types |=
1630 ((u64)abilities->phy_type_ext << 32);
1631 }
Carolyn Wyborny31232372016-11-21 13:03:48 -08001632 }
Kevin Scott3ac67d72015-09-03 17:18:58 -04001633
Catherine Sullivan8109e122014-06-04 08:45:24 +00001634 return status;
1635}
1636
1637/**
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001638 * i40e_aq_set_phy_config
1639 * @hw: pointer to the hw struct
1640 * @config: structure with PHY configuration to be set
1641 * @cmd_details: pointer to command details structure or NULL
1642 *
1643 * Set the various PHY configuration parameters
1644 * supported on the Port.One or more of the Set PHY config parameters may be
1645 * ignored in an MFP mode as the PF may not have the privilege to set some
1646 * of the PHY Config parameters. This status will be indicated by the
1647 * command response.
1648 **/
1649enum i40e_status_code i40e_aq_set_phy_config(struct i40e_hw *hw,
1650 struct i40e_aq_set_phy_config *config,
1651 struct i40e_asq_cmd_details *cmd_details)
1652{
1653 struct i40e_aq_desc desc;
1654 struct i40e_aq_set_phy_config *cmd =
1655 (struct i40e_aq_set_phy_config *)&desc.params.raw;
1656 enum i40e_status_code status;
1657
1658 if (!config)
1659 return I40E_ERR_PARAM;
1660
1661 i40e_fill_default_direct_cmd_desc(&desc,
1662 i40e_aqc_opc_set_phy_config);
1663
1664 *cmd = *config;
1665
1666 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1667
1668 return status;
1669}
1670
1671/**
1672 * i40e_set_fc
1673 * @hw: pointer to the hw struct
Jacob Kellerf5254422018-04-20 01:41:33 -07001674 * @aq_failures: buffer to return AdminQ failure information
1675 * @atomic_restart: whether to enable atomic link restart
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001676 *
1677 * Set the requested flow control mode using set_phy_config.
1678 **/
1679enum i40e_status_code i40e_set_fc(struct i40e_hw *hw, u8 *aq_failures,
1680 bool atomic_restart)
1681{
1682 enum i40e_fc_mode fc_mode = hw->fc.requested_mode;
1683 struct i40e_aq_get_phy_abilities_resp abilities;
1684 struct i40e_aq_set_phy_config config;
1685 enum i40e_status_code status;
1686 u8 pause_mask = 0x0;
1687
1688 *aq_failures = 0x0;
1689
1690 switch (fc_mode) {
1691 case I40E_FC_FULL:
1692 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
1693 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
1694 break;
1695 case I40E_FC_RX_PAUSE:
1696 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
1697 break;
1698 case I40E_FC_TX_PAUSE:
1699 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
1700 break;
1701 default:
1702 break;
1703 }
1704
1705 /* Get the current phy config */
1706 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
1707 NULL);
1708 if (status) {
1709 *aq_failures |= I40E_SET_FC_AQ_FAIL_GET;
1710 return status;
1711 }
1712
1713 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
1714 /* clear the old pause settings */
1715 config.abilities = abilities.abilities & ~(I40E_AQ_PHY_FLAG_PAUSE_TX) &
1716 ~(I40E_AQ_PHY_FLAG_PAUSE_RX);
1717 /* set the new abilities */
1718 config.abilities |= pause_mask;
1719 /* If the abilities have changed, then set the new config */
1720 if (config.abilities != abilities.abilities) {
1721 /* Auto restart link so settings take effect */
1722 if (atomic_restart)
1723 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
1724 /* Copy over all the old settings */
1725 config.phy_type = abilities.phy_type;
Carolyn Wyborny31232372016-11-21 13:03:48 -08001726 config.phy_type_ext = abilities.phy_type_ext;
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001727 config.link_speed = abilities.link_speed;
1728 config.eee_capability = abilities.eee_capability;
1729 config.eeer = abilities.eeer_val;
1730 config.low_power_ctrl = abilities.d3_lpan;
Carolyn Wyborny60f000a2016-11-21 13:03:49 -08001731 config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
1732 I40E_AQ_PHY_FEC_CONFIG_MASK;
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001733 status = i40e_aq_set_phy_config(hw, &config, NULL);
1734
1735 if (status)
1736 *aq_failures |= I40E_SET_FC_AQ_FAIL_SET;
1737 }
1738 /* Update the link info */
Catherine Sullivan0a862b42015-08-31 19:54:53 -04001739 status = i40e_update_link_info(hw);
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001740 if (status) {
1741 /* Wait a little bit (on 40G cards it sometimes takes a really
1742 * long time for link to come back from the atomic reset)
1743 * and try once more
1744 */
1745 msleep(1000);
Catherine Sullivan0a862b42015-08-31 19:54:53 -04001746 status = i40e_update_link_info(hw);
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001747 }
1748 if (status)
1749 *aq_failures |= I40E_SET_FC_AQ_FAIL_UPDATE;
1750
1751 return status;
1752}
1753
1754/**
Shannon Nelsonc9b9b0a2014-04-09 05:59:05 +00001755 * i40e_aq_clear_pxe_mode
1756 * @hw: pointer to the hw struct
1757 * @cmd_details: pointer to command details structure or NULL
1758 *
1759 * Tell the firmware that the driver is taking over from PXE
1760 **/
1761i40e_status i40e_aq_clear_pxe_mode(struct i40e_hw *hw,
1762 struct i40e_asq_cmd_details *cmd_details)
1763{
1764 i40e_status status;
1765 struct i40e_aq_desc desc;
1766 struct i40e_aqc_clear_pxe *cmd =
1767 (struct i40e_aqc_clear_pxe *)&desc.params.raw;
1768
1769 i40e_fill_default_direct_cmd_desc(&desc,
1770 i40e_aqc_opc_clear_pxe_mode);
1771
1772 cmd->rx_cnt = 0x2;
1773
1774 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1775
1776 wr32(hw, I40E_GLLAN_RCTL_0, 0x1);
1777
1778 return status;
1779}
1780
1781/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001782 * i40e_aq_set_link_restart_an
1783 * @hw: pointer to the hw struct
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001784 * @enable_link: if true: enable link, if false: disable link
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001785 * @cmd_details: pointer to command details structure or NULL
1786 *
1787 * Sets up the link and restarts the Auto-Negotiation over the link.
1788 **/
1789i40e_status i40e_aq_set_link_restart_an(struct i40e_hw *hw,
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001790 bool enable_link,
1791 struct i40e_asq_cmd_details *cmd_details)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001792{
1793 struct i40e_aq_desc desc;
1794 struct i40e_aqc_set_link_restart_an *cmd =
1795 (struct i40e_aqc_set_link_restart_an *)&desc.params.raw;
1796 i40e_status status;
1797
1798 i40e_fill_default_direct_cmd_desc(&desc,
1799 i40e_aqc_opc_set_link_restart_an);
1800
1801 cmd->command = I40E_AQ_PHY_RESTART_AN;
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001802 if (enable_link)
1803 cmd->command |= I40E_AQ_PHY_LINK_ENABLE;
1804 else
1805 cmd->command &= ~I40E_AQ_PHY_LINK_ENABLE;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001806
1807 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1808
1809 return status;
1810}
1811
1812/**
1813 * i40e_aq_get_link_info
1814 * @hw: pointer to the hw struct
1815 * @enable_lse: enable/disable LinkStatusEvent reporting
1816 * @link: pointer to link status structure - optional
1817 * @cmd_details: pointer to command details structure or NULL
1818 *
1819 * Returns the link status of the adapter.
1820 **/
1821i40e_status i40e_aq_get_link_info(struct i40e_hw *hw,
1822 bool enable_lse, struct i40e_link_status *link,
1823 struct i40e_asq_cmd_details *cmd_details)
1824{
1825 struct i40e_aq_desc desc;
1826 struct i40e_aqc_get_link_status *resp =
1827 (struct i40e_aqc_get_link_status *)&desc.params.raw;
1828 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
1829 i40e_status status;
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001830 bool tx_pause, rx_pause;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001831 u16 command_flags;
1832
1833 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_link_status);
1834
1835 if (enable_lse)
1836 command_flags = I40E_AQ_LSE_ENABLE;
1837 else
1838 command_flags = I40E_AQ_LSE_DISABLE;
1839 resp->command_flags = cpu_to_le16(command_flags);
1840
1841 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1842
1843 if (status)
1844 goto aq_get_link_info_exit;
1845
1846 /* save off old link status information */
Mitch Williamsc36bd4a72013-12-18 13:46:04 +00001847 hw->phy.link_info_old = *hw_link_info;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001848
1849 /* update link status */
1850 hw_link_info->phy_type = (enum i40e_aq_phy_type)resp->phy_type;
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001851 hw->phy.media_type = i40e_get_media_type(hw);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001852 hw_link_info->link_speed = (enum i40e_aq_link_speed)resp->link_speed;
1853 hw_link_info->link_info = resp->link_info;
1854 hw_link_info->an_info = resp->an_info;
Henry Tieman3e03d7c2016-12-02 12:32:57 -08001855 hw_link_info->fec_info = resp->config & (I40E_AQ_CONFIG_FEC_KR_ENA |
1856 I40E_AQ_CONFIG_FEC_RS_ENA);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001857 hw_link_info->ext_info = resp->ext_info;
Filip Sadowskid60bcc72017-08-22 06:57:43 -04001858 hw_link_info->loopback = resp->loopback & I40E_AQ_LOOPBACK_MASK;
Neerav Parikh6bb3f232014-04-01 07:11:56 +00001859 hw_link_info->max_frame_size = le16_to_cpu(resp->max_frame_size);
1860 hw_link_info->pacing = resp->config & I40E_AQ_CONFIG_PACING_MASK;
1861
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001862 /* update fc info */
1863 tx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_TX);
1864 rx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_RX);
1865 if (tx_pause & rx_pause)
1866 hw->fc.current_mode = I40E_FC_FULL;
1867 else if (tx_pause)
1868 hw->fc.current_mode = I40E_FC_TX_PAUSE;
1869 else if (rx_pause)
1870 hw->fc.current_mode = I40E_FC_RX_PAUSE;
1871 else
1872 hw->fc.current_mode = I40E_FC_NONE;
1873
Neerav Parikh6bb3f232014-04-01 07:11:56 +00001874 if (resp->config & I40E_AQ_CONFIG_CRC_ENA)
1875 hw_link_info->crc_enable = true;
1876 else
1877 hw_link_info->crc_enable = false;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001878
Filip Sadowski7ed35732016-09-14 16:24:33 -07001879 if (resp->command_flags & cpu_to_le16(I40E_AQ_LSE_IS_ENABLED))
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001880 hw_link_info->lse_enable = true;
1881 else
1882 hw_link_info->lse_enable = false;
1883
Henry Tiemane586bb62016-11-08 13:05:07 -08001884 if ((hw->mac.type == I40E_MAC_XL710) &&
1885 (hw->aq.fw_maj_ver < 4 || (hw->aq.fw_maj_ver == 4 &&
Catherine Sullivan088c4ee2015-02-26 16:14:12 +00001886 hw->aq.fw_min_ver < 40)) && hw_link_info->phy_type == 0xE)
1887 hw_link_info->phy_type = I40E_PHY_TYPE_10GBASE_SFPP_CU;
1888
Filip Sadowskid60bcc72017-08-22 06:57:43 -04001889 if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
1890 hw->aq.api_min_ver >= 7) {
1891 __le32 tmp;
1892
1893 memcpy(&tmp, resp->link_type, sizeof(tmp));
1894 hw->phy.phy_types = le32_to_cpu(tmp);
1895 hw->phy.phy_types |= ((u64)resp->link_type_ext << 32);
1896 }
1897
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001898 /* save link status information */
1899 if (link)
Jesse Brandeburgd7595a22013-09-13 08:23:22 +00001900 *link = *hw_link_info;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001901
1902 /* flag cleared so helper functions don't call AQ again */
1903 hw->phy.get_link_info = false;
1904
1905aq_get_link_info_exit:
1906 return status;
1907}
1908
1909/**
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00001910 * i40e_aq_set_phy_int_mask
1911 * @hw: pointer to the hw struct
1912 * @mask: interrupt mask to be set
1913 * @cmd_details: pointer to command details structure or NULL
1914 *
1915 * Set link interrupt mask.
1916 **/
1917i40e_status i40e_aq_set_phy_int_mask(struct i40e_hw *hw,
1918 u16 mask,
1919 struct i40e_asq_cmd_details *cmd_details)
1920{
1921 struct i40e_aq_desc desc;
1922 struct i40e_aqc_set_phy_int_mask *cmd =
1923 (struct i40e_aqc_set_phy_int_mask *)&desc.params.raw;
1924 i40e_status status;
1925
1926 i40e_fill_default_direct_cmd_desc(&desc,
1927 i40e_aqc_opc_set_phy_int_mask);
1928
1929 cmd->event_mask = cpu_to_le16(mask);
1930
1931 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1932
1933 return status;
1934}
1935
1936/**
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001937 * i40e_aq_set_phy_debug
1938 * @hw: pointer to the hw struct
1939 * @cmd_flags: debug command flags
1940 * @cmd_details: pointer to command details structure or NULL
1941 *
1942 * Reset the external PHY.
1943 **/
Jesse Brandeburg61829022016-03-10 14:59:42 -08001944i40e_status i40e_aq_set_phy_debug(struct i40e_hw *hw, u8 cmd_flags,
1945 struct i40e_asq_cmd_details *cmd_details)
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001946{
1947 struct i40e_aq_desc desc;
1948 struct i40e_aqc_set_phy_debug *cmd =
1949 (struct i40e_aqc_set_phy_debug *)&desc.params.raw;
Jesse Brandeburg61829022016-03-10 14:59:42 -08001950 i40e_status status;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001951
1952 i40e_fill_default_direct_cmd_desc(&desc,
1953 i40e_aqc_opc_set_phy_debug);
1954
1955 cmd->command_flags = cmd_flags;
1956
1957 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1958
1959 return status;
1960}
1961
1962/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001963 * i40e_aq_add_vsi
1964 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00001965 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001966 * @cmd_details: pointer to command details structure or NULL
1967 *
1968 * Add a VSI context to the hardware.
1969**/
1970i40e_status i40e_aq_add_vsi(struct i40e_hw *hw,
1971 struct i40e_vsi_context *vsi_ctx,
1972 struct i40e_asq_cmd_details *cmd_details)
1973{
1974 struct i40e_aq_desc desc;
1975 struct i40e_aqc_add_get_update_vsi *cmd =
1976 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
1977 struct i40e_aqc_add_get_update_vsi_completion *resp =
1978 (struct i40e_aqc_add_get_update_vsi_completion *)
1979 &desc.params.raw;
1980 i40e_status status;
1981
1982 i40e_fill_default_direct_cmd_desc(&desc,
1983 i40e_aqc_opc_add_vsi);
1984
1985 cmd->uplink_seid = cpu_to_le16(vsi_ctx->uplink_seid);
1986 cmd->connection_type = vsi_ctx->connection_type;
1987 cmd->vf_id = vsi_ctx->vf_num;
1988 cmd->vsi_flags = cpu_to_le16(vsi_ctx->flags);
1989
1990 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001991
1992 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
1993 sizeof(vsi_ctx->info), cmd_details);
1994
1995 if (status)
1996 goto aq_add_vsi_exit;
1997
1998 vsi_ctx->seid = le16_to_cpu(resp->seid);
1999 vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
2000 vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
2001 vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
2002
2003aq_add_vsi_exit:
2004 return status;
2005}
2006
2007/**
Mitch Williamsfb70fab2016-05-16 10:26:31 -07002008 * i40e_aq_set_default_vsi
2009 * @hw: pointer to the hw struct
2010 * @seid: vsi number
2011 * @cmd_details: pointer to command details structure or NULL
2012 **/
2013i40e_status i40e_aq_set_default_vsi(struct i40e_hw *hw,
2014 u16 seid,
2015 struct i40e_asq_cmd_details *cmd_details)
2016{
2017 struct i40e_aq_desc desc;
2018 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2019 (struct i40e_aqc_set_vsi_promiscuous_modes *)
2020 &desc.params.raw;
2021 i40e_status status;
2022
2023 i40e_fill_default_direct_cmd_desc(&desc,
2024 i40e_aqc_opc_set_vsi_promiscuous_modes);
2025
2026 cmd->promiscuous_flags = cpu_to_le16(I40E_AQC_SET_VSI_DEFAULT);
2027 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_DEFAULT);
2028 cmd->seid = cpu_to_le16(seid);
2029
2030 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2031
2032 return status;
2033}
2034
2035/**
2036 * i40e_aq_clear_default_vsi
2037 * @hw: pointer to the hw struct
2038 * @seid: vsi number
2039 * @cmd_details: pointer to command details structure or NULL
2040 **/
2041i40e_status i40e_aq_clear_default_vsi(struct i40e_hw *hw,
2042 u16 seid,
2043 struct i40e_asq_cmd_details *cmd_details)
2044{
2045 struct i40e_aq_desc desc;
2046 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2047 (struct i40e_aqc_set_vsi_promiscuous_modes *)
2048 &desc.params.raw;
2049 i40e_status status;
2050
2051 i40e_fill_default_direct_cmd_desc(&desc,
2052 i40e_aqc_opc_set_vsi_promiscuous_modes);
2053
2054 cmd->promiscuous_flags = cpu_to_le16(0);
2055 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_DEFAULT);
2056 cmd->seid = cpu_to_le16(seid);
2057
2058 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2059
2060 return status;
2061}
2062
2063/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002064 * i40e_aq_set_vsi_unicast_promiscuous
2065 * @hw: pointer to the hw struct
2066 * @seid: vsi number
2067 * @set: set unicast promiscuous enable/disable
2068 * @cmd_details: pointer to command details structure or NULL
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002069 * @rx_only_promisc: flag to decide if egress traffic gets mirrored in promisc
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002070 **/
2071i40e_status i40e_aq_set_vsi_unicast_promiscuous(struct i40e_hw *hw,
Mitch Williams885552a2013-12-21 05:44:41 +00002072 u16 seid, bool set,
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002073 struct i40e_asq_cmd_details *cmd_details,
2074 bool rx_only_promisc)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002075{
2076 struct i40e_aq_desc desc;
2077 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2078 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2079 i40e_status status;
2080 u16 flags = 0;
2081
2082 i40e_fill_default_direct_cmd_desc(&desc,
2083 i40e_aqc_opc_set_vsi_promiscuous_modes);
2084
Anjali Singhai Jain3b120082016-01-15 14:33:21 -08002085 if (set) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002086 flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002087 if (rx_only_promisc &&
2088 (((hw->aq.api_maj_ver == 1) && (hw->aq.api_min_ver >= 5)) ||
2089 (hw->aq.api_maj_ver > 1)))
Anjali Singhai Jain3b120082016-01-15 14:33:21 -08002090 flags |= I40E_AQC_SET_VSI_PROMISC_TX;
2091 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002092
2093 cmd->promiscuous_flags = cpu_to_le16(flags);
2094
2095 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
Anjali Singhai Jain3b120082016-01-15 14:33:21 -08002096 if (((hw->aq.api_maj_ver >= 1) && (hw->aq.api_min_ver >= 5)) ||
2097 (hw->aq.api_maj_ver > 1))
2098 cmd->valid_flags |= cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_TX);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002099
2100 cmd->seid = cpu_to_le16(seid);
2101 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2102
2103 return status;
2104}
2105
2106/**
2107 * i40e_aq_set_vsi_multicast_promiscuous
2108 * @hw: pointer to the hw struct
2109 * @seid: vsi number
2110 * @set: set multicast promiscuous enable/disable
2111 * @cmd_details: pointer to command details structure or NULL
2112 **/
2113i40e_status i40e_aq_set_vsi_multicast_promiscuous(struct i40e_hw *hw,
2114 u16 seid, bool set, struct i40e_asq_cmd_details *cmd_details)
2115{
2116 struct i40e_aq_desc desc;
2117 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2118 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2119 i40e_status status;
2120 u16 flags = 0;
2121
2122 i40e_fill_default_direct_cmd_desc(&desc,
2123 i40e_aqc_opc_set_vsi_promiscuous_modes);
2124
2125 if (set)
2126 flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
2127
2128 cmd->promiscuous_flags = cpu_to_le16(flags);
2129
2130 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
2131
2132 cmd->seid = cpu_to_le16(seid);
2133 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2134
2135 return status;
2136}
2137
2138/**
Greg Rose6c41a762016-04-12 08:30:50 -07002139 * i40e_aq_set_vsi_mc_promisc_on_vlan
2140 * @hw: pointer to the hw struct
2141 * @seid: vsi number
2142 * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
2143 * @vid: The VLAN tag filter - capture any multicast packet with this VLAN tag
2144 * @cmd_details: pointer to command details structure or NULL
2145 **/
2146enum i40e_status_code i40e_aq_set_vsi_mc_promisc_on_vlan(struct i40e_hw *hw,
2147 u16 seid, bool enable,
2148 u16 vid,
2149 struct i40e_asq_cmd_details *cmd_details)
2150{
2151 struct i40e_aq_desc desc;
2152 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2153 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2154 enum i40e_status_code status;
2155 u16 flags = 0;
2156
2157 i40e_fill_default_direct_cmd_desc(&desc,
2158 i40e_aqc_opc_set_vsi_promiscuous_modes);
2159
2160 if (enable)
2161 flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
2162
2163 cmd->promiscuous_flags = cpu_to_le16(flags);
2164 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
2165 cmd->seid = cpu_to_le16(seid);
2166 cmd->vlan_tag = cpu_to_le16(vid | I40E_AQC_SET_VSI_VLAN_VALID);
2167
2168 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2169
2170 return status;
2171}
2172
2173/**
2174 * i40e_aq_set_vsi_uc_promisc_on_vlan
2175 * @hw: pointer to the hw struct
2176 * @seid: vsi number
2177 * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
2178 * @vid: The VLAN tag filter - capture any unicast packet with this VLAN tag
2179 * @cmd_details: pointer to command details structure or NULL
2180 **/
2181enum i40e_status_code i40e_aq_set_vsi_uc_promisc_on_vlan(struct i40e_hw *hw,
2182 u16 seid, bool enable,
2183 u16 vid,
2184 struct i40e_asq_cmd_details *cmd_details)
2185{
2186 struct i40e_aq_desc desc;
2187 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2188 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2189 enum i40e_status_code status;
2190 u16 flags = 0;
2191
2192 i40e_fill_default_direct_cmd_desc(&desc,
2193 i40e_aqc_opc_set_vsi_promiscuous_modes);
2194
2195 if (enable)
2196 flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
2197
2198 cmd->promiscuous_flags = cpu_to_le16(flags);
2199 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
2200 cmd->seid = cpu_to_le16(seid);
2201 cmd->vlan_tag = cpu_to_le16(vid | I40E_AQC_SET_VSI_VLAN_VALID);
2202
2203 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2204
2205 return status;
2206}
2207
2208/**
Jacob Keller435c0842016-11-08 13:05:10 -08002209 * i40e_aq_set_vsi_bc_promisc_on_vlan
2210 * @hw: pointer to the hw struct
2211 * @seid: vsi number
2212 * @enable: set broadcast promiscuous enable/disable for a given VLAN
2213 * @vid: The VLAN tag filter - capture any broadcast packet with this VLAN tag
2214 * @cmd_details: pointer to command details structure or NULL
2215 **/
2216i40e_status i40e_aq_set_vsi_bc_promisc_on_vlan(struct i40e_hw *hw,
2217 u16 seid, bool enable, u16 vid,
2218 struct i40e_asq_cmd_details *cmd_details)
2219{
2220 struct i40e_aq_desc desc;
2221 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2222 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2223 i40e_status status;
2224 u16 flags = 0;
2225
2226 i40e_fill_default_direct_cmd_desc(&desc,
2227 i40e_aqc_opc_set_vsi_promiscuous_modes);
2228
2229 if (enable)
2230 flags |= I40E_AQC_SET_VSI_PROMISC_BROADCAST;
2231
2232 cmd->promiscuous_flags = cpu_to_le16(flags);
2233 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2234 cmd->seid = cpu_to_le16(seid);
2235 cmd->vlan_tag = cpu_to_le16(vid | I40E_AQC_SET_VSI_VLAN_VALID);
2236
2237 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2238
2239 return status;
2240}
2241
2242/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002243 * i40e_aq_set_vsi_broadcast
2244 * @hw: pointer to the hw struct
2245 * @seid: vsi number
2246 * @set_filter: true to set filter, false to clear filter
2247 * @cmd_details: pointer to command details structure or NULL
2248 *
2249 * Set or clear the broadcast promiscuous flag (filter) for a given VSI.
2250 **/
2251i40e_status i40e_aq_set_vsi_broadcast(struct i40e_hw *hw,
2252 u16 seid, bool set_filter,
2253 struct i40e_asq_cmd_details *cmd_details)
2254{
2255 struct i40e_aq_desc desc;
2256 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2257 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2258 i40e_status status;
2259
2260 i40e_fill_default_direct_cmd_desc(&desc,
2261 i40e_aqc_opc_set_vsi_promiscuous_modes);
2262
2263 if (set_filter)
2264 cmd->promiscuous_flags
2265 |= cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2266 else
2267 cmd->promiscuous_flags
2268 &= cpu_to_le16(~I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2269
2270 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2271 cmd->seid = cpu_to_le16(seid);
2272 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2273
2274 return status;
2275}
2276
2277/**
Kiran Patil7bd68752016-01-04 10:33:07 -08002278 * i40e_aq_set_vsi_vlan_promisc - control the VLAN promiscuous setting
2279 * @hw: pointer to the hw struct
2280 * @seid: vsi number
2281 * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
2282 * @cmd_details: pointer to command details structure or NULL
2283 **/
2284i40e_status i40e_aq_set_vsi_vlan_promisc(struct i40e_hw *hw,
2285 u16 seid, bool enable,
2286 struct i40e_asq_cmd_details *cmd_details)
2287{
2288 struct i40e_aq_desc desc;
2289 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2290 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2291 i40e_status status;
2292 u16 flags = 0;
2293
2294 i40e_fill_default_direct_cmd_desc(&desc,
2295 i40e_aqc_opc_set_vsi_promiscuous_modes);
2296 if (enable)
2297 flags |= I40E_AQC_SET_VSI_PROMISC_VLAN;
2298
2299 cmd->promiscuous_flags = cpu_to_le16(flags);
2300 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_VLAN);
2301 cmd->seid = cpu_to_le16(seid);
2302
2303 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2304
2305 return status;
2306}
2307
2308/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002309 * i40e_get_vsi_params - get VSI configuration info
2310 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00002311 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002312 * @cmd_details: pointer to command details structure or NULL
2313 **/
2314i40e_status i40e_aq_get_vsi_params(struct i40e_hw *hw,
2315 struct i40e_vsi_context *vsi_ctx,
2316 struct i40e_asq_cmd_details *cmd_details)
2317{
2318 struct i40e_aq_desc desc;
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002319 struct i40e_aqc_add_get_update_vsi *cmd =
2320 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002321 struct i40e_aqc_add_get_update_vsi_completion *resp =
2322 (struct i40e_aqc_add_get_update_vsi_completion *)
2323 &desc.params.raw;
2324 i40e_status status;
2325
2326 i40e_fill_default_direct_cmd_desc(&desc,
2327 i40e_aqc_opc_get_vsi_parameters);
2328
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002329 cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002330
2331 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002332
2333 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
2334 sizeof(vsi_ctx->info), NULL);
2335
2336 if (status)
2337 goto aq_get_vsi_params_exit;
2338
2339 vsi_ctx->seid = le16_to_cpu(resp->seid);
2340 vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
2341 vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
2342 vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
2343
2344aq_get_vsi_params_exit:
2345 return status;
2346}
2347
2348/**
2349 * i40e_aq_update_vsi_params
2350 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00002351 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002352 * @cmd_details: pointer to command details structure or NULL
2353 *
2354 * Update a VSI context.
2355 **/
2356i40e_status i40e_aq_update_vsi_params(struct i40e_hw *hw,
2357 struct i40e_vsi_context *vsi_ctx,
2358 struct i40e_asq_cmd_details *cmd_details)
2359{
2360 struct i40e_aq_desc desc;
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002361 struct i40e_aqc_add_get_update_vsi *cmd =
2362 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
Kevin Scottb6cacca2016-03-10 14:59:41 -08002363 struct i40e_aqc_add_get_update_vsi_completion *resp =
2364 (struct i40e_aqc_add_get_update_vsi_completion *)
2365 &desc.params.raw;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002366 i40e_status status;
2367
2368 i40e_fill_default_direct_cmd_desc(&desc,
2369 i40e_aqc_opc_update_vsi_parameters);
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002370 cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002371
2372 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002373
2374 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
2375 sizeof(vsi_ctx->info), cmd_details);
2376
Kevin Scottb6cacca2016-03-10 14:59:41 -08002377 vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
2378 vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
2379
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002380 return status;
2381}
2382
2383/**
2384 * i40e_aq_get_switch_config
2385 * @hw: pointer to the hardware structure
2386 * @buf: pointer to the result buffer
2387 * @buf_size: length of input buffer
2388 * @start_seid: seid to start for the report, 0 == beginning
2389 * @cmd_details: pointer to command details structure or NULL
2390 *
2391 * Fill the buf with switch configuration returned from AdminQ command
2392 **/
2393i40e_status i40e_aq_get_switch_config(struct i40e_hw *hw,
2394 struct i40e_aqc_get_switch_config_resp *buf,
2395 u16 buf_size, u16 *start_seid,
2396 struct i40e_asq_cmd_details *cmd_details)
2397{
2398 struct i40e_aq_desc desc;
2399 struct i40e_aqc_switch_seid *scfg =
2400 (struct i40e_aqc_switch_seid *)&desc.params.raw;
2401 i40e_status status;
2402
2403 i40e_fill_default_direct_cmd_desc(&desc,
2404 i40e_aqc_opc_get_switch_config);
2405 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
2406 if (buf_size > I40E_AQ_LARGE_BUF)
2407 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2408 scfg->seid = cpu_to_le16(*start_seid);
2409
2410 status = i40e_asq_send_command(hw, &desc, buf, buf_size, cmd_details);
2411 *start_seid = le16_to_cpu(scfg->seid);
2412
2413 return status;
2414}
2415
2416/**
Shannon Nelsonf3d58492016-05-03 15:13:11 -07002417 * i40e_aq_set_switch_config
2418 * @hw: pointer to the hardware structure
2419 * @flags: bit flag values to set
Jacob Keller35bea902018-03-19 09:28:04 -07002420 * @mode: cloud filter mode
Shannon Nelsonf3d58492016-05-03 15:13:11 -07002421 * @valid_flags: which bit flags to set
Amritha Nambiar5efe0c62017-10-27 02:35:45 -07002422 * @mode: cloud filter mode
Shannon Nelsonf3d58492016-05-03 15:13:11 -07002423 * @cmd_details: pointer to command details structure or NULL
2424 *
2425 * Set switch configuration bits
2426 **/
2427enum i40e_status_code i40e_aq_set_switch_config(struct i40e_hw *hw,
2428 u16 flags,
Amritha Nambiar5efe0c62017-10-27 02:35:45 -07002429 u16 valid_flags, u8 mode,
Shannon Nelsonf3d58492016-05-03 15:13:11 -07002430 struct i40e_asq_cmd_details *cmd_details)
2431{
2432 struct i40e_aq_desc desc;
2433 struct i40e_aqc_set_switch_config *scfg =
2434 (struct i40e_aqc_set_switch_config *)&desc.params.raw;
2435 enum i40e_status_code status;
2436
2437 i40e_fill_default_direct_cmd_desc(&desc,
2438 i40e_aqc_opc_set_switch_config);
2439 scfg->flags = cpu_to_le16(flags);
2440 scfg->valid_flags = cpu_to_le16(valid_flags);
Amritha Nambiar5efe0c62017-10-27 02:35:45 -07002441 scfg->mode = mode;
Scott Petersonab243ec2017-08-22 06:57:54 -04002442 if (hw->flags & I40E_HW_FLAG_802_1AD_CAPABLE) {
2443 scfg->switch_tag = cpu_to_le16(hw->switch_tag);
2444 scfg->first_tag = cpu_to_le16(hw->first_tag);
2445 scfg->second_tag = cpu_to_le16(hw->second_tag);
2446 }
Shannon Nelsonf3d58492016-05-03 15:13:11 -07002447 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2448
2449 return status;
2450}
2451
2452/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002453 * i40e_aq_get_firmware_version
2454 * @hw: pointer to the hw struct
2455 * @fw_major_version: firmware major version
2456 * @fw_minor_version: firmware minor version
Shannon Nelson7edf8102015-02-24 06:58:41 +00002457 * @fw_build: firmware build number
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002458 * @api_major_version: major queue version
2459 * @api_minor_version: minor queue version
2460 * @cmd_details: pointer to command details structure or NULL
2461 *
2462 * Get the firmware version from the admin queue commands
2463 **/
2464i40e_status i40e_aq_get_firmware_version(struct i40e_hw *hw,
2465 u16 *fw_major_version, u16 *fw_minor_version,
Shannon Nelson7edf8102015-02-24 06:58:41 +00002466 u32 *fw_build,
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002467 u16 *api_major_version, u16 *api_minor_version,
2468 struct i40e_asq_cmd_details *cmd_details)
2469{
2470 struct i40e_aq_desc desc;
2471 struct i40e_aqc_get_version *resp =
2472 (struct i40e_aqc_get_version *)&desc.params.raw;
2473 i40e_status status;
2474
2475 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_version);
2476
2477 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2478
2479 if (!status) {
Shannon Nelson7edf8102015-02-24 06:58:41 +00002480 if (fw_major_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002481 *fw_major_version = le16_to_cpu(resp->fw_major);
Shannon Nelson7edf8102015-02-24 06:58:41 +00002482 if (fw_minor_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002483 *fw_minor_version = le16_to_cpu(resp->fw_minor);
Shannon Nelson7edf8102015-02-24 06:58:41 +00002484 if (fw_build)
2485 *fw_build = le32_to_cpu(resp->fw_build);
2486 if (api_major_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002487 *api_major_version = le16_to_cpu(resp->api_major);
Shannon Nelson7edf8102015-02-24 06:58:41 +00002488 if (api_minor_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002489 *api_minor_version = le16_to_cpu(resp->api_minor);
2490 }
2491
2492 return status;
2493}
2494
2495/**
2496 * i40e_aq_send_driver_version
2497 * @hw: pointer to the hw struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002498 * @dv: driver's major, minor version
2499 * @cmd_details: pointer to command details structure or NULL
2500 *
2501 * Send the driver version to the firmware
2502 **/
2503i40e_status i40e_aq_send_driver_version(struct i40e_hw *hw,
2504 struct i40e_driver_version *dv,
2505 struct i40e_asq_cmd_details *cmd_details)
2506{
2507 struct i40e_aq_desc desc;
2508 struct i40e_aqc_driver_version *cmd =
2509 (struct i40e_aqc_driver_version *)&desc.params.raw;
2510 i40e_status status;
Kevin Scott9d2f98e2014-04-01 07:11:52 +00002511 u16 len;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002512
2513 if (dv == NULL)
2514 return I40E_ERR_PARAM;
2515
2516 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_driver_version);
2517
Kevin Scott3b38cd12015-02-06 08:52:18 +00002518 desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002519 cmd->driver_major_ver = dv->major_version;
2520 cmd->driver_minor_ver = dv->minor_version;
2521 cmd->driver_build_ver = dv->build_version;
2522 cmd->driver_subbuild_ver = dv->subbuild_version;
Shannon Nelsond2466012014-04-01 07:11:45 +00002523
2524 len = 0;
2525 while (len < sizeof(dv->driver_string) &&
2526 (dv->driver_string[len] < 0x80) &&
2527 dv->driver_string[len])
2528 len++;
2529 status = i40e_asq_send_command(hw, &desc, dv->driver_string,
2530 len, cmd_details);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002531
2532 return status;
2533}
2534
2535/**
2536 * i40e_get_link_status - get status of the HW network link
2537 * @hw: pointer to the hw struct
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002538 * @link_up: pointer to bool (true/false = linkup/linkdown)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002539 *
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002540 * Variable link_up true if link is up, false if link is down.
2541 * The variable link_up is invalid if returned value of status != 0
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002542 *
2543 * Side effect: LinkStatusEvent reporting becomes enabled
2544 **/
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002545i40e_status i40e_get_link_status(struct i40e_hw *hw, bool *link_up)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002546{
2547 i40e_status status = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002548
2549 if (hw->phy.get_link_info) {
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002550 status = i40e_update_link_info(hw);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002551
2552 if (status)
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002553 i40e_debug(hw, I40E_DEBUG_LINK, "get link failed: status %d\n",
2554 status);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002555 }
2556
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002557 *link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002558
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002559 return status;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002560}
2561
2562/**
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002563 * i40e_updatelink_status - update status of the HW network link
2564 * @hw: pointer to the hw struct
2565 **/
2566i40e_status i40e_update_link_info(struct i40e_hw *hw)
2567{
2568 struct i40e_aq_get_phy_abilities_resp abilities;
2569 i40e_status status = 0;
2570
2571 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
2572 if (status)
2573 return status;
2574
Carolyn Wybornyab425cb2016-09-27 11:28:52 -07002575 /* extra checking needed to ensure link info to user is timely */
2576 if ((hw->phy.link_info.link_info & I40E_AQ_MEDIA_AVAILABLE) &&
2577 ((hw->phy.link_info.link_info & I40E_AQ_LINK_UP) ||
2578 !(hw->phy.link_info_old.link_info & I40E_AQ_LINK_UP))) {
Carolyn Wyborny8589af72015-09-28 14:16:56 -04002579 status = i40e_aq_get_phy_capabilities(hw, false, false,
2580 &abilities, NULL);
2581 if (status)
2582 return status;
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002583
Mariusz Stachuraed601f62017-07-12 05:46:08 -04002584 hw->phy.link_info.req_fec_info =
2585 abilities.fec_cfg_curr_mod_ext_info &
2586 (I40E_AQ_REQUEST_FEC_KR | I40E_AQ_REQUEST_FEC_RS);
2587
Carolyn Wyborny8589af72015-09-28 14:16:56 -04002588 memcpy(hw->phy.link_info.module_type, &abilities.module_type,
2589 sizeof(hw->phy.link_info.module_type));
2590 }
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002591
2592 return status;
2593}
2594
2595/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002596 * i40e_aq_add_veb - Insert a VEB between the VSI and the MAC
2597 * @hw: pointer to the hw struct
2598 * @uplink_seid: the MAC or other gizmo SEID
2599 * @downlink_seid: the VSI SEID
2600 * @enabled_tc: bitmap of TCs to be enabled
2601 * @default_port: true for default port VSI, false for control port
2602 * @veb_seid: pointer to where to put the resulting VEB SEID
Shannon Nelson8a187f42016-01-13 16:51:41 -08002603 * @enable_stats: true to turn on VEB stats
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002604 * @cmd_details: pointer to command details structure or NULL
2605 *
2606 * This asks the FW to add a VEB between the uplink and downlink
2607 * elements. If the uplink SEID is 0, this will be a floating VEB.
2608 **/
2609i40e_status i40e_aq_add_veb(struct i40e_hw *hw, u16 uplink_seid,
2610 u16 downlink_seid, u8 enabled_tc,
Shannon Nelson8a187f42016-01-13 16:51:41 -08002611 bool default_port, u16 *veb_seid,
2612 bool enable_stats,
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002613 struct i40e_asq_cmd_details *cmd_details)
2614{
2615 struct i40e_aq_desc desc;
2616 struct i40e_aqc_add_veb *cmd =
2617 (struct i40e_aqc_add_veb *)&desc.params.raw;
2618 struct i40e_aqc_add_veb_completion *resp =
2619 (struct i40e_aqc_add_veb_completion *)&desc.params.raw;
2620 i40e_status status;
2621 u16 veb_flags = 0;
2622
2623 /* SEIDs need to either both be set or both be 0 for floating VEB */
2624 if (!!uplink_seid != !!downlink_seid)
2625 return I40E_ERR_PARAM;
2626
2627 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_veb);
2628
2629 cmd->uplink_seid = cpu_to_le16(uplink_seid);
2630 cmd->downlink_seid = cpu_to_le16(downlink_seid);
2631 cmd->enable_tcs = enabled_tc;
2632 if (!uplink_seid)
2633 veb_flags |= I40E_AQC_ADD_VEB_FLOATING;
2634 if (default_port)
2635 veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DEFAULT;
2636 else
2637 veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DATA;
Kevin Scotte1c51b952013-11-20 10:02:51 +00002638
Shannon Nelson8a187f42016-01-13 16:51:41 -08002639 /* reverse logic here: set the bitflag to disable the stats */
2640 if (!enable_stats)
2641 veb_flags |= I40E_AQC_ADD_VEB_ENABLE_DISABLE_STATS;
Kevin Scotte1c51b952013-11-20 10:02:51 +00002642
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002643 cmd->veb_flags = cpu_to_le16(veb_flags);
2644
2645 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2646
2647 if (!status && veb_seid)
2648 *veb_seid = le16_to_cpu(resp->veb_seid);
2649
2650 return status;
2651}
2652
2653/**
2654 * i40e_aq_get_veb_parameters - Retrieve VEB parameters
2655 * @hw: pointer to the hw struct
2656 * @veb_seid: the SEID of the VEB to query
2657 * @switch_id: the uplink switch id
Jeff Kirsher98d44382013-12-21 05:44:42 +00002658 * @floating: set to true if the VEB is floating
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002659 * @statistic_index: index of the stats counter block for this VEB
2660 * @vebs_used: number of VEB's used by function
Jeff Kirsher98d44382013-12-21 05:44:42 +00002661 * @vebs_free: total VEB's not reserved by any function
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002662 * @cmd_details: pointer to command details structure or NULL
2663 *
2664 * This retrieves the parameters for a particular VEB, specified by
2665 * uplink_seid, and returns them to the caller.
2666 **/
2667i40e_status i40e_aq_get_veb_parameters(struct i40e_hw *hw,
2668 u16 veb_seid, u16 *switch_id,
2669 bool *floating, u16 *statistic_index,
2670 u16 *vebs_used, u16 *vebs_free,
2671 struct i40e_asq_cmd_details *cmd_details)
2672{
2673 struct i40e_aq_desc desc;
2674 struct i40e_aqc_get_veb_parameters_completion *cmd_resp =
2675 (struct i40e_aqc_get_veb_parameters_completion *)
2676 &desc.params.raw;
2677 i40e_status status;
2678
2679 if (veb_seid == 0)
2680 return I40E_ERR_PARAM;
2681
2682 i40e_fill_default_direct_cmd_desc(&desc,
2683 i40e_aqc_opc_get_veb_parameters);
2684 cmd_resp->seid = cpu_to_le16(veb_seid);
2685
2686 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2687 if (status)
2688 goto get_veb_exit;
2689
2690 if (switch_id)
2691 *switch_id = le16_to_cpu(cmd_resp->switch_id);
2692 if (statistic_index)
2693 *statistic_index = le16_to_cpu(cmd_resp->statistic_index);
2694 if (vebs_used)
2695 *vebs_used = le16_to_cpu(cmd_resp->vebs_used);
2696 if (vebs_free)
2697 *vebs_free = le16_to_cpu(cmd_resp->vebs_free);
2698 if (floating) {
2699 u16 flags = le16_to_cpu(cmd_resp->veb_flags);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04002700
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002701 if (flags & I40E_AQC_ADD_VEB_FLOATING)
2702 *floating = true;
2703 else
2704 *floating = false;
2705 }
2706
2707get_veb_exit:
2708 return status;
2709}
2710
2711/**
2712 * i40e_aq_add_macvlan
2713 * @hw: pointer to the hw struct
2714 * @seid: VSI for the mac address
2715 * @mv_list: list of macvlans to be added
2716 * @count: length of the list
2717 * @cmd_details: pointer to command details structure or NULL
2718 *
2719 * Add MAC/VLAN addresses to the HW filtering
2720 **/
2721i40e_status i40e_aq_add_macvlan(struct i40e_hw *hw, u16 seid,
2722 struct i40e_aqc_add_macvlan_element_data *mv_list,
2723 u16 count, struct i40e_asq_cmd_details *cmd_details)
2724{
2725 struct i40e_aq_desc desc;
2726 struct i40e_aqc_macvlan *cmd =
2727 (struct i40e_aqc_macvlan *)&desc.params.raw;
2728 i40e_status status;
2729 u16 buf_size;
Shannon Nelson67be6eb2016-01-13 16:51:40 -08002730 int i;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002731
2732 if (count == 0 || !mv_list || !hw)
2733 return I40E_ERR_PARAM;
2734
Shannon Nelson1efc80e2015-02-27 09:18:30 +00002735 buf_size = count * sizeof(*mv_list);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002736
2737 /* prep the rest of the request */
2738 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_macvlan);
2739 cmd->num_addresses = cpu_to_le16(count);
2740 cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
2741 cmd->seid[1] = 0;
2742 cmd->seid[2] = 0;
2743
Shannon Nelson67be6eb2016-01-13 16:51:40 -08002744 for (i = 0; i < count; i++)
2745 if (is_multicast_ether_addr(mv_list[i].mac_addr))
2746 mv_list[i].flags |=
2747 cpu_to_le16(I40E_AQC_MACVLAN_ADD_USE_SHARED_MAC);
2748
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002749 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
2750 if (buf_size > I40E_AQ_LARGE_BUF)
2751 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2752
2753 status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
Shannon Nelson67be6eb2016-01-13 16:51:40 -08002754 cmd_details);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002755
2756 return status;
2757}
2758
2759/**
2760 * i40e_aq_remove_macvlan
2761 * @hw: pointer to the hw struct
2762 * @seid: VSI for the mac address
2763 * @mv_list: list of macvlans to be removed
2764 * @count: length of the list
2765 * @cmd_details: pointer to command details structure or NULL
2766 *
2767 * Remove MAC/VLAN addresses from the HW filtering
2768 **/
2769i40e_status i40e_aq_remove_macvlan(struct i40e_hw *hw, u16 seid,
2770 struct i40e_aqc_remove_macvlan_element_data *mv_list,
2771 u16 count, struct i40e_asq_cmd_details *cmd_details)
2772{
2773 struct i40e_aq_desc desc;
2774 struct i40e_aqc_macvlan *cmd =
2775 (struct i40e_aqc_macvlan *)&desc.params.raw;
2776 i40e_status status;
2777 u16 buf_size;
2778
2779 if (count == 0 || !mv_list || !hw)
2780 return I40E_ERR_PARAM;
2781
Shannon Nelson1efc80e2015-02-27 09:18:30 +00002782 buf_size = count * sizeof(*mv_list);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002783
2784 /* prep the rest of the request */
2785 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_macvlan);
2786 cmd->num_addresses = cpu_to_le16(count);
2787 cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
2788 cmd->seid[1] = 0;
2789 cmd->seid[2] = 0;
2790
2791 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
2792 if (buf_size > I40E_AQ_LARGE_BUF)
2793 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2794
2795 status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
2796 cmd_details);
2797
2798 return status;
2799}
2800
2801/**
Kiran Patil7bd68752016-01-04 10:33:07 -08002802 * i40e_mirrorrule_op - Internal helper function to add/delete mirror rule
2803 * @hw: pointer to the hw struct
2804 * @opcode: AQ opcode for add or delete mirror rule
2805 * @sw_seid: Switch SEID (to which rule refers)
2806 * @rule_type: Rule Type (ingress/egress/VLAN)
2807 * @id: Destination VSI SEID or Rule ID
2808 * @count: length of the list
2809 * @mr_list: list of mirrored VSI SEIDs or VLAN IDs
2810 * @cmd_details: pointer to command details structure or NULL
2811 * @rule_id: Rule ID returned from FW
Jacob Kellerf5254422018-04-20 01:41:33 -07002812 * @rules_used: Number of rules used in internal switch
2813 * @rules_free: Number of rules free in internal switch
Kiran Patil7bd68752016-01-04 10:33:07 -08002814 *
2815 * Add/Delete a mirror rule to a specific switch. Mirror rules are supported for
2816 * VEBs/VEPA elements only
2817 **/
2818static i40e_status i40e_mirrorrule_op(struct i40e_hw *hw,
2819 u16 opcode, u16 sw_seid, u16 rule_type, u16 id,
2820 u16 count, __le16 *mr_list,
2821 struct i40e_asq_cmd_details *cmd_details,
2822 u16 *rule_id, u16 *rules_used, u16 *rules_free)
2823{
2824 struct i40e_aq_desc desc;
2825 struct i40e_aqc_add_delete_mirror_rule *cmd =
2826 (struct i40e_aqc_add_delete_mirror_rule *)&desc.params.raw;
2827 struct i40e_aqc_add_delete_mirror_rule_completion *resp =
2828 (struct i40e_aqc_add_delete_mirror_rule_completion *)&desc.params.raw;
2829 i40e_status status;
2830 u16 buf_size;
2831
2832 buf_size = count * sizeof(*mr_list);
2833
2834 /* prep the rest of the request */
2835 i40e_fill_default_direct_cmd_desc(&desc, opcode);
2836 cmd->seid = cpu_to_le16(sw_seid);
2837 cmd->rule_type = cpu_to_le16(rule_type &
2838 I40E_AQC_MIRROR_RULE_TYPE_MASK);
2839 cmd->num_entries = cpu_to_le16(count);
2840 /* Dest VSI for add, rule_id for delete */
2841 cmd->destination = cpu_to_le16(id);
2842 if (mr_list) {
2843 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
2844 I40E_AQ_FLAG_RD));
2845 if (buf_size > I40E_AQ_LARGE_BUF)
2846 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2847 }
2848
2849 status = i40e_asq_send_command(hw, &desc, mr_list, buf_size,
2850 cmd_details);
2851 if (!status ||
2852 hw->aq.asq_last_status == I40E_AQ_RC_ENOSPC) {
2853 if (rule_id)
2854 *rule_id = le16_to_cpu(resp->rule_id);
2855 if (rules_used)
2856 *rules_used = le16_to_cpu(resp->mirror_rules_used);
2857 if (rules_free)
2858 *rules_free = le16_to_cpu(resp->mirror_rules_free);
2859 }
2860 return status;
2861}
2862
2863/**
2864 * i40e_aq_add_mirrorrule - add a mirror rule
2865 * @hw: pointer to the hw struct
2866 * @sw_seid: Switch SEID (to which rule refers)
2867 * @rule_type: Rule Type (ingress/egress/VLAN)
2868 * @dest_vsi: SEID of VSI to which packets will be mirrored
2869 * @count: length of the list
2870 * @mr_list: list of mirrored VSI SEIDs or VLAN IDs
2871 * @cmd_details: pointer to command details structure or NULL
2872 * @rule_id: Rule ID returned from FW
Jacob Kellerf5254422018-04-20 01:41:33 -07002873 * @rules_used: Number of rules used in internal switch
2874 * @rules_free: Number of rules free in internal switch
Kiran Patil7bd68752016-01-04 10:33:07 -08002875 *
2876 * Add mirror rule. Mirror rules are supported for VEBs or VEPA elements only
2877 **/
2878i40e_status i40e_aq_add_mirrorrule(struct i40e_hw *hw, u16 sw_seid,
2879 u16 rule_type, u16 dest_vsi, u16 count, __le16 *mr_list,
2880 struct i40e_asq_cmd_details *cmd_details,
2881 u16 *rule_id, u16 *rules_used, u16 *rules_free)
2882{
2883 if (!(rule_type == I40E_AQC_MIRROR_RULE_TYPE_ALL_INGRESS ||
2884 rule_type == I40E_AQC_MIRROR_RULE_TYPE_ALL_EGRESS)) {
2885 if (count == 0 || !mr_list)
2886 return I40E_ERR_PARAM;
2887 }
2888
2889 return i40e_mirrorrule_op(hw, i40e_aqc_opc_add_mirror_rule, sw_seid,
2890 rule_type, dest_vsi, count, mr_list,
2891 cmd_details, rule_id, rules_used, rules_free);
2892}
2893
2894/**
2895 * i40e_aq_delete_mirrorrule - delete a mirror rule
2896 * @hw: pointer to the hw struct
2897 * @sw_seid: Switch SEID (to which rule refers)
2898 * @rule_type: Rule Type (ingress/egress/VLAN)
2899 * @count: length of the list
2900 * @rule_id: Rule ID that is returned in the receive desc as part of
2901 * add_mirrorrule.
2902 * @mr_list: list of mirrored VLAN IDs to be removed
2903 * @cmd_details: pointer to command details structure or NULL
Jacob Kellerf5254422018-04-20 01:41:33 -07002904 * @rules_used: Number of rules used in internal switch
2905 * @rules_free: Number of rules free in internal switch
Kiran Patil7bd68752016-01-04 10:33:07 -08002906 *
2907 * Delete a mirror rule. Mirror rules are supported for VEBs/VEPA elements only
2908 **/
2909i40e_status i40e_aq_delete_mirrorrule(struct i40e_hw *hw, u16 sw_seid,
2910 u16 rule_type, u16 rule_id, u16 count, __le16 *mr_list,
2911 struct i40e_asq_cmd_details *cmd_details,
2912 u16 *rules_used, u16 *rules_free)
2913{
2914 /* Rule ID has to be valid except rule_type: INGRESS VLAN mirroring */
Greg Rosedb077272016-04-12 08:30:48 -07002915 if (rule_type == I40E_AQC_MIRROR_RULE_TYPE_VLAN) {
Kiran Patil7bd68752016-01-04 10:33:07 -08002916 /* count and mr_list shall be valid for rule_type INGRESS VLAN
2917 * mirroring. For other rule_type, count and rule_type should
2918 * not matter.
2919 */
2920 if (count == 0 || !mr_list)
2921 return I40E_ERR_PARAM;
2922 }
2923
2924 return i40e_mirrorrule_op(hw, i40e_aqc_opc_delete_mirror_rule, sw_seid,
2925 rule_type, rule_id, count, mr_list,
2926 cmd_details, NULL, rules_used, rules_free);
2927}
2928
2929/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002930 * i40e_aq_send_msg_to_vf
2931 * @hw: pointer to the hardware structure
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00002932 * @vfid: VF id to send msg
Jeff Kirsher98d44382013-12-21 05:44:42 +00002933 * @v_opcode: opcodes for VF-PF communication
2934 * @v_retval: return error code
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002935 * @msg: pointer to the msg buffer
2936 * @msglen: msg length
2937 * @cmd_details: pointer to command details
2938 *
2939 * send msg to vf
2940 **/
2941i40e_status i40e_aq_send_msg_to_vf(struct i40e_hw *hw, u16 vfid,
2942 u32 v_opcode, u32 v_retval, u8 *msg, u16 msglen,
2943 struct i40e_asq_cmd_details *cmd_details)
2944{
2945 struct i40e_aq_desc desc;
2946 struct i40e_aqc_pf_vf_message *cmd =
2947 (struct i40e_aqc_pf_vf_message *)&desc.params.raw;
2948 i40e_status status;
2949
2950 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_vf);
2951 cmd->id = cpu_to_le32(vfid);
2952 desc.cookie_high = cpu_to_le32(v_opcode);
2953 desc.cookie_low = cpu_to_le32(v_retval);
2954 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_SI);
2955 if (msglen) {
2956 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
2957 I40E_AQ_FLAG_RD));
2958 if (msglen > I40E_AQ_LARGE_BUF)
2959 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2960 desc.datalen = cpu_to_le16(msglen);
2961 }
2962 status = i40e_asq_send_command(hw, &desc, msg, msglen, cmd_details);
2963
2964 return status;
2965}
2966
2967/**
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002968 * i40e_aq_debug_read_register
2969 * @hw: pointer to the hw struct
2970 * @reg_addr: register address
2971 * @reg_val: register value
2972 * @cmd_details: pointer to command details structure or NULL
2973 *
2974 * Read the register using the admin queue commands
2975 **/
2976i40e_status i40e_aq_debug_read_register(struct i40e_hw *hw,
Jesse Brandeburg7b115dd2015-02-27 09:15:23 +00002977 u32 reg_addr, u64 *reg_val,
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002978 struct i40e_asq_cmd_details *cmd_details)
2979{
2980 struct i40e_aq_desc desc;
2981 struct i40e_aqc_debug_reg_read_write *cmd_resp =
2982 (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
2983 i40e_status status;
2984
2985 if (reg_val == NULL)
2986 return I40E_ERR_PARAM;
2987
Jesse Brandeburg7b115dd2015-02-27 09:15:23 +00002988 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_read_reg);
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002989
2990 cmd_resp->address = cpu_to_le32(reg_addr);
2991
2992 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2993
2994 if (!status) {
Jesse Brandeburg7b115dd2015-02-27 09:15:23 +00002995 *reg_val = ((u64)le32_to_cpu(cmd_resp->value_high) << 32) |
2996 (u64)le32_to_cpu(cmd_resp->value_low);
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002997 }
2998
2999 return status;
3000}
3001
3002/**
Shannon Nelson53db45c2014-08-01 13:27:05 -07003003 * i40e_aq_debug_write_register
3004 * @hw: pointer to the hw struct
3005 * @reg_addr: register address
3006 * @reg_val: register value
3007 * @cmd_details: pointer to command details structure or NULL
3008 *
3009 * Write to a register using the admin queue commands
3010 **/
3011i40e_status i40e_aq_debug_write_register(struct i40e_hw *hw,
3012 u32 reg_addr, u64 reg_val,
3013 struct i40e_asq_cmd_details *cmd_details)
3014{
3015 struct i40e_aq_desc desc;
3016 struct i40e_aqc_debug_reg_read_write *cmd =
3017 (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
3018 i40e_status status;
3019
3020 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_write_reg);
3021
3022 cmd->address = cpu_to_le32(reg_addr);
3023 cmd->value_high = cpu_to_le32((u32)(reg_val >> 32));
3024 cmd->value_low = cpu_to_le32((u32)(reg_val & 0xFFFFFFFF));
3025
3026 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3027
3028 return status;
3029}
3030
3031/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003032 * i40e_aq_request_resource
3033 * @hw: pointer to the hw struct
3034 * @resource: resource id
3035 * @access: access type
3036 * @sdp_number: resource number
3037 * @timeout: the maximum time in ms that the driver may hold the resource
3038 * @cmd_details: pointer to command details structure or NULL
3039 *
3040 * requests common resource using the admin queue commands
3041 **/
3042i40e_status i40e_aq_request_resource(struct i40e_hw *hw,
3043 enum i40e_aq_resources_ids resource,
3044 enum i40e_aq_resource_access_type access,
3045 u8 sdp_number, u64 *timeout,
3046 struct i40e_asq_cmd_details *cmd_details)
3047{
3048 struct i40e_aq_desc desc;
3049 struct i40e_aqc_request_resource *cmd_resp =
3050 (struct i40e_aqc_request_resource *)&desc.params.raw;
3051 i40e_status status;
3052
3053 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_request_resource);
3054
3055 cmd_resp->resource_id = cpu_to_le16(resource);
3056 cmd_resp->access_type = cpu_to_le16(access);
3057 cmd_resp->resource_number = cpu_to_le32(sdp_number);
3058
3059 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3060 /* The completion specifies the maximum time in ms that the driver
3061 * may hold the resource in the Timeout field.
3062 * If the resource is held by someone else, the command completes with
3063 * busy return value and the timeout field indicates the maximum time
3064 * the current owner of the resource has to free it.
3065 */
3066 if (!status || hw->aq.asq_last_status == I40E_AQ_RC_EBUSY)
3067 *timeout = le32_to_cpu(cmd_resp->timeout);
3068
3069 return status;
3070}
3071
3072/**
3073 * i40e_aq_release_resource
3074 * @hw: pointer to the hw struct
3075 * @resource: resource id
3076 * @sdp_number: resource number
3077 * @cmd_details: pointer to command details structure or NULL
3078 *
3079 * release common resource using the admin queue commands
3080 **/
3081i40e_status i40e_aq_release_resource(struct i40e_hw *hw,
3082 enum i40e_aq_resources_ids resource,
3083 u8 sdp_number,
3084 struct i40e_asq_cmd_details *cmd_details)
3085{
3086 struct i40e_aq_desc desc;
3087 struct i40e_aqc_request_resource *cmd =
3088 (struct i40e_aqc_request_resource *)&desc.params.raw;
3089 i40e_status status;
3090
3091 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_release_resource);
3092
3093 cmd->resource_id = cpu_to_le16(resource);
3094 cmd->resource_number = cpu_to_le32(sdp_number);
3095
3096 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3097
3098 return status;
3099}
3100
3101/**
3102 * i40e_aq_read_nvm
3103 * @hw: pointer to the hw struct
3104 * @module_pointer: module pointer location in words from the NVM beginning
3105 * @offset: byte offset from the module beginning
3106 * @length: length of the section to be read (in bytes from the offset)
3107 * @data: command buffer (size [bytes] = length)
3108 * @last_command: tells if this is the last command in a series
3109 * @cmd_details: pointer to command details structure or NULL
3110 *
3111 * Read the NVM using the admin queue commands
3112 **/
3113i40e_status i40e_aq_read_nvm(struct i40e_hw *hw, u8 module_pointer,
3114 u32 offset, u16 length, void *data,
3115 bool last_command,
3116 struct i40e_asq_cmd_details *cmd_details)
3117{
3118 struct i40e_aq_desc desc;
3119 struct i40e_aqc_nvm_update *cmd =
3120 (struct i40e_aqc_nvm_update *)&desc.params.raw;
3121 i40e_status status;
3122
3123 /* In offset the highest byte must be zeroed. */
3124 if (offset & 0xFF000000) {
3125 status = I40E_ERR_PARAM;
3126 goto i40e_aq_read_nvm_exit;
3127 }
3128
3129 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_read);
3130
3131 /* If this is the last command in a series, set the proper flag. */
3132 if (last_command)
3133 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
3134 cmd->module_pointer = module_pointer;
3135 cmd->offset = cpu_to_le32(offset);
3136 cmd->length = cpu_to_le16(length);
3137
3138 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3139 if (length > I40E_AQ_LARGE_BUF)
3140 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3141
3142 status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
3143
3144i40e_aq_read_nvm_exit:
3145 return status;
3146}
3147
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003148/**
3149 * i40e_aq_erase_nvm
3150 * @hw: pointer to the hw struct
3151 * @module_pointer: module pointer location in words from the NVM beginning
3152 * @offset: offset in the module (expressed in 4 KB from module's beginning)
3153 * @length: length of the section to be erased (expressed in 4 KB)
3154 * @last_command: tells if this is the last command in a series
3155 * @cmd_details: pointer to command details structure or NULL
3156 *
3157 * Erase the NVM sector using the admin queue commands
3158 **/
3159i40e_status i40e_aq_erase_nvm(struct i40e_hw *hw, u8 module_pointer,
3160 u32 offset, u16 length, bool last_command,
3161 struct i40e_asq_cmd_details *cmd_details)
3162{
3163 struct i40e_aq_desc desc;
3164 struct i40e_aqc_nvm_update *cmd =
3165 (struct i40e_aqc_nvm_update *)&desc.params.raw;
3166 i40e_status status;
3167
3168 /* In offset the highest byte must be zeroed. */
3169 if (offset & 0xFF000000) {
3170 status = I40E_ERR_PARAM;
3171 goto i40e_aq_erase_nvm_exit;
3172 }
3173
3174 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_erase);
3175
3176 /* If this is the last command in a series, set the proper flag. */
3177 if (last_command)
3178 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
3179 cmd->module_pointer = module_pointer;
3180 cmd->offset = cpu_to_le32(offset);
3181 cmd->length = cpu_to_le16(length);
3182
3183 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3184
3185i40e_aq_erase_nvm_exit:
3186 return status;
3187}
3188
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003189/**
3190 * i40e_parse_discover_capabilities
3191 * @hw: pointer to the hw struct
3192 * @buff: pointer to a buffer containing device/function capability records
3193 * @cap_count: number of capability records in the list
3194 * @list_type_opc: type of capabilities list to parse
3195 *
3196 * Parse the device/function capabilities list.
3197 **/
3198static void i40e_parse_discover_capabilities(struct i40e_hw *hw, void *buff,
3199 u32 cap_count,
3200 enum i40e_admin_queue_opc list_type_opc)
3201{
3202 struct i40e_aqc_list_capabilities_element_resp *cap;
Shannon Nelson9fee9db2014-12-11 07:06:30 +00003203 u32 valid_functions, num_functions;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003204 u32 number, logical_id, phys_id;
3205 struct i40e_hw_capabilities *p;
Mariusz Stachurabc2a3a62018-03-08 14:52:10 -08003206 u16 id, ocp_cfg_word0;
3207 i40e_status status;
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003208 u8 major_rev;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003209 u32 i = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003210
3211 cap = (struct i40e_aqc_list_capabilities_element_resp *) buff;
3212
3213 if (list_type_opc == i40e_aqc_opc_list_dev_capabilities)
Joe Perchesb58f2f72014-03-25 04:30:32 +00003214 p = &hw->dev_caps;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003215 else if (list_type_opc == i40e_aqc_opc_list_func_capabilities)
Joe Perchesb58f2f72014-03-25 04:30:32 +00003216 p = &hw->func_caps;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003217 else
3218 return;
3219
3220 for (i = 0; i < cap_count; i++, cap++) {
3221 id = le16_to_cpu(cap->id);
3222 number = le32_to_cpu(cap->number);
3223 logical_id = le32_to_cpu(cap->logical_id);
3224 phys_id = le32_to_cpu(cap->phys_id);
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003225 major_rev = cap->major_rev;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003226
3227 switch (id) {
Shannon Nelson406e7342015-12-10 11:38:49 -08003228 case I40E_AQ_CAP_ID_SWITCH_MODE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003229 p->switch_mode = number;
3230 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003231 case I40E_AQ_CAP_ID_MNG_MODE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003232 p->management_mode = number;
Piotr Raczynski64f5ead2016-10-25 16:08:53 -07003233 if (major_rev > 1) {
3234 p->mng_protocols_over_mctp = logical_id;
3235 i40e_debug(hw, I40E_DEBUG_INIT,
3236 "HW Capability: Protocols over MCTP = %d\n",
3237 p->mng_protocols_over_mctp);
3238 } else {
3239 p->mng_protocols_over_mctp = 0;
3240 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003241 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003242 case I40E_AQ_CAP_ID_NPAR_ACTIVE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003243 p->npar_enable = number;
3244 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003245 case I40E_AQ_CAP_ID_OS2BMC_CAP:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003246 p->os2bmc = number;
3247 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003248 case I40E_AQ_CAP_ID_FUNCTIONS_VALID:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003249 p->valid_functions = number;
3250 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003251 case I40E_AQ_CAP_ID_SRIOV:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003252 if (number == 1)
3253 p->sr_iov_1_1 = true;
3254 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003255 case I40E_AQ_CAP_ID_VF:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003256 p->num_vfs = number;
3257 p->vf_base_id = logical_id;
3258 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003259 case I40E_AQ_CAP_ID_VMDQ:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003260 if (number == 1)
3261 p->vmdq = true;
3262 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003263 case I40E_AQ_CAP_ID_8021QBG:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003264 if (number == 1)
3265 p->evb_802_1_qbg = true;
3266 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003267 case I40E_AQ_CAP_ID_8021QBR:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003268 if (number == 1)
3269 p->evb_802_1_qbh = true;
3270 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003271 case I40E_AQ_CAP_ID_VSI:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003272 p->num_vsis = number;
3273 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003274 case I40E_AQ_CAP_ID_DCB:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003275 if (number == 1) {
3276 p->dcb = true;
3277 p->enabled_tcmap = logical_id;
3278 p->maxtc = phys_id;
3279 }
3280 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003281 case I40E_AQ_CAP_ID_FCOE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003282 if (number == 1)
3283 p->fcoe = true;
3284 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003285 case I40E_AQ_CAP_ID_ISCSI:
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00003286 if (number == 1)
3287 p->iscsi = true;
3288 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003289 case I40E_AQ_CAP_ID_RSS:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003290 p->rss = true;
Carolyn Wybornye157ea32014-06-03 23:50:22 +00003291 p->rss_table_size = number;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003292 p->rss_table_entry_width = logical_id;
3293 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003294 case I40E_AQ_CAP_ID_RXQ:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003295 p->num_rx_qp = number;
3296 p->base_queue = phys_id;
3297 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003298 case I40E_AQ_CAP_ID_TXQ:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003299 p->num_tx_qp = number;
3300 p->base_queue = phys_id;
3301 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003302 case I40E_AQ_CAP_ID_MSIX:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003303 p->num_msix_vectors = number;
Deepthi Kavalur453e16e2016-04-01 03:56:01 -07003304 i40e_debug(hw, I40E_DEBUG_INIT,
3305 "HW Capability: MSIX vector count = %d\n",
3306 p->num_msix_vectors);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003307 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003308 case I40E_AQ_CAP_ID_VF_MSIX:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003309 p->num_msix_vectors_vf = number;
3310 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003311 case I40E_AQ_CAP_ID_FLEX10:
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003312 if (major_rev == 1) {
3313 if (number == 1) {
3314 p->flex10_enable = true;
3315 p->flex10_capable = true;
3316 }
3317 } else {
3318 /* Capability revision >= 2 */
3319 if (number & 1)
3320 p->flex10_enable = true;
3321 if (number & 2)
3322 p->flex10_capable = true;
3323 }
3324 p->flex10_mode = logical_id;
3325 p->flex10_status = phys_id;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003326 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003327 case I40E_AQ_CAP_ID_CEM:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003328 if (number == 1)
3329 p->mgmt_cem = true;
3330 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003331 case I40E_AQ_CAP_ID_IWARP:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003332 if (number == 1)
3333 p->iwarp = true;
3334 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003335 case I40E_AQ_CAP_ID_LED:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003336 if (phys_id < I40E_HW_CAP_MAX_GPIO)
3337 p->led[phys_id] = true;
3338 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003339 case I40E_AQ_CAP_ID_SDP:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003340 if (phys_id < I40E_HW_CAP_MAX_GPIO)
3341 p->sdp[phys_id] = true;
3342 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003343 case I40E_AQ_CAP_ID_MDIO:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003344 if (number == 1) {
3345 p->mdio_port_num = phys_id;
3346 p->mdio_port_mode = logical_id;
3347 }
3348 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003349 case I40E_AQ_CAP_ID_1588:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003350 if (number == 1)
3351 p->ieee_1588 = true;
3352 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003353 case I40E_AQ_CAP_ID_FLOW_DIRECTOR:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003354 p->fd = true;
3355 p->fd_filters_guaranteed = number;
3356 p->fd_filters_best_effort = logical_id;
3357 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003358 case I40E_AQ_CAP_ID_WSR_PROT:
Kevin Scott73b23402015-04-07 19:45:38 -04003359 p->wr_csr_prot = (u64)number;
3360 p->wr_csr_prot |= (u64)logical_id << 32;
3361 break;
Michal Kosiarz68a1c5a2016-04-12 08:30:46 -07003362 case I40E_AQ_CAP_ID_NVM_MGMT:
3363 if (number & I40E_NVM_MGMT_SEC_REV_DISABLED)
3364 p->sec_rev_disabled = true;
3365 if (number & I40E_NVM_MGMT_UPDATE_DISABLED)
3366 p->update_disabled = true;
3367 break;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003368 default:
3369 break;
3370 }
3371 }
3372
Vasu Devf18ae102015-04-07 19:45:36 -04003373 if (p->fcoe)
3374 i40e_debug(hw, I40E_DEBUG_ALL, "device is FCoE capable\n");
3375
Vasu Dev566bb852014-04-09 05:59:06 +00003376 /* Software override ensuring FCoE is disabled if npar or mfp
3377 * mode because it is not supported in these modes.
3378 */
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003379 if (p->npar_enable || p->flex10_enable)
Vasu Dev566bb852014-04-09 05:59:06 +00003380 p->fcoe = false;
3381
Shannon Nelson9fee9db2014-12-11 07:06:30 +00003382 /* count the enabled ports (aka the "not disabled" ports) */
3383 hw->num_ports = 0;
3384 for (i = 0; i < 4; i++) {
3385 u32 port_cfg_reg = I40E_PRTGEN_CNF + (4 * i);
3386 u64 port_cfg = 0;
3387
3388 /* use AQ read to get the physical register offset instead
3389 * of the port relative offset
3390 */
3391 i40e_aq_debug_read_register(hw, port_cfg_reg, &port_cfg, NULL);
3392 if (!(port_cfg & I40E_PRTGEN_CNF_PORT_DIS_MASK))
3393 hw->num_ports++;
3394 }
3395
Mariusz Stachurabc2a3a62018-03-08 14:52:10 -08003396 /* OCP cards case: if a mezz is removed the Ethernet port is at
3397 * disabled state in PRTGEN_CNF register. Additional NVM read is
3398 * needed in order to check if we are dealing with OCP card.
3399 * Those cards have 4 PFs at minimum, so using PRTGEN_CNF for counting
3400 * physical ports results in wrong partition id calculation and thus
3401 * not supporting WoL.
3402 */
3403 if (hw->mac.type == I40E_MAC_X722) {
3404 if (!i40e_acquire_nvm(hw, I40E_RESOURCE_READ)) {
3405 status = i40e_aq_read_nvm(hw, I40E_SR_EMP_MODULE_PTR,
3406 2 * I40E_SR_OCP_CFG_WORD0,
3407 sizeof(ocp_cfg_word0),
3408 &ocp_cfg_word0, true, NULL);
3409 if (!status &&
3410 (ocp_cfg_word0 & I40E_SR_OCP_ENABLED))
3411 hw->num_ports = 4;
3412 i40e_release_nvm(hw);
3413 }
3414 }
3415
Shannon Nelson9fee9db2014-12-11 07:06:30 +00003416 valid_functions = p->valid_functions;
3417 num_functions = 0;
3418 while (valid_functions) {
3419 if (valid_functions & 1)
3420 num_functions++;
3421 valid_functions >>= 1;
3422 }
3423
3424 /* partition id is 1-based, and functions are evenly spread
3425 * across the ports as partitions
3426 */
Michal Kosiarz999b3152016-10-11 15:26:56 -07003427 if (hw->num_ports != 0) {
3428 hw->partition_id = (hw->pf_id / hw->num_ports) + 1;
3429 hw->num_partitions = num_functions / hw->num_ports;
3430 }
Shannon Nelson9fee9db2014-12-11 07:06:30 +00003431
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003432 /* additional HW specific goodies that might
3433 * someday be HW version specific
3434 */
3435 p->rx_buf_chain_len = I40E_MAX_CHAINED_RX_BUFFERS;
3436}
3437
3438/**
3439 * i40e_aq_discover_capabilities
3440 * @hw: pointer to the hw struct
3441 * @buff: a virtual buffer to hold the capabilities
3442 * @buff_size: Size of the virtual buffer
3443 * @data_size: Size of the returned data, or buff size needed if AQ err==ENOMEM
3444 * @list_type_opc: capabilities type to discover - pass in the command opcode
3445 * @cmd_details: pointer to command details structure or NULL
3446 *
3447 * Get the device capabilities descriptions from the firmware
3448 **/
3449i40e_status i40e_aq_discover_capabilities(struct i40e_hw *hw,
3450 void *buff, u16 buff_size, u16 *data_size,
3451 enum i40e_admin_queue_opc list_type_opc,
3452 struct i40e_asq_cmd_details *cmd_details)
3453{
3454 struct i40e_aqc_list_capabilites *cmd;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003455 struct i40e_aq_desc desc;
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08003456 i40e_status status = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003457
3458 cmd = (struct i40e_aqc_list_capabilites *)&desc.params.raw;
3459
3460 if (list_type_opc != i40e_aqc_opc_list_func_capabilities &&
3461 list_type_opc != i40e_aqc_opc_list_dev_capabilities) {
3462 status = I40E_ERR_PARAM;
3463 goto exit;
3464 }
3465
3466 i40e_fill_default_direct_cmd_desc(&desc, list_type_opc);
3467
3468 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3469 if (buff_size > I40E_AQ_LARGE_BUF)
3470 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3471
3472 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3473 *data_size = le16_to_cpu(desc.datalen);
3474
3475 if (status)
3476 goto exit;
3477
3478 i40e_parse_discover_capabilities(hw, buff, le32_to_cpu(cmd->count),
3479 list_type_opc);
3480
3481exit:
3482 return status;
3483}
3484
3485/**
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003486 * i40e_aq_update_nvm
3487 * @hw: pointer to the hw struct
3488 * @module_pointer: module pointer location in words from the NVM beginning
3489 * @offset: byte offset from the module beginning
3490 * @length: length of the section to be written (in bytes from the offset)
3491 * @data: command buffer (size [bytes] = length)
3492 * @last_command: tells if this is the last command in a series
Pawel Jablonskie3a5d6e2017-12-18 05:14:44 -05003493 * @preservation_flags: Preservation mode flags
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003494 * @cmd_details: pointer to command details structure or NULL
3495 *
3496 * Update the NVM using the admin queue commands
3497 **/
3498i40e_status i40e_aq_update_nvm(struct i40e_hw *hw, u8 module_pointer,
3499 u32 offset, u16 length, void *data,
Pawel Jablonskie3a5d6e2017-12-18 05:14:44 -05003500 bool last_command, u8 preservation_flags,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003501 struct i40e_asq_cmd_details *cmd_details)
3502{
3503 struct i40e_aq_desc desc;
3504 struct i40e_aqc_nvm_update *cmd =
3505 (struct i40e_aqc_nvm_update *)&desc.params.raw;
3506 i40e_status status;
3507
3508 /* In offset the highest byte must be zeroed. */
3509 if (offset & 0xFF000000) {
3510 status = I40E_ERR_PARAM;
3511 goto i40e_aq_update_nvm_exit;
3512 }
3513
3514 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_update);
3515
3516 /* If this is the last command in a series, set the proper flag. */
3517 if (last_command)
3518 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
Pawel Jablonskie3a5d6e2017-12-18 05:14:44 -05003519 if (hw->mac.type == I40E_MAC_X722) {
3520 if (preservation_flags == I40E_NVM_PRESERVATION_FLAGS_SELECTED)
3521 cmd->command_flags |=
3522 (I40E_AQ_NVM_PRESERVATION_FLAGS_SELECTED <<
3523 I40E_AQ_NVM_PRESERVATION_FLAGS_SHIFT);
3524 else if (preservation_flags == I40E_NVM_PRESERVATION_FLAGS_ALL)
3525 cmd->command_flags |=
3526 (I40E_AQ_NVM_PRESERVATION_FLAGS_ALL <<
3527 I40E_AQ_NVM_PRESERVATION_FLAGS_SHIFT);
3528 }
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003529 cmd->module_pointer = module_pointer;
3530 cmd->offset = cpu_to_le32(offset);
3531 cmd->length = cpu_to_le16(length);
3532
3533 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
3534 if (length > I40E_AQ_LARGE_BUF)
3535 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3536
3537 status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
3538
3539i40e_aq_update_nvm_exit:
3540 return status;
3541}
3542
3543/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003544 * i40e_aq_get_lldp_mib
3545 * @hw: pointer to the hw struct
3546 * @bridge_type: type of bridge requested
3547 * @mib_type: Local, Remote or both Local and Remote MIBs
3548 * @buff: pointer to a user supplied buffer to store the MIB block
3549 * @buff_size: size of the buffer (in bytes)
3550 * @local_len : length of the returned Local LLDP MIB
3551 * @remote_len: length of the returned Remote LLDP MIB
3552 * @cmd_details: pointer to command details structure or NULL
3553 *
3554 * Requests the complete LLDP MIB (entire packet).
3555 **/
3556i40e_status i40e_aq_get_lldp_mib(struct i40e_hw *hw, u8 bridge_type,
3557 u8 mib_type, void *buff, u16 buff_size,
3558 u16 *local_len, u16 *remote_len,
3559 struct i40e_asq_cmd_details *cmd_details)
3560{
3561 struct i40e_aq_desc desc;
3562 struct i40e_aqc_lldp_get_mib *cmd =
3563 (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
3564 struct i40e_aqc_lldp_get_mib *resp =
3565 (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
3566 i40e_status status;
3567
3568 if (buff_size == 0 || !buff)
3569 return I40E_ERR_PARAM;
3570
3571 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_get_mib);
3572 /* Indirect Command */
3573 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3574
3575 cmd->type = mib_type & I40E_AQ_LLDP_MIB_TYPE_MASK;
3576 cmd->type |= ((bridge_type << I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) &
3577 I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
3578
3579 desc.datalen = cpu_to_le16(buff_size);
3580
3581 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3582 if (buff_size > I40E_AQ_LARGE_BUF)
3583 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3584
3585 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3586 if (!status) {
3587 if (local_len != NULL)
3588 *local_len = le16_to_cpu(resp->local_len);
3589 if (remote_len != NULL)
3590 *remote_len = le16_to_cpu(resp->remote_len);
3591 }
3592
3593 return status;
3594}
3595
3596/**
3597 * i40e_aq_cfg_lldp_mib_change_event
3598 * @hw: pointer to the hw struct
3599 * @enable_update: Enable or Disable event posting
3600 * @cmd_details: pointer to command details structure or NULL
3601 *
3602 * Enable or Disable posting of an event on ARQ when LLDP MIB
3603 * associated with the interface changes
3604 **/
3605i40e_status i40e_aq_cfg_lldp_mib_change_event(struct i40e_hw *hw,
3606 bool enable_update,
3607 struct i40e_asq_cmd_details *cmd_details)
3608{
3609 struct i40e_aq_desc desc;
3610 struct i40e_aqc_lldp_update_mib *cmd =
3611 (struct i40e_aqc_lldp_update_mib *)&desc.params.raw;
3612 i40e_status status;
3613
3614 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_update_mib);
3615
3616 if (!enable_update)
3617 cmd->command |= I40E_AQ_LLDP_MIB_UPDATE_DISABLE;
3618
3619 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3620
3621 return status;
3622}
3623
3624/**
3625 * i40e_aq_stop_lldp
3626 * @hw: pointer to the hw struct
3627 * @shutdown_agent: True if LLDP Agent needs to be Shutdown
3628 * @cmd_details: pointer to command details structure or NULL
3629 *
3630 * Stop or Shutdown the embedded LLDP Agent
3631 **/
3632i40e_status i40e_aq_stop_lldp(struct i40e_hw *hw, bool shutdown_agent,
3633 struct i40e_asq_cmd_details *cmd_details)
3634{
3635 struct i40e_aq_desc desc;
3636 struct i40e_aqc_lldp_stop *cmd =
3637 (struct i40e_aqc_lldp_stop *)&desc.params.raw;
3638 i40e_status status;
3639
3640 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_stop);
3641
3642 if (shutdown_agent)
3643 cmd->command |= I40E_AQ_LLDP_AGENT_SHUTDOWN;
3644
3645 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3646
3647 return status;
3648}
3649
3650/**
3651 * i40e_aq_start_lldp
3652 * @hw: pointer to the hw struct
Jacob Kellerf5254422018-04-20 01:41:33 -07003653 * @buff: buffer for result
3654 * @buff_size: buffer size
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003655 * @cmd_details: pointer to command details structure or NULL
3656 *
3657 * Start the embedded LLDP Agent on all ports.
3658 **/
3659i40e_status i40e_aq_start_lldp(struct i40e_hw *hw,
3660 struct i40e_asq_cmd_details *cmd_details)
3661{
3662 struct i40e_aq_desc desc;
3663 struct i40e_aqc_lldp_start *cmd =
3664 (struct i40e_aqc_lldp_start *)&desc.params.raw;
3665 i40e_status status;
3666
3667 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_start);
3668
3669 cmd->command = I40E_AQ_LLDP_AGENT_START;
Upasana Menonb6a02a62017-12-27 08:17:07 -05003670 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003671
Upasana Menonb6a02a62017-12-27 08:17:07 -05003672 return status;
3673}
3674
3675/**
3676 * i40e_aq_set_dcb_parameters
3677 * @hw: pointer to the hw struct
3678 * @cmd_details: pointer to command details structure or NULL
3679 * @dcb_enable: True if DCB configuration needs to be applied
3680 *
3681 **/
3682enum i40e_status_code
3683i40e_aq_set_dcb_parameters(struct i40e_hw *hw, bool dcb_enable,
3684 struct i40e_asq_cmd_details *cmd_details)
3685{
3686 struct i40e_aq_desc desc;
3687 struct i40e_aqc_set_dcb_parameters *cmd =
3688 (struct i40e_aqc_set_dcb_parameters *)&desc.params.raw;
3689 i40e_status status;
3690
3691 i40e_fill_default_direct_cmd_desc(&desc,
3692 i40e_aqc_opc_set_dcb_parameters);
3693
3694 if (dcb_enable) {
3695 cmd->valid_flags = I40E_DCB_VALID;
3696 cmd->command = I40E_AQ_DCB_SET_AGENT;
3697 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003698 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3699
3700 return status;
3701}
3702
3703/**
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00003704 * i40e_aq_get_cee_dcb_config
3705 * @hw: pointer to the hw struct
3706 * @buff: response buffer that stores CEE operational configuration
3707 * @buff_size: size of the buffer passed
3708 * @cmd_details: pointer to command details structure or NULL
3709 *
3710 * Get CEE DCBX mode operational configuration from firmware
3711 **/
3712i40e_status i40e_aq_get_cee_dcb_config(struct i40e_hw *hw,
3713 void *buff, u16 buff_size,
3714 struct i40e_asq_cmd_details *cmd_details)
3715{
3716 struct i40e_aq_desc desc;
3717 i40e_status status;
3718
3719 if (buff_size == 0 || !buff)
3720 return I40E_ERR_PARAM;
3721
3722 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_cee_dcb_cfg);
3723
3724 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3725 status = i40e_asq_send_command(hw, &desc, (void *)buff, buff_size,
3726 cmd_details);
3727
3728 return status;
3729}
3730
3731/**
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003732 * i40e_aq_add_udp_tunnel
3733 * @hw: pointer to the hw struct
Jacob Keller15d23b42017-06-07 05:43:04 -04003734 * @udp_port: the UDP port to add in Host byte order
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003735 * @protocol_index: protocol index type
Jeff Kirsher98d44382013-12-21 05:44:42 +00003736 * @filter_index: pointer to filter index
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003737 * @cmd_details: pointer to command details structure or NULL
Jacob Keller15d23b42017-06-07 05:43:04 -04003738 *
3739 * Note: Firmware expects the udp_port value to be in Little Endian format,
3740 * and this function will call cpu_to_le16 to convert from Host byte order to
3741 * Little Endian order.
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003742 **/
3743i40e_status i40e_aq_add_udp_tunnel(struct i40e_hw *hw,
Kevin Scottf4f94b92014-04-05 07:46:10 +00003744 u16 udp_port, u8 protocol_index,
3745 u8 *filter_index,
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003746 struct i40e_asq_cmd_details *cmd_details)
3747{
3748 struct i40e_aq_desc desc;
3749 struct i40e_aqc_add_udp_tunnel *cmd =
3750 (struct i40e_aqc_add_udp_tunnel *)&desc.params.raw;
3751 struct i40e_aqc_del_udp_tunnel_completion *resp =
3752 (struct i40e_aqc_del_udp_tunnel_completion *)&desc.params.raw;
3753 i40e_status status;
3754
3755 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_udp_tunnel);
3756
3757 cmd->udp_port = cpu_to_le16(udp_port);
Shannon Nelson981b7542013-12-11 08:17:11 +00003758 cmd->protocol_type = protocol_index;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003759
3760 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3761
Shannon Nelson65d13462015-02-21 06:45:28 +00003762 if (!status && filter_index)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003763 *filter_index = resp->index;
3764
3765 return status;
3766}
3767
3768/**
3769 * i40e_aq_del_udp_tunnel
3770 * @hw: pointer to the hw struct
3771 * @index: filter index
3772 * @cmd_details: pointer to command details structure or NULL
3773 **/
3774i40e_status i40e_aq_del_udp_tunnel(struct i40e_hw *hw, u8 index,
3775 struct i40e_asq_cmd_details *cmd_details)
3776{
3777 struct i40e_aq_desc desc;
3778 struct i40e_aqc_remove_udp_tunnel *cmd =
3779 (struct i40e_aqc_remove_udp_tunnel *)&desc.params.raw;
3780 i40e_status status;
3781
3782 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_del_udp_tunnel);
3783
3784 cmd->index = index;
3785
3786 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3787
3788 return status;
3789}
3790
3791/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003792 * i40e_aq_delete_element - Delete switch element
3793 * @hw: pointer to the hw struct
3794 * @seid: the SEID to delete from the switch
3795 * @cmd_details: pointer to command details structure or NULL
3796 *
3797 * This deletes a switch element from the switch.
3798 **/
3799i40e_status i40e_aq_delete_element(struct i40e_hw *hw, u16 seid,
3800 struct i40e_asq_cmd_details *cmd_details)
3801{
3802 struct i40e_aq_desc desc;
3803 struct i40e_aqc_switch_seid *cmd =
3804 (struct i40e_aqc_switch_seid *)&desc.params.raw;
3805 i40e_status status;
3806
3807 if (seid == 0)
3808 return I40E_ERR_PARAM;
3809
3810 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_delete_element);
3811
3812 cmd->seid = cpu_to_le16(seid);
3813
3814 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3815
3816 return status;
3817}
3818
3819/**
Neerav Parikhafb3ff02014-01-17 15:36:36 -08003820 * i40e_aq_dcb_updated - DCB Updated Command
3821 * @hw: pointer to the hw struct
3822 * @cmd_details: pointer to command details structure or NULL
3823 *
3824 * EMP will return when the shared RPB settings have been
3825 * recomputed and modified. The retval field in the descriptor
3826 * will be set to 0 when RPB is modified.
3827 **/
3828i40e_status i40e_aq_dcb_updated(struct i40e_hw *hw,
3829 struct i40e_asq_cmd_details *cmd_details)
3830{
3831 struct i40e_aq_desc desc;
3832 i40e_status status;
3833
3834 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_dcb_updated);
3835
3836 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3837
3838 return status;
3839}
3840
3841/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003842 * i40e_aq_tx_sched_cmd - generic Tx scheduler AQ command handler
3843 * @hw: pointer to the hw struct
3844 * @seid: seid for the physical port/switching component/vsi
3845 * @buff: Indirect buffer to hold data parameters and response
3846 * @buff_size: Indirect buffer size
3847 * @opcode: Tx scheduler AQ command opcode
3848 * @cmd_details: pointer to command details structure or NULL
3849 *
3850 * Generic command handler for Tx scheduler AQ commands
3851 **/
3852static i40e_status i40e_aq_tx_sched_cmd(struct i40e_hw *hw, u16 seid,
3853 void *buff, u16 buff_size,
3854 enum i40e_admin_queue_opc opcode,
3855 struct i40e_asq_cmd_details *cmd_details)
3856{
3857 struct i40e_aq_desc desc;
3858 struct i40e_aqc_tx_sched_ind *cmd =
3859 (struct i40e_aqc_tx_sched_ind *)&desc.params.raw;
3860 i40e_status status;
3861 bool cmd_param_flag = false;
3862
3863 switch (opcode) {
3864 case i40e_aqc_opc_configure_vsi_ets_sla_bw_limit:
3865 case i40e_aqc_opc_configure_vsi_tc_bw:
3866 case i40e_aqc_opc_enable_switching_comp_ets:
3867 case i40e_aqc_opc_modify_switching_comp_ets:
3868 case i40e_aqc_opc_disable_switching_comp_ets:
3869 case i40e_aqc_opc_configure_switching_comp_ets_bw_limit:
3870 case i40e_aqc_opc_configure_switching_comp_bw_config:
3871 cmd_param_flag = true;
3872 break;
3873 case i40e_aqc_opc_query_vsi_bw_config:
3874 case i40e_aqc_opc_query_vsi_ets_sla_config:
3875 case i40e_aqc_opc_query_switching_comp_ets_config:
3876 case i40e_aqc_opc_query_port_ets_config:
3877 case i40e_aqc_opc_query_switching_comp_bw_config:
3878 cmd_param_flag = false;
3879 break;
3880 default:
3881 return I40E_ERR_PARAM;
3882 }
3883
3884 i40e_fill_default_direct_cmd_desc(&desc, opcode);
3885
3886 /* Indirect command */
3887 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3888 if (cmd_param_flag)
3889 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
3890 if (buff_size > I40E_AQ_LARGE_BUF)
3891 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3892
3893 desc.datalen = cpu_to_le16(buff_size);
3894
3895 cmd->vsi_seid = cpu_to_le16(seid);
3896
3897 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3898
3899 return status;
3900}
3901
3902/**
Mitch Williams6b192892014-03-06 09:02:29 +00003903 * i40e_aq_config_vsi_bw_limit - Configure VSI BW Limit
3904 * @hw: pointer to the hw struct
3905 * @seid: VSI seid
3906 * @credit: BW limit credits (0 = disabled)
3907 * @max_credit: Max BW limit credits
3908 * @cmd_details: pointer to command details structure or NULL
3909 **/
3910i40e_status i40e_aq_config_vsi_bw_limit(struct i40e_hw *hw,
3911 u16 seid, u16 credit, u8 max_credit,
3912 struct i40e_asq_cmd_details *cmd_details)
3913{
3914 struct i40e_aq_desc desc;
3915 struct i40e_aqc_configure_vsi_bw_limit *cmd =
3916 (struct i40e_aqc_configure_vsi_bw_limit *)&desc.params.raw;
3917 i40e_status status;
3918
3919 i40e_fill_default_direct_cmd_desc(&desc,
3920 i40e_aqc_opc_configure_vsi_bw_limit);
3921
3922 cmd->vsi_seid = cpu_to_le16(seid);
3923 cmd->credit = cpu_to_le16(credit);
3924 cmd->max_credit = max_credit;
3925
3926 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3927
3928 return status;
3929}
3930
3931/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003932 * i40e_aq_config_vsi_tc_bw - Config VSI BW Allocation per TC
3933 * @hw: pointer to the hw struct
3934 * @seid: VSI seid
3935 * @bw_data: Buffer holding enabled TCs, relative TC BW limit/credits
3936 * @cmd_details: pointer to command details structure or NULL
3937 **/
3938i40e_status i40e_aq_config_vsi_tc_bw(struct i40e_hw *hw,
3939 u16 seid,
3940 struct i40e_aqc_configure_vsi_tc_bw_data *bw_data,
3941 struct i40e_asq_cmd_details *cmd_details)
3942{
3943 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3944 i40e_aqc_opc_configure_vsi_tc_bw,
3945 cmd_details);
3946}
3947
3948/**
Neerav Parikhafb3ff02014-01-17 15:36:36 -08003949 * i40e_aq_config_switch_comp_ets - Enable/Disable/Modify ETS on the port
3950 * @hw: pointer to the hw struct
3951 * @seid: seid of the switching component connected to Physical Port
3952 * @ets_data: Buffer holding ETS parameters
Jacob Kellerf5254422018-04-20 01:41:33 -07003953 * @opcode: Tx scheduler AQ command opcode
Neerav Parikhafb3ff02014-01-17 15:36:36 -08003954 * @cmd_details: pointer to command details structure or NULL
3955 **/
3956i40e_status i40e_aq_config_switch_comp_ets(struct i40e_hw *hw,
3957 u16 seid,
3958 struct i40e_aqc_configure_switching_comp_ets_data *ets_data,
3959 enum i40e_admin_queue_opc opcode,
3960 struct i40e_asq_cmd_details *cmd_details)
3961{
3962 return i40e_aq_tx_sched_cmd(hw, seid, (void *)ets_data,
3963 sizeof(*ets_data), opcode, cmd_details);
3964}
3965
3966/**
3967 * i40e_aq_config_switch_comp_bw_config - Config Switch comp BW Alloc per TC
3968 * @hw: pointer to the hw struct
3969 * @seid: seid of the switching component
3970 * @bw_data: Buffer holding enabled TCs, relative/absolute TC BW limit/credits
3971 * @cmd_details: pointer to command details structure or NULL
3972 **/
3973i40e_status i40e_aq_config_switch_comp_bw_config(struct i40e_hw *hw,
3974 u16 seid,
3975 struct i40e_aqc_configure_switching_comp_bw_config_data *bw_data,
3976 struct i40e_asq_cmd_details *cmd_details)
3977{
3978 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3979 i40e_aqc_opc_configure_switching_comp_bw_config,
3980 cmd_details);
3981}
3982
3983/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003984 * i40e_aq_query_vsi_bw_config - Query VSI BW configuration
3985 * @hw: pointer to the hw struct
3986 * @seid: seid of the VSI
3987 * @bw_data: Buffer to hold VSI BW configuration
3988 * @cmd_details: pointer to command details structure or NULL
3989 **/
3990i40e_status i40e_aq_query_vsi_bw_config(struct i40e_hw *hw,
3991 u16 seid,
3992 struct i40e_aqc_query_vsi_bw_config_resp *bw_data,
3993 struct i40e_asq_cmd_details *cmd_details)
3994{
3995 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3996 i40e_aqc_opc_query_vsi_bw_config,
3997 cmd_details);
3998}
3999
4000/**
4001 * i40e_aq_query_vsi_ets_sla_config - Query VSI BW configuration per TC
4002 * @hw: pointer to the hw struct
4003 * @seid: seid of the VSI
4004 * @bw_data: Buffer to hold VSI BW configuration per TC
4005 * @cmd_details: pointer to command details structure or NULL
4006 **/
4007i40e_status i40e_aq_query_vsi_ets_sla_config(struct i40e_hw *hw,
4008 u16 seid,
4009 struct i40e_aqc_query_vsi_ets_sla_config_resp *bw_data,
4010 struct i40e_asq_cmd_details *cmd_details)
4011{
4012 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
4013 i40e_aqc_opc_query_vsi_ets_sla_config,
4014 cmd_details);
4015}
4016
4017/**
4018 * i40e_aq_query_switch_comp_ets_config - Query Switch comp BW config per TC
4019 * @hw: pointer to the hw struct
4020 * @seid: seid of the switching component
4021 * @bw_data: Buffer to hold switching component's per TC BW config
4022 * @cmd_details: pointer to command details structure or NULL
4023 **/
4024i40e_status i40e_aq_query_switch_comp_ets_config(struct i40e_hw *hw,
4025 u16 seid,
4026 struct i40e_aqc_query_switching_comp_ets_config_resp *bw_data,
4027 struct i40e_asq_cmd_details *cmd_details)
4028{
4029 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
4030 i40e_aqc_opc_query_switching_comp_ets_config,
4031 cmd_details);
4032}
4033
4034/**
4035 * i40e_aq_query_port_ets_config - Query Physical Port ETS configuration
4036 * @hw: pointer to the hw struct
4037 * @seid: seid of the VSI or switching component connected to Physical Port
4038 * @bw_data: Buffer to hold current ETS configuration for the Physical Port
4039 * @cmd_details: pointer to command details structure or NULL
4040 **/
4041i40e_status i40e_aq_query_port_ets_config(struct i40e_hw *hw,
4042 u16 seid,
4043 struct i40e_aqc_query_port_ets_config_resp *bw_data,
4044 struct i40e_asq_cmd_details *cmd_details)
4045{
4046 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
4047 i40e_aqc_opc_query_port_ets_config,
4048 cmd_details);
4049}
4050
4051/**
4052 * i40e_aq_query_switch_comp_bw_config - Query Switch comp BW configuration
4053 * @hw: pointer to the hw struct
4054 * @seid: seid of the switching component
4055 * @bw_data: Buffer to hold switching component's BW configuration
4056 * @cmd_details: pointer to command details structure or NULL
4057 **/
4058i40e_status i40e_aq_query_switch_comp_bw_config(struct i40e_hw *hw,
4059 u16 seid,
4060 struct i40e_aqc_query_switching_comp_bw_config_resp *bw_data,
4061 struct i40e_asq_cmd_details *cmd_details)
4062{
4063 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
4064 i40e_aqc_opc_query_switching_comp_bw_config,
4065 cmd_details);
4066}
4067
4068/**
4069 * i40e_validate_filter_settings
4070 * @hw: pointer to the hardware structure
4071 * @settings: Filter control settings
4072 *
4073 * Check and validate the filter control settings passed.
4074 * The function checks for the valid filter/context sizes being
4075 * passed for FCoE and PE.
4076 *
4077 * Returns 0 if the values passed are valid and within
4078 * range else returns an error.
4079 **/
4080static i40e_status i40e_validate_filter_settings(struct i40e_hw *hw,
4081 struct i40e_filter_control_settings *settings)
4082{
4083 u32 fcoe_cntx_size, fcoe_filt_size;
4084 u32 pe_cntx_size, pe_filt_size;
Anjali Singhai Jain467d7292014-05-10 04:49:02 +00004085 u32 fcoe_fmax;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00004086 u32 val;
4087
4088 /* Validate FCoE settings passed */
4089 switch (settings->fcoe_filt_num) {
4090 case I40E_HASH_FILTER_SIZE_1K:
4091 case I40E_HASH_FILTER_SIZE_2K:
4092 case I40E_HASH_FILTER_SIZE_4K:
4093 case I40E_HASH_FILTER_SIZE_8K:
4094 case I40E_HASH_FILTER_SIZE_16K:
4095 case I40E_HASH_FILTER_SIZE_32K:
4096 fcoe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
4097 fcoe_filt_size <<= (u32)settings->fcoe_filt_num;
4098 break;
4099 default:
4100 return I40E_ERR_PARAM;
4101 }
4102
4103 switch (settings->fcoe_cntx_num) {
4104 case I40E_DMA_CNTX_SIZE_512:
4105 case I40E_DMA_CNTX_SIZE_1K:
4106 case I40E_DMA_CNTX_SIZE_2K:
4107 case I40E_DMA_CNTX_SIZE_4K:
4108 fcoe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
4109 fcoe_cntx_size <<= (u32)settings->fcoe_cntx_num;
4110 break;
4111 default:
4112 return I40E_ERR_PARAM;
4113 }
4114
4115 /* Validate PE settings passed */
4116 switch (settings->pe_filt_num) {
4117 case I40E_HASH_FILTER_SIZE_1K:
4118 case I40E_HASH_FILTER_SIZE_2K:
4119 case I40E_HASH_FILTER_SIZE_4K:
4120 case I40E_HASH_FILTER_SIZE_8K:
4121 case I40E_HASH_FILTER_SIZE_16K:
4122 case I40E_HASH_FILTER_SIZE_32K:
4123 case I40E_HASH_FILTER_SIZE_64K:
4124 case I40E_HASH_FILTER_SIZE_128K:
4125 case I40E_HASH_FILTER_SIZE_256K:
4126 case I40E_HASH_FILTER_SIZE_512K:
4127 case I40E_HASH_FILTER_SIZE_1M:
4128 pe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
4129 pe_filt_size <<= (u32)settings->pe_filt_num;
4130 break;
4131 default:
4132 return I40E_ERR_PARAM;
4133 }
4134
4135 switch (settings->pe_cntx_num) {
4136 case I40E_DMA_CNTX_SIZE_512:
4137 case I40E_DMA_CNTX_SIZE_1K:
4138 case I40E_DMA_CNTX_SIZE_2K:
4139 case I40E_DMA_CNTX_SIZE_4K:
4140 case I40E_DMA_CNTX_SIZE_8K:
4141 case I40E_DMA_CNTX_SIZE_16K:
4142 case I40E_DMA_CNTX_SIZE_32K:
4143 case I40E_DMA_CNTX_SIZE_64K:
4144 case I40E_DMA_CNTX_SIZE_128K:
4145 case I40E_DMA_CNTX_SIZE_256K:
4146 pe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
4147 pe_cntx_size <<= (u32)settings->pe_cntx_num;
4148 break;
4149 default:
4150 return I40E_ERR_PARAM;
4151 }
4152
4153 /* FCHSIZE + FCDSIZE should not be greater than PMFCOEFMAX */
4154 val = rd32(hw, I40E_GLHMC_FCOEFMAX);
4155 fcoe_fmax = (val & I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_MASK)
4156 >> I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_SHIFT;
4157 if (fcoe_filt_size + fcoe_cntx_size > fcoe_fmax)
4158 return I40E_ERR_INVALID_SIZE;
4159
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00004160 return 0;
4161}
4162
4163/**
4164 * i40e_set_filter_control
4165 * @hw: pointer to the hardware structure
4166 * @settings: Filter control settings
4167 *
4168 * Set the Queue Filters for PE/FCoE and enable filters required
4169 * for a single PF. It is expected that these settings are programmed
4170 * at the driver initialization time.
4171 **/
4172i40e_status i40e_set_filter_control(struct i40e_hw *hw,
4173 struct i40e_filter_control_settings *settings)
4174{
4175 i40e_status ret = 0;
4176 u32 hash_lut_size = 0;
4177 u32 val;
4178
4179 if (!settings)
4180 return I40E_ERR_PARAM;
4181
4182 /* Validate the input settings */
4183 ret = i40e_validate_filter_settings(hw, settings);
4184 if (ret)
4185 return ret;
4186
4187 /* Read the PF Queue Filter control register */
Shannon Nelsonf6581372016-02-17 16:12:20 -08004188 val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00004189
4190 /* Program required PE hash buckets for the PF */
4191 val &= ~I40E_PFQF_CTL_0_PEHSIZE_MASK;
4192 val |= ((u32)settings->pe_filt_num << I40E_PFQF_CTL_0_PEHSIZE_SHIFT) &
4193 I40E_PFQF_CTL_0_PEHSIZE_MASK;
4194 /* Program required PE contexts for the PF */
4195 val &= ~I40E_PFQF_CTL_0_PEDSIZE_MASK;
4196 val |= ((u32)settings->pe_cntx_num << I40E_PFQF_CTL_0_PEDSIZE_SHIFT) &
4197 I40E_PFQF_CTL_0_PEDSIZE_MASK;
4198
4199 /* Program required FCoE hash buckets for the PF */
4200 val &= ~I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
4201 val |= ((u32)settings->fcoe_filt_num <<
4202 I40E_PFQF_CTL_0_PFFCHSIZE_SHIFT) &
4203 I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
4204 /* Program required FCoE DDP contexts for the PF */
4205 val &= ~I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
4206 val |= ((u32)settings->fcoe_cntx_num <<
4207 I40E_PFQF_CTL_0_PFFCDSIZE_SHIFT) &
4208 I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
4209
4210 /* Program Hash LUT size for the PF */
4211 val &= ~I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
4212 if (settings->hash_lut_size == I40E_HASH_LUT_SIZE_512)
4213 hash_lut_size = 1;
4214 val |= (hash_lut_size << I40E_PFQF_CTL_0_HASHLUTSIZE_SHIFT) &
4215 I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
4216
4217 /* Enable FDIR, Ethertype and MACVLAN filters for PF and VFs */
4218 if (settings->enable_fdir)
4219 val |= I40E_PFQF_CTL_0_FD_ENA_MASK;
4220 if (settings->enable_ethtype)
4221 val |= I40E_PFQF_CTL_0_ETYPE_ENA_MASK;
4222 if (settings->enable_macvlan)
4223 val |= I40E_PFQF_CTL_0_MACVLAN_ENA_MASK;
4224
Shannon Nelsonf6581372016-02-17 16:12:20 -08004225 i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, val);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00004226
4227 return 0;
4228}
Neerav Parikhafb3ff02014-01-17 15:36:36 -08004229
4230/**
4231 * i40e_aq_add_rem_control_packet_filter - Add or Remove Control Packet Filter
4232 * @hw: pointer to the hw struct
4233 * @mac_addr: MAC address to use in the filter
4234 * @ethtype: Ethertype to use in the filter
4235 * @flags: Flags that needs to be applied to the filter
4236 * @vsi_seid: seid of the control VSI
4237 * @queue: VSI queue number to send the packet to
4238 * @is_add: Add control packet filter if True else remove
4239 * @stats: Structure to hold information on control filter counts
4240 * @cmd_details: pointer to command details structure or NULL
4241 *
4242 * This command will Add or Remove control packet filter for a control VSI.
4243 * In return it will update the total number of perfect filter count in
4244 * the stats member.
4245 **/
4246i40e_status i40e_aq_add_rem_control_packet_filter(struct i40e_hw *hw,
4247 u8 *mac_addr, u16 ethtype, u16 flags,
4248 u16 vsi_seid, u16 queue, bool is_add,
4249 struct i40e_control_filter_stats *stats,
4250 struct i40e_asq_cmd_details *cmd_details)
4251{
4252 struct i40e_aq_desc desc;
4253 struct i40e_aqc_add_remove_control_packet_filter *cmd =
4254 (struct i40e_aqc_add_remove_control_packet_filter *)
4255 &desc.params.raw;
4256 struct i40e_aqc_add_remove_control_packet_filter_completion *resp =
4257 (struct i40e_aqc_add_remove_control_packet_filter_completion *)
4258 &desc.params.raw;
4259 i40e_status status;
4260
4261 if (vsi_seid == 0)
4262 return I40E_ERR_PARAM;
4263
4264 if (is_add) {
4265 i40e_fill_default_direct_cmd_desc(&desc,
4266 i40e_aqc_opc_add_control_packet_filter);
4267 cmd->queue = cpu_to_le16(queue);
4268 } else {
4269 i40e_fill_default_direct_cmd_desc(&desc,
4270 i40e_aqc_opc_remove_control_packet_filter);
4271 }
4272
4273 if (mac_addr)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04004274 ether_addr_copy(cmd->mac, mac_addr);
Neerav Parikhafb3ff02014-01-17 15:36:36 -08004275
4276 cmd->etype = cpu_to_le16(ethtype);
4277 cmd->flags = cpu_to_le16(flags);
4278 cmd->seid = cpu_to_le16(vsi_seid);
4279
4280 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4281
4282 if (!status && stats) {
4283 stats->mac_etype_used = le16_to_cpu(resp->mac_etype_used);
4284 stats->etype_used = le16_to_cpu(resp->etype_used);
4285 stats->mac_etype_free = le16_to_cpu(resp->mac_etype_free);
4286 stats->etype_free = le16_to_cpu(resp->etype_free);
4287 }
4288
4289 return status;
4290}
4291
Catherine Sullivand4dfb812013-11-28 06:39:21 +00004292/**
Anjali Singhai Jaine7358f52015-10-01 14:37:34 -04004293 * i40e_add_filter_to_drop_tx_flow_control_frames- filter to drop flow control
4294 * @hw: pointer to the hw struct
4295 * @seid: VSI seid to add ethertype filter from
4296 **/
Anjali Singhai Jaine7358f52015-10-01 14:37:34 -04004297void i40e_add_filter_to_drop_tx_flow_control_frames(struct i40e_hw *hw,
4298 u16 seid)
4299{
Jacob Kellerf5254422018-04-20 01:41:33 -07004300#define I40E_FLOW_CONTROL_ETHTYPE 0x8808
Anjali Singhai Jaine7358f52015-10-01 14:37:34 -04004301 u16 flag = I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC |
4302 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP |
4303 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX;
4304 u16 ethtype = I40E_FLOW_CONTROL_ETHTYPE;
4305 i40e_status status;
4306
4307 status = i40e_aq_add_rem_control_packet_filter(hw, NULL, ethtype, flag,
4308 seid, 0, true, NULL,
4309 NULL);
4310 if (status)
4311 hw_dbg(hw, "Ethtype Filter Add failed: Error pruning Tx flow control frames\n");
4312}
4313
4314/**
Greg Rosef4492db2015-02-06 08:52:12 +00004315 * i40e_aq_alternate_read
4316 * @hw: pointer to the hardware structure
4317 * @reg_addr0: address of first dword to be read
4318 * @reg_val0: pointer for data read from 'reg_addr0'
4319 * @reg_addr1: address of second dword to be read
4320 * @reg_val1: pointer for data read from 'reg_addr1'
4321 *
4322 * Read one or two dwords from alternate structure. Fields are indicated
4323 * by 'reg_addr0' and 'reg_addr1' register numbers. If 'reg_val1' pointer
4324 * is not passed then only register at 'reg_addr0' is read.
4325 *
4326 **/
Shannon Nelson37a29732015-02-27 09:15:19 +00004327static i40e_status i40e_aq_alternate_read(struct i40e_hw *hw,
4328 u32 reg_addr0, u32 *reg_val0,
4329 u32 reg_addr1, u32 *reg_val1)
Greg Rosef4492db2015-02-06 08:52:12 +00004330{
4331 struct i40e_aq_desc desc;
4332 struct i40e_aqc_alternate_write *cmd_resp =
4333 (struct i40e_aqc_alternate_write *)&desc.params.raw;
4334 i40e_status status;
4335
4336 if (!reg_val0)
4337 return I40E_ERR_PARAM;
4338
4339 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_alternate_read);
4340 cmd_resp->address0 = cpu_to_le32(reg_addr0);
4341 cmd_resp->address1 = cpu_to_le32(reg_addr1);
4342
4343 status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
4344
4345 if (!status) {
4346 *reg_val0 = le32_to_cpu(cmd_resp->data0);
4347
4348 if (reg_val1)
4349 *reg_val1 = le32_to_cpu(cmd_resp->data1);
4350 }
4351
4352 return status;
4353}
4354
4355/**
Neerav Parikh2fd75f32014-11-12 00:18:20 +00004356 * i40e_aq_resume_port_tx
4357 * @hw: pointer to the hardware structure
4358 * @cmd_details: pointer to command details structure or NULL
4359 *
4360 * Resume port's Tx traffic
4361 **/
4362i40e_status i40e_aq_resume_port_tx(struct i40e_hw *hw,
4363 struct i40e_asq_cmd_details *cmd_details)
4364{
4365 struct i40e_aq_desc desc;
4366 i40e_status status;
4367
4368 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_resume_port_tx);
4369
4370 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4371
4372 return status;
4373}
4374
4375/**
Catherine Sullivand4dfb812013-11-28 06:39:21 +00004376 * i40e_set_pci_config_data - store PCI bus info
4377 * @hw: pointer to hardware structure
4378 * @link_status: the link status word from PCI config space
4379 *
4380 * Stores the PCI bus info (speed, width, type) within the i40e_hw structure
4381 **/
4382void i40e_set_pci_config_data(struct i40e_hw *hw, u16 link_status)
4383{
4384 hw->bus.type = i40e_bus_type_pci_express;
4385
4386 switch (link_status & PCI_EXP_LNKSTA_NLW) {
4387 case PCI_EXP_LNKSTA_NLW_X1:
4388 hw->bus.width = i40e_bus_width_pcie_x1;
4389 break;
4390 case PCI_EXP_LNKSTA_NLW_X2:
4391 hw->bus.width = i40e_bus_width_pcie_x2;
4392 break;
4393 case PCI_EXP_LNKSTA_NLW_X4:
4394 hw->bus.width = i40e_bus_width_pcie_x4;
4395 break;
4396 case PCI_EXP_LNKSTA_NLW_X8:
4397 hw->bus.width = i40e_bus_width_pcie_x8;
4398 break;
4399 default:
4400 hw->bus.width = i40e_bus_width_unknown;
4401 break;
4402 }
4403
4404 switch (link_status & PCI_EXP_LNKSTA_CLS) {
4405 case PCI_EXP_LNKSTA_CLS_2_5GB:
4406 hw->bus.speed = i40e_bus_speed_2500;
4407 break;
4408 case PCI_EXP_LNKSTA_CLS_5_0GB:
4409 hw->bus.speed = i40e_bus_speed_5000;
4410 break;
4411 case PCI_EXP_LNKSTA_CLS_8_0GB:
4412 hw->bus.speed = i40e_bus_speed_8000;
4413 break;
4414 default:
4415 hw->bus.speed = i40e_bus_speed_unknown;
4416 break;
4417 }
4418}
Greg Rosef4492db2015-02-06 08:52:12 +00004419
4420/**
Jesse Brandeburg3169c322015-04-07 19:45:37 -04004421 * i40e_aq_debug_dump
4422 * @hw: pointer to the hardware structure
4423 * @cluster_id: specific cluster to dump
4424 * @table_id: table id within cluster
4425 * @start_index: index of line in the block to read
4426 * @buff_size: dump buffer size
4427 * @buff: dump buffer
4428 * @ret_buff_size: actual buffer size returned
4429 * @ret_next_table: next block to read
4430 * @ret_next_index: next index to read
Jacob Kellerf5254422018-04-20 01:41:33 -07004431 * @cmd_details: pointer to command details structure or NULL
Jesse Brandeburg3169c322015-04-07 19:45:37 -04004432 *
4433 * Dump internal FW/HW data for debug purposes.
4434 *
4435 **/
4436i40e_status i40e_aq_debug_dump(struct i40e_hw *hw, u8 cluster_id,
4437 u8 table_id, u32 start_index, u16 buff_size,
4438 void *buff, u16 *ret_buff_size,
4439 u8 *ret_next_table, u32 *ret_next_index,
4440 struct i40e_asq_cmd_details *cmd_details)
4441{
4442 struct i40e_aq_desc desc;
4443 struct i40e_aqc_debug_dump_internals *cmd =
4444 (struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
4445 struct i40e_aqc_debug_dump_internals *resp =
4446 (struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
4447 i40e_status status;
4448
4449 if (buff_size == 0 || !buff)
4450 return I40E_ERR_PARAM;
4451
4452 i40e_fill_default_direct_cmd_desc(&desc,
4453 i40e_aqc_opc_debug_dump_internals);
4454 /* Indirect Command */
4455 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
4456 if (buff_size > I40E_AQ_LARGE_BUF)
4457 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
4458
4459 cmd->cluster_id = cluster_id;
4460 cmd->table_id = table_id;
4461 cmd->idx = cpu_to_le32(start_index);
4462
4463 desc.datalen = cpu_to_le16(buff_size);
4464
4465 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
4466 if (!status) {
4467 if (ret_buff_size)
4468 *ret_buff_size = le16_to_cpu(desc.datalen);
4469 if (ret_next_table)
4470 *ret_next_table = resp->table_id;
4471 if (ret_next_index)
4472 *ret_next_index = le32_to_cpu(resp->idx);
4473 }
4474
4475 return status;
4476}
4477
4478/**
Greg Rosef4492db2015-02-06 08:52:12 +00004479 * i40e_read_bw_from_alt_ram
4480 * @hw: pointer to the hardware structure
4481 * @max_bw: pointer for max_bw read
4482 * @min_bw: pointer for min_bw read
4483 * @min_valid: pointer for bool that is true if min_bw is a valid value
4484 * @max_valid: pointer for bool that is true if max_bw is a valid value
4485 *
4486 * Read bw from the alternate ram for the given pf
4487 **/
4488i40e_status i40e_read_bw_from_alt_ram(struct i40e_hw *hw,
4489 u32 *max_bw, u32 *min_bw,
4490 bool *min_valid, bool *max_valid)
4491{
4492 i40e_status status;
4493 u32 max_bw_addr, min_bw_addr;
4494
4495 /* Calculate the address of the min/max bw registers */
4496 max_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
4497 I40E_ALT_STRUCT_MAX_BW_OFFSET +
4498 (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
4499 min_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
4500 I40E_ALT_STRUCT_MIN_BW_OFFSET +
4501 (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
4502
4503 /* Read the bandwidths from alt ram */
4504 status = i40e_aq_alternate_read(hw, max_bw_addr, max_bw,
4505 min_bw_addr, min_bw);
4506
4507 if (*min_bw & I40E_ALT_BW_VALID_MASK)
4508 *min_valid = true;
4509 else
4510 *min_valid = false;
4511
4512 if (*max_bw & I40E_ALT_BW_VALID_MASK)
4513 *max_valid = true;
4514 else
4515 *max_valid = false;
4516
4517 return status;
4518}
4519
4520/**
4521 * i40e_aq_configure_partition_bw
4522 * @hw: pointer to the hardware structure
4523 * @bw_data: Buffer holding valid pfs and bw limits
4524 * @cmd_details: pointer to command details
4525 *
4526 * Configure partitions guaranteed/max bw
4527 **/
4528i40e_status i40e_aq_configure_partition_bw(struct i40e_hw *hw,
4529 struct i40e_aqc_configure_partition_bw_data *bw_data,
4530 struct i40e_asq_cmd_details *cmd_details)
4531{
4532 i40e_status status;
4533 struct i40e_aq_desc desc;
4534 u16 bwd_size = sizeof(*bw_data);
4535
4536 i40e_fill_default_direct_cmd_desc(&desc,
4537 i40e_aqc_opc_configure_partition_bw);
4538
4539 /* Indirect command */
4540 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
4541 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
4542
4543 if (bwd_size > I40E_AQ_LARGE_BUF)
4544 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
4545
4546 desc.datalen = cpu_to_le16(bwd_size);
4547
4548 status = i40e_asq_send_command(hw, &desc, bw_data, bwd_size,
4549 cmd_details);
4550
4551 return status;
4552}
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004553
4554/**
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004555 * i40e_read_phy_register_clause22
4556 * @hw: pointer to the HW structure
4557 * @reg: register address in the page
Jacob Kellerf5254422018-04-20 01:41:33 -07004558 * @phy_addr: PHY address on MDIO interface
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004559 * @value: PHY register value
4560 *
4561 * Reads specified PHY register value
4562 **/
4563i40e_status i40e_read_phy_register_clause22(struct i40e_hw *hw,
4564 u16 reg, u8 phy_addr, u16 *value)
4565{
4566 i40e_status status = I40E_ERR_TIMEOUT;
4567 u8 port_num = (u8)hw->func_caps.mdio_port_num;
4568 u32 command = 0;
4569 u16 retry = 1000;
4570
4571 command = (reg << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4572 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
4573 (I40E_MDIO_CLAUSE22_OPCODE_READ_MASK) |
4574 (I40E_MDIO_CLAUSE22_STCODE_MASK) |
4575 (I40E_GLGEN_MSCA_MDICMD_MASK);
4576 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4577 do {
4578 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4579 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4580 status = 0;
4581 break;
4582 }
4583 udelay(10);
4584 retry--;
4585 } while (retry);
4586
4587 if (status) {
4588 i40e_debug(hw, I40E_DEBUG_PHY,
4589 "PHY: Can't write command to external PHY.\n");
Henry Tieman27e5f252016-11-08 13:05:06 -08004590 } else {
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004591 command = rd32(hw, I40E_GLGEN_MSRWD(port_num));
4592 *value = (command & I40E_GLGEN_MSRWD_MDIRDDATA_MASK) >>
4593 I40E_GLGEN_MSRWD_MDIRDDATA_SHIFT;
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004594 }
4595
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004596 return status;
4597}
4598
4599/**
4600 * i40e_write_phy_register_clause22
4601 * @hw: pointer to the HW structure
4602 * @reg: register address in the page
Jacob Kellerf5254422018-04-20 01:41:33 -07004603 * @phy_addr: PHY address on MDIO interface
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004604 * @value: PHY register value
4605 *
4606 * Writes specified PHY register value
4607 **/
4608i40e_status i40e_write_phy_register_clause22(struct i40e_hw *hw,
4609 u16 reg, u8 phy_addr, u16 value)
4610{
4611 i40e_status status = I40E_ERR_TIMEOUT;
4612 u8 port_num = (u8)hw->func_caps.mdio_port_num;
4613 u32 command = 0;
4614 u16 retry = 1000;
4615
4616 command = value << I40E_GLGEN_MSRWD_MDIWRDATA_SHIFT;
4617 wr32(hw, I40E_GLGEN_MSRWD(port_num), command);
4618
4619 command = (reg << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4620 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
4621 (I40E_MDIO_CLAUSE22_OPCODE_WRITE_MASK) |
4622 (I40E_MDIO_CLAUSE22_STCODE_MASK) |
4623 (I40E_GLGEN_MSCA_MDICMD_MASK);
4624
4625 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4626 do {
4627 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4628 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4629 status = 0;
4630 break;
4631 }
4632 udelay(10);
4633 retry--;
4634 } while (retry);
4635
4636 return status;
4637}
4638
4639/**
4640 * i40e_read_phy_register_clause45
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004641 * @hw: pointer to the HW structure
4642 * @page: registers page number
4643 * @reg: register address in the page
Jacob Kellerf5254422018-04-20 01:41:33 -07004644 * @phy_addr: PHY address on MDIO interface
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004645 * @value: PHY register value
4646 *
4647 * Reads specified PHY register value
4648 **/
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004649i40e_status i40e_read_phy_register_clause45(struct i40e_hw *hw,
4650 u8 page, u16 reg, u8 phy_addr, u16 *value)
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004651{
4652 i40e_status status = I40E_ERR_TIMEOUT;
4653 u32 command = 0;
4654 u16 retry = 1000;
4655 u8 port_num = hw->func_caps.mdio_port_num;
4656
4657 command = (reg << I40E_GLGEN_MSCA_MDIADD_SHIFT) |
4658 (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4659 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004660 (I40E_MDIO_CLAUSE45_OPCODE_ADDRESS_MASK) |
4661 (I40E_MDIO_CLAUSE45_STCODE_MASK) |
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004662 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4663 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4664 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4665 do {
4666 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4667 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4668 status = 0;
4669 break;
4670 }
4671 usleep_range(10, 20);
4672 retry--;
4673 } while (retry);
4674
4675 if (status) {
4676 i40e_debug(hw, I40E_DEBUG_PHY,
4677 "PHY: Can't write command to external PHY.\n");
4678 goto phy_read_end;
4679 }
4680
4681 command = (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4682 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004683 (I40E_MDIO_CLAUSE45_OPCODE_READ_MASK) |
4684 (I40E_MDIO_CLAUSE45_STCODE_MASK) |
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004685 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4686 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4687 status = I40E_ERR_TIMEOUT;
4688 retry = 1000;
4689 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4690 do {
4691 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4692 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4693 status = 0;
4694 break;
4695 }
4696 usleep_range(10, 20);
4697 retry--;
4698 } while (retry);
4699
4700 if (!status) {
4701 command = rd32(hw, I40E_GLGEN_MSRWD(port_num));
4702 *value = (command & I40E_GLGEN_MSRWD_MDIRDDATA_MASK) >>
4703 I40E_GLGEN_MSRWD_MDIRDDATA_SHIFT;
4704 } else {
4705 i40e_debug(hw, I40E_DEBUG_PHY,
4706 "PHY: Can't read register value from external PHY.\n");
4707 }
4708
4709phy_read_end:
4710 return status;
4711}
4712
4713/**
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004714 * i40e_write_phy_register_clause45
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004715 * @hw: pointer to the HW structure
4716 * @page: registers page number
4717 * @reg: register address in the page
Jacob Kellerf5254422018-04-20 01:41:33 -07004718 * @phy_addr: PHY address on MDIO interface
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004719 * @value: PHY register value
4720 *
4721 * Writes value to specified PHY register
4722 **/
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004723i40e_status i40e_write_phy_register_clause45(struct i40e_hw *hw,
4724 u8 page, u16 reg, u8 phy_addr, u16 value)
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004725{
4726 i40e_status status = I40E_ERR_TIMEOUT;
4727 u32 command = 0;
4728 u16 retry = 1000;
4729 u8 port_num = hw->func_caps.mdio_port_num;
4730
4731 command = (reg << I40E_GLGEN_MSCA_MDIADD_SHIFT) |
4732 (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4733 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004734 (I40E_MDIO_CLAUSE45_OPCODE_ADDRESS_MASK) |
4735 (I40E_MDIO_CLAUSE45_STCODE_MASK) |
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004736 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4737 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4738 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4739 do {
4740 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4741 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4742 status = 0;
4743 break;
4744 }
4745 usleep_range(10, 20);
4746 retry--;
4747 } while (retry);
4748 if (status) {
4749 i40e_debug(hw, I40E_DEBUG_PHY,
4750 "PHY: Can't write command to external PHY.\n");
4751 goto phy_write_end;
4752 }
4753
4754 command = value << I40E_GLGEN_MSRWD_MDIWRDATA_SHIFT;
4755 wr32(hw, I40E_GLGEN_MSRWD(port_num), command);
4756
4757 command = (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4758 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004759 (I40E_MDIO_CLAUSE45_OPCODE_WRITE_MASK) |
4760 (I40E_MDIO_CLAUSE45_STCODE_MASK) |
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004761 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4762 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4763 status = I40E_ERR_TIMEOUT;
4764 retry = 1000;
4765 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4766 do {
4767 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4768 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4769 status = 0;
4770 break;
4771 }
4772 usleep_range(10, 20);
4773 retry--;
4774 } while (retry);
4775
4776phy_write_end:
4777 return status;
4778}
4779
4780/**
Michal Kosiarzf62ba912016-11-21 13:03:50 -08004781 * i40e_write_phy_register
4782 * @hw: pointer to the HW structure
4783 * @page: registers page number
4784 * @reg: register address in the page
Jacob Kellerf5254422018-04-20 01:41:33 -07004785 * @phy_addr: PHY address on MDIO interface
Michal Kosiarzf62ba912016-11-21 13:03:50 -08004786 * @value: PHY register value
4787 *
4788 * Writes value to specified PHY register
4789 **/
4790i40e_status i40e_write_phy_register(struct i40e_hw *hw,
4791 u8 page, u16 reg, u8 phy_addr, u16 value)
4792{
4793 i40e_status status;
4794
4795 switch (hw->device_id) {
4796 case I40E_DEV_ID_1G_BASE_T_X722:
4797 status = i40e_write_phy_register_clause22(hw, reg, phy_addr,
4798 value);
4799 break;
4800 case I40E_DEV_ID_10G_BASE_T:
4801 case I40E_DEV_ID_10G_BASE_T4:
4802 case I40E_DEV_ID_10G_BASE_T_X722:
4803 case I40E_DEV_ID_25G_B:
4804 case I40E_DEV_ID_25G_SFP28:
4805 status = i40e_write_phy_register_clause45(hw, page, reg,
4806 phy_addr, value);
4807 break;
4808 default:
4809 status = I40E_ERR_UNKNOWN_PHY;
4810 break;
4811 }
4812
4813 return status;
4814}
4815
4816/**
4817 * i40e_read_phy_register
4818 * @hw: pointer to the HW structure
4819 * @page: registers page number
4820 * @reg: register address in the page
Jacob Kellerf5254422018-04-20 01:41:33 -07004821 * @phy_addr: PHY address on MDIO interface
Michal Kosiarzf62ba912016-11-21 13:03:50 -08004822 * @value: PHY register value
4823 *
4824 * Reads specified PHY register value
4825 **/
4826i40e_status i40e_read_phy_register(struct i40e_hw *hw,
4827 u8 page, u16 reg, u8 phy_addr, u16 *value)
4828{
4829 i40e_status status;
4830
4831 switch (hw->device_id) {
4832 case I40E_DEV_ID_1G_BASE_T_X722:
4833 status = i40e_read_phy_register_clause22(hw, reg, phy_addr,
4834 value);
4835 break;
4836 case I40E_DEV_ID_10G_BASE_T:
4837 case I40E_DEV_ID_10G_BASE_T4:
4838 case I40E_DEV_ID_10G_BASE_T_X722:
4839 case I40E_DEV_ID_25G_B:
4840 case I40E_DEV_ID_25G_SFP28:
4841 status = i40e_read_phy_register_clause45(hw, page, reg,
4842 phy_addr, value);
4843 break;
4844 default:
4845 status = I40E_ERR_UNKNOWN_PHY;
4846 break;
4847 }
4848
4849 return status;
4850}
4851
4852/**
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004853 * i40e_get_phy_address
4854 * @hw: pointer to the HW structure
4855 * @dev_num: PHY port num that address we want
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004856 *
4857 * Gets PHY address for current port
4858 **/
4859u8 i40e_get_phy_address(struct i40e_hw *hw, u8 dev_num)
4860{
4861 u8 port_num = hw->func_caps.mdio_port_num;
4862 u32 reg_val = rd32(hw, I40E_GLGEN_MDIO_I2C_SEL(port_num));
4863
4864 return (u8)(reg_val >> ((dev_num + 1) * 5)) & 0x1f;
4865}
4866
4867/**
4868 * i40e_blink_phy_led
4869 * @hw: pointer to the HW structure
4870 * @time: time how long led will blinks in secs
4871 * @interval: gap between LED on and off in msecs
4872 *
4873 * Blinks PHY link LED
4874 **/
4875i40e_status i40e_blink_phy_link_led(struct i40e_hw *hw,
4876 u32 time, u32 interval)
4877{
4878 i40e_status status = 0;
4879 u32 i;
4880 u16 led_ctl;
4881 u16 gpio_led_port;
4882 u16 led_reg;
4883 u16 led_addr = I40E_PHY_LED_PROV_REG_1;
4884 u8 phy_addr = 0;
4885 u8 port_num;
4886
4887 i = rd32(hw, I40E_PFGEN_PORTNUM);
4888 port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
4889 phy_addr = i40e_get_phy_address(hw, port_num);
4890
4891 for (gpio_led_port = 0; gpio_led_port < 3; gpio_led_port++,
4892 led_addr++) {
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004893 status = i40e_read_phy_register_clause45(hw,
4894 I40E_PHY_COM_REG_PAGE,
4895 led_addr, phy_addr,
4896 &led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004897 if (status)
4898 goto phy_blinking_end;
4899 led_ctl = led_reg;
4900 if (led_reg & I40E_PHY_LED_LINK_MODE_MASK) {
4901 led_reg = 0;
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004902 status = i40e_write_phy_register_clause45(hw,
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004903 I40E_PHY_COM_REG_PAGE,
4904 led_addr, phy_addr,
4905 led_reg);
4906 if (status)
4907 goto phy_blinking_end;
4908 break;
4909 }
4910 }
4911
4912 if (time > 0 && interval > 0) {
4913 for (i = 0; i < time * 1000; i += interval) {
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004914 status = i40e_read_phy_register_clause45(hw,
4915 I40E_PHY_COM_REG_PAGE,
4916 led_addr, phy_addr, &led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004917 if (status)
4918 goto restore_config;
4919 if (led_reg & I40E_PHY_LED_MANUAL_ON)
4920 led_reg = 0;
4921 else
4922 led_reg = I40E_PHY_LED_MANUAL_ON;
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004923 status = i40e_write_phy_register_clause45(hw,
4924 I40E_PHY_COM_REG_PAGE,
4925 led_addr, phy_addr, led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004926 if (status)
4927 goto restore_config;
4928 msleep(interval);
4929 }
4930 }
4931
4932restore_config:
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07004933 status = i40e_write_phy_register_clause45(hw,
4934 I40E_PHY_COM_REG_PAGE,
4935 led_addr, phy_addr, led_ctl);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004936
4937phy_blinking_end:
4938 return status;
4939}
4940
4941/**
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04004942 * i40e_led_get_reg - read LED register
4943 * @hw: pointer to the HW structure
4944 * @led_addr: LED register address
4945 * @reg_val: read register value
4946 **/
4947static enum i40e_status_code i40e_led_get_reg(struct i40e_hw *hw, u16 led_addr,
4948 u32 *reg_val)
4949{
4950 enum i40e_status_code status;
4951 u8 phy_addr = 0;
4952 u8 port_num;
4953 u32 i;
4954
4955 *reg_val = 0;
4956 if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) {
4957 status =
4958 i40e_aq_get_phy_register(hw,
4959 I40E_AQ_PHY_REG_ACCESS_EXTERNAL,
4960 I40E_PHY_COM_REG_PAGE,
4961 I40E_PHY_LED_PROV_REG_1,
4962 reg_val, NULL);
4963 } else {
4964 i = rd32(hw, I40E_PFGEN_PORTNUM);
4965 port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
4966 phy_addr = i40e_get_phy_address(hw, port_num);
4967 status = i40e_read_phy_register_clause45(hw,
4968 I40E_PHY_COM_REG_PAGE,
4969 led_addr, phy_addr,
4970 (u16 *)reg_val);
4971 }
4972 return status;
4973}
4974
4975/**
4976 * i40e_led_set_reg - write LED register
4977 * @hw: pointer to the HW structure
4978 * @led_addr: LED register address
4979 * @reg_val: register value to write
4980 **/
4981static enum i40e_status_code i40e_led_set_reg(struct i40e_hw *hw, u16 led_addr,
4982 u32 reg_val)
4983{
4984 enum i40e_status_code status;
4985 u8 phy_addr = 0;
4986 u8 port_num;
4987 u32 i;
4988
4989 if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) {
4990 status =
4991 i40e_aq_set_phy_register(hw,
4992 I40E_AQ_PHY_REG_ACCESS_EXTERNAL,
4993 I40E_PHY_COM_REG_PAGE,
4994 I40E_PHY_LED_PROV_REG_1,
4995 reg_val, NULL);
4996 } else {
4997 i = rd32(hw, I40E_PFGEN_PORTNUM);
4998 port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
4999 phy_addr = i40e_get_phy_address(hw, port_num);
5000 status = i40e_write_phy_register_clause45(hw,
5001 I40E_PHY_COM_REG_PAGE,
5002 led_addr, phy_addr,
5003 (u16)reg_val);
5004 }
5005
5006 return status;
5007}
5008
5009/**
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005010 * i40e_led_get_phy - return current on/off mode
5011 * @hw: pointer to the hw struct
5012 * @led_addr: address of led register to use
5013 * @val: original value of register to use
5014 *
5015 **/
5016i40e_status i40e_led_get_phy(struct i40e_hw *hw, u16 *led_addr,
5017 u16 *val)
5018{
5019 i40e_status status = 0;
5020 u16 gpio_led_port;
5021 u8 phy_addr = 0;
5022 u16 reg_val;
5023 u16 temp_addr;
5024 u8 port_num;
5025 u32 i;
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005026 u32 reg_val_aq;
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005027
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005028 if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) {
5029 status =
5030 i40e_aq_get_phy_register(hw,
5031 I40E_AQ_PHY_REG_ACCESS_EXTERNAL,
5032 I40E_PHY_COM_REG_PAGE,
5033 I40E_PHY_LED_PROV_REG_1,
5034 &reg_val_aq, NULL);
5035 if (status == I40E_SUCCESS)
5036 *val = (u16)reg_val_aq;
5037 return status;
5038 }
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005039 temp_addr = I40E_PHY_LED_PROV_REG_1;
5040 i = rd32(hw, I40E_PFGEN_PORTNUM);
5041 port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
5042 phy_addr = i40e_get_phy_address(hw, port_num);
5043
5044 for (gpio_led_port = 0; gpio_led_port < 3; gpio_led_port++,
5045 temp_addr++) {
Michal Kosiarz91dc1e52016-10-25 16:08:51 -07005046 status = i40e_read_phy_register_clause45(hw,
5047 I40E_PHY_COM_REG_PAGE,
5048 temp_addr, phy_addr,
5049 &reg_val);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005050 if (status)
5051 return status;
5052 *val = reg_val;
5053 if (reg_val & I40E_PHY_LED_LINK_MODE_MASK) {
5054 *led_addr = temp_addr;
5055 break;
5056 }
5057 }
5058 return status;
5059}
5060
5061/**
5062 * i40e_led_set_phy
5063 * @hw: pointer to the HW structure
5064 * @on: true or false
Jacob Kellerf5254422018-04-20 01:41:33 -07005065 * @led_addr: address of led register to use
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005066 * @mode: original val plus bit for set or ignore
Jacob Kellerf5254422018-04-20 01:41:33 -07005067 *
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005068 * Set led's on or off when controlled by the PHY
5069 *
5070 **/
5071i40e_status i40e_led_set_phy(struct i40e_hw *hw, bool on,
5072 u16 led_addr, u32 mode)
5073{
5074 i40e_status status = 0;
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005075 u32 led_ctl = 0;
5076 u32 led_reg = 0;
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005077
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005078 status = i40e_led_get_reg(hw, led_addr, &led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005079 if (status)
5080 return status;
5081 led_ctl = led_reg;
5082 if (led_reg & I40E_PHY_LED_LINK_MODE_MASK) {
5083 led_reg = 0;
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005084 status = i40e_led_set_reg(hw, led_addr, led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005085 if (status)
5086 return status;
5087 }
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005088 status = i40e_led_get_reg(hw, led_addr, &led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005089 if (status)
5090 goto restore_config;
5091 if (on)
5092 led_reg = I40E_PHY_LED_MANUAL_ON;
5093 else
5094 led_reg = 0;
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005095
5096 status = i40e_led_set_reg(hw, led_addr, led_reg);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005097 if (status)
5098 goto restore_config;
5099 if (mode & I40E_PHY_LED_MODE_ORIG) {
5100 led_ctl = (mode & I40E_PHY_LED_MODE_MASK);
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005101 status = i40e_led_set_reg(hw, led_addr, led_ctl);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005102 }
5103 return status;
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005104
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005105restore_config:
Mariusz Stachura00f6c2f2017-08-22 06:57:45 -04005106 status = i40e_led_set_reg(hw, led_addr, led_ctl);
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08005107 return status;
5108}
Shannon Nelsonf6581372016-02-17 16:12:20 -08005109
5110/**
5111 * i40e_aq_rx_ctl_read_register - use FW to read from an Rx control register
5112 * @hw: pointer to the hw struct
5113 * @reg_addr: register address
5114 * @reg_val: ptr to register value
5115 * @cmd_details: pointer to command details structure or NULL
5116 *
5117 * Use the firmware to read the Rx control register,
5118 * especially useful if the Rx unit is under heavy pressure
5119 **/
5120i40e_status i40e_aq_rx_ctl_read_register(struct i40e_hw *hw,
5121 u32 reg_addr, u32 *reg_val,
5122 struct i40e_asq_cmd_details *cmd_details)
5123{
5124 struct i40e_aq_desc desc;
5125 struct i40e_aqc_rx_ctl_reg_read_write *cmd_resp =
5126 (struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
5127 i40e_status status;
5128
5129 if (!reg_val)
5130 return I40E_ERR_PARAM;
5131
5132 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_rx_ctl_reg_read);
5133
5134 cmd_resp->address = cpu_to_le32(reg_addr);
5135
5136 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5137
5138 if (status == 0)
5139 *reg_val = le32_to_cpu(cmd_resp->value);
5140
5141 return status;
5142}
5143
5144/**
5145 * i40e_read_rx_ctl - read from an Rx control register
5146 * @hw: pointer to the hw struct
5147 * @reg_addr: register address
5148 **/
5149u32 i40e_read_rx_ctl(struct i40e_hw *hw, u32 reg_addr)
5150{
5151 i40e_status status = 0;
5152 bool use_register;
5153 int retry = 5;
5154 u32 val = 0;
5155
Paul M Stillwell Jr60303082017-03-10 12:22:02 -08005156 use_register = (((hw->aq.api_maj_ver == 1) &&
5157 (hw->aq.api_min_ver < 5)) ||
5158 (hw->mac.type == I40E_MAC_X722));
Shannon Nelsonf6581372016-02-17 16:12:20 -08005159 if (!use_register) {
5160do_retry:
5161 status = i40e_aq_rx_ctl_read_register(hw, reg_addr, &val, NULL);
5162 if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
5163 usleep_range(1000, 2000);
5164 retry--;
5165 goto do_retry;
5166 }
5167 }
5168
5169 /* if the AQ access failed, try the old-fashioned way */
5170 if (status || use_register)
5171 val = rd32(hw, reg_addr);
5172
5173 return val;
5174}
5175
5176/**
5177 * i40e_aq_rx_ctl_write_register
5178 * @hw: pointer to the hw struct
5179 * @reg_addr: register address
5180 * @reg_val: register value
5181 * @cmd_details: pointer to command details structure or NULL
5182 *
5183 * Use the firmware to write to an Rx control register,
5184 * especially useful if the Rx unit is under heavy pressure
5185 **/
5186i40e_status i40e_aq_rx_ctl_write_register(struct i40e_hw *hw,
5187 u32 reg_addr, u32 reg_val,
5188 struct i40e_asq_cmd_details *cmd_details)
5189{
5190 struct i40e_aq_desc desc;
5191 struct i40e_aqc_rx_ctl_reg_read_write *cmd =
5192 (struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
5193 i40e_status status;
5194
5195 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_rx_ctl_reg_write);
5196
5197 cmd->address = cpu_to_le32(reg_addr);
5198 cmd->value = cpu_to_le32(reg_val);
5199
5200 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5201
5202 return status;
5203}
5204
5205/**
5206 * i40e_write_rx_ctl - write to an Rx control register
5207 * @hw: pointer to the hw struct
5208 * @reg_addr: register address
5209 * @reg_val: register value
5210 **/
5211void i40e_write_rx_ctl(struct i40e_hw *hw, u32 reg_addr, u32 reg_val)
5212{
5213 i40e_status status = 0;
5214 bool use_register;
5215 int retry = 5;
5216
Paul M Stillwell Jr60303082017-03-10 12:22:02 -08005217 use_register = (((hw->aq.api_maj_ver == 1) &&
5218 (hw->aq.api_min_ver < 5)) ||
5219 (hw->mac.type == I40E_MAC_X722));
Shannon Nelsonf6581372016-02-17 16:12:20 -08005220 if (!use_register) {
5221do_retry:
5222 status = i40e_aq_rx_ctl_write_register(hw, reg_addr,
5223 reg_val, NULL);
5224 if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
5225 usleep_range(1000, 2000);
5226 retry--;
5227 goto do_retry;
5228 }
5229 }
5230
5231 /* if the AQ access failed, try the old-fashioned way */
5232 if (status || use_register)
5233 wr32(hw, reg_addr, reg_val);
5234}
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005235
5236/**
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04005237 * i40e_aq_set_phy_register
5238 * @hw: pointer to the hw struct
5239 * @phy_select: select which phy should be accessed
5240 * @dev_addr: PHY device address
5241 * @reg_addr: PHY register address
5242 * @reg_val: new register value
5243 * @cmd_details: pointer to command details structure or NULL
5244 *
5245 * Write the external PHY register.
5246 **/
5247i40e_status i40e_aq_set_phy_register(struct i40e_hw *hw,
5248 u8 phy_select, u8 dev_addr,
5249 u32 reg_addr, u32 reg_val,
5250 struct i40e_asq_cmd_details *cmd_details)
5251{
5252 struct i40e_aq_desc desc;
5253 struct i40e_aqc_phy_register_access *cmd =
5254 (struct i40e_aqc_phy_register_access *)&desc.params.raw;
5255 i40e_status status;
5256
5257 i40e_fill_default_direct_cmd_desc(&desc,
5258 i40e_aqc_opc_set_phy_register);
5259
5260 cmd->phy_interface = phy_select;
5261 cmd->dev_address = dev_addr;
5262 cmd->reg_address = cpu_to_le32(reg_addr);
5263 cmd->reg_value = cpu_to_le32(reg_val);
5264
5265 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5266
5267 return status;
5268}
5269
5270/**
5271 * i40e_aq_get_phy_register
5272 * @hw: pointer to the hw struct
5273 * @phy_select: select which phy should be accessed
5274 * @dev_addr: PHY device address
5275 * @reg_addr: PHY register address
5276 * @reg_val: read register value
5277 * @cmd_details: pointer to command details structure or NULL
5278 *
5279 * Read the external PHY register.
5280 **/
5281i40e_status i40e_aq_get_phy_register(struct i40e_hw *hw,
5282 u8 phy_select, u8 dev_addr,
5283 u32 reg_addr, u32 *reg_val,
5284 struct i40e_asq_cmd_details *cmd_details)
5285{
5286 struct i40e_aq_desc desc;
5287 struct i40e_aqc_phy_register_access *cmd =
5288 (struct i40e_aqc_phy_register_access *)&desc.params.raw;
5289 i40e_status status;
5290
5291 i40e_fill_default_direct_cmd_desc(&desc,
5292 i40e_aqc_opc_get_phy_register);
5293
5294 cmd->phy_interface = phy_select;
5295 cmd->dev_address = dev_addr;
5296 cmd->reg_address = cpu_to_le32(reg_addr);
5297
5298 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5299 if (!status)
5300 *reg_val = le32_to_cpu(cmd->reg_value);
5301
5302 return status;
5303}
5304
5305/**
Jingjing Wu329e5982017-11-14 07:00:47 -05005306 * i40e_aq_write_ddp - Write dynamic device personalization (ddp)
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005307 * @hw: pointer to the hw struct
5308 * @buff: command buffer (size in bytes = buff_size)
5309 * @buff_size: buffer size in bytes
5310 * @track_id: package tracking id
5311 * @error_offset: returns error offset
5312 * @error_info: returns error information
5313 * @cmd_details: pointer to command details structure or NULL
5314 **/
5315enum
Jingjing Wu329e5982017-11-14 07:00:47 -05005316i40e_status_code i40e_aq_write_ddp(struct i40e_hw *hw, void *buff,
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005317 u16 buff_size, u32 track_id,
5318 u32 *error_offset, u32 *error_info,
5319 struct i40e_asq_cmd_details *cmd_details)
5320{
5321 struct i40e_aq_desc desc;
5322 struct i40e_aqc_write_personalization_profile *cmd =
5323 (struct i40e_aqc_write_personalization_profile *)
5324 &desc.params.raw;
Jingjing Wu329e5982017-11-14 07:00:47 -05005325 struct i40e_aqc_write_ddp_resp *resp;
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005326 i40e_status status;
5327
5328 i40e_fill_default_direct_cmd_desc(&desc,
5329 i40e_aqc_opc_write_personalization_profile);
5330
5331 desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
5332 if (buff_size > I40E_AQ_LARGE_BUF)
5333 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
5334
5335 desc.datalen = cpu_to_le16(buff_size);
5336
5337 cmd->profile_track_id = cpu_to_le32(track_id);
5338
5339 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
5340 if (!status) {
Jingjing Wu329e5982017-11-14 07:00:47 -05005341 resp = (struct i40e_aqc_write_ddp_resp *)&desc.params.raw;
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005342 if (error_offset)
5343 *error_offset = le32_to_cpu(resp->error_offset);
5344 if (error_info)
5345 *error_info = le32_to_cpu(resp->error_info);
5346 }
5347
5348 return status;
5349}
5350
5351/**
Jingjing Wu329e5982017-11-14 07:00:47 -05005352 * i40e_aq_get_ddp_list - Read dynamic device personalization (ddp)
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005353 * @hw: pointer to the hw struct
5354 * @buff: command buffer (size in bytes = buff_size)
5355 * @buff_size: buffer size in bytes
Jacob Kellerf5254422018-04-20 01:41:33 -07005356 * @flags: AdminQ command flags
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005357 * @cmd_details: pointer to command details structure or NULL
5358 **/
5359enum
Jingjing Wu329e5982017-11-14 07:00:47 -05005360i40e_status_code i40e_aq_get_ddp_list(struct i40e_hw *hw, void *buff,
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005361 u16 buff_size, u8 flags,
5362 struct i40e_asq_cmd_details *cmd_details)
5363{
5364 struct i40e_aq_desc desc;
5365 struct i40e_aqc_get_applied_profiles *cmd =
5366 (struct i40e_aqc_get_applied_profiles *)&desc.params.raw;
5367 i40e_status status;
5368
5369 i40e_fill_default_direct_cmd_desc(&desc,
5370 i40e_aqc_opc_get_personalization_profile_list);
5371
5372 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
5373 if (buff_size > I40E_AQ_LARGE_BUF)
5374 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
5375 desc.datalen = cpu_to_le16(buff_size);
5376
5377 cmd->flags = flags;
5378
5379 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
5380
5381 return status;
5382}
5383
5384/**
5385 * i40e_find_segment_in_package
5386 * @segment_type: the segment type to search for (i.e., SEGMENT_TYPE_I40E)
5387 * @pkg_hdr: pointer to the package header to be searched
5388 *
5389 * This function searches a package file for a particular segment type. On
5390 * success it returns a pointer to the segment header, otherwise it will
5391 * return NULL.
5392 **/
5393struct i40e_generic_seg_header *
5394i40e_find_segment_in_package(u32 segment_type,
5395 struct i40e_package_header *pkg_hdr)
5396{
5397 struct i40e_generic_seg_header *segment;
5398 u32 i;
5399
5400 /* Search all package segments for the requested segment type */
5401 for (i = 0; i < pkg_hdr->segment_count; i++) {
5402 segment =
5403 (struct i40e_generic_seg_header *)((u8 *)pkg_hdr +
5404 pkg_hdr->segment_offset[i]);
5405
5406 if (segment->type == segment_type)
5407 return segment;
5408 }
5409
5410 return NULL;
5411}
5412
5413/**
5414 * i40e_write_profile
5415 * @hw: pointer to the hardware structure
5416 * @profile: pointer to the profile segment of the package to be downloaded
5417 * @track_id: package tracking id
5418 *
5419 * Handles the download of a complete package.
5420 */
5421enum i40e_status_code
5422i40e_write_profile(struct i40e_hw *hw, struct i40e_profile_segment *profile,
5423 u32 track_id)
5424{
5425 i40e_status status = 0;
5426 struct i40e_section_table *sec_tbl;
5427 struct i40e_profile_section_header *sec = NULL;
5428 u32 dev_cnt;
5429 u32 vendor_dev_id;
5430 u32 *nvm;
5431 u32 section_size = 0;
5432 u32 offset = 0, info = 0;
5433 u32 i;
5434
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005435 dev_cnt = profile->device_table_count;
5436
5437 for (i = 0; i < dev_cnt; i++) {
5438 vendor_dev_id = profile->device_table[i].vendor_dev_id;
5439 if ((vendor_dev_id >> 16) == PCI_VENDOR_ID_INTEL)
5440 if (hw->device_id == (vendor_dev_id & 0xFFFF))
5441 break;
5442 }
5443 if (i == dev_cnt) {
Jingjing Wu329e5982017-11-14 07:00:47 -05005444 i40e_debug(hw, I40E_DEBUG_PACKAGE, "Device doesn't support DDP");
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005445 return I40E_ERR_DEVICE_NOT_SUPPORTED;
5446 }
5447
5448 nvm = (u32 *)&profile->device_table[dev_cnt];
5449 sec_tbl = (struct i40e_section_table *)&nvm[nvm[0] + 1];
5450
5451 for (i = 0; i < sec_tbl->section_count; i++) {
5452 sec = (struct i40e_profile_section_header *)((u8 *)profile +
5453 sec_tbl->section_offset[i]);
5454
5455 /* Skip 'AQ', 'note' and 'name' sections */
5456 if (sec->section.type != SECTION_TYPE_MMIO)
5457 continue;
5458
5459 section_size = sec->section.size +
5460 sizeof(struct i40e_profile_section_header);
5461
5462 /* Write profile */
Jingjing Wu329e5982017-11-14 07:00:47 -05005463 status = i40e_aq_write_ddp(hw, (void *)sec, (u16)section_size,
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005464 track_id, &offset, &info, NULL);
5465 if (status) {
5466 i40e_debug(hw, I40E_DEBUG_PACKAGE,
5467 "Failed to write profile: offset %d, info %d",
5468 offset, info);
5469 break;
5470 }
5471 }
5472 return status;
5473}
5474
5475/**
5476 * i40e_add_pinfo_to_list
5477 * @hw: pointer to the hardware structure
5478 * @profile: pointer to the profile segment of the package
5479 * @profile_info_sec: buffer for information section
5480 * @track_id: package tracking id
5481 *
5482 * Register a profile to the list of loaded profiles.
5483 */
5484enum i40e_status_code
5485i40e_add_pinfo_to_list(struct i40e_hw *hw,
5486 struct i40e_profile_segment *profile,
5487 u8 *profile_info_sec, u32 track_id)
5488{
5489 i40e_status status = 0;
5490 struct i40e_profile_section_header *sec = NULL;
5491 struct i40e_profile_info *pinfo;
5492 u32 offset = 0, info = 0;
5493
5494 sec = (struct i40e_profile_section_header *)profile_info_sec;
5495 sec->tbl_size = 1;
5496 sec->data_end = sizeof(struct i40e_profile_section_header) +
5497 sizeof(struct i40e_profile_info);
5498 sec->section.type = SECTION_TYPE_INFO;
5499 sec->section.offset = sizeof(struct i40e_profile_section_header);
5500 sec->section.size = sizeof(struct i40e_profile_info);
5501 pinfo = (struct i40e_profile_info *)(profile_info_sec +
5502 sec->section.offset);
5503 pinfo->track_id = track_id;
5504 pinfo->version = profile->version;
Jingjing Wu329e5982017-11-14 07:00:47 -05005505 pinfo->op = I40E_DDP_ADD_TRACKID;
5506 memcpy(pinfo->name, profile->name, I40E_DDP_NAME_SIZE);
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005507
Jingjing Wu329e5982017-11-14 07:00:47 -05005508 status = i40e_aq_write_ddp(hw, (void *)sec, sec->data_end,
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005509 track_id, &offset, &info, NULL);
Amritha Nambiar2f4b4112017-10-27 02:36:01 -07005510
5511 return status;
5512}
5513
5514/**
5515 * i40e_aq_add_cloud_filters
5516 * @hw: pointer to the hardware structure
5517 * @seid: VSI seid to add cloud filters from
5518 * @filters: Buffer which contains the filters to be added
5519 * @filter_count: number of filters contained in the buffer
5520 *
5521 * Set the cloud filters for a given VSI. The contents of the
5522 * i40e_aqc_cloud_filters_element_data are filled in by the caller
5523 * of the function.
5524 *
5525 **/
5526enum i40e_status_code
5527i40e_aq_add_cloud_filters(struct i40e_hw *hw, u16 seid,
5528 struct i40e_aqc_cloud_filters_element_data *filters,
5529 u8 filter_count)
5530{
5531 struct i40e_aq_desc desc;
5532 struct i40e_aqc_add_remove_cloud_filters *cmd =
5533 (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
5534 enum i40e_status_code status;
5535 u16 buff_len;
5536
5537 i40e_fill_default_direct_cmd_desc(&desc,
5538 i40e_aqc_opc_add_cloud_filters);
5539
5540 buff_len = filter_count * sizeof(*filters);
5541 desc.datalen = cpu_to_le16(buff_len);
5542 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
5543 cmd->num_filters = filter_count;
5544 cmd->seid = cpu_to_le16(seid);
5545
5546 status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
5547
5548 return status;
5549}
5550
5551/**
5552 * i40e_aq_add_cloud_filters_bb
5553 * @hw: pointer to the hardware structure
5554 * @seid: VSI seid to add cloud filters from
5555 * @filters: Buffer which contains the filters in big buffer to be added
5556 * @filter_count: number of filters contained in the buffer
5557 *
5558 * Set the big buffer cloud filters for a given VSI. The contents of the
5559 * i40e_aqc_cloud_filters_element_bb are filled in by the caller of the
5560 * function.
5561 *
5562 **/
Doug Dziggel85925cd2018-03-19 09:28:04 -07005563enum i40e_status_code
Amritha Nambiar2f4b4112017-10-27 02:36:01 -07005564i40e_aq_add_cloud_filters_bb(struct i40e_hw *hw, u16 seid,
5565 struct i40e_aqc_cloud_filters_element_bb *filters,
5566 u8 filter_count)
5567{
5568 struct i40e_aq_desc desc;
5569 struct i40e_aqc_add_remove_cloud_filters *cmd =
5570 (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
5571 i40e_status status;
5572 u16 buff_len;
5573 int i;
5574
5575 i40e_fill_default_direct_cmd_desc(&desc,
5576 i40e_aqc_opc_add_cloud_filters);
5577
5578 buff_len = filter_count * sizeof(*filters);
5579 desc.datalen = cpu_to_le16(buff_len);
5580 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
5581 cmd->num_filters = filter_count;
5582 cmd->seid = cpu_to_le16(seid);
5583 cmd->big_buffer_flag = I40E_AQC_ADD_CLOUD_CMD_BB;
5584
5585 for (i = 0; i < filter_count; i++) {
5586 u16 tnl_type;
5587 u32 ti;
5588
5589 tnl_type = (le16_to_cpu(filters[i].element.flags) &
5590 I40E_AQC_ADD_CLOUD_TNL_TYPE_MASK) >>
5591 I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT;
5592
5593 /* Due to hardware eccentricities, the VNI for Geneve is shifted
5594 * one more byte further than normally used for Tenant ID in
5595 * other tunnel types.
5596 */
5597 if (tnl_type == I40E_AQC_ADD_CLOUD_TNL_TYPE_GENEVE) {
5598 ti = le32_to_cpu(filters[i].element.tenant_id);
5599 filters[i].element.tenant_id = cpu_to_le32(ti << 8);
5600 }
5601 }
5602
5603 status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
5604
5605 return status;
5606}
5607
5608/**
5609 * i40e_aq_rem_cloud_filters
5610 * @hw: pointer to the hardware structure
5611 * @seid: VSI seid to remove cloud filters from
5612 * @filters: Buffer which contains the filters to be removed
5613 * @filter_count: number of filters contained in the buffer
5614 *
5615 * Remove the cloud filters for a given VSI. The contents of the
5616 * i40e_aqc_cloud_filters_element_data are filled in by the caller
5617 * of the function.
5618 *
5619 **/
5620enum i40e_status_code
5621i40e_aq_rem_cloud_filters(struct i40e_hw *hw, u16 seid,
5622 struct i40e_aqc_cloud_filters_element_data *filters,
5623 u8 filter_count)
5624{
5625 struct i40e_aq_desc desc;
5626 struct i40e_aqc_add_remove_cloud_filters *cmd =
5627 (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
5628 enum i40e_status_code status;
5629 u16 buff_len;
5630
5631 i40e_fill_default_direct_cmd_desc(&desc,
5632 i40e_aqc_opc_remove_cloud_filters);
5633
5634 buff_len = filter_count * sizeof(*filters);
5635 desc.datalen = cpu_to_le16(buff_len);
5636 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
5637 cmd->num_filters = filter_count;
5638 cmd->seid = cpu_to_le16(seid);
5639
5640 status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
5641
5642 return status;
5643}
5644
5645/**
5646 * i40e_aq_rem_cloud_filters_bb
5647 * @hw: pointer to the hardware structure
5648 * @seid: VSI seid to remove cloud filters from
5649 * @filters: Buffer which contains the filters in big buffer to be removed
5650 * @filter_count: number of filters contained in the buffer
5651 *
5652 * Remove the big buffer cloud filters for a given VSI. The contents of the
5653 * i40e_aqc_cloud_filters_element_bb are filled in by the caller of the
5654 * function.
5655 *
5656 **/
Doug Dziggel85925cd2018-03-19 09:28:04 -07005657enum i40e_status_code
Amritha Nambiar2f4b4112017-10-27 02:36:01 -07005658i40e_aq_rem_cloud_filters_bb(struct i40e_hw *hw, u16 seid,
5659 struct i40e_aqc_cloud_filters_element_bb *filters,
5660 u8 filter_count)
5661{
5662 struct i40e_aq_desc desc;
5663 struct i40e_aqc_add_remove_cloud_filters *cmd =
5664 (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
5665 i40e_status status;
5666 u16 buff_len;
5667 int i;
5668
5669 i40e_fill_default_direct_cmd_desc(&desc,
5670 i40e_aqc_opc_remove_cloud_filters);
5671
5672 buff_len = filter_count * sizeof(*filters);
5673 desc.datalen = cpu_to_le16(buff_len);
5674 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
5675 cmd->num_filters = filter_count;
5676 cmd->seid = cpu_to_le16(seid);
5677 cmd->big_buffer_flag = I40E_AQC_ADD_CLOUD_CMD_BB;
5678
5679 for (i = 0; i < filter_count; i++) {
5680 u16 tnl_type;
5681 u32 ti;
5682
5683 tnl_type = (le16_to_cpu(filters[i].element.flags) &
5684 I40E_AQC_ADD_CLOUD_TNL_TYPE_MASK) >>
5685 I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT;
5686
5687 /* Due to hardware eccentricities, the VNI for Geneve is shifted
5688 * one more byte further than normally used for Tenant ID in
5689 * other tunnel types.
5690 */
5691 if (tnl_type == I40E_AQC_ADD_CLOUD_TNL_TYPE_GENEVE) {
5692 ti = le32_to_cpu(filters[i].element.tenant_id);
5693 filters[i].element.tenant_id = cpu_to_le32(ti << 8);
5694 }
5695 }
5696
5697 status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
5698
Jingjing Wu1d5c9602017-04-13 04:45:45 -04005699 return status;
5700}