1/* SPDX-License-Identifier: BSD-3-Clause */ 2/* Copyright (c) 2024, Intel Corporation 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * 3. Neither the name of the Intel Corporation nor the names of its 16 * contributors may be used to endorse or promote products derived from 17 * this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#ifndef _ICE_COMMON_H_ 33#define _ICE_COMMON_H_ 34 35#include "ice_type.h" 36#include "ice_nvm.h" 37#include "ice_flex_pipe.h" 38#include "virtchnl.h" 39#include "ice_switch.h" 40 41#define ICE_SQ_SEND_DELAY_TIME_MS 10 42#define ICE_SQ_SEND_MAX_EXECUTE 3 43 44enum ice_fw_modes { 45 ICE_FW_MODE_NORMAL, 46 ICE_FW_MODE_DBG, 47 ICE_FW_MODE_REC, 48 ICE_FW_MODE_ROLLBACK 49}; 50 51void ice_idle_aq(struct ice_hw *hw, struct ice_ctl_q_info *cq); 52bool ice_sq_done(struct ice_hw *hw, struct ice_ctl_q_info *cq); 53 54void ice_set_umac_shared(struct ice_hw *hw); 55enum ice_status ice_init_hw(struct ice_hw *hw); 56void ice_deinit_hw(struct ice_hw *hw); 57enum ice_status ice_check_reset(struct ice_hw *hw); 58enum ice_status ice_reset(struct ice_hw *hw, enum ice_reset_req req); 59enum ice_status ice_create_all_ctrlq(struct ice_hw *hw); 60enum ice_status ice_init_all_ctrlq(struct ice_hw *hw); 61void ice_shutdown_all_ctrlq(struct ice_hw *hw, bool unloading); 62void ice_destroy_all_ctrlq(struct ice_hw *hw); 63enum ice_status 64ice_clean_rq_elem(struct ice_hw *hw, struct ice_ctl_q_info *cq, 65 struct ice_rq_event_info *e, u16 *pending); 66enum ice_status 67ice_get_link_status(struct ice_port_info *pi, bool *link_up); 68enum ice_status ice_update_link_info(struct ice_port_info *pi); 69enum ice_status 70ice_acquire_res(struct ice_hw *hw, enum ice_aq_res_ids res, 71 enum ice_aq_res_access_type access, u32 timeout); 72void ice_release_res(struct ice_hw *hw, enum ice_aq_res_ids res); 73enum ice_status 74ice_alloc_hw_res(struct ice_hw *hw, u16 type, u16 num, bool btm, u16 *res); 75enum ice_status 76ice_free_hw_res(struct ice_hw *hw, u16 type, u16 num, u16 *res); 77enum ice_status 78ice_aq_alloc_free_res(struct ice_hw *hw, u16 num_entries, 79 struct ice_aqc_alloc_free_res_elem *buf, u16 buf_size, 80 enum ice_adminq_opc opc, struct ice_sq_cd *cd); 81enum ice_status 82ice_sq_send_cmd(struct ice_hw *hw, struct ice_ctl_q_info *cq, 83 struct ice_aq_desc *desc, void *buf, u16 buf_size, 84 struct ice_sq_cd *cd); 85void ice_clear_pxe_mode(struct ice_hw *hw); 86enum ice_status ice_get_caps(struct ice_hw *hw); 87 88void ice_set_safe_mode_caps(struct ice_hw *hw); 89 90enum ice_status 91ice_aq_get_internal_data(struct ice_hw *hw, u16 cluster_id, u16 table_id, 92 u32 start, void *buf, u16 buf_size, u16 *ret_buf_size, 93 u16 *ret_next_cluster, u16 *ret_next_table, 94 u32 *ret_next_index, struct ice_sq_cd *cd); 95 96enum ice_status ice_set_mac_type(struct ice_hw *hw); 97 98/* Define a macro that will align a pointer to point to the next memory address 99 * that falls on the given power of 2 (i.e., 2, 4, 8, 16, 32, 64...). For 100 * example, given the variable pointer = 0x1006, then after the following call: 101 * 102 * pointer = ICE_ALIGN(pointer, 4) 103 * 104 * ... the value of pointer would equal 0x1008, since 0x1008 is the next 105 * address after 0x1006 which is divisible by 4. 106 */ 107#define ICE_ALIGN(ptr, align) (((ptr) + ((align) - 1)) & ~((align) - 1)) 108 109#define ice_arr_elem_idx(idx, val) [(idx)] = (val) 110 111enum ice_status 112ice_write_rxq_ctx(struct ice_hw *hw, struct ice_rlan_ctx *rlan_ctx, 113 u32 rxq_index); 114enum ice_status 115ice_read_rxq_ctx(struct ice_hw *hw, struct ice_rlan_ctx *rlan_ctx, 116 u32 rxq_index); 117enum ice_status ice_clear_rxq_ctx(struct ice_hw *hw, u32 rxq_index); 118enum ice_status 119ice_clear_tx_cmpltnq_ctx(struct ice_hw *hw, u32 tx_cmpltnq_index); 120enum ice_status 121ice_write_tx_cmpltnq_ctx(struct ice_hw *hw, 122 struct ice_tx_cmpltnq_ctx *tx_cmpltnq_ctx, 123 u32 tx_cmpltnq_index); 124enum ice_status 125ice_clear_tx_drbell_q_ctx(struct ice_hw *hw, u32 tx_drbell_q_index); 126enum ice_status 127ice_write_tx_drbell_q_ctx(struct ice_hw *hw, 128 struct ice_tx_drbell_q_ctx *tx_drbell_q_ctx, 129 u32 tx_drbell_q_index); 130 131int ice_lut_size_to_type(int lut_size); 132enum ice_status 133ice_aq_get_rss_lut(struct ice_hw *hw, struct ice_aq_get_set_rss_lut_params *get_params); 134enum ice_status 135ice_aq_set_rss_lut(struct ice_hw *hw, struct ice_aq_get_set_rss_lut_params *set_params); 136enum ice_status 137ice_aq_get_rss_key(struct ice_hw *hw, u16 vsi_handle, 138 struct ice_aqc_get_set_rss_keys *keys); 139enum ice_status 140ice_aq_set_rss_key(struct ice_hw *hw, u16 vsi_handle, 141 struct ice_aqc_get_set_rss_keys *keys); 142enum ice_status 143ice_aq_add_lan_txq(struct ice_hw *hw, u8 count, 144 struct ice_aqc_add_tx_qgrp *qg_list, u16 buf_size, 145 struct ice_sq_cd *cd); 146enum ice_status 147ice_aq_move_recfg_lan_txq(struct ice_hw *hw, u8 num_qs, bool is_move, 148 bool is_tc_change, bool subseq_call, bool flush_pipe, 149 u8 timeout, u32 *blocked_cgds, 150 struct ice_aqc_move_txqs_data *buf, u16 buf_size, 151 u8 *txqs_moved, struct ice_sq_cd *cd); 152 153enum ice_status 154ice_aq_add_rdma_qsets(struct ice_hw *hw, u8 num_qset_grps, 155 struct ice_aqc_add_rdma_qset_data *qset_list, 156 u16 buf_size, struct ice_sq_cd *cd); 157 158bool ice_check_sq_alive(struct ice_hw *hw, struct ice_ctl_q_info *cq); 159enum ice_status ice_aq_q_shutdown(struct ice_hw *hw, bool unloading); 160void ice_fill_dflt_direct_cmd_desc(struct ice_aq_desc *desc, u16 opcode); 161extern const struct ice_ctx_ele ice_tlan_ctx_info[]; 162enum ice_status 163ice_set_ctx(struct ice_hw *hw, u8 *src_ctx, u8 *dest_ctx, 164 const struct ice_ctx_ele *ce_info); 165enum ice_status 166ice_get_ctx(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info); 167 168enum ice_status 169ice_aq_send_cmd(struct ice_hw *hw, struct ice_aq_desc *desc, 170 void *buf, u16 buf_size, struct ice_sq_cd *cd); 171enum ice_status ice_aq_get_fw_ver(struct ice_hw *hw, struct ice_sq_cd *cd); 172 173enum ice_status 174ice_aq_send_driver_ver(struct ice_hw *hw, struct ice_driver_ver *dv, 175 struct ice_sq_cd *cd); 176enum ice_status 177ice_aq_set_port_params(struct ice_port_info *pi, u16 bad_frame_vsi, 178 bool save_bad_pac, bool pad_short_pac, bool double_vlan, 179 struct ice_sq_cd *cd); 180enum ice_status 181ice_aq_get_phy_caps(struct ice_port_info *pi, bool qual_mods, u8 report_mode, 182 struct ice_aqc_get_phy_caps_data *caps, 183 struct ice_sq_cd *cd); 184enum ice_status 185ice_aq_get_netlist_node(struct ice_hw *hw, struct ice_aqc_get_link_topo *cmd, 186 u8 *node_part_number, u16 *node_handle); 187enum ice_status 188ice_find_netlist_node(struct ice_hw *hw, u8 node_type_ctx, u8 node_part_number, 189 u16 *node_handle); 190void 191ice_update_phy_type(u64 *phy_type_low, u64 *phy_type_high, 192 u16 link_speeds_bitmap); 193enum ice_status 194ice_aq_manage_mac_read(struct ice_hw *hw, void *buf, u16 buf_size, 195 struct ice_sq_cd *cd); 196enum ice_status 197ice_aq_manage_mac_write(struct ice_hw *hw, const u8 *mac_addr, u8 flags, 198 struct ice_sq_cd *cd); 199 200enum ice_status ice_clear_pf_cfg(struct ice_hw *hw); 201enum ice_status 202ice_aq_set_phy_cfg(struct ice_hw *hw, struct ice_port_info *pi, 203 struct ice_aqc_set_phy_cfg_data *cfg, struct ice_sq_cd *cd); 204bool ice_fw_supports_link_override(struct ice_hw *hw); 205bool ice_fw_supports_fec_dis_auto(struct ice_hw *hw); 206enum ice_status 207ice_get_link_default_override(struct ice_link_default_override_tlv *ldo, 208 struct ice_port_info *pi); 209bool ice_is_phy_caps_an_enabled(struct ice_aqc_get_phy_caps_data *caps); 210enum ice_fc_mode ice_caps_to_fc_mode(u8 caps); 211enum ice_fec_mode ice_caps_to_fec_mode(u8 caps, u8 fec_options); 212enum ice_status 213ice_set_fc(struct ice_port_info *pi, u8 *aq_failures, 214 bool ena_auto_link_update); 215bool 216ice_phy_caps_equals_cfg(struct ice_aqc_get_phy_caps_data *caps, 217 struct ice_aqc_set_phy_cfg_data *cfg); 218void 219ice_copy_phy_caps_to_cfg(struct ice_port_info *pi, 220 struct ice_aqc_get_phy_caps_data *caps, 221 struct ice_aqc_set_phy_cfg_data *cfg); 222enum ice_status 223ice_cfg_phy_fec(struct ice_port_info *pi, struct ice_aqc_set_phy_cfg_data *cfg, 224 enum ice_fec_mode fec); 225enum ice_status 226ice_aq_set_link_restart_an(struct ice_port_info *pi, bool ena_link, 227 struct ice_sq_cd *cd); 228enum ice_status 229ice_aq_set_mac_cfg(struct ice_hw *hw, u16 max_frame_size, bool auto_drop, 230 struct ice_sq_cd *cd); 231enum ice_status 232ice_aq_get_link_info(struct ice_port_info *pi, bool ena_lse, 233 struct ice_link_status *link, struct ice_sq_cd *cd); 234enum ice_status 235ice_aq_set_event_mask(struct ice_hw *hw, u8 port_num, u16 mask, 236 struct ice_sq_cd *cd); 237enum ice_status 238ice_aq_set_mac_loopback(struct ice_hw *hw, bool ena_lpbk, struct ice_sq_cd *cd); 239 240enum ice_status 241ice_aq_set_port_id_led(struct ice_port_info *pi, bool is_orig_mode, 242 struct ice_sq_cd *cd); 243enum ice_status 244ice_aq_sff_eeprom(struct ice_hw *hw, u16 lport, u8 bus_addr, 245 u16 mem_addr, u8 page, u8 set_page, u8 *data, u8 length, 246 bool write, struct ice_sq_cd *cd); 247u32 ice_get_link_speed(u16 index); 248 249enum ice_status 250ice_aq_prog_topo_dev_nvm(struct ice_hw *hw, 251 struct ice_aqc_link_topo_params *topo_params, 252 struct ice_sq_cd *cd); 253enum ice_status 254ice_aq_read_topo_dev_nvm(struct ice_hw *hw, 255 struct ice_aqc_link_topo_params *topo_params, 256 u32 start_address, u8 *buf, u8 buf_size, 257 struct ice_sq_cd *cd); 258 259enum ice_status 260ice_aq_get_port_options(struct ice_hw *hw, 261 struct ice_aqc_get_port_options_elem *options, 262 u8 *option_count, u8 lport, bool lport_valid, 263 u8 *active_option_idx, bool *active_option_valid, 264 u8 *pending_option_idx, bool *pending_option_valid); 265enum ice_status 266ice_aq_set_port_option(struct ice_hw *hw, u8 lport, u8 lport_valid, 267 u8 new_option); 268enum ice_status 269__ice_write_sr_word(struct ice_hw *hw, u32 offset, const u16 *data); 270enum ice_status 271__ice_write_sr_buf(struct ice_hw *hw, u32 offset, u16 words, const u16 *data); 272enum ice_status 273ice_cfg_vsi_rdma(struct ice_port_info *pi, u16 vsi_handle, u16 tc_bitmap, 274 u16 *max_rdmaqs); 275enum ice_status 276ice_ena_vsi_rdma_qset(struct ice_port_info *pi, u16 vsi_handle, u8 tc, 277 u16 *rdma_qset, u16 num_qsets, u32 *qset_teid); 278enum ice_status 279ice_dis_vsi_rdma_qset(struct ice_port_info *pi, u16 count, u32 *qset_teid, 280 u16 *q_id); 281enum ice_status 282ice_dis_vsi_txq(struct ice_port_info *pi, u16 vsi_handle, u8 tc, u8 num_queues, 283 u16 *q_handle, u16 *q_ids, u32 *q_teids, 284 enum ice_disq_rst_src rst_src, u16 vmvf_num, 285 struct ice_sq_cd *cd); 286enum ice_status 287ice_cfg_vsi_lan(struct ice_port_info *pi, u16 vsi_handle, u16 tc_bitmap, 288 u16 *max_lanqs); 289enum ice_status 290ice_ena_vsi_txq(struct ice_port_info *pi, u16 vsi_handle, u8 tc, u16 q_handle, 291 u8 num_qgrps, struct ice_aqc_add_tx_qgrp *buf, u16 buf_size, 292 struct ice_sq_cd *cd); 293enum ice_status 294ice_replay_pre_init(struct ice_hw *hw, struct ice_switch_info *sw); 295enum ice_status ice_replay_vsi(struct ice_hw *hw, u16 vsi_handle); 296void ice_replay_post(struct ice_hw *hw); 297struct ice_q_ctx * 298ice_get_lan_q_ctx(struct ice_hw *hw, u16 vsi_handle, u8 tc, u16 q_handle); 299enum ice_status 300ice_aq_get_sensor_reading(struct ice_hw *hw, u8 sensor, u8 format, 301 struct ice_aqc_get_sensor_reading_resp *data, 302 struct ice_sq_cd *cd); 303void 304ice_stat_update40(struct ice_hw *hw, u32 reg, bool prev_stat_loaded, 305 u64 *prev_stat, u64 *cur_stat); 306void 307ice_stat_update32(struct ice_hw *hw, u32 reg, bool prev_stat_loaded, 308 u64 *prev_stat, u64 *cur_stat); 309void 310ice_stat_update_repc(struct ice_hw *hw, u16 vsi_handle, bool prev_stat_loaded, 311 struct ice_eth_stats *cur_stats); 312enum ice_fw_modes ice_get_fw_mode(struct ice_hw *hw); 313void ice_print_rollback_msg(struct ice_hw *hw); 314bool ice_is_e810(struct ice_hw *hw); 315bool ice_is_e810t(struct ice_hw *hw); 316bool ice_is_e823(struct ice_hw *hw); 317enum ice_status 318ice_aq_alternate_write(struct ice_hw *hw, u32 reg_addr0, u32 reg_val0, 319 u32 reg_addr1, u32 reg_val1); 320enum ice_status 321ice_aq_alternate_read(struct ice_hw *hw, u32 reg_addr0, u32 *reg_val0, 322 u32 reg_addr1, u32 *reg_val1); 323enum ice_status 324ice_aq_alternate_write_done(struct ice_hw *hw, u8 bios_mode, 325 bool *reset_needed); 326enum ice_status ice_aq_alternate_clear(struct ice_hw *hw); 327enum ice_status 328ice_sched_query_elem(struct ice_hw *hw, u32 node_teid, 329 struct ice_aqc_txsched_elem_data *buf); 330enum ice_status 331ice_get_cur_lldp_persist_status(struct ice_hw *hw, u32 *lldp_status); 332enum ice_status 333ice_get_dflt_lldp_persist_status(struct ice_hw *hw, u32 *lldp_status); 334enum ice_status 335ice_aq_set_gpio(struct ice_hw *hw, u16 gpio_ctrl_handle, u8 pin_idx, bool value, 336 struct ice_sq_cd *cd); 337enum ice_status 338ice_aq_get_gpio(struct ice_hw *hw, u16 gpio_ctrl_handle, u8 pin_idx, 339 bool *value, struct ice_sq_cd *cd); 340bool ice_is_100m_speed_supported(struct ice_hw *hw); 341enum ice_status ice_get_netlist_ver_info(struct ice_hw *hw, struct ice_netlist_info *netlist); 342enum ice_status 343ice_aq_set_lldp_mib(struct ice_hw *hw, u8 mib_type, void *buf, u16 buf_size, 344 struct ice_sq_cd *cd); 345bool ice_fw_supports_lldp_fltr_ctrl(struct ice_hw *hw); 346enum ice_status 347ice_lldp_fltr_add_remove(struct ice_hw *hw, u16 vsi_num, bool add); 348enum ice_status ice_lldp_execute_pending_mib(struct ice_hw *hw); 349enum ice_status 350ice_aq_read_i2c(struct ice_hw *hw, struct ice_aqc_link_topo_addr topo_addr, 351 u16 bus_addr, __le16 addr, u8 params, u8 *data, 352 struct ice_sq_cd *cd); 353enum ice_status 354ice_aq_write_i2c(struct ice_hw *hw, struct ice_aqc_link_topo_addr topo_addr, 355 u16 bus_addr, __le16 addr, u8 params, const u8 *data, 356 struct ice_sq_cd *cd); 357enum ice_status 358ice_aq_set_health_status_config(struct ice_hw *hw, u8 event_source, 359 struct ice_sq_cd *cd); 360bool ice_is_fw_health_report_supported(struct ice_hw *hw); 361bool ice_fw_supports_report_dflt_cfg(struct ice_hw *hw); 362/* AQ API version for FW auto drop reports */ 363bool ice_is_fw_auto_drop_supported(struct ice_hw *hw); 364#endif /* _ICE_COMMON_H_ */ 365