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 case ICE_DEV_ID_E823L_10G_BASE_T:
47 case ICE_DEV_ID_E823L_1GBE:
48 case ICE_DEV_ID_E823L_BACKPLANE:
49 case ICE_DEV_ID_E823L_QSFP:
50 case ICE_DEV_ID_E823L_SFP:
51 hw->mac_type = ICE_MAC_GENERIC;
54 hw->mac_type = ICE_MAC_UNKNOWN;
58 ice_debug(hw, ICE_DBG_INIT, "mac_type: %d\n", hw->mac_type);
63 * ice_clear_pf_cfg - Clear PF configuration
64 * @hw: pointer to the hardware structure
66 * Clears any existing PF configuration (VSIs, VSI lists, switch rules, port
67 * configuration, flow director filters, etc.).
69 enum ice_status ice_clear_pf_cfg(struct ice_hw *hw)
71 struct ice_aq_desc desc;
73 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_clear_pf_cfg);
75 return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
79 * ice_aq_manage_mac_read - manage MAC address read command
80 * @hw: pointer to the HW struct
81 * @buf: a virtual buffer to hold the manage MAC read response
82 * @buf_size: Size of the virtual buffer
83 * @cd: pointer to command details structure or NULL
85 * This function is used to return per PF station MAC address (0x0107).
86 * NOTE: Upon successful completion of this command, MAC address information
87 * is returned in user specified buffer. Please interpret user specified
88 * buffer as "manage_mac_read" response.
89 * Response such as various MAC addresses are stored in HW struct (port.mac)
90 * ice_aq_discover_caps is expected to be called before this function is called.
92 static enum ice_status
93 ice_aq_manage_mac_read(struct ice_hw *hw, void *buf, u16 buf_size,
96 struct ice_aqc_manage_mac_read_resp *resp;
97 struct ice_aqc_manage_mac_read *cmd;
98 struct ice_aq_desc desc;
99 enum ice_status status;
103 cmd = &desc.params.mac_read;
105 if (buf_size < sizeof(*resp))
106 return ICE_ERR_BUF_TOO_SHORT;
108 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_manage_mac_read);
110 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
114 resp = (struct ice_aqc_manage_mac_read_resp *)buf;
115 flags = LE16_TO_CPU(cmd->flags) & ICE_AQC_MAN_MAC_READ_M;
117 if (!(flags & ICE_AQC_MAN_MAC_LAN_ADDR_VALID)) {
118 ice_debug(hw, ICE_DBG_LAN, "got invalid MAC address\n");
122 /* A single port can report up to two (LAN and WoL) addresses */
123 for (i = 0; i < cmd->num_addr; i++)
124 if (resp[i].addr_type == ICE_AQC_MAN_MAC_ADDR_TYPE_LAN) {
125 ice_memcpy(hw->port_info->mac.lan_addr,
126 resp[i].mac_addr, ETH_ALEN,
128 ice_memcpy(hw->port_info->mac.perm_addr,
130 ETH_ALEN, ICE_DMA_TO_NONDMA);
137 * ice_aq_get_phy_caps - returns PHY capabilities
138 * @pi: port information structure
139 * @qual_mods: report qualified modules
140 * @report_mode: report mode capabilities
141 * @pcaps: structure for PHY capabilities to be filled
142 * @cd: pointer to command details structure or NULL
144 * Returns the various PHY capabilities supported on the Port (0x0600)
147 ice_aq_get_phy_caps(struct ice_port_info *pi, bool qual_mods, u8 report_mode,
148 struct ice_aqc_get_phy_caps_data *pcaps,
149 struct ice_sq_cd *cd)
151 struct ice_aqc_get_phy_caps *cmd;
152 u16 pcaps_size = sizeof(*pcaps);
153 struct ice_aq_desc desc;
154 enum ice_status status;
157 cmd = &desc.params.get_phy;
159 if (!pcaps || (report_mode & ~ICE_AQC_REPORT_MODE_M) || !pi)
160 return ICE_ERR_PARAM;
163 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_phy_caps);
166 cmd->param0 |= CPU_TO_LE16(ICE_AQC_GET_PHY_RQM);
168 cmd->param0 |= CPU_TO_LE16(report_mode);
169 status = ice_aq_send_cmd(hw, &desc, pcaps, pcaps_size, cd);
171 ice_debug(hw, ICE_DBG_LINK, "get phy caps - report_mode = 0x%x\n",
173 ice_debug(hw, ICE_DBG_LINK, " phy_type_low = 0x%llx\n",
174 (unsigned long long)LE64_TO_CPU(pcaps->phy_type_low));
175 ice_debug(hw, ICE_DBG_LINK, " phy_type_high = 0x%llx\n",
176 (unsigned long long)LE64_TO_CPU(pcaps->phy_type_high));
177 ice_debug(hw, ICE_DBG_LINK, " caps = 0x%x\n", pcaps->caps);
178 ice_debug(hw, ICE_DBG_LINK, " low_power_ctrl_an = 0x%x\n",
179 pcaps->low_power_ctrl_an);
180 ice_debug(hw, ICE_DBG_LINK, " eee_cap = 0x%x\n", pcaps->eee_cap);
181 ice_debug(hw, ICE_DBG_LINK, " eeer_value = 0x%x\n",
183 ice_debug(hw, ICE_DBG_LINK, " link_fec_options = 0x%x\n",
184 pcaps->link_fec_options);
185 ice_debug(hw, ICE_DBG_LINK, " module_compliance_enforcement = 0x%x\n",
186 pcaps->module_compliance_enforcement);
187 ice_debug(hw, ICE_DBG_LINK, " extended_compliance_code = 0x%x\n",
188 pcaps->extended_compliance_code);
189 ice_debug(hw, ICE_DBG_LINK, " module_type[0] = 0x%x\n",
190 pcaps->module_type[0]);
191 ice_debug(hw, ICE_DBG_LINK, " module_type[1] = 0x%x\n",
192 pcaps->module_type[1]);
193 ice_debug(hw, ICE_DBG_LINK, " module_type[2] = 0x%x\n",
194 pcaps->module_type[2]);
197 if (status == ICE_SUCCESS && report_mode == ICE_AQC_REPORT_TOPO_CAP) {
198 pi->phy.phy_type_low = LE64_TO_CPU(pcaps->phy_type_low);
199 pi->phy.phy_type_high = LE64_TO_CPU(pcaps->phy_type_high);
206 * ice_aq_get_link_topo_handle - get link topology node return status
207 * @pi: port information structure
208 * @node_type: requested node type
209 * @cd: pointer to command details structure or NULL
211 * Get link topology node return status for specified node type (0x06E0)
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 static enum ice_status
218 ice_aq_get_link_topo_handle(struct ice_port_info *pi, u8 node_type,
219 struct ice_sq_cd *cd)
221 struct ice_aqc_get_link_topo *cmd;
222 struct ice_aq_desc desc;
224 cmd = &desc.params.get_link_topo;
226 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_link_topo);
228 cmd->addr.node_type_ctx = (ICE_AQC_LINK_TOPO_NODE_CTX_PORT <<
229 ICE_AQC_LINK_TOPO_NODE_CTX_S);
232 cmd->addr.node_type_ctx |= (ICE_AQC_LINK_TOPO_NODE_TYPE_M & node_type);
234 return ice_aq_send_cmd(pi->hw, &desc, NULL, 0, cd);
238 * ice_is_media_cage_present
239 * @pi: port information structure
241 * Returns true if media cage is present, else false. If no cage, then
242 * media type is backplane or BASE-T.
244 static bool ice_is_media_cage_present(struct ice_port_info *pi)
246 /* Node type cage can be used to determine if cage is present. If AQC
247 * returns error (ENOENT), then no cage present. If no cage present then
248 * connection type is backplane or BASE-T.
250 return !ice_aq_get_link_topo_handle(pi,
251 ICE_AQC_LINK_TOPO_NODE_TYPE_CAGE,
256 * ice_get_media_type - Gets media type
257 * @pi: port information structure
259 static enum ice_media_type ice_get_media_type(struct ice_port_info *pi)
261 struct ice_link_status *hw_link_info;
264 return ICE_MEDIA_UNKNOWN;
266 hw_link_info = &pi->phy.link_info;
267 if (hw_link_info->phy_type_low && hw_link_info->phy_type_high)
268 /* If more than one media type is selected, report unknown */
269 return ICE_MEDIA_UNKNOWN;
271 if (hw_link_info->phy_type_low) {
272 switch (hw_link_info->phy_type_low) {
273 case ICE_PHY_TYPE_LOW_1000BASE_SX:
274 case ICE_PHY_TYPE_LOW_1000BASE_LX:
275 case ICE_PHY_TYPE_LOW_10GBASE_SR:
276 case ICE_PHY_TYPE_LOW_10GBASE_LR:
277 case ICE_PHY_TYPE_LOW_10G_SFI_C2C:
278 case ICE_PHY_TYPE_LOW_25GBASE_SR:
279 case ICE_PHY_TYPE_LOW_25GBASE_LR:
280 case ICE_PHY_TYPE_LOW_40GBASE_SR4:
281 case ICE_PHY_TYPE_LOW_40GBASE_LR4:
282 case ICE_PHY_TYPE_LOW_50GBASE_SR2:
283 case ICE_PHY_TYPE_LOW_50GBASE_LR2:
284 case ICE_PHY_TYPE_LOW_50GBASE_SR:
285 case ICE_PHY_TYPE_LOW_50GBASE_FR:
286 case ICE_PHY_TYPE_LOW_50GBASE_LR:
287 case ICE_PHY_TYPE_LOW_100GBASE_SR4:
288 case ICE_PHY_TYPE_LOW_100GBASE_LR4:
289 case ICE_PHY_TYPE_LOW_100GBASE_SR2:
290 case ICE_PHY_TYPE_LOW_100GBASE_DR:
291 return ICE_MEDIA_FIBER;
292 case ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC:
293 case ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC:
294 case ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC:
295 case ICE_PHY_TYPE_LOW_50G_LAUI2_AOC_ACC:
296 case ICE_PHY_TYPE_LOW_50G_AUI2_AOC_ACC:
297 case ICE_PHY_TYPE_LOW_50G_AUI1_AOC_ACC:
298 case ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC:
299 case ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC:
300 return ICE_MEDIA_FIBER;
301 case ICE_PHY_TYPE_LOW_100BASE_TX:
302 case ICE_PHY_TYPE_LOW_1000BASE_T:
303 case ICE_PHY_TYPE_LOW_2500BASE_T:
304 case ICE_PHY_TYPE_LOW_5GBASE_T:
305 case ICE_PHY_TYPE_LOW_10GBASE_T:
306 case ICE_PHY_TYPE_LOW_25GBASE_T:
307 return ICE_MEDIA_BASET;
308 case ICE_PHY_TYPE_LOW_10G_SFI_DA:
309 case ICE_PHY_TYPE_LOW_25GBASE_CR:
310 case ICE_PHY_TYPE_LOW_25GBASE_CR_S:
311 case ICE_PHY_TYPE_LOW_25GBASE_CR1:
312 case ICE_PHY_TYPE_LOW_40GBASE_CR4:
313 case ICE_PHY_TYPE_LOW_50GBASE_CR2:
314 case ICE_PHY_TYPE_LOW_50GBASE_CP:
315 case ICE_PHY_TYPE_LOW_100GBASE_CR4:
316 case ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4:
317 case ICE_PHY_TYPE_LOW_100GBASE_CP2:
319 case ICE_PHY_TYPE_LOW_25G_AUI_C2C:
320 case ICE_PHY_TYPE_LOW_40G_XLAUI:
321 case ICE_PHY_TYPE_LOW_50G_LAUI2:
322 case ICE_PHY_TYPE_LOW_50G_AUI2:
323 case ICE_PHY_TYPE_LOW_50G_AUI1:
324 case ICE_PHY_TYPE_LOW_100G_AUI4:
325 case ICE_PHY_TYPE_LOW_100G_CAUI4:
326 if (ice_is_media_cage_present(pi))
327 return ICE_MEDIA_AUI;
329 case ICE_PHY_TYPE_LOW_1000BASE_KX:
330 case ICE_PHY_TYPE_LOW_2500BASE_KX:
331 case ICE_PHY_TYPE_LOW_2500BASE_X:
332 case ICE_PHY_TYPE_LOW_5GBASE_KR:
333 case ICE_PHY_TYPE_LOW_10GBASE_KR_CR1:
334 case ICE_PHY_TYPE_LOW_25GBASE_KR:
335 case ICE_PHY_TYPE_LOW_25GBASE_KR1:
336 case ICE_PHY_TYPE_LOW_25GBASE_KR_S:
337 case ICE_PHY_TYPE_LOW_40GBASE_KR4:
338 case ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4:
339 case ICE_PHY_TYPE_LOW_50GBASE_KR2:
340 case ICE_PHY_TYPE_LOW_100GBASE_KR4:
341 case ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4:
342 return ICE_MEDIA_BACKPLANE;
345 switch (hw_link_info->phy_type_high) {
346 case ICE_PHY_TYPE_HIGH_100G_AUI2:
347 case ICE_PHY_TYPE_HIGH_100G_CAUI2:
348 if (ice_is_media_cage_present(pi))
349 return ICE_MEDIA_AUI;
351 case ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4:
352 return ICE_MEDIA_BACKPLANE;
353 case ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC:
354 case ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC:
355 return ICE_MEDIA_FIBER;
358 return ICE_MEDIA_UNKNOWN;
362 * ice_aq_get_link_info
363 * @pi: port information structure
364 * @ena_lse: enable/disable LinkStatusEvent reporting
365 * @link: pointer to link status structure - optional
366 * @cd: pointer to command details structure or NULL
368 * Get Link Status (0x607). Returns the link status of the adapter.
371 ice_aq_get_link_info(struct ice_port_info *pi, bool ena_lse,
372 struct ice_link_status *link, struct ice_sq_cd *cd)
374 struct ice_aqc_get_link_status_data link_data = { 0 };
375 struct ice_aqc_get_link_status *resp;
376 struct ice_link_status *li_old, *li;
377 enum ice_media_type *hw_media_type;
378 struct ice_fc_info *hw_fc_info;
379 bool tx_pause, rx_pause;
380 struct ice_aq_desc desc;
381 enum ice_status status;
386 return ICE_ERR_PARAM;
388 li_old = &pi->phy.link_info_old;
389 hw_media_type = &pi->phy.media_type;
390 li = &pi->phy.link_info;
391 hw_fc_info = &pi->fc;
393 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_link_status);
394 cmd_flags = (ena_lse) ? ICE_AQ_LSE_ENA : ICE_AQ_LSE_DIS;
395 resp = &desc.params.get_link_status;
396 resp->cmd_flags = CPU_TO_LE16(cmd_flags);
397 resp->lport_num = pi->lport;
399 status = ice_aq_send_cmd(hw, &desc, &link_data, sizeof(link_data), cd);
401 if (status != ICE_SUCCESS)
404 /* save off old link status information */
407 /* update current link status information */
408 li->link_speed = LE16_TO_CPU(link_data.link_speed);
409 li->phy_type_low = LE64_TO_CPU(link_data.phy_type_low);
410 li->phy_type_high = LE64_TO_CPU(link_data.phy_type_high);
411 *hw_media_type = ice_get_media_type(pi);
412 li->link_info = link_data.link_info;
413 li->an_info = link_data.an_info;
414 li->ext_info = link_data.ext_info;
415 li->max_frame_size = LE16_TO_CPU(link_data.max_frame_size);
416 li->fec_info = link_data.cfg & ICE_AQ_FEC_MASK;
417 li->topo_media_conflict = link_data.topo_media_conflict;
418 li->pacing = link_data.cfg & (ICE_AQ_CFG_PACING_M |
419 ICE_AQ_CFG_PACING_TYPE_M);
422 tx_pause = !!(link_data.an_info & ICE_AQ_LINK_PAUSE_TX);
423 rx_pause = !!(link_data.an_info & ICE_AQ_LINK_PAUSE_RX);
424 if (tx_pause && rx_pause)
425 hw_fc_info->current_mode = ICE_FC_FULL;
427 hw_fc_info->current_mode = ICE_FC_TX_PAUSE;
429 hw_fc_info->current_mode = ICE_FC_RX_PAUSE;
431 hw_fc_info->current_mode = ICE_FC_NONE;
433 li->lse_ena = !!(resp->cmd_flags & CPU_TO_LE16(ICE_AQ_LSE_IS_ENABLED));
435 ice_debug(hw, ICE_DBG_LINK, "get link info\n");
436 ice_debug(hw, ICE_DBG_LINK, " link_speed = 0x%x\n", li->link_speed);
437 ice_debug(hw, ICE_DBG_LINK, " phy_type_low = 0x%llx\n",
438 (unsigned long long)li->phy_type_low);
439 ice_debug(hw, ICE_DBG_LINK, " phy_type_high = 0x%llx\n",
440 (unsigned long long)li->phy_type_high);
441 ice_debug(hw, ICE_DBG_LINK, " media_type = 0x%x\n", *hw_media_type);
442 ice_debug(hw, ICE_DBG_LINK, " link_info = 0x%x\n", li->link_info);
443 ice_debug(hw, ICE_DBG_LINK, " an_info = 0x%x\n", li->an_info);
444 ice_debug(hw, ICE_DBG_LINK, " ext_info = 0x%x\n", li->ext_info);
445 ice_debug(hw, ICE_DBG_LINK, " fec_info = 0x%x\n", li->fec_info);
446 ice_debug(hw, ICE_DBG_LINK, " lse_ena = 0x%x\n", li->lse_ena);
447 ice_debug(hw, ICE_DBG_LINK, " max_frame = 0x%x\n",
449 ice_debug(hw, ICE_DBG_LINK, " pacing = 0x%x\n", li->pacing);
451 /* save link status information */
455 /* flag cleared so calling functions don't call AQ again */
456 pi->phy.get_link_info = false;
462 * ice_fill_tx_timer_and_fc_thresh
463 * @hw: pointer to the HW struct
464 * @cmd: pointer to MAC cfg structure
466 * Add Tx timer and FC refresh threshold info to Set MAC Config AQ command
470 ice_fill_tx_timer_and_fc_thresh(struct ice_hw *hw,
471 struct ice_aqc_set_mac_cfg *cmd)
473 u16 fc_thres_val, tx_timer_val;
476 /* We read back the transmit timer and fc threshold value of
477 * LFC. Thus, we will use index =
478 * PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA_MAX_INDEX.
480 * Also, because we are opearating on transmit timer and fc
481 * threshold of LFC, we don't turn on any bit in tx_tmr_priority
483 #define IDX_OF_LFC PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA_MAX_INDEX
485 /* Retrieve the transmit timer */
486 val = rd32(hw, PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA(IDX_OF_LFC));
488 PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA_HSEC_CTL_TX_PAUSE_QUANTA_M;
489 cmd->tx_tmr_value = CPU_TO_LE16(tx_timer_val);
491 /* Retrieve the fc threshold */
492 val = rd32(hw, PRTMAC_HSEC_CTL_TX_PAUSE_REFRESH_TIMER(IDX_OF_LFC));
493 fc_thres_val = val & PRTMAC_HSEC_CTL_TX_PAUSE_REFRESH_TIMER_M;
495 cmd->fc_refresh_threshold = CPU_TO_LE16(fc_thres_val);
500 * @hw: pointer to the HW struct
501 * @max_frame_size: Maximum Frame Size to be supported
502 * @cd: pointer to command details structure or NULL
504 * Set MAC configuration (0x0603)
507 ice_aq_set_mac_cfg(struct ice_hw *hw, u16 max_frame_size, struct ice_sq_cd *cd)
509 struct ice_aqc_set_mac_cfg *cmd;
510 struct ice_aq_desc desc;
512 cmd = &desc.params.set_mac_cfg;
514 if (max_frame_size == 0)
515 return ICE_ERR_PARAM;
517 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_mac_cfg);
519 cmd->max_frame_size = CPU_TO_LE16(max_frame_size);
521 ice_fill_tx_timer_and_fc_thresh(hw, cmd);
523 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
527 * ice_init_fltr_mgmt_struct - initializes filter management list and locks
528 * @hw: pointer to the HW struct
530 enum ice_status ice_init_fltr_mgmt_struct(struct ice_hw *hw)
532 struct ice_switch_info *sw;
533 enum ice_status status;
535 hw->switch_info = (struct ice_switch_info *)
536 ice_malloc(hw, sizeof(*hw->switch_info));
538 sw = hw->switch_info;
541 return ICE_ERR_NO_MEMORY;
543 INIT_LIST_HEAD(&sw->vsi_list_map_head);
544 sw->prof_res_bm_init = 0;
546 status = ice_init_def_sw_recp(hw, &hw->switch_info->recp_list);
548 ice_free(hw, hw->switch_info);
555 * ice_cleanup_fltr_mgmt_single - clears single filter mngt struct
556 * @hw: pointer to the HW struct
557 * @sw: pointer to switch info struct for which function clears filters
560 ice_cleanup_fltr_mgmt_single(struct ice_hw *hw, struct ice_switch_info *sw)
562 struct ice_vsi_list_map_info *v_pos_map;
563 struct ice_vsi_list_map_info *v_tmp_map;
564 struct ice_sw_recipe *recps;
570 LIST_FOR_EACH_ENTRY_SAFE(v_pos_map, v_tmp_map, &sw->vsi_list_map_head,
571 ice_vsi_list_map_info, list_entry) {
572 LIST_DEL(&v_pos_map->list_entry);
573 ice_free(hw, v_pos_map);
575 recps = sw->recp_list;
576 for (i = 0; i < ICE_MAX_NUM_RECIPES; i++) {
577 struct ice_recp_grp_entry *rg_entry, *tmprg_entry;
579 recps[i].root_rid = i;
580 LIST_FOR_EACH_ENTRY_SAFE(rg_entry, tmprg_entry,
581 &recps[i].rg_list, ice_recp_grp_entry,
583 LIST_DEL(&rg_entry->l_entry);
584 ice_free(hw, rg_entry);
587 if (recps[i].adv_rule) {
588 struct ice_adv_fltr_mgmt_list_entry *tmp_entry;
589 struct ice_adv_fltr_mgmt_list_entry *lst_itr;
591 ice_destroy_lock(&recps[i].filt_rule_lock);
592 LIST_FOR_EACH_ENTRY_SAFE(lst_itr, tmp_entry,
593 &recps[i].filt_rules,
594 ice_adv_fltr_mgmt_list_entry,
596 LIST_DEL(&lst_itr->list_entry);
597 ice_free(hw, lst_itr->lkups);
598 ice_free(hw, lst_itr);
601 struct ice_fltr_mgmt_list_entry *lst_itr, *tmp_entry;
603 ice_destroy_lock(&recps[i].filt_rule_lock);
604 LIST_FOR_EACH_ENTRY_SAFE(lst_itr, tmp_entry,
605 &recps[i].filt_rules,
606 ice_fltr_mgmt_list_entry,
608 LIST_DEL(&lst_itr->list_entry);
609 ice_free(hw, lst_itr);
612 if (recps[i].root_buf)
613 ice_free(hw, recps[i].root_buf);
615 ice_rm_sw_replay_rule_info(hw, sw);
616 ice_free(hw, sw->recp_list);
621 * ice_cleanup_all_fltr_mgmt - cleanup filter management list and locks
622 * @hw: pointer to the HW struct
624 void ice_cleanup_fltr_mgmt_struct(struct ice_hw *hw)
626 ice_cleanup_fltr_mgmt_single(hw, hw->switch_info);
630 * ice_get_itr_intrl_gran
631 * @hw: pointer to the HW struct
633 * Determines the ITR/INTRL granularities based on the maximum aggregate
634 * bandwidth according to the device's configuration during power-on.
636 static void ice_get_itr_intrl_gran(struct ice_hw *hw)
638 u8 max_agg_bw = (rd32(hw, GL_PWR_MODE_CTL) &
639 GL_PWR_MODE_CTL_CAR_MAX_BW_M) >>
640 GL_PWR_MODE_CTL_CAR_MAX_BW_S;
642 switch (max_agg_bw) {
643 case ICE_MAX_AGG_BW_200G:
644 case ICE_MAX_AGG_BW_100G:
645 case ICE_MAX_AGG_BW_50G:
646 hw->itr_gran = ICE_ITR_GRAN_ABOVE_25;
647 hw->intrl_gran = ICE_INTRL_GRAN_ABOVE_25;
649 case ICE_MAX_AGG_BW_25G:
650 hw->itr_gran = ICE_ITR_GRAN_MAX_25;
651 hw->intrl_gran = ICE_INTRL_GRAN_MAX_25;
657 * ice_print_rollback_msg - print FW rollback message
658 * @hw: pointer to the hardware structure
660 void ice_print_rollback_msg(struct ice_hw *hw)
662 char nvm_str[ICE_NVM_VER_LEN] = { 0 };
663 struct ice_nvm_info *nvm = &hw->nvm;
664 struct ice_orom_info *orom;
668 SNPRINTF(nvm_str, sizeof(nvm_str), "%x.%02x 0x%x %d.%d.%d",
669 nvm->major_ver, nvm->minor_ver, nvm->eetrack, orom->major,
670 orom->build, orom->patch);
672 "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",
673 nvm_str, hw->fw_maj_ver, hw->fw_min_ver);
677 * ice_init_hw - main hardware initialization routine
678 * @hw: pointer to the hardware structure
680 enum ice_status ice_init_hw(struct ice_hw *hw)
682 struct ice_aqc_get_phy_caps_data *pcaps;
683 enum ice_status status;
687 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
689 /* Set MAC type based on DeviceID */
690 status = ice_set_mac_type(hw);
694 hw->pf_id = (u8)(rd32(hw, PF_FUNC_RID) &
695 PF_FUNC_RID_FUNCTION_NUMBER_M) >>
696 PF_FUNC_RID_FUNCTION_NUMBER_S;
698 status = ice_reset(hw, ICE_RESET_PFR);
702 ice_get_itr_intrl_gran(hw);
704 status = ice_create_all_ctrlq(hw);
706 goto err_unroll_cqinit;
708 status = ice_init_nvm(hw);
710 goto err_unroll_cqinit;
712 if (ice_get_fw_mode(hw) == ICE_FW_MODE_ROLLBACK)
713 ice_print_rollback_msg(hw);
715 status = ice_clear_pf_cfg(hw);
717 goto err_unroll_cqinit;
719 /* Set bit to enable Flow Director filters */
720 wr32(hw, PFQF_FD_ENA, PFQF_FD_ENA_FD_ENA_M);
721 INIT_LIST_HEAD(&hw->fdir_list_head);
723 ice_clear_pxe_mode(hw);
725 status = ice_get_caps(hw);
727 goto err_unroll_cqinit;
729 hw->port_info = (struct ice_port_info *)
730 ice_malloc(hw, sizeof(*hw->port_info));
731 if (!hw->port_info) {
732 status = ICE_ERR_NO_MEMORY;
733 goto err_unroll_cqinit;
736 /* set the back pointer to HW */
737 hw->port_info->hw = hw;
739 /* Initialize port_info struct with switch configuration data */
740 status = ice_get_initial_sw_cfg(hw);
742 goto err_unroll_alloc;
745 /* Query the allocated resources for Tx scheduler */
746 status = ice_sched_query_res_alloc(hw);
748 ice_debug(hw, ICE_DBG_SCHED,
749 "Failed to get scheduler allocated resources\n");
750 goto err_unroll_alloc;
752 ice_sched_get_psm_clk_freq(hw);
754 /* Initialize port_info struct with scheduler data */
755 status = ice_sched_init_port(hw->port_info);
757 goto err_unroll_sched;
759 pcaps = (struct ice_aqc_get_phy_caps_data *)
760 ice_malloc(hw, sizeof(*pcaps));
762 status = ICE_ERR_NO_MEMORY;
763 goto err_unroll_sched;
766 /* Initialize port_info struct with PHY capabilities */
767 status = ice_aq_get_phy_caps(hw->port_info, false,
768 ICE_AQC_REPORT_TOPO_CAP, pcaps, NULL);
771 goto err_unroll_sched;
773 /* Initialize port_info struct with link information */
774 status = ice_aq_get_link_info(hw->port_info, false, NULL, NULL);
776 goto err_unroll_sched;
777 /* need a valid SW entry point to build a Tx tree */
778 if (!hw->sw_entry_point_layer) {
779 ice_debug(hw, ICE_DBG_SCHED, "invalid sw entry point\n");
780 status = ICE_ERR_CFG;
781 goto err_unroll_sched;
783 INIT_LIST_HEAD(&hw->agg_list);
784 /* Initialize max burst size */
785 if (!hw->max_burst_size)
786 ice_cfg_rl_burst_size(hw, ICE_SCHED_DFLT_BURST_SIZE);
787 status = ice_init_fltr_mgmt_struct(hw);
789 goto err_unroll_sched;
791 /* Get MAC information */
792 /* A single port can report up to two (LAN and WoL) addresses */
793 mac_buf = ice_calloc(hw, 2,
794 sizeof(struct ice_aqc_manage_mac_read_resp));
795 mac_buf_len = 2 * sizeof(struct ice_aqc_manage_mac_read_resp);
798 status = ICE_ERR_NO_MEMORY;
799 goto err_unroll_fltr_mgmt_struct;
802 status = ice_aq_manage_mac_read(hw, mac_buf, mac_buf_len, NULL);
803 ice_free(hw, mac_buf);
806 goto err_unroll_fltr_mgmt_struct;
807 /* enable jumbo frame support at MAC level */
808 status = ice_aq_set_mac_cfg(hw, ICE_AQ_SET_MAC_FRAME_SIZE_MAX, NULL);
810 goto err_unroll_fltr_mgmt_struct;
811 /* Obtain counter base index which would be used by flow director */
812 status = ice_alloc_fd_res_cntr(hw, &hw->fd_ctr_base);
814 goto err_unroll_fltr_mgmt_struct;
815 status = ice_init_hw_tbls(hw);
817 goto err_unroll_fltr_mgmt_struct;
818 ice_init_lock(&hw->tnl_lock);
821 err_unroll_fltr_mgmt_struct:
822 ice_cleanup_fltr_mgmt_struct(hw);
824 ice_sched_cleanup_all(hw);
826 ice_free(hw, hw->port_info);
827 hw->port_info = NULL;
829 ice_destroy_all_ctrlq(hw);
834 * ice_deinit_hw - unroll initialization operations done by ice_init_hw
835 * @hw: pointer to the hardware structure
837 * This should be called only during nominal operation, not as a result of
838 * ice_init_hw() failing since ice_init_hw() will take care of unrolling
839 * applicable initializations if it fails for any reason.
841 void ice_deinit_hw(struct ice_hw *hw)
843 ice_free_fd_res_cntr(hw, hw->fd_ctr_base);
844 ice_cleanup_fltr_mgmt_struct(hw);
846 ice_sched_cleanup_all(hw);
847 ice_sched_clear_agg(hw);
849 ice_free_hw_tbls(hw);
850 ice_destroy_lock(&hw->tnl_lock);
853 ice_free(hw, hw->port_info);
854 hw->port_info = NULL;
857 ice_destroy_all_ctrlq(hw);
859 /* Clear VSI contexts if not already cleared */
860 ice_clear_all_vsi_ctx(hw);
864 * ice_check_reset - Check to see if a global reset is complete
865 * @hw: pointer to the hardware structure
867 enum ice_status ice_check_reset(struct ice_hw *hw)
869 u32 cnt, reg = 0, grst_delay, uld_mask;
871 /* Poll for Device Active state in case a recent CORER, GLOBR,
872 * or EMPR has occurred. The grst delay value is in 100ms units.
873 * Add 1sec for outstanding AQ commands that can take a long time.
875 grst_delay = ((rd32(hw, GLGEN_RSTCTL) & GLGEN_RSTCTL_GRSTDEL_M) >>
876 GLGEN_RSTCTL_GRSTDEL_S) + 10;
878 for (cnt = 0; cnt < grst_delay; cnt++) {
879 ice_msec_delay(100, true);
880 reg = rd32(hw, GLGEN_RSTAT);
881 if (!(reg & GLGEN_RSTAT_DEVSTATE_M))
885 if (cnt == grst_delay) {
886 ice_debug(hw, ICE_DBG_INIT,
887 "Global reset polling failed to complete.\n");
888 return ICE_ERR_RESET_FAILED;
891 #define ICE_RESET_DONE_MASK (GLNVM_ULD_PCIER_DONE_M |\
892 GLNVM_ULD_PCIER_DONE_1_M |\
893 GLNVM_ULD_CORER_DONE_M |\
894 GLNVM_ULD_GLOBR_DONE_M |\
895 GLNVM_ULD_POR_DONE_M |\
896 GLNVM_ULD_POR_DONE_1_M |\
897 GLNVM_ULD_PCIER_DONE_2_M)
899 uld_mask = ICE_RESET_DONE_MASK;
901 /* Device is Active; check Global Reset processes are done */
902 for (cnt = 0; cnt < ICE_PF_RESET_WAIT_COUNT; cnt++) {
903 reg = rd32(hw, GLNVM_ULD) & uld_mask;
904 if (reg == uld_mask) {
905 ice_debug(hw, ICE_DBG_INIT,
906 "Global reset processes done. %d\n", cnt);
909 ice_msec_delay(10, true);
912 if (cnt == ICE_PF_RESET_WAIT_COUNT) {
913 ice_debug(hw, ICE_DBG_INIT,
914 "Wait for Reset Done timed out. GLNVM_ULD = 0x%x\n",
916 return ICE_ERR_RESET_FAILED;
923 * ice_pf_reset - Reset the PF
924 * @hw: pointer to the hardware structure
926 * If a global reset has been triggered, this function checks
927 * for its completion and then issues the PF reset
929 static enum ice_status ice_pf_reset(struct ice_hw *hw)
933 /* If at function entry a global reset was already in progress, i.e.
934 * state is not 'device active' or any of the reset done bits are not
935 * set in GLNVM_ULD, there is no need for a PF Reset; poll until the
936 * global reset is done.
938 if ((rd32(hw, GLGEN_RSTAT) & GLGEN_RSTAT_DEVSTATE_M) ||
939 (rd32(hw, GLNVM_ULD) & ICE_RESET_DONE_MASK) ^ ICE_RESET_DONE_MASK) {
940 /* poll on global reset currently in progress until done */
941 if (ice_check_reset(hw))
942 return ICE_ERR_RESET_FAILED;
948 reg = rd32(hw, PFGEN_CTRL);
950 wr32(hw, PFGEN_CTRL, (reg | PFGEN_CTRL_PFSWR_M));
952 /* Wait for the PFR to complete. The wait time is the global config lock
953 * timeout plus the PFR timeout which will account for a possible reset
954 * that is occurring during a download package operation.
956 for (cnt = 0; cnt < ICE_GLOBAL_CFG_LOCK_TIMEOUT +
957 ICE_PF_RESET_WAIT_COUNT; cnt++) {
958 reg = rd32(hw, PFGEN_CTRL);
959 if (!(reg & PFGEN_CTRL_PFSWR_M))
962 ice_msec_delay(1, true);
965 if (cnt == ICE_PF_RESET_WAIT_COUNT) {
966 ice_debug(hw, ICE_DBG_INIT,
967 "PF reset polling failed to complete.\n");
968 return ICE_ERR_RESET_FAILED;
975 * ice_reset - Perform different types of reset
976 * @hw: pointer to the hardware structure
977 * @req: reset request
979 * This function triggers a reset as specified by the req parameter.
982 * If anything other than a PF reset is triggered, PXE mode is restored.
983 * This has to be cleared using ice_clear_pxe_mode again, once the AQ
984 * interface has been restored in the rebuild flow.
986 enum ice_status ice_reset(struct ice_hw *hw, enum ice_reset_req req)
992 return ice_pf_reset(hw);
993 case ICE_RESET_CORER:
994 ice_debug(hw, ICE_DBG_INIT, "CoreR requested\n");
995 val = GLGEN_RTRIG_CORER_M;
997 case ICE_RESET_GLOBR:
998 ice_debug(hw, ICE_DBG_INIT, "GlobalR requested\n");
999 val = GLGEN_RTRIG_GLOBR_M;
1002 return ICE_ERR_PARAM;
1005 val |= rd32(hw, GLGEN_RTRIG);
1006 wr32(hw, GLGEN_RTRIG, val);
1009 /* wait for the FW to be ready */
1010 return ice_check_reset(hw);
1014 * ice_copy_rxq_ctx_to_hw
1015 * @hw: pointer to the hardware structure
1016 * @ice_rxq_ctx: pointer to the rxq context
1017 * @rxq_index: the index of the Rx queue
1019 * Copies rxq context from dense structure to HW register space
1021 static enum ice_status
1022 ice_copy_rxq_ctx_to_hw(struct ice_hw *hw, u8 *ice_rxq_ctx, u32 rxq_index)
1027 return ICE_ERR_BAD_PTR;
1029 if (rxq_index > QRX_CTRL_MAX_INDEX)
1030 return ICE_ERR_PARAM;
1032 /* Copy each dword separately to HW */
1033 for (i = 0; i < ICE_RXQ_CTX_SIZE_DWORDS; i++) {
1034 wr32(hw, QRX_CONTEXT(i, rxq_index),
1035 *((u32 *)(ice_rxq_ctx + (i * sizeof(u32)))));
1037 ice_debug(hw, ICE_DBG_QCTX, "qrxdata[%d]: %08X\n", i,
1038 *((u32 *)(ice_rxq_ctx + (i * sizeof(u32)))));
1044 /* LAN Rx Queue Context */
1045 static const struct ice_ctx_ele ice_rlan_ctx_info[] = {
1046 /* Field Width LSB */
1047 ICE_CTX_STORE(ice_rlan_ctx, head, 13, 0),
1048 ICE_CTX_STORE(ice_rlan_ctx, cpuid, 8, 13),
1049 ICE_CTX_STORE(ice_rlan_ctx, base, 57, 32),
1050 ICE_CTX_STORE(ice_rlan_ctx, qlen, 13, 89),
1051 ICE_CTX_STORE(ice_rlan_ctx, dbuf, 7, 102),
1052 ICE_CTX_STORE(ice_rlan_ctx, hbuf, 5, 109),
1053 ICE_CTX_STORE(ice_rlan_ctx, dtype, 2, 114),
1054 ICE_CTX_STORE(ice_rlan_ctx, dsize, 1, 116),
1055 ICE_CTX_STORE(ice_rlan_ctx, crcstrip, 1, 117),
1056 ICE_CTX_STORE(ice_rlan_ctx, l2tsel, 1, 119),
1057 ICE_CTX_STORE(ice_rlan_ctx, hsplit_0, 4, 120),
1058 ICE_CTX_STORE(ice_rlan_ctx, hsplit_1, 2, 124),
1059 ICE_CTX_STORE(ice_rlan_ctx, showiv, 1, 127),
1060 ICE_CTX_STORE(ice_rlan_ctx, rxmax, 14, 174),
1061 ICE_CTX_STORE(ice_rlan_ctx, tphrdesc_ena, 1, 193),
1062 ICE_CTX_STORE(ice_rlan_ctx, tphwdesc_ena, 1, 194),
1063 ICE_CTX_STORE(ice_rlan_ctx, tphdata_ena, 1, 195),
1064 ICE_CTX_STORE(ice_rlan_ctx, tphhead_ena, 1, 196),
1065 ICE_CTX_STORE(ice_rlan_ctx, lrxqthresh, 3, 198),
1066 ICE_CTX_STORE(ice_rlan_ctx, prefena, 1, 201),
1072 * @hw: pointer to the hardware structure
1073 * @rlan_ctx: pointer to the rxq context
1074 * @rxq_index: the index of the Rx queue
1076 * Converts rxq context from sparse to dense structure and then writes
1077 * it to HW register space and enables the hardware to prefetch descriptors
1078 * instead of only fetching them on demand
1081 ice_write_rxq_ctx(struct ice_hw *hw, struct ice_rlan_ctx *rlan_ctx,
1084 u8 ctx_buf[ICE_RXQ_CTX_SZ] = { 0 };
1087 return ICE_ERR_BAD_PTR;
1089 rlan_ctx->prefena = 1;
1091 ice_set_ctx(hw, (u8 *)rlan_ctx, ctx_buf, ice_rlan_ctx_info);
1092 return ice_copy_rxq_ctx_to_hw(hw, ctx_buf, rxq_index);
1097 * @hw: pointer to the hardware structure
1098 * @rxq_index: the index of the Rx queue to clear
1100 * Clears rxq context in HW register space
1102 enum ice_status ice_clear_rxq_ctx(struct ice_hw *hw, u32 rxq_index)
1106 if (rxq_index > QRX_CTRL_MAX_INDEX)
1107 return ICE_ERR_PARAM;
1109 /* Clear each dword register separately */
1110 for (i = 0; i < ICE_RXQ_CTX_SIZE_DWORDS; i++)
1111 wr32(hw, QRX_CONTEXT(i, rxq_index), 0);
1116 /* LAN Tx Queue Context */
1117 const struct ice_ctx_ele ice_tlan_ctx_info[] = {
1118 /* Field Width LSB */
1119 ICE_CTX_STORE(ice_tlan_ctx, base, 57, 0),
1120 ICE_CTX_STORE(ice_tlan_ctx, port_num, 3, 57),
1121 ICE_CTX_STORE(ice_tlan_ctx, cgd_num, 5, 60),
1122 ICE_CTX_STORE(ice_tlan_ctx, pf_num, 3, 65),
1123 ICE_CTX_STORE(ice_tlan_ctx, vmvf_num, 10, 68),
1124 ICE_CTX_STORE(ice_tlan_ctx, vmvf_type, 2, 78),
1125 ICE_CTX_STORE(ice_tlan_ctx, src_vsi, 10, 80),
1126 ICE_CTX_STORE(ice_tlan_ctx, tsyn_ena, 1, 90),
1127 ICE_CTX_STORE(ice_tlan_ctx, internal_usage_flag, 1, 91),
1128 ICE_CTX_STORE(ice_tlan_ctx, alt_vlan, 1, 92),
1129 ICE_CTX_STORE(ice_tlan_ctx, cpuid, 8, 93),
1130 ICE_CTX_STORE(ice_tlan_ctx, wb_mode, 1, 101),
1131 ICE_CTX_STORE(ice_tlan_ctx, tphrd_desc, 1, 102),
1132 ICE_CTX_STORE(ice_tlan_ctx, tphrd, 1, 103),
1133 ICE_CTX_STORE(ice_tlan_ctx, tphwr_desc, 1, 104),
1134 ICE_CTX_STORE(ice_tlan_ctx, cmpq_id, 9, 105),
1135 ICE_CTX_STORE(ice_tlan_ctx, qnum_in_func, 14, 114),
1136 ICE_CTX_STORE(ice_tlan_ctx, itr_notification_mode, 1, 128),
1137 ICE_CTX_STORE(ice_tlan_ctx, adjust_prof_id, 6, 129),
1138 ICE_CTX_STORE(ice_tlan_ctx, qlen, 13, 135),
1139 ICE_CTX_STORE(ice_tlan_ctx, quanta_prof_idx, 4, 148),
1140 ICE_CTX_STORE(ice_tlan_ctx, tso_ena, 1, 152),
1141 ICE_CTX_STORE(ice_tlan_ctx, tso_qnum, 11, 153),
1142 ICE_CTX_STORE(ice_tlan_ctx, legacy_int, 1, 164),
1143 ICE_CTX_STORE(ice_tlan_ctx, drop_ena, 1, 165),
1144 ICE_CTX_STORE(ice_tlan_ctx, cache_prof_idx, 2, 166),
1145 ICE_CTX_STORE(ice_tlan_ctx, pkt_shaper_prof_idx, 3, 168),
1146 ICE_CTX_STORE(ice_tlan_ctx, int_q_state, 122, 171),
1151 * ice_copy_tx_cmpltnq_ctx_to_hw
1152 * @hw: pointer to the hardware structure
1153 * @ice_tx_cmpltnq_ctx: pointer to the Tx completion queue context
1154 * @tx_cmpltnq_index: the index of the completion queue
1156 * Copies Tx completion queue context from dense structure to HW register space
1158 static enum ice_status
1159 ice_copy_tx_cmpltnq_ctx_to_hw(struct ice_hw *hw, u8 *ice_tx_cmpltnq_ctx,
1160 u32 tx_cmpltnq_index)
1164 if (!ice_tx_cmpltnq_ctx)
1165 return ICE_ERR_BAD_PTR;
1167 if (tx_cmpltnq_index > GLTCLAN_CQ_CNTX0_MAX_INDEX)
1168 return ICE_ERR_PARAM;
1170 /* Copy each dword separately to HW */
1171 for (i = 0; i < ICE_TX_CMPLTNQ_CTX_SIZE_DWORDS; i++) {
1172 wr32(hw, GLTCLAN_CQ_CNTX(i, tx_cmpltnq_index),
1173 *((u32 *)(ice_tx_cmpltnq_ctx + (i * sizeof(u32)))));
1175 ice_debug(hw, ICE_DBG_QCTX, "cmpltnqdata[%d]: %08X\n", i,
1176 *((u32 *)(ice_tx_cmpltnq_ctx + (i * sizeof(u32)))));
1182 /* LAN Tx Completion Queue Context */
1183 static const struct ice_ctx_ele ice_tx_cmpltnq_ctx_info[] = {
1184 /* Field Width LSB */
1185 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, base, 57, 0),
1186 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, q_len, 18, 64),
1187 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, generation, 1, 96),
1188 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, wrt_ptr, 22, 97),
1189 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, pf_num, 3, 128),
1190 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, vmvf_num, 10, 131),
1191 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, vmvf_type, 2, 141),
1192 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, tph_desc_wr, 1, 160),
1193 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, cpuid, 8, 161),
1194 ICE_CTX_STORE(ice_tx_cmpltnq_ctx, cmpltn_cache, 512, 192),
1199 * ice_write_tx_cmpltnq_ctx
1200 * @hw: pointer to the hardware structure
1201 * @tx_cmpltnq_ctx: pointer to the completion queue context
1202 * @tx_cmpltnq_index: the index of the completion queue
1204 * Converts completion queue context from sparse to dense structure and then
1205 * writes it to HW register space
1208 ice_write_tx_cmpltnq_ctx(struct ice_hw *hw,
1209 struct ice_tx_cmpltnq_ctx *tx_cmpltnq_ctx,
1210 u32 tx_cmpltnq_index)
1212 u8 ctx_buf[ICE_TX_CMPLTNQ_CTX_SIZE_DWORDS * sizeof(u32)] = { 0 };
1214 ice_set_ctx(hw, (u8 *)tx_cmpltnq_ctx, ctx_buf, ice_tx_cmpltnq_ctx_info);
1215 return ice_copy_tx_cmpltnq_ctx_to_hw(hw, ctx_buf, tx_cmpltnq_index);
1219 * ice_clear_tx_cmpltnq_ctx
1220 * @hw: pointer to the hardware structure
1221 * @tx_cmpltnq_index: the index of the completion queue to clear
1223 * Clears Tx completion queue context in HW register space
1226 ice_clear_tx_cmpltnq_ctx(struct ice_hw *hw, u32 tx_cmpltnq_index)
1230 if (tx_cmpltnq_index > GLTCLAN_CQ_CNTX0_MAX_INDEX)
1231 return ICE_ERR_PARAM;
1233 /* Clear each dword register separately */
1234 for (i = 0; i < ICE_TX_CMPLTNQ_CTX_SIZE_DWORDS; i++)
1235 wr32(hw, GLTCLAN_CQ_CNTX(i, tx_cmpltnq_index), 0);
1241 * ice_copy_tx_drbell_q_ctx_to_hw
1242 * @hw: pointer to the hardware structure
1243 * @ice_tx_drbell_q_ctx: pointer to the doorbell queue context
1244 * @tx_drbell_q_index: the index of the doorbell queue
1246 * Copies doorbell queue context from dense structure to HW register space
1248 static enum ice_status
1249 ice_copy_tx_drbell_q_ctx_to_hw(struct ice_hw *hw, u8 *ice_tx_drbell_q_ctx,
1250 u32 tx_drbell_q_index)
1254 if (!ice_tx_drbell_q_ctx)
1255 return ICE_ERR_BAD_PTR;
1257 if (tx_drbell_q_index > QTX_COMM_DBLQ_DBELL_MAX_INDEX)
1258 return ICE_ERR_PARAM;
1260 /* Copy each dword separately to HW */
1261 for (i = 0; i < ICE_TX_DRBELL_Q_CTX_SIZE_DWORDS; i++) {
1262 wr32(hw, QTX_COMM_DBLQ_CNTX(i, tx_drbell_q_index),
1263 *((u32 *)(ice_tx_drbell_q_ctx + (i * sizeof(u32)))));
1265 ice_debug(hw, ICE_DBG_QCTX, "tx_drbell_qdata[%d]: %08X\n", i,
1266 *((u32 *)(ice_tx_drbell_q_ctx + (i * sizeof(u32)))));
1272 /* LAN Tx Doorbell Queue Context info */
1273 static const struct ice_ctx_ele ice_tx_drbell_q_ctx_info[] = {
1274 /* Field Width LSB */
1275 ICE_CTX_STORE(ice_tx_drbell_q_ctx, base, 57, 0),
1276 ICE_CTX_STORE(ice_tx_drbell_q_ctx, ring_len, 13, 64),
1277 ICE_CTX_STORE(ice_tx_drbell_q_ctx, pf_num, 3, 80),
1278 ICE_CTX_STORE(ice_tx_drbell_q_ctx, vf_num, 8, 84),
1279 ICE_CTX_STORE(ice_tx_drbell_q_ctx, vmvf_type, 2, 94),
1280 ICE_CTX_STORE(ice_tx_drbell_q_ctx, cpuid, 8, 96),
1281 ICE_CTX_STORE(ice_tx_drbell_q_ctx, tph_desc_rd, 1, 104),
1282 ICE_CTX_STORE(ice_tx_drbell_q_ctx, tph_desc_wr, 1, 108),
1283 ICE_CTX_STORE(ice_tx_drbell_q_ctx, db_q_en, 1, 112),
1284 ICE_CTX_STORE(ice_tx_drbell_q_ctx, rd_head, 13, 128),
1285 ICE_CTX_STORE(ice_tx_drbell_q_ctx, rd_tail, 13, 144),
1290 * ice_write_tx_drbell_q_ctx
1291 * @hw: pointer to the hardware structure
1292 * @tx_drbell_q_ctx: pointer to the doorbell queue context
1293 * @tx_drbell_q_index: the index of the doorbell queue
1295 * Converts doorbell queue context from sparse to dense structure and then
1296 * writes it to HW register space
1299 ice_write_tx_drbell_q_ctx(struct ice_hw *hw,
1300 struct ice_tx_drbell_q_ctx *tx_drbell_q_ctx,
1301 u32 tx_drbell_q_index)
1303 u8 ctx_buf[ICE_TX_DRBELL_Q_CTX_SIZE_DWORDS * sizeof(u32)] = { 0 };
1305 ice_set_ctx(hw, (u8 *)tx_drbell_q_ctx, ctx_buf,
1306 ice_tx_drbell_q_ctx_info);
1307 return ice_copy_tx_drbell_q_ctx_to_hw(hw, ctx_buf, tx_drbell_q_index);
1311 * ice_clear_tx_drbell_q_ctx
1312 * @hw: pointer to the hardware structure
1313 * @tx_drbell_q_index: the index of the doorbell queue to clear
1315 * Clears doorbell queue context in HW register space
1318 ice_clear_tx_drbell_q_ctx(struct ice_hw *hw, u32 tx_drbell_q_index)
1322 if (tx_drbell_q_index > QTX_COMM_DBLQ_DBELL_MAX_INDEX)
1323 return ICE_ERR_PARAM;
1325 /* Clear each dword register separately */
1326 for (i = 0; i < ICE_TX_DRBELL_Q_CTX_SIZE_DWORDS; i++)
1327 wr32(hw, QTX_COMM_DBLQ_CNTX(i, tx_drbell_q_index), 0);
1332 /* FW Admin Queue command wrappers */
1335 * ice_aq_send_cmd - send FW Admin Queue command to FW Admin Queue
1336 * @hw: pointer to the HW struct
1337 * @desc: descriptor describing the command
1338 * @buf: buffer to use for indirect commands (NULL for direct commands)
1339 * @buf_size: size of buffer for indirect commands (0 for direct commands)
1340 * @cd: pointer to command details structure
1342 * Helper function to send FW Admin Queue commands to the FW Admin Queue.
1345 ice_aq_send_cmd(struct ice_hw *hw, struct ice_aq_desc *desc, void *buf,
1346 u16 buf_size, struct ice_sq_cd *cd)
1348 if (hw->aq_send_cmd_fn) {
1349 enum ice_status status = ICE_ERR_NOT_READY;
1350 u16 retval = ICE_AQ_RC_OK;
1352 ice_acquire_lock(&hw->adminq.sq_lock);
1353 if (!hw->aq_send_cmd_fn(hw->aq_send_cmd_param, desc,
1355 retval = LE16_TO_CPU(desc->retval);
1356 /* strip off FW internal code */
1359 if (retval == ICE_AQ_RC_OK)
1360 status = ICE_SUCCESS;
1362 status = ICE_ERR_AQ_ERROR;
1365 hw->adminq.sq_last_status = (enum ice_aq_err)retval;
1366 ice_release_lock(&hw->adminq.sq_lock);
1370 return ice_sq_send_cmd(hw, &hw->adminq, desc, buf, buf_size, cd);
1375 * @hw: pointer to the HW struct
1376 * @cd: pointer to command details structure or NULL
1378 * Get the firmware version (0x0001) from the admin queue commands
1380 enum ice_status ice_aq_get_fw_ver(struct ice_hw *hw, struct ice_sq_cd *cd)
1382 struct ice_aqc_get_ver *resp;
1383 struct ice_aq_desc desc;
1384 enum ice_status status;
1386 resp = &desc.params.get_ver;
1388 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_ver);
1390 status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
1393 hw->fw_branch = resp->fw_branch;
1394 hw->fw_maj_ver = resp->fw_major;
1395 hw->fw_min_ver = resp->fw_minor;
1396 hw->fw_patch = resp->fw_patch;
1397 hw->fw_build = LE32_TO_CPU(resp->fw_build);
1398 hw->api_branch = resp->api_branch;
1399 hw->api_maj_ver = resp->api_major;
1400 hw->api_min_ver = resp->api_minor;
1401 hw->api_patch = resp->api_patch;
1408 * ice_aq_send_driver_ver
1409 * @hw: pointer to the HW struct
1410 * @dv: driver's major, minor version
1411 * @cd: pointer to command details structure or NULL
1413 * Send the driver version (0x0002) to the firmware
1416 ice_aq_send_driver_ver(struct ice_hw *hw, struct ice_driver_ver *dv,
1417 struct ice_sq_cd *cd)
1419 struct ice_aqc_driver_ver *cmd;
1420 struct ice_aq_desc desc;
1423 cmd = &desc.params.driver_ver;
1426 return ICE_ERR_PARAM;
1428 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_driver_ver);
1430 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
1431 cmd->major_ver = dv->major_ver;
1432 cmd->minor_ver = dv->minor_ver;
1433 cmd->build_ver = dv->build_ver;
1434 cmd->subbuild_ver = dv->subbuild_ver;
1437 while (len < sizeof(dv->driver_string) &&
1438 IS_ASCII(dv->driver_string[len]) && dv->driver_string[len])
1441 return ice_aq_send_cmd(hw, &desc, dv->driver_string, len, cd);
1446 * @hw: pointer to the HW struct
1447 * @unloading: is the driver unloading itself
1449 * Tell the Firmware that we're shutting down the AdminQ and whether
1450 * or not the driver is unloading as well (0x0003).
1452 enum ice_status ice_aq_q_shutdown(struct ice_hw *hw, bool unloading)
1454 struct ice_aqc_q_shutdown *cmd;
1455 struct ice_aq_desc desc;
1457 cmd = &desc.params.q_shutdown;
1459 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_q_shutdown);
1462 cmd->driver_unloading = ICE_AQC_DRIVER_UNLOADING;
1464 return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
1469 * @hw: pointer to the HW struct
1471 * @access: access type
1472 * @sdp_number: resource number
1473 * @timeout: the maximum time in ms that the driver may hold the resource
1474 * @cd: pointer to command details structure or NULL
1476 * Requests common resource using the admin queue commands (0x0008).
1477 * When attempting to acquire the Global Config Lock, the driver can
1478 * learn of three states:
1479 * 1) ICE_SUCCESS - acquired lock, and can perform download package
1480 * 2) ICE_ERR_AQ_ERROR - did not get lock, driver should fail to load
1481 * 3) ICE_ERR_AQ_NO_WORK - did not get lock, but another driver has
1482 * successfully downloaded the package; the driver does
1483 * not have to download the package and can continue
1486 * Note that if the caller is in an acquire lock, perform action, release lock
1487 * phase of operation, it is possible that the FW may detect a timeout and issue
1488 * a CORER. In this case, the driver will receive a CORER interrupt and will
1489 * have to determine its cause. The calling thread that is handling this flow
1490 * will likely get an error propagated back to it indicating the Download
1491 * Package, Update Package or the Release Resource AQ commands timed out.
1493 static enum ice_status
1494 ice_aq_req_res(struct ice_hw *hw, enum ice_aq_res_ids res,
1495 enum ice_aq_res_access_type access, u8 sdp_number, u32 *timeout,
1496 struct ice_sq_cd *cd)
1498 struct ice_aqc_req_res *cmd_resp;
1499 struct ice_aq_desc desc;
1500 enum ice_status status;
1502 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1504 cmd_resp = &desc.params.res_owner;
1506 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_req_res);
1508 cmd_resp->res_id = CPU_TO_LE16(res);
1509 cmd_resp->access_type = CPU_TO_LE16(access);
1510 cmd_resp->res_number = CPU_TO_LE32(sdp_number);
1511 cmd_resp->timeout = CPU_TO_LE32(*timeout);
1514 status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
1516 /* The completion specifies the maximum time in ms that the driver
1517 * may hold the resource in the Timeout field.
1520 /* Global config lock response utilizes an additional status field.
1522 * If the Global config lock resource is held by some other driver, the
1523 * command completes with ICE_AQ_RES_GLBL_IN_PROG in the status field
1524 * and the timeout field indicates the maximum time the current owner
1525 * of the resource has to free it.
1527 if (res == ICE_GLOBAL_CFG_LOCK_RES_ID) {
1528 if (LE16_TO_CPU(cmd_resp->status) == ICE_AQ_RES_GLBL_SUCCESS) {
1529 *timeout = LE32_TO_CPU(cmd_resp->timeout);
1531 } else if (LE16_TO_CPU(cmd_resp->status) ==
1532 ICE_AQ_RES_GLBL_IN_PROG) {
1533 *timeout = LE32_TO_CPU(cmd_resp->timeout);
1534 return ICE_ERR_AQ_ERROR;
1535 } else if (LE16_TO_CPU(cmd_resp->status) ==
1536 ICE_AQ_RES_GLBL_DONE) {
1537 return ICE_ERR_AQ_NO_WORK;
1540 /* invalid FW response, force a timeout immediately */
1542 return ICE_ERR_AQ_ERROR;
1545 /* If the resource is held by some other driver, the command completes
1546 * with a busy return value and the timeout field indicates the maximum
1547 * time the current owner of the resource has to free it.
1549 if (!status || hw->adminq.sq_last_status == ICE_AQ_RC_EBUSY)
1550 *timeout = LE32_TO_CPU(cmd_resp->timeout);
1556 * ice_aq_release_res
1557 * @hw: pointer to the HW struct
1559 * @sdp_number: resource number
1560 * @cd: pointer to command details structure or NULL
1562 * release common resource using the admin queue commands (0x0009)
1564 static enum ice_status
1565 ice_aq_release_res(struct ice_hw *hw, enum ice_aq_res_ids res, u8 sdp_number,
1566 struct ice_sq_cd *cd)
1568 struct ice_aqc_req_res *cmd;
1569 struct ice_aq_desc desc;
1571 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1573 cmd = &desc.params.res_owner;
1575 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_release_res);
1577 cmd->res_id = CPU_TO_LE16(res);
1578 cmd->res_number = CPU_TO_LE32(sdp_number);
1580 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
1585 * @hw: pointer to the HW structure
1587 * @access: access type (read or write)
1588 * @timeout: timeout in milliseconds
1590 * This function will attempt to acquire the ownership of a resource.
1593 ice_acquire_res(struct ice_hw *hw, enum ice_aq_res_ids res,
1594 enum ice_aq_res_access_type access, u32 timeout)
1596 #define ICE_RES_POLLING_DELAY_MS 10
1597 u32 delay = ICE_RES_POLLING_DELAY_MS;
1598 u32 time_left = timeout;
1599 enum ice_status status;
1601 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1603 status = ice_aq_req_res(hw, res, access, 0, &time_left, NULL);
1605 /* A return code of ICE_ERR_AQ_NO_WORK means that another driver has
1606 * previously acquired the resource and performed any necessary updates;
1607 * in this case the caller does not obtain the resource and has no
1608 * further work to do.
1610 if (status == ICE_ERR_AQ_NO_WORK)
1611 goto ice_acquire_res_exit;
1614 ice_debug(hw, ICE_DBG_RES,
1615 "resource %d acquire type %d failed.\n", res, access);
1617 /* If necessary, poll until the current lock owner timeouts */
1618 timeout = time_left;
1619 while (status && timeout && time_left) {
1620 ice_msec_delay(delay, true);
1621 timeout = (timeout > delay) ? timeout - delay : 0;
1622 status = ice_aq_req_res(hw, res, access, 0, &time_left, NULL);
1624 if (status == ICE_ERR_AQ_NO_WORK)
1625 /* lock free, but no work to do */
1632 if (status && status != ICE_ERR_AQ_NO_WORK)
1633 ice_debug(hw, ICE_DBG_RES, "resource acquire timed out.\n");
1635 ice_acquire_res_exit:
1636 if (status == ICE_ERR_AQ_NO_WORK) {
1637 if (access == ICE_RES_WRITE)
1638 ice_debug(hw, ICE_DBG_RES,
1639 "resource indicates no work to do.\n");
1641 ice_debug(hw, ICE_DBG_RES,
1642 "Warning: ICE_ERR_AQ_NO_WORK not expected\n");
1649 * @hw: pointer to the HW structure
1652 * This function will release a resource using the proper Admin Command.
1654 void ice_release_res(struct ice_hw *hw, enum ice_aq_res_ids res)
1656 enum ice_status status;
1657 u32 total_delay = 0;
1659 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1661 status = ice_aq_release_res(hw, res, 0, NULL);
1663 /* there are some rare cases when trying to release the resource
1664 * results in an admin queue timeout, so handle them correctly
1666 while ((status == ICE_ERR_AQ_TIMEOUT) &&
1667 (total_delay < hw->adminq.sq_cmd_timeout)) {
1668 ice_msec_delay(1, true);
1669 status = ice_aq_release_res(hw, res, 0, NULL);
1675 * ice_aq_alloc_free_res - command to allocate/free resources
1676 * @hw: pointer to the HW struct
1677 * @num_entries: number of resource entries in buffer
1678 * @buf: Indirect buffer to hold data parameters and response
1679 * @buf_size: size of buffer for indirect commands
1680 * @opc: pass in the command opcode
1681 * @cd: pointer to command details structure or NULL
1683 * Helper function to allocate/free resources using the admin queue commands
1686 ice_aq_alloc_free_res(struct ice_hw *hw, u16 num_entries,
1687 struct ice_aqc_alloc_free_res_elem *buf, u16 buf_size,
1688 enum ice_adminq_opc opc, struct ice_sq_cd *cd)
1690 struct ice_aqc_alloc_free_res_cmd *cmd;
1691 struct ice_aq_desc desc;
1693 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1695 cmd = &desc.params.sw_res_ctrl;
1698 return ICE_ERR_PARAM;
1700 if (buf_size < (num_entries * sizeof(buf->elem[0])))
1701 return ICE_ERR_PARAM;
1703 ice_fill_dflt_direct_cmd_desc(&desc, opc);
1705 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
1707 cmd->num_entries = CPU_TO_LE16(num_entries);
1709 return ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
1713 * ice_alloc_hw_res - allocate resource
1714 * @hw: pointer to the HW struct
1715 * @type: type of resource
1716 * @num: number of resources to allocate
1717 * @btm: allocate from bottom
1718 * @res: pointer to array that will receive the resources
1721 ice_alloc_hw_res(struct ice_hw *hw, u16 type, u16 num, bool btm, u16 *res)
1723 struct ice_aqc_alloc_free_res_elem *buf;
1724 enum ice_status status;
1727 buf_len = ice_struct_size(buf, elem, num - 1);
1728 buf = (struct ice_aqc_alloc_free_res_elem *)
1729 ice_malloc(hw, buf_len);
1731 return ICE_ERR_NO_MEMORY;
1733 /* Prepare buffer to allocate resource. */
1734 buf->num_elems = CPU_TO_LE16(num);
1735 buf->res_type = CPU_TO_LE16(type | ICE_AQC_RES_TYPE_FLAG_DEDICATED |
1736 ICE_AQC_RES_TYPE_FLAG_IGNORE_INDEX);
1738 buf->res_type |= CPU_TO_LE16(ICE_AQC_RES_TYPE_FLAG_SCAN_BOTTOM);
1740 status = ice_aq_alloc_free_res(hw, 1, buf, buf_len,
1741 ice_aqc_opc_alloc_res, NULL);
1743 goto ice_alloc_res_exit;
1745 ice_memcpy(res, buf->elem, sizeof(buf->elem) * num,
1746 ICE_NONDMA_TO_NONDMA);
1754 * ice_free_hw_res - free allocated HW resource
1755 * @hw: pointer to the HW struct
1756 * @type: type of resource to free
1757 * @num: number of resources
1758 * @res: pointer to array that contains the resources to free
1760 enum ice_status ice_free_hw_res(struct ice_hw *hw, u16 type, u16 num, u16 *res)
1762 struct ice_aqc_alloc_free_res_elem *buf;
1763 enum ice_status status;
1766 buf_len = ice_struct_size(buf, elem, num - 1);
1767 buf = (struct ice_aqc_alloc_free_res_elem *)ice_malloc(hw, buf_len);
1769 return ICE_ERR_NO_MEMORY;
1771 /* Prepare buffer to free resource. */
1772 buf->num_elems = CPU_TO_LE16(num);
1773 buf->res_type = CPU_TO_LE16(type);
1774 ice_memcpy(buf->elem, res, sizeof(buf->elem) * num,
1775 ICE_NONDMA_TO_NONDMA);
1777 status = ice_aq_alloc_free_res(hw, num, buf, buf_len,
1778 ice_aqc_opc_free_res, NULL);
1780 ice_debug(hw, ICE_DBG_SW, "CQ CMD Buffer:\n");
1787 * ice_get_num_per_func - determine number of resources per PF
1788 * @hw: pointer to the HW structure
1789 * @max: value to be evenly split between each PF
1791 * Determine the number of valid functions by going through the bitmap returned
1792 * from parsing capabilities and use this to calculate the number of resources
1793 * per PF based on the max value passed in.
1795 static u32 ice_get_num_per_func(struct ice_hw *hw, u32 max)
1799 #define ICE_CAPS_VALID_FUNCS_M 0xFF
1800 funcs = ice_hweight8(hw->dev_caps.common_cap.valid_functions &
1801 ICE_CAPS_VALID_FUNCS_M);
1810 * ice_parse_caps - parse function/device capabilities
1811 * @hw: pointer to the HW struct
1812 * @buf: pointer to a buffer containing function/device capability records
1813 * @cap_count: number of capability records in the list
1814 * @opc: type of capabilities list to parse
1816 * Helper function to parse function(0x000a)/device(0x000b) capabilities list.
1819 ice_parse_caps(struct ice_hw *hw, void *buf, u32 cap_count,
1820 enum ice_adminq_opc opc)
1822 struct ice_aqc_list_caps_elem *cap_resp;
1823 struct ice_hw_func_caps *func_p = NULL;
1824 struct ice_hw_dev_caps *dev_p = NULL;
1825 struct ice_hw_common_caps *caps;
1832 cap_resp = (struct ice_aqc_list_caps_elem *)buf;
1834 if (opc == ice_aqc_opc_list_dev_caps) {
1835 dev_p = &hw->dev_caps;
1836 caps = &dev_p->common_cap;
1838 ice_memset(dev_p, 0, sizeof(*dev_p), ICE_NONDMA_MEM);
1841 } else if (opc == ice_aqc_opc_list_func_caps) {
1842 func_p = &hw->func_caps;
1843 caps = &func_p->common_cap;
1845 ice_memset(func_p, 0, sizeof(*func_p), ICE_NONDMA_MEM);
1847 prefix = "func cap";
1849 ice_debug(hw, ICE_DBG_INIT, "wrong opcode\n");
1853 for (i = 0; caps && i < cap_count; i++, cap_resp++) {
1854 u32 logical_id = LE32_TO_CPU(cap_resp->logical_id);
1855 u32 phys_id = LE32_TO_CPU(cap_resp->phys_id);
1856 u32 number = LE32_TO_CPU(cap_resp->number);
1857 u16 cap = LE16_TO_CPU(cap_resp->cap);
1860 case ICE_AQC_CAPS_VALID_FUNCTIONS:
1861 caps->valid_functions = number;
1862 ice_debug(hw, ICE_DBG_INIT,
1863 "%s: valid_functions (bitmap) = %d\n", prefix,
1864 caps->valid_functions);
1866 /* store func count for resource management purposes */
1868 dev_p->num_funcs = ice_hweight32(number);
1870 case ICE_AQC_CAPS_VSI:
1872 dev_p->num_vsi_allocd_to_host = number;
1873 ice_debug(hw, ICE_DBG_INIT,
1874 "%s: num_vsi_allocd_to_host = %d\n",
1876 dev_p->num_vsi_allocd_to_host);
1877 } else if (func_p) {
1878 func_p->guar_num_vsi =
1879 ice_get_num_per_func(hw, ICE_MAX_VSI);
1880 ice_debug(hw, ICE_DBG_INIT,
1881 "%s: guar_num_vsi (fw) = %d\n",
1883 ice_debug(hw, ICE_DBG_INIT,
1884 "%s: guar_num_vsi = %d\n",
1885 prefix, func_p->guar_num_vsi);
1888 case ICE_AQC_CAPS_DCB:
1889 caps->dcb = (number == 1);
1890 caps->active_tc_bitmap = logical_id;
1891 caps->maxtc = phys_id;
1892 ice_debug(hw, ICE_DBG_INIT,
1893 "%s: dcb = %d\n", prefix, caps->dcb);
1894 ice_debug(hw, ICE_DBG_INIT,
1895 "%s: active_tc_bitmap = %d\n", prefix,
1896 caps->active_tc_bitmap);
1897 ice_debug(hw, ICE_DBG_INIT,
1898 "%s: maxtc = %d\n", prefix, caps->maxtc);
1900 case ICE_AQC_CAPS_RSS:
1901 caps->rss_table_size = number;
1902 caps->rss_table_entry_width = logical_id;
1903 ice_debug(hw, ICE_DBG_INIT,
1904 "%s: rss_table_size = %d\n", prefix,
1905 caps->rss_table_size);
1906 ice_debug(hw, ICE_DBG_INIT,
1907 "%s: rss_table_entry_width = %d\n", prefix,
1908 caps->rss_table_entry_width);
1910 case ICE_AQC_CAPS_RXQS:
1911 caps->num_rxq = number;
1912 caps->rxq_first_id = phys_id;
1913 ice_debug(hw, ICE_DBG_INIT,
1914 "%s: num_rxq = %d\n", prefix,
1916 ice_debug(hw, ICE_DBG_INIT,
1917 "%s: rxq_first_id = %d\n", prefix,
1918 caps->rxq_first_id);
1920 case ICE_AQC_CAPS_TXQS:
1921 caps->num_txq = number;
1922 caps->txq_first_id = phys_id;
1923 ice_debug(hw, ICE_DBG_INIT,
1924 "%s: num_txq = %d\n", prefix,
1926 ice_debug(hw, ICE_DBG_INIT,
1927 "%s: txq_first_id = %d\n", prefix,
1928 caps->txq_first_id);
1930 case ICE_AQC_CAPS_MSIX:
1931 caps->num_msix_vectors = number;
1932 caps->msix_vector_first_id = phys_id;
1933 ice_debug(hw, ICE_DBG_INIT,
1934 "%s: num_msix_vectors = %d\n", prefix,
1935 caps->num_msix_vectors);
1936 ice_debug(hw, ICE_DBG_INIT,
1937 "%s: msix_vector_first_id = %d\n", prefix,
1938 caps->msix_vector_first_id);
1940 case ICE_AQC_CAPS_FD:
1942 dev_p->num_flow_director_fltr = number;
1943 ice_debug(hw, ICE_DBG_INIT,
1944 "%s: num_flow_director_fltr = %d\n",
1946 dev_p->num_flow_director_fltr);
1951 if (hw->dcf_enabled)
1953 reg_val = rd32(hw, GLQF_FD_SIZE);
1954 val = (reg_val & GLQF_FD_SIZE_FD_GSIZE_M) >>
1955 GLQF_FD_SIZE_FD_GSIZE_S;
1956 func_p->fd_fltr_guar =
1957 ice_get_num_per_func(hw, val);
1958 val = (reg_val & GLQF_FD_SIZE_FD_BSIZE_M) >>
1959 GLQF_FD_SIZE_FD_BSIZE_S;
1960 func_p->fd_fltr_best_effort = val;
1961 ice_debug(hw, ICE_DBG_INIT,
1962 "%s: fd_fltr_guar = %d\n",
1963 prefix, func_p->fd_fltr_guar);
1964 ice_debug(hw, ICE_DBG_INIT,
1965 "%s: fd_fltr_best_effort = %d\n",
1966 prefix, func_p->fd_fltr_best_effort);
1969 case ICE_AQC_CAPS_MAX_MTU:
1970 caps->max_mtu = number;
1971 ice_debug(hw, ICE_DBG_INIT, "%s: max_mtu = %d\n",
1972 prefix, caps->max_mtu);
1975 ice_debug(hw, ICE_DBG_INIT,
1976 "%s: unknown capability[%d]: 0x%x\n", prefix,
1982 /* Re-calculate capabilities that are dependent on the number of
1983 * physical ports; i.e. some features are not supported or function
1984 * differently on devices with more than 4 ports.
1986 if (hw->dev_caps.num_funcs > 4) {
1987 /* Max 4 TCs per port */
1989 ice_debug(hw, ICE_DBG_INIT,
1990 "%s: maxtc = %d (based on #ports)\n", prefix,
1996 * ice_aq_discover_caps - query function/device capabilities
1997 * @hw: pointer to the HW struct
1998 * @buf: a virtual buffer to hold the capabilities
1999 * @buf_size: Size of the virtual buffer
2000 * @cap_count: cap count needed if AQ err==ENOMEM
2001 * @opc: capabilities type to discover - pass in the command opcode
2002 * @cd: pointer to command details structure or NULL
2004 * Get the function(0x000a)/device(0x000b) capabilities description from
2007 static enum ice_status
2008 ice_aq_discover_caps(struct ice_hw *hw, void *buf, u16 buf_size, u32 *cap_count,
2009 enum ice_adminq_opc opc, struct ice_sq_cd *cd)
2011 struct ice_aqc_list_caps *cmd;
2012 struct ice_aq_desc desc;
2013 enum ice_status status;
2015 cmd = &desc.params.get_cap;
2017 if (opc != ice_aqc_opc_list_func_caps &&
2018 opc != ice_aqc_opc_list_dev_caps)
2019 return ICE_ERR_PARAM;
2021 ice_fill_dflt_direct_cmd_desc(&desc, opc);
2023 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
2025 ice_parse_caps(hw, buf, LE32_TO_CPU(cmd->count), opc);
2026 else if (hw->adminq.sq_last_status == ICE_AQ_RC_ENOMEM)
2027 *cap_count = LE32_TO_CPU(cmd->count);
2032 * ice_discover_caps - get info about the HW
2033 * @hw: pointer to the hardware structure
2034 * @opc: capabilities type to discover - pass in the command opcode
2036 static enum ice_status
2037 ice_discover_caps(struct ice_hw *hw, enum ice_adminq_opc opc)
2039 enum ice_status status;
2044 /* The driver doesn't know how many capabilities the device will return
2045 * so the buffer size required isn't known ahead of time. The driver
2046 * starts with cbuf_len and if this turns out to be insufficient, the
2047 * device returns ICE_AQ_RC_ENOMEM and also the cap_count it needs.
2048 * The driver then allocates the buffer based on the count and retries
2049 * the operation. So it follows that the retry count is 2.
2051 #define ICE_GET_CAP_BUF_COUNT 40
2052 #define ICE_GET_CAP_RETRY_COUNT 2
2054 cap_count = ICE_GET_CAP_BUF_COUNT;
2055 retries = ICE_GET_CAP_RETRY_COUNT;
2060 cbuf_len = (u16)(cap_count *
2061 sizeof(struct ice_aqc_list_caps_elem));
2062 cbuf = ice_malloc(hw, cbuf_len);
2064 return ICE_ERR_NO_MEMORY;
2066 status = ice_aq_discover_caps(hw, cbuf, cbuf_len, &cap_count,
2070 if (!status || hw->adminq.sq_last_status != ICE_AQ_RC_ENOMEM)
2073 /* If ENOMEM is returned, try again with bigger buffer */
2074 } while (--retries);
2080 * ice_set_safe_mode_caps - Override dev/func capabilities when in safe mode
2081 * @hw: pointer to the hardware structure
2083 void ice_set_safe_mode_caps(struct ice_hw *hw)
2085 struct ice_hw_func_caps *func_caps = &hw->func_caps;
2086 struct ice_hw_dev_caps *dev_caps = &hw->dev_caps;
2087 u32 valid_func, rxq_first_id, txq_first_id;
2088 u32 msix_vector_first_id, max_mtu;
2091 /* cache some func_caps values that should be restored after memset */
2092 valid_func = func_caps->common_cap.valid_functions;
2093 txq_first_id = func_caps->common_cap.txq_first_id;
2094 rxq_first_id = func_caps->common_cap.rxq_first_id;
2095 msix_vector_first_id = func_caps->common_cap.msix_vector_first_id;
2096 max_mtu = func_caps->common_cap.max_mtu;
2098 /* unset func capabilities */
2099 memset(func_caps, 0, sizeof(*func_caps));
2101 /* restore cached values */
2102 func_caps->common_cap.valid_functions = valid_func;
2103 func_caps->common_cap.txq_first_id = txq_first_id;
2104 func_caps->common_cap.rxq_first_id = rxq_first_id;
2105 func_caps->common_cap.msix_vector_first_id = msix_vector_first_id;
2106 func_caps->common_cap.max_mtu = max_mtu;
2108 /* one Tx and one Rx queue in safe mode */
2109 func_caps->common_cap.num_rxq = 1;
2110 func_caps->common_cap.num_txq = 1;
2112 /* two MSIX vectors, one for traffic and one for misc causes */
2113 func_caps->common_cap.num_msix_vectors = 2;
2114 func_caps->guar_num_vsi = 1;
2116 /* cache some dev_caps values that should be restored after memset */
2117 valid_func = dev_caps->common_cap.valid_functions;
2118 txq_first_id = dev_caps->common_cap.txq_first_id;
2119 rxq_first_id = dev_caps->common_cap.rxq_first_id;
2120 msix_vector_first_id = dev_caps->common_cap.msix_vector_first_id;
2121 max_mtu = dev_caps->common_cap.max_mtu;
2122 num_funcs = dev_caps->num_funcs;
2124 /* unset dev capabilities */
2125 memset(dev_caps, 0, sizeof(*dev_caps));
2127 /* restore cached values */
2128 dev_caps->common_cap.valid_functions = valid_func;
2129 dev_caps->common_cap.txq_first_id = txq_first_id;
2130 dev_caps->common_cap.rxq_first_id = rxq_first_id;
2131 dev_caps->common_cap.msix_vector_first_id = msix_vector_first_id;
2132 dev_caps->common_cap.max_mtu = max_mtu;
2133 dev_caps->num_funcs = num_funcs;
2135 /* one Tx and one Rx queue per function in safe mode */
2136 dev_caps->common_cap.num_rxq = num_funcs;
2137 dev_caps->common_cap.num_txq = num_funcs;
2139 /* two MSIX vectors per function */
2140 dev_caps->common_cap.num_msix_vectors = 2 * num_funcs;
2144 * ice_get_caps - get info about the HW
2145 * @hw: pointer to the hardware structure
2147 enum ice_status ice_get_caps(struct ice_hw *hw)
2149 enum ice_status status;
2151 status = ice_discover_caps(hw, ice_aqc_opc_list_dev_caps);
2153 status = ice_discover_caps(hw, ice_aqc_opc_list_func_caps);
2159 * ice_aq_manage_mac_write - manage MAC address write command
2160 * @hw: pointer to the HW struct
2161 * @mac_addr: MAC address to be written as LAA/LAA+WoL/Port address
2162 * @flags: flags to control write behavior
2163 * @cd: pointer to command details structure or NULL
2165 * This function is used to write MAC address to the NVM (0x0108).
2168 ice_aq_manage_mac_write(struct ice_hw *hw, const u8 *mac_addr, u8 flags,
2169 struct ice_sq_cd *cd)
2171 struct ice_aqc_manage_mac_write *cmd;
2172 struct ice_aq_desc desc;
2174 cmd = &desc.params.mac_write;
2175 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_manage_mac_write);
2178 ice_memcpy(cmd->mac_addr, mac_addr, ETH_ALEN, ICE_NONDMA_TO_DMA);
2180 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
2184 * ice_aq_clear_pxe_mode
2185 * @hw: pointer to the HW struct
2187 * Tell the firmware that the driver is taking over from PXE (0x0110).
2189 static enum ice_status ice_aq_clear_pxe_mode(struct ice_hw *hw)
2191 struct ice_aq_desc desc;
2193 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_clear_pxe_mode);
2194 desc.params.clear_pxe.rx_cnt = ICE_AQC_CLEAR_PXE_RX_CNT;
2196 return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
2200 * ice_clear_pxe_mode - clear pxe operations mode
2201 * @hw: pointer to the HW struct
2203 * Make sure all PXE mode settings are cleared, including things
2204 * like descriptor fetch/write-back mode.
2206 void ice_clear_pxe_mode(struct ice_hw *hw)
2208 if (ice_check_sq_alive(hw, &hw->adminq))
2209 ice_aq_clear_pxe_mode(hw);
2213 * ice_get_link_speed_based_on_phy_type - returns link speed
2214 * @phy_type_low: lower part of phy_type
2215 * @phy_type_high: higher part of phy_type
2217 * This helper function will convert an entry in PHY type structure
2218 * [phy_type_low, phy_type_high] to its corresponding link speed.
2219 * Note: In the structure of [phy_type_low, phy_type_high], there should
2220 * be one bit set, as this function will convert one PHY type to its
2222 * If no bit gets set, ICE_LINK_SPEED_UNKNOWN will be returned
2223 * If more than one bit gets set, ICE_LINK_SPEED_UNKNOWN will be returned
2226 ice_get_link_speed_based_on_phy_type(u64 phy_type_low, u64 phy_type_high)
2228 u16 speed_phy_type_high = ICE_AQ_LINK_SPEED_UNKNOWN;
2229 u16 speed_phy_type_low = ICE_AQ_LINK_SPEED_UNKNOWN;
2231 switch (phy_type_low) {
2232 case ICE_PHY_TYPE_LOW_100BASE_TX:
2233 case ICE_PHY_TYPE_LOW_100M_SGMII:
2234 speed_phy_type_low = ICE_AQ_LINK_SPEED_100MB;
2236 case ICE_PHY_TYPE_LOW_1000BASE_T:
2237 case ICE_PHY_TYPE_LOW_1000BASE_SX:
2238 case ICE_PHY_TYPE_LOW_1000BASE_LX:
2239 case ICE_PHY_TYPE_LOW_1000BASE_KX:
2240 case ICE_PHY_TYPE_LOW_1G_SGMII:
2241 speed_phy_type_low = ICE_AQ_LINK_SPEED_1000MB;
2243 case ICE_PHY_TYPE_LOW_2500BASE_T:
2244 case ICE_PHY_TYPE_LOW_2500BASE_X:
2245 case ICE_PHY_TYPE_LOW_2500BASE_KX:
2246 speed_phy_type_low = ICE_AQ_LINK_SPEED_2500MB;
2248 case ICE_PHY_TYPE_LOW_5GBASE_T:
2249 case ICE_PHY_TYPE_LOW_5GBASE_KR:
2250 speed_phy_type_low = ICE_AQ_LINK_SPEED_5GB;
2252 case ICE_PHY_TYPE_LOW_10GBASE_T:
2253 case ICE_PHY_TYPE_LOW_10G_SFI_DA:
2254 case ICE_PHY_TYPE_LOW_10GBASE_SR:
2255 case ICE_PHY_TYPE_LOW_10GBASE_LR:
2256 case ICE_PHY_TYPE_LOW_10GBASE_KR_CR1:
2257 case ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC:
2258 case ICE_PHY_TYPE_LOW_10G_SFI_C2C:
2259 speed_phy_type_low = ICE_AQ_LINK_SPEED_10GB;
2261 case ICE_PHY_TYPE_LOW_25GBASE_T:
2262 case ICE_PHY_TYPE_LOW_25GBASE_CR:
2263 case ICE_PHY_TYPE_LOW_25GBASE_CR_S:
2264 case ICE_PHY_TYPE_LOW_25GBASE_CR1:
2265 case ICE_PHY_TYPE_LOW_25GBASE_SR:
2266 case ICE_PHY_TYPE_LOW_25GBASE_LR:
2267 case ICE_PHY_TYPE_LOW_25GBASE_KR:
2268 case ICE_PHY_TYPE_LOW_25GBASE_KR_S:
2269 case ICE_PHY_TYPE_LOW_25GBASE_KR1:
2270 case ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC:
2271 case ICE_PHY_TYPE_LOW_25G_AUI_C2C:
2272 speed_phy_type_low = ICE_AQ_LINK_SPEED_25GB;
2274 case ICE_PHY_TYPE_LOW_40GBASE_CR4:
2275 case ICE_PHY_TYPE_LOW_40GBASE_SR4:
2276 case ICE_PHY_TYPE_LOW_40GBASE_LR4:
2277 case ICE_PHY_TYPE_LOW_40GBASE_KR4:
2278 case ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC:
2279 case ICE_PHY_TYPE_LOW_40G_XLAUI:
2280 speed_phy_type_low = ICE_AQ_LINK_SPEED_40GB;
2282 case ICE_PHY_TYPE_LOW_50GBASE_CR2:
2283 case ICE_PHY_TYPE_LOW_50GBASE_SR2:
2284 case ICE_PHY_TYPE_LOW_50GBASE_LR2:
2285 case ICE_PHY_TYPE_LOW_50GBASE_KR2:
2286 case ICE_PHY_TYPE_LOW_50G_LAUI2_AOC_ACC:
2287 case ICE_PHY_TYPE_LOW_50G_LAUI2:
2288 case ICE_PHY_TYPE_LOW_50G_AUI2_AOC_ACC:
2289 case ICE_PHY_TYPE_LOW_50G_AUI2:
2290 case ICE_PHY_TYPE_LOW_50GBASE_CP:
2291 case ICE_PHY_TYPE_LOW_50GBASE_SR:
2292 case ICE_PHY_TYPE_LOW_50GBASE_FR:
2293 case ICE_PHY_TYPE_LOW_50GBASE_LR:
2294 case ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4:
2295 case ICE_PHY_TYPE_LOW_50G_AUI1_AOC_ACC:
2296 case ICE_PHY_TYPE_LOW_50G_AUI1:
2297 speed_phy_type_low = ICE_AQ_LINK_SPEED_50GB;
2299 case ICE_PHY_TYPE_LOW_100GBASE_CR4:
2300 case ICE_PHY_TYPE_LOW_100GBASE_SR4:
2301 case ICE_PHY_TYPE_LOW_100GBASE_LR4:
2302 case ICE_PHY_TYPE_LOW_100GBASE_KR4:
2303 case ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC:
2304 case ICE_PHY_TYPE_LOW_100G_CAUI4:
2305 case ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC:
2306 case ICE_PHY_TYPE_LOW_100G_AUI4:
2307 case ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4:
2308 case ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4:
2309 case ICE_PHY_TYPE_LOW_100GBASE_CP2:
2310 case ICE_PHY_TYPE_LOW_100GBASE_SR2:
2311 case ICE_PHY_TYPE_LOW_100GBASE_DR:
2312 speed_phy_type_low = ICE_AQ_LINK_SPEED_100GB;
2315 speed_phy_type_low = ICE_AQ_LINK_SPEED_UNKNOWN;
2319 switch (phy_type_high) {
2320 case ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4:
2321 case ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC:
2322 case ICE_PHY_TYPE_HIGH_100G_CAUI2:
2323 case ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC:
2324 case ICE_PHY_TYPE_HIGH_100G_AUI2:
2325 speed_phy_type_high = ICE_AQ_LINK_SPEED_100GB;
2328 speed_phy_type_high = ICE_AQ_LINK_SPEED_UNKNOWN;
2332 if (speed_phy_type_low == ICE_AQ_LINK_SPEED_UNKNOWN &&
2333 speed_phy_type_high == ICE_AQ_LINK_SPEED_UNKNOWN)
2334 return ICE_AQ_LINK_SPEED_UNKNOWN;
2335 else if (speed_phy_type_low != ICE_AQ_LINK_SPEED_UNKNOWN &&
2336 speed_phy_type_high != ICE_AQ_LINK_SPEED_UNKNOWN)
2337 return ICE_AQ_LINK_SPEED_UNKNOWN;
2338 else if (speed_phy_type_low != ICE_AQ_LINK_SPEED_UNKNOWN &&
2339 speed_phy_type_high == ICE_AQ_LINK_SPEED_UNKNOWN)
2340 return speed_phy_type_low;
2342 return speed_phy_type_high;
2346 * ice_update_phy_type
2347 * @phy_type_low: pointer to the lower part of phy_type
2348 * @phy_type_high: pointer to the higher part of phy_type
2349 * @link_speeds_bitmap: targeted link speeds bitmap
2351 * Note: For the link_speeds_bitmap structure, you can check it at
2352 * [ice_aqc_get_link_status->link_speed]. Caller can pass in
2353 * link_speeds_bitmap include multiple speeds.
2355 * Each entry in this [phy_type_low, phy_type_high] structure will
2356 * present a certain link speed. This helper function will turn on bits
2357 * in [phy_type_low, phy_type_high] structure based on the value of
2358 * link_speeds_bitmap input parameter.
2361 ice_update_phy_type(u64 *phy_type_low, u64 *phy_type_high,
2362 u16 link_speeds_bitmap)
2369 /* We first check with low part of phy_type */
2370 for (index = 0; index <= ICE_PHY_TYPE_LOW_MAX_INDEX; index++) {
2371 pt_low = BIT_ULL(index);
2372 speed = ice_get_link_speed_based_on_phy_type(pt_low, 0);
2374 if (link_speeds_bitmap & speed)
2375 *phy_type_low |= BIT_ULL(index);
2378 /* We then check with high part of phy_type */
2379 for (index = 0; index <= ICE_PHY_TYPE_HIGH_MAX_INDEX; index++) {
2380 pt_high = BIT_ULL(index);
2381 speed = ice_get_link_speed_based_on_phy_type(0, pt_high);
2383 if (link_speeds_bitmap & speed)
2384 *phy_type_high |= BIT_ULL(index);
2389 * ice_aq_set_phy_cfg
2390 * @hw: pointer to the HW struct
2391 * @pi: port info structure of the interested logical port
2392 * @cfg: structure with PHY configuration data to be set
2393 * @cd: pointer to command details structure or NULL
2395 * Set the various PHY configuration parameters supported on the Port.
2396 * One or more of the Set PHY config parameters may be ignored in an MFP
2397 * mode as the PF may not have the privilege to set some of the PHY Config
2398 * parameters. This status will be indicated by the command response (0x0601).
2401 ice_aq_set_phy_cfg(struct ice_hw *hw, struct ice_port_info *pi,
2402 struct ice_aqc_set_phy_cfg_data *cfg, struct ice_sq_cd *cd)
2404 struct ice_aq_desc desc;
2405 enum ice_status status;
2408 return ICE_ERR_PARAM;
2410 /* Ensure that only valid bits of cfg->caps can be turned on. */
2411 if (cfg->caps & ~ICE_AQ_PHY_ENA_VALID_MASK) {
2412 ice_debug(hw, ICE_DBG_PHY,
2413 "Invalid bit is set in ice_aqc_set_phy_cfg_data->caps : 0x%x\n",
2416 cfg->caps &= ICE_AQ_PHY_ENA_VALID_MASK;
2419 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_phy_cfg);
2420 desc.params.set_phy.lport_num = pi->lport;
2421 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
2423 ice_debug(hw, ICE_DBG_LINK, "set phy cfg\n");
2424 ice_debug(hw, ICE_DBG_LINK, " phy_type_low = 0x%llx\n",
2425 (unsigned long long)LE64_TO_CPU(cfg->phy_type_low));
2426 ice_debug(hw, ICE_DBG_LINK, " phy_type_high = 0x%llx\n",
2427 (unsigned long long)LE64_TO_CPU(cfg->phy_type_high));
2428 ice_debug(hw, ICE_DBG_LINK, " caps = 0x%x\n", cfg->caps);
2429 ice_debug(hw, ICE_DBG_LINK, " low_power_ctrl_an = 0x%x\n",
2430 cfg->low_power_ctrl_an);
2431 ice_debug(hw, ICE_DBG_LINK, " eee_cap = 0x%x\n", cfg->eee_cap);
2432 ice_debug(hw, ICE_DBG_LINK, " eeer_value = 0x%x\n", cfg->eeer_value);
2433 ice_debug(hw, ICE_DBG_LINK, " link_fec_opt = 0x%x\n",
2436 status = ice_aq_send_cmd(hw, &desc, cfg, sizeof(*cfg), cd);
2438 if (hw->adminq.sq_last_status == ICE_AQ_RC_EMODE)
2439 status = ICE_SUCCESS;
2442 pi->phy.curr_user_phy_cfg = *cfg;
2448 * ice_update_link_info - update status of the HW network link
2449 * @pi: port info structure of the interested logical port
2451 enum ice_status ice_update_link_info(struct ice_port_info *pi)
2453 struct ice_link_status *li;
2454 enum ice_status status;
2457 return ICE_ERR_PARAM;
2459 li = &pi->phy.link_info;
2461 status = ice_aq_get_link_info(pi, true, NULL, NULL);
2465 if (li->link_info & ICE_AQ_MEDIA_AVAILABLE) {
2466 struct ice_aqc_get_phy_caps_data *pcaps;
2470 pcaps = (struct ice_aqc_get_phy_caps_data *)
2471 ice_malloc(hw, sizeof(*pcaps));
2473 return ICE_ERR_NO_MEMORY;
2475 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP,
2477 if (status == ICE_SUCCESS)
2478 ice_memcpy(li->module_type, &pcaps->module_type,
2479 sizeof(li->module_type),
2480 ICE_NONDMA_TO_NONDMA);
2482 ice_free(hw, pcaps);
2489 * ice_cache_phy_user_req
2490 * @pi: port information structure
2491 * @cache_data: PHY logging data
2492 * @cache_mode: PHY logging mode
2494 * Log the user request on (FC, FEC, SPEED) for later user.
2497 ice_cache_phy_user_req(struct ice_port_info *pi,
2498 struct ice_phy_cache_mode_data cache_data,
2499 enum ice_phy_cache_mode cache_mode)
2504 switch (cache_mode) {
2506 pi->phy.curr_user_fc_req = cache_data.data.curr_user_fc_req;
2508 case ICE_SPEED_MODE:
2509 pi->phy.curr_user_speed_req =
2510 cache_data.data.curr_user_speed_req;
2513 pi->phy.curr_user_fec_req = cache_data.data.curr_user_fec_req;
2521 * ice_caps_to_fc_mode
2522 * @caps: PHY capabilities
2524 * Convert PHY FC capabilities to ice FC mode
2526 enum ice_fc_mode ice_caps_to_fc_mode(u8 caps)
2528 if (caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE &&
2529 caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)
2532 if (caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE)
2533 return ICE_FC_TX_PAUSE;
2535 if (caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)
2536 return ICE_FC_RX_PAUSE;
2542 * ice_caps_to_fec_mode
2543 * @caps: PHY capabilities
2544 * @fec_options: Link FEC options
2546 * Convert PHY FEC capabilities to ice FEC mode
2548 enum ice_fec_mode ice_caps_to_fec_mode(u8 caps, u8 fec_options)
2550 if (caps & ICE_AQC_PHY_EN_AUTO_FEC)
2551 return ICE_FEC_AUTO;
2553 if (fec_options & (ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN |
2554 ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ |
2555 ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN |
2556 ICE_AQC_PHY_FEC_25G_KR_REQ))
2557 return ICE_FEC_BASER;
2559 if (fec_options & (ICE_AQC_PHY_FEC_25G_RS_528_REQ |
2560 ICE_AQC_PHY_FEC_25G_RS_544_REQ |
2561 ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN))
2564 return ICE_FEC_NONE;
2567 static enum ice_status
2568 ice_cfg_phy_fc(struct ice_port_info *pi, struct ice_aqc_set_phy_cfg_data *cfg,
2569 enum ice_fc_mode req_mode)
2571 struct ice_aqc_get_phy_caps_data *pcaps = NULL;
2572 struct ice_phy_cache_mode_data cache_data;
2573 enum ice_status status = ICE_SUCCESS;
2574 u8 pause_mask = 0x0;
2577 return ICE_ERR_BAD_PTR;
2579 pcaps = (struct ice_aqc_get_phy_caps_data *)
2580 ice_malloc(pi->hw, sizeof(*pcaps));
2582 return ICE_ERR_NO_MEMORY;
2584 /* Cache user FC request */
2585 cache_data.data.curr_user_fc_req = req_mode;
2586 ice_cache_phy_user_req(pi, cache_data, ICE_FC_MODE);
2590 /* Query the value of FC that both the NIC and attached media
2593 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP,
2598 pause_mask |= pcaps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE;
2599 pause_mask |= pcaps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE;
2602 pause_mask |= ICE_AQC_PHY_EN_TX_LINK_PAUSE;
2603 pause_mask |= ICE_AQC_PHY_EN_RX_LINK_PAUSE;
2605 case ICE_FC_RX_PAUSE:
2606 pause_mask |= ICE_AQC_PHY_EN_RX_LINK_PAUSE;
2608 case ICE_FC_TX_PAUSE:
2609 pause_mask |= ICE_AQC_PHY_EN_TX_LINK_PAUSE;
2615 /* clear the old pause settings */
2616 cfg->caps &= ~(ICE_AQC_PHY_EN_TX_LINK_PAUSE |
2617 ICE_AQC_PHY_EN_RX_LINK_PAUSE);
2619 /* set the new capabilities */
2620 cfg->caps |= pause_mask;
2623 ice_free(pi->hw, pcaps);
2629 * @pi: port information structure
2630 * @aq_failures: pointer to status code, specific to ice_set_fc routine
2631 * @ena_auto_link_update: enable automatic link update
2633 * Set the requested flow control mode.
2636 ice_set_fc(struct ice_port_info *pi, u8 *aq_failures, bool ena_auto_link_update)
2638 struct ice_aqc_set_phy_cfg_data cfg = { 0 };
2639 struct ice_aqc_get_phy_caps_data *pcaps;
2640 enum ice_status status;
2643 if (!pi || !aq_failures)
2644 return ICE_ERR_BAD_PTR;
2649 pcaps = (struct ice_aqc_get_phy_caps_data *)
2650 ice_malloc(hw, sizeof(*pcaps));
2652 return ICE_ERR_NO_MEMORY;
2654 /* Get the current PHY config */
2655 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps,
2658 *aq_failures = ICE_SET_FC_AQ_FAIL_GET;
2662 ice_copy_phy_caps_to_cfg(pi, pcaps, &cfg);
2664 /* Configure the set PHY data */
2665 status = ice_cfg_phy_fc(pi, &cfg, pi->fc.req_mode);
2667 if (status != ICE_ERR_BAD_PTR)
2668 *aq_failures = ICE_SET_FC_AQ_FAIL_GET;
2673 /* If the capabilities have changed, then set the new config */
2674 if (cfg.caps != pcaps->caps) {
2675 int retry_count, retry_max = 10;
2677 /* Auto restart link so settings take effect */
2678 if (ena_auto_link_update)
2679 cfg.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2681 status = ice_aq_set_phy_cfg(hw, pi, &cfg, NULL);
2683 *aq_failures = ICE_SET_FC_AQ_FAIL_SET;
2687 /* Update the link info
2688 * It sometimes takes a really long time for link to
2689 * come back from the atomic reset. Thus, we wait a
2692 for (retry_count = 0; retry_count < retry_max; retry_count++) {
2693 status = ice_update_link_info(pi);
2695 if (status == ICE_SUCCESS)
2698 ice_msec_delay(100, true);
2702 *aq_failures = ICE_SET_FC_AQ_FAIL_UPDATE;
2706 ice_free(hw, pcaps);
2711 * ice_phy_caps_equals_cfg
2712 * @phy_caps: PHY capabilities
2713 * @phy_cfg: PHY configuration
2715 * Helper function to determine if PHY capabilities matches PHY
2719 ice_phy_caps_equals_cfg(struct ice_aqc_get_phy_caps_data *phy_caps,
2720 struct ice_aqc_set_phy_cfg_data *phy_cfg)
2722 u8 caps_mask, cfg_mask;
2724 if (!phy_caps || !phy_cfg)
2727 /* These bits are not common between capabilities and configuration.
2728 * Do not use them to determine equality.
2730 caps_mask = ICE_AQC_PHY_CAPS_MASK & ~(ICE_AQC_PHY_AN_MODE |
2731 ICE_AQC_PHY_EN_MOD_QUAL);
2732 cfg_mask = ICE_AQ_PHY_ENA_VALID_MASK & ~ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2734 if (phy_caps->phy_type_low != phy_cfg->phy_type_low ||
2735 phy_caps->phy_type_high != phy_cfg->phy_type_high ||
2736 ((phy_caps->caps & caps_mask) != (phy_cfg->caps & cfg_mask)) ||
2737 phy_caps->low_power_ctrl_an != phy_cfg->low_power_ctrl_an ||
2738 phy_caps->eee_cap != phy_cfg->eee_cap ||
2739 phy_caps->eeer_value != phy_cfg->eeer_value ||
2740 phy_caps->link_fec_options != phy_cfg->link_fec_opt)
2747 * ice_copy_phy_caps_to_cfg - Copy PHY ability data to configuration data
2748 * @pi: port information structure
2749 * @caps: PHY ability structure to copy date from
2750 * @cfg: PHY configuration structure to copy data to
2752 * Helper function to copy AQC PHY get ability data to PHY set configuration
2756 ice_copy_phy_caps_to_cfg(struct ice_port_info *pi,
2757 struct ice_aqc_get_phy_caps_data *caps,
2758 struct ice_aqc_set_phy_cfg_data *cfg)
2760 if (!pi || !caps || !cfg)
2763 ice_memset(cfg, 0, sizeof(*cfg), ICE_NONDMA_MEM);
2764 cfg->phy_type_low = caps->phy_type_low;
2765 cfg->phy_type_high = caps->phy_type_high;
2766 cfg->caps = caps->caps;
2767 cfg->low_power_ctrl_an = caps->low_power_ctrl_an;
2768 cfg->eee_cap = caps->eee_cap;
2769 cfg->eeer_value = caps->eeer_value;
2770 cfg->link_fec_opt = caps->link_fec_options;
2771 cfg->module_compliance_enforcement =
2772 caps->module_compliance_enforcement;
2774 if (ice_fw_supports_link_override(pi->hw)) {
2775 struct ice_link_default_override_tlv tlv;
2777 if (ice_get_link_default_override(&tlv, pi))
2780 if (tlv.options & ICE_LINK_OVERRIDE_STRICT_MODE)
2781 cfg->module_compliance_enforcement |=
2782 ICE_LINK_OVERRIDE_STRICT_MODE;
2787 * ice_cfg_phy_fec - Configure PHY FEC data based on FEC mode
2788 * @pi: port information structure
2789 * @cfg: PHY configuration data to set FEC mode
2790 * @fec: FEC mode to configure
2793 ice_cfg_phy_fec(struct ice_port_info *pi, struct ice_aqc_set_phy_cfg_data *cfg,
2794 enum ice_fec_mode fec)
2796 struct ice_aqc_get_phy_caps_data *pcaps;
2797 enum ice_status status = ICE_SUCCESS;
2801 return ICE_ERR_BAD_PTR;
2805 pcaps = (struct ice_aqc_get_phy_caps_data *)
2806 ice_malloc(hw, sizeof(*pcaps));
2808 return ICE_ERR_NO_MEMORY;
2810 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP, pcaps,
2815 cfg->caps |= (pcaps->caps & ICE_AQC_PHY_EN_AUTO_FEC);
2816 cfg->link_fec_opt = pcaps->link_fec_options;
2820 /* Clear RS bits, and AND BASE-R ability
2821 * bits and OR request bits.
2823 cfg->link_fec_opt &= ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN |
2824 ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN;
2825 cfg->link_fec_opt |= ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ |
2826 ICE_AQC_PHY_FEC_25G_KR_REQ;
2829 /* Clear BASE-R bits, and AND RS ability
2830 * bits and OR request bits.
2832 cfg->link_fec_opt &= ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN;
2833 cfg->link_fec_opt |= ICE_AQC_PHY_FEC_25G_RS_528_REQ |
2834 ICE_AQC_PHY_FEC_25G_RS_544_REQ;
2837 /* Clear all FEC option bits. */
2838 cfg->link_fec_opt &= ~ICE_AQC_PHY_FEC_MASK;
2841 /* AND auto FEC bit, and all caps bits. */
2842 cfg->caps &= ICE_AQC_PHY_CAPS_MASK;
2843 cfg->link_fec_opt |= pcaps->link_fec_options;
2846 status = ICE_ERR_PARAM;
2850 if (fec == ICE_FEC_AUTO && ice_fw_supports_link_override(pi->hw)) {
2851 struct ice_link_default_override_tlv tlv;
2853 if (ice_get_link_default_override(&tlv, pi))
2856 if (!(tlv.options & ICE_LINK_OVERRIDE_STRICT_MODE) &&
2857 (tlv.options & ICE_LINK_OVERRIDE_EN))
2858 cfg->link_fec_opt = tlv.fec_options;
2862 ice_free(hw, pcaps);
2868 * ice_get_link_status - get status of the HW network link
2869 * @pi: port information structure
2870 * @link_up: pointer to bool (true/false = linkup/linkdown)
2872 * Variable link_up is true if link is up, false if link is down.
2873 * The variable link_up is invalid if status is non zero. As a
2874 * result of this call, link status reporting becomes enabled
2876 enum ice_status ice_get_link_status(struct ice_port_info *pi, bool *link_up)
2878 struct ice_phy_info *phy_info;
2879 enum ice_status status = ICE_SUCCESS;
2881 if (!pi || !link_up)
2882 return ICE_ERR_PARAM;
2884 phy_info = &pi->phy;
2886 if (phy_info->get_link_info) {
2887 status = ice_update_link_info(pi);
2890 ice_debug(pi->hw, ICE_DBG_LINK,
2891 "get link status error, status = %d\n",
2895 *link_up = phy_info->link_info.link_info & ICE_AQ_LINK_UP;
2901 * ice_aq_set_link_restart_an
2902 * @pi: pointer to the port information structure
2903 * @ena_link: if true: enable link, if false: disable link
2904 * @cd: pointer to command details structure or NULL
2906 * Sets up the link and restarts the Auto-Negotiation over the link.
2909 ice_aq_set_link_restart_an(struct ice_port_info *pi, bool ena_link,
2910 struct ice_sq_cd *cd)
2912 struct ice_aqc_restart_an *cmd;
2913 struct ice_aq_desc desc;
2915 cmd = &desc.params.restart_an;
2917 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_restart_an);
2919 cmd->cmd_flags = ICE_AQC_RESTART_AN_LINK_RESTART;
2920 cmd->lport_num = pi->lport;
2922 cmd->cmd_flags |= ICE_AQC_RESTART_AN_LINK_ENABLE;
2924 cmd->cmd_flags &= ~ICE_AQC_RESTART_AN_LINK_ENABLE;
2926 return ice_aq_send_cmd(pi->hw, &desc, NULL, 0, cd);
2930 * ice_aq_set_event_mask
2931 * @hw: pointer to the HW struct
2932 * @port_num: port number of the physical function
2933 * @mask: event mask to be set
2934 * @cd: pointer to command details structure or NULL
2936 * Set event mask (0x0613)
2939 ice_aq_set_event_mask(struct ice_hw *hw, u8 port_num, u16 mask,
2940 struct ice_sq_cd *cd)
2942 struct ice_aqc_set_event_mask *cmd;
2943 struct ice_aq_desc desc;
2945 cmd = &desc.params.set_event_mask;
2947 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_event_mask);
2949 cmd->lport_num = port_num;
2951 cmd->event_mask = CPU_TO_LE16(mask);
2952 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
2956 * ice_aq_set_mac_loopback
2957 * @hw: pointer to the HW struct
2958 * @ena_lpbk: Enable or Disable loopback
2959 * @cd: pointer to command details structure or NULL
2961 * Enable/disable loopback on a given port
2964 ice_aq_set_mac_loopback(struct ice_hw *hw, bool ena_lpbk, struct ice_sq_cd *cd)
2966 struct ice_aqc_set_mac_lb *cmd;
2967 struct ice_aq_desc desc;
2969 cmd = &desc.params.set_mac_lb;
2971 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_mac_lb);
2973 cmd->lb_mode = ICE_AQ_MAC_LB_EN;
2975 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
2979 * ice_aq_set_port_id_led
2980 * @pi: pointer to the port information
2981 * @is_orig_mode: is this LED set to original mode (by the net-list)
2982 * @cd: pointer to command details structure or NULL
2984 * Set LED value for the given port (0x06e9)
2987 ice_aq_set_port_id_led(struct ice_port_info *pi, bool is_orig_mode,
2988 struct ice_sq_cd *cd)
2990 struct ice_aqc_set_port_id_led *cmd;
2991 struct ice_hw *hw = pi->hw;
2992 struct ice_aq_desc desc;
2994 cmd = &desc.params.set_port_id_led;
2996 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_port_id_led);
2999 cmd->ident_mode = ICE_AQC_PORT_IDENT_LED_ORIG;
3001 cmd->ident_mode = ICE_AQC_PORT_IDENT_LED_BLINK;
3003 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
3008 * @hw: pointer to the HW struct
3009 * @lport: bits [7:0] = logical port, bit [8] = logical port valid
3010 * @bus_addr: I2C bus address of the eeprom (typically 0xA0, 0=topo default)
3011 * @mem_addr: I2C offset. lower 8 bits for address, 8 upper bits zero padding.
3013 * @set_page: set or ignore the page
3014 * @data: pointer to data buffer to be read/written to the I2C device.
3015 * @length: 1-16 for read, 1 for write.
3016 * @write: 0 read, 1 for write.
3017 * @cd: pointer to command details structure or NULL
3019 * Read/Write SFF EEPROM (0x06EE)
3022 ice_aq_sff_eeprom(struct ice_hw *hw, u16 lport, u8 bus_addr,
3023 u16 mem_addr, u8 page, u8 set_page, u8 *data, u8 length,
3024 bool write, struct ice_sq_cd *cd)
3026 struct ice_aqc_sff_eeprom *cmd;
3027 struct ice_aq_desc desc;
3028 enum ice_status status;
3030 if (!data || (mem_addr & 0xff00))
3031 return ICE_ERR_PARAM;
3033 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_sff_eeprom);
3034 cmd = &desc.params.read_write_sff_param;
3035 desc.flags = CPU_TO_LE16(ICE_AQ_FLAG_RD | ICE_AQ_FLAG_BUF);
3036 cmd->lport_num = (u8)(lport & 0xff);
3037 cmd->lport_num_valid = (u8)((lport >> 8) & 0x01);
3038 cmd->i2c_bus_addr = CPU_TO_LE16(((bus_addr >> 1) &
3039 ICE_AQC_SFF_I2CBUS_7BIT_M) |
3041 ICE_AQC_SFF_SET_EEPROM_PAGE_S) &
3042 ICE_AQC_SFF_SET_EEPROM_PAGE_M));
3043 cmd->i2c_mem_addr = CPU_TO_LE16(mem_addr & 0xff);
3044 cmd->eeprom_page = CPU_TO_LE16((u16)page << ICE_AQC_SFF_EEPROM_PAGE_S);
3046 cmd->i2c_bus_addr |= CPU_TO_LE16(ICE_AQC_SFF_IS_WRITE);
3048 status = ice_aq_send_cmd(hw, &desc, data, length, cd);
3053 * __ice_aq_get_set_rss_lut
3054 * @hw: pointer to the hardware structure
3055 * @vsi_id: VSI FW index
3056 * @lut_type: LUT table type
3057 * @lut: pointer to the LUT buffer provided by the caller
3058 * @lut_size: size of the LUT buffer
3059 * @glob_lut_idx: global LUT index
3060 * @set: set true to set the table, false to get the table
3062 * Internal function to get (0x0B05) or set (0x0B03) RSS look up table
3064 static enum ice_status
3065 __ice_aq_get_set_rss_lut(struct ice_hw *hw, u16 vsi_id, u8 lut_type, u8 *lut,
3066 u16 lut_size, u8 glob_lut_idx, bool set)
3068 struct ice_aqc_get_set_rss_lut *cmd_resp;
3069 struct ice_aq_desc desc;
3070 enum ice_status status;
3073 cmd_resp = &desc.params.get_set_rss_lut;
3076 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_rss_lut);
3077 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
3079 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_rss_lut);
3082 cmd_resp->vsi_id = CPU_TO_LE16(((vsi_id <<
3083 ICE_AQC_GSET_RSS_LUT_VSI_ID_S) &
3084 ICE_AQC_GSET_RSS_LUT_VSI_ID_M) |
3085 ICE_AQC_GSET_RSS_LUT_VSI_VALID);
3088 case ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_VSI:
3089 case ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF:
3090 case ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_GLOBAL:
3091 flags |= ((lut_type << ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_S) &
3092 ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_M);
3095 status = ICE_ERR_PARAM;
3096 goto ice_aq_get_set_rss_lut_exit;
3099 if (lut_type == ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_GLOBAL) {
3100 flags |= ((glob_lut_idx << ICE_AQC_GSET_RSS_LUT_GLOBAL_IDX_S) &
3101 ICE_AQC_GSET_RSS_LUT_GLOBAL_IDX_M);
3104 goto ice_aq_get_set_rss_lut_send;
3105 } else if (lut_type == ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF) {
3107 goto ice_aq_get_set_rss_lut_send;
3109 goto ice_aq_get_set_rss_lut_send;
3112 /* LUT size is only valid for Global and PF table types */
3114 case ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_128:
3115 flags |= (ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_128_FLAG <<
3116 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_S) &
3117 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_M;
3119 case ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_512:
3120 flags |= (ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_512_FLAG <<
3121 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_S) &
3122 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_M;
3124 case ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K:
3125 if (lut_type == ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF) {
3126 flags |= (ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K_FLAG <<
3127 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_S) &
3128 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_M;
3133 status = ICE_ERR_PARAM;
3134 goto ice_aq_get_set_rss_lut_exit;
3137 ice_aq_get_set_rss_lut_send:
3138 cmd_resp->flags = CPU_TO_LE16(flags);
3139 status = ice_aq_send_cmd(hw, &desc, lut, lut_size, NULL);
3141 ice_aq_get_set_rss_lut_exit:
3146 * ice_aq_get_rss_lut
3147 * @hw: pointer to the hardware structure
3148 * @vsi_handle: software VSI handle
3149 * @lut_type: LUT table type
3150 * @lut: pointer to the LUT buffer provided by the caller
3151 * @lut_size: size of the LUT buffer
3153 * get the RSS lookup table, PF or VSI type
3156 ice_aq_get_rss_lut(struct ice_hw *hw, u16 vsi_handle, u8 lut_type,
3157 u8 *lut, u16 lut_size)
3159 if (!ice_is_vsi_valid(hw, vsi_handle) || !lut)
3160 return ICE_ERR_PARAM;
3162 return __ice_aq_get_set_rss_lut(hw, ice_get_hw_vsi_num(hw, vsi_handle),
3163 lut_type, lut, lut_size, 0, false);
3167 * ice_aq_set_rss_lut
3168 * @hw: pointer to the hardware structure
3169 * @vsi_handle: software VSI handle
3170 * @lut_type: LUT table type
3171 * @lut: pointer to the LUT buffer provided by the caller
3172 * @lut_size: size of the LUT buffer
3174 * set the RSS lookup table, PF or VSI type
3177 ice_aq_set_rss_lut(struct ice_hw *hw, u16 vsi_handle, u8 lut_type,
3178 u8 *lut, u16 lut_size)
3180 if (!ice_is_vsi_valid(hw, vsi_handle) || !lut)
3181 return ICE_ERR_PARAM;
3183 return __ice_aq_get_set_rss_lut(hw, ice_get_hw_vsi_num(hw, vsi_handle),
3184 lut_type, lut, lut_size, 0, true);
3188 * __ice_aq_get_set_rss_key
3189 * @hw: pointer to the HW struct
3190 * @vsi_id: VSI FW index
3191 * @key: pointer to key info struct
3192 * @set: set true to set the key, false to get the key
3194 * get (0x0B04) or set (0x0B02) the RSS key per VSI
3197 ice_status __ice_aq_get_set_rss_key(struct ice_hw *hw, u16 vsi_id,
3198 struct ice_aqc_get_set_rss_keys *key,
3201 struct ice_aqc_get_set_rss_key *cmd_resp;
3202 u16 key_size = sizeof(*key);
3203 struct ice_aq_desc desc;
3205 cmd_resp = &desc.params.get_set_rss_key;
3208 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_rss_key);
3209 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
3211 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_rss_key);
3214 cmd_resp->vsi_id = CPU_TO_LE16(((vsi_id <<
3215 ICE_AQC_GSET_RSS_KEY_VSI_ID_S) &
3216 ICE_AQC_GSET_RSS_KEY_VSI_ID_M) |
3217 ICE_AQC_GSET_RSS_KEY_VSI_VALID);
3219 return ice_aq_send_cmd(hw, &desc, key, key_size, NULL);
3223 * ice_aq_get_rss_key
3224 * @hw: pointer to the HW struct
3225 * @vsi_handle: software VSI handle
3226 * @key: pointer to key info struct
3228 * get the RSS key per VSI
3231 ice_aq_get_rss_key(struct ice_hw *hw, u16 vsi_handle,
3232 struct ice_aqc_get_set_rss_keys *key)
3234 if (!ice_is_vsi_valid(hw, vsi_handle) || !key)
3235 return ICE_ERR_PARAM;
3237 return __ice_aq_get_set_rss_key(hw, ice_get_hw_vsi_num(hw, vsi_handle),
3242 * ice_aq_set_rss_key
3243 * @hw: pointer to the HW struct
3244 * @vsi_handle: software VSI handle
3245 * @keys: pointer to key info struct
3247 * set the RSS key per VSI
3250 ice_aq_set_rss_key(struct ice_hw *hw, u16 vsi_handle,
3251 struct ice_aqc_get_set_rss_keys *keys)
3253 if (!ice_is_vsi_valid(hw, vsi_handle) || !keys)
3254 return ICE_ERR_PARAM;
3256 return __ice_aq_get_set_rss_key(hw, ice_get_hw_vsi_num(hw, vsi_handle),
3261 * ice_aq_add_lan_txq
3262 * @hw: pointer to the hardware structure
3263 * @num_qgrps: Number of added queue groups
3264 * @qg_list: list of queue groups to be added
3265 * @buf_size: size of buffer for indirect command
3266 * @cd: pointer to command details structure or NULL
3268 * Add Tx LAN queue (0x0C30)
3271 * Prior to calling add Tx LAN queue:
3272 * Initialize the following as part of the Tx queue context:
3273 * Completion queue ID if the queue uses Completion queue, Quanta profile,
3274 * Cache profile and Packet shaper profile.
3276 * After add Tx LAN queue AQ command is completed:
3277 * Interrupts should be associated with specific queues,
3278 * Association of Tx queue to Doorbell queue is not part of Add LAN Tx queue
3282 ice_aq_add_lan_txq(struct ice_hw *hw, u8 num_qgrps,
3283 struct ice_aqc_add_tx_qgrp *qg_list, u16 buf_size,
3284 struct ice_sq_cd *cd)
3286 u16 i, sum_header_size, sum_q_size = 0;
3287 struct ice_aqc_add_tx_qgrp *list;
3288 struct ice_aqc_add_txqs *cmd;
3289 struct ice_aq_desc desc;
3291 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
3293 cmd = &desc.params.add_txqs;
3295 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_add_txqs);
3298 return ICE_ERR_PARAM;
3300 if (num_qgrps > ICE_LAN_TXQ_MAX_QGRPS)
3301 return ICE_ERR_PARAM;
3303 sum_header_size = num_qgrps *
3304 (sizeof(*qg_list) - sizeof(*qg_list->txqs));
3307 for (i = 0; i < num_qgrps; i++) {
3308 struct ice_aqc_add_txqs_perq *q = list->txqs;
3310 sum_q_size += list->num_txqs * sizeof(*q);
3311 list = (struct ice_aqc_add_tx_qgrp *)(q + list->num_txqs);
3314 if (buf_size != (sum_header_size + sum_q_size))
3315 return ICE_ERR_PARAM;
3317 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
3319 cmd->num_qgrps = num_qgrps;
3321 return ice_aq_send_cmd(hw, &desc, qg_list, buf_size, cd);
3325 * ice_aq_dis_lan_txq
3326 * @hw: pointer to the hardware structure
3327 * @num_qgrps: number of groups in the list
3328 * @qg_list: the list of groups to disable
3329 * @buf_size: the total size of the qg_list buffer in bytes
3330 * @rst_src: if called due to reset, specifies the reset source
3331 * @vmvf_num: the relative VM or VF number that is undergoing the reset
3332 * @cd: pointer to command details structure or NULL
3334 * Disable LAN Tx queue (0x0C31)
3336 static enum ice_status
3337 ice_aq_dis_lan_txq(struct ice_hw *hw, u8 num_qgrps,
3338 struct ice_aqc_dis_txq_item *qg_list, u16 buf_size,
3339 enum ice_disq_rst_src rst_src, u16 vmvf_num,
3340 struct ice_sq_cd *cd)
3342 struct ice_aqc_dis_txqs *cmd;
3343 struct ice_aq_desc desc;
3344 enum ice_status status;
3347 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
3348 cmd = &desc.params.dis_txqs;
3349 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_dis_txqs);
3351 /* qg_list can be NULL only in VM/VF reset flow */
3352 if (!qg_list && !rst_src)
3353 return ICE_ERR_PARAM;
3355 if (num_qgrps > ICE_LAN_TXQ_MAX_QGRPS)
3356 return ICE_ERR_PARAM;
3358 cmd->num_entries = num_qgrps;
3360 cmd->vmvf_and_timeout = CPU_TO_LE16((5 << ICE_AQC_Q_DIS_TIMEOUT_S) &
3361 ICE_AQC_Q_DIS_TIMEOUT_M);
3365 cmd->cmd_type = ICE_AQC_Q_DIS_CMD_VM_RESET;
3366 cmd->vmvf_and_timeout |=
3367 CPU_TO_LE16(vmvf_num & ICE_AQC_Q_DIS_VMVF_NUM_M);
3374 /* flush pipe on time out */
3375 cmd->cmd_type |= ICE_AQC_Q_DIS_CMD_FLUSH_PIPE;
3376 /* If no queue group info, we are in a reset flow. Issue the AQ */
3380 /* set RD bit to indicate that command buffer is provided by the driver
3381 * and it needs to be read by the firmware
3383 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
3385 for (i = 0; i < num_qgrps; ++i) {
3386 /* Calculate the size taken up by the queue IDs in this group */
3387 sz += qg_list[i].num_qs * sizeof(qg_list[i].q_id);
3389 /* Add the size of the group header */
3390 sz += sizeof(qg_list[i]) - sizeof(qg_list[i].q_id);
3392 /* If the num of queues is even, add 2 bytes of padding */
3393 if ((qg_list[i].num_qs % 2) == 0)
3398 return ICE_ERR_PARAM;
3401 status = ice_aq_send_cmd(hw, &desc, qg_list, buf_size, cd);
3404 ice_debug(hw, ICE_DBG_SCHED, "VM%d disable failed %d\n",
3405 vmvf_num, hw->adminq.sq_last_status);
3407 ice_debug(hw, ICE_DBG_SCHED, "disable queue %d failed %d\n",
3408 LE16_TO_CPU(qg_list[0].q_id[0]),
3409 hw->adminq.sq_last_status);
3415 * ice_aq_move_recfg_lan_txq
3416 * @hw: pointer to the hardware structure
3417 * @num_qs: number of queues to move/reconfigure
3418 * @is_move: true if this operation involves node movement
3419 * @is_tc_change: true if this operation involves a TC change
3420 * @subseq_call: true if this operation is a subsequent call
3421 * @flush_pipe: on timeout, true to flush pipe, false to return EAGAIN
3422 * @timeout: timeout in units of 100 usec (valid values 0-50)
3423 * @blocked_cgds: out param, bitmap of CGDs that timed out if returning EAGAIN
3424 * @buf: struct containing src/dest TEID and per-queue info
3425 * @buf_size: size of buffer for indirect command
3426 * @txqs_moved: out param, number of queues successfully moved
3427 * @cd: pointer to command details structure or NULL
3429 * Move / Reconfigure Tx LAN queues (0x0C32)
3432 ice_aq_move_recfg_lan_txq(struct ice_hw *hw, u8 num_qs, bool is_move,
3433 bool is_tc_change, bool subseq_call, bool flush_pipe,
3434 u8 timeout, u32 *blocked_cgds,
3435 struct ice_aqc_move_txqs_data *buf, u16 buf_size,
3436 u8 *txqs_moved, struct ice_sq_cd *cd)
3438 struct ice_aqc_move_txqs *cmd;
3439 struct ice_aq_desc desc;
3440 enum ice_status status;
3442 cmd = &desc.params.move_txqs;
3443 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_move_recfg_txqs);
3445 #define ICE_LAN_TXQ_MOVE_TIMEOUT_MAX 50
3446 if (timeout > ICE_LAN_TXQ_MOVE_TIMEOUT_MAX)
3447 return ICE_ERR_PARAM;
3449 if (is_tc_change && !flush_pipe && !blocked_cgds)
3450 return ICE_ERR_PARAM;
3452 if (!is_move && !is_tc_change)
3453 return ICE_ERR_PARAM;
3455 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
3458 cmd->cmd_type |= ICE_AQC_Q_CMD_TYPE_MOVE;
3461 cmd->cmd_type |= ICE_AQC_Q_CMD_TYPE_TC_CHANGE;
3464 cmd->cmd_type |= ICE_AQC_Q_CMD_SUBSEQ_CALL;
3467 cmd->cmd_type |= ICE_AQC_Q_CMD_FLUSH_PIPE;
3469 cmd->num_qs = num_qs;
3470 cmd->timeout = ((timeout << ICE_AQC_Q_CMD_TIMEOUT_S) &
3471 ICE_AQC_Q_CMD_TIMEOUT_M);
3473 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
3475 if (!status && txqs_moved)
3476 *txqs_moved = cmd->num_qs;
3478 if (hw->adminq.sq_last_status == ICE_AQ_RC_EAGAIN &&
3479 is_tc_change && !flush_pipe)
3480 *blocked_cgds = LE32_TO_CPU(cmd->blocked_cgds);
3485 /* End of FW Admin Queue command wrappers */
3488 * ice_write_byte - write a byte to a packed context structure
3489 * @src_ctx: the context structure to read from
3490 * @dest_ctx: the context to be written to
3491 * @ce_info: a description of the struct to be filled
3494 ice_write_byte(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info)
3496 u8 src_byte, dest_byte, mask;
3500 /* copy from the next struct field */
3501 from = src_ctx + ce_info->offset;
3503 /* prepare the bits and mask */
3504 shift_width = ce_info->lsb % 8;
3505 mask = (u8)(BIT(ce_info->width) - 1);
3510 /* shift to correct alignment */
3511 mask <<= shift_width;
3512 src_byte <<= shift_width;
3514 /* get the current bits from the target bit string */
3515 dest = dest_ctx + (ce_info->lsb / 8);
3517 ice_memcpy(&dest_byte, dest, sizeof(dest_byte), ICE_DMA_TO_NONDMA);
3519 dest_byte &= ~mask; /* get the bits not changing */
3520 dest_byte |= src_byte; /* add in the new bits */
3522 /* put it all back */
3523 ice_memcpy(dest, &dest_byte, sizeof(dest_byte), ICE_NONDMA_TO_DMA);
3527 * ice_write_word - write a word to a packed context structure
3528 * @src_ctx: the context structure to read from
3529 * @dest_ctx: the context to be written to
3530 * @ce_info: a description of the struct to be filled
3533 ice_write_word(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info)
3540 /* copy from the next struct field */
3541 from = src_ctx + ce_info->offset;
3543 /* prepare the bits and mask */
3544 shift_width = ce_info->lsb % 8;
3545 mask = BIT(ce_info->width) - 1;
3547 /* don't swizzle the bits until after the mask because the mask bits
3548 * will be in a different bit position on big endian machines
3550 src_word = *(u16 *)from;
3553 /* shift to correct alignment */
3554 mask <<= shift_width;
3555 src_word <<= shift_width;
3557 /* get the current bits from the target bit string */
3558 dest = dest_ctx + (ce_info->lsb / 8);
3560 ice_memcpy(&dest_word, dest, sizeof(dest_word), ICE_DMA_TO_NONDMA);
3562 dest_word &= ~(CPU_TO_LE16(mask)); /* get the bits not changing */
3563 dest_word |= CPU_TO_LE16(src_word); /* add in the new bits */
3565 /* put it all back */
3566 ice_memcpy(dest, &dest_word, sizeof(dest_word), ICE_NONDMA_TO_DMA);
3570 * ice_write_dword - write a dword to a packed context structure
3571 * @src_ctx: the context structure to read from
3572 * @dest_ctx: the context to be written to
3573 * @ce_info: a description of the struct to be filled
3576 ice_write_dword(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info)
3578 u32 src_dword, mask;
3583 /* copy from the next struct field */
3584 from = src_ctx + ce_info->offset;
3586 /* prepare the bits and mask */
3587 shift_width = ce_info->lsb % 8;
3589 /* if the field width is exactly 32 on an x86 machine, then the shift
3590 * operation will not work because the SHL instructions count is masked
3591 * to 5 bits so the shift will do nothing
3593 if (ce_info->width < 32)
3594 mask = BIT(ce_info->width) - 1;
3598 /* don't swizzle the bits until after the mask because the mask bits
3599 * will be in a different bit position on big endian machines
3601 src_dword = *(u32 *)from;
3604 /* shift to correct alignment */
3605 mask <<= shift_width;
3606 src_dword <<= shift_width;
3608 /* get the current bits from the target bit string */
3609 dest = dest_ctx + (ce_info->lsb / 8);
3611 ice_memcpy(&dest_dword, dest, sizeof(dest_dword), ICE_DMA_TO_NONDMA);
3613 dest_dword &= ~(CPU_TO_LE32(mask)); /* get the bits not changing */
3614 dest_dword |= CPU_TO_LE32(src_dword); /* add in the new bits */
3616 /* put it all back */
3617 ice_memcpy(dest, &dest_dword, sizeof(dest_dword), ICE_NONDMA_TO_DMA);
3621 * ice_write_qword - write a qword to a packed context structure
3622 * @src_ctx: the context structure to read from
3623 * @dest_ctx: the context to be written to
3624 * @ce_info: a description of the struct to be filled
3627 ice_write_qword(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info)
3629 u64 src_qword, mask;
3634 /* copy from the next struct field */
3635 from = src_ctx + ce_info->offset;
3637 /* prepare the bits and mask */
3638 shift_width = ce_info->lsb % 8;
3640 /* if the field width is exactly 64 on an x86 machine, then the shift
3641 * operation will not work because the SHL instructions count is masked
3642 * to 6 bits so the shift will do nothing
3644 if (ce_info->width < 64)
3645 mask = BIT_ULL(ce_info->width) - 1;
3649 /* don't swizzle the bits until after the mask because the mask bits
3650 * will be in a different bit position on big endian machines
3652 src_qword = *(u64 *)from;
3655 /* shift to correct alignment */
3656 mask <<= shift_width;
3657 src_qword <<= shift_width;
3659 /* get the current bits from the target bit string */
3660 dest = dest_ctx + (ce_info->lsb / 8);
3662 ice_memcpy(&dest_qword, dest, sizeof(dest_qword), ICE_DMA_TO_NONDMA);
3664 dest_qword &= ~(CPU_TO_LE64(mask)); /* get the bits not changing */
3665 dest_qword |= CPU_TO_LE64(src_qword); /* add in the new bits */
3667 /* put it all back */
3668 ice_memcpy(dest, &dest_qword, sizeof(dest_qword), ICE_NONDMA_TO_DMA);
3672 * ice_set_ctx - set context bits in packed structure
3673 * @hw: pointer to the hardware structure
3674 * @src_ctx: pointer to a generic non-packed context structure
3675 * @dest_ctx: pointer to memory for the packed structure
3676 * @ce_info: a description of the structure to be transformed
3679 ice_set_ctx(struct ice_hw *hw, u8 *src_ctx, u8 *dest_ctx,
3680 const struct ice_ctx_ele *ce_info)
3684 for (f = 0; ce_info[f].width; f++) {
3685 /* We have to deal with each element of the FW response
3686 * using the correct size so that we are correct regardless
3687 * of the endianness of the machine.
3689 if (ce_info[f].width > (ce_info[f].size_of * BITS_PER_BYTE)) {
3690 ice_debug(hw, ICE_DBG_QCTX,
3691 "Field %d width of %d bits larger than size of %d byte(s) ... skipping write\n",
3692 f, ce_info[f].width, ce_info[f].size_of);
3695 switch (ce_info[f].size_of) {
3697 ice_write_byte(src_ctx, dest_ctx, &ce_info[f]);
3700 ice_write_word(src_ctx, dest_ctx, &ce_info[f]);
3703 ice_write_dword(src_ctx, dest_ctx, &ce_info[f]);
3706 ice_write_qword(src_ctx, dest_ctx, &ce_info[f]);
3709 return ICE_ERR_INVAL_SIZE;
3717 * ice_read_byte - read context byte into struct
3718 * @src_ctx: the context structure to read from
3719 * @dest_ctx: the context to be written to
3720 * @ce_info: a description of the struct to be filled
3723 ice_read_byte(u8 *src_ctx, u8 *dest_ctx, struct ice_ctx_ele *ce_info)
3729 /* prepare the bits and mask */
3730 shift_width = ce_info->lsb % 8;
3731 mask = (u8)(BIT(ce_info->width) - 1);
3733 /* shift to correct alignment */
3734 mask <<= shift_width;
3736 /* get the current bits from the src bit string */
3737 src = src_ctx + (ce_info->lsb / 8);
3739 ice_memcpy(&dest_byte, src, sizeof(dest_byte), ICE_DMA_TO_NONDMA);
3741 dest_byte &= ~(mask);
3743 dest_byte >>= shift_width;
3745 /* get the address from the struct field */
3746 target = dest_ctx + ce_info->offset;
3748 /* put it back in the struct */
3749 ice_memcpy(target, &dest_byte, sizeof(dest_byte), ICE_NONDMA_TO_DMA);
3753 * ice_read_word - read context word into struct
3754 * @src_ctx: the context structure to read from
3755 * @dest_ctx: the context to be written to
3756 * @ce_info: a description of the struct to be filled
3759 ice_read_word(u8 *src_ctx, u8 *dest_ctx, struct ice_ctx_ele *ce_info)
3761 u16 dest_word, mask;
3766 /* prepare the bits and mask */
3767 shift_width = ce_info->lsb % 8;
3768 mask = BIT(ce_info->width) - 1;
3770 /* shift to correct alignment */
3771 mask <<= shift_width;
3773 /* get the current bits from the src bit string */
3774 src = src_ctx + (ce_info->lsb / 8);
3776 ice_memcpy(&src_word, src, sizeof(src_word), ICE_DMA_TO_NONDMA);
3778 /* the data in the memory is stored as little endian so mask it
3781 src_word &= ~(CPU_TO_LE16(mask));
3783 /* get the data back into host order before shifting */
3784 dest_word = LE16_TO_CPU(src_word);
3786 dest_word >>= shift_width;
3788 /* get the address from the struct field */
3789 target = dest_ctx + ce_info->offset;
3791 /* put it back in the struct */
3792 ice_memcpy(target, &dest_word, sizeof(dest_word), ICE_NONDMA_TO_DMA);
3796 * ice_read_dword - read context dword into struct
3797 * @src_ctx: the context structure to read from
3798 * @dest_ctx: the context to be written to
3799 * @ce_info: a description of the struct to be filled
3802 ice_read_dword(u8 *src_ctx, u8 *dest_ctx, struct ice_ctx_ele *ce_info)
3804 u32 dest_dword, mask;
3809 /* prepare the bits and mask */
3810 shift_width = ce_info->lsb % 8;
3812 /* if the field width is exactly 32 on an x86 machine, then the shift
3813 * operation will not work because the SHL instructions count is masked
3814 * to 5 bits so the shift will do nothing
3816 if (ce_info->width < 32)
3817 mask = BIT(ce_info->width) - 1;
3821 /* shift to correct alignment */
3822 mask <<= shift_width;
3824 /* get the current bits from the src bit string */
3825 src = src_ctx + (ce_info->lsb / 8);
3827 ice_memcpy(&src_dword, src, sizeof(src_dword), ICE_DMA_TO_NONDMA);
3829 /* the data in the memory is stored as little endian so mask it
3832 src_dword &= ~(CPU_TO_LE32(mask));
3834 /* get the data back into host order before shifting */
3835 dest_dword = LE32_TO_CPU(src_dword);
3837 dest_dword >>= shift_width;
3839 /* get the address from the struct field */
3840 target = dest_ctx + ce_info->offset;
3842 /* put it back in the struct */
3843 ice_memcpy(target, &dest_dword, sizeof(dest_dword), ICE_NONDMA_TO_DMA);
3847 * ice_read_qword - read context qword into struct
3848 * @src_ctx: the context structure to read from
3849 * @dest_ctx: the context to be written to
3850 * @ce_info: a description of the struct to be filled
3853 ice_read_qword(u8 *src_ctx, u8 *dest_ctx, struct ice_ctx_ele *ce_info)
3855 u64 dest_qword, mask;
3860 /* prepare the bits and mask */
3861 shift_width = ce_info->lsb % 8;
3863 /* if the field width is exactly 64 on an x86 machine, then the shift
3864 * operation will not work because the SHL instructions count is masked
3865 * to 6 bits so the shift will do nothing
3867 if (ce_info->width < 64)
3868 mask = BIT_ULL(ce_info->width) - 1;
3872 /* shift to correct alignment */
3873 mask <<= shift_width;
3875 /* get the current bits from the src bit string */
3876 src = src_ctx + (ce_info->lsb / 8);
3878 ice_memcpy(&src_qword, src, sizeof(src_qword), ICE_DMA_TO_NONDMA);
3880 /* the data in the memory is stored as little endian so mask it
3883 src_qword &= ~(CPU_TO_LE64(mask));
3885 /* get the data back into host order before shifting */
3886 dest_qword = LE64_TO_CPU(src_qword);
3888 dest_qword >>= shift_width;
3890 /* get the address from the struct field */
3891 target = dest_ctx + ce_info->offset;
3893 /* put it back in the struct */
3894 ice_memcpy(target, &dest_qword, sizeof(dest_qword), ICE_NONDMA_TO_DMA);
3898 * ice_get_ctx - extract context bits from a packed structure
3899 * @src_ctx: pointer to a generic packed context structure
3900 * @dest_ctx: pointer to a generic non-packed context structure
3901 * @ce_info: a description of the structure to be read from
3904 ice_get_ctx(u8 *src_ctx, u8 *dest_ctx, struct ice_ctx_ele *ce_info)
3908 for (f = 0; ce_info[f].width; f++) {
3909 switch (ce_info[f].size_of) {
3911 ice_read_byte(src_ctx, dest_ctx, &ce_info[f]);
3914 ice_read_word(src_ctx, dest_ctx, &ce_info[f]);
3917 ice_read_dword(src_ctx, dest_ctx, &ce_info[f]);
3920 ice_read_qword(src_ctx, dest_ctx, &ce_info[f]);
3923 /* nothing to do, just keep going */
3932 * ice_get_lan_q_ctx - get the LAN queue context for the given VSI and TC
3933 * @hw: pointer to the HW struct
3934 * @vsi_handle: software VSI handle
3936 * @q_handle: software queue handle
3939 ice_get_lan_q_ctx(struct ice_hw *hw, u16 vsi_handle, u8 tc, u16 q_handle)
3941 struct ice_vsi_ctx *vsi;
3942 struct ice_q_ctx *q_ctx;
3944 vsi = ice_get_vsi_ctx(hw, vsi_handle);
3947 if (q_handle >= vsi->num_lan_q_entries[tc])
3949 if (!vsi->lan_q_ctx[tc])
3951 q_ctx = vsi->lan_q_ctx[tc];
3952 return &q_ctx[q_handle];
3957 * @pi: port information structure
3958 * @vsi_handle: software VSI handle
3960 * @q_handle: software queue handle
3961 * @num_qgrps: Number of added queue groups
3962 * @buf: list of queue groups to be added
3963 * @buf_size: size of buffer for indirect command
3964 * @cd: pointer to command details structure or NULL
3966 * This function adds one LAN queue
3969 ice_ena_vsi_txq(struct ice_port_info *pi, u16 vsi_handle, u8 tc, u16 q_handle,
3970 u8 num_qgrps, struct ice_aqc_add_tx_qgrp *buf, u16 buf_size,
3971 struct ice_sq_cd *cd)
3973 struct ice_aqc_txsched_elem_data node = { 0 };
3974 struct ice_sched_node *parent;
3975 struct ice_q_ctx *q_ctx;
3976 enum ice_status status;
3979 if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
3982 if (num_qgrps > 1 || buf->num_txqs > 1)
3983 return ICE_ERR_MAX_LIMIT;
3987 if (!ice_is_vsi_valid(hw, vsi_handle))
3988 return ICE_ERR_PARAM;
3990 ice_acquire_lock(&pi->sched_lock);
3992 q_ctx = ice_get_lan_q_ctx(hw, vsi_handle, tc, q_handle);
3994 ice_debug(hw, ICE_DBG_SCHED, "Enaq: invalid queue handle %d\n",
3996 status = ICE_ERR_PARAM;
4000 /* find a parent node */
4001 parent = ice_sched_get_free_qparent(pi, vsi_handle, tc,
4002 ICE_SCHED_NODE_OWNER_LAN);
4004 status = ICE_ERR_PARAM;
4008 buf->parent_teid = parent->info.node_teid;
4009 node.parent_teid = parent->info.node_teid;
4010 /* Mark that the values in the "generic" section as valid. The default
4011 * value in the "generic" section is zero. This means that :
4012 * - Scheduling mode is Bytes Per Second (BPS), indicated by Bit 0.
4013 * - 0 priority among siblings, indicated by Bit 1-3.
4014 * - WFQ, indicated by Bit 4.
4015 * - 0 Adjustment value is used in PSM credit update flow, indicated by
4017 * - Bit 7 is reserved.
4018 * Without setting the generic section as valid in valid_sections, the
4019 * Admin queue command will fail with error code ICE_AQ_RC_EINVAL.
4021 buf->txqs[0].info.valid_sections =
4022 ICE_AQC_ELEM_VALID_GENERIC | ICE_AQC_ELEM_VALID_CIR |
4023 ICE_AQC_ELEM_VALID_EIR;
4024 buf->txqs[0].info.generic = 0;
4025 buf->txqs[0].info.cir_bw.bw_profile_idx =
4026 CPU_TO_LE16(ICE_SCHED_DFLT_RL_PROF_ID);
4027 buf->txqs[0].info.cir_bw.bw_alloc =
4028 CPU_TO_LE16(ICE_SCHED_DFLT_BW_WT);
4029 buf->txqs[0].info.eir_bw.bw_profile_idx =
4030 CPU_TO_LE16(ICE_SCHED_DFLT_RL_PROF_ID);
4031 buf->txqs[0].info.eir_bw.bw_alloc =
4032 CPU_TO_LE16(ICE_SCHED_DFLT_BW_WT);
4034 /* add the LAN queue */
4035 status = ice_aq_add_lan_txq(hw, num_qgrps, buf, buf_size, cd);
4036 if (status != ICE_SUCCESS) {
4037 ice_debug(hw, ICE_DBG_SCHED, "enable queue %d failed %d\n",
4038 LE16_TO_CPU(buf->txqs[0].txq_id),
4039 hw->adminq.sq_last_status);
4043 node.node_teid = buf->txqs[0].q_teid;
4044 node.data.elem_type = ICE_AQC_ELEM_TYPE_LEAF;
4045 q_ctx->q_handle = q_handle;
4046 q_ctx->q_teid = LE32_TO_CPU(node.node_teid);
4048 /* add a leaf node into scheduler tree queue layer */
4049 status = ice_sched_add_node(pi, hw->num_tx_sched_layers - 1, &node);
4051 status = ice_sched_replay_q_bw(pi, q_ctx);
4054 ice_release_lock(&pi->sched_lock);
4060 * @pi: port information structure
4061 * @vsi_handle: software VSI handle
4063 * @num_queues: number of queues
4064 * @q_handles: pointer to software queue handle array
4065 * @q_ids: pointer to the q_id array
4066 * @q_teids: pointer to queue node teids
4067 * @rst_src: if called due to reset, specifies the reset source
4068 * @vmvf_num: the relative VM or VF number that is undergoing the reset
4069 * @cd: pointer to command details structure or NULL
4071 * This function removes queues and their corresponding nodes in SW DB
4074 ice_dis_vsi_txq(struct ice_port_info *pi, u16 vsi_handle, u8 tc, u8 num_queues,
4075 u16 *q_handles, u16 *q_ids, u32 *q_teids,
4076 enum ice_disq_rst_src rst_src, u16 vmvf_num,
4077 struct ice_sq_cd *cd)
4079 enum ice_status status = ICE_ERR_DOES_NOT_EXIST;
4080 struct ice_aqc_dis_txq_item qg_list;
4081 struct ice_q_ctx *q_ctx;
4084 if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
4088 /* if queue is disabled already yet the disable queue command
4089 * has to be sent to complete the VF reset, then call
4090 * ice_aq_dis_lan_txq without any queue information
4093 return ice_aq_dis_lan_txq(pi->hw, 0, NULL, 0, rst_src,
4098 ice_acquire_lock(&pi->sched_lock);
4100 for (i = 0; i < num_queues; i++) {
4101 struct ice_sched_node *node;
4103 node = ice_sched_find_node_by_teid(pi->root, q_teids[i]);
4106 q_ctx = ice_get_lan_q_ctx(pi->hw, vsi_handle, tc, q_handles[i]);
4108 ice_debug(pi->hw, ICE_DBG_SCHED, "invalid queue handle%d\n",
4112 if (q_ctx->q_handle != q_handles[i]) {
4113 ice_debug(pi->hw, ICE_DBG_SCHED, "Err:handles %d %d\n",
4114 q_ctx->q_handle, q_handles[i]);
4117 qg_list.parent_teid = node->info.parent_teid;
4119 qg_list.q_id[0] = CPU_TO_LE16(q_ids[i]);
4120 status = ice_aq_dis_lan_txq(pi->hw, 1, &qg_list,
4121 sizeof(qg_list), rst_src, vmvf_num,
4124 if (status != ICE_SUCCESS)
4126 ice_free_sched_node(pi, node);
4127 q_ctx->q_handle = ICE_INVAL_Q_HANDLE;
4129 ice_release_lock(&pi->sched_lock);
4134 * ice_cfg_vsi_qs - configure the new/existing VSI queues
4135 * @pi: port information structure
4136 * @vsi_handle: software VSI handle
4137 * @tc_bitmap: TC bitmap
4138 * @maxqs: max queues array per TC
4139 * @owner: LAN or RDMA
4141 * This function adds/updates the VSI queues per TC.
4143 static enum ice_status
4144 ice_cfg_vsi_qs(struct ice_port_info *pi, u16 vsi_handle, u16 tc_bitmap,
4145 u16 *maxqs, u8 owner)
4147 enum ice_status status = ICE_SUCCESS;
4150 if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY)
4153 if (!ice_is_vsi_valid(pi->hw, vsi_handle))
4154 return ICE_ERR_PARAM;
4156 ice_acquire_lock(&pi->sched_lock);
4158 ice_for_each_traffic_class(i) {
4159 /* configuration is possible only if TC node is present */
4160 if (!ice_sched_get_tc_node(pi, i))
4163 status = ice_sched_cfg_vsi(pi, vsi_handle, i, maxqs[i], owner,
4164 ice_is_tc_ena(tc_bitmap, i));
4169 ice_release_lock(&pi->sched_lock);
4174 * ice_cfg_vsi_lan - configure VSI LAN queues
4175 * @pi: port information structure
4176 * @vsi_handle: software VSI handle
4177 * @tc_bitmap: TC bitmap
4178 * @max_lanqs: max LAN queues array per TC
4180 * This function adds/updates the VSI LAN queues per TC.
4183 ice_cfg_vsi_lan(struct ice_port_info *pi, u16 vsi_handle, u16 tc_bitmap,
4186 return ice_cfg_vsi_qs(pi, vsi_handle, tc_bitmap, max_lanqs,
4187 ICE_SCHED_NODE_OWNER_LAN);
4191 * ice_is_main_vsi - checks whether the VSI is main VSI
4192 * @hw: pointer to the HW struct
4193 * @vsi_handle: VSI handle
4195 * Checks whether the VSI is the main VSI (the first PF VSI created on
4198 static bool ice_is_main_vsi(struct ice_hw *hw, u16 vsi_handle)
4200 return vsi_handle == ICE_MAIN_VSI_HANDLE && hw->vsi_ctx[vsi_handle];
4204 * ice_replay_pre_init - replay pre initialization
4205 * @hw: pointer to the HW struct
4206 * @sw: pointer to switch info struct for which function initializes filters
4208 * Initializes required config data for VSI, FD, ACL, and RSS before replay.
4210 static enum ice_status
4211 ice_replay_pre_init(struct ice_hw *hw, struct ice_switch_info *sw)
4215 /* Delete old entries from replay filter list head if there is any */
4216 ice_rm_sw_replay_rule_info(hw, sw);
4217 /* In start of replay, move entries into replay_rules list, it
4218 * will allow adding rules entries back to filt_rules list,
4219 * which is operational list.
4221 for (i = 0; i < ICE_MAX_NUM_RECIPES; i++)
4222 LIST_REPLACE_INIT(&sw->recp_list[i].filt_rules,
4223 &sw->recp_list[i].filt_replay_rules);
4224 ice_sched_replay_agg_vsi_preinit(hw);
4226 return ice_sched_replay_tc_node_bw(hw->port_info);
4230 * ice_replay_vsi - replay VSI configuration
4231 * @hw: pointer to the HW struct
4232 * @vsi_handle: driver VSI handle
4234 * Restore all VSI configuration after reset. It is required to call this
4235 * function with main VSI first.
4237 enum ice_status ice_replay_vsi(struct ice_hw *hw, u16 vsi_handle)
4239 struct ice_switch_info *sw = hw->switch_info;
4240 struct ice_port_info *pi = hw->port_info;
4241 enum ice_status status;
4243 if (!ice_is_vsi_valid(hw, vsi_handle))
4244 return ICE_ERR_PARAM;
4246 /* Replay pre-initialization if there is any */
4247 if (ice_is_main_vsi(hw, vsi_handle)) {
4248 status = ice_replay_pre_init(hw, sw);
4252 /* Replay per VSI all RSS configurations */
4253 status = ice_replay_rss_cfg(hw, vsi_handle);
4256 /* Replay per VSI all filters */
4257 status = ice_replay_vsi_all_fltr(hw, pi, vsi_handle);
4259 status = ice_replay_vsi_agg(hw, vsi_handle);
4264 * ice_replay_post - post replay configuration cleanup
4265 * @hw: pointer to the HW struct
4267 * Post replay cleanup.
4269 void ice_replay_post(struct ice_hw *hw)
4271 /* Delete old entries from replay filter list head */
4272 ice_rm_all_sw_replay_rule_info(hw);
4273 ice_sched_replay_agg(hw);
4277 * ice_stat_update40 - read 40 bit stat from the chip and update stat values
4278 * @hw: ptr to the hardware info
4279 * @reg: offset of 64 bit HW register to read from
4280 * @prev_stat_loaded: bool to specify if previous stats are loaded
4281 * @prev_stat: ptr to previous loaded stat value
4282 * @cur_stat: ptr to current stat value
4285 ice_stat_update40(struct ice_hw *hw, u32 reg, bool prev_stat_loaded,
4286 u64 *prev_stat, u64 *cur_stat)
4288 u64 new_data = rd64(hw, reg) & (BIT_ULL(40) - 1);
4290 /* device stats are not reset at PFR, they likely will not be zeroed
4291 * when the driver starts. Thus, save the value from the first read
4292 * without adding to the statistic value so that we report stats which
4293 * count up from zero.
4295 if (!prev_stat_loaded) {
4296 *prev_stat = new_data;
4300 /* Calculate the difference between the new and old values, and then
4301 * add it to the software stat value.
4303 if (new_data >= *prev_stat)
4304 *cur_stat += new_data - *prev_stat;
4306 /* to manage the potential roll-over */
4307 *cur_stat += (new_data + BIT_ULL(40)) - *prev_stat;
4309 /* Update the previously stored value to prepare for next read */
4310 *prev_stat = new_data;
4314 * ice_stat_update32 - read 32 bit stat from the chip and update stat values
4315 * @hw: ptr to the hardware info
4316 * @reg: offset of HW register to read from
4317 * @prev_stat_loaded: bool to specify if previous stats are loaded
4318 * @prev_stat: ptr to previous loaded stat value
4319 * @cur_stat: ptr to current stat value
4322 ice_stat_update32(struct ice_hw *hw, u32 reg, bool prev_stat_loaded,
4323 u64 *prev_stat, u64 *cur_stat)
4327 new_data = rd32(hw, reg);
4329 /* device stats are not reset at PFR, they likely will not be zeroed
4330 * when the driver starts. Thus, save the value from the first read
4331 * without adding to the statistic value so that we report stats which
4332 * count up from zero.
4334 if (!prev_stat_loaded) {
4335 *prev_stat = new_data;
4339 /* Calculate the difference between the new and old values, and then
4340 * add it to the software stat value.
4342 if (new_data >= *prev_stat)
4343 *cur_stat += new_data - *prev_stat;
4345 /* to manage the potential roll-over */
4346 *cur_stat += (new_data + BIT_ULL(32)) - *prev_stat;
4348 /* Update the previously stored value to prepare for next read */
4349 *prev_stat = new_data;
4353 * ice_stat_update_repc - read GLV_REPC stats from chip and update stat values
4354 * @hw: ptr to the hardware info
4355 * @vsi_handle: VSI handle
4356 * @prev_stat_loaded: bool to specify if the previous stat values are loaded
4357 * @cur_stats: ptr to current stats structure
4359 * The GLV_REPC statistic register actually tracks two 16bit statistics, and
4360 * thus cannot be read using the normal ice_stat_update32 function.
4362 * Read the GLV_REPC register associated with the given VSI, and update the
4363 * rx_no_desc and rx_error values in the ice_eth_stats structure.
4365 * Because the statistics in GLV_REPC stick at 0xFFFF, the register must be
4366 * cleared each time it's read.
4368 * Note that the GLV_RDPC register also counts the causes that would trigger
4369 * GLV_REPC. However, it does not give the finer grained detail about why the
4370 * packets are being dropped. The GLV_REPC values can be used to distinguish
4371 * whether Rx packets are dropped due to errors or due to no available
4375 ice_stat_update_repc(struct ice_hw *hw, u16 vsi_handle, bool prev_stat_loaded,
4376 struct ice_eth_stats *cur_stats)
4378 u16 vsi_num, no_desc, error_cnt;
4381 if (!ice_is_vsi_valid(hw, vsi_handle))
4384 vsi_num = ice_get_hw_vsi_num(hw, vsi_handle);
4386 /* If we haven't loaded stats yet, just clear the current value */
4387 if (!prev_stat_loaded) {
4388 wr32(hw, GLV_REPC(vsi_num), 0);
4392 repc = rd32(hw, GLV_REPC(vsi_num));
4393 no_desc = (repc & GLV_REPC_NO_DESC_CNT_M) >> GLV_REPC_NO_DESC_CNT_S;
4394 error_cnt = (repc & GLV_REPC_ERROR_CNT_M) >> GLV_REPC_ERROR_CNT_S;
4396 /* Clear the count by writing to the stats register */
4397 wr32(hw, GLV_REPC(vsi_num), 0);
4399 cur_stats->rx_no_desc += no_desc;
4400 cur_stats->rx_errors += error_cnt;
4404 * ice_sched_query_elem - query element information from HW
4405 * @hw: pointer to the HW struct
4406 * @node_teid: node TEID to be queried
4407 * @buf: buffer to element information
4409 * This function queries HW element information
4412 ice_sched_query_elem(struct ice_hw *hw, u32 node_teid,
4413 struct ice_aqc_get_elem *buf)
4415 u16 buf_size, num_elem_ret = 0;
4416 enum ice_status status;
4418 buf_size = sizeof(*buf);
4419 ice_memset(buf, 0, buf_size, ICE_NONDMA_MEM);
4420 buf->generic[0].node_teid = CPU_TO_LE32(node_teid);
4421 status = ice_aq_query_sched_elems(hw, 1, buf, buf_size, &num_elem_ret,
4423 if (status != ICE_SUCCESS || num_elem_ret != 1)
4424 ice_debug(hw, ICE_DBG_SCHED, "query element failed\n");
4429 * ice_get_fw_mode - returns FW mode
4430 * @hw: pointer to the HW struct
4432 enum ice_fw_modes ice_get_fw_mode(struct ice_hw *hw)
4434 #define ICE_FW_MODE_DBG_M BIT(0)
4435 #define ICE_FW_MODE_REC_M BIT(1)
4436 #define ICE_FW_MODE_ROLLBACK_M BIT(2)
4439 /* check the current FW mode */
4440 fw_mode = rd32(hw, GL_MNG_FWSM) & GL_MNG_FWSM_FW_MODES_M;
4442 if (fw_mode & ICE_FW_MODE_DBG_M)
4443 return ICE_FW_MODE_DBG;
4444 else if (fw_mode & ICE_FW_MODE_REC_M)
4445 return ICE_FW_MODE_REC;
4446 else if (fw_mode & ICE_FW_MODE_ROLLBACK_M)
4447 return ICE_FW_MODE_ROLLBACK;
4449 return ICE_FW_MODE_NORMAL;
4453 * ice_fw_supports_link_override
4454 * @hw: pointer to the hardware structure
4456 * Checks if the firmware supports link override
4458 bool ice_fw_supports_link_override(struct ice_hw *hw)
4460 /* Currently, only supported for E810 devices */
4461 if (hw->mac_type != ICE_MAC_E810)
4464 if (hw->api_maj_ver == ICE_FW_API_LINK_OVERRIDE_MAJ) {
4465 if (hw->api_min_ver > ICE_FW_API_LINK_OVERRIDE_MIN)
4467 if (hw->api_min_ver == ICE_FW_API_LINK_OVERRIDE_MIN &&
4468 hw->api_patch >= ICE_FW_API_LINK_OVERRIDE_PATCH)
4470 } else if (hw->api_maj_ver > ICE_FW_API_LINK_OVERRIDE_MAJ) {
4478 * ice_get_link_default_override
4479 * @ldo: pointer to the link default override struct
4480 * @pi: pointer to the port info struct
4482 * Gets the link default override for a port
4485 ice_get_link_default_override(struct ice_link_default_override_tlv *ldo,
4486 struct ice_port_info *pi)
4488 u16 i, tlv, tlv_len, tlv_start, buf, offset;
4489 struct ice_hw *hw = pi->hw;
4490 enum ice_status status;
4492 status = ice_get_pfa_module_tlv(hw, &tlv, &tlv_len,
4493 ICE_SR_LINK_DEFAULT_OVERRIDE_PTR);
4495 ice_debug(hw, ICE_DBG_INIT,
4496 "Failed to read link override TLV.\n");
4500 /* Each port has its own config; calculate for our port */
4501 tlv_start = tlv + pi->lport * ICE_SR_PFA_LINK_OVERRIDE_WORDS +
4502 ICE_SR_PFA_LINK_OVERRIDE_OFFSET;
4504 /* link options first */
4505 status = ice_read_sr_word(hw, tlv_start, &buf);
4507 ice_debug(hw, ICE_DBG_INIT,
4508 "Failed to read override link options.\n");
4511 ldo->options = buf & ICE_LINK_OVERRIDE_OPT_M;
4512 ldo->phy_config = (buf & ICE_LINK_OVERRIDE_PHY_CFG_M) >>
4513 ICE_LINK_OVERRIDE_PHY_CFG_S;
4515 /* link PHY config */
4516 offset = tlv_start + ICE_SR_PFA_LINK_OVERRIDE_FEC_OFFSET;
4517 status = ice_read_sr_word(hw, offset, &buf);
4519 ice_debug(hw, ICE_DBG_INIT,
4520 "Failed to read override phy config.\n");
4523 ldo->fec_options = buf & ICE_LINK_OVERRIDE_FEC_OPT_M;
4526 offset = tlv_start + ICE_SR_PFA_LINK_OVERRIDE_PHY_OFFSET;
4527 for (i = 0; i < ICE_SR_PFA_LINK_OVERRIDE_PHY_WORDS; i++) {
4528 status = ice_read_sr_word(hw, (offset + i), &buf);
4530 ice_debug(hw, ICE_DBG_INIT,
4531 "Failed to read override link options.\n");
4534 /* shift 16 bits at a time to fill 64 bits */
4535 ldo->phy_type_low |= ((u64)buf << (i * 16));
4538 /* PHY types high */
4539 offset = tlv_start + ICE_SR_PFA_LINK_OVERRIDE_PHY_OFFSET +
4540 ICE_SR_PFA_LINK_OVERRIDE_PHY_WORDS;
4541 for (i = 0; i < ICE_SR_PFA_LINK_OVERRIDE_PHY_WORDS; i++) {
4542 status = ice_read_sr_word(hw, (offset + i), &buf);
4544 ice_debug(hw, ICE_DBG_INIT,
4545 "Failed to read override link options.\n");
4548 /* shift 16 bits at a time to fill 64 bits */
4549 ldo->phy_type_high |= ((u64)buf << (i * 16));
4556 * ice_is_phy_caps_an_enabled - check if PHY capabilities autoneg is enabled
4557 * @caps: get PHY capability data
4559 bool ice_is_phy_caps_an_enabled(struct ice_aqc_get_phy_caps_data *caps)
4561 if (caps->caps & ICE_AQC_PHY_AN_MODE ||
4562 caps->low_power_ctrl_an & (ICE_AQC_PHY_AN_EN_CLAUSE28 |
4563 ICE_AQC_PHY_AN_EN_CLAUSE73 |
4564 ICE_AQC_PHY_AN_EN_CLAUSE37))