1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright (c) 2020, Intel Corporation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the Intel Corporation nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 #include "ice_common.h"
34 #include "ice_flex_pipe.h"
35 #include "ice_protocol_type.h"
38 /* To support tunneling entries by PF, the package will append the PF number to
39 * the label; for example TNL_VXLAN_PF0, TNL_VXLAN_PF1, TNL_VXLAN_PF2, etc.
41 static const struct ice_tunnel_type_scan tnls[] = {
42 { TNL_VXLAN, "TNL_VXLAN_PF" },
43 { TNL_GENEVE, "TNL_GENEVE_PF" },
47 static const u32 ice_sect_lkup[ICE_BLK_COUNT][ICE_SECT_COUNT] = {
51 ICE_SID_XLT_KEY_BUILDER_SW,
54 ICE_SID_PROFID_TCAM_SW,
55 ICE_SID_PROFID_REDIR_SW,
57 ICE_SID_CDID_KEY_BUILDER_SW,
64 ICE_SID_XLT_KEY_BUILDER_ACL,
67 ICE_SID_PROFID_TCAM_ACL,
68 ICE_SID_PROFID_REDIR_ACL,
70 ICE_SID_CDID_KEY_BUILDER_ACL,
71 ICE_SID_CDID_REDIR_ACL
77 ICE_SID_XLT_KEY_BUILDER_FD,
80 ICE_SID_PROFID_TCAM_FD,
81 ICE_SID_PROFID_REDIR_FD,
83 ICE_SID_CDID_KEY_BUILDER_FD,
90 ICE_SID_XLT_KEY_BUILDER_RSS,
93 ICE_SID_PROFID_TCAM_RSS,
94 ICE_SID_PROFID_REDIR_RSS,
96 ICE_SID_CDID_KEY_BUILDER_RSS,
97 ICE_SID_CDID_REDIR_RSS
103 ICE_SID_XLT_KEY_BUILDER_PE,
106 ICE_SID_PROFID_TCAM_PE,
107 ICE_SID_PROFID_REDIR_PE,
109 ICE_SID_CDID_KEY_BUILDER_PE,
110 ICE_SID_CDID_REDIR_PE
115 * ice_sect_id - returns section ID
117 * @sect: section type
119 * This helper function returns the proper section ID given a block type and a
122 static u32 ice_sect_id(enum ice_block blk, enum ice_sect sect)
124 return ice_sect_lkup[blk][sect];
129 * @buf: pointer to the ice buffer
131 * This helper function validates a buffer's header.
133 static struct ice_buf_hdr *ice_pkg_val_buf(struct ice_buf *buf)
135 struct ice_buf_hdr *hdr;
139 hdr = (struct ice_buf_hdr *)buf->buf;
141 section_count = LE16_TO_CPU(hdr->section_count);
142 if (section_count < ICE_MIN_S_COUNT || section_count > ICE_MAX_S_COUNT)
145 data_end = LE16_TO_CPU(hdr->data_end);
146 if (data_end < ICE_MIN_S_DATA_END || data_end > ICE_MAX_S_DATA_END)
154 * @ice_seg: pointer to the ice segment
156 * Returns the address of the buffer table within the ice segment.
158 static struct ice_buf_table *ice_find_buf_table(struct ice_seg *ice_seg)
160 struct ice_nvm_table *nvms;
162 nvms = (struct ice_nvm_table *)
163 (ice_seg->device_table +
164 LE32_TO_CPU(ice_seg->device_table_count));
166 return (_FORCE_ struct ice_buf_table *)
167 (nvms->vers + LE32_TO_CPU(nvms->table_count));
172 * @ice_seg: pointer to the ice segment (or NULL on subsequent calls)
173 * @state: pointer to the enum state
175 * This function will enumerate all the buffers in the ice segment. The first
176 * call is made with the ice_seg parameter non-NULL; on subsequent calls,
177 * ice_seg is set to NULL which continues the enumeration. When the function
178 * returns a NULL pointer, then the end of the buffers has been reached, or an
179 * unexpected value has been detected (for example an invalid section count or
180 * an invalid buffer end value).
182 static struct ice_buf_hdr *
183 ice_pkg_enum_buf(struct ice_seg *ice_seg, struct ice_pkg_enum *state)
186 state->buf_table = ice_find_buf_table(ice_seg);
187 if (!state->buf_table)
191 return ice_pkg_val_buf(state->buf_table->buf_array);
194 if (++state->buf_idx < LE32_TO_CPU(state->buf_table->buf_count))
195 return ice_pkg_val_buf(state->buf_table->buf_array +
202 * ice_pkg_advance_sect
203 * @ice_seg: pointer to the ice segment (or NULL on subsequent calls)
204 * @state: pointer to the enum state
206 * This helper function will advance the section within the ice segment,
207 * also advancing the buffer if needed.
210 ice_pkg_advance_sect(struct ice_seg *ice_seg, struct ice_pkg_enum *state)
212 if (!ice_seg && !state->buf)
215 if (!ice_seg && state->buf)
216 if (++state->sect_idx < LE16_TO_CPU(state->buf->section_count))
219 state->buf = ice_pkg_enum_buf(ice_seg, state);
223 /* start of new buffer, reset section index */
229 * ice_pkg_enum_section
230 * @ice_seg: pointer to the ice segment (or NULL on subsequent calls)
231 * @state: pointer to the enum state
232 * @sect_type: section type to enumerate
234 * This function will enumerate all the sections of a particular type in the
235 * ice segment. The first call is made with the ice_seg parameter non-NULL;
236 * on subsequent calls, ice_seg is set to NULL which continues the enumeration.
237 * When the function returns a NULL pointer, then the end of the matching
238 * sections has been reached.
241 ice_pkg_enum_section(struct ice_seg *ice_seg, struct ice_pkg_enum *state,
247 state->type = sect_type;
249 if (!ice_pkg_advance_sect(ice_seg, state))
252 /* scan for next matching section */
253 while (state->buf->section_entry[state->sect_idx].type !=
254 CPU_TO_LE32(state->type))
255 if (!ice_pkg_advance_sect(NULL, state))
258 /* validate section */
259 offset = LE16_TO_CPU(state->buf->section_entry[state->sect_idx].offset);
260 if (offset < ICE_MIN_S_OFF || offset > ICE_MAX_S_OFF)
263 size = LE16_TO_CPU(state->buf->section_entry[state->sect_idx].size);
264 if (size < ICE_MIN_S_SZ || size > ICE_MAX_S_SZ)
267 /* make sure the section fits in the buffer */
268 if (offset + size > ICE_PKG_BUF_SIZE)
272 LE32_TO_CPU(state->buf->section_entry[state->sect_idx].type);
274 /* calc pointer to this section */
275 state->sect = ((u8 *)state->buf) +
276 LE16_TO_CPU(state->buf->section_entry[state->sect_idx].offset);
283 * @ice_seg: pointer to the ice segment (or NULL on subsequent calls)
284 * @state: pointer to the enum state
285 * @sect_type: section type to enumerate
286 * @offset: pointer to variable that receives the offset in the table (optional)
287 * @handler: function that handles access to the entries into the section type
289 * This function will enumerate all the entries in particular section type in
290 * the ice segment. The first call is made with the ice_seg parameter non-NULL;
291 * on subsequent calls, ice_seg is set to NULL which continues the enumeration.
292 * When the function returns a NULL pointer, then the end of the entries has
295 * Since each section may have a different header and entry size, the handler
296 * function is needed to determine the number and location entries in each
299 * The offset parameter is optional, but should be used for sections that
300 * contain an offset for each section table. For such cases, the section handler
301 * function must return the appropriate offset + index to give the absolution
302 * offset for each entry. For example, if the base for a section's header
303 * indicates a base offset of 10, and the index for the entry is 2, then
304 * section handler function should set the offset to 10 + 2 = 12.
307 ice_pkg_enum_entry(struct ice_seg *ice_seg, struct ice_pkg_enum *state,
308 u32 sect_type, u32 *offset,
309 void *(*handler)(u32 sect_type, void *section,
310 u32 index, u32 *offset))
318 if (!ice_pkg_enum_section(ice_seg, state, sect_type))
321 state->entry_idx = 0;
322 state->handler = handler;
331 entry = state->handler(state->sect_type, state->sect, state->entry_idx,
334 /* end of a section, look for another section of this type */
335 if (!ice_pkg_enum_section(NULL, state, 0))
338 state->entry_idx = 0;
339 entry = state->handler(state->sect_type, state->sect,
340 state->entry_idx, offset);
347 * ice_boost_tcam_handler
348 * @sect_type: section type
349 * @section: pointer to section
350 * @index: index of the boost TCAM entry to be returned
351 * @offset: pointer to receive absolute offset, always 0 for boost TCAM sections
353 * This is a callback function that can be passed to ice_pkg_enum_entry.
354 * Handles enumeration of individual boost TCAM entries.
357 ice_boost_tcam_handler(u32 sect_type, void *section, u32 index, u32 *offset)
359 struct ice_boost_tcam_section *boost;
364 if (sect_type != ICE_SID_RXPARSER_BOOST_TCAM)
367 if (index > ICE_MAX_BST_TCAMS_IN_BUF)
373 boost = (struct ice_boost_tcam_section *)section;
374 if (index >= LE16_TO_CPU(boost->count))
377 return boost->tcam + index;
381 * ice_find_boost_entry
382 * @ice_seg: pointer to the ice segment (non-NULL)
383 * @addr: Boost TCAM address of entry to search for
384 * @entry: returns pointer to the entry
386 * Finds a particular Boost TCAM entry and returns a pointer to that entry
387 * if it is found. The ice_seg parameter must not be NULL since the first call
388 * to ice_pkg_enum_entry requires a pointer to an actual ice_segment structure.
390 static enum ice_status
391 ice_find_boost_entry(struct ice_seg *ice_seg, u16 addr,
392 struct ice_boost_tcam_entry **entry)
394 struct ice_boost_tcam_entry *tcam;
395 struct ice_pkg_enum state;
397 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
400 return ICE_ERR_PARAM;
403 tcam = (struct ice_boost_tcam_entry *)
404 ice_pkg_enum_entry(ice_seg, &state,
405 ICE_SID_RXPARSER_BOOST_TCAM, NULL,
406 ice_boost_tcam_handler);
407 if (tcam && LE16_TO_CPU(tcam->addr) == addr) {
420 * ice_label_enum_handler
421 * @sect_type: section type
422 * @section: pointer to section
423 * @index: index of the label entry to be returned
424 * @offset: pointer to receive absolute offset, always zero for label sections
426 * This is a callback function that can be passed to ice_pkg_enum_entry.
427 * Handles enumeration of individual label entries.
430 ice_label_enum_handler(u32 __ALWAYS_UNUSED sect_type, void *section, u32 index,
433 struct ice_label_section *labels;
438 if (index > ICE_MAX_LABELS_IN_BUF)
444 labels = (struct ice_label_section *)section;
445 if (index >= LE16_TO_CPU(labels->count))
448 return labels->label + index;
453 * @ice_seg: pointer to the ice segment (NULL on subsequent calls)
454 * @type: the section type that will contain the label (0 on subsequent calls)
455 * @state: ice_pkg_enum structure that will hold the state of the enumeration
456 * @value: pointer to a value that will return the label's value if found
458 * Enumerates a list of labels in the package. The caller will call
459 * ice_enum_labels(ice_seg, type, ...) to start the enumeration, then call
460 * ice_enum_labels(NULL, 0, ...) to continue. When the function returns a NULL
461 * the end of the list has been reached.
464 ice_enum_labels(struct ice_seg *ice_seg, u32 type, struct ice_pkg_enum *state,
467 struct ice_label *label;
469 /* Check for valid label section on first call */
470 if (type && !(type >= ICE_SID_LBL_FIRST && type <= ICE_SID_LBL_LAST))
473 label = (struct ice_label *)ice_pkg_enum_entry(ice_seg, state, type,
475 ice_label_enum_handler);
479 *value = LE16_TO_CPU(label->value);
485 * @hw: pointer to the HW structure
486 * @ice_seg: pointer to the segment of the package scan (non-NULL)
488 * This function will scan the package and save off relevant information
489 * (hints or metadata) for driver use. The ice_seg parameter must not be NULL
490 * since the first call to ice_enum_labels requires a pointer to an actual
493 static void ice_init_pkg_hints(struct ice_hw *hw, struct ice_seg *ice_seg)
495 struct ice_pkg_enum state;
500 ice_memset(&hw->tnl, 0, sizeof(hw->tnl), ICE_NONDMA_MEM);
501 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
506 label_name = ice_enum_labels(ice_seg, ICE_SID_LBL_RXPARSER_TMEM, &state,
509 while (label_name && hw->tnl.count < ICE_TUNNEL_MAX_ENTRIES) {
510 for (i = 0; tnls[i].type != TNL_LAST; i++) {
511 size_t len = strlen(tnls[i].label_prefix);
513 /* Look for matching label start, before continuing */
514 if (strncmp(label_name, tnls[i].label_prefix, len))
517 /* Make sure this label matches our PF. Note that the PF
518 * character ('0' - '7') will be located where our
519 * prefix string's null terminator is located.
521 if ((label_name[len] - '0') == hw->pf_id) {
522 hw->tnl.tbl[hw->tnl.count].type = tnls[i].type;
523 hw->tnl.tbl[hw->tnl.count].valid = false;
524 hw->tnl.tbl[hw->tnl.count].in_use = false;
525 hw->tnl.tbl[hw->tnl.count].marked = false;
526 hw->tnl.tbl[hw->tnl.count].boost_addr = val;
527 hw->tnl.tbl[hw->tnl.count].port = 0;
533 label_name = ice_enum_labels(NULL, 0, &state, &val);
536 /* Cache the appropriate boost TCAM entry pointers */
537 for (i = 0; i < hw->tnl.count; i++) {
538 ice_find_boost_entry(ice_seg, hw->tnl.tbl[i].boost_addr,
539 &hw->tnl.tbl[i].boost_entry);
540 if (hw->tnl.tbl[i].boost_entry)
541 hw->tnl.tbl[i].valid = true;
547 #define ICE_DC_KEY 0x1 /* don't care */
548 #define ICE_DC_KEYINV 0x1
549 #define ICE_NM_KEY 0x0 /* never match */
550 #define ICE_NM_KEYINV 0x0
551 #define ICE_0_KEY 0x1 /* match 0 */
552 #define ICE_0_KEYINV 0x0
553 #define ICE_1_KEY 0x0 /* match 1 */
554 #define ICE_1_KEYINV 0x1
557 * ice_gen_key_word - generate 16-bits of a key/mask word
559 * @valid: valid bits mask (change only the valid bits)
560 * @dont_care: don't care mask
561 * @nvr_mtch: never match mask
562 * @key: pointer to an array of where the resulting key portion
563 * @key_inv: pointer to an array of where the resulting key invert portion
565 * This function generates 16-bits from a 8-bit value, an 8-bit don't care mask
566 * and an 8-bit never match mask. The 16-bits of output are divided into 8 bits
567 * of key and 8 bits of key invert.
569 * '0' = b01, always match a 0 bit
570 * '1' = b10, always match a 1 bit
571 * '?' = b11, don't care bit (always matches)
572 * '~' = b00, never match bit
576 * dont_care: b0 0 1 1 0 0
577 * never_mtch: b0 0 0 0 1 1
578 * ------------------------------
579 * Result: key: b01 10 11 11 00 00
581 static enum ice_status
582 ice_gen_key_word(u8 val, u8 valid, u8 dont_care, u8 nvr_mtch, u8 *key,
585 u8 in_key = *key, in_key_inv = *key_inv;
588 /* 'dont_care' and 'nvr_mtch' masks cannot overlap */
589 if ((dont_care ^ nvr_mtch) != (dont_care | nvr_mtch))
595 /* encode the 8 bits into 8-bit key and 8-bit key invert */
596 for (i = 0; i < 8; i++) {
600 if (!(valid & 0x1)) { /* change only valid bits */
601 *key |= (in_key & 0x1) << 7;
602 *key_inv |= (in_key_inv & 0x1) << 7;
603 } else if (dont_care & 0x1) { /* don't care bit */
604 *key |= ICE_DC_KEY << 7;
605 *key_inv |= ICE_DC_KEYINV << 7;
606 } else if (nvr_mtch & 0x1) { /* never match bit */
607 *key |= ICE_NM_KEY << 7;
608 *key_inv |= ICE_NM_KEYINV << 7;
609 } else if (val & 0x01) { /* exact 1 match */
610 *key |= ICE_1_KEY << 7;
611 *key_inv |= ICE_1_KEYINV << 7;
612 } else { /* exact 0 match */
613 *key |= ICE_0_KEY << 7;
614 *key_inv |= ICE_0_KEYINV << 7;
629 * ice_bits_max_set - determine if the number of bits set is within a maximum
630 * @mask: pointer to the byte array which is the mask
631 * @size: the number of bytes in the mask
632 * @max: the max number of set bits
634 * This function determines if there are at most 'max' number of bits set in an
635 * array. Returns true if the number for bits set is <= max or will return false
638 static bool ice_bits_max_set(const u8 *mask, u16 size, u16 max)
643 /* check each byte */
644 for (i = 0; i < size; i++) {
645 /* if 0, go to next byte */
649 /* We know there is at least one set bit in this byte because of
650 * the above check; if we already have found 'max' number of
651 * bits set, then we can return failure now.
656 /* count the bits in this byte, checking threshold */
657 count += ice_hweight8(mask[i]);
666 * ice_set_key - generate a variable sized key with multiples of 16-bits
667 * @key: pointer to where the key will be stored
668 * @size: the size of the complete key in bytes (must be even)
669 * @val: array of 8-bit values that makes up the value portion of the key
670 * @upd: array of 8-bit masks that determine what key portion to update
671 * @dc: array of 8-bit masks that make up the don't care mask
672 * @nm: array of 8-bit masks that make up the never match mask
673 * @off: the offset of the first byte in the key to update
674 * @len: the number of bytes in the key update
676 * This function generates a key from a value, a don't care mask and a never
678 * upd, dc, and nm are optional parameters, and can be NULL:
679 * upd == NULL --> udp mask is all 1's (update all bits)
680 * dc == NULL --> dc mask is all 0's (no don't care bits)
681 * nm == NULL --> nm mask is all 0's (no never match bits)
684 ice_set_key(u8 *key, u16 size, u8 *val, u8 *upd, u8 *dc, u8 *nm, u16 off,
690 /* size must be a multiple of 2 bytes. */
693 half_size = size / 2;
695 if (off + len > half_size)
698 /* Make sure at most one bit is set in the never match mask. Having more
699 * than one never match mask bit set will cause HW to consume excessive
700 * power otherwise; this is a power management efficiency check.
702 #define ICE_NVR_MTCH_BITS_MAX 1
703 if (nm && !ice_bits_max_set(nm, len, ICE_NVR_MTCH_BITS_MAX))
706 for (i = 0; i < len; i++)
707 if (ice_gen_key_word(val[i], upd ? upd[i] : 0xff,
708 dc ? dc[i] : 0, nm ? nm[i] : 0,
709 key + off + i, key + half_size + off + i))
716 * ice_acquire_global_cfg_lock
717 * @hw: pointer to the HW structure
718 * @access: access type (read or write)
720 * This function will request ownership of the global config lock for reading
721 * or writing of the package. When attempting to obtain write access, the
722 * caller must check for the following two return values:
724 * ICE_SUCCESS - Means the caller has acquired the global config lock
725 * and can perform writing of the package.
726 * ICE_ERR_AQ_NO_WORK - Indicates another driver has already written the
727 * package or has found that no update was necessary; in
728 * this case, the caller can just skip performing any
729 * update of the package.
731 static enum ice_status
732 ice_acquire_global_cfg_lock(struct ice_hw *hw,
733 enum ice_aq_res_access_type access)
735 enum ice_status status;
737 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
739 status = ice_acquire_res(hw, ICE_GLOBAL_CFG_LOCK_RES_ID, access,
740 ICE_GLOBAL_CFG_LOCK_TIMEOUT);
742 if (status == ICE_ERR_AQ_NO_WORK)
743 ice_debug(hw, ICE_DBG_PKG,
744 "Global config lock: No work to do\n");
750 * ice_release_global_cfg_lock
751 * @hw: pointer to the HW structure
753 * This function will release the global config lock.
755 static void ice_release_global_cfg_lock(struct ice_hw *hw)
757 ice_release_res(hw, ICE_GLOBAL_CFG_LOCK_RES_ID);
761 * ice_acquire_change_lock
762 * @hw: pointer to the HW structure
763 * @access: access type (read or write)
765 * This function will request ownership of the change lock.
768 ice_acquire_change_lock(struct ice_hw *hw, enum ice_aq_res_access_type access)
770 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
772 return ice_acquire_res(hw, ICE_CHANGE_LOCK_RES_ID, access,
773 ICE_CHANGE_LOCK_TIMEOUT);
777 * ice_release_change_lock
778 * @hw: pointer to the HW structure
780 * This function will release the change lock using the proper Admin Command.
782 void ice_release_change_lock(struct ice_hw *hw)
784 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
786 ice_release_res(hw, ICE_CHANGE_LOCK_RES_ID);
790 * ice_aq_download_pkg
791 * @hw: pointer to the hardware structure
792 * @pkg_buf: the package buffer to transfer
793 * @buf_size: the size of the package buffer
794 * @last_buf: last buffer indicator
795 * @error_offset: returns error offset
796 * @error_info: returns error information
797 * @cd: pointer to command details structure or NULL
799 * Download Package (0x0C40)
801 static enum ice_status
802 ice_aq_download_pkg(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf,
803 u16 buf_size, bool last_buf, u32 *error_offset,
804 u32 *error_info, struct ice_sq_cd *cd)
806 struct ice_aqc_download_pkg *cmd;
807 struct ice_aq_desc desc;
808 enum ice_status status;
810 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
817 cmd = &desc.params.download_pkg;
818 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_download_pkg);
819 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
822 cmd->flags |= ICE_AQC_DOWNLOAD_PKG_LAST_BUF;
824 status = ice_aq_send_cmd(hw, &desc, pkg_buf, buf_size, cd);
825 if (status == ICE_ERR_AQ_ERROR) {
826 /* Read error from buffer only when the FW returned an error */
827 struct ice_aqc_download_pkg_resp *resp;
829 resp = (struct ice_aqc_download_pkg_resp *)pkg_buf;
831 *error_offset = LE32_TO_CPU(resp->error_offset);
833 *error_info = LE32_TO_CPU(resp->error_info);
840 * ice_aq_upload_section
841 * @hw: pointer to the hardware structure
842 * @pkg_buf: the package buffer which will receive the section
843 * @buf_size: the size of the package buffer
844 * @cd: pointer to command details structure or NULL
846 * Upload Section (0x0C41)
849 ice_aq_upload_section(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf,
850 u16 buf_size, struct ice_sq_cd *cd)
852 struct ice_aq_desc desc;
854 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
855 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_upload_section);
856 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
858 return ice_aq_send_cmd(hw, &desc, pkg_buf, buf_size, cd);
863 * @hw: pointer to the hardware structure
864 * @pkg_buf: the package cmd buffer
865 * @buf_size: the size of the package cmd buffer
866 * @last_buf: last buffer indicator
867 * @error_offset: returns error offset
868 * @error_info: returns error information
869 * @cd: pointer to command details structure or NULL
871 * Update Package (0x0C42)
873 static enum ice_status
874 ice_aq_update_pkg(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf, u16 buf_size,
875 bool last_buf, u32 *error_offset, u32 *error_info,
876 struct ice_sq_cd *cd)
878 struct ice_aqc_download_pkg *cmd;
879 struct ice_aq_desc desc;
880 enum ice_status status;
882 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
889 cmd = &desc.params.download_pkg;
890 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_update_pkg);
891 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
894 cmd->flags |= ICE_AQC_DOWNLOAD_PKG_LAST_BUF;
896 status = ice_aq_send_cmd(hw, &desc, pkg_buf, buf_size, cd);
897 if (status == ICE_ERR_AQ_ERROR) {
898 /* Read error from buffer only when the FW returned an error */
899 struct ice_aqc_download_pkg_resp *resp;
901 resp = (struct ice_aqc_download_pkg_resp *)pkg_buf;
903 *error_offset = LE32_TO_CPU(resp->error_offset);
905 *error_info = LE32_TO_CPU(resp->error_info);
912 * ice_find_seg_in_pkg
913 * @hw: pointer to the hardware structure
914 * @seg_type: the segment type to search for (i.e., SEGMENT_TYPE_CPK)
915 * @pkg_hdr: pointer to the package header to be searched
917 * This function searches a package file for a particular segment type. On
918 * success it returns a pointer to the segment header, otherwise it will
921 static struct ice_generic_seg_hdr *
922 ice_find_seg_in_pkg(struct ice_hw *hw, u32 seg_type,
923 struct ice_pkg_hdr *pkg_hdr)
927 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
928 ice_debug(hw, ICE_DBG_PKG, "Package format version: %d.%d.%d.%d\n",
929 pkg_hdr->pkg_format_ver.major, pkg_hdr->pkg_format_ver.minor,
930 pkg_hdr->pkg_format_ver.update,
931 pkg_hdr->pkg_format_ver.draft);
933 /* Search all package segments for the requested segment type */
934 for (i = 0; i < LE32_TO_CPU(pkg_hdr->seg_count); i++) {
935 struct ice_generic_seg_hdr *seg;
937 seg = (struct ice_generic_seg_hdr *)
938 ((u8 *)pkg_hdr + LE32_TO_CPU(pkg_hdr->seg_offset[i]));
940 if (LE32_TO_CPU(seg->seg_type) == seg_type)
949 * @hw: pointer to the hardware structure
950 * @bufs: pointer to an array of buffers
951 * @count: the number of buffers in the array
953 * Obtains change lock and updates package.
956 ice_update_pkg(struct ice_hw *hw, struct ice_buf *bufs, u32 count)
958 enum ice_status status;
961 status = ice_acquire_change_lock(hw, ICE_RES_WRITE);
965 for (i = 0; i < count; i++) {
966 struct ice_buf_hdr *bh = (struct ice_buf_hdr *)(bufs + i);
967 bool last = ((i + 1) == count);
969 status = ice_aq_update_pkg(hw, bh, LE16_TO_CPU(bh->data_end),
970 last, &offset, &info, NULL);
973 ice_debug(hw, ICE_DBG_PKG,
974 "Update pkg failed: err %d off %d inf %d\n",
975 status, offset, info);
980 ice_release_change_lock(hw);
987 * @hw: pointer to the hardware structure
988 * @bufs: pointer to an array of buffers
989 * @count: the number of buffers in the array
991 * Obtains global config lock and downloads the package configuration buffers
992 * to the firmware. Metadata buffers are skipped, and the first metadata buffer
993 * found indicates that the rest of the buffers are all metadata buffers.
995 static enum ice_status
996 ice_dwnld_cfg_bufs(struct ice_hw *hw, struct ice_buf *bufs, u32 count)
998 enum ice_status status;
999 struct ice_buf_hdr *bh;
1000 u32 offset, info, i;
1002 if (!bufs || !count)
1003 return ICE_ERR_PARAM;
1005 /* If the first buffer's first section has its metadata bit set
1006 * then there are no buffers to be downloaded, and the operation is
1007 * considered a success.
1009 bh = (struct ice_buf_hdr *)bufs;
1010 if (LE32_TO_CPU(bh->section_entry[0].type) & ICE_METADATA_BUF)
1013 /* reset pkg_dwnld_status in case this function is called in the
1014 * reset/rebuild flow
1016 hw->pkg_dwnld_status = ICE_AQ_RC_OK;
1018 status = ice_acquire_global_cfg_lock(hw, ICE_RES_WRITE);
1020 if (status == ICE_ERR_AQ_NO_WORK)
1021 hw->pkg_dwnld_status = ICE_AQ_RC_EEXIST;
1023 hw->pkg_dwnld_status = hw->adminq.sq_last_status;
1027 for (i = 0; i < count; i++) {
1028 bool last = ((i + 1) == count);
1031 /* check next buffer for metadata flag */
1032 bh = (struct ice_buf_hdr *)(bufs + i + 1);
1034 /* A set metadata flag in the next buffer will signal
1035 * that the current buffer will be the last buffer
1038 if (LE16_TO_CPU(bh->section_count))
1039 if (LE32_TO_CPU(bh->section_entry[0].type) &
1044 bh = (struct ice_buf_hdr *)(bufs + i);
1046 status = ice_aq_download_pkg(hw, bh, ICE_PKG_BUF_SIZE, last,
1047 &offset, &info, NULL);
1049 /* Save AQ status from download package */
1050 hw->pkg_dwnld_status = hw->adminq.sq_last_status;
1052 ice_debug(hw, ICE_DBG_PKG,
1053 "Pkg download failed: err %d off %d inf %d\n",
1054 status, offset, info);
1063 ice_release_global_cfg_lock(hw);
1069 * ice_aq_get_pkg_info_list
1070 * @hw: pointer to the hardware structure
1071 * @pkg_info: the buffer which will receive the information list
1072 * @buf_size: the size of the pkg_info information buffer
1073 * @cd: pointer to command details structure or NULL
1075 * Get Package Info List (0x0C43)
1077 static enum ice_status
1078 ice_aq_get_pkg_info_list(struct ice_hw *hw,
1079 struct ice_aqc_get_pkg_info_resp *pkg_info,
1080 u16 buf_size, struct ice_sq_cd *cd)
1082 struct ice_aq_desc desc;
1084 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1085 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_pkg_info_list);
1087 return ice_aq_send_cmd(hw, &desc, pkg_info, buf_size, cd);
1092 * @hw: pointer to the hardware structure
1093 * @ice_seg: pointer to the segment of the package to be downloaded
1095 * Handles the download of a complete package.
1097 static enum ice_status
1098 ice_download_pkg(struct ice_hw *hw, struct ice_seg *ice_seg)
1100 struct ice_buf_table *ice_buf_tbl;
1102 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1103 ice_debug(hw, ICE_DBG_PKG, "Segment format version: %d.%d.%d.%d\n",
1104 ice_seg->hdr.seg_format_ver.major,
1105 ice_seg->hdr.seg_format_ver.minor,
1106 ice_seg->hdr.seg_format_ver.update,
1107 ice_seg->hdr.seg_format_ver.draft);
1109 ice_debug(hw, ICE_DBG_PKG, "Seg: type 0x%X, size %d, name %s\n",
1110 LE32_TO_CPU(ice_seg->hdr.seg_type),
1111 LE32_TO_CPU(ice_seg->hdr.seg_size), ice_seg->hdr.seg_id);
1113 ice_buf_tbl = ice_find_buf_table(ice_seg);
1115 ice_debug(hw, ICE_DBG_PKG, "Seg buf count: %d\n",
1116 LE32_TO_CPU(ice_buf_tbl->buf_count));
1118 return ice_dwnld_cfg_bufs(hw, ice_buf_tbl->buf_array,
1119 LE32_TO_CPU(ice_buf_tbl->buf_count));
1124 * @hw: pointer to the hardware structure
1125 * @pkg_hdr: pointer to the driver's package hdr
1127 * Saves off the package details into the HW structure.
1129 static enum ice_status
1130 ice_init_pkg_info(struct ice_hw *hw, struct ice_pkg_hdr *pkg_hdr)
1132 struct ice_global_metadata_seg *meta_seg;
1133 struct ice_generic_seg_hdr *seg_hdr;
1135 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1137 return ICE_ERR_PARAM;
1139 meta_seg = (struct ice_global_metadata_seg *)
1140 ice_find_seg_in_pkg(hw, SEGMENT_TYPE_METADATA, pkg_hdr);
1142 hw->pkg_ver = meta_seg->pkg_ver;
1143 ice_memcpy(hw->pkg_name, meta_seg->pkg_name,
1144 sizeof(hw->pkg_name), ICE_NONDMA_TO_NONDMA);
1146 ice_debug(hw, ICE_DBG_PKG, "Pkg: %d.%d.%d.%d, %s\n",
1147 meta_seg->pkg_ver.major, meta_seg->pkg_ver.minor,
1148 meta_seg->pkg_ver.update, meta_seg->pkg_ver.draft,
1149 meta_seg->pkg_name);
1151 ice_debug(hw, ICE_DBG_INIT,
1152 "Did not find metadata segment in driver package\n");
1156 seg_hdr = ice_find_seg_in_pkg(hw, SEGMENT_TYPE_ICE, pkg_hdr);
1158 hw->ice_pkg_ver = seg_hdr->seg_format_ver;
1159 ice_memcpy(hw->ice_pkg_name, seg_hdr->seg_id,
1160 sizeof(hw->ice_pkg_name), ICE_NONDMA_TO_NONDMA);
1162 ice_debug(hw, ICE_DBG_PKG, "Ice Seg: %d.%d.%d.%d, %s\n",
1163 seg_hdr->seg_format_ver.major,
1164 seg_hdr->seg_format_ver.minor,
1165 seg_hdr->seg_format_ver.update,
1166 seg_hdr->seg_format_ver.draft,
1169 ice_debug(hw, ICE_DBG_INIT,
1170 "Did not find ice segment in driver package\n");
1179 * @hw: pointer to the hardware structure
1181 * Store details of the package currently loaded in HW into the HW structure.
1183 static enum ice_status ice_get_pkg_info(struct ice_hw *hw)
1185 struct ice_aqc_get_pkg_info_resp *pkg_info;
1186 enum ice_status status;
1190 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1192 size = ice_struct_size(pkg_info, pkg_info, ICE_PKG_CNT - 1);
1193 pkg_info = (struct ice_aqc_get_pkg_info_resp *)ice_malloc(hw, size);
1195 return ICE_ERR_NO_MEMORY;
1197 status = ice_aq_get_pkg_info_list(hw, pkg_info, size, NULL);
1199 goto init_pkg_free_alloc;
1201 for (i = 0; i < LE32_TO_CPU(pkg_info->count); i++) {
1202 #define ICE_PKG_FLAG_COUNT 4
1203 char flags[ICE_PKG_FLAG_COUNT + 1] = { 0 };
1206 if (pkg_info->pkg_info[i].is_active) {
1207 flags[place++] = 'A';
1208 hw->active_pkg_ver = pkg_info->pkg_info[i].ver;
1209 hw->active_track_id =
1210 LE32_TO_CPU(pkg_info->pkg_info[i].track_id);
1211 ice_memcpy(hw->active_pkg_name,
1212 pkg_info->pkg_info[i].name,
1213 sizeof(pkg_info->pkg_info[i].name),
1214 ICE_NONDMA_TO_NONDMA);
1215 hw->active_pkg_in_nvm = pkg_info->pkg_info[i].is_in_nvm;
1217 if (pkg_info->pkg_info[i].is_active_at_boot)
1218 flags[place++] = 'B';
1219 if (pkg_info->pkg_info[i].is_modified)
1220 flags[place++] = 'M';
1221 if (pkg_info->pkg_info[i].is_in_nvm)
1222 flags[place++] = 'N';
1224 ice_debug(hw, ICE_DBG_PKG, "Pkg[%d]: %d.%d.%d.%d,%s,%s\n",
1225 i, pkg_info->pkg_info[i].ver.major,
1226 pkg_info->pkg_info[i].ver.minor,
1227 pkg_info->pkg_info[i].ver.update,
1228 pkg_info->pkg_info[i].ver.draft,
1229 pkg_info->pkg_info[i].name, flags);
1232 init_pkg_free_alloc:
1233 ice_free(hw, pkg_info);
1239 * ice_find_label_value
1240 * @ice_seg: pointer to the ice segment (non-NULL)
1241 * @name: name of the label to search for
1242 * @type: the section type that will contain the label
1243 * @value: pointer to a value that will return the label's value if found
1245 * Finds a label's value given the label name and the section type to search.
1246 * The ice_seg parameter must not be NULL since the first call to
1247 * ice_enum_labels requires a pointer to an actual ice_seg structure.
1250 ice_find_label_value(struct ice_seg *ice_seg, char const *name, u32 type,
1253 struct ice_pkg_enum state;
1257 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1260 return ICE_ERR_PARAM;
1263 label_name = ice_enum_labels(ice_seg, type, &state, &val);
1264 if (label_name && !strcmp(label_name, name)) {
1270 } while (label_name);
1276 * ice_verify_pkg - verify package
1277 * @pkg: pointer to the package buffer
1278 * @len: size of the package buffer
1280 * Verifies various attributes of the package file, including length, format
1281 * version, and the requirement of at least one segment.
1283 static enum ice_status ice_verify_pkg(struct ice_pkg_hdr *pkg, u32 len)
1288 if (len < sizeof(*pkg))
1289 return ICE_ERR_BUF_TOO_SHORT;
1291 if (pkg->pkg_format_ver.major != ICE_PKG_FMT_VER_MAJ ||
1292 pkg->pkg_format_ver.minor != ICE_PKG_FMT_VER_MNR ||
1293 pkg->pkg_format_ver.update != ICE_PKG_FMT_VER_UPD ||
1294 pkg->pkg_format_ver.draft != ICE_PKG_FMT_VER_DFT)
1297 /* pkg must have at least one segment */
1298 seg_count = LE32_TO_CPU(pkg->seg_count);
1302 /* make sure segment array fits in package length */
1303 if (len < ice_struct_size(pkg, seg_offset, seg_count - 1))
1304 return ICE_ERR_BUF_TOO_SHORT;
1306 /* all segments must fit within length */
1307 for (i = 0; i < seg_count; i++) {
1308 u32 off = LE32_TO_CPU(pkg->seg_offset[i]);
1309 struct ice_generic_seg_hdr *seg;
1311 /* segment header must fit */
1312 if (len < off + sizeof(*seg))
1313 return ICE_ERR_BUF_TOO_SHORT;
1315 seg = (struct ice_generic_seg_hdr *)((u8 *)pkg + off);
1317 /* segment body must fit */
1318 if (len < off + LE32_TO_CPU(seg->seg_size))
1319 return ICE_ERR_BUF_TOO_SHORT;
1326 * ice_free_seg - free package segment pointer
1327 * @hw: pointer to the hardware structure
1329 * Frees the package segment pointer in the proper manner, depending on if the
1330 * segment was allocated or just the passed in pointer was stored.
1332 void ice_free_seg(struct ice_hw *hw)
1335 ice_free(hw, hw->pkg_copy);
1336 hw->pkg_copy = NULL;
1343 * ice_init_pkg_regs - initialize additional package registers
1344 * @hw: pointer to the hardware structure
1346 static void ice_init_pkg_regs(struct ice_hw *hw)
1348 #define ICE_SW_BLK_INP_MASK_L 0xFFFFFFFF
1349 #define ICE_SW_BLK_INP_MASK_H 0x0000FFFF
1350 #define ICE_SW_BLK_IDX 0
1352 /* setup Switch block input mask, which is 48-bits in two parts */
1353 wr32(hw, GL_PREEXT_L2_PMASK0(ICE_SW_BLK_IDX), ICE_SW_BLK_INP_MASK_L);
1354 wr32(hw, GL_PREEXT_L2_PMASK1(ICE_SW_BLK_IDX), ICE_SW_BLK_INP_MASK_H);
1358 * ice_chk_pkg_version - check package version for compatibility with driver
1359 * @pkg_ver: pointer to a version structure to check
1361 * Check to make sure that the package about to be downloaded is compatible with
1362 * the driver. To be compatible, the major and minor components of the package
1363 * version must match our ICE_PKG_SUPP_VER_MAJ and ICE_PKG_SUPP_VER_MNR
1366 static enum ice_status ice_chk_pkg_version(struct ice_pkg_ver *pkg_ver)
1368 if (pkg_ver->major != ICE_PKG_SUPP_VER_MAJ ||
1369 pkg_ver->minor != ICE_PKG_SUPP_VER_MNR)
1370 return ICE_ERR_NOT_SUPPORTED;
1376 * ice_chk_pkg_compat
1377 * @hw: pointer to the hardware structure
1378 * @ospkg: pointer to the package hdr
1379 * @seg: pointer to the package segment hdr
1381 * This function checks the package version compatibility with driver and NVM
1383 static enum ice_status
1384 ice_chk_pkg_compat(struct ice_hw *hw, struct ice_pkg_hdr *ospkg,
1385 struct ice_seg **seg)
1387 struct ice_aqc_get_pkg_info_resp *pkg;
1388 enum ice_status status;
1392 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1394 /* Check package version compatibility */
1395 status = ice_chk_pkg_version(&hw->pkg_ver);
1397 ice_debug(hw, ICE_DBG_INIT, "Package version check failed.\n");
1401 /* find ICE segment in given package */
1402 *seg = (struct ice_seg *)ice_find_seg_in_pkg(hw, SEGMENT_TYPE_ICE,
1405 ice_debug(hw, ICE_DBG_INIT, "no ice segment in package.\n");
1409 /* Check if FW is compatible with the OS package */
1410 size = ice_struct_size(pkg, pkg_info, ICE_PKG_CNT - 1);
1411 pkg = (struct ice_aqc_get_pkg_info_resp *)ice_malloc(hw, size);
1413 return ICE_ERR_NO_MEMORY;
1415 status = ice_aq_get_pkg_info_list(hw, pkg, size, NULL);
1417 goto fw_ddp_compat_free_alloc;
1419 for (i = 0; i < LE32_TO_CPU(pkg->count); i++) {
1420 /* loop till we find the NVM package */
1421 if (!pkg->pkg_info[i].is_in_nvm)
1423 if ((*seg)->hdr.seg_format_ver.major !=
1424 pkg->pkg_info[i].ver.major ||
1425 (*seg)->hdr.seg_format_ver.minor >
1426 pkg->pkg_info[i].ver.minor) {
1427 status = ICE_ERR_FW_DDP_MISMATCH;
1428 ice_debug(hw, ICE_DBG_INIT,
1429 "OS package is not compatible with NVM.\n");
1431 /* done processing NVM package so break */
1434 fw_ddp_compat_free_alloc:
1440 * ice_init_pkg - initialize/download package
1441 * @hw: pointer to the hardware structure
1442 * @buf: pointer to the package buffer
1443 * @len: size of the package buffer
1445 * This function initializes a package. The package contains HW tables
1446 * required to do packet processing. First, the function extracts package
1447 * information such as version. Then it finds the ice configuration segment
1448 * within the package; this function then saves a copy of the segment pointer
1449 * within the supplied package buffer. Next, the function will cache any hints
1450 * from the package, followed by downloading the package itself. Note, that if
1451 * a previous PF driver has already downloaded the package successfully, then
1452 * the current driver will not have to download the package again.
1454 * The local package contents will be used to query default behavior and to
1455 * update specific sections of the HW's version of the package (e.g. to update
1456 * the parse graph to understand new protocols).
1458 * This function stores a pointer to the package buffer memory, and it is
1459 * expected that the supplied buffer will not be freed immediately. If the
1460 * package buffer needs to be freed, such as when read from a file, use
1461 * ice_copy_and_init_pkg() instead of directly calling ice_init_pkg() in this
1464 enum ice_status ice_init_pkg(struct ice_hw *hw, u8 *buf, u32 len)
1466 struct ice_pkg_hdr *pkg;
1467 enum ice_status status;
1468 struct ice_seg *seg;
1471 return ICE_ERR_PARAM;
1473 pkg = (struct ice_pkg_hdr *)buf;
1474 status = ice_verify_pkg(pkg, len);
1476 ice_debug(hw, ICE_DBG_INIT, "failed to verify pkg (err: %d)\n",
1481 /* initialize package info */
1482 status = ice_init_pkg_info(hw, pkg);
1486 /* before downloading the package, check package version for
1487 * compatibility with driver
1489 status = ice_chk_pkg_compat(hw, pkg, &seg);
1493 /* initialize package hints and then download package */
1494 ice_init_pkg_hints(hw, seg);
1495 status = ice_download_pkg(hw, seg);
1496 if (status == ICE_ERR_AQ_NO_WORK) {
1497 ice_debug(hw, ICE_DBG_INIT,
1498 "package previously loaded - no work.\n");
1499 status = ICE_SUCCESS;
1502 /* Get information on the package currently loaded in HW, then make sure
1503 * the driver is compatible with this version.
1506 status = ice_get_pkg_info(hw);
1508 status = ice_chk_pkg_version(&hw->active_pkg_ver);
1513 /* on successful package download update other required
1514 * registers to support the package and fill HW tables
1515 * with package content.
1517 ice_init_pkg_regs(hw);
1518 ice_fill_blk_tbls(hw);
1520 ice_debug(hw, ICE_DBG_INIT, "package load failed, %d\n",
1528 * ice_copy_and_init_pkg - initialize/download a copy of the package
1529 * @hw: pointer to the hardware structure
1530 * @buf: pointer to the package buffer
1531 * @len: size of the package buffer
1533 * This function copies the package buffer, and then calls ice_init_pkg() to
1534 * initialize the copied package contents.
1536 * The copying is necessary if the package buffer supplied is constant, or if
1537 * the memory may disappear shortly after calling this function.
1539 * If the package buffer resides in the data segment and can be modified, the
1540 * caller is free to use ice_init_pkg() instead of ice_copy_and_init_pkg().
1542 * However, if the package buffer needs to be copied first, such as when being
1543 * read from a file, the caller should use ice_copy_and_init_pkg().
1545 * This function will first copy the package buffer, before calling
1546 * ice_init_pkg(). The caller is free to immediately destroy the original
1547 * package buffer, as the new copy will be managed by this function and
1550 enum ice_status ice_copy_and_init_pkg(struct ice_hw *hw, const u8 *buf, u32 len)
1552 enum ice_status status;
1556 return ICE_ERR_PARAM;
1558 buf_copy = (u8 *)ice_memdup(hw, buf, len, ICE_NONDMA_TO_NONDMA);
1560 status = ice_init_pkg(hw, buf_copy, len);
1562 /* Free the copy, since we failed to initialize the package */
1563 ice_free(hw, buf_copy);
1565 /* Track the copied pkg so we can free it later */
1566 hw->pkg_copy = buf_copy;
1575 * @hw: pointer to the HW structure
1577 * Allocates a package buffer and returns a pointer to the buffer header.
1578 * Note: all package contents must be in Little Endian form.
1580 static struct ice_buf_build *ice_pkg_buf_alloc(struct ice_hw *hw)
1582 struct ice_buf_build *bld;
1583 struct ice_buf_hdr *buf;
1585 bld = (struct ice_buf_build *)ice_malloc(hw, sizeof(*bld));
1589 buf = (struct ice_buf_hdr *)bld;
1590 buf->data_end = CPU_TO_LE16(offsetof(struct ice_buf_hdr,
1597 * @sect_type: section type
1598 * @section: pointer to section
1599 * @index: index of the field vector entry to be returned
1600 * @offset: ptr to variable that receives the offset in the field vector table
1602 * This is a callback function that can be passed to ice_pkg_enum_entry.
1603 * This function treats the given section as of type ice_sw_fv_section and
1604 * enumerates offset field. "offset" is an index into the field vector
1608 ice_sw_fv_handler(u32 sect_type, void *section, u32 index, u32 *offset)
1610 struct ice_sw_fv_section *fv_section =
1611 (struct ice_sw_fv_section *)section;
1613 if (!section || sect_type != ICE_SID_FLD_VEC_SW)
1615 if (index >= LE16_TO_CPU(fv_section->count))
1618 /* "index" passed in to this function is relative to a given
1619 * 4k block. To get to the true index into the field vector
1620 * table need to add the relative index to the base_offset
1621 * field of this section
1623 *offset = LE16_TO_CPU(fv_section->base_offset) + index;
1624 return fv_section->fv + index;
1628 * ice_get_sw_prof_type - determine switch profile type
1629 * @hw: pointer to the HW structure
1630 * @fv: pointer to the switch field vector
1632 static enum ice_prof_type
1633 ice_get_sw_prof_type(struct ice_hw *hw, struct ice_fv *fv)
1637 for (i = 0; i < hw->blk[ICE_BLK_SW].es.fvw; i++) {
1638 /* UDP tunnel will have UDP_OF protocol ID and VNI offset */
1639 if (fv->ew[i].prot_id == (u8)ICE_PROT_UDP_OF &&
1640 fv->ew[i].off == ICE_VNI_OFFSET)
1641 return ICE_PROF_TUN_UDP;
1643 /* GRE tunnel will have GRE protocol */
1644 if (fv->ew[i].prot_id == (u8)ICE_PROT_GRE_OF)
1645 return ICE_PROF_TUN_GRE;
1648 return ICE_PROF_NON_TUN;
1652 * ice_get_sw_fv_bitmap - Get switch field vector bitmap based on profile type
1653 * @hw: pointer to hardware structure
1654 * @req_profs: type of profiles requested
1655 * @bm: pointer to memory for returning the bitmap of field vectors
1658 ice_get_sw_fv_bitmap(struct ice_hw *hw, enum ice_prof_type req_profs,
1661 struct ice_pkg_enum state;
1662 struct ice_seg *ice_seg;
1665 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1667 if (req_profs == ICE_PROF_ALL) {
1670 for (i = 0; i < ICE_MAX_NUM_PROFILES; i++)
1675 ice_zero_bitmap(bm, ICE_MAX_NUM_PROFILES);
1679 enum ice_prof_type prof_type;
1682 fv = (struct ice_fv *)
1683 ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1684 &offset, ice_sw_fv_handler);
1688 /* Determine field vector type */
1689 prof_type = ice_get_sw_prof_type(hw, fv);
1691 if (req_profs & prof_type)
1692 ice_set_bit((u16)offset, bm);
1698 * ice_get_sw_fv_list
1699 * @hw: pointer to the HW structure
1700 * @prot_ids: field vector to search for with a given protocol ID
1701 * @ids_cnt: lookup/protocol count
1702 * @bm: bitmap of field vectors to consider
1703 * @fv_list: Head of a list
1705 * Finds all the field vector entries from switch block that contain
1706 * a given protocol ID and returns a list of structures of type
1707 * "ice_sw_fv_list_entry". Every structure in the list has a field vector
1708 * definition and profile ID information
1709 * NOTE: The caller of the function is responsible for freeing the memory
1710 * allocated for every list entry.
1713 ice_get_sw_fv_list(struct ice_hw *hw, u8 *prot_ids, u16 ids_cnt,
1714 ice_bitmap_t *bm, struct LIST_HEAD_TYPE *fv_list)
1716 struct ice_sw_fv_list_entry *fvl;
1717 struct ice_sw_fv_list_entry *tmp;
1718 struct ice_pkg_enum state;
1719 struct ice_seg *ice_seg;
1723 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1725 if (!ids_cnt || !hw->seg)
1726 return ICE_ERR_PARAM;
1732 fv = (struct ice_fv *)
1733 ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1734 &offset, ice_sw_fv_handler);
1739 /* If field vector is not in the bitmap list, then skip this
1742 if (!ice_is_bit_set(bm, (u16)offset))
1745 for (i = 0; i < ids_cnt; i++) {
1748 /* This code assumes that if a switch field vector line
1749 * has a matching protocol, then this line will contain
1750 * the entries necessary to represent every field in
1751 * that protocol header.
1753 for (j = 0; j < hw->blk[ICE_BLK_SW].es.fvw; j++)
1754 if (fv->ew[j].prot_id == prot_ids[i])
1756 if (j >= hw->blk[ICE_BLK_SW].es.fvw)
1758 if (i + 1 == ids_cnt) {
1759 fvl = (struct ice_sw_fv_list_entry *)
1760 ice_malloc(hw, sizeof(*fvl));
1764 fvl->profile_id = offset;
1765 LIST_ADD(&fvl->list_entry, fv_list);
1770 if (LIST_EMPTY(fv_list))
1775 LIST_FOR_EACH_ENTRY_SAFE(fvl, tmp, fv_list, ice_sw_fv_list_entry,
1777 LIST_DEL(&fvl->list_entry);
1781 return ICE_ERR_NO_MEMORY;
1785 * ice_init_prof_result_bm - Initialize the profile result index bitmap
1786 * @hw: pointer to hardware structure
1788 void ice_init_prof_result_bm(struct ice_hw *hw)
1790 struct ice_pkg_enum state;
1791 struct ice_seg *ice_seg;
1794 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1804 fv = (struct ice_fv *)
1805 ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1806 &off, ice_sw_fv_handler);
1811 ice_zero_bitmap(hw->switch_info->prof_res_bm[off],
1814 /* Determine empty field vector indices, these can be
1815 * used for recipe results. Skip index 0, since it is
1816 * always used for Switch ID.
1818 for (i = 1; i < ICE_MAX_FV_WORDS; i++)
1819 if (fv->ew[i].prot_id == ICE_PROT_INVALID &&
1820 fv->ew[i].off == ICE_FV_OFFSET_INVAL)
1822 hw->switch_info->prof_res_bm[off]);
1828 * @hw: pointer to the HW structure
1829 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1831 * Frees a package buffer
1833 static void ice_pkg_buf_free(struct ice_hw *hw, struct ice_buf_build *bld)
1839 * ice_pkg_buf_reserve_section
1840 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1841 * @count: the number of sections to reserve
1843 * Reserves one or more section table entries in a package buffer. This routine
1844 * can be called multiple times as long as they are made before calling
1845 * ice_pkg_buf_alloc_section(). Once ice_pkg_buf_alloc_section()
1846 * is called once, the number of sections that can be allocated will not be able
1847 * to be increased; not using all reserved sections is fine, but this will
1848 * result in some wasted space in the buffer.
1849 * Note: all package contents must be in Little Endian form.
1851 static enum ice_status
1852 ice_pkg_buf_reserve_section(struct ice_buf_build *bld, u16 count)
1854 struct ice_buf_hdr *buf;
1859 return ICE_ERR_PARAM;
1861 buf = (struct ice_buf_hdr *)&bld->buf;
1863 /* already an active section, can't increase table size */
1864 section_count = LE16_TO_CPU(buf->section_count);
1865 if (section_count > 0)
1868 if (bld->reserved_section_table_entries + count > ICE_MAX_S_COUNT)
1870 bld->reserved_section_table_entries += count;
1872 data_end = LE16_TO_CPU(buf->data_end) +
1873 (count * sizeof(buf->section_entry[0]));
1874 buf->data_end = CPU_TO_LE16(data_end);
1880 * ice_pkg_buf_alloc_section
1881 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1882 * @type: the section type value
1883 * @size: the size of the section to reserve (in bytes)
1885 * Reserves memory in the buffer for a section's content and updates the
1886 * buffers' status accordingly. This routine returns a pointer to the first
1887 * byte of the section start within the buffer, which is used to fill in the
1889 * Note: all package contents must be in Little Endian form.
1892 ice_pkg_buf_alloc_section(struct ice_buf_build *bld, u32 type, u16 size)
1894 struct ice_buf_hdr *buf;
1898 if (!bld || !type || !size)
1901 buf = (struct ice_buf_hdr *)&bld->buf;
1903 /* check for enough space left in buffer */
1904 data_end = LE16_TO_CPU(buf->data_end);
1906 /* section start must align on 4 byte boundary */
1907 data_end = ICE_ALIGN(data_end, 4);
1909 if ((data_end + size) > ICE_MAX_S_DATA_END)
1912 /* check for more available section table entries */
1913 sect_count = LE16_TO_CPU(buf->section_count);
1914 if (sect_count < bld->reserved_section_table_entries) {
1915 void *section_ptr = ((u8 *)buf) + data_end;
1917 buf->section_entry[sect_count].offset = CPU_TO_LE16(data_end);
1918 buf->section_entry[sect_count].size = CPU_TO_LE16(size);
1919 buf->section_entry[sect_count].type = CPU_TO_LE32(type);
1922 buf->data_end = CPU_TO_LE16(data_end);
1924 buf->section_count = CPU_TO_LE16(sect_count + 1);
1928 /* no free section table entries */
1933 * ice_pkg_buf_alloc_single_section
1934 * @hw: pointer to the HW structure
1935 * @type: the section type value
1936 * @size: the size of the section to reserve (in bytes)
1937 * @section: returns pointer to the section
1939 * Allocates a package buffer with a single section.
1940 * Note: all package contents must be in Little Endian form.
1942 static struct ice_buf_build *
1943 ice_pkg_buf_alloc_single_section(struct ice_hw *hw, u32 type, u16 size,
1946 struct ice_buf_build *buf;
1951 buf = ice_pkg_buf_alloc(hw);
1955 if (ice_pkg_buf_reserve_section(buf, 1))
1956 goto ice_pkg_buf_alloc_single_section_err;
1958 *section = ice_pkg_buf_alloc_section(buf, type, size);
1960 goto ice_pkg_buf_alloc_single_section_err;
1964 ice_pkg_buf_alloc_single_section_err:
1965 ice_pkg_buf_free(hw, buf);
1970 * ice_pkg_buf_unreserve_section
1971 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1972 * @count: the number of sections to unreserve
1974 * Unreserves one or more section table entries in a package buffer, releasing
1975 * space that can be used for section data. This routine can be called
1976 * multiple times as long as they are made before calling
1977 * ice_pkg_buf_alloc_section(). Once ice_pkg_buf_alloc_section()
1978 * is called once, the number of sections that can be allocated will not be able
1979 * to be increased; not using all reserved sections is fine, but this will
1980 * result in some wasted space in the buffer.
1981 * Note: all package contents must be in Little Endian form.
1984 ice_pkg_buf_unreserve_section(struct ice_buf_build *bld, u16 count)
1986 struct ice_buf_hdr *buf;
1991 return ICE_ERR_PARAM;
1993 buf = (struct ice_buf_hdr *)&bld->buf;
1995 /* already an active section, can't decrease table size */
1996 section_count = LE16_TO_CPU(buf->section_count);
1997 if (section_count > 0)
2000 if (count > bld->reserved_section_table_entries)
2002 bld->reserved_section_table_entries -= count;
2004 data_end = LE16_TO_CPU(buf->data_end) -
2005 (count * sizeof(buf->section_entry[0]));
2006 buf->data_end = CPU_TO_LE16(data_end);
2012 * ice_pkg_buf_get_free_space
2013 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
2015 * Returns the number of free bytes remaining in the buffer.
2016 * Note: all package contents must be in Little Endian form.
2018 u16 ice_pkg_buf_get_free_space(struct ice_buf_build *bld)
2020 struct ice_buf_hdr *buf;
2025 buf = (struct ice_buf_hdr *)&bld->buf;
2026 return ICE_MAX_S_DATA_END - LE16_TO_CPU(buf->data_end);
2030 * ice_pkg_buf_get_active_sections
2031 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
2033 * Returns the number of active sections. Before using the package buffer
2034 * in an update package command, the caller should make sure that there is at
2035 * least one active section - otherwise, the buffer is not legal and should
2037 * Note: all package contents must be in Little Endian form.
2039 static u16 ice_pkg_buf_get_active_sections(struct ice_buf_build *bld)
2041 struct ice_buf_hdr *buf;
2046 buf = (struct ice_buf_hdr *)&bld->buf;
2047 return LE16_TO_CPU(buf->section_count);
2052 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
2054 * Return a pointer to the buffer's header
2056 static struct ice_buf *ice_pkg_buf(struct ice_buf_build *bld)
2065 * ice_tunnel_port_in_use_hlpr - helper function to determine tunnel usage
2066 * @hw: pointer to the HW structure
2067 * @port: port to search for
2068 * @index: optionally returns index
2070 * Returns whether a port is already in use as a tunnel, and optionally its
2073 static bool ice_tunnel_port_in_use_hlpr(struct ice_hw *hw, u16 port, u16 *index)
2077 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
2078 if (hw->tnl.tbl[i].in_use && hw->tnl.tbl[i].port == port) {
2088 * ice_tunnel_port_in_use
2089 * @hw: pointer to the HW structure
2090 * @port: port to search for
2091 * @index: optionally returns index
2093 * Returns whether a port is already in use as a tunnel, and optionally its
2096 bool ice_tunnel_port_in_use(struct ice_hw *hw, u16 port, u16 *index)
2100 ice_acquire_lock(&hw->tnl_lock);
2101 res = ice_tunnel_port_in_use_hlpr(hw, port, index);
2102 ice_release_lock(&hw->tnl_lock);
2108 * ice_tunnel_get_type
2109 * @hw: pointer to the HW structure
2110 * @port: port to search for
2111 * @type: returns tunnel index
2113 * For a given port number, will return the type of tunnel.
2116 ice_tunnel_get_type(struct ice_hw *hw, u16 port, enum ice_tunnel_type *type)
2121 ice_acquire_lock(&hw->tnl_lock);
2123 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
2124 if (hw->tnl.tbl[i].in_use && hw->tnl.tbl[i].port == port) {
2125 *type = hw->tnl.tbl[i].type;
2130 ice_release_lock(&hw->tnl_lock);
2136 * ice_find_free_tunnel_entry
2137 * @hw: pointer to the HW structure
2138 * @type: tunnel type
2139 * @index: optionally returns index
2141 * Returns whether there is a free tunnel entry, and optionally its index
2144 ice_find_free_tunnel_entry(struct ice_hw *hw, enum ice_tunnel_type type,
2149 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
2150 if (hw->tnl.tbl[i].valid && !hw->tnl.tbl[i].in_use &&
2151 hw->tnl.tbl[i].type == type) {
2161 * ice_get_open_tunnel_port - retrieve an open tunnel port
2162 * @hw: pointer to the HW structure
2163 * @type: tunnel type (TNL_ALL will return any open port)
2164 * @port: returns open port
2167 ice_get_open_tunnel_port(struct ice_hw *hw, enum ice_tunnel_type type,
2173 ice_acquire_lock(&hw->tnl_lock);
2175 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
2176 if (hw->tnl.tbl[i].valid && hw->tnl.tbl[i].in_use &&
2177 (type == TNL_ALL || hw->tnl.tbl[i].type == type)) {
2178 *port = hw->tnl.tbl[i].port;
2183 ice_release_lock(&hw->tnl_lock);
2190 * @hw: pointer to the HW structure
2191 * @type: type of tunnel
2192 * @port: port of tunnel to create
2194 * Create a tunnel by updating the parse graph in the parser. We do that by
2195 * creating a package buffer with the tunnel info and issuing an update package
2199 ice_create_tunnel(struct ice_hw *hw, enum ice_tunnel_type type, u16 port)
2201 struct ice_boost_tcam_section *sect_rx, *sect_tx;
2202 enum ice_status status = ICE_ERR_MAX_LIMIT;
2203 struct ice_buf_build *bld;
2206 ice_acquire_lock(&hw->tnl_lock);
2208 if (ice_tunnel_port_in_use_hlpr(hw, port, &index)) {
2209 hw->tnl.tbl[index].ref++;
2210 status = ICE_SUCCESS;
2211 goto ice_create_tunnel_end;
2214 if (!ice_find_free_tunnel_entry(hw, type, &index)) {
2215 status = ICE_ERR_OUT_OF_RANGE;
2216 goto ice_create_tunnel_end;
2219 bld = ice_pkg_buf_alloc(hw);
2221 status = ICE_ERR_NO_MEMORY;
2222 goto ice_create_tunnel_end;
2225 /* allocate 2 sections, one for Rx parser, one for Tx parser */
2226 if (ice_pkg_buf_reserve_section(bld, 2))
2227 goto ice_create_tunnel_err;
2229 sect_rx = (struct ice_boost_tcam_section *)
2230 ice_pkg_buf_alloc_section(bld, ICE_SID_RXPARSER_BOOST_TCAM,
2233 goto ice_create_tunnel_err;
2234 sect_rx->count = CPU_TO_LE16(1);
2236 sect_tx = (struct ice_boost_tcam_section *)
2237 ice_pkg_buf_alloc_section(bld, ICE_SID_TXPARSER_BOOST_TCAM,
2240 goto ice_create_tunnel_err;
2241 sect_tx->count = CPU_TO_LE16(1);
2243 /* copy original boost entry to update package buffer */
2244 ice_memcpy(sect_rx->tcam, hw->tnl.tbl[index].boost_entry,
2245 sizeof(*sect_rx->tcam), ICE_NONDMA_TO_NONDMA);
2247 /* over-write the never-match dest port key bits with the encoded port
2250 ice_set_key((u8 *)§_rx->tcam[0].key, sizeof(sect_rx->tcam[0].key),
2251 (u8 *)&port, NULL, NULL, NULL,
2252 (u16)offsetof(struct ice_boost_key_value, hv_dst_port_key),
2253 sizeof(sect_rx->tcam[0].key.key.hv_dst_port_key));
2255 /* exact copy of entry to Tx section entry */
2256 ice_memcpy(sect_tx->tcam, sect_rx->tcam, sizeof(*sect_tx->tcam),
2257 ICE_NONDMA_TO_NONDMA);
2259 status = ice_update_pkg(hw, ice_pkg_buf(bld), 1);
2261 hw->tnl.tbl[index].port = port;
2262 hw->tnl.tbl[index].in_use = true;
2263 hw->tnl.tbl[index].ref = 1;
2266 ice_create_tunnel_err:
2267 ice_pkg_buf_free(hw, bld);
2269 ice_create_tunnel_end:
2270 ice_release_lock(&hw->tnl_lock);
2276 * ice_destroy_tunnel
2277 * @hw: pointer to the HW structure
2278 * @port: port of tunnel to destroy (ignored if the all parameter is true)
2279 * @all: flag that states to destroy all tunnels
2281 * Destroys a tunnel or all tunnels by creating an update package buffer
2282 * targeting the specific updates requested and then performing an update
2285 enum ice_status ice_destroy_tunnel(struct ice_hw *hw, u16 port, bool all)
2287 struct ice_boost_tcam_section *sect_rx, *sect_tx;
2288 enum ice_status status = ICE_ERR_MAX_LIMIT;
2289 struct ice_buf_build *bld;
2295 ice_acquire_lock(&hw->tnl_lock);
2297 if (!all && ice_tunnel_port_in_use_hlpr(hw, port, &index))
2298 if (hw->tnl.tbl[index].ref > 1) {
2299 hw->tnl.tbl[index].ref--;
2300 status = ICE_SUCCESS;
2301 goto ice_destroy_tunnel_end;
2304 /* determine count */
2305 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
2306 if (hw->tnl.tbl[i].valid && hw->tnl.tbl[i].in_use &&
2307 (all || hw->tnl.tbl[i].port == port))
2311 status = ICE_ERR_PARAM;
2312 goto ice_destroy_tunnel_end;
2315 /* size of section - there is at least one entry */
2316 size = ice_struct_size(sect_rx, tcam, count - 1);
2318 bld = ice_pkg_buf_alloc(hw);
2320 status = ICE_ERR_NO_MEMORY;
2321 goto ice_destroy_tunnel_end;
2324 /* allocate 2 sections, one for Rx parser, one for Tx parser */
2325 if (ice_pkg_buf_reserve_section(bld, 2))
2326 goto ice_destroy_tunnel_err;
2328 sect_rx = (struct ice_boost_tcam_section *)
2329 ice_pkg_buf_alloc_section(bld, ICE_SID_RXPARSER_BOOST_TCAM,
2332 goto ice_destroy_tunnel_err;
2333 sect_rx->count = CPU_TO_LE16(1);
2335 sect_tx = (struct ice_boost_tcam_section *)
2336 ice_pkg_buf_alloc_section(bld, ICE_SID_TXPARSER_BOOST_TCAM,
2339 goto ice_destroy_tunnel_err;
2340 sect_tx->count = CPU_TO_LE16(1);
2342 /* copy original boost entry to update package buffer, one copy to Rx
2343 * section, another copy to the Tx section
2345 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
2346 if (hw->tnl.tbl[i].valid && hw->tnl.tbl[i].in_use &&
2347 (all || hw->tnl.tbl[i].port == port)) {
2348 ice_memcpy(sect_rx->tcam + i,
2349 hw->tnl.tbl[i].boost_entry,
2350 sizeof(*sect_rx->tcam),
2351 ICE_NONDMA_TO_NONDMA);
2352 ice_memcpy(sect_tx->tcam + i,
2353 hw->tnl.tbl[i].boost_entry,
2354 sizeof(*sect_tx->tcam),
2355 ICE_NONDMA_TO_NONDMA);
2356 hw->tnl.tbl[i].marked = true;
2359 status = ice_update_pkg(hw, ice_pkg_buf(bld), 1);
2361 for (i = 0; i < hw->tnl.count &&
2362 i < ICE_TUNNEL_MAX_ENTRIES; i++)
2363 if (hw->tnl.tbl[i].marked) {
2364 hw->tnl.tbl[i].ref = 0;
2365 hw->tnl.tbl[i].port = 0;
2366 hw->tnl.tbl[i].in_use = false;
2367 hw->tnl.tbl[i].marked = false;
2370 ice_destroy_tunnel_err:
2371 ice_pkg_buf_free(hw, bld);
2373 ice_destroy_tunnel_end:
2374 ice_release_lock(&hw->tnl_lock);
2380 * ice_replay_tunnels
2381 * @hw: pointer to the HW structure
2383 * Replays all tunnels
2385 enum ice_status ice_replay_tunnels(struct ice_hw *hw)
2387 enum ice_status status = ICE_SUCCESS;
2390 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
2392 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++) {
2393 enum ice_tunnel_type type = hw->tnl.tbl[i].type;
2394 u16 refs = hw->tnl.tbl[i].ref;
2395 u16 port = hw->tnl.tbl[i].port;
2397 if (!hw->tnl.tbl[i].in_use)
2400 /* Replay tunnels one at a time by destroying them, then
2403 hw->tnl.tbl[i].ref = 1; /* make sure to destroy in one call */
2404 status = ice_destroy_tunnel(hw, port, false);
2406 ice_debug(hw, ICE_DBG_PKG,
2407 "ERR: 0x%x - destroy tunnel port 0x%x\n",
2412 status = ice_create_tunnel(hw, type, port);
2414 ice_debug(hw, ICE_DBG_PKG,
2415 "ERR: 0x%x - create tunnel port 0x%x\n",
2420 /* reset to original ref count */
2421 hw->tnl.tbl[i].ref = refs;
2428 * ice_find_prot_off - find prot ID and offset pair, based on prof and FV index
2429 * @hw: pointer to the hardware structure
2430 * @blk: hardware block
2432 * @fv_idx: field vector word index
2433 * @prot: variable to receive the protocol ID
2434 * @off: variable to receive the protocol offset
2437 ice_find_prot_off(struct ice_hw *hw, enum ice_block blk, u8 prof, u16 fv_idx,
2440 struct ice_fv_word *fv_ext;
2442 if (prof >= hw->blk[blk].es.count)
2443 return ICE_ERR_PARAM;
2445 if (fv_idx >= hw->blk[blk].es.fvw)
2446 return ICE_ERR_PARAM;
2448 fv_ext = hw->blk[blk].es.t + (prof * hw->blk[blk].es.fvw);
2450 *prot = fv_ext[fv_idx].prot_id;
2451 *off = fv_ext[fv_idx].off;
2456 /* PTG Management */
2459 * ice_ptg_update_xlt1 - Updates packet type groups in HW via XLT1 table
2460 * @hw: pointer to the hardware structure
2463 * This function will update the XLT1 hardware table to reflect the new
2464 * packet type group configuration.
2466 enum ice_status ice_ptg_update_xlt1(struct ice_hw *hw, enum ice_block blk)
2468 struct ice_xlt1_section *sect;
2469 struct ice_buf_build *bld;
2470 enum ice_status status;
2473 bld = ice_pkg_buf_alloc_single_section(hw, ice_sect_id(blk, ICE_XLT1),
2474 ICE_XLT1_SIZE(ICE_XLT1_CNT),
2477 return ICE_ERR_NO_MEMORY;
2479 sect->count = CPU_TO_LE16(ICE_XLT1_CNT);
2480 sect->offset = CPU_TO_LE16(0);
2481 for (index = 0; index < ICE_XLT1_CNT; index++)
2482 sect->value[index] = hw->blk[blk].xlt1.ptypes[index].ptg;
2484 status = ice_update_pkg(hw, ice_pkg_buf(bld), 1);
2486 ice_pkg_buf_free(hw, bld);
2492 * ice_ptg_find_ptype - Search for packet type group using packet type (ptype)
2493 * @hw: pointer to the hardware structure
2495 * @ptype: the ptype to search for
2496 * @ptg: pointer to variable that receives the PTG
2498 * This function will search the PTGs for a particular ptype, returning the
2499 * PTG ID that contains it through the PTG parameter, with the value of
2500 * ICE_DEFAULT_PTG (0) meaning it is part the default PTG.
2502 static enum ice_status
2503 ice_ptg_find_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 *ptg)
2505 if (ptype >= ICE_XLT1_CNT || !ptg)
2506 return ICE_ERR_PARAM;
2508 *ptg = hw->blk[blk].xlt1.ptypes[ptype].ptg;
2513 * ice_ptg_alloc_val - Allocates a new packet type group ID by value
2514 * @hw: pointer to the hardware structure
2516 * @ptg: the PTG to allocate
2518 * This function allocates a given packet type group ID specified by the PTG
2521 static void ice_ptg_alloc_val(struct ice_hw *hw, enum ice_block blk, u8 ptg)
2523 hw->blk[blk].xlt1.ptg_tbl[ptg].in_use = true;
2527 * ice_ptg_free - Frees a packet type group
2528 * @hw: pointer to the hardware structure
2530 * @ptg: the PTG ID to free
2532 * This function frees a packet type group, and returns all the current ptypes
2533 * within it to the default PTG.
2535 void ice_ptg_free(struct ice_hw *hw, enum ice_block blk, u8 ptg)
2537 struct ice_ptg_ptype *p, *temp;
2539 hw->blk[blk].xlt1.ptg_tbl[ptg].in_use = false;
2540 p = hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2542 p->ptg = ICE_DEFAULT_PTG;
2543 temp = p->next_ptype;
2544 p->next_ptype = NULL;
2548 hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype = NULL;
2552 * ice_ptg_remove_ptype - Removes ptype from a particular packet type group
2553 * @hw: pointer to the hardware structure
2555 * @ptype: the ptype to remove
2556 * @ptg: the PTG to remove the ptype from
2558 * This function will remove the ptype from the specific PTG, and move it to
2559 * the default PTG (ICE_DEFAULT_PTG).
2561 static enum ice_status
2562 ice_ptg_remove_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 ptg)
2564 struct ice_ptg_ptype **ch;
2565 struct ice_ptg_ptype *p;
2567 if (ptype > ICE_XLT1_CNT - 1)
2568 return ICE_ERR_PARAM;
2570 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].in_use)
2571 return ICE_ERR_DOES_NOT_EXIST;
2573 /* Should not happen if .in_use is set, bad config */
2574 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype)
2577 /* find the ptype within this PTG, and bypass the link over it */
2578 p = hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2579 ch = &hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2581 if (ptype == (p - hw->blk[blk].xlt1.ptypes)) {
2582 *ch = p->next_ptype;
2586 ch = &p->next_ptype;
2590 hw->blk[blk].xlt1.ptypes[ptype].ptg = ICE_DEFAULT_PTG;
2591 hw->blk[blk].xlt1.ptypes[ptype].next_ptype = NULL;
2597 * ice_ptg_add_mv_ptype - Adds/moves ptype to a particular packet type group
2598 * @hw: pointer to the hardware structure
2600 * @ptype: the ptype to add or move
2601 * @ptg: the PTG to add or move the ptype to
2603 * This function will either add or move a ptype to a particular PTG depending
2604 * on if the ptype is already part of another group. Note that using a
2605 * a destination PTG ID of ICE_DEFAULT_PTG (0) will move the ptype to the
2608 static enum ice_status
2609 ice_ptg_add_mv_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 ptg)
2611 enum ice_status status;
2614 if (ptype > ICE_XLT1_CNT - 1)
2615 return ICE_ERR_PARAM;
2617 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].in_use && ptg != ICE_DEFAULT_PTG)
2618 return ICE_ERR_DOES_NOT_EXIST;
2620 status = ice_ptg_find_ptype(hw, blk, ptype, &original_ptg);
2624 /* Is ptype already in the correct PTG? */
2625 if (original_ptg == ptg)
2628 /* Remove from original PTG and move back to the default PTG */
2629 if (original_ptg != ICE_DEFAULT_PTG)
2630 ice_ptg_remove_ptype(hw, blk, ptype, original_ptg);
2632 /* Moving to default PTG? Then we're done with this request */
2633 if (ptg == ICE_DEFAULT_PTG)
2636 /* Add ptype to PTG at beginning of list */
2637 hw->blk[blk].xlt1.ptypes[ptype].next_ptype =
2638 hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2639 hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype =
2640 &hw->blk[blk].xlt1.ptypes[ptype];
2642 hw->blk[blk].xlt1.ptypes[ptype].ptg = ptg;
2643 hw->blk[blk].xlt1.t[ptype] = ptg;
2648 /* Block / table size info */
2649 struct ice_blk_size_details {
2650 u16 xlt1; /* # XLT1 entries */
2651 u16 xlt2; /* # XLT2 entries */
2652 u16 prof_tcam; /* # profile ID TCAM entries */
2653 u16 prof_id; /* # profile IDs */
2654 u8 prof_cdid_bits; /* # CDID one-hot bits used in key */
2655 u16 prof_redir; /* # profile redirection entries */
2656 u16 es; /* # extraction sequence entries */
2657 u16 fvw; /* # field vector words */
2658 u8 overwrite; /* overwrite existing entries allowed */
2659 u8 reverse; /* reverse FV order */
2662 static const struct ice_blk_size_details blk_sizes[ICE_BLK_COUNT] = {
2665 * XLT1 - Number of entries in XLT1 table
2666 * XLT2 - Number of entries in XLT2 table
2667 * TCAM - Number of entries Profile ID TCAM table
2668 * CDID - Control Domain ID of the hardware block
2669 * PRED - Number of entries in the Profile Redirection Table
2670 * FV - Number of entries in the Field Vector
2671 * FVW - Width (in WORDs) of the Field Vector
2672 * OVR - Overwrite existing table entries
2675 /* XLT1 , XLT2 ,TCAM, PID,CDID,PRED, FV, FVW */
2676 /* Overwrite , Reverse FV */
2677 /* SW */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 256, 0, 256, 256, 48,
2679 /* ACL */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 32,
2681 /* FD */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 24,
2683 /* RSS */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 24,
2685 /* PE */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 64, 32, 0, 32, 32, 24,
2690 ICE_SID_XLT1_OFF = 0,
2693 ICE_SID_PR_REDIR_OFF,
2698 /* Characteristic handling */
2701 * ice_match_prop_lst - determine if properties of two lists match
2702 * @list1: first properties list
2703 * @list2: second properties list
2705 * Count, cookies and the order must match in order to be considered equivalent.
2708 ice_match_prop_lst(struct LIST_HEAD_TYPE *list1, struct LIST_HEAD_TYPE *list2)
2710 struct ice_vsig_prof *tmp1;
2711 struct ice_vsig_prof *tmp2;
2715 /* compare counts */
2716 LIST_FOR_EACH_ENTRY(tmp1, list1, ice_vsig_prof, list) {
2719 LIST_FOR_EACH_ENTRY(tmp2, list2, ice_vsig_prof, list) {
2722 if (!count || count != chk_count)
2725 tmp1 = LIST_FIRST_ENTRY(list1, struct ice_vsig_prof, list);
2726 tmp2 = LIST_FIRST_ENTRY(list2, struct ice_vsig_prof, list);
2728 /* profile cookies must compare, and in the exact same order to take
2729 * into account priority
2732 if (tmp2->profile_cookie != tmp1->profile_cookie)
2735 tmp1 = LIST_NEXT_ENTRY(tmp1, struct ice_vsig_prof, list);
2736 tmp2 = LIST_NEXT_ENTRY(tmp2, struct ice_vsig_prof, list);
2742 /* VSIG Management */
2745 * ice_vsig_update_xlt2_sect - update one section of XLT2 table
2746 * @hw: pointer to the hardware structure
2748 * @vsi: HW VSI number to program
2749 * @vsig: VSIG for the VSI
2751 * This function will update the XLT2 hardware table with the input VSI
2752 * group configuration.
2754 static enum ice_status
2755 ice_vsig_update_xlt2_sect(struct ice_hw *hw, enum ice_block blk, u16 vsi,
2758 struct ice_xlt2_section *sect;
2759 struct ice_buf_build *bld;
2760 enum ice_status status;
2762 bld = ice_pkg_buf_alloc_single_section(hw, ice_sect_id(blk, ICE_XLT2),
2763 sizeof(struct ice_xlt2_section),
2766 return ICE_ERR_NO_MEMORY;
2768 sect->count = CPU_TO_LE16(1);
2769 sect->offset = CPU_TO_LE16(vsi);
2770 sect->value[0] = CPU_TO_LE16(vsig);
2772 status = ice_update_pkg(hw, ice_pkg_buf(bld), 1);
2774 ice_pkg_buf_free(hw, bld);
2780 * ice_vsig_update_xlt2 - update XLT2 table with VSIG configuration
2781 * @hw: pointer to the hardware structure
2784 * This function will update the XLT2 hardware table with the input VSI
2785 * group configuration of used vsis.
2787 enum ice_status ice_vsig_update_xlt2(struct ice_hw *hw, enum ice_block blk)
2791 for (vsi = 0; vsi < ICE_MAX_VSI; vsi++) {
2792 /* update only vsis that have been changed */
2793 if (hw->blk[blk].xlt2.vsis[vsi].changed) {
2794 enum ice_status status;
2797 vsig = hw->blk[blk].xlt2.vsis[vsi].vsig;
2798 status = ice_vsig_update_xlt2_sect(hw, blk, vsi, vsig);
2802 hw->blk[blk].xlt2.vsis[vsi].changed = 0;
2810 * ice_vsig_find_vsi - find a VSIG that contains a specified VSI
2811 * @hw: pointer to the hardware structure
2813 * @vsi: VSI of interest
2814 * @vsig: pointer to receive the VSI group
2816 * This function will lookup the VSI entry in the XLT2 list and return
2817 * the VSI group its associated with.
2820 ice_vsig_find_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 *vsig)
2822 if (!vsig || vsi >= ICE_MAX_VSI)
2823 return ICE_ERR_PARAM;
2825 /* As long as there's a default or valid VSIG associated with the input
2826 * VSI, the functions returns a success. Any handling of VSIG will be
2827 * done by the following add, update or remove functions.
2829 *vsig = hw->blk[blk].xlt2.vsis[vsi].vsig;
2835 * ice_vsig_alloc_val - allocate a new VSIG by value
2836 * @hw: pointer to the hardware structure
2838 * @vsig: the VSIG to allocate
2840 * This function will allocate a given VSIG specified by the VSIG parameter.
2842 static u16 ice_vsig_alloc_val(struct ice_hw *hw, enum ice_block blk, u16 vsig)
2844 u16 idx = vsig & ICE_VSIG_IDX_M;
2846 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use) {
2847 INIT_LIST_HEAD(&hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst);
2848 hw->blk[blk].xlt2.vsig_tbl[idx].in_use = true;
2851 return ICE_VSIG_VALUE(idx, hw->pf_id);
2855 * ice_vsig_alloc - Finds a free entry and allocates a new VSIG
2856 * @hw: pointer to the hardware structure
2859 * This function will iterate through the VSIG list and mark the first
2860 * unused entry for the new VSIG entry as used and return that value.
2862 static u16 ice_vsig_alloc(struct ice_hw *hw, enum ice_block blk)
2866 for (i = 1; i < ICE_MAX_VSIGS; i++)
2867 if (!hw->blk[blk].xlt2.vsig_tbl[i].in_use)
2868 return ice_vsig_alloc_val(hw, blk, i);
2870 return ICE_DEFAULT_VSIG;
2874 * ice_find_dup_props_vsig - find VSI group with a specified set of properties
2875 * @hw: pointer to the hardware structure
2877 * @chs: characteristic list
2878 * @vsig: returns the VSIG with the matching profiles, if found
2880 * Each VSIG is associated with a characteristic set; i.e. all VSIs under
2881 * a group have the same characteristic set. To check if there exists a VSIG
2882 * which has the same characteristics as the input characteristics; this
2883 * function will iterate through the XLT2 list and return the VSIG that has a
2884 * matching configuration. In order to make sure that priorities are accounted
2885 * for, the list must match exactly, including the order in which the
2886 * characteristics are listed.
2888 static enum ice_status
2889 ice_find_dup_props_vsig(struct ice_hw *hw, enum ice_block blk,
2890 struct LIST_HEAD_TYPE *chs, u16 *vsig)
2892 struct ice_xlt2 *xlt2 = &hw->blk[blk].xlt2;
2895 for (i = 0; i < xlt2->count; i++) {
2896 if (xlt2->vsig_tbl[i].in_use &&
2897 ice_match_prop_lst(chs, &xlt2->vsig_tbl[i].prop_lst)) {
2898 *vsig = ICE_VSIG_VALUE(i, hw->pf_id);
2903 return ICE_ERR_DOES_NOT_EXIST;
2907 * ice_vsig_free - free VSI group
2908 * @hw: pointer to the hardware structure
2910 * @vsig: VSIG to remove
2912 * The function will remove all VSIs associated with the input VSIG and move
2913 * them to the DEFAULT_VSIG and mark the VSIG available.
2915 static enum ice_status
2916 ice_vsig_free(struct ice_hw *hw, enum ice_block blk, u16 vsig)
2918 struct ice_vsig_prof *dtmp, *del;
2919 struct ice_vsig_vsi *vsi_cur;
2922 idx = vsig & ICE_VSIG_IDX_M;
2923 if (idx >= ICE_MAX_VSIGS)
2924 return ICE_ERR_PARAM;
2926 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
2927 return ICE_ERR_DOES_NOT_EXIST;
2929 hw->blk[blk].xlt2.vsig_tbl[idx].in_use = false;
2931 vsi_cur = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2932 /* If the VSIG has at least 1 VSI then iterate through the
2933 * list and remove the VSIs before deleting the group.
2936 /* remove all vsis associated with this VSIG XLT2 entry */
2938 struct ice_vsig_vsi *tmp = vsi_cur->next_vsi;
2940 vsi_cur->vsig = ICE_DEFAULT_VSIG;
2941 vsi_cur->changed = 1;
2942 vsi_cur->next_vsi = NULL;
2946 /* NULL terminate head of VSI list */
2947 hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi = NULL;
2950 /* free characteristic list */
2951 LIST_FOR_EACH_ENTRY_SAFE(del, dtmp,
2952 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
2953 ice_vsig_prof, list) {
2954 LIST_DEL(&del->list);
2958 /* if VSIG characteristic list was cleared for reset
2959 * re-initialize the list head
2961 INIT_LIST_HEAD(&hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst);
2967 * ice_vsig_remove_vsi - remove VSI from VSIG
2968 * @hw: pointer to the hardware structure
2970 * @vsi: VSI to remove
2971 * @vsig: VSI group to remove from
2973 * The function will remove the input VSI from its VSI group and move it
2974 * to the DEFAULT_VSIG.
2976 static enum ice_status
2977 ice_vsig_remove_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
2979 struct ice_vsig_vsi **vsi_head, *vsi_cur, *vsi_tgt;
2982 idx = vsig & ICE_VSIG_IDX_M;
2984 if (vsi >= ICE_MAX_VSI || idx >= ICE_MAX_VSIGS)
2985 return ICE_ERR_PARAM;
2987 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
2988 return ICE_ERR_DOES_NOT_EXIST;
2990 /* entry already in default VSIG, don't have to remove */
2991 if (idx == ICE_DEFAULT_VSIG)
2994 vsi_head = &hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2998 vsi_tgt = &hw->blk[blk].xlt2.vsis[vsi];
2999 vsi_cur = (*vsi_head);
3001 /* iterate the VSI list, skip over the entry to be removed */
3003 if (vsi_tgt == vsi_cur) {
3004 (*vsi_head) = vsi_cur->next_vsi;
3007 vsi_head = &vsi_cur->next_vsi;
3008 vsi_cur = vsi_cur->next_vsi;
3011 /* verify if VSI was removed from group list */
3013 return ICE_ERR_DOES_NOT_EXIST;
3015 vsi_cur->vsig = ICE_DEFAULT_VSIG;
3016 vsi_cur->changed = 1;
3017 vsi_cur->next_vsi = NULL;
3023 * ice_vsig_add_mv_vsi - add or move a VSI to a VSI group
3024 * @hw: pointer to the hardware structure
3027 * @vsig: destination VSI group
3029 * This function will move or add the input VSI to the target VSIG.
3030 * The function will find the original VSIG the VSI belongs to and
3031 * move the entry to the DEFAULT_VSIG, update the original VSIG and
3032 * then move entry to the new VSIG.
3034 static enum ice_status
3035 ice_vsig_add_mv_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
3037 struct ice_vsig_vsi *tmp;
3038 enum ice_status status;
3041 idx = vsig & ICE_VSIG_IDX_M;
3043 if (vsi >= ICE_MAX_VSI || idx >= ICE_MAX_VSIGS)
3044 return ICE_ERR_PARAM;
3046 /* if VSIG not in use and VSIG is not default type this VSIG
3049 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use &&
3050 vsig != ICE_DEFAULT_VSIG)
3051 return ICE_ERR_DOES_NOT_EXIST;
3053 status = ice_vsig_find_vsi(hw, blk, vsi, &orig_vsig);
3057 /* no update required if vsigs match */
3058 if (orig_vsig == vsig)
3061 if (orig_vsig != ICE_DEFAULT_VSIG) {
3062 /* remove entry from orig_vsig and add to default VSIG */
3063 status = ice_vsig_remove_vsi(hw, blk, vsi, orig_vsig);
3068 if (idx == ICE_DEFAULT_VSIG)
3071 /* Create VSI entry and add VSIG and prop_mask values */
3072 hw->blk[blk].xlt2.vsis[vsi].vsig = vsig;
3073 hw->blk[blk].xlt2.vsis[vsi].changed = 1;
3075 /* Add new entry to the head of the VSIG list */
3076 tmp = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
3077 hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi =
3078 &hw->blk[blk].xlt2.vsis[vsi];
3079 hw->blk[blk].xlt2.vsis[vsi].next_vsi = tmp;
3080 hw->blk[blk].xlt2.t[vsi] = vsig;
3086 * ice_find_prof_id - find profile ID for a given field vector
3087 * @hw: pointer to the hardware structure
3089 * @fv: field vector to search for
3090 * @prof_id: receives the profile ID
3092 static enum ice_status
3093 ice_find_prof_id(struct ice_hw *hw, enum ice_block blk,
3094 struct ice_fv_word *fv, u8 *prof_id)
3096 struct ice_es *es = &hw->blk[blk].es;
3100 for (i = 0; i < (u8)es->count; i++) {
3103 if (memcmp(&es->t[off], fv, es->fvw * sizeof(*fv)))
3110 return ICE_ERR_DOES_NOT_EXIST;
3114 * ice_prof_id_rsrc_type - get profile ID resource type for a block type
3115 * @blk: the block type
3116 * @rsrc_type: pointer to variable to receive the resource type
3118 static bool ice_prof_id_rsrc_type(enum ice_block blk, u16 *rsrc_type)
3122 *rsrc_type = ICE_AQC_RES_TYPE_SWITCH_PROF_BLDR_PROFID;
3125 *rsrc_type = ICE_AQC_RES_TYPE_ACL_PROF_BLDR_PROFID;
3128 *rsrc_type = ICE_AQC_RES_TYPE_FD_PROF_BLDR_PROFID;
3131 *rsrc_type = ICE_AQC_RES_TYPE_HASH_PROF_BLDR_PROFID;
3134 *rsrc_type = ICE_AQC_RES_TYPE_QHASH_PROF_BLDR_PROFID;
3143 * ice_tcam_ent_rsrc_type - get TCAM entry resource type for a block type
3144 * @blk: the block type
3145 * @rsrc_type: pointer to variable to receive the resource type
3147 static bool ice_tcam_ent_rsrc_type(enum ice_block blk, u16 *rsrc_type)
3151 *rsrc_type = ICE_AQC_RES_TYPE_SWITCH_PROF_BLDR_TCAM;
3154 *rsrc_type = ICE_AQC_RES_TYPE_ACL_PROF_BLDR_TCAM;
3157 *rsrc_type = ICE_AQC_RES_TYPE_FD_PROF_BLDR_TCAM;
3160 *rsrc_type = ICE_AQC_RES_TYPE_HASH_PROF_BLDR_TCAM;
3163 *rsrc_type = ICE_AQC_RES_TYPE_QHASH_PROF_BLDR_TCAM;
3172 * ice_alloc_tcam_ent - allocate hardware TCAM entry
3173 * @hw: pointer to the HW struct
3174 * @blk: the block to allocate the TCAM for
3175 * @tcam_idx: pointer to variable to receive the TCAM entry
3177 * This function allocates a new entry in a Profile ID TCAM for a specific
3180 static enum ice_status
3181 ice_alloc_tcam_ent(struct ice_hw *hw, enum ice_block blk, u16 *tcam_idx)
3185 if (!ice_tcam_ent_rsrc_type(blk, &res_type))
3186 return ICE_ERR_PARAM;
3188 return ice_alloc_hw_res(hw, res_type, 1, true, tcam_idx);
3192 * ice_free_tcam_ent - free hardware TCAM entry
3193 * @hw: pointer to the HW struct
3194 * @blk: the block from which to free the TCAM entry
3195 * @tcam_idx: the TCAM entry to free
3197 * This function frees an entry in a Profile ID TCAM for a specific block.
3199 static enum ice_status
3200 ice_free_tcam_ent(struct ice_hw *hw, enum ice_block blk, u16 tcam_idx)
3204 if (!ice_tcam_ent_rsrc_type(blk, &res_type))
3205 return ICE_ERR_PARAM;
3207 return ice_free_hw_res(hw, res_type, 1, &tcam_idx);
3211 * ice_alloc_prof_id - allocate profile ID
3212 * @hw: pointer to the HW struct
3213 * @blk: the block to allocate the profile ID for
3214 * @prof_id: pointer to variable to receive the profile ID
3216 * This function allocates a new profile ID, which also corresponds to a Field
3217 * Vector (Extraction Sequence) entry.
3219 static enum ice_status
3220 ice_alloc_prof_id(struct ice_hw *hw, enum ice_block blk, u8 *prof_id)
3222 enum ice_status status;
3226 if (!ice_prof_id_rsrc_type(blk, &res_type))
3227 return ICE_ERR_PARAM;
3229 status = ice_alloc_hw_res(hw, res_type, 1, false, &get_prof);
3231 *prof_id = (u8)get_prof;
3237 * ice_free_prof_id - free profile ID
3238 * @hw: pointer to the HW struct
3239 * @blk: the block from which to free the profile ID
3240 * @prof_id: the profile ID to free
3242 * This function frees a profile ID, which also corresponds to a Field Vector.
3244 static enum ice_status
3245 ice_free_prof_id(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
3247 u16 tmp_prof_id = (u16)prof_id;
3250 if (!ice_prof_id_rsrc_type(blk, &res_type))
3251 return ICE_ERR_PARAM;
3253 return ice_free_hw_res(hw, res_type, 1, &tmp_prof_id);
3257 * ice_prof_inc_ref - increment reference count for profile
3258 * @hw: pointer to the HW struct
3259 * @blk: the block from which to free the profile ID
3260 * @prof_id: the profile ID for which to increment the reference count
3262 static enum ice_status
3263 ice_prof_inc_ref(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
3265 if (prof_id > hw->blk[blk].es.count)
3266 return ICE_ERR_PARAM;
3268 hw->blk[blk].es.ref_count[prof_id]++;
3274 * ice_write_es - write an extraction sequence to hardware
3275 * @hw: pointer to the HW struct
3276 * @blk: the block in which to write the extraction sequence
3277 * @prof_id: the profile ID to write
3278 * @fv: pointer to the extraction sequence to write - NULL to clear extraction
3281 ice_write_es(struct ice_hw *hw, enum ice_block blk, u8 prof_id,
3282 struct ice_fv_word *fv)
3286 off = prof_id * hw->blk[blk].es.fvw;
3288 ice_memset(&hw->blk[blk].es.t[off], 0, hw->blk[blk].es.fvw *
3289 sizeof(*fv), ICE_NONDMA_MEM);
3290 hw->blk[blk].es.written[prof_id] = false;
3292 ice_memcpy(&hw->blk[blk].es.t[off], fv, hw->blk[blk].es.fvw *
3293 sizeof(*fv), ICE_NONDMA_TO_NONDMA);
3298 * ice_prof_dec_ref - decrement reference count for profile
3299 * @hw: pointer to the HW struct
3300 * @blk: the block from which to free the profile ID
3301 * @prof_id: the profile ID for which to decrement the reference count
3303 static enum ice_status
3304 ice_prof_dec_ref(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
3306 if (prof_id > hw->blk[blk].es.count)
3307 return ICE_ERR_PARAM;
3309 if (hw->blk[blk].es.ref_count[prof_id] > 0) {
3310 if (!--hw->blk[blk].es.ref_count[prof_id]) {
3311 ice_write_es(hw, blk, prof_id, NULL);
3312 return ice_free_prof_id(hw, blk, prof_id);
3319 /* Block / table section IDs */
3320 static const u32 ice_blk_sids[ICE_BLK_COUNT][ICE_SID_OFF_COUNT] = {
3324 ICE_SID_PROFID_TCAM_SW,
3325 ICE_SID_PROFID_REDIR_SW,
3332 ICE_SID_PROFID_TCAM_ACL,
3333 ICE_SID_PROFID_REDIR_ACL,
3340 ICE_SID_PROFID_TCAM_FD,
3341 ICE_SID_PROFID_REDIR_FD,
3348 ICE_SID_PROFID_TCAM_RSS,
3349 ICE_SID_PROFID_REDIR_RSS,
3356 ICE_SID_PROFID_TCAM_PE,
3357 ICE_SID_PROFID_REDIR_PE,
3363 * ice_init_sw_xlt1_db - init software XLT1 database from HW tables
3364 * @hw: pointer to the hardware structure
3365 * @blk: the HW block to initialize
3367 static void ice_init_sw_xlt1_db(struct ice_hw *hw, enum ice_block blk)
3371 for (pt = 0; pt < hw->blk[blk].xlt1.count; pt++) {
3374 ptg = hw->blk[blk].xlt1.t[pt];
3375 if (ptg != ICE_DEFAULT_PTG) {
3376 ice_ptg_alloc_val(hw, blk, ptg);
3377 ice_ptg_add_mv_ptype(hw, blk, pt, ptg);
3383 * ice_init_sw_xlt2_db - init software XLT2 database from HW tables
3384 * @hw: pointer to the hardware structure
3385 * @blk: the HW block to initialize
3387 static void ice_init_sw_xlt2_db(struct ice_hw *hw, enum ice_block blk)
3391 for (vsi = 0; vsi < hw->blk[blk].xlt2.count; vsi++) {
3394 vsig = hw->blk[blk].xlt2.t[vsi];
3396 ice_vsig_alloc_val(hw, blk, vsig);
3397 ice_vsig_add_mv_vsi(hw, blk, vsi, vsig);
3398 /* no changes at this time, since this has been
3399 * initialized from the original package
3401 hw->blk[blk].xlt2.vsis[vsi].changed = 0;
3407 * ice_init_sw_db - init software database from HW tables
3408 * @hw: pointer to the hardware structure
3410 static void ice_init_sw_db(struct ice_hw *hw)
3414 for (i = 0; i < ICE_BLK_COUNT; i++) {
3415 ice_init_sw_xlt1_db(hw, (enum ice_block)i);
3416 ice_init_sw_xlt2_db(hw, (enum ice_block)i);
3421 * ice_fill_tbl - Reads content of a single table type into database
3422 * @hw: pointer to the hardware structure
3423 * @block_id: Block ID of the table to copy
3424 * @sid: Section ID of the table to copy
3426 * Will attempt to read the entire content of a given table of a single block
3427 * into the driver database. We assume that the buffer will always
3428 * be as large or larger than the data contained in the package. If
3429 * this condition is not met, there is most likely an error in the package
3432 static void ice_fill_tbl(struct ice_hw *hw, enum ice_block block_id, u32 sid)
3434 u32 dst_len, sect_len, offset = 0;
3435 struct ice_prof_redir_section *pr;
3436 struct ice_prof_id_section *pid;
3437 struct ice_xlt1_section *xlt1;
3438 struct ice_xlt2_section *xlt2;
3439 struct ice_sw_fv_section *es;
3440 struct ice_pkg_enum state;
3444 /* if the HW segment pointer is null then the first iteration of
3445 * ice_pkg_enum_section() will fail. In this case the HW tables will
3446 * not be filled and return success.
3449 ice_debug(hw, ICE_DBG_PKG, "hw->seg is NULL, tables are not filled\n");
3453 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
3455 sect = ice_pkg_enum_section(hw->seg, &state, sid);
3459 case ICE_SID_XLT1_SW:
3460 case ICE_SID_XLT1_FD:
3461 case ICE_SID_XLT1_RSS:
3462 case ICE_SID_XLT1_ACL:
3463 case ICE_SID_XLT1_PE:
3464 xlt1 = (struct ice_xlt1_section *)sect;
3466 sect_len = LE16_TO_CPU(xlt1->count) *
3467 sizeof(*hw->blk[block_id].xlt1.t);
3468 dst = hw->blk[block_id].xlt1.t;
3469 dst_len = hw->blk[block_id].xlt1.count *
3470 sizeof(*hw->blk[block_id].xlt1.t);
3472 case ICE_SID_XLT2_SW:
3473 case ICE_SID_XLT2_FD:
3474 case ICE_SID_XLT2_RSS:
3475 case ICE_SID_XLT2_ACL:
3476 case ICE_SID_XLT2_PE:
3477 xlt2 = (struct ice_xlt2_section *)sect;
3478 src = (_FORCE_ u8 *)xlt2->value;
3479 sect_len = LE16_TO_CPU(xlt2->count) *
3480 sizeof(*hw->blk[block_id].xlt2.t);
3481 dst = (u8 *)hw->blk[block_id].xlt2.t;
3482 dst_len = hw->blk[block_id].xlt2.count *
3483 sizeof(*hw->blk[block_id].xlt2.t);
3485 case ICE_SID_PROFID_TCAM_SW:
3486 case ICE_SID_PROFID_TCAM_FD:
3487 case ICE_SID_PROFID_TCAM_RSS:
3488 case ICE_SID_PROFID_TCAM_ACL:
3489 case ICE_SID_PROFID_TCAM_PE:
3490 pid = (struct ice_prof_id_section *)sect;
3491 src = (u8 *)pid->entry;
3492 sect_len = LE16_TO_CPU(pid->count) *
3493 sizeof(*hw->blk[block_id].prof.t);
3494 dst = (u8 *)hw->blk[block_id].prof.t;
3495 dst_len = hw->blk[block_id].prof.count *
3496 sizeof(*hw->blk[block_id].prof.t);
3498 case ICE_SID_PROFID_REDIR_SW:
3499 case ICE_SID_PROFID_REDIR_FD:
3500 case ICE_SID_PROFID_REDIR_RSS:
3501 case ICE_SID_PROFID_REDIR_ACL:
3502 case ICE_SID_PROFID_REDIR_PE:
3503 pr = (struct ice_prof_redir_section *)sect;
3504 src = pr->redir_value;
3505 sect_len = LE16_TO_CPU(pr->count) *
3506 sizeof(*hw->blk[block_id].prof_redir.t);
3507 dst = hw->blk[block_id].prof_redir.t;
3508 dst_len = hw->blk[block_id].prof_redir.count *
3509 sizeof(*hw->blk[block_id].prof_redir.t);
3511 case ICE_SID_FLD_VEC_SW:
3512 case ICE_SID_FLD_VEC_FD:
3513 case ICE_SID_FLD_VEC_RSS:
3514 case ICE_SID_FLD_VEC_ACL:
3515 case ICE_SID_FLD_VEC_PE:
3516 es = (struct ice_sw_fv_section *)sect;
3518 sect_len = (u32)(LE16_TO_CPU(es->count) *
3519 hw->blk[block_id].es.fvw) *
3520 sizeof(*hw->blk[block_id].es.t);
3521 dst = (u8 *)hw->blk[block_id].es.t;
3522 dst_len = (u32)(hw->blk[block_id].es.count *
3523 hw->blk[block_id].es.fvw) *
3524 sizeof(*hw->blk[block_id].es.t);
3530 /* if the section offset exceeds destination length, terminate
3533 if (offset > dst_len)
3536 /* if the sum of section size and offset exceed destination size
3537 * then we are out of bounds of the HW table size for that PF.
3538 * Changing section length to fill the remaining table space
3541 if ((offset + sect_len) > dst_len)
3542 sect_len = dst_len - offset;
3544 ice_memcpy(dst + offset, src, sect_len, ICE_NONDMA_TO_NONDMA);
3546 sect = ice_pkg_enum_section(NULL, &state, sid);
3551 * ice_fill_blk_tbls - Read package context for tables
3552 * @hw: pointer to the hardware structure
3554 * Reads the current package contents and populates the driver
3555 * database with the data iteratively for all advanced feature
3556 * blocks. Assume that the HW tables have been allocated.
3558 void ice_fill_blk_tbls(struct ice_hw *hw)
3562 for (i = 0; i < ICE_BLK_COUNT; i++) {
3563 enum ice_block blk_id = (enum ice_block)i;
3565 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].xlt1.sid);
3566 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].xlt2.sid);
3567 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].prof.sid);
3568 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].prof_redir.sid);
3569 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].es.sid);
3576 * ice_free_prof_map - free profile map
3577 * @hw: pointer to the hardware structure
3578 * @blk_idx: HW block index
3580 static void ice_free_prof_map(struct ice_hw *hw, u8 blk_idx)
3582 struct ice_es *es = &hw->blk[blk_idx].es;
3583 struct ice_prof_map *del, *tmp;
3585 ice_acquire_lock(&es->prof_map_lock);
3586 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &es->prof_map,
3587 ice_prof_map, list) {
3588 LIST_DEL(&del->list);
3591 INIT_LIST_HEAD(&es->prof_map);
3592 ice_release_lock(&es->prof_map_lock);
3596 * ice_free_flow_profs - free flow profile entries
3597 * @hw: pointer to the hardware structure
3598 * @blk_idx: HW block index
3600 static void ice_free_flow_profs(struct ice_hw *hw, u8 blk_idx)
3602 struct ice_flow_prof *p, *tmp;
3604 ice_acquire_lock(&hw->fl_profs_locks[blk_idx]);
3605 LIST_FOR_EACH_ENTRY_SAFE(p, tmp, &hw->fl_profs[blk_idx],
3606 ice_flow_prof, l_entry) {
3607 struct ice_flow_entry *e, *t;
3609 LIST_FOR_EACH_ENTRY_SAFE(e, t, &p->entries,
3610 ice_flow_entry, l_entry)
3611 ice_flow_rem_entry(hw, (enum ice_block)blk_idx,
3612 ICE_FLOW_ENTRY_HNDL(e));
3614 LIST_DEL(&p->l_entry);
3616 ice_free(hw, p->acts);
3619 ice_release_lock(&hw->fl_profs_locks[blk_idx]);
3621 /* if driver is in reset and tables are being cleared
3622 * re-initialize the flow profile list heads
3624 INIT_LIST_HEAD(&hw->fl_profs[blk_idx]);
3628 * ice_free_vsig_tbl - free complete VSIG table entries
3629 * @hw: pointer to the hardware structure
3630 * @blk: the HW block on which to free the VSIG table entries
3632 static void ice_free_vsig_tbl(struct ice_hw *hw, enum ice_block blk)
3636 if (!hw->blk[blk].xlt2.vsig_tbl)
3639 for (i = 1; i < ICE_MAX_VSIGS; i++)
3640 if (hw->blk[blk].xlt2.vsig_tbl[i].in_use)
3641 ice_vsig_free(hw, blk, i);
3645 * ice_free_hw_tbls - free hardware table memory
3646 * @hw: pointer to the hardware structure
3648 void ice_free_hw_tbls(struct ice_hw *hw)
3650 struct ice_rss_cfg *r, *rt;
3653 for (i = 0; i < ICE_BLK_COUNT; i++) {
3654 if (hw->blk[i].is_list_init) {
3655 struct ice_es *es = &hw->blk[i].es;
3657 ice_free_prof_map(hw, i);
3658 ice_destroy_lock(&es->prof_map_lock);
3660 ice_free_flow_profs(hw, i);
3661 ice_destroy_lock(&hw->fl_profs_locks[i]);
3663 hw->blk[i].is_list_init = false;
3665 ice_free_vsig_tbl(hw, (enum ice_block)i);
3666 ice_free(hw, hw->blk[i].xlt1.ptypes);
3667 ice_free(hw, hw->blk[i].xlt1.ptg_tbl);
3668 ice_free(hw, hw->blk[i].xlt1.t);
3669 ice_free(hw, hw->blk[i].xlt2.t);
3670 ice_free(hw, hw->blk[i].xlt2.vsig_tbl);
3671 ice_free(hw, hw->blk[i].xlt2.vsis);
3672 ice_free(hw, hw->blk[i].prof.t);
3673 ice_free(hw, hw->blk[i].prof_redir.t);
3674 ice_free(hw, hw->blk[i].es.t);
3675 ice_free(hw, hw->blk[i].es.ref_count);
3676 ice_free(hw, hw->blk[i].es.written);
3679 LIST_FOR_EACH_ENTRY_SAFE(r, rt, &hw->rss_list_head,
3680 ice_rss_cfg, l_entry) {
3681 LIST_DEL(&r->l_entry);
3684 ice_destroy_lock(&hw->rss_locks);
3685 ice_memset(hw->blk, 0, sizeof(hw->blk), ICE_NONDMA_MEM);
3689 * ice_init_flow_profs - init flow profile locks and list heads
3690 * @hw: pointer to the hardware structure
3691 * @blk_idx: HW block index
3693 static void ice_init_flow_profs(struct ice_hw *hw, u8 blk_idx)
3695 ice_init_lock(&hw->fl_profs_locks[blk_idx]);
3696 INIT_LIST_HEAD(&hw->fl_profs[blk_idx]);
3700 * ice_clear_hw_tbls - clear HW tables and flow profiles
3701 * @hw: pointer to the hardware structure
3703 void ice_clear_hw_tbls(struct ice_hw *hw)
3707 for (i = 0; i < ICE_BLK_COUNT; i++) {
3708 struct ice_prof_redir *prof_redir = &hw->blk[i].prof_redir;
3709 struct ice_prof_tcam *prof = &hw->blk[i].prof;
3710 struct ice_xlt1 *xlt1 = &hw->blk[i].xlt1;
3711 struct ice_xlt2 *xlt2 = &hw->blk[i].xlt2;
3712 struct ice_es *es = &hw->blk[i].es;
3714 if (hw->blk[i].is_list_init) {
3715 ice_free_prof_map(hw, i);
3716 ice_free_flow_profs(hw, i);
3719 ice_free_vsig_tbl(hw, (enum ice_block)i);
3721 ice_memset(xlt1->ptypes, 0, xlt1->count * sizeof(*xlt1->ptypes),
3723 ice_memset(xlt1->ptg_tbl, 0,
3724 ICE_MAX_PTGS * sizeof(*xlt1->ptg_tbl),
3726 ice_memset(xlt1->t, 0, xlt1->count * sizeof(*xlt1->t),
3729 ice_memset(xlt2->vsis, 0, xlt2->count * sizeof(*xlt2->vsis),
3731 ice_memset(xlt2->vsig_tbl, 0,
3732 xlt2->count * sizeof(*xlt2->vsig_tbl),
3734 ice_memset(xlt2->t, 0, xlt2->count * sizeof(*xlt2->t),
3737 ice_memset(prof->t, 0, prof->count * sizeof(*prof->t),
3739 ice_memset(prof_redir->t, 0,
3740 prof_redir->count * sizeof(*prof_redir->t),
3743 ice_memset(es->t, 0, es->count * sizeof(*es->t),
3745 ice_memset(es->ref_count, 0, es->count * sizeof(*es->ref_count),
3747 ice_memset(es->written, 0, es->count * sizeof(*es->written),
3753 * ice_init_hw_tbls - init hardware table memory
3754 * @hw: pointer to the hardware structure
3756 enum ice_status ice_init_hw_tbls(struct ice_hw *hw)
3760 ice_init_lock(&hw->rss_locks);
3761 INIT_LIST_HEAD(&hw->rss_list_head);
3762 for (i = 0; i < ICE_BLK_COUNT; i++) {
3763 struct ice_prof_redir *prof_redir = &hw->blk[i].prof_redir;
3764 struct ice_prof_tcam *prof = &hw->blk[i].prof;
3765 struct ice_xlt1 *xlt1 = &hw->blk[i].xlt1;
3766 struct ice_xlt2 *xlt2 = &hw->blk[i].xlt2;
3767 struct ice_es *es = &hw->blk[i].es;
3770 if (hw->blk[i].is_list_init)
3773 ice_init_flow_profs(hw, i);
3774 ice_init_lock(&es->prof_map_lock);
3775 INIT_LIST_HEAD(&es->prof_map);
3776 hw->blk[i].is_list_init = true;
3778 hw->blk[i].overwrite = blk_sizes[i].overwrite;
3779 es->reverse = blk_sizes[i].reverse;
3781 xlt1->sid = ice_blk_sids[i][ICE_SID_XLT1_OFF];
3782 xlt1->count = blk_sizes[i].xlt1;
3784 xlt1->ptypes = (struct ice_ptg_ptype *)
3785 ice_calloc(hw, xlt1->count, sizeof(*xlt1->ptypes));
3790 xlt1->ptg_tbl = (struct ice_ptg_entry *)
3791 ice_calloc(hw, ICE_MAX_PTGS, sizeof(*xlt1->ptg_tbl));
3796 xlt1->t = (u8 *)ice_calloc(hw, xlt1->count, sizeof(*xlt1->t));
3800 xlt2->sid = ice_blk_sids[i][ICE_SID_XLT2_OFF];
3801 xlt2->count = blk_sizes[i].xlt2;
3803 xlt2->vsis = (struct ice_vsig_vsi *)
3804 ice_calloc(hw, xlt2->count, sizeof(*xlt2->vsis));
3809 xlt2->vsig_tbl = (struct ice_vsig_entry *)
3810 ice_calloc(hw, xlt2->count, sizeof(*xlt2->vsig_tbl));
3811 if (!xlt2->vsig_tbl)
3814 for (j = 0; j < xlt2->count; j++)
3815 INIT_LIST_HEAD(&xlt2->vsig_tbl[j].prop_lst);
3817 xlt2->t = (u16 *)ice_calloc(hw, xlt2->count, sizeof(*xlt2->t));
3821 prof->sid = ice_blk_sids[i][ICE_SID_PR_OFF];
3822 prof->count = blk_sizes[i].prof_tcam;
3823 prof->max_prof_id = blk_sizes[i].prof_id;
3824 prof->cdid_bits = blk_sizes[i].prof_cdid_bits;
3825 prof->t = (struct ice_prof_tcam_entry *)
3826 ice_calloc(hw, prof->count, sizeof(*prof->t));
3831 prof_redir->sid = ice_blk_sids[i][ICE_SID_PR_REDIR_OFF];
3832 prof_redir->count = blk_sizes[i].prof_redir;
3833 prof_redir->t = (u8 *)ice_calloc(hw, prof_redir->count,
3834 sizeof(*prof_redir->t));
3839 es->sid = ice_blk_sids[i][ICE_SID_ES_OFF];
3840 es->count = blk_sizes[i].es;
3841 es->fvw = blk_sizes[i].fvw;
3842 es->t = (struct ice_fv_word *)
3843 ice_calloc(hw, (u32)(es->count * es->fvw),
3848 es->ref_count = (u16 *)
3849 ice_calloc(hw, es->count, sizeof(*es->ref_count));
3851 es->written = (u8 *)
3852 ice_calloc(hw, es->count, sizeof(*es->written));
3859 ice_free_hw_tbls(hw);
3860 return ICE_ERR_NO_MEMORY;
3864 * ice_prof_gen_key - generate profile ID key
3865 * @hw: pointer to the HW struct
3866 * @blk: the block in which to write profile ID to
3867 * @ptg: packet type group (PTG) portion of key
3868 * @vsig: VSIG portion of key
3869 * @cdid: CDID portion of key
3870 * @flags: flag portion of key
3871 * @vl_msk: valid mask
3872 * @dc_msk: don't care mask
3873 * @nm_msk: never match mask
3874 * @key: output of profile ID key
3876 static enum ice_status
3877 ice_prof_gen_key(struct ice_hw *hw, enum ice_block blk, u8 ptg, u16 vsig,
3878 u8 cdid, u16 flags, u8 vl_msk[ICE_TCAM_KEY_VAL_SZ],
3879 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ], u8 nm_msk[ICE_TCAM_KEY_VAL_SZ],
3880 u8 key[ICE_TCAM_KEY_SZ])
3882 struct ice_prof_id_key inkey;
3885 inkey.xlt2_cdid = CPU_TO_LE16(vsig);
3886 inkey.flags = CPU_TO_LE16(flags);
3888 switch (hw->blk[blk].prof.cdid_bits) {
3892 #define ICE_CD_2_M 0xC000U
3893 #define ICE_CD_2_S 14
3894 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_2_M);
3895 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_2_S);
3898 #define ICE_CD_4_M 0xF000U
3899 #define ICE_CD_4_S 12
3900 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_4_M);
3901 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_4_S);
3904 #define ICE_CD_8_M 0xFF00U
3905 #define ICE_CD_8_S 16
3906 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_8_M);
3907 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_8_S);
3910 ice_debug(hw, ICE_DBG_PKG, "Error in profile config\n");
3914 return ice_set_key(key, ICE_TCAM_KEY_SZ, (u8 *)&inkey, vl_msk, dc_msk,
3915 nm_msk, 0, ICE_TCAM_KEY_SZ / 2);
3919 * ice_tcam_write_entry - write TCAM entry
3920 * @hw: pointer to the HW struct
3921 * @blk: the block in which to write profile ID to
3922 * @idx: the entry index to write to
3923 * @prof_id: profile ID
3924 * @ptg: packet type group (PTG) portion of key
3925 * @vsig: VSIG portion of key
3926 * @cdid: CDID: portion of key
3927 * @flags: flag portion of key
3928 * @vl_msk: valid mask
3929 * @dc_msk: don't care mask
3930 * @nm_msk: never match mask
3932 static enum ice_status
3933 ice_tcam_write_entry(struct ice_hw *hw, enum ice_block blk, u16 idx,
3934 u8 prof_id, u8 ptg, u16 vsig, u8 cdid, u16 flags,
3935 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ],
3936 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ],
3937 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ])
3939 struct ice_prof_tcam_entry;
3940 enum ice_status status;
3942 status = ice_prof_gen_key(hw, blk, ptg, vsig, cdid, flags, vl_msk,
3943 dc_msk, nm_msk, hw->blk[blk].prof.t[idx].key);
3945 hw->blk[blk].prof.t[idx].addr = CPU_TO_LE16(idx);
3946 hw->blk[blk].prof.t[idx].prof_id = prof_id;
3953 * ice_vsig_get_ref - returns number of VSIs belong to a VSIG
3954 * @hw: pointer to the hardware structure
3956 * @vsig: VSIG to query
3957 * @refs: pointer to variable to receive the reference count
3959 static enum ice_status
3960 ice_vsig_get_ref(struct ice_hw *hw, enum ice_block blk, u16 vsig, u16 *refs)
3962 u16 idx = vsig & ICE_VSIG_IDX_M;
3963 struct ice_vsig_vsi *ptr;
3967 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
3968 return ICE_ERR_DOES_NOT_EXIST;
3970 ptr = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
3973 ptr = ptr->next_vsi;
3980 * ice_has_prof_vsig - check to see if VSIG has a specific profile
3981 * @hw: pointer to the hardware structure
3983 * @vsig: VSIG to check against
3984 * @hdl: profile handle
3987 ice_has_prof_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl)
3989 u16 idx = vsig & ICE_VSIG_IDX_M;
3990 struct ice_vsig_prof *ent;
3992 LIST_FOR_EACH_ENTRY(ent, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
3993 ice_vsig_prof, list) {
3994 if (ent->profile_cookie == hdl)
3998 ice_debug(hw, ICE_DBG_INIT,
3999 "Characteristic list for VSI group %d not found.\n",
4005 * ice_prof_bld_es - build profile ID extraction sequence changes
4006 * @hw: pointer to the HW struct
4007 * @blk: hardware block
4008 * @bld: the update package buffer build to add to
4009 * @chgs: the list of changes to make in hardware
4011 static enum ice_status
4012 ice_prof_bld_es(struct ice_hw *hw, enum ice_block blk,
4013 struct ice_buf_build *bld, struct LIST_HEAD_TYPE *chgs)
4015 u16 vec_size = hw->blk[blk].es.fvw * sizeof(struct ice_fv_word);
4016 struct ice_chs_chg *tmp;
4018 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
4019 if (tmp->type == ICE_PTG_ES_ADD && tmp->add_prof) {
4020 u16 off = tmp->prof_id * hw->blk[blk].es.fvw;
4021 struct ice_pkg_es *p;
4024 id = ice_sect_id(blk, ICE_VEC_TBL);
4025 p = (struct ice_pkg_es *)
4026 ice_pkg_buf_alloc_section(bld, id, sizeof(*p) +
4031 return ICE_ERR_MAX_LIMIT;
4033 p->count = CPU_TO_LE16(1);
4034 p->offset = CPU_TO_LE16(tmp->prof_id);
4036 ice_memcpy(p->es, &hw->blk[blk].es.t[off], vec_size,
4037 ICE_NONDMA_TO_NONDMA);
4045 * ice_prof_bld_tcam - build profile ID TCAM changes
4046 * @hw: pointer to the HW struct
4047 * @blk: hardware block
4048 * @bld: the update package buffer build to add to
4049 * @chgs: the list of changes to make in hardware
4051 static enum ice_status
4052 ice_prof_bld_tcam(struct ice_hw *hw, enum ice_block blk,
4053 struct ice_buf_build *bld, struct LIST_HEAD_TYPE *chgs)
4055 struct ice_chs_chg *tmp;
4057 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
4058 if (tmp->type == ICE_TCAM_ADD && tmp->add_tcam_idx) {
4059 struct ice_prof_id_section *p;
4062 id = ice_sect_id(blk, ICE_PROF_TCAM);
4063 p = (struct ice_prof_id_section *)
4064 ice_pkg_buf_alloc_section(bld, id, sizeof(*p));
4067 return ICE_ERR_MAX_LIMIT;
4069 p->count = CPU_TO_LE16(1);
4070 p->entry[0].addr = CPU_TO_LE16(tmp->tcam_idx);
4071 p->entry[0].prof_id = tmp->prof_id;
4073 ice_memcpy(p->entry[0].key,
4074 &hw->blk[blk].prof.t[tmp->tcam_idx].key,
4075 sizeof(hw->blk[blk].prof.t->key),
4076 ICE_NONDMA_TO_NONDMA);
4084 * ice_prof_bld_xlt1 - build XLT1 changes
4085 * @blk: hardware block
4086 * @bld: the update package buffer build to add to
4087 * @chgs: the list of changes to make in hardware
4089 static enum ice_status
4090 ice_prof_bld_xlt1(enum ice_block blk, struct ice_buf_build *bld,
4091 struct LIST_HEAD_TYPE *chgs)
4093 struct ice_chs_chg *tmp;
4095 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
4096 if (tmp->type == ICE_PTG_ES_ADD && tmp->add_ptg) {
4097 struct ice_xlt1_section *p;
4100 id = ice_sect_id(blk, ICE_XLT1);
4101 p = (struct ice_xlt1_section *)
4102 ice_pkg_buf_alloc_section(bld, id, sizeof(*p));
4105 return ICE_ERR_MAX_LIMIT;
4107 p->count = CPU_TO_LE16(1);
4108 p->offset = CPU_TO_LE16(tmp->ptype);
4109 p->value[0] = tmp->ptg;
4117 * ice_prof_bld_xlt2 - build XLT2 changes
4118 * @blk: hardware block
4119 * @bld: the update package buffer build to add to
4120 * @chgs: the list of changes to make in hardware
4122 static enum ice_status
4123 ice_prof_bld_xlt2(enum ice_block blk, struct ice_buf_build *bld,
4124 struct LIST_HEAD_TYPE *chgs)
4126 struct ice_chs_chg *tmp;
4128 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
4129 struct ice_xlt2_section *p;
4132 switch (tmp->type) {
4136 id = ice_sect_id(blk, ICE_XLT2);
4137 p = (struct ice_xlt2_section *)
4138 ice_pkg_buf_alloc_section(bld, id, sizeof(*p));
4141 return ICE_ERR_MAX_LIMIT;
4143 p->count = CPU_TO_LE16(1);
4144 p->offset = CPU_TO_LE16(tmp->vsi);
4145 p->value[0] = CPU_TO_LE16(tmp->vsig);
4156 * ice_upd_prof_hw - update hardware using the change list
4157 * @hw: pointer to the HW struct
4158 * @blk: hardware block
4159 * @chgs: the list of changes to make in hardware
4161 static enum ice_status
4162 ice_upd_prof_hw(struct ice_hw *hw, enum ice_block blk,
4163 struct LIST_HEAD_TYPE *chgs)
4165 struct ice_buf_build *b;
4166 struct ice_chs_chg *tmp;
4167 enum ice_status status;
4175 /* count number of sections we need */
4176 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
4177 switch (tmp->type) {
4178 case ICE_PTG_ES_ADD:
4196 sects = xlt1 + xlt2 + tcam + es;
4201 /* Build update package buffer */
4202 b = ice_pkg_buf_alloc(hw);
4204 return ICE_ERR_NO_MEMORY;
4206 status = ice_pkg_buf_reserve_section(b, sects);
4210 /* Preserve order of table update: ES, TCAM, PTG, VSIG */
4212 status = ice_prof_bld_es(hw, blk, b, chgs);
4218 status = ice_prof_bld_tcam(hw, blk, b, chgs);
4224 status = ice_prof_bld_xlt1(blk, b, chgs);
4230 status = ice_prof_bld_xlt2(blk, b, chgs);
4235 /* After package buffer build check if the section count in buffer is
4236 * non-zero and matches the number of sections detected for package
4239 pkg_sects = ice_pkg_buf_get_active_sections(b);
4240 if (!pkg_sects || pkg_sects != sects) {
4241 status = ICE_ERR_INVAL_SIZE;
4245 /* update package */
4246 status = ice_update_pkg(hw, ice_pkg_buf(b), 1);
4247 if (status == ICE_ERR_AQ_ERROR)
4248 ice_debug(hw, ICE_DBG_INIT, "Unable to update HW profile\n");
4251 ice_pkg_buf_free(hw, b);
4256 * ice_add_prof - add profile
4257 * @hw: pointer to the HW struct
4258 * @blk: hardware block
4259 * @id: profile tracking ID
4260 * @ptypes: array of bitmaps indicating ptypes (ICE_FLOW_PTYPE_MAX bits)
4261 * @es: extraction sequence (length of array is determined by the block)
4263 * This function registers a profile, which matches a set of PTGs with a
4264 * particular extraction sequence. While the hardware profile is allocated
4265 * it will not be written until the first call to ice_add_flow that specifies
4266 * the ID value used here.
4269 ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64 id, u8 ptypes[],
4270 struct ice_fv_word *es)
4272 u32 bytes = DIVIDE_AND_ROUND_UP(ICE_FLOW_PTYPE_MAX, BITS_PER_BYTE);
4273 ice_declare_bitmap(ptgs_used, ICE_XLT1_CNT);
4274 struct ice_prof_map *prof;
4275 enum ice_status status;
4279 ice_zero_bitmap(ptgs_used, ICE_XLT1_CNT);
4281 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
4283 /* search for existing profile */
4284 status = ice_find_prof_id(hw, blk, es, &prof_id);
4286 /* allocate profile ID */
4287 status = ice_alloc_prof_id(hw, blk, &prof_id);
4289 goto err_ice_add_prof;
4291 /* and write new es */
4292 ice_write_es(hw, blk, prof_id, es);
4295 ice_prof_inc_ref(hw, blk, prof_id);
4297 /* add profile info */
4299 prof = (struct ice_prof_map *)ice_malloc(hw, sizeof(*prof));
4301 goto err_ice_add_prof;
4303 prof->profile_cookie = id;
4304 prof->prof_id = prof_id;
4308 /* build list of ptgs */
4309 while (bytes && prof->ptg_cnt < ICE_MAX_PTG_PER_PROFILE) {
4312 if (!ptypes[byte]) {
4317 /* Examine 8 bits per byte */
4318 for (bit = 0; bit < 8; bit++) {
4319 if (ptypes[byte] & BIT(bit)) {
4324 ptype = byte * BITS_PER_BYTE + bit;
4326 /* The package should place all ptypes in a
4327 * non-zero PTG, so the following call should
4330 if (ice_ptg_find_ptype(hw, blk, ptype, &ptg))
4333 /* If PTG is already added, skip and continue */
4334 if (ice_is_bit_set(ptgs_used, ptg))
4337 ice_set_bit(ptg, ptgs_used);
4338 prof->ptg[prof->ptg_cnt] = ptg;
4340 if (++prof->ptg_cnt >= ICE_MAX_PTG_PER_PROFILE)
4343 /* nothing left in byte, then exit */
4344 m = ~(u8)((1 << (bit + 1)) - 1);
4345 if (!(ptypes[byte] & m))
4354 LIST_ADD(&prof->list, &hw->blk[blk].es.prof_map);
4355 status = ICE_SUCCESS;
4358 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
4363 * ice_search_prof_id_low - Search for a profile tracking ID low level
4364 * @hw: pointer to the HW struct
4365 * @blk: hardware block
4366 * @id: profile tracking ID
4368 * This will search for a profile tracking ID which was previously added. This
4369 * version assumes that the caller has already acquired the prof map lock.
4371 static struct ice_prof_map *
4372 ice_search_prof_id_low(struct ice_hw *hw, enum ice_block blk, u64 id)
4374 struct ice_prof_map *entry = NULL;
4375 struct ice_prof_map *map;
4377 LIST_FOR_EACH_ENTRY(map, &hw->blk[blk].es.prof_map, ice_prof_map,
4379 if (map->profile_cookie == id) {
4389 * ice_search_prof_id - Search for a profile tracking ID
4390 * @hw: pointer to the HW struct
4391 * @blk: hardware block
4392 * @id: profile tracking ID
4394 * This will search for a profile tracking ID which was previously added.
4396 struct ice_prof_map *
4397 ice_search_prof_id(struct ice_hw *hw, enum ice_block blk, u64 id)
4399 struct ice_prof_map *entry;
4401 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
4402 entry = ice_search_prof_id_low(hw, blk, id);
4403 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
4409 * ice_set_prof_context - Set context for a given profile
4410 * @hw: pointer to the HW struct
4411 * @blk: hardware block
4412 * @id: profile tracking ID
4415 struct ice_prof_map *
4416 ice_set_prof_context(struct ice_hw *hw, enum ice_block blk, u64 id, u64 cntxt)
4418 struct ice_prof_map *entry;
4420 entry = ice_search_prof_id(hw, blk, id);
4422 entry->context = cntxt;
4428 * ice_get_prof_context - Get context for a given profile
4429 * @hw: pointer to the HW struct
4430 * @blk: hardware block
4431 * @id: profile tracking ID
4432 * @cntxt: pointer to variable to receive the context
4434 struct ice_prof_map *
4435 ice_get_prof_context(struct ice_hw *hw, enum ice_block blk, u64 id, u64 *cntxt)
4437 struct ice_prof_map *entry;
4439 entry = ice_search_prof_id(hw, blk, id);
4441 *cntxt = entry->context;
4447 * ice_vsig_prof_id_count - count profiles in a VSIG
4448 * @hw: pointer to the HW struct
4449 * @blk: hardware block
4450 * @vsig: VSIG to remove the profile from
4453 ice_vsig_prof_id_count(struct ice_hw *hw, enum ice_block blk, u16 vsig)
4455 u16 idx = vsig & ICE_VSIG_IDX_M, count = 0;
4456 struct ice_vsig_prof *p;
4458 LIST_FOR_EACH_ENTRY(p, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4459 ice_vsig_prof, list) {
4467 * ice_rel_tcam_idx - release a TCAM index
4468 * @hw: pointer to the HW struct
4469 * @blk: hardware block
4470 * @idx: the index to release
4472 static enum ice_status
4473 ice_rel_tcam_idx(struct ice_hw *hw, enum ice_block blk, u16 idx)
4475 /* Masks to invoke a never match entry */
4476 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4477 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFE, 0xFF, 0xFF, 0xFF, 0xFF };
4478 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x01, 0x00, 0x00, 0x00, 0x00 };
4479 enum ice_status status;
4481 /* write the TCAM entry */
4482 status = ice_tcam_write_entry(hw, blk, idx, 0, 0, 0, 0, 0, vl_msk,
4487 /* release the TCAM entry */
4488 status = ice_free_tcam_ent(hw, blk, idx);
4494 * ice_rem_prof_id - remove one profile from a VSIG
4495 * @hw: pointer to the HW struct
4496 * @blk: hardware block
4497 * @prof: pointer to profile structure to remove
4499 static enum ice_status
4500 ice_rem_prof_id(struct ice_hw *hw, enum ice_block blk,
4501 struct ice_vsig_prof *prof)
4503 enum ice_status status;
4506 for (i = 0; i < prof->tcam_count; i++) {
4507 if (prof->tcam[i].in_use) {
4508 prof->tcam[i].in_use = false;
4509 status = ice_rel_tcam_idx(hw, blk,
4510 prof->tcam[i].tcam_idx);
4512 return ICE_ERR_HW_TABLE;
4520 * ice_rem_vsig - remove VSIG
4521 * @hw: pointer to the HW struct
4522 * @blk: hardware block
4523 * @vsig: the VSIG to remove
4524 * @chg: the change list
4526 static enum ice_status
4527 ice_rem_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig,
4528 struct LIST_HEAD_TYPE *chg)
4530 u16 idx = vsig & ICE_VSIG_IDX_M;
4531 struct ice_vsig_vsi *vsi_cur;
4532 struct ice_vsig_prof *d, *t;
4533 enum ice_status status;
4535 /* remove TCAM entries */
4536 LIST_FOR_EACH_ENTRY_SAFE(d, t,
4537 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4538 ice_vsig_prof, list) {
4539 status = ice_rem_prof_id(hw, blk, d);
4547 /* Move all VSIS associated with this VSIG to the default VSIG */
4548 vsi_cur = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
4549 /* If the VSIG has at least 1 VSI then iterate through the list
4550 * and remove the VSIs before deleting the group.
4554 struct ice_vsig_vsi *tmp = vsi_cur->next_vsi;
4555 struct ice_chs_chg *p;
4557 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4559 return ICE_ERR_NO_MEMORY;
4561 p->type = ICE_VSIG_REM;
4562 p->orig_vsig = vsig;
4563 p->vsig = ICE_DEFAULT_VSIG;
4564 p->vsi = vsi_cur - hw->blk[blk].xlt2.vsis;
4566 LIST_ADD(&p->list_entry, chg);
4572 return ice_vsig_free(hw, blk, vsig);
4576 * ice_rem_prof_id_vsig - remove a specific profile from a VSIG
4577 * @hw: pointer to the HW struct
4578 * @blk: hardware block
4579 * @vsig: VSIG to remove the profile from
4580 * @hdl: profile handle indicating which profile to remove
4581 * @chg: list to receive a record of changes
4583 static enum ice_status
4584 ice_rem_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl,
4585 struct LIST_HEAD_TYPE *chg)
4587 u16 idx = vsig & ICE_VSIG_IDX_M;
4588 struct ice_vsig_prof *p, *t;
4589 enum ice_status status;
4591 LIST_FOR_EACH_ENTRY_SAFE(p, t,
4592 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4593 ice_vsig_prof, list) {
4594 if (p->profile_cookie == hdl) {
4595 if (ice_vsig_prof_id_count(hw, blk, vsig) == 1)
4596 /* this is the last profile, remove the VSIG */
4597 return ice_rem_vsig(hw, blk, vsig, chg);
4599 status = ice_rem_prof_id(hw, blk, p);
4608 return ICE_ERR_DOES_NOT_EXIST;
4612 * ice_rem_flow_all - remove all flows with a particular profile
4613 * @hw: pointer to the HW struct
4614 * @blk: hardware block
4615 * @id: profile tracking ID
4617 static enum ice_status
4618 ice_rem_flow_all(struct ice_hw *hw, enum ice_block blk, u64 id)
4620 struct ice_chs_chg *del, *tmp;
4621 struct LIST_HEAD_TYPE chg;
4622 enum ice_status status;
4625 INIT_LIST_HEAD(&chg);
4627 for (i = 1; i < ICE_MAX_VSIGS; i++) {
4628 if (hw->blk[blk].xlt2.vsig_tbl[i].in_use) {
4629 if (ice_has_prof_vsig(hw, blk, i, id)) {
4630 status = ice_rem_prof_id_vsig(hw, blk, i, id,
4633 goto err_ice_rem_flow_all;
4638 status = ice_upd_prof_hw(hw, blk, &chg);
4640 err_ice_rem_flow_all:
4641 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
4642 LIST_DEL(&del->list_entry);
4650 * ice_rem_prof - remove profile
4651 * @hw: pointer to the HW struct
4652 * @blk: hardware block
4653 * @id: profile tracking ID
4655 * This will remove the profile specified by the ID parameter, which was
4656 * previously created through ice_add_prof. If any existing entries
4657 * are associated with this profile, they will be removed as well.
4659 enum ice_status ice_rem_prof(struct ice_hw *hw, enum ice_block blk, u64 id)
4661 struct ice_prof_map *pmap;
4662 enum ice_status status;
4664 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
4666 pmap = ice_search_prof_id_low(hw, blk, id);
4668 status = ICE_ERR_DOES_NOT_EXIST;
4669 goto err_ice_rem_prof;
4672 /* remove all flows with this profile */
4673 status = ice_rem_flow_all(hw, blk, pmap->profile_cookie);
4675 goto err_ice_rem_prof;
4677 /* dereference profile, and possibly remove */
4678 ice_prof_dec_ref(hw, blk, pmap->prof_id);
4680 LIST_DEL(&pmap->list);
4684 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
4689 * ice_get_prof - get profile
4690 * @hw: pointer to the HW struct
4691 * @blk: hardware block
4692 * @hdl: profile handle
4695 static enum ice_status
4696 ice_get_prof(struct ice_hw *hw, enum ice_block blk, u64 hdl,
4697 struct LIST_HEAD_TYPE *chg)
4699 struct ice_prof_map *map;
4700 struct ice_chs_chg *p;
4703 /* Get the details on the profile specified by the handle ID */
4704 map = ice_search_prof_id(hw, blk, hdl);
4706 return ICE_ERR_DOES_NOT_EXIST;
4708 for (i = 0; i < map->ptg_cnt; i++) {
4709 if (!hw->blk[blk].es.written[map->prof_id]) {
4710 /* add ES to change list */
4711 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4713 goto err_ice_get_prof;
4715 p->type = ICE_PTG_ES_ADD;
4717 p->ptg = map->ptg[i];
4721 p->prof_id = map->prof_id;
4723 hw->blk[blk].es.written[map->prof_id] = true;
4725 LIST_ADD(&p->list_entry, chg);
4732 /* let caller clean up the change list */
4733 return ICE_ERR_NO_MEMORY;
4737 * ice_get_profs_vsig - get a copy of the list of profiles from a VSIG
4738 * @hw: pointer to the HW struct
4739 * @blk: hardware block
4740 * @vsig: VSIG from which to copy the list
4743 * This routine makes a copy of the list of profiles in the specified VSIG.
4745 static enum ice_status
4746 ice_get_profs_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig,
4747 struct LIST_HEAD_TYPE *lst)
4749 struct ice_vsig_prof *ent1, *ent2;
4750 u16 idx = vsig & ICE_VSIG_IDX_M;
4752 LIST_FOR_EACH_ENTRY(ent1, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4753 ice_vsig_prof, list) {
4754 struct ice_vsig_prof *p;
4756 /* copy to the input list */
4757 p = (struct ice_vsig_prof *)ice_memdup(hw, ent1, sizeof(*p),
4758 ICE_NONDMA_TO_NONDMA);
4760 goto err_ice_get_profs_vsig;
4762 LIST_ADD_TAIL(&p->list, lst);
4767 err_ice_get_profs_vsig:
4768 LIST_FOR_EACH_ENTRY_SAFE(ent1, ent2, lst, ice_vsig_prof, list) {
4769 LIST_DEL(&ent1->list);
4773 return ICE_ERR_NO_MEMORY;
4777 * ice_add_prof_to_lst - add profile entry to a list
4778 * @hw: pointer to the HW struct
4779 * @blk: hardware block
4780 * @lst: the list to be added to
4781 * @hdl: profile handle of entry to add
4783 static enum ice_status
4784 ice_add_prof_to_lst(struct ice_hw *hw, enum ice_block blk,
4785 struct LIST_HEAD_TYPE *lst, u64 hdl)
4787 struct ice_prof_map *map;
4788 struct ice_vsig_prof *p;
4791 map = ice_search_prof_id(hw, blk, hdl);
4793 return ICE_ERR_DOES_NOT_EXIST;
4795 p = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*p));
4797 return ICE_ERR_NO_MEMORY;
4799 p->profile_cookie = map->profile_cookie;
4800 p->prof_id = map->prof_id;
4801 p->tcam_count = map->ptg_cnt;
4803 for (i = 0; i < map->ptg_cnt; i++) {
4804 p->tcam[i].prof_id = map->prof_id;
4805 p->tcam[i].tcam_idx = ICE_INVALID_TCAM;
4806 p->tcam[i].ptg = map->ptg[i];
4809 LIST_ADD(&p->list, lst);
4815 * ice_move_vsi - move VSI to another VSIG
4816 * @hw: pointer to the HW struct
4817 * @blk: hardware block
4818 * @vsi: the VSI to move
4819 * @vsig: the VSIG to move the VSI to
4820 * @chg: the change list
4822 static enum ice_status
4823 ice_move_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig,
4824 struct LIST_HEAD_TYPE *chg)
4826 enum ice_status status;
4827 struct ice_chs_chg *p;
4830 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4832 return ICE_ERR_NO_MEMORY;
4834 status = ice_vsig_find_vsi(hw, blk, vsi, &orig_vsig);
4836 status = ice_vsig_add_mv_vsi(hw, blk, vsi, vsig);
4843 p->type = ICE_VSI_MOVE;
4845 p->orig_vsig = orig_vsig;
4848 LIST_ADD(&p->list_entry, chg);
4854 * ice_rem_chg_tcam_ent - remove a specific TCAM entry from change list
4855 * @hw: pointer to the HW struct
4856 * @idx: the index of the TCAM entry to remove
4857 * @chg: the list of change structures to search
4860 ice_rem_chg_tcam_ent(struct ice_hw *hw, u16 idx, struct LIST_HEAD_TYPE *chg)
4862 struct ice_chs_chg *pos, *tmp;
4864 LIST_FOR_EACH_ENTRY_SAFE(tmp, pos, chg, ice_chs_chg, list_entry) {
4865 if (tmp->type == ICE_TCAM_ADD && tmp->tcam_idx == idx) {
4866 LIST_DEL(&tmp->list_entry);
4873 * ice_prof_tcam_ena_dis - add enable or disable TCAM change
4874 * @hw: pointer to the HW struct
4875 * @blk: hardware block
4876 * @enable: true to enable, false to disable
4877 * @vsig: the VSIG of the TCAM entry
4878 * @tcam: pointer the TCAM info structure of the TCAM to disable
4879 * @chg: the change list
4881 * This function appends an enable or disable TCAM entry in the change log
4883 static enum ice_status
4884 ice_prof_tcam_ena_dis(struct ice_hw *hw, enum ice_block blk, bool enable,
4885 u16 vsig, struct ice_tcam_inf *tcam,
4886 struct LIST_HEAD_TYPE *chg)
4888 enum ice_status status;
4889 struct ice_chs_chg *p;
4891 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4892 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0x00, 0x00, 0x00 };
4893 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
4895 /* if disabling, free the TCAM */
4897 status = ice_rel_tcam_idx(hw, blk, tcam->tcam_idx);
4899 /* if we have already created a change for this TCAM entry, then
4900 * we need to remove that entry, in order to prevent writing to
4901 * a TCAM entry we no longer will have ownership of.
4903 ice_rem_chg_tcam_ent(hw, tcam->tcam_idx, chg);
4909 /* for re-enabling, reallocate a TCAM */
4910 status = ice_alloc_tcam_ent(hw, blk, &tcam->tcam_idx);
4914 /* add TCAM to change list */
4915 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4917 return ICE_ERR_NO_MEMORY;
4919 status = ice_tcam_write_entry(hw, blk, tcam->tcam_idx, tcam->prof_id,
4920 tcam->ptg, vsig, 0, 0, vl_msk, dc_msk,
4923 goto err_ice_prof_tcam_ena_dis;
4927 p->type = ICE_TCAM_ADD;
4928 p->add_tcam_idx = true;
4929 p->prof_id = tcam->prof_id;
4932 p->tcam_idx = tcam->tcam_idx;
4935 LIST_ADD(&p->list_entry, chg);
4939 err_ice_prof_tcam_ena_dis:
4945 * ice_adj_prof_priorities - adjust profile based on priorities
4946 * @hw: pointer to the HW struct
4947 * @blk: hardware block
4948 * @vsig: the VSIG for which to adjust profile priorities
4949 * @chg: the change list
4951 static enum ice_status
4952 ice_adj_prof_priorities(struct ice_hw *hw, enum ice_block blk, u16 vsig,
4953 struct LIST_HEAD_TYPE *chg)
4955 ice_declare_bitmap(ptgs_used, ICE_XLT1_CNT);
4956 enum ice_status status = ICE_SUCCESS;
4957 struct ice_vsig_prof *t;
4960 ice_zero_bitmap(ptgs_used, ICE_XLT1_CNT);
4961 idx = vsig & ICE_VSIG_IDX_M;
4963 /* Priority is based on the order in which the profiles are added. The
4964 * newest added profile has highest priority and the oldest added
4965 * profile has the lowest priority. Since the profile property list for
4966 * a VSIG is sorted from newest to oldest, this code traverses the list
4967 * in order and enables the first of each PTG that it finds (that is not
4968 * already enabled); it also disables any duplicate PTGs that it finds
4969 * in the older profiles (that are currently enabled).
4972 LIST_FOR_EACH_ENTRY(t, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4973 ice_vsig_prof, list) {
4976 for (i = 0; i < t->tcam_count; i++) {
4979 /* Scan the priorities from newest to oldest.
4980 * Make sure that the newest profiles take priority.
4982 used = ice_is_bit_set(ptgs_used, t->tcam[i].ptg);
4984 if (used && t->tcam[i].in_use) {
4985 /* need to mark this PTG as never match, as it
4986 * was already in use and therefore duplicate
4987 * (and lower priority)
4989 status = ice_prof_tcam_ena_dis(hw, blk, false,
4995 } else if (!used && !t->tcam[i].in_use) {
4996 /* need to enable this PTG, as it in not in use
4997 * and not enabled (highest priority)
4999 status = ice_prof_tcam_ena_dis(hw, blk, true,
5007 /* keep track of used ptgs */
5008 ice_set_bit(t->tcam[i].ptg, ptgs_used);
5016 * ice_add_prof_id_vsig - add profile to VSIG
5017 * @hw: pointer to the HW struct
5018 * @blk: hardware block
5019 * @vsig: the VSIG to which this profile is to be added
5020 * @hdl: the profile handle indicating the profile to add
5021 * @rev: true to add entries to the end of the list
5022 * @chg: the change list
5024 static enum ice_status
5025 ice_add_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl,
5026 bool rev, struct LIST_HEAD_TYPE *chg)
5028 /* Masks that ignore flags */
5029 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
5030 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0x00, 0x00, 0x00 };
5031 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
5032 struct ice_prof_map *map;
5033 struct ice_vsig_prof *t;
5034 struct ice_chs_chg *p;
5037 /* Get the details on the profile specified by the handle ID */
5038 map = ice_search_prof_id(hw, blk, hdl);
5040 return ICE_ERR_DOES_NOT_EXIST;
5042 /* Error, if this VSIG already has this profile */
5043 if (ice_has_prof_vsig(hw, blk, vsig, hdl))
5044 return ICE_ERR_ALREADY_EXISTS;
5046 /* new VSIG profile structure */
5047 t = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*t));
5049 return ICE_ERR_NO_MEMORY;
5051 t->profile_cookie = map->profile_cookie;
5052 t->prof_id = map->prof_id;
5053 t->tcam_count = map->ptg_cnt;
5055 /* create TCAM entries */
5056 for (i = 0; i < map->ptg_cnt; i++) {
5057 enum ice_status status;
5060 /* add TCAM to change list */
5061 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5063 goto err_ice_add_prof_id_vsig;
5065 /* allocate the TCAM entry index */
5066 status = ice_alloc_tcam_ent(hw, blk, &tcam_idx);
5069 goto err_ice_add_prof_id_vsig;
5072 t->tcam[i].ptg = map->ptg[i];
5073 t->tcam[i].prof_id = map->prof_id;
5074 t->tcam[i].tcam_idx = tcam_idx;
5075 t->tcam[i].in_use = true;
5077 p->type = ICE_TCAM_ADD;
5078 p->add_tcam_idx = true;
5079 p->prof_id = t->tcam[i].prof_id;
5080 p->ptg = t->tcam[i].ptg;
5082 p->tcam_idx = t->tcam[i].tcam_idx;
5084 /* write the TCAM entry */
5085 status = ice_tcam_write_entry(hw, blk, t->tcam[i].tcam_idx,
5087 t->tcam[i].ptg, vsig, 0, 0,
5088 vl_msk, dc_msk, nm_msk);
5091 goto err_ice_add_prof_id_vsig;
5095 LIST_ADD(&p->list_entry, chg);
5098 /* add profile to VSIG */
5099 vsig_idx = vsig & ICE_VSIG_IDX_M;
5101 LIST_ADD_TAIL(&t->list,
5102 &hw->blk[blk].xlt2.vsig_tbl[vsig_idx].prop_lst);
5105 &hw->blk[blk].xlt2.vsig_tbl[vsig_idx].prop_lst);
5109 err_ice_add_prof_id_vsig:
5110 /* let caller clean up the change list */
5112 return ICE_ERR_NO_MEMORY;
5116 * ice_create_prof_id_vsig - add a new VSIG with a single profile
5117 * @hw: pointer to the HW struct
5118 * @blk: hardware block
5119 * @vsi: the initial VSI that will be in VSIG
5120 * @hdl: the profile handle of the profile that will be added to the VSIG
5121 * @chg: the change list
5123 static enum ice_status
5124 ice_create_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl,
5125 struct LIST_HEAD_TYPE *chg)
5127 enum ice_status status;
5128 struct ice_chs_chg *p;
5131 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5133 return ICE_ERR_NO_MEMORY;
5135 new_vsig = ice_vsig_alloc(hw, blk);
5137 status = ICE_ERR_HW_TABLE;
5138 goto err_ice_create_prof_id_vsig;
5141 status = ice_move_vsi(hw, blk, vsi, new_vsig, chg);
5143 goto err_ice_create_prof_id_vsig;
5145 status = ice_add_prof_id_vsig(hw, blk, new_vsig, hdl, false, chg);
5147 goto err_ice_create_prof_id_vsig;
5149 p->type = ICE_VSIG_ADD;
5151 p->orig_vsig = ICE_DEFAULT_VSIG;
5154 LIST_ADD(&p->list_entry, chg);
5158 err_ice_create_prof_id_vsig:
5159 /* let caller clean up the change list */
5165 * ice_create_vsig_from_lst - create a new VSIG with a list of profiles
5166 * @hw: pointer to the HW struct
5167 * @blk: hardware block
5168 * @vsi: the initial VSI that will be in VSIG
5169 * @lst: the list of profile that will be added to the VSIG
5170 * @new_vsig: return of new VSIG
5171 * @chg: the change list
5173 static enum ice_status
5174 ice_create_vsig_from_lst(struct ice_hw *hw, enum ice_block blk, u16 vsi,
5175 struct LIST_HEAD_TYPE *lst, u16 *new_vsig,
5176 struct LIST_HEAD_TYPE *chg)
5178 struct ice_vsig_prof *t;
5179 enum ice_status status;
5182 vsig = ice_vsig_alloc(hw, blk);
5184 return ICE_ERR_HW_TABLE;
5186 status = ice_move_vsi(hw, blk, vsi, vsig, chg);
5190 LIST_FOR_EACH_ENTRY(t, lst, ice_vsig_prof, list) {
5191 /* Reverse the order here since we are copying the list */
5192 status = ice_add_prof_id_vsig(hw, blk, vsig, t->profile_cookie,
5204 * ice_find_prof_vsig - find a VSIG with a specific profile handle
5205 * @hw: pointer to the HW struct
5206 * @blk: hardware block
5207 * @hdl: the profile handle of the profile to search for
5208 * @vsig: returns the VSIG with the matching profile
5211 ice_find_prof_vsig(struct ice_hw *hw, enum ice_block blk, u64 hdl, u16 *vsig)
5213 struct ice_vsig_prof *t;
5214 struct LIST_HEAD_TYPE lst;
5215 enum ice_status status;
5217 INIT_LIST_HEAD(&lst);
5219 t = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*t));
5223 t->profile_cookie = hdl;
5224 LIST_ADD(&t->list, &lst);
5226 status = ice_find_dup_props_vsig(hw, blk, &lst, vsig);
5231 return status == ICE_SUCCESS;
5235 * ice_add_vsi_flow - add VSI flow
5236 * @hw: pointer to the HW struct
5237 * @blk: hardware block
5239 * @vsig: target VSIG to include the input VSI
5241 * Calling this function will add the VSI to a given VSIG and
5242 * update the HW tables accordingly. This call can be used to
5243 * add multiple VSIs to a VSIG if we know beforehand that those
5244 * VSIs have the same characteristics of the VSIG. This will
5245 * save time in generating a new VSIG and TCAMs till a match is
5246 * found and subsequent rollback when a matching VSIG is found.
5249 ice_add_vsi_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
5251 struct ice_chs_chg *tmp, *del;
5252 struct LIST_HEAD_TYPE chg;
5253 enum ice_status status;
5255 /* if target VSIG is default the move is invalid */
5256 if ((vsig & ICE_VSIG_IDX_M) == ICE_DEFAULT_VSIG)
5257 return ICE_ERR_PARAM;
5259 INIT_LIST_HEAD(&chg);
5261 /* move VSI to the VSIG that matches */
5262 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5263 /* update hardware if success */
5265 status = ice_upd_prof_hw(hw, blk, &chg);
5267 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
5268 LIST_DEL(&del->list_entry);
5276 * ice_add_prof_id_flow - add profile flow
5277 * @hw: pointer to the HW struct
5278 * @blk: hardware block
5279 * @vsi: the VSI to enable with the profile specified by ID
5280 * @hdl: profile handle
5282 * Calling this function will update the hardware tables to enable the
5283 * profile indicated by the ID parameter for the VSIs specified in the VSI
5284 * array. Once successfully called, the flow will be enabled.
5287 ice_add_prof_id_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl)
5289 struct ice_vsig_prof *tmp1, *del1;
5290 struct LIST_HEAD_TYPE union_lst;
5291 struct ice_chs_chg *tmp, *del;
5292 struct LIST_HEAD_TYPE chg;
5293 enum ice_status status;
5296 INIT_LIST_HEAD(&union_lst);
5297 INIT_LIST_HEAD(&chg);
5300 status = ice_get_prof(hw, blk, hdl, &chg);
5304 /* determine if VSI is already part of a VSIG */
5305 status = ice_vsig_find_vsi(hw, blk, vsi, &vsig);
5306 if (!status && vsig) {
5314 /* make sure that there is no overlap/conflict between the new
5315 * characteristics and the existing ones; we don't support that
5318 if (ice_has_prof_vsig(hw, blk, vsig, hdl)) {
5319 status = ICE_ERR_ALREADY_EXISTS;
5320 goto err_ice_add_prof_id_flow;
5323 /* last VSI in the VSIG? */
5324 status = ice_vsig_get_ref(hw, blk, vsig, &ref);
5326 goto err_ice_add_prof_id_flow;
5327 only_vsi = (ref == 1);
5329 /* create a union of the current profiles and the one being
5332 status = ice_get_profs_vsig(hw, blk, vsig, &union_lst);
5334 goto err_ice_add_prof_id_flow;
5336 status = ice_add_prof_to_lst(hw, blk, &union_lst, hdl);
5338 goto err_ice_add_prof_id_flow;
5340 /* search for an existing VSIG with an exact charc match */
5341 status = ice_find_dup_props_vsig(hw, blk, &union_lst, &vsig);
5343 /* move VSI to the VSIG that matches */
5344 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5346 goto err_ice_add_prof_id_flow;
5348 /* VSI has been moved out of or_vsig. If the or_vsig had
5349 * only that VSI it is now empty and can be removed.
5352 status = ice_rem_vsig(hw, blk, or_vsig, &chg);
5354 goto err_ice_add_prof_id_flow;
5356 } else if (only_vsi) {
5357 /* If the original VSIG only contains one VSI, then it
5358 * will be the requesting VSI. In this case the VSI is
5359 * not sharing entries and we can simply add the new
5360 * profile to the VSIG.
5362 status = ice_add_prof_id_vsig(hw, blk, vsig, hdl, false,
5365 goto err_ice_add_prof_id_flow;
5367 /* Adjust priorities */
5368 status = ice_adj_prof_priorities(hw, blk, vsig, &chg);
5370 goto err_ice_add_prof_id_flow;
5372 /* No match, so we need a new VSIG */
5373 status = ice_create_vsig_from_lst(hw, blk, vsi,
5377 goto err_ice_add_prof_id_flow;
5379 /* Adjust priorities */
5380 status = ice_adj_prof_priorities(hw, blk, vsig, &chg);
5382 goto err_ice_add_prof_id_flow;
5385 /* need to find or add a VSIG */
5386 /* search for an existing VSIG with an exact charc match */
5387 if (ice_find_prof_vsig(hw, blk, hdl, &vsig)) {
5388 /* found an exact match */
5389 /* add or move VSI to the VSIG that matches */
5390 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5392 goto err_ice_add_prof_id_flow;
5394 /* we did not find an exact match */
5395 /* we need to add a VSIG */
5396 status = ice_create_prof_id_vsig(hw, blk, vsi, hdl,
5399 goto err_ice_add_prof_id_flow;
5403 /* update hardware */
5405 status = ice_upd_prof_hw(hw, blk, &chg);
5407 err_ice_add_prof_id_flow:
5408 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
5409 LIST_DEL(&del->list_entry);
5413 LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, &union_lst, ice_vsig_prof, list) {
5414 LIST_DEL(&del1->list);
5422 * ice_add_flow - add flow
5423 * @hw: pointer to the HW struct
5424 * @blk: hardware block
5425 * @vsi: array of VSIs to enable with the profile specified by ID
5426 * @count: number of elements in the VSI array
5427 * @id: profile tracking ID
5429 * Calling this function will update the hardware tables to enable the
5430 * profile indicated by the ID parameter for the VSIs specified in the VSI
5431 * array. Once successfully called, the flow will be enabled.
5434 ice_add_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi[], u8 count,
5437 enum ice_status status;
5440 for (i = 0; i < count; i++) {
5441 status = ice_add_prof_id_flow(hw, blk, vsi[i], id);
5450 * ice_rem_prof_from_list - remove a profile from list
5451 * @hw: pointer to the HW struct
5452 * @lst: list to remove the profile from
5453 * @hdl: the profile handle indicating the profile to remove
5455 static enum ice_status
5456 ice_rem_prof_from_list(struct ice_hw *hw, struct LIST_HEAD_TYPE *lst, u64 hdl)
5458 struct ice_vsig_prof *ent, *tmp;
5460 LIST_FOR_EACH_ENTRY_SAFE(ent, tmp, lst, ice_vsig_prof, list) {
5461 if (ent->profile_cookie == hdl) {
5462 LIST_DEL(&ent->list);
5468 return ICE_ERR_DOES_NOT_EXIST;
5472 * ice_rem_prof_id_flow - remove flow
5473 * @hw: pointer to the HW struct
5474 * @blk: hardware block
5475 * @vsi: the VSI from which to remove the profile specified by ID
5476 * @hdl: profile tracking handle
5478 * Calling this function will update the hardware tables to remove the
5479 * profile indicated by the ID parameter for the VSIs specified in the VSI
5480 * array. Once successfully called, the flow will be disabled.
5483 ice_rem_prof_id_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl)
5485 struct ice_vsig_prof *tmp1, *del1;
5486 struct LIST_HEAD_TYPE chg, copy;
5487 struct ice_chs_chg *tmp, *del;
5488 enum ice_status status;
5491 INIT_LIST_HEAD(©);
5492 INIT_LIST_HEAD(&chg);
5494 /* determine if VSI is already part of a VSIG */
5495 status = ice_vsig_find_vsi(hw, blk, vsi, &vsig);
5496 if (!status && vsig) {
5502 last_profile = ice_vsig_prof_id_count(hw, blk, vsig) == 1;
5503 status = ice_vsig_get_ref(hw, blk, vsig, &ref);
5505 goto err_ice_rem_prof_id_flow;
5506 only_vsi = (ref == 1);
5509 /* If the original VSIG only contains one reference,
5510 * which will be the requesting VSI, then the VSI is not
5511 * sharing entries and we can simply remove the specific
5512 * characteristics from the VSIG.
5516 /* If there are no profiles left for this VSIG,
5517 * then simply remove the the VSIG.
5519 status = ice_rem_vsig(hw, blk, vsig, &chg);
5521 goto err_ice_rem_prof_id_flow;
5523 status = ice_rem_prof_id_vsig(hw, blk, vsig,
5526 goto err_ice_rem_prof_id_flow;
5528 /* Adjust priorities */
5529 status = ice_adj_prof_priorities(hw, blk, vsig,
5532 goto err_ice_rem_prof_id_flow;
5536 /* Make a copy of the VSIG's list of Profiles */
5537 status = ice_get_profs_vsig(hw, blk, vsig, ©);
5539 goto err_ice_rem_prof_id_flow;
5541 /* Remove specified profile entry from the list */
5542 status = ice_rem_prof_from_list(hw, ©, hdl);
5544 goto err_ice_rem_prof_id_flow;
5546 if (LIST_EMPTY(©)) {
5547 status = ice_move_vsi(hw, blk, vsi,
5548 ICE_DEFAULT_VSIG, &chg);
5550 goto err_ice_rem_prof_id_flow;
5552 } else if (!ice_find_dup_props_vsig(hw, blk, ©,
5554 /* found an exact match */
5555 /* add or move VSI to the VSIG that matches */
5556 /* Search for a VSIG with a matching profile
5560 /* Found match, move VSI to the matching VSIG */
5561 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5563 goto err_ice_rem_prof_id_flow;
5565 /* since no existing VSIG supports this
5566 * characteristic pattern, we need to create a
5567 * new VSIG and TCAM entries
5569 status = ice_create_vsig_from_lst(hw, blk, vsi,
5573 goto err_ice_rem_prof_id_flow;
5575 /* Adjust priorities */
5576 status = ice_adj_prof_priorities(hw, blk, vsig,
5579 goto err_ice_rem_prof_id_flow;
5583 status = ICE_ERR_DOES_NOT_EXIST;
5586 /* update hardware tables */
5588 status = ice_upd_prof_hw(hw, blk, &chg);
5590 err_ice_rem_prof_id_flow:
5591 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
5592 LIST_DEL(&del->list_entry);
5596 LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, ©, ice_vsig_prof, list) {
5597 LIST_DEL(&del1->list);
5605 * ice_rem_flow - remove flow
5606 * @hw: pointer to the HW struct
5607 * @blk: hardware block
5608 * @vsi: array of VSIs from which to remove the profile specified by ID
5609 * @count: number of elements in the VSI array
5610 * @id: profile tracking ID
5612 * The function will remove flows from the specified VSIs that were enabled
5613 * using ice_add_flow. The ID value will indicated which profile will be
5614 * removed. Once successfully called, the flow will be disabled.
5617 ice_rem_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi[], u8 count,
5620 enum ice_status status;
5623 for (i = 0; i < count; i++) {
5624 status = ice_rem_prof_id_flow(hw, blk, vsi[i], id);