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 status = ice_acquire_global_cfg_lock(hw, ICE_RES_WRITE);
968 for (i = 0; i < count; i++) {
969 bool last = ((i + 1) == count);
972 /* check next buffer for metadata flag */
973 bh = (struct ice_buf_hdr *)(bufs + i + 1);
975 /* A set metadata flag in the next buffer will signal
976 * that the current buffer will be the last buffer
979 if (LE16_TO_CPU(bh->section_count))
980 if (LE32_TO_CPU(bh->section_entry[0].type) &
985 bh = (struct ice_buf_hdr *)(bufs + i);
987 status = ice_aq_download_pkg(hw, bh, ICE_PKG_BUF_SIZE, last,
988 &offset, &info, NULL);
990 ice_debug(hw, ICE_DBG_PKG,
991 "Pkg download failed: err %d off %d inf %d\n",
992 status, offset, info);
1000 ice_release_global_cfg_lock(hw);
1006 * ice_aq_get_pkg_info_list
1007 * @hw: pointer to the hardware structure
1008 * @pkg_info: the buffer which will receive the information list
1009 * @buf_size: the size of the pkg_info information buffer
1010 * @cd: pointer to command details structure or NULL
1012 * Get Package Info List (0x0C43)
1014 static enum ice_status
1015 ice_aq_get_pkg_info_list(struct ice_hw *hw,
1016 struct ice_aqc_get_pkg_info_resp *pkg_info,
1017 u16 buf_size, struct ice_sq_cd *cd)
1019 struct ice_aq_desc desc;
1021 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1022 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_pkg_info_list);
1024 return ice_aq_send_cmd(hw, &desc, pkg_info, buf_size, cd);
1029 * @hw: pointer to the hardware structure
1030 * @ice_seg: pointer to the segment of the package to be downloaded
1032 * Handles the download of a complete package.
1034 static enum ice_status
1035 ice_download_pkg(struct ice_hw *hw, struct ice_seg *ice_seg)
1037 struct ice_buf_table *ice_buf_tbl;
1039 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1040 ice_debug(hw, ICE_DBG_PKG, "Segment version: %d.%d.%d.%d\n",
1041 ice_seg->hdr.seg_ver.major, ice_seg->hdr.seg_ver.minor,
1042 ice_seg->hdr.seg_ver.update, ice_seg->hdr.seg_ver.draft);
1044 ice_debug(hw, ICE_DBG_PKG, "Seg: type 0x%X, size %d, name %s\n",
1045 LE32_TO_CPU(ice_seg->hdr.seg_type),
1046 LE32_TO_CPU(ice_seg->hdr.seg_size), ice_seg->hdr.seg_name);
1048 ice_buf_tbl = ice_find_buf_table(ice_seg);
1050 ice_debug(hw, ICE_DBG_PKG, "Seg buf count: %d\n",
1051 LE32_TO_CPU(ice_buf_tbl->buf_count));
1053 return ice_dwnld_cfg_bufs(hw, ice_buf_tbl->buf_array,
1054 LE32_TO_CPU(ice_buf_tbl->buf_count));
1059 * @hw: pointer to the hardware structure
1060 * @pkg_hdr: pointer to the driver's package hdr
1062 * Saves off the package details into the HW structure.
1064 static enum ice_status
1065 ice_init_pkg_info(struct ice_hw *hw, struct ice_pkg_hdr *pkg_hdr)
1067 struct ice_global_metadata_seg *meta_seg;
1068 struct ice_generic_seg_hdr *seg_hdr;
1070 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1072 return ICE_ERR_PARAM;
1074 meta_seg = (struct ice_global_metadata_seg *)
1075 ice_find_seg_in_pkg(hw, SEGMENT_TYPE_METADATA, pkg_hdr);
1077 hw->pkg_ver = meta_seg->pkg_ver;
1078 ice_memcpy(hw->pkg_name, meta_seg->pkg_name,
1079 sizeof(hw->pkg_name), ICE_NONDMA_TO_NONDMA);
1081 ice_debug(hw, ICE_DBG_PKG, "Pkg: %d.%d.%d.%d, %s\n",
1082 meta_seg->pkg_ver.major, meta_seg->pkg_ver.minor,
1083 meta_seg->pkg_ver.update, meta_seg->pkg_ver.draft,
1084 meta_seg->pkg_name);
1086 ice_debug(hw, ICE_DBG_INIT,
1087 "Did not find metadata segment in driver package\n");
1091 seg_hdr = ice_find_seg_in_pkg(hw, SEGMENT_TYPE_ICE, pkg_hdr);
1093 hw->ice_pkg_ver = seg_hdr->seg_ver;
1094 ice_memcpy(hw->ice_pkg_name, seg_hdr->seg_name,
1095 sizeof(hw->ice_pkg_name), ICE_NONDMA_TO_NONDMA);
1097 ice_debug(hw, ICE_DBG_PKG, "Ice Pkg: %d.%d.%d.%d, %s\n",
1098 seg_hdr->seg_ver.major, seg_hdr->seg_ver.minor,
1099 seg_hdr->seg_ver.update, seg_hdr->seg_ver.draft,
1102 ice_debug(hw, ICE_DBG_INIT,
1103 "Did not find ice segment in driver package\n");
1112 * @hw: pointer to the hardware structure
1114 * Store details of the package currently loaded in HW into the HW structure.
1116 static enum ice_status ice_get_pkg_info(struct ice_hw *hw)
1118 struct ice_aqc_get_pkg_info_resp *pkg_info;
1119 enum ice_status status;
1123 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1125 size = sizeof(*pkg_info) + (sizeof(pkg_info->pkg_info[0]) *
1127 pkg_info = (struct ice_aqc_get_pkg_info_resp *)ice_malloc(hw, size);
1129 return ICE_ERR_NO_MEMORY;
1131 status = ice_aq_get_pkg_info_list(hw, pkg_info, size, NULL);
1133 goto init_pkg_free_alloc;
1135 for (i = 0; i < LE32_TO_CPU(pkg_info->count); i++) {
1136 #define ICE_PKG_FLAG_COUNT 4
1137 char flags[ICE_PKG_FLAG_COUNT + 1] = { 0 };
1140 if (pkg_info->pkg_info[i].is_active) {
1141 flags[place++] = 'A';
1142 hw->active_pkg_ver = pkg_info->pkg_info[i].ver;
1143 ice_memcpy(hw->active_pkg_name,
1144 pkg_info->pkg_info[i].name,
1145 sizeof(hw->active_pkg_name),
1146 ICE_NONDMA_TO_NONDMA);
1147 hw->active_pkg_in_nvm = pkg_info->pkg_info[i].is_in_nvm;
1149 if (pkg_info->pkg_info[i].is_active_at_boot)
1150 flags[place++] = 'B';
1151 if (pkg_info->pkg_info[i].is_modified)
1152 flags[place++] = 'M';
1153 if (pkg_info->pkg_info[i].is_in_nvm)
1154 flags[place++] = 'N';
1156 ice_debug(hw, ICE_DBG_PKG, "Pkg[%d]: %d.%d.%d.%d,%s,%s\n",
1157 i, pkg_info->pkg_info[i].ver.major,
1158 pkg_info->pkg_info[i].ver.minor,
1159 pkg_info->pkg_info[i].ver.update,
1160 pkg_info->pkg_info[i].ver.draft,
1161 pkg_info->pkg_info[i].name, flags);
1164 init_pkg_free_alloc:
1165 ice_free(hw, pkg_info);
1172 * ice_verify_pkg - verify package
1173 * @pkg: pointer to the package buffer
1174 * @len: size of the package buffer
1176 * Verifies various attributes of the package file, including length, format
1177 * version, and the requirement of at least one segment.
1179 static enum ice_status ice_verify_pkg(struct ice_pkg_hdr *pkg, u32 len)
1184 if (len < sizeof(*pkg))
1185 return ICE_ERR_BUF_TOO_SHORT;
1187 if (pkg->format_ver.major != ICE_PKG_FMT_VER_MAJ ||
1188 pkg->format_ver.minor != ICE_PKG_FMT_VER_MNR ||
1189 pkg->format_ver.update != ICE_PKG_FMT_VER_UPD ||
1190 pkg->format_ver.draft != ICE_PKG_FMT_VER_DFT)
1193 /* pkg must have at least one segment */
1194 seg_count = LE32_TO_CPU(pkg->seg_count);
1198 /* make sure segment array fits in package length */
1199 if (len < sizeof(*pkg) + ((seg_count - 1) * sizeof(pkg->seg_offset)))
1200 return ICE_ERR_BUF_TOO_SHORT;
1202 /* all segments must fit within length */
1203 for (i = 0; i < seg_count; i++) {
1204 u32 off = LE32_TO_CPU(pkg->seg_offset[i]);
1205 struct ice_generic_seg_hdr *seg;
1207 /* segment header must fit */
1208 if (len < off + sizeof(*seg))
1209 return ICE_ERR_BUF_TOO_SHORT;
1211 seg = (struct ice_generic_seg_hdr *)((u8 *)pkg + off);
1213 /* segment body must fit */
1214 if (len < off + LE32_TO_CPU(seg->seg_size))
1215 return ICE_ERR_BUF_TOO_SHORT;
1222 * ice_free_seg - free package segment pointer
1223 * @hw: pointer to the hardware structure
1225 * Frees the package segment pointer in the proper manner, depending on if the
1226 * segment was allocated or just the passed in pointer was stored.
1228 void ice_free_seg(struct ice_hw *hw)
1231 ice_free(hw, hw->pkg_copy);
1232 hw->pkg_copy = NULL;
1239 * ice_init_fd_mask_regs - initialize Flow Director mask registers
1240 * @hw: pointer to the HW struct
1242 * This function sets up the Flow Director mask registers to allow for complete
1243 * masking off of any of the 24 Field Vector words. After this call, mask 0 will
1244 * mask off all of FV index 0, mask 1 will mask off all of FV index 1, etc.
1246 static void ice_init_fd_mask_regs(struct ice_hw *hw)
1250 for (i = 0; i < hw->blk[ICE_BLK_FD].es.fvw; i++) {
1251 wr32(hw, GLQF_FDMASK(i), i);
1252 ice_debug(hw, ICE_DBG_INIT, "init fd mask(%d): %x = %x\n", i,
1258 * ice_init_pkg_regs - initialize additional package registers
1259 * @hw: pointer to the hardware structure
1261 static void ice_init_pkg_regs(struct ice_hw *hw)
1263 #define ICE_SW_BLK_INP_MASK_L 0xFFFFFFFF
1264 #define ICE_SW_BLK_INP_MASK_H 0x0000FFFF
1265 #define ICE_SW_BLK_IDX 0
1267 /* setup Switch block input mask, which is 48-bits in two parts */
1268 wr32(hw, GL_PREEXT_L2_PMASK0(ICE_SW_BLK_IDX), ICE_SW_BLK_INP_MASK_L);
1269 wr32(hw, GL_PREEXT_L2_PMASK1(ICE_SW_BLK_IDX), ICE_SW_BLK_INP_MASK_H);
1270 /* setup default flow director masks */
1271 ice_init_fd_mask_regs(hw);
1275 * ice_chk_pkg_version - check package version for compatibility with driver
1276 * @hw: pointer to the hardware structure
1277 * @pkg_ver: pointer to a version structure to check
1279 * Check to make sure that the package about to be downloaded is compatible with
1280 * the driver. To be compatible, the major and minor components of the package
1281 * version must match our ICE_PKG_SUPP_VER_MAJ and ICE_PKG_SUPP_VER_MNR
1284 static enum ice_status
1285 ice_chk_pkg_version(struct ice_hw *hw, struct ice_pkg_ver *pkg_ver)
1287 if (pkg_ver->major != ICE_PKG_SUPP_VER_MAJ ||
1288 pkg_ver->minor != ICE_PKG_SUPP_VER_MNR) {
1289 ice_info(hw, "ERROR: Incompatible package: %d.%d.%d.%d - requires package version: %d.%d.*.*\n",
1290 pkg_ver->major, pkg_ver->minor, pkg_ver->update,
1291 pkg_ver->draft, ICE_PKG_SUPP_VER_MAJ,
1292 ICE_PKG_SUPP_VER_MNR);
1294 return ICE_ERR_NOT_SUPPORTED;
1301 * ice_init_pkg - initialize/download package
1302 * @hw: pointer to the hardware structure
1303 * @buf: pointer to the package buffer
1304 * @len: size of the package buffer
1306 * This function initializes a package. The package contains HW tables
1307 * required to do packet processing. First, the function extracts package
1308 * information such as version. Then it finds the ice configuration segment
1309 * within the package; this function then saves a copy of the segment pointer
1310 * within the supplied package buffer. Next, the function will cache any hints
1311 * from the package, followed by downloading the package itself. Note, that if
1312 * a previous PF driver has already downloaded the package successfully, then
1313 * the current driver will not have to download the package again.
1315 * The local package contents will be used to query default behavior and to
1316 * update specific sections of the HW's version of the package (e.g. to update
1317 * the parse graph to understand new protocols).
1319 * This function stores a pointer to the package buffer memory, and it is
1320 * expected that the supplied buffer will not be freed immediately. If the
1321 * package buffer needs to be freed, such as when read from a file, use
1322 * ice_copy_and_init_pkg() instead of directly calling ice_init_pkg() in this
1325 enum ice_status ice_init_pkg(struct ice_hw *hw, u8 *buf, u32 len)
1327 struct ice_pkg_hdr *pkg;
1328 enum ice_status status;
1329 struct ice_seg *seg;
1332 return ICE_ERR_PARAM;
1334 pkg = (struct ice_pkg_hdr *)buf;
1335 status = ice_verify_pkg(pkg, len);
1337 ice_debug(hw, ICE_DBG_INIT, "failed to verify pkg (err: %d)\n",
1342 /* initialize package info */
1343 status = ice_init_pkg_info(hw, pkg);
1347 /* before downloading the package, check package version for
1348 * compatibility with driver
1350 status = ice_chk_pkg_version(hw, &hw->pkg_ver);
1354 /* find segment in given package */
1355 seg = (struct ice_seg *)ice_find_seg_in_pkg(hw, SEGMENT_TYPE_ICE, pkg);
1357 ice_debug(hw, ICE_DBG_INIT, "no ice segment in package.\n");
1361 /* initialize package hints and then download package */
1362 ice_init_pkg_hints(hw, seg);
1363 status = ice_download_pkg(hw, seg);
1364 if (status == ICE_ERR_AQ_NO_WORK) {
1365 ice_debug(hw, ICE_DBG_INIT,
1366 "package previously loaded - no work.\n");
1367 status = ICE_SUCCESS;
1370 /* Get information on the package currently loaded in HW, then make sure
1371 * the driver is compatible with this version.
1374 status = ice_get_pkg_info(hw);
1376 status = ice_chk_pkg_version(hw, &hw->active_pkg_ver);
1381 /* on successful package download update other required
1382 * registers to support the package and fill HW tables
1383 * with package content.
1385 ice_init_pkg_regs(hw);
1386 ice_fill_blk_tbls(hw);
1388 ice_debug(hw, ICE_DBG_INIT, "package load failed, %d\n",
1396 * ice_copy_and_init_pkg - initialize/download a copy of the package
1397 * @hw: pointer to the hardware structure
1398 * @buf: pointer to the package buffer
1399 * @len: size of the package buffer
1401 * This function copies the package buffer, and then calls ice_init_pkg() to
1402 * initialize the copied package contents.
1404 * The copying is necessary if the package buffer supplied is constant, or if
1405 * the memory may disappear shortly after calling this function.
1407 * If the package buffer resides in the data segment and can be modified, the
1408 * caller is free to use ice_init_pkg() instead of ice_copy_and_init_pkg().
1410 * However, if the package buffer needs to be copied first, such as when being
1411 * read from a file, the caller should use ice_copy_and_init_pkg().
1413 * This function will first copy the package buffer, before calling
1414 * ice_init_pkg(). The caller is free to immediately destroy the original
1415 * package buffer, as the new copy will be managed by this function and
1418 enum ice_status ice_copy_and_init_pkg(struct ice_hw *hw, const u8 *buf, u32 len)
1420 enum ice_status status;
1424 return ICE_ERR_PARAM;
1426 buf_copy = (u8 *)ice_memdup(hw, buf, len, ICE_NONDMA_TO_NONDMA);
1428 status = ice_init_pkg(hw, buf_copy, len);
1430 /* Free the copy, since we failed to initialize the package */
1431 ice_free(hw, buf_copy);
1433 /* Track the copied pkg so we can free it later */
1434 hw->pkg_copy = buf_copy;
1443 * @hw: pointer to the HW structure
1445 * Allocates a package buffer and returns a pointer to the buffer header.
1446 * Note: all package contents must be in Little Endian form.
1448 static struct ice_buf_build *ice_pkg_buf_alloc(struct ice_hw *hw)
1450 struct ice_buf_build *bld;
1451 struct ice_buf_hdr *buf;
1453 bld = (struct ice_buf_build *)ice_malloc(hw, sizeof(*bld));
1457 buf = (struct ice_buf_hdr *)bld;
1458 buf->data_end = CPU_TO_LE16(sizeof(*buf) -
1459 sizeof(buf->section_entry[0]));
1465 * @sect_type: section type
1466 * @section: pointer to section
1467 * @index: index of the field vector entry to be returned
1468 * @offset: ptr to variable that receives the offset in the field vector table
1470 * This is a callback function that can be passed to ice_pkg_enum_entry.
1471 * This function treats the given section as of type ice_sw_fv_section and
1472 * enumerates offset field. "offset" is an index into the field vector
1476 ice_sw_fv_handler(u32 sect_type, void *section, u32 index, u32 *offset)
1478 struct ice_sw_fv_section *fv_section =
1479 (struct ice_sw_fv_section *)section;
1481 if (!section || sect_type != ICE_SID_FLD_VEC_SW)
1483 if (index >= LE16_TO_CPU(fv_section->count))
1486 /* "index" passed in to this function is relative to a given
1487 * 4k block. To get to the true index into the field vector
1488 * table need to add the relative index to the base_offset
1489 * field of this section
1491 *offset = LE16_TO_CPU(fv_section->base_offset) + index;
1492 return fv_section->fv + index;
1496 * ice_get_sw_fv_list
1497 * @hw: pointer to the HW structure
1498 * @prot_ids: field vector to search for with a given protocol ID
1499 * @ids_cnt: lookup/protocol count
1500 * @fv_list: Head of a list
1502 * Finds all the field vector entries from switch block that contain
1503 * a given protocol ID and returns a list of structures of type
1504 * "ice_sw_fv_list_entry". Every structure in the list has a field vector
1505 * definition and profile ID information
1506 * NOTE: The caller of the function is responsible for freeing the memory
1507 * allocated for every list entry.
1510 ice_get_sw_fv_list(struct ice_hw *hw, u16 *prot_ids, u8 ids_cnt,
1511 struct LIST_HEAD_TYPE *fv_list)
1513 struct ice_sw_fv_list_entry *fvl;
1514 struct ice_sw_fv_list_entry *tmp;
1515 struct ice_pkg_enum state;
1516 struct ice_seg *ice_seg;
1520 if (!ids_cnt || !hw->seg)
1521 return ICE_ERR_PARAM;
1527 fv = (struct ice_fv *)
1528 ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1529 &offset, ice_sw_fv_handler);
1531 for (i = 0; i < ids_cnt && fv; i++) {
1534 /* This code assumes that if a switch field vector line
1535 * has a matching protocol, then this line will contain
1536 * the entries necessary to represent every field in
1537 * that protocol header.
1539 for (j = 0; j < hw->blk[ICE_BLK_SW].es.fvw; j++)
1540 if (fv->ew[j].prot_id == prot_ids[i])
1542 if (j >= hw->blk[ICE_BLK_SW].es.fvw)
1544 if (i + 1 == ids_cnt) {
1545 fvl = (struct ice_sw_fv_list_entry *)
1546 ice_malloc(hw, sizeof(*fvl));
1550 fvl->profile_id = offset;
1551 LIST_ADD(&fvl->list_entry, fv_list);
1557 if (LIST_EMPTY(fv_list))
1562 LIST_FOR_EACH_ENTRY_SAFE(fvl, tmp, fv_list, ice_sw_fv_list_entry,
1564 LIST_DEL(&fvl->list_entry);
1568 return ICE_ERR_NO_MEMORY;
1573 * @hw: pointer to the HW structure
1574 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1576 * Frees a package buffer
1578 static void ice_pkg_buf_free(struct ice_hw *hw, struct ice_buf_build *bld)
1584 * ice_pkg_buf_reserve_section
1585 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1586 * @count: the number of sections to reserve
1588 * Reserves one or more section table entries in a package buffer. This routine
1589 * can be called multiple times as long as they are made before calling
1590 * ice_pkg_buf_alloc_section(). Once ice_pkg_buf_alloc_section()
1591 * is called once, the number of sections that can be allocated will not be able
1592 * to be increased; not using all reserved sections is fine, but this will
1593 * result in some wasted space in the buffer.
1594 * Note: all package contents must be in Little Endian form.
1596 static enum ice_status
1597 ice_pkg_buf_reserve_section(struct ice_buf_build *bld, u16 count)
1599 struct ice_buf_hdr *buf;
1604 return ICE_ERR_PARAM;
1606 buf = (struct ice_buf_hdr *)&bld->buf;
1608 /* already an active section, can't increase table size */
1609 section_count = LE16_TO_CPU(buf->section_count);
1610 if (section_count > 0)
1613 if (bld->reserved_section_table_entries + count > ICE_MAX_S_COUNT)
1615 bld->reserved_section_table_entries += count;
1617 data_end = LE16_TO_CPU(buf->data_end) +
1618 (count * sizeof(buf->section_entry[0]));
1619 buf->data_end = CPU_TO_LE16(data_end);
1625 * ice_pkg_buf_alloc_section
1626 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1627 * @type: the section type value
1628 * @size: the size of the section to reserve (in bytes)
1630 * Reserves memory in the buffer for a section's content and updates the
1631 * buffers' status accordingly. This routine returns a pointer to the first
1632 * byte of the section start within the buffer, which is used to fill in the
1634 * Note: all package contents must be in Little Endian form.
1637 ice_pkg_buf_alloc_section(struct ice_buf_build *bld, u32 type, u16 size)
1639 struct ice_buf_hdr *buf;
1643 if (!bld || !type || !size)
1646 buf = (struct ice_buf_hdr *)&bld->buf;
1648 /* check for enough space left in buffer */
1649 data_end = LE16_TO_CPU(buf->data_end);
1651 /* section start must align on 4 byte boundary */
1652 data_end = ICE_ALIGN(data_end, 4);
1654 if ((data_end + size) > ICE_MAX_S_DATA_END)
1657 /* check for more available section table entries */
1658 sect_count = LE16_TO_CPU(buf->section_count);
1659 if (sect_count < bld->reserved_section_table_entries) {
1660 void *section_ptr = ((u8 *)buf) + data_end;
1662 buf->section_entry[sect_count].offset = CPU_TO_LE16(data_end);
1663 buf->section_entry[sect_count].size = CPU_TO_LE16(size);
1664 buf->section_entry[sect_count].type = CPU_TO_LE32(type);
1667 buf->data_end = CPU_TO_LE16(data_end);
1669 buf->section_count = CPU_TO_LE16(sect_count + 1);
1673 /* no free section table entries */
1678 * ice_pkg_buf_get_active_sections
1679 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1681 * Returns the number of active sections. Before using the package buffer
1682 * in an update package command, the caller should make sure that there is at
1683 * least one active section - otherwise, the buffer is not legal and should
1685 * Note: all package contents must be in Little Endian form.
1687 static u16 ice_pkg_buf_get_active_sections(struct ice_buf_build *bld)
1689 struct ice_buf_hdr *buf;
1694 buf = (struct ice_buf_hdr *)&bld->buf;
1695 return LE16_TO_CPU(buf->section_count);
1699 * ice_pkg_buf_header
1700 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1702 * Return a pointer to the buffer's header
1704 static struct ice_buf *ice_pkg_buf(struct ice_buf_build *bld)
1713 * ice_tunnel_port_in_use
1714 * @hw: pointer to the HW structure
1715 * @port: port to search for
1716 * @index: optionally returns index
1718 * Returns whether a port is already in use as a tunnel, and optionally its
1721 bool ice_tunnel_port_in_use(struct ice_hw *hw, u16 port, u16 *index)
1725 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
1726 if (hw->tnl.tbl[i].in_use && hw->tnl.tbl[i].port == port) {
1736 * ice_tunnel_get_type
1737 * @hw: pointer to the HW structure
1738 * @port: port to search for
1739 * @type: returns tunnel index
1741 * For a given port number, will return the type of tunnel.
1744 ice_tunnel_get_type(struct ice_hw *hw, u16 port, enum ice_tunnel_type *type)
1748 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
1749 if (hw->tnl.tbl[i].in_use && hw->tnl.tbl[i].port == port) {
1750 *type = hw->tnl.tbl[i].type;
1758 * ice_find_free_tunnel_entry
1759 * @hw: pointer to the HW structure
1760 * @type: tunnel type
1761 * @index: optionally returns index
1763 * Returns whether there is a free tunnel entry, and optionally its index
1766 ice_find_free_tunnel_entry(struct ice_hw *hw, enum ice_tunnel_type type,
1771 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
1772 if (hw->tnl.tbl[i].valid && !hw->tnl.tbl[i].in_use &&
1773 hw->tnl.tbl[i].type == type) {
1784 * @hw: pointer to the HW structure
1785 * @type: type of tunnel
1786 * @port: port to use for vxlan tunnel
1791 ice_create_tunnel(struct ice_hw *hw, enum ice_tunnel_type type, u16 port)
1793 struct ice_boost_tcam_section *sect_rx, *sect_tx;
1794 enum ice_status status = ICE_ERR_MAX_LIMIT;
1795 struct ice_buf_build *bld;
1798 if (ice_tunnel_port_in_use(hw, port, NULL))
1799 return ICE_ERR_ALREADY_EXISTS;
1801 if (!ice_find_free_tunnel_entry(hw, type, &index))
1802 return ICE_ERR_OUT_OF_RANGE;
1804 bld = ice_pkg_buf_alloc(hw);
1806 return ICE_ERR_NO_MEMORY;
1808 /* allocate 2 sections, one for RX parser, one for TX parser */
1809 if (ice_pkg_buf_reserve_section(bld, 2))
1810 goto ice_create_tunnel_err;
1812 sect_rx = (struct ice_boost_tcam_section *)
1813 ice_pkg_buf_alloc_section(bld, ICE_SID_RXPARSER_BOOST_TCAM,
1816 goto ice_create_tunnel_err;
1817 sect_rx->count = CPU_TO_LE16(1);
1819 sect_tx = (struct ice_boost_tcam_section *)
1820 ice_pkg_buf_alloc_section(bld, ICE_SID_TXPARSER_BOOST_TCAM,
1823 goto ice_create_tunnel_err;
1824 sect_tx->count = CPU_TO_LE16(1);
1826 /* copy original boost entry to update package buffer */
1827 ice_memcpy(sect_rx->tcam, hw->tnl.tbl[index].boost_entry,
1828 sizeof(*sect_rx->tcam), ICE_NONDMA_TO_NONDMA);
1830 /* over-write the never-match dest port key bits with the encoded port
1833 ice_set_key((u8 *)§_rx->tcam[0].key, sizeof(sect_rx->tcam[0].key),
1834 (u8 *)&port, NULL, NULL, NULL,
1835 offsetof(struct ice_boost_key_value, hv_dst_port_key),
1836 sizeof(sect_rx->tcam[0].key.key.hv_dst_port_key));
1838 /* exact copy of entry to TX section entry */
1839 ice_memcpy(sect_tx->tcam, sect_rx->tcam, sizeof(*sect_tx->tcam),
1840 ICE_NONDMA_TO_NONDMA);
1842 status = ice_update_pkg(hw, ice_pkg_buf(bld), 1);
1844 hw->tnl.tbl[index].port = port;
1845 hw->tnl.tbl[index].in_use = true;
1848 ice_create_tunnel_err:
1849 ice_pkg_buf_free(hw, bld);
1855 * ice_destroy_tunnel
1856 * @hw: pointer to the HW structure
1857 * @port: port of tunnel to destroy (ignored if the all parameter is true)
1858 * @all: flag that states to destroy all tunnels
1860 * Destroys a tunnel or all tunnels by creating an update package buffer
1861 * targeting the specific updates requested and then performing an update
1864 enum ice_status ice_destroy_tunnel(struct ice_hw *hw, u16 port, bool all)
1866 struct ice_boost_tcam_section *sect_rx, *sect_tx;
1867 enum ice_status status = ICE_ERR_MAX_LIMIT;
1868 struct ice_buf_build *bld;
1873 /* determine count */
1874 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
1875 if (hw->tnl.tbl[i].valid && hw->tnl.tbl[i].in_use &&
1876 (all || hw->tnl.tbl[i].port == port))
1880 return ICE_ERR_PARAM;
1882 /* size of section - there is at least one entry */
1883 size = (count - 1) * sizeof(*sect_rx->tcam) + sizeof(*sect_rx);
1885 bld = ice_pkg_buf_alloc(hw);
1887 return ICE_ERR_NO_MEMORY;
1889 /* allocate 2 sections, one for RX parser, one for TX parser */
1890 if (ice_pkg_buf_reserve_section(bld, 2))
1891 goto ice_destroy_tunnel_err;
1893 sect_rx = (struct ice_boost_tcam_section *)
1894 ice_pkg_buf_alloc_section(bld, ICE_SID_RXPARSER_BOOST_TCAM,
1897 goto ice_destroy_tunnel_err;
1898 sect_rx->count = CPU_TO_LE16(1);
1900 sect_tx = (struct ice_boost_tcam_section *)
1901 ice_pkg_buf_alloc_section(bld, ICE_SID_TXPARSER_BOOST_TCAM,
1904 goto ice_destroy_tunnel_err;
1905 sect_tx->count = CPU_TO_LE16(1);
1907 /* copy original boost entry to update package buffer, one copy to RX
1908 * section, another copy to the TX section
1910 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
1911 if (hw->tnl.tbl[i].valid && hw->tnl.tbl[i].in_use &&
1912 (all || hw->tnl.tbl[i].port == port)) {
1913 ice_memcpy(sect_rx->tcam + i,
1914 hw->tnl.tbl[i].boost_entry,
1915 sizeof(*sect_rx->tcam),
1916 ICE_NONDMA_TO_NONDMA);
1917 ice_memcpy(sect_tx->tcam + i,
1918 hw->tnl.tbl[i].boost_entry,
1919 sizeof(*sect_tx->tcam),
1920 ICE_NONDMA_TO_NONDMA);
1921 hw->tnl.tbl[i].marked = true;
1924 status = ice_update_pkg(hw, ice_pkg_buf(bld), 1);
1926 for (i = 0; i < hw->tnl.count &&
1927 i < ICE_TUNNEL_MAX_ENTRIES; i++)
1928 if (hw->tnl.tbl[i].marked) {
1929 hw->tnl.tbl[i].port = 0;
1930 hw->tnl.tbl[i].in_use = false;
1931 hw->tnl.tbl[i].marked = false;
1934 ice_destroy_tunnel_err:
1935 ice_pkg_buf_free(hw, bld);
1941 * ice_find_prot_off - find prot ID and offset pair, based on prof and FV index
1942 * @hw: pointer to the hardware structure
1943 * @blk: hardware block
1945 * @fv_idx: field vector word index
1946 * @prot: variable to receive the protocol ID
1947 * @off: variable to receive the protocol offset
1950 ice_find_prot_off(struct ice_hw *hw, enum ice_block blk, u8 prof, u8 fv_idx,
1953 struct ice_fv_word *fv_ext;
1955 if (prof >= hw->blk[blk].es.count)
1956 return ICE_ERR_PARAM;
1958 if (fv_idx >= hw->blk[blk].es.fvw)
1959 return ICE_ERR_PARAM;
1961 fv_ext = hw->blk[blk].es.t + (prof * hw->blk[blk].es.fvw);
1963 *prot = fv_ext[fv_idx].prot_id;
1964 *off = fv_ext[fv_idx].off;
1969 /* PTG Management */
1973 * ice_ptg_find_ptype - Search for packet type group using packet type (ptype)
1974 * @hw: pointer to the hardware structure
1976 * @ptype: the ptype to search for
1977 * @ptg: pointer to variable that receives the PTG
1979 * This function will search the PTGs for a particular ptype, returning the
1980 * PTG ID that contains it through the ptg parameter, with the value of
1981 * ICE_DEFAULT_PTG (0) meaning it is part the default PTG.
1983 static enum ice_status
1984 ice_ptg_find_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 *ptg)
1986 if (ptype >= ICE_XLT1_CNT || !ptg)
1987 return ICE_ERR_PARAM;
1989 *ptg = hw->blk[blk].xlt1.ptypes[ptype].ptg;
1994 * ice_ptg_alloc_val - Allocates a new packet type group ID by value
1995 * @hw: pointer to the hardware structure
1997 * @ptg: the ptg to allocate
1999 * This function allocates a given packet type group ID specified by the ptg
2003 void ice_ptg_alloc_val(struct ice_hw *hw, enum ice_block blk, u8 ptg)
2005 hw->blk[blk].xlt1.ptg_tbl[ptg].in_use = true;
2009 * ice_ptg_alloc - Find a free entry and allocates a new packet type group ID
2010 * @hw: pointer to the hardware structure
2013 * This function allocates and returns a new packet type group ID. Note
2014 * that 0 is the default packet type group, so successfully created PTGs will
2015 * have a non-zero ID value; which means a 0 return value indicates an error.
2017 static u8 ice_ptg_alloc(struct ice_hw *hw, enum ice_block blk)
2021 /* Skip the default PTG of 0 */
2022 for (i = 1; i < ICE_MAX_PTGS; i++)
2023 if (!hw->blk[blk].xlt1.ptg_tbl[i].in_use) {
2024 /* found a free PTG ID */
2025 ice_ptg_alloc_val(hw, blk, i);
2033 * ice_ptg_remove_ptype - Removes ptype from a particular packet type group
2034 * @hw: pointer to the hardware structure
2036 * @ptype: the ptype to remove
2037 * @ptg: the ptg to remove the ptype from
2039 * This function will remove the ptype from the specific ptg, and move it to
2040 * the default PTG (ICE_DEFAULT_PTG).
2042 static enum ice_status
2043 ice_ptg_remove_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 ptg)
2045 struct ice_ptg_ptype **ch;
2046 struct ice_ptg_ptype *p;
2048 if (ptype > ICE_XLT1_CNT - 1)
2049 return ICE_ERR_PARAM;
2051 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].in_use)
2052 return ICE_ERR_DOES_NOT_EXIST;
2054 /* Should not happen if .in_use is set, bad config */
2055 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype)
2058 /* find the ptype within this PTG, and bypass the link over it */
2059 p = hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2060 ch = &hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2062 if (ptype == (p - hw->blk[blk].xlt1.ptypes)) {
2063 *ch = p->next_ptype;
2067 ch = &p->next_ptype;
2071 hw->blk[blk].xlt1.ptypes[ptype].ptg = ICE_DEFAULT_PTG;
2072 hw->blk[blk].xlt1.ptypes[ptype].next_ptype = NULL;
2078 * ice_ptg_add_mv_ptype - Adds/moves ptype to a particular packet type group
2079 * @hw: pointer to the hardware structure
2081 * @ptype: the ptype to add or move
2082 * @ptg: the ptg to add or move the ptype to
2084 * This function will either add or move a ptype to a particular PTG depending
2085 * on if the ptype is already part of another group. Note that using a
2086 * a destination PTG ID of ICE_DEFAULT_PTG (0) will move the ptype to the
2089 static enum ice_status
2090 ice_ptg_add_mv_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 ptg)
2092 enum ice_status status;
2095 if (ptype > ICE_XLT1_CNT - 1)
2096 return ICE_ERR_PARAM;
2098 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].in_use && ptg != ICE_DEFAULT_PTG)
2099 return ICE_ERR_DOES_NOT_EXIST;
2101 status = ice_ptg_find_ptype(hw, blk, ptype, &original_ptg);
2105 /* Is ptype already in the correct PTG? */
2106 if (original_ptg == ptg)
2109 /* Remove from original PTG and move back to the default PTG */
2110 if (original_ptg != ICE_DEFAULT_PTG)
2111 ice_ptg_remove_ptype(hw, blk, ptype, original_ptg);
2113 /* Moving to default PTG? Then we're done with this request */
2114 if (ptg == ICE_DEFAULT_PTG)
2117 /* Add ptype to PTG at beginning of list */
2118 hw->blk[blk].xlt1.ptypes[ptype].next_ptype =
2119 hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2120 hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype =
2121 &hw->blk[blk].xlt1.ptypes[ptype];
2123 hw->blk[blk].xlt1.ptypes[ptype].ptg = ptg;
2124 hw->blk[blk].xlt1.t[ptype] = ptg;
2129 /* Block / table size info */
2130 struct ice_blk_size_details {
2131 u16 xlt1; /* # XLT1 entries */
2132 u16 xlt2; /* # XLT2 entries */
2133 u16 prof_tcam; /* # profile ID TCAM entries */
2134 u16 prof_id; /* # profile IDs */
2135 u8 prof_cdid_bits; /* # cdid one-hot bits used in key */
2136 u16 prof_redir; /* # profile redirection entries */
2137 u16 es; /* # extraction sequence entries */
2138 u16 fvw; /* # field vector words */
2139 u8 overwrite; /* overwrite existing entries allowed */
2140 u8 reverse; /* reverse FV order */
2143 static const struct ice_blk_size_details blk_sizes[ICE_BLK_COUNT] = {
2146 * XLT1 - Number of entries in XLT1 table
2147 * XLT2 - Number of entries in XLT2 table
2148 * TCAM - Number of entries Profile ID TCAM table
2149 * CDID - Control Domain ID of the hardware block
2150 * PRED - Number of entries in the Profile Redirection Table
2151 * FV - Number of entries in the Field Vector
2152 * FVW - Width (in WORDs) of the Field Vector
2153 * OVR - Overwrite existing table entries
2156 /* XLT1 , XLT2 ,TCAM, PID,CDID,PRED, FV, FVW */
2157 /* Overwrite , Reverse FV */
2158 /* SW */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 256, 0, 256, 256, 48,
2160 /* ACL */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 32,
2162 /* FD */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 24,
2164 /* RSS */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 24,
2166 /* PE */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 64, 32, 0, 32, 32, 24,
2171 ICE_SID_XLT1_OFF = 0,
2174 ICE_SID_PR_REDIR_OFF,
2179 /* Characteristic handling */
2182 * ice_match_prop_lst - determine if properties of two lists match
2183 * @list1: first properties list
2184 * @list2: second properties list
2186 * Count, cookies and the order must match in order to be considered equivalent.
2189 ice_match_prop_lst(struct LIST_HEAD_TYPE *list1, struct LIST_HEAD_TYPE *list2)
2191 struct ice_vsig_prof *tmp1;
2192 struct ice_vsig_prof *tmp2;
2196 /* compare counts */
2197 LIST_FOR_EACH_ENTRY(tmp1, list1, ice_vsig_prof, list) {
2200 LIST_FOR_EACH_ENTRY(tmp2, list2, ice_vsig_prof, list) {
2203 if (!count || count != chk_count)
2206 tmp1 = LIST_FIRST_ENTRY(list1, struct ice_vsig_prof, list);
2207 tmp2 = LIST_FIRST_ENTRY(list2, struct ice_vsig_prof, list);
2209 /* profile cookies must compare, and in the exact same order to take
2210 * into account priority
2213 if (tmp2->profile_cookie != tmp1->profile_cookie)
2216 tmp1 = LIST_NEXT_ENTRY(tmp1, struct ice_vsig_prof, list);
2217 tmp2 = LIST_NEXT_ENTRY(tmp2, struct ice_vsig_prof, list);
2223 /* VSIG Management */
2227 * ice_vsig_find_vsi - find a VSIG that contains a specified VSI
2228 * @hw: pointer to the hardware structure
2230 * @vsi: VSI of interest
2231 * @vsig: pointer to receive the VSI group
2233 * This function will lookup the VSI entry in the XLT2 list and return
2234 * the VSI group its associated with.
2237 ice_vsig_find_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 *vsig)
2239 if (!vsig || vsi >= ICE_MAX_VSI)
2240 return ICE_ERR_PARAM;
2242 /* As long as there's a default or valid VSIG associated with the input
2243 * VSI, the functions returns a success. Any handling of VSIG will be
2244 * done by the following add, update or remove functions.
2246 *vsig = hw->blk[blk].xlt2.vsis[vsi].vsig;
2252 * ice_vsig_alloc_val - allocate a new VSIG by value
2253 * @hw: pointer to the hardware structure
2255 * @vsig: the vsig to allocate
2257 * This function will allocate a given VSIG specified by the vsig parameter.
2259 static u16 ice_vsig_alloc_val(struct ice_hw *hw, enum ice_block blk, u16 vsig)
2261 u16 idx = vsig & ICE_VSIG_IDX_M;
2263 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use) {
2264 INIT_LIST_HEAD(&hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst);
2265 hw->blk[blk].xlt2.vsig_tbl[idx].in_use = true;
2268 return ICE_VSIG_VALUE(idx, hw->pf_id);
2272 * ice_vsig_alloc - Finds a free entry and allocates a new VSIG
2273 * @hw: pointer to the hardware structure
2276 * This function will iterate through the VSIG list and mark the first
2277 * unused entry for the new VSIG entry as used and return that value.
2279 static u16 ice_vsig_alloc(struct ice_hw *hw, enum ice_block blk)
2283 for (i = 1; i < ICE_MAX_VSIGS; i++)
2284 if (!hw->blk[blk].xlt2.vsig_tbl[i].in_use)
2285 return ice_vsig_alloc_val(hw, blk, i);
2287 return ICE_DEFAULT_VSIG;
2291 * ice_find_dup_props_vsig - find VSI group with a specified set of properties
2292 * @hw: pointer to the hardware structure
2294 * @chs: characteristic list
2295 * @vsig: returns the VSIG with the matching profiles, if found
2297 * Each VSIG is associated with a characteristic set; i.e. all VSIs under
2298 * a group have the same characteristic set. To check if there exists a VSIG
2299 * which has the same characteristics as the input characteristics; this
2300 * function will iterate through the XLT2 list and return the VSIG that has a
2301 * matching configuration. In order to make sure that priorities are accounted
2302 * for, the list must match exactly, including the order in which the
2303 * characteristics are listed.
2305 static enum ice_status
2306 ice_find_dup_props_vsig(struct ice_hw *hw, enum ice_block blk,
2307 struct LIST_HEAD_TYPE *chs, u16 *vsig)
2309 struct ice_xlt2 *xlt2 = &hw->blk[blk].xlt2;
2312 for (i = 0; i < xlt2->count; i++) {
2313 if (xlt2->vsig_tbl[i].in_use &&
2314 ice_match_prop_lst(chs, &xlt2->vsig_tbl[i].prop_lst)) {
2315 *vsig = ICE_VSIG_VALUE(i, hw->pf_id);
2320 return ICE_ERR_DOES_NOT_EXIST;
2324 * ice_vsig_free - free VSI group
2325 * @hw: pointer to the hardware structure
2327 * @vsig: VSIG to remove
2329 * The function will remove all VSIs associated with the input VSIG and move
2330 * them to the DEFAULT_VSIG and mark the VSIG available.
2332 static enum ice_status
2333 ice_vsig_free(struct ice_hw *hw, enum ice_block blk, u16 vsig)
2335 struct ice_vsig_prof *dtmp, *del;
2336 struct ice_vsig_vsi *vsi_cur;
2339 idx = vsig & ICE_VSIG_IDX_M;
2340 if (idx >= ICE_MAX_VSIGS)
2341 return ICE_ERR_PARAM;
2343 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
2344 return ICE_ERR_DOES_NOT_EXIST;
2346 hw->blk[blk].xlt2.vsig_tbl[idx].in_use = false;
2348 vsi_cur = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2349 /* If the VSIG has at least 1 VSI then iterate through the
2350 * list and remove the VSIs before deleting the group.
2353 /* remove all vsis associated with this VSIG XLT2 entry */
2355 struct ice_vsig_vsi *tmp = vsi_cur->next_vsi;
2357 vsi_cur->vsig = ICE_DEFAULT_VSIG;
2358 vsi_cur->changed = 1;
2359 vsi_cur->next_vsi = NULL;
2363 /* NULL terminate head of VSI list */
2364 hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi = NULL;
2367 /* free characteristic list */
2368 LIST_FOR_EACH_ENTRY_SAFE(del, dtmp,
2369 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
2370 ice_vsig_prof, list) {
2371 LIST_DEL(&del->list);
2375 /* if VSIG characteristic list was cleared for reset
2376 * re-initialize the list head
2378 INIT_LIST_HEAD(&hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst);
2384 * ice_vsig_remove_vsi - remove VSI from VSIG
2385 * @hw: pointer to the hardware structure
2387 * @vsi: VSI to remove
2388 * @vsig: VSI group to remove from
2390 * The function will remove the input VSI from its VSI group and move it
2391 * to the DEFAULT_VSIG.
2393 static enum ice_status
2394 ice_vsig_remove_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
2396 struct ice_vsig_vsi **vsi_head, *vsi_cur, *vsi_tgt;
2399 idx = vsig & ICE_VSIG_IDX_M;
2401 if (vsi >= ICE_MAX_VSI || idx >= ICE_MAX_VSIGS)
2402 return ICE_ERR_PARAM;
2404 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
2405 return ICE_ERR_DOES_NOT_EXIST;
2407 /* entry already in default VSIG, don't have to remove */
2408 if (idx == ICE_DEFAULT_VSIG)
2411 vsi_head = &hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2415 vsi_tgt = &hw->blk[blk].xlt2.vsis[vsi];
2416 vsi_cur = (*vsi_head);
2418 /* iterate the VSI list, skip over the entry to be removed */
2420 if (vsi_tgt == vsi_cur) {
2421 (*vsi_head) = vsi_cur->next_vsi;
2424 vsi_head = &vsi_cur->next_vsi;
2425 vsi_cur = vsi_cur->next_vsi;
2428 /* verify if VSI was removed from group list */
2430 return ICE_ERR_DOES_NOT_EXIST;
2432 vsi_cur->vsig = ICE_DEFAULT_VSIG;
2433 vsi_cur->changed = 1;
2434 vsi_cur->next_vsi = NULL;
2440 * ice_vsig_add_mv_vsi - add or move a VSI to a VSI group
2441 * @hw: pointer to the hardware structure
2444 * @vsig: destination VSI group
2446 * This function will move or add the input VSI to the target VSIG.
2447 * The function will find the original VSIG the VSI belongs to and
2448 * move the entry to the DEFAULT_VSIG, update the original VSIG and
2449 * then move entry to the new VSIG.
2451 static enum ice_status
2452 ice_vsig_add_mv_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
2454 struct ice_vsig_vsi *tmp;
2455 enum ice_status status;
2458 idx = vsig & ICE_VSIG_IDX_M;
2460 if (vsi >= ICE_MAX_VSI || idx >= ICE_MAX_VSIGS)
2461 return ICE_ERR_PARAM;
2463 /* if VSIG not in use and VSIG is not default type this VSIG
2466 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use &&
2467 vsig != ICE_DEFAULT_VSIG)
2468 return ICE_ERR_DOES_NOT_EXIST;
2470 status = ice_vsig_find_vsi(hw, blk, vsi, &orig_vsig);
2474 /* no update required if vsigs match */
2475 if (orig_vsig == vsig)
2478 if (orig_vsig != ICE_DEFAULT_VSIG) {
2479 /* remove entry from orig_vsig and add to default VSIG */
2480 status = ice_vsig_remove_vsi(hw, blk, vsi, orig_vsig);
2485 if (idx == ICE_DEFAULT_VSIG)
2488 /* Create VSI entry and add VSIG and prop_mask values */
2489 hw->blk[blk].xlt2.vsis[vsi].vsig = vsig;
2490 hw->blk[blk].xlt2.vsis[vsi].changed = 1;
2492 /* Add new entry to the head of the VSIG list */
2493 tmp = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2494 hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi =
2495 &hw->blk[blk].xlt2.vsis[vsi];
2496 hw->blk[blk].xlt2.vsis[vsi].next_vsi = tmp;
2497 hw->blk[blk].xlt2.t[vsi] = vsig;
2503 * ice_find_prof_id - find profile ID for a given field vector
2504 * @hw: pointer to the hardware structure
2506 * @fv: field vector to search for
2507 * @prof_id: receives the profile ID
2509 static enum ice_status
2510 ice_find_prof_id(struct ice_hw *hw, enum ice_block blk,
2511 struct ice_fv_word *fv, u8 *prof_id)
2513 struct ice_es *es = &hw->blk[blk].es;
2516 for (i = 0; i < es->count; i++) {
2519 if (memcmp(&es->t[off], fv, es->fvw * sizeof(*fv)))
2526 return ICE_ERR_DOES_NOT_EXIST;
2530 * ice_prof_id_rsrc_type - get profile ID resource type for a block type
2531 * @blk: the block type
2532 * @rsrc_type: pointer to variable to receive the resource type
2534 static bool ice_prof_id_rsrc_type(enum ice_block blk, u16 *rsrc_type)
2538 *rsrc_type = ICE_AQC_RES_TYPE_SWITCH_PROF_BLDR_PROFID;
2541 *rsrc_type = ICE_AQC_RES_TYPE_ACL_PROF_BLDR_PROFID;
2544 *rsrc_type = ICE_AQC_RES_TYPE_FD_PROF_BLDR_PROFID;
2547 *rsrc_type = ICE_AQC_RES_TYPE_HASH_PROF_BLDR_PROFID;
2550 *rsrc_type = ICE_AQC_RES_TYPE_QHASH_PROF_BLDR_PROFID;
2559 * ice_tcam_ent_rsrc_type - get TCAM entry resource type for a block type
2560 * @blk: the block type
2561 * @rsrc_type: pointer to variable to receive the resource type
2563 static bool ice_tcam_ent_rsrc_type(enum ice_block blk, u16 *rsrc_type)
2567 *rsrc_type = ICE_AQC_RES_TYPE_SWITCH_PROF_BLDR_TCAM;
2570 *rsrc_type = ICE_AQC_RES_TYPE_ACL_PROF_BLDR_TCAM;
2573 *rsrc_type = ICE_AQC_RES_TYPE_FD_PROF_BLDR_TCAM;
2576 *rsrc_type = ICE_AQC_RES_TYPE_HASH_PROF_BLDR_TCAM;
2579 *rsrc_type = ICE_AQC_RES_TYPE_QHASH_PROF_BLDR_TCAM;
2588 * ice_alloc_tcam_ent - allocate hardware TCAM entry
2589 * @hw: pointer to the HW struct
2590 * @blk: the block to allocate the TCAM for
2591 * @tcam_idx: pointer to variable to receive the TCAM entry
2593 * This function allocates a new entry in a Profile ID TCAM for a specific
2596 static enum ice_status
2597 ice_alloc_tcam_ent(struct ice_hw *hw, enum ice_block blk, u16 *tcam_idx)
2601 if (!ice_tcam_ent_rsrc_type(blk, &res_type))
2602 return ICE_ERR_PARAM;
2604 return ice_alloc_hw_res(hw, res_type, 1, true, tcam_idx);
2608 * ice_free_tcam_ent - free hardware TCAM entry
2609 * @hw: pointer to the HW struct
2610 * @blk: the block from which to free the TCAM entry
2611 * @tcam_idx: the TCAM entry to free
2613 * This function frees an entry in a Profile ID TCAM for a specific block.
2615 static enum ice_status
2616 ice_free_tcam_ent(struct ice_hw *hw, enum ice_block blk, u16 tcam_idx)
2620 if (!ice_tcam_ent_rsrc_type(blk, &res_type))
2621 return ICE_ERR_PARAM;
2623 return ice_free_hw_res(hw, res_type, 1, &tcam_idx);
2627 * ice_alloc_prof_id - allocate profile ID
2628 * @hw: pointer to the HW struct
2629 * @blk: the block to allocate the profile ID for
2630 * @prof_id: pointer to variable to receive the profile ID
2632 * This function allocates a new profile ID, which also corresponds to a Field
2633 * Vector (Extraction Sequence) entry.
2635 static enum ice_status
2636 ice_alloc_prof_id(struct ice_hw *hw, enum ice_block blk, u8 *prof_id)
2638 enum ice_status status;
2642 if (!ice_prof_id_rsrc_type(blk, &res_type))
2643 return ICE_ERR_PARAM;
2645 status = ice_alloc_hw_res(hw, res_type, 1, false, &get_prof);
2647 *prof_id = (u8)get_prof;
2653 * ice_free_prof_id - free profile ID
2654 * @hw: pointer to the HW struct
2655 * @blk: the block from which to free the profile ID
2656 * @prof_id: the profile ID to free
2658 * This function frees a profile ID, which also corresponds to a Field Vector.
2660 static enum ice_status
2661 ice_free_prof_id(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
2663 u16 tmp_prof_id = (u16)prof_id;
2666 if (!ice_prof_id_rsrc_type(blk, &res_type))
2667 return ICE_ERR_PARAM;
2669 return ice_free_hw_res(hw, res_type, 1, &tmp_prof_id);
2673 * ice_prof_inc_ref - increment reference count for profile
2674 * @hw: pointer to the HW struct
2675 * @blk: the block from which to free the profile ID
2676 * @prof_id: the profile ID for which to increment the reference count
2678 static enum ice_status
2679 ice_prof_inc_ref(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
2681 if (prof_id > hw->blk[blk].es.count)
2682 return ICE_ERR_PARAM;
2684 hw->blk[blk].es.ref_count[prof_id]++;
2690 * ice_write_es - write an extraction sequence to hardware
2691 * @hw: pointer to the HW struct
2692 * @blk: the block in which to write the extraction sequence
2693 * @prof_id: the profile ID to write
2694 * @fv: pointer to the extraction sequence to write - NULL to clear extraction
2697 ice_write_es(struct ice_hw *hw, enum ice_block blk, u8 prof_id,
2698 struct ice_fv_word *fv)
2702 off = prof_id * hw->blk[blk].es.fvw;
2704 ice_memset(&hw->blk[blk].es.t[off], 0, hw->blk[blk].es.fvw *
2705 sizeof(*fv), ICE_NONDMA_MEM);
2706 hw->blk[blk].es.written[prof_id] = false;
2708 ice_memcpy(&hw->blk[blk].es.t[off], fv, hw->blk[blk].es.fvw *
2709 sizeof(*fv), ICE_NONDMA_TO_NONDMA);
2714 * ice_prof_dec_ref - decrement reference count for profile
2715 * @hw: pointer to the HW struct
2716 * @blk: the block from which to free the profile ID
2717 * @prof_id: the profile ID for which to decrement the reference count
2719 static enum ice_status
2720 ice_prof_dec_ref(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
2722 if (prof_id > hw->blk[blk].es.count)
2723 return ICE_ERR_PARAM;
2725 if (hw->blk[blk].es.ref_count[prof_id] > 0) {
2726 if (!--hw->blk[blk].es.ref_count[prof_id]) {
2727 ice_write_es(hw, blk, prof_id, NULL);
2728 return ice_free_prof_id(hw, blk, prof_id);
2735 /* Block / table section IDs */
2736 static const u32 ice_blk_sids[ICE_BLK_COUNT][ICE_SID_OFF_COUNT] = {
2740 ICE_SID_PROFID_TCAM_SW,
2741 ICE_SID_PROFID_REDIR_SW,
2748 ICE_SID_PROFID_TCAM_ACL,
2749 ICE_SID_PROFID_REDIR_ACL,
2756 ICE_SID_PROFID_TCAM_FD,
2757 ICE_SID_PROFID_REDIR_FD,
2764 ICE_SID_PROFID_TCAM_RSS,
2765 ICE_SID_PROFID_REDIR_RSS,
2772 ICE_SID_PROFID_TCAM_PE,
2773 ICE_SID_PROFID_REDIR_PE,
2779 * ice_init_sw_xlt1_db - init software XLT1 database from HW tables
2780 * @hw: pointer to the hardware structure
2781 * @blk: the HW block to initialize
2784 void ice_init_sw_xlt1_db(struct ice_hw *hw, enum ice_block blk)
2788 for (pt = 0; pt < hw->blk[blk].xlt1.count; pt++) {
2791 ptg = hw->blk[blk].xlt1.t[pt];
2792 if (ptg != ICE_DEFAULT_PTG) {
2793 ice_ptg_alloc_val(hw, blk, ptg);
2794 ice_ptg_add_mv_ptype(hw, blk, pt, ptg);
2800 * ice_init_sw_xlt2_db - init software XLT2 database from HW tables
2801 * @hw: pointer to the hardware structure
2802 * @blk: the HW block to initialize
2804 static void ice_init_sw_xlt2_db(struct ice_hw *hw, enum ice_block blk)
2808 for (vsi = 0; vsi < hw->blk[blk].xlt2.count; vsi++) {
2811 vsig = hw->blk[blk].xlt2.t[vsi];
2813 ice_vsig_alloc_val(hw, blk, vsig);
2814 ice_vsig_add_mv_vsi(hw, blk, vsi, vsig);
2815 /* no changes at this time, since this has been
2816 * initialized from the original package
2818 hw->blk[blk].xlt2.vsis[vsi].changed = 0;
2824 * ice_init_sw_db - init software database from HW tables
2825 * @hw: pointer to the hardware structure
2827 static void ice_init_sw_db(struct ice_hw *hw)
2831 for (i = 0; i < ICE_BLK_COUNT; i++) {
2832 ice_init_sw_xlt1_db(hw, (enum ice_block)i);
2833 ice_init_sw_xlt2_db(hw, (enum ice_block)i);
2838 * ice_fill_tbl - Reads content of a single table type into database
2839 * @hw: pointer to the hardware structure
2840 * @block_id: Block ID of the table to copy
2841 * @sid: Section ID of the table to copy
2843 * Will attempt to read the entire content of a given table of a single block
2844 * into the driver database. We assume that the buffer will always
2845 * be as large or larger than the data contained in the package. If
2846 * this condition is not met, there is most likely an error in the package
2849 static void ice_fill_tbl(struct ice_hw *hw, enum ice_block block_id, u32 sid)
2851 u32 dst_len, sect_len, offset = 0;
2852 struct ice_prof_redir_section *pr;
2853 struct ice_prof_id_section *pid;
2854 struct ice_xlt1_section *xlt1;
2855 struct ice_xlt2_section *xlt2;
2856 struct ice_sw_fv_section *es;
2857 struct ice_pkg_enum state;
2861 /* if the HW segment pointer is null then the first iteration of
2862 * ice_pkg_enum_section() will fail. In this case the Hw tables will
2863 * not be filled and return success.
2866 ice_debug(hw, ICE_DBG_PKG, "hw->seg is NULL, tables are not filled\n");
2870 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
2872 sect = ice_pkg_enum_section(hw->seg, &state, sid);
2876 case ICE_SID_XLT1_SW:
2877 case ICE_SID_XLT1_FD:
2878 case ICE_SID_XLT1_RSS:
2879 case ICE_SID_XLT1_ACL:
2880 case ICE_SID_XLT1_PE:
2881 xlt1 = (struct ice_xlt1_section *)sect;
2883 sect_len = LE16_TO_CPU(xlt1->count) *
2884 sizeof(*hw->blk[block_id].xlt1.t);
2885 dst = hw->blk[block_id].xlt1.t;
2886 dst_len = hw->blk[block_id].xlt1.count *
2887 sizeof(*hw->blk[block_id].xlt1.t);
2889 case ICE_SID_XLT2_SW:
2890 case ICE_SID_XLT2_FD:
2891 case ICE_SID_XLT2_RSS:
2892 case ICE_SID_XLT2_ACL:
2893 case ICE_SID_XLT2_PE:
2894 xlt2 = (struct ice_xlt2_section *)sect;
2895 src = (_FORCE_ u8 *)xlt2->value;
2896 sect_len = LE16_TO_CPU(xlt2->count) *
2897 sizeof(*hw->blk[block_id].xlt2.t);
2898 dst = (u8 *)hw->blk[block_id].xlt2.t;
2899 dst_len = hw->blk[block_id].xlt2.count *
2900 sizeof(*hw->blk[block_id].xlt2.t);
2902 case ICE_SID_PROFID_TCAM_SW:
2903 case ICE_SID_PROFID_TCAM_FD:
2904 case ICE_SID_PROFID_TCAM_RSS:
2905 case ICE_SID_PROFID_TCAM_ACL:
2906 case ICE_SID_PROFID_TCAM_PE:
2907 pid = (struct ice_prof_id_section *)sect;
2908 src = (u8 *)pid->entry;
2909 sect_len = LE16_TO_CPU(pid->count) *
2910 sizeof(*hw->blk[block_id].prof.t);
2911 dst = (u8 *)hw->blk[block_id].prof.t;
2912 dst_len = hw->blk[block_id].prof.count *
2913 sizeof(*hw->blk[block_id].prof.t);
2915 case ICE_SID_PROFID_REDIR_SW:
2916 case ICE_SID_PROFID_REDIR_FD:
2917 case ICE_SID_PROFID_REDIR_RSS:
2918 case ICE_SID_PROFID_REDIR_ACL:
2919 case ICE_SID_PROFID_REDIR_PE:
2920 pr = (struct ice_prof_redir_section *)sect;
2921 src = pr->redir_value;
2922 sect_len = LE16_TO_CPU(pr->count) *
2923 sizeof(*hw->blk[block_id].prof_redir.t);
2924 dst = hw->blk[block_id].prof_redir.t;
2925 dst_len = hw->blk[block_id].prof_redir.count *
2926 sizeof(*hw->blk[block_id].prof_redir.t);
2928 case ICE_SID_FLD_VEC_SW:
2929 case ICE_SID_FLD_VEC_FD:
2930 case ICE_SID_FLD_VEC_RSS:
2931 case ICE_SID_FLD_VEC_ACL:
2932 case ICE_SID_FLD_VEC_PE:
2933 es = (struct ice_sw_fv_section *)sect;
2935 sect_len = (u32)(LE16_TO_CPU(es->count) *
2936 hw->blk[block_id].es.fvw) *
2937 sizeof(*hw->blk[block_id].es.t);
2938 dst = (u8 *)hw->blk[block_id].es.t;
2939 dst_len = (u32)(hw->blk[block_id].es.count *
2940 hw->blk[block_id].es.fvw) *
2941 sizeof(*hw->blk[block_id].es.t);
2947 /* if the section offset exceeds destination length, terminate
2950 if (offset > dst_len)
2953 /* if the sum of section size and offset exceed destination size
2954 * then we are out of bounds of the Hw table size for that PF.
2955 * Changing section length to fill the remaining table space
2958 if ((offset + sect_len) > dst_len)
2959 sect_len = dst_len - offset;
2961 ice_memcpy(dst + offset, src, sect_len, ICE_NONDMA_TO_NONDMA);
2963 sect = ice_pkg_enum_section(NULL, &state, sid);
2968 * ice_fill_blk_tbls - Read package context for tables
2969 * @hw: pointer to the hardware structure
2971 * Reads the current package contents and populates the driver
2972 * database with the data iteratively for all advanced feature
2973 * blocks. Assume that the Hw tables have been allocated.
2975 void ice_fill_blk_tbls(struct ice_hw *hw)
2979 for (i = 0; i < ICE_BLK_COUNT; i++) {
2980 enum ice_block blk_id = (enum ice_block)i;
2982 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].xlt1.sid);
2983 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].xlt2.sid);
2984 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].prof.sid);
2985 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].prof_redir.sid);
2986 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].es.sid);
2993 * ice_free_prof_map - free profile map
2994 * @hw: pointer to the hardware structure
2995 * @blk_idx: HW block index
2997 static void ice_free_prof_map(struct ice_hw *hw, u8 blk_idx)
2999 struct ice_es *es = &hw->blk[blk_idx].es;
3000 struct ice_prof_map *del, *tmp;
3002 ice_acquire_lock(&es->prof_map_lock);
3003 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &es->prof_map,
3004 ice_prof_map, list) {
3005 LIST_DEL(&del->list);
3008 INIT_LIST_HEAD(&es->prof_map);
3009 ice_release_lock(&es->prof_map_lock);
3013 * ice_free_flow_profs - free flow profile entries
3014 * @hw: pointer to the hardware structure
3015 * @blk_idx: HW block index
3017 static void ice_free_flow_profs(struct ice_hw *hw, u8 blk_idx)
3019 struct ice_flow_prof *p, *tmp;
3021 ice_acquire_lock(&hw->fl_profs_locks[blk_idx]);
3022 LIST_FOR_EACH_ENTRY_SAFE(p, tmp, &hw->fl_profs[blk_idx],
3023 ice_flow_prof, l_entry) {
3024 struct ice_flow_entry *e, *t;
3026 LIST_FOR_EACH_ENTRY_SAFE(e, t, &p->entries,
3027 ice_flow_entry, l_entry)
3028 ice_flow_rem_entry(hw, ICE_FLOW_ENTRY_HNDL(e));
3030 LIST_DEL(&p->l_entry);
3032 ice_free(hw, p->acts);
3035 ice_release_lock(&hw->fl_profs_locks[blk_idx]);
3037 /* if driver is in reset and tables are being cleared
3038 * re-initialize the flow profile list heads
3040 INIT_LIST_HEAD(&hw->fl_profs[blk_idx]);
3044 * ice_free_vsig_tbl - free complete VSIG table entries
3045 * @hw: pointer to the hardware structure
3046 * @blk: the HW block on which to free the VSIG table entries
3048 static void ice_free_vsig_tbl(struct ice_hw *hw, enum ice_block blk)
3052 if (!hw->blk[blk].xlt2.vsig_tbl)
3055 for (i = 1; i < ICE_MAX_VSIGS; i++)
3056 if (hw->blk[blk].xlt2.vsig_tbl[i].in_use)
3057 ice_vsig_free(hw, blk, i);
3061 * ice_free_hw_tbls - free hardware table memory
3062 * @hw: pointer to the hardware structure
3064 void ice_free_hw_tbls(struct ice_hw *hw)
3066 struct ice_rss_cfg *r, *rt;
3069 for (i = 0; i < ICE_BLK_COUNT; i++) {
3070 if (hw->blk[i].is_list_init) {
3071 struct ice_es *es = &hw->blk[i].es;
3073 ice_free_prof_map(hw, i);
3074 ice_destroy_lock(&es->prof_map_lock);
3075 ice_free_flow_profs(hw, i);
3076 ice_destroy_lock(&hw->fl_profs_locks[i]);
3078 hw->blk[i].is_list_init = false;
3080 ice_free_vsig_tbl(hw, (enum ice_block)i);
3081 ice_free(hw, hw->blk[i].xlt1.ptypes);
3082 ice_free(hw, hw->blk[i].xlt1.ptg_tbl);
3083 ice_free(hw, hw->blk[i].xlt1.t);
3084 ice_free(hw, hw->blk[i].xlt2.t);
3085 ice_free(hw, hw->blk[i].xlt2.vsig_tbl);
3086 ice_free(hw, hw->blk[i].xlt2.vsis);
3087 ice_free(hw, hw->blk[i].prof.t);
3088 ice_free(hw, hw->blk[i].prof_redir.t);
3089 ice_free(hw, hw->blk[i].es.t);
3090 ice_free(hw, hw->blk[i].es.ref_count);
3091 ice_free(hw, hw->blk[i].es.written);
3094 LIST_FOR_EACH_ENTRY_SAFE(r, rt, &hw->rss_list_head,
3095 ice_rss_cfg, l_entry) {
3096 LIST_DEL(&r->l_entry);
3099 ice_destroy_lock(&hw->rss_locks);
3100 ice_memset(hw->blk, 0, sizeof(hw->blk), ICE_NONDMA_MEM);
3104 * ice_init_flow_profs - init flow profile locks and list heads
3105 * @hw: pointer to the hardware structure
3106 * @blk_idx: HW block index
3108 static void ice_init_flow_profs(struct ice_hw *hw, u8 blk_idx)
3110 ice_init_lock(&hw->fl_profs_locks[blk_idx]);
3111 INIT_LIST_HEAD(&hw->fl_profs[blk_idx]);
3115 * ice_init_hw_tbls - init hardware table memory
3116 * @hw: pointer to the hardware structure
3118 enum ice_status ice_init_hw_tbls(struct ice_hw *hw)
3122 ice_init_lock(&hw->rss_locks);
3123 INIT_LIST_HEAD(&hw->rss_list_head);
3124 for (i = 0; i < ICE_BLK_COUNT; i++) {
3125 struct ice_prof_redir *prof_redir = &hw->blk[i].prof_redir;
3126 struct ice_prof_tcam *prof = &hw->blk[i].prof;
3127 struct ice_xlt1 *xlt1 = &hw->blk[i].xlt1;
3128 struct ice_xlt2 *xlt2 = &hw->blk[i].xlt2;
3129 struct ice_es *es = &hw->blk[i].es;
3132 if (hw->blk[i].is_list_init)
3135 ice_init_flow_profs(hw, i);
3136 ice_init_lock(&es->prof_map_lock);
3137 INIT_LIST_HEAD(&es->prof_map);
3138 hw->blk[i].is_list_init = true;
3140 hw->blk[i].overwrite = blk_sizes[i].overwrite;
3141 es->reverse = blk_sizes[i].reverse;
3143 xlt1->sid = ice_blk_sids[i][ICE_SID_XLT1_OFF];
3144 xlt1->count = blk_sizes[i].xlt1;
3146 xlt1->ptypes = (struct ice_ptg_ptype *)
3147 ice_calloc(hw, xlt1->count, sizeof(*xlt1->ptypes));
3152 xlt1->ptg_tbl = (struct ice_ptg_entry *)
3153 ice_calloc(hw, ICE_MAX_PTGS, sizeof(*xlt1->ptg_tbl));
3158 xlt1->t = (u8 *)ice_calloc(hw, xlt1->count, sizeof(*xlt1->t));
3162 xlt2->sid = ice_blk_sids[i][ICE_SID_XLT2_OFF];
3163 xlt2->count = blk_sizes[i].xlt2;
3165 xlt2->vsis = (struct ice_vsig_vsi *)
3166 ice_calloc(hw, xlt2->count, sizeof(*xlt2->vsis));
3171 xlt2->vsig_tbl = (struct ice_vsig_entry *)
3172 ice_calloc(hw, xlt2->count, sizeof(*xlt2->vsig_tbl));
3173 if (!xlt2->vsig_tbl)
3176 for (j = 0; j < xlt2->count; j++)
3177 INIT_LIST_HEAD(&xlt2->vsig_tbl[j].prop_lst);
3179 xlt2->t = (u16 *)ice_calloc(hw, xlt2->count, sizeof(*xlt2->t));
3183 prof->sid = ice_blk_sids[i][ICE_SID_PR_OFF];
3184 prof->count = blk_sizes[i].prof_tcam;
3185 prof->max_prof_id = blk_sizes[i].prof_id;
3186 prof->cdid_bits = blk_sizes[i].prof_cdid_bits;
3187 prof->t = (struct ice_prof_tcam_entry *)
3188 ice_calloc(hw, prof->count, sizeof(*prof->t));
3193 prof_redir->sid = ice_blk_sids[i][ICE_SID_PR_REDIR_OFF];
3194 prof_redir->count = blk_sizes[i].prof_redir;
3195 prof_redir->t = (u8 *)ice_calloc(hw, prof_redir->count,
3196 sizeof(*prof_redir->t));
3201 es->sid = ice_blk_sids[i][ICE_SID_ES_OFF];
3202 es->count = blk_sizes[i].es;
3203 es->fvw = blk_sizes[i].fvw;
3204 es->t = (struct ice_fv_word *)
3205 ice_calloc(hw, (u32)(es->count * es->fvw),
3210 es->ref_count = (u16 *)
3211 ice_calloc(hw, es->count, sizeof(*es->ref_count));
3213 es->written = (u8 *)
3214 ice_calloc(hw, es->count, sizeof(*es->written));
3222 ice_free_hw_tbls(hw);
3223 return ICE_ERR_NO_MEMORY;
3227 * ice_prof_gen_key - generate profile ID key
3228 * @hw: pointer to the HW struct
3229 * @blk: the block in which to write profile ID to
3230 * @ptg: packet type group (PTG) portion of key
3231 * @vsig: VSIG portion of key
3232 * @cdid: cdid portion of key
3233 * @flags: flag portion of key
3234 * @vl_msk: valid mask
3235 * @dc_msk: don't care mask
3236 * @nm_msk: never match mask
3237 * @key: output of profile ID key
3239 static enum ice_status
3240 ice_prof_gen_key(struct ice_hw *hw, enum ice_block blk, u8 ptg, u16 vsig,
3241 u8 cdid, u16 flags, u8 vl_msk[ICE_TCAM_KEY_VAL_SZ],
3242 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ], u8 nm_msk[ICE_TCAM_KEY_VAL_SZ],
3243 u8 key[ICE_TCAM_KEY_SZ])
3245 struct ice_prof_id_key inkey;
3248 inkey.xlt2_cdid = CPU_TO_LE16(vsig);
3249 inkey.flags = CPU_TO_LE16(flags);
3251 switch (hw->blk[blk].prof.cdid_bits) {
3255 #define ICE_CD_2_M 0xC000U
3256 #define ICE_CD_2_S 14
3257 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_2_M);
3258 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_2_S);
3261 #define ICE_CD_4_M 0xF000U
3262 #define ICE_CD_4_S 12
3263 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_4_M);
3264 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_4_S);
3267 #define ICE_CD_8_M 0xFF00U
3268 #define ICE_CD_8_S 16
3269 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_8_M);
3270 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_8_S);
3273 ice_debug(hw, ICE_DBG_PKG, "Error in profile config\n");
3277 return ice_set_key(key, ICE_TCAM_KEY_SZ, (u8 *)&inkey, vl_msk, dc_msk,
3278 nm_msk, 0, ICE_TCAM_KEY_SZ / 2);
3282 * ice_tcam_write_entry - write TCAM entry
3283 * @hw: pointer to the HW struct
3284 * @blk: the block in which to write profile ID to
3285 * @idx: the entry index to write to
3286 * @prof_id: profile ID
3287 * @ptg: packet type group (PTG) portion of key
3288 * @vsig: VSIG portion of key
3289 * @cdid: cdid portion of key
3290 * @flags: flag portion of key
3291 * @vl_msk: valid mask
3292 * @dc_msk: don't care mask
3293 * @nm_msk: never match mask
3295 static enum ice_status
3296 ice_tcam_write_entry(struct ice_hw *hw, enum ice_block blk, u16 idx,
3297 u8 prof_id, u8 ptg, u16 vsig, u8 cdid, u16 flags,
3298 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ],
3299 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ],
3300 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ])
3302 struct ice_prof_tcam_entry;
3303 enum ice_status status;
3305 status = ice_prof_gen_key(hw, blk, ptg, vsig, cdid, flags, vl_msk,
3306 dc_msk, nm_msk, hw->blk[blk].prof.t[idx].key);
3308 hw->blk[blk].prof.t[idx].addr = CPU_TO_LE16(idx);
3309 hw->blk[blk].prof.t[idx].prof_id = prof_id;
3316 * ice_vsig_get_ref - returns number of VSIs belong to a VSIG
3317 * @hw: pointer to the hardware structure
3319 * @vsig: VSIG to query
3320 * @refs: pointer to variable to receive the reference count
3322 static enum ice_status
3323 ice_vsig_get_ref(struct ice_hw *hw, enum ice_block blk, u16 vsig, u16 *refs)
3325 u16 idx = vsig & ICE_VSIG_IDX_M;
3326 struct ice_vsig_vsi *ptr;
3329 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
3330 return ICE_ERR_DOES_NOT_EXIST;
3332 ptr = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
3335 ptr = ptr->next_vsi;
3342 * ice_get_ptg - get or allocate a ptg for a ptype
3343 * @hw: pointer to the hardware structure
3345 * @ptype: the ptype to retrieve the PTG for
3346 * @ptg: receives the PTG of the ptype
3347 * @add: receive boolean indicating whether PTG was added or not
3349 static enum ice_status
3350 ice_get_ptg(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 *ptg,
3353 enum ice_status status;
3355 *ptg = ICE_DEFAULT_PTG;
3358 status = ice_ptg_find_ptype(hw, blk, ptype, ptg);
3362 if (*ptg == ICE_DEFAULT_PTG) {
3363 /* need to allocate a PTG, and add ptype to it */
3364 *ptg = ice_ptg_alloc(hw, blk);
3365 if (*ptg == ICE_DEFAULT_PTG)
3366 return ICE_ERR_HW_TABLE;
3368 status = ice_ptg_add_mv_ptype(hw, blk, ptype, *ptg);
3370 return ICE_ERR_HW_TABLE;
3379 * ice_has_prof_vsig - check to see if VSIG has a specific profile
3380 * @hw: pointer to the hardware structure
3382 * @vsig: VSIG to check against
3383 * @hdl: profile handle
3386 ice_has_prof_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl)
3388 u16 idx = vsig & ICE_VSIG_IDX_M;
3389 struct ice_vsig_prof *ent;
3391 LIST_FOR_EACH_ENTRY(ent, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
3392 ice_vsig_prof, list) {
3393 if (ent->profile_cookie == hdl)
3397 ice_debug(hw, ICE_DBG_INIT,
3398 "Characteristic list for VSI group %d not found.\n",
3404 * ice_prof_bld_es - build profile ID extraction sequence changes
3405 * @hw: pointer to the HW struct
3406 * @blk: hardware block
3407 * @bld: the update package buffer build to add to
3408 * @chgs: the list of changes to make in hardware
3410 static enum ice_status
3411 ice_prof_bld_es(struct ice_hw *hw, enum ice_block blk,
3412 struct ice_buf_build *bld, struct LIST_HEAD_TYPE *chgs)
3414 u16 vec_size = hw->blk[blk].es.fvw * sizeof(struct ice_fv_word);
3415 struct ice_chs_chg *tmp;
3417 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
3418 if (tmp->type == ICE_PTG_ES_ADD && tmp->add_prof) {
3419 u16 off = tmp->prof_id * hw->blk[blk].es.fvw;
3420 struct ice_pkg_es *p;
3423 id = ice_sect_id(blk, ICE_VEC_TBL);
3424 p = (struct ice_pkg_es *)
3425 ice_pkg_buf_alloc_section(bld, id, sizeof(*p) +
3430 return ICE_ERR_MAX_LIMIT;
3432 p->count = CPU_TO_LE16(1);
3433 p->offset = CPU_TO_LE16(tmp->prof_id);
3435 ice_memcpy(p->es, &hw->blk[blk].es.t[off], vec_size,
3436 ICE_NONDMA_TO_NONDMA);
3444 * ice_prof_bld_tcam - build profile ID TCAM changes
3445 * @hw: pointer to the HW struct
3446 * @blk: hardware block
3447 * @bld: the update package buffer build to add to
3448 * @chgs: the list of changes to make in hardware
3450 static enum ice_status
3451 ice_prof_bld_tcam(struct ice_hw *hw, enum ice_block blk,
3452 struct ice_buf_build *bld, struct LIST_HEAD_TYPE *chgs)
3454 struct ice_chs_chg *tmp;
3456 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
3457 if (tmp->type == ICE_TCAM_ADD && tmp->add_tcam_idx) {
3458 struct ice_prof_id_section *p;
3461 id = ice_sect_id(blk, ICE_PROF_TCAM);
3462 p = (struct ice_prof_id_section *)
3463 ice_pkg_buf_alloc_section(bld, id, sizeof(*p));
3466 return ICE_ERR_MAX_LIMIT;
3468 p->count = CPU_TO_LE16(1);
3469 p->entry[0].addr = CPU_TO_LE16(tmp->tcam_idx);
3470 p->entry[0].prof_id = tmp->prof_id;
3472 ice_memcpy(p->entry[0].key,
3473 &hw->blk[blk].prof.t[tmp->tcam_idx].key,
3474 sizeof(hw->blk[blk].prof.t->key),
3475 ICE_NONDMA_TO_NONDMA);
3483 * ice_prof_bld_xlt1 - build XLT1 changes
3484 * @blk: hardware block
3485 * @bld: the update package buffer build to add to
3486 * @chgs: the list of changes to make in hardware
3488 static enum ice_status
3489 ice_prof_bld_xlt1(enum ice_block blk, struct ice_buf_build *bld,
3490 struct LIST_HEAD_TYPE *chgs)
3492 struct ice_chs_chg *tmp;
3494 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
3495 if (tmp->type == ICE_PTG_ES_ADD && tmp->add_ptg) {
3496 struct ice_xlt1_section *p;
3499 id = ice_sect_id(blk, ICE_XLT1);
3500 p = (struct ice_xlt1_section *)
3501 ice_pkg_buf_alloc_section(bld, id, sizeof(*p));
3504 return ICE_ERR_MAX_LIMIT;
3506 p->count = CPU_TO_LE16(1);
3507 p->offset = CPU_TO_LE16(tmp->ptype);
3508 p->value[0] = tmp->ptg;
3516 * ice_prof_bld_xlt2 - build XLT2 changes
3517 * @blk: hardware block
3518 * @bld: the update package buffer build to add to
3519 * @chgs: the list of changes to make in hardware
3521 static enum ice_status
3522 ice_prof_bld_xlt2(enum ice_block blk, struct ice_buf_build *bld,
3523 struct LIST_HEAD_TYPE *chgs)
3525 struct ice_chs_chg *tmp;
3527 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
3530 if (tmp->type == ICE_VSIG_ADD)
3532 else if (tmp->type == ICE_VSI_MOVE)
3534 else if (tmp->type == ICE_VSIG_REM)
3538 struct ice_xlt2_section *p;
3541 id = ice_sect_id(blk, ICE_XLT2);
3542 p = (struct ice_xlt2_section *)
3543 ice_pkg_buf_alloc_section(bld, id, sizeof(*p));
3546 return ICE_ERR_MAX_LIMIT;
3548 p->count = CPU_TO_LE16(1);
3549 p->offset = CPU_TO_LE16(tmp->vsi);
3550 p->value[0] = CPU_TO_LE16(tmp->vsig);
3558 * ice_upd_prof_hw - update hardware using the change list
3559 * @hw: pointer to the HW struct
3560 * @blk: hardware block
3561 * @chgs: the list of changes to make in hardware
3563 static enum ice_status
3564 ice_upd_prof_hw(struct ice_hw *hw, enum ice_block blk,
3565 struct LIST_HEAD_TYPE *chgs)
3567 struct ice_buf_build *b;
3568 struct ice_chs_chg *tmp;
3569 enum ice_status status;
3577 /* count number of sections we need */
3578 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
3579 switch (tmp->type) {
3580 case ICE_PTG_ES_ADD:
3598 sects = xlt1 + xlt2 + tcam + es;
3603 /* Build update package buffer */
3604 b = ice_pkg_buf_alloc(hw);
3606 return ICE_ERR_NO_MEMORY;
3608 status = ice_pkg_buf_reserve_section(b, sects);
3612 /* Preserve order of table update: ES, TCAM, PTG, VSIG */
3614 status = ice_prof_bld_es(hw, blk, b, chgs);
3620 status = ice_prof_bld_tcam(hw, blk, b, chgs);
3626 status = ice_prof_bld_xlt1(blk, b, chgs);
3632 status = ice_prof_bld_xlt2(blk, b, chgs);
3637 /* After package buffer build check if the section count in buffer is
3638 * non-zero and matches the number of sections detected for package
3641 pkg_sects = ice_pkg_buf_get_active_sections(b);
3642 if (!pkg_sects || pkg_sects != sects) {
3643 status = ICE_ERR_INVAL_SIZE;
3647 /* update package */
3648 status = ice_update_pkg(hw, ice_pkg_buf(b), 1);
3649 if (status == ICE_ERR_AQ_ERROR)
3650 ice_debug(hw, ICE_DBG_INIT, "Unable to update HW profile.");
3653 ice_pkg_buf_free(hw, b);
3658 * ice_update_fd_mask - set Flow Director Field Vector mask for a profile
3659 * @hw: pointer to the HW struct
3660 * @prof_id: profile ID
3661 * @mask_sel: mask select
3663 * This function enable any of the masks selected by the mask select parameter
3664 * for the profile specified.
3666 static void ice_update_fd_mask(struct ice_hw *hw, u16 prof_id, u32 mask_sel)
3668 wr32(hw, GLQF_FDMASK_SEL(prof_id), mask_sel);
3670 ice_debug(hw, ICE_DBG_INIT, "fd mask(%d): %x = %x\n", prof_id,
3671 GLQF_FDMASK_SEL(prof_id), mask_sel);
3674 #define ICE_SRC_DST_MAX_COUNT 8
3676 struct ice_fd_src_dst_pair {
3682 static const struct ice_fd_src_dst_pair ice_fd_pairs[] = {
3683 /* These are defined in pairs */
3684 { ICE_PROT_IPV4_OF_OR_S, 2, 12 },
3685 { ICE_PROT_IPV4_OF_OR_S, 2, 16 },
3687 { ICE_PROT_IPV4_IL, 2, 12 },
3688 { ICE_PROT_IPV4_IL, 2, 16 },
3690 { ICE_PROT_IPV6_OF_OR_S, 8, 8 },
3691 { ICE_PROT_IPV6_OF_OR_S, 8, 24 },
3693 { ICE_PROT_IPV6_IL, 8, 8 },
3694 { ICE_PROT_IPV6_IL, 8, 24 },
3696 { ICE_PROT_TCP_IL, 1, 0 },
3697 { ICE_PROT_TCP_IL, 1, 2 },
3699 { ICE_PROT_UDP_OF, 1, 0 },
3700 { ICE_PROT_UDP_OF, 1, 2 },
3702 { ICE_PROT_UDP_IL_OR_S, 1, 0 },
3703 { ICE_PROT_UDP_IL_OR_S, 1, 2 },
3705 { ICE_PROT_SCTP_IL, 1, 0 },
3706 { ICE_PROT_SCTP_IL, 1, 2 }
3709 #define ICE_FD_SRC_DST_PAIR_COUNT ARRAY_SIZE(ice_fd_pairs)
3712 * ice_update_fd_swap - set register appropriately for a FD FV extraction
3713 * @hw: pointer to the HW struct
3714 * @prof_id: profile ID
3715 * @es: extraction sequence (length of array is determined by the block)
3717 static enum ice_status
3718 ice_update_fd_swap(struct ice_hw *hw, u16 prof_id, struct ice_fv_word *es)
3720 ice_declare_bitmap(pair_list, ICE_FD_SRC_DST_PAIR_COUNT);
3721 u8 pair_start[ICE_FD_SRC_DST_PAIR_COUNT] = { 0 };
3722 #define ICE_FD_FV_NOT_FOUND (-2)
3723 s8 first_free = ICE_FD_FV_NOT_FOUND;
3724 u8 used[ICE_MAX_FV_WORDS] = { 0 };
3729 ice_zero_bitmap(pair_list, ICE_FD_SRC_DST_PAIR_COUNT);
3731 ice_init_fd_mask_regs(hw);
3733 /* This code assumes that the Flow Director field vectors are assigned
3734 * from the end of the FV indexes working towards the zero index, that
3735 * only complete fields will be included and will be consecutive, and
3736 * that there are no gaps between valid indexes.
3739 /* Determine swap fields present */
3740 for (i = 0; i < hw->blk[ICE_BLK_FD].es.fvw; i++) {
3741 /* Find the first free entry, assuming right to left population.
3742 * This is where we can start adding additional pairs if needed.
3744 if (first_free == ICE_FD_FV_NOT_FOUND && es[i].prot_id !=
3748 for (j = 0; j < ICE_FD_SRC_DST_PAIR_COUNT; j++) {
3749 if (es[i].prot_id == ice_fd_pairs[j].prot_id &&
3750 es[i].off == ice_fd_pairs[j].off) {
3751 ice_set_bit(j, pair_list);
3757 orig_free = first_free;
3759 /* determine missing swap fields that need to be added */
3760 for (i = 0; i < ICE_FD_SRC_DST_PAIR_COUNT; i += 2) {
3761 u8 bit1 = ice_is_bit_set(pair_list, i + 1);
3762 u8 bit0 = ice_is_bit_set(pair_list, i);
3767 /* add the appropriate 'paired' entry */
3773 /* check for room */
3774 if (first_free + 1 < ice_fd_pairs[index].count)
3775 return ICE_ERR_MAX_LIMIT;
3777 /* place in extraction sequence */
3778 for (k = 0; k < ice_fd_pairs[index].count; k++) {
3779 es[first_free - k].prot_id =
3780 ice_fd_pairs[index].prot_id;
3781 es[first_free - k].off =
3782 ice_fd_pairs[index].off + (k * 2);
3784 /* keep track of non-relevant fields */
3785 mask_sel |= 1 << (first_free - k);
3788 pair_start[index] = first_free;
3789 first_free -= ice_fd_pairs[index].count;
3793 /* fill in the swap array */
3794 si = hw->blk[ICE_BLK_FD].es.fvw - 1;
3796 u8 indexes_used = 1;
3798 /* assume flat at this index */
3799 #define ICE_SWAP_VALID 0x80
3800 used[si] = si | ICE_SWAP_VALID;
3802 if (orig_free == ICE_FD_FV_NOT_FOUND || si <= orig_free) {
3807 /* check for a swap location */
3808 for (j = 0; j < ICE_FD_SRC_DST_PAIR_COUNT; j++) {
3809 if (es[si].prot_id == ice_fd_pairs[j].prot_id &&
3810 es[si].off == ice_fd_pairs[j].off) {
3813 /* determine the appropriate matching field */
3814 idx = j + ((j % 2) ? -1 : 1);
3816 indexes_used = ice_fd_pairs[idx].count;
3817 for (k = 0; k < indexes_used; k++) {
3818 used[si - k] = (pair_start[idx] - k) |
3829 /* for each set of 4 swap indexes, write the appropriate register */
3830 for (j = 0; j < hw->blk[ICE_BLK_FD].es.fvw / 4; j++) {
3833 for (k = 0; k < 4; k++) {
3838 raw_entry |= used[idx] << (k * BITS_PER_BYTE);
3841 /* write the appropriate register set, based on HW block */
3842 wr32(hw, GLQF_FDSWAP(prof_id, j), raw_entry);
3844 ice_debug(hw, ICE_DBG_INIT, "swap wr(%d, %d): %x = %x\n",
3845 prof_id, j, GLQF_FDSWAP(prof_id, j), raw_entry);
3848 /* update the masks for this profile to be sure we ignore fields that
3849 * are not relevant to our match criteria
3851 ice_update_fd_mask(hw, prof_id, mask_sel);
3857 * ice_add_prof - add profile
3858 * @hw: pointer to the HW struct
3859 * @blk: hardware block
3860 * @id: profile tracking ID
3861 * @ptypes: array of bitmaps indicating ptypes (ICE_FLOW_PTYPE_MAX bits)
3862 * @es: extraction sequence (length of array is determined by the block)
3864 * This function registers a profile, which matches a set of PTYPES with a
3865 * particular extraction sequence. While the hardware profile is allocated
3866 * it will not be written until the first call to ice_add_flow that specifies
3867 * the ID value used here.
3870 ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64 id, u8 ptypes[],
3871 struct ice_fv_word *es)
3873 u32 bytes = DIVIDE_AND_ROUND_UP(ICE_FLOW_PTYPE_MAX, BITS_PER_BYTE);
3874 struct ice_prof_map *prof;
3875 enum ice_status status;
3879 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
3881 /* search for existing profile */
3882 status = ice_find_prof_id(hw, blk, es, &prof_id);
3884 /* allocate profile ID */
3885 status = ice_alloc_prof_id(hw, blk, &prof_id);
3887 goto err_ice_add_prof;
3888 if (blk == ICE_BLK_FD) {
3889 /* For Flow Director block, the extraction sequence may
3890 * need to be altered in the case where there are paired
3891 * fields that have no match. This is necessary because
3892 * for Flow Director, src and dest fields need to paired
3893 * for filter programming and these values are swapped
3896 status = ice_update_fd_swap(hw, prof_id, es);
3898 goto err_ice_add_prof;
3901 /* and write new es */
3902 ice_write_es(hw, blk, prof_id, es);
3905 ice_prof_inc_ref(hw, blk, prof_id);
3907 /* add profile info */
3909 prof = (struct ice_prof_map *)ice_malloc(hw, sizeof(*prof));
3911 goto err_ice_add_prof;
3913 prof->profile_cookie = id;
3914 prof->prof_id = prof_id;
3915 prof->ptype_count = 0;
3918 /* build list of ptgs */
3919 while (bytes && prof->ptype_count < ICE_MAX_PTYPE_PER_PROFILE) {
3922 if (!ptypes[byte]) {
3927 /* Examine 8 bits per byte */
3928 for (bit = 0; bit < 8; bit++) {
3929 if (ptypes[byte] & 1 << bit) {
3933 ptype = byte * BITS_PER_BYTE + bit;
3934 if (ptype < ICE_FLOW_PTYPE_MAX) {
3935 prof->ptype[prof->ptype_count] = ptype;
3937 if (++prof->ptype_count >=
3938 ICE_MAX_PTYPE_PER_PROFILE)
3942 /* nothing left in byte, then exit */
3943 m = ~((1 << (bit + 1)) - 1);
3944 if (!(ptypes[byte] & m))
3953 LIST_ADD(&prof->list, &hw->blk[blk].es.prof_map);
3954 status = ICE_SUCCESS;
3957 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
3962 * ice_search_prof_id_low - Search for a profile tracking ID low level
3963 * @hw: pointer to the HW struct
3964 * @blk: hardware block
3965 * @id: profile tracking ID
3967 * This will search for a profile tracking ID which was previously added. This
3968 * version assumes that the caller has already acquired the prof map lock.
3970 static struct ice_prof_map *
3971 ice_search_prof_id_low(struct ice_hw *hw, enum ice_block blk, u64 id)
3973 struct ice_prof_map *entry = NULL;
3974 struct ice_prof_map *map;
3976 LIST_FOR_EACH_ENTRY(map, &hw->blk[blk].es.prof_map, ice_prof_map,
3978 if (map->profile_cookie == id) {
3988 * ice_search_prof_id - Search for a profile tracking ID
3989 * @hw: pointer to the HW struct
3990 * @blk: hardware block
3991 * @id: profile tracking ID
3993 * This will search for a profile tracking ID which was previously added.
3995 struct ice_prof_map *
3996 ice_search_prof_id(struct ice_hw *hw, enum ice_block blk, u64 id)
3998 struct ice_prof_map *entry;
4000 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
4001 entry = ice_search_prof_id_low(hw, blk, id);
4002 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
4008 * ice_vsig_prof_id_count - count profiles in a VSIG
4009 * @hw: pointer to the HW struct
4010 * @blk: hardware block
4011 * @vsig: VSIG to remove the profile from
4014 ice_vsig_prof_id_count(struct ice_hw *hw, enum ice_block blk, u16 vsig)
4016 u16 idx = vsig & ICE_VSIG_IDX_M, count = 0;
4017 struct ice_vsig_prof *p;
4019 LIST_FOR_EACH_ENTRY(p, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4020 ice_vsig_prof, list) {
4028 * ice_rel_tcam_idx - release a TCAM index
4029 * @hw: pointer to the HW struct
4030 * @blk: hardware block
4031 * @idx: the index to release
4033 static enum ice_status
4034 ice_rel_tcam_idx(struct ice_hw *hw, enum ice_block blk, u16 idx)
4036 /* Masks to invoke a never match entry */
4037 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4038 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFE, 0xFF, 0xFF, 0xFF, 0xFF };
4039 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x01, 0x00, 0x00, 0x00, 0x00 };
4040 enum ice_status status;
4042 /* write the TCAM entry */
4043 status = ice_tcam_write_entry(hw, blk, idx, 0, 0, 0, 0, 0, vl_msk,
4048 /* release the TCAM entry */
4049 status = ice_free_tcam_ent(hw, blk, idx);
4055 * ice_rem_prof_id - remove one profile from a VSIG
4056 * @hw: pointer to the HW struct
4057 * @blk: hardware block
4058 * @prof: pointer to profile structure to remove
4060 static enum ice_status
4061 ice_rem_prof_id(struct ice_hw *hw, enum ice_block blk,
4062 struct ice_vsig_prof *prof)
4064 enum ice_status status;
4067 for (i = 0; i < prof->tcam_count; i++) {
4068 prof->tcam[i].in_use = false;
4069 status = ice_rel_tcam_idx(hw, blk, prof->tcam[i].tcam_idx);
4071 return ICE_ERR_HW_TABLE;
4078 * ice_rem_vsig - remove VSIG
4079 * @hw: pointer to the HW struct
4080 * @blk: hardware block
4081 * @vsig: the VSIG to remove
4082 * @chg: the change list
4084 static enum ice_status
4085 ice_rem_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig,
4086 struct LIST_HEAD_TYPE *chg)
4088 u16 idx = vsig & ICE_VSIG_IDX_M;
4089 struct ice_vsig_vsi *vsi_cur;
4090 struct ice_vsig_prof *d, *t;
4091 enum ice_status status;
4093 /* remove TCAM entries */
4094 LIST_FOR_EACH_ENTRY_SAFE(d, t,
4095 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4096 ice_vsig_prof, list) {
4097 status = ice_rem_prof_id(hw, blk, d);
4105 /* Move all VSIS associated with this VSIG to the default VSIG */
4106 vsi_cur = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
4107 /* If the VSIG has at least 1 VSI then iterate through the list
4108 * and remove the VSIs before deleting the group.
4112 struct ice_vsig_vsi *tmp = vsi_cur->next_vsi;
4113 struct ice_chs_chg *p;
4115 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4117 return ICE_ERR_NO_MEMORY;
4119 p->type = ICE_VSIG_REM;
4120 p->orig_vsig = vsig;
4121 p->vsig = ICE_DEFAULT_VSIG;
4122 p->vsi = vsi_cur - hw->blk[blk].xlt2.vsis;
4124 LIST_ADD(&p->list_entry, chg);
4130 status = ice_vsig_free(hw, blk, vsig);
4136 * ice_rem_prof_id_vsig - remove a specific profile from a VSIG
4137 * @hw: pointer to the HW struct
4138 * @blk: hardware block
4139 * @vsig: VSIG to remove the profile from
4140 * @hdl: profile handle indicating which profile to remove
4141 * @chg: list to receive a record of changes
4143 static enum ice_status
4144 ice_rem_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl,
4145 struct LIST_HEAD_TYPE *chg)
4147 u16 idx = vsig & ICE_VSIG_IDX_M;
4148 struct ice_vsig_prof *p, *t;
4149 enum ice_status status;
4151 LIST_FOR_EACH_ENTRY_SAFE(p, t,
4152 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4153 ice_vsig_prof, list) {
4154 if (p->profile_cookie == hdl) {
4155 if (ice_vsig_prof_id_count(hw, blk, vsig) == 1)
4156 /* this is the last profile, remove the VSIG */
4157 return ice_rem_vsig(hw, blk, vsig, chg);
4159 status = ice_rem_prof_id(hw, blk, p);
4168 return ICE_ERR_DOES_NOT_EXIST;
4172 * ice_rem_flow_all - remove all flows with a particular profile
4173 * @hw: pointer to the HW struct
4174 * @blk: hardware block
4175 * @id: profile tracking ID
4177 static enum ice_status
4178 ice_rem_flow_all(struct ice_hw *hw, enum ice_block blk, u64 id)
4180 struct ice_chs_chg *del, *tmp;
4181 struct LIST_HEAD_TYPE chg;
4182 enum ice_status status;
4185 INIT_LIST_HEAD(&chg);
4187 for (i = 1; i < ICE_MAX_VSIGS; i++) {
4188 if (hw->blk[blk].xlt2.vsig_tbl[i].in_use) {
4189 if (ice_has_prof_vsig(hw, blk, i, id)) {
4190 status = ice_rem_prof_id_vsig(hw, blk, i, id,
4193 goto err_ice_rem_flow_all;
4198 status = ice_upd_prof_hw(hw, blk, &chg);
4200 err_ice_rem_flow_all:
4201 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
4202 LIST_DEL(&del->list_entry);
4210 * ice_rem_prof - remove profile
4211 * @hw: pointer to the HW struct
4212 * @blk: hardware block
4213 * @id: profile tracking ID
4215 * This will remove the profile specified by the ID parameter, which was
4216 * previously created through ice_add_prof. If any existing entries
4217 * are associated with this profile, they will be removed as well.
4219 enum ice_status ice_rem_prof(struct ice_hw *hw, enum ice_block blk, u64 id)
4221 struct ice_prof_map *pmap;
4222 enum ice_status status;
4224 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
4226 pmap = ice_search_prof_id_low(hw, blk, id);
4228 status = ICE_ERR_DOES_NOT_EXIST;
4229 goto err_ice_rem_prof;
4232 /* remove all flows with this profile */
4233 status = ice_rem_flow_all(hw, blk, pmap->profile_cookie);
4235 goto err_ice_rem_prof;
4237 /* dereference profile, and possibly remove */
4238 ice_prof_dec_ref(hw, blk, pmap->prof_id);
4240 LIST_DEL(&pmap->list);
4243 status = ICE_SUCCESS;
4246 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
4251 * ice_get_prof_ptgs - get ptgs for profile
4252 * @hw: pointer to the HW struct
4253 * @blk: hardware block
4254 * @hdl: profile handle
4257 static enum ice_status
4258 ice_get_prof_ptgs(struct ice_hw *hw, enum ice_block blk, u64 hdl,
4259 struct LIST_HEAD_TYPE *chg)
4261 struct ice_prof_map *map;
4262 struct ice_chs_chg *p;
4265 /* Get the details on the profile specified by the handle ID */
4266 map = ice_search_prof_id(hw, blk, hdl);
4268 return ICE_ERR_DOES_NOT_EXIST;
4270 for (i = 0; i < map->ptype_count; i++) {
4271 enum ice_status status;
4275 status = ice_get_ptg(hw, blk, map->ptype[i], &ptg, &add);
4277 goto err_ice_get_prof_ptgs;
4279 if (add || !hw->blk[blk].es.written[map->prof_id]) {
4280 /* add PTG to change list */
4281 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4283 goto err_ice_get_prof_ptgs;
4285 p->type = ICE_PTG_ES_ADD;
4286 p->ptype = map->ptype[i];
4290 p->add_prof = !hw->blk[blk].es.written[map->prof_id];
4291 p->prof_id = map->prof_id;
4293 hw->blk[blk].es.written[map->prof_id] = true;
4295 LIST_ADD(&p->list_entry, chg);
4301 err_ice_get_prof_ptgs:
4302 /* let caller clean up the change list */
4303 return ICE_ERR_NO_MEMORY;
4307 * ice_get_profs_vsig - get a copy of the list of profiles from a VSIG
4308 * @hw: pointer to the HW struct
4309 * @blk: hardware block
4310 * @vsig: VSIG from which to copy the list
4313 * This routine makes a copy of the list of profiles in the specified VSIG.
4315 static enum ice_status
4316 ice_get_profs_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig,
4317 struct LIST_HEAD_TYPE *lst)
4319 struct ice_vsig_prof *ent1, *ent2;
4320 u16 idx = vsig & ICE_VSIG_IDX_M;
4322 LIST_FOR_EACH_ENTRY(ent1, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4323 ice_vsig_prof, list) {
4324 struct ice_vsig_prof *p;
4326 /* copy to the input list */
4327 p = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*p));
4329 goto err_ice_get_profs_vsig;
4331 ice_memcpy(p, ent1, sizeof(*p), ICE_NONDMA_TO_NONDMA);
4333 LIST_ADD_TAIL(&p->list, lst);
4338 err_ice_get_profs_vsig:
4339 LIST_FOR_EACH_ENTRY_SAFE(ent1, ent2, lst, ice_vsig_prof, list) {
4340 LIST_DEL(&ent1->list);
4344 return ICE_ERR_NO_MEMORY;
4348 * ice_add_prof_to_lst - add profile entry to a list
4349 * @hw: pointer to the HW struct
4350 * @blk: hardware block
4351 * @lst: the list to be added to
4352 * @hdl: profile handle of entry to add
4354 static enum ice_status
4355 ice_add_prof_to_lst(struct ice_hw *hw, enum ice_block blk,
4356 struct LIST_HEAD_TYPE *lst, u64 hdl)
4358 struct ice_vsig_prof *p;
4359 struct ice_prof_map *map;
4362 map = ice_search_prof_id(hw, blk, hdl);
4364 return ICE_ERR_DOES_NOT_EXIST;
4366 p = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*p));
4368 return ICE_ERR_NO_MEMORY;
4370 p->profile_cookie = map->profile_cookie;
4371 p->prof_id = map->prof_id;
4372 p->tcam_count = map->ptype_count;
4374 for (i = 0; i < map->ptype_count; i++) {
4377 p->tcam[i].prof_id = map->prof_id;
4378 p->tcam[i].tcam_idx = ICE_INVALID_TCAM;
4380 if (ice_ptg_find_ptype(hw, blk, map->ptype[i], &ptg))
4383 p->tcam[i].ptg = ptg;
4386 LIST_ADD(&p->list, lst);
4392 * ice_move_vsi - move VSI to another VSIG
4393 * @hw: pointer to the HW struct
4394 * @blk: hardware block
4395 * @vsi: the VSI to move
4396 * @vsig: the VSIG to move the VSI to
4397 * @chg: the change list
4399 static enum ice_status
4400 ice_move_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig,
4401 struct LIST_HEAD_TYPE *chg)
4403 enum ice_status status;
4404 struct ice_chs_chg *p;
4407 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4409 return ICE_ERR_NO_MEMORY;
4411 status = ice_vsig_find_vsi(hw, blk, vsi, &orig_vsig);
4413 status = ice_vsig_add_mv_vsi(hw, blk, vsi, vsig);
4420 p->type = ICE_VSI_MOVE;
4422 p->orig_vsig = orig_vsig;
4425 LIST_ADD(&p->list_entry, chg);
4431 * ice_prof_tcam_ena_dis - add enable or disable TCAM change
4432 * @hw: pointer to the HW struct
4433 * @blk: hardware block
4434 * @enable: true to enable, false to disable
4435 * @vsig: the vsig of the TCAM entry
4436 * @tcam: pointer the TCAM info structure of the TCAM to disable
4437 * @chg: the change list
4439 * This function appends an enable or disable TCAM entry in the change log
4441 static enum ice_status
4442 ice_prof_tcam_ena_dis(struct ice_hw *hw, enum ice_block blk, bool enable,
4443 u16 vsig, struct ice_tcam_inf *tcam,
4444 struct LIST_HEAD_TYPE *chg)
4446 enum ice_status status;
4447 struct ice_chs_chg *p;
4449 /* Default: enable means change the low flag bit to don't care */
4450 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x01, 0x00, 0x00, 0x00, 0x00 };
4451 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
4452 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x01, 0x00, 0x00, 0x00, 0x00 };
4454 /* If disabled, change the low flag bit to never match */
4460 /* add TCAM to change list */
4461 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4463 return ICE_ERR_NO_MEMORY;
4465 status = ice_tcam_write_entry(hw, blk, tcam->tcam_idx, tcam->prof_id,
4466 tcam->ptg, vsig, 0, 0, vl_msk, dc_msk,
4469 goto err_ice_prof_tcam_ena_dis;
4471 tcam->in_use = enable;
4473 p->type = ICE_TCAM_ADD;
4474 p->add_tcam_idx = true;
4475 p->prof_id = tcam->prof_id;
4478 p->tcam_idx = tcam->tcam_idx;
4481 LIST_ADD(&p->list_entry, chg);
4485 err_ice_prof_tcam_ena_dis:
4491 * ice_adj_prof_priorities - adjust profile based on priorities
4492 * @hw: pointer to the HW struct
4493 * @blk: hardware block
4494 * @vsig: the VSIG for which to adjust profile priorities
4495 * @chg: the change list
4497 static enum ice_status
4498 ice_adj_prof_priorities(struct ice_hw *hw, enum ice_block blk, u16 vsig,
4499 struct LIST_HEAD_TYPE *chg)
4501 ice_declare_bitmap(ptgs_used, ICE_XLT1_CNT);
4502 struct ice_vsig_prof *t;
4503 enum ice_status status;
4506 ice_zero_bitmap(ptgs_used, ICE_XLT1_CNT);
4507 idx = vsig & ICE_VSIG_IDX_M;
4509 /* Priority is based on the order in which the profiles are added. The
4510 * newest added profile has highest priority and the oldest added
4511 * profile has the lowest priority. Since the profile property list for
4512 * a VSIG is sorted from newest to oldest, this code traverses the list
4513 * in order and enables the first of each PTG that it finds (that is not
4514 * already enabled); it also disables any duplicate PTGs that it finds
4515 * in the older profiles (that are currently enabled).
4518 LIST_FOR_EACH_ENTRY(t, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4519 ice_vsig_prof, list) {
4522 for (i = 0; i < t->tcam_count; i++) {
4523 /* Scan the priorities from newest to oldest.
4524 * Make sure that the newest profiles take priority.
4526 if (ice_is_bit_set(ptgs_used, t->tcam[i].ptg) &&
4527 t->tcam[i].in_use) {
4528 /* need to mark this PTG as never match, as it
4529 * was already in use and therefore duplicate
4530 * (and lower priority)
4532 status = ice_prof_tcam_ena_dis(hw, blk, false,
4538 } else if (!ice_is_bit_set(ptgs_used, t->tcam[i].ptg) &&
4539 !t->tcam[i].in_use) {
4540 /* need to enable this PTG, as it in not in use
4541 * and not enabled (highest priority)
4543 status = ice_prof_tcam_ena_dis(hw, blk, true,
4551 /* keep track of used ptgs */
4552 ice_set_bit(t->tcam[i].ptg, ptgs_used);
4560 * ice_add_prof_id_vsig - add profile to VSIG
4561 * @hw: pointer to the HW struct
4562 * @blk: hardware block
4563 * @vsig: the VSIG to which this profile is to be added
4564 * @hdl: the profile handle indicating the profile to add
4565 * @chg: the change list
4567 static enum ice_status
4568 ice_add_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl,
4569 struct LIST_HEAD_TYPE *chg)
4571 /* Masks that ignore flags */
4572 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4573 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0x00, 0x00, 0x00 };
4574 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
4575 struct ice_prof_map *map;
4576 struct ice_vsig_prof *t;
4577 struct ice_chs_chg *p;
4580 /* Get the details on the profile specified by the handle ID */
4581 map = ice_search_prof_id(hw, blk, hdl);
4583 return ICE_ERR_DOES_NOT_EXIST;
4585 /* Error, if this VSIG already has this profile */
4586 if (ice_has_prof_vsig(hw, blk, vsig, hdl))
4587 return ICE_ERR_ALREADY_EXISTS;
4589 /* new VSIG profile structure */
4590 t = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*t));
4592 goto err_ice_add_prof_id_vsig;
4594 t->profile_cookie = map->profile_cookie;
4595 t->prof_id = map->prof_id;
4596 t->tcam_count = map->ptype_count;
4598 /* create TCAM entries */
4599 for (i = 0; i < map->ptype_count; i++) {
4600 enum ice_status status;
4605 /* If properly sequenced, we should never have to allocate new
4608 status = ice_get_ptg(hw, blk, map->ptype[i], &ptg, &add);
4610 goto err_ice_add_prof_id_vsig;
4612 /* add TCAM to change list */
4613 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4615 goto err_ice_add_prof_id_vsig;
4617 /* allocate the TCAM entry index */
4618 status = ice_alloc_tcam_ent(hw, blk, &tcam_idx);
4621 goto err_ice_add_prof_id_vsig;
4624 t->tcam[i].ptg = ptg;
4625 t->tcam[i].prof_id = map->prof_id;
4626 t->tcam[i].tcam_idx = tcam_idx;
4627 t->tcam[i].in_use = true;
4629 p->type = ICE_TCAM_ADD;
4630 p->add_tcam_idx = true;
4631 p->prof_id = t->tcam[i].prof_id;
4632 p->ptg = t->tcam[i].ptg;
4634 p->tcam_idx = t->tcam[i].tcam_idx;
4636 /* write the TCAM entry */
4637 status = ice_tcam_write_entry(hw, blk, t->tcam[i].tcam_idx,
4639 t->tcam[i].ptg, vsig, 0, 0,
4640 vl_msk, dc_msk, nm_msk);
4642 goto err_ice_add_prof_id_vsig;
4645 LIST_ADD(&p->list_entry, chg);
4648 /* add profile to VSIG */
4650 &hw->blk[blk].xlt2.vsig_tbl[(vsig & ICE_VSIG_IDX_M)].prop_lst);
4654 err_ice_add_prof_id_vsig:
4655 /* let caller clean up the change list */
4657 return ICE_ERR_NO_MEMORY;
4661 * ice_create_prof_id_vsig - add a new VSIG with a single profile
4662 * @hw: pointer to the HW struct
4663 * @blk: hardware block
4664 * @vsi: the initial VSI that will be in VSIG
4665 * @hdl: the profile handle of the profile that will be added to the VSIG
4666 * @chg: the change list
4668 static enum ice_status
4669 ice_create_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl,
4670 struct LIST_HEAD_TYPE *chg)
4672 enum ice_status status;
4673 struct ice_chs_chg *p;
4676 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4678 return ICE_ERR_NO_MEMORY;
4680 new_vsig = ice_vsig_alloc(hw, blk);
4682 status = ICE_ERR_HW_TABLE;
4683 goto err_ice_create_prof_id_vsig;
4686 status = ice_move_vsi(hw, blk, vsi, new_vsig, chg);
4688 goto err_ice_create_prof_id_vsig;
4690 status = ice_add_prof_id_vsig(hw, blk, new_vsig, hdl, chg);
4692 goto err_ice_create_prof_id_vsig;
4694 p->type = ICE_VSIG_ADD;
4696 p->orig_vsig = ICE_DEFAULT_VSIG;
4699 LIST_ADD(&p->list_entry, chg);
4703 err_ice_create_prof_id_vsig:
4704 /* let caller clean up the change list */
4710 * ice_create_vsig_from_list - create a new VSIG with a list of profiles
4711 * @hw: pointer to the HW struct
4712 * @blk: hardware block
4713 * @vsi: the initial VSI that will be in VSIG
4714 * @lst: the list of profile that will be added to the VSIG
4715 * @chg: the change list
4717 static enum ice_status
4718 ice_create_vsig_from_lst(struct ice_hw *hw, enum ice_block blk, u16 vsi,
4719 struct LIST_HEAD_TYPE *lst, struct LIST_HEAD_TYPE *chg)
4721 struct ice_vsig_prof *t;
4722 enum ice_status status;
4725 vsig = ice_vsig_alloc(hw, blk);
4727 return ICE_ERR_HW_TABLE;
4729 status = ice_move_vsi(hw, blk, vsi, vsig, chg);
4733 LIST_FOR_EACH_ENTRY(t, lst, ice_vsig_prof, list) {
4734 status = ice_add_prof_id_vsig(hw, blk, vsig, t->profile_cookie,
4744 * ice_find_prof_vsig - find a VSIG with a specific profile handle
4745 * @hw: pointer to the HW struct
4746 * @blk: hardware block
4747 * @hdl: the profile handle of the profile to search for
4748 * @vsig: returns the VSIG with the matching profile
4751 ice_find_prof_vsig(struct ice_hw *hw, enum ice_block blk, u64 hdl, u16 *vsig)
4753 struct ice_vsig_prof *t;
4754 struct LIST_HEAD_TYPE lst;
4755 enum ice_status status;
4757 INIT_LIST_HEAD(&lst);
4759 t = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*t));
4763 t->profile_cookie = hdl;
4764 LIST_ADD(&t->list, &lst);
4766 status = ice_find_dup_props_vsig(hw, blk, &lst, vsig);
4771 return status == ICE_SUCCESS;
4775 * ice_add_prof_id_flow - add profile flow
4776 * @hw: pointer to the HW struct
4777 * @blk: hardware block
4778 * @vsi: the VSI to enable with the profile specified by ID
4779 * @hdl: profile handle
4781 * Calling this function will update the hardware tables to enable the
4782 * profile indicated by the ID parameter for the VSIs specified in the VSI
4783 * array. Once successfully called, the flow will be enabled.
4786 ice_add_prof_id_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl)
4788 struct ice_vsig_prof *tmp1, *del1;
4789 struct LIST_HEAD_TYPE union_lst;
4790 struct ice_chs_chg *tmp, *del;
4791 struct LIST_HEAD_TYPE chrs;
4792 struct LIST_HEAD_TYPE chg;
4793 enum ice_status status;
4794 u16 vsig, or_vsig = 0;
4796 INIT_LIST_HEAD(&union_lst);
4797 INIT_LIST_HEAD(&chrs);
4798 INIT_LIST_HEAD(&chg);
4800 status = ice_get_prof_ptgs(hw, blk, hdl, &chg);
4804 /* determine if VSI is already part of a VSIG */
4805 status = ice_vsig_find_vsi(hw, blk, vsi, &vsig);
4806 if (!status && vsig) {
4813 /* make sure that there is no overlap/conflict between the new
4814 * characteristics and the existing ones; we don't support that
4817 if (ice_has_prof_vsig(hw, blk, vsig, hdl)) {
4818 status = ICE_ERR_ALREADY_EXISTS;
4819 goto err_ice_add_prof_id_flow;
4822 /* last VSI in the VSIG? */
4823 status = ice_vsig_get_ref(hw, blk, vsig, &ref);
4825 goto err_ice_add_prof_id_flow;
4826 only_vsi = (ref == 1);
4828 /* create a union of the current profiles and the one being
4831 status = ice_get_profs_vsig(hw, blk, vsig, &union_lst);
4833 goto err_ice_add_prof_id_flow;
4835 status = ice_add_prof_to_lst(hw, blk, &union_lst, hdl);
4837 goto err_ice_add_prof_id_flow;
4839 /* search for an existing VSIG with an exact charc match */
4840 status = ice_find_dup_props_vsig(hw, blk, &union_lst, &vsig);
4842 /* move VSI to the VSIG that matches */
4843 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
4845 goto err_ice_add_prof_id_flow;
4847 /* VSI has been moved out of or_vsig. If the or_vsig had
4848 * only that VSI it is now empty and can be removed.
4851 status = ice_rem_vsig(hw, blk, or_vsig, &chg);
4853 goto err_ice_add_prof_id_flow;
4855 } else if (only_vsi) {
4856 /* If the original VSIG only contains one VSI, then it
4857 * will be the requesting VSI. In this case the VSI is
4858 * not sharing entries and we can simply add the new
4859 * profile to the VSIG.
4861 status = ice_add_prof_id_vsig(hw, blk, vsig, hdl, &chg);
4863 goto err_ice_add_prof_id_flow;
4865 /* Adjust priorities */
4866 status = ice_adj_prof_priorities(hw, blk, vsig, &chg);
4868 goto err_ice_add_prof_id_flow;
4870 /* No match, so we need a new VSIG */
4871 status = ice_create_vsig_from_lst(hw, blk, vsi,
4874 goto err_ice_add_prof_id_flow;
4876 /* Adjust priorities */
4877 status = ice_adj_prof_priorities(hw, blk, vsig, &chg);
4879 goto err_ice_add_prof_id_flow;
4882 /* need to find or add a VSIG */
4883 /* search for an existing VSIG with an exact charc match */
4884 if (ice_find_prof_vsig(hw, blk, hdl, &vsig)) {
4885 /* found an exact match */
4886 /* add or move VSI to the VSIG that matches */
4887 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
4889 goto err_ice_add_prof_id_flow;
4891 /* we did not find an exact match */
4892 /* we need to add a VSIG */
4893 status = ice_create_prof_id_vsig(hw, blk, vsi, hdl,
4896 goto err_ice_add_prof_id_flow;
4900 /* update hardware */
4902 status = ice_upd_prof_hw(hw, blk, &chg);
4904 err_ice_add_prof_id_flow:
4905 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
4906 LIST_DEL(&del->list_entry);
4910 LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, &union_lst, ice_vsig_prof, list) {
4911 LIST_DEL(&del1->list);
4915 LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, &chrs, ice_vsig_prof, list) {
4916 LIST_DEL(&del1->list);
4924 * ice_rem_prof_from_list - remove a profile from list
4925 * @hw: pointer to the HW struct
4926 * @lst: list to remove the profile from
4927 * @hdl: the profile handle indicating the profile to remove
4929 static enum ice_status
4930 ice_rem_prof_from_list(struct ice_hw *hw, struct LIST_HEAD_TYPE *lst, u64 hdl)
4932 struct ice_vsig_prof *ent, *tmp;
4934 LIST_FOR_EACH_ENTRY_SAFE(ent, tmp, lst, ice_vsig_prof, list) {
4935 if (ent->profile_cookie == hdl) {
4936 LIST_DEL(&ent->list);
4942 return ICE_ERR_DOES_NOT_EXIST;
4946 * ice_rem_prof_id_flow - remove flow
4947 * @hw: pointer to the HW struct
4948 * @blk: hardware block
4949 * @vsi: the VSI from which to remove the profile specified by ID
4950 * @hdl: profile tracking handle
4952 * Calling this function will update the hardware tables to remove the
4953 * profile indicated by the ID parameter for the VSIs specified in the VSI
4954 * array. Once successfully called, the flow will be disabled.
4957 ice_rem_prof_id_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl)
4959 struct ice_vsig_prof *tmp1, *del1;
4960 struct LIST_HEAD_TYPE chg, copy;
4961 struct ice_chs_chg *tmp, *del;
4962 enum ice_status status;
4965 INIT_LIST_HEAD(©);
4966 INIT_LIST_HEAD(&chg);
4968 /* determine if VSI is already part of a VSIG */
4969 status = ice_vsig_find_vsi(hw, blk, vsi, &vsig);
4970 if (!status && vsig) {
4976 last_profile = ice_vsig_prof_id_count(hw, blk, vsig) == 1;
4977 status = ice_vsig_get_ref(hw, blk, vsig, &ref);
4979 goto err_ice_rem_prof_id_flow;
4980 only_vsi = (ref == 1);
4983 /* If the original VSIG only contains one reference,
4984 * which will be the requesting VSI, then the VSI is not
4985 * sharing entries and we can simply remove the specific
4986 * characteristics from the VSIG.
4990 /* If there are no profiles left for this VSIG,
4991 * then simply remove the the VSIG.
4993 status = ice_rem_vsig(hw, blk, vsig, &chg);
4995 goto err_ice_rem_prof_id_flow;
4997 status = ice_rem_prof_id_vsig(hw, blk, vsig,
5000 goto err_ice_rem_prof_id_flow;
5002 /* Adjust priorities */
5003 status = ice_adj_prof_priorities(hw, blk, vsig,
5006 goto err_ice_rem_prof_id_flow;
5010 /* Make a copy of the VSIG's list of Profiles */
5011 status = ice_get_profs_vsig(hw, blk, vsig, ©);
5013 goto err_ice_rem_prof_id_flow;
5015 /* Remove specified profile entry from the list */
5016 status = ice_rem_prof_from_list(hw, ©, hdl);
5018 goto err_ice_rem_prof_id_flow;
5020 if (LIST_EMPTY(©)) {
5021 status = ice_move_vsi(hw, blk, vsi,
5022 ICE_DEFAULT_VSIG, &chg);
5024 goto err_ice_rem_prof_id_flow;
5026 } else if (!ice_find_dup_props_vsig(hw, blk, ©,
5028 /* found an exact match */
5029 /* add or move VSI to the VSIG that matches */
5030 /* Search for a VSIG with a matching profile
5034 /* Found match, move VSI to the matching VSIG */
5035 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5037 goto err_ice_rem_prof_id_flow;
5039 /* since no existing VSIG supports this
5040 * characteristic pattern, we need to create a
5041 * new VSIG and TCAM entries
5043 status = ice_create_vsig_from_lst(hw, blk, vsi,
5046 goto err_ice_rem_prof_id_flow;
5048 /* Adjust priorities */
5049 status = ice_adj_prof_priorities(hw, blk, vsig,
5052 goto err_ice_rem_prof_id_flow;
5056 status = ICE_ERR_DOES_NOT_EXIST;
5059 /* update hardware tables */
5061 status = ice_upd_prof_hw(hw, blk, &chg);
5063 err_ice_rem_prof_id_flow:
5064 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
5065 LIST_DEL(&del->list_entry);
5069 LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, ©, ice_vsig_prof, list) {
5070 LIST_DEL(&del1->list);