1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2021 Intel Corporation
5 #include "ice_common.h"
7 #include "ice_adminq_cmd.h"
10 #include "ice_switch.h"
12 #define ICE_PF_RESET_WAIT_COUNT 300
15 * ice_set_mac_type - Sets MAC type
16 * @hw: pointer to the HW structure
18 * This function sets the MAC type of the adapter based on the
19 * vendor ID and device ID stored in the HW structure.
21 static enum ice_status ice_set_mac_type(struct ice_hw *hw)
23 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
25 if (hw->vendor_id != ICE_INTEL_VENDOR_ID)
26 return ICE_ERR_DEVICE_NOT_SUPPORTED;
28 switch (hw->device_id) {
29 case ICE_DEV_ID_E810C_BACKPLANE:
30 case ICE_DEV_ID_E810C_QSFP:
31 case ICE_DEV_ID_E810C_SFP:
32 case ICE_DEV_ID_E810_XXV_BACKPLANE:
33 case ICE_DEV_ID_E810_XXV_QSFP:
34 case ICE_DEV_ID_E810_XXV_SFP:
35 hw->mac_type = ICE_MAC_E810;
37 case ICE_DEV_ID_E822C_10G_BASE_T:
38 case ICE_DEV_ID_E822C_BACKPLANE:
39 case ICE_DEV_ID_E822C_QSFP:
40 case ICE_DEV_ID_E822C_SFP:
41 case ICE_DEV_ID_E822C_SGMII:
42 case ICE_DEV_ID_E822L_10G_BASE_T:
43 case ICE_DEV_ID_E822L_BACKPLANE:
44 case ICE_DEV_ID_E822L_SFP:
45 case ICE_DEV_ID_E822L_SGMII:
46 case ICE_DEV_ID_E823L_10G_BASE_T:
47 case ICE_DEV_ID_E823L_1GBE:
48 case ICE_DEV_ID_E823L_BACKPLANE:
49 case ICE_DEV_ID_E823L_QSFP:
50 case ICE_DEV_ID_E823L_SFP:
51 case ICE_DEV_ID_E823C_10G_BASE_T:
52 case ICE_DEV_ID_E823C_BACKPLANE:
53 case ICE_DEV_ID_E823C_QSFP:
54 case ICE_DEV_ID_E823C_SFP:
55 case ICE_DEV_ID_E823C_SGMII:
56 hw->mac_type = ICE_MAC_GENERIC;
59 hw->mac_type = ICE_MAC_UNKNOWN;
63 ice_debug(hw, ICE_DBG_INIT, "mac_type: %d\n", hw->mac_type);
68 * ice_clear_pf_cfg - Clear PF configuration
69 * @hw: pointer to the hardware structure
71 * Clears any existing PF configuration (VSIs, VSI lists, switch rules, port
72 * configuration, flow director filters, etc.).
74 enum ice_status ice_clear_pf_cfg(struct ice_hw *hw)
76 struct ice_aq_desc desc;
78 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_clear_pf_cfg);
80 return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
84 * ice_aq_manage_mac_read - manage MAC address read command
85 * @hw: pointer to the HW struct
86 * @buf: a virtual buffer to hold the manage MAC read response
87 * @buf_size: Size of the virtual buffer
88 * @cd: pointer to command details structure or NULL
90 * This function is used to return per PF station MAC address (0x0107).
91 * NOTE: Upon successful completion of this command, MAC address information
92 * is returned in user specified buffer. Please interpret user specified
93 * buffer as "manage_mac_read" response.
94 * Response such as various MAC addresses are stored in HW struct (port.mac)
95 * ice_discover_dev_caps is expected to be called before this function is
98 static enum ice_status
99 ice_aq_manage_mac_read(struct ice_hw *hw, void *buf, u16 buf_size,
100 struct ice_sq_cd *cd)
102 struct ice_aqc_manage_mac_read_resp *resp;
103 struct ice_aqc_manage_mac_read *cmd;
104 struct ice_aq_desc desc;
105 enum ice_status status;
109 cmd = &desc.params.mac_read;
111 if (buf_size < sizeof(*resp))
112 return ICE_ERR_BUF_TOO_SHORT;
114 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_manage_mac_read);
116 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
120 resp = (struct ice_aqc_manage_mac_read_resp *)buf;
121 flags = LE16_TO_CPU(cmd->flags) & ICE_AQC_MAN_MAC_READ_M;
123 if (!(flags & ICE_AQC_MAN_MAC_LAN_ADDR_VALID)) {
124 ice_debug(hw, ICE_DBG_LAN, "got invalid MAC address\n");
128 /* A single port can report up to two (LAN and WoL) addresses */
129 for (i = 0; i < cmd->num_addr; i++)
130 if (resp[i].addr_type == ICE_AQC_MAN_MAC_ADDR_TYPE_LAN) {
131 ice_memcpy(hw->port_info->mac.lan_addr,
132 resp[i].mac_addr, ETH_ALEN,
134 ice_memcpy(hw->port_info->mac.perm_addr,
136 ETH_ALEN, ICE_DMA_TO_NONDMA);
143 * ice_aq_get_phy_caps - returns PHY capabilities
144 * @pi: port information structure
145 * @qual_mods: report qualified modules
146 * @report_mode: report mode capabilities
147 * @pcaps: structure for PHY capabilities to be filled
148 * @cd: pointer to command details structure or NULL
150 * Returns the various PHY capabilities supported on the Port (0x0600)
153 ice_aq_get_phy_caps(struct ice_port_info *pi, bool qual_mods, u8 report_mode,
154 struct ice_aqc_get_phy_caps_data *pcaps,
155 struct ice_sq_cd *cd)
157 struct ice_aqc_get_phy_caps *cmd;
158 u16 pcaps_size = sizeof(*pcaps);
159 struct ice_aq_desc desc;
160 enum ice_status status;
163 cmd = &desc.params.get_phy;
165 if (!pcaps || (report_mode & ~ICE_AQC_REPORT_MODE_M) || !pi)
166 return ICE_ERR_PARAM;
169 if (report_mode == ICE_AQC_REPORT_DFLT_CFG &&
170 !ice_fw_supports_report_dflt_cfg(hw))
171 return ICE_ERR_PARAM;
173 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_phy_caps);
176 cmd->param0 |= CPU_TO_LE16(ICE_AQC_GET_PHY_RQM);
178 cmd->param0 |= CPU_TO_LE16(report_mode);
179 status = ice_aq_send_cmd(hw, &desc, pcaps, pcaps_size, cd);
181 ice_debug(hw, ICE_DBG_LINK, "get phy caps - report_mode = 0x%x\n",
183 ice_debug(hw, ICE_DBG_LINK, " phy_type_low = 0x%llx\n",
184 (unsigned long long)LE64_TO_CPU(pcaps->phy_type_low));
185 ice_debug(hw, ICE_DBG_LINK, " phy_type_high = 0x%llx\n",
186 (unsigned long long)LE64_TO_CPU(pcaps->phy_type_high));
187 ice_debug(hw, ICE_DBG_LINK, " caps = 0x%x\n", pcaps->caps);
188 ice_debug(hw, ICE_DBG_LINK, " low_power_ctrl_an = 0x%x\n",
189 pcaps->low_power_ctrl_an);
190 ice_debug(hw, ICE_DBG_LINK, " eee_cap = 0x%x\n", pcaps->eee_cap);
191 ice_debug(hw, ICE_DBG_LINK, " eeer_value = 0x%x\n",
193 ice_debug(hw, ICE_DBG_LINK, " link_fec_options = 0x%x\n",
194 pcaps->link_fec_options);
195 ice_debug(hw, ICE_DBG_LINK, " module_compliance_enforcement = 0x%x\n",
196 pcaps->module_compliance_enforcement);
197 ice_debug(hw, ICE_DBG_LINK, " extended_compliance_code = 0x%x\n",
198 pcaps->extended_compliance_code);
199 ice_debug(hw, ICE_DBG_LINK, " module_type[0] = 0x%x\n",
200 pcaps->module_type[0]);
201 ice_debug(hw, ICE_DBG_LINK, " module_type[1] = 0x%x\n",
202 pcaps->module_type[1]);
203 ice_debug(hw, ICE_DBG_LINK, " module_type[2] = 0x%x\n",
204 pcaps->module_type[2]);
206 if (status == ICE_SUCCESS && report_mode == ICE_AQC_REPORT_TOPO_CAP_MEDIA) {
207 pi->phy.phy_type_low = LE64_TO_CPU(pcaps->phy_type_low);
208 pi->phy.phy_type_high = LE64_TO_CPU(pcaps->phy_type_high);
209 ice_memcpy(pi->phy.link_info.module_type, &pcaps->module_type,
210 sizeof(pi->phy.link_info.module_type),
211 ICE_NONDMA_TO_NONDMA);
218 * ice_aq_get_link_topo_handle - get link topology node return status
219 * @pi: port information structure
220 * @node_type: requested node type
221 * @cd: pointer to command details structure or NULL
223 * Get link topology node return status for specified node type (0x06E0)
225 * Node type cage can be used to determine if cage is present. If AQC
226 * returns error (ENOENT), then no cage present. If no cage present, then
227 * connection type is backplane or BASE-T.
229 static enum ice_status
230 ice_aq_get_link_topo_handle(struct ice_port_info *pi, u8 node_type,
231 struct ice_sq_cd *cd)
233 struct ice_aqc_get_link_topo *cmd;
234 struct ice_aq_desc desc;
236 cmd = &desc.params.get_link_topo;
238 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_link_topo);
240 cmd->addr.topo_params.node_type_ctx =
241 (ICE_AQC_LINK_TOPO_NODE_CTX_PORT <<
242 ICE_AQC_LINK_TOPO_NODE_CTX_S);
245 cmd->addr.topo_params.node_type_ctx |=
246 (ICE_AQC_LINK_TOPO_NODE_TYPE_M & node_type);
248 return ice_aq_send_cmd(pi->hw, &desc, NULL, 0, cd);
252 * ice_is_media_cage_present
253 * @pi: port information structure
255 * Returns true if media cage is present, else false. If no cage, then
256 * media type is backplane or BASE-T.
258 static bool ice_is_media_cage_present(struct ice_port_info *pi)
260 /* Node type cage can be used to determine if cage is present. If AQC
261 * returns error (ENOENT), then no cage present. If no cage present then
262 * connection type is backplane or BASE-T.
264 return !ice_aq_get_link_topo_handle(pi,
265 ICE_AQC_LINK_TOPO_NODE_TYPE_CAGE,
270 * ice_get_media_type - Gets media type
271 * @pi: port information structure
273 static enum ice_media_type ice_get_media_type(struct ice_port_info *pi)
275 struct ice_link_status *hw_link_info;
278 return ICE_MEDIA_UNKNOWN;
280 hw_link_info = &pi->phy.link_info;
281 if (hw_link_info->phy_type_low && hw_link_info->phy_type_high)
282 /* If more than one media type is selected, report unknown */
283 return ICE_MEDIA_UNKNOWN;
285 if (hw_link_info->phy_type_low) {
286 /* 1G SGMII is a special case where some DA cable PHYs
287 * may show this as an option when it really shouldn't
288 * be since SGMII is meant to be between a MAC and a PHY
289 * in a backplane. Try to detect this case and handle it
291 if (hw_link_info->phy_type_low == ICE_PHY_TYPE_LOW_1G_SGMII &&
292 (hw_link_info->module_type[ICE_AQC_MOD_TYPE_IDENT] ==
293 ICE_AQC_MOD_TYPE_BYTE1_SFP_PLUS_CU_ACTIVE ||
294 hw_link_info->module_type[ICE_AQC_MOD_TYPE_IDENT] ==
295 ICE_AQC_MOD_TYPE_BYTE1_SFP_PLUS_CU_PASSIVE))
298 switch (hw_link_info->phy_type_low) {
299 case ICE_PHY_TYPE_LOW_1000BASE_SX:
300 case ICE_PHY_TYPE_LOW_1000BASE_LX:
301 case ICE_PHY_TYPE_LOW_10GBASE_SR:
302 case ICE_PHY_TYPE_LOW_10GBASE_LR:
303 case ICE_PHY_TYPE_LOW_10G_SFI_C2C:
304 case ICE_PHY_TYPE_LOW_25GBASE_SR:
305 case ICE_PHY_TYPE_LOW_25GBASE_LR:
306 case ICE_PHY_TYPE_LOW_40GBASE_SR4:
307 case ICE_PHY_TYPE_LOW_40GBASE_LR4:
308 case ICE_PHY_TYPE_LOW_50GBASE_SR2:
309 case ICE_PHY_TYPE_LOW_50GBASE_LR2:
310 case ICE_PHY_TYPE_LOW_50GBASE_SR:
311 case ICE_PHY_TYPE_LOW_50GBASE_FR:
312 case ICE_PHY_TYPE_LOW_50GBASE_LR:
313 case ICE_PHY_TYPE_LOW_100GBASE_SR4:
314 case ICE_PHY_TYPE_LOW_100GBASE_LR4:
315 case ICE_PHY_TYPE_LOW_100GBASE_SR2:
316 case ICE_PHY_TYPE_LOW_100GBASE_DR:
317 return ICE_MEDIA_FIBER;
318 case ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC:
319 case ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC:
320 case ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC:
321 case ICE_PHY_TYPE_LOW_50G_LAUI2_AOC_ACC:
322 case ICE_PHY_TYPE_LOW_50G_AUI2_AOC_ACC:
323 case ICE_PHY_TYPE_LOW_50G_AUI1_AOC_ACC:
324 case ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC:
325 case ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC:
326 return ICE_MEDIA_FIBER;
327 case ICE_PHY_TYPE_LOW_100BASE_TX:
328 case ICE_PHY_TYPE_LOW_1000BASE_T:
329 case ICE_PHY_TYPE_LOW_2500BASE_T:
330 case ICE_PHY_TYPE_LOW_5GBASE_T:
331 case ICE_PHY_TYPE_LOW_10GBASE_T:
332 case ICE_PHY_TYPE_LOW_25GBASE_T:
333 return ICE_MEDIA_BASET;
334 case ICE_PHY_TYPE_LOW_10G_SFI_DA:
335 case ICE_PHY_TYPE_LOW_25GBASE_CR:
336 case ICE_PHY_TYPE_LOW_25GBASE_CR_S:
337 case ICE_PHY_TYPE_LOW_25GBASE_CR1:
338 case ICE_PHY_TYPE_LOW_40GBASE_CR4:
339 case ICE_PHY_TYPE_LOW_50GBASE_CR2:
340 case ICE_PHY_TYPE_LOW_50GBASE_CP:
341 case ICE_PHY_TYPE_LOW_100GBASE_CR4:
342 case ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4:
343 case ICE_PHY_TYPE_LOW_100GBASE_CP2:
345 case ICE_PHY_TYPE_LOW_25G_AUI_C2C:
346 case ICE_PHY_TYPE_LOW_40G_XLAUI:
347 case ICE_PHY_TYPE_LOW_50G_LAUI2:
348 case ICE_PHY_TYPE_LOW_50G_AUI2:
349 case ICE_PHY_TYPE_LOW_50G_AUI1:
350 case ICE_PHY_TYPE_LOW_100G_AUI4:
351 case ICE_PHY_TYPE_LOW_100G_CAUI4:
352 if (ice_is_media_cage_present(pi))
353 return ICE_MEDIA_AUI;
355 case ICE_PHY_TYPE_LOW_1000BASE_KX:
356 case ICE_PHY_TYPE_LOW_2500BASE_KX:
357 case ICE_PHY_TYPE_LOW_2500BASE_X:
358 case ICE_PHY_TYPE_LOW_5GBASE_KR:
359 case ICE_PHY_TYPE_LOW_10GBASE_KR_CR1:
360 case ICE_PHY_TYPE_LOW_25GBASE_KR:
361 case ICE_PHY_TYPE_LOW_25GBASE_KR1:
362 case ICE_PHY_TYPE_LOW_25GBASE_KR_S:
363 case ICE_PHY_TYPE_LOW_40GBASE_KR4:
364 case ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4:
365 case ICE_PHY_TYPE_LOW_50GBASE_KR2:
366 case ICE_PHY_TYPE_LOW_100GBASE_KR4:
367 case ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4:
368 return ICE_MEDIA_BACKPLANE;
371 switch (hw_link_info->phy_type_high) {
372 case ICE_PHY_TYPE_HIGH_100G_AUI2:
373 case ICE_PHY_TYPE_HIGH_100G_CAUI2:
374 if (ice_is_media_cage_present(pi))
375 return ICE_MEDIA_AUI;
377 case ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4:
378 return ICE_MEDIA_BACKPLANE;
379 case ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC:
380 case ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC:
381 return ICE_MEDIA_FIBER;
384 return ICE_MEDIA_UNKNOWN;
388 * ice_aq_get_link_info
389 * @pi: port information structure
390 * @ena_lse: enable/disable LinkStatusEvent reporting
391 * @link: pointer to link status structure - optional
392 * @cd: pointer to command details structure or NULL
394 * Get Link Status (0x607). Returns the link status of the adapter.
397 ice_aq_get_link_info(struct ice_port_info *pi, bool ena_lse,
398 struct ice_link_status *link, struct ice_sq_cd *cd)
400 struct ice_aqc_get_link_status_data link_data = { 0 };
401 struct ice_aqc_get_link_status *resp;
402 struct ice_link_status *li_old, *li;
403 enum ice_media_type *hw_media_type;
404 struct ice_fc_info *hw_fc_info;
405 bool tx_pause, rx_pause;
406 struct ice_aq_desc desc;
407 enum ice_status status;
412 return ICE_ERR_PARAM;
414 li_old = &pi->phy.link_info_old;
415 hw_media_type = &pi->phy.media_type;
416 li = &pi->phy.link_info;
417 hw_fc_info = &pi->fc;
419 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_link_status);
420 cmd_flags = (ena_lse) ? ICE_AQ_LSE_ENA : ICE_AQ_LSE_DIS;
421 resp = &desc.params.get_link_status;
422 resp->cmd_flags = CPU_TO_LE16(cmd_flags);
423 resp->lport_num = pi->lport;
425 status = ice_aq_send_cmd(hw, &desc, &link_data, sizeof(link_data), cd);
427 if (status != ICE_SUCCESS)
430 /* save off old link status information */
433 /* update current link status information */
434 li->link_speed = LE16_TO_CPU(link_data.link_speed);
435 li->phy_type_low = LE64_TO_CPU(link_data.phy_type_low);
436 li->phy_type_high = LE64_TO_CPU(link_data.phy_type_high);
437 *hw_media_type = ice_get_media_type(pi);
438 li->link_info = link_data.link_info;
439 li->link_cfg_err = link_data.link_cfg_err;
440 li->an_info = link_data.an_info;
441 li->ext_info = link_data.ext_info;
442 li->max_frame_size = LE16_TO_CPU(link_data.max_frame_size);
443 li->fec_info = link_data.cfg & ICE_AQ_FEC_MASK;
444 li->topo_media_conflict = link_data.topo_media_conflict;
445 li->pacing = link_data.cfg & (ICE_AQ_CFG_PACING_M |
446 ICE_AQ_CFG_PACING_TYPE_M);
449 tx_pause = !!(link_data.an_info & ICE_AQ_LINK_PAUSE_TX);
450 rx_pause = !!(link_data.an_info & ICE_AQ_LINK_PAUSE_RX);
451 if (tx_pause && rx_pause)
452 hw_fc_info->current_mode = ICE_FC_FULL;
454 hw_fc_info->current_mode = ICE_FC_TX_PAUSE;
456 hw_fc_info->current_mode = ICE_FC_RX_PAUSE;
458 hw_fc_info->current_mode = ICE_FC_NONE;
460 li->lse_ena = !!(resp->cmd_flags & CPU_TO_LE16(ICE_AQ_LSE_IS_ENABLED));
462 ice_debug(hw, ICE_DBG_LINK, "get link info\n");
463 ice_debug(hw, ICE_DBG_LINK, " link_speed = 0x%x\n", li->link_speed);
464 ice_debug(hw, ICE_DBG_LINK, " phy_type_low = 0x%llx\n",
465 (unsigned long long)li->phy_type_low);
466 ice_debug(hw, ICE_DBG_LINK, " phy_type_high = 0x%llx\n",
467 (unsigned long long)li->phy_type_high);
468 ice_debug(hw, ICE_DBG_LINK, " media_type = 0x%x\n", *hw_media_type);
469 ice_debug(hw, ICE_DBG_LINK, " link_info = 0x%x\n", li->link_info);
470 ice_debug(hw, ICE_DBG_LINK, " link_cfg_err = 0x%x\n", li->link_cfg_err);
471 ice_debug(hw, ICE_DBG_LINK, " an_info = 0x%x\n", li->an_info);
472 ice_debug(hw, ICE_DBG_LINK, " ext_info = 0x%x\n", li->ext_info);
473 ice_debug(hw, ICE_DBG_LINK, " fec_info = 0x%x\n", li->fec_info);
474 ice_debug(hw, ICE_DBG_LINK, " lse_ena = 0x%x\n", li->lse_ena);
475 ice_debug(hw, ICE_DBG_LINK, " max_frame = 0x%x\n",
477 ice_debug(hw, ICE_DBG_LINK, " pacing = 0x%x\n", li->pacing);
479 /* save link status information */
483 /* flag cleared so calling functions don't call AQ again */
484 pi->phy.get_link_info = false;
490 * ice_fill_tx_timer_and_fc_thresh
491 * @hw: pointer to the HW struct
492 * @cmd: pointer to MAC cfg structure
494 * Add Tx timer and FC refresh threshold info to Set MAC Config AQ command
498 ice_fill_tx_timer_and_fc_thresh(struct ice_hw *hw,
499 struct ice_aqc_set_mac_cfg *cmd)
501 u16 fc_thres_val, tx_timer_val;
504 /* We read back the transmit timer and fc threshold value of
505 * LFC. Thus, we will use index =
506 * PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA_MAX_INDEX.
508 * Also, because we are opearating on transmit timer and fc
509 * threshold of LFC, we don't turn on any bit in tx_tmr_priority
511 #define IDX_OF_LFC PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA_MAX_INDEX
513 /* Retrieve the transmit timer */
514 val = rd32(hw, PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA(IDX_OF_LFC));
516 PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA_HSEC_CTL_TX_PAUSE_QUANTA_M;
517 cmd->tx_tmr_value = CPU_TO_LE16(tx_timer_val);
519 /* Retrieve the fc threshold */
520 val = rd32(hw, PRTMAC_HSEC_CTL_TX_PAUSE_REFRESH_TIMER(IDX_OF_LFC));
521 fc_thres_val = val & PRTMAC_HSEC_CTL_TX_PAUSE_REFRESH_TIMER_M;
523 cmd->fc_refresh_threshold = CPU_TO_LE16(fc_thres_val);
528 * @hw: pointer to the HW struct
529 * @max_frame_size: Maximum Frame Size to be supported
530 * @cd: pointer to command details structure or NULL
532 * Set MAC configuration (0x0603)
535 ice_aq_set_mac_cfg(struct ice_hw *hw, u16 max_frame_size, struct ice_sq_cd *cd)
537 struct ice_aqc_set_mac_cfg *cmd;
538 struct ice_aq_desc desc;
540 cmd = &desc.params.set_mac_cfg;
542 if (max_frame_size == 0)
543 return ICE_ERR_PARAM;
545 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_mac_cfg);
547 cmd->max_frame_size = CPU_TO_LE16(max_frame_size);
549 ice_fill_tx_timer_and_fc_thresh(hw, cmd);
551 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
555 * ice_init_fltr_mgmt_struct - initializes filter management list and locks
556 * @hw: pointer to the HW struct
558 enum ice_status ice_init_fltr_mgmt_struct(struct ice_hw *hw)
560 struct ice_switch_info *sw;
561 enum ice_status status;
563 hw->switch_info = (struct ice_switch_info *)
564 ice_malloc(hw, sizeof(*hw->switch_info));
566 sw = hw->switch_info;
569 return ICE_ERR_NO_MEMORY;
571 INIT_LIST_HEAD(&sw->vsi_list_map_head);
572 sw->prof_res_bm_init = 0;
574 status = ice_init_def_sw_recp(hw, &hw->switch_info->recp_list);
576 ice_free(hw, hw->switch_info);
583 * ice_cleanup_fltr_mgmt_single - clears single filter mngt struct
584 * @hw: pointer to the HW struct
585 * @sw: pointer to switch info struct for which function clears filters
588 ice_cleanup_fltr_mgmt_single(struct ice_hw *hw, struct ice_switch_info *sw)
590 struct ice_vsi_list_map_info *v_pos_map;
591 struct ice_vsi_list_map_info *v_tmp_map;
592 struct ice_sw_recipe *recps;
598 LIST_FOR_EACH_ENTRY_SAFE(v_pos_map, v_tmp_map, &sw->vsi_list_map_head,
599 ice_vsi_list_map_info, list_entry) {
600 LIST_DEL(&v_pos_map->list_entry);
601 ice_free(hw, v_pos_map);
603 recps = sw->recp_list;
604 for (i = 0; i < ICE_MAX_NUM_RECIPES; i++) {
605 struct ice_recp_grp_entry *rg_entry, *tmprg_entry;
607 recps[i].root_rid = i;
608 LIST_FOR_EACH_ENTRY_SAFE(rg_entry, tmprg_entry,
609 &recps[i].rg_list, ice_recp_grp_entry,
611 LIST_DEL(&rg_entry->l_entry);
612 ice_free(hw, rg_entry);
615 if (recps[i].adv_rule) {
616 struct ice_adv_fltr_mgmt_list_entry *tmp_entry;
617 struct ice_adv_fltr_mgmt_list_entry *lst_itr;
619 ice_destroy_lock(&recps[i].filt_rule_lock);
620 LIST_FOR_EACH_ENTRY_SAFE(lst_itr, tmp_entry,
621 &recps[i].filt_rules,
622 ice_adv_fltr_mgmt_list_entry,
624 LIST_DEL(&lst_itr->list_entry);
625 ice_free(hw, lst_itr->lkups);
626 ice_free(hw, lst_itr);
629 struct ice_fltr_mgmt_list_entry *lst_itr, *tmp_entry;
631 ice_destroy_lock(&recps[i].filt_rule_lock);
632 LIST_FOR_EACH_ENTRY_SAFE(lst_itr, tmp_entry,
633 &recps[i].filt_rules,
634 ice_fltr_mgmt_list_entry,
636 LIST_DEL(&lst_itr->list_entry);
637 ice_free(hw, lst_itr);
640 if (recps[i].root_buf)
641 ice_free(hw, recps[i].root_buf);
643 ice_rm_sw_replay_rule_info(hw, sw);
644 ice_free(hw, sw->recp_list);
649 * ice_cleanup_fltr_mgmt_struct - cleanup filter management list and locks
650 * @hw: pointer to the HW struct
652 void ice_cleanup_fltr_mgmt_struct(struct ice_hw *hw)
654 ice_cleanup_fltr_mgmt_single(hw, hw->switch_info);
658 * ice_get_itr_intrl_gran
659 * @hw: pointer to the HW struct
661 * Determines the ITR/INTRL granularities based on the maximum aggregate
662 * bandwidth according to the device's configuration during power-on.
664 static void ice_get_itr_intrl_gran(struct ice_hw *hw)
666 u8 max_agg_bw = (rd32(hw, GL_PWR_MODE_CTL) &
667 GL_PWR_MODE_CTL_CAR_MAX_BW_M) >>
668 GL_PWR_MODE_CTL_CAR_MAX_BW_S;
670 switch (max_agg_bw) {
671 case ICE_MAX_AGG_BW_200G:
672 case ICE_MAX_AGG_BW_100G:
673 case ICE_MAX_AGG_BW_50G:
674 hw->itr_gran = ICE_ITR_GRAN_ABOVE_25;
675 hw->intrl_gran = ICE_INTRL_GRAN_ABOVE_25;
677 case ICE_MAX_AGG_BW_25G:
678 hw->itr_gran = ICE_ITR_GRAN_MAX_25;
679 hw->intrl_gran = ICE_INTRL_GRAN_MAX_25;
685 * ice_print_rollback_msg - print FW rollback message
686 * @hw: pointer to the hardware structure
688 void ice_print_rollback_msg(struct ice_hw *hw)
690 char nvm_str[ICE_NVM_VER_LEN] = { 0 };
691 struct ice_orom_info *orom;
692 struct ice_nvm_info *nvm;
694 orom = &hw->flash.orom;
695 nvm = &hw->flash.nvm;
697 SNPRINTF(nvm_str, sizeof(nvm_str), "%x.%02x 0x%x %d.%d.%d",
698 nvm->major, nvm->minor, nvm->eetrack, orom->major,
699 orom->build, orom->patch);
701 "Firmware rollback mode detected. Current version is NVM: %s, FW: %d.%d. Device may exhibit limited functionality. Refer to the Intel(R) Ethernet Adapters and Devices User Guide for details on firmware rollback mode\n",
702 nvm_str, hw->fw_maj_ver, hw->fw_min_ver);
706 * ice_init_hw - main hardware initialization routine
707 * @hw: pointer to the hardware structure
709 enum ice_status ice_init_hw(struct ice_hw *hw)
711 struct ice_aqc_get_phy_caps_data *pcaps;
712 enum ice_status status;
716 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
718 /* Set MAC type based on DeviceID */
719 status = ice_set_mac_type(hw);
723 hw->pf_id = (u8)(rd32(hw, PF_FUNC_RID) &
724 PF_FUNC_RID_FUNCTION_NUMBER_M) >>
725 PF_FUNC_RID_FUNCTION_NUMBER_S;
727 status = ice_reset(hw, ICE_RESET_PFR);
731 ice_get_itr_intrl_gran(hw);
733 status = ice_create_all_ctrlq(hw);
735 goto err_unroll_cqinit;
737 status = ice_init_nvm(hw);
739 goto err_unroll_cqinit;
741 if (ice_get_fw_mode(hw) == ICE_FW_MODE_ROLLBACK)
742 ice_print_rollback_msg(hw);
744 status = ice_clear_pf_cfg(hw);
746 goto err_unroll_cqinit;
748 /* Set bit to enable Flow Director filters */
749 wr32(hw, PFQF_FD_ENA, PFQF_FD_ENA_FD_ENA_M);
750 INIT_LIST_HEAD(&hw->fdir_list_head);
752 ice_clear_pxe_mode(hw);
754 status = ice_get_caps(hw);
756 goto err_unroll_cqinit;
758 hw->port_info = (struct ice_port_info *)
759 ice_malloc(hw, sizeof(*hw->port_info));
760 if (!hw->port_info) {
761 status = ICE_ERR_NO_MEMORY;
762 goto err_unroll_cqinit;
765 /* set the back pointer to HW */
766 hw->port_info->hw = hw;
768 /* Initialize port_info struct with switch configuration data */
769 status = ice_get_initial_sw_cfg(hw);
771 goto err_unroll_alloc;
774 /* Query the allocated resources for Tx scheduler */
775 status = ice_sched_query_res_alloc(hw);
777 ice_debug(hw, ICE_DBG_SCHED, "Failed to get scheduler allocated resources\n");
778 goto err_unroll_alloc;
780 ice_sched_get_psm_clk_freq(hw);
782 /* Initialize port_info struct with scheduler data */
783 status = ice_sched_init_port(hw->port_info);
785 goto err_unroll_sched;
786 pcaps = (struct ice_aqc_get_phy_caps_data *)
787 ice_malloc(hw, sizeof(*pcaps));
789 status = ICE_ERR_NO_MEMORY;
790 goto err_unroll_sched;
793 /* Initialize port_info struct with PHY capabilities */
794 status = ice_aq_get_phy_caps(hw->port_info, false,
795 ICE_AQC_REPORT_TOPO_CAP_MEDIA, pcaps, NULL);
798 ice_warn(hw, "Get PHY capabilities failed status = %d, continuing anyway\n",
801 /* Initialize port_info struct with link information */
802 status = ice_aq_get_link_info(hw->port_info, false, NULL, NULL);
804 goto err_unroll_sched;
805 /* need a valid SW entry point to build a Tx tree */
806 if (!hw->sw_entry_point_layer) {
807 ice_debug(hw, ICE_DBG_SCHED, "invalid sw entry point\n");
808 status = ICE_ERR_CFG;
809 goto err_unroll_sched;
811 INIT_LIST_HEAD(&hw->agg_list);
812 /* Initialize max burst size */
813 if (!hw->max_burst_size)
814 ice_cfg_rl_burst_size(hw, ICE_SCHED_DFLT_BURST_SIZE);
815 status = ice_init_fltr_mgmt_struct(hw);
817 goto err_unroll_sched;
819 /* Get MAC information */
820 /* A single port can report up to two (LAN and WoL) addresses */
821 mac_buf = ice_calloc(hw, 2,
822 sizeof(struct ice_aqc_manage_mac_read_resp));
823 mac_buf_len = 2 * sizeof(struct ice_aqc_manage_mac_read_resp);
826 status = ICE_ERR_NO_MEMORY;
827 goto err_unroll_fltr_mgmt_struct;
830 status = ice_aq_manage_mac_read(hw, mac_buf, mac_buf_len, NULL);
831 ice_free(hw, mac_buf);
834 goto err_unroll_fltr_mgmt_struct;
835 /* Obtain counter base index which would be used by flow director */
836 status = ice_alloc_fd_res_cntr(hw, &hw->fd_ctr_base);
838 goto err_unroll_fltr_mgmt_struct;
839 status = ice_init_hw_tbls(hw);
841 goto err_unroll_fltr_mgmt_struct;
842 ice_init_lock(&hw->tnl_lock);
846 err_unroll_fltr_mgmt_struct:
847 ice_cleanup_fltr_mgmt_struct(hw);
849 ice_sched_cleanup_all(hw);
851 ice_free(hw, hw->port_info);
852 hw->port_info = NULL;
854 ice_destroy_all_ctrlq(hw);
859 * ice_deinit_hw - unroll initialization operations done by ice_init_hw
860 * @hw: pointer to the hardware structure
862 * This should be called only during nominal operation, not as a result of
863 * ice_init_hw() failing since ice_init_hw() will take care of unrolling
864 * applicable initializations if it fails for any reason.
866 void ice_deinit_hw(struct ice_hw *hw)
868 ice_free_fd_res_cntr(hw, hw->fd_ctr_base);
869 ice_cleanup_fltr_mgmt_struct(hw);
871 ice_sched_cleanup_all(hw);
872 ice_sched_clear_agg(hw);
874 ice_free_hw_tbls(hw);
875 ice_destroy_lock(&hw->tnl_lock);
878 ice_free(hw, hw->port_info);
879 hw->port_info = NULL;
882 ice_destroy_all_ctrlq(hw);
884 /* Clear VSI contexts if not already cleared */
885 ice_clear_all_vsi_ctx(hw);
889 * ice_check_reset - Check to see if a global reset is complete
890 * @hw: pointer to the hardware structure
892 enum ice_status ice_check_reset(struct ice_hw *hw)
894 u32 cnt, reg = 0, grst_timeout, uld_mask;
896 /* Poll for Device Active state in case a recent CORER, GLOBR,
897 * or EMPR has occurred. The grst delay value is in 100ms units.
898 * Add 1sec for outstanding AQ commands that can take a long time.
900 grst_timeout = ((rd32(hw, GLGEN_RSTCTL) & GLGEN_RSTCTL_GRSTDEL_M) >>
901 GLGEN_RSTCTL_GRSTDEL_S) + 10;
903 for (cnt = 0; cnt < grst_timeout; cnt++) {
904 ice_msec_delay(100, true);
905 reg = rd32(hw, GLGEN_RSTAT);
906 if (!(reg & GLGEN_RSTAT_DEVSTATE_M))
910 if (cnt == grst_timeout) {
911 ice_debug(hw, ICE_DBG_INIT, "Global reset polling failed to complete.\n");
912 return ICE_ERR_RESET_FAILED;
915 #define ICE_RESET_DONE_MASK (GLNVM_ULD_PCIER_DONE_M |\
916 GLNVM_ULD_PCIER_DONE_1_M |\
917 GLNVM_ULD_CORER_DONE_M |\
918 GLNVM_ULD_GLOBR_DONE_M |\
919 GLNVM_ULD_POR_DONE_M |\
920 GLNVM_ULD_POR_DONE_1_M |\
921 GLNVM_ULD_PCIER_DONE_2_M)
923 uld_mask = ICE_RESET_DONE_MASK;
925 /* Device is Active; check Global Reset processes are done */
926 for (cnt = 0; cnt < ICE_PF_RESET_WAIT_COUNT; cnt++) {
927 reg = rd32(hw, GLNVM_ULD) & uld_mask;
928 if (reg == uld_mask) {
929 ice_debug(hw, ICE_DBG_INIT, "Global reset processes done. %d\n", cnt);
932 ice_msec_delay(10, true);
935 if (cnt == ICE_PF_RESET_WAIT_COUNT) {
936 ice_debug(hw, ICE_DBG_INIT, "Wait for Reset Done timed out. GLNVM_ULD = 0x%x\n",
938 return ICE_ERR_RESET_FAILED;
945 * ice_pf_reset - Reset the PF
946 * @hw: pointer to the hardware structure
948 * If a global reset has been triggered, this function checks
949 * for its completion and then issues the PF reset
951 static enum ice_status ice_pf_reset(struct ice_hw *hw)
955 /* If at function entry a global reset was already in progress, i.e.
956 * state is not 'device active' or any of the reset done bits are not
957 * set in GLNVM_ULD, there is no need for a PF Reset; poll until the
958 * global reset is done.
960 if ((rd32(hw, GLGEN_RSTAT) & GLGEN_RSTAT_DEVSTATE_M) ||
961 (rd32(hw, GLNVM_ULD) & ICE_RESET_DONE_MASK) ^ ICE_RESET_DONE_MASK) {
962 /* poll on global reset currently in progress until done */
963 if (ice_check_reset(hw))
964 return ICE_ERR_RESET_FAILED;
970 reg = rd32(hw, PFGEN_CTRL);
972 wr32(hw, PFGEN_CTRL, (reg | PFGEN_CTRL_PFSWR_M));
974 /* Wait for the PFR to complete. The wait time is the global config lock
975 * timeout plus the PFR timeout which will account for a possible reset
976 * that is occurring during a download package operation.
978 for (cnt = 0; cnt < ICE_GLOBAL_CFG_LOCK_TIMEOUT +
979 ICE_PF_RESET_WAIT_COUNT; cnt++) {
980 reg = rd32(hw, PFGEN_CTRL);
981 if (!(reg & PFGEN_CTRL_PFSWR_M))
984 ice_msec_delay(1, true);
987 if (cnt == ICE_PF_RESET_WAIT_COUNT) {
988 ice_debug(hw, ICE_DBG_INIT, "PF reset polling failed to complete.\n");
989 return ICE_ERR_RESET_FAILED;
996 * ice_reset - Perform different types of reset
997 * @hw: pointer to the hardware structure
998 * @req: reset request
1000 * This function triggers a reset as specified by the req parameter.
1003 * If anything other than a PF reset is triggered, PXE mode is restored.
1004 * This has to be cleared using ice_clear_pxe_mode again, once the AQ
1005 * interface has been restored in the rebuild flow.
1007 enum ice_status ice_reset(struct ice_hw *hw, enum ice_reset_req req)
1013 return ice_pf_reset(hw);
1014 case ICE_RESET_CORER:
1015 ice_debug(hw, ICE_DBG_INIT, "CoreR requested\n");
1016 val = GLGEN_RTRIG_CORER_M;
1018 case ICE_RESET_GLOBR:
1019 ice_debug(hw, ICE_DBG_INIT, "GlobalR requested\n");
1020 val = GLGEN_RTRIG_GLOBR_M;
1023 return ICE_ERR_PARAM;
1026 val |= rd32(hw, GLGEN_RTRIG);
1027 wr32(hw, GLGEN_RTRIG, val);
1030 /* wait for the FW to be ready */
1031 return ice_check_reset(hw);
1035 * ice_copy_rxq_ctx_to_hw
1036 * @hw: pointer to the hardware structure
1037 * @ice_rxq_ctx: pointer to the rxq context
1038 * @rxq_index: the index of the Rx queue
1040 * Copies rxq context from dense structure to HW register space
1042 static enum ice_status
1043 ice_copy_rxq_ctx_to_hw(struct ice_hw *hw, u8 *ice_rxq_ctx, u32 rxq_index)
1048 return ICE_ERR_BAD_PTR;
1050 if (rxq_index > QRX_CTRL_MAX_INDEX)
1051 return ICE_ERR_PARAM;
1053 /* Copy each dword separately to HW */
1054 for (i = 0; i < ICE_RXQ_CTX_SIZE_DWORDS; i++) {
1055 wr32(hw, QRX_CONTEXT(i, rxq_index),
1056 *((u32 *)(ice_rxq_ctx + (i * sizeof(u32)))));
1058 ice_debug(hw, ICE_DBG_QCTX, "qrxdata[%d]: %08X\n", i,
1059 *((u32 *)(ice_rxq_ctx + (i * sizeof(u32)))));
1065 /* LAN Rx Queue Context */
1066 static const struct ice_ctx_ele ice_rlan_ctx_info[] = {
1067 /* Field Width LSB */
1068 ICE_CTX_STORE(ice_rlan_ctx, head, 13, 0),
1069 ICE_CTX_STORE(ice_rlan_ctx, cpuid, 8, 13),
1070 ICE_CTX_STORE(ice_rlan_ctx, base, 57, 32),
1071 ICE_CTX_STORE(ice_rlan_ctx, qlen, 13, 89),
1072 ICE_CTX_STORE(ice_rlan_ctx, dbuf, 7, 102),
1073 ICE_CTX_STORE(ice_rlan_ctx, hbuf, 5, 109),
1074 ICE_CTX_STORE(ice_rlan_ctx, dtype, 2, 114),
1075 ICE_CTX_STORE(ice_rlan_ctx, dsize, 1, 116),
1076 ICE_CTX_STORE(ice_rlan_ctx, crcstrip, 1, 117),
1077 ICE_CTX_STORE(ice_rlan_ctx, l2tsel, 1, 119),
1078 ICE_CTX_STORE(ice_rlan_ctx, hsplit_0, 4, 120),
1079 ICE_CTX_STORE(ice_rlan_ctx, hsplit_1, 2, 124),
1080 ICE_CTX_STORE(ice_rlan_ctx, showiv, 1, 127),
1081 ICE_CTX_STORE(ice_rlan_ctx, rxmax, 14, 174),
1082 ICE_CTX_STORE(ice_rlan_ctx, tphrdesc_ena, 1, 193),
1083 ICE_CTX_STORE(ice_rlan_ctx, tphwdesc_ena, 1, 194),
1084 ICE_CTX_STORE(ice_rlan_ctx, tphdata_ena, 1, 195),
1085 ICE_CTX_STORE(ice_rlan_ctx, tphhead_ena, 1, 196),
1086 ICE_CTX_STORE(ice_rlan_ctx, lrxqthresh, 3, 198),
1087 ICE_CTX_STORE(ice_rlan_ctx, prefena, 1, 201),
1093 * @hw: pointer to the hardware structure
1094 * @rlan_ctx: pointer to the rxq context
1095 * @rxq_index: the index of the Rx queue
1097 * Converts rxq context from sparse to dense structure and then writes
1098 * it to HW register space and enables the hardware to prefetch descriptors
1099 * instead of only fetching them on demand
1102 ice_write_rxq_ctx(struct ice_hw *hw, struct ice_rlan_ctx *rlan_ctx,
1105 u8 ctx_buf[ICE_RXQ_CTX_SZ] = { 0 };
1108 return ICE_ERR_BAD_PTR;
1110 rlan_ctx->prefena = 1;
1112 ice_set_ctx(hw, (u8 *)rlan_ctx, ctx_buf, ice_rlan_ctx_info);
1113 return ice_copy_rxq_ctx_to_hw(hw, ctx_buf, rxq_index);
1118 * @hw: pointer to the hardware structure
1119 * @rxq_index: the index of the Rx queue to clear
1121 * Clears rxq context in HW register space
1123 enum ice_status ice_clear_rxq_ctx(struct ice_hw *hw, u32 rxq_index)
1127 if (rxq_index > QRX_CTRL_MAX_INDEX)
1128 return ICE_ERR_PARAM;
1130 /* Clear each dword register separately */
1131 for (i = 0; i < ICE_RXQ_CTX_SIZE_DWORDS; i++)
1132 wr32(hw, QRX_CONTEXT(i, rxq_index), 0);
1137 /* LAN Tx Queue Context */
1138 const struct ice_ctx_ele ice_tlan_ctx_info[] = {
1139 /* Field Width LSB */
1140 ICE_CTX_STORE(ice_tlan_ctx, base, 57, 0),
1141 ICE_CTX_STORE(ice_tlan_ctx, port_num, 3, 57),
1142 ICE_CTX_STORE(ice_tlan_ctx, cgd_num, 5, 60),
1143 ICE_CTX_STORE(ice_tlan_ctx, pf_num, 3, 65),
1144 ICE_CTX_STORE(ice_tlan_ctx, vmvf_num, 10, 68),
1145 ICE_CTX_STORE(ice_tlan_ctx, vmvf_type, 2, 78),
1146 ICE_CTX_STORE(ice_tlan_ctx, src_vsi, 10, 80),
1147 ICE_CTX_STORE(ice_tlan_ctx, tsyn_ena, 1, 90),
1148 ICE_CTX_STORE(ice_tlan_ctx, internal_usage_flag, 1, 91),
1149 ICE_CTX_STORE(ice_tlan_ctx, alt_vlan, 1, 92),
1150 ICE_CTX_STORE(ice_tlan_ctx, cpuid, 8, 93),
1151 ICE_CTX_STORE(ice_tlan_ctx, wb_mode, 1, 101),
1152 ICE_CTX_STORE(ice_tlan_ctx, tphrd_desc, 1, 102),
1153 ICE_CTX_STORE(ice_tlan_ctx, tphrd, 1, 103),
1154 ICE_CTX_STORE(ice_tlan_ctx, tphwr_desc, 1, 104),
1155 ICE_CTX_STORE(ice_tlan_ctx, cmpq_id, 9, 105),
1156 ICE_CTX_STORE(ice_tlan_ctx, qnum_in_func, 14, 114),
1157 ICE_CTX_STORE(ice_tlan_ctx, itr_notification_mode, 1, 128),
1158 ICE_CTX_STORE(ice_tlan_ctx, adjust_prof_id, 6, 129),
1159 ICE_CTX_STORE(ice_tlan_ctx, qlen, 13, 135),
1160 ICE_CTX_STORE(ice_tlan_ctx, quanta_prof_idx, 4, 148),
1161 ICE_CTX_STORE(ice_tlan_ctx, tso_ena, 1, 152),
1162 ICE_CTX_STORE(ice_tlan_ctx, tso_qnum, 11, 153),
1163 ICE_CTX_STORE(ice_tlan_ctx, legacy_int, 1, 164),
1164 ICE_CTX_STORE(ice_tlan_ctx, drop_ena, 1, 165),
1165 ICE_CTX_STORE(ice_tlan_ctx, cache_prof_idx, 2, 166),
1166 ICE_CTX_STORE(ice_tlan_ctx, pkt_shaper_prof_idx, 3, 168),
1167 ICE_CTX_STORE(ice_tlan_ctx, int_q_state, 122, 171),
1172 * ice_copy_tx_cmpltnq_ctx_to_hw
1173 * @hw: pointer to the hardware structure
1174 * @ice_tx_cmpltnq_ctx: pointer to the Tx completion queue context
1175 * @tx_cmpltnq_index: the index of the completion queue
1177 * Copies Tx completion queue context from dense structure to HW register space
1179 static enum ice_status
1180 ice_copy_tx_cmpltnq_ctx_to_hw(struct ice_hw *hw, u8 *ice_tx_cmpltnq_ctx,
1181 u32 tx_cmpltnq_index)
1185 if (!ice_tx_cmpltnq_ctx)
1186 return ICE_ERR_BAD_PTR;
1188 if (tx_cmpltnq_index > GLTCLAN_CQ_CNTX0_MAX_INDEX)
1189 return ICE_ERR_PARAM;
1191 /* Copy each dword separately to HW */
1192 for (i = 0; i < ICE_TX_CMPLTNQ_CTX_SIZE_DWORDS; i++) {
1193 wr32(hw, GLTCLAN_CQ_CNTX(i, tx_cmpltnq_index),
1194 *((u32 *)(ice_tx_cmpltnq_ctx + (i * sizeof(u32)))));
1196 ice_debug(hw, ICE_DBG_QCTX, "cmpltnqdata[%d]: %08X\n", i,
1197 *((u32 *)(ice_tx_cmpltnq_ctx + (i * sizeof(u32)))));
1203 /* LAN Tx Completion Queue Context */
1204 static const struct ice_ctx_ele ice_tx_cmpltnq_ctx_info[] = {
1205 /* Field Width LSB */
1206 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, base, 57, 0),
1207 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, q_len, 18, 64),
1208 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, generation, 1, 96),
1209 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, wrt_ptr, 22, 97),
1210 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, pf_num, 3, 128),
1211 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, vmvf_num, 10, 131),
1212 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, vmvf_type, 2, 141),
1213 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, tph_desc_wr, 1, 160),
1214 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, cpuid, 8, 161),
1215 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, cmpltn_cache, 512, 192),
1220 * ice_write_tx_cmpltnq_ctx
1221 * @hw: pointer to the hardware structure
1222 * @tx_cmpltnq_ctx: pointer to the completion queue context
1223 * @tx_cmpltnq_index: the index of the completion queue
1225 * Converts completion queue context from sparse to dense structure and then
1226 * writes it to HW register space
1229 ice_write_tx_cmpltnq_ctx(struct ice_hw *hw,
1230 struct ice_tx_cmpltnq_ctx *tx_cmpltnq_ctx,
1231 u32 tx_cmpltnq_index)
1233 u8 ctx_buf[ICE_TX_CMPLTNQ_CTX_SIZE_DWORDS * sizeof(u32)] = { 0 };
1235 ice_set_ctx(hw, (u8 *)tx_cmpltnq_ctx, ctx_buf, ice_tx_cmpltnq_ctx_info);
1236 return ice_copy_tx_cmpltnq_ctx_to_hw(hw, ctx_buf, tx_cmpltnq_index);
1240 * ice_clear_tx_cmpltnq_ctx
1241 * @hw: pointer to the hardware structure
1242 * @tx_cmpltnq_index: the index of the completion queue to clear
1244 * Clears Tx completion queue context in HW register space
1247 ice_clear_tx_cmpltnq_ctx(struct ice_hw *hw, u32 tx_cmpltnq_index)
1251 if (tx_cmpltnq_index > GLTCLAN_CQ_CNTX0_MAX_INDEX)
1252 return ICE_ERR_PARAM;
1254 /* Clear each dword register separately */
1255 for (i = 0; i < ICE_TX_CMPLTNQ_CTX_SIZE_DWORDS; i++)
1256 wr32(hw, GLTCLAN_CQ_CNTX(i, tx_cmpltnq_index), 0);
1262 * ice_copy_tx_drbell_q_ctx_to_hw
1263 * @hw: pointer to the hardware structure
1264 * @ice_tx_drbell_q_ctx: pointer to the doorbell queue context
1265 * @tx_drbell_q_index: the index of the doorbell queue
1267 * Copies doorbell queue context from dense structure to HW register space
1269 static enum ice_status
1270 ice_copy_tx_drbell_q_ctx_to_hw(struct ice_hw *hw, u8 *ice_tx_drbell_q_ctx,
1271 u32 tx_drbell_q_index)
1275 if (!ice_tx_drbell_q_ctx)
1276 return ICE_ERR_BAD_PTR;
1278 if (tx_drbell_q_index > QTX_COMM_DBLQ_DBELL_MAX_INDEX)
1279 return ICE_ERR_PARAM;
1281 /* Copy each dword separately to HW */
1282 for (i = 0; i < ICE_TX_DRBELL_Q_CTX_SIZE_DWORDS; i++) {
1283 wr32(hw, QTX_COMM_DBLQ_CNTX(i, tx_drbell_q_index),
1284 *((u32 *)(ice_tx_drbell_q_ctx + (i * sizeof(u32)))));
1286 ice_debug(hw, ICE_DBG_QCTX, "tx_drbell_qdata[%d]: %08X\n", i,
1287 *((u32 *)(ice_tx_drbell_q_ctx + (i * sizeof(u32)))));
1293 /* LAN Tx Doorbell Queue Context info */
1294 static const struct ice_ctx_ele ice_tx_drbell_q_ctx_info[] = {
1295 /* Field Width LSB */
1296 ICE_CTX_STORE(ice_tx_drbell_q_ctx, base, 57, 0),
1297 ICE_CTX_STORE(ice_tx_drbell_q_ctx, ring_len, 13, 64),
1298 ICE_CTX_STORE(ice_tx_drbell_q_ctx, pf_num, 3, 80),
1299 ICE_CTX_STORE(ice_tx_drbell_q_ctx, vf_num, 8, 84),
1300 ICE_CTX_STORE(ice_tx_drbell_q_ctx, vmvf_type, 2, 94),
1301 ICE_CTX_STORE(ice_tx_drbell_q_ctx, cpuid, 8, 96),
1302 ICE_CTX_STORE(ice_tx_drbell_q_ctx, tph_desc_rd, 1, 104),
1303 ICE_CTX_STORE(ice_tx_drbell_q_ctx, tph_desc_wr, 1, 108),
1304 ICE_CTX_STORE(ice_tx_drbell_q_ctx, db_q_en, 1, 112),
1305 ICE_CTX_STORE(ice_tx_drbell_q_ctx, rd_head, 13, 128),
1306 ICE_CTX_STORE(ice_tx_drbell_q_ctx, rd_tail, 13, 144),
1311 * ice_write_tx_drbell_q_ctx
1312 * @hw: pointer to the hardware structure
1313 * @tx_drbell_q_ctx: pointer to the doorbell queue context
1314 * @tx_drbell_q_index: the index of the doorbell queue
1316 * Converts doorbell queue context from sparse to dense structure and then
1317 * writes it to HW register space
1320 ice_write_tx_drbell_q_ctx(struct ice_hw *hw,
1321 struct ice_tx_drbell_q_ctx *tx_drbell_q_ctx,
1322 u32 tx_drbell_q_index)
1324 u8 ctx_buf[ICE_TX_DRBELL_Q_CTX_SIZE_DWORDS * sizeof(u32)] = { 0 };
1326 ice_set_ctx(hw, (u8 *)tx_drbell_q_ctx, ctx_buf,
1327 ice_tx_drbell_q_ctx_info);
1328 return ice_copy_tx_drbell_q_ctx_to_hw(hw, ctx_buf, tx_drbell_q_index);
1332 * ice_clear_tx_drbell_q_ctx
1333 * @hw: pointer to the hardware structure
1334 * @tx_drbell_q_index: the index of the doorbell queue to clear
1336 * Clears doorbell queue context in HW register space
1339 ice_clear_tx_drbell_q_ctx(struct ice_hw *hw, u32 tx_drbell_q_index)
1343 if (tx_drbell_q_index > QTX_COMM_DBLQ_DBELL_MAX_INDEX)
1344 return ICE_ERR_PARAM;
1346 /* Clear each dword register separately */
1347 for (i = 0; i < ICE_TX_DRBELL_Q_CTX_SIZE_DWORDS; i++)
1348 wr32(hw, QTX_COMM_DBLQ_CNTX(i, tx_drbell_q_index), 0);
1353 /* FW Admin Queue command wrappers */
1356 * ice_should_retry_sq_send_cmd
1357 * @opcode: AQ opcode
1359 * Decide if we should retry the send command routine for the ATQ, depending
1362 static bool ice_should_retry_sq_send_cmd(u16 opcode)
1365 case ice_aqc_opc_get_link_topo:
1366 case ice_aqc_opc_lldp_stop:
1367 case ice_aqc_opc_lldp_start:
1368 case ice_aqc_opc_lldp_filter_ctrl:
1376 * ice_sq_send_cmd_retry - send command to Control Queue (ATQ)
1377 * @hw: pointer to the HW struct
1378 * @cq: pointer to the specific Control queue
1379 * @desc: prefilled descriptor describing the command
1380 * @buf: buffer to use for indirect commands (or NULL for direct commands)
1381 * @buf_size: size of buffer for indirect commands (or 0 for direct commands)
1382 * @cd: pointer to command details structure
1384 * Retry sending the FW Admin Queue command, multiple times, to the FW Admin
1385 * Queue if the EBUSY AQ error is returned.
1387 static enum ice_status
1388 ice_sq_send_cmd_retry(struct ice_hw *hw, struct ice_ctl_q_info *cq,
1389 struct ice_aq_desc *desc, void *buf, u16 buf_size,
1390 struct ice_sq_cd *cd)
1392 struct ice_aq_desc desc_cpy;
1393 enum ice_status status;
1394 bool is_cmd_for_retry;
1399 opcode = LE16_TO_CPU(desc->opcode);
1400 is_cmd_for_retry = ice_should_retry_sq_send_cmd(opcode);
1401 ice_memset(&desc_cpy, 0, sizeof(desc_cpy), ICE_NONDMA_MEM);
1403 if (is_cmd_for_retry) {
1405 buf_cpy = (u8 *)ice_malloc(hw, buf_size);
1407 return ICE_ERR_NO_MEMORY;
1410 ice_memcpy(&desc_cpy, desc, sizeof(desc_cpy),
1411 ICE_NONDMA_TO_NONDMA);
1415 status = ice_sq_send_cmd(hw, cq, desc, buf, buf_size, cd);
1417 if (!is_cmd_for_retry || status == ICE_SUCCESS ||
1418 hw->adminq.sq_last_status != ICE_AQ_RC_EBUSY)
1422 ice_memcpy(buf, buf_cpy, buf_size,
1423 ICE_NONDMA_TO_NONDMA);
1425 ice_memcpy(desc, &desc_cpy, sizeof(desc_cpy),
1426 ICE_NONDMA_TO_NONDMA);
1428 ice_msec_delay(ICE_SQ_SEND_DELAY_TIME_MS, false);
1430 } while (++idx < ICE_SQ_SEND_MAX_EXECUTE);
1433 ice_free(hw, buf_cpy);
1439 * ice_aq_send_cmd - send FW Admin Queue command to FW Admin Queue
1440 * @hw: pointer to the HW struct
1441 * @desc: descriptor describing the command
1442 * @buf: buffer to use for indirect commands (NULL for direct commands)
1443 * @buf_size: size of buffer for indirect commands (0 for direct commands)
1444 * @cd: pointer to command details structure
1446 * Helper function to send FW Admin Queue commands to the FW Admin Queue.
1449 ice_aq_send_cmd(struct ice_hw *hw, struct ice_aq_desc *desc, void *buf,
1450 u16 buf_size, struct ice_sq_cd *cd)
1452 if (hw->aq_send_cmd_fn) {
1453 enum ice_status status = ICE_ERR_NOT_READY;
1454 u16 retval = ICE_AQ_RC_OK;
1456 ice_acquire_lock(&hw->adminq.sq_lock);
1457 if (!hw->aq_send_cmd_fn(hw->aq_send_cmd_param, desc,
1459 retval = LE16_TO_CPU(desc->retval);
1460 /* strip off FW internal code */
1463 if (retval == ICE_AQ_RC_OK)
1464 status = ICE_SUCCESS;
1466 status = ICE_ERR_AQ_ERROR;
1469 hw->adminq.sq_last_status = (enum ice_aq_err)retval;
1470 ice_release_lock(&hw->adminq.sq_lock);
1474 return ice_sq_send_cmd_retry(hw, &hw->adminq, desc, buf, buf_size, cd);
1479 * @hw: pointer to the HW struct
1480 * @cd: pointer to command details structure or NULL
1482 * Get the firmware version (0x0001) from the admin queue commands
1484 enum ice_status ice_aq_get_fw_ver(struct ice_hw *hw, struct ice_sq_cd *cd)
1486 struct ice_aqc_get_ver *resp;
1487 struct ice_aq_desc desc;
1488 enum ice_status status;
1490 resp = &desc.params.get_ver;
1492 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_ver);
1494 status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
1497 hw->fw_branch = resp->fw_branch;
1498 hw->fw_maj_ver = resp->fw_major;
1499 hw->fw_min_ver = resp->fw_minor;
1500 hw->fw_patch = resp->fw_patch;
1501 hw->fw_build = LE32_TO_CPU(resp->fw_build);
1502 hw->api_branch = resp->api_branch;
1503 hw->api_maj_ver = resp->api_major;
1504 hw->api_min_ver = resp->api_minor;
1505 hw->api_patch = resp->api_patch;
1512 * ice_aq_send_driver_ver
1513 * @hw: pointer to the HW struct
1514 * @dv: driver's major, minor version
1515 * @cd: pointer to command details structure or NULL
1517 * Send the driver version (0x0002) to the firmware
1520 ice_aq_send_driver_ver(struct ice_hw *hw, struct ice_driver_ver *dv,
1521 struct ice_sq_cd *cd)
1523 struct ice_aqc_driver_ver *cmd;
1524 struct ice_aq_desc desc;
1527 cmd = &desc.params.driver_ver;
1530 return ICE_ERR_PARAM;
1532 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_driver_ver);
1534 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
1535 cmd->major_ver = dv->major_ver;
1536 cmd->minor_ver = dv->minor_ver;
1537 cmd->build_ver = dv->build_ver;
1538 cmd->subbuild_ver = dv->subbuild_ver;
1541 while (len < sizeof(dv->driver_string) &&
1542 IS_ASCII(dv->driver_string[len]) && dv->driver_string[len])
1545 return ice_aq_send_cmd(hw, &desc, dv->driver_string, len, cd);
1550 * @hw: pointer to the HW struct
1551 * @unloading: is the driver unloading itself
1553 * Tell the Firmware that we're shutting down the AdminQ and whether
1554 * or not the driver is unloading as well (0x0003).
1556 enum ice_status ice_aq_q_shutdown(struct ice_hw *hw, bool unloading)
1558 struct ice_aqc_q_shutdown *cmd;
1559 struct ice_aq_desc desc;
1561 cmd = &desc.params.q_shutdown;
1563 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_q_shutdown);
1566 cmd->driver_unloading = ICE_AQC_DRIVER_UNLOADING;
1568 return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
1573 * @hw: pointer to the HW struct
1575 * @access: access type
1576 * @sdp_number: resource number
1577 * @timeout: the maximum time in ms that the driver may hold the resource
1578 * @cd: pointer to command details structure or NULL
1580 * Requests common resource using the admin queue commands (0x0008).
1581 * When attempting to acquire the Global Config Lock, the driver can
1582 * learn of three states:
1583 * 1) ICE_SUCCESS - acquired lock, and can perform download package
1584 * 2) ICE_ERR_AQ_ERROR - did not get lock, driver should fail to load
1585 * 3) ICE_ERR_AQ_NO_WORK - did not get lock, but another driver has
1586 * successfully downloaded the package; the driver does
1587 * not have to download the package and can continue
1590 * Note that if the caller is in an acquire lock, perform action, release lock
1591 * phase of operation, it is possible that the FW may detect a timeout and issue
1592 * a CORER. In this case, the driver will receive a CORER interrupt and will
1593 * have to determine its cause. The calling thread that is handling this flow
1594 * will likely get an error propagated back to it indicating the Download
1595 * Package, Update Package or the Release Resource AQ commands timed out.
1597 static enum ice_status
1598 ice_aq_req_res(struct ice_hw *hw, enum ice_aq_res_ids res,
1599 enum ice_aq_res_access_type access, u8 sdp_number, u32 *timeout,
1600 struct ice_sq_cd *cd)
1602 struct ice_aqc_req_res *cmd_resp;
1603 struct ice_aq_desc desc;
1604 enum ice_status status;
1606 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1608 cmd_resp = &desc.params.res_owner;
1610 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_req_res);
1612 cmd_resp->res_id = CPU_TO_LE16(res);
1613 cmd_resp->access_type = CPU_TO_LE16(access);
1614 cmd_resp->res_number = CPU_TO_LE32(sdp_number);
1615 cmd_resp->timeout = CPU_TO_LE32(*timeout);
1618 status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
1620 /* The completion specifies the maximum time in ms that the driver
1621 * may hold the resource in the Timeout field.
1624 /* Global config lock response utilizes an additional status field.
1626 * If the Global config lock resource is held by some other driver, the
1627 * command completes with ICE_AQ_RES_GLBL_IN_PROG in the status field
1628 * and the timeout field indicates the maximum time the current owner
1629 * of the resource has to free it.
1631 if (res == ICE_GLOBAL_CFG_LOCK_RES_ID) {
1632 if (LE16_TO_CPU(cmd_resp->status) == ICE_AQ_RES_GLBL_SUCCESS) {
1633 *timeout = LE32_TO_CPU(cmd_resp->timeout);
1635 } else if (LE16_TO_CPU(cmd_resp->status) ==
1636 ICE_AQ_RES_GLBL_IN_PROG) {
1637 *timeout = LE32_TO_CPU(cmd_resp->timeout);
1638 return ICE_ERR_AQ_ERROR;
1639 } else if (LE16_TO_CPU(cmd_resp->status) ==
1640 ICE_AQ_RES_GLBL_DONE) {
1641 return ICE_ERR_AQ_NO_WORK;
1644 /* invalid FW response, force a timeout immediately */
1646 return ICE_ERR_AQ_ERROR;
1649 /* If the resource is held by some other driver, the command completes
1650 * with a busy return value and the timeout field indicates the maximum
1651 * time the current owner of the resource has to free it.
1653 if (!status || hw->adminq.sq_last_status == ICE_AQ_RC_EBUSY)
1654 *timeout = LE32_TO_CPU(cmd_resp->timeout);
1660 * ice_aq_release_res
1661 * @hw: pointer to the HW struct
1663 * @sdp_number: resource number
1664 * @cd: pointer to command details structure or NULL
1666 * release common resource using the admin queue commands (0x0009)
1668 static enum ice_status
1669 ice_aq_release_res(struct ice_hw *hw, enum ice_aq_res_ids res, u8 sdp_number,
1670 struct ice_sq_cd *cd)
1672 struct ice_aqc_req_res *cmd;
1673 struct ice_aq_desc desc;
1675 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1677 cmd = &desc.params.res_owner;
1679 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_release_res);
1681 cmd->res_id = CPU_TO_LE16(res);
1682 cmd->res_number = CPU_TO_LE32(sdp_number);
1684 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
1689 * @hw: pointer to the HW structure
1691 * @access: access type (read or write)
1692 * @timeout: timeout in milliseconds
1694 * This function will attempt to acquire the ownership of a resource.
1697 ice_acquire_res(struct ice_hw *hw, enum ice_aq_res_ids res,
1698 enum ice_aq_res_access_type access, u32 timeout)
1700 #define ICE_RES_POLLING_DELAY_MS 10
1701 u32 delay = ICE_RES_POLLING_DELAY_MS;
1702 u32 time_left = timeout;
1703 enum ice_status status;
1705 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1707 status = ice_aq_req_res(hw, res, access, 0, &time_left, NULL);
1709 /* A return code of ICE_ERR_AQ_NO_WORK means that another driver has
1710 * previously acquired the resource and performed any necessary updates;
1711 * in this case the caller does not obtain the resource and has no
1712 * further work to do.
1714 if (status == ICE_ERR_AQ_NO_WORK)
1715 goto ice_acquire_res_exit;
1718 ice_debug(hw, ICE_DBG_RES, "resource %d acquire type %d failed.\n", res, access);
1720 /* If necessary, poll until the current lock owner timeouts */
1721 timeout = time_left;
1722 while (status && timeout && time_left) {
1723 ice_msec_delay(delay, true);
1724 timeout = (timeout > delay) ? timeout - delay : 0;
1725 status = ice_aq_req_res(hw, res, access, 0, &time_left, NULL);
1727 if (status == ICE_ERR_AQ_NO_WORK)
1728 /* lock free, but no work to do */
1735 if (status && status != ICE_ERR_AQ_NO_WORK)
1736 ice_debug(hw, ICE_DBG_RES, "resource acquire timed out.\n");
1738 ice_acquire_res_exit:
1739 if (status == ICE_ERR_AQ_NO_WORK) {
1740 if (access == ICE_RES_WRITE)
1741 ice_debug(hw, ICE_DBG_RES, "resource indicates no work to do.\n");
1743 ice_debug(hw, ICE_DBG_RES, "Warning: ICE_ERR_AQ_NO_WORK not expected\n");
1750 * @hw: pointer to the HW structure
1753 * This function will release a resource using the proper Admin Command.
1755 void ice_release_res(struct ice_hw *hw, enum ice_aq_res_ids res)
1757 enum ice_status status;
1758 u32 total_delay = 0;
1760 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1762 status = ice_aq_release_res(hw, res, 0, NULL);
1764 /* there are some rare cases when trying to release the resource
1765 * results in an admin queue timeout, so handle them correctly
1767 while ((status == ICE_ERR_AQ_TIMEOUT) &&
1768 (total_delay < hw->adminq.sq_cmd_timeout)) {
1769 ice_msec_delay(1, true);
1770 status = ice_aq_release_res(hw, res, 0, NULL);
1776 * ice_aq_alloc_free_res - command to allocate/free resources
1777 * @hw: pointer to the HW struct
1778 * @num_entries: number of resource entries in buffer
1779 * @buf: Indirect buffer to hold data parameters and response
1780 * @buf_size: size of buffer for indirect commands
1781 * @opc: pass in the command opcode
1782 * @cd: pointer to command details structure or NULL
1784 * Helper function to allocate/free resources using the admin queue commands
1787 ice_aq_alloc_free_res(struct ice_hw *hw, u16 num_entries,
1788 struct ice_aqc_alloc_free_res_elem *buf, u16 buf_size,
1789 enum ice_adminq_opc opc, struct ice_sq_cd *cd)
1791 struct ice_aqc_alloc_free_res_cmd *cmd;
1792 struct ice_aq_desc desc;
1794 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1796 cmd = &desc.params.sw_res_ctrl;
1799 return ICE_ERR_PARAM;
1801 if (buf_size < FLEX_ARRAY_SIZE(buf, elem, num_entries))
1802 return ICE_ERR_PARAM;
1804 ice_fill_dflt_direct_cmd_desc(&desc, opc);
1806 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
1808 cmd->num_entries = CPU_TO_LE16(num_entries);
1810 return ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
1814 * ice_alloc_hw_res - allocate resource
1815 * @hw: pointer to the HW struct
1816 * @type: type of resource
1817 * @num: number of resources to allocate
1818 * @btm: allocate from bottom
1819 * @res: pointer to array that will receive the resources
1822 ice_alloc_hw_res(struct ice_hw *hw, u16 type, u16 num, bool btm, u16 *res)
1824 struct ice_aqc_alloc_free_res_elem *buf;
1825 enum ice_status status;
1828 buf_len = ice_struct_size(buf, elem, num);
1829 buf = (struct ice_aqc_alloc_free_res_elem *)ice_malloc(hw, buf_len);
1831 return ICE_ERR_NO_MEMORY;
1833 /* Prepare buffer to allocate resource. */
1834 buf->num_elems = CPU_TO_LE16(num);
1835 buf->res_type = CPU_TO_LE16(type | ICE_AQC_RES_TYPE_FLAG_DEDICATED |
1836 ICE_AQC_RES_TYPE_FLAG_IGNORE_INDEX);
1838 buf->res_type |= CPU_TO_LE16(ICE_AQC_RES_TYPE_FLAG_SCAN_BOTTOM);
1840 status = ice_aq_alloc_free_res(hw, 1, buf, buf_len,
1841 ice_aqc_opc_alloc_res, NULL);
1843 goto ice_alloc_res_exit;
1845 ice_memcpy(res, buf->elem, sizeof(*buf->elem) * num,
1846 ICE_NONDMA_TO_NONDMA);
1854 * ice_free_hw_res - free allocated HW resource
1855 * @hw: pointer to the HW struct
1856 * @type: type of resource to free
1857 * @num: number of resources
1858 * @res: pointer to array that contains the resources to free
1860 enum ice_status ice_free_hw_res(struct ice_hw *hw, u16 type, u16 num, u16 *res)
1862 struct ice_aqc_alloc_free_res_elem *buf;
1863 enum ice_status status;
1866 buf_len = ice_struct_size(buf, elem, num);
1867 buf = (struct ice_aqc_alloc_free_res_elem *)ice_malloc(hw, buf_len);
1869 return ICE_ERR_NO_MEMORY;
1871 /* Prepare buffer to free resource. */
1872 buf->num_elems = CPU_TO_LE16(num);
1873 buf->res_type = CPU_TO_LE16(type);
1874 ice_memcpy(buf->elem, res, sizeof(*buf->elem) * num,
1875 ICE_NONDMA_TO_NONDMA);
1877 status = ice_aq_alloc_free_res(hw, num, buf, buf_len,
1878 ice_aqc_opc_free_res, NULL);
1880 ice_debug(hw, ICE_DBG_SW, "CQ CMD Buffer:\n");
1887 * ice_get_num_per_func - determine number of resources per PF
1888 * @hw: pointer to the HW structure
1889 * @max: value to be evenly split between each PF
1891 * Determine the number of valid functions by going through the bitmap returned
1892 * from parsing capabilities and use this to calculate the number of resources
1893 * per PF based on the max value passed in.
1895 static u32 ice_get_num_per_func(struct ice_hw *hw, u32 max)
1899 #define ICE_CAPS_VALID_FUNCS_M 0xFF
1900 funcs = ice_hweight8(hw->dev_caps.common_cap.valid_functions &
1901 ICE_CAPS_VALID_FUNCS_M);
1910 * ice_parse_common_caps - parse common device/function capabilities
1911 * @hw: pointer to the HW struct
1912 * @caps: pointer to common capabilities structure
1913 * @elem: the capability element to parse
1914 * @prefix: message prefix for tracing capabilities
1916 * Given a capability element, extract relevant details into the common
1917 * capability structure.
1919 * Returns: true if the capability matches one of the common capability ids,
1923 ice_parse_common_caps(struct ice_hw *hw, struct ice_hw_common_caps *caps,
1924 struct ice_aqc_list_caps_elem *elem, const char *prefix)
1926 u32 logical_id = LE32_TO_CPU(elem->logical_id);
1927 u32 phys_id = LE32_TO_CPU(elem->phys_id);
1928 u32 number = LE32_TO_CPU(elem->number);
1929 u16 cap = LE16_TO_CPU(elem->cap);
1933 case ICE_AQC_CAPS_VALID_FUNCTIONS:
1934 caps->valid_functions = number;
1935 ice_debug(hw, ICE_DBG_INIT, "%s: valid_functions (bitmap) = %d\n", prefix,
1936 caps->valid_functions);
1938 case ICE_AQC_CAPS_DCB:
1939 caps->dcb = (number == 1);
1940 caps->active_tc_bitmap = logical_id;
1941 caps->maxtc = phys_id;
1942 ice_debug(hw, ICE_DBG_INIT, "%s: dcb = %d\n", prefix, caps->dcb);
1943 ice_debug(hw, ICE_DBG_INIT, "%s: active_tc_bitmap = %d\n", prefix,
1944 caps->active_tc_bitmap);
1945 ice_debug(hw, ICE_DBG_INIT, "%s: maxtc = %d\n", prefix, caps->maxtc);
1947 case ICE_AQC_CAPS_RSS:
1948 caps->rss_table_size = number;
1949 caps->rss_table_entry_width = logical_id;
1950 ice_debug(hw, ICE_DBG_INIT, "%s: rss_table_size = %d\n", prefix,
1951 caps->rss_table_size);
1952 ice_debug(hw, ICE_DBG_INIT, "%s: rss_table_entry_width = %d\n", prefix,
1953 caps->rss_table_entry_width);
1955 case ICE_AQC_CAPS_RXQS:
1956 caps->num_rxq = number;
1957 caps->rxq_first_id = phys_id;
1958 ice_debug(hw, ICE_DBG_INIT, "%s: num_rxq = %d\n", prefix,
1960 ice_debug(hw, ICE_DBG_INIT, "%s: rxq_first_id = %d\n", prefix,
1961 caps->rxq_first_id);
1963 case ICE_AQC_CAPS_TXQS:
1964 caps->num_txq = number;
1965 caps->txq_first_id = phys_id;
1966 ice_debug(hw, ICE_DBG_INIT, "%s: num_txq = %d\n", prefix,
1968 ice_debug(hw, ICE_DBG_INIT, "%s: txq_first_id = %d\n", prefix,
1969 caps->txq_first_id);
1971 case ICE_AQC_CAPS_MSIX:
1972 caps->num_msix_vectors = number;
1973 caps->msix_vector_first_id = phys_id;
1974 ice_debug(hw, ICE_DBG_INIT, "%s: num_msix_vectors = %d\n", prefix,
1975 caps->num_msix_vectors);
1976 ice_debug(hw, ICE_DBG_INIT, "%s: msix_vector_first_id = %d\n", prefix,
1977 caps->msix_vector_first_id);
1979 case ICE_AQC_CAPS_NVM_MGMT:
1980 caps->sec_rev_disabled =
1981 (number & ICE_NVM_MGMT_SEC_REV_DISABLED) ?
1983 ice_debug(hw, ICE_DBG_INIT, "%s: sec_rev_disabled = %d\n", prefix,
1984 caps->sec_rev_disabled);
1985 caps->update_disabled =
1986 (number & ICE_NVM_MGMT_UPDATE_DISABLED) ?
1988 ice_debug(hw, ICE_DBG_INIT, "%s: update_disabled = %d\n", prefix,
1989 caps->update_disabled);
1990 caps->nvm_unified_update =
1991 (number & ICE_NVM_MGMT_UNIFIED_UPD_SUPPORT) ?
1993 ice_debug(hw, ICE_DBG_INIT, "%s: nvm_unified_update = %d\n", prefix,
1994 caps->nvm_unified_update);
1996 case ICE_AQC_CAPS_MAX_MTU:
1997 caps->max_mtu = number;
1998 ice_debug(hw, ICE_DBG_INIT, "%s: max_mtu = %d\n",
1999 prefix, caps->max_mtu);
2001 case ICE_AQC_CAPS_EXT_TOPO_DEV_IMG0:
2002 case ICE_AQC_CAPS_EXT_TOPO_DEV_IMG1:
2003 case ICE_AQC_CAPS_EXT_TOPO_DEV_IMG2:
2004 case ICE_AQC_CAPS_EXT_TOPO_DEV_IMG3:
2006 u8 index = cap - ICE_AQC_CAPS_EXT_TOPO_DEV_IMG0;
2008 caps->ext_topo_dev_img_ver_high[index] = number;
2009 caps->ext_topo_dev_img_ver_low[index] = logical_id;
2010 caps->ext_topo_dev_img_part_num[index] =
2011 (phys_id & ICE_EXT_TOPO_DEV_IMG_PART_NUM_M) >>
2012 ICE_EXT_TOPO_DEV_IMG_PART_NUM_S;
2013 caps->ext_topo_dev_img_load_en[index] =
2014 (phys_id & ICE_EXT_TOPO_DEV_IMG_LOAD_EN) != 0;
2015 caps->ext_topo_dev_img_prog_en[index] =
2016 (phys_id & ICE_EXT_TOPO_DEV_IMG_PROG_EN) != 0;
2017 ice_debug(hw, ICE_DBG_INIT,
2018 "%s: ext_topo_dev_img_ver_high[%d] = %d\n",
2020 caps->ext_topo_dev_img_ver_high[index]);
2021 ice_debug(hw, ICE_DBG_INIT,
2022 "%s: ext_topo_dev_img_ver_low[%d] = %d\n",
2024 caps->ext_topo_dev_img_ver_low[index]);
2025 ice_debug(hw, ICE_DBG_INIT,
2026 "%s: ext_topo_dev_img_part_num[%d] = %d\n",
2028 caps->ext_topo_dev_img_part_num[index]);
2029 ice_debug(hw, ICE_DBG_INIT,
2030 "%s: ext_topo_dev_img_load_en[%d] = %d\n",
2032 caps->ext_topo_dev_img_load_en[index]);
2033 ice_debug(hw, ICE_DBG_INIT,
2034 "%s: ext_topo_dev_img_prog_en[%d] = %d\n",
2036 caps->ext_topo_dev_img_prog_en[index]);
2040 /* Not one of the recognized common capabilities */
2048 * ice_recalc_port_limited_caps - Recalculate port limited capabilities
2049 * @hw: pointer to the HW structure
2050 * @caps: pointer to capabilities structure to fix
2052 * Re-calculate the capabilities that are dependent on the number of physical
2053 * ports; i.e. some features are not supported or function differently on
2054 * devices with more than 4 ports.
2057 ice_recalc_port_limited_caps(struct ice_hw *hw, struct ice_hw_common_caps *caps)
2059 /* This assumes device capabilities are always scanned before function
2060 * capabilities during the initialization flow.
2062 if (hw->dev_caps.num_funcs > 4) {
2063 /* Max 4 TCs per port */
2065 ice_debug(hw, ICE_DBG_INIT, "reducing maxtc to %d (based on #ports)\n",
2071 * ice_parse_vsi_func_caps - Parse ICE_AQC_CAPS_VSI function caps
2072 * @hw: pointer to the HW struct
2073 * @func_p: pointer to function capabilities structure
2074 * @cap: pointer to the capability element to parse
2076 * Extract function capabilities for ICE_AQC_CAPS_VSI.
2079 ice_parse_vsi_func_caps(struct ice_hw *hw, struct ice_hw_func_caps *func_p,
2080 struct ice_aqc_list_caps_elem *cap)
2082 func_p->guar_num_vsi = ice_get_num_per_func(hw, ICE_MAX_VSI);
2083 ice_debug(hw, ICE_DBG_INIT, "func caps: guar_num_vsi (fw) = %d\n",
2084 LE32_TO_CPU(cap->number));
2085 ice_debug(hw, ICE_DBG_INIT, "func caps: guar_num_vsi = %d\n",
2086 func_p->guar_num_vsi);
2090 * ice_parse_1588_func_caps - Parse ICE_AQC_CAPS_1588 function caps
2091 * @hw: pointer to the HW struct
2092 * @func_p: pointer to function capabilities structure
2093 * @cap: pointer to the capability element to parse
2095 * Extract function capabilities for ICE_AQC_CAPS_1588.
2098 ice_parse_1588_func_caps(struct ice_hw *hw, struct ice_hw_func_caps *func_p,
2099 struct ice_aqc_list_caps_elem *cap)
2101 struct ice_ts_func_info *info = &func_p->ts_func_info;
2102 u32 number = LE32_TO_CPU(cap->number);
2104 info->ena = ((number & ICE_TS_FUNC_ENA_M) != 0);
2105 func_p->common_cap.ieee_1588 = info->ena;
2107 info->src_tmr_owned = ((number & ICE_TS_SRC_TMR_OWND_M) != 0);
2108 info->tmr_ena = ((number & ICE_TS_TMR_ENA_M) != 0);
2109 info->tmr_index_owned = ((number & ICE_TS_TMR_IDX_OWND_M) != 0);
2110 info->tmr_index_assoc = ((number & ICE_TS_TMR_IDX_ASSOC_M) != 0);
2112 info->clk_freq = (number & ICE_TS_CLK_FREQ_M) >> ICE_TS_CLK_FREQ_S;
2113 info->clk_src = ((number & ICE_TS_CLK_SRC_M) != 0);
2115 if (info->clk_freq < NUM_ICE_TIME_REF_FREQ) {
2116 info->time_ref = (enum ice_time_ref_freq)info->clk_freq;
2118 /* Unknown clock frequency, so assume a (probably incorrect)
2119 * default to avoid out-of-bounds look ups of frequency
2120 * related information.
2122 ice_debug(hw, ICE_DBG_INIT, "1588 func caps: unknown clock frequency %u\n",
2124 info->time_ref = ICE_TIME_REF_FREQ_25_000;
2127 ice_debug(hw, ICE_DBG_INIT, "func caps: ieee_1588 = %u\n",
2128 func_p->common_cap.ieee_1588);
2129 ice_debug(hw, ICE_DBG_INIT, "func caps: src_tmr_owned = %u\n",
2130 info->src_tmr_owned);
2131 ice_debug(hw, ICE_DBG_INIT, "func caps: tmr_ena = %u\n",
2133 ice_debug(hw, ICE_DBG_INIT, "func caps: tmr_index_owned = %u\n",
2134 info->tmr_index_owned);
2135 ice_debug(hw, ICE_DBG_INIT, "func caps: tmr_index_assoc = %u\n",
2136 info->tmr_index_assoc);
2137 ice_debug(hw, ICE_DBG_INIT, "func caps: clk_freq = %u\n",
2139 ice_debug(hw, ICE_DBG_INIT, "func caps: clk_src = %u\n",
2144 * ice_parse_fdir_func_caps - Parse ICE_AQC_CAPS_FD function caps
2145 * @hw: pointer to the HW struct
2146 * @func_p: pointer to function capabilities structure
2148 * Extract function capabilities for ICE_AQC_CAPS_FD.
2151 ice_parse_fdir_func_caps(struct ice_hw *hw, struct ice_hw_func_caps *func_p)
2155 if (hw->dcf_enabled)
2157 reg_val = rd32(hw, GLQF_FD_SIZE);
2158 val = (reg_val & GLQF_FD_SIZE_FD_GSIZE_M) >>
2159 GLQF_FD_SIZE_FD_GSIZE_S;
2160 func_p->fd_fltr_guar =
2161 ice_get_num_per_func(hw, val);
2162 val = (reg_val & GLQF_FD_SIZE_FD_BSIZE_M) >>
2163 GLQF_FD_SIZE_FD_BSIZE_S;
2164 func_p->fd_fltr_best_effort = val;
2166 ice_debug(hw, ICE_DBG_INIT, "func caps: fd_fltr_guar = %d\n",
2167 func_p->fd_fltr_guar);
2168 ice_debug(hw, ICE_DBG_INIT, "func caps: fd_fltr_best_effort = %d\n",
2169 func_p->fd_fltr_best_effort);
2173 * ice_parse_func_caps - Parse function capabilities
2174 * @hw: pointer to the HW struct
2175 * @func_p: pointer to function capabilities structure
2176 * @buf: buffer containing the function capability records
2177 * @cap_count: the number of capabilities
2179 * Helper function to parse function (0x000A) capabilities list. For
2180 * capabilities shared between device and function, this relies on
2181 * ice_parse_common_caps.
2183 * Loop through the list of provided capabilities and extract the relevant
2184 * data into the function capabilities structured.
2187 ice_parse_func_caps(struct ice_hw *hw, struct ice_hw_func_caps *func_p,
2188 void *buf, u32 cap_count)
2190 struct ice_aqc_list_caps_elem *cap_resp;
2193 cap_resp = (struct ice_aqc_list_caps_elem *)buf;
2195 ice_memset(func_p, 0, sizeof(*func_p), ICE_NONDMA_MEM);
2197 for (i = 0; i < cap_count; i++) {
2198 u16 cap = LE16_TO_CPU(cap_resp[i].cap);
2201 found = ice_parse_common_caps(hw, &func_p->common_cap,
2202 &cap_resp[i], "func caps");
2205 case ICE_AQC_CAPS_VSI:
2206 ice_parse_vsi_func_caps(hw, func_p, &cap_resp[i]);
2208 case ICE_AQC_CAPS_1588:
2209 ice_parse_1588_func_caps(hw, func_p, &cap_resp[i]);
2211 case ICE_AQC_CAPS_FD:
2212 ice_parse_fdir_func_caps(hw, func_p);
2215 /* Don't list common capabilities as unknown */
2217 ice_debug(hw, ICE_DBG_INIT, "func caps: unknown capability[%d]: 0x%x\n",
2223 ice_recalc_port_limited_caps(hw, &func_p->common_cap);
2227 * ice_parse_valid_functions_cap - Parse ICE_AQC_CAPS_VALID_FUNCTIONS caps
2228 * @hw: pointer to the HW struct
2229 * @dev_p: pointer to device capabilities structure
2230 * @cap: capability element to parse
2232 * Parse ICE_AQC_CAPS_VALID_FUNCTIONS for device capabilities.
2235 ice_parse_valid_functions_cap(struct ice_hw *hw, struct ice_hw_dev_caps *dev_p,
2236 struct ice_aqc_list_caps_elem *cap)
2238 u32 number = LE32_TO_CPU(cap->number);
2240 dev_p->num_funcs = ice_hweight32(number);
2241 ice_debug(hw, ICE_DBG_INIT, "dev caps: num_funcs = %d\n",
2246 * ice_parse_vsi_dev_caps - Parse ICE_AQC_CAPS_VSI device caps
2247 * @hw: pointer to the HW struct
2248 * @dev_p: pointer to device capabilities structure
2249 * @cap: capability element to parse
2251 * Parse ICE_AQC_CAPS_VSI for device capabilities.
2254 ice_parse_vsi_dev_caps(struct ice_hw *hw, struct ice_hw_dev_caps *dev_p,
2255 struct ice_aqc_list_caps_elem *cap)
2257 u32 number = LE32_TO_CPU(cap->number);
2259 dev_p->num_vsi_allocd_to_host = number;
2260 ice_debug(hw, ICE_DBG_INIT, "dev caps: num_vsi_allocd_to_host = %d\n",
2261 dev_p->num_vsi_allocd_to_host);
2265 * ice_parse_1588_dev_caps - Parse ICE_AQC_CAPS_1588 device caps
2266 * @hw: pointer to the HW struct
2267 * @dev_p: pointer to device capabilities structure
2268 * @cap: capability element to parse
2270 * Parse ICE_AQC_CAPS_1588 for device capabilities.
2273 ice_parse_1588_dev_caps(struct ice_hw *hw, struct ice_hw_dev_caps *dev_p,
2274 struct ice_aqc_list_caps_elem *cap)
2276 struct ice_ts_dev_info *info = &dev_p->ts_dev_info;
2277 u32 logical_id = LE32_TO_CPU(cap->logical_id);
2278 u32 phys_id = LE32_TO_CPU(cap->phys_id);
2279 u32 number = LE32_TO_CPU(cap->number);
2281 info->ena = ((number & ICE_TS_DEV_ENA_M) != 0);
2282 dev_p->common_cap.ieee_1588 = info->ena;
2284 info->tmr0_owner = number & ICE_TS_TMR0_OWNR_M;
2285 info->tmr0_owned = ((number & ICE_TS_TMR0_OWND_M) != 0);
2286 info->tmr0_ena = ((number & ICE_TS_TMR0_ENA_M) != 0);
2288 info->tmr1_owner = (number & ICE_TS_TMR1_OWNR_M) >> ICE_TS_TMR1_OWNR_S;
2289 info->tmr1_owned = ((number & ICE_TS_TMR1_OWND_M) != 0);
2290 info->tmr1_ena = ((number & ICE_TS_TMR1_ENA_M) != 0);
2292 info->ena_ports = logical_id;
2293 info->tmr_own_map = phys_id;
2295 ice_debug(hw, ICE_DBG_INIT, "dev caps: ieee_1588 = %u\n",
2296 dev_p->common_cap.ieee_1588);
2297 ice_debug(hw, ICE_DBG_INIT, "dev caps: tmr0_owner = %u\n",
2299 ice_debug(hw, ICE_DBG_INIT, "dev caps: tmr0_owned = %u\n",
2301 ice_debug(hw, ICE_DBG_INIT, "dev caps: tmr0_ena = %u\n",
2303 ice_debug(hw, ICE_DBG_INIT, "dev caps: tmr1_owner = %u\n",
2305 ice_debug(hw, ICE_DBG_INIT, "dev caps: tmr1_owned = %u\n",
2307 ice_debug(hw, ICE_DBG_INIT, "dev caps: tmr1_ena = %u\n",
2309 ice_debug(hw, ICE_DBG_INIT, "dev caps: ieee_1588 ena_ports = %u\n",
2311 ice_debug(hw, ICE_DBG_INIT, "dev caps: tmr_own_map = %u\n",
2316 * ice_parse_fdir_dev_caps - Parse ICE_AQC_CAPS_FD device caps
2317 * @hw: pointer to the HW struct
2318 * @dev_p: pointer to device capabilities structure
2319 * @cap: capability element to parse
2321 * Parse ICE_AQC_CAPS_FD for device capabilities.
2324 ice_parse_fdir_dev_caps(struct ice_hw *hw, struct ice_hw_dev_caps *dev_p,
2325 struct ice_aqc_list_caps_elem *cap)
2327 u32 number = LE32_TO_CPU(cap->number);
2329 dev_p->num_flow_director_fltr = number;
2330 ice_debug(hw, ICE_DBG_INIT, "dev caps: num_flow_director_fltr = %d\n",
2331 dev_p->num_flow_director_fltr);
2335 * ice_parse_dev_caps - Parse device capabilities
2336 * @hw: pointer to the HW struct
2337 * @dev_p: pointer to device capabilities structure
2338 * @buf: buffer containing the device capability records
2339 * @cap_count: the number of capabilities
2341 * Helper device to parse device (0x000B) capabilities list. For
2342 * capabilities shared between device and function, this relies on
2343 * ice_parse_common_caps.
2345 * Loop through the list of provided capabilities and extract the relevant
2346 * data into the device capabilities structured.
2349 ice_parse_dev_caps(struct ice_hw *hw, struct ice_hw_dev_caps *dev_p,
2350 void *buf, u32 cap_count)
2352 struct ice_aqc_list_caps_elem *cap_resp;
2355 cap_resp = (struct ice_aqc_list_caps_elem *)buf;
2357 ice_memset(dev_p, 0, sizeof(*dev_p), ICE_NONDMA_MEM);
2359 for (i = 0; i < cap_count; i++) {
2360 u16 cap = LE16_TO_CPU(cap_resp[i].cap);
2363 found = ice_parse_common_caps(hw, &dev_p->common_cap,
2364 &cap_resp[i], "dev caps");
2367 case ICE_AQC_CAPS_VALID_FUNCTIONS:
2368 ice_parse_valid_functions_cap(hw, dev_p, &cap_resp[i]);
2370 case ICE_AQC_CAPS_VSI:
2371 ice_parse_vsi_dev_caps(hw, dev_p, &cap_resp[i]);
2373 case ICE_AQC_CAPS_1588:
2374 ice_parse_1588_dev_caps(hw, dev_p, &cap_resp[i]);
2376 case ICE_AQC_CAPS_FD:
2377 ice_parse_fdir_dev_caps(hw, dev_p, &cap_resp[i]);
2380 /* Don't list common capabilities as unknown */
2382 ice_debug(hw, ICE_DBG_INIT, "dev caps: unknown capability[%d]: 0x%x\n",
2388 ice_recalc_port_limited_caps(hw, &dev_p->common_cap);
2392 * ice_aq_list_caps - query function/device capabilities
2393 * @hw: pointer to the HW struct
2394 * @buf: a buffer to hold the capabilities
2395 * @buf_size: size of the buffer
2396 * @cap_count: if not NULL, set to the number of capabilities reported
2397 * @opc: capabilities type to discover, device or function
2398 * @cd: pointer to command details structure or NULL
2400 * Get the function (0x000A) or device (0x000B) capabilities description from
2401 * firmware and store it in the buffer.
2403 * If the cap_count pointer is not NULL, then it is set to the number of
2404 * capabilities firmware will report. Note that if the buffer size is too
2405 * small, it is possible the command will return ICE_AQ_ERR_ENOMEM. The
2406 * cap_count will still be updated in this case. It is recommended that the
2407 * buffer size be set to ICE_AQ_MAX_BUF_LEN (the largest possible buffer that
2408 * firmware could return) to avoid this.
2410 static enum ice_status
2411 ice_aq_list_caps(struct ice_hw *hw, void *buf, u16 buf_size, u32 *cap_count,
2412 enum ice_adminq_opc opc, struct ice_sq_cd *cd)
2414 struct ice_aqc_list_caps *cmd;
2415 struct ice_aq_desc desc;
2416 enum ice_status status;
2418 cmd = &desc.params.get_cap;
2420 if (opc != ice_aqc_opc_list_func_caps &&
2421 opc != ice_aqc_opc_list_dev_caps)
2422 return ICE_ERR_PARAM;
2424 ice_fill_dflt_direct_cmd_desc(&desc, opc);
2425 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
2428 *cap_count = LE32_TO_CPU(cmd->count);
2434 * ice_discover_dev_caps - Read and extract device capabilities
2435 * @hw: pointer to the hardware structure
2436 * @dev_caps: pointer to device capabilities structure
2438 * Read the device capabilities and extract them into the dev_caps structure
2441 static enum ice_status
2442 ice_discover_dev_caps(struct ice_hw *hw, struct ice_hw_dev_caps *dev_caps)
2444 enum ice_status status;
2448 cbuf = ice_malloc(hw, ICE_AQ_MAX_BUF_LEN);
2450 return ICE_ERR_NO_MEMORY;
2452 /* Although the driver doesn't know the number of capabilities the
2453 * device will return, we can simply send a 4KB buffer, the maximum
2454 * possible size that firmware can return.
2456 cap_count = ICE_AQ_MAX_BUF_LEN / sizeof(struct ice_aqc_list_caps_elem);
2458 status = ice_aq_list_caps(hw, cbuf, ICE_AQ_MAX_BUF_LEN, &cap_count,
2459 ice_aqc_opc_list_dev_caps, NULL);
2461 ice_parse_dev_caps(hw, dev_caps, cbuf, cap_count);
2468 * ice_discover_func_caps - Read and extract function capabilities
2469 * @hw: pointer to the hardware structure
2470 * @func_caps: pointer to function capabilities structure
2472 * Read the function capabilities and extract them into the func_caps structure
2475 static enum ice_status
2476 ice_discover_func_caps(struct ice_hw *hw, struct ice_hw_func_caps *func_caps)
2478 enum ice_status status;
2482 cbuf = ice_malloc(hw, ICE_AQ_MAX_BUF_LEN);
2484 return ICE_ERR_NO_MEMORY;
2486 /* Although the driver doesn't know the number of capabilities the
2487 * device will return, we can simply send a 4KB buffer, the maximum
2488 * possible size that firmware can return.
2490 cap_count = ICE_AQ_MAX_BUF_LEN / sizeof(struct ice_aqc_list_caps_elem);
2492 status = ice_aq_list_caps(hw, cbuf, ICE_AQ_MAX_BUF_LEN, &cap_count,
2493 ice_aqc_opc_list_func_caps, NULL);
2495 ice_parse_func_caps(hw, func_caps, cbuf, cap_count);
2502 * ice_set_safe_mode_caps - Override dev/func capabilities when in safe mode
2503 * @hw: pointer to the hardware structure
2505 void ice_set_safe_mode_caps(struct ice_hw *hw)
2507 struct ice_hw_func_caps *func_caps = &hw->func_caps;
2508 struct ice_hw_dev_caps *dev_caps = &hw->dev_caps;
2509 struct ice_hw_common_caps cached_caps;
2512 /* cache some func_caps values that should be restored after memset */
2513 cached_caps = func_caps->common_cap;
2515 /* unset func capabilities */
2516 memset(func_caps, 0, sizeof(*func_caps));
2518 #define ICE_RESTORE_FUNC_CAP(name) \
2519 func_caps->common_cap.name = cached_caps.name
2521 /* restore cached values */
2522 ICE_RESTORE_FUNC_CAP(valid_functions);
2523 ICE_RESTORE_FUNC_CAP(txq_first_id);
2524 ICE_RESTORE_FUNC_CAP(rxq_first_id);
2525 ICE_RESTORE_FUNC_CAP(msix_vector_first_id);
2526 ICE_RESTORE_FUNC_CAP(max_mtu);
2527 ICE_RESTORE_FUNC_CAP(nvm_unified_update);
2529 /* one Tx and one Rx queue in safe mode */
2530 func_caps->common_cap.num_rxq = 1;
2531 func_caps->common_cap.num_txq = 1;
2533 /* two MSIX vectors, one for traffic and one for misc causes */
2534 func_caps->common_cap.num_msix_vectors = 2;
2535 func_caps->guar_num_vsi = 1;
2537 /* cache some dev_caps values that should be restored after memset */
2538 cached_caps = dev_caps->common_cap;
2539 num_funcs = dev_caps->num_funcs;
2541 /* unset dev capabilities */
2542 memset(dev_caps, 0, sizeof(*dev_caps));
2544 #define ICE_RESTORE_DEV_CAP(name) \
2545 dev_caps->common_cap.name = cached_caps.name
2547 /* restore cached values */
2548 ICE_RESTORE_DEV_CAP(valid_functions);
2549 ICE_RESTORE_DEV_CAP(txq_first_id);
2550 ICE_RESTORE_DEV_CAP(rxq_first_id);
2551 ICE_RESTORE_DEV_CAP(msix_vector_first_id);
2552 ICE_RESTORE_DEV_CAP(max_mtu);
2553 ICE_RESTORE_DEV_CAP(nvm_unified_update);
2554 dev_caps->num_funcs = num_funcs;
2556 /* one Tx and one Rx queue per function in safe mode */
2557 dev_caps->common_cap.num_rxq = num_funcs;
2558 dev_caps->common_cap.num_txq = num_funcs;
2560 /* two MSIX vectors per function */
2561 dev_caps->common_cap.num_msix_vectors = 2 * num_funcs;
2565 * ice_get_caps - get info about the HW
2566 * @hw: pointer to the hardware structure
2568 enum ice_status ice_get_caps(struct ice_hw *hw)
2570 enum ice_status status;
2572 status = ice_discover_dev_caps(hw, &hw->dev_caps);
2576 return ice_discover_func_caps(hw, &hw->func_caps);
2580 * ice_aq_manage_mac_write - manage MAC address write command
2581 * @hw: pointer to the HW struct
2582 * @mac_addr: MAC address to be written as LAA/LAA+WoL/Port address
2583 * @flags: flags to control write behavior
2584 * @cd: pointer to command details structure or NULL
2586 * This function is used to write MAC address to the NVM (0x0108).
2589 ice_aq_manage_mac_write(struct ice_hw *hw, const u8 *mac_addr, u8 flags,
2590 struct ice_sq_cd *cd)
2592 struct ice_aqc_manage_mac_write *cmd;
2593 struct ice_aq_desc desc;
2595 cmd = &desc.params.mac_write;
2596 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_manage_mac_write);
2599 ice_memcpy(cmd->mac_addr, mac_addr, ETH_ALEN, ICE_NONDMA_TO_NONDMA);
2601 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
2605 * ice_aq_clear_pxe_mode
2606 * @hw: pointer to the HW struct
2608 * Tell the firmware that the driver is taking over from PXE (0x0110).
2610 static enum ice_status ice_aq_clear_pxe_mode(struct ice_hw *hw)
2612 struct ice_aq_desc desc;
2614 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_clear_pxe_mode);
2615 desc.params.clear_pxe.rx_cnt = ICE_AQC_CLEAR_PXE_RX_CNT;
2617 return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
2621 * ice_clear_pxe_mode - clear pxe operations mode
2622 * @hw: pointer to the HW struct
2624 * Make sure all PXE mode settings are cleared, including things
2625 * like descriptor fetch/write-back mode.
2627 void ice_clear_pxe_mode(struct ice_hw *hw)
2629 if (ice_check_sq_alive(hw, &hw->adminq))
2630 ice_aq_clear_pxe_mode(hw);
2634 * ice_aq_set_port_params - set physical port parameters.
2635 * @pi: pointer to the port info struct
2636 * @bad_frame_vsi: defines the VSI to which bad frames are forwarded
2637 * @save_bad_pac: if set packets with errors are forwarded to the bad frames VSI
2638 * @pad_short_pac: if set transmit packets smaller than 60 bytes are padded
2639 * @double_vlan: if set double VLAN is enabled
2640 * @cd: pointer to command details structure or NULL
2642 * Set Physical port parameters (0x0203)
2645 ice_aq_set_port_params(struct ice_port_info *pi, u16 bad_frame_vsi,
2646 bool save_bad_pac, bool pad_short_pac, bool double_vlan,
2647 struct ice_sq_cd *cd)
2650 struct ice_aqc_set_port_params *cmd;
2651 struct ice_hw *hw = pi->hw;
2652 struct ice_aq_desc desc;
2655 cmd = &desc.params.set_port_params;
2657 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_port_params);
2658 cmd->bad_frame_vsi = CPU_TO_LE16(bad_frame_vsi);
2660 cmd_flags |= ICE_AQC_SET_P_PARAMS_SAVE_BAD_PACKETS;
2662 cmd_flags |= ICE_AQC_SET_P_PARAMS_PAD_SHORT_PACKETS;
2664 cmd_flags |= ICE_AQC_SET_P_PARAMS_DOUBLE_VLAN_ENA;
2665 cmd->cmd_flags = CPU_TO_LE16(cmd_flags);
2667 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
2671 * ice_get_link_speed_based_on_phy_type - returns link speed
2672 * @phy_type_low: lower part of phy_type
2673 * @phy_type_high: higher part of phy_type
2675 * This helper function will convert an entry in PHY type structure
2676 * [phy_type_low, phy_type_high] to its corresponding link speed.
2677 * Note: In the structure of [phy_type_low, phy_type_high], there should
2678 * be one bit set, as this function will convert one PHY type to its
2680 * If no bit gets set, ICE_LINK_SPEED_UNKNOWN will be returned
2681 * If more than one bit gets set, ICE_LINK_SPEED_UNKNOWN will be returned
2684 ice_get_link_speed_based_on_phy_type(u64 phy_type_low, u64 phy_type_high)
2686 u16 speed_phy_type_high = ICE_AQ_LINK_SPEED_UNKNOWN;
2687 u16 speed_phy_type_low = ICE_AQ_LINK_SPEED_UNKNOWN;
2689 switch (phy_type_low) {
2690 case ICE_PHY_TYPE_LOW_100BASE_TX:
2691 case ICE_PHY_TYPE_LOW_100M_SGMII:
2692 speed_phy_type_low = ICE_AQ_LINK_SPEED_100MB;
2694 case ICE_PHY_TYPE_LOW_1000BASE_T:
2695 case ICE_PHY_TYPE_LOW_1000BASE_SX:
2696 case ICE_PHY_TYPE_LOW_1000BASE_LX:
2697 case ICE_PHY_TYPE_LOW_1000BASE_KX:
2698 case ICE_PHY_TYPE_LOW_1G_SGMII:
2699 speed_phy_type_low = ICE_AQ_LINK_SPEED_1000MB;
2701 case ICE_PHY_TYPE_LOW_2500BASE_T:
2702 case ICE_PHY_TYPE_LOW_2500BASE_X:
2703 case ICE_PHY_TYPE_LOW_2500BASE_KX:
2704 speed_phy_type_low = ICE_AQ_LINK_SPEED_2500MB;
2706 case ICE_PHY_TYPE_LOW_5GBASE_T:
2707 case ICE_PHY_TYPE_LOW_5GBASE_KR:
2708 speed_phy_type_low = ICE_AQ_LINK_SPEED_5GB;
2710 case ICE_PHY_TYPE_LOW_10GBASE_T:
2711 case ICE_PHY_TYPE_LOW_10G_SFI_DA:
2712 case ICE_PHY_TYPE_LOW_10GBASE_SR:
2713 case ICE_PHY_TYPE_LOW_10GBASE_LR:
2714 case ICE_PHY_TYPE_LOW_10GBASE_KR_CR1:
2715 case ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC:
2716 case ICE_PHY_TYPE_LOW_10G_SFI_C2C:
2717 speed_phy_type_low = ICE_AQ_LINK_SPEED_10GB;
2719 case ICE_PHY_TYPE_LOW_25GBASE_T:
2720 case ICE_PHY_TYPE_LOW_25GBASE_CR:
2721 case ICE_PHY_TYPE_LOW_25GBASE_CR_S:
2722 case ICE_PHY_TYPE_LOW_25GBASE_CR1:
2723 case ICE_PHY_TYPE_LOW_25GBASE_SR:
2724 case ICE_PHY_TYPE_LOW_25GBASE_LR:
2725 case ICE_PHY_TYPE_LOW_25GBASE_KR:
2726 case ICE_PHY_TYPE_LOW_25GBASE_KR_S:
2727 case ICE_PHY_TYPE_LOW_25GBASE_KR1:
2728 case ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC:
2729 case ICE_PHY_TYPE_LOW_25G_AUI_C2C:
2730 speed_phy_type_low = ICE_AQ_LINK_SPEED_25GB;
2732 case ICE_PHY_TYPE_LOW_40GBASE_CR4:
2733 case ICE_PHY_TYPE_LOW_40GBASE_SR4:
2734 case ICE_PHY_TYPE_LOW_40GBASE_LR4:
2735 case ICE_PHY_TYPE_LOW_40GBASE_KR4:
2736 case ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC:
2737 case ICE_PHY_TYPE_LOW_40G_XLAUI:
2738 speed_phy_type_low = ICE_AQ_LINK_SPEED_40GB;
2740 case ICE_PHY_TYPE_LOW_50GBASE_CR2:
2741 case ICE_PHY_TYPE_LOW_50GBASE_SR2:
2742 case ICE_PHY_TYPE_LOW_50GBASE_LR2:
2743 case ICE_PHY_TYPE_LOW_50GBASE_KR2:
2744 case ICE_PHY_TYPE_LOW_50G_LAUI2_AOC_ACC:
2745 case ICE_PHY_TYPE_LOW_50G_LAUI2:
2746 case ICE_PHY_TYPE_LOW_50G_AUI2_AOC_ACC:
2747 case ICE_PHY_TYPE_LOW_50G_AUI2:
2748 case ICE_PHY_TYPE_LOW_50GBASE_CP:
2749 case ICE_PHY_TYPE_LOW_50GBASE_SR:
2750 case ICE_PHY_TYPE_LOW_50GBASE_FR:
2751 case ICE_PHY_TYPE_LOW_50GBASE_LR:
2752 case ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4:
2753 case ICE_PHY_TYPE_LOW_50G_AUI1_AOC_ACC:
2754 case ICE_PHY_TYPE_LOW_50G_AUI1:
2755 speed_phy_type_low = ICE_AQ_LINK_SPEED_50GB;
2757 case ICE_PHY_TYPE_LOW_100GBASE_CR4:
2758 case ICE_PHY_TYPE_LOW_100GBASE_SR4:
2759 case ICE_PHY_TYPE_LOW_100GBASE_LR4:
2760 case ICE_PHY_TYPE_LOW_100GBASE_KR4:
2761 case ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC:
2762 case ICE_PHY_TYPE_LOW_100G_CAUI4:
2763 case ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC:
2764 case ICE_PHY_TYPE_LOW_100G_AUI4:
2765 case ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4:
2766 case ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4:
2767 case ICE_PHY_TYPE_LOW_100GBASE_CP2:
2768 case ICE_PHY_TYPE_LOW_100GBASE_SR2:
2769 case ICE_PHY_TYPE_LOW_100GBASE_DR:
2770 speed_phy_type_low = ICE_AQ_LINK_SPEED_100GB;
2773 speed_phy_type_low = ICE_AQ_LINK_SPEED_UNKNOWN;
2777 switch (phy_type_high) {
2778 case ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4:
2779 case ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC:
2780 case ICE_PHY_TYPE_HIGH_100G_CAUI2:
2781 case ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC:
2782 case ICE_PHY_TYPE_HIGH_100G_AUI2:
2783 speed_phy_type_high = ICE_AQ_LINK_SPEED_100GB;
2786 speed_phy_type_high = ICE_AQ_LINK_SPEED_UNKNOWN;
2790 if (speed_phy_type_low == ICE_AQ_LINK_SPEED_UNKNOWN &&
2791 speed_phy_type_high == ICE_AQ_LINK_SPEED_UNKNOWN)
2792 return ICE_AQ_LINK_SPEED_UNKNOWN;
2793 else if (speed_phy_type_low != ICE_AQ_LINK_SPEED_UNKNOWN &&
2794 speed_phy_type_high != ICE_AQ_LINK_SPEED_UNKNOWN)
2795 return ICE_AQ_LINK_SPEED_UNKNOWN;
2796 else if (speed_phy_type_low != ICE_AQ_LINK_SPEED_UNKNOWN &&
2797 speed_phy_type_high == ICE_AQ_LINK_SPEED_UNKNOWN)
2798 return speed_phy_type_low;
2800 return speed_phy_type_high;
2804 * ice_update_phy_type
2805 * @phy_type_low: pointer to the lower part of phy_type
2806 * @phy_type_high: pointer to the higher part of phy_type
2807 * @link_speeds_bitmap: targeted link speeds bitmap
2809 * Note: For the link_speeds_bitmap structure, you can check it at
2810 * [ice_aqc_get_link_status->link_speed]. Caller can pass in
2811 * link_speeds_bitmap include multiple speeds.
2813 * Each entry in this [phy_type_low, phy_type_high] structure will
2814 * present a certain link speed. This helper function will turn on bits
2815 * in [phy_type_low, phy_type_high] structure based on the value of
2816 * link_speeds_bitmap input parameter.
2819 ice_update_phy_type(u64 *phy_type_low, u64 *phy_type_high,
2820 u16 link_speeds_bitmap)
2827 /* We first check with low part of phy_type */
2828 for (index = 0; index <= ICE_PHY_TYPE_LOW_MAX_INDEX; index++) {
2829 pt_low = BIT_ULL(index);
2830 speed = ice_get_link_speed_based_on_phy_type(pt_low, 0);
2832 if (link_speeds_bitmap & speed)
2833 *phy_type_low |= BIT_ULL(index);
2836 /* We then check with high part of phy_type */
2837 for (index = 0; index <= ICE_PHY_TYPE_HIGH_MAX_INDEX; index++) {
2838 pt_high = BIT_ULL(index);
2839 speed = ice_get_link_speed_based_on_phy_type(0, pt_high);
2841 if (link_speeds_bitmap & speed)
2842 *phy_type_high |= BIT_ULL(index);
2847 * ice_aq_set_phy_cfg
2848 * @hw: pointer to the HW struct
2849 * @pi: port info structure of the interested logical port
2850 * @cfg: structure with PHY configuration data to be set
2851 * @cd: pointer to command details structure or NULL
2853 * Set the various PHY configuration parameters supported on the Port.
2854 * One or more of the Set PHY config parameters may be ignored in an MFP
2855 * mode as the PF may not have the privilege to set some of the PHY Config
2856 * parameters. This status will be indicated by the command response (0x0601).
2859 ice_aq_set_phy_cfg(struct ice_hw *hw, struct ice_port_info *pi,
2860 struct ice_aqc_set_phy_cfg_data *cfg, struct ice_sq_cd *cd)
2862 struct ice_aq_desc desc;
2863 enum ice_status status;
2866 return ICE_ERR_PARAM;
2868 /* Ensure that only valid bits of cfg->caps can be turned on. */
2869 if (cfg->caps & ~ICE_AQ_PHY_ENA_VALID_MASK) {
2870 ice_debug(hw, ICE_DBG_PHY, "Invalid bit is set in ice_aqc_set_phy_cfg_data->caps : 0x%x\n",
2873 cfg->caps &= ICE_AQ_PHY_ENA_VALID_MASK;
2876 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_phy_cfg);
2877 desc.params.set_phy.lport_num = pi->lport;
2878 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
2880 ice_debug(hw, ICE_DBG_LINK, "set phy cfg\n");
2881 ice_debug(hw, ICE_DBG_LINK, " phy_type_low = 0x%llx\n",
2882 (unsigned long long)LE64_TO_CPU(cfg->phy_type_low));
2883 ice_debug(hw, ICE_DBG_LINK, " phy_type_high = 0x%llx\n",
2884 (unsigned long long)LE64_TO_CPU(cfg->phy_type_high));
2885 ice_debug(hw, ICE_DBG_LINK, " caps = 0x%x\n", cfg->caps);
2886 ice_debug(hw, ICE_DBG_LINK, " low_power_ctrl_an = 0x%x\n",
2887 cfg->low_power_ctrl_an);
2888 ice_debug(hw, ICE_DBG_LINK, " eee_cap = 0x%x\n", cfg->eee_cap);
2889 ice_debug(hw, ICE_DBG_LINK, " eeer_value = 0x%x\n", cfg->eeer_value);
2890 ice_debug(hw, ICE_DBG_LINK, " link_fec_opt = 0x%x\n",
2893 status = ice_aq_send_cmd(hw, &desc, cfg, sizeof(*cfg), cd);
2895 if (hw->adminq.sq_last_status == ICE_AQ_RC_EMODE)
2896 status = ICE_SUCCESS;
2899 pi->phy.curr_user_phy_cfg = *cfg;
2905 * ice_update_link_info - update status of the HW network link
2906 * @pi: port info structure of the interested logical port
2908 enum ice_status ice_update_link_info(struct ice_port_info *pi)
2910 struct ice_link_status *li;
2911 enum ice_status status;
2914 return ICE_ERR_PARAM;
2916 li = &pi->phy.link_info;
2918 status = ice_aq_get_link_info(pi, true, NULL, NULL);
2922 if (li->link_info & ICE_AQ_MEDIA_AVAILABLE) {
2923 struct ice_aqc_get_phy_caps_data *pcaps;
2927 pcaps = (struct ice_aqc_get_phy_caps_data *)
2928 ice_malloc(hw, sizeof(*pcaps));
2930 return ICE_ERR_NO_MEMORY;
2932 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
2935 if (status == ICE_SUCCESS)
2936 ice_memcpy(li->module_type, &pcaps->module_type,
2937 sizeof(li->module_type),
2938 ICE_NONDMA_TO_NONDMA);
2940 ice_free(hw, pcaps);
2947 * ice_cache_phy_user_req
2948 * @pi: port information structure
2949 * @cache_data: PHY logging data
2950 * @cache_mode: PHY logging mode
2952 * Log the user request on (FC, FEC, SPEED) for later user.
2955 ice_cache_phy_user_req(struct ice_port_info *pi,
2956 struct ice_phy_cache_mode_data cache_data,
2957 enum ice_phy_cache_mode cache_mode)
2962 switch (cache_mode) {
2964 pi->phy.curr_user_fc_req = cache_data.data.curr_user_fc_req;
2966 case ICE_SPEED_MODE:
2967 pi->phy.curr_user_speed_req =
2968 cache_data.data.curr_user_speed_req;
2971 pi->phy.curr_user_fec_req = cache_data.data.curr_user_fec_req;
2979 * ice_caps_to_fc_mode
2980 * @caps: PHY capabilities
2982 * Convert PHY FC capabilities to ice FC mode
2984 enum ice_fc_mode ice_caps_to_fc_mode(u8 caps)
2986 if (caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE &&
2987 caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)
2990 if (caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE)
2991 return ICE_FC_TX_PAUSE;
2993 if (caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)
2994 return ICE_FC_RX_PAUSE;
3000 * ice_caps_to_fec_mode
3001 * @caps: PHY capabilities
3002 * @fec_options: Link FEC options
3004 * Convert PHY FEC capabilities to ice FEC mode
3006 enum ice_fec_mode ice_caps_to_fec_mode(u8 caps, u8 fec_options)
3008 if (caps & ICE_AQC_PHY_EN_AUTO_FEC)
3009 return ICE_FEC_AUTO;
3011 if (fec_options & (ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN |
3012 ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ |
3013 ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN |
3014 ICE_AQC_PHY_FEC_25G_KR_REQ))
3015 return ICE_FEC_BASER;
3017 if (fec_options & (ICE_AQC_PHY_FEC_25G_RS_528_REQ |
3018 ICE_AQC_PHY_FEC_25G_RS_544_REQ |
3019 ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN))
3022 return ICE_FEC_NONE;
3026 * ice_cfg_phy_fc - Configure PHY FC data based on FC mode
3027 * @pi: port information structure
3028 * @cfg: PHY configuration data to set FC mode
3029 * @req_mode: FC mode to configure
3031 static enum ice_status
3032 ice_cfg_phy_fc(struct ice_port_info *pi, struct ice_aqc_set_phy_cfg_data *cfg,
3033 enum ice_fc_mode req_mode)
3035 struct ice_phy_cache_mode_data cache_data;
3036 u8 pause_mask = 0x0;
3039 return ICE_ERR_BAD_PTR;
3044 struct ice_aqc_get_phy_caps_data *pcaps;
3045 enum ice_status status;
3047 pcaps = (struct ice_aqc_get_phy_caps_data *)
3048 ice_malloc(pi->hw, sizeof(*pcaps));
3050 return ICE_ERR_NO_MEMORY;
3052 /* Query the value of FC that both the NIC and attached media
3055 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
3058 ice_free(pi->hw, pcaps);
3062 pause_mask |= pcaps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE;
3063 pause_mask |= pcaps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE;
3065 ice_free(pi->hw, pcaps);
3069 pause_mask |= ICE_AQC_PHY_EN_TX_LINK_PAUSE;
3070 pause_mask |= ICE_AQC_PHY_EN_RX_LINK_PAUSE;
3072 case ICE_FC_RX_PAUSE:
3073 pause_mask |= ICE_AQC_PHY_EN_RX_LINK_PAUSE;
3075 case ICE_FC_TX_PAUSE:
3076 pause_mask |= ICE_AQC_PHY_EN_TX_LINK_PAUSE;
3082 /* clear the old pause settings */
3083 cfg->caps &= ~(ICE_AQC_PHY_EN_TX_LINK_PAUSE |
3084 ICE_AQC_PHY_EN_RX_LINK_PAUSE);
3086 /* set the new capabilities */
3087 cfg->caps |= pause_mask;
3089 /* Cache user FC request */
3090 cache_data.data.curr_user_fc_req = req_mode;
3091 ice_cache_phy_user_req(pi, cache_data, ICE_FC_MODE);
3098 * @pi: port information structure
3099 * @aq_failures: pointer to status code, specific to ice_set_fc routine
3100 * @ena_auto_link_update: enable automatic link update
3102 * Set the requested flow control mode.
3105 ice_set_fc(struct ice_port_info *pi, u8 *aq_failures, bool ena_auto_link_update)
3107 struct ice_aqc_set_phy_cfg_data cfg = { 0 };
3108 struct ice_aqc_get_phy_caps_data *pcaps;
3109 enum ice_status status;
3112 if (!pi || !aq_failures)
3113 return ICE_ERR_BAD_PTR;
3118 pcaps = (struct ice_aqc_get_phy_caps_data *)
3119 ice_malloc(hw, sizeof(*pcaps));
3121 return ICE_ERR_NO_MEMORY;
3123 /* Get the current PHY config */
3124 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG,
3128 *aq_failures = ICE_SET_FC_AQ_FAIL_GET;
3132 ice_copy_phy_caps_to_cfg(pi, pcaps, &cfg);
3134 /* Configure the set PHY data */
3135 status = ice_cfg_phy_fc(pi, &cfg, pi->fc.req_mode);
3137 if (status != ICE_ERR_BAD_PTR)
3138 *aq_failures = ICE_SET_FC_AQ_FAIL_GET;
3143 /* If the capabilities have changed, then set the new config */
3144 if (cfg.caps != pcaps->caps) {
3145 int retry_count, retry_max = 10;
3147 /* Auto restart link so settings take effect */
3148 if (ena_auto_link_update)
3149 cfg.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
3151 status = ice_aq_set_phy_cfg(hw, pi, &cfg, NULL);
3153 *aq_failures = ICE_SET_FC_AQ_FAIL_SET;
3157 /* Update the link info
3158 * It sometimes takes a really long time for link to
3159 * come back from the atomic reset. Thus, we wait a
3162 for (retry_count = 0; retry_count < retry_max; retry_count++) {
3163 status = ice_update_link_info(pi);
3165 if (status == ICE_SUCCESS)
3168 ice_msec_delay(100, true);
3172 *aq_failures = ICE_SET_FC_AQ_FAIL_UPDATE;
3176 ice_free(hw, pcaps);
3181 * ice_phy_caps_equals_cfg
3182 * @phy_caps: PHY capabilities
3183 * @phy_cfg: PHY configuration
3185 * Helper function to determine if PHY capabilities matches PHY
3189 ice_phy_caps_equals_cfg(struct ice_aqc_get_phy_caps_data *phy_caps,
3190 struct ice_aqc_set_phy_cfg_data *phy_cfg)
3192 u8 caps_mask, cfg_mask;
3194 if (!phy_caps || !phy_cfg)
3197 /* These bits are not common between capabilities and configuration.
3198 * Do not use them to determine equality.
3200 caps_mask = ICE_AQC_PHY_CAPS_MASK & ~(ICE_AQC_PHY_AN_MODE |
3201 ICE_AQC_PHY_EN_MOD_QUAL);
3202 cfg_mask = ICE_AQ_PHY_ENA_VALID_MASK & ~ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
3204 if (phy_caps->phy_type_low != phy_cfg->phy_type_low ||
3205 phy_caps->phy_type_high != phy_cfg->phy_type_high ||
3206 ((phy_caps->caps & caps_mask) != (phy_cfg->caps & cfg_mask)) ||
3207 phy_caps->low_power_ctrl_an != phy_cfg->low_power_ctrl_an ||
3208 phy_caps->eee_cap != phy_cfg->eee_cap ||
3209 phy_caps->eeer_value != phy_cfg->eeer_value ||
3210 phy_caps->link_fec_options != phy_cfg->link_fec_opt)
3217 * ice_copy_phy_caps_to_cfg - Copy PHY ability data to configuration data
3218 * @pi: port information structure
3219 * @caps: PHY ability structure to copy date from
3220 * @cfg: PHY configuration structure to copy data to
3222 * Helper function to copy AQC PHY get ability data to PHY set configuration
3226 ice_copy_phy_caps_to_cfg(struct ice_port_info *pi,
3227 struct ice_aqc_get_phy_caps_data *caps,
3228 struct ice_aqc_set_phy_cfg_data *cfg)
3230 if (!pi || !caps || !cfg)
3233 ice_memset(cfg, 0, sizeof(*cfg), ICE_NONDMA_MEM);
3234 cfg->phy_type_low = caps->phy_type_low;
3235 cfg->phy_type_high = caps->phy_type_high;
3236 cfg->caps = caps->caps;
3237 cfg->low_power_ctrl_an = caps->low_power_ctrl_an;
3238 cfg->eee_cap = caps->eee_cap;
3239 cfg->eeer_value = caps->eeer_value;
3240 cfg->link_fec_opt = caps->link_fec_options;
3241 cfg->module_compliance_enforcement =
3242 caps->module_compliance_enforcement;
3246 * ice_cfg_phy_fec - Configure PHY FEC data based on FEC mode
3247 * @pi: port information structure
3248 * @cfg: PHY configuration data to set FEC mode
3249 * @fec: FEC mode to configure
3252 ice_cfg_phy_fec(struct ice_port_info *pi, struct ice_aqc_set_phy_cfg_data *cfg,
3253 enum ice_fec_mode fec)
3255 struct ice_aqc_get_phy_caps_data *pcaps;
3256 enum ice_status status = ICE_SUCCESS;
3260 return ICE_ERR_BAD_PTR;
3264 pcaps = (struct ice_aqc_get_phy_caps_data *)
3265 ice_malloc(hw, sizeof(*pcaps));
3267 return ICE_ERR_NO_MEMORY;
3269 status = ice_aq_get_phy_caps(pi, false,
3270 (ice_fw_supports_report_dflt_cfg(hw) ?
3271 ICE_AQC_REPORT_DFLT_CFG :
3272 ICE_AQC_REPORT_TOPO_CAP_MEDIA), pcaps, NULL);
3277 cfg->caps |= (pcaps->caps & ICE_AQC_PHY_EN_AUTO_FEC);
3278 cfg->link_fec_opt = pcaps->link_fec_options;
3282 /* Clear RS bits, and AND BASE-R ability
3283 * bits and OR request bits.
3285 cfg->link_fec_opt &= ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN |
3286 ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN;
3287 cfg->link_fec_opt |= ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ |
3288 ICE_AQC_PHY_FEC_25G_KR_REQ;
3291 /* Clear BASE-R bits, and AND RS ability
3292 * bits and OR request bits.
3294 cfg->link_fec_opt &= ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN;
3295 cfg->link_fec_opt |= ICE_AQC_PHY_FEC_25G_RS_528_REQ |
3296 ICE_AQC_PHY_FEC_25G_RS_544_REQ;
3299 /* Clear all FEC option bits. */
3300 cfg->link_fec_opt &= ~ICE_AQC_PHY_FEC_MASK;
3303 /* AND auto FEC bit, and all caps bits. */
3304 cfg->caps &= ICE_AQC_PHY_CAPS_MASK;
3305 cfg->link_fec_opt |= pcaps->link_fec_options;
3308 status = ICE_ERR_PARAM;
3312 if (fec == ICE_FEC_AUTO && ice_fw_supports_link_override(pi->hw) &&
3313 !ice_fw_supports_report_dflt_cfg(pi->hw)) {
3314 struct ice_link_default_override_tlv tlv;
3316 if (ice_get_link_default_override(&tlv, pi))
3319 if (!(tlv.options & ICE_LINK_OVERRIDE_STRICT_MODE) &&
3320 (tlv.options & ICE_LINK_OVERRIDE_EN))
3321 cfg->link_fec_opt = tlv.fec_options;
3325 ice_free(hw, pcaps);
3331 * ice_get_link_status - get status of the HW network link
3332 * @pi: port information structure
3333 * @link_up: pointer to bool (true/false = linkup/linkdown)
3335 * Variable link_up is true if link is up, false if link is down.
3336 * The variable link_up is invalid if status is non zero. As a
3337 * result of this call, link status reporting becomes enabled
3339 enum ice_status ice_get_link_status(struct ice_port_info *pi, bool *link_up)
3341 struct ice_phy_info *phy_info;
3342 enum ice_status status = ICE_SUCCESS;
3344 if (!pi || !link_up)
3345 return ICE_ERR_PARAM;
3347 phy_info = &pi->phy;
3349 if (phy_info->get_link_info) {
3350 status = ice_update_link_info(pi);
3353 ice_debug(pi->hw, ICE_DBG_LINK, "get link status error, status = %d\n",
3357 *link_up = phy_info->link_info.link_info & ICE_AQ_LINK_UP;
3363 * ice_aq_set_link_restart_an
3364 * @pi: pointer to the port information structure
3365 * @ena_link: if true: enable link, if false: disable link
3366 * @cd: pointer to command details structure or NULL
3368 * Sets up the link and restarts the Auto-Negotiation over the link.
3371 ice_aq_set_link_restart_an(struct ice_port_info *pi, bool ena_link,
3372 struct ice_sq_cd *cd)
3374 struct ice_aqc_restart_an *cmd;
3375 struct ice_aq_desc desc;
3377 cmd = &desc.params.restart_an;
3379 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_restart_an);
3381 cmd->cmd_flags = ICE_AQC_RESTART_AN_LINK_RESTART;
3382 cmd->lport_num = pi->lport;
3384 cmd->cmd_flags |= ICE_AQC_RESTART_AN_LINK_ENABLE;
3386 cmd->cmd_flags &= ~ICE_AQC_RESTART_AN_LINK_ENABLE;
3388 return ice_aq_send_cmd(pi->hw, &desc, NULL, 0, cd);
3392 * ice_aq_set_event_mask
3393 * @hw: pointer to the HW struct
3394 * @port_num: port number of the physical function
3395 * @mask: event mask to be set
3396 * @cd: pointer to command details structure or NULL
3398 * Set event mask (0x0613)
3401 ice_aq_set_event_mask(struct ice_hw *hw, u8 port_num, u16 mask,
3402 struct ice_sq_cd *cd)
3404 struct ice_aqc_set_event_mask *cmd;
3405 struct ice_aq_desc desc;
3407 cmd = &desc.params.set_event_mask;
3409 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_event_mask);
3411 cmd->lport_num = port_num;
3413 cmd->event_mask = CPU_TO_LE16(mask);
3414 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
3418 * ice_aq_set_mac_loopback
3419 * @hw: pointer to the HW struct
3420 * @ena_lpbk: Enable or Disable loopback
3421 * @cd: pointer to command details structure or NULL
3423 * Enable/disable loopback on a given port
3426 ice_aq_set_mac_loopback(struct ice_hw *hw, bool ena_lpbk, struct ice_sq_cd *cd)
3428 struct ice_aqc_set_mac_lb *cmd;
3429 struct ice_aq_desc desc;
3431 cmd = &desc.params.set_mac_lb;
3433 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_mac_lb);
3435 cmd->lb_mode = ICE_AQ_MAC_LB_EN;
3437 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
3441 * ice_aq_set_port_id_led
3442 * @pi: pointer to the port information
3443 * @is_orig_mode: is this LED set to original mode (by the net-list)
3444 * @cd: pointer to command details structure or NULL
3446 * Set LED value for the given port (0x06e9)
3449 ice_aq_set_port_id_led(struct ice_port_info *pi, bool is_orig_mode,
3450 struct ice_sq_cd *cd)
3452 struct ice_aqc_set_port_id_led *cmd;
3453 struct ice_hw *hw = pi->hw;
3454 struct ice_aq_desc desc;
3456 cmd = &desc.params.set_port_id_led;
3458 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_port_id_led);
3461 cmd->ident_mode = ICE_AQC_PORT_IDENT_LED_ORIG;
3463 cmd->ident_mode = ICE_AQC_PORT_IDENT_LED_BLINK;
3465 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
3470 * @hw: pointer to the HW struct
3471 * @lport: bits [7:0] = logical port, bit [8] = logical port valid
3472 * @bus_addr: I2C bus address of the eeprom (typically 0xA0, 0=topo default)
3473 * @mem_addr: I2C offset. lower 8 bits for address, 8 upper bits zero padding.
3475 * @set_page: set or ignore the page
3476 * @data: pointer to data buffer to be read/written to the I2C device.
3477 * @length: 1-16 for read, 1 for write.
3478 * @write: 0 read, 1 for write.
3479 * @cd: pointer to command details structure or NULL
3481 * Read/Write SFF EEPROM (0x06EE)
3484 ice_aq_sff_eeprom(struct ice_hw *hw, u16 lport, u8 bus_addr,
3485 u16 mem_addr, u8 page, u8 set_page, u8 *data, u8 length,
3486 bool write, struct ice_sq_cd *cd)
3488 struct ice_aqc_sff_eeprom *cmd;
3489 struct ice_aq_desc desc;
3490 enum ice_status status;
3492 if (!data || (mem_addr & 0xff00))
3493 return ICE_ERR_PARAM;
3495 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_sff_eeprom);
3496 cmd = &desc.params.read_write_sff_param;
3497 desc.flags = CPU_TO_LE16(ICE_AQ_FLAG_RD);
3498 cmd->lport_num = (u8)(lport & 0xff);
3499 cmd->lport_num_valid = (u8)((lport >> 8) & 0x01);
3500 cmd->i2c_bus_addr = CPU_TO_LE16(((bus_addr >> 1) &
3501 ICE_AQC_SFF_I2CBUS_7BIT_M) |
3503 ICE_AQC_SFF_SET_EEPROM_PAGE_S) &
3504 ICE_AQC_SFF_SET_EEPROM_PAGE_M));
3505 cmd->i2c_mem_addr = CPU_TO_LE16(mem_addr & 0xff);
3506 cmd->eeprom_page = CPU_TO_LE16((u16)page << ICE_AQC_SFF_EEPROM_PAGE_S);
3508 cmd->i2c_bus_addr |= CPU_TO_LE16(ICE_AQC_SFF_IS_WRITE);
3510 status = ice_aq_send_cmd(hw, &desc, data, length, cd);
3515 * ice_aq_prog_topo_dev_nvm
3516 * @hw: pointer to the hardware structure
3517 * @topo_params: pointer to structure storing topology parameters for a device
3518 * @cd: pointer to command details structure or NULL
3520 * Program Topology Device NVM (0x06F2)
3524 ice_aq_prog_topo_dev_nvm(struct ice_hw *hw,
3525 struct ice_aqc_link_topo_params *topo_params,
3526 struct ice_sq_cd *cd)
3528 struct ice_aqc_prog_topo_dev_nvm *cmd;
3529 struct ice_aq_desc desc;
3531 cmd = &desc.params.prog_topo_dev_nvm;
3533 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_prog_topo_dev_nvm);
3535 ice_memcpy(&cmd->topo_params, topo_params, sizeof(*topo_params),
3536 ICE_NONDMA_TO_NONDMA);
3538 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
3542 * ice_aq_read_topo_dev_nvm
3543 * @hw: pointer to the hardware structure
3544 * @topo_params: pointer to structure storing topology parameters for a device
3545 * @start_address: byte offset in the topology device NVM
3546 * @data: pointer to data buffer
3547 * @data_size: number of bytes to be read from the topology device NVM
3548 * @cd: pointer to command details structure or NULL
3549 * Read Topology Device NVM (0x06F3)
3553 ice_aq_read_topo_dev_nvm(struct ice_hw *hw,
3554 struct ice_aqc_link_topo_params *topo_params,
3555 u32 start_address, u8 *data, u8 data_size,
3556 struct ice_sq_cd *cd)
3558 struct ice_aqc_read_topo_dev_nvm *cmd;
3559 struct ice_aq_desc desc;
3560 enum ice_status status;
3562 if (!data || data_size == 0 ||
3563 data_size > ICE_AQC_READ_TOPO_DEV_NVM_DATA_READ_SIZE)
3564 return ICE_ERR_PARAM;
3566 cmd = &desc.params.read_topo_dev_nvm;
3568 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_read_topo_dev_nvm);
3570 desc.datalen = data_size;
3571 ice_memcpy(&cmd->topo_params, topo_params, sizeof(*topo_params),
3572 ICE_NONDMA_TO_NONDMA);
3573 cmd->start_address = CPU_TO_LE32(start_address);
3575 status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
3579 ice_memcpy(data, cmd->data_read, data_size, ICE_NONDMA_TO_NONDMA);
3585 * __ice_aq_get_set_rss_lut
3586 * @hw: pointer to the hardware structure
3587 * @params: RSS LUT parameters
3588 * @set: set true to set the table, false to get the table
3590 * Internal function to get (0x0B05) or set (0x0B03) RSS look up table
3592 static enum ice_status
3593 __ice_aq_get_set_rss_lut(struct ice_hw *hw, struct ice_aq_get_set_rss_lut_params *params, bool set)
3595 u16 flags = 0, vsi_id, lut_type, lut_size, glob_lut_idx, vsi_handle;
3596 struct ice_aqc_get_set_rss_lut *cmd_resp;
3597 struct ice_aq_desc desc;
3598 enum ice_status status;
3602 return ICE_ERR_PARAM;
3604 vsi_handle = params->vsi_handle;
3607 if (!ice_is_vsi_valid(hw, vsi_handle) || !lut)
3608 return ICE_ERR_PARAM;
3610 lut_size = params->lut_size;
3611 lut_type = params->lut_type;
3612 glob_lut_idx = params->global_lut_id;
3613 vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
3615 cmd_resp = &desc.params.get_set_rss_lut;
3618 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_rss_lut);
3619 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
3621 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_rss_lut);
3624 cmd_resp->vsi_id = CPU_TO_LE16(((vsi_id <<
3625 ICE_AQC_GSET_RSS_LUT_VSI_ID_S) &
3626 ICE_AQC_GSET_RSS_LUT_VSI_ID_M) |
3627 ICE_AQC_GSET_RSS_LUT_VSI_VALID);
3630 case ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_VSI:
3631 case ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF:
3632 case ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_GLOBAL:
3633 flags |= ((lut_type << ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_S) &
3634 ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_M);
3637 status = ICE_ERR_PARAM;
3638 goto ice_aq_get_set_rss_lut_exit;
3641 if (lut_type == ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_GLOBAL) {
3642 flags |= ((glob_lut_idx << ICE_AQC_GSET_RSS_LUT_GLOBAL_IDX_S) &
3643 ICE_AQC_GSET_RSS_LUT_GLOBAL_IDX_M);
3646 goto ice_aq_get_set_rss_lut_send;
3647 } else if (lut_type == ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF) {
3649 goto ice_aq_get_set_rss_lut_send;
3651 goto ice_aq_get_set_rss_lut_send;
3654 /* LUT size is only valid for Global and PF table types */
3656 case ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_128:
3657 flags |= (ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_128_FLAG <<
3658 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_S) &
3659 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_M;
3661 case ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_512:
3662 flags |= (ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_512_FLAG <<
3663 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_S) &
3664 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_M;
3666 case ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K:
3667 if (lut_type == ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF) {
3668 flags |= (ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K_FLAG <<
3669 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_S) &
3670 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_M;
3675 status = ICE_ERR_PARAM;
3676 goto ice_aq_get_set_rss_lut_exit;
3679 ice_aq_get_set_rss_lut_send:
3680 cmd_resp->flags = CPU_TO_LE16(flags);
3681 status = ice_aq_send_cmd(hw, &desc, lut, lut_size, NULL);
3683 ice_aq_get_set_rss_lut_exit:
3688 * ice_aq_get_rss_lut
3689 * @hw: pointer to the hardware structure
3690 * @get_params: RSS LUT parameters used to specify which RSS LUT to get
3692 * get the RSS lookup table, PF or VSI type
3695 ice_aq_get_rss_lut(struct ice_hw *hw, struct ice_aq_get_set_rss_lut_params *get_params)
3697 return __ice_aq_get_set_rss_lut(hw, get_params, false);
3701 * ice_aq_set_rss_lut
3702 * @hw: pointer to the hardware structure
3703 * @set_params: RSS LUT parameters used to specify how to set the RSS LUT
3705 * set the RSS lookup table, PF or VSI type
3708 ice_aq_set_rss_lut(struct ice_hw *hw, struct ice_aq_get_set_rss_lut_params *set_params)
3710 return __ice_aq_get_set_rss_lut(hw, set_params, true);
3714 * __ice_aq_get_set_rss_key
3715 * @hw: pointer to the HW struct
3716 * @vsi_id: VSI FW index
3717 * @key: pointer to key info struct
3718 * @set: set true to set the key, false to get the key
3720 * get (0x0B04) or set (0x0B02) the RSS key per VSI
3723 ice_status __ice_aq_get_set_rss_key(struct ice_hw *hw, u16 vsi_id,
3724 struct ice_aqc_get_set_rss_keys *key,
3727 struct ice_aqc_get_set_rss_key *cmd_resp;
3728 u16 key_size = sizeof(*key);
3729 struct ice_aq_desc desc;
3731 cmd_resp = &desc.params.get_set_rss_key;
3734 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_rss_key);
3735 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
3737 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_rss_key);
3740 cmd_resp->vsi_id = CPU_TO_LE16(((vsi_id <<
3741 ICE_AQC_GSET_RSS_KEY_VSI_ID_S) &
3742 ICE_AQC_GSET_RSS_KEY_VSI_ID_M) |
3743 ICE_AQC_GSET_RSS_KEY_VSI_VALID);
3745 return ice_aq_send_cmd(hw, &desc, key, key_size, NULL);
3749 * ice_aq_get_rss_key
3750 * @hw: pointer to the HW struct
3751 * @vsi_handle: software VSI handle
3752 * @key: pointer to key info struct
3754 * get the RSS key per VSI
3757 ice_aq_get_rss_key(struct ice_hw *hw, u16 vsi_handle,
3758 struct ice_aqc_get_set_rss_keys *key)
3760 if (!ice_is_vsi_valid(hw, vsi_handle) || !key)
3761 return ICE_ERR_PARAM;
3763 return __ice_aq_get_set_rss_key(hw, ice_get_hw_vsi_num(hw, vsi_handle),
3768 * ice_aq_set_rss_key
3769 * @hw: pointer to the HW struct
3770 * @vsi_handle: software VSI handle
3771 * @keys: pointer to key info struct
3773 * set the RSS key per VSI
3776 ice_aq_set_rss_key(struct ice_hw *hw, u16 vsi_handle,
3777 struct ice_aqc_get_set_rss_keys *keys)
3779 if (!ice_is_vsi_valid(hw, vsi_handle) || !keys)
3780 return ICE_ERR_PARAM;
3782 return __ice_aq_get_set_rss_key(hw, ice_get_hw_vsi_num(hw, vsi_handle),
3787 * ice_aq_add_lan_txq
3788 * @hw: pointer to the hardware structure
3789 * @num_qgrps: Number of added queue groups
3790 * @qg_list: list of queue groups to be added
3791 * @buf_size: size of buffer for indirect command
3792 * @cd: pointer to command details structure or NULL
3794 * Add Tx LAN queue (0x0C30)
3797 * Prior to calling add Tx LAN queue:
3798 * Initialize the following as part of the Tx queue context:
3799 * Completion queue ID if the queue uses Completion queue, Quanta profile,
3800 * Cache profile and Packet shaper profile.
3802 * After add Tx LAN queue AQ command is completed:
3803 * Interrupts should be associated with specific queues,
3804 * Association of Tx queue to Doorbell queue is not part of Add LAN Tx queue
3808 ice_aq_add_lan_txq(struct ice_hw *hw, u8 num_qgrps,
3809 struct ice_aqc_add_tx_qgrp *qg_list, u16 buf_size,
3810 struct ice_sq_cd *cd)
3812 struct ice_aqc_add_tx_qgrp *list;
3813 struct ice_aqc_add_txqs *cmd;
3814 struct ice_aq_desc desc;
3815 u16 i, sum_size = 0;
3817 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
3819 cmd = &desc.params.add_txqs;
3821 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_add_txqs);
3824 return ICE_ERR_PARAM;
3826 if (num_qgrps > ICE_LAN_TXQ_MAX_QGRPS)
3827 return ICE_ERR_PARAM;
3829 for (i = 0, list = qg_list; i < num_qgrps; i++) {
3830 sum_size += ice_struct_size(list, txqs, list->num_txqs);
3831 list = (struct ice_aqc_add_tx_qgrp *)(list->txqs +
3835 if (buf_size != sum_size)
3836 return ICE_ERR_PARAM;
3838 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
3840 cmd->num_qgrps = num_qgrps;
3842 return ice_aq_send_cmd(hw, &desc, qg_list, buf_size, cd);
3846 * ice_aq_dis_lan_txq
3847 * @hw: pointer to the hardware structure
3848 * @num_qgrps: number of groups in the list
3849 * @qg_list: the list of groups to disable
3850 * @buf_size: the total size of the qg_list buffer in bytes
3851 * @rst_src: if called due to reset, specifies the reset source
3852 * @vmvf_num: the relative VM or VF number that is undergoing the reset
3853 * @cd: pointer to command details structure or NULL
3855 * Disable LAN Tx queue (0x0C31)
3857 static enum ice_status
3858 ice_aq_dis_lan_txq(struct ice_hw *hw, u8 num_qgrps,
3859 struct ice_aqc_dis_txq_item *qg_list, u16 buf_size,
3860 enum ice_disq_rst_src rst_src, u16 vmvf_num,
3861 struct ice_sq_cd *cd)
3863 struct ice_aqc_dis_txq_item *item;
3864 struct ice_aqc_dis_txqs *cmd;
3865 struct ice_aq_desc desc;
3866 enum ice_status status;
3869 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
3870 cmd = &desc.params.dis_txqs;
3871 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_dis_txqs);
3873 /* qg_list can be NULL only in VM/VF reset flow */
3874 if (!qg_list && !rst_src)
3875 return ICE_ERR_PARAM;
3877 if (num_qgrps > ICE_LAN_TXQ_MAX_QGRPS)
3878 return ICE_ERR_PARAM;
3880 cmd->num_entries = num_qgrps;
3882 cmd->vmvf_and_timeout = CPU_TO_LE16((5 << ICE_AQC_Q_DIS_TIMEOUT_S) &
3883 ICE_AQC_Q_DIS_TIMEOUT_M);
3887 cmd->cmd_type = ICE_AQC_Q_DIS_CMD_VM_RESET;
3888 cmd->vmvf_and_timeout |=
3889 CPU_TO_LE16(vmvf_num & ICE_AQC_Q_DIS_VMVF_NUM_M);
3896 /* flush pipe on time out */
3897 cmd->cmd_type |= ICE_AQC_Q_DIS_CMD_FLUSH_PIPE;
3898 /* If no queue group info, we are in a reset flow. Issue the AQ */
3902 /* set RD bit to indicate that command buffer is provided by the driver
3903 * and it needs to be read by the firmware
3905 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
3907 for (i = 0, item = qg_list; i < num_qgrps; i++) {
3908 u16 item_size = ice_struct_size(item, q_id, item->num_qs);
3910 /* If the num of queues is even, add 2 bytes of padding */
3911 if ((item->num_qs % 2) == 0)
3916 item = (struct ice_aqc_dis_txq_item *)((u8 *)item + item_size);
3920 return ICE_ERR_PARAM;
3923 status = ice_aq_send_cmd(hw, &desc, qg_list, buf_size, cd);
3926 ice_debug(hw, ICE_DBG_SCHED, "VM%d disable failed %d\n",
3927 vmvf_num, hw->adminq.sq_last_status);
3929 ice_debug(hw, ICE_DBG_SCHED, "disable queue %d failed %d\n",
3930 LE16_TO_CPU(qg_list[0].q_id[0]),
3931 hw->adminq.sq_last_status);
3937 * ice_aq_move_recfg_lan_txq
3938 * @hw: pointer to the hardware structure
3939 * @num_qs: number of queues to move/reconfigure
3940 * @is_move: true if this operation involves node movement
3941 * @is_tc_change: true if this operation involves a TC change
3942 * @subseq_call: true if this operation is a subsequent call
3943 * @flush_pipe: on timeout, true to flush pipe, false to return EAGAIN
3944 * @timeout: timeout in units of 100 usec (valid values 0-50)
3945 * @blocked_cgds: out param, bitmap of CGDs that timed out if returning EAGAIN
3946 * @buf: struct containing src/dest TEID and per-queue info
3947 * @buf_size: size of buffer for indirect command
3948 * @txqs_moved: out param, number of queues successfully moved
3949 * @cd: pointer to command details structure or NULL
3951 * Move / Reconfigure Tx LAN queues (0x0C32)
3954 ice_aq_move_recfg_lan_txq(struct ice_hw *hw, u8 num_qs, bool is_move,
3955 bool is_tc_change, bool subseq_call, bool flush_pipe,
3956 u8 timeout, u32 *blocked_cgds,
3957 struct ice_aqc_move_txqs_data *buf, u16 buf_size,
3958 u8 *txqs_moved, struct ice_sq_cd *cd)
3960 struct ice_aqc_move_txqs *cmd;
3961 struct ice_aq_desc desc;
3962 enum ice_status status;
3964 cmd = &desc.params.move_txqs;
3965 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_move_recfg_txqs);
3967 #define ICE_LAN_TXQ_MOVE_TIMEOUT_MAX 50
3968 if (timeout > ICE_LAN_TXQ_MOVE_TIMEOUT_MAX)
3969 return ICE_ERR_PARAM;
3971 if (is_tc_change && !flush_pipe && !blocked_cgds)
3972 return ICE_ERR_PARAM;
3974 if (!is_move && !is_tc_change)
3975 return ICE_ERR_PARAM;
3977 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
3980 cmd->cmd_type |= ICE_AQC_Q_CMD_TYPE_MOVE;
3983 cmd->cmd_type |= ICE_AQC_Q_CMD_TYPE_TC_CHANGE;
3986 cmd->cmd_type |= ICE_AQC_Q_CMD_SUBSEQ_CALL;
3989 cmd->cmd_type |= ICE_AQC_Q_CMD_FLUSH_PIPE;
3991 cmd->num_qs = num_qs;
3992 cmd->timeout = ((timeout << ICE_AQC_Q_CMD_TIMEOUT_S) &
3993 ICE_AQC_Q_CMD_TIMEOUT_M);
3995 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
3997 if (!status && txqs_moved)
3998 *txqs_moved = cmd->num_qs;
4000 if (hw->adminq.sq_last_status == ICE_AQ_RC_EAGAIN &&
4001 is_tc_change && !flush_pipe)
4002 *blocked_cgds = LE32_TO_CPU(cmd->blocked_cgds);
4007 /* End of FW Admin Queue command wrappers */
4010 * ice_write_byte - write a byte to a packed context structure
4011 * @src_ctx: the context structure to read from
4012 * @dest_ctx: the context to be written to
4013 * @ce_info: a description of the struct to be filled
4016 ice_write_byte(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info)
4018 u8 src_byte, dest_byte, mask;
4022 /* copy from the next struct field */
4023 from = src_ctx + ce_info->offset;
4025 /* prepare the bits and mask */
4026 shift_width = ce_info->lsb % 8;
4027 mask = (u8)(BIT(ce_info->width) - 1);
4032 /* shift to correct alignment */
4033 mask <<= shift_width;
4034 src_byte <<= shift_width;
4036 /* get the current bits from the target bit string */
4037 dest = dest_ctx + (ce_info->lsb / 8);
4039 ice_memcpy(&dest_byte, dest, sizeof(dest_byte), ICE_DMA_TO_NONDMA);
4041 dest_byte &= ~mask; /* get the bits not changing */
4042 dest_byte |= src_byte; /* add in the new bits */
4044 /* put it all back */
4045 ice_memcpy(dest, &dest_byte, sizeof(dest_byte), ICE_NONDMA_TO_DMA);
4049 * ice_write_word - write a word to a packed context structure
4050 * @src_ctx: the context structure to read from
4051 * @dest_ctx: the context to be written to
4052 * @ce_info: a description of the struct to be filled
4055 ice_write_word(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info)
4062 /* copy from the next struct field */
4063 from = src_ctx + ce_info->offset;
4065 /* prepare the bits and mask */
4066 shift_width = ce_info->lsb % 8;
4067 mask = BIT(ce_info->width) - 1;
4069 /* don't swizzle the bits until after the mask because the mask bits
4070 * will be in a different bit position on big endian machines
4072 src_word = *(u16 *)from;
4075 /* shift to correct alignment */
4076 mask <<= shift_width;
4077 src_word <<= shift_width;
4079 /* get the current bits from the target bit string */
4080 dest = dest_ctx + (ce_info->lsb / 8);
4082 ice_memcpy(&dest_word, dest, sizeof(dest_word), ICE_DMA_TO_NONDMA);
4084 dest_word &= ~(CPU_TO_LE16(mask)); /* get the bits not changing */
4085 dest_word |= CPU_TO_LE16(src_word); /* add in the new bits */
4087 /* put it all back */
4088 ice_memcpy(dest, &dest_word, sizeof(dest_word), ICE_NONDMA_TO_DMA);
4092 * ice_write_dword - write a dword to a packed context structure
4093 * @src_ctx: the context structure to read from
4094 * @dest_ctx: the context to be written to
4095 * @ce_info: a description of the struct to be filled
4098 ice_write_dword(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info)
4100 u32 src_dword, mask;
4105 /* copy from the next struct field */
4106 from = src_ctx + ce_info->offset;
4108 /* prepare the bits and mask */
4109 shift_width = ce_info->lsb % 8;
4111 /* if the field width is exactly 32 on an x86 machine, then the shift
4112 * operation will not work because the SHL instructions count is masked
4113 * to 5 bits so the shift will do nothing
4115 if (ce_info->width < 32)
4116 mask = BIT(ce_info->width) - 1;
4120 /* don't swizzle the bits until after the mask because the mask bits
4121 * will be in a different bit position on big endian machines
4123 src_dword = *(u32 *)from;
4126 /* shift to correct alignment */
4127 mask <<= shift_width;
4128 src_dword <<= shift_width;
4130 /* get the current bits from the target bit string */
4131 dest = dest_ctx + (ce_info->lsb / 8);
4133 ice_memcpy(&dest_dword, dest, sizeof(dest_dword), ICE_DMA_TO_NONDMA);
4135 dest_dword &= ~(CPU_TO_LE32(mask)); /* get the bits not changing */
4136 dest_dword |= CPU_TO_LE32(src_dword); /* add in the new bits */
4138 /* put it all back */
4139 ice_memcpy(dest, &dest_dword, sizeof(dest_dword), ICE_NONDMA_TO_DMA);
4143 * ice_write_qword - write a qword to a packed context structure
4144 * @src_ctx: the context structure to read from
4145 * @dest_ctx: the context to be written to
4146 * @ce_info: a description of the struct to be filled
4149 ice_write_qword(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info)
4151 u64 src_qword, mask;
4156 /* copy from the next struct field */
4157 from = src_ctx + ce_info->offset;
4159 /* prepare the bits and mask */
4160 shift_width = ce_info->lsb % 8;
4162 /* if the field width is exactly 64 on an x86 machine, then the shift
4163 * operation will not work because the SHL instructions count is masked
4164 * to 6 bits so the shift will do nothing
4166 if (ce_info->width < 64)
4167 mask = BIT_ULL(ce_info->width) - 1;
4171 /* don't swizzle the bits until after the mask because the mask bits
4172 * will be in a different bit position on big endian machines
4174 src_qword = *(u64 *)from;
4177 /* shift to correct alignment */
4178 mask <<= shift_width;
4179 src_qword <<= shift_width;
4181 /* get the current bits from the target bit string */
4182 dest = dest_ctx + (ce_info->lsb / 8);
4184 ice_memcpy(&dest_qword, dest, sizeof(dest_qword), ICE_DMA_TO_NONDMA);
4186 dest_qword &= ~(CPU_TO_LE64(mask)); /* get the bits not changing */
4187 dest_qword |= CPU_TO_LE64(src_qword); /* add in the new bits */
4189 /* put it all back */
4190 ice_memcpy(dest, &dest_qword, sizeof(dest_qword), ICE_NONDMA_TO_DMA);
4194 * ice_set_ctx - set context bits in packed structure
4195 * @hw: pointer to the hardware structure
4196 * @src_ctx: pointer to a generic non-packed context structure
4197 * @dest_ctx: pointer to memory for the packed structure
4198 * @ce_info: a description of the structure to be transformed
4201 ice_set_ctx(struct ice_hw *hw, u8 *src_ctx, u8 *dest_ctx,
4202 const struct ice_ctx_ele *ce_info)
4206 for (f = 0; ce_info[f].width; f++) {
4207 /* We have to deal with each element of the FW response
4208 * using the correct size so that we are correct regardless
4209 * of the endianness of the machine.
4211 if (ce_info[f].width > (ce_info[f].size_of * BITS_PER_BYTE)) {
4212 ice_debug(hw, ICE_DBG_QCTX, "Field %d width of %d bits larger than size of %d byte(s) ... skipping write\n",
4213 f, ce_info[f].width, ce_info[f].size_of);
4216 switch (ce_info[f].size_of) {
4218 ice_write_byte(src_ctx, dest_ctx, &ce_info[f]);
4221 ice_write_word(src_ctx, dest_ctx, &ce_info[f]);
4224 ice_write_dword(src_ctx, dest_ctx, &ce_info[f]);
4227 ice_write_qword(src_ctx, dest_ctx, &ce_info[f]);
4230 return ICE_ERR_INVAL_SIZE;
4238 * ice_read_byte - read context byte into struct
4239 * @src_ctx: the context structure to read from
4240 * @dest_ctx: the context to be written to
4241 * @ce_info: a description of the struct to be filled
4244 ice_read_byte(u8 *src_ctx, u8 *dest_ctx, struct ice_ctx_ele *ce_info)
4250 /* prepare the bits and mask */
4251 shift_width = ce_info->lsb % 8;
4252 mask = (u8)(BIT(ce_info->width) - 1);
4254 /* shift to correct alignment */
4255 mask <<= shift_width;
4257 /* get the current bits from the src bit string */
4258 src = src_ctx + (ce_info->lsb / 8);
4260 ice_memcpy(&dest_byte, src, sizeof(dest_byte), ICE_DMA_TO_NONDMA);
4262 dest_byte &= ~(mask);
4264 dest_byte >>= shift_width;
4266 /* get the address from the struct field */
4267 target = dest_ctx + ce_info->offset;
4269 /* put it back in the struct */
4270 ice_memcpy(target, &dest_byte, sizeof(dest_byte), ICE_NONDMA_TO_DMA);
4274 * ice_read_word - read context word into struct
4275 * @src_ctx: the context structure to read from
4276 * @dest_ctx: the context to be written to
4277 * @ce_info: a description of the struct to be filled
4280 ice_read_word(u8 *src_ctx, u8 *dest_ctx, struct ice_ctx_ele *ce_info)
4282 u16 dest_word, mask;
4287 /* prepare the bits and mask */
4288 shift_width = ce_info->lsb % 8;
4289 mask = BIT(ce_info->width) - 1;
4291 /* shift to correct alignment */
4292 mask <<= shift_width;
4294 /* get the current bits from the src bit string */
4295 src = src_ctx + (ce_info->lsb / 8);
4297 ice_memcpy(&src_word, src, sizeof(src_word), ICE_DMA_TO_NONDMA);
4299 /* the data in the memory is stored as little endian so mask it
4302 src_word &= ~(CPU_TO_LE16(mask));
4304 /* get the data back into host order before shifting */
4305 dest_word = LE16_TO_CPU(src_word);
4307 dest_word >>= shift_width;
4309 /* get the address from the struct field */
4310 target = dest_ctx + ce_info->offset;
4312 /* put it back in the struct */
4313 ice_memcpy(target, &dest_word, sizeof(dest_word), ICE_NONDMA_TO_DMA);
4317 * ice_read_dword - read context dword into struct
4318 * @src_ctx: the context structure to read from
4319 * @dest_ctx: the context to be written to
4320 * @ce_info: a description of the struct to be filled
4323 ice_read_dword(u8 *src_ctx, u8 *dest_ctx, struct ice_ctx_ele *ce_info)
4325 u32 dest_dword, mask;
4330 /* prepare the bits and mask */
4331 shift_width = ce_info->lsb % 8;
4333 /* if the field width is exactly 32 on an x86 machine, then the shift
4334 * operation will not work because the SHL instructions count is masked
4335 * to 5 bits so the shift will do nothing
4337 if (ce_info->width < 32)
4338 mask = BIT(ce_info->width) - 1;
4342 /* shift to correct alignment */
4343 mask <<= shift_width;
4345 /* get the current bits from the src bit string */
4346 src = src_ctx + (ce_info->lsb / 8);
4348 ice_memcpy(&src_dword, src, sizeof(src_dword), ICE_DMA_TO_NONDMA);
4350 /* the data in the memory is stored as little endian so mask it
4353 src_dword &= ~(CPU_TO_LE32(mask));
4355 /* get the data back into host order before shifting */
4356 dest_dword = LE32_TO_CPU(src_dword);
4358 dest_dword >>= shift_width;
4360 /* get the address from the struct field */
4361 target = dest_ctx + ce_info->offset;
4363 /* put it back in the struct */
4364 ice_memcpy(target, &dest_dword, sizeof(dest_dword), ICE_NONDMA_TO_DMA);
4368 * ice_read_qword - read context qword into struct
4369 * @src_ctx: the context structure to read from
4370 * @dest_ctx: the context to be written to
4371 * @ce_info: a description of the struct to be filled
4374 ice_read_qword(u8 *src_ctx, u8 *dest_ctx, struct ice_ctx_ele *ce_info)
4376 u64 dest_qword, mask;
4381 /* prepare the bits and mask */
4382 shift_width = ce_info->lsb % 8;
4384 /* if the field width is exactly 64 on an x86 machine, then the shift
4385 * operation will not work because the SHL instructions count is masked
4386 * to 6 bits so the shift will do nothing
4388 if (ce_info->width < 64)
4389 mask = BIT_ULL(ce_info->width) - 1;
4393 /* shift to correct alignment */
4394 mask <<= shift_width;
4396 /* get the current bits from the src bit string */
4397 src = src_ctx + (ce_info->lsb / 8);
4399 ice_memcpy(&src_qword, src, sizeof(src_qword), ICE_DMA_TO_NONDMA);
4401 /* the data in the memory is stored as little endian so mask it
4404 src_qword &= ~(CPU_TO_LE64(mask));
4406 /* get the data back into host order before shifting */
4407 dest_qword = LE64_TO_CPU(src_qword);
4409 dest_qword >>= shift_width;
4411 /* get the address from the struct field */
4412 target = dest_ctx + ce_info->offset;
4414 /* put it back in the struct */
4415 ice_memcpy(target, &dest_qword, sizeof(dest_qword), ICE_NONDMA_TO_DMA);
4419 * ice_get_ctx - extract context bits from a packed structure
4420 * @src_ctx: pointer to a generic packed context structure
4421 * @dest_ctx: pointer to a generic non-packed context structure
4422 * @ce_info: a description of the structure to be read from
4425 ice_get_ctx(u8 *src_ctx, u8 *dest_ctx, struct ice_ctx_ele *ce_info)
4429 for (f = 0; ce_info[f].width; f++) {
4430 switch (ce_info[f].size_of) {
4432 ice_read_byte(src_ctx, dest_ctx, &ce_info[f]);
4435 ice_read_word(src_ctx, dest_ctx, &ce_info[f]);
4438 ice_read_dword(src_ctx, dest_ctx, &ce_info[f]);
4441 ice_read_qword(src_ctx, dest_ctx, &ce_info[f]);
4444 /* nothing to do, just keep going */
4453 * ice_get_lan_q_ctx - get the LAN queue context for the given VSI and TC
4454 * @hw: pointer to the HW struct
4455 * @vsi_handle: software VSI handle
4457 * @q_handle: software queue handle
4460 ice_get_lan_q_ctx(struct ice_hw *hw, u16 vsi_handle, u8 tc, u16 q_handle)
4462 struct ice_vsi_ctx *vsi;
4463 struct ice_q_ctx *q_ctx;
4465 vsi = ice_get_vsi_ctx(hw, vsi_handle);
4468 if (q_handle >= vsi->num_lan_q_entries[tc])
4470 if (!vsi->lan_q_ctx[tc])
4472 q_ctx = vsi->lan_q_ctx[tc];
4473 return &q_ctx[q_handle];
4478 * @pi: port information structure
4479 * @vsi_handle: software VSI handle
4481 * @q_handle: software queue handle
4482 * @num_qgrps: Number of added queue groups
4483 * @buf: list of queue groups to be added
4484 * @buf_size: size of buffer for indirect command
4485 * @cd: pointer to command details structure or NULL
4487 * This function adds one LAN queue
4490 ice_ena_vsi_txq(struct ice_port_info *pi, u16 vsi_handle, u8 tc, u16 q_handle,
4491 u8 num_qgrps, struct ice_aqc_add_tx_qgrp *buf, u16 buf_size,
4492 struct ice_sq_cd *cd)
4494 struct ice_aqc_txsched_elem_data node = { 0 };
4495 struct ice_sched_node *parent;
4496 struct ice_q_ctx *q_ctx;
4497 enum ice_status status;
4500 if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
4503 if (num_qgrps > 1 || buf->num_txqs > 1)
4504 return ICE_ERR_MAX_LIMIT;
4508 if (!ice_is_vsi_valid(hw, vsi_handle))
4509 return ICE_ERR_PARAM;
4511 ice_acquire_lock(&pi->sched_lock);
4513 q_ctx = ice_get_lan_q_ctx(hw, vsi_handle, tc, q_handle);
4515 ice_debug(hw, ICE_DBG_SCHED, "Enaq: invalid queue handle %d\n",
4517 status = ICE_ERR_PARAM;
4521 /* find a parent node */
4522 parent = ice_sched_get_free_qparent(pi, vsi_handle, tc,
4523 ICE_SCHED_NODE_OWNER_LAN);
4525 status = ICE_ERR_PARAM;
4529 buf->parent_teid = parent->info.node_teid;
4530 node.parent_teid = parent->info.node_teid;
4531 /* Mark that the values in the "generic" section as valid. The default
4532 * value in the "generic" section is zero. This means that :
4533 * - Scheduling mode is Bytes Per Second (BPS), indicated by Bit 0.
4534 * - 0 priority among siblings, indicated by Bit 1-3.
4535 * - WFQ, indicated by Bit 4.
4536 * - 0 Adjustment value is used in PSM credit update flow, indicated by
4538 * - Bit 7 is reserved.
4539 * Without setting the generic section as valid in valid_sections, the
4540 * Admin queue command will fail with error code ICE_AQ_RC_EINVAL.
4542 buf->txqs[0].info.valid_sections =
4543 ICE_AQC_ELEM_VALID_GENERIC | ICE_AQC_ELEM_VALID_CIR |
4544 ICE_AQC_ELEM_VALID_EIR;
4545 buf->txqs[0].info.generic = 0;
4546 buf->txqs[0].info.cir_bw.bw_profile_idx =
4547 CPU_TO_LE16(ICE_SCHED_DFLT_RL_PROF_ID);
4548 buf->txqs[0].info.cir_bw.bw_alloc =
4549 CPU_TO_LE16(ICE_SCHED_DFLT_BW_WT);
4550 buf->txqs[0].info.eir_bw.bw_profile_idx =
4551 CPU_TO_LE16(ICE_SCHED_DFLT_RL_PROF_ID);
4552 buf->txqs[0].info.eir_bw.bw_alloc =
4553 CPU_TO_LE16(ICE_SCHED_DFLT_BW_WT);
4555 /* add the LAN queue */
4556 status = ice_aq_add_lan_txq(hw, num_qgrps, buf, buf_size, cd);
4557 if (status != ICE_SUCCESS) {
4558 ice_debug(hw, ICE_DBG_SCHED, "enable queue %d failed %d\n",
4559 LE16_TO_CPU(buf->txqs[0].txq_id),
4560 hw->adminq.sq_last_status);
4564 node.node_teid = buf->txqs[0].q_teid;
4565 node.data.elem_type = ICE_AQC_ELEM_TYPE_LEAF;
4566 q_ctx->q_handle = q_handle;
4567 q_ctx->q_teid = LE32_TO_CPU(node.node_teid);
4569 /* add a leaf node into scheduler tree queue layer */
4570 status = ice_sched_add_node(pi, hw->num_tx_sched_layers - 1, &node);
4572 status = ice_sched_replay_q_bw(pi, q_ctx);
4575 ice_release_lock(&pi->sched_lock);
4581 * @pi: port information structure
4582 * @vsi_handle: software VSI handle
4584 * @num_queues: number of queues
4585 * @q_handles: pointer to software queue handle array
4586 * @q_ids: pointer to the q_id array
4587 * @q_teids: pointer to queue node teids
4588 * @rst_src: if called due to reset, specifies the reset source
4589 * @vmvf_num: the relative VM or VF number that is undergoing the reset
4590 * @cd: pointer to command details structure or NULL
4592 * This function removes queues and their corresponding nodes in SW DB
4595 ice_dis_vsi_txq(struct ice_port_info *pi, u16 vsi_handle, u8 tc, u8 num_queues,
4596 u16 *q_handles, u16 *q_ids, u32 *q_teids,
4597 enum ice_disq_rst_src rst_src, u16 vmvf_num,
4598 struct ice_sq_cd *cd)
4600 enum ice_status status = ICE_ERR_DOES_NOT_EXIST;
4601 struct ice_aqc_dis_txq_item *qg_list;
4602 struct ice_q_ctx *q_ctx;
4606 if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
4612 /* if queue is disabled already yet the disable queue command
4613 * has to be sent to complete the VF reset, then call
4614 * ice_aq_dis_lan_txq without any queue information
4617 return ice_aq_dis_lan_txq(hw, 0, NULL, 0, rst_src,
4622 buf_size = ice_struct_size(qg_list, q_id, 1);
4623 qg_list = (struct ice_aqc_dis_txq_item *)ice_malloc(hw, buf_size);
4625 return ICE_ERR_NO_MEMORY;
4627 ice_acquire_lock(&pi->sched_lock);
4629 for (i = 0; i < num_queues; i++) {
4630 struct ice_sched_node *node;
4632 node = ice_sched_find_node_by_teid(pi->root, q_teids[i]);
4635 q_ctx = ice_get_lan_q_ctx(hw, vsi_handle, tc, q_handles[i]);
4637 ice_debug(hw, ICE_DBG_SCHED, "invalid queue handle%d\n",
4641 if (q_ctx->q_handle != q_handles[i]) {
4642 ice_debug(hw, ICE_DBG_SCHED, "Err:handles %d %d\n",
4643 q_ctx->q_handle, q_handles[i]);
4646 qg_list->parent_teid = node->info.parent_teid;
4647 qg_list->num_qs = 1;
4648 qg_list->q_id[0] = CPU_TO_LE16(q_ids[i]);
4649 status = ice_aq_dis_lan_txq(hw, 1, qg_list, buf_size, rst_src,
4652 if (status != ICE_SUCCESS)
4654 ice_free_sched_node(pi, node);
4655 q_ctx->q_handle = ICE_INVAL_Q_HANDLE;
4657 ice_release_lock(&pi->sched_lock);
4658 ice_free(hw, qg_list);
4663 * ice_cfg_vsi_qs - configure the new/existing VSI queues
4664 * @pi: port information structure
4665 * @vsi_handle: software VSI handle
4666 * @tc_bitmap: TC bitmap
4667 * @maxqs: max queues array per TC
4668 * @owner: LAN or RDMA
4670 * This function adds/updates the VSI queues per TC.
4672 static enum ice_status
4673 ice_cfg_vsi_qs(struct ice_port_info *pi, u16 vsi_handle, u16 tc_bitmap,
4674 u16 *maxqs, u8 owner)
4676 enum ice_status status = ICE_SUCCESS;
4679 if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
4682 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
4683 return ICE_ERR_PARAM;
4685 ice_acquire_lock(&pi->sched_lock);
4687 ice_for_each_traffic_class(i) {
4688 /* configuration is possible only if TC node is present */
4689 if (!ice_sched_get_tc_node(pi, i))
4692 status = ice_sched_cfg_vsi(pi, vsi_handle, i, maxqs[i], owner,
4693 ice_is_tc_ena(tc_bitmap, i));
4698 ice_release_lock(&pi->sched_lock);
4703 * ice_cfg_vsi_lan - configure VSI LAN queues
4704 * @pi: port information structure
4705 * @vsi_handle: software VSI handle
4706 * @tc_bitmap: TC bitmap
4707 * @max_lanqs: max LAN queues array per TC
4709 * This function adds/updates the VSI LAN queues per TC.
4712 ice_cfg_vsi_lan(struct ice_port_info *pi, u16 vsi_handle, u16 tc_bitmap,
4715 return ice_cfg_vsi_qs(pi, vsi_handle, tc_bitmap, max_lanqs,
4716 ICE_SCHED_NODE_OWNER_LAN);
4720 * ice_is_main_vsi - checks whether the VSI is main VSI
4721 * @hw: pointer to the HW struct
4722 * @vsi_handle: VSI handle
4724 * Checks whether the VSI is the main VSI (the first PF VSI created on
4727 static bool ice_is_main_vsi(struct ice_hw *hw, u16 vsi_handle)
4729 return vsi_handle == ICE_MAIN_VSI_HANDLE && hw->vsi_ctx[vsi_handle];
4733 * ice_replay_pre_init - replay pre initialization
4734 * @hw: pointer to the HW struct
4735 * @sw: pointer to switch info struct for which function initializes filters
4737 * Initializes required config data for VSI, FD, ACL, and RSS before replay.
4739 static enum ice_status
4740 ice_replay_pre_init(struct ice_hw *hw, struct ice_switch_info *sw)
4742 enum ice_status status;
4745 /* Delete old entries from replay filter list head if there is any */
4746 ice_rm_sw_replay_rule_info(hw, sw);
4747 /* In start of replay, move entries into replay_rules list, it
4748 * will allow adding rules entries back to filt_rules list,
4749 * which is operational list.
4751 for (i = 0; i < ICE_MAX_NUM_RECIPES; i++)
4752 LIST_REPLACE_INIT(&sw->recp_list[i].filt_rules,
4753 &sw->recp_list[i].filt_replay_rules);
4754 ice_sched_replay_agg_vsi_preinit(hw);
4756 status = ice_sched_replay_root_node_bw(hw->port_info);
4760 return ice_sched_replay_tc_node_bw(hw->port_info);
4764 * ice_replay_vsi - replay VSI configuration
4765 * @hw: pointer to the HW struct
4766 * @vsi_handle: driver VSI handle
4768 * Restore all VSI configuration after reset. It is required to call this
4769 * function with main VSI first.
4771 enum ice_status ice_replay_vsi(struct ice_hw *hw, u16 vsi_handle)
4773 struct ice_switch_info *sw = hw->switch_info;
4774 struct ice_port_info *pi = hw->port_info;
4775 enum ice_status status;
4777 if (!ice_is_vsi_valid(hw, vsi_handle))
4778 return ICE_ERR_PARAM;
4780 /* Replay pre-initialization if there is any */
4781 if (ice_is_main_vsi(hw, vsi_handle)) {
4782 status = ice_replay_pre_init(hw, sw);
4786 /* Replay per VSI all RSS configurations */
4787 status = ice_replay_rss_cfg(hw, vsi_handle);
4790 /* Replay per VSI all filters */
4791 status = ice_replay_vsi_all_fltr(hw, pi, vsi_handle);
4793 status = ice_replay_vsi_agg(hw, vsi_handle);
4798 * ice_replay_post - post replay configuration cleanup
4799 * @hw: pointer to the HW struct
4801 * Post replay cleanup.
4803 void ice_replay_post(struct ice_hw *hw)
4805 /* Delete old entries from replay filter list head */
4806 ice_rm_all_sw_replay_rule_info(hw);
4807 ice_sched_replay_agg(hw);
4811 * ice_stat_update40 - read 40 bit stat from the chip and update stat values
4812 * @hw: ptr to the hardware info
4813 * @reg: offset of 64 bit HW register to read from
4814 * @prev_stat_loaded: bool to specify if previous stats are loaded
4815 * @prev_stat: ptr to previous loaded stat value
4816 * @cur_stat: ptr to current stat value
4819 ice_stat_update40(struct ice_hw *hw, u32 reg, bool prev_stat_loaded,
4820 u64 *prev_stat, u64 *cur_stat)
4822 u64 new_data = rd64(hw, reg) & (BIT_ULL(40) - 1);
4824 /* device stats are not reset at PFR, they likely will not be zeroed
4825 * when the driver starts. Thus, save the value from the first read
4826 * without adding to the statistic value so that we report stats which
4827 * count up from zero.
4829 if (!prev_stat_loaded) {
4830 *prev_stat = new_data;
4834 /* Calculate the difference between the new and old values, and then
4835 * add it to the software stat value.
4837 if (new_data >= *prev_stat)
4838 *cur_stat += new_data - *prev_stat;
4840 /* to manage the potential roll-over */
4841 *cur_stat += (new_data + BIT_ULL(40)) - *prev_stat;
4843 /* Update the previously stored value to prepare for next read */
4844 *prev_stat = new_data;
4848 * ice_stat_update32 - read 32 bit stat from the chip and update stat values
4849 * @hw: ptr to the hardware info
4850 * @reg: offset of HW register to read from
4851 * @prev_stat_loaded: bool to specify if previous stats are loaded
4852 * @prev_stat: ptr to previous loaded stat value
4853 * @cur_stat: ptr to current stat value
4856 ice_stat_update32(struct ice_hw *hw, u32 reg, bool prev_stat_loaded,
4857 u64 *prev_stat, u64 *cur_stat)
4861 new_data = rd32(hw, reg);
4863 /* device stats are not reset at PFR, they likely will not be zeroed
4864 * when the driver starts. Thus, save the value from the first read
4865 * without adding to the statistic value so that we report stats which
4866 * count up from zero.
4868 if (!prev_stat_loaded) {
4869 *prev_stat = new_data;
4873 /* Calculate the difference between the new and old values, and then
4874 * add it to the software stat value.
4876 if (new_data >= *prev_stat)
4877 *cur_stat += new_data - *prev_stat;
4879 /* to manage the potential roll-over */
4880 *cur_stat += (new_data + BIT_ULL(32)) - *prev_stat;
4882 /* Update the previously stored value to prepare for next read */
4883 *prev_stat = new_data;
4887 * ice_stat_update_repc - read GLV_REPC stats from chip and update stat values
4888 * @hw: ptr to the hardware info
4889 * @vsi_handle: VSI handle
4890 * @prev_stat_loaded: bool to specify if the previous stat values are loaded
4891 * @cur_stats: ptr to current stats structure
4893 * The GLV_REPC statistic register actually tracks two 16bit statistics, and
4894 * thus cannot be read using the normal ice_stat_update32 function.
4896 * Read the GLV_REPC register associated with the given VSI, and update the
4897 * rx_no_desc and rx_error values in the ice_eth_stats structure.
4899 * Because the statistics in GLV_REPC stick at 0xFFFF, the register must be
4900 * cleared each time it's read.
4902 * Note that the GLV_RDPC register also counts the causes that would trigger
4903 * GLV_REPC. However, it does not give the finer grained detail about why the
4904 * packets are being dropped. The GLV_REPC values can be used to distinguish
4905 * whether Rx packets are dropped due to errors or due to no available
4909 ice_stat_update_repc(struct ice_hw *hw, u16 vsi_handle, bool prev_stat_loaded,
4910 struct ice_eth_stats *cur_stats)
4912 u16 vsi_num, no_desc, error_cnt;
4915 if (!ice_is_vsi_valid(hw, vsi_handle))
4918 vsi_num = ice_get_hw_vsi_num(hw, vsi_handle);
4920 /* If we haven't loaded stats yet, just clear the current value */
4921 if (!prev_stat_loaded) {
4922 wr32(hw, GLV_REPC(vsi_num), 0);
4926 repc = rd32(hw, GLV_REPC(vsi_num));
4927 no_desc = (repc & GLV_REPC_NO_DESC_CNT_M) >> GLV_REPC_NO_DESC_CNT_S;
4928 error_cnt = (repc & GLV_REPC_ERROR_CNT_M) >> GLV_REPC_ERROR_CNT_S;
4930 /* Clear the count by writing to the stats register */
4931 wr32(hw, GLV_REPC(vsi_num), 0);
4933 cur_stats->rx_no_desc += no_desc;
4934 cur_stats->rx_errors += error_cnt;
4938 * ice_sched_query_elem - query element information from HW
4939 * @hw: pointer to the HW struct
4940 * @node_teid: node TEID to be queried
4941 * @buf: buffer to element information
4943 * This function queries HW element information
4946 ice_sched_query_elem(struct ice_hw *hw, u32 node_teid,
4947 struct ice_aqc_txsched_elem_data *buf)
4949 u16 buf_size, num_elem_ret = 0;
4950 enum ice_status status;
4952 buf_size = sizeof(*buf);
4953 ice_memset(buf, 0, buf_size, ICE_NONDMA_MEM);
4954 buf->node_teid = CPU_TO_LE32(node_teid);
4955 status = ice_aq_query_sched_elems(hw, 1, buf, buf_size, &num_elem_ret,
4957 if (status != ICE_SUCCESS || num_elem_ret != 1)
4958 ice_debug(hw, ICE_DBG_SCHED, "query element failed\n");
4963 * ice_get_fw_mode - returns FW mode
4964 * @hw: pointer to the HW struct
4966 enum ice_fw_modes ice_get_fw_mode(struct ice_hw *hw)
4968 #define ICE_FW_MODE_DBG_M BIT(0)
4969 #define ICE_FW_MODE_REC_M BIT(1)
4970 #define ICE_FW_MODE_ROLLBACK_M BIT(2)
4973 /* check the current FW mode */
4974 fw_mode = rd32(hw, GL_MNG_FWSM) & GL_MNG_FWSM_FW_MODES_M;
4976 if (fw_mode & ICE_FW_MODE_DBG_M)
4977 return ICE_FW_MODE_DBG;
4978 else if (fw_mode & ICE_FW_MODE_REC_M)
4979 return ICE_FW_MODE_REC;
4980 else if (fw_mode & ICE_FW_MODE_ROLLBACK_M)
4981 return ICE_FW_MODE_ROLLBACK;
4983 return ICE_FW_MODE_NORMAL;
4988 * @hw: pointer to the hw struct
4989 * @topo_addr: topology address for a device to communicate with
4990 * @bus_addr: 7-bit I2C bus address
4991 * @addr: I2C memory address (I2C offset) with up to 16 bits
4992 * @params: I2C parameters: bit [7] - Repeated start, bits [6:5] data offset size,
4993 * bit [4] - I2C address type, bits [3:0] - data size to read (0-16 bytes)
4994 * @data: pointer to data (0 to 16 bytes) to be read from the I2C device
4995 * @cd: pointer to command details structure or NULL
5000 ice_aq_read_i2c(struct ice_hw *hw, struct ice_aqc_link_topo_addr topo_addr,
5001 u16 bus_addr, __le16 addr, u8 params, u8 *data,
5002 struct ice_sq_cd *cd)
5004 struct ice_aq_desc desc = { 0 };
5005 struct ice_aqc_i2c *cmd;
5006 enum ice_status status;
5009 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_read_i2c);
5010 cmd = &desc.params.read_write_i2c;
5013 return ICE_ERR_PARAM;
5015 data_size = (params & ICE_AQC_I2C_DATA_SIZE_M) >> ICE_AQC_I2C_DATA_SIZE_S;
5017 cmd->i2c_bus_addr = CPU_TO_LE16(bus_addr);
5018 cmd->topo_addr = topo_addr;
5019 cmd->i2c_params = params;
5020 cmd->i2c_addr = addr;
5022 status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
5024 struct ice_aqc_read_i2c_resp *resp;
5027 resp = &desc.params.read_i2c_resp;
5028 for (i = 0; i < data_size; i++) {
5029 *data = resp->i2c_data[i];
5039 * @hw: pointer to the hw struct
5040 * @topo_addr: topology address for a device to communicate with
5041 * @bus_addr: 7-bit I2C bus address
5042 * @addr: I2C memory address (I2C offset) with up to 16 bits
5043 * @params: I2C parameters: bit [4] - I2C address type, bits [3:0] - data size to write (0-7 bytes)
5044 * @data: pointer to data (0 to 4 bytes) to be written to the I2C device
5045 * @cd: pointer to command details structure or NULL
5047 * Write I2C (0x06E3)
5050 ice_aq_write_i2c(struct ice_hw *hw, struct ice_aqc_link_topo_addr topo_addr,
5051 u16 bus_addr, __le16 addr, u8 params, u8 *data,
5052 struct ice_sq_cd *cd)
5054 struct ice_aq_desc desc = { 0 };
5055 struct ice_aqc_i2c *cmd;
5058 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_write_i2c);
5059 cmd = &desc.params.read_write_i2c;
5061 data_size = (params & ICE_AQC_I2C_DATA_SIZE_M) >> ICE_AQC_I2C_DATA_SIZE_S;
5063 /* data_size limited to 4 */
5065 return ICE_ERR_PARAM;
5067 cmd->i2c_bus_addr = CPU_TO_LE16(bus_addr);
5068 cmd->topo_addr = topo_addr;
5069 cmd->i2c_params = params;
5070 cmd->i2c_addr = addr;
5072 for (i = 0; i < data_size; i++) {
5073 cmd->i2c_data[i] = *data;
5077 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
5082 * @hw: pointer to the hw struct
5083 * @gpio_ctrl_handle: GPIO controller node handle
5084 * @pin_idx: IO Number of the GPIO that needs to be set
5085 * @value: SW provide IO value to set in the LSB
5086 * @cd: pointer to command details structure or NULL
5088 * Sends 0x06EC AQ command to set the GPIO pin state that's part of the topology
5091 ice_aq_set_gpio(struct ice_hw *hw, u16 gpio_ctrl_handle, u8 pin_idx, bool value,
5092 struct ice_sq_cd *cd)
5094 struct ice_aqc_gpio *cmd;
5095 struct ice_aq_desc desc;
5097 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_gpio);
5098 cmd = &desc.params.read_write_gpio;
5099 cmd->gpio_ctrl_handle = gpio_ctrl_handle;
5100 cmd->gpio_num = pin_idx;
5101 cmd->gpio_val = value ? 1 : 0;
5103 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
5108 * @hw: pointer to the hw struct
5109 * @gpio_ctrl_handle: GPIO controller node handle
5110 * @pin_idx: IO Number of the GPIO that needs to be set
5111 * @value: IO value read
5112 * @cd: pointer to command details structure or NULL
5114 * Sends 0x06ED AQ command to get the value of a GPIO signal which is part of
5118 ice_aq_get_gpio(struct ice_hw *hw, u16 gpio_ctrl_handle, u8 pin_idx,
5119 bool *value, struct ice_sq_cd *cd)
5121 struct ice_aqc_gpio *cmd;
5122 struct ice_aq_desc desc;
5123 enum ice_status status;
5125 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_gpio);
5126 cmd = &desc.params.read_write_gpio;
5127 cmd->gpio_ctrl_handle = gpio_ctrl_handle;
5128 cmd->gpio_num = pin_idx;
5130 status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
5134 *value = !!cmd->gpio_val;
5139 * ice_fw_supports_link_override
5140 * @hw: pointer to the hardware structure
5142 * Checks if the firmware supports link override
5144 bool ice_fw_supports_link_override(struct ice_hw *hw)
5146 if (hw->api_maj_ver == ICE_FW_API_LINK_OVERRIDE_MAJ) {
5147 if (hw->api_min_ver > ICE_FW_API_LINK_OVERRIDE_MIN)
5149 if (hw->api_min_ver == ICE_FW_API_LINK_OVERRIDE_MIN &&
5150 hw->api_patch >= ICE_FW_API_LINK_OVERRIDE_PATCH)
5152 } else if (hw->api_maj_ver > ICE_FW_API_LINK_OVERRIDE_MAJ) {
5160 * ice_get_link_default_override
5161 * @ldo: pointer to the link default override struct
5162 * @pi: pointer to the port info struct
5164 * Gets the link default override for a port
5167 ice_get_link_default_override(struct ice_link_default_override_tlv *ldo,
5168 struct ice_port_info *pi)
5170 u16 i, tlv, tlv_len, tlv_start, buf, offset;
5171 struct ice_hw *hw = pi->hw;
5172 enum ice_status status;
5174 status = ice_get_pfa_module_tlv(hw, &tlv, &tlv_len,
5175 ICE_SR_LINK_DEFAULT_OVERRIDE_PTR);
5177 ice_debug(hw, ICE_DBG_INIT, "Failed to read link override TLV.\n");
5181 /* Each port has its own config; calculate for our port */
5182 tlv_start = tlv + pi->lport * ICE_SR_PFA_LINK_OVERRIDE_WORDS +
5183 ICE_SR_PFA_LINK_OVERRIDE_OFFSET;
5185 /* link options first */
5186 status = ice_read_sr_word(hw, tlv_start, &buf);
5188 ice_debug(hw, ICE_DBG_INIT, "Failed to read override link options.\n");
5191 ldo->options = buf & ICE_LINK_OVERRIDE_OPT_M;
5192 ldo->phy_config = (buf & ICE_LINK_OVERRIDE_PHY_CFG_M) >>
5193 ICE_LINK_OVERRIDE_PHY_CFG_S;
5195 /* link PHY config */
5196 offset = tlv_start + ICE_SR_PFA_LINK_OVERRIDE_FEC_OFFSET;
5197 status = ice_read_sr_word(hw, offset, &buf);
5199 ice_debug(hw, ICE_DBG_INIT, "Failed to read override phy config.\n");
5202 ldo->fec_options = buf & ICE_LINK_OVERRIDE_FEC_OPT_M;
5205 offset = tlv_start + ICE_SR_PFA_LINK_OVERRIDE_PHY_OFFSET;
5206 for (i = 0; i < ICE_SR_PFA_LINK_OVERRIDE_PHY_WORDS; i++) {
5207 status = ice_read_sr_word(hw, (offset + i), &buf);
5209 ice_debug(hw, ICE_DBG_INIT, "Failed to read override link options.\n");
5212 /* shift 16 bits at a time to fill 64 bits */
5213 ldo->phy_type_low |= ((u64)buf << (i * 16));
5216 /* PHY types high */
5217 offset = tlv_start + ICE_SR_PFA_LINK_OVERRIDE_PHY_OFFSET +
5218 ICE_SR_PFA_LINK_OVERRIDE_PHY_WORDS;
5219 for (i = 0; i < ICE_SR_PFA_LINK_OVERRIDE_PHY_WORDS; i++) {
5220 status = ice_read_sr_word(hw, (offset + i), &buf);
5222 ice_debug(hw, ICE_DBG_INIT, "Failed to read override link options.\n");
5225 /* shift 16 bits at a time to fill 64 bits */
5226 ldo->phy_type_high |= ((u64)buf << (i * 16));
5233 * ice_is_phy_caps_an_enabled - check if PHY capabilities autoneg is enabled
5234 * @caps: get PHY capability data
5236 bool ice_is_phy_caps_an_enabled(struct ice_aqc_get_phy_caps_data *caps)
5238 if (caps->caps & ICE_AQC_PHY_AN_MODE ||
5239 caps->low_power_ctrl_an & (ICE_AQC_PHY_AN_EN_CLAUSE28 |
5240 ICE_AQC_PHY_AN_EN_CLAUSE73 |
5241 ICE_AQC_PHY_AN_EN_CLAUSE37))
5248 * ice_aq_set_lldp_mib - Set the LLDP MIB
5249 * @hw: pointer to the HW struct
5250 * @mib_type: Local, Remote or both Local and Remote MIBs
5251 * @buf: pointer to the caller-supplied buffer to store the MIB block
5252 * @buf_size: size of the buffer (in bytes)
5253 * @cd: pointer to command details structure or NULL
5255 * Set the LLDP MIB. (0x0A08)
5258 ice_aq_set_lldp_mib(struct ice_hw *hw, u8 mib_type, void *buf, u16 buf_size,
5259 struct ice_sq_cd *cd)
5261 struct ice_aqc_lldp_set_local_mib *cmd;
5262 struct ice_aq_desc desc;
5264 cmd = &desc.params.lldp_set_mib;
5266 if (buf_size == 0 || !buf)
5267 return ICE_ERR_PARAM;
5269 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_lldp_set_local_mib);
5271 desc.flags |= CPU_TO_LE16((u16)ICE_AQ_FLAG_RD);
5272 desc.datalen = CPU_TO_LE16(buf_size);
5274 cmd->type = mib_type;
5275 cmd->length = CPU_TO_LE16(buf_size);
5277 return ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
5281 * ice_fw_supports_lldp_fltr_ctrl - check NVM version supports lldp_fltr_ctrl
5282 * @hw: pointer to HW struct
5284 bool ice_fw_supports_lldp_fltr_ctrl(struct ice_hw *hw)
5286 if (hw->mac_type != ICE_MAC_E810)
5289 if (hw->api_maj_ver == ICE_FW_API_LLDP_FLTR_MAJ) {
5290 if (hw->api_min_ver > ICE_FW_API_LLDP_FLTR_MIN)
5292 if (hw->api_min_ver == ICE_FW_API_LLDP_FLTR_MIN &&
5293 hw->api_patch >= ICE_FW_API_LLDP_FLTR_PATCH)
5295 } else if (hw->api_maj_ver > ICE_FW_API_LLDP_FLTR_MAJ) {
5302 * ice_lldp_fltr_add_remove - add or remove a LLDP Rx switch filter
5303 * @hw: pointer to HW struct
5304 * @vsi_num: absolute HW index for VSI
5305 * @add: boolean for if adding or removing a filter
5308 ice_lldp_fltr_add_remove(struct ice_hw *hw, u16 vsi_num, bool add)
5310 struct ice_aqc_lldp_filter_ctrl *cmd;
5311 struct ice_aq_desc desc;
5313 cmd = &desc.params.lldp_filter_ctrl;
5315 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_lldp_filter_ctrl);
5318 cmd->cmd_flags = ICE_AQC_LLDP_FILTER_ACTION_ADD;
5320 cmd->cmd_flags = ICE_AQC_LLDP_FILTER_ACTION_DELETE;
5322 cmd->vsi_num = CPU_TO_LE16(vsi_num);
5324 return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
5328 * ice_fw_supports_report_dflt_cfg
5329 * @hw: pointer to the hardware structure
5331 * Checks if the firmware supports report default configuration
5333 bool ice_fw_supports_report_dflt_cfg(struct ice_hw *hw)
5335 if (hw->api_maj_ver == ICE_FW_API_REPORT_DFLT_CFG_MAJ) {
5336 if (hw->api_min_ver > ICE_FW_API_REPORT_DFLT_CFG_MIN)
5338 if (hw->api_min_ver == ICE_FW_API_REPORT_DFLT_CFG_MIN &&
5339 hw->api_patch >= ICE_FW_API_REPORT_DFLT_CFG_PATCH)
5341 } else if (hw->api_maj_ver > ICE_FW_API_REPORT_DFLT_CFG_MAJ) {