1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2020 Intel Corporation
5 #include "ice_common.h"
6 #include "ice_flex_pipe.h"
7 #include "ice_protocol_type.h"
10 /* To support tunneling entries by PF, the package will append the PF number to
11 * the label; for example TNL_VXLAN_PF0, TNL_VXLAN_PF1, TNL_VXLAN_PF2, etc.
13 static const struct ice_tunnel_type_scan tnls[] = {
14 { TNL_VXLAN, "TNL_VXLAN_PF" },
15 { TNL_GENEVE, "TNL_GENEVE_PF" },
19 static const u32 ice_sect_lkup[ICE_BLK_COUNT][ICE_SECT_COUNT] = {
23 ICE_SID_XLT_KEY_BUILDER_SW,
26 ICE_SID_PROFID_TCAM_SW,
27 ICE_SID_PROFID_REDIR_SW,
29 ICE_SID_CDID_KEY_BUILDER_SW,
36 ICE_SID_XLT_KEY_BUILDER_ACL,
39 ICE_SID_PROFID_TCAM_ACL,
40 ICE_SID_PROFID_REDIR_ACL,
42 ICE_SID_CDID_KEY_BUILDER_ACL,
43 ICE_SID_CDID_REDIR_ACL
49 ICE_SID_XLT_KEY_BUILDER_FD,
52 ICE_SID_PROFID_TCAM_FD,
53 ICE_SID_PROFID_REDIR_FD,
55 ICE_SID_CDID_KEY_BUILDER_FD,
62 ICE_SID_XLT_KEY_BUILDER_RSS,
65 ICE_SID_PROFID_TCAM_RSS,
66 ICE_SID_PROFID_REDIR_RSS,
68 ICE_SID_CDID_KEY_BUILDER_RSS,
69 ICE_SID_CDID_REDIR_RSS
75 ICE_SID_XLT_KEY_BUILDER_PE,
78 ICE_SID_PROFID_TCAM_PE,
79 ICE_SID_PROFID_REDIR_PE,
81 ICE_SID_CDID_KEY_BUILDER_PE,
87 * ice_sect_id - returns section ID
91 * This helper function returns the proper section ID given a block type and a
94 static u32 ice_sect_id(enum ice_block blk, enum ice_sect sect)
96 return ice_sect_lkup[blk][sect];
101 * @buf: pointer to the ice buffer
103 * This helper function validates a buffer's header.
105 static struct ice_buf_hdr *ice_pkg_val_buf(struct ice_buf *buf)
107 struct ice_buf_hdr *hdr;
111 hdr = (struct ice_buf_hdr *)buf->buf;
113 section_count = LE16_TO_CPU(hdr->section_count);
114 if (section_count < ICE_MIN_S_COUNT || section_count > ICE_MAX_S_COUNT)
117 data_end = LE16_TO_CPU(hdr->data_end);
118 if (data_end < ICE_MIN_S_DATA_END || data_end > ICE_MAX_S_DATA_END)
126 * @ice_seg: pointer to the ice segment
128 * Returns the address of the buffer table within the ice segment.
130 static struct ice_buf_table *ice_find_buf_table(struct ice_seg *ice_seg)
132 struct ice_nvm_table *nvms;
134 nvms = (struct ice_nvm_table *)
135 (ice_seg->device_table +
136 LE32_TO_CPU(ice_seg->device_table_count));
138 return (_FORCE_ struct ice_buf_table *)
139 (nvms->vers + LE32_TO_CPU(nvms->table_count));
144 * @ice_seg: pointer to the ice segment (or NULL on subsequent calls)
145 * @state: pointer to the enum state
147 * This function will enumerate all the buffers in the ice segment. The first
148 * call is made with the ice_seg parameter non-NULL; on subsequent calls,
149 * ice_seg is set to NULL which continues the enumeration. When the function
150 * returns a NULL pointer, then the end of the buffers has been reached, or an
151 * unexpected value has been detected (for example an invalid section count or
152 * an invalid buffer end value).
154 static struct ice_buf_hdr *
155 ice_pkg_enum_buf(struct ice_seg *ice_seg, struct ice_pkg_enum *state)
158 state->buf_table = ice_find_buf_table(ice_seg);
159 if (!state->buf_table)
163 return ice_pkg_val_buf(state->buf_table->buf_array);
166 if (++state->buf_idx < LE32_TO_CPU(state->buf_table->buf_count))
167 return ice_pkg_val_buf(state->buf_table->buf_array +
174 * ice_pkg_advance_sect
175 * @ice_seg: pointer to the ice segment (or NULL on subsequent calls)
176 * @state: pointer to the enum state
178 * This helper function will advance the section within the ice segment,
179 * also advancing the buffer if needed.
182 ice_pkg_advance_sect(struct ice_seg *ice_seg, struct ice_pkg_enum *state)
184 if (!ice_seg && !state->buf)
187 if (!ice_seg && state->buf)
188 if (++state->sect_idx < LE16_TO_CPU(state->buf->section_count))
191 state->buf = ice_pkg_enum_buf(ice_seg, state);
195 /* start of new buffer, reset section index */
201 * ice_pkg_enum_section
202 * @ice_seg: pointer to the ice segment (or NULL on subsequent calls)
203 * @state: pointer to the enum state
204 * @sect_type: section type to enumerate
206 * This function will enumerate all the sections of a particular type in the
207 * ice segment. The first call is made with the ice_seg parameter non-NULL;
208 * on subsequent calls, ice_seg is set to NULL which continues the enumeration.
209 * When the function returns a NULL pointer, then the end of the matching
210 * sections has been reached.
213 ice_pkg_enum_section(struct ice_seg *ice_seg, struct ice_pkg_enum *state,
219 state->type = sect_type;
221 if (!ice_pkg_advance_sect(ice_seg, state))
224 /* scan for next matching section */
225 while (state->buf->section_entry[state->sect_idx].type !=
226 CPU_TO_LE32(state->type))
227 if (!ice_pkg_advance_sect(NULL, state))
230 /* validate section */
231 offset = LE16_TO_CPU(state->buf->section_entry[state->sect_idx].offset);
232 if (offset < ICE_MIN_S_OFF || offset > ICE_MAX_S_OFF)
235 size = LE16_TO_CPU(state->buf->section_entry[state->sect_idx].size);
236 if (size < ICE_MIN_S_SZ || size > ICE_MAX_S_SZ)
239 /* make sure the section fits in the buffer */
240 if (offset + size > ICE_PKG_BUF_SIZE)
244 LE32_TO_CPU(state->buf->section_entry[state->sect_idx].type);
246 /* calc pointer to this section */
247 state->sect = ((u8 *)state->buf) +
248 LE16_TO_CPU(state->buf->section_entry[state->sect_idx].offset);
255 * @ice_seg: pointer to the ice segment (or NULL on subsequent calls)
256 * @state: pointer to the enum state
257 * @sect_type: section type to enumerate
258 * @offset: pointer to variable that receives the offset in the table (optional)
259 * @handler: function that handles access to the entries into the section type
261 * This function will enumerate all the entries in particular section type in
262 * the ice segment. The first call is made with the ice_seg parameter non-NULL;
263 * on subsequent calls, ice_seg is set to NULL which continues the enumeration.
264 * When the function returns a NULL pointer, then the end of the entries has
267 * Since each section may have a different header and entry size, the handler
268 * function is needed to determine the number and location entries in each
271 * The offset parameter is optional, but should be used for sections that
272 * contain an offset for each section table. For such cases, the section handler
273 * function must return the appropriate offset + index to give the absolution
274 * offset for each entry. For example, if the base for a section's header
275 * indicates a base offset of 10, and the index for the entry is 2, then
276 * section handler function should set the offset to 10 + 2 = 12.
279 ice_pkg_enum_entry(struct ice_seg *ice_seg, struct ice_pkg_enum *state,
280 u32 sect_type, u32 *offset,
281 void *(*handler)(u32 sect_type, void *section,
282 u32 index, u32 *offset))
290 if (!ice_pkg_enum_section(ice_seg, state, sect_type))
293 state->entry_idx = 0;
294 state->handler = handler;
303 entry = state->handler(state->sect_type, state->sect, state->entry_idx,
306 /* end of a section, look for another section of this type */
307 if (!ice_pkg_enum_section(NULL, state, 0))
310 state->entry_idx = 0;
311 entry = state->handler(state->sect_type, state->sect,
312 state->entry_idx, offset);
319 * ice_boost_tcam_handler
320 * @sect_type: section type
321 * @section: pointer to section
322 * @index: index of the boost TCAM entry to be returned
323 * @offset: pointer to receive absolute offset, always 0 for boost TCAM sections
325 * This is a callback function that can be passed to ice_pkg_enum_entry.
326 * Handles enumeration of individual boost TCAM entries.
329 ice_boost_tcam_handler(u32 sect_type, void *section, u32 index, u32 *offset)
331 struct ice_boost_tcam_section *boost;
336 if (sect_type != ICE_SID_RXPARSER_BOOST_TCAM)
339 if (index > ICE_MAX_BST_TCAMS_IN_BUF)
345 boost = (struct ice_boost_tcam_section *)section;
346 if (index >= LE16_TO_CPU(boost->count))
349 return boost->tcam + index;
353 * ice_find_boost_entry
354 * @ice_seg: pointer to the ice segment (non-NULL)
355 * @addr: Boost TCAM address of entry to search for
356 * @entry: returns pointer to the entry
358 * Finds a particular Boost TCAM entry and returns a pointer to that entry
359 * if it is found. The ice_seg parameter must not be NULL since the first call
360 * to ice_pkg_enum_entry requires a pointer to an actual ice_segment structure.
362 static enum ice_status
363 ice_find_boost_entry(struct ice_seg *ice_seg, u16 addr,
364 struct ice_boost_tcam_entry **entry)
366 struct ice_boost_tcam_entry *tcam;
367 struct ice_pkg_enum state;
369 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
372 return ICE_ERR_PARAM;
375 tcam = (struct ice_boost_tcam_entry *)
376 ice_pkg_enum_entry(ice_seg, &state,
377 ICE_SID_RXPARSER_BOOST_TCAM, NULL,
378 ice_boost_tcam_handler);
379 if (tcam && LE16_TO_CPU(tcam->addr) == addr) {
392 * ice_label_enum_handler
393 * @sect_type: section type
394 * @section: pointer to section
395 * @index: index of the label entry to be returned
396 * @offset: pointer to receive absolute offset, always zero for label sections
398 * This is a callback function that can be passed to ice_pkg_enum_entry.
399 * Handles enumeration of individual label entries.
402 ice_label_enum_handler(u32 __ALWAYS_UNUSED sect_type, void *section, u32 index,
405 struct ice_label_section *labels;
410 if (index > ICE_MAX_LABELS_IN_BUF)
416 labels = (struct ice_label_section *)section;
417 if (index >= LE16_TO_CPU(labels->count))
420 return labels->label + index;
425 * @ice_seg: pointer to the ice segment (NULL on subsequent calls)
426 * @type: the section type that will contain the label (0 on subsequent calls)
427 * @state: ice_pkg_enum structure that will hold the state of the enumeration
428 * @value: pointer to a value that will return the label's value if found
430 * Enumerates a list of labels in the package. The caller will call
431 * ice_enum_labels(ice_seg, type, ...) to start the enumeration, then call
432 * ice_enum_labels(NULL, 0, ...) to continue. When the function returns a NULL
433 * the end of the list has been reached.
436 ice_enum_labels(struct ice_seg *ice_seg, u32 type, struct ice_pkg_enum *state,
439 struct ice_label *label;
441 /* Check for valid label section on first call */
442 if (type && !(type >= ICE_SID_LBL_FIRST && type <= ICE_SID_LBL_LAST))
445 label = (struct ice_label *)ice_pkg_enum_entry(ice_seg, state, type,
447 ice_label_enum_handler);
451 *value = LE16_TO_CPU(label->value);
457 * @hw: pointer to the HW structure
458 * @ice_seg: pointer to the segment of the package scan (non-NULL)
460 * This function will scan the package and save off relevant information
461 * (hints or metadata) for driver use. The ice_seg parameter must not be NULL
462 * since the first call to ice_enum_labels requires a pointer to an actual
465 static void ice_init_pkg_hints(struct ice_hw *hw, struct ice_seg *ice_seg)
467 struct ice_pkg_enum state;
472 ice_memset(&hw->tnl, 0, sizeof(hw->tnl), ICE_NONDMA_MEM);
473 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
478 label_name = ice_enum_labels(ice_seg, ICE_SID_LBL_RXPARSER_TMEM, &state,
481 while (label_name && hw->tnl.count < ICE_TUNNEL_MAX_ENTRIES) {
482 for (i = 0; tnls[i].type != TNL_LAST; i++) {
483 size_t len = strlen(tnls[i].label_prefix);
485 /* Look for matching label start, before continuing */
486 if (strncmp(label_name, tnls[i].label_prefix, len))
489 /* Make sure this label matches our PF. Note that the PF
490 * character ('0' - '7') will be located where our
491 * prefix string's null terminator is located.
493 if ((label_name[len] - '0') == hw->pf_id) {
494 hw->tnl.tbl[hw->tnl.count].type = tnls[i].type;
495 hw->tnl.tbl[hw->tnl.count].valid = false;
496 hw->tnl.tbl[hw->tnl.count].in_use = false;
497 hw->tnl.tbl[hw->tnl.count].marked = false;
498 hw->tnl.tbl[hw->tnl.count].boost_addr = val;
499 hw->tnl.tbl[hw->tnl.count].port = 0;
505 label_name = ice_enum_labels(NULL, 0, &state, &val);
508 /* Cache the appropriate boost TCAM entry pointers */
509 for (i = 0; i < hw->tnl.count; i++) {
510 ice_find_boost_entry(ice_seg, hw->tnl.tbl[i].boost_addr,
511 &hw->tnl.tbl[i].boost_entry);
512 if (hw->tnl.tbl[i].boost_entry)
513 hw->tnl.tbl[i].valid = true;
519 #define ICE_DC_KEY 0x1 /* don't care */
520 #define ICE_DC_KEYINV 0x1
521 #define ICE_NM_KEY 0x0 /* never match */
522 #define ICE_NM_KEYINV 0x0
523 #define ICE_0_KEY 0x1 /* match 0 */
524 #define ICE_0_KEYINV 0x0
525 #define ICE_1_KEY 0x0 /* match 1 */
526 #define ICE_1_KEYINV 0x1
529 * ice_gen_key_word - generate 16-bits of a key/mask word
531 * @valid: valid bits mask (change only the valid bits)
532 * @dont_care: don't care mask
533 * @nvr_mtch: never match mask
534 * @key: pointer to an array of where the resulting key portion
535 * @key_inv: pointer to an array of where the resulting key invert portion
537 * This function generates 16-bits from a 8-bit value, an 8-bit don't care mask
538 * and an 8-bit never match mask. The 16-bits of output are divided into 8 bits
539 * of key and 8 bits of key invert.
541 * '0' = b01, always match a 0 bit
542 * '1' = b10, always match a 1 bit
543 * '?' = b11, don't care bit (always matches)
544 * '~' = b00, never match bit
548 * dont_care: b0 0 1 1 0 0
549 * never_mtch: b0 0 0 0 1 1
550 * ------------------------------
551 * Result: key: b01 10 11 11 00 00
553 static enum ice_status
554 ice_gen_key_word(u8 val, u8 valid, u8 dont_care, u8 nvr_mtch, u8 *key,
557 u8 in_key = *key, in_key_inv = *key_inv;
560 /* 'dont_care' and 'nvr_mtch' masks cannot overlap */
561 if ((dont_care ^ nvr_mtch) != (dont_care | nvr_mtch))
567 /* encode the 8 bits into 8-bit key and 8-bit key invert */
568 for (i = 0; i < 8; i++) {
572 if (!(valid & 0x1)) { /* change only valid bits */
573 *key |= (in_key & 0x1) << 7;
574 *key_inv |= (in_key_inv & 0x1) << 7;
575 } else if (dont_care & 0x1) { /* don't care bit */
576 *key |= ICE_DC_KEY << 7;
577 *key_inv |= ICE_DC_KEYINV << 7;
578 } else if (nvr_mtch & 0x1) { /* never match bit */
579 *key |= ICE_NM_KEY << 7;
580 *key_inv |= ICE_NM_KEYINV << 7;
581 } else if (val & 0x01) { /* exact 1 match */
582 *key |= ICE_1_KEY << 7;
583 *key_inv |= ICE_1_KEYINV << 7;
584 } else { /* exact 0 match */
585 *key |= ICE_0_KEY << 7;
586 *key_inv |= ICE_0_KEYINV << 7;
601 * ice_bits_max_set - determine if the number of bits set is within a maximum
602 * @mask: pointer to the byte array which is the mask
603 * @size: the number of bytes in the mask
604 * @max: the max number of set bits
606 * This function determines if there are at most 'max' number of bits set in an
607 * array. Returns true if the number for bits set is <= max or will return false
610 static bool ice_bits_max_set(const u8 *mask, u16 size, u16 max)
615 /* check each byte */
616 for (i = 0; i < size; i++) {
617 /* if 0, go to next byte */
621 /* We know there is at least one set bit in this byte because of
622 * the above check; if we already have found 'max' number of
623 * bits set, then we can return failure now.
628 /* count the bits in this byte, checking threshold */
629 count += ice_hweight8(mask[i]);
638 * ice_set_key - generate a variable sized key with multiples of 16-bits
639 * @key: pointer to where the key will be stored
640 * @size: the size of the complete key in bytes (must be even)
641 * @val: array of 8-bit values that makes up the value portion of the key
642 * @upd: array of 8-bit masks that determine what key portion to update
643 * @dc: array of 8-bit masks that make up the don't care mask
644 * @nm: array of 8-bit masks that make up the never match mask
645 * @off: the offset of the first byte in the key to update
646 * @len: the number of bytes in the key update
648 * This function generates a key from a value, a don't care mask and a never
650 * upd, dc, and nm are optional parameters, and can be NULL:
651 * upd == NULL --> upd mask is all 1's (update all bits)
652 * dc == NULL --> dc mask is all 0's (no don't care bits)
653 * nm == NULL --> nm mask is all 0's (no never match bits)
656 ice_set_key(u8 *key, u16 size, u8 *val, u8 *upd, u8 *dc, u8 *nm, u16 off,
662 /* size must be a multiple of 2 bytes. */
665 half_size = size / 2;
667 if (off + len > half_size)
670 /* Make sure at most one bit is set in the never match mask. Having more
671 * than one never match mask bit set will cause HW to consume excessive
672 * power otherwise; this is a power management efficiency check.
674 #define ICE_NVR_MTCH_BITS_MAX 1
675 if (nm && !ice_bits_max_set(nm, len, ICE_NVR_MTCH_BITS_MAX))
678 for (i = 0; i < len; i++)
679 if (ice_gen_key_word(val[i], upd ? upd[i] : 0xff,
680 dc ? dc[i] : 0, nm ? nm[i] : 0,
681 key + off + i, key + half_size + off + i))
688 * ice_acquire_global_cfg_lock
689 * @hw: pointer to the HW structure
690 * @access: access type (read or write)
692 * This function will request ownership of the global config lock for reading
693 * or writing of the package. When attempting to obtain write access, the
694 * caller must check for the following two return values:
696 * ICE_SUCCESS - Means the caller has acquired the global config lock
697 * and can perform writing of the package.
698 * ICE_ERR_AQ_NO_WORK - Indicates another driver has already written the
699 * package or has found that no update was necessary; in
700 * this case, the caller can just skip performing any
701 * update of the package.
703 static enum ice_status
704 ice_acquire_global_cfg_lock(struct ice_hw *hw,
705 enum ice_aq_res_access_type access)
707 enum ice_status status;
709 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
711 status = ice_acquire_res(hw, ICE_GLOBAL_CFG_LOCK_RES_ID, access,
712 ICE_GLOBAL_CFG_LOCK_TIMEOUT);
714 if (status == ICE_ERR_AQ_NO_WORK)
715 ice_debug(hw, ICE_DBG_PKG, "Global config lock: No work to do\n");
721 * ice_release_global_cfg_lock
722 * @hw: pointer to the HW structure
724 * This function will release the global config lock.
726 static void ice_release_global_cfg_lock(struct ice_hw *hw)
728 ice_release_res(hw, ICE_GLOBAL_CFG_LOCK_RES_ID);
732 * ice_acquire_change_lock
733 * @hw: pointer to the HW structure
734 * @access: access type (read or write)
736 * This function will request ownership of the change lock.
739 ice_acquire_change_lock(struct ice_hw *hw, enum ice_aq_res_access_type access)
741 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
743 return ice_acquire_res(hw, ICE_CHANGE_LOCK_RES_ID, access,
744 ICE_CHANGE_LOCK_TIMEOUT);
748 * ice_release_change_lock
749 * @hw: pointer to the HW structure
751 * This function will release the change lock using the proper Admin Command.
753 void ice_release_change_lock(struct ice_hw *hw)
755 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
757 ice_release_res(hw, ICE_CHANGE_LOCK_RES_ID);
761 * ice_aq_download_pkg
762 * @hw: pointer to the hardware structure
763 * @pkg_buf: the package buffer to transfer
764 * @buf_size: the size of the package buffer
765 * @last_buf: last buffer indicator
766 * @error_offset: returns error offset
767 * @error_info: returns error information
768 * @cd: pointer to command details structure or NULL
770 * Download Package (0x0C40)
772 static enum ice_status
773 ice_aq_download_pkg(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf,
774 u16 buf_size, bool last_buf, u32 *error_offset,
775 u32 *error_info, struct ice_sq_cd *cd)
777 struct ice_aqc_download_pkg *cmd;
778 struct ice_aq_desc desc;
779 enum ice_status status;
781 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
788 cmd = &desc.params.download_pkg;
789 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_download_pkg);
790 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
793 cmd->flags |= ICE_AQC_DOWNLOAD_PKG_LAST_BUF;
795 status = ice_aq_send_cmd(hw, &desc, pkg_buf, buf_size, cd);
796 if (status == ICE_ERR_AQ_ERROR) {
797 /* Read error from buffer only when the FW returned an error */
798 struct ice_aqc_download_pkg_resp *resp;
800 resp = (struct ice_aqc_download_pkg_resp *)pkg_buf;
802 *error_offset = LE32_TO_CPU(resp->error_offset);
804 *error_info = LE32_TO_CPU(resp->error_info);
812 * @hw: pointer to the hardware structure
813 * @pkg_buf: the package cmd buffer
814 * @buf_size: the size of the package cmd buffer
815 * @last_buf: last buffer indicator
816 * @error_offset: returns error offset
817 * @error_info: returns error information
818 * @cd: pointer to command details structure or NULL
820 * Update Package (0x0C42)
822 static enum ice_status
823 ice_aq_update_pkg(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf, u16 buf_size,
824 bool last_buf, u32 *error_offset, u32 *error_info,
825 struct ice_sq_cd *cd)
827 struct ice_aqc_download_pkg *cmd;
828 struct ice_aq_desc desc;
829 enum ice_status status;
831 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
838 cmd = &desc.params.download_pkg;
839 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_update_pkg);
840 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
843 cmd->flags |= ICE_AQC_DOWNLOAD_PKG_LAST_BUF;
845 status = ice_aq_send_cmd(hw, &desc, pkg_buf, buf_size, cd);
846 if (status == ICE_ERR_AQ_ERROR) {
847 /* Read error from buffer only when the FW returned an error */
848 struct ice_aqc_download_pkg_resp *resp;
850 resp = (struct ice_aqc_download_pkg_resp *)pkg_buf;
852 *error_offset = LE32_TO_CPU(resp->error_offset);
854 *error_info = LE32_TO_CPU(resp->error_info);
861 * ice_find_seg_in_pkg
862 * @hw: pointer to the hardware structure
863 * @seg_type: the segment type to search for (i.e., SEGMENT_TYPE_CPK)
864 * @pkg_hdr: pointer to the package header to be searched
866 * This function searches a package file for a particular segment type. On
867 * success it returns a pointer to the segment header, otherwise it will
870 static struct ice_generic_seg_hdr *
871 ice_find_seg_in_pkg(struct ice_hw *hw, u32 seg_type,
872 struct ice_pkg_hdr *pkg_hdr)
876 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
877 ice_debug(hw, ICE_DBG_PKG, "Package format version: %d.%d.%d.%d\n",
878 pkg_hdr->pkg_format_ver.major, pkg_hdr->pkg_format_ver.minor,
879 pkg_hdr->pkg_format_ver.update,
880 pkg_hdr->pkg_format_ver.draft);
882 /* Search all package segments for the requested segment type */
883 for (i = 0; i < LE32_TO_CPU(pkg_hdr->seg_count); i++) {
884 struct ice_generic_seg_hdr *seg;
886 seg = (struct ice_generic_seg_hdr *)
887 ((u8 *)pkg_hdr + LE32_TO_CPU(pkg_hdr->seg_offset[i]));
889 if (LE32_TO_CPU(seg->seg_type) == seg_type)
898 * @hw: pointer to the hardware structure
899 * @bufs: pointer to an array of buffers
900 * @count: the number of buffers in the array
902 * Obtains change lock and updates package.
905 ice_update_pkg(struct ice_hw *hw, struct ice_buf *bufs, u32 count)
907 enum ice_status status;
910 status = ice_acquire_change_lock(hw, ICE_RES_WRITE);
914 for (i = 0; i < count; i++) {
915 struct ice_buf_hdr *bh = (struct ice_buf_hdr *)(bufs + i);
916 bool last = ((i + 1) == count);
918 status = ice_aq_update_pkg(hw, bh, LE16_TO_CPU(bh->data_end),
919 last, &offset, &info, NULL);
922 ice_debug(hw, ICE_DBG_PKG, "Update pkg failed: err %d off %d inf %d\n",
923 status, offset, info);
928 ice_release_change_lock(hw);
935 * @hw: pointer to the hardware structure
936 * @bufs: pointer to an array of buffers
937 * @count: the number of buffers in the array
939 * Obtains global config lock and downloads the package configuration buffers
940 * to the firmware. Metadata buffers are skipped, and the first metadata buffer
941 * found indicates that the rest of the buffers are all metadata buffers.
943 static enum ice_status
944 ice_dwnld_cfg_bufs(struct ice_hw *hw, struct ice_buf *bufs, u32 count)
946 enum ice_status status;
947 struct ice_buf_hdr *bh;
951 return ICE_ERR_PARAM;
953 /* If the first buffer's first section has its metadata bit set
954 * then there are no buffers to be downloaded, and the operation is
955 * considered a success.
957 bh = (struct ice_buf_hdr *)bufs;
958 if (LE32_TO_CPU(bh->section_entry[0].type) & ICE_METADATA_BUF)
961 /* reset pkg_dwnld_status in case this function is called in the
964 hw->pkg_dwnld_status = ICE_AQ_RC_OK;
966 status = ice_acquire_global_cfg_lock(hw, ICE_RES_WRITE);
968 if (status == ICE_ERR_AQ_NO_WORK)
969 hw->pkg_dwnld_status = ICE_AQ_RC_EEXIST;
971 hw->pkg_dwnld_status = hw->adminq.sq_last_status;
975 for (i = 0; i < count; i++) {
976 bool last = ((i + 1) == count);
979 /* check next buffer for metadata flag */
980 bh = (struct ice_buf_hdr *)(bufs + i + 1);
982 /* A set metadata flag in the next buffer will signal
983 * that the current buffer will be the last buffer
986 if (LE16_TO_CPU(bh->section_count))
987 if (LE32_TO_CPU(bh->section_entry[0].type) &
992 bh = (struct ice_buf_hdr *)(bufs + i);
994 status = ice_aq_download_pkg(hw, bh, ICE_PKG_BUF_SIZE, last,
995 &offset, &info, NULL);
997 /* Save AQ status from download package */
998 hw->pkg_dwnld_status = hw->adminq.sq_last_status;
1000 ice_debug(hw, ICE_DBG_PKG, "Pkg download failed: err %d off %d inf %d\n",
1001 status, offset, info);
1010 status = ice_set_vlan_mode(hw);
1012 ice_debug(hw, ICE_DBG_PKG, "Failed to set VLAN mode: err %d\n",
1016 ice_release_global_cfg_lock(hw);
1022 * ice_aq_get_pkg_info_list
1023 * @hw: pointer to the hardware structure
1024 * @pkg_info: the buffer which will receive the information list
1025 * @buf_size: the size of the pkg_info information buffer
1026 * @cd: pointer to command details structure or NULL
1028 * Get Package Info List (0x0C43)
1030 static enum ice_status
1031 ice_aq_get_pkg_info_list(struct ice_hw *hw,
1032 struct ice_aqc_get_pkg_info_resp *pkg_info,
1033 u16 buf_size, struct ice_sq_cd *cd)
1035 struct ice_aq_desc desc;
1037 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1038 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_pkg_info_list);
1040 return ice_aq_send_cmd(hw, &desc, pkg_info, buf_size, cd);
1045 * @hw: pointer to the hardware structure
1046 * @ice_seg: pointer to the segment of the package to be downloaded
1048 * Handles the download of a complete package.
1050 static enum ice_status
1051 ice_download_pkg(struct ice_hw *hw, struct ice_seg *ice_seg)
1053 struct ice_buf_table *ice_buf_tbl;
1055 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1056 ice_debug(hw, ICE_DBG_PKG, "Segment format version: %d.%d.%d.%d\n",
1057 ice_seg->hdr.seg_format_ver.major,
1058 ice_seg->hdr.seg_format_ver.minor,
1059 ice_seg->hdr.seg_format_ver.update,
1060 ice_seg->hdr.seg_format_ver.draft);
1062 ice_debug(hw, ICE_DBG_PKG, "Seg: type 0x%X, size %d, name %s\n",
1063 LE32_TO_CPU(ice_seg->hdr.seg_type),
1064 LE32_TO_CPU(ice_seg->hdr.seg_size), ice_seg->hdr.seg_id);
1066 ice_buf_tbl = ice_find_buf_table(ice_seg);
1068 ice_debug(hw, ICE_DBG_PKG, "Seg buf count: %d\n",
1069 LE32_TO_CPU(ice_buf_tbl->buf_count));
1071 return ice_dwnld_cfg_bufs(hw, ice_buf_tbl->buf_array,
1072 LE32_TO_CPU(ice_buf_tbl->buf_count));
1077 * @hw: pointer to the hardware structure
1078 * @pkg_hdr: pointer to the driver's package hdr
1080 * Saves off the package details into the HW structure.
1082 static enum ice_status
1083 ice_init_pkg_info(struct ice_hw *hw, struct ice_pkg_hdr *pkg_hdr)
1085 struct ice_generic_seg_hdr *seg_hdr;
1087 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1089 return ICE_ERR_PARAM;
1091 seg_hdr = (struct ice_generic_seg_hdr *)
1092 ice_find_seg_in_pkg(hw, SEGMENT_TYPE_ICE, pkg_hdr);
1094 struct ice_meta_sect *meta;
1095 struct ice_pkg_enum state;
1097 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1099 /* Get package information from the Metadata Section */
1100 meta = (struct ice_meta_sect *)
1101 ice_pkg_enum_section((struct ice_seg *)seg_hdr, &state,
1104 ice_debug(hw, ICE_DBG_INIT, "Did not find ice metadata section in package\n");
1108 hw->pkg_ver = meta->ver;
1109 ice_memcpy(hw->pkg_name, meta->name, sizeof(meta->name),
1110 ICE_NONDMA_TO_NONDMA);
1112 ice_debug(hw, ICE_DBG_PKG, "Pkg: %d.%d.%d.%d, %s\n",
1113 meta->ver.major, meta->ver.minor, meta->ver.update,
1114 meta->ver.draft, meta->name);
1116 hw->ice_seg_fmt_ver = seg_hdr->seg_format_ver;
1117 ice_memcpy(hw->ice_seg_id, seg_hdr->seg_id,
1118 sizeof(hw->ice_seg_id), ICE_NONDMA_TO_NONDMA);
1120 ice_debug(hw, ICE_DBG_PKG, "Ice Seg: %d.%d.%d.%d, %s\n",
1121 seg_hdr->seg_format_ver.major,
1122 seg_hdr->seg_format_ver.minor,
1123 seg_hdr->seg_format_ver.update,
1124 seg_hdr->seg_format_ver.draft,
1127 ice_debug(hw, ICE_DBG_INIT, "Did not find ice segment in driver package\n");
1136 * @hw: pointer to the hardware structure
1138 * Store details of the package currently loaded in HW into the HW structure.
1140 static enum ice_status ice_get_pkg_info(struct ice_hw *hw)
1142 struct ice_aqc_get_pkg_info_resp *pkg_info;
1143 enum ice_status status;
1147 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1149 size = ice_struct_size(pkg_info, pkg_info, ICE_PKG_CNT);
1150 pkg_info = (struct ice_aqc_get_pkg_info_resp *)ice_malloc(hw, size);
1152 return ICE_ERR_NO_MEMORY;
1154 status = ice_aq_get_pkg_info_list(hw, pkg_info, size, NULL);
1156 goto init_pkg_free_alloc;
1158 for (i = 0; i < LE32_TO_CPU(pkg_info->count); i++) {
1159 #define ICE_PKG_FLAG_COUNT 4
1160 char flags[ICE_PKG_FLAG_COUNT + 1] = { 0 };
1163 if (pkg_info->pkg_info[i].is_active) {
1164 flags[place++] = 'A';
1165 hw->active_pkg_ver = pkg_info->pkg_info[i].ver;
1166 hw->active_track_id =
1167 LE32_TO_CPU(pkg_info->pkg_info[i].track_id);
1168 ice_memcpy(hw->active_pkg_name,
1169 pkg_info->pkg_info[i].name,
1170 sizeof(pkg_info->pkg_info[i].name),
1171 ICE_NONDMA_TO_NONDMA);
1172 hw->active_pkg_in_nvm = pkg_info->pkg_info[i].is_in_nvm;
1174 if (pkg_info->pkg_info[i].is_active_at_boot)
1175 flags[place++] = 'B';
1176 if (pkg_info->pkg_info[i].is_modified)
1177 flags[place++] = 'M';
1178 if (pkg_info->pkg_info[i].is_in_nvm)
1179 flags[place++] = 'N';
1181 ice_debug(hw, ICE_DBG_PKG, "Pkg[%d]: %d.%d.%d.%d,%s,%s\n",
1182 i, pkg_info->pkg_info[i].ver.major,
1183 pkg_info->pkg_info[i].ver.minor,
1184 pkg_info->pkg_info[i].ver.update,
1185 pkg_info->pkg_info[i].ver.draft,
1186 pkg_info->pkg_info[i].name, flags);
1189 init_pkg_free_alloc:
1190 ice_free(hw, pkg_info);
1196 * ice_verify_pkg - verify package
1197 * @pkg: pointer to the package buffer
1198 * @len: size of the package buffer
1200 * Verifies various attributes of the package file, including length, format
1201 * version, and the requirement of at least one segment.
1203 static enum ice_status ice_verify_pkg(struct ice_pkg_hdr *pkg, u32 len)
1208 if (len < ice_struct_size(pkg, seg_offset, 1))
1209 return ICE_ERR_BUF_TOO_SHORT;
1211 if (pkg->pkg_format_ver.major != ICE_PKG_FMT_VER_MAJ ||
1212 pkg->pkg_format_ver.minor != ICE_PKG_FMT_VER_MNR ||
1213 pkg->pkg_format_ver.update != ICE_PKG_FMT_VER_UPD ||
1214 pkg->pkg_format_ver.draft != ICE_PKG_FMT_VER_DFT)
1217 /* pkg must have at least one segment */
1218 seg_count = LE32_TO_CPU(pkg->seg_count);
1222 /* make sure segment array fits in package length */
1223 if (len < ice_struct_size(pkg, seg_offset, seg_count))
1224 return ICE_ERR_BUF_TOO_SHORT;
1226 /* all segments must fit within length */
1227 for (i = 0; i < seg_count; i++) {
1228 u32 off = LE32_TO_CPU(pkg->seg_offset[i]);
1229 struct ice_generic_seg_hdr *seg;
1231 /* segment header must fit */
1232 if (len < off + sizeof(*seg))
1233 return ICE_ERR_BUF_TOO_SHORT;
1235 seg = (struct ice_generic_seg_hdr *)((u8 *)pkg + off);
1237 /* segment body must fit */
1238 if (len < off + LE32_TO_CPU(seg->seg_size))
1239 return ICE_ERR_BUF_TOO_SHORT;
1246 * ice_free_seg - free package segment pointer
1247 * @hw: pointer to the hardware structure
1249 * Frees the package segment pointer in the proper manner, depending on if the
1250 * segment was allocated or just the passed in pointer was stored.
1252 void ice_free_seg(struct ice_hw *hw)
1255 ice_free(hw, hw->pkg_copy);
1256 hw->pkg_copy = NULL;
1263 * ice_init_pkg_regs - initialize additional package registers
1264 * @hw: pointer to the hardware structure
1266 static void ice_init_pkg_regs(struct ice_hw *hw)
1268 #define ICE_SW_BLK_INP_MASK_L 0xFFFFFFFF
1269 #define ICE_SW_BLK_INP_MASK_H 0x0000FFFF
1270 #define ICE_SW_BLK_IDX 0
1271 if (hw->dcf_enabled)
1274 /* setup Switch block input mask, which is 48-bits in two parts */
1275 wr32(hw, GL_PREEXT_L2_PMASK0(ICE_SW_BLK_IDX), ICE_SW_BLK_INP_MASK_L);
1276 wr32(hw, GL_PREEXT_L2_PMASK1(ICE_SW_BLK_IDX), ICE_SW_BLK_INP_MASK_H);
1280 * ice_chk_pkg_version - check package version for compatibility with driver
1281 * @pkg_ver: pointer to a version structure to check
1283 * Check to make sure that the package about to be downloaded is compatible with
1284 * the driver. To be compatible, the major and minor components of the package
1285 * version must match our ICE_PKG_SUPP_VER_MAJ and ICE_PKG_SUPP_VER_MNR
1288 static enum ice_status ice_chk_pkg_version(struct ice_pkg_ver *pkg_ver)
1290 if (pkg_ver->major != ICE_PKG_SUPP_VER_MAJ ||
1291 pkg_ver->minor != ICE_PKG_SUPP_VER_MNR)
1292 return ICE_ERR_NOT_SUPPORTED;
1298 * ice_chk_pkg_compat
1299 * @hw: pointer to the hardware structure
1300 * @ospkg: pointer to the package hdr
1301 * @seg: pointer to the package segment hdr
1303 * This function checks the package version compatibility with driver and NVM
1305 static enum ice_status
1306 ice_chk_pkg_compat(struct ice_hw *hw, struct ice_pkg_hdr *ospkg,
1307 struct ice_seg **seg)
1309 struct ice_aqc_get_pkg_info_resp *pkg;
1310 enum ice_status status;
1314 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1316 /* Check package version compatibility */
1317 status = ice_chk_pkg_version(&hw->pkg_ver);
1319 ice_debug(hw, ICE_DBG_INIT, "Package version check failed.\n");
1323 /* find ICE segment in given package */
1324 *seg = (struct ice_seg *)ice_find_seg_in_pkg(hw, SEGMENT_TYPE_ICE,
1327 ice_debug(hw, ICE_DBG_INIT, "no ice segment in package.\n");
1331 /* Check if FW is compatible with the OS package */
1332 size = ice_struct_size(pkg, pkg_info, ICE_PKG_CNT);
1333 pkg = (struct ice_aqc_get_pkg_info_resp *)ice_malloc(hw, size);
1335 return ICE_ERR_NO_MEMORY;
1337 status = ice_aq_get_pkg_info_list(hw, pkg, size, NULL);
1339 goto fw_ddp_compat_free_alloc;
1341 for (i = 0; i < LE32_TO_CPU(pkg->count); i++) {
1342 /* loop till we find the NVM package */
1343 if (!pkg->pkg_info[i].is_in_nvm)
1345 if ((*seg)->hdr.seg_format_ver.major !=
1346 pkg->pkg_info[i].ver.major ||
1347 (*seg)->hdr.seg_format_ver.minor >
1348 pkg->pkg_info[i].ver.minor) {
1349 status = ICE_ERR_FW_DDP_MISMATCH;
1350 ice_debug(hw, ICE_DBG_INIT, "OS package is not compatible with NVM.\n");
1352 /* done processing NVM package so break */
1355 fw_ddp_compat_free_alloc:
1362 * @sect_type: section type
1363 * @section: pointer to section
1364 * @index: index of the field vector entry to be returned
1365 * @offset: ptr to variable that receives the offset in the field vector table
1367 * This is a callback function that can be passed to ice_pkg_enum_entry.
1368 * This function treats the given section as of type ice_sw_fv_section and
1369 * enumerates offset field. "offset" is an index into the field vector table.
1372 ice_sw_fv_handler(u32 sect_type, void *section, u32 index, u32 *offset)
1374 struct ice_sw_fv_section *fv_section =
1375 (struct ice_sw_fv_section *)section;
1377 if (!section || sect_type != ICE_SID_FLD_VEC_SW)
1379 if (index >= LE16_TO_CPU(fv_section->count))
1382 /* "index" passed in to this function is relative to a given
1383 * 4k block. To get to the true index into the field vector
1384 * table need to add the relative index to the base_offset
1385 * field of this section
1387 *offset = LE16_TO_CPU(fv_section->base_offset) + index;
1388 return fv_section->fv + index;
1392 * ice_get_prof_index_max - get the max profile index for used profile
1393 * @hw: pointer to the HW struct
1395 * Calling this function will get the max profile index for used profile
1396 * and store the index number in struct ice_switch_info *switch_info
1397 * in hw for following use.
1399 static int ice_get_prof_index_max(struct ice_hw *hw)
1401 u16 prof_index = 0, j, max_prof_index = 0;
1402 struct ice_pkg_enum state;
1403 struct ice_seg *ice_seg;
1408 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1411 return ICE_ERR_PARAM;
1416 fv = (struct ice_fv *)
1417 ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1418 &offset, ice_sw_fv_handler);
1423 /* in the profile that not be used, the prot_id is set to 0xff
1424 * and the off is set to 0x1ff for all the field vectors.
1426 for (j = 0; j < hw->blk[ICE_BLK_SW].es.fvw; j++)
1427 if (fv->ew[j].prot_id != ICE_PROT_INVALID ||
1428 fv->ew[j].off != ICE_FV_OFFSET_INVAL)
1430 if (flag && prof_index > max_prof_index)
1431 max_prof_index = prof_index;
1437 hw->switch_info->max_used_prof_index = max_prof_index;
1443 * ice_init_pkg - initialize/download package
1444 * @hw: pointer to the hardware structure
1445 * @buf: pointer to the package buffer
1446 * @len: size of the package buffer
1448 * This function initializes a package. The package contains HW tables
1449 * required to do packet processing. First, the function extracts package
1450 * information such as version. Then it finds the ice configuration segment
1451 * within the package; this function then saves a copy of the segment pointer
1452 * within the supplied package buffer. Next, the function will cache any hints
1453 * from the package, followed by downloading the package itself. Note, that if
1454 * a previous PF driver has already downloaded the package successfully, then
1455 * the current driver will not have to download the package again.
1457 * The local package contents will be used to query default behavior and to
1458 * update specific sections of the HW's version of the package (e.g. to update
1459 * the parse graph to understand new protocols).
1461 * This function stores a pointer to the package buffer memory, and it is
1462 * expected that the supplied buffer will not be freed immediately. If the
1463 * package buffer needs to be freed, such as when read from a file, use
1464 * ice_copy_and_init_pkg() instead of directly calling ice_init_pkg() in this
1467 enum ice_status ice_init_pkg(struct ice_hw *hw, u8 *buf, u32 len)
1469 struct ice_pkg_hdr *pkg;
1470 enum ice_status status;
1471 struct ice_seg *seg;
1474 return ICE_ERR_PARAM;
1476 pkg = (struct ice_pkg_hdr *)buf;
1477 status = ice_verify_pkg(pkg, len);
1479 ice_debug(hw, ICE_DBG_INIT, "failed to verify pkg (err: %d)\n",
1484 /* initialize package info */
1485 status = ice_init_pkg_info(hw, pkg);
1489 /* before downloading the package, check package version for
1490 * compatibility with driver
1492 status = ice_chk_pkg_compat(hw, pkg, &seg);
1496 /* initialize package hints and then download package */
1497 ice_init_pkg_hints(hw, seg);
1498 status = ice_download_pkg(hw, seg);
1499 if (status == ICE_ERR_AQ_NO_WORK) {
1500 ice_debug(hw, ICE_DBG_INIT, "package previously loaded - no work.\n");
1501 status = ICE_SUCCESS;
1504 /* Get information on the package currently loaded in HW, then make sure
1505 * the driver is compatible with this version.
1508 status = ice_get_pkg_info(hw);
1510 status = ice_chk_pkg_version(&hw->active_pkg_ver);
1515 /* on successful package download update other required
1516 * registers to support the package and fill HW tables
1517 * with package content.
1519 ice_init_pkg_regs(hw);
1520 ice_fill_blk_tbls(hw);
1521 ice_get_prof_index_max(hw);
1523 ice_debug(hw, ICE_DBG_INIT, "package load failed, %d\n",
1531 * ice_copy_and_init_pkg - initialize/download a copy of the package
1532 * @hw: pointer to the hardware structure
1533 * @buf: pointer to the package buffer
1534 * @len: size of the package buffer
1536 * This function copies the package buffer, and then calls ice_init_pkg() to
1537 * initialize the copied package contents.
1539 * The copying is necessary if the package buffer supplied is constant, or if
1540 * the memory may disappear shortly after calling this function.
1542 * If the package buffer resides in the data segment and can be modified, the
1543 * caller is free to use ice_init_pkg() instead of ice_copy_and_init_pkg().
1545 * However, if the package buffer needs to be copied first, such as when being
1546 * read from a file, the caller should use ice_copy_and_init_pkg().
1548 * This function will first copy the package buffer, before calling
1549 * ice_init_pkg(). The caller is free to immediately destroy the original
1550 * package buffer, as the new copy will be managed by this function and
1553 enum ice_status ice_copy_and_init_pkg(struct ice_hw *hw, const u8 *buf, u32 len)
1555 enum ice_status status;
1559 return ICE_ERR_PARAM;
1561 buf_copy = (u8 *)ice_memdup(hw, buf, len, ICE_NONDMA_TO_NONDMA);
1563 status = ice_init_pkg(hw, buf_copy, len);
1565 /* Free the copy, since we failed to initialize the package */
1566 ice_free(hw, buf_copy);
1568 /* Track the copied pkg so we can free it later */
1569 hw->pkg_copy = buf_copy;
1578 * @hw: pointer to the HW structure
1580 * Allocates a package buffer and returns a pointer to the buffer header.
1581 * Note: all package contents must be in Little Endian form.
1583 static struct ice_buf_build *ice_pkg_buf_alloc(struct ice_hw *hw)
1585 struct ice_buf_build *bld;
1586 struct ice_buf_hdr *buf;
1588 bld = (struct ice_buf_build *)ice_malloc(hw, sizeof(*bld));
1592 buf = (struct ice_buf_hdr *)bld;
1593 buf->data_end = CPU_TO_LE16(offsetof(struct ice_buf_hdr,
1599 * ice_get_sw_prof_type - determine switch profile type
1600 * @hw: pointer to the HW structure
1601 * @fv: pointer to the switch field vector
1603 static enum ice_prof_type
1604 ice_get_sw_prof_type(struct ice_hw *hw, struct ice_fv *fv)
1608 for (i = 0; i < hw->blk[ICE_BLK_SW].es.fvw; i++) {
1609 /* UDP tunnel will have UDP_OF protocol ID and VNI offset */
1610 if (fv->ew[i].prot_id == (u8)ICE_PROT_UDP_OF &&
1611 fv->ew[i].off == ICE_VNI_OFFSET)
1612 return ICE_PROF_TUN_UDP;
1614 /* GRE tunnel will have GRE protocol */
1615 if (fv->ew[i].prot_id == (u8)ICE_PROT_GRE_OF)
1616 return ICE_PROF_TUN_GRE;
1618 /* PPPOE tunnel will have PPPOE protocol */
1619 if (fv->ew[i].prot_id == (u8)ICE_PROT_PPPOE)
1620 return ICE_PROF_TUN_PPPOE;
1623 return ICE_PROF_NON_TUN;
1627 * ice_get_sw_fv_bitmap - Get switch field vector bitmap based on profile type
1628 * @hw: pointer to hardware structure
1629 * @req_profs: type of profiles requested
1630 * @bm: pointer to memory for returning the bitmap of field vectors
1633 ice_get_sw_fv_bitmap(struct ice_hw *hw, enum ice_prof_type req_profs,
1636 struct ice_pkg_enum state;
1637 struct ice_seg *ice_seg;
1640 if (req_profs == ICE_PROF_ALL) {
1641 ice_bitmap_set(bm, 0, ICE_MAX_NUM_PROFILES);
1645 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1646 ice_zero_bitmap(bm, ICE_MAX_NUM_PROFILES);
1649 enum ice_prof_type prof_type;
1652 fv = (struct ice_fv *)
1653 ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1654 &offset, ice_sw_fv_handler);
1658 /* Determine field vector type */
1659 prof_type = ice_get_sw_prof_type(hw, fv);
1661 if (req_profs & prof_type)
1662 ice_set_bit((u16)offset, bm);
1668 * ice_get_sw_fv_list
1669 * @hw: pointer to the HW structure
1670 * @prot_ids: field vector to search for with a given protocol ID
1671 * @ids_cnt: lookup/protocol count
1672 * @bm: bitmap of field vectors to consider
1673 * @fv_list: Head of a list
1675 * Finds all the field vector entries from switch block that contain
1676 * a given protocol ID and returns a list of structures of type
1677 * "ice_sw_fv_list_entry". Every structure in the list has a field vector
1678 * definition and profile ID information
1679 * NOTE: The caller of the function is responsible for freeing the memory
1680 * allocated for every list entry.
1683 ice_get_sw_fv_list(struct ice_hw *hw, u8 *prot_ids, u16 ids_cnt,
1684 ice_bitmap_t *bm, struct LIST_HEAD_TYPE *fv_list)
1686 struct ice_sw_fv_list_entry *fvl;
1687 struct ice_sw_fv_list_entry *tmp;
1688 struct ice_pkg_enum state;
1689 struct ice_seg *ice_seg;
1693 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1695 if (!ids_cnt || !hw->seg)
1696 return ICE_ERR_PARAM;
1702 fv = (struct ice_fv *)
1703 ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1704 &offset, ice_sw_fv_handler);
1709 /* If field vector is not in the bitmap list, then skip this
1712 if (!ice_is_bit_set(bm, (u16)offset))
1715 for (i = 0; i < ids_cnt; i++) {
1718 /* This code assumes that if a switch field vector line
1719 * has a matching protocol, then this line will contain
1720 * the entries necessary to represent every field in
1721 * that protocol header.
1723 for (j = 0; j < hw->blk[ICE_BLK_SW].es.fvw; j++)
1724 if (fv->ew[j].prot_id == prot_ids[i])
1726 if (j >= hw->blk[ICE_BLK_SW].es.fvw)
1728 if (i + 1 == ids_cnt) {
1729 fvl = (struct ice_sw_fv_list_entry *)
1730 ice_malloc(hw, sizeof(*fvl));
1734 fvl->profile_id = offset;
1735 LIST_ADD(&fvl->list_entry, fv_list);
1740 if (LIST_EMPTY(fv_list))
1745 LIST_FOR_EACH_ENTRY_SAFE(fvl, tmp, fv_list, ice_sw_fv_list_entry,
1747 LIST_DEL(&fvl->list_entry);
1751 return ICE_ERR_NO_MEMORY;
1755 * ice_init_prof_result_bm - Initialize the profile result index bitmap
1756 * @hw: pointer to hardware structure
1758 void ice_init_prof_result_bm(struct ice_hw *hw)
1760 struct ice_pkg_enum state;
1761 struct ice_seg *ice_seg;
1764 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1774 fv = (struct ice_fv *)
1775 ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1776 &off, ice_sw_fv_handler);
1781 ice_zero_bitmap(hw->switch_info->prof_res_bm[off],
1784 /* Determine empty field vector indices, these can be
1785 * used for recipe results. Skip index 0, since it is
1786 * always used for Switch ID.
1788 for (i = 1; i < ICE_MAX_FV_WORDS; i++)
1789 if (fv->ew[i].prot_id == ICE_PROT_INVALID &&
1790 fv->ew[i].off == ICE_FV_OFFSET_INVAL)
1792 hw->switch_info->prof_res_bm[off]);
1798 * @hw: pointer to the HW structure
1799 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1801 * Frees a package buffer
1803 static void ice_pkg_buf_free(struct ice_hw *hw, struct ice_buf_build *bld)
1809 * ice_pkg_buf_reserve_section
1810 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1811 * @count: the number of sections to reserve
1813 * Reserves one or more section table entries in a package buffer. This routine
1814 * can be called multiple times as long as they are made before calling
1815 * ice_pkg_buf_alloc_section(). Once ice_pkg_buf_alloc_section()
1816 * is called once, the number of sections that can be allocated will not be able
1817 * to be increased; not using all reserved sections is fine, but this will
1818 * result in some wasted space in the buffer.
1819 * Note: all package contents must be in Little Endian form.
1821 static enum ice_status
1822 ice_pkg_buf_reserve_section(struct ice_buf_build *bld, u16 count)
1824 struct ice_buf_hdr *buf;
1829 return ICE_ERR_PARAM;
1831 buf = (struct ice_buf_hdr *)&bld->buf;
1833 /* already an active section, can't increase table size */
1834 section_count = LE16_TO_CPU(buf->section_count);
1835 if (section_count > 0)
1838 if (bld->reserved_section_table_entries + count > ICE_MAX_S_COUNT)
1840 bld->reserved_section_table_entries += count;
1842 data_end = LE16_TO_CPU(buf->data_end) +
1843 FLEX_ARRAY_SIZE(buf, section_entry, count);
1844 buf->data_end = CPU_TO_LE16(data_end);
1850 * ice_pkg_buf_alloc_section
1851 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1852 * @type: the section type value
1853 * @size: the size of the section to reserve (in bytes)
1855 * Reserves memory in the buffer for a section's content and updates the
1856 * buffers' status accordingly. This routine returns a pointer to the first
1857 * byte of the section start within the buffer, which is used to fill in the
1859 * Note: all package contents must be in Little Endian form.
1862 ice_pkg_buf_alloc_section(struct ice_buf_build *bld, u32 type, u16 size)
1864 struct ice_buf_hdr *buf;
1868 if (!bld || !type || !size)
1871 buf = (struct ice_buf_hdr *)&bld->buf;
1873 /* check for enough space left in buffer */
1874 data_end = LE16_TO_CPU(buf->data_end);
1876 /* section start must align on 4 byte boundary */
1877 data_end = ICE_ALIGN(data_end, 4);
1879 if ((data_end + size) > ICE_MAX_S_DATA_END)
1882 /* check for more available section table entries */
1883 sect_count = LE16_TO_CPU(buf->section_count);
1884 if (sect_count < bld->reserved_section_table_entries) {
1885 void *section_ptr = ((u8 *)buf) + data_end;
1887 buf->section_entry[sect_count].offset = CPU_TO_LE16(data_end);
1888 buf->section_entry[sect_count].size = CPU_TO_LE16(size);
1889 buf->section_entry[sect_count].type = CPU_TO_LE32(type);
1892 buf->data_end = CPU_TO_LE16(data_end);
1894 buf->section_count = CPU_TO_LE16(sect_count + 1);
1898 /* no free section table entries */
1903 * ice_pkg_buf_get_active_sections
1904 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1906 * Returns the number of active sections. Before using the package buffer
1907 * in an update package command, the caller should make sure that there is at
1908 * least one active section - otherwise, the buffer is not legal and should
1910 * Note: all package contents must be in Little Endian form.
1912 static u16 ice_pkg_buf_get_active_sections(struct ice_buf_build *bld)
1914 struct ice_buf_hdr *buf;
1919 buf = (struct ice_buf_hdr *)&bld->buf;
1920 return LE16_TO_CPU(buf->section_count);
1925 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1927 * Return a pointer to the buffer's header
1929 static struct ice_buf *ice_pkg_buf(struct ice_buf_build *bld)
1938 * ice_tunnel_port_in_use_hlpr - helper function to determine tunnel usage
1939 * @hw: pointer to the HW structure
1940 * @port: port to search for
1941 * @index: optionally returns index
1943 * Returns whether a port is already in use as a tunnel, and optionally its
1946 static bool ice_tunnel_port_in_use_hlpr(struct ice_hw *hw, u16 port, u16 *index)
1950 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
1951 if (hw->tnl.tbl[i].in_use && hw->tnl.tbl[i].port == port) {
1961 * ice_tunnel_port_in_use
1962 * @hw: pointer to the HW structure
1963 * @port: port to search for
1964 * @index: optionally returns index
1966 * Returns whether a port is already in use as a tunnel, and optionally its
1969 bool ice_tunnel_port_in_use(struct ice_hw *hw, u16 port, u16 *index)
1973 ice_acquire_lock(&hw->tnl_lock);
1974 res = ice_tunnel_port_in_use_hlpr(hw, port, index);
1975 ice_release_lock(&hw->tnl_lock);
1981 * ice_tunnel_get_type
1982 * @hw: pointer to the HW structure
1983 * @port: port to search for
1984 * @type: returns tunnel index
1986 * For a given port number, will return the type of tunnel.
1989 ice_tunnel_get_type(struct ice_hw *hw, u16 port, enum ice_tunnel_type *type)
1994 ice_acquire_lock(&hw->tnl_lock);
1996 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
1997 if (hw->tnl.tbl[i].in_use && hw->tnl.tbl[i].port == port) {
1998 *type = hw->tnl.tbl[i].type;
2003 ice_release_lock(&hw->tnl_lock);
2009 * ice_find_free_tunnel_entry
2010 * @hw: pointer to the HW structure
2011 * @type: tunnel type
2012 * @index: optionally returns index
2014 * Returns whether there is a free tunnel entry, and optionally its index
2017 ice_find_free_tunnel_entry(struct ice_hw *hw, enum ice_tunnel_type type,
2022 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
2023 if (hw->tnl.tbl[i].valid && !hw->tnl.tbl[i].in_use &&
2024 hw->tnl.tbl[i].type == type) {
2034 * ice_get_open_tunnel_port - retrieve an open tunnel port
2035 * @hw: pointer to the HW structure
2036 * @type: tunnel type (TNL_ALL will return any open port)
2037 * @port: returns open port
2040 ice_get_open_tunnel_port(struct ice_hw *hw, enum ice_tunnel_type type,
2046 ice_acquire_lock(&hw->tnl_lock);
2048 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
2049 if (hw->tnl.tbl[i].valid && hw->tnl.tbl[i].in_use &&
2050 (type == TNL_ALL || hw->tnl.tbl[i].type == type)) {
2051 *port = hw->tnl.tbl[i].port;
2056 ice_release_lock(&hw->tnl_lock);
2063 * @hw: pointer to the HW structure
2064 * @type: type of tunnel
2065 * @port: port of tunnel to create
2067 * Create a tunnel by updating the parse graph in the parser. We do that by
2068 * creating a package buffer with the tunnel info and issuing an update package
2072 ice_create_tunnel(struct ice_hw *hw, enum ice_tunnel_type type, u16 port)
2074 struct ice_boost_tcam_section *sect_rx, *sect_tx;
2075 enum ice_status status = ICE_ERR_MAX_LIMIT;
2076 struct ice_buf_build *bld;
2079 ice_acquire_lock(&hw->tnl_lock);
2081 if (ice_tunnel_port_in_use_hlpr(hw, port, &index)) {
2082 hw->tnl.tbl[index].ref++;
2083 status = ICE_SUCCESS;
2084 goto ice_create_tunnel_end;
2087 if (!ice_find_free_tunnel_entry(hw, type, &index)) {
2088 status = ICE_ERR_OUT_OF_RANGE;
2089 goto ice_create_tunnel_end;
2092 bld = ice_pkg_buf_alloc(hw);
2094 status = ICE_ERR_NO_MEMORY;
2095 goto ice_create_tunnel_end;
2098 /* allocate 2 sections, one for Rx parser, one for Tx parser */
2099 if (ice_pkg_buf_reserve_section(bld, 2))
2100 goto ice_create_tunnel_err;
2102 sect_rx = (struct ice_boost_tcam_section *)
2103 ice_pkg_buf_alloc_section(bld, ICE_SID_RXPARSER_BOOST_TCAM,
2104 ice_struct_size(sect_rx, tcam, 1));
2106 goto ice_create_tunnel_err;
2107 sect_rx->count = CPU_TO_LE16(1);
2109 sect_tx = (struct ice_boost_tcam_section *)
2110 ice_pkg_buf_alloc_section(bld, ICE_SID_TXPARSER_BOOST_TCAM,
2111 ice_struct_size(sect_tx, tcam, 1));
2113 goto ice_create_tunnel_err;
2114 sect_tx->count = CPU_TO_LE16(1);
2116 /* copy original boost entry to update package buffer */
2117 ice_memcpy(sect_rx->tcam, hw->tnl.tbl[index].boost_entry,
2118 sizeof(*sect_rx->tcam), ICE_NONDMA_TO_NONDMA);
2120 /* over-write the never-match dest port key bits with the encoded port
2123 ice_set_key((u8 *)§_rx->tcam[0].key, sizeof(sect_rx->tcam[0].key),
2124 (u8 *)&port, NULL, NULL, NULL,
2125 (u16)offsetof(struct ice_boost_key_value, hv_dst_port_key),
2126 sizeof(sect_rx->tcam[0].key.key.hv_dst_port_key));
2128 /* exact copy of entry to Tx section entry */
2129 ice_memcpy(sect_tx->tcam, sect_rx->tcam, sizeof(*sect_tx->tcam),
2130 ICE_NONDMA_TO_NONDMA);
2132 status = ice_update_pkg(hw, ice_pkg_buf(bld), 1);
2134 hw->tnl.tbl[index].port = port;
2135 hw->tnl.tbl[index].in_use = true;
2136 hw->tnl.tbl[index].ref = 1;
2139 ice_create_tunnel_err:
2140 ice_pkg_buf_free(hw, bld);
2142 ice_create_tunnel_end:
2143 ice_release_lock(&hw->tnl_lock);
2149 * ice_destroy_tunnel
2150 * @hw: pointer to the HW structure
2151 * @port: port of tunnel to destroy (ignored if the all parameter is true)
2152 * @all: flag that states to destroy all tunnels
2154 * Destroys a tunnel or all tunnels by creating an update package buffer
2155 * targeting the specific updates requested and then performing an update
2158 enum ice_status ice_destroy_tunnel(struct ice_hw *hw, u16 port, bool all)
2160 struct ice_boost_tcam_section *sect_rx, *sect_tx;
2161 enum ice_status status = ICE_ERR_MAX_LIMIT;
2162 struct ice_buf_build *bld;
2168 ice_acquire_lock(&hw->tnl_lock);
2170 if (!all && ice_tunnel_port_in_use_hlpr(hw, port, &index))
2171 if (hw->tnl.tbl[index].ref > 1) {
2172 hw->tnl.tbl[index].ref--;
2173 status = ICE_SUCCESS;
2174 goto ice_destroy_tunnel_end;
2177 /* determine count */
2178 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
2179 if (hw->tnl.tbl[i].valid && hw->tnl.tbl[i].in_use &&
2180 (all || hw->tnl.tbl[i].port == port))
2184 status = ICE_ERR_PARAM;
2185 goto ice_destroy_tunnel_end;
2188 /* size of section - there is at least one entry */
2189 size = ice_struct_size(sect_rx, tcam, count);
2191 bld = ice_pkg_buf_alloc(hw);
2193 status = ICE_ERR_NO_MEMORY;
2194 goto ice_destroy_tunnel_end;
2197 /* allocate 2 sections, one for Rx parser, one for Tx parser */
2198 if (ice_pkg_buf_reserve_section(bld, 2))
2199 goto ice_destroy_tunnel_err;
2201 sect_rx = (struct ice_boost_tcam_section *)
2202 ice_pkg_buf_alloc_section(bld, ICE_SID_RXPARSER_BOOST_TCAM,
2205 goto ice_destroy_tunnel_err;
2206 sect_rx->count = CPU_TO_LE16(1);
2208 sect_tx = (struct ice_boost_tcam_section *)
2209 ice_pkg_buf_alloc_section(bld, ICE_SID_TXPARSER_BOOST_TCAM,
2212 goto ice_destroy_tunnel_err;
2213 sect_tx->count = CPU_TO_LE16(1);
2215 /* copy original boost entry to update package buffer, one copy to Rx
2216 * section, another copy to the Tx section
2218 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
2219 if (hw->tnl.tbl[i].valid && hw->tnl.tbl[i].in_use &&
2220 (all || hw->tnl.tbl[i].port == port)) {
2221 ice_memcpy(sect_rx->tcam + i,
2222 hw->tnl.tbl[i].boost_entry,
2223 sizeof(*sect_rx->tcam),
2224 ICE_NONDMA_TO_NONDMA);
2225 ice_memcpy(sect_tx->tcam + i,
2226 hw->tnl.tbl[i].boost_entry,
2227 sizeof(*sect_tx->tcam),
2228 ICE_NONDMA_TO_NONDMA);
2229 hw->tnl.tbl[i].marked = true;
2232 status = ice_update_pkg(hw, ice_pkg_buf(bld), 1);
2234 for (i = 0; i < hw->tnl.count &&
2235 i < ICE_TUNNEL_MAX_ENTRIES; i++)
2236 if (hw->tnl.tbl[i].marked) {
2237 hw->tnl.tbl[i].ref = 0;
2238 hw->tnl.tbl[i].port = 0;
2239 hw->tnl.tbl[i].in_use = false;
2240 hw->tnl.tbl[i].marked = false;
2243 ice_destroy_tunnel_err:
2244 ice_pkg_buf_free(hw, bld);
2246 ice_destroy_tunnel_end:
2247 ice_release_lock(&hw->tnl_lock);
2253 * ice_find_prot_off - find prot ID and offset pair, based on prof and FV index
2254 * @hw: pointer to the hardware structure
2255 * @blk: hardware block
2257 * @fv_idx: field vector word index
2258 * @prot: variable to receive the protocol ID
2259 * @off: variable to receive the protocol offset
2262 ice_find_prot_off(struct ice_hw *hw, enum ice_block blk, u8 prof, u16 fv_idx,
2265 struct ice_fv_word *fv_ext;
2267 if (prof >= hw->blk[blk].es.count)
2268 return ICE_ERR_PARAM;
2270 if (fv_idx >= hw->blk[blk].es.fvw)
2271 return ICE_ERR_PARAM;
2273 fv_ext = hw->blk[blk].es.t + (prof * hw->blk[blk].es.fvw);
2275 *prot = fv_ext[fv_idx].prot_id;
2276 *off = fv_ext[fv_idx].off;
2281 /* PTG Management */
2284 * ice_ptg_find_ptype - Search for packet type group using packet type (ptype)
2285 * @hw: pointer to the hardware structure
2287 * @ptype: the ptype to search for
2288 * @ptg: pointer to variable that receives the PTG
2290 * This function will search the PTGs for a particular ptype, returning the
2291 * PTG ID that contains it through the PTG parameter, with the value of
2292 * ICE_DEFAULT_PTG (0) meaning it is part the default PTG.
2294 static enum ice_status
2295 ice_ptg_find_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 *ptg)
2297 if (ptype >= ICE_XLT1_CNT || !ptg)
2298 return ICE_ERR_PARAM;
2300 *ptg = hw->blk[blk].xlt1.ptypes[ptype].ptg;
2305 * ice_ptg_alloc_val - Allocates a new packet type group ID by value
2306 * @hw: pointer to the hardware structure
2308 * @ptg: the PTG to allocate
2310 * This function allocates a given packet type group ID specified by the PTG
2313 static void ice_ptg_alloc_val(struct ice_hw *hw, enum ice_block blk, u8 ptg)
2315 hw->blk[blk].xlt1.ptg_tbl[ptg].in_use = true;
2319 * ice_ptg_remove_ptype - Removes ptype from a particular packet type group
2320 * @hw: pointer to the hardware structure
2322 * @ptype: the ptype to remove
2323 * @ptg: the PTG to remove the ptype from
2325 * This function will remove the ptype from the specific PTG, and move it to
2326 * the default PTG (ICE_DEFAULT_PTG).
2328 static enum ice_status
2329 ice_ptg_remove_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 ptg)
2331 struct ice_ptg_ptype **ch;
2332 struct ice_ptg_ptype *p;
2334 if (ptype > ICE_XLT1_CNT - 1)
2335 return ICE_ERR_PARAM;
2337 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].in_use)
2338 return ICE_ERR_DOES_NOT_EXIST;
2340 /* Should not happen if .in_use is set, bad config */
2341 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype)
2344 /* find the ptype within this PTG, and bypass the link over it */
2345 p = hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2346 ch = &hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2348 if (ptype == (p - hw->blk[blk].xlt1.ptypes)) {
2349 *ch = p->next_ptype;
2353 ch = &p->next_ptype;
2357 hw->blk[blk].xlt1.ptypes[ptype].ptg = ICE_DEFAULT_PTG;
2358 hw->blk[blk].xlt1.ptypes[ptype].next_ptype = NULL;
2364 * ice_ptg_add_mv_ptype - Adds/moves ptype to a particular packet type group
2365 * @hw: pointer to the hardware structure
2367 * @ptype: the ptype to add or move
2368 * @ptg: the PTG to add or move the ptype to
2370 * This function will either add or move a ptype to a particular PTG depending
2371 * on if the ptype is already part of another group. Note that using a
2372 * a destination PTG ID of ICE_DEFAULT_PTG (0) will move the ptype to the
2375 static enum ice_status
2376 ice_ptg_add_mv_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 ptg)
2378 enum ice_status status;
2381 if (ptype > ICE_XLT1_CNT - 1)
2382 return ICE_ERR_PARAM;
2384 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].in_use && ptg != ICE_DEFAULT_PTG)
2385 return ICE_ERR_DOES_NOT_EXIST;
2387 status = ice_ptg_find_ptype(hw, blk, ptype, &original_ptg);
2391 /* Is ptype already in the correct PTG? */
2392 if (original_ptg == ptg)
2395 /* Remove from original PTG and move back to the default PTG */
2396 if (original_ptg != ICE_DEFAULT_PTG)
2397 ice_ptg_remove_ptype(hw, blk, ptype, original_ptg);
2399 /* Moving to default PTG? Then we're done with this request */
2400 if (ptg == ICE_DEFAULT_PTG)
2403 /* Add ptype to PTG at beginning of list */
2404 hw->blk[blk].xlt1.ptypes[ptype].next_ptype =
2405 hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2406 hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype =
2407 &hw->blk[blk].xlt1.ptypes[ptype];
2409 hw->blk[blk].xlt1.ptypes[ptype].ptg = ptg;
2410 hw->blk[blk].xlt1.t[ptype] = ptg;
2415 /* Block / table size info */
2416 struct ice_blk_size_details {
2417 u16 xlt1; /* # XLT1 entries */
2418 u16 xlt2; /* # XLT2 entries */
2419 u16 prof_tcam; /* # profile ID TCAM entries */
2420 u16 prof_id; /* # profile IDs */
2421 u8 prof_cdid_bits; /* # CDID one-hot bits used in key */
2422 u16 prof_redir; /* # profile redirection entries */
2423 u16 es; /* # extraction sequence entries */
2424 u16 fvw; /* # field vector words */
2425 u8 overwrite; /* overwrite existing entries allowed */
2426 u8 reverse; /* reverse FV order */
2429 static const struct ice_blk_size_details blk_sizes[ICE_BLK_COUNT] = {
2432 * XLT1 - Number of entries in XLT1 table
2433 * XLT2 - Number of entries in XLT2 table
2434 * TCAM - Number of entries Profile ID TCAM table
2435 * CDID - Control Domain ID of the hardware block
2436 * PRED - Number of entries in the Profile Redirection Table
2437 * FV - Number of entries in the Field Vector
2438 * FVW - Width (in WORDs) of the Field Vector
2439 * OVR - Overwrite existing table entries
2442 /* XLT1 , XLT2 ,TCAM, PID,CDID,PRED, FV, FVW */
2443 /* Overwrite , Reverse FV */
2444 /* SW */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 256, 0, 256, 256, 48,
2446 /* ACL */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 32,
2448 /* FD */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 24,
2450 /* RSS */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 24,
2452 /* PE */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 64, 32, 0, 32, 32, 24,
2457 ICE_SID_XLT1_OFF = 0,
2460 ICE_SID_PR_REDIR_OFF,
2465 /* Characteristic handling */
2468 * ice_match_prop_lst - determine if properties of two lists match
2469 * @list1: first properties list
2470 * @list2: second properties list
2472 * Count, cookies and the order must match in order to be considered equivalent.
2475 ice_match_prop_lst(struct LIST_HEAD_TYPE *list1, struct LIST_HEAD_TYPE *list2)
2477 struct ice_vsig_prof *tmp1;
2478 struct ice_vsig_prof *tmp2;
2482 /* compare counts */
2483 LIST_FOR_EACH_ENTRY(tmp1, list1, ice_vsig_prof, list)
2485 LIST_FOR_EACH_ENTRY(tmp2, list2, ice_vsig_prof, list)
2487 if (!count || count != chk_count)
2490 tmp1 = LIST_FIRST_ENTRY(list1, struct ice_vsig_prof, list);
2491 tmp2 = LIST_FIRST_ENTRY(list2, struct ice_vsig_prof, list);
2493 /* profile cookies must compare, and in the exact same order to take
2494 * into account priority
2497 if (tmp2->profile_cookie != tmp1->profile_cookie)
2500 tmp1 = LIST_NEXT_ENTRY(tmp1, struct ice_vsig_prof, list);
2501 tmp2 = LIST_NEXT_ENTRY(tmp2, struct ice_vsig_prof, list);
2507 /* VSIG Management */
2510 * ice_vsig_find_vsi - find a VSIG that contains a specified VSI
2511 * @hw: pointer to the hardware structure
2513 * @vsi: VSI of interest
2514 * @vsig: pointer to receive the VSI group
2516 * This function will lookup the VSI entry in the XLT2 list and return
2517 * the VSI group its associated with.
2520 ice_vsig_find_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 *vsig)
2522 if (!vsig || vsi >= ICE_MAX_VSI)
2523 return ICE_ERR_PARAM;
2525 /* As long as there's a default or valid VSIG associated with the input
2526 * VSI, the functions returns a success. Any handling of VSIG will be
2527 * done by the following add, update or remove functions.
2529 *vsig = hw->blk[blk].xlt2.vsis[vsi].vsig;
2535 * ice_vsig_alloc_val - allocate a new VSIG by value
2536 * @hw: pointer to the hardware structure
2538 * @vsig: the VSIG to allocate
2540 * This function will allocate a given VSIG specified by the VSIG parameter.
2542 static u16 ice_vsig_alloc_val(struct ice_hw *hw, enum ice_block blk, u16 vsig)
2544 u16 idx = vsig & ICE_VSIG_IDX_M;
2546 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use) {
2547 INIT_LIST_HEAD(&hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst);
2548 hw->blk[blk].xlt2.vsig_tbl[idx].in_use = true;
2551 return ICE_VSIG_VALUE(idx, hw->pf_id);
2555 * ice_vsig_alloc - Finds a free entry and allocates a new VSIG
2556 * @hw: pointer to the hardware structure
2559 * This function will iterate through the VSIG list and mark the first
2560 * unused entry for the new VSIG entry as used and return that value.
2562 static u16 ice_vsig_alloc(struct ice_hw *hw, enum ice_block blk)
2566 for (i = 1; i < ICE_MAX_VSIGS; i++)
2567 if (!hw->blk[blk].xlt2.vsig_tbl[i].in_use)
2568 return ice_vsig_alloc_val(hw, blk, i);
2570 return ICE_DEFAULT_VSIG;
2574 * ice_find_dup_props_vsig - find VSI group with a specified set of properties
2575 * @hw: pointer to the hardware structure
2577 * @chs: characteristic list
2578 * @vsig: returns the VSIG with the matching profiles, if found
2580 * Each VSIG is associated with a characteristic set; i.e. all VSIs under
2581 * a group have the same characteristic set. To check if there exists a VSIG
2582 * which has the same characteristics as the input characteristics; this
2583 * function will iterate through the XLT2 list and return the VSIG that has a
2584 * matching configuration. In order to make sure that priorities are accounted
2585 * for, the list must match exactly, including the order in which the
2586 * characteristics are listed.
2588 static enum ice_status
2589 ice_find_dup_props_vsig(struct ice_hw *hw, enum ice_block blk,
2590 struct LIST_HEAD_TYPE *chs, u16 *vsig)
2592 struct ice_xlt2 *xlt2 = &hw->blk[blk].xlt2;
2595 for (i = 0; i < xlt2->count; i++)
2596 if (xlt2->vsig_tbl[i].in_use &&
2597 ice_match_prop_lst(chs, &xlt2->vsig_tbl[i].prop_lst)) {
2598 *vsig = ICE_VSIG_VALUE(i, hw->pf_id);
2602 return ICE_ERR_DOES_NOT_EXIST;
2606 * ice_vsig_free - free VSI group
2607 * @hw: pointer to the hardware structure
2609 * @vsig: VSIG to remove
2611 * The function will remove all VSIs associated with the input VSIG and move
2612 * them to the DEFAULT_VSIG and mark the VSIG available.
2614 static enum ice_status
2615 ice_vsig_free(struct ice_hw *hw, enum ice_block blk, u16 vsig)
2617 struct ice_vsig_prof *dtmp, *del;
2618 struct ice_vsig_vsi *vsi_cur;
2621 idx = vsig & ICE_VSIG_IDX_M;
2622 if (idx >= ICE_MAX_VSIGS)
2623 return ICE_ERR_PARAM;
2625 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
2626 return ICE_ERR_DOES_NOT_EXIST;
2628 hw->blk[blk].xlt2.vsig_tbl[idx].in_use = false;
2630 vsi_cur = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2631 /* If the VSIG has at least 1 VSI then iterate through the
2632 * list and remove the VSIs before deleting the group.
2635 /* remove all vsis associated with this VSIG XLT2 entry */
2637 struct ice_vsig_vsi *tmp = vsi_cur->next_vsi;
2639 vsi_cur->vsig = ICE_DEFAULT_VSIG;
2640 vsi_cur->changed = 1;
2641 vsi_cur->next_vsi = NULL;
2645 /* NULL terminate head of VSI list */
2646 hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi = NULL;
2649 /* free characteristic list */
2650 LIST_FOR_EACH_ENTRY_SAFE(del, dtmp,
2651 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
2652 ice_vsig_prof, list) {
2653 LIST_DEL(&del->list);
2657 /* if VSIG characteristic list was cleared for reset
2658 * re-initialize the list head
2660 INIT_LIST_HEAD(&hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst);
2666 * ice_vsig_remove_vsi - remove VSI from VSIG
2667 * @hw: pointer to the hardware structure
2669 * @vsi: VSI to remove
2670 * @vsig: VSI group to remove from
2672 * The function will remove the input VSI from its VSI group and move it
2673 * to the DEFAULT_VSIG.
2675 static enum ice_status
2676 ice_vsig_remove_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
2678 struct ice_vsig_vsi **vsi_head, *vsi_cur, *vsi_tgt;
2681 idx = vsig & ICE_VSIG_IDX_M;
2683 if (vsi >= ICE_MAX_VSI || idx >= ICE_MAX_VSIGS)
2684 return ICE_ERR_PARAM;
2686 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
2687 return ICE_ERR_DOES_NOT_EXIST;
2689 /* entry already in default VSIG, don't have to remove */
2690 if (idx == ICE_DEFAULT_VSIG)
2693 vsi_head = &hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2697 vsi_tgt = &hw->blk[blk].xlt2.vsis[vsi];
2698 vsi_cur = (*vsi_head);
2700 /* iterate the VSI list, skip over the entry to be removed */
2702 if (vsi_tgt == vsi_cur) {
2703 (*vsi_head) = vsi_cur->next_vsi;
2706 vsi_head = &vsi_cur->next_vsi;
2707 vsi_cur = vsi_cur->next_vsi;
2710 /* verify if VSI was removed from group list */
2712 return ICE_ERR_DOES_NOT_EXIST;
2714 vsi_cur->vsig = ICE_DEFAULT_VSIG;
2715 vsi_cur->changed = 1;
2716 vsi_cur->next_vsi = NULL;
2722 * ice_vsig_add_mv_vsi - add or move a VSI to a VSI group
2723 * @hw: pointer to the hardware structure
2726 * @vsig: destination VSI group
2728 * This function will move or add the input VSI to the target VSIG.
2729 * The function will find the original VSIG the VSI belongs to and
2730 * move the entry to the DEFAULT_VSIG, update the original VSIG and
2731 * then move entry to the new VSIG.
2733 static enum ice_status
2734 ice_vsig_add_mv_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
2736 struct ice_vsig_vsi *tmp;
2737 enum ice_status status;
2740 idx = vsig & ICE_VSIG_IDX_M;
2742 if (vsi >= ICE_MAX_VSI || idx >= ICE_MAX_VSIGS)
2743 return ICE_ERR_PARAM;
2745 /* if VSIG not in use and VSIG is not default type this VSIG
2748 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use &&
2749 vsig != ICE_DEFAULT_VSIG)
2750 return ICE_ERR_DOES_NOT_EXIST;
2752 status = ice_vsig_find_vsi(hw, blk, vsi, &orig_vsig);
2756 /* no update required if vsigs match */
2757 if (orig_vsig == vsig)
2760 if (orig_vsig != ICE_DEFAULT_VSIG) {
2761 /* remove entry from orig_vsig and add to default VSIG */
2762 status = ice_vsig_remove_vsi(hw, blk, vsi, orig_vsig);
2767 if (idx == ICE_DEFAULT_VSIG)
2770 /* Create VSI entry and add VSIG and prop_mask values */
2771 hw->blk[blk].xlt2.vsis[vsi].vsig = vsig;
2772 hw->blk[blk].xlt2.vsis[vsi].changed = 1;
2774 /* Add new entry to the head of the VSIG list */
2775 tmp = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2776 hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi =
2777 &hw->blk[blk].xlt2.vsis[vsi];
2778 hw->blk[blk].xlt2.vsis[vsi].next_vsi = tmp;
2779 hw->blk[blk].xlt2.t[vsi] = vsig;
2785 * ice_prof_has_mask_idx - determine if profile index masking is identical
2786 * @hw: pointer to the hardware structure
2788 * @prof: profile to check
2789 * @idx: profile index to check
2790 * @mask: mask to match
2793 ice_prof_has_mask_idx(struct ice_hw *hw, enum ice_block blk, u8 prof, u16 idx,
2796 bool expect_no_mask = false;
2801 /* If mask is 0x0000 or 0xffff, then there is no masking */
2802 if (mask == 0 || mask == 0xffff)
2803 expect_no_mask = true;
2805 /* Scan the enabled masks on this profile, for the specified idx */
2806 for (i = hw->blk[blk].masks.first; i < hw->blk[blk].masks.first +
2807 hw->blk[blk].masks.count; i++)
2808 if (hw->blk[blk].es.mask_ena[prof] & BIT(i))
2809 if (hw->blk[blk].masks.masks[i].in_use &&
2810 hw->blk[blk].masks.masks[i].idx == idx) {
2812 if (hw->blk[blk].masks.masks[i].mask == mask)
2817 if (expect_no_mask) {
2829 * ice_prof_has_mask - determine if profile masking is identical
2830 * @hw: pointer to the hardware structure
2832 * @prof: profile to check
2833 * @masks: masks to match
2836 ice_prof_has_mask(struct ice_hw *hw, enum ice_block blk, u8 prof, u16 *masks)
2840 /* es->mask_ena[prof] will have the mask */
2841 for (i = 0; i < hw->blk[blk].es.fvw; i++)
2842 if (!ice_prof_has_mask_idx(hw, blk, prof, i, masks[i]))
2849 * ice_find_prof_id_with_mask - find profile ID for a given field vector
2850 * @hw: pointer to the hardware structure
2852 * @fv: field vector to search for
2853 * @masks: masks for fv
2854 * @prof_id: receives the profile ID
2856 static enum ice_status
2857 ice_find_prof_id_with_mask(struct ice_hw *hw, enum ice_block blk,
2858 struct ice_fv_word *fv, u16 *masks, u8 *prof_id)
2860 struct ice_es *es = &hw->blk[blk].es;
2863 /* For FD and RSS, we don't want to re-use an existed profile with the
2864 * same field vector and mask. This will cause rule interference.
2866 if (blk == ICE_BLK_FD || blk == ICE_BLK_RSS)
2867 return ICE_ERR_DOES_NOT_EXIST;
2869 for (i = 0; i < (u8)es->count; i++) {
2870 u16 off = i * es->fvw;
2872 if (memcmp(&es->t[off], fv, es->fvw * sizeof(*fv)))
2875 /* check if masks settings are the same for this profile */
2876 if (masks && !ice_prof_has_mask(hw, blk, i, masks))
2883 return ICE_ERR_DOES_NOT_EXIST;
2887 * ice_prof_id_rsrc_type - get profile ID resource type for a block type
2888 * @blk: the block type
2889 * @rsrc_type: pointer to variable to receive the resource type
2891 static bool ice_prof_id_rsrc_type(enum ice_block blk, u16 *rsrc_type)
2895 *rsrc_type = ICE_AQC_RES_TYPE_SWITCH_PROF_BLDR_PROFID;
2898 *rsrc_type = ICE_AQC_RES_TYPE_ACL_PROF_BLDR_PROFID;
2901 *rsrc_type = ICE_AQC_RES_TYPE_FD_PROF_BLDR_PROFID;
2904 *rsrc_type = ICE_AQC_RES_TYPE_HASH_PROF_BLDR_PROFID;
2907 *rsrc_type = ICE_AQC_RES_TYPE_QHASH_PROF_BLDR_PROFID;
2916 * ice_tcam_ent_rsrc_type - get TCAM entry resource type for a block type
2917 * @blk: the block type
2918 * @rsrc_type: pointer to variable to receive the resource type
2920 static bool ice_tcam_ent_rsrc_type(enum ice_block blk, u16 *rsrc_type)
2924 *rsrc_type = ICE_AQC_RES_TYPE_SWITCH_PROF_BLDR_TCAM;
2927 *rsrc_type = ICE_AQC_RES_TYPE_ACL_PROF_BLDR_TCAM;
2930 *rsrc_type = ICE_AQC_RES_TYPE_FD_PROF_BLDR_TCAM;
2933 *rsrc_type = ICE_AQC_RES_TYPE_HASH_PROF_BLDR_TCAM;
2936 *rsrc_type = ICE_AQC_RES_TYPE_QHASH_PROF_BLDR_TCAM;
2945 * ice_alloc_tcam_ent - allocate hardware TCAM entry
2946 * @hw: pointer to the HW struct
2947 * @blk: the block to allocate the TCAM for
2948 * @btm: true to allocate from bottom of table, false to allocate from top
2949 * @tcam_idx: pointer to variable to receive the TCAM entry
2951 * This function allocates a new entry in a Profile ID TCAM for a specific
2954 static enum ice_status
2955 ice_alloc_tcam_ent(struct ice_hw *hw, enum ice_block blk, bool btm,
2960 if (!ice_tcam_ent_rsrc_type(blk, &res_type))
2961 return ICE_ERR_PARAM;
2963 return ice_alloc_hw_res(hw, res_type, 1, btm, tcam_idx);
2967 * ice_free_tcam_ent - free hardware TCAM entry
2968 * @hw: pointer to the HW struct
2969 * @blk: the block from which to free the TCAM entry
2970 * @tcam_idx: the TCAM entry to free
2972 * This function frees an entry in a Profile ID TCAM for a specific block.
2974 static enum ice_status
2975 ice_free_tcam_ent(struct ice_hw *hw, enum ice_block blk, u16 tcam_idx)
2979 if (!ice_tcam_ent_rsrc_type(blk, &res_type))
2980 return ICE_ERR_PARAM;
2982 return ice_free_hw_res(hw, res_type, 1, &tcam_idx);
2986 * ice_alloc_prof_id - allocate profile ID
2987 * @hw: pointer to the HW struct
2988 * @blk: the block to allocate the profile ID for
2989 * @prof_id: pointer to variable to receive the profile ID
2991 * This function allocates a new profile ID, which also corresponds to a Field
2992 * Vector (Extraction Sequence) entry.
2994 static enum ice_status
2995 ice_alloc_prof_id(struct ice_hw *hw, enum ice_block blk, u8 *prof_id)
2997 enum ice_status status;
3001 if (!ice_prof_id_rsrc_type(blk, &res_type))
3002 return ICE_ERR_PARAM;
3004 status = ice_alloc_hw_res(hw, res_type, 1, false, &get_prof);
3006 *prof_id = (u8)get_prof;
3012 * ice_free_prof_id - free profile ID
3013 * @hw: pointer to the HW struct
3014 * @blk: the block from which to free the profile ID
3015 * @prof_id: the profile ID to free
3017 * This function frees a profile ID, which also corresponds to a Field Vector.
3019 static enum ice_status
3020 ice_free_prof_id(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
3022 u16 tmp_prof_id = (u16)prof_id;
3025 if (!ice_prof_id_rsrc_type(blk, &res_type))
3026 return ICE_ERR_PARAM;
3028 return ice_free_hw_res(hw, res_type, 1, &tmp_prof_id);
3032 * ice_prof_inc_ref - increment reference count for profile
3033 * @hw: pointer to the HW struct
3034 * @blk: the block from which to free the profile ID
3035 * @prof_id: the profile ID for which to increment the reference count
3037 static enum ice_status
3038 ice_prof_inc_ref(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
3040 if (prof_id > hw->blk[blk].es.count)
3041 return ICE_ERR_PARAM;
3043 hw->blk[blk].es.ref_count[prof_id]++;
3049 * ice_write_prof_mask_reg - write profile mask register
3050 * @hw: pointer to the HW struct
3051 * @blk: hardware block
3052 * @mask_idx: mask index
3053 * @idx: index of the FV which will use the mask
3054 * @mask: the 16-bit mask
3057 ice_write_prof_mask_reg(struct ice_hw *hw, enum ice_block blk, u16 mask_idx,
3065 offset = GLQF_HMASK(mask_idx);
3066 val = (idx << GLQF_HMASK_MSK_INDEX_S) &
3067 GLQF_HMASK_MSK_INDEX_M;
3068 val |= (mask << GLQF_HMASK_MASK_S) & GLQF_HMASK_MASK_M;
3071 offset = GLQF_FDMASK(mask_idx);
3072 val = (idx << GLQF_FDMASK_MSK_INDEX_S) &
3073 GLQF_FDMASK_MSK_INDEX_M;
3074 val |= (mask << GLQF_FDMASK_MASK_S) &
3078 ice_debug(hw, ICE_DBG_PKG, "No profile masks for block %d\n",
3083 wr32(hw, offset, val);
3084 ice_debug(hw, ICE_DBG_PKG, "write mask, blk %d (%d): %x = %x\n",
3085 blk, idx, offset, val);
3089 * ice_write_prof_mask_enable_res - write profile mask enable register
3090 * @hw: pointer to the HW struct
3091 * @blk: hardware block
3092 * @prof_id: profile ID
3093 * @enable_mask: enable mask
3096 ice_write_prof_mask_enable_res(struct ice_hw *hw, enum ice_block blk,
3097 u16 prof_id, u32 enable_mask)
3103 offset = GLQF_HMASK_SEL(prof_id);
3106 offset = GLQF_FDMASK_SEL(prof_id);
3109 ice_debug(hw, ICE_DBG_PKG, "No profile masks for block %d\n",
3114 wr32(hw, offset, enable_mask);
3115 ice_debug(hw, ICE_DBG_PKG, "write mask enable, blk %d (%d): %x = %x\n",
3116 blk, prof_id, offset, enable_mask);
3120 * ice_init_prof_masks - initial prof masks
3121 * @hw: pointer to the HW struct
3122 * @blk: hardware block
3124 static void ice_init_prof_masks(struct ice_hw *hw, enum ice_block blk)
3129 ice_init_lock(&hw->blk[blk].masks.lock);
3131 per_pf = ICE_PROF_MASK_COUNT / hw->dev_caps.num_funcs;
3133 hw->blk[blk].masks.count = per_pf;
3134 hw->blk[blk].masks.first = hw->pf_id * per_pf;
3136 ice_memset(hw->blk[blk].masks.masks, 0,
3137 sizeof(hw->blk[blk].masks.masks), ICE_NONDMA_MEM);
3139 for (i = hw->blk[blk].masks.first;
3140 i < hw->blk[blk].masks.first + hw->blk[blk].masks.count; i++)
3141 ice_write_prof_mask_reg(hw, blk, i, 0, 0);
3145 * ice_init_all_prof_masks - initial all prof masks
3146 * @hw: pointer to the HW struct
3148 void ice_init_all_prof_masks(struct ice_hw *hw)
3150 ice_init_prof_masks(hw, ICE_BLK_RSS);
3151 ice_init_prof_masks(hw, ICE_BLK_FD);
3155 * ice_alloc_prof_mask - allocate profile mask
3156 * @hw: pointer to the HW struct
3157 * @blk: hardware block
3158 * @idx: index of FV which will use the mask
3159 * @mask: the 16-bit mask
3160 * @mask_idx: variable to receive the mask index
3162 static enum ice_status
3163 ice_alloc_prof_mask(struct ice_hw *hw, enum ice_block blk, u16 idx, u16 mask,
3166 bool found_unused = false, found_copy = false;
3167 enum ice_status status = ICE_ERR_MAX_LIMIT;
3168 u16 unused_idx = 0, copy_idx = 0;
3171 if (blk != ICE_BLK_RSS && blk != ICE_BLK_FD)
3172 return ICE_ERR_PARAM;
3174 ice_acquire_lock(&hw->blk[blk].masks.lock);
3176 for (i = hw->blk[blk].masks.first;
3177 i < hw->blk[blk].masks.first + hw->blk[blk].masks.count; i++)
3178 if (hw->blk[blk].masks.masks[i].in_use) {
3179 /* if mask is in use and it exactly duplicates the
3180 * desired mask and index, then in can be reused
3182 if (hw->blk[blk].masks.masks[i].mask == mask &&
3183 hw->blk[blk].masks.masks[i].idx == idx) {
3189 /* save off unused index, but keep searching in case
3190 * there is an exact match later on
3192 if (!found_unused) {
3193 found_unused = true;
3200 else if (found_unused)
3203 goto err_ice_alloc_prof_mask;
3205 /* update mask for a new entry */
3207 hw->blk[blk].masks.masks[i].in_use = true;
3208 hw->blk[blk].masks.masks[i].mask = mask;
3209 hw->blk[blk].masks.masks[i].idx = idx;
3210 hw->blk[blk].masks.masks[i].ref = 0;
3211 ice_write_prof_mask_reg(hw, blk, i, idx, mask);
3214 hw->blk[blk].masks.masks[i].ref++;
3216 status = ICE_SUCCESS;
3218 err_ice_alloc_prof_mask:
3219 ice_release_lock(&hw->blk[blk].masks.lock);
3225 * ice_free_prof_mask - free profile mask
3226 * @hw: pointer to the HW struct
3227 * @blk: hardware block
3228 * @mask_idx: index of mask
3230 static enum ice_status
3231 ice_free_prof_mask(struct ice_hw *hw, enum ice_block blk, u16 mask_idx)
3233 if (blk != ICE_BLK_RSS && blk != ICE_BLK_FD)
3234 return ICE_ERR_PARAM;
3236 if (!(mask_idx >= hw->blk[blk].masks.first &&
3237 mask_idx < hw->blk[blk].masks.first + hw->blk[blk].masks.count))
3238 return ICE_ERR_DOES_NOT_EXIST;
3240 ice_acquire_lock(&hw->blk[blk].masks.lock);
3242 if (!hw->blk[blk].masks.masks[mask_idx].in_use)
3243 goto exit_ice_free_prof_mask;
3245 if (hw->blk[blk].masks.masks[mask_idx].ref > 1) {
3246 hw->blk[blk].masks.masks[mask_idx].ref--;
3247 goto exit_ice_free_prof_mask;
3251 hw->blk[blk].masks.masks[mask_idx].in_use = false;
3252 hw->blk[blk].masks.masks[mask_idx].mask = 0;
3253 hw->blk[blk].masks.masks[mask_idx].idx = 0;
3255 /* update mask as unused entry */
3256 ice_debug(hw, ICE_DBG_PKG, "Free mask, blk %d, mask %d\n", blk,
3258 ice_write_prof_mask_reg(hw, blk, mask_idx, 0, 0);
3260 exit_ice_free_prof_mask:
3261 ice_release_lock(&hw->blk[blk].masks.lock);
3267 * ice_free_prof_masks - free all profile masks for a profile
3268 * @hw: pointer to the HW struct
3269 * @blk: hardware block
3270 * @prof_id: profile ID
3272 static enum ice_status
3273 ice_free_prof_masks(struct ice_hw *hw, enum ice_block blk, u16 prof_id)
3278 if (blk != ICE_BLK_RSS && blk != ICE_BLK_FD)
3279 return ICE_ERR_PARAM;
3281 mask_bm = hw->blk[blk].es.mask_ena[prof_id];
3282 for (i = 0; i < BITS_PER_BYTE * sizeof(mask_bm); i++)
3283 if (mask_bm & BIT(i))
3284 ice_free_prof_mask(hw, blk, i);
3290 * ice_shutdown_prof_masks - releases lock for masking
3291 * @hw: pointer to the HW struct
3292 * @blk: hardware block
3294 * This should be called before unloading the driver
3296 static void ice_shutdown_prof_masks(struct ice_hw *hw, enum ice_block blk)
3300 ice_acquire_lock(&hw->blk[blk].masks.lock);
3302 for (i = hw->blk[blk].masks.first;
3303 i < hw->blk[blk].masks.first + hw->blk[blk].masks.count; i++) {
3304 ice_write_prof_mask_reg(hw, blk, i, 0, 0);
3306 hw->blk[blk].masks.masks[i].in_use = false;
3307 hw->blk[blk].masks.masks[i].idx = 0;
3308 hw->blk[blk].masks.masks[i].mask = 0;
3311 ice_release_lock(&hw->blk[blk].masks.lock);
3312 ice_destroy_lock(&hw->blk[blk].masks.lock);
3316 * ice_shutdown_all_prof_masks - releases all locks for masking
3317 * @hw: pointer to the HW struct
3319 * This should be called before unloading the driver
3321 void ice_shutdown_all_prof_masks(struct ice_hw *hw)
3323 ice_shutdown_prof_masks(hw, ICE_BLK_RSS);
3324 ice_shutdown_prof_masks(hw, ICE_BLK_FD);
3328 * ice_update_prof_masking - set registers according to masking
3329 * @hw: pointer to the HW struct
3330 * @blk: hardware block
3331 * @prof_id: profile ID
3334 static enum ice_status
3335 ice_update_prof_masking(struct ice_hw *hw, enum ice_block blk, u16 prof_id,
3343 /* Only support FD and RSS masking, otherwise nothing to be done */
3344 if (blk != ICE_BLK_RSS && blk != ICE_BLK_FD)
3347 for (i = 0; i < hw->blk[blk].es.fvw; i++)
3348 if (masks[i] && masks[i] != 0xFFFF) {
3349 if (!ice_alloc_prof_mask(hw, blk, i, masks[i], &idx)) {
3350 ena_mask |= BIT(idx);
3352 /* not enough bitmaps */
3359 /* free any bitmaps we have allocated */
3360 for (i = 0; i < BITS_PER_BYTE * sizeof(ena_mask); i++)
3361 if (ena_mask & BIT(i))
3362 ice_free_prof_mask(hw, blk, i);
3364 return ICE_ERR_OUT_OF_RANGE;
3367 /* enable the masks for this profile */
3368 ice_write_prof_mask_enable_res(hw, blk, prof_id, ena_mask);
3370 /* store enabled masks with profile so that they can be freed later */
3371 hw->blk[blk].es.mask_ena[prof_id] = ena_mask;
3377 * ice_write_es - write an extraction sequence to hardware
3378 * @hw: pointer to the HW struct
3379 * @blk: the block in which to write the extraction sequence
3380 * @prof_id: the profile ID to write
3381 * @fv: pointer to the extraction sequence to write - NULL to clear extraction
3384 ice_write_es(struct ice_hw *hw, enum ice_block blk, u8 prof_id,
3385 struct ice_fv_word *fv)
3389 off = prof_id * hw->blk[blk].es.fvw;
3391 ice_memset(&hw->blk[blk].es.t[off], 0, hw->blk[blk].es.fvw *
3392 sizeof(*fv), ICE_NONDMA_MEM);
3393 hw->blk[blk].es.written[prof_id] = false;
3395 ice_memcpy(&hw->blk[blk].es.t[off], fv, hw->blk[blk].es.fvw *
3396 sizeof(*fv), ICE_NONDMA_TO_NONDMA);
3401 * ice_prof_dec_ref - decrement reference count for profile
3402 * @hw: pointer to the HW struct
3403 * @blk: the block from which to free the profile ID
3404 * @prof_id: the profile ID for which to decrement the reference count
3406 static enum ice_status
3407 ice_prof_dec_ref(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
3409 if (prof_id > hw->blk[blk].es.count)
3410 return ICE_ERR_PARAM;
3412 if (hw->blk[blk].es.ref_count[prof_id] > 0) {
3413 if (!--hw->blk[blk].es.ref_count[prof_id]) {
3414 ice_write_es(hw, blk, prof_id, NULL);
3415 ice_free_prof_masks(hw, blk, prof_id);
3416 return ice_free_prof_id(hw, blk, prof_id);
3423 /* Block / table section IDs */
3424 static const u32 ice_blk_sids[ICE_BLK_COUNT][ICE_SID_OFF_COUNT] = {
3428 ICE_SID_PROFID_TCAM_SW,
3429 ICE_SID_PROFID_REDIR_SW,
3436 ICE_SID_PROFID_TCAM_ACL,
3437 ICE_SID_PROFID_REDIR_ACL,
3444 ICE_SID_PROFID_TCAM_FD,
3445 ICE_SID_PROFID_REDIR_FD,
3452 ICE_SID_PROFID_TCAM_RSS,
3453 ICE_SID_PROFID_REDIR_RSS,
3460 ICE_SID_PROFID_TCAM_PE,
3461 ICE_SID_PROFID_REDIR_PE,
3467 * ice_init_sw_xlt1_db - init software XLT1 database from HW tables
3468 * @hw: pointer to the hardware structure
3469 * @blk: the HW block to initialize
3471 static void ice_init_sw_xlt1_db(struct ice_hw *hw, enum ice_block blk)
3475 for (pt = 0; pt < hw->blk[blk].xlt1.count; pt++) {
3478 ptg = hw->blk[blk].xlt1.t[pt];
3479 if (ptg != ICE_DEFAULT_PTG) {
3480 ice_ptg_alloc_val(hw, blk, ptg);
3481 ice_ptg_add_mv_ptype(hw, blk, pt, ptg);
3487 * ice_init_sw_xlt2_db - init software XLT2 database from HW tables
3488 * @hw: pointer to the hardware structure
3489 * @blk: the HW block to initialize
3491 static void ice_init_sw_xlt2_db(struct ice_hw *hw, enum ice_block blk)
3495 for (vsi = 0; vsi < hw->blk[blk].xlt2.count; vsi++) {
3498 vsig = hw->blk[blk].xlt2.t[vsi];
3500 ice_vsig_alloc_val(hw, blk, vsig);
3501 ice_vsig_add_mv_vsi(hw, blk, vsi, vsig);
3502 /* no changes at this time, since this has been
3503 * initialized from the original package
3505 hw->blk[blk].xlt2.vsis[vsi].changed = 0;
3511 * ice_init_sw_db - init software database from HW tables
3512 * @hw: pointer to the hardware structure
3514 static void ice_init_sw_db(struct ice_hw *hw)
3518 for (i = 0; i < ICE_BLK_COUNT; i++) {
3519 ice_init_sw_xlt1_db(hw, (enum ice_block)i);
3520 ice_init_sw_xlt2_db(hw, (enum ice_block)i);
3525 * ice_fill_tbl - Reads content of a single table type into database
3526 * @hw: pointer to the hardware structure
3527 * @block_id: Block ID of the table to copy
3528 * @sid: Section ID of the table to copy
3530 * Will attempt to read the entire content of a given table of a single block
3531 * into the driver database. We assume that the buffer will always
3532 * be as large or larger than the data contained in the package. If
3533 * this condition is not met, there is most likely an error in the package
3536 static void ice_fill_tbl(struct ice_hw *hw, enum ice_block block_id, u32 sid)
3538 u32 dst_len, sect_len, offset = 0;
3539 struct ice_prof_redir_section *pr;
3540 struct ice_prof_id_section *pid;
3541 struct ice_xlt1_section *xlt1;
3542 struct ice_xlt2_section *xlt2;
3543 struct ice_sw_fv_section *es;
3544 struct ice_pkg_enum state;
3548 /* if the HW segment pointer is null then the first iteration of
3549 * ice_pkg_enum_section() will fail. In this case the HW tables will
3550 * not be filled and return success.
3553 ice_debug(hw, ICE_DBG_PKG, "hw->seg is NULL, tables are not filled\n");
3557 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
3559 sect = ice_pkg_enum_section(hw->seg, &state, sid);
3563 case ICE_SID_XLT1_SW:
3564 case ICE_SID_XLT1_FD:
3565 case ICE_SID_XLT1_RSS:
3566 case ICE_SID_XLT1_ACL:
3567 case ICE_SID_XLT1_PE:
3568 xlt1 = (struct ice_xlt1_section *)sect;
3570 sect_len = LE16_TO_CPU(xlt1->count) *
3571 sizeof(*hw->blk[block_id].xlt1.t);
3572 dst = hw->blk[block_id].xlt1.t;
3573 dst_len = hw->blk[block_id].xlt1.count *
3574 sizeof(*hw->blk[block_id].xlt1.t);
3576 case ICE_SID_XLT2_SW:
3577 case ICE_SID_XLT2_FD:
3578 case ICE_SID_XLT2_RSS:
3579 case ICE_SID_XLT2_ACL:
3580 case ICE_SID_XLT2_PE:
3581 xlt2 = (struct ice_xlt2_section *)sect;
3582 src = (_FORCE_ u8 *)xlt2->value;
3583 sect_len = LE16_TO_CPU(xlt2->count) *
3584 sizeof(*hw->blk[block_id].xlt2.t);
3585 dst = (u8 *)hw->blk[block_id].xlt2.t;
3586 dst_len = hw->blk[block_id].xlt2.count *
3587 sizeof(*hw->blk[block_id].xlt2.t);
3589 case ICE_SID_PROFID_TCAM_SW:
3590 case ICE_SID_PROFID_TCAM_FD:
3591 case ICE_SID_PROFID_TCAM_RSS:
3592 case ICE_SID_PROFID_TCAM_ACL:
3593 case ICE_SID_PROFID_TCAM_PE:
3594 pid = (struct ice_prof_id_section *)sect;
3595 src = (u8 *)pid->entry;
3596 sect_len = LE16_TO_CPU(pid->count) *
3597 sizeof(*hw->blk[block_id].prof.t);
3598 dst = (u8 *)hw->blk[block_id].prof.t;
3599 dst_len = hw->blk[block_id].prof.count *
3600 sizeof(*hw->blk[block_id].prof.t);
3602 case ICE_SID_PROFID_REDIR_SW:
3603 case ICE_SID_PROFID_REDIR_FD:
3604 case ICE_SID_PROFID_REDIR_RSS:
3605 case ICE_SID_PROFID_REDIR_ACL:
3606 case ICE_SID_PROFID_REDIR_PE:
3607 pr = (struct ice_prof_redir_section *)sect;
3608 src = pr->redir_value;
3609 sect_len = LE16_TO_CPU(pr->count) *
3610 sizeof(*hw->blk[block_id].prof_redir.t);
3611 dst = hw->blk[block_id].prof_redir.t;
3612 dst_len = hw->blk[block_id].prof_redir.count *
3613 sizeof(*hw->blk[block_id].prof_redir.t);
3615 case ICE_SID_FLD_VEC_SW:
3616 case ICE_SID_FLD_VEC_FD:
3617 case ICE_SID_FLD_VEC_RSS:
3618 case ICE_SID_FLD_VEC_ACL:
3619 case ICE_SID_FLD_VEC_PE:
3620 es = (struct ice_sw_fv_section *)sect;
3622 sect_len = (u32)(LE16_TO_CPU(es->count) *
3623 hw->blk[block_id].es.fvw) *
3624 sizeof(*hw->blk[block_id].es.t);
3625 dst = (u8 *)hw->blk[block_id].es.t;
3626 dst_len = (u32)(hw->blk[block_id].es.count *
3627 hw->blk[block_id].es.fvw) *
3628 sizeof(*hw->blk[block_id].es.t);
3634 /* if the section offset exceeds destination length, terminate
3637 if (offset > dst_len)
3640 /* if the sum of section size and offset exceed destination size
3641 * then we are out of bounds of the HW table size for that PF.
3642 * Changing section length to fill the remaining table space
3645 if ((offset + sect_len) > dst_len)
3646 sect_len = dst_len - offset;
3648 ice_memcpy(dst + offset, src, sect_len, ICE_NONDMA_TO_NONDMA);
3650 sect = ice_pkg_enum_section(NULL, &state, sid);
3655 * ice_fill_blk_tbls - Read package context for tables
3656 * @hw: pointer to the hardware structure
3658 * Reads the current package contents and populates the driver
3659 * database with the data iteratively for all advanced feature
3660 * blocks. Assume that the HW tables have been allocated.
3662 void ice_fill_blk_tbls(struct ice_hw *hw)
3666 for (i = 0; i < ICE_BLK_COUNT; i++) {
3667 enum ice_block blk_id = (enum ice_block)i;
3669 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].xlt1.sid);
3670 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].xlt2.sid);
3671 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].prof.sid);
3672 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].prof_redir.sid);
3673 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].es.sid);
3680 * ice_free_prof_map - free profile map
3681 * @hw: pointer to the hardware structure
3682 * @blk_idx: HW block index
3684 static void ice_free_prof_map(struct ice_hw *hw, u8 blk_idx)
3686 struct ice_es *es = &hw->blk[blk_idx].es;
3687 struct ice_prof_map *del, *tmp;
3689 ice_acquire_lock(&es->prof_map_lock);
3690 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &es->prof_map,
3691 ice_prof_map, list) {
3692 LIST_DEL(&del->list);
3695 INIT_LIST_HEAD(&es->prof_map);
3696 ice_release_lock(&es->prof_map_lock);
3700 * ice_free_flow_profs - free flow profile entries
3701 * @hw: pointer to the hardware structure
3702 * @blk_idx: HW block index
3704 static void ice_free_flow_profs(struct ice_hw *hw, u8 blk_idx)
3706 struct ice_flow_prof *p, *tmp;
3708 ice_acquire_lock(&hw->fl_profs_locks[blk_idx]);
3709 LIST_FOR_EACH_ENTRY_SAFE(p, tmp, &hw->fl_profs[blk_idx],
3710 ice_flow_prof, l_entry) {
3711 struct ice_flow_entry *e, *t;
3713 LIST_FOR_EACH_ENTRY_SAFE(e, t, &p->entries,
3714 ice_flow_entry, l_entry)
3715 ice_flow_rem_entry(hw, (enum ice_block)blk_idx,
3716 ICE_FLOW_ENTRY_HNDL(e));
3718 LIST_DEL(&p->l_entry);
3720 ice_free(hw, p->acts);
3722 ice_destroy_lock(&p->entries_lock);
3725 ice_release_lock(&hw->fl_profs_locks[blk_idx]);
3727 /* if driver is in reset and tables are being cleared
3728 * re-initialize the flow profile list heads
3730 INIT_LIST_HEAD(&hw->fl_profs[blk_idx]);
3734 * ice_free_vsig_tbl - free complete VSIG table entries
3735 * @hw: pointer to the hardware structure
3736 * @blk: the HW block on which to free the VSIG table entries
3738 static void ice_free_vsig_tbl(struct ice_hw *hw, enum ice_block blk)
3742 if (!hw->blk[blk].xlt2.vsig_tbl)
3745 for (i = 1; i < ICE_MAX_VSIGS; i++)
3746 if (hw->blk[blk].xlt2.vsig_tbl[i].in_use)
3747 ice_vsig_free(hw, blk, i);
3751 * ice_free_hw_tbls - free hardware table memory
3752 * @hw: pointer to the hardware structure
3754 void ice_free_hw_tbls(struct ice_hw *hw)
3756 struct ice_rss_cfg *r, *rt;
3759 for (i = 0; i < ICE_BLK_COUNT; i++) {
3760 if (hw->blk[i].is_list_init) {
3761 struct ice_es *es = &hw->blk[i].es;
3763 ice_free_prof_map(hw, i);
3764 ice_destroy_lock(&es->prof_map_lock);
3765 ice_free_flow_profs(hw, i);
3766 ice_destroy_lock(&hw->fl_profs_locks[i]);
3768 hw->blk[i].is_list_init = false;
3770 ice_free_vsig_tbl(hw, (enum ice_block)i);
3771 ice_free(hw, hw->blk[i].xlt1.ptypes);
3772 ice_free(hw, hw->blk[i].xlt1.ptg_tbl);
3773 ice_free(hw, hw->blk[i].xlt1.t);
3774 ice_free(hw, hw->blk[i].xlt2.t);
3775 ice_free(hw, hw->blk[i].xlt2.vsig_tbl);
3776 ice_free(hw, hw->blk[i].xlt2.vsis);
3777 ice_free(hw, hw->blk[i].prof.t);
3778 ice_free(hw, hw->blk[i].prof_redir.t);
3779 ice_free(hw, hw->blk[i].es.t);
3780 ice_free(hw, hw->blk[i].es.ref_count);
3781 ice_free(hw, hw->blk[i].es.written);
3782 ice_free(hw, hw->blk[i].es.mask_ena);
3785 LIST_FOR_EACH_ENTRY_SAFE(r, rt, &hw->rss_list_head,
3786 ice_rss_cfg, l_entry) {
3787 LIST_DEL(&r->l_entry);
3790 ice_destroy_lock(&hw->rss_locks);
3791 if (!hw->dcf_enabled)
3792 ice_shutdown_all_prof_masks(hw);
3793 ice_memset(hw->blk, 0, sizeof(hw->blk), ICE_NONDMA_MEM);
3797 * ice_init_flow_profs - init flow profile locks and list heads
3798 * @hw: pointer to the hardware structure
3799 * @blk_idx: HW block index
3801 static void ice_init_flow_profs(struct ice_hw *hw, u8 blk_idx)
3803 ice_init_lock(&hw->fl_profs_locks[blk_idx]);
3804 INIT_LIST_HEAD(&hw->fl_profs[blk_idx]);
3808 * ice_clear_hw_tbls - clear HW tables and flow profiles
3809 * @hw: pointer to the hardware structure
3811 void ice_clear_hw_tbls(struct ice_hw *hw)
3815 for (i = 0; i < ICE_BLK_COUNT; i++) {
3816 struct ice_prof_redir *prof_redir = &hw->blk[i].prof_redir;
3817 struct ice_prof_tcam *prof = &hw->blk[i].prof;
3818 struct ice_xlt1 *xlt1 = &hw->blk[i].xlt1;
3819 struct ice_xlt2 *xlt2 = &hw->blk[i].xlt2;
3820 struct ice_es *es = &hw->blk[i].es;
3822 if (hw->blk[i].is_list_init) {
3823 ice_free_prof_map(hw, i);
3824 ice_free_flow_profs(hw, i);
3827 ice_free_vsig_tbl(hw, (enum ice_block)i);
3829 ice_memset(xlt1->ptypes, 0, xlt1->count * sizeof(*xlt1->ptypes),
3831 ice_memset(xlt1->ptg_tbl, 0,
3832 ICE_MAX_PTGS * sizeof(*xlt1->ptg_tbl),
3834 ice_memset(xlt1->t, 0, xlt1->count * sizeof(*xlt1->t),
3837 ice_memset(xlt2->vsis, 0, xlt2->count * sizeof(*xlt2->vsis),
3839 ice_memset(xlt2->vsig_tbl, 0,
3840 xlt2->count * sizeof(*xlt2->vsig_tbl),
3842 ice_memset(xlt2->t, 0, xlt2->count * sizeof(*xlt2->t),
3845 ice_memset(prof->t, 0, prof->count * sizeof(*prof->t),
3847 ice_memset(prof_redir->t, 0,
3848 prof_redir->count * sizeof(*prof_redir->t),
3851 ice_memset(es->t, 0, es->count * sizeof(*es->t) * es->fvw,
3853 ice_memset(es->ref_count, 0, es->count * sizeof(*es->ref_count),
3855 ice_memset(es->written, 0, es->count * sizeof(*es->written),
3857 ice_memset(es->mask_ena, 0, es->count * sizeof(*es->mask_ena),
3863 * ice_init_hw_tbls - init hardware table memory
3864 * @hw: pointer to the hardware structure
3866 enum ice_status ice_init_hw_tbls(struct ice_hw *hw)
3870 ice_init_lock(&hw->rss_locks);
3871 INIT_LIST_HEAD(&hw->rss_list_head);
3872 if (!hw->dcf_enabled)
3873 ice_init_all_prof_masks(hw);
3874 for (i = 0; i < ICE_BLK_COUNT; i++) {
3875 struct ice_prof_redir *prof_redir = &hw->blk[i].prof_redir;
3876 struct ice_prof_tcam *prof = &hw->blk[i].prof;
3877 struct ice_xlt1 *xlt1 = &hw->blk[i].xlt1;
3878 struct ice_xlt2 *xlt2 = &hw->blk[i].xlt2;
3879 struct ice_es *es = &hw->blk[i].es;
3882 if (hw->blk[i].is_list_init)
3885 ice_init_flow_profs(hw, i);
3886 ice_init_lock(&es->prof_map_lock);
3887 INIT_LIST_HEAD(&es->prof_map);
3888 hw->blk[i].is_list_init = true;
3890 hw->blk[i].overwrite = blk_sizes[i].overwrite;
3891 es->reverse = blk_sizes[i].reverse;
3893 xlt1->sid = ice_blk_sids[i][ICE_SID_XLT1_OFF];
3894 xlt1->count = blk_sizes[i].xlt1;
3896 xlt1->ptypes = (struct ice_ptg_ptype *)
3897 ice_calloc(hw, xlt1->count, sizeof(*xlt1->ptypes));
3902 xlt1->ptg_tbl = (struct ice_ptg_entry *)
3903 ice_calloc(hw, ICE_MAX_PTGS, sizeof(*xlt1->ptg_tbl));
3908 xlt1->t = (u8 *)ice_calloc(hw, xlt1->count, sizeof(*xlt1->t));
3912 xlt2->sid = ice_blk_sids[i][ICE_SID_XLT2_OFF];
3913 xlt2->count = blk_sizes[i].xlt2;
3915 xlt2->vsis = (struct ice_vsig_vsi *)
3916 ice_calloc(hw, xlt2->count, sizeof(*xlt2->vsis));
3921 xlt2->vsig_tbl = (struct ice_vsig_entry *)
3922 ice_calloc(hw, xlt2->count, sizeof(*xlt2->vsig_tbl));
3923 if (!xlt2->vsig_tbl)
3926 for (j = 0; j < xlt2->count; j++)
3927 INIT_LIST_HEAD(&xlt2->vsig_tbl[j].prop_lst);
3929 xlt2->t = (u16 *)ice_calloc(hw, xlt2->count, sizeof(*xlt2->t));
3933 prof->sid = ice_blk_sids[i][ICE_SID_PR_OFF];
3934 prof->count = blk_sizes[i].prof_tcam;
3935 prof->max_prof_id = blk_sizes[i].prof_id;
3936 prof->cdid_bits = blk_sizes[i].prof_cdid_bits;
3937 prof->t = (struct ice_prof_tcam_entry *)
3938 ice_calloc(hw, prof->count, sizeof(*prof->t));
3943 prof_redir->sid = ice_blk_sids[i][ICE_SID_PR_REDIR_OFF];
3944 prof_redir->count = blk_sizes[i].prof_redir;
3945 prof_redir->t = (u8 *)ice_calloc(hw, prof_redir->count,
3946 sizeof(*prof_redir->t));
3951 es->sid = ice_blk_sids[i][ICE_SID_ES_OFF];
3952 es->count = blk_sizes[i].es;
3953 es->fvw = blk_sizes[i].fvw;
3954 es->t = (struct ice_fv_word *)
3955 ice_calloc(hw, (u32)(es->count * es->fvw),
3960 es->ref_count = (u16 *)
3961 ice_calloc(hw, es->count, sizeof(*es->ref_count));
3966 es->written = (u8 *)
3967 ice_calloc(hw, es->count, sizeof(*es->written));
3972 es->mask_ena = (u32 *)
3973 ice_calloc(hw, es->count, sizeof(*es->mask_ena));
3981 ice_free_hw_tbls(hw);
3982 return ICE_ERR_NO_MEMORY;
3986 * ice_prof_gen_key - generate profile ID key
3987 * @hw: pointer to the HW struct
3988 * @blk: the block in which to write profile ID to
3989 * @ptg: packet type group (PTG) portion of key
3990 * @vsig: VSIG portion of key
3991 * @cdid: CDID portion of key
3992 * @flags: flag portion of key
3993 * @vl_msk: valid mask
3994 * @dc_msk: don't care mask
3995 * @nm_msk: never match mask
3996 * @key: output of profile ID key
3998 static enum ice_status
3999 ice_prof_gen_key(struct ice_hw *hw, enum ice_block blk, u8 ptg, u16 vsig,
4000 u8 cdid, u16 flags, u8 vl_msk[ICE_TCAM_KEY_VAL_SZ],
4001 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ], u8 nm_msk[ICE_TCAM_KEY_VAL_SZ],
4002 u8 key[ICE_TCAM_KEY_SZ])
4004 struct ice_prof_id_key inkey;
4007 inkey.xlt2_cdid = CPU_TO_LE16(vsig);
4008 inkey.flags = CPU_TO_LE16(flags);
4010 switch (hw->blk[blk].prof.cdid_bits) {
4014 #define ICE_CD_2_M 0xC000U
4015 #define ICE_CD_2_S 14
4016 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_2_M);
4017 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_2_S);
4020 #define ICE_CD_4_M 0xF000U
4021 #define ICE_CD_4_S 12
4022 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_4_M);
4023 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_4_S);
4026 #define ICE_CD_8_M 0xFF00U
4027 #define ICE_CD_8_S 16
4028 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_8_M);
4029 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_8_S);
4032 ice_debug(hw, ICE_DBG_PKG, "Error in profile config\n");
4036 return ice_set_key(key, ICE_TCAM_KEY_SZ, (u8 *)&inkey, vl_msk, dc_msk,
4037 nm_msk, 0, ICE_TCAM_KEY_SZ / 2);
4041 * ice_tcam_write_entry - write TCAM entry
4042 * @hw: pointer to the HW struct
4043 * @blk: the block in which to write profile ID to
4044 * @idx: the entry index to write to
4045 * @prof_id: profile ID
4046 * @ptg: packet type group (PTG) portion of key
4047 * @vsig: VSIG portion of key
4048 * @cdid: CDID portion of key
4049 * @flags: flag portion of key
4050 * @vl_msk: valid mask
4051 * @dc_msk: don't care mask
4052 * @nm_msk: never match mask
4054 static enum ice_status
4055 ice_tcam_write_entry(struct ice_hw *hw, enum ice_block blk, u16 idx,
4056 u8 prof_id, u8 ptg, u16 vsig, u8 cdid, u16 flags,
4057 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ],
4058 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ],
4059 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ])
4061 struct ice_prof_tcam_entry;
4062 enum ice_status status;
4064 status = ice_prof_gen_key(hw, blk, ptg, vsig, cdid, flags, vl_msk,
4065 dc_msk, nm_msk, hw->blk[blk].prof.t[idx].key);
4067 hw->blk[blk].prof.t[idx].addr = CPU_TO_LE16(idx);
4068 hw->blk[blk].prof.t[idx].prof_id = prof_id;
4075 * ice_vsig_get_ref - returns number of VSIs belong to a VSIG
4076 * @hw: pointer to the hardware structure
4078 * @vsig: VSIG to query
4079 * @refs: pointer to variable to receive the reference count
4081 static enum ice_status
4082 ice_vsig_get_ref(struct ice_hw *hw, enum ice_block blk, u16 vsig, u16 *refs)
4084 u16 idx = vsig & ICE_VSIG_IDX_M;
4085 struct ice_vsig_vsi *ptr;
4089 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
4090 return ICE_ERR_DOES_NOT_EXIST;
4092 ptr = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
4095 ptr = ptr->next_vsi;
4102 * ice_has_prof_vsig - check to see if VSIG has a specific profile
4103 * @hw: pointer to the hardware structure
4105 * @vsig: VSIG to check against
4106 * @hdl: profile handle
4109 ice_has_prof_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl)
4111 u16 idx = vsig & ICE_VSIG_IDX_M;
4112 struct ice_vsig_prof *ent;
4114 LIST_FOR_EACH_ENTRY(ent, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4115 ice_vsig_prof, list)
4116 if (ent->profile_cookie == hdl)
4119 ice_debug(hw, ICE_DBG_INIT, "Characteristic list for VSI group %d not found.\n",
4125 * ice_prof_bld_es - build profile ID extraction sequence changes
4126 * @hw: pointer to the HW struct
4127 * @blk: hardware block
4128 * @bld: the update package buffer build to add to
4129 * @chgs: the list of changes to make in hardware
4131 static enum ice_status
4132 ice_prof_bld_es(struct ice_hw *hw, enum ice_block blk,
4133 struct ice_buf_build *bld, struct LIST_HEAD_TYPE *chgs)
4135 u16 vec_size = hw->blk[blk].es.fvw * sizeof(struct ice_fv_word);
4136 struct ice_chs_chg *tmp;
4138 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry)
4139 if (tmp->type == ICE_PTG_ES_ADD && tmp->add_prof) {
4140 u16 off = tmp->prof_id * hw->blk[blk].es.fvw;
4141 struct ice_pkg_es *p;
4144 id = ice_sect_id(blk, ICE_VEC_TBL);
4145 p = (struct ice_pkg_es *)
4146 ice_pkg_buf_alloc_section(bld, id,
4147 ice_struct_size(p, es,
4153 return ICE_ERR_MAX_LIMIT;
4155 p->count = CPU_TO_LE16(1);
4156 p->offset = CPU_TO_LE16(tmp->prof_id);
4158 ice_memcpy(p->es, &hw->blk[blk].es.t[off], vec_size,
4159 ICE_NONDMA_TO_NONDMA);
4166 * ice_prof_bld_tcam - build profile ID TCAM changes
4167 * @hw: pointer to the HW struct
4168 * @blk: hardware block
4169 * @bld: the update package buffer build to add to
4170 * @chgs: the list of changes to make in hardware
4172 static enum ice_status
4173 ice_prof_bld_tcam(struct ice_hw *hw, enum ice_block blk,
4174 struct ice_buf_build *bld, struct LIST_HEAD_TYPE *chgs)
4176 struct ice_chs_chg *tmp;
4178 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry)
4179 if (tmp->type == ICE_TCAM_ADD && tmp->add_tcam_idx) {
4180 struct ice_prof_id_section *p;
4183 id = ice_sect_id(blk, ICE_PROF_TCAM);
4184 p = (struct ice_prof_id_section *)
4185 ice_pkg_buf_alloc_section(bld, id,
4191 return ICE_ERR_MAX_LIMIT;
4193 p->count = CPU_TO_LE16(1);
4194 p->entry[0].addr = CPU_TO_LE16(tmp->tcam_idx);
4195 p->entry[0].prof_id = tmp->prof_id;
4197 ice_memcpy(p->entry[0].key,
4198 &hw->blk[blk].prof.t[tmp->tcam_idx].key,
4199 sizeof(hw->blk[blk].prof.t->key),
4200 ICE_NONDMA_TO_NONDMA);
4207 * ice_prof_bld_xlt1 - build XLT1 changes
4208 * @blk: hardware block
4209 * @bld: the update package buffer build to add to
4210 * @chgs: the list of changes to make in hardware
4212 static enum ice_status
4213 ice_prof_bld_xlt1(enum ice_block blk, struct ice_buf_build *bld,
4214 struct LIST_HEAD_TYPE *chgs)
4216 struct ice_chs_chg *tmp;
4218 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry)
4219 if (tmp->type == ICE_PTG_ES_ADD && tmp->add_ptg) {
4220 struct ice_xlt1_section *p;
4223 id = ice_sect_id(blk, ICE_XLT1);
4224 p = (struct ice_xlt1_section *)
4225 ice_pkg_buf_alloc_section(bld, id,
4231 return ICE_ERR_MAX_LIMIT;
4233 p->count = CPU_TO_LE16(1);
4234 p->offset = CPU_TO_LE16(tmp->ptype);
4235 p->value[0] = tmp->ptg;
4242 * ice_prof_bld_xlt2 - build XLT2 changes
4243 * @blk: hardware block
4244 * @bld: the update package buffer build to add to
4245 * @chgs: the list of changes to make in hardware
4247 static enum ice_status
4248 ice_prof_bld_xlt2(enum ice_block blk, struct ice_buf_build *bld,
4249 struct LIST_HEAD_TYPE *chgs)
4251 struct ice_chs_chg *tmp;
4253 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
4254 struct ice_xlt2_section *p;
4257 switch (tmp->type) {
4261 id = ice_sect_id(blk, ICE_XLT2);
4262 p = (struct ice_xlt2_section *)
4263 ice_pkg_buf_alloc_section(bld, id,
4269 return ICE_ERR_MAX_LIMIT;
4271 p->count = CPU_TO_LE16(1);
4272 p->offset = CPU_TO_LE16(tmp->vsi);
4273 p->value[0] = CPU_TO_LE16(tmp->vsig);
4284 * ice_upd_prof_hw - update hardware using the change list
4285 * @hw: pointer to the HW struct
4286 * @blk: hardware block
4287 * @chgs: the list of changes to make in hardware
4289 static enum ice_status
4290 ice_upd_prof_hw(struct ice_hw *hw, enum ice_block blk,
4291 struct LIST_HEAD_TYPE *chgs)
4293 struct ice_buf_build *b;
4294 struct ice_chs_chg *tmp;
4295 enum ice_status status;
4303 /* count number of sections we need */
4304 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
4305 switch (tmp->type) {
4306 case ICE_PTG_ES_ADD:
4324 sects = xlt1 + xlt2 + tcam + es;
4329 /* Build update package buffer */
4330 b = ice_pkg_buf_alloc(hw);
4332 return ICE_ERR_NO_MEMORY;
4334 status = ice_pkg_buf_reserve_section(b, sects);
4338 /* Preserve order of table update: ES, TCAM, PTG, VSIG */
4340 status = ice_prof_bld_es(hw, blk, b, chgs);
4346 status = ice_prof_bld_tcam(hw, blk, b, chgs);
4352 status = ice_prof_bld_xlt1(blk, b, chgs);
4358 status = ice_prof_bld_xlt2(blk, b, chgs);
4363 /* After package buffer build check if the section count in buffer is
4364 * non-zero and matches the number of sections detected for package
4367 pkg_sects = ice_pkg_buf_get_active_sections(b);
4368 if (!pkg_sects || pkg_sects != sects) {
4369 status = ICE_ERR_INVAL_SIZE;
4373 /* update package */
4374 status = ice_update_pkg(hw, ice_pkg_buf(b), 1);
4375 if (status == ICE_ERR_AQ_ERROR)
4376 ice_debug(hw, ICE_DBG_INIT, "Unable to update HW profile\n");
4379 ice_pkg_buf_free(hw, b);
4384 * ice_update_fd_mask - set Flow Director Field Vector mask for a profile
4385 * @hw: pointer to the HW struct
4386 * @prof_id: profile ID
4387 * @mask_sel: mask select
4389 * This function enable any of the masks selected by the mask select parameter
4390 * for the profile specified.
4392 static void ice_update_fd_mask(struct ice_hw *hw, u16 prof_id, u32 mask_sel)
4394 wr32(hw, GLQF_FDMASK_SEL(prof_id), mask_sel);
4396 ice_debug(hw, ICE_DBG_INIT, "fd mask(%d): %x = %x\n", prof_id,
4397 GLQF_FDMASK_SEL(prof_id), mask_sel);
4400 struct ice_fd_src_dst_pair {
4406 static const struct ice_fd_src_dst_pair ice_fd_pairs[] = {
4407 /* These are defined in pairs */
4408 { ICE_PROT_IPV4_OF_OR_S, 2, 12 },
4409 { ICE_PROT_IPV4_OF_OR_S, 2, 16 },
4411 { ICE_PROT_IPV4_IL, 2, 12 },
4412 { ICE_PROT_IPV4_IL, 2, 16 },
4414 { ICE_PROT_IPV6_OF_OR_S, 8, 8 },
4415 { ICE_PROT_IPV6_OF_OR_S, 8, 24 },
4417 { ICE_PROT_IPV6_IL, 8, 8 },
4418 { ICE_PROT_IPV6_IL, 8, 24 },
4420 { ICE_PROT_TCP_IL, 1, 0 },
4421 { ICE_PROT_TCP_IL, 1, 2 },
4423 { ICE_PROT_UDP_OF, 1, 0 },
4424 { ICE_PROT_UDP_OF, 1, 2 },
4426 { ICE_PROT_UDP_IL_OR_S, 1, 0 },
4427 { ICE_PROT_UDP_IL_OR_S, 1, 2 },
4429 { ICE_PROT_SCTP_IL, 1, 0 },
4430 { ICE_PROT_SCTP_IL, 1, 2 }
4433 #define ICE_FD_SRC_DST_PAIR_COUNT ARRAY_SIZE(ice_fd_pairs)
4436 * ice_update_fd_swap - set register appropriately for a FD FV extraction
4437 * @hw: pointer to the HW struct
4438 * @prof_id: profile ID
4439 * @es: extraction sequence (length of array is determined by the block)
4441 static enum ice_status
4442 ice_update_fd_swap(struct ice_hw *hw, u16 prof_id, struct ice_fv_word *es)
4444 ice_declare_bitmap(pair_list, ICE_FD_SRC_DST_PAIR_COUNT);
4445 u8 pair_start[ICE_FD_SRC_DST_PAIR_COUNT] = { 0 };
4446 #define ICE_FD_FV_NOT_FOUND (-2)
4447 s8 first_free = ICE_FD_FV_NOT_FOUND;
4448 u8 used[ICE_MAX_FV_WORDS] = { 0 };
4453 ice_zero_bitmap(pair_list, ICE_FD_SRC_DST_PAIR_COUNT);
4455 /* This code assumes that the Flow Director field vectors are assigned
4456 * from the end of the FV indexes working towards the zero index, that
4457 * only complete fields will be included and will be consecutive, and
4458 * that there are no gaps between valid indexes.
4461 /* Determine swap fields present */
4462 for (i = 0; i < hw->blk[ICE_BLK_FD].es.fvw; i++) {
4463 /* Find the first free entry, assuming right to left population.
4464 * This is where we can start adding additional pairs if needed.
4466 if (first_free == ICE_FD_FV_NOT_FOUND && es[i].prot_id !=
4470 for (j = 0; j < ICE_FD_SRC_DST_PAIR_COUNT; j++)
4471 if (es[i].prot_id == ice_fd_pairs[j].prot_id &&
4472 es[i].off == ice_fd_pairs[j].off) {
4473 ice_set_bit(j, pair_list);
4478 orig_free = first_free;
4480 /* determine missing swap fields that need to be added */
4481 for (i = 0; i < ICE_FD_SRC_DST_PAIR_COUNT; i += 2) {
4482 u8 bit1 = ice_is_bit_set(pair_list, i + 1);
4483 u8 bit0 = ice_is_bit_set(pair_list, i);
4488 /* add the appropriate 'paired' entry */
4494 /* check for room */
4495 if (first_free + 1 < (s8)ice_fd_pairs[index].count)
4496 return ICE_ERR_MAX_LIMIT;
4498 /* place in extraction sequence */
4499 for (k = 0; k < ice_fd_pairs[index].count; k++) {
4500 es[first_free - k].prot_id =
4501 ice_fd_pairs[index].prot_id;
4502 es[first_free - k].off =
4503 ice_fd_pairs[index].off + (k * 2);
4506 return ICE_ERR_OUT_OF_RANGE;
4508 /* keep track of non-relevant fields */
4509 mask_sel |= BIT(first_free - k);
4512 pair_start[index] = first_free;
4513 first_free -= ice_fd_pairs[index].count;
4517 /* fill in the swap array */
4518 si = hw->blk[ICE_BLK_FD].es.fvw - 1;
4520 u8 indexes_used = 1;
4522 /* assume flat at this index */
4523 #define ICE_SWAP_VALID 0x80
4524 used[si] = si | ICE_SWAP_VALID;
4526 if (orig_free == ICE_FD_FV_NOT_FOUND || si <= orig_free) {
4531 /* check for a swap location */
4532 for (j = 0; j < ICE_FD_SRC_DST_PAIR_COUNT; j++)
4533 if (es[si].prot_id == ice_fd_pairs[j].prot_id &&
4534 es[si].off == ice_fd_pairs[j].off) {
4537 /* determine the appropriate matching field */
4538 idx = j + ((j % 2) ? -1 : 1);
4540 indexes_used = ice_fd_pairs[idx].count;
4541 for (k = 0; k < indexes_used; k++) {
4542 used[si - k] = (pair_start[idx] - k) |
4552 /* for each set of 4 swap and 4 inset indexes, write the appropriate
4555 for (j = 0; j < hw->blk[ICE_BLK_FD].es.fvw / 4; j++) {
4559 for (k = 0; k < 4; k++) {
4563 if (used[idx] && !(mask_sel & BIT(idx))) {
4564 raw_swap |= used[idx] << (k * BITS_PER_BYTE);
4565 #define ICE_INSET_DFLT 0x9f
4566 raw_in |= ICE_INSET_DFLT << (k * BITS_PER_BYTE);
4570 /* write the appropriate swap register set */
4571 wr32(hw, GLQF_FDSWAP(prof_id, j), raw_swap);
4573 ice_debug(hw, ICE_DBG_INIT, "swap wr(%d, %d): %x = %08x\n",
4574 prof_id, j, GLQF_FDSWAP(prof_id, j), raw_swap);
4576 /* write the appropriate inset register set */
4577 wr32(hw, GLQF_FDINSET(prof_id, j), raw_in);
4579 ice_debug(hw, ICE_DBG_INIT, "inset wr(%d, %d): %x = %08x\n",
4580 prof_id, j, GLQF_FDINSET(prof_id, j), raw_in);
4583 /* initially clear the mask select for this profile */
4584 ice_update_fd_mask(hw, prof_id, 0);
4589 /* The entries here needs to match the order of enum ice_ptype_attrib */
4590 static const struct ice_ptype_attrib_info ice_ptype_attributes[] = {
4591 { ICE_GTP_PDU_EH, ICE_GTP_PDU_FLAG_MASK },
4592 { ICE_GTP_SESSION, ICE_GTP_FLAGS_MASK },
4593 { ICE_GTP_DOWNLINK, ICE_GTP_FLAGS_MASK },
4594 { ICE_GTP_UPLINK, ICE_GTP_FLAGS_MASK },
4598 * ice_get_ptype_attrib_info - get ptype attribute information
4599 * @type: attribute type
4600 * @info: pointer to variable to the attribute information
4603 ice_get_ptype_attrib_info(enum ice_ptype_attrib_type type,
4604 struct ice_ptype_attrib_info *info)
4606 *info = ice_ptype_attributes[type];
4610 * ice_add_prof_attrib - add any PTG with attributes to profile
4611 * @prof: pointer to the profile to which PTG entries will be added
4612 * @ptg: PTG to be added
4613 * @ptype: PTYPE that needs to be looked up
4614 * @attr: array of attributes that will be considered
4615 * @attr_cnt: number of elements in the attribute array
4617 static enum ice_status
4618 ice_add_prof_attrib(struct ice_prof_map *prof, u8 ptg, u16 ptype,
4619 const struct ice_ptype_attributes *attr, u16 attr_cnt)
4624 for (i = 0; i < attr_cnt; i++) {
4625 if (attr[i].ptype == ptype) {
4628 prof->ptg[prof->ptg_cnt] = ptg;
4629 ice_get_ptype_attrib_info(attr[i].attrib,
4630 &prof->attr[prof->ptg_cnt]);
4632 if (++prof->ptg_cnt >= ICE_MAX_PTG_PER_PROFILE)
4633 return ICE_ERR_MAX_LIMIT;
4638 return ICE_ERR_DOES_NOT_EXIST;
4644 * ice_add_prof - add profile
4645 * @hw: pointer to the HW struct
4646 * @blk: hardware block
4647 * @id: profile tracking ID
4648 * @ptypes: array of bitmaps indicating ptypes (ICE_FLOW_PTYPE_MAX bits)
4649 * @attr: array of attributes
4650 * @attr_cnt: number of elements in attrib array
4651 * @es: extraction sequence (length of array is determined by the block)
4652 * @masks: mask for extraction sequence
4654 * This function registers a profile, which matches a set of PTYPES with a
4655 * particular extraction sequence. While the hardware profile is allocated
4656 * it will not be written until the first call to ice_add_flow that specifies
4657 * the ID value used here.
4660 ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64 id, u8 ptypes[],
4661 const struct ice_ptype_attributes *attr, u16 attr_cnt,
4662 struct ice_fv_word *es, u16 *masks)
4664 u32 bytes = DIVIDE_AND_ROUND_UP(ICE_FLOW_PTYPE_MAX, BITS_PER_BYTE);
4665 ice_declare_bitmap(ptgs_used, ICE_XLT1_CNT);
4666 struct ice_prof_map *prof;
4667 enum ice_status status;
4671 ice_zero_bitmap(ptgs_used, ICE_XLT1_CNT);
4673 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
4675 /* search for existing profile */
4676 status = ice_find_prof_id_with_mask(hw, blk, es, masks, &prof_id);
4678 /* allocate profile ID */
4679 status = ice_alloc_prof_id(hw, blk, &prof_id);
4681 goto err_ice_add_prof;
4682 if (blk == ICE_BLK_FD) {
4683 /* For Flow Director block, the extraction sequence may
4684 * need to be altered in the case where there are paired
4685 * fields that have no match. This is necessary because
4686 * for Flow Director, src and dest fields need to paired
4687 * for filter programming and these values are swapped
4690 status = ice_update_fd_swap(hw, prof_id, es);
4692 goto err_ice_add_prof;
4694 status = ice_update_prof_masking(hw, blk, prof_id, masks);
4696 goto err_ice_add_prof;
4698 /* and write new es */
4699 ice_write_es(hw, blk, prof_id, es);
4702 ice_prof_inc_ref(hw, blk, prof_id);
4704 /* add profile info */
4706 prof = (struct ice_prof_map *)ice_malloc(hw, sizeof(*prof));
4708 goto err_ice_add_prof;
4710 prof->profile_cookie = id;
4711 prof->prof_id = prof_id;
4715 /* build list of ptgs */
4716 while (bytes && prof->ptg_cnt < ICE_MAX_PTG_PER_PROFILE) {
4719 if (!ptypes[byte]) {
4725 /* Examine 8 bits per byte */
4726 ice_for_each_set_bit(bit, (ice_bitmap_t *)&ptypes[byte],
4731 ptype = byte * BITS_PER_BYTE + bit;
4733 /* The package should place all ptypes in a non-zero
4734 * PTG, so the following call should never fail.
4736 if (ice_ptg_find_ptype(hw, blk, ptype, &ptg))
4739 /* If PTG is already added, skip and continue */
4740 if (ice_is_bit_set(ptgs_used, ptg))
4743 ice_set_bit(ptg, ptgs_used);
4744 /* Check to see there are any attributes for this
4745 * ptype, and add them if found.
4747 status = ice_add_prof_attrib(prof, ptg, ptype, attr,
4749 if (status == ICE_ERR_MAX_LIMIT)
4752 /* This is simple a ptype/PTG with no
4755 prof->ptg[prof->ptg_cnt] = ptg;
4756 prof->attr[prof->ptg_cnt].flags = 0;
4757 prof->attr[prof->ptg_cnt].mask = 0;
4759 if (++prof->ptg_cnt >= ICE_MAX_PTG_PER_PROFILE)
4768 LIST_ADD(&prof->list, &hw->blk[blk].es.prof_map);
4769 status = ICE_SUCCESS;
4772 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
4777 * ice_search_prof_id - Search for a profile tracking ID
4778 * @hw: pointer to the HW struct
4779 * @blk: hardware block
4780 * @id: profile tracking ID
4782 * This will search for a profile tracking ID which was previously added.
4783 * The profile map lock should be held before calling this function.
4785 struct ice_prof_map *
4786 ice_search_prof_id(struct ice_hw *hw, enum ice_block blk, u64 id)
4788 struct ice_prof_map *entry = NULL;
4789 struct ice_prof_map *map;
4791 LIST_FOR_EACH_ENTRY(map, &hw->blk[blk].es.prof_map, ice_prof_map, list)
4792 if (map->profile_cookie == id) {
4801 * ice_vsig_prof_id_count - count profiles in a VSIG
4802 * @hw: pointer to the HW struct
4803 * @blk: hardware block
4804 * @vsig: VSIG to remove the profile from
4807 ice_vsig_prof_id_count(struct ice_hw *hw, enum ice_block blk, u16 vsig)
4809 u16 idx = vsig & ICE_VSIG_IDX_M, count = 0;
4810 struct ice_vsig_prof *p;
4812 LIST_FOR_EACH_ENTRY(p, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4813 ice_vsig_prof, list)
4820 * ice_rel_tcam_idx - release a TCAM index
4821 * @hw: pointer to the HW struct
4822 * @blk: hardware block
4823 * @idx: the index to release
4825 static enum ice_status
4826 ice_rel_tcam_idx(struct ice_hw *hw, enum ice_block blk, u16 idx)
4828 /* Masks to invoke a never match entry */
4829 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4830 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFE, 0xFF, 0xFF, 0xFF, 0xFF };
4831 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x01, 0x00, 0x00, 0x00, 0x00 };
4832 enum ice_status status;
4834 /* write the TCAM entry */
4835 status = ice_tcam_write_entry(hw, blk, idx, 0, 0, 0, 0, 0, vl_msk,
4840 /* release the TCAM entry */
4841 status = ice_free_tcam_ent(hw, blk, idx);
4847 * ice_rem_prof_id - remove one profile from a VSIG
4848 * @hw: pointer to the HW struct
4849 * @blk: hardware block
4850 * @prof: pointer to profile structure to remove
4852 static enum ice_status
4853 ice_rem_prof_id(struct ice_hw *hw, enum ice_block blk,
4854 struct ice_vsig_prof *prof)
4856 enum ice_status status;
4859 for (i = 0; i < prof->tcam_count; i++)
4860 if (prof->tcam[i].in_use) {
4861 prof->tcam[i].in_use = false;
4862 status = ice_rel_tcam_idx(hw, blk,
4863 prof->tcam[i].tcam_idx);
4865 return ICE_ERR_HW_TABLE;
4872 * ice_rem_vsig - remove VSIG
4873 * @hw: pointer to the HW struct
4874 * @blk: hardware block
4875 * @vsig: the VSIG to remove
4876 * @chg: the change list
4878 static enum ice_status
4879 ice_rem_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig,
4880 struct LIST_HEAD_TYPE *chg)
4882 u16 idx = vsig & ICE_VSIG_IDX_M;
4883 struct ice_vsig_vsi *vsi_cur;
4884 struct ice_vsig_prof *d, *t;
4885 enum ice_status status;
4887 /* remove TCAM entries */
4888 LIST_FOR_EACH_ENTRY_SAFE(d, t,
4889 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4890 ice_vsig_prof, list) {
4891 status = ice_rem_prof_id(hw, blk, d);
4899 /* Move all VSIS associated with this VSIG to the default VSIG */
4900 vsi_cur = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
4901 /* If the VSIG has at least 1 VSI then iterate through the list
4902 * and remove the VSIs before deleting the group.
4906 struct ice_vsig_vsi *tmp = vsi_cur->next_vsi;
4907 struct ice_chs_chg *p;
4909 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4911 return ICE_ERR_NO_MEMORY;
4913 p->type = ICE_VSIG_REM;
4914 p->orig_vsig = vsig;
4915 p->vsig = ICE_DEFAULT_VSIG;
4916 p->vsi = vsi_cur - hw->blk[blk].xlt2.vsis;
4918 LIST_ADD(&p->list_entry, chg);
4923 return ice_vsig_free(hw, blk, vsig);
4927 * ice_rem_prof_id_vsig - remove a specific profile from a VSIG
4928 * @hw: pointer to the HW struct
4929 * @blk: hardware block
4930 * @vsig: VSIG to remove the profile from
4931 * @hdl: profile handle indicating which profile to remove
4932 * @chg: list to receive a record of changes
4934 static enum ice_status
4935 ice_rem_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl,
4936 struct LIST_HEAD_TYPE *chg)
4938 u16 idx = vsig & ICE_VSIG_IDX_M;
4939 struct ice_vsig_prof *p, *t;
4940 enum ice_status status;
4942 LIST_FOR_EACH_ENTRY_SAFE(p, t,
4943 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4944 ice_vsig_prof, list)
4945 if (p->profile_cookie == hdl) {
4946 if (ice_vsig_prof_id_count(hw, blk, vsig) == 1)
4947 /* this is the last profile, remove the VSIG */
4948 return ice_rem_vsig(hw, blk, vsig, chg);
4950 status = ice_rem_prof_id(hw, blk, p);
4958 return ICE_ERR_DOES_NOT_EXIST;
4962 * ice_rem_flow_all - remove all flows with a particular profile
4963 * @hw: pointer to the HW struct
4964 * @blk: hardware block
4965 * @id: profile tracking ID
4967 static enum ice_status
4968 ice_rem_flow_all(struct ice_hw *hw, enum ice_block blk, u64 id)
4970 struct ice_chs_chg *del, *tmp;
4971 struct LIST_HEAD_TYPE chg;
4972 enum ice_status status;
4975 INIT_LIST_HEAD(&chg);
4977 for (i = 1; i < ICE_MAX_VSIGS; i++)
4978 if (hw->blk[blk].xlt2.vsig_tbl[i].in_use) {
4979 if (ice_has_prof_vsig(hw, blk, i, id)) {
4980 status = ice_rem_prof_id_vsig(hw, blk, i, id,
4983 goto err_ice_rem_flow_all;
4987 status = ice_upd_prof_hw(hw, blk, &chg);
4989 err_ice_rem_flow_all:
4990 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
4991 LIST_DEL(&del->list_entry);
4999 * ice_rem_prof - remove profile
5000 * @hw: pointer to the HW struct
5001 * @blk: hardware block
5002 * @id: profile tracking ID
5004 * This will remove the profile specified by the ID parameter, which was
5005 * previously created through ice_add_prof. If any existing entries
5006 * are associated with this profile, they will be removed as well.
5008 enum ice_status ice_rem_prof(struct ice_hw *hw, enum ice_block blk, u64 id)
5010 struct ice_prof_map *pmap;
5011 enum ice_status status;
5013 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
5015 pmap = ice_search_prof_id(hw, blk, id);
5017 status = ICE_ERR_DOES_NOT_EXIST;
5018 goto err_ice_rem_prof;
5021 /* remove all flows with this profile */
5022 status = ice_rem_flow_all(hw, blk, pmap->profile_cookie);
5024 goto err_ice_rem_prof;
5026 /* dereference profile, and possibly remove */
5027 ice_prof_dec_ref(hw, blk, pmap->prof_id);
5029 LIST_DEL(&pmap->list);
5033 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
5038 * ice_get_prof - get profile
5039 * @hw: pointer to the HW struct
5040 * @blk: hardware block
5041 * @hdl: profile handle
5044 static enum ice_status
5045 ice_get_prof(struct ice_hw *hw, enum ice_block blk, u64 hdl,
5046 struct LIST_HEAD_TYPE *chg)
5048 enum ice_status status = ICE_SUCCESS;
5049 struct ice_prof_map *map;
5050 struct ice_chs_chg *p;
5053 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
5054 /* Get the details on the profile specified by the handle ID */
5055 map = ice_search_prof_id(hw, blk, hdl);
5057 status = ICE_ERR_DOES_NOT_EXIST;
5058 goto err_ice_get_prof;
5061 for (i = 0; i < map->ptg_cnt; i++)
5062 if (!hw->blk[blk].es.written[map->prof_id]) {
5063 /* add ES to change list */
5064 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5066 status = ICE_ERR_NO_MEMORY;
5067 goto err_ice_get_prof;
5070 p->type = ICE_PTG_ES_ADD;
5072 p->ptg = map->ptg[i];
5073 p->attr = map->attr[i];
5077 p->prof_id = map->prof_id;
5079 hw->blk[blk].es.written[map->prof_id] = true;
5081 LIST_ADD(&p->list_entry, chg);
5085 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
5086 /* let caller clean up the change list */
5091 * ice_get_profs_vsig - get a copy of the list of profiles from a VSIG
5092 * @hw: pointer to the HW struct
5093 * @blk: hardware block
5094 * @vsig: VSIG from which to copy the list
5097 * This routine makes a copy of the list of profiles in the specified VSIG.
5099 static enum ice_status
5100 ice_get_profs_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig,
5101 struct LIST_HEAD_TYPE *lst)
5103 struct ice_vsig_prof *ent1, *ent2;
5104 u16 idx = vsig & ICE_VSIG_IDX_M;
5106 LIST_FOR_EACH_ENTRY(ent1, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
5107 ice_vsig_prof, list) {
5108 struct ice_vsig_prof *p;
5110 /* copy to the input list */
5111 p = (struct ice_vsig_prof *)ice_memdup(hw, ent1, sizeof(*p),
5112 ICE_NONDMA_TO_NONDMA);
5114 goto err_ice_get_profs_vsig;
5116 LIST_ADD_TAIL(&p->list, lst);
5121 err_ice_get_profs_vsig:
5122 LIST_FOR_EACH_ENTRY_SAFE(ent1, ent2, lst, ice_vsig_prof, list) {
5123 LIST_DEL(&ent1->list);
5127 return ICE_ERR_NO_MEMORY;
5131 * ice_add_prof_to_lst - add profile entry to a list
5132 * @hw: pointer to the HW struct
5133 * @blk: hardware block
5134 * @lst: the list to be added to
5135 * @hdl: profile handle of entry to add
5137 static enum ice_status
5138 ice_add_prof_to_lst(struct ice_hw *hw, enum ice_block blk,
5139 struct LIST_HEAD_TYPE *lst, u64 hdl)
5141 enum ice_status status = ICE_SUCCESS;
5142 struct ice_prof_map *map;
5143 struct ice_vsig_prof *p;
5146 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
5147 map = ice_search_prof_id(hw, blk, hdl);
5149 status = ICE_ERR_DOES_NOT_EXIST;
5150 goto err_ice_add_prof_to_lst;
5153 p = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*p));
5155 status = ICE_ERR_NO_MEMORY;
5156 goto err_ice_add_prof_to_lst;
5159 p->profile_cookie = map->profile_cookie;
5160 p->prof_id = map->prof_id;
5161 p->tcam_count = map->ptg_cnt;
5163 for (i = 0; i < map->ptg_cnt; i++) {
5164 p->tcam[i].prof_id = map->prof_id;
5165 p->tcam[i].tcam_idx = ICE_INVALID_TCAM;
5166 p->tcam[i].ptg = map->ptg[i];
5167 p->tcam[i].attr = map->attr[i];
5170 LIST_ADD(&p->list, lst);
5172 err_ice_add_prof_to_lst:
5173 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
5178 * ice_move_vsi - move VSI to another VSIG
5179 * @hw: pointer to the HW struct
5180 * @blk: hardware block
5181 * @vsi: the VSI to move
5182 * @vsig: the VSIG to move the VSI to
5183 * @chg: the change list
5185 static enum ice_status
5186 ice_move_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig,
5187 struct LIST_HEAD_TYPE *chg)
5189 enum ice_status status;
5190 struct ice_chs_chg *p;
5193 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5195 return ICE_ERR_NO_MEMORY;
5197 status = ice_vsig_find_vsi(hw, blk, vsi, &orig_vsig);
5199 status = ice_vsig_add_mv_vsi(hw, blk, vsi, vsig);
5206 p->type = ICE_VSI_MOVE;
5208 p->orig_vsig = orig_vsig;
5211 LIST_ADD(&p->list_entry, chg);
5217 * ice_set_tcam_flags - set TCAM flag don't care mask
5218 * @mask: mask for flags
5219 * @dc_mask: pointer to the don't care mask
5221 static void ice_set_tcam_flags(u16 mask, u8 dc_mask[ICE_TCAM_KEY_VAL_SZ])
5225 /* flags are lowest u16 */
5226 flag_word = (u16 *)dc_mask;
5231 * ice_rem_chg_tcam_ent - remove a specific TCAM entry from change list
5232 * @hw: pointer to the HW struct
5233 * @idx: the index of the TCAM entry to remove
5234 * @chg: the list of change structures to search
5237 ice_rem_chg_tcam_ent(struct ice_hw *hw, u16 idx, struct LIST_HEAD_TYPE *chg)
5239 struct ice_chs_chg *pos, *tmp;
5241 LIST_FOR_EACH_ENTRY_SAFE(tmp, pos, chg, ice_chs_chg, list_entry)
5242 if (tmp->type == ICE_TCAM_ADD && tmp->tcam_idx == idx) {
5243 LIST_DEL(&tmp->list_entry);
5249 * ice_prof_tcam_ena_dis - add enable or disable TCAM change
5250 * @hw: pointer to the HW struct
5251 * @blk: hardware block
5252 * @enable: true to enable, false to disable
5253 * @vsig: the VSIG of the TCAM entry
5254 * @tcam: pointer the TCAM info structure of the TCAM to disable
5255 * @chg: the change list
5257 * This function appends an enable or disable TCAM entry in the change log
5259 static enum ice_status
5260 ice_prof_tcam_ena_dis(struct ice_hw *hw, enum ice_block blk, bool enable,
5261 u16 vsig, struct ice_tcam_inf *tcam,
5262 struct LIST_HEAD_TYPE *chg)
5264 enum ice_status status;
5265 struct ice_chs_chg *p;
5267 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
5268 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0x00, 0x00, 0x00 };
5269 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
5271 /* if disabling, free the TCAM */
5273 status = ice_rel_tcam_idx(hw, blk, tcam->tcam_idx);
5275 /* if we have already created a change for this TCAM entry, then
5276 * we need to remove that entry, in order to prevent writing to
5277 * a TCAM entry we no longer will have ownership of.
5279 ice_rem_chg_tcam_ent(hw, tcam->tcam_idx, chg);
5285 /* for re-enabling, reallocate a TCAM */
5286 /* for entries with empty attribute masks, allocate entry from
5287 * the bottom of the TCAM table; otherwise, allocate from the
5288 * top of the table in order to give it higher priority
5290 status = ice_alloc_tcam_ent(hw, blk, tcam->attr.mask == 0,
5295 /* add TCAM to change list */
5296 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5298 return ICE_ERR_NO_MEMORY;
5300 /* set don't care masks for TCAM flags */
5301 ice_set_tcam_flags(tcam->attr.mask, dc_msk);
5303 status = ice_tcam_write_entry(hw, blk, tcam->tcam_idx, tcam->prof_id,
5304 tcam->ptg, vsig, 0, tcam->attr.flags,
5305 vl_msk, dc_msk, nm_msk);
5307 goto err_ice_prof_tcam_ena_dis;
5311 p->type = ICE_TCAM_ADD;
5312 p->add_tcam_idx = true;
5313 p->prof_id = tcam->prof_id;
5316 p->tcam_idx = tcam->tcam_idx;
5319 LIST_ADD(&p->list_entry, chg);
5323 err_ice_prof_tcam_ena_dis:
5329 * ice_ptg_attr_in_use - determine if PTG and attribute pair is in use
5330 * @ptg_attr: pointer to the PTG and attribute pair to check
5331 * @ptgs_used: bitmap that denotes which PTGs are in use
5332 * @attr_used: array of PTG and attributes pairs already used
5333 * @attr_cnt: count of entries in the attr_used array
5336 ice_ptg_attr_in_use(struct ice_tcam_inf *ptg_attr, ice_bitmap_t *ptgs_used,
5337 struct ice_tcam_inf *attr_used[], u16 attr_cnt)
5341 if (!ice_is_bit_set(ptgs_used, ptg_attr->ptg))
5344 /* the PTG is used, so now look for correct attributes */
5345 for (i = 0; i < attr_cnt; i++)
5346 if (attr_used[i]->ptg == ptg_attr->ptg &&
5347 attr_used[i]->attr.flags == ptg_attr->attr.flags &&
5348 attr_used[i]->attr.mask == ptg_attr->attr.mask)
5355 * ice_adj_prof_priorities - adjust profile based on priorities
5356 * @hw: pointer to the HW struct
5357 * @blk: hardware block
5358 * @vsig: the VSIG for which to adjust profile priorities
5359 * @chg: the change list
5361 static enum ice_status
5362 ice_adj_prof_priorities(struct ice_hw *hw, enum ice_block blk, u16 vsig,
5363 struct LIST_HEAD_TYPE *chg)
5365 ice_declare_bitmap(ptgs_used, ICE_XLT1_CNT);
5366 struct ice_tcam_inf **attr_used;
5367 enum ice_status status = ICE_SUCCESS;
5368 struct ice_vsig_prof *t;
5369 u16 attr_used_cnt = 0;
5372 #define ICE_MAX_PTG_ATTRS 1024
5373 attr_used = (struct ice_tcam_inf **)ice_calloc(hw, ICE_MAX_PTG_ATTRS,
5374 sizeof(*attr_used));
5376 return ICE_ERR_NO_MEMORY;
5378 ice_zero_bitmap(ptgs_used, ICE_XLT1_CNT);
5379 idx = vsig & ICE_VSIG_IDX_M;
5381 /* Priority is based on the order in which the profiles are added. The
5382 * newest added profile has highest priority and the oldest added
5383 * profile has the lowest priority. Since the profile property list for
5384 * a VSIG is sorted from newest to oldest, this code traverses the list
5385 * in order and enables the first of each PTG that it finds (that is not
5386 * already enabled); it also disables any duplicate PTGs that it finds
5387 * in the older profiles (that are currently enabled).
5390 LIST_FOR_EACH_ENTRY(t, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
5391 ice_vsig_prof, list) {
5394 for (i = 0; i < t->tcam_count; i++) {
5397 /* Scan the priorities from newest to oldest.
5398 * Make sure that the newest profiles take priority.
5400 used = ice_ptg_attr_in_use(&t->tcam[i], ptgs_used,
5401 attr_used, attr_used_cnt);
5403 if (used && t->tcam[i].in_use) {
5404 /* need to mark this PTG as never match, as it
5405 * was already in use and therefore duplicate
5406 * (and lower priority)
5408 status = ice_prof_tcam_ena_dis(hw, blk, false,
5413 goto err_ice_adj_prof_priorities;
5414 } else if (!used && !t->tcam[i].in_use) {
5415 /* need to enable this PTG, as it in not in use
5416 * and not enabled (highest priority)
5418 status = ice_prof_tcam_ena_dis(hw, blk, true,
5423 goto err_ice_adj_prof_priorities;
5426 /* keep track of used ptgs */
5427 ice_set_bit(t->tcam[i].ptg, ptgs_used);
5428 if (attr_used_cnt < ICE_MAX_PTG_ATTRS)
5429 attr_used[attr_used_cnt++] = &t->tcam[i];
5431 ice_debug(hw, ICE_DBG_INIT, "Warn: ICE_MAX_PTG_ATTRS exceeded\n");
5435 err_ice_adj_prof_priorities:
5436 ice_free(hw, attr_used);
5441 * ice_add_prof_id_vsig - add profile to VSIG
5442 * @hw: pointer to the HW struct
5443 * @blk: hardware block
5444 * @vsig: the VSIG to which this profile is to be added
5445 * @hdl: the profile handle indicating the profile to add
5446 * @rev: true to add entries to the end of the list
5447 * @chg: the change list
5449 static enum ice_status
5450 ice_add_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl,
5451 bool rev, struct LIST_HEAD_TYPE *chg)
5453 /* Masks that ignore flags */
5454 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
5455 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0x00, 0x00, 0x00 };
5456 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
5457 enum ice_status status = ICE_SUCCESS;
5458 struct ice_prof_map *map;
5459 struct ice_vsig_prof *t;
5460 struct ice_chs_chg *p;
5463 /* Error, if this VSIG already has this profile */
5464 if (ice_has_prof_vsig(hw, blk, vsig, hdl))
5465 return ICE_ERR_ALREADY_EXISTS;
5467 /* new VSIG profile structure */
5468 t = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*t));
5470 return ICE_ERR_NO_MEMORY;
5472 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
5473 /* Get the details on the profile specified by the handle ID */
5474 map = ice_search_prof_id(hw, blk, hdl);
5476 status = ICE_ERR_DOES_NOT_EXIST;
5477 goto err_ice_add_prof_id_vsig;
5480 t->profile_cookie = map->profile_cookie;
5481 t->prof_id = map->prof_id;
5482 t->tcam_count = map->ptg_cnt;
5484 /* create TCAM entries */
5485 for (i = 0; i < map->ptg_cnt; i++) {
5488 /* add TCAM to change list */
5489 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5491 status = ICE_ERR_NO_MEMORY;
5492 goto err_ice_add_prof_id_vsig;
5495 /* allocate the TCAM entry index */
5496 /* for entries with empty attribute masks, allocate entry from
5497 * the bottom of the TCAM table; otherwise, allocate from the
5498 * top of the table in order to give it higher priority
5500 status = ice_alloc_tcam_ent(hw, blk, map->attr[i].mask == 0,
5504 goto err_ice_add_prof_id_vsig;
5507 t->tcam[i].ptg = map->ptg[i];
5508 t->tcam[i].prof_id = map->prof_id;
5509 t->tcam[i].tcam_idx = tcam_idx;
5510 t->tcam[i].attr = map->attr[i];
5511 t->tcam[i].in_use = true;
5513 p->type = ICE_TCAM_ADD;
5514 p->add_tcam_idx = true;
5515 p->prof_id = t->tcam[i].prof_id;
5516 p->ptg = t->tcam[i].ptg;
5518 p->tcam_idx = t->tcam[i].tcam_idx;
5520 /* set don't care masks for TCAM flags */
5521 ice_set_tcam_flags(t->tcam[i].attr.mask, dc_msk);
5523 /* write the TCAM entry */
5524 status = ice_tcam_write_entry(hw, blk, t->tcam[i].tcam_idx,
5526 t->tcam[i].ptg, vsig, 0,
5527 t->tcam[i].attr.flags, vl_msk,
5531 goto err_ice_add_prof_id_vsig;
5535 LIST_ADD(&p->list_entry, chg);
5538 /* add profile to VSIG */
5539 vsig_idx = vsig & ICE_VSIG_IDX_M;
5541 LIST_ADD_TAIL(&t->list,
5542 &hw->blk[blk].xlt2.vsig_tbl[vsig_idx].prop_lst);
5545 &hw->blk[blk].xlt2.vsig_tbl[vsig_idx].prop_lst);
5547 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
5550 err_ice_add_prof_id_vsig:
5551 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
5552 /* let caller clean up the change list */
5558 * ice_create_prof_id_vsig - add a new VSIG with a single profile
5559 * @hw: pointer to the HW struct
5560 * @blk: hardware block
5561 * @vsi: the initial VSI that will be in VSIG
5562 * @hdl: the profile handle of the profile that will be added to the VSIG
5563 * @chg: the change list
5565 static enum ice_status
5566 ice_create_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl,
5567 struct LIST_HEAD_TYPE *chg)
5569 enum ice_status status;
5570 struct ice_chs_chg *p;
5573 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5575 return ICE_ERR_NO_MEMORY;
5577 new_vsig = ice_vsig_alloc(hw, blk);
5579 status = ICE_ERR_HW_TABLE;
5580 goto err_ice_create_prof_id_vsig;
5583 status = ice_move_vsi(hw, blk, vsi, new_vsig, chg);
5585 goto err_ice_create_prof_id_vsig;
5587 status = ice_add_prof_id_vsig(hw, blk, new_vsig, hdl, false, chg);
5589 goto err_ice_create_prof_id_vsig;
5591 p->type = ICE_VSIG_ADD;
5593 p->orig_vsig = ICE_DEFAULT_VSIG;
5596 LIST_ADD(&p->list_entry, chg);
5600 err_ice_create_prof_id_vsig:
5601 /* let caller clean up the change list */
5607 * ice_create_vsig_from_lst - create a new VSIG with a list of profiles
5608 * @hw: pointer to the HW struct
5609 * @blk: hardware block
5610 * @vsi: the initial VSI that will be in VSIG
5611 * @lst: the list of profile that will be added to the VSIG
5612 * @new_vsig: return of new VSIG
5613 * @chg: the change list
5615 static enum ice_status
5616 ice_create_vsig_from_lst(struct ice_hw *hw, enum ice_block blk, u16 vsi,
5617 struct LIST_HEAD_TYPE *lst, u16 *new_vsig,
5618 struct LIST_HEAD_TYPE *chg)
5620 struct ice_vsig_prof *t;
5621 enum ice_status status;
5624 vsig = ice_vsig_alloc(hw, blk);
5626 return ICE_ERR_HW_TABLE;
5628 status = ice_move_vsi(hw, blk, vsi, vsig, chg);
5632 LIST_FOR_EACH_ENTRY(t, lst, ice_vsig_prof, list) {
5633 /* Reverse the order here since we are copying the list */
5634 status = ice_add_prof_id_vsig(hw, blk, vsig, t->profile_cookie,
5646 * ice_find_prof_vsig - find a VSIG with a specific profile handle
5647 * @hw: pointer to the HW struct
5648 * @blk: hardware block
5649 * @hdl: the profile handle of the profile to search for
5650 * @vsig: returns the VSIG with the matching profile
5653 ice_find_prof_vsig(struct ice_hw *hw, enum ice_block blk, u64 hdl, u16 *vsig)
5655 struct ice_vsig_prof *t;
5656 struct LIST_HEAD_TYPE lst;
5657 enum ice_status status;
5659 INIT_LIST_HEAD(&lst);
5661 t = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*t));
5665 t->profile_cookie = hdl;
5666 LIST_ADD(&t->list, &lst);
5668 status = ice_find_dup_props_vsig(hw, blk, &lst, vsig);
5673 return status == ICE_SUCCESS;
5677 * ice_add_vsi_flow - add VSI flow
5678 * @hw: pointer to the HW struct
5679 * @blk: hardware block
5681 * @vsig: target VSIG to include the input VSI
5683 * Calling this function will add the VSI to a given VSIG and
5684 * update the HW tables accordingly. This call can be used to
5685 * add multiple VSIs to a VSIG if we know beforehand that those
5686 * VSIs have the same characteristics of the VSIG. This will
5687 * save time in generating a new VSIG and TCAMs till a match is
5688 * found and subsequent rollback when a matching VSIG is found.
5691 ice_add_vsi_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
5693 struct ice_chs_chg *tmp, *del;
5694 struct LIST_HEAD_TYPE chg;
5695 enum ice_status status;
5697 /* if target VSIG is default the move is invalid */
5698 if ((vsig & ICE_VSIG_IDX_M) == ICE_DEFAULT_VSIG)
5699 return ICE_ERR_PARAM;
5701 INIT_LIST_HEAD(&chg);
5703 /* move VSI to the VSIG that matches */
5704 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5705 /* update hardware if success */
5707 status = ice_upd_prof_hw(hw, blk, &chg);
5709 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
5710 LIST_DEL(&del->list_entry);
5718 * ice_add_prof_id_flow - add profile flow
5719 * @hw: pointer to the HW struct
5720 * @blk: hardware block
5721 * @vsi: the VSI to enable with the profile specified by ID
5722 * @hdl: profile handle
5724 * Calling this function will update the hardware tables to enable the
5725 * profile indicated by the ID parameter for the VSIs specified in the VSI
5726 * array. Once successfully called, the flow will be enabled.
5729 ice_add_prof_id_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl)
5731 struct ice_vsig_prof *tmp1, *del1;
5732 struct LIST_HEAD_TYPE union_lst;
5733 struct ice_chs_chg *tmp, *del;
5734 struct LIST_HEAD_TYPE chg;
5735 enum ice_status status;
5738 INIT_LIST_HEAD(&union_lst);
5739 INIT_LIST_HEAD(&chg);
5742 status = ice_get_prof(hw, blk, hdl, &chg);
5746 /* determine if VSI is already part of a VSIG */
5747 status = ice_vsig_find_vsi(hw, blk, vsi, &vsig);
5748 if (!status && vsig) {
5756 /* make sure that there is no overlap/conflict between the new
5757 * characteristics and the existing ones; we don't support that
5760 if (ice_has_prof_vsig(hw, blk, vsig, hdl)) {
5761 status = ICE_ERR_ALREADY_EXISTS;
5762 goto err_ice_add_prof_id_flow;
5765 /* last VSI in the VSIG? */
5766 status = ice_vsig_get_ref(hw, blk, vsig, &ref);
5768 goto err_ice_add_prof_id_flow;
5769 only_vsi = (ref == 1);
5771 /* create a union of the current profiles and the one being
5774 status = ice_get_profs_vsig(hw, blk, vsig, &union_lst);
5776 goto err_ice_add_prof_id_flow;
5778 status = ice_add_prof_to_lst(hw, blk, &union_lst, hdl);
5780 goto err_ice_add_prof_id_flow;
5782 /* search for an existing VSIG with an exact charc match */
5783 status = ice_find_dup_props_vsig(hw, blk, &union_lst, &vsig);
5785 /* move VSI to the VSIG that matches */
5786 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5788 goto err_ice_add_prof_id_flow;
5790 /* VSI has been moved out of or_vsig. If the or_vsig had
5791 * only that VSI it is now empty and can be removed.
5794 status = ice_rem_vsig(hw, blk, or_vsig, &chg);
5796 goto err_ice_add_prof_id_flow;
5798 } else if (only_vsi) {
5799 /* If the original VSIG only contains one VSI, then it
5800 * will be the requesting VSI. In this case the VSI is
5801 * not sharing entries and we can simply add the new
5802 * profile to the VSIG.
5804 status = ice_add_prof_id_vsig(hw, blk, vsig, hdl, false,
5807 goto err_ice_add_prof_id_flow;
5809 /* Adjust priorities */
5810 status = ice_adj_prof_priorities(hw, blk, vsig, &chg);
5812 goto err_ice_add_prof_id_flow;
5814 /* No match, so we need a new VSIG */
5815 status = ice_create_vsig_from_lst(hw, blk, vsi,
5819 goto err_ice_add_prof_id_flow;
5821 /* Adjust priorities */
5822 status = ice_adj_prof_priorities(hw, blk, vsig, &chg);
5824 goto err_ice_add_prof_id_flow;
5827 /* need to find or add a VSIG */
5828 /* search for an existing VSIG with an exact charc match */
5829 if (ice_find_prof_vsig(hw, blk, hdl, &vsig)) {
5830 /* found an exact match */
5831 /* add or move VSI to the VSIG that matches */
5832 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5834 goto err_ice_add_prof_id_flow;
5836 /* we did not find an exact match */
5837 /* we need to add a VSIG */
5838 status = ice_create_prof_id_vsig(hw, blk, vsi, hdl,
5841 goto err_ice_add_prof_id_flow;
5845 /* update hardware */
5847 status = ice_upd_prof_hw(hw, blk, &chg);
5849 err_ice_add_prof_id_flow:
5850 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
5851 LIST_DEL(&del->list_entry);
5855 LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, &union_lst, ice_vsig_prof, list) {
5856 LIST_DEL(&del1->list);
5864 * ice_rem_prof_from_list - remove a profile from list
5865 * @hw: pointer to the HW struct
5866 * @lst: list to remove the profile from
5867 * @hdl: the profile handle indicating the profile to remove
5869 static enum ice_status
5870 ice_rem_prof_from_list(struct ice_hw *hw, struct LIST_HEAD_TYPE *lst, u64 hdl)
5872 struct ice_vsig_prof *ent, *tmp;
5874 LIST_FOR_EACH_ENTRY_SAFE(ent, tmp, lst, ice_vsig_prof, list)
5875 if (ent->profile_cookie == hdl) {
5876 LIST_DEL(&ent->list);
5881 return ICE_ERR_DOES_NOT_EXIST;
5885 * ice_rem_prof_id_flow - remove flow
5886 * @hw: pointer to the HW struct
5887 * @blk: hardware block
5888 * @vsi: the VSI from which to remove the profile specified by ID
5889 * @hdl: profile tracking handle
5891 * Calling this function will update the hardware tables to remove the
5892 * profile indicated by the ID parameter for the VSIs specified in the VSI
5893 * array. Once successfully called, the flow will be disabled.
5896 ice_rem_prof_id_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl)
5898 struct ice_vsig_prof *tmp1, *del1;
5899 struct LIST_HEAD_TYPE chg, copy;
5900 struct ice_chs_chg *tmp, *del;
5901 enum ice_status status;
5904 INIT_LIST_HEAD(©);
5905 INIT_LIST_HEAD(&chg);
5907 /* determine if VSI is already part of a VSIG */
5908 status = ice_vsig_find_vsi(hw, blk, vsi, &vsig);
5909 if (!status && vsig) {
5915 last_profile = ice_vsig_prof_id_count(hw, blk, vsig) == 1;
5916 status = ice_vsig_get_ref(hw, blk, vsig, &ref);
5918 goto err_ice_rem_prof_id_flow;
5919 only_vsi = (ref == 1);
5922 /* If the original VSIG only contains one reference,
5923 * which will be the requesting VSI, then the VSI is not
5924 * sharing entries and we can simply remove the specific
5925 * characteristics from the VSIG.
5929 /* If there are no profiles left for this VSIG,
5930 * then simply remove the VSIG.
5932 status = ice_rem_vsig(hw, blk, vsig, &chg);
5934 goto err_ice_rem_prof_id_flow;
5936 status = ice_rem_prof_id_vsig(hw, blk, vsig,
5939 goto err_ice_rem_prof_id_flow;
5941 /* Adjust priorities */
5942 status = ice_adj_prof_priorities(hw, blk, vsig,
5945 goto err_ice_rem_prof_id_flow;
5949 /* Make a copy of the VSIG's list of Profiles */
5950 status = ice_get_profs_vsig(hw, blk, vsig, ©);
5952 goto err_ice_rem_prof_id_flow;
5954 /* Remove specified profile entry from the list */
5955 status = ice_rem_prof_from_list(hw, ©, hdl);
5957 goto err_ice_rem_prof_id_flow;
5959 if (LIST_EMPTY(©)) {
5960 status = ice_move_vsi(hw, blk, vsi,
5961 ICE_DEFAULT_VSIG, &chg);
5963 goto err_ice_rem_prof_id_flow;
5965 } else if (!ice_find_dup_props_vsig(hw, blk, ©,
5967 /* found an exact match */
5968 /* add or move VSI to the VSIG that matches */
5969 /* Search for a VSIG with a matching profile
5973 /* Found match, move VSI to the matching VSIG */
5974 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5976 goto err_ice_rem_prof_id_flow;
5978 /* since no existing VSIG supports this
5979 * characteristic pattern, we need to create a
5980 * new VSIG and TCAM entries
5982 status = ice_create_vsig_from_lst(hw, blk, vsi,
5986 goto err_ice_rem_prof_id_flow;
5988 /* Adjust priorities */
5989 status = ice_adj_prof_priorities(hw, blk, vsig,
5992 goto err_ice_rem_prof_id_flow;
5996 status = ICE_ERR_DOES_NOT_EXIST;
5999 /* update hardware tables */
6001 status = ice_upd_prof_hw(hw, blk, &chg);
6003 err_ice_rem_prof_id_flow:
6004 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
6005 LIST_DEL(&del->list_entry);
6009 LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, ©, ice_vsig_prof, list) {
6010 LIST_DEL(&del1->list);