xref: /openbmc/linux/drivers/net/ethernet/intel/i40e/i40e_common.c (revision 86aa961bb4619a68077ebeba21c52e9ba0eab43d)
1ae06c70bSJeff Kirsher // SPDX-License-Identifier: GPL-2.0
290bc8e00SArkadiusz Kubalewski /* Copyright(c) 2013 - 2021 Intel Corporation. */
356a62fc8SJesse Brandeburg 
455cdfd48SJesse Brandeburg #include <linux/avf/virtchnl.h>
5*e383353bSJesse Brandeburg #include <linux/bitfield.h>
6e77220eeSIvan Vecera #include <linux/delay.h>
7e77220eeSIvan Vecera #include <linux/etherdevice.h>
8e77220eeSIvan Vecera #include <linux/pci.h>
9e77220eeSIvan Vecera #include "i40e_adminq_cmd.h"
10e77220eeSIvan Vecera #include "i40e_devids.h"
11e77220eeSIvan Vecera #include "i40e_prototype.h"
12e77220eeSIvan Vecera #include "i40e_register.h"
1356a62fc8SJesse Brandeburg 
1456a62fc8SJesse Brandeburg /**
1556a62fc8SJesse Brandeburg  * i40e_set_mac_type - Sets MAC type
1656a62fc8SJesse Brandeburg  * @hw: pointer to the HW structure
1756a62fc8SJesse Brandeburg  *
1856a62fc8SJesse Brandeburg  * This function sets the mac type of the adapter based on the
1956a62fc8SJesse Brandeburg  * vendor ID and device ID stored in the hw structure.
2056a62fc8SJesse Brandeburg  **/
i40e_set_mac_type(struct i40e_hw * hw)215180ff13SJan Sokolowski int i40e_set_mac_type(struct i40e_hw *hw)
2256a62fc8SJesse Brandeburg {
235180ff13SJan Sokolowski 	int status = 0;
2456a62fc8SJesse Brandeburg 
2556a62fc8SJesse Brandeburg 	if (hw->vendor_id == PCI_VENDOR_ID_INTEL) {
2656a62fc8SJesse Brandeburg 		switch (hw->device_id) {
27ab60085eSShannon Nelson 		case I40E_DEV_ID_SFP_XL710:
28ab60085eSShannon Nelson 		case I40E_DEV_ID_QEMU:
29ab60085eSShannon Nelson 		case I40E_DEV_ID_KX_B:
30ab60085eSShannon Nelson 		case I40E_DEV_ID_KX_C:
31ab60085eSShannon Nelson 		case I40E_DEV_ID_QSFP_A:
32ab60085eSShannon Nelson 		case I40E_DEV_ID_QSFP_B:
33ab60085eSShannon Nelson 		case I40E_DEV_ID_QSFP_C:
346617be3cSStanislaw Grzeszczak 		case I40E_DEV_ID_1G_BASE_T_BC:
353dbdd6c2SAleksandr Loktionov 		case I40E_DEV_ID_5G_BASE_T_BC:
365960d33fSMitch Williams 		case I40E_DEV_ID_10G_BASE_T:
37bc5166b9SShannon Nelson 		case I40E_DEV_ID_10G_BASE_T4:
383df5b9a6SAlice Michael 		case I40E_DEV_ID_10G_BASE_T_BC:
392e45d3f4SAleksandr Loktionov 		case I40E_DEV_ID_10G_B:
402e45d3f4SAleksandr Loktionov 		case I40E_DEV_ID_10G_SFP:
41ae24b409SJesse Brandeburg 		case I40E_DEV_ID_20G_KR2:
4248a3b512SShannon Nelson 		case I40E_DEV_ID_20G_KR2_A:
433123237aSCarolyn Wyborny 		case I40E_DEV_ID_25G_B:
443123237aSCarolyn Wyborny 		case I40E_DEV_ID_25G_SFP28:
45e576e769SAleksandr Loktionov 		case I40E_DEV_ID_X710_N3000:
46e576e769SAleksandr Loktionov 		case I40E_DEV_ID_XXV710_N3000:
4756a62fc8SJesse Brandeburg 			hw->mac.type = I40E_MAC_XL710;
4856a62fc8SJesse Brandeburg 			break;
4935dae51dSAnjali Singhai Jain 		case I40E_DEV_ID_KX_X722:
5035dae51dSAnjali Singhai Jain 		case I40E_DEV_ID_QSFP_X722:
5187e6c1d7SAnjali Singhai Jain 		case I40E_DEV_ID_SFP_X722:
5287e6c1d7SAnjali Singhai Jain 		case I40E_DEV_ID_1G_BASE_T_X722:
5387e6c1d7SAnjali Singhai Jain 		case I40E_DEV_ID_10G_BASE_T_X722:
54d6bf58c2SCatherine Sullivan 		case I40E_DEV_ID_SFP_I_X722:
55a941d5eeSMateusz Palczewski 		case I40E_DEV_ID_SFP_X722_A:
5687e6c1d7SAnjali Singhai Jain 			hw->mac.type = I40E_MAC_X722;
5787e6c1d7SAnjali Singhai Jain 			break;
5856a62fc8SJesse Brandeburg 		default:
5956a62fc8SJesse Brandeburg 			hw->mac.type = I40E_MAC_GENERIC;
6056a62fc8SJesse Brandeburg 			break;
6156a62fc8SJesse Brandeburg 		}
6256a62fc8SJesse Brandeburg 	} else {
63230f3d53SJan Sokolowski 		status = -ENODEV;
6456a62fc8SJesse Brandeburg 	}
6556a62fc8SJesse Brandeburg 
6656a62fc8SJesse Brandeburg 	hw_dbg(hw, "i40e_set_mac_type found mac: %d, returns: %d\n",
6756a62fc8SJesse Brandeburg 		  hw->mac.type, status);
6856a62fc8SJesse Brandeburg 	return status;
6956a62fc8SJesse Brandeburg }
7056a62fc8SJesse Brandeburg 
7156a62fc8SJesse Brandeburg /**
72f1c7e72eSShannon Nelson  * i40e_aq_str - convert AQ err code to a string
73f1c7e72eSShannon Nelson  * @hw: pointer to the HW structure
74f1c7e72eSShannon Nelson  * @aq_err: the AQ error code to convert
75f1c7e72eSShannon Nelson  **/
i40e_aq_str(struct i40e_hw * hw,enum i40e_admin_queue_err aq_err)764e68adfeSJingjing Wu const char *i40e_aq_str(struct i40e_hw *hw, enum i40e_admin_queue_err aq_err)
77f1c7e72eSShannon Nelson {
78f1c7e72eSShannon Nelson 	switch (aq_err) {
79f1c7e72eSShannon Nelson 	case I40E_AQ_RC_OK:
80f1c7e72eSShannon Nelson 		return "OK";
81f1c7e72eSShannon Nelson 	case I40E_AQ_RC_EPERM:
82f1c7e72eSShannon Nelson 		return "I40E_AQ_RC_EPERM";
83f1c7e72eSShannon Nelson 	case I40E_AQ_RC_ENOENT:
84f1c7e72eSShannon Nelson 		return "I40E_AQ_RC_ENOENT";
85f1c7e72eSShannon Nelson 	case I40E_AQ_RC_ESRCH:
86f1c7e72eSShannon Nelson 		return "I40E_AQ_RC_ESRCH";
87f1c7e72eSShannon Nelson 	case I40E_AQ_RC_EINTR:
88f1c7e72eSShannon Nelson 		return "I40E_AQ_RC_EINTR";
89f1c7e72eSShannon Nelson 	case I40E_AQ_RC_EIO:
90f1c7e72eSShannon Nelson 		return "I40E_AQ_RC_EIO";
91f1c7e72eSShannon Nelson 	case I40E_AQ_RC_ENXIO:
92f1c7e72eSShannon Nelson 		return "I40E_AQ_RC_ENXIO";
93f1c7e72eSShannon Nelson 	case I40E_AQ_RC_E2BIG:
94f1c7e72eSShannon Nelson 		return "I40E_AQ_RC_E2BIG";
95f1c7e72eSShannon Nelson 	case I40E_AQ_RC_EAGAIN:
96f1c7e72eSShannon Nelson 		return "I40E_AQ_RC_EAGAIN";
97f1c7e72eSShannon Nelson 	case I40E_AQ_RC_ENOMEM:
98f1c7e72eSShannon Nelson 		return "I40E_AQ_RC_ENOMEM";
99f1c7e72eSShannon Nelson 	case I40E_AQ_RC_EACCES:
100f1c7e72eSShannon Nelson 		return "I40E_AQ_RC_EACCES";
101f1c7e72eSShannon Nelson 	case I40E_AQ_RC_EFAULT:
102f1c7e72eSShannon Nelson 		return "I40E_AQ_RC_EFAULT";
103f1c7e72eSShannon Nelson 	case I40E_AQ_RC_EBUSY:
104f1c7e72eSShannon Nelson 		return "I40E_AQ_RC_EBUSY";
105f1c7e72eSShannon Nelson 	case I40E_AQ_RC_EEXIST:
106f1c7e72eSShannon Nelson 		return "I40E_AQ_RC_EEXIST";
107f1c7e72eSShannon Nelson 	case I40E_AQ_RC_EINVAL:
108f1c7e72eSShannon Nelson 		return "I40E_AQ_RC_EINVAL";
109f1c7e72eSShannon Nelson 	case I40E_AQ_RC_ENOTTY:
110f1c7e72eSShannon Nelson 		return "I40E_AQ_RC_ENOTTY";
111f1c7e72eSShannon Nelson 	case I40E_AQ_RC_ENOSPC:
112f1c7e72eSShannon Nelson 		return "I40E_AQ_RC_ENOSPC";
113f1c7e72eSShannon Nelson 	case I40E_AQ_RC_ENOSYS:
114f1c7e72eSShannon Nelson 		return "I40E_AQ_RC_ENOSYS";
115f1c7e72eSShannon Nelson 	case I40E_AQ_RC_ERANGE:
116f1c7e72eSShannon Nelson 		return "I40E_AQ_RC_ERANGE";
117f1c7e72eSShannon Nelson 	case I40E_AQ_RC_EFLUSHED:
118f1c7e72eSShannon Nelson 		return "I40E_AQ_RC_EFLUSHED";
119f1c7e72eSShannon Nelson 	case I40E_AQ_RC_BAD_ADDR:
120f1c7e72eSShannon Nelson 		return "I40E_AQ_RC_BAD_ADDR";
121f1c7e72eSShannon Nelson 	case I40E_AQ_RC_EMODE:
122f1c7e72eSShannon Nelson 		return "I40E_AQ_RC_EMODE";
123f1c7e72eSShannon Nelson 	case I40E_AQ_RC_EFBIG:
124f1c7e72eSShannon Nelson 		return "I40E_AQ_RC_EFBIG";
125f1c7e72eSShannon Nelson 	}
126f1c7e72eSShannon Nelson 
127f1c7e72eSShannon Nelson 	snprintf(hw->err_str, sizeof(hw->err_str), "%d", aq_err);
128f1c7e72eSShannon Nelson 	return hw->err_str;
129f1c7e72eSShannon Nelson }
130f1c7e72eSShannon Nelson 
131f1c7e72eSShannon Nelson /**
13256a62fc8SJesse Brandeburg  * i40e_debug_aq
13356a62fc8SJesse Brandeburg  * @hw: debug mask related to admin queue
13498d44381SJeff Kirsher  * @mask: debug mask
13598d44381SJeff Kirsher  * @desc: pointer to admin queue descriptor
13656a62fc8SJesse Brandeburg  * @buffer: pointer to command buffer
137f905dd62SShannon Nelson  * @buf_len: max length of buffer
13856a62fc8SJesse Brandeburg  *
13956a62fc8SJesse Brandeburg  * Dumps debug log about adminq command with descriptor contents.
14056a62fc8SJesse Brandeburg  **/
i40e_debug_aq(struct i40e_hw * hw,enum i40e_debug_mask mask,void * desc,void * buffer,u16 buf_len)14156a62fc8SJesse Brandeburg void i40e_debug_aq(struct i40e_hw *hw, enum i40e_debug_mask mask, void *desc,
142f905dd62SShannon Nelson 		   void *buffer, u16 buf_len)
14356a62fc8SJesse Brandeburg {
14456a62fc8SJesse Brandeburg 	struct i40e_aq_desc *aq_desc = (struct i40e_aq_desc *)desc;
145b83ebf50SDoug Dziggel 	u32 effective_mask = hw->debug_mask & mask;
146b83ebf50SDoug Dziggel 	char prefix[27];
147cd956722SHeinrich Schuchardt 	u16 len;
14837a2973aSShannon Nelson 	u8 *buf = (u8 *)buffer;
14956a62fc8SJesse Brandeburg 
150b83ebf50SDoug Dziggel 	if (!effective_mask || !desc)
15156a62fc8SJesse Brandeburg 		return;
15256a62fc8SJesse Brandeburg 
153cd956722SHeinrich Schuchardt 	len = le16_to_cpu(aq_desc->datalen);
154cd956722SHeinrich Schuchardt 
155b83ebf50SDoug Dziggel 	i40e_debug(hw, mask & I40E_DEBUG_AQ_DESCRIPTOR,
15656a62fc8SJesse Brandeburg 		   "AQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
157f1abd7dbSPaul M Stillwell Jr 		   le16_to_cpu(aq_desc->opcode),
158f1abd7dbSPaul M Stillwell Jr 		   le16_to_cpu(aq_desc->flags),
159f1abd7dbSPaul M Stillwell Jr 		   le16_to_cpu(aq_desc->datalen),
160f1abd7dbSPaul M Stillwell Jr 		   le16_to_cpu(aq_desc->retval));
161b83ebf50SDoug Dziggel 	i40e_debug(hw, mask & I40E_DEBUG_AQ_DESCRIPTOR,
162b83ebf50SDoug Dziggel 		   "\tcookie (h,l) 0x%08X 0x%08X\n",
163f1abd7dbSPaul M Stillwell Jr 		   le32_to_cpu(aq_desc->cookie_high),
164f1abd7dbSPaul M Stillwell Jr 		   le32_to_cpu(aq_desc->cookie_low));
165b83ebf50SDoug Dziggel 	i40e_debug(hw, mask & I40E_DEBUG_AQ_DESCRIPTOR,
166b83ebf50SDoug Dziggel 		   "\tparam (0,1)  0x%08X 0x%08X\n",
167f1abd7dbSPaul M Stillwell Jr 		   le32_to_cpu(aq_desc->params.internal.param0),
168f1abd7dbSPaul M Stillwell Jr 		   le32_to_cpu(aq_desc->params.internal.param1));
169b83ebf50SDoug Dziggel 	i40e_debug(hw, mask & I40E_DEBUG_AQ_DESCRIPTOR,
170b83ebf50SDoug Dziggel 		   "\taddr (h,l)   0x%08X 0x%08X\n",
171f1abd7dbSPaul M Stillwell Jr 		   le32_to_cpu(aq_desc->params.external.addr_high),
172f1abd7dbSPaul M Stillwell Jr 		   le32_to_cpu(aq_desc->params.external.addr_low));
17356a62fc8SJesse Brandeburg 
174b83ebf50SDoug Dziggel 	if (buffer && buf_len != 0 && len != 0 &&
175b83ebf50SDoug Dziggel 	    (effective_mask & I40E_DEBUG_AQ_DESC_BUFFER)) {
17656a62fc8SJesse Brandeburg 		i40e_debug(hw, mask, "AQ CMD Buffer:\n");
177f905dd62SShannon Nelson 		if (buf_len < len)
178f905dd62SShannon Nelson 			len = buf_len;
179773d4023SAlan Brady 
180b5d5504aSJacob Keller 		snprintf(prefix, sizeof(prefix),
181773d4023SAlan Brady 			 "i40e %02x:%02x.%x: \t0x",
182773d4023SAlan Brady 			 hw->bus.bus_id,
183773d4023SAlan Brady 			 hw->bus.device,
184773d4023SAlan Brady 			 hw->bus.func);
185773d4023SAlan Brady 
186773d4023SAlan Brady 		print_hex_dump(KERN_INFO, prefix, DUMP_PREFIX_OFFSET,
187773d4023SAlan Brady 			       16, 1, buf, len, false);
188773d4023SAlan Brady 	}
18956a62fc8SJesse Brandeburg }
19056a62fc8SJesse Brandeburg 
19156a62fc8SJesse Brandeburg /**
192e1860d8fSAnjali Singhai Jain  * i40e_check_asq_alive
193e1860d8fSAnjali Singhai Jain  * @hw: pointer to the hw struct
194e1860d8fSAnjali Singhai Jain  *
195e1860d8fSAnjali Singhai Jain  * Returns true if Queue is enabled else false.
196e1860d8fSAnjali Singhai Jain  **/
i40e_check_asq_alive(struct i40e_hw * hw)197e1860d8fSAnjali Singhai Jain bool i40e_check_asq_alive(struct i40e_hw *hw)
198e1860d8fSAnjali Singhai Jain {
1998b833b4fSKevin Scott 	if (hw->aq.asq.len)
2008b833b4fSKevin Scott 		return !!(rd32(hw, hw->aq.asq.len) &
2018b833b4fSKevin Scott 			  I40E_PF_ATQLEN_ATQENABLE_MASK);
2028b833b4fSKevin Scott 	else
2038b833b4fSKevin Scott 		return false;
204e1860d8fSAnjali Singhai Jain }
205e1860d8fSAnjali Singhai Jain 
206e1860d8fSAnjali Singhai Jain /**
207e1860d8fSAnjali Singhai Jain  * i40e_aq_queue_shutdown
208e1860d8fSAnjali Singhai Jain  * @hw: pointer to the hw struct
209e1860d8fSAnjali Singhai Jain  * @unloading: is the driver unloading itself
210e1860d8fSAnjali Singhai Jain  *
211e1860d8fSAnjali Singhai Jain  * Tell the Firmware that we're shutting down the AdminQ and whether
212e1860d8fSAnjali Singhai Jain  * or not the driver is unloading as well.
213e1860d8fSAnjali Singhai Jain  **/
i40e_aq_queue_shutdown(struct i40e_hw * hw,bool unloading)2145180ff13SJan Sokolowski int i40e_aq_queue_shutdown(struct i40e_hw *hw,
215e1860d8fSAnjali Singhai Jain 			   bool unloading)
216e1860d8fSAnjali Singhai Jain {
217e1860d8fSAnjali Singhai Jain 	struct i40e_aq_desc desc;
218e1860d8fSAnjali Singhai Jain 	struct i40e_aqc_queue_shutdown *cmd =
219e1860d8fSAnjali Singhai Jain 		(struct i40e_aqc_queue_shutdown *)&desc.params.raw;
2205180ff13SJan Sokolowski 	int status;
221e1860d8fSAnjali Singhai Jain 
222e1860d8fSAnjali Singhai Jain 	i40e_fill_default_direct_cmd_desc(&desc,
223e1860d8fSAnjali Singhai Jain 					  i40e_aqc_opc_queue_shutdown);
224e1860d8fSAnjali Singhai Jain 
225e1860d8fSAnjali Singhai Jain 	if (unloading)
226e1860d8fSAnjali Singhai Jain 		cmd->driver_unloading = cpu_to_le32(I40E_AQ_DRIVER_UNLOADING);
227e1860d8fSAnjali Singhai Jain 	status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
228e1860d8fSAnjali Singhai Jain 
229e1860d8fSAnjali Singhai Jain 	return status;
230e1860d8fSAnjali Singhai Jain }
231e1860d8fSAnjali Singhai Jain 
232e50c8d6dSAnjali Singhai Jain /**
233e50c8d6dSAnjali Singhai Jain  * i40e_aq_get_set_rss_lut
234e50c8d6dSAnjali Singhai Jain  * @hw: pointer to the hardware structure
235e50c8d6dSAnjali Singhai Jain  * @vsi_id: vsi fw index
236e50c8d6dSAnjali Singhai Jain  * @pf_lut: for PF table set true, for VSI table set false
237e50c8d6dSAnjali Singhai Jain  * @lut: pointer to the lut buffer provided by the caller
238e50c8d6dSAnjali Singhai Jain  * @lut_size: size of the lut buffer
239e50c8d6dSAnjali Singhai Jain  * @set: set true to set the table, false to get the table
240e50c8d6dSAnjali Singhai Jain  *
241e50c8d6dSAnjali Singhai Jain  * Internal function to get or set RSS look up table
242e50c8d6dSAnjali Singhai Jain  **/
i40e_aq_get_set_rss_lut(struct i40e_hw * hw,u16 vsi_id,bool pf_lut,u8 * lut,u16 lut_size,bool set)2435180ff13SJan Sokolowski static int i40e_aq_get_set_rss_lut(struct i40e_hw *hw,
244e50c8d6dSAnjali Singhai Jain 				   u16 vsi_id, bool pf_lut,
245e50c8d6dSAnjali Singhai Jain 				   u8 *lut, u16 lut_size,
246e50c8d6dSAnjali Singhai Jain 				   bool set)
247e50c8d6dSAnjali Singhai Jain {
248e50c8d6dSAnjali Singhai Jain 	struct i40e_aq_desc desc;
249e50c8d6dSAnjali Singhai Jain 	struct i40e_aqc_get_set_rss_lut *cmd_resp =
250e50c8d6dSAnjali Singhai Jain 		   (struct i40e_aqc_get_set_rss_lut *)&desc.params.raw;
2515180ff13SJan Sokolowski 	int status;
252e50c8d6dSAnjali Singhai Jain 
253e50c8d6dSAnjali Singhai Jain 	if (set)
254e50c8d6dSAnjali Singhai Jain 		i40e_fill_default_direct_cmd_desc(&desc,
255e50c8d6dSAnjali Singhai Jain 						  i40e_aqc_opc_set_rss_lut);
256e50c8d6dSAnjali Singhai Jain 	else
257e50c8d6dSAnjali Singhai Jain 		i40e_fill_default_direct_cmd_desc(&desc,
258e50c8d6dSAnjali Singhai Jain 						  i40e_aqc_opc_get_rss_lut);
259e50c8d6dSAnjali Singhai Jain 
260e50c8d6dSAnjali Singhai Jain 	/* Indirect command */
261e50c8d6dSAnjali Singhai Jain 	desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
262e50c8d6dSAnjali Singhai Jain 	desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
263e50c8d6dSAnjali Singhai Jain 
264e50c8d6dSAnjali Singhai Jain 	cmd_resp->vsi_id =
265e50c8d6dSAnjali Singhai Jain 			cpu_to_le16((u16)((vsi_id <<
266e50c8d6dSAnjali Singhai Jain 					  I40E_AQC_SET_RSS_LUT_VSI_ID_SHIFT) &
267e50c8d6dSAnjali Singhai Jain 					  I40E_AQC_SET_RSS_LUT_VSI_ID_MASK));
268e50c8d6dSAnjali Singhai Jain 	cmd_resp->vsi_id |= cpu_to_le16((u16)I40E_AQC_SET_RSS_LUT_VSI_VALID);
269e50c8d6dSAnjali Singhai Jain 
270e50c8d6dSAnjali Singhai Jain 	if (pf_lut)
271e50c8d6dSAnjali Singhai Jain 		cmd_resp->flags |= cpu_to_le16((u16)
272e50c8d6dSAnjali Singhai Jain 					((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_PF <<
273e50c8d6dSAnjali Singhai Jain 					I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
274e50c8d6dSAnjali Singhai Jain 					I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
275e50c8d6dSAnjali Singhai Jain 	else
276e50c8d6dSAnjali Singhai Jain 		cmd_resp->flags |= cpu_to_le16((u16)
277e50c8d6dSAnjali Singhai Jain 					((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_VSI <<
278e50c8d6dSAnjali Singhai Jain 					I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
279e50c8d6dSAnjali Singhai Jain 					I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
280e50c8d6dSAnjali Singhai Jain 
281e50c8d6dSAnjali Singhai Jain 	status = i40e_asq_send_command(hw, &desc, lut, lut_size, NULL);
282e50c8d6dSAnjali Singhai Jain 
283e50c8d6dSAnjali Singhai Jain 	return status;
284e50c8d6dSAnjali Singhai Jain }
285e50c8d6dSAnjali Singhai Jain 
286e50c8d6dSAnjali Singhai Jain /**
287e50c8d6dSAnjali Singhai Jain  * i40e_aq_get_rss_lut
288e50c8d6dSAnjali Singhai Jain  * @hw: pointer to the hardware structure
289e50c8d6dSAnjali Singhai Jain  * @vsi_id: vsi fw index
290e50c8d6dSAnjali Singhai Jain  * @pf_lut: for PF table set true, for VSI table set false
291e50c8d6dSAnjali Singhai Jain  * @lut: pointer to the lut buffer provided by the caller
292e50c8d6dSAnjali Singhai Jain  * @lut_size: size of the lut buffer
293e50c8d6dSAnjali Singhai Jain  *
294e50c8d6dSAnjali Singhai Jain  * get the RSS lookup table, PF or VSI type
295e50c8d6dSAnjali Singhai Jain  **/
i40e_aq_get_rss_lut(struct i40e_hw * hw,u16 vsi_id,bool pf_lut,u8 * lut,u16 lut_size)2965180ff13SJan Sokolowski int i40e_aq_get_rss_lut(struct i40e_hw *hw, u16 vsi_id,
297e50c8d6dSAnjali Singhai Jain 			bool pf_lut, u8 *lut, u16 lut_size)
298e50c8d6dSAnjali Singhai Jain {
299e50c8d6dSAnjali Singhai Jain 	return i40e_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size,
300e50c8d6dSAnjali Singhai Jain 				       false);
301e50c8d6dSAnjali Singhai Jain }
302e50c8d6dSAnjali Singhai Jain 
303e50c8d6dSAnjali Singhai Jain /**
304e50c8d6dSAnjali Singhai Jain  * i40e_aq_set_rss_lut
305e50c8d6dSAnjali Singhai Jain  * @hw: pointer to the hardware structure
306e50c8d6dSAnjali Singhai Jain  * @vsi_id: vsi fw index
307e50c8d6dSAnjali Singhai Jain  * @pf_lut: for PF table set true, for VSI table set false
308e50c8d6dSAnjali Singhai Jain  * @lut: pointer to the lut buffer provided by the caller
309e50c8d6dSAnjali Singhai Jain  * @lut_size: size of the lut buffer
310e50c8d6dSAnjali Singhai Jain  *
311e50c8d6dSAnjali Singhai Jain  * set the RSS lookup table, PF or VSI type
312e50c8d6dSAnjali Singhai Jain  **/
i40e_aq_set_rss_lut(struct i40e_hw * hw,u16 vsi_id,bool pf_lut,u8 * lut,u16 lut_size)3135180ff13SJan Sokolowski int i40e_aq_set_rss_lut(struct i40e_hw *hw, u16 vsi_id,
314e50c8d6dSAnjali Singhai Jain 			bool pf_lut, u8 *lut, u16 lut_size)
315e50c8d6dSAnjali Singhai Jain {
316e50c8d6dSAnjali Singhai Jain 	return i40e_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size, true);
317e50c8d6dSAnjali Singhai Jain }
318e50c8d6dSAnjali Singhai Jain 
319e50c8d6dSAnjali Singhai Jain /**
320e50c8d6dSAnjali Singhai Jain  * i40e_aq_get_set_rss_key
321e50c8d6dSAnjali Singhai Jain  * @hw: pointer to the hw struct
322e50c8d6dSAnjali Singhai Jain  * @vsi_id: vsi fw index
323e50c8d6dSAnjali Singhai Jain  * @key: pointer to key info struct
324e50c8d6dSAnjali Singhai Jain  * @set: set true to set the key, false to get the key
325e50c8d6dSAnjali Singhai Jain  *
326e50c8d6dSAnjali Singhai Jain  * get the RSS key per VSI
327e50c8d6dSAnjali Singhai Jain  **/
i40e_aq_get_set_rss_key(struct i40e_hw * hw,u16 vsi_id,struct i40e_aqc_get_set_rss_key_data * key,bool set)3285180ff13SJan Sokolowski static int i40e_aq_get_set_rss_key(struct i40e_hw *hw,
329e50c8d6dSAnjali Singhai Jain 				   u16 vsi_id,
330e50c8d6dSAnjali Singhai Jain 				   struct i40e_aqc_get_set_rss_key_data *key,
331e50c8d6dSAnjali Singhai Jain 				   bool set)
332e50c8d6dSAnjali Singhai Jain {
333e50c8d6dSAnjali Singhai Jain 	struct i40e_aq_desc desc;
334e50c8d6dSAnjali Singhai Jain 	struct i40e_aqc_get_set_rss_key *cmd_resp =
335e50c8d6dSAnjali Singhai Jain 			(struct i40e_aqc_get_set_rss_key *)&desc.params.raw;
336e50c8d6dSAnjali Singhai Jain 	u16 key_size = sizeof(struct i40e_aqc_get_set_rss_key_data);
3375180ff13SJan Sokolowski 	int status;
338e50c8d6dSAnjali Singhai Jain 
339e50c8d6dSAnjali Singhai Jain 	if (set)
340e50c8d6dSAnjali Singhai Jain 		i40e_fill_default_direct_cmd_desc(&desc,
341e50c8d6dSAnjali Singhai Jain 						  i40e_aqc_opc_set_rss_key);
342e50c8d6dSAnjali Singhai Jain 	else
343e50c8d6dSAnjali Singhai Jain 		i40e_fill_default_direct_cmd_desc(&desc,
344e50c8d6dSAnjali Singhai Jain 						  i40e_aqc_opc_get_rss_key);
345e50c8d6dSAnjali Singhai Jain 
346e50c8d6dSAnjali Singhai Jain 	/* Indirect command */
347e50c8d6dSAnjali Singhai Jain 	desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
348e50c8d6dSAnjali Singhai Jain 	desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
349e50c8d6dSAnjali Singhai Jain 
350e50c8d6dSAnjali Singhai Jain 	cmd_resp->vsi_id =
351e50c8d6dSAnjali Singhai Jain 			cpu_to_le16((u16)((vsi_id <<
352e50c8d6dSAnjali Singhai Jain 					  I40E_AQC_SET_RSS_KEY_VSI_ID_SHIFT) &
353e50c8d6dSAnjali Singhai Jain 					  I40E_AQC_SET_RSS_KEY_VSI_ID_MASK));
354e50c8d6dSAnjali Singhai Jain 	cmd_resp->vsi_id |= cpu_to_le16((u16)I40E_AQC_SET_RSS_KEY_VSI_VALID);
355e50c8d6dSAnjali Singhai Jain 
356e50c8d6dSAnjali Singhai Jain 	status = i40e_asq_send_command(hw, &desc, key, key_size, NULL);
357e50c8d6dSAnjali Singhai Jain 
358e50c8d6dSAnjali Singhai Jain 	return status;
359e50c8d6dSAnjali Singhai Jain }
360e50c8d6dSAnjali Singhai Jain 
361e50c8d6dSAnjali Singhai Jain /**
362e50c8d6dSAnjali Singhai Jain  * i40e_aq_get_rss_key
363e50c8d6dSAnjali Singhai Jain  * @hw: pointer to the hw struct
364e50c8d6dSAnjali Singhai Jain  * @vsi_id: vsi fw index
365e50c8d6dSAnjali Singhai Jain  * @key: pointer to key info struct
366e50c8d6dSAnjali Singhai Jain  *
367e50c8d6dSAnjali Singhai Jain  **/
i40e_aq_get_rss_key(struct i40e_hw * hw,u16 vsi_id,struct i40e_aqc_get_set_rss_key_data * key)3685180ff13SJan Sokolowski int i40e_aq_get_rss_key(struct i40e_hw *hw,
369e50c8d6dSAnjali Singhai Jain 			u16 vsi_id,
370e50c8d6dSAnjali Singhai Jain 			struct i40e_aqc_get_set_rss_key_data *key)
371e50c8d6dSAnjali Singhai Jain {
372e50c8d6dSAnjali Singhai Jain 	return i40e_aq_get_set_rss_key(hw, vsi_id, key, false);
373e50c8d6dSAnjali Singhai Jain }
374e50c8d6dSAnjali Singhai Jain 
375e50c8d6dSAnjali Singhai Jain /**
376e50c8d6dSAnjali Singhai Jain  * i40e_aq_set_rss_key
377e50c8d6dSAnjali Singhai Jain  * @hw: pointer to the hw struct
378e50c8d6dSAnjali Singhai Jain  * @vsi_id: vsi fw index
379e50c8d6dSAnjali Singhai Jain  * @key: pointer to key info struct
380e50c8d6dSAnjali Singhai Jain  *
381e50c8d6dSAnjali Singhai Jain  * set the RSS key per VSI
382e50c8d6dSAnjali Singhai Jain  **/
i40e_aq_set_rss_key(struct i40e_hw * hw,u16 vsi_id,struct i40e_aqc_get_set_rss_key_data * key)3835180ff13SJan Sokolowski int i40e_aq_set_rss_key(struct i40e_hw *hw,
384e50c8d6dSAnjali Singhai Jain 			u16 vsi_id,
385e50c8d6dSAnjali Singhai Jain 			struct i40e_aqc_get_set_rss_key_data *key)
386e50c8d6dSAnjali Singhai Jain {
387e50c8d6dSAnjali Singhai Jain 	return i40e_aq_get_set_rss_key(hw, vsi_id, key, true);
388e50c8d6dSAnjali Singhai Jain }
389e50c8d6dSAnjali Singhai Jain 
390206812b5SJesse Brandeburg /* The i40e_ptype_lookup table is used to convert from the 8-bit ptype in the
391206812b5SJesse Brandeburg  * hardware to a bit-field that can be used by SW to more easily determine the
392206812b5SJesse Brandeburg  * packet type.
393206812b5SJesse Brandeburg  *
394206812b5SJesse Brandeburg  * Macros are used to shorten the table lines and make this table human
395206812b5SJesse Brandeburg  * readable.
396206812b5SJesse Brandeburg  *
397206812b5SJesse Brandeburg  * We store the PTYPE in the top byte of the bit field - this is just so that
398206812b5SJesse Brandeburg  * we can check that the table doesn't have a row missing, as the index into
399206812b5SJesse Brandeburg  * the table should be the PTYPE.
400206812b5SJesse Brandeburg  *
401206812b5SJesse Brandeburg  * Typical work flow:
402206812b5SJesse Brandeburg  *
403206812b5SJesse Brandeburg  * IF NOT i40e_ptype_lookup[ptype].known
404206812b5SJesse Brandeburg  * THEN
405206812b5SJesse Brandeburg  *      Packet is unknown
406206812b5SJesse Brandeburg  * ELSE IF i40e_ptype_lookup[ptype].outer_ip == I40E_RX_PTYPE_OUTER_IP
407206812b5SJesse Brandeburg  *      Use the rest of the fields to look at the tunnels, inner protocols, etc
408206812b5SJesse Brandeburg  * ELSE
409206812b5SJesse Brandeburg  *      Use the enum i40e_rx_l2_ptype to decode the packet type
410206812b5SJesse Brandeburg  * ENDIF
411206812b5SJesse Brandeburg  */
412206812b5SJesse Brandeburg 
413c6e088bfSJesse Brandeburg /* macro to make the table lines short, use explicit indexing with [PTYPE] */
414206812b5SJesse Brandeburg #define I40E_PTT(PTYPE, OUTER_IP, OUTER_IP_VER, OUTER_FRAG, T, TE, TEF, I, PL)\
415c6e088bfSJesse Brandeburg 	[PTYPE] = { \
416206812b5SJesse Brandeburg 		1, \
417206812b5SJesse Brandeburg 		I40E_RX_PTYPE_OUTER_##OUTER_IP, \
418206812b5SJesse Brandeburg 		I40E_RX_PTYPE_OUTER_##OUTER_IP_VER, \
419206812b5SJesse Brandeburg 		I40E_RX_PTYPE_##OUTER_FRAG, \
420206812b5SJesse Brandeburg 		I40E_RX_PTYPE_TUNNEL_##T, \
421206812b5SJesse Brandeburg 		I40E_RX_PTYPE_TUNNEL_END_##TE, \
422206812b5SJesse Brandeburg 		I40E_RX_PTYPE_##TEF, \
423206812b5SJesse Brandeburg 		I40E_RX_PTYPE_INNER_PROT_##I, \
424206812b5SJesse Brandeburg 		I40E_RX_PTYPE_PAYLOAD_LAYER_##PL }
425206812b5SJesse Brandeburg 
426c6e088bfSJesse Brandeburg #define I40E_PTT_UNUSED_ENTRY(PTYPE) [PTYPE] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
427206812b5SJesse Brandeburg 
428206812b5SJesse Brandeburg /* shorter macros makes the table fit but are terse */
429206812b5SJesse Brandeburg #define I40E_RX_PTYPE_NOF		I40E_RX_PTYPE_NOT_FRAG
430206812b5SJesse Brandeburg #define I40E_RX_PTYPE_FRG		I40E_RX_PTYPE_FRAG
431206812b5SJesse Brandeburg #define I40E_RX_PTYPE_INNER_PROT_TS	I40E_RX_PTYPE_INNER_PROT_TIMESYNC
432206812b5SJesse Brandeburg 
433c6e088bfSJesse Brandeburg /* Lookup table mapping in the 8-bit HW PTYPE to the bit field for decoding */
434c6e088bfSJesse Brandeburg struct i40e_rx_ptype_decoded i40e_ptype_lookup[BIT(8)] = {
435206812b5SJesse Brandeburg 	/* L2 Packet types */
436206812b5SJesse Brandeburg 	I40E_PTT_UNUSED_ENTRY(0),
437206812b5SJesse Brandeburg 	I40E_PTT(1,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
438206812b5SJesse Brandeburg 	I40E_PTT(2,  L2, NONE, NOF, NONE, NONE, NOF, TS,   PAY2),
439206812b5SJesse Brandeburg 	I40E_PTT(3,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
440206812b5SJesse Brandeburg 	I40E_PTT_UNUSED_ENTRY(4),
441206812b5SJesse Brandeburg 	I40E_PTT_UNUSED_ENTRY(5),
442206812b5SJesse Brandeburg 	I40E_PTT(6,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
443206812b5SJesse Brandeburg 	I40E_PTT(7,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
444206812b5SJesse Brandeburg 	I40E_PTT_UNUSED_ENTRY(8),
445206812b5SJesse Brandeburg 	I40E_PTT_UNUSED_ENTRY(9),
446206812b5SJesse Brandeburg 	I40E_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
447206812b5SJesse Brandeburg 	I40E_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
448206812b5SJesse Brandeburg 	I40E_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
449206812b5SJesse Brandeburg 	I40E_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
450206812b5SJesse Brandeburg 	I40E_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
451206812b5SJesse Brandeburg 	I40E_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
452206812b5SJesse Brandeburg 	I40E_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
453206812b5SJesse Brandeburg 	I40E_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
454206812b5SJesse Brandeburg 	I40E_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
455206812b5SJesse Brandeburg 	I40E_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
456206812b5SJesse Brandeburg 	I40E_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
457206812b5SJesse Brandeburg 	I40E_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
458206812b5SJesse Brandeburg 
459206812b5SJesse Brandeburg 	/* Non Tunneled IPv4 */
460206812b5SJesse Brandeburg 	I40E_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
461206812b5SJesse Brandeburg 	I40E_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
462206812b5SJesse Brandeburg 	I40E_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP,  PAY4),
463206812b5SJesse Brandeburg 	I40E_PTT_UNUSED_ENTRY(25),
464206812b5SJesse Brandeburg 	I40E_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP,  PAY4),
465206812b5SJesse Brandeburg 	I40E_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
466206812b5SJesse Brandeburg 	I40E_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
467206812b5SJesse Brandeburg 
468206812b5SJesse Brandeburg 	/* IPv4 --> IPv4 */
469206812b5SJesse Brandeburg 	I40E_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
470206812b5SJesse Brandeburg 	I40E_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
471206812b5SJesse Brandeburg 	I40E_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP,  PAY4),
472206812b5SJesse Brandeburg 	I40E_PTT_UNUSED_ENTRY(32),
473206812b5SJesse Brandeburg 	I40E_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP,  PAY4),
474206812b5SJesse Brandeburg 	I40E_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
475206812b5SJesse Brandeburg 	I40E_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
476206812b5SJesse Brandeburg 
477206812b5SJesse Brandeburg 	/* IPv4 --> IPv6 */
478206812b5SJesse Brandeburg 	I40E_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
479206812b5SJesse Brandeburg 	I40E_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
480206812b5SJesse Brandeburg 	I40E_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP,  PAY4),
481206812b5SJesse Brandeburg 	I40E_PTT_UNUSED_ENTRY(39),
482206812b5SJesse Brandeburg 	I40E_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP,  PAY4),
483206812b5SJesse Brandeburg 	I40E_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
484206812b5SJesse Brandeburg 	I40E_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
485206812b5SJesse Brandeburg 
486206812b5SJesse Brandeburg 	/* IPv4 --> GRE/NAT */
487206812b5SJesse Brandeburg 	I40E_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
488206812b5SJesse Brandeburg 
489206812b5SJesse Brandeburg 	/* IPv4 --> GRE/NAT --> IPv4 */
490206812b5SJesse Brandeburg 	I40E_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
491206812b5SJesse Brandeburg 	I40E_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
492206812b5SJesse Brandeburg 	I40E_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP,  PAY4),
493206812b5SJesse Brandeburg 	I40E_PTT_UNUSED_ENTRY(47),
494206812b5SJesse Brandeburg 	I40E_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP,  PAY4),
495206812b5SJesse Brandeburg 	I40E_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
496206812b5SJesse Brandeburg 	I40E_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
497206812b5SJesse Brandeburg 
498206812b5SJesse Brandeburg 	/* IPv4 --> GRE/NAT --> IPv6 */
499206812b5SJesse Brandeburg 	I40E_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
500206812b5SJesse Brandeburg 	I40E_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
501206812b5SJesse Brandeburg 	I40E_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP,  PAY4),
502206812b5SJesse Brandeburg 	I40E_PTT_UNUSED_ENTRY(54),
503206812b5SJesse Brandeburg 	I40E_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP,  PAY4),
504206812b5SJesse Brandeburg 	I40E_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
505206812b5SJesse Brandeburg 	I40E_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
506206812b5SJesse Brandeburg 
507206812b5SJesse Brandeburg 	/* IPv4 --> GRE/NAT --> MAC */
508206812b5SJesse Brandeburg 	I40E_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
509206812b5SJesse Brandeburg 
510206812b5SJesse Brandeburg 	/* IPv4 --> GRE/NAT --> MAC --> IPv4 */
511206812b5SJesse Brandeburg 	I40E_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
512206812b5SJesse Brandeburg 	I40E_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
513206812b5SJesse Brandeburg 	I40E_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP,  PAY4),
514206812b5SJesse Brandeburg 	I40E_PTT_UNUSED_ENTRY(62),
515206812b5SJesse Brandeburg 	I40E_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP,  PAY4),
516206812b5SJesse Brandeburg 	I40E_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
517206812b5SJesse Brandeburg 	I40E_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
518206812b5SJesse Brandeburg 
519206812b5SJesse Brandeburg 	/* IPv4 --> GRE/NAT -> MAC --> IPv6 */
520206812b5SJesse Brandeburg 	I40E_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
521206812b5SJesse Brandeburg 	I40E_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
522206812b5SJesse Brandeburg 	I40E_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP,  PAY4),
523206812b5SJesse Brandeburg 	I40E_PTT_UNUSED_ENTRY(69),
524206812b5SJesse Brandeburg 	I40E_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP,  PAY4),
525206812b5SJesse Brandeburg 	I40E_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
526206812b5SJesse Brandeburg 	I40E_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
527206812b5SJesse Brandeburg 
528206812b5SJesse Brandeburg 	/* IPv4 --> GRE/NAT --> MAC/VLAN */
529206812b5SJesse Brandeburg 	I40E_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
530206812b5SJesse Brandeburg 
531206812b5SJesse Brandeburg 	/* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
532206812b5SJesse Brandeburg 	I40E_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
533206812b5SJesse Brandeburg 	I40E_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
534206812b5SJesse Brandeburg 	I40E_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP,  PAY4),
535206812b5SJesse Brandeburg 	I40E_PTT_UNUSED_ENTRY(77),
536206812b5SJesse Brandeburg 	I40E_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP,  PAY4),
537206812b5SJesse Brandeburg 	I40E_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
538206812b5SJesse Brandeburg 	I40E_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
539206812b5SJesse Brandeburg 
540206812b5SJesse Brandeburg 	/* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
541206812b5SJesse Brandeburg 	I40E_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
542206812b5SJesse Brandeburg 	I40E_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
543206812b5SJesse Brandeburg 	I40E_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP,  PAY4),
544206812b5SJesse Brandeburg 	I40E_PTT_UNUSED_ENTRY(84),
545206812b5SJesse Brandeburg 	I40E_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP,  PAY4),
546206812b5SJesse Brandeburg 	I40E_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
547206812b5SJesse Brandeburg 	I40E_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
548206812b5SJesse Brandeburg 
549206812b5SJesse Brandeburg 	/* Non Tunneled IPv6 */
550206812b5SJesse Brandeburg 	I40E_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
551206812b5SJesse Brandeburg 	I40E_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
55273df8c9eSAkeem G Abodunrin 	I40E_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP,  PAY4),
553206812b5SJesse Brandeburg 	I40E_PTT_UNUSED_ENTRY(91),
554206812b5SJesse Brandeburg 	I40E_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP,  PAY4),
555206812b5SJesse Brandeburg 	I40E_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
556206812b5SJesse Brandeburg 	I40E_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
557206812b5SJesse Brandeburg 
558206812b5SJesse Brandeburg 	/* IPv6 --> IPv4 */
559206812b5SJesse Brandeburg 	I40E_PTT(95,  IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
560206812b5SJesse Brandeburg 	I40E_PTT(96,  IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
561206812b5SJesse Brandeburg 	I40E_PTT(97,  IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP,  PAY4),
562206812b5SJesse Brandeburg 	I40E_PTT_UNUSED_ENTRY(98),
563206812b5SJesse Brandeburg 	I40E_PTT(99,  IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP,  PAY4),
564206812b5SJesse Brandeburg 	I40E_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
565206812b5SJesse Brandeburg 	I40E_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
566206812b5SJesse Brandeburg 
567206812b5SJesse Brandeburg 	/* IPv6 --> IPv6 */
568206812b5SJesse Brandeburg 	I40E_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
569206812b5SJesse Brandeburg 	I40E_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
570206812b5SJesse Brandeburg 	I40E_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP,  PAY4),
571206812b5SJesse Brandeburg 	I40E_PTT_UNUSED_ENTRY(105),
572206812b5SJesse Brandeburg 	I40E_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP,  PAY4),
573206812b5SJesse Brandeburg 	I40E_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
574206812b5SJesse Brandeburg 	I40E_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
575206812b5SJesse Brandeburg 
576206812b5SJesse Brandeburg 	/* IPv6 --> GRE/NAT */
577206812b5SJesse Brandeburg 	I40E_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
578206812b5SJesse Brandeburg 
579206812b5SJesse Brandeburg 	/* IPv6 --> GRE/NAT -> IPv4 */
580206812b5SJesse Brandeburg 	I40E_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
581206812b5SJesse Brandeburg 	I40E_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
582206812b5SJesse Brandeburg 	I40E_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP,  PAY4),
583206812b5SJesse Brandeburg 	I40E_PTT_UNUSED_ENTRY(113),
584206812b5SJesse Brandeburg 	I40E_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP,  PAY4),
585206812b5SJesse Brandeburg 	I40E_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
586206812b5SJesse Brandeburg 	I40E_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
587206812b5SJesse Brandeburg 
588206812b5SJesse Brandeburg 	/* IPv6 --> GRE/NAT -> IPv6 */
589206812b5SJesse Brandeburg 	I40E_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
590206812b5SJesse Brandeburg 	I40E_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
591206812b5SJesse Brandeburg 	I40E_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP,  PAY4),
592206812b5SJesse Brandeburg 	I40E_PTT_UNUSED_ENTRY(120),
593206812b5SJesse Brandeburg 	I40E_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP,  PAY4),
594206812b5SJesse Brandeburg 	I40E_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
595206812b5SJesse Brandeburg 	I40E_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
596206812b5SJesse Brandeburg 
597206812b5SJesse Brandeburg 	/* IPv6 --> GRE/NAT -> MAC */
598206812b5SJesse Brandeburg 	I40E_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
599206812b5SJesse Brandeburg 
600206812b5SJesse Brandeburg 	/* IPv6 --> GRE/NAT -> MAC -> IPv4 */
601206812b5SJesse Brandeburg 	I40E_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
602206812b5SJesse Brandeburg 	I40E_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
603206812b5SJesse Brandeburg 	I40E_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP,  PAY4),
604206812b5SJesse Brandeburg 	I40E_PTT_UNUSED_ENTRY(128),
605206812b5SJesse Brandeburg 	I40E_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP,  PAY4),
606206812b5SJesse Brandeburg 	I40E_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
607206812b5SJesse Brandeburg 	I40E_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
608206812b5SJesse Brandeburg 
609206812b5SJesse Brandeburg 	/* IPv6 --> GRE/NAT -> MAC -> IPv6 */
610206812b5SJesse Brandeburg 	I40E_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
611206812b5SJesse Brandeburg 	I40E_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
612206812b5SJesse Brandeburg 	I40E_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP,  PAY4),
613206812b5SJesse Brandeburg 	I40E_PTT_UNUSED_ENTRY(135),
614206812b5SJesse Brandeburg 	I40E_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP,  PAY4),
615206812b5SJesse Brandeburg 	I40E_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
616206812b5SJesse Brandeburg 	I40E_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
617206812b5SJesse Brandeburg 
618206812b5SJesse Brandeburg 	/* IPv6 --> GRE/NAT -> MAC/VLAN */
619206812b5SJesse Brandeburg 	I40E_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
620206812b5SJesse Brandeburg 
621206812b5SJesse Brandeburg 	/* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
622206812b5SJesse Brandeburg 	I40E_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
623206812b5SJesse Brandeburg 	I40E_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
624206812b5SJesse Brandeburg 	I40E_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP,  PAY4),
625206812b5SJesse Brandeburg 	I40E_PTT_UNUSED_ENTRY(143),
626206812b5SJesse Brandeburg 	I40E_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP,  PAY4),
627206812b5SJesse Brandeburg 	I40E_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
628206812b5SJesse Brandeburg 	I40E_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
629206812b5SJesse Brandeburg 
630206812b5SJesse Brandeburg 	/* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
631206812b5SJesse Brandeburg 	I40E_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
632206812b5SJesse Brandeburg 	I40E_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
633206812b5SJesse Brandeburg 	I40E_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP,  PAY4),
634206812b5SJesse Brandeburg 	I40E_PTT_UNUSED_ENTRY(150),
635206812b5SJesse Brandeburg 	I40E_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP,  PAY4),
636206812b5SJesse Brandeburg 	I40E_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
637206812b5SJesse Brandeburg 	I40E_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
638206812b5SJesse Brandeburg 
639206812b5SJesse Brandeburg 	/* unused entries */
640c6e088bfSJesse Brandeburg 	[154 ... 255] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
641206812b5SJesse Brandeburg };
642206812b5SJesse Brandeburg 
643e1860d8fSAnjali Singhai Jain /**
64456a62fc8SJesse Brandeburg  * i40e_init_shared_code - Initialize the shared code
64556a62fc8SJesse Brandeburg  * @hw: pointer to hardware structure
64656a62fc8SJesse Brandeburg  *
64756a62fc8SJesse Brandeburg  * This assigns the MAC type and PHY code and inits the NVM.
64856a62fc8SJesse Brandeburg  * Does not touch the hardware. This function must be called prior to any
64956a62fc8SJesse Brandeburg  * other function in the shared code. The i40e_hw structure should be
65056a62fc8SJesse Brandeburg  * memset to 0 prior to calling this function.  The following fields in
65156a62fc8SJesse Brandeburg  * hw structure should be filled in prior to calling this function:
65256a62fc8SJesse Brandeburg  * hw_addr, back, device_id, vendor_id, subsystem_device_id,
65356a62fc8SJesse Brandeburg  * subsystem_vendor_id, and revision_id
65456a62fc8SJesse Brandeburg  **/
i40e_init_shared_code(struct i40e_hw * hw)6555180ff13SJan Sokolowski int i40e_init_shared_code(struct i40e_hw *hw)
65656a62fc8SJesse Brandeburg {
6575fb11d76SShannon Nelson 	u32 port, ari, func_rid;
6585180ff13SJan Sokolowski 	int status = 0;
65956a62fc8SJesse Brandeburg 
66056a62fc8SJesse Brandeburg 	i40e_set_mac_type(hw);
66156a62fc8SJesse Brandeburg 
66256a62fc8SJesse Brandeburg 	switch (hw->mac.type) {
66356a62fc8SJesse Brandeburg 	case I40E_MAC_XL710:
66487e6c1d7SAnjali Singhai Jain 	case I40E_MAC_X722:
66556a62fc8SJesse Brandeburg 		break;
66656a62fc8SJesse Brandeburg 	default:
667230f3d53SJan Sokolowski 		return -ENODEV;
66856a62fc8SJesse Brandeburg 	}
66956a62fc8SJesse Brandeburg 
670af89d26cSShannon Nelson 	hw->phy.get_link_info = true;
671af89d26cSShannon Nelson 
6725fb11d76SShannon Nelson 	/* Determine port number and PF number*/
6735fb11d76SShannon Nelson 	port = (rd32(hw, I40E_PFGEN_PORTNUM) & I40E_PFGEN_PORTNUM_PORT_NUM_MASK)
6745fb11d76SShannon Nelson 					   >> I40E_PFGEN_PORTNUM_PORT_NUM_SHIFT;
6755fb11d76SShannon Nelson 	hw->port = (u8)port;
6765fb11d76SShannon Nelson 	ari = (rd32(hw, I40E_GLPCI_CAPSUP) & I40E_GLPCI_CAPSUP_ARI_EN_MASK) >>
6775fb11d76SShannon Nelson 						 I40E_GLPCI_CAPSUP_ARI_EN_SHIFT;
6785fb11d76SShannon Nelson 	func_rid = rd32(hw, I40E_PF_FUNC_RID);
6795fb11d76SShannon Nelson 	if (ari)
6805fb11d76SShannon Nelson 		hw->pf_id = (u8)(func_rid & 0xff);
6815f9116acSShannon Nelson 	else
6825fb11d76SShannon Nelson 		hw->pf_id = (u8)(func_rid & 0x7);
6835f9116acSShannon Nelson 
68456a62fc8SJesse Brandeburg 	status = i40e_init_nvm(hw);
68556a62fc8SJesse Brandeburg 	return status;
68656a62fc8SJesse Brandeburg }
68756a62fc8SJesse Brandeburg 
68856a62fc8SJesse Brandeburg /**
68956a62fc8SJesse Brandeburg  * i40e_aq_mac_address_read - Retrieve the MAC addresses
69056a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
69156a62fc8SJesse Brandeburg  * @flags: a return indicator of what addresses were added to the addr store
69256a62fc8SJesse Brandeburg  * @addrs: the requestor's mac addr store
69356a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
69456a62fc8SJesse Brandeburg  **/
6955180ff13SJan Sokolowski static int
i40e_aq_mac_address_read(struct i40e_hw * hw,u16 * flags,struct i40e_aqc_mac_address_read_data * addrs,struct i40e_asq_cmd_details * cmd_details)6965180ff13SJan Sokolowski i40e_aq_mac_address_read(struct i40e_hw *hw,
69756a62fc8SJesse Brandeburg 			 u16 *flags,
69856a62fc8SJesse Brandeburg 			 struct i40e_aqc_mac_address_read_data *addrs,
69956a62fc8SJesse Brandeburg 			 struct i40e_asq_cmd_details *cmd_details)
70056a62fc8SJesse Brandeburg {
70156a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
70256a62fc8SJesse Brandeburg 	struct i40e_aqc_mac_address_read *cmd_data =
70356a62fc8SJesse Brandeburg 		(struct i40e_aqc_mac_address_read *)&desc.params.raw;
7045180ff13SJan Sokolowski 	int status;
70556a62fc8SJesse Brandeburg 
70656a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_mac_address_read);
70756a62fc8SJesse Brandeburg 	desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF);
70856a62fc8SJesse Brandeburg 
70956a62fc8SJesse Brandeburg 	status = i40e_asq_send_command(hw, &desc, addrs,
71056a62fc8SJesse Brandeburg 				       sizeof(*addrs), cmd_details);
71156a62fc8SJesse Brandeburg 	*flags = le16_to_cpu(cmd_data->command_flags);
71256a62fc8SJesse Brandeburg 
71356a62fc8SJesse Brandeburg 	return status;
71456a62fc8SJesse Brandeburg }
71556a62fc8SJesse Brandeburg 
71656a62fc8SJesse Brandeburg /**
71756a62fc8SJesse Brandeburg  * i40e_aq_mac_address_write - Change the MAC addresses
71856a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
71956a62fc8SJesse Brandeburg  * @flags: indicates which MAC to be written
72056a62fc8SJesse Brandeburg  * @mac_addr: address to write
72156a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
72256a62fc8SJesse Brandeburg  **/
i40e_aq_mac_address_write(struct i40e_hw * hw,u16 flags,u8 * mac_addr,struct i40e_asq_cmd_details * cmd_details)7235180ff13SJan Sokolowski int i40e_aq_mac_address_write(struct i40e_hw *hw,
72456a62fc8SJesse Brandeburg 			      u16 flags, u8 *mac_addr,
72556a62fc8SJesse Brandeburg 			      struct i40e_asq_cmd_details *cmd_details)
72656a62fc8SJesse Brandeburg {
72756a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
72856a62fc8SJesse Brandeburg 	struct i40e_aqc_mac_address_write *cmd_data =
72956a62fc8SJesse Brandeburg 		(struct i40e_aqc_mac_address_write *)&desc.params.raw;
7305180ff13SJan Sokolowski 	int status;
73156a62fc8SJesse Brandeburg 
73256a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc,
73356a62fc8SJesse Brandeburg 					  i40e_aqc_opc_mac_address_write);
73456a62fc8SJesse Brandeburg 	cmd_data->command_flags = cpu_to_le16(flags);
73555c29c31SKamil Krawczyk 	cmd_data->mac_sah = cpu_to_le16((u16)mac_addr[0] << 8 | mac_addr[1]);
73655c29c31SKamil Krawczyk 	cmd_data->mac_sal = cpu_to_le32(((u32)mac_addr[2] << 24) |
73755c29c31SKamil Krawczyk 					((u32)mac_addr[3] << 16) |
73855c29c31SKamil Krawczyk 					((u32)mac_addr[4] << 8) |
73955c29c31SKamil Krawczyk 					mac_addr[5]);
74056a62fc8SJesse Brandeburg 
74156a62fc8SJesse Brandeburg 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
74256a62fc8SJesse Brandeburg 
74356a62fc8SJesse Brandeburg 	return status;
74456a62fc8SJesse Brandeburg }
74556a62fc8SJesse Brandeburg 
74656a62fc8SJesse Brandeburg /**
74756a62fc8SJesse Brandeburg  * i40e_get_mac_addr - get MAC address
74856a62fc8SJesse Brandeburg  * @hw: pointer to the HW structure
74956a62fc8SJesse Brandeburg  * @mac_addr: pointer to MAC address
75056a62fc8SJesse Brandeburg  *
75156a62fc8SJesse Brandeburg  * Reads the adapter's MAC address from register
75256a62fc8SJesse Brandeburg  **/
i40e_get_mac_addr(struct i40e_hw * hw,u8 * mac_addr)7535180ff13SJan Sokolowski int i40e_get_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
75456a62fc8SJesse Brandeburg {
75556a62fc8SJesse Brandeburg 	struct i40e_aqc_mac_address_read_data addrs;
75656a62fc8SJesse Brandeburg 	u16 flags = 0;
7575180ff13SJan Sokolowski 	int status;
75856a62fc8SJesse Brandeburg 
75956a62fc8SJesse Brandeburg 	status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
76056a62fc8SJesse Brandeburg 
76156a62fc8SJesse Brandeburg 	if (flags & I40E_AQC_LAN_ADDR_VALID)
7626995b36cSJesse Brandeburg 		ether_addr_copy(mac_addr, addrs.pf_lan_mac);
76356a62fc8SJesse Brandeburg 
76456a62fc8SJesse Brandeburg 	return status;
76556a62fc8SJesse Brandeburg }
76656a62fc8SJesse Brandeburg 
76756a62fc8SJesse Brandeburg /**
7681f224ad2SNeerav Parikh  * i40e_get_port_mac_addr - get Port MAC address
7691f224ad2SNeerav Parikh  * @hw: pointer to the HW structure
7701f224ad2SNeerav Parikh  * @mac_addr: pointer to Port MAC address
7711f224ad2SNeerav Parikh  *
7721f224ad2SNeerav Parikh  * Reads the adapter's Port MAC address
7731f224ad2SNeerav Parikh  **/
i40e_get_port_mac_addr(struct i40e_hw * hw,u8 * mac_addr)7745180ff13SJan Sokolowski int i40e_get_port_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
7751f224ad2SNeerav Parikh {
7761f224ad2SNeerav Parikh 	struct i40e_aqc_mac_address_read_data addrs;
7771f224ad2SNeerav Parikh 	u16 flags = 0;
7785180ff13SJan Sokolowski 	int status;
7791f224ad2SNeerav Parikh 
7801f224ad2SNeerav Parikh 	status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
7811f224ad2SNeerav Parikh 	if (status)
7821f224ad2SNeerav Parikh 		return status;
7831f224ad2SNeerav Parikh 
7841f224ad2SNeerav Parikh 	if (flags & I40E_AQC_PORT_ADDR_VALID)
7856995b36cSJesse Brandeburg 		ether_addr_copy(mac_addr, addrs.port_mac);
7861f224ad2SNeerav Parikh 	else
787230f3d53SJan Sokolowski 		status = -EINVAL;
7881f224ad2SNeerav Parikh 
7891f224ad2SNeerav Parikh 	return status;
7901f224ad2SNeerav Parikh }
7911f224ad2SNeerav Parikh 
7921f224ad2SNeerav Parikh /**
793351499abSMatt Jared  * i40e_pre_tx_queue_cfg - pre tx queue configure
794351499abSMatt Jared  * @hw: pointer to the HW structure
795b40c82e6SJeff Kirsher  * @queue: target PF queue index
796351499abSMatt Jared  * @enable: state change request
797351499abSMatt Jared  *
798351499abSMatt Jared  * Handles hw requirement to indicate intention to enable
799351499abSMatt Jared  * or disable target queue.
800351499abSMatt Jared  **/
i40e_pre_tx_queue_cfg(struct i40e_hw * hw,u32 queue,bool enable)801351499abSMatt Jared void i40e_pre_tx_queue_cfg(struct i40e_hw *hw, u32 queue, bool enable)
802351499abSMatt Jared {
803dfb699f9SShannon Nelson 	u32 abs_queue_idx = hw->func_caps.base_queue + queue;
804351499abSMatt Jared 	u32 reg_block = 0;
805dfb699f9SShannon Nelson 	u32 reg_val;
806351499abSMatt Jared 
80724a768cfSChristopher Pau 	if (abs_queue_idx >= 128) {
808351499abSMatt Jared 		reg_block = abs_queue_idx / 128;
80924a768cfSChristopher Pau 		abs_queue_idx %= 128;
81024a768cfSChristopher Pau 	}
811351499abSMatt Jared 
812351499abSMatt Jared 	reg_val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
813351499abSMatt Jared 	reg_val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
814351499abSMatt Jared 	reg_val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
815351499abSMatt Jared 
816351499abSMatt Jared 	if (enable)
817351499abSMatt Jared 		reg_val |= I40E_GLLAN_TXPRE_QDIS_CLEAR_QDIS_MASK;
818351499abSMatt Jared 	else
819351499abSMatt Jared 		reg_val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
820351499abSMatt Jared 
821351499abSMatt Jared 	wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), reg_val);
822351499abSMatt Jared }
823351499abSMatt Jared 
824351499abSMatt Jared /**
82518f680c6SKamil Krawczyk  *  i40e_read_pba_string - Reads part number string from EEPROM
82618f680c6SKamil Krawczyk  *  @hw: pointer to hardware structure
82718f680c6SKamil Krawczyk  *  @pba_num: stores the part number string from the EEPROM
82818f680c6SKamil Krawczyk  *  @pba_num_size: part number string buffer length
82918f680c6SKamil Krawczyk  *
83018f680c6SKamil Krawczyk  *  Reads the part number string from the EEPROM.
83118f680c6SKamil Krawczyk  **/
i40e_read_pba_string(struct i40e_hw * hw,u8 * pba_num,u32 pba_num_size)8325180ff13SJan Sokolowski int i40e_read_pba_string(struct i40e_hw *hw, u8 *pba_num,
83318f680c6SKamil Krawczyk 			 u32 pba_num_size)
83418f680c6SKamil Krawczyk {
83518f680c6SKamil Krawczyk 	u16 pba_word = 0;
83618f680c6SKamil Krawczyk 	u16 pba_size = 0;
83718f680c6SKamil Krawczyk 	u16 pba_ptr = 0;
8385180ff13SJan Sokolowski 	int status = 0;
83918f680c6SKamil Krawczyk 	u16 i = 0;
84018f680c6SKamil Krawczyk 
84118f680c6SKamil Krawczyk 	status = i40e_read_nvm_word(hw, I40E_SR_PBA_FLAGS, &pba_word);
84218f680c6SKamil Krawczyk 	if (status || (pba_word != 0xFAFA)) {
84318f680c6SKamil Krawczyk 		hw_dbg(hw, "Failed to read PBA flags or flag is invalid.\n");
84418f680c6SKamil Krawczyk 		return status;
84518f680c6SKamil Krawczyk 	}
84618f680c6SKamil Krawczyk 
84718f680c6SKamil Krawczyk 	status = i40e_read_nvm_word(hw, I40E_SR_PBA_BLOCK_PTR, &pba_ptr);
84818f680c6SKamil Krawczyk 	if (status) {
84918f680c6SKamil Krawczyk 		hw_dbg(hw, "Failed to read PBA Block pointer.\n");
85018f680c6SKamil Krawczyk 		return status;
85118f680c6SKamil Krawczyk 	}
85218f680c6SKamil Krawczyk 
85318f680c6SKamil Krawczyk 	status = i40e_read_nvm_word(hw, pba_ptr, &pba_size);
85418f680c6SKamil Krawczyk 	if (status) {
85518f680c6SKamil Krawczyk 		hw_dbg(hw, "Failed to read PBA Block size.\n");
85618f680c6SKamil Krawczyk 		return status;
85718f680c6SKamil Krawczyk 	}
85818f680c6SKamil Krawczyk 
85918f680c6SKamil Krawczyk 	/* Subtract one to get PBA word count (PBA Size word is included in
86018f680c6SKamil Krawczyk 	 * total size)
86118f680c6SKamil Krawczyk 	 */
86218f680c6SKamil Krawczyk 	pba_size--;
86318f680c6SKamil Krawczyk 	if (pba_num_size < (((u32)pba_size * 2) + 1)) {
864959b1825SColin Ian King 		hw_dbg(hw, "Buffer too small for PBA data.\n");
865230f3d53SJan Sokolowski 		return -EINVAL;
86618f680c6SKamil Krawczyk 	}
86718f680c6SKamil Krawczyk 
86818f680c6SKamil Krawczyk 	for (i = 0; i < pba_size; i++) {
86918f680c6SKamil Krawczyk 		status = i40e_read_nvm_word(hw, (pba_ptr + 1) + i, &pba_word);
87018f680c6SKamil Krawczyk 		if (status) {
87118f680c6SKamil Krawczyk 			hw_dbg(hw, "Failed to read PBA Block word %d.\n", i);
87218f680c6SKamil Krawczyk 			return status;
87318f680c6SKamil Krawczyk 		}
87418f680c6SKamil Krawczyk 
87518f680c6SKamil Krawczyk 		pba_num[(i * 2)] = (pba_word >> 8) & 0xFF;
87618f680c6SKamil Krawczyk 		pba_num[(i * 2) + 1] = pba_word & 0xFF;
87718f680c6SKamil Krawczyk 	}
87818f680c6SKamil Krawczyk 	pba_num[(pba_size * 2)] = '\0';
87918f680c6SKamil Krawczyk 
88018f680c6SKamil Krawczyk 	return status;
88118f680c6SKamil Krawczyk }
88218f680c6SKamil Krawczyk 
88318f680c6SKamil Krawczyk /**
884be405eb0SJesse Brandeburg  * i40e_get_media_type - Gets media type
885be405eb0SJesse Brandeburg  * @hw: pointer to the hardware structure
886be405eb0SJesse Brandeburg  **/
i40e_get_media_type(struct i40e_hw * hw)887be405eb0SJesse Brandeburg static enum i40e_media_type i40e_get_media_type(struct i40e_hw *hw)
888be405eb0SJesse Brandeburg {
889be405eb0SJesse Brandeburg 	enum i40e_media_type media;
890be405eb0SJesse Brandeburg 
891be405eb0SJesse Brandeburg 	switch (hw->phy.link_info.phy_type) {
892be405eb0SJesse Brandeburg 	case I40E_PHY_TYPE_10GBASE_SR:
893be405eb0SJesse Brandeburg 	case I40E_PHY_TYPE_10GBASE_LR:
894124ed15bSCatherine Sullivan 	case I40E_PHY_TYPE_1000BASE_SX:
895124ed15bSCatherine Sullivan 	case I40E_PHY_TYPE_1000BASE_LX:
896be405eb0SJesse Brandeburg 	case I40E_PHY_TYPE_40GBASE_SR4:
897be405eb0SJesse Brandeburg 	case I40E_PHY_TYPE_40GBASE_LR4:
8983123237aSCarolyn Wyborny 	case I40E_PHY_TYPE_25GBASE_LR:
8993123237aSCarolyn Wyborny 	case I40E_PHY_TYPE_25GBASE_SR:
900be405eb0SJesse Brandeburg 		media = I40E_MEDIA_TYPE_FIBER;
901be405eb0SJesse Brandeburg 		break;
902be405eb0SJesse Brandeburg 	case I40E_PHY_TYPE_100BASE_TX:
903be405eb0SJesse Brandeburg 	case I40E_PHY_TYPE_1000BASE_T:
90415395ec4SMateusz Palczewski 	case I40E_PHY_TYPE_2_5GBASE_T_LINK_STATUS:
90515395ec4SMateusz Palczewski 	case I40E_PHY_TYPE_5GBASE_T_LINK_STATUS:
906be405eb0SJesse Brandeburg 	case I40E_PHY_TYPE_10GBASE_T:
907be405eb0SJesse Brandeburg 		media = I40E_MEDIA_TYPE_BASET;
908be405eb0SJesse Brandeburg 		break;
909be405eb0SJesse Brandeburg 	case I40E_PHY_TYPE_10GBASE_CR1_CU:
910be405eb0SJesse Brandeburg 	case I40E_PHY_TYPE_40GBASE_CR4_CU:
911be405eb0SJesse Brandeburg 	case I40E_PHY_TYPE_10GBASE_CR1:
912be405eb0SJesse Brandeburg 	case I40E_PHY_TYPE_40GBASE_CR4:
913be405eb0SJesse Brandeburg 	case I40E_PHY_TYPE_10GBASE_SFPP_CU:
914180204c7SCatherine Sullivan 	case I40E_PHY_TYPE_40GBASE_AOC:
915180204c7SCatherine Sullivan 	case I40E_PHY_TYPE_10GBASE_AOC:
9163123237aSCarolyn Wyborny 	case I40E_PHY_TYPE_25GBASE_CR:
917211b4c14SSudheer Mogilappagari 	case I40E_PHY_TYPE_25GBASE_AOC:
918211b4c14SSudheer Mogilappagari 	case I40E_PHY_TYPE_25GBASE_ACC:
919be405eb0SJesse Brandeburg 		media = I40E_MEDIA_TYPE_DA;
920be405eb0SJesse Brandeburg 		break;
921be405eb0SJesse Brandeburg 	case I40E_PHY_TYPE_1000BASE_KX:
922be405eb0SJesse Brandeburg 	case I40E_PHY_TYPE_10GBASE_KX4:
923be405eb0SJesse Brandeburg 	case I40E_PHY_TYPE_10GBASE_KR:
924be405eb0SJesse Brandeburg 	case I40E_PHY_TYPE_40GBASE_KR4:
925ae24b409SJesse Brandeburg 	case I40E_PHY_TYPE_20GBASE_KR2:
9263123237aSCarolyn Wyborny 	case I40E_PHY_TYPE_25GBASE_KR:
927be405eb0SJesse Brandeburg 		media = I40E_MEDIA_TYPE_BACKPLANE;
928be405eb0SJesse Brandeburg 		break;
929be405eb0SJesse Brandeburg 	case I40E_PHY_TYPE_SGMII:
930be405eb0SJesse Brandeburg 	case I40E_PHY_TYPE_XAUI:
931be405eb0SJesse Brandeburg 	case I40E_PHY_TYPE_XFI:
932be405eb0SJesse Brandeburg 	case I40E_PHY_TYPE_XLAUI:
933be405eb0SJesse Brandeburg 	case I40E_PHY_TYPE_XLPPI:
934be405eb0SJesse Brandeburg 	default:
935be405eb0SJesse Brandeburg 		media = I40E_MEDIA_TYPE_UNKNOWN;
936be405eb0SJesse Brandeburg 		break;
937be405eb0SJesse Brandeburg 	}
938be405eb0SJesse Brandeburg 
939be405eb0SJesse Brandeburg 	return media;
940be405eb0SJesse Brandeburg }
941be405eb0SJesse Brandeburg 
94212d80bcaSPaweł Jabłoński /**
94312d80bcaSPaweł Jabłoński  * i40e_poll_globr - Poll for Global Reset completion
94412d80bcaSPaweł Jabłoński  * @hw: pointer to the hardware structure
94512d80bcaSPaweł Jabłoński  * @retry_limit: how many times to retry before failure
94612d80bcaSPaweł Jabłoński  **/
i40e_poll_globr(struct i40e_hw * hw,u32 retry_limit)9475180ff13SJan Sokolowski static int i40e_poll_globr(struct i40e_hw *hw,
94812d80bcaSPaweł Jabłoński 			   u32 retry_limit)
94912d80bcaSPaweł Jabłoński {
95012d80bcaSPaweł Jabłoński 	u32 cnt, reg = 0;
95112d80bcaSPaweł Jabłoński 
95212d80bcaSPaweł Jabłoński 	for (cnt = 0; cnt < retry_limit; cnt++) {
95312d80bcaSPaweł Jabłoński 		reg = rd32(hw, I40E_GLGEN_RSTAT);
95412d80bcaSPaweł Jabłoński 		if (!(reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK))
95512d80bcaSPaweł Jabłoński 			return 0;
95612d80bcaSPaweł Jabłoński 		msleep(100);
95712d80bcaSPaweł Jabłoński 	}
95812d80bcaSPaweł Jabłoński 
95912d80bcaSPaweł Jabłoński 	hw_dbg(hw, "Global reset failed.\n");
96012d80bcaSPaweł Jabłoński 	hw_dbg(hw, "I40E_GLGEN_RSTAT = 0x%x\n", reg);
96112d80bcaSPaweł Jabłoński 
962230f3d53SJan Sokolowski 	return -EIO;
96312d80bcaSPaweł Jabłoński }
96412d80bcaSPaweł Jabłoński 
9657134f9ceSJesse Brandeburg #define I40E_PF_RESET_WAIT_COUNT_A0	200
9668af580dfSAkeem G Abodunrin #define I40E_PF_RESET_WAIT_COUNT	200
967be405eb0SJesse Brandeburg /**
96856a62fc8SJesse Brandeburg  * i40e_pf_reset - Reset the PF
96956a62fc8SJesse Brandeburg  * @hw: pointer to the hardware structure
97056a62fc8SJesse Brandeburg  *
97156a62fc8SJesse Brandeburg  * Assuming someone else has triggered a global reset,
97256a62fc8SJesse Brandeburg  * assure the global reset is complete and then reset the PF
97356a62fc8SJesse Brandeburg  **/
i40e_pf_reset(struct i40e_hw * hw)9745180ff13SJan Sokolowski int i40e_pf_reset(struct i40e_hw *hw)
97556a62fc8SJesse Brandeburg {
9767134f9ceSJesse Brandeburg 	u32 cnt = 0;
97742794bd8SShannon Nelson 	u32 cnt1 = 0;
97856a62fc8SJesse Brandeburg 	u32 reg = 0;
97956a62fc8SJesse Brandeburg 	u32 grst_del;
98056a62fc8SJesse Brandeburg 
98156a62fc8SJesse Brandeburg 	/* Poll for Global Reset steady state in case of recent GRST.
98256a62fc8SJesse Brandeburg 	 * The grst delay value is in 100ms units, and we'll wait a
98356a62fc8SJesse Brandeburg 	 * couple counts longer to be sure we don't just miss the end.
98456a62fc8SJesse Brandeburg 	 */
985de78fc5aSShannon Nelson 	grst_del = (rd32(hw, I40E_GLGEN_RSTCTL) &
986de78fc5aSShannon Nelson 		    I40E_GLGEN_RSTCTL_GRSTDEL_MASK) >>
987de78fc5aSShannon Nelson 		    I40E_GLGEN_RSTCTL_GRSTDEL_SHIFT;
9884d7cec07SKevin Scott 
9894d7cec07SKevin Scott 	/* It can take upto 15 secs for GRST steady state.
9904d7cec07SKevin Scott 	 * Bump it to 16 secs max to be safe.
9914d7cec07SKevin Scott 	 */
9924d7cec07SKevin Scott 	grst_del = grst_del * 20;
9934d7cec07SKevin Scott 
9944d7cec07SKevin Scott 	for (cnt = 0; cnt < grst_del; cnt++) {
99556a62fc8SJesse Brandeburg 		reg = rd32(hw, I40E_GLGEN_RSTAT);
99656a62fc8SJesse Brandeburg 		if (!(reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK))
99756a62fc8SJesse Brandeburg 			break;
99856a62fc8SJesse Brandeburg 		msleep(100);
99956a62fc8SJesse Brandeburg 	}
100056a62fc8SJesse Brandeburg 	if (reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
100156a62fc8SJesse Brandeburg 		hw_dbg(hw, "Global reset polling failed to complete.\n");
1002230f3d53SJan Sokolowski 		return -EIO;
100356a62fc8SJesse Brandeburg 	}
100456a62fc8SJesse Brandeburg 
100542794bd8SShannon Nelson 	/* Now Wait for the FW to be ready */
100642794bd8SShannon Nelson 	for (cnt1 = 0; cnt1 < I40E_PF_RESET_WAIT_COUNT; cnt1++) {
100742794bd8SShannon Nelson 		reg = rd32(hw, I40E_GLNVM_ULD);
100842794bd8SShannon Nelson 		reg &= (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
100942794bd8SShannon Nelson 			I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK);
101042794bd8SShannon Nelson 		if (reg == (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
101142794bd8SShannon Nelson 			    I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK)) {
101242794bd8SShannon Nelson 			hw_dbg(hw, "Core and Global modules ready %d\n", cnt1);
101342794bd8SShannon Nelson 			break;
101442794bd8SShannon Nelson 		}
101542794bd8SShannon Nelson 		usleep_range(10000, 20000);
101642794bd8SShannon Nelson 	}
101742794bd8SShannon Nelson 	if (!(reg & (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
101842794bd8SShannon Nelson 		     I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK))) {
101942794bd8SShannon Nelson 		hw_dbg(hw, "wait for FW Reset complete timedout\n");
102042794bd8SShannon Nelson 		hw_dbg(hw, "I40E_GLNVM_ULD = 0x%x\n", reg);
1021230f3d53SJan Sokolowski 		return -EIO;
102242794bd8SShannon Nelson 	}
102342794bd8SShannon Nelson 
102456a62fc8SJesse Brandeburg 	/* If there was a Global Reset in progress when we got here,
102556a62fc8SJesse Brandeburg 	 * we don't need to do the PF Reset
102656a62fc8SJesse Brandeburg 	 */
10277134f9ceSJesse Brandeburg 	if (!cnt) {
102894075bb1SFilip Sadowski 		u32 reg2 = 0;
10297134f9ceSJesse Brandeburg 		if (hw->revision_id == 0)
10307134f9ceSJesse Brandeburg 			cnt = I40E_PF_RESET_WAIT_COUNT_A0;
10317134f9ceSJesse Brandeburg 		else
10327134f9ceSJesse Brandeburg 			cnt = I40E_PF_RESET_WAIT_COUNT;
103356a62fc8SJesse Brandeburg 		reg = rd32(hw, I40E_PFGEN_CTRL);
103456a62fc8SJesse Brandeburg 		wr32(hw, I40E_PFGEN_CTRL,
103556a62fc8SJesse Brandeburg 		     (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
10367134f9ceSJesse Brandeburg 		for (; cnt; cnt--) {
103756a62fc8SJesse Brandeburg 			reg = rd32(hw, I40E_PFGEN_CTRL);
103856a62fc8SJesse Brandeburg 			if (!(reg & I40E_PFGEN_CTRL_PFSWR_MASK))
103956a62fc8SJesse Brandeburg 				break;
104094075bb1SFilip Sadowski 			reg2 = rd32(hw, I40E_GLGEN_RSTAT);
104112d80bcaSPaweł Jabłoński 			if (reg2 & I40E_GLGEN_RSTAT_DEVSTATE_MASK)
104212d80bcaSPaweł Jabłoński 				break;
104356a62fc8SJesse Brandeburg 			usleep_range(1000, 2000);
104456a62fc8SJesse Brandeburg 		}
104512d80bcaSPaweł Jabłoński 		if (reg2 & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
104612d80bcaSPaweł Jabłoński 			if (i40e_poll_globr(hw, grst_del))
1047230f3d53SJan Sokolowski 				return -EIO;
104812d80bcaSPaweł Jabłoński 		} else if (reg & I40E_PFGEN_CTRL_PFSWR_MASK) {
104956a62fc8SJesse Brandeburg 			hw_dbg(hw, "PF reset polling failed to complete.\n");
1050230f3d53SJan Sokolowski 			return -EIO;
105156a62fc8SJesse Brandeburg 		}
105256a62fc8SJesse Brandeburg 	}
105356a62fc8SJesse Brandeburg 
105456a62fc8SJesse Brandeburg 	i40e_clear_pxe_mode(hw);
1055922680b9SShannon Nelson 
105656a62fc8SJesse Brandeburg 	return 0;
105756a62fc8SJesse Brandeburg }
105856a62fc8SJesse Brandeburg 
105956a62fc8SJesse Brandeburg /**
1060838d41d9SShannon Nelson  * i40e_clear_hw - clear out any left over hw state
1061838d41d9SShannon Nelson  * @hw: pointer to the hw struct
1062838d41d9SShannon Nelson  *
1063838d41d9SShannon Nelson  * Clear queues and interrupts, typically called at init time,
1064838d41d9SShannon Nelson  * but after the capabilities have been found so we know how many
1065838d41d9SShannon Nelson  * queues and msix vectors have been allocated.
1066838d41d9SShannon Nelson  **/
i40e_clear_hw(struct i40e_hw * hw)1067838d41d9SShannon Nelson void i40e_clear_hw(struct i40e_hw *hw)
1068838d41d9SShannon Nelson {
1069838d41d9SShannon Nelson 	u32 num_queues, base_queue;
1070838d41d9SShannon Nelson 	u32 num_pf_int;
1071838d41d9SShannon Nelson 	u32 num_vf_int;
1072838d41d9SShannon Nelson 	u32 num_vfs;
1073838d41d9SShannon Nelson 	u32 i, j;
1074838d41d9SShannon Nelson 	u32 val;
1075838d41d9SShannon Nelson 	u32 eol = 0x7ff;
1076838d41d9SShannon Nelson 
1077b40c82e6SJeff Kirsher 	/* get number of interrupts, queues, and VFs */
1078838d41d9SShannon Nelson 	val = rd32(hw, I40E_GLPCI_CNF2);
1079838d41d9SShannon Nelson 	num_pf_int = (val & I40E_GLPCI_CNF2_MSI_X_PF_N_MASK) >>
1080838d41d9SShannon Nelson 		     I40E_GLPCI_CNF2_MSI_X_PF_N_SHIFT;
1081838d41d9SShannon Nelson 	num_vf_int = (val & I40E_GLPCI_CNF2_MSI_X_VF_N_MASK) >>
1082838d41d9SShannon Nelson 		     I40E_GLPCI_CNF2_MSI_X_VF_N_SHIFT;
1083838d41d9SShannon Nelson 
1084272cdaf2SShannon Nelson 	val = rd32(hw, I40E_PFLAN_QALLOC);
1085838d41d9SShannon Nelson 	base_queue = (val & I40E_PFLAN_QALLOC_FIRSTQ_MASK) >>
1086838d41d9SShannon Nelson 		     I40E_PFLAN_QALLOC_FIRSTQ_SHIFT;
1087838d41d9SShannon Nelson 	j = (val & I40E_PFLAN_QALLOC_LASTQ_MASK) >>
1088838d41d9SShannon Nelson 	    I40E_PFLAN_QALLOC_LASTQ_SHIFT;
1089fc6f716aSMichal Schmidt 	if (val & I40E_PFLAN_QALLOC_VALID_MASK && j >= base_queue)
1090838d41d9SShannon Nelson 		num_queues = (j - base_queue) + 1;
1091838d41d9SShannon Nelson 	else
1092838d41d9SShannon Nelson 		num_queues = 0;
1093838d41d9SShannon Nelson 
1094838d41d9SShannon Nelson 	val = rd32(hw, I40E_PF_VT_PFALLOC);
1095838d41d9SShannon Nelson 	i = (val & I40E_PF_VT_PFALLOC_FIRSTVF_MASK) >>
1096838d41d9SShannon Nelson 	    I40E_PF_VT_PFALLOC_FIRSTVF_SHIFT;
1097838d41d9SShannon Nelson 	j = (val & I40E_PF_VT_PFALLOC_LASTVF_MASK) >>
1098838d41d9SShannon Nelson 	    I40E_PF_VT_PFALLOC_LASTVF_SHIFT;
1099fc6f716aSMichal Schmidt 	if (val & I40E_PF_VT_PFALLOC_VALID_MASK && j >= i)
1100838d41d9SShannon Nelson 		num_vfs = (j - i) + 1;
1101838d41d9SShannon Nelson 	else
1102838d41d9SShannon Nelson 		num_vfs = 0;
1103838d41d9SShannon Nelson 
1104838d41d9SShannon Nelson 	/* stop all the interrupts */
1105838d41d9SShannon Nelson 	wr32(hw, I40E_PFINT_ICR0_ENA, 0);
1106838d41d9SShannon Nelson 	val = 0x3 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT;
1107838d41d9SShannon Nelson 	for (i = 0; i < num_pf_int - 2; i++)
1108838d41d9SShannon Nelson 		wr32(hw, I40E_PFINT_DYN_CTLN(i), val);
1109838d41d9SShannon Nelson 
1110838d41d9SShannon Nelson 	/* Set the FIRSTQ_INDX field to 0x7FF in PFINT_LNKLSTx */
1111838d41d9SShannon Nelson 	val = eol << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
1112838d41d9SShannon Nelson 	wr32(hw, I40E_PFINT_LNKLST0, val);
1113838d41d9SShannon Nelson 	for (i = 0; i < num_pf_int - 2; i++)
1114838d41d9SShannon Nelson 		wr32(hw, I40E_PFINT_LNKLSTN(i), val);
1115838d41d9SShannon Nelson 	val = eol << I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT;
1116838d41d9SShannon Nelson 	for (i = 0; i < num_vfs; i++)
1117838d41d9SShannon Nelson 		wr32(hw, I40E_VPINT_LNKLST0(i), val);
1118838d41d9SShannon Nelson 	for (i = 0; i < num_vf_int - 2; i++)
1119838d41d9SShannon Nelson 		wr32(hw, I40E_VPINT_LNKLSTN(i), val);
1120838d41d9SShannon Nelson 
1121838d41d9SShannon Nelson 	/* warn the HW of the coming Tx disables */
1122838d41d9SShannon Nelson 	for (i = 0; i < num_queues; i++) {
1123838d41d9SShannon Nelson 		u32 abs_queue_idx = base_queue + i;
1124838d41d9SShannon Nelson 		u32 reg_block = 0;
1125838d41d9SShannon Nelson 
1126838d41d9SShannon Nelson 		if (abs_queue_idx >= 128) {
1127838d41d9SShannon Nelson 			reg_block = abs_queue_idx / 128;
1128838d41d9SShannon Nelson 			abs_queue_idx %= 128;
1129838d41d9SShannon Nelson 		}
1130838d41d9SShannon Nelson 
1131838d41d9SShannon Nelson 		val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
1132838d41d9SShannon Nelson 		val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
1133838d41d9SShannon Nelson 		val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
1134838d41d9SShannon Nelson 		val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
1135838d41d9SShannon Nelson 
1136838d41d9SShannon Nelson 		wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), val);
1137838d41d9SShannon Nelson 	}
1138838d41d9SShannon Nelson 	udelay(400);
1139838d41d9SShannon Nelson 
1140838d41d9SShannon Nelson 	/* stop all the queues */
1141838d41d9SShannon Nelson 	for (i = 0; i < num_queues; i++) {
1142838d41d9SShannon Nelson 		wr32(hw, I40E_QINT_TQCTL(i), 0);
1143838d41d9SShannon Nelson 		wr32(hw, I40E_QTX_ENA(i), 0);
1144838d41d9SShannon Nelson 		wr32(hw, I40E_QINT_RQCTL(i), 0);
1145838d41d9SShannon Nelson 		wr32(hw, I40E_QRX_ENA(i), 0);
1146838d41d9SShannon Nelson 	}
1147838d41d9SShannon Nelson 
1148838d41d9SShannon Nelson 	/* short wait for all queue disables to settle */
1149838d41d9SShannon Nelson 	udelay(50);
1150838d41d9SShannon Nelson }
1151838d41d9SShannon Nelson 
1152838d41d9SShannon Nelson /**
115356a62fc8SJesse Brandeburg  * i40e_clear_pxe_mode - clear pxe operations mode
115456a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
115556a62fc8SJesse Brandeburg  *
115656a62fc8SJesse Brandeburg  * Make sure all PXE mode settings are cleared, including things
115756a62fc8SJesse Brandeburg  * like descriptor fetch/write-back mode.
115856a62fc8SJesse Brandeburg  **/
i40e_clear_pxe_mode(struct i40e_hw * hw)115956a62fc8SJesse Brandeburg void i40e_clear_pxe_mode(struct i40e_hw *hw)
116056a62fc8SJesse Brandeburg {
116156a62fc8SJesse Brandeburg 	u32 reg;
116256a62fc8SJesse Brandeburg 
1163c9b9b0aeSShannon Nelson 	if (i40e_check_asq_alive(hw))
1164c9b9b0aeSShannon Nelson 		i40e_aq_clear_pxe_mode(hw, NULL);
1165c9b9b0aeSShannon Nelson 
116656a62fc8SJesse Brandeburg 	/* Clear single descriptor fetch/write-back mode */
116756a62fc8SJesse Brandeburg 	reg = rd32(hw, I40E_GLLAN_RCTL_0);
11687134f9ceSJesse Brandeburg 
11697134f9ceSJesse Brandeburg 	if (hw->revision_id == 0) {
11707134f9ceSJesse Brandeburg 		/* As a work around clear PXE_MODE instead of setting it */
11717134f9ceSJesse Brandeburg 		wr32(hw, I40E_GLLAN_RCTL_0, (reg & (~I40E_GLLAN_RCTL_0_PXE_MODE_MASK)));
11727134f9ceSJesse Brandeburg 	} else {
117356a62fc8SJesse Brandeburg 		wr32(hw, I40E_GLLAN_RCTL_0, (reg | I40E_GLLAN_RCTL_0_PXE_MODE_MASK));
117456a62fc8SJesse Brandeburg 	}
11757134f9ceSJesse Brandeburg }
117656a62fc8SJesse Brandeburg 
117756a62fc8SJesse Brandeburg /**
11780556a9e3SJesse Brandeburg  * i40e_led_is_mine - helper to find matching led
11790556a9e3SJesse Brandeburg  * @hw: pointer to the hw struct
11800556a9e3SJesse Brandeburg  * @idx: index into GPIO registers
11810556a9e3SJesse Brandeburg  *
11820556a9e3SJesse Brandeburg  * returns: 0 if no match, otherwise the value of the GPIO_CTL register
11830556a9e3SJesse Brandeburg  */
i40e_led_is_mine(struct i40e_hw * hw,int idx)11840556a9e3SJesse Brandeburg static u32 i40e_led_is_mine(struct i40e_hw *hw, int idx)
11850556a9e3SJesse Brandeburg {
11860556a9e3SJesse Brandeburg 	u32 gpio_val = 0;
11870556a9e3SJesse Brandeburg 	u32 port;
11880556a9e3SJesse Brandeburg 
1189d80a476fSDamian Milosek 	if (!I40E_IS_X710TL_DEVICE(hw->device_id) &&
1190d80a476fSDamian Milosek 	    !hw->func_caps.led[idx])
11910556a9e3SJesse Brandeburg 		return 0;
11920556a9e3SJesse Brandeburg 	gpio_val = rd32(hw, I40E_GLGEN_GPIO_CTL(idx));
11930556a9e3SJesse Brandeburg 	port = (gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_MASK) >>
11940556a9e3SJesse Brandeburg 		I40E_GLGEN_GPIO_CTL_PRT_NUM_SHIFT;
11950556a9e3SJesse Brandeburg 
11960556a9e3SJesse Brandeburg 	/* if PRT_NUM_NA is 1 then this LED is not port specific, OR
11970556a9e3SJesse Brandeburg 	 * if it is not our port then ignore
11980556a9e3SJesse Brandeburg 	 */
11990556a9e3SJesse Brandeburg 	if ((gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_NA_MASK) ||
12000556a9e3SJesse Brandeburg 	    (port != hw->port))
12010556a9e3SJesse Brandeburg 		return 0;
12020556a9e3SJesse Brandeburg 
12030556a9e3SJesse Brandeburg 	return gpio_val;
12040556a9e3SJesse Brandeburg }
12050556a9e3SJesse Brandeburg 
1206d80a476fSDamian Milosek #define I40E_FW_LED BIT(4)
1207d80a476fSDamian Milosek #define I40E_LED_MODE_VALID (I40E_GLGEN_GPIO_CTL_LED_MODE_MASK >> \
1208d80a476fSDamian Milosek 			     I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT)
1209d80a476fSDamian Milosek 
1210b84d5cd8SMatt Jared #define I40E_LED0 22
12110556a9e3SJesse Brandeburg 
1212d80a476fSDamian Milosek #define I40E_PIN_FUNC_SDP 0x0
1213d80a476fSDamian Milosek #define I40E_PIN_FUNC_LED 0x1
1214d80a476fSDamian Milosek 
12150556a9e3SJesse Brandeburg /**
121656a62fc8SJesse Brandeburg  * i40e_led_get - return current on/off mode
121756a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
121856a62fc8SJesse Brandeburg  *
121956a62fc8SJesse Brandeburg  * The value returned is the 'mode' field as defined in the
122056a62fc8SJesse Brandeburg  * GPIO register definitions: 0x0 = off, 0xf = on, and other
122156a62fc8SJesse Brandeburg  * values are variations of possible behaviors relating to
122256a62fc8SJesse Brandeburg  * blink, link, and wire.
122356a62fc8SJesse Brandeburg  **/
i40e_led_get(struct i40e_hw * hw)122456a62fc8SJesse Brandeburg u32 i40e_led_get(struct i40e_hw *hw)
122556a62fc8SJesse Brandeburg {
122656a62fc8SJesse Brandeburg 	u32 mode = 0;
122756a62fc8SJesse Brandeburg 	int i;
122856a62fc8SJesse Brandeburg 
12290556a9e3SJesse Brandeburg 	/* as per the documentation GPIO 22-29 are the LED
12300556a9e3SJesse Brandeburg 	 * GPIO pins named LED0..LED7
12310556a9e3SJesse Brandeburg 	 */
12320556a9e3SJesse Brandeburg 	for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
12330556a9e3SJesse Brandeburg 		u32 gpio_val = i40e_led_is_mine(hw, i);
12340556a9e3SJesse Brandeburg 
12350556a9e3SJesse Brandeburg 		if (!gpio_val)
123656a62fc8SJesse Brandeburg 			continue;
123756a62fc8SJesse Brandeburg 
12380556a9e3SJesse Brandeburg 		mode = (gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK) >>
12390556a9e3SJesse Brandeburg 			I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT;
124056a62fc8SJesse Brandeburg 		break;
124156a62fc8SJesse Brandeburg 	}
124256a62fc8SJesse Brandeburg 
124356a62fc8SJesse Brandeburg 	return mode;
124456a62fc8SJesse Brandeburg }
124556a62fc8SJesse Brandeburg 
124656a62fc8SJesse Brandeburg /**
124756a62fc8SJesse Brandeburg  * i40e_led_set - set new on/off mode
124856a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
12490556a9e3SJesse Brandeburg  * @mode: 0=off, 0xf=on (else see manual for mode details)
12500556a9e3SJesse Brandeburg  * @blink: true if the LED should blink when on, false if steady
12510556a9e3SJesse Brandeburg  *
12520556a9e3SJesse Brandeburg  * if this function is used to turn on the blink it should
12530556a9e3SJesse Brandeburg  * be used to disable the blink when restoring the original state.
125456a62fc8SJesse Brandeburg  **/
i40e_led_set(struct i40e_hw * hw,u32 mode,bool blink)12550556a9e3SJesse Brandeburg void i40e_led_set(struct i40e_hw *hw, u32 mode, bool blink)
125656a62fc8SJesse Brandeburg {
125756a62fc8SJesse Brandeburg 	int i;
125856a62fc8SJesse Brandeburg 
1259d80a476fSDamian Milosek 	if (mode & ~I40E_LED_MODE_VALID) {
12600556a9e3SJesse Brandeburg 		hw_dbg(hw, "invalid mode passed in %X\n", mode);
1261d80a476fSDamian Milosek 		return;
1262d80a476fSDamian Milosek 	}
12630556a9e3SJesse Brandeburg 
12640556a9e3SJesse Brandeburg 	/* as per the documentation GPIO 22-29 are the LED
12650556a9e3SJesse Brandeburg 	 * GPIO pins named LED0..LED7
12660556a9e3SJesse Brandeburg 	 */
12670556a9e3SJesse Brandeburg 	for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
12680556a9e3SJesse Brandeburg 		u32 gpio_val = i40e_led_is_mine(hw, i);
12690556a9e3SJesse Brandeburg 
12700556a9e3SJesse Brandeburg 		if (!gpio_val)
127156a62fc8SJesse Brandeburg 			continue;
1272d80a476fSDamian Milosek 
1273d80a476fSDamian Milosek 		if (I40E_IS_X710TL_DEVICE(hw->device_id)) {
1274d80a476fSDamian Milosek 			u32 pin_func = 0;
1275d80a476fSDamian Milosek 
1276d80a476fSDamian Milosek 			if (mode & I40E_FW_LED)
1277d80a476fSDamian Milosek 				pin_func = I40E_PIN_FUNC_SDP;
1278d80a476fSDamian Milosek 			else
1279d80a476fSDamian Milosek 				pin_func = I40E_PIN_FUNC_LED;
1280d80a476fSDamian Milosek 
1281d80a476fSDamian Milosek 			gpio_val &= ~I40E_GLGEN_GPIO_CTL_PIN_FUNC_MASK;
1282d80a476fSDamian Milosek 			gpio_val |= ((pin_func <<
1283d80a476fSDamian Milosek 				     I40E_GLGEN_GPIO_CTL_PIN_FUNC_SHIFT) &
1284d80a476fSDamian Milosek 				     I40E_GLGEN_GPIO_CTL_PIN_FUNC_MASK);
1285d80a476fSDamian Milosek 		}
128656a62fc8SJesse Brandeburg 		gpio_val &= ~I40E_GLGEN_GPIO_CTL_LED_MODE_MASK;
12870556a9e3SJesse Brandeburg 		/* this & is a bit of paranoia, but serves as a range check */
12880556a9e3SJesse Brandeburg 		gpio_val |= ((mode << I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT) &
12890556a9e3SJesse Brandeburg 			     I40E_GLGEN_GPIO_CTL_LED_MODE_MASK);
12900556a9e3SJesse Brandeburg 
12919be00d67SMatt Jared 		if (blink)
129241a1d04bSJesse Brandeburg 			gpio_val |= BIT(I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
12939be00d67SMatt Jared 		else
129441a1d04bSJesse Brandeburg 			gpio_val &= ~BIT(I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
12950556a9e3SJesse Brandeburg 
129656a62fc8SJesse Brandeburg 		wr32(hw, I40E_GLGEN_GPIO_CTL(i), gpio_val);
12970556a9e3SJesse Brandeburg 		break;
129856a62fc8SJesse Brandeburg 	}
129956a62fc8SJesse Brandeburg }
130056a62fc8SJesse Brandeburg 
130156a62fc8SJesse Brandeburg /* Admin command wrappers */
130256a62fc8SJesse Brandeburg 
130356a62fc8SJesse Brandeburg /**
13048109e123SCatherine Sullivan  * i40e_aq_get_phy_capabilities
13058109e123SCatherine Sullivan  * @hw: pointer to the hw struct
13068109e123SCatherine Sullivan  * @abilities: structure for PHY capabilities to be filled
13078109e123SCatherine Sullivan  * @qualified_modules: report Qualified Modules
13088109e123SCatherine Sullivan  * @report_init: report init capabilities (active are default)
13098109e123SCatherine Sullivan  * @cmd_details: pointer to command details structure or NULL
13108109e123SCatherine Sullivan  *
13118109e123SCatherine Sullivan  * Returns the various PHY abilities supported on the Port.
13128109e123SCatherine Sullivan  **/
13135180ff13SJan Sokolowski int
i40e_aq_get_phy_capabilities(struct i40e_hw * hw,bool qualified_modules,bool report_init,struct i40e_aq_get_phy_abilities_resp * abilities,struct i40e_asq_cmd_details * cmd_details)13145180ff13SJan Sokolowski i40e_aq_get_phy_capabilities(struct i40e_hw *hw,
13158109e123SCatherine Sullivan 			     bool qualified_modules, bool report_init,
13168109e123SCatherine Sullivan 			     struct i40e_aq_get_phy_abilities_resp *abilities,
13178109e123SCatherine Sullivan 			     struct i40e_asq_cmd_details *cmd_details)
13188109e123SCatherine Sullivan {
13198109e123SCatherine Sullivan 	u16 abilities_size = sizeof(struct i40e_aq_get_phy_abilities_resp);
13204988410fSJayaprakash Shanmugam 	u16 max_delay = I40E_MAX_PHY_TIMEOUT, total_delay = 0;
13215180ff13SJan Sokolowski 	struct i40e_aq_desc desc;
13225180ff13SJan Sokolowski 	int status;
13238109e123SCatherine Sullivan 
13248109e123SCatherine Sullivan 	if (!abilities)
1325230f3d53SJan Sokolowski 		return -EINVAL;
13268109e123SCatherine Sullivan 
13274988410fSJayaprakash Shanmugam 	do {
13288109e123SCatherine Sullivan 		i40e_fill_default_direct_cmd_desc(&desc,
13298109e123SCatherine Sullivan 					       i40e_aqc_opc_get_phy_abilities);
13308109e123SCatherine Sullivan 
13318109e123SCatherine Sullivan 		desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
13328109e123SCatherine Sullivan 		if (abilities_size > I40E_AQ_LARGE_BUF)
13338109e123SCatherine Sullivan 			desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
13348109e123SCatherine Sullivan 
13358109e123SCatherine Sullivan 		if (qualified_modules)
13368109e123SCatherine Sullivan 			desc.params.external.param0 |=
13378109e123SCatherine Sullivan 			cpu_to_le32(I40E_AQ_PHY_REPORT_QUALIFIED_MODULES);
13388109e123SCatherine Sullivan 
13398109e123SCatherine Sullivan 		if (report_init)
13408109e123SCatherine Sullivan 			desc.params.external.param0 |=
13418109e123SCatherine Sullivan 			cpu_to_le32(I40E_AQ_PHY_REPORT_INITIAL_VALUES);
13428109e123SCatherine Sullivan 
13434988410fSJayaprakash Shanmugam 		status = i40e_asq_send_command(hw, &desc, abilities,
13444988410fSJayaprakash Shanmugam 					       abilities_size, cmd_details);
13458109e123SCatherine Sullivan 
13461b5f5d38SMarcin Formela 		switch (hw->aq.asq_last_status) {
13471b5f5d38SMarcin Formela 		case I40E_AQ_RC_EIO:
1348230f3d53SJan Sokolowski 			status = -EIO;
13494988410fSJayaprakash Shanmugam 			break;
13501b5f5d38SMarcin Formela 		case I40E_AQ_RC_EAGAIN:
13514988410fSJayaprakash Shanmugam 			usleep_range(1000, 2000);
13524988410fSJayaprakash Shanmugam 			total_delay++;
1353230f3d53SJan Sokolowski 			status = -EIO;
13541b5f5d38SMarcin Formela 			break;
13551b5f5d38SMarcin Formela 		/* also covers I40E_AQ_RC_OK */
13561b5f5d38SMarcin Formela 		default:
13571b5f5d38SMarcin Formela 			break;
13584988410fSJayaprakash Shanmugam 		}
13591b5f5d38SMarcin Formela 
13601b5f5d38SMarcin Formela 	} while ((hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN) &&
13614988410fSJayaprakash Shanmugam 		(total_delay < max_delay));
13624988410fSJayaprakash Shanmugam 
13634988410fSJayaprakash Shanmugam 	if (status)
13644988410fSJayaprakash Shanmugam 		return status;
13658109e123SCatherine Sullivan 
13663123237aSCarolyn Wyborny 	if (report_init) {
136722b96551SMitch Williams 		if (hw->mac.type ==  I40E_MAC_XL710 &&
136822b96551SMitch Williams 		    hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
13698fdb69ddSAlan Brady 		    hw->aq.api_min_ver >= I40E_MINOR_VER_GET_LINK_INFO_XL710) {
137022b96551SMitch Williams 			status = i40e_aq_get_link_info(hw, true, NULL, NULL);
13718fdb69ddSAlan Brady 		} else {
13728fdb69ddSAlan Brady 			hw->phy.phy_types = le32_to_cpu(abilities->phy_type);
13738fdb69ddSAlan Brady 			hw->phy.phy_types |=
13748fdb69ddSAlan Brady 					((u64)abilities->phy_type_ext << 32);
13758fdb69ddSAlan Brady 		}
13763123237aSCarolyn Wyborny 	}
13773ac67d7bSKevin Scott 
13788109e123SCatherine Sullivan 	return status;
13798109e123SCatherine Sullivan }
13808109e123SCatherine Sullivan 
13818109e123SCatherine Sullivan /**
1382c56999f9SCatherine Sullivan  * i40e_aq_set_phy_config
1383c56999f9SCatherine Sullivan  * @hw: pointer to the hw struct
1384c56999f9SCatherine Sullivan  * @config: structure with PHY configuration to be set
1385c56999f9SCatherine Sullivan  * @cmd_details: pointer to command details structure or NULL
1386c56999f9SCatherine Sullivan  *
1387c56999f9SCatherine Sullivan  * Set the various PHY configuration parameters
1388c56999f9SCatherine Sullivan  * supported on the Port.One or more of the Set PHY config parameters may be
1389c56999f9SCatherine Sullivan  * ignored in an MFP mode as the PF may not have the privilege to set some
1390c56999f9SCatherine Sullivan  * of the PHY Config parameters. This status will be indicated by the
1391c56999f9SCatherine Sullivan  * command response.
1392c56999f9SCatherine Sullivan  **/
i40e_aq_set_phy_config(struct i40e_hw * hw,struct i40e_aq_set_phy_config * config,struct i40e_asq_cmd_details * cmd_details)13935180ff13SJan Sokolowski int i40e_aq_set_phy_config(struct i40e_hw *hw,
1394c56999f9SCatherine Sullivan 			   struct i40e_aq_set_phy_config *config,
1395c56999f9SCatherine Sullivan 			   struct i40e_asq_cmd_details *cmd_details)
1396c56999f9SCatherine Sullivan {
1397c56999f9SCatherine Sullivan 	struct i40e_aq_desc desc;
1398c56999f9SCatherine Sullivan 	struct i40e_aq_set_phy_config *cmd =
1399c56999f9SCatherine Sullivan 			(struct i40e_aq_set_phy_config *)&desc.params.raw;
14005180ff13SJan Sokolowski 	int status;
1401c56999f9SCatherine Sullivan 
1402c56999f9SCatherine Sullivan 	if (!config)
1403230f3d53SJan Sokolowski 		return -EINVAL;
1404c56999f9SCatherine Sullivan 
1405c56999f9SCatherine Sullivan 	i40e_fill_default_direct_cmd_desc(&desc,
1406c56999f9SCatherine Sullivan 					  i40e_aqc_opc_set_phy_config);
1407c56999f9SCatherine Sullivan 
1408c56999f9SCatherine Sullivan 	*cmd = *config;
1409c56999f9SCatherine Sullivan 
1410c56999f9SCatherine Sullivan 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1411c56999f9SCatherine Sullivan 
1412c56999f9SCatherine Sullivan 	return status;
1413c56999f9SCatherine Sullivan }
1414c56999f9SCatherine Sullivan 
14155180ff13SJan Sokolowski static noinline_for_stack int
i40e_set_fc_status(struct i40e_hw * hw,struct i40e_aq_get_phy_abilities_resp * abilities,bool atomic_restart)141633b16568SArnd Bergmann i40e_set_fc_status(struct i40e_hw *hw,
141733b16568SArnd Bergmann 		   struct i40e_aq_get_phy_abilities_resp *abilities,
1418c56999f9SCatherine Sullivan 		   bool atomic_restart)
1419c56999f9SCatherine Sullivan {
1420c56999f9SCatherine Sullivan 	struct i40e_aq_set_phy_config config;
142133b16568SArnd Bergmann 	enum i40e_fc_mode fc_mode = hw->fc.requested_mode;
1422c56999f9SCatherine Sullivan 	u8 pause_mask = 0x0;
1423c56999f9SCatherine Sullivan 
1424c56999f9SCatherine Sullivan 	switch (fc_mode) {
1425c56999f9SCatherine Sullivan 	case I40E_FC_FULL:
1426c56999f9SCatherine Sullivan 		pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
1427c56999f9SCatherine Sullivan 		pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
1428c56999f9SCatherine Sullivan 		break;
1429c56999f9SCatherine Sullivan 	case I40E_FC_RX_PAUSE:
1430c56999f9SCatherine Sullivan 		pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
1431c56999f9SCatherine Sullivan 		break;
1432c56999f9SCatherine Sullivan 	case I40E_FC_TX_PAUSE:
1433c56999f9SCatherine Sullivan 		pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
1434c56999f9SCatherine Sullivan 		break;
1435c56999f9SCatherine Sullivan 	default:
1436c56999f9SCatherine Sullivan 		break;
1437c56999f9SCatherine Sullivan 	}
1438c56999f9SCatherine Sullivan 
143933b16568SArnd Bergmann 	memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
144033b16568SArnd Bergmann 	/* clear the old pause settings */
144133b16568SArnd Bergmann 	config.abilities = abilities->abilities & ~(I40E_AQ_PHY_FLAG_PAUSE_TX) &
144233b16568SArnd Bergmann 			   ~(I40E_AQ_PHY_FLAG_PAUSE_RX);
144333b16568SArnd Bergmann 	/* set the new abilities */
144433b16568SArnd Bergmann 	config.abilities |= pause_mask;
144533b16568SArnd Bergmann 	/* If the abilities have changed, then set the new config */
144633b16568SArnd Bergmann 	if (config.abilities == abilities->abilities)
144733b16568SArnd Bergmann 		return 0;
144833b16568SArnd Bergmann 
144933b16568SArnd Bergmann 	/* Auto restart link so settings take effect */
145033b16568SArnd Bergmann 	if (atomic_restart)
145133b16568SArnd Bergmann 		config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
145233b16568SArnd Bergmann 	/* Copy over all the old settings */
145333b16568SArnd Bergmann 	config.phy_type = abilities->phy_type;
145433b16568SArnd Bergmann 	config.phy_type_ext = abilities->phy_type_ext;
145533b16568SArnd Bergmann 	config.link_speed = abilities->link_speed;
145633b16568SArnd Bergmann 	config.eee_capability = abilities->eee_capability;
145733b16568SArnd Bergmann 	config.eeer = abilities->eeer_val;
145833b16568SArnd Bergmann 	config.low_power_ctrl = abilities->d3_lpan;
145933b16568SArnd Bergmann 	config.fec_config = abilities->fec_cfg_curr_mod_ext_info &
146033b16568SArnd Bergmann 			    I40E_AQ_PHY_FEC_CONFIG_MASK;
146133b16568SArnd Bergmann 
146233b16568SArnd Bergmann 	return i40e_aq_set_phy_config(hw, &config, NULL);
146333b16568SArnd Bergmann }
146433b16568SArnd Bergmann 
146533b16568SArnd Bergmann /**
146633b16568SArnd Bergmann  * i40e_set_fc
146733b16568SArnd Bergmann  * @hw: pointer to the hw struct
146833b16568SArnd Bergmann  * @aq_failures: buffer to return AdminQ failure information
146933b16568SArnd Bergmann  * @atomic_restart: whether to enable atomic link restart
147033b16568SArnd Bergmann  *
147133b16568SArnd Bergmann  * Set the requested flow control mode using set_phy_config.
147233b16568SArnd Bergmann  **/
i40e_set_fc(struct i40e_hw * hw,u8 * aq_failures,bool atomic_restart)14735180ff13SJan Sokolowski int i40e_set_fc(struct i40e_hw *hw, u8 *aq_failures,
147433b16568SArnd Bergmann 		bool atomic_restart)
147533b16568SArnd Bergmann {
147633b16568SArnd Bergmann 	struct i40e_aq_get_phy_abilities_resp abilities;
14775180ff13SJan Sokolowski 	int status;
147833b16568SArnd Bergmann 
147933b16568SArnd Bergmann 	*aq_failures = 0x0;
148033b16568SArnd Bergmann 
1481c56999f9SCatherine Sullivan 	/* Get the current phy config */
1482c56999f9SCatherine Sullivan 	status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
1483c56999f9SCatherine Sullivan 					      NULL);
1484c56999f9SCatherine Sullivan 	if (status) {
1485c56999f9SCatherine Sullivan 		*aq_failures |= I40E_SET_FC_AQ_FAIL_GET;
1486c56999f9SCatherine Sullivan 		return status;
1487c56999f9SCatherine Sullivan 	}
1488c56999f9SCatherine Sullivan 
148933b16568SArnd Bergmann 	status = i40e_set_fc_status(hw, &abilities, atomic_restart);
1490c56999f9SCatherine Sullivan 	if (status)
1491c56999f9SCatherine Sullivan 		*aq_failures |= I40E_SET_FC_AQ_FAIL_SET;
149233b16568SArnd Bergmann 
1493c56999f9SCatherine Sullivan 	/* Update the link info */
14940a862b43SCatherine Sullivan 	status = i40e_update_link_info(hw);
1495c56999f9SCatherine Sullivan 	if (status) {
1496c56999f9SCatherine Sullivan 		/* Wait a little bit (on 40G cards it sometimes takes a really
1497c56999f9SCatherine Sullivan 		 * long time for link to come back from the atomic reset)
1498c56999f9SCatherine Sullivan 		 * and try once more
1499c56999f9SCatherine Sullivan 		 */
1500c56999f9SCatherine Sullivan 		msleep(1000);
15010a862b43SCatherine Sullivan 		status = i40e_update_link_info(hw);
1502c56999f9SCatherine Sullivan 	}
1503c56999f9SCatherine Sullivan 	if (status)
1504c56999f9SCatherine Sullivan 		*aq_failures |= I40E_SET_FC_AQ_FAIL_UPDATE;
1505c56999f9SCatherine Sullivan 
1506c56999f9SCatherine Sullivan 	return status;
1507c56999f9SCatherine Sullivan }
1508c56999f9SCatherine Sullivan 
1509c56999f9SCatherine Sullivan /**
1510c9b9b0aeSShannon Nelson  * i40e_aq_clear_pxe_mode
1511c9b9b0aeSShannon Nelson  * @hw: pointer to the hw struct
1512c9b9b0aeSShannon Nelson  * @cmd_details: pointer to command details structure or NULL
1513c9b9b0aeSShannon Nelson  *
1514c9b9b0aeSShannon Nelson  * Tell the firmware that the driver is taking over from PXE
1515c9b9b0aeSShannon Nelson  **/
i40e_aq_clear_pxe_mode(struct i40e_hw * hw,struct i40e_asq_cmd_details * cmd_details)15165180ff13SJan Sokolowski int i40e_aq_clear_pxe_mode(struct i40e_hw *hw,
1517c9b9b0aeSShannon Nelson 			   struct i40e_asq_cmd_details *cmd_details)
1518c9b9b0aeSShannon Nelson {
1519c9b9b0aeSShannon Nelson 	struct i40e_aq_desc desc;
1520c9b9b0aeSShannon Nelson 	struct i40e_aqc_clear_pxe *cmd =
1521c9b9b0aeSShannon Nelson 		(struct i40e_aqc_clear_pxe *)&desc.params.raw;
15225180ff13SJan Sokolowski 	int status;
1523c9b9b0aeSShannon Nelson 
1524c9b9b0aeSShannon Nelson 	i40e_fill_default_direct_cmd_desc(&desc,
1525c9b9b0aeSShannon Nelson 					  i40e_aqc_opc_clear_pxe_mode);
1526c9b9b0aeSShannon Nelson 
1527c9b9b0aeSShannon Nelson 	cmd->rx_cnt = 0x2;
1528c9b9b0aeSShannon Nelson 
1529c9b9b0aeSShannon Nelson 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1530c9b9b0aeSShannon Nelson 
1531c9b9b0aeSShannon Nelson 	wr32(hw, I40E_GLLAN_RCTL_0, 0x1);
1532c9b9b0aeSShannon Nelson 
1533c9b9b0aeSShannon Nelson 	return status;
1534c9b9b0aeSShannon Nelson }
1535c9b9b0aeSShannon Nelson 
1536c9b9b0aeSShannon Nelson /**
153756a62fc8SJesse Brandeburg  * i40e_aq_set_link_restart_an
153856a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
15391ac978afSCatherine Sullivan  * @enable_link: if true: enable link, if false: disable link
154056a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
154156a62fc8SJesse Brandeburg  *
154256a62fc8SJesse Brandeburg  * Sets up the link and restarts the Auto-Negotiation over the link.
154356a62fc8SJesse Brandeburg  **/
i40e_aq_set_link_restart_an(struct i40e_hw * hw,bool enable_link,struct i40e_asq_cmd_details * cmd_details)15445180ff13SJan Sokolowski int i40e_aq_set_link_restart_an(struct i40e_hw *hw,
15451ac978afSCatherine Sullivan 				bool enable_link,
154656a62fc8SJesse Brandeburg 				struct i40e_asq_cmd_details *cmd_details)
154756a62fc8SJesse Brandeburg {
154856a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
154956a62fc8SJesse Brandeburg 	struct i40e_aqc_set_link_restart_an *cmd =
155056a62fc8SJesse Brandeburg 		(struct i40e_aqc_set_link_restart_an *)&desc.params.raw;
15515180ff13SJan Sokolowski 	int status;
155256a62fc8SJesse Brandeburg 
155356a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc,
155456a62fc8SJesse Brandeburg 					  i40e_aqc_opc_set_link_restart_an);
155556a62fc8SJesse Brandeburg 
155656a62fc8SJesse Brandeburg 	cmd->command = I40E_AQ_PHY_RESTART_AN;
15571ac978afSCatherine Sullivan 	if (enable_link)
15581ac978afSCatherine Sullivan 		cmd->command |= I40E_AQ_PHY_LINK_ENABLE;
15591ac978afSCatherine Sullivan 	else
15601ac978afSCatherine Sullivan 		cmd->command &= ~I40E_AQ_PHY_LINK_ENABLE;
156156a62fc8SJesse Brandeburg 
156256a62fc8SJesse Brandeburg 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
156356a62fc8SJesse Brandeburg 
156456a62fc8SJesse Brandeburg 	return status;
156556a62fc8SJesse Brandeburg }
156656a62fc8SJesse Brandeburg 
156756a62fc8SJesse Brandeburg /**
156856a62fc8SJesse Brandeburg  * i40e_aq_get_link_info
156956a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
157056a62fc8SJesse Brandeburg  * @enable_lse: enable/disable LinkStatusEvent reporting
157156a62fc8SJesse Brandeburg  * @link: pointer to link status structure - optional
157256a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
157356a62fc8SJesse Brandeburg  *
157456a62fc8SJesse Brandeburg  * Returns the link status of the adapter.
157556a62fc8SJesse Brandeburg  **/
i40e_aq_get_link_info(struct i40e_hw * hw,bool enable_lse,struct i40e_link_status * link,struct i40e_asq_cmd_details * cmd_details)15765180ff13SJan Sokolowski int i40e_aq_get_link_info(struct i40e_hw *hw,
157756a62fc8SJesse Brandeburg 			  bool enable_lse, struct i40e_link_status *link,
157856a62fc8SJesse Brandeburg 			  struct i40e_asq_cmd_details *cmd_details)
157956a62fc8SJesse Brandeburg {
158056a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
158156a62fc8SJesse Brandeburg 	struct i40e_aqc_get_link_status *resp =
158256a62fc8SJesse Brandeburg 		(struct i40e_aqc_get_link_status *)&desc.params.raw;
158356a62fc8SJesse Brandeburg 	struct i40e_link_status *hw_link_info = &hw->phy.link_info;
1584c56999f9SCatherine Sullivan 	bool tx_pause, rx_pause;
158556a62fc8SJesse Brandeburg 	u16 command_flags;
15865180ff13SJan Sokolowski 	int status;
158756a62fc8SJesse Brandeburg 
158856a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_link_status);
158956a62fc8SJesse Brandeburg 
159056a62fc8SJesse Brandeburg 	if (enable_lse)
159156a62fc8SJesse Brandeburg 		command_flags = I40E_AQ_LSE_ENABLE;
159256a62fc8SJesse Brandeburg 	else
159356a62fc8SJesse Brandeburg 		command_flags = I40E_AQ_LSE_DISABLE;
159456a62fc8SJesse Brandeburg 	resp->command_flags = cpu_to_le16(command_flags);
159556a62fc8SJesse Brandeburg 
159656a62fc8SJesse Brandeburg 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
159756a62fc8SJesse Brandeburg 
159856a62fc8SJesse Brandeburg 	if (status)
159956a62fc8SJesse Brandeburg 		goto aq_get_link_info_exit;
160056a62fc8SJesse Brandeburg 
160156a62fc8SJesse Brandeburg 	/* save off old link status information */
1602c36bd4a7SMitch Williams 	hw->phy.link_info_old = *hw_link_info;
160356a62fc8SJesse Brandeburg 
160456a62fc8SJesse Brandeburg 	/* update link status */
160556a62fc8SJesse Brandeburg 	hw_link_info->phy_type = (enum i40e_aq_phy_type)resp->phy_type;
1606be405eb0SJesse Brandeburg 	hw->phy.media_type = i40e_get_media_type(hw);
160756a62fc8SJesse Brandeburg 	hw_link_info->link_speed = (enum i40e_aq_link_speed)resp->link_speed;
160856a62fc8SJesse Brandeburg 	hw_link_info->link_info = resp->link_info;
160956a62fc8SJesse Brandeburg 	hw_link_info->an_info = resp->an_info;
16103e03d7ccSHenry Tieman 	hw_link_info->fec_info = resp->config & (I40E_AQ_CONFIG_FEC_KR_ENA |
16113e03d7ccSHenry Tieman 						 I40E_AQ_CONFIG_FEC_RS_ENA);
161256a62fc8SJesse Brandeburg 	hw_link_info->ext_info = resp->ext_info;
1613d60bcc79SFilip Sadowski 	hw_link_info->loopback = resp->loopback & I40E_AQ_LOOPBACK_MASK;
16146bb3f23cSNeerav Parikh 	hw_link_info->max_frame_size = le16_to_cpu(resp->max_frame_size);
16156bb3f23cSNeerav Parikh 	hw_link_info->pacing = resp->config & I40E_AQ_CONFIG_PACING_MASK;
16166bb3f23cSNeerav Parikh 
1617c56999f9SCatherine Sullivan 	/* update fc info */
1618c56999f9SCatherine Sullivan 	tx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_TX);
1619c56999f9SCatherine Sullivan 	rx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_RX);
1620c56999f9SCatherine Sullivan 	if (tx_pause & rx_pause)
1621c56999f9SCatherine Sullivan 		hw->fc.current_mode = I40E_FC_FULL;
1622c56999f9SCatherine Sullivan 	else if (tx_pause)
1623c56999f9SCatherine Sullivan 		hw->fc.current_mode = I40E_FC_TX_PAUSE;
1624c56999f9SCatherine Sullivan 	else if (rx_pause)
1625c56999f9SCatherine Sullivan 		hw->fc.current_mode = I40E_FC_RX_PAUSE;
1626c56999f9SCatherine Sullivan 	else
1627c56999f9SCatherine Sullivan 		hw->fc.current_mode = I40E_FC_NONE;
1628c56999f9SCatherine Sullivan 
16296bb3f23cSNeerav Parikh 	if (resp->config & I40E_AQ_CONFIG_CRC_ENA)
16306bb3f23cSNeerav Parikh 		hw_link_info->crc_enable = true;
16316bb3f23cSNeerav Parikh 	else
16326bb3f23cSNeerav Parikh 		hw_link_info->crc_enable = false;
163356a62fc8SJesse Brandeburg 
16347ed35732SFilip Sadowski 	if (resp->command_flags & cpu_to_le16(I40E_AQ_LSE_IS_ENABLED))
163556a62fc8SJesse Brandeburg 		hw_link_info->lse_enable = true;
163656a62fc8SJesse Brandeburg 	else
163756a62fc8SJesse Brandeburg 		hw_link_info->lse_enable = false;
163856a62fc8SJesse Brandeburg 
1639e586bb66SHenry Tieman 	if ((hw->mac.type == I40E_MAC_XL710) &&
1640e586bb66SHenry Tieman 	    (hw->aq.fw_maj_ver < 4 || (hw->aq.fw_maj_ver == 4 &&
1641088c4ee3SCatherine Sullivan 	     hw->aq.fw_min_ver < 40)) && hw_link_info->phy_type == 0xE)
1642088c4ee3SCatherine Sullivan 		hw_link_info->phy_type = I40E_PHY_TYPE_10GBASE_SFPP_CU;
1643088c4ee3SCatherine Sullivan 
16444c9da6f2SArkadiusz Kubalewski 	if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE &&
16454c9da6f2SArkadiusz Kubalewski 	    hw->mac.type != I40E_MAC_X722) {
1646d60bcc79SFilip Sadowski 		__le32 tmp;
1647d60bcc79SFilip Sadowski 
1648d60bcc79SFilip Sadowski 		memcpy(&tmp, resp->link_type, sizeof(tmp));
1649d60bcc79SFilip Sadowski 		hw->phy.phy_types = le32_to_cpu(tmp);
1650d60bcc79SFilip Sadowski 		hw->phy.phy_types |= ((u64)resp->link_type_ext << 32);
1651d60bcc79SFilip Sadowski 	}
1652d60bcc79SFilip Sadowski 
165356a62fc8SJesse Brandeburg 	/* save link status information */
165456a62fc8SJesse Brandeburg 	if (link)
1655d7595a22SJesse Brandeburg 		*link = *hw_link_info;
165656a62fc8SJesse Brandeburg 
165756a62fc8SJesse Brandeburg 	/* flag cleared so helper functions don't call AQ again */
165856a62fc8SJesse Brandeburg 	hw->phy.get_link_info = false;
165956a62fc8SJesse Brandeburg 
166056a62fc8SJesse Brandeburg aq_get_link_info_exit:
166156a62fc8SJesse Brandeburg 	return status;
166256a62fc8SJesse Brandeburg }
166356a62fc8SJesse Brandeburg 
166456a62fc8SJesse Brandeburg /**
16657e2453feSJesse Brandeburg  * i40e_aq_set_phy_int_mask
16667e2453feSJesse Brandeburg  * @hw: pointer to the hw struct
16677e2453feSJesse Brandeburg  * @mask: interrupt mask to be set
16687e2453feSJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
16697e2453feSJesse Brandeburg  *
16707e2453feSJesse Brandeburg  * Set link interrupt mask.
16717e2453feSJesse Brandeburg  **/
i40e_aq_set_phy_int_mask(struct i40e_hw * hw,u16 mask,struct i40e_asq_cmd_details * cmd_details)16725180ff13SJan Sokolowski int i40e_aq_set_phy_int_mask(struct i40e_hw *hw,
16737e2453feSJesse Brandeburg 			     u16 mask,
16747e2453feSJesse Brandeburg 			     struct i40e_asq_cmd_details *cmd_details)
16757e2453feSJesse Brandeburg {
16767e2453feSJesse Brandeburg 	struct i40e_aq_desc desc;
16777e2453feSJesse Brandeburg 	struct i40e_aqc_set_phy_int_mask *cmd =
16787e2453feSJesse Brandeburg 		(struct i40e_aqc_set_phy_int_mask *)&desc.params.raw;
16795180ff13SJan Sokolowski 	int status;
16807e2453feSJesse Brandeburg 
16817e2453feSJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc,
16827e2453feSJesse Brandeburg 					  i40e_aqc_opc_set_phy_int_mask);
16837e2453feSJesse Brandeburg 
16847e2453feSJesse Brandeburg 	cmd->event_mask = cpu_to_le16(mask);
16857e2453feSJesse Brandeburg 
16867e2453feSJesse Brandeburg 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
16877e2453feSJesse Brandeburg 
16887e2453feSJesse Brandeburg 	return status;
16897e2453feSJesse Brandeburg }
16907e2453feSJesse Brandeburg 
16917e2453feSJesse Brandeburg /**
1692b1746fbaSTirthendu Sarkar  * i40e_aq_set_mac_loopback
1693b1746fbaSTirthendu Sarkar  * @hw: pointer to the HW struct
1694b1746fbaSTirthendu Sarkar  * @ena_lpbk: Enable or Disable loopback
1695b1746fbaSTirthendu Sarkar  * @cmd_details: pointer to command details structure or NULL
1696b1746fbaSTirthendu Sarkar  *
1697b1746fbaSTirthendu Sarkar  * Enable/disable loopback on a given port
1698b1746fbaSTirthendu Sarkar  */
i40e_aq_set_mac_loopback(struct i40e_hw * hw,bool ena_lpbk,struct i40e_asq_cmd_details * cmd_details)16995180ff13SJan Sokolowski int i40e_aq_set_mac_loopback(struct i40e_hw *hw, bool ena_lpbk,
1700b1746fbaSTirthendu Sarkar 			     struct i40e_asq_cmd_details *cmd_details)
1701b1746fbaSTirthendu Sarkar {
1702b1746fbaSTirthendu Sarkar 	struct i40e_aq_desc desc;
1703b1746fbaSTirthendu Sarkar 	struct i40e_aqc_set_lb_mode *cmd =
1704b1746fbaSTirthendu Sarkar 		(struct i40e_aqc_set_lb_mode *)&desc.params.raw;
1705b1746fbaSTirthendu Sarkar 
1706b1746fbaSTirthendu Sarkar 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_set_lb_modes);
1707b1746fbaSTirthendu Sarkar 	if (ena_lpbk) {
1708b1746fbaSTirthendu Sarkar 		if (hw->nvm.version <= I40E_LEGACY_LOOPBACK_NVM_VER)
1709b1746fbaSTirthendu Sarkar 			cmd->lb_mode = cpu_to_le16(I40E_AQ_LB_MAC_LOCAL_LEGACY);
1710b1746fbaSTirthendu Sarkar 		else
1711b1746fbaSTirthendu Sarkar 			cmd->lb_mode = cpu_to_le16(I40E_AQ_LB_MAC_LOCAL);
1712b1746fbaSTirthendu Sarkar 	}
1713b1746fbaSTirthendu Sarkar 
1714b1746fbaSTirthendu Sarkar 	return i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1715b1746fbaSTirthendu Sarkar }
1716b1746fbaSTirthendu Sarkar 
1717b1746fbaSTirthendu Sarkar /**
171831b606d0SCarolyn Wyborny  * i40e_aq_set_phy_debug
171931b606d0SCarolyn Wyborny  * @hw: pointer to the hw struct
172031b606d0SCarolyn Wyborny  * @cmd_flags: debug command flags
172131b606d0SCarolyn Wyborny  * @cmd_details: pointer to command details structure or NULL
172231b606d0SCarolyn Wyborny  *
172331b606d0SCarolyn Wyborny  * Reset the external PHY.
172431b606d0SCarolyn Wyborny  **/
i40e_aq_set_phy_debug(struct i40e_hw * hw,u8 cmd_flags,struct i40e_asq_cmd_details * cmd_details)17255180ff13SJan Sokolowski int i40e_aq_set_phy_debug(struct i40e_hw *hw, u8 cmd_flags,
172631b606d0SCarolyn Wyborny 			  struct i40e_asq_cmd_details *cmd_details)
172731b606d0SCarolyn Wyborny {
172831b606d0SCarolyn Wyborny 	struct i40e_aq_desc desc;
172931b606d0SCarolyn Wyborny 	struct i40e_aqc_set_phy_debug *cmd =
173031b606d0SCarolyn Wyborny 		(struct i40e_aqc_set_phy_debug *)&desc.params.raw;
17315180ff13SJan Sokolowski 	int status;
173231b606d0SCarolyn Wyborny 
173331b606d0SCarolyn Wyborny 	i40e_fill_default_direct_cmd_desc(&desc,
173431b606d0SCarolyn Wyborny 					  i40e_aqc_opc_set_phy_debug);
173531b606d0SCarolyn Wyborny 
173631b606d0SCarolyn Wyborny 	cmd->command_flags = cmd_flags;
173731b606d0SCarolyn Wyborny 
173831b606d0SCarolyn Wyborny 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
173931b606d0SCarolyn Wyborny 
174031b606d0SCarolyn Wyborny 	return status;
174131b606d0SCarolyn Wyborny }
174231b606d0SCarolyn Wyborny 
174331b606d0SCarolyn Wyborny /**
17444bd5e02aSPrzemyslaw Patynowski  * i40e_is_aq_api_ver_ge
17454bd5e02aSPrzemyslaw Patynowski  * @aq: pointer to AdminQ info containing HW API version to compare
17464bd5e02aSPrzemyslaw Patynowski  * @maj: API major value
17474bd5e02aSPrzemyslaw Patynowski  * @min: API minor value
17484bd5e02aSPrzemyslaw Patynowski  *
17494bd5e02aSPrzemyslaw Patynowski  * Assert whether current HW API version is greater/equal than provided.
17504bd5e02aSPrzemyslaw Patynowski  **/
i40e_is_aq_api_ver_ge(struct i40e_adminq_info * aq,u16 maj,u16 min)17514bd5e02aSPrzemyslaw Patynowski static bool i40e_is_aq_api_ver_ge(struct i40e_adminq_info *aq, u16 maj,
17524bd5e02aSPrzemyslaw Patynowski 				  u16 min)
17534bd5e02aSPrzemyslaw Patynowski {
17544bd5e02aSPrzemyslaw Patynowski 	return (aq->api_maj_ver > maj ||
17554bd5e02aSPrzemyslaw Patynowski 		(aq->api_maj_ver == maj && aq->api_min_ver >= min));
17564bd5e02aSPrzemyslaw Patynowski }
17574bd5e02aSPrzemyslaw Patynowski 
17584bd5e02aSPrzemyslaw Patynowski /**
175956a62fc8SJesse Brandeburg  * i40e_aq_add_vsi
176056a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
176198d44381SJeff Kirsher  * @vsi_ctx: pointer to a vsi context struct
176256a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
176356a62fc8SJesse Brandeburg  *
176456a62fc8SJesse Brandeburg  * Add a VSI context to the hardware.
176556a62fc8SJesse Brandeburg **/
i40e_aq_add_vsi(struct i40e_hw * hw,struct i40e_vsi_context * vsi_ctx,struct i40e_asq_cmd_details * cmd_details)17665180ff13SJan Sokolowski int i40e_aq_add_vsi(struct i40e_hw *hw,
176756a62fc8SJesse Brandeburg 		    struct i40e_vsi_context *vsi_ctx,
176856a62fc8SJesse Brandeburg 		    struct i40e_asq_cmd_details *cmd_details)
176956a62fc8SJesse Brandeburg {
177056a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
177156a62fc8SJesse Brandeburg 	struct i40e_aqc_add_get_update_vsi *cmd =
177256a62fc8SJesse Brandeburg 		(struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
177356a62fc8SJesse Brandeburg 	struct i40e_aqc_add_get_update_vsi_completion *resp =
177456a62fc8SJesse Brandeburg 		(struct i40e_aqc_add_get_update_vsi_completion *)
177556a62fc8SJesse Brandeburg 		&desc.params.raw;
17765180ff13SJan Sokolowski 	int status;
177756a62fc8SJesse Brandeburg 
177856a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc,
177956a62fc8SJesse Brandeburg 					  i40e_aqc_opc_add_vsi);
178056a62fc8SJesse Brandeburg 
178156a62fc8SJesse Brandeburg 	cmd->uplink_seid = cpu_to_le16(vsi_ctx->uplink_seid);
178256a62fc8SJesse Brandeburg 	cmd->connection_type = vsi_ctx->connection_type;
178356a62fc8SJesse Brandeburg 	cmd->vf_id = vsi_ctx->vf_num;
178456a62fc8SJesse Brandeburg 	cmd->vsi_flags = cpu_to_le16(vsi_ctx->flags);
178556a62fc8SJesse Brandeburg 
178656a62fc8SJesse Brandeburg 	desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
178756a62fc8SJesse Brandeburg 
178859b3d735SJedrzej Jagielski 	status = i40e_asq_send_command_atomic(hw, &desc, &vsi_ctx->info,
178959b3d735SJedrzej Jagielski 					      sizeof(vsi_ctx->info),
179059b3d735SJedrzej Jagielski 					      cmd_details, true);
179156a62fc8SJesse Brandeburg 
179256a62fc8SJesse Brandeburg 	if (status)
179356a62fc8SJesse Brandeburg 		goto aq_add_vsi_exit;
179456a62fc8SJesse Brandeburg 
179556a62fc8SJesse Brandeburg 	vsi_ctx->seid = le16_to_cpu(resp->seid);
179656a62fc8SJesse Brandeburg 	vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
179756a62fc8SJesse Brandeburg 	vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
179856a62fc8SJesse Brandeburg 	vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
179956a62fc8SJesse Brandeburg 
180056a62fc8SJesse Brandeburg aq_add_vsi_exit:
180156a62fc8SJesse Brandeburg 	return status;
180256a62fc8SJesse Brandeburg }
180356a62fc8SJesse Brandeburg 
180456a62fc8SJesse Brandeburg /**
1805fb70fabaSMitch Williams  * i40e_aq_set_default_vsi
1806fb70fabaSMitch Williams  * @hw: pointer to the hw struct
1807fb70fabaSMitch Williams  * @seid: vsi number
1808fb70fabaSMitch Williams  * @cmd_details: pointer to command details structure or NULL
1809fb70fabaSMitch Williams  **/
i40e_aq_set_default_vsi(struct i40e_hw * hw,u16 seid,struct i40e_asq_cmd_details * cmd_details)18105180ff13SJan Sokolowski int i40e_aq_set_default_vsi(struct i40e_hw *hw,
1811fb70fabaSMitch Williams 			    u16 seid,
1812fb70fabaSMitch Williams 			    struct i40e_asq_cmd_details *cmd_details)
1813fb70fabaSMitch Williams {
1814fb70fabaSMitch Williams 	struct i40e_aq_desc desc;
1815fb70fabaSMitch Williams 	struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
1816fb70fabaSMitch Williams 		(struct i40e_aqc_set_vsi_promiscuous_modes *)
1817fb70fabaSMitch Williams 		&desc.params.raw;
18185180ff13SJan Sokolowski 	int status;
1819fb70fabaSMitch Williams 
1820fb70fabaSMitch Williams 	i40e_fill_default_direct_cmd_desc(&desc,
1821fb70fabaSMitch Williams 					  i40e_aqc_opc_set_vsi_promiscuous_modes);
1822fb70fabaSMitch Williams 
1823fb70fabaSMitch Williams 	cmd->promiscuous_flags = cpu_to_le16(I40E_AQC_SET_VSI_DEFAULT);
1824fb70fabaSMitch Williams 	cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_DEFAULT);
1825fb70fabaSMitch Williams 	cmd->seid = cpu_to_le16(seid);
1826fb70fabaSMitch Williams 
1827fb70fabaSMitch Williams 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1828fb70fabaSMitch Williams 
1829fb70fabaSMitch Williams 	return status;
1830fb70fabaSMitch Williams }
1831fb70fabaSMitch Williams 
1832fb70fabaSMitch Williams /**
1833fb70fabaSMitch Williams  * i40e_aq_clear_default_vsi
1834fb70fabaSMitch Williams  * @hw: pointer to the hw struct
1835fb70fabaSMitch Williams  * @seid: vsi number
1836fb70fabaSMitch Williams  * @cmd_details: pointer to command details structure or NULL
1837fb70fabaSMitch Williams  **/
i40e_aq_clear_default_vsi(struct i40e_hw * hw,u16 seid,struct i40e_asq_cmd_details * cmd_details)18385180ff13SJan Sokolowski int i40e_aq_clear_default_vsi(struct i40e_hw *hw,
1839fb70fabaSMitch Williams 			      u16 seid,
1840fb70fabaSMitch Williams 			      struct i40e_asq_cmd_details *cmd_details)
1841fb70fabaSMitch Williams {
1842fb70fabaSMitch Williams 	struct i40e_aq_desc desc;
1843fb70fabaSMitch Williams 	struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
1844fb70fabaSMitch Williams 		(struct i40e_aqc_set_vsi_promiscuous_modes *)
1845fb70fabaSMitch Williams 		&desc.params.raw;
18465180ff13SJan Sokolowski 	int status;
1847fb70fabaSMitch Williams 
1848fb70fabaSMitch Williams 	i40e_fill_default_direct_cmd_desc(&desc,
1849fb70fabaSMitch Williams 					  i40e_aqc_opc_set_vsi_promiscuous_modes);
1850fb70fabaSMitch Williams 
1851fb70fabaSMitch Williams 	cmd->promiscuous_flags = cpu_to_le16(0);
1852fb70fabaSMitch Williams 	cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_DEFAULT);
1853fb70fabaSMitch Williams 	cmd->seid = cpu_to_le16(seid);
1854fb70fabaSMitch Williams 
1855fb70fabaSMitch Williams 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1856fb70fabaSMitch Williams 
1857fb70fabaSMitch Williams 	return status;
1858fb70fabaSMitch Williams }
1859fb70fabaSMitch Williams 
1860fb70fabaSMitch Williams /**
186156a62fc8SJesse Brandeburg  * i40e_aq_set_vsi_unicast_promiscuous
186256a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
186356a62fc8SJesse Brandeburg  * @seid: vsi number
186456a62fc8SJesse Brandeburg  * @set: set unicast promiscuous enable/disable
186556a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
1866b5569892SAnjali Singhai Jain  * @rx_only_promisc: flag to decide if egress traffic gets mirrored in promisc
186756a62fc8SJesse Brandeburg  **/
i40e_aq_set_vsi_unicast_promiscuous(struct i40e_hw * hw,u16 seid,bool set,struct i40e_asq_cmd_details * cmd_details,bool rx_only_promisc)18685180ff13SJan Sokolowski int i40e_aq_set_vsi_unicast_promiscuous(struct i40e_hw *hw,
1869885552a2SMitch Williams 					u16 seid, bool set,
1870b5569892SAnjali Singhai Jain 					struct i40e_asq_cmd_details *cmd_details,
1871b5569892SAnjali Singhai Jain 					bool rx_only_promisc)
187256a62fc8SJesse Brandeburg {
187356a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
187456a62fc8SJesse Brandeburg 	struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
187556a62fc8SJesse Brandeburg 		(struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
187656a62fc8SJesse Brandeburg 	u16 flags = 0;
18775180ff13SJan Sokolowski 	int status;
187856a62fc8SJesse Brandeburg 
187956a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc,
188056a62fc8SJesse Brandeburg 					i40e_aqc_opc_set_vsi_promiscuous_modes);
188156a62fc8SJesse Brandeburg 
18823b120089SAnjali Singhai Jain 	if (set) {
188356a62fc8SJesse Brandeburg 		flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
18844bd5e02aSPrzemyslaw Patynowski 		if (rx_only_promisc && i40e_is_aq_api_ver_ge(&hw->aq, 1, 5))
18854bd5e02aSPrzemyslaw Patynowski 			flags |= I40E_AQC_SET_VSI_PROMISC_RX_ONLY;
18863b120089SAnjali Singhai Jain 	}
188756a62fc8SJesse Brandeburg 
188856a62fc8SJesse Brandeburg 	cmd->promiscuous_flags = cpu_to_le16(flags);
188956a62fc8SJesse Brandeburg 
189056a62fc8SJesse Brandeburg 	cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
18914bd5e02aSPrzemyslaw Patynowski 	if (i40e_is_aq_api_ver_ge(&hw->aq, 1, 5))
18924bd5e02aSPrzemyslaw Patynowski 		cmd->valid_flags |=
18934bd5e02aSPrzemyslaw Patynowski 			cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_RX_ONLY);
189456a62fc8SJesse Brandeburg 
189556a62fc8SJesse Brandeburg 	cmd->seid = cpu_to_le16(seid);
189656a62fc8SJesse Brandeburg 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
189756a62fc8SJesse Brandeburg 
189856a62fc8SJesse Brandeburg 	return status;
189956a62fc8SJesse Brandeburg }
190056a62fc8SJesse Brandeburg 
190156a62fc8SJesse Brandeburg /**
190256a62fc8SJesse Brandeburg  * i40e_aq_set_vsi_multicast_promiscuous
190356a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
190456a62fc8SJesse Brandeburg  * @seid: vsi number
190556a62fc8SJesse Brandeburg  * @set: set multicast promiscuous enable/disable
190656a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
190756a62fc8SJesse Brandeburg  **/
i40e_aq_set_vsi_multicast_promiscuous(struct i40e_hw * hw,u16 seid,bool set,struct i40e_asq_cmd_details * cmd_details)19085180ff13SJan Sokolowski int i40e_aq_set_vsi_multicast_promiscuous(struct i40e_hw *hw,
19095180ff13SJan Sokolowski 					  u16 seid, bool set,
19105180ff13SJan Sokolowski 					  struct i40e_asq_cmd_details *cmd_details)
191156a62fc8SJesse Brandeburg {
191256a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
191356a62fc8SJesse Brandeburg 	struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
191456a62fc8SJesse Brandeburg 		(struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
191556a62fc8SJesse Brandeburg 	u16 flags = 0;
19165180ff13SJan Sokolowski 	int status;
191756a62fc8SJesse Brandeburg 
191856a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc,
191956a62fc8SJesse Brandeburg 					i40e_aqc_opc_set_vsi_promiscuous_modes);
192056a62fc8SJesse Brandeburg 
192156a62fc8SJesse Brandeburg 	if (set)
192256a62fc8SJesse Brandeburg 		flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
192356a62fc8SJesse Brandeburg 
192456a62fc8SJesse Brandeburg 	cmd->promiscuous_flags = cpu_to_le16(flags);
192556a62fc8SJesse Brandeburg 
192656a62fc8SJesse Brandeburg 	cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
192756a62fc8SJesse Brandeburg 
192856a62fc8SJesse Brandeburg 	cmd->seid = cpu_to_le16(seid);
192956a62fc8SJesse Brandeburg 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
193056a62fc8SJesse Brandeburg 
193156a62fc8SJesse Brandeburg 	return status;
193256a62fc8SJesse Brandeburg }
193356a62fc8SJesse Brandeburg 
193456a62fc8SJesse Brandeburg /**
19356c41a760SGreg Rose  * i40e_aq_set_vsi_mc_promisc_on_vlan
19366c41a760SGreg Rose  * @hw: pointer to the hw struct
19376c41a760SGreg Rose  * @seid: vsi number
19386c41a760SGreg Rose  * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
19396c41a760SGreg Rose  * @vid: The VLAN tag filter - capture any multicast packet with this VLAN tag
19406c41a760SGreg Rose  * @cmd_details: pointer to command details structure or NULL
19416c41a760SGreg Rose  **/
i40e_aq_set_vsi_mc_promisc_on_vlan(struct i40e_hw * hw,u16 seid,bool enable,u16 vid,struct i40e_asq_cmd_details * cmd_details)19425180ff13SJan Sokolowski int i40e_aq_set_vsi_mc_promisc_on_vlan(struct i40e_hw *hw,
19436c41a760SGreg Rose 				       u16 seid, bool enable,
19446c41a760SGreg Rose 				       u16 vid,
19456c41a760SGreg Rose 				       struct i40e_asq_cmd_details *cmd_details)
19466c41a760SGreg Rose {
19476c41a760SGreg Rose 	struct i40e_aq_desc desc;
19486c41a760SGreg Rose 	struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
19496c41a760SGreg Rose 		(struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
19506c41a760SGreg Rose 	u16 flags = 0;
19515180ff13SJan Sokolowski 	int status;
19526c41a760SGreg Rose 
19536c41a760SGreg Rose 	i40e_fill_default_direct_cmd_desc(&desc,
19546c41a760SGreg Rose 					  i40e_aqc_opc_set_vsi_promiscuous_modes);
19556c41a760SGreg Rose 
19566c41a760SGreg Rose 	if (enable)
19576c41a760SGreg Rose 		flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
19586c41a760SGreg Rose 
19596c41a760SGreg Rose 	cmd->promiscuous_flags = cpu_to_le16(flags);
19606c41a760SGreg Rose 	cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
19616c41a760SGreg Rose 	cmd->seid = cpu_to_le16(seid);
19626c41a760SGreg Rose 	cmd->vlan_tag = cpu_to_le16(vid | I40E_AQC_SET_VSI_VLAN_VALID);
19636c41a760SGreg Rose 
1964ef39584dSJedrzej Jagielski 	status = i40e_asq_send_command_atomic(hw, &desc, NULL, 0,
1965ef39584dSJedrzej Jagielski 					      cmd_details, true);
19666c41a760SGreg Rose 
19676c41a760SGreg Rose 	return status;
19686c41a760SGreg Rose }
19696c41a760SGreg Rose 
19706c41a760SGreg Rose /**
19716c41a760SGreg Rose  * i40e_aq_set_vsi_uc_promisc_on_vlan
19726c41a760SGreg Rose  * @hw: pointer to the hw struct
19736c41a760SGreg Rose  * @seid: vsi number
19746c41a760SGreg Rose  * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
19756c41a760SGreg Rose  * @vid: The VLAN tag filter - capture any unicast packet with this VLAN tag
19766c41a760SGreg Rose  * @cmd_details: pointer to command details structure or NULL
19776c41a760SGreg Rose  **/
i40e_aq_set_vsi_uc_promisc_on_vlan(struct i40e_hw * hw,u16 seid,bool enable,u16 vid,struct i40e_asq_cmd_details * cmd_details)19785180ff13SJan Sokolowski int i40e_aq_set_vsi_uc_promisc_on_vlan(struct i40e_hw *hw,
19796c41a760SGreg Rose 				       u16 seid, bool enable,
19806c41a760SGreg Rose 				       u16 vid,
19816c41a760SGreg Rose 				       struct i40e_asq_cmd_details *cmd_details)
19826c41a760SGreg Rose {
19836c41a760SGreg Rose 	struct i40e_aq_desc desc;
19846c41a760SGreg Rose 	struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
19856c41a760SGreg Rose 		(struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
19866c41a760SGreg Rose 	u16 flags = 0;
19875180ff13SJan Sokolowski 	int status;
19886c41a760SGreg Rose 
19896c41a760SGreg Rose 	i40e_fill_default_direct_cmd_desc(&desc,
19906c41a760SGreg Rose 					  i40e_aqc_opc_set_vsi_promiscuous_modes);
19916c41a760SGreg Rose 
19924bd5e02aSPrzemyslaw Patynowski 	if (enable) {
19936c41a760SGreg Rose 		flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
19944bd5e02aSPrzemyslaw Patynowski 		if (i40e_is_aq_api_ver_ge(&hw->aq, 1, 5))
19954bd5e02aSPrzemyslaw Patynowski 			flags |= I40E_AQC_SET_VSI_PROMISC_RX_ONLY;
19964bd5e02aSPrzemyslaw Patynowski 	}
19976c41a760SGreg Rose 
19986c41a760SGreg Rose 	cmd->promiscuous_flags = cpu_to_le16(flags);
19996c41a760SGreg Rose 	cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
20004bd5e02aSPrzemyslaw Patynowski 	if (i40e_is_aq_api_ver_ge(&hw->aq, 1, 5))
20014bd5e02aSPrzemyslaw Patynowski 		cmd->valid_flags |=
20024bd5e02aSPrzemyslaw Patynowski 			cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_RX_ONLY);
20036c41a760SGreg Rose 	cmd->seid = cpu_to_le16(seid);
20046c41a760SGreg Rose 	cmd->vlan_tag = cpu_to_le16(vid | I40E_AQC_SET_VSI_VLAN_VALID);
20056c41a760SGreg Rose 
2006ef39584dSJedrzej Jagielski 	status = i40e_asq_send_command_atomic(hw, &desc, NULL, 0,
2007ef39584dSJedrzej Jagielski 					      cmd_details, true);
20086c41a760SGreg Rose 
20096c41a760SGreg Rose 	return status;
20106c41a760SGreg Rose }
20116c41a760SGreg Rose 
20126c41a760SGreg Rose /**
2013435c084aSJacob Keller  * i40e_aq_set_vsi_bc_promisc_on_vlan
2014435c084aSJacob Keller  * @hw: pointer to the hw struct
2015435c084aSJacob Keller  * @seid: vsi number
2016435c084aSJacob Keller  * @enable: set broadcast promiscuous enable/disable for a given VLAN
2017435c084aSJacob Keller  * @vid: The VLAN tag filter - capture any broadcast packet with this VLAN tag
2018435c084aSJacob Keller  * @cmd_details: pointer to command details structure or NULL
2019435c084aSJacob Keller  **/
i40e_aq_set_vsi_bc_promisc_on_vlan(struct i40e_hw * hw,u16 seid,bool enable,u16 vid,struct i40e_asq_cmd_details * cmd_details)20205180ff13SJan Sokolowski int i40e_aq_set_vsi_bc_promisc_on_vlan(struct i40e_hw *hw,
2021435c084aSJacob Keller 				       u16 seid, bool enable, u16 vid,
2022435c084aSJacob Keller 				       struct i40e_asq_cmd_details *cmd_details)
2023435c084aSJacob Keller {
2024435c084aSJacob Keller 	struct i40e_aq_desc desc;
2025435c084aSJacob Keller 	struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2026435c084aSJacob Keller 		(struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2027435c084aSJacob Keller 	u16 flags = 0;
20285180ff13SJan Sokolowski 	int status;
2029435c084aSJacob Keller 
2030435c084aSJacob Keller 	i40e_fill_default_direct_cmd_desc(&desc,
2031435c084aSJacob Keller 					i40e_aqc_opc_set_vsi_promiscuous_modes);
2032435c084aSJacob Keller 
2033435c084aSJacob Keller 	if (enable)
2034435c084aSJacob Keller 		flags |= I40E_AQC_SET_VSI_PROMISC_BROADCAST;
2035435c084aSJacob Keller 
2036435c084aSJacob Keller 	cmd->promiscuous_flags = cpu_to_le16(flags);
2037435c084aSJacob Keller 	cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2038435c084aSJacob Keller 	cmd->seid = cpu_to_le16(seid);
2039435c084aSJacob Keller 	cmd->vlan_tag = cpu_to_le16(vid | I40E_AQC_SET_VSI_VLAN_VALID);
2040435c084aSJacob Keller 
2041435c084aSJacob Keller 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2042435c084aSJacob Keller 
2043435c084aSJacob Keller 	return status;
2044435c084aSJacob Keller }
2045435c084aSJacob Keller 
2046435c084aSJacob Keller /**
204756a62fc8SJesse Brandeburg  * i40e_aq_set_vsi_broadcast
204856a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
204956a62fc8SJesse Brandeburg  * @seid: vsi number
205056a62fc8SJesse Brandeburg  * @set_filter: true to set filter, false to clear filter
205156a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
205256a62fc8SJesse Brandeburg  *
205356a62fc8SJesse Brandeburg  * Set or clear the broadcast promiscuous flag (filter) for a given VSI.
205456a62fc8SJesse Brandeburg  **/
i40e_aq_set_vsi_broadcast(struct i40e_hw * hw,u16 seid,bool set_filter,struct i40e_asq_cmd_details * cmd_details)20555180ff13SJan Sokolowski int i40e_aq_set_vsi_broadcast(struct i40e_hw *hw,
205656a62fc8SJesse Brandeburg 			      u16 seid, bool set_filter,
205756a62fc8SJesse Brandeburg 			      struct i40e_asq_cmd_details *cmd_details)
205856a62fc8SJesse Brandeburg {
205956a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
206056a62fc8SJesse Brandeburg 	struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
206156a62fc8SJesse Brandeburg 		(struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
20625180ff13SJan Sokolowski 	int status;
206356a62fc8SJesse Brandeburg 
206456a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc,
206556a62fc8SJesse Brandeburg 					i40e_aqc_opc_set_vsi_promiscuous_modes);
206656a62fc8SJesse Brandeburg 
206756a62fc8SJesse Brandeburg 	if (set_filter)
206856a62fc8SJesse Brandeburg 		cmd->promiscuous_flags
206956a62fc8SJesse Brandeburg 			    |= cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
207056a62fc8SJesse Brandeburg 	else
207156a62fc8SJesse Brandeburg 		cmd->promiscuous_flags
207256a62fc8SJesse Brandeburg 			    &= cpu_to_le16(~I40E_AQC_SET_VSI_PROMISC_BROADCAST);
207356a62fc8SJesse Brandeburg 
207456a62fc8SJesse Brandeburg 	cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
207556a62fc8SJesse Brandeburg 	cmd->seid = cpu_to_le16(seid);
207656a62fc8SJesse Brandeburg 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
207756a62fc8SJesse Brandeburg 
207856a62fc8SJesse Brandeburg 	return status;
207956a62fc8SJesse Brandeburg }
208056a62fc8SJesse Brandeburg 
208156a62fc8SJesse Brandeburg /**
20827bd6875bSKiran Patil  * i40e_aq_set_vsi_vlan_promisc - control the VLAN promiscuous setting
20837bd6875bSKiran Patil  * @hw: pointer to the hw struct
20847bd6875bSKiran Patil  * @seid: vsi number
20857bd6875bSKiran Patil  * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
20867bd6875bSKiran Patil  * @cmd_details: pointer to command details structure or NULL
20877bd6875bSKiran Patil  **/
i40e_aq_set_vsi_vlan_promisc(struct i40e_hw * hw,u16 seid,bool enable,struct i40e_asq_cmd_details * cmd_details)20885180ff13SJan Sokolowski int i40e_aq_set_vsi_vlan_promisc(struct i40e_hw *hw,
20897bd6875bSKiran Patil 				 u16 seid, bool enable,
20907bd6875bSKiran Patil 				 struct i40e_asq_cmd_details *cmd_details)
20917bd6875bSKiran Patil {
20927bd6875bSKiran Patil 	struct i40e_aq_desc desc;
20937bd6875bSKiran Patil 	struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
20947bd6875bSKiran Patil 		(struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
20957bd6875bSKiran Patil 	u16 flags = 0;
20965180ff13SJan Sokolowski 	int status;
20977bd6875bSKiran Patil 
20987bd6875bSKiran Patil 	i40e_fill_default_direct_cmd_desc(&desc,
20997bd6875bSKiran Patil 					i40e_aqc_opc_set_vsi_promiscuous_modes);
21007bd6875bSKiran Patil 	if (enable)
21017bd6875bSKiran Patil 		flags |= I40E_AQC_SET_VSI_PROMISC_VLAN;
21027bd6875bSKiran Patil 
21037bd6875bSKiran Patil 	cmd->promiscuous_flags = cpu_to_le16(flags);
21047bd6875bSKiran Patil 	cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_VLAN);
21057bd6875bSKiran Patil 	cmd->seid = cpu_to_le16(seid);
21067bd6875bSKiran Patil 
21077bd6875bSKiran Patil 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
21087bd6875bSKiran Patil 
21097bd6875bSKiran Patil 	return status;
21107bd6875bSKiran Patil }
21117bd6875bSKiran Patil 
21127bd6875bSKiran Patil /**
2113262de08fSJesse Brandeburg  * i40e_aq_get_vsi_params - get VSI configuration info
211456a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
211598d44381SJeff Kirsher  * @vsi_ctx: pointer to a vsi context struct
211656a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
211756a62fc8SJesse Brandeburg  **/
i40e_aq_get_vsi_params(struct i40e_hw * hw,struct i40e_vsi_context * vsi_ctx,struct i40e_asq_cmd_details * cmd_details)21185180ff13SJan Sokolowski int i40e_aq_get_vsi_params(struct i40e_hw *hw,
211956a62fc8SJesse Brandeburg 			   struct i40e_vsi_context *vsi_ctx,
212056a62fc8SJesse Brandeburg 			   struct i40e_asq_cmd_details *cmd_details)
212156a62fc8SJesse Brandeburg {
212256a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
2123f5ac8579SShannon Nelson 	struct i40e_aqc_add_get_update_vsi *cmd =
2124f5ac8579SShannon Nelson 		(struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
212556a62fc8SJesse Brandeburg 	struct i40e_aqc_add_get_update_vsi_completion *resp =
212656a62fc8SJesse Brandeburg 		(struct i40e_aqc_add_get_update_vsi_completion *)
212756a62fc8SJesse Brandeburg 		&desc.params.raw;
21285180ff13SJan Sokolowski 	int status;
212956a62fc8SJesse Brandeburg 
213056a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc,
213156a62fc8SJesse Brandeburg 					  i40e_aqc_opc_get_vsi_parameters);
213256a62fc8SJesse Brandeburg 
2133f5ac8579SShannon Nelson 	cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
213456a62fc8SJesse Brandeburg 
213556a62fc8SJesse Brandeburg 	desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
213656a62fc8SJesse Brandeburg 
213756a62fc8SJesse Brandeburg 	status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
213856a62fc8SJesse Brandeburg 				    sizeof(vsi_ctx->info), NULL);
213956a62fc8SJesse Brandeburg 
214056a62fc8SJesse Brandeburg 	if (status)
214156a62fc8SJesse Brandeburg 		goto aq_get_vsi_params_exit;
214256a62fc8SJesse Brandeburg 
214356a62fc8SJesse Brandeburg 	vsi_ctx->seid = le16_to_cpu(resp->seid);
214456a62fc8SJesse Brandeburg 	vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
214556a62fc8SJesse Brandeburg 	vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
214656a62fc8SJesse Brandeburg 	vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
214756a62fc8SJesse Brandeburg 
214856a62fc8SJesse Brandeburg aq_get_vsi_params_exit:
214956a62fc8SJesse Brandeburg 	return status;
215056a62fc8SJesse Brandeburg }
215156a62fc8SJesse Brandeburg 
215256a62fc8SJesse Brandeburg /**
215356a62fc8SJesse Brandeburg  * i40e_aq_update_vsi_params
215456a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
215598d44381SJeff Kirsher  * @vsi_ctx: pointer to a vsi context struct
215656a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
215756a62fc8SJesse Brandeburg  *
215856a62fc8SJesse Brandeburg  * Update a VSI context.
215956a62fc8SJesse Brandeburg  **/
i40e_aq_update_vsi_params(struct i40e_hw * hw,struct i40e_vsi_context * vsi_ctx,struct i40e_asq_cmd_details * cmd_details)21605180ff13SJan Sokolowski int i40e_aq_update_vsi_params(struct i40e_hw *hw,
216156a62fc8SJesse Brandeburg 			      struct i40e_vsi_context *vsi_ctx,
216256a62fc8SJesse Brandeburg 			      struct i40e_asq_cmd_details *cmd_details)
216356a62fc8SJesse Brandeburg {
216456a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
2165f5ac8579SShannon Nelson 	struct i40e_aqc_add_get_update_vsi *cmd =
2166f5ac8579SShannon Nelson 		(struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
2167b6caccacSKevin Scott 	struct i40e_aqc_add_get_update_vsi_completion *resp =
2168b6caccacSKevin Scott 		(struct i40e_aqc_add_get_update_vsi_completion *)
2169b6caccacSKevin Scott 		&desc.params.raw;
21705180ff13SJan Sokolowski 	int status;
217156a62fc8SJesse Brandeburg 
217256a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc,
217356a62fc8SJesse Brandeburg 					  i40e_aqc_opc_update_vsi_parameters);
2174f5ac8579SShannon Nelson 	cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
217556a62fc8SJesse Brandeburg 
217656a62fc8SJesse Brandeburg 	desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
217756a62fc8SJesse Brandeburg 
217859b3d735SJedrzej Jagielski 	status = i40e_asq_send_command_atomic(hw, &desc, &vsi_ctx->info,
217959b3d735SJedrzej Jagielski 					      sizeof(vsi_ctx->info),
218059b3d735SJedrzej Jagielski 					      cmd_details, true);
218156a62fc8SJesse Brandeburg 
2182b6caccacSKevin Scott 	vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
2183b6caccacSKevin Scott 	vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
2184b6caccacSKevin Scott 
218556a62fc8SJesse Brandeburg 	return status;
218656a62fc8SJesse Brandeburg }
218756a62fc8SJesse Brandeburg 
218856a62fc8SJesse Brandeburg /**
218956a62fc8SJesse Brandeburg  * i40e_aq_get_switch_config
219056a62fc8SJesse Brandeburg  * @hw: pointer to the hardware structure
219156a62fc8SJesse Brandeburg  * @buf: pointer to the result buffer
219256a62fc8SJesse Brandeburg  * @buf_size: length of input buffer
219356a62fc8SJesse Brandeburg  * @start_seid: seid to start for the report, 0 == beginning
219456a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
219556a62fc8SJesse Brandeburg  *
219656a62fc8SJesse Brandeburg  * Fill the buf with switch configuration returned from AdminQ command
219756a62fc8SJesse Brandeburg  **/
i40e_aq_get_switch_config(struct i40e_hw * hw,struct i40e_aqc_get_switch_config_resp * buf,u16 buf_size,u16 * start_seid,struct i40e_asq_cmd_details * cmd_details)21985180ff13SJan Sokolowski int i40e_aq_get_switch_config(struct i40e_hw *hw,
219956a62fc8SJesse Brandeburg 			      struct i40e_aqc_get_switch_config_resp *buf,
220056a62fc8SJesse Brandeburg 			      u16 buf_size, u16 *start_seid,
220156a62fc8SJesse Brandeburg 			      struct i40e_asq_cmd_details *cmd_details)
220256a62fc8SJesse Brandeburg {
220356a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
220456a62fc8SJesse Brandeburg 	struct i40e_aqc_switch_seid *scfg =
220556a62fc8SJesse Brandeburg 		(struct i40e_aqc_switch_seid *)&desc.params.raw;
22065180ff13SJan Sokolowski 	int status;
220756a62fc8SJesse Brandeburg 
220856a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc,
220956a62fc8SJesse Brandeburg 					  i40e_aqc_opc_get_switch_config);
221056a62fc8SJesse Brandeburg 	desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
221156a62fc8SJesse Brandeburg 	if (buf_size > I40E_AQ_LARGE_BUF)
221256a62fc8SJesse Brandeburg 		desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
221356a62fc8SJesse Brandeburg 	scfg->seid = cpu_to_le16(*start_seid);
221456a62fc8SJesse Brandeburg 
221556a62fc8SJesse Brandeburg 	status = i40e_asq_send_command(hw, &desc, buf, buf_size, cmd_details);
221656a62fc8SJesse Brandeburg 	*start_seid = le16_to_cpu(scfg->seid);
221756a62fc8SJesse Brandeburg 
221856a62fc8SJesse Brandeburg 	return status;
221956a62fc8SJesse Brandeburg }
222056a62fc8SJesse Brandeburg 
222156a62fc8SJesse Brandeburg /**
2222f3d58497SShannon Nelson  * i40e_aq_set_switch_config
2223f3d58497SShannon Nelson  * @hw: pointer to the hardware structure
2224f3d58497SShannon Nelson  * @flags: bit flag values to set
222535bea904SJacob Keller  * @mode: cloud filter mode
2226f3d58497SShannon Nelson  * @valid_flags: which bit flags to set
22275efe0c6cSAmritha Nambiar  * @mode: cloud filter mode
2228f3d58497SShannon Nelson  * @cmd_details: pointer to command details structure or NULL
2229f3d58497SShannon Nelson  *
2230f3d58497SShannon Nelson  * Set switch configuration bits
2231f3d58497SShannon Nelson  **/
i40e_aq_set_switch_config(struct i40e_hw * hw,u16 flags,u16 valid_flags,u8 mode,struct i40e_asq_cmd_details * cmd_details)22325180ff13SJan Sokolowski int i40e_aq_set_switch_config(struct i40e_hw *hw,
2233f3d58497SShannon Nelson 			      u16 flags,
22345efe0c6cSAmritha Nambiar 			      u16 valid_flags, u8 mode,
2235f3d58497SShannon Nelson 			      struct i40e_asq_cmd_details *cmd_details)
2236f3d58497SShannon Nelson {
2237f3d58497SShannon Nelson 	struct i40e_aq_desc desc;
2238f3d58497SShannon Nelson 	struct i40e_aqc_set_switch_config *scfg =
2239f3d58497SShannon Nelson 		(struct i40e_aqc_set_switch_config *)&desc.params.raw;
22405180ff13SJan Sokolowski 	int status;
2241f3d58497SShannon Nelson 
2242f3d58497SShannon Nelson 	i40e_fill_default_direct_cmd_desc(&desc,
2243f3d58497SShannon Nelson 					  i40e_aqc_opc_set_switch_config);
2244f3d58497SShannon Nelson 	scfg->flags = cpu_to_le16(flags);
2245f3d58497SShannon Nelson 	scfg->valid_flags = cpu_to_le16(valid_flags);
22465efe0c6cSAmritha Nambiar 	scfg->mode = mode;
2247ab243ec9SScott Peterson 	if (hw->flags & I40E_HW_FLAG_802_1AD_CAPABLE) {
2248ab243ec9SScott Peterson 		scfg->switch_tag = cpu_to_le16(hw->switch_tag);
2249ab243ec9SScott Peterson 		scfg->first_tag = cpu_to_le16(hw->first_tag);
2250ab243ec9SScott Peterson 		scfg->second_tag = cpu_to_le16(hw->second_tag);
2251ab243ec9SScott Peterson 	}
2252f3d58497SShannon Nelson 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2253f3d58497SShannon Nelson 
2254f3d58497SShannon Nelson 	return status;
2255f3d58497SShannon Nelson }
2256f3d58497SShannon Nelson 
2257f3d58497SShannon Nelson /**
225856a62fc8SJesse Brandeburg  * i40e_aq_get_firmware_version
225956a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
226056a62fc8SJesse Brandeburg  * @fw_major_version: firmware major version
226156a62fc8SJesse Brandeburg  * @fw_minor_version: firmware minor version
22627edf810cSShannon Nelson  * @fw_build: firmware build number
226356a62fc8SJesse Brandeburg  * @api_major_version: major queue version
226456a62fc8SJesse Brandeburg  * @api_minor_version: minor queue version
226556a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
226656a62fc8SJesse Brandeburg  *
226756a62fc8SJesse Brandeburg  * Get the firmware version from the admin queue commands
226856a62fc8SJesse Brandeburg  **/
i40e_aq_get_firmware_version(struct i40e_hw * hw,u16 * fw_major_version,u16 * fw_minor_version,u32 * fw_build,u16 * api_major_version,u16 * api_minor_version,struct i40e_asq_cmd_details * cmd_details)22695180ff13SJan Sokolowski int i40e_aq_get_firmware_version(struct i40e_hw *hw,
227056a62fc8SJesse Brandeburg 				 u16 *fw_major_version, u16 *fw_minor_version,
22717edf810cSShannon Nelson 				 u32 *fw_build,
227256a62fc8SJesse Brandeburg 				 u16 *api_major_version, u16 *api_minor_version,
227356a62fc8SJesse Brandeburg 				 struct i40e_asq_cmd_details *cmd_details)
227456a62fc8SJesse Brandeburg {
227556a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
227656a62fc8SJesse Brandeburg 	struct i40e_aqc_get_version *resp =
227756a62fc8SJesse Brandeburg 		(struct i40e_aqc_get_version *)&desc.params.raw;
22785180ff13SJan Sokolowski 	int status;
227956a62fc8SJesse Brandeburg 
228056a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_version);
228156a62fc8SJesse Brandeburg 
228256a62fc8SJesse Brandeburg 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
228356a62fc8SJesse Brandeburg 
228456a62fc8SJesse Brandeburg 	if (!status) {
22857edf810cSShannon Nelson 		if (fw_major_version)
228656a62fc8SJesse Brandeburg 			*fw_major_version = le16_to_cpu(resp->fw_major);
22877edf810cSShannon Nelson 		if (fw_minor_version)
228856a62fc8SJesse Brandeburg 			*fw_minor_version = le16_to_cpu(resp->fw_minor);
22897edf810cSShannon Nelson 		if (fw_build)
22907edf810cSShannon Nelson 			*fw_build = le32_to_cpu(resp->fw_build);
22917edf810cSShannon Nelson 		if (api_major_version)
229256a62fc8SJesse Brandeburg 			*api_major_version = le16_to_cpu(resp->api_major);
22937edf810cSShannon Nelson 		if (api_minor_version)
229456a62fc8SJesse Brandeburg 			*api_minor_version = le16_to_cpu(resp->api_minor);
229556a62fc8SJesse Brandeburg 	}
229656a62fc8SJesse Brandeburg 
229756a62fc8SJesse Brandeburg 	return status;
229856a62fc8SJesse Brandeburg }
229956a62fc8SJesse Brandeburg 
230056a62fc8SJesse Brandeburg /**
230156a62fc8SJesse Brandeburg  * i40e_aq_send_driver_version
230256a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
230356a62fc8SJesse Brandeburg  * @dv: driver's major, minor version
230456a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
230556a62fc8SJesse Brandeburg  *
230656a62fc8SJesse Brandeburg  * Send the driver version to the firmware
230756a62fc8SJesse Brandeburg  **/
i40e_aq_send_driver_version(struct i40e_hw * hw,struct i40e_driver_version * dv,struct i40e_asq_cmd_details * cmd_details)23085180ff13SJan Sokolowski int i40e_aq_send_driver_version(struct i40e_hw *hw,
230956a62fc8SJesse Brandeburg 				struct i40e_driver_version *dv,
231056a62fc8SJesse Brandeburg 				struct i40e_asq_cmd_details *cmd_details)
231156a62fc8SJesse Brandeburg {
231256a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
231356a62fc8SJesse Brandeburg 	struct i40e_aqc_driver_version *cmd =
231456a62fc8SJesse Brandeburg 		(struct i40e_aqc_driver_version *)&desc.params.raw;
23155180ff13SJan Sokolowski 	int status;
23169d2f98e1SKevin Scott 	u16 len;
231756a62fc8SJesse Brandeburg 
231856a62fc8SJesse Brandeburg 	if (dv == NULL)
2319230f3d53SJan Sokolowski 		return -EINVAL;
232056a62fc8SJesse Brandeburg 
232156a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_driver_version);
232256a62fc8SJesse Brandeburg 
23233b38cd17SKevin Scott 	desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
232456a62fc8SJesse Brandeburg 	cmd->driver_major_ver = dv->major_version;
232556a62fc8SJesse Brandeburg 	cmd->driver_minor_ver = dv->minor_version;
232656a62fc8SJesse Brandeburg 	cmd->driver_build_ver = dv->build_version;
232756a62fc8SJesse Brandeburg 	cmd->driver_subbuild_ver = dv->subbuild_version;
2328d2466013SShannon Nelson 
2329d2466013SShannon Nelson 	len = 0;
2330d2466013SShannon Nelson 	while (len < sizeof(dv->driver_string) &&
2331d2466013SShannon Nelson 	       (dv->driver_string[len] < 0x80) &&
2332d2466013SShannon Nelson 	       dv->driver_string[len])
2333d2466013SShannon Nelson 		len++;
2334d2466013SShannon Nelson 	status = i40e_asq_send_command(hw, &desc, dv->driver_string,
2335d2466013SShannon Nelson 				       len, cmd_details);
233656a62fc8SJesse Brandeburg 
233756a62fc8SJesse Brandeburg 	return status;
233856a62fc8SJesse Brandeburg }
233956a62fc8SJesse Brandeburg 
234056a62fc8SJesse Brandeburg /**
234156a62fc8SJesse Brandeburg  * i40e_get_link_status - get status of the HW network link
234256a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
2343a72a5abcSJesse Brandeburg  * @link_up: pointer to bool (true/false = linkup/linkdown)
234456a62fc8SJesse Brandeburg  *
2345a72a5abcSJesse Brandeburg  * Variable link_up true if link is up, false if link is down.
2346a72a5abcSJesse Brandeburg  * The variable link_up is invalid if returned value of status != 0
234756a62fc8SJesse Brandeburg  *
234856a62fc8SJesse Brandeburg  * Side effect: LinkStatusEvent reporting becomes enabled
234956a62fc8SJesse Brandeburg  **/
i40e_get_link_status(struct i40e_hw * hw,bool * link_up)23505180ff13SJan Sokolowski int i40e_get_link_status(struct i40e_hw *hw, bool *link_up)
235156a62fc8SJesse Brandeburg {
23525180ff13SJan Sokolowski 	int status = 0;
235356a62fc8SJesse Brandeburg 
235456a62fc8SJesse Brandeburg 	if (hw->phy.get_link_info) {
23550a862b43SCatherine Sullivan 		status = i40e_update_link_info(hw);
235656a62fc8SJesse Brandeburg 
235756a62fc8SJesse Brandeburg 		if (status)
2358a72a5abcSJesse Brandeburg 			i40e_debug(hw, I40E_DEBUG_LINK, "get link failed: status %d\n",
2359a72a5abcSJesse Brandeburg 				   status);
236056a62fc8SJesse Brandeburg 	}
236156a62fc8SJesse Brandeburg 
2362a72a5abcSJesse Brandeburg 	*link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
236356a62fc8SJesse Brandeburg 
2364a72a5abcSJesse Brandeburg 	return status;
236556a62fc8SJesse Brandeburg }
236656a62fc8SJesse Brandeburg 
236756a62fc8SJesse Brandeburg /**
2368262de08fSJesse Brandeburg  * i40e_update_link_info - update status of the HW network link
23690a862b43SCatherine Sullivan  * @hw: pointer to the hw struct
23700a862b43SCatherine Sullivan  **/
i40e_update_link_info(struct i40e_hw * hw)23715180ff13SJan Sokolowski noinline_for_stack int i40e_update_link_info(struct i40e_hw *hw)
23720a862b43SCatherine Sullivan {
23730a862b43SCatherine Sullivan 	struct i40e_aq_get_phy_abilities_resp abilities;
23745180ff13SJan Sokolowski 	int status = 0;
23750a862b43SCatherine Sullivan 
23760a862b43SCatherine Sullivan 	status = i40e_aq_get_link_info(hw, true, NULL, NULL);
23770a862b43SCatherine Sullivan 	if (status)
23780a862b43SCatherine Sullivan 		return status;
23790a862b43SCatherine Sullivan 
2380ab425cb7SCarolyn Wyborny 	/* extra checking needed to ensure link info to user is timely */
2381ab425cb7SCarolyn Wyborny 	if ((hw->phy.link_info.link_info & I40E_AQ_MEDIA_AVAILABLE) &&
2382ab425cb7SCarolyn Wyborny 	    ((hw->phy.link_info.link_info & I40E_AQ_LINK_UP) ||
2383ab425cb7SCarolyn Wyborny 	     !(hw->phy.link_info_old.link_info & I40E_AQ_LINK_UP))) {
23848589af70SCarolyn Wyborny 		status = i40e_aq_get_phy_capabilities(hw, false, false,
23858589af70SCarolyn Wyborny 						      &abilities, NULL);
23860a862b43SCatherine Sullivan 		if (status)
23870a862b43SCatherine Sullivan 			return status;
23880a862b43SCatherine Sullivan 
2389e42b7e9cSJaroslaw Gawin 		if (abilities.fec_cfg_curr_mod_ext_info &
2390e42b7e9cSJaroslaw Gawin 		    I40E_AQ_ENABLE_FEC_AUTO)
2391e42b7e9cSJaroslaw Gawin 			hw->phy.link_info.req_fec_info =
2392e42b7e9cSJaroslaw Gawin 				(I40E_AQ_REQUEST_FEC_KR |
2393e42b7e9cSJaroslaw Gawin 				 I40E_AQ_REQUEST_FEC_RS);
2394e42b7e9cSJaroslaw Gawin 		else
2395ed601f66SMariusz Stachura 			hw->phy.link_info.req_fec_info =
2396ed601f66SMariusz Stachura 				abilities.fec_cfg_curr_mod_ext_info &
2397e42b7e9cSJaroslaw Gawin 				(I40E_AQ_REQUEST_FEC_KR |
2398e42b7e9cSJaroslaw Gawin 				 I40E_AQ_REQUEST_FEC_RS);
2399ed601f66SMariusz Stachura 
24000a862b43SCatherine Sullivan 		memcpy(hw->phy.link_info.module_type, &abilities.module_type,
24010a862b43SCatherine Sullivan 		       sizeof(hw->phy.link_info.module_type));
24028589af70SCarolyn Wyborny 	}
24030a862b43SCatherine Sullivan 
24040a862b43SCatherine Sullivan 	return status;
24050a862b43SCatherine Sullivan }
24060a862b43SCatherine Sullivan 
24070a862b43SCatherine Sullivan /**
240856a62fc8SJesse Brandeburg  * i40e_aq_add_veb - Insert a VEB between the VSI and the MAC
240956a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
241056a62fc8SJesse Brandeburg  * @uplink_seid: the MAC or other gizmo SEID
241156a62fc8SJesse Brandeburg  * @downlink_seid: the VSI SEID
241256a62fc8SJesse Brandeburg  * @enabled_tc: bitmap of TCs to be enabled
241356a62fc8SJesse Brandeburg  * @default_port: true for default port VSI, false for control port
241456a62fc8SJesse Brandeburg  * @veb_seid: pointer to where to put the resulting VEB SEID
24158a187f44SShannon Nelson  * @enable_stats: true to turn on VEB stats
241656a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
241756a62fc8SJesse Brandeburg  *
241856a62fc8SJesse Brandeburg  * This asks the FW to add a VEB between the uplink and downlink
241956a62fc8SJesse Brandeburg  * elements.  If the uplink SEID is 0, this will be a floating VEB.
242056a62fc8SJesse Brandeburg  **/
i40e_aq_add_veb(struct i40e_hw * hw,u16 uplink_seid,u16 downlink_seid,u8 enabled_tc,bool default_port,u16 * veb_seid,bool enable_stats,struct i40e_asq_cmd_details * cmd_details)24215180ff13SJan Sokolowski int i40e_aq_add_veb(struct i40e_hw *hw, u16 uplink_seid,
242256a62fc8SJesse Brandeburg 		    u16 downlink_seid, u8 enabled_tc,
24238a187f44SShannon Nelson 		    bool default_port, u16 *veb_seid,
24248a187f44SShannon Nelson 		    bool enable_stats,
242556a62fc8SJesse Brandeburg 		    struct i40e_asq_cmd_details *cmd_details)
242656a62fc8SJesse Brandeburg {
242756a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
242856a62fc8SJesse Brandeburg 	struct i40e_aqc_add_veb *cmd =
242956a62fc8SJesse Brandeburg 		(struct i40e_aqc_add_veb *)&desc.params.raw;
243056a62fc8SJesse Brandeburg 	struct i40e_aqc_add_veb_completion *resp =
243156a62fc8SJesse Brandeburg 		(struct i40e_aqc_add_veb_completion *)&desc.params.raw;
243256a62fc8SJesse Brandeburg 	u16 veb_flags = 0;
24335180ff13SJan Sokolowski 	int status;
243456a62fc8SJesse Brandeburg 
243556a62fc8SJesse Brandeburg 	/* SEIDs need to either both be set or both be 0 for floating VEB */
243656a62fc8SJesse Brandeburg 	if (!!uplink_seid != !!downlink_seid)
2437230f3d53SJan Sokolowski 		return -EINVAL;
243856a62fc8SJesse Brandeburg 
243956a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_veb);
244056a62fc8SJesse Brandeburg 
244156a62fc8SJesse Brandeburg 	cmd->uplink_seid = cpu_to_le16(uplink_seid);
244256a62fc8SJesse Brandeburg 	cmd->downlink_seid = cpu_to_le16(downlink_seid);
244356a62fc8SJesse Brandeburg 	cmd->enable_tcs = enabled_tc;
244456a62fc8SJesse Brandeburg 	if (!uplink_seid)
244556a62fc8SJesse Brandeburg 		veb_flags |= I40E_AQC_ADD_VEB_FLOATING;
244656a62fc8SJesse Brandeburg 	if (default_port)
244756a62fc8SJesse Brandeburg 		veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DEFAULT;
244856a62fc8SJesse Brandeburg 	else
244956a62fc8SJesse Brandeburg 		veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DATA;
2450e1c51b95SKevin Scott 
24518a187f44SShannon Nelson 	/* reverse logic here: set the bitflag to disable the stats */
24528a187f44SShannon Nelson 	if (!enable_stats)
24538a187f44SShannon Nelson 		veb_flags |= I40E_AQC_ADD_VEB_ENABLE_DISABLE_STATS;
2454e1c51b95SKevin Scott 
245556a62fc8SJesse Brandeburg 	cmd->veb_flags = cpu_to_le16(veb_flags);
245656a62fc8SJesse Brandeburg 
245756a62fc8SJesse Brandeburg 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
245856a62fc8SJesse Brandeburg 
245956a62fc8SJesse Brandeburg 	if (!status && veb_seid)
246056a62fc8SJesse Brandeburg 		*veb_seid = le16_to_cpu(resp->veb_seid);
246156a62fc8SJesse Brandeburg 
246256a62fc8SJesse Brandeburg 	return status;
246356a62fc8SJesse Brandeburg }
246456a62fc8SJesse Brandeburg 
246556a62fc8SJesse Brandeburg /**
246656a62fc8SJesse Brandeburg  * i40e_aq_get_veb_parameters - Retrieve VEB parameters
246756a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
246856a62fc8SJesse Brandeburg  * @veb_seid: the SEID of the VEB to query
246956a62fc8SJesse Brandeburg  * @switch_id: the uplink switch id
247098d44381SJeff Kirsher  * @floating: set to true if the VEB is floating
247156a62fc8SJesse Brandeburg  * @statistic_index: index of the stats counter block for this VEB
247256a62fc8SJesse Brandeburg  * @vebs_used: number of VEB's used by function
247398d44381SJeff Kirsher  * @vebs_free: total VEB's not reserved by any function
247456a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
247556a62fc8SJesse Brandeburg  *
247656a62fc8SJesse Brandeburg  * This retrieves the parameters for a particular VEB, specified by
247756a62fc8SJesse Brandeburg  * uplink_seid, and returns them to the caller.
247856a62fc8SJesse Brandeburg  **/
i40e_aq_get_veb_parameters(struct i40e_hw * hw,u16 veb_seid,u16 * switch_id,bool * floating,u16 * statistic_index,u16 * vebs_used,u16 * vebs_free,struct i40e_asq_cmd_details * cmd_details)24795180ff13SJan Sokolowski int i40e_aq_get_veb_parameters(struct i40e_hw *hw,
248056a62fc8SJesse Brandeburg 			       u16 veb_seid, u16 *switch_id,
248156a62fc8SJesse Brandeburg 			       bool *floating, u16 *statistic_index,
248256a62fc8SJesse Brandeburg 			       u16 *vebs_used, u16 *vebs_free,
248356a62fc8SJesse Brandeburg 			       struct i40e_asq_cmd_details *cmd_details)
248456a62fc8SJesse Brandeburg {
248556a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
248656a62fc8SJesse Brandeburg 	struct i40e_aqc_get_veb_parameters_completion *cmd_resp =
248756a62fc8SJesse Brandeburg 		(struct i40e_aqc_get_veb_parameters_completion *)
248856a62fc8SJesse Brandeburg 		&desc.params.raw;
24895180ff13SJan Sokolowski 	int status;
249056a62fc8SJesse Brandeburg 
249156a62fc8SJesse Brandeburg 	if (veb_seid == 0)
2492230f3d53SJan Sokolowski 		return -EINVAL;
249356a62fc8SJesse Brandeburg 
249456a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc,
249556a62fc8SJesse Brandeburg 					  i40e_aqc_opc_get_veb_parameters);
249656a62fc8SJesse Brandeburg 	cmd_resp->seid = cpu_to_le16(veb_seid);
249756a62fc8SJesse Brandeburg 
249856a62fc8SJesse Brandeburg 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
249956a62fc8SJesse Brandeburg 	if (status)
250056a62fc8SJesse Brandeburg 		goto get_veb_exit;
250156a62fc8SJesse Brandeburg 
250256a62fc8SJesse Brandeburg 	if (switch_id)
250356a62fc8SJesse Brandeburg 		*switch_id = le16_to_cpu(cmd_resp->switch_id);
250456a62fc8SJesse Brandeburg 	if (statistic_index)
250556a62fc8SJesse Brandeburg 		*statistic_index = le16_to_cpu(cmd_resp->statistic_index);
250656a62fc8SJesse Brandeburg 	if (vebs_used)
250756a62fc8SJesse Brandeburg 		*vebs_used = le16_to_cpu(cmd_resp->vebs_used);
250856a62fc8SJesse Brandeburg 	if (vebs_free)
250956a62fc8SJesse Brandeburg 		*vebs_free = le16_to_cpu(cmd_resp->vebs_free);
251056a62fc8SJesse Brandeburg 	if (floating) {
251156a62fc8SJesse Brandeburg 		u16 flags = le16_to_cpu(cmd_resp->veb_flags);
25126995b36cSJesse Brandeburg 
251356a62fc8SJesse Brandeburg 		if (flags & I40E_AQC_ADD_VEB_FLOATING)
251456a62fc8SJesse Brandeburg 			*floating = true;
251556a62fc8SJesse Brandeburg 		else
251656a62fc8SJesse Brandeburg 			*floating = false;
251756a62fc8SJesse Brandeburg 	}
251856a62fc8SJesse Brandeburg 
251956a62fc8SJesse Brandeburg get_veb_exit:
252056a62fc8SJesse Brandeburg 	return status;
252156a62fc8SJesse Brandeburg }
252256a62fc8SJesse Brandeburg 
252356a62fc8SJesse Brandeburg /**
2524b3237df9SJedrzej Jagielski  * i40e_prepare_add_macvlan
252556a62fc8SJesse Brandeburg  * @mv_list: list of macvlans to be added
2526b3237df9SJedrzej Jagielski  * @desc: pointer to AQ descriptor structure
252756a62fc8SJesse Brandeburg  * @count: length of the list
2528b3237df9SJedrzej Jagielski  * @seid: VSI for the mac address
252956a62fc8SJesse Brandeburg  *
2530b3237df9SJedrzej Jagielski  * Internal helper function that prepares the add macvlan request
2531b3237df9SJedrzej Jagielski  * and returns the buffer size.
253256a62fc8SJesse Brandeburg  **/
2533b3237df9SJedrzej Jagielski static u16
i40e_prepare_add_macvlan(struct i40e_aqc_add_macvlan_element_data * mv_list,struct i40e_aq_desc * desc,u16 count,u16 seid)2534b3237df9SJedrzej Jagielski i40e_prepare_add_macvlan(struct i40e_aqc_add_macvlan_element_data *mv_list,
2535b3237df9SJedrzej Jagielski 			 struct i40e_aq_desc *desc, u16 count, u16 seid)
253656a62fc8SJesse Brandeburg {
253756a62fc8SJesse Brandeburg 	struct i40e_aqc_macvlan *cmd =
2538b3237df9SJedrzej Jagielski 		(struct i40e_aqc_macvlan *)&desc->params.raw;
253956a62fc8SJesse Brandeburg 	u16 buf_size;
254067be6eb2SShannon Nelson 	int i;
254156a62fc8SJesse Brandeburg 
25421efc80eeSShannon Nelson 	buf_size = count * sizeof(*mv_list);
254356a62fc8SJesse Brandeburg 
254456a62fc8SJesse Brandeburg 	/* prep the rest of the request */
2545b3237df9SJedrzej Jagielski 	i40e_fill_default_direct_cmd_desc(desc, i40e_aqc_opc_add_macvlan);
254656a62fc8SJesse Brandeburg 	cmd->num_addresses = cpu_to_le16(count);
254756a62fc8SJesse Brandeburg 	cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
254856a62fc8SJesse Brandeburg 	cmd->seid[1] = 0;
254956a62fc8SJesse Brandeburg 	cmd->seid[2] = 0;
255056a62fc8SJesse Brandeburg 
255167be6eb2SShannon Nelson 	for (i = 0; i < count; i++)
255267be6eb2SShannon Nelson 		if (is_multicast_ether_addr(mv_list[i].mac_addr))
255367be6eb2SShannon Nelson 			mv_list[i].flags |=
255467be6eb2SShannon Nelson 			       cpu_to_le16(I40E_AQC_MACVLAN_ADD_USE_SHARED_MAC);
255567be6eb2SShannon Nelson 
2556b3237df9SJedrzej Jagielski 	desc->flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
255756a62fc8SJesse Brandeburg 	if (buf_size > I40E_AQ_LARGE_BUF)
2558b3237df9SJedrzej Jagielski 		desc->flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
255956a62fc8SJesse Brandeburg 
2560b3237df9SJedrzej Jagielski 	return buf_size;
2561b3237df9SJedrzej Jagielski }
2562b3237df9SJedrzej Jagielski 
2563b3237df9SJedrzej Jagielski /**
2564b3237df9SJedrzej Jagielski  * i40e_aq_add_macvlan
2565b3237df9SJedrzej Jagielski  * @hw: pointer to the hw struct
2566b3237df9SJedrzej Jagielski  * @seid: VSI for the mac address
2567b3237df9SJedrzej Jagielski  * @mv_list: list of macvlans to be added
2568b3237df9SJedrzej Jagielski  * @count: length of the list
2569b3237df9SJedrzej Jagielski  * @cmd_details: pointer to command details structure or NULL
2570b3237df9SJedrzej Jagielski  *
2571b3237df9SJedrzej Jagielski  * Add MAC/VLAN addresses to the HW filtering
2572b3237df9SJedrzej Jagielski  **/
25735180ff13SJan Sokolowski int
i40e_aq_add_macvlan(struct i40e_hw * hw,u16 seid,struct i40e_aqc_add_macvlan_element_data * mv_list,u16 count,struct i40e_asq_cmd_details * cmd_details)2574b3237df9SJedrzej Jagielski i40e_aq_add_macvlan(struct i40e_hw *hw, u16 seid,
2575b3237df9SJedrzej Jagielski 		    struct i40e_aqc_add_macvlan_element_data *mv_list,
2576b3237df9SJedrzej Jagielski 		    u16 count, struct i40e_asq_cmd_details *cmd_details)
2577b3237df9SJedrzej Jagielski {
2578b3237df9SJedrzej Jagielski 	struct i40e_aq_desc desc;
2579b3237df9SJedrzej Jagielski 	u16 buf_size;
2580b3237df9SJedrzej Jagielski 
2581b3237df9SJedrzej Jagielski 	if (count == 0 || !mv_list || !hw)
2582230f3d53SJan Sokolowski 		return -EINVAL;
2583b3237df9SJedrzej Jagielski 
2584b3237df9SJedrzej Jagielski 	buf_size = i40e_prepare_add_macvlan(mv_list, &desc, count, seid);
2585b3237df9SJedrzej Jagielski 
2586b3237df9SJedrzej Jagielski 	return i40e_asq_send_command_atomic(hw, &desc, mv_list, buf_size,
258759b3d735SJedrzej Jagielski 					    cmd_details, true);
2588b3237df9SJedrzej Jagielski }
258956a62fc8SJesse Brandeburg 
2590b3237df9SJedrzej Jagielski /**
2591b3237df9SJedrzej Jagielski  * i40e_aq_add_macvlan_v2
2592b3237df9SJedrzej Jagielski  * @hw: pointer to the hw struct
2593b3237df9SJedrzej Jagielski  * @seid: VSI for the mac address
2594b3237df9SJedrzej Jagielski  * @mv_list: list of macvlans to be added
2595b3237df9SJedrzej Jagielski  * @count: length of the list
2596b3237df9SJedrzej Jagielski  * @cmd_details: pointer to command details structure or NULL
2597b3237df9SJedrzej Jagielski  * @aq_status: pointer to Admin Queue status return value
2598b3237df9SJedrzej Jagielski  *
2599b3237df9SJedrzej Jagielski  * Add MAC/VLAN addresses to the HW filtering.
2600b3237df9SJedrzej Jagielski  * The _v2 version returns the last Admin Queue status in aq_status
2601b3237df9SJedrzej Jagielski  * to avoid race conditions in access to hw->aq.asq_last_status.
2602b3237df9SJedrzej Jagielski  * It also calls _v2 versions of asq_send_command functions to
2603b3237df9SJedrzej Jagielski  * get the aq_status on the stack.
2604b3237df9SJedrzej Jagielski  **/
26055180ff13SJan Sokolowski int
i40e_aq_add_macvlan_v2(struct i40e_hw * hw,u16 seid,struct i40e_aqc_add_macvlan_element_data * mv_list,u16 count,struct i40e_asq_cmd_details * cmd_details,enum i40e_admin_queue_err * aq_status)2606b3237df9SJedrzej Jagielski i40e_aq_add_macvlan_v2(struct i40e_hw *hw, u16 seid,
2607b3237df9SJedrzej Jagielski 		       struct i40e_aqc_add_macvlan_element_data *mv_list,
2608b3237df9SJedrzej Jagielski 		       u16 count, struct i40e_asq_cmd_details *cmd_details,
2609b3237df9SJedrzej Jagielski 		       enum i40e_admin_queue_err *aq_status)
2610b3237df9SJedrzej Jagielski {
2611b3237df9SJedrzej Jagielski 	struct i40e_aq_desc desc;
2612b3237df9SJedrzej Jagielski 	u16 buf_size;
2613b3237df9SJedrzej Jagielski 
2614b3237df9SJedrzej Jagielski 	if (count == 0 || !mv_list || !hw)
2615230f3d53SJan Sokolowski 		return -EINVAL;
2616b3237df9SJedrzej Jagielski 
2617b3237df9SJedrzej Jagielski 	buf_size = i40e_prepare_add_macvlan(mv_list, &desc, count, seid);
2618b3237df9SJedrzej Jagielski 
2619b3237df9SJedrzej Jagielski 	return i40e_asq_send_command_atomic_v2(hw, &desc, mv_list, buf_size,
2620b3237df9SJedrzej Jagielski 					       cmd_details, true, aq_status);
262156a62fc8SJesse Brandeburg }
262256a62fc8SJesse Brandeburg 
262356a62fc8SJesse Brandeburg /**
262456a62fc8SJesse Brandeburg  * i40e_aq_remove_macvlan
262556a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
262656a62fc8SJesse Brandeburg  * @seid: VSI for the mac address
262756a62fc8SJesse Brandeburg  * @mv_list: list of macvlans to be removed
262856a62fc8SJesse Brandeburg  * @count: length of the list
262956a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
263056a62fc8SJesse Brandeburg  *
263156a62fc8SJesse Brandeburg  * Remove MAC/VLAN addresses from the HW filtering
263256a62fc8SJesse Brandeburg  **/
26335180ff13SJan Sokolowski int
i40e_aq_remove_macvlan(struct i40e_hw * hw,u16 seid,struct i40e_aqc_remove_macvlan_element_data * mv_list,u16 count,struct i40e_asq_cmd_details * cmd_details)26345180ff13SJan Sokolowski i40e_aq_remove_macvlan(struct i40e_hw *hw, u16 seid,
263556a62fc8SJesse Brandeburg 		       struct i40e_aqc_remove_macvlan_element_data *mv_list,
263656a62fc8SJesse Brandeburg 		       u16 count, struct i40e_asq_cmd_details *cmd_details)
263756a62fc8SJesse Brandeburg {
263856a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
263956a62fc8SJesse Brandeburg 	struct i40e_aqc_macvlan *cmd =
264056a62fc8SJesse Brandeburg 		(struct i40e_aqc_macvlan *)&desc.params.raw;
264156a62fc8SJesse Brandeburg 	u16 buf_size;
26425180ff13SJan Sokolowski 	int status;
264356a62fc8SJesse Brandeburg 
264456a62fc8SJesse Brandeburg 	if (count == 0 || !mv_list || !hw)
2645230f3d53SJan Sokolowski 		return -EINVAL;
264656a62fc8SJesse Brandeburg 
26471efc80eeSShannon Nelson 	buf_size = count * sizeof(*mv_list);
264856a62fc8SJesse Brandeburg 
264956a62fc8SJesse Brandeburg 	/* prep the rest of the request */
265056a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_macvlan);
265156a62fc8SJesse Brandeburg 	cmd->num_addresses = cpu_to_le16(count);
265256a62fc8SJesse Brandeburg 	cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
265356a62fc8SJesse Brandeburg 	cmd->seid[1] = 0;
265456a62fc8SJesse Brandeburg 	cmd->seid[2] = 0;
265556a62fc8SJesse Brandeburg 
265656a62fc8SJesse Brandeburg 	desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
265756a62fc8SJesse Brandeburg 	if (buf_size > I40E_AQ_LARGE_BUF)
265856a62fc8SJesse Brandeburg 		desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
265956a62fc8SJesse Brandeburg 
266059b3d735SJedrzej Jagielski 	status = i40e_asq_send_command_atomic(hw, &desc, mv_list, buf_size,
266159b3d735SJedrzej Jagielski 					      cmd_details, true);
266256a62fc8SJesse Brandeburg 
266356a62fc8SJesse Brandeburg 	return status;
266456a62fc8SJesse Brandeburg }
266556a62fc8SJesse Brandeburg 
266656a62fc8SJesse Brandeburg /**
266774073848SJedrzej Jagielski  * i40e_aq_remove_macvlan_v2
266874073848SJedrzej Jagielski  * @hw: pointer to the hw struct
266974073848SJedrzej Jagielski  * @seid: VSI for the mac address
267074073848SJedrzej Jagielski  * @mv_list: list of macvlans to be removed
267174073848SJedrzej Jagielski  * @count: length of the list
267274073848SJedrzej Jagielski  * @cmd_details: pointer to command details structure or NULL
267374073848SJedrzej Jagielski  * @aq_status: pointer to Admin Queue status return value
267474073848SJedrzej Jagielski  *
267574073848SJedrzej Jagielski  * Remove MAC/VLAN addresses from the HW filtering.
267674073848SJedrzej Jagielski  * The _v2 version returns the last Admin Queue status in aq_status
267774073848SJedrzej Jagielski  * to avoid race conditions in access to hw->aq.asq_last_status.
267874073848SJedrzej Jagielski  * It also calls _v2 versions of asq_send_command functions to
267974073848SJedrzej Jagielski  * get the aq_status on the stack.
268074073848SJedrzej Jagielski  **/
26815180ff13SJan Sokolowski int
i40e_aq_remove_macvlan_v2(struct i40e_hw * hw,u16 seid,struct i40e_aqc_remove_macvlan_element_data * mv_list,u16 count,struct i40e_asq_cmd_details * cmd_details,enum i40e_admin_queue_err * aq_status)268274073848SJedrzej Jagielski i40e_aq_remove_macvlan_v2(struct i40e_hw *hw, u16 seid,
268374073848SJedrzej Jagielski 			  struct i40e_aqc_remove_macvlan_element_data *mv_list,
268474073848SJedrzej Jagielski 			  u16 count, struct i40e_asq_cmd_details *cmd_details,
268574073848SJedrzej Jagielski 			  enum i40e_admin_queue_err *aq_status)
268674073848SJedrzej Jagielski {
268774073848SJedrzej Jagielski 	struct i40e_aqc_macvlan *cmd;
268874073848SJedrzej Jagielski 	struct i40e_aq_desc desc;
268974073848SJedrzej Jagielski 	u16 buf_size;
269074073848SJedrzej Jagielski 
269174073848SJedrzej Jagielski 	if (count == 0 || !mv_list || !hw)
2692230f3d53SJan Sokolowski 		return -EINVAL;
269374073848SJedrzej Jagielski 
269474073848SJedrzej Jagielski 	buf_size = count * sizeof(*mv_list);
269574073848SJedrzej Jagielski 
269674073848SJedrzej Jagielski 	/* prep the rest of the request */
269774073848SJedrzej Jagielski 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_macvlan);
269874073848SJedrzej Jagielski 	cmd = (struct i40e_aqc_macvlan *)&desc.params.raw;
269974073848SJedrzej Jagielski 	cmd->num_addresses = cpu_to_le16(count);
270074073848SJedrzej Jagielski 	cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
270174073848SJedrzej Jagielski 	cmd->seid[1] = 0;
270274073848SJedrzej Jagielski 	cmd->seid[2] = 0;
270374073848SJedrzej Jagielski 
270474073848SJedrzej Jagielski 	desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
270574073848SJedrzej Jagielski 	if (buf_size > I40E_AQ_LARGE_BUF)
270674073848SJedrzej Jagielski 		desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
270774073848SJedrzej Jagielski 
270874073848SJedrzej Jagielski 	return i40e_asq_send_command_atomic_v2(hw, &desc, mv_list, buf_size,
270974073848SJedrzej Jagielski 						 cmd_details, true, aq_status);
271074073848SJedrzej Jagielski }
271174073848SJedrzej Jagielski 
271274073848SJedrzej Jagielski /**
27137bd6875bSKiran Patil  * i40e_mirrorrule_op - Internal helper function to add/delete mirror rule
27147bd6875bSKiran Patil  * @hw: pointer to the hw struct
27157bd6875bSKiran Patil  * @opcode: AQ opcode for add or delete mirror rule
27167bd6875bSKiran Patil  * @sw_seid: Switch SEID (to which rule refers)
27177bd6875bSKiran Patil  * @rule_type: Rule Type (ingress/egress/VLAN)
27187bd6875bSKiran Patil  * @id: Destination VSI SEID or Rule ID
27197bd6875bSKiran Patil  * @count: length of the list
27207bd6875bSKiran Patil  * @mr_list: list of mirrored VSI SEIDs or VLAN IDs
27217bd6875bSKiran Patil  * @cmd_details: pointer to command details structure or NULL
27227bd6875bSKiran Patil  * @rule_id: Rule ID returned from FW
2723f5254429SJacob Keller  * @rules_used: Number of rules used in internal switch
2724f5254429SJacob Keller  * @rules_free: Number of rules free in internal switch
27257bd6875bSKiran Patil  *
27267bd6875bSKiran Patil  * Add/Delete a mirror rule to a specific switch. Mirror rules are supported for
27277bd6875bSKiran Patil  * VEBs/VEPA elements only
27287bd6875bSKiran Patil  **/
i40e_mirrorrule_op(struct i40e_hw * hw,u16 opcode,u16 sw_seid,u16 rule_type,u16 id,u16 count,__le16 * mr_list,struct i40e_asq_cmd_details * cmd_details,u16 * rule_id,u16 * rules_used,u16 * rules_free)27295180ff13SJan Sokolowski static int i40e_mirrorrule_op(struct i40e_hw *hw,
27307bd6875bSKiran Patil 			      u16 opcode, u16 sw_seid, u16 rule_type, u16 id,
27317bd6875bSKiran Patil 			      u16 count, __le16 *mr_list,
27327bd6875bSKiran Patil 			      struct i40e_asq_cmd_details *cmd_details,
27337bd6875bSKiran Patil 			      u16 *rule_id, u16 *rules_used, u16 *rules_free)
27347bd6875bSKiran Patil {
27357bd6875bSKiran Patil 	struct i40e_aq_desc desc;
27367bd6875bSKiran Patil 	struct i40e_aqc_add_delete_mirror_rule *cmd =
27377bd6875bSKiran Patil 		(struct i40e_aqc_add_delete_mirror_rule *)&desc.params.raw;
27387bd6875bSKiran Patil 	struct i40e_aqc_add_delete_mirror_rule_completion *resp =
27397bd6875bSKiran Patil 	(struct i40e_aqc_add_delete_mirror_rule_completion *)&desc.params.raw;
27407bd6875bSKiran Patil 	u16 buf_size;
27415180ff13SJan Sokolowski 	int status;
27427bd6875bSKiran Patil 
27437bd6875bSKiran Patil 	buf_size = count * sizeof(*mr_list);
27447bd6875bSKiran Patil 
27457bd6875bSKiran Patil 	/* prep the rest of the request */
27467bd6875bSKiran Patil 	i40e_fill_default_direct_cmd_desc(&desc, opcode);
27477bd6875bSKiran Patil 	cmd->seid = cpu_to_le16(sw_seid);
27487bd6875bSKiran Patil 	cmd->rule_type = cpu_to_le16(rule_type &
27497bd6875bSKiran Patil 				     I40E_AQC_MIRROR_RULE_TYPE_MASK);
27507bd6875bSKiran Patil 	cmd->num_entries = cpu_to_le16(count);
27517bd6875bSKiran Patil 	/* Dest VSI for add, rule_id for delete */
27527bd6875bSKiran Patil 	cmd->destination = cpu_to_le16(id);
27537bd6875bSKiran Patil 	if (mr_list) {
27547bd6875bSKiran Patil 		desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
27557bd6875bSKiran Patil 						I40E_AQ_FLAG_RD));
27567bd6875bSKiran Patil 		if (buf_size > I40E_AQ_LARGE_BUF)
27577bd6875bSKiran Patil 			desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
27587bd6875bSKiran Patil 	}
27597bd6875bSKiran Patil 
27607bd6875bSKiran Patil 	status = i40e_asq_send_command(hw, &desc, mr_list, buf_size,
27617bd6875bSKiran Patil 				       cmd_details);
27627bd6875bSKiran Patil 	if (!status ||
27637bd6875bSKiran Patil 	    hw->aq.asq_last_status == I40E_AQ_RC_ENOSPC) {
27647bd6875bSKiran Patil 		if (rule_id)
27657bd6875bSKiran Patil 			*rule_id = le16_to_cpu(resp->rule_id);
27667bd6875bSKiran Patil 		if (rules_used)
27677bd6875bSKiran Patil 			*rules_used = le16_to_cpu(resp->mirror_rules_used);
27687bd6875bSKiran Patil 		if (rules_free)
27697bd6875bSKiran Patil 			*rules_free = le16_to_cpu(resp->mirror_rules_free);
27707bd6875bSKiran Patil 	}
27717bd6875bSKiran Patil 	return status;
27727bd6875bSKiran Patil }
27737bd6875bSKiran Patil 
27747bd6875bSKiran Patil /**
27757bd6875bSKiran Patil  * i40e_aq_add_mirrorrule - add a mirror rule
27767bd6875bSKiran Patil  * @hw: pointer to the hw struct
27777bd6875bSKiran Patil  * @sw_seid: Switch SEID (to which rule refers)
27787bd6875bSKiran Patil  * @rule_type: Rule Type (ingress/egress/VLAN)
27797bd6875bSKiran Patil  * @dest_vsi: SEID of VSI to which packets will be mirrored
27807bd6875bSKiran Patil  * @count: length of the list
27817bd6875bSKiran Patil  * @mr_list: list of mirrored VSI SEIDs or VLAN IDs
27827bd6875bSKiran Patil  * @cmd_details: pointer to command details structure or NULL
27837bd6875bSKiran Patil  * @rule_id: Rule ID returned from FW
2784f5254429SJacob Keller  * @rules_used: Number of rules used in internal switch
2785f5254429SJacob Keller  * @rules_free: Number of rules free in internal switch
27867bd6875bSKiran Patil  *
27877bd6875bSKiran Patil  * Add mirror rule. Mirror rules are supported for VEBs or VEPA elements only
27887bd6875bSKiran Patil  **/
i40e_aq_add_mirrorrule(struct i40e_hw * hw,u16 sw_seid,u16 rule_type,u16 dest_vsi,u16 count,__le16 * mr_list,struct i40e_asq_cmd_details * cmd_details,u16 * rule_id,u16 * rules_used,u16 * rules_free)27895180ff13SJan Sokolowski int i40e_aq_add_mirrorrule(struct i40e_hw *hw, u16 sw_seid,
27905180ff13SJan Sokolowski 			   u16 rule_type, u16 dest_vsi, u16 count,
27915180ff13SJan Sokolowski 			   __le16 *mr_list,
27927bd6875bSKiran Patil 			   struct i40e_asq_cmd_details *cmd_details,
27937bd6875bSKiran Patil 			   u16 *rule_id, u16 *rules_used, u16 *rules_free)
27947bd6875bSKiran Patil {
27957bd6875bSKiran Patil 	if (!(rule_type == I40E_AQC_MIRROR_RULE_TYPE_ALL_INGRESS ||
27967bd6875bSKiran Patil 	    rule_type == I40E_AQC_MIRROR_RULE_TYPE_ALL_EGRESS)) {
27977bd6875bSKiran Patil 		if (count == 0 || !mr_list)
2798230f3d53SJan Sokolowski 			return -EINVAL;
27997bd6875bSKiran Patil 	}
28007bd6875bSKiran Patil 
28017bd6875bSKiran Patil 	return i40e_mirrorrule_op(hw, i40e_aqc_opc_add_mirror_rule, sw_seid,
28027bd6875bSKiran Patil 				  rule_type, dest_vsi, count, mr_list,
28037bd6875bSKiran Patil 				  cmd_details, rule_id, rules_used, rules_free);
28047bd6875bSKiran Patil }
28057bd6875bSKiran Patil 
28067bd6875bSKiran Patil /**
28077bd6875bSKiran Patil  * i40e_aq_delete_mirrorrule - delete a mirror rule
28087bd6875bSKiran Patil  * @hw: pointer to the hw struct
28097bd6875bSKiran Patil  * @sw_seid: Switch SEID (to which rule refers)
28107bd6875bSKiran Patil  * @rule_type: Rule Type (ingress/egress/VLAN)
28117bd6875bSKiran Patil  * @count: length of the list
28127bd6875bSKiran Patil  * @rule_id: Rule ID that is returned in the receive desc as part of
28137bd6875bSKiran Patil  *		add_mirrorrule.
28147bd6875bSKiran Patil  * @mr_list: list of mirrored VLAN IDs to be removed
28157bd6875bSKiran Patil  * @cmd_details: pointer to command details structure or NULL
2816f5254429SJacob Keller  * @rules_used: Number of rules used in internal switch
2817f5254429SJacob Keller  * @rules_free: Number of rules free in internal switch
28187bd6875bSKiran Patil  *
28197bd6875bSKiran Patil  * Delete a mirror rule. Mirror rules are supported for VEBs/VEPA elements only
28207bd6875bSKiran Patil  **/
i40e_aq_delete_mirrorrule(struct i40e_hw * hw,u16 sw_seid,u16 rule_type,u16 rule_id,u16 count,__le16 * mr_list,struct i40e_asq_cmd_details * cmd_details,u16 * rules_used,u16 * rules_free)28215180ff13SJan Sokolowski int i40e_aq_delete_mirrorrule(struct i40e_hw *hw, u16 sw_seid,
28225180ff13SJan Sokolowski 			      u16 rule_type, u16 rule_id, u16 count,
28235180ff13SJan Sokolowski 			      __le16 *mr_list,
28247bd6875bSKiran Patil 			      struct i40e_asq_cmd_details *cmd_details,
28257bd6875bSKiran Patil 			      u16 *rules_used, u16 *rules_free)
28267bd6875bSKiran Patil {
28277bd6875bSKiran Patil 	/* Rule ID has to be valid except rule_type: INGRESS VLAN mirroring */
2828db077278SGreg Rose 	if (rule_type == I40E_AQC_MIRROR_RULE_TYPE_VLAN) {
28297bd6875bSKiran Patil 		/* count and mr_list shall be valid for rule_type INGRESS VLAN
28307bd6875bSKiran Patil 		 * mirroring. For other rule_type, count and rule_type should
28317bd6875bSKiran Patil 		 * not matter.
28327bd6875bSKiran Patil 		 */
28337bd6875bSKiran Patil 		if (count == 0 || !mr_list)
2834230f3d53SJan Sokolowski 			return -EINVAL;
28357bd6875bSKiran Patil 	}
28367bd6875bSKiran Patil 
28377bd6875bSKiran Patil 	return i40e_mirrorrule_op(hw, i40e_aqc_opc_delete_mirror_rule, sw_seid,
28387bd6875bSKiran Patil 				  rule_type, rule_id, count, mr_list,
28397bd6875bSKiran Patil 				  cmd_details, NULL, rules_used, rules_free);
28407bd6875bSKiran Patil }
28417bd6875bSKiran Patil 
28427bd6875bSKiran Patil /**
284356a62fc8SJesse Brandeburg  * i40e_aq_send_msg_to_vf
284456a62fc8SJesse Brandeburg  * @hw: pointer to the hardware structure
2845b40c82e6SJeff Kirsher  * @vfid: VF id to send msg
284698d44381SJeff Kirsher  * @v_opcode: opcodes for VF-PF communication
284798d44381SJeff Kirsher  * @v_retval: return error code
284856a62fc8SJesse Brandeburg  * @msg: pointer to the msg buffer
284956a62fc8SJesse Brandeburg  * @msglen: msg length
285056a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details
285156a62fc8SJesse Brandeburg  *
285256a62fc8SJesse Brandeburg  * send msg to vf
285356a62fc8SJesse Brandeburg  **/
i40e_aq_send_msg_to_vf(struct i40e_hw * hw,u16 vfid,u32 v_opcode,u32 v_retval,u8 * msg,u16 msglen,struct i40e_asq_cmd_details * cmd_details)28545180ff13SJan Sokolowski int i40e_aq_send_msg_to_vf(struct i40e_hw *hw, u16 vfid,
285556a62fc8SJesse Brandeburg 			   u32 v_opcode, u32 v_retval, u8 *msg, u16 msglen,
285656a62fc8SJesse Brandeburg 			   struct i40e_asq_cmd_details *cmd_details)
285756a62fc8SJesse Brandeburg {
285856a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
285956a62fc8SJesse Brandeburg 	struct i40e_aqc_pf_vf_message *cmd =
286056a62fc8SJesse Brandeburg 		(struct i40e_aqc_pf_vf_message *)&desc.params.raw;
28615180ff13SJan Sokolowski 	int status;
286256a62fc8SJesse Brandeburg 
286356a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_vf);
286456a62fc8SJesse Brandeburg 	cmd->id = cpu_to_le32(vfid);
286556a62fc8SJesse Brandeburg 	desc.cookie_high = cpu_to_le32(v_opcode);
286656a62fc8SJesse Brandeburg 	desc.cookie_low = cpu_to_le32(v_retval);
286756a62fc8SJesse Brandeburg 	desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_SI);
286856a62fc8SJesse Brandeburg 	if (msglen) {
286956a62fc8SJesse Brandeburg 		desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
287056a62fc8SJesse Brandeburg 						I40E_AQ_FLAG_RD));
287156a62fc8SJesse Brandeburg 		if (msglen > I40E_AQ_LARGE_BUF)
287256a62fc8SJesse Brandeburg 			desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
287356a62fc8SJesse Brandeburg 		desc.datalen = cpu_to_le16(msglen);
287456a62fc8SJesse Brandeburg 	}
287556a62fc8SJesse Brandeburg 	status = i40e_asq_send_command(hw, &desc, msg, msglen, cmd_details);
287656a62fc8SJesse Brandeburg 
287756a62fc8SJesse Brandeburg 	return status;
287856a62fc8SJesse Brandeburg }
287956a62fc8SJesse Brandeburg 
288056a62fc8SJesse Brandeburg /**
28819fee9db5SShannon Nelson  * i40e_aq_debug_read_register
28829fee9db5SShannon Nelson  * @hw: pointer to the hw struct
28839fee9db5SShannon Nelson  * @reg_addr: register address
28849fee9db5SShannon Nelson  * @reg_val: register value
28859fee9db5SShannon Nelson  * @cmd_details: pointer to command details structure or NULL
28869fee9db5SShannon Nelson  *
28879fee9db5SShannon Nelson  * Read the register using the admin queue commands
28889fee9db5SShannon Nelson  **/
i40e_aq_debug_read_register(struct i40e_hw * hw,u32 reg_addr,u64 * reg_val,struct i40e_asq_cmd_details * cmd_details)28895180ff13SJan Sokolowski int i40e_aq_debug_read_register(struct i40e_hw *hw,
28909fee9db5SShannon Nelson 				u32 reg_addr, u64 *reg_val,
28919fee9db5SShannon Nelson 				struct i40e_asq_cmd_details *cmd_details)
28929fee9db5SShannon Nelson {
28939fee9db5SShannon Nelson 	struct i40e_aq_desc desc;
28949fee9db5SShannon Nelson 	struct i40e_aqc_debug_reg_read_write *cmd_resp =
28959fee9db5SShannon Nelson 		(struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
28965180ff13SJan Sokolowski 	int status;
28979fee9db5SShannon Nelson 
28989fee9db5SShannon Nelson 	if (reg_val == NULL)
2899230f3d53SJan Sokolowski 		return -EINVAL;
29009fee9db5SShannon Nelson 
29017b115dd0SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_read_reg);
29029fee9db5SShannon Nelson 
29039fee9db5SShannon Nelson 	cmd_resp->address = cpu_to_le32(reg_addr);
29049fee9db5SShannon Nelson 
29059fee9db5SShannon Nelson 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
29069fee9db5SShannon Nelson 
29079fee9db5SShannon Nelson 	if (!status) {
29087b115dd0SJesse Brandeburg 		*reg_val = ((u64)le32_to_cpu(cmd_resp->value_high) << 32) |
29097b115dd0SJesse Brandeburg 			   (u64)le32_to_cpu(cmd_resp->value_low);
29109fee9db5SShannon Nelson 	}
29119fee9db5SShannon Nelson 
29129fee9db5SShannon Nelson 	return status;
29139fee9db5SShannon Nelson }
29149fee9db5SShannon Nelson 
29159fee9db5SShannon Nelson /**
291653db45cdSShannon Nelson  * i40e_aq_debug_write_register
291753db45cdSShannon Nelson  * @hw: pointer to the hw struct
291853db45cdSShannon Nelson  * @reg_addr: register address
291953db45cdSShannon Nelson  * @reg_val: register value
292053db45cdSShannon Nelson  * @cmd_details: pointer to command details structure or NULL
292153db45cdSShannon Nelson  *
292253db45cdSShannon Nelson  * Write to a register using the admin queue commands
292353db45cdSShannon Nelson  **/
i40e_aq_debug_write_register(struct i40e_hw * hw,u32 reg_addr,u64 reg_val,struct i40e_asq_cmd_details * cmd_details)29245180ff13SJan Sokolowski int i40e_aq_debug_write_register(struct i40e_hw *hw,
292553db45cdSShannon Nelson 				 u32 reg_addr, u64 reg_val,
292653db45cdSShannon Nelson 				 struct i40e_asq_cmd_details *cmd_details)
292753db45cdSShannon Nelson {
292853db45cdSShannon Nelson 	struct i40e_aq_desc desc;
292953db45cdSShannon Nelson 	struct i40e_aqc_debug_reg_read_write *cmd =
293053db45cdSShannon Nelson 		(struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
29315180ff13SJan Sokolowski 	int status;
293253db45cdSShannon Nelson 
293353db45cdSShannon Nelson 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_write_reg);
293453db45cdSShannon Nelson 
293553db45cdSShannon Nelson 	cmd->address = cpu_to_le32(reg_addr);
293653db45cdSShannon Nelson 	cmd->value_high = cpu_to_le32((u32)(reg_val >> 32));
293753db45cdSShannon Nelson 	cmd->value_low = cpu_to_le32((u32)(reg_val & 0xFFFFFFFF));
293853db45cdSShannon Nelson 
293953db45cdSShannon Nelson 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
294053db45cdSShannon Nelson 
294153db45cdSShannon Nelson 	return status;
294253db45cdSShannon Nelson }
294353db45cdSShannon Nelson 
294453db45cdSShannon Nelson /**
294556a62fc8SJesse Brandeburg  * i40e_aq_request_resource
294656a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
294756a62fc8SJesse Brandeburg  * @resource: resource id
294856a62fc8SJesse Brandeburg  * @access: access type
294956a62fc8SJesse Brandeburg  * @sdp_number: resource number
295056a62fc8SJesse Brandeburg  * @timeout: the maximum time in ms that the driver may hold the resource
295156a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
295256a62fc8SJesse Brandeburg  *
295356a62fc8SJesse Brandeburg  * requests common resource using the admin queue commands
295456a62fc8SJesse Brandeburg  **/
i40e_aq_request_resource(struct i40e_hw * hw,enum i40e_aq_resources_ids resource,enum i40e_aq_resource_access_type access,u8 sdp_number,u64 * timeout,struct i40e_asq_cmd_details * cmd_details)29555180ff13SJan Sokolowski int i40e_aq_request_resource(struct i40e_hw *hw,
295656a62fc8SJesse Brandeburg 			     enum i40e_aq_resources_ids resource,
295756a62fc8SJesse Brandeburg 			     enum i40e_aq_resource_access_type access,
295856a62fc8SJesse Brandeburg 			     u8 sdp_number, u64 *timeout,
295956a62fc8SJesse Brandeburg 			     struct i40e_asq_cmd_details *cmd_details)
296056a62fc8SJesse Brandeburg {
296156a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
296256a62fc8SJesse Brandeburg 	struct i40e_aqc_request_resource *cmd_resp =
296356a62fc8SJesse Brandeburg 		(struct i40e_aqc_request_resource *)&desc.params.raw;
29645180ff13SJan Sokolowski 	int status;
296556a62fc8SJesse Brandeburg 
296656a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_request_resource);
296756a62fc8SJesse Brandeburg 
296856a62fc8SJesse Brandeburg 	cmd_resp->resource_id = cpu_to_le16(resource);
296956a62fc8SJesse Brandeburg 	cmd_resp->access_type = cpu_to_le16(access);
297056a62fc8SJesse Brandeburg 	cmd_resp->resource_number = cpu_to_le32(sdp_number);
297156a62fc8SJesse Brandeburg 
297256a62fc8SJesse Brandeburg 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
297356a62fc8SJesse Brandeburg 	/* The completion specifies the maximum time in ms that the driver
297456a62fc8SJesse Brandeburg 	 * may hold the resource in the Timeout field.
297556a62fc8SJesse Brandeburg 	 * If the resource is held by someone else, the command completes with
297656a62fc8SJesse Brandeburg 	 * busy return value and the timeout field indicates the maximum time
297756a62fc8SJesse Brandeburg 	 * the current owner of the resource has to free it.
297856a62fc8SJesse Brandeburg 	 */
297956a62fc8SJesse Brandeburg 	if (!status || hw->aq.asq_last_status == I40E_AQ_RC_EBUSY)
298056a62fc8SJesse Brandeburg 		*timeout = le32_to_cpu(cmd_resp->timeout);
298156a62fc8SJesse Brandeburg 
298256a62fc8SJesse Brandeburg 	return status;
298356a62fc8SJesse Brandeburg }
298456a62fc8SJesse Brandeburg 
298556a62fc8SJesse Brandeburg /**
298656a62fc8SJesse Brandeburg  * i40e_aq_release_resource
298756a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
298856a62fc8SJesse Brandeburg  * @resource: resource id
298956a62fc8SJesse Brandeburg  * @sdp_number: resource number
299056a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
299156a62fc8SJesse Brandeburg  *
299256a62fc8SJesse Brandeburg  * release common resource using the admin queue commands
299356a62fc8SJesse Brandeburg  **/
i40e_aq_release_resource(struct i40e_hw * hw,enum i40e_aq_resources_ids resource,u8 sdp_number,struct i40e_asq_cmd_details * cmd_details)29945180ff13SJan Sokolowski int i40e_aq_release_resource(struct i40e_hw *hw,
299556a62fc8SJesse Brandeburg 			     enum i40e_aq_resources_ids resource,
299656a62fc8SJesse Brandeburg 			     u8 sdp_number,
299756a62fc8SJesse Brandeburg 			     struct i40e_asq_cmd_details *cmd_details)
299856a62fc8SJesse Brandeburg {
299956a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
300056a62fc8SJesse Brandeburg 	struct i40e_aqc_request_resource *cmd =
300156a62fc8SJesse Brandeburg 		(struct i40e_aqc_request_resource *)&desc.params.raw;
30025180ff13SJan Sokolowski 	int status;
300356a62fc8SJesse Brandeburg 
300456a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_release_resource);
300556a62fc8SJesse Brandeburg 
300656a62fc8SJesse Brandeburg 	cmd->resource_id = cpu_to_le16(resource);
300756a62fc8SJesse Brandeburg 	cmd->resource_number = cpu_to_le32(sdp_number);
300856a62fc8SJesse Brandeburg 
300956a62fc8SJesse Brandeburg 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
301056a62fc8SJesse Brandeburg 
301156a62fc8SJesse Brandeburg 	return status;
301256a62fc8SJesse Brandeburg }
301356a62fc8SJesse Brandeburg 
301456a62fc8SJesse Brandeburg /**
301556a62fc8SJesse Brandeburg  * i40e_aq_read_nvm
301656a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
301756a62fc8SJesse Brandeburg  * @module_pointer: module pointer location in words from the NVM beginning
301856a62fc8SJesse Brandeburg  * @offset: byte offset from the module beginning
301956a62fc8SJesse Brandeburg  * @length: length of the section to be read (in bytes from the offset)
302056a62fc8SJesse Brandeburg  * @data: command buffer (size [bytes] = length)
302156a62fc8SJesse Brandeburg  * @last_command: tells if this is the last command in a series
302256a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
302356a62fc8SJesse Brandeburg  *
302456a62fc8SJesse Brandeburg  * Read the NVM using the admin queue commands
302556a62fc8SJesse Brandeburg  **/
i40e_aq_read_nvm(struct i40e_hw * hw,u8 module_pointer,u32 offset,u16 length,void * data,bool last_command,struct i40e_asq_cmd_details * cmd_details)30265180ff13SJan Sokolowski int i40e_aq_read_nvm(struct i40e_hw *hw, u8 module_pointer,
302756a62fc8SJesse Brandeburg 		     u32 offset, u16 length, void *data,
302856a62fc8SJesse Brandeburg 		     bool last_command,
302956a62fc8SJesse Brandeburg 		     struct i40e_asq_cmd_details *cmd_details)
303056a62fc8SJesse Brandeburg {
303156a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
303256a62fc8SJesse Brandeburg 	struct i40e_aqc_nvm_update *cmd =
303356a62fc8SJesse Brandeburg 		(struct i40e_aqc_nvm_update *)&desc.params.raw;
30345180ff13SJan Sokolowski 	int status;
303556a62fc8SJesse Brandeburg 
303656a62fc8SJesse Brandeburg 	/* In offset the highest byte must be zeroed. */
303756a62fc8SJesse Brandeburg 	if (offset & 0xFF000000) {
3038230f3d53SJan Sokolowski 		status = -EINVAL;
303956a62fc8SJesse Brandeburg 		goto i40e_aq_read_nvm_exit;
304056a62fc8SJesse Brandeburg 	}
304156a62fc8SJesse Brandeburg 
304256a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_read);
304356a62fc8SJesse Brandeburg 
304456a62fc8SJesse Brandeburg 	/* If this is the last command in a series, set the proper flag. */
304556a62fc8SJesse Brandeburg 	if (last_command)
304656a62fc8SJesse Brandeburg 		cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
304756a62fc8SJesse Brandeburg 	cmd->module_pointer = module_pointer;
304856a62fc8SJesse Brandeburg 	cmd->offset = cpu_to_le32(offset);
304956a62fc8SJesse Brandeburg 	cmd->length = cpu_to_le16(length);
305056a62fc8SJesse Brandeburg 
305156a62fc8SJesse Brandeburg 	desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
305256a62fc8SJesse Brandeburg 	if (length > I40E_AQ_LARGE_BUF)
305356a62fc8SJesse Brandeburg 		desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
305456a62fc8SJesse Brandeburg 
305556a62fc8SJesse Brandeburg 	status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
305656a62fc8SJesse Brandeburg 
305756a62fc8SJesse Brandeburg i40e_aq_read_nvm_exit:
305856a62fc8SJesse Brandeburg 	return status;
305956a62fc8SJesse Brandeburg }
306056a62fc8SJesse Brandeburg 
3061cd552cb4SShannon Nelson /**
3062cd552cb4SShannon Nelson  * i40e_aq_erase_nvm
3063cd552cb4SShannon Nelson  * @hw: pointer to the hw struct
3064cd552cb4SShannon Nelson  * @module_pointer: module pointer location in words from the NVM beginning
3065cd552cb4SShannon Nelson  * @offset: offset in the module (expressed in 4 KB from module's beginning)
3066cd552cb4SShannon Nelson  * @length: length of the section to be erased (expressed in 4 KB)
3067cd552cb4SShannon Nelson  * @last_command: tells if this is the last command in a series
3068cd552cb4SShannon Nelson  * @cmd_details: pointer to command details structure or NULL
3069cd552cb4SShannon Nelson  *
3070cd552cb4SShannon Nelson  * Erase the NVM sector using the admin queue commands
3071cd552cb4SShannon Nelson  **/
i40e_aq_erase_nvm(struct i40e_hw * hw,u8 module_pointer,u32 offset,u16 length,bool last_command,struct i40e_asq_cmd_details * cmd_details)30725180ff13SJan Sokolowski int i40e_aq_erase_nvm(struct i40e_hw *hw, u8 module_pointer,
3073cd552cb4SShannon Nelson 		      u32 offset, u16 length, bool last_command,
3074cd552cb4SShannon Nelson 		      struct i40e_asq_cmd_details *cmd_details)
3075cd552cb4SShannon Nelson {
3076cd552cb4SShannon Nelson 	struct i40e_aq_desc desc;
3077cd552cb4SShannon Nelson 	struct i40e_aqc_nvm_update *cmd =
3078cd552cb4SShannon Nelson 		(struct i40e_aqc_nvm_update *)&desc.params.raw;
30795180ff13SJan Sokolowski 	int status;
3080cd552cb4SShannon Nelson 
3081cd552cb4SShannon Nelson 	/* In offset the highest byte must be zeroed. */
3082cd552cb4SShannon Nelson 	if (offset & 0xFF000000) {
3083230f3d53SJan Sokolowski 		status = -EINVAL;
3084cd552cb4SShannon Nelson 		goto i40e_aq_erase_nvm_exit;
3085cd552cb4SShannon Nelson 	}
3086cd552cb4SShannon Nelson 
3087cd552cb4SShannon Nelson 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_erase);
3088cd552cb4SShannon Nelson 
3089cd552cb4SShannon Nelson 	/* If this is the last command in a series, set the proper flag. */
3090cd552cb4SShannon Nelson 	if (last_command)
3091cd552cb4SShannon Nelson 		cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
3092cd552cb4SShannon Nelson 	cmd->module_pointer = module_pointer;
3093cd552cb4SShannon Nelson 	cmd->offset = cpu_to_le32(offset);
3094cd552cb4SShannon Nelson 	cmd->length = cpu_to_le16(length);
3095cd552cb4SShannon Nelson 
3096cd552cb4SShannon Nelson 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3097cd552cb4SShannon Nelson 
3098cd552cb4SShannon Nelson i40e_aq_erase_nvm_exit:
3099cd552cb4SShannon Nelson 	return status;
3100cd552cb4SShannon Nelson }
3101cd552cb4SShannon Nelson 
310256a62fc8SJesse Brandeburg /**
310356a62fc8SJesse Brandeburg  * i40e_parse_discover_capabilities
310456a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
310556a62fc8SJesse Brandeburg  * @buff: pointer to a buffer containing device/function capability records
310656a62fc8SJesse Brandeburg  * @cap_count: number of capability records in the list
310756a62fc8SJesse Brandeburg  * @list_type_opc: type of capabilities list to parse
310856a62fc8SJesse Brandeburg  *
310956a62fc8SJesse Brandeburg  * Parse the device/function capabilities list.
311056a62fc8SJesse Brandeburg  **/
i40e_parse_discover_capabilities(struct i40e_hw * hw,void * buff,u32 cap_count,enum i40e_admin_queue_opc list_type_opc)311156a62fc8SJesse Brandeburg static void i40e_parse_discover_capabilities(struct i40e_hw *hw, void *buff,
311256a62fc8SJesse Brandeburg 				     u32 cap_count,
311356a62fc8SJesse Brandeburg 				     enum i40e_admin_queue_opc list_type_opc)
311456a62fc8SJesse Brandeburg {
311556a62fc8SJesse Brandeburg 	struct i40e_aqc_list_capabilities_element_resp *cap;
31169fee9db5SShannon Nelson 	u32 valid_functions, num_functions;
311756a62fc8SJesse Brandeburg 	u32 number, logical_id, phys_id;
311856a62fc8SJesse Brandeburg 	struct i40e_hw_capabilities *p;
3119bc2a3a6cSMariusz Stachura 	u16 id, ocp_cfg_word0;
3120c78b953eSPawel Orlowski 	u8 major_rev;
31215180ff13SJan Sokolowski 	int status;
312256a62fc8SJesse Brandeburg 	u32 i = 0;
312356a62fc8SJesse Brandeburg 
312456a62fc8SJesse Brandeburg 	cap = (struct i40e_aqc_list_capabilities_element_resp *) buff;
312556a62fc8SJesse Brandeburg 
312656a62fc8SJesse Brandeburg 	if (list_type_opc == i40e_aqc_opc_list_dev_capabilities)
3127b58f2f72SJoe Perches 		p = &hw->dev_caps;
312856a62fc8SJesse Brandeburg 	else if (list_type_opc == i40e_aqc_opc_list_func_capabilities)
3129b58f2f72SJoe Perches 		p = &hw->func_caps;
313056a62fc8SJesse Brandeburg 	else
313156a62fc8SJesse Brandeburg 		return;
313256a62fc8SJesse Brandeburg 
313356a62fc8SJesse Brandeburg 	for (i = 0; i < cap_count; i++, cap++) {
313456a62fc8SJesse Brandeburg 		id = le16_to_cpu(cap->id);
313556a62fc8SJesse Brandeburg 		number = le32_to_cpu(cap->number);
313656a62fc8SJesse Brandeburg 		logical_id = le32_to_cpu(cap->logical_id);
313756a62fc8SJesse Brandeburg 		phys_id = le32_to_cpu(cap->phys_id);
3138c78b953eSPawel Orlowski 		major_rev = cap->major_rev;
313956a62fc8SJesse Brandeburg 
314056a62fc8SJesse Brandeburg 		switch (id) {
3141406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_SWITCH_MODE:
314256a62fc8SJesse Brandeburg 			p->switch_mode = number;
314356a62fc8SJesse Brandeburg 			break;
3144406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_MNG_MODE:
314556a62fc8SJesse Brandeburg 			p->management_mode = number;
314664f5ead9SPiotr Raczynski 			if (major_rev > 1) {
314764f5ead9SPiotr Raczynski 				p->mng_protocols_over_mctp = logical_id;
314864f5ead9SPiotr Raczynski 				i40e_debug(hw, I40E_DEBUG_INIT,
314964f5ead9SPiotr Raczynski 					   "HW Capability: Protocols over MCTP = %d\n",
315064f5ead9SPiotr Raczynski 					   p->mng_protocols_over_mctp);
315164f5ead9SPiotr Raczynski 			} else {
315264f5ead9SPiotr Raczynski 				p->mng_protocols_over_mctp = 0;
315364f5ead9SPiotr Raczynski 			}
315456a62fc8SJesse Brandeburg 			break;
3155406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_NPAR_ACTIVE:
315656a62fc8SJesse Brandeburg 			p->npar_enable = number;
315756a62fc8SJesse Brandeburg 			break;
3158406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_OS2BMC_CAP:
315956a62fc8SJesse Brandeburg 			p->os2bmc = number;
316056a62fc8SJesse Brandeburg 			break;
3161406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_FUNCTIONS_VALID:
316256a62fc8SJesse Brandeburg 			p->valid_functions = number;
316356a62fc8SJesse Brandeburg 			break;
3164406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_SRIOV:
316556a62fc8SJesse Brandeburg 			if (number == 1)
316656a62fc8SJesse Brandeburg 				p->sr_iov_1_1 = true;
316756a62fc8SJesse Brandeburg 			break;
3168406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_VF:
316956a62fc8SJesse Brandeburg 			p->num_vfs = number;
317056a62fc8SJesse Brandeburg 			p->vf_base_id = logical_id;
317156a62fc8SJesse Brandeburg 			break;
3172406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_VMDQ:
317356a62fc8SJesse Brandeburg 			if (number == 1)
317456a62fc8SJesse Brandeburg 				p->vmdq = true;
317556a62fc8SJesse Brandeburg 			break;
3176406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_8021QBG:
317756a62fc8SJesse Brandeburg 			if (number == 1)
317856a62fc8SJesse Brandeburg 				p->evb_802_1_qbg = true;
317956a62fc8SJesse Brandeburg 			break;
3180406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_8021QBR:
318156a62fc8SJesse Brandeburg 			if (number == 1)
318256a62fc8SJesse Brandeburg 				p->evb_802_1_qbh = true;
318356a62fc8SJesse Brandeburg 			break;
3184406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_VSI:
318556a62fc8SJesse Brandeburg 			p->num_vsis = number;
318656a62fc8SJesse Brandeburg 			break;
3187406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_DCB:
318856a62fc8SJesse Brandeburg 			if (number == 1) {
318956a62fc8SJesse Brandeburg 				p->dcb = true;
319056a62fc8SJesse Brandeburg 				p->enabled_tcmap = logical_id;
319156a62fc8SJesse Brandeburg 				p->maxtc = phys_id;
319256a62fc8SJesse Brandeburg 			}
319356a62fc8SJesse Brandeburg 			break;
3194406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_FCOE:
319556a62fc8SJesse Brandeburg 			if (number == 1)
319656a62fc8SJesse Brandeburg 				p->fcoe = true;
319756a62fc8SJesse Brandeburg 			break;
3198406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_ISCSI:
319963d7e5a4SNeerav Parikh 			if (number == 1)
320063d7e5a4SNeerav Parikh 				p->iscsi = true;
320163d7e5a4SNeerav Parikh 			break;
3202406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_RSS:
320356a62fc8SJesse Brandeburg 			p->rss = true;
320456a62fc8SJesse Brandeburg 			p->rss_table_size = number;
320556a62fc8SJesse Brandeburg 			p->rss_table_entry_width = logical_id;
320656a62fc8SJesse Brandeburg 			break;
3207406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_RXQ:
320856a62fc8SJesse Brandeburg 			p->num_rx_qp = number;
320956a62fc8SJesse Brandeburg 			p->base_queue = phys_id;
321056a62fc8SJesse Brandeburg 			break;
3211406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_TXQ:
321256a62fc8SJesse Brandeburg 			p->num_tx_qp = number;
321356a62fc8SJesse Brandeburg 			p->base_queue = phys_id;
321456a62fc8SJesse Brandeburg 			break;
3215406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_MSIX:
321656a62fc8SJesse Brandeburg 			p->num_msix_vectors = number;
3217453e16e8SDeepthi Kavalur 			i40e_debug(hw, I40E_DEBUG_INIT,
3218453e16e8SDeepthi Kavalur 				   "HW Capability: MSIX vector count = %d\n",
3219453e16e8SDeepthi Kavalur 				   p->num_msix_vectors);
322056a62fc8SJesse Brandeburg 			break;
3221406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_VF_MSIX:
322256a62fc8SJesse Brandeburg 			p->num_msix_vectors_vf = number;
322356a62fc8SJesse Brandeburg 			break;
3224406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_FLEX10:
3225c78b953eSPawel Orlowski 			if (major_rev == 1) {
3226c78b953eSPawel Orlowski 				if (number == 1) {
3227c78b953eSPawel Orlowski 					p->flex10_enable = true;
3228c78b953eSPawel Orlowski 					p->flex10_capable = true;
3229c78b953eSPawel Orlowski 				}
3230c78b953eSPawel Orlowski 			} else {
3231c78b953eSPawel Orlowski 				/* Capability revision >= 2 */
3232c78b953eSPawel Orlowski 				if (number & 1)
3233c78b953eSPawel Orlowski 					p->flex10_enable = true;
3234c78b953eSPawel Orlowski 				if (number & 2)
3235c78b953eSPawel Orlowski 					p->flex10_capable = true;
3236c78b953eSPawel Orlowski 			}
3237c78b953eSPawel Orlowski 			p->flex10_mode = logical_id;
3238c78b953eSPawel Orlowski 			p->flex10_status = phys_id;
323956a62fc8SJesse Brandeburg 			break;
3240406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_CEM:
324156a62fc8SJesse Brandeburg 			if (number == 1)
324256a62fc8SJesse Brandeburg 				p->mgmt_cem = true;
324356a62fc8SJesse Brandeburg 			break;
3244406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_IWARP:
324556a62fc8SJesse Brandeburg 			if (number == 1)
324656a62fc8SJesse Brandeburg 				p->iwarp = true;
324756a62fc8SJesse Brandeburg 			break;
3248406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_LED:
324956a62fc8SJesse Brandeburg 			if (phys_id < I40E_HW_CAP_MAX_GPIO)
325056a62fc8SJesse Brandeburg 				p->led[phys_id] = true;
325156a62fc8SJesse Brandeburg 			break;
3252406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_SDP:
325356a62fc8SJesse Brandeburg 			if (phys_id < I40E_HW_CAP_MAX_GPIO)
325456a62fc8SJesse Brandeburg 				p->sdp[phys_id] = true;
325556a62fc8SJesse Brandeburg 			break;
3256406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_MDIO:
325756a62fc8SJesse Brandeburg 			if (number == 1) {
325856a62fc8SJesse Brandeburg 				p->mdio_port_num = phys_id;
325956a62fc8SJesse Brandeburg 				p->mdio_port_mode = logical_id;
326056a62fc8SJesse Brandeburg 			}
326156a62fc8SJesse Brandeburg 			break;
3262406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_1588:
326356a62fc8SJesse Brandeburg 			if (number == 1)
326456a62fc8SJesse Brandeburg 				p->ieee_1588 = true;
326556a62fc8SJesse Brandeburg 			break;
3266406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_FLOW_DIRECTOR:
326756a62fc8SJesse Brandeburg 			p->fd = true;
326856a62fc8SJesse Brandeburg 			p->fd_filters_guaranteed = number;
326956a62fc8SJesse Brandeburg 			p->fd_filters_best_effort = logical_id;
327056a62fc8SJesse Brandeburg 			break;
3271406e734aSShannon Nelson 		case I40E_AQ_CAP_ID_WSR_PROT:
327273b23402SKevin Scott 			p->wr_csr_prot = (u64)number;
327373b23402SKevin Scott 			p->wr_csr_prot |= (u64)logical_id << 32;
327473b23402SKevin Scott 			break;
327568a1c5a7SMichal Kosiarz 		case I40E_AQ_CAP_ID_NVM_MGMT:
327668a1c5a7SMichal Kosiarz 			if (number & I40E_NVM_MGMT_SEC_REV_DISABLED)
327768a1c5a7SMichal Kosiarz 				p->sec_rev_disabled = true;
327868a1c5a7SMichal Kosiarz 			if (number & I40E_NVM_MGMT_UPDATE_DISABLED)
327968a1c5a7SMichal Kosiarz 				p->update_disabled = true;
328068a1c5a7SMichal Kosiarz 			break;
328156a62fc8SJesse Brandeburg 		default:
328256a62fc8SJesse Brandeburg 			break;
328356a62fc8SJesse Brandeburg 		}
328456a62fc8SJesse Brandeburg 	}
328556a62fc8SJesse Brandeburg 
3286f18ae100SVasu Dev 	if (p->fcoe)
3287f18ae100SVasu Dev 		i40e_debug(hw, I40E_DEBUG_ALL, "device is FCoE capable\n");
3288f18ae100SVasu Dev 
3289566bb85dSVasu Dev 	/* Software override ensuring FCoE is disabled if npar or mfp
3290566bb85dSVasu Dev 	 * mode because it is not supported in these modes.
3291566bb85dSVasu Dev 	 */
3292c78b953eSPawel Orlowski 	if (p->npar_enable || p->flex10_enable)
3293566bb85dSVasu Dev 		p->fcoe = false;
3294566bb85dSVasu Dev 
32959fee9db5SShannon Nelson 	/* count the enabled ports (aka the "not disabled" ports) */
32969fee9db5SShannon Nelson 	hw->num_ports = 0;
32979fee9db5SShannon Nelson 	for (i = 0; i < 4; i++) {
32989fee9db5SShannon Nelson 		u32 port_cfg_reg = I40E_PRTGEN_CNF + (4 * i);
32999fee9db5SShannon Nelson 		u64 port_cfg = 0;
33009fee9db5SShannon Nelson 
33019fee9db5SShannon Nelson 		/* use AQ read to get the physical register offset instead
33029fee9db5SShannon Nelson 		 * of the port relative offset
33039fee9db5SShannon Nelson 		 */
33049fee9db5SShannon Nelson 		i40e_aq_debug_read_register(hw, port_cfg_reg, &port_cfg, NULL);
33059fee9db5SShannon Nelson 		if (!(port_cfg & I40E_PRTGEN_CNF_PORT_DIS_MASK))
33069fee9db5SShannon Nelson 			hw->num_ports++;
33079fee9db5SShannon Nelson 	}
33089fee9db5SShannon Nelson 
3309bc2a3a6cSMariusz Stachura 	/* OCP cards case: if a mezz is removed the Ethernet port is at
3310bc2a3a6cSMariusz Stachura 	 * disabled state in PRTGEN_CNF register. Additional NVM read is
3311bc2a3a6cSMariusz Stachura 	 * needed in order to check if we are dealing with OCP card.
3312bc2a3a6cSMariusz Stachura 	 * Those cards have 4 PFs at minimum, so using PRTGEN_CNF for counting
3313bc2a3a6cSMariusz Stachura 	 * physical ports results in wrong partition id calculation and thus
3314bc2a3a6cSMariusz Stachura 	 * not supporting WoL.
3315bc2a3a6cSMariusz Stachura 	 */
3316bc2a3a6cSMariusz Stachura 	if (hw->mac.type == I40E_MAC_X722) {
3317bc2a3a6cSMariusz Stachura 		if (!i40e_acquire_nvm(hw, I40E_RESOURCE_READ)) {
3318bc2a3a6cSMariusz Stachura 			status = i40e_aq_read_nvm(hw, I40E_SR_EMP_MODULE_PTR,
3319bc2a3a6cSMariusz Stachura 						  2 * I40E_SR_OCP_CFG_WORD0,
3320bc2a3a6cSMariusz Stachura 						  sizeof(ocp_cfg_word0),
3321bc2a3a6cSMariusz Stachura 						  &ocp_cfg_word0, true, NULL);
3322bc2a3a6cSMariusz Stachura 			if (!status &&
3323bc2a3a6cSMariusz Stachura 			    (ocp_cfg_word0 & I40E_SR_OCP_ENABLED))
3324bc2a3a6cSMariusz Stachura 				hw->num_ports = 4;
3325bc2a3a6cSMariusz Stachura 			i40e_release_nvm(hw);
3326bc2a3a6cSMariusz Stachura 		}
3327bc2a3a6cSMariusz Stachura 	}
3328bc2a3a6cSMariusz Stachura 
33299fee9db5SShannon Nelson 	valid_functions = p->valid_functions;
33309fee9db5SShannon Nelson 	num_functions = 0;
33319fee9db5SShannon Nelson 	while (valid_functions) {
33329fee9db5SShannon Nelson 		if (valid_functions & 1)
33339fee9db5SShannon Nelson 			num_functions++;
33349fee9db5SShannon Nelson 		valid_functions >>= 1;
33359fee9db5SShannon Nelson 	}
33369fee9db5SShannon Nelson 
33379fee9db5SShannon Nelson 	/* partition id is 1-based, and functions are evenly spread
33389fee9db5SShannon Nelson 	 * across the ports as partitions
33399fee9db5SShannon Nelson 	 */
3340999b315dSMichal Kosiarz 	if (hw->num_ports != 0) {
33419fee9db5SShannon Nelson 		hw->partition_id = (hw->pf_id / hw->num_ports) + 1;
33429fee9db5SShannon Nelson 		hw->num_partitions = num_functions / hw->num_ports;
3343999b315dSMichal Kosiarz 	}
33449fee9db5SShannon Nelson 
334556a62fc8SJesse Brandeburg 	/* additional HW specific goodies that might
334656a62fc8SJesse Brandeburg 	 * someday be HW version specific
334756a62fc8SJesse Brandeburg 	 */
334856a62fc8SJesse Brandeburg 	p->rx_buf_chain_len = I40E_MAX_CHAINED_RX_BUFFERS;
334956a62fc8SJesse Brandeburg }
335056a62fc8SJesse Brandeburg 
335156a62fc8SJesse Brandeburg /**
335256a62fc8SJesse Brandeburg  * i40e_aq_discover_capabilities
335356a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
335456a62fc8SJesse Brandeburg  * @buff: a virtual buffer to hold the capabilities
335556a62fc8SJesse Brandeburg  * @buff_size: Size of the virtual buffer
335656a62fc8SJesse Brandeburg  * @data_size: Size of the returned data, or buff size needed if AQ err==ENOMEM
335756a62fc8SJesse Brandeburg  * @list_type_opc: capabilities type to discover - pass in the command opcode
335856a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
335956a62fc8SJesse Brandeburg  *
336056a62fc8SJesse Brandeburg  * Get the device capabilities descriptions from the firmware
336156a62fc8SJesse Brandeburg  **/
i40e_aq_discover_capabilities(struct i40e_hw * hw,void * buff,u16 buff_size,u16 * data_size,enum i40e_admin_queue_opc list_type_opc,struct i40e_asq_cmd_details * cmd_details)33625180ff13SJan Sokolowski int i40e_aq_discover_capabilities(struct i40e_hw *hw,
336356a62fc8SJesse Brandeburg 				  void *buff, u16 buff_size, u16 *data_size,
336456a62fc8SJesse Brandeburg 				  enum i40e_admin_queue_opc list_type_opc,
336556a62fc8SJesse Brandeburg 				  struct i40e_asq_cmd_details *cmd_details)
336656a62fc8SJesse Brandeburg {
336756a62fc8SJesse Brandeburg 	struct i40e_aqc_list_capabilites *cmd;
336856a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
33695180ff13SJan Sokolowski 	int status = 0;
337056a62fc8SJesse Brandeburg 
337156a62fc8SJesse Brandeburg 	cmd = (struct i40e_aqc_list_capabilites *)&desc.params.raw;
337256a62fc8SJesse Brandeburg 
337356a62fc8SJesse Brandeburg 	if (list_type_opc != i40e_aqc_opc_list_func_capabilities &&
337456a62fc8SJesse Brandeburg 		list_type_opc != i40e_aqc_opc_list_dev_capabilities) {
3375230f3d53SJan Sokolowski 		status = -EINVAL;
337656a62fc8SJesse Brandeburg 		goto exit;
337756a62fc8SJesse Brandeburg 	}
337856a62fc8SJesse Brandeburg 
337956a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc, list_type_opc);
338056a62fc8SJesse Brandeburg 
338156a62fc8SJesse Brandeburg 	desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
338256a62fc8SJesse Brandeburg 	if (buff_size > I40E_AQ_LARGE_BUF)
338356a62fc8SJesse Brandeburg 		desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
338456a62fc8SJesse Brandeburg 
338556a62fc8SJesse Brandeburg 	status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
338656a62fc8SJesse Brandeburg 	*data_size = le16_to_cpu(desc.datalen);
338756a62fc8SJesse Brandeburg 
338856a62fc8SJesse Brandeburg 	if (status)
338956a62fc8SJesse Brandeburg 		goto exit;
339056a62fc8SJesse Brandeburg 
339156a62fc8SJesse Brandeburg 	i40e_parse_discover_capabilities(hw, buff, le32_to_cpu(cmd->count),
339256a62fc8SJesse Brandeburg 					 list_type_opc);
339356a62fc8SJesse Brandeburg 
339456a62fc8SJesse Brandeburg exit:
339556a62fc8SJesse Brandeburg 	return status;
339656a62fc8SJesse Brandeburg }
339756a62fc8SJesse Brandeburg 
339856a62fc8SJesse Brandeburg /**
3399cd552cb4SShannon Nelson  * i40e_aq_update_nvm
3400cd552cb4SShannon Nelson  * @hw: pointer to the hw struct
3401cd552cb4SShannon Nelson  * @module_pointer: module pointer location in words from the NVM beginning
3402cd552cb4SShannon Nelson  * @offset: byte offset from the module beginning
3403cd552cb4SShannon Nelson  * @length: length of the section to be written (in bytes from the offset)
3404cd552cb4SShannon Nelson  * @data: command buffer (size [bytes] = length)
3405cd552cb4SShannon Nelson  * @last_command: tells if this is the last command in a series
3406e3a5d6e6SPawel Jablonski  * @preservation_flags: Preservation mode flags
3407cd552cb4SShannon Nelson  * @cmd_details: pointer to command details structure or NULL
3408cd552cb4SShannon Nelson  *
3409cd552cb4SShannon Nelson  * Update the NVM using the admin queue commands
3410cd552cb4SShannon Nelson  **/
i40e_aq_update_nvm(struct i40e_hw * hw,u8 module_pointer,u32 offset,u16 length,void * data,bool last_command,u8 preservation_flags,struct i40e_asq_cmd_details * cmd_details)34115180ff13SJan Sokolowski int i40e_aq_update_nvm(struct i40e_hw *hw, u8 module_pointer,
3412cd552cb4SShannon Nelson 		       u32 offset, u16 length, void *data,
3413e3a5d6e6SPawel Jablonski 		       bool last_command, u8 preservation_flags,
3414cd552cb4SShannon Nelson 		       struct i40e_asq_cmd_details *cmd_details)
3415cd552cb4SShannon Nelson {
3416cd552cb4SShannon Nelson 	struct i40e_aq_desc desc;
3417cd552cb4SShannon Nelson 	struct i40e_aqc_nvm_update *cmd =
3418cd552cb4SShannon Nelson 		(struct i40e_aqc_nvm_update *)&desc.params.raw;
34195180ff13SJan Sokolowski 	int status;
3420cd552cb4SShannon Nelson 
3421cd552cb4SShannon Nelson 	/* In offset the highest byte must be zeroed. */
3422cd552cb4SShannon Nelson 	if (offset & 0xFF000000) {
3423230f3d53SJan Sokolowski 		status = -EINVAL;
3424cd552cb4SShannon Nelson 		goto i40e_aq_update_nvm_exit;
3425cd552cb4SShannon Nelson 	}
3426cd552cb4SShannon Nelson 
3427cd552cb4SShannon Nelson 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_update);
3428cd552cb4SShannon Nelson 
3429cd552cb4SShannon Nelson 	/* If this is the last command in a series, set the proper flag. */
3430cd552cb4SShannon Nelson 	if (last_command)
3431cd552cb4SShannon Nelson 		cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
3432e3a5d6e6SPawel Jablonski 	if (hw->mac.type == I40E_MAC_X722) {
3433e3a5d6e6SPawel Jablonski 		if (preservation_flags == I40E_NVM_PRESERVATION_FLAGS_SELECTED)
3434e3a5d6e6SPawel Jablonski 			cmd->command_flags |=
3435e3a5d6e6SPawel Jablonski 				(I40E_AQ_NVM_PRESERVATION_FLAGS_SELECTED <<
3436e3a5d6e6SPawel Jablonski 				 I40E_AQ_NVM_PRESERVATION_FLAGS_SHIFT);
3437e3a5d6e6SPawel Jablonski 		else if (preservation_flags == I40E_NVM_PRESERVATION_FLAGS_ALL)
3438e3a5d6e6SPawel Jablonski 			cmd->command_flags |=
3439e3a5d6e6SPawel Jablonski 				(I40E_AQ_NVM_PRESERVATION_FLAGS_ALL <<
3440e3a5d6e6SPawel Jablonski 				 I40E_AQ_NVM_PRESERVATION_FLAGS_SHIFT);
3441e3a5d6e6SPawel Jablonski 	}
3442cd552cb4SShannon Nelson 	cmd->module_pointer = module_pointer;
3443cd552cb4SShannon Nelson 	cmd->offset = cpu_to_le32(offset);
3444cd552cb4SShannon Nelson 	cmd->length = cpu_to_le16(length);
3445cd552cb4SShannon Nelson 
3446cd552cb4SShannon Nelson 	desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
3447cd552cb4SShannon Nelson 	if (length > I40E_AQ_LARGE_BUF)
3448cd552cb4SShannon Nelson 		desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
3449cd552cb4SShannon Nelson 
3450cd552cb4SShannon Nelson 	status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
3451cd552cb4SShannon Nelson 
3452cd552cb4SShannon Nelson i40e_aq_update_nvm_exit:
3453cd552cb4SShannon Nelson 	return status;
3454cd552cb4SShannon Nelson }
3455cd552cb4SShannon Nelson 
3456cd552cb4SShannon Nelson /**
3457f05798b4SPiotr Azarewicz  * i40e_aq_rearrange_nvm
3458f05798b4SPiotr Azarewicz  * @hw: pointer to the hw struct
3459f05798b4SPiotr Azarewicz  * @rearrange_nvm: defines direction of rearrangement
3460f05798b4SPiotr Azarewicz  * @cmd_details: pointer to command details structure or NULL
3461f05798b4SPiotr Azarewicz  *
3462f05798b4SPiotr Azarewicz  * Rearrange NVM structure, available only for transition FW
3463f05798b4SPiotr Azarewicz  **/
i40e_aq_rearrange_nvm(struct i40e_hw * hw,u8 rearrange_nvm,struct i40e_asq_cmd_details * cmd_details)34645180ff13SJan Sokolowski int i40e_aq_rearrange_nvm(struct i40e_hw *hw,
3465f05798b4SPiotr Azarewicz 			  u8 rearrange_nvm,
3466f05798b4SPiotr Azarewicz 			  struct i40e_asq_cmd_details *cmd_details)
3467f05798b4SPiotr Azarewicz {
3468f05798b4SPiotr Azarewicz 	struct i40e_aqc_nvm_update *cmd;
3469f05798b4SPiotr Azarewicz 	struct i40e_aq_desc desc;
34705180ff13SJan Sokolowski 	int status;
3471f05798b4SPiotr Azarewicz 
3472f05798b4SPiotr Azarewicz 	cmd = (struct i40e_aqc_nvm_update *)&desc.params.raw;
3473f05798b4SPiotr Azarewicz 
3474f05798b4SPiotr Azarewicz 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_update);
3475f05798b4SPiotr Azarewicz 
3476f05798b4SPiotr Azarewicz 	rearrange_nvm &= (I40E_AQ_NVM_REARRANGE_TO_FLAT |
3477f05798b4SPiotr Azarewicz 			 I40E_AQ_NVM_REARRANGE_TO_STRUCT);
3478f05798b4SPiotr Azarewicz 
3479f05798b4SPiotr Azarewicz 	if (!rearrange_nvm) {
3480230f3d53SJan Sokolowski 		status = -EINVAL;
3481f05798b4SPiotr Azarewicz 		goto i40e_aq_rearrange_nvm_exit;
3482f05798b4SPiotr Azarewicz 	}
3483f05798b4SPiotr Azarewicz 
3484f05798b4SPiotr Azarewicz 	cmd->command_flags |= rearrange_nvm;
3485f05798b4SPiotr Azarewicz 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3486f05798b4SPiotr Azarewicz 
3487f05798b4SPiotr Azarewicz i40e_aq_rearrange_nvm_exit:
3488f05798b4SPiotr Azarewicz 	return status;
3489f05798b4SPiotr Azarewicz }
3490f05798b4SPiotr Azarewicz 
3491f05798b4SPiotr Azarewicz /**
349256a62fc8SJesse Brandeburg  * i40e_aq_get_lldp_mib
349356a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
349456a62fc8SJesse Brandeburg  * @bridge_type: type of bridge requested
349556a62fc8SJesse Brandeburg  * @mib_type: Local, Remote or both Local and Remote MIBs
349656a62fc8SJesse Brandeburg  * @buff: pointer to a user supplied buffer to store the MIB block
349756a62fc8SJesse Brandeburg  * @buff_size: size of the buffer (in bytes)
349856a62fc8SJesse Brandeburg  * @local_len : length of the returned Local LLDP MIB
349956a62fc8SJesse Brandeburg  * @remote_len: length of the returned Remote LLDP MIB
350056a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
350156a62fc8SJesse Brandeburg  *
350256a62fc8SJesse Brandeburg  * Requests the complete LLDP MIB (entire packet).
350356a62fc8SJesse Brandeburg  **/
i40e_aq_get_lldp_mib(struct i40e_hw * hw,u8 bridge_type,u8 mib_type,void * buff,u16 buff_size,u16 * local_len,u16 * remote_len,struct i40e_asq_cmd_details * cmd_details)35045180ff13SJan Sokolowski int i40e_aq_get_lldp_mib(struct i40e_hw *hw, u8 bridge_type,
350556a62fc8SJesse Brandeburg 			 u8 mib_type, void *buff, u16 buff_size,
350656a62fc8SJesse Brandeburg 			 u16 *local_len, u16 *remote_len,
350756a62fc8SJesse Brandeburg 			 struct i40e_asq_cmd_details *cmd_details)
350856a62fc8SJesse Brandeburg {
350956a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
351056a62fc8SJesse Brandeburg 	struct i40e_aqc_lldp_get_mib *cmd =
351156a62fc8SJesse Brandeburg 		(struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
351256a62fc8SJesse Brandeburg 	struct i40e_aqc_lldp_get_mib *resp =
351356a62fc8SJesse Brandeburg 		(struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
35145180ff13SJan Sokolowski 	int status;
351556a62fc8SJesse Brandeburg 
351656a62fc8SJesse Brandeburg 	if (buff_size == 0 || !buff)
3517230f3d53SJan Sokolowski 		return -EINVAL;
351856a62fc8SJesse Brandeburg 
351956a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_get_mib);
352056a62fc8SJesse Brandeburg 	/* Indirect Command */
352156a62fc8SJesse Brandeburg 	desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
352256a62fc8SJesse Brandeburg 
352356a62fc8SJesse Brandeburg 	cmd->type = mib_type & I40E_AQ_LLDP_MIB_TYPE_MASK;
352456a62fc8SJesse Brandeburg 	cmd->type |= ((bridge_type << I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) &
352556a62fc8SJesse Brandeburg 		       I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
352656a62fc8SJesse Brandeburg 
352756a62fc8SJesse Brandeburg 	desc.datalen = cpu_to_le16(buff_size);
352856a62fc8SJesse Brandeburg 
352956a62fc8SJesse Brandeburg 	desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
353056a62fc8SJesse Brandeburg 	if (buff_size > I40E_AQ_LARGE_BUF)
353156a62fc8SJesse Brandeburg 		desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
353256a62fc8SJesse Brandeburg 
353356a62fc8SJesse Brandeburg 	status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
353456a62fc8SJesse Brandeburg 	if (!status) {
353556a62fc8SJesse Brandeburg 		if (local_len != NULL)
353656a62fc8SJesse Brandeburg 			*local_len = le16_to_cpu(resp->local_len);
353756a62fc8SJesse Brandeburg 		if (remote_len != NULL)
353856a62fc8SJesse Brandeburg 			*remote_len = le16_to_cpu(resp->remote_len);
353956a62fc8SJesse Brandeburg 	}
354056a62fc8SJesse Brandeburg 
354156a62fc8SJesse Brandeburg 	return status;
354256a62fc8SJesse Brandeburg }
354356a62fc8SJesse Brandeburg 
354456a62fc8SJesse Brandeburg /**
354590bc8e00SArkadiusz Kubalewski  * i40e_aq_set_lldp_mib - Set the LLDP MIB
354690bc8e00SArkadiusz Kubalewski  * @hw: pointer to the hw struct
354790bc8e00SArkadiusz Kubalewski  * @mib_type: Local, Remote or both Local and Remote MIBs
354890bc8e00SArkadiusz Kubalewski  * @buff: pointer to a user supplied buffer to store the MIB block
354990bc8e00SArkadiusz Kubalewski  * @buff_size: size of the buffer (in bytes)
355090bc8e00SArkadiusz Kubalewski  * @cmd_details: pointer to command details structure or NULL
355190bc8e00SArkadiusz Kubalewski  *
355290bc8e00SArkadiusz Kubalewski  * Set the LLDP MIB.
355390bc8e00SArkadiusz Kubalewski  **/
35545180ff13SJan Sokolowski int
i40e_aq_set_lldp_mib(struct i40e_hw * hw,u8 mib_type,void * buff,u16 buff_size,struct i40e_asq_cmd_details * cmd_details)355590bc8e00SArkadiusz Kubalewski i40e_aq_set_lldp_mib(struct i40e_hw *hw,
355690bc8e00SArkadiusz Kubalewski 		     u8 mib_type, void *buff, u16 buff_size,
355790bc8e00SArkadiusz Kubalewski 		     struct i40e_asq_cmd_details *cmd_details)
355890bc8e00SArkadiusz Kubalewski {
355990bc8e00SArkadiusz Kubalewski 	struct i40e_aqc_lldp_set_local_mib *cmd;
356090bc8e00SArkadiusz Kubalewski 	struct i40e_aq_desc desc;
35615180ff13SJan Sokolowski 	int status;
356290bc8e00SArkadiusz Kubalewski 
356390bc8e00SArkadiusz Kubalewski 	cmd = (struct i40e_aqc_lldp_set_local_mib *)&desc.params.raw;
356490bc8e00SArkadiusz Kubalewski 	if (buff_size == 0 || !buff)
3565230f3d53SJan Sokolowski 		return -EINVAL;
356690bc8e00SArkadiusz Kubalewski 
356790bc8e00SArkadiusz Kubalewski 	i40e_fill_default_direct_cmd_desc(&desc,
356890bc8e00SArkadiusz Kubalewski 					  i40e_aqc_opc_lldp_set_local_mib);
356990bc8e00SArkadiusz Kubalewski 	/* Indirect Command */
357090bc8e00SArkadiusz Kubalewski 	desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
357190bc8e00SArkadiusz Kubalewski 	if (buff_size > I40E_AQ_LARGE_BUF)
357290bc8e00SArkadiusz Kubalewski 		desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
357390bc8e00SArkadiusz Kubalewski 	desc.datalen = cpu_to_le16(buff_size);
357490bc8e00SArkadiusz Kubalewski 
357590bc8e00SArkadiusz Kubalewski 	cmd->type = mib_type;
357690bc8e00SArkadiusz Kubalewski 	cmd->length = cpu_to_le16(buff_size);
357790bc8e00SArkadiusz Kubalewski 	cmd->address_high = cpu_to_le32(upper_32_bits((uintptr_t)buff));
357890bc8e00SArkadiusz Kubalewski 	cmd->address_low = cpu_to_le32(lower_32_bits((uintptr_t)buff));
357990bc8e00SArkadiusz Kubalewski 
358090bc8e00SArkadiusz Kubalewski 	status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
358190bc8e00SArkadiusz Kubalewski 	return status;
358290bc8e00SArkadiusz Kubalewski }
358390bc8e00SArkadiusz Kubalewski 
358490bc8e00SArkadiusz Kubalewski /**
358556a62fc8SJesse Brandeburg  * i40e_aq_cfg_lldp_mib_change_event
358656a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
358756a62fc8SJesse Brandeburg  * @enable_update: Enable or Disable event posting
358856a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
358956a62fc8SJesse Brandeburg  *
359056a62fc8SJesse Brandeburg  * Enable or Disable posting of an event on ARQ when LLDP MIB
359156a62fc8SJesse Brandeburg  * associated with the interface changes
359256a62fc8SJesse Brandeburg  **/
i40e_aq_cfg_lldp_mib_change_event(struct i40e_hw * hw,bool enable_update,struct i40e_asq_cmd_details * cmd_details)35935180ff13SJan Sokolowski int i40e_aq_cfg_lldp_mib_change_event(struct i40e_hw *hw,
359456a62fc8SJesse Brandeburg 				      bool enable_update,
359556a62fc8SJesse Brandeburg 				      struct i40e_asq_cmd_details *cmd_details)
359656a62fc8SJesse Brandeburg {
359756a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
359856a62fc8SJesse Brandeburg 	struct i40e_aqc_lldp_update_mib *cmd =
359956a62fc8SJesse Brandeburg 		(struct i40e_aqc_lldp_update_mib *)&desc.params.raw;
36005180ff13SJan Sokolowski 	int status;
360156a62fc8SJesse Brandeburg 
360256a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_update_mib);
360356a62fc8SJesse Brandeburg 
360456a62fc8SJesse Brandeburg 	if (!enable_update)
360556a62fc8SJesse Brandeburg 		cmd->command |= I40E_AQ_LLDP_MIB_UPDATE_DISABLE;
360656a62fc8SJesse Brandeburg 
360756a62fc8SJesse Brandeburg 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
360856a62fc8SJesse Brandeburg 
360956a62fc8SJesse Brandeburg 	return status;
361056a62fc8SJesse Brandeburg }
361156a62fc8SJesse Brandeburg 
361256a62fc8SJesse Brandeburg /**
3613c65e78f8SAleksandr Loktionov  * i40e_aq_restore_lldp
3614c65e78f8SAleksandr Loktionov  * @hw: pointer to the hw struct
3615c65e78f8SAleksandr Loktionov  * @setting: pointer to factory setting variable or NULL
3616c65e78f8SAleksandr Loktionov  * @restore: True if factory settings should be restored
3617c65e78f8SAleksandr Loktionov  * @cmd_details: pointer to command details structure or NULL
3618c65e78f8SAleksandr Loktionov  *
3619c65e78f8SAleksandr Loktionov  * Restore LLDP Agent factory settings if @restore set to True. In other case
3620c65e78f8SAleksandr Loktionov  * only returns factory setting in AQ response.
3621c65e78f8SAleksandr Loktionov  **/
36225180ff13SJan Sokolowski int
i40e_aq_restore_lldp(struct i40e_hw * hw,u8 * setting,bool restore,struct i40e_asq_cmd_details * cmd_details)3623c65e78f8SAleksandr Loktionov i40e_aq_restore_lldp(struct i40e_hw *hw, u8 *setting, bool restore,
3624c65e78f8SAleksandr Loktionov 		     struct i40e_asq_cmd_details *cmd_details)
3625c65e78f8SAleksandr Loktionov {
3626c65e78f8SAleksandr Loktionov 	struct i40e_aq_desc desc;
3627c65e78f8SAleksandr Loktionov 	struct i40e_aqc_lldp_restore *cmd =
3628c65e78f8SAleksandr Loktionov 		(struct i40e_aqc_lldp_restore *)&desc.params.raw;
36295180ff13SJan Sokolowski 	int status;
3630c65e78f8SAleksandr Loktionov 
3631c65e78f8SAleksandr Loktionov 	if (!(hw->flags & I40E_HW_FLAG_FW_LLDP_PERSISTENT)) {
3632c65e78f8SAleksandr Loktionov 		i40e_debug(hw, I40E_DEBUG_ALL,
3633c65e78f8SAleksandr Loktionov 			   "Restore LLDP not supported by current FW version.\n");
3634230f3d53SJan Sokolowski 		return -ENODEV;
3635c65e78f8SAleksandr Loktionov 	}
3636c65e78f8SAleksandr Loktionov 
3637c65e78f8SAleksandr Loktionov 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_restore);
3638c65e78f8SAleksandr Loktionov 
3639c65e78f8SAleksandr Loktionov 	if (restore)
3640c65e78f8SAleksandr Loktionov 		cmd->command |= I40E_AQ_LLDP_AGENT_RESTORE;
3641c65e78f8SAleksandr Loktionov 
3642c65e78f8SAleksandr Loktionov 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3643c65e78f8SAleksandr Loktionov 
3644c65e78f8SAleksandr Loktionov 	if (setting)
3645c65e78f8SAleksandr Loktionov 		*setting = cmd->command & 1;
3646c65e78f8SAleksandr Loktionov 
3647c65e78f8SAleksandr Loktionov 	return status;
3648c65e78f8SAleksandr Loktionov }
3649c65e78f8SAleksandr Loktionov 
3650c65e78f8SAleksandr Loktionov /**
365156a62fc8SJesse Brandeburg  * i40e_aq_stop_lldp
365256a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
365356a62fc8SJesse Brandeburg  * @shutdown_agent: True if LLDP Agent needs to be Shutdown
3654c65e78f8SAleksandr Loktionov  * @persist: True if stop of LLDP should be persistent across power cycles
365556a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
365656a62fc8SJesse Brandeburg  *
365756a62fc8SJesse Brandeburg  * Stop or Shutdown the embedded LLDP Agent
365856a62fc8SJesse Brandeburg  **/
i40e_aq_stop_lldp(struct i40e_hw * hw,bool shutdown_agent,bool persist,struct i40e_asq_cmd_details * cmd_details)36595180ff13SJan Sokolowski int i40e_aq_stop_lldp(struct i40e_hw *hw, bool shutdown_agent,
3660c65e78f8SAleksandr Loktionov 		      bool persist,
366156a62fc8SJesse Brandeburg 		      struct i40e_asq_cmd_details *cmd_details)
366256a62fc8SJesse Brandeburg {
366356a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
366456a62fc8SJesse Brandeburg 	struct i40e_aqc_lldp_stop *cmd =
366556a62fc8SJesse Brandeburg 		(struct i40e_aqc_lldp_stop *)&desc.params.raw;
36665180ff13SJan Sokolowski 	int status;
366756a62fc8SJesse Brandeburg 
366856a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_stop);
366956a62fc8SJesse Brandeburg 
367056a62fc8SJesse Brandeburg 	if (shutdown_agent)
367156a62fc8SJesse Brandeburg 		cmd->command |= I40E_AQ_LLDP_AGENT_SHUTDOWN;
367256a62fc8SJesse Brandeburg 
3673c65e78f8SAleksandr Loktionov 	if (persist) {
3674c65e78f8SAleksandr Loktionov 		if (hw->flags & I40E_HW_FLAG_FW_LLDP_PERSISTENT)
3675c65e78f8SAleksandr Loktionov 			cmd->command |= I40E_AQ_LLDP_AGENT_STOP_PERSIST;
3676c65e78f8SAleksandr Loktionov 		else
3677c65e78f8SAleksandr Loktionov 			i40e_debug(hw, I40E_DEBUG_ALL,
3678c65e78f8SAleksandr Loktionov 				   "Persistent Stop LLDP not supported by current FW version.\n");
3679c65e78f8SAleksandr Loktionov 	}
3680c65e78f8SAleksandr Loktionov 
368156a62fc8SJesse Brandeburg 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
368256a62fc8SJesse Brandeburg 
368356a62fc8SJesse Brandeburg 	return status;
368456a62fc8SJesse Brandeburg }
368556a62fc8SJesse Brandeburg 
368656a62fc8SJesse Brandeburg /**
368756a62fc8SJesse Brandeburg  * i40e_aq_start_lldp
368856a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
3689c65e78f8SAleksandr Loktionov  * @persist: True if start of LLDP should be persistent across power cycles
369056a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
369156a62fc8SJesse Brandeburg  *
369256a62fc8SJesse Brandeburg  * Start the embedded LLDP Agent on all ports.
369356a62fc8SJesse Brandeburg  **/
i40e_aq_start_lldp(struct i40e_hw * hw,bool persist,struct i40e_asq_cmd_details * cmd_details)36945180ff13SJan Sokolowski int i40e_aq_start_lldp(struct i40e_hw *hw, bool persist,
369556a62fc8SJesse Brandeburg 		       struct i40e_asq_cmd_details *cmd_details)
369656a62fc8SJesse Brandeburg {
369756a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
369856a62fc8SJesse Brandeburg 	struct i40e_aqc_lldp_start *cmd =
369956a62fc8SJesse Brandeburg 		(struct i40e_aqc_lldp_start *)&desc.params.raw;
37005180ff13SJan Sokolowski 	int status;
370156a62fc8SJesse Brandeburg 
370256a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_start);
370356a62fc8SJesse Brandeburg 
370456a62fc8SJesse Brandeburg 	cmd->command = I40E_AQ_LLDP_AGENT_START;
3705c65e78f8SAleksandr Loktionov 
3706c65e78f8SAleksandr Loktionov 	if (persist) {
3707c65e78f8SAleksandr Loktionov 		if (hw->flags & I40E_HW_FLAG_FW_LLDP_PERSISTENT)
3708c65e78f8SAleksandr Loktionov 			cmd->command |= I40E_AQ_LLDP_AGENT_START_PERSIST;
3709c65e78f8SAleksandr Loktionov 		else
3710c65e78f8SAleksandr Loktionov 			i40e_debug(hw, I40E_DEBUG_ALL,
3711c65e78f8SAleksandr Loktionov 				   "Persistent Start LLDP not supported by current FW version.\n");
3712c65e78f8SAleksandr Loktionov 	}
3713c65e78f8SAleksandr Loktionov 
3714b6a02a6fSUpasana Menon 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
371556a62fc8SJesse Brandeburg 
3716b6a02a6fSUpasana Menon 	return status;
3717b6a02a6fSUpasana Menon }
3718b6a02a6fSUpasana Menon 
3719b6a02a6fSUpasana Menon /**
3720b6a02a6fSUpasana Menon  * i40e_aq_set_dcb_parameters
3721b6a02a6fSUpasana Menon  * @hw: pointer to the hw struct
3722b6a02a6fSUpasana Menon  * @cmd_details: pointer to command details structure or NULL
3723b6a02a6fSUpasana Menon  * @dcb_enable: True if DCB configuration needs to be applied
3724b6a02a6fSUpasana Menon  *
3725b6a02a6fSUpasana Menon  **/
37265180ff13SJan Sokolowski int
i40e_aq_set_dcb_parameters(struct i40e_hw * hw,bool dcb_enable,struct i40e_asq_cmd_details * cmd_details)3727b6a02a6fSUpasana Menon i40e_aq_set_dcb_parameters(struct i40e_hw *hw, bool dcb_enable,
3728b6a02a6fSUpasana Menon 			   struct i40e_asq_cmd_details *cmd_details)
3729b6a02a6fSUpasana Menon {
3730b6a02a6fSUpasana Menon 	struct i40e_aq_desc desc;
3731b6a02a6fSUpasana Menon 	struct i40e_aqc_set_dcb_parameters *cmd =
3732b6a02a6fSUpasana Menon 		(struct i40e_aqc_set_dcb_parameters *)&desc.params.raw;
37335180ff13SJan Sokolowski 	int status;
3734b6a02a6fSUpasana Menon 
37355734fe87SPatryk Małek 	if (!(hw->flags & I40E_HW_FLAG_FW_LLDP_STOPPABLE))
3736230f3d53SJan Sokolowski 		return -ENODEV;
37375734fe87SPatryk Małek 
3738b6a02a6fSUpasana Menon 	i40e_fill_default_direct_cmd_desc(&desc,
3739b6a02a6fSUpasana Menon 					  i40e_aqc_opc_set_dcb_parameters);
3740b6a02a6fSUpasana Menon 
3741b6a02a6fSUpasana Menon 	if (dcb_enable) {
3742b6a02a6fSUpasana Menon 		cmd->valid_flags = I40E_DCB_VALID;
3743b6a02a6fSUpasana Menon 		cmd->command = I40E_AQ_DCB_SET_AGENT;
3744b6a02a6fSUpasana Menon 	}
374556a62fc8SJesse Brandeburg 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
374656a62fc8SJesse Brandeburg 
374756a62fc8SJesse Brandeburg 	return status;
374856a62fc8SJesse Brandeburg }
374956a62fc8SJesse Brandeburg 
375056a62fc8SJesse Brandeburg /**
37519fa61dd2SNeerav Parikh  * i40e_aq_get_cee_dcb_config
37529fa61dd2SNeerav Parikh  * @hw: pointer to the hw struct
37539fa61dd2SNeerav Parikh  * @buff: response buffer that stores CEE operational configuration
37549fa61dd2SNeerav Parikh  * @buff_size: size of the buffer passed
37559fa61dd2SNeerav Parikh  * @cmd_details: pointer to command details structure or NULL
37569fa61dd2SNeerav Parikh  *
37579fa61dd2SNeerav Parikh  * Get CEE DCBX mode operational configuration from firmware
37589fa61dd2SNeerav Parikh  **/
i40e_aq_get_cee_dcb_config(struct i40e_hw * hw,void * buff,u16 buff_size,struct i40e_asq_cmd_details * cmd_details)37595180ff13SJan Sokolowski int i40e_aq_get_cee_dcb_config(struct i40e_hw *hw,
37609fa61dd2SNeerav Parikh 			       void *buff, u16 buff_size,
37619fa61dd2SNeerav Parikh 			       struct i40e_asq_cmd_details *cmd_details)
37629fa61dd2SNeerav Parikh {
37639fa61dd2SNeerav Parikh 	struct i40e_aq_desc desc;
37645180ff13SJan Sokolowski 	int status;
37659fa61dd2SNeerav Parikh 
37669fa61dd2SNeerav Parikh 	if (buff_size == 0 || !buff)
3767230f3d53SJan Sokolowski 		return -EINVAL;
37689fa61dd2SNeerav Parikh 
37699fa61dd2SNeerav Parikh 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_cee_dcb_cfg);
37709fa61dd2SNeerav Parikh 
37719fa61dd2SNeerav Parikh 	desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
37729fa61dd2SNeerav Parikh 	status = i40e_asq_send_command(hw, &desc, (void *)buff, buff_size,
37739fa61dd2SNeerav Parikh 				       cmd_details);
37749fa61dd2SNeerav Parikh 
37759fa61dd2SNeerav Parikh 	return status;
37769fa61dd2SNeerav Parikh }
37779fa61dd2SNeerav Parikh 
37789fa61dd2SNeerav Parikh /**
3779a1c9a9d9SJeff Kirsher  * i40e_aq_add_udp_tunnel
3780a1c9a9d9SJeff Kirsher  * @hw: pointer to the hw struct
378115d23b4cSJacob Keller  * @udp_port: the UDP port to add in Host byte order
3782a1c9a9d9SJeff Kirsher  * @protocol_index: protocol index type
378398d44381SJeff Kirsher  * @filter_index: pointer to filter index
3784a1c9a9d9SJeff Kirsher  * @cmd_details: pointer to command details structure or NULL
378515d23b4cSJacob Keller  *
378615d23b4cSJacob Keller  * Note: Firmware expects the udp_port value to be in Little Endian format,
378715d23b4cSJacob Keller  * and this function will call cpu_to_le16 to convert from Host byte order to
378815d23b4cSJacob Keller  * Little Endian order.
3789a1c9a9d9SJeff Kirsher  **/
i40e_aq_add_udp_tunnel(struct i40e_hw * hw,u16 udp_port,u8 protocol_index,u8 * filter_index,struct i40e_asq_cmd_details * cmd_details)37905180ff13SJan Sokolowski int i40e_aq_add_udp_tunnel(struct i40e_hw *hw,
3791f4f94b94SKevin Scott 			   u16 udp_port, u8 protocol_index,
3792f4f94b94SKevin Scott 			   u8 *filter_index,
3793a1c9a9d9SJeff Kirsher 			   struct i40e_asq_cmd_details *cmd_details)
3794a1c9a9d9SJeff Kirsher {
3795a1c9a9d9SJeff Kirsher 	struct i40e_aq_desc desc;
3796a1c9a9d9SJeff Kirsher 	struct i40e_aqc_add_udp_tunnel *cmd =
3797a1c9a9d9SJeff Kirsher 		(struct i40e_aqc_add_udp_tunnel *)&desc.params.raw;
3798a1c9a9d9SJeff Kirsher 	struct i40e_aqc_del_udp_tunnel_completion *resp =
3799a1c9a9d9SJeff Kirsher 		(struct i40e_aqc_del_udp_tunnel_completion *)&desc.params.raw;
38005180ff13SJan Sokolowski 	int status;
3801a1c9a9d9SJeff Kirsher 
3802a1c9a9d9SJeff Kirsher 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_udp_tunnel);
3803a1c9a9d9SJeff Kirsher 
3804a1c9a9d9SJeff Kirsher 	cmd->udp_port = cpu_to_le16(udp_port);
3805981b7545SShannon Nelson 	cmd->protocol_type = protocol_index;
3806a1c9a9d9SJeff Kirsher 
3807a1c9a9d9SJeff Kirsher 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3808a1c9a9d9SJeff Kirsher 
380965d13461SShannon Nelson 	if (!status && filter_index)
3810a1c9a9d9SJeff Kirsher 		*filter_index = resp->index;
3811a1c9a9d9SJeff Kirsher 
3812a1c9a9d9SJeff Kirsher 	return status;
3813a1c9a9d9SJeff Kirsher }
3814a1c9a9d9SJeff Kirsher 
3815a1c9a9d9SJeff Kirsher /**
3816a1c9a9d9SJeff Kirsher  * i40e_aq_del_udp_tunnel
3817a1c9a9d9SJeff Kirsher  * @hw: pointer to the hw struct
3818a1c9a9d9SJeff Kirsher  * @index: filter index
3819a1c9a9d9SJeff Kirsher  * @cmd_details: pointer to command details structure or NULL
3820a1c9a9d9SJeff Kirsher  **/
i40e_aq_del_udp_tunnel(struct i40e_hw * hw,u8 index,struct i40e_asq_cmd_details * cmd_details)38215180ff13SJan Sokolowski int i40e_aq_del_udp_tunnel(struct i40e_hw *hw, u8 index,
3822a1c9a9d9SJeff Kirsher 			   struct i40e_asq_cmd_details *cmd_details)
3823a1c9a9d9SJeff Kirsher {
3824a1c9a9d9SJeff Kirsher 	struct i40e_aq_desc desc;
3825a1c9a9d9SJeff Kirsher 	struct i40e_aqc_remove_udp_tunnel *cmd =
3826a1c9a9d9SJeff Kirsher 		(struct i40e_aqc_remove_udp_tunnel *)&desc.params.raw;
38275180ff13SJan Sokolowski 	int status;
3828a1c9a9d9SJeff Kirsher 
3829a1c9a9d9SJeff Kirsher 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_del_udp_tunnel);
3830a1c9a9d9SJeff Kirsher 
3831a1c9a9d9SJeff Kirsher 	cmd->index = index;
3832a1c9a9d9SJeff Kirsher 
3833a1c9a9d9SJeff Kirsher 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3834a1c9a9d9SJeff Kirsher 
3835a1c9a9d9SJeff Kirsher 	return status;
3836a1c9a9d9SJeff Kirsher }
3837a1c9a9d9SJeff Kirsher 
3838a1c9a9d9SJeff Kirsher /**
383956a62fc8SJesse Brandeburg  * i40e_aq_delete_element - Delete switch element
384056a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
384156a62fc8SJesse Brandeburg  * @seid: the SEID to delete from the switch
384256a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
384356a62fc8SJesse Brandeburg  *
384456a62fc8SJesse Brandeburg  * This deletes a switch element from the switch.
384556a62fc8SJesse Brandeburg  **/
i40e_aq_delete_element(struct i40e_hw * hw,u16 seid,struct i40e_asq_cmd_details * cmd_details)38465180ff13SJan Sokolowski int i40e_aq_delete_element(struct i40e_hw *hw, u16 seid,
384756a62fc8SJesse Brandeburg 			   struct i40e_asq_cmd_details *cmd_details)
384856a62fc8SJesse Brandeburg {
384956a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
385056a62fc8SJesse Brandeburg 	struct i40e_aqc_switch_seid *cmd =
385156a62fc8SJesse Brandeburg 		(struct i40e_aqc_switch_seid *)&desc.params.raw;
38525180ff13SJan Sokolowski 	int status;
385356a62fc8SJesse Brandeburg 
385456a62fc8SJesse Brandeburg 	if (seid == 0)
3855230f3d53SJan Sokolowski 		return -EINVAL;
385656a62fc8SJesse Brandeburg 
385756a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_delete_element);
385856a62fc8SJesse Brandeburg 
385956a62fc8SJesse Brandeburg 	cmd->seid = cpu_to_le16(seid);
386056a62fc8SJesse Brandeburg 
386159b3d735SJedrzej Jagielski 	status = i40e_asq_send_command_atomic(hw, &desc, NULL, 0,
386259b3d735SJedrzej Jagielski 					      cmd_details, true);
386356a62fc8SJesse Brandeburg 
386456a62fc8SJesse Brandeburg 	return status;
386556a62fc8SJesse Brandeburg }
386656a62fc8SJesse Brandeburg 
386756a62fc8SJesse Brandeburg /**
3868afb3ff0dSNeerav Parikh  * i40e_aq_dcb_updated - DCB Updated Command
3869afb3ff0dSNeerav Parikh  * @hw: pointer to the hw struct
3870afb3ff0dSNeerav Parikh  * @cmd_details: pointer to command details structure or NULL
3871afb3ff0dSNeerav Parikh  *
3872afb3ff0dSNeerav Parikh  * EMP will return when the shared RPB settings have been
3873afb3ff0dSNeerav Parikh  * recomputed and modified. The retval field in the descriptor
3874afb3ff0dSNeerav Parikh  * will be set to 0 when RPB is modified.
3875afb3ff0dSNeerav Parikh  **/
i40e_aq_dcb_updated(struct i40e_hw * hw,struct i40e_asq_cmd_details * cmd_details)38765180ff13SJan Sokolowski int i40e_aq_dcb_updated(struct i40e_hw *hw,
3877afb3ff0dSNeerav Parikh 			struct i40e_asq_cmd_details *cmd_details)
3878afb3ff0dSNeerav Parikh {
3879afb3ff0dSNeerav Parikh 	struct i40e_aq_desc desc;
38805180ff13SJan Sokolowski 	int status;
3881afb3ff0dSNeerav Parikh 
3882afb3ff0dSNeerav Parikh 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_dcb_updated);
3883afb3ff0dSNeerav Parikh 
3884afb3ff0dSNeerav Parikh 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3885afb3ff0dSNeerav Parikh 
3886afb3ff0dSNeerav Parikh 	return status;
3887afb3ff0dSNeerav Parikh }
3888afb3ff0dSNeerav Parikh 
3889afb3ff0dSNeerav Parikh /**
389056a62fc8SJesse Brandeburg  * i40e_aq_tx_sched_cmd - generic Tx scheduler AQ command handler
389156a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
389256a62fc8SJesse Brandeburg  * @seid: seid for the physical port/switching component/vsi
389356a62fc8SJesse Brandeburg  * @buff: Indirect buffer to hold data parameters and response
389456a62fc8SJesse Brandeburg  * @buff_size: Indirect buffer size
389556a62fc8SJesse Brandeburg  * @opcode: Tx scheduler AQ command opcode
389656a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
389756a62fc8SJesse Brandeburg  *
389856a62fc8SJesse Brandeburg  * Generic command handler for Tx scheduler AQ commands
389956a62fc8SJesse Brandeburg  **/
i40e_aq_tx_sched_cmd(struct i40e_hw * hw,u16 seid,void * buff,u16 buff_size,enum i40e_admin_queue_opc opcode,struct i40e_asq_cmd_details * cmd_details)39005180ff13SJan Sokolowski static int i40e_aq_tx_sched_cmd(struct i40e_hw *hw, u16 seid,
390156a62fc8SJesse Brandeburg 				void *buff, u16 buff_size,
390256a62fc8SJesse Brandeburg 				enum i40e_admin_queue_opc opcode,
390356a62fc8SJesse Brandeburg 				struct i40e_asq_cmd_details *cmd_details)
390456a62fc8SJesse Brandeburg {
390556a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
390656a62fc8SJesse Brandeburg 	struct i40e_aqc_tx_sched_ind *cmd =
390756a62fc8SJesse Brandeburg 		(struct i40e_aqc_tx_sched_ind *)&desc.params.raw;
39085180ff13SJan Sokolowski 	int status;
390956a62fc8SJesse Brandeburg 	bool cmd_param_flag = false;
391056a62fc8SJesse Brandeburg 
391156a62fc8SJesse Brandeburg 	switch (opcode) {
391256a62fc8SJesse Brandeburg 	case i40e_aqc_opc_configure_vsi_ets_sla_bw_limit:
391356a62fc8SJesse Brandeburg 	case i40e_aqc_opc_configure_vsi_tc_bw:
391456a62fc8SJesse Brandeburg 	case i40e_aqc_opc_enable_switching_comp_ets:
391556a62fc8SJesse Brandeburg 	case i40e_aqc_opc_modify_switching_comp_ets:
391656a62fc8SJesse Brandeburg 	case i40e_aqc_opc_disable_switching_comp_ets:
391756a62fc8SJesse Brandeburg 	case i40e_aqc_opc_configure_switching_comp_ets_bw_limit:
391856a62fc8SJesse Brandeburg 	case i40e_aqc_opc_configure_switching_comp_bw_config:
391956a62fc8SJesse Brandeburg 		cmd_param_flag = true;
392056a62fc8SJesse Brandeburg 		break;
392156a62fc8SJesse Brandeburg 	case i40e_aqc_opc_query_vsi_bw_config:
392256a62fc8SJesse Brandeburg 	case i40e_aqc_opc_query_vsi_ets_sla_config:
392356a62fc8SJesse Brandeburg 	case i40e_aqc_opc_query_switching_comp_ets_config:
392456a62fc8SJesse Brandeburg 	case i40e_aqc_opc_query_port_ets_config:
392556a62fc8SJesse Brandeburg 	case i40e_aqc_opc_query_switching_comp_bw_config:
392656a62fc8SJesse Brandeburg 		cmd_param_flag = false;
392756a62fc8SJesse Brandeburg 		break;
392856a62fc8SJesse Brandeburg 	default:
3929230f3d53SJan Sokolowski 		return -EINVAL;
393056a62fc8SJesse Brandeburg 	}
393156a62fc8SJesse Brandeburg 
393256a62fc8SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc, opcode);
393356a62fc8SJesse Brandeburg 
393456a62fc8SJesse Brandeburg 	/* Indirect command */
393556a62fc8SJesse Brandeburg 	desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
393656a62fc8SJesse Brandeburg 	if (cmd_param_flag)
393756a62fc8SJesse Brandeburg 		desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
393856a62fc8SJesse Brandeburg 	if (buff_size > I40E_AQ_LARGE_BUF)
393956a62fc8SJesse Brandeburg 		desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
394056a62fc8SJesse Brandeburg 
394156a62fc8SJesse Brandeburg 	desc.datalen = cpu_to_le16(buff_size);
394256a62fc8SJesse Brandeburg 
394356a62fc8SJesse Brandeburg 	cmd->vsi_seid = cpu_to_le16(seid);
394456a62fc8SJesse Brandeburg 
394556a62fc8SJesse Brandeburg 	status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
394656a62fc8SJesse Brandeburg 
394756a62fc8SJesse Brandeburg 	return status;
394856a62fc8SJesse Brandeburg }
394956a62fc8SJesse Brandeburg 
395056a62fc8SJesse Brandeburg /**
39516b192891SMitch Williams  * i40e_aq_config_vsi_bw_limit - Configure VSI BW Limit
39526b192891SMitch Williams  * @hw: pointer to the hw struct
39536b192891SMitch Williams  * @seid: VSI seid
39546b192891SMitch Williams  * @credit: BW limit credits (0 = disabled)
39556b192891SMitch Williams  * @max_credit: Max BW limit credits
39566b192891SMitch Williams  * @cmd_details: pointer to command details structure or NULL
39576b192891SMitch Williams  **/
i40e_aq_config_vsi_bw_limit(struct i40e_hw * hw,u16 seid,u16 credit,u8 max_credit,struct i40e_asq_cmd_details * cmd_details)39585180ff13SJan Sokolowski int i40e_aq_config_vsi_bw_limit(struct i40e_hw *hw,
39596b192891SMitch Williams 				u16 seid, u16 credit, u8 max_credit,
39606b192891SMitch Williams 				struct i40e_asq_cmd_details *cmd_details)
39616b192891SMitch Williams {
39626b192891SMitch Williams 	struct i40e_aq_desc desc;
39636b192891SMitch Williams 	struct i40e_aqc_configure_vsi_bw_limit *cmd =
39646b192891SMitch Williams 		(struct i40e_aqc_configure_vsi_bw_limit *)&desc.params.raw;
39655180ff13SJan Sokolowski 	int status;
39666b192891SMitch Williams 
39676b192891SMitch Williams 	i40e_fill_default_direct_cmd_desc(&desc,
39686b192891SMitch Williams 					  i40e_aqc_opc_configure_vsi_bw_limit);
39696b192891SMitch Williams 
39706b192891SMitch Williams 	cmd->vsi_seid = cpu_to_le16(seid);
39716b192891SMitch Williams 	cmd->credit = cpu_to_le16(credit);
39726b192891SMitch Williams 	cmd->max_credit = max_credit;
39736b192891SMitch Williams 
39746b192891SMitch Williams 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
39756b192891SMitch Williams 
39766b192891SMitch Williams 	return status;
39776b192891SMitch Williams }
39786b192891SMitch Williams 
39796b192891SMitch Williams /**
398056a62fc8SJesse Brandeburg  * i40e_aq_config_vsi_tc_bw - Config VSI BW Allocation per TC
398156a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
398256a62fc8SJesse Brandeburg  * @seid: VSI seid
398356a62fc8SJesse Brandeburg  * @bw_data: Buffer holding enabled TCs, relative TC BW limit/credits
398456a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
398556a62fc8SJesse Brandeburg  **/
i40e_aq_config_vsi_tc_bw(struct i40e_hw * hw,u16 seid,struct i40e_aqc_configure_vsi_tc_bw_data * bw_data,struct i40e_asq_cmd_details * cmd_details)39865180ff13SJan Sokolowski int i40e_aq_config_vsi_tc_bw(struct i40e_hw *hw,
398756a62fc8SJesse Brandeburg 			     u16 seid,
398856a62fc8SJesse Brandeburg 			     struct i40e_aqc_configure_vsi_tc_bw_data *bw_data,
398956a62fc8SJesse Brandeburg 			     struct i40e_asq_cmd_details *cmd_details)
399056a62fc8SJesse Brandeburg {
399156a62fc8SJesse Brandeburg 	return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
399256a62fc8SJesse Brandeburg 				    i40e_aqc_opc_configure_vsi_tc_bw,
399356a62fc8SJesse Brandeburg 				    cmd_details);
399456a62fc8SJesse Brandeburg }
399556a62fc8SJesse Brandeburg 
399656a62fc8SJesse Brandeburg /**
3997afb3ff0dSNeerav Parikh  * i40e_aq_config_switch_comp_ets - Enable/Disable/Modify ETS on the port
3998afb3ff0dSNeerav Parikh  * @hw: pointer to the hw struct
3999afb3ff0dSNeerav Parikh  * @seid: seid of the switching component connected to Physical Port
4000afb3ff0dSNeerav Parikh  * @ets_data: Buffer holding ETS parameters
4001f5254429SJacob Keller  * @opcode: Tx scheduler AQ command opcode
4002afb3ff0dSNeerav Parikh  * @cmd_details: pointer to command details structure or NULL
4003afb3ff0dSNeerav Parikh  **/
40045180ff13SJan Sokolowski int
i40e_aq_config_switch_comp_ets(struct i40e_hw * hw,u16 seid,struct i40e_aqc_configure_switching_comp_ets_data * ets_data,enum i40e_admin_queue_opc opcode,struct i40e_asq_cmd_details * cmd_details)40055180ff13SJan Sokolowski i40e_aq_config_switch_comp_ets(struct i40e_hw *hw,
4006afb3ff0dSNeerav Parikh 			       u16 seid,
4007afb3ff0dSNeerav Parikh 			       struct i40e_aqc_configure_switching_comp_ets_data *ets_data,
4008afb3ff0dSNeerav Parikh 			       enum i40e_admin_queue_opc opcode,
4009afb3ff0dSNeerav Parikh 			       struct i40e_asq_cmd_details *cmd_details)
4010afb3ff0dSNeerav Parikh {
4011afb3ff0dSNeerav Parikh 	return i40e_aq_tx_sched_cmd(hw, seid, (void *)ets_data,
4012afb3ff0dSNeerav Parikh 				    sizeof(*ets_data), opcode, cmd_details);
4013afb3ff0dSNeerav Parikh }
4014afb3ff0dSNeerav Parikh 
4015afb3ff0dSNeerav Parikh /**
4016afb3ff0dSNeerav Parikh  * i40e_aq_config_switch_comp_bw_config - Config Switch comp BW Alloc per TC
4017afb3ff0dSNeerav Parikh  * @hw: pointer to the hw struct
4018afb3ff0dSNeerav Parikh  * @seid: seid of the switching component
4019afb3ff0dSNeerav Parikh  * @bw_data: Buffer holding enabled TCs, relative/absolute TC BW limit/credits
4020afb3ff0dSNeerav Parikh  * @cmd_details: pointer to command details structure or NULL
4021afb3ff0dSNeerav Parikh  **/
40225180ff13SJan Sokolowski int
i40e_aq_config_switch_comp_bw_config(struct i40e_hw * hw,u16 seid,struct i40e_aqc_configure_switching_comp_bw_config_data * bw_data,struct i40e_asq_cmd_details * cmd_details)40235180ff13SJan Sokolowski i40e_aq_config_switch_comp_bw_config(struct i40e_hw *hw,
4024afb3ff0dSNeerav Parikh 	u16 seid,
4025afb3ff0dSNeerav Parikh 	struct i40e_aqc_configure_switching_comp_bw_config_data *bw_data,
4026afb3ff0dSNeerav Parikh 	struct i40e_asq_cmd_details *cmd_details)
4027afb3ff0dSNeerav Parikh {
4028afb3ff0dSNeerav Parikh 	return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
4029afb3ff0dSNeerav Parikh 			    i40e_aqc_opc_configure_switching_comp_bw_config,
4030afb3ff0dSNeerav Parikh 			    cmd_details);
4031afb3ff0dSNeerav Parikh }
4032afb3ff0dSNeerav Parikh 
4033afb3ff0dSNeerav Parikh /**
403456a62fc8SJesse Brandeburg  * i40e_aq_query_vsi_bw_config - Query VSI BW configuration
403556a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
403656a62fc8SJesse Brandeburg  * @seid: seid of the VSI
403756a62fc8SJesse Brandeburg  * @bw_data: Buffer to hold VSI BW configuration
403856a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
403956a62fc8SJesse Brandeburg  **/
40405180ff13SJan Sokolowski int
i40e_aq_query_vsi_bw_config(struct i40e_hw * hw,u16 seid,struct i40e_aqc_query_vsi_bw_config_resp * bw_data,struct i40e_asq_cmd_details * cmd_details)40415180ff13SJan Sokolowski i40e_aq_query_vsi_bw_config(struct i40e_hw *hw,
404256a62fc8SJesse Brandeburg 			    u16 seid,
404356a62fc8SJesse Brandeburg 			    struct i40e_aqc_query_vsi_bw_config_resp *bw_data,
404456a62fc8SJesse Brandeburg 			    struct i40e_asq_cmd_details *cmd_details)
404556a62fc8SJesse Brandeburg {
404656a62fc8SJesse Brandeburg 	return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
404756a62fc8SJesse Brandeburg 				    i40e_aqc_opc_query_vsi_bw_config,
404856a62fc8SJesse Brandeburg 				    cmd_details);
404956a62fc8SJesse Brandeburg }
405056a62fc8SJesse Brandeburg 
405156a62fc8SJesse Brandeburg /**
405256a62fc8SJesse Brandeburg  * i40e_aq_query_vsi_ets_sla_config - Query VSI BW configuration per TC
405356a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
405456a62fc8SJesse Brandeburg  * @seid: seid of the VSI
405556a62fc8SJesse Brandeburg  * @bw_data: Buffer to hold VSI BW configuration per TC
405656a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
405756a62fc8SJesse Brandeburg  **/
40585180ff13SJan Sokolowski int
i40e_aq_query_vsi_ets_sla_config(struct i40e_hw * hw,u16 seid,struct i40e_aqc_query_vsi_ets_sla_config_resp * bw_data,struct i40e_asq_cmd_details * cmd_details)40595180ff13SJan Sokolowski i40e_aq_query_vsi_ets_sla_config(struct i40e_hw *hw,
406056a62fc8SJesse Brandeburg 				 u16 seid,
406156a62fc8SJesse Brandeburg 				 struct i40e_aqc_query_vsi_ets_sla_config_resp *bw_data,
406256a62fc8SJesse Brandeburg 				 struct i40e_asq_cmd_details *cmd_details)
406356a62fc8SJesse Brandeburg {
406456a62fc8SJesse Brandeburg 	return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
406556a62fc8SJesse Brandeburg 				    i40e_aqc_opc_query_vsi_ets_sla_config,
406656a62fc8SJesse Brandeburg 				    cmd_details);
406756a62fc8SJesse Brandeburg }
406856a62fc8SJesse Brandeburg 
406956a62fc8SJesse Brandeburg /**
407056a62fc8SJesse Brandeburg  * i40e_aq_query_switch_comp_ets_config - Query Switch comp BW config per TC
407156a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
407256a62fc8SJesse Brandeburg  * @seid: seid of the switching component
407356a62fc8SJesse Brandeburg  * @bw_data: Buffer to hold switching component's per TC BW config
407456a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
407556a62fc8SJesse Brandeburg  **/
40765180ff13SJan Sokolowski int
i40e_aq_query_switch_comp_ets_config(struct i40e_hw * hw,u16 seid,struct i40e_aqc_query_switching_comp_ets_config_resp * bw_data,struct i40e_asq_cmd_details * cmd_details)40775180ff13SJan Sokolowski i40e_aq_query_switch_comp_ets_config(struct i40e_hw *hw,
407856a62fc8SJesse Brandeburg 				     u16 seid,
407956a62fc8SJesse Brandeburg 				     struct i40e_aqc_query_switching_comp_ets_config_resp *bw_data,
408056a62fc8SJesse Brandeburg 				     struct i40e_asq_cmd_details *cmd_details)
408156a62fc8SJesse Brandeburg {
408256a62fc8SJesse Brandeburg 	return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
408356a62fc8SJesse Brandeburg 				   i40e_aqc_opc_query_switching_comp_ets_config,
408456a62fc8SJesse Brandeburg 				   cmd_details);
408556a62fc8SJesse Brandeburg }
408656a62fc8SJesse Brandeburg 
408756a62fc8SJesse Brandeburg /**
408856a62fc8SJesse Brandeburg  * i40e_aq_query_port_ets_config - Query Physical Port ETS configuration
408956a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
409056a62fc8SJesse Brandeburg  * @seid: seid of the VSI or switching component connected to Physical Port
409156a62fc8SJesse Brandeburg  * @bw_data: Buffer to hold current ETS configuration for the Physical Port
409256a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
409356a62fc8SJesse Brandeburg  **/
40945180ff13SJan Sokolowski int
i40e_aq_query_port_ets_config(struct i40e_hw * hw,u16 seid,struct i40e_aqc_query_port_ets_config_resp * bw_data,struct i40e_asq_cmd_details * cmd_details)40955180ff13SJan Sokolowski i40e_aq_query_port_ets_config(struct i40e_hw *hw,
409656a62fc8SJesse Brandeburg 			      u16 seid,
409756a62fc8SJesse Brandeburg 			      struct i40e_aqc_query_port_ets_config_resp *bw_data,
409856a62fc8SJesse Brandeburg 			      struct i40e_asq_cmd_details *cmd_details)
409956a62fc8SJesse Brandeburg {
410056a62fc8SJesse Brandeburg 	return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
410156a62fc8SJesse Brandeburg 				    i40e_aqc_opc_query_port_ets_config,
410256a62fc8SJesse Brandeburg 				    cmd_details);
410356a62fc8SJesse Brandeburg }
410456a62fc8SJesse Brandeburg 
410556a62fc8SJesse Brandeburg /**
410656a62fc8SJesse Brandeburg  * i40e_aq_query_switch_comp_bw_config - Query Switch comp BW configuration
410756a62fc8SJesse Brandeburg  * @hw: pointer to the hw struct
410856a62fc8SJesse Brandeburg  * @seid: seid of the switching component
410956a62fc8SJesse Brandeburg  * @bw_data: Buffer to hold switching component's BW configuration
411056a62fc8SJesse Brandeburg  * @cmd_details: pointer to command details structure or NULL
411156a62fc8SJesse Brandeburg  **/
41125180ff13SJan Sokolowski int
i40e_aq_query_switch_comp_bw_config(struct i40e_hw * hw,u16 seid,struct i40e_aqc_query_switching_comp_bw_config_resp * bw_data,struct i40e_asq_cmd_details * cmd_details)41135180ff13SJan Sokolowski i40e_aq_query_switch_comp_bw_config(struct i40e_hw *hw,
411456a62fc8SJesse Brandeburg 				    u16 seid,
411556a62fc8SJesse Brandeburg 				    struct i40e_aqc_query_switching_comp_bw_config_resp *bw_data,
411656a62fc8SJesse Brandeburg 				    struct i40e_asq_cmd_details *cmd_details)
411756a62fc8SJesse Brandeburg {
411856a62fc8SJesse Brandeburg 	return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
411956a62fc8SJesse Brandeburg 				    i40e_aqc_opc_query_switching_comp_bw_config,
412056a62fc8SJesse Brandeburg 				    cmd_details);
412156a62fc8SJesse Brandeburg }
412256a62fc8SJesse Brandeburg 
412356a62fc8SJesse Brandeburg /**
412456a62fc8SJesse Brandeburg  * i40e_validate_filter_settings
412556a62fc8SJesse Brandeburg  * @hw: pointer to the hardware structure
412656a62fc8SJesse Brandeburg  * @settings: Filter control settings
412756a62fc8SJesse Brandeburg  *
412856a62fc8SJesse Brandeburg  * Check and validate the filter control settings passed.
412956a62fc8SJesse Brandeburg  * The function checks for the valid filter/context sizes being
413056a62fc8SJesse Brandeburg  * passed for FCoE and PE.
413156a62fc8SJesse Brandeburg  *
413256a62fc8SJesse Brandeburg  * Returns 0 if the values passed are valid and within
413356a62fc8SJesse Brandeburg  * range else returns an error.
413456a62fc8SJesse Brandeburg  **/
41355180ff13SJan Sokolowski static int
i40e_validate_filter_settings(struct i40e_hw * hw,struct i40e_filter_control_settings * settings)41365180ff13SJan Sokolowski i40e_validate_filter_settings(struct i40e_hw *hw,
413756a62fc8SJesse Brandeburg 			      struct i40e_filter_control_settings *settings)
413856a62fc8SJesse Brandeburg {
413956a62fc8SJesse Brandeburg 	u32 fcoe_cntx_size, fcoe_filt_size;
4140467d729aSAnjali Singhai Jain 	u32 fcoe_fmax;
414156a62fc8SJesse Brandeburg 	u32 val;
414256a62fc8SJesse Brandeburg 
414356a62fc8SJesse Brandeburg 	/* Validate FCoE settings passed */
414456a62fc8SJesse Brandeburg 	switch (settings->fcoe_filt_num) {
414556a62fc8SJesse Brandeburg 	case I40E_HASH_FILTER_SIZE_1K:
414656a62fc8SJesse Brandeburg 	case I40E_HASH_FILTER_SIZE_2K:
414756a62fc8SJesse Brandeburg 	case I40E_HASH_FILTER_SIZE_4K:
414856a62fc8SJesse Brandeburg 	case I40E_HASH_FILTER_SIZE_8K:
414956a62fc8SJesse Brandeburg 	case I40E_HASH_FILTER_SIZE_16K:
415056a62fc8SJesse Brandeburg 	case I40E_HASH_FILTER_SIZE_32K:
415156a62fc8SJesse Brandeburg 		fcoe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
415256a62fc8SJesse Brandeburg 		fcoe_filt_size <<= (u32)settings->fcoe_filt_num;
415356a62fc8SJesse Brandeburg 		break;
415456a62fc8SJesse Brandeburg 	default:
4155230f3d53SJan Sokolowski 		return -EINVAL;
415656a62fc8SJesse Brandeburg 	}
415756a62fc8SJesse Brandeburg 
415856a62fc8SJesse Brandeburg 	switch (settings->fcoe_cntx_num) {
415956a62fc8SJesse Brandeburg 	case I40E_DMA_CNTX_SIZE_512:
416056a62fc8SJesse Brandeburg 	case I40E_DMA_CNTX_SIZE_1K:
416156a62fc8SJesse Brandeburg 	case I40E_DMA_CNTX_SIZE_2K:
416256a62fc8SJesse Brandeburg 	case I40E_DMA_CNTX_SIZE_4K:
416356a62fc8SJesse Brandeburg 		fcoe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
416456a62fc8SJesse Brandeburg 		fcoe_cntx_size <<= (u32)settings->fcoe_cntx_num;
416556a62fc8SJesse Brandeburg 		break;
416656a62fc8SJesse Brandeburg 	default:
4167230f3d53SJan Sokolowski 		return -EINVAL;
416856a62fc8SJesse Brandeburg 	}
416956a62fc8SJesse Brandeburg 
417056a62fc8SJesse Brandeburg 	/* Validate PE settings passed */
417156a62fc8SJesse Brandeburg 	switch (settings->pe_filt_num) {
417256a62fc8SJesse Brandeburg 	case I40E_HASH_FILTER_SIZE_1K:
417356a62fc8SJesse Brandeburg 	case I40E_HASH_FILTER_SIZE_2K:
417456a62fc8SJesse Brandeburg 	case I40E_HASH_FILTER_SIZE_4K:
417556a62fc8SJesse Brandeburg 	case I40E_HASH_FILTER_SIZE_8K:
417656a62fc8SJesse Brandeburg 	case I40E_HASH_FILTER_SIZE_16K:
417756a62fc8SJesse Brandeburg 	case I40E_HASH_FILTER_SIZE_32K:
417856a62fc8SJesse Brandeburg 	case I40E_HASH_FILTER_SIZE_64K:
417956a62fc8SJesse Brandeburg 	case I40E_HASH_FILTER_SIZE_128K:
418056a62fc8SJesse Brandeburg 	case I40E_HASH_FILTER_SIZE_256K:
418156a62fc8SJesse Brandeburg 	case I40E_HASH_FILTER_SIZE_512K:
418256a62fc8SJesse Brandeburg 	case I40E_HASH_FILTER_SIZE_1M:
418356a62fc8SJesse Brandeburg 		break;
418456a62fc8SJesse Brandeburg 	default:
4185230f3d53SJan Sokolowski 		return -EINVAL;
418656a62fc8SJesse Brandeburg 	}
418756a62fc8SJesse Brandeburg 
418856a62fc8SJesse Brandeburg 	switch (settings->pe_cntx_num) {
418956a62fc8SJesse Brandeburg 	case I40E_DMA_CNTX_SIZE_512:
419056a62fc8SJesse Brandeburg 	case I40E_DMA_CNTX_SIZE_1K:
419156a62fc8SJesse Brandeburg 	case I40E_DMA_CNTX_SIZE_2K:
419256a62fc8SJesse Brandeburg 	case I40E_DMA_CNTX_SIZE_4K:
419356a62fc8SJesse Brandeburg 	case I40E_DMA_CNTX_SIZE_8K:
419456a62fc8SJesse Brandeburg 	case I40E_DMA_CNTX_SIZE_16K:
419556a62fc8SJesse Brandeburg 	case I40E_DMA_CNTX_SIZE_32K:
419656a62fc8SJesse Brandeburg 	case I40E_DMA_CNTX_SIZE_64K:
419756a62fc8SJesse Brandeburg 	case I40E_DMA_CNTX_SIZE_128K:
419856a62fc8SJesse Brandeburg 	case I40E_DMA_CNTX_SIZE_256K:
419956a62fc8SJesse Brandeburg 		break;
420056a62fc8SJesse Brandeburg 	default:
4201230f3d53SJan Sokolowski 		return -EINVAL;
420256a62fc8SJesse Brandeburg 	}
420356a62fc8SJesse Brandeburg 
420456a62fc8SJesse Brandeburg 	/* FCHSIZE + FCDSIZE should not be greater than PMFCOEFMAX */
420556a62fc8SJesse Brandeburg 	val = rd32(hw, I40E_GLHMC_FCOEFMAX);
420656a62fc8SJesse Brandeburg 	fcoe_fmax = (val & I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_MASK)
420756a62fc8SJesse Brandeburg 		     >> I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_SHIFT;
420856a62fc8SJesse Brandeburg 	if (fcoe_filt_size + fcoe_cntx_size >  fcoe_fmax)
4209230f3d53SJan Sokolowski 		return -EINVAL;
421056a62fc8SJesse Brandeburg 
421156a62fc8SJesse Brandeburg 	return 0;
421256a62fc8SJesse Brandeburg }
421356a62fc8SJesse Brandeburg 
421456a62fc8SJesse Brandeburg /**
421556a62fc8SJesse Brandeburg  * i40e_set_filter_control
421656a62fc8SJesse Brandeburg  * @hw: pointer to the hardware structure
421756a62fc8SJesse Brandeburg  * @settings: Filter control settings
421856a62fc8SJesse Brandeburg  *
421956a62fc8SJesse Brandeburg  * Set the Queue Filters for PE/FCoE and enable filters required
422056a62fc8SJesse Brandeburg  * for a single PF. It is expected that these settings are programmed
422156a62fc8SJesse Brandeburg  * at the driver initialization time.
422256a62fc8SJesse Brandeburg  **/
i40e_set_filter_control(struct i40e_hw * hw,struct i40e_filter_control_settings * settings)42235180ff13SJan Sokolowski int i40e_set_filter_control(struct i40e_hw *hw,
422456a62fc8SJesse Brandeburg 			    struct i40e_filter_control_settings *settings)
422556a62fc8SJesse Brandeburg {
422656a62fc8SJesse Brandeburg 	u32 hash_lut_size = 0;
42275180ff13SJan Sokolowski 	int ret = 0;
422856a62fc8SJesse Brandeburg 	u32 val;
422956a62fc8SJesse Brandeburg 
423056a62fc8SJesse Brandeburg 	if (!settings)
4231230f3d53SJan Sokolowski 		return -EINVAL;
423256a62fc8SJesse Brandeburg 
423356a62fc8SJesse Brandeburg 	/* Validate the input settings */
423456a62fc8SJesse Brandeburg 	ret = i40e_validate_filter_settings(hw, settings);
423556a62fc8SJesse Brandeburg 	if (ret)
423656a62fc8SJesse Brandeburg 		return ret;
423756a62fc8SJesse Brandeburg 
423856a62fc8SJesse Brandeburg 	/* Read the PF Queue Filter control register */
4239f658137cSShannon Nelson 	val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
424056a62fc8SJesse Brandeburg 
424156a62fc8SJesse Brandeburg 	/* Program required PE hash buckets for the PF */
424256a62fc8SJesse Brandeburg 	val &= ~I40E_PFQF_CTL_0_PEHSIZE_MASK;
424356a62fc8SJesse Brandeburg 	val |= ((u32)settings->pe_filt_num << I40E_PFQF_CTL_0_PEHSIZE_SHIFT) &
424456a62fc8SJesse Brandeburg 		I40E_PFQF_CTL_0_PEHSIZE_MASK;
424556a62fc8SJesse Brandeburg 	/* Program required PE contexts for the PF */
424656a62fc8SJesse Brandeburg 	val &= ~I40E_PFQF_CTL_0_PEDSIZE_MASK;
424756a62fc8SJesse Brandeburg 	val |= ((u32)settings->pe_cntx_num << I40E_PFQF_CTL_0_PEDSIZE_SHIFT) &
424856a62fc8SJesse Brandeburg 		I40E_PFQF_CTL_0_PEDSIZE_MASK;
424956a62fc8SJesse Brandeburg 
425056a62fc8SJesse Brandeburg 	/* Program required FCoE hash buckets for the PF */
425156a62fc8SJesse Brandeburg 	val &= ~I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
425256a62fc8SJesse Brandeburg 	val |= ((u32)settings->fcoe_filt_num <<
425356a62fc8SJesse Brandeburg 			I40E_PFQF_CTL_0_PFFCHSIZE_SHIFT) &
425456a62fc8SJesse Brandeburg 		I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
425556a62fc8SJesse Brandeburg 	/* Program required FCoE DDP contexts for the PF */
425656a62fc8SJesse Brandeburg 	val &= ~I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
425756a62fc8SJesse Brandeburg 	val |= ((u32)settings->fcoe_cntx_num <<
425856a62fc8SJesse Brandeburg 			I40E_PFQF_CTL_0_PFFCDSIZE_SHIFT) &
425956a62fc8SJesse Brandeburg 		I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
426056a62fc8SJesse Brandeburg 
426156a62fc8SJesse Brandeburg 	/* Program Hash LUT size for the PF */
426256a62fc8SJesse Brandeburg 	val &= ~I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
426356a62fc8SJesse Brandeburg 	if (settings->hash_lut_size == I40E_HASH_LUT_SIZE_512)
426456a62fc8SJesse Brandeburg 		hash_lut_size = 1;
426556a62fc8SJesse Brandeburg 	val |= (hash_lut_size << I40E_PFQF_CTL_0_HASHLUTSIZE_SHIFT) &
426656a62fc8SJesse Brandeburg 		I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
426756a62fc8SJesse Brandeburg 
426856a62fc8SJesse Brandeburg 	/* Enable FDIR, Ethertype and MACVLAN filters for PF and VFs */
426956a62fc8SJesse Brandeburg 	if (settings->enable_fdir)
427056a62fc8SJesse Brandeburg 		val |= I40E_PFQF_CTL_0_FD_ENA_MASK;
427156a62fc8SJesse Brandeburg 	if (settings->enable_ethtype)
427256a62fc8SJesse Brandeburg 		val |= I40E_PFQF_CTL_0_ETYPE_ENA_MASK;
427356a62fc8SJesse Brandeburg 	if (settings->enable_macvlan)
427456a62fc8SJesse Brandeburg 		val |= I40E_PFQF_CTL_0_MACVLAN_ENA_MASK;
427556a62fc8SJesse Brandeburg 
4276f658137cSShannon Nelson 	i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, val);
427756a62fc8SJesse Brandeburg 
427856a62fc8SJesse Brandeburg 	return 0;
427956a62fc8SJesse Brandeburg }
4280afb3ff0dSNeerav Parikh 
4281afb3ff0dSNeerav Parikh /**
4282afb3ff0dSNeerav Parikh  * i40e_aq_add_rem_control_packet_filter - Add or Remove Control Packet Filter
4283afb3ff0dSNeerav Parikh  * @hw: pointer to the hw struct
4284afb3ff0dSNeerav Parikh  * @mac_addr: MAC address to use in the filter
4285afb3ff0dSNeerav Parikh  * @ethtype: Ethertype to use in the filter
4286afb3ff0dSNeerav Parikh  * @flags: Flags that needs to be applied to the filter
4287afb3ff0dSNeerav Parikh  * @vsi_seid: seid of the control VSI
4288afb3ff0dSNeerav Parikh  * @queue: VSI queue number to send the packet to
4289afb3ff0dSNeerav Parikh  * @is_add: Add control packet filter if True else remove
4290afb3ff0dSNeerav Parikh  * @stats: Structure to hold information on control filter counts
4291afb3ff0dSNeerav Parikh  * @cmd_details: pointer to command details structure or NULL
4292afb3ff0dSNeerav Parikh  *
4293afb3ff0dSNeerav Parikh  * This command will Add or Remove control packet filter for a control VSI.
4294afb3ff0dSNeerav Parikh  * In return it will update the total number of perfect filter count in
4295afb3ff0dSNeerav Parikh  * the stats member.
4296afb3ff0dSNeerav Parikh  **/
i40e_aq_add_rem_control_packet_filter(struct i40e_hw * hw,u8 * mac_addr,u16 ethtype,u16 flags,u16 vsi_seid,u16 queue,bool is_add,struct i40e_control_filter_stats * stats,struct i40e_asq_cmd_details * cmd_details)42975180ff13SJan Sokolowski int i40e_aq_add_rem_control_packet_filter(struct i40e_hw *hw,
4298afb3ff0dSNeerav Parikh 					  u8 *mac_addr, u16 ethtype, u16 flags,
4299afb3ff0dSNeerav Parikh 					  u16 vsi_seid, u16 queue, bool is_add,
4300afb3ff0dSNeerav Parikh 					  struct i40e_control_filter_stats *stats,
4301afb3ff0dSNeerav Parikh 					  struct i40e_asq_cmd_details *cmd_details)
4302afb3ff0dSNeerav Parikh {
4303afb3ff0dSNeerav Parikh 	struct i40e_aq_desc desc;
4304afb3ff0dSNeerav Parikh 	struct i40e_aqc_add_remove_control_packet_filter *cmd =
4305afb3ff0dSNeerav Parikh 		(struct i40e_aqc_add_remove_control_packet_filter *)
4306afb3ff0dSNeerav Parikh 		&desc.params.raw;
4307afb3ff0dSNeerav Parikh 	struct i40e_aqc_add_remove_control_packet_filter_completion *resp =
4308afb3ff0dSNeerav Parikh 		(struct i40e_aqc_add_remove_control_packet_filter_completion *)
4309afb3ff0dSNeerav Parikh 		&desc.params.raw;
43105180ff13SJan Sokolowski 	int status;
4311afb3ff0dSNeerav Parikh 
4312afb3ff0dSNeerav Parikh 	if (vsi_seid == 0)
4313230f3d53SJan Sokolowski 		return -EINVAL;
4314afb3ff0dSNeerav Parikh 
4315afb3ff0dSNeerav Parikh 	if (is_add) {
4316afb3ff0dSNeerav Parikh 		i40e_fill_default_direct_cmd_desc(&desc,
4317afb3ff0dSNeerav Parikh 				i40e_aqc_opc_add_control_packet_filter);
4318afb3ff0dSNeerav Parikh 		cmd->queue = cpu_to_le16(queue);
4319afb3ff0dSNeerav Parikh 	} else {
4320afb3ff0dSNeerav Parikh 		i40e_fill_default_direct_cmd_desc(&desc,
4321afb3ff0dSNeerav Parikh 				i40e_aqc_opc_remove_control_packet_filter);
4322afb3ff0dSNeerav Parikh 	}
4323afb3ff0dSNeerav Parikh 
4324afb3ff0dSNeerav Parikh 	if (mac_addr)
43256995b36cSJesse Brandeburg 		ether_addr_copy(cmd->mac, mac_addr);
4326afb3ff0dSNeerav Parikh 
4327afb3ff0dSNeerav Parikh 	cmd->etype = cpu_to_le16(ethtype);
4328afb3ff0dSNeerav Parikh 	cmd->flags = cpu_to_le16(flags);
4329afb3ff0dSNeerav Parikh 	cmd->seid = cpu_to_le16(vsi_seid);
4330afb3ff0dSNeerav Parikh 
4331afb3ff0dSNeerav Parikh 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4332afb3ff0dSNeerav Parikh 
4333afb3ff0dSNeerav Parikh 	if (!status && stats) {
4334afb3ff0dSNeerav Parikh 		stats->mac_etype_used = le16_to_cpu(resp->mac_etype_used);
4335afb3ff0dSNeerav Parikh 		stats->etype_used = le16_to_cpu(resp->etype_used);
4336afb3ff0dSNeerav Parikh 		stats->mac_etype_free = le16_to_cpu(resp->mac_etype_free);
4337afb3ff0dSNeerav Parikh 		stats->etype_free = le16_to_cpu(resp->etype_free);
4338afb3ff0dSNeerav Parikh 	}
4339afb3ff0dSNeerav Parikh 
4340afb3ff0dSNeerav Parikh 	return status;
4341afb3ff0dSNeerav Parikh }
4342afb3ff0dSNeerav Parikh 
4343d4dfb81aSCatherine Sullivan /**
4344e7358f54SAnjali Singhai Jain  * i40e_add_filter_to_drop_tx_flow_control_frames- filter to drop flow control
4345e7358f54SAnjali Singhai Jain  * @hw: pointer to the hw struct
4346e7358f54SAnjali Singhai Jain  * @seid: VSI seid to add ethertype filter from
4347e7358f54SAnjali Singhai Jain  **/
i40e_add_filter_to_drop_tx_flow_control_frames(struct i40e_hw * hw,u16 seid)4348e7358f54SAnjali Singhai Jain void i40e_add_filter_to_drop_tx_flow_control_frames(struct i40e_hw *hw,
4349e7358f54SAnjali Singhai Jain 						    u16 seid)
4350e7358f54SAnjali Singhai Jain {
4351f5254429SJacob Keller #define I40E_FLOW_CONTROL_ETHTYPE 0x8808
4352e7358f54SAnjali Singhai Jain 	u16 flag = I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC |
4353e7358f54SAnjali Singhai Jain 		   I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP |
4354e7358f54SAnjali Singhai Jain 		   I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX;
4355e7358f54SAnjali Singhai Jain 	u16 ethtype = I40E_FLOW_CONTROL_ETHTYPE;
43565180ff13SJan Sokolowski 	int status;
4357e7358f54SAnjali Singhai Jain 
4358e7358f54SAnjali Singhai Jain 	status = i40e_aq_add_rem_control_packet_filter(hw, NULL, ethtype, flag,
4359e7358f54SAnjali Singhai Jain 						       seid, 0, true, NULL,
4360e7358f54SAnjali Singhai Jain 						       NULL);
4361e7358f54SAnjali Singhai Jain 	if (status)
4362e7358f54SAnjali Singhai Jain 		hw_dbg(hw, "Ethtype Filter Add failed: Error pruning Tx flow control frames\n");
4363e7358f54SAnjali Singhai Jain }
4364e7358f54SAnjali Singhai Jain 
4365e7358f54SAnjali Singhai Jain /**
4366f4492db1SGreg Rose  * i40e_aq_alternate_read
4367f4492db1SGreg Rose  * @hw: pointer to the hardware structure
4368f4492db1SGreg Rose  * @reg_addr0: address of first dword to be read
4369f4492db1SGreg Rose  * @reg_val0: pointer for data read from 'reg_addr0'
4370f4492db1SGreg Rose  * @reg_addr1: address of second dword to be read
4371f4492db1SGreg Rose  * @reg_val1: pointer for data read from 'reg_addr1'
4372f4492db1SGreg Rose  *
4373f4492db1SGreg Rose  * Read one or two dwords from alternate structure. Fields are indicated
4374f4492db1SGreg Rose  * by 'reg_addr0' and 'reg_addr1' register numbers. If 'reg_val1' pointer
4375f4492db1SGreg Rose  * is not passed then only register at 'reg_addr0' is read.
4376f4492db1SGreg Rose  *
4377f4492db1SGreg Rose  **/
i40e_aq_alternate_read(struct i40e_hw * hw,u32 reg_addr0,u32 * reg_val0,u32 reg_addr1,u32 * reg_val1)43785180ff13SJan Sokolowski static int i40e_aq_alternate_read(struct i40e_hw *hw,
4379f4492db1SGreg Rose 				  u32 reg_addr0, u32 *reg_val0,
4380f4492db1SGreg Rose 				  u32 reg_addr1, u32 *reg_val1)
4381f4492db1SGreg Rose {
4382f4492db1SGreg Rose 	struct i40e_aq_desc desc;
4383f4492db1SGreg Rose 	struct i40e_aqc_alternate_write *cmd_resp =
4384f4492db1SGreg Rose 		(struct i40e_aqc_alternate_write *)&desc.params.raw;
43855180ff13SJan Sokolowski 	int status;
4386f4492db1SGreg Rose 
4387f4492db1SGreg Rose 	if (!reg_val0)
4388230f3d53SJan Sokolowski 		return -EINVAL;
4389f4492db1SGreg Rose 
4390f4492db1SGreg Rose 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_alternate_read);
4391f4492db1SGreg Rose 	cmd_resp->address0 = cpu_to_le32(reg_addr0);
4392f4492db1SGreg Rose 	cmd_resp->address1 = cpu_to_le32(reg_addr1);
4393f4492db1SGreg Rose 
4394f4492db1SGreg Rose 	status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
4395f4492db1SGreg Rose 
4396f4492db1SGreg Rose 	if (!status) {
4397f4492db1SGreg Rose 		*reg_val0 = le32_to_cpu(cmd_resp->data0);
4398f4492db1SGreg Rose 
4399f4492db1SGreg Rose 		if (reg_val1)
4400f4492db1SGreg Rose 			*reg_val1 = le32_to_cpu(cmd_resp->data1);
4401f4492db1SGreg Rose 	}
4402f4492db1SGreg Rose 
4403f4492db1SGreg Rose 	return status;
4404f4492db1SGreg Rose }
4405f4492db1SGreg Rose 
4406f4492db1SGreg Rose /**
440790bc8e00SArkadiusz Kubalewski  * i40e_aq_suspend_port_tx
440890bc8e00SArkadiusz Kubalewski  * @hw: pointer to the hardware structure
440990bc8e00SArkadiusz Kubalewski  * @seid: port seid
441090bc8e00SArkadiusz Kubalewski  * @cmd_details: pointer to command details structure or NULL
441190bc8e00SArkadiusz Kubalewski  *
441290bc8e00SArkadiusz Kubalewski  * Suspend port's Tx traffic
441390bc8e00SArkadiusz Kubalewski  **/
i40e_aq_suspend_port_tx(struct i40e_hw * hw,u16 seid,struct i40e_asq_cmd_details * cmd_details)44145180ff13SJan Sokolowski int i40e_aq_suspend_port_tx(struct i40e_hw *hw, u16 seid,
441590bc8e00SArkadiusz Kubalewski 			    struct i40e_asq_cmd_details *cmd_details)
441690bc8e00SArkadiusz Kubalewski {
441790bc8e00SArkadiusz Kubalewski 	struct i40e_aqc_tx_sched_ind *cmd;
441890bc8e00SArkadiusz Kubalewski 	struct i40e_aq_desc desc;
44195180ff13SJan Sokolowski 	int status;
442090bc8e00SArkadiusz Kubalewski 
442190bc8e00SArkadiusz Kubalewski 	cmd = (struct i40e_aqc_tx_sched_ind *)&desc.params.raw;
442290bc8e00SArkadiusz Kubalewski 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_suspend_port_tx);
442390bc8e00SArkadiusz Kubalewski 	cmd->vsi_seid = cpu_to_le16(seid);
442490bc8e00SArkadiusz Kubalewski 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
442590bc8e00SArkadiusz Kubalewski 
442690bc8e00SArkadiusz Kubalewski 	return status;
442790bc8e00SArkadiusz Kubalewski }
442890bc8e00SArkadiusz Kubalewski 
442990bc8e00SArkadiusz Kubalewski /**
44302fd75f31SNeerav Parikh  * i40e_aq_resume_port_tx
44312fd75f31SNeerav Parikh  * @hw: pointer to the hardware structure
44322fd75f31SNeerav Parikh  * @cmd_details: pointer to command details structure or NULL
44332fd75f31SNeerav Parikh  *
44342fd75f31SNeerav Parikh  * Resume port's Tx traffic
44352fd75f31SNeerav Parikh  **/
i40e_aq_resume_port_tx(struct i40e_hw * hw,struct i40e_asq_cmd_details * cmd_details)44365180ff13SJan Sokolowski int i40e_aq_resume_port_tx(struct i40e_hw *hw,
44372fd75f31SNeerav Parikh 			   struct i40e_asq_cmd_details *cmd_details)
44382fd75f31SNeerav Parikh {
44392fd75f31SNeerav Parikh 	struct i40e_aq_desc desc;
44405180ff13SJan Sokolowski 	int status;
44412fd75f31SNeerav Parikh 
44422fd75f31SNeerav Parikh 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_resume_port_tx);
44432fd75f31SNeerav Parikh 
44442fd75f31SNeerav Parikh 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
44452fd75f31SNeerav Parikh 
44462fd75f31SNeerav Parikh 	return status;
44472fd75f31SNeerav Parikh }
44482fd75f31SNeerav Parikh 
44492fd75f31SNeerav Parikh /**
4450d4dfb81aSCatherine Sullivan  * i40e_set_pci_config_data - store PCI bus info
4451d4dfb81aSCatherine Sullivan  * @hw: pointer to hardware structure
4452d4dfb81aSCatherine Sullivan  * @link_status: the link status word from PCI config space
4453d4dfb81aSCatherine Sullivan  *
4454d4dfb81aSCatherine Sullivan  * Stores the PCI bus info (speed, width, type) within the i40e_hw structure
4455d4dfb81aSCatherine Sullivan  **/
i40e_set_pci_config_data(struct i40e_hw * hw,u16 link_status)4456d4dfb81aSCatherine Sullivan void i40e_set_pci_config_data(struct i40e_hw *hw, u16 link_status)
4457d4dfb81aSCatherine Sullivan {
4458d4dfb81aSCatherine Sullivan 	hw->bus.type = i40e_bus_type_pci_express;
4459d4dfb81aSCatherine Sullivan 
4460d4dfb81aSCatherine Sullivan 	switch (link_status & PCI_EXP_LNKSTA_NLW) {
4461d4dfb81aSCatherine Sullivan 	case PCI_EXP_LNKSTA_NLW_X1:
4462d4dfb81aSCatherine Sullivan 		hw->bus.width = i40e_bus_width_pcie_x1;
4463d4dfb81aSCatherine Sullivan 		break;
4464d4dfb81aSCatherine Sullivan 	case PCI_EXP_LNKSTA_NLW_X2:
4465d4dfb81aSCatherine Sullivan 		hw->bus.width = i40e_bus_width_pcie_x2;
4466d4dfb81aSCatherine Sullivan 		break;
4467d4dfb81aSCatherine Sullivan 	case PCI_EXP_LNKSTA_NLW_X4:
4468d4dfb81aSCatherine Sullivan 		hw->bus.width = i40e_bus_width_pcie_x4;
4469d4dfb81aSCatherine Sullivan 		break;
4470d4dfb81aSCatherine Sullivan 	case PCI_EXP_LNKSTA_NLW_X8:
4471d4dfb81aSCatherine Sullivan 		hw->bus.width = i40e_bus_width_pcie_x8;
4472d4dfb81aSCatherine Sullivan 		break;
4473d4dfb81aSCatherine Sullivan 	default:
4474d4dfb81aSCatherine Sullivan 		hw->bus.width = i40e_bus_width_unknown;
4475d4dfb81aSCatherine Sullivan 		break;
4476d4dfb81aSCatherine Sullivan 	}
4477d4dfb81aSCatherine Sullivan 
4478d4dfb81aSCatherine Sullivan 	switch (link_status & PCI_EXP_LNKSTA_CLS) {
4479d4dfb81aSCatherine Sullivan 	case PCI_EXP_LNKSTA_CLS_2_5GB:
4480d4dfb81aSCatherine Sullivan 		hw->bus.speed = i40e_bus_speed_2500;
4481d4dfb81aSCatherine Sullivan 		break;
4482d4dfb81aSCatherine Sullivan 	case PCI_EXP_LNKSTA_CLS_5_0GB:
4483d4dfb81aSCatherine Sullivan 		hw->bus.speed = i40e_bus_speed_5000;
4484d4dfb81aSCatherine Sullivan 		break;
4485d4dfb81aSCatherine Sullivan 	case PCI_EXP_LNKSTA_CLS_8_0GB:
4486d4dfb81aSCatherine Sullivan 		hw->bus.speed = i40e_bus_speed_8000;
4487d4dfb81aSCatherine Sullivan 		break;
4488d4dfb81aSCatherine Sullivan 	default:
4489d4dfb81aSCatherine Sullivan 		hw->bus.speed = i40e_bus_speed_unknown;
4490d4dfb81aSCatherine Sullivan 		break;
4491d4dfb81aSCatherine Sullivan 	}
4492d4dfb81aSCatherine Sullivan }
4493f4492db1SGreg Rose 
4494f4492db1SGreg Rose /**
44953169c323SJesse Brandeburg  * i40e_aq_debug_dump
44963169c323SJesse Brandeburg  * @hw: pointer to the hardware structure
44973169c323SJesse Brandeburg  * @cluster_id: specific cluster to dump
44983169c323SJesse Brandeburg  * @table_id: table id within cluster
44993169c323SJesse Brandeburg  * @start_index: index of line in the block to read
45003169c323SJesse Brandeburg  * @buff_size: dump buffer size
45013169c323SJesse Brandeburg  * @buff: dump buffer
45023169c323SJesse Brandeburg  * @ret_buff_size: actual buffer size returned
45033169c323SJesse Brandeburg  * @ret_next_table: next block to read
45043169c323SJesse Brandeburg  * @ret_next_index: next index to read
4505f5254429SJacob Keller  * @cmd_details: pointer to command details structure or NULL
45063169c323SJesse Brandeburg  *
45073169c323SJesse Brandeburg  * Dump internal FW/HW data for debug purposes.
45083169c323SJesse Brandeburg  *
45093169c323SJesse Brandeburg  **/
i40e_aq_debug_dump(struct i40e_hw * hw,u8 cluster_id,u8 table_id,u32 start_index,u16 buff_size,void * buff,u16 * ret_buff_size,u8 * ret_next_table,u32 * ret_next_index,struct i40e_asq_cmd_details * cmd_details)45105180ff13SJan Sokolowski int i40e_aq_debug_dump(struct i40e_hw *hw, u8 cluster_id,
45113169c323SJesse Brandeburg 		       u8 table_id, u32 start_index, u16 buff_size,
45123169c323SJesse Brandeburg 		       void *buff, u16 *ret_buff_size,
45133169c323SJesse Brandeburg 		       u8 *ret_next_table, u32 *ret_next_index,
45143169c323SJesse Brandeburg 		       struct i40e_asq_cmd_details *cmd_details)
45153169c323SJesse Brandeburg {
45163169c323SJesse Brandeburg 	struct i40e_aq_desc desc;
45173169c323SJesse Brandeburg 	struct i40e_aqc_debug_dump_internals *cmd =
45183169c323SJesse Brandeburg 		(struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
45193169c323SJesse Brandeburg 	struct i40e_aqc_debug_dump_internals *resp =
45203169c323SJesse Brandeburg 		(struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
45215180ff13SJan Sokolowski 	int status;
45223169c323SJesse Brandeburg 
45233169c323SJesse Brandeburg 	if (buff_size == 0 || !buff)
4524230f3d53SJan Sokolowski 		return -EINVAL;
45253169c323SJesse Brandeburg 
45263169c323SJesse Brandeburg 	i40e_fill_default_direct_cmd_desc(&desc,
45273169c323SJesse Brandeburg 					  i40e_aqc_opc_debug_dump_internals);
45283169c323SJesse Brandeburg 	/* Indirect Command */
45293169c323SJesse Brandeburg 	desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
45303169c323SJesse Brandeburg 	if (buff_size > I40E_AQ_LARGE_BUF)
45313169c323SJesse Brandeburg 		desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
45323169c323SJesse Brandeburg 
45333169c323SJesse Brandeburg 	cmd->cluster_id = cluster_id;
45343169c323SJesse Brandeburg 	cmd->table_id = table_id;
45353169c323SJesse Brandeburg 	cmd->idx = cpu_to_le32(start_index);
45363169c323SJesse Brandeburg 
45373169c323SJesse Brandeburg 	desc.datalen = cpu_to_le16(buff_size);
45383169c323SJesse Brandeburg 
45393169c323SJesse Brandeburg 	status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
45403169c323SJesse Brandeburg 	if (!status) {
45413169c323SJesse Brandeburg 		if (ret_buff_size)
45423169c323SJesse Brandeburg 			*ret_buff_size = le16_to_cpu(desc.datalen);
45433169c323SJesse Brandeburg 		if (ret_next_table)
45443169c323SJesse Brandeburg 			*ret_next_table = resp->table_id;
45453169c323SJesse Brandeburg 		if (ret_next_index)
45463169c323SJesse Brandeburg 			*ret_next_index = le32_to_cpu(resp->idx);
45473169c323SJesse Brandeburg 	}
45483169c323SJesse Brandeburg 
45493169c323SJesse Brandeburg 	return status;
45503169c323SJesse Brandeburg }
45513169c323SJesse Brandeburg 
45523169c323SJesse Brandeburg /**
4553f4492db1SGreg Rose  * i40e_read_bw_from_alt_ram
4554f4492db1SGreg Rose  * @hw: pointer to the hardware structure
4555f4492db1SGreg Rose  * @max_bw: pointer for max_bw read
4556f4492db1SGreg Rose  * @min_bw: pointer for min_bw read
4557f4492db1SGreg Rose  * @min_valid: pointer for bool that is true if min_bw is a valid value
4558f4492db1SGreg Rose  * @max_valid: pointer for bool that is true if max_bw is a valid value
4559f4492db1SGreg Rose  *
4560f4492db1SGreg Rose  * Read bw from the alternate ram for the given pf
4561f4492db1SGreg Rose  **/
i40e_read_bw_from_alt_ram(struct i40e_hw * hw,u32 * max_bw,u32 * min_bw,bool * min_valid,bool * max_valid)45625180ff13SJan Sokolowski int i40e_read_bw_from_alt_ram(struct i40e_hw *hw,
4563f4492db1SGreg Rose 			      u32 *max_bw, u32 *min_bw,
4564f4492db1SGreg Rose 			      bool *min_valid, bool *max_valid)
4565f4492db1SGreg Rose {
4566f4492db1SGreg Rose 	u32 max_bw_addr, min_bw_addr;
45675180ff13SJan Sokolowski 	int status;
4568f4492db1SGreg Rose 
4569f4492db1SGreg Rose 	/* Calculate the address of the min/max bw registers */
4570f4492db1SGreg Rose 	max_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
4571f4492db1SGreg Rose 		      I40E_ALT_STRUCT_MAX_BW_OFFSET +
4572f4492db1SGreg Rose 		      (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
4573f4492db1SGreg Rose 	min_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
4574f4492db1SGreg Rose 		      I40E_ALT_STRUCT_MIN_BW_OFFSET +
4575f4492db1SGreg Rose 		      (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
4576f4492db1SGreg Rose 
4577f4492db1SGreg Rose 	/* Read the bandwidths from alt ram */
4578f4492db1SGreg Rose 	status = i40e_aq_alternate_read(hw, max_bw_addr, max_bw,
4579f4492db1SGreg Rose 					min_bw_addr, min_bw);
4580f4492db1SGreg Rose 
4581f4492db1SGreg Rose 	if (*min_bw & I40E_ALT_BW_VALID_MASK)
4582f4492db1SGreg Rose 		*min_valid = true;
4583f4492db1SGreg Rose 	else
4584f4492db1SGreg Rose 		*min_valid = false;
4585f4492db1SGreg Rose 
4586f4492db1SGreg Rose 	if (*max_bw & I40E_ALT_BW_VALID_MASK)
4587f4492db1SGreg Rose 		*max_valid = true;
4588f4492db1SGreg Rose 	else
4589f4492db1SGreg Rose 		*max_valid = false;
4590f4492db1SGreg Rose 
4591f4492db1SGreg Rose 	return status;
4592f4492db1SGreg Rose }
4593f4492db1SGreg Rose 
4594f4492db1SGreg Rose /**
4595f4492db1SGreg Rose  * i40e_aq_configure_partition_bw
4596f4492db1SGreg Rose  * @hw: pointer to the hardware structure
4597f4492db1SGreg Rose  * @bw_data: Buffer holding valid pfs and bw limits
4598f4492db1SGreg Rose  * @cmd_details: pointer to command details
4599f4492db1SGreg Rose  *
4600f4492db1SGreg Rose  * Configure partitions guaranteed/max bw
4601f4492db1SGreg Rose  **/
46025180ff13SJan Sokolowski int
i40e_aq_configure_partition_bw(struct i40e_hw * hw,struct i40e_aqc_configure_partition_bw_data * bw_data,struct i40e_asq_cmd_details * cmd_details)46035180ff13SJan Sokolowski i40e_aq_configure_partition_bw(struct i40e_hw *hw,
4604f4492db1SGreg Rose 			       struct i40e_aqc_configure_partition_bw_data *bw_data,
4605f4492db1SGreg Rose 			       struct i40e_asq_cmd_details *cmd_details)
4606f4492db1SGreg Rose {
4607f4492db1SGreg Rose 	u16 bwd_size = sizeof(*bw_data);
46085180ff13SJan Sokolowski 	struct i40e_aq_desc desc;
46095180ff13SJan Sokolowski 	int status;
4610f4492db1SGreg Rose 
4611f4492db1SGreg Rose 	i40e_fill_default_direct_cmd_desc(&desc,
4612f4492db1SGreg Rose 					  i40e_aqc_opc_configure_partition_bw);
4613f4492db1SGreg Rose 
4614f4492db1SGreg Rose 	/* Indirect command */
4615f4492db1SGreg Rose 	desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
4616f4492db1SGreg Rose 	desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
4617f4492db1SGreg Rose 
4618f4492db1SGreg Rose 	if (bwd_size > I40E_AQ_LARGE_BUF)
4619f4492db1SGreg Rose 		desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
4620f4492db1SGreg Rose 
4621f4492db1SGreg Rose 	desc.datalen = cpu_to_le16(bwd_size);
4622f4492db1SGreg Rose 
4623f4492db1SGreg Rose 	status = i40e_asq_send_command(hw, &desc, bw_data, bwd_size,
4624f4492db1SGreg Rose 				       cmd_details);
4625f4492db1SGreg Rose 
4626f4492db1SGreg Rose 	return status;
4627f4492db1SGreg Rose }
4628fd077cd3SCarolyn Wyborny 
4629fd077cd3SCarolyn Wyborny /**
463091dc1e5dSMichal Kosiarz  * i40e_read_phy_register_clause22
463191dc1e5dSMichal Kosiarz  * @hw: pointer to the HW structure
463291dc1e5dSMichal Kosiarz  * @reg: register address in the page
4633f5254429SJacob Keller  * @phy_addr: PHY address on MDIO interface
463491dc1e5dSMichal Kosiarz  * @value: PHY register value
463591dc1e5dSMichal Kosiarz  *
463691dc1e5dSMichal Kosiarz  * Reads specified PHY register value
463791dc1e5dSMichal Kosiarz  **/
i40e_read_phy_register_clause22(struct i40e_hw * hw,u16 reg,u8 phy_addr,u16 * value)46385180ff13SJan Sokolowski int i40e_read_phy_register_clause22(struct i40e_hw *hw,
463991dc1e5dSMichal Kosiarz 				    u16 reg, u8 phy_addr, u16 *value)
464091dc1e5dSMichal Kosiarz {
464191dc1e5dSMichal Kosiarz 	u8 port_num = (u8)hw->func_caps.mdio_port_num;
4642230f3d53SJan Sokolowski 	int status = -EIO;
464391dc1e5dSMichal Kosiarz 	u32 command = 0;
464491dc1e5dSMichal Kosiarz 	u16 retry = 1000;
464591dc1e5dSMichal Kosiarz 
464691dc1e5dSMichal Kosiarz 	command = (reg << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
464791dc1e5dSMichal Kosiarz 		  (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
464891dc1e5dSMichal Kosiarz 		  (I40E_MDIO_CLAUSE22_OPCODE_READ_MASK) |
464991dc1e5dSMichal Kosiarz 		  (I40E_MDIO_CLAUSE22_STCODE_MASK) |
465091dc1e5dSMichal Kosiarz 		  (I40E_GLGEN_MSCA_MDICMD_MASK);
465191dc1e5dSMichal Kosiarz 	wr32(hw, I40E_GLGEN_MSCA(port_num), command);
465291dc1e5dSMichal Kosiarz 	do {
465391dc1e5dSMichal Kosiarz 		command = rd32(hw, I40E_GLGEN_MSCA(port_num));
465491dc1e5dSMichal Kosiarz 		if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
465591dc1e5dSMichal Kosiarz 			status = 0;
465691dc1e5dSMichal Kosiarz 			break;
465791dc1e5dSMichal Kosiarz 		}
465891dc1e5dSMichal Kosiarz 		udelay(10);
465991dc1e5dSMichal Kosiarz 		retry--;
466091dc1e5dSMichal Kosiarz 	} while (retry);
466191dc1e5dSMichal Kosiarz 
466291dc1e5dSMichal Kosiarz 	if (status) {
466391dc1e5dSMichal Kosiarz 		i40e_debug(hw, I40E_DEBUG_PHY,
466491dc1e5dSMichal Kosiarz 			   "PHY: Can't write command to external PHY.\n");
466527e5f25bSHenry Tieman 	} else {
466691dc1e5dSMichal Kosiarz 		command = rd32(hw, I40E_GLGEN_MSRWD(port_num));
466791dc1e5dSMichal Kosiarz 		*value = (command & I40E_GLGEN_MSRWD_MDIRDDATA_MASK) >>
466891dc1e5dSMichal Kosiarz 			 I40E_GLGEN_MSRWD_MDIRDDATA_SHIFT;
466991dc1e5dSMichal Kosiarz 	}
467091dc1e5dSMichal Kosiarz 
467191dc1e5dSMichal Kosiarz 	return status;
467291dc1e5dSMichal Kosiarz }
467391dc1e5dSMichal Kosiarz 
467491dc1e5dSMichal Kosiarz /**
467591dc1e5dSMichal Kosiarz  * i40e_write_phy_register_clause22
467691dc1e5dSMichal Kosiarz  * @hw: pointer to the HW structure
467791dc1e5dSMichal Kosiarz  * @reg: register address in the page
4678f5254429SJacob Keller  * @phy_addr: PHY address on MDIO interface
467991dc1e5dSMichal Kosiarz  * @value: PHY register value
468091dc1e5dSMichal Kosiarz  *
468191dc1e5dSMichal Kosiarz  * Writes specified PHY register value
468291dc1e5dSMichal Kosiarz  **/
i40e_write_phy_register_clause22(struct i40e_hw * hw,u16 reg,u8 phy_addr,u16 value)46835180ff13SJan Sokolowski int i40e_write_phy_register_clause22(struct i40e_hw *hw,
468491dc1e5dSMichal Kosiarz 				     u16 reg, u8 phy_addr, u16 value)
468591dc1e5dSMichal Kosiarz {
468691dc1e5dSMichal Kosiarz 	u8 port_num = (u8)hw->func_caps.mdio_port_num;
4687230f3d53SJan Sokolowski 	int status = -EIO;
468891dc1e5dSMichal Kosiarz 	u32 command  = 0;
468991dc1e5dSMichal Kosiarz 	u16 retry = 1000;
469091dc1e5dSMichal Kosiarz 
469191dc1e5dSMichal Kosiarz 	command = value << I40E_GLGEN_MSRWD_MDIWRDATA_SHIFT;
469291dc1e5dSMichal Kosiarz 	wr32(hw, I40E_GLGEN_MSRWD(port_num), command);
469391dc1e5dSMichal Kosiarz 
469491dc1e5dSMichal Kosiarz 	command = (reg << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
469591dc1e5dSMichal Kosiarz 		  (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
469691dc1e5dSMichal Kosiarz 		  (I40E_MDIO_CLAUSE22_OPCODE_WRITE_MASK) |
469791dc1e5dSMichal Kosiarz 		  (I40E_MDIO_CLAUSE22_STCODE_MASK) |
469891dc1e5dSMichal Kosiarz 		  (I40E_GLGEN_MSCA_MDICMD_MASK);
469991dc1e5dSMichal Kosiarz 
470091dc1e5dSMichal Kosiarz 	wr32(hw, I40E_GLGEN_MSCA(port_num), command);
470191dc1e5dSMichal Kosiarz 	do {
470291dc1e5dSMichal Kosiarz 		command = rd32(hw, I40E_GLGEN_MSCA(port_num));
470391dc1e5dSMichal Kosiarz 		if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
470491dc1e5dSMichal Kosiarz 			status = 0;
470591dc1e5dSMichal Kosiarz 			break;
470691dc1e5dSMichal Kosiarz 		}
470791dc1e5dSMichal Kosiarz 		udelay(10);
470891dc1e5dSMichal Kosiarz 		retry--;
470991dc1e5dSMichal Kosiarz 	} while (retry);
471091dc1e5dSMichal Kosiarz 
471191dc1e5dSMichal Kosiarz 	return status;
471291dc1e5dSMichal Kosiarz }
471391dc1e5dSMichal Kosiarz 
471491dc1e5dSMichal Kosiarz /**
471591dc1e5dSMichal Kosiarz  * i40e_read_phy_register_clause45
4716fd077cd3SCarolyn Wyborny  * @hw: pointer to the HW structure
4717fd077cd3SCarolyn Wyborny  * @page: registers page number
4718fd077cd3SCarolyn Wyborny  * @reg: register address in the page
4719f5254429SJacob Keller  * @phy_addr: PHY address on MDIO interface
4720fd077cd3SCarolyn Wyborny  * @value: PHY register value
4721fd077cd3SCarolyn Wyborny  *
4722fd077cd3SCarolyn Wyborny  * Reads specified PHY register value
4723fd077cd3SCarolyn Wyborny  **/
i40e_read_phy_register_clause45(struct i40e_hw * hw,u8 page,u16 reg,u8 phy_addr,u16 * value)47245180ff13SJan Sokolowski int i40e_read_phy_register_clause45(struct i40e_hw *hw,
472591dc1e5dSMichal Kosiarz 				    u8 page, u16 reg, u8 phy_addr, u16 *value)
4726fd077cd3SCarolyn Wyborny {
47275180ff13SJan Sokolowski 	u8 port_num = hw->func_caps.mdio_port_num;
4728230f3d53SJan Sokolowski 	int status = -EIO;
4729fd077cd3SCarolyn Wyborny 	u32 command = 0;
4730fd077cd3SCarolyn Wyborny 	u16 retry = 1000;
4731fd077cd3SCarolyn Wyborny 
4732fd077cd3SCarolyn Wyborny 	command = (reg << I40E_GLGEN_MSCA_MDIADD_SHIFT) |
4733fd077cd3SCarolyn Wyborny 		  (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4734fd077cd3SCarolyn Wyborny 		  (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
473591dc1e5dSMichal Kosiarz 		  (I40E_MDIO_CLAUSE45_OPCODE_ADDRESS_MASK) |
473691dc1e5dSMichal Kosiarz 		  (I40E_MDIO_CLAUSE45_STCODE_MASK) |
4737fd077cd3SCarolyn Wyborny 		  (I40E_GLGEN_MSCA_MDICMD_MASK) |
4738fd077cd3SCarolyn Wyborny 		  (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4739fd077cd3SCarolyn Wyborny 	wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4740fd077cd3SCarolyn Wyborny 	do {
4741fd077cd3SCarolyn Wyborny 		command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4742fd077cd3SCarolyn Wyborny 		if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4743fd077cd3SCarolyn Wyborny 			status = 0;
4744fd077cd3SCarolyn Wyborny 			break;
4745fd077cd3SCarolyn Wyborny 		}
4746fd077cd3SCarolyn Wyborny 		usleep_range(10, 20);
4747fd077cd3SCarolyn Wyborny 		retry--;
4748fd077cd3SCarolyn Wyborny 	} while (retry);
4749fd077cd3SCarolyn Wyborny 
4750fd077cd3SCarolyn Wyborny 	if (status) {
4751fd077cd3SCarolyn Wyborny 		i40e_debug(hw, I40E_DEBUG_PHY,
4752fd077cd3SCarolyn Wyborny 			   "PHY: Can't write command to external PHY.\n");
4753fd077cd3SCarolyn Wyborny 		goto phy_read_end;
4754fd077cd3SCarolyn Wyborny 	}
4755fd077cd3SCarolyn Wyborny 
4756fd077cd3SCarolyn Wyborny 	command = (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4757fd077cd3SCarolyn Wyborny 		  (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
475891dc1e5dSMichal Kosiarz 		  (I40E_MDIO_CLAUSE45_OPCODE_READ_MASK) |
475991dc1e5dSMichal Kosiarz 		  (I40E_MDIO_CLAUSE45_STCODE_MASK) |
4760fd077cd3SCarolyn Wyborny 		  (I40E_GLGEN_MSCA_MDICMD_MASK) |
4761fd077cd3SCarolyn Wyborny 		  (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4762230f3d53SJan Sokolowski 	status = -EIO;
4763fd077cd3SCarolyn Wyborny 	retry = 1000;
4764fd077cd3SCarolyn Wyborny 	wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4765fd077cd3SCarolyn Wyborny 	do {
4766fd077cd3SCarolyn Wyborny 		command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4767fd077cd3SCarolyn Wyborny 		if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4768fd077cd3SCarolyn Wyborny 			status = 0;
4769fd077cd3SCarolyn Wyborny 			break;
4770fd077cd3SCarolyn Wyborny 		}
4771fd077cd3SCarolyn Wyborny 		usleep_range(10, 20);
4772fd077cd3SCarolyn Wyborny 		retry--;
4773fd077cd3SCarolyn Wyborny 	} while (retry);
4774fd077cd3SCarolyn Wyborny 
4775fd077cd3SCarolyn Wyborny 	if (!status) {
4776fd077cd3SCarolyn Wyborny 		command = rd32(hw, I40E_GLGEN_MSRWD(port_num));
4777fd077cd3SCarolyn Wyborny 		*value = (command & I40E_GLGEN_MSRWD_MDIRDDATA_MASK) >>
4778fd077cd3SCarolyn Wyborny 			 I40E_GLGEN_MSRWD_MDIRDDATA_SHIFT;
4779fd077cd3SCarolyn Wyborny 	} else {
4780fd077cd3SCarolyn Wyborny 		i40e_debug(hw, I40E_DEBUG_PHY,
4781fd077cd3SCarolyn Wyborny 			   "PHY: Can't read register value from external PHY.\n");
4782fd077cd3SCarolyn Wyborny 	}
4783fd077cd3SCarolyn Wyborny 
4784fd077cd3SCarolyn Wyborny phy_read_end:
4785fd077cd3SCarolyn Wyborny 	return status;
4786fd077cd3SCarolyn Wyborny }
4787fd077cd3SCarolyn Wyborny 
4788fd077cd3SCarolyn Wyborny /**
478991dc1e5dSMichal Kosiarz  * i40e_write_phy_register_clause45
4790fd077cd3SCarolyn Wyborny  * @hw: pointer to the HW structure
4791fd077cd3SCarolyn Wyborny  * @page: registers page number
4792fd077cd3SCarolyn Wyborny  * @reg: register address in the page
4793f5254429SJacob Keller  * @phy_addr: PHY address on MDIO interface
4794fd077cd3SCarolyn Wyborny  * @value: PHY register value
4795fd077cd3SCarolyn Wyborny  *
4796fd077cd3SCarolyn Wyborny  * Writes value to specified PHY register
4797fd077cd3SCarolyn Wyborny  **/
i40e_write_phy_register_clause45(struct i40e_hw * hw,u8 page,u16 reg,u8 phy_addr,u16 value)47985180ff13SJan Sokolowski int i40e_write_phy_register_clause45(struct i40e_hw *hw,
479991dc1e5dSMichal Kosiarz 				     u8 page, u16 reg, u8 phy_addr, u16 value)
4800fd077cd3SCarolyn Wyborny {
4801fd077cd3SCarolyn Wyborny 	u8 port_num = hw->func_caps.mdio_port_num;
4802230f3d53SJan Sokolowski 	int status = -EIO;
48035180ff13SJan Sokolowski 	u16 retry = 1000;
48045180ff13SJan Sokolowski 	u32 command = 0;
4805fd077cd3SCarolyn Wyborny 
4806fd077cd3SCarolyn Wyborny 	command = (reg << I40E_GLGEN_MSCA_MDIADD_SHIFT) |
4807fd077cd3SCarolyn Wyborny 		  (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4808fd077cd3SCarolyn Wyborny 		  (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
480991dc1e5dSMichal Kosiarz 		  (I40E_MDIO_CLAUSE45_OPCODE_ADDRESS_MASK) |
481091dc1e5dSMichal Kosiarz 		  (I40E_MDIO_CLAUSE45_STCODE_MASK) |
4811fd077cd3SCarolyn Wyborny 		  (I40E_GLGEN_MSCA_MDICMD_MASK) |
4812fd077cd3SCarolyn Wyborny 		  (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4813fd077cd3SCarolyn Wyborny 	wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4814fd077cd3SCarolyn Wyborny 	do {
4815fd077cd3SCarolyn Wyborny 		command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4816fd077cd3SCarolyn Wyborny 		if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4817fd077cd3SCarolyn Wyborny 			status = 0;
4818fd077cd3SCarolyn Wyborny 			break;
4819fd077cd3SCarolyn Wyborny 		}
4820fd077cd3SCarolyn Wyborny 		usleep_range(10, 20);
4821fd077cd3SCarolyn Wyborny 		retry--;
4822fd077cd3SCarolyn Wyborny 	} while (retry);
4823fd077cd3SCarolyn Wyborny 	if (status) {
4824fd077cd3SCarolyn Wyborny 		i40e_debug(hw, I40E_DEBUG_PHY,
4825fd077cd3SCarolyn Wyborny 			   "PHY: Can't write command to external PHY.\n");
4826fd077cd3SCarolyn Wyborny 		goto phy_write_end;
4827fd077cd3SCarolyn Wyborny 	}
4828fd077cd3SCarolyn Wyborny 
4829fd077cd3SCarolyn Wyborny 	command = value << I40E_GLGEN_MSRWD_MDIWRDATA_SHIFT;
4830fd077cd3SCarolyn Wyborny 	wr32(hw, I40E_GLGEN_MSRWD(port_num), command);
4831fd077cd3SCarolyn Wyborny 
4832fd077cd3SCarolyn Wyborny 	command = (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
4833fd077cd3SCarolyn Wyborny 		  (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
483491dc1e5dSMichal Kosiarz 		  (I40E_MDIO_CLAUSE45_OPCODE_WRITE_MASK) |
483591dc1e5dSMichal Kosiarz 		  (I40E_MDIO_CLAUSE45_STCODE_MASK) |
4836fd077cd3SCarolyn Wyborny 		  (I40E_GLGEN_MSCA_MDICMD_MASK) |
4837fd077cd3SCarolyn Wyborny 		  (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
4838230f3d53SJan Sokolowski 	status = -EIO;
4839fd077cd3SCarolyn Wyborny 	retry = 1000;
4840fd077cd3SCarolyn Wyborny 	wr32(hw, I40E_GLGEN_MSCA(port_num), command);
4841fd077cd3SCarolyn Wyborny 	do {
4842fd077cd3SCarolyn Wyborny 		command = rd32(hw, I40E_GLGEN_MSCA(port_num));
4843fd077cd3SCarolyn Wyborny 		if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
4844fd077cd3SCarolyn Wyborny 			status = 0;
4845fd077cd3SCarolyn Wyborny 			break;
4846fd077cd3SCarolyn Wyborny 		}
4847fd077cd3SCarolyn Wyborny 		usleep_range(10, 20);
4848fd077cd3SCarolyn Wyborny 		retry--;
4849fd077cd3SCarolyn Wyborny 	} while (retry);
4850fd077cd3SCarolyn Wyborny 
4851fd077cd3SCarolyn Wyborny phy_write_end:
4852fd077cd3SCarolyn Wyborny 	return status;
4853fd077cd3SCarolyn Wyborny }
4854fd077cd3SCarolyn Wyborny 
4855fd077cd3SCarolyn Wyborny /**
4856f62ba914SMichal Kosiarz  * i40e_write_phy_register
4857f62ba914SMichal Kosiarz  * @hw: pointer to the HW structure
4858f62ba914SMichal Kosiarz  * @page: registers page number
4859f62ba914SMichal Kosiarz  * @reg: register address in the page
4860f5254429SJacob Keller  * @phy_addr: PHY address on MDIO interface
4861f62ba914SMichal Kosiarz  * @value: PHY register value
4862f62ba914SMichal Kosiarz  *
4863f62ba914SMichal Kosiarz  * Writes value to specified PHY register
4864f62ba914SMichal Kosiarz  **/
i40e_write_phy_register(struct i40e_hw * hw,u8 page,u16 reg,u8 phy_addr,u16 value)48655180ff13SJan Sokolowski int i40e_write_phy_register(struct i40e_hw *hw,
4866f62ba914SMichal Kosiarz 			    u8 page, u16 reg, u8 phy_addr, u16 value)
4867f62ba914SMichal Kosiarz {
48685180ff13SJan Sokolowski 	int status;
4869f62ba914SMichal Kosiarz 
4870f62ba914SMichal Kosiarz 	switch (hw->device_id) {
4871f62ba914SMichal Kosiarz 	case I40E_DEV_ID_1G_BASE_T_X722:
4872f62ba914SMichal Kosiarz 		status = i40e_write_phy_register_clause22(hw, reg, phy_addr,
4873f62ba914SMichal Kosiarz 							  value);
4874f62ba914SMichal Kosiarz 		break;
48756617be3cSStanislaw Grzeszczak 	case I40E_DEV_ID_1G_BASE_T_BC:
48763dbdd6c2SAleksandr Loktionov 	case I40E_DEV_ID_5G_BASE_T_BC:
4877f62ba914SMichal Kosiarz 	case I40E_DEV_ID_10G_BASE_T:
4878f62ba914SMichal Kosiarz 	case I40E_DEV_ID_10G_BASE_T4:
48793df5b9a6SAlice Michael 	case I40E_DEV_ID_10G_BASE_T_BC:
4880f62ba914SMichal Kosiarz 	case I40E_DEV_ID_10G_BASE_T_X722:
4881f62ba914SMichal Kosiarz 	case I40E_DEV_ID_25G_B:
4882f62ba914SMichal Kosiarz 	case I40E_DEV_ID_25G_SFP28:
4883f62ba914SMichal Kosiarz 		status = i40e_write_phy_register_clause45(hw, page, reg,
4884f62ba914SMichal Kosiarz 							  phy_addr, value);
4885f62ba914SMichal Kosiarz 		break;
4886f62ba914SMichal Kosiarz 	default:
4887230f3d53SJan Sokolowski 		status = -EIO;
4888f62ba914SMichal Kosiarz 		break;
4889f62ba914SMichal Kosiarz 	}
4890f62ba914SMichal Kosiarz 
4891f62ba914SMichal Kosiarz 	return status;
4892f62ba914SMichal Kosiarz }
4893f62ba914SMichal Kosiarz 
4894f62ba914SMichal Kosiarz /**
4895f62ba914SMichal Kosiarz  * i40e_read_phy_register
4896f62ba914SMichal Kosiarz  * @hw: pointer to the HW structure
4897f62ba914SMichal Kosiarz  * @page: registers page number
4898f62ba914SMichal Kosiarz  * @reg: register address in the page
4899f5254429SJacob Keller  * @phy_addr: PHY address on MDIO interface
4900f62ba914SMichal Kosiarz  * @value: PHY register value
4901f62ba914SMichal Kosiarz  *
4902f62ba914SMichal Kosiarz  * Reads specified PHY register value
4903f62ba914SMichal Kosiarz  **/
i40e_read_phy_register(struct i40e_hw * hw,u8 page,u16 reg,u8 phy_addr,u16 * value)49045180ff13SJan Sokolowski int i40e_read_phy_register(struct i40e_hw *hw,
4905f62ba914SMichal Kosiarz 			   u8 page, u16 reg, u8 phy_addr, u16 *value)
4906f62ba914SMichal Kosiarz {
49075180ff13SJan Sokolowski 	int status;
4908f62ba914SMichal Kosiarz 
4909f62ba914SMichal Kosiarz 	switch (hw->device_id) {
4910f62ba914SMichal Kosiarz 	case I40E_DEV_ID_1G_BASE_T_X722:
4911f62ba914SMichal Kosiarz 		status = i40e_read_phy_register_clause22(hw, reg, phy_addr,
4912f62ba914SMichal Kosiarz 							 value);
4913f62ba914SMichal Kosiarz 		break;
49146617be3cSStanislaw Grzeszczak 	case I40E_DEV_ID_1G_BASE_T_BC:
49153dbdd6c2SAleksandr Loktionov 	case I40E_DEV_ID_5G_BASE_T_BC:
4916f62ba914SMichal Kosiarz 	case I40E_DEV_ID_10G_BASE_T:
4917f62ba914SMichal Kosiarz 	case I40E_DEV_ID_10G_BASE_T4:
49182e45d3f4SAleksandr Loktionov 	case I40E_DEV_ID_10G_BASE_T_BC:
4919f62ba914SMichal Kosiarz 	case I40E_DEV_ID_10G_BASE_T_X722:
4920f62ba914SMichal Kosiarz 	case I40E_DEV_ID_25G_B:
4921f62ba914SMichal Kosiarz 	case I40E_DEV_ID_25G_SFP28:
4922f62ba914SMichal Kosiarz 		status = i40e_read_phy_register_clause45(hw, page, reg,
4923f62ba914SMichal Kosiarz 							 phy_addr, value);
4924f62ba914SMichal Kosiarz 		break;
4925f62ba914SMichal Kosiarz 	default:
4926230f3d53SJan Sokolowski 		status = -EIO;
4927f62ba914SMichal Kosiarz 		break;
4928f62ba914SMichal Kosiarz 	}
4929f62ba914SMichal Kosiarz 
4930f62ba914SMichal Kosiarz 	return status;
4931f62ba914SMichal Kosiarz }
4932f62ba914SMichal Kosiarz 
4933f62ba914SMichal Kosiarz /**
4934fd077cd3SCarolyn Wyborny  * i40e_get_phy_address
4935fd077cd3SCarolyn Wyborny  * @hw: pointer to the HW structure
4936fd077cd3SCarolyn Wyborny  * @dev_num: PHY port num that address we want
4937fd077cd3SCarolyn Wyborny  *
4938fd077cd3SCarolyn Wyborny  * Gets PHY address for current port
4939fd077cd3SCarolyn Wyborny  **/
i40e_get_phy_address(struct i40e_hw * hw,u8 dev_num)4940fd077cd3SCarolyn Wyborny u8 i40e_get_phy_address(struct i40e_hw *hw, u8 dev_num)
4941fd077cd3SCarolyn Wyborny {
4942fd077cd3SCarolyn Wyborny 	u8 port_num = hw->func_caps.mdio_port_num;
4943fd077cd3SCarolyn Wyborny 	u32 reg_val = rd32(hw, I40E_GLGEN_MDIO_I2C_SEL(port_num));
4944fd077cd3SCarolyn Wyborny 
4945fd077cd3SCarolyn Wyborny 	return (u8)(reg_val >> ((dev_num + 1) * 5)) & 0x1f;
4946fd077cd3SCarolyn Wyborny }
4947fd077cd3SCarolyn Wyborny 
4948fd077cd3SCarolyn Wyborny /**
4949262de08fSJesse Brandeburg  * i40e_blink_phy_link_led
4950fd077cd3SCarolyn Wyborny  * @hw: pointer to the HW structure
4951fd077cd3SCarolyn Wyborny  * @time: time how long led will blinks in secs
4952fd077cd3SCarolyn Wyborny  * @interval: gap between LED on and off in msecs
4953fd077cd3SCarolyn Wyborny  *
4954fd077cd3SCarolyn Wyborny  * Blinks PHY link LED
4955fd077cd3SCarolyn Wyborny  **/
i40e_blink_phy_link_led(struct i40e_hw * hw,u32 time,u32 interval)49565180ff13SJan Sokolowski int i40e_blink_phy_link_led(struct i40e_hw *hw,
4957fd077cd3SCarolyn Wyborny 			    u32 time, u32 interval)
4958fd077cd3SCarolyn Wyborny {
4959fd077cd3SCarolyn Wyborny 	u16 led_addr = I40E_PHY_LED_PROV_REG_1;
49605180ff13SJan Sokolowski 	u16 gpio_led_port;
4961fd077cd3SCarolyn Wyborny 	u8 phy_addr = 0;
49625180ff13SJan Sokolowski 	int status = 0;
49635180ff13SJan Sokolowski 	u16 led_ctl;
4964fd077cd3SCarolyn Wyborny 	u8 port_num;
49655180ff13SJan Sokolowski 	u16 led_reg;
49665180ff13SJan Sokolowski 	u32 i;
4967fd077cd3SCarolyn Wyborny 
4968fd077cd3SCarolyn Wyborny 	i = rd32(hw, I40E_PFGEN_PORTNUM);
4969fd077cd3SCarolyn Wyborny 	port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
4970fd077cd3SCarolyn Wyborny 	phy_addr = i40e_get_phy_address(hw, port_num);
4971fd077cd3SCarolyn Wyborny 
4972fd077cd3SCarolyn Wyborny 	for (gpio_led_port = 0; gpio_led_port < 3; gpio_led_port++,
4973fd077cd3SCarolyn Wyborny 	     led_addr++) {
497491dc1e5dSMichal Kosiarz 		status = i40e_read_phy_register_clause45(hw,
497591dc1e5dSMichal Kosiarz 							 I40E_PHY_COM_REG_PAGE,
497691dc1e5dSMichal Kosiarz 							 led_addr, phy_addr,
497791dc1e5dSMichal Kosiarz 							 &led_reg);
4978fd077cd3SCarolyn Wyborny 		if (status)
4979fd077cd3SCarolyn Wyborny 			goto phy_blinking_end;
4980fd077cd3SCarolyn Wyborny 		led_ctl = led_reg;
4981fd077cd3SCarolyn Wyborny 		if (led_reg & I40E_PHY_LED_LINK_MODE_MASK) {
4982fd077cd3SCarolyn Wyborny 			led_reg = 0;
498391dc1e5dSMichal Kosiarz 			status = i40e_write_phy_register_clause45(hw,
4984fd077cd3SCarolyn Wyborny 							 I40E_PHY_COM_REG_PAGE,
4985fd077cd3SCarolyn Wyborny 							 led_addr, phy_addr,
4986fd077cd3SCarolyn Wyborny 							 led_reg);
4987fd077cd3SCarolyn Wyborny 			if (status)
4988fd077cd3SCarolyn Wyborny 				goto phy_blinking_end;
4989fd077cd3SCarolyn Wyborny 			break;
4990fd077cd3SCarolyn Wyborny 		}
4991fd077cd3SCarolyn Wyborny 	}
4992fd077cd3SCarolyn Wyborny 
4993fd077cd3SCarolyn Wyborny 	if (time > 0 && interval > 0) {
4994fd077cd3SCarolyn Wyborny 		for (i = 0; i < time * 1000; i += interval) {
499591dc1e5dSMichal Kosiarz 			status = i40e_read_phy_register_clause45(hw,
4996fd077cd3SCarolyn Wyborny 						I40E_PHY_COM_REG_PAGE,
499791dc1e5dSMichal Kosiarz 						led_addr, phy_addr, &led_reg);
4998fd077cd3SCarolyn Wyborny 			if (status)
4999fd077cd3SCarolyn Wyborny 				goto restore_config;
5000fd077cd3SCarolyn Wyborny 			if (led_reg & I40E_PHY_LED_MANUAL_ON)
5001fd077cd3SCarolyn Wyborny 				led_reg = 0;
5002fd077cd3SCarolyn Wyborny 			else
5003fd077cd3SCarolyn Wyborny 				led_reg = I40E_PHY_LED_MANUAL_ON;
500491dc1e5dSMichal Kosiarz 			status = i40e_write_phy_register_clause45(hw,
5005fd077cd3SCarolyn Wyborny 						I40E_PHY_COM_REG_PAGE,
500691dc1e5dSMichal Kosiarz 						led_addr, phy_addr, led_reg);
5007fd077cd3SCarolyn Wyborny 			if (status)
5008fd077cd3SCarolyn Wyborny 				goto restore_config;
5009fd077cd3SCarolyn Wyborny 			msleep(interval);
5010fd077cd3SCarolyn Wyborny 		}
5011fd077cd3SCarolyn Wyborny 	}
5012fd077cd3SCarolyn Wyborny 
5013fd077cd3SCarolyn Wyborny restore_config:
501491dc1e5dSMichal Kosiarz 	status = i40e_write_phy_register_clause45(hw,
501591dc1e5dSMichal Kosiarz 						  I40E_PHY_COM_REG_PAGE,
501691dc1e5dSMichal Kosiarz 						  led_addr, phy_addr, led_ctl);
5017fd077cd3SCarolyn Wyborny 
5018fd077cd3SCarolyn Wyborny phy_blinking_end:
5019fd077cd3SCarolyn Wyborny 	return status;
5020fd077cd3SCarolyn Wyborny }
5021fd077cd3SCarolyn Wyborny 
5022fd077cd3SCarolyn Wyborny /**
502300f6c2f5SMariusz Stachura  * i40e_led_get_reg - read LED register
502400f6c2f5SMariusz Stachura  * @hw: pointer to the HW structure
502500f6c2f5SMariusz Stachura  * @led_addr: LED register address
502600f6c2f5SMariusz Stachura  * @reg_val: read register value
502700f6c2f5SMariusz Stachura  **/
i40e_led_get_reg(struct i40e_hw * hw,u16 led_addr,u32 * reg_val)50285180ff13SJan Sokolowski static int i40e_led_get_reg(struct i40e_hw *hw, u16 led_addr,
502900f6c2f5SMariusz Stachura 			    u32 *reg_val)
503000f6c2f5SMariusz Stachura {
503100f6c2f5SMariusz Stachura 	u8 phy_addr = 0;
503200f6c2f5SMariusz Stachura 	u8 port_num;
50335180ff13SJan Sokolowski 	int status;
503400f6c2f5SMariusz Stachura 	u32 i;
503500f6c2f5SMariusz Stachura 
503600f6c2f5SMariusz Stachura 	*reg_val = 0;
503700f6c2f5SMariusz Stachura 	if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) {
503800f6c2f5SMariusz Stachura 		status =
503900f6c2f5SMariusz Stachura 		       i40e_aq_get_phy_register(hw,
504000f6c2f5SMariusz Stachura 						I40E_AQ_PHY_REG_ACCESS_EXTERNAL,
50410514db37SPiotr Azarewicz 						I40E_PHY_COM_REG_PAGE, true,
504200f6c2f5SMariusz Stachura 						I40E_PHY_LED_PROV_REG_1,
504300f6c2f5SMariusz Stachura 						reg_val, NULL);
504400f6c2f5SMariusz Stachura 	} else {
504500f6c2f5SMariusz Stachura 		i = rd32(hw, I40E_PFGEN_PORTNUM);
504600f6c2f5SMariusz Stachura 		port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
504700f6c2f5SMariusz Stachura 		phy_addr = i40e_get_phy_address(hw, port_num);
504800f6c2f5SMariusz Stachura 		status = i40e_read_phy_register_clause45(hw,
504900f6c2f5SMariusz Stachura 							 I40E_PHY_COM_REG_PAGE,
505000f6c2f5SMariusz Stachura 							 led_addr, phy_addr,
505100f6c2f5SMariusz Stachura 							 (u16 *)reg_val);
505200f6c2f5SMariusz Stachura 	}
505300f6c2f5SMariusz Stachura 	return status;
505400f6c2f5SMariusz Stachura }
505500f6c2f5SMariusz Stachura 
505600f6c2f5SMariusz Stachura /**
505700f6c2f5SMariusz Stachura  * i40e_led_set_reg - write LED register
505800f6c2f5SMariusz Stachura  * @hw: pointer to the HW structure
505900f6c2f5SMariusz Stachura  * @led_addr: LED register address
506000f6c2f5SMariusz Stachura  * @reg_val: register value to write
506100f6c2f5SMariusz Stachura  **/
i40e_led_set_reg(struct i40e_hw * hw,u16 led_addr,u32 reg_val)50625180ff13SJan Sokolowski static int i40e_led_set_reg(struct i40e_hw *hw, u16 led_addr,
506300f6c2f5SMariusz Stachura 			    u32 reg_val)
506400f6c2f5SMariusz Stachura {
506500f6c2f5SMariusz Stachura 	u8 phy_addr = 0;
506600f6c2f5SMariusz Stachura 	u8 port_num;
50675180ff13SJan Sokolowski 	int status;
506800f6c2f5SMariusz Stachura 	u32 i;
506900f6c2f5SMariusz Stachura 
507000f6c2f5SMariusz Stachura 	if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) {
507100f6c2f5SMariusz Stachura 		status =
507200f6c2f5SMariusz Stachura 		       i40e_aq_set_phy_register(hw,
507300f6c2f5SMariusz Stachura 						I40E_AQ_PHY_REG_ACCESS_EXTERNAL,
50740514db37SPiotr Azarewicz 						I40E_PHY_COM_REG_PAGE, true,
507500f6c2f5SMariusz Stachura 						I40E_PHY_LED_PROV_REG_1,
507600f6c2f5SMariusz Stachura 						reg_val, NULL);
507700f6c2f5SMariusz Stachura 	} else {
507800f6c2f5SMariusz Stachura 		i = rd32(hw, I40E_PFGEN_PORTNUM);
507900f6c2f5SMariusz Stachura 		port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
508000f6c2f5SMariusz Stachura 		phy_addr = i40e_get_phy_address(hw, port_num);
508100f6c2f5SMariusz Stachura 		status = i40e_write_phy_register_clause45(hw,
508200f6c2f5SMariusz Stachura 							  I40E_PHY_COM_REG_PAGE,
508300f6c2f5SMariusz Stachura 							  led_addr, phy_addr,
508400f6c2f5SMariusz Stachura 							  (u16)reg_val);
508500f6c2f5SMariusz Stachura 	}
508600f6c2f5SMariusz Stachura 
508700f6c2f5SMariusz Stachura 	return status;
508800f6c2f5SMariusz Stachura }
508900f6c2f5SMariusz Stachura 
509000f6c2f5SMariusz Stachura /**
5091fd077cd3SCarolyn Wyborny  * i40e_led_get_phy - return current on/off mode
5092fd077cd3SCarolyn Wyborny  * @hw: pointer to the hw struct
5093fd077cd3SCarolyn Wyborny  * @led_addr: address of led register to use
5094fd077cd3SCarolyn Wyborny  * @val: original value of register to use
5095fd077cd3SCarolyn Wyborny  *
5096fd077cd3SCarolyn Wyborny  **/
i40e_led_get_phy(struct i40e_hw * hw,u16 * led_addr,u16 * val)50975180ff13SJan Sokolowski int i40e_led_get_phy(struct i40e_hw *hw, u16 *led_addr,
5098fd077cd3SCarolyn Wyborny 		     u16 *val)
5099fd077cd3SCarolyn Wyborny {
5100fd077cd3SCarolyn Wyborny 	u16 gpio_led_port;
5101fd077cd3SCarolyn Wyborny 	u8 phy_addr = 0;
51025180ff13SJan Sokolowski 	u32 reg_val_aq;
51035180ff13SJan Sokolowski 	int status = 0;
5104fd077cd3SCarolyn Wyborny 	u16 temp_addr;
51055180ff13SJan Sokolowski 	u16 reg_val;
5106fd077cd3SCarolyn Wyborny 	u8 port_num;
5107fd077cd3SCarolyn Wyborny 	u32 i;
5108fd077cd3SCarolyn Wyborny 
510900f6c2f5SMariusz Stachura 	if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) {
511000f6c2f5SMariusz Stachura 		status =
511100f6c2f5SMariusz Stachura 		      i40e_aq_get_phy_register(hw,
511200f6c2f5SMariusz Stachura 					       I40E_AQ_PHY_REG_ACCESS_EXTERNAL,
51130514db37SPiotr Azarewicz 					       I40E_PHY_COM_REG_PAGE, true,
511400f6c2f5SMariusz Stachura 					       I40E_PHY_LED_PROV_REG_1,
511500f6c2f5SMariusz Stachura 					       &reg_val_aq, NULL);
5116230f3d53SJan Sokolowski 		if (status == 0)
511700f6c2f5SMariusz Stachura 			*val = (u16)reg_val_aq;
511800f6c2f5SMariusz Stachura 		return status;
511900f6c2f5SMariusz Stachura 	}
5120fd077cd3SCarolyn Wyborny 	temp_addr = I40E_PHY_LED_PROV_REG_1;
5121fd077cd3SCarolyn Wyborny 	i = rd32(hw, I40E_PFGEN_PORTNUM);
5122fd077cd3SCarolyn Wyborny 	port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
5123fd077cd3SCarolyn Wyborny 	phy_addr = i40e_get_phy_address(hw, port_num);
5124fd077cd3SCarolyn Wyborny 
5125fd077cd3SCarolyn Wyborny 	for (gpio_led_port = 0; gpio_led_port < 3; gpio_led_port++,
5126fd077cd3SCarolyn Wyborny 	     temp_addr++) {
512791dc1e5dSMichal Kosiarz 		status = i40e_read_phy_register_clause45(hw,
512891dc1e5dSMichal Kosiarz 							 I40E_PHY_COM_REG_PAGE,
512991dc1e5dSMichal Kosiarz 							 temp_addr, phy_addr,
513091dc1e5dSMichal Kosiarz 							 &reg_val);
5131fd077cd3SCarolyn Wyborny 		if (status)
5132fd077cd3SCarolyn Wyborny 			return status;
5133fd077cd3SCarolyn Wyborny 		*val = reg_val;
5134fd077cd3SCarolyn Wyborny 		if (reg_val & I40E_PHY_LED_LINK_MODE_MASK) {
5135fd077cd3SCarolyn Wyborny 			*led_addr = temp_addr;
5136fd077cd3SCarolyn Wyborny 			break;
5137fd077cd3SCarolyn Wyborny 		}
5138fd077cd3SCarolyn Wyborny 	}
5139fd077cd3SCarolyn Wyborny 	return status;
5140fd077cd3SCarolyn Wyborny }
5141fd077cd3SCarolyn Wyborny 
5142fd077cd3SCarolyn Wyborny /**
5143fd077cd3SCarolyn Wyborny  * i40e_led_set_phy
5144fd077cd3SCarolyn Wyborny  * @hw: pointer to the HW structure
5145fd077cd3SCarolyn Wyborny  * @on: true or false
5146f5254429SJacob Keller  * @led_addr: address of led register to use
5147fd077cd3SCarolyn Wyborny  * @mode: original val plus bit for set or ignore
5148f5254429SJacob Keller  *
5149fd077cd3SCarolyn Wyborny  * Set led's on or off when controlled by the PHY
5150fd077cd3SCarolyn Wyborny  *
5151fd077cd3SCarolyn Wyborny  **/
i40e_led_set_phy(struct i40e_hw * hw,bool on,u16 led_addr,u32 mode)51525180ff13SJan Sokolowski int i40e_led_set_phy(struct i40e_hw *hw, bool on,
5153fd077cd3SCarolyn Wyborny 		     u16 led_addr, u32 mode)
5154fd077cd3SCarolyn Wyborny {
515500f6c2f5SMariusz Stachura 	u32 led_ctl = 0;
515600f6c2f5SMariusz Stachura 	u32 led_reg = 0;
51575180ff13SJan Sokolowski 	int status = 0;
5158fd077cd3SCarolyn Wyborny 
515900f6c2f5SMariusz Stachura 	status = i40e_led_get_reg(hw, led_addr, &led_reg);
5160fd077cd3SCarolyn Wyborny 	if (status)
5161fd077cd3SCarolyn Wyborny 		return status;
5162fd077cd3SCarolyn Wyborny 	led_ctl = led_reg;
5163fd077cd3SCarolyn Wyborny 	if (led_reg & I40E_PHY_LED_LINK_MODE_MASK) {
5164fd077cd3SCarolyn Wyborny 		led_reg = 0;
516500f6c2f5SMariusz Stachura 		status = i40e_led_set_reg(hw, led_addr, led_reg);
5166fd077cd3SCarolyn Wyborny 		if (status)
5167fd077cd3SCarolyn Wyborny 			return status;
5168fd077cd3SCarolyn Wyborny 	}
516900f6c2f5SMariusz Stachura 	status = i40e_led_get_reg(hw, led_addr, &led_reg);
5170fd077cd3SCarolyn Wyborny 	if (status)
5171fd077cd3SCarolyn Wyborny 		goto restore_config;
5172fd077cd3SCarolyn Wyborny 	if (on)
5173fd077cd3SCarolyn Wyborny 		led_reg = I40E_PHY_LED_MANUAL_ON;
5174fd077cd3SCarolyn Wyborny 	else
5175fd077cd3SCarolyn Wyborny 		led_reg = 0;
517600f6c2f5SMariusz Stachura 
517700f6c2f5SMariusz Stachura 	status = i40e_led_set_reg(hw, led_addr, led_reg);
5178fd077cd3SCarolyn Wyborny 	if (status)
5179fd077cd3SCarolyn Wyborny 		goto restore_config;
5180fd077cd3SCarolyn Wyborny 	if (mode & I40E_PHY_LED_MODE_ORIG) {
5181fd077cd3SCarolyn Wyborny 		led_ctl = (mode & I40E_PHY_LED_MODE_MASK);
518200f6c2f5SMariusz Stachura 		status = i40e_led_set_reg(hw, led_addr, led_ctl);
5183fd077cd3SCarolyn Wyborny 	}
5184fd077cd3SCarolyn Wyborny 	return status;
518500f6c2f5SMariusz Stachura 
5186fd077cd3SCarolyn Wyborny restore_config:
518700f6c2f5SMariusz Stachura 	status = i40e_led_set_reg(hw, led_addr, led_ctl);
5188fd077cd3SCarolyn Wyborny 	return status;
5189fd077cd3SCarolyn Wyborny }
5190f658137cSShannon Nelson 
5191f658137cSShannon Nelson /**
5192f658137cSShannon Nelson  * i40e_aq_rx_ctl_read_register - use FW to read from an Rx control register
5193f658137cSShannon Nelson  * @hw: pointer to the hw struct
5194f658137cSShannon Nelson  * @reg_addr: register address
5195f658137cSShannon Nelson  * @reg_val: ptr to register value
5196f658137cSShannon Nelson  * @cmd_details: pointer to command details structure or NULL
5197f658137cSShannon Nelson  *
5198f658137cSShannon Nelson  * Use the firmware to read the Rx control register,
5199f658137cSShannon Nelson  * especially useful if the Rx unit is under heavy pressure
5200f658137cSShannon Nelson  **/
i40e_aq_rx_ctl_read_register(struct i40e_hw * hw,u32 reg_addr,u32 * reg_val,struct i40e_asq_cmd_details * cmd_details)52015180ff13SJan Sokolowski int i40e_aq_rx_ctl_read_register(struct i40e_hw *hw,
5202f658137cSShannon Nelson 				 u32 reg_addr, u32 *reg_val,
5203f658137cSShannon Nelson 				 struct i40e_asq_cmd_details *cmd_details)
5204f658137cSShannon Nelson {
5205f658137cSShannon Nelson 	struct i40e_aq_desc desc;
5206f658137cSShannon Nelson 	struct i40e_aqc_rx_ctl_reg_read_write *cmd_resp =
5207f658137cSShannon Nelson 		(struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
52085180ff13SJan Sokolowski 	int status;
5209f658137cSShannon Nelson 
5210f658137cSShannon Nelson 	if (!reg_val)
5211230f3d53SJan Sokolowski 		return -EINVAL;
5212f658137cSShannon Nelson 
5213f658137cSShannon Nelson 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_rx_ctl_reg_read);
5214f658137cSShannon Nelson 
5215f658137cSShannon Nelson 	cmd_resp->address = cpu_to_le32(reg_addr);
5216f658137cSShannon Nelson 
5217f658137cSShannon Nelson 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5218f658137cSShannon Nelson 
5219f658137cSShannon Nelson 	if (status == 0)
5220f658137cSShannon Nelson 		*reg_val = le32_to_cpu(cmd_resp->value);
5221f658137cSShannon Nelson 
5222f658137cSShannon Nelson 	return status;
5223f658137cSShannon Nelson }
5224f658137cSShannon Nelson 
5225f658137cSShannon Nelson /**
5226f658137cSShannon Nelson  * i40e_read_rx_ctl - read from an Rx control register
5227f658137cSShannon Nelson  * @hw: pointer to the hw struct
5228f658137cSShannon Nelson  * @reg_addr: register address
5229f658137cSShannon Nelson  **/
i40e_read_rx_ctl(struct i40e_hw * hw,u32 reg_addr)5230f658137cSShannon Nelson u32 i40e_read_rx_ctl(struct i40e_hw *hw, u32 reg_addr)
5231f658137cSShannon Nelson {
5232f658137cSShannon Nelson 	bool use_register;
52335180ff13SJan Sokolowski 	int status = 0;
5234f658137cSShannon Nelson 	int retry = 5;
5235f658137cSShannon Nelson 	u32 val = 0;
5236f658137cSShannon Nelson 
52376030308eSPaul M Stillwell Jr 	use_register = (((hw->aq.api_maj_ver == 1) &&
52386030308eSPaul M Stillwell Jr 			(hw->aq.api_min_ver < 5)) ||
52396030308eSPaul M Stillwell Jr 			(hw->mac.type == I40E_MAC_X722));
5240f658137cSShannon Nelson 	if (!use_register) {
5241f658137cSShannon Nelson do_retry:
5242f658137cSShannon Nelson 		status = i40e_aq_rx_ctl_read_register(hw, reg_addr, &val, NULL);
5243f658137cSShannon Nelson 		if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
5244f658137cSShannon Nelson 			usleep_range(1000, 2000);
5245f658137cSShannon Nelson 			retry--;
5246f658137cSShannon Nelson 			goto do_retry;
5247f658137cSShannon Nelson 		}
5248f658137cSShannon Nelson 	}
5249f658137cSShannon Nelson 
5250f658137cSShannon Nelson 	/* if the AQ access failed, try the old-fashioned way */
5251f658137cSShannon Nelson 	if (status || use_register)
5252f658137cSShannon Nelson 		val = rd32(hw, reg_addr);
5253f658137cSShannon Nelson 
5254f658137cSShannon Nelson 	return val;
5255f658137cSShannon Nelson }
5256f658137cSShannon Nelson 
5257f658137cSShannon Nelson /**
5258f658137cSShannon Nelson  * i40e_aq_rx_ctl_write_register
5259f658137cSShannon Nelson  * @hw: pointer to the hw struct
5260f658137cSShannon Nelson  * @reg_addr: register address
5261f658137cSShannon Nelson  * @reg_val: register value
5262f658137cSShannon Nelson  * @cmd_details: pointer to command details structure or NULL
5263f658137cSShannon Nelson  *
5264f658137cSShannon Nelson  * Use the firmware to write to an Rx control register,
5265f658137cSShannon Nelson  * especially useful if the Rx unit is under heavy pressure
5266f658137cSShannon Nelson  **/
i40e_aq_rx_ctl_write_register(struct i40e_hw * hw,u32 reg_addr,u32 reg_val,struct i40e_asq_cmd_details * cmd_details)52675180ff13SJan Sokolowski int i40e_aq_rx_ctl_write_register(struct i40e_hw *hw,
5268f658137cSShannon Nelson 				  u32 reg_addr, u32 reg_val,
5269f658137cSShannon Nelson 				  struct i40e_asq_cmd_details *cmd_details)
5270f658137cSShannon Nelson {
5271f658137cSShannon Nelson 	struct i40e_aq_desc desc;
5272f658137cSShannon Nelson 	struct i40e_aqc_rx_ctl_reg_read_write *cmd =
5273f658137cSShannon Nelson 		(struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
52745180ff13SJan Sokolowski 	int status;
5275f658137cSShannon Nelson 
5276f658137cSShannon Nelson 	i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_rx_ctl_reg_write);
5277f658137cSShannon Nelson 
5278f658137cSShannon Nelson 	cmd->address = cpu_to_le32(reg_addr);
5279f658137cSShannon Nelson 	cmd->value = cpu_to_le32(reg_val);
5280f658137cSShannon Nelson 
5281f658137cSShannon Nelson 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5282f658137cSShannon Nelson 
5283f658137cSShannon Nelson 	return status;
5284f658137cSShannon Nelson }
5285f658137cSShannon Nelson 
5286f658137cSShannon Nelson /**
5287f658137cSShannon Nelson  * i40e_write_rx_ctl - write to an Rx control register
5288f658137cSShannon Nelson  * @hw: pointer to the hw struct
5289f658137cSShannon Nelson  * @reg_addr: register address
5290f658137cSShannon Nelson  * @reg_val: register value
5291f658137cSShannon Nelson  **/
i40e_write_rx_ctl(struct i40e_hw * hw,u32 reg_addr,u32 reg_val)5292f658137cSShannon Nelson void i40e_write_rx_ctl(struct i40e_hw *hw, u32 reg_addr, u32 reg_val)
5293f658137cSShannon Nelson {
5294f658137cSShannon Nelson 	bool use_register;
52955180ff13SJan Sokolowski 	int status = 0;
5296f658137cSShannon Nelson 	int retry = 5;
5297f658137cSShannon Nelson 
52986030308eSPaul M Stillwell Jr 	use_register = (((hw->aq.api_maj_ver == 1) &&
52996030308eSPaul M Stillwell Jr 			(hw->aq.api_min_ver < 5)) ||
53006030308eSPaul M Stillwell Jr 			(hw->mac.type == I40E_MAC_X722));
5301f658137cSShannon Nelson 	if (!use_register) {
5302f658137cSShannon Nelson do_retry:
5303f658137cSShannon Nelson 		status = i40e_aq_rx_ctl_write_register(hw, reg_addr,
5304f658137cSShannon Nelson 						       reg_val, NULL);
5305f658137cSShannon Nelson 		if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
5306f658137cSShannon Nelson 			usleep_range(1000, 2000);
5307f658137cSShannon Nelson 			retry--;
5308f658137cSShannon Nelson 			goto do_retry;
5309f658137cSShannon Nelson 		}
5310f658137cSShannon Nelson 	}
5311f658137cSShannon Nelson 
5312f658137cSShannon Nelson 	/* if the AQ access failed, try the old-fashioned way */
5313f658137cSShannon Nelson 	if (status || use_register)
5314f658137cSShannon Nelson 		wr32(hw, reg_addr, reg_val);
5315f658137cSShannon Nelson }
53161d5c960cSJingjing Wu 
53171d5c960cSJingjing Wu /**
53180514db37SPiotr Azarewicz  * i40e_mdio_if_number_selection - MDIO I/F number selection
53190514db37SPiotr Azarewicz  * @hw: pointer to the hw struct
53200514db37SPiotr Azarewicz  * @set_mdio: use MDIO I/F number specified by mdio_num
53210514db37SPiotr Azarewicz  * @mdio_num: MDIO I/F number
53220514db37SPiotr Azarewicz  * @cmd: pointer to PHY Register command structure
53230514db37SPiotr Azarewicz  **/
i40e_mdio_if_number_selection(struct i40e_hw * hw,bool set_mdio,u8 mdio_num,struct i40e_aqc_phy_register_access * cmd)53240514db37SPiotr Azarewicz static void i40e_mdio_if_number_selection(struct i40e_hw *hw, bool set_mdio,
53250514db37SPiotr Azarewicz 					  u8 mdio_num,
53260514db37SPiotr Azarewicz 					  struct i40e_aqc_phy_register_access *cmd)
53270514db37SPiotr Azarewicz {
53280514db37SPiotr Azarewicz 	if (set_mdio && cmd->phy_interface == I40E_AQ_PHY_REG_ACCESS_EXTERNAL) {
53290514db37SPiotr Azarewicz 		if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_EXTENDED)
53300514db37SPiotr Azarewicz 			cmd->cmd_flags |=
53310514db37SPiotr Azarewicz 				I40E_AQ_PHY_REG_ACCESS_SET_MDIO_IF_NUMBER |
53320514db37SPiotr Azarewicz 				((mdio_num <<
53330514db37SPiotr Azarewicz 				I40E_AQ_PHY_REG_ACCESS_MDIO_IF_NUMBER_SHIFT) &
53340514db37SPiotr Azarewicz 				I40E_AQ_PHY_REG_ACCESS_MDIO_IF_NUMBER_MASK);
53350514db37SPiotr Azarewicz 		else
53360514db37SPiotr Azarewicz 			i40e_debug(hw, I40E_DEBUG_PHY,
53370514db37SPiotr Azarewicz 				   "MDIO I/F number selection not supported by current FW version.\n");
53380514db37SPiotr Azarewicz 	}
53390514db37SPiotr Azarewicz }
53400514db37SPiotr Azarewicz 
53410514db37SPiotr Azarewicz /**
53420514db37SPiotr Azarewicz  * i40e_aq_set_phy_register_ext
53439c0e5cafSFilip Sadowski  * @hw: pointer to the hw struct
53449c0e5cafSFilip Sadowski  * @phy_select: select which phy should be accessed
53459c0e5cafSFilip Sadowski  * @dev_addr: PHY device address
5346b50f7bcaSJesse Brandeburg  * @page_change: flag to indicate if phy page should be updated
53470514db37SPiotr Azarewicz  * @set_mdio: use MDIO I/F number specified by mdio_num
53480514db37SPiotr Azarewicz  * @mdio_num: MDIO I/F number
53499c0e5cafSFilip Sadowski  * @reg_addr: PHY register address
53509c0e5cafSFilip Sadowski  * @reg_val: new register value
53519c0e5cafSFilip Sadowski  * @cmd_details: pointer to command details structure or NULL
53529c0e5cafSFilip Sadowski  *
53539c0e5cafSFilip Sadowski  * Write the external PHY register.
53540514db37SPiotr Azarewicz  * NOTE: In common cases MDIO I/F number should not be changed, thats why you
53550514db37SPiotr Azarewicz  * may use simple wrapper i40e_aq_set_phy_register.
53569c0e5cafSFilip Sadowski  **/
i40e_aq_set_phy_register_ext(struct i40e_hw * hw,u8 phy_select,u8 dev_addr,bool page_change,bool set_mdio,u8 mdio_num,u32 reg_addr,u32 reg_val,struct i40e_asq_cmd_details * cmd_details)53575180ff13SJan Sokolowski int i40e_aq_set_phy_register_ext(struct i40e_hw *hw,
53580514db37SPiotr Azarewicz 				 u8 phy_select, u8 dev_addr, bool page_change,
53590514db37SPiotr Azarewicz 				 bool set_mdio, u8 mdio_num,
53609c0e5cafSFilip Sadowski 				 u32 reg_addr, u32 reg_val,
53619c0e5cafSFilip Sadowski 				 struct i40e_asq_cmd_details *cmd_details)
53629c0e5cafSFilip Sadowski {
53639c0e5cafSFilip Sadowski 	struct i40e_aq_desc desc;
53649c0e5cafSFilip Sadowski 	struct i40e_aqc_phy_register_access *cmd =
53659c0e5cafSFilip Sadowski 		(struct i40e_aqc_phy_register_access *)&desc.params.raw;
53665180ff13SJan Sokolowski 	int status;
53679c0e5cafSFilip Sadowski 
53689c0e5cafSFilip Sadowski 	i40e_fill_default_direct_cmd_desc(&desc,
53699c0e5cafSFilip Sadowski 					  i40e_aqc_opc_set_phy_register);
53709c0e5cafSFilip Sadowski 
53719c0e5cafSFilip Sadowski 	cmd->phy_interface = phy_select;
53729c0e5cafSFilip Sadowski 	cmd->dev_address = dev_addr;
53739c0e5cafSFilip Sadowski 	cmd->reg_address = cpu_to_le32(reg_addr);
53749c0e5cafSFilip Sadowski 	cmd->reg_value = cpu_to_le32(reg_val);
53759c0e5cafSFilip Sadowski 
53760514db37SPiotr Azarewicz 	i40e_mdio_if_number_selection(hw, set_mdio, mdio_num, cmd);
53770514db37SPiotr Azarewicz 
53780514db37SPiotr Azarewicz 	if (!page_change)
53790514db37SPiotr Azarewicz 		cmd->cmd_flags = I40E_AQ_PHY_REG_ACCESS_DONT_CHANGE_QSFP_PAGE;
53800514db37SPiotr Azarewicz 
53819c0e5cafSFilip Sadowski 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
53829c0e5cafSFilip Sadowski 
53839c0e5cafSFilip Sadowski 	return status;
53849c0e5cafSFilip Sadowski }
53859c0e5cafSFilip Sadowski 
53869c0e5cafSFilip Sadowski /**
53870514db37SPiotr Azarewicz  * i40e_aq_get_phy_register_ext
53889c0e5cafSFilip Sadowski  * @hw: pointer to the hw struct
53899c0e5cafSFilip Sadowski  * @phy_select: select which phy should be accessed
53909c0e5cafSFilip Sadowski  * @dev_addr: PHY device address
5391b50f7bcaSJesse Brandeburg  * @page_change: flag to indicate if phy page should be updated
53920514db37SPiotr Azarewicz  * @set_mdio: use MDIO I/F number specified by mdio_num
53930514db37SPiotr Azarewicz  * @mdio_num: MDIO I/F number
53949c0e5cafSFilip Sadowski  * @reg_addr: PHY register address
53959c0e5cafSFilip Sadowski  * @reg_val: read register value
53969c0e5cafSFilip Sadowski  * @cmd_details: pointer to command details structure or NULL
53979c0e5cafSFilip Sadowski  *
53989c0e5cafSFilip Sadowski  * Read the external PHY register.
53990514db37SPiotr Azarewicz  * NOTE: In common cases MDIO I/F number should not be changed, thats why you
54000514db37SPiotr Azarewicz  * may use simple wrapper i40e_aq_get_phy_register.
54019c0e5cafSFilip Sadowski  **/
i40e_aq_get_phy_register_ext(struct i40e_hw * hw,u8 phy_select,u8 dev_addr,bool page_change,bool set_mdio,u8 mdio_num,u32 reg_addr,u32 * reg_val,struct i40e_asq_cmd_details * cmd_details)54025180ff13SJan Sokolowski int i40e_aq_get_phy_register_ext(struct i40e_hw *hw,
54030514db37SPiotr Azarewicz 				 u8 phy_select, u8 dev_addr, bool page_change,
54040514db37SPiotr Azarewicz 				 bool set_mdio, u8 mdio_num,
54059c0e5cafSFilip Sadowski 				 u32 reg_addr, u32 *reg_val,
54069c0e5cafSFilip Sadowski 				 struct i40e_asq_cmd_details *cmd_details)
54079c0e5cafSFilip Sadowski {
54089c0e5cafSFilip Sadowski 	struct i40e_aq_desc desc;
54099c0e5cafSFilip Sadowski 	struct i40e_aqc_phy_register_access *cmd =
54109c0e5cafSFilip Sadowski 		(struct i40e_aqc_phy_register_access *)&desc.params.raw;
54115180ff13SJan Sokolowski 	int status;
54129c0e5cafSFilip Sadowski 
54139c0e5cafSFilip Sadowski 	i40e_fill_default_direct_cmd_desc(&desc,
54149c0e5cafSFilip Sadowski 					  i40e_aqc_opc_get_phy_register);
54159c0e5cafSFilip Sadowski 
54169c0e5cafSFilip Sadowski 	cmd->phy_interface = phy_select;
54179c0e5cafSFilip Sadowski 	cmd->dev_address = dev_addr;
54189c0e5cafSFilip Sadowski 	cmd->reg_address = cpu_to_le32(reg_addr);
54199c0e5cafSFilip Sadowski 
54200514db37SPiotr Azarewicz 	i40e_mdio_if_number_selection(hw, set_mdio, mdio_num, cmd);
54210514db37SPiotr Azarewicz 
54220514db37SPiotr Azarewicz 	if (!page_change)
54230514db37SPiotr Azarewicz 		cmd->cmd_flags = I40E_AQ_PHY_REG_ACCESS_DONT_CHANGE_QSFP_PAGE;
54240514db37SPiotr Azarewicz 
54259c0e5cafSFilip Sadowski 	status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
54269c0e5cafSFilip Sadowski 	if (!status)
54279c0e5cafSFilip Sadowski 		*reg_val = le32_to_cpu(cmd->reg_value);
54289c0e5cafSFilip Sadowski 
54299c0e5cafSFilip Sadowski 	return status;
54309c0e5cafSFilip Sadowski }
54319c0e5cafSFilip Sadowski 
54329c0e5cafSFilip Sadowski /**
5433329e5983SJingjing Wu  * i40e_aq_write_ddp - Write dynamic device personalization (ddp)
54341d5c960cSJingjing Wu  * @hw: pointer to the hw struct
54351d5c960cSJingjing Wu  * @buff: command buffer (size in bytes = buff_size)
54361d5c960cSJingjing Wu  * @buff_size: buffer size in bytes
54371d5c960cSJingjing Wu  * @track_id: package tracking id
54381d5c960cSJingjing Wu  * @error_offset: returns error offset
54391d5c960cSJingjing Wu  * @error_info: returns error information
54401d5c960cSJingjing Wu  * @cmd_details: pointer to command details structure or NULL
54411d5c960cSJingjing Wu  **/
i40e_aq_write_ddp(struct i40e_hw * hw,void * buff,u16 buff_size,u32 track_id,u32 * error_offset,u32 * error_info,struct i40e_asq_cmd_details * cmd_details)54425180ff13SJan Sokolowski int i40e_aq_write_ddp(struct i40e_hw *hw, void *buff,
54431d5c960cSJingjing Wu 		      u16 buff_size, u32 track_id,
54441d5c960cSJingjing Wu 		      u32 *error_offset, u32 *error_info,
54451d5c960cSJingjing Wu 		      struct i40e_asq_cmd_details *cmd_details)
54461d5c960cSJingjing Wu {
54471d5c960cSJingjing Wu 	struct i40e_aq_desc desc;
54481d5c960cSJingjing Wu 	struct i40e_aqc_write_personalization_profile *cmd =
54491d5c960cSJingjing Wu 		(struct i40e_aqc_write_personalization_profile *)
54501d5c960cSJingjing Wu 		&desc.params.raw;
5451329e5983SJingjing Wu 	struct i40e_aqc_write_ddp_resp *resp;
54525180ff13SJan Sokolowski 	int status;
54531d5c960cSJingjing Wu 
54541d5c960cSJingjing Wu 	i40e_fill_default_direct_cmd_desc(&desc,
54551d5c960cSJingjing Wu 					  i40e_aqc_opc_write_personalization_profile);
54561d5c960cSJingjing Wu 
54571d5c960cSJingjing Wu 	desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
54581d5c960cSJingjing Wu 	if (buff_size > I40E_AQ_LARGE_BUF)
54591d5c960cSJingjing Wu 		desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
54601d5c960cSJingjing Wu 
54611d5c960cSJingjing Wu 	desc.datalen = cpu_to_le16(buff_size);
54621d5c960cSJingjing Wu 
54631d5c960cSJingjing Wu 	cmd->profile_track_id = cpu_to_le32(track_id);
54641d5c960cSJingjing Wu 
54651d5c960cSJingjing Wu 	status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
54661d5c960cSJingjing Wu 	if (!status) {
5467329e5983SJingjing Wu 		resp = (struct i40e_aqc_write_ddp_resp *)&desc.params.raw;
54681d5c960cSJingjing Wu 		if (error_offset)
54691d5c960cSJingjing Wu 			*error_offset = le32_to_cpu(resp->error_offset);
54701d5c960cSJingjing Wu 		if (error_info)
54711d5c960cSJingjing Wu 			*error_info = le32_to_cpu(resp->error_info);
54721d5c960cSJingjing Wu 	}
54731d5c960cSJingjing Wu 
54741d5c960cSJingjing Wu 	return status;
54751d5c960cSJingjing Wu }
54761d5c960cSJingjing Wu 
54771d5c960cSJingjing Wu /**
5478329e5983SJingjing Wu  * i40e_aq_get_ddp_list - Read dynamic device personalization (ddp)
54791d5c960cSJingjing Wu  * @hw: pointer to the hw struct
54801d5c960cSJingjing Wu  * @buff: command buffer (size in bytes = buff_size)
54811d5c960cSJingjing Wu  * @buff_size: buffer size in bytes
5482f5254429SJacob Keller  * @flags: AdminQ command flags
54831d5c960cSJingjing Wu  * @cmd_details: pointer to command details structure or NULL
54841d5c960cSJingjing Wu  **/
i40e_aq_get_ddp_list(struct i40e_hw * hw,void * buff,u16 buff_size,u8 flags,struct i40e_asq_cmd_details * cmd_details)54855180ff13SJan Sokolowski int i40e_aq_get_ddp_list(struct i40e_hw *hw, void *buff,
54861d5c960cSJingjing Wu 			 u16 buff_size, u8 flags,
54871d5c960cSJingjing Wu 			 struct i40e_asq_cmd_details *cmd_details)
54881d5c960cSJingjing Wu {
54891d5c960cSJingjing Wu 	struct i40e_aq_desc desc;
54901d5c960cSJingjing Wu 	struct i40e_aqc_get_applied_profiles *cmd =
54911d5c960cSJingjing Wu 		(struct i40e_aqc_get_applied_profiles *)&desc.params.raw;
54925180ff13SJan Sokolowski 	int status;
54931d5c960cSJingjing Wu 
54941d5c960cSJingjing Wu 	i40e_fill_default_direct_cmd_desc(&desc,
54951d5c960cSJingjing Wu 					  i40e_aqc_opc_get_personalization_profile_list);
54961d5c960cSJingjing Wu 
54971d5c960cSJingjing Wu 	desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
54981d5c960cSJingjing Wu 	if (buff_size > I40E_AQ_LARGE_BUF)
54991d5c960cSJingjing Wu 		desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
55001d5c960cSJingjing Wu 	desc.datalen = cpu_to_le16(buff_size);
55011d5c960cSJingjing Wu 
55021d5c960cSJingjing Wu 	cmd->flags = flags;
55031d5c960cSJingjing Wu 
55041d5c960cSJingjing Wu 	status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
55051d5c960cSJingjing Wu 
55061d5c960cSJingjing Wu 	return status;
55071d5c960cSJingjing Wu }
55081d5c960cSJingjing Wu 
55091d5c960cSJingjing Wu /**
55101d5c960cSJingjing Wu  * i40e_find_segment_in_package
55111d5c960cSJingjing Wu  * @segment_type: the segment type to search for (i.e., SEGMENT_TYPE_I40E)
55121d5c960cSJingjing Wu  * @pkg_hdr: pointer to the package header to be searched
55131d5c960cSJingjing Wu  *
55141d5c960cSJingjing Wu  * This function searches a package file for a particular segment type. On
55151d5c960cSJingjing Wu  * success it returns a pointer to the segment header, otherwise it will
55161d5c960cSJingjing Wu  * return NULL.
55171d5c960cSJingjing Wu  **/
55181d5c960cSJingjing Wu struct i40e_generic_seg_header *
i40e_find_segment_in_package(u32 segment_type,struct i40e_package_header * pkg_hdr)55191d5c960cSJingjing Wu i40e_find_segment_in_package(u32 segment_type,
55201d5c960cSJingjing Wu 			     struct i40e_package_header *pkg_hdr)
55211d5c960cSJingjing Wu {
55221d5c960cSJingjing Wu 	struct i40e_generic_seg_header *segment;
55231d5c960cSJingjing Wu 	u32 i;
55241d5c960cSJingjing Wu 
55251d5c960cSJingjing Wu 	/* Search all package segments for the requested segment type */
55261d5c960cSJingjing Wu 	for (i = 0; i < pkg_hdr->segment_count; i++) {
55271d5c960cSJingjing Wu 		segment =
55281d5c960cSJingjing Wu 			(struct i40e_generic_seg_header *)((u8 *)pkg_hdr +
55291d5c960cSJingjing Wu 			 pkg_hdr->segment_offset[i]);
55301d5c960cSJingjing Wu 
55311d5c960cSJingjing Wu 		if (segment->type == segment_type)
55321d5c960cSJingjing Wu 			return segment;
55331d5c960cSJingjing Wu 	}
55341d5c960cSJingjing Wu 
55351d5c960cSJingjing Wu 	return NULL;
55361d5c960cSJingjing Wu }
55371d5c960cSJingjing Wu 
5538cdc594e0SAleksandr Loktionov /* Get section table in profile */
5539cdc594e0SAleksandr Loktionov #define I40E_SECTION_TABLE(profile, sec_tbl)				\
5540cdc594e0SAleksandr Loktionov 	do {								\
5541cdc594e0SAleksandr Loktionov 		struct i40e_profile_segment *p = (profile);		\
5542cdc594e0SAleksandr Loktionov 		u32 count;						\
5543cdc594e0SAleksandr Loktionov 		u32 *nvm;						\
5544cdc594e0SAleksandr Loktionov 		count = p->device_table_count;				\
5545cdc594e0SAleksandr Loktionov 		nvm = (u32 *)&p->device_table[count];			\
5546cdc594e0SAleksandr Loktionov 		sec_tbl = (struct i40e_section_table *)&nvm[nvm[0] + 1]; \
5547cdc594e0SAleksandr Loktionov 	} while (0)
5548cdc594e0SAleksandr Loktionov 
5549cdc594e0SAleksandr Loktionov /* Get section header in profile */
5550cdc594e0SAleksandr Loktionov #define I40E_SECTION_HEADER(profile, offset)				\
5551cdc594e0SAleksandr Loktionov 	(struct i40e_profile_section_header *)((u8 *)(profile) + (offset))
5552cdc594e0SAleksandr Loktionov 
5553cdc594e0SAleksandr Loktionov /**
5554cdc594e0SAleksandr Loktionov  * i40e_find_section_in_profile
5555cdc594e0SAleksandr Loktionov  * @section_type: the section type to search for (i.e., SECTION_TYPE_NOTE)
5556cdc594e0SAleksandr Loktionov  * @profile: pointer to the i40e segment header to be searched
5557cdc594e0SAleksandr Loktionov  *
5558cdc594e0SAleksandr Loktionov  * This function searches i40e segment for a particular section type. On
5559cdc594e0SAleksandr Loktionov  * success it returns a pointer to the section header, otherwise it will
5560cdc594e0SAleksandr Loktionov  * return NULL.
5561cdc594e0SAleksandr Loktionov  **/
5562cdc594e0SAleksandr Loktionov struct i40e_profile_section_header *
i40e_find_section_in_profile(u32 section_type,struct i40e_profile_segment * profile)5563cdc594e0SAleksandr Loktionov i40e_find_section_in_profile(u32 section_type,
5564cdc594e0SAleksandr Loktionov 			     struct i40e_profile_segment *profile)
5565cdc594e0SAleksandr Loktionov {
5566cdc594e0SAleksandr Loktionov 	struct i40e_profile_section_header *sec;
5567cdc594e0SAleksandr Loktionov 	struct i40e_section_table *sec_tbl;
5568cdc594e0SAleksandr Loktionov 	u32 sec_off;
5569cdc594e0SAleksandr Loktionov 	u32 i;
5570cdc594e0SAleksandr Loktionov 
5571cdc594e0SAleksandr Loktionov 	if (profile->header.type != SEGMENT_TYPE_I40E)
5572cdc594e0SAleksandr Loktionov 		return NULL;
5573cdc594e0SAleksandr Loktionov 
5574cdc594e0SAleksandr Loktionov 	I40E_SECTION_TABLE(profile, sec_tbl);
5575cdc594e0SAleksandr Loktionov 
5576cdc594e0SAleksandr Loktionov 	for (i = 0; i < sec_tbl->section_count; i++) {
5577cdc594e0SAleksandr Loktionov 		sec_off = sec_tbl->section_offset[i];
5578cdc594e0SAleksandr Loktionov 		sec = I40E_SECTION_HEADER(profile, sec_off);
5579cdc594e0SAleksandr Loktionov 		if (sec->section.type == section_type)
5580cdc594e0SAleksandr Loktionov 			return sec;
5581cdc594e0SAleksandr Loktionov 	}
5582cdc594e0SAleksandr Loktionov 
5583cdc594e0SAleksandr Loktionov 	return NULL;
5584cdc594e0SAleksandr Loktionov }
5585cdc594e0SAleksandr Loktionov 
5586cdc594e0SAleksandr Loktionov /**
5587cdc594e0SAleksandr Loktionov  * i40e_ddp_exec_aq_section - Execute generic AQ for DDP
5588cdc594e0SAleksandr Loktionov  * @hw: pointer to the hw struct
5589cdc594e0SAleksandr Loktionov  * @aq: command buffer containing all data to execute AQ
5590cdc594e0SAleksandr Loktionov  **/
i40e_ddp_exec_aq_section(struct i40e_hw * hw,struct i40e_profile_aq_section * aq)55915180ff13SJan Sokolowski static int i40e_ddp_exec_aq_section(struct i40e_hw *hw,
5592cdc594e0SAleksandr Loktionov 				    struct i40e_profile_aq_section *aq)
5593cdc594e0SAleksandr Loktionov {
5594cdc594e0SAleksandr Loktionov 	struct i40e_aq_desc desc;
5595cdc594e0SAleksandr Loktionov 	u8 *msg = NULL;
5596cdc594e0SAleksandr Loktionov 	u16 msglen;
55975180ff13SJan Sokolowski 	int status;
5598cdc594e0SAleksandr Loktionov 
5599cdc594e0SAleksandr Loktionov 	i40e_fill_default_direct_cmd_desc(&desc, aq->opcode);
5600cdc594e0SAleksandr Loktionov 	desc.flags |= cpu_to_le16(aq->flags);
5601cdc594e0SAleksandr Loktionov 	memcpy(desc.params.raw, aq->param, sizeof(desc.params.raw));
5602cdc594e0SAleksandr Loktionov 
5603cdc594e0SAleksandr Loktionov 	msglen = aq->datalen;
5604cdc594e0SAleksandr Loktionov 	if (msglen) {
5605cdc594e0SAleksandr Loktionov 		desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
5606cdc594e0SAleksandr Loktionov 						I40E_AQ_FLAG_RD));
5607cdc594e0SAleksandr Loktionov 		if (msglen > I40E_AQ_LARGE_BUF)
5608cdc594e0SAleksandr Loktionov 			desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
5609cdc594e0SAleksandr Loktionov 		desc.datalen = cpu_to_le16(msglen);
5610cdc594e0SAleksandr Loktionov 		msg = &aq->data[0];
5611cdc594e0SAleksandr Loktionov 	}
5612cdc594e0SAleksandr Loktionov 
5613cdc594e0SAleksandr Loktionov 	status = i40e_asq_send_command(hw, &desc, msg, msglen, NULL);
5614cdc594e0SAleksandr Loktionov 
5615cdc594e0SAleksandr Loktionov 	if (status) {
5616cdc594e0SAleksandr Loktionov 		i40e_debug(hw, I40E_DEBUG_PACKAGE,
5617cdc594e0SAleksandr Loktionov 			   "unable to exec DDP AQ opcode %u, error %d\n",
5618cdc594e0SAleksandr Loktionov 			   aq->opcode, status);
5619cdc594e0SAleksandr Loktionov 		return status;
5620cdc594e0SAleksandr Loktionov 	}
5621cdc594e0SAleksandr Loktionov 
5622cdc594e0SAleksandr Loktionov 	/* copy returned desc to aq_buf */
5623cdc594e0SAleksandr Loktionov 	memcpy(aq->param, desc.params.raw, sizeof(desc.params.raw));
5624cdc594e0SAleksandr Loktionov 
5625cdc594e0SAleksandr Loktionov 	return 0;
5626cdc594e0SAleksandr Loktionov }
5627cdc594e0SAleksandr Loktionov 
5628cdc594e0SAleksandr Loktionov /**
5629cdc594e0SAleksandr Loktionov  * i40e_validate_profile
5630cdc594e0SAleksandr Loktionov  * @hw: pointer to the hardware structure
5631cdc594e0SAleksandr Loktionov  * @profile: pointer to the profile segment of the package to be validated
5632cdc594e0SAleksandr Loktionov  * @track_id: package tracking id
5633cdc594e0SAleksandr Loktionov  * @rollback: flag if the profile is for rollback.
5634cdc594e0SAleksandr Loktionov  *
5635cdc594e0SAleksandr Loktionov  * Validates supported devices and profile's sections.
5636cdc594e0SAleksandr Loktionov  */
56375180ff13SJan Sokolowski static int
i40e_validate_profile(struct i40e_hw * hw,struct i40e_profile_segment * profile,u32 track_id,bool rollback)5638cdc594e0SAleksandr Loktionov i40e_validate_profile(struct i40e_hw *hw, struct i40e_profile_segment *profile,
5639cdc594e0SAleksandr Loktionov 		      u32 track_id, bool rollback)
5640cdc594e0SAleksandr Loktionov {
5641cdc594e0SAleksandr Loktionov 	struct i40e_profile_section_header *sec = NULL;
5642cdc594e0SAleksandr Loktionov 	struct i40e_section_table *sec_tbl;
5643cdc594e0SAleksandr Loktionov 	u32 vendor_dev_id;
56445180ff13SJan Sokolowski 	int status = 0;
5645cdc594e0SAleksandr Loktionov 	u32 dev_cnt;
5646cdc594e0SAleksandr Loktionov 	u32 sec_off;
5647cdc594e0SAleksandr Loktionov 	u32 i;
5648cdc594e0SAleksandr Loktionov 
5649cdc594e0SAleksandr Loktionov 	if (track_id == I40E_DDP_TRACKID_INVALID) {
5650cdc594e0SAleksandr Loktionov 		i40e_debug(hw, I40E_DEBUG_PACKAGE, "Invalid track_id\n");
5651230f3d53SJan Sokolowski 		return -EOPNOTSUPP;
5652cdc594e0SAleksandr Loktionov 	}
5653cdc594e0SAleksandr Loktionov 
5654cdc594e0SAleksandr Loktionov 	dev_cnt = profile->device_table_count;
5655cdc594e0SAleksandr Loktionov 	for (i = 0; i < dev_cnt; i++) {
5656cdc594e0SAleksandr Loktionov 		vendor_dev_id = profile->device_table[i].vendor_dev_id;
5657cdc594e0SAleksandr Loktionov 		if ((vendor_dev_id >> 16) == PCI_VENDOR_ID_INTEL &&
5658cdc594e0SAleksandr Loktionov 		    hw->device_id == (vendor_dev_id & 0xFFFF))
5659cdc594e0SAleksandr Loktionov 			break;
5660cdc594e0SAleksandr Loktionov 	}
5661cdc594e0SAleksandr Loktionov 	if (dev_cnt && i == dev_cnt) {
5662cdc594e0SAleksandr Loktionov 		i40e_debug(hw, I40E_DEBUG_PACKAGE,
5663cdc594e0SAleksandr Loktionov 			   "Device doesn't support DDP\n");
5664230f3d53SJan Sokolowski 		return -ENODEV;
5665cdc594e0SAleksandr Loktionov 	}
5666cdc594e0SAleksandr Loktionov 
5667cdc594e0SAleksandr Loktionov 	I40E_SECTION_TABLE(profile, sec_tbl);
5668cdc594e0SAleksandr Loktionov 
5669cdc594e0SAleksandr Loktionov 	/* Validate sections types */
5670cdc594e0SAleksandr Loktionov 	for (i = 0; i < sec_tbl->section_count; i++) {
5671cdc594e0SAleksandr Loktionov 		sec_off = sec_tbl->section_offset[i];
5672cdc594e0SAleksandr Loktionov 		sec = I40E_SECTION_HEADER(profile, sec_off);
5673cdc594e0SAleksandr Loktionov 		if (rollback) {
5674cdc594e0SAleksandr Loktionov 			if (sec->section.type == SECTION_TYPE_MMIO ||
5675cdc594e0SAleksandr Loktionov 			    sec->section.type == SECTION_TYPE_AQ ||
5676cdc594e0SAleksandr Loktionov 			    sec->section.type == SECTION_TYPE_RB_AQ) {
5677cdc594e0SAleksandr Loktionov 				i40e_debug(hw, I40E_DEBUG_PACKAGE,
5678cdc594e0SAleksandr Loktionov 					   "Not a roll-back package\n");
5679230f3d53SJan Sokolowski 				return -EOPNOTSUPP;
5680cdc594e0SAleksandr Loktionov 			}
5681cdc594e0SAleksandr Loktionov 		} else {
5682cdc594e0SAleksandr Loktionov 			if (sec->section.type == SECTION_TYPE_RB_AQ ||
5683cdc594e0SAleksandr Loktionov 			    sec->section.type == SECTION_TYPE_RB_MMIO) {
5684cdc594e0SAleksandr Loktionov 				i40e_debug(hw, I40E_DEBUG_PACKAGE,
5685cdc594e0SAleksandr Loktionov 					   "Not an original package\n");
5686230f3d53SJan Sokolowski 				return -EOPNOTSUPP;
5687cdc594e0SAleksandr Loktionov 			}
5688cdc594e0SAleksandr Loktionov 		}
5689cdc594e0SAleksandr Loktionov 	}
5690cdc594e0SAleksandr Loktionov 
5691cdc594e0SAleksandr Loktionov 	return status;
5692cdc594e0SAleksandr Loktionov }
5693cdc594e0SAleksandr Loktionov 
56941d5c960cSJingjing Wu /**
56951d5c960cSJingjing Wu  * i40e_write_profile
56961d5c960cSJingjing Wu  * @hw: pointer to the hardware structure
56971d5c960cSJingjing Wu  * @profile: pointer to the profile segment of the package to be downloaded
56981d5c960cSJingjing Wu  * @track_id: package tracking id
56991d5c960cSJingjing Wu  *
57001d5c960cSJingjing Wu  * Handles the download of a complete package.
57011d5c960cSJingjing Wu  */
57025180ff13SJan Sokolowski int
i40e_write_profile(struct i40e_hw * hw,struct i40e_profile_segment * profile,u32 track_id)57031d5c960cSJingjing Wu i40e_write_profile(struct i40e_hw *hw, struct i40e_profile_segment *profile,
57041d5c960cSJingjing Wu 		   u32 track_id)
57051d5c960cSJingjing Wu {
57061d5c960cSJingjing Wu 	struct i40e_profile_section_header *sec = NULL;
5707cdc594e0SAleksandr Loktionov 	struct i40e_profile_aq_section *ddp_aq;
57085180ff13SJan Sokolowski 	struct i40e_section_table *sec_tbl;
57091d5c960cSJingjing Wu 	u32 offset = 0, info = 0;
57105180ff13SJan Sokolowski 	u32 section_size = 0;
57115180ff13SJan Sokolowski 	int status = 0;
5712cdc594e0SAleksandr Loktionov 	u32 sec_off;
57131d5c960cSJingjing Wu 	u32 i;
57141d5c960cSJingjing Wu 
5715cdc594e0SAleksandr Loktionov 	status = i40e_validate_profile(hw, profile, track_id, false);
5716cdc594e0SAleksandr Loktionov 	if (status)
5717cdc594e0SAleksandr Loktionov 		return status;
57181d5c960cSJingjing Wu 
5719cdc594e0SAleksandr Loktionov 	I40E_SECTION_TABLE(profile, sec_tbl);
57201d5c960cSJingjing Wu 
57211d5c960cSJingjing Wu 	for (i = 0; i < sec_tbl->section_count; i++) {
5722cdc594e0SAleksandr Loktionov 		sec_off = sec_tbl->section_offset[i];
5723cdc594e0SAleksandr Loktionov 		sec = I40E_SECTION_HEADER(profile, sec_off);
5724cdc594e0SAleksandr Loktionov 		/* Process generic admin command */
5725cdc594e0SAleksandr Loktionov 		if (sec->section.type == SECTION_TYPE_AQ) {
5726cdc594e0SAleksandr Loktionov 			ddp_aq = (struct i40e_profile_aq_section *)&sec[1];
5727cdc594e0SAleksandr Loktionov 			status = i40e_ddp_exec_aq_section(hw, ddp_aq);
5728cdc594e0SAleksandr Loktionov 			if (status) {
5729cdc594e0SAleksandr Loktionov 				i40e_debug(hw, I40E_DEBUG_PACKAGE,
5730cdc594e0SAleksandr Loktionov 					   "Failed to execute aq: section %d, opcode %u\n",
5731cdc594e0SAleksandr Loktionov 					   i, ddp_aq->opcode);
5732cdc594e0SAleksandr Loktionov 				break;
5733cdc594e0SAleksandr Loktionov 			}
5734cdc594e0SAleksandr Loktionov 			sec->section.type = SECTION_TYPE_RB_AQ;
5735cdc594e0SAleksandr Loktionov 		}
57361d5c960cSJingjing Wu 
5737cdc594e0SAleksandr Loktionov 		/* Skip any non-mmio sections */
57381d5c960cSJingjing Wu 		if (sec->section.type != SECTION_TYPE_MMIO)
57391d5c960cSJingjing Wu 			continue;
57401d5c960cSJingjing Wu 
57411d5c960cSJingjing Wu 		section_size = sec->section.size +
57421d5c960cSJingjing Wu 			sizeof(struct i40e_profile_section_header);
57431d5c960cSJingjing Wu 
5744cdc594e0SAleksandr Loktionov 		/* Write MMIO section */
5745329e5983SJingjing Wu 		status = i40e_aq_write_ddp(hw, (void *)sec, (u16)section_size,
57461d5c960cSJingjing Wu 					   track_id, &offset, &info, NULL);
57471d5c960cSJingjing Wu 		if (status) {
57481d5c960cSJingjing Wu 			i40e_debug(hw, I40E_DEBUG_PACKAGE,
5749cdc594e0SAleksandr Loktionov 				   "Failed to write profile: section %d, offset %d, info %d\n",
5750cdc594e0SAleksandr Loktionov 				   i, offset, info);
5751cdc594e0SAleksandr Loktionov 			break;
5752cdc594e0SAleksandr Loktionov 		}
5753cdc594e0SAleksandr Loktionov 	}
5754cdc594e0SAleksandr Loktionov 	return status;
5755cdc594e0SAleksandr Loktionov }
5756cdc594e0SAleksandr Loktionov 
5757cdc594e0SAleksandr Loktionov /**
5758cdc594e0SAleksandr Loktionov  * i40e_rollback_profile
5759cdc594e0SAleksandr Loktionov  * @hw: pointer to the hardware structure
5760cdc594e0SAleksandr Loktionov  * @profile: pointer to the profile segment of the package to be removed
5761cdc594e0SAleksandr Loktionov  * @track_id: package tracking id
5762cdc594e0SAleksandr Loktionov  *
5763cdc594e0SAleksandr Loktionov  * Rolls back previously loaded package.
5764cdc594e0SAleksandr Loktionov  */
57655180ff13SJan Sokolowski int
i40e_rollback_profile(struct i40e_hw * hw,struct i40e_profile_segment * profile,u32 track_id)5766cdc594e0SAleksandr Loktionov i40e_rollback_profile(struct i40e_hw *hw, struct i40e_profile_segment *profile,
5767cdc594e0SAleksandr Loktionov 		      u32 track_id)
5768cdc594e0SAleksandr Loktionov {
5769cdc594e0SAleksandr Loktionov 	struct i40e_profile_section_header *sec = NULL;
5770cdc594e0SAleksandr Loktionov 	struct i40e_section_table *sec_tbl;
5771cdc594e0SAleksandr Loktionov 	u32 offset = 0, info = 0;
5772cdc594e0SAleksandr Loktionov 	u32 section_size = 0;
57735180ff13SJan Sokolowski 	int status = 0;
5774cdc594e0SAleksandr Loktionov 	u32 sec_off;
5775cdc594e0SAleksandr Loktionov 	int i;
5776cdc594e0SAleksandr Loktionov 
5777cdc594e0SAleksandr Loktionov 	status = i40e_validate_profile(hw, profile, track_id, true);
5778cdc594e0SAleksandr Loktionov 	if (status)
5779cdc594e0SAleksandr Loktionov 		return status;
5780cdc594e0SAleksandr Loktionov 
5781cdc594e0SAleksandr Loktionov 	I40E_SECTION_TABLE(profile, sec_tbl);
5782cdc594e0SAleksandr Loktionov 
5783cdc594e0SAleksandr Loktionov 	/* For rollback write sections in reverse */
5784cdc594e0SAleksandr Loktionov 	for (i = sec_tbl->section_count - 1; i >= 0; i--) {
5785cdc594e0SAleksandr Loktionov 		sec_off = sec_tbl->section_offset[i];
5786cdc594e0SAleksandr Loktionov 		sec = I40E_SECTION_HEADER(profile, sec_off);
5787cdc594e0SAleksandr Loktionov 
5788cdc594e0SAleksandr Loktionov 		/* Skip any non-rollback sections */
5789cdc594e0SAleksandr Loktionov 		if (sec->section.type != SECTION_TYPE_RB_MMIO)
5790cdc594e0SAleksandr Loktionov 			continue;
5791cdc594e0SAleksandr Loktionov 
5792cdc594e0SAleksandr Loktionov 		section_size = sec->section.size +
5793cdc594e0SAleksandr Loktionov 			sizeof(struct i40e_profile_section_header);
5794cdc594e0SAleksandr Loktionov 
5795cdc594e0SAleksandr Loktionov 		/* Write roll-back MMIO section */
5796cdc594e0SAleksandr Loktionov 		status = i40e_aq_write_ddp(hw, (void *)sec, (u16)section_size,
5797cdc594e0SAleksandr Loktionov 					   track_id, &offset, &info, NULL);
5798cdc594e0SAleksandr Loktionov 		if (status) {
5799cdc594e0SAleksandr Loktionov 			i40e_debug(hw, I40E_DEBUG_PACKAGE,
5800cdc594e0SAleksandr Loktionov 				   "Failed to write profile: section %d, offset %d, info %d\n",
5801cdc594e0SAleksandr Loktionov 				   i, offset, info);
58021d5c960cSJingjing Wu 			break;
58031d5c960cSJingjing Wu 		}
58041d5c960cSJingjing Wu 	}
58051d5c960cSJingjing Wu 	return status;
58061d5c960cSJingjing Wu }
58071d5c960cSJingjing Wu 
58081d5c960cSJingjing Wu /**
58091d5c960cSJingjing Wu  * i40e_add_pinfo_to_list
58101d5c960cSJingjing Wu  * @hw: pointer to the hardware structure
58111d5c960cSJingjing Wu  * @profile: pointer to the profile segment of the package
58121d5c960cSJingjing Wu  * @profile_info_sec: buffer for information section
58131d5c960cSJingjing Wu  * @track_id: package tracking id
58141d5c960cSJingjing Wu  *
58151d5c960cSJingjing Wu  * Register a profile to the list of loaded profiles.
58161d5c960cSJingjing Wu  */
58175180ff13SJan Sokolowski int
i40e_add_pinfo_to_list(struct i40e_hw * hw,struct i40e_profile_segment * profile,u8 * profile_info_sec,u32 track_id)58181d5c960cSJingjing Wu i40e_add_pinfo_to_list(struct i40e_hw *hw,
58191d5c960cSJingjing Wu 		       struct i40e_profile_segment *profile,
58201d5c960cSJingjing Wu 		       u8 *profile_info_sec, u32 track_id)
58211d5c960cSJingjing Wu {
58221d5c960cSJingjing Wu 	struct i40e_profile_section_header *sec = NULL;
58231d5c960cSJingjing Wu 	struct i40e_profile_info *pinfo;
58241d5c960cSJingjing Wu 	u32 offset = 0, info = 0;
58255180ff13SJan Sokolowski 	int status = 0;
58261d5c960cSJingjing Wu 
58271d5c960cSJingjing Wu 	sec = (struct i40e_profile_section_header *)profile_info_sec;
58281d5c960cSJingjing Wu 	sec->tbl_size = 1;
58291d5c960cSJingjing Wu 	sec->data_end = sizeof(struct i40e_profile_section_header) +
58301d5c960cSJingjing Wu 			sizeof(struct i40e_profile_info);
58311d5c960cSJingjing Wu 	sec->section.type = SECTION_TYPE_INFO;
58321d5c960cSJingjing Wu 	sec->section.offset = sizeof(struct i40e_profile_section_header);
58331d5c960cSJingjing Wu 	sec->section.size = sizeof(struct i40e_profile_info);
58341d5c960cSJingjing Wu 	pinfo = (struct i40e_profile_info *)(profile_info_sec +
58351d5c960cSJingjing Wu 					     sec->section.offset);
58361d5c960cSJingjing Wu 	pinfo->track_id = track_id;
58371d5c960cSJingjing Wu 	pinfo->version = profile->version;
5838329e5983SJingjing Wu 	pinfo->op = I40E_DDP_ADD_TRACKID;
5839329e5983SJingjing Wu 	memcpy(pinfo->name, profile->name, I40E_DDP_NAME_SIZE);
58401d5c960cSJingjing Wu 
5841329e5983SJingjing Wu 	status = i40e_aq_write_ddp(hw, (void *)sec, sec->data_end,
58421d5c960cSJingjing Wu 				   track_id, &offset, &info, NULL);
58432f4b411aSAmritha Nambiar 
58442f4b411aSAmritha Nambiar 	return status;
58452f4b411aSAmritha Nambiar }
58462f4b411aSAmritha Nambiar 
58472f4b411aSAmritha Nambiar /**
58482f4b411aSAmritha Nambiar  * i40e_aq_add_cloud_filters
58492f4b411aSAmritha Nambiar  * @hw: pointer to the hardware structure
58502f4b411aSAmritha Nambiar  * @seid: VSI seid to add cloud filters from
58512f4b411aSAmritha Nambiar  * @filters: Buffer which contains the filters to be added
58522f4b411aSAmritha Nambiar  * @filter_count: number of filters contained in the buffer
58532f4b411aSAmritha Nambiar  *
58542f4b411aSAmritha Nambiar  * Set the cloud filters for a given VSI.  The contents of the
58552f4b411aSAmritha Nambiar  * i40e_aqc_cloud_filters_element_data are filled in by the caller
58562f4b411aSAmritha Nambiar  * of the function.
58572f4b411aSAmritha Nambiar  *
58582f4b411aSAmritha Nambiar  **/
58595180ff13SJan Sokolowski int
i40e_aq_add_cloud_filters(struct i40e_hw * hw,u16 seid,struct i40e_aqc_cloud_filters_element_data * filters,u8 filter_count)58602f4b411aSAmritha Nambiar i40e_aq_add_cloud_filters(struct i40e_hw *hw, u16 seid,
58612f4b411aSAmritha Nambiar 			  struct i40e_aqc_cloud_filters_element_data *filters,
58622f4b411aSAmritha Nambiar 			  u8 filter_count)
58632f4b411aSAmritha Nambiar {
58642f4b411aSAmritha Nambiar 	struct i40e_aq_desc desc;
58652f4b411aSAmritha Nambiar 	struct i40e_aqc_add_remove_cloud_filters *cmd =
58662f4b411aSAmritha Nambiar 	(struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
58672f4b411aSAmritha Nambiar 	u16 buff_len;
58685180ff13SJan Sokolowski 	int status;
58692f4b411aSAmritha Nambiar 
58702f4b411aSAmritha Nambiar 	i40e_fill_default_direct_cmd_desc(&desc,
58712f4b411aSAmritha Nambiar 					  i40e_aqc_opc_add_cloud_filters);
58722f4b411aSAmritha Nambiar 
58732f4b411aSAmritha Nambiar 	buff_len = filter_count * sizeof(*filters);
58742f4b411aSAmritha Nambiar 	desc.datalen = cpu_to_le16(buff_len);
58752f4b411aSAmritha Nambiar 	desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
58762f4b411aSAmritha Nambiar 	cmd->num_filters = filter_count;
58772f4b411aSAmritha Nambiar 	cmd->seid = cpu_to_le16(seid);
58782f4b411aSAmritha Nambiar 
58792f4b411aSAmritha Nambiar 	status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
58802f4b411aSAmritha Nambiar 
58812f4b411aSAmritha Nambiar 	return status;
58822f4b411aSAmritha Nambiar }
58832f4b411aSAmritha Nambiar 
58842f4b411aSAmritha Nambiar /**
58852f4b411aSAmritha Nambiar  * i40e_aq_add_cloud_filters_bb
58862f4b411aSAmritha Nambiar  * @hw: pointer to the hardware structure
58872f4b411aSAmritha Nambiar  * @seid: VSI seid to add cloud filters from
58882f4b411aSAmritha Nambiar  * @filters: Buffer which contains the filters in big buffer to be added
58892f4b411aSAmritha Nambiar  * @filter_count: number of filters contained in the buffer
58902f4b411aSAmritha Nambiar  *
58912f4b411aSAmritha Nambiar  * Set the big buffer cloud filters for a given VSI.  The contents of the
58922f4b411aSAmritha Nambiar  * i40e_aqc_cloud_filters_element_bb are filled in by the caller of the
58932f4b411aSAmritha Nambiar  * function.
58942f4b411aSAmritha Nambiar  *
58952f4b411aSAmritha Nambiar  **/
58965180ff13SJan Sokolowski int
i40e_aq_add_cloud_filters_bb(struct i40e_hw * hw,u16 seid,struct i40e_aqc_cloud_filters_element_bb * filters,u8 filter_count)58972f4b411aSAmritha Nambiar i40e_aq_add_cloud_filters_bb(struct i40e_hw *hw, u16 seid,
58982f4b411aSAmritha Nambiar 			     struct i40e_aqc_cloud_filters_element_bb *filters,
58992f4b411aSAmritha Nambiar 			     u8 filter_count)
59002f4b411aSAmritha Nambiar {
59012f4b411aSAmritha Nambiar 	struct i40e_aq_desc desc;
59022f4b411aSAmritha Nambiar 	struct i40e_aqc_add_remove_cloud_filters *cmd =
59032f4b411aSAmritha Nambiar 	(struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
59042f4b411aSAmritha Nambiar 	u16 buff_len;
59055180ff13SJan Sokolowski 	int status;
59062f4b411aSAmritha Nambiar 	int i;
59072f4b411aSAmritha Nambiar 
59082f4b411aSAmritha Nambiar 	i40e_fill_default_direct_cmd_desc(&desc,
59092f4b411aSAmritha Nambiar 					  i40e_aqc_opc_add_cloud_filters);
59102f4b411aSAmritha Nambiar 
59112f4b411aSAmritha Nambiar 	buff_len = filter_count * sizeof(*filters);
59122f4b411aSAmritha Nambiar 	desc.datalen = cpu_to_le16(buff_len);
59132f4b411aSAmritha Nambiar 	desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
59142f4b411aSAmritha Nambiar 	cmd->num_filters = filter_count;
59152f4b411aSAmritha Nambiar 	cmd->seid = cpu_to_le16(seid);
59162f4b411aSAmritha Nambiar 	cmd->big_buffer_flag = I40E_AQC_ADD_CLOUD_CMD_BB;
59172f4b411aSAmritha Nambiar 
59182f4b411aSAmritha Nambiar 	for (i = 0; i < filter_count; i++) {
59192f4b411aSAmritha Nambiar 		u16 tnl_type;
59202f4b411aSAmritha Nambiar 		u32 ti;
59212f4b411aSAmritha Nambiar 
59222f4b411aSAmritha Nambiar 		tnl_type = (le16_to_cpu(filters[i].element.flags) &
59232f4b411aSAmritha Nambiar 			   I40E_AQC_ADD_CLOUD_TNL_TYPE_MASK) >>
59242f4b411aSAmritha Nambiar 			   I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT;
59252f4b411aSAmritha Nambiar 
59262f4b411aSAmritha Nambiar 		/* Due to hardware eccentricities, the VNI for Geneve is shifted
59272f4b411aSAmritha Nambiar 		 * one more byte further than normally used for Tenant ID in
59282f4b411aSAmritha Nambiar 		 * other tunnel types.
59292f4b411aSAmritha Nambiar 		 */
59302f4b411aSAmritha Nambiar 		if (tnl_type == I40E_AQC_ADD_CLOUD_TNL_TYPE_GENEVE) {
59312f4b411aSAmritha Nambiar 			ti = le32_to_cpu(filters[i].element.tenant_id);
59322f4b411aSAmritha Nambiar 			filters[i].element.tenant_id = cpu_to_le32(ti << 8);
59332f4b411aSAmritha Nambiar 		}
59342f4b411aSAmritha Nambiar 	}
59352f4b411aSAmritha Nambiar 
59362f4b411aSAmritha Nambiar 	status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
59372f4b411aSAmritha Nambiar 
59382f4b411aSAmritha Nambiar 	return status;
59392f4b411aSAmritha Nambiar }
59402f4b411aSAmritha Nambiar 
59412f4b411aSAmritha Nambiar /**
59422f4b411aSAmritha Nambiar  * i40e_aq_rem_cloud_filters
59432f4b411aSAmritha Nambiar  * @hw: pointer to the hardware structure
59442f4b411aSAmritha Nambiar  * @seid: VSI seid to remove cloud filters from
59452f4b411aSAmritha Nambiar  * @filters: Buffer which contains the filters to be removed
59462f4b411aSAmritha Nambiar  * @filter_count: number of filters contained in the buffer
59472f4b411aSAmritha Nambiar  *
59482f4b411aSAmritha Nambiar  * Remove the cloud filters for a given VSI.  The contents of the
59492f4b411aSAmritha Nambiar  * i40e_aqc_cloud_filters_element_data are filled in by the caller
59502f4b411aSAmritha Nambiar  * of the function.
59512f4b411aSAmritha Nambiar  *
59522f4b411aSAmritha Nambiar  **/
59535180ff13SJan Sokolowski int
i40e_aq_rem_cloud_filters(struct i40e_hw * hw,u16 seid,struct i40e_aqc_cloud_filters_element_data * filters,u8 filter_count)59542f4b411aSAmritha Nambiar i40e_aq_rem_cloud_filters(struct i40e_hw *hw, u16 seid,
59552f4b411aSAmritha Nambiar 			  struct i40e_aqc_cloud_filters_element_data *filters,
59562f4b411aSAmritha Nambiar 			  u8 filter_count)
59572f4b411aSAmritha Nambiar {
59582f4b411aSAmritha Nambiar 	struct i40e_aq_desc desc;
59592f4b411aSAmritha Nambiar 	struct i40e_aqc_add_remove_cloud_filters *cmd =
59602f4b411aSAmritha Nambiar 	(struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
59612f4b411aSAmritha Nambiar 	u16 buff_len;
59625180ff13SJan Sokolowski 	int status;
59632f4b411aSAmritha Nambiar 
59642f4b411aSAmritha Nambiar 	i40e_fill_default_direct_cmd_desc(&desc,
59652f4b411aSAmritha Nambiar 					  i40e_aqc_opc_remove_cloud_filters);
59662f4b411aSAmritha Nambiar 
59672f4b411aSAmritha Nambiar 	buff_len = filter_count * sizeof(*filters);
59682f4b411aSAmritha Nambiar 	desc.datalen = cpu_to_le16(buff_len);
59692f4b411aSAmritha Nambiar 	desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
59702f4b411aSAmritha Nambiar 	cmd->num_filters = filter_count;
59712f4b411aSAmritha Nambiar 	cmd->seid = cpu_to_le16(seid);
59722f4b411aSAmritha Nambiar 
59732f4b411aSAmritha Nambiar 	status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
59742f4b411aSAmritha Nambiar 
59752f4b411aSAmritha Nambiar 	return status;
59762f4b411aSAmritha Nambiar }
59772f4b411aSAmritha Nambiar 
59782f4b411aSAmritha Nambiar /**
59792f4b411aSAmritha Nambiar  * i40e_aq_rem_cloud_filters_bb
59802f4b411aSAmritha Nambiar  * @hw: pointer to the hardware structure
59812f4b411aSAmritha Nambiar  * @seid: VSI seid to remove cloud filters from
59822f4b411aSAmritha Nambiar  * @filters: Buffer which contains the filters in big buffer to be removed
59832f4b411aSAmritha Nambiar  * @filter_count: number of filters contained in the buffer
59842f4b411aSAmritha Nambiar  *
59852f4b411aSAmritha Nambiar  * Remove the big buffer cloud filters for a given VSI.  The contents of the
59862f4b411aSAmritha Nambiar  * i40e_aqc_cloud_filters_element_bb are filled in by the caller of the
59872f4b411aSAmritha Nambiar  * function.
59882f4b411aSAmritha Nambiar  *
59892f4b411aSAmritha Nambiar  **/
59905180ff13SJan Sokolowski int
i40e_aq_rem_cloud_filters_bb(struct i40e_hw * hw,u16 seid,struct i40e_aqc_cloud_filters_element_bb * filters,u8 filter_count)59912f4b411aSAmritha Nambiar i40e_aq_rem_cloud_filters_bb(struct i40e_hw *hw, u16 seid,
59922f4b411aSAmritha Nambiar 			     struct i40e_aqc_cloud_filters_element_bb *filters,
59932f4b411aSAmritha Nambiar 			     u8 filter_count)
59942f4b411aSAmritha Nambiar {
59952f4b411aSAmritha Nambiar 	struct i40e_aq_desc desc;
59962f4b411aSAmritha Nambiar 	struct i40e_aqc_add_remove_cloud_filters *cmd =
59972f4b411aSAmritha Nambiar 	(struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
59982f4b411aSAmritha Nambiar 	u16 buff_len;
59995180ff13SJan Sokolowski 	int status;
60002f4b411aSAmritha Nambiar 	int i;
60012f4b411aSAmritha Nambiar 
60022f4b411aSAmritha Nambiar 	i40e_fill_default_direct_cmd_desc(&desc,
60032f4b411aSAmritha Nambiar 					  i40e_aqc_opc_remove_cloud_filters);
60042f4b411aSAmritha Nambiar 
60052f4b411aSAmritha Nambiar 	buff_len = filter_count * sizeof(*filters);
60062f4b411aSAmritha Nambiar 	desc.datalen = cpu_to_le16(buff_len);
60072f4b411aSAmritha Nambiar 	desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
60082f4b411aSAmritha Nambiar 	cmd->num_filters = filter_count;
60092f4b411aSAmritha Nambiar 	cmd->seid = cpu_to_le16(seid);
60102f4b411aSAmritha Nambiar 	cmd->big_buffer_flag = I40E_AQC_ADD_CLOUD_CMD_BB;
60112f4b411aSAmritha Nambiar 
60122f4b411aSAmritha Nambiar 	for (i = 0; i < filter_count; i++) {
60132f4b411aSAmritha Nambiar 		u16 tnl_type;
60142f4b411aSAmritha Nambiar 		u32 ti;
60152f4b411aSAmritha Nambiar 
60162f4b411aSAmritha Nambiar 		tnl_type = (le16_to_cpu(filters[i].element.flags) &
60172f4b411aSAmritha Nambiar 			   I40E_AQC_ADD_CLOUD_TNL_TYPE_MASK) >>
60182f4b411aSAmritha Nambiar 			   I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT;
60192f4b411aSAmritha Nambiar 
60202f4b411aSAmritha Nambiar 		/* Due to hardware eccentricities, the VNI for Geneve is shifted
60212f4b411aSAmritha Nambiar 		 * one more byte further than normally used for Tenant ID in
60222f4b411aSAmritha Nambiar 		 * other tunnel types.
60232f4b411aSAmritha Nambiar 		 */
60242f4b411aSAmritha Nambiar 		if (tnl_type == I40E_AQC_ADD_CLOUD_TNL_TYPE_GENEVE) {
60252f4b411aSAmritha Nambiar 			ti = le32_to_cpu(filters[i].element.tenant_id);
60262f4b411aSAmritha Nambiar 			filters[i].element.tenant_id = cpu_to_le32(ti << 8);
60272f4b411aSAmritha Nambiar 		}
60282f4b411aSAmritha Nambiar 	}
60292f4b411aSAmritha Nambiar 
60302f4b411aSAmritha Nambiar 	status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
60312f4b411aSAmritha Nambiar 
60321d5c960cSJingjing Wu 	return status;
60331d5c960cSJingjing Wu }
6034