1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /* Copyright (c) 2018, Intel Corporation. */
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun #include "ice_common.h"
5*4882a593Smuzhiyun #include "ice_sched.h"
6*4882a593Smuzhiyun #include "ice_adminq_cmd.h"
7*4882a593Smuzhiyun #include "ice_flow.h"
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun #define ICE_PF_RESET_WAIT_COUNT 300
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun /**
12*4882a593Smuzhiyun * ice_set_mac_type - Sets MAC type
13*4882a593Smuzhiyun * @hw: pointer to the HW structure
14*4882a593Smuzhiyun *
15*4882a593Smuzhiyun * This function sets the MAC type of the adapter based on the
16*4882a593Smuzhiyun * vendor ID and device ID stored in the HW structure.
17*4882a593Smuzhiyun */
ice_set_mac_type(struct ice_hw * hw)18*4882a593Smuzhiyun static enum ice_status ice_set_mac_type(struct ice_hw *hw)
19*4882a593Smuzhiyun {
20*4882a593Smuzhiyun if (hw->vendor_id != PCI_VENDOR_ID_INTEL)
21*4882a593Smuzhiyun return ICE_ERR_DEVICE_NOT_SUPPORTED;
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun switch (hw->device_id) {
24*4882a593Smuzhiyun case ICE_DEV_ID_E810C_BACKPLANE:
25*4882a593Smuzhiyun case ICE_DEV_ID_E810C_QSFP:
26*4882a593Smuzhiyun case ICE_DEV_ID_E810C_SFP:
27*4882a593Smuzhiyun case ICE_DEV_ID_E810_XXV_BACKPLANE:
28*4882a593Smuzhiyun case ICE_DEV_ID_E810_XXV_QSFP:
29*4882a593Smuzhiyun case ICE_DEV_ID_E810_XXV_SFP:
30*4882a593Smuzhiyun hw->mac_type = ICE_MAC_E810;
31*4882a593Smuzhiyun break;
32*4882a593Smuzhiyun case ICE_DEV_ID_E823C_10G_BASE_T:
33*4882a593Smuzhiyun case ICE_DEV_ID_E823C_BACKPLANE:
34*4882a593Smuzhiyun case ICE_DEV_ID_E823C_QSFP:
35*4882a593Smuzhiyun case ICE_DEV_ID_E823C_SFP:
36*4882a593Smuzhiyun case ICE_DEV_ID_E823C_SGMII:
37*4882a593Smuzhiyun case ICE_DEV_ID_E822C_10G_BASE_T:
38*4882a593Smuzhiyun case ICE_DEV_ID_E822C_BACKPLANE:
39*4882a593Smuzhiyun case ICE_DEV_ID_E822C_QSFP:
40*4882a593Smuzhiyun case ICE_DEV_ID_E822C_SFP:
41*4882a593Smuzhiyun case ICE_DEV_ID_E822C_SGMII:
42*4882a593Smuzhiyun case ICE_DEV_ID_E822L_10G_BASE_T:
43*4882a593Smuzhiyun case ICE_DEV_ID_E822L_BACKPLANE:
44*4882a593Smuzhiyun case ICE_DEV_ID_E822L_SFP:
45*4882a593Smuzhiyun case ICE_DEV_ID_E822L_SGMII:
46*4882a593Smuzhiyun case ICE_DEV_ID_E823L_10G_BASE_T:
47*4882a593Smuzhiyun case ICE_DEV_ID_E823L_1GBE:
48*4882a593Smuzhiyun case ICE_DEV_ID_E823L_BACKPLANE:
49*4882a593Smuzhiyun case ICE_DEV_ID_E823L_QSFP:
50*4882a593Smuzhiyun case ICE_DEV_ID_E823L_SFP:
51*4882a593Smuzhiyun hw->mac_type = ICE_MAC_GENERIC;
52*4882a593Smuzhiyun break;
53*4882a593Smuzhiyun default:
54*4882a593Smuzhiyun hw->mac_type = ICE_MAC_UNKNOWN;
55*4882a593Smuzhiyun break;
56*4882a593Smuzhiyun }
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT, "mac_type: %d\n", hw->mac_type);
59*4882a593Smuzhiyun return 0;
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun /**
63*4882a593Smuzhiyun * ice_clear_pf_cfg - Clear PF configuration
64*4882a593Smuzhiyun * @hw: pointer to the hardware structure
65*4882a593Smuzhiyun *
66*4882a593Smuzhiyun * Clears any existing PF configuration (VSIs, VSI lists, switch rules, port
67*4882a593Smuzhiyun * configuration, flow director filters, etc.).
68*4882a593Smuzhiyun */
ice_clear_pf_cfg(struct ice_hw * hw)69*4882a593Smuzhiyun enum ice_status ice_clear_pf_cfg(struct ice_hw *hw)
70*4882a593Smuzhiyun {
71*4882a593Smuzhiyun struct ice_aq_desc desc;
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_clear_pf_cfg);
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
76*4882a593Smuzhiyun }
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun /**
79*4882a593Smuzhiyun * ice_aq_manage_mac_read - manage MAC address read command
80*4882a593Smuzhiyun * @hw: pointer to the HW struct
81*4882a593Smuzhiyun * @buf: a virtual buffer to hold the manage MAC read response
82*4882a593Smuzhiyun * @buf_size: Size of the virtual buffer
83*4882a593Smuzhiyun * @cd: pointer to command details structure or NULL
84*4882a593Smuzhiyun *
85*4882a593Smuzhiyun * This function is used to return per PF station MAC address (0x0107).
86*4882a593Smuzhiyun * NOTE: Upon successful completion of this command, MAC address information
87*4882a593Smuzhiyun * is returned in user specified buffer. Please interpret user specified
88*4882a593Smuzhiyun * buffer as "manage_mac_read" response.
89*4882a593Smuzhiyun * Response such as various MAC addresses are stored in HW struct (port.mac)
90*4882a593Smuzhiyun * ice_discover_dev_caps is expected to be called before this function is
91*4882a593Smuzhiyun * called.
92*4882a593Smuzhiyun */
93*4882a593Smuzhiyun static enum ice_status
ice_aq_manage_mac_read(struct ice_hw * hw,void * buf,u16 buf_size,struct ice_sq_cd * cd)94*4882a593Smuzhiyun ice_aq_manage_mac_read(struct ice_hw *hw, void *buf, u16 buf_size,
95*4882a593Smuzhiyun struct ice_sq_cd *cd)
96*4882a593Smuzhiyun {
97*4882a593Smuzhiyun struct ice_aqc_manage_mac_read_resp *resp;
98*4882a593Smuzhiyun struct ice_aqc_manage_mac_read *cmd;
99*4882a593Smuzhiyun struct ice_aq_desc desc;
100*4882a593Smuzhiyun enum ice_status status;
101*4882a593Smuzhiyun u16 flags;
102*4882a593Smuzhiyun u8 i;
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun cmd = &desc.params.mac_read;
105*4882a593Smuzhiyun
106*4882a593Smuzhiyun if (buf_size < sizeof(*resp))
107*4882a593Smuzhiyun return ICE_ERR_BUF_TOO_SHORT;
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_manage_mac_read);
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
112*4882a593Smuzhiyun if (status)
113*4882a593Smuzhiyun return status;
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun resp = (struct ice_aqc_manage_mac_read_resp *)buf;
116*4882a593Smuzhiyun flags = le16_to_cpu(cmd->flags) & ICE_AQC_MAN_MAC_READ_M;
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun if (!(flags & ICE_AQC_MAN_MAC_LAN_ADDR_VALID)) {
119*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LAN, "got invalid MAC address\n");
120*4882a593Smuzhiyun return ICE_ERR_CFG;
121*4882a593Smuzhiyun }
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun /* A single port can report up to two (LAN and WoL) addresses */
124*4882a593Smuzhiyun for (i = 0; i < cmd->num_addr; i++)
125*4882a593Smuzhiyun if (resp[i].addr_type == ICE_AQC_MAN_MAC_ADDR_TYPE_LAN) {
126*4882a593Smuzhiyun ether_addr_copy(hw->port_info->mac.lan_addr,
127*4882a593Smuzhiyun resp[i].mac_addr);
128*4882a593Smuzhiyun ether_addr_copy(hw->port_info->mac.perm_addr,
129*4882a593Smuzhiyun resp[i].mac_addr);
130*4882a593Smuzhiyun break;
131*4882a593Smuzhiyun }
132*4882a593Smuzhiyun
133*4882a593Smuzhiyun return 0;
134*4882a593Smuzhiyun }
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun /**
137*4882a593Smuzhiyun * ice_aq_get_phy_caps - returns PHY capabilities
138*4882a593Smuzhiyun * @pi: port information structure
139*4882a593Smuzhiyun * @qual_mods: report qualified modules
140*4882a593Smuzhiyun * @report_mode: report mode capabilities
141*4882a593Smuzhiyun * @pcaps: structure for PHY capabilities to be filled
142*4882a593Smuzhiyun * @cd: pointer to command details structure or NULL
143*4882a593Smuzhiyun *
144*4882a593Smuzhiyun * Returns the various PHY capabilities supported on the Port (0x0600)
145*4882a593Smuzhiyun */
146*4882a593Smuzhiyun enum ice_status
ice_aq_get_phy_caps(struct ice_port_info * pi,bool qual_mods,u8 report_mode,struct ice_aqc_get_phy_caps_data * pcaps,struct ice_sq_cd * cd)147*4882a593Smuzhiyun ice_aq_get_phy_caps(struct ice_port_info *pi, bool qual_mods, u8 report_mode,
148*4882a593Smuzhiyun struct ice_aqc_get_phy_caps_data *pcaps,
149*4882a593Smuzhiyun struct ice_sq_cd *cd)
150*4882a593Smuzhiyun {
151*4882a593Smuzhiyun struct ice_aqc_get_phy_caps *cmd;
152*4882a593Smuzhiyun u16 pcaps_size = sizeof(*pcaps);
153*4882a593Smuzhiyun struct ice_aq_desc desc;
154*4882a593Smuzhiyun enum ice_status status;
155*4882a593Smuzhiyun struct ice_hw *hw;
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun cmd = &desc.params.get_phy;
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun if (!pcaps || (report_mode & ~ICE_AQC_REPORT_MODE_M) || !pi)
160*4882a593Smuzhiyun return ICE_ERR_PARAM;
161*4882a593Smuzhiyun hw = pi->hw;
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_phy_caps);
164*4882a593Smuzhiyun
165*4882a593Smuzhiyun if (qual_mods)
166*4882a593Smuzhiyun cmd->param0 |= cpu_to_le16(ICE_AQC_GET_PHY_RQM);
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun cmd->param0 |= cpu_to_le16(report_mode);
169*4882a593Smuzhiyun status = ice_aq_send_cmd(hw, &desc, pcaps, pcaps_size, cd);
170*4882a593Smuzhiyun
171*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, "get phy caps - report_mode = 0x%x\n",
172*4882a593Smuzhiyun report_mode);
173*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " phy_type_low = 0x%llx\n",
174*4882a593Smuzhiyun (unsigned long long)le64_to_cpu(pcaps->phy_type_low));
175*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " phy_type_high = 0x%llx\n",
176*4882a593Smuzhiyun (unsigned long long)le64_to_cpu(pcaps->phy_type_high));
177*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " caps = 0x%x\n", pcaps->caps);
178*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " low_power_ctrl_an = 0x%x\n",
179*4882a593Smuzhiyun pcaps->low_power_ctrl_an);
180*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " eee_cap = 0x%x\n", pcaps->eee_cap);
181*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " eeer_value = 0x%x\n",
182*4882a593Smuzhiyun pcaps->eeer_value);
183*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " link_fec_options = 0x%x\n",
184*4882a593Smuzhiyun pcaps->link_fec_options);
185*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " module_compliance_enforcement = 0x%x\n",
186*4882a593Smuzhiyun pcaps->module_compliance_enforcement);
187*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " extended_compliance_code = 0x%x\n",
188*4882a593Smuzhiyun pcaps->extended_compliance_code);
189*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " module_type[0] = 0x%x\n",
190*4882a593Smuzhiyun pcaps->module_type[0]);
191*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " module_type[1] = 0x%x\n",
192*4882a593Smuzhiyun pcaps->module_type[1]);
193*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " module_type[2] = 0x%x\n",
194*4882a593Smuzhiyun pcaps->module_type[2]);
195*4882a593Smuzhiyun
196*4882a593Smuzhiyun if (!status && report_mode == ICE_AQC_REPORT_TOPO_CAP_MEDIA) {
197*4882a593Smuzhiyun pi->phy.phy_type_low = le64_to_cpu(pcaps->phy_type_low);
198*4882a593Smuzhiyun pi->phy.phy_type_high = le64_to_cpu(pcaps->phy_type_high);
199*4882a593Smuzhiyun memcpy(pi->phy.link_info.module_type, &pcaps->module_type,
200*4882a593Smuzhiyun sizeof(pi->phy.link_info.module_type));
201*4882a593Smuzhiyun }
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun return status;
204*4882a593Smuzhiyun }
205*4882a593Smuzhiyun
206*4882a593Smuzhiyun /**
207*4882a593Smuzhiyun * ice_aq_get_link_topo_handle - get link topology node return status
208*4882a593Smuzhiyun * @pi: port information structure
209*4882a593Smuzhiyun * @node_type: requested node type
210*4882a593Smuzhiyun * @cd: pointer to command details structure or NULL
211*4882a593Smuzhiyun *
212*4882a593Smuzhiyun * Get link topology node return status for specified node type (0x06E0)
213*4882a593Smuzhiyun *
214*4882a593Smuzhiyun * Node type cage can be used to determine if cage is present. If AQC
215*4882a593Smuzhiyun * returns error (ENOENT), then no cage present. If no cage present, then
216*4882a593Smuzhiyun * connection type is backplane or BASE-T.
217*4882a593Smuzhiyun */
218*4882a593Smuzhiyun static enum ice_status
ice_aq_get_link_topo_handle(struct ice_port_info * pi,u8 node_type,struct ice_sq_cd * cd)219*4882a593Smuzhiyun ice_aq_get_link_topo_handle(struct ice_port_info *pi, u8 node_type,
220*4882a593Smuzhiyun struct ice_sq_cd *cd)
221*4882a593Smuzhiyun {
222*4882a593Smuzhiyun struct ice_aqc_get_link_topo *cmd;
223*4882a593Smuzhiyun struct ice_aq_desc desc;
224*4882a593Smuzhiyun
225*4882a593Smuzhiyun cmd = &desc.params.get_link_topo;
226*4882a593Smuzhiyun
227*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_link_topo);
228*4882a593Smuzhiyun
229*4882a593Smuzhiyun cmd->addr.node_type_ctx = (ICE_AQC_LINK_TOPO_NODE_CTX_PORT <<
230*4882a593Smuzhiyun ICE_AQC_LINK_TOPO_NODE_CTX_S);
231*4882a593Smuzhiyun
232*4882a593Smuzhiyun /* set node type */
233*4882a593Smuzhiyun cmd->addr.node_type_ctx |= (ICE_AQC_LINK_TOPO_NODE_TYPE_M & node_type);
234*4882a593Smuzhiyun
235*4882a593Smuzhiyun return ice_aq_send_cmd(pi->hw, &desc, NULL, 0, cd);
236*4882a593Smuzhiyun }
237*4882a593Smuzhiyun
238*4882a593Smuzhiyun /**
239*4882a593Smuzhiyun * ice_is_media_cage_present
240*4882a593Smuzhiyun * @pi: port information structure
241*4882a593Smuzhiyun *
242*4882a593Smuzhiyun * Returns true if media cage is present, else false. If no cage, then
243*4882a593Smuzhiyun * media type is backplane or BASE-T.
244*4882a593Smuzhiyun */
ice_is_media_cage_present(struct ice_port_info * pi)245*4882a593Smuzhiyun static bool ice_is_media_cage_present(struct ice_port_info *pi)
246*4882a593Smuzhiyun {
247*4882a593Smuzhiyun /* Node type cage can be used to determine if cage is present. If AQC
248*4882a593Smuzhiyun * returns error (ENOENT), then no cage present. If no cage present then
249*4882a593Smuzhiyun * connection type is backplane or BASE-T.
250*4882a593Smuzhiyun */
251*4882a593Smuzhiyun return !ice_aq_get_link_topo_handle(pi,
252*4882a593Smuzhiyun ICE_AQC_LINK_TOPO_NODE_TYPE_CAGE,
253*4882a593Smuzhiyun NULL);
254*4882a593Smuzhiyun }
255*4882a593Smuzhiyun
256*4882a593Smuzhiyun /**
257*4882a593Smuzhiyun * ice_get_media_type - Gets media type
258*4882a593Smuzhiyun * @pi: port information structure
259*4882a593Smuzhiyun */
ice_get_media_type(struct ice_port_info * pi)260*4882a593Smuzhiyun static enum ice_media_type ice_get_media_type(struct ice_port_info *pi)
261*4882a593Smuzhiyun {
262*4882a593Smuzhiyun struct ice_link_status *hw_link_info;
263*4882a593Smuzhiyun
264*4882a593Smuzhiyun if (!pi)
265*4882a593Smuzhiyun return ICE_MEDIA_UNKNOWN;
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun hw_link_info = &pi->phy.link_info;
268*4882a593Smuzhiyun if (hw_link_info->phy_type_low && hw_link_info->phy_type_high)
269*4882a593Smuzhiyun /* If more than one media type is selected, report unknown */
270*4882a593Smuzhiyun return ICE_MEDIA_UNKNOWN;
271*4882a593Smuzhiyun
272*4882a593Smuzhiyun if (hw_link_info->phy_type_low) {
273*4882a593Smuzhiyun /* 1G SGMII is a special case where some DA cable PHYs
274*4882a593Smuzhiyun * may show this as an option when it really shouldn't
275*4882a593Smuzhiyun * be since SGMII is meant to be between a MAC and a PHY
276*4882a593Smuzhiyun * in a backplane. Try to detect this case and handle it
277*4882a593Smuzhiyun */
278*4882a593Smuzhiyun if (hw_link_info->phy_type_low == ICE_PHY_TYPE_LOW_1G_SGMII &&
279*4882a593Smuzhiyun (hw_link_info->module_type[ICE_AQC_MOD_TYPE_IDENT] ==
280*4882a593Smuzhiyun ICE_AQC_MOD_TYPE_BYTE1_SFP_PLUS_CU_ACTIVE ||
281*4882a593Smuzhiyun hw_link_info->module_type[ICE_AQC_MOD_TYPE_IDENT] ==
282*4882a593Smuzhiyun ICE_AQC_MOD_TYPE_BYTE1_SFP_PLUS_CU_PASSIVE))
283*4882a593Smuzhiyun return ICE_MEDIA_DA;
284*4882a593Smuzhiyun
285*4882a593Smuzhiyun switch (hw_link_info->phy_type_low) {
286*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_1000BASE_SX:
287*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_1000BASE_LX:
288*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_10GBASE_SR:
289*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_10GBASE_LR:
290*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_10G_SFI_C2C:
291*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_25GBASE_SR:
292*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_25GBASE_LR:
293*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_40GBASE_SR4:
294*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_40GBASE_LR4:
295*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50GBASE_SR2:
296*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50GBASE_LR2:
297*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50GBASE_SR:
298*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50GBASE_FR:
299*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50GBASE_LR:
300*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100GBASE_SR4:
301*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100GBASE_LR4:
302*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100GBASE_SR2:
303*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100GBASE_DR:
304*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC:
305*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC:
306*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC:
307*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50G_LAUI2_AOC_ACC:
308*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50G_AUI2_AOC_ACC:
309*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50G_AUI1_AOC_ACC:
310*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC:
311*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC:
312*4882a593Smuzhiyun return ICE_MEDIA_FIBER;
313*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100BASE_TX:
314*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_1000BASE_T:
315*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_2500BASE_T:
316*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_5GBASE_T:
317*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_10GBASE_T:
318*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_25GBASE_T:
319*4882a593Smuzhiyun return ICE_MEDIA_BASET;
320*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_10G_SFI_DA:
321*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_25GBASE_CR:
322*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_25GBASE_CR_S:
323*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_25GBASE_CR1:
324*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_40GBASE_CR4:
325*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50GBASE_CR2:
326*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50GBASE_CP:
327*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100GBASE_CR4:
328*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4:
329*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100GBASE_CP2:
330*4882a593Smuzhiyun return ICE_MEDIA_DA;
331*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_25G_AUI_C2C:
332*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_40G_XLAUI:
333*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50G_LAUI2:
334*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50G_AUI2:
335*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50G_AUI1:
336*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100G_AUI4:
337*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100G_CAUI4:
338*4882a593Smuzhiyun if (ice_is_media_cage_present(pi))
339*4882a593Smuzhiyun return ICE_MEDIA_DA;
340*4882a593Smuzhiyun fallthrough;
341*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_1000BASE_KX:
342*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_2500BASE_KX:
343*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_2500BASE_X:
344*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_5GBASE_KR:
345*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_10GBASE_KR_CR1:
346*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_25GBASE_KR:
347*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_25GBASE_KR1:
348*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_25GBASE_KR_S:
349*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_40GBASE_KR4:
350*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4:
351*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50GBASE_KR2:
352*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100GBASE_KR4:
353*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4:
354*4882a593Smuzhiyun return ICE_MEDIA_BACKPLANE;
355*4882a593Smuzhiyun }
356*4882a593Smuzhiyun } else {
357*4882a593Smuzhiyun switch (hw_link_info->phy_type_high) {
358*4882a593Smuzhiyun case ICE_PHY_TYPE_HIGH_100G_AUI2:
359*4882a593Smuzhiyun case ICE_PHY_TYPE_HIGH_100G_CAUI2:
360*4882a593Smuzhiyun if (ice_is_media_cage_present(pi))
361*4882a593Smuzhiyun return ICE_MEDIA_DA;
362*4882a593Smuzhiyun fallthrough;
363*4882a593Smuzhiyun case ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4:
364*4882a593Smuzhiyun return ICE_MEDIA_BACKPLANE;
365*4882a593Smuzhiyun case ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC:
366*4882a593Smuzhiyun case ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC:
367*4882a593Smuzhiyun return ICE_MEDIA_FIBER;
368*4882a593Smuzhiyun }
369*4882a593Smuzhiyun }
370*4882a593Smuzhiyun return ICE_MEDIA_UNKNOWN;
371*4882a593Smuzhiyun }
372*4882a593Smuzhiyun
373*4882a593Smuzhiyun /**
374*4882a593Smuzhiyun * ice_aq_get_link_info
375*4882a593Smuzhiyun * @pi: port information structure
376*4882a593Smuzhiyun * @ena_lse: enable/disable LinkStatusEvent reporting
377*4882a593Smuzhiyun * @link: pointer to link status structure - optional
378*4882a593Smuzhiyun * @cd: pointer to command details structure or NULL
379*4882a593Smuzhiyun *
380*4882a593Smuzhiyun * Get Link Status (0x607). Returns the link status of the adapter.
381*4882a593Smuzhiyun */
382*4882a593Smuzhiyun enum ice_status
ice_aq_get_link_info(struct ice_port_info * pi,bool ena_lse,struct ice_link_status * link,struct ice_sq_cd * cd)383*4882a593Smuzhiyun ice_aq_get_link_info(struct ice_port_info *pi, bool ena_lse,
384*4882a593Smuzhiyun struct ice_link_status *link, struct ice_sq_cd *cd)
385*4882a593Smuzhiyun {
386*4882a593Smuzhiyun struct ice_aqc_get_link_status_data link_data = { 0 };
387*4882a593Smuzhiyun struct ice_aqc_get_link_status *resp;
388*4882a593Smuzhiyun struct ice_link_status *li_old, *li;
389*4882a593Smuzhiyun enum ice_media_type *hw_media_type;
390*4882a593Smuzhiyun struct ice_fc_info *hw_fc_info;
391*4882a593Smuzhiyun bool tx_pause, rx_pause;
392*4882a593Smuzhiyun struct ice_aq_desc desc;
393*4882a593Smuzhiyun enum ice_status status;
394*4882a593Smuzhiyun struct ice_hw *hw;
395*4882a593Smuzhiyun u16 cmd_flags;
396*4882a593Smuzhiyun
397*4882a593Smuzhiyun if (!pi)
398*4882a593Smuzhiyun return ICE_ERR_PARAM;
399*4882a593Smuzhiyun hw = pi->hw;
400*4882a593Smuzhiyun li_old = &pi->phy.link_info_old;
401*4882a593Smuzhiyun hw_media_type = &pi->phy.media_type;
402*4882a593Smuzhiyun li = &pi->phy.link_info;
403*4882a593Smuzhiyun hw_fc_info = &pi->fc;
404*4882a593Smuzhiyun
405*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_link_status);
406*4882a593Smuzhiyun cmd_flags = (ena_lse) ? ICE_AQ_LSE_ENA : ICE_AQ_LSE_DIS;
407*4882a593Smuzhiyun resp = &desc.params.get_link_status;
408*4882a593Smuzhiyun resp->cmd_flags = cpu_to_le16(cmd_flags);
409*4882a593Smuzhiyun resp->lport_num = pi->lport;
410*4882a593Smuzhiyun
411*4882a593Smuzhiyun status = ice_aq_send_cmd(hw, &desc, &link_data, sizeof(link_data), cd);
412*4882a593Smuzhiyun
413*4882a593Smuzhiyun if (status)
414*4882a593Smuzhiyun return status;
415*4882a593Smuzhiyun
416*4882a593Smuzhiyun /* save off old link status information */
417*4882a593Smuzhiyun *li_old = *li;
418*4882a593Smuzhiyun
419*4882a593Smuzhiyun /* update current link status information */
420*4882a593Smuzhiyun li->link_speed = le16_to_cpu(link_data.link_speed);
421*4882a593Smuzhiyun li->phy_type_low = le64_to_cpu(link_data.phy_type_low);
422*4882a593Smuzhiyun li->phy_type_high = le64_to_cpu(link_data.phy_type_high);
423*4882a593Smuzhiyun *hw_media_type = ice_get_media_type(pi);
424*4882a593Smuzhiyun li->link_info = link_data.link_info;
425*4882a593Smuzhiyun li->an_info = link_data.an_info;
426*4882a593Smuzhiyun li->ext_info = link_data.ext_info;
427*4882a593Smuzhiyun li->max_frame_size = le16_to_cpu(link_data.max_frame_size);
428*4882a593Smuzhiyun li->fec_info = link_data.cfg & ICE_AQ_FEC_MASK;
429*4882a593Smuzhiyun li->topo_media_conflict = link_data.topo_media_conflict;
430*4882a593Smuzhiyun li->pacing = link_data.cfg & (ICE_AQ_CFG_PACING_M |
431*4882a593Smuzhiyun ICE_AQ_CFG_PACING_TYPE_M);
432*4882a593Smuzhiyun
433*4882a593Smuzhiyun /* update fc info */
434*4882a593Smuzhiyun tx_pause = !!(link_data.an_info & ICE_AQ_LINK_PAUSE_TX);
435*4882a593Smuzhiyun rx_pause = !!(link_data.an_info & ICE_AQ_LINK_PAUSE_RX);
436*4882a593Smuzhiyun if (tx_pause && rx_pause)
437*4882a593Smuzhiyun hw_fc_info->current_mode = ICE_FC_FULL;
438*4882a593Smuzhiyun else if (tx_pause)
439*4882a593Smuzhiyun hw_fc_info->current_mode = ICE_FC_TX_PAUSE;
440*4882a593Smuzhiyun else if (rx_pause)
441*4882a593Smuzhiyun hw_fc_info->current_mode = ICE_FC_RX_PAUSE;
442*4882a593Smuzhiyun else
443*4882a593Smuzhiyun hw_fc_info->current_mode = ICE_FC_NONE;
444*4882a593Smuzhiyun
445*4882a593Smuzhiyun li->lse_ena = !!(resp->cmd_flags & cpu_to_le16(ICE_AQ_LSE_IS_ENABLED));
446*4882a593Smuzhiyun
447*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, "get link info\n");
448*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " link_speed = 0x%x\n", li->link_speed);
449*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " phy_type_low = 0x%llx\n",
450*4882a593Smuzhiyun (unsigned long long)li->phy_type_low);
451*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " phy_type_high = 0x%llx\n",
452*4882a593Smuzhiyun (unsigned long long)li->phy_type_high);
453*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " media_type = 0x%x\n", *hw_media_type);
454*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " link_info = 0x%x\n", li->link_info);
455*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " an_info = 0x%x\n", li->an_info);
456*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " ext_info = 0x%x\n", li->ext_info);
457*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " fec_info = 0x%x\n", li->fec_info);
458*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " lse_ena = 0x%x\n", li->lse_ena);
459*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " max_frame = 0x%x\n",
460*4882a593Smuzhiyun li->max_frame_size);
461*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " pacing = 0x%x\n", li->pacing);
462*4882a593Smuzhiyun
463*4882a593Smuzhiyun /* save link status information */
464*4882a593Smuzhiyun if (link)
465*4882a593Smuzhiyun *link = *li;
466*4882a593Smuzhiyun
467*4882a593Smuzhiyun /* flag cleared so calling functions don't call AQ again */
468*4882a593Smuzhiyun pi->phy.get_link_info = false;
469*4882a593Smuzhiyun
470*4882a593Smuzhiyun return 0;
471*4882a593Smuzhiyun }
472*4882a593Smuzhiyun
473*4882a593Smuzhiyun /**
474*4882a593Smuzhiyun * ice_fill_tx_timer_and_fc_thresh
475*4882a593Smuzhiyun * @hw: pointer to the HW struct
476*4882a593Smuzhiyun * @cmd: pointer to MAC cfg structure
477*4882a593Smuzhiyun *
478*4882a593Smuzhiyun * Add Tx timer and FC refresh threshold info to Set MAC Config AQ command
479*4882a593Smuzhiyun * descriptor
480*4882a593Smuzhiyun */
481*4882a593Smuzhiyun static void
ice_fill_tx_timer_and_fc_thresh(struct ice_hw * hw,struct ice_aqc_set_mac_cfg * cmd)482*4882a593Smuzhiyun ice_fill_tx_timer_and_fc_thresh(struct ice_hw *hw,
483*4882a593Smuzhiyun struct ice_aqc_set_mac_cfg *cmd)
484*4882a593Smuzhiyun {
485*4882a593Smuzhiyun u16 fc_thres_val, tx_timer_val;
486*4882a593Smuzhiyun u32 val;
487*4882a593Smuzhiyun
488*4882a593Smuzhiyun /* We read back the transmit timer and FC threshold value of
489*4882a593Smuzhiyun * LFC. Thus, we will use index =
490*4882a593Smuzhiyun * PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA_MAX_INDEX.
491*4882a593Smuzhiyun *
492*4882a593Smuzhiyun * Also, because we are operating on transmit timer and FC
493*4882a593Smuzhiyun * threshold of LFC, we don't turn on any bit in tx_tmr_priority
494*4882a593Smuzhiyun */
495*4882a593Smuzhiyun #define IDX_OF_LFC PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA_MAX_INDEX
496*4882a593Smuzhiyun
497*4882a593Smuzhiyun /* Retrieve the transmit timer */
498*4882a593Smuzhiyun val = rd32(hw, PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA(IDX_OF_LFC));
499*4882a593Smuzhiyun tx_timer_val = val &
500*4882a593Smuzhiyun PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA_HSEC_CTL_TX_PAUSE_QUANTA_M;
501*4882a593Smuzhiyun cmd->tx_tmr_value = cpu_to_le16(tx_timer_val);
502*4882a593Smuzhiyun
503*4882a593Smuzhiyun /* Retrieve the FC threshold */
504*4882a593Smuzhiyun val = rd32(hw, PRTMAC_HSEC_CTL_TX_PAUSE_REFRESH_TIMER(IDX_OF_LFC));
505*4882a593Smuzhiyun fc_thres_val = val & PRTMAC_HSEC_CTL_TX_PAUSE_REFRESH_TIMER_M;
506*4882a593Smuzhiyun
507*4882a593Smuzhiyun cmd->fc_refresh_threshold = cpu_to_le16(fc_thres_val);
508*4882a593Smuzhiyun }
509*4882a593Smuzhiyun
510*4882a593Smuzhiyun /**
511*4882a593Smuzhiyun * ice_aq_set_mac_cfg
512*4882a593Smuzhiyun * @hw: pointer to the HW struct
513*4882a593Smuzhiyun * @max_frame_size: Maximum Frame Size to be supported
514*4882a593Smuzhiyun * @cd: pointer to command details structure or NULL
515*4882a593Smuzhiyun *
516*4882a593Smuzhiyun * Set MAC configuration (0x0603)
517*4882a593Smuzhiyun */
518*4882a593Smuzhiyun enum ice_status
ice_aq_set_mac_cfg(struct ice_hw * hw,u16 max_frame_size,struct ice_sq_cd * cd)519*4882a593Smuzhiyun ice_aq_set_mac_cfg(struct ice_hw *hw, u16 max_frame_size, struct ice_sq_cd *cd)
520*4882a593Smuzhiyun {
521*4882a593Smuzhiyun struct ice_aqc_set_mac_cfg *cmd;
522*4882a593Smuzhiyun struct ice_aq_desc desc;
523*4882a593Smuzhiyun
524*4882a593Smuzhiyun cmd = &desc.params.set_mac_cfg;
525*4882a593Smuzhiyun
526*4882a593Smuzhiyun if (max_frame_size == 0)
527*4882a593Smuzhiyun return ICE_ERR_PARAM;
528*4882a593Smuzhiyun
529*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_mac_cfg);
530*4882a593Smuzhiyun
531*4882a593Smuzhiyun cmd->max_frame_size = cpu_to_le16(max_frame_size);
532*4882a593Smuzhiyun
533*4882a593Smuzhiyun ice_fill_tx_timer_and_fc_thresh(hw, cmd);
534*4882a593Smuzhiyun
535*4882a593Smuzhiyun return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
536*4882a593Smuzhiyun }
537*4882a593Smuzhiyun
538*4882a593Smuzhiyun /**
539*4882a593Smuzhiyun * ice_init_fltr_mgmt_struct - initializes filter management list and locks
540*4882a593Smuzhiyun * @hw: pointer to the HW struct
541*4882a593Smuzhiyun */
ice_init_fltr_mgmt_struct(struct ice_hw * hw)542*4882a593Smuzhiyun static enum ice_status ice_init_fltr_mgmt_struct(struct ice_hw *hw)
543*4882a593Smuzhiyun {
544*4882a593Smuzhiyun struct ice_switch_info *sw;
545*4882a593Smuzhiyun enum ice_status status;
546*4882a593Smuzhiyun
547*4882a593Smuzhiyun hw->switch_info = devm_kzalloc(ice_hw_to_dev(hw),
548*4882a593Smuzhiyun sizeof(*hw->switch_info), GFP_KERNEL);
549*4882a593Smuzhiyun sw = hw->switch_info;
550*4882a593Smuzhiyun
551*4882a593Smuzhiyun if (!sw)
552*4882a593Smuzhiyun return ICE_ERR_NO_MEMORY;
553*4882a593Smuzhiyun
554*4882a593Smuzhiyun INIT_LIST_HEAD(&sw->vsi_list_map_head);
555*4882a593Smuzhiyun
556*4882a593Smuzhiyun status = ice_init_def_sw_recp(hw);
557*4882a593Smuzhiyun if (status) {
558*4882a593Smuzhiyun devm_kfree(ice_hw_to_dev(hw), hw->switch_info);
559*4882a593Smuzhiyun return status;
560*4882a593Smuzhiyun }
561*4882a593Smuzhiyun return 0;
562*4882a593Smuzhiyun }
563*4882a593Smuzhiyun
564*4882a593Smuzhiyun /**
565*4882a593Smuzhiyun * ice_cleanup_fltr_mgmt_struct - cleanup filter management list and locks
566*4882a593Smuzhiyun * @hw: pointer to the HW struct
567*4882a593Smuzhiyun */
ice_cleanup_fltr_mgmt_struct(struct ice_hw * hw)568*4882a593Smuzhiyun static void ice_cleanup_fltr_mgmt_struct(struct ice_hw *hw)
569*4882a593Smuzhiyun {
570*4882a593Smuzhiyun struct ice_switch_info *sw = hw->switch_info;
571*4882a593Smuzhiyun struct ice_vsi_list_map_info *v_pos_map;
572*4882a593Smuzhiyun struct ice_vsi_list_map_info *v_tmp_map;
573*4882a593Smuzhiyun struct ice_sw_recipe *recps;
574*4882a593Smuzhiyun u8 i;
575*4882a593Smuzhiyun
576*4882a593Smuzhiyun list_for_each_entry_safe(v_pos_map, v_tmp_map, &sw->vsi_list_map_head,
577*4882a593Smuzhiyun list_entry) {
578*4882a593Smuzhiyun list_del(&v_pos_map->list_entry);
579*4882a593Smuzhiyun devm_kfree(ice_hw_to_dev(hw), v_pos_map);
580*4882a593Smuzhiyun }
581*4882a593Smuzhiyun recps = hw->switch_info->recp_list;
582*4882a593Smuzhiyun for (i = 0; i < ICE_SW_LKUP_LAST; i++) {
583*4882a593Smuzhiyun struct ice_fltr_mgmt_list_entry *lst_itr, *tmp_entry;
584*4882a593Smuzhiyun
585*4882a593Smuzhiyun recps[i].root_rid = i;
586*4882a593Smuzhiyun mutex_destroy(&recps[i].filt_rule_lock);
587*4882a593Smuzhiyun list_for_each_entry_safe(lst_itr, tmp_entry,
588*4882a593Smuzhiyun &recps[i].filt_rules, list_entry) {
589*4882a593Smuzhiyun list_del(&lst_itr->list_entry);
590*4882a593Smuzhiyun devm_kfree(ice_hw_to_dev(hw), lst_itr);
591*4882a593Smuzhiyun }
592*4882a593Smuzhiyun }
593*4882a593Smuzhiyun ice_rm_all_sw_replay_rule_info(hw);
594*4882a593Smuzhiyun devm_kfree(ice_hw_to_dev(hw), sw->recp_list);
595*4882a593Smuzhiyun devm_kfree(ice_hw_to_dev(hw), sw);
596*4882a593Smuzhiyun }
597*4882a593Smuzhiyun
598*4882a593Smuzhiyun /**
599*4882a593Smuzhiyun * ice_get_fw_log_cfg - get FW logging configuration
600*4882a593Smuzhiyun * @hw: pointer to the HW struct
601*4882a593Smuzhiyun */
ice_get_fw_log_cfg(struct ice_hw * hw)602*4882a593Smuzhiyun static enum ice_status ice_get_fw_log_cfg(struct ice_hw *hw)
603*4882a593Smuzhiyun {
604*4882a593Smuzhiyun struct ice_aq_desc desc;
605*4882a593Smuzhiyun enum ice_status status;
606*4882a593Smuzhiyun __le16 *config;
607*4882a593Smuzhiyun u16 size;
608*4882a593Smuzhiyun
609*4882a593Smuzhiyun size = sizeof(*config) * ICE_AQC_FW_LOG_ID_MAX;
610*4882a593Smuzhiyun config = devm_kzalloc(ice_hw_to_dev(hw), size, GFP_KERNEL);
611*4882a593Smuzhiyun if (!config)
612*4882a593Smuzhiyun return ICE_ERR_NO_MEMORY;
613*4882a593Smuzhiyun
614*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_fw_logging_info);
615*4882a593Smuzhiyun
616*4882a593Smuzhiyun status = ice_aq_send_cmd(hw, &desc, config, size, NULL);
617*4882a593Smuzhiyun if (!status) {
618*4882a593Smuzhiyun u16 i;
619*4882a593Smuzhiyun
620*4882a593Smuzhiyun /* Save FW logging information into the HW structure */
621*4882a593Smuzhiyun for (i = 0; i < ICE_AQC_FW_LOG_ID_MAX; i++) {
622*4882a593Smuzhiyun u16 v, m, flgs;
623*4882a593Smuzhiyun
624*4882a593Smuzhiyun v = le16_to_cpu(config[i]);
625*4882a593Smuzhiyun m = (v & ICE_AQC_FW_LOG_ID_M) >> ICE_AQC_FW_LOG_ID_S;
626*4882a593Smuzhiyun flgs = (v & ICE_AQC_FW_LOG_EN_M) >> ICE_AQC_FW_LOG_EN_S;
627*4882a593Smuzhiyun
628*4882a593Smuzhiyun if (m < ICE_AQC_FW_LOG_ID_MAX)
629*4882a593Smuzhiyun hw->fw_log.evnts[m].cur = flgs;
630*4882a593Smuzhiyun }
631*4882a593Smuzhiyun }
632*4882a593Smuzhiyun
633*4882a593Smuzhiyun devm_kfree(ice_hw_to_dev(hw), config);
634*4882a593Smuzhiyun
635*4882a593Smuzhiyun return status;
636*4882a593Smuzhiyun }
637*4882a593Smuzhiyun
638*4882a593Smuzhiyun /**
639*4882a593Smuzhiyun * ice_cfg_fw_log - configure FW logging
640*4882a593Smuzhiyun * @hw: pointer to the HW struct
641*4882a593Smuzhiyun * @enable: enable certain FW logging events if true, disable all if false
642*4882a593Smuzhiyun *
643*4882a593Smuzhiyun * This function enables/disables the FW logging via Rx CQ events and a UART
644*4882a593Smuzhiyun * port based on predetermined configurations. FW logging via the Rx CQ can be
645*4882a593Smuzhiyun * enabled/disabled for individual PF's. However, FW logging via the UART can
646*4882a593Smuzhiyun * only be enabled/disabled for all PFs on the same device.
647*4882a593Smuzhiyun *
648*4882a593Smuzhiyun * To enable overall FW logging, the "cq_en" and "uart_en" enable bits in
649*4882a593Smuzhiyun * hw->fw_log need to be set accordingly, e.g. based on user-provided input,
650*4882a593Smuzhiyun * before initializing the device.
651*4882a593Smuzhiyun *
652*4882a593Smuzhiyun * When re/configuring FW logging, callers need to update the "cfg" elements of
653*4882a593Smuzhiyun * the hw->fw_log.evnts array with the desired logging event configurations for
654*4882a593Smuzhiyun * modules of interest. When disabling FW logging completely, the callers can
655*4882a593Smuzhiyun * just pass false in the "enable" parameter. On completion, the function will
656*4882a593Smuzhiyun * update the "cur" element of the hw->fw_log.evnts array with the resulting
657*4882a593Smuzhiyun * logging event configurations of the modules that are being re/configured. FW
658*4882a593Smuzhiyun * logging modules that are not part of a reconfiguration operation retain their
659*4882a593Smuzhiyun * previous states.
660*4882a593Smuzhiyun *
661*4882a593Smuzhiyun * Before resetting the device, it is recommended that the driver disables FW
662*4882a593Smuzhiyun * logging before shutting down the control queue. When disabling FW logging
663*4882a593Smuzhiyun * ("enable" = false), the latest configurations of FW logging events stored in
664*4882a593Smuzhiyun * hw->fw_log.evnts[] are not overridden to allow them to be reconfigured after
665*4882a593Smuzhiyun * a device reset.
666*4882a593Smuzhiyun *
667*4882a593Smuzhiyun * When enabling FW logging to emit log messages via the Rx CQ during the
668*4882a593Smuzhiyun * device's initialization phase, a mechanism alternative to interrupt handlers
669*4882a593Smuzhiyun * needs to be used to extract FW log messages from the Rx CQ periodically and
670*4882a593Smuzhiyun * to prevent the Rx CQ from being full and stalling other types of control
671*4882a593Smuzhiyun * messages from FW to SW. Interrupts are typically disabled during the device's
672*4882a593Smuzhiyun * initialization phase.
673*4882a593Smuzhiyun */
ice_cfg_fw_log(struct ice_hw * hw,bool enable)674*4882a593Smuzhiyun static enum ice_status ice_cfg_fw_log(struct ice_hw *hw, bool enable)
675*4882a593Smuzhiyun {
676*4882a593Smuzhiyun struct ice_aqc_fw_logging *cmd;
677*4882a593Smuzhiyun enum ice_status status = 0;
678*4882a593Smuzhiyun u16 i, chgs = 0, len = 0;
679*4882a593Smuzhiyun struct ice_aq_desc desc;
680*4882a593Smuzhiyun __le16 *data = NULL;
681*4882a593Smuzhiyun u8 actv_evnts = 0;
682*4882a593Smuzhiyun void *buf = NULL;
683*4882a593Smuzhiyun
684*4882a593Smuzhiyun if (!hw->fw_log.cq_en && !hw->fw_log.uart_en)
685*4882a593Smuzhiyun return 0;
686*4882a593Smuzhiyun
687*4882a593Smuzhiyun /* Disable FW logging only when the control queue is still responsive */
688*4882a593Smuzhiyun if (!enable &&
689*4882a593Smuzhiyun (!hw->fw_log.actv_evnts || !ice_check_sq_alive(hw, &hw->adminq)))
690*4882a593Smuzhiyun return 0;
691*4882a593Smuzhiyun
692*4882a593Smuzhiyun /* Get current FW log settings */
693*4882a593Smuzhiyun status = ice_get_fw_log_cfg(hw);
694*4882a593Smuzhiyun if (status)
695*4882a593Smuzhiyun return status;
696*4882a593Smuzhiyun
697*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_fw_logging);
698*4882a593Smuzhiyun cmd = &desc.params.fw_logging;
699*4882a593Smuzhiyun
700*4882a593Smuzhiyun /* Indicate which controls are valid */
701*4882a593Smuzhiyun if (hw->fw_log.cq_en)
702*4882a593Smuzhiyun cmd->log_ctrl_valid |= ICE_AQC_FW_LOG_AQ_VALID;
703*4882a593Smuzhiyun
704*4882a593Smuzhiyun if (hw->fw_log.uart_en)
705*4882a593Smuzhiyun cmd->log_ctrl_valid |= ICE_AQC_FW_LOG_UART_VALID;
706*4882a593Smuzhiyun
707*4882a593Smuzhiyun if (enable) {
708*4882a593Smuzhiyun /* Fill in an array of entries with FW logging modules and
709*4882a593Smuzhiyun * logging events being reconfigured.
710*4882a593Smuzhiyun */
711*4882a593Smuzhiyun for (i = 0; i < ICE_AQC_FW_LOG_ID_MAX; i++) {
712*4882a593Smuzhiyun u16 val;
713*4882a593Smuzhiyun
714*4882a593Smuzhiyun /* Keep track of enabled event types */
715*4882a593Smuzhiyun actv_evnts |= hw->fw_log.evnts[i].cfg;
716*4882a593Smuzhiyun
717*4882a593Smuzhiyun if (hw->fw_log.evnts[i].cfg == hw->fw_log.evnts[i].cur)
718*4882a593Smuzhiyun continue;
719*4882a593Smuzhiyun
720*4882a593Smuzhiyun if (!data) {
721*4882a593Smuzhiyun data = devm_kcalloc(ice_hw_to_dev(hw),
722*4882a593Smuzhiyun ICE_AQC_FW_LOG_ID_MAX,
723*4882a593Smuzhiyun sizeof(*data),
724*4882a593Smuzhiyun GFP_KERNEL);
725*4882a593Smuzhiyun if (!data)
726*4882a593Smuzhiyun return ICE_ERR_NO_MEMORY;
727*4882a593Smuzhiyun }
728*4882a593Smuzhiyun
729*4882a593Smuzhiyun val = i << ICE_AQC_FW_LOG_ID_S;
730*4882a593Smuzhiyun val |= hw->fw_log.evnts[i].cfg << ICE_AQC_FW_LOG_EN_S;
731*4882a593Smuzhiyun data[chgs++] = cpu_to_le16(val);
732*4882a593Smuzhiyun }
733*4882a593Smuzhiyun
734*4882a593Smuzhiyun /* Only enable FW logging if at least one module is specified.
735*4882a593Smuzhiyun * If FW logging is currently enabled but all modules are not
736*4882a593Smuzhiyun * enabled to emit log messages, disable FW logging altogether.
737*4882a593Smuzhiyun */
738*4882a593Smuzhiyun if (actv_evnts) {
739*4882a593Smuzhiyun /* Leave if there is effectively no change */
740*4882a593Smuzhiyun if (!chgs)
741*4882a593Smuzhiyun goto out;
742*4882a593Smuzhiyun
743*4882a593Smuzhiyun if (hw->fw_log.cq_en)
744*4882a593Smuzhiyun cmd->log_ctrl |= ICE_AQC_FW_LOG_AQ_EN;
745*4882a593Smuzhiyun
746*4882a593Smuzhiyun if (hw->fw_log.uart_en)
747*4882a593Smuzhiyun cmd->log_ctrl |= ICE_AQC_FW_LOG_UART_EN;
748*4882a593Smuzhiyun
749*4882a593Smuzhiyun buf = data;
750*4882a593Smuzhiyun len = sizeof(*data) * chgs;
751*4882a593Smuzhiyun desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
752*4882a593Smuzhiyun }
753*4882a593Smuzhiyun }
754*4882a593Smuzhiyun
755*4882a593Smuzhiyun status = ice_aq_send_cmd(hw, &desc, buf, len, NULL);
756*4882a593Smuzhiyun if (!status) {
757*4882a593Smuzhiyun /* Update the current configuration to reflect events enabled.
758*4882a593Smuzhiyun * hw->fw_log.cq_en and hw->fw_log.uart_en indicate if the FW
759*4882a593Smuzhiyun * logging mode is enabled for the device. They do not reflect
760*4882a593Smuzhiyun * actual modules being enabled to emit log messages. So, their
761*4882a593Smuzhiyun * values remain unchanged even when all modules are disabled.
762*4882a593Smuzhiyun */
763*4882a593Smuzhiyun u16 cnt = enable ? chgs : (u16)ICE_AQC_FW_LOG_ID_MAX;
764*4882a593Smuzhiyun
765*4882a593Smuzhiyun hw->fw_log.actv_evnts = actv_evnts;
766*4882a593Smuzhiyun for (i = 0; i < cnt; i++) {
767*4882a593Smuzhiyun u16 v, m;
768*4882a593Smuzhiyun
769*4882a593Smuzhiyun if (!enable) {
770*4882a593Smuzhiyun /* When disabling all FW logging events as part
771*4882a593Smuzhiyun * of device's de-initialization, the original
772*4882a593Smuzhiyun * configurations are retained, and can be used
773*4882a593Smuzhiyun * to reconfigure FW logging later if the device
774*4882a593Smuzhiyun * is re-initialized.
775*4882a593Smuzhiyun */
776*4882a593Smuzhiyun hw->fw_log.evnts[i].cur = 0;
777*4882a593Smuzhiyun continue;
778*4882a593Smuzhiyun }
779*4882a593Smuzhiyun
780*4882a593Smuzhiyun v = le16_to_cpu(data[i]);
781*4882a593Smuzhiyun m = (v & ICE_AQC_FW_LOG_ID_M) >> ICE_AQC_FW_LOG_ID_S;
782*4882a593Smuzhiyun hw->fw_log.evnts[m].cur = hw->fw_log.evnts[m].cfg;
783*4882a593Smuzhiyun }
784*4882a593Smuzhiyun }
785*4882a593Smuzhiyun
786*4882a593Smuzhiyun out:
787*4882a593Smuzhiyun if (data)
788*4882a593Smuzhiyun devm_kfree(ice_hw_to_dev(hw), data);
789*4882a593Smuzhiyun
790*4882a593Smuzhiyun return status;
791*4882a593Smuzhiyun }
792*4882a593Smuzhiyun
793*4882a593Smuzhiyun /**
794*4882a593Smuzhiyun * ice_output_fw_log
795*4882a593Smuzhiyun * @hw: pointer to the HW struct
796*4882a593Smuzhiyun * @desc: pointer to the AQ message descriptor
797*4882a593Smuzhiyun * @buf: pointer to the buffer accompanying the AQ message
798*4882a593Smuzhiyun *
799*4882a593Smuzhiyun * Formats a FW Log message and outputs it via the standard driver logs.
800*4882a593Smuzhiyun */
ice_output_fw_log(struct ice_hw * hw,struct ice_aq_desc * desc,void * buf)801*4882a593Smuzhiyun void ice_output_fw_log(struct ice_hw *hw, struct ice_aq_desc *desc, void *buf)
802*4882a593Smuzhiyun {
803*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_FW_LOG, "[ FW Log Msg Start ]\n");
804*4882a593Smuzhiyun ice_debug_array(hw, ICE_DBG_FW_LOG, 16, 1, (u8 *)buf,
805*4882a593Smuzhiyun le16_to_cpu(desc->datalen));
806*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_FW_LOG, "[ FW Log Msg End ]\n");
807*4882a593Smuzhiyun }
808*4882a593Smuzhiyun
809*4882a593Smuzhiyun /**
810*4882a593Smuzhiyun * ice_get_itr_intrl_gran
811*4882a593Smuzhiyun * @hw: pointer to the HW struct
812*4882a593Smuzhiyun *
813*4882a593Smuzhiyun * Determines the ITR/INTRL granularities based on the maximum aggregate
814*4882a593Smuzhiyun * bandwidth according to the device's configuration during power-on.
815*4882a593Smuzhiyun */
ice_get_itr_intrl_gran(struct ice_hw * hw)816*4882a593Smuzhiyun static void ice_get_itr_intrl_gran(struct ice_hw *hw)
817*4882a593Smuzhiyun {
818*4882a593Smuzhiyun u8 max_agg_bw = (rd32(hw, GL_PWR_MODE_CTL) &
819*4882a593Smuzhiyun GL_PWR_MODE_CTL_CAR_MAX_BW_M) >>
820*4882a593Smuzhiyun GL_PWR_MODE_CTL_CAR_MAX_BW_S;
821*4882a593Smuzhiyun
822*4882a593Smuzhiyun switch (max_agg_bw) {
823*4882a593Smuzhiyun case ICE_MAX_AGG_BW_200G:
824*4882a593Smuzhiyun case ICE_MAX_AGG_BW_100G:
825*4882a593Smuzhiyun case ICE_MAX_AGG_BW_50G:
826*4882a593Smuzhiyun hw->itr_gran = ICE_ITR_GRAN_ABOVE_25;
827*4882a593Smuzhiyun hw->intrl_gran = ICE_INTRL_GRAN_ABOVE_25;
828*4882a593Smuzhiyun break;
829*4882a593Smuzhiyun case ICE_MAX_AGG_BW_25G:
830*4882a593Smuzhiyun hw->itr_gran = ICE_ITR_GRAN_MAX_25;
831*4882a593Smuzhiyun hw->intrl_gran = ICE_INTRL_GRAN_MAX_25;
832*4882a593Smuzhiyun break;
833*4882a593Smuzhiyun }
834*4882a593Smuzhiyun }
835*4882a593Smuzhiyun
836*4882a593Smuzhiyun /**
837*4882a593Smuzhiyun * ice_init_hw - main hardware initialization routine
838*4882a593Smuzhiyun * @hw: pointer to the hardware structure
839*4882a593Smuzhiyun */
ice_init_hw(struct ice_hw * hw)840*4882a593Smuzhiyun enum ice_status ice_init_hw(struct ice_hw *hw)
841*4882a593Smuzhiyun {
842*4882a593Smuzhiyun struct ice_aqc_get_phy_caps_data *pcaps;
843*4882a593Smuzhiyun enum ice_status status;
844*4882a593Smuzhiyun u16 mac_buf_len;
845*4882a593Smuzhiyun void *mac_buf;
846*4882a593Smuzhiyun
847*4882a593Smuzhiyun /* Set MAC type based on DeviceID */
848*4882a593Smuzhiyun status = ice_set_mac_type(hw);
849*4882a593Smuzhiyun if (status)
850*4882a593Smuzhiyun return status;
851*4882a593Smuzhiyun
852*4882a593Smuzhiyun hw->pf_id = (u8)(rd32(hw, PF_FUNC_RID) &
853*4882a593Smuzhiyun PF_FUNC_RID_FUNC_NUM_M) >>
854*4882a593Smuzhiyun PF_FUNC_RID_FUNC_NUM_S;
855*4882a593Smuzhiyun
856*4882a593Smuzhiyun status = ice_reset(hw, ICE_RESET_PFR);
857*4882a593Smuzhiyun if (status)
858*4882a593Smuzhiyun return status;
859*4882a593Smuzhiyun
860*4882a593Smuzhiyun ice_get_itr_intrl_gran(hw);
861*4882a593Smuzhiyun
862*4882a593Smuzhiyun status = ice_create_all_ctrlq(hw);
863*4882a593Smuzhiyun if (status)
864*4882a593Smuzhiyun goto err_unroll_cqinit;
865*4882a593Smuzhiyun
866*4882a593Smuzhiyun /* Enable FW logging. Not fatal if this fails. */
867*4882a593Smuzhiyun status = ice_cfg_fw_log(hw, true);
868*4882a593Smuzhiyun if (status)
869*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT, "Failed to enable FW logging.\n");
870*4882a593Smuzhiyun
871*4882a593Smuzhiyun status = ice_clear_pf_cfg(hw);
872*4882a593Smuzhiyun if (status)
873*4882a593Smuzhiyun goto err_unroll_cqinit;
874*4882a593Smuzhiyun
875*4882a593Smuzhiyun /* Set bit to enable Flow Director filters */
876*4882a593Smuzhiyun wr32(hw, PFQF_FD_ENA, PFQF_FD_ENA_FD_ENA_M);
877*4882a593Smuzhiyun INIT_LIST_HEAD(&hw->fdir_list_head);
878*4882a593Smuzhiyun
879*4882a593Smuzhiyun ice_clear_pxe_mode(hw);
880*4882a593Smuzhiyun
881*4882a593Smuzhiyun status = ice_init_nvm(hw);
882*4882a593Smuzhiyun if (status)
883*4882a593Smuzhiyun goto err_unroll_cqinit;
884*4882a593Smuzhiyun
885*4882a593Smuzhiyun status = ice_get_caps(hw);
886*4882a593Smuzhiyun if (status)
887*4882a593Smuzhiyun goto err_unroll_cqinit;
888*4882a593Smuzhiyun
889*4882a593Smuzhiyun hw->port_info = devm_kzalloc(ice_hw_to_dev(hw),
890*4882a593Smuzhiyun sizeof(*hw->port_info), GFP_KERNEL);
891*4882a593Smuzhiyun if (!hw->port_info) {
892*4882a593Smuzhiyun status = ICE_ERR_NO_MEMORY;
893*4882a593Smuzhiyun goto err_unroll_cqinit;
894*4882a593Smuzhiyun }
895*4882a593Smuzhiyun
896*4882a593Smuzhiyun /* set the back pointer to HW */
897*4882a593Smuzhiyun hw->port_info->hw = hw;
898*4882a593Smuzhiyun
899*4882a593Smuzhiyun /* Initialize port_info struct with switch configuration data */
900*4882a593Smuzhiyun status = ice_get_initial_sw_cfg(hw);
901*4882a593Smuzhiyun if (status)
902*4882a593Smuzhiyun goto err_unroll_alloc;
903*4882a593Smuzhiyun
904*4882a593Smuzhiyun hw->evb_veb = true;
905*4882a593Smuzhiyun
906*4882a593Smuzhiyun /* Query the allocated resources for Tx scheduler */
907*4882a593Smuzhiyun status = ice_sched_query_res_alloc(hw);
908*4882a593Smuzhiyun if (status) {
909*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_SCHED,
910*4882a593Smuzhiyun "Failed to get scheduler allocated resources\n");
911*4882a593Smuzhiyun goto err_unroll_alloc;
912*4882a593Smuzhiyun }
913*4882a593Smuzhiyun
914*4882a593Smuzhiyun /* Initialize port_info struct with scheduler data */
915*4882a593Smuzhiyun status = ice_sched_init_port(hw->port_info);
916*4882a593Smuzhiyun if (status)
917*4882a593Smuzhiyun goto err_unroll_sched;
918*4882a593Smuzhiyun
919*4882a593Smuzhiyun pcaps = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*pcaps), GFP_KERNEL);
920*4882a593Smuzhiyun if (!pcaps) {
921*4882a593Smuzhiyun status = ICE_ERR_NO_MEMORY;
922*4882a593Smuzhiyun goto err_unroll_sched;
923*4882a593Smuzhiyun }
924*4882a593Smuzhiyun
925*4882a593Smuzhiyun /* Initialize port_info struct with PHY capabilities */
926*4882a593Smuzhiyun status = ice_aq_get_phy_caps(hw->port_info, false,
927*4882a593Smuzhiyun ICE_AQC_REPORT_TOPO_CAP_MEDIA, pcaps,
928*4882a593Smuzhiyun NULL);
929*4882a593Smuzhiyun devm_kfree(ice_hw_to_dev(hw), pcaps);
930*4882a593Smuzhiyun if (status)
931*4882a593Smuzhiyun goto err_unroll_sched;
932*4882a593Smuzhiyun
933*4882a593Smuzhiyun /* Initialize port_info struct with link information */
934*4882a593Smuzhiyun status = ice_aq_get_link_info(hw->port_info, false, NULL, NULL);
935*4882a593Smuzhiyun if (status)
936*4882a593Smuzhiyun goto err_unroll_sched;
937*4882a593Smuzhiyun
938*4882a593Smuzhiyun /* need a valid SW entry point to build a Tx tree */
939*4882a593Smuzhiyun if (!hw->sw_entry_point_layer) {
940*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_SCHED, "invalid sw entry point\n");
941*4882a593Smuzhiyun status = ICE_ERR_CFG;
942*4882a593Smuzhiyun goto err_unroll_sched;
943*4882a593Smuzhiyun }
944*4882a593Smuzhiyun INIT_LIST_HEAD(&hw->agg_list);
945*4882a593Smuzhiyun /* Initialize max burst size */
946*4882a593Smuzhiyun if (!hw->max_burst_size)
947*4882a593Smuzhiyun ice_cfg_rl_burst_size(hw, ICE_SCHED_DFLT_BURST_SIZE);
948*4882a593Smuzhiyun
949*4882a593Smuzhiyun status = ice_init_fltr_mgmt_struct(hw);
950*4882a593Smuzhiyun if (status)
951*4882a593Smuzhiyun goto err_unroll_sched;
952*4882a593Smuzhiyun
953*4882a593Smuzhiyun /* Get MAC information */
954*4882a593Smuzhiyun /* A single port can report up to two (LAN and WoL) addresses */
955*4882a593Smuzhiyun mac_buf = devm_kcalloc(ice_hw_to_dev(hw), 2,
956*4882a593Smuzhiyun sizeof(struct ice_aqc_manage_mac_read_resp),
957*4882a593Smuzhiyun GFP_KERNEL);
958*4882a593Smuzhiyun mac_buf_len = 2 * sizeof(struct ice_aqc_manage_mac_read_resp);
959*4882a593Smuzhiyun
960*4882a593Smuzhiyun if (!mac_buf) {
961*4882a593Smuzhiyun status = ICE_ERR_NO_MEMORY;
962*4882a593Smuzhiyun goto err_unroll_fltr_mgmt_struct;
963*4882a593Smuzhiyun }
964*4882a593Smuzhiyun
965*4882a593Smuzhiyun status = ice_aq_manage_mac_read(hw, mac_buf, mac_buf_len, NULL);
966*4882a593Smuzhiyun devm_kfree(ice_hw_to_dev(hw), mac_buf);
967*4882a593Smuzhiyun
968*4882a593Smuzhiyun if (status)
969*4882a593Smuzhiyun goto err_unroll_fltr_mgmt_struct;
970*4882a593Smuzhiyun /* enable jumbo frame support at MAC level */
971*4882a593Smuzhiyun status = ice_aq_set_mac_cfg(hw, ICE_AQ_SET_MAC_FRAME_SIZE_MAX, NULL);
972*4882a593Smuzhiyun if (status)
973*4882a593Smuzhiyun goto err_unroll_fltr_mgmt_struct;
974*4882a593Smuzhiyun /* Obtain counter base index which would be used by flow director */
975*4882a593Smuzhiyun status = ice_alloc_fd_res_cntr(hw, &hw->fd_ctr_base);
976*4882a593Smuzhiyun if (status)
977*4882a593Smuzhiyun goto err_unroll_fltr_mgmt_struct;
978*4882a593Smuzhiyun status = ice_init_hw_tbls(hw);
979*4882a593Smuzhiyun if (status)
980*4882a593Smuzhiyun goto err_unroll_fltr_mgmt_struct;
981*4882a593Smuzhiyun mutex_init(&hw->tnl_lock);
982*4882a593Smuzhiyun return 0;
983*4882a593Smuzhiyun
984*4882a593Smuzhiyun err_unroll_fltr_mgmt_struct:
985*4882a593Smuzhiyun ice_cleanup_fltr_mgmt_struct(hw);
986*4882a593Smuzhiyun err_unroll_sched:
987*4882a593Smuzhiyun ice_sched_cleanup_all(hw);
988*4882a593Smuzhiyun err_unroll_alloc:
989*4882a593Smuzhiyun devm_kfree(ice_hw_to_dev(hw), hw->port_info);
990*4882a593Smuzhiyun err_unroll_cqinit:
991*4882a593Smuzhiyun ice_destroy_all_ctrlq(hw);
992*4882a593Smuzhiyun return status;
993*4882a593Smuzhiyun }
994*4882a593Smuzhiyun
995*4882a593Smuzhiyun /**
996*4882a593Smuzhiyun * ice_deinit_hw - unroll initialization operations done by ice_init_hw
997*4882a593Smuzhiyun * @hw: pointer to the hardware structure
998*4882a593Smuzhiyun *
999*4882a593Smuzhiyun * This should be called only during nominal operation, not as a result of
1000*4882a593Smuzhiyun * ice_init_hw() failing since ice_init_hw() will take care of unrolling
1001*4882a593Smuzhiyun * applicable initializations if it fails for any reason.
1002*4882a593Smuzhiyun */
ice_deinit_hw(struct ice_hw * hw)1003*4882a593Smuzhiyun void ice_deinit_hw(struct ice_hw *hw)
1004*4882a593Smuzhiyun {
1005*4882a593Smuzhiyun ice_free_fd_res_cntr(hw, hw->fd_ctr_base);
1006*4882a593Smuzhiyun ice_cleanup_fltr_mgmt_struct(hw);
1007*4882a593Smuzhiyun
1008*4882a593Smuzhiyun ice_sched_cleanup_all(hw);
1009*4882a593Smuzhiyun ice_sched_clear_agg(hw);
1010*4882a593Smuzhiyun ice_free_seg(hw);
1011*4882a593Smuzhiyun ice_free_hw_tbls(hw);
1012*4882a593Smuzhiyun mutex_destroy(&hw->tnl_lock);
1013*4882a593Smuzhiyun
1014*4882a593Smuzhiyun if (hw->port_info) {
1015*4882a593Smuzhiyun devm_kfree(ice_hw_to_dev(hw), hw->port_info);
1016*4882a593Smuzhiyun hw->port_info = NULL;
1017*4882a593Smuzhiyun }
1018*4882a593Smuzhiyun
1019*4882a593Smuzhiyun /* Attempt to disable FW logging before shutting down control queues */
1020*4882a593Smuzhiyun ice_cfg_fw_log(hw, false);
1021*4882a593Smuzhiyun ice_destroy_all_ctrlq(hw);
1022*4882a593Smuzhiyun
1023*4882a593Smuzhiyun /* Clear VSI contexts if not already cleared */
1024*4882a593Smuzhiyun ice_clear_all_vsi_ctx(hw);
1025*4882a593Smuzhiyun }
1026*4882a593Smuzhiyun
1027*4882a593Smuzhiyun /**
1028*4882a593Smuzhiyun * ice_check_reset - Check to see if a global reset is complete
1029*4882a593Smuzhiyun * @hw: pointer to the hardware structure
1030*4882a593Smuzhiyun */
ice_check_reset(struct ice_hw * hw)1031*4882a593Smuzhiyun enum ice_status ice_check_reset(struct ice_hw *hw)
1032*4882a593Smuzhiyun {
1033*4882a593Smuzhiyun u32 cnt, reg = 0, grst_timeout, uld_mask;
1034*4882a593Smuzhiyun
1035*4882a593Smuzhiyun /* Poll for Device Active state in case a recent CORER, GLOBR,
1036*4882a593Smuzhiyun * or EMPR has occurred. The grst delay value is in 100ms units.
1037*4882a593Smuzhiyun * Add 1sec for outstanding AQ commands that can take a long time.
1038*4882a593Smuzhiyun */
1039*4882a593Smuzhiyun grst_timeout = ((rd32(hw, GLGEN_RSTCTL) & GLGEN_RSTCTL_GRSTDEL_M) >>
1040*4882a593Smuzhiyun GLGEN_RSTCTL_GRSTDEL_S) + 10;
1041*4882a593Smuzhiyun
1042*4882a593Smuzhiyun for (cnt = 0; cnt < grst_timeout; cnt++) {
1043*4882a593Smuzhiyun mdelay(100);
1044*4882a593Smuzhiyun reg = rd32(hw, GLGEN_RSTAT);
1045*4882a593Smuzhiyun if (!(reg & GLGEN_RSTAT_DEVSTATE_M))
1046*4882a593Smuzhiyun break;
1047*4882a593Smuzhiyun }
1048*4882a593Smuzhiyun
1049*4882a593Smuzhiyun if (cnt == grst_timeout) {
1050*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
1051*4882a593Smuzhiyun "Global reset polling failed to complete.\n");
1052*4882a593Smuzhiyun return ICE_ERR_RESET_FAILED;
1053*4882a593Smuzhiyun }
1054*4882a593Smuzhiyun
1055*4882a593Smuzhiyun #define ICE_RESET_DONE_MASK (GLNVM_ULD_PCIER_DONE_M |\
1056*4882a593Smuzhiyun GLNVM_ULD_PCIER_DONE_1_M |\
1057*4882a593Smuzhiyun GLNVM_ULD_CORER_DONE_M |\
1058*4882a593Smuzhiyun GLNVM_ULD_GLOBR_DONE_M |\
1059*4882a593Smuzhiyun GLNVM_ULD_POR_DONE_M |\
1060*4882a593Smuzhiyun GLNVM_ULD_POR_DONE_1_M |\
1061*4882a593Smuzhiyun GLNVM_ULD_PCIER_DONE_2_M)
1062*4882a593Smuzhiyun
1063*4882a593Smuzhiyun uld_mask = ICE_RESET_DONE_MASK;
1064*4882a593Smuzhiyun
1065*4882a593Smuzhiyun /* Device is Active; check Global Reset processes are done */
1066*4882a593Smuzhiyun for (cnt = 0; cnt < ICE_PF_RESET_WAIT_COUNT; cnt++) {
1067*4882a593Smuzhiyun reg = rd32(hw, GLNVM_ULD) & uld_mask;
1068*4882a593Smuzhiyun if (reg == uld_mask) {
1069*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
1070*4882a593Smuzhiyun "Global reset processes done. %d\n", cnt);
1071*4882a593Smuzhiyun break;
1072*4882a593Smuzhiyun }
1073*4882a593Smuzhiyun mdelay(10);
1074*4882a593Smuzhiyun }
1075*4882a593Smuzhiyun
1076*4882a593Smuzhiyun if (cnt == ICE_PF_RESET_WAIT_COUNT) {
1077*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
1078*4882a593Smuzhiyun "Wait for Reset Done timed out. GLNVM_ULD = 0x%x\n",
1079*4882a593Smuzhiyun reg);
1080*4882a593Smuzhiyun return ICE_ERR_RESET_FAILED;
1081*4882a593Smuzhiyun }
1082*4882a593Smuzhiyun
1083*4882a593Smuzhiyun return 0;
1084*4882a593Smuzhiyun }
1085*4882a593Smuzhiyun
1086*4882a593Smuzhiyun /**
1087*4882a593Smuzhiyun * ice_pf_reset - Reset the PF
1088*4882a593Smuzhiyun * @hw: pointer to the hardware structure
1089*4882a593Smuzhiyun *
1090*4882a593Smuzhiyun * If a global reset has been triggered, this function checks
1091*4882a593Smuzhiyun * for its completion and then issues the PF reset
1092*4882a593Smuzhiyun */
ice_pf_reset(struct ice_hw * hw)1093*4882a593Smuzhiyun static enum ice_status ice_pf_reset(struct ice_hw *hw)
1094*4882a593Smuzhiyun {
1095*4882a593Smuzhiyun u32 cnt, reg;
1096*4882a593Smuzhiyun
1097*4882a593Smuzhiyun /* If at function entry a global reset was already in progress, i.e.
1098*4882a593Smuzhiyun * state is not 'device active' or any of the reset done bits are not
1099*4882a593Smuzhiyun * set in GLNVM_ULD, there is no need for a PF Reset; poll until the
1100*4882a593Smuzhiyun * global reset is done.
1101*4882a593Smuzhiyun */
1102*4882a593Smuzhiyun if ((rd32(hw, GLGEN_RSTAT) & GLGEN_RSTAT_DEVSTATE_M) ||
1103*4882a593Smuzhiyun (rd32(hw, GLNVM_ULD) & ICE_RESET_DONE_MASK) ^ ICE_RESET_DONE_MASK) {
1104*4882a593Smuzhiyun /* poll on global reset currently in progress until done */
1105*4882a593Smuzhiyun if (ice_check_reset(hw))
1106*4882a593Smuzhiyun return ICE_ERR_RESET_FAILED;
1107*4882a593Smuzhiyun
1108*4882a593Smuzhiyun return 0;
1109*4882a593Smuzhiyun }
1110*4882a593Smuzhiyun
1111*4882a593Smuzhiyun /* Reset the PF */
1112*4882a593Smuzhiyun reg = rd32(hw, PFGEN_CTRL);
1113*4882a593Smuzhiyun
1114*4882a593Smuzhiyun wr32(hw, PFGEN_CTRL, (reg | PFGEN_CTRL_PFSWR_M));
1115*4882a593Smuzhiyun
1116*4882a593Smuzhiyun /* Wait for the PFR to complete. The wait time is the global config lock
1117*4882a593Smuzhiyun * timeout plus the PFR timeout which will account for a possible reset
1118*4882a593Smuzhiyun * that is occurring during a download package operation.
1119*4882a593Smuzhiyun */
1120*4882a593Smuzhiyun for (cnt = 0; cnt < ICE_GLOBAL_CFG_LOCK_TIMEOUT +
1121*4882a593Smuzhiyun ICE_PF_RESET_WAIT_COUNT; cnt++) {
1122*4882a593Smuzhiyun reg = rd32(hw, PFGEN_CTRL);
1123*4882a593Smuzhiyun if (!(reg & PFGEN_CTRL_PFSWR_M))
1124*4882a593Smuzhiyun break;
1125*4882a593Smuzhiyun
1126*4882a593Smuzhiyun mdelay(1);
1127*4882a593Smuzhiyun }
1128*4882a593Smuzhiyun
1129*4882a593Smuzhiyun if (cnt == ICE_PF_RESET_WAIT_COUNT) {
1130*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
1131*4882a593Smuzhiyun "PF reset polling failed to complete.\n");
1132*4882a593Smuzhiyun return ICE_ERR_RESET_FAILED;
1133*4882a593Smuzhiyun }
1134*4882a593Smuzhiyun
1135*4882a593Smuzhiyun return 0;
1136*4882a593Smuzhiyun }
1137*4882a593Smuzhiyun
1138*4882a593Smuzhiyun /**
1139*4882a593Smuzhiyun * ice_reset - Perform different types of reset
1140*4882a593Smuzhiyun * @hw: pointer to the hardware structure
1141*4882a593Smuzhiyun * @req: reset request
1142*4882a593Smuzhiyun *
1143*4882a593Smuzhiyun * This function triggers a reset as specified by the req parameter.
1144*4882a593Smuzhiyun *
1145*4882a593Smuzhiyun * Note:
1146*4882a593Smuzhiyun * If anything other than a PF reset is triggered, PXE mode is restored.
1147*4882a593Smuzhiyun * This has to be cleared using ice_clear_pxe_mode again, once the AQ
1148*4882a593Smuzhiyun * interface has been restored in the rebuild flow.
1149*4882a593Smuzhiyun */
ice_reset(struct ice_hw * hw,enum ice_reset_req req)1150*4882a593Smuzhiyun enum ice_status ice_reset(struct ice_hw *hw, enum ice_reset_req req)
1151*4882a593Smuzhiyun {
1152*4882a593Smuzhiyun u32 val = 0;
1153*4882a593Smuzhiyun
1154*4882a593Smuzhiyun switch (req) {
1155*4882a593Smuzhiyun case ICE_RESET_PFR:
1156*4882a593Smuzhiyun return ice_pf_reset(hw);
1157*4882a593Smuzhiyun case ICE_RESET_CORER:
1158*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT, "CoreR requested\n");
1159*4882a593Smuzhiyun val = GLGEN_RTRIG_CORER_M;
1160*4882a593Smuzhiyun break;
1161*4882a593Smuzhiyun case ICE_RESET_GLOBR:
1162*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT, "GlobalR requested\n");
1163*4882a593Smuzhiyun val = GLGEN_RTRIG_GLOBR_M;
1164*4882a593Smuzhiyun break;
1165*4882a593Smuzhiyun default:
1166*4882a593Smuzhiyun return ICE_ERR_PARAM;
1167*4882a593Smuzhiyun }
1168*4882a593Smuzhiyun
1169*4882a593Smuzhiyun val |= rd32(hw, GLGEN_RTRIG);
1170*4882a593Smuzhiyun wr32(hw, GLGEN_RTRIG, val);
1171*4882a593Smuzhiyun ice_flush(hw);
1172*4882a593Smuzhiyun
1173*4882a593Smuzhiyun /* wait for the FW to be ready */
1174*4882a593Smuzhiyun return ice_check_reset(hw);
1175*4882a593Smuzhiyun }
1176*4882a593Smuzhiyun
1177*4882a593Smuzhiyun /**
1178*4882a593Smuzhiyun * ice_copy_rxq_ctx_to_hw
1179*4882a593Smuzhiyun * @hw: pointer to the hardware structure
1180*4882a593Smuzhiyun * @ice_rxq_ctx: pointer to the rxq context
1181*4882a593Smuzhiyun * @rxq_index: the index of the Rx queue
1182*4882a593Smuzhiyun *
1183*4882a593Smuzhiyun * Copies rxq context from dense structure to HW register space
1184*4882a593Smuzhiyun */
1185*4882a593Smuzhiyun static enum ice_status
ice_copy_rxq_ctx_to_hw(struct ice_hw * hw,u8 * ice_rxq_ctx,u32 rxq_index)1186*4882a593Smuzhiyun ice_copy_rxq_ctx_to_hw(struct ice_hw *hw, u8 *ice_rxq_ctx, u32 rxq_index)
1187*4882a593Smuzhiyun {
1188*4882a593Smuzhiyun u8 i;
1189*4882a593Smuzhiyun
1190*4882a593Smuzhiyun if (!ice_rxq_ctx)
1191*4882a593Smuzhiyun return ICE_ERR_BAD_PTR;
1192*4882a593Smuzhiyun
1193*4882a593Smuzhiyun if (rxq_index > QRX_CTRL_MAX_INDEX)
1194*4882a593Smuzhiyun return ICE_ERR_PARAM;
1195*4882a593Smuzhiyun
1196*4882a593Smuzhiyun /* Copy each dword separately to HW */
1197*4882a593Smuzhiyun for (i = 0; i < ICE_RXQ_CTX_SIZE_DWORDS; i++) {
1198*4882a593Smuzhiyun wr32(hw, QRX_CONTEXT(i, rxq_index),
1199*4882a593Smuzhiyun *((u32 *)(ice_rxq_ctx + (i * sizeof(u32)))));
1200*4882a593Smuzhiyun
1201*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_QCTX, "qrxdata[%d]: %08X\n", i,
1202*4882a593Smuzhiyun *((u32 *)(ice_rxq_ctx + (i * sizeof(u32)))));
1203*4882a593Smuzhiyun }
1204*4882a593Smuzhiyun
1205*4882a593Smuzhiyun return 0;
1206*4882a593Smuzhiyun }
1207*4882a593Smuzhiyun
1208*4882a593Smuzhiyun /* LAN Rx Queue Context */
1209*4882a593Smuzhiyun static const struct ice_ctx_ele ice_rlan_ctx_info[] = {
1210*4882a593Smuzhiyun /* Field Width LSB */
1211*4882a593Smuzhiyun ICE_CTX_STORE(ice_rlan_ctx, head, 13, 0),
1212*4882a593Smuzhiyun ICE_CTX_STORE(ice_rlan_ctx, cpuid, 8, 13),
1213*4882a593Smuzhiyun ICE_CTX_STORE(ice_rlan_ctx, base, 57, 32),
1214*4882a593Smuzhiyun ICE_CTX_STORE(ice_rlan_ctx, qlen, 13, 89),
1215*4882a593Smuzhiyun ICE_CTX_STORE(ice_rlan_ctx, dbuf, 7, 102),
1216*4882a593Smuzhiyun ICE_CTX_STORE(ice_rlan_ctx, hbuf, 5, 109),
1217*4882a593Smuzhiyun ICE_CTX_STORE(ice_rlan_ctx, dtype, 2, 114),
1218*4882a593Smuzhiyun ICE_CTX_STORE(ice_rlan_ctx, dsize, 1, 116),
1219*4882a593Smuzhiyun ICE_CTX_STORE(ice_rlan_ctx, crcstrip, 1, 117),
1220*4882a593Smuzhiyun ICE_CTX_STORE(ice_rlan_ctx, l2tsel, 1, 119),
1221*4882a593Smuzhiyun ICE_CTX_STORE(ice_rlan_ctx, hsplit_0, 4, 120),
1222*4882a593Smuzhiyun ICE_CTX_STORE(ice_rlan_ctx, hsplit_1, 2, 124),
1223*4882a593Smuzhiyun ICE_CTX_STORE(ice_rlan_ctx, showiv, 1, 127),
1224*4882a593Smuzhiyun ICE_CTX_STORE(ice_rlan_ctx, rxmax, 14, 174),
1225*4882a593Smuzhiyun ICE_CTX_STORE(ice_rlan_ctx, tphrdesc_ena, 1, 193),
1226*4882a593Smuzhiyun ICE_CTX_STORE(ice_rlan_ctx, tphwdesc_ena, 1, 194),
1227*4882a593Smuzhiyun ICE_CTX_STORE(ice_rlan_ctx, tphdata_ena, 1, 195),
1228*4882a593Smuzhiyun ICE_CTX_STORE(ice_rlan_ctx, tphhead_ena, 1, 196),
1229*4882a593Smuzhiyun ICE_CTX_STORE(ice_rlan_ctx, lrxqthresh, 3, 198),
1230*4882a593Smuzhiyun ICE_CTX_STORE(ice_rlan_ctx, prefena, 1, 201),
1231*4882a593Smuzhiyun { 0 }
1232*4882a593Smuzhiyun };
1233*4882a593Smuzhiyun
1234*4882a593Smuzhiyun /**
1235*4882a593Smuzhiyun * ice_write_rxq_ctx
1236*4882a593Smuzhiyun * @hw: pointer to the hardware structure
1237*4882a593Smuzhiyun * @rlan_ctx: pointer to the rxq context
1238*4882a593Smuzhiyun * @rxq_index: the index of the Rx queue
1239*4882a593Smuzhiyun *
1240*4882a593Smuzhiyun * Converts rxq context from sparse to dense structure and then writes
1241*4882a593Smuzhiyun * it to HW register space and enables the hardware to prefetch descriptors
1242*4882a593Smuzhiyun * instead of only fetching them on demand
1243*4882a593Smuzhiyun */
1244*4882a593Smuzhiyun enum ice_status
ice_write_rxq_ctx(struct ice_hw * hw,struct ice_rlan_ctx * rlan_ctx,u32 rxq_index)1245*4882a593Smuzhiyun ice_write_rxq_ctx(struct ice_hw *hw, struct ice_rlan_ctx *rlan_ctx,
1246*4882a593Smuzhiyun u32 rxq_index)
1247*4882a593Smuzhiyun {
1248*4882a593Smuzhiyun u8 ctx_buf[ICE_RXQ_CTX_SZ] = { 0 };
1249*4882a593Smuzhiyun
1250*4882a593Smuzhiyun if (!rlan_ctx)
1251*4882a593Smuzhiyun return ICE_ERR_BAD_PTR;
1252*4882a593Smuzhiyun
1253*4882a593Smuzhiyun rlan_ctx->prefena = 1;
1254*4882a593Smuzhiyun
1255*4882a593Smuzhiyun ice_set_ctx(hw, (u8 *)rlan_ctx, ctx_buf, ice_rlan_ctx_info);
1256*4882a593Smuzhiyun return ice_copy_rxq_ctx_to_hw(hw, ctx_buf, rxq_index);
1257*4882a593Smuzhiyun }
1258*4882a593Smuzhiyun
1259*4882a593Smuzhiyun /* LAN Tx Queue Context */
1260*4882a593Smuzhiyun const struct ice_ctx_ele ice_tlan_ctx_info[] = {
1261*4882a593Smuzhiyun /* Field Width LSB */
1262*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, base, 57, 0),
1263*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, port_num, 3, 57),
1264*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, cgd_num, 5, 60),
1265*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, pf_num, 3, 65),
1266*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, vmvf_num, 10, 68),
1267*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, vmvf_type, 2, 78),
1268*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, src_vsi, 10, 80),
1269*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, tsyn_ena, 1, 90),
1270*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, internal_usage_flag, 1, 91),
1271*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, alt_vlan, 1, 92),
1272*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, cpuid, 8, 93),
1273*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, wb_mode, 1, 101),
1274*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, tphrd_desc, 1, 102),
1275*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, tphrd, 1, 103),
1276*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, tphwr_desc, 1, 104),
1277*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, cmpq_id, 9, 105),
1278*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, qnum_in_func, 14, 114),
1279*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, itr_notification_mode, 1, 128),
1280*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, adjust_prof_id, 6, 129),
1281*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, qlen, 13, 135),
1282*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, quanta_prof_idx, 4, 148),
1283*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, tso_ena, 1, 152),
1284*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, tso_qnum, 11, 153),
1285*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, legacy_int, 1, 164),
1286*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, drop_ena, 1, 165),
1287*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, cache_prof_idx, 2, 166),
1288*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, pkt_shaper_prof_idx, 3, 168),
1289*4882a593Smuzhiyun ICE_CTX_STORE(ice_tlan_ctx, int_q_state, 122, 171),
1290*4882a593Smuzhiyun { 0 }
1291*4882a593Smuzhiyun };
1292*4882a593Smuzhiyun
1293*4882a593Smuzhiyun /* FW Admin Queue command wrappers */
1294*4882a593Smuzhiyun
1295*4882a593Smuzhiyun /* Software lock/mutex that is meant to be held while the Global Config Lock
1296*4882a593Smuzhiyun * in firmware is acquired by the software to prevent most (but not all) types
1297*4882a593Smuzhiyun * of AQ commands from being sent to FW
1298*4882a593Smuzhiyun */
1299*4882a593Smuzhiyun DEFINE_MUTEX(ice_global_cfg_lock_sw);
1300*4882a593Smuzhiyun
1301*4882a593Smuzhiyun /**
1302*4882a593Smuzhiyun * ice_aq_send_cmd - send FW Admin Queue command to FW Admin Queue
1303*4882a593Smuzhiyun * @hw: pointer to the HW struct
1304*4882a593Smuzhiyun * @desc: descriptor describing the command
1305*4882a593Smuzhiyun * @buf: buffer to use for indirect commands (NULL for direct commands)
1306*4882a593Smuzhiyun * @buf_size: size of buffer for indirect commands (0 for direct commands)
1307*4882a593Smuzhiyun * @cd: pointer to command details structure
1308*4882a593Smuzhiyun *
1309*4882a593Smuzhiyun * Helper function to send FW Admin Queue commands to the FW Admin Queue.
1310*4882a593Smuzhiyun */
1311*4882a593Smuzhiyun enum ice_status
ice_aq_send_cmd(struct ice_hw * hw,struct ice_aq_desc * desc,void * buf,u16 buf_size,struct ice_sq_cd * cd)1312*4882a593Smuzhiyun ice_aq_send_cmd(struct ice_hw *hw, struct ice_aq_desc *desc, void *buf,
1313*4882a593Smuzhiyun u16 buf_size, struct ice_sq_cd *cd)
1314*4882a593Smuzhiyun {
1315*4882a593Smuzhiyun struct ice_aqc_req_res *cmd = &desc->params.res_owner;
1316*4882a593Smuzhiyun bool lock_acquired = false;
1317*4882a593Smuzhiyun enum ice_status status;
1318*4882a593Smuzhiyun
1319*4882a593Smuzhiyun /* When a package download is in process (i.e. when the firmware's
1320*4882a593Smuzhiyun * Global Configuration Lock resource is held), only the Download
1321*4882a593Smuzhiyun * Package, Get Version, Get Package Info List and Release Resource
1322*4882a593Smuzhiyun * (with resource ID set to Global Config Lock) AdminQ commands are
1323*4882a593Smuzhiyun * allowed; all others must block until the package download completes
1324*4882a593Smuzhiyun * and the Global Config Lock is released. See also
1325*4882a593Smuzhiyun * ice_acquire_global_cfg_lock().
1326*4882a593Smuzhiyun */
1327*4882a593Smuzhiyun switch (le16_to_cpu(desc->opcode)) {
1328*4882a593Smuzhiyun case ice_aqc_opc_download_pkg:
1329*4882a593Smuzhiyun case ice_aqc_opc_get_pkg_info_list:
1330*4882a593Smuzhiyun case ice_aqc_opc_get_ver:
1331*4882a593Smuzhiyun break;
1332*4882a593Smuzhiyun case ice_aqc_opc_release_res:
1333*4882a593Smuzhiyun if (le16_to_cpu(cmd->res_id) == ICE_AQC_RES_ID_GLBL_LOCK)
1334*4882a593Smuzhiyun break;
1335*4882a593Smuzhiyun fallthrough;
1336*4882a593Smuzhiyun default:
1337*4882a593Smuzhiyun mutex_lock(&ice_global_cfg_lock_sw);
1338*4882a593Smuzhiyun lock_acquired = true;
1339*4882a593Smuzhiyun break;
1340*4882a593Smuzhiyun }
1341*4882a593Smuzhiyun
1342*4882a593Smuzhiyun status = ice_sq_send_cmd(hw, &hw->adminq, desc, buf, buf_size, cd);
1343*4882a593Smuzhiyun if (lock_acquired)
1344*4882a593Smuzhiyun mutex_unlock(&ice_global_cfg_lock_sw);
1345*4882a593Smuzhiyun
1346*4882a593Smuzhiyun return status;
1347*4882a593Smuzhiyun }
1348*4882a593Smuzhiyun
1349*4882a593Smuzhiyun /**
1350*4882a593Smuzhiyun * ice_aq_get_fw_ver
1351*4882a593Smuzhiyun * @hw: pointer to the HW struct
1352*4882a593Smuzhiyun * @cd: pointer to command details structure or NULL
1353*4882a593Smuzhiyun *
1354*4882a593Smuzhiyun * Get the firmware version (0x0001) from the admin queue commands
1355*4882a593Smuzhiyun */
ice_aq_get_fw_ver(struct ice_hw * hw,struct ice_sq_cd * cd)1356*4882a593Smuzhiyun enum ice_status ice_aq_get_fw_ver(struct ice_hw *hw, struct ice_sq_cd *cd)
1357*4882a593Smuzhiyun {
1358*4882a593Smuzhiyun struct ice_aqc_get_ver *resp;
1359*4882a593Smuzhiyun struct ice_aq_desc desc;
1360*4882a593Smuzhiyun enum ice_status status;
1361*4882a593Smuzhiyun
1362*4882a593Smuzhiyun resp = &desc.params.get_ver;
1363*4882a593Smuzhiyun
1364*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_ver);
1365*4882a593Smuzhiyun
1366*4882a593Smuzhiyun status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
1367*4882a593Smuzhiyun
1368*4882a593Smuzhiyun if (!status) {
1369*4882a593Smuzhiyun hw->fw_branch = resp->fw_branch;
1370*4882a593Smuzhiyun hw->fw_maj_ver = resp->fw_major;
1371*4882a593Smuzhiyun hw->fw_min_ver = resp->fw_minor;
1372*4882a593Smuzhiyun hw->fw_patch = resp->fw_patch;
1373*4882a593Smuzhiyun hw->fw_build = le32_to_cpu(resp->fw_build);
1374*4882a593Smuzhiyun hw->api_branch = resp->api_branch;
1375*4882a593Smuzhiyun hw->api_maj_ver = resp->api_major;
1376*4882a593Smuzhiyun hw->api_min_ver = resp->api_minor;
1377*4882a593Smuzhiyun hw->api_patch = resp->api_patch;
1378*4882a593Smuzhiyun }
1379*4882a593Smuzhiyun
1380*4882a593Smuzhiyun return status;
1381*4882a593Smuzhiyun }
1382*4882a593Smuzhiyun
1383*4882a593Smuzhiyun /**
1384*4882a593Smuzhiyun * ice_aq_send_driver_ver
1385*4882a593Smuzhiyun * @hw: pointer to the HW struct
1386*4882a593Smuzhiyun * @dv: driver's major, minor version
1387*4882a593Smuzhiyun * @cd: pointer to command details structure or NULL
1388*4882a593Smuzhiyun *
1389*4882a593Smuzhiyun * Send the driver version (0x0002) to the firmware
1390*4882a593Smuzhiyun */
1391*4882a593Smuzhiyun enum ice_status
ice_aq_send_driver_ver(struct ice_hw * hw,struct ice_driver_ver * dv,struct ice_sq_cd * cd)1392*4882a593Smuzhiyun ice_aq_send_driver_ver(struct ice_hw *hw, struct ice_driver_ver *dv,
1393*4882a593Smuzhiyun struct ice_sq_cd *cd)
1394*4882a593Smuzhiyun {
1395*4882a593Smuzhiyun struct ice_aqc_driver_ver *cmd;
1396*4882a593Smuzhiyun struct ice_aq_desc desc;
1397*4882a593Smuzhiyun u16 len;
1398*4882a593Smuzhiyun
1399*4882a593Smuzhiyun cmd = &desc.params.driver_ver;
1400*4882a593Smuzhiyun
1401*4882a593Smuzhiyun if (!dv)
1402*4882a593Smuzhiyun return ICE_ERR_PARAM;
1403*4882a593Smuzhiyun
1404*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_driver_ver);
1405*4882a593Smuzhiyun
1406*4882a593Smuzhiyun desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
1407*4882a593Smuzhiyun cmd->major_ver = dv->major_ver;
1408*4882a593Smuzhiyun cmd->minor_ver = dv->minor_ver;
1409*4882a593Smuzhiyun cmd->build_ver = dv->build_ver;
1410*4882a593Smuzhiyun cmd->subbuild_ver = dv->subbuild_ver;
1411*4882a593Smuzhiyun
1412*4882a593Smuzhiyun len = 0;
1413*4882a593Smuzhiyun while (len < sizeof(dv->driver_string) &&
1414*4882a593Smuzhiyun isascii(dv->driver_string[len]) && dv->driver_string[len])
1415*4882a593Smuzhiyun len++;
1416*4882a593Smuzhiyun
1417*4882a593Smuzhiyun return ice_aq_send_cmd(hw, &desc, dv->driver_string, len, cd);
1418*4882a593Smuzhiyun }
1419*4882a593Smuzhiyun
1420*4882a593Smuzhiyun /**
1421*4882a593Smuzhiyun * ice_aq_q_shutdown
1422*4882a593Smuzhiyun * @hw: pointer to the HW struct
1423*4882a593Smuzhiyun * @unloading: is the driver unloading itself
1424*4882a593Smuzhiyun *
1425*4882a593Smuzhiyun * Tell the Firmware that we're shutting down the AdminQ and whether
1426*4882a593Smuzhiyun * or not the driver is unloading as well (0x0003).
1427*4882a593Smuzhiyun */
ice_aq_q_shutdown(struct ice_hw * hw,bool unloading)1428*4882a593Smuzhiyun enum ice_status ice_aq_q_shutdown(struct ice_hw *hw, bool unloading)
1429*4882a593Smuzhiyun {
1430*4882a593Smuzhiyun struct ice_aqc_q_shutdown *cmd;
1431*4882a593Smuzhiyun struct ice_aq_desc desc;
1432*4882a593Smuzhiyun
1433*4882a593Smuzhiyun cmd = &desc.params.q_shutdown;
1434*4882a593Smuzhiyun
1435*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_q_shutdown);
1436*4882a593Smuzhiyun
1437*4882a593Smuzhiyun if (unloading)
1438*4882a593Smuzhiyun cmd->driver_unloading = ICE_AQC_DRIVER_UNLOADING;
1439*4882a593Smuzhiyun
1440*4882a593Smuzhiyun return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
1441*4882a593Smuzhiyun }
1442*4882a593Smuzhiyun
1443*4882a593Smuzhiyun /**
1444*4882a593Smuzhiyun * ice_aq_req_res
1445*4882a593Smuzhiyun * @hw: pointer to the HW struct
1446*4882a593Smuzhiyun * @res: resource ID
1447*4882a593Smuzhiyun * @access: access type
1448*4882a593Smuzhiyun * @sdp_number: resource number
1449*4882a593Smuzhiyun * @timeout: the maximum time in ms that the driver may hold the resource
1450*4882a593Smuzhiyun * @cd: pointer to command details structure or NULL
1451*4882a593Smuzhiyun *
1452*4882a593Smuzhiyun * Requests common resource using the admin queue commands (0x0008).
1453*4882a593Smuzhiyun * When attempting to acquire the Global Config Lock, the driver can
1454*4882a593Smuzhiyun * learn of three states:
1455*4882a593Smuzhiyun * 1) ICE_SUCCESS - acquired lock, and can perform download package
1456*4882a593Smuzhiyun * 2) ICE_ERR_AQ_ERROR - did not get lock, driver should fail to load
1457*4882a593Smuzhiyun * 3) ICE_ERR_AQ_NO_WORK - did not get lock, but another driver has
1458*4882a593Smuzhiyun * successfully downloaded the package; the driver does
1459*4882a593Smuzhiyun * not have to download the package and can continue
1460*4882a593Smuzhiyun * loading
1461*4882a593Smuzhiyun *
1462*4882a593Smuzhiyun * Note that if the caller is in an acquire lock, perform action, release lock
1463*4882a593Smuzhiyun * phase of operation, it is possible that the FW may detect a timeout and issue
1464*4882a593Smuzhiyun * a CORER. In this case, the driver will receive a CORER interrupt and will
1465*4882a593Smuzhiyun * have to determine its cause. The calling thread that is handling this flow
1466*4882a593Smuzhiyun * will likely get an error propagated back to it indicating the Download
1467*4882a593Smuzhiyun * Package, Update Package or the Release Resource AQ commands timed out.
1468*4882a593Smuzhiyun */
1469*4882a593Smuzhiyun static enum ice_status
ice_aq_req_res(struct ice_hw * hw,enum ice_aq_res_ids res,enum ice_aq_res_access_type access,u8 sdp_number,u32 * timeout,struct ice_sq_cd * cd)1470*4882a593Smuzhiyun ice_aq_req_res(struct ice_hw *hw, enum ice_aq_res_ids res,
1471*4882a593Smuzhiyun enum ice_aq_res_access_type access, u8 sdp_number, u32 *timeout,
1472*4882a593Smuzhiyun struct ice_sq_cd *cd)
1473*4882a593Smuzhiyun {
1474*4882a593Smuzhiyun struct ice_aqc_req_res *cmd_resp;
1475*4882a593Smuzhiyun struct ice_aq_desc desc;
1476*4882a593Smuzhiyun enum ice_status status;
1477*4882a593Smuzhiyun
1478*4882a593Smuzhiyun cmd_resp = &desc.params.res_owner;
1479*4882a593Smuzhiyun
1480*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_req_res);
1481*4882a593Smuzhiyun
1482*4882a593Smuzhiyun cmd_resp->res_id = cpu_to_le16(res);
1483*4882a593Smuzhiyun cmd_resp->access_type = cpu_to_le16(access);
1484*4882a593Smuzhiyun cmd_resp->res_number = cpu_to_le32(sdp_number);
1485*4882a593Smuzhiyun cmd_resp->timeout = cpu_to_le32(*timeout);
1486*4882a593Smuzhiyun *timeout = 0;
1487*4882a593Smuzhiyun
1488*4882a593Smuzhiyun status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
1489*4882a593Smuzhiyun
1490*4882a593Smuzhiyun /* The completion specifies the maximum time in ms that the driver
1491*4882a593Smuzhiyun * may hold the resource in the Timeout field.
1492*4882a593Smuzhiyun */
1493*4882a593Smuzhiyun
1494*4882a593Smuzhiyun /* Global config lock response utilizes an additional status field.
1495*4882a593Smuzhiyun *
1496*4882a593Smuzhiyun * If the Global config lock resource is held by some other driver, the
1497*4882a593Smuzhiyun * command completes with ICE_AQ_RES_GLBL_IN_PROG in the status field
1498*4882a593Smuzhiyun * and the timeout field indicates the maximum time the current owner
1499*4882a593Smuzhiyun * of the resource has to free it.
1500*4882a593Smuzhiyun */
1501*4882a593Smuzhiyun if (res == ICE_GLOBAL_CFG_LOCK_RES_ID) {
1502*4882a593Smuzhiyun if (le16_to_cpu(cmd_resp->status) == ICE_AQ_RES_GLBL_SUCCESS) {
1503*4882a593Smuzhiyun *timeout = le32_to_cpu(cmd_resp->timeout);
1504*4882a593Smuzhiyun return 0;
1505*4882a593Smuzhiyun } else if (le16_to_cpu(cmd_resp->status) ==
1506*4882a593Smuzhiyun ICE_AQ_RES_GLBL_IN_PROG) {
1507*4882a593Smuzhiyun *timeout = le32_to_cpu(cmd_resp->timeout);
1508*4882a593Smuzhiyun return ICE_ERR_AQ_ERROR;
1509*4882a593Smuzhiyun } else if (le16_to_cpu(cmd_resp->status) ==
1510*4882a593Smuzhiyun ICE_AQ_RES_GLBL_DONE) {
1511*4882a593Smuzhiyun return ICE_ERR_AQ_NO_WORK;
1512*4882a593Smuzhiyun }
1513*4882a593Smuzhiyun
1514*4882a593Smuzhiyun /* invalid FW response, force a timeout immediately */
1515*4882a593Smuzhiyun *timeout = 0;
1516*4882a593Smuzhiyun return ICE_ERR_AQ_ERROR;
1517*4882a593Smuzhiyun }
1518*4882a593Smuzhiyun
1519*4882a593Smuzhiyun /* If the resource is held by some other driver, the command completes
1520*4882a593Smuzhiyun * with a busy return value and the timeout field indicates the maximum
1521*4882a593Smuzhiyun * time the current owner of the resource has to free it.
1522*4882a593Smuzhiyun */
1523*4882a593Smuzhiyun if (!status || hw->adminq.sq_last_status == ICE_AQ_RC_EBUSY)
1524*4882a593Smuzhiyun *timeout = le32_to_cpu(cmd_resp->timeout);
1525*4882a593Smuzhiyun
1526*4882a593Smuzhiyun return status;
1527*4882a593Smuzhiyun }
1528*4882a593Smuzhiyun
1529*4882a593Smuzhiyun /**
1530*4882a593Smuzhiyun * ice_aq_release_res
1531*4882a593Smuzhiyun * @hw: pointer to the HW struct
1532*4882a593Smuzhiyun * @res: resource ID
1533*4882a593Smuzhiyun * @sdp_number: resource number
1534*4882a593Smuzhiyun * @cd: pointer to command details structure or NULL
1535*4882a593Smuzhiyun *
1536*4882a593Smuzhiyun * release common resource using the admin queue commands (0x0009)
1537*4882a593Smuzhiyun */
1538*4882a593Smuzhiyun static enum ice_status
ice_aq_release_res(struct ice_hw * hw,enum ice_aq_res_ids res,u8 sdp_number,struct ice_sq_cd * cd)1539*4882a593Smuzhiyun ice_aq_release_res(struct ice_hw *hw, enum ice_aq_res_ids res, u8 sdp_number,
1540*4882a593Smuzhiyun struct ice_sq_cd *cd)
1541*4882a593Smuzhiyun {
1542*4882a593Smuzhiyun struct ice_aqc_req_res *cmd;
1543*4882a593Smuzhiyun struct ice_aq_desc desc;
1544*4882a593Smuzhiyun
1545*4882a593Smuzhiyun cmd = &desc.params.res_owner;
1546*4882a593Smuzhiyun
1547*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_release_res);
1548*4882a593Smuzhiyun
1549*4882a593Smuzhiyun cmd->res_id = cpu_to_le16(res);
1550*4882a593Smuzhiyun cmd->res_number = cpu_to_le32(sdp_number);
1551*4882a593Smuzhiyun
1552*4882a593Smuzhiyun return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
1553*4882a593Smuzhiyun }
1554*4882a593Smuzhiyun
1555*4882a593Smuzhiyun /**
1556*4882a593Smuzhiyun * ice_acquire_res
1557*4882a593Smuzhiyun * @hw: pointer to the HW structure
1558*4882a593Smuzhiyun * @res: resource ID
1559*4882a593Smuzhiyun * @access: access type (read or write)
1560*4882a593Smuzhiyun * @timeout: timeout in milliseconds
1561*4882a593Smuzhiyun *
1562*4882a593Smuzhiyun * This function will attempt to acquire the ownership of a resource.
1563*4882a593Smuzhiyun */
1564*4882a593Smuzhiyun enum ice_status
ice_acquire_res(struct ice_hw * hw,enum ice_aq_res_ids res,enum ice_aq_res_access_type access,u32 timeout)1565*4882a593Smuzhiyun ice_acquire_res(struct ice_hw *hw, enum ice_aq_res_ids res,
1566*4882a593Smuzhiyun enum ice_aq_res_access_type access, u32 timeout)
1567*4882a593Smuzhiyun {
1568*4882a593Smuzhiyun #define ICE_RES_POLLING_DELAY_MS 10
1569*4882a593Smuzhiyun u32 delay = ICE_RES_POLLING_DELAY_MS;
1570*4882a593Smuzhiyun u32 time_left = timeout;
1571*4882a593Smuzhiyun enum ice_status status;
1572*4882a593Smuzhiyun
1573*4882a593Smuzhiyun status = ice_aq_req_res(hw, res, access, 0, &time_left, NULL);
1574*4882a593Smuzhiyun
1575*4882a593Smuzhiyun /* A return code of ICE_ERR_AQ_NO_WORK means that another driver has
1576*4882a593Smuzhiyun * previously acquired the resource and performed any necessary updates;
1577*4882a593Smuzhiyun * in this case the caller does not obtain the resource and has no
1578*4882a593Smuzhiyun * further work to do.
1579*4882a593Smuzhiyun */
1580*4882a593Smuzhiyun if (status == ICE_ERR_AQ_NO_WORK)
1581*4882a593Smuzhiyun goto ice_acquire_res_exit;
1582*4882a593Smuzhiyun
1583*4882a593Smuzhiyun if (status)
1584*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_RES,
1585*4882a593Smuzhiyun "resource %d acquire type %d failed.\n", res, access);
1586*4882a593Smuzhiyun
1587*4882a593Smuzhiyun /* If necessary, poll until the current lock owner timeouts */
1588*4882a593Smuzhiyun timeout = time_left;
1589*4882a593Smuzhiyun while (status && timeout && time_left) {
1590*4882a593Smuzhiyun mdelay(delay);
1591*4882a593Smuzhiyun timeout = (timeout > delay) ? timeout - delay : 0;
1592*4882a593Smuzhiyun status = ice_aq_req_res(hw, res, access, 0, &time_left, NULL);
1593*4882a593Smuzhiyun
1594*4882a593Smuzhiyun if (status == ICE_ERR_AQ_NO_WORK)
1595*4882a593Smuzhiyun /* lock free, but no work to do */
1596*4882a593Smuzhiyun break;
1597*4882a593Smuzhiyun
1598*4882a593Smuzhiyun if (!status)
1599*4882a593Smuzhiyun /* lock acquired */
1600*4882a593Smuzhiyun break;
1601*4882a593Smuzhiyun }
1602*4882a593Smuzhiyun if (status && status != ICE_ERR_AQ_NO_WORK)
1603*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_RES, "resource acquire timed out.\n");
1604*4882a593Smuzhiyun
1605*4882a593Smuzhiyun ice_acquire_res_exit:
1606*4882a593Smuzhiyun if (status == ICE_ERR_AQ_NO_WORK) {
1607*4882a593Smuzhiyun if (access == ICE_RES_WRITE)
1608*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_RES,
1609*4882a593Smuzhiyun "resource indicates no work to do.\n");
1610*4882a593Smuzhiyun else
1611*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_RES,
1612*4882a593Smuzhiyun "Warning: ICE_ERR_AQ_NO_WORK not expected\n");
1613*4882a593Smuzhiyun }
1614*4882a593Smuzhiyun return status;
1615*4882a593Smuzhiyun }
1616*4882a593Smuzhiyun
1617*4882a593Smuzhiyun /**
1618*4882a593Smuzhiyun * ice_release_res
1619*4882a593Smuzhiyun * @hw: pointer to the HW structure
1620*4882a593Smuzhiyun * @res: resource ID
1621*4882a593Smuzhiyun *
1622*4882a593Smuzhiyun * This function will release a resource using the proper Admin Command.
1623*4882a593Smuzhiyun */
ice_release_res(struct ice_hw * hw,enum ice_aq_res_ids res)1624*4882a593Smuzhiyun void ice_release_res(struct ice_hw *hw, enum ice_aq_res_ids res)
1625*4882a593Smuzhiyun {
1626*4882a593Smuzhiyun enum ice_status status;
1627*4882a593Smuzhiyun u32 total_delay = 0;
1628*4882a593Smuzhiyun
1629*4882a593Smuzhiyun status = ice_aq_release_res(hw, res, 0, NULL);
1630*4882a593Smuzhiyun
1631*4882a593Smuzhiyun /* there are some rare cases when trying to release the resource
1632*4882a593Smuzhiyun * results in an admin queue timeout, so handle them correctly
1633*4882a593Smuzhiyun */
1634*4882a593Smuzhiyun while ((status == ICE_ERR_AQ_TIMEOUT) &&
1635*4882a593Smuzhiyun (total_delay < hw->adminq.sq_cmd_timeout)) {
1636*4882a593Smuzhiyun mdelay(1);
1637*4882a593Smuzhiyun status = ice_aq_release_res(hw, res, 0, NULL);
1638*4882a593Smuzhiyun total_delay++;
1639*4882a593Smuzhiyun }
1640*4882a593Smuzhiyun }
1641*4882a593Smuzhiyun
1642*4882a593Smuzhiyun /**
1643*4882a593Smuzhiyun * ice_aq_alloc_free_res - command to allocate/free resources
1644*4882a593Smuzhiyun * @hw: pointer to the HW struct
1645*4882a593Smuzhiyun * @num_entries: number of resource entries in buffer
1646*4882a593Smuzhiyun * @buf: Indirect buffer to hold data parameters and response
1647*4882a593Smuzhiyun * @buf_size: size of buffer for indirect commands
1648*4882a593Smuzhiyun * @opc: pass in the command opcode
1649*4882a593Smuzhiyun * @cd: pointer to command details structure or NULL
1650*4882a593Smuzhiyun *
1651*4882a593Smuzhiyun * Helper function to allocate/free resources using the admin queue commands
1652*4882a593Smuzhiyun */
1653*4882a593Smuzhiyun enum ice_status
ice_aq_alloc_free_res(struct ice_hw * hw,u16 num_entries,struct ice_aqc_alloc_free_res_elem * buf,u16 buf_size,enum ice_adminq_opc opc,struct ice_sq_cd * cd)1654*4882a593Smuzhiyun ice_aq_alloc_free_res(struct ice_hw *hw, u16 num_entries,
1655*4882a593Smuzhiyun struct ice_aqc_alloc_free_res_elem *buf, u16 buf_size,
1656*4882a593Smuzhiyun enum ice_adminq_opc opc, struct ice_sq_cd *cd)
1657*4882a593Smuzhiyun {
1658*4882a593Smuzhiyun struct ice_aqc_alloc_free_res_cmd *cmd;
1659*4882a593Smuzhiyun struct ice_aq_desc desc;
1660*4882a593Smuzhiyun
1661*4882a593Smuzhiyun cmd = &desc.params.sw_res_ctrl;
1662*4882a593Smuzhiyun
1663*4882a593Smuzhiyun if (!buf)
1664*4882a593Smuzhiyun return ICE_ERR_PARAM;
1665*4882a593Smuzhiyun
1666*4882a593Smuzhiyun if (buf_size < (num_entries * sizeof(buf->elem[0])))
1667*4882a593Smuzhiyun return ICE_ERR_PARAM;
1668*4882a593Smuzhiyun
1669*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, opc);
1670*4882a593Smuzhiyun
1671*4882a593Smuzhiyun desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
1672*4882a593Smuzhiyun
1673*4882a593Smuzhiyun cmd->num_entries = cpu_to_le16(num_entries);
1674*4882a593Smuzhiyun
1675*4882a593Smuzhiyun return ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
1676*4882a593Smuzhiyun }
1677*4882a593Smuzhiyun
1678*4882a593Smuzhiyun /**
1679*4882a593Smuzhiyun * ice_alloc_hw_res - allocate resource
1680*4882a593Smuzhiyun * @hw: pointer to the HW struct
1681*4882a593Smuzhiyun * @type: type of resource
1682*4882a593Smuzhiyun * @num: number of resources to allocate
1683*4882a593Smuzhiyun * @btm: allocate from bottom
1684*4882a593Smuzhiyun * @res: pointer to array that will receive the resources
1685*4882a593Smuzhiyun */
1686*4882a593Smuzhiyun enum ice_status
ice_alloc_hw_res(struct ice_hw * hw,u16 type,u16 num,bool btm,u16 * res)1687*4882a593Smuzhiyun ice_alloc_hw_res(struct ice_hw *hw, u16 type, u16 num, bool btm, u16 *res)
1688*4882a593Smuzhiyun {
1689*4882a593Smuzhiyun struct ice_aqc_alloc_free_res_elem *buf;
1690*4882a593Smuzhiyun enum ice_status status;
1691*4882a593Smuzhiyun u16 buf_len;
1692*4882a593Smuzhiyun
1693*4882a593Smuzhiyun buf_len = struct_size(buf, elem, num);
1694*4882a593Smuzhiyun buf = kzalloc(buf_len, GFP_KERNEL);
1695*4882a593Smuzhiyun if (!buf)
1696*4882a593Smuzhiyun return ICE_ERR_NO_MEMORY;
1697*4882a593Smuzhiyun
1698*4882a593Smuzhiyun /* Prepare buffer to allocate resource. */
1699*4882a593Smuzhiyun buf->num_elems = cpu_to_le16(num);
1700*4882a593Smuzhiyun buf->res_type = cpu_to_le16(type | ICE_AQC_RES_TYPE_FLAG_DEDICATED |
1701*4882a593Smuzhiyun ICE_AQC_RES_TYPE_FLAG_IGNORE_INDEX);
1702*4882a593Smuzhiyun if (btm)
1703*4882a593Smuzhiyun buf->res_type |= cpu_to_le16(ICE_AQC_RES_TYPE_FLAG_SCAN_BOTTOM);
1704*4882a593Smuzhiyun
1705*4882a593Smuzhiyun status = ice_aq_alloc_free_res(hw, 1, buf, buf_len,
1706*4882a593Smuzhiyun ice_aqc_opc_alloc_res, NULL);
1707*4882a593Smuzhiyun if (status)
1708*4882a593Smuzhiyun goto ice_alloc_res_exit;
1709*4882a593Smuzhiyun
1710*4882a593Smuzhiyun memcpy(res, buf->elem, sizeof(*buf->elem) * num);
1711*4882a593Smuzhiyun
1712*4882a593Smuzhiyun ice_alloc_res_exit:
1713*4882a593Smuzhiyun kfree(buf);
1714*4882a593Smuzhiyun return status;
1715*4882a593Smuzhiyun }
1716*4882a593Smuzhiyun
1717*4882a593Smuzhiyun /**
1718*4882a593Smuzhiyun * ice_free_hw_res - free allocated HW resource
1719*4882a593Smuzhiyun * @hw: pointer to the HW struct
1720*4882a593Smuzhiyun * @type: type of resource to free
1721*4882a593Smuzhiyun * @num: number of resources
1722*4882a593Smuzhiyun * @res: pointer to array that contains the resources to free
1723*4882a593Smuzhiyun */
ice_free_hw_res(struct ice_hw * hw,u16 type,u16 num,u16 * res)1724*4882a593Smuzhiyun enum ice_status ice_free_hw_res(struct ice_hw *hw, u16 type, u16 num, u16 *res)
1725*4882a593Smuzhiyun {
1726*4882a593Smuzhiyun struct ice_aqc_alloc_free_res_elem *buf;
1727*4882a593Smuzhiyun enum ice_status status;
1728*4882a593Smuzhiyun u16 buf_len;
1729*4882a593Smuzhiyun
1730*4882a593Smuzhiyun buf_len = struct_size(buf, elem, num);
1731*4882a593Smuzhiyun buf = kzalloc(buf_len, GFP_KERNEL);
1732*4882a593Smuzhiyun if (!buf)
1733*4882a593Smuzhiyun return ICE_ERR_NO_MEMORY;
1734*4882a593Smuzhiyun
1735*4882a593Smuzhiyun /* Prepare buffer to free resource. */
1736*4882a593Smuzhiyun buf->num_elems = cpu_to_le16(num);
1737*4882a593Smuzhiyun buf->res_type = cpu_to_le16(type);
1738*4882a593Smuzhiyun memcpy(buf->elem, res, sizeof(*buf->elem) * num);
1739*4882a593Smuzhiyun
1740*4882a593Smuzhiyun status = ice_aq_alloc_free_res(hw, num, buf, buf_len,
1741*4882a593Smuzhiyun ice_aqc_opc_free_res, NULL);
1742*4882a593Smuzhiyun if (status)
1743*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_SW, "CQ CMD Buffer:\n");
1744*4882a593Smuzhiyun
1745*4882a593Smuzhiyun kfree(buf);
1746*4882a593Smuzhiyun return status;
1747*4882a593Smuzhiyun }
1748*4882a593Smuzhiyun
1749*4882a593Smuzhiyun /**
1750*4882a593Smuzhiyun * ice_get_num_per_func - determine number of resources per PF
1751*4882a593Smuzhiyun * @hw: pointer to the HW structure
1752*4882a593Smuzhiyun * @max: value to be evenly split between each PF
1753*4882a593Smuzhiyun *
1754*4882a593Smuzhiyun * Determine the number of valid functions by going through the bitmap returned
1755*4882a593Smuzhiyun * from parsing capabilities and use this to calculate the number of resources
1756*4882a593Smuzhiyun * per PF based on the max value passed in.
1757*4882a593Smuzhiyun */
ice_get_num_per_func(struct ice_hw * hw,u32 max)1758*4882a593Smuzhiyun static u32 ice_get_num_per_func(struct ice_hw *hw, u32 max)
1759*4882a593Smuzhiyun {
1760*4882a593Smuzhiyun u8 funcs;
1761*4882a593Smuzhiyun
1762*4882a593Smuzhiyun #define ICE_CAPS_VALID_FUNCS_M 0xFF
1763*4882a593Smuzhiyun funcs = hweight8(hw->dev_caps.common_cap.valid_functions &
1764*4882a593Smuzhiyun ICE_CAPS_VALID_FUNCS_M);
1765*4882a593Smuzhiyun
1766*4882a593Smuzhiyun if (!funcs)
1767*4882a593Smuzhiyun return 0;
1768*4882a593Smuzhiyun
1769*4882a593Smuzhiyun return max / funcs;
1770*4882a593Smuzhiyun }
1771*4882a593Smuzhiyun
1772*4882a593Smuzhiyun /**
1773*4882a593Smuzhiyun * ice_parse_common_caps - parse common device/function capabilities
1774*4882a593Smuzhiyun * @hw: pointer to the HW struct
1775*4882a593Smuzhiyun * @caps: pointer to common capabilities structure
1776*4882a593Smuzhiyun * @elem: the capability element to parse
1777*4882a593Smuzhiyun * @prefix: message prefix for tracing capabilities
1778*4882a593Smuzhiyun *
1779*4882a593Smuzhiyun * Given a capability element, extract relevant details into the common
1780*4882a593Smuzhiyun * capability structure.
1781*4882a593Smuzhiyun *
1782*4882a593Smuzhiyun * Returns: true if the capability matches one of the common capability ids,
1783*4882a593Smuzhiyun * false otherwise.
1784*4882a593Smuzhiyun */
1785*4882a593Smuzhiyun static bool
ice_parse_common_caps(struct ice_hw * hw,struct ice_hw_common_caps * caps,struct ice_aqc_list_caps_elem * elem,const char * prefix)1786*4882a593Smuzhiyun ice_parse_common_caps(struct ice_hw *hw, struct ice_hw_common_caps *caps,
1787*4882a593Smuzhiyun struct ice_aqc_list_caps_elem *elem, const char *prefix)
1788*4882a593Smuzhiyun {
1789*4882a593Smuzhiyun u32 logical_id = le32_to_cpu(elem->logical_id);
1790*4882a593Smuzhiyun u32 phys_id = le32_to_cpu(elem->phys_id);
1791*4882a593Smuzhiyun u32 number = le32_to_cpu(elem->number);
1792*4882a593Smuzhiyun u16 cap = le16_to_cpu(elem->cap);
1793*4882a593Smuzhiyun bool found = true;
1794*4882a593Smuzhiyun
1795*4882a593Smuzhiyun switch (cap) {
1796*4882a593Smuzhiyun case ICE_AQC_CAPS_VALID_FUNCTIONS:
1797*4882a593Smuzhiyun caps->valid_functions = number;
1798*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
1799*4882a593Smuzhiyun "%s: valid_functions (bitmap) = %d\n", prefix,
1800*4882a593Smuzhiyun caps->valid_functions);
1801*4882a593Smuzhiyun break;
1802*4882a593Smuzhiyun case ICE_AQC_CAPS_SRIOV:
1803*4882a593Smuzhiyun caps->sr_iov_1_1 = (number == 1);
1804*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
1805*4882a593Smuzhiyun "%s: sr_iov_1_1 = %d\n", prefix,
1806*4882a593Smuzhiyun caps->sr_iov_1_1);
1807*4882a593Smuzhiyun break;
1808*4882a593Smuzhiyun case ICE_AQC_CAPS_DCB:
1809*4882a593Smuzhiyun caps->dcb = (number == 1);
1810*4882a593Smuzhiyun caps->active_tc_bitmap = logical_id;
1811*4882a593Smuzhiyun caps->maxtc = phys_id;
1812*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
1813*4882a593Smuzhiyun "%s: dcb = %d\n", prefix, caps->dcb);
1814*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
1815*4882a593Smuzhiyun "%s: active_tc_bitmap = %d\n", prefix,
1816*4882a593Smuzhiyun caps->active_tc_bitmap);
1817*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
1818*4882a593Smuzhiyun "%s: maxtc = %d\n", prefix, caps->maxtc);
1819*4882a593Smuzhiyun break;
1820*4882a593Smuzhiyun case ICE_AQC_CAPS_RSS:
1821*4882a593Smuzhiyun caps->rss_table_size = number;
1822*4882a593Smuzhiyun caps->rss_table_entry_width = logical_id;
1823*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
1824*4882a593Smuzhiyun "%s: rss_table_size = %d\n", prefix,
1825*4882a593Smuzhiyun caps->rss_table_size);
1826*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
1827*4882a593Smuzhiyun "%s: rss_table_entry_width = %d\n", prefix,
1828*4882a593Smuzhiyun caps->rss_table_entry_width);
1829*4882a593Smuzhiyun break;
1830*4882a593Smuzhiyun case ICE_AQC_CAPS_RXQS:
1831*4882a593Smuzhiyun caps->num_rxq = number;
1832*4882a593Smuzhiyun caps->rxq_first_id = phys_id;
1833*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
1834*4882a593Smuzhiyun "%s: num_rxq = %d\n", prefix,
1835*4882a593Smuzhiyun caps->num_rxq);
1836*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
1837*4882a593Smuzhiyun "%s: rxq_first_id = %d\n", prefix,
1838*4882a593Smuzhiyun caps->rxq_first_id);
1839*4882a593Smuzhiyun break;
1840*4882a593Smuzhiyun case ICE_AQC_CAPS_TXQS:
1841*4882a593Smuzhiyun caps->num_txq = number;
1842*4882a593Smuzhiyun caps->txq_first_id = phys_id;
1843*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
1844*4882a593Smuzhiyun "%s: num_txq = %d\n", prefix,
1845*4882a593Smuzhiyun caps->num_txq);
1846*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
1847*4882a593Smuzhiyun "%s: txq_first_id = %d\n", prefix,
1848*4882a593Smuzhiyun caps->txq_first_id);
1849*4882a593Smuzhiyun break;
1850*4882a593Smuzhiyun case ICE_AQC_CAPS_MSIX:
1851*4882a593Smuzhiyun caps->num_msix_vectors = number;
1852*4882a593Smuzhiyun caps->msix_vector_first_id = phys_id;
1853*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
1854*4882a593Smuzhiyun "%s: num_msix_vectors = %d\n", prefix,
1855*4882a593Smuzhiyun caps->num_msix_vectors);
1856*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
1857*4882a593Smuzhiyun "%s: msix_vector_first_id = %d\n", prefix,
1858*4882a593Smuzhiyun caps->msix_vector_first_id);
1859*4882a593Smuzhiyun break;
1860*4882a593Smuzhiyun case ICE_AQC_CAPS_PENDING_NVM_VER:
1861*4882a593Smuzhiyun caps->nvm_update_pending_nvm = true;
1862*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT, "%s: update_pending_nvm\n", prefix);
1863*4882a593Smuzhiyun break;
1864*4882a593Smuzhiyun case ICE_AQC_CAPS_PENDING_OROM_VER:
1865*4882a593Smuzhiyun caps->nvm_update_pending_orom = true;
1866*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT, "%s: update_pending_orom\n", prefix);
1867*4882a593Smuzhiyun break;
1868*4882a593Smuzhiyun case ICE_AQC_CAPS_PENDING_NET_VER:
1869*4882a593Smuzhiyun caps->nvm_update_pending_netlist = true;
1870*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT, "%s: update_pending_netlist\n", prefix);
1871*4882a593Smuzhiyun break;
1872*4882a593Smuzhiyun case ICE_AQC_CAPS_NVM_MGMT:
1873*4882a593Smuzhiyun caps->nvm_unified_update =
1874*4882a593Smuzhiyun (number & ICE_NVM_MGMT_UNIFIED_UPD_SUPPORT) ?
1875*4882a593Smuzhiyun true : false;
1876*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT, "%s: nvm_unified_update = %d\n", prefix,
1877*4882a593Smuzhiyun caps->nvm_unified_update);
1878*4882a593Smuzhiyun break;
1879*4882a593Smuzhiyun case ICE_AQC_CAPS_MAX_MTU:
1880*4882a593Smuzhiyun caps->max_mtu = number;
1881*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT, "%s: max_mtu = %d\n",
1882*4882a593Smuzhiyun prefix, caps->max_mtu);
1883*4882a593Smuzhiyun break;
1884*4882a593Smuzhiyun default:
1885*4882a593Smuzhiyun /* Not one of the recognized common capabilities */
1886*4882a593Smuzhiyun found = false;
1887*4882a593Smuzhiyun }
1888*4882a593Smuzhiyun
1889*4882a593Smuzhiyun return found;
1890*4882a593Smuzhiyun }
1891*4882a593Smuzhiyun
1892*4882a593Smuzhiyun /**
1893*4882a593Smuzhiyun * ice_recalc_port_limited_caps - Recalculate port limited capabilities
1894*4882a593Smuzhiyun * @hw: pointer to the HW structure
1895*4882a593Smuzhiyun * @caps: pointer to capabilities structure to fix
1896*4882a593Smuzhiyun *
1897*4882a593Smuzhiyun * Re-calculate the capabilities that are dependent on the number of physical
1898*4882a593Smuzhiyun * ports; i.e. some features are not supported or function differently on
1899*4882a593Smuzhiyun * devices with more than 4 ports.
1900*4882a593Smuzhiyun */
1901*4882a593Smuzhiyun static void
ice_recalc_port_limited_caps(struct ice_hw * hw,struct ice_hw_common_caps * caps)1902*4882a593Smuzhiyun ice_recalc_port_limited_caps(struct ice_hw *hw, struct ice_hw_common_caps *caps)
1903*4882a593Smuzhiyun {
1904*4882a593Smuzhiyun /* This assumes device capabilities are always scanned before function
1905*4882a593Smuzhiyun * capabilities during the initialization flow.
1906*4882a593Smuzhiyun */
1907*4882a593Smuzhiyun if (hw->dev_caps.num_funcs > 4) {
1908*4882a593Smuzhiyun /* Max 4 TCs per port */
1909*4882a593Smuzhiyun caps->maxtc = 4;
1910*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
1911*4882a593Smuzhiyun "reducing maxtc to %d (based on #ports)\n",
1912*4882a593Smuzhiyun caps->maxtc);
1913*4882a593Smuzhiyun }
1914*4882a593Smuzhiyun }
1915*4882a593Smuzhiyun
1916*4882a593Smuzhiyun /**
1917*4882a593Smuzhiyun * ice_parse_vf_func_caps - Parse ICE_AQC_CAPS_VF function caps
1918*4882a593Smuzhiyun * @hw: pointer to the HW struct
1919*4882a593Smuzhiyun * @func_p: pointer to function capabilities structure
1920*4882a593Smuzhiyun * @cap: pointer to the capability element to parse
1921*4882a593Smuzhiyun *
1922*4882a593Smuzhiyun * Extract function capabilities for ICE_AQC_CAPS_VF.
1923*4882a593Smuzhiyun */
1924*4882a593Smuzhiyun static void
ice_parse_vf_func_caps(struct ice_hw * hw,struct ice_hw_func_caps * func_p,struct ice_aqc_list_caps_elem * cap)1925*4882a593Smuzhiyun ice_parse_vf_func_caps(struct ice_hw *hw, struct ice_hw_func_caps *func_p,
1926*4882a593Smuzhiyun struct ice_aqc_list_caps_elem *cap)
1927*4882a593Smuzhiyun {
1928*4882a593Smuzhiyun u32 logical_id = le32_to_cpu(cap->logical_id);
1929*4882a593Smuzhiyun u32 number = le32_to_cpu(cap->number);
1930*4882a593Smuzhiyun
1931*4882a593Smuzhiyun func_p->num_allocd_vfs = number;
1932*4882a593Smuzhiyun func_p->vf_base_id = logical_id;
1933*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT, "func caps: num_allocd_vfs = %d\n",
1934*4882a593Smuzhiyun func_p->num_allocd_vfs);
1935*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT, "func caps: vf_base_id = %d\n",
1936*4882a593Smuzhiyun func_p->vf_base_id);
1937*4882a593Smuzhiyun }
1938*4882a593Smuzhiyun
1939*4882a593Smuzhiyun /**
1940*4882a593Smuzhiyun * ice_parse_vsi_func_caps - Parse ICE_AQC_CAPS_VSI function caps
1941*4882a593Smuzhiyun * @hw: pointer to the HW struct
1942*4882a593Smuzhiyun * @func_p: pointer to function capabilities structure
1943*4882a593Smuzhiyun * @cap: pointer to the capability element to parse
1944*4882a593Smuzhiyun *
1945*4882a593Smuzhiyun * Extract function capabilities for ICE_AQC_CAPS_VSI.
1946*4882a593Smuzhiyun */
1947*4882a593Smuzhiyun static void
ice_parse_vsi_func_caps(struct ice_hw * hw,struct ice_hw_func_caps * func_p,struct ice_aqc_list_caps_elem * cap)1948*4882a593Smuzhiyun ice_parse_vsi_func_caps(struct ice_hw *hw, struct ice_hw_func_caps *func_p,
1949*4882a593Smuzhiyun struct ice_aqc_list_caps_elem *cap)
1950*4882a593Smuzhiyun {
1951*4882a593Smuzhiyun func_p->guar_num_vsi = ice_get_num_per_func(hw, ICE_MAX_VSI);
1952*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT, "func caps: guar_num_vsi (fw) = %d\n",
1953*4882a593Smuzhiyun le32_to_cpu(cap->number));
1954*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT, "func caps: guar_num_vsi = %d\n",
1955*4882a593Smuzhiyun func_p->guar_num_vsi);
1956*4882a593Smuzhiyun }
1957*4882a593Smuzhiyun
1958*4882a593Smuzhiyun /**
1959*4882a593Smuzhiyun * ice_parse_fdir_func_caps - Parse ICE_AQC_CAPS_FD function caps
1960*4882a593Smuzhiyun * @hw: pointer to the HW struct
1961*4882a593Smuzhiyun * @func_p: pointer to function capabilities structure
1962*4882a593Smuzhiyun *
1963*4882a593Smuzhiyun * Extract function capabilities for ICE_AQC_CAPS_FD.
1964*4882a593Smuzhiyun */
1965*4882a593Smuzhiyun static void
ice_parse_fdir_func_caps(struct ice_hw * hw,struct ice_hw_func_caps * func_p)1966*4882a593Smuzhiyun ice_parse_fdir_func_caps(struct ice_hw *hw, struct ice_hw_func_caps *func_p)
1967*4882a593Smuzhiyun {
1968*4882a593Smuzhiyun u32 reg_val, val;
1969*4882a593Smuzhiyun
1970*4882a593Smuzhiyun reg_val = rd32(hw, GLQF_FD_SIZE);
1971*4882a593Smuzhiyun val = (reg_val & GLQF_FD_SIZE_FD_GSIZE_M) >>
1972*4882a593Smuzhiyun GLQF_FD_SIZE_FD_GSIZE_S;
1973*4882a593Smuzhiyun func_p->fd_fltr_guar =
1974*4882a593Smuzhiyun ice_get_num_per_func(hw, val);
1975*4882a593Smuzhiyun val = (reg_val & GLQF_FD_SIZE_FD_BSIZE_M) >>
1976*4882a593Smuzhiyun GLQF_FD_SIZE_FD_BSIZE_S;
1977*4882a593Smuzhiyun func_p->fd_fltr_best_effort = val;
1978*4882a593Smuzhiyun
1979*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
1980*4882a593Smuzhiyun "func caps: fd_fltr_guar = %d\n",
1981*4882a593Smuzhiyun func_p->fd_fltr_guar);
1982*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
1983*4882a593Smuzhiyun "func caps: fd_fltr_best_effort = %d\n",
1984*4882a593Smuzhiyun func_p->fd_fltr_best_effort);
1985*4882a593Smuzhiyun }
1986*4882a593Smuzhiyun
1987*4882a593Smuzhiyun /**
1988*4882a593Smuzhiyun * ice_parse_func_caps - Parse function capabilities
1989*4882a593Smuzhiyun * @hw: pointer to the HW struct
1990*4882a593Smuzhiyun * @func_p: pointer to function capabilities structure
1991*4882a593Smuzhiyun * @buf: buffer containing the function capability records
1992*4882a593Smuzhiyun * @cap_count: the number of capabilities
1993*4882a593Smuzhiyun *
1994*4882a593Smuzhiyun * Helper function to parse function (0x000A) capabilities list. For
1995*4882a593Smuzhiyun * capabilities shared between device and function, this relies on
1996*4882a593Smuzhiyun * ice_parse_common_caps.
1997*4882a593Smuzhiyun *
1998*4882a593Smuzhiyun * Loop through the list of provided capabilities and extract the relevant
1999*4882a593Smuzhiyun * data into the function capabilities structured.
2000*4882a593Smuzhiyun */
2001*4882a593Smuzhiyun static void
ice_parse_func_caps(struct ice_hw * hw,struct ice_hw_func_caps * func_p,void * buf,u32 cap_count)2002*4882a593Smuzhiyun ice_parse_func_caps(struct ice_hw *hw, struct ice_hw_func_caps *func_p,
2003*4882a593Smuzhiyun void *buf, u32 cap_count)
2004*4882a593Smuzhiyun {
2005*4882a593Smuzhiyun struct ice_aqc_list_caps_elem *cap_resp;
2006*4882a593Smuzhiyun u32 i;
2007*4882a593Smuzhiyun
2008*4882a593Smuzhiyun cap_resp = (struct ice_aqc_list_caps_elem *)buf;
2009*4882a593Smuzhiyun
2010*4882a593Smuzhiyun memset(func_p, 0, sizeof(*func_p));
2011*4882a593Smuzhiyun
2012*4882a593Smuzhiyun for (i = 0; i < cap_count; i++) {
2013*4882a593Smuzhiyun u16 cap = le16_to_cpu(cap_resp[i].cap);
2014*4882a593Smuzhiyun bool found;
2015*4882a593Smuzhiyun
2016*4882a593Smuzhiyun found = ice_parse_common_caps(hw, &func_p->common_cap,
2017*4882a593Smuzhiyun &cap_resp[i], "func caps");
2018*4882a593Smuzhiyun
2019*4882a593Smuzhiyun switch (cap) {
2020*4882a593Smuzhiyun case ICE_AQC_CAPS_VF:
2021*4882a593Smuzhiyun ice_parse_vf_func_caps(hw, func_p, &cap_resp[i]);
2022*4882a593Smuzhiyun break;
2023*4882a593Smuzhiyun case ICE_AQC_CAPS_VSI:
2024*4882a593Smuzhiyun ice_parse_vsi_func_caps(hw, func_p, &cap_resp[i]);
2025*4882a593Smuzhiyun break;
2026*4882a593Smuzhiyun case ICE_AQC_CAPS_FD:
2027*4882a593Smuzhiyun ice_parse_fdir_func_caps(hw, func_p);
2028*4882a593Smuzhiyun break;
2029*4882a593Smuzhiyun default:
2030*4882a593Smuzhiyun /* Don't list common capabilities as unknown */
2031*4882a593Smuzhiyun if (!found)
2032*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
2033*4882a593Smuzhiyun "func caps: unknown capability[%d]: 0x%x\n",
2034*4882a593Smuzhiyun i, cap);
2035*4882a593Smuzhiyun break;
2036*4882a593Smuzhiyun }
2037*4882a593Smuzhiyun }
2038*4882a593Smuzhiyun
2039*4882a593Smuzhiyun ice_recalc_port_limited_caps(hw, &func_p->common_cap);
2040*4882a593Smuzhiyun }
2041*4882a593Smuzhiyun
2042*4882a593Smuzhiyun /**
2043*4882a593Smuzhiyun * ice_parse_valid_functions_cap - Parse ICE_AQC_CAPS_VALID_FUNCTIONS caps
2044*4882a593Smuzhiyun * @hw: pointer to the HW struct
2045*4882a593Smuzhiyun * @dev_p: pointer to device capabilities structure
2046*4882a593Smuzhiyun * @cap: capability element to parse
2047*4882a593Smuzhiyun *
2048*4882a593Smuzhiyun * Parse ICE_AQC_CAPS_VALID_FUNCTIONS for device capabilities.
2049*4882a593Smuzhiyun */
2050*4882a593Smuzhiyun static void
ice_parse_valid_functions_cap(struct ice_hw * hw,struct ice_hw_dev_caps * dev_p,struct ice_aqc_list_caps_elem * cap)2051*4882a593Smuzhiyun ice_parse_valid_functions_cap(struct ice_hw *hw, struct ice_hw_dev_caps *dev_p,
2052*4882a593Smuzhiyun struct ice_aqc_list_caps_elem *cap)
2053*4882a593Smuzhiyun {
2054*4882a593Smuzhiyun u32 number = le32_to_cpu(cap->number);
2055*4882a593Smuzhiyun
2056*4882a593Smuzhiyun dev_p->num_funcs = hweight32(number);
2057*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT, "dev caps: num_funcs = %d\n",
2058*4882a593Smuzhiyun dev_p->num_funcs);
2059*4882a593Smuzhiyun }
2060*4882a593Smuzhiyun
2061*4882a593Smuzhiyun /**
2062*4882a593Smuzhiyun * ice_parse_vf_dev_caps - Parse ICE_AQC_CAPS_VF device caps
2063*4882a593Smuzhiyun * @hw: pointer to the HW struct
2064*4882a593Smuzhiyun * @dev_p: pointer to device capabilities structure
2065*4882a593Smuzhiyun * @cap: capability element to parse
2066*4882a593Smuzhiyun *
2067*4882a593Smuzhiyun * Parse ICE_AQC_CAPS_VF for device capabilities.
2068*4882a593Smuzhiyun */
2069*4882a593Smuzhiyun static void
ice_parse_vf_dev_caps(struct ice_hw * hw,struct ice_hw_dev_caps * dev_p,struct ice_aqc_list_caps_elem * cap)2070*4882a593Smuzhiyun ice_parse_vf_dev_caps(struct ice_hw *hw, struct ice_hw_dev_caps *dev_p,
2071*4882a593Smuzhiyun struct ice_aqc_list_caps_elem *cap)
2072*4882a593Smuzhiyun {
2073*4882a593Smuzhiyun u32 number = le32_to_cpu(cap->number);
2074*4882a593Smuzhiyun
2075*4882a593Smuzhiyun dev_p->num_vfs_exposed = number;
2076*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT, "dev_caps: num_vfs_exposed = %d\n",
2077*4882a593Smuzhiyun dev_p->num_vfs_exposed);
2078*4882a593Smuzhiyun }
2079*4882a593Smuzhiyun
2080*4882a593Smuzhiyun /**
2081*4882a593Smuzhiyun * ice_parse_vsi_dev_caps - Parse ICE_AQC_CAPS_VSI device caps
2082*4882a593Smuzhiyun * @hw: pointer to the HW struct
2083*4882a593Smuzhiyun * @dev_p: pointer to device capabilities structure
2084*4882a593Smuzhiyun * @cap: capability element to parse
2085*4882a593Smuzhiyun *
2086*4882a593Smuzhiyun * Parse ICE_AQC_CAPS_VSI for device capabilities.
2087*4882a593Smuzhiyun */
2088*4882a593Smuzhiyun static void
ice_parse_vsi_dev_caps(struct ice_hw * hw,struct ice_hw_dev_caps * dev_p,struct ice_aqc_list_caps_elem * cap)2089*4882a593Smuzhiyun ice_parse_vsi_dev_caps(struct ice_hw *hw, struct ice_hw_dev_caps *dev_p,
2090*4882a593Smuzhiyun struct ice_aqc_list_caps_elem *cap)
2091*4882a593Smuzhiyun {
2092*4882a593Smuzhiyun u32 number = le32_to_cpu(cap->number);
2093*4882a593Smuzhiyun
2094*4882a593Smuzhiyun dev_p->num_vsi_allocd_to_host = number;
2095*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT, "dev caps: num_vsi_allocd_to_host = %d\n",
2096*4882a593Smuzhiyun dev_p->num_vsi_allocd_to_host);
2097*4882a593Smuzhiyun }
2098*4882a593Smuzhiyun
2099*4882a593Smuzhiyun /**
2100*4882a593Smuzhiyun * ice_parse_fdir_dev_caps - Parse ICE_AQC_CAPS_FD device caps
2101*4882a593Smuzhiyun * @hw: pointer to the HW struct
2102*4882a593Smuzhiyun * @dev_p: pointer to device capabilities structure
2103*4882a593Smuzhiyun * @cap: capability element to parse
2104*4882a593Smuzhiyun *
2105*4882a593Smuzhiyun * Parse ICE_AQC_CAPS_FD for device capabilities.
2106*4882a593Smuzhiyun */
2107*4882a593Smuzhiyun static void
ice_parse_fdir_dev_caps(struct ice_hw * hw,struct ice_hw_dev_caps * dev_p,struct ice_aqc_list_caps_elem * cap)2108*4882a593Smuzhiyun ice_parse_fdir_dev_caps(struct ice_hw *hw, struct ice_hw_dev_caps *dev_p,
2109*4882a593Smuzhiyun struct ice_aqc_list_caps_elem *cap)
2110*4882a593Smuzhiyun {
2111*4882a593Smuzhiyun u32 number = le32_to_cpu(cap->number);
2112*4882a593Smuzhiyun
2113*4882a593Smuzhiyun dev_p->num_flow_director_fltr = number;
2114*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT, "dev caps: num_flow_director_fltr = %d\n",
2115*4882a593Smuzhiyun dev_p->num_flow_director_fltr);
2116*4882a593Smuzhiyun }
2117*4882a593Smuzhiyun
2118*4882a593Smuzhiyun /**
2119*4882a593Smuzhiyun * ice_parse_dev_caps - Parse device capabilities
2120*4882a593Smuzhiyun * @hw: pointer to the HW struct
2121*4882a593Smuzhiyun * @dev_p: pointer to device capabilities structure
2122*4882a593Smuzhiyun * @buf: buffer containing the device capability records
2123*4882a593Smuzhiyun * @cap_count: the number of capabilities
2124*4882a593Smuzhiyun *
2125*4882a593Smuzhiyun * Helper device to parse device (0x000B) capabilities list. For
2126*4882a593Smuzhiyun * capabilities shared between device and function, this relies on
2127*4882a593Smuzhiyun * ice_parse_common_caps.
2128*4882a593Smuzhiyun *
2129*4882a593Smuzhiyun * Loop through the list of provided capabilities and extract the relevant
2130*4882a593Smuzhiyun * data into the device capabilities structured.
2131*4882a593Smuzhiyun */
2132*4882a593Smuzhiyun static void
ice_parse_dev_caps(struct ice_hw * hw,struct ice_hw_dev_caps * dev_p,void * buf,u32 cap_count)2133*4882a593Smuzhiyun ice_parse_dev_caps(struct ice_hw *hw, struct ice_hw_dev_caps *dev_p,
2134*4882a593Smuzhiyun void *buf, u32 cap_count)
2135*4882a593Smuzhiyun {
2136*4882a593Smuzhiyun struct ice_aqc_list_caps_elem *cap_resp;
2137*4882a593Smuzhiyun u32 i;
2138*4882a593Smuzhiyun
2139*4882a593Smuzhiyun cap_resp = (struct ice_aqc_list_caps_elem *)buf;
2140*4882a593Smuzhiyun
2141*4882a593Smuzhiyun memset(dev_p, 0, sizeof(*dev_p));
2142*4882a593Smuzhiyun
2143*4882a593Smuzhiyun for (i = 0; i < cap_count; i++) {
2144*4882a593Smuzhiyun u16 cap = le16_to_cpu(cap_resp[i].cap);
2145*4882a593Smuzhiyun bool found;
2146*4882a593Smuzhiyun
2147*4882a593Smuzhiyun found = ice_parse_common_caps(hw, &dev_p->common_cap,
2148*4882a593Smuzhiyun &cap_resp[i], "dev caps");
2149*4882a593Smuzhiyun
2150*4882a593Smuzhiyun switch (cap) {
2151*4882a593Smuzhiyun case ICE_AQC_CAPS_VALID_FUNCTIONS:
2152*4882a593Smuzhiyun ice_parse_valid_functions_cap(hw, dev_p, &cap_resp[i]);
2153*4882a593Smuzhiyun break;
2154*4882a593Smuzhiyun case ICE_AQC_CAPS_VF:
2155*4882a593Smuzhiyun ice_parse_vf_dev_caps(hw, dev_p, &cap_resp[i]);
2156*4882a593Smuzhiyun break;
2157*4882a593Smuzhiyun case ICE_AQC_CAPS_VSI:
2158*4882a593Smuzhiyun ice_parse_vsi_dev_caps(hw, dev_p, &cap_resp[i]);
2159*4882a593Smuzhiyun break;
2160*4882a593Smuzhiyun case ICE_AQC_CAPS_FD:
2161*4882a593Smuzhiyun ice_parse_fdir_dev_caps(hw, dev_p, &cap_resp[i]);
2162*4882a593Smuzhiyun break;
2163*4882a593Smuzhiyun default:
2164*4882a593Smuzhiyun /* Don't list common capabilities as unknown */
2165*4882a593Smuzhiyun if (!found)
2166*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
2167*4882a593Smuzhiyun "dev caps: unknown capability[%d]: 0x%x\n",
2168*4882a593Smuzhiyun i, cap);
2169*4882a593Smuzhiyun break;
2170*4882a593Smuzhiyun }
2171*4882a593Smuzhiyun }
2172*4882a593Smuzhiyun
2173*4882a593Smuzhiyun ice_recalc_port_limited_caps(hw, &dev_p->common_cap);
2174*4882a593Smuzhiyun }
2175*4882a593Smuzhiyun
2176*4882a593Smuzhiyun /**
2177*4882a593Smuzhiyun * ice_aq_list_caps - query function/device capabilities
2178*4882a593Smuzhiyun * @hw: pointer to the HW struct
2179*4882a593Smuzhiyun * @buf: a buffer to hold the capabilities
2180*4882a593Smuzhiyun * @buf_size: size of the buffer
2181*4882a593Smuzhiyun * @cap_count: if not NULL, set to the number of capabilities reported
2182*4882a593Smuzhiyun * @opc: capabilities type to discover, device or function
2183*4882a593Smuzhiyun * @cd: pointer to command details structure or NULL
2184*4882a593Smuzhiyun *
2185*4882a593Smuzhiyun * Get the function (0x000A) or device (0x000B) capabilities description from
2186*4882a593Smuzhiyun * firmware and store it in the buffer.
2187*4882a593Smuzhiyun *
2188*4882a593Smuzhiyun * If the cap_count pointer is not NULL, then it is set to the number of
2189*4882a593Smuzhiyun * capabilities firmware will report. Note that if the buffer size is too
2190*4882a593Smuzhiyun * small, it is possible the command will return ICE_AQ_ERR_ENOMEM. The
2191*4882a593Smuzhiyun * cap_count will still be updated in this case. It is recommended that the
2192*4882a593Smuzhiyun * buffer size be set to ICE_AQ_MAX_BUF_LEN (the largest possible buffer that
2193*4882a593Smuzhiyun * firmware could return) to avoid this.
2194*4882a593Smuzhiyun */
2195*4882a593Smuzhiyun enum ice_status
ice_aq_list_caps(struct ice_hw * hw,void * buf,u16 buf_size,u32 * cap_count,enum ice_adminq_opc opc,struct ice_sq_cd * cd)2196*4882a593Smuzhiyun ice_aq_list_caps(struct ice_hw *hw, void *buf, u16 buf_size, u32 *cap_count,
2197*4882a593Smuzhiyun enum ice_adminq_opc opc, struct ice_sq_cd *cd)
2198*4882a593Smuzhiyun {
2199*4882a593Smuzhiyun struct ice_aqc_list_caps *cmd;
2200*4882a593Smuzhiyun struct ice_aq_desc desc;
2201*4882a593Smuzhiyun enum ice_status status;
2202*4882a593Smuzhiyun
2203*4882a593Smuzhiyun cmd = &desc.params.get_cap;
2204*4882a593Smuzhiyun
2205*4882a593Smuzhiyun if (opc != ice_aqc_opc_list_func_caps &&
2206*4882a593Smuzhiyun opc != ice_aqc_opc_list_dev_caps)
2207*4882a593Smuzhiyun return ICE_ERR_PARAM;
2208*4882a593Smuzhiyun
2209*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, opc);
2210*4882a593Smuzhiyun status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
2211*4882a593Smuzhiyun
2212*4882a593Smuzhiyun if (cap_count)
2213*4882a593Smuzhiyun *cap_count = le32_to_cpu(cmd->count);
2214*4882a593Smuzhiyun
2215*4882a593Smuzhiyun return status;
2216*4882a593Smuzhiyun }
2217*4882a593Smuzhiyun
2218*4882a593Smuzhiyun /**
2219*4882a593Smuzhiyun * ice_discover_dev_caps - Read and extract device capabilities
2220*4882a593Smuzhiyun * @hw: pointer to the hardware structure
2221*4882a593Smuzhiyun * @dev_caps: pointer to device capabilities structure
2222*4882a593Smuzhiyun *
2223*4882a593Smuzhiyun * Read the device capabilities and extract them into the dev_caps structure
2224*4882a593Smuzhiyun * for later use.
2225*4882a593Smuzhiyun */
2226*4882a593Smuzhiyun enum ice_status
ice_discover_dev_caps(struct ice_hw * hw,struct ice_hw_dev_caps * dev_caps)2227*4882a593Smuzhiyun ice_discover_dev_caps(struct ice_hw *hw, struct ice_hw_dev_caps *dev_caps)
2228*4882a593Smuzhiyun {
2229*4882a593Smuzhiyun enum ice_status status;
2230*4882a593Smuzhiyun u32 cap_count = 0;
2231*4882a593Smuzhiyun void *cbuf;
2232*4882a593Smuzhiyun
2233*4882a593Smuzhiyun cbuf = kzalloc(ICE_AQ_MAX_BUF_LEN, GFP_KERNEL);
2234*4882a593Smuzhiyun if (!cbuf)
2235*4882a593Smuzhiyun return ICE_ERR_NO_MEMORY;
2236*4882a593Smuzhiyun
2237*4882a593Smuzhiyun /* Although the driver doesn't know the number of capabilities the
2238*4882a593Smuzhiyun * device will return, we can simply send a 4KB buffer, the maximum
2239*4882a593Smuzhiyun * possible size that firmware can return.
2240*4882a593Smuzhiyun */
2241*4882a593Smuzhiyun cap_count = ICE_AQ_MAX_BUF_LEN / sizeof(struct ice_aqc_list_caps_elem);
2242*4882a593Smuzhiyun
2243*4882a593Smuzhiyun status = ice_aq_list_caps(hw, cbuf, ICE_AQ_MAX_BUF_LEN, &cap_count,
2244*4882a593Smuzhiyun ice_aqc_opc_list_dev_caps, NULL);
2245*4882a593Smuzhiyun if (!status)
2246*4882a593Smuzhiyun ice_parse_dev_caps(hw, dev_caps, cbuf, cap_count);
2247*4882a593Smuzhiyun kfree(cbuf);
2248*4882a593Smuzhiyun
2249*4882a593Smuzhiyun return status;
2250*4882a593Smuzhiyun }
2251*4882a593Smuzhiyun
2252*4882a593Smuzhiyun /**
2253*4882a593Smuzhiyun * ice_discover_func_caps - Read and extract function capabilities
2254*4882a593Smuzhiyun * @hw: pointer to the hardware structure
2255*4882a593Smuzhiyun * @func_caps: pointer to function capabilities structure
2256*4882a593Smuzhiyun *
2257*4882a593Smuzhiyun * Read the function capabilities and extract them into the func_caps structure
2258*4882a593Smuzhiyun * for later use.
2259*4882a593Smuzhiyun */
2260*4882a593Smuzhiyun static enum ice_status
ice_discover_func_caps(struct ice_hw * hw,struct ice_hw_func_caps * func_caps)2261*4882a593Smuzhiyun ice_discover_func_caps(struct ice_hw *hw, struct ice_hw_func_caps *func_caps)
2262*4882a593Smuzhiyun {
2263*4882a593Smuzhiyun enum ice_status status;
2264*4882a593Smuzhiyun u32 cap_count = 0;
2265*4882a593Smuzhiyun void *cbuf;
2266*4882a593Smuzhiyun
2267*4882a593Smuzhiyun cbuf = kzalloc(ICE_AQ_MAX_BUF_LEN, GFP_KERNEL);
2268*4882a593Smuzhiyun if (!cbuf)
2269*4882a593Smuzhiyun return ICE_ERR_NO_MEMORY;
2270*4882a593Smuzhiyun
2271*4882a593Smuzhiyun /* Although the driver doesn't know the number of capabilities the
2272*4882a593Smuzhiyun * device will return, we can simply send a 4KB buffer, the maximum
2273*4882a593Smuzhiyun * possible size that firmware can return.
2274*4882a593Smuzhiyun */
2275*4882a593Smuzhiyun cap_count = ICE_AQ_MAX_BUF_LEN / sizeof(struct ice_aqc_list_caps_elem);
2276*4882a593Smuzhiyun
2277*4882a593Smuzhiyun status = ice_aq_list_caps(hw, cbuf, ICE_AQ_MAX_BUF_LEN, &cap_count,
2278*4882a593Smuzhiyun ice_aqc_opc_list_func_caps, NULL);
2279*4882a593Smuzhiyun if (!status)
2280*4882a593Smuzhiyun ice_parse_func_caps(hw, func_caps, cbuf, cap_count);
2281*4882a593Smuzhiyun kfree(cbuf);
2282*4882a593Smuzhiyun
2283*4882a593Smuzhiyun return status;
2284*4882a593Smuzhiyun }
2285*4882a593Smuzhiyun
2286*4882a593Smuzhiyun /**
2287*4882a593Smuzhiyun * ice_set_safe_mode_caps - Override dev/func capabilities when in safe mode
2288*4882a593Smuzhiyun * @hw: pointer to the hardware structure
2289*4882a593Smuzhiyun */
ice_set_safe_mode_caps(struct ice_hw * hw)2290*4882a593Smuzhiyun void ice_set_safe_mode_caps(struct ice_hw *hw)
2291*4882a593Smuzhiyun {
2292*4882a593Smuzhiyun struct ice_hw_func_caps *func_caps = &hw->func_caps;
2293*4882a593Smuzhiyun struct ice_hw_dev_caps *dev_caps = &hw->dev_caps;
2294*4882a593Smuzhiyun struct ice_hw_common_caps cached_caps;
2295*4882a593Smuzhiyun u32 num_funcs;
2296*4882a593Smuzhiyun
2297*4882a593Smuzhiyun /* cache some func_caps values that should be restored after memset */
2298*4882a593Smuzhiyun cached_caps = func_caps->common_cap;
2299*4882a593Smuzhiyun
2300*4882a593Smuzhiyun /* unset func capabilities */
2301*4882a593Smuzhiyun memset(func_caps, 0, sizeof(*func_caps));
2302*4882a593Smuzhiyun
2303*4882a593Smuzhiyun #define ICE_RESTORE_FUNC_CAP(name) \
2304*4882a593Smuzhiyun func_caps->common_cap.name = cached_caps.name
2305*4882a593Smuzhiyun
2306*4882a593Smuzhiyun /* restore cached values */
2307*4882a593Smuzhiyun ICE_RESTORE_FUNC_CAP(valid_functions);
2308*4882a593Smuzhiyun ICE_RESTORE_FUNC_CAP(txq_first_id);
2309*4882a593Smuzhiyun ICE_RESTORE_FUNC_CAP(rxq_first_id);
2310*4882a593Smuzhiyun ICE_RESTORE_FUNC_CAP(msix_vector_first_id);
2311*4882a593Smuzhiyun ICE_RESTORE_FUNC_CAP(max_mtu);
2312*4882a593Smuzhiyun ICE_RESTORE_FUNC_CAP(nvm_unified_update);
2313*4882a593Smuzhiyun ICE_RESTORE_FUNC_CAP(nvm_update_pending_nvm);
2314*4882a593Smuzhiyun ICE_RESTORE_FUNC_CAP(nvm_update_pending_orom);
2315*4882a593Smuzhiyun ICE_RESTORE_FUNC_CAP(nvm_update_pending_netlist);
2316*4882a593Smuzhiyun
2317*4882a593Smuzhiyun /* one Tx and one Rx queue in safe mode */
2318*4882a593Smuzhiyun func_caps->common_cap.num_rxq = 1;
2319*4882a593Smuzhiyun func_caps->common_cap.num_txq = 1;
2320*4882a593Smuzhiyun
2321*4882a593Smuzhiyun /* two MSIX vectors, one for traffic and one for misc causes */
2322*4882a593Smuzhiyun func_caps->common_cap.num_msix_vectors = 2;
2323*4882a593Smuzhiyun func_caps->guar_num_vsi = 1;
2324*4882a593Smuzhiyun
2325*4882a593Smuzhiyun /* cache some dev_caps values that should be restored after memset */
2326*4882a593Smuzhiyun cached_caps = dev_caps->common_cap;
2327*4882a593Smuzhiyun num_funcs = dev_caps->num_funcs;
2328*4882a593Smuzhiyun
2329*4882a593Smuzhiyun /* unset dev capabilities */
2330*4882a593Smuzhiyun memset(dev_caps, 0, sizeof(*dev_caps));
2331*4882a593Smuzhiyun
2332*4882a593Smuzhiyun #define ICE_RESTORE_DEV_CAP(name) \
2333*4882a593Smuzhiyun dev_caps->common_cap.name = cached_caps.name
2334*4882a593Smuzhiyun
2335*4882a593Smuzhiyun /* restore cached values */
2336*4882a593Smuzhiyun ICE_RESTORE_DEV_CAP(valid_functions);
2337*4882a593Smuzhiyun ICE_RESTORE_DEV_CAP(txq_first_id);
2338*4882a593Smuzhiyun ICE_RESTORE_DEV_CAP(rxq_first_id);
2339*4882a593Smuzhiyun ICE_RESTORE_DEV_CAP(msix_vector_first_id);
2340*4882a593Smuzhiyun ICE_RESTORE_DEV_CAP(max_mtu);
2341*4882a593Smuzhiyun ICE_RESTORE_DEV_CAP(nvm_unified_update);
2342*4882a593Smuzhiyun ICE_RESTORE_DEV_CAP(nvm_update_pending_nvm);
2343*4882a593Smuzhiyun ICE_RESTORE_DEV_CAP(nvm_update_pending_orom);
2344*4882a593Smuzhiyun ICE_RESTORE_DEV_CAP(nvm_update_pending_netlist);
2345*4882a593Smuzhiyun dev_caps->num_funcs = num_funcs;
2346*4882a593Smuzhiyun
2347*4882a593Smuzhiyun /* one Tx and one Rx queue per function in safe mode */
2348*4882a593Smuzhiyun dev_caps->common_cap.num_rxq = num_funcs;
2349*4882a593Smuzhiyun dev_caps->common_cap.num_txq = num_funcs;
2350*4882a593Smuzhiyun
2351*4882a593Smuzhiyun /* two MSIX vectors per function */
2352*4882a593Smuzhiyun dev_caps->common_cap.num_msix_vectors = 2 * num_funcs;
2353*4882a593Smuzhiyun }
2354*4882a593Smuzhiyun
2355*4882a593Smuzhiyun /**
2356*4882a593Smuzhiyun * ice_get_caps - get info about the HW
2357*4882a593Smuzhiyun * @hw: pointer to the hardware structure
2358*4882a593Smuzhiyun */
ice_get_caps(struct ice_hw * hw)2359*4882a593Smuzhiyun enum ice_status ice_get_caps(struct ice_hw *hw)
2360*4882a593Smuzhiyun {
2361*4882a593Smuzhiyun enum ice_status status;
2362*4882a593Smuzhiyun
2363*4882a593Smuzhiyun status = ice_discover_dev_caps(hw, &hw->dev_caps);
2364*4882a593Smuzhiyun if (status)
2365*4882a593Smuzhiyun return status;
2366*4882a593Smuzhiyun
2367*4882a593Smuzhiyun return ice_discover_func_caps(hw, &hw->func_caps);
2368*4882a593Smuzhiyun }
2369*4882a593Smuzhiyun
2370*4882a593Smuzhiyun /**
2371*4882a593Smuzhiyun * ice_aq_manage_mac_write - manage MAC address write command
2372*4882a593Smuzhiyun * @hw: pointer to the HW struct
2373*4882a593Smuzhiyun * @mac_addr: MAC address to be written as LAA/LAA+WoL/Port address
2374*4882a593Smuzhiyun * @flags: flags to control write behavior
2375*4882a593Smuzhiyun * @cd: pointer to command details structure or NULL
2376*4882a593Smuzhiyun *
2377*4882a593Smuzhiyun * This function is used to write MAC address to the NVM (0x0108).
2378*4882a593Smuzhiyun */
2379*4882a593Smuzhiyun enum ice_status
ice_aq_manage_mac_write(struct ice_hw * hw,const u8 * mac_addr,u8 flags,struct ice_sq_cd * cd)2380*4882a593Smuzhiyun ice_aq_manage_mac_write(struct ice_hw *hw, const u8 *mac_addr, u8 flags,
2381*4882a593Smuzhiyun struct ice_sq_cd *cd)
2382*4882a593Smuzhiyun {
2383*4882a593Smuzhiyun struct ice_aqc_manage_mac_write *cmd;
2384*4882a593Smuzhiyun struct ice_aq_desc desc;
2385*4882a593Smuzhiyun
2386*4882a593Smuzhiyun cmd = &desc.params.mac_write;
2387*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_manage_mac_write);
2388*4882a593Smuzhiyun
2389*4882a593Smuzhiyun cmd->flags = flags;
2390*4882a593Smuzhiyun ether_addr_copy(cmd->mac_addr, mac_addr);
2391*4882a593Smuzhiyun
2392*4882a593Smuzhiyun return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
2393*4882a593Smuzhiyun }
2394*4882a593Smuzhiyun
2395*4882a593Smuzhiyun /**
2396*4882a593Smuzhiyun * ice_aq_clear_pxe_mode
2397*4882a593Smuzhiyun * @hw: pointer to the HW struct
2398*4882a593Smuzhiyun *
2399*4882a593Smuzhiyun * Tell the firmware that the driver is taking over from PXE (0x0110).
2400*4882a593Smuzhiyun */
ice_aq_clear_pxe_mode(struct ice_hw * hw)2401*4882a593Smuzhiyun static enum ice_status ice_aq_clear_pxe_mode(struct ice_hw *hw)
2402*4882a593Smuzhiyun {
2403*4882a593Smuzhiyun struct ice_aq_desc desc;
2404*4882a593Smuzhiyun
2405*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_clear_pxe_mode);
2406*4882a593Smuzhiyun desc.params.clear_pxe.rx_cnt = ICE_AQC_CLEAR_PXE_RX_CNT;
2407*4882a593Smuzhiyun
2408*4882a593Smuzhiyun return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
2409*4882a593Smuzhiyun }
2410*4882a593Smuzhiyun
2411*4882a593Smuzhiyun /**
2412*4882a593Smuzhiyun * ice_clear_pxe_mode - clear pxe operations mode
2413*4882a593Smuzhiyun * @hw: pointer to the HW struct
2414*4882a593Smuzhiyun *
2415*4882a593Smuzhiyun * Make sure all PXE mode settings are cleared, including things
2416*4882a593Smuzhiyun * like descriptor fetch/write-back mode.
2417*4882a593Smuzhiyun */
ice_clear_pxe_mode(struct ice_hw * hw)2418*4882a593Smuzhiyun void ice_clear_pxe_mode(struct ice_hw *hw)
2419*4882a593Smuzhiyun {
2420*4882a593Smuzhiyun if (ice_check_sq_alive(hw, &hw->adminq))
2421*4882a593Smuzhiyun ice_aq_clear_pxe_mode(hw);
2422*4882a593Smuzhiyun }
2423*4882a593Smuzhiyun
2424*4882a593Smuzhiyun /**
2425*4882a593Smuzhiyun * ice_get_link_speed_based_on_phy_type - returns link speed
2426*4882a593Smuzhiyun * @phy_type_low: lower part of phy_type
2427*4882a593Smuzhiyun * @phy_type_high: higher part of phy_type
2428*4882a593Smuzhiyun *
2429*4882a593Smuzhiyun * This helper function will convert an entry in PHY type structure
2430*4882a593Smuzhiyun * [phy_type_low, phy_type_high] to its corresponding link speed.
2431*4882a593Smuzhiyun * Note: In the structure of [phy_type_low, phy_type_high], there should
2432*4882a593Smuzhiyun * be one bit set, as this function will convert one PHY type to its
2433*4882a593Smuzhiyun * speed.
2434*4882a593Smuzhiyun * If no bit gets set, ICE_LINK_SPEED_UNKNOWN will be returned
2435*4882a593Smuzhiyun * If more than one bit gets set, ICE_LINK_SPEED_UNKNOWN will be returned
2436*4882a593Smuzhiyun */
2437*4882a593Smuzhiyun static u16
ice_get_link_speed_based_on_phy_type(u64 phy_type_low,u64 phy_type_high)2438*4882a593Smuzhiyun ice_get_link_speed_based_on_phy_type(u64 phy_type_low, u64 phy_type_high)
2439*4882a593Smuzhiyun {
2440*4882a593Smuzhiyun u16 speed_phy_type_high = ICE_AQ_LINK_SPEED_UNKNOWN;
2441*4882a593Smuzhiyun u16 speed_phy_type_low = ICE_AQ_LINK_SPEED_UNKNOWN;
2442*4882a593Smuzhiyun
2443*4882a593Smuzhiyun switch (phy_type_low) {
2444*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100BASE_TX:
2445*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100M_SGMII:
2446*4882a593Smuzhiyun speed_phy_type_low = ICE_AQ_LINK_SPEED_100MB;
2447*4882a593Smuzhiyun break;
2448*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_1000BASE_T:
2449*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_1000BASE_SX:
2450*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_1000BASE_LX:
2451*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_1000BASE_KX:
2452*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_1G_SGMII:
2453*4882a593Smuzhiyun speed_phy_type_low = ICE_AQ_LINK_SPEED_1000MB;
2454*4882a593Smuzhiyun break;
2455*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_2500BASE_T:
2456*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_2500BASE_X:
2457*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_2500BASE_KX:
2458*4882a593Smuzhiyun speed_phy_type_low = ICE_AQ_LINK_SPEED_2500MB;
2459*4882a593Smuzhiyun break;
2460*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_5GBASE_T:
2461*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_5GBASE_KR:
2462*4882a593Smuzhiyun speed_phy_type_low = ICE_AQ_LINK_SPEED_5GB;
2463*4882a593Smuzhiyun break;
2464*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_10GBASE_T:
2465*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_10G_SFI_DA:
2466*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_10GBASE_SR:
2467*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_10GBASE_LR:
2468*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_10GBASE_KR_CR1:
2469*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC:
2470*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_10G_SFI_C2C:
2471*4882a593Smuzhiyun speed_phy_type_low = ICE_AQ_LINK_SPEED_10GB;
2472*4882a593Smuzhiyun break;
2473*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_25GBASE_T:
2474*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_25GBASE_CR:
2475*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_25GBASE_CR_S:
2476*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_25GBASE_CR1:
2477*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_25GBASE_SR:
2478*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_25GBASE_LR:
2479*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_25GBASE_KR:
2480*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_25GBASE_KR_S:
2481*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_25GBASE_KR1:
2482*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC:
2483*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_25G_AUI_C2C:
2484*4882a593Smuzhiyun speed_phy_type_low = ICE_AQ_LINK_SPEED_25GB;
2485*4882a593Smuzhiyun break;
2486*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_40GBASE_CR4:
2487*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_40GBASE_SR4:
2488*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_40GBASE_LR4:
2489*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_40GBASE_KR4:
2490*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC:
2491*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_40G_XLAUI:
2492*4882a593Smuzhiyun speed_phy_type_low = ICE_AQ_LINK_SPEED_40GB;
2493*4882a593Smuzhiyun break;
2494*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50GBASE_CR2:
2495*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50GBASE_SR2:
2496*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50GBASE_LR2:
2497*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50GBASE_KR2:
2498*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50G_LAUI2_AOC_ACC:
2499*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50G_LAUI2:
2500*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50G_AUI2_AOC_ACC:
2501*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50G_AUI2:
2502*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50GBASE_CP:
2503*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50GBASE_SR:
2504*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50GBASE_FR:
2505*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50GBASE_LR:
2506*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4:
2507*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50G_AUI1_AOC_ACC:
2508*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_50G_AUI1:
2509*4882a593Smuzhiyun speed_phy_type_low = ICE_AQ_LINK_SPEED_50GB;
2510*4882a593Smuzhiyun break;
2511*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100GBASE_CR4:
2512*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100GBASE_SR4:
2513*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100GBASE_LR4:
2514*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100GBASE_KR4:
2515*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC:
2516*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100G_CAUI4:
2517*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC:
2518*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100G_AUI4:
2519*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4:
2520*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4:
2521*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100GBASE_CP2:
2522*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100GBASE_SR2:
2523*4882a593Smuzhiyun case ICE_PHY_TYPE_LOW_100GBASE_DR:
2524*4882a593Smuzhiyun speed_phy_type_low = ICE_AQ_LINK_SPEED_100GB;
2525*4882a593Smuzhiyun break;
2526*4882a593Smuzhiyun default:
2527*4882a593Smuzhiyun speed_phy_type_low = ICE_AQ_LINK_SPEED_UNKNOWN;
2528*4882a593Smuzhiyun break;
2529*4882a593Smuzhiyun }
2530*4882a593Smuzhiyun
2531*4882a593Smuzhiyun switch (phy_type_high) {
2532*4882a593Smuzhiyun case ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4:
2533*4882a593Smuzhiyun case ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC:
2534*4882a593Smuzhiyun case ICE_PHY_TYPE_HIGH_100G_CAUI2:
2535*4882a593Smuzhiyun case ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC:
2536*4882a593Smuzhiyun case ICE_PHY_TYPE_HIGH_100G_AUI2:
2537*4882a593Smuzhiyun speed_phy_type_high = ICE_AQ_LINK_SPEED_100GB;
2538*4882a593Smuzhiyun break;
2539*4882a593Smuzhiyun default:
2540*4882a593Smuzhiyun speed_phy_type_high = ICE_AQ_LINK_SPEED_UNKNOWN;
2541*4882a593Smuzhiyun break;
2542*4882a593Smuzhiyun }
2543*4882a593Smuzhiyun
2544*4882a593Smuzhiyun if (speed_phy_type_low == ICE_AQ_LINK_SPEED_UNKNOWN &&
2545*4882a593Smuzhiyun speed_phy_type_high == ICE_AQ_LINK_SPEED_UNKNOWN)
2546*4882a593Smuzhiyun return ICE_AQ_LINK_SPEED_UNKNOWN;
2547*4882a593Smuzhiyun else if (speed_phy_type_low != ICE_AQ_LINK_SPEED_UNKNOWN &&
2548*4882a593Smuzhiyun speed_phy_type_high != ICE_AQ_LINK_SPEED_UNKNOWN)
2549*4882a593Smuzhiyun return ICE_AQ_LINK_SPEED_UNKNOWN;
2550*4882a593Smuzhiyun else if (speed_phy_type_low != ICE_AQ_LINK_SPEED_UNKNOWN &&
2551*4882a593Smuzhiyun speed_phy_type_high == ICE_AQ_LINK_SPEED_UNKNOWN)
2552*4882a593Smuzhiyun return speed_phy_type_low;
2553*4882a593Smuzhiyun else
2554*4882a593Smuzhiyun return speed_phy_type_high;
2555*4882a593Smuzhiyun }
2556*4882a593Smuzhiyun
2557*4882a593Smuzhiyun /**
2558*4882a593Smuzhiyun * ice_update_phy_type
2559*4882a593Smuzhiyun * @phy_type_low: pointer to the lower part of phy_type
2560*4882a593Smuzhiyun * @phy_type_high: pointer to the higher part of phy_type
2561*4882a593Smuzhiyun * @link_speeds_bitmap: targeted link speeds bitmap
2562*4882a593Smuzhiyun *
2563*4882a593Smuzhiyun * Note: For the link_speeds_bitmap structure, you can check it at
2564*4882a593Smuzhiyun * [ice_aqc_get_link_status->link_speed]. Caller can pass in
2565*4882a593Smuzhiyun * link_speeds_bitmap include multiple speeds.
2566*4882a593Smuzhiyun *
2567*4882a593Smuzhiyun * Each entry in this [phy_type_low, phy_type_high] structure will
2568*4882a593Smuzhiyun * present a certain link speed. This helper function will turn on bits
2569*4882a593Smuzhiyun * in [phy_type_low, phy_type_high] structure based on the value of
2570*4882a593Smuzhiyun * link_speeds_bitmap input parameter.
2571*4882a593Smuzhiyun */
2572*4882a593Smuzhiyun void
ice_update_phy_type(u64 * phy_type_low,u64 * phy_type_high,u16 link_speeds_bitmap)2573*4882a593Smuzhiyun ice_update_phy_type(u64 *phy_type_low, u64 *phy_type_high,
2574*4882a593Smuzhiyun u16 link_speeds_bitmap)
2575*4882a593Smuzhiyun {
2576*4882a593Smuzhiyun u64 pt_high;
2577*4882a593Smuzhiyun u64 pt_low;
2578*4882a593Smuzhiyun int index;
2579*4882a593Smuzhiyun u16 speed;
2580*4882a593Smuzhiyun
2581*4882a593Smuzhiyun /* We first check with low part of phy_type */
2582*4882a593Smuzhiyun for (index = 0; index <= ICE_PHY_TYPE_LOW_MAX_INDEX; index++) {
2583*4882a593Smuzhiyun pt_low = BIT_ULL(index);
2584*4882a593Smuzhiyun speed = ice_get_link_speed_based_on_phy_type(pt_low, 0);
2585*4882a593Smuzhiyun
2586*4882a593Smuzhiyun if (link_speeds_bitmap & speed)
2587*4882a593Smuzhiyun *phy_type_low |= BIT_ULL(index);
2588*4882a593Smuzhiyun }
2589*4882a593Smuzhiyun
2590*4882a593Smuzhiyun /* We then check with high part of phy_type */
2591*4882a593Smuzhiyun for (index = 0; index <= ICE_PHY_TYPE_HIGH_MAX_INDEX; index++) {
2592*4882a593Smuzhiyun pt_high = BIT_ULL(index);
2593*4882a593Smuzhiyun speed = ice_get_link_speed_based_on_phy_type(0, pt_high);
2594*4882a593Smuzhiyun
2595*4882a593Smuzhiyun if (link_speeds_bitmap & speed)
2596*4882a593Smuzhiyun *phy_type_high |= BIT_ULL(index);
2597*4882a593Smuzhiyun }
2598*4882a593Smuzhiyun }
2599*4882a593Smuzhiyun
2600*4882a593Smuzhiyun /**
2601*4882a593Smuzhiyun * ice_aq_set_phy_cfg
2602*4882a593Smuzhiyun * @hw: pointer to the HW struct
2603*4882a593Smuzhiyun * @pi: port info structure of the interested logical port
2604*4882a593Smuzhiyun * @cfg: structure with PHY configuration data to be set
2605*4882a593Smuzhiyun * @cd: pointer to command details structure or NULL
2606*4882a593Smuzhiyun *
2607*4882a593Smuzhiyun * Set the various PHY configuration parameters supported on the Port.
2608*4882a593Smuzhiyun * One or more of the Set PHY config parameters may be ignored in an MFP
2609*4882a593Smuzhiyun * mode as the PF may not have the privilege to set some of the PHY Config
2610*4882a593Smuzhiyun * parameters. This status will be indicated by the command response (0x0601).
2611*4882a593Smuzhiyun */
2612*4882a593Smuzhiyun enum ice_status
ice_aq_set_phy_cfg(struct ice_hw * hw,struct ice_port_info * pi,struct ice_aqc_set_phy_cfg_data * cfg,struct ice_sq_cd * cd)2613*4882a593Smuzhiyun ice_aq_set_phy_cfg(struct ice_hw *hw, struct ice_port_info *pi,
2614*4882a593Smuzhiyun struct ice_aqc_set_phy_cfg_data *cfg, struct ice_sq_cd *cd)
2615*4882a593Smuzhiyun {
2616*4882a593Smuzhiyun struct ice_aq_desc desc;
2617*4882a593Smuzhiyun enum ice_status status;
2618*4882a593Smuzhiyun
2619*4882a593Smuzhiyun if (!cfg)
2620*4882a593Smuzhiyun return ICE_ERR_PARAM;
2621*4882a593Smuzhiyun
2622*4882a593Smuzhiyun /* Ensure that only valid bits of cfg->caps can be turned on. */
2623*4882a593Smuzhiyun if (cfg->caps & ~ICE_AQ_PHY_ENA_VALID_MASK) {
2624*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_PHY,
2625*4882a593Smuzhiyun "Invalid bit is set in ice_aqc_set_phy_cfg_data->caps : 0x%x\n",
2626*4882a593Smuzhiyun cfg->caps);
2627*4882a593Smuzhiyun
2628*4882a593Smuzhiyun cfg->caps &= ICE_AQ_PHY_ENA_VALID_MASK;
2629*4882a593Smuzhiyun }
2630*4882a593Smuzhiyun
2631*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_phy_cfg);
2632*4882a593Smuzhiyun desc.params.set_phy.lport_num = pi->lport;
2633*4882a593Smuzhiyun desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
2634*4882a593Smuzhiyun
2635*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, "set phy cfg\n");
2636*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " phy_type_low = 0x%llx\n",
2637*4882a593Smuzhiyun (unsigned long long)le64_to_cpu(cfg->phy_type_low));
2638*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " phy_type_high = 0x%llx\n",
2639*4882a593Smuzhiyun (unsigned long long)le64_to_cpu(cfg->phy_type_high));
2640*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " caps = 0x%x\n", cfg->caps);
2641*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " low_power_ctrl_an = 0x%x\n",
2642*4882a593Smuzhiyun cfg->low_power_ctrl_an);
2643*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " eee_cap = 0x%x\n", cfg->eee_cap);
2644*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " eeer_value = 0x%x\n", cfg->eeer_value);
2645*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_LINK, " link_fec_opt = 0x%x\n",
2646*4882a593Smuzhiyun cfg->link_fec_opt);
2647*4882a593Smuzhiyun
2648*4882a593Smuzhiyun status = ice_aq_send_cmd(hw, &desc, cfg, sizeof(*cfg), cd);
2649*4882a593Smuzhiyun if (hw->adminq.sq_last_status == ICE_AQ_RC_EMODE)
2650*4882a593Smuzhiyun status = 0;
2651*4882a593Smuzhiyun
2652*4882a593Smuzhiyun if (!status)
2653*4882a593Smuzhiyun pi->phy.curr_user_phy_cfg = *cfg;
2654*4882a593Smuzhiyun
2655*4882a593Smuzhiyun return status;
2656*4882a593Smuzhiyun }
2657*4882a593Smuzhiyun
2658*4882a593Smuzhiyun /**
2659*4882a593Smuzhiyun * ice_update_link_info - update status of the HW network link
2660*4882a593Smuzhiyun * @pi: port info structure of the interested logical port
2661*4882a593Smuzhiyun */
ice_update_link_info(struct ice_port_info * pi)2662*4882a593Smuzhiyun enum ice_status ice_update_link_info(struct ice_port_info *pi)
2663*4882a593Smuzhiyun {
2664*4882a593Smuzhiyun struct ice_link_status *li;
2665*4882a593Smuzhiyun enum ice_status status;
2666*4882a593Smuzhiyun
2667*4882a593Smuzhiyun if (!pi)
2668*4882a593Smuzhiyun return ICE_ERR_PARAM;
2669*4882a593Smuzhiyun
2670*4882a593Smuzhiyun li = &pi->phy.link_info;
2671*4882a593Smuzhiyun
2672*4882a593Smuzhiyun status = ice_aq_get_link_info(pi, true, NULL, NULL);
2673*4882a593Smuzhiyun if (status)
2674*4882a593Smuzhiyun return status;
2675*4882a593Smuzhiyun
2676*4882a593Smuzhiyun if (li->link_info & ICE_AQ_MEDIA_AVAILABLE) {
2677*4882a593Smuzhiyun struct ice_aqc_get_phy_caps_data *pcaps;
2678*4882a593Smuzhiyun struct ice_hw *hw;
2679*4882a593Smuzhiyun
2680*4882a593Smuzhiyun hw = pi->hw;
2681*4882a593Smuzhiyun pcaps = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*pcaps),
2682*4882a593Smuzhiyun GFP_KERNEL);
2683*4882a593Smuzhiyun if (!pcaps)
2684*4882a593Smuzhiyun return ICE_ERR_NO_MEMORY;
2685*4882a593Smuzhiyun
2686*4882a593Smuzhiyun status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
2687*4882a593Smuzhiyun pcaps, NULL);
2688*4882a593Smuzhiyun
2689*4882a593Smuzhiyun devm_kfree(ice_hw_to_dev(hw), pcaps);
2690*4882a593Smuzhiyun }
2691*4882a593Smuzhiyun
2692*4882a593Smuzhiyun return status;
2693*4882a593Smuzhiyun }
2694*4882a593Smuzhiyun
2695*4882a593Smuzhiyun /**
2696*4882a593Smuzhiyun * ice_cache_phy_user_req
2697*4882a593Smuzhiyun * @pi: port information structure
2698*4882a593Smuzhiyun * @cache_data: PHY logging data
2699*4882a593Smuzhiyun * @cache_mode: PHY logging mode
2700*4882a593Smuzhiyun *
2701*4882a593Smuzhiyun * Log the user request on (FC, FEC, SPEED) for later use.
2702*4882a593Smuzhiyun */
2703*4882a593Smuzhiyun static void
ice_cache_phy_user_req(struct ice_port_info * pi,struct ice_phy_cache_mode_data cache_data,enum ice_phy_cache_mode cache_mode)2704*4882a593Smuzhiyun ice_cache_phy_user_req(struct ice_port_info *pi,
2705*4882a593Smuzhiyun struct ice_phy_cache_mode_data cache_data,
2706*4882a593Smuzhiyun enum ice_phy_cache_mode cache_mode)
2707*4882a593Smuzhiyun {
2708*4882a593Smuzhiyun if (!pi)
2709*4882a593Smuzhiyun return;
2710*4882a593Smuzhiyun
2711*4882a593Smuzhiyun switch (cache_mode) {
2712*4882a593Smuzhiyun case ICE_FC_MODE:
2713*4882a593Smuzhiyun pi->phy.curr_user_fc_req = cache_data.data.curr_user_fc_req;
2714*4882a593Smuzhiyun break;
2715*4882a593Smuzhiyun case ICE_SPEED_MODE:
2716*4882a593Smuzhiyun pi->phy.curr_user_speed_req =
2717*4882a593Smuzhiyun cache_data.data.curr_user_speed_req;
2718*4882a593Smuzhiyun break;
2719*4882a593Smuzhiyun case ICE_FEC_MODE:
2720*4882a593Smuzhiyun pi->phy.curr_user_fec_req = cache_data.data.curr_user_fec_req;
2721*4882a593Smuzhiyun break;
2722*4882a593Smuzhiyun default:
2723*4882a593Smuzhiyun break;
2724*4882a593Smuzhiyun }
2725*4882a593Smuzhiyun }
2726*4882a593Smuzhiyun
2727*4882a593Smuzhiyun /**
2728*4882a593Smuzhiyun * ice_caps_to_fc_mode
2729*4882a593Smuzhiyun * @caps: PHY capabilities
2730*4882a593Smuzhiyun *
2731*4882a593Smuzhiyun * Convert PHY FC capabilities to ice FC mode
2732*4882a593Smuzhiyun */
ice_caps_to_fc_mode(u8 caps)2733*4882a593Smuzhiyun enum ice_fc_mode ice_caps_to_fc_mode(u8 caps)
2734*4882a593Smuzhiyun {
2735*4882a593Smuzhiyun if (caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE &&
2736*4882a593Smuzhiyun caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)
2737*4882a593Smuzhiyun return ICE_FC_FULL;
2738*4882a593Smuzhiyun
2739*4882a593Smuzhiyun if (caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE)
2740*4882a593Smuzhiyun return ICE_FC_TX_PAUSE;
2741*4882a593Smuzhiyun
2742*4882a593Smuzhiyun if (caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)
2743*4882a593Smuzhiyun return ICE_FC_RX_PAUSE;
2744*4882a593Smuzhiyun
2745*4882a593Smuzhiyun return ICE_FC_NONE;
2746*4882a593Smuzhiyun }
2747*4882a593Smuzhiyun
2748*4882a593Smuzhiyun /**
2749*4882a593Smuzhiyun * ice_caps_to_fec_mode
2750*4882a593Smuzhiyun * @caps: PHY capabilities
2751*4882a593Smuzhiyun * @fec_options: Link FEC options
2752*4882a593Smuzhiyun *
2753*4882a593Smuzhiyun * Convert PHY FEC capabilities to ice FEC mode
2754*4882a593Smuzhiyun */
ice_caps_to_fec_mode(u8 caps,u8 fec_options)2755*4882a593Smuzhiyun enum ice_fec_mode ice_caps_to_fec_mode(u8 caps, u8 fec_options)
2756*4882a593Smuzhiyun {
2757*4882a593Smuzhiyun if (caps & ICE_AQC_PHY_EN_AUTO_FEC)
2758*4882a593Smuzhiyun return ICE_FEC_AUTO;
2759*4882a593Smuzhiyun
2760*4882a593Smuzhiyun if (fec_options & (ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN |
2761*4882a593Smuzhiyun ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ |
2762*4882a593Smuzhiyun ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN |
2763*4882a593Smuzhiyun ICE_AQC_PHY_FEC_25G_KR_REQ))
2764*4882a593Smuzhiyun return ICE_FEC_BASER;
2765*4882a593Smuzhiyun
2766*4882a593Smuzhiyun if (fec_options & (ICE_AQC_PHY_FEC_25G_RS_528_REQ |
2767*4882a593Smuzhiyun ICE_AQC_PHY_FEC_25G_RS_544_REQ |
2768*4882a593Smuzhiyun ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN))
2769*4882a593Smuzhiyun return ICE_FEC_RS;
2770*4882a593Smuzhiyun
2771*4882a593Smuzhiyun return ICE_FEC_NONE;
2772*4882a593Smuzhiyun }
2773*4882a593Smuzhiyun
2774*4882a593Smuzhiyun /**
2775*4882a593Smuzhiyun * ice_cfg_phy_fc - Configure PHY FC data based on FC mode
2776*4882a593Smuzhiyun * @pi: port information structure
2777*4882a593Smuzhiyun * @cfg: PHY configuration data to set FC mode
2778*4882a593Smuzhiyun * @req_mode: FC mode to configure
2779*4882a593Smuzhiyun */
2780*4882a593Smuzhiyun enum ice_status
ice_cfg_phy_fc(struct ice_port_info * pi,struct ice_aqc_set_phy_cfg_data * cfg,enum ice_fc_mode req_mode)2781*4882a593Smuzhiyun ice_cfg_phy_fc(struct ice_port_info *pi, struct ice_aqc_set_phy_cfg_data *cfg,
2782*4882a593Smuzhiyun enum ice_fc_mode req_mode)
2783*4882a593Smuzhiyun {
2784*4882a593Smuzhiyun struct ice_phy_cache_mode_data cache_data;
2785*4882a593Smuzhiyun u8 pause_mask = 0x0;
2786*4882a593Smuzhiyun
2787*4882a593Smuzhiyun if (!pi || !cfg)
2788*4882a593Smuzhiyun return ICE_ERR_BAD_PTR;
2789*4882a593Smuzhiyun
2790*4882a593Smuzhiyun switch (req_mode) {
2791*4882a593Smuzhiyun case ICE_FC_FULL:
2792*4882a593Smuzhiyun pause_mask |= ICE_AQC_PHY_EN_TX_LINK_PAUSE;
2793*4882a593Smuzhiyun pause_mask |= ICE_AQC_PHY_EN_RX_LINK_PAUSE;
2794*4882a593Smuzhiyun break;
2795*4882a593Smuzhiyun case ICE_FC_RX_PAUSE:
2796*4882a593Smuzhiyun pause_mask |= ICE_AQC_PHY_EN_RX_LINK_PAUSE;
2797*4882a593Smuzhiyun break;
2798*4882a593Smuzhiyun case ICE_FC_TX_PAUSE:
2799*4882a593Smuzhiyun pause_mask |= ICE_AQC_PHY_EN_TX_LINK_PAUSE;
2800*4882a593Smuzhiyun break;
2801*4882a593Smuzhiyun default:
2802*4882a593Smuzhiyun break;
2803*4882a593Smuzhiyun }
2804*4882a593Smuzhiyun
2805*4882a593Smuzhiyun /* clear the old pause settings */
2806*4882a593Smuzhiyun cfg->caps &= ~(ICE_AQC_PHY_EN_TX_LINK_PAUSE |
2807*4882a593Smuzhiyun ICE_AQC_PHY_EN_RX_LINK_PAUSE);
2808*4882a593Smuzhiyun
2809*4882a593Smuzhiyun /* set the new capabilities */
2810*4882a593Smuzhiyun cfg->caps |= pause_mask;
2811*4882a593Smuzhiyun
2812*4882a593Smuzhiyun /* Cache user FC request */
2813*4882a593Smuzhiyun cache_data.data.curr_user_fc_req = req_mode;
2814*4882a593Smuzhiyun ice_cache_phy_user_req(pi, cache_data, ICE_FC_MODE);
2815*4882a593Smuzhiyun
2816*4882a593Smuzhiyun return 0;
2817*4882a593Smuzhiyun }
2818*4882a593Smuzhiyun
2819*4882a593Smuzhiyun /**
2820*4882a593Smuzhiyun * ice_set_fc
2821*4882a593Smuzhiyun * @pi: port information structure
2822*4882a593Smuzhiyun * @aq_failures: pointer to status code, specific to ice_set_fc routine
2823*4882a593Smuzhiyun * @ena_auto_link_update: enable automatic link update
2824*4882a593Smuzhiyun *
2825*4882a593Smuzhiyun * Set the requested flow control mode.
2826*4882a593Smuzhiyun */
2827*4882a593Smuzhiyun enum ice_status
ice_set_fc(struct ice_port_info * pi,u8 * aq_failures,bool ena_auto_link_update)2828*4882a593Smuzhiyun ice_set_fc(struct ice_port_info *pi, u8 *aq_failures, bool ena_auto_link_update)
2829*4882a593Smuzhiyun {
2830*4882a593Smuzhiyun struct ice_aqc_set_phy_cfg_data cfg = { 0 };
2831*4882a593Smuzhiyun struct ice_aqc_get_phy_caps_data *pcaps;
2832*4882a593Smuzhiyun enum ice_status status;
2833*4882a593Smuzhiyun struct ice_hw *hw;
2834*4882a593Smuzhiyun
2835*4882a593Smuzhiyun if (!pi || !aq_failures)
2836*4882a593Smuzhiyun return ICE_ERR_BAD_PTR;
2837*4882a593Smuzhiyun
2838*4882a593Smuzhiyun *aq_failures = 0;
2839*4882a593Smuzhiyun hw = pi->hw;
2840*4882a593Smuzhiyun
2841*4882a593Smuzhiyun pcaps = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*pcaps), GFP_KERNEL);
2842*4882a593Smuzhiyun if (!pcaps)
2843*4882a593Smuzhiyun return ICE_ERR_NO_MEMORY;
2844*4882a593Smuzhiyun
2845*4882a593Smuzhiyun /* Get the current PHY config */
2846*4882a593Smuzhiyun status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG,
2847*4882a593Smuzhiyun pcaps, NULL);
2848*4882a593Smuzhiyun if (status) {
2849*4882a593Smuzhiyun *aq_failures = ICE_SET_FC_AQ_FAIL_GET;
2850*4882a593Smuzhiyun goto out;
2851*4882a593Smuzhiyun }
2852*4882a593Smuzhiyun
2853*4882a593Smuzhiyun ice_copy_phy_caps_to_cfg(pi, pcaps, &cfg);
2854*4882a593Smuzhiyun
2855*4882a593Smuzhiyun /* Configure the set PHY data */
2856*4882a593Smuzhiyun status = ice_cfg_phy_fc(pi, &cfg, pi->fc.req_mode);
2857*4882a593Smuzhiyun if (status)
2858*4882a593Smuzhiyun goto out;
2859*4882a593Smuzhiyun
2860*4882a593Smuzhiyun /* If the capabilities have changed, then set the new config */
2861*4882a593Smuzhiyun if (cfg.caps != pcaps->caps) {
2862*4882a593Smuzhiyun int retry_count, retry_max = 10;
2863*4882a593Smuzhiyun
2864*4882a593Smuzhiyun /* Auto restart link so settings take effect */
2865*4882a593Smuzhiyun if (ena_auto_link_update)
2866*4882a593Smuzhiyun cfg.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2867*4882a593Smuzhiyun
2868*4882a593Smuzhiyun status = ice_aq_set_phy_cfg(hw, pi, &cfg, NULL);
2869*4882a593Smuzhiyun if (status) {
2870*4882a593Smuzhiyun *aq_failures = ICE_SET_FC_AQ_FAIL_SET;
2871*4882a593Smuzhiyun goto out;
2872*4882a593Smuzhiyun }
2873*4882a593Smuzhiyun
2874*4882a593Smuzhiyun /* Update the link info
2875*4882a593Smuzhiyun * It sometimes takes a really long time for link to
2876*4882a593Smuzhiyun * come back from the atomic reset. Thus, we wait a
2877*4882a593Smuzhiyun * little bit.
2878*4882a593Smuzhiyun */
2879*4882a593Smuzhiyun for (retry_count = 0; retry_count < retry_max; retry_count++) {
2880*4882a593Smuzhiyun status = ice_update_link_info(pi);
2881*4882a593Smuzhiyun
2882*4882a593Smuzhiyun if (!status)
2883*4882a593Smuzhiyun break;
2884*4882a593Smuzhiyun
2885*4882a593Smuzhiyun mdelay(100);
2886*4882a593Smuzhiyun }
2887*4882a593Smuzhiyun
2888*4882a593Smuzhiyun if (status)
2889*4882a593Smuzhiyun *aq_failures = ICE_SET_FC_AQ_FAIL_UPDATE;
2890*4882a593Smuzhiyun }
2891*4882a593Smuzhiyun
2892*4882a593Smuzhiyun out:
2893*4882a593Smuzhiyun devm_kfree(ice_hw_to_dev(hw), pcaps);
2894*4882a593Smuzhiyun return status;
2895*4882a593Smuzhiyun }
2896*4882a593Smuzhiyun
2897*4882a593Smuzhiyun /**
2898*4882a593Smuzhiyun * ice_phy_caps_equals_cfg
2899*4882a593Smuzhiyun * @phy_caps: PHY capabilities
2900*4882a593Smuzhiyun * @phy_cfg: PHY configuration
2901*4882a593Smuzhiyun *
2902*4882a593Smuzhiyun * Helper function to determine if PHY capabilities matches PHY
2903*4882a593Smuzhiyun * configuration
2904*4882a593Smuzhiyun */
2905*4882a593Smuzhiyun bool
ice_phy_caps_equals_cfg(struct ice_aqc_get_phy_caps_data * phy_caps,struct ice_aqc_set_phy_cfg_data * phy_cfg)2906*4882a593Smuzhiyun ice_phy_caps_equals_cfg(struct ice_aqc_get_phy_caps_data *phy_caps,
2907*4882a593Smuzhiyun struct ice_aqc_set_phy_cfg_data *phy_cfg)
2908*4882a593Smuzhiyun {
2909*4882a593Smuzhiyun u8 caps_mask, cfg_mask;
2910*4882a593Smuzhiyun
2911*4882a593Smuzhiyun if (!phy_caps || !phy_cfg)
2912*4882a593Smuzhiyun return false;
2913*4882a593Smuzhiyun
2914*4882a593Smuzhiyun /* These bits are not common between capabilities and configuration.
2915*4882a593Smuzhiyun * Do not use them to determine equality.
2916*4882a593Smuzhiyun */
2917*4882a593Smuzhiyun caps_mask = ICE_AQC_PHY_CAPS_MASK & ~(ICE_AQC_PHY_AN_MODE |
2918*4882a593Smuzhiyun ICE_AQC_GET_PHY_EN_MOD_QUAL);
2919*4882a593Smuzhiyun cfg_mask = ICE_AQ_PHY_ENA_VALID_MASK & ~ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2920*4882a593Smuzhiyun
2921*4882a593Smuzhiyun if (phy_caps->phy_type_low != phy_cfg->phy_type_low ||
2922*4882a593Smuzhiyun phy_caps->phy_type_high != phy_cfg->phy_type_high ||
2923*4882a593Smuzhiyun ((phy_caps->caps & caps_mask) != (phy_cfg->caps & cfg_mask)) ||
2924*4882a593Smuzhiyun phy_caps->low_power_ctrl_an != phy_cfg->low_power_ctrl_an ||
2925*4882a593Smuzhiyun phy_caps->eee_cap != phy_cfg->eee_cap ||
2926*4882a593Smuzhiyun phy_caps->eeer_value != phy_cfg->eeer_value ||
2927*4882a593Smuzhiyun phy_caps->link_fec_options != phy_cfg->link_fec_opt)
2928*4882a593Smuzhiyun return false;
2929*4882a593Smuzhiyun
2930*4882a593Smuzhiyun return true;
2931*4882a593Smuzhiyun }
2932*4882a593Smuzhiyun
2933*4882a593Smuzhiyun /**
2934*4882a593Smuzhiyun * ice_copy_phy_caps_to_cfg - Copy PHY ability data to configuration data
2935*4882a593Smuzhiyun * @pi: port information structure
2936*4882a593Smuzhiyun * @caps: PHY ability structure to copy date from
2937*4882a593Smuzhiyun * @cfg: PHY configuration structure to copy data to
2938*4882a593Smuzhiyun *
2939*4882a593Smuzhiyun * Helper function to copy AQC PHY get ability data to PHY set configuration
2940*4882a593Smuzhiyun * data structure
2941*4882a593Smuzhiyun */
2942*4882a593Smuzhiyun void
ice_copy_phy_caps_to_cfg(struct ice_port_info * pi,struct ice_aqc_get_phy_caps_data * caps,struct ice_aqc_set_phy_cfg_data * cfg)2943*4882a593Smuzhiyun ice_copy_phy_caps_to_cfg(struct ice_port_info *pi,
2944*4882a593Smuzhiyun struct ice_aqc_get_phy_caps_data *caps,
2945*4882a593Smuzhiyun struct ice_aqc_set_phy_cfg_data *cfg)
2946*4882a593Smuzhiyun {
2947*4882a593Smuzhiyun if (!pi || !caps || !cfg)
2948*4882a593Smuzhiyun return;
2949*4882a593Smuzhiyun
2950*4882a593Smuzhiyun memset(cfg, 0, sizeof(*cfg));
2951*4882a593Smuzhiyun cfg->phy_type_low = caps->phy_type_low;
2952*4882a593Smuzhiyun cfg->phy_type_high = caps->phy_type_high;
2953*4882a593Smuzhiyun cfg->caps = caps->caps;
2954*4882a593Smuzhiyun cfg->low_power_ctrl_an = caps->low_power_ctrl_an;
2955*4882a593Smuzhiyun cfg->eee_cap = caps->eee_cap;
2956*4882a593Smuzhiyun cfg->eeer_value = caps->eeer_value;
2957*4882a593Smuzhiyun cfg->link_fec_opt = caps->link_fec_options;
2958*4882a593Smuzhiyun cfg->module_compliance_enforcement =
2959*4882a593Smuzhiyun caps->module_compliance_enforcement;
2960*4882a593Smuzhiyun
2961*4882a593Smuzhiyun if (ice_fw_supports_link_override(pi->hw)) {
2962*4882a593Smuzhiyun struct ice_link_default_override_tlv tlv;
2963*4882a593Smuzhiyun
2964*4882a593Smuzhiyun if (ice_get_link_default_override(&tlv, pi))
2965*4882a593Smuzhiyun return;
2966*4882a593Smuzhiyun
2967*4882a593Smuzhiyun if (tlv.options & ICE_LINK_OVERRIDE_STRICT_MODE)
2968*4882a593Smuzhiyun cfg->module_compliance_enforcement |=
2969*4882a593Smuzhiyun ICE_LINK_OVERRIDE_STRICT_MODE;
2970*4882a593Smuzhiyun }
2971*4882a593Smuzhiyun }
2972*4882a593Smuzhiyun
2973*4882a593Smuzhiyun /**
2974*4882a593Smuzhiyun * ice_cfg_phy_fec - Configure PHY FEC data based on FEC mode
2975*4882a593Smuzhiyun * @pi: port information structure
2976*4882a593Smuzhiyun * @cfg: PHY configuration data to set FEC mode
2977*4882a593Smuzhiyun * @fec: FEC mode to configure
2978*4882a593Smuzhiyun */
2979*4882a593Smuzhiyun enum ice_status
ice_cfg_phy_fec(struct ice_port_info * pi,struct ice_aqc_set_phy_cfg_data * cfg,enum ice_fec_mode fec)2980*4882a593Smuzhiyun ice_cfg_phy_fec(struct ice_port_info *pi, struct ice_aqc_set_phy_cfg_data *cfg,
2981*4882a593Smuzhiyun enum ice_fec_mode fec)
2982*4882a593Smuzhiyun {
2983*4882a593Smuzhiyun struct ice_aqc_get_phy_caps_data *pcaps;
2984*4882a593Smuzhiyun enum ice_status status;
2985*4882a593Smuzhiyun
2986*4882a593Smuzhiyun if (!pi || !cfg)
2987*4882a593Smuzhiyun return ICE_ERR_BAD_PTR;
2988*4882a593Smuzhiyun
2989*4882a593Smuzhiyun pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
2990*4882a593Smuzhiyun if (!pcaps)
2991*4882a593Smuzhiyun return ICE_ERR_NO_MEMORY;
2992*4882a593Smuzhiyun
2993*4882a593Smuzhiyun status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA, pcaps,
2994*4882a593Smuzhiyun NULL);
2995*4882a593Smuzhiyun if (status)
2996*4882a593Smuzhiyun goto out;
2997*4882a593Smuzhiyun
2998*4882a593Smuzhiyun cfg->caps |= pcaps->caps & ICE_AQC_PHY_EN_AUTO_FEC;
2999*4882a593Smuzhiyun cfg->link_fec_opt = pcaps->link_fec_options;
3000*4882a593Smuzhiyun
3001*4882a593Smuzhiyun switch (fec) {
3002*4882a593Smuzhiyun case ICE_FEC_BASER:
3003*4882a593Smuzhiyun /* Clear RS bits, and AND BASE-R ability
3004*4882a593Smuzhiyun * bits and OR request bits.
3005*4882a593Smuzhiyun */
3006*4882a593Smuzhiyun cfg->link_fec_opt &= ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN |
3007*4882a593Smuzhiyun ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN;
3008*4882a593Smuzhiyun cfg->link_fec_opt |= ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ |
3009*4882a593Smuzhiyun ICE_AQC_PHY_FEC_25G_KR_REQ;
3010*4882a593Smuzhiyun break;
3011*4882a593Smuzhiyun case ICE_FEC_RS:
3012*4882a593Smuzhiyun /* Clear BASE-R bits, and AND RS ability
3013*4882a593Smuzhiyun * bits and OR request bits.
3014*4882a593Smuzhiyun */
3015*4882a593Smuzhiyun cfg->link_fec_opt &= ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN;
3016*4882a593Smuzhiyun cfg->link_fec_opt |= ICE_AQC_PHY_FEC_25G_RS_528_REQ |
3017*4882a593Smuzhiyun ICE_AQC_PHY_FEC_25G_RS_544_REQ;
3018*4882a593Smuzhiyun break;
3019*4882a593Smuzhiyun case ICE_FEC_NONE:
3020*4882a593Smuzhiyun /* Clear all FEC option bits. */
3021*4882a593Smuzhiyun cfg->link_fec_opt &= ~ICE_AQC_PHY_FEC_MASK;
3022*4882a593Smuzhiyun break;
3023*4882a593Smuzhiyun case ICE_FEC_AUTO:
3024*4882a593Smuzhiyun /* AND auto FEC bit, and all caps bits. */
3025*4882a593Smuzhiyun cfg->caps &= ICE_AQC_PHY_CAPS_MASK;
3026*4882a593Smuzhiyun cfg->link_fec_opt |= pcaps->link_fec_options;
3027*4882a593Smuzhiyun break;
3028*4882a593Smuzhiyun default:
3029*4882a593Smuzhiyun status = ICE_ERR_PARAM;
3030*4882a593Smuzhiyun break;
3031*4882a593Smuzhiyun }
3032*4882a593Smuzhiyun
3033*4882a593Smuzhiyun if (fec == ICE_FEC_AUTO && ice_fw_supports_link_override(pi->hw)) {
3034*4882a593Smuzhiyun struct ice_link_default_override_tlv tlv;
3035*4882a593Smuzhiyun
3036*4882a593Smuzhiyun status = ice_get_link_default_override(&tlv, pi);
3037*4882a593Smuzhiyun if (status)
3038*4882a593Smuzhiyun goto out;
3039*4882a593Smuzhiyun
3040*4882a593Smuzhiyun if (!(tlv.options & ICE_LINK_OVERRIDE_STRICT_MODE) &&
3041*4882a593Smuzhiyun (tlv.options & ICE_LINK_OVERRIDE_EN))
3042*4882a593Smuzhiyun cfg->link_fec_opt = tlv.fec_options;
3043*4882a593Smuzhiyun }
3044*4882a593Smuzhiyun
3045*4882a593Smuzhiyun out:
3046*4882a593Smuzhiyun kfree(pcaps);
3047*4882a593Smuzhiyun
3048*4882a593Smuzhiyun return status;
3049*4882a593Smuzhiyun }
3050*4882a593Smuzhiyun
3051*4882a593Smuzhiyun /**
3052*4882a593Smuzhiyun * ice_get_link_status - get status of the HW network link
3053*4882a593Smuzhiyun * @pi: port information structure
3054*4882a593Smuzhiyun * @link_up: pointer to bool (true/false = linkup/linkdown)
3055*4882a593Smuzhiyun *
3056*4882a593Smuzhiyun * Variable link_up is true if link is up, false if link is down.
3057*4882a593Smuzhiyun * The variable link_up is invalid if status is non zero. As a
3058*4882a593Smuzhiyun * result of this call, link status reporting becomes enabled
3059*4882a593Smuzhiyun */
ice_get_link_status(struct ice_port_info * pi,bool * link_up)3060*4882a593Smuzhiyun enum ice_status ice_get_link_status(struct ice_port_info *pi, bool *link_up)
3061*4882a593Smuzhiyun {
3062*4882a593Smuzhiyun struct ice_phy_info *phy_info;
3063*4882a593Smuzhiyun enum ice_status status = 0;
3064*4882a593Smuzhiyun
3065*4882a593Smuzhiyun if (!pi || !link_up)
3066*4882a593Smuzhiyun return ICE_ERR_PARAM;
3067*4882a593Smuzhiyun
3068*4882a593Smuzhiyun phy_info = &pi->phy;
3069*4882a593Smuzhiyun
3070*4882a593Smuzhiyun if (phy_info->get_link_info) {
3071*4882a593Smuzhiyun status = ice_update_link_info(pi);
3072*4882a593Smuzhiyun
3073*4882a593Smuzhiyun if (status)
3074*4882a593Smuzhiyun ice_debug(pi->hw, ICE_DBG_LINK,
3075*4882a593Smuzhiyun "get link status error, status = %d\n",
3076*4882a593Smuzhiyun status);
3077*4882a593Smuzhiyun }
3078*4882a593Smuzhiyun
3079*4882a593Smuzhiyun *link_up = phy_info->link_info.link_info & ICE_AQ_LINK_UP;
3080*4882a593Smuzhiyun
3081*4882a593Smuzhiyun return status;
3082*4882a593Smuzhiyun }
3083*4882a593Smuzhiyun
3084*4882a593Smuzhiyun /**
3085*4882a593Smuzhiyun * ice_aq_set_link_restart_an
3086*4882a593Smuzhiyun * @pi: pointer to the port information structure
3087*4882a593Smuzhiyun * @ena_link: if true: enable link, if false: disable link
3088*4882a593Smuzhiyun * @cd: pointer to command details structure or NULL
3089*4882a593Smuzhiyun *
3090*4882a593Smuzhiyun * Sets up the link and restarts the Auto-Negotiation over the link.
3091*4882a593Smuzhiyun */
3092*4882a593Smuzhiyun enum ice_status
ice_aq_set_link_restart_an(struct ice_port_info * pi,bool ena_link,struct ice_sq_cd * cd)3093*4882a593Smuzhiyun ice_aq_set_link_restart_an(struct ice_port_info *pi, bool ena_link,
3094*4882a593Smuzhiyun struct ice_sq_cd *cd)
3095*4882a593Smuzhiyun {
3096*4882a593Smuzhiyun struct ice_aqc_restart_an *cmd;
3097*4882a593Smuzhiyun struct ice_aq_desc desc;
3098*4882a593Smuzhiyun
3099*4882a593Smuzhiyun cmd = &desc.params.restart_an;
3100*4882a593Smuzhiyun
3101*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_restart_an);
3102*4882a593Smuzhiyun
3103*4882a593Smuzhiyun cmd->cmd_flags = ICE_AQC_RESTART_AN_LINK_RESTART;
3104*4882a593Smuzhiyun cmd->lport_num = pi->lport;
3105*4882a593Smuzhiyun if (ena_link)
3106*4882a593Smuzhiyun cmd->cmd_flags |= ICE_AQC_RESTART_AN_LINK_ENABLE;
3107*4882a593Smuzhiyun else
3108*4882a593Smuzhiyun cmd->cmd_flags &= ~ICE_AQC_RESTART_AN_LINK_ENABLE;
3109*4882a593Smuzhiyun
3110*4882a593Smuzhiyun return ice_aq_send_cmd(pi->hw, &desc, NULL, 0, cd);
3111*4882a593Smuzhiyun }
3112*4882a593Smuzhiyun
3113*4882a593Smuzhiyun /**
3114*4882a593Smuzhiyun * ice_aq_set_event_mask
3115*4882a593Smuzhiyun * @hw: pointer to the HW struct
3116*4882a593Smuzhiyun * @port_num: port number of the physical function
3117*4882a593Smuzhiyun * @mask: event mask to be set
3118*4882a593Smuzhiyun * @cd: pointer to command details structure or NULL
3119*4882a593Smuzhiyun *
3120*4882a593Smuzhiyun * Set event mask (0x0613)
3121*4882a593Smuzhiyun */
3122*4882a593Smuzhiyun enum ice_status
ice_aq_set_event_mask(struct ice_hw * hw,u8 port_num,u16 mask,struct ice_sq_cd * cd)3123*4882a593Smuzhiyun ice_aq_set_event_mask(struct ice_hw *hw, u8 port_num, u16 mask,
3124*4882a593Smuzhiyun struct ice_sq_cd *cd)
3125*4882a593Smuzhiyun {
3126*4882a593Smuzhiyun struct ice_aqc_set_event_mask *cmd;
3127*4882a593Smuzhiyun struct ice_aq_desc desc;
3128*4882a593Smuzhiyun
3129*4882a593Smuzhiyun cmd = &desc.params.set_event_mask;
3130*4882a593Smuzhiyun
3131*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_event_mask);
3132*4882a593Smuzhiyun
3133*4882a593Smuzhiyun cmd->lport_num = port_num;
3134*4882a593Smuzhiyun
3135*4882a593Smuzhiyun cmd->event_mask = cpu_to_le16(mask);
3136*4882a593Smuzhiyun return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
3137*4882a593Smuzhiyun }
3138*4882a593Smuzhiyun
3139*4882a593Smuzhiyun /**
3140*4882a593Smuzhiyun * ice_aq_set_mac_loopback
3141*4882a593Smuzhiyun * @hw: pointer to the HW struct
3142*4882a593Smuzhiyun * @ena_lpbk: Enable or Disable loopback
3143*4882a593Smuzhiyun * @cd: pointer to command details structure or NULL
3144*4882a593Smuzhiyun *
3145*4882a593Smuzhiyun * Enable/disable loopback on a given port
3146*4882a593Smuzhiyun */
3147*4882a593Smuzhiyun enum ice_status
ice_aq_set_mac_loopback(struct ice_hw * hw,bool ena_lpbk,struct ice_sq_cd * cd)3148*4882a593Smuzhiyun ice_aq_set_mac_loopback(struct ice_hw *hw, bool ena_lpbk, struct ice_sq_cd *cd)
3149*4882a593Smuzhiyun {
3150*4882a593Smuzhiyun struct ice_aqc_set_mac_lb *cmd;
3151*4882a593Smuzhiyun struct ice_aq_desc desc;
3152*4882a593Smuzhiyun
3153*4882a593Smuzhiyun cmd = &desc.params.set_mac_lb;
3154*4882a593Smuzhiyun
3155*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_mac_lb);
3156*4882a593Smuzhiyun if (ena_lpbk)
3157*4882a593Smuzhiyun cmd->lb_mode = ICE_AQ_MAC_LB_EN;
3158*4882a593Smuzhiyun
3159*4882a593Smuzhiyun return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
3160*4882a593Smuzhiyun }
3161*4882a593Smuzhiyun
3162*4882a593Smuzhiyun /**
3163*4882a593Smuzhiyun * ice_aq_set_port_id_led
3164*4882a593Smuzhiyun * @pi: pointer to the port information
3165*4882a593Smuzhiyun * @is_orig_mode: is this LED set to original mode (by the net-list)
3166*4882a593Smuzhiyun * @cd: pointer to command details structure or NULL
3167*4882a593Smuzhiyun *
3168*4882a593Smuzhiyun * Set LED value for the given port (0x06e9)
3169*4882a593Smuzhiyun */
3170*4882a593Smuzhiyun enum ice_status
ice_aq_set_port_id_led(struct ice_port_info * pi,bool is_orig_mode,struct ice_sq_cd * cd)3171*4882a593Smuzhiyun ice_aq_set_port_id_led(struct ice_port_info *pi, bool is_orig_mode,
3172*4882a593Smuzhiyun struct ice_sq_cd *cd)
3173*4882a593Smuzhiyun {
3174*4882a593Smuzhiyun struct ice_aqc_set_port_id_led *cmd;
3175*4882a593Smuzhiyun struct ice_hw *hw = pi->hw;
3176*4882a593Smuzhiyun struct ice_aq_desc desc;
3177*4882a593Smuzhiyun
3178*4882a593Smuzhiyun cmd = &desc.params.set_port_id_led;
3179*4882a593Smuzhiyun
3180*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_port_id_led);
3181*4882a593Smuzhiyun
3182*4882a593Smuzhiyun if (is_orig_mode)
3183*4882a593Smuzhiyun cmd->ident_mode = ICE_AQC_PORT_IDENT_LED_ORIG;
3184*4882a593Smuzhiyun else
3185*4882a593Smuzhiyun cmd->ident_mode = ICE_AQC_PORT_IDENT_LED_BLINK;
3186*4882a593Smuzhiyun
3187*4882a593Smuzhiyun return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
3188*4882a593Smuzhiyun }
3189*4882a593Smuzhiyun
3190*4882a593Smuzhiyun /**
3191*4882a593Smuzhiyun * ice_aq_sff_eeprom
3192*4882a593Smuzhiyun * @hw: pointer to the HW struct
3193*4882a593Smuzhiyun * @lport: bits [7:0] = logical port, bit [8] = logical port valid
3194*4882a593Smuzhiyun * @bus_addr: I2C bus address of the eeprom (typically 0xA0, 0=topo default)
3195*4882a593Smuzhiyun * @mem_addr: I2C offset. lower 8 bits for address, 8 upper bits zero padding.
3196*4882a593Smuzhiyun * @page: QSFP page
3197*4882a593Smuzhiyun * @set_page: set or ignore the page
3198*4882a593Smuzhiyun * @data: pointer to data buffer to be read/written to the I2C device.
3199*4882a593Smuzhiyun * @length: 1-16 for read, 1 for write.
3200*4882a593Smuzhiyun * @write: 0 read, 1 for write.
3201*4882a593Smuzhiyun * @cd: pointer to command details structure or NULL
3202*4882a593Smuzhiyun *
3203*4882a593Smuzhiyun * Read/Write SFF EEPROM (0x06EE)
3204*4882a593Smuzhiyun */
3205*4882a593Smuzhiyun enum ice_status
ice_aq_sff_eeprom(struct ice_hw * hw,u16 lport,u8 bus_addr,u16 mem_addr,u8 page,u8 set_page,u8 * data,u8 length,bool write,struct ice_sq_cd * cd)3206*4882a593Smuzhiyun ice_aq_sff_eeprom(struct ice_hw *hw, u16 lport, u8 bus_addr,
3207*4882a593Smuzhiyun u16 mem_addr, u8 page, u8 set_page, u8 *data, u8 length,
3208*4882a593Smuzhiyun bool write, struct ice_sq_cd *cd)
3209*4882a593Smuzhiyun {
3210*4882a593Smuzhiyun struct ice_aqc_sff_eeprom *cmd;
3211*4882a593Smuzhiyun struct ice_aq_desc desc;
3212*4882a593Smuzhiyun enum ice_status status;
3213*4882a593Smuzhiyun
3214*4882a593Smuzhiyun if (!data || (mem_addr & 0xff00))
3215*4882a593Smuzhiyun return ICE_ERR_PARAM;
3216*4882a593Smuzhiyun
3217*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_sff_eeprom);
3218*4882a593Smuzhiyun cmd = &desc.params.read_write_sff_param;
3219*4882a593Smuzhiyun desc.flags = cpu_to_le16(ICE_AQ_FLAG_RD | ICE_AQ_FLAG_BUF);
3220*4882a593Smuzhiyun cmd->lport_num = (u8)(lport & 0xff);
3221*4882a593Smuzhiyun cmd->lport_num_valid = (u8)((lport >> 8) & 0x01);
3222*4882a593Smuzhiyun cmd->i2c_bus_addr = cpu_to_le16(((bus_addr >> 1) &
3223*4882a593Smuzhiyun ICE_AQC_SFF_I2CBUS_7BIT_M) |
3224*4882a593Smuzhiyun ((set_page <<
3225*4882a593Smuzhiyun ICE_AQC_SFF_SET_EEPROM_PAGE_S) &
3226*4882a593Smuzhiyun ICE_AQC_SFF_SET_EEPROM_PAGE_M));
3227*4882a593Smuzhiyun cmd->i2c_mem_addr = cpu_to_le16(mem_addr & 0xff);
3228*4882a593Smuzhiyun cmd->eeprom_page = cpu_to_le16((u16)page << ICE_AQC_SFF_EEPROM_PAGE_S);
3229*4882a593Smuzhiyun if (write)
3230*4882a593Smuzhiyun cmd->i2c_bus_addr |= cpu_to_le16(ICE_AQC_SFF_IS_WRITE);
3231*4882a593Smuzhiyun
3232*4882a593Smuzhiyun status = ice_aq_send_cmd(hw, &desc, data, length, cd);
3233*4882a593Smuzhiyun return status;
3234*4882a593Smuzhiyun }
3235*4882a593Smuzhiyun
3236*4882a593Smuzhiyun /**
3237*4882a593Smuzhiyun * __ice_aq_get_set_rss_lut
3238*4882a593Smuzhiyun * @hw: pointer to the hardware structure
3239*4882a593Smuzhiyun * @vsi_id: VSI FW index
3240*4882a593Smuzhiyun * @lut_type: LUT table type
3241*4882a593Smuzhiyun * @lut: pointer to the LUT buffer provided by the caller
3242*4882a593Smuzhiyun * @lut_size: size of the LUT buffer
3243*4882a593Smuzhiyun * @glob_lut_idx: global LUT index
3244*4882a593Smuzhiyun * @set: set true to set the table, false to get the table
3245*4882a593Smuzhiyun *
3246*4882a593Smuzhiyun * Internal function to get (0x0B05) or set (0x0B03) RSS look up table
3247*4882a593Smuzhiyun */
3248*4882a593Smuzhiyun static enum ice_status
__ice_aq_get_set_rss_lut(struct ice_hw * hw,u16 vsi_id,u8 lut_type,u8 * lut,u16 lut_size,u8 glob_lut_idx,bool set)3249*4882a593Smuzhiyun __ice_aq_get_set_rss_lut(struct ice_hw *hw, u16 vsi_id, u8 lut_type, u8 *lut,
3250*4882a593Smuzhiyun u16 lut_size, u8 glob_lut_idx, bool set)
3251*4882a593Smuzhiyun {
3252*4882a593Smuzhiyun struct ice_aqc_get_set_rss_lut *cmd_resp;
3253*4882a593Smuzhiyun struct ice_aq_desc desc;
3254*4882a593Smuzhiyun enum ice_status status;
3255*4882a593Smuzhiyun u16 flags = 0;
3256*4882a593Smuzhiyun
3257*4882a593Smuzhiyun cmd_resp = &desc.params.get_set_rss_lut;
3258*4882a593Smuzhiyun
3259*4882a593Smuzhiyun if (set) {
3260*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_rss_lut);
3261*4882a593Smuzhiyun desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
3262*4882a593Smuzhiyun } else {
3263*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_rss_lut);
3264*4882a593Smuzhiyun }
3265*4882a593Smuzhiyun
3266*4882a593Smuzhiyun cmd_resp->vsi_id = cpu_to_le16(((vsi_id <<
3267*4882a593Smuzhiyun ICE_AQC_GSET_RSS_LUT_VSI_ID_S) &
3268*4882a593Smuzhiyun ICE_AQC_GSET_RSS_LUT_VSI_ID_M) |
3269*4882a593Smuzhiyun ICE_AQC_GSET_RSS_LUT_VSI_VALID);
3270*4882a593Smuzhiyun
3271*4882a593Smuzhiyun switch (lut_type) {
3272*4882a593Smuzhiyun case ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_VSI:
3273*4882a593Smuzhiyun case ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF:
3274*4882a593Smuzhiyun case ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_GLOBAL:
3275*4882a593Smuzhiyun flags |= ((lut_type << ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_S) &
3276*4882a593Smuzhiyun ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_M);
3277*4882a593Smuzhiyun break;
3278*4882a593Smuzhiyun default:
3279*4882a593Smuzhiyun status = ICE_ERR_PARAM;
3280*4882a593Smuzhiyun goto ice_aq_get_set_rss_lut_exit;
3281*4882a593Smuzhiyun }
3282*4882a593Smuzhiyun
3283*4882a593Smuzhiyun if (lut_type == ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_GLOBAL) {
3284*4882a593Smuzhiyun flags |= ((glob_lut_idx << ICE_AQC_GSET_RSS_LUT_GLOBAL_IDX_S) &
3285*4882a593Smuzhiyun ICE_AQC_GSET_RSS_LUT_GLOBAL_IDX_M);
3286*4882a593Smuzhiyun
3287*4882a593Smuzhiyun if (!set)
3288*4882a593Smuzhiyun goto ice_aq_get_set_rss_lut_send;
3289*4882a593Smuzhiyun } else if (lut_type == ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF) {
3290*4882a593Smuzhiyun if (!set)
3291*4882a593Smuzhiyun goto ice_aq_get_set_rss_lut_send;
3292*4882a593Smuzhiyun } else {
3293*4882a593Smuzhiyun goto ice_aq_get_set_rss_lut_send;
3294*4882a593Smuzhiyun }
3295*4882a593Smuzhiyun
3296*4882a593Smuzhiyun /* LUT size is only valid for Global and PF table types */
3297*4882a593Smuzhiyun switch (lut_size) {
3298*4882a593Smuzhiyun case ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_128:
3299*4882a593Smuzhiyun break;
3300*4882a593Smuzhiyun case ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_512:
3301*4882a593Smuzhiyun flags |= (ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_512_FLAG <<
3302*4882a593Smuzhiyun ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_S) &
3303*4882a593Smuzhiyun ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_M;
3304*4882a593Smuzhiyun break;
3305*4882a593Smuzhiyun case ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K:
3306*4882a593Smuzhiyun if (lut_type == ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF) {
3307*4882a593Smuzhiyun flags |= (ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K_FLAG <<
3308*4882a593Smuzhiyun ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_S) &
3309*4882a593Smuzhiyun ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_M;
3310*4882a593Smuzhiyun break;
3311*4882a593Smuzhiyun }
3312*4882a593Smuzhiyun fallthrough;
3313*4882a593Smuzhiyun default:
3314*4882a593Smuzhiyun status = ICE_ERR_PARAM;
3315*4882a593Smuzhiyun goto ice_aq_get_set_rss_lut_exit;
3316*4882a593Smuzhiyun }
3317*4882a593Smuzhiyun
3318*4882a593Smuzhiyun ice_aq_get_set_rss_lut_send:
3319*4882a593Smuzhiyun cmd_resp->flags = cpu_to_le16(flags);
3320*4882a593Smuzhiyun status = ice_aq_send_cmd(hw, &desc, lut, lut_size, NULL);
3321*4882a593Smuzhiyun
3322*4882a593Smuzhiyun ice_aq_get_set_rss_lut_exit:
3323*4882a593Smuzhiyun return status;
3324*4882a593Smuzhiyun }
3325*4882a593Smuzhiyun
3326*4882a593Smuzhiyun /**
3327*4882a593Smuzhiyun * ice_aq_get_rss_lut
3328*4882a593Smuzhiyun * @hw: pointer to the hardware structure
3329*4882a593Smuzhiyun * @vsi_handle: software VSI handle
3330*4882a593Smuzhiyun * @lut_type: LUT table type
3331*4882a593Smuzhiyun * @lut: pointer to the LUT buffer provided by the caller
3332*4882a593Smuzhiyun * @lut_size: size of the LUT buffer
3333*4882a593Smuzhiyun *
3334*4882a593Smuzhiyun * get the RSS lookup table, PF or VSI type
3335*4882a593Smuzhiyun */
3336*4882a593Smuzhiyun enum ice_status
ice_aq_get_rss_lut(struct ice_hw * hw,u16 vsi_handle,u8 lut_type,u8 * lut,u16 lut_size)3337*4882a593Smuzhiyun ice_aq_get_rss_lut(struct ice_hw *hw, u16 vsi_handle, u8 lut_type,
3338*4882a593Smuzhiyun u8 *lut, u16 lut_size)
3339*4882a593Smuzhiyun {
3340*4882a593Smuzhiyun if (!ice_is_vsi_valid(hw, vsi_handle) || !lut)
3341*4882a593Smuzhiyun return ICE_ERR_PARAM;
3342*4882a593Smuzhiyun
3343*4882a593Smuzhiyun return __ice_aq_get_set_rss_lut(hw, ice_get_hw_vsi_num(hw, vsi_handle),
3344*4882a593Smuzhiyun lut_type, lut, lut_size, 0, false);
3345*4882a593Smuzhiyun }
3346*4882a593Smuzhiyun
3347*4882a593Smuzhiyun /**
3348*4882a593Smuzhiyun * ice_aq_set_rss_lut
3349*4882a593Smuzhiyun * @hw: pointer to the hardware structure
3350*4882a593Smuzhiyun * @vsi_handle: software VSI handle
3351*4882a593Smuzhiyun * @lut_type: LUT table type
3352*4882a593Smuzhiyun * @lut: pointer to the LUT buffer provided by the caller
3353*4882a593Smuzhiyun * @lut_size: size of the LUT buffer
3354*4882a593Smuzhiyun *
3355*4882a593Smuzhiyun * set the RSS lookup table, PF or VSI type
3356*4882a593Smuzhiyun */
3357*4882a593Smuzhiyun enum ice_status
ice_aq_set_rss_lut(struct ice_hw * hw,u16 vsi_handle,u8 lut_type,u8 * lut,u16 lut_size)3358*4882a593Smuzhiyun ice_aq_set_rss_lut(struct ice_hw *hw, u16 vsi_handle, u8 lut_type,
3359*4882a593Smuzhiyun u8 *lut, u16 lut_size)
3360*4882a593Smuzhiyun {
3361*4882a593Smuzhiyun if (!ice_is_vsi_valid(hw, vsi_handle) || !lut)
3362*4882a593Smuzhiyun return ICE_ERR_PARAM;
3363*4882a593Smuzhiyun
3364*4882a593Smuzhiyun return __ice_aq_get_set_rss_lut(hw, ice_get_hw_vsi_num(hw, vsi_handle),
3365*4882a593Smuzhiyun lut_type, lut, lut_size, 0, true);
3366*4882a593Smuzhiyun }
3367*4882a593Smuzhiyun
3368*4882a593Smuzhiyun /**
3369*4882a593Smuzhiyun * __ice_aq_get_set_rss_key
3370*4882a593Smuzhiyun * @hw: pointer to the HW struct
3371*4882a593Smuzhiyun * @vsi_id: VSI FW index
3372*4882a593Smuzhiyun * @key: pointer to key info struct
3373*4882a593Smuzhiyun * @set: set true to set the key, false to get the key
3374*4882a593Smuzhiyun *
3375*4882a593Smuzhiyun * get (0x0B04) or set (0x0B02) the RSS key per VSI
3376*4882a593Smuzhiyun */
3377*4882a593Smuzhiyun static enum
__ice_aq_get_set_rss_key(struct ice_hw * hw,u16 vsi_id,struct ice_aqc_get_set_rss_keys * key,bool set)3378*4882a593Smuzhiyun ice_status __ice_aq_get_set_rss_key(struct ice_hw *hw, u16 vsi_id,
3379*4882a593Smuzhiyun struct ice_aqc_get_set_rss_keys *key,
3380*4882a593Smuzhiyun bool set)
3381*4882a593Smuzhiyun {
3382*4882a593Smuzhiyun struct ice_aqc_get_set_rss_key *cmd_resp;
3383*4882a593Smuzhiyun u16 key_size = sizeof(*key);
3384*4882a593Smuzhiyun struct ice_aq_desc desc;
3385*4882a593Smuzhiyun
3386*4882a593Smuzhiyun cmd_resp = &desc.params.get_set_rss_key;
3387*4882a593Smuzhiyun
3388*4882a593Smuzhiyun if (set) {
3389*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_rss_key);
3390*4882a593Smuzhiyun desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
3391*4882a593Smuzhiyun } else {
3392*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_rss_key);
3393*4882a593Smuzhiyun }
3394*4882a593Smuzhiyun
3395*4882a593Smuzhiyun cmd_resp->vsi_id = cpu_to_le16(((vsi_id <<
3396*4882a593Smuzhiyun ICE_AQC_GSET_RSS_KEY_VSI_ID_S) &
3397*4882a593Smuzhiyun ICE_AQC_GSET_RSS_KEY_VSI_ID_M) |
3398*4882a593Smuzhiyun ICE_AQC_GSET_RSS_KEY_VSI_VALID);
3399*4882a593Smuzhiyun
3400*4882a593Smuzhiyun return ice_aq_send_cmd(hw, &desc, key, key_size, NULL);
3401*4882a593Smuzhiyun }
3402*4882a593Smuzhiyun
3403*4882a593Smuzhiyun /**
3404*4882a593Smuzhiyun * ice_aq_get_rss_key
3405*4882a593Smuzhiyun * @hw: pointer to the HW struct
3406*4882a593Smuzhiyun * @vsi_handle: software VSI handle
3407*4882a593Smuzhiyun * @key: pointer to key info struct
3408*4882a593Smuzhiyun *
3409*4882a593Smuzhiyun * get the RSS key per VSI
3410*4882a593Smuzhiyun */
3411*4882a593Smuzhiyun enum ice_status
ice_aq_get_rss_key(struct ice_hw * hw,u16 vsi_handle,struct ice_aqc_get_set_rss_keys * key)3412*4882a593Smuzhiyun ice_aq_get_rss_key(struct ice_hw *hw, u16 vsi_handle,
3413*4882a593Smuzhiyun struct ice_aqc_get_set_rss_keys *key)
3414*4882a593Smuzhiyun {
3415*4882a593Smuzhiyun if (!ice_is_vsi_valid(hw, vsi_handle) || !key)
3416*4882a593Smuzhiyun return ICE_ERR_PARAM;
3417*4882a593Smuzhiyun
3418*4882a593Smuzhiyun return __ice_aq_get_set_rss_key(hw, ice_get_hw_vsi_num(hw, vsi_handle),
3419*4882a593Smuzhiyun key, false);
3420*4882a593Smuzhiyun }
3421*4882a593Smuzhiyun
3422*4882a593Smuzhiyun /**
3423*4882a593Smuzhiyun * ice_aq_set_rss_key
3424*4882a593Smuzhiyun * @hw: pointer to the HW struct
3425*4882a593Smuzhiyun * @vsi_handle: software VSI handle
3426*4882a593Smuzhiyun * @keys: pointer to key info struct
3427*4882a593Smuzhiyun *
3428*4882a593Smuzhiyun * set the RSS key per VSI
3429*4882a593Smuzhiyun */
3430*4882a593Smuzhiyun enum ice_status
ice_aq_set_rss_key(struct ice_hw * hw,u16 vsi_handle,struct ice_aqc_get_set_rss_keys * keys)3431*4882a593Smuzhiyun ice_aq_set_rss_key(struct ice_hw *hw, u16 vsi_handle,
3432*4882a593Smuzhiyun struct ice_aqc_get_set_rss_keys *keys)
3433*4882a593Smuzhiyun {
3434*4882a593Smuzhiyun if (!ice_is_vsi_valid(hw, vsi_handle) || !keys)
3435*4882a593Smuzhiyun return ICE_ERR_PARAM;
3436*4882a593Smuzhiyun
3437*4882a593Smuzhiyun return __ice_aq_get_set_rss_key(hw, ice_get_hw_vsi_num(hw, vsi_handle),
3438*4882a593Smuzhiyun keys, true);
3439*4882a593Smuzhiyun }
3440*4882a593Smuzhiyun
3441*4882a593Smuzhiyun /**
3442*4882a593Smuzhiyun * ice_aq_add_lan_txq
3443*4882a593Smuzhiyun * @hw: pointer to the hardware structure
3444*4882a593Smuzhiyun * @num_qgrps: Number of added queue groups
3445*4882a593Smuzhiyun * @qg_list: list of queue groups to be added
3446*4882a593Smuzhiyun * @buf_size: size of buffer for indirect command
3447*4882a593Smuzhiyun * @cd: pointer to command details structure or NULL
3448*4882a593Smuzhiyun *
3449*4882a593Smuzhiyun * Add Tx LAN queue (0x0C30)
3450*4882a593Smuzhiyun *
3451*4882a593Smuzhiyun * NOTE:
3452*4882a593Smuzhiyun * Prior to calling add Tx LAN queue:
3453*4882a593Smuzhiyun * Initialize the following as part of the Tx queue context:
3454*4882a593Smuzhiyun * Completion queue ID if the queue uses Completion queue, Quanta profile,
3455*4882a593Smuzhiyun * Cache profile and Packet shaper profile.
3456*4882a593Smuzhiyun *
3457*4882a593Smuzhiyun * After add Tx LAN queue AQ command is completed:
3458*4882a593Smuzhiyun * Interrupts should be associated with specific queues,
3459*4882a593Smuzhiyun * Association of Tx queue to Doorbell queue is not part of Add LAN Tx queue
3460*4882a593Smuzhiyun * flow.
3461*4882a593Smuzhiyun */
3462*4882a593Smuzhiyun static enum ice_status
ice_aq_add_lan_txq(struct ice_hw * hw,u8 num_qgrps,struct ice_aqc_add_tx_qgrp * qg_list,u16 buf_size,struct ice_sq_cd * cd)3463*4882a593Smuzhiyun ice_aq_add_lan_txq(struct ice_hw *hw, u8 num_qgrps,
3464*4882a593Smuzhiyun struct ice_aqc_add_tx_qgrp *qg_list, u16 buf_size,
3465*4882a593Smuzhiyun struct ice_sq_cd *cd)
3466*4882a593Smuzhiyun {
3467*4882a593Smuzhiyun struct ice_aqc_add_tx_qgrp *list;
3468*4882a593Smuzhiyun struct ice_aqc_add_txqs *cmd;
3469*4882a593Smuzhiyun struct ice_aq_desc desc;
3470*4882a593Smuzhiyun u16 i, sum_size = 0;
3471*4882a593Smuzhiyun
3472*4882a593Smuzhiyun cmd = &desc.params.add_txqs;
3473*4882a593Smuzhiyun
3474*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_add_txqs);
3475*4882a593Smuzhiyun
3476*4882a593Smuzhiyun if (!qg_list)
3477*4882a593Smuzhiyun return ICE_ERR_PARAM;
3478*4882a593Smuzhiyun
3479*4882a593Smuzhiyun if (num_qgrps > ICE_LAN_TXQ_MAX_QGRPS)
3480*4882a593Smuzhiyun return ICE_ERR_PARAM;
3481*4882a593Smuzhiyun
3482*4882a593Smuzhiyun for (i = 0, list = qg_list; i < num_qgrps; i++) {
3483*4882a593Smuzhiyun sum_size += struct_size(list, txqs, list->num_txqs);
3484*4882a593Smuzhiyun list = (struct ice_aqc_add_tx_qgrp *)(list->txqs +
3485*4882a593Smuzhiyun list->num_txqs);
3486*4882a593Smuzhiyun }
3487*4882a593Smuzhiyun
3488*4882a593Smuzhiyun if (buf_size != sum_size)
3489*4882a593Smuzhiyun return ICE_ERR_PARAM;
3490*4882a593Smuzhiyun
3491*4882a593Smuzhiyun desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
3492*4882a593Smuzhiyun
3493*4882a593Smuzhiyun cmd->num_qgrps = num_qgrps;
3494*4882a593Smuzhiyun
3495*4882a593Smuzhiyun return ice_aq_send_cmd(hw, &desc, qg_list, buf_size, cd);
3496*4882a593Smuzhiyun }
3497*4882a593Smuzhiyun
3498*4882a593Smuzhiyun /**
3499*4882a593Smuzhiyun * ice_aq_dis_lan_txq
3500*4882a593Smuzhiyun * @hw: pointer to the hardware structure
3501*4882a593Smuzhiyun * @num_qgrps: number of groups in the list
3502*4882a593Smuzhiyun * @qg_list: the list of groups to disable
3503*4882a593Smuzhiyun * @buf_size: the total size of the qg_list buffer in bytes
3504*4882a593Smuzhiyun * @rst_src: if called due to reset, specifies the reset source
3505*4882a593Smuzhiyun * @vmvf_num: the relative VM or VF number that is undergoing the reset
3506*4882a593Smuzhiyun * @cd: pointer to command details structure or NULL
3507*4882a593Smuzhiyun *
3508*4882a593Smuzhiyun * Disable LAN Tx queue (0x0C31)
3509*4882a593Smuzhiyun */
3510*4882a593Smuzhiyun static enum ice_status
ice_aq_dis_lan_txq(struct ice_hw * hw,u8 num_qgrps,struct ice_aqc_dis_txq_item * qg_list,u16 buf_size,enum ice_disq_rst_src rst_src,u16 vmvf_num,struct ice_sq_cd * cd)3511*4882a593Smuzhiyun ice_aq_dis_lan_txq(struct ice_hw *hw, u8 num_qgrps,
3512*4882a593Smuzhiyun struct ice_aqc_dis_txq_item *qg_list, u16 buf_size,
3513*4882a593Smuzhiyun enum ice_disq_rst_src rst_src, u16 vmvf_num,
3514*4882a593Smuzhiyun struct ice_sq_cd *cd)
3515*4882a593Smuzhiyun {
3516*4882a593Smuzhiyun struct ice_aqc_dis_txq_item *item;
3517*4882a593Smuzhiyun struct ice_aqc_dis_txqs *cmd;
3518*4882a593Smuzhiyun struct ice_aq_desc desc;
3519*4882a593Smuzhiyun enum ice_status status;
3520*4882a593Smuzhiyun u16 i, sz = 0;
3521*4882a593Smuzhiyun
3522*4882a593Smuzhiyun cmd = &desc.params.dis_txqs;
3523*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_dis_txqs);
3524*4882a593Smuzhiyun
3525*4882a593Smuzhiyun /* qg_list can be NULL only in VM/VF reset flow */
3526*4882a593Smuzhiyun if (!qg_list && !rst_src)
3527*4882a593Smuzhiyun return ICE_ERR_PARAM;
3528*4882a593Smuzhiyun
3529*4882a593Smuzhiyun if (num_qgrps > ICE_LAN_TXQ_MAX_QGRPS)
3530*4882a593Smuzhiyun return ICE_ERR_PARAM;
3531*4882a593Smuzhiyun
3532*4882a593Smuzhiyun cmd->num_entries = num_qgrps;
3533*4882a593Smuzhiyun
3534*4882a593Smuzhiyun cmd->vmvf_and_timeout = cpu_to_le16((5 << ICE_AQC_Q_DIS_TIMEOUT_S) &
3535*4882a593Smuzhiyun ICE_AQC_Q_DIS_TIMEOUT_M);
3536*4882a593Smuzhiyun
3537*4882a593Smuzhiyun switch (rst_src) {
3538*4882a593Smuzhiyun case ICE_VM_RESET:
3539*4882a593Smuzhiyun cmd->cmd_type = ICE_AQC_Q_DIS_CMD_VM_RESET;
3540*4882a593Smuzhiyun cmd->vmvf_and_timeout |=
3541*4882a593Smuzhiyun cpu_to_le16(vmvf_num & ICE_AQC_Q_DIS_VMVF_NUM_M);
3542*4882a593Smuzhiyun break;
3543*4882a593Smuzhiyun case ICE_VF_RESET:
3544*4882a593Smuzhiyun cmd->cmd_type = ICE_AQC_Q_DIS_CMD_VF_RESET;
3545*4882a593Smuzhiyun /* In this case, FW expects vmvf_num to be absolute VF ID */
3546*4882a593Smuzhiyun cmd->vmvf_and_timeout |=
3547*4882a593Smuzhiyun cpu_to_le16((vmvf_num + hw->func_caps.vf_base_id) &
3548*4882a593Smuzhiyun ICE_AQC_Q_DIS_VMVF_NUM_M);
3549*4882a593Smuzhiyun break;
3550*4882a593Smuzhiyun case ICE_NO_RESET:
3551*4882a593Smuzhiyun default:
3552*4882a593Smuzhiyun break;
3553*4882a593Smuzhiyun }
3554*4882a593Smuzhiyun
3555*4882a593Smuzhiyun /* flush pipe on time out */
3556*4882a593Smuzhiyun cmd->cmd_type |= ICE_AQC_Q_DIS_CMD_FLUSH_PIPE;
3557*4882a593Smuzhiyun /* If no queue group info, we are in a reset flow. Issue the AQ */
3558*4882a593Smuzhiyun if (!qg_list)
3559*4882a593Smuzhiyun goto do_aq;
3560*4882a593Smuzhiyun
3561*4882a593Smuzhiyun /* set RD bit to indicate that command buffer is provided by the driver
3562*4882a593Smuzhiyun * and it needs to be read by the firmware
3563*4882a593Smuzhiyun */
3564*4882a593Smuzhiyun desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
3565*4882a593Smuzhiyun
3566*4882a593Smuzhiyun for (i = 0, item = qg_list; i < num_qgrps; i++) {
3567*4882a593Smuzhiyun u16 item_size = struct_size(item, q_id, item->num_qs);
3568*4882a593Smuzhiyun
3569*4882a593Smuzhiyun /* If the num of queues is even, add 2 bytes of padding */
3570*4882a593Smuzhiyun if ((item->num_qs % 2) == 0)
3571*4882a593Smuzhiyun item_size += 2;
3572*4882a593Smuzhiyun
3573*4882a593Smuzhiyun sz += item_size;
3574*4882a593Smuzhiyun
3575*4882a593Smuzhiyun item = (struct ice_aqc_dis_txq_item *)((u8 *)item + item_size);
3576*4882a593Smuzhiyun }
3577*4882a593Smuzhiyun
3578*4882a593Smuzhiyun if (buf_size != sz)
3579*4882a593Smuzhiyun return ICE_ERR_PARAM;
3580*4882a593Smuzhiyun
3581*4882a593Smuzhiyun do_aq:
3582*4882a593Smuzhiyun status = ice_aq_send_cmd(hw, &desc, qg_list, buf_size, cd);
3583*4882a593Smuzhiyun if (status) {
3584*4882a593Smuzhiyun if (!qg_list)
3585*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_SCHED, "VM%d disable failed %d\n",
3586*4882a593Smuzhiyun vmvf_num, hw->adminq.sq_last_status);
3587*4882a593Smuzhiyun else
3588*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_SCHED, "disable queue %d failed %d\n",
3589*4882a593Smuzhiyun le16_to_cpu(qg_list[0].q_id[0]),
3590*4882a593Smuzhiyun hw->adminq.sq_last_status);
3591*4882a593Smuzhiyun }
3592*4882a593Smuzhiyun return status;
3593*4882a593Smuzhiyun }
3594*4882a593Smuzhiyun
3595*4882a593Smuzhiyun /* End of FW Admin Queue command wrappers */
3596*4882a593Smuzhiyun
3597*4882a593Smuzhiyun /**
3598*4882a593Smuzhiyun * ice_write_byte - write a byte to a packed context structure
3599*4882a593Smuzhiyun * @src_ctx: the context structure to read from
3600*4882a593Smuzhiyun * @dest_ctx: the context to be written to
3601*4882a593Smuzhiyun * @ce_info: a description of the struct to be filled
3602*4882a593Smuzhiyun */
3603*4882a593Smuzhiyun static void
ice_write_byte(u8 * src_ctx,u8 * dest_ctx,const struct ice_ctx_ele * ce_info)3604*4882a593Smuzhiyun ice_write_byte(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info)
3605*4882a593Smuzhiyun {
3606*4882a593Smuzhiyun u8 src_byte, dest_byte, mask;
3607*4882a593Smuzhiyun u8 *from, *dest;
3608*4882a593Smuzhiyun u16 shift_width;
3609*4882a593Smuzhiyun
3610*4882a593Smuzhiyun /* copy from the next struct field */
3611*4882a593Smuzhiyun from = src_ctx + ce_info->offset;
3612*4882a593Smuzhiyun
3613*4882a593Smuzhiyun /* prepare the bits and mask */
3614*4882a593Smuzhiyun shift_width = ce_info->lsb % 8;
3615*4882a593Smuzhiyun mask = (u8)(BIT(ce_info->width) - 1);
3616*4882a593Smuzhiyun
3617*4882a593Smuzhiyun src_byte = *from;
3618*4882a593Smuzhiyun src_byte &= mask;
3619*4882a593Smuzhiyun
3620*4882a593Smuzhiyun /* shift to correct alignment */
3621*4882a593Smuzhiyun mask <<= shift_width;
3622*4882a593Smuzhiyun src_byte <<= shift_width;
3623*4882a593Smuzhiyun
3624*4882a593Smuzhiyun /* get the current bits from the target bit string */
3625*4882a593Smuzhiyun dest = dest_ctx + (ce_info->lsb / 8);
3626*4882a593Smuzhiyun
3627*4882a593Smuzhiyun memcpy(&dest_byte, dest, sizeof(dest_byte));
3628*4882a593Smuzhiyun
3629*4882a593Smuzhiyun dest_byte &= ~mask; /* get the bits not changing */
3630*4882a593Smuzhiyun dest_byte |= src_byte; /* add in the new bits */
3631*4882a593Smuzhiyun
3632*4882a593Smuzhiyun /* put it all back */
3633*4882a593Smuzhiyun memcpy(dest, &dest_byte, sizeof(dest_byte));
3634*4882a593Smuzhiyun }
3635*4882a593Smuzhiyun
3636*4882a593Smuzhiyun /**
3637*4882a593Smuzhiyun * ice_write_word - write a word to a packed context structure
3638*4882a593Smuzhiyun * @src_ctx: the context structure to read from
3639*4882a593Smuzhiyun * @dest_ctx: the context to be written to
3640*4882a593Smuzhiyun * @ce_info: a description of the struct to be filled
3641*4882a593Smuzhiyun */
3642*4882a593Smuzhiyun static void
ice_write_word(u8 * src_ctx,u8 * dest_ctx,const struct ice_ctx_ele * ce_info)3643*4882a593Smuzhiyun ice_write_word(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info)
3644*4882a593Smuzhiyun {
3645*4882a593Smuzhiyun u16 src_word, mask;
3646*4882a593Smuzhiyun __le16 dest_word;
3647*4882a593Smuzhiyun u8 *from, *dest;
3648*4882a593Smuzhiyun u16 shift_width;
3649*4882a593Smuzhiyun
3650*4882a593Smuzhiyun /* copy from the next struct field */
3651*4882a593Smuzhiyun from = src_ctx + ce_info->offset;
3652*4882a593Smuzhiyun
3653*4882a593Smuzhiyun /* prepare the bits and mask */
3654*4882a593Smuzhiyun shift_width = ce_info->lsb % 8;
3655*4882a593Smuzhiyun mask = BIT(ce_info->width) - 1;
3656*4882a593Smuzhiyun
3657*4882a593Smuzhiyun /* don't swizzle the bits until after the mask because the mask bits
3658*4882a593Smuzhiyun * will be in a different bit position on big endian machines
3659*4882a593Smuzhiyun */
3660*4882a593Smuzhiyun src_word = *(u16 *)from;
3661*4882a593Smuzhiyun src_word &= mask;
3662*4882a593Smuzhiyun
3663*4882a593Smuzhiyun /* shift to correct alignment */
3664*4882a593Smuzhiyun mask <<= shift_width;
3665*4882a593Smuzhiyun src_word <<= shift_width;
3666*4882a593Smuzhiyun
3667*4882a593Smuzhiyun /* get the current bits from the target bit string */
3668*4882a593Smuzhiyun dest = dest_ctx + (ce_info->lsb / 8);
3669*4882a593Smuzhiyun
3670*4882a593Smuzhiyun memcpy(&dest_word, dest, sizeof(dest_word));
3671*4882a593Smuzhiyun
3672*4882a593Smuzhiyun dest_word &= ~(cpu_to_le16(mask)); /* get the bits not changing */
3673*4882a593Smuzhiyun dest_word |= cpu_to_le16(src_word); /* add in the new bits */
3674*4882a593Smuzhiyun
3675*4882a593Smuzhiyun /* put it all back */
3676*4882a593Smuzhiyun memcpy(dest, &dest_word, sizeof(dest_word));
3677*4882a593Smuzhiyun }
3678*4882a593Smuzhiyun
3679*4882a593Smuzhiyun /**
3680*4882a593Smuzhiyun * ice_write_dword - write a dword to a packed context structure
3681*4882a593Smuzhiyun * @src_ctx: the context structure to read from
3682*4882a593Smuzhiyun * @dest_ctx: the context to be written to
3683*4882a593Smuzhiyun * @ce_info: a description of the struct to be filled
3684*4882a593Smuzhiyun */
3685*4882a593Smuzhiyun static void
ice_write_dword(u8 * src_ctx,u8 * dest_ctx,const struct ice_ctx_ele * ce_info)3686*4882a593Smuzhiyun ice_write_dword(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info)
3687*4882a593Smuzhiyun {
3688*4882a593Smuzhiyun u32 src_dword, mask;
3689*4882a593Smuzhiyun __le32 dest_dword;
3690*4882a593Smuzhiyun u8 *from, *dest;
3691*4882a593Smuzhiyun u16 shift_width;
3692*4882a593Smuzhiyun
3693*4882a593Smuzhiyun /* copy from the next struct field */
3694*4882a593Smuzhiyun from = src_ctx + ce_info->offset;
3695*4882a593Smuzhiyun
3696*4882a593Smuzhiyun /* prepare the bits and mask */
3697*4882a593Smuzhiyun shift_width = ce_info->lsb % 8;
3698*4882a593Smuzhiyun
3699*4882a593Smuzhiyun /* if the field width is exactly 32 on an x86 machine, then the shift
3700*4882a593Smuzhiyun * operation will not work because the SHL instructions count is masked
3701*4882a593Smuzhiyun * to 5 bits so the shift will do nothing
3702*4882a593Smuzhiyun */
3703*4882a593Smuzhiyun if (ce_info->width < 32)
3704*4882a593Smuzhiyun mask = BIT(ce_info->width) - 1;
3705*4882a593Smuzhiyun else
3706*4882a593Smuzhiyun mask = (u32)~0;
3707*4882a593Smuzhiyun
3708*4882a593Smuzhiyun /* don't swizzle the bits until after the mask because the mask bits
3709*4882a593Smuzhiyun * will be in a different bit position on big endian machines
3710*4882a593Smuzhiyun */
3711*4882a593Smuzhiyun src_dword = *(u32 *)from;
3712*4882a593Smuzhiyun src_dword &= mask;
3713*4882a593Smuzhiyun
3714*4882a593Smuzhiyun /* shift to correct alignment */
3715*4882a593Smuzhiyun mask <<= shift_width;
3716*4882a593Smuzhiyun src_dword <<= shift_width;
3717*4882a593Smuzhiyun
3718*4882a593Smuzhiyun /* get the current bits from the target bit string */
3719*4882a593Smuzhiyun dest = dest_ctx + (ce_info->lsb / 8);
3720*4882a593Smuzhiyun
3721*4882a593Smuzhiyun memcpy(&dest_dword, dest, sizeof(dest_dword));
3722*4882a593Smuzhiyun
3723*4882a593Smuzhiyun dest_dword &= ~(cpu_to_le32(mask)); /* get the bits not changing */
3724*4882a593Smuzhiyun dest_dword |= cpu_to_le32(src_dword); /* add in the new bits */
3725*4882a593Smuzhiyun
3726*4882a593Smuzhiyun /* put it all back */
3727*4882a593Smuzhiyun memcpy(dest, &dest_dword, sizeof(dest_dword));
3728*4882a593Smuzhiyun }
3729*4882a593Smuzhiyun
3730*4882a593Smuzhiyun /**
3731*4882a593Smuzhiyun * ice_write_qword - write a qword to a packed context structure
3732*4882a593Smuzhiyun * @src_ctx: the context structure to read from
3733*4882a593Smuzhiyun * @dest_ctx: the context to be written to
3734*4882a593Smuzhiyun * @ce_info: a description of the struct to be filled
3735*4882a593Smuzhiyun */
3736*4882a593Smuzhiyun static void
ice_write_qword(u8 * src_ctx,u8 * dest_ctx,const struct ice_ctx_ele * ce_info)3737*4882a593Smuzhiyun ice_write_qword(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info)
3738*4882a593Smuzhiyun {
3739*4882a593Smuzhiyun u64 src_qword, mask;
3740*4882a593Smuzhiyun __le64 dest_qword;
3741*4882a593Smuzhiyun u8 *from, *dest;
3742*4882a593Smuzhiyun u16 shift_width;
3743*4882a593Smuzhiyun
3744*4882a593Smuzhiyun /* copy from the next struct field */
3745*4882a593Smuzhiyun from = src_ctx + ce_info->offset;
3746*4882a593Smuzhiyun
3747*4882a593Smuzhiyun /* prepare the bits and mask */
3748*4882a593Smuzhiyun shift_width = ce_info->lsb % 8;
3749*4882a593Smuzhiyun
3750*4882a593Smuzhiyun /* if the field width is exactly 64 on an x86 machine, then the shift
3751*4882a593Smuzhiyun * operation will not work because the SHL instructions count is masked
3752*4882a593Smuzhiyun * to 6 bits so the shift will do nothing
3753*4882a593Smuzhiyun */
3754*4882a593Smuzhiyun if (ce_info->width < 64)
3755*4882a593Smuzhiyun mask = BIT_ULL(ce_info->width) - 1;
3756*4882a593Smuzhiyun else
3757*4882a593Smuzhiyun mask = (u64)~0;
3758*4882a593Smuzhiyun
3759*4882a593Smuzhiyun /* don't swizzle the bits until after the mask because the mask bits
3760*4882a593Smuzhiyun * will be in a different bit position on big endian machines
3761*4882a593Smuzhiyun */
3762*4882a593Smuzhiyun src_qword = *(u64 *)from;
3763*4882a593Smuzhiyun src_qword &= mask;
3764*4882a593Smuzhiyun
3765*4882a593Smuzhiyun /* shift to correct alignment */
3766*4882a593Smuzhiyun mask <<= shift_width;
3767*4882a593Smuzhiyun src_qword <<= shift_width;
3768*4882a593Smuzhiyun
3769*4882a593Smuzhiyun /* get the current bits from the target bit string */
3770*4882a593Smuzhiyun dest = dest_ctx + (ce_info->lsb / 8);
3771*4882a593Smuzhiyun
3772*4882a593Smuzhiyun memcpy(&dest_qword, dest, sizeof(dest_qword));
3773*4882a593Smuzhiyun
3774*4882a593Smuzhiyun dest_qword &= ~(cpu_to_le64(mask)); /* get the bits not changing */
3775*4882a593Smuzhiyun dest_qword |= cpu_to_le64(src_qword); /* add in the new bits */
3776*4882a593Smuzhiyun
3777*4882a593Smuzhiyun /* put it all back */
3778*4882a593Smuzhiyun memcpy(dest, &dest_qword, sizeof(dest_qword));
3779*4882a593Smuzhiyun }
3780*4882a593Smuzhiyun
3781*4882a593Smuzhiyun /**
3782*4882a593Smuzhiyun * ice_set_ctx - set context bits in packed structure
3783*4882a593Smuzhiyun * @hw: pointer to the hardware structure
3784*4882a593Smuzhiyun * @src_ctx: pointer to a generic non-packed context structure
3785*4882a593Smuzhiyun * @dest_ctx: pointer to memory for the packed structure
3786*4882a593Smuzhiyun * @ce_info: a description of the structure to be transformed
3787*4882a593Smuzhiyun */
3788*4882a593Smuzhiyun enum ice_status
ice_set_ctx(struct ice_hw * hw,u8 * src_ctx,u8 * dest_ctx,const struct ice_ctx_ele * ce_info)3789*4882a593Smuzhiyun ice_set_ctx(struct ice_hw *hw, u8 *src_ctx, u8 *dest_ctx,
3790*4882a593Smuzhiyun const struct ice_ctx_ele *ce_info)
3791*4882a593Smuzhiyun {
3792*4882a593Smuzhiyun int f;
3793*4882a593Smuzhiyun
3794*4882a593Smuzhiyun for (f = 0; ce_info[f].width; f++) {
3795*4882a593Smuzhiyun /* We have to deal with each element of the FW response
3796*4882a593Smuzhiyun * using the correct size so that we are correct regardless
3797*4882a593Smuzhiyun * of the endianness of the machine.
3798*4882a593Smuzhiyun */
3799*4882a593Smuzhiyun if (ce_info[f].width > (ce_info[f].size_of * BITS_PER_BYTE)) {
3800*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_QCTX,
3801*4882a593Smuzhiyun "Field %d width of %d bits larger than size of %d byte(s) ... skipping write\n",
3802*4882a593Smuzhiyun f, ce_info[f].width, ce_info[f].size_of);
3803*4882a593Smuzhiyun continue;
3804*4882a593Smuzhiyun }
3805*4882a593Smuzhiyun switch (ce_info[f].size_of) {
3806*4882a593Smuzhiyun case sizeof(u8):
3807*4882a593Smuzhiyun ice_write_byte(src_ctx, dest_ctx, &ce_info[f]);
3808*4882a593Smuzhiyun break;
3809*4882a593Smuzhiyun case sizeof(u16):
3810*4882a593Smuzhiyun ice_write_word(src_ctx, dest_ctx, &ce_info[f]);
3811*4882a593Smuzhiyun break;
3812*4882a593Smuzhiyun case sizeof(u32):
3813*4882a593Smuzhiyun ice_write_dword(src_ctx, dest_ctx, &ce_info[f]);
3814*4882a593Smuzhiyun break;
3815*4882a593Smuzhiyun case sizeof(u64):
3816*4882a593Smuzhiyun ice_write_qword(src_ctx, dest_ctx, &ce_info[f]);
3817*4882a593Smuzhiyun break;
3818*4882a593Smuzhiyun default:
3819*4882a593Smuzhiyun return ICE_ERR_INVAL_SIZE;
3820*4882a593Smuzhiyun }
3821*4882a593Smuzhiyun }
3822*4882a593Smuzhiyun
3823*4882a593Smuzhiyun return 0;
3824*4882a593Smuzhiyun }
3825*4882a593Smuzhiyun
3826*4882a593Smuzhiyun /**
3827*4882a593Smuzhiyun * ice_get_lan_q_ctx - get the LAN queue context for the given VSI and TC
3828*4882a593Smuzhiyun * @hw: pointer to the HW struct
3829*4882a593Smuzhiyun * @vsi_handle: software VSI handle
3830*4882a593Smuzhiyun * @tc: TC number
3831*4882a593Smuzhiyun * @q_handle: software queue handle
3832*4882a593Smuzhiyun */
3833*4882a593Smuzhiyun struct ice_q_ctx *
ice_get_lan_q_ctx(struct ice_hw * hw,u16 vsi_handle,u8 tc,u16 q_handle)3834*4882a593Smuzhiyun ice_get_lan_q_ctx(struct ice_hw *hw, u16 vsi_handle, u8 tc, u16 q_handle)
3835*4882a593Smuzhiyun {
3836*4882a593Smuzhiyun struct ice_vsi_ctx *vsi;
3837*4882a593Smuzhiyun struct ice_q_ctx *q_ctx;
3838*4882a593Smuzhiyun
3839*4882a593Smuzhiyun vsi = ice_get_vsi_ctx(hw, vsi_handle);
3840*4882a593Smuzhiyun if (!vsi)
3841*4882a593Smuzhiyun return NULL;
3842*4882a593Smuzhiyun if (q_handle >= vsi->num_lan_q_entries[tc])
3843*4882a593Smuzhiyun return NULL;
3844*4882a593Smuzhiyun if (!vsi->lan_q_ctx[tc])
3845*4882a593Smuzhiyun return NULL;
3846*4882a593Smuzhiyun q_ctx = vsi->lan_q_ctx[tc];
3847*4882a593Smuzhiyun return &q_ctx[q_handle];
3848*4882a593Smuzhiyun }
3849*4882a593Smuzhiyun
3850*4882a593Smuzhiyun /**
3851*4882a593Smuzhiyun * ice_ena_vsi_txq
3852*4882a593Smuzhiyun * @pi: port information structure
3853*4882a593Smuzhiyun * @vsi_handle: software VSI handle
3854*4882a593Smuzhiyun * @tc: TC number
3855*4882a593Smuzhiyun * @q_handle: software queue handle
3856*4882a593Smuzhiyun * @num_qgrps: Number of added queue groups
3857*4882a593Smuzhiyun * @buf: list of queue groups to be added
3858*4882a593Smuzhiyun * @buf_size: size of buffer for indirect command
3859*4882a593Smuzhiyun * @cd: pointer to command details structure or NULL
3860*4882a593Smuzhiyun *
3861*4882a593Smuzhiyun * This function adds one LAN queue
3862*4882a593Smuzhiyun */
3863*4882a593Smuzhiyun enum ice_status
ice_ena_vsi_txq(struct ice_port_info * pi,u16 vsi_handle,u8 tc,u16 q_handle,u8 num_qgrps,struct ice_aqc_add_tx_qgrp * buf,u16 buf_size,struct ice_sq_cd * cd)3864*4882a593Smuzhiyun ice_ena_vsi_txq(struct ice_port_info *pi, u16 vsi_handle, u8 tc, u16 q_handle,
3865*4882a593Smuzhiyun u8 num_qgrps, struct ice_aqc_add_tx_qgrp *buf, u16 buf_size,
3866*4882a593Smuzhiyun struct ice_sq_cd *cd)
3867*4882a593Smuzhiyun {
3868*4882a593Smuzhiyun struct ice_aqc_txsched_elem_data node = { 0 };
3869*4882a593Smuzhiyun struct ice_sched_node *parent;
3870*4882a593Smuzhiyun struct ice_q_ctx *q_ctx;
3871*4882a593Smuzhiyun enum ice_status status;
3872*4882a593Smuzhiyun struct ice_hw *hw;
3873*4882a593Smuzhiyun
3874*4882a593Smuzhiyun if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
3875*4882a593Smuzhiyun return ICE_ERR_CFG;
3876*4882a593Smuzhiyun
3877*4882a593Smuzhiyun if (num_qgrps > 1 || buf->num_txqs > 1)
3878*4882a593Smuzhiyun return ICE_ERR_MAX_LIMIT;
3879*4882a593Smuzhiyun
3880*4882a593Smuzhiyun hw = pi->hw;
3881*4882a593Smuzhiyun
3882*4882a593Smuzhiyun if (!ice_is_vsi_valid(hw, vsi_handle))
3883*4882a593Smuzhiyun return ICE_ERR_PARAM;
3884*4882a593Smuzhiyun
3885*4882a593Smuzhiyun mutex_lock(&pi->sched_lock);
3886*4882a593Smuzhiyun
3887*4882a593Smuzhiyun q_ctx = ice_get_lan_q_ctx(hw, vsi_handle, tc, q_handle);
3888*4882a593Smuzhiyun if (!q_ctx) {
3889*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_SCHED, "Enaq: invalid queue handle %d\n",
3890*4882a593Smuzhiyun q_handle);
3891*4882a593Smuzhiyun status = ICE_ERR_PARAM;
3892*4882a593Smuzhiyun goto ena_txq_exit;
3893*4882a593Smuzhiyun }
3894*4882a593Smuzhiyun
3895*4882a593Smuzhiyun /* find a parent node */
3896*4882a593Smuzhiyun parent = ice_sched_get_free_qparent(pi, vsi_handle, tc,
3897*4882a593Smuzhiyun ICE_SCHED_NODE_OWNER_LAN);
3898*4882a593Smuzhiyun if (!parent) {
3899*4882a593Smuzhiyun status = ICE_ERR_PARAM;
3900*4882a593Smuzhiyun goto ena_txq_exit;
3901*4882a593Smuzhiyun }
3902*4882a593Smuzhiyun
3903*4882a593Smuzhiyun buf->parent_teid = parent->info.node_teid;
3904*4882a593Smuzhiyun node.parent_teid = parent->info.node_teid;
3905*4882a593Smuzhiyun /* Mark that the values in the "generic" section as valid. The default
3906*4882a593Smuzhiyun * value in the "generic" section is zero. This means that :
3907*4882a593Smuzhiyun * - Scheduling mode is Bytes Per Second (BPS), indicated by Bit 0.
3908*4882a593Smuzhiyun * - 0 priority among siblings, indicated by Bit 1-3.
3909*4882a593Smuzhiyun * - WFQ, indicated by Bit 4.
3910*4882a593Smuzhiyun * - 0 Adjustment value is used in PSM credit update flow, indicated by
3911*4882a593Smuzhiyun * Bit 5-6.
3912*4882a593Smuzhiyun * - Bit 7 is reserved.
3913*4882a593Smuzhiyun * Without setting the generic section as valid in valid_sections, the
3914*4882a593Smuzhiyun * Admin queue command will fail with error code ICE_AQ_RC_EINVAL.
3915*4882a593Smuzhiyun */
3916*4882a593Smuzhiyun buf->txqs[0].info.valid_sections =
3917*4882a593Smuzhiyun ICE_AQC_ELEM_VALID_GENERIC | ICE_AQC_ELEM_VALID_CIR |
3918*4882a593Smuzhiyun ICE_AQC_ELEM_VALID_EIR;
3919*4882a593Smuzhiyun buf->txqs[0].info.generic = 0;
3920*4882a593Smuzhiyun buf->txqs[0].info.cir_bw.bw_profile_idx =
3921*4882a593Smuzhiyun cpu_to_le16(ICE_SCHED_DFLT_RL_PROF_ID);
3922*4882a593Smuzhiyun buf->txqs[0].info.cir_bw.bw_alloc =
3923*4882a593Smuzhiyun cpu_to_le16(ICE_SCHED_DFLT_BW_WT);
3924*4882a593Smuzhiyun buf->txqs[0].info.eir_bw.bw_profile_idx =
3925*4882a593Smuzhiyun cpu_to_le16(ICE_SCHED_DFLT_RL_PROF_ID);
3926*4882a593Smuzhiyun buf->txqs[0].info.eir_bw.bw_alloc =
3927*4882a593Smuzhiyun cpu_to_le16(ICE_SCHED_DFLT_BW_WT);
3928*4882a593Smuzhiyun
3929*4882a593Smuzhiyun /* add the LAN queue */
3930*4882a593Smuzhiyun status = ice_aq_add_lan_txq(hw, num_qgrps, buf, buf_size, cd);
3931*4882a593Smuzhiyun if (status) {
3932*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_SCHED, "enable queue %d failed %d\n",
3933*4882a593Smuzhiyun le16_to_cpu(buf->txqs[0].txq_id),
3934*4882a593Smuzhiyun hw->adminq.sq_last_status);
3935*4882a593Smuzhiyun goto ena_txq_exit;
3936*4882a593Smuzhiyun }
3937*4882a593Smuzhiyun
3938*4882a593Smuzhiyun node.node_teid = buf->txqs[0].q_teid;
3939*4882a593Smuzhiyun node.data.elem_type = ICE_AQC_ELEM_TYPE_LEAF;
3940*4882a593Smuzhiyun q_ctx->q_handle = q_handle;
3941*4882a593Smuzhiyun q_ctx->q_teid = le32_to_cpu(node.node_teid);
3942*4882a593Smuzhiyun
3943*4882a593Smuzhiyun /* add a leaf node into scheduler tree queue layer */
3944*4882a593Smuzhiyun status = ice_sched_add_node(pi, hw->num_tx_sched_layers - 1, &node);
3945*4882a593Smuzhiyun if (!status)
3946*4882a593Smuzhiyun status = ice_sched_replay_q_bw(pi, q_ctx);
3947*4882a593Smuzhiyun
3948*4882a593Smuzhiyun ena_txq_exit:
3949*4882a593Smuzhiyun mutex_unlock(&pi->sched_lock);
3950*4882a593Smuzhiyun return status;
3951*4882a593Smuzhiyun }
3952*4882a593Smuzhiyun
3953*4882a593Smuzhiyun /**
3954*4882a593Smuzhiyun * ice_dis_vsi_txq
3955*4882a593Smuzhiyun * @pi: port information structure
3956*4882a593Smuzhiyun * @vsi_handle: software VSI handle
3957*4882a593Smuzhiyun * @tc: TC number
3958*4882a593Smuzhiyun * @num_queues: number of queues
3959*4882a593Smuzhiyun * @q_handles: pointer to software queue handle array
3960*4882a593Smuzhiyun * @q_ids: pointer to the q_id array
3961*4882a593Smuzhiyun * @q_teids: pointer to queue node teids
3962*4882a593Smuzhiyun * @rst_src: if called due to reset, specifies the reset source
3963*4882a593Smuzhiyun * @vmvf_num: the relative VM or VF number that is undergoing the reset
3964*4882a593Smuzhiyun * @cd: pointer to command details structure or NULL
3965*4882a593Smuzhiyun *
3966*4882a593Smuzhiyun * This function removes queues and their corresponding nodes in SW DB
3967*4882a593Smuzhiyun */
3968*4882a593Smuzhiyun enum ice_status
ice_dis_vsi_txq(struct ice_port_info * pi,u16 vsi_handle,u8 tc,u8 num_queues,u16 * q_handles,u16 * q_ids,u32 * q_teids,enum ice_disq_rst_src rst_src,u16 vmvf_num,struct ice_sq_cd * cd)3969*4882a593Smuzhiyun ice_dis_vsi_txq(struct ice_port_info *pi, u16 vsi_handle, u8 tc, u8 num_queues,
3970*4882a593Smuzhiyun u16 *q_handles, u16 *q_ids, u32 *q_teids,
3971*4882a593Smuzhiyun enum ice_disq_rst_src rst_src, u16 vmvf_num,
3972*4882a593Smuzhiyun struct ice_sq_cd *cd)
3973*4882a593Smuzhiyun {
3974*4882a593Smuzhiyun enum ice_status status = ICE_ERR_DOES_NOT_EXIST;
3975*4882a593Smuzhiyun struct ice_aqc_dis_txq_item *qg_list;
3976*4882a593Smuzhiyun struct ice_q_ctx *q_ctx;
3977*4882a593Smuzhiyun struct ice_hw *hw;
3978*4882a593Smuzhiyun u16 i, buf_size;
3979*4882a593Smuzhiyun
3980*4882a593Smuzhiyun if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
3981*4882a593Smuzhiyun return ICE_ERR_CFG;
3982*4882a593Smuzhiyun
3983*4882a593Smuzhiyun hw = pi->hw;
3984*4882a593Smuzhiyun
3985*4882a593Smuzhiyun if (!num_queues) {
3986*4882a593Smuzhiyun /* if queue is disabled already yet the disable queue command
3987*4882a593Smuzhiyun * has to be sent to complete the VF reset, then call
3988*4882a593Smuzhiyun * ice_aq_dis_lan_txq without any queue information
3989*4882a593Smuzhiyun */
3990*4882a593Smuzhiyun if (rst_src)
3991*4882a593Smuzhiyun return ice_aq_dis_lan_txq(hw, 0, NULL, 0, rst_src,
3992*4882a593Smuzhiyun vmvf_num, NULL);
3993*4882a593Smuzhiyun return ICE_ERR_CFG;
3994*4882a593Smuzhiyun }
3995*4882a593Smuzhiyun
3996*4882a593Smuzhiyun buf_size = struct_size(qg_list, q_id, 1);
3997*4882a593Smuzhiyun qg_list = kzalloc(buf_size, GFP_KERNEL);
3998*4882a593Smuzhiyun if (!qg_list)
3999*4882a593Smuzhiyun return ICE_ERR_NO_MEMORY;
4000*4882a593Smuzhiyun
4001*4882a593Smuzhiyun mutex_lock(&pi->sched_lock);
4002*4882a593Smuzhiyun
4003*4882a593Smuzhiyun for (i = 0; i < num_queues; i++) {
4004*4882a593Smuzhiyun struct ice_sched_node *node;
4005*4882a593Smuzhiyun
4006*4882a593Smuzhiyun node = ice_sched_find_node_by_teid(pi->root, q_teids[i]);
4007*4882a593Smuzhiyun if (!node)
4008*4882a593Smuzhiyun continue;
4009*4882a593Smuzhiyun q_ctx = ice_get_lan_q_ctx(hw, vsi_handle, tc, q_handles[i]);
4010*4882a593Smuzhiyun if (!q_ctx) {
4011*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_SCHED, "invalid queue handle%d\n",
4012*4882a593Smuzhiyun q_handles[i]);
4013*4882a593Smuzhiyun continue;
4014*4882a593Smuzhiyun }
4015*4882a593Smuzhiyun if (q_ctx->q_handle != q_handles[i]) {
4016*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_SCHED, "Err:handles %d %d\n",
4017*4882a593Smuzhiyun q_ctx->q_handle, q_handles[i]);
4018*4882a593Smuzhiyun continue;
4019*4882a593Smuzhiyun }
4020*4882a593Smuzhiyun qg_list->parent_teid = node->info.parent_teid;
4021*4882a593Smuzhiyun qg_list->num_qs = 1;
4022*4882a593Smuzhiyun qg_list->q_id[0] = cpu_to_le16(q_ids[i]);
4023*4882a593Smuzhiyun status = ice_aq_dis_lan_txq(hw, 1, qg_list, buf_size, rst_src,
4024*4882a593Smuzhiyun vmvf_num, cd);
4025*4882a593Smuzhiyun
4026*4882a593Smuzhiyun if (status)
4027*4882a593Smuzhiyun break;
4028*4882a593Smuzhiyun ice_free_sched_node(pi, node);
4029*4882a593Smuzhiyun q_ctx->q_handle = ICE_INVAL_Q_HANDLE;
4030*4882a593Smuzhiyun }
4031*4882a593Smuzhiyun mutex_unlock(&pi->sched_lock);
4032*4882a593Smuzhiyun kfree(qg_list);
4033*4882a593Smuzhiyun return status;
4034*4882a593Smuzhiyun }
4035*4882a593Smuzhiyun
4036*4882a593Smuzhiyun /**
4037*4882a593Smuzhiyun * ice_cfg_vsi_qs - configure the new/existing VSI queues
4038*4882a593Smuzhiyun * @pi: port information structure
4039*4882a593Smuzhiyun * @vsi_handle: software VSI handle
4040*4882a593Smuzhiyun * @tc_bitmap: TC bitmap
4041*4882a593Smuzhiyun * @maxqs: max queues array per TC
4042*4882a593Smuzhiyun * @owner: LAN or RDMA
4043*4882a593Smuzhiyun *
4044*4882a593Smuzhiyun * This function adds/updates the VSI queues per TC.
4045*4882a593Smuzhiyun */
4046*4882a593Smuzhiyun static enum ice_status
ice_cfg_vsi_qs(struct ice_port_info * pi,u16 vsi_handle,u8 tc_bitmap,u16 * maxqs,u8 owner)4047*4882a593Smuzhiyun ice_cfg_vsi_qs(struct ice_port_info *pi, u16 vsi_handle, u8 tc_bitmap,
4048*4882a593Smuzhiyun u16 *maxqs, u8 owner)
4049*4882a593Smuzhiyun {
4050*4882a593Smuzhiyun enum ice_status status = 0;
4051*4882a593Smuzhiyun u8 i;
4052*4882a593Smuzhiyun
4053*4882a593Smuzhiyun if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
4054*4882a593Smuzhiyun return ICE_ERR_CFG;
4055*4882a593Smuzhiyun
4056*4882a593Smuzhiyun if (!ice_is_vsi_valid(pi->hw, vsi_handle))
4057*4882a593Smuzhiyun return ICE_ERR_PARAM;
4058*4882a593Smuzhiyun
4059*4882a593Smuzhiyun mutex_lock(&pi->sched_lock);
4060*4882a593Smuzhiyun
4061*4882a593Smuzhiyun ice_for_each_traffic_class(i) {
4062*4882a593Smuzhiyun /* configuration is possible only if TC node is present */
4063*4882a593Smuzhiyun if (!ice_sched_get_tc_node(pi, i))
4064*4882a593Smuzhiyun continue;
4065*4882a593Smuzhiyun
4066*4882a593Smuzhiyun status = ice_sched_cfg_vsi(pi, vsi_handle, i, maxqs[i], owner,
4067*4882a593Smuzhiyun ice_is_tc_ena(tc_bitmap, i));
4068*4882a593Smuzhiyun if (status)
4069*4882a593Smuzhiyun break;
4070*4882a593Smuzhiyun }
4071*4882a593Smuzhiyun
4072*4882a593Smuzhiyun mutex_unlock(&pi->sched_lock);
4073*4882a593Smuzhiyun return status;
4074*4882a593Smuzhiyun }
4075*4882a593Smuzhiyun
4076*4882a593Smuzhiyun /**
4077*4882a593Smuzhiyun * ice_cfg_vsi_lan - configure VSI LAN queues
4078*4882a593Smuzhiyun * @pi: port information structure
4079*4882a593Smuzhiyun * @vsi_handle: software VSI handle
4080*4882a593Smuzhiyun * @tc_bitmap: TC bitmap
4081*4882a593Smuzhiyun * @max_lanqs: max LAN queues array per TC
4082*4882a593Smuzhiyun *
4083*4882a593Smuzhiyun * This function adds/updates the VSI LAN queues per TC.
4084*4882a593Smuzhiyun */
4085*4882a593Smuzhiyun enum ice_status
ice_cfg_vsi_lan(struct ice_port_info * pi,u16 vsi_handle,u8 tc_bitmap,u16 * max_lanqs)4086*4882a593Smuzhiyun ice_cfg_vsi_lan(struct ice_port_info *pi, u16 vsi_handle, u8 tc_bitmap,
4087*4882a593Smuzhiyun u16 *max_lanqs)
4088*4882a593Smuzhiyun {
4089*4882a593Smuzhiyun return ice_cfg_vsi_qs(pi, vsi_handle, tc_bitmap, max_lanqs,
4090*4882a593Smuzhiyun ICE_SCHED_NODE_OWNER_LAN);
4091*4882a593Smuzhiyun }
4092*4882a593Smuzhiyun
4093*4882a593Smuzhiyun /**
4094*4882a593Smuzhiyun * ice_replay_pre_init - replay pre initialization
4095*4882a593Smuzhiyun * @hw: pointer to the HW struct
4096*4882a593Smuzhiyun *
4097*4882a593Smuzhiyun * Initializes required config data for VSI, FD, ACL, and RSS before replay.
4098*4882a593Smuzhiyun */
ice_replay_pre_init(struct ice_hw * hw)4099*4882a593Smuzhiyun static enum ice_status ice_replay_pre_init(struct ice_hw *hw)
4100*4882a593Smuzhiyun {
4101*4882a593Smuzhiyun struct ice_switch_info *sw = hw->switch_info;
4102*4882a593Smuzhiyun u8 i;
4103*4882a593Smuzhiyun
4104*4882a593Smuzhiyun /* Delete old entries from replay filter list head if there is any */
4105*4882a593Smuzhiyun ice_rm_all_sw_replay_rule_info(hw);
4106*4882a593Smuzhiyun /* In start of replay, move entries into replay_rules list, it
4107*4882a593Smuzhiyun * will allow adding rules entries back to filt_rules list,
4108*4882a593Smuzhiyun * which is operational list.
4109*4882a593Smuzhiyun */
4110*4882a593Smuzhiyun for (i = 0; i < ICE_SW_LKUP_LAST; i++)
4111*4882a593Smuzhiyun list_replace_init(&sw->recp_list[i].filt_rules,
4112*4882a593Smuzhiyun &sw->recp_list[i].filt_replay_rules);
4113*4882a593Smuzhiyun
4114*4882a593Smuzhiyun return 0;
4115*4882a593Smuzhiyun }
4116*4882a593Smuzhiyun
4117*4882a593Smuzhiyun /**
4118*4882a593Smuzhiyun * ice_replay_vsi - replay VSI configuration
4119*4882a593Smuzhiyun * @hw: pointer to the HW struct
4120*4882a593Smuzhiyun * @vsi_handle: driver VSI handle
4121*4882a593Smuzhiyun *
4122*4882a593Smuzhiyun * Restore all VSI configuration after reset. It is required to call this
4123*4882a593Smuzhiyun * function with main VSI first.
4124*4882a593Smuzhiyun */
ice_replay_vsi(struct ice_hw * hw,u16 vsi_handle)4125*4882a593Smuzhiyun enum ice_status ice_replay_vsi(struct ice_hw *hw, u16 vsi_handle)
4126*4882a593Smuzhiyun {
4127*4882a593Smuzhiyun enum ice_status status;
4128*4882a593Smuzhiyun
4129*4882a593Smuzhiyun if (!ice_is_vsi_valid(hw, vsi_handle))
4130*4882a593Smuzhiyun return ICE_ERR_PARAM;
4131*4882a593Smuzhiyun
4132*4882a593Smuzhiyun /* Replay pre-initialization if there is any */
4133*4882a593Smuzhiyun if (vsi_handle == ICE_MAIN_VSI_HANDLE) {
4134*4882a593Smuzhiyun status = ice_replay_pre_init(hw);
4135*4882a593Smuzhiyun if (status)
4136*4882a593Smuzhiyun return status;
4137*4882a593Smuzhiyun }
4138*4882a593Smuzhiyun /* Replay per VSI all RSS configurations */
4139*4882a593Smuzhiyun status = ice_replay_rss_cfg(hw, vsi_handle);
4140*4882a593Smuzhiyun if (status)
4141*4882a593Smuzhiyun return status;
4142*4882a593Smuzhiyun /* Replay per VSI all filters */
4143*4882a593Smuzhiyun status = ice_replay_vsi_all_fltr(hw, vsi_handle);
4144*4882a593Smuzhiyun return status;
4145*4882a593Smuzhiyun }
4146*4882a593Smuzhiyun
4147*4882a593Smuzhiyun /**
4148*4882a593Smuzhiyun * ice_replay_post - post replay configuration cleanup
4149*4882a593Smuzhiyun * @hw: pointer to the HW struct
4150*4882a593Smuzhiyun *
4151*4882a593Smuzhiyun * Post replay cleanup.
4152*4882a593Smuzhiyun */
ice_replay_post(struct ice_hw * hw)4153*4882a593Smuzhiyun void ice_replay_post(struct ice_hw *hw)
4154*4882a593Smuzhiyun {
4155*4882a593Smuzhiyun /* Delete old entries from replay filter list head */
4156*4882a593Smuzhiyun ice_rm_all_sw_replay_rule_info(hw);
4157*4882a593Smuzhiyun }
4158*4882a593Smuzhiyun
4159*4882a593Smuzhiyun /**
4160*4882a593Smuzhiyun * ice_stat_update40 - read 40 bit stat from the chip and update stat values
4161*4882a593Smuzhiyun * @hw: ptr to the hardware info
4162*4882a593Smuzhiyun * @reg: offset of 64 bit HW register to read from
4163*4882a593Smuzhiyun * @prev_stat_loaded: bool to specify if previous stats are loaded
4164*4882a593Smuzhiyun * @prev_stat: ptr to previous loaded stat value
4165*4882a593Smuzhiyun * @cur_stat: ptr to current stat value
4166*4882a593Smuzhiyun */
4167*4882a593Smuzhiyun void
ice_stat_update40(struct ice_hw * hw,u32 reg,bool prev_stat_loaded,u64 * prev_stat,u64 * cur_stat)4168*4882a593Smuzhiyun ice_stat_update40(struct ice_hw *hw, u32 reg, bool prev_stat_loaded,
4169*4882a593Smuzhiyun u64 *prev_stat, u64 *cur_stat)
4170*4882a593Smuzhiyun {
4171*4882a593Smuzhiyun u64 new_data = rd64(hw, reg) & (BIT_ULL(40) - 1);
4172*4882a593Smuzhiyun
4173*4882a593Smuzhiyun /* device stats are not reset at PFR, they likely will not be zeroed
4174*4882a593Smuzhiyun * when the driver starts. Thus, save the value from the first read
4175*4882a593Smuzhiyun * without adding to the statistic value so that we report stats which
4176*4882a593Smuzhiyun * count up from zero.
4177*4882a593Smuzhiyun */
4178*4882a593Smuzhiyun if (!prev_stat_loaded) {
4179*4882a593Smuzhiyun *prev_stat = new_data;
4180*4882a593Smuzhiyun return;
4181*4882a593Smuzhiyun }
4182*4882a593Smuzhiyun
4183*4882a593Smuzhiyun /* Calculate the difference between the new and old values, and then
4184*4882a593Smuzhiyun * add it to the software stat value.
4185*4882a593Smuzhiyun */
4186*4882a593Smuzhiyun if (new_data >= *prev_stat)
4187*4882a593Smuzhiyun *cur_stat += new_data - *prev_stat;
4188*4882a593Smuzhiyun else
4189*4882a593Smuzhiyun /* to manage the potential roll-over */
4190*4882a593Smuzhiyun *cur_stat += (new_data + BIT_ULL(40)) - *prev_stat;
4191*4882a593Smuzhiyun
4192*4882a593Smuzhiyun /* Update the previously stored value to prepare for next read */
4193*4882a593Smuzhiyun *prev_stat = new_data;
4194*4882a593Smuzhiyun }
4195*4882a593Smuzhiyun
4196*4882a593Smuzhiyun /**
4197*4882a593Smuzhiyun * ice_stat_update32 - read 32 bit stat from the chip and update stat values
4198*4882a593Smuzhiyun * @hw: ptr to the hardware info
4199*4882a593Smuzhiyun * @reg: offset of HW register to read from
4200*4882a593Smuzhiyun * @prev_stat_loaded: bool to specify if previous stats are loaded
4201*4882a593Smuzhiyun * @prev_stat: ptr to previous loaded stat value
4202*4882a593Smuzhiyun * @cur_stat: ptr to current stat value
4203*4882a593Smuzhiyun */
4204*4882a593Smuzhiyun void
ice_stat_update32(struct ice_hw * hw,u32 reg,bool prev_stat_loaded,u64 * prev_stat,u64 * cur_stat)4205*4882a593Smuzhiyun ice_stat_update32(struct ice_hw *hw, u32 reg, bool prev_stat_loaded,
4206*4882a593Smuzhiyun u64 *prev_stat, u64 *cur_stat)
4207*4882a593Smuzhiyun {
4208*4882a593Smuzhiyun u32 new_data;
4209*4882a593Smuzhiyun
4210*4882a593Smuzhiyun new_data = rd32(hw, reg);
4211*4882a593Smuzhiyun
4212*4882a593Smuzhiyun /* device stats are not reset at PFR, they likely will not be zeroed
4213*4882a593Smuzhiyun * when the driver starts. Thus, save the value from the first read
4214*4882a593Smuzhiyun * without adding to the statistic value so that we report stats which
4215*4882a593Smuzhiyun * count up from zero.
4216*4882a593Smuzhiyun */
4217*4882a593Smuzhiyun if (!prev_stat_loaded) {
4218*4882a593Smuzhiyun *prev_stat = new_data;
4219*4882a593Smuzhiyun return;
4220*4882a593Smuzhiyun }
4221*4882a593Smuzhiyun
4222*4882a593Smuzhiyun /* Calculate the difference between the new and old values, and then
4223*4882a593Smuzhiyun * add it to the software stat value.
4224*4882a593Smuzhiyun */
4225*4882a593Smuzhiyun if (new_data >= *prev_stat)
4226*4882a593Smuzhiyun *cur_stat += new_data - *prev_stat;
4227*4882a593Smuzhiyun else
4228*4882a593Smuzhiyun /* to manage the potential roll-over */
4229*4882a593Smuzhiyun *cur_stat += (new_data + BIT_ULL(32)) - *prev_stat;
4230*4882a593Smuzhiyun
4231*4882a593Smuzhiyun /* Update the previously stored value to prepare for next read */
4232*4882a593Smuzhiyun *prev_stat = new_data;
4233*4882a593Smuzhiyun }
4234*4882a593Smuzhiyun
4235*4882a593Smuzhiyun /**
4236*4882a593Smuzhiyun * ice_sched_query_elem - query element information from HW
4237*4882a593Smuzhiyun * @hw: pointer to the HW struct
4238*4882a593Smuzhiyun * @node_teid: node TEID to be queried
4239*4882a593Smuzhiyun * @buf: buffer to element information
4240*4882a593Smuzhiyun *
4241*4882a593Smuzhiyun * This function queries HW element information
4242*4882a593Smuzhiyun */
4243*4882a593Smuzhiyun enum ice_status
ice_sched_query_elem(struct ice_hw * hw,u32 node_teid,struct ice_aqc_txsched_elem_data * buf)4244*4882a593Smuzhiyun ice_sched_query_elem(struct ice_hw *hw, u32 node_teid,
4245*4882a593Smuzhiyun struct ice_aqc_txsched_elem_data *buf)
4246*4882a593Smuzhiyun {
4247*4882a593Smuzhiyun u16 buf_size, num_elem_ret = 0;
4248*4882a593Smuzhiyun enum ice_status status;
4249*4882a593Smuzhiyun
4250*4882a593Smuzhiyun buf_size = sizeof(*buf);
4251*4882a593Smuzhiyun memset(buf, 0, buf_size);
4252*4882a593Smuzhiyun buf->node_teid = cpu_to_le32(node_teid);
4253*4882a593Smuzhiyun status = ice_aq_query_sched_elems(hw, 1, buf, buf_size, &num_elem_ret,
4254*4882a593Smuzhiyun NULL);
4255*4882a593Smuzhiyun if (status || num_elem_ret != 1)
4256*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_SCHED, "query element failed\n");
4257*4882a593Smuzhiyun return status;
4258*4882a593Smuzhiyun }
4259*4882a593Smuzhiyun
4260*4882a593Smuzhiyun /**
4261*4882a593Smuzhiyun * ice_fw_supports_link_override
4262*4882a593Smuzhiyun * @hw: pointer to the hardware structure
4263*4882a593Smuzhiyun *
4264*4882a593Smuzhiyun * Checks if the firmware supports link override
4265*4882a593Smuzhiyun */
ice_fw_supports_link_override(struct ice_hw * hw)4266*4882a593Smuzhiyun bool ice_fw_supports_link_override(struct ice_hw *hw)
4267*4882a593Smuzhiyun {
4268*4882a593Smuzhiyun /* Currently, only supported for E810 devices */
4269*4882a593Smuzhiyun if (hw->mac_type != ICE_MAC_E810)
4270*4882a593Smuzhiyun return false;
4271*4882a593Smuzhiyun
4272*4882a593Smuzhiyun if (hw->api_maj_ver == ICE_FW_API_LINK_OVERRIDE_MAJ) {
4273*4882a593Smuzhiyun if (hw->api_min_ver > ICE_FW_API_LINK_OVERRIDE_MIN)
4274*4882a593Smuzhiyun return true;
4275*4882a593Smuzhiyun if (hw->api_min_ver == ICE_FW_API_LINK_OVERRIDE_MIN &&
4276*4882a593Smuzhiyun hw->api_patch >= ICE_FW_API_LINK_OVERRIDE_PATCH)
4277*4882a593Smuzhiyun return true;
4278*4882a593Smuzhiyun } else if (hw->api_maj_ver > ICE_FW_API_LINK_OVERRIDE_MAJ) {
4279*4882a593Smuzhiyun return true;
4280*4882a593Smuzhiyun }
4281*4882a593Smuzhiyun
4282*4882a593Smuzhiyun return false;
4283*4882a593Smuzhiyun }
4284*4882a593Smuzhiyun
4285*4882a593Smuzhiyun /**
4286*4882a593Smuzhiyun * ice_get_link_default_override
4287*4882a593Smuzhiyun * @ldo: pointer to the link default override struct
4288*4882a593Smuzhiyun * @pi: pointer to the port info struct
4289*4882a593Smuzhiyun *
4290*4882a593Smuzhiyun * Gets the link default override for a port
4291*4882a593Smuzhiyun */
4292*4882a593Smuzhiyun enum ice_status
ice_get_link_default_override(struct ice_link_default_override_tlv * ldo,struct ice_port_info * pi)4293*4882a593Smuzhiyun ice_get_link_default_override(struct ice_link_default_override_tlv *ldo,
4294*4882a593Smuzhiyun struct ice_port_info *pi)
4295*4882a593Smuzhiyun {
4296*4882a593Smuzhiyun u16 i, tlv, tlv_len, tlv_start, buf, offset;
4297*4882a593Smuzhiyun struct ice_hw *hw = pi->hw;
4298*4882a593Smuzhiyun enum ice_status status;
4299*4882a593Smuzhiyun
4300*4882a593Smuzhiyun status = ice_get_pfa_module_tlv(hw, &tlv, &tlv_len,
4301*4882a593Smuzhiyun ICE_SR_LINK_DEFAULT_OVERRIDE_PTR);
4302*4882a593Smuzhiyun if (status) {
4303*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
4304*4882a593Smuzhiyun "Failed to read link override TLV.\n");
4305*4882a593Smuzhiyun return status;
4306*4882a593Smuzhiyun }
4307*4882a593Smuzhiyun
4308*4882a593Smuzhiyun /* Each port has its own config; calculate for our port */
4309*4882a593Smuzhiyun tlv_start = tlv + pi->lport * ICE_SR_PFA_LINK_OVERRIDE_WORDS +
4310*4882a593Smuzhiyun ICE_SR_PFA_LINK_OVERRIDE_OFFSET;
4311*4882a593Smuzhiyun
4312*4882a593Smuzhiyun /* link options first */
4313*4882a593Smuzhiyun status = ice_read_sr_word(hw, tlv_start, &buf);
4314*4882a593Smuzhiyun if (status) {
4315*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
4316*4882a593Smuzhiyun "Failed to read override link options.\n");
4317*4882a593Smuzhiyun return status;
4318*4882a593Smuzhiyun }
4319*4882a593Smuzhiyun ldo->options = buf & ICE_LINK_OVERRIDE_OPT_M;
4320*4882a593Smuzhiyun ldo->phy_config = (buf & ICE_LINK_OVERRIDE_PHY_CFG_M) >>
4321*4882a593Smuzhiyun ICE_LINK_OVERRIDE_PHY_CFG_S;
4322*4882a593Smuzhiyun
4323*4882a593Smuzhiyun /* link PHY config */
4324*4882a593Smuzhiyun offset = tlv_start + ICE_SR_PFA_LINK_OVERRIDE_FEC_OFFSET;
4325*4882a593Smuzhiyun status = ice_read_sr_word(hw, offset, &buf);
4326*4882a593Smuzhiyun if (status) {
4327*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
4328*4882a593Smuzhiyun "Failed to read override phy config.\n");
4329*4882a593Smuzhiyun return status;
4330*4882a593Smuzhiyun }
4331*4882a593Smuzhiyun ldo->fec_options = buf & ICE_LINK_OVERRIDE_FEC_OPT_M;
4332*4882a593Smuzhiyun
4333*4882a593Smuzhiyun /* PHY types low */
4334*4882a593Smuzhiyun offset = tlv_start + ICE_SR_PFA_LINK_OVERRIDE_PHY_OFFSET;
4335*4882a593Smuzhiyun for (i = 0; i < ICE_SR_PFA_LINK_OVERRIDE_PHY_WORDS; i++) {
4336*4882a593Smuzhiyun status = ice_read_sr_word(hw, (offset + i), &buf);
4337*4882a593Smuzhiyun if (status) {
4338*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
4339*4882a593Smuzhiyun "Failed to read override link options.\n");
4340*4882a593Smuzhiyun return status;
4341*4882a593Smuzhiyun }
4342*4882a593Smuzhiyun /* shift 16 bits at a time to fill 64 bits */
4343*4882a593Smuzhiyun ldo->phy_type_low |= ((u64)buf << (i * 16));
4344*4882a593Smuzhiyun }
4345*4882a593Smuzhiyun
4346*4882a593Smuzhiyun /* PHY types high */
4347*4882a593Smuzhiyun offset = tlv_start + ICE_SR_PFA_LINK_OVERRIDE_PHY_OFFSET +
4348*4882a593Smuzhiyun ICE_SR_PFA_LINK_OVERRIDE_PHY_WORDS;
4349*4882a593Smuzhiyun for (i = 0; i < ICE_SR_PFA_LINK_OVERRIDE_PHY_WORDS; i++) {
4350*4882a593Smuzhiyun status = ice_read_sr_word(hw, (offset + i), &buf);
4351*4882a593Smuzhiyun if (status) {
4352*4882a593Smuzhiyun ice_debug(hw, ICE_DBG_INIT,
4353*4882a593Smuzhiyun "Failed to read override link options.\n");
4354*4882a593Smuzhiyun return status;
4355*4882a593Smuzhiyun }
4356*4882a593Smuzhiyun /* shift 16 bits at a time to fill 64 bits */
4357*4882a593Smuzhiyun ldo->phy_type_high |= ((u64)buf << (i * 16));
4358*4882a593Smuzhiyun }
4359*4882a593Smuzhiyun
4360*4882a593Smuzhiyun return status;
4361*4882a593Smuzhiyun }
4362*4882a593Smuzhiyun
4363*4882a593Smuzhiyun /**
4364*4882a593Smuzhiyun * ice_is_phy_caps_an_enabled - check if PHY capabilities autoneg is enabled
4365*4882a593Smuzhiyun * @caps: get PHY capability data
4366*4882a593Smuzhiyun */
ice_is_phy_caps_an_enabled(struct ice_aqc_get_phy_caps_data * caps)4367*4882a593Smuzhiyun bool ice_is_phy_caps_an_enabled(struct ice_aqc_get_phy_caps_data *caps)
4368*4882a593Smuzhiyun {
4369*4882a593Smuzhiyun if (caps->caps & ICE_AQC_PHY_AN_MODE ||
4370*4882a593Smuzhiyun caps->low_power_ctrl_an & (ICE_AQC_PHY_AN_EN_CLAUSE28 |
4371*4882a593Smuzhiyun ICE_AQC_PHY_AN_EN_CLAUSE73 |
4372*4882a593Smuzhiyun ICE_AQC_PHY_AN_EN_CLAUSE37))
4373*4882a593Smuzhiyun return true;
4374*4882a593Smuzhiyun
4375*4882a593Smuzhiyun return false;
4376*4882a593Smuzhiyun }
4377*4882a593Smuzhiyun
4378*4882a593Smuzhiyun /**
4379*4882a593Smuzhiyun * ice_aq_set_lldp_mib - Set the LLDP MIB
4380*4882a593Smuzhiyun * @hw: pointer to the HW struct
4381*4882a593Smuzhiyun * @mib_type: Local, Remote or both Local and Remote MIBs
4382*4882a593Smuzhiyun * @buf: pointer to the caller-supplied buffer to store the MIB block
4383*4882a593Smuzhiyun * @buf_size: size of the buffer (in bytes)
4384*4882a593Smuzhiyun * @cd: pointer to command details structure or NULL
4385*4882a593Smuzhiyun *
4386*4882a593Smuzhiyun * Set the LLDP MIB. (0x0A08)
4387*4882a593Smuzhiyun */
4388*4882a593Smuzhiyun enum ice_status
ice_aq_set_lldp_mib(struct ice_hw * hw,u8 mib_type,void * buf,u16 buf_size,struct ice_sq_cd * cd)4389*4882a593Smuzhiyun ice_aq_set_lldp_mib(struct ice_hw *hw, u8 mib_type, void *buf, u16 buf_size,
4390*4882a593Smuzhiyun struct ice_sq_cd *cd)
4391*4882a593Smuzhiyun {
4392*4882a593Smuzhiyun struct ice_aqc_lldp_set_local_mib *cmd;
4393*4882a593Smuzhiyun struct ice_aq_desc desc;
4394*4882a593Smuzhiyun
4395*4882a593Smuzhiyun cmd = &desc.params.lldp_set_mib;
4396*4882a593Smuzhiyun
4397*4882a593Smuzhiyun if (buf_size == 0 || !buf)
4398*4882a593Smuzhiyun return ICE_ERR_PARAM;
4399*4882a593Smuzhiyun
4400*4882a593Smuzhiyun ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_lldp_set_local_mib);
4401*4882a593Smuzhiyun
4402*4882a593Smuzhiyun desc.flags |= cpu_to_le16((u16)ICE_AQ_FLAG_RD);
4403*4882a593Smuzhiyun desc.datalen = cpu_to_le16(buf_size);
4404*4882a593Smuzhiyun
4405*4882a593Smuzhiyun cmd->type = mib_type;
4406*4882a593Smuzhiyun cmd->length = cpu_to_le16(buf_size);
4407*4882a593Smuzhiyun
4408*4882a593Smuzhiyun return ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
4409*4882a593Smuzhiyun }
4410