blob: ffd1cd0642f1338b9f309fef310a38ead38a8682 [file] [log] [blame]
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +00004 * Copyright(c) 2013 - 2015 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:
47 case I40E_DEV_ID_KX_A:
48 case I40E_DEV_ID_KX_B:
49 case I40E_DEV_ID_KX_C:
Shannon Nelsonab600852014-01-17 15:36:39 -080050 case I40E_DEV_ID_QSFP_A:
51 case I40E_DEV_ID_QSFP_B:
52 case I40E_DEV_ID_QSFP_C:
Mitch Williams5960d332014-09-13 07:40:47 +000053 case I40E_DEV_ID_10G_BASE_T:
Shannon Nelsonbc5166b92015-08-26 15:14:10 -040054 case I40E_DEV_ID_10G_BASE_T4:
Jesse Brandeburgae24b402015-03-27 00:12:09 -070055 case I40E_DEV_ID_20G_KR2:
Shannon Nelson48a3b512015-07-23 16:54:39 -040056 case I40E_DEV_ID_20G_KR2_A:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +000057 hw->mac.type = I40E_MAC_XL710;
58 break;
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -040059 case I40E_DEV_ID_SFP_X722:
60 case I40E_DEV_ID_1G_BASE_T_X722:
61 case I40E_DEV_ID_10G_BASE_T_X722:
62 hw->mac.type = I40E_MAC_X722;
63 break;
64 case I40E_DEV_ID_X722_VF:
65 case I40E_DEV_ID_X722_VF_HV:
66 hw->mac.type = I40E_MAC_X722_VF;
67 break;
Shannon Nelsonab600852014-01-17 15:36:39 -080068 case I40E_DEV_ID_VF:
69 case I40E_DEV_ID_VF_HV:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +000070 hw->mac.type = I40E_MAC_VF;
71 break;
72 default:
73 hw->mac.type = I40E_MAC_GENERIC;
74 break;
75 }
76 } else {
77 status = I40E_ERR_DEVICE_NOT_SUPPORTED;
78 }
79
80 hw_dbg(hw, "i40e_set_mac_type found mac: %d, returns: %d\n",
81 hw->mac.type, status);
82 return status;
83}
84
85/**
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040086 * i40e_aq_str - convert AQ err code to a string
87 * @hw: pointer to the HW structure
88 * @aq_err: the AQ error code to convert
89 **/
90char *i40e_aq_str(struct i40e_hw *hw, enum i40e_admin_queue_err aq_err)
91{
92 switch (aq_err) {
93 case I40E_AQ_RC_OK:
94 return "OK";
95 case I40E_AQ_RC_EPERM:
96 return "I40E_AQ_RC_EPERM";
97 case I40E_AQ_RC_ENOENT:
98 return "I40E_AQ_RC_ENOENT";
99 case I40E_AQ_RC_ESRCH:
100 return "I40E_AQ_RC_ESRCH";
101 case I40E_AQ_RC_EINTR:
102 return "I40E_AQ_RC_EINTR";
103 case I40E_AQ_RC_EIO:
104 return "I40E_AQ_RC_EIO";
105 case I40E_AQ_RC_ENXIO:
106 return "I40E_AQ_RC_ENXIO";
107 case I40E_AQ_RC_E2BIG:
108 return "I40E_AQ_RC_E2BIG";
109 case I40E_AQ_RC_EAGAIN:
110 return "I40E_AQ_RC_EAGAIN";
111 case I40E_AQ_RC_ENOMEM:
112 return "I40E_AQ_RC_ENOMEM";
113 case I40E_AQ_RC_EACCES:
114 return "I40E_AQ_RC_EACCES";
115 case I40E_AQ_RC_EFAULT:
116 return "I40E_AQ_RC_EFAULT";
117 case I40E_AQ_RC_EBUSY:
118 return "I40E_AQ_RC_EBUSY";
119 case I40E_AQ_RC_EEXIST:
120 return "I40E_AQ_RC_EEXIST";
121 case I40E_AQ_RC_EINVAL:
122 return "I40E_AQ_RC_EINVAL";
123 case I40E_AQ_RC_ENOTTY:
124 return "I40E_AQ_RC_ENOTTY";
125 case I40E_AQ_RC_ENOSPC:
126 return "I40E_AQ_RC_ENOSPC";
127 case I40E_AQ_RC_ENOSYS:
128 return "I40E_AQ_RC_ENOSYS";
129 case I40E_AQ_RC_ERANGE:
130 return "I40E_AQ_RC_ERANGE";
131 case I40E_AQ_RC_EFLUSHED:
132 return "I40E_AQ_RC_EFLUSHED";
133 case I40E_AQ_RC_BAD_ADDR:
134 return "I40E_AQ_RC_BAD_ADDR";
135 case I40E_AQ_RC_EMODE:
136 return "I40E_AQ_RC_EMODE";
137 case I40E_AQ_RC_EFBIG:
138 return "I40E_AQ_RC_EFBIG";
139 }
140
141 snprintf(hw->err_str, sizeof(hw->err_str), "%d", aq_err);
142 return hw->err_str;
143}
144
145/**
146 * i40e_stat_str - convert status err code to a string
147 * @hw: pointer to the HW structure
148 * @stat_err: the status error code to convert
149 **/
150char *i40e_stat_str(struct i40e_hw *hw, i40e_status stat_err)
151{
152 switch (stat_err) {
153 case 0:
154 return "OK";
155 case I40E_ERR_NVM:
156 return "I40E_ERR_NVM";
157 case I40E_ERR_NVM_CHECKSUM:
158 return "I40E_ERR_NVM_CHECKSUM";
159 case I40E_ERR_PHY:
160 return "I40E_ERR_PHY";
161 case I40E_ERR_CONFIG:
162 return "I40E_ERR_CONFIG";
163 case I40E_ERR_PARAM:
164 return "I40E_ERR_PARAM";
165 case I40E_ERR_MAC_TYPE:
166 return "I40E_ERR_MAC_TYPE";
167 case I40E_ERR_UNKNOWN_PHY:
168 return "I40E_ERR_UNKNOWN_PHY";
169 case I40E_ERR_LINK_SETUP:
170 return "I40E_ERR_LINK_SETUP";
171 case I40E_ERR_ADAPTER_STOPPED:
172 return "I40E_ERR_ADAPTER_STOPPED";
173 case I40E_ERR_INVALID_MAC_ADDR:
174 return "I40E_ERR_INVALID_MAC_ADDR";
175 case I40E_ERR_DEVICE_NOT_SUPPORTED:
176 return "I40E_ERR_DEVICE_NOT_SUPPORTED";
177 case I40E_ERR_MASTER_REQUESTS_PENDING:
178 return "I40E_ERR_MASTER_REQUESTS_PENDING";
179 case I40E_ERR_INVALID_LINK_SETTINGS:
180 return "I40E_ERR_INVALID_LINK_SETTINGS";
181 case I40E_ERR_AUTONEG_NOT_COMPLETE:
182 return "I40E_ERR_AUTONEG_NOT_COMPLETE";
183 case I40E_ERR_RESET_FAILED:
184 return "I40E_ERR_RESET_FAILED";
185 case I40E_ERR_SWFW_SYNC:
186 return "I40E_ERR_SWFW_SYNC";
187 case I40E_ERR_NO_AVAILABLE_VSI:
188 return "I40E_ERR_NO_AVAILABLE_VSI";
189 case I40E_ERR_NO_MEMORY:
190 return "I40E_ERR_NO_MEMORY";
191 case I40E_ERR_BAD_PTR:
192 return "I40E_ERR_BAD_PTR";
193 case I40E_ERR_RING_FULL:
194 return "I40E_ERR_RING_FULL";
195 case I40E_ERR_INVALID_PD_ID:
196 return "I40E_ERR_INVALID_PD_ID";
197 case I40E_ERR_INVALID_QP_ID:
198 return "I40E_ERR_INVALID_QP_ID";
199 case I40E_ERR_INVALID_CQ_ID:
200 return "I40E_ERR_INVALID_CQ_ID";
201 case I40E_ERR_INVALID_CEQ_ID:
202 return "I40E_ERR_INVALID_CEQ_ID";
203 case I40E_ERR_INVALID_AEQ_ID:
204 return "I40E_ERR_INVALID_AEQ_ID";
205 case I40E_ERR_INVALID_SIZE:
206 return "I40E_ERR_INVALID_SIZE";
207 case I40E_ERR_INVALID_ARP_INDEX:
208 return "I40E_ERR_INVALID_ARP_INDEX";
209 case I40E_ERR_INVALID_FPM_FUNC_ID:
210 return "I40E_ERR_INVALID_FPM_FUNC_ID";
211 case I40E_ERR_QP_INVALID_MSG_SIZE:
212 return "I40E_ERR_QP_INVALID_MSG_SIZE";
213 case I40E_ERR_QP_TOOMANY_WRS_POSTED:
214 return "I40E_ERR_QP_TOOMANY_WRS_POSTED";
215 case I40E_ERR_INVALID_FRAG_COUNT:
216 return "I40E_ERR_INVALID_FRAG_COUNT";
217 case I40E_ERR_QUEUE_EMPTY:
218 return "I40E_ERR_QUEUE_EMPTY";
219 case I40E_ERR_INVALID_ALIGNMENT:
220 return "I40E_ERR_INVALID_ALIGNMENT";
221 case I40E_ERR_FLUSHED_QUEUE:
222 return "I40E_ERR_FLUSHED_QUEUE";
223 case I40E_ERR_INVALID_PUSH_PAGE_INDEX:
224 return "I40E_ERR_INVALID_PUSH_PAGE_INDEX";
225 case I40E_ERR_INVALID_IMM_DATA_SIZE:
226 return "I40E_ERR_INVALID_IMM_DATA_SIZE";
227 case I40E_ERR_TIMEOUT:
228 return "I40E_ERR_TIMEOUT";
229 case I40E_ERR_OPCODE_MISMATCH:
230 return "I40E_ERR_OPCODE_MISMATCH";
231 case I40E_ERR_CQP_COMPL_ERROR:
232 return "I40E_ERR_CQP_COMPL_ERROR";
233 case I40E_ERR_INVALID_VF_ID:
234 return "I40E_ERR_INVALID_VF_ID";
235 case I40E_ERR_INVALID_HMCFN_ID:
236 return "I40E_ERR_INVALID_HMCFN_ID";
237 case I40E_ERR_BACKING_PAGE_ERROR:
238 return "I40E_ERR_BACKING_PAGE_ERROR";
239 case I40E_ERR_NO_PBLCHUNKS_AVAILABLE:
240 return "I40E_ERR_NO_PBLCHUNKS_AVAILABLE";
241 case I40E_ERR_INVALID_PBLE_INDEX:
242 return "I40E_ERR_INVALID_PBLE_INDEX";
243 case I40E_ERR_INVALID_SD_INDEX:
244 return "I40E_ERR_INVALID_SD_INDEX";
245 case I40E_ERR_INVALID_PAGE_DESC_INDEX:
246 return "I40E_ERR_INVALID_PAGE_DESC_INDEX";
247 case I40E_ERR_INVALID_SD_TYPE:
248 return "I40E_ERR_INVALID_SD_TYPE";
249 case I40E_ERR_MEMCPY_FAILED:
250 return "I40E_ERR_MEMCPY_FAILED";
251 case I40E_ERR_INVALID_HMC_OBJ_INDEX:
252 return "I40E_ERR_INVALID_HMC_OBJ_INDEX";
253 case I40E_ERR_INVALID_HMC_OBJ_COUNT:
254 return "I40E_ERR_INVALID_HMC_OBJ_COUNT";
255 case I40E_ERR_INVALID_SRQ_ARM_LIMIT:
256 return "I40E_ERR_INVALID_SRQ_ARM_LIMIT";
257 case I40E_ERR_SRQ_ENABLED:
258 return "I40E_ERR_SRQ_ENABLED";
259 case I40E_ERR_ADMIN_QUEUE_ERROR:
260 return "I40E_ERR_ADMIN_QUEUE_ERROR";
261 case I40E_ERR_ADMIN_QUEUE_TIMEOUT:
262 return "I40E_ERR_ADMIN_QUEUE_TIMEOUT";
263 case I40E_ERR_BUF_TOO_SHORT:
264 return "I40E_ERR_BUF_TOO_SHORT";
265 case I40E_ERR_ADMIN_QUEUE_FULL:
266 return "I40E_ERR_ADMIN_QUEUE_FULL";
267 case I40E_ERR_ADMIN_QUEUE_NO_WORK:
268 return "I40E_ERR_ADMIN_QUEUE_NO_WORK";
269 case I40E_ERR_BAD_IWARP_CQE:
270 return "I40E_ERR_BAD_IWARP_CQE";
271 case I40E_ERR_NVM_BLANK_MODE:
272 return "I40E_ERR_NVM_BLANK_MODE";
273 case I40E_ERR_NOT_IMPLEMENTED:
274 return "I40E_ERR_NOT_IMPLEMENTED";
275 case I40E_ERR_PE_DOORBELL_NOT_ENABLED:
276 return "I40E_ERR_PE_DOORBELL_NOT_ENABLED";
277 case I40E_ERR_DIAG_TEST_FAILED:
278 return "I40E_ERR_DIAG_TEST_FAILED";
279 case I40E_ERR_NOT_READY:
280 return "I40E_ERR_NOT_READY";
281 case I40E_NOT_SUPPORTED:
282 return "I40E_NOT_SUPPORTED";
283 case I40E_ERR_FIRMWARE_API_VERSION:
284 return "I40E_ERR_FIRMWARE_API_VERSION";
285 }
286
287 snprintf(hw->err_str, sizeof(hw->err_str), "%d", stat_err);
288 return hw->err_str;
289}
290
291/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000292 * i40e_debug_aq
293 * @hw: debug mask related to admin queue
Jeff Kirsher98d44382013-12-21 05:44:42 +0000294 * @mask: debug mask
295 * @desc: pointer to admin queue descriptor
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000296 * @buffer: pointer to command buffer
Shannon Nelsonf905dd62014-07-10 07:58:20 +0000297 * @buf_len: max length of buffer
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000298 *
299 * Dumps debug log about adminq command with descriptor contents.
300 **/
301void i40e_debug_aq(struct i40e_hw *hw, enum i40e_debug_mask mask, void *desc,
Shannon Nelsonf905dd62014-07-10 07:58:20 +0000302 void *buffer, u16 buf_len)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000303{
304 struct i40e_aq_desc *aq_desc = (struct i40e_aq_desc *)desc;
Shannon Nelsonf905dd62014-07-10 07:58:20 +0000305 u16 len = le16_to_cpu(aq_desc->datalen);
Shannon Nelson37a29732015-02-27 09:15:19 +0000306 u8 *buf = (u8 *)buffer;
307 u16 i = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000308
309 if ((!(mask & hw->debug_mask)) || (desc == NULL))
310 return;
311
312 i40e_debug(hw, mask,
313 "AQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000314 le16_to_cpu(aq_desc->opcode),
315 le16_to_cpu(aq_desc->flags),
316 le16_to_cpu(aq_desc->datalen),
317 le16_to_cpu(aq_desc->retval));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000318 i40e_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000319 le32_to_cpu(aq_desc->cookie_high),
320 le32_to_cpu(aq_desc->cookie_low));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000321 i40e_debug(hw, mask, "\tparam (0,1) 0x%08X 0x%08X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000322 le32_to_cpu(aq_desc->params.internal.param0),
323 le32_to_cpu(aq_desc->params.internal.param1));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000324 i40e_debug(hw, mask, "\taddr (h,l) 0x%08X 0x%08X\n",
Paul M Stillwell Jrf1abd7d2015-02-06 08:52:07 +0000325 le32_to_cpu(aq_desc->params.external.addr_high),
326 le32_to_cpu(aq_desc->params.external.addr_low));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000327
328 if ((buffer != NULL) && (aq_desc->datalen != 0)) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000329 i40e_debug(hw, mask, "AQ CMD Buffer:\n");
Shannon Nelsonf905dd62014-07-10 07:58:20 +0000330 if (buf_len < len)
331 len = buf_len;
Shannon Nelson37a29732015-02-27 09:15:19 +0000332 /* write the full 16-byte chunks */
333 for (i = 0; i < (len - 16); i += 16)
334 i40e_debug(hw, mask,
335 "\t0x%04X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n",
336 i, buf[i], buf[i + 1], buf[i + 2],
337 buf[i + 3], buf[i + 4], buf[i + 5],
338 buf[i + 6], buf[i + 7], buf[i + 8],
339 buf[i + 9], buf[i + 10], buf[i + 11],
340 buf[i + 12], buf[i + 13], buf[i + 14],
341 buf[i + 15]);
342 /* write whatever's left over without overrunning the buffer */
343 if (i < len) {
344 char d_buf[80];
345 int j = 0;
346
347 memset(d_buf, 0, sizeof(d_buf));
348 j += sprintf(d_buf, "\t0x%04X ", i);
349 while (i < len)
350 j += sprintf(&d_buf[j], " %02X", buf[i++]);
351 i40e_debug(hw, mask, "%s\n", d_buf);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000352 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000353 }
354}
355
356/**
Anjali Singhai Jaine1860d82013-11-28 06:39:45 +0000357 * i40e_check_asq_alive
358 * @hw: pointer to the hw struct
359 *
360 * Returns true if Queue is enabled else false.
361 **/
362bool i40e_check_asq_alive(struct i40e_hw *hw)
363{
Kevin Scott8b833b42014-04-09 05:58:54 +0000364 if (hw->aq.asq.len)
365 return !!(rd32(hw, hw->aq.asq.len) &
366 I40E_PF_ATQLEN_ATQENABLE_MASK);
367 else
368 return false;
Anjali Singhai Jaine1860d82013-11-28 06:39:45 +0000369}
370
371/**
372 * i40e_aq_queue_shutdown
373 * @hw: pointer to the hw struct
374 * @unloading: is the driver unloading itself
375 *
376 * Tell the Firmware that we're shutting down the AdminQ and whether
377 * or not the driver is unloading as well.
378 **/
379i40e_status i40e_aq_queue_shutdown(struct i40e_hw *hw,
380 bool unloading)
381{
382 struct i40e_aq_desc desc;
383 struct i40e_aqc_queue_shutdown *cmd =
384 (struct i40e_aqc_queue_shutdown *)&desc.params.raw;
385 i40e_status status;
386
387 i40e_fill_default_direct_cmd_desc(&desc,
388 i40e_aqc_opc_queue_shutdown);
389
390 if (unloading)
391 cmd->driver_unloading = cpu_to_le32(I40E_AQ_DRIVER_UNLOADING);
392 status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
393
394 return status;
395}
396
Anjali Singhai Jaine50c8d62015-06-05 12:20:27 -0400397/**
398 * i40e_aq_get_set_rss_lut
399 * @hw: pointer to the hardware structure
400 * @vsi_id: vsi fw index
401 * @pf_lut: for PF table set true, for VSI table set false
402 * @lut: pointer to the lut buffer provided by the caller
403 * @lut_size: size of the lut buffer
404 * @set: set true to set the table, false to get the table
405 *
406 * Internal function to get or set RSS look up table
407 **/
408static i40e_status i40e_aq_get_set_rss_lut(struct i40e_hw *hw,
409 u16 vsi_id, bool pf_lut,
410 u8 *lut, u16 lut_size,
411 bool set)
412{
413 i40e_status status;
414 struct i40e_aq_desc desc;
415 struct i40e_aqc_get_set_rss_lut *cmd_resp =
416 (struct i40e_aqc_get_set_rss_lut *)&desc.params.raw;
417
418 if (set)
419 i40e_fill_default_direct_cmd_desc(&desc,
420 i40e_aqc_opc_set_rss_lut);
421 else
422 i40e_fill_default_direct_cmd_desc(&desc,
423 i40e_aqc_opc_get_rss_lut);
424
425 /* Indirect command */
426 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
427 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
428
429 cmd_resp->vsi_id =
430 cpu_to_le16((u16)((vsi_id <<
431 I40E_AQC_SET_RSS_LUT_VSI_ID_SHIFT) &
432 I40E_AQC_SET_RSS_LUT_VSI_ID_MASK));
433 cmd_resp->vsi_id |= cpu_to_le16((u16)I40E_AQC_SET_RSS_LUT_VSI_VALID);
434
435 if (pf_lut)
436 cmd_resp->flags |= cpu_to_le16((u16)
437 ((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_PF <<
438 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
439 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
440 else
441 cmd_resp->flags |= cpu_to_le16((u16)
442 ((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_VSI <<
443 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
444 I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
445
Anjali Singhai Jaine50c8d62015-06-05 12:20:27 -0400446 status = i40e_asq_send_command(hw, &desc, lut, lut_size, NULL);
447
448 return status;
449}
450
451/**
452 * i40e_aq_get_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 * get the RSS lookup table, PF or VSI type
460 **/
461i40e_status i40e_aq_get_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,
465 false);
466}
467
468/**
469 * i40e_aq_set_rss_lut
470 * @hw: pointer to the hardware structure
471 * @vsi_id: vsi fw index
472 * @pf_lut: for PF table set true, for VSI table set false
473 * @lut: pointer to the lut buffer provided by the caller
474 * @lut_size: size of the lut buffer
475 *
476 * set the RSS lookup table, PF or VSI type
477 **/
478i40e_status i40e_aq_set_rss_lut(struct i40e_hw *hw, u16 vsi_id,
479 bool pf_lut, u8 *lut, u16 lut_size)
480{
481 return i40e_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size, true);
482}
483
484/**
485 * i40e_aq_get_set_rss_key
486 * @hw: pointer to the hw struct
487 * @vsi_id: vsi fw index
488 * @key: pointer to key info struct
489 * @set: set true to set the key, false to get the key
490 *
491 * get the RSS key per VSI
492 **/
493static i40e_status i40e_aq_get_set_rss_key(struct i40e_hw *hw,
494 u16 vsi_id,
495 struct i40e_aqc_get_set_rss_key_data *key,
496 bool set)
497{
498 i40e_status status;
499 struct i40e_aq_desc desc;
500 struct i40e_aqc_get_set_rss_key *cmd_resp =
501 (struct i40e_aqc_get_set_rss_key *)&desc.params.raw;
502 u16 key_size = sizeof(struct i40e_aqc_get_set_rss_key_data);
503
504 if (set)
505 i40e_fill_default_direct_cmd_desc(&desc,
506 i40e_aqc_opc_set_rss_key);
507 else
508 i40e_fill_default_direct_cmd_desc(&desc,
509 i40e_aqc_opc_get_rss_key);
510
511 /* Indirect command */
512 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
513 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
514
515 cmd_resp->vsi_id =
516 cpu_to_le16((u16)((vsi_id <<
517 I40E_AQC_SET_RSS_KEY_VSI_ID_SHIFT) &
518 I40E_AQC_SET_RSS_KEY_VSI_ID_MASK));
519 cmd_resp->vsi_id |= cpu_to_le16((u16)I40E_AQC_SET_RSS_KEY_VSI_VALID);
Anjali Singhai Jaine50c8d62015-06-05 12:20:27 -0400520
521 status = i40e_asq_send_command(hw, &desc, key, key_size, NULL);
522
523 return status;
524}
525
526/**
527 * i40e_aq_get_rss_key
528 * @hw: pointer to the hw struct
529 * @vsi_id: vsi fw index
530 * @key: pointer to key info struct
531 *
532 **/
533i40e_status i40e_aq_get_rss_key(struct i40e_hw *hw,
534 u16 vsi_id,
535 struct i40e_aqc_get_set_rss_key_data *key)
536{
537 return i40e_aq_get_set_rss_key(hw, vsi_id, key, false);
538}
539
540/**
541 * i40e_aq_set_rss_key
542 * @hw: pointer to the hw struct
543 * @vsi_id: vsi fw index
544 * @key: pointer to key info struct
545 *
546 * set the RSS key per VSI
547 **/
548i40e_status i40e_aq_set_rss_key(struct i40e_hw *hw,
549 u16 vsi_id,
550 struct i40e_aqc_get_set_rss_key_data *key)
551{
552 return i40e_aq_get_set_rss_key(hw, vsi_id, key, true);
553}
554
Jesse Brandeburg206812b2014-02-12 01:45:33 +0000555/* The i40e_ptype_lookup table is used to convert from the 8-bit ptype in the
556 * hardware to a bit-field that can be used by SW to more easily determine the
557 * packet type.
558 *
559 * Macros are used to shorten the table lines and make this table human
560 * readable.
561 *
562 * We store the PTYPE in the top byte of the bit field - this is just so that
563 * we can check that the table doesn't have a row missing, as the index into
564 * the table should be the PTYPE.
565 *
566 * Typical work flow:
567 *
568 * IF NOT i40e_ptype_lookup[ptype].known
569 * THEN
570 * Packet is unknown
571 * ELSE IF i40e_ptype_lookup[ptype].outer_ip == I40E_RX_PTYPE_OUTER_IP
572 * Use the rest of the fields to look at the tunnels, inner protocols, etc
573 * ELSE
574 * Use the enum i40e_rx_l2_ptype to decode the packet type
575 * ENDIF
576 */
577
578/* macro to make the table lines short */
579#define I40E_PTT(PTYPE, OUTER_IP, OUTER_IP_VER, OUTER_FRAG, T, TE, TEF, I, PL)\
580 { PTYPE, \
581 1, \
582 I40E_RX_PTYPE_OUTER_##OUTER_IP, \
583 I40E_RX_PTYPE_OUTER_##OUTER_IP_VER, \
584 I40E_RX_PTYPE_##OUTER_FRAG, \
585 I40E_RX_PTYPE_TUNNEL_##T, \
586 I40E_RX_PTYPE_TUNNEL_END_##TE, \
587 I40E_RX_PTYPE_##TEF, \
588 I40E_RX_PTYPE_INNER_PROT_##I, \
589 I40E_RX_PTYPE_PAYLOAD_LAYER_##PL }
590
591#define I40E_PTT_UNUSED_ENTRY(PTYPE) \
592 { PTYPE, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
593
594/* shorter macros makes the table fit but are terse */
595#define I40E_RX_PTYPE_NOF I40E_RX_PTYPE_NOT_FRAG
596#define I40E_RX_PTYPE_FRG I40E_RX_PTYPE_FRAG
597#define I40E_RX_PTYPE_INNER_PROT_TS I40E_RX_PTYPE_INNER_PROT_TIMESYNC
598
599/* Lookup table mapping the HW PTYPE to the bit field for decoding */
600struct i40e_rx_ptype_decoded i40e_ptype_lookup[] = {
601 /* L2 Packet types */
602 I40E_PTT_UNUSED_ENTRY(0),
603 I40E_PTT(1, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
604 I40E_PTT(2, L2, NONE, NOF, NONE, NONE, NOF, TS, PAY2),
605 I40E_PTT(3, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
606 I40E_PTT_UNUSED_ENTRY(4),
607 I40E_PTT_UNUSED_ENTRY(5),
608 I40E_PTT(6, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
609 I40E_PTT(7, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
610 I40E_PTT_UNUSED_ENTRY(8),
611 I40E_PTT_UNUSED_ENTRY(9),
612 I40E_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
613 I40E_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
614 I40E_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
615 I40E_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
616 I40E_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
617 I40E_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
618 I40E_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
619 I40E_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
620 I40E_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
621 I40E_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
622 I40E_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
623 I40E_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
624
625 /* Non Tunneled IPv4 */
626 I40E_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
627 I40E_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
628 I40E_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP, PAY4),
629 I40E_PTT_UNUSED_ENTRY(25),
630 I40E_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP, PAY4),
631 I40E_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
632 I40E_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
633
634 /* IPv4 --> IPv4 */
635 I40E_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
636 I40E_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
637 I40E_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
638 I40E_PTT_UNUSED_ENTRY(32),
639 I40E_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
640 I40E_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
641 I40E_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
642
643 /* IPv4 --> IPv6 */
644 I40E_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
645 I40E_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
646 I40E_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
647 I40E_PTT_UNUSED_ENTRY(39),
648 I40E_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
649 I40E_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
650 I40E_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
651
652 /* IPv4 --> GRE/NAT */
653 I40E_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
654
655 /* IPv4 --> GRE/NAT --> IPv4 */
656 I40E_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
657 I40E_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
658 I40E_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
659 I40E_PTT_UNUSED_ENTRY(47),
660 I40E_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
661 I40E_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
662 I40E_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
663
664 /* IPv4 --> GRE/NAT --> IPv6 */
665 I40E_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
666 I40E_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
667 I40E_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
668 I40E_PTT_UNUSED_ENTRY(54),
669 I40E_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
670 I40E_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
671 I40E_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
672
673 /* IPv4 --> GRE/NAT --> MAC */
674 I40E_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
675
676 /* IPv4 --> GRE/NAT --> MAC --> IPv4 */
677 I40E_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
678 I40E_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
679 I40E_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
680 I40E_PTT_UNUSED_ENTRY(62),
681 I40E_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
682 I40E_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
683 I40E_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
684
685 /* IPv4 --> GRE/NAT -> MAC --> IPv6 */
686 I40E_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
687 I40E_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
688 I40E_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
689 I40E_PTT_UNUSED_ENTRY(69),
690 I40E_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
691 I40E_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
692 I40E_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
693
694 /* IPv4 --> GRE/NAT --> MAC/VLAN */
695 I40E_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
696
697 /* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
698 I40E_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
699 I40E_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
700 I40E_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
701 I40E_PTT_UNUSED_ENTRY(77),
702 I40E_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
703 I40E_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
704 I40E_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
705
706 /* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
707 I40E_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
708 I40E_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
709 I40E_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
710 I40E_PTT_UNUSED_ENTRY(84),
711 I40E_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
712 I40E_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
713 I40E_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
714
715 /* Non Tunneled IPv6 */
716 I40E_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
717 I40E_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
718 I40E_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP, PAY3),
719 I40E_PTT_UNUSED_ENTRY(91),
720 I40E_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP, PAY4),
721 I40E_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
722 I40E_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
723
724 /* IPv6 --> IPv4 */
725 I40E_PTT(95, IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
726 I40E_PTT(96, IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
727 I40E_PTT(97, IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
728 I40E_PTT_UNUSED_ENTRY(98),
729 I40E_PTT(99, IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
730 I40E_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
731 I40E_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
732
733 /* IPv6 --> IPv6 */
734 I40E_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
735 I40E_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
736 I40E_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
737 I40E_PTT_UNUSED_ENTRY(105),
738 I40E_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
739 I40E_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
740 I40E_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
741
742 /* IPv6 --> GRE/NAT */
743 I40E_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
744
745 /* IPv6 --> GRE/NAT -> IPv4 */
746 I40E_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
747 I40E_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
748 I40E_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
749 I40E_PTT_UNUSED_ENTRY(113),
750 I40E_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
751 I40E_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
752 I40E_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
753
754 /* IPv6 --> GRE/NAT -> IPv6 */
755 I40E_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
756 I40E_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
757 I40E_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
758 I40E_PTT_UNUSED_ENTRY(120),
759 I40E_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
760 I40E_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
761 I40E_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
762
763 /* IPv6 --> GRE/NAT -> MAC */
764 I40E_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
765
766 /* IPv6 --> GRE/NAT -> MAC -> IPv4 */
767 I40E_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
768 I40E_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
769 I40E_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
770 I40E_PTT_UNUSED_ENTRY(128),
771 I40E_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
772 I40E_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
773 I40E_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
774
775 /* IPv6 --> GRE/NAT -> MAC -> IPv6 */
776 I40E_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
777 I40E_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
778 I40E_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
779 I40E_PTT_UNUSED_ENTRY(135),
780 I40E_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
781 I40E_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
782 I40E_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
783
784 /* IPv6 --> GRE/NAT -> MAC/VLAN */
785 I40E_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
786
787 /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
788 I40E_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
789 I40E_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
790 I40E_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
791 I40E_PTT_UNUSED_ENTRY(143),
792 I40E_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
793 I40E_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
794 I40E_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
795
796 /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
797 I40E_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
798 I40E_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
799 I40E_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
800 I40E_PTT_UNUSED_ENTRY(150),
801 I40E_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
802 I40E_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
803 I40E_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
804
805 /* unused entries */
806 I40E_PTT_UNUSED_ENTRY(154),
807 I40E_PTT_UNUSED_ENTRY(155),
808 I40E_PTT_UNUSED_ENTRY(156),
809 I40E_PTT_UNUSED_ENTRY(157),
810 I40E_PTT_UNUSED_ENTRY(158),
811 I40E_PTT_UNUSED_ENTRY(159),
812
813 I40E_PTT_UNUSED_ENTRY(160),
814 I40E_PTT_UNUSED_ENTRY(161),
815 I40E_PTT_UNUSED_ENTRY(162),
816 I40E_PTT_UNUSED_ENTRY(163),
817 I40E_PTT_UNUSED_ENTRY(164),
818 I40E_PTT_UNUSED_ENTRY(165),
819 I40E_PTT_UNUSED_ENTRY(166),
820 I40E_PTT_UNUSED_ENTRY(167),
821 I40E_PTT_UNUSED_ENTRY(168),
822 I40E_PTT_UNUSED_ENTRY(169),
823
824 I40E_PTT_UNUSED_ENTRY(170),
825 I40E_PTT_UNUSED_ENTRY(171),
826 I40E_PTT_UNUSED_ENTRY(172),
827 I40E_PTT_UNUSED_ENTRY(173),
828 I40E_PTT_UNUSED_ENTRY(174),
829 I40E_PTT_UNUSED_ENTRY(175),
830 I40E_PTT_UNUSED_ENTRY(176),
831 I40E_PTT_UNUSED_ENTRY(177),
832 I40E_PTT_UNUSED_ENTRY(178),
833 I40E_PTT_UNUSED_ENTRY(179),
834
835 I40E_PTT_UNUSED_ENTRY(180),
836 I40E_PTT_UNUSED_ENTRY(181),
837 I40E_PTT_UNUSED_ENTRY(182),
838 I40E_PTT_UNUSED_ENTRY(183),
839 I40E_PTT_UNUSED_ENTRY(184),
840 I40E_PTT_UNUSED_ENTRY(185),
841 I40E_PTT_UNUSED_ENTRY(186),
842 I40E_PTT_UNUSED_ENTRY(187),
843 I40E_PTT_UNUSED_ENTRY(188),
844 I40E_PTT_UNUSED_ENTRY(189),
845
846 I40E_PTT_UNUSED_ENTRY(190),
847 I40E_PTT_UNUSED_ENTRY(191),
848 I40E_PTT_UNUSED_ENTRY(192),
849 I40E_PTT_UNUSED_ENTRY(193),
850 I40E_PTT_UNUSED_ENTRY(194),
851 I40E_PTT_UNUSED_ENTRY(195),
852 I40E_PTT_UNUSED_ENTRY(196),
853 I40E_PTT_UNUSED_ENTRY(197),
854 I40E_PTT_UNUSED_ENTRY(198),
855 I40E_PTT_UNUSED_ENTRY(199),
856
857 I40E_PTT_UNUSED_ENTRY(200),
858 I40E_PTT_UNUSED_ENTRY(201),
859 I40E_PTT_UNUSED_ENTRY(202),
860 I40E_PTT_UNUSED_ENTRY(203),
861 I40E_PTT_UNUSED_ENTRY(204),
862 I40E_PTT_UNUSED_ENTRY(205),
863 I40E_PTT_UNUSED_ENTRY(206),
864 I40E_PTT_UNUSED_ENTRY(207),
865 I40E_PTT_UNUSED_ENTRY(208),
866 I40E_PTT_UNUSED_ENTRY(209),
867
868 I40E_PTT_UNUSED_ENTRY(210),
869 I40E_PTT_UNUSED_ENTRY(211),
870 I40E_PTT_UNUSED_ENTRY(212),
871 I40E_PTT_UNUSED_ENTRY(213),
872 I40E_PTT_UNUSED_ENTRY(214),
873 I40E_PTT_UNUSED_ENTRY(215),
874 I40E_PTT_UNUSED_ENTRY(216),
875 I40E_PTT_UNUSED_ENTRY(217),
876 I40E_PTT_UNUSED_ENTRY(218),
877 I40E_PTT_UNUSED_ENTRY(219),
878
879 I40E_PTT_UNUSED_ENTRY(220),
880 I40E_PTT_UNUSED_ENTRY(221),
881 I40E_PTT_UNUSED_ENTRY(222),
882 I40E_PTT_UNUSED_ENTRY(223),
883 I40E_PTT_UNUSED_ENTRY(224),
884 I40E_PTT_UNUSED_ENTRY(225),
885 I40E_PTT_UNUSED_ENTRY(226),
886 I40E_PTT_UNUSED_ENTRY(227),
887 I40E_PTT_UNUSED_ENTRY(228),
888 I40E_PTT_UNUSED_ENTRY(229),
889
890 I40E_PTT_UNUSED_ENTRY(230),
891 I40E_PTT_UNUSED_ENTRY(231),
892 I40E_PTT_UNUSED_ENTRY(232),
893 I40E_PTT_UNUSED_ENTRY(233),
894 I40E_PTT_UNUSED_ENTRY(234),
895 I40E_PTT_UNUSED_ENTRY(235),
896 I40E_PTT_UNUSED_ENTRY(236),
897 I40E_PTT_UNUSED_ENTRY(237),
898 I40E_PTT_UNUSED_ENTRY(238),
899 I40E_PTT_UNUSED_ENTRY(239),
900
901 I40E_PTT_UNUSED_ENTRY(240),
902 I40E_PTT_UNUSED_ENTRY(241),
903 I40E_PTT_UNUSED_ENTRY(242),
904 I40E_PTT_UNUSED_ENTRY(243),
905 I40E_PTT_UNUSED_ENTRY(244),
906 I40E_PTT_UNUSED_ENTRY(245),
907 I40E_PTT_UNUSED_ENTRY(246),
908 I40E_PTT_UNUSED_ENTRY(247),
909 I40E_PTT_UNUSED_ENTRY(248),
910 I40E_PTT_UNUSED_ENTRY(249),
911
912 I40E_PTT_UNUSED_ENTRY(250),
913 I40E_PTT_UNUSED_ENTRY(251),
914 I40E_PTT_UNUSED_ENTRY(252),
915 I40E_PTT_UNUSED_ENTRY(253),
916 I40E_PTT_UNUSED_ENTRY(254),
917 I40E_PTT_UNUSED_ENTRY(255)
918};
919
Anjali Singhai Jaine1860d82013-11-28 06:39:45 +0000920/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000921 * i40e_init_shared_code - Initialize the shared code
922 * @hw: pointer to hardware structure
923 *
924 * This assigns the MAC type and PHY code and inits the NVM.
925 * Does not touch the hardware. This function must be called prior to any
926 * other function in the shared code. The i40e_hw structure should be
927 * memset to 0 prior to calling this function. The following fields in
928 * hw structure should be filled in prior to calling this function:
929 * hw_addr, back, device_id, vendor_id, subsystem_device_id,
930 * subsystem_vendor_id, and revision_id
931 **/
932i40e_status i40e_init_shared_code(struct i40e_hw *hw)
933{
934 i40e_status status = 0;
Shannon Nelson5fb11d72014-11-13 03:06:19 +0000935 u32 port, ari, func_rid;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000936
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000937 i40e_set_mac_type(hw);
938
939 switch (hw->mac.type) {
940 case I40E_MAC_XL710:
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -0400941 case I40E_MAC_X722:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000942 break;
943 default:
944 return I40E_ERR_DEVICE_NOT_SUPPORTED;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000945 }
946
Shannon Nelsonaf89d26c2013-12-11 08:17:14 +0000947 hw->phy.get_link_info = true;
948
Shannon Nelson5fb11d72014-11-13 03:06:19 +0000949 /* Determine port number and PF number*/
950 port = (rd32(hw, I40E_PFGEN_PORTNUM) & I40E_PFGEN_PORTNUM_PORT_NUM_MASK)
951 >> I40E_PFGEN_PORTNUM_PORT_NUM_SHIFT;
952 hw->port = (u8)port;
953 ari = (rd32(hw, I40E_GLPCI_CAPSUP) & I40E_GLPCI_CAPSUP_ARI_EN_MASK) >>
954 I40E_GLPCI_CAPSUP_ARI_EN_SHIFT;
955 func_rid = rd32(hw, I40E_PF_FUNC_RID);
956 if (ari)
957 hw->pf_id = (u8)(func_rid & 0xff);
Shannon Nelson5f9116a2013-12-11 08:17:13 +0000958 else
Shannon Nelson5fb11d72014-11-13 03:06:19 +0000959 hw->pf_id = (u8)(func_rid & 0x7);
Shannon Nelson5f9116a2013-12-11 08:17:13 +0000960
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000961 status = i40e_init_nvm(hw);
962 return status;
963}
964
965/**
966 * i40e_aq_mac_address_read - Retrieve the MAC addresses
967 * @hw: pointer to the hw struct
968 * @flags: a return indicator of what addresses were added to the addr store
969 * @addrs: the requestor's mac addr store
970 * @cmd_details: pointer to command details structure or NULL
971 **/
972static i40e_status i40e_aq_mac_address_read(struct i40e_hw *hw,
973 u16 *flags,
974 struct i40e_aqc_mac_address_read_data *addrs,
975 struct i40e_asq_cmd_details *cmd_details)
976{
977 struct i40e_aq_desc desc;
978 struct i40e_aqc_mac_address_read *cmd_data =
979 (struct i40e_aqc_mac_address_read *)&desc.params.raw;
980 i40e_status status;
981
982 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_mac_address_read);
983 desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF);
984
985 status = i40e_asq_send_command(hw, &desc, addrs,
986 sizeof(*addrs), cmd_details);
987 *flags = le16_to_cpu(cmd_data->command_flags);
988
989 return status;
990}
991
992/**
993 * i40e_aq_mac_address_write - Change the MAC addresses
994 * @hw: pointer to the hw struct
995 * @flags: indicates which MAC to be written
996 * @mac_addr: address to write
997 * @cmd_details: pointer to command details structure or NULL
998 **/
999i40e_status i40e_aq_mac_address_write(struct i40e_hw *hw,
1000 u16 flags, u8 *mac_addr,
1001 struct i40e_asq_cmd_details *cmd_details)
1002{
1003 struct i40e_aq_desc desc;
1004 struct i40e_aqc_mac_address_write *cmd_data =
1005 (struct i40e_aqc_mac_address_write *)&desc.params.raw;
1006 i40e_status status;
1007
1008 i40e_fill_default_direct_cmd_desc(&desc,
1009 i40e_aqc_opc_mac_address_write);
1010 cmd_data->command_flags = cpu_to_le16(flags);
Kamil Krawczyk55c29c32013-12-18 13:45:52 +00001011 cmd_data->mac_sah = cpu_to_le16((u16)mac_addr[0] << 8 | mac_addr[1]);
1012 cmd_data->mac_sal = cpu_to_le32(((u32)mac_addr[2] << 24) |
1013 ((u32)mac_addr[3] << 16) |
1014 ((u32)mac_addr[4] << 8) |
1015 mac_addr[5]);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001016
1017 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1018
1019 return status;
1020}
1021
1022/**
1023 * i40e_get_mac_addr - get MAC address
1024 * @hw: pointer to the HW structure
1025 * @mac_addr: pointer to MAC address
1026 *
1027 * Reads the adapter's MAC address from register
1028 **/
1029i40e_status i40e_get_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
1030{
1031 struct i40e_aqc_mac_address_read_data addrs;
1032 i40e_status status;
1033 u16 flags = 0;
1034
1035 status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
1036
1037 if (flags & I40E_AQC_LAN_ADDR_VALID)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001038 ether_addr_copy(mac_addr, addrs.pf_lan_mac);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001039
1040 return status;
1041}
1042
1043/**
Neerav Parikh1f224ad2014-02-12 01:45:31 +00001044 * i40e_get_port_mac_addr - get Port MAC address
1045 * @hw: pointer to the HW structure
1046 * @mac_addr: pointer to Port MAC address
1047 *
1048 * Reads the adapter's Port MAC address
1049 **/
1050i40e_status i40e_get_port_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
1051{
1052 struct i40e_aqc_mac_address_read_data addrs;
1053 i40e_status status;
1054 u16 flags = 0;
1055
1056 status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
1057 if (status)
1058 return status;
1059
1060 if (flags & I40E_AQC_PORT_ADDR_VALID)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001061 ether_addr_copy(mac_addr, addrs.port_mac);
Neerav Parikh1f224ad2014-02-12 01:45:31 +00001062 else
1063 status = I40E_ERR_INVALID_MAC_ADDR;
1064
1065 return status;
1066}
1067
1068/**
Matt Jared351499ab2014-04-23 04:50:03 +00001069 * i40e_pre_tx_queue_cfg - pre tx queue configure
1070 * @hw: pointer to the HW structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001071 * @queue: target PF queue index
Matt Jared351499ab2014-04-23 04:50:03 +00001072 * @enable: state change request
1073 *
1074 * Handles hw requirement to indicate intention to enable
1075 * or disable target queue.
1076 **/
1077void i40e_pre_tx_queue_cfg(struct i40e_hw *hw, u32 queue, bool enable)
1078{
Shannon Nelsondfb699f2014-05-22 06:32:28 +00001079 u32 abs_queue_idx = hw->func_caps.base_queue + queue;
Matt Jared351499ab2014-04-23 04:50:03 +00001080 u32 reg_block = 0;
Shannon Nelsondfb699f2014-05-22 06:32:28 +00001081 u32 reg_val;
Matt Jared351499ab2014-04-23 04:50:03 +00001082
Christopher Pau24a768c2014-06-04 20:41:59 +00001083 if (abs_queue_idx >= 128) {
Matt Jared351499ab2014-04-23 04:50:03 +00001084 reg_block = abs_queue_idx / 128;
Christopher Pau24a768c2014-06-04 20:41:59 +00001085 abs_queue_idx %= 128;
1086 }
Matt Jared351499ab2014-04-23 04:50:03 +00001087
1088 reg_val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
1089 reg_val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
1090 reg_val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
1091
1092 if (enable)
1093 reg_val |= I40E_GLLAN_TXPRE_QDIS_CLEAR_QDIS_MASK;
1094 else
1095 reg_val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
1096
1097 wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), reg_val);
1098}
Vasu Dev38e00432014-08-01 13:27:03 -07001099#ifdef I40E_FCOE
1100
1101/**
1102 * i40e_get_san_mac_addr - get SAN MAC address
1103 * @hw: pointer to the HW structure
1104 * @mac_addr: pointer to SAN MAC address
1105 *
1106 * Reads the adapter's SAN MAC address from NVM
1107 **/
1108i40e_status i40e_get_san_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
1109{
1110 struct i40e_aqc_mac_address_read_data addrs;
1111 i40e_status status;
1112 u16 flags = 0;
1113
1114 status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
1115 if (status)
1116 return status;
1117
1118 if (flags & I40E_AQC_SAN_ADDR_VALID)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001119 ether_addr_copy(mac_addr, addrs.pf_san_mac);
Vasu Dev38e00432014-08-01 13:27:03 -07001120 else
1121 status = I40E_ERR_INVALID_MAC_ADDR;
1122
1123 return status;
1124}
1125#endif
Matt Jared351499ab2014-04-23 04:50:03 +00001126
1127/**
Kamil Krawczyk18f680c2014-12-11 07:06:31 +00001128 * i40e_read_pba_string - Reads part number string from EEPROM
1129 * @hw: pointer to hardware structure
1130 * @pba_num: stores the part number string from the EEPROM
1131 * @pba_num_size: part number string buffer length
1132 *
1133 * Reads the part number string from the EEPROM.
1134 **/
1135i40e_status i40e_read_pba_string(struct i40e_hw *hw, u8 *pba_num,
1136 u32 pba_num_size)
1137{
1138 i40e_status status = 0;
1139 u16 pba_word = 0;
1140 u16 pba_size = 0;
1141 u16 pba_ptr = 0;
1142 u16 i = 0;
1143
1144 status = i40e_read_nvm_word(hw, I40E_SR_PBA_FLAGS, &pba_word);
1145 if (status || (pba_word != 0xFAFA)) {
1146 hw_dbg(hw, "Failed to read PBA flags or flag is invalid.\n");
1147 return status;
1148 }
1149
1150 status = i40e_read_nvm_word(hw, I40E_SR_PBA_BLOCK_PTR, &pba_ptr);
1151 if (status) {
1152 hw_dbg(hw, "Failed to read PBA Block pointer.\n");
1153 return status;
1154 }
1155
1156 status = i40e_read_nvm_word(hw, pba_ptr, &pba_size);
1157 if (status) {
1158 hw_dbg(hw, "Failed to read PBA Block size.\n");
1159 return status;
1160 }
1161
1162 /* Subtract one to get PBA word count (PBA Size word is included in
1163 * total size)
1164 */
1165 pba_size--;
1166 if (pba_num_size < (((u32)pba_size * 2) + 1)) {
1167 hw_dbg(hw, "Buffer to small for PBA data.\n");
1168 return I40E_ERR_PARAM;
1169 }
1170
1171 for (i = 0; i < pba_size; i++) {
1172 status = i40e_read_nvm_word(hw, (pba_ptr + 1) + i, &pba_word);
1173 if (status) {
1174 hw_dbg(hw, "Failed to read PBA Block word %d.\n", i);
1175 return status;
1176 }
1177
1178 pba_num[(i * 2)] = (pba_word >> 8) & 0xFF;
1179 pba_num[(i * 2) + 1] = pba_word & 0xFF;
1180 }
1181 pba_num[(pba_size * 2)] = '\0';
1182
1183 return status;
1184}
1185
1186/**
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001187 * i40e_get_media_type - Gets media type
1188 * @hw: pointer to the hardware structure
1189 **/
1190static enum i40e_media_type i40e_get_media_type(struct i40e_hw *hw)
1191{
1192 enum i40e_media_type media;
1193
1194 switch (hw->phy.link_info.phy_type) {
1195 case I40E_PHY_TYPE_10GBASE_SR:
1196 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +00001197 case I40E_PHY_TYPE_1000BASE_SX:
1198 case I40E_PHY_TYPE_1000BASE_LX:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001199 case I40E_PHY_TYPE_40GBASE_SR4:
1200 case I40E_PHY_TYPE_40GBASE_LR4:
1201 media = I40E_MEDIA_TYPE_FIBER;
1202 break;
1203 case I40E_PHY_TYPE_100BASE_TX:
1204 case I40E_PHY_TYPE_1000BASE_T:
1205 case I40E_PHY_TYPE_10GBASE_T:
1206 media = I40E_MEDIA_TYPE_BASET;
1207 break;
1208 case I40E_PHY_TYPE_10GBASE_CR1_CU:
1209 case I40E_PHY_TYPE_40GBASE_CR4_CU:
1210 case I40E_PHY_TYPE_10GBASE_CR1:
1211 case I40E_PHY_TYPE_40GBASE_CR4:
1212 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +00001213 case I40E_PHY_TYPE_40GBASE_AOC:
1214 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001215 media = I40E_MEDIA_TYPE_DA;
1216 break;
1217 case I40E_PHY_TYPE_1000BASE_KX:
1218 case I40E_PHY_TYPE_10GBASE_KX4:
1219 case I40E_PHY_TYPE_10GBASE_KR:
1220 case I40E_PHY_TYPE_40GBASE_KR4:
Jesse Brandeburgae24b402015-03-27 00:12:09 -07001221 case I40E_PHY_TYPE_20GBASE_KR2:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001222 media = I40E_MEDIA_TYPE_BACKPLANE;
1223 break;
1224 case I40E_PHY_TYPE_SGMII:
1225 case I40E_PHY_TYPE_XAUI:
1226 case I40E_PHY_TYPE_XFI:
1227 case I40E_PHY_TYPE_XLAUI:
1228 case I40E_PHY_TYPE_XLPPI:
1229 default:
1230 media = I40E_MEDIA_TYPE_UNKNOWN;
1231 break;
1232 }
1233
1234 return media;
1235}
1236
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001237#define I40E_PF_RESET_WAIT_COUNT_A0 200
Akeem G Abodunrin8af580d2015-03-27 00:12:10 -07001238#define I40E_PF_RESET_WAIT_COUNT 200
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001239/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001240 * i40e_pf_reset - Reset the PF
1241 * @hw: pointer to the hardware structure
1242 *
1243 * Assuming someone else has triggered a global reset,
1244 * assure the global reset is complete and then reset the PF
1245 **/
1246i40e_status i40e_pf_reset(struct i40e_hw *hw)
1247{
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001248 u32 cnt = 0;
Shannon Nelson42794bd2013-12-11 08:17:10 +00001249 u32 cnt1 = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001250 u32 reg = 0;
1251 u32 grst_del;
1252
1253 /* Poll for Global Reset steady state in case of recent GRST.
1254 * The grst delay value is in 100ms units, and we'll wait a
1255 * couple counts longer to be sure we don't just miss the end.
1256 */
Shannon Nelsonde78fc52015-02-21 06:41:47 +00001257 grst_del = (rd32(hw, I40E_GLGEN_RSTCTL) &
1258 I40E_GLGEN_RSTCTL_GRSTDEL_MASK) >>
1259 I40E_GLGEN_RSTCTL_GRSTDEL_SHIFT;
Paul M Stillwell Jr22e05bd2015-08-26 15:14:07 -04001260 for (cnt = 0; cnt < grst_del + 10; cnt++) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001261 reg = rd32(hw, I40E_GLGEN_RSTAT);
1262 if (!(reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK))
1263 break;
1264 msleep(100);
1265 }
1266 if (reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
1267 hw_dbg(hw, "Global reset polling failed to complete.\n");
1268 return I40E_ERR_RESET_FAILED;
1269 }
1270
Shannon Nelson42794bd2013-12-11 08:17:10 +00001271 /* Now Wait for the FW to be ready */
1272 for (cnt1 = 0; cnt1 < I40E_PF_RESET_WAIT_COUNT; cnt1++) {
1273 reg = rd32(hw, I40E_GLNVM_ULD);
1274 reg &= (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
1275 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK);
1276 if (reg == (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
1277 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK)) {
1278 hw_dbg(hw, "Core and Global modules ready %d\n", cnt1);
1279 break;
1280 }
1281 usleep_range(10000, 20000);
1282 }
1283 if (!(reg & (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
1284 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK))) {
1285 hw_dbg(hw, "wait for FW Reset complete timedout\n");
1286 hw_dbg(hw, "I40E_GLNVM_ULD = 0x%x\n", reg);
1287 return I40E_ERR_RESET_FAILED;
1288 }
1289
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001290 /* If there was a Global Reset in progress when we got here,
1291 * we don't need to do the PF Reset
1292 */
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001293 if (!cnt) {
1294 if (hw->revision_id == 0)
1295 cnt = I40E_PF_RESET_WAIT_COUNT_A0;
1296 else
1297 cnt = I40E_PF_RESET_WAIT_COUNT;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001298 reg = rd32(hw, I40E_PFGEN_CTRL);
1299 wr32(hw, I40E_PFGEN_CTRL,
1300 (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001301 for (; cnt; cnt--) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001302 reg = rd32(hw, I40E_PFGEN_CTRL);
1303 if (!(reg & I40E_PFGEN_CTRL_PFSWR_MASK))
1304 break;
1305 usleep_range(1000, 2000);
1306 }
1307 if (reg & I40E_PFGEN_CTRL_PFSWR_MASK) {
1308 hw_dbg(hw, "PF reset polling failed to complete.\n");
1309 return I40E_ERR_RESET_FAILED;
1310 }
1311 }
1312
1313 i40e_clear_pxe_mode(hw);
Shannon Nelson922680b2013-12-18 05:29:17 +00001314
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001315 return 0;
1316}
1317
1318/**
Shannon Nelson838d41d2014-06-04 20:41:27 +00001319 * i40e_clear_hw - clear out any left over hw state
1320 * @hw: pointer to the hw struct
1321 *
1322 * Clear queues and interrupts, typically called at init time,
1323 * but after the capabilities have been found so we know how many
1324 * queues and msix vectors have been allocated.
1325 **/
1326void i40e_clear_hw(struct i40e_hw *hw)
1327{
1328 u32 num_queues, base_queue;
1329 u32 num_pf_int;
1330 u32 num_vf_int;
1331 u32 num_vfs;
1332 u32 i, j;
1333 u32 val;
1334 u32 eol = 0x7ff;
1335
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001336 /* get number of interrupts, queues, and VFs */
Shannon Nelson838d41d2014-06-04 20:41:27 +00001337 val = rd32(hw, I40E_GLPCI_CNF2);
1338 num_pf_int = (val & I40E_GLPCI_CNF2_MSI_X_PF_N_MASK) >>
1339 I40E_GLPCI_CNF2_MSI_X_PF_N_SHIFT;
1340 num_vf_int = (val & I40E_GLPCI_CNF2_MSI_X_VF_N_MASK) >>
1341 I40E_GLPCI_CNF2_MSI_X_VF_N_SHIFT;
1342
1343 val = rd32(hw, I40E_PFLAN_QALLOC);
1344 base_queue = (val & I40E_PFLAN_QALLOC_FIRSTQ_MASK) >>
1345 I40E_PFLAN_QALLOC_FIRSTQ_SHIFT;
1346 j = (val & I40E_PFLAN_QALLOC_LASTQ_MASK) >>
1347 I40E_PFLAN_QALLOC_LASTQ_SHIFT;
1348 if (val & I40E_PFLAN_QALLOC_VALID_MASK)
1349 num_queues = (j - base_queue) + 1;
1350 else
1351 num_queues = 0;
1352
1353 val = rd32(hw, I40E_PF_VT_PFALLOC);
1354 i = (val & I40E_PF_VT_PFALLOC_FIRSTVF_MASK) >>
1355 I40E_PF_VT_PFALLOC_FIRSTVF_SHIFT;
1356 j = (val & I40E_PF_VT_PFALLOC_LASTVF_MASK) >>
1357 I40E_PF_VT_PFALLOC_LASTVF_SHIFT;
1358 if (val & I40E_PF_VT_PFALLOC_VALID_MASK)
1359 num_vfs = (j - i) + 1;
1360 else
1361 num_vfs = 0;
1362
1363 /* stop all the interrupts */
1364 wr32(hw, I40E_PFINT_ICR0_ENA, 0);
1365 val = 0x3 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT;
1366 for (i = 0; i < num_pf_int - 2; i++)
1367 wr32(hw, I40E_PFINT_DYN_CTLN(i), val);
1368
1369 /* Set the FIRSTQ_INDX field to 0x7FF in PFINT_LNKLSTx */
1370 val = eol << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
1371 wr32(hw, I40E_PFINT_LNKLST0, val);
1372 for (i = 0; i < num_pf_int - 2; i++)
1373 wr32(hw, I40E_PFINT_LNKLSTN(i), val);
1374 val = eol << I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT;
1375 for (i = 0; i < num_vfs; i++)
1376 wr32(hw, I40E_VPINT_LNKLST0(i), val);
1377 for (i = 0; i < num_vf_int - 2; i++)
1378 wr32(hw, I40E_VPINT_LNKLSTN(i), val);
1379
1380 /* warn the HW of the coming Tx disables */
1381 for (i = 0; i < num_queues; i++) {
1382 u32 abs_queue_idx = base_queue + i;
1383 u32 reg_block = 0;
1384
1385 if (abs_queue_idx >= 128) {
1386 reg_block = abs_queue_idx / 128;
1387 abs_queue_idx %= 128;
1388 }
1389
1390 val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
1391 val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
1392 val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
1393 val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
1394
1395 wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), val);
1396 }
1397 udelay(400);
1398
1399 /* stop all the queues */
1400 for (i = 0; i < num_queues; i++) {
1401 wr32(hw, I40E_QINT_TQCTL(i), 0);
1402 wr32(hw, I40E_QTX_ENA(i), 0);
1403 wr32(hw, I40E_QINT_RQCTL(i), 0);
1404 wr32(hw, I40E_QRX_ENA(i), 0);
1405 }
1406
1407 /* short wait for all queue disables to settle */
1408 udelay(50);
1409}
1410
1411/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001412 * i40e_clear_pxe_mode - clear pxe operations mode
1413 * @hw: pointer to the hw struct
1414 *
1415 * Make sure all PXE mode settings are cleared, including things
1416 * like descriptor fetch/write-back mode.
1417 **/
1418void i40e_clear_pxe_mode(struct i40e_hw *hw)
1419{
1420 u32 reg;
1421
Shannon Nelsonc9b9b0a2014-04-09 05:59:05 +00001422 if (i40e_check_asq_alive(hw))
1423 i40e_aq_clear_pxe_mode(hw, NULL);
1424
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001425 /* Clear single descriptor fetch/write-back mode */
1426 reg = rd32(hw, I40E_GLLAN_RCTL_0);
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00001427
1428 if (hw->revision_id == 0) {
1429 /* As a work around clear PXE_MODE instead of setting it */
1430 wr32(hw, I40E_GLLAN_RCTL_0, (reg & (~I40E_GLLAN_RCTL_0_PXE_MODE_MASK)));
1431 } else {
1432 wr32(hw, I40E_GLLAN_RCTL_0, (reg | I40E_GLLAN_RCTL_0_PXE_MODE_MASK));
1433 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001434}
1435
1436/**
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001437 * i40e_led_is_mine - helper to find matching led
1438 * @hw: pointer to the hw struct
1439 * @idx: index into GPIO registers
1440 *
1441 * returns: 0 if no match, otherwise the value of the GPIO_CTL register
1442 */
1443static u32 i40e_led_is_mine(struct i40e_hw *hw, int idx)
1444{
1445 u32 gpio_val = 0;
1446 u32 port;
1447
1448 if (!hw->func_caps.led[idx])
1449 return 0;
1450
1451 gpio_val = rd32(hw, I40E_GLGEN_GPIO_CTL(idx));
1452 port = (gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_MASK) >>
1453 I40E_GLGEN_GPIO_CTL_PRT_NUM_SHIFT;
1454
1455 /* if PRT_NUM_NA is 1 then this LED is not port specific, OR
1456 * if it is not our port then ignore
1457 */
1458 if ((gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_NA_MASK) ||
1459 (port != hw->port))
1460 return 0;
1461
1462 return gpio_val;
1463}
1464
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001465#define I40E_COMBINED_ACTIVITY 0xA
1466#define I40E_FILTER_ACTIVITY 0xE
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001467#define I40E_LINK_ACTIVITY 0xC
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001468#define I40E_MAC_ACTIVITY 0xD
1469#define I40E_LED0 22
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001470
1471/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001472 * i40e_led_get - return current on/off mode
1473 * @hw: pointer to the hw struct
1474 *
1475 * The value returned is the 'mode' field as defined in the
1476 * GPIO register definitions: 0x0 = off, 0xf = on, and other
1477 * values are variations of possible behaviors relating to
1478 * blink, link, and wire.
1479 **/
1480u32 i40e_led_get(struct i40e_hw *hw)
1481{
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001482 u32 current_mode = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001483 u32 mode = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001484 int i;
1485
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001486 /* as per the documentation GPIO 22-29 are the LED
1487 * GPIO pins named LED0..LED7
1488 */
1489 for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
1490 u32 gpio_val = i40e_led_is_mine(hw, i);
1491
1492 if (!gpio_val)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001493 continue;
1494
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001495 /* ignore gpio LED src mode entries related to the activity
1496 * LEDs
1497 */
1498 current_mode = ((gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK)
1499 >> I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT);
1500 switch (current_mode) {
1501 case I40E_COMBINED_ACTIVITY:
1502 case I40E_FILTER_ACTIVITY:
1503 case I40E_MAC_ACTIVITY:
1504 continue;
1505 default:
1506 break;
1507 }
1508
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001509 mode = (gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK) >>
1510 I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001511 break;
1512 }
1513
1514 return mode;
1515}
1516
1517/**
1518 * i40e_led_set - set new on/off mode
1519 * @hw: pointer to the hw struct
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001520 * @mode: 0=off, 0xf=on (else see manual for mode details)
1521 * @blink: true if the LED should blink when on, false if steady
1522 *
1523 * if this function is used to turn on the blink it should
1524 * be used to disable the blink when restoring the original state.
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001525 **/
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001526void i40e_led_set(struct i40e_hw *hw, u32 mode, bool blink)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001527{
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001528 u32 current_mode = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001529 int i;
1530
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001531 if (mode & 0xfffffff0)
1532 hw_dbg(hw, "invalid mode passed in %X\n", mode);
1533
1534 /* as per the documentation GPIO 22-29 are the LED
1535 * GPIO pins named LED0..LED7
1536 */
1537 for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
1538 u32 gpio_val = i40e_led_is_mine(hw, i);
1539
1540 if (!gpio_val)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001541 continue;
1542
Matt Jaredb84d5cd2015-02-26 16:11:30 +00001543 /* ignore gpio LED src mode entries related to the activity
1544 * LEDs
1545 */
1546 current_mode = ((gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK)
1547 >> I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT);
1548 switch (current_mode) {
1549 case I40E_COMBINED_ACTIVITY:
1550 case I40E_FILTER_ACTIVITY:
1551 case I40E_MAC_ACTIVITY:
1552 continue;
1553 default:
1554 break;
1555 }
1556
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001557 gpio_val &= ~I40E_GLGEN_GPIO_CTL_LED_MODE_MASK;
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001558 /* this & is a bit of paranoia, but serves as a range check */
1559 gpio_val |= ((mode << I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT) &
1560 I40E_GLGEN_GPIO_CTL_LED_MODE_MASK);
1561
1562 if (mode == I40E_LINK_ACTIVITY)
1563 blink = false;
1564
Matt Jared9be00d62015-01-24 09:58:28 +00001565 if (blink)
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001566 gpio_val |= BIT(I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
Matt Jared9be00d62015-01-24 09:58:28 +00001567 else
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001568 gpio_val &= ~BIT(I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001569
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001570 wr32(hw, I40E_GLGEN_GPIO_CTL(i), gpio_val);
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001571 break;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001572 }
1573}
1574
1575/* Admin command wrappers */
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001576
1577/**
Catherine Sullivan8109e122014-06-04 08:45:24 +00001578 * i40e_aq_get_phy_capabilities
1579 * @hw: pointer to the hw struct
1580 * @abilities: structure for PHY capabilities to be filled
1581 * @qualified_modules: report Qualified Modules
1582 * @report_init: report init capabilities (active are default)
1583 * @cmd_details: pointer to command details structure or NULL
1584 *
1585 * Returns the various PHY abilities supported on the Port.
1586 **/
1587i40e_status i40e_aq_get_phy_capabilities(struct i40e_hw *hw,
1588 bool qualified_modules, bool report_init,
1589 struct i40e_aq_get_phy_abilities_resp *abilities,
1590 struct i40e_asq_cmd_details *cmd_details)
1591{
1592 struct i40e_aq_desc desc;
1593 i40e_status status;
1594 u16 abilities_size = sizeof(struct i40e_aq_get_phy_abilities_resp);
1595
1596 if (!abilities)
1597 return I40E_ERR_PARAM;
1598
1599 i40e_fill_default_direct_cmd_desc(&desc,
1600 i40e_aqc_opc_get_phy_abilities);
1601
1602 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
1603 if (abilities_size > I40E_AQ_LARGE_BUF)
1604 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
1605
1606 if (qualified_modules)
1607 desc.params.external.param0 |=
1608 cpu_to_le32(I40E_AQ_PHY_REPORT_QUALIFIED_MODULES);
1609
1610 if (report_init)
1611 desc.params.external.param0 |=
1612 cpu_to_le32(I40E_AQ_PHY_REPORT_INITIAL_VALUES);
1613
1614 status = i40e_asq_send_command(hw, &desc, abilities, abilities_size,
1615 cmd_details);
1616
1617 if (hw->aq.asq_last_status == I40E_AQ_RC_EIO)
1618 status = I40E_ERR_UNKNOWN_PHY;
1619
1620 return status;
1621}
1622
1623/**
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001624 * i40e_aq_set_phy_config
1625 * @hw: pointer to the hw struct
1626 * @config: structure with PHY configuration to be set
1627 * @cmd_details: pointer to command details structure or NULL
1628 *
1629 * Set the various PHY configuration parameters
1630 * supported on the Port.One or more of the Set PHY config parameters may be
1631 * ignored in an MFP mode as the PF may not have the privilege to set some
1632 * of the PHY Config parameters. This status will be indicated by the
1633 * command response.
1634 **/
1635enum i40e_status_code i40e_aq_set_phy_config(struct i40e_hw *hw,
1636 struct i40e_aq_set_phy_config *config,
1637 struct i40e_asq_cmd_details *cmd_details)
1638{
1639 struct i40e_aq_desc desc;
1640 struct i40e_aq_set_phy_config *cmd =
1641 (struct i40e_aq_set_phy_config *)&desc.params.raw;
1642 enum i40e_status_code status;
1643
1644 if (!config)
1645 return I40E_ERR_PARAM;
1646
1647 i40e_fill_default_direct_cmd_desc(&desc,
1648 i40e_aqc_opc_set_phy_config);
1649
1650 *cmd = *config;
1651
1652 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1653
1654 return status;
1655}
1656
1657/**
1658 * i40e_set_fc
1659 * @hw: pointer to the hw struct
1660 *
1661 * Set the requested flow control mode using set_phy_config.
1662 **/
1663enum i40e_status_code i40e_set_fc(struct i40e_hw *hw, u8 *aq_failures,
1664 bool atomic_restart)
1665{
1666 enum i40e_fc_mode fc_mode = hw->fc.requested_mode;
1667 struct i40e_aq_get_phy_abilities_resp abilities;
1668 struct i40e_aq_set_phy_config config;
1669 enum i40e_status_code status;
1670 u8 pause_mask = 0x0;
1671
1672 *aq_failures = 0x0;
1673
1674 switch (fc_mode) {
1675 case I40E_FC_FULL:
1676 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
1677 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
1678 break;
1679 case I40E_FC_RX_PAUSE:
1680 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
1681 break;
1682 case I40E_FC_TX_PAUSE:
1683 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
1684 break;
1685 default:
1686 break;
1687 }
1688
1689 /* Get the current phy config */
1690 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
1691 NULL);
1692 if (status) {
1693 *aq_failures |= I40E_SET_FC_AQ_FAIL_GET;
1694 return status;
1695 }
1696
1697 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
1698 /* clear the old pause settings */
1699 config.abilities = abilities.abilities & ~(I40E_AQ_PHY_FLAG_PAUSE_TX) &
1700 ~(I40E_AQ_PHY_FLAG_PAUSE_RX);
1701 /* set the new abilities */
1702 config.abilities |= pause_mask;
1703 /* If the abilities have changed, then set the new config */
1704 if (config.abilities != abilities.abilities) {
1705 /* Auto restart link so settings take effect */
1706 if (atomic_restart)
1707 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
1708 /* Copy over all the old settings */
1709 config.phy_type = abilities.phy_type;
1710 config.link_speed = abilities.link_speed;
1711 config.eee_capability = abilities.eee_capability;
1712 config.eeer = abilities.eeer_val;
1713 config.low_power_ctrl = abilities.d3_lpan;
1714 status = i40e_aq_set_phy_config(hw, &config, NULL);
1715
1716 if (status)
1717 *aq_failures |= I40E_SET_FC_AQ_FAIL_SET;
1718 }
1719 /* Update the link info */
Catherine Sullivan0a862b42015-08-31 19:54:53 -04001720 status = i40e_update_link_info(hw);
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001721 if (status) {
1722 /* Wait a little bit (on 40G cards it sometimes takes a really
1723 * long time for link to come back from the atomic reset)
1724 * and try once more
1725 */
1726 msleep(1000);
Catherine Sullivan0a862b42015-08-31 19:54:53 -04001727 status = i40e_update_link_info(hw);
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001728 }
1729 if (status)
1730 *aq_failures |= I40E_SET_FC_AQ_FAIL_UPDATE;
1731
1732 return status;
1733}
1734
1735/**
Shannon Nelsonc9b9b0a2014-04-09 05:59:05 +00001736 * i40e_aq_clear_pxe_mode
1737 * @hw: pointer to the hw struct
1738 * @cmd_details: pointer to command details structure or NULL
1739 *
1740 * Tell the firmware that the driver is taking over from PXE
1741 **/
1742i40e_status i40e_aq_clear_pxe_mode(struct i40e_hw *hw,
1743 struct i40e_asq_cmd_details *cmd_details)
1744{
1745 i40e_status status;
1746 struct i40e_aq_desc desc;
1747 struct i40e_aqc_clear_pxe *cmd =
1748 (struct i40e_aqc_clear_pxe *)&desc.params.raw;
1749
1750 i40e_fill_default_direct_cmd_desc(&desc,
1751 i40e_aqc_opc_clear_pxe_mode);
1752
1753 cmd->rx_cnt = 0x2;
1754
1755 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1756
1757 wr32(hw, I40E_GLLAN_RCTL_0, 0x1);
1758
1759 return status;
1760}
1761
1762/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001763 * i40e_aq_set_link_restart_an
1764 * @hw: pointer to the hw struct
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001765 * @enable_link: if true: enable link, if false: disable link
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001766 * @cmd_details: pointer to command details structure or NULL
1767 *
1768 * Sets up the link and restarts the Auto-Negotiation over the link.
1769 **/
1770i40e_status i40e_aq_set_link_restart_an(struct i40e_hw *hw,
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001771 bool enable_link,
1772 struct i40e_asq_cmd_details *cmd_details)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001773{
1774 struct i40e_aq_desc desc;
1775 struct i40e_aqc_set_link_restart_an *cmd =
1776 (struct i40e_aqc_set_link_restart_an *)&desc.params.raw;
1777 i40e_status status;
1778
1779 i40e_fill_default_direct_cmd_desc(&desc,
1780 i40e_aqc_opc_set_link_restart_an);
1781
1782 cmd->command = I40E_AQ_PHY_RESTART_AN;
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001783 if (enable_link)
1784 cmd->command |= I40E_AQ_PHY_LINK_ENABLE;
1785 else
1786 cmd->command &= ~I40E_AQ_PHY_LINK_ENABLE;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001787
1788 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1789
1790 return status;
1791}
1792
1793/**
1794 * i40e_aq_get_link_info
1795 * @hw: pointer to the hw struct
1796 * @enable_lse: enable/disable LinkStatusEvent reporting
1797 * @link: pointer to link status structure - optional
1798 * @cmd_details: pointer to command details structure or NULL
1799 *
1800 * Returns the link status of the adapter.
1801 **/
1802i40e_status i40e_aq_get_link_info(struct i40e_hw *hw,
1803 bool enable_lse, struct i40e_link_status *link,
1804 struct i40e_asq_cmd_details *cmd_details)
1805{
1806 struct i40e_aq_desc desc;
1807 struct i40e_aqc_get_link_status *resp =
1808 (struct i40e_aqc_get_link_status *)&desc.params.raw;
1809 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
1810 i40e_status status;
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001811 bool tx_pause, rx_pause;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001812 u16 command_flags;
1813
1814 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_link_status);
1815
1816 if (enable_lse)
1817 command_flags = I40E_AQ_LSE_ENABLE;
1818 else
1819 command_flags = I40E_AQ_LSE_DISABLE;
1820 resp->command_flags = cpu_to_le16(command_flags);
1821
1822 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1823
1824 if (status)
1825 goto aq_get_link_info_exit;
1826
1827 /* save off old link status information */
Mitch Williamsc36bd4a72013-12-18 13:46:04 +00001828 hw->phy.link_info_old = *hw_link_info;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001829
1830 /* update link status */
1831 hw_link_info->phy_type = (enum i40e_aq_phy_type)resp->phy_type;
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001832 hw->phy.media_type = i40e_get_media_type(hw);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001833 hw_link_info->link_speed = (enum i40e_aq_link_speed)resp->link_speed;
1834 hw_link_info->link_info = resp->link_info;
1835 hw_link_info->an_info = resp->an_info;
1836 hw_link_info->ext_info = resp->ext_info;
Kamil Krawczyk639dc372013-11-20 10:03:07 +00001837 hw_link_info->loopback = resp->loopback;
Neerav Parikh6bb3f232014-04-01 07:11:56 +00001838 hw_link_info->max_frame_size = le16_to_cpu(resp->max_frame_size);
1839 hw_link_info->pacing = resp->config & I40E_AQ_CONFIG_PACING_MASK;
1840
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001841 /* update fc info */
1842 tx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_TX);
1843 rx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_RX);
1844 if (tx_pause & rx_pause)
1845 hw->fc.current_mode = I40E_FC_FULL;
1846 else if (tx_pause)
1847 hw->fc.current_mode = I40E_FC_TX_PAUSE;
1848 else if (rx_pause)
1849 hw->fc.current_mode = I40E_FC_RX_PAUSE;
1850 else
1851 hw->fc.current_mode = I40E_FC_NONE;
1852
Neerav Parikh6bb3f232014-04-01 07:11:56 +00001853 if (resp->config & I40E_AQ_CONFIG_CRC_ENA)
1854 hw_link_info->crc_enable = true;
1855 else
1856 hw_link_info->crc_enable = false;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001857
1858 if (resp->command_flags & cpu_to_le16(I40E_AQ_LSE_ENABLE))
1859 hw_link_info->lse_enable = true;
1860 else
1861 hw_link_info->lse_enable = false;
1862
Catherine Sullivan088c4ee2015-02-26 16:14:12 +00001863 if ((hw->aq.fw_maj_ver < 4 || (hw->aq.fw_maj_ver == 4 &&
1864 hw->aq.fw_min_ver < 40)) && hw_link_info->phy_type == 0xE)
1865 hw_link_info->phy_type = I40E_PHY_TYPE_10GBASE_SFPP_CU;
1866
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001867 /* save link status information */
1868 if (link)
Jesse Brandeburgd7595a22013-09-13 08:23:22 +00001869 *link = *hw_link_info;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001870
1871 /* flag cleared so helper functions don't call AQ again */
1872 hw->phy.get_link_info = false;
1873
1874aq_get_link_info_exit:
1875 return status;
1876}
1877
1878/**
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00001879 * i40e_aq_set_phy_int_mask
1880 * @hw: pointer to the hw struct
1881 * @mask: interrupt mask to be set
1882 * @cmd_details: pointer to command details structure or NULL
1883 *
1884 * Set link interrupt mask.
1885 **/
1886i40e_status i40e_aq_set_phy_int_mask(struct i40e_hw *hw,
1887 u16 mask,
1888 struct i40e_asq_cmd_details *cmd_details)
1889{
1890 struct i40e_aq_desc desc;
1891 struct i40e_aqc_set_phy_int_mask *cmd =
1892 (struct i40e_aqc_set_phy_int_mask *)&desc.params.raw;
1893 i40e_status status;
1894
1895 i40e_fill_default_direct_cmd_desc(&desc,
1896 i40e_aqc_opc_set_phy_int_mask);
1897
1898 cmd->event_mask = cpu_to_le16(mask);
1899
1900 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1901
1902 return status;
1903}
1904
1905/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001906 * i40e_aq_add_vsi
1907 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00001908 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001909 * @cmd_details: pointer to command details structure or NULL
1910 *
1911 * Add a VSI context to the hardware.
1912**/
1913i40e_status i40e_aq_add_vsi(struct i40e_hw *hw,
1914 struct i40e_vsi_context *vsi_ctx,
1915 struct i40e_asq_cmd_details *cmd_details)
1916{
1917 struct i40e_aq_desc desc;
1918 struct i40e_aqc_add_get_update_vsi *cmd =
1919 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
1920 struct i40e_aqc_add_get_update_vsi_completion *resp =
1921 (struct i40e_aqc_add_get_update_vsi_completion *)
1922 &desc.params.raw;
1923 i40e_status status;
1924
1925 i40e_fill_default_direct_cmd_desc(&desc,
1926 i40e_aqc_opc_add_vsi);
1927
1928 cmd->uplink_seid = cpu_to_le16(vsi_ctx->uplink_seid);
1929 cmd->connection_type = vsi_ctx->connection_type;
1930 cmd->vf_id = vsi_ctx->vf_num;
1931 cmd->vsi_flags = cpu_to_le16(vsi_ctx->flags);
1932
1933 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001934
1935 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
1936 sizeof(vsi_ctx->info), cmd_details);
1937
1938 if (status)
1939 goto aq_add_vsi_exit;
1940
1941 vsi_ctx->seid = le16_to_cpu(resp->seid);
1942 vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
1943 vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
1944 vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
1945
1946aq_add_vsi_exit:
1947 return status;
1948}
1949
1950/**
1951 * i40e_aq_set_vsi_unicast_promiscuous
1952 * @hw: pointer to the hw struct
1953 * @seid: vsi number
1954 * @set: set unicast promiscuous enable/disable
1955 * @cmd_details: pointer to command details structure or NULL
1956 **/
1957i40e_status i40e_aq_set_vsi_unicast_promiscuous(struct i40e_hw *hw,
Mitch Williams885552a2013-12-21 05:44:41 +00001958 u16 seid, bool set,
1959 struct i40e_asq_cmd_details *cmd_details)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001960{
1961 struct i40e_aq_desc desc;
1962 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
1963 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
1964 i40e_status status;
1965 u16 flags = 0;
1966
1967 i40e_fill_default_direct_cmd_desc(&desc,
1968 i40e_aqc_opc_set_vsi_promiscuous_modes);
1969
1970 if (set)
1971 flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
1972
1973 cmd->promiscuous_flags = cpu_to_le16(flags);
1974
1975 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
1976
1977 cmd->seid = cpu_to_le16(seid);
1978 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1979
1980 return status;
1981}
1982
1983/**
1984 * i40e_aq_set_vsi_multicast_promiscuous
1985 * @hw: pointer to the hw struct
1986 * @seid: vsi number
1987 * @set: set multicast promiscuous enable/disable
1988 * @cmd_details: pointer to command details structure or NULL
1989 **/
1990i40e_status i40e_aq_set_vsi_multicast_promiscuous(struct i40e_hw *hw,
1991 u16 seid, bool set, struct i40e_asq_cmd_details *cmd_details)
1992{
1993 struct i40e_aq_desc desc;
1994 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
1995 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
1996 i40e_status status;
1997 u16 flags = 0;
1998
1999 i40e_fill_default_direct_cmd_desc(&desc,
2000 i40e_aqc_opc_set_vsi_promiscuous_modes);
2001
2002 if (set)
2003 flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
2004
2005 cmd->promiscuous_flags = cpu_to_le16(flags);
2006
2007 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
2008
2009 cmd->seid = cpu_to_le16(seid);
2010 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2011
2012 return status;
2013}
2014
2015/**
2016 * i40e_aq_set_vsi_broadcast
2017 * @hw: pointer to the hw struct
2018 * @seid: vsi number
2019 * @set_filter: true to set filter, false to clear filter
2020 * @cmd_details: pointer to command details structure or NULL
2021 *
2022 * Set or clear the broadcast promiscuous flag (filter) for a given VSI.
2023 **/
2024i40e_status i40e_aq_set_vsi_broadcast(struct i40e_hw *hw,
2025 u16 seid, bool set_filter,
2026 struct i40e_asq_cmd_details *cmd_details)
2027{
2028 struct i40e_aq_desc desc;
2029 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2030 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2031 i40e_status status;
2032
2033 i40e_fill_default_direct_cmd_desc(&desc,
2034 i40e_aqc_opc_set_vsi_promiscuous_modes);
2035
2036 if (set_filter)
2037 cmd->promiscuous_flags
2038 |= cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2039 else
2040 cmd->promiscuous_flags
2041 &= cpu_to_le16(~I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2042
2043 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2044 cmd->seid = cpu_to_le16(seid);
2045 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2046
2047 return status;
2048}
2049
2050/**
2051 * i40e_get_vsi_params - get VSI configuration info
2052 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00002053 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002054 * @cmd_details: pointer to command details structure or NULL
2055 **/
2056i40e_status i40e_aq_get_vsi_params(struct i40e_hw *hw,
2057 struct i40e_vsi_context *vsi_ctx,
2058 struct i40e_asq_cmd_details *cmd_details)
2059{
2060 struct i40e_aq_desc desc;
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002061 struct i40e_aqc_add_get_update_vsi *cmd =
2062 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002063 struct i40e_aqc_add_get_update_vsi_completion *resp =
2064 (struct i40e_aqc_add_get_update_vsi_completion *)
2065 &desc.params.raw;
2066 i40e_status status;
2067
2068 i40e_fill_default_direct_cmd_desc(&desc,
2069 i40e_aqc_opc_get_vsi_parameters);
2070
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002071 cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002072
2073 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002074
2075 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
2076 sizeof(vsi_ctx->info), NULL);
2077
2078 if (status)
2079 goto aq_get_vsi_params_exit;
2080
2081 vsi_ctx->seid = le16_to_cpu(resp->seid);
2082 vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
2083 vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
2084 vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
2085
2086aq_get_vsi_params_exit:
2087 return status;
2088}
2089
2090/**
2091 * i40e_aq_update_vsi_params
2092 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00002093 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002094 * @cmd_details: pointer to command details structure or NULL
2095 *
2096 * Update a VSI context.
2097 **/
2098i40e_status i40e_aq_update_vsi_params(struct i40e_hw *hw,
2099 struct i40e_vsi_context *vsi_ctx,
2100 struct i40e_asq_cmd_details *cmd_details)
2101{
2102 struct i40e_aq_desc desc;
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002103 struct i40e_aqc_add_get_update_vsi *cmd =
2104 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002105 i40e_status status;
2106
2107 i40e_fill_default_direct_cmd_desc(&desc,
2108 i40e_aqc_opc_update_vsi_parameters);
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00002109 cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002110
2111 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002112
2113 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
2114 sizeof(vsi_ctx->info), cmd_details);
2115
2116 return status;
2117}
2118
2119/**
2120 * i40e_aq_get_switch_config
2121 * @hw: pointer to the hardware structure
2122 * @buf: pointer to the result buffer
2123 * @buf_size: length of input buffer
2124 * @start_seid: seid to start for the report, 0 == beginning
2125 * @cmd_details: pointer to command details structure or NULL
2126 *
2127 * Fill the buf with switch configuration returned from AdminQ command
2128 **/
2129i40e_status i40e_aq_get_switch_config(struct i40e_hw *hw,
2130 struct i40e_aqc_get_switch_config_resp *buf,
2131 u16 buf_size, u16 *start_seid,
2132 struct i40e_asq_cmd_details *cmd_details)
2133{
2134 struct i40e_aq_desc desc;
2135 struct i40e_aqc_switch_seid *scfg =
2136 (struct i40e_aqc_switch_seid *)&desc.params.raw;
2137 i40e_status status;
2138
2139 i40e_fill_default_direct_cmd_desc(&desc,
2140 i40e_aqc_opc_get_switch_config);
2141 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
2142 if (buf_size > I40E_AQ_LARGE_BUF)
2143 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2144 scfg->seid = cpu_to_le16(*start_seid);
2145
2146 status = i40e_asq_send_command(hw, &desc, buf, buf_size, cmd_details);
2147 *start_seid = le16_to_cpu(scfg->seid);
2148
2149 return status;
2150}
2151
2152/**
2153 * i40e_aq_get_firmware_version
2154 * @hw: pointer to the hw struct
2155 * @fw_major_version: firmware major version
2156 * @fw_minor_version: firmware minor version
Shannon Nelson7edf8102015-02-24 06:58:41 +00002157 * @fw_build: firmware build number
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002158 * @api_major_version: major queue version
2159 * @api_minor_version: minor queue version
2160 * @cmd_details: pointer to command details structure or NULL
2161 *
2162 * Get the firmware version from the admin queue commands
2163 **/
2164i40e_status i40e_aq_get_firmware_version(struct i40e_hw *hw,
2165 u16 *fw_major_version, u16 *fw_minor_version,
Shannon Nelson7edf8102015-02-24 06:58:41 +00002166 u32 *fw_build,
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002167 u16 *api_major_version, u16 *api_minor_version,
2168 struct i40e_asq_cmd_details *cmd_details)
2169{
2170 struct i40e_aq_desc desc;
2171 struct i40e_aqc_get_version *resp =
2172 (struct i40e_aqc_get_version *)&desc.params.raw;
2173 i40e_status status;
2174
2175 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_version);
2176
2177 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2178
2179 if (!status) {
Shannon Nelson7edf8102015-02-24 06:58:41 +00002180 if (fw_major_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002181 *fw_major_version = le16_to_cpu(resp->fw_major);
Shannon Nelson7edf8102015-02-24 06:58:41 +00002182 if (fw_minor_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002183 *fw_minor_version = le16_to_cpu(resp->fw_minor);
Shannon Nelson7edf8102015-02-24 06:58:41 +00002184 if (fw_build)
2185 *fw_build = le32_to_cpu(resp->fw_build);
2186 if (api_major_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002187 *api_major_version = le16_to_cpu(resp->api_major);
Shannon Nelson7edf8102015-02-24 06:58:41 +00002188 if (api_minor_version)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002189 *api_minor_version = le16_to_cpu(resp->api_minor);
2190 }
2191
2192 return status;
2193}
2194
2195/**
2196 * i40e_aq_send_driver_version
2197 * @hw: pointer to the hw struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002198 * @dv: driver's major, minor version
2199 * @cmd_details: pointer to command details structure or NULL
2200 *
2201 * Send the driver version to the firmware
2202 **/
2203i40e_status i40e_aq_send_driver_version(struct i40e_hw *hw,
2204 struct i40e_driver_version *dv,
2205 struct i40e_asq_cmd_details *cmd_details)
2206{
2207 struct i40e_aq_desc desc;
2208 struct i40e_aqc_driver_version *cmd =
2209 (struct i40e_aqc_driver_version *)&desc.params.raw;
2210 i40e_status status;
Kevin Scott9d2f98e2014-04-01 07:11:52 +00002211 u16 len;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002212
2213 if (dv == NULL)
2214 return I40E_ERR_PARAM;
2215
2216 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_driver_version);
2217
Kevin Scott3b38cd12015-02-06 08:52:18 +00002218 desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002219 cmd->driver_major_ver = dv->major_version;
2220 cmd->driver_minor_ver = dv->minor_version;
2221 cmd->driver_build_ver = dv->build_version;
2222 cmd->driver_subbuild_ver = dv->subbuild_version;
Shannon Nelsond2466012014-04-01 07:11:45 +00002223
2224 len = 0;
2225 while (len < sizeof(dv->driver_string) &&
2226 (dv->driver_string[len] < 0x80) &&
2227 dv->driver_string[len])
2228 len++;
2229 status = i40e_asq_send_command(hw, &desc, dv->driver_string,
2230 len, cmd_details);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002231
2232 return status;
2233}
2234
2235/**
2236 * i40e_get_link_status - get status of the HW network link
2237 * @hw: pointer to the hw struct
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002238 * @link_up: pointer to bool (true/false = linkup/linkdown)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002239 *
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002240 * Variable link_up true if link is up, false if link is down.
2241 * The variable link_up is invalid if returned value of status != 0
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002242 *
2243 * Side effect: LinkStatusEvent reporting becomes enabled
2244 **/
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002245i40e_status i40e_get_link_status(struct i40e_hw *hw, bool *link_up)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002246{
2247 i40e_status status = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002248
2249 if (hw->phy.get_link_info) {
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002250 status = i40e_update_link_info(hw);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002251
2252 if (status)
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002253 i40e_debug(hw, I40E_DEBUG_LINK, "get link failed: status %d\n",
2254 status);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002255 }
2256
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002257 *link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002258
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002259 return status;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002260}
2261
2262/**
Catherine Sullivan0a862b42015-08-31 19:54:53 -04002263 * i40e_updatelink_status - update status of the HW network link
2264 * @hw: pointer to the hw struct
2265 **/
2266i40e_status i40e_update_link_info(struct i40e_hw *hw)
2267{
2268 struct i40e_aq_get_phy_abilities_resp abilities;
2269 i40e_status status = 0;
2270
2271 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
2272 if (status)
2273 return status;
2274
2275 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
2276 NULL);
2277 if (status)
2278 return status;
2279
2280 memcpy(hw->phy.link_info.module_type, &abilities.module_type,
2281 sizeof(hw->phy.link_info.module_type));
2282
2283 return status;
2284}
2285
2286/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002287 * i40e_aq_add_veb - Insert a VEB between the VSI and the MAC
2288 * @hw: pointer to the hw struct
2289 * @uplink_seid: the MAC or other gizmo SEID
2290 * @downlink_seid: the VSI SEID
2291 * @enabled_tc: bitmap of TCs to be enabled
2292 * @default_port: true for default port VSI, false for control port
Kevin Scotte1c51b952013-11-20 10:02:51 +00002293 * @enable_l2_filtering: true to add L2 filter table rules to regular forwarding rules for cloud support
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002294 * @veb_seid: pointer to where to put the resulting VEB SEID
2295 * @cmd_details: pointer to command details structure or NULL
2296 *
2297 * This asks the FW to add a VEB between the uplink and downlink
2298 * elements. If the uplink SEID is 0, this will be a floating VEB.
2299 **/
2300i40e_status i40e_aq_add_veb(struct i40e_hw *hw, u16 uplink_seid,
2301 u16 downlink_seid, u8 enabled_tc,
Kevin Scotte1c51b952013-11-20 10:02:51 +00002302 bool default_port, bool enable_l2_filtering,
2303 u16 *veb_seid,
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002304 struct i40e_asq_cmd_details *cmd_details)
2305{
2306 struct i40e_aq_desc desc;
2307 struct i40e_aqc_add_veb *cmd =
2308 (struct i40e_aqc_add_veb *)&desc.params.raw;
2309 struct i40e_aqc_add_veb_completion *resp =
2310 (struct i40e_aqc_add_veb_completion *)&desc.params.raw;
2311 i40e_status status;
2312 u16 veb_flags = 0;
2313
2314 /* SEIDs need to either both be set or both be 0 for floating VEB */
2315 if (!!uplink_seid != !!downlink_seid)
2316 return I40E_ERR_PARAM;
2317
2318 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_veb);
2319
2320 cmd->uplink_seid = cpu_to_le16(uplink_seid);
2321 cmd->downlink_seid = cpu_to_le16(downlink_seid);
2322 cmd->enable_tcs = enabled_tc;
2323 if (!uplink_seid)
2324 veb_flags |= I40E_AQC_ADD_VEB_FLOATING;
2325 if (default_port)
2326 veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DEFAULT;
2327 else
2328 veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DATA;
Kevin Scotte1c51b952013-11-20 10:02:51 +00002329
2330 if (enable_l2_filtering)
2331 veb_flags |= I40E_AQC_ADD_VEB_ENABLE_L2_FILTER;
2332
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002333 cmd->veb_flags = cpu_to_le16(veb_flags);
2334
2335 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2336
2337 if (!status && veb_seid)
2338 *veb_seid = le16_to_cpu(resp->veb_seid);
2339
2340 return status;
2341}
2342
2343/**
2344 * i40e_aq_get_veb_parameters - Retrieve VEB parameters
2345 * @hw: pointer to the hw struct
2346 * @veb_seid: the SEID of the VEB to query
2347 * @switch_id: the uplink switch id
Jeff Kirsher98d44382013-12-21 05:44:42 +00002348 * @floating: set to true if the VEB is floating
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002349 * @statistic_index: index of the stats counter block for this VEB
2350 * @vebs_used: number of VEB's used by function
Jeff Kirsher98d44382013-12-21 05:44:42 +00002351 * @vebs_free: total VEB's not reserved by any function
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002352 * @cmd_details: pointer to command details structure or NULL
2353 *
2354 * This retrieves the parameters for a particular VEB, specified by
2355 * uplink_seid, and returns them to the caller.
2356 **/
2357i40e_status i40e_aq_get_veb_parameters(struct i40e_hw *hw,
2358 u16 veb_seid, u16 *switch_id,
2359 bool *floating, u16 *statistic_index,
2360 u16 *vebs_used, u16 *vebs_free,
2361 struct i40e_asq_cmd_details *cmd_details)
2362{
2363 struct i40e_aq_desc desc;
2364 struct i40e_aqc_get_veb_parameters_completion *cmd_resp =
2365 (struct i40e_aqc_get_veb_parameters_completion *)
2366 &desc.params.raw;
2367 i40e_status status;
2368
2369 if (veb_seid == 0)
2370 return I40E_ERR_PARAM;
2371
2372 i40e_fill_default_direct_cmd_desc(&desc,
2373 i40e_aqc_opc_get_veb_parameters);
2374 cmd_resp->seid = cpu_to_le16(veb_seid);
2375
2376 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2377 if (status)
2378 goto get_veb_exit;
2379
2380 if (switch_id)
2381 *switch_id = le16_to_cpu(cmd_resp->switch_id);
2382 if (statistic_index)
2383 *statistic_index = le16_to_cpu(cmd_resp->statistic_index);
2384 if (vebs_used)
2385 *vebs_used = le16_to_cpu(cmd_resp->vebs_used);
2386 if (vebs_free)
2387 *vebs_free = le16_to_cpu(cmd_resp->vebs_free);
2388 if (floating) {
2389 u16 flags = le16_to_cpu(cmd_resp->veb_flags);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04002390
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002391 if (flags & I40E_AQC_ADD_VEB_FLOATING)
2392 *floating = true;
2393 else
2394 *floating = false;
2395 }
2396
2397get_veb_exit:
2398 return status;
2399}
2400
2401/**
2402 * i40e_aq_add_macvlan
2403 * @hw: pointer to the hw struct
2404 * @seid: VSI for the mac address
2405 * @mv_list: list of macvlans to be added
2406 * @count: length of the list
2407 * @cmd_details: pointer to command details structure or NULL
2408 *
2409 * Add MAC/VLAN addresses to the HW filtering
2410 **/
2411i40e_status i40e_aq_add_macvlan(struct i40e_hw *hw, u16 seid,
2412 struct i40e_aqc_add_macvlan_element_data *mv_list,
2413 u16 count, struct i40e_asq_cmd_details *cmd_details)
2414{
2415 struct i40e_aq_desc desc;
2416 struct i40e_aqc_macvlan *cmd =
2417 (struct i40e_aqc_macvlan *)&desc.params.raw;
2418 i40e_status status;
2419 u16 buf_size;
2420
2421 if (count == 0 || !mv_list || !hw)
2422 return I40E_ERR_PARAM;
2423
Shannon Nelson1efc80e2015-02-27 09:18:30 +00002424 buf_size = count * sizeof(*mv_list);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002425
2426 /* prep the rest of the request */
2427 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_macvlan);
2428 cmd->num_addresses = cpu_to_le16(count);
2429 cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
2430 cmd->seid[1] = 0;
2431 cmd->seid[2] = 0;
2432
2433 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
2434 if (buf_size > I40E_AQ_LARGE_BUF)
2435 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2436
2437 status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
2438 cmd_details);
2439
2440 return status;
2441}
2442
2443/**
2444 * i40e_aq_remove_macvlan
2445 * @hw: pointer to the hw struct
2446 * @seid: VSI for the mac address
2447 * @mv_list: list of macvlans to be removed
2448 * @count: length of the list
2449 * @cmd_details: pointer to command details structure or NULL
2450 *
2451 * Remove MAC/VLAN addresses from the HW filtering
2452 **/
2453i40e_status i40e_aq_remove_macvlan(struct i40e_hw *hw, u16 seid,
2454 struct i40e_aqc_remove_macvlan_element_data *mv_list,
2455 u16 count, struct i40e_asq_cmd_details *cmd_details)
2456{
2457 struct i40e_aq_desc desc;
2458 struct i40e_aqc_macvlan *cmd =
2459 (struct i40e_aqc_macvlan *)&desc.params.raw;
2460 i40e_status status;
2461 u16 buf_size;
2462
2463 if (count == 0 || !mv_list || !hw)
2464 return I40E_ERR_PARAM;
2465
Shannon Nelson1efc80e2015-02-27 09:18:30 +00002466 buf_size = count * sizeof(*mv_list);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002467
2468 /* prep the rest of the request */
2469 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_macvlan);
2470 cmd->num_addresses = cpu_to_le16(count);
2471 cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
2472 cmd->seid[1] = 0;
2473 cmd->seid[2] = 0;
2474
2475 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
2476 if (buf_size > I40E_AQ_LARGE_BUF)
2477 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2478
2479 status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
2480 cmd_details);
2481
2482 return status;
2483}
2484
2485/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002486 * i40e_aq_send_msg_to_vf
2487 * @hw: pointer to the hardware structure
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00002488 * @vfid: VF id to send msg
Jeff Kirsher98d44382013-12-21 05:44:42 +00002489 * @v_opcode: opcodes for VF-PF communication
2490 * @v_retval: return error code
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002491 * @msg: pointer to the msg buffer
2492 * @msglen: msg length
2493 * @cmd_details: pointer to command details
2494 *
2495 * send msg to vf
2496 **/
2497i40e_status i40e_aq_send_msg_to_vf(struct i40e_hw *hw, u16 vfid,
2498 u32 v_opcode, u32 v_retval, u8 *msg, u16 msglen,
2499 struct i40e_asq_cmd_details *cmd_details)
2500{
2501 struct i40e_aq_desc desc;
2502 struct i40e_aqc_pf_vf_message *cmd =
2503 (struct i40e_aqc_pf_vf_message *)&desc.params.raw;
2504 i40e_status status;
2505
2506 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_vf);
2507 cmd->id = cpu_to_le32(vfid);
2508 desc.cookie_high = cpu_to_le32(v_opcode);
2509 desc.cookie_low = cpu_to_le32(v_retval);
2510 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_SI);
2511 if (msglen) {
2512 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
2513 I40E_AQ_FLAG_RD));
2514 if (msglen > I40E_AQ_LARGE_BUF)
2515 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2516 desc.datalen = cpu_to_le16(msglen);
2517 }
2518 status = i40e_asq_send_command(hw, &desc, msg, msglen, cmd_details);
2519
2520 return status;
2521}
2522
2523/**
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002524 * i40e_aq_debug_read_register
2525 * @hw: pointer to the hw struct
2526 * @reg_addr: register address
2527 * @reg_val: register value
2528 * @cmd_details: pointer to command details structure or NULL
2529 *
2530 * Read the register using the admin queue commands
2531 **/
2532i40e_status i40e_aq_debug_read_register(struct i40e_hw *hw,
Jesse Brandeburg7b115dd2015-02-27 09:15:23 +00002533 u32 reg_addr, u64 *reg_val,
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002534 struct i40e_asq_cmd_details *cmd_details)
2535{
2536 struct i40e_aq_desc desc;
2537 struct i40e_aqc_debug_reg_read_write *cmd_resp =
2538 (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
2539 i40e_status status;
2540
2541 if (reg_val == NULL)
2542 return I40E_ERR_PARAM;
2543
Jesse Brandeburg7b115dd2015-02-27 09:15:23 +00002544 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_read_reg);
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002545
2546 cmd_resp->address = cpu_to_le32(reg_addr);
2547
2548 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2549
2550 if (!status) {
Jesse Brandeburg7b115dd2015-02-27 09:15:23 +00002551 *reg_val = ((u64)le32_to_cpu(cmd_resp->value_high) << 32) |
2552 (u64)le32_to_cpu(cmd_resp->value_low);
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002553 }
2554
2555 return status;
2556}
2557
2558/**
Shannon Nelson53db45c2014-08-01 13:27:05 -07002559 * i40e_aq_debug_write_register
2560 * @hw: pointer to the hw struct
2561 * @reg_addr: register address
2562 * @reg_val: register value
2563 * @cmd_details: pointer to command details structure or NULL
2564 *
2565 * Write to a register using the admin queue commands
2566 **/
2567i40e_status i40e_aq_debug_write_register(struct i40e_hw *hw,
2568 u32 reg_addr, u64 reg_val,
2569 struct i40e_asq_cmd_details *cmd_details)
2570{
2571 struct i40e_aq_desc desc;
2572 struct i40e_aqc_debug_reg_read_write *cmd =
2573 (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
2574 i40e_status status;
2575
2576 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_write_reg);
2577
2578 cmd->address = cpu_to_le32(reg_addr);
2579 cmd->value_high = cpu_to_le32((u32)(reg_val >> 32));
2580 cmd->value_low = cpu_to_le32((u32)(reg_val & 0xFFFFFFFF));
2581
2582 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2583
2584 return status;
2585}
2586
2587/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002588 * i40e_aq_set_hmc_resource_profile
2589 * @hw: pointer to the hw struct
2590 * @profile: type of profile the HMC is to be set as
2591 * @pe_vf_enabled_count: the number of PE enabled VFs the system has
2592 * @cmd_details: pointer to command details structure or NULL
2593 *
2594 * set the HMC profile of the device.
2595 **/
2596i40e_status i40e_aq_set_hmc_resource_profile(struct i40e_hw *hw,
2597 enum i40e_aq_hmc_profile profile,
2598 u8 pe_vf_enabled_count,
2599 struct i40e_asq_cmd_details *cmd_details)
2600{
2601 struct i40e_aq_desc desc;
2602 struct i40e_aq_get_set_hmc_resource_profile *cmd =
2603 (struct i40e_aq_get_set_hmc_resource_profile *)&desc.params.raw;
2604 i40e_status status;
2605
2606 i40e_fill_default_direct_cmd_desc(&desc,
2607 i40e_aqc_opc_set_hmc_resource_profile);
2608
2609 cmd->pm_profile = (u8)profile;
2610 cmd->pe_vf_enabled = pe_vf_enabled_count;
2611
2612 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2613
2614 return status;
2615}
2616
2617/**
2618 * i40e_aq_request_resource
2619 * @hw: pointer to the hw struct
2620 * @resource: resource id
2621 * @access: access type
2622 * @sdp_number: resource number
2623 * @timeout: the maximum time in ms that the driver may hold the resource
2624 * @cmd_details: pointer to command details structure or NULL
2625 *
2626 * requests common resource using the admin queue commands
2627 **/
2628i40e_status i40e_aq_request_resource(struct i40e_hw *hw,
2629 enum i40e_aq_resources_ids resource,
2630 enum i40e_aq_resource_access_type access,
2631 u8 sdp_number, u64 *timeout,
2632 struct i40e_asq_cmd_details *cmd_details)
2633{
2634 struct i40e_aq_desc desc;
2635 struct i40e_aqc_request_resource *cmd_resp =
2636 (struct i40e_aqc_request_resource *)&desc.params.raw;
2637 i40e_status status;
2638
2639 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_request_resource);
2640
2641 cmd_resp->resource_id = cpu_to_le16(resource);
2642 cmd_resp->access_type = cpu_to_le16(access);
2643 cmd_resp->resource_number = cpu_to_le32(sdp_number);
2644
2645 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2646 /* The completion specifies the maximum time in ms that the driver
2647 * may hold the resource in the Timeout field.
2648 * If the resource is held by someone else, the command completes with
2649 * busy return value and the timeout field indicates the maximum time
2650 * the current owner of the resource has to free it.
2651 */
2652 if (!status || hw->aq.asq_last_status == I40E_AQ_RC_EBUSY)
2653 *timeout = le32_to_cpu(cmd_resp->timeout);
2654
2655 return status;
2656}
2657
2658/**
2659 * i40e_aq_release_resource
2660 * @hw: pointer to the hw struct
2661 * @resource: resource id
2662 * @sdp_number: resource number
2663 * @cmd_details: pointer to command details structure or NULL
2664 *
2665 * release common resource using the admin queue commands
2666 **/
2667i40e_status i40e_aq_release_resource(struct i40e_hw *hw,
2668 enum i40e_aq_resources_ids resource,
2669 u8 sdp_number,
2670 struct i40e_asq_cmd_details *cmd_details)
2671{
2672 struct i40e_aq_desc desc;
2673 struct i40e_aqc_request_resource *cmd =
2674 (struct i40e_aqc_request_resource *)&desc.params.raw;
2675 i40e_status status;
2676
2677 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_release_resource);
2678
2679 cmd->resource_id = cpu_to_le16(resource);
2680 cmd->resource_number = cpu_to_le32(sdp_number);
2681
2682 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2683
2684 return status;
2685}
2686
2687/**
2688 * i40e_aq_read_nvm
2689 * @hw: pointer to the hw struct
2690 * @module_pointer: module pointer location in words from the NVM beginning
2691 * @offset: byte offset from the module beginning
2692 * @length: length of the section to be read (in bytes from the offset)
2693 * @data: command buffer (size [bytes] = length)
2694 * @last_command: tells if this is the last command in a series
2695 * @cmd_details: pointer to command details structure or NULL
2696 *
2697 * Read the NVM using the admin queue commands
2698 **/
2699i40e_status i40e_aq_read_nvm(struct i40e_hw *hw, u8 module_pointer,
2700 u32 offset, u16 length, void *data,
2701 bool last_command,
2702 struct i40e_asq_cmd_details *cmd_details)
2703{
2704 struct i40e_aq_desc desc;
2705 struct i40e_aqc_nvm_update *cmd =
2706 (struct i40e_aqc_nvm_update *)&desc.params.raw;
2707 i40e_status status;
2708
2709 /* In offset the highest byte must be zeroed. */
2710 if (offset & 0xFF000000) {
2711 status = I40E_ERR_PARAM;
2712 goto i40e_aq_read_nvm_exit;
2713 }
2714
2715 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_read);
2716
2717 /* If this is the last command in a series, set the proper flag. */
2718 if (last_command)
2719 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
2720 cmd->module_pointer = module_pointer;
2721 cmd->offset = cpu_to_le32(offset);
2722 cmd->length = cpu_to_le16(length);
2723
2724 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
2725 if (length > I40E_AQ_LARGE_BUF)
2726 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2727
2728 status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
2729
2730i40e_aq_read_nvm_exit:
2731 return status;
2732}
2733
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002734/**
2735 * i40e_aq_erase_nvm
2736 * @hw: pointer to the hw struct
2737 * @module_pointer: module pointer location in words from the NVM beginning
2738 * @offset: offset in the module (expressed in 4 KB from module's beginning)
2739 * @length: length of the section to be erased (expressed in 4 KB)
2740 * @last_command: tells if this is the last command in a series
2741 * @cmd_details: pointer to command details structure or NULL
2742 *
2743 * Erase the NVM sector using the admin queue commands
2744 **/
2745i40e_status i40e_aq_erase_nvm(struct i40e_hw *hw, u8 module_pointer,
2746 u32 offset, u16 length, bool last_command,
2747 struct i40e_asq_cmd_details *cmd_details)
2748{
2749 struct i40e_aq_desc desc;
2750 struct i40e_aqc_nvm_update *cmd =
2751 (struct i40e_aqc_nvm_update *)&desc.params.raw;
2752 i40e_status status;
2753
2754 /* In offset the highest byte must be zeroed. */
2755 if (offset & 0xFF000000) {
2756 status = I40E_ERR_PARAM;
2757 goto i40e_aq_erase_nvm_exit;
2758 }
2759
2760 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_erase);
2761
2762 /* If this is the last command in a series, set the proper flag. */
2763 if (last_command)
2764 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
2765 cmd->module_pointer = module_pointer;
2766 cmd->offset = cpu_to_le32(offset);
2767 cmd->length = cpu_to_le16(length);
2768
2769 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2770
2771i40e_aq_erase_nvm_exit:
2772 return status;
2773}
2774
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002775#define I40E_DEV_FUNC_CAP_SWITCH_MODE 0x01
2776#define I40E_DEV_FUNC_CAP_MGMT_MODE 0x02
2777#define I40E_DEV_FUNC_CAP_NPAR 0x03
2778#define I40E_DEV_FUNC_CAP_OS2BMC 0x04
2779#define I40E_DEV_FUNC_CAP_VALID_FUNC 0x05
2780#define I40E_DEV_FUNC_CAP_SRIOV_1_1 0x12
2781#define I40E_DEV_FUNC_CAP_VF 0x13
2782#define I40E_DEV_FUNC_CAP_VMDQ 0x14
2783#define I40E_DEV_FUNC_CAP_802_1_QBG 0x15
2784#define I40E_DEV_FUNC_CAP_802_1_QBH 0x16
2785#define I40E_DEV_FUNC_CAP_VSI 0x17
2786#define I40E_DEV_FUNC_CAP_DCB 0x18
2787#define I40E_DEV_FUNC_CAP_FCOE 0x21
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00002788#define I40E_DEV_FUNC_CAP_ISCSI 0x22
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002789#define I40E_DEV_FUNC_CAP_RSS 0x40
2790#define I40E_DEV_FUNC_CAP_RX_QUEUES 0x41
2791#define I40E_DEV_FUNC_CAP_TX_QUEUES 0x42
2792#define I40E_DEV_FUNC_CAP_MSIX 0x43
2793#define I40E_DEV_FUNC_CAP_MSIX_VF 0x44
2794#define I40E_DEV_FUNC_CAP_FLOW_DIRECTOR 0x45
2795#define I40E_DEV_FUNC_CAP_IEEE_1588 0x46
Pawel Orlowskic78b9532015-04-22 19:34:06 -04002796#define I40E_DEV_FUNC_CAP_FLEX10 0xF1
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002797#define I40E_DEV_FUNC_CAP_CEM 0xF2
2798#define I40E_DEV_FUNC_CAP_IWARP 0x51
2799#define I40E_DEV_FUNC_CAP_LED 0x61
2800#define I40E_DEV_FUNC_CAP_SDP 0x62
2801#define I40E_DEV_FUNC_CAP_MDIO 0x63
Kevin Scott73b23402015-04-07 19:45:38 -04002802#define I40E_DEV_FUNC_CAP_WR_CSR_PROT 0x64
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002803
2804/**
2805 * i40e_parse_discover_capabilities
2806 * @hw: pointer to the hw struct
2807 * @buff: pointer to a buffer containing device/function capability records
2808 * @cap_count: number of capability records in the list
2809 * @list_type_opc: type of capabilities list to parse
2810 *
2811 * Parse the device/function capabilities list.
2812 **/
2813static void i40e_parse_discover_capabilities(struct i40e_hw *hw, void *buff,
2814 u32 cap_count,
2815 enum i40e_admin_queue_opc list_type_opc)
2816{
2817 struct i40e_aqc_list_capabilities_element_resp *cap;
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002818 u32 valid_functions, num_functions;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002819 u32 number, logical_id, phys_id;
2820 struct i40e_hw_capabilities *p;
Pawel Orlowskic78b9532015-04-22 19:34:06 -04002821 u8 major_rev;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002822 u32 i = 0;
2823 u16 id;
2824
2825 cap = (struct i40e_aqc_list_capabilities_element_resp *) buff;
2826
2827 if (list_type_opc == i40e_aqc_opc_list_dev_capabilities)
Joe Perchesb58f2f72014-03-25 04:30:32 +00002828 p = &hw->dev_caps;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002829 else if (list_type_opc == i40e_aqc_opc_list_func_capabilities)
Joe Perchesb58f2f72014-03-25 04:30:32 +00002830 p = &hw->func_caps;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002831 else
2832 return;
2833
2834 for (i = 0; i < cap_count; i++, cap++) {
2835 id = le16_to_cpu(cap->id);
2836 number = le32_to_cpu(cap->number);
2837 logical_id = le32_to_cpu(cap->logical_id);
2838 phys_id = le32_to_cpu(cap->phys_id);
Pawel Orlowskic78b9532015-04-22 19:34:06 -04002839 major_rev = cap->major_rev;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002840
2841 switch (id) {
2842 case I40E_DEV_FUNC_CAP_SWITCH_MODE:
2843 p->switch_mode = number;
2844 break;
2845 case I40E_DEV_FUNC_CAP_MGMT_MODE:
2846 p->management_mode = number;
2847 break;
2848 case I40E_DEV_FUNC_CAP_NPAR:
2849 p->npar_enable = number;
2850 break;
2851 case I40E_DEV_FUNC_CAP_OS2BMC:
2852 p->os2bmc = number;
2853 break;
2854 case I40E_DEV_FUNC_CAP_VALID_FUNC:
2855 p->valid_functions = number;
2856 break;
2857 case I40E_DEV_FUNC_CAP_SRIOV_1_1:
2858 if (number == 1)
2859 p->sr_iov_1_1 = true;
2860 break;
2861 case I40E_DEV_FUNC_CAP_VF:
2862 p->num_vfs = number;
2863 p->vf_base_id = logical_id;
2864 break;
2865 case I40E_DEV_FUNC_CAP_VMDQ:
2866 if (number == 1)
2867 p->vmdq = true;
2868 break;
2869 case I40E_DEV_FUNC_CAP_802_1_QBG:
2870 if (number == 1)
2871 p->evb_802_1_qbg = true;
2872 break;
2873 case I40E_DEV_FUNC_CAP_802_1_QBH:
2874 if (number == 1)
2875 p->evb_802_1_qbh = true;
2876 break;
2877 case I40E_DEV_FUNC_CAP_VSI:
2878 p->num_vsis = number;
2879 break;
2880 case I40E_DEV_FUNC_CAP_DCB:
2881 if (number == 1) {
2882 p->dcb = true;
2883 p->enabled_tcmap = logical_id;
2884 p->maxtc = phys_id;
2885 }
2886 break;
2887 case I40E_DEV_FUNC_CAP_FCOE:
2888 if (number == 1)
2889 p->fcoe = true;
2890 break;
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00002891 case I40E_DEV_FUNC_CAP_ISCSI:
2892 if (number == 1)
2893 p->iscsi = true;
2894 break;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002895 case I40E_DEV_FUNC_CAP_RSS:
2896 p->rss = true;
Carolyn Wybornye157ea32014-06-03 23:50:22 +00002897 p->rss_table_size = number;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002898 p->rss_table_entry_width = logical_id;
2899 break;
2900 case I40E_DEV_FUNC_CAP_RX_QUEUES:
2901 p->num_rx_qp = number;
2902 p->base_queue = phys_id;
2903 break;
2904 case I40E_DEV_FUNC_CAP_TX_QUEUES:
2905 p->num_tx_qp = number;
2906 p->base_queue = phys_id;
2907 break;
2908 case I40E_DEV_FUNC_CAP_MSIX:
2909 p->num_msix_vectors = number;
2910 break;
2911 case I40E_DEV_FUNC_CAP_MSIX_VF:
2912 p->num_msix_vectors_vf = number;
2913 break;
Pawel Orlowskic78b9532015-04-22 19:34:06 -04002914 case I40E_DEV_FUNC_CAP_FLEX10:
2915 if (major_rev == 1) {
2916 if (number == 1) {
2917 p->flex10_enable = true;
2918 p->flex10_capable = true;
2919 }
2920 } else {
2921 /* Capability revision >= 2 */
2922 if (number & 1)
2923 p->flex10_enable = true;
2924 if (number & 2)
2925 p->flex10_capable = true;
2926 }
2927 p->flex10_mode = logical_id;
2928 p->flex10_status = phys_id;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002929 break;
2930 case I40E_DEV_FUNC_CAP_CEM:
2931 if (number == 1)
2932 p->mgmt_cem = true;
2933 break;
2934 case I40E_DEV_FUNC_CAP_IWARP:
2935 if (number == 1)
2936 p->iwarp = true;
2937 break;
2938 case I40E_DEV_FUNC_CAP_LED:
2939 if (phys_id < I40E_HW_CAP_MAX_GPIO)
2940 p->led[phys_id] = true;
2941 break;
2942 case I40E_DEV_FUNC_CAP_SDP:
2943 if (phys_id < I40E_HW_CAP_MAX_GPIO)
2944 p->sdp[phys_id] = true;
2945 break;
2946 case I40E_DEV_FUNC_CAP_MDIO:
2947 if (number == 1) {
2948 p->mdio_port_num = phys_id;
2949 p->mdio_port_mode = logical_id;
2950 }
2951 break;
2952 case I40E_DEV_FUNC_CAP_IEEE_1588:
2953 if (number == 1)
2954 p->ieee_1588 = true;
2955 break;
2956 case I40E_DEV_FUNC_CAP_FLOW_DIRECTOR:
2957 p->fd = true;
2958 p->fd_filters_guaranteed = number;
2959 p->fd_filters_best_effort = logical_id;
2960 break;
Kevin Scott73b23402015-04-07 19:45:38 -04002961 case I40E_DEV_FUNC_CAP_WR_CSR_PROT:
2962 p->wr_csr_prot = (u64)number;
2963 p->wr_csr_prot |= (u64)logical_id << 32;
2964 break;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002965 default:
2966 break;
2967 }
2968 }
2969
Vasu Devf18ae102015-04-07 19:45:36 -04002970 if (p->fcoe)
2971 i40e_debug(hw, I40E_DEBUG_ALL, "device is FCoE capable\n");
2972
Vasu Dev566bb852014-04-09 05:59:06 +00002973 /* Software override ensuring FCoE is disabled if npar or mfp
2974 * mode because it is not supported in these modes.
2975 */
Pawel Orlowskic78b9532015-04-22 19:34:06 -04002976 if (p->npar_enable || p->flex10_enable)
Vasu Dev566bb852014-04-09 05:59:06 +00002977 p->fcoe = false;
2978
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002979 /* count the enabled ports (aka the "not disabled" ports) */
2980 hw->num_ports = 0;
2981 for (i = 0; i < 4; i++) {
2982 u32 port_cfg_reg = I40E_PRTGEN_CNF + (4 * i);
2983 u64 port_cfg = 0;
2984
2985 /* use AQ read to get the physical register offset instead
2986 * of the port relative offset
2987 */
2988 i40e_aq_debug_read_register(hw, port_cfg_reg, &port_cfg, NULL);
2989 if (!(port_cfg & I40E_PRTGEN_CNF_PORT_DIS_MASK))
2990 hw->num_ports++;
2991 }
2992
2993 valid_functions = p->valid_functions;
2994 num_functions = 0;
2995 while (valid_functions) {
2996 if (valid_functions & 1)
2997 num_functions++;
2998 valid_functions >>= 1;
2999 }
3000
3001 /* partition id is 1-based, and functions are evenly spread
3002 * across the ports as partitions
3003 */
3004 hw->partition_id = (hw->pf_id / hw->num_ports) + 1;
3005 hw->num_partitions = num_functions / hw->num_ports;
3006
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003007 /* additional HW specific goodies that might
3008 * someday be HW version specific
3009 */
3010 p->rx_buf_chain_len = I40E_MAX_CHAINED_RX_BUFFERS;
3011}
3012
3013/**
3014 * i40e_aq_discover_capabilities
3015 * @hw: pointer to the hw struct
3016 * @buff: a virtual buffer to hold the capabilities
3017 * @buff_size: Size of the virtual buffer
3018 * @data_size: Size of the returned data, or buff size needed if AQ err==ENOMEM
3019 * @list_type_opc: capabilities type to discover - pass in the command opcode
3020 * @cmd_details: pointer to command details structure or NULL
3021 *
3022 * Get the device capabilities descriptions from the firmware
3023 **/
3024i40e_status i40e_aq_discover_capabilities(struct i40e_hw *hw,
3025 void *buff, u16 buff_size, u16 *data_size,
3026 enum i40e_admin_queue_opc list_type_opc,
3027 struct i40e_asq_cmd_details *cmd_details)
3028{
3029 struct i40e_aqc_list_capabilites *cmd;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003030 struct i40e_aq_desc desc;
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08003031 i40e_status status = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003032
3033 cmd = (struct i40e_aqc_list_capabilites *)&desc.params.raw;
3034
3035 if (list_type_opc != i40e_aqc_opc_list_func_capabilities &&
3036 list_type_opc != i40e_aqc_opc_list_dev_capabilities) {
3037 status = I40E_ERR_PARAM;
3038 goto exit;
3039 }
3040
3041 i40e_fill_default_direct_cmd_desc(&desc, list_type_opc);
3042
3043 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3044 if (buff_size > I40E_AQ_LARGE_BUF)
3045 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3046
3047 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3048 *data_size = le16_to_cpu(desc.datalen);
3049
3050 if (status)
3051 goto exit;
3052
3053 i40e_parse_discover_capabilities(hw, buff, le32_to_cpu(cmd->count),
3054 list_type_opc);
3055
3056exit:
3057 return status;
3058}
3059
3060/**
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003061 * i40e_aq_update_nvm
3062 * @hw: pointer to the hw struct
3063 * @module_pointer: module pointer location in words from the NVM beginning
3064 * @offset: byte offset from the module beginning
3065 * @length: length of the section to be written (in bytes from the offset)
3066 * @data: command buffer (size [bytes] = length)
3067 * @last_command: tells if this is the last command in a series
3068 * @cmd_details: pointer to command details structure or NULL
3069 *
3070 * Update the NVM using the admin queue commands
3071 **/
3072i40e_status i40e_aq_update_nvm(struct i40e_hw *hw, u8 module_pointer,
3073 u32 offset, u16 length, void *data,
3074 bool last_command,
3075 struct i40e_asq_cmd_details *cmd_details)
3076{
3077 struct i40e_aq_desc desc;
3078 struct i40e_aqc_nvm_update *cmd =
3079 (struct i40e_aqc_nvm_update *)&desc.params.raw;
3080 i40e_status status;
3081
3082 /* In offset the highest byte must be zeroed. */
3083 if (offset & 0xFF000000) {
3084 status = I40E_ERR_PARAM;
3085 goto i40e_aq_update_nvm_exit;
3086 }
3087
3088 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_update);
3089
3090 /* If this is the last command in a series, set the proper flag. */
3091 if (last_command)
3092 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
3093 cmd->module_pointer = module_pointer;
3094 cmd->offset = cpu_to_le32(offset);
3095 cmd->length = cpu_to_le16(length);
3096
3097 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
3098 if (length > I40E_AQ_LARGE_BUF)
3099 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3100
3101 status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
3102
3103i40e_aq_update_nvm_exit:
3104 return status;
3105}
3106
3107/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003108 * i40e_aq_get_lldp_mib
3109 * @hw: pointer to the hw struct
3110 * @bridge_type: type of bridge requested
3111 * @mib_type: Local, Remote or both Local and Remote MIBs
3112 * @buff: pointer to a user supplied buffer to store the MIB block
3113 * @buff_size: size of the buffer (in bytes)
3114 * @local_len : length of the returned Local LLDP MIB
3115 * @remote_len: length of the returned Remote LLDP MIB
3116 * @cmd_details: pointer to command details structure or NULL
3117 *
3118 * Requests the complete LLDP MIB (entire packet).
3119 **/
3120i40e_status i40e_aq_get_lldp_mib(struct i40e_hw *hw, u8 bridge_type,
3121 u8 mib_type, void *buff, u16 buff_size,
3122 u16 *local_len, u16 *remote_len,
3123 struct i40e_asq_cmd_details *cmd_details)
3124{
3125 struct i40e_aq_desc desc;
3126 struct i40e_aqc_lldp_get_mib *cmd =
3127 (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
3128 struct i40e_aqc_lldp_get_mib *resp =
3129 (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
3130 i40e_status status;
3131
3132 if (buff_size == 0 || !buff)
3133 return I40E_ERR_PARAM;
3134
3135 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_get_mib);
3136 /* Indirect Command */
3137 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3138
3139 cmd->type = mib_type & I40E_AQ_LLDP_MIB_TYPE_MASK;
3140 cmd->type |= ((bridge_type << I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) &
3141 I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
3142
3143 desc.datalen = cpu_to_le16(buff_size);
3144
3145 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3146 if (buff_size > I40E_AQ_LARGE_BUF)
3147 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3148
3149 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3150 if (!status) {
3151 if (local_len != NULL)
3152 *local_len = le16_to_cpu(resp->local_len);
3153 if (remote_len != NULL)
3154 *remote_len = le16_to_cpu(resp->remote_len);
3155 }
3156
3157 return status;
3158}
3159
3160/**
3161 * i40e_aq_cfg_lldp_mib_change_event
3162 * @hw: pointer to the hw struct
3163 * @enable_update: Enable or Disable event posting
3164 * @cmd_details: pointer to command details structure or NULL
3165 *
3166 * Enable or Disable posting of an event on ARQ when LLDP MIB
3167 * associated with the interface changes
3168 **/
3169i40e_status i40e_aq_cfg_lldp_mib_change_event(struct i40e_hw *hw,
3170 bool enable_update,
3171 struct i40e_asq_cmd_details *cmd_details)
3172{
3173 struct i40e_aq_desc desc;
3174 struct i40e_aqc_lldp_update_mib *cmd =
3175 (struct i40e_aqc_lldp_update_mib *)&desc.params.raw;
3176 i40e_status status;
3177
3178 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_update_mib);
3179
3180 if (!enable_update)
3181 cmd->command |= I40E_AQ_LLDP_MIB_UPDATE_DISABLE;
3182
3183 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3184
3185 return status;
3186}
3187
3188/**
3189 * i40e_aq_stop_lldp
3190 * @hw: pointer to the hw struct
3191 * @shutdown_agent: True if LLDP Agent needs to be Shutdown
3192 * @cmd_details: pointer to command details structure or NULL
3193 *
3194 * Stop or Shutdown the embedded LLDP Agent
3195 **/
3196i40e_status i40e_aq_stop_lldp(struct i40e_hw *hw, bool shutdown_agent,
3197 struct i40e_asq_cmd_details *cmd_details)
3198{
3199 struct i40e_aq_desc desc;
3200 struct i40e_aqc_lldp_stop *cmd =
3201 (struct i40e_aqc_lldp_stop *)&desc.params.raw;
3202 i40e_status status;
3203
3204 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_stop);
3205
3206 if (shutdown_agent)
3207 cmd->command |= I40E_AQ_LLDP_AGENT_SHUTDOWN;
3208
3209 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3210
3211 return status;
3212}
3213
3214/**
3215 * i40e_aq_start_lldp
3216 * @hw: pointer to the hw struct
3217 * @cmd_details: pointer to command details structure or NULL
3218 *
3219 * Start the embedded LLDP Agent on all ports.
3220 **/
3221i40e_status i40e_aq_start_lldp(struct i40e_hw *hw,
3222 struct i40e_asq_cmd_details *cmd_details)
3223{
3224 struct i40e_aq_desc desc;
3225 struct i40e_aqc_lldp_start *cmd =
3226 (struct i40e_aqc_lldp_start *)&desc.params.raw;
3227 i40e_status status;
3228
3229 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_start);
3230
3231 cmd->command = I40E_AQ_LLDP_AGENT_START;
3232
3233 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3234
3235 return status;
3236}
3237
3238/**
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00003239 * i40e_aq_get_cee_dcb_config
3240 * @hw: pointer to the hw struct
3241 * @buff: response buffer that stores CEE operational configuration
3242 * @buff_size: size of the buffer passed
3243 * @cmd_details: pointer to command details structure or NULL
3244 *
3245 * Get CEE DCBX mode operational configuration from firmware
3246 **/
3247i40e_status i40e_aq_get_cee_dcb_config(struct i40e_hw *hw,
3248 void *buff, u16 buff_size,
3249 struct i40e_asq_cmd_details *cmd_details)
3250{
3251 struct i40e_aq_desc desc;
3252 i40e_status status;
3253
3254 if (buff_size == 0 || !buff)
3255 return I40E_ERR_PARAM;
3256
3257 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_cee_dcb_cfg);
3258
3259 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3260 status = i40e_asq_send_command(hw, &desc, (void *)buff, buff_size,
3261 cmd_details);
3262
3263 return status;
3264}
3265
3266/**
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003267 * i40e_aq_add_udp_tunnel
3268 * @hw: pointer to the hw struct
3269 * @udp_port: the UDP port to add
3270 * @header_len: length of the tunneling header length in DWords
3271 * @protocol_index: protocol index type
Jeff Kirsher98d44382013-12-21 05:44:42 +00003272 * @filter_index: pointer to filter index
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003273 * @cmd_details: pointer to command details structure or NULL
3274 **/
3275i40e_status i40e_aq_add_udp_tunnel(struct i40e_hw *hw,
Kevin Scottf4f94b92014-04-05 07:46:10 +00003276 u16 udp_port, u8 protocol_index,
3277 u8 *filter_index,
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003278 struct i40e_asq_cmd_details *cmd_details)
3279{
3280 struct i40e_aq_desc desc;
3281 struct i40e_aqc_add_udp_tunnel *cmd =
3282 (struct i40e_aqc_add_udp_tunnel *)&desc.params.raw;
3283 struct i40e_aqc_del_udp_tunnel_completion *resp =
3284 (struct i40e_aqc_del_udp_tunnel_completion *)&desc.params.raw;
3285 i40e_status status;
3286
3287 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_udp_tunnel);
3288
3289 cmd->udp_port = cpu_to_le16(udp_port);
Shannon Nelson981b7542013-12-11 08:17:11 +00003290 cmd->protocol_type = protocol_index;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003291
3292 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3293
Shannon Nelson65d13462015-02-21 06:45:28 +00003294 if (!status && filter_index)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00003295 *filter_index = resp->index;
3296
3297 return status;
3298}
3299
3300/**
3301 * i40e_aq_del_udp_tunnel
3302 * @hw: pointer to the hw struct
3303 * @index: filter index
3304 * @cmd_details: pointer to command details structure or NULL
3305 **/
3306i40e_status i40e_aq_del_udp_tunnel(struct i40e_hw *hw, u8 index,
3307 struct i40e_asq_cmd_details *cmd_details)
3308{
3309 struct i40e_aq_desc desc;
3310 struct i40e_aqc_remove_udp_tunnel *cmd =
3311 (struct i40e_aqc_remove_udp_tunnel *)&desc.params.raw;
3312 i40e_status status;
3313
3314 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_del_udp_tunnel);
3315
3316 cmd->index = index;
3317
3318 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3319
3320 return status;
3321}
3322
3323/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003324 * i40e_aq_delete_element - Delete switch element
3325 * @hw: pointer to the hw struct
3326 * @seid: the SEID to delete from the switch
3327 * @cmd_details: pointer to command details structure or NULL
3328 *
3329 * This deletes a switch element from the switch.
3330 **/
3331i40e_status i40e_aq_delete_element(struct i40e_hw *hw, u16 seid,
3332 struct i40e_asq_cmd_details *cmd_details)
3333{
3334 struct i40e_aq_desc desc;
3335 struct i40e_aqc_switch_seid *cmd =
3336 (struct i40e_aqc_switch_seid *)&desc.params.raw;
3337 i40e_status status;
3338
3339 if (seid == 0)
3340 return I40E_ERR_PARAM;
3341
3342 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_delete_element);
3343
3344 cmd->seid = cpu_to_le16(seid);
3345
3346 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3347
3348 return status;
3349}
3350
3351/**
Neerav Parikhafb3ff02014-01-17 15:36:36 -08003352 * i40e_aq_dcb_updated - DCB Updated Command
3353 * @hw: pointer to the hw struct
3354 * @cmd_details: pointer to command details structure or NULL
3355 *
3356 * EMP will return when the shared RPB settings have been
3357 * recomputed and modified. The retval field in the descriptor
3358 * will be set to 0 when RPB is modified.
3359 **/
3360i40e_status i40e_aq_dcb_updated(struct i40e_hw *hw,
3361 struct i40e_asq_cmd_details *cmd_details)
3362{
3363 struct i40e_aq_desc desc;
3364 i40e_status status;
3365
3366 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_dcb_updated);
3367
3368 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3369
3370 return status;
3371}
3372
3373/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003374 * i40e_aq_tx_sched_cmd - generic Tx scheduler AQ command handler
3375 * @hw: pointer to the hw struct
3376 * @seid: seid for the physical port/switching component/vsi
3377 * @buff: Indirect buffer to hold data parameters and response
3378 * @buff_size: Indirect buffer size
3379 * @opcode: Tx scheduler AQ command opcode
3380 * @cmd_details: pointer to command details structure or NULL
3381 *
3382 * Generic command handler for Tx scheduler AQ commands
3383 **/
3384static i40e_status i40e_aq_tx_sched_cmd(struct i40e_hw *hw, u16 seid,
3385 void *buff, u16 buff_size,
3386 enum i40e_admin_queue_opc opcode,
3387 struct i40e_asq_cmd_details *cmd_details)
3388{
3389 struct i40e_aq_desc desc;
3390 struct i40e_aqc_tx_sched_ind *cmd =
3391 (struct i40e_aqc_tx_sched_ind *)&desc.params.raw;
3392 i40e_status status;
3393 bool cmd_param_flag = false;
3394
3395 switch (opcode) {
3396 case i40e_aqc_opc_configure_vsi_ets_sla_bw_limit:
3397 case i40e_aqc_opc_configure_vsi_tc_bw:
3398 case i40e_aqc_opc_enable_switching_comp_ets:
3399 case i40e_aqc_opc_modify_switching_comp_ets:
3400 case i40e_aqc_opc_disable_switching_comp_ets:
3401 case i40e_aqc_opc_configure_switching_comp_ets_bw_limit:
3402 case i40e_aqc_opc_configure_switching_comp_bw_config:
3403 cmd_param_flag = true;
3404 break;
3405 case i40e_aqc_opc_query_vsi_bw_config:
3406 case i40e_aqc_opc_query_vsi_ets_sla_config:
3407 case i40e_aqc_opc_query_switching_comp_ets_config:
3408 case i40e_aqc_opc_query_port_ets_config:
3409 case i40e_aqc_opc_query_switching_comp_bw_config:
3410 cmd_param_flag = false;
3411 break;
3412 default:
3413 return I40E_ERR_PARAM;
3414 }
3415
3416 i40e_fill_default_direct_cmd_desc(&desc, opcode);
3417
3418 /* Indirect command */
3419 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3420 if (cmd_param_flag)
3421 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
3422 if (buff_size > I40E_AQ_LARGE_BUF)
3423 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3424
3425 desc.datalen = cpu_to_le16(buff_size);
3426
3427 cmd->vsi_seid = cpu_to_le16(seid);
3428
3429 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3430
3431 return status;
3432}
3433
3434/**
Mitch Williams6b192892014-03-06 09:02:29 +00003435 * i40e_aq_config_vsi_bw_limit - Configure VSI BW Limit
3436 * @hw: pointer to the hw struct
3437 * @seid: VSI seid
3438 * @credit: BW limit credits (0 = disabled)
3439 * @max_credit: Max BW limit credits
3440 * @cmd_details: pointer to command details structure or NULL
3441 **/
3442i40e_status i40e_aq_config_vsi_bw_limit(struct i40e_hw *hw,
3443 u16 seid, u16 credit, u8 max_credit,
3444 struct i40e_asq_cmd_details *cmd_details)
3445{
3446 struct i40e_aq_desc desc;
3447 struct i40e_aqc_configure_vsi_bw_limit *cmd =
3448 (struct i40e_aqc_configure_vsi_bw_limit *)&desc.params.raw;
3449 i40e_status status;
3450
3451 i40e_fill_default_direct_cmd_desc(&desc,
3452 i40e_aqc_opc_configure_vsi_bw_limit);
3453
3454 cmd->vsi_seid = cpu_to_le16(seid);
3455 cmd->credit = cpu_to_le16(credit);
3456 cmd->max_credit = max_credit;
3457
3458 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3459
3460 return status;
3461}
3462
3463/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003464 * i40e_aq_config_vsi_tc_bw - Config VSI BW Allocation per TC
3465 * @hw: pointer to the hw struct
3466 * @seid: VSI seid
3467 * @bw_data: Buffer holding enabled TCs, relative TC BW limit/credits
3468 * @cmd_details: pointer to command details structure or NULL
3469 **/
3470i40e_status i40e_aq_config_vsi_tc_bw(struct i40e_hw *hw,
3471 u16 seid,
3472 struct i40e_aqc_configure_vsi_tc_bw_data *bw_data,
3473 struct i40e_asq_cmd_details *cmd_details)
3474{
3475 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3476 i40e_aqc_opc_configure_vsi_tc_bw,
3477 cmd_details);
3478}
3479
3480/**
Neerav Parikhafb3ff02014-01-17 15:36:36 -08003481 * i40e_aq_config_switch_comp_ets - Enable/Disable/Modify ETS on the port
3482 * @hw: pointer to the hw struct
3483 * @seid: seid of the switching component connected to Physical Port
3484 * @ets_data: Buffer holding ETS parameters
3485 * @cmd_details: pointer to command details structure or NULL
3486 **/
3487i40e_status i40e_aq_config_switch_comp_ets(struct i40e_hw *hw,
3488 u16 seid,
3489 struct i40e_aqc_configure_switching_comp_ets_data *ets_data,
3490 enum i40e_admin_queue_opc opcode,
3491 struct i40e_asq_cmd_details *cmd_details)
3492{
3493 return i40e_aq_tx_sched_cmd(hw, seid, (void *)ets_data,
3494 sizeof(*ets_data), opcode, cmd_details);
3495}
3496
3497/**
3498 * i40e_aq_config_switch_comp_bw_config - Config Switch comp BW Alloc per TC
3499 * @hw: pointer to the hw struct
3500 * @seid: seid of the switching component
3501 * @bw_data: Buffer holding enabled TCs, relative/absolute TC BW limit/credits
3502 * @cmd_details: pointer to command details structure or NULL
3503 **/
3504i40e_status i40e_aq_config_switch_comp_bw_config(struct i40e_hw *hw,
3505 u16 seid,
3506 struct i40e_aqc_configure_switching_comp_bw_config_data *bw_data,
3507 struct i40e_asq_cmd_details *cmd_details)
3508{
3509 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3510 i40e_aqc_opc_configure_switching_comp_bw_config,
3511 cmd_details);
3512}
3513
3514/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003515 * i40e_aq_query_vsi_bw_config - Query VSI BW configuration
3516 * @hw: pointer to the hw struct
3517 * @seid: seid of the VSI
3518 * @bw_data: Buffer to hold VSI BW configuration
3519 * @cmd_details: pointer to command details structure or NULL
3520 **/
3521i40e_status i40e_aq_query_vsi_bw_config(struct i40e_hw *hw,
3522 u16 seid,
3523 struct i40e_aqc_query_vsi_bw_config_resp *bw_data,
3524 struct i40e_asq_cmd_details *cmd_details)
3525{
3526 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3527 i40e_aqc_opc_query_vsi_bw_config,
3528 cmd_details);
3529}
3530
3531/**
3532 * i40e_aq_query_vsi_ets_sla_config - Query VSI BW configuration per TC
3533 * @hw: pointer to the hw struct
3534 * @seid: seid of the VSI
3535 * @bw_data: Buffer to hold VSI BW configuration per TC
3536 * @cmd_details: pointer to command details structure or NULL
3537 **/
3538i40e_status i40e_aq_query_vsi_ets_sla_config(struct i40e_hw *hw,
3539 u16 seid,
3540 struct i40e_aqc_query_vsi_ets_sla_config_resp *bw_data,
3541 struct i40e_asq_cmd_details *cmd_details)
3542{
3543 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3544 i40e_aqc_opc_query_vsi_ets_sla_config,
3545 cmd_details);
3546}
3547
3548/**
3549 * i40e_aq_query_switch_comp_ets_config - Query Switch comp BW config per TC
3550 * @hw: pointer to the hw struct
3551 * @seid: seid of the switching component
3552 * @bw_data: Buffer to hold switching component's per TC BW config
3553 * @cmd_details: pointer to command details structure or NULL
3554 **/
3555i40e_status i40e_aq_query_switch_comp_ets_config(struct i40e_hw *hw,
3556 u16 seid,
3557 struct i40e_aqc_query_switching_comp_ets_config_resp *bw_data,
3558 struct i40e_asq_cmd_details *cmd_details)
3559{
3560 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3561 i40e_aqc_opc_query_switching_comp_ets_config,
3562 cmd_details);
3563}
3564
3565/**
3566 * i40e_aq_query_port_ets_config - Query Physical Port ETS configuration
3567 * @hw: pointer to the hw struct
3568 * @seid: seid of the VSI or switching component connected to Physical Port
3569 * @bw_data: Buffer to hold current ETS configuration for the Physical Port
3570 * @cmd_details: pointer to command details structure or NULL
3571 **/
3572i40e_status i40e_aq_query_port_ets_config(struct i40e_hw *hw,
3573 u16 seid,
3574 struct i40e_aqc_query_port_ets_config_resp *bw_data,
3575 struct i40e_asq_cmd_details *cmd_details)
3576{
3577 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3578 i40e_aqc_opc_query_port_ets_config,
3579 cmd_details);
3580}
3581
3582/**
3583 * i40e_aq_query_switch_comp_bw_config - Query Switch comp BW configuration
3584 * @hw: pointer to the hw struct
3585 * @seid: seid of the switching component
3586 * @bw_data: Buffer to hold switching component's BW configuration
3587 * @cmd_details: pointer to command details structure or NULL
3588 **/
3589i40e_status i40e_aq_query_switch_comp_bw_config(struct i40e_hw *hw,
3590 u16 seid,
3591 struct i40e_aqc_query_switching_comp_bw_config_resp *bw_data,
3592 struct i40e_asq_cmd_details *cmd_details)
3593{
3594 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3595 i40e_aqc_opc_query_switching_comp_bw_config,
3596 cmd_details);
3597}
3598
3599/**
3600 * i40e_validate_filter_settings
3601 * @hw: pointer to the hardware structure
3602 * @settings: Filter control settings
3603 *
3604 * Check and validate the filter control settings passed.
3605 * The function checks for the valid filter/context sizes being
3606 * passed for FCoE and PE.
3607 *
3608 * Returns 0 if the values passed are valid and within
3609 * range else returns an error.
3610 **/
3611static i40e_status i40e_validate_filter_settings(struct i40e_hw *hw,
3612 struct i40e_filter_control_settings *settings)
3613{
3614 u32 fcoe_cntx_size, fcoe_filt_size;
3615 u32 pe_cntx_size, pe_filt_size;
Anjali Singhai Jain467d7292014-05-10 04:49:02 +00003616 u32 fcoe_fmax;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003617 u32 val;
3618
3619 /* Validate FCoE settings passed */
3620 switch (settings->fcoe_filt_num) {
3621 case I40E_HASH_FILTER_SIZE_1K:
3622 case I40E_HASH_FILTER_SIZE_2K:
3623 case I40E_HASH_FILTER_SIZE_4K:
3624 case I40E_HASH_FILTER_SIZE_8K:
3625 case I40E_HASH_FILTER_SIZE_16K:
3626 case I40E_HASH_FILTER_SIZE_32K:
3627 fcoe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
3628 fcoe_filt_size <<= (u32)settings->fcoe_filt_num;
3629 break;
3630 default:
3631 return I40E_ERR_PARAM;
3632 }
3633
3634 switch (settings->fcoe_cntx_num) {
3635 case I40E_DMA_CNTX_SIZE_512:
3636 case I40E_DMA_CNTX_SIZE_1K:
3637 case I40E_DMA_CNTX_SIZE_2K:
3638 case I40E_DMA_CNTX_SIZE_4K:
3639 fcoe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
3640 fcoe_cntx_size <<= (u32)settings->fcoe_cntx_num;
3641 break;
3642 default:
3643 return I40E_ERR_PARAM;
3644 }
3645
3646 /* Validate PE settings passed */
3647 switch (settings->pe_filt_num) {
3648 case I40E_HASH_FILTER_SIZE_1K:
3649 case I40E_HASH_FILTER_SIZE_2K:
3650 case I40E_HASH_FILTER_SIZE_4K:
3651 case I40E_HASH_FILTER_SIZE_8K:
3652 case I40E_HASH_FILTER_SIZE_16K:
3653 case I40E_HASH_FILTER_SIZE_32K:
3654 case I40E_HASH_FILTER_SIZE_64K:
3655 case I40E_HASH_FILTER_SIZE_128K:
3656 case I40E_HASH_FILTER_SIZE_256K:
3657 case I40E_HASH_FILTER_SIZE_512K:
3658 case I40E_HASH_FILTER_SIZE_1M:
3659 pe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
3660 pe_filt_size <<= (u32)settings->pe_filt_num;
3661 break;
3662 default:
3663 return I40E_ERR_PARAM;
3664 }
3665
3666 switch (settings->pe_cntx_num) {
3667 case I40E_DMA_CNTX_SIZE_512:
3668 case I40E_DMA_CNTX_SIZE_1K:
3669 case I40E_DMA_CNTX_SIZE_2K:
3670 case I40E_DMA_CNTX_SIZE_4K:
3671 case I40E_DMA_CNTX_SIZE_8K:
3672 case I40E_DMA_CNTX_SIZE_16K:
3673 case I40E_DMA_CNTX_SIZE_32K:
3674 case I40E_DMA_CNTX_SIZE_64K:
3675 case I40E_DMA_CNTX_SIZE_128K:
3676 case I40E_DMA_CNTX_SIZE_256K:
3677 pe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
3678 pe_cntx_size <<= (u32)settings->pe_cntx_num;
3679 break;
3680 default:
3681 return I40E_ERR_PARAM;
3682 }
3683
3684 /* FCHSIZE + FCDSIZE should not be greater than PMFCOEFMAX */
3685 val = rd32(hw, I40E_GLHMC_FCOEFMAX);
3686 fcoe_fmax = (val & I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_MASK)
3687 >> I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_SHIFT;
3688 if (fcoe_filt_size + fcoe_cntx_size > fcoe_fmax)
3689 return I40E_ERR_INVALID_SIZE;
3690
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003691 return 0;
3692}
3693
3694/**
3695 * i40e_set_filter_control
3696 * @hw: pointer to the hardware structure
3697 * @settings: Filter control settings
3698 *
3699 * Set the Queue Filters for PE/FCoE and enable filters required
3700 * for a single PF. It is expected that these settings are programmed
3701 * at the driver initialization time.
3702 **/
3703i40e_status i40e_set_filter_control(struct i40e_hw *hw,
3704 struct i40e_filter_control_settings *settings)
3705{
3706 i40e_status ret = 0;
3707 u32 hash_lut_size = 0;
3708 u32 val;
3709
3710 if (!settings)
3711 return I40E_ERR_PARAM;
3712
3713 /* Validate the input settings */
3714 ret = i40e_validate_filter_settings(hw, settings);
3715 if (ret)
3716 return ret;
3717
3718 /* Read the PF Queue Filter control register */
3719 val = rd32(hw, I40E_PFQF_CTL_0);
3720
3721 /* Program required PE hash buckets for the PF */
3722 val &= ~I40E_PFQF_CTL_0_PEHSIZE_MASK;
3723 val |= ((u32)settings->pe_filt_num << I40E_PFQF_CTL_0_PEHSIZE_SHIFT) &
3724 I40E_PFQF_CTL_0_PEHSIZE_MASK;
3725 /* Program required PE contexts for the PF */
3726 val &= ~I40E_PFQF_CTL_0_PEDSIZE_MASK;
3727 val |= ((u32)settings->pe_cntx_num << I40E_PFQF_CTL_0_PEDSIZE_SHIFT) &
3728 I40E_PFQF_CTL_0_PEDSIZE_MASK;
3729
3730 /* Program required FCoE hash buckets for the PF */
3731 val &= ~I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
3732 val |= ((u32)settings->fcoe_filt_num <<
3733 I40E_PFQF_CTL_0_PFFCHSIZE_SHIFT) &
3734 I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
3735 /* Program required FCoE DDP contexts for the PF */
3736 val &= ~I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
3737 val |= ((u32)settings->fcoe_cntx_num <<
3738 I40E_PFQF_CTL_0_PFFCDSIZE_SHIFT) &
3739 I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
3740
3741 /* Program Hash LUT size for the PF */
3742 val &= ~I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
3743 if (settings->hash_lut_size == I40E_HASH_LUT_SIZE_512)
3744 hash_lut_size = 1;
3745 val |= (hash_lut_size << I40E_PFQF_CTL_0_HASHLUTSIZE_SHIFT) &
3746 I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
3747
3748 /* Enable FDIR, Ethertype and MACVLAN filters for PF and VFs */
3749 if (settings->enable_fdir)
3750 val |= I40E_PFQF_CTL_0_FD_ENA_MASK;
3751 if (settings->enable_ethtype)
3752 val |= I40E_PFQF_CTL_0_ETYPE_ENA_MASK;
3753 if (settings->enable_macvlan)
3754 val |= I40E_PFQF_CTL_0_MACVLAN_ENA_MASK;
3755
3756 wr32(hw, I40E_PFQF_CTL_0, val);
3757
3758 return 0;
3759}
Neerav Parikhafb3ff02014-01-17 15:36:36 -08003760
3761/**
3762 * i40e_aq_add_rem_control_packet_filter - Add or Remove Control Packet Filter
3763 * @hw: pointer to the hw struct
3764 * @mac_addr: MAC address to use in the filter
3765 * @ethtype: Ethertype to use in the filter
3766 * @flags: Flags that needs to be applied to the filter
3767 * @vsi_seid: seid of the control VSI
3768 * @queue: VSI queue number to send the packet to
3769 * @is_add: Add control packet filter if True else remove
3770 * @stats: Structure to hold information on control filter counts
3771 * @cmd_details: pointer to command details structure or NULL
3772 *
3773 * This command will Add or Remove control packet filter for a control VSI.
3774 * In return it will update the total number of perfect filter count in
3775 * the stats member.
3776 **/
3777i40e_status i40e_aq_add_rem_control_packet_filter(struct i40e_hw *hw,
3778 u8 *mac_addr, u16 ethtype, u16 flags,
3779 u16 vsi_seid, u16 queue, bool is_add,
3780 struct i40e_control_filter_stats *stats,
3781 struct i40e_asq_cmd_details *cmd_details)
3782{
3783 struct i40e_aq_desc desc;
3784 struct i40e_aqc_add_remove_control_packet_filter *cmd =
3785 (struct i40e_aqc_add_remove_control_packet_filter *)
3786 &desc.params.raw;
3787 struct i40e_aqc_add_remove_control_packet_filter_completion *resp =
3788 (struct i40e_aqc_add_remove_control_packet_filter_completion *)
3789 &desc.params.raw;
3790 i40e_status status;
3791
3792 if (vsi_seid == 0)
3793 return I40E_ERR_PARAM;
3794
3795 if (is_add) {
3796 i40e_fill_default_direct_cmd_desc(&desc,
3797 i40e_aqc_opc_add_control_packet_filter);
3798 cmd->queue = cpu_to_le16(queue);
3799 } else {
3800 i40e_fill_default_direct_cmd_desc(&desc,
3801 i40e_aqc_opc_remove_control_packet_filter);
3802 }
3803
3804 if (mac_addr)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04003805 ether_addr_copy(cmd->mac, mac_addr);
Neerav Parikhafb3ff02014-01-17 15:36:36 -08003806
3807 cmd->etype = cpu_to_le16(ethtype);
3808 cmd->flags = cpu_to_le16(flags);
3809 cmd->seid = cpu_to_le16(vsi_seid);
3810
3811 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3812
3813 if (!status && stats) {
3814 stats->mac_etype_used = le16_to_cpu(resp->mac_etype_used);
3815 stats->etype_used = le16_to_cpu(resp->etype_used);
3816 stats->mac_etype_free = le16_to_cpu(resp->mac_etype_free);
3817 stats->etype_free = le16_to_cpu(resp->etype_free);
3818 }
3819
3820 return status;
3821}
3822
Catherine Sullivand4dfb812013-11-28 06:39:21 +00003823/**
Greg Rosef4492db2015-02-06 08:52:12 +00003824 * i40e_aq_alternate_read
3825 * @hw: pointer to the hardware structure
3826 * @reg_addr0: address of first dword to be read
3827 * @reg_val0: pointer for data read from 'reg_addr0'
3828 * @reg_addr1: address of second dword to be read
3829 * @reg_val1: pointer for data read from 'reg_addr1'
3830 *
3831 * Read one or two dwords from alternate structure. Fields are indicated
3832 * by 'reg_addr0' and 'reg_addr1' register numbers. If 'reg_val1' pointer
3833 * is not passed then only register at 'reg_addr0' is read.
3834 *
3835 **/
Shannon Nelson37a29732015-02-27 09:15:19 +00003836static i40e_status i40e_aq_alternate_read(struct i40e_hw *hw,
3837 u32 reg_addr0, u32 *reg_val0,
3838 u32 reg_addr1, u32 *reg_val1)
Greg Rosef4492db2015-02-06 08:52:12 +00003839{
3840 struct i40e_aq_desc desc;
3841 struct i40e_aqc_alternate_write *cmd_resp =
3842 (struct i40e_aqc_alternate_write *)&desc.params.raw;
3843 i40e_status status;
3844
3845 if (!reg_val0)
3846 return I40E_ERR_PARAM;
3847
3848 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_alternate_read);
3849 cmd_resp->address0 = cpu_to_le32(reg_addr0);
3850 cmd_resp->address1 = cpu_to_le32(reg_addr1);
3851
3852 status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
3853
3854 if (!status) {
3855 *reg_val0 = le32_to_cpu(cmd_resp->data0);
3856
3857 if (reg_val1)
3858 *reg_val1 = le32_to_cpu(cmd_resp->data1);
3859 }
3860
3861 return status;
3862}
3863
3864/**
Neerav Parikh2fd75f32014-11-12 00:18:20 +00003865 * i40e_aq_resume_port_tx
3866 * @hw: pointer to the hardware structure
3867 * @cmd_details: pointer to command details structure or NULL
3868 *
3869 * Resume port's Tx traffic
3870 **/
3871i40e_status i40e_aq_resume_port_tx(struct i40e_hw *hw,
3872 struct i40e_asq_cmd_details *cmd_details)
3873{
3874 struct i40e_aq_desc desc;
3875 i40e_status status;
3876
3877 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_resume_port_tx);
3878
3879 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3880
3881 return status;
3882}
3883
3884/**
Catherine Sullivand4dfb812013-11-28 06:39:21 +00003885 * i40e_set_pci_config_data - store PCI bus info
3886 * @hw: pointer to hardware structure
3887 * @link_status: the link status word from PCI config space
3888 *
3889 * Stores the PCI bus info (speed, width, type) within the i40e_hw structure
3890 **/
3891void i40e_set_pci_config_data(struct i40e_hw *hw, u16 link_status)
3892{
3893 hw->bus.type = i40e_bus_type_pci_express;
3894
3895 switch (link_status & PCI_EXP_LNKSTA_NLW) {
3896 case PCI_EXP_LNKSTA_NLW_X1:
3897 hw->bus.width = i40e_bus_width_pcie_x1;
3898 break;
3899 case PCI_EXP_LNKSTA_NLW_X2:
3900 hw->bus.width = i40e_bus_width_pcie_x2;
3901 break;
3902 case PCI_EXP_LNKSTA_NLW_X4:
3903 hw->bus.width = i40e_bus_width_pcie_x4;
3904 break;
3905 case PCI_EXP_LNKSTA_NLW_X8:
3906 hw->bus.width = i40e_bus_width_pcie_x8;
3907 break;
3908 default:
3909 hw->bus.width = i40e_bus_width_unknown;
3910 break;
3911 }
3912
3913 switch (link_status & PCI_EXP_LNKSTA_CLS) {
3914 case PCI_EXP_LNKSTA_CLS_2_5GB:
3915 hw->bus.speed = i40e_bus_speed_2500;
3916 break;
3917 case PCI_EXP_LNKSTA_CLS_5_0GB:
3918 hw->bus.speed = i40e_bus_speed_5000;
3919 break;
3920 case PCI_EXP_LNKSTA_CLS_8_0GB:
3921 hw->bus.speed = i40e_bus_speed_8000;
3922 break;
3923 default:
3924 hw->bus.speed = i40e_bus_speed_unknown;
3925 break;
3926 }
3927}
Greg Rosef4492db2015-02-06 08:52:12 +00003928
3929/**
Jesse Brandeburg3169c322015-04-07 19:45:37 -04003930 * i40e_aq_debug_dump
3931 * @hw: pointer to the hardware structure
3932 * @cluster_id: specific cluster to dump
3933 * @table_id: table id within cluster
3934 * @start_index: index of line in the block to read
3935 * @buff_size: dump buffer size
3936 * @buff: dump buffer
3937 * @ret_buff_size: actual buffer size returned
3938 * @ret_next_table: next block to read
3939 * @ret_next_index: next index to read
3940 *
3941 * Dump internal FW/HW data for debug purposes.
3942 *
3943 **/
3944i40e_status i40e_aq_debug_dump(struct i40e_hw *hw, u8 cluster_id,
3945 u8 table_id, u32 start_index, u16 buff_size,
3946 void *buff, u16 *ret_buff_size,
3947 u8 *ret_next_table, u32 *ret_next_index,
3948 struct i40e_asq_cmd_details *cmd_details)
3949{
3950 struct i40e_aq_desc desc;
3951 struct i40e_aqc_debug_dump_internals *cmd =
3952 (struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
3953 struct i40e_aqc_debug_dump_internals *resp =
3954 (struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
3955 i40e_status status;
3956
3957 if (buff_size == 0 || !buff)
3958 return I40E_ERR_PARAM;
3959
3960 i40e_fill_default_direct_cmd_desc(&desc,
3961 i40e_aqc_opc_debug_dump_internals);
3962 /* Indirect Command */
3963 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
3964 if (buff_size > I40E_AQ_LARGE_BUF)
3965 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3966
3967 cmd->cluster_id = cluster_id;
3968 cmd->table_id = table_id;
3969 cmd->idx = cpu_to_le32(start_index);
3970
3971 desc.datalen = cpu_to_le16(buff_size);
3972
3973 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3974 if (!status) {
3975 if (ret_buff_size)
3976 *ret_buff_size = le16_to_cpu(desc.datalen);
3977 if (ret_next_table)
3978 *ret_next_table = resp->table_id;
3979 if (ret_next_index)
3980 *ret_next_index = le32_to_cpu(resp->idx);
3981 }
3982
3983 return status;
3984}
3985
3986/**
Greg Rosef4492db2015-02-06 08:52:12 +00003987 * i40e_read_bw_from_alt_ram
3988 * @hw: pointer to the hardware structure
3989 * @max_bw: pointer for max_bw read
3990 * @min_bw: pointer for min_bw read
3991 * @min_valid: pointer for bool that is true if min_bw is a valid value
3992 * @max_valid: pointer for bool that is true if max_bw is a valid value
3993 *
3994 * Read bw from the alternate ram for the given pf
3995 **/
3996i40e_status i40e_read_bw_from_alt_ram(struct i40e_hw *hw,
3997 u32 *max_bw, u32 *min_bw,
3998 bool *min_valid, bool *max_valid)
3999{
4000 i40e_status status;
4001 u32 max_bw_addr, min_bw_addr;
4002
4003 /* Calculate the address of the min/max bw registers */
4004 max_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
4005 I40E_ALT_STRUCT_MAX_BW_OFFSET +
4006 (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
4007 min_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
4008 I40E_ALT_STRUCT_MIN_BW_OFFSET +
4009 (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
4010
4011 /* Read the bandwidths from alt ram */
4012 status = i40e_aq_alternate_read(hw, max_bw_addr, max_bw,
4013 min_bw_addr, min_bw);
4014
4015 if (*min_bw & I40E_ALT_BW_VALID_MASK)
4016 *min_valid = true;
4017 else
4018 *min_valid = false;
4019
4020 if (*max_bw & I40E_ALT_BW_VALID_MASK)
4021 *max_valid = true;
4022 else
4023 *max_valid = false;
4024
4025 return status;
4026}
4027
4028/**
4029 * i40e_aq_configure_partition_bw
4030 * @hw: pointer to the hardware structure
4031 * @bw_data: Buffer holding valid pfs and bw limits
4032 * @cmd_details: pointer to command details
4033 *
4034 * Configure partitions guaranteed/max bw
4035 **/
4036i40e_status i40e_aq_configure_partition_bw(struct i40e_hw *hw,
4037 struct i40e_aqc_configure_partition_bw_data *bw_data,
4038 struct i40e_asq_cmd_details *cmd_details)
4039{
4040 i40e_status status;
4041 struct i40e_aq_desc desc;
4042 u16 bwd_size = sizeof(*bw_data);
4043
4044 i40e_fill_default_direct_cmd_desc(&desc,
4045 i40e_aqc_opc_configure_partition_bw);
4046
4047 /* Indirect command */
4048 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
4049 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
4050
4051 if (bwd_size > I40E_AQ_LARGE_BUF)
4052 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
4053
4054 desc.datalen = cpu_to_le16(bwd_size);
4055
4056 status = i40e_asq_send_command(hw, &desc, bw_data, bwd_size,
4057 cmd_details);
4058
4059 return status;
4060}