blob: bb63df854ab490e6eba4a77de7710773c6658dd6 [file] [log] [blame]
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Shannon Nelson67be6eb2016-01-13 16:51:40 -08004 * Copyright(c) 2013 - 2016 Intel Corporation.
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
Greg Rosedc641b72013-12-18 13:45:51 +000015 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +000017 *
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
27#include "i40e_type.h"
28#include "i40e_adminq.h"
29#include "i40e_prototype.h"
30#include "i40e_virtchnl.h"
31
32/**
33 * i40e_set_mac_type - Sets MAC type
34 * @hw: pointer to the HW structure
35 *
36 * This function sets the mac type of the adapter based on the
37 * vendor ID and device ID stored in the hw structure.
38 **/
39static i40e_status i40e_set_mac_type(struct i40e_hw *hw)
40{
41 i40e_status status = 0;
42
43 if (hw->vendor_id == PCI_VENDOR_ID_INTEL) {
44 switch (hw->device_id) {
Shannon Nelsonab600852014-01-17 15:36:39 -080045 case I40E_DEV_ID_SFP_XL710:
Shannon Nelsonab600852014-01-17 15:36:39 -080046 case I40E_DEV_ID_QEMU:
Shannon Nelsonab600852014-01-17 15:36:39 -080047 case I40E_DEV_ID_KX_B:
48 case I40E_DEV_ID_KX_C:
Shannon Nelsonab600852014-01-17 15:36:39 -080049 case I40E_DEV_ID_QSFP_A:
50 case I40E_DEV_ID_QSFP_B:
51 case I40E_DEV_ID_QSFP_C:
Mitch Williams5960d332014-09-13 07:40:47 +000052 case I40E_DEV_ID_10G_BASE_T:
Shannon Nelsonbc5166b92015-08-26 15:14:10 -040053 case I40E_DEV_ID_10G_BASE_T4:
Jesse Brandeburgae24b402015-03-27 00:12:09 -070054 case I40E_DEV_ID_20G_KR2:
Shannon Nelson48a3b512015-07-23 16:54:39 -040055 case I40E_DEV_ID_20G_KR2_A:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +000056 hw->mac.type = I40E_MAC_XL710;
57 break;
Anjali Singhai Jain35dae512015-12-22 14:25:03 -080058 case I40E_DEV_ID_KX_X722:
59 case I40E_DEV_ID_QSFP_X722:
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -040060 case I40E_DEV_ID_SFP_X722:
61 case I40E_DEV_ID_1G_BASE_T_X722:
62 case I40E_DEV_ID_10G_BASE_T_X722:
Catherine Sullivand6bf58c2016-03-18 12:18:08 -070063 case I40E_DEV_ID_SFP_I_X722:
Kamil Krawczykbccf4742016-04-12 08:30:47 -070064 case I40E_DEV_ID_QSFP_I_X722:
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -040065 hw->mac.type = I40E_MAC_X722;
66 break;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +000067 default:
68 hw->mac.type = I40E_MAC_GENERIC;
69 break;
70 }
71 } else {
72 status = I40E_ERR_DEVICE_NOT_SUPPORTED;
73 }
74
75 hw_dbg(hw, "i40e_set_mac_type found mac: %d, returns: %d\n",
76 hw->mac.type, status);
77 return status;
78}
79
80/**
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040081 * i40e_aq_str - convert AQ err code to a string
82 * @hw: pointer to the HW structure
83 * @aq_err: the AQ error code to convert
84 **/
Jingjing Wu4e68adfe2015-09-28 14:12:31 -040085const char *i40e_aq_str(struct i40e_hw *hw, enum i40e_admin_queue_err aq_err)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040086{
87 switch (aq_err) {
88 case I40E_AQ_RC_OK:
89 return "OK";
90 case I40E_AQ_RC_EPERM:
91 return "I40E_AQ_RC_EPERM";
92 case I40E_AQ_RC_ENOENT:
93 return "I40E_AQ_RC_ENOENT";
94 case I40E_AQ_RC_ESRCH:
95 return "I40E_AQ_RC_ESRCH";
96 case I40E_AQ_RC_EINTR:
97 return "I40E_AQ_RC_EINTR";
98 case I40E_AQ_RC_EIO:
99 return "I40E_AQ_RC_EIO";
100 case I40E_AQ_RC_ENXIO:
101 return "I40E_AQ_RC_ENXIO";
102 case I40E_AQ_RC_E2BIG:
103 return "I40E_AQ_RC_E2BIG";
104 case I40E_AQ_RC_EAGAIN:
105 return "I40E_AQ_RC_EAGAIN";
106 case I40E_AQ_RC_ENOMEM:
107 return "I40E_AQ_RC_ENOMEM";
108 case I40E_AQ_RC_EACCES:
109 return "I40E_AQ_RC_EACCES";
110 case I40E_AQ_RC_EFAULT:
111 return "I40E_AQ_RC_EFAULT";
112 case I40E_AQ_RC_EBUSY:
113 return "I40E_AQ_RC_EBUSY";
114 case I40E_AQ_RC_EEXIST:
115 return "I40E_AQ_RC_EEXIST";
116 case I40E_AQ_RC_EINVAL:
117 return "I40E_AQ_RC_EINVAL";
118 case I40E_AQ_RC_ENOTTY:
119 return "I40E_AQ_RC_ENOTTY";
120 case I40E_AQ_RC_ENOSPC:
121 return "I40E_AQ_RC_ENOSPC";
122 case I40E_AQ_RC_ENOSYS:
123 return "I40E_AQ_RC_ENOSYS";
124 case I40E_AQ_RC_ERANGE:
125 return "I40E_AQ_RC_ERANGE";
126 case I40E_AQ_RC_EFLUSHED:
127 return "I40E_AQ_RC_EFLUSHED";
128 case I40E_AQ_RC_BAD_ADDR:
129 return "I40E_AQ_RC_BAD_ADDR";
130 case I40E_AQ_RC_EMODE:
131 return "I40E_AQ_RC_EMODE";
132 case I40E_AQ_RC_EFBIG:
133 return "I40E_AQ_RC_EFBIG";
134 }
135
136 snprintf(hw->err_str, sizeof(hw->err_str), "%d", aq_err);
137 return hw->err_str;
138}
139
140/**
141 * i40e_stat_str - convert status err code to a string
142 * @hw: pointer to the HW structure
143 * @stat_err: the status error code to convert
144 **/
Jingjing Wu4e68adfe2015-09-28 14:12:31 -0400145const char *i40e_stat_str(struct i40e_hw *hw, i40e_status stat_err)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400146{
147 switch (stat_err) {
148 case 0:
149 return "OK";
150 case I40E_ERR_NVM:
151 return "I40E_ERR_NVM";
152 case I40E_ERR_NVM_CHECKSUM:
153 return "I40E_ERR_NVM_CHECKSUM";
154 case I40E_ERR_PHY:
155 return "I40E_ERR_PHY";
156 case I40E_ERR_CONFIG:
157 return "I40E_ERR_CONFIG";
158 case I40E_ERR_PARAM:
159 return "I40E_ERR_PARAM";
160 case I40E_ERR_MAC_TYPE:
161 return "I40E_ERR_MAC_TYPE";
162 case I40E_ERR_UNKNOWN_PHY:
163 return "I40E_ERR_UNKNOWN_PHY";
164 case I40E_ERR_LINK_SETUP:
165 return "I40E_ERR_LINK_SETUP";
166 case I40E_ERR_ADAPTER_STOPPED:
167 return "I40E_ERR_ADAPTER_STOPPED";
168 case I40E_ERR_INVALID_MAC_ADDR:
169 return "I40E_ERR_INVALID_MAC_ADDR";
170 case I40E_ERR_DEVICE_NOT_SUPPORTED:
171 return "I40E_ERR_DEVICE_NOT_SUPPORTED";
172 case I40E_ERR_MASTER_REQUESTS_PENDING:
173 return "I40E_ERR_MASTER_REQUESTS_PENDING";
174 case I40E_ERR_INVALID_LINK_SETTINGS:
175 return "I40E_ERR_INVALID_LINK_SETTINGS";
176 case I40E_ERR_AUTONEG_NOT_COMPLETE:
177 return "I40E_ERR_AUTONEG_NOT_COMPLETE";
178 case I40E_ERR_RESET_FAILED:
179 return "I40E_ERR_RESET_FAILED";
180 case I40E_ERR_SWFW_SYNC:
181 return "I40E_ERR_SWFW_SYNC";
182 case I40E_ERR_NO_AVAILABLE_VSI:
183 return "I40E_ERR_NO_AVAILABLE_VSI";
184 case I40E_ERR_NO_MEMORY:
185 return "I40E_ERR_NO_MEMORY";
186 case I40E_ERR_BAD_PTR:
187 return "I40E_ERR_BAD_PTR";
188 case I40E_ERR_RING_FULL:
189 return "I40E_ERR_RING_FULL";
190 case I40E_ERR_INVALID_PD_ID:
191 return "I40E_ERR_INVALID_PD_ID";
192 case I40E_ERR_INVALID_QP_ID:
193 return "I40E_ERR_INVALID_QP_ID";
194 case I40E_ERR_INVALID_CQ_ID:
195 return "I40E_ERR_INVALID_CQ_ID";
196 case I40E_ERR_INVALID_CEQ_ID:
197 return "I40E_ERR_INVALID_CEQ_ID";
198 case I40E_ERR_INVALID_AEQ_ID:
199 return "I40E_ERR_INVALID_AEQ_ID";
200 case I40E_ERR_INVALID_SIZE:
201 return "I40E_ERR_INVALID_SIZE";
202 case I40E_ERR_INVALID_ARP_INDEX:
203 return "I40E_ERR_INVALID_ARP_INDEX";
204 case I40E_ERR_INVALID_FPM_FUNC_ID:
205 return "I40E_ERR_INVALID_FPM_FUNC_ID";
206 case I40E_ERR_QP_INVALID_MSG_SIZE:
207 return "I40E_ERR_QP_INVALID_MSG_SIZE";
208 case I40E_ERR_QP_TOOMANY_WRS_POSTED:
209 return "I40E_ERR_QP_TOOMANY_WRS_POSTED";
210 case I40E_ERR_INVALID_FRAG_COUNT:
211 return "I40E_ERR_INVALID_FRAG_COUNT";
212 case I40E_ERR_QUEUE_EMPTY:
213 return "I40E_ERR_QUEUE_EMPTY";
214 case I40E_ERR_INVALID_ALIGNMENT:
215 return "I40E_ERR_INVALID_ALIGNMENT";
216 case I40E_ERR_FLUSHED_QUEUE:
217 return "I40E_ERR_FLUSHED_QUEUE";
218 case I40E_ERR_INVALID_PUSH_PAGE_INDEX:
219 return "I40E_ERR_INVALID_PUSH_PAGE_INDEX";
220 case I40E_ERR_INVALID_IMM_DATA_SIZE:
221 return "I40E_ERR_INVALID_IMM_DATA_SIZE";
222 case I40E_ERR_TIMEOUT:
223 return "I40E_ERR_TIMEOUT";
224 case I40E_ERR_OPCODE_MISMATCH:
225 return "I40E_ERR_OPCODE_MISMATCH";
226 case I40E_ERR_CQP_COMPL_ERROR:
227 return "I40E_ERR_CQP_COMPL_ERROR";
228 case I40E_ERR_INVALID_VF_ID:
229 return "I40E_ERR_INVALID_VF_ID";
230 case I40E_ERR_INVALID_HMCFN_ID:
231 return "I40E_ERR_INVALID_HMCFN_ID";
232 case I40E_ERR_BACKING_PAGE_ERROR:
233 return "I40E_ERR_BACKING_PAGE_ERROR";
234 case I40E_ERR_NO_PBLCHUNKS_AVAILABLE:
235 return "I40E_ERR_NO_PBLCHUNKS_AVAILABLE";
236 case I40E_ERR_INVALID_PBLE_INDEX:
237 return "I40E_ERR_INVALID_PBLE_INDEX";
238 case I40E_ERR_INVALID_SD_INDEX:
239 return "I40E_ERR_INVALID_SD_INDEX";
240 case I40E_ERR_INVALID_PAGE_DESC_INDEX:
241 return "I40E_ERR_INVALID_PAGE_DESC_INDEX";
242 case I40E_ERR_INVALID_SD_TYPE:
243 return "I40E_ERR_INVALID_SD_TYPE";
244 case I40E_ERR_MEMCPY_FAILED:
245 return "I40E_ERR_MEMCPY_FAILED";
246 case I40E_ERR_INVALID_HMC_OBJ_INDEX:
247 return "I40E_ERR_INVALID_HMC_OBJ_INDEX";
248 case I40E_ERR_INVALID_HMC_OBJ_COUNT:
249 return "I40E_ERR_INVALID_HMC_OBJ_COUNT";
250 case I40E_ERR_INVALID_SRQ_ARM_LIMIT:
251 return "I40E_ERR_INVALID_SRQ_ARM_LIMIT";
252 case I40E_ERR_SRQ_ENABLED:
253 return "I40E_ERR_SRQ_ENABLED";
254 case I40E_ERR_ADMIN_QUEUE_ERROR:
255 return "I40E_ERR_ADMIN_QUEUE_ERROR";
256 case I40E_ERR_ADMIN_QUEUE_TIMEOUT:
257 return "I40E_ERR_ADMIN_QUEUE_TIMEOUT";
258 case I40E_ERR_BUF_TOO_SHORT:
259 return "I40E_ERR_BUF_TOO_SHORT";
260 case I40E_ERR_ADMIN_QUEUE_FULL:
261 return "I40E_ERR_ADMIN_QUEUE_FULL";
262 case I40E_ERR_ADMIN_QUEUE_NO_WORK:
263 return "I40E_ERR_ADMIN_QUEUE_NO_WORK";
264 case I40E_ERR_BAD_IWARP_CQE:
265 return "I40E_ERR_BAD_IWARP_CQE";
266 case I40E_ERR_NVM_BLANK_MODE:
267 return "I40E_ERR_NVM_BLANK_MODE";
268 case I40E_ERR_NOT_IMPLEMENTED:
269 return "I40E_ERR_NOT_IMPLEMENTED";
270 case I40E_ERR_PE_DOORBELL_NOT_ENABLED:
271 return "I40E_ERR_PE_DOORBELL_NOT_ENABLED";
272 case I40E_ERR_DIAG_TEST_FAILED:
273 return "I40E_ERR_DIAG_TEST_FAILED";
274 case I40E_ERR_NOT_READY:
275 return "I40E_ERR_NOT_READY";
276 case I40E_NOT_SUPPORTED:
277 return "I40E_NOT_SUPPORTED";
278 case I40E_ERR_FIRMWARE_API_VERSION:
279 return "I40E_ERR_FIRMWARE_API_VERSION";
280 }
281
282 snprintf(hw->err_str, sizeof(hw->err_str), "%d", stat_err);
283 return hw->err_str;
284}
285
286/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000287 * i40e_debug_aq
288 * @hw: debug mask related to admin queue
Jeff Kirsher98d44382013-12-21 05:44:42 +0000289 * @mask: debug mask
290 * @desc: pointer to admin queue descriptor
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000291 * @buffer: pointer to command buffer
Shannon Nelsonf905dd62014-07-10 07:58:20 +0000292 * @buf_len: max length of buffer
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000293 *
294 * Dumps debug log about adminq command with descriptor contents.
295 **/
296void i40e_debug_aq(struct i40e_hw *hw, enum i40e_debug_mask mask, void *desc,
Shannon Nelsonf905dd62014-07-10 07:58:20 +0000297 void *buffer, u16 buf_len)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000298{
299 struct i40e_aq_desc *aq_desc = (struct i40e_aq_desc *)desc;
Heinrich Schuchardtcd956722016-05-17 22:41:33 +0200300 u16 len;
Shannon Nelson37a29732015-02-27 09:15:19 +0000301 u8 *buf = (u8 *)buffer;
302 u16 i = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000303
304 if ((!(mask & hw->debug_mask)) || (desc == NULL))
305 return;
306
Heinrich Schuchardtcd956722016-05-17 22:41:33 +0200307 len = le16_to_cpu(aq_desc->datalen);
308
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000309 i40e_debug(hw, mask,
310 "AQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000311 le16_to_cpu(aq_desc->opcode),
312 le16_to_cpu(aq_desc->flags),
313 le16_to_cpu(aq_desc->datalen),
314 le16_to_cpu(aq_desc->retval));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000315 i40e_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000316 le32_to_cpu(aq_desc->cookie_high),
317 le32_to_cpu(aq_desc->cookie_low));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000318 i40e_debug(hw, mask, "\tparam (0,1) 0x%08X 0x%08X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000319 le32_to_cpu(aq_desc->params.internal.param0),
320 le32_to_cpu(aq_desc->params.internal.param1));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000321 i40e_debug(hw, mask, "\taddr (h,l) 0x%08X 0x%08X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000322 le32_to_cpu(aq_desc->params.external.addr_high),
323 le32_to_cpu(aq_desc->params.external.addr_low));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000324
325 if ((buffer != NULL) && (aq_desc->datalen != 0)) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000326 i40e_debug(hw, mask, "AQ CMD Buffer:\n");
Shannon Nelsonf905dd62014-07-10 07:58:20 +0000327 if (buf_len < len)
328 len = buf_len;
Shannon Nelson37a29732015-02-27 09:15:19 +0000329 /* write the full 16-byte chunks */
330 for (i = 0; i < (len - 16); i += 16)
Andy Shevchenkoa3524e92015-10-02 12:18:16 +0300331 i40e_debug(hw, mask, "\t0x%04X %16ph\n", i, buf + i);
Shannon Nelson37a29732015-02-27 09:15:19 +0000332 /* write whatever's left over without overrunning the buffer */
Andy Shevchenkoa3524e92015-10-02 12:18:16 +0300333 if (i < len)
334 i40e_debug(hw, mask, "\t0x%04X %*ph\n",
335 i, len - i, buf + i);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000336 }
337}
338
339/**
Anjali Singhai Jaine1860d82013-11-28 06:39:45 +0000340 * i40e_check_asq_alive
341 * @hw: pointer to the hw struct
342 *
343 * Returns true if Queue is enabled else false.
344 **/
345bool i40e_check_asq_alive(struct i40e_hw *hw)
346{
Kevin Scott8b833b42014-04-09 05:58:54 +0000347 if (hw->aq.asq.len)
348 return !!(rd32(hw, hw->aq.asq.len) &
349 I40E_PF_ATQLEN_ATQENABLE_MASK);
350 else
351 return false;
Anjali Singhai Jaine1860d82013-11-28 06:39:45 +0000352}
353
354/**
355 * i40e_aq_queue_shutdown
356 * @hw: pointer to the hw struct
357 * @unloading: is the driver unloading itself
358 *
359 * Tell the Firmware that we're shutting down the AdminQ and whether
360 * or not the driver is unloading as well.
361 **/
362i40e_status i40e_aq_queue_shutdown(struct i40e_hw *hw,
363 bool unloading)
364{
365 struct i40e_aq_desc desc;
366 struct i40e_aqc_queue_shutdown *cmd =
367 (struct i40e_aqc_queue_shutdown *)&desc.params.raw;
368 i40e_status status;
369
370 i40e_fill_default_direct_cmd_desc(&desc,
371 i40e_aqc_opc_queue_shutdown);
372
373 if (unloading)
374 cmd->driver_unloading = cpu_to_le32(I40E_AQ_DRIVER_UNLOADING);
375 status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
376
377 return status;
378}
379
Anjali Singhai Jaine50c8d62015-06-05 12:20:27 -0400380/**
381 * i40e_aq_get_set_rss_lut
382 * @hw: pointer to the hardware structure
383 * @vsi_id: vsi fw index
384 * @pf_lut: for PF table set true, for VSI table set false
385 * @lut: pointer to the lut buffer provided by the caller
386 * @lut_size: size of the lut buffer
387 * @set: set true to set the table, false to get the table
388 *
389 * Internal function to get or set RSS look up table
390 **/
391static i40e_status i40e_aq_get_set_rss_lut(struct i40e_hw *hw,
392 u16 vsi_id, bool pf_lut,
393 u8 *lut, u16 lut_size,
394 bool set)
395{
396 i40e_status status;
397 struct i40e_aq_desc desc;
398 struct i40e_aqc_get_set_rss_lut *cmd_resp =
399 (struct i40e_aqc_get_set_rss_lut *)&desc.params.raw;
400
401 if (set)
402 i40e_fill_default_direct_cmd_desc(&desc,
403 i40e_aqc_opc_set_rss_lut);
404 else
405 i40e_fill_default_direct_cmd_desc(&desc,
406 i40e_aqc_opc_get_rss_lut);
407
408 /* Indirect command */
409 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
410 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
411
412 cmd_resp->vsi_id =
413 cpu_to_le16((u16)((vsi_id <<
414 I40E_AQC_SET_RSS_LUT_VSI_ID_SHIFT) &
415 I40E_AQC_SET_RSS_LUT_VSI_ID_MASK));
416 cmd_resp->vsi_id |= cpu_to_le16((u16)I40E_AQC_SET_RSS_LUT_VSI_VALID);
417
418 if (pf_lut)
419 cmd_resp->flags |= cpu_to_le16((u16)
420 ((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_PF <<
421 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
422 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
423 else
424 cmd_resp->flags |= cpu_to_le16((u16)
425 ((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_VSI <<
426 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
427 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
428
Anjali Singhai Jaine50c8d62015-06-05 12:20:27 -0400429 status = i40e_asq_send_command(hw, &desc, lut, lut_size, NULL);
430
431 return status;
432}
433
434/**
435 * i40e_aq_get_rss_lut
436 * @hw: pointer to the hardware structure
437 * @vsi_id: vsi fw index
438 * @pf_lut: for PF table set true, for VSI table set false
439 * @lut: pointer to the lut buffer provided by the caller
440 * @lut_size: size of the lut buffer
441 *
442 * get the RSS lookup table, PF or VSI type
443 **/
444i40e_status i40e_aq_get_rss_lut(struct i40e_hw *hw, u16 vsi_id,
445 bool pf_lut, u8 *lut, u16 lut_size)
446{
447 return i40e_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size,
448 false);
449}
450
451/**
452 * i40e_aq_set_rss_lut
453 * @hw: pointer to the hardware structure
454 * @vsi_id: vsi fw index
455 * @pf_lut: for PF table set true, for VSI table set false
456 * @lut: pointer to the lut buffer provided by the caller
457 * @lut_size: size of the lut buffer
458 *
459 * set the RSS lookup table, PF or VSI type
460 **/
461i40e_status i40e_aq_set_rss_lut(struct i40e_hw *hw, u16 vsi_id,
462 bool pf_lut, u8 *lut, u16 lut_size)
463{
464 return i40e_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size, true);
465}
466
467/**
468 * i40e_aq_get_set_rss_key
469 * @hw: pointer to the hw struct
470 * @vsi_id: vsi fw index
471 * @key: pointer to key info struct
472 * @set: set true to set the key, false to get the key
473 *
474 * get the RSS key per VSI
475 **/
476static i40e_status i40e_aq_get_set_rss_key(struct i40e_hw *hw,
477 u16 vsi_id,
478 struct i40e_aqc_get_set_rss_key_data *key,
479 bool set)
480{
481 i40e_status status;
482 struct i40e_aq_desc desc;
483 struct i40e_aqc_get_set_rss_key *cmd_resp =
484 (struct i40e_aqc_get_set_rss_key *)&desc.params.raw;
485 u16 key_size = sizeof(struct i40e_aqc_get_set_rss_key_data);
486
487 if (set)
488 i40e_fill_default_direct_cmd_desc(&desc,
489 i40e_aqc_opc_set_rss_key);
490 else
491 i40e_fill_default_direct_cmd_desc(&desc,
492 i40e_aqc_opc_get_rss_key);
493
494 /* Indirect command */
495 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
496 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
497
498 cmd_resp->vsi_id =
499 cpu_to_le16((u16)((vsi_id <<
500 I40E_AQC_SET_RSS_KEY_VSI_ID_SHIFT) &
501 I40E_AQC_SET_RSS_KEY_VSI_ID_MASK));
502 cmd_resp->vsi_id |= cpu_to_le16((u16)I40E_AQC_SET_RSS_KEY_VSI_VALID);
Anjali Singhai Jaine50c8d62015-06-05 12:20:27 -0400503
504 status = i40e_asq_send_command(hw, &desc, key, key_size, NULL);
505
506 return status;
507}
508
509/**
510 * i40e_aq_get_rss_key
511 * @hw: pointer to the hw struct
512 * @vsi_id: vsi fw index
513 * @key: pointer to key info struct
514 *
515 **/
516i40e_status i40e_aq_get_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, false);
521}
522
523/**
524 * i40e_aq_set_rss_key
525 * @hw: pointer to the hw struct
526 * @vsi_id: vsi fw index
527 * @key: pointer to key info struct
528 *
529 * set the RSS key per VSI
530 **/
531i40e_status i40e_aq_set_rss_key(struct i40e_hw *hw,
532 u16 vsi_id,
533 struct i40e_aqc_get_set_rss_key_data *key)
534{
535 return i40e_aq_get_set_rss_key(hw, vsi_id, key, true);
536}
537
Jesse Brandeburg206812b2014-02-12 01:45:33 +0000538/* The i40e_ptype_lookup table is used to convert from the 8-bit ptype in the
539 * hardware to a bit-field that can be used by SW to more easily determine the
540 * packet type.
541 *
542 * Macros are used to shorten the table lines and make this table human
543 * readable.
544 *
545 * We store the PTYPE in the top byte of the bit field - this is just so that
546 * we can check that the table doesn't have a row missing, as the index into
547 * the table should be the PTYPE.
548 *
549 * Typical work flow:
550 *
551 * IF NOT i40e_ptype_lookup[ptype].known
552 * THEN
553 * Packet is unknown
554 * ELSE IF i40e_ptype_lookup[ptype].outer_ip == I40E_RX_PTYPE_OUTER_IP
555 * Use the rest of the fields to look at the tunnels, inner protocols, etc
556 * ELSE
557 * Use the enum i40e_rx_l2_ptype to decode the packet type
558 * ENDIF
559 */
560
561/* macro to make the table lines short */
562#define I40E_PTT(PTYPE, OUTER_IP, OUTER_IP_VER, OUTER_FRAG, T, TE, TEF, I, PL)\
563 { PTYPE, \
564 1, \
565 I40E_RX_PTYPE_OUTER_##OUTER_IP, \
566 I40E_RX_PTYPE_OUTER_##OUTER_IP_VER, \
567 I40E_RX_PTYPE_##OUTER_FRAG, \
568 I40E_RX_PTYPE_TUNNEL_##T, \
569 I40E_RX_PTYPE_TUNNEL_END_##TE, \
570 I40E_RX_PTYPE_##TEF, \
571 I40E_RX_PTYPE_INNER_PROT_##I, \
572 I40E_RX_PTYPE_PAYLOAD_LAYER_##PL }
573
574#define I40E_PTT_UNUSED_ENTRY(PTYPE) \
575 { PTYPE, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
576
577/* shorter macros makes the table fit but are terse */
578#define I40E_RX_PTYPE_NOF I40E_RX_PTYPE_NOT_FRAG
579#define I40E_RX_PTYPE_FRG I40E_RX_PTYPE_FRAG
580#define I40E_RX_PTYPE_INNER_PROT_TS I40E_RX_PTYPE_INNER_PROT_TIMESYNC
581
582/* Lookup table mapping the HW PTYPE to the bit field for decoding */
583struct i40e_rx_ptype_decoded i40e_ptype_lookup[] = {
584 /* L2 Packet types */
585 I40E_PTT_UNUSED_ENTRY(0),
586 I40E_PTT(1, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
587 I40E_PTT(2, L2, NONE, NOF, NONE, NONE, NOF, TS, PAY2),
588 I40E_PTT(3, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
589 I40E_PTT_UNUSED_ENTRY(4),
590 I40E_PTT_UNUSED_ENTRY(5),
591 I40E_PTT(6, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
592 I40E_PTT(7, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
593 I40E_PTT_UNUSED_ENTRY(8),
594 I40E_PTT_UNUSED_ENTRY(9),
595 I40E_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
596 I40E_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
597 I40E_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
598 I40E_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
599 I40E_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
600 I40E_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
601 I40E_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
602 I40E_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
603 I40E_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
604 I40E_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
605 I40E_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
606 I40E_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
607
608 /* Non Tunneled IPv4 */
609 I40E_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
610 I40E_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
611 I40E_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP, PAY4),
612 I40E_PTT_UNUSED_ENTRY(25),
613 I40E_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP, PAY4),
614 I40E_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
615 I40E_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
616
617 /* IPv4 --> IPv4 */
618 I40E_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
619 I40E_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
620 I40E_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
621 I40E_PTT_UNUSED_ENTRY(32),
622 I40E_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
623 I40E_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
624 I40E_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
625
626 /* IPv4 --> IPv6 */
627 I40E_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
628 I40E_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
629 I40E_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
630 I40E_PTT_UNUSED_ENTRY(39),
631 I40E_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
632 I40E_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
633 I40E_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
634
635 /* IPv4 --> GRE/NAT */
636 I40E_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
637
638 /* IPv4 --> GRE/NAT --> IPv4 */
639 I40E_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
640 I40E_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
641 I40E_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
642 I40E_PTT_UNUSED_ENTRY(47),
643 I40E_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
644 I40E_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
645 I40E_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
646
647 /* IPv4 --> GRE/NAT --> IPv6 */
648 I40E_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
649 I40E_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
650 I40E_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
651 I40E_PTT_UNUSED_ENTRY(54),
652 I40E_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
653 I40E_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
654 I40E_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
655
656 /* IPv4 --> GRE/NAT --> MAC */
657 I40E_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
658
659 /* IPv4 --> GRE/NAT --> MAC --> IPv4 */
660 I40E_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
661 I40E_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
662 I40E_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
663 I40E_PTT_UNUSED_ENTRY(62),
664 I40E_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
665 I40E_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
666 I40E_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
667
668 /* IPv4 --> GRE/NAT -> MAC --> IPv6 */
669 I40E_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
670 I40E_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
671 I40E_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
672 I40E_PTT_UNUSED_ENTRY(69),
673 I40E_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
674 I40E_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
675 I40E_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
676
677 /* IPv4 --> GRE/NAT --> MAC/VLAN */
678 I40E_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
679
680 /* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
681 I40E_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
682 I40E_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
683 I40E_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
684 I40E_PTT_UNUSED_ENTRY(77),
685 I40E_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
686 I40E_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
687 I40E_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
688
689 /* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
690 I40E_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
691 I40E_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
692 I40E_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
693 I40E_PTT_UNUSED_ENTRY(84),
694 I40E_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
695 I40E_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
696 I40E_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
697
698 /* Non Tunneled IPv6 */
699 I40E_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
700 I40E_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
Akeem G Abodunrin73df8c92016-05-03 15:13:16 -0700701 I40E_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP, PAY4),
Jesse Brandeburg206812b2014-02-12 01:45:33 +0000702 I40E_PTT_UNUSED_ENTRY(91),
703 I40E_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP, PAY4),
704 I40E_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
705 I40E_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
706
707 /* IPv6 --> IPv4 */
708 I40E_PTT(95, IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
709 I40E_PTT(96, IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
710 I40E_PTT(97, IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
711 I40E_PTT_UNUSED_ENTRY(98),
712 I40E_PTT(99, IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
713 I40E_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
714 I40E_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
715
716 /* IPv6 --> IPv6 */
717 I40E_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
718 I40E_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
719 I40E_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
720 I40E_PTT_UNUSED_ENTRY(105),
721 I40E_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
722 I40E_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
723 I40E_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
724
725 /* IPv6 --> GRE/NAT */
726 I40E_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
727
728 /* IPv6 --> GRE/NAT -> IPv4 */
729 I40E_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
730 I40E_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
731 I40E_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
732 I40E_PTT_UNUSED_ENTRY(113),
733 I40E_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
734 I40E_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
735 I40E_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
736
737 /* IPv6 --> GRE/NAT -> IPv6 */
738 I40E_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
739 I40E_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
740 I40E_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
741 I40E_PTT_UNUSED_ENTRY(120),
742 I40E_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
743 I40E_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
744 I40E_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
745
746 /* IPv6 --> GRE/NAT -> MAC */
747 I40E_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
748
749 /* IPv6 --> GRE/NAT -> MAC -> IPv4 */
750 I40E_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
751 I40E_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
752 I40E_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
753 I40E_PTT_UNUSED_ENTRY(128),
754 I40E_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
755 I40E_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
756 I40E_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
757
758 /* IPv6 --> GRE/NAT -> MAC -> IPv6 */
759 I40E_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
760 I40E_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
761 I40E_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
762 I40E_PTT_UNUSED_ENTRY(135),
763 I40E_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
764 I40E_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
765 I40E_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
766
767 /* IPv6 --> GRE/NAT -> MAC/VLAN */
768 I40E_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
769
770 /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
771 I40E_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
772 I40E_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
773 I40E_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
774 I40E_PTT_UNUSED_ENTRY(143),
775 I40E_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
776 I40E_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
777 I40E_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
778
779 /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
780 I40E_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
781 I40E_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
782 I40E_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
783 I40E_PTT_UNUSED_ENTRY(150),
784 I40E_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
785 I40E_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
786 I40E_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
787
788 /* unused entries */
789 I40E_PTT_UNUSED_ENTRY(154),
790 I40E_PTT_UNUSED_ENTRY(155),
791 I40E_PTT_UNUSED_ENTRY(156),
792 I40E_PTT_UNUSED_ENTRY(157),
793 I40E_PTT_UNUSED_ENTRY(158),
794 I40E_PTT_UNUSED_ENTRY(159),
795
796 I40E_PTT_UNUSED_ENTRY(160),
797 I40E_PTT_UNUSED_ENTRY(161),
798 I40E_PTT_UNUSED_ENTRY(162),
799 I40E_PTT_UNUSED_ENTRY(163),
800 I40E_PTT_UNUSED_ENTRY(164),
801 I40E_PTT_UNUSED_ENTRY(165),
802 I40E_PTT_UNUSED_ENTRY(166),
803 I40E_PTT_UNUSED_ENTRY(167),
804 I40E_PTT_UNUSED_ENTRY(168),
805 I40E_PTT_UNUSED_ENTRY(169),
806
807 I40E_PTT_UNUSED_ENTRY(170),
808 I40E_PTT_UNUSED_ENTRY(171),
809 I40E_PTT_UNUSED_ENTRY(172),
810 I40E_PTT_UNUSED_ENTRY(173),
811 I40E_PTT_UNUSED_ENTRY(174),
812 I40E_PTT_UNUSED_ENTRY(175),
813 I40E_PTT_UNUSED_ENTRY(176),
814 I40E_PTT_UNUSED_ENTRY(177),
815 I40E_PTT_UNUSED_ENTRY(178),
816 I40E_PTT_UNUSED_ENTRY(179),
817
818 I40E_PTT_UNUSED_ENTRY(180),
819 I40E_PTT_UNUSED_ENTRY(181),
820 I40E_PTT_UNUSED_ENTRY(182),
821 I40E_PTT_UNUSED_ENTRY(183),
822 I40E_PTT_UNUSED_ENTRY(184),
823 I40E_PTT_UNUSED_ENTRY(185),
824 I40E_PTT_UNUSED_ENTRY(186),
825 I40E_PTT_UNUSED_ENTRY(187),
826 I40E_PTT_UNUSED_ENTRY(188),
827 I40E_PTT_UNUSED_ENTRY(189),
828
829 I40E_PTT_UNUSED_ENTRY(190),
830 I40E_PTT_UNUSED_ENTRY(191),
831 I40E_PTT_UNUSED_ENTRY(192),
832 I40E_PTT_UNUSED_ENTRY(193),
833 I40E_PTT_UNUSED_ENTRY(194),
834 I40E_PTT_UNUSED_ENTRY(195),
835 I40E_PTT_UNUSED_ENTRY(196),
836 I40E_PTT_UNUSED_ENTRY(197),
837 I40E_PTT_UNUSED_ENTRY(198),
838 I40E_PTT_UNUSED_ENTRY(199),
839
840 I40E_PTT_UNUSED_ENTRY(200),
841 I40E_PTT_UNUSED_ENTRY(201),
842 I40E_PTT_UNUSED_ENTRY(202),
843 I40E_PTT_UNUSED_ENTRY(203),
844 I40E_PTT_UNUSED_ENTRY(204),
845 I40E_PTT_UNUSED_ENTRY(205),
846 I40E_PTT_UNUSED_ENTRY(206),
847 I40E_PTT_UNUSED_ENTRY(207),
848 I40E_PTT_UNUSED_ENTRY(208),
849 I40E_PTT_UNUSED_ENTRY(209),
850
851 I40E_PTT_UNUSED_ENTRY(210),
852 I40E_PTT_UNUSED_ENTRY(211),
853 I40E_PTT_UNUSED_ENTRY(212),
854 I40E_PTT_UNUSED_ENTRY(213),
855 I40E_PTT_UNUSED_ENTRY(214),
856 I40E_PTT_UNUSED_ENTRY(215),
857 I40E_PTT_UNUSED_ENTRY(216),
858 I40E_PTT_UNUSED_ENTRY(217),
859 I40E_PTT_UNUSED_ENTRY(218),
860 I40E_PTT_UNUSED_ENTRY(219),
861
862 I40E_PTT_UNUSED_ENTRY(220),
863 I40E_PTT_UNUSED_ENTRY(221),
864 I40E_PTT_UNUSED_ENTRY(222),
865 I40E_PTT_UNUSED_ENTRY(223),
866 I40E_PTT_UNUSED_ENTRY(224),
867 I40E_PTT_UNUSED_ENTRY(225),
868 I40E_PTT_UNUSED_ENTRY(226),
869 I40E_PTT_UNUSED_ENTRY(227),
870 I40E_PTT_UNUSED_ENTRY(228),
871 I40E_PTT_UNUSED_ENTRY(229),
872
873 I40E_PTT_UNUSED_ENTRY(230),
874 I40E_PTT_UNUSED_ENTRY(231),
875 I40E_PTT_UNUSED_ENTRY(232),
876 I40E_PTT_UNUSED_ENTRY(233),
877 I40E_PTT_UNUSED_ENTRY(234),
878 I40E_PTT_UNUSED_ENTRY(235),
879 I40E_PTT_UNUSED_ENTRY(236),
880 I40E_PTT_UNUSED_ENTRY(237),
881 I40E_PTT_UNUSED_ENTRY(238),
882 I40E_PTT_UNUSED_ENTRY(239),
883
884 I40E_PTT_UNUSED_ENTRY(240),
885 I40E_PTT_UNUSED_ENTRY(241),
886 I40E_PTT_UNUSED_ENTRY(242),
887 I40E_PTT_UNUSED_ENTRY(243),
888 I40E_PTT_UNUSED_ENTRY(244),
889 I40E_PTT_UNUSED_ENTRY(245),
890 I40E_PTT_UNUSED_ENTRY(246),
891 I40E_PTT_UNUSED_ENTRY(247),
892 I40E_PTT_UNUSED_ENTRY(248),
893 I40E_PTT_UNUSED_ENTRY(249),
894
895 I40E_PTT_UNUSED_ENTRY(250),
896 I40E_PTT_UNUSED_ENTRY(251),
897 I40E_PTT_UNUSED_ENTRY(252),
898 I40E_PTT_UNUSED_ENTRY(253),
899 I40E_PTT_UNUSED_ENTRY(254),
900 I40E_PTT_UNUSED_ENTRY(255)
901};
902
Anjali Singhai Jaine1860d82013-11-28 06:39:45 +0000903/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000904 * i40e_init_shared_code - Initialize the shared code
905 * @hw: pointer to hardware structure
906 *
907 * This assigns the MAC type and PHY code and inits the NVM.
908 * Does not touch the hardware. This function must be called prior to any
909 * other function in the shared code. The i40e_hw structure should be
910 * memset to 0 prior to calling this function. The following fields in
911 * hw structure should be filled in prior to calling this function:
912 * hw_addr, back, device_id, vendor_id, subsystem_device_id,
913 * subsystem_vendor_id, and revision_id
914 **/
915i40e_status i40e_init_shared_code(struct i40e_hw *hw)
916{
917 i40e_status status = 0;
Shannon Nelson5fb11d72014-11-13 03:06:19 +0000918 u32 port, ari, func_rid;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000919
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000920 i40e_set_mac_type(hw);
921
922 switch (hw->mac.type) {
923 case I40E_MAC_XL710:
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -0400924 case I40E_MAC_X722:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000925 break;
926 default:
927 return I40E_ERR_DEVICE_NOT_SUPPORTED;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000928 }
929
Shannon Nelsonaf89d26c2013-12-11 08:17:14 +0000930 hw->phy.get_link_info = true;
931
Shannon Nelson5fb11d72014-11-13 03:06:19 +0000932 /* Determine port number and PF number*/
933 port = (rd32(hw, I40E_PFGEN_PORTNUM) & I40E_PFGEN_PORTNUM_PORT_NUM_MASK)
934 >> I40E_PFGEN_PORTNUM_PORT_NUM_SHIFT;
935 hw->port = (u8)port;
936 ari = (rd32(hw, I40E_GLPCI_CAPSUP) & I40E_GLPCI_CAPSUP_ARI_EN_MASK) >>
937 I40E_GLPCI_CAPSUP_ARI_EN_SHIFT;
938 func_rid = rd32(hw, I40E_PF_FUNC_RID);
939 if (ari)
940 hw->pf_id = (u8)(func_rid & 0xff);
Shannon Nelson5f9116a2013-12-11 08:17:13 +0000941 else
Shannon Nelson5fb11d72014-11-13 03:06:19 +0000942 hw->pf_id = (u8)(func_rid & 0x7);
Shannon Nelson5f9116a2013-12-11 08:17:13 +0000943
Anjali Singhai07f89be2015-09-24 15:26:32 -0700944 if (hw->mac.type == I40E_MAC_X722)
945 hw->flags |= I40E_HW_FLAG_AQ_SRCTL_ACCESS_ENABLE;
946
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000947 status = i40e_init_nvm(hw);
948 return status;
949}
950
951/**
952 * i40e_aq_mac_address_read - Retrieve the MAC addresses
953 * @hw: pointer to the hw struct
954 * @flags: a return indicator of what addresses were added to the addr store
955 * @addrs: the requestor's mac addr store
956 * @cmd_details: pointer to command details structure or NULL
957 **/
958static i40e_status i40e_aq_mac_address_read(struct i40e_hw *hw,
959 u16 *flags,
960 struct i40e_aqc_mac_address_read_data *addrs,
961 struct i40e_asq_cmd_details *cmd_details)
962{
963 struct i40e_aq_desc desc;
964 struct i40e_aqc_mac_address_read *cmd_data =
965 (struct i40e_aqc_mac_address_read *)&desc.params.raw;
966 i40e_status status;
967
968 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_mac_address_read);
969 desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF);
970
971 status = i40e_asq_send_command(hw, &desc, addrs,
972 sizeof(*addrs), cmd_details);
973 *flags = le16_to_cpu(cmd_data->command_flags);
974
975 return status;
976}
977
978/**
979 * i40e_aq_mac_address_write - Change the MAC addresses
980 * @hw: pointer to the hw struct
981 * @flags: indicates which MAC to be written
982 * @mac_addr: address to write
983 * @cmd_details: pointer to command details structure or NULL
984 **/
985i40e_status i40e_aq_mac_address_write(struct i40e_hw *hw,
986 u16 flags, u8 *mac_addr,
987 struct i40e_asq_cmd_details *cmd_details)
988{
989 struct i40e_aq_desc desc;
990 struct i40e_aqc_mac_address_write *cmd_data =
991 (struct i40e_aqc_mac_address_write *)&desc.params.raw;
992 i40e_status status;
993
994 i40e_fill_default_direct_cmd_desc(&desc,
995 i40e_aqc_opc_mac_address_write);
996 cmd_data->command_flags = cpu_to_le16(flags);
Kamil Krawczyk55c29c32013-12-18 13:45:52 +0000997 cmd_data->mac_sah = cpu_to_le16((u16)mac_addr[0] << 8 | mac_addr[1]);
998 cmd_data->mac_sal = cpu_to_le32(((u32)mac_addr[2] << 24) |
999 ((u32)mac_addr[3] << 16) |
1000 ((u32)mac_addr[4] << 8) |
1001 mac_addr[5]);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001002
1003 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1004
1005 return status;
1006}
1007
1008/**
1009 * i40e_get_mac_addr - get MAC address
1010 * @hw: pointer to the HW structure
1011 * @mac_addr: pointer to MAC address
1012 *
1013 * Reads the adapter's MAC address from register
1014 **/
1015i40e_status i40e_get_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
1016{
1017 struct i40e_aqc_mac_address_read_data addrs;
1018 i40e_status status;
1019 u16 flags = 0;
1020
1021 status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
1022
1023 if (flags & I40E_AQC_LAN_ADDR_VALID)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001024 ether_addr_copy(mac_addr, addrs.pf_lan_mac);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001025
1026 return status;
1027}
1028
1029/**
Neerav Parikh1f224ad2014-02-12 01:45:31 +00001030 * i40e_get_port_mac_addr - get Port MAC address
1031 * @hw: pointer to the HW structure
1032 * @mac_addr: pointer to Port MAC address
1033 *
1034 * Reads the adapter's Port MAC address
1035 **/
1036i40e_status i40e_get_port_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
1037{
1038 struct i40e_aqc_mac_address_read_data addrs;
1039 i40e_status status;
1040 u16 flags = 0;
1041
1042 status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
1043 if (status)
1044 return status;
1045
1046 if (flags & I40E_AQC_PORT_ADDR_VALID)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001047 ether_addr_copy(mac_addr, addrs.port_mac);
Neerav Parikh1f224ad2014-02-12 01:45:31 +00001048 else
1049 status = I40E_ERR_INVALID_MAC_ADDR;
1050
1051 return status;
1052}
1053
1054/**
Matt Jared351499ab2014-04-23 04:50:03 +00001055 * i40e_pre_tx_queue_cfg - pre tx queue configure
1056 * @hw: pointer to the HW structure
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00001057 * @queue: target PF queue index
Matt Jared351499ab2014-04-23 04:50:03 +00001058 * @enable: state change request
1059 *
1060 * Handles hw requirement to indicate intention to enable
1061 * or disable target queue.
1062 **/
1063void i40e_pre_tx_queue_cfg(struct i40e_hw *hw, u32 queue, bool enable)
1064{
Shannon Nelsondfb699f2014-05-22 06:32:28 +00001065 u32 abs_queue_idx = hw->func_caps.base_queue + queue;
Matt Jared351499ab2014-04-23 04:50:03 +00001066 u32 reg_block = 0;
Shannon Nelsondfb699f2014-05-22 06:32:28 +00001067 u32 reg_val;
Matt Jared351499ab2014-04-23 04:50:03 +00001068
Christopher Pau24a768c2014-06-04 20:41:59 +00001069 if (abs_queue_idx >= 128) {
Matt Jared351499ab2014-04-23 04:50:03 +00001070 reg_block = abs_queue_idx / 128;
Christopher Pau24a768c2014-06-04 20:41:59 +00001071 abs_queue_idx %= 128;
1072 }
Matt Jared351499ab2014-04-23 04:50:03 +00001073
1074 reg_val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
1075 reg_val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
1076 reg_val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
1077
1078 if (enable)
1079 reg_val |= I40E_GLLAN_TXPRE_QDIS_CLEAR_QDIS_MASK;
1080 else
1081 reg_val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
1082
1083 wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), reg_val);
1084}
Vasu Dev38e00432014-08-01 13:27:03 -07001085#ifdef I40E_FCOE
1086
1087/**
1088 * i40e_get_san_mac_addr - get SAN MAC address
1089 * @hw: pointer to the HW structure
1090 * @mac_addr: pointer to SAN MAC address
1091 *
1092 * Reads the adapter's SAN MAC address from NVM
1093 **/
1094i40e_status i40e_get_san_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
1095{
1096 struct i40e_aqc_mac_address_read_data addrs;
1097 i40e_status status;
1098 u16 flags = 0;
1099
1100 status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
1101 if (status)
1102 return status;
1103
1104 if (flags & I40E_AQC_SAN_ADDR_VALID)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001105 ether_addr_copy(mac_addr, addrs.pf_san_mac);
Vasu Dev38e00432014-08-01 13:27:03 -07001106 else
1107 status = I40E_ERR_INVALID_MAC_ADDR;
1108
1109 return status;
1110}
1111#endif
Matt Jared351499ab2014-04-23 04:50:03 +00001112
1113/**
Kamil Krawczyk18f680c2014-12-11 07:06:31 +00001114 * i40e_read_pba_string - Reads part number string from EEPROM
1115 * @hw: pointer to hardware structure
1116 * @pba_num: stores the part number string from the EEPROM
1117 * @pba_num_size: part number string buffer length
1118 *
1119 * Reads the part number string from the EEPROM.
1120 **/
1121i40e_status i40e_read_pba_string(struct i40e_hw *hw, u8 *pba_num,
1122 u32 pba_num_size)
1123{
1124 i40e_status status = 0;
1125 u16 pba_word = 0;
1126 u16 pba_size = 0;
1127 u16 pba_ptr = 0;
1128 u16 i = 0;
1129
1130 status = i40e_read_nvm_word(hw, I40E_SR_PBA_FLAGS, &pba_word);
1131 if (status || (pba_word != 0xFAFA)) {
1132 hw_dbg(hw, "Failed to read PBA flags or flag is invalid.\n");
1133 return status;
1134 }
1135
1136 status = i40e_read_nvm_word(hw, I40E_SR_PBA_BLOCK_PTR, &pba_ptr);
1137 if (status) {
1138 hw_dbg(hw, "Failed to read PBA Block pointer.\n");
1139 return status;
1140 }
1141
1142 status = i40e_read_nvm_word(hw, pba_ptr, &pba_size);
1143 if (status) {
1144 hw_dbg(hw, "Failed to read PBA Block size.\n");
1145 return status;
1146 }
1147
1148 /* Subtract one to get PBA word count (PBA Size word is included in
1149 * total size)
1150 */
1151 pba_size--;
1152 if (pba_num_size < (((u32)pba_size * 2) + 1)) {
1153 hw_dbg(hw, "Buffer to small for PBA data.\n");
1154 return I40E_ERR_PARAM;
1155 }
1156
1157 for (i = 0; i < pba_size; i++) {
1158 status = i40e_read_nvm_word(hw, (pba_ptr + 1) + i, &pba_word);
1159 if (status) {
1160 hw_dbg(hw, "Failed to read PBA Block word %d.\n", i);
1161 return status;
1162 }
1163
1164 pba_num[(i * 2)] = (pba_word >> 8) & 0xFF;
1165 pba_num[(i * 2) + 1] = pba_word & 0xFF;
1166 }
1167 pba_num[(pba_size * 2)] = '\0';
1168
1169 return status;
1170}
1171
1172/**
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001173 * i40e_get_media_type - Gets media type
1174 * @hw: pointer to the hardware structure
1175 **/
1176static enum i40e_media_type i40e_get_media_type(struct i40e_hw *hw)
1177{
1178 enum i40e_media_type media;
1179
1180 switch (hw->phy.link_info.phy_type) {
1181 case I40E_PHY_TYPE_10GBASE_SR:
1182 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +00001183 case I40E_PHY_TYPE_1000BASE_SX:
1184 case I40E_PHY_TYPE_1000BASE_LX:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001185 case I40E_PHY_TYPE_40GBASE_SR4:
1186 case I40E_PHY_TYPE_40GBASE_LR4:
1187 media = I40E_MEDIA_TYPE_FIBER;
1188 break;
1189 case I40E_PHY_TYPE_100BASE_TX:
1190 case I40E_PHY_TYPE_1000BASE_T:
1191 case I40E_PHY_TYPE_10GBASE_T:
1192 media = I40E_MEDIA_TYPE_BASET;
1193 break;
1194 case I40E_PHY_TYPE_10GBASE_CR1_CU:
1195 case I40E_PHY_TYPE_40GBASE_CR4_CU:
1196 case I40E_PHY_TYPE_10GBASE_CR1:
1197 case I40E_PHY_TYPE_40GBASE_CR4:
1198 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +00001199 case I40E_PHY_TYPE_40GBASE_AOC:
1200 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001201 media = I40E_MEDIA_TYPE_DA;
1202 break;
1203 case I40E_PHY_TYPE_1000BASE_KX:
1204 case I40E_PHY_TYPE_10GBASE_KX4:
1205 case I40E_PHY_TYPE_10GBASE_KR:
1206 case I40E_PHY_TYPE_40GBASE_KR4:
Jesse Brandeburgae24b402015-03-27 00:12:09 -07001207 case I40E_PHY_TYPE_20GBASE_KR2:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001208 media = I40E_MEDIA_TYPE_BACKPLANE;
1209 break;
1210 case I40E_PHY_TYPE_SGMII:
1211 case I40E_PHY_TYPE_XAUI:
1212 case I40E_PHY_TYPE_XFI:
1213 case I40E_PHY_TYPE_XLAUI:
1214 case I40E_PHY_TYPE_XLPPI:
1215 default:
1216 media = I40E_MEDIA_TYPE_UNKNOWN;
1217 break;
1218 }
1219
1220 return media;
1221}
1222
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001223#define I40E_PF_RESET_WAIT_COUNT_A0 200
Akeem G Abodunrin8af580d2015-03-27 00:12:10 -07001224#define I40E_PF_RESET_WAIT_COUNT 200
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001225/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001226 * i40e_pf_reset - Reset the PF
1227 * @hw: pointer to the hardware structure
1228 *
1229 * Assuming someone else has triggered a global reset,
1230 * assure the global reset is complete and then reset the PF
1231 **/
1232i40e_status i40e_pf_reset(struct i40e_hw *hw)
1233{
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001234 u32 cnt = 0;
Shannon Nelson42794bd2013-12-11 08:17:10 +00001235 u32 cnt1 = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001236 u32 reg = 0;
1237 u32 grst_del;
1238
1239 /* Poll for Global Reset steady state in case of recent GRST.
1240 * The grst delay value is in 100ms units, and we'll wait a
1241 * couple counts longer to be sure we don't just miss the end.
1242 */
Shannon Nelsonde78fc52015-02-21 06:41:47 +00001243 grst_del = (rd32(hw, I40E_GLGEN_RSTCTL) &
1244 I40E_GLGEN_RSTCTL_GRSTDEL_MASK) >>
1245 I40E_GLGEN_RSTCTL_GRSTDEL_SHIFT;
Kevin Scott4d7cec02016-02-17 16:12:13 -08001246
1247 /* It can take upto 15 secs for GRST steady state.
1248 * Bump it to 16 secs max to be safe.
1249 */
1250 grst_del = grst_del * 20;
1251
1252 for (cnt = 0; cnt < grst_del; cnt++) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001253 reg = rd32(hw, I40E_GLGEN_RSTAT);
1254 if (!(reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK))
1255 break;
1256 msleep(100);
1257 }
1258 if (reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
1259 hw_dbg(hw, "Global reset polling failed to complete.\n");
1260 return I40E_ERR_RESET_FAILED;
1261 }
1262
Shannon Nelson42794bd2013-12-11 08:17:10 +00001263 /* Now Wait for the FW to be ready */
1264 for (cnt1 = 0; cnt1 < I40E_PF_RESET_WAIT_COUNT; cnt1++) {
1265 reg = rd32(hw, I40E_GLNVM_ULD);
1266 reg &= (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
1267 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK);
1268 if (reg == (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
1269 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK)) {
1270 hw_dbg(hw, "Core and Global modules ready %d\n", cnt1);
1271 break;
1272 }
1273 usleep_range(10000, 20000);
1274 }
1275 if (!(reg & (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
1276 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK))) {
1277 hw_dbg(hw, "wait for FW Reset complete timedout\n");
1278 hw_dbg(hw, "I40E_GLNVM_ULD = 0x%x\n", reg);
1279 return I40E_ERR_RESET_FAILED;
1280 }
1281
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001282 /* If there was a Global Reset in progress when we got here,
1283 * we don't need to do the PF Reset
1284 */
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001285 if (!cnt) {
1286 if (hw->revision_id == 0)
1287 cnt = I40E_PF_RESET_WAIT_COUNT_A0;
1288 else
1289 cnt = I40E_PF_RESET_WAIT_COUNT;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001290 reg = rd32(hw, I40E_PFGEN_CTRL);
1291 wr32(hw, I40E_PFGEN_CTRL,
1292 (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001293 for (; cnt; cnt--) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001294 reg = rd32(hw, I40E_PFGEN_CTRL);
1295 if (!(reg & I40E_PFGEN_CTRL_PFSWR_MASK))
1296 break;
1297 usleep_range(1000, 2000);
1298 }
1299 if (reg & I40E_PFGEN_CTRL_PFSWR_MASK) {
1300 hw_dbg(hw, "PF reset polling failed to complete.\n");
1301 return I40E_ERR_RESET_FAILED;
1302 }
1303 }
1304
1305 i40e_clear_pxe_mode(hw);
Shannon Nelson922680b2013-12-18 05:29:17 +00001306
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001307 return 0;
1308}
1309
1310/**
Shannon Nelson838d41d2014-06-04 20:41:27 +00001311 * i40e_clear_hw - clear out any left over hw state
1312 * @hw: pointer to the hw struct
1313 *
1314 * Clear queues and interrupts, typically called at init time,
1315 * but after the capabilities have been found so we know how many
1316 * queues and msix vectors have been allocated.
1317 **/
1318void i40e_clear_hw(struct i40e_hw *hw)
1319{
1320 u32 num_queues, base_queue;
1321 u32 num_pf_int;
1322 u32 num_vf_int;
1323 u32 num_vfs;
1324 u32 i, j;
1325 u32 val;
1326 u32 eol = 0x7ff;
1327
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00001328 /* get number of interrupts, queues, and VFs */
Shannon Nelson838d41d2014-06-04 20:41:27 +00001329 val = rd32(hw, I40E_GLPCI_CNF2);
1330 num_pf_int = (val & I40E_GLPCI_CNF2_MSI_X_PF_N_MASK) >>
1331 I40E_GLPCI_CNF2_MSI_X_PF_N_SHIFT;
1332 num_vf_int = (val & I40E_GLPCI_CNF2_MSI_X_VF_N_MASK) >>
1333 I40E_GLPCI_CNF2_MSI_X_VF_N_SHIFT;
1334
Shannon Nelson272cdaf22016-02-17 16:12:21 -08001335 val = rd32(hw, I40E_PFLAN_QALLOC);
Shannon Nelson838d41d2014-06-04 20:41:27 +00001336 base_queue = (val & I40E_PFLAN_QALLOC_FIRSTQ_MASK) >>
1337 I40E_PFLAN_QALLOC_FIRSTQ_SHIFT;
1338 j = (val & I40E_PFLAN_QALLOC_LASTQ_MASK) >>
1339 I40E_PFLAN_QALLOC_LASTQ_SHIFT;
1340 if (val & I40E_PFLAN_QALLOC_VALID_MASK)
1341 num_queues = (j - base_queue) + 1;
1342 else
1343 num_queues = 0;
1344
1345 val = rd32(hw, I40E_PF_VT_PFALLOC);
1346 i = (val & I40E_PF_VT_PFALLOC_FIRSTVF_MASK) >>
1347 I40E_PF_VT_PFALLOC_FIRSTVF_SHIFT;
1348 j = (val & I40E_PF_VT_PFALLOC_LASTVF_MASK) >>
1349 I40E_PF_VT_PFALLOC_LASTVF_SHIFT;
1350 if (val & I40E_PF_VT_PFALLOC_VALID_MASK)
1351 num_vfs = (j - i) + 1;
1352 else
1353 num_vfs = 0;
1354
1355 /* stop all the interrupts */
1356 wr32(hw, I40E_PFINT_ICR0_ENA, 0);
1357 val = 0x3 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT;
1358 for (i = 0; i < num_pf_int - 2; i++)
1359 wr32(hw, I40E_PFINT_DYN_CTLN(i), val);
1360
1361 /* Set the FIRSTQ_INDX field to 0x7FF in PFINT_LNKLSTx */
1362 val = eol << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
1363 wr32(hw, I40E_PFINT_LNKLST0, val);
1364 for (i = 0; i < num_pf_int - 2; i++)
1365 wr32(hw, I40E_PFINT_LNKLSTN(i), val);
1366 val = eol << I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT;
1367 for (i = 0; i < num_vfs; i++)
1368 wr32(hw, I40E_VPINT_LNKLST0(i), val);
1369 for (i = 0; i < num_vf_int - 2; i++)
1370 wr32(hw, I40E_VPINT_LNKLSTN(i), val);
1371
1372 /* warn the HW of the coming Tx disables */
1373 for (i = 0; i < num_queues; i++) {
1374 u32 abs_queue_idx = base_queue + i;
1375 u32 reg_block = 0;
1376
1377 if (abs_queue_idx >= 128) {
1378 reg_block = abs_queue_idx / 128;
1379 abs_queue_idx %= 128;
1380 }
1381
1382 val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
1383 val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
1384 val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
1385 val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
1386
1387 wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), val);
1388 }
1389 udelay(400);
1390
1391 /* stop all the queues */
1392 for (i = 0; i < num_queues; i++) {
1393 wr32(hw, I40E_QINT_TQCTL(i), 0);
1394 wr32(hw, I40E_QTX_ENA(i), 0);
1395 wr32(hw, I40E_QINT_RQCTL(i), 0);
1396 wr32(hw, I40E_QRX_ENA(i), 0);
1397 }
1398
1399 /* short wait for all queue disables to settle */
1400 udelay(50);
1401}
1402
1403/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001404 * i40e_clear_pxe_mode - clear pxe operations mode
1405 * @hw: pointer to the hw struct
1406 *
1407 * Make sure all PXE mode settings are cleared, including things
1408 * like descriptor fetch/write-back mode.
1409 **/
1410void i40e_clear_pxe_mode(struct i40e_hw *hw)
1411{
1412 u32 reg;
1413
Shannon Nelsonc9b9b0a2014-04-09 05:59:05 +00001414 if (i40e_check_asq_alive(hw))
1415 i40e_aq_clear_pxe_mode(hw, NULL);
1416
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001417 /* Clear single descriptor fetch/write-back mode */
1418 reg = rd32(hw, I40E_GLLAN_RCTL_0);
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001419
1420 if (hw->revision_id == 0) {
1421 /* As a work around clear PXE_MODE instead of setting it */
1422 wr32(hw, I40E_GLLAN_RCTL_0, (reg & (~I40E_GLLAN_RCTL_0_PXE_MODE_MASK)));
1423 } else {
1424 wr32(hw, I40E_GLLAN_RCTL_0, (reg | I40E_GLLAN_RCTL_0_PXE_MODE_MASK));
1425 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001426}
1427
1428/**
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001429 * i40e_led_is_mine - helper to find matching led
1430 * @hw: pointer to the hw struct
1431 * @idx: index into GPIO registers
1432 *
1433 * returns: 0 if no match, otherwise the value of the GPIO_CTL register
1434 */
1435static u32 i40e_led_is_mine(struct i40e_hw *hw, int idx)
1436{
1437 u32 gpio_val = 0;
1438 u32 port;
1439
1440 if (!hw->func_caps.led[idx])
1441 return 0;
1442
1443 gpio_val = rd32(hw, I40E_GLGEN_GPIO_CTL(idx));
1444 port = (gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_MASK) >>
1445 I40E_GLGEN_GPIO_CTL_PRT_NUM_SHIFT;
1446
1447 /* if PRT_NUM_NA is 1 then this LED is not port specific, OR
1448 * if it is not our port then ignore
1449 */
1450 if ((gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_NA_MASK) ||
1451 (port != hw->port))
1452 return 0;
1453
1454 return gpio_val;
1455}
1456
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001457#define I40E_COMBINED_ACTIVITY 0xA
1458#define I40E_FILTER_ACTIVITY 0xE
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001459#define I40E_LINK_ACTIVITY 0xC
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001460#define I40E_MAC_ACTIVITY 0xD
1461#define I40E_LED0 22
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001462
1463/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001464 * i40e_led_get - return current on/off mode
1465 * @hw: pointer to the hw struct
1466 *
1467 * The value returned is the 'mode' field as defined in the
1468 * GPIO register definitions: 0x0 = off, 0xf = on, and other
1469 * values are variations of possible behaviors relating to
1470 * blink, link, and wire.
1471 **/
1472u32 i40e_led_get(struct i40e_hw *hw)
1473{
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001474 u32 current_mode = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001475 u32 mode = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001476 int i;
1477
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001478 /* as per the documentation GPIO 22-29 are the LED
1479 * GPIO pins named LED0..LED7
1480 */
1481 for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
1482 u32 gpio_val = i40e_led_is_mine(hw, i);
1483
1484 if (!gpio_val)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001485 continue;
1486
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001487 /* ignore gpio LED src mode entries related to the activity
1488 * LEDs
1489 */
1490 current_mode = ((gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK)
1491 >> I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT);
1492 switch (current_mode) {
1493 case I40E_COMBINED_ACTIVITY:
1494 case I40E_FILTER_ACTIVITY:
1495 case I40E_MAC_ACTIVITY:
1496 continue;
1497 default:
1498 break;
1499 }
1500
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001501 mode = (gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK) >>
1502 I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001503 break;
1504 }
1505
1506 return mode;
1507}
1508
1509/**
1510 * i40e_led_set - set new on/off mode
1511 * @hw: pointer to the hw struct
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001512 * @mode: 0=off, 0xf=on (else see manual for mode details)
1513 * @blink: true if the LED should blink when on, false if steady
1514 *
1515 * if this function is used to turn on the blink it should
1516 * be used to disable the blink when restoring the original state.
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001517 **/
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001518void i40e_led_set(struct i40e_hw *hw, u32 mode, bool blink)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001519{
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001520 u32 current_mode = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001521 int i;
1522
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001523 if (mode & 0xfffffff0)
1524 hw_dbg(hw, "invalid mode passed in %X\n", mode);
1525
1526 /* as per the documentation GPIO 22-29 are the LED
1527 * GPIO pins named LED0..LED7
1528 */
1529 for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
1530 u32 gpio_val = i40e_led_is_mine(hw, i);
1531
1532 if (!gpio_val)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001533 continue;
1534
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001535 /* ignore gpio LED src mode entries related to the activity
1536 * LEDs
1537 */
1538 current_mode = ((gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK)
1539 >> I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT);
1540 switch (current_mode) {
1541 case I40E_COMBINED_ACTIVITY:
1542 case I40E_FILTER_ACTIVITY:
1543 case I40E_MAC_ACTIVITY:
1544 continue;
1545 default:
1546 break;
1547 }
1548
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001549 gpio_val &= ~I40E_GLGEN_GPIO_CTL_LED_MODE_MASK;
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001550 /* this & is a bit of paranoia, but serves as a range check */
1551 gpio_val |= ((mode << I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT) &
1552 I40E_GLGEN_GPIO_CTL_LED_MODE_MASK);
1553
1554 if (mode == I40E_LINK_ACTIVITY)
1555 blink = false;
1556
Matt Jared9be00d62015-01-24 09:58:28 +00001557 if (blink)
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001558 gpio_val |= BIT(I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
Matt Jared9be00d62015-01-24 09:58:28 +00001559 else
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001560 gpio_val &= ~BIT(I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001561
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001562 wr32(hw, I40E_GLGEN_GPIO_CTL(i), gpio_val);
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001563 break;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001564 }
1565}
1566
1567/* Admin command wrappers */
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001568
1569/**
Catherine Sullivan8109e122014-06-04 08:45:24 +00001570 * i40e_aq_get_phy_capabilities
1571 * @hw: pointer to the hw struct
1572 * @abilities: structure for PHY capabilities to be filled
1573 * @qualified_modules: report Qualified Modules
1574 * @report_init: report init capabilities (active are default)
1575 * @cmd_details: pointer to command details structure or NULL
1576 *
1577 * Returns the various PHY abilities supported on the Port.
1578 **/
1579i40e_status i40e_aq_get_phy_capabilities(struct i40e_hw *hw,
1580 bool qualified_modules, bool report_init,
1581 struct i40e_aq_get_phy_abilities_resp *abilities,
1582 struct i40e_asq_cmd_details *cmd_details)
1583{
1584 struct i40e_aq_desc desc;
1585 i40e_status status;
1586 u16 abilities_size = sizeof(struct i40e_aq_get_phy_abilities_resp);
1587
1588 if (!abilities)
1589 return I40E_ERR_PARAM;
1590
1591 i40e_fill_default_direct_cmd_desc(&desc,
1592 i40e_aqc_opc_get_phy_abilities);
1593
1594 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
1595 if (abilities_size > I40E_AQ_LARGE_BUF)
1596 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
1597
1598 if (qualified_modules)
1599 desc.params.external.param0 |=
1600 cpu_to_le32(I40E_AQ_PHY_REPORT_QUALIFIED_MODULES);
1601
1602 if (report_init)
1603 desc.params.external.param0 |=
1604 cpu_to_le32(I40E_AQ_PHY_REPORT_INITIAL_VALUES);
1605
1606 status = i40e_asq_send_command(hw, &desc, abilities, abilities_size,
1607 cmd_details);
1608
1609 if (hw->aq.asq_last_status == I40E_AQ_RC_EIO)
1610 status = I40E_ERR_UNKNOWN_PHY;
1611
Kevin Scott3ac67d72015-09-03 17:18:58 -04001612 if (report_init)
1613 hw->phy.phy_types = le32_to_cpu(abilities->phy_type);
1614
Catherine Sullivan8109e122014-06-04 08:45:24 +00001615 return status;
1616}
1617
1618/**
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001619 * i40e_aq_set_phy_config
1620 * @hw: pointer to the hw struct
1621 * @config: structure with PHY configuration to be set
1622 * @cmd_details: pointer to command details structure or NULL
1623 *
1624 * Set the various PHY configuration parameters
1625 * supported on the Port.One or more of the Set PHY config parameters may be
1626 * ignored in an MFP mode as the PF may not have the privilege to set some
1627 * of the PHY Config parameters. This status will be indicated by the
1628 * command response.
1629 **/
1630enum i40e_status_code i40e_aq_set_phy_config(struct i40e_hw *hw,
1631 struct i40e_aq_set_phy_config *config,
1632 struct i40e_asq_cmd_details *cmd_details)
1633{
1634 struct i40e_aq_desc desc;
1635 struct i40e_aq_set_phy_config *cmd =
1636 (struct i40e_aq_set_phy_config *)&desc.params.raw;
1637 enum i40e_status_code status;
1638
1639 if (!config)
1640 return I40E_ERR_PARAM;
1641
1642 i40e_fill_default_direct_cmd_desc(&desc,
1643 i40e_aqc_opc_set_phy_config);
1644
1645 *cmd = *config;
1646
1647 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1648
1649 return status;
1650}
1651
1652/**
1653 * i40e_set_fc
1654 * @hw: pointer to the hw struct
1655 *
1656 * Set the requested flow control mode using set_phy_config.
1657 **/
1658enum i40e_status_code i40e_set_fc(struct i40e_hw *hw, u8 *aq_failures,
1659 bool atomic_restart)
1660{
1661 enum i40e_fc_mode fc_mode = hw->fc.requested_mode;
1662 struct i40e_aq_get_phy_abilities_resp abilities;
1663 struct i40e_aq_set_phy_config config;
1664 enum i40e_status_code status;
1665 u8 pause_mask = 0x0;
1666
1667 *aq_failures = 0x0;
1668
1669 switch (fc_mode) {
1670 case I40E_FC_FULL:
1671 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
1672 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
1673 break;
1674 case I40E_FC_RX_PAUSE:
1675 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
1676 break;
1677 case I40E_FC_TX_PAUSE:
1678 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
1679 break;
1680 default:
1681 break;
1682 }
1683
1684 /* Get the current phy config */
1685 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
1686 NULL);
1687 if (status) {
1688 *aq_failures |= I40E_SET_FC_AQ_FAIL_GET;
1689 return status;
1690 }
1691
1692 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
1693 /* clear the old pause settings */
1694 config.abilities = abilities.abilities & ~(I40E_AQ_PHY_FLAG_PAUSE_TX) &
1695 ~(I40E_AQ_PHY_FLAG_PAUSE_RX);
1696 /* set the new abilities */
1697 config.abilities |= pause_mask;
1698 /* If the abilities have changed, then set the new config */
1699 if (config.abilities != abilities.abilities) {
1700 /* Auto restart link so settings take effect */
1701 if (atomic_restart)
1702 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
1703 /* Copy over all the old settings */
1704 config.phy_type = abilities.phy_type;
1705 config.link_speed = abilities.link_speed;
1706 config.eee_capability = abilities.eee_capability;
1707 config.eeer = abilities.eeer_val;
1708 config.low_power_ctrl = abilities.d3_lpan;
1709 status = i40e_aq_set_phy_config(hw, &config, NULL);
1710
1711 if (status)
1712 *aq_failures |= I40E_SET_FC_AQ_FAIL_SET;
1713 }
1714 /* Update the link info */
Catherine Sullivan0a862b42015-08-31 19:54:53 -04001715 status = i40e_update_link_info(hw);
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001716 if (status) {
1717 /* Wait a little bit (on 40G cards it sometimes takes a really
1718 * long time for link to come back from the atomic reset)
1719 * and try once more
1720 */
1721 msleep(1000);
Catherine Sullivan0a862b42015-08-31 19:54:53 -04001722 status = i40e_update_link_info(hw);
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001723 }
1724 if (status)
1725 *aq_failures |= I40E_SET_FC_AQ_FAIL_UPDATE;
1726
1727 return status;
1728}
1729
1730/**
Shannon Nelsonc9b9b0a2014-04-09 05:59:05 +00001731 * i40e_aq_clear_pxe_mode
1732 * @hw: pointer to the hw struct
1733 * @cmd_details: pointer to command details structure or NULL
1734 *
1735 * Tell the firmware that the driver is taking over from PXE
1736 **/
1737i40e_status i40e_aq_clear_pxe_mode(struct i40e_hw *hw,
1738 struct i40e_asq_cmd_details *cmd_details)
1739{
1740 i40e_status status;
1741 struct i40e_aq_desc desc;
1742 struct i40e_aqc_clear_pxe *cmd =
1743 (struct i40e_aqc_clear_pxe *)&desc.params.raw;
1744
1745 i40e_fill_default_direct_cmd_desc(&desc,
1746 i40e_aqc_opc_clear_pxe_mode);
1747
1748 cmd->rx_cnt = 0x2;
1749
1750 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1751
1752 wr32(hw, I40E_GLLAN_RCTL_0, 0x1);
1753
1754 return status;
1755}
1756
1757/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001758 * i40e_aq_set_link_restart_an
1759 * @hw: pointer to the hw struct
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001760 * @enable_link: if true: enable link, if false: disable link
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001761 * @cmd_details: pointer to command details structure or NULL
1762 *
1763 * Sets up the link and restarts the Auto-Negotiation over the link.
1764 **/
1765i40e_status i40e_aq_set_link_restart_an(struct i40e_hw *hw,
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001766 bool enable_link,
1767 struct i40e_asq_cmd_details *cmd_details)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001768{
1769 struct i40e_aq_desc desc;
1770 struct i40e_aqc_set_link_restart_an *cmd =
1771 (struct i40e_aqc_set_link_restart_an *)&desc.params.raw;
1772 i40e_status status;
1773
1774 i40e_fill_default_direct_cmd_desc(&desc,
1775 i40e_aqc_opc_set_link_restart_an);
1776
1777 cmd->command = I40E_AQ_PHY_RESTART_AN;
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001778 if (enable_link)
1779 cmd->command |= I40E_AQ_PHY_LINK_ENABLE;
1780 else
1781 cmd->command &= ~I40E_AQ_PHY_LINK_ENABLE;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001782
1783 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1784
1785 return status;
1786}
1787
1788/**
1789 * i40e_aq_get_link_info
1790 * @hw: pointer to the hw struct
1791 * @enable_lse: enable/disable LinkStatusEvent reporting
1792 * @link: pointer to link status structure - optional
1793 * @cmd_details: pointer to command details structure or NULL
1794 *
1795 * Returns the link status of the adapter.
1796 **/
1797i40e_status i40e_aq_get_link_info(struct i40e_hw *hw,
1798 bool enable_lse, struct i40e_link_status *link,
1799 struct i40e_asq_cmd_details *cmd_details)
1800{
1801 struct i40e_aq_desc desc;
1802 struct i40e_aqc_get_link_status *resp =
1803 (struct i40e_aqc_get_link_status *)&desc.params.raw;
1804 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
1805 i40e_status status;
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001806 bool tx_pause, rx_pause;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001807 u16 command_flags;
1808
1809 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_link_status);
1810
1811 if (enable_lse)
1812 command_flags = I40E_AQ_LSE_ENABLE;
1813 else
1814 command_flags = I40E_AQ_LSE_DISABLE;
1815 resp->command_flags = cpu_to_le16(command_flags);
1816
1817 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1818
1819 if (status)
1820 goto aq_get_link_info_exit;
1821
1822 /* save off old link status information */
Mitch Williamsc36bd4a72013-12-18 13:46:04 +00001823 hw->phy.link_info_old = *hw_link_info;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001824
1825 /* update link status */
1826 hw_link_info->phy_type = (enum i40e_aq_phy_type)resp->phy_type;
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001827 hw->phy.media_type = i40e_get_media_type(hw);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001828 hw_link_info->link_speed = (enum i40e_aq_link_speed)resp->link_speed;
1829 hw_link_info->link_info = resp->link_info;
1830 hw_link_info->an_info = resp->an_info;
1831 hw_link_info->ext_info = resp->ext_info;
Kamil Krawczyk639dc372013-11-20 10:03:07 +00001832 hw_link_info->loopback = resp->loopback;
Neerav Parikh6bb3f232014-04-01 07:11:56 +00001833 hw_link_info->max_frame_size = le16_to_cpu(resp->max_frame_size);
1834 hw_link_info->pacing = resp->config & I40E_AQ_CONFIG_PACING_MASK;
1835
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001836 /* update fc info */
1837 tx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_TX);
1838 rx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_RX);
1839 if (tx_pause & rx_pause)
1840 hw->fc.current_mode = I40E_FC_FULL;
1841 else if (tx_pause)
1842 hw->fc.current_mode = I40E_FC_TX_PAUSE;
1843 else if (rx_pause)
1844 hw->fc.current_mode = I40E_FC_RX_PAUSE;
1845 else
1846 hw->fc.current_mode = I40E_FC_NONE;
1847
Neerav Parikh6bb3f232014-04-01 07:11:56 +00001848 if (resp->config & I40E_AQ_CONFIG_CRC_ENA)
1849 hw_link_info->crc_enable = true;
1850 else
1851 hw_link_info->crc_enable = false;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001852
1853 if (resp->command_flags & cpu_to_le16(I40E_AQ_LSE_ENABLE))
1854 hw_link_info->lse_enable = true;
1855 else
1856 hw_link_info->lse_enable = false;
1857
Catherine Sullivan088c4ee2015-02-26 16:14:12 +00001858 if ((hw->aq.fw_maj_ver < 4 || (hw->aq.fw_maj_ver == 4 &&
1859 hw->aq.fw_min_ver < 40)) && hw_link_info->phy_type == 0xE)
1860 hw_link_info->phy_type = I40E_PHY_TYPE_10GBASE_SFPP_CU;
1861
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001862 /* save link status information */
1863 if (link)
Jesse Brandeburgd7595a22013-09-13 08:23:22 +00001864 *link = *hw_link_info;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001865
1866 /* flag cleared so helper functions don't call AQ again */
1867 hw->phy.get_link_info = false;
1868
1869aq_get_link_info_exit:
1870 return status;
1871}
1872
1873/**
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00001874 * i40e_aq_set_phy_int_mask
1875 * @hw: pointer to the hw struct
1876 * @mask: interrupt mask to be set
1877 * @cmd_details: pointer to command details structure or NULL
1878 *
1879 * Set link interrupt mask.
1880 **/
1881i40e_status i40e_aq_set_phy_int_mask(struct i40e_hw *hw,
1882 u16 mask,
1883 struct i40e_asq_cmd_details *cmd_details)
1884{
1885 struct i40e_aq_desc desc;
1886 struct i40e_aqc_set_phy_int_mask *cmd =
1887 (struct i40e_aqc_set_phy_int_mask *)&desc.params.raw;
1888 i40e_status status;
1889
1890 i40e_fill_default_direct_cmd_desc(&desc,
1891 i40e_aqc_opc_set_phy_int_mask);
1892
1893 cmd->event_mask = cpu_to_le16(mask);
1894
1895 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1896
1897 return status;
1898}
1899
1900/**
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001901 * i40e_aq_set_phy_debug
1902 * @hw: pointer to the hw struct
1903 * @cmd_flags: debug command flags
1904 * @cmd_details: pointer to command details structure or NULL
1905 *
1906 * Reset the external PHY.
1907 **/
Jesse Brandeburg61829022016-03-10 14:59:42 -08001908i40e_status i40e_aq_set_phy_debug(struct i40e_hw *hw, u8 cmd_flags,
1909 struct i40e_asq_cmd_details *cmd_details)
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001910{
1911 struct i40e_aq_desc desc;
1912 struct i40e_aqc_set_phy_debug *cmd =
1913 (struct i40e_aqc_set_phy_debug *)&desc.params.raw;
Jesse Brandeburg61829022016-03-10 14:59:42 -08001914 i40e_status status;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001915
1916 i40e_fill_default_direct_cmd_desc(&desc,
1917 i40e_aqc_opc_set_phy_debug);
1918
1919 cmd->command_flags = cmd_flags;
1920
1921 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1922
1923 return status;
1924}
1925
1926/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001927 * i40e_aq_add_vsi
1928 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00001929 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001930 * @cmd_details: pointer to command details structure or NULL
1931 *
1932 * Add a VSI context to the hardware.
1933**/
1934i40e_status i40e_aq_add_vsi(struct i40e_hw *hw,
1935 struct i40e_vsi_context *vsi_ctx,
1936 struct i40e_asq_cmd_details *cmd_details)
1937{
1938 struct i40e_aq_desc desc;
1939 struct i40e_aqc_add_get_update_vsi *cmd =
1940 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
1941 struct i40e_aqc_add_get_update_vsi_completion *resp =
1942 (struct i40e_aqc_add_get_update_vsi_completion *)
1943 &desc.params.raw;
1944 i40e_status status;
1945
1946 i40e_fill_default_direct_cmd_desc(&desc,
1947 i40e_aqc_opc_add_vsi);
1948
1949 cmd->uplink_seid = cpu_to_le16(vsi_ctx->uplink_seid);
1950 cmd->connection_type = vsi_ctx->connection_type;
1951 cmd->vf_id = vsi_ctx->vf_num;
1952 cmd->vsi_flags = cpu_to_le16(vsi_ctx->flags);
1953
1954 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001955
1956 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
1957 sizeof(vsi_ctx->info), cmd_details);
1958
1959 if (status)
1960 goto aq_add_vsi_exit;
1961
1962 vsi_ctx->seid = le16_to_cpu(resp->seid);
1963 vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
1964 vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
1965 vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
1966
1967aq_add_vsi_exit:
1968 return status;
1969}
1970
1971/**
Mitch Williamsfb70fab2016-05-16 10:26:31 -07001972 * i40e_aq_set_default_vsi
1973 * @hw: pointer to the hw struct
1974 * @seid: vsi number
1975 * @cmd_details: pointer to command details structure or NULL
1976 **/
1977i40e_status i40e_aq_set_default_vsi(struct i40e_hw *hw,
1978 u16 seid,
1979 struct i40e_asq_cmd_details *cmd_details)
1980{
1981 struct i40e_aq_desc desc;
1982 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
1983 (struct i40e_aqc_set_vsi_promiscuous_modes *)
1984 &desc.params.raw;
1985 i40e_status status;
1986
1987 i40e_fill_default_direct_cmd_desc(&desc,
1988 i40e_aqc_opc_set_vsi_promiscuous_modes);
1989
1990 cmd->promiscuous_flags = cpu_to_le16(I40E_AQC_SET_VSI_DEFAULT);
1991 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_DEFAULT);
1992 cmd->seid = cpu_to_le16(seid);
1993
1994 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1995
1996 return status;
1997}
1998
1999/**
2000 * i40e_aq_clear_default_vsi
2001 * @hw: pointer to the hw struct
2002 * @seid: vsi number
2003 * @cmd_details: pointer to command details structure or NULL
2004 **/
2005i40e_status i40e_aq_clear_default_vsi(struct i40e_hw *hw,
2006 u16 seid,
2007 struct i40e_asq_cmd_details *cmd_details)
2008{
2009 struct i40e_aq_desc desc;
2010 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2011 (struct i40e_aqc_set_vsi_promiscuous_modes *)
2012 &desc.params.raw;
2013 i40e_status status;
2014
2015 i40e_fill_default_direct_cmd_desc(&desc,
2016 i40e_aqc_opc_set_vsi_promiscuous_modes);
2017
2018 cmd->promiscuous_flags = cpu_to_le16(0);
2019 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_DEFAULT);
2020 cmd->seid = cpu_to_le16(seid);
2021
2022 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2023
2024 return status;
2025}
2026
2027/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002028 * i40e_aq_set_vsi_unicast_promiscuous
2029 * @hw: pointer to the hw struct
2030 * @seid: vsi number
2031 * @set: set unicast promiscuous enable/disable
2032 * @cmd_details: pointer to command details structure or NULL
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002033 * @rx_only_promisc: flag to decide if egress traffic gets mirrored in promisc
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002034 **/
2035i40e_status i40e_aq_set_vsi_unicast_promiscuous(struct i40e_hw *hw,
Mitch Williams885552a2013-12-21 05:44:41 +00002036 u16 seid, bool set,
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002037 struct i40e_asq_cmd_details *cmd_details,
2038 bool rx_only_promisc)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002039{
2040 struct i40e_aq_desc desc;
2041 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2042 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2043 i40e_status status;
2044 u16 flags = 0;
2045
2046 i40e_fill_default_direct_cmd_desc(&desc,
2047 i40e_aqc_opc_set_vsi_promiscuous_modes);
2048
Anjali Singhai Jain3b120082016-01-15 14:33:21 -08002049 if (set) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002050 flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002051 if (rx_only_promisc &&
2052 (((hw->aq.api_maj_ver == 1) && (hw->aq.api_min_ver >= 5)) ||
2053 (hw->aq.api_maj_ver > 1)))
Anjali Singhai Jain3b120082016-01-15 14:33:21 -08002054 flags |= I40E_AQC_SET_VSI_PROMISC_TX;
2055 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002056
2057 cmd->promiscuous_flags = cpu_to_le16(flags);
2058
2059 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
Anjali Singhai Jain3b120082016-01-15 14:33:21 -08002060 if (((hw->aq.api_maj_ver >= 1) && (hw->aq.api_min_ver >= 5)) ||
2061 (hw->aq.api_maj_ver > 1))
2062 cmd->valid_flags |= cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_TX);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002063
2064 cmd->seid = cpu_to_le16(seid);
2065 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2066
2067 return status;
2068}
2069
2070/**
2071 * i40e_aq_set_vsi_multicast_promiscuous
2072 * @hw: pointer to the hw struct
2073 * @seid: vsi number
2074 * @set: set multicast promiscuous enable/disable
2075 * @cmd_details: pointer to command details structure or NULL
2076 **/
2077i40e_status i40e_aq_set_vsi_multicast_promiscuous(struct i40e_hw *hw,
2078 u16 seid, bool set, struct i40e_asq_cmd_details *cmd_details)
2079{
2080 struct i40e_aq_desc desc;
2081 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2082 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2083 i40e_status status;
2084 u16 flags = 0;
2085
2086 i40e_fill_default_direct_cmd_desc(&desc,
2087 i40e_aqc_opc_set_vsi_promiscuous_modes);
2088
2089 if (set)
2090 flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
2091
2092 cmd->promiscuous_flags = cpu_to_le16(flags);
2093
2094 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
2095
2096 cmd->seid = cpu_to_le16(seid);
2097 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2098
2099 return status;
2100}
2101
2102/**
Greg Rose6c41a762016-04-12 08:30:50 -07002103 * i40e_aq_set_vsi_mc_promisc_on_vlan
2104 * @hw: pointer to the hw struct
2105 * @seid: vsi number
2106 * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
2107 * @vid: The VLAN tag filter - capture any multicast packet with this VLAN tag
2108 * @cmd_details: pointer to command details structure or NULL
2109 **/
2110enum i40e_status_code i40e_aq_set_vsi_mc_promisc_on_vlan(struct i40e_hw *hw,
2111 u16 seid, bool enable,
2112 u16 vid,
2113 struct i40e_asq_cmd_details *cmd_details)
2114{
2115 struct i40e_aq_desc desc;
2116 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2117 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2118 enum i40e_status_code status;
2119 u16 flags = 0;
2120
2121 i40e_fill_default_direct_cmd_desc(&desc,
2122 i40e_aqc_opc_set_vsi_promiscuous_modes);
2123
2124 if (enable)
2125 flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
2126
2127 cmd->promiscuous_flags = cpu_to_le16(flags);
2128 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
2129 cmd->seid = cpu_to_le16(seid);
2130 cmd->vlan_tag = cpu_to_le16(vid | I40E_AQC_SET_VSI_VLAN_VALID);
2131
2132 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2133
2134 return status;
2135}
2136
2137/**
2138 * i40e_aq_set_vsi_uc_promisc_on_vlan
2139 * @hw: pointer to the hw struct
2140 * @seid: vsi number
2141 * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
2142 * @vid: The VLAN tag filter - capture any unicast packet with this VLAN tag
2143 * @cmd_details: pointer to command details structure or NULL
2144 **/
2145enum i40e_status_code i40e_aq_set_vsi_uc_promisc_on_vlan(struct i40e_hw *hw,
2146 u16 seid, bool enable,
2147 u16 vid,
2148 struct i40e_asq_cmd_details *cmd_details)
2149{
2150 struct i40e_aq_desc desc;
2151 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2152 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2153 enum i40e_status_code status;
2154 u16 flags = 0;
2155
2156 i40e_fill_default_direct_cmd_desc(&desc,
2157 i40e_aqc_opc_set_vsi_promiscuous_modes);
2158
2159 if (enable)
2160 flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
2161
2162 cmd->promiscuous_flags = cpu_to_le16(flags);
2163 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
2164 cmd->seid = cpu_to_le16(seid);
2165 cmd->vlan_tag = cpu_to_le16(vid | I40E_AQC_SET_VSI_VLAN_VALID);
2166
2167 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2168
2169 return status;
2170}
2171
2172/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002173 * i40e_aq_set_vsi_broadcast
2174 * @hw: pointer to the hw struct
2175 * @seid: vsi number
2176 * @set_filter: true to set filter, false to clear filter
2177 * @cmd_details: pointer to command details structure or NULL
2178 *
2179 * Set or clear the broadcast promiscuous flag (filter) for a given VSI.
2180 **/
2181i40e_status i40e_aq_set_vsi_broadcast(struct i40e_hw *hw,
2182 u16 seid, bool set_filter,
2183 struct i40e_asq_cmd_details *cmd_details)
2184{
2185 struct i40e_aq_desc desc;
2186 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2187 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2188 i40e_status status;
2189
2190 i40e_fill_default_direct_cmd_desc(&desc,
2191 i40e_aqc_opc_set_vsi_promiscuous_modes);
2192
2193 if (set_filter)
2194 cmd->promiscuous_flags
2195 |= cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2196 else
2197 cmd->promiscuous_flags
2198 &= cpu_to_le16(~I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2199
2200 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2201 cmd->seid = cpu_to_le16(seid);
2202 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2203
2204 return status;
2205}
2206
2207/**
Kiran Patil7bd68752016-01-04 10:33:07 -08002208 * i40e_aq_set_vsi_vlan_promisc - control the VLAN promiscuous setting
2209 * @hw: pointer to the hw struct
2210 * @seid: vsi number
2211 * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
2212 * @cmd_details: pointer to command details structure or NULL
2213 **/
2214i40e_status i40e_aq_set_vsi_vlan_promisc(struct i40e_hw *hw,
2215 u16 seid, bool enable,
2216 struct i40e_asq_cmd_details *cmd_details)
2217{
2218 struct i40e_aq_desc desc;
2219 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2220 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2221 i40e_status status;
2222 u16 flags = 0;
2223
2224 i40e_fill_default_direct_cmd_desc(&desc,
2225 i40e_aqc_opc_set_vsi_promiscuous_modes);
2226 if (enable)
2227 flags |= I40E_AQC_SET_VSI_PROMISC_VLAN;
2228
2229 cmd->promiscuous_flags = cpu_to_le16(flags);
2230 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_VLAN);
2231 cmd->seid = cpu_to_le16(seid);
2232
2233 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2234
2235 return status;
2236}
2237
2238/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002239 * i40e_get_vsi_params - get VSI configuration info
2240 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00002241 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002242 * @cmd_details: pointer to command details structure or NULL
2243 **/
2244i40e_status i40e_aq_get_vsi_params(struct i40e_hw *hw,
2245 struct i40e_vsi_context *vsi_ctx,
2246 struct i40e_asq_cmd_details *cmd_details)
2247{
2248 struct i40e_aq_desc desc;
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002249 struct i40e_aqc_add_get_update_vsi *cmd =
2250 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002251 struct i40e_aqc_add_get_update_vsi_completion *resp =
2252 (struct i40e_aqc_add_get_update_vsi_completion *)
2253 &desc.params.raw;
2254 i40e_status status;
2255
2256 i40e_fill_default_direct_cmd_desc(&desc,
2257 i40e_aqc_opc_get_vsi_parameters);
2258
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002259 cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002260
2261 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002262
2263 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
2264 sizeof(vsi_ctx->info), NULL);
2265
2266 if (status)
2267 goto aq_get_vsi_params_exit;
2268
2269 vsi_ctx->seid = le16_to_cpu(resp->seid);
2270 vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
2271 vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
2272 vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
2273
2274aq_get_vsi_params_exit:
2275 return status;
2276}
2277
2278/**
2279 * i40e_aq_update_vsi_params
2280 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00002281 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002282 * @cmd_details: pointer to command details structure or NULL
2283 *
2284 * Update a VSI context.
2285 **/
2286i40e_status i40e_aq_update_vsi_params(struct i40e_hw *hw,
2287 struct i40e_vsi_context *vsi_ctx,
2288 struct i40e_asq_cmd_details *cmd_details)
2289{
2290 struct i40e_aq_desc desc;
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002291 struct i40e_aqc_add_get_update_vsi *cmd =
2292 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
Kevin Scottb6cacca2016-03-10 14:59:41 -08002293 struct i40e_aqc_add_get_update_vsi_completion *resp =
2294 (struct i40e_aqc_add_get_update_vsi_completion *)
2295 &desc.params.raw;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002296 i40e_status status;
2297
2298 i40e_fill_default_direct_cmd_desc(&desc,
2299 i40e_aqc_opc_update_vsi_parameters);
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002300 cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002301
2302 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002303
2304 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
2305 sizeof(vsi_ctx->info), cmd_details);
2306
Kevin Scottb6cacca2016-03-10 14:59:41 -08002307 vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
2308 vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
2309
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002310 return status;
2311}
2312
2313/**
2314 * i40e_aq_get_switch_config
2315 * @hw: pointer to the hardware structure
2316 * @buf: pointer to the result buffer
2317 * @buf_size: length of input buffer
2318 * @start_seid: seid to start for the report, 0 == beginning
2319 * @cmd_details: pointer to command details structure or NULL
2320 *
2321 * Fill the buf with switch configuration returned from AdminQ command
2322 **/
2323i40e_status i40e_aq_get_switch_config(struct i40e_hw *hw,
2324 struct i40e_aqc_get_switch_config_resp *buf,
2325 u16 buf_size, u16 *start_seid,
2326 struct i40e_asq_cmd_details *cmd_details)
2327{
2328 struct i40e_aq_desc desc;
2329 struct i40e_aqc_switch_seid *scfg =
2330 (struct i40e_aqc_switch_seid *)&desc.params.raw;
2331 i40e_status status;
2332
2333 i40e_fill_default_direct_cmd_desc(&desc,
2334 i40e_aqc_opc_get_switch_config);
2335 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
2336 if (buf_size > I40E_AQ_LARGE_BUF)
2337 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2338 scfg->seid = cpu_to_le16(*start_seid);
2339
2340 status = i40e_asq_send_command(hw, &desc, buf, buf_size, cmd_details);
2341 *start_seid = le16_to_cpu(scfg->seid);
2342
2343 return status;
2344}
2345
2346/**
Shannon Nelsonf3d58492016-05-03 15:13:11 -07002347 * i40e_aq_set_switch_config
2348 * @hw: pointer to the hardware structure
2349 * @flags: bit flag values to set
2350 * @valid_flags: which bit flags to set
2351 * @cmd_details: pointer to command details structure or NULL
2352 *
2353 * Set switch configuration bits
2354 **/
2355enum i40e_status_code i40e_aq_set_switch_config(struct i40e_hw *hw,
2356 u16 flags,
2357 u16 valid_flags,
2358 struct i40e_asq_cmd_details *cmd_details)
2359{
2360 struct i40e_aq_desc desc;
2361 struct i40e_aqc_set_switch_config *scfg =
2362 (struct i40e_aqc_set_switch_config *)&desc.params.raw;
2363 enum i40e_status_code status;
2364
2365 i40e_fill_default_direct_cmd_desc(&desc,
2366 i40e_aqc_opc_set_switch_config);
2367 scfg->flags = cpu_to_le16(flags);
2368 scfg->valid_flags = cpu_to_le16(valid_flags);
2369
2370 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2371
2372 return status;
2373}
2374
2375/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002376 * i40e_aq_get_firmware_version
2377 * @hw: pointer to the hw struct
2378 * @fw_major_version: firmware major version
2379 * @fw_minor_version: firmware minor version
Shannon Nelson7edf8102015-02-24 06:58:41 +00002380 * @fw_build: firmware build number
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002381 * @api_major_version: major queue version
2382 * @api_minor_version: minor queue version
2383 * @cmd_details: pointer to command details structure or NULL
2384 *
2385 * Get the firmware version from the admin queue commands
2386 **/
2387i40e_status i40e_aq_get_firmware_version(struct i40e_hw *hw,
2388 u16 *fw_major_version, u16 *fw_minor_version,
Shannon Nelson7edf8102015-02-24 06:58:41 +00002389 u32 *fw_build,
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002390 u16 *api_major_version, u16 *api_minor_version,
2391 struct i40e_asq_cmd_details *cmd_details)
2392{
2393 struct i40e_aq_desc desc;
2394 struct i40e_aqc_get_version *resp =
2395 (struct i40e_aqc_get_version *)&desc.params.raw;
2396 i40e_status status;
2397
2398 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_version);
2399
2400 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2401
2402 if (!status) {
Shannon Nelson7edf8102015-02-24 06:58:41 +00002403 if (fw_major_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002404 *fw_major_version = le16_to_cpu(resp->fw_major);
Shannon Nelson7edf8102015-02-24 06:58:41 +00002405 if (fw_minor_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002406 *fw_minor_version = le16_to_cpu(resp->fw_minor);
Shannon Nelson7edf8102015-02-24 06:58:41 +00002407 if (fw_build)
2408 *fw_build = le32_to_cpu(resp->fw_build);
2409 if (api_major_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002410 *api_major_version = le16_to_cpu(resp->api_major);
Shannon Nelson7edf8102015-02-24 06:58:41 +00002411 if (api_minor_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002412 *api_minor_version = le16_to_cpu(resp->api_minor);
2413 }
2414
2415 return status;
2416}
2417
2418/**
2419 * i40e_aq_send_driver_version
2420 * @hw: pointer to the hw struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002421 * @dv: driver's major, minor version
2422 * @cmd_details: pointer to command details structure or NULL
2423 *
2424 * Send the driver version to the firmware
2425 **/
2426i40e_status i40e_aq_send_driver_version(struct i40e_hw *hw,
2427 struct i40e_driver_version *dv,
2428 struct i40e_asq_cmd_details *cmd_details)
2429{
2430 struct i40e_aq_desc desc;
2431 struct i40e_aqc_driver_version *cmd =
2432 (struct i40e_aqc_driver_version *)&desc.params.raw;
2433 i40e_status status;
Kevin Scott9d2f98e2014-04-01 07:11:52 +00002434 u16 len;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002435
2436 if (dv == NULL)
2437 return I40E_ERR_PARAM;
2438
2439 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_driver_version);
2440
Kevin Scott3b38cd12015-02-06 08:52:18 +00002441 desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002442 cmd->driver_major_ver = dv->major_version;
2443 cmd->driver_minor_ver = dv->minor_version;
2444 cmd->driver_build_ver = dv->build_version;
2445 cmd->driver_subbuild_ver = dv->subbuild_version;
Shannon Nelsond2466012014-04-01 07:11:45 +00002446
2447 len = 0;
2448 while (len < sizeof(dv->driver_string) &&
2449 (dv->driver_string[len] < 0x80) &&
2450 dv->driver_string[len])
2451 len++;
2452 status = i40e_asq_send_command(hw, &desc, dv->driver_string,
2453 len, cmd_details);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002454
2455 return status;
2456}
2457
2458/**
2459 * i40e_get_link_status - get status of the HW network link
2460 * @hw: pointer to the hw struct
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002461 * @link_up: pointer to bool (true/false = linkup/linkdown)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002462 *
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002463 * Variable link_up true if link is up, false if link is down.
2464 * The variable link_up is invalid if returned value of status != 0
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002465 *
2466 * Side effect: LinkStatusEvent reporting becomes enabled
2467 **/
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002468i40e_status i40e_get_link_status(struct i40e_hw *hw, bool *link_up)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002469{
2470 i40e_status status = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002471
2472 if (hw->phy.get_link_info) {
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002473 status = i40e_update_link_info(hw);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002474
2475 if (status)
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002476 i40e_debug(hw, I40E_DEBUG_LINK, "get link failed: status %d\n",
2477 status);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002478 }
2479
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002480 *link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002481
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002482 return status;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002483}
2484
2485/**
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002486 * i40e_updatelink_status - update status of the HW network link
2487 * @hw: pointer to the hw struct
2488 **/
2489i40e_status i40e_update_link_info(struct i40e_hw *hw)
2490{
2491 struct i40e_aq_get_phy_abilities_resp abilities;
2492 i40e_status status = 0;
2493
2494 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
2495 if (status)
2496 return status;
2497
Carolyn Wyborny8589af72015-09-28 14:16:56 -04002498 if (hw->phy.link_info.link_info & I40E_AQ_MEDIA_AVAILABLE) {
2499 status = i40e_aq_get_phy_capabilities(hw, false, false,
2500 &abilities, NULL);
2501 if (status)
2502 return status;
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002503
Carolyn Wyborny8589af72015-09-28 14:16:56 -04002504 memcpy(hw->phy.link_info.module_type, &abilities.module_type,
2505 sizeof(hw->phy.link_info.module_type));
2506 }
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002507
2508 return status;
2509}
2510
2511/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002512 * i40e_aq_add_veb - Insert a VEB between the VSI and the MAC
2513 * @hw: pointer to the hw struct
2514 * @uplink_seid: the MAC or other gizmo SEID
2515 * @downlink_seid: the VSI SEID
2516 * @enabled_tc: bitmap of TCs to be enabled
2517 * @default_port: true for default port VSI, false for control port
2518 * @veb_seid: pointer to where to put the resulting VEB SEID
Shannon Nelson8a187f42016-01-13 16:51:41 -08002519 * @enable_stats: true to turn on VEB stats
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002520 * @cmd_details: pointer to command details structure or NULL
2521 *
2522 * This asks the FW to add a VEB between the uplink and downlink
2523 * elements. If the uplink SEID is 0, this will be a floating VEB.
2524 **/
2525i40e_status i40e_aq_add_veb(struct i40e_hw *hw, u16 uplink_seid,
2526 u16 downlink_seid, u8 enabled_tc,
Shannon Nelson8a187f42016-01-13 16:51:41 -08002527 bool default_port, u16 *veb_seid,
2528 bool enable_stats,
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002529 struct i40e_asq_cmd_details *cmd_details)
2530{
2531 struct i40e_aq_desc desc;
2532 struct i40e_aqc_add_veb *cmd =
2533 (struct i40e_aqc_add_veb *)&desc.params.raw;
2534 struct i40e_aqc_add_veb_completion *resp =
2535 (struct i40e_aqc_add_veb_completion *)&desc.params.raw;
2536 i40e_status status;
2537 u16 veb_flags = 0;
2538
2539 /* SEIDs need to either both be set or both be 0 for floating VEB */
2540 if (!!uplink_seid != !!downlink_seid)
2541 return I40E_ERR_PARAM;
2542
2543 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_veb);
2544
2545 cmd->uplink_seid = cpu_to_le16(uplink_seid);
2546 cmd->downlink_seid = cpu_to_le16(downlink_seid);
2547 cmd->enable_tcs = enabled_tc;
2548 if (!uplink_seid)
2549 veb_flags |= I40E_AQC_ADD_VEB_FLOATING;
2550 if (default_port)
2551 veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DEFAULT;
2552 else
2553 veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DATA;
Kevin Scotte1c51b952013-11-20 10:02:51 +00002554
Shannon Nelson8a187f42016-01-13 16:51:41 -08002555 /* reverse logic here: set the bitflag to disable the stats */
2556 if (!enable_stats)
2557 veb_flags |= I40E_AQC_ADD_VEB_ENABLE_DISABLE_STATS;
Kevin Scotte1c51b952013-11-20 10:02:51 +00002558
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002559 cmd->veb_flags = cpu_to_le16(veb_flags);
2560
2561 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2562
2563 if (!status && veb_seid)
2564 *veb_seid = le16_to_cpu(resp->veb_seid);
2565
2566 return status;
2567}
2568
2569/**
2570 * i40e_aq_get_veb_parameters - Retrieve VEB parameters
2571 * @hw: pointer to the hw struct
2572 * @veb_seid: the SEID of the VEB to query
2573 * @switch_id: the uplink switch id
Jeff Kirsher98d44382013-12-21 05:44:42 +00002574 * @floating: set to true if the VEB is floating
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002575 * @statistic_index: index of the stats counter block for this VEB
2576 * @vebs_used: number of VEB's used by function
Jeff Kirsher98d44382013-12-21 05:44:42 +00002577 * @vebs_free: total VEB's not reserved by any function
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002578 * @cmd_details: pointer to command details structure or NULL
2579 *
2580 * This retrieves the parameters for a particular VEB, specified by
2581 * uplink_seid, and returns them to the caller.
2582 **/
2583i40e_status i40e_aq_get_veb_parameters(struct i40e_hw *hw,
2584 u16 veb_seid, u16 *switch_id,
2585 bool *floating, u16 *statistic_index,
2586 u16 *vebs_used, u16 *vebs_free,
2587 struct i40e_asq_cmd_details *cmd_details)
2588{
2589 struct i40e_aq_desc desc;
2590 struct i40e_aqc_get_veb_parameters_completion *cmd_resp =
2591 (struct i40e_aqc_get_veb_parameters_completion *)
2592 &desc.params.raw;
2593 i40e_status status;
2594
2595 if (veb_seid == 0)
2596 return I40E_ERR_PARAM;
2597
2598 i40e_fill_default_direct_cmd_desc(&desc,
2599 i40e_aqc_opc_get_veb_parameters);
2600 cmd_resp->seid = cpu_to_le16(veb_seid);
2601
2602 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2603 if (status)
2604 goto get_veb_exit;
2605
2606 if (switch_id)
2607 *switch_id = le16_to_cpu(cmd_resp->switch_id);
2608 if (statistic_index)
2609 *statistic_index = le16_to_cpu(cmd_resp->statistic_index);
2610 if (vebs_used)
2611 *vebs_used = le16_to_cpu(cmd_resp->vebs_used);
2612 if (vebs_free)
2613 *vebs_free = le16_to_cpu(cmd_resp->vebs_free);
2614 if (floating) {
2615 u16 flags = le16_to_cpu(cmd_resp->veb_flags);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04002616
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002617 if (flags & I40E_AQC_ADD_VEB_FLOATING)
2618 *floating = true;
2619 else
2620 *floating = false;
2621 }
2622
2623get_veb_exit:
2624 return status;
2625}
2626
2627/**
2628 * i40e_aq_add_macvlan
2629 * @hw: pointer to the hw struct
2630 * @seid: VSI for the mac address
2631 * @mv_list: list of macvlans to be added
2632 * @count: length of the list
2633 * @cmd_details: pointer to command details structure or NULL
2634 *
2635 * Add MAC/VLAN addresses to the HW filtering
2636 **/
2637i40e_status i40e_aq_add_macvlan(struct i40e_hw *hw, u16 seid,
2638 struct i40e_aqc_add_macvlan_element_data *mv_list,
2639 u16 count, struct i40e_asq_cmd_details *cmd_details)
2640{
2641 struct i40e_aq_desc desc;
2642 struct i40e_aqc_macvlan *cmd =
2643 (struct i40e_aqc_macvlan *)&desc.params.raw;
2644 i40e_status status;
2645 u16 buf_size;
Shannon Nelson67be6eb2016-01-13 16:51:40 -08002646 int i;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002647
2648 if (count == 0 || !mv_list || !hw)
2649 return I40E_ERR_PARAM;
2650
Shannon Nelson1efc80e2015-02-27 09:18:30 +00002651 buf_size = count * sizeof(*mv_list);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002652
2653 /* prep the rest of the request */
2654 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_macvlan);
2655 cmd->num_addresses = cpu_to_le16(count);
2656 cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
2657 cmd->seid[1] = 0;
2658 cmd->seid[2] = 0;
2659
Shannon Nelson67be6eb2016-01-13 16:51:40 -08002660 for (i = 0; i < count; i++)
2661 if (is_multicast_ether_addr(mv_list[i].mac_addr))
2662 mv_list[i].flags |=
2663 cpu_to_le16(I40E_AQC_MACVLAN_ADD_USE_SHARED_MAC);
2664
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002665 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
2666 if (buf_size > I40E_AQ_LARGE_BUF)
2667 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2668
2669 status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
Shannon Nelson67be6eb2016-01-13 16:51:40 -08002670 cmd_details);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002671
2672 return status;
2673}
2674
2675/**
2676 * i40e_aq_remove_macvlan
2677 * @hw: pointer to the hw struct
2678 * @seid: VSI for the mac address
2679 * @mv_list: list of macvlans to be removed
2680 * @count: length of the list
2681 * @cmd_details: pointer to command details structure or NULL
2682 *
2683 * Remove MAC/VLAN addresses from the HW filtering
2684 **/
2685i40e_status i40e_aq_remove_macvlan(struct i40e_hw *hw, u16 seid,
2686 struct i40e_aqc_remove_macvlan_element_data *mv_list,
2687 u16 count, struct i40e_asq_cmd_details *cmd_details)
2688{
2689 struct i40e_aq_desc desc;
2690 struct i40e_aqc_macvlan *cmd =
2691 (struct i40e_aqc_macvlan *)&desc.params.raw;
2692 i40e_status status;
2693 u16 buf_size;
2694
2695 if (count == 0 || !mv_list || !hw)
2696 return I40E_ERR_PARAM;
2697
Shannon Nelson1efc80e2015-02-27 09:18:30 +00002698 buf_size = count * sizeof(*mv_list);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002699
2700 /* prep the rest of the request */
2701 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_macvlan);
2702 cmd->num_addresses = cpu_to_le16(count);
2703 cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
2704 cmd->seid[1] = 0;
2705 cmd->seid[2] = 0;
2706
2707 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
2708 if (buf_size > I40E_AQ_LARGE_BUF)
2709 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2710
2711 status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
2712 cmd_details);
2713
2714 return status;
2715}
2716
2717/**
Kiran Patil7bd68752016-01-04 10:33:07 -08002718 * i40e_mirrorrule_op - Internal helper function to add/delete mirror rule
2719 * @hw: pointer to the hw struct
2720 * @opcode: AQ opcode for add or delete mirror rule
2721 * @sw_seid: Switch SEID (to which rule refers)
2722 * @rule_type: Rule Type (ingress/egress/VLAN)
2723 * @id: Destination VSI SEID or Rule ID
2724 * @count: length of the list
2725 * @mr_list: list of mirrored VSI SEIDs or VLAN IDs
2726 * @cmd_details: pointer to command details structure or NULL
2727 * @rule_id: Rule ID returned from FW
2728 * @rule_used: Number of rules used in internal switch
2729 * @rule_free: Number of rules free in internal switch
2730 *
2731 * Add/Delete a mirror rule to a specific switch. Mirror rules are supported for
2732 * VEBs/VEPA elements only
2733 **/
2734static i40e_status i40e_mirrorrule_op(struct i40e_hw *hw,
2735 u16 opcode, u16 sw_seid, u16 rule_type, u16 id,
2736 u16 count, __le16 *mr_list,
2737 struct i40e_asq_cmd_details *cmd_details,
2738 u16 *rule_id, u16 *rules_used, u16 *rules_free)
2739{
2740 struct i40e_aq_desc desc;
2741 struct i40e_aqc_add_delete_mirror_rule *cmd =
2742 (struct i40e_aqc_add_delete_mirror_rule *)&desc.params.raw;
2743 struct i40e_aqc_add_delete_mirror_rule_completion *resp =
2744 (struct i40e_aqc_add_delete_mirror_rule_completion *)&desc.params.raw;
2745 i40e_status status;
2746 u16 buf_size;
2747
2748 buf_size = count * sizeof(*mr_list);
2749
2750 /* prep the rest of the request */
2751 i40e_fill_default_direct_cmd_desc(&desc, opcode);
2752 cmd->seid = cpu_to_le16(sw_seid);
2753 cmd->rule_type = cpu_to_le16(rule_type &
2754 I40E_AQC_MIRROR_RULE_TYPE_MASK);
2755 cmd->num_entries = cpu_to_le16(count);
2756 /* Dest VSI for add, rule_id for delete */
2757 cmd->destination = cpu_to_le16(id);
2758 if (mr_list) {
2759 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
2760 I40E_AQ_FLAG_RD));
2761 if (buf_size > I40E_AQ_LARGE_BUF)
2762 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2763 }
2764
2765 status = i40e_asq_send_command(hw, &desc, mr_list, buf_size,
2766 cmd_details);
2767 if (!status ||
2768 hw->aq.asq_last_status == I40E_AQ_RC_ENOSPC) {
2769 if (rule_id)
2770 *rule_id = le16_to_cpu(resp->rule_id);
2771 if (rules_used)
2772 *rules_used = le16_to_cpu(resp->mirror_rules_used);
2773 if (rules_free)
2774 *rules_free = le16_to_cpu(resp->mirror_rules_free);
2775 }
2776 return status;
2777}
2778
2779/**
2780 * i40e_aq_add_mirrorrule - add a mirror rule
2781 * @hw: pointer to the hw struct
2782 * @sw_seid: Switch SEID (to which rule refers)
2783 * @rule_type: Rule Type (ingress/egress/VLAN)
2784 * @dest_vsi: SEID of VSI to which packets will be mirrored
2785 * @count: length of the list
2786 * @mr_list: list of mirrored VSI SEIDs or VLAN IDs
2787 * @cmd_details: pointer to command details structure or NULL
2788 * @rule_id: Rule ID returned from FW
2789 * @rule_used: Number of rules used in internal switch
2790 * @rule_free: Number of rules free in internal switch
2791 *
2792 * Add mirror rule. Mirror rules are supported for VEBs or VEPA elements only
2793 **/
2794i40e_status i40e_aq_add_mirrorrule(struct i40e_hw *hw, u16 sw_seid,
2795 u16 rule_type, u16 dest_vsi, u16 count, __le16 *mr_list,
2796 struct i40e_asq_cmd_details *cmd_details,
2797 u16 *rule_id, u16 *rules_used, u16 *rules_free)
2798{
2799 if (!(rule_type == I40E_AQC_MIRROR_RULE_TYPE_ALL_INGRESS ||
2800 rule_type == I40E_AQC_MIRROR_RULE_TYPE_ALL_EGRESS)) {
2801 if (count == 0 || !mr_list)
2802 return I40E_ERR_PARAM;
2803 }
2804
2805 return i40e_mirrorrule_op(hw, i40e_aqc_opc_add_mirror_rule, sw_seid,
2806 rule_type, dest_vsi, count, mr_list,
2807 cmd_details, rule_id, rules_used, rules_free);
2808}
2809
2810/**
2811 * i40e_aq_delete_mirrorrule - delete a mirror rule
2812 * @hw: pointer to the hw struct
2813 * @sw_seid: Switch SEID (to which rule refers)
2814 * @rule_type: Rule Type (ingress/egress/VLAN)
2815 * @count: length of the list
2816 * @rule_id: Rule ID that is returned in the receive desc as part of
2817 * add_mirrorrule.
2818 * @mr_list: list of mirrored VLAN IDs to be removed
2819 * @cmd_details: pointer to command details structure or NULL
2820 * @rule_used: Number of rules used in internal switch
2821 * @rule_free: Number of rules free in internal switch
2822 *
2823 * Delete a mirror rule. Mirror rules are supported for VEBs/VEPA elements only
2824 **/
2825i40e_status i40e_aq_delete_mirrorrule(struct i40e_hw *hw, u16 sw_seid,
2826 u16 rule_type, u16 rule_id, u16 count, __le16 *mr_list,
2827 struct i40e_asq_cmd_details *cmd_details,
2828 u16 *rules_used, u16 *rules_free)
2829{
2830 /* Rule ID has to be valid except rule_type: INGRESS VLAN mirroring */
Greg Rosedb077272016-04-12 08:30:48 -07002831 if (rule_type == I40E_AQC_MIRROR_RULE_TYPE_VLAN) {
Kiran Patil7bd68752016-01-04 10:33:07 -08002832 /* count and mr_list shall be valid for rule_type INGRESS VLAN
2833 * mirroring. For other rule_type, count and rule_type should
2834 * not matter.
2835 */
2836 if (count == 0 || !mr_list)
2837 return I40E_ERR_PARAM;
2838 }
2839
2840 return i40e_mirrorrule_op(hw, i40e_aqc_opc_delete_mirror_rule, sw_seid,
2841 rule_type, rule_id, count, mr_list,
2842 cmd_details, NULL, rules_used, rules_free);
2843}
2844
2845/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002846 * i40e_aq_send_msg_to_vf
2847 * @hw: pointer to the hardware structure
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00002848 * @vfid: VF id to send msg
Jeff Kirsher98d44382013-12-21 05:44:42 +00002849 * @v_opcode: opcodes for VF-PF communication
2850 * @v_retval: return error code
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002851 * @msg: pointer to the msg buffer
2852 * @msglen: msg length
2853 * @cmd_details: pointer to command details
2854 *
2855 * send msg to vf
2856 **/
2857i40e_status i40e_aq_send_msg_to_vf(struct i40e_hw *hw, u16 vfid,
2858 u32 v_opcode, u32 v_retval, u8 *msg, u16 msglen,
2859 struct i40e_asq_cmd_details *cmd_details)
2860{
2861 struct i40e_aq_desc desc;
2862 struct i40e_aqc_pf_vf_message *cmd =
2863 (struct i40e_aqc_pf_vf_message *)&desc.params.raw;
2864 i40e_status status;
2865
2866 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_vf);
2867 cmd->id = cpu_to_le32(vfid);
2868 desc.cookie_high = cpu_to_le32(v_opcode);
2869 desc.cookie_low = cpu_to_le32(v_retval);
2870 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_SI);
2871 if (msglen) {
2872 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
2873 I40E_AQ_FLAG_RD));
2874 if (msglen > I40E_AQ_LARGE_BUF)
2875 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2876 desc.datalen = cpu_to_le16(msglen);
2877 }
2878 status = i40e_asq_send_command(hw, &desc, msg, msglen, cmd_details);
2879
2880 return status;
2881}
2882
2883/**
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002884 * i40e_aq_debug_read_register
2885 * @hw: pointer to the hw struct
2886 * @reg_addr: register address
2887 * @reg_val: register value
2888 * @cmd_details: pointer to command details structure or NULL
2889 *
2890 * Read the register using the admin queue commands
2891 **/
2892i40e_status i40e_aq_debug_read_register(struct i40e_hw *hw,
Jesse Brandeburg7b115dd2015-02-27 09:15:23 +00002893 u32 reg_addr, u64 *reg_val,
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002894 struct i40e_asq_cmd_details *cmd_details)
2895{
2896 struct i40e_aq_desc desc;
2897 struct i40e_aqc_debug_reg_read_write *cmd_resp =
2898 (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
2899 i40e_status status;
2900
2901 if (reg_val == NULL)
2902 return I40E_ERR_PARAM;
2903
Jesse Brandeburg7b115dd2015-02-27 09:15:23 +00002904 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_read_reg);
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002905
2906 cmd_resp->address = cpu_to_le32(reg_addr);
2907
2908 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2909
2910 if (!status) {
Jesse Brandeburg7b115dd2015-02-27 09:15:23 +00002911 *reg_val = ((u64)le32_to_cpu(cmd_resp->value_high) << 32) |
2912 (u64)le32_to_cpu(cmd_resp->value_low);
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002913 }
2914
2915 return status;
2916}
2917
2918/**
Shannon Nelson53db45c2014-08-01 13:27:05 -07002919 * i40e_aq_debug_write_register
2920 * @hw: pointer to the hw struct
2921 * @reg_addr: register address
2922 * @reg_val: register value
2923 * @cmd_details: pointer to command details structure or NULL
2924 *
2925 * Write to a register using the admin queue commands
2926 **/
2927i40e_status i40e_aq_debug_write_register(struct i40e_hw *hw,
2928 u32 reg_addr, u64 reg_val,
2929 struct i40e_asq_cmd_details *cmd_details)
2930{
2931 struct i40e_aq_desc desc;
2932 struct i40e_aqc_debug_reg_read_write *cmd =
2933 (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
2934 i40e_status status;
2935
2936 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_write_reg);
2937
2938 cmd->address = cpu_to_le32(reg_addr);
2939 cmd->value_high = cpu_to_le32((u32)(reg_val >> 32));
2940 cmd->value_low = cpu_to_le32((u32)(reg_val & 0xFFFFFFFF));
2941
2942 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2943
2944 return status;
2945}
2946
2947/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002948 * i40e_aq_request_resource
2949 * @hw: pointer to the hw struct
2950 * @resource: resource id
2951 * @access: access type
2952 * @sdp_number: resource number
2953 * @timeout: the maximum time in ms that the driver may hold the resource
2954 * @cmd_details: pointer to command details structure or NULL
2955 *
2956 * requests common resource using the admin queue commands
2957 **/
2958i40e_status i40e_aq_request_resource(struct i40e_hw *hw,
2959 enum i40e_aq_resources_ids resource,
2960 enum i40e_aq_resource_access_type access,
2961 u8 sdp_number, u64 *timeout,
2962 struct i40e_asq_cmd_details *cmd_details)
2963{
2964 struct i40e_aq_desc desc;
2965 struct i40e_aqc_request_resource *cmd_resp =
2966 (struct i40e_aqc_request_resource *)&desc.params.raw;
2967 i40e_status status;
2968
2969 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_request_resource);
2970
2971 cmd_resp->resource_id = cpu_to_le16(resource);
2972 cmd_resp->access_type = cpu_to_le16(access);
2973 cmd_resp->resource_number = cpu_to_le32(sdp_number);
2974
2975 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2976 /* The completion specifies the maximum time in ms that the driver
2977 * may hold the resource in the Timeout field.
2978 * If the resource is held by someone else, the command completes with
2979 * busy return value and the timeout field indicates the maximum time
2980 * the current owner of the resource has to free it.
2981 */
2982 if (!status || hw->aq.asq_last_status == I40E_AQ_RC_EBUSY)
2983 *timeout = le32_to_cpu(cmd_resp->timeout);
2984
2985 return status;
2986}
2987
2988/**
2989 * i40e_aq_release_resource
2990 * @hw: pointer to the hw struct
2991 * @resource: resource id
2992 * @sdp_number: resource number
2993 * @cmd_details: pointer to command details structure or NULL
2994 *
2995 * release common resource using the admin queue commands
2996 **/
2997i40e_status i40e_aq_release_resource(struct i40e_hw *hw,
2998 enum i40e_aq_resources_ids resource,
2999 u8 sdp_number,
3000 struct i40e_asq_cmd_details *cmd_details)
3001{
3002 struct i40e_aq_desc desc;
3003 struct i40e_aqc_request_resource *cmd =
3004 (struct i40e_aqc_request_resource *)&desc.params.raw;
3005 i40e_status status;
3006
3007 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_release_resource);
3008
3009 cmd->resource_id = cpu_to_le16(resource);
3010 cmd->resource_number = cpu_to_le32(sdp_number);
3011
3012 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3013
3014 return status;
3015}
3016
3017/**
3018 * i40e_aq_read_nvm
3019 * @hw: pointer to the hw struct
3020 * @module_pointer: module pointer location in words from the NVM beginning
3021 * @offset: byte offset from the module beginning
3022 * @length: length of the section to be read (in bytes from the offset)
3023 * @data: command buffer (size [bytes] = length)
3024 * @last_command: tells if this is the last command in a series
3025 * @cmd_details: pointer to command details structure or NULL
3026 *
3027 * Read the NVM using the admin queue commands
3028 **/
3029i40e_status i40e_aq_read_nvm(struct i40e_hw *hw, u8 module_pointer,
3030 u32 offset, u16 length, void *data,
3031 bool last_command,
3032 struct i40e_asq_cmd_details *cmd_details)
3033{
3034 struct i40e_aq_desc desc;
3035 struct i40e_aqc_nvm_update *cmd =
3036 (struct i40e_aqc_nvm_update *)&desc.params.raw;
3037 i40e_status status;
3038
3039 /* In offset the highest byte must be zeroed. */
3040 if (offset & 0xFF000000) {
3041 status = I40E_ERR_PARAM;
3042 goto i40e_aq_read_nvm_exit;
3043 }
3044
3045 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_read);
3046
3047 /* If this is the last command in a series, set the proper flag. */
3048 if (last_command)
3049 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
3050 cmd->module_pointer = module_pointer;
3051 cmd->offset = cpu_to_le32(offset);
3052 cmd->length = cpu_to_le16(length);
3053
3054 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3055 if (length > I40E_AQ_LARGE_BUF)
3056 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3057
3058 status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
3059
3060i40e_aq_read_nvm_exit:
3061 return status;
3062}
3063
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003064/**
3065 * i40e_aq_erase_nvm
3066 * @hw: pointer to the hw struct
3067 * @module_pointer: module pointer location in words from the NVM beginning
3068 * @offset: offset in the module (expressed in 4 KB from module's beginning)
3069 * @length: length of the section to be erased (expressed in 4 KB)
3070 * @last_command: tells if this is the last command in a series
3071 * @cmd_details: pointer to command details structure or NULL
3072 *
3073 * Erase the NVM sector using the admin queue commands
3074 **/
3075i40e_status i40e_aq_erase_nvm(struct i40e_hw *hw, u8 module_pointer,
3076 u32 offset, u16 length, bool last_command,
3077 struct i40e_asq_cmd_details *cmd_details)
3078{
3079 struct i40e_aq_desc desc;
3080 struct i40e_aqc_nvm_update *cmd =
3081 (struct i40e_aqc_nvm_update *)&desc.params.raw;
3082 i40e_status status;
3083
3084 /* In offset the highest byte must be zeroed. */
3085 if (offset & 0xFF000000) {
3086 status = I40E_ERR_PARAM;
3087 goto i40e_aq_erase_nvm_exit;
3088 }
3089
3090 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_erase);
3091
3092 /* If this is the last command in a series, set the proper flag. */
3093 if (last_command)
3094 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
3095 cmd->module_pointer = module_pointer;
3096 cmd->offset = cpu_to_le32(offset);
3097 cmd->length = cpu_to_le16(length);
3098
3099 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3100
3101i40e_aq_erase_nvm_exit:
3102 return status;
3103}
3104
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003105/**
3106 * i40e_parse_discover_capabilities
3107 * @hw: pointer to the hw struct
3108 * @buff: pointer to a buffer containing device/function capability records
3109 * @cap_count: number of capability records in the list
3110 * @list_type_opc: type of capabilities list to parse
3111 *
3112 * Parse the device/function capabilities list.
3113 **/
3114static void i40e_parse_discover_capabilities(struct i40e_hw *hw, void *buff,
3115 u32 cap_count,
3116 enum i40e_admin_queue_opc list_type_opc)
3117{
3118 struct i40e_aqc_list_capabilities_element_resp *cap;
Shannon Nelson9fee9db2014-12-11 07:06:30 +00003119 u32 valid_functions, num_functions;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003120 u32 number, logical_id, phys_id;
3121 struct i40e_hw_capabilities *p;
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003122 u8 major_rev;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003123 u32 i = 0;
3124 u16 id;
3125
3126 cap = (struct i40e_aqc_list_capabilities_element_resp *) buff;
3127
3128 if (list_type_opc == i40e_aqc_opc_list_dev_capabilities)
Joe Perchesb58f2f72014-03-25 04:30:32 +00003129 p = &hw->dev_caps;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003130 else if (list_type_opc == i40e_aqc_opc_list_func_capabilities)
Joe Perchesb58f2f72014-03-25 04:30:32 +00003131 p = &hw->func_caps;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003132 else
3133 return;
3134
3135 for (i = 0; i < cap_count; i++, cap++) {
3136 id = le16_to_cpu(cap->id);
3137 number = le32_to_cpu(cap->number);
3138 logical_id = le32_to_cpu(cap->logical_id);
3139 phys_id = le32_to_cpu(cap->phys_id);
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003140 major_rev = cap->major_rev;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003141
3142 switch (id) {
Shannon Nelson406e7342015-12-10 11:38:49 -08003143 case I40E_AQ_CAP_ID_SWITCH_MODE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003144 p->switch_mode = number;
3145 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003146 case I40E_AQ_CAP_ID_MNG_MODE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003147 p->management_mode = number;
3148 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003149 case I40E_AQ_CAP_ID_NPAR_ACTIVE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003150 p->npar_enable = number;
3151 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003152 case I40E_AQ_CAP_ID_OS2BMC_CAP:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003153 p->os2bmc = number;
3154 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003155 case I40E_AQ_CAP_ID_FUNCTIONS_VALID:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003156 p->valid_functions = number;
3157 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003158 case I40E_AQ_CAP_ID_SRIOV:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003159 if (number == 1)
3160 p->sr_iov_1_1 = true;
3161 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003162 case I40E_AQ_CAP_ID_VF:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003163 p->num_vfs = number;
3164 p->vf_base_id = logical_id;
3165 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003166 case I40E_AQ_CAP_ID_VMDQ:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003167 if (number == 1)
3168 p->vmdq = true;
3169 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003170 case I40E_AQ_CAP_ID_8021QBG:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003171 if (number == 1)
3172 p->evb_802_1_qbg = true;
3173 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003174 case I40E_AQ_CAP_ID_8021QBR:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003175 if (number == 1)
3176 p->evb_802_1_qbh = true;
3177 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003178 case I40E_AQ_CAP_ID_VSI:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003179 p->num_vsis = number;
3180 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003181 case I40E_AQ_CAP_ID_DCB:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003182 if (number == 1) {
3183 p->dcb = true;
3184 p->enabled_tcmap = logical_id;
3185 p->maxtc = phys_id;
3186 }
3187 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003188 case I40E_AQ_CAP_ID_FCOE:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003189 if (number == 1)
3190 p->fcoe = true;
3191 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003192 case I40E_AQ_CAP_ID_ISCSI:
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00003193 if (number == 1)
3194 p->iscsi = true;
3195 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003196 case I40E_AQ_CAP_ID_RSS:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003197 p->rss = true;
Carolyn Wybornye157ea32014-06-03 23:50:22 +00003198 p->rss_table_size = number;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003199 p->rss_table_entry_width = logical_id;
3200 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003201 case I40E_AQ_CAP_ID_RXQ:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003202 p->num_rx_qp = number;
3203 p->base_queue = phys_id;
3204 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003205 case I40E_AQ_CAP_ID_TXQ:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003206 p->num_tx_qp = number;
3207 p->base_queue = phys_id;
3208 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003209 case I40E_AQ_CAP_ID_MSIX:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003210 p->num_msix_vectors = number;
Deepthi Kavalur453e16e2016-04-01 03:56:01 -07003211 i40e_debug(hw, I40E_DEBUG_INIT,
3212 "HW Capability: MSIX vector count = %d\n",
3213 p->num_msix_vectors);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003214 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003215 case I40E_AQ_CAP_ID_VF_MSIX:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003216 p->num_msix_vectors_vf = number;
3217 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003218 case I40E_AQ_CAP_ID_FLEX10:
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003219 if (major_rev == 1) {
3220 if (number == 1) {
3221 p->flex10_enable = true;
3222 p->flex10_capable = true;
3223 }
3224 } else {
3225 /* Capability revision >= 2 */
3226 if (number & 1)
3227 p->flex10_enable = true;
3228 if (number & 2)
3229 p->flex10_capable = true;
3230 }
3231 p->flex10_mode = logical_id;
3232 p->flex10_status = phys_id;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003233 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003234 case I40E_AQ_CAP_ID_CEM:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003235 if (number == 1)
3236 p->mgmt_cem = true;
3237 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003238 case I40E_AQ_CAP_ID_IWARP:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003239 if (number == 1)
3240 p->iwarp = true;
3241 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003242 case I40E_AQ_CAP_ID_LED:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003243 if (phys_id < I40E_HW_CAP_MAX_GPIO)
3244 p->led[phys_id] = true;
3245 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003246 case I40E_AQ_CAP_ID_SDP:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003247 if (phys_id < I40E_HW_CAP_MAX_GPIO)
3248 p->sdp[phys_id] = true;
3249 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003250 case I40E_AQ_CAP_ID_MDIO:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003251 if (number == 1) {
3252 p->mdio_port_num = phys_id;
3253 p->mdio_port_mode = logical_id;
3254 }
3255 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003256 case I40E_AQ_CAP_ID_1588:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003257 if (number == 1)
3258 p->ieee_1588 = true;
3259 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003260 case I40E_AQ_CAP_ID_FLOW_DIRECTOR:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003261 p->fd = true;
3262 p->fd_filters_guaranteed = number;
3263 p->fd_filters_best_effort = logical_id;
3264 break;
Shannon Nelson406e7342015-12-10 11:38:49 -08003265 case I40E_AQ_CAP_ID_WSR_PROT:
Kevin Scott73b23402015-04-07 19:45:38 -04003266 p->wr_csr_prot = (u64)number;
3267 p->wr_csr_prot |= (u64)logical_id << 32;
3268 break;
Michal Kosiarz68a1c5a2016-04-12 08:30:46 -07003269 case I40E_AQ_CAP_ID_NVM_MGMT:
3270 if (number & I40E_NVM_MGMT_SEC_REV_DISABLED)
3271 p->sec_rev_disabled = true;
3272 if (number & I40E_NVM_MGMT_UPDATE_DISABLED)
3273 p->update_disabled = true;
3274 break;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003275 default:
3276 break;
3277 }
3278 }
3279
Vasu Devf18ae102015-04-07 19:45:36 -04003280 if (p->fcoe)
3281 i40e_debug(hw, I40E_DEBUG_ALL, "device is FCoE capable\n");
3282
Vasu Dev566bb852014-04-09 05:59:06 +00003283 /* Software override ensuring FCoE is disabled if npar or mfp
3284 * mode because it is not supported in these modes.
3285 */
Pawel Orlowskic78b9532015-04-22 19:34:06 -04003286 if (p->npar_enable || p->flex10_enable)
Vasu Dev566bb852014-04-09 05:59:06 +00003287 p->fcoe = false;
3288
Shannon Nelson9fee9db2014-12-11 07:06:30 +00003289 /* count the enabled ports (aka the "not disabled" ports) */
3290 hw->num_ports = 0;
3291 for (i = 0; i < 4; i++) {
3292 u32 port_cfg_reg = I40E_PRTGEN_CNF + (4 * i);
3293 u64 port_cfg = 0;
3294
3295 /* use AQ read to get the physical register offset instead
3296 * of the port relative offset
3297 */
3298 i40e_aq_debug_read_register(hw, port_cfg_reg, &port_cfg, NULL);
3299 if (!(port_cfg & I40E_PRTGEN_CNF_PORT_DIS_MASK))
3300 hw->num_ports++;
3301 }
3302
3303 valid_functions = p->valid_functions;
3304 num_functions = 0;
3305 while (valid_functions) {
3306 if (valid_functions & 1)
3307 num_functions++;
3308 valid_functions >>= 1;
3309 }
3310
3311 /* partition id is 1-based, and functions are evenly spread
3312 * across the ports as partitions
3313 */
3314 hw->partition_id = (hw->pf_id / hw->num_ports) + 1;
3315 hw->num_partitions = num_functions / hw->num_ports;
3316
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003317 /* additional HW specific goodies that might
3318 * someday be HW version specific
3319 */
3320 p->rx_buf_chain_len = I40E_MAX_CHAINED_RX_BUFFERS;
3321}
3322
3323/**
3324 * i40e_aq_discover_capabilities
3325 * @hw: pointer to the hw struct
3326 * @buff: a virtual buffer to hold the capabilities
3327 * @buff_size: Size of the virtual buffer
3328 * @data_size: Size of the returned data, or buff size needed if AQ err==ENOMEM
3329 * @list_type_opc: capabilities type to discover - pass in the command opcode
3330 * @cmd_details: pointer to command details structure or NULL
3331 *
3332 * Get the device capabilities descriptions from the firmware
3333 **/
3334i40e_status i40e_aq_discover_capabilities(struct i40e_hw *hw,
3335 void *buff, u16 buff_size, u16 *data_size,
3336 enum i40e_admin_queue_opc list_type_opc,
3337 struct i40e_asq_cmd_details *cmd_details)
3338{
3339 struct i40e_aqc_list_capabilites *cmd;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003340 struct i40e_aq_desc desc;
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08003341 i40e_status status = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003342
3343 cmd = (struct i40e_aqc_list_capabilites *)&desc.params.raw;
3344
3345 if (list_type_opc != i40e_aqc_opc_list_func_capabilities &&
3346 list_type_opc != i40e_aqc_opc_list_dev_capabilities) {
3347 status = I40E_ERR_PARAM;
3348 goto exit;
3349 }
3350
3351 i40e_fill_default_direct_cmd_desc(&desc, list_type_opc);
3352
3353 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3354 if (buff_size > I40E_AQ_LARGE_BUF)
3355 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3356
3357 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3358 *data_size = le16_to_cpu(desc.datalen);
3359
3360 if (status)
3361 goto exit;
3362
3363 i40e_parse_discover_capabilities(hw, buff, le32_to_cpu(cmd->count),
3364 list_type_opc);
3365
3366exit:
3367 return status;
3368}
3369
3370/**
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003371 * i40e_aq_update_nvm
3372 * @hw: pointer to the hw struct
3373 * @module_pointer: module pointer location in words from the NVM beginning
3374 * @offset: byte offset from the module beginning
3375 * @length: length of the section to be written (in bytes from the offset)
3376 * @data: command buffer (size [bytes] = length)
3377 * @last_command: tells if this is the last command in a series
3378 * @cmd_details: pointer to command details structure or NULL
3379 *
3380 * Update the NVM using the admin queue commands
3381 **/
3382i40e_status i40e_aq_update_nvm(struct i40e_hw *hw, u8 module_pointer,
3383 u32 offset, u16 length, void *data,
3384 bool last_command,
3385 struct i40e_asq_cmd_details *cmd_details)
3386{
3387 struct i40e_aq_desc desc;
3388 struct i40e_aqc_nvm_update *cmd =
3389 (struct i40e_aqc_nvm_update *)&desc.params.raw;
3390 i40e_status status;
3391
3392 /* In offset the highest byte must be zeroed. */
3393 if (offset & 0xFF000000) {
3394 status = I40E_ERR_PARAM;
3395 goto i40e_aq_update_nvm_exit;
3396 }
3397
3398 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_update);
3399
3400 /* If this is the last command in a series, set the proper flag. */
3401 if (last_command)
3402 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
3403 cmd->module_pointer = module_pointer;
3404 cmd->offset = cpu_to_le32(offset);
3405 cmd->length = cpu_to_le16(length);
3406
3407 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
3408 if (length > I40E_AQ_LARGE_BUF)
3409 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3410
3411 status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
3412
3413i40e_aq_update_nvm_exit:
3414 return status;
3415}
3416
3417/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003418 * i40e_aq_get_lldp_mib
3419 * @hw: pointer to the hw struct
3420 * @bridge_type: type of bridge requested
3421 * @mib_type: Local, Remote or both Local and Remote MIBs
3422 * @buff: pointer to a user supplied buffer to store the MIB block
3423 * @buff_size: size of the buffer (in bytes)
3424 * @local_len : length of the returned Local LLDP MIB
3425 * @remote_len: length of the returned Remote LLDP MIB
3426 * @cmd_details: pointer to command details structure or NULL
3427 *
3428 * Requests the complete LLDP MIB (entire packet).
3429 **/
3430i40e_status i40e_aq_get_lldp_mib(struct i40e_hw *hw, u8 bridge_type,
3431 u8 mib_type, void *buff, u16 buff_size,
3432 u16 *local_len, u16 *remote_len,
3433 struct i40e_asq_cmd_details *cmd_details)
3434{
3435 struct i40e_aq_desc desc;
3436 struct i40e_aqc_lldp_get_mib *cmd =
3437 (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
3438 struct i40e_aqc_lldp_get_mib *resp =
3439 (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
3440 i40e_status status;
3441
3442 if (buff_size == 0 || !buff)
3443 return I40E_ERR_PARAM;
3444
3445 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_get_mib);
3446 /* Indirect Command */
3447 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3448
3449 cmd->type = mib_type & I40E_AQ_LLDP_MIB_TYPE_MASK;
3450 cmd->type |= ((bridge_type << I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) &
3451 I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
3452
3453 desc.datalen = cpu_to_le16(buff_size);
3454
3455 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3456 if (buff_size > I40E_AQ_LARGE_BUF)
3457 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3458
3459 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3460 if (!status) {
3461 if (local_len != NULL)
3462 *local_len = le16_to_cpu(resp->local_len);
3463 if (remote_len != NULL)
3464 *remote_len = le16_to_cpu(resp->remote_len);
3465 }
3466
3467 return status;
3468}
3469
3470/**
3471 * i40e_aq_cfg_lldp_mib_change_event
3472 * @hw: pointer to the hw struct
3473 * @enable_update: Enable or Disable event posting
3474 * @cmd_details: pointer to command details structure or NULL
3475 *
3476 * Enable or Disable posting of an event on ARQ when LLDP MIB
3477 * associated with the interface changes
3478 **/
3479i40e_status i40e_aq_cfg_lldp_mib_change_event(struct i40e_hw *hw,
3480 bool enable_update,
3481 struct i40e_asq_cmd_details *cmd_details)
3482{
3483 struct i40e_aq_desc desc;
3484 struct i40e_aqc_lldp_update_mib *cmd =
3485 (struct i40e_aqc_lldp_update_mib *)&desc.params.raw;
3486 i40e_status status;
3487
3488 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_update_mib);
3489
3490 if (!enable_update)
3491 cmd->command |= I40E_AQ_LLDP_MIB_UPDATE_DISABLE;
3492
3493 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3494
3495 return status;
3496}
3497
3498/**
3499 * i40e_aq_stop_lldp
3500 * @hw: pointer to the hw struct
3501 * @shutdown_agent: True if LLDP Agent needs to be Shutdown
3502 * @cmd_details: pointer to command details structure or NULL
3503 *
3504 * Stop or Shutdown the embedded LLDP Agent
3505 **/
3506i40e_status i40e_aq_stop_lldp(struct i40e_hw *hw, bool shutdown_agent,
3507 struct i40e_asq_cmd_details *cmd_details)
3508{
3509 struct i40e_aq_desc desc;
3510 struct i40e_aqc_lldp_stop *cmd =
3511 (struct i40e_aqc_lldp_stop *)&desc.params.raw;
3512 i40e_status status;
3513
3514 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_stop);
3515
3516 if (shutdown_agent)
3517 cmd->command |= I40E_AQ_LLDP_AGENT_SHUTDOWN;
3518
3519 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3520
3521 return status;
3522}
3523
3524/**
3525 * i40e_aq_start_lldp
3526 * @hw: pointer to the hw struct
3527 * @cmd_details: pointer to command details structure or NULL
3528 *
3529 * Start the embedded LLDP Agent on all ports.
3530 **/
3531i40e_status i40e_aq_start_lldp(struct i40e_hw *hw,
3532 struct i40e_asq_cmd_details *cmd_details)
3533{
3534 struct i40e_aq_desc desc;
3535 struct i40e_aqc_lldp_start *cmd =
3536 (struct i40e_aqc_lldp_start *)&desc.params.raw;
3537 i40e_status status;
3538
3539 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_start);
3540
3541 cmd->command = I40E_AQ_LLDP_AGENT_START;
3542
3543 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3544
3545 return status;
3546}
3547
3548/**
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00003549 * i40e_aq_get_cee_dcb_config
3550 * @hw: pointer to the hw struct
3551 * @buff: response buffer that stores CEE operational configuration
3552 * @buff_size: size of the buffer passed
3553 * @cmd_details: pointer to command details structure or NULL
3554 *
3555 * Get CEE DCBX mode operational configuration from firmware
3556 **/
3557i40e_status i40e_aq_get_cee_dcb_config(struct i40e_hw *hw,
3558 void *buff, u16 buff_size,
3559 struct i40e_asq_cmd_details *cmd_details)
3560{
3561 struct i40e_aq_desc desc;
3562 i40e_status status;
3563
3564 if (buff_size == 0 || !buff)
3565 return I40E_ERR_PARAM;
3566
3567 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_cee_dcb_cfg);
3568
3569 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3570 status = i40e_asq_send_command(hw, &desc, (void *)buff, buff_size,
3571 cmd_details);
3572
3573 return status;
3574}
3575
3576/**
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003577 * i40e_aq_add_udp_tunnel
3578 * @hw: pointer to the hw struct
3579 * @udp_port: the UDP port to add
3580 * @header_len: length of the tunneling header length in DWords
3581 * @protocol_index: protocol index type
Jeff Kirsher98d44382013-12-21 05:44:42 +00003582 * @filter_index: pointer to filter index
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003583 * @cmd_details: pointer to command details structure or NULL
3584 **/
3585i40e_status i40e_aq_add_udp_tunnel(struct i40e_hw *hw,
Kevin Scottf4f94b92014-04-05 07:46:10 +00003586 u16 udp_port, u8 protocol_index,
3587 u8 *filter_index,
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003588 struct i40e_asq_cmd_details *cmd_details)
3589{
3590 struct i40e_aq_desc desc;
3591 struct i40e_aqc_add_udp_tunnel *cmd =
3592 (struct i40e_aqc_add_udp_tunnel *)&desc.params.raw;
3593 struct i40e_aqc_del_udp_tunnel_completion *resp =
3594 (struct i40e_aqc_del_udp_tunnel_completion *)&desc.params.raw;
3595 i40e_status status;
3596
3597 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_udp_tunnel);
3598
3599 cmd->udp_port = cpu_to_le16(udp_port);
Shannon Nelson981b7542013-12-11 08:17:11 +00003600 cmd->protocol_type = protocol_index;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003601
3602 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3603
Shannon Nelson65d13462015-02-21 06:45:28 +00003604 if (!status && filter_index)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003605 *filter_index = resp->index;
3606
3607 return status;
3608}
3609
3610/**
3611 * i40e_aq_del_udp_tunnel
3612 * @hw: pointer to the hw struct
3613 * @index: filter index
3614 * @cmd_details: pointer to command details structure or NULL
3615 **/
3616i40e_status i40e_aq_del_udp_tunnel(struct i40e_hw *hw, u8 index,
3617 struct i40e_asq_cmd_details *cmd_details)
3618{
3619 struct i40e_aq_desc desc;
3620 struct i40e_aqc_remove_udp_tunnel *cmd =
3621 (struct i40e_aqc_remove_udp_tunnel *)&desc.params.raw;
3622 i40e_status status;
3623
3624 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_del_udp_tunnel);
3625
3626 cmd->index = index;
3627
3628 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3629
3630 return status;
3631}
3632
3633/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003634 * i40e_aq_delete_element - Delete switch element
3635 * @hw: pointer to the hw struct
3636 * @seid: the SEID to delete from the switch
3637 * @cmd_details: pointer to command details structure or NULL
3638 *
3639 * This deletes a switch element from the switch.
3640 **/
3641i40e_status i40e_aq_delete_element(struct i40e_hw *hw, u16 seid,
3642 struct i40e_asq_cmd_details *cmd_details)
3643{
3644 struct i40e_aq_desc desc;
3645 struct i40e_aqc_switch_seid *cmd =
3646 (struct i40e_aqc_switch_seid *)&desc.params.raw;
3647 i40e_status status;
3648
3649 if (seid == 0)
3650 return I40E_ERR_PARAM;
3651
3652 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_delete_element);
3653
3654 cmd->seid = cpu_to_le16(seid);
3655
3656 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3657
3658 return status;
3659}
3660
3661/**
Neerav Parikhafb3ff02014-01-17 15:36:36 -08003662 * i40e_aq_dcb_updated - DCB Updated Command
3663 * @hw: pointer to the hw struct
3664 * @cmd_details: pointer to command details structure or NULL
3665 *
3666 * EMP will return when the shared RPB settings have been
3667 * recomputed and modified. The retval field in the descriptor
3668 * will be set to 0 when RPB is modified.
3669 **/
3670i40e_status i40e_aq_dcb_updated(struct i40e_hw *hw,
3671 struct i40e_asq_cmd_details *cmd_details)
3672{
3673 struct i40e_aq_desc desc;
3674 i40e_status status;
3675
3676 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_dcb_updated);
3677
3678 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3679
3680 return status;
3681}
3682
3683/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003684 * i40e_aq_tx_sched_cmd - generic Tx scheduler AQ command handler
3685 * @hw: pointer to the hw struct
3686 * @seid: seid for the physical port/switching component/vsi
3687 * @buff: Indirect buffer to hold data parameters and response
3688 * @buff_size: Indirect buffer size
3689 * @opcode: Tx scheduler AQ command opcode
3690 * @cmd_details: pointer to command details structure or NULL
3691 *
3692 * Generic command handler for Tx scheduler AQ commands
3693 **/
3694static i40e_status i40e_aq_tx_sched_cmd(struct i40e_hw *hw, u16 seid,
3695 void *buff, u16 buff_size,
3696 enum i40e_admin_queue_opc opcode,
3697 struct i40e_asq_cmd_details *cmd_details)
3698{
3699 struct i40e_aq_desc desc;
3700 struct i40e_aqc_tx_sched_ind *cmd =
3701 (struct i40e_aqc_tx_sched_ind *)&desc.params.raw;
3702 i40e_status status;
3703 bool cmd_param_flag = false;
3704
3705 switch (opcode) {
3706 case i40e_aqc_opc_configure_vsi_ets_sla_bw_limit:
3707 case i40e_aqc_opc_configure_vsi_tc_bw:
3708 case i40e_aqc_opc_enable_switching_comp_ets:
3709 case i40e_aqc_opc_modify_switching_comp_ets:
3710 case i40e_aqc_opc_disable_switching_comp_ets:
3711 case i40e_aqc_opc_configure_switching_comp_ets_bw_limit:
3712 case i40e_aqc_opc_configure_switching_comp_bw_config:
3713 cmd_param_flag = true;
3714 break;
3715 case i40e_aqc_opc_query_vsi_bw_config:
3716 case i40e_aqc_opc_query_vsi_ets_sla_config:
3717 case i40e_aqc_opc_query_switching_comp_ets_config:
3718 case i40e_aqc_opc_query_port_ets_config:
3719 case i40e_aqc_opc_query_switching_comp_bw_config:
3720 cmd_param_flag = false;
3721 break;
3722 default:
3723 return I40E_ERR_PARAM;
3724 }
3725
3726 i40e_fill_default_direct_cmd_desc(&desc, opcode);
3727
3728 /* Indirect command */
3729 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3730 if (cmd_param_flag)
3731 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
3732 if (buff_size > I40E_AQ_LARGE_BUF)
3733 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3734
3735 desc.datalen = cpu_to_le16(buff_size);
3736
3737 cmd->vsi_seid = cpu_to_le16(seid);
3738
3739 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3740
3741 return status;
3742}
3743
3744/**
Mitch Williams6b192892014-03-06 09:02:29 +00003745 * i40e_aq_config_vsi_bw_limit - Configure VSI BW Limit
3746 * @hw: pointer to the hw struct
3747 * @seid: VSI seid
3748 * @credit: BW limit credits (0 = disabled)
3749 * @max_credit: Max BW limit credits
3750 * @cmd_details: pointer to command details structure or NULL
3751 **/
3752i40e_status i40e_aq_config_vsi_bw_limit(struct i40e_hw *hw,
3753 u16 seid, u16 credit, u8 max_credit,
3754 struct i40e_asq_cmd_details *cmd_details)
3755{
3756 struct i40e_aq_desc desc;
3757 struct i40e_aqc_configure_vsi_bw_limit *cmd =
3758 (struct i40e_aqc_configure_vsi_bw_limit *)&desc.params.raw;
3759 i40e_status status;
3760
3761 i40e_fill_default_direct_cmd_desc(&desc,
3762 i40e_aqc_opc_configure_vsi_bw_limit);
3763
3764 cmd->vsi_seid = cpu_to_le16(seid);
3765 cmd->credit = cpu_to_le16(credit);
3766 cmd->max_credit = max_credit;
3767
3768 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3769
3770 return status;
3771}
3772
3773/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003774 * i40e_aq_config_vsi_tc_bw - Config VSI BW Allocation per TC
3775 * @hw: pointer to the hw struct
3776 * @seid: VSI seid
3777 * @bw_data: Buffer holding enabled TCs, relative TC BW limit/credits
3778 * @cmd_details: pointer to command details structure or NULL
3779 **/
3780i40e_status i40e_aq_config_vsi_tc_bw(struct i40e_hw *hw,
3781 u16 seid,
3782 struct i40e_aqc_configure_vsi_tc_bw_data *bw_data,
3783 struct i40e_asq_cmd_details *cmd_details)
3784{
3785 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3786 i40e_aqc_opc_configure_vsi_tc_bw,
3787 cmd_details);
3788}
3789
3790/**
Neerav Parikhafb3ff02014-01-17 15:36:36 -08003791 * i40e_aq_config_switch_comp_ets - Enable/Disable/Modify ETS on the port
3792 * @hw: pointer to the hw struct
3793 * @seid: seid of the switching component connected to Physical Port
3794 * @ets_data: Buffer holding ETS parameters
3795 * @cmd_details: pointer to command details structure or NULL
3796 **/
3797i40e_status i40e_aq_config_switch_comp_ets(struct i40e_hw *hw,
3798 u16 seid,
3799 struct i40e_aqc_configure_switching_comp_ets_data *ets_data,
3800 enum i40e_admin_queue_opc opcode,
3801 struct i40e_asq_cmd_details *cmd_details)
3802{
3803 return i40e_aq_tx_sched_cmd(hw, seid, (void *)ets_data,
3804 sizeof(*ets_data), opcode, cmd_details);
3805}
3806
3807/**
3808 * i40e_aq_config_switch_comp_bw_config - Config Switch comp BW Alloc per TC
3809 * @hw: pointer to the hw struct
3810 * @seid: seid of the switching component
3811 * @bw_data: Buffer holding enabled TCs, relative/absolute TC BW limit/credits
3812 * @cmd_details: pointer to command details structure or NULL
3813 **/
3814i40e_status i40e_aq_config_switch_comp_bw_config(struct i40e_hw *hw,
3815 u16 seid,
3816 struct i40e_aqc_configure_switching_comp_bw_config_data *bw_data,
3817 struct i40e_asq_cmd_details *cmd_details)
3818{
3819 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3820 i40e_aqc_opc_configure_switching_comp_bw_config,
3821 cmd_details);
3822}
3823
3824/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003825 * i40e_aq_query_vsi_bw_config - Query VSI BW configuration
3826 * @hw: pointer to the hw struct
3827 * @seid: seid of the VSI
3828 * @bw_data: Buffer to hold VSI BW configuration
3829 * @cmd_details: pointer to command details structure or NULL
3830 **/
3831i40e_status i40e_aq_query_vsi_bw_config(struct i40e_hw *hw,
3832 u16 seid,
3833 struct i40e_aqc_query_vsi_bw_config_resp *bw_data,
3834 struct i40e_asq_cmd_details *cmd_details)
3835{
3836 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3837 i40e_aqc_opc_query_vsi_bw_config,
3838 cmd_details);
3839}
3840
3841/**
3842 * i40e_aq_query_vsi_ets_sla_config - Query VSI BW configuration per TC
3843 * @hw: pointer to the hw struct
3844 * @seid: seid of the VSI
3845 * @bw_data: Buffer to hold VSI BW configuration per TC
3846 * @cmd_details: pointer to command details structure or NULL
3847 **/
3848i40e_status i40e_aq_query_vsi_ets_sla_config(struct i40e_hw *hw,
3849 u16 seid,
3850 struct i40e_aqc_query_vsi_ets_sla_config_resp *bw_data,
3851 struct i40e_asq_cmd_details *cmd_details)
3852{
3853 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3854 i40e_aqc_opc_query_vsi_ets_sla_config,
3855 cmd_details);
3856}
3857
3858/**
3859 * i40e_aq_query_switch_comp_ets_config - Query Switch comp BW config per TC
3860 * @hw: pointer to the hw struct
3861 * @seid: seid of the switching component
3862 * @bw_data: Buffer to hold switching component's per TC BW config
3863 * @cmd_details: pointer to command details structure or NULL
3864 **/
3865i40e_status i40e_aq_query_switch_comp_ets_config(struct i40e_hw *hw,
3866 u16 seid,
3867 struct i40e_aqc_query_switching_comp_ets_config_resp *bw_data,
3868 struct i40e_asq_cmd_details *cmd_details)
3869{
3870 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3871 i40e_aqc_opc_query_switching_comp_ets_config,
3872 cmd_details);
3873}
3874
3875/**
3876 * i40e_aq_query_port_ets_config - Query Physical Port ETS configuration
3877 * @hw: pointer to the hw struct
3878 * @seid: seid of the VSI or switching component connected to Physical Port
3879 * @bw_data: Buffer to hold current ETS configuration for the Physical Port
3880 * @cmd_details: pointer to command details structure or NULL
3881 **/
3882i40e_status i40e_aq_query_port_ets_config(struct i40e_hw *hw,
3883 u16 seid,
3884 struct i40e_aqc_query_port_ets_config_resp *bw_data,
3885 struct i40e_asq_cmd_details *cmd_details)
3886{
3887 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3888 i40e_aqc_opc_query_port_ets_config,
3889 cmd_details);
3890}
3891
3892/**
3893 * i40e_aq_query_switch_comp_bw_config - Query Switch comp BW configuration
3894 * @hw: pointer to the hw struct
3895 * @seid: seid of the switching component
3896 * @bw_data: Buffer to hold switching component's BW configuration
3897 * @cmd_details: pointer to command details structure or NULL
3898 **/
3899i40e_status i40e_aq_query_switch_comp_bw_config(struct i40e_hw *hw,
3900 u16 seid,
3901 struct i40e_aqc_query_switching_comp_bw_config_resp *bw_data,
3902 struct i40e_asq_cmd_details *cmd_details)
3903{
3904 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3905 i40e_aqc_opc_query_switching_comp_bw_config,
3906 cmd_details);
3907}
3908
3909/**
3910 * i40e_validate_filter_settings
3911 * @hw: pointer to the hardware structure
3912 * @settings: Filter control settings
3913 *
3914 * Check and validate the filter control settings passed.
3915 * The function checks for the valid filter/context sizes being
3916 * passed for FCoE and PE.
3917 *
3918 * Returns 0 if the values passed are valid and within
3919 * range else returns an error.
3920 **/
3921static i40e_status i40e_validate_filter_settings(struct i40e_hw *hw,
3922 struct i40e_filter_control_settings *settings)
3923{
3924 u32 fcoe_cntx_size, fcoe_filt_size;
3925 u32 pe_cntx_size, pe_filt_size;
Anjali Singhai Jain467d7292014-05-10 04:49:02 +00003926 u32 fcoe_fmax;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003927 u32 val;
3928
3929 /* Validate FCoE settings passed */
3930 switch (settings->fcoe_filt_num) {
3931 case I40E_HASH_FILTER_SIZE_1K:
3932 case I40E_HASH_FILTER_SIZE_2K:
3933 case I40E_HASH_FILTER_SIZE_4K:
3934 case I40E_HASH_FILTER_SIZE_8K:
3935 case I40E_HASH_FILTER_SIZE_16K:
3936 case I40E_HASH_FILTER_SIZE_32K:
3937 fcoe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
3938 fcoe_filt_size <<= (u32)settings->fcoe_filt_num;
3939 break;
3940 default:
3941 return I40E_ERR_PARAM;
3942 }
3943
3944 switch (settings->fcoe_cntx_num) {
3945 case I40E_DMA_CNTX_SIZE_512:
3946 case I40E_DMA_CNTX_SIZE_1K:
3947 case I40E_DMA_CNTX_SIZE_2K:
3948 case I40E_DMA_CNTX_SIZE_4K:
3949 fcoe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
3950 fcoe_cntx_size <<= (u32)settings->fcoe_cntx_num;
3951 break;
3952 default:
3953 return I40E_ERR_PARAM;
3954 }
3955
3956 /* Validate PE settings passed */
3957 switch (settings->pe_filt_num) {
3958 case I40E_HASH_FILTER_SIZE_1K:
3959 case I40E_HASH_FILTER_SIZE_2K:
3960 case I40E_HASH_FILTER_SIZE_4K:
3961 case I40E_HASH_FILTER_SIZE_8K:
3962 case I40E_HASH_FILTER_SIZE_16K:
3963 case I40E_HASH_FILTER_SIZE_32K:
3964 case I40E_HASH_FILTER_SIZE_64K:
3965 case I40E_HASH_FILTER_SIZE_128K:
3966 case I40E_HASH_FILTER_SIZE_256K:
3967 case I40E_HASH_FILTER_SIZE_512K:
3968 case I40E_HASH_FILTER_SIZE_1M:
3969 pe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
3970 pe_filt_size <<= (u32)settings->pe_filt_num;
3971 break;
3972 default:
3973 return I40E_ERR_PARAM;
3974 }
3975
3976 switch (settings->pe_cntx_num) {
3977 case I40E_DMA_CNTX_SIZE_512:
3978 case I40E_DMA_CNTX_SIZE_1K:
3979 case I40E_DMA_CNTX_SIZE_2K:
3980 case I40E_DMA_CNTX_SIZE_4K:
3981 case I40E_DMA_CNTX_SIZE_8K:
3982 case I40E_DMA_CNTX_SIZE_16K:
3983 case I40E_DMA_CNTX_SIZE_32K:
3984 case I40E_DMA_CNTX_SIZE_64K:
3985 case I40E_DMA_CNTX_SIZE_128K:
3986 case I40E_DMA_CNTX_SIZE_256K:
3987 pe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
3988 pe_cntx_size <<= (u32)settings->pe_cntx_num;
3989 break;
3990 default:
3991 return I40E_ERR_PARAM;
3992 }
3993
3994 /* FCHSIZE + FCDSIZE should not be greater than PMFCOEFMAX */
3995 val = rd32(hw, I40E_GLHMC_FCOEFMAX);
3996 fcoe_fmax = (val & I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_MASK)
3997 >> I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_SHIFT;
3998 if (fcoe_filt_size + fcoe_cntx_size > fcoe_fmax)
3999 return I40E_ERR_INVALID_SIZE;
4000
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00004001 return 0;
4002}
4003
4004/**
4005 * i40e_set_filter_control
4006 * @hw: pointer to the hardware structure
4007 * @settings: Filter control settings
4008 *
4009 * Set the Queue Filters for PE/FCoE and enable filters required
4010 * for a single PF. It is expected that these settings are programmed
4011 * at the driver initialization time.
4012 **/
4013i40e_status i40e_set_filter_control(struct i40e_hw *hw,
4014 struct i40e_filter_control_settings *settings)
4015{
4016 i40e_status ret = 0;
4017 u32 hash_lut_size = 0;
4018 u32 val;
4019
4020 if (!settings)
4021 return I40E_ERR_PARAM;
4022
4023 /* Validate the input settings */
4024 ret = i40e_validate_filter_settings(hw, settings);
4025 if (ret)
4026 return ret;
4027
4028 /* Read the PF Queue Filter control register */
Shannon Nelsonf6581372016-02-17 16:12:20 -08004029 val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00004030
4031 /* Program required PE hash buckets for the PF */
4032 val &= ~I40E_PFQF_CTL_0_PEHSIZE_MASK;
4033 val |= ((u32)settings->pe_filt_num << I40E_PFQF_CTL_0_PEHSIZE_SHIFT) &
4034 I40E_PFQF_CTL_0_PEHSIZE_MASK;
4035 /* Program required PE contexts for the PF */
4036 val &= ~I40E_PFQF_CTL_0_PEDSIZE_MASK;
4037 val |= ((u32)settings->pe_cntx_num << I40E_PFQF_CTL_0_PEDSIZE_SHIFT) &
4038 I40E_PFQF_CTL_0_PEDSIZE_MASK;
4039
4040 /* Program required FCoE hash buckets for the PF */
4041 val &= ~I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
4042 val |= ((u32)settings->fcoe_filt_num <<
4043 I40E_PFQF_CTL_0_PFFCHSIZE_SHIFT) &
4044 I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
4045 /* Program required FCoE DDP contexts for the PF */
4046 val &= ~I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
4047 val |= ((u32)settings->fcoe_cntx_num <<
4048 I40E_PFQF_CTL_0_PFFCDSIZE_SHIFT) &
4049 I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
4050
4051 /* Program Hash LUT size for the PF */
4052 val &= ~I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
4053 if (settings->hash_lut_size == I40E_HASH_LUT_SIZE_512)
4054 hash_lut_size = 1;
4055 val |= (hash_lut_size << I40E_PFQF_CTL_0_HASHLUTSIZE_SHIFT) &
4056 I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
4057
4058 /* Enable FDIR, Ethertype and MACVLAN filters for PF and VFs */
4059 if (settings->enable_fdir)
4060 val |= I40E_PFQF_CTL_0_FD_ENA_MASK;
4061 if (settings->enable_ethtype)
4062 val |= I40E_PFQF_CTL_0_ETYPE_ENA_MASK;
4063 if (settings->enable_macvlan)
4064 val |= I40E_PFQF_CTL_0_MACVLAN_ENA_MASK;
4065
Shannon Nelsonf6581372016-02-17 16:12:20 -08004066 i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, val);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00004067
4068 return 0;
4069}
Neerav Parikhafb3ff02014-01-17 15:36:36 -08004070
4071/**
4072 * i40e_aq_add_rem_control_packet_filter - Add or Remove Control Packet Filter
4073 * @hw: pointer to the hw struct
4074 * @mac_addr: MAC address to use in the filter
4075 * @ethtype: Ethertype to use in the filter
4076 * @flags: Flags that needs to be applied to the filter
4077 * @vsi_seid: seid of the control VSI
4078 * @queue: VSI queue number to send the packet to
4079 * @is_add: Add control packet filter if True else remove
4080 * @stats: Structure to hold information on control filter counts
4081 * @cmd_details: pointer to command details structure or NULL
4082 *
4083 * This command will Add or Remove control packet filter for a control VSI.
4084 * In return it will update the total number of perfect filter count in
4085 * the stats member.
4086 **/
4087i40e_status i40e_aq_add_rem_control_packet_filter(struct i40e_hw *hw,
4088 u8 *mac_addr, u16 ethtype, u16 flags,
4089 u16 vsi_seid, u16 queue, bool is_add,
4090 struct i40e_control_filter_stats *stats,
4091 struct i40e_asq_cmd_details *cmd_details)
4092{
4093 struct i40e_aq_desc desc;
4094 struct i40e_aqc_add_remove_control_packet_filter *cmd =
4095 (struct i40e_aqc_add_remove_control_packet_filter *)
4096 &desc.params.raw;
4097 struct i40e_aqc_add_remove_control_packet_filter_completion *resp =
4098 (struct i40e_aqc_add_remove_control_packet_filter_completion *)
4099 &desc.params.raw;
4100 i40e_status status;
4101
4102 if (vsi_seid == 0)
4103 return I40E_ERR_PARAM;
4104
4105 if (is_add) {
4106 i40e_fill_default_direct_cmd_desc(&desc,
4107 i40e_aqc_opc_add_control_packet_filter);
4108 cmd->queue = cpu_to_le16(queue);
4109 } else {
4110 i40e_fill_default_direct_cmd_desc(&desc,
4111 i40e_aqc_opc_remove_control_packet_filter);
4112 }
4113
4114 if (mac_addr)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04004115 ether_addr_copy(cmd->mac, mac_addr);
Neerav Parikhafb3ff02014-01-17 15:36:36 -08004116
4117 cmd->etype = cpu_to_le16(ethtype);
4118 cmd->flags = cpu_to_le16(flags);
4119 cmd->seid = cpu_to_le16(vsi_seid);
4120
4121 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4122
4123 if (!status && stats) {
4124 stats->mac_etype_used = le16_to_cpu(resp->mac_etype_used);
4125 stats->etype_used = le16_to_cpu(resp->etype_used);
4126 stats->mac_etype_free = le16_to_cpu(resp->mac_etype_free);
4127 stats->etype_free = le16_to_cpu(resp->etype_free);
4128 }
4129
4130 return status;
4131}
4132
Catherine Sullivand4dfb812013-11-28 06:39:21 +00004133/**
Anjali Singhai Jaine7358f52015-10-01 14:37:34 -04004134 * i40e_add_filter_to_drop_tx_flow_control_frames- filter to drop flow control
4135 * @hw: pointer to the hw struct
4136 * @seid: VSI seid to add ethertype filter from
4137 **/
4138#define I40E_FLOW_CONTROL_ETHTYPE 0x8808
4139void i40e_add_filter_to_drop_tx_flow_control_frames(struct i40e_hw *hw,
4140 u16 seid)
4141{
4142 u16 flag = I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC |
4143 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP |
4144 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX;
4145 u16 ethtype = I40E_FLOW_CONTROL_ETHTYPE;
4146 i40e_status status;
4147
4148 status = i40e_aq_add_rem_control_packet_filter(hw, NULL, ethtype, flag,
4149 seid, 0, true, NULL,
4150 NULL);
4151 if (status)
4152 hw_dbg(hw, "Ethtype Filter Add failed: Error pruning Tx flow control frames\n");
4153}
4154
4155/**
Greg Rosef4492db2015-02-06 08:52:12 +00004156 * i40e_aq_alternate_read
4157 * @hw: pointer to the hardware structure
4158 * @reg_addr0: address of first dword to be read
4159 * @reg_val0: pointer for data read from 'reg_addr0'
4160 * @reg_addr1: address of second dword to be read
4161 * @reg_val1: pointer for data read from 'reg_addr1'
4162 *
4163 * Read one or two dwords from alternate structure. Fields are indicated
4164 * by 'reg_addr0' and 'reg_addr1' register numbers. If 'reg_val1' pointer
4165 * is not passed then only register at 'reg_addr0' is read.
4166 *
4167 **/
Shannon Nelson37a29732015-02-27 09:15:19 +00004168static i40e_status i40e_aq_alternate_read(struct i40e_hw *hw,
4169 u32 reg_addr0, u32 *reg_val0,
4170 u32 reg_addr1, u32 *reg_val1)
Greg Rosef4492db2015-02-06 08:52:12 +00004171{
4172 struct i40e_aq_desc desc;
4173 struct i40e_aqc_alternate_write *cmd_resp =
4174 (struct i40e_aqc_alternate_write *)&desc.params.raw;
4175 i40e_status status;
4176
4177 if (!reg_val0)
4178 return I40E_ERR_PARAM;
4179
4180 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_alternate_read);
4181 cmd_resp->address0 = cpu_to_le32(reg_addr0);
4182 cmd_resp->address1 = cpu_to_le32(reg_addr1);
4183
4184 status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
4185
4186 if (!status) {
4187 *reg_val0 = le32_to_cpu(cmd_resp->data0);
4188
4189 if (reg_val1)
4190 *reg_val1 = le32_to_cpu(cmd_resp->data1);
4191 }
4192
4193 return status;
4194}
4195
4196/**
Neerav Parikh2fd75f32014-11-12 00:18:20 +00004197 * i40e_aq_resume_port_tx
4198 * @hw: pointer to the hardware structure
4199 * @cmd_details: pointer to command details structure or NULL
4200 *
4201 * Resume port's Tx traffic
4202 **/
4203i40e_status i40e_aq_resume_port_tx(struct i40e_hw *hw,
4204 struct i40e_asq_cmd_details *cmd_details)
4205{
4206 struct i40e_aq_desc desc;
4207 i40e_status status;
4208
4209 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_resume_port_tx);
4210
4211 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4212
4213 return status;
4214}
4215
4216/**
Catherine Sullivand4dfb812013-11-28 06:39:21 +00004217 * i40e_set_pci_config_data - store PCI bus info
4218 * @hw: pointer to hardware structure
4219 * @link_status: the link status word from PCI config space
4220 *
4221 * Stores the PCI bus info (speed, width, type) within the i40e_hw structure
4222 **/
4223void i40e_set_pci_config_data(struct i40e_hw *hw, u16 link_status)
4224{
4225 hw->bus.type = i40e_bus_type_pci_express;
4226
4227 switch (link_status & PCI_EXP_LNKSTA_NLW) {
4228 case PCI_EXP_LNKSTA_NLW_X1:
4229 hw->bus.width = i40e_bus_width_pcie_x1;
4230 break;
4231 case PCI_EXP_LNKSTA_NLW_X2:
4232 hw->bus.width = i40e_bus_width_pcie_x2;
4233 break;
4234 case PCI_EXP_LNKSTA_NLW_X4:
4235 hw->bus.width = i40e_bus_width_pcie_x4;
4236 break;
4237 case PCI_EXP_LNKSTA_NLW_X8:
4238 hw->bus.width = i40e_bus_width_pcie_x8;
4239 break;
4240 default:
4241 hw->bus.width = i40e_bus_width_unknown;
4242 break;
4243 }
4244
4245 switch (link_status & PCI_EXP_LNKSTA_CLS) {
4246 case PCI_EXP_LNKSTA_CLS_2_5GB:
4247 hw->bus.speed = i40e_bus_speed_2500;
4248 break;
4249 case PCI_EXP_LNKSTA_CLS_5_0GB:
4250 hw->bus.speed = i40e_bus_speed_5000;
4251 break;
4252 case PCI_EXP_LNKSTA_CLS_8_0GB:
4253 hw->bus.speed = i40e_bus_speed_8000;
4254 break;
4255 default:
4256 hw->bus.speed = i40e_bus_speed_unknown;
4257 break;
4258 }
4259}
Greg Rosef4492db2015-02-06 08:52:12 +00004260
4261/**
Jesse Brandeburg3169c322015-04-07 19:45:37 -04004262 * i40e_aq_debug_dump
4263 * @hw: pointer to the hardware structure
4264 * @cluster_id: specific cluster to dump
4265 * @table_id: table id within cluster
4266 * @start_index: index of line in the block to read
4267 * @buff_size: dump buffer size
4268 * @buff: dump buffer
4269 * @ret_buff_size: actual buffer size returned
4270 * @ret_next_table: next block to read
4271 * @ret_next_index: next index to read
4272 *
4273 * Dump internal FW/HW data for debug purposes.
4274 *
4275 **/
4276i40e_status i40e_aq_debug_dump(struct i40e_hw *hw, u8 cluster_id,
4277 u8 table_id, u32 start_index, u16 buff_size,
4278 void *buff, u16 *ret_buff_size,
4279 u8 *ret_next_table, u32 *ret_next_index,
4280 struct i40e_asq_cmd_details *cmd_details)
4281{
4282 struct i40e_aq_desc desc;
4283 struct i40e_aqc_debug_dump_internals *cmd =
4284 (struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
4285 struct i40e_aqc_debug_dump_internals *resp =
4286 (struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
4287 i40e_status status;
4288
4289 if (buff_size == 0 || !buff)
4290 return I40E_ERR_PARAM;
4291
4292 i40e_fill_default_direct_cmd_desc(&desc,
4293 i40e_aqc_opc_debug_dump_internals);
4294 /* Indirect Command */
4295 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
4296 if (buff_size > I40E_AQ_LARGE_BUF)
4297 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
4298
4299 cmd->cluster_id = cluster_id;
4300 cmd->table_id = table_id;
4301 cmd->idx = cpu_to_le32(start_index);
4302
4303 desc.datalen = cpu_to_le16(buff_size);
4304
4305 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
4306 if (!status) {
4307 if (ret_buff_size)
4308 *ret_buff_size = le16_to_cpu(desc.datalen);
4309 if (ret_next_table)
4310 *ret_next_table = resp->table_id;
4311 if (ret_next_index)
4312 *ret_next_index = le32_to_cpu(resp->idx);
4313 }
4314
4315 return status;
4316}
4317
4318/**
Greg Rosef4492db2015-02-06 08:52:12 +00004319 * i40e_read_bw_from_alt_ram
4320 * @hw: pointer to the hardware structure
4321 * @max_bw: pointer for max_bw read
4322 * @min_bw: pointer for min_bw read
4323 * @min_valid: pointer for bool that is true if min_bw is a valid value
4324 * @max_valid: pointer for bool that is true if max_bw is a valid value
4325 *
4326 * Read bw from the alternate ram for the given pf
4327 **/
4328i40e_status i40e_read_bw_from_alt_ram(struct i40e_hw *hw,
4329 u32 *max_bw, u32 *min_bw,
4330 bool *min_valid, bool *max_valid)
4331{
4332 i40e_status status;
4333 u32 max_bw_addr, min_bw_addr;
4334
4335 /* Calculate the address of the min/max bw registers */
4336 max_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
4337 I40E_ALT_STRUCT_MAX_BW_OFFSET +
4338 (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
4339 min_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
4340 I40E_ALT_STRUCT_MIN_BW_OFFSET +
4341 (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
4342
4343 /* Read the bandwidths from alt ram */
4344 status = i40e_aq_alternate_read(hw, max_bw_addr, max_bw,
4345 min_bw_addr, min_bw);
4346
4347 if (*min_bw & I40E_ALT_BW_VALID_MASK)
4348 *min_valid = true;
4349 else
4350 *min_valid = false;
4351
4352 if (*max_bw & I40E_ALT_BW_VALID_MASK)
4353 *max_valid = true;
4354 else
4355 *max_valid = false;
4356
4357 return status;
4358}
4359
4360/**
4361 * i40e_aq_configure_partition_bw
4362 * @hw: pointer to the hardware structure
4363 * @bw_data: Buffer holding valid pfs and bw limits
4364 * @cmd_details: pointer to command details
4365 *
4366 * Configure partitions guaranteed/max bw
4367 **/
4368i40e_status i40e_aq_configure_partition_bw(struct i40e_hw *hw,
4369 struct i40e_aqc_configure_partition_bw_data *bw_data,
4370 struct i40e_asq_cmd_details *cmd_details)
4371{
4372 i40e_status status;
4373 struct i40e_aq_desc desc;
4374 u16 bwd_size = sizeof(*bw_data);
4375
4376 i40e_fill_default_direct_cmd_desc(&desc,
4377 i40e_aqc_opc_configure_partition_bw);
4378
4379 /* Indirect command */
4380 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
4381 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
4382
4383 if (bwd_size > I40E_AQ_LARGE_BUF)
4384 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
4385
4386 desc.datalen = cpu_to_le16(bwd_size);
4387
4388 status = i40e_asq_send_command(hw, &desc, bw_data, bwd_size,
4389 cmd_details);
4390
4391 return status;
4392}
Carolyn Wybornyfd077cd2016-02-17 16:12:11 -08004393
4394/**
4395 * i40e_read_phy_register
4396 * @hw: pointer to the HW structure
4397 * @page: registers page number
4398 * @reg: register address in the page
4399 * @phy_adr: PHY address on MDIO interface
4400 * @value: PHY register value
4401 *
4402 * Reads specified PHY register value
4403 **/
4404i40e_status i40e_read_phy_register(struct i40e_hw *hw,
4405 u8 page, u16 reg, u8 phy_addr,
4406 u16 *value)
4407{
4408 i40e_status status = I40E_ERR_TIMEOUT;
4409 u32 command = 0;
4410 u16 retry = 1000;
4411 u8 port_num = hw->func_caps.mdio_port_num;
4412
4413 command = (reg << I40E_GLGEN_MSCA_MDIADD_SHIFT) |
4414 (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4415 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
4416 (I40E_MDIO_OPCODE_ADDRESS) |
4417 (I40E_MDIO_STCODE) |
4418 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4419 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4420 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4421 do {
4422 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4423 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4424 status = 0;
4425 break;
4426 }
4427 usleep_range(10, 20);
4428 retry--;
4429 } while (retry);
4430
4431 if (status) {
4432 i40e_debug(hw, I40E_DEBUG_PHY,
4433 "PHY: Can't write command to external PHY.\n");
4434 goto phy_read_end;
4435 }
4436
4437 command = (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4438 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
4439 (I40E_MDIO_OPCODE_READ) |
4440 (I40E_MDIO_STCODE) |
4441 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4442 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4443 status = I40E_ERR_TIMEOUT;
4444 retry = 1000;
4445 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4446 do {
4447 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4448 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4449 status = 0;
4450 break;
4451 }
4452 usleep_range(10, 20);
4453 retry--;
4454 } while (retry);
4455
4456 if (!status) {
4457 command = rd32(hw, I40E_GLGEN_MSRWD(port_num));
4458 *value = (command & I40E_GLGEN_MSRWD_MDIRDDATA_MASK) >>
4459 I40E_GLGEN_MSRWD_MDIRDDATA_SHIFT;
4460 } else {
4461 i40e_debug(hw, I40E_DEBUG_PHY,
4462 "PHY: Can't read register value from external PHY.\n");
4463 }
4464
4465phy_read_end:
4466 return status;
4467}
4468
4469/**
4470 * i40e_write_phy_register
4471 * @hw: pointer to the HW structure
4472 * @page: registers page number
4473 * @reg: register address in the page
4474 * @phy_adr: PHY address on MDIO interface
4475 * @value: PHY register value
4476 *
4477 * Writes value to specified PHY register
4478 **/
4479i40e_status i40e_write_phy_register(struct i40e_hw *hw,
4480 u8 page, u16 reg, u8 phy_addr,
4481 u16 value)
4482{
4483 i40e_status status = I40E_ERR_TIMEOUT;
4484 u32 command = 0;
4485 u16 retry = 1000;
4486 u8 port_num = hw->func_caps.mdio_port_num;
4487
4488 command = (reg << I40E_GLGEN_MSCA_MDIADD_SHIFT) |
4489 (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4490 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
4491 (I40E_MDIO_OPCODE_ADDRESS) |
4492 (I40E_MDIO_STCODE) |
4493 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4494 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4495 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4496 do {
4497 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4498 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4499 status = 0;
4500 break;
4501 }
4502 usleep_range(10, 20);
4503 retry--;
4504 } while (retry);
4505 if (status) {
4506 i40e_debug(hw, I40E_DEBUG_PHY,
4507 "PHY: Can't write command to external PHY.\n");
4508 goto phy_write_end;
4509 }
4510
4511 command = value << I40E_GLGEN_MSRWD_MDIWRDATA_SHIFT;
4512 wr32(hw, I40E_GLGEN_MSRWD(port_num), command);
4513
4514 command = (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4515 (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
4516 (I40E_MDIO_OPCODE_WRITE) |
4517 (I40E_MDIO_STCODE) |
4518 (I40E_GLGEN_MSCA_MDICMD_MASK) |
4519 (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4520 status = I40E_ERR_TIMEOUT;
4521 retry = 1000;
4522 wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4523 do {
4524 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4525 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4526 status = 0;
4527 break;
4528 }
4529 usleep_range(10, 20);
4530 retry--;
4531 } while (retry);
4532
4533phy_write_end:
4534 return status;
4535}
4536
4537/**
4538 * i40e_get_phy_address
4539 * @hw: pointer to the HW structure
4540 * @dev_num: PHY port num that address we want
4541 * @phy_addr: Returned PHY address
4542 *
4543 * Gets PHY address for current port
4544 **/
4545u8 i40e_get_phy_address(struct i40e_hw *hw, u8 dev_num)
4546{
4547 u8 port_num = hw->func_caps.mdio_port_num;
4548 u32 reg_val = rd32(hw, I40E_GLGEN_MDIO_I2C_SEL(port_num));
4549
4550 return (u8)(reg_val >> ((dev_num + 1) * 5)) & 0x1f;
4551}
4552
4553/**
4554 * i40e_blink_phy_led
4555 * @hw: pointer to the HW structure
4556 * @time: time how long led will blinks in secs
4557 * @interval: gap between LED on and off in msecs
4558 *
4559 * Blinks PHY link LED
4560 **/
4561i40e_status i40e_blink_phy_link_led(struct i40e_hw *hw,
4562 u32 time, u32 interval)
4563{
4564 i40e_status status = 0;
4565 u32 i;
4566 u16 led_ctl;
4567 u16 gpio_led_port;
4568 u16 led_reg;
4569 u16 led_addr = I40E_PHY_LED_PROV_REG_1;
4570 u8 phy_addr = 0;
4571 u8 port_num;
4572
4573 i = rd32(hw, I40E_PFGEN_PORTNUM);
4574 port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
4575 phy_addr = i40e_get_phy_address(hw, port_num);
4576
4577 for (gpio_led_port = 0; gpio_led_port < 3; gpio_led_port++,
4578 led_addr++) {
4579 status = i40e_read_phy_register(hw, I40E_PHY_COM_REG_PAGE,
4580 led_addr, phy_addr, &led_reg);
4581 if (status)
4582 goto phy_blinking_end;
4583 led_ctl = led_reg;
4584 if (led_reg & I40E_PHY_LED_LINK_MODE_MASK) {
4585 led_reg = 0;
4586 status = i40e_write_phy_register(hw,
4587 I40E_PHY_COM_REG_PAGE,
4588 led_addr, phy_addr,
4589 led_reg);
4590 if (status)
4591 goto phy_blinking_end;
4592 break;
4593 }
4594 }
4595
4596 if (time > 0 && interval > 0) {
4597 for (i = 0; i < time * 1000; i += interval) {
4598 status = i40e_read_phy_register(hw,
4599 I40E_PHY_COM_REG_PAGE,
4600 led_addr, phy_addr,
4601 &led_reg);
4602 if (status)
4603 goto restore_config;
4604 if (led_reg & I40E_PHY_LED_MANUAL_ON)
4605 led_reg = 0;
4606 else
4607 led_reg = I40E_PHY_LED_MANUAL_ON;
4608 status = i40e_write_phy_register(hw,
4609 I40E_PHY_COM_REG_PAGE,
4610 led_addr, phy_addr,
4611 led_reg);
4612 if (status)
4613 goto restore_config;
4614 msleep(interval);
4615 }
4616 }
4617
4618restore_config:
4619 status = i40e_write_phy_register(hw, I40E_PHY_COM_REG_PAGE, led_addr,
4620 phy_addr, led_ctl);
4621
4622phy_blinking_end:
4623 return status;
4624}
4625
4626/**
4627 * i40e_led_get_phy - return current on/off mode
4628 * @hw: pointer to the hw struct
4629 * @led_addr: address of led register to use
4630 * @val: original value of register to use
4631 *
4632 **/
4633i40e_status i40e_led_get_phy(struct i40e_hw *hw, u16 *led_addr,
4634 u16 *val)
4635{
4636 i40e_status status = 0;
4637 u16 gpio_led_port;
4638 u8 phy_addr = 0;
4639 u16 reg_val;
4640 u16 temp_addr;
4641 u8 port_num;
4642 u32 i;
4643
4644 temp_addr = I40E_PHY_LED_PROV_REG_1;
4645 i = rd32(hw, I40E_PFGEN_PORTNUM);
4646 port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
4647 phy_addr = i40e_get_phy_address(hw, port_num);
4648
4649 for (gpio_led_port = 0; gpio_led_port < 3; gpio_led_port++,
4650 temp_addr++) {
4651 status = i40e_read_phy_register(hw, I40E_PHY_COM_REG_PAGE,
4652 temp_addr, phy_addr, &reg_val);
4653 if (status)
4654 return status;
4655 *val = reg_val;
4656 if (reg_val & I40E_PHY_LED_LINK_MODE_MASK) {
4657 *led_addr = temp_addr;
4658 break;
4659 }
4660 }
4661 return status;
4662}
4663
4664/**
4665 * i40e_led_set_phy
4666 * @hw: pointer to the HW structure
4667 * @on: true or false
4668 * @mode: original val plus bit for set or ignore
4669 * Set led's on or off when controlled by the PHY
4670 *
4671 **/
4672i40e_status i40e_led_set_phy(struct i40e_hw *hw, bool on,
4673 u16 led_addr, u32 mode)
4674{
4675 i40e_status status = 0;
4676 u16 led_ctl = 0;
4677 u16 led_reg = 0;
4678 u8 phy_addr = 0;
4679 u8 port_num;
4680 u32 i;
4681
4682 i = rd32(hw, I40E_PFGEN_PORTNUM);
4683 port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
4684 phy_addr = i40e_get_phy_address(hw, port_num);
4685
4686 status = i40e_read_phy_register(hw, I40E_PHY_COM_REG_PAGE, led_addr,
4687 phy_addr, &led_reg);
4688 if (status)
4689 return status;
4690 led_ctl = led_reg;
4691 if (led_reg & I40E_PHY_LED_LINK_MODE_MASK) {
4692 led_reg = 0;
4693 status = i40e_write_phy_register(hw, I40E_PHY_COM_REG_PAGE,
4694 led_addr, phy_addr, led_reg);
4695 if (status)
4696 return status;
4697 }
4698 status = i40e_read_phy_register(hw, I40E_PHY_COM_REG_PAGE,
4699 led_addr, phy_addr, &led_reg);
4700 if (status)
4701 goto restore_config;
4702 if (on)
4703 led_reg = I40E_PHY_LED_MANUAL_ON;
4704 else
4705 led_reg = 0;
4706 status = i40e_write_phy_register(hw, I40E_PHY_COM_REG_PAGE,
4707 led_addr, phy_addr, led_reg);
4708 if (status)
4709 goto restore_config;
4710 if (mode & I40E_PHY_LED_MODE_ORIG) {
4711 led_ctl = (mode & I40E_PHY_LED_MODE_MASK);
4712 status = i40e_write_phy_register(hw,
4713 I40E_PHY_COM_REG_PAGE,
4714 led_addr, phy_addr, led_ctl);
4715 }
4716 return status;
4717restore_config:
4718 status = i40e_write_phy_register(hw, I40E_PHY_COM_REG_PAGE, led_addr,
4719 phy_addr, led_ctl);
4720 return status;
4721}
Shannon Nelsonf6581372016-02-17 16:12:20 -08004722
4723/**
4724 * i40e_aq_rx_ctl_read_register - use FW to read from an Rx control register
4725 * @hw: pointer to the hw struct
4726 * @reg_addr: register address
4727 * @reg_val: ptr to register value
4728 * @cmd_details: pointer to command details structure or NULL
4729 *
4730 * Use the firmware to read the Rx control register,
4731 * especially useful if the Rx unit is under heavy pressure
4732 **/
4733i40e_status i40e_aq_rx_ctl_read_register(struct i40e_hw *hw,
4734 u32 reg_addr, u32 *reg_val,
4735 struct i40e_asq_cmd_details *cmd_details)
4736{
4737 struct i40e_aq_desc desc;
4738 struct i40e_aqc_rx_ctl_reg_read_write *cmd_resp =
4739 (struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
4740 i40e_status status;
4741
4742 if (!reg_val)
4743 return I40E_ERR_PARAM;
4744
4745 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_rx_ctl_reg_read);
4746
4747 cmd_resp->address = cpu_to_le32(reg_addr);
4748
4749 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4750
4751 if (status == 0)
4752 *reg_val = le32_to_cpu(cmd_resp->value);
4753
4754 return status;
4755}
4756
4757/**
4758 * i40e_read_rx_ctl - read from an Rx control register
4759 * @hw: pointer to the hw struct
4760 * @reg_addr: register address
4761 **/
4762u32 i40e_read_rx_ctl(struct i40e_hw *hw, u32 reg_addr)
4763{
4764 i40e_status status = 0;
4765 bool use_register;
4766 int retry = 5;
4767 u32 val = 0;
4768
4769 use_register = (hw->aq.api_maj_ver == 1) && (hw->aq.api_min_ver < 5);
4770 if (!use_register) {
4771do_retry:
4772 status = i40e_aq_rx_ctl_read_register(hw, reg_addr, &val, NULL);
4773 if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
4774 usleep_range(1000, 2000);
4775 retry--;
4776 goto do_retry;
4777 }
4778 }
4779
4780 /* if the AQ access failed, try the old-fashioned way */
4781 if (status || use_register)
4782 val = rd32(hw, reg_addr);
4783
4784 return val;
4785}
4786
4787/**
4788 * i40e_aq_rx_ctl_write_register
4789 * @hw: pointer to the hw struct
4790 * @reg_addr: register address
4791 * @reg_val: register value
4792 * @cmd_details: pointer to command details structure or NULL
4793 *
4794 * Use the firmware to write to an Rx control register,
4795 * especially useful if the Rx unit is under heavy pressure
4796 **/
4797i40e_status i40e_aq_rx_ctl_write_register(struct i40e_hw *hw,
4798 u32 reg_addr, u32 reg_val,
4799 struct i40e_asq_cmd_details *cmd_details)
4800{
4801 struct i40e_aq_desc desc;
4802 struct i40e_aqc_rx_ctl_reg_read_write *cmd =
4803 (struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
4804 i40e_status status;
4805
4806 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_rx_ctl_reg_write);
4807
4808 cmd->address = cpu_to_le32(reg_addr);
4809 cmd->value = cpu_to_le32(reg_val);
4810
4811 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4812
4813 return status;
4814}
4815
4816/**
4817 * i40e_write_rx_ctl - write to an Rx control register
4818 * @hw: pointer to the hw struct
4819 * @reg_addr: register address
4820 * @reg_val: register value
4821 **/
4822void i40e_write_rx_ctl(struct i40e_hw *hw, u32 reg_addr, u32 reg_val)
4823{
4824 i40e_status status = 0;
4825 bool use_register;
4826 int retry = 5;
4827
4828 use_register = (hw->aq.api_maj_ver == 1) && (hw->aq.api_min_ver < 5);
4829 if (!use_register) {
4830do_retry:
4831 status = i40e_aq_rx_ctl_write_register(hw, reg_addr,
4832 reg_val, NULL);
4833 if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
4834 usleep_range(1000, 2000);
4835 retry--;
4836 goto do_retry;
4837 }
4838 }
4839
4840 /* if the AQ access failed, try the old-fashioned way */
4841 if (status || use_register)
4842 wr32(hw, reg_addr, reg_val);
4843}