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,
716 "Global config lock: No work to do\n");
722 * ice_release_global_cfg_lock
723 * @hw: pointer to the HW structure
725 * This function will release the global config lock.
727 static void ice_release_global_cfg_lock(struct ice_hw *hw)
729 ice_release_res(hw, ICE_GLOBAL_CFG_LOCK_RES_ID);
733 * ice_acquire_change_lock
734 * @hw: pointer to the HW structure
735 * @access: access type (read or write)
737 * This function will request ownership of the change lock.
740 ice_acquire_change_lock(struct ice_hw *hw, enum ice_aq_res_access_type access)
742 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
744 return ice_acquire_res(hw, ICE_CHANGE_LOCK_RES_ID, access,
745 ICE_CHANGE_LOCK_TIMEOUT);
749 * ice_release_change_lock
750 * @hw: pointer to the HW structure
752 * This function will release the change lock using the proper Admin Command.
754 void ice_release_change_lock(struct ice_hw *hw)
756 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
758 ice_release_res(hw, ICE_CHANGE_LOCK_RES_ID);
762 * ice_aq_download_pkg
763 * @hw: pointer to the hardware structure
764 * @pkg_buf: the package buffer to transfer
765 * @buf_size: the size of the package buffer
766 * @last_buf: last buffer indicator
767 * @error_offset: returns error offset
768 * @error_info: returns error information
769 * @cd: pointer to command details structure or NULL
771 * Download Package (0x0C40)
773 static enum ice_status
774 ice_aq_download_pkg(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf,
775 u16 buf_size, bool last_buf, u32 *error_offset,
776 u32 *error_info, struct ice_sq_cd *cd)
778 struct ice_aqc_download_pkg *cmd;
779 struct ice_aq_desc desc;
780 enum ice_status status;
782 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
789 cmd = &desc.params.download_pkg;
790 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_download_pkg);
791 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
794 cmd->flags |= ICE_AQC_DOWNLOAD_PKG_LAST_BUF;
796 status = ice_aq_send_cmd(hw, &desc, pkg_buf, buf_size, cd);
797 if (status == ICE_ERR_AQ_ERROR) {
798 /* Read error from buffer only when the FW returned an error */
799 struct ice_aqc_download_pkg_resp *resp;
801 resp = (struct ice_aqc_download_pkg_resp *)pkg_buf;
803 *error_offset = LE32_TO_CPU(resp->error_offset);
805 *error_info = LE32_TO_CPU(resp->error_info);
813 * @hw: pointer to the hardware structure
814 * @pkg_buf: the package cmd buffer
815 * @buf_size: the size of the package cmd buffer
816 * @last_buf: last buffer indicator
817 * @error_offset: returns error offset
818 * @error_info: returns error information
819 * @cd: pointer to command details structure or NULL
821 * Update Package (0x0C42)
823 static enum ice_status
824 ice_aq_update_pkg(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf, u16 buf_size,
825 bool last_buf, u32 *error_offset, u32 *error_info,
826 struct ice_sq_cd *cd)
828 struct ice_aqc_download_pkg *cmd;
829 struct ice_aq_desc desc;
830 enum ice_status status;
832 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
839 cmd = &desc.params.download_pkg;
840 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_update_pkg);
841 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
844 cmd->flags |= ICE_AQC_DOWNLOAD_PKG_LAST_BUF;
846 status = ice_aq_send_cmd(hw, &desc, pkg_buf, buf_size, cd);
847 if (status == ICE_ERR_AQ_ERROR) {
848 /* Read error from buffer only when the FW returned an error */
849 struct ice_aqc_download_pkg_resp *resp;
851 resp = (struct ice_aqc_download_pkg_resp *)pkg_buf;
853 *error_offset = LE32_TO_CPU(resp->error_offset);
855 *error_info = LE32_TO_CPU(resp->error_info);
862 * ice_find_seg_in_pkg
863 * @hw: pointer to the hardware structure
864 * @seg_type: the segment type to search for (i.e., SEGMENT_TYPE_CPK)
865 * @pkg_hdr: pointer to the package header to be searched
867 * This function searches a package file for a particular segment type. On
868 * success it returns a pointer to the segment header, otherwise it will
871 static struct ice_generic_seg_hdr *
872 ice_find_seg_in_pkg(struct ice_hw *hw, u32 seg_type,
873 struct ice_pkg_hdr *pkg_hdr)
877 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
878 ice_debug(hw, ICE_DBG_PKG, "Package format version: %d.%d.%d.%d\n",
879 pkg_hdr->pkg_format_ver.major, pkg_hdr->pkg_format_ver.minor,
880 pkg_hdr->pkg_format_ver.update,
881 pkg_hdr->pkg_format_ver.draft);
883 /* Search all package segments for the requested segment type */
884 for (i = 0; i < LE32_TO_CPU(pkg_hdr->seg_count); i++) {
885 struct ice_generic_seg_hdr *seg;
887 seg = (struct ice_generic_seg_hdr *)
888 ((u8 *)pkg_hdr + LE32_TO_CPU(pkg_hdr->seg_offset[i]));
890 if (LE32_TO_CPU(seg->seg_type) == seg_type)
899 * @hw: pointer to the hardware structure
900 * @bufs: pointer to an array of buffers
901 * @count: the number of buffers in the array
903 * Obtains change lock and updates package.
906 ice_update_pkg(struct ice_hw *hw, struct ice_buf *bufs, u32 count)
908 enum ice_status status;
911 status = ice_acquire_change_lock(hw, ICE_RES_WRITE);
915 for (i = 0; i < count; i++) {
916 struct ice_buf_hdr *bh = (struct ice_buf_hdr *)(bufs + i);
917 bool last = ((i + 1) == count);
919 status = ice_aq_update_pkg(hw, bh, LE16_TO_CPU(bh->data_end),
920 last, &offset, &info, NULL);
923 ice_debug(hw, ICE_DBG_PKG,
924 "Update pkg failed: err %d off %d inf %d\n",
925 status, offset, info);
930 ice_release_change_lock(hw);
937 * @hw: pointer to the hardware structure
938 * @bufs: pointer to an array of buffers
939 * @count: the number of buffers in the array
941 * Obtains global config lock and downloads the package configuration buffers
942 * to the firmware. Metadata buffers are skipped, and the first metadata buffer
943 * found indicates that the rest of the buffers are all metadata buffers.
945 static enum ice_status
946 ice_dwnld_cfg_bufs(struct ice_hw *hw, struct ice_buf *bufs, u32 count)
948 enum ice_status status;
949 struct ice_buf_hdr *bh;
953 return ICE_ERR_PARAM;
955 /* If the first buffer's first section has its metadata bit set
956 * then there are no buffers to be downloaded, and the operation is
957 * considered a success.
959 bh = (struct ice_buf_hdr *)bufs;
960 if (LE32_TO_CPU(bh->section_entry[0].type) & ICE_METADATA_BUF)
963 /* reset pkg_dwnld_status in case this function is called in the
966 hw->pkg_dwnld_status = ICE_AQ_RC_OK;
968 status = ice_acquire_global_cfg_lock(hw, ICE_RES_WRITE);
970 if (status == ICE_ERR_AQ_NO_WORK)
971 hw->pkg_dwnld_status = ICE_AQ_RC_EEXIST;
973 hw->pkg_dwnld_status = hw->adminq.sq_last_status;
977 for (i = 0; i < count; i++) {
978 bool last = ((i + 1) == count);
981 /* check next buffer for metadata flag */
982 bh = (struct ice_buf_hdr *)(bufs + i + 1);
984 /* A set metadata flag in the next buffer will signal
985 * that the current buffer will be the last buffer
988 if (LE16_TO_CPU(bh->section_count))
989 if (LE32_TO_CPU(bh->section_entry[0].type) &
994 bh = (struct ice_buf_hdr *)(bufs + i);
996 status = ice_aq_download_pkg(hw, bh, ICE_PKG_BUF_SIZE, last,
997 &offset, &info, NULL);
999 /* Save AQ status from download package */
1000 hw->pkg_dwnld_status = hw->adminq.sq_last_status;
1002 ice_debug(hw, ICE_DBG_PKG,
1003 "Pkg download failed: err %d off %d inf %d\n",
1004 status, offset, info);
1012 ice_release_global_cfg_lock(hw);
1018 * ice_aq_get_pkg_info_list
1019 * @hw: pointer to the hardware structure
1020 * @pkg_info: the buffer which will receive the information list
1021 * @buf_size: the size of the pkg_info information buffer
1022 * @cd: pointer to command details structure or NULL
1024 * Get Package Info List (0x0C43)
1026 static enum ice_status
1027 ice_aq_get_pkg_info_list(struct ice_hw *hw,
1028 struct ice_aqc_get_pkg_info_resp *pkg_info,
1029 u16 buf_size, struct ice_sq_cd *cd)
1031 struct ice_aq_desc desc;
1033 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1034 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_pkg_info_list);
1036 return ice_aq_send_cmd(hw, &desc, pkg_info, buf_size, cd);
1041 * @hw: pointer to the hardware structure
1042 * @ice_seg: pointer to the segment of the package to be downloaded
1044 * Handles the download of a complete package.
1046 static enum ice_status
1047 ice_download_pkg(struct ice_hw *hw, struct ice_seg *ice_seg)
1049 struct ice_buf_table *ice_buf_tbl;
1051 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1052 ice_debug(hw, ICE_DBG_PKG, "Segment format version: %d.%d.%d.%d\n",
1053 ice_seg->hdr.seg_format_ver.major,
1054 ice_seg->hdr.seg_format_ver.minor,
1055 ice_seg->hdr.seg_format_ver.update,
1056 ice_seg->hdr.seg_format_ver.draft);
1058 ice_debug(hw, ICE_DBG_PKG, "Seg: type 0x%X, size %d, name %s\n",
1059 LE32_TO_CPU(ice_seg->hdr.seg_type),
1060 LE32_TO_CPU(ice_seg->hdr.seg_size), ice_seg->hdr.seg_id);
1062 ice_buf_tbl = ice_find_buf_table(ice_seg);
1064 ice_debug(hw, ICE_DBG_PKG, "Seg buf count: %d\n",
1065 LE32_TO_CPU(ice_buf_tbl->buf_count));
1067 return ice_dwnld_cfg_bufs(hw, ice_buf_tbl->buf_array,
1068 LE32_TO_CPU(ice_buf_tbl->buf_count));
1073 * @hw: pointer to the hardware structure
1074 * @pkg_hdr: pointer to the driver's package hdr
1076 * Saves off the package details into the HW structure.
1078 static enum ice_status
1079 ice_init_pkg_info(struct ice_hw *hw, struct ice_pkg_hdr *pkg_hdr)
1081 struct ice_global_metadata_seg *meta_seg;
1082 struct ice_generic_seg_hdr *seg_hdr;
1084 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1086 return ICE_ERR_PARAM;
1088 meta_seg = (struct ice_global_metadata_seg *)
1089 ice_find_seg_in_pkg(hw, SEGMENT_TYPE_METADATA, pkg_hdr);
1091 hw->pkg_ver = meta_seg->pkg_ver;
1092 ice_memcpy(hw->pkg_name, meta_seg->pkg_name,
1093 sizeof(hw->pkg_name), ICE_NONDMA_TO_NONDMA);
1095 ice_debug(hw, ICE_DBG_PKG, "Pkg: %d.%d.%d.%d, %s\n",
1096 meta_seg->pkg_ver.major, meta_seg->pkg_ver.minor,
1097 meta_seg->pkg_ver.update, meta_seg->pkg_ver.draft,
1098 meta_seg->pkg_name);
1100 ice_debug(hw, ICE_DBG_INIT,
1101 "Did not find metadata segment in driver package\n");
1105 seg_hdr = ice_find_seg_in_pkg(hw, SEGMENT_TYPE_ICE, pkg_hdr);
1107 hw->ice_pkg_ver = seg_hdr->seg_format_ver;
1108 ice_memcpy(hw->ice_pkg_name, seg_hdr->seg_id,
1109 sizeof(hw->ice_pkg_name), ICE_NONDMA_TO_NONDMA);
1111 ice_debug(hw, ICE_DBG_PKG, "Ice Seg: %d.%d.%d.%d, %s\n",
1112 seg_hdr->seg_format_ver.major,
1113 seg_hdr->seg_format_ver.minor,
1114 seg_hdr->seg_format_ver.update,
1115 seg_hdr->seg_format_ver.draft,
1118 ice_debug(hw, ICE_DBG_INIT,
1119 "Did not find ice segment in driver package\n");
1128 * @hw: pointer to the hardware structure
1130 * Store details of the package currently loaded in HW into the HW structure.
1132 static enum ice_status ice_get_pkg_info(struct ice_hw *hw)
1134 struct ice_aqc_get_pkg_info_resp *pkg_info;
1135 enum ice_status status;
1139 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1141 size = ice_struct_size(pkg_info, pkg_info, ICE_PKG_CNT - 1);
1142 pkg_info = (struct ice_aqc_get_pkg_info_resp *)ice_malloc(hw, size);
1144 return ICE_ERR_NO_MEMORY;
1146 status = ice_aq_get_pkg_info_list(hw, pkg_info, size, NULL);
1148 goto init_pkg_free_alloc;
1150 for (i = 0; i < LE32_TO_CPU(pkg_info->count); i++) {
1151 #define ICE_PKG_FLAG_COUNT 4
1152 char flags[ICE_PKG_FLAG_COUNT + 1] = { 0 };
1155 if (pkg_info->pkg_info[i].is_active) {
1156 flags[place++] = 'A';
1157 hw->active_pkg_ver = pkg_info->pkg_info[i].ver;
1158 hw->active_track_id =
1159 LE32_TO_CPU(pkg_info->pkg_info[i].track_id);
1160 ice_memcpy(hw->active_pkg_name,
1161 pkg_info->pkg_info[i].name,
1162 sizeof(pkg_info->pkg_info[i].name),
1163 ICE_NONDMA_TO_NONDMA);
1164 hw->active_pkg_in_nvm = pkg_info->pkg_info[i].is_in_nvm;
1166 if (pkg_info->pkg_info[i].is_active_at_boot)
1167 flags[place++] = 'B';
1168 if (pkg_info->pkg_info[i].is_modified)
1169 flags[place++] = 'M';
1170 if (pkg_info->pkg_info[i].is_in_nvm)
1171 flags[place++] = 'N';
1173 ice_debug(hw, ICE_DBG_PKG, "Pkg[%d]: %d.%d.%d.%d,%s,%s\n",
1174 i, pkg_info->pkg_info[i].ver.major,
1175 pkg_info->pkg_info[i].ver.minor,
1176 pkg_info->pkg_info[i].ver.update,
1177 pkg_info->pkg_info[i].ver.draft,
1178 pkg_info->pkg_info[i].name, flags);
1181 init_pkg_free_alloc:
1182 ice_free(hw, pkg_info);
1188 * ice_verify_pkg - verify package
1189 * @pkg: pointer to the package buffer
1190 * @len: size of the package buffer
1192 * Verifies various attributes of the package file, including length, format
1193 * version, and the requirement of at least one segment.
1195 static enum ice_status ice_verify_pkg(struct ice_pkg_hdr *pkg, u32 len)
1200 if (len < sizeof(*pkg))
1201 return ICE_ERR_BUF_TOO_SHORT;
1203 if (pkg->pkg_format_ver.major != ICE_PKG_FMT_VER_MAJ ||
1204 pkg->pkg_format_ver.minor != ICE_PKG_FMT_VER_MNR ||
1205 pkg->pkg_format_ver.update != ICE_PKG_FMT_VER_UPD ||
1206 pkg->pkg_format_ver.draft != ICE_PKG_FMT_VER_DFT)
1209 /* pkg must have at least one segment */
1210 seg_count = LE32_TO_CPU(pkg->seg_count);
1214 /* make sure segment array fits in package length */
1215 if (len < ice_struct_size(pkg, seg_offset, seg_count - 1))
1216 return ICE_ERR_BUF_TOO_SHORT;
1218 /* all segments must fit within length */
1219 for (i = 0; i < seg_count; i++) {
1220 u32 off = LE32_TO_CPU(pkg->seg_offset[i]);
1221 struct ice_generic_seg_hdr *seg;
1223 /* segment header must fit */
1224 if (len < off + sizeof(*seg))
1225 return ICE_ERR_BUF_TOO_SHORT;
1227 seg = (struct ice_generic_seg_hdr *)((u8 *)pkg + off);
1229 /* segment body must fit */
1230 if (len < off + LE32_TO_CPU(seg->seg_size))
1231 return ICE_ERR_BUF_TOO_SHORT;
1238 * ice_free_seg - free package segment pointer
1239 * @hw: pointer to the hardware structure
1241 * Frees the package segment pointer in the proper manner, depending on if the
1242 * segment was allocated or just the passed in pointer was stored.
1244 void ice_free_seg(struct ice_hw *hw)
1247 ice_free(hw, hw->pkg_copy);
1248 hw->pkg_copy = NULL;
1255 * ice_init_pkg_regs - initialize additional package registers
1256 * @hw: pointer to the hardware structure
1258 static void ice_init_pkg_regs(struct ice_hw *hw)
1260 #define ICE_SW_BLK_INP_MASK_L 0xFFFFFFFF
1261 #define ICE_SW_BLK_INP_MASK_H 0x0000FFFF
1262 #define ICE_SW_BLK_IDX 0
1263 if (hw->dcf_enabled)
1266 /* setup Switch block input mask, which is 48-bits in two parts */
1267 wr32(hw, GL_PREEXT_L2_PMASK0(ICE_SW_BLK_IDX), ICE_SW_BLK_INP_MASK_L);
1268 wr32(hw, GL_PREEXT_L2_PMASK1(ICE_SW_BLK_IDX), ICE_SW_BLK_INP_MASK_H);
1272 * ice_chk_pkg_version - check package version for compatibility with driver
1273 * @pkg_ver: pointer to a version structure to check
1275 * Check to make sure that the package about to be downloaded is compatible with
1276 * the driver. To be compatible, the major and minor components of the package
1277 * version must match our ICE_PKG_SUPP_VER_MAJ and ICE_PKG_SUPP_VER_MNR
1280 static enum ice_status ice_chk_pkg_version(struct ice_pkg_ver *pkg_ver)
1282 if (pkg_ver->major != ICE_PKG_SUPP_VER_MAJ ||
1283 pkg_ver->minor != ICE_PKG_SUPP_VER_MNR)
1284 return ICE_ERR_NOT_SUPPORTED;
1290 * ice_chk_pkg_compat
1291 * @hw: pointer to the hardware structure
1292 * @ospkg: pointer to the package hdr
1293 * @seg: pointer to the package segment hdr
1295 * This function checks the package version compatibility with driver and NVM
1297 static enum ice_status
1298 ice_chk_pkg_compat(struct ice_hw *hw, struct ice_pkg_hdr *ospkg,
1299 struct ice_seg **seg)
1301 struct ice_aqc_get_pkg_info_resp *pkg;
1302 enum ice_status status;
1306 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1308 /* Check package version compatibility */
1309 status = ice_chk_pkg_version(&hw->pkg_ver);
1311 ice_debug(hw, ICE_DBG_INIT, "Package version check failed.\n");
1315 /* find ICE segment in given package */
1316 *seg = (struct ice_seg *)ice_find_seg_in_pkg(hw, SEGMENT_TYPE_ICE,
1319 ice_debug(hw, ICE_DBG_INIT, "no ice segment in package.\n");
1323 /* Check if FW is compatible with the OS package */
1324 size = ice_struct_size(pkg, pkg_info, ICE_PKG_CNT - 1);
1325 pkg = (struct ice_aqc_get_pkg_info_resp *)ice_malloc(hw, size);
1327 return ICE_ERR_NO_MEMORY;
1329 status = ice_aq_get_pkg_info_list(hw, pkg, size, NULL);
1331 goto fw_ddp_compat_free_alloc;
1333 for (i = 0; i < LE32_TO_CPU(pkg->count); i++) {
1334 /* loop till we find the NVM package */
1335 if (!pkg->pkg_info[i].is_in_nvm)
1337 if ((*seg)->hdr.seg_format_ver.major !=
1338 pkg->pkg_info[i].ver.major ||
1339 (*seg)->hdr.seg_format_ver.minor >
1340 pkg->pkg_info[i].ver.minor) {
1341 status = ICE_ERR_FW_DDP_MISMATCH;
1342 ice_debug(hw, ICE_DBG_INIT,
1343 "OS package is not compatible with NVM.\n");
1345 /* done processing NVM package so break */
1348 fw_ddp_compat_free_alloc:
1354 * ice_init_pkg - initialize/download package
1355 * @hw: pointer to the hardware structure
1356 * @buf: pointer to the package buffer
1357 * @len: size of the package buffer
1359 * This function initializes a package. The package contains HW tables
1360 * required to do packet processing. First, the function extracts package
1361 * information such as version. Then it finds the ice configuration segment
1362 * within the package; this function then saves a copy of the segment pointer
1363 * within the supplied package buffer. Next, the function will cache any hints
1364 * from the package, followed by downloading the package itself. Note, that if
1365 * a previous PF driver has already downloaded the package successfully, then
1366 * the current driver will not have to download the package again.
1368 * The local package contents will be used to query default behavior and to
1369 * update specific sections of the HW's version of the package (e.g. to update
1370 * the parse graph to understand new protocols).
1372 * This function stores a pointer to the package buffer memory, and it is
1373 * expected that the supplied buffer will not be freed immediately. If the
1374 * package buffer needs to be freed, such as when read from a file, use
1375 * ice_copy_and_init_pkg() instead of directly calling ice_init_pkg() in this
1378 enum ice_status ice_init_pkg(struct ice_hw *hw, u8 *buf, u32 len)
1380 struct ice_pkg_hdr *pkg;
1381 enum ice_status status;
1382 struct ice_seg *seg;
1385 return ICE_ERR_PARAM;
1387 pkg = (struct ice_pkg_hdr *)buf;
1388 status = ice_verify_pkg(pkg, len);
1390 ice_debug(hw, ICE_DBG_INIT, "failed to verify pkg (err: %d)\n",
1395 /* initialize package info */
1396 status = ice_init_pkg_info(hw, pkg);
1400 /* before downloading the package, check package version for
1401 * compatibility with driver
1403 status = ice_chk_pkg_compat(hw, pkg, &seg);
1407 /* initialize package hints and then download package */
1408 ice_init_pkg_hints(hw, seg);
1409 status = ice_download_pkg(hw, seg);
1410 if (status == ICE_ERR_AQ_NO_WORK) {
1411 ice_debug(hw, ICE_DBG_INIT,
1412 "package previously loaded - no work.\n");
1413 status = ICE_SUCCESS;
1416 /* Get information on the package currently loaded in HW, then make sure
1417 * the driver is compatible with this version.
1420 status = ice_get_pkg_info(hw);
1422 status = ice_chk_pkg_version(&hw->active_pkg_ver);
1427 /* on successful package download update other required
1428 * registers to support the package and fill HW tables
1429 * with package content.
1431 ice_init_pkg_regs(hw);
1432 ice_fill_blk_tbls(hw);
1434 ice_debug(hw, ICE_DBG_INIT, "package load failed, %d\n",
1442 * ice_copy_and_init_pkg - initialize/download a copy of the package
1443 * @hw: pointer to the hardware structure
1444 * @buf: pointer to the package buffer
1445 * @len: size of the package buffer
1447 * This function copies the package buffer, and then calls ice_init_pkg() to
1448 * initialize the copied package contents.
1450 * The copying is necessary if the package buffer supplied is constant, or if
1451 * the memory may disappear shortly after calling this function.
1453 * If the package buffer resides in the data segment and can be modified, the
1454 * caller is free to use ice_init_pkg() instead of ice_copy_and_init_pkg().
1456 * However, if the package buffer needs to be copied first, such as when being
1457 * read from a file, the caller should use ice_copy_and_init_pkg().
1459 * This function will first copy the package buffer, before calling
1460 * ice_init_pkg(). The caller is free to immediately destroy the original
1461 * package buffer, as the new copy will be managed by this function and
1464 enum ice_status ice_copy_and_init_pkg(struct ice_hw *hw, const u8 *buf, u32 len)
1466 enum ice_status status;
1470 return ICE_ERR_PARAM;
1472 buf_copy = (u8 *)ice_memdup(hw, buf, len, ICE_NONDMA_TO_NONDMA);
1474 status = ice_init_pkg(hw, buf_copy, len);
1476 /* Free the copy, since we failed to initialize the package */
1477 ice_free(hw, buf_copy);
1479 /* Track the copied pkg so we can free it later */
1480 hw->pkg_copy = buf_copy;
1489 * @hw: pointer to the HW structure
1491 * Allocates a package buffer and returns a pointer to the buffer header.
1492 * Note: all package contents must be in Little Endian form.
1494 static struct ice_buf_build *ice_pkg_buf_alloc(struct ice_hw *hw)
1496 struct ice_buf_build *bld;
1497 struct ice_buf_hdr *buf;
1499 bld = (struct ice_buf_build *)ice_malloc(hw, sizeof(*bld));
1503 buf = (struct ice_buf_hdr *)bld;
1504 buf->data_end = CPU_TO_LE16(offsetof(struct ice_buf_hdr,
1511 * @sect_type: section type
1512 * @section: pointer to section
1513 * @index: index of the field vector entry to be returned
1514 * @offset: ptr to variable that receives the offset in the field vector table
1516 * This is a callback function that can be passed to ice_pkg_enum_entry.
1517 * This function treats the given section as of type ice_sw_fv_section and
1518 * enumerates offset field. "offset" is an index into the field vector
1522 ice_sw_fv_handler(u32 sect_type, void *section, u32 index, u32 *offset)
1524 struct ice_sw_fv_section *fv_section =
1525 (struct ice_sw_fv_section *)section;
1527 if (!section || sect_type != ICE_SID_FLD_VEC_SW)
1529 if (index >= LE16_TO_CPU(fv_section->count))
1532 /* "index" passed in to this function is relative to a given
1533 * 4k block. To get to the true index into the field vector
1534 * table need to add the relative index to the base_offset
1535 * field of this section
1537 *offset = LE16_TO_CPU(fv_section->base_offset) + index;
1538 return fv_section->fv + index;
1542 * ice_get_sw_prof_type - determine switch profile type
1543 * @hw: pointer to the HW structure
1544 * @fv: pointer to the switch field vector
1546 static enum ice_prof_type
1547 ice_get_sw_prof_type(struct ice_hw *hw, struct ice_fv *fv)
1551 for (i = 0; i < hw->blk[ICE_BLK_SW].es.fvw; i++) {
1552 /* UDP tunnel will have UDP_OF protocol ID and VNI offset */
1553 if (fv->ew[i].prot_id == (u8)ICE_PROT_UDP_OF &&
1554 fv->ew[i].off == ICE_VNI_OFFSET)
1555 return ICE_PROF_TUN_UDP;
1557 /* GRE tunnel will have GRE protocol */
1558 if (fv->ew[i].prot_id == (u8)ICE_PROT_GRE_OF)
1559 return ICE_PROF_TUN_GRE;
1561 /* PPPOE tunnel will have PPPOE protocol */
1562 if (fv->ew[i].prot_id == (u8)ICE_PROT_PPPOE)
1563 return ICE_PROF_TUN_PPPOE;
1566 return ICE_PROF_NON_TUN;
1570 * ice_get_sw_fv_bitmap - Get switch field vector bitmap based on profile type
1571 * @hw: pointer to hardware structure
1572 * @req_profs: type of profiles requested
1573 * @bm: pointer to memory for returning the bitmap of field vectors
1576 ice_get_sw_fv_bitmap(struct ice_hw *hw, enum ice_prof_type req_profs,
1579 struct ice_pkg_enum state;
1580 struct ice_seg *ice_seg;
1583 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1585 if (req_profs == ICE_PROF_ALL) {
1588 for (i = 0; i < ICE_MAX_NUM_PROFILES; i++)
1593 ice_zero_bitmap(bm, ICE_MAX_NUM_PROFILES);
1597 enum ice_prof_type prof_type;
1600 fv = (struct ice_fv *)
1601 ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1602 &offset, ice_sw_fv_handler);
1606 /* Determine field vector type */
1607 prof_type = ice_get_sw_prof_type(hw, fv);
1609 if (req_profs & prof_type)
1610 ice_set_bit((u16)offset, bm);
1616 * ice_get_sw_fv_list
1617 * @hw: pointer to the HW structure
1618 * @prot_ids: field vector to search for with a given protocol ID
1619 * @ids_cnt: lookup/protocol count
1620 * @bm: bitmap of field vectors to consider
1621 * @fv_list: Head of a list
1623 * Finds all the field vector entries from switch block that contain
1624 * a given protocol ID and returns a list of structures of type
1625 * "ice_sw_fv_list_entry". Every structure in the list has a field vector
1626 * definition and profile ID information
1627 * NOTE: The caller of the function is responsible for freeing the memory
1628 * allocated for every list entry.
1631 ice_get_sw_fv_list(struct ice_hw *hw, u8 *prot_ids, u16 ids_cnt,
1632 ice_bitmap_t *bm, struct LIST_HEAD_TYPE *fv_list)
1634 struct ice_sw_fv_list_entry *fvl;
1635 struct ice_sw_fv_list_entry *tmp;
1636 struct ice_pkg_enum state;
1637 struct ice_seg *ice_seg;
1641 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1643 if (!ids_cnt || !hw->seg)
1644 return ICE_ERR_PARAM;
1650 fv = (struct ice_fv *)
1651 ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1652 &offset, ice_sw_fv_handler);
1657 /* If field vector is not in the bitmap list, then skip this
1660 if (!ice_is_bit_set(bm, (u16)offset))
1663 for (i = 0; i < ids_cnt; i++) {
1666 /* This code assumes that if a switch field vector line
1667 * has a matching protocol, then this line will contain
1668 * the entries necessary to represent every field in
1669 * that protocol header.
1671 for (j = 0; j < hw->blk[ICE_BLK_SW].es.fvw; j++)
1672 if (fv->ew[j].prot_id == prot_ids[i])
1674 if (j >= hw->blk[ICE_BLK_SW].es.fvw)
1676 if (i + 1 == ids_cnt) {
1677 fvl = (struct ice_sw_fv_list_entry *)
1678 ice_malloc(hw, sizeof(*fvl));
1682 fvl->profile_id = offset;
1683 LIST_ADD(&fvl->list_entry, fv_list);
1688 if (LIST_EMPTY(fv_list))
1693 LIST_FOR_EACH_ENTRY_SAFE(fvl, tmp, fv_list, ice_sw_fv_list_entry,
1695 LIST_DEL(&fvl->list_entry);
1699 return ICE_ERR_NO_MEMORY;
1703 * ice_init_prof_result_bm - Initialize the profile result index bitmap
1704 * @hw: pointer to hardware structure
1706 void ice_init_prof_result_bm(struct ice_hw *hw)
1708 struct ice_pkg_enum state;
1709 struct ice_seg *ice_seg;
1712 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1722 fv = (struct ice_fv *)
1723 ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1724 &off, ice_sw_fv_handler);
1729 ice_zero_bitmap(hw->switch_info->prof_res_bm[off],
1732 /* Determine empty field vector indices, these can be
1733 * used for recipe results. Skip index 0, since it is
1734 * always used for Switch ID.
1736 for (i = 1; i < ICE_MAX_FV_WORDS; i++)
1737 if (fv->ew[i].prot_id == ICE_PROT_INVALID &&
1738 fv->ew[i].off == ICE_FV_OFFSET_INVAL)
1740 hw->switch_info->prof_res_bm[off]);
1746 * @hw: pointer to the HW structure
1747 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1749 * Frees a package buffer
1751 static void ice_pkg_buf_free(struct ice_hw *hw, struct ice_buf_build *bld)
1757 * ice_pkg_buf_reserve_section
1758 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1759 * @count: the number of sections to reserve
1761 * Reserves one or more section table entries in a package buffer. This routine
1762 * can be called multiple times as long as they are made before calling
1763 * ice_pkg_buf_alloc_section(). Once ice_pkg_buf_alloc_section()
1764 * is called once, the number of sections that can be allocated will not be able
1765 * to be increased; not using all reserved sections is fine, but this will
1766 * result in some wasted space in the buffer.
1767 * Note: all package contents must be in Little Endian form.
1769 static enum ice_status
1770 ice_pkg_buf_reserve_section(struct ice_buf_build *bld, u16 count)
1772 struct ice_buf_hdr *buf;
1777 return ICE_ERR_PARAM;
1779 buf = (struct ice_buf_hdr *)&bld->buf;
1781 /* already an active section, can't increase table size */
1782 section_count = LE16_TO_CPU(buf->section_count);
1783 if (section_count > 0)
1786 if (bld->reserved_section_table_entries + count > ICE_MAX_S_COUNT)
1788 bld->reserved_section_table_entries += count;
1790 data_end = LE16_TO_CPU(buf->data_end) +
1791 (count * sizeof(buf->section_entry[0]));
1792 buf->data_end = CPU_TO_LE16(data_end);
1798 * ice_pkg_buf_alloc_section
1799 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1800 * @type: the section type value
1801 * @size: the size of the section to reserve (in bytes)
1803 * Reserves memory in the buffer for a section's content and updates the
1804 * buffers' status accordingly. This routine returns a pointer to the first
1805 * byte of the section start within the buffer, which is used to fill in the
1807 * Note: all package contents must be in Little Endian form.
1810 ice_pkg_buf_alloc_section(struct ice_buf_build *bld, u32 type, u16 size)
1812 struct ice_buf_hdr *buf;
1816 if (!bld || !type || !size)
1819 buf = (struct ice_buf_hdr *)&bld->buf;
1821 /* check for enough space left in buffer */
1822 data_end = LE16_TO_CPU(buf->data_end);
1824 /* section start must align on 4 byte boundary */
1825 data_end = ICE_ALIGN(data_end, 4);
1827 if ((data_end + size) > ICE_MAX_S_DATA_END)
1830 /* check for more available section table entries */
1831 sect_count = LE16_TO_CPU(buf->section_count);
1832 if (sect_count < bld->reserved_section_table_entries) {
1833 void *section_ptr = ((u8 *)buf) + data_end;
1835 buf->section_entry[sect_count].offset = CPU_TO_LE16(data_end);
1836 buf->section_entry[sect_count].size = CPU_TO_LE16(size);
1837 buf->section_entry[sect_count].type = CPU_TO_LE32(type);
1840 buf->data_end = CPU_TO_LE16(data_end);
1842 buf->section_count = CPU_TO_LE16(sect_count + 1);
1846 /* no free section table entries */
1851 * ice_pkg_buf_get_active_sections
1852 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1854 * Returns the number of active sections. Before using the package buffer
1855 * in an update package command, the caller should make sure that there is at
1856 * least one active section - otherwise, the buffer is not legal and should
1858 * Note: all package contents must be in Little Endian form.
1860 static u16 ice_pkg_buf_get_active_sections(struct ice_buf_build *bld)
1862 struct ice_buf_hdr *buf;
1867 buf = (struct ice_buf_hdr *)&bld->buf;
1868 return LE16_TO_CPU(buf->section_count);
1873 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1875 * Return a pointer to the buffer's header
1877 static struct ice_buf *ice_pkg_buf(struct ice_buf_build *bld)
1886 * ice_tunnel_port_in_use_hlpr - helper function to determine tunnel usage
1887 * @hw: pointer to the HW structure
1888 * @port: port to search for
1889 * @index: optionally returns index
1891 * Returns whether a port is already in use as a tunnel, and optionally its
1894 static bool ice_tunnel_port_in_use_hlpr(struct ice_hw *hw, u16 port, u16 *index)
1898 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
1899 if (hw->tnl.tbl[i].in_use && hw->tnl.tbl[i].port == port) {
1909 * ice_tunnel_port_in_use
1910 * @hw: pointer to the HW structure
1911 * @port: port to search for
1912 * @index: optionally returns index
1914 * Returns whether a port is already in use as a tunnel, and optionally its
1917 bool ice_tunnel_port_in_use(struct ice_hw *hw, u16 port, u16 *index)
1921 ice_acquire_lock(&hw->tnl_lock);
1922 res = ice_tunnel_port_in_use_hlpr(hw, port, index);
1923 ice_release_lock(&hw->tnl_lock);
1929 * ice_tunnel_get_type
1930 * @hw: pointer to the HW structure
1931 * @port: port to search for
1932 * @type: returns tunnel index
1934 * For a given port number, will return the type of tunnel.
1937 ice_tunnel_get_type(struct ice_hw *hw, u16 port, enum ice_tunnel_type *type)
1942 ice_acquire_lock(&hw->tnl_lock);
1944 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
1945 if (hw->tnl.tbl[i].in_use && hw->tnl.tbl[i].port == port) {
1946 *type = hw->tnl.tbl[i].type;
1951 ice_release_lock(&hw->tnl_lock);
1957 * ice_find_free_tunnel_entry
1958 * @hw: pointer to the HW structure
1959 * @type: tunnel type
1960 * @index: optionally returns index
1962 * Returns whether there is a free tunnel entry, and optionally its index
1965 ice_find_free_tunnel_entry(struct ice_hw *hw, enum ice_tunnel_type type,
1970 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
1971 if (hw->tnl.tbl[i].valid && !hw->tnl.tbl[i].in_use &&
1972 hw->tnl.tbl[i].type == type) {
1982 * ice_get_open_tunnel_port - retrieve an open tunnel port
1983 * @hw: pointer to the HW structure
1984 * @type: tunnel type (TNL_ALL will return any open port)
1985 * @port: returns open port
1988 ice_get_open_tunnel_port(struct ice_hw *hw, 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].valid && hw->tnl.tbl[i].in_use &&
1998 (type == TNL_ALL || hw->tnl.tbl[i].type == type)) {
1999 *port = hw->tnl.tbl[i].port;
2004 ice_release_lock(&hw->tnl_lock);
2011 * @hw: pointer to the HW structure
2012 * @type: type of tunnel
2013 * @port: port of tunnel to create
2015 * Create a tunnel by updating the parse graph in the parser. We do that by
2016 * creating a package buffer with the tunnel info and issuing an update package
2020 ice_create_tunnel(struct ice_hw *hw, enum ice_tunnel_type type, u16 port)
2022 struct ice_boost_tcam_section *sect_rx, *sect_tx;
2023 enum ice_status status = ICE_ERR_MAX_LIMIT;
2024 struct ice_buf_build *bld;
2027 ice_acquire_lock(&hw->tnl_lock);
2029 if (ice_tunnel_port_in_use_hlpr(hw, port, &index)) {
2030 hw->tnl.tbl[index].ref++;
2031 status = ICE_SUCCESS;
2032 goto ice_create_tunnel_end;
2035 if (!ice_find_free_tunnel_entry(hw, type, &index)) {
2036 status = ICE_ERR_OUT_OF_RANGE;
2037 goto ice_create_tunnel_end;
2040 bld = ice_pkg_buf_alloc(hw);
2042 status = ICE_ERR_NO_MEMORY;
2043 goto ice_create_tunnel_end;
2046 /* allocate 2 sections, one for Rx parser, one for Tx parser */
2047 if (ice_pkg_buf_reserve_section(bld, 2))
2048 goto ice_create_tunnel_err;
2050 sect_rx = (struct ice_boost_tcam_section *)
2051 ice_pkg_buf_alloc_section(bld, ICE_SID_RXPARSER_BOOST_TCAM,
2054 goto ice_create_tunnel_err;
2055 sect_rx->count = CPU_TO_LE16(1);
2057 sect_tx = (struct ice_boost_tcam_section *)
2058 ice_pkg_buf_alloc_section(bld, ICE_SID_TXPARSER_BOOST_TCAM,
2061 goto ice_create_tunnel_err;
2062 sect_tx->count = CPU_TO_LE16(1);
2064 /* copy original boost entry to update package buffer */
2065 ice_memcpy(sect_rx->tcam, hw->tnl.tbl[index].boost_entry,
2066 sizeof(*sect_rx->tcam), ICE_NONDMA_TO_NONDMA);
2068 /* over-write the never-match dest port key bits with the encoded port
2071 ice_set_key((u8 *)§_rx->tcam[0].key, sizeof(sect_rx->tcam[0].key),
2072 (u8 *)&port, NULL, NULL, NULL,
2073 (u16)offsetof(struct ice_boost_key_value, hv_dst_port_key),
2074 sizeof(sect_rx->tcam[0].key.key.hv_dst_port_key));
2076 /* exact copy of entry to Tx section entry */
2077 ice_memcpy(sect_tx->tcam, sect_rx->tcam, sizeof(*sect_tx->tcam),
2078 ICE_NONDMA_TO_NONDMA);
2080 status = ice_update_pkg(hw, ice_pkg_buf(bld), 1);
2082 hw->tnl.tbl[index].port = port;
2083 hw->tnl.tbl[index].in_use = true;
2084 hw->tnl.tbl[index].ref = 1;
2087 ice_create_tunnel_err:
2088 ice_pkg_buf_free(hw, bld);
2090 ice_create_tunnel_end:
2091 ice_release_lock(&hw->tnl_lock);
2097 * ice_destroy_tunnel
2098 * @hw: pointer to the HW structure
2099 * @port: port of tunnel to destroy (ignored if the all parameter is true)
2100 * @all: flag that states to destroy all tunnels
2102 * Destroys a tunnel or all tunnels by creating an update package buffer
2103 * targeting the specific updates requested and then performing an update
2106 enum ice_status ice_destroy_tunnel(struct ice_hw *hw, u16 port, bool all)
2108 struct ice_boost_tcam_section *sect_rx, *sect_tx;
2109 enum ice_status status = ICE_ERR_MAX_LIMIT;
2110 struct ice_buf_build *bld;
2116 ice_acquire_lock(&hw->tnl_lock);
2118 if (!all && ice_tunnel_port_in_use_hlpr(hw, port, &index))
2119 if (hw->tnl.tbl[index].ref > 1) {
2120 hw->tnl.tbl[index].ref--;
2121 status = ICE_SUCCESS;
2122 goto ice_destroy_tunnel_end;
2125 /* determine count */
2126 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
2127 if (hw->tnl.tbl[i].valid && hw->tnl.tbl[i].in_use &&
2128 (all || hw->tnl.tbl[i].port == port))
2132 status = ICE_ERR_PARAM;
2133 goto ice_destroy_tunnel_end;
2136 /* size of section - there is at least one entry */
2137 size = ice_struct_size(sect_rx, tcam, count - 1);
2139 bld = ice_pkg_buf_alloc(hw);
2141 status = ICE_ERR_NO_MEMORY;
2142 goto ice_destroy_tunnel_end;
2145 /* allocate 2 sections, one for Rx parser, one for Tx parser */
2146 if (ice_pkg_buf_reserve_section(bld, 2))
2147 goto ice_destroy_tunnel_err;
2149 sect_rx = (struct ice_boost_tcam_section *)
2150 ice_pkg_buf_alloc_section(bld, ICE_SID_RXPARSER_BOOST_TCAM,
2153 goto ice_destroy_tunnel_err;
2154 sect_rx->count = CPU_TO_LE16(1);
2156 sect_tx = (struct ice_boost_tcam_section *)
2157 ice_pkg_buf_alloc_section(bld, ICE_SID_TXPARSER_BOOST_TCAM,
2160 goto ice_destroy_tunnel_err;
2161 sect_tx->count = CPU_TO_LE16(1);
2163 /* copy original boost entry to update package buffer, one copy to Rx
2164 * section, another copy to the Tx section
2166 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
2167 if (hw->tnl.tbl[i].valid && hw->tnl.tbl[i].in_use &&
2168 (all || hw->tnl.tbl[i].port == port)) {
2169 ice_memcpy(sect_rx->tcam + i,
2170 hw->tnl.tbl[i].boost_entry,
2171 sizeof(*sect_rx->tcam),
2172 ICE_NONDMA_TO_NONDMA);
2173 ice_memcpy(sect_tx->tcam + i,
2174 hw->tnl.tbl[i].boost_entry,
2175 sizeof(*sect_tx->tcam),
2176 ICE_NONDMA_TO_NONDMA);
2177 hw->tnl.tbl[i].marked = true;
2180 status = ice_update_pkg(hw, ice_pkg_buf(bld), 1);
2182 for (i = 0; i < hw->tnl.count &&
2183 i < ICE_TUNNEL_MAX_ENTRIES; i++)
2184 if (hw->tnl.tbl[i].marked) {
2185 hw->tnl.tbl[i].ref = 0;
2186 hw->tnl.tbl[i].port = 0;
2187 hw->tnl.tbl[i].in_use = false;
2188 hw->tnl.tbl[i].marked = false;
2191 ice_destroy_tunnel_err:
2192 ice_pkg_buf_free(hw, bld);
2194 ice_destroy_tunnel_end:
2195 ice_release_lock(&hw->tnl_lock);
2201 * ice_find_prot_off - find prot ID and offset pair, based on prof and FV index
2202 * @hw: pointer to the hardware structure
2203 * @blk: hardware block
2205 * @fv_idx: field vector word index
2206 * @prot: variable to receive the protocol ID
2207 * @off: variable to receive the protocol offset
2210 ice_find_prot_off(struct ice_hw *hw, enum ice_block blk, u8 prof, u16 fv_idx,
2213 struct ice_fv_word *fv_ext;
2215 if (prof >= hw->blk[blk].es.count)
2216 return ICE_ERR_PARAM;
2218 if (fv_idx >= hw->blk[blk].es.fvw)
2219 return ICE_ERR_PARAM;
2221 fv_ext = hw->blk[blk].es.t + (prof * hw->blk[blk].es.fvw);
2223 *prot = fv_ext[fv_idx].prot_id;
2224 *off = fv_ext[fv_idx].off;
2229 /* PTG Management */
2232 * ice_ptg_find_ptype - Search for packet type group using packet type (ptype)
2233 * @hw: pointer to the hardware structure
2235 * @ptype: the ptype to search for
2236 * @ptg: pointer to variable that receives the PTG
2238 * This function will search the PTGs for a particular ptype, returning the
2239 * PTG ID that contains it through the PTG parameter, with the value of
2240 * ICE_DEFAULT_PTG (0) meaning it is part the default PTG.
2242 static enum ice_status
2243 ice_ptg_find_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 *ptg)
2245 if (ptype >= ICE_XLT1_CNT || !ptg)
2246 return ICE_ERR_PARAM;
2248 *ptg = hw->blk[blk].xlt1.ptypes[ptype].ptg;
2253 * ice_ptg_alloc_val - Allocates a new packet type group ID by value
2254 * @hw: pointer to the hardware structure
2256 * @ptg: the PTG to allocate
2258 * This function allocates a given packet type group ID specified by the PTG
2261 static void ice_ptg_alloc_val(struct ice_hw *hw, enum ice_block blk, u8 ptg)
2263 hw->blk[blk].xlt1.ptg_tbl[ptg].in_use = true;
2267 * ice_ptg_remove_ptype - Removes ptype from a particular packet type group
2268 * @hw: pointer to the hardware structure
2270 * @ptype: the ptype to remove
2271 * @ptg: the PTG to remove the ptype from
2273 * This function will remove the ptype from the specific PTG, and move it to
2274 * the default PTG (ICE_DEFAULT_PTG).
2276 static enum ice_status
2277 ice_ptg_remove_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 ptg)
2279 struct ice_ptg_ptype **ch;
2280 struct ice_ptg_ptype *p;
2282 if (ptype > ICE_XLT1_CNT - 1)
2283 return ICE_ERR_PARAM;
2285 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].in_use)
2286 return ICE_ERR_DOES_NOT_EXIST;
2288 /* Should not happen if .in_use is set, bad config */
2289 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype)
2292 /* find the ptype within this PTG, and bypass the link over it */
2293 p = hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2294 ch = &hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2296 if (ptype == (p - hw->blk[blk].xlt1.ptypes)) {
2297 *ch = p->next_ptype;
2301 ch = &p->next_ptype;
2305 hw->blk[blk].xlt1.ptypes[ptype].ptg = ICE_DEFAULT_PTG;
2306 hw->blk[blk].xlt1.ptypes[ptype].next_ptype = NULL;
2312 * ice_ptg_add_mv_ptype - Adds/moves ptype to a particular packet type group
2313 * @hw: pointer to the hardware structure
2315 * @ptype: the ptype to add or move
2316 * @ptg: the PTG to add or move the ptype to
2318 * This function will either add or move a ptype to a particular PTG depending
2319 * on if the ptype is already part of another group. Note that using a
2320 * a destination PTG ID of ICE_DEFAULT_PTG (0) will move the ptype to the
2323 static enum ice_status
2324 ice_ptg_add_mv_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 ptg)
2326 enum ice_status status;
2329 if (ptype > ICE_XLT1_CNT - 1)
2330 return ICE_ERR_PARAM;
2332 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].in_use && ptg != ICE_DEFAULT_PTG)
2333 return ICE_ERR_DOES_NOT_EXIST;
2335 status = ice_ptg_find_ptype(hw, blk, ptype, &original_ptg);
2339 /* Is ptype already in the correct PTG? */
2340 if (original_ptg == ptg)
2343 /* Remove from original PTG and move back to the default PTG */
2344 if (original_ptg != ICE_DEFAULT_PTG)
2345 ice_ptg_remove_ptype(hw, blk, ptype, original_ptg);
2347 /* Moving to default PTG? Then we're done with this request */
2348 if (ptg == ICE_DEFAULT_PTG)
2351 /* Add ptype to PTG at beginning of list */
2352 hw->blk[blk].xlt1.ptypes[ptype].next_ptype =
2353 hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2354 hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype =
2355 &hw->blk[blk].xlt1.ptypes[ptype];
2357 hw->blk[blk].xlt1.ptypes[ptype].ptg = ptg;
2358 hw->blk[blk].xlt1.t[ptype] = ptg;
2363 /* Block / table size info */
2364 struct ice_blk_size_details {
2365 u16 xlt1; /* # XLT1 entries */
2366 u16 xlt2; /* # XLT2 entries */
2367 u16 prof_tcam; /* # profile ID TCAM entries */
2368 u16 prof_id; /* # profile IDs */
2369 u8 prof_cdid_bits; /* # CDID one-hot bits used in key */
2370 u16 prof_redir; /* # profile redirection entries */
2371 u16 es; /* # extraction sequence entries */
2372 u16 fvw; /* # field vector words */
2373 u8 overwrite; /* overwrite existing entries allowed */
2374 u8 reverse; /* reverse FV order */
2377 static const struct ice_blk_size_details blk_sizes[ICE_BLK_COUNT] = {
2380 * XLT1 - Number of entries in XLT1 table
2381 * XLT2 - Number of entries in XLT2 table
2382 * TCAM - Number of entries Profile ID TCAM table
2383 * CDID - Control Domain ID of the hardware block
2384 * PRED - Number of entries in the Profile Redirection Table
2385 * FV - Number of entries in the Field Vector
2386 * FVW - Width (in WORDs) of the Field Vector
2387 * OVR - Overwrite existing table entries
2390 /* XLT1 , XLT2 ,TCAM, PID,CDID,PRED, FV, FVW */
2391 /* Overwrite , Reverse FV */
2392 /* SW */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 256, 0, 256, 256, 48,
2394 /* ACL */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 32,
2396 /* FD */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 24,
2398 /* RSS */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 24,
2400 /* PE */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 64, 32, 0, 32, 32, 24,
2405 ICE_SID_XLT1_OFF = 0,
2408 ICE_SID_PR_REDIR_OFF,
2413 /* Characteristic handling */
2416 * ice_match_prop_lst - determine if properties of two lists match
2417 * @list1: first properties list
2418 * @list2: second properties list
2420 * Count, cookies and the order must match in order to be considered equivalent.
2423 ice_match_prop_lst(struct LIST_HEAD_TYPE *list1, struct LIST_HEAD_TYPE *list2)
2425 struct ice_vsig_prof *tmp1;
2426 struct ice_vsig_prof *tmp2;
2430 /* compare counts */
2431 LIST_FOR_EACH_ENTRY(tmp1, list1, ice_vsig_prof, list) {
2434 LIST_FOR_EACH_ENTRY(tmp2, list2, ice_vsig_prof, list) {
2437 if (!count || count != chk_count)
2440 tmp1 = LIST_FIRST_ENTRY(list1, struct ice_vsig_prof, list);
2441 tmp2 = LIST_FIRST_ENTRY(list2, struct ice_vsig_prof, list);
2443 /* profile cookies must compare, and in the exact same order to take
2444 * into account priority
2447 if (tmp2->profile_cookie != tmp1->profile_cookie)
2450 tmp1 = LIST_NEXT_ENTRY(tmp1, struct ice_vsig_prof, list);
2451 tmp2 = LIST_NEXT_ENTRY(tmp2, struct ice_vsig_prof, list);
2457 /* VSIG Management */
2460 * ice_vsig_find_vsi - find a VSIG that contains a specified VSI
2461 * @hw: pointer to the hardware structure
2463 * @vsi: VSI of interest
2464 * @vsig: pointer to receive the VSI group
2466 * This function will lookup the VSI entry in the XLT2 list and return
2467 * the VSI group its associated with.
2470 ice_vsig_find_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 *vsig)
2472 if (!vsig || vsi >= ICE_MAX_VSI)
2473 return ICE_ERR_PARAM;
2475 /* As long as there's a default or valid VSIG associated with the input
2476 * VSI, the functions returns a success. Any handling of VSIG will be
2477 * done by the following add, update or remove functions.
2479 *vsig = hw->blk[blk].xlt2.vsis[vsi].vsig;
2485 * ice_vsig_alloc_val - allocate a new VSIG by value
2486 * @hw: pointer to the hardware structure
2488 * @vsig: the VSIG to allocate
2490 * This function will allocate a given VSIG specified by the VSIG parameter.
2492 static u16 ice_vsig_alloc_val(struct ice_hw *hw, enum ice_block blk, u16 vsig)
2494 u16 idx = vsig & ICE_VSIG_IDX_M;
2496 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use) {
2497 INIT_LIST_HEAD(&hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst);
2498 hw->blk[blk].xlt2.vsig_tbl[idx].in_use = true;
2501 return ICE_VSIG_VALUE(idx, hw->pf_id);
2505 * ice_vsig_alloc - Finds a free entry and allocates a new VSIG
2506 * @hw: pointer to the hardware structure
2509 * This function will iterate through the VSIG list and mark the first
2510 * unused entry for the new VSIG entry as used and return that value.
2512 static u16 ice_vsig_alloc(struct ice_hw *hw, enum ice_block blk)
2516 for (i = 1; i < ICE_MAX_VSIGS; i++)
2517 if (!hw->blk[blk].xlt2.vsig_tbl[i].in_use)
2518 return ice_vsig_alloc_val(hw, blk, i);
2520 return ICE_DEFAULT_VSIG;
2524 * ice_find_dup_props_vsig - find VSI group with a specified set of properties
2525 * @hw: pointer to the hardware structure
2527 * @chs: characteristic list
2528 * @vsig: returns the VSIG with the matching profiles, if found
2530 * Each VSIG is associated with a characteristic set; i.e. all VSIs under
2531 * a group have the same characteristic set. To check if there exists a VSIG
2532 * which has the same characteristics as the input characteristics; this
2533 * function will iterate through the XLT2 list and return the VSIG that has a
2534 * matching configuration. In order to make sure that priorities are accounted
2535 * for, the list must match exactly, including the order in which the
2536 * characteristics are listed.
2538 static enum ice_status
2539 ice_find_dup_props_vsig(struct ice_hw *hw, enum ice_block blk,
2540 struct LIST_HEAD_TYPE *chs, u16 *vsig)
2542 struct ice_xlt2 *xlt2 = &hw->blk[blk].xlt2;
2545 for (i = 0; i < xlt2->count; i++) {
2546 if (xlt2->vsig_tbl[i].in_use &&
2547 ice_match_prop_lst(chs, &xlt2->vsig_tbl[i].prop_lst)) {
2548 *vsig = ICE_VSIG_VALUE(i, hw->pf_id);
2553 return ICE_ERR_DOES_NOT_EXIST;
2557 * ice_vsig_free - free VSI group
2558 * @hw: pointer to the hardware structure
2560 * @vsig: VSIG to remove
2562 * The function will remove all VSIs associated with the input VSIG and move
2563 * them to the DEFAULT_VSIG and mark the VSIG available.
2565 static enum ice_status
2566 ice_vsig_free(struct ice_hw *hw, enum ice_block blk, u16 vsig)
2568 struct ice_vsig_prof *dtmp, *del;
2569 struct ice_vsig_vsi *vsi_cur;
2572 idx = vsig & ICE_VSIG_IDX_M;
2573 if (idx >= ICE_MAX_VSIGS)
2574 return ICE_ERR_PARAM;
2576 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
2577 return ICE_ERR_DOES_NOT_EXIST;
2579 hw->blk[blk].xlt2.vsig_tbl[idx].in_use = false;
2581 vsi_cur = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2582 /* If the VSIG has at least 1 VSI then iterate through the
2583 * list and remove the VSIs before deleting the group.
2586 /* remove all vsis associated with this VSIG XLT2 entry */
2588 struct ice_vsig_vsi *tmp = vsi_cur->next_vsi;
2590 vsi_cur->vsig = ICE_DEFAULT_VSIG;
2591 vsi_cur->changed = 1;
2592 vsi_cur->next_vsi = NULL;
2596 /* NULL terminate head of VSI list */
2597 hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi = NULL;
2600 /* free characteristic list */
2601 LIST_FOR_EACH_ENTRY_SAFE(del, dtmp,
2602 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
2603 ice_vsig_prof, list) {
2604 LIST_DEL(&del->list);
2608 /* if VSIG characteristic list was cleared for reset
2609 * re-initialize the list head
2611 INIT_LIST_HEAD(&hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst);
2617 * ice_vsig_remove_vsi - remove VSI from VSIG
2618 * @hw: pointer to the hardware structure
2620 * @vsi: VSI to remove
2621 * @vsig: VSI group to remove from
2623 * The function will remove the input VSI from its VSI group and move it
2624 * to the DEFAULT_VSIG.
2626 static enum ice_status
2627 ice_vsig_remove_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
2629 struct ice_vsig_vsi **vsi_head, *vsi_cur, *vsi_tgt;
2632 idx = vsig & ICE_VSIG_IDX_M;
2634 if (vsi >= ICE_MAX_VSI || idx >= ICE_MAX_VSIGS)
2635 return ICE_ERR_PARAM;
2637 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
2638 return ICE_ERR_DOES_NOT_EXIST;
2640 /* entry already in default VSIG, don't have to remove */
2641 if (idx == ICE_DEFAULT_VSIG)
2644 vsi_head = &hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2648 vsi_tgt = &hw->blk[blk].xlt2.vsis[vsi];
2649 vsi_cur = (*vsi_head);
2651 /* iterate the VSI list, skip over the entry to be removed */
2653 if (vsi_tgt == vsi_cur) {
2654 (*vsi_head) = vsi_cur->next_vsi;
2657 vsi_head = &vsi_cur->next_vsi;
2658 vsi_cur = vsi_cur->next_vsi;
2661 /* verify if VSI was removed from group list */
2663 return ICE_ERR_DOES_NOT_EXIST;
2665 vsi_cur->vsig = ICE_DEFAULT_VSIG;
2666 vsi_cur->changed = 1;
2667 vsi_cur->next_vsi = NULL;
2673 * ice_vsig_add_mv_vsi - add or move a VSI to a VSI group
2674 * @hw: pointer to the hardware structure
2677 * @vsig: destination VSI group
2679 * This function will move or add the input VSI to the target VSIG.
2680 * The function will find the original VSIG the VSI belongs to and
2681 * move the entry to the DEFAULT_VSIG, update the original VSIG and
2682 * then move entry to the new VSIG.
2684 static enum ice_status
2685 ice_vsig_add_mv_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
2687 struct ice_vsig_vsi *tmp;
2688 enum ice_status status;
2691 idx = vsig & ICE_VSIG_IDX_M;
2693 if (vsi >= ICE_MAX_VSI || idx >= ICE_MAX_VSIGS)
2694 return ICE_ERR_PARAM;
2696 /* if VSIG not in use and VSIG is not default type this VSIG
2699 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use &&
2700 vsig != ICE_DEFAULT_VSIG)
2701 return ICE_ERR_DOES_NOT_EXIST;
2703 status = ice_vsig_find_vsi(hw, blk, vsi, &orig_vsig);
2707 /* no update required if vsigs match */
2708 if (orig_vsig == vsig)
2711 if (orig_vsig != ICE_DEFAULT_VSIG) {
2712 /* remove entry from orig_vsig and add to default VSIG */
2713 status = ice_vsig_remove_vsi(hw, blk, vsi, orig_vsig);
2718 if (idx == ICE_DEFAULT_VSIG)
2721 /* Create VSI entry and add VSIG and prop_mask values */
2722 hw->blk[blk].xlt2.vsis[vsi].vsig = vsig;
2723 hw->blk[blk].xlt2.vsis[vsi].changed = 1;
2725 /* Add new entry to the head of the VSIG list */
2726 tmp = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2727 hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi =
2728 &hw->blk[blk].xlt2.vsis[vsi];
2729 hw->blk[blk].xlt2.vsis[vsi].next_vsi = tmp;
2730 hw->blk[blk].xlt2.t[vsi] = vsig;
2736 * ice_prof_has_mask_idx - determine if profile index masking is identical
2737 * @hw: pointer to the hardware structure
2739 * @prof: profile to check
2740 * @idx: profile index to check
2741 * @mask: mask to match
2744 ice_prof_has_mask_idx(struct ice_hw *hw, enum ice_block blk, u8 prof, u16 idx,
2747 bool expect_no_mask = false;
2752 /* If mask is 0x0000 or 0xffff, then there is no masking */
2753 if (mask == 0 || mask == 0xffff)
2754 expect_no_mask = true;
2756 /* Scan the enabled masks on this profile, for the specified idx */
2757 for (i = hw->blk[blk].masks.first; i < hw->blk[blk].masks.first +
2758 hw->blk[blk].masks.count; i++)
2759 if (hw->blk[blk].es.mask_ena[prof] & BIT(i))
2760 if (hw->blk[blk].masks.masks[i].in_use &&
2761 hw->blk[blk].masks.masks[i].idx == idx) {
2763 if (hw->blk[blk].masks.masks[i].mask == mask)
2768 if (expect_no_mask) {
2780 * ice_prof_has_mask - determine if profile masking is identical
2781 * @hw: pointer to the hardware structure
2783 * @prof: profile to check
2784 * @masks: masks to match
2787 ice_prof_has_mask(struct ice_hw *hw, enum ice_block blk, u8 prof, u16 *masks)
2791 /* es->mask_ena[prof] will have the mask */
2792 for (i = 0; i < hw->blk[blk].es.fvw; i++)
2793 if (!ice_prof_has_mask_idx(hw, blk, prof, i, masks[i]))
2800 * ice_find_prof_id_with_mask - find profile ID for a given field vector
2801 * @hw: pointer to the hardware structure
2803 * @fv: field vector to search for
2804 * @masks: masks for fv
2805 * @prof_id: receives the profile ID
2807 static enum ice_status
2808 ice_find_prof_id_with_mask(struct ice_hw *hw, enum ice_block blk,
2809 struct ice_fv_word *fv, u16 *masks, u8 *prof_id)
2811 struct ice_es *es = &hw->blk[blk].es;
2814 /* For FD, we don't want to re-use an existed profile with the same
2815 * field vector and mask. This will cause rule interference.
2817 if (blk == ICE_BLK_FD)
2818 return ICE_ERR_DOES_NOT_EXIST;
2820 for (i = 0; i < (u8)es->count; i++) {
2821 u16 off = i * es->fvw;
2823 if (memcmp(&es->t[off], fv, es->fvw * sizeof(*fv)))
2826 /* check if masks settings are the same for this profile */
2827 if (masks && !ice_prof_has_mask(hw, blk, i, masks))
2834 return ICE_ERR_DOES_NOT_EXIST;
2838 * ice_prof_id_rsrc_type - get profile ID resource type for a block type
2839 * @blk: the block type
2840 * @rsrc_type: pointer to variable to receive the resource type
2842 static bool ice_prof_id_rsrc_type(enum ice_block blk, u16 *rsrc_type)
2846 *rsrc_type = ICE_AQC_RES_TYPE_SWITCH_PROF_BLDR_PROFID;
2849 *rsrc_type = ICE_AQC_RES_TYPE_ACL_PROF_BLDR_PROFID;
2852 *rsrc_type = ICE_AQC_RES_TYPE_FD_PROF_BLDR_PROFID;
2855 *rsrc_type = ICE_AQC_RES_TYPE_HASH_PROF_BLDR_PROFID;
2858 *rsrc_type = ICE_AQC_RES_TYPE_QHASH_PROF_BLDR_PROFID;
2867 * ice_tcam_ent_rsrc_type - get TCAM entry resource type for a block type
2868 * @blk: the block type
2869 * @rsrc_type: pointer to variable to receive the resource type
2871 static bool ice_tcam_ent_rsrc_type(enum ice_block blk, u16 *rsrc_type)
2875 *rsrc_type = ICE_AQC_RES_TYPE_SWITCH_PROF_BLDR_TCAM;
2878 *rsrc_type = ICE_AQC_RES_TYPE_ACL_PROF_BLDR_TCAM;
2881 *rsrc_type = ICE_AQC_RES_TYPE_FD_PROF_BLDR_TCAM;
2884 *rsrc_type = ICE_AQC_RES_TYPE_HASH_PROF_BLDR_TCAM;
2887 *rsrc_type = ICE_AQC_RES_TYPE_QHASH_PROF_BLDR_TCAM;
2896 * ice_alloc_tcam_ent - allocate hardware TCAM entry
2897 * @hw: pointer to the HW struct
2898 * @blk: the block to allocate the TCAM for
2899 * @tcam_idx: pointer to variable to receive the TCAM entry
2901 * This function allocates a new entry in a Profile ID TCAM for a specific
2904 static enum ice_status
2905 ice_alloc_tcam_ent(struct ice_hw *hw, enum ice_block blk, u16 *tcam_idx)
2909 if (!ice_tcam_ent_rsrc_type(blk, &res_type))
2910 return ICE_ERR_PARAM;
2912 return ice_alloc_hw_res(hw, res_type, 1, true, tcam_idx);
2916 * ice_free_tcam_ent - free hardware TCAM entry
2917 * @hw: pointer to the HW struct
2918 * @blk: the block from which to free the TCAM entry
2919 * @tcam_idx: the TCAM entry to free
2921 * This function frees an entry in a Profile ID TCAM for a specific block.
2923 static enum ice_status
2924 ice_free_tcam_ent(struct ice_hw *hw, enum ice_block blk, u16 tcam_idx)
2928 if (!ice_tcam_ent_rsrc_type(blk, &res_type))
2929 return ICE_ERR_PARAM;
2931 return ice_free_hw_res(hw, res_type, 1, &tcam_idx);
2935 * ice_alloc_prof_id - allocate profile ID
2936 * @hw: pointer to the HW struct
2937 * @blk: the block to allocate the profile ID for
2938 * @prof_id: pointer to variable to receive the profile ID
2940 * This function allocates a new profile ID, which also corresponds to a Field
2941 * Vector (Extraction Sequence) entry.
2943 static enum ice_status
2944 ice_alloc_prof_id(struct ice_hw *hw, enum ice_block blk, u8 *prof_id)
2946 enum ice_status status;
2950 if (!ice_prof_id_rsrc_type(blk, &res_type))
2951 return ICE_ERR_PARAM;
2953 status = ice_alloc_hw_res(hw, res_type, 1, false, &get_prof);
2955 *prof_id = (u8)get_prof;
2961 * ice_free_prof_id - free profile ID
2962 * @hw: pointer to the HW struct
2963 * @blk: the block from which to free the profile ID
2964 * @prof_id: the profile ID to free
2966 * This function frees a profile ID, which also corresponds to a Field Vector.
2968 static enum ice_status
2969 ice_free_prof_id(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
2971 u16 tmp_prof_id = (u16)prof_id;
2974 if (!ice_prof_id_rsrc_type(blk, &res_type))
2975 return ICE_ERR_PARAM;
2977 return ice_free_hw_res(hw, res_type, 1, &tmp_prof_id);
2981 * ice_prof_inc_ref - increment reference count for profile
2982 * @hw: pointer to the HW struct
2983 * @blk: the block from which to free the profile ID
2984 * @prof_id: the profile ID for which to increment the reference count
2986 static enum ice_status
2987 ice_prof_inc_ref(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
2989 if (prof_id > hw->blk[blk].es.count)
2990 return ICE_ERR_PARAM;
2992 hw->blk[blk].es.ref_count[prof_id]++;
2998 * ice_write_prof_mask_reg - write profile mask register
2999 * @hw: pointer to the HW struct
3000 * @blk: hardware block
3001 * @mask_idx: mask index
3002 * @idx: index of the FV which will use the mask
3003 * @mask: the 16-bit mask
3006 ice_write_prof_mask_reg(struct ice_hw *hw, enum ice_block blk, u16 mask_idx,
3014 offset = GLQF_HMASK(mask_idx);
3015 val = (idx << GLQF_HMASK_MSK_INDEX_S) &
3016 GLQF_HMASK_MSK_INDEX_M;
3017 val |= (mask << GLQF_HMASK_MASK_S) & GLQF_HMASK_MASK_M;
3020 offset = GLQF_FDMASK(mask_idx);
3021 val = (idx << GLQF_FDMASK_MSK_INDEX_S) &
3022 GLQF_FDMASK_MSK_INDEX_M;
3023 val |= (mask << GLQF_FDMASK_MASK_S) &
3027 ice_debug(hw, ICE_DBG_PKG, "No profile masks for block %d\n",
3032 wr32(hw, offset, val);
3033 ice_debug(hw, ICE_DBG_PKG, "write mask, blk %d (%d): %x = %x\n",
3034 blk, idx, offset, val);
3038 * ice_write_prof_mask_enable_res - write profile mask enable register
3039 * @hw: pointer to the HW struct
3040 * @blk: hardware block
3041 * @prof_id: profile ID
3042 * @enable_mask: enable mask
3045 ice_write_prof_mask_enable_res(struct ice_hw *hw, enum ice_block blk,
3046 u16 prof_id, u32 enable_mask)
3052 offset = GLQF_HMASK_SEL(prof_id);
3055 offset = GLQF_FDMASK_SEL(prof_id);
3058 ice_debug(hw, ICE_DBG_PKG, "No profile masks for block %d\n",
3063 wr32(hw, offset, enable_mask);
3064 ice_debug(hw, ICE_DBG_PKG, "write mask enable, blk %d (%d): %x = %x\n",
3065 blk, prof_id, offset, enable_mask);
3069 * ice_init_prof_masks - initial prof masks
3070 * @hw: pointer to the HW struct
3071 * @blk: hardware block
3073 static void ice_init_prof_masks(struct ice_hw *hw, enum ice_block blk)
3078 ice_init_lock(&hw->blk[blk].masks.lock);
3080 per_pf = ICE_PROF_MASK_COUNT / hw->dev_caps.num_funcs;
3082 hw->blk[blk].masks.count = per_pf;
3083 hw->blk[blk].masks.first = hw->pf_id * per_pf;
3085 ice_memset(hw->blk[blk].masks.masks, 0,
3086 sizeof(hw->blk[blk].masks.masks), ICE_NONDMA_MEM);
3088 for (i = hw->blk[blk].masks.first;
3089 i < hw->blk[blk].masks.first + hw->blk[blk].masks.count; i++)
3090 ice_write_prof_mask_reg(hw, blk, i, 0, 0);
3094 * ice_init_all_prof_masks - initial all prof masks
3095 * @hw: pointer to the HW struct
3097 void ice_init_all_prof_masks(struct ice_hw *hw)
3099 ice_init_prof_masks(hw, ICE_BLK_RSS);
3100 ice_init_prof_masks(hw, ICE_BLK_FD);
3104 * ice_alloc_prof_mask - allocate profile mask
3105 * @hw: pointer to the HW struct
3106 * @blk: hardware block
3107 * @idx: index of FV which will use the mask
3108 * @mask: the 16-bit mask
3109 * @mask_idx: variable to receive the mask index
3111 static enum ice_status
3112 ice_alloc_prof_mask(struct ice_hw *hw, enum ice_block blk, u16 idx, u16 mask,
3115 bool found_unused = false, found_copy = false;
3116 enum ice_status status = ICE_ERR_MAX_LIMIT;
3117 u16 unused_idx = 0, copy_idx = 0;
3120 if (blk != ICE_BLK_RSS && blk != ICE_BLK_FD)
3121 return ICE_ERR_PARAM;
3123 ice_acquire_lock(&hw->blk[blk].masks.lock);
3125 for (i = hw->blk[blk].masks.first;
3126 i < hw->blk[blk].masks.first + hw->blk[blk].masks.count; i++)
3127 if (hw->blk[blk].masks.masks[i].in_use) {
3128 /* if mask is in use and it exactly duplicates the
3129 * desired mask and index, then in can be reused
3131 if (hw->blk[blk].masks.masks[i].mask == mask &&
3132 hw->blk[blk].masks.masks[i].idx == idx) {
3138 /* save off unused index, but keep searching in case
3139 * there is an exact match later on
3141 if (!found_unused) {
3142 found_unused = true;
3149 else if (found_unused)
3152 goto err_ice_alloc_prof_mask;
3154 /* update mask for a new entry */
3156 hw->blk[blk].masks.masks[i].in_use = true;
3157 hw->blk[blk].masks.masks[i].mask = mask;
3158 hw->blk[blk].masks.masks[i].idx = idx;
3159 hw->blk[blk].masks.masks[i].ref = 0;
3160 ice_write_prof_mask_reg(hw, blk, i, idx, mask);
3163 hw->blk[blk].masks.masks[i].ref++;
3165 status = ICE_SUCCESS;
3167 err_ice_alloc_prof_mask:
3168 ice_release_lock(&hw->blk[blk].masks.lock);
3174 * ice_free_prof_mask - free profile mask
3175 * @hw: pointer to the HW struct
3176 * @blk: hardware block
3177 * @mask_idx: index of mask
3179 static enum ice_status
3180 ice_free_prof_mask(struct ice_hw *hw, enum ice_block blk, u16 mask_idx)
3182 if (blk != ICE_BLK_RSS && blk != ICE_BLK_FD)
3183 return ICE_ERR_PARAM;
3185 if (!(mask_idx >= hw->blk[blk].masks.first &&
3186 mask_idx < hw->blk[blk].masks.first + hw->blk[blk].masks.count))
3187 return ICE_ERR_DOES_NOT_EXIST;
3189 ice_acquire_lock(&hw->blk[blk].masks.lock);
3191 if (!hw->blk[blk].masks.masks[mask_idx].in_use)
3192 goto exit_ice_free_prof_mask;
3194 if (hw->blk[blk].masks.masks[mask_idx].ref > 1) {
3195 hw->blk[blk].masks.masks[mask_idx].ref--;
3196 goto exit_ice_free_prof_mask;
3200 hw->blk[blk].masks.masks[mask_idx].in_use = false;
3201 hw->blk[blk].masks.masks[mask_idx].mask = 0;
3202 hw->blk[blk].masks.masks[mask_idx].idx = 0;
3204 /* update mask as unused entry */
3205 ice_debug(hw, ICE_DBG_PKG, "Free mask, blk %d, mask %d\n", blk,
3207 ice_write_prof_mask_reg(hw, blk, mask_idx, 0, 0);
3209 exit_ice_free_prof_mask:
3210 ice_release_lock(&hw->blk[blk].masks.lock);
3216 * ice_free_prof_masks - free all profile masks for a profile
3217 * @hw: pointer to the HW struct
3218 * @blk: hardware block
3219 * @prof_id: profile ID
3221 static enum ice_status
3222 ice_free_prof_masks(struct ice_hw *hw, enum ice_block blk, u16 prof_id)
3227 if (blk != ICE_BLK_RSS && blk != ICE_BLK_FD)
3228 return ICE_ERR_PARAM;
3230 mask_bm = hw->blk[blk].es.mask_ena[prof_id];
3231 for (i = 0; i < BITS_PER_BYTE * sizeof(mask_bm); i++)
3232 if (mask_bm & BIT(i))
3233 ice_free_prof_mask(hw, blk, i);
3239 * ice_shutdown_prof_masks - releases lock for masking
3240 * @hw: pointer to the HW struct
3241 * @blk: hardware block
3243 * This should be called before unloading the driver
3245 static void ice_shutdown_prof_masks(struct ice_hw *hw, enum ice_block blk)
3249 ice_acquire_lock(&hw->blk[blk].masks.lock);
3251 for (i = hw->blk[blk].masks.first;
3252 i < hw->blk[blk].masks.first + hw->blk[blk].masks.count; i++) {
3253 ice_write_prof_mask_reg(hw, blk, i, 0, 0);
3255 hw->blk[blk].masks.masks[i].in_use = false;
3256 hw->blk[blk].masks.masks[i].idx = 0;
3257 hw->blk[blk].masks.masks[i].mask = 0;
3260 ice_release_lock(&hw->blk[blk].masks.lock);
3261 ice_destroy_lock(&hw->blk[blk].masks.lock);
3265 * ice_shutdown_all_prof_masks - releases all locks for masking
3266 * @hw: pointer to the HW struct
3268 * This should be called before unloading the driver
3270 void ice_shutdown_all_prof_masks(struct ice_hw *hw)
3272 ice_shutdown_prof_masks(hw, ICE_BLK_RSS);
3273 ice_shutdown_prof_masks(hw, ICE_BLK_FD);
3277 * ice_update_prof_masking - set registers according to masking
3278 * @hw: pointer to the HW struct
3279 * @blk: hardware block
3280 * @prof_id: profile ID
3283 static enum ice_status
3284 ice_update_prof_masking(struct ice_hw *hw, enum ice_block blk, u16 prof_id,
3292 /* Only support FD and RSS masking, otherwise nothing to be done */
3293 if (blk != ICE_BLK_RSS && blk != ICE_BLK_FD)
3296 for (i = 0; i < hw->blk[blk].es.fvw; i++)
3297 if (masks[i] && masks[i] != 0xFFFF) {
3298 if (!ice_alloc_prof_mask(hw, blk, i, masks[i], &idx)) {
3299 ena_mask |= BIT(idx);
3301 /* not enough bitmaps */
3308 /* free any bitmaps we have allocated */
3309 for (i = 0; i < BITS_PER_BYTE * sizeof(ena_mask); i++)
3310 if (ena_mask & BIT(i))
3311 ice_free_prof_mask(hw, blk, i);
3313 return ICE_ERR_OUT_OF_RANGE;
3316 /* enable the masks for this profile */
3317 ice_write_prof_mask_enable_res(hw, blk, prof_id, ena_mask);
3319 /* store enabled masks with profile so that they can be freed later */
3320 hw->blk[blk].es.mask_ena[prof_id] = ena_mask;
3326 * ice_write_es - write an extraction sequence to hardware
3327 * @hw: pointer to the HW struct
3328 * @blk: the block in which to write the extraction sequence
3329 * @prof_id: the profile ID to write
3330 * @fv: pointer to the extraction sequence to write - NULL to clear extraction
3333 ice_write_es(struct ice_hw *hw, enum ice_block blk, u8 prof_id,
3334 struct ice_fv_word *fv)
3338 off = prof_id * hw->blk[blk].es.fvw;
3340 ice_memset(&hw->blk[blk].es.t[off], 0, hw->blk[blk].es.fvw *
3341 sizeof(*fv), ICE_NONDMA_MEM);
3342 hw->blk[blk].es.written[prof_id] = false;
3344 ice_memcpy(&hw->blk[blk].es.t[off], fv, hw->blk[blk].es.fvw *
3345 sizeof(*fv), ICE_NONDMA_TO_NONDMA);
3350 * ice_prof_dec_ref - decrement reference count for profile
3351 * @hw: pointer to the HW struct
3352 * @blk: the block from which to free the profile ID
3353 * @prof_id: the profile ID for which to decrement the reference count
3355 static enum ice_status
3356 ice_prof_dec_ref(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
3358 if (prof_id > hw->blk[blk].es.count)
3359 return ICE_ERR_PARAM;
3361 if (hw->blk[blk].es.ref_count[prof_id] > 0) {
3362 if (!--hw->blk[blk].es.ref_count[prof_id]) {
3363 ice_write_es(hw, blk, prof_id, NULL);
3364 ice_free_prof_masks(hw, blk, prof_id);
3365 return ice_free_prof_id(hw, blk, prof_id);
3372 /* Block / table section IDs */
3373 static const u32 ice_blk_sids[ICE_BLK_COUNT][ICE_SID_OFF_COUNT] = {
3377 ICE_SID_PROFID_TCAM_SW,
3378 ICE_SID_PROFID_REDIR_SW,
3385 ICE_SID_PROFID_TCAM_ACL,
3386 ICE_SID_PROFID_REDIR_ACL,
3393 ICE_SID_PROFID_TCAM_FD,
3394 ICE_SID_PROFID_REDIR_FD,
3401 ICE_SID_PROFID_TCAM_RSS,
3402 ICE_SID_PROFID_REDIR_RSS,
3409 ICE_SID_PROFID_TCAM_PE,
3410 ICE_SID_PROFID_REDIR_PE,
3416 * ice_init_sw_xlt1_db - init software XLT1 database from HW tables
3417 * @hw: pointer to the hardware structure
3418 * @blk: the HW block to initialize
3420 static void ice_init_sw_xlt1_db(struct ice_hw *hw, enum ice_block blk)
3424 for (pt = 0; pt < hw->blk[blk].xlt1.count; pt++) {
3427 ptg = hw->blk[blk].xlt1.t[pt];
3428 if (ptg != ICE_DEFAULT_PTG) {
3429 ice_ptg_alloc_val(hw, blk, ptg);
3430 ice_ptg_add_mv_ptype(hw, blk, pt, ptg);
3436 * ice_init_sw_xlt2_db - init software XLT2 database from HW tables
3437 * @hw: pointer to the hardware structure
3438 * @blk: the HW block to initialize
3440 static void ice_init_sw_xlt2_db(struct ice_hw *hw, enum ice_block blk)
3444 for (vsi = 0; vsi < hw->blk[blk].xlt2.count; vsi++) {
3447 vsig = hw->blk[blk].xlt2.t[vsi];
3449 ice_vsig_alloc_val(hw, blk, vsig);
3450 ice_vsig_add_mv_vsi(hw, blk, vsi, vsig);
3451 /* no changes at this time, since this has been
3452 * initialized from the original package
3454 hw->blk[blk].xlt2.vsis[vsi].changed = 0;
3460 * ice_init_sw_db - init software database from HW tables
3461 * @hw: pointer to the hardware structure
3463 static void ice_init_sw_db(struct ice_hw *hw)
3467 for (i = 0; i < ICE_BLK_COUNT; i++) {
3468 ice_init_sw_xlt1_db(hw, (enum ice_block)i);
3469 ice_init_sw_xlt2_db(hw, (enum ice_block)i);
3474 * ice_fill_tbl - Reads content of a single table type into database
3475 * @hw: pointer to the hardware structure
3476 * @block_id: Block ID of the table to copy
3477 * @sid: Section ID of the table to copy
3479 * Will attempt to read the entire content of a given table of a single block
3480 * into the driver database. We assume that the buffer will always
3481 * be as large or larger than the data contained in the package. If
3482 * this condition is not met, there is most likely an error in the package
3485 static void ice_fill_tbl(struct ice_hw *hw, enum ice_block block_id, u32 sid)
3487 u32 dst_len, sect_len, offset = 0;
3488 struct ice_prof_redir_section *pr;
3489 struct ice_prof_id_section *pid;
3490 struct ice_xlt1_section *xlt1;
3491 struct ice_xlt2_section *xlt2;
3492 struct ice_sw_fv_section *es;
3493 struct ice_pkg_enum state;
3497 /* if the HW segment pointer is null then the first iteration of
3498 * ice_pkg_enum_section() will fail. In this case the HW tables will
3499 * not be filled and return success.
3502 ice_debug(hw, ICE_DBG_PKG, "hw->seg is NULL, tables are not filled\n");
3506 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
3508 sect = ice_pkg_enum_section(hw->seg, &state, sid);
3512 case ICE_SID_XLT1_SW:
3513 case ICE_SID_XLT1_FD:
3514 case ICE_SID_XLT1_RSS:
3515 case ICE_SID_XLT1_ACL:
3516 case ICE_SID_XLT1_PE:
3517 xlt1 = (struct ice_xlt1_section *)sect;
3519 sect_len = LE16_TO_CPU(xlt1->count) *
3520 sizeof(*hw->blk[block_id].xlt1.t);
3521 dst = hw->blk[block_id].xlt1.t;
3522 dst_len = hw->blk[block_id].xlt1.count *
3523 sizeof(*hw->blk[block_id].xlt1.t);
3525 case ICE_SID_XLT2_SW:
3526 case ICE_SID_XLT2_FD:
3527 case ICE_SID_XLT2_RSS:
3528 case ICE_SID_XLT2_ACL:
3529 case ICE_SID_XLT2_PE:
3530 xlt2 = (struct ice_xlt2_section *)sect;
3531 src = (_FORCE_ u8 *)xlt2->value;
3532 sect_len = LE16_TO_CPU(xlt2->count) *
3533 sizeof(*hw->blk[block_id].xlt2.t);
3534 dst = (u8 *)hw->blk[block_id].xlt2.t;
3535 dst_len = hw->blk[block_id].xlt2.count *
3536 sizeof(*hw->blk[block_id].xlt2.t);
3538 case ICE_SID_PROFID_TCAM_SW:
3539 case ICE_SID_PROFID_TCAM_FD:
3540 case ICE_SID_PROFID_TCAM_RSS:
3541 case ICE_SID_PROFID_TCAM_ACL:
3542 case ICE_SID_PROFID_TCAM_PE:
3543 pid = (struct ice_prof_id_section *)sect;
3544 src = (u8 *)pid->entry;
3545 sect_len = LE16_TO_CPU(pid->count) *
3546 sizeof(*hw->blk[block_id].prof.t);
3547 dst = (u8 *)hw->blk[block_id].prof.t;
3548 dst_len = hw->blk[block_id].prof.count *
3549 sizeof(*hw->blk[block_id].prof.t);
3551 case ICE_SID_PROFID_REDIR_SW:
3552 case ICE_SID_PROFID_REDIR_FD:
3553 case ICE_SID_PROFID_REDIR_RSS:
3554 case ICE_SID_PROFID_REDIR_ACL:
3555 case ICE_SID_PROFID_REDIR_PE:
3556 pr = (struct ice_prof_redir_section *)sect;
3557 src = pr->redir_value;
3558 sect_len = LE16_TO_CPU(pr->count) *
3559 sizeof(*hw->blk[block_id].prof_redir.t);
3560 dst = hw->blk[block_id].prof_redir.t;
3561 dst_len = hw->blk[block_id].prof_redir.count *
3562 sizeof(*hw->blk[block_id].prof_redir.t);
3564 case ICE_SID_FLD_VEC_SW:
3565 case ICE_SID_FLD_VEC_FD:
3566 case ICE_SID_FLD_VEC_RSS:
3567 case ICE_SID_FLD_VEC_ACL:
3568 case ICE_SID_FLD_VEC_PE:
3569 es = (struct ice_sw_fv_section *)sect;
3571 sect_len = (u32)(LE16_TO_CPU(es->count) *
3572 hw->blk[block_id].es.fvw) *
3573 sizeof(*hw->blk[block_id].es.t);
3574 dst = (u8 *)hw->blk[block_id].es.t;
3575 dst_len = (u32)(hw->blk[block_id].es.count *
3576 hw->blk[block_id].es.fvw) *
3577 sizeof(*hw->blk[block_id].es.t);
3583 /* if the section offset exceeds destination length, terminate
3586 if (offset > dst_len)
3589 /* if the sum of section size and offset exceed destination size
3590 * then we are out of bounds of the HW table size for that PF.
3591 * Changing section length to fill the remaining table space
3594 if ((offset + sect_len) > dst_len)
3595 sect_len = dst_len - offset;
3597 ice_memcpy(dst + offset, src, sect_len, ICE_NONDMA_TO_NONDMA);
3599 sect = ice_pkg_enum_section(NULL, &state, sid);
3604 * ice_fill_blk_tbls - Read package context for tables
3605 * @hw: pointer to the hardware structure
3607 * Reads the current package contents and populates the driver
3608 * database with the data iteratively for all advanced feature
3609 * blocks. Assume that the HW tables have been allocated.
3611 void ice_fill_blk_tbls(struct ice_hw *hw)
3615 for (i = 0; i < ICE_BLK_COUNT; i++) {
3616 enum ice_block blk_id = (enum ice_block)i;
3618 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].xlt1.sid);
3619 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].xlt2.sid);
3620 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].prof.sid);
3621 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].prof_redir.sid);
3622 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].es.sid);
3629 * ice_free_prof_map - free profile map
3630 * @hw: pointer to the hardware structure
3631 * @blk_idx: HW block index
3633 static void ice_free_prof_map(struct ice_hw *hw, u8 blk_idx)
3635 struct ice_es *es = &hw->blk[blk_idx].es;
3636 struct ice_prof_map *del, *tmp;
3638 ice_acquire_lock(&es->prof_map_lock);
3639 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &es->prof_map,
3640 ice_prof_map, list) {
3641 LIST_DEL(&del->list);
3644 INIT_LIST_HEAD(&es->prof_map);
3645 ice_release_lock(&es->prof_map_lock);
3649 * ice_free_flow_profs - free flow profile entries
3650 * @hw: pointer to the hardware structure
3651 * @blk_idx: HW block index
3653 static void ice_free_flow_profs(struct ice_hw *hw, u8 blk_idx)
3655 struct ice_flow_prof *p, *tmp;
3657 ice_acquire_lock(&hw->fl_profs_locks[blk_idx]);
3658 LIST_FOR_EACH_ENTRY_SAFE(p, tmp, &hw->fl_profs[blk_idx],
3659 ice_flow_prof, l_entry) {
3660 struct ice_flow_entry *e, *t;
3662 LIST_FOR_EACH_ENTRY_SAFE(e, t, &p->entries,
3663 ice_flow_entry, l_entry)
3664 ice_flow_rem_entry(hw, (enum ice_block)blk_idx,
3665 ICE_FLOW_ENTRY_HNDL(e));
3667 LIST_DEL(&p->l_entry);
3669 ice_free(hw, p->acts);
3672 ice_release_lock(&hw->fl_profs_locks[blk_idx]);
3674 /* if driver is in reset and tables are being cleared
3675 * re-initialize the flow profile list heads
3677 INIT_LIST_HEAD(&hw->fl_profs[blk_idx]);
3681 * ice_free_vsig_tbl - free complete VSIG table entries
3682 * @hw: pointer to the hardware structure
3683 * @blk: the HW block on which to free the VSIG table entries
3685 static void ice_free_vsig_tbl(struct ice_hw *hw, enum ice_block blk)
3689 if (!hw->blk[blk].xlt2.vsig_tbl)
3692 for (i = 1; i < ICE_MAX_VSIGS; i++)
3693 if (hw->blk[blk].xlt2.vsig_tbl[i].in_use)
3694 ice_vsig_free(hw, blk, i);
3698 * ice_free_hw_tbls - free hardware table memory
3699 * @hw: pointer to the hardware structure
3701 void ice_free_hw_tbls(struct ice_hw *hw)
3703 struct ice_rss_cfg *r, *rt;
3706 for (i = 0; i < ICE_BLK_COUNT; i++) {
3707 if (hw->blk[i].is_list_init) {
3708 struct ice_es *es = &hw->blk[i].es;
3710 ice_free_prof_map(hw, i);
3711 ice_destroy_lock(&es->prof_map_lock);
3712 ice_free_flow_profs(hw, i);
3713 ice_destroy_lock(&hw->fl_profs_locks[i]);
3715 hw->blk[i].is_list_init = false;
3717 ice_free_vsig_tbl(hw, (enum ice_block)i);
3718 ice_free(hw, hw->blk[i].xlt1.ptypes);
3719 ice_free(hw, hw->blk[i].xlt1.ptg_tbl);
3720 ice_free(hw, hw->blk[i].xlt1.t);
3721 ice_free(hw, hw->blk[i].xlt2.t);
3722 ice_free(hw, hw->blk[i].xlt2.vsig_tbl);
3723 ice_free(hw, hw->blk[i].xlt2.vsis);
3724 ice_free(hw, hw->blk[i].prof.t);
3725 ice_free(hw, hw->blk[i].prof_redir.t);
3726 ice_free(hw, hw->blk[i].es.t);
3727 ice_free(hw, hw->blk[i].es.ref_count);
3728 ice_free(hw, hw->blk[i].es.written);
3729 ice_free(hw, hw->blk[i].es.mask_ena);
3732 LIST_FOR_EACH_ENTRY_SAFE(r, rt, &hw->rss_list_head,
3733 ice_rss_cfg, l_entry) {
3734 LIST_DEL(&r->l_entry);
3737 ice_destroy_lock(&hw->rss_locks);
3738 if (!hw->dcf_enabled)
3739 ice_shutdown_all_prof_masks(hw);
3740 ice_memset(hw->blk, 0, sizeof(hw->blk), ICE_NONDMA_MEM);
3744 * ice_init_flow_profs - init flow profile locks and list heads
3745 * @hw: pointer to the hardware structure
3746 * @blk_idx: HW block index
3748 static void ice_init_flow_profs(struct ice_hw *hw, u8 blk_idx)
3750 ice_init_lock(&hw->fl_profs_locks[blk_idx]);
3751 INIT_LIST_HEAD(&hw->fl_profs[blk_idx]);
3755 * ice_clear_hw_tbls - clear HW tables and flow profiles
3756 * @hw: pointer to the hardware structure
3758 void ice_clear_hw_tbls(struct ice_hw *hw)
3762 for (i = 0; i < ICE_BLK_COUNT; i++) {
3763 struct ice_prof_redir *prof_redir = &hw->blk[i].prof_redir;
3764 struct ice_prof_tcam *prof = &hw->blk[i].prof;
3765 struct ice_xlt1 *xlt1 = &hw->blk[i].xlt1;
3766 struct ice_xlt2 *xlt2 = &hw->blk[i].xlt2;
3767 struct ice_es *es = &hw->blk[i].es;
3769 if (hw->blk[i].is_list_init) {
3770 ice_free_prof_map(hw, i);
3771 ice_free_flow_profs(hw, i);
3774 ice_free_vsig_tbl(hw, (enum ice_block)i);
3776 ice_memset(xlt1->ptypes, 0, xlt1->count * sizeof(*xlt1->ptypes),
3778 ice_memset(xlt1->ptg_tbl, 0,
3779 ICE_MAX_PTGS * sizeof(*xlt1->ptg_tbl),
3781 ice_memset(xlt1->t, 0, xlt1->count * sizeof(*xlt1->t),
3784 ice_memset(xlt2->vsis, 0, xlt2->count * sizeof(*xlt2->vsis),
3786 ice_memset(xlt2->vsig_tbl, 0,
3787 xlt2->count * sizeof(*xlt2->vsig_tbl),
3789 ice_memset(xlt2->t, 0, xlt2->count * sizeof(*xlt2->t),
3792 ice_memset(prof->t, 0, prof->count * sizeof(*prof->t),
3794 ice_memset(prof_redir->t, 0,
3795 prof_redir->count * sizeof(*prof_redir->t),
3798 ice_memset(es->t, 0, es->count * sizeof(*es->t),
3800 ice_memset(es->ref_count, 0, es->count * sizeof(*es->ref_count),
3802 ice_memset(es->written, 0, es->count * sizeof(*es->written),
3804 ice_memset(es->mask_ena, 0, es->count * sizeof(*es->mask_ena),
3810 * ice_init_hw_tbls - init hardware table memory
3811 * @hw: pointer to the hardware structure
3813 enum ice_status ice_init_hw_tbls(struct ice_hw *hw)
3817 ice_init_lock(&hw->rss_locks);
3818 INIT_LIST_HEAD(&hw->rss_list_head);
3819 if (!hw->dcf_enabled)
3820 ice_init_all_prof_masks(hw);
3821 for (i = 0; i < ICE_BLK_COUNT; i++) {
3822 struct ice_prof_redir *prof_redir = &hw->blk[i].prof_redir;
3823 struct ice_prof_tcam *prof = &hw->blk[i].prof;
3824 struct ice_xlt1 *xlt1 = &hw->blk[i].xlt1;
3825 struct ice_xlt2 *xlt2 = &hw->blk[i].xlt2;
3826 struct ice_es *es = &hw->blk[i].es;
3829 if (hw->blk[i].is_list_init)
3832 ice_init_flow_profs(hw, i);
3833 ice_init_lock(&es->prof_map_lock);
3834 INIT_LIST_HEAD(&es->prof_map);
3835 hw->blk[i].is_list_init = true;
3837 hw->blk[i].overwrite = blk_sizes[i].overwrite;
3838 es->reverse = blk_sizes[i].reverse;
3840 xlt1->sid = ice_blk_sids[i][ICE_SID_XLT1_OFF];
3841 xlt1->count = blk_sizes[i].xlt1;
3843 xlt1->ptypes = (struct ice_ptg_ptype *)
3844 ice_calloc(hw, xlt1->count, sizeof(*xlt1->ptypes));
3849 xlt1->ptg_tbl = (struct ice_ptg_entry *)
3850 ice_calloc(hw, ICE_MAX_PTGS, sizeof(*xlt1->ptg_tbl));
3855 xlt1->t = (u8 *)ice_calloc(hw, xlt1->count, sizeof(*xlt1->t));
3859 xlt2->sid = ice_blk_sids[i][ICE_SID_XLT2_OFF];
3860 xlt2->count = blk_sizes[i].xlt2;
3862 xlt2->vsis = (struct ice_vsig_vsi *)
3863 ice_calloc(hw, xlt2->count, sizeof(*xlt2->vsis));
3868 xlt2->vsig_tbl = (struct ice_vsig_entry *)
3869 ice_calloc(hw, xlt2->count, sizeof(*xlt2->vsig_tbl));
3870 if (!xlt2->vsig_tbl)
3873 for (j = 0; j < xlt2->count; j++)
3874 INIT_LIST_HEAD(&xlt2->vsig_tbl[j].prop_lst);
3876 xlt2->t = (u16 *)ice_calloc(hw, xlt2->count, sizeof(*xlt2->t));
3880 prof->sid = ice_blk_sids[i][ICE_SID_PR_OFF];
3881 prof->count = blk_sizes[i].prof_tcam;
3882 prof->max_prof_id = blk_sizes[i].prof_id;
3883 prof->cdid_bits = blk_sizes[i].prof_cdid_bits;
3884 prof->t = (struct ice_prof_tcam_entry *)
3885 ice_calloc(hw, prof->count, sizeof(*prof->t));
3890 prof_redir->sid = ice_blk_sids[i][ICE_SID_PR_REDIR_OFF];
3891 prof_redir->count = blk_sizes[i].prof_redir;
3892 prof_redir->t = (u8 *)ice_calloc(hw, prof_redir->count,
3893 sizeof(*prof_redir->t));
3898 es->sid = ice_blk_sids[i][ICE_SID_ES_OFF];
3899 es->count = blk_sizes[i].es;
3900 es->fvw = blk_sizes[i].fvw;
3901 es->t = (struct ice_fv_word *)
3902 ice_calloc(hw, (u32)(es->count * es->fvw),
3907 es->ref_count = (u16 *)
3908 ice_calloc(hw, es->count, sizeof(*es->ref_count));
3910 es->written = (u8 *)
3911 ice_calloc(hw, es->count, sizeof(*es->written));
3912 es->mask_ena = (u32 *)
3913 ice_calloc(hw, es->count, sizeof(*es->mask_ena));
3920 ice_free_hw_tbls(hw);
3921 return ICE_ERR_NO_MEMORY;
3925 * ice_prof_gen_key - generate profile ID key
3926 * @hw: pointer to the HW struct
3927 * @blk: the block in which to write profile ID to
3928 * @ptg: packet type group (PTG) portion of key
3929 * @vsig: VSIG portion of key
3930 * @cdid: CDID portion of key
3931 * @flags: flag portion of key
3932 * @vl_msk: valid mask
3933 * @dc_msk: don't care mask
3934 * @nm_msk: never match mask
3935 * @key: output of profile ID key
3937 static enum ice_status
3938 ice_prof_gen_key(struct ice_hw *hw, enum ice_block blk, u8 ptg, u16 vsig,
3939 u8 cdid, u16 flags, u8 vl_msk[ICE_TCAM_KEY_VAL_SZ],
3940 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ], u8 nm_msk[ICE_TCAM_KEY_VAL_SZ],
3941 u8 key[ICE_TCAM_KEY_SZ])
3943 struct ice_prof_id_key inkey;
3946 inkey.xlt2_cdid = CPU_TO_LE16(vsig);
3947 inkey.flags = CPU_TO_LE16(flags);
3949 switch (hw->blk[blk].prof.cdid_bits) {
3953 #define ICE_CD_2_M 0xC000U
3954 #define ICE_CD_2_S 14
3955 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_2_M);
3956 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_2_S);
3959 #define ICE_CD_4_M 0xF000U
3960 #define ICE_CD_4_S 12
3961 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_4_M);
3962 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_4_S);
3965 #define ICE_CD_8_M 0xFF00U
3966 #define ICE_CD_8_S 16
3967 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_8_M);
3968 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_8_S);
3971 ice_debug(hw, ICE_DBG_PKG, "Error in profile config\n");
3975 return ice_set_key(key, ICE_TCAM_KEY_SZ, (u8 *)&inkey, vl_msk, dc_msk,
3976 nm_msk, 0, ICE_TCAM_KEY_SZ / 2);
3980 * ice_tcam_write_entry - write TCAM entry
3981 * @hw: pointer to the HW struct
3982 * @blk: the block in which to write profile ID to
3983 * @idx: the entry index to write to
3984 * @prof_id: profile ID
3985 * @ptg: packet type group (PTG) portion of key
3986 * @vsig: VSIG portion of key
3987 * @cdid: CDID portion of key
3988 * @flags: flag portion of key
3989 * @vl_msk: valid mask
3990 * @dc_msk: don't care mask
3991 * @nm_msk: never match mask
3993 static enum ice_status
3994 ice_tcam_write_entry(struct ice_hw *hw, enum ice_block blk, u16 idx,
3995 u8 prof_id, u8 ptg, u16 vsig, u8 cdid, u16 flags,
3996 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ],
3997 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ],
3998 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ])
4000 struct ice_prof_tcam_entry;
4001 enum ice_status status;
4003 status = ice_prof_gen_key(hw, blk, ptg, vsig, cdid, flags, vl_msk,
4004 dc_msk, nm_msk, hw->blk[blk].prof.t[idx].key);
4006 hw->blk[blk].prof.t[idx].addr = CPU_TO_LE16(idx);
4007 hw->blk[blk].prof.t[idx].prof_id = prof_id;
4014 * ice_vsig_get_ref - returns number of VSIs belong to a VSIG
4015 * @hw: pointer to the hardware structure
4017 * @vsig: VSIG to query
4018 * @refs: pointer to variable to receive the reference count
4020 static enum ice_status
4021 ice_vsig_get_ref(struct ice_hw *hw, enum ice_block blk, u16 vsig, u16 *refs)
4023 u16 idx = vsig & ICE_VSIG_IDX_M;
4024 struct ice_vsig_vsi *ptr;
4028 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
4029 return ICE_ERR_DOES_NOT_EXIST;
4031 ptr = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
4034 ptr = ptr->next_vsi;
4041 * ice_has_prof_vsig - check to see if VSIG has a specific profile
4042 * @hw: pointer to the hardware structure
4044 * @vsig: VSIG to check against
4045 * @hdl: profile handle
4048 ice_has_prof_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl)
4050 u16 idx = vsig & ICE_VSIG_IDX_M;
4051 struct ice_vsig_prof *ent;
4053 LIST_FOR_EACH_ENTRY(ent, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4054 ice_vsig_prof, list) {
4055 if (ent->profile_cookie == hdl)
4059 ice_debug(hw, ICE_DBG_INIT,
4060 "Characteristic list for VSI group %d not found.\n",
4066 * ice_prof_bld_es - build profile ID extraction sequence changes
4067 * @hw: pointer to the HW struct
4068 * @blk: hardware block
4069 * @bld: the update package buffer build to add to
4070 * @chgs: the list of changes to make in hardware
4072 static enum ice_status
4073 ice_prof_bld_es(struct ice_hw *hw, enum ice_block blk,
4074 struct ice_buf_build *bld, struct LIST_HEAD_TYPE *chgs)
4076 u16 vec_size = hw->blk[blk].es.fvw * sizeof(struct ice_fv_word);
4077 struct ice_chs_chg *tmp;
4079 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
4080 if (tmp->type == ICE_PTG_ES_ADD && tmp->add_prof) {
4081 u16 off = tmp->prof_id * hw->blk[blk].es.fvw;
4082 struct ice_pkg_es *p;
4085 id = ice_sect_id(blk, ICE_VEC_TBL);
4086 p = (struct ice_pkg_es *)
4087 ice_pkg_buf_alloc_section(bld, id, sizeof(*p) +
4092 return ICE_ERR_MAX_LIMIT;
4094 p->count = CPU_TO_LE16(1);
4095 p->offset = CPU_TO_LE16(tmp->prof_id);
4097 ice_memcpy(p->es, &hw->blk[blk].es.t[off], vec_size,
4098 ICE_NONDMA_TO_NONDMA);
4106 * ice_prof_bld_tcam - build profile ID TCAM changes
4107 * @hw: pointer to the HW struct
4108 * @blk: hardware block
4109 * @bld: the update package buffer build to add to
4110 * @chgs: the list of changes to make in hardware
4112 static enum ice_status
4113 ice_prof_bld_tcam(struct ice_hw *hw, enum ice_block blk,
4114 struct ice_buf_build *bld, struct LIST_HEAD_TYPE *chgs)
4116 struct ice_chs_chg *tmp;
4118 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
4119 if (tmp->type == ICE_TCAM_ADD && tmp->add_tcam_idx) {
4120 struct ice_prof_id_section *p;
4123 id = ice_sect_id(blk, ICE_PROF_TCAM);
4124 p = (struct ice_prof_id_section *)
4125 ice_pkg_buf_alloc_section(bld, id, sizeof(*p));
4128 return ICE_ERR_MAX_LIMIT;
4130 p->count = CPU_TO_LE16(1);
4131 p->entry[0].addr = CPU_TO_LE16(tmp->tcam_idx);
4132 p->entry[0].prof_id = tmp->prof_id;
4134 ice_memcpy(p->entry[0].key,
4135 &hw->blk[blk].prof.t[tmp->tcam_idx].key,
4136 sizeof(hw->blk[blk].prof.t->key),
4137 ICE_NONDMA_TO_NONDMA);
4145 * ice_prof_bld_xlt1 - build XLT1 changes
4146 * @blk: hardware block
4147 * @bld: the update package buffer build to add to
4148 * @chgs: the list of changes to make in hardware
4150 static enum ice_status
4151 ice_prof_bld_xlt1(enum ice_block blk, struct ice_buf_build *bld,
4152 struct LIST_HEAD_TYPE *chgs)
4154 struct ice_chs_chg *tmp;
4156 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
4157 if (tmp->type == ICE_PTG_ES_ADD && tmp->add_ptg) {
4158 struct ice_xlt1_section *p;
4161 id = ice_sect_id(blk, ICE_XLT1);
4162 p = (struct ice_xlt1_section *)
4163 ice_pkg_buf_alloc_section(bld, id, sizeof(*p));
4166 return ICE_ERR_MAX_LIMIT;
4168 p->count = CPU_TO_LE16(1);
4169 p->offset = CPU_TO_LE16(tmp->ptype);
4170 p->value[0] = tmp->ptg;
4178 * ice_prof_bld_xlt2 - build XLT2 changes
4179 * @blk: hardware block
4180 * @bld: the update package buffer build to add to
4181 * @chgs: the list of changes to make in hardware
4183 static enum ice_status
4184 ice_prof_bld_xlt2(enum ice_block blk, struct ice_buf_build *bld,
4185 struct LIST_HEAD_TYPE *chgs)
4187 struct ice_chs_chg *tmp;
4189 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
4190 struct ice_xlt2_section *p;
4193 switch (tmp->type) {
4197 id = ice_sect_id(blk, ICE_XLT2);
4198 p = (struct ice_xlt2_section *)
4199 ice_pkg_buf_alloc_section(bld, id, sizeof(*p));
4202 return ICE_ERR_MAX_LIMIT;
4204 p->count = CPU_TO_LE16(1);
4205 p->offset = CPU_TO_LE16(tmp->vsi);
4206 p->value[0] = CPU_TO_LE16(tmp->vsig);
4217 * ice_upd_prof_hw - update hardware using the change list
4218 * @hw: pointer to the HW struct
4219 * @blk: hardware block
4220 * @chgs: the list of changes to make in hardware
4222 static enum ice_status
4223 ice_upd_prof_hw(struct ice_hw *hw, enum ice_block blk,
4224 struct LIST_HEAD_TYPE *chgs)
4226 struct ice_buf_build *b;
4227 struct ice_chs_chg *tmp;
4228 enum ice_status status;
4236 /* count number of sections we need */
4237 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
4238 switch (tmp->type) {
4239 case ICE_PTG_ES_ADD:
4257 sects = xlt1 + xlt2 + tcam + es;
4262 /* Build update package buffer */
4263 b = ice_pkg_buf_alloc(hw);
4265 return ICE_ERR_NO_MEMORY;
4267 status = ice_pkg_buf_reserve_section(b, sects);
4271 /* Preserve order of table update: ES, TCAM, PTG, VSIG */
4273 status = ice_prof_bld_es(hw, blk, b, chgs);
4279 status = ice_prof_bld_tcam(hw, blk, b, chgs);
4285 status = ice_prof_bld_xlt1(blk, b, chgs);
4291 status = ice_prof_bld_xlt2(blk, b, chgs);
4296 /* After package buffer build check if the section count in buffer is
4297 * non-zero and matches the number of sections detected for package
4300 pkg_sects = ice_pkg_buf_get_active_sections(b);
4301 if (!pkg_sects || pkg_sects != sects) {
4302 status = ICE_ERR_INVAL_SIZE;
4306 /* update package */
4307 status = ice_update_pkg(hw, ice_pkg_buf(b), 1);
4308 if (status == ICE_ERR_AQ_ERROR)
4309 ice_debug(hw, ICE_DBG_INIT, "Unable to update HW profile\n");
4312 ice_pkg_buf_free(hw, b);
4317 * ice_update_fd_mask - set Flow Director Field Vector mask for a profile
4318 * @hw: pointer to the HW struct
4319 * @prof_id: profile ID
4320 * @mask_sel: mask select
4322 * This function enable any of the masks selected by the mask select parameter
4323 * for the profile specified.
4325 static void ice_update_fd_mask(struct ice_hw *hw, u16 prof_id, u32 mask_sel)
4327 wr32(hw, GLQF_FDMASK_SEL(prof_id), mask_sel);
4329 ice_debug(hw, ICE_DBG_INIT, "fd mask(%d): %x = %x\n", prof_id,
4330 GLQF_FDMASK_SEL(prof_id), mask_sel);
4333 struct ice_fd_src_dst_pair {
4339 static const struct ice_fd_src_dst_pair ice_fd_pairs[] = {
4340 /* These are defined in pairs */
4341 { ICE_PROT_IPV4_OF_OR_S, 2, 12 },
4342 { ICE_PROT_IPV4_OF_OR_S, 2, 16 },
4344 { ICE_PROT_IPV4_IL, 2, 12 },
4345 { ICE_PROT_IPV4_IL, 2, 16 },
4347 { ICE_PROT_IPV6_OF_OR_S, 8, 8 },
4348 { ICE_PROT_IPV6_OF_OR_S, 8, 24 },
4350 { ICE_PROT_IPV6_IL, 8, 8 },
4351 { ICE_PROT_IPV6_IL, 8, 24 },
4353 { ICE_PROT_TCP_IL, 1, 0 },
4354 { ICE_PROT_TCP_IL, 1, 2 },
4356 { ICE_PROT_UDP_OF, 1, 0 },
4357 { ICE_PROT_UDP_OF, 1, 2 },
4359 { ICE_PROT_UDP_IL_OR_S, 1, 0 },
4360 { ICE_PROT_UDP_IL_OR_S, 1, 2 },
4362 { ICE_PROT_SCTP_IL, 1, 0 },
4363 { ICE_PROT_SCTP_IL, 1, 2 }
4366 #define ICE_FD_SRC_DST_PAIR_COUNT ARRAY_SIZE(ice_fd_pairs)
4369 * ice_update_fd_swap - set register appropriately for a FD FV extraction
4370 * @hw: pointer to the HW struct
4371 * @prof_id: profile ID
4372 * @es: extraction sequence (length of array is determined by the block)
4374 static enum ice_status
4375 ice_update_fd_swap(struct ice_hw *hw, u16 prof_id, struct ice_fv_word *es)
4377 ice_declare_bitmap(pair_list, ICE_FD_SRC_DST_PAIR_COUNT);
4378 u8 pair_start[ICE_FD_SRC_DST_PAIR_COUNT] = { 0 };
4379 #define ICE_FD_FV_NOT_FOUND (-2)
4380 s8 first_free = ICE_FD_FV_NOT_FOUND;
4381 u8 used[ICE_MAX_FV_WORDS] = { 0 };
4386 ice_zero_bitmap(pair_list, ICE_FD_SRC_DST_PAIR_COUNT);
4388 /* This code assumes that the Flow Director field vectors are assigned
4389 * from the end of the FV indexes working towards the zero index, that
4390 * only complete fields will be included and will be consecutive, and
4391 * that there are no gaps between valid indexes.
4394 /* Determine swap fields present */
4395 for (i = 0; i < hw->blk[ICE_BLK_FD].es.fvw; i++) {
4396 /* Find the first free entry, assuming right to left population.
4397 * This is where we can start adding additional pairs if needed.
4399 if (first_free == ICE_FD_FV_NOT_FOUND && es[i].prot_id !=
4403 for (j = 0; j < ICE_FD_SRC_DST_PAIR_COUNT; j++) {
4404 if (es[i].prot_id == ice_fd_pairs[j].prot_id &&
4405 es[i].off == ice_fd_pairs[j].off) {
4406 ice_set_bit(j, pair_list);
4412 orig_free = first_free;
4414 /* determine missing swap fields that need to be added */
4415 for (i = 0; i < ICE_FD_SRC_DST_PAIR_COUNT; i += 2) {
4416 u8 bit1 = ice_is_bit_set(pair_list, i + 1);
4417 u8 bit0 = ice_is_bit_set(pair_list, i);
4422 /* add the appropriate 'paired' entry */
4428 /* check for room */
4429 if (first_free + 1 < (s8)ice_fd_pairs[index].count)
4430 return ICE_ERR_MAX_LIMIT;
4432 /* place in extraction sequence */
4433 for (k = 0; k < ice_fd_pairs[index].count; k++) {
4434 es[first_free - k].prot_id =
4435 ice_fd_pairs[index].prot_id;
4436 es[first_free - k].off =
4437 ice_fd_pairs[index].off + (k * 2);
4440 return ICE_ERR_OUT_OF_RANGE;
4442 /* keep track of non-relevant fields */
4443 mask_sel |= BIT(first_free - k);
4446 pair_start[index] = first_free;
4447 first_free -= ice_fd_pairs[index].count;
4451 /* fill in the swap array */
4452 si = hw->blk[ICE_BLK_FD].es.fvw - 1;
4454 u8 indexes_used = 1;
4456 /* assume flat at this index */
4457 #define ICE_SWAP_VALID 0x80
4458 used[si] = si | ICE_SWAP_VALID;
4460 if (orig_free == ICE_FD_FV_NOT_FOUND || si <= orig_free) {
4465 /* check for a swap location */
4466 for (j = 0; j < ICE_FD_SRC_DST_PAIR_COUNT; j++) {
4467 if (es[si].prot_id == ice_fd_pairs[j].prot_id &&
4468 es[si].off == ice_fd_pairs[j].off) {
4471 /* determine the appropriate matching field */
4472 idx = j + ((j % 2) ? -1 : 1);
4474 indexes_used = ice_fd_pairs[idx].count;
4475 for (k = 0; k < indexes_used; k++) {
4476 used[si - k] = (pair_start[idx] - k) |
4487 /* for each set of 4 swap and 4 inset indexes, write the appropriate
4490 for (j = 0; j < hw->blk[ICE_BLK_FD].es.fvw / 4; j++) {
4494 for (k = 0; k < 4; k++) {
4498 if (used[idx] && !(mask_sel & BIT(idx))) {
4499 raw_swap |= used[idx] << (k * BITS_PER_BYTE);
4500 #define ICE_INSET_DFLT 0x9f
4501 raw_in |= ICE_INSET_DFLT << (k * BITS_PER_BYTE);
4505 /* write the appropriate swap register set */
4506 wr32(hw, GLQF_FDSWAP(prof_id, j), raw_swap);
4508 ice_debug(hw, ICE_DBG_INIT, "swap wr(%d, %d): %x = %08x\n",
4509 prof_id, j, GLQF_FDSWAP(prof_id, j), raw_swap);
4511 /* write the appropriate inset register set */
4512 wr32(hw, GLQF_FDINSET(prof_id, j), raw_in);
4514 ice_debug(hw, ICE_DBG_INIT, "inset wr(%d, %d): %x = %08x\n",
4515 prof_id, j, GLQF_FDINSET(prof_id, j), raw_in);
4518 /* initially clear the mask select for this profile */
4519 ice_update_fd_mask(hw, prof_id, 0);
4524 /* The entries here needs to match the order of enum ice_ptype_attrib */
4525 static const struct ice_ptype_attrib_info ice_ptype_attributes[] = {
4526 { ICE_GTP_PDU_EH, ICE_GTP_PDU_FLAG_MASK },
4527 { ICE_GTP_SESSION, ICE_GTP_FLAGS_MASK },
4528 { ICE_GTP_DOWNLINK, ICE_GTP_FLAGS_MASK },
4529 { ICE_GTP_UPLINK, ICE_GTP_FLAGS_MASK },
4533 * ice_get_ptype_attrib_info - get ptype attribute information
4534 * @type: attribute type
4535 * @info: pointer to variable to the attribute information
4538 ice_get_ptype_attrib_info(enum ice_ptype_attrib_type type,
4539 struct ice_ptype_attrib_info *info)
4541 *info = ice_ptype_attributes[type];
4545 * ice_add_prof_attrib - add any PTG with attributes to profile
4546 * @prof: pointer to the profile to which PTG entries will be added
4547 * @ptg: PTG to be added
4548 * @ptype: PTYPE that needs to be looked up
4549 * @attr: array of attributes that will be considered
4550 * @attr_cnt: number of elements in the attribute array
4552 static enum ice_status
4553 ice_add_prof_attrib(struct ice_prof_map *prof, u8 ptg, u16 ptype,
4554 const struct ice_ptype_attributes *attr, u16 attr_cnt)
4559 for (i = 0; i < attr_cnt; i++) {
4560 if (attr[i].ptype == ptype) {
4563 prof->ptg[prof->ptg_cnt] = ptg;
4564 ice_get_ptype_attrib_info(attr[i].attrib,
4565 &prof->attr[prof->ptg_cnt]);
4567 if (++prof->ptg_cnt >= ICE_MAX_PTG_PER_PROFILE)
4568 return ICE_ERR_MAX_LIMIT;
4573 return ICE_ERR_DOES_NOT_EXIST;
4579 * ice_add_prof - add profile
4580 * @hw: pointer to the HW struct
4581 * @blk: hardware block
4582 * @id: profile tracking ID
4583 * @ptypes: array of bitmaps indicating ptypes (ICE_FLOW_PTYPE_MAX bits)
4584 * @attr: array of attributes
4585 * @attr_cnt: number of elements in attrib array
4586 * @es: extraction sequence (length of array is determined by the block)
4587 * @masks: mask for extraction sequence
4589 * This function registers a profile, which matches a set of PTYPES with a
4590 * particular extraction sequence. While the hardware profile is allocated
4591 * it will not be written until the first call to ice_add_flow that specifies
4592 * the ID value used here.
4595 ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64 id, u8 ptypes[],
4596 const struct ice_ptype_attributes *attr, u16 attr_cnt,
4597 struct ice_fv_word *es, u16 *masks)
4599 u32 bytes = DIVIDE_AND_ROUND_UP(ICE_FLOW_PTYPE_MAX, BITS_PER_BYTE);
4600 ice_declare_bitmap(ptgs_used, ICE_XLT1_CNT);
4601 struct ice_prof_map *prof;
4602 enum ice_status status;
4606 ice_zero_bitmap(ptgs_used, ICE_XLT1_CNT);
4608 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
4610 /* search for existing profile */
4611 status = ice_find_prof_id_with_mask(hw, blk, es, masks, &prof_id);
4613 /* allocate profile ID */
4614 status = ice_alloc_prof_id(hw, blk, &prof_id);
4616 goto err_ice_add_prof;
4617 if (blk == ICE_BLK_FD) {
4618 /* For Flow Director block, the extraction sequence may
4619 * need to be altered in the case where there are paired
4620 * fields that have no match. This is necessary because
4621 * for Flow Director, src and dest fields need to paired
4622 * for filter programming and these values are swapped
4625 status = ice_update_fd_swap(hw, prof_id, es);
4627 goto err_ice_add_prof;
4629 status = ice_update_prof_masking(hw, blk, prof_id, masks);
4631 goto err_ice_add_prof;
4633 /* and write new es */
4634 ice_write_es(hw, blk, prof_id, es);
4637 ice_prof_inc_ref(hw, blk, prof_id);
4639 /* add profile info */
4641 prof = (struct ice_prof_map *)ice_malloc(hw, sizeof(*prof));
4643 goto err_ice_add_prof;
4645 prof->profile_cookie = id;
4646 prof->prof_id = prof_id;
4650 /* build list of ptgs */
4651 while (bytes && prof->ptg_cnt < ICE_MAX_PTG_PER_PROFILE) {
4654 if (!ptypes[byte]) {
4659 /* Examine 8 bits per byte */
4660 for (bit = 0; bit < 8; bit++) {
4661 if (ptypes[byte] & BIT(bit)) {
4666 ptype = byte * BITS_PER_BYTE + bit;
4668 /* The package should place all ptypes in a
4669 * non-zero PTG, so the following call should
4672 if (ice_ptg_find_ptype(hw, blk, ptype, &ptg))
4675 /* If PTG is already added, skip and continue */
4676 if (ice_is_bit_set(ptgs_used, ptg))
4679 ice_set_bit(ptg, ptgs_used);
4680 /* Check to see there are any attributes for
4681 * this ptype, and add them if found.
4683 status = ice_add_prof_attrib(prof, ptg, ptype,
4685 if (status == ICE_ERR_MAX_LIMIT)
4688 /* This is simple a ptype/PTG with no
4691 prof->ptg[prof->ptg_cnt] = ptg;
4692 prof->attr[prof->ptg_cnt].flags = 0;
4693 prof->attr[prof->ptg_cnt].mask = 0;
4695 if (++prof->ptg_cnt >=
4696 ICE_MAX_PTG_PER_PROFILE)
4700 /* nothing left in byte, then exit */
4701 m = ~(u8)((1 << (bit + 1)) - 1);
4702 if (!(ptypes[byte] & m))
4711 LIST_ADD(&prof->list, &hw->blk[blk].es.prof_map);
4712 status = ICE_SUCCESS;
4715 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
4720 * ice_search_prof_id_low - Search for a profile tracking ID low level
4721 * @hw: pointer to the HW struct
4722 * @blk: hardware block
4723 * @id: profile tracking ID
4725 * This will search for a profile tracking ID which was previously added. This
4726 * version assumes that the caller has already acquired the prof map lock.
4728 static struct ice_prof_map *
4729 ice_search_prof_id_low(struct ice_hw *hw, enum ice_block blk, u64 id)
4731 struct ice_prof_map *entry = NULL;
4732 struct ice_prof_map *map;
4734 LIST_FOR_EACH_ENTRY(map, &hw->blk[blk].es.prof_map, ice_prof_map,
4736 if (map->profile_cookie == id) {
4746 * ice_search_prof_id - Search for a profile tracking ID
4747 * @hw: pointer to the HW struct
4748 * @blk: hardware block
4749 * @id: profile tracking ID
4751 * This will search for a profile tracking ID which was previously added.
4753 struct ice_prof_map *
4754 ice_search_prof_id(struct ice_hw *hw, enum ice_block blk, u64 id)
4756 struct ice_prof_map *entry;
4758 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
4759 entry = ice_search_prof_id_low(hw, blk, id);
4760 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
4766 * ice_vsig_prof_id_count - count profiles in a VSIG
4767 * @hw: pointer to the HW struct
4768 * @blk: hardware block
4769 * @vsig: VSIG to remove the profile from
4772 ice_vsig_prof_id_count(struct ice_hw *hw, enum ice_block blk, u16 vsig)
4774 u16 idx = vsig & ICE_VSIG_IDX_M, count = 0;
4775 struct ice_vsig_prof *p;
4777 LIST_FOR_EACH_ENTRY(p, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4778 ice_vsig_prof, list) {
4786 * ice_rel_tcam_idx - release a TCAM index
4787 * @hw: pointer to the HW struct
4788 * @blk: hardware block
4789 * @idx: the index to release
4791 static enum ice_status
4792 ice_rel_tcam_idx(struct ice_hw *hw, enum ice_block blk, u16 idx)
4794 /* Masks to invoke a never match entry */
4795 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4796 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFE, 0xFF, 0xFF, 0xFF, 0xFF };
4797 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x01, 0x00, 0x00, 0x00, 0x00 };
4798 enum ice_status status;
4800 /* write the TCAM entry */
4801 status = ice_tcam_write_entry(hw, blk, idx, 0, 0, 0, 0, 0, vl_msk,
4806 /* release the TCAM entry */
4807 status = ice_free_tcam_ent(hw, blk, idx);
4813 * ice_rem_prof_id - remove one profile from a VSIG
4814 * @hw: pointer to the HW struct
4815 * @blk: hardware block
4816 * @prof: pointer to profile structure to remove
4818 static enum ice_status
4819 ice_rem_prof_id(struct ice_hw *hw, enum ice_block blk,
4820 struct ice_vsig_prof *prof)
4822 enum ice_status status;
4825 for (i = 0; i < prof->tcam_count; i++) {
4826 if (prof->tcam[i].in_use) {
4827 prof->tcam[i].in_use = false;
4828 status = ice_rel_tcam_idx(hw, blk,
4829 prof->tcam[i].tcam_idx);
4831 return ICE_ERR_HW_TABLE;
4839 * ice_rem_vsig - remove VSIG
4840 * @hw: pointer to the HW struct
4841 * @blk: hardware block
4842 * @vsig: the VSIG to remove
4843 * @chg: the change list
4845 static enum ice_status
4846 ice_rem_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig,
4847 struct LIST_HEAD_TYPE *chg)
4849 u16 idx = vsig & ICE_VSIG_IDX_M;
4850 struct ice_vsig_vsi *vsi_cur;
4851 struct ice_vsig_prof *d, *t;
4852 enum ice_status status;
4854 /* remove TCAM entries */
4855 LIST_FOR_EACH_ENTRY_SAFE(d, t,
4856 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4857 ice_vsig_prof, list) {
4858 status = ice_rem_prof_id(hw, blk, d);
4866 /* Move all VSIS associated with this VSIG to the default VSIG */
4867 vsi_cur = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
4868 /* If the VSIG has at least 1 VSI then iterate through the list
4869 * and remove the VSIs before deleting the group.
4873 struct ice_vsig_vsi *tmp = vsi_cur->next_vsi;
4874 struct ice_chs_chg *p;
4876 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4878 return ICE_ERR_NO_MEMORY;
4880 p->type = ICE_VSIG_REM;
4881 p->orig_vsig = vsig;
4882 p->vsig = ICE_DEFAULT_VSIG;
4883 p->vsi = vsi_cur - hw->blk[blk].xlt2.vsis;
4885 LIST_ADD(&p->list_entry, chg);
4891 return ice_vsig_free(hw, blk, vsig);
4895 * ice_rem_prof_id_vsig - remove a specific profile from a VSIG
4896 * @hw: pointer to the HW struct
4897 * @blk: hardware block
4898 * @vsig: VSIG to remove the profile from
4899 * @hdl: profile handle indicating which profile to remove
4900 * @chg: list to receive a record of changes
4902 static enum ice_status
4903 ice_rem_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl,
4904 struct LIST_HEAD_TYPE *chg)
4906 u16 idx = vsig & ICE_VSIG_IDX_M;
4907 struct ice_vsig_prof *p, *t;
4908 enum ice_status status;
4910 LIST_FOR_EACH_ENTRY_SAFE(p, t,
4911 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4912 ice_vsig_prof, list) {
4913 if (p->profile_cookie == hdl) {
4914 if (ice_vsig_prof_id_count(hw, blk, vsig) == 1)
4915 /* this is the last profile, remove the VSIG */
4916 return ice_rem_vsig(hw, blk, vsig, chg);
4918 status = ice_rem_prof_id(hw, blk, p);
4927 return ICE_ERR_DOES_NOT_EXIST;
4931 * ice_rem_flow_all - remove all flows with a particular profile
4932 * @hw: pointer to the HW struct
4933 * @blk: hardware block
4934 * @id: profile tracking ID
4936 static enum ice_status
4937 ice_rem_flow_all(struct ice_hw *hw, enum ice_block blk, u64 id)
4939 struct ice_chs_chg *del, *tmp;
4940 struct LIST_HEAD_TYPE chg;
4941 enum ice_status status;
4944 INIT_LIST_HEAD(&chg);
4946 for (i = 1; i < ICE_MAX_VSIGS; i++) {
4947 if (hw->blk[blk].xlt2.vsig_tbl[i].in_use) {
4948 if (ice_has_prof_vsig(hw, blk, i, id)) {
4949 status = ice_rem_prof_id_vsig(hw, blk, i, id,
4952 goto err_ice_rem_flow_all;
4957 status = ice_upd_prof_hw(hw, blk, &chg);
4959 err_ice_rem_flow_all:
4960 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
4961 LIST_DEL(&del->list_entry);
4969 * ice_rem_prof - remove profile
4970 * @hw: pointer to the HW struct
4971 * @blk: hardware block
4972 * @id: profile tracking ID
4974 * This will remove the profile specified by the ID parameter, which was
4975 * previously created through ice_add_prof. If any existing entries
4976 * are associated with this profile, they will be removed as well.
4978 enum ice_status ice_rem_prof(struct ice_hw *hw, enum ice_block blk, u64 id)
4980 struct ice_prof_map *pmap;
4981 enum ice_status status;
4983 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
4985 pmap = ice_search_prof_id_low(hw, blk, id);
4987 status = ICE_ERR_DOES_NOT_EXIST;
4988 goto err_ice_rem_prof;
4991 /* remove all flows with this profile */
4992 status = ice_rem_flow_all(hw, blk, pmap->profile_cookie);
4994 goto err_ice_rem_prof;
4996 /* dereference profile, and possibly remove */
4997 ice_prof_dec_ref(hw, blk, pmap->prof_id);
4999 LIST_DEL(&pmap->list);
5003 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
5008 * ice_get_prof - get profile
5009 * @hw: pointer to the HW struct
5010 * @blk: hardware block
5011 * @hdl: profile handle
5014 static enum ice_status
5015 ice_get_prof(struct ice_hw *hw, enum ice_block blk, u64 hdl,
5016 struct LIST_HEAD_TYPE *chg)
5018 struct ice_prof_map *map;
5019 struct ice_chs_chg *p;
5022 /* Get the details on the profile specified by the handle ID */
5023 map = ice_search_prof_id(hw, blk, hdl);
5025 return ICE_ERR_DOES_NOT_EXIST;
5027 for (i = 0; i < map->ptg_cnt; i++) {
5028 if (!hw->blk[blk].es.written[map->prof_id]) {
5029 /* add ES to change list */
5030 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5032 goto err_ice_get_prof;
5034 p->type = ICE_PTG_ES_ADD;
5036 p->ptg = map->ptg[i];
5037 p->attr = map->attr[i];
5041 p->prof_id = map->prof_id;
5043 hw->blk[blk].es.written[map->prof_id] = true;
5045 LIST_ADD(&p->list_entry, chg);
5052 /* let caller clean up the change list */
5053 return ICE_ERR_NO_MEMORY;
5057 * ice_get_profs_vsig - get a copy of the list of profiles from a VSIG
5058 * @hw: pointer to the HW struct
5059 * @blk: hardware block
5060 * @vsig: VSIG from which to copy the list
5063 * This routine makes a copy of the list of profiles in the specified VSIG.
5065 static enum ice_status
5066 ice_get_profs_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig,
5067 struct LIST_HEAD_TYPE *lst)
5069 struct ice_vsig_prof *ent1, *ent2;
5070 u16 idx = vsig & ICE_VSIG_IDX_M;
5072 LIST_FOR_EACH_ENTRY(ent1, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
5073 ice_vsig_prof, list) {
5074 struct ice_vsig_prof *p;
5076 /* copy to the input list */
5077 p = (struct ice_vsig_prof *)ice_memdup(hw, ent1, sizeof(*p),
5078 ICE_NONDMA_TO_NONDMA);
5080 goto err_ice_get_profs_vsig;
5082 LIST_ADD_TAIL(&p->list, lst);
5087 err_ice_get_profs_vsig:
5088 LIST_FOR_EACH_ENTRY_SAFE(ent1, ent2, lst, ice_vsig_prof, list) {
5089 LIST_DEL(&ent1->list);
5093 return ICE_ERR_NO_MEMORY;
5097 * ice_add_prof_to_lst - add profile entry to a list
5098 * @hw: pointer to the HW struct
5099 * @blk: hardware block
5100 * @lst: the list to be added to
5101 * @hdl: profile handle of entry to add
5103 static enum ice_status
5104 ice_add_prof_to_lst(struct ice_hw *hw, enum ice_block blk,
5105 struct LIST_HEAD_TYPE *lst, u64 hdl)
5107 struct ice_prof_map *map;
5108 struct ice_vsig_prof *p;
5111 map = ice_search_prof_id(hw, blk, hdl);
5113 return ICE_ERR_DOES_NOT_EXIST;
5115 p = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*p));
5117 return ICE_ERR_NO_MEMORY;
5119 p->profile_cookie = map->profile_cookie;
5120 p->prof_id = map->prof_id;
5121 p->tcam_count = map->ptg_cnt;
5123 for (i = 0; i < map->ptg_cnt; i++) {
5124 p->tcam[i].prof_id = map->prof_id;
5125 p->tcam[i].tcam_idx = ICE_INVALID_TCAM;
5126 p->tcam[i].ptg = map->ptg[i];
5127 p->tcam[i].attr = map->attr[i];
5130 LIST_ADD(&p->list, lst);
5136 * ice_move_vsi - move VSI to another VSIG
5137 * @hw: pointer to the HW struct
5138 * @blk: hardware block
5139 * @vsi: the VSI to move
5140 * @vsig: the VSIG to move the VSI to
5141 * @chg: the change list
5143 static enum ice_status
5144 ice_move_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig,
5145 struct LIST_HEAD_TYPE *chg)
5147 enum ice_status status;
5148 struct ice_chs_chg *p;
5151 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5153 return ICE_ERR_NO_MEMORY;
5155 status = ice_vsig_find_vsi(hw, blk, vsi, &orig_vsig);
5157 status = ice_vsig_add_mv_vsi(hw, blk, vsi, vsig);
5164 p->type = ICE_VSI_MOVE;
5166 p->orig_vsig = orig_vsig;
5169 LIST_ADD(&p->list_entry, chg);
5175 * ice_set_tcam_flags - set TCAM flag don't care mask
5176 * @mask: mask for flags
5177 * @dc_mask: pointer to the don't care mask
5179 static void ice_set_tcam_flags(u16 mask, u8 dc_mask[ICE_TCAM_KEY_VAL_SZ])
5183 /* flags are lowest u16 */
5184 flag_word = (u16 *)dc_mask;
5189 * ice_rem_chg_tcam_ent - remove a specific TCAM entry from change list
5190 * @hw: pointer to the HW struct
5191 * @idx: the index of the TCAM entry to remove
5192 * @chg: the list of change structures to search
5195 ice_rem_chg_tcam_ent(struct ice_hw *hw, u16 idx, struct LIST_HEAD_TYPE *chg)
5197 struct ice_chs_chg *pos, *tmp;
5199 LIST_FOR_EACH_ENTRY_SAFE(tmp, pos, chg, ice_chs_chg, list_entry) {
5200 if (tmp->type == ICE_TCAM_ADD && tmp->tcam_idx == idx) {
5201 LIST_DEL(&tmp->list_entry);
5208 * ice_prof_tcam_ena_dis - add enable or disable TCAM change
5209 * @hw: pointer to the HW struct
5210 * @blk: hardware block
5211 * @enable: true to enable, false to disable
5212 * @vsig: the VSIG of the TCAM entry
5213 * @tcam: pointer the TCAM info structure of the TCAM to disable
5214 * @chg: the change list
5216 * This function appends an enable or disable TCAM entry in the change log
5218 static enum ice_status
5219 ice_prof_tcam_ena_dis(struct ice_hw *hw, enum ice_block blk, bool enable,
5220 u16 vsig, struct ice_tcam_inf *tcam,
5221 struct LIST_HEAD_TYPE *chg)
5223 enum ice_status status;
5224 struct ice_chs_chg *p;
5226 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
5227 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0x00, 0x00, 0x00 };
5228 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
5230 /* if disabling, free the TCAM */
5232 status = ice_rel_tcam_idx(hw, blk, tcam->tcam_idx);
5234 /* if we have already created a change for this TCAM entry, then
5235 * we need to remove that entry, in order to prevent writing to
5236 * a TCAM entry we no longer will have ownership of.
5238 ice_rem_chg_tcam_ent(hw, tcam->tcam_idx, chg);
5244 /* for re-enabling, reallocate a TCAM */
5245 status = ice_alloc_tcam_ent(hw, blk, &tcam->tcam_idx);
5249 /* add TCAM to change list */
5250 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5252 return ICE_ERR_NO_MEMORY;
5254 /* set don't care masks for TCAM flags */
5255 ice_set_tcam_flags(tcam->attr.mask, dc_msk);
5257 status = ice_tcam_write_entry(hw, blk, tcam->tcam_idx, tcam->prof_id,
5258 tcam->ptg, vsig, 0, tcam->attr.flags,
5259 vl_msk, dc_msk, nm_msk);
5261 goto err_ice_prof_tcam_ena_dis;
5265 p->type = ICE_TCAM_ADD;
5266 p->add_tcam_idx = true;
5267 p->prof_id = tcam->prof_id;
5270 p->tcam_idx = tcam->tcam_idx;
5273 LIST_ADD(&p->list_entry, chg);
5277 err_ice_prof_tcam_ena_dis:
5283 * ice_ptg_attr_in_use - determine if PTG and attribute pair is in use
5284 * @ptg_attr: pointer to the PTG and attribute pair to check
5285 * @ptgs_used: bitmap that denotes which PTGs are in use
5286 * @attr_used: array of PTG and attributes pairs already used
5287 * @attr_cnt: count of entries in the attr_used array
5290 ice_ptg_attr_in_use(struct ice_tcam_inf *ptg_attr, ice_bitmap_t *ptgs_used,
5291 struct ice_tcam_inf *attr_used[], u16 attr_cnt)
5295 if (!ice_is_bit_set(ptgs_used, ptg_attr->ptg))
5298 /* the PTG is used, so now look for correct attributes */
5299 for (i = 0; i < attr_cnt; i++)
5300 if (attr_used[i]->ptg == ptg_attr->ptg &&
5301 attr_used[i]->attr.flags == ptg_attr->attr.flags &&
5302 attr_used[i]->attr.mask == ptg_attr->attr.mask)
5309 * ice_adj_prof_priorities - adjust profile based on priorities
5310 * @hw: pointer to the HW struct
5311 * @blk: hardware block
5312 * @vsig: the VSIG for which to adjust profile priorities
5313 * @chg: the change list
5315 static enum ice_status
5316 ice_adj_prof_priorities(struct ice_hw *hw, enum ice_block blk, u16 vsig,
5317 struct LIST_HEAD_TYPE *chg)
5319 ice_declare_bitmap(ptgs_used, ICE_XLT1_CNT);
5320 struct ice_tcam_inf **attr_used;
5321 enum ice_status status = ICE_SUCCESS;
5322 struct ice_vsig_prof *t;
5323 u16 attr_used_cnt = 0;
5326 #define ICE_MAX_PTG_ATTRS 1024
5327 attr_used = (struct ice_tcam_inf **)ice_calloc(hw, ICE_MAX_PTG_ATTRS,
5328 sizeof(*attr_used));
5330 return ICE_ERR_NO_MEMORY;
5332 ice_zero_bitmap(ptgs_used, ICE_XLT1_CNT);
5333 idx = vsig & ICE_VSIG_IDX_M;
5335 /* Priority is based on the order in which the profiles are added. The
5336 * newest added profile has highest priority and the oldest added
5337 * profile has the lowest priority. Since the profile property list for
5338 * a VSIG is sorted from newest to oldest, this code traverses the list
5339 * in order and enables the first of each PTG that it finds (that is not
5340 * already enabled); it also disables any duplicate PTGs that it finds
5341 * in the older profiles (that are currently enabled).
5344 LIST_FOR_EACH_ENTRY(t, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
5345 ice_vsig_prof, list) {
5348 for (i = 0; i < t->tcam_count; i++) {
5351 /* Scan the priorities from newest to oldest.
5352 * Make sure that the newest profiles take priority.
5354 used = ice_ptg_attr_in_use(&t->tcam[i], ptgs_used,
5355 attr_used, attr_used_cnt);
5357 if (used && t->tcam[i].in_use) {
5358 /* need to mark this PTG as never match, as it
5359 * was already in use and therefore duplicate
5360 * (and lower priority)
5362 status = ice_prof_tcam_ena_dis(hw, blk, false,
5367 goto err_ice_adj_prof_priorities;
5368 } else if (!used && !t->tcam[i].in_use) {
5369 /* need to enable this PTG, as it in not in use
5370 * and not enabled (highest priority)
5372 status = ice_prof_tcam_ena_dis(hw, blk, true,
5377 goto err_ice_adj_prof_priorities;
5380 /* keep track of used ptgs */
5381 ice_set_bit(t->tcam[i].ptg, ptgs_used);
5382 if (attr_used_cnt < ICE_MAX_PTG_ATTRS)
5383 attr_used[attr_used_cnt++] = &t->tcam[i];
5385 ice_debug(hw, ICE_DBG_INIT,
5386 "Warn: ICE_MAX_PTG_ATTRS exceeded\n");
5390 err_ice_adj_prof_priorities:
5391 ice_free(hw, attr_used);
5396 * ice_add_prof_id_vsig - add profile to VSIG
5397 * @hw: pointer to the HW struct
5398 * @blk: hardware block
5399 * @vsig: the VSIG to which this profile is to be added
5400 * @hdl: the profile handle indicating the profile to add
5401 * @rev: true to add entries to the end of the list
5402 * @chg: the change list
5404 static enum ice_status
5405 ice_add_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl,
5406 bool rev, struct LIST_HEAD_TYPE *chg)
5408 /* Masks that ignore flags */
5409 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
5410 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0x00, 0x00, 0x00 };
5411 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
5412 struct ice_prof_map *map;
5413 struct ice_vsig_prof *t;
5414 struct ice_chs_chg *p;
5417 /* Get the details on the profile specified by the handle ID */
5418 map = ice_search_prof_id(hw, blk, hdl);
5420 return ICE_ERR_DOES_NOT_EXIST;
5422 /* Error, if this VSIG already has this profile */
5423 if (ice_has_prof_vsig(hw, blk, vsig, hdl))
5424 return ICE_ERR_ALREADY_EXISTS;
5426 /* new VSIG profile structure */
5427 t = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*t));
5429 return ICE_ERR_NO_MEMORY;
5431 t->profile_cookie = map->profile_cookie;
5432 t->prof_id = map->prof_id;
5433 t->tcam_count = map->ptg_cnt;
5435 /* create TCAM entries */
5436 for (i = 0; i < map->ptg_cnt; i++) {
5437 enum ice_status status;
5440 /* add TCAM to change list */
5441 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5443 goto err_ice_add_prof_id_vsig;
5445 /* allocate the TCAM entry index */
5446 status = ice_alloc_tcam_ent(hw, blk, &tcam_idx);
5449 goto err_ice_add_prof_id_vsig;
5452 t->tcam[i].ptg = map->ptg[i];
5453 t->tcam[i].prof_id = map->prof_id;
5454 t->tcam[i].tcam_idx = tcam_idx;
5455 t->tcam[i].attr = map->attr[i];
5456 t->tcam[i].in_use = true;
5458 p->type = ICE_TCAM_ADD;
5459 p->add_tcam_idx = true;
5460 p->prof_id = t->tcam[i].prof_id;
5461 p->ptg = t->tcam[i].ptg;
5463 p->tcam_idx = t->tcam[i].tcam_idx;
5465 /* set don't care masks for TCAM flags */
5466 ice_set_tcam_flags(t->tcam[i].attr.mask, dc_msk);
5468 /* write the TCAM entry */
5469 status = ice_tcam_write_entry(hw, blk, t->tcam[i].tcam_idx,
5471 t->tcam[i].ptg, vsig, 0,
5472 t->tcam[i].attr.flags, vl_msk,
5476 goto err_ice_add_prof_id_vsig;
5480 LIST_ADD(&p->list_entry, chg);
5483 /* add profile to VSIG */
5484 vsig_idx = vsig & ICE_VSIG_IDX_M;
5486 LIST_ADD_TAIL(&t->list,
5487 &hw->blk[blk].xlt2.vsig_tbl[vsig_idx].prop_lst);
5490 &hw->blk[blk].xlt2.vsig_tbl[vsig_idx].prop_lst);
5494 err_ice_add_prof_id_vsig:
5495 /* let caller clean up the change list */
5497 return ICE_ERR_NO_MEMORY;
5501 * ice_create_prof_id_vsig - add a new VSIG with a single profile
5502 * @hw: pointer to the HW struct
5503 * @blk: hardware block
5504 * @vsi: the initial VSI that will be in VSIG
5505 * @hdl: the profile handle of the profile that will be added to the VSIG
5506 * @chg: the change list
5508 static enum ice_status
5509 ice_create_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl,
5510 struct LIST_HEAD_TYPE *chg)
5512 enum ice_status status;
5513 struct ice_chs_chg *p;
5516 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5518 return ICE_ERR_NO_MEMORY;
5520 new_vsig = ice_vsig_alloc(hw, blk);
5522 status = ICE_ERR_HW_TABLE;
5523 goto err_ice_create_prof_id_vsig;
5526 status = ice_move_vsi(hw, blk, vsi, new_vsig, chg);
5528 goto err_ice_create_prof_id_vsig;
5530 status = ice_add_prof_id_vsig(hw, blk, new_vsig, hdl, false, chg);
5532 goto err_ice_create_prof_id_vsig;
5534 p->type = ICE_VSIG_ADD;
5536 p->orig_vsig = ICE_DEFAULT_VSIG;
5539 LIST_ADD(&p->list_entry, chg);
5543 err_ice_create_prof_id_vsig:
5544 /* let caller clean up the change list */
5550 * ice_create_vsig_from_lst - create a new VSIG with a list of profiles
5551 * @hw: pointer to the HW struct
5552 * @blk: hardware block
5553 * @vsi: the initial VSI that will be in VSIG
5554 * @lst: the list of profile that will be added to the VSIG
5555 * @new_vsig: return of new VSIG
5556 * @chg: the change list
5558 static enum ice_status
5559 ice_create_vsig_from_lst(struct ice_hw *hw, enum ice_block blk, u16 vsi,
5560 struct LIST_HEAD_TYPE *lst, u16 *new_vsig,
5561 struct LIST_HEAD_TYPE *chg)
5563 struct ice_vsig_prof *t;
5564 enum ice_status status;
5567 vsig = ice_vsig_alloc(hw, blk);
5569 return ICE_ERR_HW_TABLE;
5571 status = ice_move_vsi(hw, blk, vsi, vsig, chg);
5575 LIST_FOR_EACH_ENTRY(t, lst, ice_vsig_prof, list) {
5576 /* Reverse the order here since we are copying the list */
5577 status = ice_add_prof_id_vsig(hw, blk, vsig, t->profile_cookie,
5589 * ice_find_prof_vsig - find a VSIG with a specific profile handle
5590 * @hw: pointer to the HW struct
5591 * @blk: hardware block
5592 * @hdl: the profile handle of the profile to search for
5593 * @vsig: returns the VSIG with the matching profile
5596 ice_find_prof_vsig(struct ice_hw *hw, enum ice_block blk, u64 hdl, u16 *vsig)
5598 struct ice_vsig_prof *t;
5599 struct LIST_HEAD_TYPE lst;
5600 enum ice_status status;
5602 INIT_LIST_HEAD(&lst);
5604 t = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*t));
5608 t->profile_cookie = hdl;
5609 LIST_ADD(&t->list, &lst);
5611 status = ice_find_dup_props_vsig(hw, blk, &lst, vsig);
5616 return status == ICE_SUCCESS;
5620 * ice_add_vsi_flow - add VSI flow
5621 * @hw: pointer to the HW struct
5622 * @blk: hardware block
5624 * @vsig: target VSIG to include the input VSI
5626 * Calling this function will add the VSI to a given VSIG and
5627 * update the HW tables accordingly. This call can be used to
5628 * add multiple VSIs to a VSIG if we know beforehand that those
5629 * VSIs have the same characteristics of the VSIG. This will
5630 * save time in generating a new VSIG and TCAMs till a match is
5631 * found and subsequent rollback when a matching VSIG is found.
5634 ice_add_vsi_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
5636 struct ice_chs_chg *tmp, *del;
5637 struct LIST_HEAD_TYPE chg;
5638 enum ice_status status;
5640 /* if target VSIG is default the move is invalid */
5641 if ((vsig & ICE_VSIG_IDX_M) == ICE_DEFAULT_VSIG)
5642 return ICE_ERR_PARAM;
5644 INIT_LIST_HEAD(&chg);
5646 /* move VSI to the VSIG that matches */
5647 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5648 /* update hardware if success */
5650 status = ice_upd_prof_hw(hw, blk, &chg);
5652 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
5653 LIST_DEL(&del->list_entry);
5661 * ice_add_prof_id_flow - add profile flow
5662 * @hw: pointer to the HW struct
5663 * @blk: hardware block
5664 * @vsi: the VSI to enable with the profile specified by ID
5665 * @hdl: profile handle
5667 * Calling this function will update the hardware tables to enable the
5668 * profile indicated by the ID parameter for the VSIs specified in the VSI
5669 * array. Once successfully called, the flow will be enabled.
5672 ice_add_prof_id_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl)
5674 struct ice_vsig_prof *tmp1, *del1;
5675 struct LIST_HEAD_TYPE union_lst;
5676 struct ice_chs_chg *tmp, *del;
5677 struct LIST_HEAD_TYPE chg;
5678 enum ice_status status;
5681 INIT_LIST_HEAD(&union_lst);
5682 INIT_LIST_HEAD(&chg);
5685 status = ice_get_prof(hw, blk, hdl, &chg);
5689 /* determine if VSI is already part of a VSIG */
5690 status = ice_vsig_find_vsi(hw, blk, vsi, &vsig);
5691 if (!status && vsig) {
5699 /* make sure that there is no overlap/conflict between the new
5700 * characteristics and the existing ones; we don't support that
5703 if (ice_has_prof_vsig(hw, blk, vsig, hdl)) {
5704 status = ICE_ERR_ALREADY_EXISTS;
5705 goto err_ice_add_prof_id_flow;
5708 /* last VSI in the VSIG? */
5709 status = ice_vsig_get_ref(hw, blk, vsig, &ref);
5711 goto err_ice_add_prof_id_flow;
5712 only_vsi = (ref == 1);
5714 /* create a union of the current profiles and the one being
5717 status = ice_get_profs_vsig(hw, blk, vsig, &union_lst);
5719 goto err_ice_add_prof_id_flow;
5721 status = ice_add_prof_to_lst(hw, blk, &union_lst, hdl);
5723 goto err_ice_add_prof_id_flow;
5725 /* search for an existing VSIG with an exact charc match */
5726 status = ice_find_dup_props_vsig(hw, blk, &union_lst, &vsig);
5728 /* move VSI to the VSIG that matches */
5729 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5731 goto err_ice_add_prof_id_flow;
5733 /* VSI has been moved out of or_vsig. If the or_vsig had
5734 * only that VSI it is now empty and can be removed.
5737 status = ice_rem_vsig(hw, blk, or_vsig, &chg);
5739 goto err_ice_add_prof_id_flow;
5741 } else if (only_vsi) {
5742 /* If the original VSIG only contains one VSI, then it
5743 * will be the requesting VSI. In this case the VSI is
5744 * not sharing entries and we can simply add the new
5745 * profile to the VSIG.
5747 status = ice_add_prof_id_vsig(hw, blk, vsig, hdl, false,
5750 goto err_ice_add_prof_id_flow;
5752 /* Adjust priorities */
5753 status = ice_adj_prof_priorities(hw, blk, vsig, &chg);
5755 goto err_ice_add_prof_id_flow;
5757 /* No match, so we need a new VSIG */
5758 status = ice_create_vsig_from_lst(hw, blk, vsi,
5762 goto err_ice_add_prof_id_flow;
5764 /* Adjust priorities */
5765 status = ice_adj_prof_priorities(hw, blk, vsig, &chg);
5767 goto err_ice_add_prof_id_flow;
5770 /* need to find or add a VSIG */
5771 /* search for an existing VSIG with an exact charc match */
5772 if (ice_find_prof_vsig(hw, blk, hdl, &vsig)) {
5773 /* found an exact match */
5774 /* add or move VSI to the VSIG that matches */
5775 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5777 goto err_ice_add_prof_id_flow;
5779 /* we did not find an exact match */
5780 /* we need to add a VSIG */
5781 status = ice_create_prof_id_vsig(hw, blk, vsi, hdl,
5784 goto err_ice_add_prof_id_flow;
5788 /* update hardware */
5790 status = ice_upd_prof_hw(hw, blk, &chg);
5792 err_ice_add_prof_id_flow:
5793 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
5794 LIST_DEL(&del->list_entry);
5798 LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, &union_lst, ice_vsig_prof, list) {
5799 LIST_DEL(&del1->list);
5807 * ice_rem_prof_from_list - remove a profile from list
5808 * @hw: pointer to the HW struct
5809 * @lst: list to remove the profile from
5810 * @hdl: the profile handle indicating the profile to remove
5812 static enum ice_status
5813 ice_rem_prof_from_list(struct ice_hw *hw, struct LIST_HEAD_TYPE *lst, u64 hdl)
5815 struct ice_vsig_prof *ent, *tmp;
5817 LIST_FOR_EACH_ENTRY_SAFE(ent, tmp, lst, ice_vsig_prof, list) {
5818 if (ent->profile_cookie == hdl) {
5819 LIST_DEL(&ent->list);
5825 return ICE_ERR_DOES_NOT_EXIST;
5829 * ice_rem_prof_id_flow - remove flow
5830 * @hw: pointer to the HW struct
5831 * @blk: hardware block
5832 * @vsi: the VSI from which to remove the profile specified by ID
5833 * @hdl: profile tracking handle
5835 * Calling this function will update the hardware tables to remove the
5836 * profile indicated by the ID parameter for the VSIs specified in the VSI
5837 * array. Once successfully called, the flow will be disabled.
5840 ice_rem_prof_id_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl)
5842 struct ice_vsig_prof *tmp1, *del1;
5843 struct LIST_HEAD_TYPE chg, copy;
5844 struct ice_chs_chg *tmp, *del;
5845 enum ice_status status;
5848 INIT_LIST_HEAD(©);
5849 INIT_LIST_HEAD(&chg);
5851 /* determine if VSI is already part of a VSIG */
5852 status = ice_vsig_find_vsi(hw, blk, vsi, &vsig);
5853 if (!status && vsig) {
5859 last_profile = ice_vsig_prof_id_count(hw, blk, vsig) == 1;
5860 status = ice_vsig_get_ref(hw, blk, vsig, &ref);
5862 goto err_ice_rem_prof_id_flow;
5863 only_vsi = (ref == 1);
5866 /* If the original VSIG only contains one reference,
5867 * which will be the requesting VSI, then the VSI is not
5868 * sharing entries and we can simply remove the specific
5869 * characteristics from the VSIG.
5873 /* If there are no profiles left for this VSIG,
5874 * then simply remove the the VSIG.
5876 status = ice_rem_vsig(hw, blk, vsig, &chg);
5878 goto err_ice_rem_prof_id_flow;
5880 status = ice_rem_prof_id_vsig(hw, blk, vsig,
5883 goto err_ice_rem_prof_id_flow;
5885 /* Adjust priorities */
5886 status = ice_adj_prof_priorities(hw, blk, vsig,
5889 goto err_ice_rem_prof_id_flow;
5893 /* Make a copy of the VSIG's list of Profiles */
5894 status = ice_get_profs_vsig(hw, blk, vsig, ©);
5896 goto err_ice_rem_prof_id_flow;
5898 /* Remove specified profile entry from the list */
5899 status = ice_rem_prof_from_list(hw, ©, hdl);
5901 goto err_ice_rem_prof_id_flow;
5903 if (LIST_EMPTY(©)) {
5904 status = ice_move_vsi(hw, blk, vsi,
5905 ICE_DEFAULT_VSIG, &chg);
5907 goto err_ice_rem_prof_id_flow;
5909 } else if (!ice_find_dup_props_vsig(hw, blk, ©,
5911 /* found an exact match */
5912 /* add or move VSI to the VSIG that matches */
5913 /* Search for a VSIG with a matching profile
5917 /* Found match, move VSI to the matching VSIG */
5918 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5920 goto err_ice_rem_prof_id_flow;
5922 /* since no existing VSIG supports this
5923 * characteristic pattern, we need to create a
5924 * new VSIG and TCAM entries
5926 status = ice_create_vsig_from_lst(hw, blk, vsi,
5930 goto err_ice_rem_prof_id_flow;
5932 /* Adjust priorities */
5933 status = ice_adj_prof_priorities(hw, blk, vsig,
5936 goto err_ice_rem_prof_id_flow;
5940 status = ICE_ERR_DOES_NOT_EXIST;
5943 /* update hardware tables */
5945 status = ice_upd_prof_hw(hw, blk, &chg);
5947 err_ice_rem_prof_id_flow:
5948 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
5949 LIST_DEL(&del->list_entry);
5953 LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, ©, ice_vsig_prof, list) {
5954 LIST_DEL(&del1->list);