1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2020 Intel Corporation
6 #include "ice_adminq_cmd.h"
9 * ice_aq_alloc_acl_tbl - allocate ACL table
10 * @hw: pointer to the HW struct
11 * @tbl: pointer to ice_acl_alloc_tbl struct
12 * @cd: pointer to command details structure or NULL
14 * Allocate ACL table (indirect 0x0C10)
17 ice_aq_alloc_acl_tbl(struct ice_hw *hw, struct ice_acl_alloc_tbl *tbl,
20 struct ice_aqc_acl_alloc_table *cmd;
21 struct ice_aq_desc desc;
23 if (!tbl->act_pairs_per_entry)
26 if (tbl->act_pairs_per_entry > ICE_AQC_MAX_ACTION_MEMORIES)
27 return ICE_ERR_MAX_LIMIT;
29 /* If this is concurrent table, then buffer shall be valid and
30 * contain DependentAllocIDs, 'num_dependent_alloc_ids' should be valid
34 if (!tbl->num_dependent_alloc_ids)
36 if (tbl->num_dependent_alloc_ids >
37 ICE_AQC_MAX_CONCURRENT_ACL_TBL)
38 return ICE_ERR_INVAL_SIZE;
41 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_alloc_acl_tbl);
42 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
44 cmd = &desc.params.alloc_table;
45 cmd->table_width = CPU_TO_LE16(tbl->width * BITS_PER_BYTE);
46 cmd->table_depth = CPU_TO_LE16(tbl->depth);
47 cmd->act_pairs_per_entry = tbl->act_pairs_per_entry;
49 cmd->table_type = tbl->num_dependent_alloc_ids;
51 return ice_aq_send_cmd(hw, &desc, &tbl->buf, sizeof(tbl->buf), cd);
55 * ice_aq_dealloc_acl_tbl - deallocate ACL table
56 * @hw: pointer to the HW struct
57 * @alloc_id: allocation ID of the table being released
58 * @buf: address of indirect data buffer
59 * @cd: pointer to command details structure or NULL
61 * Deallocate ACL table (indirect 0x0C11)
63 * NOTE: This command has no buffer format for command itself but response
64 * format is 'struct ice_aqc_acl_generic', pass ptr to that struct
65 * as 'buf' and its size as 'buf_size'
68 ice_aq_dealloc_acl_tbl(struct ice_hw *hw, u16 alloc_id,
69 struct ice_aqc_acl_generic *buf, struct ice_sq_cd *cd)
71 struct ice_aqc_acl_tbl_actpair *cmd;
72 struct ice_aq_desc desc;
74 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_dealloc_acl_tbl);
75 cmd = &desc.params.tbl_actpair;
76 cmd->alloc_id = CPU_TO_LE16(alloc_id);
78 return ice_aq_send_cmd(hw, &desc, buf, sizeof(*buf), cd);
81 static enum ice_status
82 ice_aq_acl_entry(struct ice_hw *hw, u16 opcode, u8 tcam_idx, u16 entry_idx,
83 struct ice_aqc_acl_data *buf, struct ice_sq_cd *cd)
85 struct ice_aqc_acl_entry *cmd;
86 struct ice_aq_desc desc;
88 ice_fill_dflt_direct_cmd_desc(&desc, opcode);
90 if (opcode == ice_aqc_opc_program_acl_entry)
91 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
93 cmd = &desc.params.program_query_entry;
94 cmd->tcam_index = tcam_idx;
95 cmd->entry_index = CPU_TO_LE16(entry_idx);
97 return ice_aq_send_cmd(hw, &desc, buf, sizeof(*buf), cd);
101 * ice_aq_program_acl_entry - program ACL entry
102 * @hw: pointer to the HW struct
103 * @tcam_idx: Updated TCAM block index
104 * @entry_idx: updated entry index
105 * @buf: address of indirect data buffer
106 * @cd: pointer to command details structure or NULL
108 * Program ACL entry (direct 0x0C20)
111 ice_aq_program_acl_entry(struct ice_hw *hw, u8 tcam_idx, u16 entry_idx,
112 struct ice_aqc_acl_data *buf, struct ice_sq_cd *cd)
114 return ice_aq_acl_entry(hw, ice_aqc_opc_program_acl_entry, tcam_idx,
119 * ice_aq_query_acl_entry - query ACL entry
120 * @hw: pointer to the HW struct
121 * @tcam_idx: Updated TCAM block index
122 * @entry_idx: updated entry index
123 * @buf: address of indirect data buffer
124 * @cd: pointer to command details structure or NULL
126 * Query ACL entry (direct 0x0C24)
128 * NOTE: Caller of this API to parse 'buf' appropriately since it contains
129 * response (key and key invert)
132 ice_aq_query_acl_entry(struct ice_hw *hw, u8 tcam_idx, u16 entry_idx,
133 struct ice_aqc_acl_data *buf, struct ice_sq_cd *cd)
135 return ice_aq_acl_entry(hw, ice_aqc_opc_query_acl_entry, tcam_idx,
139 /* Helper function to alloc/dealloc ACL action pair */
140 static enum ice_status
141 ice_aq_actpair_a_d(struct ice_hw *hw, u16 opcode, u16 alloc_id,
142 struct ice_aqc_acl_generic *buf, struct ice_sq_cd *cd)
144 struct ice_aqc_acl_tbl_actpair *cmd;
145 struct ice_aq_desc desc;
147 ice_fill_dflt_direct_cmd_desc(&desc, opcode);
148 cmd = &desc.params.tbl_actpair;
149 cmd->alloc_id = CPU_TO_LE16(alloc_id);
151 return ice_aq_send_cmd(hw, &desc, buf, sizeof(*buf), cd);
155 * ice_aq_alloc_actpair - allocate actionpair for specified ACL table
156 * @hw: pointer to the HW struct
157 * @alloc_id: allocation ID of the table being associated with the actionpair
158 * @buf: address of indirect data buffer
159 * @cd: pointer to command details structure or NULL
161 * Allocate ACL actionpair (direct 0x0C12)
163 * This command doesn't need and doesn't have its own command buffer
164 * but for response format is as specified in 'struct ice_aqc_acl_generic'
167 ice_aq_alloc_actpair(struct ice_hw *hw, u16 alloc_id,
168 struct ice_aqc_acl_generic *buf, struct ice_sq_cd *cd)
170 return ice_aq_actpair_a_d(hw, ice_aqc_opc_alloc_acl_actpair, alloc_id,
175 * ice_aq_dealloc_actpair - dealloc actionpair for specified ACL table
176 * @hw: pointer to the HW struct
177 * @alloc_id: allocation ID of the table being associated with the actionpair
178 * @buf: address of indirect data buffer
179 * @cd: pointer to command details structure or NULL
181 * Deallocate ACL actionpair (direct 0x0C13)
184 ice_aq_dealloc_actpair(struct ice_hw *hw, u16 alloc_id,
185 struct ice_aqc_acl_generic *buf, struct ice_sq_cd *cd)
187 return ice_aq_actpair_a_d(hw, ice_aqc_opc_dealloc_acl_actpair, alloc_id,
191 /* Helper function to program/query ACL action pair */
192 static enum ice_status
193 ice_aq_actpair_p_q(struct ice_hw *hw, u16 opcode, u8 act_mem_idx,
194 u16 act_entry_idx, struct ice_aqc_actpair *buf,
195 struct ice_sq_cd *cd)
197 struct ice_aqc_acl_actpair *cmd;
198 struct ice_aq_desc desc;
200 ice_fill_dflt_direct_cmd_desc(&desc, opcode);
202 if (opcode == ice_aqc_opc_program_acl_actpair)
203 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
205 cmd = &desc.params.program_query_actpair;
206 cmd->act_mem_index = act_mem_idx;
207 cmd->act_entry_index = CPU_TO_LE16(act_entry_idx);
209 return ice_aq_send_cmd(hw, &desc, buf, sizeof(*buf), cd);
213 * ice_aq_program_actpair - program ACL actionpair
214 * @hw: pointer to the HW struct
215 * @act_mem_idx: action memory index to program/update/query
216 * @act_entry_idx: the entry index in action memory to be programmed/updated
217 * @buf: address of indirect data buffer
218 * @cd: pointer to command details structure or NULL
220 * Program action entries (indirect 0x0C1C)
223 ice_aq_program_actpair(struct ice_hw *hw, u8 act_mem_idx, u16 act_entry_idx,
224 struct ice_aqc_actpair *buf, struct ice_sq_cd *cd)
226 return ice_aq_actpair_p_q(hw, ice_aqc_opc_program_acl_actpair,
227 act_mem_idx, act_entry_idx, buf, cd);
231 * ice_aq_query_actpair - query ACL actionpair
232 * @hw: pointer to the HW struct
233 * @act_mem_idx: action memory index to program/update/query
234 * @act_entry_idx: the entry index in action memory to be programmed/updated
235 * @buf: address of indirect data buffer
236 * @cd: pointer to command details structure or NULL
238 * Query ACL actionpair (indirect 0x0C25)
241 ice_aq_query_actpair(struct ice_hw *hw, u8 act_mem_idx, u16 act_entry_idx,
242 struct ice_aqc_actpair *buf, struct ice_sq_cd *cd)
244 return ice_aq_actpair_p_q(hw, ice_aqc_opc_query_acl_actpair,
245 act_mem_idx, act_entry_idx, buf, cd);
249 * ice_aq_dealloc_acl_res - deallocate ACL resources
250 * @hw: pointer to the HW struct
251 * @cd: pointer to command details structure or NULL
253 * ACL - de-allocate (direct 0x0C1A) resources. Used by SW to release all the
254 * resources allocated for it using a single command
256 enum ice_status ice_aq_dealloc_acl_res(struct ice_hw *hw, struct ice_sq_cd *cd)
258 struct ice_aq_desc desc;
260 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_dealloc_acl_res);
262 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
266 * ice_acl_prof_aq_send - sending acl profile aq commands
267 * @hw: pointer to the HW struct
268 * @opc: command opcode
269 * @prof_id: profile ID
270 * @buf: ptr to buffer
271 * @cd: pointer to command details structure or NULL
273 * This function sends ACL profile commands
275 static enum ice_status
276 ice_acl_prof_aq_send(struct ice_hw *hw, u16 opc, u8 prof_id,
277 struct ice_aqc_acl_prof_generic_frmt *buf,
278 struct ice_sq_cd *cd)
280 struct ice_aq_desc desc;
282 ice_fill_dflt_direct_cmd_desc(&desc, opc);
283 desc.params.profile.profile_id = prof_id;
284 if (opc == ice_aqc_opc_program_acl_prof_extraction ||
285 opc == ice_aqc_opc_program_acl_prof_ranges)
286 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
287 return ice_aq_send_cmd(hw, &desc, buf, sizeof(*buf), cd);
291 * ice_prgm_acl_prof_extrt - program ACL profile extraction sequence
292 * @hw: pointer to the HW struct
293 * @prof_id: profile ID
294 * @buf: ptr to buffer
295 * @cd: pointer to command details structure or NULL
297 * ACL - program ACL profile extraction (indirect 0x0C1D)
300 ice_prgm_acl_prof_extrt(struct ice_hw *hw, u8 prof_id,
301 struct ice_aqc_acl_prof_generic_frmt *buf,
302 struct ice_sq_cd *cd)
304 return ice_acl_prof_aq_send(hw, ice_aqc_opc_program_acl_prof_extraction,
309 * ice_query_acl_prof - query ACL profile
310 * @hw: pointer to the HW struct
311 * @prof_id: profile ID
312 * @buf: ptr to buffer (which will contain response of this command)
313 * @cd: pointer to command details structure or NULL
315 * ACL - query ACL profile (indirect 0x0C21)
318 ice_query_acl_prof(struct ice_hw *hw, u8 prof_id,
319 struct ice_aqc_acl_prof_generic_frmt *buf,
320 struct ice_sq_cd *cd)
322 return ice_acl_prof_aq_send(hw, ice_aqc_opc_query_acl_prof, prof_id,
327 * ice_aq_acl_cntrs_chk_params - Checks ACL counter parameters
328 * @cntrs: ptr to buffer describing input and output params
330 * This function checks the counter bank range for counter type and returns
331 * success or failure.
333 static enum ice_status ice_aq_acl_cntrs_chk_params(struct ice_acl_cntrs *cntrs)
335 enum ice_status status = ICE_SUCCESS;
337 if (!cntrs || !cntrs->amount)
338 return ICE_ERR_PARAM;
340 switch (cntrs->type) {
341 case ICE_AQC_ACL_CNT_TYPE_SINGLE:
342 /* Single counter type - configured to count either bytes
343 * or packets, the valid values for byte or packet counters
346 if (cntrs->bank > ICE_AQC_ACL_MAX_CNT_SINGLE)
347 status = ICE_ERR_OUT_OF_RANGE;
349 case ICE_AQC_ACL_CNT_TYPE_DUAL:
350 /* Pair counter type - counts number of bytes and packets
351 * The valid values for byte/packet counter duals shall be 0-1
353 if (cntrs->bank > ICE_AQC_ACL_MAX_CNT_DUAL)
354 status = ICE_ERR_OUT_OF_RANGE;
357 /* Unspecified counter type - Invalid or error*/
358 status = ICE_ERR_PARAM;
365 * ice_aq_alloc_acl_cntrs - allocate ACL counters
366 * @hw: pointer to the HW struct
367 * @cntrs: ptr to buffer describing input and output params
368 * @cd: pointer to command details structure or NULL
370 * ACL - allocate (indirect 0x0C16) counters. This function attempts to
371 * allocate a contiguous block of counters. In case of failures, caller can
372 * attempt to allocate a smaller chunk. The allocation is considered
373 * unsuccessful if returned counter value is invalid. In this case it returns
374 * an error otherwise success.
377 ice_aq_alloc_acl_cntrs(struct ice_hw *hw, struct ice_acl_cntrs *cntrs,
378 struct ice_sq_cd *cd)
380 struct ice_aqc_acl_alloc_counters *cmd;
381 u16 first_cntr, last_cntr;
382 struct ice_aq_desc desc;
383 enum ice_status status;
385 /* check for invalid params */
386 status = ice_aq_acl_cntrs_chk_params(cntrs);
389 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_alloc_acl_counters);
390 cmd = &desc.params.alloc_counters;
391 cmd->counter_amount = cntrs->amount;
392 cmd->counters_type = cntrs->type;
393 cmd->bank_alloc = cntrs->bank;
394 status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
396 first_cntr = LE16_TO_CPU(cmd->ops.resp.first_counter);
397 last_cntr = LE16_TO_CPU(cmd->ops.resp.last_counter);
398 if (first_cntr == ICE_AQC_ACL_ALLOC_CNT_INVAL ||
399 last_cntr == ICE_AQC_ACL_ALLOC_CNT_INVAL)
400 return ICE_ERR_OUT_OF_RANGE;
401 cntrs->first_cntr = first_cntr;
402 cntrs->last_cntr = last_cntr;
408 * ice_aq_dealloc_acl_cntrs - deallocate ACL counters
409 * @hw: pointer to the HW struct
410 * @cntrs: ptr to buffer describing input and output params
411 * @cd: pointer to command details structure or NULL
413 * ACL - de-allocate (direct 0x0C17) counters.
414 * This function deallocate ACL counters.
417 ice_aq_dealloc_acl_cntrs(struct ice_hw *hw, struct ice_acl_cntrs *cntrs,
418 struct ice_sq_cd *cd)
420 struct ice_aqc_acl_dealloc_counters *cmd;
421 struct ice_aq_desc desc;
422 enum ice_status status;
424 /* check for invalid params */
425 status = ice_aq_acl_cntrs_chk_params(cntrs);
429 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_dealloc_acl_counters);
430 cmd = &desc.params.dealloc_counters;
431 cmd->first_counter = CPU_TO_LE16(cntrs->first_cntr);
432 cmd->last_counter = CPU_TO_LE16(cntrs->last_cntr);
433 cmd->counters_type = cntrs->type;
434 cmd->bank_alloc = cntrs->bank;
435 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
439 * ice_aq_query_acl_cntrs - query ACL counter
440 * @hw: pointer to the HW struct
441 * @bank: queries counter bank
442 * @index: queried counter index
443 * @cntr_val: pointer to counter or packet counter value
444 * @cd: pointer to command details structure or NULL
446 * ACL - query ACL counter (direct 0x0C27)
449 ice_aq_query_acl_cntrs(struct ice_hw *hw, u8 bank, u16 index, u64 *cntr_val,
450 struct ice_sq_cd *cd)
452 struct ice_aqc_acl_query_counter *cmd;
453 struct ice_aq_desc desc;
454 enum ice_status status;
457 return ICE_ERR_PARAM;
459 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_query_acl_counter);
460 cmd = &desc.params.query_counter;
461 cmd->counter_index = CPU_TO_LE16(index);
462 cmd->counter_bank = bank;
463 status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
467 ice_memcpy(&resp_val, cmd->ops.resp.val,
468 sizeof(cmd->ops.resp.val), ICE_NONDMA_TO_NONDMA);
469 *cntr_val = LE64_TO_CPU(resp_val);
475 * ice_prog_acl_prof_ranges - program ACL profile ranges
476 * @hw: pointer to the HW struct
477 * @prof_id: programmed or updated profile ID
478 * @buf: pointer to input buffer
479 * @cd: pointer to command details structure or NULL
481 * ACL - program ACL profile ranges (indirect 0x0C1E)
484 ice_prog_acl_prof_ranges(struct ice_hw *hw, u8 prof_id,
485 struct ice_aqc_acl_profile_ranges *buf,
486 struct ice_sq_cd *cd)
488 struct ice_aq_desc desc;
490 ice_fill_dflt_direct_cmd_desc(&desc,
491 ice_aqc_opc_program_acl_prof_ranges);
492 desc.params.profile.profile_id = prof_id;
493 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
494 return ice_aq_send_cmd(hw, &desc, buf, sizeof(*buf), cd);
498 * ice_query_acl_prof_ranges - query ACL profile ranges
499 * @hw: pointer to the HW struct
500 * @prof_id: programmed or updated profile ID
501 * @buf: pointer to response buffer
502 * @cd: pointer to command details structure or NULL
504 * ACL - query ACL profile ranges (indirect 0x0C22)
507 ice_query_acl_prof_ranges(struct ice_hw *hw, u8 prof_id,
508 struct ice_aqc_acl_profile_ranges *buf,
509 struct ice_sq_cd *cd)
511 struct ice_aq_desc desc;
513 ice_fill_dflt_direct_cmd_desc(&desc,
514 ice_aqc_opc_query_acl_prof_ranges);
515 desc.params.profile.profile_id = prof_id;
516 return ice_aq_send_cmd(hw, &desc, buf, sizeof(*buf), cd);
520 * ice_aq_alloc_acl_scen - allocate ACL scenario
521 * @hw: pointer to the HW struct
522 * @scen_id: memory location to receive allocated scenario ID
523 * @buf: address of indirect data buffer
524 * @cd: pointer to command details structure or NULL
526 * Allocate ACL scenario (indirect 0x0C14)
529 ice_aq_alloc_acl_scen(struct ice_hw *hw, u16 *scen_id,
530 struct ice_aqc_acl_scen *buf, struct ice_sq_cd *cd)
532 struct ice_aqc_acl_alloc_scen *cmd;
533 struct ice_aq_desc desc;
534 enum ice_status status;
537 return ICE_ERR_PARAM;
539 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_alloc_acl_scen);
540 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
541 cmd = &desc.params.alloc_scen;
543 status = ice_aq_send_cmd(hw, &desc, buf, sizeof(*buf), cd);
545 *scen_id = LE16_TO_CPU(cmd->ops.resp.scen_id);
551 * ice_aq_dealloc_acl_scen - deallocate ACL scenario
552 * @hw: pointer to the HW struct
553 * @scen_id: scen_id to be deallocated (input and output field)
554 * @cd: pointer to command details structure or NULL
556 * Deallocate ACL scenario (direct 0x0C15)
559 ice_aq_dealloc_acl_scen(struct ice_hw *hw, u16 scen_id, struct ice_sq_cd *cd)
561 struct ice_aqc_acl_dealloc_scen *cmd;
562 struct ice_aq_desc desc;
564 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_dealloc_acl_scen);
565 cmd = &desc.params.dealloc_scen;
566 cmd->scen_id = CPU_TO_LE16(scen_id);
568 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
572 * ice_aq_update_query_scen - update or query ACL scenario
573 * @hw: pointer to the HW struct
574 * @opcode: aq command opcode for either query or update scenario
575 * @scen_id: scen_id to be updated or queried
576 * @buf: address of indirect data buffer
577 * @cd: pointer to command details structure or NULL
579 * Calls update or query ACL scenario
581 static enum ice_status
582 ice_aq_update_query_scen(struct ice_hw *hw, u16 opcode, u16 scen_id,
583 struct ice_aqc_acl_scen *buf, struct ice_sq_cd *cd)
585 struct ice_aqc_acl_update_query_scen *cmd;
586 struct ice_aq_desc desc;
588 ice_fill_dflt_direct_cmd_desc(&desc, opcode);
589 if (opcode == ice_aqc_opc_update_acl_scen)
590 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
591 cmd = &desc.params.update_query_scen;
592 cmd->scen_id = CPU_TO_LE16(scen_id);
594 return ice_aq_send_cmd(hw, &desc, buf, sizeof(*buf), cd);
598 * ice_aq_update_acl_scen - update ACL scenario
599 * @hw: pointer to the HW struct
600 * @scen_id: scen_id to be updated
601 * @buf: address of indirect data buffer
602 * @cd: pointer to command details structure or NULL
604 * Update ACL scenario (indirect 0x0C1B)
607 ice_aq_update_acl_scen(struct ice_hw *hw, u16 scen_id,
608 struct ice_aqc_acl_scen *buf, struct ice_sq_cd *cd)
610 return ice_aq_update_query_scen(hw, ice_aqc_opc_update_acl_scen,
615 * ice_aq_query_acl_scen - query ACL scenario
616 * @hw: pointer to the HW struct
617 * @scen_id: scen_id to be queried
618 * @buf: address of indirect data buffer
619 * @cd: pointer to command details structure or NULL
621 * Query ACL scenario (indirect 0x0C23)
624 ice_aq_query_acl_scen(struct ice_hw *hw, u16 scen_id,
625 struct ice_aqc_acl_scen *buf, struct ice_sq_cd *cd)
627 return ice_aq_update_query_scen(hw, ice_aqc_opc_query_acl_scen,