17ec59eeaSAnirudh Venkataramanan /* SPDX-License-Identifier: GPL-2.0 */
27ec59eeaSAnirudh Venkataramanan /* Copyright (c) 2018, Intel Corporation. */
37ec59eeaSAnirudh Venkataramanan 
47ec59eeaSAnirudh Venkataramanan #ifndef _ICE_COMMON_H_
57ec59eeaSAnirudh Venkataramanan #define _ICE_COMMON_H_
67ec59eeaSAnirudh Venkataramanan 
743113ff7SKarol Kolacinski #include <linux/bitfield.h>
843113ff7SKarol Kolacinski 
97ec59eeaSAnirudh Venkataramanan #include "ice_type.h"
10031f2147SMd Fahad Iqbal Polash #include "ice_nvm.h"
11c7648810STony Nguyen #include "ice_flex_pipe.h"
12ddf30f7fSAnirudh Venkataramanan #include <linux/avf/virtchnl.h>
13649c87c6SJacob Keller #include "ice_switch.h"
14649c87c6SJacob Keller #include "ice_fdir.h"
157ec59eeaSAnirudh Venkataramanan 
163056df93SChinh T Cao #define ICE_SQ_SEND_DELAY_TIME_MS	10
173056df93SChinh T Cao #define ICE_SQ_SEND_MAX_EXECUTE		3
183056df93SChinh T Cao 
195e24d598STony Nguyen int ice_init_hw(struct ice_hw *hw);
20f31e4b6fSAnirudh Venkataramanan void ice_deinit_hw(struct ice_hw *hw);
215e24d598STony Nguyen int ice_check_reset(struct ice_hw *hw);
225e24d598STony Nguyen int ice_reset(struct ice_hw *hw, enum ice_reset_req req);
235e24d598STony Nguyen int ice_create_all_ctrlq(struct ice_hw *hw);
245e24d598STony Nguyen int ice_init_all_ctrlq(struct ice_hw *hw);
257ec59eeaSAnirudh Venkataramanan void ice_shutdown_all_ctrlq(struct ice_hw *hw);
265c91ecfdSJacob Keller void ice_destroy_all_ctrlq(struct ice_hw *hw);
275e24d598STony Nguyen int
28940b61afSAnirudh Venkataramanan ice_clean_rq_elem(struct ice_hw *hw, struct ice_ctl_q_info *cq,
29940b61afSAnirudh Venkataramanan 		  struct ice_rq_event_info *e, u16 *pending);
305e24d598STony Nguyen int
310b28b702SAnirudh Venkataramanan ice_get_link_status(struct ice_port_info *pi, bool *link_up);
325e24d598STony Nguyen int ice_update_link_info(struct ice_port_info *pi);
335e24d598STony Nguyen int
34f31e4b6fSAnirudh Venkataramanan ice_acquire_res(struct ice_hw *hw, enum ice_aq_res_ids res,
35ff2b1321SDan Nowlin 		enum ice_aq_res_access_type access, u32 timeout);
36f31e4b6fSAnirudh Venkataramanan void ice_release_res(struct ice_hw *hw, enum ice_aq_res_ids res);
375e24d598STony Nguyen int
3831ad4e4eSTony Nguyen ice_alloc_hw_res(struct ice_hw *hw, u16 type, u16 num, bool btm, u16 *res);
395e24d598STony Nguyen int
40451f2c44STony Nguyen ice_free_hw_res(struct ice_hw *hw, u16 type, u16 num, u16 *res);
41*52da2fb2SPrzemek Kitszel int ice_aq_alloc_free_res(struct ice_hw *hw,
4231ad4e4eSTony Nguyen 			  struct ice_aqc_alloc_free_res_elem *buf, u16 buf_size,
43*52da2fb2SPrzemek Kitszel 			  enum ice_adminq_opc opc);
448f5ee3c4SJacob Keller bool ice_is_sbq_supported(struct ice_hw *hw);
458f5ee3c4SJacob Keller struct ice_ctl_q_info *ice_get_sbq(struct ice_hw *hw);
465e24d598STony Nguyen int
477ec59eeaSAnirudh Venkataramanan ice_sq_send_cmd(struct ice_hw *hw, struct ice_ctl_q_info *cq,
487ec59eeaSAnirudh Venkataramanan 		struct ice_aq_desc *desc, void *buf, u16 buf_size,
497ec59eeaSAnirudh Venkataramanan 		struct ice_sq_cd *cd);
50f31e4b6fSAnirudh Venkataramanan void ice_clear_pxe_mode(struct ice_hw *hw);
515e24d598STony Nguyen int ice_get_caps(struct ice_hw *hw);
52f203dca3SAnirudh Venkataramanan 
53462acf6aSTony Nguyen void ice_set_safe_mode_caps(struct ice_hw *hw);
54462acf6aSTony Nguyen 
555e24d598STony Nguyen int
56cdedef59SAnirudh Venkataramanan ice_write_rxq_ctx(struct ice_hw *hw, struct ice_rlan_ctx *rlan_ctx,
57cdedef59SAnirudh Venkataramanan 		  u32 rxq_index);
58d76a60baSAnirudh Venkataramanan 
595e24d598STony Nguyen int
60e3c53928SBrett Creeley ice_aq_get_rss_lut(struct ice_hw *hw, struct ice_aq_get_set_rss_lut_params *get_params);
615e24d598STony Nguyen int
62e3c53928SBrett Creeley ice_aq_set_rss_lut(struct ice_hw *hw, struct ice_aq_get_set_rss_lut_params *set_params);
635e24d598STony Nguyen int
644fb33f31SAnirudh Venkataramanan ice_aq_get_rss_key(struct ice_hw *hw, u16 vsi_handle,
65d76a60baSAnirudh Venkataramanan 		   struct ice_aqc_get_set_rss_keys *keys);
665e24d598STony Nguyen int
674fb33f31SAnirudh Venkataramanan ice_aq_set_rss_key(struct ice_hw *hw, u16 vsi_handle,
68d76a60baSAnirudh Venkataramanan 		   struct ice_aqc_get_set_rss_keys *keys);
694fb33f31SAnirudh Venkataramanan 
707ec59eeaSAnirudh Venkataramanan bool ice_check_sq_alive(struct ice_hw *hw, struct ice_ctl_q_info *cq);
715e24d598STony Nguyen int ice_aq_q_shutdown(struct ice_hw *hw, bool unloading);
727ec59eeaSAnirudh Venkataramanan void ice_fill_dflt_direct_cmd_desc(struct ice_aq_desc *desc, u16 opcode);
73cdedef59SAnirudh Venkataramanan extern const struct ice_ctx_ele ice_tlan_ctx_info[];
745e24d598STony Nguyen int
757e34786aSBruce Allan ice_set_ctx(struct ice_hw *hw, u8 *src_ctx, u8 *dest_ctx,
767e34786aSBruce Allan 	    const struct ice_ctx_ele *ce_info);
77c7648810STony Nguyen 
78c7648810STony Nguyen extern struct mutex ice_global_cfg_lock_sw;
79c7648810STony Nguyen 
805e24d598STony Nguyen int
817ec59eeaSAnirudh Venkataramanan ice_aq_send_cmd(struct ice_hw *hw, struct ice_aq_desc *desc,
827ec59eeaSAnirudh Venkataramanan 		void *buf, u16 buf_size, struct ice_sq_cd *cd);
835e24d598STony Nguyen int ice_aq_get_fw_ver(struct ice_hw *hw, struct ice_sq_cd *cd);
8448cb27f2SChinh Cao 
855e24d598STony Nguyen int
86e3710a01SPaul M Stillwell Jr ice_aq_send_driver_ver(struct ice_hw *hw, struct ice_driver_ver *dv,
87e3710a01SPaul M Stillwell Jr 		       struct ice_sq_cd *cd);
885e24d598STony Nguyen int
89a1ffafb0SBrett Creeley ice_aq_set_port_params(struct ice_port_info *pi, bool double_vlan,
90a1ffafb0SBrett Creeley 		       struct ice_sq_cd *cd);
91a1ffafb0SBrett Creeley int
9248cb27f2SChinh Cao ice_aq_get_phy_caps(struct ice_port_info *pi, bool qual_mods, u8 report_mode,
9348cb27f2SChinh Cao 		    struct ice_aqc_get_phy_caps_data *caps,
9448cb27f2SChinh Cao 		    struct ice_sq_cd *cd);
95272ad794SKarol Kolacinski bool ice_is_pf_c827(struct ice_hw *hw);
965e24d598STony Nguyen int
978d7aab35SJacob Keller ice_aq_list_caps(struct ice_hw *hw, void *buf, u16 buf_size, u32 *cap_count,
988d7aab35SJacob Keller 		 enum ice_adminq_opc opc, struct ice_sq_cd *cd);
995e24d598STony Nguyen int
100d69ea414SJacob Keller ice_discover_dev_caps(struct ice_hw *hw, struct ice_hw_dev_caps *dev_caps);
10148cb27f2SChinh Cao void
102aef74145SAnirudh Venkataramanan ice_update_phy_type(u64 *phy_type_low, u64 *phy_type_high,
103aef74145SAnirudh Venkataramanan 		    u16 link_speeds_bitmap);
1045e24d598STony Nguyen int
105d671e3e0SJacob Keller ice_aq_manage_mac_write(struct ice_hw *hw, const u8 *mac_addr, u8 flags,
106e94d4478SAnirudh Venkataramanan 			struct ice_sq_cd *cd);
10706c16d89SJacob Keller bool ice_is_e810(struct ice_hw *hw);
1085e24d598STony Nguyen int ice_clear_pf_cfg(struct ice_hw *hw);
1095e24d598STony Nguyen int
1101a3571b5SPaul Greenwalt ice_aq_set_phy_cfg(struct ice_hw *hw, struct ice_port_info *pi,
11148cb27f2SChinh Cao 		   struct ice_aqc_set_phy_cfg_data *cfg, struct ice_sq_cd *cd);
112ea78ce4dSPaul Greenwalt bool ice_fw_supports_link_override(struct ice_hw *hw);
1135e24d598STony Nguyen int
114ea78ce4dSPaul Greenwalt ice_get_link_default_override(struct ice_link_default_override_tlv *ldo,
115ea78ce4dSPaul Greenwalt 			      struct ice_port_info *pi);
1165ee30564SPaul Greenwalt bool ice_is_phy_caps_an_enabled(struct ice_aqc_get_phy_caps_data *caps);
117ea78ce4dSPaul Greenwalt 
1181a3571b5SPaul Greenwalt enum ice_fc_mode ice_caps_to_fc_mode(u8 caps);
1191a3571b5SPaul Greenwalt enum ice_fec_mode ice_caps_to_fec_mode(u8 caps, u8 fec_options);
1205e24d598STony Nguyen int
12148cb27f2SChinh Cao ice_set_fc(struct ice_port_info *pi, u8 *aq_failures,
12248cb27f2SChinh Cao 	   bool ena_auto_link_update);
1235e24d598STony Nguyen int
1241a3571b5SPaul Greenwalt ice_cfg_phy_fc(struct ice_port_info *pi, struct ice_aqc_set_phy_cfg_data *cfg,
125388740b3STony Nguyen 	       enum ice_fc_mode req_mode);
1261a3571b5SPaul Greenwalt bool
1271a3571b5SPaul Greenwalt ice_phy_caps_equals_cfg(struct ice_aqc_get_phy_caps_data *caps,
1281a3571b5SPaul Greenwalt 			struct ice_aqc_set_phy_cfg_data *cfg);
129f776b3acSPaul Greenwalt void
130ea78ce4dSPaul Greenwalt ice_copy_phy_caps_to_cfg(struct ice_port_info *pi,
131ea78ce4dSPaul Greenwalt 			 struct ice_aqc_get_phy_caps_data *caps,
132f776b3acSPaul Greenwalt 			 struct ice_aqc_set_phy_cfg_data *cfg);
1335e24d598STony Nguyen int
1341a3571b5SPaul Greenwalt ice_cfg_phy_fec(struct ice_port_info *pi, struct ice_aqc_set_phy_cfg_data *cfg,
1351a3571b5SPaul Greenwalt 		enum ice_fec_mode fec);
1365e24d598STony Nguyen int
137fcea6f3dSAnirudh Venkataramanan ice_aq_set_link_restart_an(struct ice_port_info *pi, bool ena_link,
138fcea6f3dSAnirudh Venkataramanan 			   struct ice_sq_cd *cd);
1395e24d598STony Nguyen int
14042449105SAnirudh Venkataramanan ice_aq_set_mac_cfg(struct ice_hw *hw, u16 max_frame_size, struct ice_sq_cd *cd);
1415e24d598STony Nguyen int
142250c3b3eSBrett Creeley ice_aq_get_link_info(struct ice_port_info *pi, bool ena_lse,
143250c3b3eSBrett Creeley 		     struct ice_link_status *link, struct ice_sq_cd *cd);
1445e24d598STony Nguyen int
145250c3b3eSBrett Creeley ice_aq_set_event_mask(struct ice_hw *hw, u8 port_num, u16 mask,
146250c3b3eSBrett Creeley 		      struct ice_sq_cd *cd);
1475e24d598STony Nguyen int
1480e674aebSAnirudh Venkataramanan ice_aq_set_mac_loopback(struct ice_hw *hw, bool ena_lpbk, struct ice_sq_cd *cd);
1490e674aebSAnirudh Venkataramanan 
1505e24d598STony Nguyen int
1518e151d50SAnirudh Venkataramanan ice_aq_set_port_id_led(struct ice_port_info *pi, bool is_orig_mode,
1528e151d50SAnirudh Venkataramanan 		       struct ice_sq_cd *cd);
1535e24d598STony Nguyen int
154781f15eaSAnatolii Gerasymenko ice_aq_get_port_options(struct ice_hw *hw,
155781f15eaSAnatolii Gerasymenko 			struct ice_aqc_get_port_options_elem *options,
156781f15eaSAnatolii Gerasymenko 			u8 *option_count, u8 lport, bool lport_valid,
157781f15eaSAnatolii Gerasymenko 			u8 *active_option_idx, bool *active_option_valid,
158781f15eaSAnatolii Gerasymenko 			u8 *pending_option_idx, bool *pending_option_valid);
159781f15eaSAnatolii Gerasymenko int
160781f15eaSAnatolii Gerasymenko ice_aq_set_port_option(struct ice_hw *hw, u8 lport, u8 lport_valid,
161781f15eaSAnatolii Gerasymenko 		       u8 new_option);
162781f15eaSAnatolii Gerasymenko int
163a012dca9SScott W Taylor ice_aq_sff_eeprom(struct ice_hw *hw, u16 lport, u8 bus_addr,
164a012dca9SScott W Taylor 		  u16 mem_addr, u8 page, u8 set_page, u8 *data, u8 length,
165a012dca9SScott W Taylor 		  bool write, struct ice_sq_cd *cd);
1661d0e28a9SBrett Creeley u32 ice_get_link_speed(u16 index);
1678e151d50SAnirudh Venkataramanan 
168348048e7SDave Ertman int
169348048e7SDave Ertman ice_cfg_vsi_rdma(struct ice_port_info *pi, u16 vsi_handle, u16 tc_bitmap,
170348048e7SDave Ertman 		 u16 *max_rdmaqs);
171348048e7SDave Ertman int
172348048e7SDave Ertman ice_ena_vsi_rdma_qset(struct ice_port_info *pi, u16 vsi_handle, u8 tc,
173348048e7SDave Ertman 		      u16 *rdma_qset, u16 num_qsets, u32 *qset_teid);
174348048e7SDave Ertman int
175348048e7SDave Ertman ice_dis_vsi_rdma_qset(struct ice_port_info *pi, u16 count, u32 *qset_teid,
176348048e7SDave Ertman 		      u16 *q_id);
1775e24d598STony Nguyen int
178bb87ee0eSAnirudh Venkataramanan ice_dis_vsi_txq(struct ice_port_info *pi, u16 vsi_handle, u8 tc, u8 num_queues,
179bb87ee0eSAnirudh Venkataramanan 		u16 *q_handle, u16 *q_ids, u32 *q_teids,
180bb87ee0eSAnirudh Venkataramanan 		enum ice_disq_rst_src rst_src, u16 vmvf_num,
181bb87ee0eSAnirudh Venkataramanan 		struct ice_sq_cd *cd);
1825e24d598STony Nguyen int
1834fb33f31SAnirudh Venkataramanan ice_cfg_vsi_lan(struct ice_port_info *pi, u16 vsi_handle, u8 tc_bitmap,
1845513b920SAnirudh Venkataramanan 		u16 *max_lanqs);
1855e24d598STony Nguyen int
186bb87ee0eSAnirudh Venkataramanan ice_ena_vsi_txq(struct ice_port_info *pi, u16 vsi_handle, u8 tc, u16 q_handle,
187bb87ee0eSAnirudh Venkataramanan 		u8 num_qgrps, struct ice_aqc_add_tx_qgrp *buf, u16 buf_size,
188cdedef59SAnirudh Venkataramanan 		struct ice_sq_cd *cd);
18923ccae5cSDave Ertman int
19023ccae5cSDave Ertman ice_aq_cfg_lan_txq(struct ice_hw *hw, struct ice_aqc_cfg_txqs_buf *buf,
19123ccae5cSDave Ertman 		   u16 buf_size, u16 num_qs, u8 oldport, u8 newport,
19223ccae5cSDave Ertman 		   struct ice_sq_cd *cd);
1935e24d598STony Nguyen int ice_replay_vsi(struct ice_hw *hw, u16 vsi_handle);
194334cb062SAnirudh Venkataramanan void ice_replay_post(struct ice_hw *hw);
1958b97ceb1SHieu Tran void ice_output_fw_log(struct ice_hw *hw, struct ice_aq_desc *desc, void *buf);
1961ddef455SUsha Ketineni struct ice_q_ctx *
1971ddef455SUsha Ketineni ice_get_lan_q_ctx(struct ice_hw *hw, u16 vsi_handle, u8 tc, u16 q_handle);
1988f5ee3c4SJacob Keller int ice_sbq_rw_reg(struct ice_hw *hw, struct ice_sbq_msg_input *in);
199c8b7abddSBruce Allan void
20036517fd3SJacob Keller ice_stat_update40(struct ice_hw *hw, u32 reg, bool prev_stat_loaded,
20136517fd3SJacob Keller 		  u64 *prev_stat, u64 *cur_stat);
202c8b7abddSBruce Allan void
203c8b7abddSBruce Allan ice_stat_update32(struct ice_hw *hw, u32 reg, bool prev_stat_loaded,
20445d3d428SAnirudh Venkataramanan 		  u64 *prev_stat, u64 *cur_stat);
205885fe693SMaciej Machnikowski bool ice_is_e810t(struct ice_hw *hw);
206634d841dSKarol Kolacinski bool ice_is_e823(struct ice_hw *hw);
2075e24d598STony Nguyen int
2087b9ffc76SAnirudh Venkataramanan ice_sched_query_elem(struct ice_hw *hw, u32 node_teid,
209b3c38904SBruce Allan 		     struct ice_aqc_txsched_elem_data *buf);
2107f9ab54dSJacob Keller int
2117f9ab54dSJacob Keller ice_aq_set_driver_param(struct ice_hw *hw, enum ice_aqc_driver_params idx,
2127f9ab54dSJacob Keller 			u32 value, struct ice_sq_cd *cd);
2137f9ab54dSJacob Keller int
2147f9ab54dSJacob Keller ice_aq_get_driver_param(struct ice_hw *hw, enum ice_aqc_driver_params idx,
2157f9ab54dSJacob Keller 			u32 *value, struct ice_sq_cd *cd);
2163bb6324bSMaciej Machnikowski int
2173bb6324bSMaciej Machnikowski ice_aq_set_gpio(struct ice_hw *hw, u16 gpio_ctrl_handle, u8 pin_idx, bool value,
2183bb6324bSMaciej Machnikowski 		struct ice_sq_cd *cd);
2193bb6324bSMaciej Machnikowski int
2203bb6324bSMaciej Machnikowski ice_aq_get_gpio(struct ice_hw *hw, u16 gpio_ctrl_handle, u8 pin_idx,
2213bb6324bSMaciej Machnikowski 		bool *value, struct ice_sq_cd *cd);
22239ed02a4SAnirudh Venkataramanan bool ice_is_100m_speed_supported(struct ice_hw *hw);
2235e24d598STony Nguyen int
2247d9c9b79SDave Ertman ice_aq_set_lldp_mib(struct ice_hw *hw, u8 mib_type, void *buf, u16 buf_size,
2257d9c9b79SDave Ertman 		    struct ice_sq_cd *cd);
22634295a36SDave Ertman bool ice_fw_supports_lldp_fltr_ctrl(struct ice_hw *hw);
2275e24d598STony Nguyen int
22834295a36SDave Ertman ice_lldp_fltr_add_remove(struct ice_hw *hw, u16 vsi_num, bool add);
229a4f68f37STsotne Chakhvadze int ice_lldp_execute_pending_mib(struct ice_hw *hw);
23043113ff7SKarol Kolacinski int
23143113ff7SKarol Kolacinski ice_aq_read_i2c(struct ice_hw *hw, struct ice_aqc_link_topo_addr topo_addr,
23243113ff7SKarol Kolacinski 		u16 bus_addr, __le16 addr, u8 params, u8 *data,
23343113ff7SKarol Kolacinski 		struct ice_sq_cd *cd);
234fcf9b695SKarol Kolacinski int
235fcf9b695SKarol Kolacinski ice_aq_write_i2c(struct ice_hw *hw, struct ice_aqc_link_topo_addr topo_addr,
236bf15bb38SMichal Schmidt 		 u16 bus_addr, __le16 addr, u8 params, const u8 *data,
237fcf9b695SKarol Kolacinski 		 struct ice_sq_cd *cd);
2380a02944fSAnirudh Venkataramanan bool ice_fw_supports_report_dflt_cfg(struct ice_hw *hw);
2397ec59eeaSAnirudh Venkataramanan #endif /* _ICE_COMMON_H_ */
240