1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright (c) 2021, 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 --> upd 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)
683 static enum ice_status
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, "Global config lock: No work to do\n");
749 * ice_release_global_cfg_lock
750 * @hw: pointer to the HW structure
752 * This function will release the global config lock.
754 static void ice_release_global_cfg_lock(struct ice_hw *hw)
756 ice_release_res(hw, ICE_GLOBAL_CFG_LOCK_RES_ID);
760 * ice_acquire_change_lock
761 * @hw: pointer to the HW structure
762 * @access: access type (read or write)
764 * This function will request ownership of the change lock.
766 static enum ice_status
767 ice_acquire_change_lock(struct ice_hw *hw, enum ice_aq_res_access_type access)
769 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
771 return ice_acquire_res(hw, ICE_CHANGE_LOCK_RES_ID, access,
772 ICE_CHANGE_LOCK_TIMEOUT);
776 * ice_release_change_lock
777 * @hw: pointer to the HW structure
779 * This function will release the change lock using the proper Admin Command.
781 static void ice_release_change_lock(struct ice_hw *hw)
783 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
785 ice_release_res(hw, ICE_CHANGE_LOCK_RES_ID);
789 * ice_aq_download_pkg
790 * @hw: pointer to the hardware structure
791 * @pkg_buf: the package buffer to transfer
792 * @buf_size: the size of the package buffer
793 * @last_buf: last buffer indicator
794 * @error_offset: returns error offset
795 * @error_info: returns error information
796 * @cd: pointer to command details structure or NULL
798 * Download Package (0x0C40)
800 static enum ice_status
801 ice_aq_download_pkg(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf,
802 u16 buf_size, bool last_buf, u32 *error_offset,
803 u32 *error_info, struct ice_sq_cd *cd)
805 struct ice_aqc_download_pkg *cmd;
806 struct ice_aq_desc desc;
807 enum ice_status status;
809 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
816 cmd = &desc.params.download_pkg;
817 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_download_pkg);
818 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
821 cmd->flags |= ICE_AQC_DOWNLOAD_PKG_LAST_BUF;
823 status = ice_aq_send_cmd(hw, &desc, pkg_buf, buf_size, cd);
824 if (status == ICE_ERR_AQ_ERROR) {
825 /* Read error from buffer only when the FW returned an error */
826 struct ice_aqc_download_pkg_resp *resp;
828 resp = (struct ice_aqc_download_pkg_resp *)pkg_buf;
830 *error_offset = LE32_TO_CPU(resp->error_offset);
832 *error_info = LE32_TO_CPU(resp->error_info);
839 * ice_aq_upload_section
840 * @hw: pointer to the hardware structure
841 * @pkg_buf: the package buffer which will receive the section
842 * @buf_size: the size of the package buffer
843 * @cd: pointer to command details structure or NULL
845 * Upload Section (0x0C41)
848 ice_aq_upload_section(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf,
849 u16 buf_size, struct ice_sq_cd *cd)
851 struct ice_aq_desc desc;
853 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
854 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_upload_section);
855 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
857 return ice_aq_send_cmd(hw, &desc, pkg_buf, buf_size, cd);
862 * @hw: pointer to the hardware structure
863 * @pkg_buf: the package cmd buffer
864 * @buf_size: the size of the package cmd buffer
865 * @last_buf: last buffer indicator
866 * @error_offset: returns error offset
867 * @error_info: returns error information
868 * @cd: pointer to command details structure or NULL
870 * Update Package (0x0C42)
872 static enum ice_status
873 ice_aq_update_pkg(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf, u16 buf_size,
874 bool last_buf, u32 *error_offset, u32 *error_info,
875 struct ice_sq_cd *cd)
877 struct ice_aqc_download_pkg *cmd;
878 struct ice_aq_desc desc;
879 enum ice_status status;
881 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
888 cmd = &desc.params.download_pkg;
889 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_update_pkg);
890 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
893 cmd->flags |= ICE_AQC_DOWNLOAD_PKG_LAST_BUF;
895 status = ice_aq_send_cmd(hw, &desc, pkg_buf, buf_size, cd);
896 if (status == ICE_ERR_AQ_ERROR) {
897 /* Read error from buffer only when the FW returned an error */
898 struct ice_aqc_download_pkg_resp *resp;
900 resp = (struct ice_aqc_download_pkg_resp *)pkg_buf;
902 *error_offset = LE32_TO_CPU(resp->error_offset);
904 *error_info = LE32_TO_CPU(resp->error_info);
911 * ice_find_seg_in_pkg
912 * @hw: pointer to the hardware structure
913 * @seg_type: the segment type to search for (i.e., SEGMENT_TYPE_CPK)
914 * @pkg_hdr: pointer to the package header to be searched
916 * This function searches a package file for a particular segment type. On
917 * success it returns a pointer to the segment header, otherwise it will
920 static struct ice_generic_seg_hdr *
921 ice_find_seg_in_pkg(struct ice_hw *hw, u32 seg_type,
922 struct ice_pkg_hdr *pkg_hdr)
926 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
927 ice_debug(hw, ICE_DBG_PKG, "Package format version: %d.%d.%d.%d\n",
928 pkg_hdr->pkg_format_ver.major, pkg_hdr->pkg_format_ver.minor,
929 pkg_hdr->pkg_format_ver.update,
930 pkg_hdr->pkg_format_ver.draft);
932 /* Search all package segments for the requested segment type */
933 for (i = 0; i < LE32_TO_CPU(pkg_hdr->seg_count); i++) {
934 struct ice_generic_seg_hdr *seg;
936 seg = (struct ice_generic_seg_hdr *)
937 ((u8 *)pkg_hdr + LE32_TO_CPU(pkg_hdr->seg_offset[i]));
939 if (LE32_TO_CPU(seg->seg_type) == seg_type)
948 * @hw: pointer to the hardware structure
949 * @bufs: pointer to an array of buffers
950 * @count: the number of buffers in the array
952 * Obtains change lock and updates package.
955 ice_update_pkg(struct ice_hw *hw, struct ice_buf *bufs, u32 count)
957 enum ice_status status;
960 status = ice_acquire_change_lock(hw, ICE_RES_WRITE);
964 for (i = 0; i < count; i++) {
965 struct ice_buf_hdr *bh = (struct ice_buf_hdr *)(bufs + i);
966 bool last = ((i + 1) == count);
968 status = ice_aq_update_pkg(hw, bh, LE16_TO_CPU(bh->data_end),
969 last, &offset, &info, NULL);
972 ice_debug(hw, ICE_DBG_PKG, "Update pkg failed: err %d off %d inf %d\n",
973 status, offset, info);
978 ice_release_change_lock(hw);
985 * @hw: pointer to the hardware structure
986 * @bufs: pointer to an array of buffers
987 * @count: the number of buffers in the array
989 * Obtains global config lock and downloads the package configuration buffers
990 * to the firmware. Metadata buffers are skipped, and the first metadata buffer
991 * found indicates that the rest of the buffers are all metadata buffers.
993 static enum ice_status
994 ice_dwnld_cfg_bufs(struct ice_hw *hw, struct ice_buf *bufs, u32 count)
996 enum ice_status status;
997 struct ice_buf_hdr *bh;
1000 if (!bufs || !count)
1001 return ICE_ERR_PARAM;
1003 /* If the first buffer's first section has its metadata bit set
1004 * then there are no buffers to be downloaded, and the operation is
1005 * considered a success.
1007 bh = (struct ice_buf_hdr *)bufs;
1008 if (LE32_TO_CPU(bh->section_entry[0].type) & ICE_METADATA_BUF)
1011 /* reset pkg_dwnld_status in case this function is called in the
1012 * reset/rebuild flow
1014 hw->pkg_dwnld_status = ICE_AQ_RC_OK;
1016 status = ice_acquire_global_cfg_lock(hw, ICE_RES_WRITE);
1018 if (status == ICE_ERR_AQ_NO_WORK)
1019 hw->pkg_dwnld_status = ICE_AQ_RC_EEXIST;
1021 hw->pkg_dwnld_status = hw->adminq.sq_last_status;
1025 for (i = 0; i < count; i++) {
1026 bool last = ((i + 1) == count);
1029 /* check next buffer for metadata flag */
1030 bh = (struct ice_buf_hdr *)(bufs + i + 1);
1032 /* A set metadata flag in the next buffer will signal
1033 * that the current buffer will be the last buffer
1036 if (LE16_TO_CPU(bh->section_count))
1037 if (LE32_TO_CPU(bh->section_entry[0].type) &
1042 bh = (struct ice_buf_hdr *)(bufs + i);
1044 status = ice_aq_download_pkg(hw, bh, ICE_PKG_BUF_SIZE, last,
1045 &offset, &info, NULL);
1047 /* Save AQ status from download package */
1048 hw->pkg_dwnld_status = hw->adminq.sq_last_status;
1050 ice_debug(hw, ICE_DBG_PKG, "Pkg download failed: err %d off %d inf %d\n",
1051 status, offset, info);
1061 status = ice_set_vlan_mode(hw);
1063 ice_debug(hw, ICE_DBG_PKG, "Failed to set VLAN mode: err %d\n",
1067 ice_release_global_cfg_lock(hw);
1073 * ice_aq_get_pkg_info_list
1074 * @hw: pointer to the hardware structure
1075 * @pkg_info: the buffer which will receive the information list
1076 * @buf_size: the size of the pkg_info information buffer
1077 * @cd: pointer to command details structure or NULL
1079 * Get Package Info List (0x0C43)
1081 static enum ice_status
1082 ice_aq_get_pkg_info_list(struct ice_hw *hw,
1083 struct ice_aqc_get_pkg_info_resp *pkg_info,
1084 u16 buf_size, struct ice_sq_cd *cd)
1086 struct ice_aq_desc desc;
1088 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1089 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_pkg_info_list);
1091 return ice_aq_send_cmd(hw, &desc, pkg_info, buf_size, cd);
1096 * @hw: pointer to the hardware structure
1097 * @ice_seg: pointer to the segment of the package to be downloaded
1099 * Handles the download of a complete package.
1101 static enum ice_status
1102 ice_download_pkg(struct ice_hw *hw, struct ice_seg *ice_seg)
1104 struct ice_buf_table *ice_buf_tbl;
1106 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1107 ice_debug(hw, ICE_DBG_PKG, "Segment format version: %d.%d.%d.%d\n",
1108 ice_seg->hdr.seg_format_ver.major,
1109 ice_seg->hdr.seg_format_ver.minor,
1110 ice_seg->hdr.seg_format_ver.update,
1111 ice_seg->hdr.seg_format_ver.draft);
1113 ice_debug(hw, ICE_DBG_PKG, "Seg: type 0x%X, size %d, name %s\n",
1114 LE32_TO_CPU(ice_seg->hdr.seg_type),
1115 LE32_TO_CPU(ice_seg->hdr.seg_size), ice_seg->hdr.seg_id);
1117 ice_buf_tbl = ice_find_buf_table(ice_seg);
1119 ice_debug(hw, ICE_DBG_PKG, "Seg buf count: %d\n",
1120 LE32_TO_CPU(ice_buf_tbl->buf_count));
1122 return ice_dwnld_cfg_bufs(hw, ice_buf_tbl->buf_array,
1123 LE32_TO_CPU(ice_buf_tbl->buf_count));
1128 * @hw: pointer to the hardware structure
1129 * @pkg_hdr: pointer to the driver's package hdr
1131 * Saves off the package details into the HW structure.
1133 static enum ice_status
1134 ice_init_pkg_info(struct ice_hw *hw, struct ice_pkg_hdr *pkg_hdr)
1136 struct ice_generic_seg_hdr *seg_hdr;
1138 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1140 return ICE_ERR_PARAM;
1142 seg_hdr = (struct ice_generic_seg_hdr *)
1143 ice_find_seg_in_pkg(hw, SEGMENT_TYPE_ICE, pkg_hdr);
1145 struct ice_meta_sect *meta;
1146 struct ice_pkg_enum state;
1148 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1150 /* Get package information from the Metadata Section */
1151 meta = (struct ice_meta_sect *)
1152 ice_pkg_enum_section((struct ice_seg *)seg_hdr, &state,
1155 ice_debug(hw, ICE_DBG_INIT, "Did not find ice metadata section in package\n");
1159 hw->pkg_ver = meta->ver;
1160 ice_memcpy(hw->pkg_name, meta->name, sizeof(meta->name),
1161 ICE_NONDMA_TO_NONDMA);
1163 ice_debug(hw, ICE_DBG_PKG, "Pkg: %d.%d.%d.%d, %s\n",
1164 meta->ver.major, meta->ver.minor, meta->ver.update,
1165 meta->ver.draft, meta->name);
1167 hw->ice_seg_fmt_ver = seg_hdr->seg_format_ver;
1168 ice_memcpy(hw->ice_seg_id, seg_hdr->seg_id,
1169 sizeof(hw->ice_seg_id), ICE_NONDMA_TO_NONDMA);
1171 ice_debug(hw, ICE_DBG_PKG, "Ice Seg: %d.%d.%d.%d, %s\n",
1172 seg_hdr->seg_format_ver.major,
1173 seg_hdr->seg_format_ver.minor,
1174 seg_hdr->seg_format_ver.update,
1175 seg_hdr->seg_format_ver.draft,
1178 ice_debug(hw, ICE_DBG_INIT, "Did not find ice segment in driver package\n");
1187 * @hw: pointer to the hardware structure
1189 * Store details of the package currently loaded in HW into the HW structure.
1191 static enum ice_status ice_get_pkg_info(struct ice_hw *hw)
1193 struct ice_aqc_get_pkg_info_resp *pkg_info;
1194 enum ice_status status;
1198 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1200 size = ice_struct_size(pkg_info, pkg_info, ICE_PKG_CNT);
1201 pkg_info = (struct ice_aqc_get_pkg_info_resp *)ice_malloc(hw, size);
1203 return ICE_ERR_NO_MEMORY;
1205 status = ice_aq_get_pkg_info_list(hw, pkg_info, size, NULL);
1207 goto init_pkg_free_alloc;
1209 for (i = 0; i < LE32_TO_CPU(pkg_info->count); i++) {
1210 #define ICE_PKG_FLAG_COUNT 4
1211 char flags[ICE_PKG_FLAG_COUNT + 1] = { 0 };
1214 if (pkg_info->pkg_info[i].is_active) {
1215 flags[place++] = 'A';
1216 hw->active_pkg_ver = pkg_info->pkg_info[i].ver;
1217 hw->active_track_id =
1218 LE32_TO_CPU(pkg_info->pkg_info[i].track_id);
1219 ice_memcpy(hw->active_pkg_name,
1220 pkg_info->pkg_info[i].name,
1221 sizeof(pkg_info->pkg_info[i].name),
1222 ICE_NONDMA_TO_NONDMA);
1223 hw->active_pkg_in_nvm = pkg_info->pkg_info[i].is_in_nvm;
1225 if (pkg_info->pkg_info[i].is_active_at_boot)
1226 flags[place++] = 'B';
1227 if (pkg_info->pkg_info[i].is_modified)
1228 flags[place++] = 'M';
1229 if (pkg_info->pkg_info[i].is_in_nvm)
1230 flags[place++] = 'N';
1232 ice_debug(hw, ICE_DBG_PKG, "Pkg[%d]: %d.%d.%d.%d,%s,%s\n",
1233 i, pkg_info->pkg_info[i].ver.major,
1234 pkg_info->pkg_info[i].ver.minor,
1235 pkg_info->pkg_info[i].ver.update,
1236 pkg_info->pkg_info[i].ver.draft,
1237 pkg_info->pkg_info[i].name, flags);
1240 init_pkg_free_alloc:
1241 ice_free(hw, pkg_info);
1247 * ice_find_label_value
1248 * @ice_seg: pointer to the ice segment (non-NULL)
1249 * @name: name of the label to search for
1250 * @type: the section type that will contain the label
1251 * @value: pointer to a value that will return the label's value if found
1253 * Finds a label's value given the label name and the section type to search.
1254 * The ice_seg parameter must not be NULL since the first call to
1255 * ice_enum_labels requires a pointer to an actual ice_seg structure.
1258 ice_find_label_value(struct ice_seg *ice_seg, char const *name, u32 type,
1261 struct ice_pkg_enum state;
1265 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1268 return ICE_ERR_PARAM;
1271 label_name = ice_enum_labels(ice_seg, type, &state, &val);
1272 if (label_name && !strcmp(label_name, name)) {
1278 } while (label_name);
1284 * ice_verify_pkg - verify package
1285 * @pkg: pointer to the package buffer
1286 * @len: size of the package buffer
1288 * Verifies various attributes of the package file, including length, format
1289 * version, and the requirement of at least one segment.
1291 static enum ice_status ice_verify_pkg(struct ice_pkg_hdr *pkg, u32 len)
1296 if (len < ice_struct_size(pkg, seg_offset, 1))
1297 return ICE_ERR_BUF_TOO_SHORT;
1299 if (pkg->pkg_format_ver.major != ICE_PKG_FMT_VER_MAJ ||
1300 pkg->pkg_format_ver.minor != ICE_PKG_FMT_VER_MNR ||
1301 pkg->pkg_format_ver.update != ICE_PKG_FMT_VER_UPD ||
1302 pkg->pkg_format_ver.draft != ICE_PKG_FMT_VER_DFT)
1305 /* pkg must have at least one segment */
1306 seg_count = LE32_TO_CPU(pkg->seg_count);
1310 /* make sure segment array fits in package length */
1311 if (len < ice_struct_size(pkg, seg_offset, seg_count))
1312 return ICE_ERR_BUF_TOO_SHORT;
1314 /* all segments must fit within length */
1315 for (i = 0; i < seg_count; i++) {
1316 u32 off = LE32_TO_CPU(pkg->seg_offset[i]);
1317 struct ice_generic_seg_hdr *seg;
1319 /* segment header must fit */
1320 if (len < off + sizeof(*seg))
1321 return ICE_ERR_BUF_TOO_SHORT;
1323 seg = (struct ice_generic_seg_hdr *)((u8 *)pkg + off);
1325 /* segment body must fit */
1326 if (len < off + LE32_TO_CPU(seg->seg_size))
1327 return ICE_ERR_BUF_TOO_SHORT;
1334 * ice_free_seg - free package segment pointer
1335 * @hw: pointer to the hardware structure
1337 * Frees the package segment pointer in the proper manner, depending on if the
1338 * segment was allocated or just the passed in pointer was stored.
1340 void ice_free_seg(struct ice_hw *hw)
1343 ice_free(hw, hw->pkg_copy);
1344 hw->pkg_copy = NULL;
1351 * ice_init_pkg_regs - initialize additional package registers
1352 * @hw: pointer to the hardware structure
1354 static void ice_init_pkg_regs(struct ice_hw *hw)
1356 #define ICE_SW_BLK_INP_MASK_L 0xFFFFFFFF
1357 #define ICE_SW_BLK_INP_MASK_H 0x0000FFFF
1358 #define ICE_SW_BLK_IDX 0
1360 /* setup Switch block input mask, which is 48-bits in two parts */
1361 wr32(hw, GL_PREEXT_L2_PMASK0(ICE_SW_BLK_IDX), ICE_SW_BLK_INP_MASK_L);
1362 wr32(hw, GL_PREEXT_L2_PMASK1(ICE_SW_BLK_IDX), ICE_SW_BLK_INP_MASK_H);
1366 * ice_chk_pkg_version - check package version for compatibility with driver
1367 * @pkg_ver: pointer to a version structure to check
1369 * Check to make sure that the package about to be downloaded is compatible with
1370 * the driver. To be compatible, the major and minor components of the package
1371 * version must match our ICE_PKG_SUPP_VER_MAJ and ICE_PKG_SUPP_VER_MNR
1374 static enum ice_status ice_chk_pkg_version(struct ice_pkg_ver *pkg_ver)
1376 if (pkg_ver->major != ICE_PKG_SUPP_VER_MAJ ||
1377 pkg_ver->minor != ICE_PKG_SUPP_VER_MNR)
1378 return ICE_ERR_NOT_SUPPORTED;
1384 * ice_chk_pkg_compat
1385 * @hw: pointer to the hardware structure
1386 * @ospkg: pointer to the package hdr
1387 * @seg: pointer to the package segment hdr
1389 * This function checks the package version compatibility with driver and NVM
1391 static enum ice_status
1392 ice_chk_pkg_compat(struct ice_hw *hw, struct ice_pkg_hdr *ospkg,
1393 struct ice_seg **seg)
1395 struct ice_aqc_get_pkg_info_resp *pkg;
1396 enum ice_status status;
1400 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1402 /* Check package version compatibility */
1403 status = ice_chk_pkg_version(&hw->pkg_ver);
1405 ice_debug(hw, ICE_DBG_INIT, "Package version check failed.\n");
1409 /* find ICE segment in given package */
1410 *seg = (struct ice_seg *)ice_find_seg_in_pkg(hw, SEGMENT_TYPE_ICE,
1413 ice_debug(hw, ICE_DBG_INIT, "no ice segment in package.\n");
1417 /* Check if FW is compatible with the OS package */
1418 size = ice_struct_size(pkg, pkg_info, ICE_PKG_CNT);
1419 pkg = (struct ice_aqc_get_pkg_info_resp *)ice_malloc(hw, size);
1421 return ICE_ERR_NO_MEMORY;
1423 status = ice_aq_get_pkg_info_list(hw, pkg, size, NULL);
1425 goto fw_ddp_compat_free_alloc;
1427 for (i = 0; i < LE32_TO_CPU(pkg->count); i++) {
1428 /* loop till we find the NVM package */
1429 if (!pkg->pkg_info[i].is_in_nvm)
1431 if ((*seg)->hdr.seg_format_ver.major !=
1432 pkg->pkg_info[i].ver.major ||
1433 (*seg)->hdr.seg_format_ver.minor >
1434 pkg->pkg_info[i].ver.minor) {
1435 status = ICE_ERR_FW_DDP_MISMATCH;
1436 ice_debug(hw, ICE_DBG_INIT, "OS package is not compatible with NVM.\n");
1438 /* done processing NVM package so break */
1441 fw_ddp_compat_free_alloc:
1448 * @sect_type: section type
1449 * @section: pointer to section
1450 * @index: index of the field vector entry to be returned
1451 * @offset: ptr to variable that receives the offset in the field vector table
1453 * This is a callback function that can be passed to ice_pkg_enum_entry.
1454 * This function treats the given section as of type ice_sw_fv_section and
1455 * enumerates offset field. "offset" is an index into the field vector table.
1458 ice_sw_fv_handler(u32 sect_type, void *section, u32 index, u32 *offset)
1460 struct ice_sw_fv_section *fv_section =
1461 (struct ice_sw_fv_section *)section;
1463 if (!section || sect_type != ICE_SID_FLD_VEC_SW)
1465 if (index >= LE16_TO_CPU(fv_section->count))
1468 /* "index" passed in to this function is relative to a given
1469 * 4k block. To get to the true index into the field vector
1470 * table need to add the relative index to the base_offset
1471 * field of this section
1473 *offset = LE16_TO_CPU(fv_section->base_offset) + index;
1474 return fv_section->fv + index;
1478 * ice_get_prof_index_max - get the max profile index for used profile
1479 * @hw: pointer to the HW struct
1481 * Calling this function will get the max profile index for used profile
1482 * and store the index number in struct ice_switch_info *switch_info
1483 * in hw for following use.
1485 static int ice_get_prof_index_max(struct ice_hw *hw)
1487 u16 prof_index = 0, j, max_prof_index = 0;
1488 struct ice_pkg_enum state;
1489 struct ice_seg *ice_seg;
1494 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1497 return ICE_ERR_PARAM;
1502 fv = (struct ice_fv *)
1503 ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1504 &offset, ice_sw_fv_handler);
1509 /* in the profile that not be used, the prot_id is set to 0xff
1510 * and the off is set to 0x1ff for all the field vectors.
1512 for (j = 0; j < hw->blk[ICE_BLK_SW].es.fvw; j++)
1513 if (fv->ew[j].prot_id != ICE_PROT_INVALID ||
1514 fv->ew[j].off != ICE_FV_OFFSET_INVAL)
1516 if (flag && prof_index > max_prof_index)
1517 max_prof_index = prof_index;
1523 hw->switch_info->max_used_prof_index = max_prof_index;
1529 * ice_init_pkg - initialize/download package
1530 * @hw: pointer to the hardware structure
1531 * @buf: pointer to the package buffer
1532 * @len: size of the package buffer
1534 * This function initializes a package. The package contains HW tables
1535 * required to do packet processing. First, the function extracts package
1536 * information such as version. Then it finds the ice configuration segment
1537 * within the package; this function then saves a copy of the segment pointer
1538 * within the supplied package buffer. Next, the function will cache any hints
1539 * from the package, followed by downloading the package itself. Note, that if
1540 * a previous PF driver has already downloaded the package successfully, then
1541 * the current driver will not have to download the package again.
1543 * The local package contents will be used to query default behavior and to
1544 * update specific sections of the HW's version of the package (e.g. to update
1545 * the parse graph to understand new protocols).
1547 * This function stores a pointer to the package buffer memory, and it is
1548 * expected that the supplied buffer will not be freed immediately. If the
1549 * package buffer needs to be freed, such as when read from a file, use
1550 * ice_copy_and_init_pkg() instead of directly calling ice_init_pkg() in this
1553 enum ice_status ice_init_pkg(struct ice_hw *hw, u8 *buf, u32 len)
1555 struct ice_pkg_hdr *pkg;
1556 enum ice_status status;
1557 struct ice_seg *seg;
1560 return ICE_ERR_PARAM;
1562 pkg = (struct ice_pkg_hdr *)buf;
1563 status = ice_verify_pkg(pkg, len);
1565 ice_debug(hw, ICE_DBG_INIT, "failed to verify pkg (err: %d)\n",
1570 /* initialize package info */
1571 status = ice_init_pkg_info(hw, pkg);
1575 /* before downloading the package, check package version for
1576 * compatibility with driver
1578 status = ice_chk_pkg_compat(hw, pkg, &seg);
1582 /* initialize package hints and then download package */
1583 ice_init_pkg_hints(hw, seg);
1584 status = ice_download_pkg(hw, seg);
1585 if (status == ICE_ERR_AQ_NO_WORK) {
1586 ice_debug(hw, ICE_DBG_INIT, "package previously loaded - no work.\n");
1587 status = ICE_SUCCESS;
1590 /* Get information on the package currently loaded in HW, then make sure
1591 * the driver is compatible with this version.
1594 status = ice_get_pkg_info(hw);
1596 status = ice_chk_pkg_version(&hw->active_pkg_ver);
1601 /* on successful package download update other required
1602 * registers to support the package and fill HW tables
1603 * with package content.
1605 ice_init_pkg_regs(hw);
1606 ice_fill_blk_tbls(hw);
1607 ice_get_prof_index_max(hw);
1609 ice_debug(hw, ICE_DBG_INIT, "package load failed, %d\n",
1617 * ice_copy_and_init_pkg - initialize/download a copy of the package
1618 * @hw: pointer to the hardware structure
1619 * @buf: pointer to the package buffer
1620 * @len: size of the package buffer
1622 * This function copies the package buffer, and then calls ice_init_pkg() to
1623 * initialize the copied package contents.
1625 * The copying is necessary if the package buffer supplied is constant, or if
1626 * the memory may disappear shortly after calling this function.
1628 * If the package buffer resides in the data segment and can be modified, the
1629 * caller is free to use ice_init_pkg() instead of ice_copy_and_init_pkg().
1631 * However, if the package buffer needs to be copied first, such as when being
1632 * read from a file, the caller should use ice_copy_and_init_pkg().
1634 * This function will first copy the package buffer, before calling
1635 * ice_init_pkg(). The caller is free to immediately destroy the original
1636 * package buffer, as the new copy will be managed by this function and
1639 enum ice_status ice_copy_and_init_pkg(struct ice_hw *hw, const u8 *buf, u32 len)
1641 enum ice_status status;
1645 return ICE_ERR_PARAM;
1647 buf_copy = (u8 *)ice_memdup(hw, buf, len, ICE_NONDMA_TO_NONDMA);
1649 status = ice_init_pkg(hw, buf_copy, len);
1651 /* Free the copy, since we failed to initialize the package */
1652 ice_free(hw, buf_copy);
1654 /* Track the copied pkg so we can free it later */
1655 hw->pkg_copy = buf_copy;
1664 * @hw: pointer to the HW structure
1666 * Allocates a package buffer and returns a pointer to the buffer header.
1667 * Note: all package contents must be in Little Endian form.
1669 static struct ice_buf_build *ice_pkg_buf_alloc(struct ice_hw *hw)
1671 struct ice_buf_build *bld;
1672 struct ice_buf_hdr *buf;
1674 bld = (struct ice_buf_build *)ice_malloc(hw, sizeof(*bld));
1678 buf = (struct ice_buf_hdr *)bld;
1679 buf->data_end = CPU_TO_LE16(offsetof(struct ice_buf_hdr,
1685 * ice_get_sw_prof_type - determine switch profile type
1686 * @hw: pointer to the HW structure
1687 * @fv: pointer to the switch field vector
1689 static enum ice_prof_type
1690 ice_get_sw_prof_type(struct ice_hw *hw, struct ice_fv *fv)
1694 for (i = 0; i < hw->blk[ICE_BLK_SW].es.fvw; i++) {
1695 /* UDP tunnel will have UDP_OF protocol ID and VNI offset */
1696 if (fv->ew[i].prot_id == (u8)ICE_PROT_UDP_OF &&
1697 fv->ew[i].off == ICE_VNI_OFFSET)
1698 return ICE_PROF_TUN_UDP;
1700 /* GRE tunnel will have GRE protocol */
1701 if (fv->ew[i].prot_id == (u8)ICE_PROT_GRE_OF)
1702 return ICE_PROF_TUN_GRE;
1705 return ICE_PROF_NON_TUN;
1709 * ice_get_sw_fv_bitmap - Get switch field vector bitmap based on profile type
1710 * @hw: pointer to hardware structure
1711 * @req_profs: type of profiles requested
1712 * @bm: pointer to memory for returning the bitmap of field vectors
1715 ice_get_sw_fv_bitmap(struct ice_hw *hw, enum ice_prof_type req_profs,
1718 struct ice_pkg_enum state;
1719 struct ice_seg *ice_seg;
1722 if (req_profs == ICE_PROF_ALL) {
1723 ice_bitmap_set(bm, 0, ICE_MAX_NUM_PROFILES);
1727 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1728 ice_zero_bitmap(bm, ICE_MAX_NUM_PROFILES);
1731 enum ice_prof_type prof_type;
1734 fv = (struct ice_fv *)
1735 ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1736 &offset, ice_sw_fv_handler);
1740 /* Determine field vector type */
1741 prof_type = ice_get_sw_prof_type(hw, fv);
1743 if (req_profs & prof_type)
1744 ice_set_bit((u16)offset, bm);
1750 * ice_get_sw_fv_list
1751 * @hw: pointer to the HW structure
1752 * @prot_ids: field vector to search for with a given protocol ID
1753 * @ids_cnt: lookup/protocol count
1754 * @bm: bitmap of field vectors to consider
1755 * @fv_list: Head of a list
1757 * Finds all the field vector entries from switch block that contain
1758 * a given protocol ID and returns a list of structures of type
1759 * "ice_sw_fv_list_entry". Every structure in the list has a field vector
1760 * definition and profile ID information
1761 * NOTE: The caller of the function is responsible for freeing the memory
1762 * allocated for every list entry.
1765 ice_get_sw_fv_list(struct ice_hw *hw, u8 *prot_ids, u16 ids_cnt,
1766 ice_bitmap_t *bm, struct LIST_HEAD_TYPE *fv_list)
1768 struct ice_sw_fv_list_entry *fvl;
1769 struct ice_sw_fv_list_entry *tmp;
1770 struct ice_pkg_enum state;
1771 struct ice_seg *ice_seg;
1775 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1777 if (!ids_cnt || !hw->seg)
1778 return ICE_ERR_PARAM;
1784 fv = (struct ice_fv *)
1785 ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1786 &offset, ice_sw_fv_handler);
1791 /* If field vector is not in the bitmap list, then skip this
1794 if (!ice_is_bit_set(bm, (u16)offset))
1797 for (i = 0; i < ids_cnt; i++) {
1800 /* This code assumes that if a switch field vector line
1801 * has a matching protocol, then this line will contain
1802 * the entries necessary to represent every field in
1803 * that protocol header.
1805 for (j = 0; j < hw->blk[ICE_BLK_SW].es.fvw; j++)
1806 if (fv->ew[j].prot_id == prot_ids[i])
1808 if (j >= hw->blk[ICE_BLK_SW].es.fvw)
1810 if (i + 1 == ids_cnt) {
1811 fvl = (struct ice_sw_fv_list_entry *)
1812 ice_malloc(hw, sizeof(*fvl));
1816 fvl->profile_id = offset;
1817 LIST_ADD(&fvl->list_entry, fv_list);
1822 if (LIST_EMPTY(fv_list))
1827 LIST_FOR_EACH_ENTRY_SAFE(fvl, tmp, fv_list, ice_sw_fv_list_entry,
1829 LIST_DEL(&fvl->list_entry);
1833 return ICE_ERR_NO_MEMORY;
1837 * ice_init_prof_result_bm - Initialize the profile result index bitmap
1838 * @hw: pointer to hardware structure
1840 void ice_init_prof_result_bm(struct ice_hw *hw)
1842 struct ice_pkg_enum state;
1843 struct ice_seg *ice_seg;
1846 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1856 fv = (struct ice_fv *)
1857 ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1858 &off, ice_sw_fv_handler);
1863 ice_zero_bitmap(hw->switch_info->prof_res_bm[off],
1866 /* Determine empty field vector indices, these can be
1867 * used for recipe results. Skip index 0, since it is
1868 * always used for Switch ID.
1870 for (i = 1; i < ICE_MAX_FV_WORDS; i++)
1871 if (fv->ew[i].prot_id == ICE_PROT_INVALID &&
1872 fv->ew[i].off == ICE_FV_OFFSET_INVAL)
1874 hw->switch_info->prof_res_bm[off]);
1880 * @hw: pointer to the HW structure
1881 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1883 * Frees a package buffer
1885 static void ice_pkg_buf_free(struct ice_hw *hw, struct ice_buf_build *bld)
1891 * ice_pkg_buf_reserve_section
1892 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1893 * @count: the number of sections to reserve
1895 * Reserves one or more section table entries in a package buffer. This routine
1896 * can be called multiple times as long as they are made before calling
1897 * ice_pkg_buf_alloc_section(). Once ice_pkg_buf_alloc_section()
1898 * is called once, the number of sections that can be allocated will not be able
1899 * to be increased; not using all reserved sections is fine, but this will
1900 * result in some wasted space in the buffer.
1901 * Note: all package contents must be in Little Endian form.
1903 static enum ice_status
1904 ice_pkg_buf_reserve_section(struct ice_buf_build *bld, u16 count)
1906 struct ice_buf_hdr *buf;
1911 return ICE_ERR_PARAM;
1913 buf = (struct ice_buf_hdr *)&bld->buf;
1915 /* already an active section, can't increase table size */
1916 section_count = LE16_TO_CPU(buf->section_count);
1917 if (section_count > 0)
1920 if (bld->reserved_section_table_entries + count > ICE_MAX_S_COUNT)
1922 bld->reserved_section_table_entries += count;
1924 data_end = LE16_TO_CPU(buf->data_end) +
1925 FLEX_ARRAY_SIZE(buf, section_entry, count);
1926 buf->data_end = CPU_TO_LE16(data_end);
1932 * ice_pkg_buf_alloc_section
1933 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1934 * @type: the section type value
1935 * @size: the size of the section to reserve (in bytes)
1937 * Reserves memory in the buffer for a section's content and updates the
1938 * buffers' status accordingly. This routine returns a pointer to the first
1939 * byte of the section start within the buffer, which is used to fill in the
1941 * Note: all package contents must be in Little Endian form.
1944 ice_pkg_buf_alloc_section(struct ice_buf_build *bld, u32 type, u16 size)
1946 struct ice_buf_hdr *buf;
1950 if (!bld || !type || !size)
1953 buf = (struct ice_buf_hdr *)&bld->buf;
1955 /* check for enough space left in buffer */
1956 data_end = LE16_TO_CPU(buf->data_end);
1958 /* section start must align on 4 byte boundary */
1959 data_end = ICE_ALIGN(data_end, 4);
1961 if ((data_end + size) > ICE_MAX_S_DATA_END)
1964 /* check for more available section table entries */
1965 sect_count = LE16_TO_CPU(buf->section_count);
1966 if (sect_count < bld->reserved_section_table_entries) {
1967 void *section_ptr = ((u8 *)buf) + data_end;
1969 buf->section_entry[sect_count].offset = CPU_TO_LE16(data_end);
1970 buf->section_entry[sect_count].size = CPU_TO_LE16(size);
1971 buf->section_entry[sect_count].type = CPU_TO_LE32(type);
1974 buf->data_end = CPU_TO_LE16(data_end);
1976 buf->section_count = CPU_TO_LE16(sect_count + 1);
1980 /* no free section table entries */
1985 * ice_pkg_buf_alloc_single_section
1986 * @hw: pointer to the HW structure
1987 * @type: the section type value
1988 * @size: the size of the section to reserve (in bytes)
1989 * @section: returns pointer to the section
1991 * Allocates a package buffer with a single section.
1992 * Note: all package contents must be in Little Endian form.
1994 static struct ice_buf_build *
1995 ice_pkg_buf_alloc_single_section(struct ice_hw *hw, u32 type, u16 size,
1998 struct ice_buf_build *buf;
2003 buf = ice_pkg_buf_alloc(hw);
2007 if (ice_pkg_buf_reserve_section(buf, 1))
2008 goto ice_pkg_buf_alloc_single_section_err;
2010 *section = ice_pkg_buf_alloc_section(buf, type, size);
2012 goto ice_pkg_buf_alloc_single_section_err;
2016 ice_pkg_buf_alloc_single_section_err:
2017 ice_pkg_buf_free(hw, buf);
2022 * ice_pkg_buf_unreserve_section
2023 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
2024 * @count: the number of sections to unreserve
2026 * Unreserves one or more section table entries in a package buffer, releasing
2027 * space that can be used for section data. This routine can be called
2028 * multiple times as long as they are made before calling
2029 * ice_pkg_buf_alloc_section(). Once ice_pkg_buf_alloc_section()
2030 * is called once, the number of sections that can be allocated will not be able
2031 * to be increased; not using all reserved sections is fine, but this will
2032 * result in some wasted space in the buffer.
2033 * Note: all package contents must be in Little Endian form.
2036 ice_pkg_buf_unreserve_section(struct ice_buf_build *bld, u16 count)
2038 struct ice_buf_hdr *buf;
2043 return ICE_ERR_PARAM;
2045 buf = (struct ice_buf_hdr *)&bld->buf;
2047 /* already an active section, can't decrease table size */
2048 section_count = LE16_TO_CPU(buf->section_count);
2049 if (section_count > 0)
2052 if (count > bld->reserved_section_table_entries)
2054 bld->reserved_section_table_entries -= count;
2056 data_end = LE16_TO_CPU(buf->data_end) -
2057 FLEX_ARRAY_SIZE(buf, section_entry, count);
2058 buf->data_end = CPU_TO_LE16(data_end);
2064 * ice_pkg_buf_get_free_space
2065 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
2067 * Returns the number of free bytes remaining in the buffer.
2068 * Note: all package contents must be in Little Endian form.
2070 u16 ice_pkg_buf_get_free_space(struct ice_buf_build *bld)
2072 struct ice_buf_hdr *buf;
2077 buf = (struct ice_buf_hdr *)&bld->buf;
2078 return ICE_MAX_S_DATA_END - LE16_TO_CPU(buf->data_end);
2082 * ice_pkg_buf_get_active_sections
2083 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
2085 * Returns the number of active sections. Before using the package buffer
2086 * in an update package command, the caller should make sure that there is at
2087 * least one active section - otherwise, the buffer is not legal and should
2089 * Note: all package contents must be in Little Endian form.
2091 static u16 ice_pkg_buf_get_active_sections(struct ice_buf_build *bld)
2093 struct ice_buf_hdr *buf;
2098 buf = (struct ice_buf_hdr *)&bld->buf;
2099 return LE16_TO_CPU(buf->section_count);
2104 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
2106 * Return a pointer to the buffer's header
2108 static struct ice_buf *ice_pkg_buf(struct ice_buf_build *bld)
2117 * ice_tunnel_port_in_use_hlpr - helper function to determine tunnel usage
2118 * @hw: pointer to the HW structure
2119 * @port: port to search for
2120 * @index: optionally returns index
2122 * Returns whether a port is already in use as a tunnel, and optionally its
2125 static bool ice_tunnel_port_in_use_hlpr(struct ice_hw *hw, u16 port, u16 *index)
2129 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
2130 if (hw->tnl.tbl[i].in_use && hw->tnl.tbl[i].port == port) {
2140 * ice_tunnel_port_in_use
2141 * @hw: pointer to the HW structure
2142 * @port: port to search for
2143 * @index: optionally returns index
2145 * Returns whether a port is already in use as a tunnel, and optionally its
2148 bool ice_tunnel_port_in_use(struct ice_hw *hw, u16 port, u16 *index)
2152 ice_acquire_lock(&hw->tnl_lock);
2153 res = ice_tunnel_port_in_use_hlpr(hw, port, index);
2154 ice_release_lock(&hw->tnl_lock);
2160 * ice_tunnel_get_type
2161 * @hw: pointer to the HW structure
2162 * @port: port to search for
2163 * @type: returns tunnel index
2165 * For a given port number, will return the type of tunnel.
2168 ice_tunnel_get_type(struct ice_hw *hw, u16 port, 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].in_use && hw->tnl.tbl[i].port == port) {
2177 *type = hw->tnl.tbl[i].type;
2182 ice_release_lock(&hw->tnl_lock);
2188 * ice_find_free_tunnel_entry
2189 * @hw: pointer to the HW structure
2190 * @type: tunnel type
2191 * @index: optionally returns index
2193 * Returns whether there is a free tunnel entry, and optionally its index
2196 ice_find_free_tunnel_entry(struct ice_hw *hw, enum ice_tunnel_type type,
2201 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
2202 if (hw->tnl.tbl[i].valid && !hw->tnl.tbl[i].in_use &&
2203 hw->tnl.tbl[i].type == type) {
2213 * ice_get_open_tunnel_port - retrieve an open tunnel port
2214 * @hw: pointer to the HW structure
2215 * @type: tunnel type (TNL_ALL will return any open port)
2216 * @port: returns open port
2219 ice_get_open_tunnel_port(struct ice_hw *hw, enum ice_tunnel_type type,
2225 ice_acquire_lock(&hw->tnl_lock);
2227 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
2228 if (hw->tnl.tbl[i].valid && hw->tnl.tbl[i].in_use &&
2229 (type == TNL_ALL || hw->tnl.tbl[i].type == type)) {
2230 *port = hw->tnl.tbl[i].port;
2235 ice_release_lock(&hw->tnl_lock);
2242 * @hw: pointer to the HW structure
2243 * @type: type of tunnel
2244 * @port: port of tunnel to create
2246 * Create a tunnel by updating the parse graph in the parser. We do that by
2247 * creating a package buffer with the tunnel info and issuing an update package
2251 ice_create_tunnel(struct ice_hw *hw, enum ice_tunnel_type type, u16 port)
2253 struct ice_boost_tcam_section *sect_rx, *sect_tx;
2254 enum ice_status status = ICE_ERR_MAX_LIMIT;
2255 struct ice_buf_build *bld;
2258 ice_acquire_lock(&hw->tnl_lock);
2260 if (ice_tunnel_port_in_use_hlpr(hw, port, &index)) {
2261 hw->tnl.tbl[index].ref++;
2262 status = ICE_SUCCESS;
2263 goto ice_create_tunnel_end;
2266 if (!ice_find_free_tunnel_entry(hw, type, &index)) {
2267 status = ICE_ERR_OUT_OF_RANGE;
2268 goto ice_create_tunnel_end;
2271 bld = ice_pkg_buf_alloc(hw);
2273 status = ICE_ERR_NO_MEMORY;
2274 goto ice_create_tunnel_end;
2277 /* allocate 2 sections, one for Rx parser, one for Tx parser */
2278 if (ice_pkg_buf_reserve_section(bld, 2))
2279 goto ice_create_tunnel_err;
2281 sect_rx = (struct ice_boost_tcam_section *)
2282 ice_pkg_buf_alloc_section(bld, ICE_SID_RXPARSER_BOOST_TCAM,
2283 ice_struct_size(sect_rx, tcam, 1));
2285 goto ice_create_tunnel_err;
2286 sect_rx->count = CPU_TO_LE16(1);
2288 sect_tx = (struct ice_boost_tcam_section *)
2289 ice_pkg_buf_alloc_section(bld, ICE_SID_TXPARSER_BOOST_TCAM,
2290 ice_struct_size(sect_tx, tcam, 1));
2292 goto ice_create_tunnel_err;
2293 sect_tx->count = CPU_TO_LE16(1);
2295 /* copy original boost entry to update package buffer */
2296 ice_memcpy(sect_rx->tcam, hw->tnl.tbl[index].boost_entry,
2297 sizeof(*sect_rx->tcam), ICE_NONDMA_TO_NONDMA);
2299 /* over-write the never-match dest port key bits with the encoded port
2302 ice_set_key((u8 *)§_rx->tcam[0].key, sizeof(sect_rx->tcam[0].key),
2303 (u8 *)&port, NULL, NULL, NULL,
2304 (u16)offsetof(struct ice_boost_key_value, hv_dst_port_key),
2305 sizeof(sect_rx->tcam[0].key.key.hv_dst_port_key));
2307 /* exact copy of entry to Tx section entry */
2308 ice_memcpy(sect_tx->tcam, sect_rx->tcam, sizeof(*sect_tx->tcam),
2309 ICE_NONDMA_TO_NONDMA);
2311 status = ice_update_pkg(hw, ice_pkg_buf(bld), 1);
2313 hw->tnl.tbl[index].port = port;
2314 hw->tnl.tbl[index].in_use = true;
2315 hw->tnl.tbl[index].ref = 1;
2318 ice_create_tunnel_err:
2319 ice_pkg_buf_free(hw, bld);
2321 ice_create_tunnel_end:
2322 ice_release_lock(&hw->tnl_lock);
2328 * ice_destroy_tunnel
2329 * @hw: pointer to the HW structure
2330 * @port: port of tunnel to destroy (ignored if the all parameter is true)
2331 * @all: flag that states to destroy all tunnels
2333 * Destroys a tunnel or all tunnels by creating an update package buffer
2334 * targeting the specific updates requested and then performing an update
2337 enum ice_status ice_destroy_tunnel(struct ice_hw *hw, u16 port, bool all)
2339 struct ice_boost_tcam_section *sect_rx, *sect_tx;
2340 enum ice_status status = ICE_ERR_MAX_LIMIT;
2341 struct ice_buf_build *bld;
2347 ice_acquire_lock(&hw->tnl_lock);
2349 if (!all && ice_tunnel_port_in_use_hlpr(hw, port, &index))
2350 if (hw->tnl.tbl[index].ref > 1) {
2351 hw->tnl.tbl[index].ref--;
2352 status = ICE_SUCCESS;
2353 goto ice_destroy_tunnel_end;
2356 /* determine count */
2357 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
2358 if (hw->tnl.tbl[i].valid && hw->tnl.tbl[i].in_use &&
2359 (all || hw->tnl.tbl[i].port == port))
2363 status = ICE_ERR_PARAM;
2364 goto ice_destroy_tunnel_end;
2367 /* size of section - there is at least one entry */
2368 size = ice_struct_size(sect_rx, tcam, count);
2370 bld = ice_pkg_buf_alloc(hw);
2372 status = ICE_ERR_NO_MEMORY;
2373 goto ice_destroy_tunnel_end;
2376 /* allocate 2 sections, one for Rx parser, one for Tx parser */
2377 if (ice_pkg_buf_reserve_section(bld, 2))
2378 goto ice_destroy_tunnel_err;
2380 sect_rx = (struct ice_boost_tcam_section *)
2381 ice_pkg_buf_alloc_section(bld, ICE_SID_RXPARSER_BOOST_TCAM,
2384 goto ice_destroy_tunnel_err;
2385 sect_rx->count = CPU_TO_LE16(1);
2387 sect_tx = (struct ice_boost_tcam_section *)
2388 ice_pkg_buf_alloc_section(bld, ICE_SID_TXPARSER_BOOST_TCAM,
2391 goto ice_destroy_tunnel_err;
2392 sect_tx->count = CPU_TO_LE16(1);
2394 /* copy original boost entry to update package buffer, one copy to Rx
2395 * section, another copy to the Tx section
2397 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
2398 if (hw->tnl.tbl[i].valid && hw->tnl.tbl[i].in_use &&
2399 (all || hw->tnl.tbl[i].port == port)) {
2400 ice_memcpy(sect_rx->tcam + i,
2401 hw->tnl.tbl[i].boost_entry,
2402 sizeof(*sect_rx->tcam),
2403 ICE_NONDMA_TO_NONDMA);
2404 ice_memcpy(sect_tx->tcam + i,
2405 hw->tnl.tbl[i].boost_entry,
2406 sizeof(*sect_tx->tcam),
2407 ICE_NONDMA_TO_NONDMA);
2408 hw->tnl.tbl[i].marked = true;
2411 status = ice_update_pkg(hw, ice_pkg_buf(bld), 1);
2413 for (i = 0; i < hw->tnl.count &&
2414 i < ICE_TUNNEL_MAX_ENTRIES; i++)
2415 if (hw->tnl.tbl[i].marked) {
2416 hw->tnl.tbl[i].ref = 0;
2417 hw->tnl.tbl[i].port = 0;
2418 hw->tnl.tbl[i].in_use = false;
2419 hw->tnl.tbl[i].marked = false;
2422 ice_destroy_tunnel_err:
2423 ice_pkg_buf_free(hw, bld);
2425 ice_destroy_tunnel_end:
2426 ice_release_lock(&hw->tnl_lock);
2432 * ice_replay_tunnels
2433 * @hw: pointer to the HW structure
2435 * Replays all tunnels
2437 enum ice_status ice_replay_tunnels(struct ice_hw *hw)
2439 enum ice_status status = ICE_SUCCESS;
2442 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
2444 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++) {
2445 enum ice_tunnel_type type = hw->tnl.tbl[i].type;
2446 u16 refs = hw->tnl.tbl[i].ref;
2447 u16 port = hw->tnl.tbl[i].port;
2449 if (!hw->tnl.tbl[i].in_use)
2452 /* Replay tunnels one at a time by destroying them, then
2455 hw->tnl.tbl[i].ref = 1; /* make sure to destroy in one call */
2456 status = ice_destroy_tunnel(hw, port, false);
2458 ice_debug(hw, ICE_DBG_PKG, "ERR: 0x%x - destroy tunnel port 0x%x\n",
2463 status = ice_create_tunnel(hw, type, port);
2465 ice_debug(hw, ICE_DBG_PKG, "ERR: 0x%x - create tunnel port 0x%x\n",
2470 /* reset to original ref count */
2471 hw->tnl.tbl[i].ref = refs;
2478 * ice_find_prot_off - find prot ID and offset pair, based on prof and FV index
2479 * @hw: pointer to the hardware structure
2480 * @blk: hardware block
2482 * @fv_idx: field vector word index
2483 * @prot: variable to receive the protocol ID
2484 * @off: variable to receive the protocol offset
2487 ice_find_prot_off(struct ice_hw *hw, enum ice_block blk, u8 prof, u16 fv_idx,
2490 struct ice_fv_word *fv_ext;
2492 if (prof >= hw->blk[blk].es.count)
2493 return ICE_ERR_PARAM;
2495 if (fv_idx >= hw->blk[blk].es.fvw)
2496 return ICE_ERR_PARAM;
2498 fv_ext = hw->blk[blk].es.t + (prof * hw->blk[blk].es.fvw);
2500 *prot = fv_ext[fv_idx].prot_id;
2501 *off = fv_ext[fv_idx].off;
2506 /* PTG Management */
2509 * ice_ptg_update_xlt1 - Updates packet type groups in HW via XLT1 table
2510 * @hw: pointer to the hardware structure
2513 * This function will update the XLT1 hardware table to reflect the new
2514 * packet type group configuration.
2516 enum ice_status ice_ptg_update_xlt1(struct ice_hw *hw, enum ice_block blk)
2518 struct ice_xlt1_section *sect;
2519 struct ice_buf_build *bld;
2520 enum ice_status status;
2523 bld = ice_pkg_buf_alloc_single_section(hw, ice_sect_id(blk, ICE_XLT1),
2524 ice_struct_size(sect, value,
2528 return ICE_ERR_NO_MEMORY;
2530 sect->count = CPU_TO_LE16(ICE_XLT1_CNT);
2531 sect->offset = CPU_TO_LE16(0);
2532 for (index = 0; index < ICE_XLT1_CNT; index++)
2533 sect->value[index] = hw->blk[blk].xlt1.ptypes[index].ptg;
2535 status = ice_update_pkg(hw, ice_pkg_buf(bld), 1);
2537 ice_pkg_buf_free(hw, bld);
2543 * ice_ptg_find_ptype - Search for packet type group using packet type (ptype)
2544 * @hw: pointer to the hardware structure
2546 * @ptype: the ptype to search for
2547 * @ptg: pointer to variable that receives the PTG
2549 * This function will search the PTGs for a particular ptype, returning the
2550 * PTG ID that contains it through the PTG parameter, with the value of
2551 * ICE_DEFAULT_PTG (0) meaning it is part the default PTG.
2553 static enum ice_status
2554 ice_ptg_find_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 *ptg)
2556 if (ptype >= ICE_XLT1_CNT || !ptg)
2557 return ICE_ERR_PARAM;
2559 *ptg = hw->blk[blk].xlt1.ptypes[ptype].ptg;
2564 * ice_ptg_alloc_val - Allocates a new packet type group ID by value
2565 * @hw: pointer to the hardware structure
2567 * @ptg: the PTG to allocate
2569 * This function allocates a given packet type group ID specified by the PTG
2572 static void ice_ptg_alloc_val(struct ice_hw *hw, enum ice_block blk, u8 ptg)
2574 hw->blk[blk].xlt1.ptg_tbl[ptg].in_use = true;
2578 * ice_ptg_free - Frees a packet type group
2579 * @hw: pointer to the hardware structure
2581 * @ptg: the PTG ID to free
2583 * This function frees a packet type group, and returns all the current ptypes
2584 * within it to the default PTG.
2586 void ice_ptg_free(struct ice_hw *hw, enum ice_block blk, u8 ptg)
2588 struct ice_ptg_ptype *p, *temp;
2590 hw->blk[blk].xlt1.ptg_tbl[ptg].in_use = false;
2591 p = hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2593 p->ptg = ICE_DEFAULT_PTG;
2594 temp = p->next_ptype;
2595 p->next_ptype = NULL;
2599 hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype = NULL;
2603 * ice_ptg_remove_ptype - Removes ptype from a particular packet type group
2604 * @hw: pointer to the hardware structure
2606 * @ptype: the ptype to remove
2607 * @ptg: the PTG to remove the ptype from
2609 * This function will remove the ptype from the specific PTG, and move it to
2610 * the default PTG (ICE_DEFAULT_PTG).
2612 static enum ice_status
2613 ice_ptg_remove_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 ptg)
2615 struct ice_ptg_ptype **ch;
2616 struct ice_ptg_ptype *p;
2618 if (ptype > ICE_XLT1_CNT - 1)
2619 return ICE_ERR_PARAM;
2621 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].in_use)
2622 return ICE_ERR_DOES_NOT_EXIST;
2624 /* Should not happen if .in_use is set, bad config */
2625 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype)
2628 /* find the ptype within this PTG, and bypass the link over it */
2629 p = hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2630 ch = &hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2632 if (ptype == (p - hw->blk[blk].xlt1.ptypes)) {
2633 *ch = p->next_ptype;
2637 ch = &p->next_ptype;
2641 hw->blk[blk].xlt1.ptypes[ptype].ptg = ICE_DEFAULT_PTG;
2642 hw->blk[blk].xlt1.ptypes[ptype].next_ptype = NULL;
2648 * ice_ptg_add_mv_ptype - Adds/moves ptype to a particular packet type group
2649 * @hw: pointer to the hardware structure
2651 * @ptype: the ptype to add or move
2652 * @ptg: the PTG to add or move the ptype to
2654 * This function will either add or move a ptype to a particular PTG depending
2655 * on if the ptype is already part of another group. Note that using a
2656 * a destination PTG ID of ICE_DEFAULT_PTG (0) will move the ptype to the
2659 static enum ice_status
2660 ice_ptg_add_mv_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 ptg)
2662 enum ice_status status;
2665 if (ptype > ICE_XLT1_CNT - 1)
2666 return ICE_ERR_PARAM;
2668 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].in_use && ptg != ICE_DEFAULT_PTG)
2669 return ICE_ERR_DOES_NOT_EXIST;
2671 status = ice_ptg_find_ptype(hw, blk, ptype, &original_ptg);
2675 /* Is ptype already in the correct PTG? */
2676 if (original_ptg == ptg)
2679 /* Remove from original PTG and move back to the default PTG */
2680 if (original_ptg != ICE_DEFAULT_PTG)
2681 ice_ptg_remove_ptype(hw, blk, ptype, original_ptg);
2683 /* Moving to default PTG? Then we're done with this request */
2684 if (ptg == ICE_DEFAULT_PTG)
2687 /* Add ptype to PTG at beginning of list */
2688 hw->blk[blk].xlt1.ptypes[ptype].next_ptype =
2689 hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2690 hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype =
2691 &hw->blk[blk].xlt1.ptypes[ptype];
2693 hw->blk[blk].xlt1.ptypes[ptype].ptg = ptg;
2694 hw->blk[blk].xlt1.t[ptype] = ptg;
2699 /* Block / table size info */
2700 struct ice_blk_size_details {
2701 u16 xlt1; /* # XLT1 entries */
2702 u16 xlt2; /* # XLT2 entries */
2703 u16 prof_tcam; /* # profile ID TCAM entries */
2704 u16 prof_id; /* # profile IDs */
2705 u8 prof_cdid_bits; /* # CDID one-hot bits used in key */
2706 u16 prof_redir; /* # profile redirection entries */
2707 u16 es; /* # extraction sequence entries */
2708 u16 fvw; /* # field vector words */
2709 u8 overwrite; /* overwrite existing entries allowed */
2710 u8 reverse; /* reverse FV order */
2713 static const struct ice_blk_size_details blk_sizes[ICE_BLK_COUNT] = {
2716 * XLT1 - Number of entries in XLT1 table
2717 * XLT2 - Number of entries in XLT2 table
2718 * TCAM - Number of entries Profile ID TCAM table
2719 * CDID - Control Domain ID of the hardware block
2720 * PRED - Number of entries in the Profile Redirection Table
2721 * FV - Number of entries in the Field Vector
2722 * FVW - Width (in WORDs) of the Field Vector
2723 * OVR - Overwrite existing table entries
2726 /* XLT1 , XLT2 ,TCAM, PID,CDID,PRED, FV, FVW */
2727 /* Overwrite , Reverse FV */
2728 /* SW */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 256, 0, 256, 256, 48,
2730 /* ACL */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 32,
2732 /* FD */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 24,
2734 /* RSS */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 24,
2736 /* PE */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 64, 32, 0, 32, 32, 24,
2741 ICE_SID_XLT1_OFF = 0,
2744 ICE_SID_PR_REDIR_OFF,
2749 /* Characteristic handling */
2752 * ice_match_prop_lst - determine if properties of two lists match
2753 * @list1: first properties list
2754 * @list2: second properties list
2756 * Count, cookies and the order must match in order to be considered equivalent.
2759 ice_match_prop_lst(struct LIST_HEAD_TYPE *list1, struct LIST_HEAD_TYPE *list2)
2761 struct ice_vsig_prof *tmp1;
2762 struct ice_vsig_prof *tmp2;
2766 /* compare counts */
2767 LIST_FOR_EACH_ENTRY(tmp1, list1, ice_vsig_prof, list)
2769 LIST_FOR_EACH_ENTRY(tmp2, list2, ice_vsig_prof, list)
2771 if (!count || count != chk_count)
2774 tmp1 = LIST_FIRST_ENTRY(list1, struct ice_vsig_prof, list);
2775 tmp2 = LIST_FIRST_ENTRY(list2, struct ice_vsig_prof, list);
2777 /* profile cookies must compare, and in the exact same order to take
2778 * into account priority
2781 if (tmp2->profile_cookie != tmp1->profile_cookie)
2784 tmp1 = LIST_NEXT_ENTRY(tmp1, struct ice_vsig_prof, list);
2785 tmp2 = LIST_NEXT_ENTRY(tmp2, struct ice_vsig_prof, list);
2791 /* VSIG Management */
2794 * ice_vsig_update_xlt2_sect - update one section of XLT2 table
2795 * @hw: pointer to the hardware structure
2797 * @vsi: HW VSI number to program
2798 * @vsig: VSIG for the VSI
2800 * This function will update the XLT2 hardware table with the input VSI
2801 * group configuration.
2803 static enum ice_status
2804 ice_vsig_update_xlt2_sect(struct ice_hw *hw, enum ice_block blk, u16 vsi,
2807 struct ice_xlt2_section *sect;
2808 struct ice_buf_build *bld;
2809 enum ice_status status;
2811 bld = ice_pkg_buf_alloc_single_section(hw, ice_sect_id(blk, ICE_XLT2),
2812 ice_struct_size(sect, value, 1),
2815 return ICE_ERR_NO_MEMORY;
2817 sect->count = CPU_TO_LE16(1);
2818 sect->offset = CPU_TO_LE16(vsi);
2819 sect->value[0] = CPU_TO_LE16(vsig);
2821 status = ice_update_pkg(hw, ice_pkg_buf(bld), 1);
2823 ice_pkg_buf_free(hw, bld);
2829 * ice_vsig_update_xlt2 - update XLT2 table with VSIG configuration
2830 * @hw: pointer to the hardware structure
2833 * This function will update the XLT2 hardware table with the input VSI
2834 * group configuration of used vsis.
2836 enum ice_status ice_vsig_update_xlt2(struct ice_hw *hw, enum ice_block blk)
2840 for (vsi = 0; vsi < ICE_MAX_VSI; vsi++) {
2841 /* update only vsis that have been changed */
2842 if (hw->blk[blk].xlt2.vsis[vsi].changed) {
2843 enum ice_status status;
2846 vsig = hw->blk[blk].xlt2.vsis[vsi].vsig;
2847 status = ice_vsig_update_xlt2_sect(hw, blk, vsi, vsig);
2851 hw->blk[blk].xlt2.vsis[vsi].changed = 0;
2859 * ice_vsig_find_vsi - find a VSIG that contains a specified VSI
2860 * @hw: pointer to the hardware structure
2862 * @vsi: VSI of interest
2863 * @vsig: pointer to receive the VSI group
2865 * This function will lookup the VSI entry in the XLT2 list and return
2866 * the VSI group its associated with.
2869 ice_vsig_find_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 *vsig)
2871 if (!vsig || vsi >= ICE_MAX_VSI)
2872 return ICE_ERR_PARAM;
2874 /* As long as there's a default or valid VSIG associated with the input
2875 * VSI, the functions returns a success. Any handling of VSIG will be
2876 * done by the following add, update or remove functions.
2878 *vsig = hw->blk[blk].xlt2.vsis[vsi].vsig;
2884 * ice_vsig_alloc_val - allocate a new VSIG by value
2885 * @hw: pointer to the hardware structure
2887 * @vsig: the VSIG to allocate
2889 * This function will allocate a given VSIG specified by the VSIG parameter.
2891 static u16 ice_vsig_alloc_val(struct ice_hw *hw, enum ice_block blk, u16 vsig)
2893 u16 idx = vsig & ICE_VSIG_IDX_M;
2895 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use) {
2896 INIT_LIST_HEAD(&hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst);
2897 hw->blk[blk].xlt2.vsig_tbl[idx].in_use = true;
2900 return ICE_VSIG_VALUE(idx, hw->pf_id);
2904 * ice_vsig_alloc - Finds a free entry and allocates a new VSIG
2905 * @hw: pointer to the hardware structure
2908 * This function will iterate through the VSIG list and mark the first
2909 * unused entry for the new VSIG entry as used and return that value.
2911 static u16 ice_vsig_alloc(struct ice_hw *hw, enum ice_block blk)
2915 for (i = 1; i < ICE_MAX_VSIGS; i++)
2916 if (!hw->blk[blk].xlt2.vsig_tbl[i].in_use)
2917 return ice_vsig_alloc_val(hw, blk, i);
2919 return ICE_DEFAULT_VSIG;
2923 * ice_find_dup_props_vsig - find VSI group with a specified set of properties
2924 * @hw: pointer to the hardware structure
2926 * @chs: characteristic list
2927 * @vsig: returns the VSIG with the matching profiles, if found
2929 * Each VSIG is associated with a characteristic set; i.e. all VSIs under
2930 * a group have the same characteristic set. To check if there exists a VSIG
2931 * which has the same characteristics as the input characteristics; this
2932 * function will iterate through the XLT2 list and return the VSIG that has a
2933 * matching configuration. In order to make sure that priorities are accounted
2934 * for, the list must match exactly, including the order in which the
2935 * characteristics are listed.
2937 static enum ice_status
2938 ice_find_dup_props_vsig(struct ice_hw *hw, enum ice_block blk,
2939 struct LIST_HEAD_TYPE *chs, u16 *vsig)
2941 struct ice_xlt2 *xlt2 = &hw->blk[blk].xlt2;
2944 for (i = 0; i < xlt2->count; i++)
2945 if (xlt2->vsig_tbl[i].in_use &&
2946 ice_match_prop_lst(chs, &xlt2->vsig_tbl[i].prop_lst)) {
2947 *vsig = ICE_VSIG_VALUE(i, hw->pf_id);
2951 return ICE_ERR_DOES_NOT_EXIST;
2955 * ice_vsig_free - free VSI group
2956 * @hw: pointer to the hardware structure
2958 * @vsig: VSIG to remove
2960 * The function will remove all VSIs associated with the input VSIG and move
2961 * them to the DEFAULT_VSIG and mark the VSIG available.
2963 static enum ice_status
2964 ice_vsig_free(struct ice_hw *hw, enum ice_block blk, u16 vsig)
2966 struct ice_vsig_prof *dtmp, *del;
2967 struct ice_vsig_vsi *vsi_cur;
2970 idx = vsig & ICE_VSIG_IDX_M;
2971 if (idx >= ICE_MAX_VSIGS)
2972 return ICE_ERR_PARAM;
2974 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
2975 return ICE_ERR_DOES_NOT_EXIST;
2977 hw->blk[blk].xlt2.vsig_tbl[idx].in_use = false;
2979 vsi_cur = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2980 /* If the VSIG has at least 1 VSI then iterate through the
2981 * list and remove the VSIs before deleting the group.
2984 /* remove all vsis associated with this VSIG XLT2 entry */
2986 struct ice_vsig_vsi *tmp = vsi_cur->next_vsi;
2988 vsi_cur->vsig = ICE_DEFAULT_VSIG;
2989 vsi_cur->changed = 1;
2990 vsi_cur->next_vsi = NULL;
2994 /* NULL terminate head of VSI list */
2995 hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi = NULL;
2998 /* free characteristic list */
2999 LIST_FOR_EACH_ENTRY_SAFE(del, dtmp,
3000 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
3001 ice_vsig_prof, list) {
3002 LIST_DEL(&del->list);
3006 /* if VSIG characteristic list was cleared for reset
3007 * re-initialize the list head
3009 INIT_LIST_HEAD(&hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst);
3015 * ice_vsig_remove_vsi - remove VSI from VSIG
3016 * @hw: pointer to the hardware structure
3018 * @vsi: VSI to remove
3019 * @vsig: VSI group to remove from
3021 * The function will remove the input VSI from its VSI group and move it
3022 * to the DEFAULT_VSIG.
3024 static enum ice_status
3025 ice_vsig_remove_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
3027 struct ice_vsig_vsi **vsi_head, *vsi_cur, *vsi_tgt;
3030 idx = vsig & ICE_VSIG_IDX_M;
3032 if (vsi >= ICE_MAX_VSI || idx >= ICE_MAX_VSIGS)
3033 return ICE_ERR_PARAM;
3035 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
3036 return ICE_ERR_DOES_NOT_EXIST;
3038 /* entry already in default VSIG, don't have to remove */
3039 if (idx == ICE_DEFAULT_VSIG)
3042 vsi_head = &hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
3046 vsi_tgt = &hw->blk[blk].xlt2.vsis[vsi];
3047 vsi_cur = (*vsi_head);
3049 /* iterate the VSI list, skip over the entry to be removed */
3051 if (vsi_tgt == vsi_cur) {
3052 (*vsi_head) = vsi_cur->next_vsi;
3055 vsi_head = &vsi_cur->next_vsi;
3056 vsi_cur = vsi_cur->next_vsi;
3059 /* verify if VSI was removed from group list */
3061 return ICE_ERR_DOES_NOT_EXIST;
3063 vsi_cur->vsig = ICE_DEFAULT_VSIG;
3064 vsi_cur->changed = 1;
3065 vsi_cur->next_vsi = NULL;
3071 * ice_vsig_add_mv_vsi - add or move a VSI to a VSI group
3072 * @hw: pointer to the hardware structure
3075 * @vsig: destination VSI group
3077 * This function will move or add the input VSI to the target VSIG.
3078 * The function will find the original VSIG the VSI belongs to and
3079 * move the entry to the DEFAULT_VSIG, update the original VSIG and
3080 * then move entry to the new VSIG.
3082 static enum ice_status
3083 ice_vsig_add_mv_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
3085 struct ice_vsig_vsi *tmp;
3086 enum ice_status status;
3089 idx = vsig & ICE_VSIG_IDX_M;
3091 if (vsi >= ICE_MAX_VSI || idx >= ICE_MAX_VSIGS)
3092 return ICE_ERR_PARAM;
3094 /* if VSIG not in use and VSIG is not default type this VSIG
3097 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use &&
3098 vsig != ICE_DEFAULT_VSIG)
3099 return ICE_ERR_DOES_NOT_EXIST;
3101 status = ice_vsig_find_vsi(hw, blk, vsi, &orig_vsig);
3105 /* no update required if vsigs match */
3106 if (orig_vsig == vsig)
3109 if (orig_vsig != ICE_DEFAULT_VSIG) {
3110 /* remove entry from orig_vsig and add to default VSIG */
3111 status = ice_vsig_remove_vsi(hw, blk, vsi, orig_vsig);
3116 if (idx == ICE_DEFAULT_VSIG)
3119 /* Create VSI entry and add VSIG and prop_mask values */
3120 hw->blk[blk].xlt2.vsis[vsi].vsig = vsig;
3121 hw->blk[blk].xlt2.vsis[vsi].changed = 1;
3123 /* Add new entry to the head of the VSIG list */
3124 tmp = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
3125 hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi =
3126 &hw->blk[blk].xlt2.vsis[vsi];
3127 hw->blk[blk].xlt2.vsis[vsi].next_vsi = tmp;
3128 hw->blk[blk].xlt2.t[vsi] = vsig;
3134 * ice_find_prof_id - find profile ID for a given field vector
3135 * @hw: pointer to the hardware structure
3137 * @fv: field vector to search for
3138 * @prof_id: receives the profile ID
3140 static enum ice_status
3141 ice_find_prof_id(struct ice_hw *hw, enum ice_block blk,
3142 struct ice_fv_word *fv, u8 *prof_id)
3144 struct ice_es *es = &hw->blk[blk].es;
3148 for (i = 0; i < (u8)es->count; i++) {
3151 if (memcmp(&es->t[off], fv, es->fvw * sizeof(*fv)))
3158 return ICE_ERR_DOES_NOT_EXIST;
3162 * ice_prof_id_rsrc_type - get profile ID resource type for a block type
3163 * @blk: the block type
3164 * @rsrc_type: pointer to variable to receive the resource type
3166 static bool ice_prof_id_rsrc_type(enum ice_block blk, u16 *rsrc_type)
3170 *rsrc_type = ICE_AQC_RES_TYPE_HASH_PROF_BLDR_PROFID;
3173 *rsrc_type = ICE_AQC_RES_TYPE_QHASH_PROF_BLDR_PROFID;
3182 * ice_tcam_ent_rsrc_type - get TCAM entry resource type for a block type
3183 * @blk: the block type
3184 * @rsrc_type: pointer to variable to receive the resource type
3186 static bool ice_tcam_ent_rsrc_type(enum ice_block blk, u16 *rsrc_type)
3190 *rsrc_type = ICE_AQC_RES_TYPE_HASH_PROF_BLDR_TCAM;
3193 *rsrc_type = ICE_AQC_RES_TYPE_QHASH_PROF_BLDR_TCAM;
3202 * ice_alloc_tcam_ent - allocate hardware TCAM entry
3203 * @hw: pointer to the HW struct
3204 * @blk: the block to allocate the TCAM for
3205 * @btm: true to allocate from bottom of table, false to allocate from top
3206 * @tcam_idx: pointer to variable to receive the TCAM entry
3208 * This function allocates a new entry in a Profile ID TCAM for a specific
3211 static enum ice_status
3212 ice_alloc_tcam_ent(struct ice_hw *hw, enum ice_block blk, bool btm,
3217 if (!ice_tcam_ent_rsrc_type(blk, &res_type))
3218 return ICE_ERR_PARAM;
3220 return ice_alloc_hw_res(hw, res_type, 1, btm, tcam_idx);
3224 * ice_free_tcam_ent - free hardware TCAM entry
3225 * @hw: pointer to the HW struct
3226 * @blk: the block from which to free the TCAM entry
3227 * @tcam_idx: the TCAM entry to free
3229 * This function frees an entry in a Profile ID TCAM for a specific block.
3231 static enum ice_status
3232 ice_free_tcam_ent(struct ice_hw *hw, enum ice_block blk, u16 tcam_idx)
3236 if (!ice_tcam_ent_rsrc_type(blk, &res_type))
3237 return ICE_ERR_PARAM;
3239 return ice_free_hw_res(hw, res_type, 1, &tcam_idx);
3243 * ice_alloc_prof_id - allocate profile ID
3244 * @hw: pointer to the HW struct
3245 * @blk: the block to allocate the profile ID for
3246 * @prof_id: pointer to variable to receive the profile ID
3248 * This function allocates a new profile ID, which also corresponds to a Field
3249 * Vector (Extraction Sequence) entry.
3251 static enum ice_status
3252 ice_alloc_prof_id(struct ice_hw *hw, enum ice_block blk, u8 *prof_id)
3254 enum ice_status status;
3258 if (!ice_prof_id_rsrc_type(blk, &res_type))
3259 return ICE_ERR_PARAM;
3261 status = ice_alloc_hw_res(hw, res_type, 1, false, &get_prof);
3263 *prof_id = (u8)get_prof;
3269 * ice_free_prof_id - free profile ID
3270 * @hw: pointer to the HW struct
3271 * @blk: the block from which to free the profile ID
3272 * @prof_id: the profile ID to free
3274 * This function frees a profile ID, which also corresponds to a Field Vector.
3276 static enum ice_status
3277 ice_free_prof_id(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
3279 u16 tmp_prof_id = (u16)prof_id;
3282 if (!ice_prof_id_rsrc_type(blk, &res_type))
3283 return ICE_ERR_PARAM;
3285 return ice_free_hw_res(hw, res_type, 1, &tmp_prof_id);
3289 * ice_prof_inc_ref - increment reference count for profile
3290 * @hw: pointer to the HW struct
3291 * @blk: the block from which to free the profile ID
3292 * @prof_id: the profile ID for which to increment the reference count
3294 static enum ice_status
3295 ice_prof_inc_ref(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
3297 if (prof_id > hw->blk[blk].es.count)
3298 return ICE_ERR_PARAM;
3300 hw->blk[blk].es.ref_count[prof_id]++;
3306 * ice_write_es - write an extraction sequence to hardware
3307 * @hw: pointer to the HW struct
3308 * @blk: the block in which to write the extraction sequence
3309 * @prof_id: the profile ID to write
3310 * @fv: pointer to the extraction sequence to write - NULL to clear extraction
3313 ice_write_es(struct ice_hw *hw, enum ice_block blk, u8 prof_id,
3314 struct ice_fv_word *fv)
3318 off = prof_id * hw->blk[blk].es.fvw;
3320 ice_memset(&hw->blk[blk].es.t[off], 0, hw->blk[blk].es.fvw *
3321 sizeof(*fv), ICE_NONDMA_MEM);
3322 hw->blk[blk].es.written[prof_id] = false;
3324 ice_memcpy(&hw->blk[blk].es.t[off], fv, hw->blk[blk].es.fvw *
3325 sizeof(*fv), ICE_NONDMA_TO_NONDMA);
3330 * ice_prof_dec_ref - decrement reference count for profile
3331 * @hw: pointer to the HW struct
3332 * @blk: the block from which to free the profile ID
3333 * @prof_id: the profile ID for which to decrement the reference count
3335 static enum ice_status
3336 ice_prof_dec_ref(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
3338 if (prof_id > hw->blk[blk].es.count)
3339 return ICE_ERR_PARAM;
3341 if (hw->blk[blk].es.ref_count[prof_id] > 0) {
3342 if (!--hw->blk[blk].es.ref_count[prof_id]) {
3343 ice_write_es(hw, blk, prof_id, NULL);
3344 return ice_free_prof_id(hw, blk, prof_id);
3351 /* Block / table section IDs */
3352 static const u32 ice_blk_sids[ICE_BLK_COUNT][ICE_SID_OFF_COUNT] = {
3356 ICE_SID_PROFID_TCAM_SW,
3357 ICE_SID_PROFID_REDIR_SW,
3364 ICE_SID_PROFID_TCAM_ACL,
3365 ICE_SID_PROFID_REDIR_ACL,
3372 ICE_SID_PROFID_TCAM_FD,
3373 ICE_SID_PROFID_REDIR_FD,
3380 ICE_SID_PROFID_TCAM_RSS,
3381 ICE_SID_PROFID_REDIR_RSS,
3388 ICE_SID_PROFID_TCAM_PE,
3389 ICE_SID_PROFID_REDIR_PE,
3395 * ice_init_sw_xlt1_db - init software XLT1 database from HW tables
3396 * @hw: pointer to the hardware structure
3397 * @blk: the HW block to initialize
3399 static void ice_init_sw_xlt1_db(struct ice_hw *hw, enum ice_block blk)
3403 for (pt = 0; pt < hw->blk[blk].xlt1.count; pt++) {
3406 ptg = hw->blk[blk].xlt1.t[pt];
3407 if (ptg != ICE_DEFAULT_PTG) {
3408 ice_ptg_alloc_val(hw, blk, ptg);
3409 ice_ptg_add_mv_ptype(hw, blk, pt, ptg);
3415 * ice_init_sw_xlt2_db - init software XLT2 database from HW tables
3416 * @hw: pointer to the hardware structure
3417 * @blk: the HW block to initialize
3419 static void ice_init_sw_xlt2_db(struct ice_hw *hw, enum ice_block blk)
3423 for (vsi = 0; vsi < hw->blk[blk].xlt2.count; vsi++) {
3426 vsig = hw->blk[blk].xlt2.t[vsi];
3428 ice_vsig_alloc_val(hw, blk, vsig);
3429 ice_vsig_add_mv_vsi(hw, blk, vsi, vsig);
3430 /* no changes at this time, since this has been
3431 * initialized from the original package
3433 hw->blk[blk].xlt2.vsis[vsi].changed = 0;
3439 * ice_init_sw_db - init software database from HW tables
3440 * @hw: pointer to the hardware structure
3442 static void ice_init_sw_db(struct ice_hw *hw)
3446 for (i = 0; i < ICE_BLK_COUNT; i++) {
3447 ice_init_sw_xlt1_db(hw, (enum ice_block)i);
3448 ice_init_sw_xlt2_db(hw, (enum ice_block)i);
3453 * ice_fill_tbl - Reads content of a single table type into database
3454 * @hw: pointer to the hardware structure
3455 * @block_id: Block ID of the table to copy
3456 * @sid: Section ID of the table to copy
3458 * Will attempt to read the entire content of a given table of a single block
3459 * into the driver database. We assume that the buffer will always
3460 * be as large or larger than the data contained in the package. If
3461 * this condition is not met, there is most likely an error in the package
3464 static void ice_fill_tbl(struct ice_hw *hw, enum ice_block block_id, u32 sid)
3466 u32 dst_len, sect_len, offset = 0;
3467 struct ice_prof_redir_section *pr;
3468 struct ice_prof_id_section *pid;
3469 struct ice_xlt1_section *xlt1;
3470 struct ice_xlt2_section *xlt2;
3471 struct ice_sw_fv_section *es;
3472 struct ice_pkg_enum state;
3476 /* if the HW segment pointer is null then the first iteration of
3477 * ice_pkg_enum_section() will fail. In this case the HW tables will
3478 * not be filled and return success.
3481 ice_debug(hw, ICE_DBG_PKG, "hw->seg is NULL, tables are not filled\n");
3485 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
3487 sect = ice_pkg_enum_section(hw->seg, &state, sid);
3491 case ICE_SID_XLT1_SW:
3492 case ICE_SID_XLT1_FD:
3493 case ICE_SID_XLT1_RSS:
3494 case ICE_SID_XLT1_ACL:
3495 case ICE_SID_XLT1_PE:
3496 xlt1 = (struct ice_xlt1_section *)sect;
3498 sect_len = LE16_TO_CPU(xlt1->count) *
3499 sizeof(*hw->blk[block_id].xlt1.t);
3500 dst = hw->blk[block_id].xlt1.t;
3501 dst_len = hw->blk[block_id].xlt1.count *
3502 sizeof(*hw->blk[block_id].xlt1.t);
3504 case ICE_SID_XLT2_SW:
3505 case ICE_SID_XLT2_FD:
3506 case ICE_SID_XLT2_RSS:
3507 case ICE_SID_XLT2_ACL:
3508 case ICE_SID_XLT2_PE:
3509 xlt2 = (struct ice_xlt2_section *)sect;
3510 src = (_FORCE_ u8 *)xlt2->value;
3511 sect_len = LE16_TO_CPU(xlt2->count) *
3512 sizeof(*hw->blk[block_id].xlt2.t);
3513 dst = (u8 *)hw->blk[block_id].xlt2.t;
3514 dst_len = hw->blk[block_id].xlt2.count *
3515 sizeof(*hw->blk[block_id].xlt2.t);
3517 case ICE_SID_PROFID_TCAM_SW:
3518 case ICE_SID_PROFID_TCAM_FD:
3519 case ICE_SID_PROFID_TCAM_RSS:
3520 case ICE_SID_PROFID_TCAM_ACL:
3521 case ICE_SID_PROFID_TCAM_PE:
3522 pid = (struct ice_prof_id_section *)sect;
3523 src = (u8 *)pid->entry;
3524 sect_len = LE16_TO_CPU(pid->count) *
3525 sizeof(*hw->blk[block_id].prof.t);
3526 dst = (u8 *)hw->blk[block_id].prof.t;
3527 dst_len = hw->blk[block_id].prof.count *
3528 sizeof(*hw->blk[block_id].prof.t);
3530 case ICE_SID_PROFID_REDIR_SW:
3531 case ICE_SID_PROFID_REDIR_FD:
3532 case ICE_SID_PROFID_REDIR_RSS:
3533 case ICE_SID_PROFID_REDIR_ACL:
3534 case ICE_SID_PROFID_REDIR_PE:
3535 pr = (struct ice_prof_redir_section *)sect;
3536 src = pr->redir_value;
3537 sect_len = LE16_TO_CPU(pr->count) *
3538 sizeof(*hw->blk[block_id].prof_redir.t);
3539 dst = hw->blk[block_id].prof_redir.t;
3540 dst_len = hw->blk[block_id].prof_redir.count *
3541 sizeof(*hw->blk[block_id].prof_redir.t);
3543 case ICE_SID_FLD_VEC_SW:
3544 case ICE_SID_FLD_VEC_FD:
3545 case ICE_SID_FLD_VEC_RSS:
3546 case ICE_SID_FLD_VEC_ACL:
3547 case ICE_SID_FLD_VEC_PE:
3548 es = (struct ice_sw_fv_section *)sect;
3550 sect_len = (u32)(LE16_TO_CPU(es->count) *
3551 hw->blk[block_id].es.fvw) *
3552 sizeof(*hw->blk[block_id].es.t);
3553 dst = (u8 *)hw->blk[block_id].es.t;
3554 dst_len = (u32)(hw->blk[block_id].es.count *
3555 hw->blk[block_id].es.fvw) *
3556 sizeof(*hw->blk[block_id].es.t);
3562 /* if the section offset exceeds destination length, terminate
3565 if (offset > dst_len)
3568 /* if the sum of section size and offset exceed destination size
3569 * then we are out of bounds of the HW table size for that PF.
3570 * Changing section length to fill the remaining table space
3573 if ((offset + sect_len) > dst_len)
3574 sect_len = dst_len - offset;
3576 ice_memcpy(dst + offset, src, sect_len, ICE_NONDMA_TO_NONDMA);
3578 sect = ice_pkg_enum_section(NULL, &state, sid);
3583 * ice_fill_blk_tbls - Read package context for tables
3584 * @hw: pointer to the hardware structure
3586 * Reads the current package contents and populates the driver
3587 * database with the data iteratively for all advanced feature
3588 * blocks. Assume that the HW tables have been allocated.
3590 void ice_fill_blk_tbls(struct ice_hw *hw)
3594 for (i = 0; i < ICE_BLK_COUNT; i++) {
3595 enum ice_block blk_id = (enum ice_block)i;
3597 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].xlt1.sid);
3598 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].xlt2.sid);
3599 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].prof.sid);
3600 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].prof_redir.sid);
3601 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].es.sid);
3608 * ice_free_prof_map - free profile map
3609 * @hw: pointer to the hardware structure
3610 * @blk_idx: HW block index
3612 static void ice_free_prof_map(struct ice_hw *hw, u8 blk_idx)
3614 struct ice_es *es = &hw->blk[blk_idx].es;
3615 struct ice_prof_map *del, *tmp;
3617 ice_acquire_lock(&es->prof_map_lock);
3618 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &es->prof_map,
3619 ice_prof_map, list) {
3620 LIST_DEL(&del->list);
3623 INIT_LIST_HEAD(&es->prof_map);
3624 ice_release_lock(&es->prof_map_lock);
3628 * ice_free_flow_profs - free flow profile entries
3629 * @hw: pointer to the hardware structure
3630 * @blk_idx: HW block index
3632 static void ice_free_flow_profs(struct ice_hw *hw, u8 blk_idx)
3634 struct ice_flow_prof *p, *tmp;
3636 ice_acquire_lock(&hw->fl_profs_locks[blk_idx]);
3637 LIST_FOR_EACH_ENTRY_SAFE(p, tmp, &hw->fl_profs[blk_idx],
3638 ice_flow_prof, l_entry) {
3639 LIST_DEL(&p->l_entry);
3643 ice_release_lock(&hw->fl_profs_locks[blk_idx]);
3645 /* if driver is in reset and tables are being cleared
3646 * re-initialize the flow profile list heads
3648 INIT_LIST_HEAD(&hw->fl_profs[blk_idx]);
3652 * ice_free_vsig_tbl - free complete VSIG table entries
3653 * @hw: pointer to the hardware structure
3654 * @blk: the HW block on which to free the VSIG table entries
3656 static void ice_free_vsig_tbl(struct ice_hw *hw, enum ice_block blk)
3660 if (!hw->blk[blk].xlt2.vsig_tbl)
3663 for (i = 1; i < ICE_MAX_VSIGS; i++)
3664 if (hw->blk[blk].xlt2.vsig_tbl[i].in_use)
3665 ice_vsig_free(hw, blk, i);
3669 * ice_free_hw_tbls - free hardware table memory
3670 * @hw: pointer to the hardware structure
3672 void ice_free_hw_tbls(struct ice_hw *hw)
3674 struct ice_rss_cfg *r, *rt;
3677 for (i = 0; i < ICE_BLK_COUNT; i++) {
3678 if (hw->blk[i].is_list_init) {
3679 struct ice_es *es = &hw->blk[i].es;
3681 ice_free_prof_map(hw, i);
3682 ice_destroy_lock(&es->prof_map_lock);
3684 ice_free_flow_profs(hw, i);
3685 ice_destroy_lock(&hw->fl_profs_locks[i]);
3687 hw->blk[i].is_list_init = false;
3689 ice_free_vsig_tbl(hw, (enum ice_block)i);
3690 ice_free(hw, hw->blk[i].xlt1.ptypes);
3691 ice_free(hw, hw->blk[i].xlt1.ptg_tbl);
3692 ice_free(hw, hw->blk[i].xlt1.t);
3693 ice_free(hw, hw->blk[i].xlt2.t);
3694 ice_free(hw, hw->blk[i].xlt2.vsig_tbl);
3695 ice_free(hw, hw->blk[i].xlt2.vsis);
3696 ice_free(hw, hw->blk[i].prof.t);
3697 ice_free(hw, hw->blk[i].prof_redir.t);
3698 ice_free(hw, hw->blk[i].es.t);
3699 ice_free(hw, hw->blk[i].es.ref_count);
3700 ice_free(hw, hw->blk[i].es.written);
3703 LIST_FOR_EACH_ENTRY_SAFE(r, rt, &hw->rss_list_head,
3704 ice_rss_cfg, l_entry) {
3705 LIST_DEL(&r->l_entry);
3708 ice_destroy_lock(&hw->rss_locks);
3709 ice_memset(hw->blk, 0, sizeof(hw->blk), ICE_NONDMA_MEM);
3713 * ice_init_flow_profs - init flow profile locks and list heads
3714 * @hw: pointer to the hardware structure
3715 * @blk_idx: HW block index
3717 static void ice_init_flow_profs(struct ice_hw *hw, u8 blk_idx)
3719 ice_init_lock(&hw->fl_profs_locks[blk_idx]);
3720 INIT_LIST_HEAD(&hw->fl_profs[blk_idx]);
3724 * ice_clear_hw_tbls - clear HW tables and flow profiles
3725 * @hw: pointer to the hardware structure
3727 void ice_clear_hw_tbls(struct ice_hw *hw)
3731 for (i = 0; i < ICE_BLK_COUNT; i++) {
3732 struct ice_prof_redir *prof_redir = &hw->blk[i].prof_redir;
3733 struct ice_prof_tcam *prof = &hw->blk[i].prof;
3734 struct ice_xlt1 *xlt1 = &hw->blk[i].xlt1;
3735 struct ice_xlt2 *xlt2 = &hw->blk[i].xlt2;
3736 struct ice_es *es = &hw->blk[i].es;
3738 if (hw->blk[i].is_list_init) {
3739 ice_free_prof_map(hw, i);
3740 ice_free_flow_profs(hw, i);
3743 ice_free_vsig_tbl(hw, (enum ice_block)i);
3745 ice_memset(xlt1->ptypes, 0, xlt1->count * sizeof(*xlt1->ptypes),
3747 ice_memset(xlt1->ptg_tbl, 0,
3748 ICE_MAX_PTGS * sizeof(*xlt1->ptg_tbl),
3750 ice_memset(xlt1->t, 0, xlt1->count * sizeof(*xlt1->t),
3753 ice_memset(xlt2->vsis, 0, xlt2->count * sizeof(*xlt2->vsis),
3755 ice_memset(xlt2->vsig_tbl, 0,
3756 xlt2->count * sizeof(*xlt2->vsig_tbl),
3758 ice_memset(xlt2->t, 0, xlt2->count * sizeof(*xlt2->t),
3761 ice_memset(prof->t, 0, prof->count * sizeof(*prof->t),
3763 ice_memset(prof_redir->t, 0,
3764 prof_redir->count * sizeof(*prof_redir->t),
3767 ice_memset(es->t, 0, es->count * sizeof(*es->t) * es->fvw,
3769 ice_memset(es->ref_count, 0, es->count * sizeof(*es->ref_count),
3771 ice_memset(es->written, 0, es->count * sizeof(*es->written),
3777 * ice_init_hw_tbls - init hardware table memory
3778 * @hw: pointer to the hardware structure
3780 enum ice_status ice_init_hw_tbls(struct ice_hw *hw)
3784 ice_init_lock(&hw->rss_locks);
3785 INIT_LIST_HEAD(&hw->rss_list_head);
3786 for (i = 0; i < ICE_BLK_COUNT; i++) {
3787 struct ice_prof_redir *prof_redir = &hw->blk[i].prof_redir;
3788 struct ice_prof_tcam *prof = &hw->blk[i].prof;
3789 struct ice_xlt1 *xlt1 = &hw->blk[i].xlt1;
3790 struct ice_xlt2 *xlt2 = &hw->blk[i].xlt2;
3791 struct ice_es *es = &hw->blk[i].es;
3794 if (hw->blk[i].is_list_init)
3797 ice_init_flow_profs(hw, i);
3798 ice_init_lock(&es->prof_map_lock);
3799 INIT_LIST_HEAD(&es->prof_map);
3800 hw->blk[i].is_list_init = true;
3802 hw->blk[i].overwrite = blk_sizes[i].overwrite;
3803 es->reverse = blk_sizes[i].reverse;
3805 xlt1->sid = ice_blk_sids[i][ICE_SID_XLT1_OFF];
3806 xlt1->count = blk_sizes[i].xlt1;
3808 xlt1->ptypes = (struct ice_ptg_ptype *)
3809 ice_calloc(hw, xlt1->count, sizeof(*xlt1->ptypes));
3814 xlt1->ptg_tbl = (struct ice_ptg_entry *)
3815 ice_calloc(hw, ICE_MAX_PTGS, sizeof(*xlt1->ptg_tbl));
3820 xlt1->t = (u8 *)ice_calloc(hw, xlt1->count, sizeof(*xlt1->t));
3824 xlt2->sid = ice_blk_sids[i][ICE_SID_XLT2_OFF];
3825 xlt2->count = blk_sizes[i].xlt2;
3827 xlt2->vsis = (struct ice_vsig_vsi *)
3828 ice_calloc(hw, xlt2->count, sizeof(*xlt2->vsis));
3833 xlt2->vsig_tbl = (struct ice_vsig_entry *)
3834 ice_calloc(hw, xlt2->count, sizeof(*xlt2->vsig_tbl));
3835 if (!xlt2->vsig_tbl)
3838 for (j = 0; j < xlt2->count; j++)
3839 INIT_LIST_HEAD(&xlt2->vsig_tbl[j].prop_lst);
3841 xlt2->t = (u16 *)ice_calloc(hw, xlt2->count, sizeof(*xlt2->t));
3845 prof->sid = ice_blk_sids[i][ICE_SID_PR_OFF];
3846 prof->count = blk_sizes[i].prof_tcam;
3847 prof->max_prof_id = blk_sizes[i].prof_id;
3848 prof->cdid_bits = blk_sizes[i].prof_cdid_bits;
3849 prof->t = (struct ice_prof_tcam_entry *)
3850 ice_calloc(hw, prof->count, sizeof(*prof->t));
3855 prof_redir->sid = ice_blk_sids[i][ICE_SID_PR_REDIR_OFF];
3856 prof_redir->count = blk_sizes[i].prof_redir;
3857 prof_redir->t = (u8 *)ice_calloc(hw, prof_redir->count,
3858 sizeof(*prof_redir->t));
3863 es->sid = ice_blk_sids[i][ICE_SID_ES_OFF];
3864 es->count = blk_sizes[i].es;
3865 es->fvw = blk_sizes[i].fvw;
3866 es->t = (struct ice_fv_word *)
3867 ice_calloc(hw, (u32)(es->count * es->fvw),
3872 es->ref_count = (u16 *)
3873 ice_calloc(hw, es->count, sizeof(*es->ref_count));
3878 es->written = (u8 *)
3879 ice_calloc(hw, es->count, sizeof(*es->written));
3888 ice_free_hw_tbls(hw);
3889 return ICE_ERR_NO_MEMORY;
3893 * ice_prof_gen_key - generate profile ID key
3894 * @hw: pointer to the HW struct
3895 * @blk: the block in which to write profile ID to
3896 * @ptg: packet type group (PTG) portion of key
3897 * @vsig: VSIG portion of key
3898 * @cdid: CDID portion of key
3899 * @flags: flag portion of key
3900 * @vl_msk: valid mask
3901 * @dc_msk: don't care mask
3902 * @nm_msk: never match mask
3903 * @key: output of profile ID key
3905 static enum ice_status
3906 ice_prof_gen_key(struct ice_hw *hw, enum ice_block blk, u8 ptg, u16 vsig,
3907 u8 cdid, u16 flags, u8 vl_msk[ICE_TCAM_KEY_VAL_SZ],
3908 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ], u8 nm_msk[ICE_TCAM_KEY_VAL_SZ],
3909 u8 key[ICE_TCAM_KEY_SZ])
3911 struct ice_prof_id_key inkey;
3914 inkey.xlt2_cdid = CPU_TO_LE16(vsig);
3915 inkey.flags = CPU_TO_LE16(flags);
3917 switch (hw->blk[blk].prof.cdid_bits) {
3921 #define ICE_CD_2_M 0xC000U
3922 #define ICE_CD_2_S 14
3923 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_2_M);
3924 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_2_S);
3927 #define ICE_CD_4_M 0xF000U
3928 #define ICE_CD_4_S 12
3929 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_4_M);
3930 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_4_S);
3933 #define ICE_CD_8_M 0xFF00U
3934 #define ICE_CD_8_S 16
3935 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_8_M);
3936 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_8_S);
3939 ice_debug(hw, ICE_DBG_PKG, "Error in profile config\n");
3943 return ice_set_key(key, ICE_TCAM_KEY_SZ, (u8 *)&inkey, vl_msk, dc_msk,
3944 nm_msk, 0, ICE_TCAM_KEY_SZ / 2);
3948 * ice_tcam_write_entry - write TCAM entry
3949 * @hw: pointer to the HW struct
3950 * @blk: the block in which to write profile ID to
3951 * @idx: the entry index to write to
3952 * @prof_id: profile ID
3953 * @ptg: packet type group (PTG) portion of key
3954 * @vsig: VSIG portion of key
3955 * @cdid: CDID portion of key
3956 * @flags: flag portion of key
3957 * @vl_msk: valid mask
3958 * @dc_msk: don't care mask
3959 * @nm_msk: never match mask
3961 static enum ice_status
3962 ice_tcam_write_entry(struct ice_hw *hw, enum ice_block blk, u16 idx,
3963 u8 prof_id, u8 ptg, u16 vsig, u8 cdid, u16 flags,
3964 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ],
3965 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ],
3966 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ])
3968 struct ice_prof_tcam_entry;
3969 enum ice_status status;
3971 status = ice_prof_gen_key(hw, blk, ptg, vsig, cdid, flags, vl_msk,
3972 dc_msk, nm_msk, hw->blk[blk].prof.t[idx].key);
3974 hw->blk[blk].prof.t[idx].addr = CPU_TO_LE16(idx);
3975 hw->blk[blk].prof.t[idx].prof_id = prof_id;
3982 * ice_vsig_get_ref - returns number of VSIs belong to a VSIG
3983 * @hw: pointer to the hardware structure
3985 * @vsig: VSIG to query
3986 * @refs: pointer to variable to receive the reference count
3988 static enum ice_status
3989 ice_vsig_get_ref(struct ice_hw *hw, enum ice_block blk, u16 vsig, u16 *refs)
3991 u16 idx = vsig & ICE_VSIG_IDX_M;
3992 struct ice_vsig_vsi *ptr;
3996 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
3997 return ICE_ERR_DOES_NOT_EXIST;
3999 ptr = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
4002 ptr = ptr->next_vsi;
4009 * ice_has_prof_vsig - check to see if VSIG has a specific profile
4010 * @hw: pointer to the hardware structure
4012 * @vsig: VSIG to check against
4013 * @hdl: profile handle
4016 ice_has_prof_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl)
4018 u16 idx = vsig & ICE_VSIG_IDX_M;
4019 struct ice_vsig_prof *ent;
4021 LIST_FOR_EACH_ENTRY(ent, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4022 ice_vsig_prof, list)
4023 if (ent->profile_cookie == hdl)
4026 ice_debug(hw, ICE_DBG_INIT, "Characteristic list for VSI group %d not found.\n",
4032 * ice_prof_bld_es - build profile ID extraction sequence changes
4033 * @hw: pointer to the HW struct
4034 * @blk: hardware block
4035 * @bld: the update package buffer build to add to
4036 * @chgs: the list of changes to make in hardware
4038 static enum ice_status
4039 ice_prof_bld_es(struct ice_hw *hw, enum ice_block blk,
4040 struct ice_buf_build *bld, struct LIST_HEAD_TYPE *chgs)
4042 u16 vec_size = hw->blk[blk].es.fvw * sizeof(struct ice_fv_word);
4043 struct ice_chs_chg *tmp;
4045 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry)
4046 if (tmp->type == ICE_PTG_ES_ADD && tmp->add_prof) {
4047 u16 off = tmp->prof_id * hw->blk[blk].es.fvw;
4048 struct ice_pkg_es *p;
4051 id = ice_sect_id(blk, ICE_VEC_TBL);
4052 p = (struct ice_pkg_es *)
4053 ice_pkg_buf_alloc_section(bld, id,
4054 ice_struct_size(p, es,
4060 return ICE_ERR_MAX_LIMIT;
4062 p->count = CPU_TO_LE16(1);
4063 p->offset = CPU_TO_LE16(tmp->prof_id);
4065 ice_memcpy(p->es, &hw->blk[blk].es.t[off], vec_size,
4066 ICE_NONDMA_TO_NONDMA);
4073 * ice_prof_bld_tcam - build profile ID TCAM changes
4074 * @hw: pointer to the HW struct
4075 * @blk: hardware block
4076 * @bld: the update package buffer build to add to
4077 * @chgs: the list of changes to make in hardware
4079 static enum ice_status
4080 ice_prof_bld_tcam(struct ice_hw *hw, enum ice_block blk,
4081 struct ice_buf_build *bld, struct LIST_HEAD_TYPE *chgs)
4083 struct ice_chs_chg *tmp;
4085 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry)
4086 if (tmp->type == ICE_TCAM_ADD && tmp->add_tcam_idx) {
4087 struct ice_prof_id_section *p;
4090 id = ice_sect_id(blk, ICE_PROF_TCAM);
4091 p = (struct ice_prof_id_section *)
4092 ice_pkg_buf_alloc_section(bld, id,
4098 return ICE_ERR_MAX_LIMIT;
4100 p->count = CPU_TO_LE16(1);
4101 p->entry[0].addr = CPU_TO_LE16(tmp->tcam_idx);
4102 p->entry[0].prof_id = tmp->prof_id;
4104 ice_memcpy(p->entry[0].key,
4105 &hw->blk[blk].prof.t[tmp->tcam_idx].key,
4106 sizeof(hw->blk[blk].prof.t->key),
4107 ICE_NONDMA_TO_NONDMA);
4114 * ice_prof_bld_xlt1 - build XLT1 changes
4115 * @blk: hardware block
4116 * @bld: the update package buffer build to add to
4117 * @chgs: the list of changes to make in hardware
4119 static enum ice_status
4120 ice_prof_bld_xlt1(enum ice_block blk, struct ice_buf_build *bld,
4121 struct LIST_HEAD_TYPE *chgs)
4123 struct ice_chs_chg *tmp;
4125 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry)
4126 if (tmp->type == ICE_PTG_ES_ADD && tmp->add_ptg) {
4127 struct ice_xlt1_section *p;
4130 id = ice_sect_id(blk, ICE_XLT1);
4131 p = (struct ice_xlt1_section *)
4132 ice_pkg_buf_alloc_section(bld, id,
4138 return ICE_ERR_MAX_LIMIT;
4140 p->count = CPU_TO_LE16(1);
4141 p->offset = CPU_TO_LE16(tmp->ptype);
4142 p->value[0] = tmp->ptg;
4149 * ice_prof_bld_xlt2 - build XLT2 changes
4150 * @blk: hardware block
4151 * @bld: the update package buffer build to add to
4152 * @chgs: the list of changes to make in hardware
4154 static enum ice_status
4155 ice_prof_bld_xlt2(enum ice_block blk, struct ice_buf_build *bld,
4156 struct LIST_HEAD_TYPE *chgs)
4158 struct ice_chs_chg *tmp;
4160 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
4161 struct ice_xlt2_section *p;
4164 switch (tmp->type) {
4168 id = ice_sect_id(blk, ICE_XLT2);
4169 p = (struct ice_xlt2_section *)
4170 ice_pkg_buf_alloc_section(bld, id,
4176 return ICE_ERR_MAX_LIMIT;
4178 p->count = CPU_TO_LE16(1);
4179 p->offset = CPU_TO_LE16(tmp->vsi);
4180 p->value[0] = CPU_TO_LE16(tmp->vsig);
4191 * ice_upd_prof_hw - update hardware using the change list
4192 * @hw: pointer to the HW struct
4193 * @blk: hardware block
4194 * @chgs: the list of changes to make in hardware
4196 static enum ice_status
4197 ice_upd_prof_hw(struct ice_hw *hw, enum ice_block blk,
4198 struct LIST_HEAD_TYPE *chgs)
4200 struct ice_buf_build *b;
4201 struct ice_chs_chg *tmp;
4202 enum ice_status status;
4210 /* count number of sections we need */
4211 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
4212 switch (tmp->type) {
4213 case ICE_PTG_ES_ADD:
4231 sects = xlt1 + xlt2 + tcam + es;
4236 /* Build update package buffer */
4237 b = ice_pkg_buf_alloc(hw);
4239 return ICE_ERR_NO_MEMORY;
4241 status = ice_pkg_buf_reserve_section(b, sects);
4245 /* Preserve order of table update: ES, TCAM, PTG, VSIG */
4247 status = ice_prof_bld_es(hw, blk, b, chgs);
4253 status = ice_prof_bld_tcam(hw, blk, b, chgs);
4259 status = ice_prof_bld_xlt1(blk, b, chgs);
4265 status = ice_prof_bld_xlt2(blk, b, chgs);
4270 /* After package buffer build check if the section count in buffer is
4271 * non-zero and matches the number of sections detected for package
4274 pkg_sects = ice_pkg_buf_get_active_sections(b);
4275 if (!pkg_sects || pkg_sects != sects) {
4276 status = ICE_ERR_INVAL_SIZE;
4280 /* update package */
4281 status = ice_update_pkg(hw, ice_pkg_buf(b), 1);
4282 if (status == ICE_ERR_AQ_ERROR)
4283 ice_debug(hw, ICE_DBG_INIT, "Unable to update HW profile\n");
4286 ice_pkg_buf_free(hw, b);
4291 * ice_add_prof - add profile
4292 * @hw: pointer to the HW struct
4293 * @blk: hardware block
4294 * @id: profile tracking ID
4295 * @ptypes: array of bitmaps indicating ptypes (ICE_FLOW_PTYPE_MAX bits)
4296 * @es: extraction sequence (length of array is determined by the block)
4298 * This function registers a profile, which matches a set of PTGs with a
4299 * particular extraction sequence. While the hardware profile is allocated
4300 * it will not be written until the first call to ice_add_flow that specifies
4301 * the ID value used here.
4304 ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64 id, u8 ptypes[],
4305 struct ice_fv_word *es)
4307 u32 bytes = DIVIDE_AND_ROUND_UP(ICE_FLOW_PTYPE_MAX, BITS_PER_BYTE);
4308 ice_declare_bitmap(ptgs_used, ICE_XLT1_CNT);
4309 struct ice_prof_map *prof;
4310 enum ice_status status;
4314 ice_zero_bitmap(ptgs_used, ICE_XLT1_CNT);
4316 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
4318 /* search for existing profile */
4319 status = ice_find_prof_id(hw, blk, es, &prof_id);
4321 /* allocate profile ID */
4322 status = ice_alloc_prof_id(hw, blk, &prof_id);
4324 goto err_ice_add_prof;
4326 /* and write new es */
4327 ice_write_es(hw, blk, prof_id, es);
4330 ice_prof_inc_ref(hw, blk, prof_id);
4332 /* add profile info */
4334 prof = (struct ice_prof_map *)ice_malloc(hw, sizeof(*prof));
4336 goto err_ice_add_prof;
4338 prof->profile_cookie = id;
4339 prof->prof_id = prof_id;
4343 /* build list of ptgs */
4344 while (bytes && prof->ptg_cnt < ICE_MAX_PTG_PER_PROFILE) {
4347 if (!ptypes[byte]) {
4353 /* Examine 8 bits per byte */
4354 ice_for_each_set_bit(bit, (ice_bitmap_t *)&ptypes[byte],
4359 ptype = byte * BITS_PER_BYTE + bit;
4361 /* The package should place all ptypes in a non-zero
4362 * PTG, so the following call should never fail.
4364 if (ice_ptg_find_ptype(hw, blk, ptype, &ptg))
4367 /* If PTG is already added, skip and continue */
4368 if (ice_is_bit_set(ptgs_used, ptg))
4371 ice_set_bit(ptg, ptgs_used);
4372 prof->ptg[prof->ptg_cnt] = ptg;
4374 if (++prof->ptg_cnt >= ICE_MAX_PTG_PER_PROFILE)
4382 LIST_ADD(&prof->list, &hw->blk[blk].es.prof_map);
4383 status = ICE_SUCCESS;
4386 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
4391 * ice_search_prof_id - Search for a profile tracking ID
4392 * @hw: pointer to the HW struct
4393 * @blk: hardware block
4394 * @id: profile tracking ID
4396 * This will search for a profile tracking ID which was previously added.
4397 * The profile map lock should be held before calling this function.
4399 struct ice_prof_map *
4400 ice_search_prof_id(struct ice_hw *hw, enum ice_block blk, u64 id)
4402 struct ice_prof_map *entry = NULL;
4403 struct ice_prof_map *map;
4405 LIST_FOR_EACH_ENTRY(map, &hw->blk[blk].es.prof_map, ice_prof_map, list)
4406 if (map->profile_cookie == id) {
4415 * ice_set_prof_context - Set context for a given profile
4416 * @hw: pointer to the HW struct
4417 * @blk: hardware block
4418 * @id: profile tracking ID
4422 ice_set_prof_context(struct ice_hw *hw, enum ice_block blk, u64 id, u64 cntxt)
4424 enum ice_status status = ICE_ERR_DOES_NOT_EXIST;
4425 struct ice_prof_map *entry;
4427 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
4428 entry = ice_search_prof_id(hw, blk, id);
4430 entry->context = cntxt;
4431 status = ICE_SUCCESS;
4433 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
4438 * ice_get_prof_context - Get context for a given profile
4439 * @hw: pointer to the HW struct
4440 * @blk: hardware block
4441 * @id: profile tracking ID
4442 * @cntxt: pointer to variable to receive the context
4445 ice_get_prof_context(struct ice_hw *hw, enum ice_block blk, u64 id, u64 *cntxt)
4447 enum ice_status status = ICE_ERR_DOES_NOT_EXIST;
4448 struct ice_prof_map *entry;
4450 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
4451 entry = ice_search_prof_id(hw, blk, id);
4453 *cntxt = entry->context;
4454 status = ICE_SUCCESS;
4456 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
4461 * ice_vsig_prof_id_count - count profiles in a VSIG
4462 * @hw: pointer to the HW struct
4463 * @blk: hardware block
4464 * @vsig: VSIG to remove the profile from
4467 ice_vsig_prof_id_count(struct ice_hw *hw, enum ice_block blk, u16 vsig)
4469 u16 idx = vsig & ICE_VSIG_IDX_M, count = 0;
4470 struct ice_vsig_prof *p;
4472 LIST_FOR_EACH_ENTRY(p, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4473 ice_vsig_prof, list)
4480 * ice_rel_tcam_idx - release a TCAM index
4481 * @hw: pointer to the HW struct
4482 * @blk: hardware block
4483 * @idx: the index to release
4485 static enum ice_status
4486 ice_rel_tcam_idx(struct ice_hw *hw, enum ice_block blk, u16 idx)
4488 /* Masks to invoke a never match entry */
4489 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4490 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFE, 0xFF, 0xFF, 0xFF, 0xFF };
4491 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x01, 0x00, 0x00, 0x00, 0x00 };
4492 enum ice_status status;
4494 /* write the TCAM entry */
4495 status = ice_tcam_write_entry(hw, blk, idx, 0, 0, 0, 0, 0, vl_msk,
4500 /* release the TCAM entry */
4501 status = ice_free_tcam_ent(hw, blk, idx);
4507 * ice_rem_prof_id - remove one profile from a VSIG
4508 * @hw: pointer to the HW struct
4509 * @blk: hardware block
4510 * @prof: pointer to profile structure to remove
4512 static enum ice_status
4513 ice_rem_prof_id(struct ice_hw *hw, enum ice_block blk,
4514 struct ice_vsig_prof *prof)
4516 enum ice_status status;
4519 for (i = 0; i < prof->tcam_count; i++)
4520 if (prof->tcam[i].in_use) {
4521 prof->tcam[i].in_use = false;
4522 status = ice_rel_tcam_idx(hw, blk,
4523 prof->tcam[i].tcam_idx);
4525 return ICE_ERR_HW_TABLE;
4532 * ice_rem_vsig - remove VSIG
4533 * @hw: pointer to the HW struct
4534 * @blk: hardware block
4535 * @vsig: the VSIG to remove
4536 * @chg: the change list
4538 static enum ice_status
4539 ice_rem_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig,
4540 struct LIST_HEAD_TYPE *chg)
4542 u16 idx = vsig & ICE_VSIG_IDX_M;
4543 struct ice_vsig_vsi *vsi_cur;
4544 struct ice_vsig_prof *d, *t;
4545 enum ice_status status;
4547 /* remove TCAM entries */
4548 LIST_FOR_EACH_ENTRY_SAFE(d, t,
4549 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4550 ice_vsig_prof, list) {
4551 status = ice_rem_prof_id(hw, blk, d);
4559 /* Move all VSIS associated with this VSIG to the default VSIG */
4560 vsi_cur = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
4561 /* If the VSIG has at least 1 VSI then iterate through the list
4562 * and remove the VSIs before deleting the group.
4566 struct ice_vsig_vsi *tmp = vsi_cur->next_vsi;
4567 struct ice_chs_chg *p;
4569 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4571 return ICE_ERR_NO_MEMORY;
4573 p->type = ICE_VSIG_REM;
4574 p->orig_vsig = vsig;
4575 p->vsig = ICE_DEFAULT_VSIG;
4576 p->vsi = vsi_cur - hw->blk[blk].xlt2.vsis;
4578 LIST_ADD(&p->list_entry, chg);
4583 return ice_vsig_free(hw, blk, vsig);
4587 * ice_rem_prof_id_vsig - remove a specific profile from a VSIG
4588 * @hw: pointer to the HW struct
4589 * @blk: hardware block
4590 * @vsig: VSIG to remove the profile from
4591 * @hdl: profile handle indicating which profile to remove
4592 * @chg: list to receive a record of changes
4594 static enum ice_status
4595 ice_rem_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl,
4596 struct LIST_HEAD_TYPE *chg)
4598 u16 idx = vsig & ICE_VSIG_IDX_M;
4599 struct ice_vsig_prof *p, *t;
4600 enum ice_status status;
4602 LIST_FOR_EACH_ENTRY_SAFE(p, t,
4603 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4604 ice_vsig_prof, list)
4605 if (p->profile_cookie == hdl) {
4606 if (ice_vsig_prof_id_count(hw, blk, vsig) == 1)
4607 /* this is the last profile, remove the VSIG */
4608 return ice_rem_vsig(hw, blk, vsig, chg);
4610 status = ice_rem_prof_id(hw, blk, p);
4618 return ICE_ERR_DOES_NOT_EXIST;
4622 * ice_rem_flow_all - remove all flows with a particular profile
4623 * @hw: pointer to the HW struct
4624 * @blk: hardware block
4625 * @id: profile tracking ID
4627 static enum ice_status
4628 ice_rem_flow_all(struct ice_hw *hw, enum ice_block blk, u64 id)
4630 struct ice_chs_chg *del, *tmp;
4631 enum ice_status status;
4632 struct LIST_HEAD_TYPE chg;
4635 INIT_LIST_HEAD(&chg);
4637 for (i = 1; i < ICE_MAX_VSIGS; i++)
4638 if (hw->blk[blk].xlt2.vsig_tbl[i].in_use) {
4639 if (ice_has_prof_vsig(hw, blk, i, id)) {
4640 status = ice_rem_prof_id_vsig(hw, blk, i, id,
4643 goto err_ice_rem_flow_all;
4647 status = ice_upd_prof_hw(hw, blk, &chg);
4649 err_ice_rem_flow_all:
4650 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
4651 LIST_DEL(&del->list_entry);
4659 * ice_rem_prof - remove profile
4660 * @hw: pointer to the HW struct
4661 * @blk: hardware block
4662 * @id: profile tracking ID
4664 * This will remove the profile specified by the ID parameter, which was
4665 * previously created through ice_add_prof. If any existing entries
4666 * are associated with this profile, they will be removed as well.
4668 enum ice_status ice_rem_prof(struct ice_hw *hw, enum ice_block blk, u64 id)
4670 struct ice_prof_map *pmap;
4671 enum ice_status status;
4673 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
4675 pmap = ice_search_prof_id(hw, blk, id);
4677 status = ICE_ERR_DOES_NOT_EXIST;
4678 goto err_ice_rem_prof;
4681 /* remove all flows with this profile */
4682 status = ice_rem_flow_all(hw, blk, pmap->profile_cookie);
4684 goto err_ice_rem_prof;
4686 /* dereference profile, and possibly remove */
4687 ice_prof_dec_ref(hw, blk, pmap->prof_id);
4689 LIST_DEL(&pmap->list);
4693 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
4698 * ice_get_prof - get profile
4699 * @hw: pointer to the HW struct
4700 * @blk: hardware block
4701 * @hdl: profile handle
4704 static enum ice_status
4705 ice_get_prof(struct ice_hw *hw, enum ice_block blk, u64 hdl,
4706 struct LIST_HEAD_TYPE *chg)
4708 enum ice_status status = ICE_SUCCESS;
4709 struct ice_prof_map *map;
4710 struct ice_chs_chg *p;
4713 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
4714 /* Get the details on the profile specified by the handle ID */
4715 map = ice_search_prof_id(hw, blk, hdl);
4717 status = ICE_ERR_DOES_NOT_EXIST;
4718 goto err_ice_get_prof;
4721 for (i = 0; i < map->ptg_cnt; i++)
4722 if (!hw->blk[blk].es.written[map->prof_id]) {
4723 /* add ES to change list */
4724 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4726 status = ICE_ERR_NO_MEMORY;
4727 goto err_ice_get_prof;
4730 p->type = ICE_PTG_ES_ADD;
4732 p->ptg = map->ptg[i];
4736 p->prof_id = map->prof_id;
4738 hw->blk[blk].es.written[map->prof_id] = true;
4740 LIST_ADD(&p->list_entry, chg);
4744 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
4745 /* let caller clean up the change list */
4750 * ice_get_profs_vsig - get a copy of the list of profiles from a VSIG
4751 * @hw: pointer to the HW struct
4752 * @blk: hardware block
4753 * @vsig: VSIG from which to copy the list
4756 * This routine makes a copy of the list of profiles in the specified VSIG.
4758 static enum ice_status
4759 ice_get_profs_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig,
4760 struct LIST_HEAD_TYPE *lst)
4762 struct ice_vsig_prof *ent1, *ent2;
4763 u16 idx = vsig & ICE_VSIG_IDX_M;
4765 LIST_FOR_EACH_ENTRY(ent1, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4766 ice_vsig_prof, list) {
4767 struct ice_vsig_prof *p;
4769 /* copy to the input list */
4770 p = (struct ice_vsig_prof *)ice_memdup(hw, ent1, sizeof(*p),
4771 ICE_NONDMA_TO_NONDMA);
4773 goto err_ice_get_profs_vsig;
4775 LIST_ADD_TAIL(&p->list, lst);
4780 err_ice_get_profs_vsig:
4781 LIST_FOR_EACH_ENTRY_SAFE(ent1, ent2, lst, ice_vsig_prof, list) {
4782 LIST_DEL(&ent1->list);
4786 return ICE_ERR_NO_MEMORY;
4790 * ice_add_prof_to_lst - add profile entry to a list
4791 * @hw: pointer to the HW struct
4792 * @blk: hardware block
4793 * @lst: the list to be added to
4794 * @hdl: profile handle of entry to add
4796 static enum ice_status
4797 ice_add_prof_to_lst(struct ice_hw *hw, enum ice_block blk,
4798 struct LIST_HEAD_TYPE *lst, u64 hdl)
4800 enum ice_status status = ICE_SUCCESS;
4801 struct ice_prof_map *map;
4802 struct ice_vsig_prof *p;
4805 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
4806 map = ice_search_prof_id(hw, blk, hdl);
4808 status = ICE_ERR_DOES_NOT_EXIST;
4809 goto err_ice_add_prof_to_lst;
4812 p = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*p));
4814 status = ICE_ERR_NO_MEMORY;
4815 goto err_ice_add_prof_to_lst;
4818 p->profile_cookie = map->profile_cookie;
4819 p->prof_id = map->prof_id;
4820 p->tcam_count = map->ptg_cnt;
4822 for (i = 0; i < map->ptg_cnt; i++) {
4823 p->tcam[i].prof_id = map->prof_id;
4824 p->tcam[i].tcam_idx = ICE_INVALID_TCAM;
4825 p->tcam[i].ptg = map->ptg[i];
4828 LIST_ADD(&p->list, lst);
4830 err_ice_add_prof_to_lst:
4831 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
4836 * ice_move_vsi - move VSI to another VSIG
4837 * @hw: pointer to the HW struct
4838 * @blk: hardware block
4839 * @vsi: the VSI to move
4840 * @vsig: the VSIG to move the VSI to
4841 * @chg: the change list
4843 static enum ice_status
4844 ice_move_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig,
4845 struct LIST_HEAD_TYPE *chg)
4847 enum ice_status status;
4848 struct ice_chs_chg *p;
4851 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4853 return ICE_ERR_NO_MEMORY;
4855 status = ice_vsig_find_vsi(hw, blk, vsi, &orig_vsig);
4857 status = ice_vsig_add_mv_vsi(hw, blk, vsi, vsig);
4864 p->type = ICE_VSI_MOVE;
4866 p->orig_vsig = orig_vsig;
4869 LIST_ADD(&p->list_entry, chg);
4875 * ice_rem_chg_tcam_ent - remove a specific TCAM entry from change list
4876 * @hw: pointer to the HW struct
4877 * @idx: the index of the TCAM entry to remove
4878 * @chg: the list of change structures to search
4881 ice_rem_chg_tcam_ent(struct ice_hw *hw, u16 idx, struct LIST_HEAD_TYPE *chg)
4883 struct ice_chs_chg *pos, *tmp;
4885 LIST_FOR_EACH_ENTRY_SAFE(tmp, pos, chg, ice_chs_chg, list_entry)
4886 if (tmp->type == ICE_TCAM_ADD && tmp->tcam_idx == idx) {
4887 LIST_DEL(&tmp->list_entry);
4893 * ice_prof_tcam_ena_dis - add enable or disable TCAM change
4894 * @hw: pointer to the HW struct
4895 * @blk: hardware block
4896 * @enable: true to enable, false to disable
4897 * @vsig: the VSIG of the TCAM entry
4898 * @tcam: pointer the TCAM info structure of the TCAM to disable
4899 * @chg: the change list
4901 * This function appends an enable or disable TCAM entry in the change log
4903 static enum ice_status
4904 ice_prof_tcam_ena_dis(struct ice_hw *hw, enum ice_block blk, bool enable,
4905 u16 vsig, struct ice_tcam_inf *tcam,
4906 struct LIST_HEAD_TYPE *chg)
4908 enum ice_status status;
4909 struct ice_chs_chg *p;
4911 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4912 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0x00, 0x00, 0x00 };
4913 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
4915 /* if disabling, free the TCAM */
4917 status = ice_rel_tcam_idx(hw, blk, tcam->tcam_idx);
4919 /* if we have already created a change for this TCAM entry, then
4920 * we need to remove that entry, in order to prevent writing to
4921 * a TCAM entry we no longer will have ownership of.
4923 ice_rem_chg_tcam_ent(hw, tcam->tcam_idx, chg);
4929 /* for re-enabling, reallocate a TCAM */
4930 status = ice_alloc_tcam_ent(hw, blk, true, &tcam->tcam_idx);
4934 /* add TCAM to change list */
4935 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4937 return ICE_ERR_NO_MEMORY;
4939 status = ice_tcam_write_entry(hw, blk, tcam->tcam_idx, tcam->prof_id,
4940 tcam->ptg, vsig, 0, 0, vl_msk, dc_msk,
4943 goto err_ice_prof_tcam_ena_dis;
4947 p->type = ICE_TCAM_ADD;
4948 p->add_tcam_idx = true;
4949 p->prof_id = tcam->prof_id;
4952 p->tcam_idx = tcam->tcam_idx;
4955 LIST_ADD(&p->list_entry, chg);
4959 err_ice_prof_tcam_ena_dis:
4965 * ice_adj_prof_priorities - adjust profile based on priorities
4966 * @hw: pointer to the HW struct
4967 * @blk: hardware block
4968 * @vsig: the VSIG for which to adjust profile priorities
4969 * @chg: the change list
4971 static enum ice_status
4972 ice_adj_prof_priorities(struct ice_hw *hw, enum ice_block blk, u16 vsig,
4973 struct LIST_HEAD_TYPE *chg)
4975 ice_declare_bitmap(ptgs_used, ICE_XLT1_CNT);
4976 enum ice_status status = ICE_SUCCESS;
4977 struct ice_vsig_prof *t;
4980 ice_zero_bitmap(ptgs_used, ICE_XLT1_CNT);
4981 idx = vsig & ICE_VSIG_IDX_M;
4983 /* Priority is based on the order in which the profiles are added. The
4984 * newest added profile has highest priority and the oldest added
4985 * profile has the lowest priority. Since the profile property list for
4986 * a VSIG is sorted from newest to oldest, this code traverses the list
4987 * in order and enables the first of each PTG that it finds (that is not
4988 * already enabled); it also disables any duplicate PTGs that it finds
4989 * in the older profiles (that are currently enabled).
4992 LIST_FOR_EACH_ENTRY(t, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4993 ice_vsig_prof, list) {
4996 for (i = 0; i < t->tcam_count; i++) {
4999 /* Scan the priorities from newest to oldest.
5000 * Make sure that the newest profiles take priority.
5002 used = ice_is_bit_set(ptgs_used, t->tcam[i].ptg);
5004 if (used && t->tcam[i].in_use) {
5005 /* need to mark this PTG as never match, as it
5006 * was already in use and therefore duplicate
5007 * (and lower priority)
5009 status = ice_prof_tcam_ena_dis(hw, blk, false,
5015 } else if (!used && !t->tcam[i].in_use) {
5016 /* need to enable this PTG, as it in not in use
5017 * and not enabled (highest priority)
5019 status = ice_prof_tcam_ena_dis(hw, blk, true,
5027 /* keep track of used ptgs */
5028 ice_set_bit(t->tcam[i].ptg, ptgs_used);
5036 * ice_add_prof_id_vsig - add profile to VSIG
5037 * @hw: pointer to the HW struct
5038 * @blk: hardware block
5039 * @vsig: the VSIG to which this profile is to be added
5040 * @hdl: the profile handle indicating the profile to add
5041 * @rev: true to add entries to the end of the list
5042 * @chg: the change list
5044 static enum ice_status
5045 ice_add_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl,
5046 bool rev, struct LIST_HEAD_TYPE *chg)
5048 /* Masks that ignore flags */
5049 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
5050 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0x00, 0x00, 0x00 };
5051 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
5052 enum ice_status status = ICE_SUCCESS;
5053 struct ice_prof_map *map;
5054 struct ice_vsig_prof *t;
5055 struct ice_chs_chg *p;
5058 /* Error, if this VSIG already has this profile */
5059 if (ice_has_prof_vsig(hw, blk, vsig, hdl))
5060 return ICE_ERR_ALREADY_EXISTS;
5062 /* new VSIG profile structure */
5063 t = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*t));
5065 return ICE_ERR_NO_MEMORY;
5067 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
5068 /* Get the details on the profile specified by the handle ID */
5069 map = ice_search_prof_id(hw, blk, hdl);
5071 status = ICE_ERR_DOES_NOT_EXIST;
5072 goto err_ice_add_prof_id_vsig;
5075 t->profile_cookie = map->profile_cookie;
5076 t->prof_id = map->prof_id;
5077 t->tcam_count = map->ptg_cnt;
5079 /* create TCAM entries */
5080 for (i = 0; i < map->ptg_cnt; i++) {
5083 /* add TCAM to change list */
5084 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5086 status = ICE_ERR_NO_MEMORY;
5087 goto err_ice_add_prof_id_vsig;
5090 /* allocate the TCAM entry index */
5091 status = ice_alloc_tcam_ent(hw, blk, true, &tcam_idx);
5094 goto err_ice_add_prof_id_vsig;
5097 t->tcam[i].ptg = map->ptg[i];
5098 t->tcam[i].prof_id = map->prof_id;
5099 t->tcam[i].tcam_idx = tcam_idx;
5100 t->tcam[i].in_use = true;
5102 p->type = ICE_TCAM_ADD;
5103 p->add_tcam_idx = true;
5104 p->prof_id = t->tcam[i].prof_id;
5105 p->ptg = t->tcam[i].ptg;
5107 p->tcam_idx = t->tcam[i].tcam_idx;
5109 /* write the TCAM entry */
5110 status = ice_tcam_write_entry(hw, blk, t->tcam[i].tcam_idx,
5112 t->tcam[i].ptg, vsig, 0, 0,
5113 vl_msk, dc_msk, nm_msk);
5116 goto err_ice_add_prof_id_vsig;
5120 LIST_ADD(&p->list_entry, chg);
5123 /* add profile to VSIG */
5124 vsig_idx = vsig & ICE_VSIG_IDX_M;
5126 LIST_ADD_TAIL(&t->list,
5127 &hw->blk[blk].xlt2.vsig_tbl[vsig_idx].prop_lst);
5130 &hw->blk[blk].xlt2.vsig_tbl[vsig_idx].prop_lst);
5132 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
5135 err_ice_add_prof_id_vsig:
5136 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
5137 /* let caller clean up the change list */
5143 * ice_create_prof_id_vsig - add a new VSIG with a single profile
5144 * @hw: pointer to the HW struct
5145 * @blk: hardware block
5146 * @vsi: the initial VSI that will be in VSIG
5147 * @hdl: the profile handle of the profile that will be added to the VSIG
5148 * @chg: the change list
5150 static enum ice_status
5151 ice_create_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl,
5152 struct LIST_HEAD_TYPE *chg)
5154 enum ice_status status;
5155 struct ice_chs_chg *p;
5158 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5160 return ICE_ERR_NO_MEMORY;
5162 new_vsig = ice_vsig_alloc(hw, blk);
5164 status = ICE_ERR_HW_TABLE;
5165 goto err_ice_create_prof_id_vsig;
5168 status = ice_move_vsi(hw, blk, vsi, new_vsig, chg);
5170 goto err_ice_create_prof_id_vsig;
5172 status = ice_add_prof_id_vsig(hw, blk, new_vsig, hdl, false, chg);
5174 goto err_ice_create_prof_id_vsig;
5176 p->type = ICE_VSIG_ADD;
5178 p->orig_vsig = ICE_DEFAULT_VSIG;
5181 LIST_ADD(&p->list_entry, chg);
5185 err_ice_create_prof_id_vsig:
5186 /* let caller clean up the change list */
5192 * ice_create_vsig_from_lst - create a new VSIG with a list of profiles
5193 * @hw: pointer to the HW struct
5194 * @blk: hardware block
5195 * @vsi: the initial VSI that will be in VSIG
5196 * @lst: the list of profile that will be added to the VSIG
5197 * @new_vsig: return of new VSIG
5198 * @chg: the change list
5200 static enum ice_status
5201 ice_create_vsig_from_lst(struct ice_hw *hw, enum ice_block blk, u16 vsi,
5202 struct LIST_HEAD_TYPE *lst, u16 *new_vsig,
5203 struct LIST_HEAD_TYPE *chg)
5205 struct ice_vsig_prof *t;
5206 enum ice_status status;
5209 vsig = ice_vsig_alloc(hw, blk);
5211 return ICE_ERR_HW_TABLE;
5213 status = ice_move_vsi(hw, blk, vsi, vsig, chg);
5217 LIST_FOR_EACH_ENTRY(t, lst, ice_vsig_prof, list) {
5218 /* Reverse the order here since we are copying the list */
5219 status = ice_add_prof_id_vsig(hw, blk, vsig, t->profile_cookie,
5231 * ice_find_prof_vsig - find a VSIG with a specific profile handle
5232 * @hw: pointer to the HW struct
5233 * @blk: hardware block
5234 * @hdl: the profile handle of the profile to search for
5235 * @vsig: returns the VSIG with the matching profile
5238 ice_find_prof_vsig(struct ice_hw *hw, enum ice_block blk, u64 hdl, u16 *vsig)
5240 struct ice_vsig_prof *t;
5241 enum ice_status status;
5242 struct LIST_HEAD_TYPE lst;
5244 INIT_LIST_HEAD(&lst);
5246 t = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*t));
5250 t->profile_cookie = hdl;
5251 LIST_ADD(&t->list, &lst);
5253 status = ice_find_dup_props_vsig(hw, blk, &lst, vsig);
5258 return status == ICE_SUCCESS;
5262 * ice_add_vsi_flow - add VSI flow
5263 * @hw: pointer to the HW struct
5264 * @blk: hardware block
5266 * @vsig: target VSIG to include the input VSI
5268 * Calling this function will add the VSI to a given VSIG and
5269 * update the HW tables accordingly. This call can be used to
5270 * add multiple VSIs to a VSIG if we know beforehand that those
5271 * VSIs have the same characteristics of the VSIG. This will
5272 * save time in generating a new VSIG and TCAMs till a match is
5273 * found and subsequent rollback when a matching VSIG is found.
5276 ice_add_vsi_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
5278 struct ice_chs_chg *tmp, *del;
5279 struct LIST_HEAD_TYPE chg;
5280 enum ice_status status;
5282 /* if target VSIG is default the move is invalid */
5283 if ((vsig & ICE_VSIG_IDX_M) == ICE_DEFAULT_VSIG)
5284 return ICE_ERR_PARAM;
5286 INIT_LIST_HEAD(&chg);
5288 /* move VSI to the VSIG that matches */
5289 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5290 /* update hardware if success */
5292 status = ice_upd_prof_hw(hw, blk, &chg);
5294 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
5295 LIST_DEL(&del->list_entry);
5303 * ice_add_prof_id_flow - add profile flow
5304 * @hw: pointer to the HW struct
5305 * @blk: hardware block
5306 * @vsi: the VSI to enable with the profile specified by ID
5307 * @hdl: profile handle
5309 * Calling this function will update the hardware tables to enable the
5310 * profile indicated by the ID parameter for the VSIs specified in the VSI
5311 * array. Once successfully called, the flow will be enabled.
5314 ice_add_prof_id_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl)
5316 struct ice_vsig_prof *tmp1, *del1;
5317 struct ice_chs_chg *tmp, *del;
5318 struct LIST_HEAD_TYPE union_lst;
5319 enum ice_status status;
5320 struct LIST_HEAD_TYPE chg;
5323 INIT_LIST_HEAD(&union_lst);
5324 INIT_LIST_HEAD(&chg);
5327 status = ice_get_prof(hw, blk, hdl, &chg);
5331 /* determine if VSI is already part of a VSIG */
5332 status = ice_vsig_find_vsi(hw, blk, vsi, &vsig);
5333 if (!status && vsig) {
5341 /* make sure that there is no overlap/conflict between the new
5342 * characteristics and the existing ones; we don't support that
5345 if (ice_has_prof_vsig(hw, blk, vsig, hdl)) {
5346 status = ICE_ERR_ALREADY_EXISTS;
5347 goto err_ice_add_prof_id_flow;
5350 /* last VSI in the VSIG? */
5351 status = ice_vsig_get_ref(hw, blk, vsig, &ref);
5353 goto err_ice_add_prof_id_flow;
5354 only_vsi = (ref == 1);
5356 /* create a union of the current profiles and the one being
5359 status = ice_get_profs_vsig(hw, blk, vsig, &union_lst);
5361 goto err_ice_add_prof_id_flow;
5363 status = ice_add_prof_to_lst(hw, blk, &union_lst, hdl);
5365 goto err_ice_add_prof_id_flow;
5367 /* search for an existing VSIG with an exact charc match */
5368 status = ice_find_dup_props_vsig(hw, blk, &union_lst, &vsig);
5370 /* move VSI to the VSIG that matches */
5371 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5373 goto err_ice_add_prof_id_flow;
5375 /* VSI has been moved out of or_vsig. If the or_vsig had
5376 * only that VSI it is now empty and can be removed.
5379 status = ice_rem_vsig(hw, blk, or_vsig, &chg);
5381 goto err_ice_add_prof_id_flow;
5383 } else if (only_vsi) {
5384 /* If the original VSIG only contains one VSI, then it
5385 * will be the requesting VSI. In this case the VSI is
5386 * not sharing entries and we can simply add the new
5387 * profile to the VSIG.
5389 status = ice_add_prof_id_vsig(hw, blk, vsig, hdl, false,
5392 goto err_ice_add_prof_id_flow;
5394 /* Adjust priorities */
5395 status = ice_adj_prof_priorities(hw, blk, vsig, &chg);
5397 goto err_ice_add_prof_id_flow;
5399 /* No match, so we need a new VSIG */
5400 status = ice_create_vsig_from_lst(hw, blk, vsi,
5404 goto err_ice_add_prof_id_flow;
5406 /* Adjust priorities */
5407 status = ice_adj_prof_priorities(hw, blk, vsig, &chg);
5409 goto err_ice_add_prof_id_flow;
5412 /* need to find or add a VSIG */
5413 /* search for an existing VSIG with an exact charc match */
5414 if (ice_find_prof_vsig(hw, blk, hdl, &vsig)) {
5415 /* found an exact match */
5416 /* add or move VSI to the VSIG that matches */
5417 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5419 goto err_ice_add_prof_id_flow;
5421 /* we did not find an exact match */
5422 /* we need to add a VSIG */
5423 status = ice_create_prof_id_vsig(hw, blk, vsi, hdl,
5426 goto err_ice_add_prof_id_flow;
5430 /* update hardware */
5432 status = ice_upd_prof_hw(hw, blk, &chg);
5434 err_ice_add_prof_id_flow:
5435 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
5436 LIST_DEL(&del->list_entry);
5440 LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, &union_lst, ice_vsig_prof, list) {
5441 LIST_DEL(&del1->list);
5449 * ice_add_flow - add flow
5450 * @hw: pointer to the HW struct
5451 * @blk: hardware block
5452 * @vsi: array of VSIs to enable with the profile specified by ID
5453 * @count: number of elements in the VSI array
5454 * @id: profile tracking ID
5456 * Calling this function will update the hardware tables to enable the
5457 * profile indicated by the ID parameter for the VSIs specified in the VSI
5458 * array. Once successfully called, the flow will be enabled.
5461 ice_add_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi[], u8 count,
5464 enum ice_status status;
5467 for (i = 0; i < count; i++) {
5468 status = ice_add_prof_id_flow(hw, blk, vsi[i], id);
5477 * ice_rem_prof_from_list - remove a profile from list
5478 * @hw: pointer to the HW struct
5479 * @lst: list to remove the profile from
5480 * @hdl: the profile handle indicating the profile to remove
5482 static enum ice_status
5483 ice_rem_prof_from_list(struct ice_hw *hw, struct LIST_HEAD_TYPE *lst, u64 hdl)
5485 struct ice_vsig_prof *ent, *tmp;
5487 LIST_FOR_EACH_ENTRY_SAFE(ent, tmp, lst, ice_vsig_prof, list)
5488 if (ent->profile_cookie == hdl) {
5489 LIST_DEL(&ent->list);
5494 return ICE_ERR_DOES_NOT_EXIST;
5498 * ice_rem_prof_id_flow - remove flow
5499 * @hw: pointer to the HW struct
5500 * @blk: hardware block
5501 * @vsi: the VSI from which to remove the profile specified by ID
5502 * @hdl: profile tracking handle
5504 * Calling this function will update the hardware tables to remove the
5505 * profile indicated by the ID parameter for the VSIs specified in the VSI
5506 * array. Once successfully called, the flow will be disabled.
5509 ice_rem_prof_id_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl)
5511 struct ice_vsig_prof *tmp1, *del1;
5512 struct ice_chs_chg *tmp, *del;
5513 struct LIST_HEAD_TYPE chg, copy;
5514 enum ice_status status;
5517 INIT_LIST_HEAD(©);
5518 INIT_LIST_HEAD(&chg);
5520 /* determine if VSI is already part of a VSIG */
5521 status = ice_vsig_find_vsi(hw, blk, vsi, &vsig);
5522 if (!status && vsig) {
5528 last_profile = ice_vsig_prof_id_count(hw, blk, vsig) == 1;
5529 status = ice_vsig_get_ref(hw, blk, vsig, &ref);
5531 goto err_ice_rem_prof_id_flow;
5532 only_vsi = (ref == 1);
5535 /* If the original VSIG only contains one reference,
5536 * which will be the requesting VSI, then the VSI is not
5537 * sharing entries and we can simply remove the specific
5538 * characteristics from the VSIG.
5542 /* If there are no profiles left for this VSIG,
5543 * then simply remove the VSIG.
5545 status = ice_rem_vsig(hw, blk, vsig, &chg);
5547 goto err_ice_rem_prof_id_flow;
5549 status = ice_rem_prof_id_vsig(hw, blk, vsig,
5552 goto err_ice_rem_prof_id_flow;
5554 /* Adjust priorities */
5555 status = ice_adj_prof_priorities(hw, blk, vsig,
5558 goto err_ice_rem_prof_id_flow;
5562 /* Make a copy of the VSIG's list of Profiles */
5563 status = ice_get_profs_vsig(hw, blk, vsig, ©);
5565 goto err_ice_rem_prof_id_flow;
5567 /* Remove specified profile entry from the list */
5568 status = ice_rem_prof_from_list(hw, ©, hdl);
5570 goto err_ice_rem_prof_id_flow;
5572 if (LIST_EMPTY(©)) {
5573 status = ice_move_vsi(hw, blk, vsi,
5574 ICE_DEFAULT_VSIG, &chg);
5576 goto err_ice_rem_prof_id_flow;
5578 } else if (!ice_find_dup_props_vsig(hw, blk, ©,
5580 /* found an exact match */
5581 /* add or move VSI to the VSIG that matches */
5582 /* Search for a VSIG with a matching profile
5586 /* Found match, move VSI to the matching VSIG */
5587 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5589 goto err_ice_rem_prof_id_flow;
5591 /* since no existing VSIG supports this
5592 * characteristic pattern, we need to create a
5593 * new VSIG and TCAM entries
5595 status = ice_create_vsig_from_lst(hw, blk, vsi,
5599 goto err_ice_rem_prof_id_flow;
5601 /* Adjust priorities */
5602 status = ice_adj_prof_priorities(hw, blk, vsig,
5605 goto err_ice_rem_prof_id_flow;
5609 status = ICE_ERR_DOES_NOT_EXIST;
5612 /* update hardware tables */
5614 status = ice_upd_prof_hw(hw, blk, &chg);
5616 err_ice_rem_prof_id_flow:
5617 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
5618 LIST_DEL(&del->list_entry);
5622 LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, ©, ice_vsig_prof, list) {
5623 LIST_DEL(&del1->list);
5631 * ice_rem_flow - remove flow
5632 * @hw: pointer to the HW struct
5633 * @blk: hardware block
5634 * @vsi: array of VSIs from which to remove the profile specified by ID
5635 * @count: number of elements in the VSI array
5636 * @id: profile tracking ID
5638 * The function will remove flows from the specified VSIs that were enabled
5639 * using ice_add_flow. The ID value will indicated which profile will be
5640 * removed. Once successfully called, the flow will be disabled.
5643 ice_rem_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi[], u8 count,
5646 enum ice_status status;
5649 for (i = 0; i < count; i++) {
5650 status = ice_rem_prof_id_flow(hw, blk, vsi[i], id);