1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2019
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 for (j = 0; j < BITS_PER_BYTE; j++) {
630 count += (mask[i] & (0x1 << j)) ? 1 : 0;
640 * ice_set_key - generate a variable sized key with multiples of 16-bits
641 * @key: pointer to where the key will be stored
642 * @size: the size of the complete key in bytes (must be even)
643 * @val: array of 8-bit values that makes up the value portion of the key
644 * @upd: array of 8-bit masks that determine what key portion to update
645 * @dc: array of 8-bit masks that make up the don't care mask
646 * @nm: array of 8-bit masks that make up the never match mask
647 * @off: the offset of the first byte in the key to update
648 * @len: the number of bytes in the key update
650 * This function generates a key from a value, a don't care mask and a never
652 * upd, dc, and nm are optional parameters, and can be NULL:
653 * upd == NULL --> udp mask is all 1's (update all bits)
654 * dc == NULL --> dc mask is all 0's (no don't care bits)
655 * nm == NULL --> nm mask is all 0's (no never match bits)
658 ice_set_key(u8 *key, u16 size, u8 *val, u8 *upd, u8 *dc, u8 *nm, u16 off,
664 /* size must be a multiple of 2 bytes. */
667 half_size = size / 2;
669 if (off + len > half_size)
672 /* Make sure at most one bit is set in the never match mask. Having more
673 * than one never match mask bit set will cause HW to consume excessive
674 * power otherwise; this is a power management efficiency check.
676 #define ICE_NVR_MTCH_BITS_MAX 1
677 if (nm && !ice_bits_max_set(nm, len, ICE_NVR_MTCH_BITS_MAX))
680 for (i = 0; i < len; i++)
681 if (ice_gen_key_word(val[i], upd ? upd[i] : 0xff,
682 dc ? dc[i] : 0, nm ? nm[i] : 0,
683 key + off + i, key + half_size + off + i))
690 * ice_acquire_global_cfg_lock
691 * @hw: pointer to the HW structure
692 * @access: access type (read or write)
694 * This function will request ownership of the global config lock for reading
695 * or writing of the package. When attempting to obtain write access, the
696 * caller must check for the following two return values:
698 * ICE_SUCCESS - Means the caller has acquired the global config lock
699 * and can perform writing of the package.
700 * ICE_ERR_AQ_NO_WORK - Indicates another driver has already written the
701 * package or has found that no update was necessary; in
702 * this case, the caller can just skip performing any
703 * update of the package.
705 static enum ice_status
706 ice_acquire_global_cfg_lock(struct ice_hw *hw,
707 enum ice_aq_res_access_type access)
709 enum ice_status status;
711 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
713 status = ice_acquire_res(hw, ICE_GLOBAL_CFG_LOCK_RES_ID, access,
714 ICE_GLOBAL_CFG_LOCK_TIMEOUT);
716 if (status == ICE_ERR_AQ_NO_WORK)
717 ice_debug(hw, ICE_DBG_PKG,
718 "Global config lock: No work to do\n");
724 * ice_release_global_cfg_lock
725 * @hw: pointer to the HW structure
727 * This function will release the global config lock.
729 static void ice_release_global_cfg_lock(struct ice_hw *hw)
731 ice_release_res(hw, ICE_GLOBAL_CFG_LOCK_RES_ID);
735 * ice_acquire_change_lock
736 * @hw: pointer to the HW structure
737 * @access: access type (read or write)
739 * This function will request ownership of the change lock.
742 ice_acquire_change_lock(struct ice_hw *hw, enum ice_aq_res_access_type access)
744 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
746 return ice_acquire_res(hw, ICE_CHANGE_LOCK_RES_ID, access,
747 ICE_CHANGE_LOCK_TIMEOUT);
751 * ice_release_change_lock
752 * @hw: pointer to the HW structure
754 * This function will release the change lock using the proper Admin Command.
756 void ice_release_change_lock(struct ice_hw *hw)
758 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
760 ice_release_res(hw, ICE_CHANGE_LOCK_RES_ID);
764 * ice_aq_download_pkg
765 * @hw: pointer to the hardware structure
766 * @pkg_buf: the package buffer to transfer
767 * @buf_size: the size of the package buffer
768 * @last_buf: last buffer indicator
769 * @error_offset: returns error offset
770 * @error_info: returns error information
771 * @cd: pointer to command details structure or NULL
773 * Download Package (0x0C40)
775 static enum ice_status
776 ice_aq_download_pkg(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf,
777 u16 buf_size, bool last_buf, u32 *error_offset,
778 u32 *error_info, struct ice_sq_cd *cd)
780 struct ice_aqc_download_pkg *cmd;
781 struct ice_aq_desc desc;
782 enum ice_status status;
784 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
791 cmd = &desc.params.download_pkg;
792 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_download_pkg);
793 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
796 cmd->flags |= ICE_AQC_DOWNLOAD_PKG_LAST_BUF;
798 status = ice_aq_send_cmd(hw, &desc, pkg_buf, buf_size, cd);
799 if (status == ICE_ERR_AQ_ERROR) {
800 /* Read error from buffer only when the FW returned an error */
801 struct ice_aqc_download_pkg_resp *resp;
803 resp = (struct ice_aqc_download_pkg_resp *)pkg_buf;
805 *error_offset = LE32_TO_CPU(resp->error_offset);
807 *error_info = LE32_TO_CPU(resp->error_info);
815 * @hw: pointer to the hardware structure
816 * @pkg_buf: the package cmd buffer
817 * @buf_size: the size of the package cmd buffer
818 * @last_buf: last buffer indicator
819 * @error_offset: returns error offset
820 * @error_info: returns error information
821 * @cd: pointer to command details structure or NULL
823 * Update Package (0x0C42)
825 static enum ice_status
826 ice_aq_update_pkg(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf, u16 buf_size,
827 bool last_buf, u32 *error_offset, u32 *error_info,
828 struct ice_sq_cd *cd)
830 struct ice_aqc_download_pkg *cmd;
831 struct ice_aq_desc desc;
832 enum ice_status status;
834 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
841 cmd = &desc.params.download_pkg;
842 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_update_pkg);
843 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
846 cmd->flags |= ICE_AQC_DOWNLOAD_PKG_LAST_BUF;
848 status = ice_aq_send_cmd(hw, &desc, pkg_buf, buf_size, cd);
849 if (status == ICE_ERR_AQ_ERROR) {
850 /* Read error from buffer only when the FW returned an error */
851 struct ice_aqc_download_pkg_resp *resp;
853 resp = (struct ice_aqc_download_pkg_resp *)pkg_buf;
855 *error_offset = LE32_TO_CPU(resp->error_offset);
857 *error_info = LE32_TO_CPU(resp->error_info);
864 * ice_find_seg_in_pkg
865 * @hw: pointer to the hardware structure
866 * @seg_type: the segment type to search for (i.e., SEGMENT_TYPE_CPK)
867 * @pkg_hdr: pointer to the package header to be searched
869 * This function searches a package file for a particular segment type. On
870 * success it returns a pointer to the segment header, otherwise it will
873 static struct ice_generic_seg_hdr *
874 ice_find_seg_in_pkg(struct ice_hw *hw, u32 seg_type,
875 struct ice_pkg_hdr *pkg_hdr)
879 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
880 ice_debug(hw, ICE_DBG_PKG, "Package format version: %d.%d.%d.%d\n",
881 pkg_hdr->format_ver.major, pkg_hdr->format_ver.minor,
882 pkg_hdr->format_ver.update, pkg_hdr->format_ver.draft);
884 /* Search all package segments for the requested segment type */
885 for (i = 0; i < LE32_TO_CPU(pkg_hdr->seg_count); i++) {
886 struct ice_generic_seg_hdr *seg;
888 seg = (struct ice_generic_seg_hdr *)
889 ((u8 *)pkg_hdr + LE32_TO_CPU(pkg_hdr->seg_offset[i]));
891 if (LE32_TO_CPU(seg->seg_type) == seg_type)
900 * @hw: pointer to the hardware structure
901 * @bufs: pointer to an array of buffers
902 * @count: the number of buffers in the array
904 * Obtains change lock and updates package.
907 ice_update_pkg(struct ice_hw *hw, struct ice_buf *bufs, u32 count)
909 enum ice_status status;
912 status = ice_acquire_change_lock(hw, ICE_RES_WRITE);
916 for (i = 0; i < count; i++) {
917 bool last = ((i + 1) == count);
919 struct ice_buf_hdr *bh = (struct ice_buf_hdr *)(bufs + i);
921 status = ice_aq_update_pkg(hw, bh, LE16_TO_CPU(bh->data_end),
922 last, &offset, &info, NULL);
925 ice_debug(hw, ICE_DBG_PKG,
926 "Update pkg failed: err %d off %d inf %d\n",
927 status, offset, info);
932 ice_release_change_lock(hw);
939 * @hw: pointer to the hardware structure
940 * @bufs: pointer to an array of buffers
941 * @count: the number of buffers in the array
943 * Obtains global config lock and downloads the package configuration buffers
944 * to the firmware. Metadata buffers are skipped, and the first metadata buffer
945 * found indicates that the rest of the buffers are all metadata buffers.
947 static enum ice_status
948 ice_dwnld_cfg_bufs(struct ice_hw *hw, struct ice_buf *bufs, u32 count)
950 enum ice_status status;
951 struct ice_buf_hdr *bh;
955 return ICE_ERR_PARAM;
957 /* If the first buffer's first section has its metadata bit set
958 * then there are no buffers to be downloaded, and the operation is
959 * considered a success.
961 bh = (struct ice_buf_hdr *)bufs;
962 if (LE32_TO_CPU(bh->section_entry[0].type) & ICE_METADATA_BUF)
965 /* reset pkg_dwnld_status in case this function is called in the
968 hw->pkg_dwnld_status = ICE_AQ_RC_OK;
970 status = ice_acquire_global_cfg_lock(hw, ICE_RES_WRITE);
972 if (status == ICE_ERR_AQ_NO_WORK)
973 hw->pkg_dwnld_status = ICE_AQ_RC_EEXIST;
975 hw->pkg_dwnld_status = hw->adminq.sq_last_status;
979 for (i = 0; i < count; i++) {
980 bool last = ((i + 1) == count);
983 /* check next buffer for metadata flag */
984 bh = (struct ice_buf_hdr *)(bufs + i + 1);
986 /* A set metadata flag in the next buffer will signal
987 * that the current buffer will be the last buffer
990 if (LE16_TO_CPU(bh->section_count))
991 if (LE32_TO_CPU(bh->section_entry[0].type) &
996 bh = (struct ice_buf_hdr *)(bufs + i);
998 status = ice_aq_download_pkg(hw, bh, ICE_PKG_BUF_SIZE, last,
999 &offset, &info, NULL);
1001 /* Save AQ status from download package */
1002 hw->pkg_dwnld_status = hw->adminq.sq_last_status;
1004 ice_debug(hw, ICE_DBG_PKG,
1005 "Pkg download failed: err %d off %d inf %d\n",
1006 status, offset, info);
1014 ice_release_global_cfg_lock(hw);
1020 * ice_aq_get_pkg_info_list
1021 * @hw: pointer to the hardware structure
1022 * @pkg_info: the buffer which will receive the information list
1023 * @buf_size: the size of the pkg_info information buffer
1024 * @cd: pointer to command details structure or NULL
1026 * Get Package Info List (0x0C43)
1028 static enum ice_status
1029 ice_aq_get_pkg_info_list(struct ice_hw *hw,
1030 struct ice_aqc_get_pkg_info_resp *pkg_info,
1031 u16 buf_size, struct ice_sq_cd *cd)
1033 struct ice_aq_desc desc;
1035 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1036 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_pkg_info_list);
1038 return ice_aq_send_cmd(hw, &desc, pkg_info, buf_size, cd);
1043 * @hw: pointer to the hardware structure
1044 * @ice_seg: pointer to the segment of the package to be downloaded
1046 * Handles the download of a complete package.
1048 static enum ice_status
1049 ice_download_pkg(struct ice_hw *hw, struct ice_seg *ice_seg)
1051 struct ice_buf_table *ice_buf_tbl;
1053 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1054 ice_debug(hw, ICE_DBG_PKG, "Segment version: %d.%d.%d.%d\n",
1055 ice_seg->hdr.seg_ver.major, ice_seg->hdr.seg_ver.minor,
1056 ice_seg->hdr.seg_ver.update, ice_seg->hdr.seg_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_name);
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_ver;
1108 ice_memcpy(hw->ice_pkg_name, seg_hdr->seg_name,
1109 sizeof(hw->ice_pkg_name), ICE_NONDMA_TO_NONDMA);
1111 ice_debug(hw, ICE_DBG_PKG, "Ice Pkg: %d.%d.%d.%d, %s\n",
1112 seg_hdr->seg_ver.major, seg_hdr->seg_ver.minor,
1113 seg_hdr->seg_ver.update, seg_hdr->seg_ver.draft,
1116 ice_debug(hw, ICE_DBG_INIT,
1117 "Did not find ice segment in driver package\n");
1126 * @hw: pointer to the hardware structure
1128 * Store details of the package currently loaded in HW into the HW structure.
1130 static enum ice_status ice_get_pkg_info(struct ice_hw *hw)
1132 struct ice_aqc_get_pkg_info_resp *pkg_info;
1133 enum ice_status status;
1137 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1139 size = sizeof(*pkg_info) + (sizeof(pkg_info->pkg_info[0]) *
1141 pkg_info = (struct ice_aqc_get_pkg_info_resp *)ice_malloc(hw, size);
1143 return ICE_ERR_NO_MEMORY;
1145 status = ice_aq_get_pkg_info_list(hw, pkg_info, size, NULL);
1147 goto init_pkg_free_alloc;
1149 for (i = 0; i < LE32_TO_CPU(pkg_info->count); i++) {
1150 #define ICE_PKG_FLAG_COUNT 4
1151 char flags[ICE_PKG_FLAG_COUNT + 1] = { 0 };
1154 if (pkg_info->pkg_info[i].is_active) {
1155 flags[place++] = 'A';
1156 hw->active_pkg_ver = pkg_info->pkg_info[i].ver;
1157 ice_memcpy(hw->active_pkg_name,
1158 pkg_info->pkg_info[i].name,
1159 sizeof(hw->active_pkg_name),
1160 ICE_NONDMA_TO_NONDMA);
1161 hw->active_pkg_in_nvm = pkg_info->pkg_info[i].is_in_nvm;
1163 if (pkg_info->pkg_info[i].is_active_at_boot)
1164 flags[place++] = 'B';
1165 if (pkg_info->pkg_info[i].is_modified)
1166 flags[place++] = 'M';
1167 if (pkg_info->pkg_info[i].is_in_nvm)
1168 flags[place++] = 'N';
1170 ice_debug(hw, ICE_DBG_PKG, "Pkg[%d]: %d.%d.%d.%d,%s,%s\n",
1171 i, pkg_info->pkg_info[i].ver.major,
1172 pkg_info->pkg_info[i].ver.minor,
1173 pkg_info->pkg_info[i].ver.update,
1174 pkg_info->pkg_info[i].ver.draft,
1175 pkg_info->pkg_info[i].name, flags);
1178 init_pkg_free_alloc:
1179 ice_free(hw, pkg_info);
1185 * ice_verify_pkg - verify package
1186 * @pkg: pointer to the package buffer
1187 * @len: size of the package buffer
1189 * Verifies various attributes of the package file, including length, format
1190 * version, and the requirement of at least one segment.
1192 static enum ice_status ice_verify_pkg(struct ice_pkg_hdr *pkg, u32 len)
1197 if (len < sizeof(*pkg))
1198 return ICE_ERR_BUF_TOO_SHORT;
1200 if (pkg->format_ver.major != ICE_PKG_FMT_VER_MAJ ||
1201 pkg->format_ver.minor != ICE_PKG_FMT_VER_MNR ||
1202 pkg->format_ver.update != ICE_PKG_FMT_VER_UPD ||
1203 pkg->format_ver.draft != ICE_PKG_FMT_VER_DFT)
1206 /* pkg must have at least one segment */
1207 seg_count = LE32_TO_CPU(pkg->seg_count);
1211 /* make sure segment array fits in package length */
1212 if (len < sizeof(*pkg) + ((seg_count - 1) * sizeof(pkg->seg_offset)))
1213 return ICE_ERR_BUF_TOO_SHORT;
1215 /* all segments must fit within length */
1216 for (i = 0; i < seg_count; i++) {
1217 u32 off = LE32_TO_CPU(pkg->seg_offset[i]);
1218 struct ice_generic_seg_hdr *seg;
1220 /* segment header must fit */
1221 if (len < off + sizeof(*seg))
1222 return ICE_ERR_BUF_TOO_SHORT;
1224 seg = (struct ice_generic_seg_hdr *)((u8 *)pkg + off);
1226 /* segment body must fit */
1227 if (len < off + LE32_TO_CPU(seg->seg_size))
1228 return ICE_ERR_BUF_TOO_SHORT;
1235 * ice_free_seg - free package segment pointer
1236 * @hw: pointer to the hardware structure
1238 * Frees the package segment pointer in the proper manner, depending on if the
1239 * segment was allocated or just the passed in pointer was stored.
1241 void ice_free_seg(struct ice_hw *hw)
1244 ice_free(hw, hw->pkg_copy);
1245 hw->pkg_copy = NULL;
1252 * ice_init_pkg_regs - initialize additional package registers
1253 * @hw: pointer to the hardware structure
1255 static void ice_init_pkg_regs(struct ice_hw *hw)
1257 #define ICE_SW_BLK_INP_MASK_L 0xFFFFFFFF
1258 #define ICE_SW_BLK_INP_MASK_H 0x0000FFFF
1259 #define ICE_SW_BLK_IDX 0
1261 /* setup Switch block input mask, which is 48-bits in two parts */
1262 wr32(hw, GL_PREEXT_L2_PMASK0(ICE_SW_BLK_IDX), ICE_SW_BLK_INP_MASK_L);
1263 wr32(hw, GL_PREEXT_L2_PMASK1(ICE_SW_BLK_IDX), ICE_SW_BLK_INP_MASK_H);
1267 * ice_chk_pkg_version - check package version for compatibility with driver
1268 * @pkg_ver: pointer to a version structure to check
1270 * Check to make sure that the package about to be downloaded is compatible with
1271 * the driver. To be compatible, the major and minor components of the package
1272 * version must match our ICE_PKG_SUPP_VER_MAJ and ICE_PKG_SUPP_VER_MNR
1275 static enum ice_status ice_chk_pkg_version(struct ice_pkg_ver *pkg_ver)
1277 if (pkg_ver->major != ICE_PKG_SUPP_VER_MAJ ||
1278 pkg_ver->minor != ICE_PKG_SUPP_VER_MNR)
1279 return ICE_ERR_NOT_SUPPORTED;
1285 * ice_init_pkg - initialize/download package
1286 * @hw: pointer to the hardware structure
1287 * @buf: pointer to the package buffer
1288 * @len: size of the package buffer
1290 * This function initializes a package. The package contains HW tables
1291 * required to do packet processing. First, the function extracts package
1292 * information such as version. Then it finds the ice configuration segment
1293 * within the package; this function then saves a copy of the segment pointer
1294 * within the supplied package buffer. Next, the function will cache any hints
1295 * from the package, followed by downloading the package itself. Note, that if
1296 * a previous PF driver has already downloaded the package successfully, then
1297 * the current driver will not have to download the package again.
1299 * The local package contents will be used to query default behavior and to
1300 * update specific sections of the HW's version of the package (e.g. to update
1301 * the parse graph to understand new protocols).
1303 * This function stores a pointer to the package buffer memory, and it is
1304 * expected that the supplied buffer will not be freed immediately. If the
1305 * package buffer needs to be freed, such as when read from a file, use
1306 * ice_copy_and_init_pkg() instead of directly calling ice_init_pkg() in this
1309 enum ice_status ice_init_pkg(struct ice_hw *hw, u8 *buf, u32 len)
1311 struct ice_pkg_hdr *pkg;
1312 enum ice_status status;
1313 struct ice_seg *seg;
1316 return ICE_ERR_PARAM;
1318 pkg = (struct ice_pkg_hdr *)buf;
1319 status = ice_verify_pkg(pkg, len);
1321 ice_debug(hw, ICE_DBG_INIT, "failed to verify pkg (err: %d)\n",
1326 /* initialize package info */
1327 status = ice_init_pkg_info(hw, pkg);
1331 /* before downloading the package, check package version for
1332 * compatibility with driver
1334 status = ice_chk_pkg_version(&hw->pkg_ver);
1338 /* find segment in given package */
1339 seg = (struct ice_seg *)ice_find_seg_in_pkg(hw, SEGMENT_TYPE_ICE, pkg);
1341 ice_debug(hw, ICE_DBG_INIT, "no ice segment in package.\n");
1345 /* initialize package hints and then download package */
1346 ice_init_pkg_hints(hw, seg);
1347 status = ice_download_pkg(hw, seg);
1348 if (status == ICE_ERR_AQ_NO_WORK) {
1349 ice_debug(hw, ICE_DBG_INIT,
1350 "package previously loaded - no work.\n");
1351 status = ICE_SUCCESS;
1354 /* Get information on the package currently loaded in HW, then make sure
1355 * the driver is compatible with this version.
1358 status = ice_get_pkg_info(hw);
1360 status = ice_chk_pkg_version(&hw->active_pkg_ver);
1365 /* on successful package download update other required
1366 * registers to support the package and fill HW tables
1367 * with package content.
1369 ice_init_pkg_regs(hw);
1370 ice_fill_blk_tbls(hw);
1372 ice_debug(hw, ICE_DBG_INIT, "package load failed, %d\n",
1380 * ice_copy_and_init_pkg - initialize/download a copy of the package
1381 * @hw: pointer to the hardware structure
1382 * @buf: pointer to the package buffer
1383 * @len: size of the package buffer
1385 * This function copies the package buffer, and then calls ice_init_pkg() to
1386 * initialize the copied package contents.
1388 * The copying is necessary if the package buffer supplied is constant, or if
1389 * the memory may disappear shortly after calling this function.
1391 * If the package buffer resides in the data segment and can be modified, the
1392 * caller is free to use ice_init_pkg() instead of ice_copy_and_init_pkg().
1394 * However, if the package buffer needs to be copied first, such as when being
1395 * read from a file, the caller should use ice_copy_and_init_pkg().
1397 * This function will first copy the package buffer, before calling
1398 * ice_init_pkg(). The caller is free to immediately destroy the original
1399 * package buffer, as the new copy will be managed by this function and
1402 enum ice_status ice_copy_and_init_pkg(struct ice_hw *hw, const u8 *buf, u32 len)
1404 enum ice_status status;
1408 return ICE_ERR_PARAM;
1410 buf_copy = (u8 *)ice_memdup(hw, buf, len, ICE_NONDMA_TO_NONDMA);
1412 status = ice_init_pkg(hw, buf_copy, len);
1414 /* Free the copy, since we failed to initialize the package */
1415 ice_free(hw, buf_copy);
1417 /* Track the copied pkg so we can free it later */
1418 hw->pkg_copy = buf_copy;
1427 * @hw: pointer to the HW structure
1429 * Allocates a package buffer and returns a pointer to the buffer header.
1430 * Note: all package contents must be in Little Endian form.
1432 static struct ice_buf_build *ice_pkg_buf_alloc(struct ice_hw *hw)
1434 struct ice_buf_build *bld;
1435 struct ice_buf_hdr *buf;
1437 bld = (struct ice_buf_build *)ice_malloc(hw, sizeof(*bld));
1441 buf = (struct ice_buf_hdr *)bld;
1442 buf->data_end = CPU_TO_LE16(sizeof(*buf) -
1443 sizeof(buf->section_entry[0]));
1449 * @sect_type: section type
1450 * @section: pointer to section
1451 * @index: index of the field vector entry to be returned
1452 * @offset: ptr to variable that receives the offset in the field vector table
1454 * This is a callback function that can be passed to ice_pkg_enum_entry.
1455 * This function treats the given section as of type ice_sw_fv_section and
1456 * enumerates offset field. "offset" is an index into the field vector
1460 ice_sw_fv_handler(u32 sect_type, void *section, u32 index, u32 *offset)
1462 struct ice_sw_fv_section *fv_section =
1463 (struct ice_sw_fv_section *)section;
1465 if (!section || sect_type != ICE_SID_FLD_VEC_SW)
1467 if (index >= LE16_TO_CPU(fv_section->count))
1470 /* "index" passed in to this function is relative to a given
1471 * 4k block. To get to the true index into the field vector
1472 * table need to add the relative index to the base_offset
1473 * field of this section
1475 *offset = LE16_TO_CPU(fv_section->base_offset) + index;
1476 return fv_section->fv + index;
1480 * ice_get_sw_prof_type - determine switch profile type
1481 * @hw: pointer to the HW structure
1482 * @fv: pointer to the switch field vector
1484 static enum ice_prof_type
1485 ice_get_sw_prof_type(struct ice_hw *hw, struct ice_fv *fv)
1489 for (i = 0; i < hw->blk[ICE_BLK_SW].es.fvw; i++) {
1490 /* UDP tunnel will have UDP_OF protocol ID and VNI offset */
1491 if (fv->ew[i].prot_id == (u8)ICE_PROT_UDP_OF &&
1492 fv->ew[i].off == ICE_VNI_OFFSET)
1493 return ICE_PROF_TUN_UDP;
1495 /* GRE tunnel will have GRE protocol */
1496 if (fv->ew[i].prot_id == (u8)ICE_PROT_GRE_OF)
1497 return ICE_PROF_TUN_GRE;
1499 /* PPPOE tunnel will have PPPOE protocol */
1500 if (fv->ew[i].prot_id == (u8)ICE_PROT_PPPOE)
1501 return ICE_PROF_TUN_PPPOE;
1504 return ICE_PROF_NON_TUN;
1508 * ice_get_sw_fv_bitmap - Get switch field vector bitmap based on profile type
1509 * @hw: pointer to hardware structure
1510 * @type: type of profiles requested
1511 * @bm: pointer to memory for returning the bitmap of field vectors
1514 ice_get_sw_fv_bitmap(struct ice_hw *hw, enum ice_prof_type type,
1517 struct ice_pkg_enum state;
1518 struct ice_seg *ice_seg;
1521 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1523 if (type == ICE_PROF_ALL) {
1526 for (i = 0; i < ICE_MAX_NUM_PROFILES; i++)
1531 ice_zero_bitmap(bm, ICE_MAX_NUM_PROFILES);
1535 enum ice_prof_type prof_type;
1538 fv = (struct ice_fv *)
1539 ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1540 &offset, ice_sw_fv_handler);
1544 /* Determine field vector type */
1545 prof_type = ice_get_sw_prof_type(hw, fv);
1547 if (type & prof_type)
1548 ice_set_bit((u16)offset, bm);
1554 * ice_get_sw_fv_list
1555 * @hw: pointer to the HW structure
1556 * @prot_ids: field vector to search for with a given protocol ID
1557 * @ids_cnt: lookup/protocol count
1558 * @bm: bitmap of field vectors to consider
1559 * @fv_list: Head of a list
1561 * Finds all the field vector entries from switch block that contain
1562 * a given protocol ID and returns a list of structures of type
1563 * "ice_sw_fv_list_entry". Every structure in the list has a field vector
1564 * definition and profile ID information
1565 * NOTE: The caller of the function is responsible for freeing the memory
1566 * allocated for every list entry.
1569 ice_get_sw_fv_list(struct ice_hw *hw, u16 *prot_ids, u8 ids_cnt,
1570 ice_bitmap_t *bm, struct LIST_HEAD_TYPE *fv_list)
1572 struct ice_sw_fv_list_entry *fvl;
1573 struct ice_sw_fv_list_entry *tmp;
1574 struct ice_pkg_enum state;
1575 struct ice_seg *ice_seg;
1579 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1581 if (!ids_cnt || !hw->seg)
1582 return ICE_ERR_PARAM;
1588 fv = (struct ice_fv *)
1589 ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1590 &offset, ice_sw_fv_handler);
1595 /* If field vector is not in the bitmap list, then skip this
1598 if (!ice_is_bit_set(bm, (u16)offset))
1601 for (i = 0; i < ids_cnt; i++) {
1604 /* This code assumes that if a switch field vector line
1605 * has a matching protocol, then this line will contain
1606 * the entries necessary to represent every field in
1607 * that protocol header.
1609 for (j = 0; j < hw->blk[ICE_BLK_SW].es.fvw; j++)
1610 if (fv->ew[j].prot_id == prot_ids[i])
1612 if (j >= hw->blk[ICE_BLK_SW].es.fvw)
1614 if (i + 1 == ids_cnt) {
1615 fvl = (struct ice_sw_fv_list_entry *)
1616 ice_malloc(hw, sizeof(*fvl));
1620 fvl->profile_id = offset;
1621 LIST_ADD(&fvl->list_entry, fv_list);
1626 if (LIST_EMPTY(fv_list))
1631 LIST_FOR_EACH_ENTRY_SAFE(fvl, tmp, fv_list, ice_sw_fv_list_entry,
1633 LIST_DEL(&fvl->list_entry);
1637 return ICE_ERR_NO_MEMORY;
1641 * ice_init_prof_result_bm - Initialize the profile result index bitmap
1642 * @hw: pointer to hardware structure
1644 void ice_init_prof_result_bm(struct ice_hw *hw)
1646 struct ice_pkg_enum state;
1647 struct ice_seg *ice_seg;
1650 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1660 fv = (struct ice_fv *)
1661 ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1662 &off, ice_sw_fv_handler);
1667 ice_zero_bitmap(hw->switch_info->prof_res_bm[off],
1670 /* Determine empty field vector indices, these can be
1671 * used for recipe results. Skip index 0, since it is
1672 * always used for Switch ID.
1674 for (i = 1; i < ICE_MAX_FV_WORDS; i++)
1675 if (fv->ew[i].prot_id == ICE_PROT_INVALID &&
1676 fv->ew[i].off == ICE_FV_OFFSET_INVAL)
1678 hw->switch_info->prof_res_bm[off]);
1684 * @hw: pointer to the HW structure
1685 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1687 * Frees a package buffer
1689 static void ice_pkg_buf_free(struct ice_hw *hw, struct ice_buf_build *bld)
1695 * ice_pkg_buf_reserve_section
1696 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1697 * @count: the number of sections to reserve
1699 * Reserves one or more section table entries in a package buffer. This routine
1700 * can be called multiple times as long as they are made before calling
1701 * ice_pkg_buf_alloc_section(). Once ice_pkg_buf_alloc_section()
1702 * is called once, the number of sections that can be allocated will not be able
1703 * to be increased; not using all reserved sections is fine, but this will
1704 * result in some wasted space in the buffer.
1705 * Note: all package contents must be in Little Endian form.
1707 static enum ice_status
1708 ice_pkg_buf_reserve_section(struct ice_buf_build *bld, u16 count)
1710 struct ice_buf_hdr *buf;
1715 return ICE_ERR_PARAM;
1717 buf = (struct ice_buf_hdr *)&bld->buf;
1719 /* already an active section, can't increase table size */
1720 section_count = LE16_TO_CPU(buf->section_count);
1721 if (section_count > 0)
1724 if (bld->reserved_section_table_entries + count > ICE_MAX_S_COUNT)
1726 bld->reserved_section_table_entries += count;
1728 data_end = LE16_TO_CPU(buf->data_end) +
1729 (count * sizeof(buf->section_entry[0]));
1730 buf->data_end = CPU_TO_LE16(data_end);
1736 * ice_pkg_buf_alloc_section
1737 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1738 * @type: the section type value
1739 * @size: the size of the section to reserve (in bytes)
1741 * Reserves memory in the buffer for a section's content and updates the
1742 * buffers' status accordingly. This routine returns a pointer to the first
1743 * byte of the section start within the buffer, which is used to fill in the
1745 * Note: all package contents must be in Little Endian form.
1748 ice_pkg_buf_alloc_section(struct ice_buf_build *bld, u32 type, u16 size)
1750 struct ice_buf_hdr *buf;
1754 if (!bld || !type || !size)
1757 buf = (struct ice_buf_hdr *)&bld->buf;
1759 /* check for enough space left in buffer */
1760 data_end = LE16_TO_CPU(buf->data_end);
1762 /* section start must align on 4 byte boundary */
1763 data_end = ICE_ALIGN(data_end, 4);
1765 if ((data_end + size) > ICE_MAX_S_DATA_END)
1768 /* check for more available section table entries */
1769 sect_count = LE16_TO_CPU(buf->section_count);
1770 if (sect_count < bld->reserved_section_table_entries) {
1771 void *section_ptr = ((u8 *)buf) + data_end;
1773 buf->section_entry[sect_count].offset = CPU_TO_LE16(data_end);
1774 buf->section_entry[sect_count].size = CPU_TO_LE16(size);
1775 buf->section_entry[sect_count].type = CPU_TO_LE32(type);
1778 buf->data_end = CPU_TO_LE16(data_end);
1780 buf->section_count = CPU_TO_LE16(sect_count + 1);
1784 /* no free section table entries */
1789 * ice_pkg_buf_get_active_sections
1790 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1792 * Returns the number of active sections. Before using the package buffer
1793 * in an update package command, the caller should make sure that there is at
1794 * least one active section - otherwise, the buffer is not legal and should
1796 * Note: all package contents must be in Little Endian form.
1798 static u16 ice_pkg_buf_get_active_sections(struct ice_buf_build *bld)
1800 struct ice_buf_hdr *buf;
1805 buf = (struct ice_buf_hdr *)&bld->buf;
1806 return LE16_TO_CPU(buf->section_count);
1810 * ice_pkg_buf_header
1811 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1813 * Return a pointer to the buffer's header
1815 static struct ice_buf *ice_pkg_buf(struct ice_buf_build *bld)
1824 * ice_tunnel_port_in_use
1825 * @hw: pointer to the HW structure
1826 * @port: port to search for
1827 * @index: optionally returns index
1829 * Returns whether a port is already in use as a tunnel, and optionally its
1832 bool ice_tunnel_port_in_use(struct ice_hw *hw, u16 port, u16 *index)
1836 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
1837 if (hw->tnl.tbl[i].in_use && hw->tnl.tbl[i].port == port) {
1847 * ice_tunnel_get_type
1848 * @hw: pointer to the HW structure
1849 * @port: port to search for
1850 * @type: returns tunnel index
1852 * For a given port number, will return the type of tunnel.
1855 ice_tunnel_get_type(struct ice_hw *hw, u16 port, enum ice_tunnel_type *type)
1859 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
1860 if (hw->tnl.tbl[i].in_use && hw->tnl.tbl[i].port == port) {
1861 *type = hw->tnl.tbl[i].type;
1869 * ice_find_free_tunnel_entry
1870 * @hw: pointer to the HW structure
1871 * @type: tunnel type
1872 * @index: optionally returns index
1874 * Returns whether there is a free tunnel entry, and optionally its index
1877 ice_find_free_tunnel_entry(struct ice_hw *hw, enum ice_tunnel_type type,
1882 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
1883 if (hw->tnl.tbl[i].valid && !hw->tnl.tbl[i].in_use &&
1884 hw->tnl.tbl[i].type == type) {
1894 * ice_get_tunnel_port - retrieve an open tunnel port
1895 * @hw: pointer to the HW structure
1896 * @type: tunnel type (TNL_ALL will return any open port)
1897 * @port: returns open port
1900 ice_get_open_tunnel_port(struct ice_hw *hw, enum ice_tunnel_type type,
1905 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
1906 if (hw->tnl.tbl[i].valid && hw->tnl.tbl[i].in_use &&
1907 (type == TNL_ALL || hw->tnl.tbl[i].type == type)) {
1908 *port = hw->tnl.tbl[i].port;
1917 * @hw: pointer to the HW structure
1918 * @type: type of tunnel
1919 * @port: port to use for vxlan tunnel
1924 ice_create_tunnel(struct ice_hw *hw, enum ice_tunnel_type type, u16 port)
1926 struct ice_boost_tcam_section *sect_rx, *sect_tx;
1927 enum ice_status status = ICE_ERR_MAX_LIMIT;
1928 struct ice_buf_build *bld;
1931 if (ice_tunnel_port_in_use(hw, port, NULL))
1932 return ICE_ERR_ALREADY_EXISTS;
1934 if (!ice_find_free_tunnel_entry(hw, type, &index))
1935 return ICE_ERR_OUT_OF_RANGE;
1937 bld = ice_pkg_buf_alloc(hw);
1939 return ICE_ERR_NO_MEMORY;
1941 /* allocate 2 sections, one for Rx parser, one for Tx parser */
1942 if (ice_pkg_buf_reserve_section(bld, 2))
1943 goto ice_create_tunnel_err;
1945 sect_rx = (struct ice_boost_tcam_section *)
1946 ice_pkg_buf_alloc_section(bld, ICE_SID_RXPARSER_BOOST_TCAM,
1949 goto ice_create_tunnel_err;
1950 sect_rx->count = CPU_TO_LE16(1);
1952 sect_tx = (struct ice_boost_tcam_section *)
1953 ice_pkg_buf_alloc_section(bld, ICE_SID_TXPARSER_BOOST_TCAM,
1956 goto ice_create_tunnel_err;
1957 sect_tx->count = CPU_TO_LE16(1);
1959 /* copy original boost entry to update package buffer */
1960 ice_memcpy(sect_rx->tcam, hw->tnl.tbl[index].boost_entry,
1961 sizeof(*sect_rx->tcam), ICE_NONDMA_TO_NONDMA);
1963 /* over-write the never-match dest port key bits with the encoded port
1966 ice_set_key((u8 *)§_rx->tcam[0].key, sizeof(sect_rx->tcam[0].key),
1967 (u8 *)&port, NULL, NULL, NULL,
1968 offsetof(struct ice_boost_key_value, hv_dst_port_key),
1969 sizeof(sect_rx->tcam[0].key.key.hv_dst_port_key));
1971 /* exact copy of entry to Tx section entry */
1972 ice_memcpy(sect_tx->tcam, sect_rx->tcam, sizeof(*sect_tx->tcam),
1973 ICE_NONDMA_TO_NONDMA);
1975 status = ice_update_pkg(hw, ice_pkg_buf(bld), 1);
1977 hw->tnl.tbl[index].port = port;
1978 hw->tnl.tbl[index].in_use = true;
1981 ice_create_tunnel_err:
1982 ice_pkg_buf_free(hw, bld);
1988 * ice_destroy_tunnel
1989 * @hw: pointer to the HW structure
1990 * @port: port of tunnel to destroy (ignored if the all parameter is true)
1991 * @all: flag that states to destroy all tunnels
1993 * Destroys a tunnel or all tunnels by creating an update package buffer
1994 * targeting the specific updates requested and then performing an update
1997 enum ice_status ice_destroy_tunnel(struct ice_hw *hw, u16 port, bool all)
1999 struct ice_boost_tcam_section *sect_rx, *sect_tx;
2000 enum ice_status status = ICE_ERR_MAX_LIMIT;
2001 struct ice_buf_build *bld;
2006 /* determine count */
2007 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
2008 if (hw->tnl.tbl[i].valid && hw->tnl.tbl[i].in_use &&
2009 (all || hw->tnl.tbl[i].port == port))
2013 return ICE_ERR_PARAM;
2015 /* size of section - there is at least one entry */
2016 size = (count - 1) * sizeof(*sect_rx->tcam) + sizeof(*sect_rx);
2018 bld = ice_pkg_buf_alloc(hw);
2020 return ICE_ERR_NO_MEMORY;
2022 /* allocate 2 sections, one for Rx parser, one for Tx parser */
2023 if (ice_pkg_buf_reserve_section(bld, 2))
2024 goto ice_destroy_tunnel_err;
2026 sect_rx = (struct ice_boost_tcam_section *)
2027 ice_pkg_buf_alloc_section(bld, ICE_SID_RXPARSER_BOOST_TCAM,
2030 goto ice_destroy_tunnel_err;
2031 sect_rx->count = CPU_TO_LE16(1);
2033 sect_tx = (struct ice_boost_tcam_section *)
2034 ice_pkg_buf_alloc_section(bld, ICE_SID_TXPARSER_BOOST_TCAM,
2037 goto ice_destroy_tunnel_err;
2038 sect_tx->count = CPU_TO_LE16(1);
2040 /* copy original boost entry to update package buffer, one copy to Rx
2041 * section, another copy to the Tx section
2043 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
2044 if (hw->tnl.tbl[i].valid && hw->tnl.tbl[i].in_use &&
2045 (all || hw->tnl.tbl[i].port == port)) {
2046 ice_memcpy(sect_rx->tcam + i,
2047 hw->tnl.tbl[i].boost_entry,
2048 sizeof(*sect_rx->tcam),
2049 ICE_NONDMA_TO_NONDMA);
2050 ice_memcpy(sect_tx->tcam + i,
2051 hw->tnl.tbl[i].boost_entry,
2052 sizeof(*sect_tx->tcam),
2053 ICE_NONDMA_TO_NONDMA);
2054 hw->tnl.tbl[i].marked = true;
2057 status = ice_update_pkg(hw, ice_pkg_buf(bld), 1);
2059 for (i = 0; i < hw->tnl.count &&
2060 i < ICE_TUNNEL_MAX_ENTRIES; i++)
2061 if (hw->tnl.tbl[i].marked) {
2062 hw->tnl.tbl[i].port = 0;
2063 hw->tnl.tbl[i].in_use = false;
2064 hw->tnl.tbl[i].marked = false;
2067 ice_destroy_tunnel_err:
2068 ice_pkg_buf_free(hw, bld);
2074 * ice_find_prot_off - find prot ID and offset pair, based on prof and FV index
2075 * @hw: pointer to the hardware structure
2076 * @blk: hardware block
2078 * @fv_idx: field vector word index
2079 * @prot: variable to receive the protocol ID
2080 * @off: variable to receive the protocol offset
2083 ice_find_prot_off(struct ice_hw *hw, enum ice_block blk, u8 prof, u8 fv_idx,
2086 struct ice_fv_word *fv_ext;
2088 if (prof >= hw->blk[blk].es.count)
2089 return ICE_ERR_PARAM;
2091 if (fv_idx >= hw->blk[blk].es.fvw)
2092 return ICE_ERR_PARAM;
2094 fv_ext = hw->blk[blk].es.t + (prof * hw->blk[blk].es.fvw);
2096 *prot = fv_ext[fv_idx].prot_id;
2097 *off = fv_ext[fv_idx].off;
2102 /* PTG Management */
2105 * ice_ptg_find_ptype - Search for packet type group using packet type (ptype)
2106 * @hw: pointer to the hardware structure
2108 * @ptype: the ptype to search for
2109 * @ptg: pointer to variable that receives the PTG
2111 * This function will search the PTGs for a particular ptype, returning the
2112 * PTG ID that contains it through the ptg parameter, with the value of
2113 * ICE_DEFAULT_PTG (0) meaning it is part the default PTG.
2115 static enum ice_status
2116 ice_ptg_find_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 *ptg)
2118 if (ptype >= ICE_XLT1_CNT || !ptg)
2119 return ICE_ERR_PARAM;
2121 *ptg = hw->blk[blk].xlt1.ptypes[ptype].ptg;
2126 * ice_ptg_alloc_val - Allocates a new packet type group ID by value
2127 * @hw: pointer to the hardware structure
2129 * @ptg: the ptg to allocate
2131 * This function allocates a given packet type group ID specified by the ptg
2134 static void ice_ptg_alloc_val(struct ice_hw *hw, enum ice_block blk, u8 ptg)
2136 hw->blk[blk].xlt1.ptg_tbl[ptg].in_use = true;
2140 * ice_ptg_remove_ptype - Removes ptype from a particular packet type group
2141 * @hw: pointer to the hardware structure
2143 * @ptype: the ptype to remove
2144 * @ptg: the ptg to remove the ptype from
2146 * This function will remove the ptype from the specific ptg, and move it to
2147 * the default PTG (ICE_DEFAULT_PTG).
2149 static enum ice_status
2150 ice_ptg_remove_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 ptg)
2152 struct ice_ptg_ptype **ch;
2153 struct ice_ptg_ptype *p;
2155 if (ptype > ICE_XLT1_CNT - 1)
2156 return ICE_ERR_PARAM;
2158 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].in_use)
2159 return ICE_ERR_DOES_NOT_EXIST;
2161 /* Should not happen if .in_use is set, bad config */
2162 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype)
2165 /* find the ptype within this PTG, and bypass the link over it */
2166 p = hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2167 ch = &hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2169 if (ptype == (p - hw->blk[blk].xlt1.ptypes)) {
2170 *ch = p->next_ptype;
2174 ch = &p->next_ptype;
2178 hw->blk[blk].xlt1.ptypes[ptype].ptg = ICE_DEFAULT_PTG;
2179 hw->blk[blk].xlt1.ptypes[ptype].next_ptype = NULL;
2185 * ice_ptg_add_mv_ptype - Adds/moves ptype to a particular packet type group
2186 * @hw: pointer to the hardware structure
2188 * @ptype: the ptype to add or move
2189 * @ptg: the ptg to add or move the ptype to
2191 * This function will either add or move a ptype to a particular PTG depending
2192 * on if the ptype is already part of another group. Note that using a
2193 * a destination PTG ID of ICE_DEFAULT_PTG (0) will move the ptype to the
2196 static enum ice_status
2197 ice_ptg_add_mv_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 ptg)
2199 enum ice_status status;
2202 if (ptype > ICE_XLT1_CNT - 1)
2203 return ICE_ERR_PARAM;
2205 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].in_use && ptg != ICE_DEFAULT_PTG)
2206 return ICE_ERR_DOES_NOT_EXIST;
2208 status = ice_ptg_find_ptype(hw, blk, ptype, &original_ptg);
2212 /* Is ptype already in the correct PTG? */
2213 if (original_ptg == ptg)
2216 /* Remove from original PTG and move back to the default PTG */
2217 if (original_ptg != ICE_DEFAULT_PTG)
2218 ice_ptg_remove_ptype(hw, blk, ptype, original_ptg);
2220 /* Moving to default PTG? Then we're done with this request */
2221 if (ptg == ICE_DEFAULT_PTG)
2224 /* Add ptype to PTG at beginning of list */
2225 hw->blk[blk].xlt1.ptypes[ptype].next_ptype =
2226 hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2227 hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype =
2228 &hw->blk[blk].xlt1.ptypes[ptype];
2230 hw->blk[blk].xlt1.ptypes[ptype].ptg = ptg;
2231 hw->blk[blk].xlt1.t[ptype] = ptg;
2236 /* Block / table size info */
2237 struct ice_blk_size_details {
2238 u16 xlt1; /* # XLT1 entries */
2239 u16 xlt2; /* # XLT2 entries */
2240 u16 prof_tcam; /* # profile ID TCAM entries */
2241 u16 prof_id; /* # profile IDs */
2242 u8 prof_cdid_bits; /* # cdid one-hot bits used in key */
2243 u16 prof_redir; /* # profile redirection entries */
2244 u16 es; /* # extraction sequence entries */
2245 u16 fvw; /* # field vector words */
2246 u8 overwrite; /* overwrite existing entries allowed */
2247 u8 reverse; /* reverse FV order */
2250 static const struct ice_blk_size_details blk_sizes[ICE_BLK_COUNT] = {
2253 * XLT1 - Number of entries in XLT1 table
2254 * XLT2 - Number of entries in XLT2 table
2255 * TCAM - Number of entries Profile ID TCAM table
2256 * CDID - Control Domain ID of the hardware block
2257 * PRED - Number of entries in the Profile Redirection Table
2258 * FV - Number of entries in the Field Vector
2259 * FVW - Width (in WORDs) of the Field Vector
2260 * OVR - Overwrite existing table entries
2263 /* XLT1 , XLT2 ,TCAM, PID,CDID,PRED, FV, FVW */
2264 /* Overwrite , Reverse FV */
2265 /* SW */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 256, 0, 256, 256, 48,
2267 /* ACL */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 32,
2269 /* FD */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 24,
2271 /* RSS */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 24,
2273 /* PE */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 64, 32, 0, 32, 32, 24,
2278 ICE_SID_XLT1_OFF = 0,
2281 ICE_SID_PR_REDIR_OFF,
2286 /* Characteristic handling */
2289 * ice_match_prop_lst - determine if properties of two lists match
2290 * @list1: first properties list
2291 * @list2: second properties list
2293 * Count, cookies and the order must match in order to be considered equivalent.
2296 ice_match_prop_lst(struct LIST_HEAD_TYPE *list1, struct LIST_HEAD_TYPE *list2)
2298 struct ice_vsig_prof *tmp1;
2299 struct ice_vsig_prof *tmp2;
2303 /* compare counts */
2304 LIST_FOR_EACH_ENTRY(tmp1, list1, ice_vsig_prof, list) {
2307 LIST_FOR_EACH_ENTRY(tmp2, list2, ice_vsig_prof, list) {
2310 if (!count || count != chk_count)
2313 tmp1 = LIST_FIRST_ENTRY(list1, struct ice_vsig_prof, list);
2314 tmp2 = LIST_FIRST_ENTRY(list2, struct ice_vsig_prof, list);
2316 /* profile cookies must compare, and in the exact same order to take
2317 * into account priority
2320 if (tmp2->profile_cookie != tmp1->profile_cookie)
2323 tmp1 = LIST_NEXT_ENTRY(tmp1, struct ice_vsig_prof, list);
2324 tmp2 = LIST_NEXT_ENTRY(tmp2, struct ice_vsig_prof, list);
2330 /* VSIG Management */
2333 * ice_vsig_find_vsi - find a VSIG that contains a specified VSI
2334 * @hw: pointer to the hardware structure
2336 * @vsi: VSI of interest
2337 * @vsig: pointer to receive the VSI group
2339 * This function will lookup the VSI entry in the XLT2 list and return
2340 * the VSI group its associated with.
2343 ice_vsig_find_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 *vsig)
2345 if (!vsig || vsi >= ICE_MAX_VSI)
2346 return ICE_ERR_PARAM;
2348 /* As long as there's a default or valid VSIG associated with the input
2349 * VSI, the functions returns a success. Any handling of VSIG will be
2350 * done by the following add, update or remove functions.
2352 *vsig = hw->blk[blk].xlt2.vsis[vsi].vsig;
2358 * ice_vsig_alloc_val - allocate a new VSIG by value
2359 * @hw: pointer to the hardware structure
2361 * @vsig: the vsig to allocate
2363 * This function will allocate a given VSIG specified by the vsig parameter.
2365 static u16 ice_vsig_alloc_val(struct ice_hw *hw, enum ice_block blk, u16 vsig)
2367 u16 idx = vsig & ICE_VSIG_IDX_M;
2369 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use) {
2370 INIT_LIST_HEAD(&hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst);
2371 hw->blk[blk].xlt2.vsig_tbl[idx].in_use = true;
2374 return ICE_VSIG_VALUE(idx, hw->pf_id);
2378 * ice_vsig_alloc - Finds a free entry and allocates a new VSIG
2379 * @hw: pointer to the hardware structure
2382 * This function will iterate through the VSIG list and mark the first
2383 * unused entry for the new VSIG entry as used and return that value.
2385 static u16 ice_vsig_alloc(struct ice_hw *hw, enum ice_block blk)
2389 for (i = 1; i < ICE_MAX_VSIGS; i++)
2390 if (!hw->blk[blk].xlt2.vsig_tbl[i].in_use)
2391 return ice_vsig_alloc_val(hw, blk, i);
2393 return ICE_DEFAULT_VSIG;
2397 * ice_find_dup_props_vsig - find VSI group with a specified set of properties
2398 * @hw: pointer to the hardware structure
2400 * @chs: characteristic list
2401 * @vsig: returns the VSIG with the matching profiles, if found
2403 * Each VSIG is associated with a characteristic set; i.e. all VSIs under
2404 * a group have the same characteristic set. To check if there exists a VSIG
2405 * which has the same characteristics as the input characteristics; this
2406 * function will iterate through the XLT2 list and return the VSIG that has a
2407 * matching configuration. In order to make sure that priorities are accounted
2408 * for, the list must match exactly, including the order in which the
2409 * characteristics are listed.
2411 static enum ice_status
2412 ice_find_dup_props_vsig(struct ice_hw *hw, enum ice_block blk,
2413 struct LIST_HEAD_TYPE *chs, u16 *vsig)
2415 struct ice_xlt2 *xlt2 = &hw->blk[blk].xlt2;
2418 for (i = 0; i < xlt2->count; i++) {
2419 if (xlt2->vsig_tbl[i].in_use &&
2420 ice_match_prop_lst(chs, &xlt2->vsig_tbl[i].prop_lst)) {
2421 *vsig = ICE_VSIG_VALUE(i, hw->pf_id);
2426 return ICE_ERR_DOES_NOT_EXIST;
2430 * ice_vsig_free - free VSI group
2431 * @hw: pointer to the hardware structure
2433 * @vsig: VSIG to remove
2435 * The function will remove all VSIs associated with the input VSIG and move
2436 * them to the DEFAULT_VSIG and mark the VSIG available.
2438 static enum ice_status
2439 ice_vsig_free(struct ice_hw *hw, enum ice_block blk, u16 vsig)
2441 struct ice_vsig_prof *dtmp, *del;
2442 struct ice_vsig_vsi *vsi_cur;
2445 idx = vsig & ICE_VSIG_IDX_M;
2446 if (idx >= ICE_MAX_VSIGS)
2447 return ICE_ERR_PARAM;
2449 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
2450 return ICE_ERR_DOES_NOT_EXIST;
2452 hw->blk[blk].xlt2.vsig_tbl[idx].in_use = false;
2454 vsi_cur = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2455 /* If the VSIG has at least 1 VSI then iterate through the
2456 * list and remove the VSIs before deleting the group.
2459 /* remove all vsis associated with this VSIG XLT2 entry */
2461 struct ice_vsig_vsi *tmp = vsi_cur->next_vsi;
2463 vsi_cur->vsig = ICE_DEFAULT_VSIG;
2464 vsi_cur->changed = 1;
2465 vsi_cur->next_vsi = NULL;
2469 /* NULL terminate head of VSI list */
2470 hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi = NULL;
2473 /* free characteristic list */
2474 LIST_FOR_EACH_ENTRY_SAFE(del, dtmp,
2475 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
2476 ice_vsig_prof, list) {
2477 LIST_DEL(&del->list);
2481 /* if VSIG characteristic list was cleared for reset
2482 * re-initialize the list head
2484 INIT_LIST_HEAD(&hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst);
2490 * ice_vsig_remove_vsi - remove VSI from VSIG
2491 * @hw: pointer to the hardware structure
2493 * @vsi: VSI to remove
2494 * @vsig: VSI group to remove from
2496 * The function will remove the input VSI from its VSI group and move it
2497 * to the DEFAULT_VSIG.
2499 static enum ice_status
2500 ice_vsig_remove_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
2502 struct ice_vsig_vsi **vsi_head, *vsi_cur, *vsi_tgt;
2505 idx = vsig & ICE_VSIG_IDX_M;
2507 if (vsi >= ICE_MAX_VSI || idx >= ICE_MAX_VSIGS)
2508 return ICE_ERR_PARAM;
2510 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
2511 return ICE_ERR_DOES_NOT_EXIST;
2513 /* entry already in default VSIG, don't have to remove */
2514 if (idx == ICE_DEFAULT_VSIG)
2517 vsi_head = &hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2521 vsi_tgt = &hw->blk[blk].xlt2.vsis[vsi];
2522 vsi_cur = (*vsi_head);
2524 /* iterate the VSI list, skip over the entry to be removed */
2526 if (vsi_tgt == vsi_cur) {
2527 (*vsi_head) = vsi_cur->next_vsi;
2530 vsi_head = &vsi_cur->next_vsi;
2531 vsi_cur = vsi_cur->next_vsi;
2534 /* verify if VSI was removed from group list */
2536 return ICE_ERR_DOES_NOT_EXIST;
2538 vsi_cur->vsig = ICE_DEFAULT_VSIG;
2539 vsi_cur->changed = 1;
2540 vsi_cur->next_vsi = NULL;
2546 * ice_vsig_add_mv_vsi - add or move a VSI to a VSI group
2547 * @hw: pointer to the hardware structure
2550 * @vsig: destination VSI group
2552 * This function will move or add the input VSI to the target VSIG.
2553 * The function will find the original VSIG the VSI belongs to and
2554 * move the entry to the DEFAULT_VSIG, update the original VSIG and
2555 * then move entry to the new VSIG.
2557 static enum ice_status
2558 ice_vsig_add_mv_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
2560 struct ice_vsig_vsi *tmp;
2561 enum ice_status status;
2564 idx = vsig & ICE_VSIG_IDX_M;
2566 if (vsi >= ICE_MAX_VSI || idx >= ICE_MAX_VSIGS)
2567 return ICE_ERR_PARAM;
2569 /* if VSIG not in use and VSIG is not default type this VSIG
2572 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use &&
2573 vsig != ICE_DEFAULT_VSIG)
2574 return ICE_ERR_DOES_NOT_EXIST;
2576 status = ice_vsig_find_vsi(hw, blk, vsi, &orig_vsig);
2580 /* no update required if vsigs match */
2581 if (orig_vsig == vsig)
2584 if (orig_vsig != ICE_DEFAULT_VSIG) {
2585 /* remove entry from orig_vsig and add to default VSIG */
2586 status = ice_vsig_remove_vsi(hw, blk, vsi, orig_vsig);
2591 if (idx == ICE_DEFAULT_VSIG)
2594 /* Create VSI entry and add VSIG and prop_mask values */
2595 hw->blk[blk].xlt2.vsis[vsi].vsig = vsig;
2596 hw->blk[blk].xlt2.vsis[vsi].changed = 1;
2598 /* Add new entry to the head of the VSIG list */
2599 tmp = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2600 hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi =
2601 &hw->blk[blk].xlt2.vsis[vsi];
2602 hw->blk[blk].xlt2.vsis[vsi].next_vsi = tmp;
2603 hw->blk[blk].xlt2.t[vsi] = vsig;
2609 * ice_prof_has_mask_idx - determine if profile index masking is identical
2610 * @hw: pointer to the hardware structure
2612 * @prof: profile to check
2613 * @idx: profile index to check
2614 * @masks: masks to match
2617 ice_prof_has_mask_idx(struct ice_hw *hw, enum ice_block blk, u8 prof, u16 idx,
2620 bool expect_no_mask = false;
2625 /* If mask is 0x0000 or 0xffff, then there is no masking */
2626 if (mask == 0 || mask == 0xffff)
2627 expect_no_mask = true;
2629 /* Scan the enabled masks on this profile, for the specified idx */
2630 for (i = hw->blk[blk].masks.first; i < hw->blk[blk].masks.first +
2631 hw->blk[blk].masks.count; i++)
2632 if (hw->blk[blk].es.mask_ena[prof] & BIT(i))
2633 if (hw->blk[blk].masks.masks[i].in_use &&
2634 hw->blk[blk].masks.masks[i].idx == idx) {
2636 if (hw->blk[blk].masks.masks[i].mask == mask)
2641 if (expect_no_mask) {
2653 * ice_prof_has_mask - determine if profile masking is identical
2654 * @hw: pointer to the hardware structure
2656 * @prof: profile to check
2657 * @masks: masks to match
2660 ice_prof_has_mask(struct ice_hw *hw, enum ice_block blk, u8 prof, u16 *masks)
2664 /* es->mask_ena[prof] will have the mask */
2665 for (i = 0; i < hw->blk[blk].es.fvw; i++)
2666 if (!ice_prof_has_mask_idx(hw, blk, prof, i, masks[i]))
2673 * ice_find_prof_id_with_mask - find profile ID for a given field vector
2674 * @hw: pointer to the hardware structure
2676 * @fv: field vector to search for
2677 * @masks: masks for fv
2678 * @prof_id: receives the profile ID
2680 static enum ice_status
2681 ice_find_prof_id_with_mask(struct ice_hw *hw, enum ice_block blk,
2682 struct ice_fv_word *fv, u16 *masks, u8 *prof_id)
2684 struct ice_es *es = &hw->blk[blk].es;
2687 for (i = 0; i < es->count; i++) {
2688 u16 off = i * es->fvw;
2690 if (memcmp(&es->t[off], fv, es->fvw * sizeof(*fv)))
2693 /* check if masks settings are the same for this profile */
2694 if (masks && !ice_prof_has_mask(hw, blk, i, masks))
2701 return ICE_ERR_DOES_NOT_EXIST;
2705 * ice_prof_id_rsrc_type - get profile ID resource type for a block type
2706 * @blk: the block type
2707 * @rsrc_type: pointer to variable to receive the resource type
2709 static bool ice_prof_id_rsrc_type(enum ice_block blk, u16 *rsrc_type)
2713 *rsrc_type = ICE_AQC_RES_TYPE_SWITCH_PROF_BLDR_PROFID;
2716 *rsrc_type = ICE_AQC_RES_TYPE_ACL_PROF_BLDR_PROFID;
2719 *rsrc_type = ICE_AQC_RES_TYPE_FD_PROF_BLDR_PROFID;
2722 *rsrc_type = ICE_AQC_RES_TYPE_HASH_PROF_BLDR_PROFID;
2725 *rsrc_type = ICE_AQC_RES_TYPE_QHASH_PROF_BLDR_PROFID;
2734 * ice_tcam_ent_rsrc_type - get TCAM entry resource type for a block type
2735 * @blk: the block type
2736 * @rsrc_type: pointer to variable to receive the resource type
2738 static bool ice_tcam_ent_rsrc_type(enum ice_block blk, u16 *rsrc_type)
2742 *rsrc_type = ICE_AQC_RES_TYPE_SWITCH_PROF_BLDR_TCAM;
2745 *rsrc_type = ICE_AQC_RES_TYPE_ACL_PROF_BLDR_TCAM;
2748 *rsrc_type = ICE_AQC_RES_TYPE_FD_PROF_BLDR_TCAM;
2751 *rsrc_type = ICE_AQC_RES_TYPE_HASH_PROF_BLDR_TCAM;
2754 *rsrc_type = ICE_AQC_RES_TYPE_QHASH_PROF_BLDR_TCAM;
2763 * ice_alloc_tcam_ent - allocate hardware TCAM entry
2764 * @hw: pointer to the HW struct
2765 * @blk: the block to allocate the TCAM for
2766 * @tcam_idx: pointer to variable to receive the TCAM entry
2768 * This function allocates a new entry in a Profile ID TCAM for a specific
2771 static enum ice_status
2772 ice_alloc_tcam_ent(struct ice_hw *hw, enum ice_block blk, u16 *tcam_idx)
2776 if (!ice_tcam_ent_rsrc_type(blk, &res_type))
2777 return ICE_ERR_PARAM;
2779 return ice_alloc_hw_res(hw, res_type, 1, true, tcam_idx);
2783 * ice_free_tcam_ent - free hardware TCAM entry
2784 * @hw: pointer to the HW struct
2785 * @blk: the block from which to free the TCAM entry
2786 * @tcam_idx: the TCAM entry to free
2788 * This function frees an entry in a Profile ID TCAM for a specific block.
2790 static enum ice_status
2791 ice_free_tcam_ent(struct ice_hw *hw, enum ice_block blk, u16 tcam_idx)
2795 if (!ice_tcam_ent_rsrc_type(blk, &res_type))
2796 return ICE_ERR_PARAM;
2798 return ice_free_hw_res(hw, res_type, 1, &tcam_idx);
2802 * ice_alloc_prof_id - allocate profile ID
2803 * @hw: pointer to the HW struct
2804 * @blk: the block to allocate the profile ID for
2805 * @prof_id: pointer to variable to receive the profile ID
2807 * This function allocates a new profile ID, which also corresponds to a Field
2808 * Vector (Extraction Sequence) entry.
2810 static enum ice_status
2811 ice_alloc_prof_id(struct ice_hw *hw, enum ice_block blk, u8 *prof_id)
2813 enum ice_status status;
2817 if (!ice_prof_id_rsrc_type(blk, &res_type))
2818 return ICE_ERR_PARAM;
2820 status = ice_alloc_hw_res(hw, res_type, 1, false, &get_prof);
2822 *prof_id = (u8)get_prof;
2828 * ice_free_prof_id - free profile ID
2829 * @hw: pointer to the HW struct
2830 * @blk: the block from which to free the profile ID
2831 * @prof_id: the profile ID to free
2833 * This function frees a profile ID, which also corresponds to a Field Vector.
2835 static enum ice_status
2836 ice_free_prof_id(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
2838 u16 tmp_prof_id = (u16)prof_id;
2841 if (!ice_prof_id_rsrc_type(blk, &res_type))
2842 return ICE_ERR_PARAM;
2844 return ice_free_hw_res(hw, res_type, 1, &tmp_prof_id);
2848 * ice_prof_inc_ref - increment reference count for profile
2849 * @hw: pointer to the HW struct
2850 * @blk: the block from which to free the profile ID
2851 * @prof_id: the profile ID for which to increment the reference count
2853 static enum ice_status
2854 ice_prof_inc_ref(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
2856 if (prof_id > hw->blk[blk].es.count)
2857 return ICE_ERR_PARAM;
2859 hw->blk[blk].es.ref_count[prof_id]++;
2865 * ice_write_prof_mask_reg - write profile mask register
2866 * @hw: pointer to the HW struct
2867 * @blk: hardware block
2868 * @mask_idx: mask index
2869 * @idx: index of the FV which will use the mask
2870 * @mask: the 16-bit mask
2873 ice_write_prof_mask_reg(struct ice_hw *hw, enum ice_block blk, u16 mask_idx,
2881 offset = GLQF_HMASK(mask_idx);
2882 val = (idx << GLQF_HMASK_MSK_INDEX_S) &
2883 GLQF_HMASK_MSK_INDEX_M;
2884 val |= (mask << GLQF_HMASK_MASK_S) & GLQF_HMASK_MASK_M;
2887 offset = GLQF_FDMASK(mask_idx);
2888 val = (idx << GLQF_FDMASK_MSK_INDEX_S) &
2889 GLQF_FDMASK_MSK_INDEX_M;
2890 val |= (mask << GLQF_FDMASK_MASK_S) &
2894 ice_debug(hw, ICE_DBG_PKG, "No profile masks for block %d\n",
2899 wr32(hw, offset, val);
2900 ice_debug(hw, ICE_DBG_PKG, "write mask, blk %d (%d): %x = %x\n",
2901 blk, idx, offset, val);
2905 * ice_write_prof_mask_enable_res - write profile mask enable register
2906 * @hw: pointer to the HW struct
2907 * @blk: hardware block
2908 * @prof_id: profile ID
2909 * @enable_mask: enable mask
2912 ice_write_prof_mask_enable_res(struct ice_hw *hw, enum ice_block blk,
2913 u16 prof_id, u32 enable_mask)
2919 offset = GLQF_HMASK_SEL(prof_id);
2922 offset = GLQF_FDMASK_SEL(prof_id);
2925 ice_debug(hw, ICE_DBG_PKG, "No profile masks for block %d\n",
2930 wr32(hw, offset, enable_mask);
2931 ice_debug(hw, ICE_DBG_PKG, "write mask enable, blk %d (%d): %x = %x\n",
2932 blk, prof_id, offset, enable_mask);
2936 * ice_init_prof_masks - initial prof masks
2937 * @hw: pointer to the HW struct
2938 * @blk: hardware block
2940 static void ice_init_prof_masks(struct ice_hw *hw, enum ice_block blk)
2945 ice_init_lock(&hw->blk[blk].masks.lock);
2947 per_pf = ICE_PROF_MASK_COUNT / hw->dev_caps.num_funcs;
2949 hw->blk[blk].masks.count = per_pf;
2950 hw->blk[blk].masks.first = hw->pf_id * per_pf;
2952 ice_memset(hw->blk[blk].masks.masks, 0,
2953 sizeof(hw->blk[blk].masks.masks), ICE_NONDMA_MEM);
2955 for (i = hw->blk[blk].masks.first;
2956 i < hw->blk[blk].masks.first + hw->blk[blk].masks.count; i++)
2957 ice_write_prof_mask_reg(hw, blk, i, 0, 0);
2961 * ice_init_all_prof_masks - initial all prof masks
2962 * @hw: pointer to the HW struct
2964 void ice_init_all_prof_masks(struct ice_hw *hw)
2966 ice_init_prof_masks(hw, ICE_BLK_RSS);
2967 ice_init_prof_masks(hw, ICE_BLK_FD);
2971 * ice_alloc_prof_mask - allocate profile mask
2972 * @hw: pointer to the HW struct
2973 * @blk: hardware block
2974 * @idx: index of FV which will use the mask
2975 * @mask: the 16-bit mask
2976 * @mask_idx: variable to receive the mask index
2978 static enum ice_status
2979 ice_alloc_prof_mask(struct ice_hw *hw, enum ice_block blk, u16 idx, u16 mask,
2982 bool found_unused = false, found_copy = false;
2983 enum ice_status status = ICE_ERR_MAX_LIMIT;
2984 u16 unused_idx = 0, copy_idx = 0;
2987 if (blk != ICE_BLK_RSS && blk != ICE_BLK_FD)
2988 return ICE_ERR_PARAM;
2990 ice_acquire_lock(&hw->blk[blk].masks.lock);
2992 for (i = hw->blk[blk].masks.first;
2993 i < hw->blk[blk].masks.first + hw->blk[blk].masks.count; i++)
2994 if (hw->blk[blk].masks.masks[i].in_use) {
2995 /* if mask is in use and it exactly duplicates the
2996 * desired mask and index, then in can be reused
2998 if (hw->blk[blk].masks.masks[i].mask == mask &&
2999 hw->blk[blk].masks.masks[i].idx == idx) {
3005 /* save off unused index, but keep searching in case
3006 * there is an exact match later on
3008 if (!found_unused) {
3009 found_unused = true;
3016 else if (found_unused)
3019 goto err_ice_alloc_prof_mask;
3021 /* update mask for a new entry */
3023 hw->blk[blk].masks.masks[i].in_use = true;
3024 hw->blk[blk].masks.masks[i].mask = mask;
3025 hw->blk[blk].masks.masks[i].idx = idx;
3026 hw->blk[blk].masks.masks[i].ref = 0;
3027 ice_write_prof_mask_reg(hw, blk, i, idx, mask);
3030 hw->blk[blk].masks.masks[i].ref++;
3032 status = ICE_SUCCESS;
3034 err_ice_alloc_prof_mask:
3035 ice_release_lock(&hw->blk[blk].masks.lock);
3041 * ice_free_prof_mask - free profile mask
3042 * @hw: pointer to the HW struct
3043 * @blk: hardware block
3044 * @mask_idx: index of mask
3046 static enum ice_status
3047 ice_free_prof_mask(struct ice_hw *hw, enum ice_block blk, u16 mask_idx)
3049 if (blk != ICE_BLK_RSS && blk != ICE_BLK_FD)
3050 return ICE_ERR_PARAM;
3052 if (!(mask_idx >= hw->blk[blk].masks.first &&
3053 mask_idx < hw->blk[blk].masks.first + hw->blk[blk].masks.count))
3054 return ICE_ERR_DOES_NOT_EXIST;
3056 ice_acquire_lock(&hw->blk[blk].masks.lock);
3058 if (!hw->blk[blk].masks.masks[mask_idx].in_use)
3059 goto exit_ice_free_prof_mask;
3061 if (hw->blk[blk].masks.masks[mask_idx].ref > 1) {
3062 hw->blk[blk].masks.masks[mask_idx].ref--;
3063 goto exit_ice_free_prof_mask;
3067 hw->blk[blk].masks.masks[mask_idx].in_use = false;
3068 hw->blk[blk].masks.masks[mask_idx].mask = 0;
3069 hw->blk[blk].masks.masks[mask_idx].idx = 0;
3071 /* update mask as unused entry */
3072 ice_debug(hw, ICE_DBG_PKG, "Free mask, blk %d, mask %d", blk, mask_idx);
3073 ice_write_prof_mask_reg(hw, blk, mask_idx, 0, 0);
3075 exit_ice_free_prof_mask:
3076 ice_release_lock(&hw->blk[blk].masks.lock);
3082 * ice_free_prof_masks - free all profile masks for a profile
3083 * @hw: pointer to the HW struct
3084 * @blk: hardware block
3085 * @prof_id: profile ID
3087 static enum ice_status
3088 ice_free_prof_masks(struct ice_hw *hw, enum ice_block blk, u16 prof_id)
3093 if (blk != ICE_BLK_RSS && blk != ICE_BLK_FD)
3094 return ICE_ERR_PARAM;
3096 mask_bm = hw->blk[blk].es.mask_ena[prof_id];
3097 for (i = 0; i < BITS_PER_BYTE * sizeof(mask_bm); i++)
3098 if (mask_bm & BIT(i))
3099 ice_free_prof_mask(hw, blk, i);
3105 * ice_shutdown_prof_masks - releases lock for masking
3106 * @hw: pointer to the HW struct
3107 * @blk: hardware block
3109 * This should be called before unloading the driver
3111 static void ice_shutdown_prof_masks(struct ice_hw *hw, enum ice_block blk)
3115 ice_acquire_lock(&hw->blk[blk].masks.lock);
3117 for (i = hw->blk[blk].masks.first;
3118 i < hw->blk[blk].masks.first + hw->blk[blk].masks.count; i++) {
3119 ice_write_prof_mask_reg(hw, blk, i, 0, 0);
3121 hw->blk[blk].masks.masks[i].in_use = false;
3122 hw->blk[blk].masks.masks[i].idx = 0;
3123 hw->blk[blk].masks.masks[i].mask = 0;
3126 ice_release_lock(&hw->blk[blk].masks.lock);
3127 ice_destroy_lock(&hw->blk[blk].masks.lock);
3131 * ice_shutdown_all_prof_masks - releases all locks for masking
3132 * @hw: pointer to the HW struct
3133 * @blk: hardware block
3135 * This should be called before unloading the driver
3137 void ice_shutdown_all_prof_masks(struct ice_hw *hw)
3139 ice_shutdown_prof_masks(hw, ICE_BLK_RSS);
3140 ice_shutdown_prof_masks(hw, ICE_BLK_FD);
3144 * ice_update_prof_masking - set registers according to masking
3145 * @hw: pointer to the HW struct
3146 * @blk: hardware block
3147 * @prof_id: profile ID
3151 static enum ice_status
3152 ice_update_prof_masking(struct ice_hw *hw, enum ice_block blk, u16 prof_id,
3153 struct ice_fv_word *es, u16 *masks)
3160 /* Only support FD and RSS masking, otherwise nothing to be done */
3161 if (blk != ICE_BLK_RSS && blk != ICE_BLK_FD)
3164 for (i = 0; i < hw->blk[blk].es.fvw; i++)
3165 if (masks[i] && masks[i] != 0xFFFF) {
3166 if (!ice_alloc_prof_mask(hw, blk, i, masks[i], &idx)) {
3167 ena_mask |= BIT(idx);
3169 /* not enough bitmaps */
3176 /* free any bitmaps we have allocated */
3177 for (i = 0; i < BITS_PER_BYTE * sizeof(ena_mask); i++)
3178 if (ena_mask & BIT(i))
3179 ice_free_prof_mask(hw, blk, i);
3181 return ICE_ERR_OUT_OF_RANGE;
3184 /* enable the masks for this profile */
3185 ice_write_prof_mask_enable_res(hw, blk, prof_id, ena_mask);
3187 /* store enabled masks with profile so that they can be freed later */
3188 hw->blk[blk].es.mask_ena[prof_id] = ena_mask;
3194 * ice_write_es - write an extraction sequence to hardware
3195 * @hw: pointer to the HW struct
3196 * @blk: the block in which to write the extraction sequence
3197 * @prof_id: the profile ID to write
3198 * @fv: pointer to the extraction sequence to write - NULL to clear extraction
3201 ice_write_es(struct ice_hw *hw, enum ice_block blk, u8 prof_id,
3202 struct ice_fv_word *fv)
3206 off = prof_id * hw->blk[blk].es.fvw;
3208 ice_memset(&hw->blk[blk].es.t[off], 0, hw->blk[blk].es.fvw *
3209 sizeof(*fv), ICE_NONDMA_MEM);
3210 hw->blk[blk].es.written[prof_id] = false;
3212 ice_memcpy(&hw->blk[blk].es.t[off], fv, hw->blk[blk].es.fvw *
3213 sizeof(*fv), ICE_NONDMA_TO_NONDMA);
3218 * ice_prof_dec_ref - decrement reference count for profile
3219 * @hw: pointer to the HW struct
3220 * @blk: the block from which to free the profile ID
3221 * @prof_id: the profile ID for which to decrement the reference count
3223 static enum ice_status
3224 ice_prof_dec_ref(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
3226 if (prof_id > hw->blk[blk].es.count)
3227 return ICE_ERR_PARAM;
3229 if (hw->blk[blk].es.ref_count[prof_id] > 0) {
3230 if (!--hw->blk[blk].es.ref_count[prof_id]) {
3231 ice_write_es(hw, blk, prof_id, NULL);
3232 ice_free_prof_masks(hw, blk, prof_id);
3233 return ice_free_prof_id(hw, blk, prof_id);
3240 /* Block / table section IDs */
3241 static const u32 ice_blk_sids[ICE_BLK_COUNT][ICE_SID_OFF_COUNT] = {
3245 ICE_SID_PROFID_TCAM_SW,
3246 ICE_SID_PROFID_REDIR_SW,
3253 ICE_SID_PROFID_TCAM_ACL,
3254 ICE_SID_PROFID_REDIR_ACL,
3261 ICE_SID_PROFID_TCAM_FD,
3262 ICE_SID_PROFID_REDIR_FD,
3269 ICE_SID_PROFID_TCAM_RSS,
3270 ICE_SID_PROFID_REDIR_RSS,
3277 ICE_SID_PROFID_TCAM_PE,
3278 ICE_SID_PROFID_REDIR_PE,
3284 * ice_init_sw_xlt1_db - init software XLT1 database from HW tables
3285 * @hw: pointer to the hardware structure
3286 * @blk: the HW block to initialize
3288 static void ice_init_sw_xlt1_db(struct ice_hw *hw, enum ice_block blk)
3292 for (pt = 0; pt < hw->blk[blk].xlt1.count; pt++) {
3295 ptg = hw->blk[blk].xlt1.t[pt];
3296 if (ptg != ICE_DEFAULT_PTG) {
3297 ice_ptg_alloc_val(hw, blk, ptg);
3298 ice_ptg_add_mv_ptype(hw, blk, pt, ptg);
3304 * ice_init_sw_xlt2_db - init software XLT2 database from HW tables
3305 * @hw: pointer to the hardware structure
3306 * @blk: the HW block to initialize
3308 static void ice_init_sw_xlt2_db(struct ice_hw *hw, enum ice_block blk)
3312 for (vsi = 0; vsi < hw->blk[blk].xlt2.count; vsi++) {
3315 vsig = hw->blk[blk].xlt2.t[vsi];
3317 ice_vsig_alloc_val(hw, blk, vsig);
3318 ice_vsig_add_mv_vsi(hw, blk, vsi, vsig);
3319 /* no changes at this time, since this has been
3320 * initialized from the original package
3322 hw->blk[blk].xlt2.vsis[vsi].changed = 0;
3328 * ice_init_sw_db - init software database from HW tables
3329 * @hw: pointer to the hardware structure
3331 static void ice_init_sw_db(struct ice_hw *hw)
3335 for (i = 0; i < ICE_BLK_COUNT; i++) {
3336 ice_init_sw_xlt1_db(hw, (enum ice_block)i);
3337 ice_init_sw_xlt2_db(hw, (enum ice_block)i);
3342 * ice_fill_tbl - Reads content of a single table type into database
3343 * @hw: pointer to the hardware structure
3344 * @block_id: Block ID of the table to copy
3345 * @sid: Section ID of the table to copy
3347 * Will attempt to read the entire content of a given table of a single block
3348 * into the driver database. We assume that the buffer will always
3349 * be as large or larger than the data contained in the package. If
3350 * this condition is not met, there is most likely an error in the package
3353 static void ice_fill_tbl(struct ice_hw *hw, enum ice_block block_id, u32 sid)
3355 u32 dst_len, sect_len, offset = 0;
3356 struct ice_prof_redir_section *pr;
3357 struct ice_prof_id_section *pid;
3358 struct ice_xlt1_section *xlt1;
3359 struct ice_xlt2_section *xlt2;
3360 struct ice_sw_fv_section *es;
3361 struct ice_pkg_enum state;
3365 /* if the HW segment pointer is null then the first iteration of
3366 * ice_pkg_enum_section() will fail. In this case the HW tables will
3367 * not be filled and return success.
3370 ice_debug(hw, ICE_DBG_PKG, "hw->seg is NULL, tables are not filled\n");
3374 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
3376 sect = ice_pkg_enum_section(hw->seg, &state, sid);
3380 case ICE_SID_XLT1_SW:
3381 case ICE_SID_XLT1_FD:
3382 case ICE_SID_XLT1_RSS:
3383 case ICE_SID_XLT1_ACL:
3384 case ICE_SID_XLT1_PE:
3385 xlt1 = (struct ice_xlt1_section *)sect;
3387 sect_len = LE16_TO_CPU(xlt1->count) *
3388 sizeof(*hw->blk[block_id].xlt1.t);
3389 dst = hw->blk[block_id].xlt1.t;
3390 dst_len = hw->blk[block_id].xlt1.count *
3391 sizeof(*hw->blk[block_id].xlt1.t);
3393 case ICE_SID_XLT2_SW:
3394 case ICE_SID_XLT2_FD:
3395 case ICE_SID_XLT2_RSS:
3396 case ICE_SID_XLT2_ACL:
3397 case ICE_SID_XLT2_PE:
3398 xlt2 = (struct ice_xlt2_section *)sect;
3399 src = (_FORCE_ u8 *)xlt2->value;
3400 sect_len = LE16_TO_CPU(xlt2->count) *
3401 sizeof(*hw->blk[block_id].xlt2.t);
3402 dst = (u8 *)hw->blk[block_id].xlt2.t;
3403 dst_len = hw->blk[block_id].xlt2.count *
3404 sizeof(*hw->blk[block_id].xlt2.t);
3406 case ICE_SID_PROFID_TCAM_SW:
3407 case ICE_SID_PROFID_TCAM_FD:
3408 case ICE_SID_PROFID_TCAM_RSS:
3409 case ICE_SID_PROFID_TCAM_ACL:
3410 case ICE_SID_PROFID_TCAM_PE:
3411 pid = (struct ice_prof_id_section *)sect;
3412 src = (u8 *)pid->entry;
3413 sect_len = LE16_TO_CPU(pid->count) *
3414 sizeof(*hw->blk[block_id].prof.t);
3415 dst = (u8 *)hw->blk[block_id].prof.t;
3416 dst_len = hw->blk[block_id].prof.count *
3417 sizeof(*hw->blk[block_id].prof.t);
3419 case ICE_SID_PROFID_REDIR_SW:
3420 case ICE_SID_PROFID_REDIR_FD:
3421 case ICE_SID_PROFID_REDIR_RSS:
3422 case ICE_SID_PROFID_REDIR_ACL:
3423 case ICE_SID_PROFID_REDIR_PE:
3424 pr = (struct ice_prof_redir_section *)sect;
3425 src = pr->redir_value;
3426 sect_len = LE16_TO_CPU(pr->count) *
3427 sizeof(*hw->blk[block_id].prof_redir.t);
3428 dst = hw->blk[block_id].prof_redir.t;
3429 dst_len = hw->blk[block_id].prof_redir.count *
3430 sizeof(*hw->blk[block_id].prof_redir.t);
3432 case ICE_SID_FLD_VEC_SW:
3433 case ICE_SID_FLD_VEC_FD:
3434 case ICE_SID_FLD_VEC_RSS:
3435 case ICE_SID_FLD_VEC_ACL:
3436 case ICE_SID_FLD_VEC_PE:
3437 es = (struct ice_sw_fv_section *)sect;
3439 sect_len = (u32)(LE16_TO_CPU(es->count) *
3440 hw->blk[block_id].es.fvw) *
3441 sizeof(*hw->blk[block_id].es.t);
3442 dst = (u8 *)hw->blk[block_id].es.t;
3443 dst_len = (u32)(hw->blk[block_id].es.count *
3444 hw->blk[block_id].es.fvw) *
3445 sizeof(*hw->blk[block_id].es.t);
3451 /* if the section offset exceeds destination length, terminate
3454 if (offset > dst_len)
3457 /* if the sum of section size and offset exceed destination size
3458 * then we are out of bounds of the HW table size for that PF.
3459 * Changing section length to fill the remaining table space
3462 if ((offset + sect_len) > dst_len)
3463 sect_len = dst_len - offset;
3465 ice_memcpy(dst + offset, src, sect_len, ICE_NONDMA_TO_NONDMA);
3467 sect = ice_pkg_enum_section(NULL, &state, sid);
3472 * ice_fill_blk_tbls - Read package context for tables
3473 * @hw: pointer to the hardware structure
3475 * Reads the current package contents and populates the driver
3476 * database with the data iteratively for all advanced feature
3477 * blocks. Assume that the HW tables have been allocated.
3479 void ice_fill_blk_tbls(struct ice_hw *hw)
3483 for (i = 0; i < ICE_BLK_COUNT; i++) {
3484 enum ice_block blk_id = (enum ice_block)i;
3486 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].xlt1.sid);
3487 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].xlt2.sid);
3488 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].prof.sid);
3489 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].prof_redir.sid);
3490 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].es.sid);
3497 * ice_free_prof_map - free profile map
3498 * @hw: pointer to the hardware structure
3499 * @blk_idx: HW block index
3501 static void ice_free_prof_map(struct ice_hw *hw, u8 blk_idx)
3503 struct ice_es *es = &hw->blk[blk_idx].es;
3504 struct ice_prof_map *del, *tmp;
3506 ice_acquire_lock(&es->prof_map_lock);
3507 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &es->prof_map,
3508 ice_prof_map, list) {
3509 LIST_DEL(&del->list);
3512 INIT_LIST_HEAD(&es->prof_map);
3513 ice_release_lock(&es->prof_map_lock);
3517 * ice_free_flow_profs - free flow profile entries
3518 * @hw: pointer to the hardware structure
3519 * @blk_idx: HW block index
3521 static void ice_free_flow_profs(struct ice_hw *hw, u8 blk_idx)
3523 struct ice_flow_prof *p, *tmp;
3525 ice_acquire_lock(&hw->fl_profs_locks[blk_idx]);
3526 LIST_FOR_EACH_ENTRY_SAFE(p, tmp, &hw->fl_profs[blk_idx],
3527 ice_flow_prof, l_entry) {
3528 struct ice_flow_entry *e, *t;
3530 LIST_FOR_EACH_ENTRY_SAFE(e, t, &p->entries,
3531 ice_flow_entry, l_entry)
3532 ice_flow_rem_entry(hw, ICE_FLOW_ENTRY_HNDL(e));
3534 LIST_DEL(&p->l_entry);
3536 ice_free(hw, p->acts);
3539 ice_release_lock(&hw->fl_profs_locks[blk_idx]);
3541 /* if driver is in reset and tables are being cleared
3542 * re-initialize the flow profile list heads
3544 INIT_LIST_HEAD(&hw->fl_profs[blk_idx]);
3548 * ice_free_vsig_tbl - free complete VSIG table entries
3549 * @hw: pointer to the hardware structure
3550 * @blk: the HW block on which to free the VSIG table entries
3552 static void ice_free_vsig_tbl(struct ice_hw *hw, enum ice_block blk)
3556 if (!hw->blk[blk].xlt2.vsig_tbl)
3559 for (i = 1; i < ICE_MAX_VSIGS; i++)
3560 if (hw->blk[blk].xlt2.vsig_tbl[i].in_use)
3561 ice_vsig_free(hw, blk, i);
3565 * ice_free_hw_tbls - free hardware table memory
3566 * @hw: pointer to the hardware structure
3568 void ice_free_hw_tbls(struct ice_hw *hw)
3570 struct ice_rss_cfg *r, *rt;
3573 for (i = 0; i < ICE_BLK_COUNT; i++) {
3574 if (hw->blk[i].is_list_init) {
3575 struct ice_es *es = &hw->blk[i].es;
3577 ice_free_prof_map(hw, i);
3578 ice_destroy_lock(&es->prof_map_lock);
3579 ice_free_flow_profs(hw, i);
3580 ice_destroy_lock(&hw->fl_profs_locks[i]);
3582 hw->blk[i].is_list_init = false;
3584 ice_free_vsig_tbl(hw, (enum ice_block)i);
3585 ice_free(hw, hw->blk[i].xlt1.ptypes);
3586 ice_free(hw, hw->blk[i].xlt1.ptg_tbl);
3587 ice_free(hw, hw->blk[i].xlt1.t);
3588 ice_free(hw, hw->blk[i].xlt2.t);
3589 ice_free(hw, hw->blk[i].xlt2.vsig_tbl);
3590 ice_free(hw, hw->blk[i].xlt2.vsis);
3591 ice_free(hw, hw->blk[i].prof.t);
3592 ice_free(hw, hw->blk[i].prof_redir.t);
3593 ice_free(hw, hw->blk[i].es.t);
3594 ice_free(hw, hw->blk[i].es.ref_count);
3595 ice_free(hw, hw->blk[i].es.written);
3596 ice_free(hw, hw->blk[i].es.mask_ena);
3599 LIST_FOR_EACH_ENTRY_SAFE(r, rt, &hw->rss_list_head,
3600 ice_rss_cfg, l_entry) {
3601 LIST_DEL(&r->l_entry);
3604 ice_destroy_lock(&hw->rss_locks);
3605 ice_shutdown_all_prof_masks(hw);
3606 ice_memset(hw->blk, 0, sizeof(hw->blk), ICE_NONDMA_MEM);
3610 * ice_init_flow_profs - init flow profile locks and list heads
3611 * @hw: pointer to the hardware structure
3612 * @blk_idx: HW block index
3614 static void ice_init_flow_profs(struct ice_hw *hw, u8 blk_idx)
3616 ice_init_lock(&hw->fl_profs_locks[blk_idx]);
3617 INIT_LIST_HEAD(&hw->fl_profs[blk_idx]);
3621 * ice_init_hw_tbls - init hardware table memory
3622 * @hw: pointer to the hardware structure
3624 enum ice_status ice_init_hw_tbls(struct ice_hw *hw)
3628 ice_init_lock(&hw->rss_locks);
3629 INIT_LIST_HEAD(&hw->rss_list_head);
3630 ice_init_all_prof_masks(hw);
3631 for (i = 0; i < ICE_BLK_COUNT; i++) {
3632 struct ice_prof_redir *prof_redir = &hw->blk[i].prof_redir;
3633 struct ice_prof_tcam *prof = &hw->blk[i].prof;
3634 struct ice_xlt1 *xlt1 = &hw->blk[i].xlt1;
3635 struct ice_xlt2 *xlt2 = &hw->blk[i].xlt2;
3636 struct ice_es *es = &hw->blk[i].es;
3639 if (hw->blk[i].is_list_init)
3642 ice_init_flow_profs(hw, i);
3643 ice_init_lock(&es->prof_map_lock);
3644 INIT_LIST_HEAD(&es->prof_map);
3645 hw->blk[i].is_list_init = true;
3647 hw->blk[i].overwrite = blk_sizes[i].overwrite;
3648 es->reverse = blk_sizes[i].reverse;
3650 xlt1->sid = ice_blk_sids[i][ICE_SID_XLT1_OFF];
3651 xlt1->count = blk_sizes[i].xlt1;
3653 xlt1->ptypes = (struct ice_ptg_ptype *)
3654 ice_calloc(hw, xlt1->count, sizeof(*xlt1->ptypes));
3659 xlt1->ptg_tbl = (struct ice_ptg_entry *)
3660 ice_calloc(hw, ICE_MAX_PTGS, sizeof(*xlt1->ptg_tbl));
3665 xlt1->t = (u8 *)ice_calloc(hw, xlt1->count, sizeof(*xlt1->t));
3669 xlt2->sid = ice_blk_sids[i][ICE_SID_XLT2_OFF];
3670 xlt2->count = blk_sizes[i].xlt2;
3672 xlt2->vsis = (struct ice_vsig_vsi *)
3673 ice_calloc(hw, xlt2->count, sizeof(*xlt2->vsis));
3678 xlt2->vsig_tbl = (struct ice_vsig_entry *)
3679 ice_calloc(hw, xlt2->count, sizeof(*xlt2->vsig_tbl));
3680 if (!xlt2->vsig_tbl)
3683 for (j = 0; j < xlt2->count; j++)
3684 INIT_LIST_HEAD(&xlt2->vsig_tbl[j].prop_lst);
3686 xlt2->t = (u16 *)ice_calloc(hw, xlt2->count, sizeof(*xlt2->t));
3690 prof->sid = ice_blk_sids[i][ICE_SID_PR_OFF];
3691 prof->count = blk_sizes[i].prof_tcam;
3692 prof->max_prof_id = blk_sizes[i].prof_id;
3693 prof->cdid_bits = blk_sizes[i].prof_cdid_bits;
3694 prof->t = (struct ice_prof_tcam_entry *)
3695 ice_calloc(hw, prof->count, sizeof(*prof->t));
3700 prof_redir->sid = ice_blk_sids[i][ICE_SID_PR_REDIR_OFF];
3701 prof_redir->count = blk_sizes[i].prof_redir;
3702 prof_redir->t = (u8 *)ice_calloc(hw, prof_redir->count,
3703 sizeof(*prof_redir->t));
3708 es->sid = ice_blk_sids[i][ICE_SID_ES_OFF];
3709 es->count = blk_sizes[i].es;
3710 es->fvw = blk_sizes[i].fvw;
3711 es->t = (struct ice_fv_word *)
3712 ice_calloc(hw, (u32)(es->count * es->fvw),
3717 es->ref_count = (u16 *)
3718 ice_calloc(hw, es->count, sizeof(*es->ref_count));
3720 es->written = (u8 *)
3721 ice_calloc(hw, es->count, sizeof(*es->written));
3722 es->mask_ena = (u32 *)
3723 ice_calloc(hw, es->count, sizeof(*es->mask_ena));
3730 ice_free_hw_tbls(hw);
3731 return ICE_ERR_NO_MEMORY;
3735 * ice_prof_gen_key - generate profile ID key
3736 * @hw: pointer to the HW struct
3737 * @blk: the block in which to write profile ID to
3738 * @ptg: packet type group (PTG) portion of key
3739 * @vsig: VSIG portion of key
3740 * @cdid: cdid portion of key
3741 * @flags: flag portion of key
3742 * @vl_msk: valid mask
3743 * @dc_msk: don't care mask
3744 * @nm_msk: never match mask
3745 * @key: output of profile ID key
3747 static enum ice_status
3748 ice_prof_gen_key(struct ice_hw *hw, enum ice_block blk, u8 ptg, u16 vsig,
3749 u8 cdid, u16 flags, u8 vl_msk[ICE_TCAM_KEY_VAL_SZ],
3750 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ], u8 nm_msk[ICE_TCAM_KEY_VAL_SZ],
3751 u8 key[ICE_TCAM_KEY_SZ])
3753 struct ice_prof_id_key inkey;
3756 inkey.xlt2_cdid = CPU_TO_LE16(vsig);
3757 inkey.flags = CPU_TO_LE16(flags);
3759 switch (hw->blk[blk].prof.cdid_bits) {
3763 #define ICE_CD_2_M 0xC000U
3764 #define ICE_CD_2_S 14
3765 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_2_M);
3766 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_2_S);
3769 #define ICE_CD_4_M 0xF000U
3770 #define ICE_CD_4_S 12
3771 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_4_M);
3772 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_4_S);
3775 #define ICE_CD_8_M 0xFF00U
3776 #define ICE_CD_8_S 16
3777 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_8_M);
3778 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_8_S);
3781 ice_debug(hw, ICE_DBG_PKG, "Error in profile config\n");
3785 return ice_set_key(key, ICE_TCAM_KEY_SZ, (u8 *)&inkey, vl_msk, dc_msk,
3786 nm_msk, 0, ICE_TCAM_KEY_SZ / 2);
3790 * ice_tcam_write_entry - write TCAM entry
3791 * @hw: pointer to the HW struct
3792 * @blk: the block in which to write profile ID to
3793 * @idx: the entry index to write to
3794 * @prof_id: profile ID
3795 * @ptg: packet type group (PTG) portion of key
3796 * @vsig: VSIG portion of key
3797 * @cdid: cdid portion of key
3798 * @flags: flag portion of key
3799 * @vl_msk: valid mask
3800 * @dc_msk: don't care mask
3801 * @nm_msk: never match mask
3803 static enum ice_status
3804 ice_tcam_write_entry(struct ice_hw *hw, enum ice_block blk, u16 idx,
3805 u8 prof_id, u8 ptg, u16 vsig, u8 cdid, u16 flags,
3806 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ],
3807 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ],
3808 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ])
3810 struct ice_prof_tcam_entry;
3811 enum ice_status status;
3813 status = ice_prof_gen_key(hw, blk, ptg, vsig, cdid, flags, vl_msk,
3814 dc_msk, nm_msk, hw->blk[blk].prof.t[idx].key);
3816 hw->blk[blk].prof.t[idx].addr = CPU_TO_LE16(idx);
3817 hw->blk[blk].prof.t[idx].prof_id = prof_id;
3824 * ice_vsig_get_ref - returns number of VSIs belong to a VSIG
3825 * @hw: pointer to the hardware structure
3827 * @vsig: VSIG to query
3828 * @refs: pointer to variable to receive the reference count
3830 static enum ice_status
3831 ice_vsig_get_ref(struct ice_hw *hw, enum ice_block blk, u16 vsig, u16 *refs)
3833 u16 idx = vsig & ICE_VSIG_IDX_M;
3834 struct ice_vsig_vsi *ptr;
3837 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
3838 return ICE_ERR_DOES_NOT_EXIST;
3840 ptr = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
3843 ptr = ptr->next_vsi;
3850 * ice_has_prof_vsig - check to see if VSIG has a specific profile
3851 * @hw: pointer to the hardware structure
3853 * @vsig: VSIG to check against
3854 * @hdl: profile handle
3857 ice_has_prof_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl)
3859 u16 idx = vsig & ICE_VSIG_IDX_M;
3860 struct ice_vsig_prof *ent;
3862 LIST_FOR_EACH_ENTRY(ent, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
3863 ice_vsig_prof, list) {
3864 if (ent->profile_cookie == hdl)
3868 ice_debug(hw, ICE_DBG_INIT,
3869 "Characteristic list for VSI group %d not found.\n",
3875 * ice_prof_bld_es - build profile ID extraction sequence changes
3876 * @hw: pointer to the HW struct
3877 * @blk: hardware block
3878 * @bld: the update package buffer build to add to
3879 * @chgs: the list of changes to make in hardware
3881 static enum ice_status
3882 ice_prof_bld_es(struct ice_hw *hw, enum ice_block blk,
3883 struct ice_buf_build *bld, struct LIST_HEAD_TYPE *chgs)
3885 u16 vec_size = hw->blk[blk].es.fvw * sizeof(struct ice_fv_word);
3886 struct ice_chs_chg *tmp;
3888 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
3889 if (tmp->type == ICE_PTG_ES_ADD && tmp->add_prof) {
3890 u16 off = tmp->prof_id * hw->blk[blk].es.fvw;
3891 struct ice_pkg_es *p;
3894 id = ice_sect_id(blk, ICE_VEC_TBL);
3895 p = (struct ice_pkg_es *)
3896 ice_pkg_buf_alloc_section(bld, id, sizeof(*p) +
3901 return ICE_ERR_MAX_LIMIT;
3903 p->count = CPU_TO_LE16(1);
3904 p->offset = CPU_TO_LE16(tmp->prof_id);
3906 ice_memcpy(p->es, &hw->blk[blk].es.t[off], vec_size,
3907 ICE_NONDMA_TO_NONDMA);
3915 * ice_prof_bld_tcam - build profile ID TCAM changes
3916 * @hw: pointer to the HW struct
3917 * @blk: hardware block
3918 * @bld: the update package buffer build to add to
3919 * @chgs: the list of changes to make in hardware
3921 static enum ice_status
3922 ice_prof_bld_tcam(struct ice_hw *hw, enum ice_block blk,
3923 struct ice_buf_build *bld, struct LIST_HEAD_TYPE *chgs)
3925 struct ice_chs_chg *tmp;
3927 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
3928 if (tmp->type == ICE_TCAM_ADD && tmp->add_tcam_idx) {
3929 struct ice_prof_id_section *p;
3932 id = ice_sect_id(blk, ICE_PROF_TCAM);
3933 p = (struct ice_prof_id_section *)
3934 ice_pkg_buf_alloc_section(bld, id, sizeof(*p));
3937 return ICE_ERR_MAX_LIMIT;
3939 p->count = CPU_TO_LE16(1);
3940 p->entry[0].addr = CPU_TO_LE16(tmp->tcam_idx);
3941 p->entry[0].prof_id = tmp->prof_id;
3943 ice_memcpy(p->entry[0].key,
3944 &hw->blk[blk].prof.t[tmp->tcam_idx].key,
3945 sizeof(hw->blk[blk].prof.t->key),
3946 ICE_NONDMA_TO_NONDMA);
3954 * ice_prof_bld_xlt1 - build XLT1 changes
3955 * @blk: hardware block
3956 * @bld: the update package buffer build to add to
3957 * @chgs: the list of changes to make in hardware
3959 static enum ice_status
3960 ice_prof_bld_xlt1(enum ice_block blk, struct ice_buf_build *bld,
3961 struct LIST_HEAD_TYPE *chgs)
3963 struct ice_chs_chg *tmp;
3965 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
3966 if (tmp->type == ICE_PTG_ES_ADD && tmp->add_ptg) {
3967 struct ice_xlt1_section *p;
3970 id = ice_sect_id(blk, ICE_XLT1);
3971 p = (struct ice_xlt1_section *)
3972 ice_pkg_buf_alloc_section(bld, id, sizeof(*p));
3975 return ICE_ERR_MAX_LIMIT;
3977 p->count = CPU_TO_LE16(1);
3978 p->offset = CPU_TO_LE16(tmp->ptype);
3979 p->value[0] = tmp->ptg;
3987 * ice_prof_bld_xlt2 - build XLT2 changes
3988 * @blk: hardware block
3989 * @bld: the update package buffer build to add to
3990 * @chgs: the list of changes to make in hardware
3992 static enum ice_status
3993 ice_prof_bld_xlt2(enum ice_block blk, struct ice_buf_build *bld,
3994 struct LIST_HEAD_TYPE *chgs)
3996 struct ice_chs_chg *tmp;
3998 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
4001 if (tmp->type == ICE_VSIG_ADD)
4003 else if (tmp->type == ICE_VSI_MOVE)
4005 else if (tmp->type == ICE_VSIG_REM)
4009 struct ice_xlt2_section *p;
4012 id = ice_sect_id(blk, ICE_XLT2);
4013 p = (struct ice_xlt2_section *)
4014 ice_pkg_buf_alloc_section(bld, id, sizeof(*p));
4017 return ICE_ERR_MAX_LIMIT;
4019 p->count = CPU_TO_LE16(1);
4020 p->offset = CPU_TO_LE16(tmp->vsi);
4021 p->value[0] = CPU_TO_LE16(tmp->vsig);
4029 * ice_upd_prof_hw - update hardware using the change list
4030 * @hw: pointer to the HW struct
4031 * @blk: hardware block
4032 * @chgs: the list of changes to make in hardware
4034 static enum ice_status
4035 ice_upd_prof_hw(struct ice_hw *hw, enum ice_block blk,
4036 struct LIST_HEAD_TYPE *chgs)
4038 struct ice_buf_build *b;
4039 struct ice_chs_chg *tmp;
4040 enum ice_status status;
4048 /* count number of sections we need */
4049 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
4050 switch (tmp->type) {
4051 case ICE_PTG_ES_ADD:
4069 sects = xlt1 + xlt2 + tcam + es;
4074 /* Build update package buffer */
4075 b = ice_pkg_buf_alloc(hw);
4077 return ICE_ERR_NO_MEMORY;
4079 status = ice_pkg_buf_reserve_section(b, sects);
4083 /* Preserve order of table update: ES, TCAM, PTG, VSIG */
4085 status = ice_prof_bld_es(hw, blk, b, chgs);
4091 status = ice_prof_bld_tcam(hw, blk, b, chgs);
4097 status = ice_prof_bld_xlt1(blk, b, chgs);
4103 status = ice_prof_bld_xlt2(blk, b, chgs);
4108 /* After package buffer build check if the section count in buffer is
4109 * non-zero and matches the number of sections detected for package
4112 pkg_sects = ice_pkg_buf_get_active_sections(b);
4113 if (!pkg_sects || pkg_sects != sects) {
4114 status = ICE_ERR_INVAL_SIZE;
4118 /* update package */
4119 status = ice_update_pkg(hw, ice_pkg_buf(b), 1);
4120 if (status == ICE_ERR_AQ_ERROR)
4121 ice_debug(hw, ICE_DBG_INIT, "Unable to update HW profile.");
4124 ice_pkg_buf_free(hw, b);
4129 * ice_update_fd_mask - set Flow Director Field Vector mask for a profile
4130 * @hw: pointer to the HW struct
4131 * @prof_id: profile ID
4132 * @mask_sel: mask select
4134 * This function enable any of the masks selected by the mask select parameter
4135 * for the profile specified.
4137 static void ice_update_fd_mask(struct ice_hw *hw, u16 prof_id, u32 mask_sel)
4139 wr32(hw, GLQF_FDMASK_SEL(prof_id), mask_sel);
4141 ice_debug(hw, ICE_DBG_INIT, "fd mask(%d): %x = %x\n", prof_id,
4142 GLQF_FDMASK_SEL(prof_id), mask_sel);
4145 #define ICE_SRC_DST_MAX_COUNT 8
4147 struct ice_fd_src_dst_pair {
4153 static const struct ice_fd_src_dst_pair ice_fd_pairs[] = {
4154 /* These are defined in pairs */
4155 { ICE_PROT_IPV4_OF_OR_S, 2, 12 },
4156 { ICE_PROT_IPV4_OF_OR_S, 2, 16 },
4158 { ICE_PROT_IPV4_IL, 2, 12 },
4159 { ICE_PROT_IPV4_IL, 2, 16 },
4161 { ICE_PROT_IPV6_OF_OR_S, 8, 8 },
4162 { ICE_PROT_IPV6_OF_OR_S, 8, 24 },
4164 { ICE_PROT_IPV6_IL, 8, 8 },
4165 { ICE_PROT_IPV6_IL, 8, 24 },
4167 { ICE_PROT_TCP_IL, 1, 0 },
4168 { ICE_PROT_TCP_IL, 1, 2 },
4170 { ICE_PROT_UDP_OF, 1, 0 },
4171 { ICE_PROT_UDP_OF, 1, 2 },
4173 { ICE_PROT_UDP_IL_OR_S, 1, 0 },
4174 { ICE_PROT_UDP_IL_OR_S, 1, 2 },
4176 { ICE_PROT_SCTP_IL, 1, 0 },
4177 { ICE_PROT_SCTP_IL, 1, 2 }
4180 #define ICE_FD_SRC_DST_PAIR_COUNT ARRAY_SIZE(ice_fd_pairs)
4183 * ice_update_fd_swap - set register appropriately for a FD FV extraction
4184 * @hw: pointer to the HW struct
4185 * @prof_id: profile ID
4186 * @es: extraction sequence (length of array is determined by the block)
4188 static enum ice_status
4189 ice_update_fd_swap(struct ice_hw *hw, u16 prof_id, struct ice_fv_word *es)
4191 ice_declare_bitmap(pair_list, ICE_FD_SRC_DST_PAIR_COUNT);
4192 u8 pair_start[ICE_FD_SRC_DST_PAIR_COUNT] = { 0 };
4193 #define ICE_FD_FV_NOT_FOUND (-2)
4194 s8 first_free = ICE_FD_FV_NOT_FOUND;
4195 u8 used[ICE_MAX_FV_WORDS] = { 0 };
4200 ice_zero_bitmap(pair_list, ICE_FD_SRC_DST_PAIR_COUNT);
4202 /* This code assumes that the Flow Director field vectors are assigned
4203 * from the end of the FV indexes working towards the zero index, that
4204 * only complete fields will be included and will be consecutive, and
4205 * that there are no gaps between valid indexes.
4208 /* Determine swap fields present */
4209 for (i = 0; i < hw->blk[ICE_BLK_FD].es.fvw; i++) {
4210 /* Find the first free entry, assuming right to left population.
4211 * This is where we can start adding additional pairs if needed.
4213 if (first_free == ICE_FD_FV_NOT_FOUND && es[i].prot_id !=
4217 for (j = 0; j < ICE_FD_SRC_DST_PAIR_COUNT; j++) {
4218 if (es[i].prot_id == ice_fd_pairs[j].prot_id &&
4219 es[i].off == ice_fd_pairs[j].off) {
4220 ice_set_bit(j, pair_list);
4226 orig_free = first_free;
4228 /* determine missing swap fields that need to be added */
4229 for (i = 0; i < ICE_FD_SRC_DST_PAIR_COUNT; i += 2) {
4230 u8 bit1 = ice_is_bit_set(pair_list, i + 1);
4231 u8 bit0 = ice_is_bit_set(pair_list, i);
4236 /* add the appropriate 'paired' entry */
4242 /* check for room */
4243 if (first_free + 1 < (s8)ice_fd_pairs[index].count)
4244 return ICE_ERR_MAX_LIMIT;
4246 /* place in extraction sequence */
4247 for (k = 0; k < ice_fd_pairs[index].count; k++) {
4248 es[first_free - k].prot_id =
4249 ice_fd_pairs[index].prot_id;
4250 es[first_free - k].off =
4251 ice_fd_pairs[index].off + (k * 2);
4254 return ICE_ERR_OUT_OF_RANGE;
4256 /* keep track of non-relevant fields */
4257 mask_sel |= BIT(first_free - k);
4260 pair_start[index] = first_free;
4261 first_free -= ice_fd_pairs[index].count;
4265 /* fill in the swap array */
4266 si = hw->blk[ICE_BLK_FD].es.fvw - 1;
4268 u8 indexes_used = 1;
4270 /* assume flat at this index */
4271 #define ICE_SWAP_VALID 0x80
4272 used[si] = si | ICE_SWAP_VALID;
4274 if (orig_free == ICE_FD_FV_NOT_FOUND || si <= orig_free) {
4279 /* check for a swap location */
4280 for (j = 0; j < ICE_FD_SRC_DST_PAIR_COUNT; j++) {
4281 if (es[si].prot_id == ice_fd_pairs[j].prot_id &&
4282 es[si].off == ice_fd_pairs[j].off) {
4285 /* determine the appropriate matching field */
4286 idx = j + ((j % 2) ? -1 : 1);
4288 indexes_used = ice_fd_pairs[idx].count;
4289 for (k = 0; k < indexes_used; k++) {
4290 used[si - k] = (pair_start[idx] - k) |
4301 /* for each set of 4 swap and 4 inset indexes, write the appropriate
4304 for (j = 0; j < hw->blk[ICE_BLK_FD].es.fvw / 4; j++) {
4308 for (k = 0; k < 4; k++) {
4312 if (used[idx] && !(mask_sel & BIT(idx))) {
4313 raw_swap |= used[idx] << (k * BITS_PER_BYTE);
4314 #define ICE_INSET_DFLT 0x9f
4315 raw_in |= ICE_INSET_DFLT << (k * BITS_PER_BYTE);
4319 /* write the appropriate swap register set */
4320 wr32(hw, GLQF_FDSWAP(prof_id, j), raw_swap);
4322 ice_debug(hw, ICE_DBG_INIT, "swap wr(%d, %d): %x = %08x\n",
4323 prof_id, j, GLQF_FDSWAP(prof_id, j), raw_swap);
4325 /* write the appropriate inset register set */
4326 wr32(hw, GLQF_FDINSET(prof_id, j), raw_in);
4328 ice_debug(hw, ICE_DBG_INIT, "inset wr(%d, %d): %x = %08x\n",
4329 prof_id, j, GLQF_FDINSET(prof_id, j), raw_in);
4332 /* initially clear the mask select for this profile */
4333 ice_update_fd_mask(hw, prof_id, 0);
4338 /* The entries here needs to match the order of enum ice_ptype_attrib */
4339 static const struct ice_ptype_attrib_info ice_ptype_attributes[] = {
4340 { ICE_GTP_PDU_EH, ICE_GTP_PDU_FLAG_MASK },
4341 { ICE_GTP_SESSION, ICE_GTP_FLAGS_MASK },
4342 { ICE_GTP_DOWNLINK, ICE_GTP_FLAGS_MASK },
4343 { ICE_GTP_UPLINK, ICE_GTP_FLAGS_MASK },
4347 * ice_get_ptype_attrib_info - get ptype attribute information
4348 * @type: attribute type
4349 * @info: pointer to variable to the attribute information
4352 ice_get_ptype_attrib_info(enum ice_ptype_attrib_type type,
4353 struct ice_ptype_attrib_info *info)
4355 *info = ice_ptype_attributes[type];
4359 * ice_add_prof_attrib - add any ptg with attributes to profile
4360 * @prof: pointer to the profile to which ptg entries will be added
4361 * @ptg: PTG to be added
4362 * @ptype: PTYPE that needs to be looked up
4363 * @attr: array of attributes that will be considered
4364 * @attr_cnt: number of elements in the attribute array
4366 static enum ice_status
4367 ice_add_prof_attrib(struct ice_prof_map *prof, u8 ptg, u16 ptype,
4368 const struct ice_ptype_attributes *attr, u16 attr_cnt)
4373 for (i = 0; i < attr_cnt; i++) {
4374 if (attr[i].ptype == ptype) {
4377 prof->ptg[prof->ptg_cnt] = ptg;
4378 ice_get_ptype_attrib_info(attr[i].attrib,
4379 &prof->attr[prof->ptg_cnt]);
4381 if (++prof->ptg_cnt >= ICE_MAX_PTG_PER_PROFILE)
4382 return ICE_ERR_MAX_LIMIT;
4387 return ICE_ERR_DOES_NOT_EXIST;
4393 * ice_add_prof - add profile
4394 * @hw: pointer to the HW struct
4395 * @blk: hardware block
4396 * @id: profile tracking ID
4397 * @ptypes: array of bitmaps indicating ptypes (ICE_FLOW_PTYPE_MAX bits)
4398 * @attr: array of attributes
4399 * @attr_cnt: number of elements in attrib array
4400 * @es: extraction sequence (length of array is determined by the block)
4401 * @masks: mask for extraction sequence
4403 * This function registers a profile, which matches a set of PTYPES with a
4404 * particular extraction sequence. While the hardware profile is allocated
4405 * it will not be written until the first call to ice_add_flow that specifies
4406 * the ID value used here.
4409 ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64 id, u8 ptypes[],
4410 const struct ice_ptype_attributes *attr, u16 attr_cnt,
4411 struct ice_fv_word *es, u16 *masks)
4413 u32 bytes = DIVIDE_AND_ROUND_UP(ICE_FLOW_PTYPE_MAX, BITS_PER_BYTE);
4414 ice_declare_bitmap(ptgs_used, ICE_XLT1_CNT);
4415 struct ice_prof_map *prof;
4416 enum ice_status status;
4420 ice_zero_bitmap(ptgs_used, ICE_XLT1_CNT);
4422 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
4424 /* search for existing profile */
4425 status = ice_find_prof_id_with_mask(hw, blk, es, masks, &prof_id);
4427 /* allocate profile ID */
4428 status = ice_alloc_prof_id(hw, blk, &prof_id);
4430 goto err_ice_add_prof;
4431 if (blk == ICE_BLK_FD) {
4432 /* For Flow Director block, the extraction sequence may
4433 * need to be altered in the case where there are paired
4434 * fields that have no match. This is necessary because
4435 * for Flow Director, src and dest fields need to paired
4436 * for filter programming and these values are swapped
4439 status = ice_update_fd_swap(hw, prof_id, es);
4441 goto err_ice_add_prof;
4443 status = ice_update_prof_masking(hw, blk, prof_id, es, masks);
4445 goto err_ice_add_prof;
4447 /* and write new es */
4448 ice_write_es(hw, blk, prof_id, es);
4451 ice_prof_inc_ref(hw, blk, prof_id);
4453 /* add profile info */
4455 prof = (struct ice_prof_map *)ice_malloc(hw, sizeof(*prof));
4457 goto err_ice_add_prof;
4459 prof->profile_cookie = id;
4460 prof->prof_id = prof_id;
4464 /* build list of ptgs */
4465 while (bytes && prof->ptg_cnt < ICE_MAX_PTG_PER_PROFILE) {
4468 if (!ptypes[byte]) {
4473 /* Examine 8 bits per byte */
4474 for (bit = 0; bit < 8; bit++) {
4475 if (ptypes[byte] & BIT(bit)) {
4480 ptype = byte * BITS_PER_BYTE + bit;
4482 /* The package should place all ptypes in a
4483 * non-zero PTG, so the following call should
4486 if (ice_ptg_find_ptype(hw, blk, ptype, &ptg))
4489 /* If PTG is already added, skip and continue */
4490 if (ice_is_bit_set(ptgs_used, ptg))
4493 ice_set_bit(ptg, ptgs_used);
4494 /* Check to see there are any attributes for
4495 * this ptype, and add them if found.
4497 status = ice_add_prof_attrib(prof, ptg, ptype,
4499 if (status == ICE_ERR_MAX_LIMIT)
4502 /* This is simple a ptype/ptg with no
4505 prof->ptg[prof->ptg_cnt] = ptg;
4506 prof->attr[prof->ptg_cnt].flags = 0;
4507 prof->attr[prof->ptg_cnt].mask = 0;
4509 if (++prof->ptg_cnt >=
4510 ICE_MAX_PTG_PER_PROFILE)
4514 /* nothing left in byte, then exit */
4515 m = ~((1 << (bit + 1)) - 1);
4516 if (!(ptypes[byte] & m))
4525 LIST_ADD(&prof->list, &hw->blk[blk].es.prof_map);
4526 status = ICE_SUCCESS;
4529 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
4534 * ice_search_prof_id_low - Search for a profile tracking ID low level
4535 * @hw: pointer to the HW struct
4536 * @blk: hardware block
4537 * @id: profile tracking ID
4539 * This will search for a profile tracking ID which was previously added. This
4540 * version assumes that the caller has already acquired the prof map lock.
4542 static struct ice_prof_map *
4543 ice_search_prof_id_low(struct ice_hw *hw, enum ice_block blk, u64 id)
4545 struct ice_prof_map *entry = NULL;
4546 struct ice_prof_map *map;
4548 LIST_FOR_EACH_ENTRY(map, &hw->blk[blk].es.prof_map, ice_prof_map,
4550 if (map->profile_cookie == id) {
4560 * ice_search_prof_id - Search for a profile tracking ID
4561 * @hw: pointer to the HW struct
4562 * @blk: hardware block
4563 * @id: profile tracking ID
4565 * This will search for a profile tracking ID which was previously added.
4567 struct ice_prof_map *
4568 ice_search_prof_id(struct ice_hw *hw, enum ice_block blk, u64 id)
4570 struct ice_prof_map *entry;
4572 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
4573 entry = ice_search_prof_id_low(hw, blk, id);
4574 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
4580 * ice_vsig_prof_id_count - count profiles in a VSIG
4581 * @hw: pointer to the HW struct
4582 * @blk: hardware block
4583 * @vsig: VSIG to remove the profile from
4586 ice_vsig_prof_id_count(struct ice_hw *hw, enum ice_block blk, u16 vsig)
4588 u16 idx = vsig & ICE_VSIG_IDX_M, count = 0;
4589 struct ice_vsig_prof *p;
4591 LIST_FOR_EACH_ENTRY(p, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4592 ice_vsig_prof, list) {
4600 * ice_rel_tcam_idx - release a TCAM index
4601 * @hw: pointer to the HW struct
4602 * @blk: hardware block
4603 * @idx: the index to release
4605 static enum ice_status
4606 ice_rel_tcam_idx(struct ice_hw *hw, enum ice_block blk, u16 idx)
4608 /* Masks to invoke a never match entry */
4609 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4610 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFE, 0xFF, 0xFF, 0xFF, 0xFF };
4611 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x01, 0x00, 0x00, 0x00, 0x00 };
4612 enum ice_status status;
4614 /* write the TCAM entry */
4615 status = ice_tcam_write_entry(hw, blk, idx, 0, 0, 0, 0, 0, vl_msk,
4620 /* release the TCAM entry */
4621 status = ice_free_tcam_ent(hw, blk, idx);
4627 * ice_rem_prof_id - remove one profile from a VSIG
4628 * @hw: pointer to the HW struct
4629 * @blk: hardware block
4630 * @prof: pointer to profile structure to remove
4632 static enum ice_status
4633 ice_rem_prof_id(struct ice_hw *hw, enum ice_block blk,
4634 struct ice_vsig_prof *prof)
4636 enum ice_status status;
4639 for (i = 0; i < prof->tcam_count; i++) {
4640 if (prof->tcam[i].in_use) {
4641 prof->tcam[i].in_use = false;
4642 status = ice_rel_tcam_idx(hw, blk,
4643 prof->tcam[i].tcam_idx);
4645 return ICE_ERR_HW_TABLE;
4653 * ice_rem_vsig - remove VSIG
4654 * @hw: pointer to the HW struct
4655 * @blk: hardware block
4656 * @vsig: the VSIG to remove
4657 * @chg: the change list
4659 static enum ice_status
4660 ice_rem_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig,
4661 struct LIST_HEAD_TYPE *chg)
4663 u16 idx = vsig & ICE_VSIG_IDX_M;
4664 struct ice_vsig_vsi *vsi_cur;
4665 struct ice_vsig_prof *d, *t;
4666 enum ice_status status;
4668 /* remove TCAM entries */
4669 LIST_FOR_EACH_ENTRY_SAFE(d, t,
4670 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4671 ice_vsig_prof, list) {
4672 status = ice_rem_prof_id(hw, blk, d);
4680 /* Move all VSIS associated with this VSIG to the default VSIG */
4681 vsi_cur = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
4682 /* If the VSIG has at least 1 VSI then iterate through the list
4683 * and remove the VSIs before deleting the group.
4687 struct ice_vsig_vsi *tmp = vsi_cur->next_vsi;
4688 struct ice_chs_chg *p;
4690 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4692 return ICE_ERR_NO_MEMORY;
4694 p->type = ICE_VSIG_REM;
4695 p->orig_vsig = vsig;
4696 p->vsig = ICE_DEFAULT_VSIG;
4697 p->vsi = vsi_cur - hw->blk[blk].xlt2.vsis;
4699 LIST_ADD(&p->list_entry, chg);
4705 status = ice_vsig_free(hw, blk, vsig);
4711 * ice_rem_prof_id_vsig - remove a specific profile from a VSIG
4712 * @hw: pointer to the HW struct
4713 * @blk: hardware block
4714 * @vsig: VSIG to remove the profile from
4715 * @hdl: profile handle indicating which profile to remove
4716 * @chg: list to receive a record of changes
4718 static enum ice_status
4719 ice_rem_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl,
4720 struct LIST_HEAD_TYPE *chg)
4722 u16 idx = vsig & ICE_VSIG_IDX_M;
4723 struct ice_vsig_prof *p, *t;
4724 enum ice_status status;
4726 LIST_FOR_EACH_ENTRY_SAFE(p, t,
4727 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4728 ice_vsig_prof, list) {
4729 if (p->profile_cookie == hdl) {
4730 if (ice_vsig_prof_id_count(hw, blk, vsig) == 1)
4731 /* this is the last profile, remove the VSIG */
4732 return ice_rem_vsig(hw, blk, vsig, chg);
4734 status = ice_rem_prof_id(hw, blk, p);
4743 return ICE_ERR_DOES_NOT_EXIST;
4747 * ice_rem_flow_all - remove all flows with a particular profile
4748 * @hw: pointer to the HW struct
4749 * @blk: hardware block
4750 * @id: profile tracking ID
4752 static enum ice_status
4753 ice_rem_flow_all(struct ice_hw *hw, enum ice_block blk, u64 id)
4755 struct ice_chs_chg *del, *tmp;
4756 struct LIST_HEAD_TYPE chg;
4757 enum ice_status status;
4760 INIT_LIST_HEAD(&chg);
4762 for (i = 1; i < ICE_MAX_VSIGS; i++) {
4763 if (hw->blk[blk].xlt2.vsig_tbl[i].in_use) {
4764 if (ice_has_prof_vsig(hw, blk, i, id)) {
4765 status = ice_rem_prof_id_vsig(hw, blk, i, id,
4768 goto err_ice_rem_flow_all;
4773 status = ice_upd_prof_hw(hw, blk, &chg);
4775 err_ice_rem_flow_all:
4776 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
4777 LIST_DEL(&del->list_entry);
4785 * ice_rem_prof - remove profile
4786 * @hw: pointer to the HW struct
4787 * @blk: hardware block
4788 * @id: profile tracking ID
4790 * This will remove the profile specified by the ID parameter, which was
4791 * previously created through ice_add_prof. If any existing entries
4792 * are associated with this profile, they will be removed as well.
4794 enum ice_status ice_rem_prof(struct ice_hw *hw, enum ice_block blk, u64 id)
4796 struct ice_prof_map *pmap;
4797 enum ice_status status;
4799 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
4801 pmap = ice_search_prof_id_low(hw, blk, id);
4803 status = ICE_ERR_DOES_NOT_EXIST;
4804 goto err_ice_rem_prof;
4807 /* remove all flows with this profile */
4808 status = ice_rem_flow_all(hw, blk, pmap->profile_cookie);
4810 goto err_ice_rem_prof;
4812 /* dereference profile, and possibly remove */
4813 ice_prof_dec_ref(hw, blk, pmap->prof_id);
4815 LIST_DEL(&pmap->list);
4818 status = ICE_SUCCESS;
4821 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
4826 * ice_get_prof - get profile
4827 * @hw: pointer to the HW struct
4828 * @blk: hardware block
4829 * @hdl: profile handle
4832 static enum ice_status
4833 ice_get_prof(struct ice_hw *hw, enum ice_block blk, u64 hdl,
4834 struct LIST_HEAD_TYPE *chg)
4836 struct ice_prof_map *map;
4837 struct ice_chs_chg *p;
4840 /* Get the details on the profile specified by the handle ID */
4841 map = ice_search_prof_id(hw, blk, hdl);
4843 return ICE_ERR_DOES_NOT_EXIST;
4845 for (i = 0; i < map->ptg_cnt; i++) {
4846 if (!hw->blk[blk].es.written[map->prof_id]) {
4847 /* add ES to change list */
4848 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4850 goto err_ice_get_prof;
4852 p->type = ICE_PTG_ES_ADD;
4854 p->ptg = map->ptg[i];
4855 p->attr = map->attr[i];
4859 p->prof_id = map->prof_id;
4861 hw->blk[blk].es.written[map->prof_id] = true;
4863 LIST_ADD(&p->list_entry, chg);
4870 /* let caller clean up the change list */
4871 return ICE_ERR_NO_MEMORY;
4875 * ice_get_profs_vsig - get a copy of the list of profiles from a VSIG
4876 * @hw: pointer to the HW struct
4877 * @blk: hardware block
4878 * @vsig: VSIG from which to copy the list
4881 * This routine makes a copy of the list of profiles in the specified VSIG.
4883 static enum ice_status
4884 ice_get_profs_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig,
4885 struct LIST_HEAD_TYPE *lst)
4887 struct ice_vsig_prof *ent1, *ent2;
4888 u16 idx = vsig & ICE_VSIG_IDX_M;
4890 LIST_FOR_EACH_ENTRY(ent1, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4891 ice_vsig_prof, list) {
4892 struct ice_vsig_prof *p;
4894 /* copy to the input list */
4895 p = (struct ice_vsig_prof *)ice_memdup(hw, ent1, sizeof(*p),
4896 ICE_NONDMA_TO_NONDMA);
4898 goto err_ice_get_profs_vsig;
4900 LIST_ADD_TAIL(&p->list, lst);
4905 err_ice_get_profs_vsig:
4906 LIST_FOR_EACH_ENTRY_SAFE(ent1, ent2, lst, ice_vsig_prof, list) {
4907 LIST_DEL(&ent1->list);
4911 return ICE_ERR_NO_MEMORY;
4915 * ice_add_prof_to_lst - add profile entry to a list
4916 * @hw: pointer to the HW struct
4917 * @blk: hardware block
4918 * @lst: the list to be added to
4919 * @hdl: profile handle of entry to add
4921 static enum ice_status
4922 ice_add_prof_to_lst(struct ice_hw *hw, enum ice_block blk,
4923 struct LIST_HEAD_TYPE *lst, u64 hdl)
4925 struct ice_vsig_prof *p;
4926 struct ice_prof_map *map;
4929 map = ice_search_prof_id(hw, blk, hdl);
4931 return ICE_ERR_DOES_NOT_EXIST;
4933 p = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*p));
4935 return ICE_ERR_NO_MEMORY;
4937 p->profile_cookie = map->profile_cookie;
4938 p->prof_id = map->prof_id;
4939 p->tcam_count = map->ptg_cnt;
4941 for (i = 0; i < map->ptg_cnt; i++) {
4942 p->tcam[i].prof_id = map->prof_id;
4943 p->tcam[i].tcam_idx = ICE_INVALID_TCAM;
4944 p->tcam[i].ptg = map->ptg[i];
4945 p->tcam[i].attr = map->attr[i];
4948 LIST_ADD(&p->list, lst);
4954 * ice_move_vsi - move VSI to another VSIG
4955 * @hw: pointer to the HW struct
4956 * @blk: hardware block
4957 * @vsi: the VSI to move
4958 * @vsig: the VSIG to move the VSI to
4959 * @chg: the change list
4961 static enum ice_status
4962 ice_move_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig,
4963 struct LIST_HEAD_TYPE *chg)
4965 enum ice_status status;
4966 struct ice_chs_chg *p;
4969 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4971 return ICE_ERR_NO_MEMORY;
4973 status = ice_vsig_find_vsi(hw, blk, vsi, &orig_vsig);
4975 status = ice_vsig_add_mv_vsi(hw, blk, vsi, vsig);
4982 p->type = ICE_VSI_MOVE;
4984 p->orig_vsig = orig_vsig;
4987 LIST_ADD(&p->list_entry, chg);
4993 * ice_set_tcam_flags - set tcam flag don't care mask
4994 * @mask: mask for flags
4995 * @dc_mask: pointer to the don't care mask
4997 static void ice_set_tcam_flags(u16 mask, u8 dc_mask[ICE_TCAM_KEY_VAL_SZ])
5001 /* flags are lowest u16 */
5002 flag_word = (u16 *)dc_mask;
5006 * ice_prof_tcam_ena_dis - add enable or disable TCAM change
5007 * @hw: pointer to the HW struct
5008 * @blk: hardware block
5009 * @enable: true to enable, false to disable
5010 * @vsig: the vsig of the TCAM entry
5011 * @tcam: pointer the TCAM info structure of the TCAM to disable
5012 * @chg: the change list
5014 * This function appends an enable or disable TCAM entry in the change log
5016 static enum ice_status
5017 ice_prof_tcam_ena_dis(struct ice_hw *hw, enum ice_block blk, bool enable,
5018 u16 vsig, struct ice_tcam_inf *tcam,
5019 struct LIST_HEAD_TYPE *chg)
5021 enum ice_status status;
5022 struct ice_chs_chg *p;
5024 /* Default: enable means change the low flag bit to don't care */
5025 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x01, 0x00, 0x00, 0x00, 0x00 };
5026 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
5027 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x01, 0x00, 0x00, 0x00, 0x00 };
5029 /* if disabling, free the tcam */
5031 status = ice_free_tcam_ent(hw, blk, tcam->tcam_idx);
5037 /* for re-enabling, reallocate a tcam */
5038 status = ice_alloc_tcam_ent(hw, blk, &tcam->tcam_idx);
5042 /* add TCAM to change list */
5043 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5045 return ICE_ERR_NO_MEMORY;
5047 /* set don't care masks for tcam flags */
5048 ice_set_tcam_flags(tcam->attr.mask, dc_msk);
5050 status = ice_tcam_write_entry(hw, blk, tcam->tcam_idx, tcam->prof_id,
5051 tcam->ptg, vsig, 0, tcam->attr.flags,
5052 vl_msk, dc_msk, nm_msk);
5054 goto err_ice_prof_tcam_ena_dis;
5058 p->type = ICE_TCAM_ADD;
5059 p->add_tcam_idx = true;
5060 p->prof_id = tcam->prof_id;
5063 p->tcam_idx = tcam->tcam_idx;
5066 LIST_ADD(&p->list_entry, chg);
5070 err_ice_prof_tcam_ena_dis:
5076 * ice_adj_prof_priorities - adjust profile based on priorities
5077 * @hw: pointer to the HW struct
5078 * @blk: hardware block
5079 * @vsig: the VSIG for which to adjust profile priorities
5080 * @chg: the change list
5082 static enum ice_status
5083 ice_adj_prof_priorities(struct ice_hw *hw, enum ice_block blk, u16 vsig,
5084 struct LIST_HEAD_TYPE *chg)
5086 ice_declare_bitmap(ptgs_used, ICE_XLT1_CNT);
5087 struct ice_vsig_prof *t;
5088 enum ice_status status;
5091 ice_zero_bitmap(ptgs_used, ICE_XLT1_CNT);
5092 idx = vsig & ICE_VSIG_IDX_M;
5094 /* Priority is based on the order in which the profiles are added. The
5095 * newest added profile has highest priority and the oldest added
5096 * profile has the lowest priority. Since the profile property list for
5097 * a VSIG is sorted from newest to oldest, this code traverses the list
5098 * in order and enables the first of each PTG that it finds (that is not
5099 * already enabled); it also disables any duplicate PTGs that it finds
5100 * in the older profiles (that are currently enabled).
5103 LIST_FOR_EACH_ENTRY(t, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
5104 ice_vsig_prof, list) {
5107 for (i = 0; i < t->tcam_count; i++) {
5108 /* Scan the priorities from newest to oldest.
5109 * Make sure that the newest profiles take priority.
5111 if (ice_is_bit_set(ptgs_used, t->tcam[i].ptg) &&
5112 t->tcam[i].in_use) {
5113 /* need to mark this PTG as never match, as it
5114 * was already in use and therefore duplicate
5115 * (and lower priority)
5117 status = ice_prof_tcam_ena_dis(hw, blk, false,
5123 } else if (!ice_is_bit_set(ptgs_used, t->tcam[i].ptg) &&
5124 !t->tcam[i].in_use) {
5125 /* need to enable this PTG, as it in not in use
5126 * and not enabled (highest priority)
5128 status = ice_prof_tcam_ena_dis(hw, blk, true,
5136 /* keep track of used ptgs */
5137 ice_set_bit(t->tcam[i].ptg, ptgs_used);
5145 * ice_add_prof_id_vsig - add profile to VSIG
5146 * @hw: pointer to the HW struct
5147 * @blk: hardware block
5148 * @vsig: the VSIG to which this profile is to be added
5149 * @hdl: the profile handle indicating the profile to add
5150 * @chg: the change list
5152 static enum ice_status
5153 ice_add_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl,
5154 struct LIST_HEAD_TYPE *chg)
5156 /* Masks that ignore flags */
5157 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
5158 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0x00, 0x00, 0x00 };
5159 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
5160 struct ice_prof_map *map;
5161 struct ice_vsig_prof *t;
5162 struct ice_chs_chg *p;
5165 /* Get the details on the profile specified by the handle ID */
5166 map = ice_search_prof_id(hw, blk, hdl);
5168 return ICE_ERR_DOES_NOT_EXIST;
5170 /* Error, if this VSIG already has this profile */
5171 if (ice_has_prof_vsig(hw, blk, vsig, hdl))
5172 return ICE_ERR_ALREADY_EXISTS;
5174 /* new VSIG profile structure */
5175 t = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*t));
5177 goto err_ice_add_prof_id_vsig;
5179 t->profile_cookie = map->profile_cookie;
5180 t->prof_id = map->prof_id;
5181 t->tcam_count = map->ptg_cnt;
5183 /* create TCAM entries */
5184 for (i = 0; i < map->ptg_cnt; i++) {
5185 enum ice_status status;
5188 /* add TCAM to change list */
5189 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5191 goto err_ice_add_prof_id_vsig;
5193 /* allocate the TCAM entry index */
5194 status = ice_alloc_tcam_ent(hw, blk, &tcam_idx);
5197 goto err_ice_add_prof_id_vsig;
5200 t->tcam[i].ptg = map->ptg[i];
5201 t->tcam[i].prof_id = map->prof_id;
5202 t->tcam[i].tcam_idx = tcam_idx;
5203 t->tcam[i].attr = map->attr[i];
5204 t->tcam[i].in_use = true;
5206 p->type = ICE_TCAM_ADD;
5207 p->add_tcam_idx = true;
5208 p->prof_id = t->tcam[i].prof_id;
5209 p->ptg = t->tcam[i].ptg;
5211 p->tcam_idx = t->tcam[i].tcam_idx;
5213 /* set don't care masks for tcam flags */
5214 ice_set_tcam_flags(t->tcam[i].attr.mask, dc_msk);
5216 /* write the TCAM entry */
5217 status = ice_tcam_write_entry(hw, blk, t->tcam[i].tcam_idx,
5219 t->tcam[i].ptg, vsig, 0,
5220 t->tcam[i].attr.flags, vl_msk,
5223 goto err_ice_add_prof_id_vsig;
5226 LIST_ADD(&p->list_entry, chg);
5229 /* add profile to VSIG */
5231 &hw->blk[blk].xlt2.vsig_tbl[(vsig & ICE_VSIG_IDX_M)].prop_lst);
5235 err_ice_add_prof_id_vsig:
5236 /* let caller clean up the change list */
5238 return ICE_ERR_NO_MEMORY;
5242 * ice_create_prof_id_vsig - add a new VSIG with a single profile
5243 * @hw: pointer to the HW struct
5244 * @blk: hardware block
5245 * @vsi: the initial VSI that will be in VSIG
5246 * @hdl: the profile handle of the profile that will be added to the VSIG
5247 * @chg: the change list
5249 static enum ice_status
5250 ice_create_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl,
5251 struct LIST_HEAD_TYPE *chg)
5253 enum ice_status status;
5254 struct ice_chs_chg *p;
5257 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5259 return ICE_ERR_NO_MEMORY;
5261 new_vsig = ice_vsig_alloc(hw, blk);
5263 status = ICE_ERR_HW_TABLE;
5264 goto err_ice_create_prof_id_vsig;
5267 status = ice_move_vsi(hw, blk, vsi, new_vsig, chg);
5269 goto err_ice_create_prof_id_vsig;
5271 status = ice_add_prof_id_vsig(hw, blk, new_vsig, hdl, chg);
5273 goto err_ice_create_prof_id_vsig;
5275 p->type = ICE_VSIG_ADD;
5277 p->orig_vsig = ICE_DEFAULT_VSIG;
5280 LIST_ADD(&p->list_entry, chg);
5284 err_ice_create_prof_id_vsig:
5285 /* let caller clean up the change list */
5291 * ice_create_vsig_from_list - create a new VSIG with a list of profiles
5292 * @hw: pointer to the HW struct
5293 * @blk: hardware block
5294 * @vsi: the initial VSI that will be in VSIG
5295 * @lst: the list of profile that will be added to the VSIG
5296 * @chg: the change list
5298 static enum ice_status
5299 ice_create_vsig_from_lst(struct ice_hw *hw, enum ice_block blk, u16 vsi,
5300 struct LIST_HEAD_TYPE *lst, struct LIST_HEAD_TYPE *chg)
5302 struct ice_vsig_prof *t;
5303 enum ice_status status;
5306 vsig = ice_vsig_alloc(hw, blk);
5308 return ICE_ERR_HW_TABLE;
5310 status = ice_move_vsi(hw, blk, vsi, vsig, chg);
5314 LIST_FOR_EACH_ENTRY(t, lst, ice_vsig_prof, list) {
5315 status = ice_add_prof_id_vsig(hw, blk, vsig, t->profile_cookie,
5325 * ice_find_prof_vsig - find a VSIG with a specific profile handle
5326 * @hw: pointer to the HW struct
5327 * @blk: hardware block
5328 * @hdl: the profile handle of the profile to search for
5329 * @vsig: returns the VSIG with the matching profile
5332 ice_find_prof_vsig(struct ice_hw *hw, enum ice_block blk, u64 hdl, u16 *vsig)
5334 struct ice_vsig_prof *t;
5335 struct LIST_HEAD_TYPE lst;
5336 enum ice_status status;
5338 INIT_LIST_HEAD(&lst);
5340 t = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*t));
5344 t->profile_cookie = hdl;
5345 LIST_ADD(&t->list, &lst);
5347 status = ice_find_dup_props_vsig(hw, blk, &lst, vsig);
5352 return status == ICE_SUCCESS;
5356 * ice_add_vsi_flow - add VSI flow
5357 * @hw: pointer to the HW struct
5358 * @blk: hardware block
5360 * @vsig: target VSIG to include the input VSI
5362 * Calling this function will add the VSI to a given VSIG and
5363 * update the HW tables accordingly. This call can be used to
5364 * add multiple VSIs to a VSIG if we know beforehand that those
5365 * VSIs have the same characteristics of the VSIG. This will
5366 * save time in generating a new VSIG and TCAMs till a match is
5367 * found and subsequent rollback when a matching VSIG is found.
5370 ice_add_vsi_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
5372 struct ice_chs_chg *tmp, *del;
5373 struct LIST_HEAD_TYPE chg;
5374 enum ice_status status;
5376 /* if target VSIG is default the move is invalid */
5377 if ((vsig & ICE_VSIG_IDX_M) == ICE_DEFAULT_VSIG)
5378 return ICE_ERR_PARAM;
5380 INIT_LIST_HEAD(&chg);
5382 /* move VSI to the VSIG that matches */
5383 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5384 /* update hardware if success */
5386 status = ice_upd_prof_hw(hw, blk, &chg);
5388 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
5389 LIST_DEL(&del->list_entry);
5397 * ice_add_prof_id_flow - add profile flow
5398 * @hw: pointer to the HW struct
5399 * @blk: hardware block
5400 * @vsi: the VSI to enable with the profile specified by ID
5401 * @hdl: profile handle
5403 * Calling this function will update the hardware tables to enable the
5404 * profile indicated by the ID parameter for the VSIs specified in the VSI
5405 * array. Once successfully called, the flow will be enabled.
5408 ice_add_prof_id_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl)
5410 struct ice_vsig_prof *tmp1, *del1;
5411 struct LIST_HEAD_TYPE union_lst;
5412 struct ice_chs_chg *tmp, *del;
5413 struct LIST_HEAD_TYPE chrs;
5414 struct LIST_HEAD_TYPE chg;
5415 enum ice_status status;
5416 u16 vsig, or_vsig = 0;
5418 INIT_LIST_HEAD(&union_lst);
5419 INIT_LIST_HEAD(&chrs);
5420 INIT_LIST_HEAD(&chg);
5423 status = ice_get_prof(hw, blk, hdl, &chg);
5427 /* determine if VSI is already part of a VSIG */
5428 status = ice_vsig_find_vsi(hw, blk, vsi, &vsig);
5429 if (!status && vsig) {
5436 /* make sure that there is no overlap/conflict between the new
5437 * characteristics and the existing ones; we don't support that
5440 if (ice_has_prof_vsig(hw, blk, vsig, hdl)) {
5441 status = ICE_ERR_ALREADY_EXISTS;
5442 goto err_ice_add_prof_id_flow;
5445 /* last VSI in the VSIG? */
5446 status = ice_vsig_get_ref(hw, blk, vsig, &ref);
5448 goto err_ice_add_prof_id_flow;
5449 only_vsi = (ref == 1);
5451 /* create a union of the current profiles and the one being
5454 status = ice_get_profs_vsig(hw, blk, vsig, &union_lst);
5456 goto err_ice_add_prof_id_flow;
5458 status = ice_add_prof_to_lst(hw, blk, &union_lst, hdl);
5460 goto err_ice_add_prof_id_flow;
5462 /* search for an existing VSIG with an exact charc match */
5463 status = ice_find_dup_props_vsig(hw, blk, &union_lst, &vsig);
5465 /* move VSI to the VSIG that matches */
5466 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5468 goto err_ice_add_prof_id_flow;
5470 /* VSI has been moved out of or_vsig. If the or_vsig had
5471 * only that VSI it is now empty and can be removed.
5474 status = ice_rem_vsig(hw, blk, or_vsig, &chg);
5476 goto err_ice_add_prof_id_flow;
5478 } else if (only_vsi) {
5479 /* If the original VSIG only contains one VSI, then it
5480 * will be the requesting VSI. In this case the VSI is
5481 * not sharing entries and we can simply add the new
5482 * profile to the VSIG.
5484 status = ice_add_prof_id_vsig(hw, blk, vsig, hdl, &chg);
5486 goto err_ice_add_prof_id_flow;
5488 /* Adjust priorities */
5489 status = ice_adj_prof_priorities(hw, blk, vsig, &chg);
5491 goto err_ice_add_prof_id_flow;
5493 /* No match, so we need a new VSIG */
5494 status = ice_create_vsig_from_lst(hw, blk, vsi,
5497 goto err_ice_add_prof_id_flow;
5499 /* Adjust priorities */
5500 status = ice_adj_prof_priorities(hw, blk, vsig, &chg);
5502 goto err_ice_add_prof_id_flow;
5505 /* need to find or add a VSIG */
5506 /* search for an existing VSIG with an exact charc match */
5507 if (ice_find_prof_vsig(hw, blk, hdl, &vsig)) {
5508 /* found an exact match */
5509 /* add or move VSI to the VSIG that matches */
5510 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5512 goto err_ice_add_prof_id_flow;
5514 /* we did not find an exact match */
5515 /* we need to add a VSIG */
5516 status = ice_create_prof_id_vsig(hw, blk, vsi, hdl,
5519 goto err_ice_add_prof_id_flow;
5523 /* update hardware */
5525 status = ice_upd_prof_hw(hw, blk, &chg);
5527 err_ice_add_prof_id_flow:
5528 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
5529 LIST_DEL(&del->list_entry);
5533 LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, &union_lst, ice_vsig_prof, list) {
5534 LIST_DEL(&del1->list);
5538 LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, &chrs, ice_vsig_prof, list) {
5539 LIST_DEL(&del1->list);
5547 * ice_rem_prof_from_list - remove a profile from list
5548 * @hw: pointer to the HW struct
5549 * @lst: list to remove the profile from
5550 * @hdl: the profile handle indicating the profile to remove
5552 static enum ice_status
5553 ice_rem_prof_from_list(struct ice_hw *hw, struct LIST_HEAD_TYPE *lst, u64 hdl)
5555 struct ice_vsig_prof *ent, *tmp;
5557 LIST_FOR_EACH_ENTRY_SAFE(ent, tmp, lst, ice_vsig_prof, list) {
5558 if (ent->profile_cookie == hdl) {
5559 LIST_DEL(&ent->list);
5565 return ICE_ERR_DOES_NOT_EXIST;
5569 * ice_rem_prof_id_flow - remove flow
5570 * @hw: pointer to the HW struct
5571 * @blk: hardware block
5572 * @vsi: the VSI from which to remove the profile specified by ID
5573 * @hdl: profile tracking handle
5575 * Calling this function will update the hardware tables to remove the
5576 * profile indicated by the ID parameter for the VSIs specified in the VSI
5577 * array. Once successfully called, the flow will be disabled.
5580 ice_rem_prof_id_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl)
5582 struct ice_vsig_prof *tmp1, *del1;
5583 struct LIST_HEAD_TYPE chg, copy;
5584 struct ice_chs_chg *tmp, *del;
5585 enum ice_status status;
5588 INIT_LIST_HEAD(©);
5589 INIT_LIST_HEAD(&chg);
5591 /* determine if VSI is already part of a VSIG */
5592 status = ice_vsig_find_vsi(hw, blk, vsi, &vsig);
5593 if (!status && vsig) {
5599 last_profile = ice_vsig_prof_id_count(hw, blk, vsig) == 1;
5600 status = ice_vsig_get_ref(hw, blk, vsig, &ref);
5602 goto err_ice_rem_prof_id_flow;
5603 only_vsi = (ref == 1);
5606 /* If the original VSIG only contains one reference,
5607 * which will be the requesting VSI, then the VSI is not
5608 * sharing entries and we can simply remove the specific
5609 * characteristics from the VSIG.
5613 /* If there are no profiles left for this VSIG,
5614 * then simply remove the the VSIG.
5616 status = ice_rem_vsig(hw, blk, vsig, &chg);
5618 goto err_ice_rem_prof_id_flow;
5620 status = ice_rem_prof_id_vsig(hw, blk, vsig,
5623 goto err_ice_rem_prof_id_flow;
5625 /* Adjust priorities */
5626 status = ice_adj_prof_priorities(hw, blk, vsig,
5629 goto err_ice_rem_prof_id_flow;
5633 /* Make a copy of the VSIG's list of Profiles */
5634 status = ice_get_profs_vsig(hw, blk, vsig, ©);
5636 goto err_ice_rem_prof_id_flow;
5638 /* Remove specified profile entry from the list */
5639 status = ice_rem_prof_from_list(hw, ©, hdl);
5641 goto err_ice_rem_prof_id_flow;
5643 if (LIST_EMPTY(©)) {
5644 status = ice_move_vsi(hw, blk, vsi,
5645 ICE_DEFAULT_VSIG, &chg);
5647 goto err_ice_rem_prof_id_flow;
5649 } else if (!ice_find_dup_props_vsig(hw, blk, ©,
5651 /* found an exact match */
5652 /* add or move VSI to the VSIG that matches */
5653 /* Search for a VSIG with a matching profile
5657 /* Found match, move VSI to the matching VSIG */
5658 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5660 goto err_ice_rem_prof_id_flow;
5662 /* since no existing VSIG supports this
5663 * characteristic pattern, we need to create a
5664 * new VSIG and TCAM entries
5666 status = ice_create_vsig_from_lst(hw, blk, vsi,
5669 goto err_ice_rem_prof_id_flow;
5671 /* Adjust priorities */
5672 status = ice_adj_prof_priorities(hw, blk, vsig,
5675 goto err_ice_rem_prof_id_flow;
5679 status = ICE_ERR_DOES_NOT_EXIST;
5682 /* update hardware tables */
5684 status = ice_upd_prof_hw(hw, blk, &chg);
5686 err_ice_rem_prof_id_flow:
5687 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
5688 LIST_DEL(&del->list_entry);
5692 LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, ©, ice_vsig_prof, list) {
5693 LIST_DEL(&del1->list);