]>
Commit | Line | Data |
---|---|---|
7ec59eea AV |
1 | // SPDX-License-Identifier: GPL-2.0 |
2 | /* Copyright (c) 2018, Intel Corporation. */ | |
3 | ||
4 | #include "ice_common.h" | |
9c20346b | 5 | #include "ice_sched.h" |
7ec59eea AV |
6 | #include "ice_adminq_cmd.h" |
7 | ||
f31e4b6f AV |
8 | #define ICE_PF_RESET_WAIT_COUNT 200 |
9 | ||
22ef683b AV |
10 | #define ICE_PROG_FLEX_ENTRY(hw, rxdid, mdid, idx) \ |
11 | wr32((hw), GLFLXP_RXDID_FLX_WRD_##idx(rxdid), \ | |
cdedef59 AV |
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)) | |
17 | ||
22ef683b AV |
18 | #define ICE_PROG_FLG_ENTRY(hw, rxdid, flg_0, flg_1, flg_2, flg_3, idx) \ |
19 | wr32((hw), GLFLXP_RXDID_FLAGS(rxdid, idx), \ | |
cdedef59 AV |
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)) | |
28 | ||
f31e4b6f AV |
29 | /** |
30 | * ice_set_mac_type - Sets MAC type | |
31 | * @hw: pointer to the HW structure | |
32 | * | |
33 | * This function sets the MAC type of the adapter based on the | |
34 | * vendor ID and device ID stored in the hw structure. | |
35 | */ | |
36 | static enum ice_status ice_set_mac_type(struct ice_hw *hw) | |
37 | { | |
38 | if (hw->vendor_id != PCI_VENDOR_ID_INTEL) | |
39 | return ICE_ERR_DEVICE_NOT_SUPPORTED; | |
40 | ||
41 | hw->mac_type = ICE_MAC_GENERIC; | |
42 | return 0; | |
43 | } | |
44 | ||
45 | /** | |
46 | * ice_clear_pf_cfg - Clear PF configuration | |
47 | * @hw: pointer to the hardware structure | |
3968540b AV |
48 | * |
49 | * Clears any existing PF configuration (VSIs, VSI lists, switch rules, port | |
50 | * configuration, flow director filters, etc.). | |
f31e4b6f AV |
51 | */ |
52 | enum ice_status ice_clear_pf_cfg(struct ice_hw *hw) | |
53 | { | |
54 | struct ice_aq_desc desc; | |
55 | ||
56 | ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_clear_pf_cfg); | |
57 | ||
58 | return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL); | |
59 | } | |
60 | ||
dc49c772 AV |
61 | /** |
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 | |
67 | * | |
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. | |
74 | */ | |
75 | static enum ice_status | |
76 | ice_aq_manage_mac_read(struct ice_hw *hw, void *buf, u16 buf_size, | |
77 | struct ice_sq_cd *cd) | |
78 | { | |
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; | |
83 | u16 flags; | |
d6fef10c | 84 | u8 i; |
dc49c772 AV |
85 | |
86 | cmd = &desc.params.mac_read; | |
87 | ||
88 | if (buf_size < sizeof(*resp)) | |
89 | return ICE_ERR_BUF_TOO_SHORT; | |
90 | ||
91 | ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_manage_mac_read); | |
92 | ||
93 | status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd); | |
94 | if (status) | |
95 | return status; | |
96 | ||
97 | resp = (struct ice_aqc_manage_mac_read_resp *)buf; | |
98 | flags = le16_to_cpu(cmd->flags) & ICE_AQC_MAN_MAC_READ_M; | |
99 | ||
100 | if (!(flags & ICE_AQC_MAN_MAC_LAN_ADDR_VALID)) { | |
101 | ice_debug(hw, ICE_DBG_LAN, "got invalid MAC address\n"); | |
102 | return ICE_ERR_CFG; | |
103 | } | |
104 | ||
d6fef10c MFIP |
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, | |
109 | resp[i].mac_addr); | |
110 | ether_addr_copy(hw->port_info->mac.perm_addr, | |
111 | resp[i].mac_addr); | |
112 | break; | |
113 | } | |
114 | ||
dc49c772 AV |
115 | return 0; |
116 | } | |
117 | ||
118 | /** | |
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 | |
125 | * | |
126 | * Returns the various PHY capabilities supported on the Port (0x0600) | |
127 | */ | |
48cb27f2 | 128 | enum ice_status |
dc49c772 AV |
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) | |
132 | { | |
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; | |
137 | ||
138 | cmd = &desc.params.get_phy; | |
139 | ||
140 | if (!pcaps || (report_mode & ~ICE_AQC_REPORT_MODE_M) || !pi) | |
141 | return ICE_ERR_PARAM; | |
142 | ||
143 | ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_phy_caps); | |
144 | ||
145 | if (qual_mods) | |
146 | cmd->param0 |= cpu_to_le16(ICE_AQC_GET_PHY_RQM); | |
147 | ||
148 | cmd->param0 |= cpu_to_le16(report_mode); | |
149 | status = ice_aq_send_cmd(pi->hw, &desc, pcaps, pcaps_size, cd); | |
150 | ||
151 | if (!status && report_mode == ICE_AQC_REPORT_TOPO_CAP) | |
152 | pi->phy.phy_type_low = le64_to_cpu(pcaps->phy_type_low); | |
153 | ||
154 | return status; | |
155 | } | |
156 | ||
157 | /** | |
158 | * ice_get_media_type - Gets media type | |
159 | * @pi: port information structure | |
160 | */ | |
161 | static enum ice_media_type ice_get_media_type(struct ice_port_info *pi) | |
162 | { | |
163 | struct ice_link_status *hw_link_info; | |
164 | ||
165 | if (!pi) | |
166 | return ICE_MEDIA_UNKNOWN; | |
167 | ||
168 | hw_link_info = &pi->phy.link_info; | |
169 | ||
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: | |
195 | return ICE_MEDIA_DA; | |
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; | |
206 | } | |
207 | } | |
208 | ||
209 | return ICE_MEDIA_UNKNOWN; | |
210 | } | |
211 | ||
212 | /** | |
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 | |
218 | * | |
219 | * Get Link Status (0x607). Returns the link status of the adapter. | |
220 | */ | |
221 | enum ice_status | |
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) | |
224 | { | |
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; | |
233 | u16 cmd_flags; | |
234 | ||
235 | if (!pi) | |
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; | |
241 | ||
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; | |
247 | ||
248 | status = ice_aq_send_cmd(pi->hw, &desc, &link_data, sizeof(link_data), | |
249 | cd); | |
250 | ||
251 | if (status) | |
252 | return status; | |
253 | ||
254 | /* save off old link status information */ | |
255 | *hw_link_info_old = *hw_link_info; | |
256 | ||
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; | |
266 | ||
267 | /* update fc info */ | |
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; | |
272 | else if (tx_pause) | |
273 | hw_fc_info->current_mode = ICE_FC_TX_PAUSE; | |
274 | else if (rx_pause) | |
275 | hw_fc_info->current_mode = ICE_FC_RX_PAUSE; | |
276 | else | |
277 | hw_fc_info->current_mode = ICE_FC_NONE; | |
278 | ||
279 | hw_link_info->lse_ena = | |
280 | !!(resp->cmd_flags & cpu_to_le16(ICE_AQ_LSE_IS_ENABLED)); | |
281 | ||
282 | /* save link status information */ | |
283 | if (link) | |
284 | *link = *hw_link_info; | |
285 | ||
286 | /* flag cleared so calling functions don't call AQ again */ | |
287 | pi->phy.get_link_info = false; | |
288 | ||
289 | return status; | |
290 | } | |
291 | ||
cdedef59 | 292 | /** |
22ef683b | 293 | * ice_init_flex_flags |
cdedef59 | 294 | * @hw: pointer to the hardware structure |
22ef683b | 295 | * @prof_id: Rx Descriptor Builder profile ID |
cdedef59 | 296 | * |
22ef683b | 297 | * Function to initialize Rx flex flags |
cdedef59 | 298 | */ |
22ef683b | 299 | static void ice_init_flex_flags(struct ice_hw *hw, enum ice_rxdid prof_id) |
cdedef59 AV |
300 | { |
301 | u8 idx = 0; | |
302 | ||
22ef683b AV |
303 | /* Flex-flag fields (0-2) are programmed with FLG64 bits with layout: |
304 | * flexiflags0[5:0] - TCP flags, is_packet_fragmented, is_packet_UDP_GRE | |
305 | * flexiflags1[3:0] - Not used for flag programming | |
306 | * flexiflags2[7:0] - Tunnel and VLAN types | |
307 | * 2 invalid fields in last index | |
308 | */ | |
309 | switch (prof_id) { | |
310 | /* Rx flex flags are currently programmed for the NIC profiles only. | |
311 | * Different flag bit programming configurations can be added per | |
312 | * profile as needed. | |
313 | */ | |
314 | case ICE_RXDID_FLEX_NIC: | |
315 | case ICE_RXDID_FLEX_NIC_2: | |
316 | ICE_PROG_FLG_ENTRY(hw, prof_id, ICE_RXFLG_PKT_FRG, | |
317 | ICE_RXFLG_UDP_GRE, ICE_RXFLG_PKT_DSI, | |
318 | ICE_RXFLG_FIN, idx++); | |
319 | /* flex flag 1 is not used for flexi-flag programming, skipping | |
320 | * these four FLG64 bits. | |
321 | */ | |
322 | ICE_PROG_FLG_ENTRY(hw, prof_id, ICE_RXFLG_SYN, ICE_RXFLG_RST, | |
323 | ICE_RXFLG_PKT_DSI, ICE_RXFLG_PKT_DSI, idx++); | |
324 | ICE_PROG_FLG_ENTRY(hw, prof_id, ICE_RXFLG_PKT_DSI, | |
325 | ICE_RXFLG_PKT_DSI, ICE_RXFLG_EVLAN_x8100, | |
326 | ICE_RXFLG_EVLAN_x9100, idx++); | |
327 | ICE_PROG_FLG_ENTRY(hw, prof_id, ICE_RXFLG_VLAN_x8100, | |
328 | ICE_RXFLG_TNL_VLAN, ICE_RXFLG_TNL_MAC, | |
329 | ICE_RXFLG_TNL0, idx++); | |
330 | ICE_PROG_FLG_ENTRY(hw, prof_id, ICE_RXFLG_TNL1, ICE_RXFLG_TNL2, | |
331 | ICE_RXFLG_PKT_DSI, ICE_RXFLG_PKT_DSI, idx); | |
332 | break; | |
333 | ||
334 | default: | |
335 | ice_debug(hw, ICE_DBG_INIT, | |
336 | "Flag programming for profile ID %d not supported\n", | |
337 | prof_id); | |
338 | } | |
339 | } | |
340 | ||
341 | /** | |
342 | * ice_init_flex_flds | |
343 | * @hw: pointer to the hardware structure | |
344 | * @prof_id: Rx Descriptor Builder profile ID | |
345 | * | |
346 | * Function to initialize flex descriptors | |
347 | */ | |
348 | static void ice_init_flex_flds(struct ice_hw *hw, enum ice_rxdid prof_id) | |
349 | { | |
350 | enum ice_flex_rx_mdid mdid; | |
351 | ||
352 | switch (prof_id) { | |
353 | case ICE_RXDID_FLEX_NIC: | |
354 | case ICE_RXDID_FLEX_NIC_2: | |
355 | ICE_PROG_FLEX_ENTRY(hw, prof_id, ICE_RX_MDID_HASH_LOW, 0); | |
356 | ICE_PROG_FLEX_ENTRY(hw, prof_id, ICE_RX_MDID_HASH_HIGH, 1); | |
357 | ICE_PROG_FLEX_ENTRY(hw, prof_id, ICE_RX_MDID_FLOW_ID_LOWER, 2); | |
358 | ||
359 | mdid = (prof_id == ICE_RXDID_FLEX_NIC_2) ? | |
360 | ICE_RX_MDID_SRC_VSI : ICE_RX_MDID_FLOW_ID_HIGH; | |
361 | ||
362 | ICE_PROG_FLEX_ENTRY(hw, prof_id, mdid, 3); | |
363 | ||
364 | ice_init_flex_flags(hw, prof_id); | |
365 | break; | |
366 | ||
367 | default: | |
368 | ice_debug(hw, ICE_DBG_INIT, | |
369 | "Field init for profile ID %d not supported\n", | |
370 | prof_id); | |
371 | } | |
cdedef59 AV |
372 | } |
373 | ||
9daf8208 AV |
374 | /** |
375 | * ice_init_fltr_mgmt_struct - initializes filter management list and locks | |
376 | * @hw: pointer to the hw struct | |
377 | */ | |
378 | static enum ice_status ice_init_fltr_mgmt_struct(struct ice_hw *hw) | |
379 | { | |
380 | struct ice_switch_info *sw; | |
381 | ||
382 | hw->switch_info = devm_kzalloc(ice_hw_to_dev(hw), | |
383 | sizeof(*hw->switch_info), GFP_KERNEL); | |
384 | sw = hw->switch_info; | |
385 | ||
386 | if (!sw) | |
387 | return ICE_ERR_NO_MEMORY; | |
388 | ||
389 | INIT_LIST_HEAD(&sw->vsi_list_map_head); | |
390 | ||
80d144c9 | 391 | ice_init_def_sw_recp(hw); |
9daf8208 AV |
392 | |
393 | return 0; | |
394 | } | |
395 | ||
396 | /** | |
397 | * ice_cleanup_fltr_mgmt_struct - cleanup filter management list and locks | |
398 | * @hw: pointer to the hw struct | |
399 | */ | |
400 | static void ice_cleanup_fltr_mgmt_struct(struct ice_hw *hw) | |
401 | { | |
402 | struct ice_switch_info *sw = hw->switch_info; | |
403 | struct ice_vsi_list_map_info *v_pos_map; | |
404 | struct ice_vsi_list_map_info *v_tmp_map; | |
80d144c9 AV |
405 | struct ice_sw_recipe *recps; |
406 | u8 i; | |
9daf8208 AV |
407 | |
408 | list_for_each_entry_safe(v_pos_map, v_tmp_map, &sw->vsi_list_map_head, | |
409 | list_entry) { | |
410 | list_del(&v_pos_map->list_entry); | |
411 | devm_kfree(ice_hw_to_dev(hw), v_pos_map); | |
412 | } | |
80d144c9 AV |
413 | recps = hw->switch_info->recp_list; |
414 | for (i = 0; i < ICE_SW_LKUP_LAST; i++) { | |
415 | struct ice_fltr_mgmt_list_entry *lst_itr, *tmp_entry; | |
416 | ||
417 | recps[i].root_rid = i; | |
418 | mutex_destroy(&recps[i].filt_rule_lock); | |
419 | list_for_each_entry_safe(lst_itr, tmp_entry, | |
420 | &recps[i].filt_rules, list_entry) { | |
421 | list_del(&lst_itr->list_entry); | |
422 | devm_kfree(ice_hw_to_dev(hw), lst_itr); | |
423 | } | |
424 | } | |
9daf8208 | 425 | |
80d144c9 | 426 | devm_kfree(ice_hw_to_dev(hw), sw->recp_list); |
9daf8208 AV |
427 | devm_kfree(ice_hw_to_dev(hw), sw); |
428 | } | |
429 | ||
f31e4b6f AV |
430 | /** |
431 | * ice_init_hw - main hardware initialization routine | |
432 | * @hw: pointer to the hardware structure | |
433 | */ | |
434 | enum ice_status ice_init_hw(struct ice_hw *hw) | |
435 | { | |
dc49c772 | 436 | struct ice_aqc_get_phy_caps_data *pcaps; |
f31e4b6f | 437 | enum ice_status status; |
dc49c772 AV |
438 | u16 mac_buf_len; |
439 | void *mac_buf; | |
f31e4b6f AV |
440 | |
441 | /* Set MAC type based on DeviceID */ | |
442 | status = ice_set_mac_type(hw); | |
443 | if (status) | |
444 | return status; | |
445 | ||
446 | hw->pf_id = (u8)(rd32(hw, PF_FUNC_RID) & | |
447 | PF_FUNC_RID_FUNC_NUM_M) >> | |
448 | PF_FUNC_RID_FUNC_NUM_S; | |
449 | ||
450 | status = ice_reset(hw, ICE_RESET_PFR); | |
451 | if (status) | |
452 | return status; | |
453 | ||
940b61af AV |
454 | /* set these values to minimum allowed */ |
455 | hw->itr_gran_200 = ICE_ITR_GRAN_MIN_200; | |
456 | hw->itr_gran_100 = ICE_ITR_GRAN_MIN_100; | |
457 | hw->itr_gran_50 = ICE_ITR_GRAN_MIN_50; | |
458 | hw->itr_gran_25 = ICE_ITR_GRAN_MIN_25; | |
459 | ||
f31e4b6f AV |
460 | status = ice_init_all_ctrlq(hw); |
461 | if (status) | |
462 | goto err_unroll_cqinit; | |
463 | ||
464 | status = ice_clear_pf_cfg(hw); | |
465 | if (status) | |
466 | goto err_unroll_cqinit; | |
467 | ||
468 | ice_clear_pxe_mode(hw); | |
469 | ||
470 | status = ice_init_nvm(hw); | |
471 | if (status) | |
472 | goto err_unroll_cqinit; | |
473 | ||
9c20346b AV |
474 | status = ice_get_caps(hw); |
475 | if (status) | |
476 | goto err_unroll_cqinit; | |
477 | ||
478 | hw->port_info = devm_kzalloc(ice_hw_to_dev(hw), | |
479 | sizeof(*hw->port_info), GFP_KERNEL); | |
480 | if (!hw->port_info) { | |
481 | status = ICE_ERR_NO_MEMORY; | |
482 | goto err_unroll_cqinit; | |
483 | } | |
484 | ||
485 | /* set the back pointer to hw */ | |
486 | hw->port_info->hw = hw; | |
487 | ||
488 | /* Initialize port_info struct with switch configuration data */ | |
489 | status = ice_get_initial_sw_cfg(hw); | |
490 | if (status) | |
491 | goto err_unroll_alloc; | |
492 | ||
9daf8208 AV |
493 | hw->evb_veb = true; |
494 | ||
9c20346b AV |
495 | /* Query the allocated resources for tx scheduler */ |
496 | status = ice_sched_query_res_alloc(hw); | |
497 | if (status) { | |
498 | ice_debug(hw, ICE_DBG_SCHED, | |
499 | "Failed to get scheduler allocated resources\n"); | |
500 | goto err_unroll_alloc; | |
501 | } | |
502 | ||
dc49c772 AV |
503 | /* Initialize port_info struct with scheduler data */ |
504 | status = ice_sched_init_port(hw->port_info); | |
505 | if (status) | |
506 | goto err_unroll_sched; | |
507 | ||
508 | pcaps = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*pcaps), GFP_KERNEL); | |
509 | if (!pcaps) { | |
510 | status = ICE_ERR_NO_MEMORY; | |
511 | goto err_unroll_sched; | |
512 | } | |
513 | ||
514 | /* Initialize port_info struct with PHY capabilities */ | |
515 | status = ice_aq_get_phy_caps(hw->port_info, false, | |
516 | ICE_AQC_REPORT_TOPO_CAP, pcaps, NULL); | |
517 | devm_kfree(ice_hw_to_dev(hw), pcaps); | |
518 | if (status) | |
519 | goto err_unroll_sched; | |
520 | ||
521 | /* Initialize port_info struct with link information */ | |
522 | status = ice_aq_get_link_info(hw->port_info, false, NULL, NULL); | |
523 | if (status) | |
524 | goto err_unroll_sched; | |
525 | ||
b36c598c AV |
526 | /* need a valid SW entry point to build a Tx tree */ |
527 | if (!hw->sw_entry_point_layer) { | |
528 | ice_debug(hw, ICE_DBG_SCHED, "invalid sw entry point\n"); | |
529 | status = ICE_ERR_CFG; | |
530 | goto err_unroll_sched; | |
531 | } | |
532 | ||
9daf8208 AV |
533 | status = ice_init_fltr_mgmt_struct(hw); |
534 | if (status) | |
535 | goto err_unroll_sched; | |
536 | ||
d6fef10c MFIP |
537 | /* Get MAC information */ |
538 | /* A single port can report up to two (LAN and WoL) addresses */ | |
539 | mac_buf = devm_kcalloc(ice_hw_to_dev(hw), 2, | |
540 | sizeof(struct ice_aqc_manage_mac_read_resp), | |
541 | GFP_KERNEL); | |
542 | mac_buf_len = 2 * sizeof(struct ice_aqc_manage_mac_read_resp); | |
dc49c772 | 543 | |
63bb4e1e WY |
544 | if (!mac_buf) { |
545 | status = ICE_ERR_NO_MEMORY; | |
9daf8208 | 546 | goto err_unroll_fltr_mgmt_struct; |
63bb4e1e | 547 | } |
dc49c772 AV |
548 | |
549 | status = ice_aq_manage_mac_read(hw, mac_buf, mac_buf_len, NULL); | |
550 | devm_kfree(ice_hw_to_dev(hw), mac_buf); | |
551 | ||
552 | if (status) | |
9daf8208 | 553 | goto err_unroll_fltr_mgmt_struct; |
dc49c772 | 554 | |
22ef683b AV |
555 | ice_init_flex_flds(hw, ICE_RXDID_FLEX_NIC); |
556 | ice_init_flex_flds(hw, ICE_RXDID_FLEX_NIC_2); | |
cdedef59 | 557 | |
f31e4b6f AV |
558 | return 0; |
559 | ||
9daf8208 AV |
560 | err_unroll_fltr_mgmt_struct: |
561 | ice_cleanup_fltr_mgmt_struct(hw); | |
dc49c772 AV |
562 | err_unroll_sched: |
563 | ice_sched_cleanup_all(hw); | |
9c20346b AV |
564 | err_unroll_alloc: |
565 | devm_kfree(ice_hw_to_dev(hw), hw->port_info); | |
f31e4b6f AV |
566 | err_unroll_cqinit: |
567 | ice_shutdown_all_ctrlq(hw); | |
568 | return status; | |
569 | } | |
570 | ||
571 | /** | |
572 | * ice_deinit_hw - unroll initialization operations done by ice_init_hw | |
573 | * @hw: pointer to the hardware structure | |
574 | */ | |
575 | void ice_deinit_hw(struct ice_hw *hw) | |
576 | { | |
9c20346b | 577 | ice_sched_cleanup_all(hw); |
f31e4b6f | 578 | ice_shutdown_all_ctrlq(hw); |
dc49c772 | 579 | |
9c20346b AV |
580 | if (hw->port_info) { |
581 | devm_kfree(ice_hw_to_dev(hw), hw->port_info); | |
582 | hw->port_info = NULL; | |
583 | } | |
9daf8208 AV |
584 | |
585 | ice_cleanup_fltr_mgmt_struct(hw); | |
f31e4b6f AV |
586 | } |
587 | ||
588 | /** | |
589 | * ice_check_reset - Check to see if a global reset is complete | |
590 | * @hw: pointer to the hardware structure | |
591 | */ | |
592 | enum ice_status ice_check_reset(struct ice_hw *hw) | |
593 | { | |
594 | u32 cnt, reg = 0, grst_delay; | |
595 | ||
596 | /* Poll for Device Active state in case a recent CORER, GLOBR, | |
597 | * or EMPR has occurred. The grst delay value is in 100ms units. | |
598 | * Add 1sec for outstanding AQ commands that can take a long time. | |
599 | */ | |
600 | grst_delay = ((rd32(hw, GLGEN_RSTCTL) & GLGEN_RSTCTL_GRSTDEL_M) >> | |
601 | GLGEN_RSTCTL_GRSTDEL_S) + 10; | |
602 | ||
603 | for (cnt = 0; cnt < grst_delay; cnt++) { | |
604 | mdelay(100); | |
605 | reg = rd32(hw, GLGEN_RSTAT); | |
606 | if (!(reg & GLGEN_RSTAT_DEVSTATE_M)) | |
607 | break; | |
608 | } | |
609 | ||
610 | if (cnt == grst_delay) { | |
611 | ice_debug(hw, ICE_DBG_INIT, | |
612 | "Global reset polling failed to complete.\n"); | |
613 | return ICE_ERR_RESET_FAILED; | |
614 | } | |
615 | ||
616 | #define ICE_RESET_DONE_MASK (GLNVM_ULD_CORER_DONE_M | \ | |
617 | GLNVM_ULD_GLOBR_DONE_M) | |
618 | ||
619 | /* Device is Active; check Global Reset processes are done */ | |
620 | for (cnt = 0; cnt < ICE_PF_RESET_WAIT_COUNT; cnt++) { | |
621 | reg = rd32(hw, GLNVM_ULD) & ICE_RESET_DONE_MASK; | |
622 | if (reg == ICE_RESET_DONE_MASK) { | |
623 | ice_debug(hw, ICE_DBG_INIT, | |
624 | "Global reset processes done. %d\n", cnt); | |
625 | break; | |
626 | } | |
627 | mdelay(10); | |
628 | } | |
629 | ||
630 | if (cnt == ICE_PF_RESET_WAIT_COUNT) { | |
631 | ice_debug(hw, ICE_DBG_INIT, | |
632 | "Wait for Reset Done timed out. GLNVM_ULD = 0x%x\n", | |
633 | reg); | |
634 | return ICE_ERR_RESET_FAILED; | |
635 | } | |
636 | ||
637 | return 0; | |
638 | } | |
639 | ||
640 | /** | |
641 | * ice_pf_reset - Reset the PF | |
642 | * @hw: pointer to the hardware structure | |
643 | * | |
644 | * If a global reset has been triggered, this function checks | |
645 | * for its completion and then issues the PF reset | |
646 | */ | |
647 | static enum ice_status ice_pf_reset(struct ice_hw *hw) | |
648 | { | |
649 | u32 cnt, reg; | |
650 | ||
651 | /* If at function entry a global reset was already in progress, i.e. | |
652 | * state is not 'device active' or any of the reset done bits are not | |
653 | * set in GLNVM_ULD, there is no need for a PF Reset; poll until the | |
654 | * global reset is done. | |
655 | */ | |
656 | if ((rd32(hw, GLGEN_RSTAT) & GLGEN_RSTAT_DEVSTATE_M) || | |
657 | (rd32(hw, GLNVM_ULD) & ICE_RESET_DONE_MASK) ^ ICE_RESET_DONE_MASK) { | |
658 | /* poll on global reset currently in progress until done */ | |
659 | if (ice_check_reset(hw)) | |
660 | return ICE_ERR_RESET_FAILED; | |
661 | ||
662 | return 0; | |
663 | } | |
664 | ||
665 | /* Reset the PF */ | |
666 | reg = rd32(hw, PFGEN_CTRL); | |
667 | ||
668 | wr32(hw, PFGEN_CTRL, (reg | PFGEN_CTRL_PFSWR_M)); | |
669 | ||
670 | for (cnt = 0; cnt < ICE_PF_RESET_WAIT_COUNT; cnt++) { | |
671 | reg = rd32(hw, PFGEN_CTRL); | |
672 | if (!(reg & PFGEN_CTRL_PFSWR_M)) | |
673 | break; | |
674 | ||
675 | mdelay(1); | |
676 | } | |
677 | ||
678 | if (cnt == ICE_PF_RESET_WAIT_COUNT) { | |
679 | ice_debug(hw, ICE_DBG_INIT, | |
680 | "PF reset polling failed to complete.\n"); | |
681 | return ICE_ERR_RESET_FAILED; | |
682 | } | |
683 | ||
684 | return 0; | |
685 | } | |
686 | ||
687 | /** | |
688 | * ice_reset - Perform different types of reset | |
689 | * @hw: pointer to the hardware structure | |
690 | * @req: reset request | |
691 | * | |
692 | * This function triggers a reset as specified by the req parameter. | |
693 | * | |
694 | * Note: | |
695 | * If anything other than a PF reset is triggered, PXE mode is restored. | |
696 | * This has to be cleared using ice_clear_pxe_mode again, once the AQ | |
697 | * interface has been restored in the rebuild flow. | |
698 | */ | |
699 | enum ice_status ice_reset(struct ice_hw *hw, enum ice_reset_req req) | |
700 | { | |
701 | u32 val = 0; | |
702 | ||
703 | switch (req) { | |
704 | case ICE_RESET_PFR: | |
705 | return ice_pf_reset(hw); | |
706 | case ICE_RESET_CORER: | |
707 | ice_debug(hw, ICE_DBG_INIT, "CoreR requested\n"); | |
708 | val = GLGEN_RTRIG_CORER_M; | |
709 | break; | |
710 | case ICE_RESET_GLOBR: | |
711 | ice_debug(hw, ICE_DBG_INIT, "GlobalR requested\n"); | |
712 | val = GLGEN_RTRIG_GLOBR_M; | |
713 | break; | |
0f9d5027 AV |
714 | default: |
715 | return ICE_ERR_PARAM; | |
f31e4b6f AV |
716 | } |
717 | ||
718 | val |= rd32(hw, GLGEN_RTRIG); | |
719 | wr32(hw, GLGEN_RTRIG, val); | |
720 | ice_flush(hw); | |
721 | ||
722 | /* wait for the FW to be ready */ | |
723 | return ice_check_reset(hw); | |
724 | } | |
725 | ||
cdedef59 AV |
726 | /** |
727 | * ice_copy_rxq_ctx_to_hw | |
728 | * @hw: pointer to the hardware structure | |
729 | * @ice_rxq_ctx: pointer to the rxq context | |
730 | * @rxq_index: the index of the rx queue | |
731 | * | |
732 | * Copies rxq context from dense structure to hw register space | |
733 | */ | |
734 | static enum ice_status | |
735 | ice_copy_rxq_ctx_to_hw(struct ice_hw *hw, u8 *ice_rxq_ctx, u32 rxq_index) | |
736 | { | |
737 | u8 i; | |
738 | ||
739 | if (!ice_rxq_ctx) | |
740 | return ICE_ERR_BAD_PTR; | |
741 | ||
742 | if (rxq_index > QRX_CTRL_MAX_INDEX) | |
743 | return ICE_ERR_PARAM; | |
744 | ||
745 | /* Copy each dword separately to hw */ | |
746 | for (i = 0; i < ICE_RXQ_CTX_SIZE_DWORDS; i++) { | |
747 | wr32(hw, QRX_CONTEXT(i, rxq_index), | |
748 | *((u32 *)(ice_rxq_ctx + (i * sizeof(u32))))); | |
749 | ||
750 | ice_debug(hw, ICE_DBG_QCTX, "qrxdata[%d]: %08X\n", i, | |
751 | *((u32 *)(ice_rxq_ctx + (i * sizeof(u32))))); | |
752 | } | |
753 | ||
754 | return 0; | |
755 | } | |
756 | ||
757 | /* LAN Rx Queue Context */ | |
758 | static const struct ice_ctx_ele ice_rlan_ctx_info[] = { | |
759 | /* Field Width LSB */ | |
760 | ICE_CTX_STORE(ice_rlan_ctx, head, 13, 0), | |
761 | ICE_CTX_STORE(ice_rlan_ctx, cpuid, 8, 13), | |
762 | ICE_CTX_STORE(ice_rlan_ctx, base, 57, 32), | |
763 | ICE_CTX_STORE(ice_rlan_ctx, qlen, 13, 89), | |
764 | ICE_CTX_STORE(ice_rlan_ctx, dbuf, 7, 102), | |
765 | ICE_CTX_STORE(ice_rlan_ctx, hbuf, 5, 109), | |
766 | ICE_CTX_STORE(ice_rlan_ctx, dtype, 2, 114), | |
767 | ICE_CTX_STORE(ice_rlan_ctx, dsize, 1, 116), | |
768 | ICE_CTX_STORE(ice_rlan_ctx, crcstrip, 1, 117), | |
769 | ICE_CTX_STORE(ice_rlan_ctx, l2tsel, 1, 119), | |
770 | ICE_CTX_STORE(ice_rlan_ctx, hsplit_0, 4, 120), | |
771 | ICE_CTX_STORE(ice_rlan_ctx, hsplit_1, 2, 124), | |
772 | ICE_CTX_STORE(ice_rlan_ctx, showiv, 1, 127), | |
773 | ICE_CTX_STORE(ice_rlan_ctx, rxmax, 14, 174), | |
774 | ICE_CTX_STORE(ice_rlan_ctx, tphrdesc_ena, 1, 193), | |
775 | ICE_CTX_STORE(ice_rlan_ctx, tphwdesc_ena, 1, 194), | |
776 | ICE_CTX_STORE(ice_rlan_ctx, tphdata_ena, 1, 195), | |
777 | ICE_CTX_STORE(ice_rlan_ctx, tphhead_ena, 1, 196), | |
778 | ICE_CTX_STORE(ice_rlan_ctx, lrxqthresh, 3, 198), | |
779 | { 0 } | |
780 | }; | |
781 | ||
782 | /** | |
783 | * ice_write_rxq_ctx | |
784 | * @hw: pointer to the hardware structure | |
785 | * @rlan_ctx: pointer to the rxq context | |
786 | * @rxq_index: the index of the rx queue | |
787 | * | |
788 | * Converts rxq context from sparse to dense structure and then writes | |
789 | * it to hw register space | |
790 | */ | |
791 | enum ice_status | |
792 | ice_write_rxq_ctx(struct ice_hw *hw, struct ice_rlan_ctx *rlan_ctx, | |
793 | u32 rxq_index) | |
794 | { | |
795 | u8 ctx_buf[ICE_RXQ_CTX_SZ] = { 0 }; | |
796 | ||
797 | ice_set_ctx((u8 *)rlan_ctx, ctx_buf, ice_rlan_ctx_info); | |
798 | return ice_copy_rxq_ctx_to_hw(hw, ctx_buf, rxq_index); | |
799 | } | |
800 | ||
801 | /* LAN Tx Queue Context */ | |
802 | const struct ice_ctx_ele ice_tlan_ctx_info[] = { | |
803 | /* Field Width LSB */ | |
804 | ICE_CTX_STORE(ice_tlan_ctx, base, 57, 0), | |
805 | ICE_CTX_STORE(ice_tlan_ctx, port_num, 3, 57), | |
806 | ICE_CTX_STORE(ice_tlan_ctx, cgd_num, 5, 60), | |
807 | ICE_CTX_STORE(ice_tlan_ctx, pf_num, 3, 65), | |
808 | ICE_CTX_STORE(ice_tlan_ctx, vmvf_num, 10, 68), | |
809 | ICE_CTX_STORE(ice_tlan_ctx, vmvf_type, 2, 78), | |
810 | ICE_CTX_STORE(ice_tlan_ctx, src_vsi, 10, 80), | |
811 | ICE_CTX_STORE(ice_tlan_ctx, tsyn_ena, 1, 90), | |
812 | ICE_CTX_STORE(ice_tlan_ctx, alt_vlan, 1, 92), | |
813 | ICE_CTX_STORE(ice_tlan_ctx, cpuid, 8, 93), | |
814 | ICE_CTX_STORE(ice_tlan_ctx, wb_mode, 1, 101), | |
815 | ICE_CTX_STORE(ice_tlan_ctx, tphrd_desc, 1, 102), | |
816 | ICE_CTX_STORE(ice_tlan_ctx, tphrd, 1, 103), | |
817 | ICE_CTX_STORE(ice_tlan_ctx, tphwr_desc, 1, 104), | |
818 | ICE_CTX_STORE(ice_tlan_ctx, cmpq_id, 9, 105), | |
819 | ICE_CTX_STORE(ice_tlan_ctx, qnum_in_func, 14, 114), | |
820 | ICE_CTX_STORE(ice_tlan_ctx, itr_notification_mode, 1, 128), | |
821 | ICE_CTX_STORE(ice_tlan_ctx, adjust_prof_id, 6, 129), | |
822 | ICE_CTX_STORE(ice_tlan_ctx, qlen, 13, 135), | |
823 | ICE_CTX_STORE(ice_tlan_ctx, quanta_prof_idx, 4, 148), | |
824 | ICE_CTX_STORE(ice_tlan_ctx, tso_ena, 1, 152), | |
825 | ICE_CTX_STORE(ice_tlan_ctx, tso_qnum, 11, 153), | |
826 | ICE_CTX_STORE(ice_tlan_ctx, legacy_int, 1, 164), | |
827 | ICE_CTX_STORE(ice_tlan_ctx, drop_ena, 1, 165), | |
828 | ICE_CTX_STORE(ice_tlan_ctx, cache_prof_idx, 2, 166), | |
829 | ICE_CTX_STORE(ice_tlan_ctx, pkt_shaper_prof_idx, 3, 168), | |
830 | ICE_CTX_STORE(ice_tlan_ctx, int_q_state, 110, 171), | |
831 | { 0 } | |
832 | }; | |
833 | ||
7ec59eea AV |
834 | /** |
835 | * ice_debug_cq | |
836 | * @hw: pointer to the hardware structure | |
837 | * @mask: debug mask | |
838 | * @desc: pointer to control queue descriptor | |
839 | * @buf: pointer to command buffer | |
840 | * @buf_len: max length of buf | |
841 | * | |
842 | * Dumps debug log about control command with descriptor contents. | |
843 | */ | |
844 | void ice_debug_cq(struct ice_hw *hw, u32 __maybe_unused mask, void *desc, | |
845 | void *buf, u16 buf_len) | |
846 | { | |
847 | struct ice_aq_desc *cq_desc = (struct ice_aq_desc *)desc; | |
848 | u16 len; | |
849 | ||
850 | #ifndef CONFIG_DYNAMIC_DEBUG | |
851 | if (!(mask & hw->debug_mask)) | |
852 | return; | |
853 | #endif | |
854 | ||
855 | if (!desc) | |
856 | return; | |
857 | ||
858 | len = le16_to_cpu(cq_desc->datalen); | |
859 | ||
860 | ice_debug(hw, mask, | |
861 | "CQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n", | |
862 | le16_to_cpu(cq_desc->opcode), | |
863 | le16_to_cpu(cq_desc->flags), | |
864 | le16_to_cpu(cq_desc->datalen), le16_to_cpu(cq_desc->retval)); | |
865 | ice_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n", | |
866 | le32_to_cpu(cq_desc->cookie_high), | |
867 | le32_to_cpu(cq_desc->cookie_low)); | |
868 | ice_debug(hw, mask, "\tparam (0,1) 0x%08X 0x%08X\n", | |
869 | le32_to_cpu(cq_desc->params.generic.param0), | |
870 | le32_to_cpu(cq_desc->params.generic.param1)); | |
871 | ice_debug(hw, mask, "\taddr (h,l) 0x%08X 0x%08X\n", | |
872 | le32_to_cpu(cq_desc->params.generic.addr_high), | |
873 | le32_to_cpu(cq_desc->params.generic.addr_low)); | |
874 | if (buf && cq_desc->datalen != 0) { | |
875 | ice_debug(hw, mask, "Buffer:\n"); | |
876 | if (buf_len < len) | |
877 | len = buf_len; | |
878 | ||
879 | ice_debug_array(hw, mask, 16, 1, (u8 *)buf, len); | |
880 | } | |
881 | } | |
882 | ||
883 | /* FW Admin Queue command wrappers */ | |
884 | ||
885 | /** | |
886 | * ice_aq_send_cmd - send FW Admin Queue command to FW Admin Queue | |
887 | * @hw: pointer to the hw struct | |
888 | * @desc: descriptor describing the command | |
889 | * @buf: buffer to use for indirect commands (NULL for direct commands) | |
890 | * @buf_size: size of buffer for indirect commands (0 for direct commands) | |
891 | * @cd: pointer to command details structure | |
892 | * | |
893 | * Helper function to send FW Admin Queue commands to the FW Admin Queue. | |
894 | */ | |
895 | enum ice_status | |
896 | ice_aq_send_cmd(struct ice_hw *hw, struct ice_aq_desc *desc, void *buf, | |
897 | u16 buf_size, struct ice_sq_cd *cd) | |
898 | { | |
899 | return ice_sq_send_cmd(hw, &hw->adminq, desc, buf, buf_size, cd); | |
900 | } | |
901 | ||
902 | /** | |
903 | * ice_aq_get_fw_ver | |
904 | * @hw: pointer to the hw struct | |
905 | * @cd: pointer to command details structure or NULL | |
906 | * | |
907 | * Get the firmware version (0x0001) from the admin queue commands | |
908 | */ | |
909 | enum ice_status ice_aq_get_fw_ver(struct ice_hw *hw, struct ice_sq_cd *cd) | |
910 | { | |
911 | struct ice_aqc_get_ver *resp; | |
912 | struct ice_aq_desc desc; | |
913 | enum ice_status status; | |
914 | ||
915 | resp = &desc.params.get_ver; | |
916 | ||
917 | ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_ver); | |
918 | ||
919 | status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd); | |
920 | ||
921 | if (!status) { | |
922 | hw->fw_branch = resp->fw_branch; | |
923 | hw->fw_maj_ver = resp->fw_major; | |
924 | hw->fw_min_ver = resp->fw_minor; | |
925 | hw->fw_patch = resp->fw_patch; | |
926 | hw->fw_build = le32_to_cpu(resp->fw_build); | |
927 | hw->api_branch = resp->api_branch; | |
928 | hw->api_maj_ver = resp->api_major; | |
929 | hw->api_min_ver = resp->api_minor; | |
930 | hw->api_patch = resp->api_patch; | |
931 | } | |
932 | ||
933 | return status; | |
934 | } | |
935 | ||
936 | /** | |
937 | * ice_aq_q_shutdown | |
938 | * @hw: pointer to the hw struct | |
939 | * @unloading: is the driver unloading itself | |
940 | * | |
941 | * Tell the Firmware that we're shutting down the AdminQ and whether | |
942 | * or not the driver is unloading as well (0x0003). | |
943 | */ | |
944 | enum ice_status ice_aq_q_shutdown(struct ice_hw *hw, bool unloading) | |
945 | { | |
946 | struct ice_aqc_q_shutdown *cmd; | |
947 | struct ice_aq_desc desc; | |
948 | ||
949 | cmd = &desc.params.q_shutdown; | |
950 | ||
951 | ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_q_shutdown); | |
952 | ||
953 | if (unloading) | |
954 | cmd->driver_unloading = cpu_to_le32(ICE_AQC_DRIVER_UNLOADING); | |
955 | ||
956 | return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL); | |
957 | } | |
f31e4b6f AV |
958 | |
959 | /** | |
960 | * ice_aq_req_res | |
961 | * @hw: pointer to the hw struct | |
962 | * @res: resource id | |
963 | * @access: access type | |
964 | * @sdp_number: resource number | |
965 | * @timeout: the maximum time in ms that the driver may hold the resource | |
966 | * @cd: pointer to command details structure or NULL | |
967 | * | |
ff2b1321 DN |
968 | * Requests common resource using the admin queue commands (0x0008). |
969 | * When attempting to acquire the Global Config Lock, the driver can | |
970 | * learn of three states: | |
971 | * 1) ICE_SUCCESS - acquired lock, and can perform download package | |
972 | * 2) ICE_ERR_AQ_ERROR - did not get lock, driver should fail to load | |
973 | * 3) ICE_ERR_AQ_NO_WORK - did not get lock, but another driver has | |
974 | * successfully downloaded the package; the driver does | |
975 | * not have to download the package and can continue | |
976 | * loading | |
977 | * | |
978 | * Note that if the caller is in an acquire lock, perform action, release lock | |
979 | * phase of operation, it is possible that the FW may detect a timeout and issue | |
980 | * a CORER. In this case, the driver will receive a CORER interrupt and will | |
981 | * have to determine its cause. The calling thread that is handling this flow | |
982 | * will likely get an error propagated back to it indicating the Download | |
983 | * Package, Update Package or the Release Resource AQ commands timed out. | |
f31e4b6f AV |
984 | */ |
985 | static enum ice_status | |
986 | ice_aq_req_res(struct ice_hw *hw, enum ice_aq_res_ids res, | |
987 | enum ice_aq_res_access_type access, u8 sdp_number, u32 *timeout, | |
988 | struct ice_sq_cd *cd) | |
989 | { | |
990 | struct ice_aqc_req_res *cmd_resp; | |
991 | struct ice_aq_desc desc; | |
992 | enum ice_status status; | |
993 | ||
994 | cmd_resp = &desc.params.res_owner; | |
995 | ||
996 | ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_req_res); | |
997 | ||
998 | cmd_resp->res_id = cpu_to_le16(res); | |
999 | cmd_resp->access_type = cpu_to_le16(access); | |
1000 | cmd_resp->res_number = cpu_to_le32(sdp_number); | |
ff2b1321 DN |
1001 | cmd_resp->timeout = cpu_to_le32(*timeout); |
1002 | *timeout = 0; | |
f31e4b6f AV |
1003 | |
1004 | status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd); | |
ff2b1321 | 1005 | |
f31e4b6f AV |
1006 | /* The completion specifies the maximum time in ms that the driver |
1007 | * may hold the resource in the Timeout field. | |
ff2b1321 DN |
1008 | */ |
1009 | ||
1010 | /* Global config lock response utilizes an additional status field. | |
1011 | * | |
1012 | * If the Global config lock resource is held by some other driver, the | |
1013 | * command completes with ICE_AQ_RES_GLBL_IN_PROG in the status field | |
1014 | * and the timeout field indicates the maximum time the current owner | |
1015 | * of the resource has to free it. | |
1016 | */ | |
1017 | if (res == ICE_GLOBAL_CFG_LOCK_RES_ID) { | |
1018 | if (le16_to_cpu(cmd_resp->status) == ICE_AQ_RES_GLBL_SUCCESS) { | |
1019 | *timeout = le32_to_cpu(cmd_resp->timeout); | |
1020 | return 0; | |
1021 | } else if (le16_to_cpu(cmd_resp->status) == | |
1022 | ICE_AQ_RES_GLBL_IN_PROG) { | |
1023 | *timeout = le32_to_cpu(cmd_resp->timeout); | |
1024 | return ICE_ERR_AQ_ERROR; | |
1025 | } else if (le16_to_cpu(cmd_resp->status) == | |
1026 | ICE_AQ_RES_GLBL_DONE) { | |
1027 | return ICE_ERR_AQ_NO_WORK; | |
1028 | } | |
1029 | ||
1030 | /* invalid FW response, force a timeout immediately */ | |
1031 | *timeout = 0; | |
1032 | return ICE_ERR_AQ_ERROR; | |
1033 | } | |
1034 | ||
1035 | /* If the resource is held by some other driver, the command completes | |
1036 | * with a busy return value and the timeout field indicates the maximum | |
1037 | * time the current owner of the resource has to free it. | |
f31e4b6f AV |
1038 | */ |
1039 | if (!status || hw->adminq.sq_last_status == ICE_AQ_RC_EBUSY) | |
1040 | *timeout = le32_to_cpu(cmd_resp->timeout); | |
1041 | ||
1042 | return status; | |
1043 | } | |
1044 | ||
1045 | /** | |
1046 | * ice_aq_release_res | |
1047 | * @hw: pointer to the hw struct | |
1048 | * @res: resource id | |
1049 | * @sdp_number: resource number | |
1050 | * @cd: pointer to command details structure or NULL | |
1051 | * | |
1052 | * release common resource using the admin queue commands (0x0009) | |
1053 | */ | |
1054 | static enum ice_status | |
1055 | ice_aq_release_res(struct ice_hw *hw, enum ice_aq_res_ids res, u8 sdp_number, | |
1056 | struct ice_sq_cd *cd) | |
1057 | { | |
1058 | struct ice_aqc_req_res *cmd; | |
1059 | struct ice_aq_desc desc; | |
1060 | ||
1061 | cmd = &desc.params.res_owner; | |
1062 | ||
1063 | ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_release_res); | |
1064 | ||
1065 | cmd->res_id = cpu_to_le16(res); | |
1066 | cmd->res_number = cpu_to_le32(sdp_number); | |
1067 | ||
1068 | return ice_aq_send_cmd(hw, &desc, NULL, 0, cd); | |
1069 | } | |
1070 | ||
1071 | /** | |
1072 | * ice_acquire_res | |
1073 | * @hw: pointer to the HW structure | |
1074 | * @res: resource id | |
1075 | * @access: access type (read or write) | |
ff2b1321 | 1076 | * @timeout: timeout in milliseconds |
f31e4b6f AV |
1077 | * |
1078 | * This function will attempt to acquire the ownership of a resource. | |
1079 | */ | |
1080 | enum ice_status | |
1081 | ice_acquire_res(struct ice_hw *hw, enum ice_aq_res_ids res, | |
ff2b1321 | 1082 | enum ice_aq_res_access_type access, u32 timeout) |
f31e4b6f AV |
1083 | { |
1084 | #define ICE_RES_POLLING_DELAY_MS 10 | |
1085 | u32 delay = ICE_RES_POLLING_DELAY_MS; | |
ff2b1321 | 1086 | u32 time_left = timeout; |
f31e4b6f | 1087 | enum ice_status status; |
f31e4b6f AV |
1088 | |
1089 | status = ice_aq_req_res(hw, res, access, 0, &time_left, NULL); | |
1090 | ||
ff2b1321 DN |
1091 | /* A return code of ICE_ERR_AQ_NO_WORK means that another driver has |
1092 | * previously acquired the resource and performed any necessary updates; | |
1093 | * in this case the caller does not obtain the resource and has no | |
1094 | * further work to do. | |
f31e4b6f | 1095 | */ |
ff2b1321 | 1096 | if (status == ICE_ERR_AQ_NO_WORK) |
f31e4b6f | 1097 | goto ice_acquire_res_exit; |
f31e4b6f AV |
1098 | |
1099 | if (status) | |
1100 | ice_debug(hw, ICE_DBG_RES, | |
1101 | "resource %d acquire type %d failed.\n", res, access); | |
1102 | ||
1103 | /* If necessary, poll until the current lock owner timeouts */ | |
1104 | timeout = time_left; | |
1105 | while (status && timeout && time_left) { | |
1106 | mdelay(delay); | |
1107 | timeout = (timeout > delay) ? timeout - delay : 0; | |
1108 | status = ice_aq_req_res(hw, res, access, 0, &time_left, NULL); | |
1109 | ||
ff2b1321 | 1110 | if (status == ICE_ERR_AQ_NO_WORK) |
f31e4b6f | 1111 | /* lock free, but no work to do */ |
f31e4b6f | 1112 | break; |
f31e4b6f AV |
1113 | |
1114 | if (!status) | |
1115 | /* lock acquired */ | |
1116 | break; | |
1117 | } | |
1118 | if (status && status != ICE_ERR_AQ_NO_WORK) | |
1119 | ice_debug(hw, ICE_DBG_RES, "resource acquire timed out.\n"); | |
1120 | ||
1121 | ice_acquire_res_exit: | |
1122 | if (status == ICE_ERR_AQ_NO_WORK) { | |
1123 | if (access == ICE_RES_WRITE) | |
1124 | ice_debug(hw, ICE_DBG_RES, | |
1125 | "resource indicates no work to do.\n"); | |
1126 | else | |
1127 | ice_debug(hw, ICE_DBG_RES, | |
1128 | "Warning: ICE_ERR_AQ_NO_WORK not expected\n"); | |
1129 | } | |
1130 | return status; | |
1131 | } | |
1132 | ||
1133 | /** | |
1134 | * ice_release_res | |
1135 | * @hw: pointer to the HW structure | |
1136 | * @res: resource id | |
1137 | * | |
1138 | * This function will release a resource using the proper Admin Command. | |
1139 | */ | |
1140 | void ice_release_res(struct ice_hw *hw, enum ice_aq_res_ids res) | |
1141 | { | |
1142 | enum ice_status status; | |
1143 | u32 total_delay = 0; | |
1144 | ||
1145 | status = ice_aq_release_res(hw, res, 0, NULL); | |
1146 | ||
1147 | /* there are some rare cases when trying to release the resource | |
1148 | * results in an admin Q timeout, so handle them correctly | |
1149 | */ | |
1150 | while ((status == ICE_ERR_AQ_TIMEOUT) && | |
1151 | (total_delay < hw->adminq.sq_cmd_timeout)) { | |
1152 | mdelay(1); | |
1153 | status = ice_aq_release_res(hw, res, 0, NULL); | |
1154 | total_delay++; | |
1155 | } | |
1156 | } | |
1157 | ||
9c20346b AV |
1158 | /** |
1159 | * ice_parse_caps - parse function/device capabilities | |
1160 | * @hw: pointer to the hw struct | |
1161 | * @buf: pointer to a buffer containing function/device capability records | |
1162 | * @cap_count: number of capability records in the list | |
1163 | * @opc: type of capabilities list to parse | |
1164 | * | |
1165 | * Helper function to parse function(0x000a)/device(0x000b) capabilities list. | |
1166 | */ | |
1167 | static void | |
1168 | ice_parse_caps(struct ice_hw *hw, void *buf, u32 cap_count, | |
1169 | enum ice_adminq_opc opc) | |
1170 | { | |
1171 | struct ice_aqc_list_caps_elem *cap_resp; | |
1172 | struct ice_hw_func_caps *func_p = NULL; | |
1173 | struct ice_hw_dev_caps *dev_p = NULL; | |
1174 | struct ice_hw_common_caps *caps; | |
1175 | u32 i; | |
1176 | ||
1177 | if (!buf) | |
1178 | return; | |
1179 | ||
1180 | cap_resp = (struct ice_aqc_list_caps_elem *)buf; | |
1181 | ||
1182 | if (opc == ice_aqc_opc_list_dev_caps) { | |
1183 | dev_p = &hw->dev_caps; | |
1184 | caps = &dev_p->common_cap; | |
1185 | } else if (opc == ice_aqc_opc_list_func_caps) { | |
1186 | func_p = &hw->func_caps; | |
1187 | caps = &func_p->common_cap; | |
1188 | } else { | |
1189 | ice_debug(hw, ICE_DBG_INIT, "wrong opcode\n"); | |
1190 | return; | |
1191 | } | |
1192 | ||
1193 | for (i = 0; caps && i < cap_count; i++, cap_resp++) { | |
1194 | u32 logical_id = le32_to_cpu(cap_resp->logical_id); | |
1195 | u32 phys_id = le32_to_cpu(cap_resp->phys_id); | |
1196 | u32 number = le32_to_cpu(cap_resp->number); | |
1197 | u16 cap = le16_to_cpu(cap_resp->cap); | |
1198 | ||
1199 | switch (cap) { | |
1200 | case ICE_AQC_CAPS_VSI: | |
1201 | if (dev_p) { | |
1202 | dev_p->num_vsi_allocd_to_host = number; | |
1203 | ice_debug(hw, ICE_DBG_INIT, | |
1204 | "HW caps: Dev.VSI cnt = %d\n", | |
1205 | dev_p->num_vsi_allocd_to_host); | |
1206 | } else if (func_p) { | |
1207 | func_p->guaranteed_num_vsi = number; | |
1208 | ice_debug(hw, ICE_DBG_INIT, | |
1209 | "HW caps: Func.VSI cnt = %d\n", | |
1210 | func_p->guaranteed_num_vsi); | |
1211 | } | |
1212 | break; | |
1213 | case ICE_AQC_CAPS_RSS: | |
1214 | caps->rss_table_size = number; | |
1215 | caps->rss_table_entry_width = logical_id; | |
1216 | ice_debug(hw, ICE_DBG_INIT, | |
1217 | "HW caps: RSS table size = %d\n", | |
1218 | caps->rss_table_size); | |
1219 | ice_debug(hw, ICE_DBG_INIT, | |
1220 | "HW caps: RSS table width = %d\n", | |
1221 | caps->rss_table_entry_width); | |
1222 | break; | |
1223 | case ICE_AQC_CAPS_RXQS: | |
1224 | caps->num_rxq = number; | |
1225 | caps->rxq_first_id = phys_id; | |
1226 | ice_debug(hw, ICE_DBG_INIT, | |
1227 | "HW caps: Num Rx Qs = %d\n", caps->num_rxq); | |
1228 | ice_debug(hw, ICE_DBG_INIT, | |
1229 | "HW caps: Rx first queue ID = %d\n", | |
1230 | caps->rxq_first_id); | |
1231 | break; | |
1232 | case ICE_AQC_CAPS_TXQS: | |
1233 | caps->num_txq = number; | |
1234 | caps->txq_first_id = phys_id; | |
1235 | ice_debug(hw, ICE_DBG_INIT, | |
1236 | "HW caps: Num Tx Qs = %d\n", caps->num_txq); | |
1237 | ice_debug(hw, ICE_DBG_INIT, | |
1238 | "HW caps: Tx first queue ID = %d\n", | |
1239 | caps->txq_first_id); | |
1240 | break; | |
1241 | case ICE_AQC_CAPS_MSIX: | |
1242 | caps->num_msix_vectors = number; | |
1243 | caps->msix_vector_first_id = phys_id; | |
1244 | ice_debug(hw, ICE_DBG_INIT, | |
1245 | "HW caps: MSIX vector count = %d\n", | |
1246 | caps->num_msix_vectors); | |
1247 | ice_debug(hw, ICE_DBG_INIT, | |
1248 | "HW caps: MSIX first vector index = %d\n", | |
1249 | caps->msix_vector_first_id); | |
1250 | break; | |
1251 | case ICE_AQC_CAPS_MAX_MTU: | |
1252 | caps->max_mtu = number; | |
1253 | if (dev_p) | |
1254 | ice_debug(hw, ICE_DBG_INIT, | |
1255 | "HW caps: Dev.MaxMTU = %d\n", | |
1256 | caps->max_mtu); | |
1257 | else if (func_p) | |
1258 | ice_debug(hw, ICE_DBG_INIT, | |
1259 | "HW caps: func.MaxMTU = %d\n", | |
1260 | caps->max_mtu); | |
1261 | break; | |
1262 | default: | |
1263 | ice_debug(hw, ICE_DBG_INIT, | |
1264 | "HW caps: Unknown capability[%d]: 0x%x\n", i, | |
1265 | cap); | |
1266 | break; | |
1267 | } | |
1268 | } | |
1269 | } | |
1270 | ||
1271 | /** | |
1272 | * ice_aq_discover_caps - query function/device capabilities | |
1273 | * @hw: pointer to the hw struct | |
1274 | * @buf: a virtual buffer to hold the capabilities | |
1275 | * @buf_size: Size of the virtual buffer | |
1276 | * @data_size: Size of the returned data, or buf size needed if AQ err==ENOMEM | |
1277 | * @opc: capabilities type to discover - pass in the command opcode | |
1278 | * @cd: pointer to command details structure or NULL | |
1279 | * | |
1280 | * Get the function(0x000a)/device(0x000b) capabilities description from | |
1281 | * the firmware. | |
1282 | */ | |
1283 | static enum ice_status | |
1284 | ice_aq_discover_caps(struct ice_hw *hw, void *buf, u16 buf_size, u16 *data_size, | |
1285 | enum ice_adminq_opc opc, struct ice_sq_cd *cd) | |
1286 | { | |
1287 | struct ice_aqc_list_caps *cmd; | |
1288 | struct ice_aq_desc desc; | |
1289 | enum ice_status status; | |
1290 | ||
1291 | cmd = &desc.params.get_cap; | |
1292 | ||
1293 | if (opc != ice_aqc_opc_list_func_caps && | |
1294 | opc != ice_aqc_opc_list_dev_caps) | |
1295 | return ICE_ERR_PARAM; | |
1296 | ||
1297 | ice_fill_dflt_direct_cmd_desc(&desc, opc); | |
1298 | ||
1299 | status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd); | |
1300 | if (!status) | |
1301 | ice_parse_caps(hw, buf, le32_to_cpu(cmd->count), opc); | |
1302 | *data_size = le16_to_cpu(desc.datalen); | |
1303 | ||
1304 | return status; | |
1305 | } | |
1306 | ||
1307 | /** | |
1308 | * ice_get_caps - get info about the HW | |
1309 | * @hw: pointer to the hardware structure | |
1310 | */ | |
1311 | enum ice_status ice_get_caps(struct ice_hw *hw) | |
1312 | { | |
1313 | enum ice_status status; | |
1314 | u16 data_size = 0; | |
1315 | u16 cbuf_len; | |
1316 | u8 retries; | |
1317 | ||
1318 | /* The driver doesn't know how many capabilities the device will return | |
1319 | * so the buffer size required isn't known ahead of time. The driver | |
1320 | * starts with cbuf_len and if this turns out to be insufficient, the | |
1321 | * device returns ICE_AQ_RC_ENOMEM and also the buffer size it needs. | |
1322 | * The driver then allocates the buffer of this size and retries the | |
1323 | * operation. So it follows that the retry count is 2. | |
1324 | */ | |
1325 | #define ICE_GET_CAP_BUF_COUNT 40 | |
1326 | #define ICE_GET_CAP_RETRY_COUNT 2 | |
1327 | ||
1328 | cbuf_len = ICE_GET_CAP_BUF_COUNT * | |
1329 | sizeof(struct ice_aqc_list_caps_elem); | |
1330 | ||
1331 | retries = ICE_GET_CAP_RETRY_COUNT; | |
1332 | ||
1333 | do { | |
1334 | void *cbuf; | |
1335 | ||
1336 | cbuf = devm_kzalloc(ice_hw_to_dev(hw), cbuf_len, GFP_KERNEL); | |
1337 | if (!cbuf) | |
1338 | return ICE_ERR_NO_MEMORY; | |
1339 | ||
1340 | status = ice_aq_discover_caps(hw, cbuf, cbuf_len, &data_size, | |
1341 | ice_aqc_opc_list_func_caps, NULL); | |
1342 | devm_kfree(ice_hw_to_dev(hw), cbuf); | |
1343 | ||
1344 | if (!status || hw->adminq.sq_last_status != ICE_AQ_RC_ENOMEM) | |
1345 | break; | |
1346 | ||
1347 | /* If ENOMEM is returned, try again with bigger buffer */ | |
1348 | cbuf_len = data_size; | |
1349 | } while (--retries); | |
1350 | ||
1351 | return status; | |
1352 | } | |
1353 | ||
e94d4478 AV |
1354 | /** |
1355 | * ice_aq_manage_mac_write - manage MAC address write command | |
1356 | * @hw: pointer to the hw struct | |
1357 | * @mac_addr: MAC address to be written as LAA/LAA+WoL/Port address | |
1358 | * @flags: flags to control write behavior | |
1359 | * @cd: pointer to command details structure or NULL | |
1360 | * | |
1361 | * This function is used to write MAC address to the NVM (0x0108). | |
1362 | */ | |
1363 | enum ice_status | |
1364 | ice_aq_manage_mac_write(struct ice_hw *hw, u8 *mac_addr, u8 flags, | |
1365 | struct ice_sq_cd *cd) | |
1366 | { | |
1367 | struct ice_aqc_manage_mac_write *cmd; | |
1368 | struct ice_aq_desc desc; | |
1369 | ||
1370 | cmd = &desc.params.mac_write; | |
1371 | ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_manage_mac_write); | |
1372 | ||
1373 | cmd->flags = flags; | |
1374 | ||
1375 | /* Prep values for flags, sah, sal */ | |
1376 | cmd->sah = htons(*((u16 *)mac_addr)); | |
1377 | cmd->sal = htonl(*((u32 *)(mac_addr + 2))); | |
1378 | ||
1379 | return ice_aq_send_cmd(hw, &desc, NULL, 0, cd); | |
1380 | } | |
1381 | ||
f31e4b6f AV |
1382 | /** |
1383 | * ice_aq_clear_pxe_mode | |
1384 | * @hw: pointer to the hw struct | |
1385 | * | |
1386 | * Tell the firmware that the driver is taking over from PXE (0x0110). | |
1387 | */ | |
1388 | static enum ice_status ice_aq_clear_pxe_mode(struct ice_hw *hw) | |
1389 | { | |
1390 | struct ice_aq_desc desc; | |
1391 | ||
1392 | ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_clear_pxe_mode); | |
1393 | desc.params.clear_pxe.rx_cnt = ICE_AQC_CLEAR_PXE_RX_CNT; | |
1394 | ||
1395 | return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL); | |
1396 | } | |
1397 | ||
1398 | /** | |
1399 | * ice_clear_pxe_mode - clear pxe operations mode | |
1400 | * @hw: pointer to the hw struct | |
1401 | * | |
1402 | * Make sure all PXE mode settings are cleared, including things | |
1403 | * like descriptor fetch/write-back mode. | |
1404 | */ | |
1405 | void ice_clear_pxe_mode(struct ice_hw *hw) | |
1406 | { | |
1407 | if (ice_check_sq_alive(hw, &hw->adminq)) | |
1408 | ice_aq_clear_pxe_mode(hw); | |
1409 | } | |
cdedef59 | 1410 | |
48cb27f2 CC |
1411 | /** |
1412 | * ice_get_link_speed_based_on_phy_type - returns link speed | |
1413 | * @phy_type_low: lower part of phy_type | |
1414 | * | |
1415 | * This helper function will convert a phy_type_low to its corresponding link | |
1416 | * speed. | |
1417 | * Note: In the structure of phy_type_low, there should be one bit set, as | |
1418 | * this function will convert one phy type to its speed. | |
1419 | * If no bit gets set, ICE_LINK_SPEED_UNKNOWN will be returned | |
1420 | * If more than one bit gets set, ICE_LINK_SPEED_UNKNOWN will be returned | |
1421 | */ | |
1422 | static u16 | |
1423 | ice_get_link_speed_based_on_phy_type(u64 phy_type_low) | |
1424 | { | |
1425 | u16 speed_phy_type_low = ICE_AQ_LINK_SPEED_UNKNOWN; | |
1426 | ||
1427 | switch (phy_type_low) { | |
1428 | case ICE_PHY_TYPE_LOW_100BASE_TX: | |
1429 | case ICE_PHY_TYPE_LOW_100M_SGMII: | |
1430 | speed_phy_type_low = ICE_AQ_LINK_SPEED_100MB; | |
1431 | break; | |
1432 | case ICE_PHY_TYPE_LOW_1000BASE_T: | |
1433 | case ICE_PHY_TYPE_LOW_1000BASE_SX: | |
1434 | case ICE_PHY_TYPE_LOW_1000BASE_LX: | |
1435 | case ICE_PHY_TYPE_LOW_1000BASE_KX: | |
1436 | case ICE_PHY_TYPE_LOW_1G_SGMII: | |
1437 | speed_phy_type_low = ICE_AQ_LINK_SPEED_1000MB; | |
1438 | break; | |
1439 | case ICE_PHY_TYPE_LOW_2500BASE_T: | |
1440 | case ICE_PHY_TYPE_LOW_2500BASE_X: | |
1441 | case ICE_PHY_TYPE_LOW_2500BASE_KX: | |
1442 | speed_phy_type_low = ICE_AQ_LINK_SPEED_2500MB; | |
1443 | break; | |
1444 | case ICE_PHY_TYPE_LOW_5GBASE_T: | |
1445 | case ICE_PHY_TYPE_LOW_5GBASE_KR: | |
1446 | speed_phy_type_low = ICE_AQ_LINK_SPEED_5GB; | |
1447 | break; | |
1448 | case ICE_PHY_TYPE_LOW_10GBASE_T: | |
1449 | case ICE_PHY_TYPE_LOW_10G_SFI_DA: | |
1450 | case ICE_PHY_TYPE_LOW_10GBASE_SR: | |
1451 | case ICE_PHY_TYPE_LOW_10GBASE_LR: | |
1452 | case ICE_PHY_TYPE_LOW_10GBASE_KR_CR1: | |
1453 | case ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC: | |
1454 | case ICE_PHY_TYPE_LOW_10G_SFI_C2C: | |
1455 | speed_phy_type_low = ICE_AQ_LINK_SPEED_10GB; | |
1456 | break; | |
1457 | case ICE_PHY_TYPE_LOW_25GBASE_T: | |
1458 | case ICE_PHY_TYPE_LOW_25GBASE_CR: | |
1459 | case ICE_PHY_TYPE_LOW_25GBASE_CR_S: | |
1460 | case ICE_PHY_TYPE_LOW_25GBASE_CR1: | |
1461 | case ICE_PHY_TYPE_LOW_25GBASE_SR: | |
1462 | case ICE_PHY_TYPE_LOW_25GBASE_LR: | |
1463 | case ICE_PHY_TYPE_LOW_25GBASE_KR: | |
1464 | case ICE_PHY_TYPE_LOW_25GBASE_KR_S: | |
1465 | case ICE_PHY_TYPE_LOW_25GBASE_KR1: | |
1466 | case ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC: | |
1467 | case ICE_PHY_TYPE_LOW_25G_AUI_C2C: | |
1468 | speed_phy_type_low = ICE_AQ_LINK_SPEED_25GB; | |
1469 | break; | |
1470 | case ICE_PHY_TYPE_LOW_40GBASE_CR4: | |
1471 | case ICE_PHY_TYPE_LOW_40GBASE_SR4: | |
1472 | case ICE_PHY_TYPE_LOW_40GBASE_LR4: | |
1473 | case ICE_PHY_TYPE_LOW_40GBASE_KR4: | |
1474 | case ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC: | |
1475 | case ICE_PHY_TYPE_LOW_40G_XLAUI: | |
1476 | speed_phy_type_low = ICE_AQ_LINK_SPEED_40GB; | |
1477 | break; | |
1478 | default: | |
1479 | speed_phy_type_low = ICE_AQ_LINK_SPEED_UNKNOWN; | |
1480 | break; | |
1481 | } | |
1482 | ||
1483 | return speed_phy_type_low; | |
1484 | } | |
1485 | ||
1486 | /** | |
1487 | * ice_update_phy_type | |
1488 | * @phy_type_low: pointer to the lower part of phy_type | |
1489 | * @link_speeds_bitmap: targeted link speeds bitmap | |
1490 | * | |
1491 | * Note: For the link_speeds_bitmap structure, you can check it at | |
1492 | * [ice_aqc_get_link_status->link_speed]. Caller can pass in | |
1493 | * link_speeds_bitmap include multiple speeds. | |
1494 | * | |
1495 | * The value of phy_type_low will present a certain link speed. This helper | |
1496 | * function will turn on bits in the phy_type_low based on the value of | |
1497 | * link_speeds_bitmap input parameter. | |
1498 | */ | |
1499 | void ice_update_phy_type(u64 *phy_type_low, u16 link_speeds_bitmap) | |
1500 | { | |
1501 | u16 speed = ICE_AQ_LINK_SPEED_UNKNOWN; | |
1502 | u64 pt_low; | |
1503 | int index; | |
1504 | ||
1505 | /* We first check with low part of phy_type */ | |
1506 | for (index = 0; index <= ICE_PHY_TYPE_LOW_MAX_INDEX; index++) { | |
1507 | pt_low = BIT_ULL(index); | |
1508 | speed = ice_get_link_speed_based_on_phy_type(pt_low); | |
1509 | ||
1510 | if (link_speeds_bitmap & speed) | |
1511 | *phy_type_low |= BIT_ULL(index); | |
1512 | } | |
1513 | } | |
1514 | ||
fcea6f3d AV |
1515 | /** |
1516 | * ice_aq_set_phy_cfg | |
1517 | * @hw: pointer to the hw struct | |
1518 | * @lport: logical port number | |
1519 | * @cfg: structure with PHY configuration data to be set | |
1520 | * @cd: pointer to command details structure or NULL | |
1521 | * | |
1522 | * Set the various PHY configuration parameters supported on the Port. | |
1523 | * One or more of the Set PHY config parameters may be ignored in an MFP | |
1524 | * mode as the PF may not have the privilege to set some of the PHY Config | |
1525 | * parameters. This status will be indicated by the command response (0x0601). | |
1526 | */ | |
48cb27f2 | 1527 | enum ice_status |
fcea6f3d AV |
1528 | ice_aq_set_phy_cfg(struct ice_hw *hw, u8 lport, |
1529 | struct ice_aqc_set_phy_cfg_data *cfg, struct ice_sq_cd *cd) | |
1530 | { | |
fcea6f3d AV |
1531 | struct ice_aq_desc desc; |
1532 | ||
1533 | if (!cfg) | |
1534 | return ICE_ERR_PARAM; | |
1535 | ||
fcea6f3d | 1536 | ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_phy_cfg); |
48cb27f2 CC |
1537 | desc.params.set_phy.lport_num = lport; |
1538 | desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD); | |
fcea6f3d AV |
1539 | |
1540 | return ice_aq_send_cmd(hw, &desc, cfg, sizeof(*cfg), cd); | |
1541 | } | |
1542 | ||
1543 | /** | |
1544 | * ice_update_link_info - update status of the HW network link | |
1545 | * @pi: port info structure of the interested logical port | |
1546 | */ | |
1547 | static enum ice_status | |
1548 | ice_update_link_info(struct ice_port_info *pi) | |
1549 | { | |
1550 | struct ice_aqc_get_phy_caps_data *pcaps; | |
1551 | struct ice_phy_info *phy_info; | |
1552 | enum ice_status status; | |
1553 | struct ice_hw *hw; | |
1554 | ||
1555 | if (!pi) | |
1556 | return ICE_ERR_PARAM; | |
1557 | ||
1558 | hw = pi->hw; | |
1559 | ||
1560 | pcaps = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*pcaps), GFP_KERNEL); | |
1561 | if (!pcaps) | |
1562 | return ICE_ERR_NO_MEMORY; | |
1563 | ||
1564 | phy_info = &pi->phy; | |
1565 | status = ice_aq_get_link_info(pi, true, NULL, NULL); | |
1566 | if (status) | |
1567 | goto out; | |
1568 | ||
1569 | if (phy_info->link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) { | |
1570 | status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, | |
1571 | pcaps, NULL); | |
1572 | if (status) | |
1573 | goto out; | |
1574 | ||
1575 | memcpy(phy_info->link_info.module_type, &pcaps->module_type, | |
1576 | sizeof(phy_info->link_info.module_type)); | |
1577 | } | |
1578 | out: | |
1579 | devm_kfree(ice_hw_to_dev(hw), pcaps); | |
1580 | return status; | |
1581 | } | |
1582 | ||
1583 | /** | |
1584 | * ice_set_fc | |
1585 | * @pi: port information structure | |
1586 | * @aq_failures: pointer to status code, specific to ice_set_fc routine | |
48cb27f2 | 1587 | * @ena_auto_link_update: enable automatic link update |
fcea6f3d AV |
1588 | * |
1589 | * Set the requested flow control mode. | |
1590 | */ | |
1591 | enum ice_status | |
48cb27f2 | 1592 | ice_set_fc(struct ice_port_info *pi, u8 *aq_failures, bool ena_auto_link_update) |
fcea6f3d AV |
1593 | { |
1594 | struct ice_aqc_set_phy_cfg_data cfg = { 0 }; | |
1595 | struct ice_aqc_get_phy_caps_data *pcaps; | |
1596 | enum ice_status status; | |
1597 | u8 pause_mask = 0x0; | |
1598 | struct ice_hw *hw; | |
1599 | ||
1600 | if (!pi) | |
1601 | return ICE_ERR_PARAM; | |
1602 | hw = pi->hw; | |
1603 | *aq_failures = ICE_SET_FC_AQ_FAIL_NONE; | |
1604 | ||
1605 | switch (pi->fc.req_mode) { | |
1606 | case ICE_FC_FULL: | |
1607 | pause_mask |= ICE_AQC_PHY_EN_TX_LINK_PAUSE; | |
1608 | pause_mask |= ICE_AQC_PHY_EN_RX_LINK_PAUSE; | |
1609 | break; | |
1610 | case ICE_FC_RX_PAUSE: | |
1611 | pause_mask |= ICE_AQC_PHY_EN_RX_LINK_PAUSE; | |
1612 | break; | |
1613 | case ICE_FC_TX_PAUSE: | |
1614 | pause_mask |= ICE_AQC_PHY_EN_TX_LINK_PAUSE; | |
1615 | break; | |
1616 | default: | |
1617 | break; | |
1618 | } | |
1619 | ||
1620 | pcaps = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*pcaps), GFP_KERNEL); | |
1621 | if (!pcaps) | |
1622 | return ICE_ERR_NO_MEMORY; | |
1623 | ||
1624 | /* Get the current phy config */ | |
1625 | status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps, | |
1626 | NULL); | |
1627 | if (status) { | |
1628 | *aq_failures = ICE_SET_FC_AQ_FAIL_GET; | |
1629 | goto out; | |
1630 | } | |
1631 | ||
1632 | /* clear the old pause settings */ | |
1633 | cfg.caps = pcaps->caps & ~(ICE_AQC_PHY_EN_TX_LINK_PAUSE | | |
1634 | ICE_AQC_PHY_EN_RX_LINK_PAUSE); | |
1635 | /* set the new capabilities */ | |
1636 | cfg.caps |= pause_mask; | |
1637 | /* If the capabilities have changed, then set the new config */ | |
1638 | if (cfg.caps != pcaps->caps) { | |
1639 | int retry_count, retry_max = 10; | |
1640 | ||
1641 | /* Auto restart link so settings take effect */ | |
48cb27f2 CC |
1642 | if (ena_auto_link_update) |
1643 | cfg.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT; | |
fcea6f3d AV |
1644 | /* Copy over all the old settings */ |
1645 | cfg.phy_type_low = pcaps->phy_type_low; | |
1646 | cfg.low_power_ctrl = pcaps->low_power_ctrl; | |
1647 | cfg.eee_cap = pcaps->eee_cap; | |
1648 | cfg.eeer_value = pcaps->eeer_value; | |
1649 | cfg.link_fec_opt = pcaps->link_fec_options; | |
1650 | ||
1651 | status = ice_aq_set_phy_cfg(hw, pi->lport, &cfg, NULL); | |
1652 | if (status) { | |
1653 | *aq_failures = ICE_SET_FC_AQ_FAIL_SET; | |
1654 | goto out; | |
1655 | } | |
1656 | ||
1657 | /* Update the link info | |
1658 | * It sometimes takes a really long time for link to | |
1659 | * come back from the atomic reset. Thus, we wait a | |
1660 | * little bit. | |
1661 | */ | |
1662 | for (retry_count = 0; retry_count < retry_max; retry_count++) { | |
1663 | status = ice_update_link_info(pi); | |
1664 | ||
1665 | if (!status) | |
1666 | break; | |
1667 | ||
1668 | mdelay(100); | |
1669 | } | |
1670 | ||
1671 | if (status) | |
1672 | *aq_failures = ICE_SET_FC_AQ_FAIL_UPDATE; | |
1673 | } | |
1674 | ||
1675 | out: | |
1676 | devm_kfree(ice_hw_to_dev(hw), pcaps); | |
1677 | return status; | |
1678 | } | |
1679 | ||
0b28b702 AV |
1680 | /** |
1681 | * ice_get_link_status - get status of the HW network link | |
1682 | * @pi: port information structure | |
1683 | * @link_up: pointer to bool (true/false = linkup/linkdown) | |
1684 | * | |
1685 | * Variable link_up is true if link is up, false if link is down. | |
1686 | * The variable link_up is invalid if status is non zero. As a | |
1687 | * result of this call, link status reporting becomes enabled | |
1688 | */ | |
1689 | enum ice_status ice_get_link_status(struct ice_port_info *pi, bool *link_up) | |
1690 | { | |
1691 | struct ice_phy_info *phy_info; | |
1692 | enum ice_status status = 0; | |
1693 | ||
c7f2c42b | 1694 | if (!pi || !link_up) |
0b28b702 AV |
1695 | return ICE_ERR_PARAM; |
1696 | ||
1697 | phy_info = &pi->phy; | |
1698 | ||
1699 | if (phy_info->get_link_info) { | |
1700 | status = ice_update_link_info(pi); | |
1701 | ||
1702 | if (status) | |
1703 | ice_debug(pi->hw, ICE_DBG_LINK, | |
1704 | "get link status error, status = %d\n", | |
1705 | status); | |
1706 | } | |
1707 | ||
1708 | *link_up = phy_info->link_info.link_info & ICE_AQ_LINK_UP; | |
1709 | ||
1710 | return status; | |
1711 | } | |
1712 | ||
fcea6f3d AV |
1713 | /** |
1714 | * ice_aq_set_link_restart_an | |
1715 | * @pi: pointer to the port information structure | |
1716 | * @ena_link: if true: enable link, if false: disable link | |
1717 | * @cd: pointer to command details structure or NULL | |
1718 | * | |
1719 | * Sets up the link and restarts the Auto-Negotiation over the link. | |
1720 | */ | |
1721 | enum ice_status | |
1722 | ice_aq_set_link_restart_an(struct ice_port_info *pi, bool ena_link, | |
1723 | struct ice_sq_cd *cd) | |
1724 | { | |
1725 | struct ice_aqc_restart_an *cmd; | |
1726 | struct ice_aq_desc desc; | |
1727 | ||
1728 | cmd = &desc.params.restart_an; | |
1729 | ||
1730 | ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_restart_an); | |
1731 | ||
1732 | cmd->cmd_flags = ICE_AQC_RESTART_AN_LINK_RESTART; | |
1733 | cmd->lport_num = pi->lport; | |
1734 | if (ena_link) | |
1735 | cmd->cmd_flags |= ICE_AQC_RESTART_AN_LINK_ENABLE; | |
1736 | else | |
1737 | cmd->cmd_flags &= ~ICE_AQC_RESTART_AN_LINK_ENABLE; | |
1738 | ||
1739 | return ice_aq_send_cmd(pi->hw, &desc, NULL, 0, cd); | |
1740 | } | |
1741 | ||
0b28b702 AV |
1742 | /** |
1743 | * ice_aq_set_event_mask | |
1744 | * @hw: pointer to the hw struct | |
1745 | * @port_num: port number of the physical function | |
1746 | * @mask: event mask to be set | |
1747 | * @cd: pointer to command details structure or NULL | |
1748 | * | |
1749 | * Set event mask (0x0613) | |
1750 | */ | |
1751 | enum ice_status | |
1752 | ice_aq_set_event_mask(struct ice_hw *hw, u8 port_num, u16 mask, | |
1753 | struct ice_sq_cd *cd) | |
1754 | { | |
1755 | struct ice_aqc_set_event_mask *cmd; | |
1756 | struct ice_aq_desc desc; | |
1757 | ||
1758 | cmd = &desc.params.set_event_mask; | |
1759 | ||
1760 | ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_event_mask); | |
1761 | ||
1762 | cmd->lport_num = port_num; | |
1763 | ||
1764 | cmd->event_mask = cpu_to_le16(mask); | |
1765 | ||
1766 | return ice_aq_send_cmd(hw, &desc, NULL, 0, cd); | |
1767 | } | |
1768 | ||
d76a60ba AV |
1769 | /** |
1770 | * __ice_aq_get_set_rss_lut | |
1771 | * @hw: pointer to the hardware structure | |
1772 | * @vsi_id: VSI FW index | |
1773 | * @lut_type: LUT table type | |
1774 | * @lut: pointer to the LUT buffer provided by the caller | |
1775 | * @lut_size: size of the LUT buffer | |
1776 | * @glob_lut_idx: global LUT index | |
1777 | * @set: set true to set the table, false to get the table | |
1778 | * | |
1779 | * Internal function to get (0x0B05) or set (0x0B03) RSS look up table | |
1780 | */ | |
1781 | static enum ice_status | |
1782 | __ice_aq_get_set_rss_lut(struct ice_hw *hw, u16 vsi_id, u8 lut_type, u8 *lut, | |
1783 | u16 lut_size, u8 glob_lut_idx, bool set) | |
1784 | { | |
1785 | struct ice_aqc_get_set_rss_lut *cmd_resp; | |
1786 | struct ice_aq_desc desc; | |
1787 | enum ice_status status; | |
1788 | u16 flags = 0; | |
1789 | ||
1790 | cmd_resp = &desc.params.get_set_rss_lut; | |
1791 | ||
1792 | if (set) { | |
1793 | ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_rss_lut); | |
1794 | desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD); | |
1795 | } else { | |
1796 | ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_rss_lut); | |
1797 | } | |
1798 | ||
1799 | cmd_resp->vsi_id = cpu_to_le16(((vsi_id << | |
1800 | ICE_AQC_GSET_RSS_LUT_VSI_ID_S) & | |
1801 | ICE_AQC_GSET_RSS_LUT_VSI_ID_M) | | |
1802 | ICE_AQC_GSET_RSS_LUT_VSI_VALID); | |
1803 | ||
1804 | switch (lut_type) { | |
1805 | case ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_VSI: | |
1806 | case ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF: | |
1807 | case ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_GLOBAL: | |
1808 | flags |= ((lut_type << ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_S) & | |
1809 | ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_M); | |
1810 | break; | |
1811 | default: | |
1812 | status = ICE_ERR_PARAM; | |
1813 | goto ice_aq_get_set_rss_lut_exit; | |
1814 | } | |
1815 | ||
1816 | if (lut_type == ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_GLOBAL) { | |
1817 | flags |= ((glob_lut_idx << ICE_AQC_GSET_RSS_LUT_GLOBAL_IDX_S) & | |
1818 | ICE_AQC_GSET_RSS_LUT_GLOBAL_IDX_M); | |
1819 | ||
1820 | if (!set) | |
1821 | goto ice_aq_get_set_rss_lut_send; | |
1822 | } else if (lut_type == ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF) { | |
1823 | if (!set) | |
1824 | goto ice_aq_get_set_rss_lut_send; | |
1825 | } else { | |
1826 | goto ice_aq_get_set_rss_lut_send; | |
1827 | } | |
1828 | ||
1829 | /* LUT size is only valid for Global and PF table types */ | |
4381147d AV |
1830 | switch (lut_size) { |
1831 | case ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_128: | |
1832 | break; | |
1833 | case ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_512: | |
d76a60ba AV |
1834 | flags |= (ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_512_FLAG << |
1835 | ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_S) & | |
1836 | ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_M; | |
4381147d AV |
1837 | break; |
1838 | case ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K: | |
1839 | if (lut_type == ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF) { | |
1840 | flags |= (ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K_FLAG << | |
1841 | ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_S) & | |
1842 | ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_M; | |
1843 | break; | |
1844 | } | |
1845 | /* fall-through */ | |
1846 | default: | |
d76a60ba AV |
1847 | status = ICE_ERR_PARAM; |
1848 | goto ice_aq_get_set_rss_lut_exit; | |
1849 | } | |
1850 | ||
1851 | ice_aq_get_set_rss_lut_send: | |
1852 | cmd_resp->flags = cpu_to_le16(flags); | |
1853 | status = ice_aq_send_cmd(hw, &desc, lut, lut_size, NULL); | |
1854 | ||
1855 | ice_aq_get_set_rss_lut_exit: | |
1856 | return status; | |
1857 | } | |
1858 | ||
1859 | /** | |
1860 | * ice_aq_get_rss_lut | |
1861 | * @hw: pointer to the hardware structure | |
1862 | * @vsi_id: VSI FW index | |
1863 | * @lut_type: LUT table type | |
1864 | * @lut: pointer to the LUT buffer provided by the caller | |
1865 | * @lut_size: size of the LUT buffer | |
1866 | * | |
1867 | * get the RSS lookup table, PF or VSI type | |
1868 | */ | |
1869 | enum ice_status | |
1870 | ice_aq_get_rss_lut(struct ice_hw *hw, u16 vsi_id, u8 lut_type, u8 *lut, | |
1871 | u16 lut_size) | |
1872 | { | |
1873 | return __ice_aq_get_set_rss_lut(hw, vsi_id, lut_type, lut, lut_size, 0, | |
1874 | false); | |
1875 | } | |
1876 | ||
1877 | /** | |
1878 | * ice_aq_set_rss_lut | |
1879 | * @hw: pointer to the hardware structure | |
1880 | * @vsi_id: VSI FW index | |
1881 | * @lut_type: LUT table type | |
1882 | * @lut: pointer to the LUT buffer provided by the caller | |
1883 | * @lut_size: size of the LUT buffer | |
1884 | * | |
1885 | * set the RSS lookup table, PF or VSI type | |
1886 | */ | |
1887 | enum ice_status | |
1888 | ice_aq_set_rss_lut(struct ice_hw *hw, u16 vsi_id, u8 lut_type, u8 *lut, | |
1889 | u16 lut_size) | |
1890 | { | |
1891 | return __ice_aq_get_set_rss_lut(hw, vsi_id, lut_type, lut, lut_size, 0, | |
1892 | true); | |
1893 | } | |
1894 | ||
1895 | /** | |
1896 | * __ice_aq_get_set_rss_key | |
1897 | * @hw: pointer to the hw struct | |
1898 | * @vsi_id: VSI FW index | |
1899 | * @key: pointer to key info struct | |
1900 | * @set: set true to set the key, false to get the key | |
1901 | * | |
1902 | * get (0x0B04) or set (0x0B02) the RSS key per VSI | |
1903 | */ | |
1904 | static enum | |
1905 | ice_status __ice_aq_get_set_rss_key(struct ice_hw *hw, u16 vsi_id, | |
1906 | struct ice_aqc_get_set_rss_keys *key, | |
1907 | bool set) | |
1908 | { | |
1909 | struct ice_aqc_get_set_rss_key *cmd_resp; | |
1910 | u16 key_size = sizeof(*key); | |
1911 | struct ice_aq_desc desc; | |
1912 | ||
1913 | cmd_resp = &desc.params.get_set_rss_key; | |
1914 | ||
1915 | if (set) { | |
1916 | ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_rss_key); | |
1917 | desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD); | |
1918 | } else { | |
1919 | ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_rss_key); | |
1920 | } | |
1921 | ||
1922 | cmd_resp->vsi_id = cpu_to_le16(((vsi_id << | |
1923 | ICE_AQC_GSET_RSS_KEY_VSI_ID_S) & | |
1924 | ICE_AQC_GSET_RSS_KEY_VSI_ID_M) | | |
1925 | ICE_AQC_GSET_RSS_KEY_VSI_VALID); | |
1926 | ||
1927 | return ice_aq_send_cmd(hw, &desc, key, key_size, NULL); | |
1928 | } | |
1929 | ||
1930 | /** | |
1931 | * ice_aq_get_rss_key | |
1932 | * @hw: pointer to the hw struct | |
1933 | * @vsi_id: VSI FW index | |
1934 | * @key: pointer to key info struct | |
1935 | * | |
1936 | * get the RSS key per VSI | |
1937 | */ | |
1938 | enum ice_status | |
1939 | ice_aq_get_rss_key(struct ice_hw *hw, u16 vsi_id, | |
1940 | struct ice_aqc_get_set_rss_keys *key) | |
1941 | { | |
1942 | return __ice_aq_get_set_rss_key(hw, vsi_id, key, false); | |
1943 | } | |
1944 | ||
1945 | /** | |
1946 | * ice_aq_set_rss_key | |
1947 | * @hw: pointer to the hw struct | |
1948 | * @vsi_id: VSI FW index | |
1949 | * @keys: pointer to key info struct | |
1950 | * | |
1951 | * set the RSS key per VSI | |
1952 | */ | |
1953 | enum ice_status | |
1954 | ice_aq_set_rss_key(struct ice_hw *hw, u16 vsi_id, | |
1955 | struct ice_aqc_get_set_rss_keys *keys) | |
1956 | { | |
1957 | return __ice_aq_get_set_rss_key(hw, vsi_id, keys, true); | |
1958 | } | |
1959 | ||
cdedef59 AV |
1960 | /** |
1961 | * ice_aq_add_lan_txq | |
1962 | * @hw: pointer to the hardware structure | |
1963 | * @num_qgrps: Number of added queue groups | |
1964 | * @qg_list: list of queue groups to be added | |
1965 | * @buf_size: size of buffer for indirect command | |
1966 | * @cd: pointer to command details structure or NULL | |
1967 | * | |
1968 | * Add Tx LAN queue (0x0C30) | |
1969 | * | |
1970 | * NOTE: | |
1971 | * Prior to calling add Tx LAN queue: | |
1972 | * Initialize the following as part of the Tx queue context: | |
1973 | * Completion queue ID if the queue uses Completion queue, Quanta profile, | |
1974 | * Cache profile and Packet shaper profile. | |
1975 | * | |
1976 | * After add Tx LAN queue AQ command is completed: | |
1977 | * Interrupts should be associated with specific queues, | |
1978 | * Association of Tx queue to Doorbell queue is not part of Add LAN Tx queue | |
1979 | * flow. | |
1980 | */ | |
1981 | static enum ice_status | |
1982 | ice_aq_add_lan_txq(struct ice_hw *hw, u8 num_qgrps, | |
1983 | struct ice_aqc_add_tx_qgrp *qg_list, u16 buf_size, | |
1984 | struct ice_sq_cd *cd) | |
1985 | { | |
1986 | u16 i, sum_header_size, sum_q_size = 0; | |
1987 | struct ice_aqc_add_tx_qgrp *list; | |
1988 | struct ice_aqc_add_txqs *cmd; | |
1989 | struct ice_aq_desc desc; | |
1990 | ||
1991 | cmd = &desc.params.add_txqs; | |
1992 | ||
1993 | ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_add_txqs); | |
1994 | ||
1995 | if (!qg_list) | |
1996 | return ICE_ERR_PARAM; | |
1997 | ||
1998 | if (num_qgrps > ICE_LAN_TXQ_MAX_QGRPS) | |
1999 | return ICE_ERR_PARAM; | |
2000 | ||
2001 | sum_header_size = num_qgrps * | |
2002 | (sizeof(*qg_list) - sizeof(*qg_list->txqs)); | |
2003 | ||
2004 | list = qg_list; | |
2005 | for (i = 0; i < num_qgrps; i++) { | |
2006 | struct ice_aqc_add_txqs_perq *q = list->txqs; | |
2007 | ||
2008 | sum_q_size += list->num_txqs * sizeof(*q); | |
2009 | list = (struct ice_aqc_add_tx_qgrp *)(q + list->num_txqs); | |
2010 | } | |
2011 | ||
2012 | if (buf_size != (sum_header_size + sum_q_size)) | |
2013 | return ICE_ERR_PARAM; | |
2014 | ||
2015 | desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD); | |
2016 | ||
2017 | cmd->num_qgrps = num_qgrps; | |
2018 | ||
2019 | return ice_aq_send_cmd(hw, &desc, qg_list, buf_size, cd); | |
2020 | } | |
2021 | ||
2022 | /** | |
2023 | * ice_aq_dis_lan_txq | |
2024 | * @hw: pointer to the hardware structure | |
2025 | * @num_qgrps: number of groups in the list | |
2026 | * @qg_list: the list of groups to disable | |
2027 | * @buf_size: the total size of the qg_list buffer in bytes | |
2028 | * @cd: pointer to command details structure or NULL | |
2029 | * | |
2030 | * Disable LAN Tx queue (0x0C31) | |
2031 | */ | |
2032 | static enum ice_status | |
2033 | ice_aq_dis_lan_txq(struct ice_hw *hw, u8 num_qgrps, | |
2034 | struct ice_aqc_dis_txq_item *qg_list, u16 buf_size, | |
2035 | struct ice_sq_cd *cd) | |
2036 | { | |
2037 | struct ice_aqc_dis_txqs *cmd; | |
2038 | struct ice_aq_desc desc; | |
2039 | u16 i, sz = 0; | |
2040 | ||
2041 | cmd = &desc.params.dis_txqs; | |
2042 | ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_dis_txqs); | |
2043 | ||
2044 | if (!qg_list) | |
2045 | return ICE_ERR_PARAM; | |
2046 | ||
2047 | if (num_qgrps > ICE_LAN_TXQ_MAX_QGRPS) | |
2048 | return ICE_ERR_PARAM; | |
2049 | desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD); | |
2050 | cmd->num_entries = num_qgrps; | |
2051 | ||
2052 | for (i = 0; i < num_qgrps; ++i) { | |
2053 | /* Calculate the size taken up by the queue IDs in this group */ | |
2054 | sz += qg_list[i].num_qs * sizeof(qg_list[i].q_id); | |
2055 | ||
2056 | /* Add the size of the group header */ | |
2057 | sz += sizeof(qg_list[i]) - sizeof(qg_list[i].q_id); | |
2058 | ||
2059 | /* If the num of queues is even, add 2 bytes of padding */ | |
2060 | if ((qg_list[i].num_qs % 2) == 0) | |
2061 | sz += 2; | |
2062 | } | |
2063 | ||
2064 | if (buf_size != sz) | |
2065 | return ICE_ERR_PARAM; | |
2066 | ||
2067 | return ice_aq_send_cmd(hw, &desc, qg_list, buf_size, cd); | |
2068 | } | |
2069 | ||
2070 | /* End of FW Admin Queue command wrappers */ | |
2071 | ||
2072 | /** | |
2073 | * ice_write_byte - write a byte to a packed context structure | |
2074 | * @src_ctx: the context structure to read from | |
2075 | * @dest_ctx: the context to be written to | |
2076 | * @ce_info: a description of the struct to be filled | |
2077 | */ | |
2078 | static void ice_write_byte(u8 *src_ctx, u8 *dest_ctx, | |
2079 | const struct ice_ctx_ele *ce_info) | |
2080 | { | |
2081 | u8 src_byte, dest_byte, mask; | |
2082 | u8 *from, *dest; | |
2083 | u16 shift_width; | |
2084 | ||
2085 | /* copy from the next struct field */ | |
2086 | from = src_ctx + ce_info->offset; | |
2087 | ||
2088 | /* prepare the bits and mask */ | |
2089 | shift_width = ce_info->lsb % 8; | |
2090 | mask = (u8)(BIT(ce_info->width) - 1); | |
2091 | ||
2092 | src_byte = *from; | |
2093 | src_byte &= mask; | |
2094 | ||
2095 | /* shift to correct alignment */ | |
2096 | mask <<= shift_width; | |
2097 | src_byte <<= shift_width; | |
2098 | ||
2099 | /* get the current bits from the target bit string */ | |
2100 | dest = dest_ctx + (ce_info->lsb / 8); | |
2101 | ||
2102 | memcpy(&dest_byte, dest, sizeof(dest_byte)); | |
2103 | ||
2104 | dest_byte &= ~mask; /* get the bits not changing */ | |
2105 | dest_byte |= src_byte; /* add in the new bits */ | |
2106 | ||
2107 | /* put it all back */ | |
2108 | memcpy(dest, &dest_byte, sizeof(dest_byte)); | |
2109 | } | |
2110 | ||
2111 | /** | |
2112 | * ice_write_word - write a word to a packed context structure | |
2113 | * @src_ctx: the context structure to read from | |
2114 | * @dest_ctx: the context to be written to | |
2115 | * @ce_info: a description of the struct to be filled | |
2116 | */ | |
2117 | static void ice_write_word(u8 *src_ctx, u8 *dest_ctx, | |
2118 | const struct ice_ctx_ele *ce_info) | |
2119 | { | |
2120 | u16 src_word, mask; | |
2121 | __le16 dest_word; | |
2122 | u8 *from, *dest; | |
2123 | u16 shift_width; | |
2124 | ||
2125 | /* copy from the next struct field */ | |
2126 | from = src_ctx + ce_info->offset; | |
2127 | ||
2128 | /* prepare the bits and mask */ | |
2129 | shift_width = ce_info->lsb % 8; | |
2130 | mask = BIT(ce_info->width) - 1; | |
2131 | ||
2132 | /* don't swizzle the bits until after the mask because the mask bits | |
2133 | * will be in a different bit position on big endian machines | |
2134 | */ | |
2135 | src_word = *(u16 *)from; | |
2136 | src_word &= mask; | |
2137 | ||
2138 | /* shift to correct alignment */ | |
2139 | mask <<= shift_width; | |
2140 | src_word <<= shift_width; | |
2141 | ||
2142 | /* get the current bits from the target bit string */ | |
2143 | dest = dest_ctx + (ce_info->lsb / 8); | |
2144 | ||
2145 | memcpy(&dest_word, dest, sizeof(dest_word)); | |
2146 | ||
2147 | dest_word &= ~(cpu_to_le16(mask)); /* get the bits not changing */ | |
2148 | dest_word |= cpu_to_le16(src_word); /* add in the new bits */ | |
2149 | ||
2150 | /* put it all back */ | |
2151 | memcpy(dest, &dest_word, sizeof(dest_word)); | |
2152 | } | |
2153 | ||
2154 | /** | |
2155 | * ice_write_dword - write a dword to a packed context structure | |
2156 | * @src_ctx: the context structure to read from | |
2157 | * @dest_ctx: the context to be written to | |
2158 | * @ce_info: a description of the struct to be filled | |
2159 | */ | |
2160 | static void ice_write_dword(u8 *src_ctx, u8 *dest_ctx, | |
2161 | const struct ice_ctx_ele *ce_info) | |
2162 | { | |
2163 | u32 src_dword, mask; | |
2164 | __le32 dest_dword; | |
2165 | u8 *from, *dest; | |
2166 | u16 shift_width; | |
2167 | ||
2168 | /* copy from the next struct field */ | |
2169 | from = src_ctx + ce_info->offset; | |
2170 | ||
2171 | /* prepare the bits and mask */ | |
2172 | shift_width = ce_info->lsb % 8; | |
2173 | ||
2174 | /* if the field width is exactly 32 on an x86 machine, then the shift | |
2175 | * operation will not work because the SHL instructions count is masked | |
2176 | * to 5 bits so the shift will do nothing | |
2177 | */ | |
2178 | if (ce_info->width < 32) | |
2179 | mask = BIT(ce_info->width) - 1; | |
2180 | else | |
2181 | mask = (u32)~0; | |
2182 | ||
2183 | /* don't swizzle the bits until after the mask because the mask bits | |
2184 | * will be in a different bit position on big endian machines | |
2185 | */ | |
2186 | src_dword = *(u32 *)from; | |
2187 | src_dword &= mask; | |
2188 | ||
2189 | /* shift to correct alignment */ | |
2190 | mask <<= shift_width; | |
2191 | src_dword <<= shift_width; | |
2192 | ||
2193 | /* get the current bits from the target bit string */ | |
2194 | dest = dest_ctx + (ce_info->lsb / 8); | |
2195 | ||
2196 | memcpy(&dest_dword, dest, sizeof(dest_dword)); | |
2197 | ||
2198 | dest_dword &= ~(cpu_to_le32(mask)); /* get the bits not changing */ | |
2199 | dest_dword |= cpu_to_le32(src_dword); /* add in the new bits */ | |
2200 | ||
2201 | /* put it all back */ | |
2202 | memcpy(dest, &dest_dword, sizeof(dest_dword)); | |
2203 | } | |
2204 | ||
2205 | /** | |
2206 | * ice_write_qword - write a qword to a packed context structure | |
2207 | * @src_ctx: the context structure to read from | |
2208 | * @dest_ctx: the context to be written to | |
2209 | * @ce_info: a description of the struct to be filled | |
2210 | */ | |
2211 | static void ice_write_qword(u8 *src_ctx, u8 *dest_ctx, | |
2212 | const struct ice_ctx_ele *ce_info) | |
2213 | { | |
2214 | u64 src_qword, mask; | |
2215 | __le64 dest_qword; | |
2216 | u8 *from, *dest; | |
2217 | u16 shift_width; | |
2218 | ||
2219 | /* copy from the next struct field */ | |
2220 | from = src_ctx + ce_info->offset; | |
2221 | ||
2222 | /* prepare the bits and mask */ | |
2223 | shift_width = ce_info->lsb % 8; | |
2224 | ||
2225 | /* if the field width is exactly 64 on an x86 machine, then the shift | |
2226 | * operation will not work because the SHL instructions count is masked | |
2227 | * to 6 bits so the shift will do nothing | |
2228 | */ | |
2229 | if (ce_info->width < 64) | |
2230 | mask = BIT_ULL(ce_info->width) - 1; | |
2231 | else | |
2232 | mask = (u64)~0; | |
2233 | ||
2234 | /* don't swizzle the bits until after the mask because the mask bits | |
2235 | * will be in a different bit position on big endian machines | |
2236 | */ | |
2237 | src_qword = *(u64 *)from; | |
2238 | src_qword &= mask; | |
2239 | ||
2240 | /* shift to correct alignment */ | |
2241 | mask <<= shift_width; | |
2242 | src_qword <<= shift_width; | |
2243 | ||
2244 | /* get the current bits from the target bit string */ | |
2245 | dest = dest_ctx + (ce_info->lsb / 8); | |
2246 | ||
2247 | memcpy(&dest_qword, dest, sizeof(dest_qword)); | |
2248 | ||
2249 | dest_qword &= ~(cpu_to_le64(mask)); /* get the bits not changing */ | |
2250 | dest_qword |= cpu_to_le64(src_qword); /* add in the new bits */ | |
2251 | ||
2252 | /* put it all back */ | |
2253 | memcpy(dest, &dest_qword, sizeof(dest_qword)); | |
2254 | } | |
2255 | ||
2256 | /** | |
2257 | * ice_set_ctx - set context bits in packed structure | |
2258 | * @src_ctx: pointer to a generic non-packed context structure | |
2259 | * @dest_ctx: pointer to memory for the packed structure | |
2260 | * @ce_info: a description of the structure to be transformed | |
2261 | */ | |
2262 | enum ice_status | |
2263 | ice_set_ctx(u8 *src_ctx, u8 *dest_ctx, const struct ice_ctx_ele *ce_info) | |
2264 | { | |
2265 | int f; | |
2266 | ||
2267 | for (f = 0; ce_info[f].width; f++) { | |
2268 | /* We have to deal with each element of the FW response | |
2269 | * using the correct size so that we are correct regardless | |
2270 | * of the endianness of the machine. | |
2271 | */ | |
2272 | switch (ce_info[f].size_of) { | |
2273 | case sizeof(u8): | |
2274 | ice_write_byte(src_ctx, dest_ctx, &ce_info[f]); | |
2275 | break; | |
2276 | case sizeof(u16): | |
2277 | ice_write_word(src_ctx, dest_ctx, &ce_info[f]); | |
2278 | break; | |
2279 | case sizeof(u32): | |
2280 | ice_write_dword(src_ctx, dest_ctx, &ce_info[f]); | |
2281 | break; | |
2282 | case sizeof(u64): | |
2283 | ice_write_qword(src_ctx, dest_ctx, &ce_info[f]); | |
2284 | break; | |
2285 | default: | |
2286 | return ICE_ERR_INVAL_SIZE; | |
2287 | } | |
2288 | } | |
2289 | ||
2290 | return 0; | |
2291 | } | |
2292 | ||
2293 | /** | |
2294 | * ice_ena_vsi_txq | |
2295 | * @pi: port information structure | |
2296 | * @vsi_id: VSI id | |
2297 | * @tc: tc number | |
2298 | * @num_qgrps: Number of added queue groups | |
2299 | * @buf: list of queue groups to be added | |
2300 | * @buf_size: size of buffer for indirect command | |
2301 | * @cd: pointer to command details structure or NULL | |
2302 | * | |
2303 | * This function adds one lan q | |
2304 | */ | |
2305 | enum ice_status | |
2306 | ice_ena_vsi_txq(struct ice_port_info *pi, u16 vsi_id, u8 tc, u8 num_qgrps, | |
2307 | struct ice_aqc_add_tx_qgrp *buf, u16 buf_size, | |
2308 | struct ice_sq_cd *cd) | |
2309 | { | |
2310 | struct ice_aqc_txsched_elem_data node = { 0 }; | |
2311 | struct ice_sched_node *parent; | |
2312 | enum ice_status status; | |
2313 | struct ice_hw *hw; | |
2314 | ||
2315 | if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY) | |
2316 | return ICE_ERR_CFG; | |
2317 | ||
2318 | if (num_qgrps > 1 || buf->num_txqs > 1) | |
2319 | return ICE_ERR_MAX_LIMIT; | |
2320 | ||
2321 | hw = pi->hw; | |
2322 | ||
2323 | mutex_lock(&pi->sched_lock); | |
2324 | ||
2325 | /* find a parent node */ | |
2326 | parent = ice_sched_get_free_qparent(pi, vsi_id, tc, | |
2327 | ICE_SCHED_NODE_OWNER_LAN); | |
2328 | if (!parent) { | |
2329 | status = ICE_ERR_PARAM; | |
2330 | goto ena_txq_exit; | |
2331 | } | |
2332 | buf->parent_teid = parent->info.node_teid; | |
2333 | node.parent_teid = parent->info.node_teid; | |
2334 | /* Mark that the values in the "generic" section as valid. The default | |
2335 | * value in the "generic" section is zero. This means that : | |
2336 | * - Scheduling mode is Bytes Per Second (BPS), indicated by Bit 0. | |
2337 | * - 0 priority among siblings, indicated by Bit 1-3. | |
2338 | * - WFQ, indicated by Bit 4. | |
2339 | * - 0 Adjustment value is used in PSM credit update flow, indicated by | |
2340 | * Bit 5-6. | |
2341 | * - Bit 7 is reserved. | |
2342 | * Without setting the generic section as valid in valid_sections, the | |
2343 | * Admin Q command will fail with error code ICE_AQ_RC_EINVAL. | |
2344 | */ | |
2345 | buf->txqs[0].info.valid_sections = ICE_AQC_ELEM_VALID_GENERIC; | |
2346 | ||
2347 | /* add the lan q */ | |
2348 | status = ice_aq_add_lan_txq(hw, num_qgrps, buf, buf_size, cd); | |
2349 | if (status) | |
2350 | goto ena_txq_exit; | |
2351 | ||
2352 | node.node_teid = buf->txqs[0].q_teid; | |
2353 | node.data.elem_type = ICE_AQC_ELEM_TYPE_LEAF; | |
2354 | ||
2355 | /* add a leaf node into schduler tree q layer */ | |
2356 | status = ice_sched_add_node(pi, hw->num_tx_sched_layers - 1, &node); | |
2357 | ||
2358 | ena_txq_exit: | |
2359 | mutex_unlock(&pi->sched_lock); | |
2360 | return status; | |
2361 | } | |
2362 | ||
2363 | /** | |
2364 | * ice_dis_vsi_txq | |
2365 | * @pi: port information structure | |
2366 | * @num_queues: number of queues | |
2367 | * @q_ids: pointer to the q_id array | |
2368 | * @q_teids: pointer to queue node teids | |
2369 | * @cd: pointer to command details structure or NULL | |
2370 | * | |
2371 | * This function removes queues and their corresponding nodes in SW DB | |
2372 | */ | |
2373 | enum ice_status | |
2374 | ice_dis_vsi_txq(struct ice_port_info *pi, u8 num_queues, u16 *q_ids, | |
2375 | u32 *q_teids, struct ice_sq_cd *cd) | |
2376 | { | |
2377 | enum ice_status status = ICE_ERR_DOES_NOT_EXIST; | |
2378 | struct ice_aqc_dis_txq_item qg_list; | |
2379 | u16 i; | |
2380 | ||
2381 | if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY) | |
2382 | return ICE_ERR_CFG; | |
2383 | ||
2384 | mutex_lock(&pi->sched_lock); | |
2385 | ||
2386 | for (i = 0; i < num_queues; i++) { | |
2387 | struct ice_sched_node *node; | |
2388 | ||
2389 | node = ice_sched_find_node_by_teid(pi->root, q_teids[i]); | |
2390 | if (!node) | |
2391 | continue; | |
2392 | qg_list.parent_teid = node->info.parent_teid; | |
2393 | qg_list.num_qs = 1; | |
2394 | qg_list.q_id[0] = cpu_to_le16(q_ids[i]); | |
2395 | status = ice_aq_dis_lan_txq(pi->hw, 1, &qg_list, | |
2396 | sizeof(qg_list), cd); | |
2397 | ||
2398 | if (status) | |
2399 | break; | |
2400 | ice_free_sched_node(pi, node); | |
2401 | } | |
2402 | mutex_unlock(&pi->sched_lock); | |
2403 | return status; | |
2404 | } | |
5513b920 AV |
2405 | |
2406 | /** | |
2407 | * ice_cfg_vsi_qs - configure the new/exisiting VSI queues | |
2408 | * @pi: port information structure | |
2409 | * @vsi_id: VSI Id | |
2410 | * @tc_bitmap: TC bitmap | |
2411 | * @maxqs: max queues array per TC | |
2412 | * @owner: lan or rdma | |
2413 | * | |
2414 | * This function adds/updates the VSI queues per TC. | |
2415 | */ | |
2416 | static enum ice_status | |
2417 | ice_cfg_vsi_qs(struct ice_port_info *pi, u16 vsi_id, u8 tc_bitmap, | |
2418 | u16 *maxqs, u8 owner) | |
2419 | { | |
2420 | enum ice_status status = 0; | |
2421 | u8 i; | |
2422 | ||
2423 | if (!pi || pi->port_state != ICE_SCHED_PORT_STATE_READY) | |
2424 | return ICE_ERR_CFG; | |
2425 | ||
2426 | mutex_lock(&pi->sched_lock); | |
2427 | ||
2428 | for (i = 0; i < ICE_MAX_TRAFFIC_CLASS; i++) { | |
2429 | /* configuration is possible only if TC node is present */ | |
2430 | if (!ice_sched_get_tc_node(pi, i)) | |
2431 | continue; | |
2432 | ||
2433 | status = ice_sched_cfg_vsi(pi, vsi_id, i, maxqs[i], owner, | |
2434 | ice_is_tc_ena(tc_bitmap, i)); | |
2435 | if (status) | |
2436 | break; | |
2437 | } | |
2438 | ||
2439 | mutex_unlock(&pi->sched_lock); | |
2440 | return status; | |
2441 | } | |
2442 | ||
2443 | /** | |
2444 | * ice_cfg_vsi_lan - configure VSI lan queues | |
2445 | * @pi: port information structure | |
2446 | * @vsi_id: VSI Id | |
2447 | * @tc_bitmap: TC bitmap | |
2448 | * @max_lanqs: max lan queues array per TC | |
2449 | * | |
2450 | * This function adds/updates the VSI lan queues per TC. | |
2451 | */ | |
2452 | enum ice_status | |
2453 | ice_cfg_vsi_lan(struct ice_port_info *pi, u16 vsi_id, u8 tc_bitmap, | |
2454 | u16 *max_lanqs) | |
2455 | { | |
2456 | return ice_cfg_vsi_qs(pi, vsi_id, tc_bitmap, max_lanqs, | |
2457 | ICE_SCHED_NODE_OWNER_LAN); | |
2458 | } |