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 *)(ice_seg->device_table +
135 LE32_TO_CPU(ice_seg->device_table_count));
137 return (_FORCE_ struct ice_buf_table *)
138 (nvms->vers + LE32_TO_CPU(nvms->table_count));
143 * @ice_seg: pointer to the ice segment (or NULL on subsequent calls)
144 * @state: pointer to the enum state
146 * This function will enumerate all the buffers in the ice segment. The first
147 * call is made with the ice_seg parameter non-NULL; on subsequent calls,
148 * ice_seg is set to NULL which continues the enumeration. When the function
149 * returns a NULL pointer, then the end of the buffers has been reached, or an
150 * unexpected value has been detected (for example an invalid section count or
151 * an invalid buffer end value).
153 static struct ice_buf_hdr *
154 ice_pkg_enum_buf(struct ice_seg *ice_seg, struct ice_pkg_enum *state)
157 state->buf_table = ice_find_buf_table(ice_seg);
158 if (!state->buf_table)
162 return ice_pkg_val_buf(state->buf_table->buf_array);
165 if (++state->buf_idx < LE32_TO_CPU(state->buf_table->buf_count))
166 return ice_pkg_val_buf(state->buf_table->buf_array +
173 * ice_pkg_advance_sect
174 * @ice_seg: pointer to the ice segment (or NULL on subsequent calls)
175 * @state: pointer to the enum state
177 * This helper function will advance the section within the ice segment,
178 * also advancing the buffer if needed.
181 ice_pkg_advance_sect(struct ice_seg *ice_seg, struct ice_pkg_enum *state)
183 if (!ice_seg && !state->buf)
186 if (!ice_seg && state->buf)
187 if (++state->sect_idx < LE16_TO_CPU(state->buf->section_count))
190 state->buf = ice_pkg_enum_buf(ice_seg, state);
194 /* start of new buffer, reset section index */
200 * ice_pkg_enum_section
201 * @ice_seg: pointer to the ice segment (or NULL on subsequent calls)
202 * @state: pointer to the enum state
203 * @sect_type: section type to enumerate
205 * This function will enumerate all the sections of a particular type in the
206 * ice segment. The first call is made with the ice_seg parameter non-NULL;
207 * on subsequent calls, ice_seg is set to NULL which continues the enumeration.
208 * When the function returns a NULL pointer, then the end of the matching
209 * sections has been reached.
212 ice_pkg_enum_section(struct ice_seg *ice_seg, struct ice_pkg_enum *state,
218 state->type = sect_type;
220 if (!ice_pkg_advance_sect(ice_seg, state))
223 /* scan for next matching section */
224 while (state->buf->section_entry[state->sect_idx].type !=
225 CPU_TO_LE32(state->type))
226 if (!ice_pkg_advance_sect(NULL, state))
229 /* validate section */
230 offset = LE16_TO_CPU(state->buf->section_entry[state->sect_idx].offset);
231 if (offset < ICE_MIN_S_OFF || offset > ICE_MAX_S_OFF)
234 size = LE16_TO_CPU(state->buf->section_entry[state->sect_idx].size);
235 if (size < ICE_MIN_S_SZ || size > ICE_MAX_S_SZ)
238 /* make sure the section fits in the buffer */
239 if (offset + size > ICE_PKG_BUF_SIZE)
243 LE32_TO_CPU(state->buf->section_entry[state->sect_idx].type);
245 /* calc pointer to this section */
246 state->sect = ((u8 *)state->buf) +
247 LE16_TO_CPU(state->buf->section_entry[state->sect_idx].offset);
254 * @ice_seg: pointer to the ice segment (or NULL on subsequent calls)
255 * @state: pointer to the enum state
256 * @sect_type: section type to enumerate
257 * @offset: pointer to variable that receives the offset in the table (optional)
258 * @handler: function that handles access to the entries into the section type
260 * This function will enumerate all the entries in particular section type in
261 * the ice segment. The first call is made with the ice_seg parameter non-NULL;
262 * on subsequent calls, ice_seg is set to NULL which continues the enumeration.
263 * When the function returns a NULL pointer, then the end of the entries has
266 * Since each section may have a different header and entry size, the handler
267 * function is needed to determine the number and location entries in each
270 * The offset parameter is optional, but should be used for sections that
271 * contain an offset for each section table. For such cases, the section handler
272 * function must return the appropriate offset + index to give the absolution
273 * offset for each entry. For example, if the base for a section's header
274 * indicates a base offset of 10, and the index for the entry is 2, then
275 * section handler function should set the offset to 10 + 2 = 12.
278 ice_pkg_enum_entry(struct ice_seg *ice_seg, struct ice_pkg_enum *state,
279 u32 sect_type, u32 *offset,
280 void *(*handler)(u32 sect_type, void *section,
281 u32 index, u32 *offset))
289 if (!ice_pkg_enum_section(ice_seg, state, sect_type))
292 state->entry_idx = 0;
293 state->handler = handler;
302 entry = state->handler(state->sect_type, state->sect, state->entry_idx,
305 /* end of a section, look for another section of this type */
306 if (!ice_pkg_enum_section(NULL, state, 0))
309 state->entry_idx = 0;
310 entry = state->handler(state->sect_type, state->sect,
311 state->entry_idx, offset);
318 * ice_boost_tcam_handler
319 * @sect_type: section type
320 * @section: pointer to section
321 * @index: index of the boost TCAM entry to be returned
322 * @offset: pointer to receive absolute offset, always 0 for boost TCAM sections
324 * This is a callback function that can be passed to ice_pkg_enum_entry.
325 * Handles enumeration of individual boost TCAM entries.
328 ice_boost_tcam_handler(u32 sect_type, void *section, u32 index, u32 *offset)
330 struct ice_boost_tcam_section *boost;
335 if (sect_type != ICE_SID_RXPARSER_BOOST_TCAM)
338 if (index > ICE_MAX_BST_TCAMS_IN_BUF)
344 boost = (struct ice_boost_tcam_section *)section;
345 if (index >= LE16_TO_CPU(boost->count))
348 return boost->tcam + index;
352 * ice_find_boost_entry
353 * @ice_seg: pointer to the ice segment (non-NULL)
354 * @addr: Boost TCAM address of entry to search for
355 * @entry: returns pointer to the entry
357 * Finds a particular Boost TCAM entry and returns a pointer to that entry
358 * if it is found. The ice_seg parameter must not be NULL since the first call
359 * to ice_pkg_enum_entry requires a pointer to an actual ice_segment structure.
361 static enum ice_status
362 ice_find_boost_entry(struct ice_seg *ice_seg, u16 addr,
363 struct ice_boost_tcam_entry **entry)
365 struct ice_boost_tcam_entry *tcam;
366 struct ice_pkg_enum state;
368 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
371 return ICE_ERR_PARAM;
374 tcam = (struct ice_boost_tcam_entry *)
375 ice_pkg_enum_entry(ice_seg, &state,
376 ICE_SID_RXPARSER_BOOST_TCAM, NULL,
377 ice_boost_tcam_handler);
378 if (tcam && LE16_TO_CPU(tcam->addr) == addr) {
391 * ice_label_enum_handler
392 * @sect_type: section type
393 * @section: pointer to section
394 * @index: index of the label entry to be returned
395 * @offset: pointer to receive absolute offset, always zero for label sections
397 * This is a callback function that can be passed to ice_pkg_enum_entry.
398 * Handles enumeration of individual label entries.
401 ice_label_enum_handler(u32 __ALWAYS_UNUSED sect_type, void *section, u32 index,
404 struct ice_label_section *labels;
409 if (index > ICE_MAX_LABELS_IN_BUF)
415 labels = (struct ice_label_section *)section;
416 if (index >= LE16_TO_CPU(labels->count))
419 return labels->label + index;
424 * @ice_seg: pointer to the ice segment (NULL on subsequent calls)
425 * @type: the section type that will contain the label (0 on subsequent calls)
426 * @state: ice_pkg_enum structure that will hold the state of the enumeration
427 * @value: pointer to a value that will return the label's value if found
429 * Enumerates a list of labels in the package. The caller will call
430 * ice_enum_labels(ice_seg, type, ...) to start the enumeration, then call
431 * ice_enum_labels(NULL, 0, ...) to continue. When the function returns a NULL
432 * the end of the list has been reached.
435 ice_enum_labels(struct ice_seg *ice_seg, u32 type, struct ice_pkg_enum *state,
438 struct ice_label *label;
440 /* Check for valid label section on first call */
441 if (type && !(type >= ICE_SID_LBL_FIRST && type <= ICE_SID_LBL_LAST))
444 label = (struct ice_label *)ice_pkg_enum_entry(ice_seg, state, type,
446 ice_label_enum_handler);
450 *value = LE16_TO_CPU(label->value);
456 * @hw: pointer to the HW structure
457 * @ice_seg: pointer to the segment of the package scan (non-NULL)
459 * This function will scan the package and save off relevant information
460 * (hints or metadata) for driver use. The ice_seg parameter must not be NULL
461 * since the first call to ice_enum_labels requires a pointer to an actual
464 static void ice_init_pkg_hints(struct ice_hw *hw, struct ice_seg *ice_seg)
466 struct ice_pkg_enum state;
471 ice_memset(&hw->tnl, 0, sizeof(hw->tnl), ICE_NONDMA_MEM);
476 label_name = ice_enum_labels(ice_seg, ICE_SID_LBL_RXPARSER_TMEM, &state,
479 while (label_name && hw->tnl.count < ICE_TUNNEL_MAX_ENTRIES) {
480 for (i = 0; tnls[i].type != TNL_LAST; i++) {
481 size_t len = strlen(tnls[i].label_prefix);
483 /* Look for matching label start, before continuing */
484 if (strncmp(label_name, tnls[i].label_prefix, len))
487 /* Make sure this label matches our PF. Note that the PF
488 * character ('0' - '7') will be located where our
489 * prefix string's null terminator is located.
491 if ((label_name[len] - '0') == hw->pf_id) {
492 hw->tnl.tbl[hw->tnl.count].type = tnls[i].type;
493 hw->tnl.tbl[hw->tnl.count].valid = false;
494 hw->tnl.tbl[hw->tnl.count].in_use = false;
495 hw->tnl.tbl[hw->tnl.count].marked = false;
496 hw->tnl.tbl[hw->tnl.count].boost_addr = val;
497 hw->tnl.tbl[hw->tnl.count].port = 0;
503 label_name = ice_enum_labels(NULL, 0, &state, &val);
506 /* Cache the appropriate boost TCAM entry pointers */
507 for (i = 0; i < hw->tnl.count; i++) {
508 ice_find_boost_entry(ice_seg, hw->tnl.tbl[i].boost_addr,
509 &hw->tnl.tbl[i].boost_entry);
510 if (hw->tnl.tbl[i].boost_entry)
511 hw->tnl.tbl[i].valid = true;
517 #define ICE_DC_KEY 0x1 /* don't care */
518 #define ICE_DC_KEYINV 0x1
519 #define ICE_NM_KEY 0x0 /* never match */
520 #define ICE_NM_KEYINV 0x0
521 #define ICE_0_KEY 0x1 /* match 0 */
522 #define ICE_0_KEYINV 0x0
523 #define ICE_1_KEY 0x0 /* match 1 */
524 #define ICE_1_KEYINV 0x1
527 * ice_gen_key_word - generate 16-bits of a key/mask word
529 * @valid: valid bits mask (change only the valid bits)
530 * @dont_care: don't care mask
531 * @nvr_mtch: never match mask
532 * @key: pointer to an array of where the resulting key portion
533 * @key_inv: pointer to an array of where the resulting key invert portion
535 * This function generates 16-bits from a 8-bit value, an 8-bit don't care mask
536 * and an 8-bit never match mask. The 16-bits of output are divided into 8 bits
537 * of key and 8 bits of key invert.
539 * '0' = b01, always match a 0 bit
540 * '1' = b10, always match a 1 bit
541 * '?' = b11, don't care bit (always matches)
542 * '~' = b00, never match bit
546 * dont_care: b0 0 1 1 0 0
547 * never_mtch: b0 0 0 0 1 1
548 * ------------------------------
549 * Result: key: b01 10 11 11 00 00
551 static enum ice_status
552 ice_gen_key_word(u8 val, u8 valid, u8 dont_care, u8 nvr_mtch, u8 *key,
555 u8 in_key = *key, in_key_inv = *key_inv;
558 /* 'dont_care' and 'nvr_mtch' masks cannot overlap */
559 if ((dont_care ^ nvr_mtch) != (dont_care | nvr_mtch))
565 /* encode the 8 bits into 8-bit key and 8-bit key invert */
566 for (i = 0; i < 8; i++) {
570 if (!(valid & 0x1)) { /* change only valid bits */
571 *key |= (in_key & 0x1) << 7;
572 *key_inv |= (in_key_inv & 0x1) << 7;
573 } else if (dont_care & 0x1) { /* don't care bit */
574 *key |= ICE_DC_KEY << 7;
575 *key_inv |= ICE_DC_KEYINV << 7;
576 } else if (nvr_mtch & 0x1) { /* never match bit */
577 *key |= ICE_NM_KEY << 7;
578 *key_inv |= ICE_NM_KEYINV << 7;
579 } else if (val & 0x01) { /* exact 1 match */
580 *key |= ICE_1_KEY << 7;
581 *key_inv |= ICE_1_KEYINV << 7;
582 } else { /* exact 0 match */
583 *key |= ICE_0_KEY << 7;
584 *key_inv |= ICE_0_KEYINV << 7;
599 * ice_bits_max_set - determine if the number of bits set is within a maximum
600 * @mask: pointer to the byte array which is the mask
601 * @size: the number of bytes in the mask
602 * @max: the max number of set bits
604 * This function determines if there are at most 'max' number of bits set in an
605 * array. Returns true if the number for bits set is <= max or will return false
608 static bool ice_bits_max_set(const u8 *mask, u16 size, u16 max)
613 /* check each byte */
614 for (i = 0; i < size; i++) {
615 /* if 0, go to next byte */
619 /* We know there is at least one set bit in this byte because of
620 * the above check; if we already have found 'max' number of
621 * bits set, then we can return failure now.
626 /* count the bits in this byte, checking threshold */
627 for (j = 0; j < BITS_PER_BYTE; j++) {
628 count += (mask[i] & (0x1 << j)) ? 1 : 0;
638 * ice_set_key - generate a variable sized key with multiples of 16-bits
639 * @key: pointer to where the key will be stored
640 * @size: the size of the complete key in bytes (must be even)
641 * @val: array of 8-bit values that makes up the value portion of the key
642 * @upd: array of 8-bit masks that determine what key portion to update
643 * @dc: array of 8-bit masks that make up the don't care mask
644 * @nm: array of 8-bit masks that make up the never match mask
645 * @off: the offset of the first byte in the key to update
646 * @len: the number of bytes in the key update
648 * This function generates a key from a value, a don't care mask and a never
650 * upd, dc, and nm are optional parameters, and can be NULL:
651 * upd == NULL --> udp mask is all 1's (update all bits)
652 * dc == NULL --> dc mask is all 0's (no don't care bits)
653 * nm == NULL --> nm mask is all 0's (no never match bits)
656 ice_set_key(u8 *key, u16 size, u8 *val, u8 *upd, u8 *dc, u8 *nm, u16 off,
662 /* size must be a multiple of 2 bytes. */
665 half_size = size / 2;
667 if (off + len > half_size)
670 /* Make sure at most one bit is set in the never match mask. Having more
671 * than one never match mask bit set will cause HW to consume excessive
672 * power otherwise; this is a power management efficiency check.
674 #define ICE_NVR_MTCH_BITS_MAX 1
675 if (nm && !ice_bits_max_set(nm, len, ICE_NVR_MTCH_BITS_MAX))
678 for (i = 0; i < len; i++)
679 if (ice_gen_key_word(val[i], upd ? upd[i] : 0xff,
680 dc ? dc[i] : 0, nm ? nm[i] : 0,
681 key + off + i, key + half_size + off + i))
688 * ice_acquire_global_cfg_lock
689 * @hw: pointer to the HW structure
690 * @access: access type (read or write)
692 * This function will request ownership of the global config lock for reading
693 * or writing of the package. When attempting to obtain write access, the
694 * caller must check for the following two return values:
696 * ICE_SUCCESS - Means the caller has acquired the global config lock
697 * and can perform writing of the package.
698 * ICE_ERR_AQ_NO_WORK - Indicates another driver has already written the
699 * package or has found that no update was necessary; in
700 * this case, the caller can just skip performing any
701 * update of the package.
703 static enum ice_status
704 ice_acquire_global_cfg_lock(struct ice_hw *hw,
705 enum ice_aq_res_access_type access)
707 enum ice_status status;
709 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
711 status = ice_acquire_res(hw, ICE_GLOBAL_CFG_LOCK_RES_ID, access,
712 ICE_GLOBAL_CFG_LOCK_TIMEOUT);
714 if (status == ICE_ERR_AQ_NO_WORK)
715 ice_debug(hw, ICE_DBG_PKG,
716 "Global config lock: No work to do\n");
722 * ice_release_global_cfg_lock
723 * @hw: pointer to the HW structure
725 * This function will release the global config lock.
727 static void ice_release_global_cfg_lock(struct ice_hw *hw)
729 ice_release_res(hw, ICE_GLOBAL_CFG_LOCK_RES_ID);
733 * ice_acquire_change_lock
734 * @hw: pointer to the HW structure
735 * @access: access type (read or write)
737 * This function will request ownership of the change lock.
740 ice_acquire_change_lock(struct ice_hw *hw, enum ice_aq_res_access_type access)
742 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
744 return ice_acquire_res(hw, ICE_CHANGE_LOCK_RES_ID, access,
745 ICE_CHANGE_LOCK_TIMEOUT);
749 * ice_release_change_lock
750 * @hw: pointer to the HW structure
752 * This function will release the change lock using the proper Admin Command.
754 void ice_release_change_lock(struct ice_hw *hw)
756 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
758 ice_release_res(hw, ICE_CHANGE_LOCK_RES_ID);
762 * ice_aq_download_pkg
763 * @hw: pointer to the hardware structure
764 * @pkg_buf: the package buffer to transfer
765 * @buf_size: the size of the package buffer
766 * @last_buf: last buffer indicator
767 * @error_offset: returns error offset
768 * @error_info: returns error information
769 * @cd: pointer to command details structure or NULL
771 * Download Package (0x0C40)
773 static enum ice_status
774 ice_aq_download_pkg(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf,
775 u16 buf_size, bool last_buf, u32 *error_offset,
776 u32 *error_info, struct ice_sq_cd *cd)
778 struct ice_aqc_download_pkg *cmd;
779 struct ice_aq_desc desc;
780 enum ice_status status;
782 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
789 cmd = &desc.params.download_pkg;
790 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_download_pkg);
791 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
794 cmd->flags |= ICE_AQC_DOWNLOAD_PKG_LAST_BUF;
796 status = ice_aq_send_cmd(hw, &desc, pkg_buf, buf_size, cd);
797 if (status == ICE_ERR_AQ_ERROR) {
798 /* Read error from buffer only when the FW returned an error */
799 struct ice_aqc_download_pkg_resp *resp;
801 resp = (struct ice_aqc_download_pkg_resp *)pkg_buf;
803 *error_offset = LE32_TO_CPU(resp->error_offset);
805 *error_info = LE32_TO_CPU(resp->error_info);
814 * @hw: pointer to the hardware structure
815 * @pkg_buf: the package cmd buffer
816 * @buf_size: the size of the package cmd buffer
817 * @last_buf: last buffer indicator
818 * @error_offset: returns error offset
819 * @error_info: returns error information
820 * @cd: pointer to command details structure or NULL
822 * Update Package (0x0C42)
824 static enum ice_status
825 ice_aq_update_pkg(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf, u16 buf_size,
826 bool last_buf, u32 *error_offset, u32 *error_info,
827 struct ice_sq_cd *cd)
829 struct ice_aqc_download_pkg *cmd;
830 struct ice_aq_desc desc;
831 enum ice_status status;
833 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
840 cmd = &desc.params.download_pkg;
841 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_update_pkg);
842 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
845 cmd->flags |= ICE_AQC_DOWNLOAD_PKG_LAST_BUF;
847 status = ice_aq_send_cmd(hw, &desc, pkg_buf, buf_size, cd);
848 if (status == ICE_ERR_AQ_ERROR) {
849 /* Read error from buffer only when the FW returned an error */
850 struct ice_aqc_download_pkg_resp *resp;
852 resp = (struct ice_aqc_download_pkg_resp *)pkg_buf;
854 *error_offset = LE32_TO_CPU(resp->error_offset);
856 *error_info = LE32_TO_CPU(resp->error_info);
863 * ice_find_seg_in_pkg
864 * @hw: pointer to the hardware structure
865 * @seg_type: the segment type to search for (i.e., SEGMENT_TYPE_CPK)
866 * @pkg_hdr: pointer to the package header to be searched
868 * This function searches a package file for a particular segment type. On
869 * success it returns a pointer to the segment header, otherwise it will
872 static struct ice_generic_seg_hdr *
873 ice_find_seg_in_pkg(struct ice_hw *hw, u32 seg_type,
874 struct ice_pkg_hdr *pkg_hdr)
878 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
879 ice_debug(hw, ICE_DBG_PKG, "Package format version: %d.%d.%d.%d\n",
880 pkg_hdr->format_ver.major, pkg_hdr->format_ver.minor,
881 pkg_hdr->format_ver.update, pkg_hdr->format_ver.draft);
883 /* Search all package segments for the requested segment type */
884 for (i = 0; i < LE32_TO_CPU(pkg_hdr->seg_count); i++) {
885 struct ice_generic_seg_hdr *seg;
887 seg = (struct ice_generic_seg_hdr *)
888 ((u8 *)pkg_hdr + LE32_TO_CPU(pkg_hdr->seg_offset[i]));
890 if (LE32_TO_CPU(seg->seg_type) == seg_type)
899 * @hw: pointer to the hardware structure
900 * @bufs: pointer to an array of buffers
901 * @count: the number of buffers in the array
903 * Obtains change lock and updates package.
906 ice_update_pkg(struct ice_hw *hw, struct ice_buf *bufs, u32 count)
908 enum ice_status status;
911 status = ice_acquire_change_lock(hw, ICE_RES_WRITE);
915 for (i = 0; i < count; i++) {
916 bool last = ((i + 1) == count);
918 struct ice_buf_hdr *bh = (struct ice_buf_hdr *)(bufs + i);
920 status = ice_aq_update_pkg(hw, bh, LE16_TO_CPU(bh->data_end),
921 last, &offset, &info, NULL);
924 ice_debug(hw, ICE_DBG_PKG,
925 "Update pkg failed: err %d off %d inf %d\n",
926 status, offset, info);
931 ice_release_change_lock(hw);
938 * @hw: pointer to the hardware structure
939 * @bufs: pointer to an array of buffers
940 * @count: the number of buffers in the array
942 * Obtains global config lock and downloads the package configuration buffers
943 * to the firmware. Metadata buffers are skipped, and the first metadata buffer
944 * found indicates that the rest of the buffers are all metadata buffers.
946 static enum ice_status
947 ice_dwnld_cfg_bufs(struct ice_hw *hw, struct ice_buf *bufs, u32 count)
949 enum ice_status status;
950 struct ice_buf_hdr *bh;
954 return ICE_ERR_PARAM;
956 /* If the first buffer's first section has its metadata bit set
957 * then there are no buffers to be downloaded, and the operation is
958 * considered a success.
960 bh = (struct ice_buf_hdr *)bufs;
961 if (LE32_TO_CPU(bh->section_entry[0].type) & ICE_METADATA_BUF)
964 /* reset pkg_dwnld_status in case this function is called in the
967 hw->pkg_dwnld_status = ICE_AQ_RC_OK;
969 status = ice_acquire_global_cfg_lock(hw, ICE_RES_WRITE);
971 if (status == ICE_ERR_AQ_NO_WORK)
972 hw->pkg_dwnld_status = ICE_AQ_RC_EEXIST;
974 hw->pkg_dwnld_status = hw->adminq.sq_last_status;
978 for (i = 0; i < count; i++) {
979 bool last = ((i + 1) == count);
982 /* check next buffer for metadata flag */
983 bh = (struct ice_buf_hdr *)(bufs + i + 1);
985 /* A set metadata flag in the next buffer will signal
986 * that the current buffer will be the last buffer
989 if (LE16_TO_CPU(bh->section_count))
990 if (LE32_TO_CPU(bh->section_entry[0].type) &
995 bh = (struct ice_buf_hdr *)(bufs + i);
997 status = ice_aq_download_pkg(hw, bh, ICE_PKG_BUF_SIZE, last,
998 &offset, &info, NULL);
1000 /* Save AQ status from download package */
1001 hw->pkg_dwnld_status = hw->adminq.sq_last_status;
1003 ice_debug(hw, ICE_DBG_PKG,
1004 "Pkg download failed: err %d off %d inf %d\n",
1005 status, offset, info);
1013 ice_release_global_cfg_lock(hw);
1019 * ice_aq_get_pkg_info_list
1020 * @hw: pointer to the hardware structure
1021 * @pkg_info: the buffer which will receive the information list
1022 * @buf_size: the size of the pkg_info information buffer
1023 * @cd: pointer to command details structure or NULL
1025 * Get Package Info List (0x0C43)
1027 static enum ice_status
1028 ice_aq_get_pkg_info_list(struct ice_hw *hw,
1029 struct ice_aqc_get_pkg_info_resp *pkg_info,
1030 u16 buf_size, struct ice_sq_cd *cd)
1032 struct ice_aq_desc desc;
1034 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1035 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_pkg_info_list);
1037 return ice_aq_send_cmd(hw, &desc, pkg_info, buf_size, cd);
1042 * @hw: pointer to the hardware structure
1043 * @ice_seg: pointer to the segment of the package to be downloaded
1045 * Handles the download of a complete package.
1047 static enum ice_status
1048 ice_download_pkg(struct ice_hw *hw, struct ice_seg *ice_seg)
1050 struct ice_buf_table *ice_buf_tbl;
1052 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1053 ice_debug(hw, ICE_DBG_PKG, "Segment version: %d.%d.%d.%d\n",
1054 ice_seg->hdr.seg_ver.major, ice_seg->hdr.seg_ver.minor,
1055 ice_seg->hdr.seg_ver.update, ice_seg->hdr.seg_ver.draft);
1057 ice_debug(hw, ICE_DBG_PKG, "Seg: type 0x%X, size %d, name %s\n",
1058 LE32_TO_CPU(ice_seg->hdr.seg_type),
1059 LE32_TO_CPU(ice_seg->hdr.seg_size), ice_seg->hdr.seg_name);
1061 ice_buf_tbl = ice_find_buf_table(ice_seg);
1063 ice_debug(hw, ICE_DBG_PKG, "Seg buf count: %d\n",
1064 LE32_TO_CPU(ice_buf_tbl->buf_count));
1066 return ice_dwnld_cfg_bufs(hw, ice_buf_tbl->buf_array,
1067 LE32_TO_CPU(ice_buf_tbl->buf_count));
1072 * @hw: pointer to the hardware structure
1073 * @pkg_hdr: pointer to the driver's package hdr
1075 * Saves off the package details into the HW structure.
1077 static enum ice_status
1078 ice_init_pkg_info(struct ice_hw *hw, struct ice_pkg_hdr *pkg_hdr)
1080 struct ice_global_metadata_seg *meta_seg;
1081 struct ice_generic_seg_hdr *seg_hdr;
1083 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1085 return ICE_ERR_PARAM;
1087 meta_seg = (struct ice_global_metadata_seg *)
1088 ice_find_seg_in_pkg(hw, SEGMENT_TYPE_METADATA, pkg_hdr);
1090 hw->pkg_ver = meta_seg->pkg_ver;
1091 ice_memcpy(hw->pkg_name, meta_seg->pkg_name,
1092 sizeof(hw->pkg_name), ICE_NONDMA_TO_NONDMA);
1094 ice_debug(hw, ICE_DBG_PKG, "Pkg: %d.%d.%d.%d, %s\n",
1095 meta_seg->pkg_ver.major, meta_seg->pkg_ver.minor,
1096 meta_seg->pkg_ver.update, meta_seg->pkg_ver.draft,
1097 meta_seg->pkg_name);
1099 ice_debug(hw, ICE_DBG_INIT,
1100 "Did not find metadata segment in driver package\n");
1104 seg_hdr = ice_find_seg_in_pkg(hw, SEGMENT_TYPE_ICE, pkg_hdr);
1106 hw->ice_pkg_ver = seg_hdr->seg_ver;
1107 ice_memcpy(hw->ice_pkg_name, seg_hdr->seg_name,
1108 sizeof(hw->ice_pkg_name), ICE_NONDMA_TO_NONDMA);
1110 ice_debug(hw, ICE_DBG_PKG, "Ice Pkg: %d.%d.%d.%d, %s\n",
1111 seg_hdr->seg_ver.major, seg_hdr->seg_ver.minor,
1112 seg_hdr->seg_ver.update, seg_hdr->seg_ver.draft,
1115 ice_debug(hw, ICE_DBG_INIT,
1116 "Did not find ice segment in driver package\n");
1125 * @hw: pointer to the hardware structure
1127 * Store details of the package currently loaded in HW into the HW structure.
1129 static enum ice_status ice_get_pkg_info(struct ice_hw *hw)
1131 struct ice_aqc_get_pkg_info_resp *pkg_info;
1132 enum ice_status status;
1136 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1138 size = sizeof(*pkg_info) + (sizeof(pkg_info->pkg_info[0]) *
1140 pkg_info = (struct ice_aqc_get_pkg_info_resp *)ice_malloc(hw, size);
1142 return ICE_ERR_NO_MEMORY;
1144 status = ice_aq_get_pkg_info_list(hw, pkg_info, size, NULL);
1146 goto init_pkg_free_alloc;
1148 for (i = 0; i < LE32_TO_CPU(pkg_info->count); i++) {
1149 #define ICE_PKG_FLAG_COUNT 4
1150 char flags[ICE_PKG_FLAG_COUNT + 1] = { 0 };
1153 if (pkg_info->pkg_info[i].is_active) {
1154 flags[place++] = 'A';
1155 hw->active_pkg_ver = pkg_info->pkg_info[i].ver;
1156 ice_memcpy(hw->active_pkg_name,
1157 pkg_info->pkg_info[i].name,
1158 sizeof(hw->active_pkg_name),
1159 ICE_NONDMA_TO_NONDMA);
1160 hw->active_pkg_in_nvm = pkg_info->pkg_info[i].is_in_nvm;
1162 if (pkg_info->pkg_info[i].is_active_at_boot)
1163 flags[place++] = 'B';
1164 if (pkg_info->pkg_info[i].is_modified)
1165 flags[place++] = 'M';
1166 if (pkg_info->pkg_info[i].is_in_nvm)
1167 flags[place++] = 'N';
1169 ice_debug(hw, ICE_DBG_PKG, "Pkg[%d]: %d.%d.%d.%d,%s,%s\n",
1170 i, pkg_info->pkg_info[i].ver.major,
1171 pkg_info->pkg_info[i].ver.minor,
1172 pkg_info->pkg_info[i].ver.update,
1173 pkg_info->pkg_info[i].ver.draft,
1174 pkg_info->pkg_info[i].name, flags);
1177 init_pkg_free_alloc:
1178 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_fd_mask_regs - initialize Flow Director mask registers
1253 * @hw: pointer to the HW struct
1255 * This function sets up the Flow Director mask registers to allow for complete
1256 * masking off of any of the 24 Field Vector words. After this call, mask 0 will
1257 * mask off all of FV index 0, mask 1 will mask off all of FV index 1, etc.
1259 static void ice_init_fd_mask_regs(struct ice_hw *hw)
1263 for (i = 0; i < hw->blk[ICE_BLK_FD].es.fvw; i++) {
1264 wr32(hw, GLQF_FDMASK(i), i);
1265 ice_debug(hw, ICE_DBG_INIT, "init fd mask(%d): %x = %x\n", i,
1271 * ice_init_pkg_regs - initialize additional package registers
1272 * @hw: pointer to the hardware structure
1274 static void ice_init_pkg_regs(struct ice_hw *hw)
1276 #define ICE_SW_BLK_INP_MASK_L 0xFFFFFFFF
1277 #define ICE_SW_BLK_INP_MASK_H 0x0000FFFF
1278 #define ICE_SW_BLK_IDX 0
1280 /* setup Switch block input mask, which is 48-bits in two parts */
1281 wr32(hw, GL_PREEXT_L2_PMASK0(ICE_SW_BLK_IDX), ICE_SW_BLK_INP_MASK_L);
1282 wr32(hw, GL_PREEXT_L2_PMASK1(ICE_SW_BLK_IDX), ICE_SW_BLK_INP_MASK_H);
1283 /* setup default flow director masks */
1284 ice_init_fd_mask_regs(hw);
1288 * ice_chk_pkg_version - check package version for compatibility with driver
1289 * @hw: pointer to the hardware structure
1290 * @pkg_ver: pointer to a version structure to check
1292 * Check to make sure that the package about to be downloaded is compatible with
1293 * the driver. To be compatible, the major and minor components of the package
1294 * version must match our ICE_PKG_SUPP_VER_MAJ and ICE_PKG_SUPP_VER_MNR
1297 static enum ice_status
1298 ice_chk_pkg_version(struct ice_hw *hw, struct ice_pkg_ver *pkg_ver)
1300 if (pkg_ver->major != ICE_PKG_SUPP_VER_MAJ ||
1301 pkg_ver->minor != ICE_PKG_SUPP_VER_MNR) {
1302 ice_info(hw, "ERROR: Incompatible package: %d.%d.%d.%d - requires package version: %d.%d.*.*\n",
1303 pkg_ver->major, pkg_ver->minor, pkg_ver->update,
1304 pkg_ver->draft, ICE_PKG_SUPP_VER_MAJ,
1305 ICE_PKG_SUPP_VER_MNR);
1307 return ICE_ERR_NOT_SUPPORTED;
1314 * ice_init_pkg - initialize/download package
1315 * @hw: pointer to the hardware structure
1316 * @buf: pointer to the package buffer
1317 * @len: size of the package buffer
1319 * This function initializes a package. The package contains HW tables
1320 * required to do packet processing. First, the function extracts package
1321 * information such as version. Then it finds the ice configuration segment
1322 * within the package; this function then saves a copy of the segment pointer
1323 * within the supplied package buffer. Next, the function will cache any hints
1324 * from the package, followed by downloading the package itself. Note, that if
1325 * a previous PF driver has already downloaded the package successfully, then
1326 * the current driver will not have to download the package again.
1328 * The local package contents will be used to query default behavior and to
1329 * update specific sections of the HW's version of the package (e.g. to update
1330 * the parse graph to understand new protocols).
1332 * This function stores a pointer to the package buffer memory, and it is
1333 * expected that the supplied buffer will not be freed immediately. If the
1334 * package buffer needs to be freed, such as when read from a file, use
1335 * ice_copy_and_init_pkg() instead of directly calling ice_init_pkg() in this
1338 enum ice_status ice_init_pkg(struct ice_hw *hw, u8 *buf, u32 len)
1340 struct ice_pkg_hdr *pkg;
1341 enum ice_status status;
1342 struct ice_seg *seg;
1345 return ICE_ERR_PARAM;
1347 pkg = (struct ice_pkg_hdr *)buf;
1348 status = ice_verify_pkg(pkg, len);
1350 ice_debug(hw, ICE_DBG_INIT, "failed to verify pkg (err: %d)\n",
1355 /* initialize package info */
1356 status = ice_init_pkg_info(hw, pkg);
1360 /* before downloading the package, check package version for
1361 * compatibility with driver
1363 status = ice_chk_pkg_version(hw, &hw->pkg_ver);
1367 /* find segment in given package */
1368 seg = (struct ice_seg *)ice_find_seg_in_pkg(hw, SEGMENT_TYPE_ICE, pkg);
1370 ice_debug(hw, ICE_DBG_INIT, "no ice segment in package.\n");
1374 /* initialize package hints and then download package */
1375 ice_init_pkg_hints(hw, seg);
1376 status = ice_download_pkg(hw, seg);
1377 if (status == ICE_ERR_AQ_NO_WORK) {
1378 ice_debug(hw, ICE_DBG_INIT,
1379 "package previously loaded - no work.\n");
1380 status = ICE_SUCCESS;
1383 /* Get information on the package currently loaded in HW, then make sure
1384 * the driver is compatible with this version.
1387 status = ice_get_pkg_info(hw);
1389 status = ice_chk_pkg_version(hw, &hw->active_pkg_ver);
1394 /* on successful package download update other required
1395 * registers to support the package and fill HW tables
1396 * with package content.
1398 ice_init_pkg_regs(hw);
1399 ice_fill_blk_tbls(hw);
1401 ice_debug(hw, ICE_DBG_INIT, "package load failed, %d\n",
1409 * ice_copy_and_init_pkg - initialize/download a copy of the package
1410 * @hw: pointer to the hardware structure
1411 * @buf: pointer to the package buffer
1412 * @len: size of the package buffer
1414 * This function copies the package buffer, and then calls ice_init_pkg() to
1415 * initialize the copied package contents.
1417 * The copying is necessary if the package buffer supplied is constant, or if
1418 * the memory may disappear shortly after calling this function.
1420 * If the package buffer resides in the data segment and can be modified, the
1421 * caller is free to use ice_init_pkg() instead of ice_copy_and_init_pkg().
1423 * However, if the package buffer needs to be copied first, such as when being
1424 * read from a file, the caller should use ice_copy_and_init_pkg().
1426 * This function will first copy the package buffer, before calling
1427 * ice_init_pkg(). The caller is free to immediately destroy the original
1428 * package buffer, as the new copy will be managed by this function and
1431 enum ice_status ice_copy_and_init_pkg(struct ice_hw *hw, const u8 *buf, u32 len)
1433 enum ice_status status;
1437 return ICE_ERR_PARAM;
1439 buf_copy = (u8 *)ice_memdup(hw, buf, len, ICE_NONDMA_TO_NONDMA);
1441 status = ice_init_pkg(hw, buf_copy, len);
1443 /* Free the copy, since we failed to initialize the package */
1444 ice_free(hw, buf_copy);
1446 /* Track the copied pkg so we can free it later */
1447 hw->pkg_copy = buf_copy;
1456 * @hw: pointer to the HW structure
1458 * Allocates a package buffer and returns a pointer to the buffer header.
1459 * Note: all package contents must be in Little Endian form.
1461 static struct ice_buf_build *ice_pkg_buf_alloc(struct ice_hw *hw)
1463 struct ice_buf_build *bld;
1464 struct ice_buf_hdr *buf;
1466 bld = (struct ice_buf_build *)ice_malloc(hw, sizeof(*bld));
1470 buf = (struct ice_buf_hdr *)bld;
1471 buf->data_end = CPU_TO_LE16(sizeof(*buf) -
1472 sizeof(buf->section_entry[0]));
1478 * @sect_type: section type
1479 * @section: pointer to section
1480 * @index: index of the field vector entry to be returned
1481 * @offset: ptr to variable that receives the offset in the field vector table
1483 * This is a callback function that can be passed to ice_pkg_enum_entry.
1484 * This function treats the given section as of type ice_sw_fv_section and
1485 * enumerates offset field. "offset" is an index into the field vector
1489 ice_sw_fv_handler(u32 sect_type, void *section, u32 index, u32 *offset)
1491 struct ice_sw_fv_section *fv_section =
1492 (struct ice_sw_fv_section *)section;
1494 if (!section || sect_type != ICE_SID_FLD_VEC_SW)
1496 if (index >= LE16_TO_CPU(fv_section->count))
1499 /* "index" passed in to this function is relative to a given
1500 * 4k block. To get to the true index into the field vector
1501 * table need to add the relative index to the base_offset
1502 * field of this section
1504 *offset = LE16_TO_CPU(fv_section->base_offset) + index;
1505 return fv_section->fv + index;
1509 * ice_get_sw_prof_type - determine switch profile type
1510 * @hw: pointer to the HW structure
1511 * @fv: pointer to the switch field vector
1513 static enum ice_prof_type
1514 ice_get_sw_prof_type(struct ice_hw *hw, struct ice_fv *fv)
1518 for (i = 0; i < hw->blk[ICE_BLK_SW].es.fvw; i++) {
1519 /* UDP tunnel will have UDP_OF protocol ID and VNI offset */
1520 if (fv->ew[i].prot_id == (u8)ICE_PROT_UDP_OF &&
1521 fv->ew[i].off == ICE_VNI_OFFSET)
1522 return ICE_PROF_TUN_UDP;
1524 /* GRE tunnel will have GRE protocol */
1525 if (fv->ew[i].prot_id == (u8)ICE_PROT_GRE_OF)
1526 return ICE_PROF_TUN_GRE;
1528 /* PPPOE tunnel will have PPPOE protocol */
1529 if (fv->ew[i].prot_id == (u8)ICE_PROT_PPPOE)
1530 return ICE_PROF_TUN_PPPOE;
1533 return ICE_PROF_NON_TUN;
1537 * ice_get_sw_fv_bitmap - Get switch field vector bitmap based on profile type
1538 * @hw: pointer to hardware structure
1539 * @type: type of profiles requested
1540 * @bm: pointer to memory for returning the bitmap of field vectors
1543 ice_get_sw_fv_bitmap(struct ice_hw *hw, enum ice_prof_type type,
1546 struct ice_pkg_enum state;
1547 struct ice_seg *ice_seg;
1550 if (type == ICE_PROF_ALL) {
1553 for (i = 0; i < ICE_MAX_NUM_PROFILES; i++)
1558 ice_zero_bitmap(bm, ICE_MAX_NUM_PROFILES);
1562 enum ice_prof_type prof_type;
1565 fv = (struct ice_fv *)
1566 ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1567 &offset, ice_sw_fv_handler);
1571 /* Determine field vector type */
1572 prof_type = ice_get_sw_prof_type(hw, fv);
1574 if (type & prof_type)
1575 ice_set_bit((u16)offset, bm);
1581 * ice_get_sw_fv_list
1582 * @hw: pointer to the HW structure
1583 * @prot_ids: field vector to search for with a given protocol ID
1584 * @ids_cnt: lookup/protocol count
1585 * @bm: bitmap of field vectors to consider
1586 * @fv_list: Head of a list
1588 * Finds all the field vector entries from switch block that contain
1589 * a given protocol ID and returns a list of structures of type
1590 * "ice_sw_fv_list_entry". Every structure in the list has a field vector
1591 * definition and profile ID information
1592 * NOTE: The caller of the function is responsible for freeing the memory
1593 * allocated for every list entry.
1596 ice_get_sw_fv_list(struct ice_hw *hw, u16 *prot_ids, u8 ids_cnt,
1597 ice_bitmap_t *bm, struct LIST_HEAD_TYPE *fv_list)
1599 struct ice_sw_fv_list_entry *fvl;
1600 struct ice_sw_fv_list_entry *tmp;
1601 struct ice_pkg_enum state;
1602 struct ice_seg *ice_seg;
1606 if (!ids_cnt || !hw->seg)
1607 return ICE_ERR_PARAM;
1613 fv = (struct ice_fv *)
1614 ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1615 &offset, ice_sw_fv_handler);
1620 /* If field vector is not in the bitmap list, then skip this
1623 if (!ice_is_bit_set(bm, (u16)offset))
1626 for (i = 0; i < ids_cnt; i++) {
1629 /* This code assumes that if a switch field vector line
1630 * has a matching protocol, then this line will contain
1631 * the entries necessary to represent every field in
1632 * that protocol header.
1634 for (j = 0; j < hw->blk[ICE_BLK_SW].es.fvw; j++)
1635 if (fv->ew[j].prot_id == prot_ids[i])
1637 if (j >= hw->blk[ICE_BLK_SW].es.fvw)
1639 if (i + 1 == ids_cnt) {
1640 fvl = (struct ice_sw_fv_list_entry *)
1641 ice_malloc(hw, sizeof(*fvl));
1645 fvl->profile_id = offset;
1646 LIST_ADD(&fvl->list_entry, fv_list);
1651 if (LIST_EMPTY(fv_list))
1656 LIST_FOR_EACH_ENTRY_SAFE(fvl, tmp, fv_list, ice_sw_fv_list_entry,
1658 LIST_DEL(&fvl->list_entry);
1662 return ICE_ERR_NO_MEMORY;
1667 * @hw: pointer to the HW structure
1668 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1670 * Frees a package buffer
1672 static void ice_pkg_buf_free(struct ice_hw *hw, struct ice_buf_build *bld)
1678 * ice_pkg_buf_reserve_section
1679 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1680 * @count: the number of sections to reserve
1682 * Reserves one or more section table entries in a package buffer. This routine
1683 * can be called multiple times as long as they are made before calling
1684 * ice_pkg_buf_alloc_section(). Once ice_pkg_buf_alloc_section()
1685 * is called once, the number of sections that can be allocated will not be able
1686 * to be increased; not using all reserved sections is fine, but this will
1687 * result in some wasted space in the buffer.
1688 * Note: all package contents must be in Little Endian form.
1690 static enum ice_status
1691 ice_pkg_buf_reserve_section(struct ice_buf_build *bld, u16 count)
1693 struct ice_buf_hdr *buf;
1698 return ICE_ERR_PARAM;
1700 buf = (struct ice_buf_hdr *)&bld->buf;
1702 /* already an active section, can't increase table size */
1703 section_count = LE16_TO_CPU(buf->section_count);
1704 if (section_count > 0)
1707 if (bld->reserved_section_table_entries + count > ICE_MAX_S_COUNT)
1709 bld->reserved_section_table_entries += count;
1711 data_end = LE16_TO_CPU(buf->data_end) +
1712 (count * sizeof(buf->section_entry[0]));
1713 buf->data_end = CPU_TO_LE16(data_end);
1719 * ice_pkg_buf_alloc_section
1720 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1721 * @type: the section type value
1722 * @size: the size of the section to reserve (in bytes)
1724 * Reserves memory in the buffer for a section's content and updates the
1725 * buffers' status accordingly. This routine returns a pointer to the first
1726 * byte of the section start within the buffer, which is used to fill in the
1728 * Note: all package contents must be in Little Endian form.
1731 ice_pkg_buf_alloc_section(struct ice_buf_build *bld, u32 type, u16 size)
1733 struct ice_buf_hdr *buf;
1737 if (!bld || !type || !size)
1740 buf = (struct ice_buf_hdr *)&bld->buf;
1742 /* check for enough space left in buffer */
1743 data_end = LE16_TO_CPU(buf->data_end);
1745 /* section start must align on 4 byte boundary */
1746 data_end = ICE_ALIGN(data_end, 4);
1748 if ((data_end + size) > ICE_MAX_S_DATA_END)
1751 /* check for more available section table entries */
1752 sect_count = LE16_TO_CPU(buf->section_count);
1753 if (sect_count < bld->reserved_section_table_entries) {
1754 void *section_ptr = ((u8 *)buf) + data_end;
1756 buf->section_entry[sect_count].offset = CPU_TO_LE16(data_end);
1757 buf->section_entry[sect_count].size = CPU_TO_LE16(size);
1758 buf->section_entry[sect_count].type = CPU_TO_LE32(type);
1761 buf->data_end = CPU_TO_LE16(data_end);
1763 buf->section_count = CPU_TO_LE16(sect_count + 1);
1767 /* no free section table entries */
1772 * ice_pkg_buf_get_active_sections
1773 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1775 * Returns the number of active sections. Before using the package buffer
1776 * in an update package command, the caller should make sure that there is at
1777 * least one active section - otherwise, the buffer is not legal and should
1779 * Note: all package contents must be in Little Endian form.
1781 static u16 ice_pkg_buf_get_active_sections(struct ice_buf_build *bld)
1783 struct ice_buf_hdr *buf;
1788 buf = (struct ice_buf_hdr *)&bld->buf;
1789 return LE16_TO_CPU(buf->section_count);
1793 * ice_pkg_buf_header
1794 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1796 * Return a pointer to the buffer's header
1798 static struct ice_buf *ice_pkg_buf(struct ice_buf_build *bld)
1807 * ice_tunnel_port_in_use
1808 * @hw: pointer to the HW structure
1809 * @port: port to search for
1810 * @index: optionally returns index
1812 * Returns whether a port is already in use as a tunnel, and optionally its
1815 bool ice_tunnel_port_in_use(struct ice_hw *hw, u16 port, u16 *index)
1819 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
1820 if (hw->tnl.tbl[i].in_use && hw->tnl.tbl[i].port == port) {
1830 * ice_tunnel_get_type
1831 * @hw: pointer to the HW structure
1832 * @port: port to search for
1833 * @type: returns tunnel index
1835 * For a given port number, will return the type of tunnel.
1838 ice_tunnel_get_type(struct ice_hw *hw, u16 port, enum ice_tunnel_type *type)
1842 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
1843 if (hw->tnl.tbl[i].in_use && hw->tnl.tbl[i].port == port) {
1844 *type = hw->tnl.tbl[i].type;
1852 * ice_find_free_tunnel_entry
1853 * @hw: pointer to the HW structure
1854 * @type: tunnel type
1855 * @index: optionally returns index
1857 * Returns whether there is a free tunnel entry, and optionally its index
1860 ice_find_free_tunnel_entry(struct ice_hw *hw, enum ice_tunnel_type type,
1865 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
1866 if (hw->tnl.tbl[i].valid && !hw->tnl.tbl[i].in_use &&
1867 hw->tnl.tbl[i].type == type) {
1877 * ice_get_tunnel_port - retrieve an open tunnel port
1878 * @hw: pointer to the HW structure
1879 * @type: tunnel type (TNL_ALL will return any open port)
1880 * @port: returns open port
1883 ice_get_open_tunnel_port(struct ice_hw *hw, enum ice_tunnel_type type,
1888 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
1889 if (hw->tnl.tbl[i].valid && hw->tnl.tbl[i].in_use &&
1890 (type == TNL_ALL || hw->tnl.tbl[i].type == type)) {
1891 *port = hw->tnl.tbl[i].port;
1900 * @hw: pointer to the HW structure
1901 * @type: type of tunnel
1902 * @port: port to use for vxlan tunnel
1907 ice_create_tunnel(struct ice_hw *hw, enum ice_tunnel_type type, u16 port)
1909 struct ice_boost_tcam_section *sect_rx, *sect_tx;
1910 enum ice_status status = ICE_ERR_MAX_LIMIT;
1911 struct ice_buf_build *bld;
1914 if (ice_tunnel_port_in_use(hw, port, NULL))
1915 return ICE_ERR_ALREADY_EXISTS;
1917 if (!ice_find_free_tunnel_entry(hw, type, &index))
1918 return ICE_ERR_OUT_OF_RANGE;
1920 bld = ice_pkg_buf_alloc(hw);
1922 return ICE_ERR_NO_MEMORY;
1924 /* allocate 2 sections, one for Rx parser, one for Tx parser */
1925 if (ice_pkg_buf_reserve_section(bld, 2))
1926 goto ice_create_tunnel_err;
1928 sect_rx = (struct ice_boost_tcam_section *)
1929 ice_pkg_buf_alloc_section(bld, ICE_SID_RXPARSER_BOOST_TCAM,
1932 goto ice_create_tunnel_err;
1933 sect_rx->count = CPU_TO_LE16(1);
1935 sect_tx = (struct ice_boost_tcam_section *)
1936 ice_pkg_buf_alloc_section(bld, ICE_SID_TXPARSER_BOOST_TCAM,
1939 goto ice_create_tunnel_err;
1940 sect_tx->count = CPU_TO_LE16(1);
1942 /* copy original boost entry to update package buffer */
1943 ice_memcpy(sect_rx->tcam, hw->tnl.tbl[index].boost_entry,
1944 sizeof(*sect_rx->tcam), ICE_NONDMA_TO_NONDMA);
1946 /* over-write the never-match dest port key bits with the encoded port
1949 ice_set_key((u8 *)§_rx->tcam[0].key, sizeof(sect_rx->tcam[0].key),
1950 (u8 *)&port, NULL, NULL, NULL,
1951 offsetof(struct ice_boost_key_value, hv_dst_port_key),
1952 sizeof(sect_rx->tcam[0].key.key.hv_dst_port_key));
1954 /* exact copy of entry to Tx section entry */
1955 ice_memcpy(sect_tx->tcam, sect_rx->tcam, sizeof(*sect_tx->tcam),
1956 ICE_NONDMA_TO_NONDMA);
1958 status = ice_update_pkg(hw, ice_pkg_buf(bld), 1);
1960 hw->tnl.tbl[index].port = port;
1961 hw->tnl.tbl[index].in_use = true;
1964 ice_create_tunnel_err:
1965 ice_pkg_buf_free(hw, bld);
1971 * ice_destroy_tunnel
1972 * @hw: pointer to the HW structure
1973 * @port: port of tunnel to destroy (ignored if the all parameter is true)
1974 * @all: flag that states to destroy all tunnels
1976 * Destroys a tunnel or all tunnels by creating an update package buffer
1977 * targeting the specific updates requested and then performing an update
1980 enum ice_status ice_destroy_tunnel(struct ice_hw *hw, u16 port, bool all)
1982 struct ice_boost_tcam_section *sect_rx, *sect_tx;
1983 enum ice_status status = ICE_ERR_MAX_LIMIT;
1984 struct ice_buf_build *bld;
1989 /* determine count */
1990 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
1991 if (hw->tnl.tbl[i].valid && hw->tnl.tbl[i].in_use &&
1992 (all || hw->tnl.tbl[i].port == port))
1996 return ICE_ERR_PARAM;
1998 /* size of section - there is at least one entry */
1999 size = (count - 1) * sizeof(*sect_rx->tcam) + sizeof(*sect_rx);
2001 bld = ice_pkg_buf_alloc(hw);
2003 return ICE_ERR_NO_MEMORY;
2005 /* allocate 2 sections, one for Rx parser, one for Tx parser */
2006 if (ice_pkg_buf_reserve_section(bld, 2))
2007 goto ice_destroy_tunnel_err;
2009 sect_rx = (struct ice_boost_tcam_section *)
2010 ice_pkg_buf_alloc_section(bld, ICE_SID_RXPARSER_BOOST_TCAM,
2013 goto ice_destroy_tunnel_err;
2014 sect_rx->count = CPU_TO_LE16(1);
2016 sect_tx = (struct ice_boost_tcam_section *)
2017 ice_pkg_buf_alloc_section(bld, ICE_SID_TXPARSER_BOOST_TCAM,
2020 goto ice_destroy_tunnel_err;
2021 sect_tx->count = CPU_TO_LE16(1);
2023 /* copy original boost entry to update package buffer, one copy to Rx
2024 * section, another copy to the Tx section
2026 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
2027 if (hw->tnl.tbl[i].valid && hw->tnl.tbl[i].in_use &&
2028 (all || hw->tnl.tbl[i].port == port)) {
2029 ice_memcpy(sect_rx->tcam + i,
2030 hw->tnl.tbl[i].boost_entry,
2031 sizeof(*sect_rx->tcam),
2032 ICE_NONDMA_TO_NONDMA);
2033 ice_memcpy(sect_tx->tcam + i,
2034 hw->tnl.tbl[i].boost_entry,
2035 sizeof(*sect_tx->tcam),
2036 ICE_NONDMA_TO_NONDMA);
2037 hw->tnl.tbl[i].marked = true;
2040 status = ice_update_pkg(hw, ice_pkg_buf(bld), 1);
2042 for (i = 0; i < hw->tnl.count &&
2043 i < ICE_TUNNEL_MAX_ENTRIES; i++)
2044 if (hw->tnl.tbl[i].marked) {
2045 hw->tnl.tbl[i].port = 0;
2046 hw->tnl.tbl[i].in_use = false;
2047 hw->tnl.tbl[i].marked = false;
2050 ice_destroy_tunnel_err:
2051 ice_pkg_buf_free(hw, bld);
2057 * ice_find_prot_off - find prot ID and offset pair, based on prof and FV index
2058 * @hw: pointer to the hardware structure
2059 * @blk: hardware block
2061 * @fv_idx: field vector word index
2062 * @prot: variable to receive the protocol ID
2063 * @off: variable to receive the protocol offset
2066 ice_find_prot_off(struct ice_hw *hw, enum ice_block blk, u8 prof, u8 fv_idx,
2069 struct ice_fv_word *fv_ext;
2071 if (prof >= hw->blk[blk].es.count)
2072 return ICE_ERR_PARAM;
2074 if (fv_idx >= hw->blk[blk].es.fvw)
2075 return ICE_ERR_PARAM;
2077 fv_ext = hw->blk[blk].es.t + (prof * hw->blk[blk].es.fvw);
2079 *prot = fv_ext[fv_idx].prot_id;
2080 *off = fv_ext[fv_idx].off;
2085 /* PTG Management */
2089 * ice_ptg_find_ptype - Search for packet type group using packet type (ptype)
2090 * @hw: pointer to the hardware structure
2092 * @ptype: the ptype to search for
2093 * @ptg: pointer to variable that receives the PTG
2095 * This function will search the PTGs for a particular ptype, returning the
2096 * PTG ID that contains it through the ptg parameter, with the value of
2097 * ICE_DEFAULT_PTG (0) meaning it is part the default PTG.
2099 static enum ice_status
2100 ice_ptg_find_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 *ptg)
2102 if (ptype >= ICE_XLT1_CNT || !ptg)
2103 return ICE_ERR_PARAM;
2105 *ptg = hw->blk[blk].xlt1.ptypes[ptype].ptg;
2110 * ice_ptg_alloc_val - Allocates a new packet type group ID by value
2111 * @hw: pointer to the hardware structure
2113 * @ptg: the ptg to allocate
2115 * This function allocates a given packet type group ID specified by the ptg
2119 void ice_ptg_alloc_val(struct ice_hw *hw, enum ice_block blk, u8 ptg)
2121 hw->blk[blk].xlt1.ptg_tbl[ptg].in_use = true;
2126 * ice_ptg_remove_ptype - Removes ptype from a particular packet type group
2127 * @hw: pointer to the hardware structure
2129 * @ptype: the ptype to remove
2130 * @ptg: the ptg to remove the ptype from
2132 * This function will remove the ptype from the specific ptg, and move it to
2133 * the default PTG (ICE_DEFAULT_PTG).
2135 static enum ice_status
2136 ice_ptg_remove_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 ptg)
2138 struct ice_ptg_ptype **ch;
2139 struct ice_ptg_ptype *p;
2141 if (ptype > ICE_XLT1_CNT - 1)
2142 return ICE_ERR_PARAM;
2144 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].in_use)
2145 return ICE_ERR_DOES_NOT_EXIST;
2147 /* Should not happen if .in_use is set, bad config */
2148 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype)
2151 /* find the ptype within this PTG, and bypass the link over it */
2152 p = hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2153 ch = &hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2155 if (ptype == (p - hw->blk[blk].xlt1.ptypes)) {
2156 *ch = p->next_ptype;
2160 ch = &p->next_ptype;
2164 hw->blk[blk].xlt1.ptypes[ptype].ptg = ICE_DEFAULT_PTG;
2165 hw->blk[blk].xlt1.ptypes[ptype].next_ptype = NULL;
2171 * ice_ptg_add_mv_ptype - Adds/moves ptype to a particular packet type group
2172 * @hw: pointer to the hardware structure
2174 * @ptype: the ptype to add or move
2175 * @ptg: the ptg to add or move the ptype to
2177 * This function will either add or move a ptype to a particular PTG depending
2178 * on if the ptype is already part of another group. Note that using a
2179 * a destination PTG ID of ICE_DEFAULT_PTG (0) will move the ptype to the
2182 static enum ice_status
2183 ice_ptg_add_mv_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 ptg)
2185 enum ice_status status;
2188 if (ptype > ICE_XLT1_CNT - 1)
2189 return ICE_ERR_PARAM;
2191 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].in_use && ptg != ICE_DEFAULT_PTG)
2192 return ICE_ERR_DOES_NOT_EXIST;
2194 status = ice_ptg_find_ptype(hw, blk, ptype, &original_ptg);
2198 /* Is ptype already in the correct PTG? */
2199 if (original_ptg == ptg)
2202 /* Remove from original PTG and move back to the default PTG */
2203 if (original_ptg != ICE_DEFAULT_PTG)
2204 ice_ptg_remove_ptype(hw, blk, ptype, original_ptg);
2206 /* Moving to default PTG? Then we're done with this request */
2207 if (ptg == ICE_DEFAULT_PTG)
2210 /* Add ptype to PTG at beginning of list */
2211 hw->blk[blk].xlt1.ptypes[ptype].next_ptype =
2212 hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2213 hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype =
2214 &hw->blk[blk].xlt1.ptypes[ptype];
2216 hw->blk[blk].xlt1.ptypes[ptype].ptg = ptg;
2217 hw->blk[blk].xlt1.t[ptype] = ptg;
2222 /* Block / table size info */
2223 struct ice_blk_size_details {
2224 u16 xlt1; /* # XLT1 entries */
2225 u16 xlt2; /* # XLT2 entries */
2226 u16 prof_tcam; /* # profile ID TCAM entries */
2227 u16 prof_id; /* # profile IDs */
2228 u8 prof_cdid_bits; /* # cdid one-hot bits used in key */
2229 u16 prof_redir; /* # profile redirection entries */
2230 u16 es; /* # extraction sequence entries */
2231 u16 fvw; /* # field vector words */
2232 u8 overwrite; /* overwrite existing entries allowed */
2233 u8 reverse; /* reverse FV order */
2236 static const struct ice_blk_size_details blk_sizes[ICE_BLK_COUNT] = {
2239 * XLT1 - Number of entries in XLT1 table
2240 * XLT2 - Number of entries in XLT2 table
2241 * TCAM - Number of entries Profile ID TCAM table
2242 * CDID - Control Domain ID of the hardware block
2243 * PRED - Number of entries in the Profile Redirection Table
2244 * FV - Number of entries in the Field Vector
2245 * FVW - Width (in WORDs) of the Field Vector
2246 * OVR - Overwrite existing table entries
2249 /* XLT1 , XLT2 ,TCAM, PID,CDID,PRED, FV, FVW */
2250 /* Overwrite , Reverse FV */
2251 /* SW */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 256, 0, 256, 256, 48,
2253 /* ACL */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 32,
2255 /* FD */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 24,
2257 /* RSS */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 24,
2259 /* PE */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 64, 32, 0, 32, 32, 24,
2264 ICE_SID_XLT1_OFF = 0,
2267 ICE_SID_PR_REDIR_OFF,
2272 /* Characteristic handling */
2275 * ice_match_prop_lst - determine if properties of two lists match
2276 * @list1: first properties list
2277 * @list2: second properties list
2279 * Count, cookies and the order must match in order to be considered equivalent.
2282 ice_match_prop_lst(struct LIST_HEAD_TYPE *list1, struct LIST_HEAD_TYPE *list2)
2284 struct ice_vsig_prof *tmp1;
2285 struct ice_vsig_prof *tmp2;
2289 /* compare counts */
2290 LIST_FOR_EACH_ENTRY(tmp1, list1, ice_vsig_prof, list) {
2293 LIST_FOR_EACH_ENTRY(tmp2, list2, ice_vsig_prof, list) {
2296 if (!count || count != chk_count)
2299 tmp1 = LIST_FIRST_ENTRY(list1, struct ice_vsig_prof, list);
2300 tmp2 = LIST_FIRST_ENTRY(list2, struct ice_vsig_prof, list);
2302 /* profile cookies must compare, and in the exact same order to take
2303 * into account priority
2306 if (tmp2->profile_cookie != tmp1->profile_cookie)
2309 tmp1 = LIST_NEXT_ENTRY(tmp1, struct ice_vsig_prof, list);
2310 tmp2 = LIST_NEXT_ENTRY(tmp2, struct ice_vsig_prof, list);
2316 /* VSIG Management */
2320 * ice_vsig_find_vsi - find a VSIG that contains a specified VSI
2321 * @hw: pointer to the hardware structure
2323 * @vsi: VSI of interest
2324 * @vsig: pointer to receive the VSI group
2326 * This function will lookup the VSI entry in the XLT2 list and return
2327 * the VSI group its associated with.
2330 ice_vsig_find_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 *vsig)
2332 if (!vsig || vsi >= ICE_MAX_VSI)
2333 return ICE_ERR_PARAM;
2335 /* As long as there's a default or valid VSIG associated with the input
2336 * VSI, the functions returns a success. Any handling of VSIG will be
2337 * done by the following add, update or remove functions.
2339 *vsig = hw->blk[blk].xlt2.vsis[vsi].vsig;
2345 * ice_vsig_alloc_val - allocate a new VSIG by value
2346 * @hw: pointer to the hardware structure
2348 * @vsig: the vsig to allocate
2350 * This function will allocate a given VSIG specified by the vsig parameter.
2352 static u16 ice_vsig_alloc_val(struct ice_hw *hw, enum ice_block blk, u16 vsig)
2354 u16 idx = vsig & ICE_VSIG_IDX_M;
2356 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use) {
2357 INIT_LIST_HEAD(&hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst);
2358 hw->blk[blk].xlt2.vsig_tbl[idx].in_use = true;
2361 return ICE_VSIG_VALUE(idx, hw->pf_id);
2365 * ice_vsig_alloc - Finds a free entry and allocates a new VSIG
2366 * @hw: pointer to the hardware structure
2369 * This function will iterate through the VSIG list and mark the first
2370 * unused entry for the new VSIG entry as used and return that value.
2372 static u16 ice_vsig_alloc(struct ice_hw *hw, enum ice_block blk)
2376 for (i = 1; i < ICE_MAX_VSIGS; i++)
2377 if (!hw->blk[blk].xlt2.vsig_tbl[i].in_use)
2378 return ice_vsig_alloc_val(hw, blk, i);
2380 return ICE_DEFAULT_VSIG;
2384 * ice_find_dup_props_vsig - find VSI group with a specified set of properties
2385 * @hw: pointer to the hardware structure
2387 * @chs: characteristic list
2388 * @vsig: returns the VSIG with the matching profiles, if found
2390 * Each VSIG is associated with a characteristic set; i.e. all VSIs under
2391 * a group have the same characteristic set. To check if there exists a VSIG
2392 * which has the same characteristics as the input characteristics; this
2393 * function will iterate through the XLT2 list and return the VSIG that has a
2394 * matching configuration. In order to make sure that priorities are accounted
2395 * for, the list must match exactly, including the order in which the
2396 * characteristics are listed.
2398 static enum ice_status
2399 ice_find_dup_props_vsig(struct ice_hw *hw, enum ice_block blk,
2400 struct LIST_HEAD_TYPE *chs, u16 *vsig)
2402 struct ice_xlt2 *xlt2 = &hw->blk[blk].xlt2;
2405 for (i = 0; i < xlt2->count; i++) {
2406 if (xlt2->vsig_tbl[i].in_use &&
2407 ice_match_prop_lst(chs, &xlt2->vsig_tbl[i].prop_lst)) {
2408 *vsig = ICE_VSIG_VALUE(i, hw->pf_id);
2413 return ICE_ERR_DOES_NOT_EXIST;
2417 * ice_vsig_free - free VSI group
2418 * @hw: pointer to the hardware structure
2420 * @vsig: VSIG to remove
2422 * The function will remove all VSIs associated with the input VSIG and move
2423 * them to the DEFAULT_VSIG and mark the VSIG available.
2425 static enum ice_status
2426 ice_vsig_free(struct ice_hw *hw, enum ice_block blk, u16 vsig)
2428 struct ice_vsig_prof *dtmp, *del;
2429 struct ice_vsig_vsi *vsi_cur;
2432 idx = vsig & ICE_VSIG_IDX_M;
2433 if (idx >= ICE_MAX_VSIGS)
2434 return ICE_ERR_PARAM;
2436 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
2437 return ICE_ERR_DOES_NOT_EXIST;
2439 hw->blk[blk].xlt2.vsig_tbl[idx].in_use = false;
2441 vsi_cur = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2442 /* If the VSIG has at least 1 VSI then iterate through the
2443 * list and remove the VSIs before deleting the group.
2446 /* remove all vsis associated with this VSIG XLT2 entry */
2448 struct ice_vsig_vsi *tmp = vsi_cur->next_vsi;
2450 vsi_cur->vsig = ICE_DEFAULT_VSIG;
2451 vsi_cur->changed = 1;
2452 vsi_cur->next_vsi = NULL;
2456 /* NULL terminate head of VSI list */
2457 hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi = NULL;
2460 /* free characteristic list */
2461 LIST_FOR_EACH_ENTRY_SAFE(del, dtmp,
2462 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
2463 ice_vsig_prof, list) {
2464 LIST_DEL(&del->list);
2468 /* if VSIG characteristic list was cleared for reset
2469 * re-initialize the list head
2471 INIT_LIST_HEAD(&hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst);
2477 * ice_vsig_remove_vsi - remove VSI from VSIG
2478 * @hw: pointer to the hardware structure
2480 * @vsi: VSI to remove
2481 * @vsig: VSI group to remove from
2483 * The function will remove the input VSI from its VSI group and move it
2484 * to the DEFAULT_VSIG.
2486 static enum ice_status
2487 ice_vsig_remove_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
2489 struct ice_vsig_vsi **vsi_head, *vsi_cur, *vsi_tgt;
2492 idx = vsig & ICE_VSIG_IDX_M;
2494 if (vsi >= ICE_MAX_VSI || idx >= ICE_MAX_VSIGS)
2495 return ICE_ERR_PARAM;
2497 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
2498 return ICE_ERR_DOES_NOT_EXIST;
2500 /* entry already in default VSIG, don't have to remove */
2501 if (idx == ICE_DEFAULT_VSIG)
2504 vsi_head = &hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2508 vsi_tgt = &hw->blk[blk].xlt2.vsis[vsi];
2509 vsi_cur = (*vsi_head);
2511 /* iterate the VSI list, skip over the entry to be removed */
2513 if (vsi_tgt == vsi_cur) {
2514 (*vsi_head) = vsi_cur->next_vsi;
2517 vsi_head = &vsi_cur->next_vsi;
2518 vsi_cur = vsi_cur->next_vsi;
2521 /* verify if VSI was removed from group list */
2523 return ICE_ERR_DOES_NOT_EXIST;
2525 vsi_cur->vsig = ICE_DEFAULT_VSIG;
2526 vsi_cur->changed = 1;
2527 vsi_cur->next_vsi = NULL;
2533 * ice_vsig_add_mv_vsi - add or move a VSI to a VSI group
2534 * @hw: pointer to the hardware structure
2537 * @vsig: destination VSI group
2539 * This function will move or add the input VSI to the target VSIG.
2540 * The function will find the original VSIG the VSI belongs to and
2541 * move the entry to the DEFAULT_VSIG, update the original VSIG and
2542 * then move entry to the new VSIG.
2544 static enum ice_status
2545 ice_vsig_add_mv_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
2547 struct ice_vsig_vsi *tmp;
2548 enum ice_status status;
2551 idx = vsig & ICE_VSIG_IDX_M;
2553 if (vsi >= ICE_MAX_VSI || idx >= ICE_MAX_VSIGS)
2554 return ICE_ERR_PARAM;
2556 /* if VSIG not in use and VSIG is not default type this VSIG
2559 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use &&
2560 vsig != ICE_DEFAULT_VSIG)
2561 return ICE_ERR_DOES_NOT_EXIST;
2563 status = ice_vsig_find_vsi(hw, blk, vsi, &orig_vsig);
2567 /* no update required if vsigs match */
2568 if (orig_vsig == vsig)
2571 if (orig_vsig != ICE_DEFAULT_VSIG) {
2572 /* remove entry from orig_vsig and add to default VSIG */
2573 status = ice_vsig_remove_vsi(hw, blk, vsi, orig_vsig);
2578 if (idx == ICE_DEFAULT_VSIG)
2581 /* Create VSI entry and add VSIG and prop_mask values */
2582 hw->blk[blk].xlt2.vsis[vsi].vsig = vsig;
2583 hw->blk[blk].xlt2.vsis[vsi].changed = 1;
2585 /* Add new entry to the head of the VSIG list */
2586 tmp = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2587 hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi =
2588 &hw->blk[blk].xlt2.vsis[vsi];
2589 hw->blk[blk].xlt2.vsis[vsi].next_vsi = tmp;
2590 hw->blk[blk].xlt2.t[vsi] = vsig;
2596 * ice_prof_has_mask_idx - determine if profile index masking is identical
2597 * @hw: pointer to the hardware structure
2599 * @prof: profile to check
2600 * @idx: profile index to check
2601 * @masks: masks to match
2604 ice_prof_has_mask_idx(struct ice_hw *hw, enum ice_block blk, u8 prof, u16 idx,
2607 bool expect_no_mask = false;
2612 /* If mask is 0x0000 or 0xffff, then there is no masking */
2613 if (mask == 0 || mask == 0xffff)
2614 expect_no_mask = true;
2616 /* Scan the enabled masks on this profile, for the specified idx */
2617 for (i = 0; i < ICE_PROFILE_MASK_COUNT; i++)
2618 if (hw->blk[blk].es.mask_ena[prof] & BIT(i))
2619 if (hw->blk[blk].masks.masks[i].in_use &&
2620 hw->blk[blk].masks.masks[i].idx == idx) {
2622 if (hw->blk[blk].masks.masks[i].mask == mask)
2627 if (expect_no_mask) {
2639 * ice_prof_has_mask - determine if profile masking is identical
2640 * @hw: pointer to the hardware structure
2642 * @prof: profile to check
2643 * @masks: masks to match
2646 ice_prof_has_mask(struct ice_hw *hw, enum ice_block blk, u8 prof, u16 *masks)
2650 /* es->mask_ena[prof] will have the mask */
2651 for (i = 0; i < hw->blk[blk].es.fvw; i++)
2652 if (!ice_prof_has_mask_idx(hw, blk, prof, i, masks[i]))
2659 * ice_find_prof_id_with_mask - find profile ID for a given field vector
2660 * @hw: pointer to the hardware structure
2662 * @fv: field vector to search for
2663 * @masks: masks for fv
2664 * @prof_id: receives the profile ID
2666 static enum ice_status
2667 ice_find_prof_id_with_mask(struct ice_hw *hw, enum ice_block blk,
2668 struct ice_fv_word *fv, u16 *masks, u8 *prof_id)
2670 struct ice_es *es = &hw->blk[blk].es;
2673 for (i = 0; i < es->count; i++) {
2674 u16 off = i * es->fvw;
2677 if (memcmp(&es->t[off], fv, es->fvw * sizeof(*fv)))
2680 /* check if masks settings are the same for this profile */
2681 if (!ice_prof_has_mask(hw, blk, i, masks))
2688 return ICE_ERR_DOES_NOT_EXIST;
2692 * ice_find_prof_id - find profile ID for a given field vector
2693 * @hw: pointer to the hardware structure
2695 * @fv: field vector to search for
2696 * @prof_id: receives the profile ID
2698 static enum ice_status
2699 ice_find_prof_id(struct ice_hw *hw, enum ice_block blk,
2700 struct ice_fv_word *fv, u8 *prof_id)
2702 struct ice_es *es = &hw->blk[blk].es;
2705 for (i = 0; i < es->count; i++) {
2708 if (memcmp(&es->t[off], fv, es->fvw * sizeof(*fv)))
2715 return ICE_ERR_DOES_NOT_EXIST;
2719 * ice_prof_id_rsrc_type - get profile ID resource type for a block type
2720 * @blk: the block type
2721 * @rsrc_type: pointer to variable to receive the resource type
2723 static bool ice_prof_id_rsrc_type(enum ice_block blk, u16 *rsrc_type)
2727 *rsrc_type = ICE_AQC_RES_TYPE_SWITCH_PROF_BLDR_PROFID;
2730 *rsrc_type = ICE_AQC_RES_TYPE_ACL_PROF_BLDR_PROFID;
2733 *rsrc_type = ICE_AQC_RES_TYPE_FD_PROF_BLDR_PROFID;
2736 *rsrc_type = ICE_AQC_RES_TYPE_HASH_PROF_BLDR_PROFID;
2739 *rsrc_type = ICE_AQC_RES_TYPE_QHASH_PROF_BLDR_PROFID;
2748 * ice_tcam_ent_rsrc_type - get TCAM entry resource type for a block type
2749 * @blk: the block type
2750 * @rsrc_type: pointer to variable to receive the resource type
2752 static bool ice_tcam_ent_rsrc_type(enum ice_block blk, u16 *rsrc_type)
2756 *rsrc_type = ICE_AQC_RES_TYPE_SWITCH_PROF_BLDR_TCAM;
2759 *rsrc_type = ICE_AQC_RES_TYPE_ACL_PROF_BLDR_TCAM;
2762 *rsrc_type = ICE_AQC_RES_TYPE_FD_PROF_BLDR_TCAM;
2765 *rsrc_type = ICE_AQC_RES_TYPE_HASH_PROF_BLDR_TCAM;
2768 *rsrc_type = ICE_AQC_RES_TYPE_QHASH_PROF_BLDR_TCAM;
2777 * ice_alloc_tcam_ent - allocate hardware TCAM entry
2778 * @hw: pointer to the HW struct
2779 * @blk: the block to allocate the TCAM for
2780 * @tcam_idx: pointer to variable to receive the TCAM entry
2782 * This function allocates a new entry in a Profile ID TCAM for a specific
2785 static enum ice_status
2786 ice_alloc_tcam_ent(struct ice_hw *hw, enum ice_block blk, u16 *tcam_idx)
2790 if (!ice_tcam_ent_rsrc_type(blk, &res_type))
2791 return ICE_ERR_PARAM;
2793 return ice_alloc_hw_res(hw, res_type, 1, true, tcam_idx);
2797 * ice_free_tcam_ent - free hardware TCAM entry
2798 * @hw: pointer to the HW struct
2799 * @blk: the block from which to free the TCAM entry
2800 * @tcam_idx: the TCAM entry to free
2802 * This function frees an entry in a Profile ID TCAM for a specific block.
2804 static enum ice_status
2805 ice_free_tcam_ent(struct ice_hw *hw, enum ice_block blk, u16 tcam_idx)
2809 if (!ice_tcam_ent_rsrc_type(blk, &res_type))
2810 return ICE_ERR_PARAM;
2812 return ice_free_hw_res(hw, res_type, 1, &tcam_idx);
2816 * ice_alloc_prof_id - allocate profile ID
2817 * @hw: pointer to the HW struct
2818 * @blk: the block to allocate the profile ID for
2819 * @prof_id: pointer to variable to receive the profile ID
2821 * This function allocates a new profile ID, which also corresponds to a Field
2822 * Vector (Extraction Sequence) entry.
2824 static enum ice_status
2825 ice_alloc_prof_id(struct ice_hw *hw, enum ice_block blk, u8 *prof_id)
2827 enum ice_status status;
2831 if (!ice_prof_id_rsrc_type(blk, &res_type))
2832 return ICE_ERR_PARAM;
2834 status = ice_alloc_hw_res(hw, res_type, 1, false, &get_prof);
2836 *prof_id = (u8)get_prof;
2842 * ice_free_prof_id - free profile ID
2843 * @hw: pointer to the HW struct
2844 * @blk: the block from which to free the profile ID
2845 * @prof_id: the profile ID to free
2847 * This function frees a profile ID, which also corresponds to a Field Vector.
2849 static enum ice_status
2850 ice_free_prof_id(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
2852 u16 tmp_prof_id = (u16)prof_id;
2855 if (!ice_prof_id_rsrc_type(blk, &res_type))
2856 return ICE_ERR_PARAM;
2858 return ice_free_hw_res(hw, res_type, 1, &tmp_prof_id);
2862 * ice_prof_inc_ref - increment reference count for profile
2863 * @hw: pointer to the HW struct
2864 * @blk: the block from which to free the profile ID
2865 * @prof_id: the profile ID for which to increment the reference count
2867 static enum ice_status
2868 ice_prof_inc_ref(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
2870 if (prof_id > hw->blk[blk].es.count)
2871 return ICE_ERR_PARAM;
2873 hw->blk[blk].es.ref_count[prof_id]++;
2879 * ice_write_prof_mask_reg - write profile mask register
2880 * @hw: pointer to the HW struct
2881 * @blk: hardware block
2882 * @mask_idx: mask index
2883 * @idx: index of the FV which will use the mask
2884 * @mask: the 16-bit mask
2887 ice_write_prof_mask_reg(struct ice_hw *hw, enum ice_block blk, u16 mask_idx,
2895 offset = GLQF_HMASK(mask_idx);
2896 val = (idx << GLQF_HMASK_MSK_INDEX_S) &
2897 GLQF_HMASK_MSK_INDEX_M;
2898 val |= (mask << GLQF_HMASK_MASK_S) & GLQF_HMASK_MASK_M;
2901 offset = GLQF_FDMASK(mask_idx);
2902 val = (idx << GLQF_FDMASK_MSK_INDEX_S) &
2903 GLQF_FDMASK_MSK_INDEX_M;
2904 val |= (mask << GLQF_FDMASK_MASK_S) &
2908 ice_debug(hw, ICE_DBG_PKG, "No profile masks for block %d\n",
2913 wr32(hw, offset, val);
2914 ice_debug(hw, ICE_DBG_PKG, "write mask, blk %d (%d): %x = %x\n",
2915 blk, idx, offset, val);
2919 * ice_write_prof_mask_enable_res - write profile mask enable register
2920 * @hw: pointer to the HW struct
2921 * @blk: hardware block
2922 * @prof_id: profile ID
2923 * @enable_mask: enable mask
2926 ice_write_prof_mask_enable_res(struct ice_hw *hw, enum ice_block blk,
2927 u16 prof_id, u32 enable_mask)
2933 offset = GLQF_HMASK_SEL(prof_id);
2936 offset = GLQF_FDMASK_SEL(prof_id);
2939 ice_debug(hw, ICE_DBG_PKG, "No profile masks for block %d\n",
2944 wr32(hw, offset, enable_mask);
2945 ice_debug(hw, ICE_DBG_PKG, "write mask enable, blk %d (%d): %x = %x\n",
2946 blk, prof_id, offset, enable_mask);
2950 * ice_init_prof_masks - initial prof masks
2951 * @hw: pointer to the HW struct
2952 * @blk: hardware block
2954 static void ice_init_prof_masks(struct ice_hw *hw, enum ice_block blk)
2956 #define MAX_NUM_PORTS 8
2957 u16 num_ports = MAX_NUM_PORTS;
2960 ice_init_lock(&hw->blk[blk].masks.lock);
2962 hw->blk[blk].masks.count = ICE_PROFILE_MASK_COUNT / num_ports;
2963 hw->blk[blk].masks.first = hw->pf_id * hw->blk[blk].masks.count;
2965 ice_memset(hw->blk[blk].masks.masks, 0,
2966 sizeof(hw->blk[blk].masks.masks), ICE_NONDMA_MEM);
2968 for (i = hw->blk[blk].masks.first;
2969 i < hw->blk[blk].masks.first + hw->blk[blk].masks.count; i++)
2970 ice_write_prof_mask_reg(hw, blk, i, 0, 0);
2974 * ice_init_all_prof_masks - initial all prof masks
2975 * @hw: pointer to the HW struct
2977 void ice_init_all_prof_masks(struct ice_hw *hw)
2979 ice_init_prof_masks(hw, ICE_BLK_RSS);
2980 ice_init_prof_masks(hw, ICE_BLK_FD);
2984 * ice_alloc_prof_mask - allocate profile mask
2985 * @hw: pointer to the HW struct
2986 * @blk: hardware block
2987 * @idx: index of FV which will use the mask
2988 * @mask: the 16-bit mask
2989 * @mask_idx: variable to receive the mask index
2991 static enum ice_status
2992 ice_alloc_prof_mask(struct ice_hw *hw, enum ice_block blk, u16 idx, u16 mask,
2995 bool found_unused = false, found_copy = false;
2996 enum ice_status status = ICE_ERR_MAX_LIMIT;
2997 u16 unused_idx = 0, copy_idx = 0;
3000 if (blk != ICE_BLK_RSS && blk != ICE_BLK_FD)
3001 return ICE_ERR_PARAM;
3003 ice_acquire_lock(&hw->blk[blk].masks.lock);
3005 for (i = hw->blk[blk].masks.first;
3006 i < hw->blk[blk].masks.first + hw->blk[blk].masks.count; i++)
3007 if (hw->blk[blk].masks.masks[i].in_use) {
3008 /* if mask is in use and it exactly duplicates the
3009 * desired mask and index, then in can be reused
3011 if (hw->blk[blk].masks.masks[i].mask == mask &&
3012 hw->blk[blk].masks.masks[i].idx == idx) {
3018 /* save off unused index, but keep searching in case
3019 * there is an exact match later on
3021 if (!found_unused) {
3022 found_unused = true;
3029 else if (found_unused)
3032 goto err_ice_alloc_prof_mask;
3034 /* update mask for a new entry */
3036 hw->blk[blk].masks.masks[i].in_use = true;
3037 hw->blk[blk].masks.masks[i].mask = mask;
3038 hw->blk[blk].masks.masks[i].idx = idx;
3039 hw->blk[blk].masks.masks[i].ref = 0;
3040 ice_write_prof_mask_reg(hw, blk, i, idx, mask);
3043 hw->blk[blk].masks.masks[i].ref++;
3045 status = ICE_SUCCESS;
3047 err_ice_alloc_prof_mask:
3048 ice_release_lock(&hw->blk[blk].masks.lock);
3054 * ice_free_prof_mask - free profile mask
3055 * @hw: pointer to the HW struct
3056 * @blk: hardware block
3057 * @mask_idx: index of mask
3059 static enum ice_status
3060 ice_free_prof_mask(struct ice_hw *hw, enum ice_block blk, u16 mask_idx)
3062 if (blk != ICE_BLK_RSS && blk != ICE_BLK_FD)
3063 return ICE_ERR_PARAM;
3065 if (!(mask_idx >= hw->blk[blk].masks.first &&
3066 mask_idx < hw->blk[blk].masks.first + hw->blk[blk].masks.count))
3067 return ICE_ERR_DOES_NOT_EXIST;
3069 ice_acquire_lock(&hw->blk[blk].masks.lock);
3071 if (!hw->blk[blk].masks.masks[mask_idx].in_use)
3072 goto exit_ice_free_prof_mask;
3074 if (hw->blk[blk].masks.masks[mask_idx].ref > 1) {
3075 hw->blk[blk].masks.masks[mask_idx].ref--;
3076 goto exit_ice_free_prof_mask;
3080 hw->blk[blk].masks.masks[mask_idx].in_use = false;
3081 hw->blk[blk].masks.masks[mask_idx].mask = 0;
3082 hw->blk[blk].masks.masks[mask_idx].idx = 0;
3084 /* update mask as unused entry */
3085 ice_debug(hw, ICE_DBG_PKG, "Free mask, blk %d, mask %d", blk, mask_idx);
3086 ice_write_prof_mask_reg(hw, blk, mask_idx, 0, 0);
3088 exit_ice_free_prof_mask:
3089 ice_release_lock(&hw->blk[blk].masks.lock);
3095 * ice_free_prof_masks - free all profile masks for a profile
3096 * @hw: pointer to the HW struct
3097 * @blk: hardware block
3098 * @prof_id: profile ID
3100 static enum ice_status
3101 ice_free_prof_masks(struct ice_hw *hw, enum ice_block blk, u16 prof_id)
3106 if (blk != ICE_BLK_RSS && blk != ICE_BLK_FD)
3107 return ICE_ERR_PARAM;
3109 mask_bm = hw->blk[blk].es.mask_ena[prof_id];
3110 for (i = 0; i < BITS_PER_BYTE * sizeof(mask_bm); i++)
3111 if (mask_bm & BIT(i))
3112 ice_free_prof_mask(hw, blk, i);
3118 * ice_shutdown_prof_masks - releases lock for masking
3119 * @hw: pointer to the HW struct
3120 * @blk: hardware block
3122 * This should be called before unloading the driver
3124 static void ice_shutdown_prof_masks(struct ice_hw *hw, enum ice_block blk)
3128 ice_acquire_lock(&hw->blk[blk].masks.lock);
3130 for (i = hw->blk[blk].masks.first;
3131 i < hw->blk[blk].masks.first + hw->blk[blk].masks.count; i++) {
3132 ice_write_prof_mask_reg(hw, blk, i, 0, 0);
3134 hw->blk[blk].masks.masks[i].in_use = false;
3135 hw->blk[blk].masks.masks[i].idx = 0;
3136 hw->blk[blk].masks.masks[i].mask = 0;
3139 ice_release_lock(&hw->blk[blk].masks.lock);
3140 ice_destroy_lock(&hw->blk[blk].masks.lock);
3144 * ice_shutdown_all_prof_masks - releases all locks for masking
3145 * @hw: pointer to the HW struct
3146 * @blk: hardware block
3148 * This should be called before unloading the driver
3150 void ice_shutdown_all_prof_masks(struct ice_hw *hw)
3152 ice_shutdown_prof_masks(hw, ICE_BLK_RSS);
3153 ice_shutdown_prof_masks(hw, ICE_BLK_FD);
3157 * ice_update_prof_masking - set registers according to masking
3158 * @hw: pointer to the HW struct
3159 * @blk: hardware block
3160 * @prof_id: profile ID
3164 static enum ice_status
3165 ice_update_prof_masking(struct ice_hw *hw, enum ice_block blk, u16 prof_id,
3166 struct ice_fv_word *es, u16 *masks)
3173 /* Only support FD and RSS masking, otherwise nothing to be done */
3174 if (blk != ICE_BLK_RSS && blk != ICE_BLK_FD)
3177 for (i = 0; i < hw->blk[blk].es.fvw; i++)
3178 if (masks[i] && masks[i] != 0xFFFF) {
3179 if (!ice_alloc_prof_mask(hw, blk, i, masks[i], &idx)) {
3180 ena_mask |= BIT(idx);
3182 /* not enough bitmaps */
3189 /* free any bitmaps we have allocated */
3190 for (i = 0; i < BITS_PER_BYTE * sizeof(ena_mask); i++)
3191 if (ena_mask & BIT(i))
3192 ice_free_prof_mask(hw, blk, i);
3194 return ICE_ERR_OUT_OF_RANGE;
3197 /* enable the masks for this profile */
3198 ice_write_prof_mask_enable_res(hw, blk, prof_id, ena_mask);
3200 /* store enabled masks with profile so that they can be freed later */
3201 hw->blk[blk].es.mask_ena[prof_id] = ena_mask;
3207 * ice_write_es - write an extraction sequence to hardware
3208 * @hw: pointer to the HW struct
3209 * @blk: the block in which to write the extraction sequence
3210 * @prof_id: the profile ID to write
3211 * @fv: pointer to the extraction sequence to write - NULL to clear extraction
3214 ice_write_es(struct ice_hw *hw, enum ice_block blk, u8 prof_id,
3215 struct ice_fv_word *fv)
3219 off = prof_id * hw->blk[blk].es.fvw;
3221 ice_memset(&hw->blk[blk].es.t[off], 0, hw->blk[blk].es.fvw *
3222 sizeof(*fv), ICE_NONDMA_MEM);
3223 hw->blk[blk].es.written[prof_id] = false;
3225 ice_memcpy(&hw->blk[blk].es.t[off], fv, hw->blk[blk].es.fvw *
3226 sizeof(*fv), ICE_NONDMA_TO_NONDMA);
3231 * ice_prof_dec_ref - decrement reference count for profile
3232 * @hw: pointer to the HW struct
3233 * @blk: the block from which to free the profile ID
3234 * @prof_id: the profile ID for which to decrement the reference count
3236 static enum ice_status
3237 ice_prof_dec_ref(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
3239 if (prof_id > hw->blk[blk].es.count)
3240 return ICE_ERR_PARAM;
3242 if (hw->blk[blk].es.ref_count[prof_id] > 0) {
3243 if (!--hw->blk[blk].es.ref_count[prof_id]) {
3244 ice_write_es(hw, blk, prof_id, NULL);
3245 ice_free_prof_masks(hw, blk, prof_id);
3246 return ice_free_prof_id(hw, blk, prof_id);
3253 /* Block / table section IDs */
3254 static const u32 ice_blk_sids[ICE_BLK_COUNT][ICE_SID_OFF_COUNT] = {
3258 ICE_SID_PROFID_TCAM_SW,
3259 ICE_SID_PROFID_REDIR_SW,
3266 ICE_SID_PROFID_TCAM_ACL,
3267 ICE_SID_PROFID_REDIR_ACL,
3274 ICE_SID_PROFID_TCAM_FD,
3275 ICE_SID_PROFID_REDIR_FD,
3282 ICE_SID_PROFID_TCAM_RSS,
3283 ICE_SID_PROFID_REDIR_RSS,
3290 ICE_SID_PROFID_TCAM_PE,
3291 ICE_SID_PROFID_REDIR_PE,
3297 * ice_init_sw_xlt1_db - init software XLT1 database from HW tables
3298 * @hw: pointer to the hardware structure
3299 * @blk: the HW block to initialize
3302 void ice_init_sw_xlt1_db(struct ice_hw *hw, enum ice_block blk)
3306 for (pt = 0; pt < hw->blk[blk].xlt1.count; pt++) {
3309 ptg = hw->blk[blk].xlt1.t[pt];
3310 if (ptg != ICE_DEFAULT_PTG) {
3311 ice_ptg_alloc_val(hw, blk, ptg);
3312 ice_ptg_add_mv_ptype(hw, blk, pt, ptg);
3318 * ice_init_sw_xlt2_db - init software XLT2 database from HW tables
3319 * @hw: pointer to the hardware structure
3320 * @blk: the HW block to initialize
3322 static void ice_init_sw_xlt2_db(struct ice_hw *hw, enum ice_block blk)
3326 for (vsi = 0; vsi < hw->blk[blk].xlt2.count; vsi++) {
3329 vsig = hw->blk[blk].xlt2.t[vsi];
3331 ice_vsig_alloc_val(hw, blk, vsig);
3332 ice_vsig_add_mv_vsi(hw, blk, vsi, vsig);
3333 /* no changes at this time, since this has been
3334 * initialized from the original package
3336 hw->blk[blk].xlt2.vsis[vsi].changed = 0;
3342 * ice_init_sw_db - init software database from HW tables
3343 * @hw: pointer to the hardware structure
3345 static void ice_init_sw_db(struct ice_hw *hw)
3349 for (i = 0; i < ICE_BLK_COUNT; i++) {
3350 ice_init_sw_xlt1_db(hw, (enum ice_block)i);
3351 ice_init_sw_xlt2_db(hw, (enum ice_block)i);
3356 * ice_fill_tbl - Reads content of a single table type into database
3357 * @hw: pointer to the hardware structure
3358 * @block_id: Block ID of the table to copy
3359 * @sid: Section ID of the table to copy
3361 * Will attempt to read the entire content of a given table of a single block
3362 * into the driver database. We assume that the buffer will always
3363 * be as large or larger than the data contained in the package. If
3364 * this condition is not met, there is most likely an error in the package
3367 static void ice_fill_tbl(struct ice_hw *hw, enum ice_block block_id, u32 sid)
3369 u32 dst_len, sect_len, offset = 0;
3370 struct ice_prof_redir_section *pr;
3371 struct ice_prof_id_section *pid;
3372 struct ice_xlt1_section *xlt1;
3373 struct ice_xlt2_section *xlt2;
3374 struct ice_sw_fv_section *es;
3375 struct ice_pkg_enum state;
3379 /* if the HW segment pointer is null then the first iteration of
3380 * ice_pkg_enum_section() will fail. In this case the HW tables will
3381 * not be filled and return success.
3384 ice_debug(hw, ICE_DBG_PKG, "hw->seg is NULL, tables are not filled\n");
3388 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
3390 sect = ice_pkg_enum_section(hw->seg, &state, sid);
3394 case ICE_SID_XLT1_SW:
3395 case ICE_SID_XLT1_FD:
3396 case ICE_SID_XLT1_RSS:
3397 case ICE_SID_XLT1_ACL:
3398 case ICE_SID_XLT1_PE:
3399 xlt1 = (struct ice_xlt1_section *)sect;
3401 sect_len = LE16_TO_CPU(xlt1->count) *
3402 sizeof(*hw->blk[block_id].xlt1.t);
3403 dst = hw->blk[block_id].xlt1.t;
3404 dst_len = hw->blk[block_id].xlt1.count *
3405 sizeof(*hw->blk[block_id].xlt1.t);
3407 case ICE_SID_XLT2_SW:
3408 case ICE_SID_XLT2_FD:
3409 case ICE_SID_XLT2_RSS:
3410 case ICE_SID_XLT2_ACL:
3411 case ICE_SID_XLT2_PE:
3412 xlt2 = (struct ice_xlt2_section *)sect;
3413 src = (_FORCE_ u8 *)xlt2->value;
3414 sect_len = LE16_TO_CPU(xlt2->count) *
3415 sizeof(*hw->blk[block_id].xlt2.t);
3416 dst = (u8 *)hw->blk[block_id].xlt2.t;
3417 dst_len = hw->blk[block_id].xlt2.count *
3418 sizeof(*hw->blk[block_id].xlt2.t);
3420 case ICE_SID_PROFID_TCAM_SW:
3421 case ICE_SID_PROFID_TCAM_FD:
3422 case ICE_SID_PROFID_TCAM_RSS:
3423 case ICE_SID_PROFID_TCAM_ACL:
3424 case ICE_SID_PROFID_TCAM_PE:
3425 pid = (struct ice_prof_id_section *)sect;
3426 src = (u8 *)pid->entry;
3427 sect_len = LE16_TO_CPU(pid->count) *
3428 sizeof(*hw->blk[block_id].prof.t);
3429 dst = (u8 *)hw->blk[block_id].prof.t;
3430 dst_len = hw->blk[block_id].prof.count *
3431 sizeof(*hw->blk[block_id].prof.t);
3433 case ICE_SID_PROFID_REDIR_SW:
3434 case ICE_SID_PROFID_REDIR_FD:
3435 case ICE_SID_PROFID_REDIR_RSS:
3436 case ICE_SID_PROFID_REDIR_ACL:
3437 case ICE_SID_PROFID_REDIR_PE:
3438 pr = (struct ice_prof_redir_section *)sect;
3439 src = pr->redir_value;
3440 sect_len = LE16_TO_CPU(pr->count) *
3441 sizeof(*hw->blk[block_id].prof_redir.t);
3442 dst = hw->blk[block_id].prof_redir.t;
3443 dst_len = hw->blk[block_id].prof_redir.count *
3444 sizeof(*hw->blk[block_id].prof_redir.t);
3446 case ICE_SID_FLD_VEC_SW:
3447 case ICE_SID_FLD_VEC_FD:
3448 case ICE_SID_FLD_VEC_RSS:
3449 case ICE_SID_FLD_VEC_ACL:
3450 case ICE_SID_FLD_VEC_PE:
3451 es = (struct ice_sw_fv_section *)sect;
3453 sect_len = (u32)(LE16_TO_CPU(es->count) *
3454 hw->blk[block_id].es.fvw) *
3455 sizeof(*hw->blk[block_id].es.t);
3456 dst = (u8 *)hw->blk[block_id].es.t;
3457 dst_len = (u32)(hw->blk[block_id].es.count *
3458 hw->blk[block_id].es.fvw) *
3459 sizeof(*hw->blk[block_id].es.t);
3465 /* if the section offset exceeds destination length, terminate
3468 if (offset > dst_len)
3471 /* if the sum of section size and offset exceed destination size
3472 * then we are out of bounds of the HW table size for that PF.
3473 * Changing section length to fill the remaining table space
3476 if ((offset + sect_len) > dst_len)
3477 sect_len = dst_len - offset;
3479 ice_memcpy(dst + offset, src, sect_len, ICE_NONDMA_TO_NONDMA);
3481 sect = ice_pkg_enum_section(NULL, &state, sid);
3486 * ice_fill_blk_tbls - Read package context for tables
3487 * @hw: pointer to the hardware structure
3489 * Reads the current package contents and populates the driver
3490 * database with the data iteratively for all advanced feature
3491 * blocks. Assume that the HW tables have been allocated.
3493 void ice_fill_blk_tbls(struct ice_hw *hw)
3497 for (i = 0; i < ICE_BLK_COUNT; i++) {
3498 enum ice_block blk_id = (enum ice_block)i;
3500 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].xlt1.sid);
3501 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].xlt2.sid);
3502 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].prof.sid);
3503 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].prof_redir.sid);
3504 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].es.sid);
3511 * ice_free_prof_map - free profile map
3512 * @hw: pointer to the hardware structure
3513 * @blk_idx: HW block index
3515 static void ice_free_prof_map(struct ice_hw *hw, u8 blk_idx)
3517 struct ice_es *es = &hw->blk[blk_idx].es;
3518 struct ice_prof_map *del, *tmp;
3520 ice_acquire_lock(&es->prof_map_lock);
3521 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &es->prof_map,
3522 ice_prof_map, list) {
3523 LIST_DEL(&del->list);
3526 INIT_LIST_HEAD(&es->prof_map);
3527 ice_release_lock(&es->prof_map_lock);
3531 * ice_free_flow_profs - free flow profile entries
3532 * @hw: pointer to the hardware structure
3533 * @blk_idx: HW block index
3535 static void ice_free_flow_profs(struct ice_hw *hw, u8 blk_idx)
3537 struct ice_flow_prof *p, *tmp;
3539 ice_acquire_lock(&hw->fl_profs_locks[blk_idx]);
3540 LIST_FOR_EACH_ENTRY_SAFE(p, tmp, &hw->fl_profs[blk_idx],
3541 ice_flow_prof, l_entry) {
3542 struct ice_flow_entry *e, *t;
3544 LIST_FOR_EACH_ENTRY_SAFE(e, t, &p->entries,
3545 ice_flow_entry, l_entry)
3546 ice_flow_rem_entry(hw, ICE_FLOW_ENTRY_HNDL(e));
3548 LIST_DEL(&p->l_entry);
3550 ice_free(hw, p->acts);
3553 ice_release_lock(&hw->fl_profs_locks[blk_idx]);
3555 /* if driver is in reset and tables are being cleared
3556 * re-initialize the flow profile list heads
3558 INIT_LIST_HEAD(&hw->fl_profs[blk_idx]);
3562 * ice_free_vsig_tbl - free complete VSIG table entries
3563 * @hw: pointer to the hardware structure
3564 * @blk: the HW block on which to free the VSIG table entries
3566 static void ice_free_vsig_tbl(struct ice_hw *hw, enum ice_block blk)
3570 if (!hw->blk[blk].xlt2.vsig_tbl)
3573 for (i = 1; i < ICE_MAX_VSIGS; i++)
3574 if (hw->blk[blk].xlt2.vsig_tbl[i].in_use)
3575 ice_vsig_free(hw, blk, i);
3579 * ice_free_hw_tbls - free hardware table memory
3580 * @hw: pointer to the hardware structure
3582 void ice_free_hw_tbls(struct ice_hw *hw)
3584 struct ice_rss_cfg *r, *rt;
3587 for (i = 0; i < ICE_BLK_COUNT; i++) {
3588 if (hw->blk[i].is_list_init) {
3589 struct ice_es *es = &hw->blk[i].es;
3591 ice_free_prof_map(hw, i);
3592 ice_destroy_lock(&es->prof_map_lock);
3593 ice_free_flow_profs(hw, i);
3594 ice_destroy_lock(&hw->fl_profs_locks[i]);
3596 hw->blk[i].is_list_init = false;
3598 ice_free_vsig_tbl(hw, (enum ice_block)i);
3599 ice_free(hw, hw->blk[i].xlt1.ptypes);
3600 ice_free(hw, hw->blk[i].xlt1.ptg_tbl);
3601 ice_free(hw, hw->blk[i].xlt1.t);
3602 ice_free(hw, hw->blk[i].xlt2.t);
3603 ice_free(hw, hw->blk[i].xlt2.vsig_tbl);
3604 ice_free(hw, hw->blk[i].xlt2.vsis);
3605 ice_free(hw, hw->blk[i].prof.t);
3606 ice_free(hw, hw->blk[i].prof_redir.t);
3607 ice_free(hw, hw->blk[i].es.t);
3608 ice_free(hw, hw->blk[i].es.ref_count);
3609 ice_free(hw, hw->blk[i].es.written);
3610 ice_free(hw, hw->blk[i].es.mask_ena);
3613 LIST_FOR_EACH_ENTRY_SAFE(r, rt, &hw->rss_list_head,
3614 ice_rss_cfg, l_entry) {
3615 LIST_DEL(&r->l_entry);
3618 ice_destroy_lock(&hw->rss_locks);
3619 ice_shutdown_all_prof_masks(hw);
3620 ice_memset(hw->blk, 0, sizeof(hw->blk), ICE_NONDMA_MEM);
3624 * ice_init_flow_profs - init flow profile locks and list heads
3625 * @hw: pointer to the hardware structure
3626 * @blk_idx: HW block index
3628 static void ice_init_flow_profs(struct ice_hw *hw, u8 blk_idx)
3630 ice_init_lock(&hw->fl_profs_locks[blk_idx]);
3631 INIT_LIST_HEAD(&hw->fl_profs[blk_idx]);
3635 * ice_init_hw_tbls - init hardware table memory
3636 * @hw: pointer to the hardware structure
3638 enum ice_status ice_init_hw_tbls(struct ice_hw *hw)
3642 ice_init_lock(&hw->rss_locks);
3643 INIT_LIST_HEAD(&hw->rss_list_head);
3644 ice_init_all_prof_masks(hw);
3645 for (i = 0; i < ICE_BLK_COUNT; i++) {
3646 struct ice_prof_redir *prof_redir = &hw->blk[i].prof_redir;
3647 struct ice_prof_tcam *prof = &hw->blk[i].prof;
3648 struct ice_xlt1 *xlt1 = &hw->blk[i].xlt1;
3649 struct ice_xlt2 *xlt2 = &hw->blk[i].xlt2;
3650 struct ice_es *es = &hw->blk[i].es;
3653 if (hw->blk[i].is_list_init)
3656 ice_init_flow_profs(hw, i);
3657 ice_init_lock(&es->prof_map_lock);
3658 INIT_LIST_HEAD(&es->prof_map);
3659 hw->blk[i].is_list_init = true;
3661 hw->blk[i].overwrite = blk_sizes[i].overwrite;
3662 es->reverse = blk_sizes[i].reverse;
3664 xlt1->sid = ice_blk_sids[i][ICE_SID_XLT1_OFF];
3665 xlt1->count = blk_sizes[i].xlt1;
3667 xlt1->ptypes = (struct ice_ptg_ptype *)
3668 ice_calloc(hw, xlt1->count, sizeof(*xlt1->ptypes));
3673 xlt1->ptg_tbl = (struct ice_ptg_entry *)
3674 ice_calloc(hw, ICE_MAX_PTGS, sizeof(*xlt1->ptg_tbl));
3679 xlt1->t = (u8 *)ice_calloc(hw, xlt1->count, sizeof(*xlt1->t));
3683 xlt2->sid = ice_blk_sids[i][ICE_SID_XLT2_OFF];
3684 xlt2->count = blk_sizes[i].xlt2;
3686 xlt2->vsis = (struct ice_vsig_vsi *)
3687 ice_calloc(hw, xlt2->count, sizeof(*xlt2->vsis));
3692 xlt2->vsig_tbl = (struct ice_vsig_entry *)
3693 ice_calloc(hw, xlt2->count, sizeof(*xlt2->vsig_tbl));
3694 if (!xlt2->vsig_tbl)
3697 for (j = 0; j < xlt2->count; j++)
3698 INIT_LIST_HEAD(&xlt2->vsig_tbl[j].prop_lst);
3700 xlt2->t = (u16 *)ice_calloc(hw, xlt2->count, sizeof(*xlt2->t));
3704 prof->sid = ice_blk_sids[i][ICE_SID_PR_OFF];
3705 prof->count = blk_sizes[i].prof_tcam;
3706 prof->max_prof_id = blk_sizes[i].prof_id;
3707 prof->cdid_bits = blk_sizes[i].prof_cdid_bits;
3708 prof->t = (struct ice_prof_tcam_entry *)
3709 ice_calloc(hw, prof->count, sizeof(*prof->t));
3714 prof_redir->sid = ice_blk_sids[i][ICE_SID_PR_REDIR_OFF];
3715 prof_redir->count = blk_sizes[i].prof_redir;
3716 prof_redir->t = (u8 *)ice_calloc(hw, prof_redir->count,
3717 sizeof(*prof_redir->t));
3722 es->sid = ice_blk_sids[i][ICE_SID_ES_OFF];
3723 es->count = blk_sizes[i].es;
3724 es->fvw = blk_sizes[i].fvw;
3725 es->t = (struct ice_fv_word *)
3726 ice_calloc(hw, (u32)(es->count * es->fvw),
3731 es->ref_count = (u16 *)
3732 ice_calloc(hw, es->count, sizeof(*es->ref_count));
3734 es->written = (u8 *)
3735 ice_calloc(hw, es->count, sizeof(*es->written));
3736 es->mask_ena = (u32 *)
3737 ice_calloc(hw, es->count, sizeof(*es->mask_ena));
3744 ice_free_hw_tbls(hw);
3745 return ICE_ERR_NO_MEMORY;
3749 * ice_prof_gen_key - generate profile ID key
3750 * @hw: pointer to the HW struct
3751 * @blk: the block in which to write profile ID to
3752 * @ptg: packet type group (PTG) portion of key
3753 * @vsig: VSIG portion of key
3754 * @cdid: cdid portion of key
3755 * @flags: flag portion of key
3756 * @vl_msk: valid mask
3757 * @dc_msk: don't care mask
3758 * @nm_msk: never match mask
3759 * @key: output of profile ID key
3761 static enum ice_status
3762 ice_prof_gen_key(struct ice_hw *hw, enum ice_block blk, u8 ptg, u16 vsig,
3763 u8 cdid, u16 flags, u8 vl_msk[ICE_TCAM_KEY_VAL_SZ],
3764 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ], u8 nm_msk[ICE_TCAM_KEY_VAL_SZ],
3765 u8 key[ICE_TCAM_KEY_SZ])
3767 struct ice_prof_id_key inkey;
3770 inkey.xlt2_cdid = CPU_TO_LE16(vsig);
3771 inkey.flags = CPU_TO_LE16(flags);
3773 switch (hw->blk[blk].prof.cdid_bits) {
3777 #define ICE_CD_2_M 0xC000U
3778 #define ICE_CD_2_S 14
3779 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_2_M);
3780 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_2_S);
3783 #define ICE_CD_4_M 0xF000U
3784 #define ICE_CD_4_S 12
3785 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_4_M);
3786 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_4_S);
3789 #define ICE_CD_8_M 0xFF00U
3790 #define ICE_CD_8_S 16
3791 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_8_M);
3792 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_8_S);
3795 ice_debug(hw, ICE_DBG_PKG, "Error in profile config\n");
3799 return ice_set_key(key, ICE_TCAM_KEY_SZ, (u8 *)&inkey, vl_msk, dc_msk,
3800 nm_msk, 0, ICE_TCAM_KEY_SZ / 2);
3804 * ice_tcam_write_entry - write TCAM entry
3805 * @hw: pointer to the HW struct
3806 * @blk: the block in which to write profile ID to
3807 * @idx: the entry index to write to
3808 * @prof_id: profile ID
3809 * @ptg: packet type group (PTG) portion of key
3810 * @vsig: VSIG portion of key
3811 * @cdid: cdid portion of key
3812 * @flags: flag portion of key
3813 * @vl_msk: valid mask
3814 * @dc_msk: don't care mask
3815 * @nm_msk: never match mask
3817 static enum ice_status
3818 ice_tcam_write_entry(struct ice_hw *hw, enum ice_block blk, u16 idx,
3819 u8 prof_id, u8 ptg, u16 vsig, u8 cdid, u16 flags,
3820 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ],
3821 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ],
3822 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ])
3824 struct ice_prof_tcam_entry;
3825 enum ice_status status;
3827 status = ice_prof_gen_key(hw, blk, ptg, vsig, cdid, flags, vl_msk,
3828 dc_msk, nm_msk, hw->blk[blk].prof.t[idx].key);
3830 hw->blk[blk].prof.t[idx].addr = CPU_TO_LE16(idx);
3831 hw->blk[blk].prof.t[idx].prof_id = prof_id;
3838 * ice_vsig_get_ref - returns number of VSIs belong to a VSIG
3839 * @hw: pointer to the hardware structure
3841 * @vsig: VSIG to query
3842 * @refs: pointer to variable to receive the reference count
3844 static enum ice_status
3845 ice_vsig_get_ref(struct ice_hw *hw, enum ice_block blk, u16 vsig, u16 *refs)
3847 u16 idx = vsig & ICE_VSIG_IDX_M;
3848 struct ice_vsig_vsi *ptr;
3851 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
3852 return ICE_ERR_DOES_NOT_EXIST;
3854 ptr = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
3857 ptr = ptr->next_vsi;
3864 * ice_has_prof_vsig - check to see if VSIG has a specific profile
3865 * @hw: pointer to the hardware structure
3867 * @vsig: VSIG to check against
3868 * @hdl: profile handle
3871 ice_has_prof_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl)
3873 u16 idx = vsig & ICE_VSIG_IDX_M;
3874 struct ice_vsig_prof *ent;
3876 LIST_FOR_EACH_ENTRY(ent, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
3877 ice_vsig_prof, list) {
3878 if (ent->profile_cookie == hdl)
3882 ice_debug(hw, ICE_DBG_INIT,
3883 "Characteristic list for VSI group %d not found.\n",
3889 * ice_prof_bld_es - build profile ID extraction sequence changes
3890 * @hw: pointer to the HW struct
3891 * @blk: hardware block
3892 * @bld: the update package buffer build to add to
3893 * @chgs: the list of changes to make in hardware
3895 static enum ice_status
3896 ice_prof_bld_es(struct ice_hw *hw, enum ice_block blk,
3897 struct ice_buf_build *bld, struct LIST_HEAD_TYPE *chgs)
3899 u16 vec_size = hw->blk[blk].es.fvw * sizeof(struct ice_fv_word);
3900 struct ice_chs_chg *tmp;
3902 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
3903 if (tmp->type == ICE_PTG_ES_ADD && tmp->add_prof) {
3904 u16 off = tmp->prof_id * hw->blk[blk].es.fvw;
3905 struct ice_pkg_es *p;
3908 id = ice_sect_id(blk, ICE_VEC_TBL);
3909 p = (struct ice_pkg_es *)
3910 ice_pkg_buf_alloc_section(bld, id, sizeof(*p) +
3915 return ICE_ERR_MAX_LIMIT;
3917 p->count = CPU_TO_LE16(1);
3918 p->offset = CPU_TO_LE16(tmp->prof_id);
3920 ice_memcpy(p->es, &hw->blk[blk].es.t[off], vec_size,
3921 ICE_NONDMA_TO_NONDMA);
3929 * ice_prof_bld_tcam - build profile ID TCAM changes
3930 * @hw: pointer to the HW struct
3931 * @blk: hardware block
3932 * @bld: the update package buffer build to add to
3933 * @chgs: the list of changes to make in hardware
3935 static enum ice_status
3936 ice_prof_bld_tcam(struct ice_hw *hw, enum ice_block blk,
3937 struct ice_buf_build *bld, struct LIST_HEAD_TYPE *chgs)
3939 struct ice_chs_chg *tmp;
3941 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
3942 if (tmp->type == ICE_TCAM_ADD && tmp->add_tcam_idx) {
3943 struct ice_prof_id_section *p;
3946 id = ice_sect_id(blk, ICE_PROF_TCAM);
3947 p = (struct ice_prof_id_section *)
3948 ice_pkg_buf_alloc_section(bld, id, sizeof(*p));
3951 return ICE_ERR_MAX_LIMIT;
3953 p->count = CPU_TO_LE16(1);
3954 p->entry[0].addr = CPU_TO_LE16(tmp->tcam_idx);
3955 p->entry[0].prof_id = tmp->prof_id;
3957 ice_memcpy(p->entry[0].key,
3958 &hw->blk[blk].prof.t[tmp->tcam_idx].key,
3959 sizeof(hw->blk[blk].prof.t->key),
3960 ICE_NONDMA_TO_NONDMA);
3968 * ice_prof_bld_xlt1 - build XLT1 changes
3969 * @blk: hardware block
3970 * @bld: the update package buffer build to add to
3971 * @chgs: the list of changes to make in hardware
3973 static enum ice_status
3974 ice_prof_bld_xlt1(enum ice_block blk, struct ice_buf_build *bld,
3975 struct LIST_HEAD_TYPE *chgs)
3977 struct ice_chs_chg *tmp;
3979 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
3980 if (tmp->type == ICE_PTG_ES_ADD && tmp->add_ptg) {
3981 struct ice_xlt1_section *p;
3984 id = ice_sect_id(blk, ICE_XLT1);
3985 p = (struct ice_xlt1_section *)
3986 ice_pkg_buf_alloc_section(bld, id, sizeof(*p));
3989 return ICE_ERR_MAX_LIMIT;
3991 p->count = CPU_TO_LE16(1);
3992 p->offset = CPU_TO_LE16(tmp->ptype);
3993 p->value[0] = tmp->ptg;
4001 * ice_prof_bld_xlt2 - build XLT2 changes
4002 * @blk: hardware block
4003 * @bld: the update package buffer build to add to
4004 * @chgs: the list of changes to make in hardware
4006 static enum ice_status
4007 ice_prof_bld_xlt2(enum ice_block blk, struct ice_buf_build *bld,
4008 struct LIST_HEAD_TYPE *chgs)
4010 struct ice_chs_chg *tmp;
4012 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
4015 if (tmp->type == ICE_VSIG_ADD)
4017 else if (tmp->type == ICE_VSI_MOVE)
4019 else if (tmp->type == ICE_VSIG_REM)
4023 struct ice_xlt2_section *p;
4026 id = ice_sect_id(blk, ICE_XLT2);
4027 p = (struct ice_xlt2_section *)
4028 ice_pkg_buf_alloc_section(bld, id, sizeof(*p));
4031 return ICE_ERR_MAX_LIMIT;
4033 p->count = CPU_TO_LE16(1);
4034 p->offset = CPU_TO_LE16(tmp->vsi);
4035 p->value[0] = CPU_TO_LE16(tmp->vsig);
4043 * ice_upd_prof_hw - update hardware using the change list
4044 * @hw: pointer to the HW struct
4045 * @blk: hardware block
4046 * @chgs: the list of changes to make in hardware
4048 static enum ice_status
4049 ice_upd_prof_hw(struct ice_hw *hw, enum ice_block blk,
4050 struct LIST_HEAD_TYPE *chgs)
4052 struct ice_buf_build *b;
4053 struct ice_chs_chg *tmp;
4054 enum ice_status status;
4062 /* count number of sections we need */
4063 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
4064 switch (tmp->type) {
4065 case ICE_PTG_ES_ADD:
4083 sects = xlt1 + xlt2 + tcam + es;
4088 /* Build update package buffer */
4089 b = ice_pkg_buf_alloc(hw);
4091 return ICE_ERR_NO_MEMORY;
4093 status = ice_pkg_buf_reserve_section(b, sects);
4097 /* Preserve order of table update: ES, TCAM, PTG, VSIG */
4099 status = ice_prof_bld_es(hw, blk, b, chgs);
4105 status = ice_prof_bld_tcam(hw, blk, b, chgs);
4111 status = ice_prof_bld_xlt1(blk, b, chgs);
4117 status = ice_prof_bld_xlt2(blk, b, chgs);
4122 /* After package buffer build check if the section count in buffer is
4123 * non-zero and matches the number of sections detected for package
4126 pkg_sects = ice_pkg_buf_get_active_sections(b);
4127 if (!pkg_sects || pkg_sects != sects) {
4128 status = ICE_ERR_INVAL_SIZE;
4132 /* update package */
4133 status = ice_update_pkg(hw, ice_pkg_buf(b), 1);
4134 if (status == ICE_ERR_AQ_ERROR)
4135 ice_debug(hw, ICE_DBG_INIT, "Unable to update HW profile.");
4138 ice_pkg_buf_free(hw, b);
4143 * ice_update_fd_mask - set Flow Director Field Vector mask for a profile
4144 * @hw: pointer to the HW struct
4145 * @prof_id: profile ID
4146 * @mask_sel: mask select
4148 * This function enable any of the masks selected by the mask select parameter
4149 * for the profile specified.
4151 static void ice_update_fd_mask(struct ice_hw *hw, u16 prof_id, u32 mask_sel)
4153 wr32(hw, GLQF_FDMASK_SEL(prof_id), mask_sel);
4155 ice_debug(hw, ICE_DBG_INIT, "fd mask(%d): %x = %x\n", prof_id,
4156 GLQF_FDMASK_SEL(prof_id), mask_sel);
4159 #define ICE_SRC_DST_MAX_COUNT 8
4161 struct ice_fd_src_dst_pair {
4167 static const struct ice_fd_src_dst_pair ice_fd_pairs[] = {
4168 /* These are defined in pairs */
4169 { ICE_PROT_IPV4_OF_OR_S, 2, 12 },
4170 { ICE_PROT_IPV4_OF_OR_S, 2, 16 },
4172 { ICE_PROT_IPV4_IL, 2, 12 },
4173 { ICE_PROT_IPV4_IL, 2, 16 },
4175 { ICE_PROT_IPV6_OF_OR_S, 8, 8 },
4176 { ICE_PROT_IPV6_OF_OR_S, 8, 24 },
4178 { ICE_PROT_IPV6_IL, 8, 8 },
4179 { ICE_PROT_IPV6_IL, 8, 24 },
4181 { ICE_PROT_TCP_IL, 1, 0 },
4182 { ICE_PROT_TCP_IL, 1, 2 },
4184 { ICE_PROT_UDP_OF, 1, 0 },
4185 { ICE_PROT_UDP_OF, 1, 2 },
4187 { ICE_PROT_UDP_IL_OR_S, 1, 0 },
4188 { ICE_PROT_UDP_IL_OR_S, 1, 2 },
4190 { ICE_PROT_SCTP_IL, 1, 0 },
4191 { ICE_PROT_SCTP_IL, 1, 2 }
4194 #define ICE_FD_SRC_DST_PAIR_COUNT ARRAY_SIZE(ice_fd_pairs)
4197 * ice_update_fd_swap - set register appropriately for a FD FV extraction
4198 * @hw: pointer to the HW struct
4199 * @prof_id: profile ID
4200 * @es: extraction sequence (length of array is determined by the block)
4202 static enum ice_status
4203 ice_update_fd_swap(struct ice_hw *hw, u16 prof_id, struct ice_fv_word *es)
4205 ice_declare_bitmap(pair_list, ICE_FD_SRC_DST_PAIR_COUNT);
4206 u8 pair_start[ICE_FD_SRC_DST_PAIR_COUNT] = { 0 };
4207 #define ICE_FD_FV_NOT_FOUND (-2)
4208 s8 first_free = ICE_FD_FV_NOT_FOUND;
4209 u8 used[ICE_MAX_FV_WORDS] = { 0 };
4214 ice_zero_bitmap(pair_list, ICE_FD_SRC_DST_PAIR_COUNT);
4216 ice_init_fd_mask_regs(hw);
4218 /* This code assumes that the Flow Director field vectors are assigned
4219 * from the end of the FV indexes working towards the zero index, that
4220 * only complete fields will be included and will be consecutive, and
4221 * that there are no gaps between valid indexes.
4224 /* Determine swap fields present */
4225 for (i = 0; i < hw->blk[ICE_BLK_FD].es.fvw; i++) {
4226 /* Find the first free entry, assuming right to left population.
4227 * This is where we can start adding additional pairs if needed.
4229 if (first_free == ICE_FD_FV_NOT_FOUND && es[i].prot_id !=
4233 for (j = 0; j < ICE_FD_SRC_DST_PAIR_COUNT; j++) {
4234 if (es[i].prot_id == ice_fd_pairs[j].prot_id &&
4235 es[i].off == ice_fd_pairs[j].off) {
4236 ice_set_bit(j, pair_list);
4242 orig_free = first_free;
4244 /* determine missing swap fields that need to be added */
4245 for (i = 0; i < ICE_FD_SRC_DST_PAIR_COUNT; i += 2) {
4246 u8 bit1 = ice_is_bit_set(pair_list, i + 1);
4247 u8 bit0 = ice_is_bit_set(pair_list, i);
4252 /* add the appropriate 'paired' entry */
4258 /* check for room */
4259 if (first_free + 1 < (s8)ice_fd_pairs[index].count)
4260 return ICE_ERR_MAX_LIMIT;
4262 /* place in extraction sequence */
4263 for (k = 0; k < ice_fd_pairs[index].count; k++) {
4264 es[first_free - k].prot_id =
4265 ice_fd_pairs[index].prot_id;
4266 es[first_free - k].off =
4267 ice_fd_pairs[index].off + (k * 2);
4270 return ICE_ERR_OUT_OF_RANGE;
4272 /* keep track of non-relevant fields */
4273 mask_sel |= 1 << (first_free - k);
4276 pair_start[index] = first_free;
4277 first_free -= ice_fd_pairs[index].count;
4281 /* fill in the swap array */
4282 si = hw->blk[ICE_BLK_FD].es.fvw - 1;
4284 u8 indexes_used = 1;
4286 /* assume flat at this index */
4287 #define ICE_SWAP_VALID 0x80
4288 used[si] = si | ICE_SWAP_VALID;
4290 if (orig_free == ICE_FD_FV_NOT_FOUND || si <= orig_free) {
4295 /* check for a swap location */
4296 for (j = 0; j < ICE_FD_SRC_DST_PAIR_COUNT; j++) {
4297 if (es[si].prot_id == ice_fd_pairs[j].prot_id &&
4298 es[si].off == ice_fd_pairs[j].off) {
4301 /* determine the appropriate matching field */
4302 idx = j + ((j % 2) ? -1 : 1);
4304 indexes_used = ice_fd_pairs[idx].count;
4305 for (k = 0; k < indexes_used; k++) {
4306 used[si - k] = (pair_start[idx] - k) |
4317 /* for each set of 4 swap indexes, write the appropriate register */
4318 for (j = 0; j < hw->blk[ICE_BLK_FD].es.fvw / 4; j++) {
4321 for (k = 0; k < 4; k++) {
4326 raw_entry |= used[idx] << (k * BITS_PER_BYTE);
4329 /* write the appropriate register set, based on HW block */
4330 wr32(hw, GLQF_FDSWAP(prof_id, j), raw_entry);
4332 ice_debug(hw, ICE_DBG_INIT, "swap wr(%d, %d): %x = %x\n",
4333 prof_id, j, GLQF_FDSWAP(prof_id, j), raw_entry);
4336 /* update the masks for this profile to be sure we ignore fields that
4337 * are not relevant to our match criteria
4339 ice_update_fd_mask(hw, prof_id, mask_sel);
4345 * ice_add_prof_with_mask - add profile
4346 * @hw: pointer to the HW struct
4347 * @blk: hardware block
4348 * @id: profile tracking ID
4349 * @ptypes: array of bitmaps indicating ptypes (ICE_FLOW_PTYPE_MAX bits)
4350 * @es: extraction sequence (length of array is determined by the block)
4351 * @masks: extraction sequence (length of array is determined by the block)
4353 * This function registers a profile, which matches a set of PTYPES with a
4354 * particular extraction sequence. While the hardware profile is allocated
4355 * it will not be written until the first call to ice_add_flow that specifies
4356 * the ID value used here.
4359 ice_add_prof_with_mask(struct ice_hw *hw, enum ice_block blk, u64 id,
4360 u8 ptypes[], struct ice_fv_word *es, u16 *masks)
4362 u32 bytes = DIVIDE_AND_ROUND_UP(ICE_FLOW_PTYPE_MAX, BITS_PER_BYTE);
4363 ice_declare_bitmap(ptgs_used, ICE_XLT1_CNT);
4364 struct ice_prof_map *prof;
4365 enum ice_status status;
4369 ice_zero_bitmap(ptgs_used, ICE_XLT1_CNT);
4371 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
4373 /* search for existing profile */
4374 status = ice_find_prof_id_with_mask(hw, blk, es, masks, &prof_id);
4376 /* allocate profile ID */
4377 status = ice_alloc_prof_id(hw, blk, &prof_id);
4379 goto err_ice_add_prof;
4380 if (blk == ICE_BLK_FD) {
4381 /* For Flow Director block, the extraction sequence may
4382 * need to be altered in the case where there are paired
4383 * fields that have no match. This is necessary because
4384 * for Flow Director, src and dest fields need to paired
4385 * for filter programming and these values are swapped
4388 status = ice_update_fd_swap(hw, prof_id, es);
4390 goto err_ice_add_prof;
4392 status = ice_update_prof_masking(hw, blk, prof_id, es, masks);
4394 goto err_ice_add_prof;
4396 /* and write new es */
4397 ice_write_es(hw, blk, prof_id, es);
4400 ice_prof_inc_ref(hw, blk, prof_id);
4402 /* add profile info */
4404 prof = (struct ice_prof_map *)ice_malloc(hw, sizeof(*prof));
4406 goto err_ice_add_prof;
4408 prof->profile_cookie = id;
4409 prof->prof_id = prof_id;
4413 /* build list of ptgs */
4414 while (bytes && prof->ptg_cnt < ICE_MAX_PTG_PER_PROFILE) {
4417 if (!ptypes[byte]) {
4422 /* Examine 8 bits per byte */
4423 for (bit = 0; bit < 8; bit++) {
4424 if (ptypes[byte] & BIT(bit)) {
4429 ptype = byte * BITS_PER_BYTE + bit;
4431 /* The package should place all ptypes in a
4432 * non-zero PTG, so the following call should
4435 if (ice_ptg_find_ptype(hw, blk, ptype, &ptg))
4438 /* If PTG is already added, skip and continue */
4439 if (ice_is_bit_set(ptgs_used, ptg))
4442 ice_set_bit(ptg, ptgs_used);
4443 prof->ptg[prof->ptg_cnt] = ptg;
4445 if (++prof->ptg_cnt >= ICE_MAX_PTG_PER_PROFILE)
4448 /* nothing left in byte, then exit */
4449 m = ~((1 << (bit + 1)) - 1);
4450 if (!(ptypes[byte] & m))
4459 LIST_ADD(&prof->list, &hw->blk[blk].es.prof_map);
4460 status = ICE_SUCCESS;
4463 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
4468 * ice_add_prof - add profile
4469 * @hw: pointer to the HW struct
4470 * @blk: hardware block
4471 * @id: profile tracking ID
4472 * @ptypes: array of bitmaps indicating ptypes (ICE_FLOW_PTYPE_MAX bits)
4473 * @es: extraction sequence (length of array is determined by the block)
4475 * This function registers a profile, which matches a set of PTGs with a
4476 * particular extraction sequence. While the hardware profile is allocated
4477 * it will not be written until the first call to ice_add_flow that specifies
4478 * the ID value used here.
4481 ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64 id, u8 ptypes[],
4482 struct ice_fv_word *es)
4484 u32 bytes = DIVIDE_AND_ROUND_UP(ICE_FLOW_PTYPE_MAX, BITS_PER_BYTE);
4485 ice_declare_bitmap(ptgs_used, ICE_XLT1_CNT);
4486 struct ice_prof_map *prof;
4487 enum ice_status status;
4491 ice_zero_bitmap(ptgs_used, ICE_XLT1_CNT);
4493 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
4495 /* search for existing profile */
4496 status = ice_find_prof_id(hw, blk, es, &prof_id);
4498 /* allocate profile ID */
4499 status = ice_alloc_prof_id(hw, blk, &prof_id);
4501 goto err_ice_add_prof;
4502 if (blk == ICE_BLK_FD) {
4503 /* For Flow Director block, the extraction sequence may
4504 * need to be altered in the case where there are paired
4505 * fields that have no match. This is necessary because
4506 * for Flow Director, src and dest fields need to paired
4507 * for filter programming and these values are swapped
4510 status = ice_update_fd_swap(hw, prof_id, es);
4512 goto err_ice_add_prof;
4515 /* and write new es */
4516 ice_write_es(hw, blk, prof_id, es);
4519 ice_prof_inc_ref(hw, blk, prof_id);
4521 /* add profile info */
4523 prof = (struct ice_prof_map *)ice_malloc(hw, sizeof(*prof));
4525 goto err_ice_add_prof;
4527 prof->profile_cookie = id;
4528 prof->prof_id = prof_id;
4532 /* build list of ptgs */
4533 while (bytes && prof->ptg_cnt < ICE_MAX_PTG_PER_PROFILE) {
4536 if (!ptypes[byte]) {
4541 /* Examine 8 bits per byte */
4542 for (bit = 0; bit < 8; bit++) {
4543 if (ptypes[byte] & BIT(bit)) {
4548 ptype = byte * BITS_PER_BYTE + bit;
4550 /* The package should place all ptypes in a
4551 * non-zero PTG, so the following call should
4554 if (ice_ptg_find_ptype(hw, blk, ptype, &ptg))
4557 /* If PTG is already added, skip and continue */
4558 if (ice_is_bit_set(ptgs_used, ptg))
4561 ice_set_bit(ptg, ptgs_used);
4562 prof->ptg[prof->ptg_cnt] = ptg;
4564 if (++prof->ptg_cnt >= ICE_MAX_PTG_PER_PROFILE)
4567 /* nothing left in byte, then exit */
4568 m = ~((1 << (bit + 1)) - 1);
4569 if (!(ptypes[byte] & m))
4578 LIST_ADD(&prof->list, &hw->blk[blk].es.prof_map);
4579 status = ICE_SUCCESS;
4582 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
4587 * ice_search_prof_id_low - Search for a profile tracking ID low level
4588 * @hw: pointer to the HW struct
4589 * @blk: hardware block
4590 * @id: profile tracking ID
4592 * This will search for a profile tracking ID which was previously added. This
4593 * version assumes that the caller has already acquired the prof map lock.
4595 static struct ice_prof_map *
4596 ice_search_prof_id_low(struct ice_hw *hw, enum ice_block blk, u64 id)
4598 struct ice_prof_map *entry = NULL;
4599 struct ice_prof_map *map;
4601 LIST_FOR_EACH_ENTRY(map, &hw->blk[blk].es.prof_map, ice_prof_map,
4603 if (map->profile_cookie == id) {
4613 * ice_search_prof_id - Search for a profile tracking ID
4614 * @hw: pointer to the HW struct
4615 * @blk: hardware block
4616 * @id: profile tracking ID
4618 * This will search for a profile tracking ID which was previously added.
4620 struct ice_prof_map *
4621 ice_search_prof_id(struct ice_hw *hw, enum ice_block blk, u64 id)
4623 struct ice_prof_map *entry;
4625 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
4626 entry = ice_search_prof_id_low(hw, blk, id);
4627 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
4633 * ice_vsig_prof_id_count - count profiles in a VSIG
4634 * @hw: pointer to the HW struct
4635 * @blk: hardware block
4636 * @vsig: VSIG to remove the profile from
4639 ice_vsig_prof_id_count(struct ice_hw *hw, enum ice_block blk, u16 vsig)
4641 u16 idx = vsig & ICE_VSIG_IDX_M, count = 0;
4642 struct ice_vsig_prof *p;
4644 LIST_FOR_EACH_ENTRY(p, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4645 ice_vsig_prof, list) {
4653 * ice_rel_tcam_idx - release a TCAM index
4654 * @hw: pointer to the HW struct
4655 * @blk: hardware block
4656 * @idx: the index to release
4658 static enum ice_status
4659 ice_rel_tcam_idx(struct ice_hw *hw, enum ice_block blk, u16 idx)
4661 /* Masks to invoke a never match entry */
4662 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4663 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFE, 0xFF, 0xFF, 0xFF, 0xFF };
4664 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x01, 0x00, 0x00, 0x00, 0x00 };
4665 enum ice_status status;
4667 /* write the TCAM entry */
4668 status = ice_tcam_write_entry(hw, blk, idx, 0, 0, 0, 0, 0, vl_msk,
4673 /* release the TCAM entry */
4674 status = ice_free_tcam_ent(hw, blk, idx);
4680 * ice_rem_prof_id - remove one profile from a VSIG
4681 * @hw: pointer to the HW struct
4682 * @blk: hardware block
4683 * @prof: pointer to profile structure to remove
4685 static enum ice_status
4686 ice_rem_prof_id(struct ice_hw *hw, enum ice_block blk,
4687 struct ice_vsig_prof *prof)
4689 enum ice_status status;
4692 for (i = 0; i < prof->tcam_count; i++) {
4693 if (prof->tcam[i].in_use) {
4694 prof->tcam[i].in_use = false;
4695 status = ice_rel_tcam_idx(hw, blk,
4696 prof->tcam[i].tcam_idx);
4698 return ICE_ERR_HW_TABLE;
4706 * ice_rem_vsig - remove VSIG
4707 * @hw: pointer to the HW struct
4708 * @blk: hardware block
4709 * @vsig: the VSIG to remove
4710 * @chg: the change list
4712 static enum ice_status
4713 ice_rem_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig,
4714 struct LIST_HEAD_TYPE *chg)
4716 u16 idx = vsig & ICE_VSIG_IDX_M;
4717 struct ice_vsig_vsi *vsi_cur;
4718 struct ice_vsig_prof *d, *t;
4719 enum ice_status status;
4721 /* remove TCAM entries */
4722 LIST_FOR_EACH_ENTRY_SAFE(d, t,
4723 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4724 ice_vsig_prof, list) {
4725 status = ice_rem_prof_id(hw, blk, d);
4733 /* Move all VSIS associated with this VSIG to the default VSIG */
4734 vsi_cur = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
4735 /* If the VSIG has at least 1 VSI then iterate through the list
4736 * and remove the VSIs before deleting the group.
4740 struct ice_vsig_vsi *tmp = vsi_cur->next_vsi;
4741 struct ice_chs_chg *p;
4743 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4745 return ICE_ERR_NO_MEMORY;
4747 p->type = ICE_VSIG_REM;
4748 p->orig_vsig = vsig;
4749 p->vsig = ICE_DEFAULT_VSIG;
4750 p->vsi = vsi_cur - hw->blk[blk].xlt2.vsis;
4752 LIST_ADD(&p->list_entry, chg);
4758 status = ice_vsig_free(hw, blk, vsig);
4764 * ice_rem_prof_id_vsig - remove a specific profile from a VSIG
4765 * @hw: pointer to the HW struct
4766 * @blk: hardware block
4767 * @vsig: VSIG to remove the profile from
4768 * @hdl: profile handle indicating which profile to remove
4769 * @chg: list to receive a record of changes
4771 static enum ice_status
4772 ice_rem_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl,
4773 struct LIST_HEAD_TYPE *chg)
4775 u16 idx = vsig & ICE_VSIG_IDX_M;
4776 struct ice_vsig_prof *p, *t;
4777 enum ice_status status;
4779 LIST_FOR_EACH_ENTRY_SAFE(p, t,
4780 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4781 ice_vsig_prof, list) {
4782 if (p->profile_cookie == hdl) {
4783 if (ice_vsig_prof_id_count(hw, blk, vsig) == 1)
4784 /* this is the last profile, remove the VSIG */
4785 return ice_rem_vsig(hw, blk, vsig, chg);
4787 status = ice_rem_prof_id(hw, blk, p);
4796 return ICE_ERR_DOES_NOT_EXIST;
4800 * ice_rem_flow_all - remove all flows with a particular profile
4801 * @hw: pointer to the HW struct
4802 * @blk: hardware block
4803 * @id: profile tracking ID
4805 static enum ice_status
4806 ice_rem_flow_all(struct ice_hw *hw, enum ice_block blk, u64 id)
4808 struct ice_chs_chg *del, *tmp;
4809 struct LIST_HEAD_TYPE chg;
4810 enum ice_status status;
4813 INIT_LIST_HEAD(&chg);
4815 for (i = 1; i < ICE_MAX_VSIGS; i++) {
4816 if (hw->blk[blk].xlt2.vsig_tbl[i].in_use) {
4817 if (ice_has_prof_vsig(hw, blk, i, id)) {
4818 status = ice_rem_prof_id_vsig(hw, blk, i, id,
4821 goto err_ice_rem_flow_all;
4826 status = ice_upd_prof_hw(hw, blk, &chg);
4828 err_ice_rem_flow_all:
4829 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
4830 LIST_DEL(&del->list_entry);
4838 * ice_rem_prof - remove profile
4839 * @hw: pointer to the HW struct
4840 * @blk: hardware block
4841 * @id: profile tracking ID
4843 * This will remove the profile specified by the ID parameter, which was
4844 * previously created through ice_add_prof. If any existing entries
4845 * are associated with this profile, they will be removed as well.
4847 enum ice_status ice_rem_prof(struct ice_hw *hw, enum ice_block blk, u64 id)
4849 struct ice_prof_map *pmap;
4850 enum ice_status status;
4852 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
4854 pmap = ice_search_prof_id_low(hw, blk, id);
4856 status = ICE_ERR_DOES_NOT_EXIST;
4857 goto err_ice_rem_prof;
4860 /* remove all flows with this profile */
4861 status = ice_rem_flow_all(hw, blk, pmap->profile_cookie);
4863 goto err_ice_rem_prof;
4865 /* dereference profile, and possibly remove */
4866 ice_prof_dec_ref(hw, blk, pmap->prof_id);
4868 LIST_DEL(&pmap->list);
4871 status = ICE_SUCCESS;
4874 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
4879 * ice_get_prof - get profile
4880 * @hw: pointer to the HW struct
4881 * @blk: hardware block
4882 * @hdl: profile handle
4885 static enum ice_status
4886 ice_get_prof(struct ice_hw *hw, enum ice_block blk, u64 hdl,
4887 struct LIST_HEAD_TYPE *chg)
4889 struct ice_prof_map *map;
4890 struct ice_chs_chg *p;
4893 /* Get the details on the profile specified by the handle ID */
4894 map = ice_search_prof_id(hw, blk, hdl);
4896 return ICE_ERR_DOES_NOT_EXIST;
4898 for (i = 0; i < map->ptg_cnt; i++) {
4899 if (!hw->blk[blk].es.written[map->prof_id]) {
4900 /* add ES to change list */
4901 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4903 goto err_ice_get_prof;
4905 p->type = ICE_PTG_ES_ADD;
4907 p->ptg = map->ptg[i];
4911 p->prof_id = map->prof_id;
4913 hw->blk[blk].es.written[map->prof_id] = true;
4915 LIST_ADD(&p->list_entry, chg);
4922 /* let caller clean up the change list */
4923 return ICE_ERR_NO_MEMORY;
4927 * ice_get_profs_vsig - get a copy of the list of profiles from a VSIG
4928 * @hw: pointer to the HW struct
4929 * @blk: hardware block
4930 * @vsig: VSIG from which to copy the list
4933 * This routine makes a copy of the list of profiles in the specified VSIG.
4935 static enum ice_status
4936 ice_get_profs_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig,
4937 struct LIST_HEAD_TYPE *lst)
4939 struct ice_vsig_prof *ent1, *ent2;
4940 u16 idx = vsig & ICE_VSIG_IDX_M;
4942 LIST_FOR_EACH_ENTRY(ent1, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4943 ice_vsig_prof, list) {
4944 struct ice_vsig_prof *p;
4946 /* copy to the input list */
4947 p = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*p));
4949 goto err_ice_get_profs_vsig;
4951 ice_memcpy(p, ent1, sizeof(*p), ICE_NONDMA_TO_NONDMA);
4953 LIST_ADD_TAIL(&p->list, lst);
4958 err_ice_get_profs_vsig:
4959 LIST_FOR_EACH_ENTRY_SAFE(ent1, ent2, lst, ice_vsig_prof, list) {
4960 LIST_DEL(&ent1->list);
4964 return ICE_ERR_NO_MEMORY;
4968 * ice_add_prof_to_lst - add profile entry to a list
4969 * @hw: pointer to the HW struct
4970 * @blk: hardware block
4971 * @lst: the list to be added to
4972 * @hdl: profile handle of entry to add
4974 static enum ice_status
4975 ice_add_prof_to_lst(struct ice_hw *hw, enum ice_block blk,
4976 struct LIST_HEAD_TYPE *lst, u64 hdl)
4978 struct ice_vsig_prof *p;
4979 struct ice_prof_map *map;
4982 map = ice_search_prof_id(hw, blk, hdl);
4984 return ICE_ERR_DOES_NOT_EXIST;
4986 p = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*p));
4988 return ICE_ERR_NO_MEMORY;
4990 p->profile_cookie = map->profile_cookie;
4991 p->prof_id = map->prof_id;
4992 p->tcam_count = map->ptg_cnt;
4994 for (i = 0; i < map->ptg_cnt; i++) {
4995 p->tcam[i].prof_id = map->prof_id;
4996 p->tcam[i].tcam_idx = ICE_INVALID_TCAM;
4997 p->tcam[i].ptg = map->ptg[i];
5000 LIST_ADD(&p->list, lst);
5006 * ice_move_vsi - move VSI to another VSIG
5007 * @hw: pointer to the HW struct
5008 * @blk: hardware block
5009 * @vsi: the VSI to move
5010 * @vsig: the VSIG to move the VSI to
5011 * @chg: the change list
5013 static enum ice_status
5014 ice_move_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig,
5015 struct LIST_HEAD_TYPE *chg)
5017 enum ice_status status;
5018 struct ice_chs_chg *p;
5021 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5023 return ICE_ERR_NO_MEMORY;
5025 status = ice_vsig_find_vsi(hw, blk, vsi, &orig_vsig);
5027 status = ice_vsig_add_mv_vsi(hw, blk, vsi, vsig);
5034 p->type = ICE_VSI_MOVE;
5036 p->orig_vsig = orig_vsig;
5039 LIST_ADD(&p->list_entry, chg);
5045 * ice_prof_tcam_ena_dis - add enable or disable TCAM change
5046 * @hw: pointer to the HW struct
5047 * @blk: hardware block
5048 * @enable: true to enable, false to disable
5049 * @vsig: the vsig of the TCAM entry
5050 * @tcam: pointer the TCAM info structure of the TCAM to disable
5051 * @chg: the change list
5053 * This function appends an enable or disable TCAM entry in the change log
5055 static enum ice_status
5056 ice_prof_tcam_ena_dis(struct ice_hw *hw, enum ice_block blk, bool enable,
5057 u16 vsig, struct ice_tcam_inf *tcam,
5058 struct LIST_HEAD_TYPE *chg)
5060 enum ice_status status;
5061 struct ice_chs_chg *p;
5063 /* Default: enable means change the low flag bit to don't care */
5064 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x01, 0x00, 0x00, 0x00, 0x00 };
5065 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
5066 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x01, 0x00, 0x00, 0x00, 0x00 };
5068 /* if disabling, free the tcam */
5070 status = ice_free_tcam_ent(hw, blk, tcam->tcam_idx);
5076 /* for re-enabling, reallocate a tcam */
5077 status = ice_alloc_tcam_ent(hw, blk, &tcam->tcam_idx);
5081 /* add TCAM to change list */
5082 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5084 return ICE_ERR_NO_MEMORY;
5086 status = ice_tcam_write_entry(hw, blk, tcam->tcam_idx, tcam->prof_id,
5087 tcam->ptg, vsig, 0, 0, vl_msk, dc_msk,
5090 goto err_ice_prof_tcam_ena_dis;
5094 p->type = ICE_TCAM_ADD;
5095 p->add_tcam_idx = true;
5096 p->prof_id = tcam->prof_id;
5099 p->tcam_idx = tcam->tcam_idx;
5102 LIST_ADD(&p->list_entry, chg);
5106 err_ice_prof_tcam_ena_dis:
5112 * ice_adj_prof_priorities - adjust profile based on priorities
5113 * @hw: pointer to the HW struct
5114 * @blk: hardware block
5115 * @vsig: the VSIG for which to adjust profile priorities
5116 * @chg: the change list
5118 static enum ice_status
5119 ice_adj_prof_priorities(struct ice_hw *hw, enum ice_block blk, u16 vsig,
5120 struct LIST_HEAD_TYPE *chg)
5122 ice_declare_bitmap(ptgs_used, ICE_XLT1_CNT);
5123 struct ice_vsig_prof *t;
5124 enum ice_status status;
5127 ice_zero_bitmap(ptgs_used, ICE_XLT1_CNT);
5128 idx = vsig & ICE_VSIG_IDX_M;
5130 /* Priority is based on the order in which the profiles are added. The
5131 * newest added profile has highest priority and the oldest added
5132 * profile has the lowest priority. Since the profile property list for
5133 * a VSIG is sorted from newest to oldest, this code traverses the list
5134 * in order and enables the first of each PTG that it finds (that is not
5135 * already enabled); it also disables any duplicate PTGs that it finds
5136 * in the older profiles (that are currently enabled).
5139 LIST_FOR_EACH_ENTRY(t, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
5140 ice_vsig_prof, list) {
5143 for (i = 0; i < t->tcam_count; i++) {
5144 /* Scan the priorities from newest to oldest.
5145 * Make sure that the newest profiles take priority.
5147 if (ice_is_bit_set(ptgs_used, t->tcam[i].ptg) &&
5148 t->tcam[i].in_use) {
5149 /* need to mark this PTG as never match, as it
5150 * was already in use and therefore duplicate
5151 * (and lower priority)
5153 status = ice_prof_tcam_ena_dis(hw, blk, false,
5159 } else if (!ice_is_bit_set(ptgs_used, t->tcam[i].ptg) &&
5160 !t->tcam[i].in_use) {
5161 /* need to enable this PTG, as it in not in use
5162 * and not enabled (highest priority)
5164 status = ice_prof_tcam_ena_dis(hw, blk, true,
5172 /* keep track of used ptgs */
5173 ice_set_bit(t->tcam[i].ptg, ptgs_used);
5181 * ice_add_prof_id_vsig - add profile to VSIG
5182 * @hw: pointer to the HW struct
5183 * @blk: hardware block
5184 * @vsig: the VSIG to which this profile is to be added
5185 * @hdl: the profile handle indicating the profile to add
5186 * @chg: the change list
5188 static enum ice_status
5189 ice_add_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl,
5190 struct LIST_HEAD_TYPE *chg)
5192 /* Masks that ignore flags */
5193 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
5194 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0x00, 0x00, 0x00 };
5195 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
5196 struct ice_prof_map *map;
5197 struct ice_vsig_prof *t;
5198 struct ice_chs_chg *p;
5201 /* Get the details on the profile specified by the handle ID */
5202 map = ice_search_prof_id(hw, blk, hdl);
5204 return ICE_ERR_DOES_NOT_EXIST;
5206 /* Error, if this VSIG already has this profile */
5207 if (ice_has_prof_vsig(hw, blk, vsig, hdl))
5208 return ICE_ERR_ALREADY_EXISTS;
5210 /* new VSIG profile structure */
5211 t = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*t));
5213 goto err_ice_add_prof_id_vsig;
5215 t->profile_cookie = map->profile_cookie;
5216 t->prof_id = map->prof_id;
5217 t->tcam_count = map->ptg_cnt;
5219 /* create TCAM entries */
5220 for (i = 0; i < map->ptg_cnt; i++) {
5221 enum ice_status status;
5224 /* add TCAM to change list */
5225 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5227 goto err_ice_add_prof_id_vsig;
5229 /* allocate the TCAM entry index */
5230 status = ice_alloc_tcam_ent(hw, blk, &tcam_idx);
5233 goto err_ice_add_prof_id_vsig;
5236 t->tcam[i].ptg = map->ptg[i];
5237 t->tcam[i].prof_id = map->prof_id;
5238 t->tcam[i].tcam_idx = tcam_idx;
5239 t->tcam[i].in_use = true;
5241 p->type = ICE_TCAM_ADD;
5242 p->add_tcam_idx = true;
5243 p->prof_id = t->tcam[i].prof_id;
5244 p->ptg = t->tcam[i].ptg;
5246 p->tcam_idx = t->tcam[i].tcam_idx;
5248 /* write the TCAM entry */
5249 status = ice_tcam_write_entry(hw, blk, t->tcam[i].tcam_idx,
5251 t->tcam[i].ptg, vsig, 0, 0,
5252 vl_msk, dc_msk, nm_msk);
5254 goto err_ice_add_prof_id_vsig;
5257 LIST_ADD(&p->list_entry, chg);
5260 /* add profile to VSIG */
5262 &hw->blk[blk].xlt2.vsig_tbl[(vsig & ICE_VSIG_IDX_M)].prop_lst);
5266 err_ice_add_prof_id_vsig:
5267 /* let caller clean up the change list */
5269 return ICE_ERR_NO_MEMORY;
5273 * ice_create_prof_id_vsig - add a new VSIG with a single profile
5274 * @hw: pointer to the HW struct
5275 * @blk: hardware block
5276 * @vsi: the initial VSI that will be in VSIG
5277 * @hdl: the profile handle of the profile that will be added to the VSIG
5278 * @chg: the change list
5280 static enum ice_status
5281 ice_create_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl,
5282 struct LIST_HEAD_TYPE *chg)
5284 enum ice_status status;
5285 struct ice_chs_chg *p;
5288 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5290 return ICE_ERR_NO_MEMORY;
5292 new_vsig = ice_vsig_alloc(hw, blk);
5294 status = ICE_ERR_HW_TABLE;
5295 goto err_ice_create_prof_id_vsig;
5298 status = ice_move_vsi(hw, blk, vsi, new_vsig, chg);
5300 goto err_ice_create_prof_id_vsig;
5302 status = ice_add_prof_id_vsig(hw, blk, new_vsig, hdl, chg);
5304 goto err_ice_create_prof_id_vsig;
5306 p->type = ICE_VSIG_ADD;
5308 p->orig_vsig = ICE_DEFAULT_VSIG;
5311 LIST_ADD(&p->list_entry, chg);
5315 err_ice_create_prof_id_vsig:
5316 /* let caller clean up the change list */
5322 * ice_create_vsig_from_list - create a new VSIG with a list of profiles
5323 * @hw: pointer to the HW struct
5324 * @blk: hardware block
5325 * @vsi: the initial VSI that will be in VSIG
5326 * @lst: the list of profile that will be added to the VSIG
5327 * @chg: the change list
5329 static enum ice_status
5330 ice_create_vsig_from_lst(struct ice_hw *hw, enum ice_block blk, u16 vsi,
5331 struct LIST_HEAD_TYPE *lst, struct LIST_HEAD_TYPE *chg)
5333 struct ice_vsig_prof *t;
5334 enum ice_status status;
5337 vsig = ice_vsig_alloc(hw, blk);
5339 return ICE_ERR_HW_TABLE;
5341 status = ice_move_vsi(hw, blk, vsi, vsig, chg);
5345 LIST_FOR_EACH_ENTRY(t, lst, ice_vsig_prof, list) {
5346 status = ice_add_prof_id_vsig(hw, blk, vsig, t->profile_cookie,
5356 * ice_find_prof_vsig - find a VSIG with a specific profile handle
5357 * @hw: pointer to the HW struct
5358 * @blk: hardware block
5359 * @hdl: the profile handle of the profile to search for
5360 * @vsig: returns the VSIG with the matching profile
5363 ice_find_prof_vsig(struct ice_hw *hw, enum ice_block blk, u64 hdl, u16 *vsig)
5365 struct ice_vsig_prof *t;
5366 struct LIST_HEAD_TYPE lst;
5367 enum ice_status status;
5369 INIT_LIST_HEAD(&lst);
5371 t = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*t));
5375 t->profile_cookie = hdl;
5376 LIST_ADD(&t->list, &lst);
5378 status = ice_find_dup_props_vsig(hw, blk, &lst, vsig);
5383 return status == ICE_SUCCESS;
5387 * ice_add_vsi_flow - add VSI flow
5388 * @hw: pointer to the HW struct
5389 * @blk: hardware block
5391 * @vsig: target VSIG to include the input VSI
5393 * Calling this function will add the VSI to a given VSIG and
5394 * update the HW tables accordingly. This call can be used to
5395 * add multiple VSIs to a VSIG if we know beforehand that those
5396 * VSIs have the same characteristics of the VSIG. This will
5397 * save time in generating a new VSIG and TCAMs till a match is
5398 * found and subsequent rollback when a matching VSIG is found.
5401 ice_add_vsi_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
5403 struct ice_chs_chg *tmp, *del;
5404 struct LIST_HEAD_TYPE chg;
5405 enum ice_status status;
5407 /* if target VSIG is default the move is invalid */
5408 if ((vsig & ICE_VSIG_IDX_M) == ICE_DEFAULT_VSIG)
5409 return ICE_ERR_PARAM;
5411 INIT_LIST_HEAD(&chg);
5413 /* move VSI to the VSIG that matches */
5414 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5415 /* update hardware if success */
5417 status = ice_upd_prof_hw(hw, blk, &chg);
5419 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
5420 LIST_DEL(&del->list_entry);
5428 * ice_add_prof_id_flow - add profile flow
5429 * @hw: pointer to the HW struct
5430 * @blk: hardware block
5431 * @vsi: the VSI to enable with the profile specified by ID
5432 * @hdl: profile handle
5434 * Calling this function will update the hardware tables to enable the
5435 * profile indicated by the ID parameter for the VSIs specified in the VSI
5436 * array. Once successfully called, the flow will be enabled.
5439 ice_add_prof_id_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl)
5441 struct ice_vsig_prof *tmp1, *del1;
5442 struct LIST_HEAD_TYPE union_lst;
5443 struct ice_chs_chg *tmp, *del;
5444 struct LIST_HEAD_TYPE chrs;
5445 struct LIST_HEAD_TYPE chg;
5446 enum ice_status status;
5447 u16 vsig, or_vsig = 0;
5449 INIT_LIST_HEAD(&union_lst);
5450 INIT_LIST_HEAD(&chrs);
5451 INIT_LIST_HEAD(&chg);
5454 status = ice_get_prof(hw, blk, hdl, &chg);
5458 /* determine if VSI is already part of a VSIG */
5459 status = ice_vsig_find_vsi(hw, blk, vsi, &vsig);
5460 if (!status && vsig) {
5467 /* make sure that there is no overlap/conflict between the new
5468 * characteristics and the existing ones; we don't support that
5471 if (ice_has_prof_vsig(hw, blk, vsig, hdl)) {
5472 status = ICE_ERR_ALREADY_EXISTS;
5473 goto err_ice_add_prof_id_flow;
5476 /* last VSI in the VSIG? */
5477 status = ice_vsig_get_ref(hw, blk, vsig, &ref);
5479 goto err_ice_add_prof_id_flow;
5480 only_vsi = (ref == 1);
5482 /* create a union of the current profiles and the one being
5485 status = ice_get_profs_vsig(hw, blk, vsig, &union_lst);
5487 goto err_ice_add_prof_id_flow;
5489 status = ice_add_prof_to_lst(hw, blk, &union_lst, hdl);
5491 goto err_ice_add_prof_id_flow;
5493 /* search for an existing VSIG with an exact charc match */
5494 status = ice_find_dup_props_vsig(hw, blk, &union_lst, &vsig);
5496 /* move VSI to the VSIG that matches */
5497 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5499 goto err_ice_add_prof_id_flow;
5501 /* VSI has been moved out of or_vsig. If the or_vsig had
5502 * only that VSI it is now empty and can be removed.
5505 status = ice_rem_vsig(hw, blk, or_vsig, &chg);
5507 goto err_ice_add_prof_id_flow;
5509 } else if (only_vsi) {
5510 /* If the original VSIG only contains one VSI, then it
5511 * will be the requesting VSI. In this case the VSI is
5512 * not sharing entries and we can simply add the new
5513 * profile to the VSIG.
5515 status = ice_add_prof_id_vsig(hw, blk, vsig, hdl, &chg);
5517 goto err_ice_add_prof_id_flow;
5519 /* Adjust priorities */
5520 status = ice_adj_prof_priorities(hw, blk, vsig, &chg);
5522 goto err_ice_add_prof_id_flow;
5524 /* No match, so we need a new VSIG */
5525 status = ice_create_vsig_from_lst(hw, blk, vsi,
5528 goto err_ice_add_prof_id_flow;
5530 /* Adjust priorities */
5531 status = ice_adj_prof_priorities(hw, blk, vsig, &chg);
5533 goto err_ice_add_prof_id_flow;
5536 /* need to find or add a VSIG */
5537 /* search for an existing VSIG with an exact charc match */
5538 if (ice_find_prof_vsig(hw, blk, hdl, &vsig)) {
5539 /* found an exact match */
5540 /* add or move VSI to the VSIG that matches */
5541 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5543 goto err_ice_add_prof_id_flow;
5545 /* we did not find an exact match */
5546 /* we need to add a VSIG */
5547 status = ice_create_prof_id_vsig(hw, blk, vsi, hdl,
5550 goto err_ice_add_prof_id_flow;
5554 /* update hardware */
5556 status = ice_upd_prof_hw(hw, blk, &chg);
5558 err_ice_add_prof_id_flow:
5559 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
5560 LIST_DEL(&del->list_entry);
5564 LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, &union_lst, ice_vsig_prof, list) {
5565 LIST_DEL(&del1->list);
5569 LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, &chrs, ice_vsig_prof, list) {
5570 LIST_DEL(&del1->list);
5578 * ice_rem_prof_from_list - remove a profile from list
5579 * @hw: pointer to the HW struct
5580 * @lst: list to remove the profile from
5581 * @hdl: the profile handle indicating the profile to remove
5583 static enum ice_status
5584 ice_rem_prof_from_list(struct ice_hw *hw, struct LIST_HEAD_TYPE *lst, u64 hdl)
5586 struct ice_vsig_prof *ent, *tmp;
5588 LIST_FOR_EACH_ENTRY_SAFE(ent, tmp, lst, ice_vsig_prof, list) {
5589 if (ent->profile_cookie == hdl) {
5590 LIST_DEL(&ent->list);
5596 return ICE_ERR_DOES_NOT_EXIST;
5600 * ice_rem_prof_id_flow - remove flow
5601 * @hw: pointer to the HW struct
5602 * @blk: hardware block
5603 * @vsi: the VSI from which to remove the profile specified by ID
5604 * @hdl: profile tracking handle
5606 * Calling this function will update the hardware tables to remove the
5607 * profile indicated by the ID parameter for the VSIs specified in the VSI
5608 * array. Once successfully called, the flow will be disabled.
5611 ice_rem_prof_id_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl)
5613 struct ice_vsig_prof *tmp1, *del1;
5614 struct LIST_HEAD_TYPE chg, copy;
5615 struct ice_chs_chg *tmp, *del;
5616 enum ice_status status;
5619 INIT_LIST_HEAD(©);
5620 INIT_LIST_HEAD(&chg);
5622 /* determine if VSI is already part of a VSIG */
5623 status = ice_vsig_find_vsi(hw, blk, vsi, &vsig);
5624 if (!status && vsig) {
5630 last_profile = ice_vsig_prof_id_count(hw, blk, vsig) == 1;
5631 status = ice_vsig_get_ref(hw, blk, vsig, &ref);
5633 goto err_ice_rem_prof_id_flow;
5634 only_vsi = (ref == 1);
5637 /* If the original VSIG only contains one reference,
5638 * which will be the requesting VSI, then the VSI is not
5639 * sharing entries and we can simply remove the specific
5640 * characteristics from the VSIG.
5644 /* If there are no profiles left for this VSIG,
5645 * then simply remove the the VSIG.
5647 status = ice_rem_vsig(hw, blk, vsig, &chg);
5649 goto err_ice_rem_prof_id_flow;
5651 status = ice_rem_prof_id_vsig(hw, blk, vsig,
5654 goto err_ice_rem_prof_id_flow;
5656 /* Adjust priorities */
5657 status = ice_adj_prof_priorities(hw, blk, vsig,
5660 goto err_ice_rem_prof_id_flow;
5664 /* Make a copy of the VSIG's list of Profiles */
5665 status = ice_get_profs_vsig(hw, blk, vsig, ©);
5667 goto err_ice_rem_prof_id_flow;
5669 /* Remove specified profile entry from the list */
5670 status = ice_rem_prof_from_list(hw, ©, hdl);
5672 goto err_ice_rem_prof_id_flow;
5674 if (LIST_EMPTY(©)) {
5675 status = ice_move_vsi(hw, blk, vsi,
5676 ICE_DEFAULT_VSIG, &chg);
5678 goto err_ice_rem_prof_id_flow;
5680 } else if (!ice_find_dup_props_vsig(hw, blk, ©,
5682 /* found an exact match */
5683 /* add or move VSI to the VSIG that matches */
5684 /* Search for a VSIG with a matching profile
5688 /* Found match, move VSI to the matching VSIG */
5689 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5691 goto err_ice_rem_prof_id_flow;
5693 /* since no existing VSIG supports this
5694 * characteristic pattern, we need to create a
5695 * new VSIG and TCAM entries
5697 status = ice_create_vsig_from_lst(hw, blk, vsi,
5700 goto err_ice_rem_prof_id_flow;
5702 /* Adjust priorities */
5703 status = ice_adj_prof_priorities(hw, blk, vsig,
5706 goto err_ice_rem_prof_id_flow;
5710 status = ICE_ERR_DOES_NOT_EXIST;
5713 /* update hardware tables */
5715 status = ice_upd_prof_hw(hw, blk, &chg);
5717 err_ice_rem_prof_id_flow:
5718 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
5719 LIST_DEL(&del->list_entry);
5723 LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, ©, ice_vsig_prof, list) {
5724 LIST_DEL(&del1->list);