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 * De-allocate ACL resources (direct 0x0C1A). 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_xtrct - 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 * Program ACL profile extraction (indirect 0x0C1D)
300 ice_prgm_acl_prof_xtrct(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 * 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 * Allocate ACL counters (indirect 0x0C16). 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 * De-allocate ACL counters (direct 0x0C17)
416 ice_aq_dealloc_acl_cntrs(struct ice_hw *hw, struct ice_acl_cntrs *cntrs,
417 struct ice_sq_cd *cd)
419 struct ice_aqc_acl_dealloc_counters *cmd;
420 struct ice_aq_desc desc;
421 enum ice_status status;
423 /* check for invalid params */
424 status = ice_aq_acl_cntrs_chk_params(cntrs);
428 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_dealloc_acl_counters);
429 cmd = &desc.params.dealloc_counters;
430 cmd->first_counter = CPU_TO_LE16(cntrs->first_cntr);
431 cmd->last_counter = CPU_TO_LE16(cntrs->last_cntr);
432 cmd->counters_type = cntrs->type;
433 cmd->bank_alloc = cntrs->bank;
434 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
438 * ice_prog_acl_prof_ranges - program ACL profile ranges
439 * @hw: pointer to the HW struct
440 * @prof_id: programmed or updated profile ID
441 * @buf: pointer to input buffer
442 * @cd: pointer to command details structure or NULL
444 * Program ACL profile ranges (indirect 0x0C1E)
447 ice_prog_acl_prof_ranges(struct ice_hw *hw, u8 prof_id,
448 struct ice_aqc_acl_profile_ranges *buf,
449 struct ice_sq_cd *cd)
451 struct ice_aq_desc desc;
453 ice_fill_dflt_direct_cmd_desc(&desc,
454 ice_aqc_opc_program_acl_prof_ranges);
455 desc.params.profile.profile_id = prof_id;
456 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
457 return ice_aq_send_cmd(hw, &desc, buf, sizeof(*buf), cd);
461 * ice_query_acl_prof_ranges - query ACL profile ranges
462 * @hw: pointer to the HW struct
463 * @prof_id: programmed or updated profile ID
464 * @buf: pointer to response buffer
465 * @cd: pointer to command details structure or NULL
467 * Query ACL profile ranges (indirect 0x0C22)
470 ice_query_acl_prof_ranges(struct ice_hw *hw, u8 prof_id,
471 struct ice_aqc_acl_profile_ranges *buf,
472 struct ice_sq_cd *cd)
474 struct ice_aq_desc desc;
476 ice_fill_dflt_direct_cmd_desc(&desc,
477 ice_aqc_opc_query_acl_prof_ranges);
478 desc.params.profile.profile_id = prof_id;
479 return ice_aq_send_cmd(hw, &desc, buf, sizeof(*buf), cd);
483 * ice_aq_alloc_acl_scen - allocate ACL scenario
484 * @hw: pointer to the HW struct
485 * @scen_id: memory location to receive allocated scenario ID
486 * @buf: address of indirect data buffer
487 * @cd: pointer to command details structure or NULL
489 * Allocate ACL scenario (indirect 0x0C14)
492 ice_aq_alloc_acl_scen(struct ice_hw *hw, u16 *scen_id,
493 struct ice_aqc_acl_scen *buf, struct ice_sq_cd *cd)
495 struct ice_aqc_acl_alloc_scen *cmd;
496 struct ice_aq_desc desc;
497 enum ice_status status;
500 return ICE_ERR_PARAM;
502 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_alloc_acl_scen);
503 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
504 cmd = &desc.params.alloc_scen;
506 status = ice_aq_send_cmd(hw, &desc, buf, sizeof(*buf), cd);
508 *scen_id = LE16_TO_CPU(cmd->ops.resp.scen_id);
514 * ice_aq_dealloc_acl_scen - deallocate ACL scenario
515 * @hw: pointer to the HW struct
516 * @scen_id: scen_id to be deallocated (input and output field)
517 * @cd: pointer to command details structure or NULL
519 * Deallocate ACL scenario (direct 0x0C15)
522 ice_aq_dealloc_acl_scen(struct ice_hw *hw, u16 scen_id, struct ice_sq_cd *cd)
524 struct ice_aqc_acl_dealloc_scen *cmd;
525 struct ice_aq_desc desc;
527 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_dealloc_acl_scen);
528 cmd = &desc.params.dealloc_scen;
529 cmd->scen_id = CPU_TO_LE16(scen_id);
531 return ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
535 * ice_aq_update_query_scen - update or query ACL scenario
536 * @hw: pointer to the HW struct
537 * @opcode: AQ command opcode for either query or update scenario
538 * @scen_id: scen_id to be updated or queried
539 * @buf: address of indirect data buffer
540 * @cd: pointer to command details structure or NULL
542 * Calls update or query ACL scenario
544 static enum ice_status
545 ice_aq_update_query_scen(struct ice_hw *hw, u16 opcode, u16 scen_id,
546 struct ice_aqc_acl_scen *buf, struct ice_sq_cd *cd)
548 struct ice_aqc_acl_update_query_scen *cmd;
549 struct ice_aq_desc desc;
551 ice_fill_dflt_direct_cmd_desc(&desc, opcode);
552 if (opcode == ice_aqc_opc_update_acl_scen)
553 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
554 cmd = &desc.params.update_query_scen;
555 cmd->scen_id = CPU_TO_LE16(scen_id);
557 return ice_aq_send_cmd(hw, &desc, buf, sizeof(*buf), cd);
561 * ice_aq_update_acl_scen - update ACL scenario
562 * @hw: pointer to the HW struct
563 * @scen_id: scen_id to be updated
564 * @buf: address of indirect data buffer
565 * @cd: pointer to command details structure or NULL
567 * Update ACL scenario (indirect 0x0C1B)
570 ice_aq_update_acl_scen(struct ice_hw *hw, u16 scen_id,
571 struct ice_aqc_acl_scen *buf, struct ice_sq_cd *cd)
573 return ice_aq_update_query_scen(hw, ice_aqc_opc_update_acl_scen,
578 * ice_aq_query_acl_scen - query ACL scenario
579 * @hw: pointer to the HW struct
580 * @scen_id: scen_id to be queried
581 * @buf: address of indirect data buffer
582 * @cd: pointer to command details structure or NULL
584 * Query ACL scenario (indirect 0x0C23)
587 ice_aq_query_acl_scen(struct ice_hw *hw, u16 scen_id,
588 struct ice_aqc_acl_scen *buf, struct ice_sq_cd *cd)
590 return ice_aq_update_query_scen(hw, ice_aqc_opc_query_acl_scen,