1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2020 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 hw->mac_type = ICE_MAC_GENERIC;
49 hw->mac_type = ICE_MAC_UNKNOWN;
53 ice_debug(hw, ICE_DBG_INIT, "mac_type: %d\n", hw->mac_type);
58 * ice_clear_pf_cfg - Clear PF configuration
59 * @hw: pointer to the hardware structure
61 * Clears any existing PF configuration (VSIs, VSI lists, switch rules, port
62 * configuration, flow director filters, etc.).
64 enum ice_status ice_clear_pf_cfg(struct ice_hw *hw)
66 struct ice_aq_desc desc;
68 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_clear_pf_cfg);
70 return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
74 * ice_aq_manage_mac_read - manage MAC address read command
75 * @hw: pointer to the HW struct
76 * @buf: a virtual buffer to hold the manage MAC read response
77 * @buf_size: Size of the virtual buffer
78 * @cd: pointer to command details structure or NULL
80 * This function is used to return per PF station MAC address (0x0107).
81 * NOTE: Upon successful completion of this command, MAC address information
82 * is returned in user specified buffer. Please interpret user specified
83 * buffer as "manage_mac_read" response.
84 * Response such as various MAC addresses are stored in HW struct (port.mac)
85 * ice_aq_discover_caps is expected to be called before this function is called.
87 static enum ice_status
88 ice_aq_manage_mac_read(struct ice_hw *hw, void *buf, u16 buf_size,
91 struct ice_aqc_manage_mac_read_resp *resp;
92 struct ice_aqc_manage_mac_read *cmd;
93 struct ice_aq_desc desc;
94 enum ice_status status;
98 cmd = &desc.params.mac_read;
100 if (buf_size < sizeof(*resp))
101 return ICE_ERR_BUF_TOO_SHORT;
103 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_manage_mac_read);
105 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
109 resp = (struct ice_aqc_manage_mac_read_resp *)buf;
110 flags = LE16_TO_CPU(cmd->flags) & ICE_AQC_MAN_MAC_READ_M;
112 if (!(flags & ICE_AQC_MAN_MAC_LAN_ADDR_VALID)) {
113 ice_debug(hw, ICE_DBG_LAN, "got invalid MAC address\n");
117 /* A single port can report up to two (LAN and WoL) addresses */
118 for (i = 0; i < cmd->num_addr; i++)
119 if (resp[i].addr_type == ICE_AQC_MAN_MAC_ADDR_TYPE_LAN) {
120 ice_memcpy(hw->port_info->mac.lan_addr,
121 resp[i].mac_addr, ETH_ALEN,
123 ice_memcpy(hw->port_info->mac.perm_addr,
125 ETH_ALEN, ICE_DMA_TO_NONDMA);
132 * ice_aq_get_phy_caps - returns PHY capabilities
133 * @pi: port information structure
134 * @qual_mods: report qualified modules
135 * @report_mode: report mode capabilities
136 * @pcaps: structure for PHY capabilities to be filled
137 * @cd: pointer to command details structure or NULL
139 * Returns the various PHY capabilities supported on the Port (0x0600)
142 ice_aq_get_phy_caps(struct ice_port_info *pi, bool qual_mods, u8 report_mode,
143 struct ice_aqc_get_phy_caps_data *pcaps,
144 struct ice_sq_cd *cd)
146 struct ice_aqc_get_phy_caps *cmd;
147 u16 pcaps_size = sizeof(*pcaps);
148 struct ice_aq_desc desc;
149 enum ice_status status;
151 cmd = &desc.params.get_phy;
153 if (!pcaps || (report_mode & ~ICE_AQC_REPORT_MODE_M) || !pi)
154 return ICE_ERR_PARAM;
156 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_phy_caps);
159 cmd->param0 |= CPU_TO_LE16(ICE_AQC_GET_PHY_RQM);
161 cmd->param0 |= CPU_TO_LE16(report_mode);
162 status = ice_aq_send_cmd(pi->hw, &desc, pcaps, pcaps_size, cd);
164 if (status == ICE_SUCCESS && report_mode == ICE_AQC_REPORT_TOPO_CAP) {
165 pi->phy.phy_type_low = LE64_TO_CPU(pcaps->phy_type_low);
166 pi->phy.phy_type_high = LE64_TO_CPU(pcaps->phy_type_high);
173 * ice_aq_get_link_topo_handle - get link topology node return status
174 * @pi: port information structure
175 * @node_type: requested node type
176 * @cd: pointer to command details structure or NULL
178 * Get link topology node return status for specified node type (0x06E0)
180 * Node type cage can be used to determine if cage is present. If AQC
181 * returns error (ENOENT), then no cage present. If no cage present, then
182 * connection type is backplane or BASE-T.
184 static enum ice_status
185 ice_aq_get_link_topo_handle(struct ice_port_info *pi, u8 node_type,
186 struct ice_sq_cd *cd)
188 struct ice_aqc_get_link_topo *cmd;
189 struct ice_aq_desc desc;
191 cmd = &desc.params.get_link_topo;
193 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_link_topo);
195 cmd->addr.node_type_ctx = (ICE_AQC_LINK_TOPO_NODE_CTX_PORT <<
196 ICE_AQC_LINK_TOPO_NODE_CTX_S);
199 cmd->addr.node_type_ctx |= (ICE_AQC_LINK_TOPO_NODE_TYPE_M & node_type);
201 return ice_aq_send_cmd(pi->hw, &desc, NULL, 0, cd);
205 * ice_is_media_cage_present
206 * @pi: port information structure
208 * Returns true if media cage is present, else false. If no cage, then
209 * media type is backplane or BASE-T.
211 static bool ice_is_media_cage_present(struct ice_port_info *pi)
213 /* Node type cage can be used to determine if cage is present. If AQC
214 * returns error (ENOENT), then no cage present. If no cage present then
215 * connection type is backplane or BASE-T.
217 return !ice_aq_get_link_topo_handle(pi,
218 ICE_AQC_LINK_TOPO_NODE_TYPE_CAGE,
223 * ice_get_media_type - Gets media type
224 * @pi: port information structure
226 static enum ice_media_type ice_get_media_type(struct ice_port_info *pi)
228 struct ice_link_status *hw_link_info;
231 return ICE_MEDIA_UNKNOWN;
233 hw_link_info = &pi->phy.link_info;
234 if (hw_link_info->phy_type_low && hw_link_info->phy_type_high)
235 /* If more than one media type is selected, report unknown */
236 return ICE_MEDIA_UNKNOWN;
238 if (hw_link_info->phy_type_low) {
239 switch (hw_link_info->phy_type_low) {
240 case ICE_PHY_TYPE_LOW_1000BASE_SX:
241 case ICE_PHY_TYPE_LOW_1000BASE_LX:
242 case ICE_PHY_TYPE_LOW_10GBASE_SR:
243 case ICE_PHY_TYPE_LOW_10GBASE_LR:
244 case ICE_PHY_TYPE_LOW_10G_SFI_C2C:
245 case ICE_PHY_TYPE_LOW_25GBASE_SR:
246 case ICE_PHY_TYPE_LOW_25GBASE_LR:
247 case ICE_PHY_TYPE_LOW_40GBASE_SR4:
248 case ICE_PHY_TYPE_LOW_40GBASE_LR4:
249 case ICE_PHY_TYPE_LOW_50GBASE_SR2:
250 case ICE_PHY_TYPE_LOW_50GBASE_LR2:
251 case ICE_PHY_TYPE_LOW_50GBASE_SR:
252 case ICE_PHY_TYPE_LOW_50GBASE_FR:
253 case ICE_PHY_TYPE_LOW_50GBASE_LR:
254 case ICE_PHY_TYPE_LOW_100GBASE_SR4:
255 case ICE_PHY_TYPE_LOW_100GBASE_LR4:
256 case ICE_PHY_TYPE_LOW_100GBASE_SR2:
257 case ICE_PHY_TYPE_LOW_100GBASE_DR:
258 return ICE_MEDIA_FIBER;
259 case ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC:
260 case ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC:
261 case ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC:
262 case ICE_PHY_TYPE_LOW_50G_LAUI2_AOC_ACC:
263 case ICE_PHY_TYPE_LOW_50G_AUI2_AOC_ACC:
264 case ICE_PHY_TYPE_LOW_50G_AUI1_AOC_ACC:
265 case ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC:
266 case ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC:
267 return ICE_MEDIA_FIBER;
268 case ICE_PHY_TYPE_LOW_100BASE_TX:
269 case ICE_PHY_TYPE_LOW_1000BASE_T:
270 case ICE_PHY_TYPE_LOW_2500BASE_T:
271 case ICE_PHY_TYPE_LOW_5GBASE_T:
272 case ICE_PHY_TYPE_LOW_10GBASE_T:
273 case ICE_PHY_TYPE_LOW_25GBASE_T:
274 return ICE_MEDIA_BASET;
275 case ICE_PHY_TYPE_LOW_10G_SFI_DA:
276 case ICE_PHY_TYPE_LOW_25GBASE_CR:
277 case ICE_PHY_TYPE_LOW_25GBASE_CR_S:
278 case ICE_PHY_TYPE_LOW_25GBASE_CR1:
279 case ICE_PHY_TYPE_LOW_40GBASE_CR4:
280 case ICE_PHY_TYPE_LOW_50GBASE_CR2:
281 case ICE_PHY_TYPE_LOW_50GBASE_CP:
282 case ICE_PHY_TYPE_LOW_100GBASE_CR4:
283 case ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4:
284 case ICE_PHY_TYPE_LOW_100GBASE_CP2:
286 case ICE_PHY_TYPE_LOW_25G_AUI_C2C:
287 case ICE_PHY_TYPE_LOW_40G_XLAUI:
288 case ICE_PHY_TYPE_LOW_50G_LAUI2:
289 case ICE_PHY_TYPE_LOW_50G_AUI2:
290 case ICE_PHY_TYPE_LOW_50G_AUI1:
291 case ICE_PHY_TYPE_LOW_100G_AUI4:
292 case ICE_PHY_TYPE_LOW_100G_CAUI4:
293 if (ice_is_media_cage_present(pi))
294 return ICE_MEDIA_AUI;
296 case ICE_PHY_TYPE_LOW_1000BASE_KX:
297 case ICE_PHY_TYPE_LOW_2500BASE_KX:
298 case ICE_PHY_TYPE_LOW_2500BASE_X:
299 case ICE_PHY_TYPE_LOW_5GBASE_KR:
300 case ICE_PHY_TYPE_LOW_10GBASE_KR_CR1:
301 case ICE_PHY_TYPE_LOW_25GBASE_KR:
302 case ICE_PHY_TYPE_LOW_25GBASE_KR1:
303 case ICE_PHY_TYPE_LOW_25GBASE_KR_S:
304 case ICE_PHY_TYPE_LOW_40GBASE_KR4:
305 case ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4:
306 case ICE_PHY_TYPE_LOW_50GBASE_KR2:
307 case ICE_PHY_TYPE_LOW_100GBASE_KR4:
308 case ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4:
309 return ICE_MEDIA_BACKPLANE;
312 switch (hw_link_info->phy_type_high) {
313 case ICE_PHY_TYPE_HIGH_100G_AUI2:
314 case ICE_PHY_TYPE_HIGH_100G_CAUI2:
315 if (ice_is_media_cage_present(pi))
316 return ICE_MEDIA_AUI;
318 case ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4:
319 return ICE_MEDIA_BACKPLANE;
320 case ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC:
321 case ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC:
322 return ICE_MEDIA_FIBER;
325 return ICE_MEDIA_UNKNOWN;
329 * ice_aq_get_link_info
330 * @pi: port information structure
331 * @ena_lse: enable/disable LinkStatusEvent reporting
332 * @link: pointer to link status structure - optional
333 * @cd: pointer to command details structure or NULL
335 * Get Link Status (0x607). Returns the link status of the adapter.
338 ice_aq_get_link_info(struct ice_port_info *pi, bool ena_lse,
339 struct ice_link_status *link, struct ice_sq_cd *cd)
341 struct ice_aqc_get_link_status_data link_data = { 0 };
342 struct ice_aqc_get_link_status *resp;
343 struct ice_link_status *li_old, *li;
344 enum ice_media_type *hw_media_type;
345 struct ice_fc_info *hw_fc_info;
346 bool tx_pause, rx_pause;
347 struct ice_aq_desc desc;
348 enum ice_status status;
353 return ICE_ERR_PARAM;
355 li_old = &pi->phy.link_info_old;
356 hw_media_type = &pi->phy.media_type;
357 li = &pi->phy.link_info;
358 hw_fc_info = &pi->fc;
360 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_link_status);
361 cmd_flags = (ena_lse) ? ICE_AQ_LSE_ENA : ICE_AQ_LSE_DIS;
362 resp = &desc.params.get_link_status;
363 resp->cmd_flags = CPU_TO_LE16(cmd_flags);
364 resp->lport_num = pi->lport;
366 status = ice_aq_send_cmd(hw, &desc, &link_data, sizeof(link_data), cd);
368 if (status != ICE_SUCCESS)
371 /* save off old link status information */
374 /* update current link status information */
375 li->link_speed = LE16_TO_CPU(link_data.link_speed);
376 li->phy_type_low = LE64_TO_CPU(link_data.phy_type_low);
377 li->phy_type_high = LE64_TO_CPU(link_data.phy_type_high);
378 *hw_media_type = ice_get_media_type(pi);
379 li->link_info = link_data.link_info;
380 li->an_info = link_data.an_info;
381 li->ext_info = link_data.ext_info;
382 li->max_frame_size = LE16_TO_CPU(link_data.max_frame_size);
383 li->fec_info = link_data.cfg & ICE_AQ_FEC_MASK;
384 li->topo_media_conflict = link_data.topo_media_conflict;
385 li->pacing = link_data.cfg & (ICE_AQ_CFG_PACING_M |
386 ICE_AQ_CFG_PACING_TYPE_M);
389 tx_pause = !!(link_data.an_info & ICE_AQ_LINK_PAUSE_TX);
390 rx_pause = !!(link_data.an_info & ICE_AQ_LINK_PAUSE_RX);
391 if (tx_pause && rx_pause)
392 hw_fc_info->current_mode = ICE_FC_FULL;
394 hw_fc_info->current_mode = ICE_FC_TX_PAUSE;
396 hw_fc_info->current_mode = ICE_FC_RX_PAUSE;
398 hw_fc_info->current_mode = ICE_FC_NONE;
400 li->lse_ena = !!(resp->cmd_flags & CPU_TO_LE16(ICE_AQ_LSE_IS_ENABLED));
402 ice_debug(hw, ICE_DBG_LINK, "link_speed = 0x%x\n", li->link_speed);
403 ice_debug(hw, ICE_DBG_LINK, "phy_type_low = 0x%llx\n",
404 (unsigned long long)li->phy_type_low);
405 ice_debug(hw, ICE_DBG_LINK, "phy_type_high = 0x%llx\n",
406 (unsigned long long)li->phy_type_high);
407 ice_debug(hw, ICE_DBG_LINK, "media_type = 0x%x\n", *hw_media_type);
408 ice_debug(hw, ICE_DBG_LINK, "link_info = 0x%x\n", li->link_info);
409 ice_debug(hw, ICE_DBG_LINK, "an_info = 0x%x\n", li->an_info);
410 ice_debug(hw, ICE_DBG_LINK, "ext_info = 0x%x\n", li->ext_info);
411 ice_debug(hw, ICE_DBG_LINK, "lse_ena = 0x%x\n", li->lse_ena);
412 ice_debug(hw, ICE_DBG_LINK, "max_frame = 0x%x\n", li->max_frame_size);
413 ice_debug(hw, ICE_DBG_LINK, "pacing = 0x%x\n", li->pacing);
415 /* save link status information */
419 /* flag cleared so calling functions don't call AQ again */
420 pi->phy.get_link_info = false;
426 * ice_fill_tx_timer_and_fc_thresh
427 * @hw: pointer to the HW struct
428 * @cmd: pointer to MAC cfg structure
430 * Add Tx timer and FC refresh threshold info to Set MAC Config AQ command
434 ice_fill_tx_timer_and_fc_thresh(struct ice_hw *hw,
435 struct ice_aqc_set_mac_cfg *cmd)
437 u16 fc_thres_val, tx_timer_val;
440 /* We read back the transmit timer and fc threshold value of
441 * LFC. Thus, we will use index =
442 * PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA_MAX_INDEX.
444 * Also, because we are opearating on transmit timer and fc
445 * threshold of LFC, we don't turn on any bit in tx_tmr_priority
447 #define IDX_OF_LFC PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA_MAX_INDEX
449 /* Retrieve the transmit timer */
450 val = rd32(hw, PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA(IDX_OF_LFC));
452 PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA_HSEC_CTL_TX_PAUSE_QUANTA_M;
453 cmd->tx_tmr_value = CPU_TO_LE16(tx_timer_val);
455 /* Retrieve the fc threshold */
456 val = rd32(hw, PRTMAC_HSEC_CTL_TX_PAUSE_REFRESH_TIMER(IDX_OF_LFC));
457 fc_thres_val = val & PRTMAC_HSEC_CTL_TX_PAUSE_REFRESH_TIMER_M;
459 cmd->fc_refresh_threshold = CPU_TO_LE16(fc_thres_val);
464 * @hw: pointer to the HW struct
465 * @max_frame_size: Maximum Frame Size to be supported
466 * @cd: pointer to command details structure or NULL
468 * Set MAC configuration (0x0603)
471 ice_aq_set_mac_cfg(struct ice_hw *hw, u16 max_frame_size, struct ice_sq_cd *cd)
473 struct ice_aqc_set_mac_cfg *cmd;
474 struct ice_aq_desc desc;
476 cmd = &desc.params.set_mac_cfg;
478 if (max_frame_size == 0)
479 return ICE_ERR_PARAM;
481 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_mac_cfg);
483 cmd->max_frame_size = CPU_TO_LE16(max_frame_size);
485 ice_fill_tx_timer_and_fc_thresh(hw, cmd);
487 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
491 * ice_init_fltr_mgmt_struct - initializes filter management list and locks
492 * @hw: pointer to the HW struct
494 enum ice_status ice_init_fltr_mgmt_struct(struct ice_hw *hw)
496 struct ice_switch_info *sw;
497 enum ice_status status;
499 hw->switch_info = (struct ice_switch_info *)
500 ice_malloc(hw, sizeof(*hw->switch_info));
502 sw = hw->switch_info;
505 return ICE_ERR_NO_MEMORY;
507 INIT_LIST_HEAD(&sw->vsi_list_map_head);
509 status = ice_init_def_sw_recp(hw, &hw->switch_info->recp_list);
511 ice_free(hw, hw->switch_info);
518 * ice_cleanup_fltr_mgmt_single - clears single filter mngt struct
519 * @hw: pointer to the HW struct
520 * @sw: pointer to switch info struct for which function clears filters
523 ice_cleanup_fltr_mgmt_single(struct ice_hw *hw, struct ice_switch_info *sw)
525 struct ice_vsi_list_map_info *v_pos_map;
526 struct ice_vsi_list_map_info *v_tmp_map;
527 struct ice_sw_recipe *recps;
533 LIST_FOR_EACH_ENTRY_SAFE(v_pos_map, v_tmp_map, &sw->vsi_list_map_head,
534 ice_vsi_list_map_info, list_entry) {
535 LIST_DEL(&v_pos_map->list_entry);
536 ice_free(hw, v_pos_map);
538 recps = sw->recp_list;
539 for (i = 0; i < ICE_MAX_NUM_RECIPES; i++) {
540 struct ice_recp_grp_entry *rg_entry, *tmprg_entry;
542 recps[i].root_rid = i;
543 LIST_FOR_EACH_ENTRY_SAFE(rg_entry, tmprg_entry,
544 &recps[i].rg_list, ice_recp_grp_entry,
546 LIST_DEL(&rg_entry->l_entry);
547 ice_free(hw, rg_entry);
550 if (recps[i].adv_rule) {
551 struct ice_adv_fltr_mgmt_list_entry *tmp_entry;
552 struct ice_adv_fltr_mgmt_list_entry *lst_itr;
554 ice_destroy_lock(&recps[i].filt_rule_lock);
555 LIST_FOR_EACH_ENTRY_SAFE(lst_itr, tmp_entry,
556 &recps[i].filt_rules,
557 ice_adv_fltr_mgmt_list_entry,
559 LIST_DEL(&lst_itr->list_entry);
560 ice_free(hw, lst_itr->lkups);
561 ice_free(hw, lst_itr);
564 struct ice_fltr_mgmt_list_entry *lst_itr, *tmp_entry;
566 ice_destroy_lock(&recps[i].filt_rule_lock);
567 LIST_FOR_EACH_ENTRY_SAFE(lst_itr, tmp_entry,
568 &recps[i].filt_rules,
569 ice_fltr_mgmt_list_entry,
571 LIST_DEL(&lst_itr->list_entry);
572 ice_free(hw, lst_itr);
575 if (recps[i].root_buf)
576 ice_free(hw, recps[i].root_buf);
578 ice_rm_sw_replay_rule_info(hw, sw);
579 ice_free(hw, sw->recp_list);
584 * ice_cleanup_all_fltr_mgmt - cleanup filter management list and locks
585 * @hw: pointer to the HW struct
587 void ice_cleanup_fltr_mgmt_struct(struct ice_hw *hw)
589 ice_cleanup_fltr_mgmt_single(hw, hw->switch_info);
593 * ice_get_itr_intrl_gran
594 * @hw: pointer to the HW struct
596 * Determines the ITR/INTRL granularities based on the maximum aggregate
597 * bandwidth according to the device's configuration during power-on.
599 static void ice_get_itr_intrl_gran(struct ice_hw *hw)
601 u8 max_agg_bw = (rd32(hw, GL_PWR_MODE_CTL) &
602 GL_PWR_MODE_CTL_CAR_MAX_BW_M) >>
603 GL_PWR_MODE_CTL_CAR_MAX_BW_S;
605 switch (max_agg_bw) {
606 case ICE_MAX_AGG_BW_200G:
607 case ICE_MAX_AGG_BW_100G:
608 case ICE_MAX_AGG_BW_50G:
609 hw->itr_gran = ICE_ITR_GRAN_ABOVE_25;
610 hw->intrl_gran = ICE_INTRL_GRAN_ABOVE_25;
612 case ICE_MAX_AGG_BW_25G:
613 hw->itr_gran = ICE_ITR_GRAN_MAX_25;
614 hw->intrl_gran = ICE_INTRL_GRAN_MAX_25;
620 * ice_print_rollback_msg - print FW rollback message
621 * @hw: pointer to the hardware structure
623 void ice_print_rollback_msg(struct ice_hw *hw)
625 char nvm_str[ICE_NVM_VER_LEN] = { 0 };
626 struct ice_nvm_info *nvm = &hw->nvm;
627 struct ice_orom_info *orom;
631 SNPRINTF(nvm_str, sizeof(nvm_str), "%x.%02x 0x%x %d.%d.%d",
632 nvm->major_ver, nvm->minor_ver, nvm->eetrack, orom->major,
633 orom->build, orom->patch);
635 "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",
636 nvm_str, hw->fw_maj_ver, hw->fw_min_ver);
640 * ice_init_hw - main hardware initialization routine
641 * @hw: pointer to the hardware structure
643 enum ice_status ice_init_hw(struct ice_hw *hw)
645 struct ice_aqc_get_phy_caps_data *pcaps;
646 enum ice_status status;
650 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
652 /* Set MAC type based on DeviceID */
653 status = ice_set_mac_type(hw);
657 hw->pf_id = (u8)(rd32(hw, PF_FUNC_RID) &
658 PF_FUNC_RID_FUNCTION_NUMBER_M) >>
659 PF_FUNC_RID_FUNCTION_NUMBER_S;
661 status = ice_reset(hw, ICE_RESET_PFR);
665 ice_get_itr_intrl_gran(hw);
667 status = ice_create_all_ctrlq(hw);
669 goto err_unroll_cqinit;
671 status = ice_init_nvm(hw);
673 goto err_unroll_cqinit;
675 if (ice_get_fw_mode(hw) == ICE_FW_MODE_ROLLBACK)
676 ice_print_rollback_msg(hw);
678 status = ice_clear_pf_cfg(hw);
680 goto err_unroll_cqinit;
682 /* Set bit to enable Flow Director filters */
683 wr32(hw, PFQF_FD_ENA, PFQF_FD_ENA_FD_ENA_M);
684 INIT_LIST_HEAD(&hw->fdir_list_head);
686 ice_clear_pxe_mode(hw);
688 status = ice_get_caps(hw);
690 goto err_unroll_cqinit;
692 hw->port_info = (struct ice_port_info *)
693 ice_malloc(hw, sizeof(*hw->port_info));
694 if (!hw->port_info) {
695 status = ICE_ERR_NO_MEMORY;
696 goto err_unroll_cqinit;
699 /* set the back pointer to HW */
700 hw->port_info->hw = hw;
702 /* Initialize port_info struct with switch configuration data */
703 status = ice_get_initial_sw_cfg(hw);
705 goto err_unroll_alloc;
708 /* Query the allocated resources for Tx scheduler */
709 status = ice_sched_query_res_alloc(hw);
711 ice_debug(hw, ICE_DBG_SCHED,
712 "Failed to get scheduler allocated resources\n");
713 goto err_unroll_alloc;
715 ice_sched_get_psm_clk_freq(hw);
717 /* Initialize port_info struct with scheduler data */
718 status = ice_sched_init_port(hw->port_info);
720 goto err_unroll_sched;
722 pcaps = (struct ice_aqc_get_phy_caps_data *)
723 ice_malloc(hw, sizeof(*pcaps));
725 status = ICE_ERR_NO_MEMORY;
726 goto err_unroll_sched;
729 /* Initialize port_info struct with PHY capabilities */
730 status = ice_aq_get_phy_caps(hw->port_info, false,
731 ICE_AQC_REPORT_TOPO_CAP, pcaps, NULL);
734 goto err_unroll_sched;
736 /* Initialize port_info struct with link information */
737 status = ice_aq_get_link_info(hw->port_info, false, NULL, NULL);
739 goto err_unroll_sched;
740 /* need a valid SW entry point to build a Tx tree */
741 if (!hw->sw_entry_point_layer) {
742 ice_debug(hw, ICE_DBG_SCHED, "invalid sw entry point\n");
743 status = ICE_ERR_CFG;
744 goto err_unroll_sched;
746 INIT_LIST_HEAD(&hw->agg_list);
747 /* Initialize max burst size */
748 if (!hw->max_burst_size)
749 ice_cfg_rl_burst_size(hw, ICE_SCHED_DFLT_BURST_SIZE);
751 status = ice_init_fltr_mgmt_struct(hw);
753 goto err_unroll_sched;
755 /* Get MAC information */
756 /* A single port can report up to two (LAN and WoL) addresses */
757 mac_buf = ice_calloc(hw, 2,
758 sizeof(struct ice_aqc_manage_mac_read_resp));
759 mac_buf_len = 2 * sizeof(struct ice_aqc_manage_mac_read_resp);
762 status = ICE_ERR_NO_MEMORY;
763 goto err_unroll_fltr_mgmt_struct;
766 status = ice_aq_manage_mac_read(hw, mac_buf, mac_buf_len, NULL);
767 ice_free(hw, mac_buf);
770 goto err_unroll_fltr_mgmt_struct;
771 /* enable jumbo frame support at MAC level */
772 status = ice_aq_set_mac_cfg(hw, ICE_AQ_SET_MAC_FRAME_SIZE_MAX, NULL);
774 goto err_unroll_fltr_mgmt_struct;
775 /* Obtain counter base index which would be used by flow director */
776 status = ice_alloc_fd_res_cntr(hw, &hw->fd_ctr_base);
778 goto err_unroll_fltr_mgmt_struct;
779 status = ice_init_hw_tbls(hw);
781 goto err_unroll_fltr_mgmt_struct;
782 ice_init_lock(&hw->tnl_lock);
785 err_unroll_fltr_mgmt_struct:
786 ice_cleanup_fltr_mgmt_struct(hw);
788 ice_sched_cleanup_all(hw);
790 ice_free(hw, hw->port_info);
791 hw->port_info = NULL;
793 ice_destroy_all_ctrlq(hw);
798 * ice_deinit_hw - unroll initialization operations done by ice_init_hw
799 * @hw: pointer to the hardware structure
801 * This should be called only during nominal operation, not as a result of
802 * ice_init_hw() failing since ice_init_hw() will take care of unrolling
803 * applicable initializations if it fails for any reason.
805 void ice_deinit_hw(struct ice_hw *hw)
807 ice_free_fd_res_cntr(hw, hw->fd_ctr_base);
808 ice_cleanup_fltr_mgmt_struct(hw);
810 ice_sched_cleanup_all(hw);
811 ice_sched_clear_agg(hw);
813 ice_free_hw_tbls(hw);
814 ice_destroy_lock(&hw->tnl_lock);
817 ice_free(hw, hw->port_info);
818 hw->port_info = NULL;
821 ice_destroy_all_ctrlq(hw);
823 /* Clear VSI contexts if not already cleared */
824 ice_clear_all_vsi_ctx(hw);
828 * ice_check_reset - Check to see if a global reset is complete
829 * @hw: pointer to the hardware structure
831 enum ice_status ice_check_reset(struct ice_hw *hw)
833 u32 cnt, reg = 0, grst_delay, uld_mask;
835 /* Poll for Device Active state in case a recent CORER, GLOBR,
836 * or EMPR has occurred. The grst delay value is in 100ms units.
837 * Add 1sec for outstanding AQ commands that can take a long time.
839 grst_delay = ((rd32(hw, GLGEN_RSTCTL) & GLGEN_RSTCTL_GRSTDEL_M) >>
840 GLGEN_RSTCTL_GRSTDEL_S) + 10;
842 for (cnt = 0; cnt < grst_delay; cnt++) {
843 ice_msec_delay(100, true);
844 reg = rd32(hw, GLGEN_RSTAT);
845 if (!(reg & GLGEN_RSTAT_DEVSTATE_M))
849 if (cnt == grst_delay) {
850 ice_debug(hw, ICE_DBG_INIT,
851 "Global reset polling failed to complete.\n");
852 return ICE_ERR_RESET_FAILED;
855 #define ICE_RESET_DONE_MASK (GLNVM_ULD_PCIER_DONE_M |\
856 GLNVM_ULD_PCIER_DONE_1_M |\
857 GLNVM_ULD_CORER_DONE_M |\
858 GLNVM_ULD_GLOBR_DONE_M |\
859 GLNVM_ULD_POR_DONE_M |\
860 GLNVM_ULD_POR_DONE_1_M |\
861 GLNVM_ULD_PCIER_DONE_2_M)
863 uld_mask = ICE_RESET_DONE_MASK;
865 /* Device is Active; check Global Reset processes are done */
866 for (cnt = 0; cnt < ICE_PF_RESET_WAIT_COUNT; cnt++) {
867 reg = rd32(hw, GLNVM_ULD) & uld_mask;
868 if (reg == uld_mask) {
869 ice_debug(hw, ICE_DBG_INIT,
870 "Global reset processes done. %d\n", cnt);
873 ice_msec_delay(10, true);
876 if (cnt == ICE_PF_RESET_WAIT_COUNT) {
877 ice_debug(hw, ICE_DBG_INIT,
878 "Wait for Reset Done timed out. GLNVM_ULD = 0x%x\n",
880 return ICE_ERR_RESET_FAILED;
887 * ice_pf_reset - Reset the PF
888 * @hw: pointer to the hardware structure
890 * If a global reset has been triggered, this function checks
891 * for its completion and then issues the PF reset
893 static enum ice_status ice_pf_reset(struct ice_hw *hw)
897 /* If at function entry a global reset was already in progress, i.e.
898 * state is not 'device active' or any of the reset done bits are not
899 * set in GLNVM_ULD, there is no need for a PF Reset; poll until the
900 * global reset is done.
902 if ((rd32(hw, GLGEN_RSTAT) & GLGEN_RSTAT_DEVSTATE_M) ||
903 (rd32(hw, GLNVM_ULD) & ICE_RESET_DONE_MASK) ^ ICE_RESET_DONE_MASK) {
904 /* poll on global reset currently in progress until done */
905 if (ice_check_reset(hw))
906 return ICE_ERR_RESET_FAILED;
912 reg = rd32(hw, PFGEN_CTRL);
914 wr32(hw, PFGEN_CTRL, (reg | PFGEN_CTRL_PFSWR_M));
916 for (cnt = 0; cnt < ICE_PF_RESET_WAIT_COUNT; cnt++) {
917 reg = rd32(hw, PFGEN_CTRL);
918 if (!(reg & PFGEN_CTRL_PFSWR_M))
921 ice_msec_delay(1, true);
924 if (cnt == ICE_PF_RESET_WAIT_COUNT) {
925 ice_debug(hw, ICE_DBG_INIT,
926 "PF reset polling failed to complete.\n");
927 return ICE_ERR_RESET_FAILED;
934 * ice_reset - Perform different types of reset
935 * @hw: pointer to the hardware structure
936 * @req: reset request
938 * This function triggers a reset as specified by the req parameter.
941 * If anything other than a PF reset is triggered, PXE mode is restored.
942 * This has to be cleared using ice_clear_pxe_mode again, once the AQ
943 * interface has been restored in the rebuild flow.
945 enum ice_status ice_reset(struct ice_hw *hw, enum ice_reset_req req)
951 return ice_pf_reset(hw);
952 case ICE_RESET_CORER:
953 ice_debug(hw, ICE_DBG_INIT, "CoreR requested\n");
954 val = GLGEN_RTRIG_CORER_M;
956 case ICE_RESET_GLOBR:
957 ice_debug(hw, ICE_DBG_INIT, "GlobalR requested\n");
958 val = GLGEN_RTRIG_GLOBR_M;
961 return ICE_ERR_PARAM;
964 val |= rd32(hw, GLGEN_RTRIG);
965 wr32(hw, GLGEN_RTRIG, val);
968 /* wait for the FW to be ready */
969 return ice_check_reset(hw);
973 * ice_copy_rxq_ctx_to_hw
974 * @hw: pointer to the hardware structure
975 * @ice_rxq_ctx: pointer to the rxq context
976 * @rxq_index: the index of the Rx queue
978 * Copies rxq context from dense structure to HW register space
980 static enum ice_status
981 ice_copy_rxq_ctx_to_hw(struct ice_hw *hw, u8 *ice_rxq_ctx, u32 rxq_index)
986 return ICE_ERR_BAD_PTR;
988 if (rxq_index > QRX_CTRL_MAX_INDEX)
989 return ICE_ERR_PARAM;
991 /* Copy each dword separately to HW */
992 for (i = 0; i < ICE_RXQ_CTX_SIZE_DWORDS; i++) {
993 wr32(hw, QRX_CONTEXT(i, rxq_index),
994 *((u32 *)(ice_rxq_ctx + (i * sizeof(u32)))));
996 ice_debug(hw, ICE_DBG_QCTX, "qrxdata[%d]: %08X\n", i,
997 *((u32 *)(ice_rxq_ctx + (i * sizeof(u32)))));
1003 /* LAN Rx Queue Context */
1004 static const struct ice_ctx_ele ice_rlan_ctx_info[] = {
1005 /* Field Width LSB */
1006 ICE_CTX_STORE(ice_rlan_ctx, head, 13, 0),
1007 ICE_CTX_STORE(ice_rlan_ctx, cpuid, 8, 13),
1008 ICE_CTX_STORE(ice_rlan_ctx, base, 57, 32),
1009 ICE_CTX_STORE(ice_rlan_ctx, qlen, 13, 89),
1010 ICE_CTX_STORE(ice_rlan_ctx, dbuf, 7, 102),
1011 ICE_CTX_STORE(ice_rlan_ctx, hbuf, 5, 109),
1012 ICE_CTX_STORE(ice_rlan_ctx, dtype, 2, 114),
1013 ICE_CTX_STORE(ice_rlan_ctx, dsize, 1, 116),
1014 ICE_CTX_STORE(ice_rlan_ctx, crcstrip, 1, 117),
1015 ICE_CTX_STORE(ice_rlan_ctx, l2tsel, 1, 119),
1016 ICE_CTX_STORE(ice_rlan_ctx, hsplit_0, 4, 120),
1017 ICE_CTX_STORE(ice_rlan_ctx, hsplit_1, 2, 124),
1018 ICE_CTX_STORE(ice_rlan_ctx, showiv, 1, 127),
1019 ICE_CTX_STORE(ice_rlan_ctx, rxmax, 14, 174),
1020 ICE_CTX_STORE(ice_rlan_ctx, tphrdesc_ena, 1, 193),
1021 ICE_CTX_STORE(ice_rlan_ctx, tphwdesc_ena, 1, 194),
1022 ICE_CTX_STORE(ice_rlan_ctx, tphdata_ena, 1, 195),
1023 ICE_CTX_STORE(ice_rlan_ctx, tphhead_ena, 1, 196),
1024 ICE_CTX_STORE(ice_rlan_ctx, lrxqthresh, 3, 198),
1025 ICE_CTX_STORE(ice_rlan_ctx, prefena, 1, 201),
1031 * @hw: pointer to the hardware structure
1032 * @rlan_ctx: pointer to the rxq context
1033 * @rxq_index: the index of the Rx queue
1035 * Converts rxq context from sparse to dense structure and then writes
1036 * it to HW register space and enables the hardware to prefetch descriptors
1037 * instead of only fetching them on demand
1040 ice_write_rxq_ctx(struct ice_hw *hw, struct ice_rlan_ctx *rlan_ctx,
1043 u8 ctx_buf[ICE_RXQ_CTX_SZ] = { 0 };
1046 return ICE_ERR_BAD_PTR;
1048 rlan_ctx->prefena = 1;
1050 ice_set_ctx(hw, (u8 *)rlan_ctx, ctx_buf, ice_rlan_ctx_info);
1051 return ice_copy_rxq_ctx_to_hw(hw, ctx_buf, rxq_index);
1056 * @hw: pointer to the hardware structure
1057 * @rxq_index: the index of the Rx queue to clear
1059 * Clears rxq context in HW register space
1061 enum ice_status ice_clear_rxq_ctx(struct ice_hw *hw, u32 rxq_index)
1065 if (rxq_index > QRX_CTRL_MAX_INDEX)
1066 return ICE_ERR_PARAM;
1068 /* Clear each dword register separately */
1069 for (i = 0; i < ICE_RXQ_CTX_SIZE_DWORDS; i++)
1070 wr32(hw, QRX_CONTEXT(i, rxq_index), 0);
1075 /* LAN Tx Queue Context */
1076 const struct ice_ctx_ele ice_tlan_ctx_info[] = {
1077 /* Field Width LSB */
1078 ICE_CTX_STORE(ice_tlan_ctx, base, 57, 0),
1079 ICE_CTX_STORE(ice_tlan_ctx, port_num, 3, 57),
1080 ICE_CTX_STORE(ice_tlan_ctx, cgd_num, 5, 60),
1081 ICE_CTX_STORE(ice_tlan_ctx, pf_num, 3, 65),
1082 ICE_CTX_STORE(ice_tlan_ctx, vmvf_num, 10, 68),
1083 ICE_CTX_STORE(ice_tlan_ctx, vmvf_type, 2, 78),
1084 ICE_CTX_STORE(ice_tlan_ctx, src_vsi, 10, 80),
1085 ICE_CTX_STORE(ice_tlan_ctx, tsyn_ena, 1, 90),
1086 ICE_CTX_STORE(ice_tlan_ctx, internal_usage_flag, 1, 91),
1087 ICE_CTX_STORE(ice_tlan_ctx, alt_vlan, 1, 92),
1088 ICE_CTX_STORE(ice_tlan_ctx, cpuid, 8, 93),
1089 ICE_CTX_STORE(ice_tlan_ctx, wb_mode, 1, 101),
1090 ICE_CTX_STORE(ice_tlan_ctx, tphrd_desc, 1, 102),
1091 ICE_CTX_STORE(ice_tlan_ctx, tphrd, 1, 103),
1092 ICE_CTX_STORE(ice_tlan_ctx, tphwr_desc, 1, 104),
1093 ICE_CTX_STORE(ice_tlan_ctx, cmpq_id, 9, 105),
1094 ICE_CTX_STORE(ice_tlan_ctx, qnum_in_func, 14, 114),
1095 ICE_CTX_STORE(ice_tlan_ctx, itr_notification_mode, 1, 128),
1096 ICE_CTX_STORE(ice_tlan_ctx, adjust_prof_id, 6, 129),
1097 ICE_CTX_STORE(ice_tlan_ctx, qlen, 13, 135),
1098 ICE_CTX_STORE(ice_tlan_ctx, quanta_prof_idx, 4, 148),
1099 ICE_CTX_STORE(ice_tlan_ctx, tso_ena, 1, 152),
1100 ICE_CTX_STORE(ice_tlan_ctx, tso_qnum, 11, 153),
1101 ICE_CTX_STORE(ice_tlan_ctx, legacy_int, 1, 164),
1102 ICE_CTX_STORE(ice_tlan_ctx, drop_ena, 1, 165),
1103 ICE_CTX_STORE(ice_tlan_ctx, cache_prof_idx, 2, 166),
1104 ICE_CTX_STORE(ice_tlan_ctx, pkt_shaper_prof_idx, 3, 168),
1105 ICE_CTX_STORE(ice_tlan_ctx, int_q_state, 122, 171),
1110 * ice_copy_tx_cmpltnq_ctx_to_hw
1111 * @hw: pointer to the hardware structure
1112 * @ice_tx_cmpltnq_ctx: pointer to the Tx completion queue context
1113 * @tx_cmpltnq_index: the index of the completion queue
1115 * Copies Tx completion queue context from dense structure to HW register space
1117 static enum ice_status
1118 ice_copy_tx_cmpltnq_ctx_to_hw(struct ice_hw *hw, u8 *ice_tx_cmpltnq_ctx,
1119 u32 tx_cmpltnq_index)
1123 if (!ice_tx_cmpltnq_ctx)
1124 return ICE_ERR_BAD_PTR;
1126 if (tx_cmpltnq_index > GLTCLAN_CQ_CNTX0_MAX_INDEX)
1127 return ICE_ERR_PARAM;
1129 /* Copy each dword separately to HW */
1130 for (i = 0; i < ICE_TX_CMPLTNQ_CTX_SIZE_DWORDS; i++) {
1131 wr32(hw, GLTCLAN_CQ_CNTX(i, tx_cmpltnq_index),
1132 *((u32 *)(ice_tx_cmpltnq_ctx + (i * sizeof(u32)))));
1134 ice_debug(hw, ICE_DBG_QCTX, "cmpltnqdata[%d]: %08X\n", i,
1135 *((u32 *)(ice_tx_cmpltnq_ctx + (i * sizeof(u32)))));
1141 /* LAN Tx Completion Queue Context */
1142 static const struct ice_ctx_ele ice_tx_cmpltnq_ctx_info[] = {
1143 /* Field Width LSB */
1144 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, base, 57, 0),
1145 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, q_len, 18, 64),
1146 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, generation, 1, 96),
1147 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, wrt_ptr, 22, 97),
1148 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, pf_num, 3, 128),
1149 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, vmvf_num, 10, 131),
1150 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, vmvf_type, 2, 141),
1151 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, tph_desc_wr, 1, 160),
1152 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, cpuid, 8, 161),
1153 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, cmpltn_cache, 512, 192),
1158 * ice_write_tx_cmpltnq_ctx
1159 * @hw: pointer to the hardware structure
1160 * @tx_cmpltnq_ctx: pointer to the completion queue context
1161 * @tx_cmpltnq_index: the index of the completion queue
1163 * Converts completion queue context from sparse to dense structure and then
1164 * writes it to HW register space
1167 ice_write_tx_cmpltnq_ctx(struct ice_hw *hw,
1168 struct ice_tx_cmpltnq_ctx *tx_cmpltnq_ctx,
1169 u32 tx_cmpltnq_index)
1171 u8 ctx_buf[ICE_TX_CMPLTNQ_CTX_SIZE_DWORDS * sizeof(u32)] = { 0 };
1173 ice_set_ctx(hw, (u8 *)tx_cmpltnq_ctx, ctx_buf, ice_tx_cmpltnq_ctx_info);
1174 return ice_copy_tx_cmpltnq_ctx_to_hw(hw, ctx_buf, tx_cmpltnq_index);
1178 * ice_clear_tx_cmpltnq_ctx
1179 * @hw: pointer to the hardware structure
1180 * @tx_cmpltnq_index: the index of the completion queue to clear
1182 * Clears Tx completion queue context in HW register space
1185 ice_clear_tx_cmpltnq_ctx(struct ice_hw *hw, u32 tx_cmpltnq_index)
1189 if (tx_cmpltnq_index > GLTCLAN_CQ_CNTX0_MAX_INDEX)
1190 return ICE_ERR_PARAM;
1192 /* Clear each dword register separately */
1193 for (i = 0; i < ICE_TX_CMPLTNQ_CTX_SIZE_DWORDS; i++)
1194 wr32(hw, GLTCLAN_CQ_CNTX(i, tx_cmpltnq_index), 0);
1200 * ice_copy_tx_drbell_q_ctx_to_hw
1201 * @hw: pointer to the hardware structure
1202 * @ice_tx_drbell_q_ctx: pointer to the doorbell queue context
1203 * @tx_drbell_q_index: the index of the doorbell queue
1205 * Copies doorbell queue context from dense structure to HW register space
1207 static enum ice_status
1208 ice_copy_tx_drbell_q_ctx_to_hw(struct ice_hw *hw, u8 *ice_tx_drbell_q_ctx,
1209 u32 tx_drbell_q_index)
1213 if (!ice_tx_drbell_q_ctx)
1214 return ICE_ERR_BAD_PTR;
1216 if (tx_drbell_q_index > QTX_COMM_DBLQ_DBELL_MAX_INDEX)
1217 return ICE_ERR_PARAM;
1219 /* Copy each dword separately to HW */
1220 for (i = 0; i < ICE_TX_DRBELL_Q_CTX_SIZE_DWORDS; i++) {
1221 wr32(hw, QTX_COMM_DBLQ_CNTX(i, tx_drbell_q_index),
1222 *((u32 *)(ice_tx_drbell_q_ctx + (i * sizeof(u32)))));
1224 ice_debug(hw, ICE_DBG_QCTX, "tx_drbell_qdata[%d]: %08X\n", i,
1225 *((u32 *)(ice_tx_drbell_q_ctx + (i * sizeof(u32)))));
1231 /* LAN Tx Doorbell Queue Context info */
1232 static const struct ice_ctx_ele ice_tx_drbell_q_ctx_info[] = {
1233 /* Field Width LSB */
1234 ICE_CTX_STORE(ice_tx_drbell_q_ctx, base, 57, 0),
1235 ICE_CTX_STORE(ice_tx_drbell_q_ctx, ring_len, 13, 64),
1236 ICE_CTX_STORE(ice_tx_drbell_q_ctx, pf_num, 3, 80),
1237 ICE_CTX_STORE(ice_tx_drbell_q_ctx, vf_num, 8, 84),
1238 ICE_CTX_STORE(ice_tx_drbell_q_ctx, vmvf_type, 2, 94),
1239 ICE_CTX_STORE(ice_tx_drbell_q_ctx, cpuid, 8, 96),
1240 ICE_CTX_STORE(ice_tx_drbell_q_ctx, tph_desc_rd, 1, 104),
1241 ICE_CTX_STORE(ice_tx_drbell_q_ctx, tph_desc_wr, 1, 108),
1242 ICE_CTX_STORE(ice_tx_drbell_q_ctx, db_q_en, 1, 112),
1243 ICE_CTX_STORE(ice_tx_drbell_q_ctx, rd_head, 13, 128),
1244 ICE_CTX_STORE(ice_tx_drbell_q_ctx, rd_tail, 13, 144),
1249 * ice_write_tx_drbell_q_ctx
1250 * @hw: pointer to the hardware structure
1251 * @tx_drbell_q_ctx: pointer to the doorbell queue context
1252 * @tx_drbell_q_index: the index of the doorbell queue
1254 * Converts doorbell queue context from sparse to dense structure and then
1255 * writes it to HW register space
1258 ice_write_tx_drbell_q_ctx(struct ice_hw *hw,
1259 struct ice_tx_drbell_q_ctx *tx_drbell_q_ctx,
1260 u32 tx_drbell_q_index)
1262 u8 ctx_buf[ICE_TX_DRBELL_Q_CTX_SIZE_DWORDS * sizeof(u32)] = { 0 };
1264 ice_set_ctx(hw, (u8 *)tx_drbell_q_ctx, ctx_buf,
1265 ice_tx_drbell_q_ctx_info);
1266 return ice_copy_tx_drbell_q_ctx_to_hw(hw, ctx_buf, tx_drbell_q_index);
1270 * ice_clear_tx_drbell_q_ctx
1271 * @hw: pointer to the hardware structure
1272 * @tx_drbell_q_index: the index of the doorbell queue to clear
1274 * Clears doorbell queue context in HW register space
1277 ice_clear_tx_drbell_q_ctx(struct ice_hw *hw, u32 tx_drbell_q_index)
1281 if (tx_drbell_q_index > QTX_COMM_DBLQ_DBELL_MAX_INDEX)
1282 return ICE_ERR_PARAM;
1284 /* Clear each dword register separately */
1285 for (i = 0; i < ICE_TX_DRBELL_Q_CTX_SIZE_DWORDS; i++)
1286 wr32(hw, QTX_COMM_DBLQ_CNTX(i, tx_drbell_q_index), 0);
1291 /* FW Admin Queue command wrappers */
1294 * ice_aq_send_cmd - send FW Admin Queue command to FW Admin Queue
1295 * @hw: pointer to the HW struct
1296 * @desc: descriptor describing the command
1297 * @buf: buffer to use for indirect commands (NULL for direct commands)
1298 * @buf_size: size of buffer for indirect commands (0 for direct commands)
1299 * @cd: pointer to command details structure
1301 * Helper function to send FW Admin Queue commands to the FW Admin Queue.
1304 ice_aq_send_cmd(struct ice_hw *hw, struct ice_aq_desc *desc, void *buf,
1305 u16 buf_size, struct ice_sq_cd *cd)
1307 if (hw->aq_send_cmd_fn) {
1308 enum ice_status status = ICE_ERR_NOT_READY;
1309 u16 retval = ICE_AQ_RC_OK;
1311 ice_acquire_lock(&hw->adminq.sq_lock);
1312 if (!hw->aq_send_cmd_fn(hw->aq_send_cmd_param, desc,
1314 retval = LE16_TO_CPU(desc->retval);
1315 /* strip off FW internal code */
1318 if (retval == ICE_AQ_RC_OK)
1319 status = ICE_SUCCESS;
1321 status = ICE_ERR_AQ_ERROR;
1324 hw->adminq.sq_last_status = (enum ice_aq_err)retval;
1325 ice_release_lock(&hw->adminq.sq_lock);
1329 return ice_sq_send_cmd(hw, &hw->adminq, desc, buf, buf_size, cd);
1334 * @hw: pointer to the HW struct
1335 * @cd: pointer to command details structure or NULL
1337 * Get the firmware version (0x0001) from the admin queue commands
1339 enum ice_status ice_aq_get_fw_ver(struct ice_hw *hw, struct ice_sq_cd *cd)
1341 struct ice_aqc_get_ver *resp;
1342 struct ice_aq_desc desc;
1343 enum ice_status status;
1345 resp = &desc.params.get_ver;
1347 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_ver);
1349 status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
1352 hw->fw_branch = resp->fw_branch;
1353 hw->fw_maj_ver = resp->fw_major;
1354 hw->fw_min_ver = resp->fw_minor;
1355 hw->fw_patch = resp->fw_patch;
1356 hw->fw_build = LE32_TO_CPU(resp->fw_build);
1357 hw->api_branch = resp->api_branch;
1358 hw->api_maj_ver = resp->api_major;
1359 hw->api_min_ver = resp->api_minor;
1360 hw->api_patch = resp->api_patch;
1367 * ice_aq_send_driver_ver
1368 * @hw: pointer to the HW struct
1369 * @dv: driver's major, minor version
1370 * @cd: pointer to command details structure or NULL
1372 * Send the driver version (0x0002) to the firmware
1375 ice_aq_send_driver_ver(struct ice_hw *hw, struct ice_driver_ver *dv,
1376 struct ice_sq_cd *cd)
1378 struct ice_aqc_driver_ver *cmd;
1379 struct ice_aq_desc desc;
1382 cmd = &desc.params.driver_ver;
1385 return ICE_ERR_PARAM;
1387 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_driver_ver);
1389 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
1390 cmd->major_ver = dv->major_ver;
1391 cmd->minor_ver = dv->minor_ver;
1392 cmd->build_ver = dv->build_ver;
1393 cmd->subbuild_ver = dv->subbuild_ver;
1396 while (len < sizeof(dv->driver_string) &&
1397 IS_ASCII(dv->driver_string[len]) && dv->driver_string[len])
1400 return ice_aq_send_cmd(hw, &desc, dv->driver_string, len, cd);
1405 * @hw: pointer to the HW struct
1406 * @unloading: is the driver unloading itself
1408 * Tell the Firmware that we're shutting down the AdminQ and whether
1409 * or not the driver is unloading as well (0x0003).
1411 enum ice_status ice_aq_q_shutdown(struct ice_hw *hw, bool unloading)
1413 struct ice_aqc_q_shutdown *cmd;
1414 struct ice_aq_desc desc;
1416 cmd = &desc.params.q_shutdown;
1418 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_q_shutdown);
1421 cmd->driver_unloading = ICE_AQC_DRIVER_UNLOADING;
1423 return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
1428 * @hw: pointer to the HW struct
1430 * @access: access type
1431 * @sdp_number: resource number
1432 * @timeout: the maximum time in ms that the driver may hold the resource
1433 * @cd: pointer to command details structure or NULL
1435 * Requests common resource using the admin queue commands (0x0008).
1436 * When attempting to acquire the Global Config Lock, the driver can
1437 * learn of three states:
1438 * 1) ICE_SUCCESS - acquired lock, and can perform download package
1439 * 2) ICE_ERR_AQ_ERROR - did not get lock, driver should fail to load
1440 * 3) ICE_ERR_AQ_NO_WORK - did not get lock, but another driver has
1441 * successfully downloaded the package; the driver does
1442 * not have to download the package and can continue
1445 * Note that if the caller is in an acquire lock, perform action, release lock
1446 * phase of operation, it is possible that the FW may detect a timeout and issue
1447 * a CORER. In this case, the driver will receive a CORER interrupt and will
1448 * have to determine its cause. The calling thread that is handling this flow
1449 * will likely get an error propagated back to it indicating the Download
1450 * Package, Update Package or the Release Resource AQ commands timed out.
1452 static enum ice_status
1453 ice_aq_req_res(struct ice_hw *hw, enum ice_aq_res_ids res,
1454 enum ice_aq_res_access_type access, u8 sdp_number, u32 *timeout,
1455 struct ice_sq_cd *cd)
1457 struct ice_aqc_req_res *cmd_resp;
1458 struct ice_aq_desc desc;
1459 enum ice_status status;
1461 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1463 cmd_resp = &desc.params.res_owner;
1465 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_req_res);
1467 cmd_resp->res_id = CPU_TO_LE16(res);
1468 cmd_resp->access_type = CPU_TO_LE16(access);
1469 cmd_resp->res_number = CPU_TO_LE32(sdp_number);
1470 cmd_resp->timeout = CPU_TO_LE32(*timeout);
1473 status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
1475 /* The completion specifies the maximum time in ms that the driver
1476 * may hold the resource in the Timeout field.
1479 /* Global config lock response utilizes an additional status field.
1481 * If the Global config lock resource is held by some other driver, the
1482 * command completes with ICE_AQ_RES_GLBL_IN_PROG in the status field
1483 * and the timeout field indicates the maximum time the current owner
1484 * of the resource has to free it.
1486 if (res == ICE_GLOBAL_CFG_LOCK_RES_ID) {
1487 if (LE16_TO_CPU(cmd_resp->status) == ICE_AQ_RES_GLBL_SUCCESS) {
1488 *timeout = LE32_TO_CPU(cmd_resp->timeout);
1490 } else if (LE16_TO_CPU(cmd_resp->status) ==
1491 ICE_AQ_RES_GLBL_IN_PROG) {
1492 *timeout = LE32_TO_CPU(cmd_resp->timeout);
1493 return ICE_ERR_AQ_ERROR;
1494 } else if (LE16_TO_CPU(cmd_resp->status) ==
1495 ICE_AQ_RES_GLBL_DONE) {
1496 return ICE_ERR_AQ_NO_WORK;
1499 /* invalid FW response, force a timeout immediately */
1501 return ICE_ERR_AQ_ERROR;
1504 /* If the resource is held by some other driver, the command completes
1505 * with a busy return value and the timeout field indicates the maximum
1506 * time the current owner of the resource has to free it.
1508 if (!status || hw->adminq.sq_last_status == ICE_AQ_RC_EBUSY)
1509 *timeout = LE32_TO_CPU(cmd_resp->timeout);
1515 * ice_aq_release_res
1516 * @hw: pointer to the HW struct
1518 * @sdp_number: resource number
1519 * @cd: pointer to command details structure or NULL
1521 * release common resource using the admin queue commands (0x0009)
1523 static enum ice_status
1524 ice_aq_release_res(struct ice_hw *hw, enum ice_aq_res_ids res, u8 sdp_number,
1525 struct ice_sq_cd *cd)
1527 struct ice_aqc_req_res *cmd;
1528 struct ice_aq_desc desc;
1530 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1532 cmd = &desc.params.res_owner;
1534 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_release_res);
1536 cmd->res_id = CPU_TO_LE16(res);
1537 cmd->res_number = CPU_TO_LE32(sdp_number);
1539 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
1544 * @hw: pointer to the HW structure
1546 * @access: access type (read or write)
1547 * @timeout: timeout in milliseconds
1549 * This function will attempt to acquire the ownership of a resource.
1552 ice_acquire_res(struct ice_hw *hw, enum ice_aq_res_ids res,
1553 enum ice_aq_res_access_type access, u32 timeout)
1555 #define ICE_RES_POLLING_DELAY_MS 10
1556 u32 delay = ICE_RES_POLLING_DELAY_MS;
1557 u32 time_left = timeout;
1558 enum ice_status status;
1560 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1562 status = ice_aq_req_res(hw, res, access, 0, &time_left, NULL);
1564 /* A return code of ICE_ERR_AQ_NO_WORK means that another driver has
1565 * previously acquired the resource and performed any necessary updates;
1566 * in this case the caller does not obtain the resource and has no
1567 * further work to do.
1569 if (status == ICE_ERR_AQ_NO_WORK)
1570 goto ice_acquire_res_exit;
1573 ice_debug(hw, ICE_DBG_RES,
1574 "resource %d acquire type %d failed.\n", res, access);
1576 /* If necessary, poll until the current lock owner timeouts */
1577 timeout = time_left;
1578 while (status && timeout && time_left) {
1579 ice_msec_delay(delay, true);
1580 timeout = (timeout > delay) ? timeout - delay : 0;
1581 status = ice_aq_req_res(hw, res, access, 0, &time_left, NULL);
1583 if (status == ICE_ERR_AQ_NO_WORK)
1584 /* lock free, but no work to do */
1591 if (status && status != ICE_ERR_AQ_NO_WORK)
1592 ice_debug(hw, ICE_DBG_RES, "resource acquire timed out.\n");
1594 ice_acquire_res_exit:
1595 if (status == ICE_ERR_AQ_NO_WORK) {
1596 if (access == ICE_RES_WRITE)
1597 ice_debug(hw, ICE_DBG_RES,
1598 "resource indicates no work to do.\n");
1600 ice_debug(hw, ICE_DBG_RES,
1601 "Warning: ICE_ERR_AQ_NO_WORK not expected\n");
1608 * @hw: pointer to the HW structure
1611 * This function will release a resource using the proper Admin Command.
1613 void ice_release_res(struct ice_hw *hw, enum ice_aq_res_ids res)
1615 enum ice_status status;
1616 u32 total_delay = 0;
1618 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1620 status = ice_aq_release_res(hw, res, 0, NULL);
1622 /* there are some rare cases when trying to release the resource
1623 * results in an admin queue timeout, so handle them correctly
1625 while ((status == ICE_ERR_AQ_TIMEOUT) &&
1626 (total_delay < hw->adminq.sq_cmd_timeout)) {
1627 ice_msec_delay(1, true);
1628 status = ice_aq_release_res(hw, res, 0, NULL);
1634 * ice_aq_alloc_free_res - command to allocate/free resources
1635 * @hw: pointer to the HW struct
1636 * @num_entries: number of resource entries in buffer
1637 * @buf: Indirect buffer to hold data parameters and response
1638 * @buf_size: size of buffer for indirect commands
1639 * @opc: pass in the command opcode
1640 * @cd: pointer to command details structure or NULL
1642 * Helper function to allocate/free resources using the admin queue commands
1645 ice_aq_alloc_free_res(struct ice_hw *hw, u16 num_entries,
1646 struct ice_aqc_alloc_free_res_elem *buf, u16 buf_size,
1647 enum ice_adminq_opc opc, struct ice_sq_cd *cd)
1649 struct ice_aqc_alloc_free_res_cmd *cmd;
1650 struct ice_aq_desc desc;
1652 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1654 cmd = &desc.params.sw_res_ctrl;
1657 return ICE_ERR_PARAM;
1659 if (buf_size < (num_entries * sizeof(buf->elem[0])))
1660 return ICE_ERR_PARAM;
1662 ice_fill_dflt_direct_cmd_desc(&desc, opc);
1664 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
1666 cmd->num_entries = CPU_TO_LE16(num_entries);
1668 return ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
1672 * ice_alloc_hw_res - allocate resource
1673 * @hw: pointer to the HW struct
1674 * @type: type of resource
1675 * @num: number of resources to allocate
1676 * @btm: allocate from bottom
1677 * @res: pointer to array that will receive the resources
1680 ice_alloc_hw_res(struct ice_hw *hw, u16 type, u16 num, bool btm, u16 *res)
1682 struct ice_aqc_alloc_free_res_elem *buf;
1683 enum ice_status status;
1686 buf_len = ice_struct_size(buf, elem, num - 1);
1687 buf = (struct ice_aqc_alloc_free_res_elem *)
1688 ice_malloc(hw, buf_len);
1690 return ICE_ERR_NO_MEMORY;
1692 /* Prepare buffer to allocate resource. */
1693 buf->num_elems = CPU_TO_LE16(num);
1694 buf->res_type = CPU_TO_LE16(type | ICE_AQC_RES_TYPE_FLAG_DEDICATED |
1695 ICE_AQC_RES_TYPE_FLAG_IGNORE_INDEX);
1697 buf->res_type |= CPU_TO_LE16(ICE_AQC_RES_TYPE_FLAG_SCAN_BOTTOM);
1699 status = ice_aq_alloc_free_res(hw, 1, buf, buf_len,
1700 ice_aqc_opc_alloc_res, NULL);
1702 goto ice_alloc_res_exit;
1704 ice_memcpy(res, buf->elem, sizeof(buf->elem) * num,
1705 ICE_NONDMA_TO_NONDMA);
1713 * ice_free_hw_res - free allocated HW resource
1714 * @hw: pointer to the HW struct
1715 * @type: type of resource to free
1716 * @num: number of resources
1717 * @res: pointer to array that contains the resources to free
1720 ice_free_hw_res(struct ice_hw *hw, u16 type, u16 num, u16 *res)
1722 struct ice_aqc_alloc_free_res_elem *buf;
1723 enum ice_status status;
1726 buf_len = ice_struct_size(buf, elem, num - 1);
1727 buf = (struct ice_aqc_alloc_free_res_elem *)ice_malloc(hw, buf_len);
1729 return ICE_ERR_NO_MEMORY;
1731 /* Prepare buffer to free resource. */
1732 buf->num_elems = CPU_TO_LE16(num);
1733 buf->res_type = CPU_TO_LE16(type);
1734 ice_memcpy(buf->elem, res, sizeof(buf->elem) * num,
1735 ICE_NONDMA_TO_NONDMA);
1737 status = ice_aq_alloc_free_res(hw, num, buf, buf_len,
1738 ice_aqc_opc_free_res, NULL);
1740 ice_debug(hw, ICE_DBG_SW, "CQ CMD Buffer:\n");
1747 * ice_get_num_per_func - determine number of resources per PF
1748 * @hw: pointer to the HW structure
1749 * @max: value to be evenly split between each PF
1751 * Determine the number of valid functions by going through the bitmap returned
1752 * from parsing capabilities and use this to calculate the number of resources
1753 * per PF based on the max value passed in.
1755 static u32 ice_get_num_per_func(struct ice_hw *hw, u32 max)
1759 #define ICE_CAPS_VALID_FUNCS_M 0xFF
1760 funcs = ice_hweight8(hw->dev_caps.common_cap.valid_functions &
1761 ICE_CAPS_VALID_FUNCS_M);
1770 * ice_parse_caps - parse function/device capabilities
1771 * @hw: pointer to the HW struct
1772 * @buf: pointer to a buffer containing function/device capability records
1773 * @cap_count: number of capability records in the list
1774 * @opc: type of capabilities list to parse
1776 * Helper function to parse function(0x000a)/device(0x000b) capabilities list.
1779 ice_parse_caps(struct ice_hw *hw, void *buf, u32 cap_count,
1780 enum ice_adminq_opc opc)
1782 struct ice_aqc_list_caps_elem *cap_resp;
1783 struct ice_hw_func_caps *func_p = NULL;
1784 struct ice_hw_dev_caps *dev_p = NULL;
1785 struct ice_hw_common_caps *caps;
1792 cap_resp = (struct ice_aqc_list_caps_elem *)buf;
1794 if (opc == ice_aqc_opc_list_dev_caps) {
1795 dev_p = &hw->dev_caps;
1796 caps = &dev_p->common_cap;
1798 } else if (opc == ice_aqc_opc_list_func_caps) {
1799 func_p = &hw->func_caps;
1800 caps = &func_p->common_cap;
1801 prefix = "func cap";
1803 ice_debug(hw, ICE_DBG_INIT, "wrong opcode\n");
1807 for (i = 0; caps && i < cap_count; i++, cap_resp++) {
1808 u32 logical_id = LE32_TO_CPU(cap_resp->logical_id);
1809 u32 phys_id = LE32_TO_CPU(cap_resp->phys_id);
1810 u32 number = LE32_TO_CPU(cap_resp->number);
1811 u16 cap = LE16_TO_CPU(cap_resp->cap);
1814 case ICE_AQC_CAPS_VALID_FUNCTIONS:
1815 caps->valid_functions = number;
1816 ice_debug(hw, ICE_DBG_INIT,
1817 "%s: valid_functions (bitmap) = %d\n", prefix,
1818 caps->valid_functions);
1820 /* store func count for resource management purposes */
1822 dev_p->num_funcs = ice_hweight32(number);
1824 case ICE_AQC_CAPS_VSI:
1826 dev_p->num_vsi_allocd_to_host = number;
1827 ice_debug(hw, ICE_DBG_INIT,
1828 "%s: num_vsi_allocd_to_host = %d\n",
1830 dev_p->num_vsi_allocd_to_host);
1831 } else if (func_p) {
1832 func_p->guar_num_vsi =
1833 ice_get_num_per_func(hw, ICE_MAX_VSI);
1834 ice_debug(hw, ICE_DBG_INIT,
1835 "%s: guar_num_vsi (fw) = %d\n",
1837 ice_debug(hw, ICE_DBG_INIT,
1838 "%s: guar_num_vsi = %d\n",
1839 prefix, func_p->guar_num_vsi);
1842 case ICE_AQC_CAPS_DCB:
1843 caps->dcb = (number == 1);
1844 caps->active_tc_bitmap = logical_id;
1845 caps->maxtc = phys_id;
1846 ice_debug(hw, ICE_DBG_INIT,
1847 "%s: dcb = %d\n", prefix, caps->dcb);
1848 ice_debug(hw, ICE_DBG_INIT,
1849 "%s: active_tc_bitmap = %d\n", prefix,
1850 caps->active_tc_bitmap);
1851 ice_debug(hw, ICE_DBG_INIT,
1852 "%s: maxtc = %d\n", prefix, caps->maxtc);
1854 case ICE_AQC_CAPS_RSS:
1855 caps->rss_table_size = number;
1856 caps->rss_table_entry_width = logical_id;
1857 ice_debug(hw, ICE_DBG_INIT,
1858 "%s: rss_table_size = %d\n", prefix,
1859 caps->rss_table_size);
1860 ice_debug(hw, ICE_DBG_INIT,
1861 "%s: rss_table_entry_width = %d\n", prefix,
1862 caps->rss_table_entry_width);
1864 case ICE_AQC_CAPS_RXQS:
1865 caps->num_rxq = number;
1866 caps->rxq_first_id = phys_id;
1867 ice_debug(hw, ICE_DBG_INIT,
1868 "%s: num_rxq = %d\n", prefix,
1870 ice_debug(hw, ICE_DBG_INIT,
1871 "%s: rxq_first_id = %d\n", prefix,
1872 caps->rxq_first_id);
1874 case ICE_AQC_CAPS_TXQS:
1875 caps->num_txq = number;
1876 caps->txq_first_id = phys_id;
1877 ice_debug(hw, ICE_DBG_INIT,
1878 "%s: num_txq = %d\n", prefix,
1880 ice_debug(hw, ICE_DBG_INIT,
1881 "%s: txq_first_id = %d\n", prefix,
1882 caps->txq_first_id);
1884 case ICE_AQC_CAPS_MSIX:
1885 caps->num_msix_vectors = number;
1886 caps->msix_vector_first_id = phys_id;
1887 ice_debug(hw, ICE_DBG_INIT,
1888 "%s: num_msix_vectors = %d\n", prefix,
1889 caps->num_msix_vectors);
1890 ice_debug(hw, ICE_DBG_INIT,
1891 "%s: msix_vector_first_id = %d\n", prefix,
1892 caps->msix_vector_first_id);
1894 case ICE_AQC_CAPS_FD:
1896 dev_p->num_flow_director_fltr = number;
1897 ice_debug(hw, ICE_DBG_INIT,
1898 "%s: num_flow_director_fltr = %d\n",
1900 dev_p->num_flow_director_fltr);
1904 if (hw->dcf_enabled)
1906 reg_val = rd32(hw, GLQF_FD_SIZE);
1907 val = (reg_val & GLQF_FD_SIZE_FD_GSIZE_M) >>
1908 GLQF_FD_SIZE_FD_GSIZE_S;
1909 func_p->fd_fltr_guar =
1910 ice_get_num_per_func(hw, val);
1911 val = (reg_val & GLQF_FD_SIZE_FD_BSIZE_M) >>
1912 GLQF_FD_SIZE_FD_BSIZE_S;
1913 func_p->fd_fltr_best_effort = val;
1914 ice_debug(hw, ICE_DBG_INIT,
1915 "%s: fd_fltr_guar = %d\n",
1916 prefix, func_p->fd_fltr_guar);
1917 ice_debug(hw, ICE_DBG_INIT,
1918 "%s: fd_fltr_best_effort = %d\n",
1919 prefix, func_p->fd_fltr_best_effort);
1922 case ICE_AQC_CAPS_MAX_MTU:
1923 caps->max_mtu = number;
1924 ice_debug(hw, ICE_DBG_INIT, "%s: max_mtu = %d\n",
1925 prefix, caps->max_mtu);
1928 ice_debug(hw, ICE_DBG_INIT,
1929 "%s: unknown capability[%d]: 0x%x\n", prefix,
1935 /* Re-calculate capabilities that are dependent on the number of
1936 * physical ports; i.e. some features are not supported or function
1937 * differently on devices with more than 4 ports.
1939 if (hw->dev_caps.num_funcs > 4) {
1940 /* Max 4 TCs per port */
1942 ice_debug(hw, ICE_DBG_INIT,
1943 "%s: maxtc = %d (based on #ports)\n", prefix,
1949 * ice_aq_discover_caps - query function/device capabilities
1950 * @hw: pointer to the HW struct
1951 * @buf: a virtual buffer to hold the capabilities
1952 * @buf_size: Size of the virtual buffer
1953 * @cap_count: cap count needed if AQ err==ENOMEM
1954 * @opc: capabilities type to discover - pass in the command opcode
1955 * @cd: pointer to command details structure or NULL
1957 * Get the function(0x000a)/device(0x000b) capabilities description from
1960 static enum ice_status
1961 ice_aq_discover_caps(struct ice_hw *hw, void *buf, u16 buf_size, u32 *cap_count,
1962 enum ice_adminq_opc opc, struct ice_sq_cd *cd)
1964 struct ice_aqc_list_caps *cmd;
1965 struct ice_aq_desc desc;
1966 enum ice_status status;
1968 cmd = &desc.params.get_cap;
1970 if (opc != ice_aqc_opc_list_func_caps &&
1971 opc != ice_aqc_opc_list_dev_caps)
1972 return ICE_ERR_PARAM;
1974 ice_fill_dflt_direct_cmd_desc(&desc, opc);
1976 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
1978 ice_parse_caps(hw, buf, LE32_TO_CPU(cmd->count), opc);
1979 else if (hw->adminq.sq_last_status == ICE_AQ_RC_ENOMEM)
1980 *cap_count = LE32_TO_CPU(cmd->count);
1985 * ice_discover_caps - get info about the HW
1986 * @hw: pointer to the hardware structure
1987 * @opc: capabilities type to discover - pass in the command opcode
1989 static enum ice_status
1990 ice_discover_caps(struct ice_hw *hw, enum ice_adminq_opc opc)
1992 enum ice_status status;
1997 /* The driver doesn't know how many capabilities the device will return
1998 * so the buffer size required isn't known ahead of time. The driver
1999 * starts with cbuf_len and if this turns out to be insufficient, the
2000 * device returns ICE_AQ_RC_ENOMEM and also the cap_count it needs.
2001 * The driver then allocates the buffer based on the count and retries
2002 * the operation. So it follows that the retry count is 2.
2004 #define ICE_GET_CAP_BUF_COUNT 40
2005 #define ICE_GET_CAP_RETRY_COUNT 2
2007 cap_count = ICE_GET_CAP_BUF_COUNT;
2008 retries = ICE_GET_CAP_RETRY_COUNT;
2013 cbuf_len = (u16)(cap_count *
2014 sizeof(struct ice_aqc_list_caps_elem));
2015 cbuf = ice_malloc(hw, cbuf_len);
2017 return ICE_ERR_NO_MEMORY;
2019 status = ice_aq_discover_caps(hw, cbuf, cbuf_len, &cap_count,
2023 if (!status || hw->adminq.sq_last_status != ICE_AQ_RC_ENOMEM)
2026 /* If ENOMEM is returned, try again with bigger buffer */
2027 } while (--retries);
2033 * ice_set_safe_mode_caps - Override dev/func capabilities when in safe mode
2034 * @hw: pointer to the hardware structure
2036 void ice_set_safe_mode_caps(struct ice_hw *hw)
2038 struct ice_hw_func_caps *func_caps = &hw->func_caps;
2039 struct ice_hw_dev_caps *dev_caps = &hw->dev_caps;
2040 u32 valid_func, rxq_first_id, txq_first_id;
2041 u32 msix_vector_first_id, max_mtu;
2044 /* cache some func_caps values that should be restored after memset */
2045 valid_func = func_caps->common_cap.valid_functions;
2046 txq_first_id = func_caps->common_cap.txq_first_id;
2047 rxq_first_id = func_caps->common_cap.rxq_first_id;
2048 msix_vector_first_id = func_caps->common_cap.msix_vector_first_id;
2049 max_mtu = func_caps->common_cap.max_mtu;
2051 /* unset func capabilities */
2052 memset(func_caps, 0, sizeof(*func_caps));
2054 /* restore cached values */
2055 func_caps->common_cap.valid_functions = valid_func;
2056 func_caps->common_cap.txq_first_id = txq_first_id;
2057 func_caps->common_cap.rxq_first_id = rxq_first_id;
2058 func_caps->common_cap.msix_vector_first_id = msix_vector_first_id;
2059 func_caps->common_cap.max_mtu = max_mtu;
2061 /* one Tx and one Rx queue in safe mode */
2062 func_caps->common_cap.num_rxq = 1;
2063 func_caps->common_cap.num_txq = 1;
2065 /* two MSIX vectors, one for traffic and one for misc causes */
2066 func_caps->common_cap.num_msix_vectors = 2;
2067 func_caps->guar_num_vsi = 1;
2069 /* cache some dev_caps values that should be restored after memset */
2070 valid_func = dev_caps->common_cap.valid_functions;
2071 txq_first_id = dev_caps->common_cap.txq_first_id;
2072 rxq_first_id = dev_caps->common_cap.rxq_first_id;
2073 msix_vector_first_id = dev_caps->common_cap.msix_vector_first_id;
2074 max_mtu = dev_caps->common_cap.max_mtu;
2075 num_funcs = dev_caps->num_funcs;
2077 /* unset dev capabilities */
2078 memset(dev_caps, 0, sizeof(*dev_caps));
2080 /* restore cached values */
2081 dev_caps->common_cap.valid_functions = valid_func;
2082 dev_caps->common_cap.txq_first_id = txq_first_id;
2083 dev_caps->common_cap.rxq_first_id = rxq_first_id;
2084 dev_caps->common_cap.msix_vector_first_id = msix_vector_first_id;
2085 dev_caps->common_cap.max_mtu = max_mtu;
2086 dev_caps->num_funcs = num_funcs;
2088 /* one Tx and one Rx queue per function in safe mode */
2089 dev_caps->common_cap.num_rxq = num_funcs;
2090 dev_caps->common_cap.num_txq = num_funcs;
2092 /* two MSIX vectors per function */
2093 dev_caps->common_cap.num_msix_vectors = 2 * num_funcs;
2097 * ice_get_caps - get info about the HW
2098 * @hw: pointer to the hardware structure
2100 enum ice_status ice_get_caps(struct ice_hw *hw)
2102 enum ice_status status;
2104 status = ice_discover_caps(hw, ice_aqc_opc_list_dev_caps);
2106 status = ice_discover_caps(hw, ice_aqc_opc_list_func_caps);
2112 * ice_aq_manage_mac_write - manage MAC address write command
2113 * @hw: pointer to the HW struct
2114 * @mac_addr: MAC address to be written as LAA/LAA+WoL/Port address
2115 * @flags: flags to control write behavior
2116 * @cd: pointer to command details structure or NULL
2118 * This function is used to write MAC address to the NVM (0x0108).
2121 ice_aq_manage_mac_write(struct ice_hw *hw, const u8 *mac_addr, u8 flags,
2122 struct ice_sq_cd *cd)
2124 struct ice_aqc_manage_mac_write *cmd;
2125 struct ice_aq_desc desc;
2127 cmd = &desc.params.mac_write;
2128 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_manage_mac_write);
2131 ice_memcpy(cmd->mac_addr, mac_addr, ETH_ALEN, ICE_NONDMA_TO_DMA);
2133 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
2137 * ice_aq_clear_pxe_mode
2138 * @hw: pointer to the HW struct
2140 * Tell the firmware that the driver is taking over from PXE (0x0110).
2142 static enum ice_status ice_aq_clear_pxe_mode(struct ice_hw *hw)
2144 struct ice_aq_desc desc;
2146 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_clear_pxe_mode);
2147 desc.params.clear_pxe.rx_cnt = ICE_AQC_CLEAR_PXE_RX_CNT;
2149 return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
2153 * ice_clear_pxe_mode - clear pxe operations mode
2154 * @hw: pointer to the HW struct
2156 * Make sure all PXE mode settings are cleared, including things
2157 * like descriptor fetch/write-back mode.
2159 void ice_clear_pxe_mode(struct ice_hw *hw)
2161 if (ice_check_sq_alive(hw, &hw->adminq))
2162 ice_aq_clear_pxe_mode(hw);
2166 * ice_get_link_speed_based_on_phy_type - returns link speed
2167 * @phy_type_low: lower part of phy_type
2168 * @phy_type_high: higher part of phy_type
2170 * This helper function will convert an entry in PHY type structure
2171 * [phy_type_low, phy_type_high] to its corresponding link speed.
2172 * Note: In the structure of [phy_type_low, phy_type_high], there should
2173 * be one bit set, as this function will convert one PHY type to its
2175 * If no bit gets set, ICE_LINK_SPEED_UNKNOWN will be returned
2176 * If more than one bit gets set, ICE_LINK_SPEED_UNKNOWN will be returned
2179 ice_get_link_speed_based_on_phy_type(u64 phy_type_low, u64 phy_type_high)
2181 u16 speed_phy_type_high = ICE_AQ_LINK_SPEED_UNKNOWN;
2182 u16 speed_phy_type_low = ICE_AQ_LINK_SPEED_UNKNOWN;
2184 switch (phy_type_low) {
2185 case ICE_PHY_TYPE_LOW_100BASE_TX:
2186 case ICE_PHY_TYPE_LOW_100M_SGMII:
2187 speed_phy_type_low = ICE_AQ_LINK_SPEED_100MB;
2189 case ICE_PHY_TYPE_LOW_1000BASE_T:
2190 case ICE_PHY_TYPE_LOW_1000BASE_SX:
2191 case ICE_PHY_TYPE_LOW_1000BASE_LX:
2192 case ICE_PHY_TYPE_LOW_1000BASE_KX:
2193 case ICE_PHY_TYPE_LOW_1G_SGMII:
2194 speed_phy_type_low = ICE_AQ_LINK_SPEED_1000MB;
2196 case ICE_PHY_TYPE_LOW_2500BASE_T:
2197 case ICE_PHY_TYPE_LOW_2500BASE_X:
2198 case ICE_PHY_TYPE_LOW_2500BASE_KX:
2199 speed_phy_type_low = ICE_AQ_LINK_SPEED_2500MB;
2201 case ICE_PHY_TYPE_LOW_5GBASE_T:
2202 case ICE_PHY_TYPE_LOW_5GBASE_KR:
2203 speed_phy_type_low = ICE_AQ_LINK_SPEED_5GB;
2205 case ICE_PHY_TYPE_LOW_10GBASE_T:
2206 case ICE_PHY_TYPE_LOW_10G_SFI_DA:
2207 case ICE_PHY_TYPE_LOW_10GBASE_SR:
2208 case ICE_PHY_TYPE_LOW_10GBASE_LR:
2209 case ICE_PHY_TYPE_LOW_10GBASE_KR_CR1:
2210 case ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC:
2211 case ICE_PHY_TYPE_LOW_10G_SFI_C2C:
2212 speed_phy_type_low = ICE_AQ_LINK_SPEED_10GB;
2214 case ICE_PHY_TYPE_LOW_25GBASE_T:
2215 case ICE_PHY_TYPE_LOW_25GBASE_CR:
2216 case ICE_PHY_TYPE_LOW_25GBASE_CR_S:
2217 case ICE_PHY_TYPE_LOW_25GBASE_CR1:
2218 case ICE_PHY_TYPE_LOW_25GBASE_SR:
2219 case ICE_PHY_TYPE_LOW_25GBASE_LR:
2220 case ICE_PHY_TYPE_LOW_25GBASE_KR:
2221 case ICE_PHY_TYPE_LOW_25GBASE_KR_S:
2222 case ICE_PHY_TYPE_LOW_25GBASE_KR1:
2223 case ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC:
2224 case ICE_PHY_TYPE_LOW_25G_AUI_C2C:
2225 speed_phy_type_low = ICE_AQ_LINK_SPEED_25GB;
2227 case ICE_PHY_TYPE_LOW_40GBASE_CR4:
2228 case ICE_PHY_TYPE_LOW_40GBASE_SR4:
2229 case ICE_PHY_TYPE_LOW_40GBASE_LR4:
2230 case ICE_PHY_TYPE_LOW_40GBASE_KR4:
2231 case ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC:
2232 case ICE_PHY_TYPE_LOW_40G_XLAUI:
2233 speed_phy_type_low = ICE_AQ_LINK_SPEED_40GB;
2235 case ICE_PHY_TYPE_LOW_50GBASE_CR2:
2236 case ICE_PHY_TYPE_LOW_50GBASE_SR2:
2237 case ICE_PHY_TYPE_LOW_50GBASE_LR2:
2238 case ICE_PHY_TYPE_LOW_50GBASE_KR2:
2239 case ICE_PHY_TYPE_LOW_50G_LAUI2_AOC_ACC:
2240 case ICE_PHY_TYPE_LOW_50G_LAUI2:
2241 case ICE_PHY_TYPE_LOW_50G_AUI2_AOC_ACC:
2242 case ICE_PHY_TYPE_LOW_50G_AUI2:
2243 case ICE_PHY_TYPE_LOW_50GBASE_CP:
2244 case ICE_PHY_TYPE_LOW_50GBASE_SR:
2245 case ICE_PHY_TYPE_LOW_50GBASE_FR:
2246 case ICE_PHY_TYPE_LOW_50GBASE_LR:
2247 case ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4:
2248 case ICE_PHY_TYPE_LOW_50G_AUI1_AOC_ACC:
2249 case ICE_PHY_TYPE_LOW_50G_AUI1:
2250 speed_phy_type_low = ICE_AQ_LINK_SPEED_50GB;
2252 case ICE_PHY_TYPE_LOW_100GBASE_CR4:
2253 case ICE_PHY_TYPE_LOW_100GBASE_SR4:
2254 case ICE_PHY_TYPE_LOW_100GBASE_LR4:
2255 case ICE_PHY_TYPE_LOW_100GBASE_KR4:
2256 case ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC:
2257 case ICE_PHY_TYPE_LOW_100G_CAUI4:
2258 case ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC:
2259 case ICE_PHY_TYPE_LOW_100G_AUI4:
2260 case ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4:
2261 case ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4:
2262 case ICE_PHY_TYPE_LOW_100GBASE_CP2:
2263 case ICE_PHY_TYPE_LOW_100GBASE_SR2:
2264 case ICE_PHY_TYPE_LOW_100GBASE_DR:
2265 speed_phy_type_low = ICE_AQ_LINK_SPEED_100GB;
2268 speed_phy_type_low = ICE_AQ_LINK_SPEED_UNKNOWN;
2272 switch (phy_type_high) {
2273 case ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4:
2274 case ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC:
2275 case ICE_PHY_TYPE_HIGH_100G_CAUI2:
2276 case ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC:
2277 case ICE_PHY_TYPE_HIGH_100G_AUI2:
2278 speed_phy_type_high = ICE_AQ_LINK_SPEED_100GB;
2281 speed_phy_type_high = ICE_AQ_LINK_SPEED_UNKNOWN;
2285 if (speed_phy_type_low == ICE_AQ_LINK_SPEED_UNKNOWN &&
2286 speed_phy_type_high == ICE_AQ_LINK_SPEED_UNKNOWN)
2287 return ICE_AQ_LINK_SPEED_UNKNOWN;
2288 else if (speed_phy_type_low != ICE_AQ_LINK_SPEED_UNKNOWN &&
2289 speed_phy_type_high != ICE_AQ_LINK_SPEED_UNKNOWN)
2290 return ICE_AQ_LINK_SPEED_UNKNOWN;
2291 else if (speed_phy_type_low != ICE_AQ_LINK_SPEED_UNKNOWN &&
2292 speed_phy_type_high == ICE_AQ_LINK_SPEED_UNKNOWN)
2293 return speed_phy_type_low;
2295 return speed_phy_type_high;
2299 * ice_update_phy_type
2300 * @phy_type_low: pointer to the lower part of phy_type
2301 * @phy_type_high: pointer to the higher part of phy_type
2302 * @link_speeds_bitmap: targeted link speeds bitmap
2304 * Note: For the link_speeds_bitmap structure, you can check it at
2305 * [ice_aqc_get_link_status->link_speed]. Caller can pass in
2306 * link_speeds_bitmap include multiple speeds.
2308 * Each entry in this [phy_type_low, phy_type_high] structure will
2309 * present a certain link speed. This helper function will turn on bits
2310 * in [phy_type_low, phy_type_high] structure based on the value of
2311 * link_speeds_bitmap input parameter.
2314 ice_update_phy_type(u64 *phy_type_low, u64 *phy_type_high,
2315 u16 link_speeds_bitmap)
2322 /* We first check with low part of phy_type */
2323 for (index = 0; index <= ICE_PHY_TYPE_LOW_MAX_INDEX; index++) {
2324 pt_low = BIT_ULL(index);
2325 speed = ice_get_link_speed_based_on_phy_type(pt_low, 0);
2327 if (link_speeds_bitmap & speed)
2328 *phy_type_low |= BIT_ULL(index);
2331 /* We then check with high part of phy_type */
2332 for (index = 0; index <= ICE_PHY_TYPE_HIGH_MAX_INDEX; index++) {
2333 pt_high = BIT_ULL(index);
2334 speed = ice_get_link_speed_based_on_phy_type(0, pt_high);
2336 if (link_speeds_bitmap & speed)
2337 *phy_type_high |= BIT_ULL(index);
2342 * ice_aq_set_phy_cfg
2343 * @hw: pointer to the HW struct
2344 * @pi: port info structure of the interested logical port
2345 * @cfg: structure with PHY configuration data to be set
2346 * @cd: pointer to command details structure or NULL
2348 * Set the various PHY configuration parameters supported on the Port.
2349 * One or more of the Set PHY config parameters may be ignored in an MFP
2350 * mode as the PF may not have the privilege to set some of the PHY Config
2351 * parameters. This status will be indicated by the command response (0x0601).
2354 ice_aq_set_phy_cfg(struct ice_hw *hw, struct ice_port_info *pi,
2355 struct ice_aqc_set_phy_cfg_data *cfg, struct ice_sq_cd *cd)
2357 struct ice_aq_desc desc;
2358 enum ice_status status;
2361 return ICE_ERR_PARAM;
2363 /* Ensure that only valid bits of cfg->caps can be turned on. */
2364 if (cfg->caps & ~ICE_AQ_PHY_ENA_VALID_MASK) {
2365 ice_debug(hw, ICE_DBG_PHY,
2366 "Invalid bit is set in ice_aqc_set_phy_cfg_data->caps : 0x%x\n",
2369 cfg->caps &= ICE_AQ_PHY_ENA_VALID_MASK;
2372 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_phy_cfg);
2373 desc.params.set_phy.lport_num = pi->lport;
2374 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
2376 ice_debug(hw, ICE_DBG_LINK, "phy_type_low = 0x%llx\n",
2377 (unsigned long long)LE64_TO_CPU(cfg->phy_type_low));
2378 ice_debug(hw, ICE_DBG_LINK, "phy_type_high = 0x%llx\n",
2379 (unsigned long long)LE64_TO_CPU(cfg->phy_type_high));
2380 ice_debug(hw, ICE_DBG_LINK, "caps = 0x%x\n", cfg->caps);
2381 ice_debug(hw, ICE_DBG_LINK, "low_power_ctrl_an = 0x%x\n",
2382 cfg->low_power_ctrl_an);
2383 ice_debug(hw, ICE_DBG_LINK, "eee_cap = 0x%x\n", cfg->eee_cap);
2384 ice_debug(hw, ICE_DBG_LINK, "eeer_value = 0x%x\n", cfg->eeer_value);
2385 ice_debug(hw, ICE_DBG_LINK, "link_fec_opt = 0x%x\n", cfg->link_fec_opt);
2387 status = ice_aq_send_cmd(hw, &desc, cfg, sizeof(*cfg), cd);
2389 if (hw->adminq.sq_last_status == ICE_AQ_RC_EMODE)
2390 status = ICE_SUCCESS;
2393 pi->phy.curr_user_phy_cfg = *cfg;
2399 * ice_update_link_info - update status of the HW network link
2400 * @pi: port info structure of the interested logical port
2402 enum ice_status ice_update_link_info(struct ice_port_info *pi)
2404 struct ice_link_status *li;
2405 enum ice_status status;
2408 return ICE_ERR_PARAM;
2410 li = &pi->phy.link_info;
2412 status = ice_aq_get_link_info(pi, true, NULL, NULL);
2416 if (li->link_info & ICE_AQ_MEDIA_AVAILABLE) {
2417 struct ice_aqc_get_phy_caps_data *pcaps;
2421 pcaps = (struct ice_aqc_get_phy_caps_data *)
2422 ice_malloc(hw, sizeof(*pcaps));
2424 return ICE_ERR_NO_MEMORY;
2426 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP,
2428 if (status == ICE_SUCCESS)
2429 ice_memcpy(li->module_type, &pcaps->module_type,
2430 sizeof(li->module_type),
2431 ICE_NONDMA_TO_NONDMA);
2433 ice_free(hw, pcaps);
2440 * ice_cache_phy_user_req
2441 * @pi: port information structure
2442 * @cache_data: PHY logging data
2443 * @cache_mode: PHY logging mode
2445 * Log the user request on (FC, FEC, SPEED) for later user.
2448 ice_cache_phy_user_req(struct ice_port_info *pi,
2449 struct ice_phy_cache_mode_data cache_data,
2450 enum ice_phy_cache_mode cache_mode)
2455 switch (cache_mode) {
2457 pi->phy.curr_user_fc_req = cache_data.data.curr_user_fc_req;
2459 case ICE_SPEED_MODE:
2460 pi->phy.curr_user_speed_req =
2461 cache_data.data.curr_user_speed_req;
2464 pi->phy.curr_user_fec_req = cache_data.data.curr_user_fec_req;
2472 * ice_caps_to_fc_mode
2473 * @caps: PHY capabilities
2475 * Convert PHY FC capabilities to ice FC mode
2477 enum ice_fc_mode ice_caps_to_fc_mode(u8 caps)
2479 if (caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE &&
2480 caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)
2483 if (caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE)
2484 return ICE_FC_TX_PAUSE;
2486 if (caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)
2487 return ICE_FC_RX_PAUSE;
2493 * ice_caps_to_fec_mode
2494 * @caps: PHY capabilities
2495 * @fec_options: Link FEC options
2497 * Convert PHY FEC capabilities to ice FEC mode
2499 enum ice_fec_mode ice_caps_to_fec_mode(u8 caps, u8 fec_options)
2501 if (caps & ICE_AQC_PHY_EN_AUTO_FEC)
2502 return ICE_FEC_AUTO;
2504 if (fec_options & (ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN |
2505 ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ |
2506 ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN |
2507 ICE_AQC_PHY_FEC_25G_KR_REQ))
2508 return ICE_FEC_BASER;
2510 if (fec_options & (ICE_AQC_PHY_FEC_25G_RS_528_REQ |
2511 ICE_AQC_PHY_FEC_25G_RS_544_REQ |
2512 ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN))
2515 return ICE_FEC_NONE;
2518 static enum ice_status
2519 ice_cfg_phy_fc(struct ice_port_info *pi, struct ice_aqc_set_phy_cfg_data *cfg,
2520 enum ice_fc_mode req_mode)
2522 struct ice_aqc_get_phy_caps_data *pcaps = NULL;
2523 struct ice_phy_cache_mode_data cache_data;
2524 enum ice_status status = ICE_SUCCESS;
2525 u8 pause_mask = 0x0;
2528 return ICE_ERR_BAD_PTR;
2530 pcaps = (struct ice_aqc_get_phy_caps_data *)
2531 ice_malloc(pi->hw, sizeof(*pcaps));
2533 return ICE_ERR_NO_MEMORY;
2535 /* Cache user FC request */
2536 cache_data.data.curr_user_fc_req = req_mode;
2537 ice_cache_phy_user_req(pi, cache_data, ICE_FC_MODE);
2541 /* Query the value of FC that both the NIC and attached media
2544 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP,
2549 pause_mask |= pcaps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE;
2550 pause_mask |= pcaps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE;
2553 pause_mask |= ICE_AQC_PHY_EN_TX_LINK_PAUSE;
2554 pause_mask |= ICE_AQC_PHY_EN_RX_LINK_PAUSE;
2556 case ICE_FC_RX_PAUSE:
2557 pause_mask |= ICE_AQC_PHY_EN_RX_LINK_PAUSE;
2559 case ICE_FC_TX_PAUSE:
2560 pause_mask |= ICE_AQC_PHY_EN_TX_LINK_PAUSE;
2566 /* clear the old pause settings */
2567 cfg->caps &= ~(ICE_AQC_PHY_EN_TX_LINK_PAUSE |
2568 ICE_AQC_PHY_EN_RX_LINK_PAUSE);
2570 /* set the new capabilities */
2571 cfg->caps |= pause_mask;
2574 ice_free(pi->hw, pcaps);
2580 * @pi: port information structure
2581 * @aq_failures: pointer to status code, specific to ice_set_fc routine
2582 * @ena_auto_link_update: enable automatic link update
2584 * Set the requested flow control mode.
2587 ice_set_fc(struct ice_port_info *pi, u8 *aq_failures, bool ena_auto_link_update)
2589 struct ice_aqc_set_phy_cfg_data cfg = { 0 };
2590 struct ice_aqc_get_phy_caps_data *pcaps;
2591 enum ice_status status;
2594 if (!pi || !aq_failures)
2595 return ICE_ERR_BAD_PTR;
2599 pcaps = (struct ice_aqc_get_phy_caps_data *)
2600 ice_malloc(hw, sizeof(*pcaps));
2602 return ICE_ERR_NO_MEMORY;
2604 /* Get the current PHY config */
2605 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps,
2608 *aq_failures = ICE_SET_FC_AQ_FAIL_GET;
2612 ice_copy_phy_caps_to_cfg(pi, pcaps, &cfg);
2614 /* Configure the set phy data */
2615 status = ice_cfg_phy_fc(pi, &cfg, pi->fc.req_mode);
2617 if (status != ICE_ERR_BAD_PTR)
2618 *aq_failures = ICE_SET_FC_AQ_FAIL_GET;
2623 /* If the capabilities have changed, then set the new config */
2624 if (cfg.caps != pcaps->caps) {
2625 int retry_count, retry_max = 10;
2627 /* Auto restart link so settings take effect */
2628 if (ena_auto_link_update)
2629 cfg.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2631 status = ice_aq_set_phy_cfg(hw, pi, &cfg, NULL);
2633 *aq_failures = ICE_SET_FC_AQ_FAIL_SET;
2637 /* Update the link info
2638 * It sometimes takes a really long time for link to
2639 * come back from the atomic reset. Thus, we wait a
2642 for (retry_count = 0; retry_count < retry_max; retry_count++) {
2643 status = ice_update_link_info(pi);
2645 if (status == ICE_SUCCESS)
2648 ice_msec_delay(100, true);
2652 *aq_failures = ICE_SET_FC_AQ_FAIL_UPDATE;
2656 ice_free(hw, pcaps);
2661 * ice_phy_caps_equals_cfg
2662 * @phy_caps: PHY capabilities
2663 * @phy_cfg: PHY configuration
2665 * Helper function to determine if PHY capabilities matches PHY
2669 ice_phy_caps_equals_cfg(struct ice_aqc_get_phy_caps_data *phy_caps,
2670 struct ice_aqc_set_phy_cfg_data *phy_cfg)
2672 u8 caps_mask, cfg_mask;
2674 if (!phy_caps || !phy_cfg)
2677 /* These bits are not common between capabilities and configuration.
2678 * Do not use them to determine equality.
2680 caps_mask = ICE_AQC_PHY_CAPS_MASK & ~(ICE_AQC_PHY_AN_MODE |
2681 ICE_AQC_PHY_EN_MOD_QUAL);
2682 cfg_mask = ICE_AQ_PHY_ENA_VALID_MASK & ~ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2684 if (phy_caps->phy_type_low != phy_cfg->phy_type_low ||
2685 phy_caps->phy_type_high != phy_cfg->phy_type_high ||
2686 ((phy_caps->caps & caps_mask) != (phy_cfg->caps & cfg_mask)) ||
2687 phy_caps->low_power_ctrl_an != phy_cfg->low_power_ctrl_an ||
2688 phy_caps->eee_cap != phy_cfg->eee_cap ||
2689 phy_caps->eeer_value != phy_cfg->eeer_value ||
2690 phy_caps->link_fec_options != phy_cfg->link_fec_opt)
2697 * ice_copy_phy_caps_to_cfg - Copy PHY ability data to configuration data
2698 * @pi: port information structure
2699 * @caps: PHY ability structure to copy date from
2700 * @cfg: PHY configuration structure to copy data to
2702 * Helper function to copy AQC PHY get ability data to PHY set configuration
2706 ice_copy_phy_caps_to_cfg(struct ice_port_info *pi,
2707 struct ice_aqc_get_phy_caps_data *caps,
2708 struct ice_aqc_set_phy_cfg_data *cfg)
2710 if (!pi || !caps || !cfg)
2713 ice_memset(cfg, 0, sizeof(*cfg), ICE_NONDMA_MEM);
2714 cfg->phy_type_low = caps->phy_type_low;
2715 cfg->phy_type_high = caps->phy_type_high;
2716 cfg->caps = caps->caps;
2717 cfg->low_power_ctrl_an = caps->low_power_ctrl_an;
2718 cfg->eee_cap = caps->eee_cap;
2719 cfg->eeer_value = caps->eeer_value;
2720 cfg->link_fec_opt = caps->link_fec_options;
2721 cfg->module_compliance_enforcement =
2722 caps->module_compliance_enforcement;
2724 if (ice_fw_supports_link_override(pi->hw)) {
2725 struct ice_link_default_override_tlv tlv;
2727 if (ice_get_link_default_override(&tlv, pi))
2730 if (tlv.options & ICE_LINK_OVERRIDE_STRICT_MODE)
2731 cfg->module_compliance_enforcement |=
2732 ICE_LINK_OVERRIDE_STRICT_MODE;
2737 * ice_cfg_phy_fec - Configure PHY FEC data based on FEC mode
2738 * @pi: port information structure
2739 * @cfg: PHY configuration data to set FEC mode
2740 * @fec: FEC mode to configure
2743 ice_cfg_phy_fec(struct ice_port_info *pi, struct ice_aqc_set_phy_cfg_data *cfg,
2744 enum ice_fec_mode fec)
2746 struct ice_aqc_get_phy_caps_data *pcaps;
2747 enum ice_status status = ICE_SUCCESS;
2751 return ICE_ERR_BAD_PTR;
2755 pcaps = (struct ice_aqc_get_phy_caps_data *)
2756 ice_malloc(hw, sizeof(*pcaps));
2758 return ICE_ERR_NO_MEMORY;
2760 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP, pcaps,
2767 /* Clear RS bits, and AND BASE-R ability
2768 * bits and OR request bits.
2770 cfg->link_fec_opt &= ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN |
2771 ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN;
2772 cfg->link_fec_opt |= ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ |
2773 ICE_AQC_PHY_FEC_25G_KR_REQ;
2776 /* Clear BASE-R bits, and AND RS ability
2777 * bits and OR request bits.
2779 cfg->link_fec_opt &= ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN;
2780 cfg->link_fec_opt |= ICE_AQC_PHY_FEC_25G_RS_528_REQ |
2781 ICE_AQC_PHY_FEC_25G_RS_544_REQ;
2784 /* Clear all FEC option bits. */
2785 cfg->link_fec_opt &= ~ICE_AQC_PHY_FEC_MASK;
2788 /* AND auto FEC bit, and all caps bits. */
2789 cfg->caps &= ICE_AQC_PHY_CAPS_MASK;
2790 cfg->link_fec_opt |= pcaps->link_fec_options;
2793 status = ICE_ERR_PARAM;
2797 if (fec == ICE_FEC_AUTO && ice_fw_supports_link_override(pi->hw)) {
2798 struct ice_link_default_override_tlv tlv;
2800 if (ice_get_link_default_override(&tlv, pi))
2803 if (!(tlv.options & ICE_LINK_OVERRIDE_STRICT_MODE) &&
2804 (tlv.options & ICE_LINK_OVERRIDE_EN))
2805 cfg->link_fec_opt = tlv.fec_options;
2809 ice_free(hw, pcaps);
2815 * ice_get_link_status - get status of the HW network link
2816 * @pi: port information structure
2817 * @link_up: pointer to bool (true/false = linkup/linkdown)
2819 * Variable link_up is true if link is up, false if link is down.
2820 * The variable link_up is invalid if status is non zero. As a
2821 * result of this call, link status reporting becomes enabled
2823 enum ice_status ice_get_link_status(struct ice_port_info *pi, bool *link_up)
2825 struct ice_phy_info *phy_info;
2826 enum ice_status status = ICE_SUCCESS;
2828 if (!pi || !link_up)
2829 return ICE_ERR_PARAM;
2831 phy_info = &pi->phy;
2833 if (phy_info->get_link_info) {
2834 status = ice_update_link_info(pi);
2837 ice_debug(pi->hw, ICE_DBG_LINK,
2838 "get link status error, status = %d\n",
2842 *link_up = phy_info->link_info.link_info & ICE_AQ_LINK_UP;
2848 * ice_aq_set_link_restart_an
2849 * @pi: pointer to the port information structure
2850 * @ena_link: if true: enable link, if false: disable link
2851 * @cd: pointer to command details structure or NULL
2853 * Sets up the link and restarts the Auto-Negotiation over the link.
2856 ice_aq_set_link_restart_an(struct ice_port_info *pi, bool ena_link,
2857 struct ice_sq_cd *cd)
2859 struct ice_aqc_restart_an *cmd;
2860 struct ice_aq_desc desc;
2862 cmd = &desc.params.restart_an;
2864 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_restart_an);
2866 cmd->cmd_flags = ICE_AQC_RESTART_AN_LINK_RESTART;
2867 cmd->lport_num = pi->lport;
2869 cmd->cmd_flags |= ICE_AQC_RESTART_AN_LINK_ENABLE;
2871 cmd->cmd_flags &= ~ICE_AQC_RESTART_AN_LINK_ENABLE;
2873 return ice_aq_send_cmd(pi->hw, &desc, NULL, 0, cd);
2877 * ice_aq_set_event_mask
2878 * @hw: pointer to the HW struct
2879 * @port_num: port number of the physical function
2880 * @mask: event mask to be set
2881 * @cd: pointer to command details structure or NULL
2883 * Set event mask (0x0613)
2886 ice_aq_set_event_mask(struct ice_hw *hw, u8 port_num, u16 mask,
2887 struct ice_sq_cd *cd)
2889 struct ice_aqc_set_event_mask *cmd;
2890 struct ice_aq_desc desc;
2892 cmd = &desc.params.set_event_mask;
2894 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_event_mask);
2896 cmd->lport_num = port_num;
2898 cmd->event_mask = CPU_TO_LE16(mask);
2899 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
2903 * ice_aq_set_mac_loopback
2904 * @hw: pointer to the HW struct
2905 * @ena_lpbk: Enable or Disable loopback
2906 * @cd: pointer to command details structure or NULL
2908 * Enable/disable loopback on a given port
2911 ice_aq_set_mac_loopback(struct ice_hw *hw, bool ena_lpbk, struct ice_sq_cd *cd)
2913 struct ice_aqc_set_mac_lb *cmd;
2914 struct ice_aq_desc desc;
2916 cmd = &desc.params.set_mac_lb;
2918 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_mac_lb);
2920 cmd->lb_mode = ICE_AQ_MAC_LB_EN;
2922 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
2926 * ice_aq_set_port_id_led
2927 * @pi: pointer to the port information
2928 * @is_orig_mode: is this LED set to original mode (by the net-list)
2929 * @cd: pointer to command details structure or NULL
2931 * Set LED value for the given port (0x06e9)
2934 ice_aq_set_port_id_led(struct ice_port_info *pi, bool is_orig_mode,
2935 struct ice_sq_cd *cd)
2937 struct ice_aqc_set_port_id_led *cmd;
2938 struct ice_hw *hw = pi->hw;
2939 struct ice_aq_desc desc;
2941 cmd = &desc.params.set_port_id_led;
2943 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_port_id_led);
2946 cmd->ident_mode = ICE_AQC_PORT_IDENT_LED_ORIG;
2948 cmd->ident_mode = ICE_AQC_PORT_IDENT_LED_BLINK;
2950 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
2955 * @hw: pointer to the HW struct
2956 * @lport: bits [7:0] = logical port, bit [8] = logical port valid
2957 * @bus_addr: I2C bus address of the eeprom (typically 0xA0, 0=topo default)
2958 * @mem_addr: I2C offset. lower 8 bits for address, 8 upper bits zero padding.
2960 * @set_page: set or ignore the page
2961 * @data: pointer to data buffer to be read/written to the I2C device.
2962 * @length: 1-16 for read, 1 for write.
2963 * @write: 0 read, 1 for write.
2964 * @cd: pointer to command details structure or NULL
2966 * Read/Write SFF EEPROM (0x06EE)
2969 ice_aq_sff_eeprom(struct ice_hw *hw, u16 lport, u8 bus_addr,
2970 u16 mem_addr, u8 page, u8 set_page, u8 *data, u8 length,
2971 bool write, struct ice_sq_cd *cd)
2973 struct ice_aqc_sff_eeprom *cmd;
2974 struct ice_aq_desc desc;
2975 enum ice_status status;
2977 if (!data || (mem_addr & 0xff00))
2978 return ICE_ERR_PARAM;
2980 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_sff_eeprom);
2981 cmd = &desc.params.read_write_sff_param;
2982 desc.flags = CPU_TO_LE16(ICE_AQ_FLAG_RD | ICE_AQ_FLAG_BUF);
2983 cmd->lport_num = (u8)(lport & 0xff);
2984 cmd->lport_num_valid = (u8)((lport >> 8) & 0x01);
2985 cmd->i2c_bus_addr = CPU_TO_LE16(((bus_addr >> 1) &
2986 ICE_AQC_SFF_I2CBUS_7BIT_M) |
2988 ICE_AQC_SFF_SET_EEPROM_PAGE_S) &
2989 ICE_AQC_SFF_SET_EEPROM_PAGE_M));
2990 cmd->i2c_mem_addr = CPU_TO_LE16(mem_addr & 0xff);
2991 cmd->eeprom_page = CPU_TO_LE16((u16)page << ICE_AQC_SFF_EEPROM_PAGE_S);
2993 cmd->i2c_bus_addr |= CPU_TO_LE16(ICE_AQC_SFF_IS_WRITE);
2995 status = ice_aq_send_cmd(hw, &desc, data, length, cd);
3000 * __ice_aq_get_set_rss_lut
3001 * @hw: pointer to the hardware structure
3002 * @vsi_id: VSI FW index
3003 * @lut_type: LUT table type
3004 * @lut: pointer to the LUT buffer provided by the caller
3005 * @lut_size: size of the LUT buffer
3006 * @glob_lut_idx: global LUT index
3007 * @set: set true to set the table, false to get the table
3009 * Internal function to get (0x0B05) or set (0x0B03) RSS look up table
3011 static enum ice_status
3012 __ice_aq_get_set_rss_lut(struct ice_hw *hw, u16 vsi_id, u8 lut_type, u8 *lut,
3013 u16 lut_size, u8 glob_lut_idx, bool set)
3015 struct ice_aqc_get_set_rss_lut *cmd_resp;
3016 struct ice_aq_desc desc;
3017 enum ice_status status;
3020 cmd_resp = &desc.params.get_set_rss_lut;
3023 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_rss_lut);
3024 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
3026 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_rss_lut);
3029 cmd_resp->vsi_id = CPU_TO_LE16(((vsi_id <<
3030 ICE_AQC_GSET_RSS_LUT_VSI_ID_S) &
3031 ICE_AQC_GSET_RSS_LUT_VSI_ID_M) |
3032 ICE_AQC_GSET_RSS_LUT_VSI_VALID);
3035 case ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_VSI:
3036 case ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF:
3037 case ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_GLOBAL:
3038 flags |= ((lut_type << ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_S) &
3039 ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_M);
3042 status = ICE_ERR_PARAM;
3043 goto ice_aq_get_set_rss_lut_exit;
3046 if (lut_type == ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_GLOBAL) {
3047 flags |= ((glob_lut_idx << ICE_AQC_GSET_RSS_LUT_GLOBAL_IDX_S) &
3048 ICE_AQC_GSET_RSS_LUT_GLOBAL_IDX_M);
3051 goto ice_aq_get_set_rss_lut_send;
3052 } else if (lut_type == ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF) {
3054 goto ice_aq_get_set_rss_lut_send;
3056 goto ice_aq_get_set_rss_lut_send;
3059 /* LUT size is only valid for Global and PF table types */
3061 case ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_128:
3062 flags |= (ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_128_FLAG <<
3063 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_S) &
3064 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_M;
3066 case ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_512:
3067 flags |= (ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_512_FLAG <<
3068 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_S) &
3069 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_M;
3071 case ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K:
3072 if (lut_type == ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF) {
3073 flags |= (ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K_FLAG <<
3074 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_S) &
3075 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_M;
3080 status = ICE_ERR_PARAM;
3081 goto ice_aq_get_set_rss_lut_exit;
3084 ice_aq_get_set_rss_lut_send:
3085 cmd_resp->flags = CPU_TO_LE16(flags);
3086 status = ice_aq_send_cmd(hw, &desc, lut, lut_size, NULL);
3088 ice_aq_get_set_rss_lut_exit:
3093 * ice_aq_get_rss_lut
3094 * @hw: pointer to the hardware structure
3095 * @vsi_handle: software VSI handle
3096 * @lut_type: LUT table type
3097 * @lut: pointer to the LUT buffer provided by the caller
3098 * @lut_size: size of the LUT buffer
3100 * get the RSS lookup table, PF or VSI type
3103 ice_aq_get_rss_lut(struct ice_hw *hw, u16 vsi_handle, u8 lut_type,
3104 u8 *lut, u16 lut_size)
3106 if (!ice_is_vsi_valid(hw, vsi_handle) || !lut)
3107 return ICE_ERR_PARAM;
3109 return __ice_aq_get_set_rss_lut(hw, ice_get_hw_vsi_num(hw, vsi_handle),
3110 lut_type, lut, lut_size, 0, false);
3114 * ice_aq_set_rss_lut
3115 * @hw: pointer to the hardware structure
3116 * @vsi_handle: software VSI handle
3117 * @lut_type: LUT table type
3118 * @lut: pointer to the LUT buffer provided by the caller
3119 * @lut_size: size of the LUT buffer
3121 * set the RSS lookup table, PF or VSI type
3124 ice_aq_set_rss_lut(struct ice_hw *hw, u16 vsi_handle, u8 lut_type,
3125 u8 *lut, u16 lut_size)
3127 if (!ice_is_vsi_valid(hw, vsi_handle) || !lut)
3128 return ICE_ERR_PARAM;
3130 return __ice_aq_get_set_rss_lut(hw, ice_get_hw_vsi_num(hw, vsi_handle),
3131 lut_type, lut, lut_size, 0, true);
3135 * __ice_aq_get_set_rss_key
3136 * @hw: pointer to the HW struct
3137 * @vsi_id: VSI FW index
3138 * @key: pointer to key info struct
3139 * @set: set true to set the key, false to get the key
3141 * get (0x0B04) or set (0x0B02) the RSS key per VSI
3144 ice_status __ice_aq_get_set_rss_key(struct ice_hw *hw, u16 vsi_id,
3145 struct ice_aqc_get_set_rss_keys *key,
3148 struct ice_aqc_get_set_rss_key *cmd_resp;
3149 u16 key_size = sizeof(*key);
3150 struct ice_aq_desc desc;
3152 cmd_resp = &desc.params.get_set_rss_key;
3155 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_rss_key);
3156 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
3158 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_rss_key);
3161 cmd_resp->vsi_id = CPU_TO_LE16(((vsi_id <<
3162 ICE_AQC_GSET_RSS_KEY_VSI_ID_S) &
3163 ICE_AQC_GSET_RSS_KEY_VSI_ID_M) |
3164 ICE_AQC_GSET_RSS_KEY_VSI_VALID);
3166 return ice_aq_send_cmd(hw, &desc, key, key_size, NULL);
3170 * ice_aq_get_rss_key
3171 * @hw: pointer to the HW struct
3172 * @vsi_handle: software VSI handle
3173 * @key: pointer to key info struct
3175 * get the RSS key per VSI
3178 ice_aq_get_rss_key(struct ice_hw *hw, u16 vsi_handle,
3179 struct ice_aqc_get_set_rss_keys *key)
3181 if (!ice_is_vsi_valid(hw, vsi_handle) || !key)
3182 return ICE_ERR_PARAM;
3184 return __ice_aq_get_set_rss_key(hw, ice_get_hw_vsi_num(hw, vsi_handle),
3189 * ice_aq_set_rss_key
3190 * @hw: pointer to the HW struct
3191 * @vsi_handle: software VSI handle
3192 * @keys: pointer to key info struct
3194 * set the RSS key per VSI
3197 ice_aq_set_rss_key(struct ice_hw *hw, u16 vsi_handle,
3198 struct ice_aqc_get_set_rss_keys *keys)
3200 if (!ice_is_vsi_valid(hw, vsi_handle) || !keys)
3201 return ICE_ERR_PARAM;
3203 return __ice_aq_get_set_rss_key(hw, ice_get_hw_vsi_num(hw, vsi_handle),
3208 * ice_aq_add_lan_txq
3209 * @hw: pointer to the hardware structure
3210 * @num_qgrps: Number of added queue groups
3211 * @qg_list: list of queue groups to be added
3212 * @buf_size: size of buffer for indirect command
3213 * @cd: pointer to command details structure or NULL
3215 * Add Tx LAN queue (0x0C30)
3218 * Prior to calling add Tx LAN queue:
3219 * Initialize the following as part of the Tx queue context:
3220 * Completion queue ID if the queue uses Completion queue, Quanta profile,
3221 * Cache profile and Packet shaper profile.
3223 * After add Tx LAN queue AQ command is completed:
3224 * Interrupts should be associated with specific queues,
3225 * Association of Tx queue to Doorbell queue is not part of Add LAN Tx queue
3229 ice_aq_add_lan_txq(struct ice_hw *hw, u8 num_qgrps,
3230 struct ice_aqc_add_tx_qgrp *qg_list, u16 buf_size,
3231 struct ice_sq_cd *cd)
3233 u16 i, sum_header_size, sum_q_size = 0;
3234 struct ice_aqc_add_tx_qgrp *list;
3235 struct ice_aqc_add_txqs *cmd;
3236 struct ice_aq_desc desc;
3238 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
3240 cmd = &desc.params.add_txqs;
3242 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_add_txqs);
3245 return ICE_ERR_PARAM;
3247 if (num_qgrps > ICE_LAN_TXQ_MAX_QGRPS)
3248 return ICE_ERR_PARAM;
3250 sum_header_size = num_qgrps *
3251 (sizeof(*qg_list) - sizeof(*qg_list->txqs));
3254 for (i = 0; i < num_qgrps; i++) {
3255 struct ice_aqc_add_txqs_perq *q = list->txqs;
3257 sum_q_size += list->num_txqs * sizeof(*q);
3258 list = (struct ice_aqc_add_tx_qgrp *)(q + list->num_txqs);
3261 if (buf_size != (sum_header_size + sum_q_size))
3262 return ICE_ERR_PARAM;
3264 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
3266 cmd->num_qgrps = num_qgrps;
3268 return ice_aq_send_cmd(hw, &desc, qg_list, buf_size, cd);
3272 * ice_aq_dis_lan_txq
3273 * @hw: pointer to the hardware structure
3274 * @num_qgrps: number of groups in the list
3275 * @qg_list: the list of groups to disable
3276 * @buf_size: the total size of the qg_list buffer in bytes
3277 * @rst_src: if called due to reset, specifies the reset source
3278 * @vmvf_num: the relative VM or VF number that is undergoing the reset
3279 * @cd: pointer to command details structure or NULL
3281 * Disable LAN Tx queue (0x0C31)
3283 static enum ice_status
3284 ice_aq_dis_lan_txq(struct ice_hw *hw, u8 num_qgrps,
3285 struct ice_aqc_dis_txq_item *qg_list, u16 buf_size,
3286 enum ice_disq_rst_src rst_src, u16 vmvf_num,
3287 struct ice_sq_cd *cd)
3289 struct ice_aqc_dis_txqs *cmd;
3290 struct ice_aq_desc desc;
3291 enum ice_status status;
3294 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
3295 cmd = &desc.params.dis_txqs;
3296 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_dis_txqs);
3298 /* qg_list can be NULL only in VM/VF reset flow */
3299 if (!qg_list && !rst_src)
3300 return ICE_ERR_PARAM;
3302 if (num_qgrps > ICE_LAN_TXQ_MAX_QGRPS)
3303 return ICE_ERR_PARAM;
3305 cmd->num_entries = num_qgrps;
3307 cmd->vmvf_and_timeout = CPU_TO_LE16((5 << ICE_AQC_Q_DIS_TIMEOUT_S) &
3308 ICE_AQC_Q_DIS_TIMEOUT_M);
3312 cmd->cmd_type = ICE_AQC_Q_DIS_CMD_VM_RESET;
3313 cmd->vmvf_and_timeout |=
3314 CPU_TO_LE16(vmvf_num & ICE_AQC_Q_DIS_VMVF_NUM_M);
3321 /* flush pipe on time out */
3322 cmd->cmd_type |= ICE_AQC_Q_DIS_CMD_FLUSH_PIPE;
3323 /* If no queue group info, we are in a reset flow. Issue the AQ */
3327 /* set RD bit to indicate that command buffer is provided by the driver
3328 * and it needs to be read by the firmware
3330 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
3332 for (i = 0; i < num_qgrps; ++i) {
3333 /* Calculate the size taken up by the queue IDs in this group */
3334 sz += qg_list[i].num_qs * sizeof(qg_list[i].q_id);
3336 /* Add the size of the group header */
3337 sz += sizeof(qg_list[i]) - sizeof(qg_list[i].q_id);
3339 /* If the num of queues is even, add 2 bytes of padding */
3340 if ((qg_list[i].num_qs % 2) == 0)
3345 return ICE_ERR_PARAM;
3348 status = ice_aq_send_cmd(hw, &desc, qg_list, buf_size, cd);
3351 ice_debug(hw, ICE_DBG_SCHED, "VM%d disable failed %d\n",
3352 vmvf_num, hw->adminq.sq_last_status);
3354 ice_debug(hw, ICE_DBG_SCHED, "disable queue %d failed %d\n",
3355 LE16_TO_CPU(qg_list[0].q_id[0]),
3356 hw->adminq.sq_last_status);
3362 * ice_aq_move_recfg_lan_txq
3363 * @hw: pointer to the hardware structure
3364 * @num_qs: number of queues to move/reconfigure
3365 * @is_move: true if this operation involves node movement
3366 * @is_tc_change: true if this operation involves a TC change
3367 * @subseq_call: true if this operation is a subsequent call
3368 * @flush_pipe: on timeout, true to flush pipe, false to return EAGAIN
3369 * @timeout: timeout in units of 100 usec (valid values 0-50)
3370 * @blocked_cgds: out param, bitmap of CGDs that timed out if returning EAGAIN
3371 * @buf: struct containing src/dest TEID and per-queue info
3372 * @buf_size: size of buffer for indirect command
3373 * @txqs_moved: out param, number of queues successfully moved
3374 * @cd: pointer to command details structure or NULL
3376 * Move / Reconfigure Tx LAN queues (0x0C32)
3379 ice_aq_move_recfg_lan_txq(struct ice_hw *hw, u8 num_qs, bool is_move,
3380 bool is_tc_change, bool subseq_call, bool flush_pipe,
3381 u8 timeout, u32 *blocked_cgds,
3382 struct ice_aqc_move_txqs_data *buf, u16 buf_size,
3383 u8 *txqs_moved, struct ice_sq_cd *cd)
3385 struct ice_aqc_move_txqs *cmd;
3386 struct ice_aq_desc desc;
3387 enum ice_status status;
3389 cmd = &desc.params.move_txqs;
3390 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_move_recfg_txqs);
3392 #define ICE_LAN_TXQ_MOVE_TIMEOUT_MAX 50
3393 if (timeout > ICE_LAN_TXQ_MOVE_TIMEOUT_MAX)
3394 return ICE_ERR_PARAM;
3396 if (is_tc_change && !flush_pipe && !blocked_cgds)
3397 return ICE_ERR_PARAM;
3399 if (!is_move && !is_tc_change)
3400 return ICE_ERR_PARAM;
3402 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
3405 cmd->cmd_type |= ICE_AQC_Q_CMD_TYPE_MOVE;
3408 cmd->cmd_type |= ICE_AQC_Q_CMD_TYPE_TC_CHANGE;
3411 cmd->cmd_type |= ICE_AQC_Q_CMD_SUBSEQ_CALL;
3414 cmd->cmd_type |= ICE_AQC_Q_CMD_FLUSH_PIPE;
3416 cmd->num_qs = num_qs;
3417 cmd->timeout = ((timeout << ICE_AQC_Q_CMD_TIMEOUT_S) &
3418 ICE_AQC_Q_CMD_TIMEOUT_M);
3420 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
3422 if (!status && txqs_moved)
3423 *txqs_moved = cmd->num_qs;
3425 if (hw->adminq.sq_last_status == ICE_AQ_RC_EAGAIN &&
3426 is_tc_change && !flush_pipe)
3427 *blocked_cgds = LE32_TO_CPU(cmd->blocked_cgds);
3432 /* End of FW Admin Queue command wrappers */
3435 * ice_write_byte - write a byte to a packed context structure
3436 * @src_ctx: the context structure to read from
3437 * @dest_ctx: the context to be written to
3438 * @ce_info: a description of the struct to be filled
3441 ice_write_byte(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info)
3443 u8 src_byte, dest_byte, mask;
3447 /* copy from the next struct field */
3448 from = src_ctx + ce_info->offset;
3450 /* prepare the bits and mask */
3451 shift_width = ce_info->lsb % 8;
3452 mask = (u8)(BIT(ce_info->width) - 1);
3457 /* shift to correct alignment */
3458 mask <<= shift_width;
3459 src_byte <<= shift_width;
3461 /* get the current bits from the target bit string */
3462 dest = dest_ctx + (ce_info->lsb / 8);
3464 ice_memcpy(&dest_byte, dest, sizeof(dest_byte), ICE_DMA_TO_NONDMA);
3466 dest_byte &= ~mask; /* get the bits not changing */
3467 dest_byte |= src_byte; /* add in the new bits */
3469 /* put it all back */
3470 ice_memcpy(dest, &dest_byte, sizeof(dest_byte), ICE_NONDMA_TO_DMA);
3474 * ice_write_word - write a word to a packed context structure
3475 * @src_ctx: the context structure to read from
3476 * @dest_ctx: the context to be written to
3477 * @ce_info: a description of the struct to be filled
3480 ice_write_word(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info)
3487 /* copy from the next struct field */
3488 from = src_ctx + ce_info->offset;
3490 /* prepare the bits and mask */
3491 shift_width = ce_info->lsb % 8;
3492 mask = BIT(ce_info->width) - 1;
3494 /* don't swizzle the bits until after the mask because the mask bits
3495 * will be in a different bit position on big endian machines
3497 src_word = *(u16 *)from;
3500 /* shift to correct alignment */
3501 mask <<= shift_width;
3502 src_word <<= shift_width;
3504 /* get the current bits from the target bit string */
3505 dest = dest_ctx + (ce_info->lsb / 8);
3507 ice_memcpy(&dest_word, dest, sizeof(dest_word), ICE_DMA_TO_NONDMA);
3509 dest_word &= ~(CPU_TO_LE16(mask)); /* get the bits not changing */
3510 dest_word |= CPU_TO_LE16(src_word); /* add in the new bits */
3512 /* put it all back */
3513 ice_memcpy(dest, &dest_word, sizeof(dest_word), ICE_NONDMA_TO_DMA);
3517 * ice_write_dword - write a dword to a packed context structure
3518 * @src_ctx: the context structure to read from
3519 * @dest_ctx: the context to be written to
3520 * @ce_info: a description of the struct to be filled
3523 ice_write_dword(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info)
3525 u32 src_dword, mask;
3530 /* copy from the next struct field */
3531 from = src_ctx + ce_info->offset;
3533 /* prepare the bits and mask */
3534 shift_width = ce_info->lsb % 8;
3536 /* if the field width is exactly 32 on an x86 machine, then the shift
3537 * operation will not work because the SHL instructions count is masked
3538 * to 5 bits so the shift will do nothing
3540 if (ce_info->width < 32)
3541 mask = BIT(ce_info->width) - 1;
3545 /* don't swizzle the bits until after the mask because the mask bits
3546 * will be in a different bit position on big endian machines
3548 src_dword = *(u32 *)from;
3551 /* shift to correct alignment */
3552 mask <<= shift_width;
3553 src_dword <<= shift_width;
3555 /* get the current bits from the target bit string */
3556 dest = dest_ctx + (ce_info->lsb / 8);
3558 ice_memcpy(&dest_dword, dest, sizeof(dest_dword), ICE_DMA_TO_NONDMA);
3560 dest_dword &= ~(CPU_TO_LE32(mask)); /* get the bits not changing */
3561 dest_dword |= CPU_TO_LE32(src_dword); /* add in the new bits */
3563 /* put it all back */
3564 ice_memcpy(dest, &dest_dword, sizeof(dest_dword), ICE_NONDMA_TO_DMA);
3568 * ice_write_qword - write a qword to a packed context structure
3569 * @src_ctx: the context structure to read from
3570 * @dest_ctx: the context to be written to
3571 * @ce_info: a description of the struct to be filled
3574 ice_write_qword(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info)
3576 u64 src_qword, mask;
3581 /* copy from the next struct field */
3582 from = src_ctx + ce_info->offset;
3584 /* prepare the bits and mask */
3585 shift_width = ce_info->lsb % 8;
3587 /* if the field width is exactly 64 on an x86 machine, then the shift
3588 * operation will not work because the SHL instructions count is masked
3589 * to 6 bits so the shift will do nothing
3591 if (ce_info->width < 64)
3592 mask = BIT_ULL(ce_info->width) - 1;
3596 /* don't swizzle the bits until after the mask because the mask bits
3597 * will be in a different bit position on big endian machines
3599 src_qword = *(u64 *)from;
3602 /* shift to correct alignment */
3603 mask <<= shift_width;
3604 src_qword <<= shift_width;
3606 /* get the current bits from the target bit string */
3607 dest = dest_ctx + (ce_info->lsb / 8);
3609 ice_memcpy(&dest_qword, dest, sizeof(dest_qword), ICE_DMA_TO_NONDMA);
3611 dest_qword &= ~(CPU_TO_LE64(mask)); /* get the bits not changing */
3612 dest_qword |= CPU_TO_LE64(src_qword); /* add in the new bits */
3614 /* put it all back */
3615 ice_memcpy(dest, &dest_qword, sizeof(dest_qword), ICE_NONDMA_TO_DMA);
3619 * ice_set_ctx - set context bits in packed structure
3620 * @hw: pointer to the hardware structure
3621 * @src_ctx: pointer to a generic non-packed context structure
3622 * @dest_ctx: pointer to memory for the packed structure
3623 * @ce_info: a description of the structure to be transformed
3626 ice_set_ctx(struct ice_hw *hw, u8 *src_ctx, u8 *dest_ctx,
3627 const struct ice_ctx_ele *ce_info)
3631 for (f = 0; ce_info[f].width; f++) {
3632 /* We have to deal with each element of the FW response
3633 * using the correct size so that we are correct regardless
3634 * of the endianness of the machine.
3636 if (ce_info[f].width > (ce_info[f].size_of * BITS_PER_BYTE)) {
3637 ice_debug(hw, ICE_DBG_QCTX,
3638 "Field %d width of %d bits larger than size of %d byte(s) ... skipping write\n",
3639 f, ce_info[f].width, ce_info[f].size_of);
3642 switch (ce_info[f].size_of) {
3644 ice_write_byte(src_ctx, dest_ctx, &ce_info[f]);
3647 ice_write_word(src_ctx, dest_ctx, &ce_info[f]);
3650 ice_write_dword(src_ctx, dest_ctx, &ce_info[f]);
3653 ice_write_qword(src_ctx, dest_ctx, &ce_info[f]);
3656 return ICE_ERR_INVAL_SIZE;
3664 * ice_read_byte - read context byte into struct
3665 * @src_ctx: the context structure to read from
3666 * @dest_ctx: the context to be written to
3667 * @ce_info: a description of the struct to be filled
3670 ice_read_byte(u8 *src_ctx, u8 *dest_ctx, struct ice_ctx_ele *ce_info)
3676 /* prepare the bits and mask */
3677 shift_width = ce_info->lsb % 8;
3678 mask = (u8)(BIT(ce_info->width) - 1);
3680 /* shift to correct alignment */
3681 mask <<= shift_width;
3683 /* get the current bits from the src bit string */
3684 src = src_ctx + (ce_info->lsb / 8);
3686 ice_memcpy(&dest_byte, src, sizeof(dest_byte), ICE_DMA_TO_NONDMA);
3688 dest_byte &= ~(mask);
3690 dest_byte >>= shift_width;
3692 /* get the address from the struct field */
3693 target = dest_ctx + ce_info->offset;
3695 /* put it back in the struct */
3696 ice_memcpy(target, &dest_byte, sizeof(dest_byte), ICE_NONDMA_TO_DMA);
3700 * ice_read_word - read context word into struct
3701 * @src_ctx: the context structure to read from
3702 * @dest_ctx: the context to be written to
3703 * @ce_info: a description of the struct to be filled
3706 ice_read_word(u8 *src_ctx, u8 *dest_ctx, struct ice_ctx_ele *ce_info)
3708 u16 dest_word, mask;
3713 /* prepare the bits and mask */
3714 shift_width = ce_info->lsb % 8;
3715 mask = BIT(ce_info->width) - 1;
3717 /* shift to correct alignment */
3718 mask <<= shift_width;
3720 /* get the current bits from the src bit string */
3721 src = src_ctx + (ce_info->lsb / 8);
3723 ice_memcpy(&src_word, src, sizeof(src_word), ICE_DMA_TO_NONDMA);
3725 /* the data in the memory is stored as little endian so mask it
3728 src_word &= ~(CPU_TO_LE16(mask));
3730 /* get the data back into host order before shifting */
3731 dest_word = LE16_TO_CPU(src_word);
3733 dest_word >>= shift_width;
3735 /* get the address from the struct field */
3736 target = dest_ctx + ce_info->offset;
3738 /* put it back in the struct */
3739 ice_memcpy(target, &dest_word, sizeof(dest_word), ICE_NONDMA_TO_DMA);
3743 * ice_read_dword - read context dword into struct
3744 * @src_ctx: the context structure to read from
3745 * @dest_ctx: the context to be written to
3746 * @ce_info: a description of the struct to be filled
3749 ice_read_dword(u8 *src_ctx, u8 *dest_ctx, struct ice_ctx_ele *ce_info)
3751 u32 dest_dword, mask;
3756 /* prepare the bits and mask */
3757 shift_width = ce_info->lsb % 8;
3759 /* if the field width is exactly 32 on an x86 machine, then the shift
3760 * operation will not work because the SHL instructions count is masked
3761 * to 5 bits so the shift will do nothing
3763 if (ce_info->width < 32)
3764 mask = BIT(ce_info->width) - 1;
3768 /* shift to correct alignment */
3769 mask <<= shift_width;
3771 /* get the current bits from the src bit string */
3772 src = src_ctx + (ce_info->lsb / 8);
3774 ice_memcpy(&src_dword, src, sizeof(src_dword), ICE_DMA_TO_NONDMA);
3776 /* the data in the memory is stored as little endian so mask it
3779 src_dword &= ~(CPU_TO_LE32(mask));
3781 /* get the data back into host order before shifting */
3782 dest_dword = LE32_TO_CPU(src_dword);
3784 dest_dword >>= shift_width;
3786 /* get the address from the struct field */
3787 target = dest_ctx + ce_info->offset;
3789 /* put it back in the struct */
3790 ice_memcpy(target, &dest_dword, sizeof(dest_dword), ICE_NONDMA_TO_DMA);
3794 * ice_read_qword - read context qword into struct
3795 * @src_ctx: the context structure to read from
3796 * @dest_ctx: the context to be written to
3797 * @ce_info: a description of the struct to be filled
3800 ice_read_qword(u8 *src_ctx, u8 *dest_ctx, struct ice_ctx_ele *ce_info)
3802 u64 dest_qword, mask;
3807 /* prepare the bits and mask */
3808 shift_width = ce_info->lsb % 8;
3810 /* if the field width is exactly 64 on an x86 machine, then the shift
3811 * operation will not work because the SHL instructions count is masked
3812 * to 6 bits so the shift will do nothing
3814 if (ce_info->width < 64)
3815 mask = BIT_ULL(ce_info->width) - 1;
3819 /* shift to correct alignment */
3820 mask <<= shift_width;
3822 /* get the current bits from the src bit string */
3823 src = src_ctx + (ce_info->lsb / 8);
3825 ice_memcpy(&src_qword, src, sizeof(src_qword), ICE_DMA_TO_NONDMA);
3827 /* the data in the memory is stored as little endian so mask it
3830 src_qword &= ~(CPU_TO_LE64(mask));
3832 /* get the data back into host order before shifting */
3833 dest_qword = LE64_TO_CPU(src_qword);
3835 dest_qword >>= shift_width;
3837 /* get the address from the struct field */
3838 target = dest_ctx + ce_info->offset;
3840 /* put it back in the struct */
3841 ice_memcpy(target, &dest_qword, sizeof(dest_qword), ICE_NONDMA_TO_DMA);
3845 * ice_get_ctx - extract context bits from a packed structure
3846 * @src_ctx: pointer to a generic packed context structure
3847 * @dest_ctx: pointer to a generic non-packed context structure
3848 * @ce_info: a description of the structure to be read from
3851 ice_get_ctx(u8 *src_ctx, u8 *dest_ctx, struct ice_ctx_ele *ce_info)
3855 for (f = 0; ce_info[f].width; f++) {
3856 switch (ce_info[f].size_of) {
3858 ice_read_byte(src_ctx, dest_ctx, &ce_info[f]);
3861 ice_read_word(src_ctx, dest_ctx, &ce_info[f]);
3864 ice_read_dword(src_ctx, dest_ctx, &ce_info[f]);
3867 ice_read_qword(src_ctx, dest_ctx, &ce_info[f]);
3870 /* nothing to do, just keep going */
3879 * ice_get_lan_q_ctx - get the LAN queue context for the given VSI and TC
3880 * @hw: pointer to the HW struct
3881 * @vsi_handle: software VSI handle
3883 * @q_handle: software queue handle
3886 ice_get_lan_q_ctx(struct ice_hw *hw, u16 vsi_handle, u8 tc, u16 q_handle)
3888 struct ice_vsi_ctx *vsi;
3889 struct ice_q_ctx *q_ctx;
3891 vsi = ice_get_vsi_ctx(hw, vsi_handle);
3894 if (q_handle >= vsi->num_lan_q_entries[tc])
3896 if (!vsi->lan_q_ctx[tc])
3898 q_ctx = vsi->lan_q_ctx[tc];
3899 return &q_ctx[q_handle];
3904 * @pi: port information structure
3905 * @vsi_handle: software VSI handle
3907 * @q_handle: software queue handle
3908 * @num_qgrps: Number of added queue groups
3909 * @buf: list of queue groups to be added
3910 * @buf_size: size of buffer for indirect command
3911 * @cd: pointer to command details structure or NULL
3913 * This function adds one LAN queue
3916 ice_ena_vsi_txq(struct ice_port_info *pi, u16 vsi_handle, u8 tc, u16 q_handle,
3917 u8 num_qgrps, struct ice_aqc_add_tx_qgrp *buf, u16 buf_size,
3918 struct ice_sq_cd *cd)
3920 struct ice_aqc_txsched_elem_data node = { 0 };
3921 struct ice_sched_node *parent;
3922 struct ice_q_ctx *q_ctx;
3923 enum ice_status status;
3926 if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
3929 if (num_qgrps > 1 || buf->num_txqs > 1)
3930 return ICE_ERR_MAX_LIMIT;
3934 if (!ice_is_vsi_valid(hw, vsi_handle))
3935 return ICE_ERR_PARAM;
3937 ice_acquire_lock(&pi->sched_lock);
3939 q_ctx = ice_get_lan_q_ctx(hw, vsi_handle, tc, q_handle);
3941 ice_debug(hw, ICE_DBG_SCHED, "Enaq: invalid queue handle %d\n",
3943 status = ICE_ERR_PARAM;
3947 /* find a parent node */
3948 parent = ice_sched_get_free_qparent(pi, vsi_handle, tc,
3949 ICE_SCHED_NODE_OWNER_LAN);
3951 status = ICE_ERR_PARAM;
3955 buf->parent_teid = parent->info.node_teid;
3956 node.parent_teid = parent->info.node_teid;
3957 /* Mark that the values in the "generic" section as valid. The default
3958 * value in the "generic" section is zero. This means that :
3959 * - Scheduling mode is Bytes Per Second (BPS), indicated by Bit 0.
3960 * - 0 priority among siblings, indicated by Bit 1-3.
3961 * - WFQ, indicated by Bit 4.
3962 * - 0 Adjustment value is used in PSM credit update flow, indicated by
3964 * - Bit 7 is reserved.
3965 * Without setting the generic section as valid in valid_sections, the
3966 * Admin queue command will fail with error code ICE_AQ_RC_EINVAL.
3968 buf->txqs[0].info.valid_sections = ICE_AQC_ELEM_VALID_GENERIC;
3970 /* add the LAN queue */
3971 status = ice_aq_add_lan_txq(hw, num_qgrps, buf, buf_size, cd);
3972 if (status != ICE_SUCCESS) {
3973 ice_debug(hw, ICE_DBG_SCHED, "enable queue %d failed %d\n",
3974 LE16_TO_CPU(buf->txqs[0].txq_id),
3975 hw->adminq.sq_last_status);
3979 node.node_teid = buf->txqs[0].q_teid;
3980 node.data.elem_type = ICE_AQC_ELEM_TYPE_LEAF;
3981 q_ctx->q_handle = q_handle;
3982 q_ctx->q_teid = LE32_TO_CPU(node.node_teid);
3984 /* add a leaf node into scheduler tree queue layer */
3985 status = ice_sched_add_node(pi, hw->num_tx_sched_layers - 1, &node);
3987 status = ice_sched_replay_q_bw(pi, q_ctx);
3990 ice_release_lock(&pi->sched_lock);
3996 * @pi: port information structure
3997 * @vsi_handle: software VSI handle
3999 * @num_queues: number of queues
4000 * @q_handles: pointer to software queue handle array
4001 * @q_ids: pointer to the q_id array
4002 * @q_teids: pointer to queue node teids
4003 * @rst_src: if called due to reset, specifies the reset source
4004 * @vmvf_num: the relative VM or VF number that is undergoing the reset
4005 * @cd: pointer to command details structure or NULL
4007 * This function removes queues and their corresponding nodes in SW DB
4010 ice_dis_vsi_txq(struct ice_port_info *pi, u16 vsi_handle, u8 tc, u8 num_queues,
4011 u16 *q_handles, u16 *q_ids, u32 *q_teids,
4012 enum ice_disq_rst_src rst_src, u16 vmvf_num,
4013 struct ice_sq_cd *cd)
4015 enum ice_status status = ICE_ERR_DOES_NOT_EXIST;
4016 struct ice_aqc_dis_txq_item qg_list;
4017 struct ice_q_ctx *q_ctx;
4020 if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
4024 /* if queue is disabled already yet the disable queue command
4025 * has to be sent to complete the VF reset, then call
4026 * ice_aq_dis_lan_txq without any queue information
4029 return ice_aq_dis_lan_txq(pi->hw, 0, NULL, 0, rst_src,
4034 ice_acquire_lock(&pi->sched_lock);
4036 for (i = 0; i < num_queues; i++) {
4037 struct ice_sched_node *node;
4039 node = ice_sched_find_node_by_teid(pi->root, q_teids[i]);
4042 q_ctx = ice_get_lan_q_ctx(pi->hw, vsi_handle, tc, q_handles[i]);
4044 ice_debug(pi->hw, ICE_DBG_SCHED, "invalid queue handle%d\n",
4048 if (q_ctx->q_handle != q_handles[i]) {
4049 ice_debug(pi->hw, ICE_DBG_SCHED, "Err:handles %d %d\n",
4050 q_ctx->q_handle, q_handles[i]);
4053 qg_list.parent_teid = node->info.parent_teid;
4055 qg_list.q_id[0] = CPU_TO_LE16(q_ids[i]);
4056 status = ice_aq_dis_lan_txq(pi->hw, 1, &qg_list,
4057 sizeof(qg_list), rst_src, vmvf_num,
4060 if (status != ICE_SUCCESS)
4062 ice_free_sched_node(pi, node);
4063 q_ctx->q_handle = ICE_INVAL_Q_HANDLE;
4065 ice_release_lock(&pi->sched_lock);
4070 * ice_cfg_vsi_qs - configure the new/existing VSI queues
4071 * @pi: port information structure
4072 * @vsi_handle: software VSI handle
4073 * @tc_bitmap: TC bitmap
4074 * @maxqs: max queues array per TC
4075 * @owner: LAN or RDMA
4077 * This function adds/updates the VSI queues per TC.
4079 static enum ice_status
4080 ice_cfg_vsi_qs(struct ice_port_info *pi, u16 vsi_handle, u16 tc_bitmap,
4081 u16 *maxqs, u8 owner)
4083 enum ice_status status = ICE_SUCCESS;
4086 if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
4089 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
4090 return ICE_ERR_PARAM;
4092 ice_acquire_lock(&pi->sched_lock);
4094 ice_for_each_traffic_class(i) {
4095 /* configuration is possible only if TC node is present */
4096 if (!ice_sched_get_tc_node(pi, i))
4099 status = ice_sched_cfg_vsi(pi, vsi_handle, i, maxqs[i], owner,
4100 ice_is_tc_ena(tc_bitmap, i));
4105 ice_release_lock(&pi->sched_lock);
4110 * ice_cfg_vsi_lan - configure VSI LAN queues
4111 * @pi: port information structure
4112 * @vsi_handle: software VSI handle
4113 * @tc_bitmap: TC bitmap
4114 * @max_lanqs: max LAN queues array per TC
4116 * This function adds/updates the VSI LAN queues per TC.
4119 ice_cfg_vsi_lan(struct ice_port_info *pi, u16 vsi_handle, u16 tc_bitmap,
4122 return ice_cfg_vsi_qs(pi, vsi_handle, tc_bitmap, max_lanqs,
4123 ICE_SCHED_NODE_OWNER_LAN);
4127 * ice_is_main_vsi - checks whether the VSI is main VSI
4128 * @hw: pointer to the HW struct
4129 * @vsi_handle: VSI handle
4131 * Checks whether the VSI is the main VSI (the first PF VSI created on
4134 static bool ice_is_main_vsi(struct ice_hw *hw, u16 vsi_handle)
4136 return vsi_handle == ICE_MAIN_VSI_HANDLE && hw->vsi_ctx[vsi_handle];
4140 * ice_replay_pre_init - replay pre initialization
4141 * @hw: pointer to the HW struct
4142 * @sw: pointer to switch info struct for which function initializes filters
4144 * Initializes required config data for VSI, FD, ACL, and RSS before replay.
4146 static enum ice_status
4147 ice_replay_pre_init(struct ice_hw *hw, struct ice_switch_info *sw)
4151 /* Delete old entries from replay filter list head if there is any */
4152 ice_rm_sw_replay_rule_info(hw, sw);
4153 /* In start of replay, move entries into replay_rules list, it
4154 * will allow adding rules entries back to filt_rules list,
4155 * which is operational list.
4157 for (i = 0; i < ICE_MAX_NUM_RECIPES; i++)
4158 LIST_REPLACE_INIT(&sw->recp_list[i].filt_rules,
4159 &sw->recp_list[i].filt_replay_rules);
4160 ice_sched_replay_agg_vsi_preinit(hw);
4162 return ice_sched_replay_tc_node_bw(hw->port_info);
4166 * ice_replay_vsi - replay VSI configuration
4167 * @hw: pointer to the HW struct
4168 * @vsi_handle: driver VSI handle
4170 * Restore all VSI configuration after reset. It is required to call this
4171 * function with main VSI first.
4173 enum ice_status ice_replay_vsi(struct ice_hw *hw, u16 vsi_handle)
4175 struct ice_switch_info *sw = hw->switch_info;
4176 struct ice_port_info *pi = hw->port_info;
4177 enum ice_status status;
4179 if (!ice_is_vsi_valid(hw, vsi_handle))
4180 return ICE_ERR_PARAM;
4182 /* Replay pre-initialization if there is any */
4183 if (ice_is_main_vsi(hw, vsi_handle)) {
4184 status = ice_replay_pre_init(hw, sw);
4188 /* Replay per VSI all RSS configurations */
4189 status = ice_replay_rss_cfg(hw, vsi_handle);
4192 /* Replay per VSI all filters */
4193 status = ice_replay_vsi_all_fltr(hw, pi, vsi_handle);
4195 status = ice_replay_vsi_agg(hw, vsi_handle);
4200 * ice_replay_post - post replay configuration cleanup
4201 * @hw: pointer to the HW struct
4203 * Post replay cleanup.
4205 void ice_replay_post(struct ice_hw *hw)
4207 /* Delete old entries from replay filter list head */
4208 ice_rm_all_sw_replay_rule_info(hw);
4209 ice_sched_replay_agg(hw);
4213 * ice_stat_update40 - read 40 bit stat from the chip and update stat values
4214 * @hw: ptr to the hardware info
4215 * @reg: offset of 64 bit HW register to read from
4216 * @prev_stat_loaded: bool to specify if previous stats are loaded
4217 * @prev_stat: ptr to previous loaded stat value
4218 * @cur_stat: ptr to current stat value
4221 ice_stat_update40(struct ice_hw *hw, u32 reg, bool prev_stat_loaded,
4222 u64 *prev_stat, u64 *cur_stat)
4224 u64 new_data = rd64(hw, reg) & (BIT_ULL(40) - 1);
4226 /* device stats are not reset at PFR, they likely will not be zeroed
4227 * when the driver starts. Thus, save the value from the first read
4228 * without adding to the statistic value so that we report stats which
4229 * count up from zero.
4231 if (!prev_stat_loaded) {
4232 *prev_stat = new_data;
4236 /* Calculate the difference between the new and old values, and then
4237 * add it to the software stat value.
4239 if (new_data >= *prev_stat)
4240 *cur_stat += new_data - *prev_stat;
4242 /* to manage the potential roll-over */
4243 *cur_stat += (new_data + BIT_ULL(40)) - *prev_stat;
4245 /* Update the previously stored value to prepare for next read */
4246 *prev_stat = new_data;
4250 * ice_stat_update32 - read 32 bit stat from the chip and update stat values
4251 * @hw: ptr to the hardware info
4252 * @reg: offset of HW register to read from
4253 * @prev_stat_loaded: bool to specify if previous stats are loaded
4254 * @prev_stat: ptr to previous loaded stat value
4255 * @cur_stat: ptr to current stat value
4258 ice_stat_update32(struct ice_hw *hw, u32 reg, bool prev_stat_loaded,
4259 u64 *prev_stat, u64 *cur_stat)
4263 new_data = rd32(hw, reg);
4265 /* device stats are not reset at PFR, they likely will not be zeroed
4266 * when the driver starts. Thus, save the value from the first read
4267 * without adding to the statistic value so that we report stats which
4268 * count up from zero.
4270 if (!prev_stat_loaded) {
4271 *prev_stat = new_data;
4275 /* Calculate the difference between the new and old values, and then
4276 * add it to the software stat value.
4278 if (new_data >= *prev_stat)
4279 *cur_stat += new_data - *prev_stat;
4281 /* to manage the potential roll-over */
4282 *cur_stat += (new_data + BIT_ULL(32)) - *prev_stat;
4284 /* Update the previously stored value to prepare for next read */
4285 *prev_stat = new_data;
4289 * ice_stat_update_repc - read GLV_REPC stats from chip and update stat values
4290 * @hw: ptr to the hardware info
4291 * @vsi_handle: VSI handle
4292 * @prev_stat_loaded: bool to specify if the previous stat values are loaded
4293 * @cur_stats: ptr to current stats structure
4295 * The GLV_REPC statistic register actually tracks two 16bit statistics, and
4296 * thus cannot be read using the normal ice_stat_update32 function.
4298 * Read the GLV_REPC register associated with the given VSI, and update the
4299 * rx_no_desc and rx_error values in the ice_eth_stats structure.
4301 * Because the statistics in GLV_REPC stick at 0xFFFF, the register must be
4302 * cleared each time it's read.
4304 * Note that the GLV_RDPC register also counts the causes that would trigger
4305 * GLV_REPC. However, it does not give the finer grained detail about why the
4306 * packets are being dropped. The GLV_REPC values can be used to distinguish
4307 * whether Rx packets are dropped due to errors or due to no available
4311 ice_stat_update_repc(struct ice_hw *hw, u16 vsi_handle, bool prev_stat_loaded,
4312 struct ice_eth_stats *cur_stats)
4314 u16 vsi_num, no_desc, error_cnt;
4317 if (!ice_is_vsi_valid(hw, vsi_handle))
4320 vsi_num = ice_get_hw_vsi_num(hw, vsi_handle);
4322 /* If we haven't loaded stats yet, just clear the current value */
4323 if (!prev_stat_loaded) {
4324 wr32(hw, GLV_REPC(vsi_num), 0);
4328 repc = rd32(hw, GLV_REPC(vsi_num));
4329 no_desc = (repc & GLV_REPC_NO_DESC_CNT_M) >> GLV_REPC_NO_DESC_CNT_S;
4330 error_cnt = (repc & GLV_REPC_ERROR_CNT_M) >> GLV_REPC_ERROR_CNT_S;
4332 /* Clear the count by writing to the stats register */
4333 wr32(hw, GLV_REPC(vsi_num), 0);
4335 cur_stats->rx_no_desc += no_desc;
4336 cur_stats->rx_errors += error_cnt;
4340 * ice_sched_query_elem - query element information from HW
4341 * @hw: pointer to the HW struct
4342 * @node_teid: node TEID to be queried
4343 * @buf: buffer to element information
4345 * This function queries HW element information
4348 ice_sched_query_elem(struct ice_hw *hw, u32 node_teid,
4349 struct ice_aqc_get_elem *buf)
4351 u16 buf_size, num_elem_ret = 0;
4352 enum ice_status status;
4354 buf_size = sizeof(*buf);
4355 ice_memset(buf, 0, buf_size, ICE_NONDMA_MEM);
4356 buf->generic[0].node_teid = CPU_TO_LE32(node_teid);
4357 status = ice_aq_query_sched_elems(hw, 1, buf, buf_size, &num_elem_ret,
4359 if (status != ICE_SUCCESS || num_elem_ret != 1)
4360 ice_debug(hw, ICE_DBG_SCHED, "query element failed\n");
4365 * ice_get_fw_mode - returns FW mode
4366 * @hw: pointer to the HW struct
4368 enum ice_fw_modes ice_get_fw_mode(struct ice_hw *hw)
4370 #define ICE_FW_MODE_DBG_M BIT(0)
4371 #define ICE_FW_MODE_REC_M BIT(1)
4372 #define ICE_FW_MODE_ROLLBACK_M BIT(2)
4375 /* check the current FW mode */
4376 fw_mode = rd32(hw, GL_MNG_FWSM) & GL_MNG_FWSM_FW_MODES_M;
4378 if (fw_mode & ICE_FW_MODE_DBG_M)
4379 return ICE_FW_MODE_DBG;
4380 else if (fw_mode & ICE_FW_MODE_REC_M)
4381 return ICE_FW_MODE_REC;
4382 else if (fw_mode & ICE_FW_MODE_ROLLBACK_M)
4383 return ICE_FW_MODE_ROLLBACK;
4385 return ICE_FW_MODE_NORMAL;
4389 * ice_fw_supports_link_override
4390 * @hw: pointer to the hardware structure
4392 * Checks if the firmware supports link override
4394 bool ice_fw_supports_link_override(struct ice_hw *hw)
4396 /* Currently, only supported for E810 devices */
4397 if (hw->mac_type != ICE_MAC_E810)
4400 if (hw->api_maj_ver == ICE_FW_API_LINK_OVERRIDE_MAJ) {
4401 if (hw->api_min_ver > ICE_FW_API_LINK_OVERRIDE_MIN)
4403 if (hw->api_min_ver == ICE_FW_API_LINK_OVERRIDE_MIN &&
4404 hw->api_patch >= ICE_FW_API_LINK_OVERRIDE_PATCH)
4406 } else if (hw->api_maj_ver > ICE_FW_API_LINK_OVERRIDE_MAJ) {
4414 * ice_get_link_default_override
4415 * @ldo: pointer to the link default override struct
4416 * @pi: pointer to the port info struct
4418 * Gets the link default override for a port
4421 ice_get_link_default_override(struct ice_link_default_override_tlv *ldo,
4422 struct ice_port_info *pi)
4424 u16 i, tlv, tlv_len, tlv_start, buf, offset;
4425 struct ice_hw *hw = pi->hw;
4426 enum ice_status status;
4428 status = ice_get_pfa_module_tlv(hw, &tlv, &tlv_len,
4429 ICE_SR_LINK_DEFAULT_OVERRIDE_PTR);
4431 ice_debug(hw, ICE_DBG_INIT,
4432 "Failed to read link override TLV.\n");
4436 /* Each port has its own config; calculate for our port */
4437 tlv_start = tlv + pi->lport * ICE_SR_PFA_LINK_OVERRIDE_WORDS +
4438 ICE_SR_PFA_LINK_OVERRIDE_OFFSET;
4440 /* link options first */
4441 status = ice_read_sr_word(hw, tlv_start, &buf);
4443 ice_debug(hw, ICE_DBG_INIT,
4444 "Failed to read override link options.\n");
4447 ldo->options = buf & ICE_LINK_OVERRIDE_OPT_M;
4448 ldo->phy_config = (buf & ICE_LINK_OVERRIDE_PHY_CFG_M) >>
4449 ICE_LINK_OVERRIDE_PHY_CFG_S;
4451 /* link PHY config */
4452 offset = tlv_start + ICE_SR_PFA_LINK_OVERRIDE_FEC_OFFSET;
4453 status = ice_read_sr_word(hw, offset, &buf);
4455 ice_debug(hw, ICE_DBG_INIT,
4456 "Failed to read override phy config.\n");
4459 ldo->fec_options = buf & ICE_LINK_OVERRIDE_FEC_OPT_M;
4462 offset = tlv_start + ICE_SR_PFA_LINK_OVERRIDE_PHY_OFFSET;
4463 for (i = 0; i < ICE_SR_PFA_LINK_OVERRIDE_PHY_WORDS; i++) {
4464 status = ice_read_sr_word(hw, (offset + i), &buf);
4466 ice_debug(hw, ICE_DBG_INIT,
4467 "Failed to read override link options.\n");
4470 /* shift 16 bits at a time to fill 64 bits */
4471 ldo->phy_type_low |= ((u64)buf << (i * 16));
4474 /* PHY types high */
4475 offset = tlv_start + ICE_SR_PFA_LINK_OVERRIDE_PHY_OFFSET +
4476 ICE_SR_PFA_LINK_OVERRIDE_PHY_WORDS;
4477 for (i = 0; i < ICE_SR_PFA_LINK_OVERRIDE_PHY_WORDS; i++) {
4478 status = ice_read_sr_word(hw, (offset + i), &buf);
4480 ice_debug(hw, ICE_DBG_INIT,
4481 "Failed to read override link options.\n");
4484 /* shift 16 bits at a time to fill 64 bits */
4485 ldo->phy_type_high |= ((u64)buf << (i * 16));