1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018, Intel Corporation. */
4 #include "ice_common.h"
6 #include "ice_adminq_cmd.h"
8 #define ICE_PF_RESET_WAIT_COUNT 200
10 #define ICE_NIC_FLX_ENTRY(hw, mdid, idx) \
11 wr32((hw), GLFLXP_RXDID_FLX_WRD_##idx(ICE_RXDID_FLEX_NIC), \
12 ((ICE_RX_OPC_MDID << \
13 GLFLXP_RXDID_FLX_WRD_##idx##_RXDID_OPCODE_S) & \
14 GLFLXP_RXDID_FLX_WRD_##idx##_RXDID_OPCODE_M) | \
15 (((mdid) << GLFLXP_RXDID_FLX_WRD_##idx##_PROT_MDID_S) & \
16 GLFLXP_RXDID_FLX_WRD_##idx##_PROT_MDID_M))
18 #define ICE_NIC_FLX_FLG_ENTRY(hw, flg_0, flg_1, flg_2, flg_3, idx) \
19 wr32((hw), GLFLXP_RXDID_FLAGS(ICE_RXDID_FLEX_NIC, idx), \
20 (((flg_0) << GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_S) & \
21 GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_M) | \
22 (((flg_1) << GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_1_S) & \
23 GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_1_M) | \
24 (((flg_2) << GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_2_S) & \
25 GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_2_M) | \
26 (((flg_3) << GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_3_S) & \
27 GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_3_M))
30 * ice_set_mac_type - Sets MAC type
31 * @hw: pointer to the HW structure
33 * This function sets the MAC type of the adapter based on the
34 * vendor ID and device ID stored in the hw structure.
36 static enum ice_status
ice_set_mac_type(struct ice_hw
*hw
)
38 if (hw
->vendor_id
!= PCI_VENDOR_ID_INTEL
)
39 return ICE_ERR_DEVICE_NOT_SUPPORTED
;
41 hw
->mac_type
= ICE_MAC_GENERIC
;
46 * ice_clear_pf_cfg - Clear PF configuration
47 * @hw: pointer to the hardware structure
49 * Clears any existing PF configuration (VSIs, VSI lists, switch rules, port
50 * configuration, flow director filters, etc.).
52 enum ice_status
ice_clear_pf_cfg(struct ice_hw
*hw
)
54 struct ice_aq_desc desc
;
56 ice_fill_dflt_direct_cmd_desc(&desc
, ice_aqc_opc_clear_pf_cfg
);
58 return ice_aq_send_cmd(hw
, &desc
, NULL
, 0, NULL
);
62 * ice_aq_manage_mac_read - manage MAC address read command
63 * @hw: pointer to the hw struct
64 * @buf: a virtual buffer to hold the manage MAC read response
65 * @buf_size: Size of the virtual buffer
66 * @cd: pointer to command details structure or NULL
68 * This function is used to return per PF station MAC address (0x0107).
69 * NOTE: Upon successful completion of this command, MAC address information
70 * is returned in user specified buffer. Please interpret user specified
71 * buffer as "manage_mac_read" response.
72 * Response such as various MAC addresses are stored in HW struct (port.mac)
73 * ice_aq_discover_caps is expected to be called before this function is called.
75 static enum ice_status
76 ice_aq_manage_mac_read(struct ice_hw
*hw
, void *buf
, u16 buf_size
,
79 struct ice_aqc_manage_mac_read_resp
*resp
;
80 struct ice_aqc_manage_mac_read
*cmd
;
81 struct ice_aq_desc desc
;
82 enum ice_status status
;
86 cmd
= &desc
.params
.mac_read
;
88 if (buf_size
< sizeof(*resp
))
89 return ICE_ERR_BUF_TOO_SHORT
;
91 ice_fill_dflt_direct_cmd_desc(&desc
, ice_aqc_opc_manage_mac_read
);
93 status
= ice_aq_send_cmd(hw
, &desc
, buf
, buf_size
, cd
);
97 resp
= (struct ice_aqc_manage_mac_read_resp
*)buf
;
98 flags
= le16_to_cpu(cmd
->flags
) & ICE_AQC_MAN_MAC_READ_M
;
100 if (!(flags
& ICE_AQC_MAN_MAC_LAN_ADDR_VALID
)) {
101 ice_debug(hw
, ICE_DBG_LAN
, "got invalid MAC address\n");
105 /* A single port can report up to two (LAN and WoL) addresses */
106 for (i
= 0; i
< cmd
->num_addr
; i
++)
107 if (resp
[i
].addr_type
== ICE_AQC_MAN_MAC_ADDR_TYPE_LAN
) {
108 ether_addr_copy(hw
->port_info
->mac
.lan_addr
,
110 ether_addr_copy(hw
->port_info
->mac
.perm_addr
,
119 * ice_aq_get_phy_caps - returns PHY capabilities
120 * @pi: port information structure
121 * @qual_mods: report qualified modules
122 * @report_mode: report mode capabilities
123 * @pcaps: structure for PHY capabilities to be filled
124 * @cd: pointer to command details structure or NULL
126 * Returns the various PHY capabilities supported on the Port (0x0600)
128 static enum ice_status
129 ice_aq_get_phy_caps(struct ice_port_info
*pi
, bool qual_mods
, u8 report_mode
,
130 struct ice_aqc_get_phy_caps_data
*pcaps
,
131 struct ice_sq_cd
*cd
)
133 struct ice_aqc_get_phy_caps
*cmd
;
134 u16 pcaps_size
= sizeof(*pcaps
);
135 struct ice_aq_desc desc
;
136 enum ice_status status
;
138 cmd
= &desc
.params
.get_phy
;
140 if (!pcaps
|| (report_mode
& ~ICE_AQC_REPORT_MODE_M
) || !pi
)
141 return ICE_ERR_PARAM
;
143 ice_fill_dflt_direct_cmd_desc(&desc
, ice_aqc_opc_get_phy_caps
);
146 cmd
->param0
|= cpu_to_le16(ICE_AQC_GET_PHY_RQM
);
148 cmd
->param0
|= cpu_to_le16(report_mode
);
149 status
= ice_aq_send_cmd(pi
->hw
, &desc
, pcaps
, pcaps_size
, cd
);
151 if (!status
&& report_mode
== ICE_AQC_REPORT_TOPO_CAP
)
152 pi
->phy
.phy_type_low
= le64_to_cpu(pcaps
->phy_type_low
);
158 * ice_get_media_type - Gets media type
159 * @pi: port information structure
161 static enum ice_media_type
ice_get_media_type(struct ice_port_info
*pi
)
163 struct ice_link_status
*hw_link_info
;
166 return ICE_MEDIA_UNKNOWN
;
168 hw_link_info
= &pi
->phy
.link_info
;
170 if (hw_link_info
->phy_type_low
) {
171 switch (hw_link_info
->phy_type_low
) {
172 case ICE_PHY_TYPE_LOW_1000BASE_SX
:
173 case ICE_PHY_TYPE_LOW_1000BASE_LX
:
174 case ICE_PHY_TYPE_LOW_10GBASE_SR
:
175 case ICE_PHY_TYPE_LOW_10GBASE_LR
:
176 case ICE_PHY_TYPE_LOW_10G_SFI_C2C
:
177 case ICE_PHY_TYPE_LOW_25GBASE_SR
:
178 case ICE_PHY_TYPE_LOW_25GBASE_LR
:
179 case ICE_PHY_TYPE_LOW_25G_AUI_C2C
:
180 case ICE_PHY_TYPE_LOW_40GBASE_SR4
:
181 case ICE_PHY_TYPE_LOW_40GBASE_LR4
:
182 return ICE_MEDIA_FIBER
;
183 case ICE_PHY_TYPE_LOW_100BASE_TX
:
184 case ICE_PHY_TYPE_LOW_1000BASE_T
:
185 case ICE_PHY_TYPE_LOW_2500BASE_T
:
186 case ICE_PHY_TYPE_LOW_5GBASE_T
:
187 case ICE_PHY_TYPE_LOW_10GBASE_T
:
188 case ICE_PHY_TYPE_LOW_25GBASE_T
:
189 return ICE_MEDIA_BASET
;
190 case ICE_PHY_TYPE_LOW_10G_SFI_DA
:
191 case ICE_PHY_TYPE_LOW_25GBASE_CR
:
192 case ICE_PHY_TYPE_LOW_25GBASE_CR_S
:
193 case ICE_PHY_TYPE_LOW_25GBASE_CR1
:
194 case ICE_PHY_TYPE_LOW_40GBASE_CR4
:
196 case ICE_PHY_TYPE_LOW_1000BASE_KX
:
197 case ICE_PHY_TYPE_LOW_2500BASE_KX
:
198 case ICE_PHY_TYPE_LOW_2500BASE_X
:
199 case ICE_PHY_TYPE_LOW_5GBASE_KR
:
200 case ICE_PHY_TYPE_LOW_10GBASE_KR_CR1
:
201 case ICE_PHY_TYPE_LOW_25GBASE_KR
:
202 case ICE_PHY_TYPE_LOW_25GBASE_KR1
:
203 case ICE_PHY_TYPE_LOW_25GBASE_KR_S
:
204 case ICE_PHY_TYPE_LOW_40GBASE_KR4
:
205 return ICE_MEDIA_BACKPLANE
;
209 return ICE_MEDIA_UNKNOWN
;
213 * ice_aq_get_link_info
214 * @pi: port information structure
215 * @ena_lse: enable/disable LinkStatusEvent reporting
216 * @link: pointer to link status structure - optional
217 * @cd: pointer to command details structure or NULL
219 * Get Link Status (0x607). Returns the link status of the adapter.
222 ice_aq_get_link_info(struct ice_port_info
*pi
, bool ena_lse
,
223 struct ice_link_status
*link
, struct ice_sq_cd
*cd
)
225 struct ice_link_status
*hw_link_info_old
, *hw_link_info
;
226 struct ice_aqc_get_link_status_data link_data
= { 0 };
227 struct ice_aqc_get_link_status
*resp
;
228 enum ice_media_type
*hw_media_type
;
229 struct ice_fc_info
*hw_fc_info
;
230 bool tx_pause
, rx_pause
;
231 struct ice_aq_desc desc
;
232 enum ice_status status
;
236 return ICE_ERR_PARAM
;
237 hw_link_info_old
= &pi
->phy
.link_info_old
;
238 hw_media_type
= &pi
->phy
.media_type
;
239 hw_link_info
= &pi
->phy
.link_info
;
240 hw_fc_info
= &pi
->fc
;
242 ice_fill_dflt_direct_cmd_desc(&desc
, ice_aqc_opc_get_link_status
);
243 cmd_flags
= (ena_lse
) ? ICE_AQ_LSE_ENA
: ICE_AQ_LSE_DIS
;
244 resp
= &desc
.params
.get_link_status
;
245 resp
->cmd_flags
= cpu_to_le16(cmd_flags
);
246 resp
->lport_num
= pi
->lport
;
248 status
= ice_aq_send_cmd(pi
->hw
, &desc
, &link_data
, sizeof(link_data
),
254 /* save off old link status information */
255 *hw_link_info_old
= *hw_link_info
;
257 /* update current link status information */
258 hw_link_info
->link_speed
= le16_to_cpu(link_data
.link_speed
);
259 hw_link_info
->phy_type_low
= le64_to_cpu(link_data
.phy_type_low
);
260 *hw_media_type
= ice_get_media_type(pi
);
261 hw_link_info
->link_info
= link_data
.link_info
;
262 hw_link_info
->an_info
= link_data
.an_info
;
263 hw_link_info
->ext_info
= link_data
.ext_info
;
264 hw_link_info
->max_frame_size
= le16_to_cpu(link_data
.max_frame_size
);
265 hw_link_info
->pacing
= link_data
.cfg
& ICE_AQ_CFG_PACING_M
;
268 tx_pause
= !!(link_data
.an_info
& ICE_AQ_LINK_PAUSE_TX
);
269 rx_pause
= !!(link_data
.an_info
& ICE_AQ_LINK_PAUSE_RX
);
270 if (tx_pause
&& rx_pause
)
271 hw_fc_info
->current_mode
= ICE_FC_FULL
;
273 hw_fc_info
->current_mode
= ICE_FC_TX_PAUSE
;
275 hw_fc_info
->current_mode
= ICE_FC_RX_PAUSE
;
277 hw_fc_info
->current_mode
= ICE_FC_NONE
;
279 hw_link_info
->lse_ena
=
280 !!(resp
->cmd_flags
& cpu_to_le16(ICE_AQ_LSE_IS_ENABLED
));
282 /* save link status information */
284 *link
= *hw_link_info
;
286 /* flag cleared so calling functions don't call AQ again */
287 pi
->phy
.get_link_info
= false;
293 * ice_init_flex_parser - initialize rx flex parser
294 * @hw: pointer to the hardware structure
296 * Function to initialize flex descriptors
298 static void ice_init_flex_parser(struct ice_hw
*hw
)
302 ICE_NIC_FLX_ENTRY(hw
, ICE_RX_MDID_HASH_LOW
, 0);
303 ICE_NIC_FLX_ENTRY(hw
, ICE_RX_MDID_HASH_HIGH
, 1);
304 ICE_NIC_FLX_ENTRY(hw
, ICE_RX_MDID_FLOW_ID_LOWER
, 2);
305 ICE_NIC_FLX_ENTRY(hw
, ICE_RX_MDID_FLOW_ID_HIGH
, 3);
306 ICE_NIC_FLX_FLG_ENTRY(hw
, ICE_RXFLG_PKT_FRG
, ICE_RXFLG_UDP_GRE
,
307 ICE_RXFLG_PKT_DSI
, ICE_RXFLG_FIN
, idx
++);
308 ICE_NIC_FLX_FLG_ENTRY(hw
, ICE_RXFLG_SYN
, ICE_RXFLG_RST
,
309 ICE_RXFLG_PKT_DSI
, ICE_RXFLG_PKT_DSI
, idx
++);
310 ICE_NIC_FLX_FLG_ENTRY(hw
, ICE_RXFLG_PKT_DSI
, ICE_RXFLG_PKT_DSI
,
311 ICE_RXFLG_EVLAN_x8100
, ICE_RXFLG_EVLAN_x9100
,
313 ICE_NIC_FLX_FLG_ENTRY(hw
, ICE_RXFLG_VLAN_x8100
, ICE_RXFLG_TNL_VLAN
,
314 ICE_RXFLG_TNL_MAC
, ICE_RXFLG_TNL0
, idx
++);
315 ICE_NIC_FLX_FLG_ENTRY(hw
, ICE_RXFLG_TNL1
, ICE_RXFLG_TNL2
,
316 ICE_RXFLG_PKT_DSI
, ICE_RXFLG_PKT_DSI
, idx
);
320 * ice_init_fltr_mgmt_struct - initializes filter management list and locks
321 * @hw: pointer to the hw struct
323 static enum ice_status
ice_init_fltr_mgmt_struct(struct ice_hw
*hw
)
325 struct ice_switch_info
*sw
;
327 hw
->switch_info
= devm_kzalloc(ice_hw_to_dev(hw
),
328 sizeof(*hw
->switch_info
), GFP_KERNEL
);
329 sw
= hw
->switch_info
;
332 return ICE_ERR_NO_MEMORY
;
334 INIT_LIST_HEAD(&sw
->vsi_list_map_head
);
336 mutex_init(&sw
->mac_list_lock
);
337 INIT_LIST_HEAD(&sw
->mac_list_head
);
339 mutex_init(&sw
->vlan_list_lock
);
340 INIT_LIST_HEAD(&sw
->vlan_list_head
);
342 mutex_init(&sw
->eth_m_list_lock
);
343 INIT_LIST_HEAD(&sw
->eth_m_list_head
);
345 mutex_init(&sw
->promisc_list_lock
);
346 INIT_LIST_HEAD(&sw
->promisc_list_head
);
348 mutex_init(&sw
->mac_vlan_list_lock
);
349 INIT_LIST_HEAD(&sw
->mac_vlan_list_head
);
355 * ice_cleanup_fltr_mgmt_struct - cleanup filter management list and locks
356 * @hw: pointer to the hw struct
358 static void ice_cleanup_fltr_mgmt_struct(struct ice_hw
*hw
)
360 struct ice_switch_info
*sw
= hw
->switch_info
;
361 struct ice_vsi_list_map_info
*v_pos_map
;
362 struct ice_vsi_list_map_info
*v_tmp_map
;
364 list_for_each_entry_safe(v_pos_map
, v_tmp_map
, &sw
->vsi_list_map_head
,
366 list_del(&v_pos_map
->list_entry
);
367 devm_kfree(ice_hw_to_dev(hw
), v_pos_map
);
370 mutex_destroy(&sw
->mac_list_lock
);
371 mutex_destroy(&sw
->vlan_list_lock
);
372 mutex_destroy(&sw
->eth_m_list_lock
);
373 mutex_destroy(&sw
->promisc_list_lock
);
374 mutex_destroy(&sw
->mac_vlan_list_lock
);
376 devm_kfree(ice_hw_to_dev(hw
), sw
);
380 * ice_init_hw - main hardware initialization routine
381 * @hw: pointer to the hardware structure
383 enum ice_status
ice_init_hw(struct ice_hw
*hw
)
385 struct ice_aqc_get_phy_caps_data
*pcaps
;
386 enum ice_status status
;
390 /* Set MAC type based on DeviceID */
391 status
= ice_set_mac_type(hw
);
395 hw
->pf_id
= (u8
)(rd32(hw
, PF_FUNC_RID
) &
396 PF_FUNC_RID_FUNC_NUM_M
) >>
397 PF_FUNC_RID_FUNC_NUM_S
;
399 status
= ice_reset(hw
, ICE_RESET_PFR
);
403 /* set these values to minimum allowed */
404 hw
->itr_gran_200
= ICE_ITR_GRAN_MIN_200
;
405 hw
->itr_gran_100
= ICE_ITR_GRAN_MIN_100
;
406 hw
->itr_gran_50
= ICE_ITR_GRAN_MIN_50
;
407 hw
->itr_gran_25
= ICE_ITR_GRAN_MIN_25
;
409 status
= ice_init_all_ctrlq(hw
);
411 goto err_unroll_cqinit
;
413 status
= ice_clear_pf_cfg(hw
);
415 goto err_unroll_cqinit
;
417 ice_clear_pxe_mode(hw
);
419 status
= ice_init_nvm(hw
);
421 goto err_unroll_cqinit
;
423 status
= ice_get_caps(hw
);
425 goto err_unroll_cqinit
;
427 hw
->port_info
= devm_kzalloc(ice_hw_to_dev(hw
),
428 sizeof(*hw
->port_info
), GFP_KERNEL
);
429 if (!hw
->port_info
) {
430 status
= ICE_ERR_NO_MEMORY
;
431 goto err_unroll_cqinit
;
434 /* set the back pointer to hw */
435 hw
->port_info
->hw
= hw
;
437 /* Initialize port_info struct with switch configuration data */
438 status
= ice_get_initial_sw_cfg(hw
);
440 goto err_unroll_alloc
;
444 /* Query the allocated resources for tx scheduler */
445 status
= ice_sched_query_res_alloc(hw
);
447 ice_debug(hw
, ICE_DBG_SCHED
,
448 "Failed to get scheduler allocated resources\n");
449 goto err_unroll_alloc
;
452 /* Initialize port_info struct with scheduler data */
453 status
= ice_sched_init_port(hw
->port_info
);
455 goto err_unroll_sched
;
457 pcaps
= devm_kzalloc(ice_hw_to_dev(hw
), sizeof(*pcaps
), GFP_KERNEL
);
459 status
= ICE_ERR_NO_MEMORY
;
460 goto err_unroll_sched
;
463 /* Initialize port_info struct with PHY capabilities */
464 status
= ice_aq_get_phy_caps(hw
->port_info
, false,
465 ICE_AQC_REPORT_TOPO_CAP
, pcaps
, NULL
);
466 devm_kfree(ice_hw_to_dev(hw
), pcaps
);
468 goto err_unroll_sched
;
470 /* Initialize port_info struct with link information */
471 status
= ice_aq_get_link_info(hw
->port_info
, false, NULL
, NULL
);
473 goto err_unroll_sched
;
475 status
= ice_init_fltr_mgmt_struct(hw
);
477 goto err_unroll_sched
;
479 /* Get MAC information */
480 /* A single port can report up to two (LAN and WoL) addresses */
481 mac_buf
= devm_kcalloc(ice_hw_to_dev(hw
), 2,
482 sizeof(struct ice_aqc_manage_mac_read_resp
),
484 mac_buf_len
= 2 * sizeof(struct ice_aqc_manage_mac_read_resp
);
487 status
= ICE_ERR_NO_MEMORY
;
488 goto err_unroll_fltr_mgmt_struct
;
491 status
= ice_aq_manage_mac_read(hw
, mac_buf
, mac_buf_len
, NULL
);
492 devm_kfree(ice_hw_to_dev(hw
), mac_buf
);
495 goto err_unroll_fltr_mgmt_struct
;
497 ice_init_flex_parser(hw
);
501 err_unroll_fltr_mgmt_struct
:
502 ice_cleanup_fltr_mgmt_struct(hw
);
504 ice_sched_cleanup_all(hw
);
506 devm_kfree(ice_hw_to_dev(hw
), hw
->port_info
);
508 ice_shutdown_all_ctrlq(hw
);
513 * ice_deinit_hw - unroll initialization operations done by ice_init_hw
514 * @hw: pointer to the hardware structure
516 void ice_deinit_hw(struct ice_hw
*hw
)
518 ice_sched_cleanup_all(hw
);
519 ice_shutdown_all_ctrlq(hw
);
522 devm_kfree(ice_hw_to_dev(hw
), hw
->port_info
);
523 hw
->port_info
= NULL
;
526 ice_cleanup_fltr_mgmt_struct(hw
);
530 * ice_check_reset - Check to see if a global reset is complete
531 * @hw: pointer to the hardware structure
533 enum ice_status
ice_check_reset(struct ice_hw
*hw
)
535 u32 cnt
, reg
= 0, grst_delay
;
537 /* Poll for Device Active state in case a recent CORER, GLOBR,
538 * or EMPR has occurred. The grst delay value is in 100ms units.
539 * Add 1sec for outstanding AQ commands that can take a long time.
541 grst_delay
= ((rd32(hw
, GLGEN_RSTCTL
) & GLGEN_RSTCTL_GRSTDEL_M
) >>
542 GLGEN_RSTCTL_GRSTDEL_S
) + 10;
544 for (cnt
= 0; cnt
< grst_delay
; cnt
++) {
546 reg
= rd32(hw
, GLGEN_RSTAT
);
547 if (!(reg
& GLGEN_RSTAT_DEVSTATE_M
))
551 if (cnt
== grst_delay
) {
552 ice_debug(hw
, ICE_DBG_INIT
,
553 "Global reset polling failed to complete.\n");
554 return ICE_ERR_RESET_FAILED
;
557 #define ICE_RESET_DONE_MASK (GLNVM_ULD_CORER_DONE_M | \
558 GLNVM_ULD_GLOBR_DONE_M)
560 /* Device is Active; check Global Reset processes are done */
561 for (cnt
= 0; cnt
< ICE_PF_RESET_WAIT_COUNT
; cnt
++) {
562 reg
= rd32(hw
, GLNVM_ULD
) & ICE_RESET_DONE_MASK
;
563 if (reg
== ICE_RESET_DONE_MASK
) {
564 ice_debug(hw
, ICE_DBG_INIT
,
565 "Global reset processes done. %d\n", cnt
);
571 if (cnt
== ICE_PF_RESET_WAIT_COUNT
) {
572 ice_debug(hw
, ICE_DBG_INIT
,
573 "Wait for Reset Done timed out. GLNVM_ULD = 0x%x\n",
575 return ICE_ERR_RESET_FAILED
;
582 * ice_pf_reset - Reset the PF
583 * @hw: pointer to the hardware structure
585 * If a global reset has been triggered, this function checks
586 * for its completion and then issues the PF reset
588 static enum ice_status
ice_pf_reset(struct ice_hw
*hw
)
592 /* If at function entry a global reset was already in progress, i.e.
593 * state is not 'device active' or any of the reset done bits are not
594 * set in GLNVM_ULD, there is no need for a PF Reset; poll until the
595 * global reset is done.
597 if ((rd32(hw
, GLGEN_RSTAT
) & GLGEN_RSTAT_DEVSTATE_M
) ||
598 (rd32(hw
, GLNVM_ULD
) & ICE_RESET_DONE_MASK
) ^ ICE_RESET_DONE_MASK
) {
599 /* poll on global reset currently in progress until done */
600 if (ice_check_reset(hw
))
601 return ICE_ERR_RESET_FAILED
;
607 reg
= rd32(hw
, PFGEN_CTRL
);
609 wr32(hw
, PFGEN_CTRL
, (reg
| PFGEN_CTRL_PFSWR_M
));
611 for (cnt
= 0; cnt
< ICE_PF_RESET_WAIT_COUNT
; cnt
++) {
612 reg
= rd32(hw
, PFGEN_CTRL
);
613 if (!(reg
& PFGEN_CTRL_PFSWR_M
))
619 if (cnt
== ICE_PF_RESET_WAIT_COUNT
) {
620 ice_debug(hw
, ICE_DBG_INIT
,
621 "PF reset polling failed to complete.\n");
622 return ICE_ERR_RESET_FAILED
;
629 * ice_reset - Perform different types of reset
630 * @hw: pointer to the hardware structure
631 * @req: reset request
633 * This function triggers a reset as specified by the req parameter.
636 * If anything other than a PF reset is triggered, PXE mode is restored.
637 * This has to be cleared using ice_clear_pxe_mode again, once the AQ
638 * interface has been restored in the rebuild flow.
640 enum ice_status
ice_reset(struct ice_hw
*hw
, enum ice_reset_req req
)
646 return ice_pf_reset(hw
);
647 case ICE_RESET_CORER
:
648 ice_debug(hw
, ICE_DBG_INIT
, "CoreR requested\n");
649 val
= GLGEN_RTRIG_CORER_M
;
651 case ICE_RESET_GLOBR
:
652 ice_debug(hw
, ICE_DBG_INIT
, "GlobalR requested\n");
653 val
= GLGEN_RTRIG_GLOBR_M
;
657 val
|= rd32(hw
, GLGEN_RTRIG
);
658 wr32(hw
, GLGEN_RTRIG
, val
);
661 /* wait for the FW to be ready */
662 return ice_check_reset(hw
);
666 * ice_copy_rxq_ctx_to_hw
667 * @hw: pointer to the hardware structure
668 * @ice_rxq_ctx: pointer to the rxq context
669 * @rxq_index: the index of the rx queue
671 * Copies rxq context from dense structure to hw register space
673 static enum ice_status
674 ice_copy_rxq_ctx_to_hw(struct ice_hw
*hw
, u8
*ice_rxq_ctx
, u32 rxq_index
)
679 return ICE_ERR_BAD_PTR
;
681 if (rxq_index
> QRX_CTRL_MAX_INDEX
)
682 return ICE_ERR_PARAM
;
684 /* Copy each dword separately to hw */
685 for (i
= 0; i
< ICE_RXQ_CTX_SIZE_DWORDS
; i
++) {
686 wr32(hw
, QRX_CONTEXT(i
, rxq_index
),
687 *((u32
*)(ice_rxq_ctx
+ (i
* sizeof(u32
)))));
689 ice_debug(hw
, ICE_DBG_QCTX
, "qrxdata[%d]: %08X\n", i
,
690 *((u32
*)(ice_rxq_ctx
+ (i
* sizeof(u32
)))));
696 /* LAN Rx Queue Context */
697 static const struct ice_ctx_ele ice_rlan_ctx_info
[] = {
698 /* Field Width LSB */
699 ICE_CTX_STORE(ice_rlan_ctx
, head
, 13, 0),
700 ICE_CTX_STORE(ice_rlan_ctx
, cpuid
, 8, 13),
701 ICE_CTX_STORE(ice_rlan_ctx
, base
, 57, 32),
702 ICE_CTX_STORE(ice_rlan_ctx
, qlen
, 13, 89),
703 ICE_CTX_STORE(ice_rlan_ctx
, dbuf
, 7, 102),
704 ICE_CTX_STORE(ice_rlan_ctx
, hbuf
, 5, 109),
705 ICE_CTX_STORE(ice_rlan_ctx
, dtype
, 2, 114),
706 ICE_CTX_STORE(ice_rlan_ctx
, dsize
, 1, 116),
707 ICE_CTX_STORE(ice_rlan_ctx
, crcstrip
, 1, 117),
708 ICE_CTX_STORE(ice_rlan_ctx
, l2tsel
, 1, 119),
709 ICE_CTX_STORE(ice_rlan_ctx
, hsplit_0
, 4, 120),
710 ICE_CTX_STORE(ice_rlan_ctx
, hsplit_1
, 2, 124),
711 ICE_CTX_STORE(ice_rlan_ctx
, showiv
, 1, 127),
712 ICE_CTX_STORE(ice_rlan_ctx
, rxmax
, 14, 174),
713 ICE_CTX_STORE(ice_rlan_ctx
, tphrdesc_ena
, 1, 193),
714 ICE_CTX_STORE(ice_rlan_ctx
, tphwdesc_ena
, 1, 194),
715 ICE_CTX_STORE(ice_rlan_ctx
, tphdata_ena
, 1, 195),
716 ICE_CTX_STORE(ice_rlan_ctx
, tphhead_ena
, 1, 196),
717 ICE_CTX_STORE(ice_rlan_ctx
, lrxqthresh
, 3, 198),
723 * @hw: pointer to the hardware structure
724 * @rlan_ctx: pointer to the rxq context
725 * @rxq_index: the index of the rx queue
727 * Converts rxq context from sparse to dense structure and then writes
728 * it to hw register space
731 ice_write_rxq_ctx(struct ice_hw
*hw
, struct ice_rlan_ctx
*rlan_ctx
,
734 u8 ctx_buf
[ICE_RXQ_CTX_SZ
] = { 0 };
736 ice_set_ctx((u8
*)rlan_ctx
, ctx_buf
, ice_rlan_ctx_info
);
737 return ice_copy_rxq_ctx_to_hw(hw
, ctx_buf
, rxq_index
);
740 /* LAN Tx Queue Context */
741 const struct ice_ctx_ele ice_tlan_ctx_info
[] = {
742 /* Field Width LSB */
743 ICE_CTX_STORE(ice_tlan_ctx
, base
, 57, 0),
744 ICE_CTX_STORE(ice_tlan_ctx
, port_num
, 3, 57),
745 ICE_CTX_STORE(ice_tlan_ctx
, cgd_num
, 5, 60),
746 ICE_CTX_STORE(ice_tlan_ctx
, pf_num
, 3, 65),
747 ICE_CTX_STORE(ice_tlan_ctx
, vmvf_num
, 10, 68),
748 ICE_CTX_STORE(ice_tlan_ctx
, vmvf_type
, 2, 78),
749 ICE_CTX_STORE(ice_tlan_ctx
, src_vsi
, 10, 80),
750 ICE_CTX_STORE(ice_tlan_ctx
, tsyn_ena
, 1, 90),
751 ICE_CTX_STORE(ice_tlan_ctx
, alt_vlan
, 1, 92),
752 ICE_CTX_STORE(ice_tlan_ctx
, cpuid
, 8, 93),
753 ICE_CTX_STORE(ice_tlan_ctx
, wb_mode
, 1, 101),
754 ICE_CTX_STORE(ice_tlan_ctx
, tphrd_desc
, 1, 102),
755 ICE_CTX_STORE(ice_tlan_ctx
, tphrd
, 1, 103),
756 ICE_CTX_STORE(ice_tlan_ctx
, tphwr_desc
, 1, 104),
757 ICE_CTX_STORE(ice_tlan_ctx
, cmpq_id
, 9, 105),
758 ICE_CTX_STORE(ice_tlan_ctx
, qnum_in_func
, 14, 114),
759 ICE_CTX_STORE(ice_tlan_ctx
, itr_notification_mode
, 1, 128),
760 ICE_CTX_STORE(ice_tlan_ctx
, adjust_prof_id
, 6, 129),
761 ICE_CTX_STORE(ice_tlan_ctx
, qlen
, 13, 135),
762 ICE_CTX_STORE(ice_tlan_ctx
, quanta_prof_idx
, 4, 148),
763 ICE_CTX_STORE(ice_tlan_ctx
, tso_ena
, 1, 152),
764 ICE_CTX_STORE(ice_tlan_ctx
, tso_qnum
, 11, 153),
765 ICE_CTX_STORE(ice_tlan_ctx
, legacy_int
, 1, 164),
766 ICE_CTX_STORE(ice_tlan_ctx
, drop_ena
, 1, 165),
767 ICE_CTX_STORE(ice_tlan_ctx
, cache_prof_idx
, 2, 166),
768 ICE_CTX_STORE(ice_tlan_ctx
, pkt_shaper_prof_idx
, 3, 168),
769 ICE_CTX_STORE(ice_tlan_ctx
, int_q_state
, 110, 171),
775 * @hw: pointer to the hardware structure
777 * @desc: pointer to control queue descriptor
778 * @buf: pointer to command buffer
779 * @buf_len: max length of buf
781 * Dumps debug log about control command with descriptor contents.
783 void ice_debug_cq(struct ice_hw
*hw
, u32 __maybe_unused mask
, void *desc
,
784 void *buf
, u16 buf_len
)
786 struct ice_aq_desc
*cq_desc
= (struct ice_aq_desc
*)desc
;
789 #ifndef CONFIG_DYNAMIC_DEBUG
790 if (!(mask
& hw
->debug_mask
))
797 len
= le16_to_cpu(cq_desc
->datalen
);
800 "CQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
801 le16_to_cpu(cq_desc
->opcode
),
802 le16_to_cpu(cq_desc
->flags
),
803 le16_to_cpu(cq_desc
->datalen
), le16_to_cpu(cq_desc
->retval
));
804 ice_debug(hw
, mask
, "\tcookie (h,l) 0x%08X 0x%08X\n",
805 le32_to_cpu(cq_desc
->cookie_high
),
806 le32_to_cpu(cq_desc
->cookie_low
));
807 ice_debug(hw
, mask
, "\tparam (0,1) 0x%08X 0x%08X\n",
808 le32_to_cpu(cq_desc
->params
.generic
.param0
),
809 le32_to_cpu(cq_desc
->params
.generic
.param1
));
810 ice_debug(hw
, mask
, "\taddr (h,l) 0x%08X 0x%08X\n",
811 le32_to_cpu(cq_desc
->params
.generic
.addr_high
),
812 le32_to_cpu(cq_desc
->params
.generic
.addr_low
));
813 if (buf
&& cq_desc
->datalen
!= 0) {
814 ice_debug(hw
, mask
, "Buffer:\n");
818 ice_debug_array(hw
, mask
, 16, 1, (u8
*)buf
, len
);
822 /* FW Admin Queue command wrappers */
825 * ice_aq_send_cmd - send FW Admin Queue command to FW Admin Queue
826 * @hw: pointer to the hw struct
827 * @desc: descriptor describing the command
828 * @buf: buffer to use for indirect commands (NULL for direct commands)
829 * @buf_size: size of buffer for indirect commands (0 for direct commands)
830 * @cd: pointer to command details structure
832 * Helper function to send FW Admin Queue commands to the FW Admin Queue.
835 ice_aq_send_cmd(struct ice_hw
*hw
, struct ice_aq_desc
*desc
, void *buf
,
836 u16 buf_size
, struct ice_sq_cd
*cd
)
838 return ice_sq_send_cmd(hw
, &hw
->adminq
, desc
, buf
, buf_size
, cd
);
843 * @hw: pointer to the hw struct
844 * @cd: pointer to command details structure or NULL
846 * Get the firmware version (0x0001) from the admin queue commands
848 enum ice_status
ice_aq_get_fw_ver(struct ice_hw
*hw
, struct ice_sq_cd
*cd
)
850 struct ice_aqc_get_ver
*resp
;
851 struct ice_aq_desc desc
;
852 enum ice_status status
;
854 resp
= &desc
.params
.get_ver
;
856 ice_fill_dflt_direct_cmd_desc(&desc
, ice_aqc_opc_get_ver
);
858 status
= ice_aq_send_cmd(hw
, &desc
, NULL
, 0, cd
);
861 hw
->fw_branch
= resp
->fw_branch
;
862 hw
->fw_maj_ver
= resp
->fw_major
;
863 hw
->fw_min_ver
= resp
->fw_minor
;
864 hw
->fw_patch
= resp
->fw_patch
;
865 hw
->fw_build
= le32_to_cpu(resp
->fw_build
);
866 hw
->api_branch
= resp
->api_branch
;
867 hw
->api_maj_ver
= resp
->api_major
;
868 hw
->api_min_ver
= resp
->api_minor
;
869 hw
->api_patch
= resp
->api_patch
;
877 * @hw: pointer to the hw struct
878 * @unloading: is the driver unloading itself
880 * Tell the Firmware that we're shutting down the AdminQ and whether
881 * or not the driver is unloading as well (0x0003).
883 enum ice_status
ice_aq_q_shutdown(struct ice_hw
*hw
, bool unloading
)
885 struct ice_aqc_q_shutdown
*cmd
;
886 struct ice_aq_desc desc
;
888 cmd
= &desc
.params
.q_shutdown
;
890 ice_fill_dflt_direct_cmd_desc(&desc
, ice_aqc_opc_q_shutdown
);
893 cmd
->driver_unloading
= cpu_to_le32(ICE_AQC_DRIVER_UNLOADING
);
895 return ice_aq_send_cmd(hw
, &desc
, NULL
, 0, NULL
);
900 * @hw: pointer to the hw struct
902 * @access: access type
903 * @sdp_number: resource number
904 * @timeout: the maximum time in ms that the driver may hold the resource
905 * @cd: pointer to command details structure or NULL
907 * requests common resource using the admin queue commands (0x0008)
909 static enum ice_status
910 ice_aq_req_res(struct ice_hw
*hw
, enum ice_aq_res_ids res
,
911 enum ice_aq_res_access_type access
, u8 sdp_number
, u32
*timeout
,
912 struct ice_sq_cd
*cd
)
914 struct ice_aqc_req_res
*cmd_resp
;
915 struct ice_aq_desc desc
;
916 enum ice_status status
;
918 cmd_resp
= &desc
.params
.res_owner
;
920 ice_fill_dflt_direct_cmd_desc(&desc
, ice_aqc_opc_req_res
);
922 cmd_resp
->res_id
= cpu_to_le16(res
);
923 cmd_resp
->access_type
= cpu_to_le16(access
);
924 cmd_resp
->res_number
= cpu_to_le32(sdp_number
);
926 status
= ice_aq_send_cmd(hw
, &desc
, NULL
, 0, cd
);
927 /* The completion specifies the maximum time in ms that the driver
928 * may hold the resource in the Timeout field.
929 * If the resource is held by someone else, the command completes with
930 * busy return value and the timeout field indicates the maximum time
931 * the current owner of the resource has to free it.
933 if (!status
|| hw
->adminq
.sq_last_status
== ICE_AQ_RC_EBUSY
)
934 *timeout
= le32_to_cpu(cmd_resp
->timeout
);
941 * @hw: pointer to the hw struct
943 * @sdp_number: resource number
944 * @cd: pointer to command details structure or NULL
946 * release common resource using the admin queue commands (0x0009)
948 static enum ice_status
949 ice_aq_release_res(struct ice_hw
*hw
, enum ice_aq_res_ids res
, u8 sdp_number
,
950 struct ice_sq_cd
*cd
)
952 struct ice_aqc_req_res
*cmd
;
953 struct ice_aq_desc desc
;
955 cmd
= &desc
.params
.res_owner
;
957 ice_fill_dflt_direct_cmd_desc(&desc
, ice_aqc_opc_release_res
);
959 cmd
->res_id
= cpu_to_le16(res
);
960 cmd
->res_number
= cpu_to_le32(sdp_number
);
962 return ice_aq_send_cmd(hw
, &desc
, NULL
, 0, cd
);
967 * @hw: pointer to the HW structure
969 * @access: access type (read or write)
971 * This function will attempt to acquire the ownership of a resource.
974 ice_acquire_res(struct ice_hw
*hw
, enum ice_aq_res_ids res
,
975 enum ice_aq_res_access_type access
)
977 #define ICE_RES_POLLING_DELAY_MS 10
978 u32 delay
= ICE_RES_POLLING_DELAY_MS
;
979 enum ice_status status
;
983 status
= ice_aq_req_res(hw
, res
, access
, 0, &time_left
, NULL
);
985 /* An admin queue return code of ICE_AQ_RC_EEXIST means that another
986 * driver has previously acquired the resource and performed any
987 * necessary updates; in this case the caller does not obtain the
988 * resource and has no further work to do.
990 if (hw
->adminq
.sq_last_status
== ICE_AQ_RC_EEXIST
) {
991 status
= ICE_ERR_AQ_NO_WORK
;
992 goto ice_acquire_res_exit
;
996 ice_debug(hw
, ICE_DBG_RES
,
997 "resource %d acquire type %d failed.\n", res
, access
);
999 /* If necessary, poll until the current lock owner timeouts */
1000 timeout
= time_left
;
1001 while (status
&& timeout
&& time_left
) {
1003 timeout
= (timeout
> delay
) ? timeout
- delay
: 0;
1004 status
= ice_aq_req_res(hw
, res
, access
, 0, &time_left
, NULL
);
1006 if (hw
->adminq
.sq_last_status
== ICE_AQ_RC_EEXIST
) {
1007 /* lock free, but no work to do */
1008 status
= ICE_ERR_AQ_NO_WORK
;
1016 if (status
&& status
!= ICE_ERR_AQ_NO_WORK
)
1017 ice_debug(hw
, ICE_DBG_RES
, "resource acquire timed out.\n");
1019 ice_acquire_res_exit
:
1020 if (status
== ICE_ERR_AQ_NO_WORK
) {
1021 if (access
== ICE_RES_WRITE
)
1022 ice_debug(hw
, ICE_DBG_RES
,
1023 "resource indicates no work to do.\n");
1025 ice_debug(hw
, ICE_DBG_RES
,
1026 "Warning: ICE_ERR_AQ_NO_WORK not expected\n");
1033 * @hw: pointer to the HW structure
1036 * This function will release a resource using the proper Admin Command.
1038 void ice_release_res(struct ice_hw
*hw
, enum ice_aq_res_ids res
)
1040 enum ice_status status
;
1041 u32 total_delay
= 0;
1043 status
= ice_aq_release_res(hw
, res
, 0, NULL
);
1045 /* there are some rare cases when trying to release the resource
1046 * results in an admin Q timeout, so handle them correctly
1048 while ((status
== ICE_ERR_AQ_TIMEOUT
) &&
1049 (total_delay
< hw
->adminq
.sq_cmd_timeout
)) {
1051 status
= ice_aq_release_res(hw
, res
, 0, NULL
);
1057 * ice_parse_caps - parse function/device capabilities
1058 * @hw: pointer to the hw struct
1059 * @buf: pointer to a buffer containing function/device capability records
1060 * @cap_count: number of capability records in the list
1061 * @opc: type of capabilities list to parse
1063 * Helper function to parse function(0x000a)/device(0x000b) capabilities list.
1066 ice_parse_caps(struct ice_hw
*hw
, void *buf
, u32 cap_count
,
1067 enum ice_adminq_opc opc
)
1069 struct ice_aqc_list_caps_elem
*cap_resp
;
1070 struct ice_hw_func_caps
*func_p
= NULL
;
1071 struct ice_hw_dev_caps
*dev_p
= NULL
;
1072 struct ice_hw_common_caps
*caps
;
1078 cap_resp
= (struct ice_aqc_list_caps_elem
*)buf
;
1080 if (opc
== ice_aqc_opc_list_dev_caps
) {
1081 dev_p
= &hw
->dev_caps
;
1082 caps
= &dev_p
->common_cap
;
1083 } else if (opc
== ice_aqc_opc_list_func_caps
) {
1084 func_p
= &hw
->func_caps
;
1085 caps
= &func_p
->common_cap
;
1087 ice_debug(hw
, ICE_DBG_INIT
, "wrong opcode\n");
1091 for (i
= 0; caps
&& i
< cap_count
; i
++, cap_resp
++) {
1092 u32 logical_id
= le32_to_cpu(cap_resp
->logical_id
);
1093 u32 phys_id
= le32_to_cpu(cap_resp
->phys_id
);
1094 u32 number
= le32_to_cpu(cap_resp
->number
);
1095 u16 cap
= le16_to_cpu(cap_resp
->cap
);
1098 case ICE_AQC_CAPS_VSI
:
1100 dev_p
->num_vsi_allocd_to_host
= number
;
1101 ice_debug(hw
, ICE_DBG_INIT
,
1102 "HW caps: Dev.VSI cnt = %d\n",
1103 dev_p
->num_vsi_allocd_to_host
);
1104 } else if (func_p
) {
1105 func_p
->guaranteed_num_vsi
= number
;
1106 ice_debug(hw
, ICE_DBG_INIT
,
1107 "HW caps: Func.VSI cnt = %d\n",
1108 func_p
->guaranteed_num_vsi
);
1111 case ICE_AQC_CAPS_RSS
:
1112 caps
->rss_table_size
= number
;
1113 caps
->rss_table_entry_width
= logical_id
;
1114 ice_debug(hw
, ICE_DBG_INIT
,
1115 "HW caps: RSS table size = %d\n",
1116 caps
->rss_table_size
);
1117 ice_debug(hw
, ICE_DBG_INIT
,
1118 "HW caps: RSS table width = %d\n",
1119 caps
->rss_table_entry_width
);
1121 case ICE_AQC_CAPS_RXQS
:
1122 caps
->num_rxq
= number
;
1123 caps
->rxq_first_id
= phys_id
;
1124 ice_debug(hw
, ICE_DBG_INIT
,
1125 "HW caps: Num Rx Qs = %d\n", caps
->num_rxq
);
1126 ice_debug(hw
, ICE_DBG_INIT
,
1127 "HW caps: Rx first queue ID = %d\n",
1128 caps
->rxq_first_id
);
1130 case ICE_AQC_CAPS_TXQS
:
1131 caps
->num_txq
= number
;
1132 caps
->txq_first_id
= phys_id
;
1133 ice_debug(hw
, ICE_DBG_INIT
,
1134 "HW caps: Num Tx Qs = %d\n", caps
->num_txq
);
1135 ice_debug(hw
, ICE_DBG_INIT
,
1136 "HW caps: Tx first queue ID = %d\n",
1137 caps
->txq_first_id
);
1139 case ICE_AQC_CAPS_MSIX
:
1140 caps
->num_msix_vectors
= number
;
1141 caps
->msix_vector_first_id
= phys_id
;
1142 ice_debug(hw
, ICE_DBG_INIT
,
1143 "HW caps: MSIX vector count = %d\n",
1144 caps
->num_msix_vectors
);
1145 ice_debug(hw
, ICE_DBG_INIT
,
1146 "HW caps: MSIX first vector index = %d\n",
1147 caps
->msix_vector_first_id
);
1149 case ICE_AQC_CAPS_MAX_MTU
:
1150 caps
->max_mtu
= number
;
1152 ice_debug(hw
, ICE_DBG_INIT
,
1153 "HW caps: Dev.MaxMTU = %d\n",
1156 ice_debug(hw
, ICE_DBG_INIT
,
1157 "HW caps: func.MaxMTU = %d\n",
1161 ice_debug(hw
, ICE_DBG_INIT
,
1162 "HW caps: Unknown capability[%d]: 0x%x\n", i
,
1170 * ice_aq_discover_caps - query function/device capabilities
1171 * @hw: pointer to the hw struct
1172 * @buf: a virtual buffer to hold the capabilities
1173 * @buf_size: Size of the virtual buffer
1174 * @data_size: Size of the returned data, or buf size needed if AQ err==ENOMEM
1175 * @opc: capabilities type to discover - pass in the command opcode
1176 * @cd: pointer to command details structure or NULL
1178 * Get the function(0x000a)/device(0x000b) capabilities description from
1181 static enum ice_status
1182 ice_aq_discover_caps(struct ice_hw
*hw
, void *buf
, u16 buf_size
, u16
*data_size
,
1183 enum ice_adminq_opc opc
, struct ice_sq_cd
*cd
)
1185 struct ice_aqc_list_caps
*cmd
;
1186 struct ice_aq_desc desc
;
1187 enum ice_status status
;
1189 cmd
= &desc
.params
.get_cap
;
1191 if (opc
!= ice_aqc_opc_list_func_caps
&&
1192 opc
!= ice_aqc_opc_list_dev_caps
)
1193 return ICE_ERR_PARAM
;
1195 ice_fill_dflt_direct_cmd_desc(&desc
, opc
);
1197 status
= ice_aq_send_cmd(hw
, &desc
, buf
, buf_size
, cd
);
1199 ice_parse_caps(hw
, buf
, le32_to_cpu(cmd
->count
), opc
);
1200 *data_size
= le16_to_cpu(desc
.datalen
);
1206 * ice_get_caps - get info about the HW
1207 * @hw: pointer to the hardware structure
1209 enum ice_status
ice_get_caps(struct ice_hw
*hw
)
1211 enum ice_status status
;
1216 /* The driver doesn't know how many capabilities the device will return
1217 * so the buffer size required isn't known ahead of time. The driver
1218 * starts with cbuf_len and if this turns out to be insufficient, the
1219 * device returns ICE_AQ_RC_ENOMEM and also the buffer size it needs.
1220 * The driver then allocates the buffer of this size and retries the
1221 * operation. So it follows that the retry count is 2.
1223 #define ICE_GET_CAP_BUF_COUNT 40
1224 #define ICE_GET_CAP_RETRY_COUNT 2
1226 cbuf_len
= ICE_GET_CAP_BUF_COUNT
*
1227 sizeof(struct ice_aqc_list_caps_elem
);
1229 retries
= ICE_GET_CAP_RETRY_COUNT
;
1234 cbuf
= devm_kzalloc(ice_hw_to_dev(hw
), cbuf_len
, GFP_KERNEL
);
1236 return ICE_ERR_NO_MEMORY
;
1238 status
= ice_aq_discover_caps(hw
, cbuf
, cbuf_len
, &data_size
,
1239 ice_aqc_opc_list_func_caps
, NULL
);
1240 devm_kfree(ice_hw_to_dev(hw
), cbuf
);
1242 if (!status
|| hw
->adminq
.sq_last_status
!= ICE_AQ_RC_ENOMEM
)
1245 /* If ENOMEM is returned, try again with bigger buffer */
1246 cbuf_len
= data_size
;
1247 } while (--retries
);
1253 * ice_aq_manage_mac_write - manage MAC address write command
1254 * @hw: pointer to the hw struct
1255 * @mac_addr: MAC address to be written as LAA/LAA+WoL/Port address
1256 * @flags: flags to control write behavior
1257 * @cd: pointer to command details structure or NULL
1259 * This function is used to write MAC address to the NVM (0x0108).
1262 ice_aq_manage_mac_write(struct ice_hw
*hw
, u8
*mac_addr
, u8 flags
,
1263 struct ice_sq_cd
*cd
)
1265 struct ice_aqc_manage_mac_write
*cmd
;
1266 struct ice_aq_desc desc
;
1268 cmd
= &desc
.params
.mac_write
;
1269 ice_fill_dflt_direct_cmd_desc(&desc
, ice_aqc_opc_manage_mac_write
);
1273 /* Prep values for flags, sah, sal */
1274 cmd
->sah
= htons(*((u16
*)mac_addr
));
1275 cmd
->sal
= htonl(*((u32
*)(mac_addr
+ 2)));
1277 return ice_aq_send_cmd(hw
, &desc
, NULL
, 0, cd
);
1281 * ice_aq_clear_pxe_mode
1282 * @hw: pointer to the hw struct
1284 * Tell the firmware that the driver is taking over from PXE (0x0110).
1286 static enum ice_status
ice_aq_clear_pxe_mode(struct ice_hw
*hw
)
1288 struct ice_aq_desc desc
;
1290 ice_fill_dflt_direct_cmd_desc(&desc
, ice_aqc_opc_clear_pxe_mode
);
1291 desc
.params
.clear_pxe
.rx_cnt
= ICE_AQC_CLEAR_PXE_RX_CNT
;
1293 return ice_aq_send_cmd(hw
, &desc
, NULL
, 0, NULL
);
1297 * ice_clear_pxe_mode - clear pxe operations mode
1298 * @hw: pointer to the hw struct
1300 * Make sure all PXE mode settings are cleared, including things
1301 * like descriptor fetch/write-back mode.
1303 void ice_clear_pxe_mode(struct ice_hw
*hw
)
1305 if (ice_check_sq_alive(hw
, &hw
->adminq
))
1306 ice_aq_clear_pxe_mode(hw
);
1310 * ice_aq_set_phy_cfg
1311 * @hw: pointer to the hw struct
1312 * @lport: logical port number
1313 * @cfg: structure with PHY configuration data to be set
1314 * @cd: pointer to command details structure or NULL
1316 * Set the various PHY configuration parameters supported on the Port.
1317 * One or more of the Set PHY config parameters may be ignored in an MFP
1318 * mode as the PF may not have the privilege to set some of the PHY Config
1319 * parameters. This status will be indicated by the command response (0x0601).
1321 static enum ice_status
1322 ice_aq_set_phy_cfg(struct ice_hw
*hw
, u8 lport
,
1323 struct ice_aqc_set_phy_cfg_data
*cfg
, struct ice_sq_cd
*cd
)
1325 struct ice_aqc_set_phy_cfg
*cmd
;
1326 struct ice_aq_desc desc
;
1329 return ICE_ERR_PARAM
;
1331 cmd
= &desc
.params
.set_phy
;
1332 ice_fill_dflt_direct_cmd_desc(&desc
, ice_aqc_opc_set_phy_cfg
);
1333 cmd
->lport_num
= lport
;
1335 return ice_aq_send_cmd(hw
, &desc
, cfg
, sizeof(*cfg
), cd
);
1339 * ice_update_link_info - update status of the HW network link
1340 * @pi: port info structure of the interested logical port
1342 static enum ice_status
1343 ice_update_link_info(struct ice_port_info
*pi
)
1345 struct ice_aqc_get_phy_caps_data
*pcaps
;
1346 struct ice_phy_info
*phy_info
;
1347 enum ice_status status
;
1351 return ICE_ERR_PARAM
;
1355 pcaps
= devm_kzalloc(ice_hw_to_dev(hw
), sizeof(*pcaps
), GFP_KERNEL
);
1357 return ICE_ERR_NO_MEMORY
;
1359 phy_info
= &pi
->phy
;
1360 status
= ice_aq_get_link_info(pi
, true, NULL
, NULL
);
1364 if (phy_info
->link_info
.link_info
& ICE_AQ_MEDIA_AVAILABLE
) {
1365 status
= ice_aq_get_phy_caps(pi
, false, ICE_AQC_REPORT_SW_CFG
,
1370 memcpy(phy_info
->link_info
.module_type
, &pcaps
->module_type
,
1371 sizeof(phy_info
->link_info
.module_type
));
1374 devm_kfree(ice_hw_to_dev(hw
), pcaps
);
1380 * @pi: port information structure
1381 * @aq_failures: pointer to status code, specific to ice_set_fc routine
1382 * @atomic_restart: enable automatic link update
1384 * Set the requested flow control mode.
1387 ice_set_fc(struct ice_port_info
*pi
, u8
*aq_failures
, bool atomic_restart
)
1389 struct ice_aqc_set_phy_cfg_data cfg
= { 0 };
1390 struct ice_aqc_get_phy_caps_data
*pcaps
;
1391 enum ice_status status
;
1392 u8 pause_mask
= 0x0;
1396 return ICE_ERR_PARAM
;
1398 *aq_failures
= ICE_SET_FC_AQ_FAIL_NONE
;
1400 switch (pi
->fc
.req_mode
) {
1402 pause_mask
|= ICE_AQC_PHY_EN_TX_LINK_PAUSE
;
1403 pause_mask
|= ICE_AQC_PHY_EN_RX_LINK_PAUSE
;
1405 case ICE_FC_RX_PAUSE
:
1406 pause_mask
|= ICE_AQC_PHY_EN_RX_LINK_PAUSE
;
1408 case ICE_FC_TX_PAUSE
:
1409 pause_mask
|= ICE_AQC_PHY_EN_TX_LINK_PAUSE
;
1415 pcaps
= devm_kzalloc(ice_hw_to_dev(hw
), sizeof(*pcaps
), GFP_KERNEL
);
1417 return ICE_ERR_NO_MEMORY
;
1419 /* Get the current phy config */
1420 status
= ice_aq_get_phy_caps(pi
, false, ICE_AQC_REPORT_SW_CFG
, pcaps
,
1423 *aq_failures
= ICE_SET_FC_AQ_FAIL_GET
;
1427 /* clear the old pause settings */
1428 cfg
.caps
= pcaps
->caps
& ~(ICE_AQC_PHY_EN_TX_LINK_PAUSE
|
1429 ICE_AQC_PHY_EN_RX_LINK_PAUSE
);
1430 /* set the new capabilities */
1431 cfg
.caps
|= pause_mask
;
1432 /* If the capabilities have changed, then set the new config */
1433 if (cfg
.caps
!= pcaps
->caps
) {
1434 int retry_count
, retry_max
= 10;
1436 /* Auto restart link so settings take effect */
1438 cfg
.caps
|= ICE_AQ_PHY_ENA_ATOMIC_LINK
;
1439 /* Copy over all the old settings */
1440 cfg
.phy_type_low
= pcaps
->phy_type_low
;
1441 cfg
.low_power_ctrl
= pcaps
->low_power_ctrl
;
1442 cfg
.eee_cap
= pcaps
->eee_cap
;
1443 cfg
.eeer_value
= pcaps
->eeer_value
;
1444 cfg
.link_fec_opt
= pcaps
->link_fec_options
;
1446 status
= ice_aq_set_phy_cfg(hw
, pi
->lport
, &cfg
, NULL
);
1448 *aq_failures
= ICE_SET_FC_AQ_FAIL_SET
;
1452 /* Update the link info
1453 * It sometimes takes a really long time for link to
1454 * come back from the atomic reset. Thus, we wait a
1457 for (retry_count
= 0; retry_count
< retry_max
; retry_count
++) {
1458 status
= ice_update_link_info(pi
);
1467 *aq_failures
= ICE_SET_FC_AQ_FAIL_UPDATE
;
1471 devm_kfree(ice_hw_to_dev(hw
), pcaps
);
1476 * ice_get_link_status - get status of the HW network link
1477 * @pi: port information structure
1478 * @link_up: pointer to bool (true/false = linkup/linkdown)
1480 * Variable link_up is true if link is up, false if link is down.
1481 * The variable link_up is invalid if status is non zero. As a
1482 * result of this call, link status reporting becomes enabled
1484 enum ice_status
ice_get_link_status(struct ice_port_info
*pi
, bool *link_up
)
1486 struct ice_phy_info
*phy_info
;
1487 enum ice_status status
= 0;
1489 if (!pi
|| !link_up
)
1490 return ICE_ERR_PARAM
;
1492 phy_info
= &pi
->phy
;
1494 if (phy_info
->get_link_info
) {
1495 status
= ice_update_link_info(pi
);
1498 ice_debug(pi
->hw
, ICE_DBG_LINK
,
1499 "get link status error, status = %d\n",
1503 *link_up
= phy_info
->link_info
.link_info
& ICE_AQ_LINK_UP
;
1509 * ice_aq_set_link_restart_an
1510 * @pi: pointer to the port information structure
1511 * @ena_link: if true: enable link, if false: disable link
1512 * @cd: pointer to command details structure or NULL
1514 * Sets up the link and restarts the Auto-Negotiation over the link.
1517 ice_aq_set_link_restart_an(struct ice_port_info
*pi
, bool ena_link
,
1518 struct ice_sq_cd
*cd
)
1520 struct ice_aqc_restart_an
*cmd
;
1521 struct ice_aq_desc desc
;
1523 cmd
= &desc
.params
.restart_an
;
1525 ice_fill_dflt_direct_cmd_desc(&desc
, ice_aqc_opc_restart_an
);
1527 cmd
->cmd_flags
= ICE_AQC_RESTART_AN_LINK_RESTART
;
1528 cmd
->lport_num
= pi
->lport
;
1530 cmd
->cmd_flags
|= ICE_AQC_RESTART_AN_LINK_ENABLE
;
1532 cmd
->cmd_flags
&= ~ICE_AQC_RESTART_AN_LINK_ENABLE
;
1534 return ice_aq_send_cmd(pi
->hw
, &desc
, NULL
, 0, cd
);
1538 * ice_aq_set_event_mask
1539 * @hw: pointer to the hw struct
1540 * @port_num: port number of the physical function
1541 * @mask: event mask to be set
1542 * @cd: pointer to command details structure or NULL
1544 * Set event mask (0x0613)
1547 ice_aq_set_event_mask(struct ice_hw
*hw
, u8 port_num
, u16 mask
,
1548 struct ice_sq_cd
*cd
)
1550 struct ice_aqc_set_event_mask
*cmd
;
1551 struct ice_aq_desc desc
;
1553 cmd
= &desc
.params
.set_event_mask
;
1555 ice_fill_dflt_direct_cmd_desc(&desc
, ice_aqc_opc_set_event_mask
);
1557 cmd
->lport_num
= port_num
;
1559 cmd
->event_mask
= cpu_to_le16(mask
);
1561 return ice_aq_send_cmd(hw
, &desc
, NULL
, 0, cd
);
1565 * __ice_aq_get_set_rss_lut
1566 * @hw: pointer to the hardware structure
1567 * @vsi_id: VSI FW index
1568 * @lut_type: LUT table type
1569 * @lut: pointer to the LUT buffer provided by the caller
1570 * @lut_size: size of the LUT buffer
1571 * @glob_lut_idx: global LUT index
1572 * @set: set true to set the table, false to get the table
1574 * Internal function to get (0x0B05) or set (0x0B03) RSS look up table
1576 static enum ice_status
1577 __ice_aq_get_set_rss_lut(struct ice_hw
*hw
, u16 vsi_id
, u8 lut_type
, u8
*lut
,
1578 u16 lut_size
, u8 glob_lut_idx
, bool set
)
1580 struct ice_aqc_get_set_rss_lut
*cmd_resp
;
1581 struct ice_aq_desc desc
;
1582 enum ice_status status
;
1585 cmd_resp
= &desc
.params
.get_set_rss_lut
;
1588 ice_fill_dflt_direct_cmd_desc(&desc
, ice_aqc_opc_set_rss_lut
);
1589 desc
.flags
|= cpu_to_le16(ICE_AQ_FLAG_RD
);
1591 ice_fill_dflt_direct_cmd_desc(&desc
, ice_aqc_opc_get_rss_lut
);
1594 cmd_resp
->vsi_id
= cpu_to_le16(((vsi_id
<<
1595 ICE_AQC_GSET_RSS_LUT_VSI_ID_S
) &
1596 ICE_AQC_GSET_RSS_LUT_VSI_ID_M
) |
1597 ICE_AQC_GSET_RSS_LUT_VSI_VALID
);
1600 case ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_VSI
:
1601 case ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF
:
1602 case ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_GLOBAL
:
1603 flags
|= ((lut_type
<< ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_S
) &
1604 ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_M
);
1607 status
= ICE_ERR_PARAM
;
1608 goto ice_aq_get_set_rss_lut_exit
;
1611 if (lut_type
== ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_GLOBAL
) {
1612 flags
|= ((glob_lut_idx
<< ICE_AQC_GSET_RSS_LUT_GLOBAL_IDX_S
) &
1613 ICE_AQC_GSET_RSS_LUT_GLOBAL_IDX_M
);
1616 goto ice_aq_get_set_rss_lut_send
;
1617 } else if (lut_type
== ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF
) {
1619 goto ice_aq_get_set_rss_lut_send
;
1621 goto ice_aq_get_set_rss_lut_send
;
1624 /* LUT size is only valid for Global and PF table types */
1626 case ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_128
:
1628 case ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_512
:
1629 flags
|= (ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_512_FLAG
<<
1630 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_S
) &
1631 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_M
;
1633 case ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K
:
1634 if (lut_type
== ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF
) {
1635 flags
|= (ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K_FLAG
<<
1636 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_S
) &
1637 ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_M
;
1642 status
= ICE_ERR_PARAM
;
1643 goto ice_aq_get_set_rss_lut_exit
;
1646 ice_aq_get_set_rss_lut_send
:
1647 cmd_resp
->flags
= cpu_to_le16(flags
);
1648 status
= ice_aq_send_cmd(hw
, &desc
, lut
, lut_size
, NULL
);
1650 ice_aq_get_set_rss_lut_exit
:
1655 * ice_aq_get_rss_lut
1656 * @hw: pointer to the hardware structure
1657 * @vsi_id: VSI FW index
1658 * @lut_type: LUT table type
1659 * @lut: pointer to the LUT buffer provided by the caller
1660 * @lut_size: size of the LUT buffer
1662 * get the RSS lookup table, PF or VSI type
1665 ice_aq_get_rss_lut(struct ice_hw
*hw
, u16 vsi_id
, u8 lut_type
, u8
*lut
,
1668 return __ice_aq_get_set_rss_lut(hw
, vsi_id
, lut_type
, lut
, lut_size
, 0,
1673 * ice_aq_set_rss_lut
1674 * @hw: pointer to the hardware structure
1675 * @vsi_id: VSI FW index
1676 * @lut_type: LUT table type
1677 * @lut: pointer to the LUT buffer provided by the caller
1678 * @lut_size: size of the LUT buffer
1680 * set the RSS lookup table, PF or VSI type
1683 ice_aq_set_rss_lut(struct ice_hw
*hw
, u16 vsi_id
, u8 lut_type
, u8
*lut
,
1686 return __ice_aq_get_set_rss_lut(hw
, vsi_id
, lut_type
, lut
, lut_size
, 0,
1691 * __ice_aq_get_set_rss_key
1692 * @hw: pointer to the hw struct
1693 * @vsi_id: VSI FW index
1694 * @key: pointer to key info struct
1695 * @set: set true to set the key, false to get the key
1697 * get (0x0B04) or set (0x0B02) the RSS key per VSI
1700 ice_status
__ice_aq_get_set_rss_key(struct ice_hw
*hw
, u16 vsi_id
,
1701 struct ice_aqc_get_set_rss_keys
*key
,
1704 struct ice_aqc_get_set_rss_key
*cmd_resp
;
1705 u16 key_size
= sizeof(*key
);
1706 struct ice_aq_desc desc
;
1708 cmd_resp
= &desc
.params
.get_set_rss_key
;
1711 ice_fill_dflt_direct_cmd_desc(&desc
, ice_aqc_opc_set_rss_key
);
1712 desc
.flags
|= cpu_to_le16(ICE_AQ_FLAG_RD
);
1714 ice_fill_dflt_direct_cmd_desc(&desc
, ice_aqc_opc_get_rss_key
);
1717 cmd_resp
->vsi_id
= cpu_to_le16(((vsi_id
<<
1718 ICE_AQC_GSET_RSS_KEY_VSI_ID_S
) &
1719 ICE_AQC_GSET_RSS_KEY_VSI_ID_M
) |
1720 ICE_AQC_GSET_RSS_KEY_VSI_VALID
);
1722 return ice_aq_send_cmd(hw
, &desc
, key
, key_size
, NULL
);
1726 * ice_aq_get_rss_key
1727 * @hw: pointer to the hw struct
1728 * @vsi_id: VSI FW index
1729 * @key: pointer to key info struct
1731 * get the RSS key per VSI
1734 ice_aq_get_rss_key(struct ice_hw
*hw
, u16 vsi_id
,
1735 struct ice_aqc_get_set_rss_keys
*key
)
1737 return __ice_aq_get_set_rss_key(hw
, vsi_id
, key
, false);
1741 * ice_aq_set_rss_key
1742 * @hw: pointer to the hw struct
1743 * @vsi_id: VSI FW index
1744 * @keys: pointer to key info struct
1746 * set the RSS key per VSI
1749 ice_aq_set_rss_key(struct ice_hw
*hw
, u16 vsi_id
,
1750 struct ice_aqc_get_set_rss_keys
*keys
)
1752 return __ice_aq_get_set_rss_key(hw
, vsi_id
, keys
, true);
1756 * ice_aq_add_lan_txq
1757 * @hw: pointer to the hardware structure
1758 * @num_qgrps: Number of added queue groups
1759 * @qg_list: list of queue groups to be added
1760 * @buf_size: size of buffer for indirect command
1761 * @cd: pointer to command details structure or NULL
1763 * Add Tx LAN queue (0x0C30)
1766 * Prior to calling add Tx LAN queue:
1767 * Initialize the following as part of the Tx queue context:
1768 * Completion queue ID if the queue uses Completion queue, Quanta profile,
1769 * Cache profile and Packet shaper profile.
1771 * After add Tx LAN queue AQ command is completed:
1772 * Interrupts should be associated with specific queues,
1773 * Association of Tx queue to Doorbell queue is not part of Add LAN Tx queue
1776 static enum ice_status
1777 ice_aq_add_lan_txq(struct ice_hw
*hw
, u8 num_qgrps
,
1778 struct ice_aqc_add_tx_qgrp
*qg_list
, u16 buf_size
,
1779 struct ice_sq_cd
*cd
)
1781 u16 i
, sum_header_size
, sum_q_size
= 0;
1782 struct ice_aqc_add_tx_qgrp
*list
;
1783 struct ice_aqc_add_txqs
*cmd
;
1784 struct ice_aq_desc desc
;
1786 cmd
= &desc
.params
.add_txqs
;
1788 ice_fill_dflt_direct_cmd_desc(&desc
, ice_aqc_opc_add_txqs
);
1791 return ICE_ERR_PARAM
;
1793 if (num_qgrps
> ICE_LAN_TXQ_MAX_QGRPS
)
1794 return ICE_ERR_PARAM
;
1796 sum_header_size
= num_qgrps
*
1797 (sizeof(*qg_list
) - sizeof(*qg_list
->txqs
));
1800 for (i
= 0; i
< num_qgrps
; i
++) {
1801 struct ice_aqc_add_txqs_perq
*q
= list
->txqs
;
1803 sum_q_size
+= list
->num_txqs
* sizeof(*q
);
1804 list
= (struct ice_aqc_add_tx_qgrp
*)(q
+ list
->num_txqs
);
1807 if (buf_size
!= (sum_header_size
+ sum_q_size
))
1808 return ICE_ERR_PARAM
;
1810 desc
.flags
|= cpu_to_le16(ICE_AQ_FLAG_RD
);
1812 cmd
->num_qgrps
= num_qgrps
;
1814 return ice_aq_send_cmd(hw
, &desc
, qg_list
, buf_size
, cd
);
1818 * ice_aq_dis_lan_txq
1819 * @hw: pointer to the hardware structure
1820 * @num_qgrps: number of groups in the list
1821 * @qg_list: the list of groups to disable
1822 * @buf_size: the total size of the qg_list buffer in bytes
1823 * @cd: pointer to command details structure or NULL
1825 * Disable LAN Tx queue (0x0C31)
1827 static enum ice_status
1828 ice_aq_dis_lan_txq(struct ice_hw
*hw
, u8 num_qgrps
,
1829 struct ice_aqc_dis_txq_item
*qg_list
, u16 buf_size
,
1830 struct ice_sq_cd
*cd
)
1832 struct ice_aqc_dis_txqs
*cmd
;
1833 struct ice_aq_desc desc
;
1836 cmd
= &desc
.params
.dis_txqs
;
1837 ice_fill_dflt_direct_cmd_desc(&desc
, ice_aqc_opc_dis_txqs
);
1840 return ICE_ERR_PARAM
;
1842 if (num_qgrps
> ICE_LAN_TXQ_MAX_QGRPS
)
1843 return ICE_ERR_PARAM
;
1844 desc
.flags
|= cpu_to_le16(ICE_AQ_FLAG_RD
);
1845 cmd
->num_entries
= num_qgrps
;
1847 for (i
= 0; i
< num_qgrps
; ++i
) {
1848 /* Calculate the size taken up by the queue IDs in this group */
1849 sz
+= qg_list
[i
].num_qs
* sizeof(qg_list
[i
].q_id
);
1851 /* Add the size of the group header */
1852 sz
+= sizeof(qg_list
[i
]) - sizeof(qg_list
[i
].q_id
);
1854 /* If the num of queues is even, add 2 bytes of padding */
1855 if ((qg_list
[i
].num_qs
% 2) == 0)
1860 return ICE_ERR_PARAM
;
1862 return ice_aq_send_cmd(hw
, &desc
, qg_list
, buf_size
, cd
);
1865 /* End of FW Admin Queue command wrappers */
1868 * ice_write_byte - write a byte to a packed context structure
1869 * @src_ctx: the context structure to read from
1870 * @dest_ctx: the context to be written to
1871 * @ce_info: a description of the struct to be filled
1873 static void ice_write_byte(u8
*src_ctx
, u8
*dest_ctx
,
1874 const struct ice_ctx_ele
*ce_info
)
1876 u8 src_byte
, dest_byte
, mask
;
1880 /* copy from the next struct field */
1881 from
= src_ctx
+ ce_info
->offset
;
1883 /* prepare the bits and mask */
1884 shift_width
= ce_info
->lsb
% 8;
1885 mask
= (u8
)(BIT(ce_info
->width
) - 1);
1890 /* shift to correct alignment */
1891 mask
<<= shift_width
;
1892 src_byte
<<= shift_width
;
1894 /* get the current bits from the target bit string */
1895 dest
= dest_ctx
+ (ce_info
->lsb
/ 8);
1897 memcpy(&dest_byte
, dest
, sizeof(dest_byte
));
1899 dest_byte
&= ~mask
; /* get the bits not changing */
1900 dest_byte
|= src_byte
; /* add in the new bits */
1902 /* put it all back */
1903 memcpy(dest
, &dest_byte
, sizeof(dest_byte
));
1907 * ice_write_word - write a word to a packed context structure
1908 * @src_ctx: the context structure to read from
1909 * @dest_ctx: the context to be written to
1910 * @ce_info: a description of the struct to be filled
1912 static void ice_write_word(u8
*src_ctx
, u8
*dest_ctx
,
1913 const struct ice_ctx_ele
*ce_info
)
1920 /* copy from the next struct field */
1921 from
= src_ctx
+ ce_info
->offset
;
1923 /* prepare the bits and mask */
1924 shift_width
= ce_info
->lsb
% 8;
1925 mask
= BIT(ce_info
->width
) - 1;
1927 /* don't swizzle the bits until after the mask because the mask bits
1928 * will be in a different bit position on big endian machines
1930 src_word
= *(u16
*)from
;
1933 /* shift to correct alignment */
1934 mask
<<= shift_width
;
1935 src_word
<<= shift_width
;
1937 /* get the current bits from the target bit string */
1938 dest
= dest_ctx
+ (ce_info
->lsb
/ 8);
1940 memcpy(&dest_word
, dest
, sizeof(dest_word
));
1942 dest_word
&= ~(cpu_to_le16(mask
)); /* get the bits not changing */
1943 dest_word
|= cpu_to_le16(src_word
); /* add in the new bits */
1945 /* put it all back */
1946 memcpy(dest
, &dest_word
, sizeof(dest_word
));
1950 * ice_write_dword - write a dword to a packed context structure
1951 * @src_ctx: the context structure to read from
1952 * @dest_ctx: the context to be written to
1953 * @ce_info: a description of the struct to be filled
1955 static void ice_write_dword(u8
*src_ctx
, u8
*dest_ctx
,
1956 const struct ice_ctx_ele
*ce_info
)
1958 u32 src_dword
, mask
;
1963 /* copy from the next struct field */
1964 from
= src_ctx
+ ce_info
->offset
;
1966 /* prepare the bits and mask */
1967 shift_width
= ce_info
->lsb
% 8;
1969 /* if the field width is exactly 32 on an x86 machine, then the shift
1970 * operation will not work because the SHL instructions count is masked
1971 * to 5 bits so the shift will do nothing
1973 if (ce_info
->width
< 32)
1974 mask
= BIT(ce_info
->width
) - 1;
1978 /* don't swizzle the bits until after the mask because the mask bits
1979 * will be in a different bit position on big endian machines
1981 src_dword
= *(u32
*)from
;
1984 /* shift to correct alignment */
1985 mask
<<= shift_width
;
1986 src_dword
<<= shift_width
;
1988 /* get the current bits from the target bit string */
1989 dest
= dest_ctx
+ (ce_info
->lsb
/ 8);
1991 memcpy(&dest_dword
, dest
, sizeof(dest_dword
));
1993 dest_dword
&= ~(cpu_to_le32(mask
)); /* get the bits not changing */
1994 dest_dword
|= cpu_to_le32(src_dword
); /* add in the new bits */
1996 /* put it all back */
1997 memcpy(dest
, &dest_dword
, sizeof(dest_dword
));
2001 * ice_write_qword - write a qword to a packed context structure
2002 * @src_ctx: the context structure to read from
2003 * @dest_ctx: the context to be written to
2004 * @ce_info: a description of the struct to be filled
2006 static void ice_write_qword(u8
*src_ctx
, u8
*dest_ctx
,
2007 const struct ice_ctx_ele
*ce_info
)
2009 u64 src_qword
, mask
;
2014 /* copy from the next struct field */
2015 from
= src_ctx
+ ce_info
->offset
;
2017 /* prepare the bits and mask */
2018 shift_width
= ce_info
->lsb
% 8;
2020 /* if the field width is exactly 64 on an x86 machine, then the shift
2021 * operation will not work because the SHL instructions count is masked
2022 * to 6 bits so the shift will do nothing
2024 if (ce_info
->width
< 64)
2025 mask
= BIT_ULL(ce_info
->width
) - 1;
2029 /* don't swizzle the bits until after the mask because the mask bits
2030 * will be in a different bit position on big endian machines
2032 src_qword
= *(u64
*)from
;
2035 /* shift to correct alignment */
2036 mask
<<= shift_width
;
2037 src_qword
<<= shift_width
;
2039 /* get the current bits from the target bit string */
2040 dest
= dest_ctx
+ (ce_info
->lsb
/ 8);
2042 memcpy(&dest_qword
, dest
, sizeof(dest_qword
));
2044 dest_qword
&= ~(cpu_to_le64(mask
)); /* get the bits not changing */
2045 dest_qword
|= cpu_to_le64(src_qword
); /* add in the new bits */
2047 /* put it all back */
2048 memcpy(dest
, &dest_qword
, sizeof(dest_qword
));
2052 * ice_set_ctx - set context bits in packed structure
2053 * @src_ctx: pointer to a generic non-packed context structure
2054 * @dest_ctx: pointer to memory for the packed structure
2055 * @ce_info: a description of the structure to be transformed
2058 ice_set_ctx(u8
*src_ctx
, u8
*dest_ctx
, const struct ice_ctx_ele
*ce_info
)
2062 for (f
= 0; ce_info
[f
].width
; f
++) {
2063 /* We have to deal with each element of the FW response
2064 * using the correct size so that we are correct regardless
2065 * of the endianness of the machine.
2067 switch (ce_info
[f
].size_of
) {
2069 ice_write_byte(src_ctx
, dest_ctx
, &ce_info
[f
]);
2072 ice_write_word(src_ctx
, dest_ctx
, &ce_info
[f
]);
2075 ice_write_dword(src_ctx
, dest_ctx
, &ce_info
[f
]);
2078 ice_write_qword(src_ctx
, dest_ctx
, &ce_info
[f
]);
2081 return ICE_ERR_INVAL_SIZE
;
2090 * @pi: port information structure
2093 * @num_qgrps: Number of added queue groups
2094 * @buf: list of queue groups to be added
2095 * @buf_size: size of buffer for indirect command
2096 * @cd: pointer to command details structure or NULL
2098 * This function adds one lan q
2101 ice_ena_vsi_txq(struct ice_port_info
*pi
, u16 vsi_id
, u8 tc
, u8 num_qgrps
,
2102 struct ice_aqc_add_tx_qgrp
*buf
, u16 buf_size
,
2103 struct ice_sq_cd
*cd
)
2105 struct ice_aqc_txsched_elem_data node
= { 0 };
2106 struct ice_sched_node
*parent
;
2107 enum ice_status status
;
2110 if (!pi
|| pi
->port_state
!= ICE_SCHED_PORT_STATE_READY
)
2113 if (num_qgrps
> 1 || buf
->num_txqs
> 1)
2114 return ICE_ERR_MAX_LIMIT
;
2118 mutex_lock(&pi
->sched_lock
);
2120 /* find a parent node */
2121 parent
= ice_sched_get_free_qparent(pi
, vsi_id
, tc
,
2122 ICE_SCHED_NODE_OWNER_LAN
);
2124 status
= ICE_ERR_PARAM
;
2127 buf
->parent_teid
= parent
->info
.node_teid
;
2128 node
.parent_teid
= parent
->info
.node_teid
;
2129 /* Mark that the values in the "generic" section as valid. The default
2130 * value in the "generic" section is zero. This means that :
2131 * - Scheduling mode is Bytes Per Second (BPS), indicated by Bit 0.
2132 * - 0 priority among siblings, indicated by Bit 1-3.
2133 * - WFQ, indicated by Bit 4.
2134 * - 0 Adjustment value is used in PSM credit update flow, indicated by
2136 * - Bit 7 is reserved.
2137 * Without setting the generic section as valid in valid_sections, the
2138 * Admin Q command will fail with error code ICE_AQ_RC_EINVAL.
2140 buf
->txqs
[0].info
.valid_sections
= ICE_AQC_ELEM_VALID_GENERIC
;
2143 status
= ice_aq_add_lan_txq(hw
, num_qgrps
, buf
, buf_size
, cd
);
2147 node
.node_teid
= buf
->txqs
[0].q_teid
;
2148 node
.data
.elem_type
= ICE_AQC_ELEM_TYPE_LEAF
;
2150 /* add a leaf node into schduler tree q layer */
2151 status
= ice_sched_add_node(pi
, hw
->num_tx_sched_layers
- 1, &node
);
2154 mutex_unlock(&pi
->sched_lock
);
2160 * @pi: port information structure
2161 * @num_queues: number of queues
2162 * @q_ids: pointer to the q_id array
2163 * @q_teids: pointer to queue node teids
2164 * @cd: pointer to command details structure or NULL
2166 * This function removes queues and their corresponding nodes in SW DB
2169 ice_dis_vsi_txq(struct ice_port_info
*pi
, u8 num_queues
, u16
*q_ids
,
2170 u32
*q_teids
, struct ice_sq_cd
*cd
)
2172 enum ice_status status
= ICE_ERR_DOES_NOT_EXIST
;
2173 struct ice_aqc_dis_txq_item qg_list
;
2176 if (!pi
|| pi
->port_state
!= ICE_SCHED_PORT_STATE_READY
)
2179 mutex_lock(&pi
->sched_lock
);
2181 for (i
= 0; i
< num_queues
; i
++) {
2182 struct ice_sched_node
*node
;
2184 node
= ice_sched_find_node_by_teid(pi
->root
, q_teids
[i
]);
2187 qg_list
.parent_teid
= node
->info
.parent_teid
;
2189 qg_list
.q_id
[0] = cpu_to_le16(q_ids
[i
]);
2190 status
= ice_aq_dis_lan_txq(pi
->hw
, 1, &qg_list
,
2191 sizeof(qg_list
), cd
);
2195 ice_free_sched_node(pi
, node
);
2197 mutex_unlock(&pi
->sched_lock
);
2202 * ice_cfg_vsi_qs - configure the new/exisiting VSI queues
2203 * @pi: port information structure
2205 * @tc_bitmap: TC bitmap
2206 * @maxqs: max queues array per TC
2207 * @owner: lan or rdma
2209 * This function adds/updates the VSI queues per TC.
2211 static enum ice_status
2212 ice_cfg_vsi_qs(struct ice_port_info
*pi
, u16 vsi_id
, u8 tc_bitmap
,
2213 u16
*maxqs
, u8 owner
)
2215 enum ice_status status
= 0;
2218 if (!pi
|| pi
->port_state
!= ICE_SCHED_PORT_STATE_READY
)
2221 mutex_lock(&pi
->sched_lock
);
2223 for (i
= 0; i
< ICE_MAX_TRAFFIC_CLASS
; i
++) {
2224 /* configuration is possible only if TC node is present */
2225 if (!ice_sched_get_tc_node(pi
, i
))
2228 status
= ice_sched_cfg_vsi(pi
, vsi_id
, i
, maxqs
[i
], owner
,
2229 ice_is_tc_ena(tc_bitmap
, i
));
2234 mutex_unlock(&pi
->sched_lock
);
2239 * ice_cfg_vsi_lan - configure VSI lan queues
2240 * @pi: port information structure
2242 * @tc_bitmap: TC bitmap
2243 * @max_lanqs: max lan queues array per TC
2245 * This function adds/updates the VSI lan queues per TC.
2248 ice_cfg_vsi_lan(struct ice_port_info
*pi
, u16 vsi_id
, u8 tc_bitmap
,
2251 return ice_cfg_vsi_qs(pi
, vsi_id
, tc_bitmap
, max_lanqs
,
2252 ICE_SCHED_NODE_OWNER_LAN
);