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 static const struct ice_tunnel_type_scan tnls[] = {
11 { TNL_VXLAN, "TNL_VXLAN" },
12 { TNL_GTPC, "TNL_GTPC" },
13 { TNL_GTPC_TEID, "TNL_GTPC_TEID" },
14 { TNL_GTPU, "TNL_GTPC" },
15 { TNL_GTPU_TEID, "TNL_GTPU_TEID" },
16 { TNL_VXLAN_GPE, "TNL_VXLAN_GPE" },
17 { TNL_GENEVE, "TNL_GENEVE" },
18 { TNL_NAT, "TNL_NAT" },
19 { TNL_ROCE_V2, "TNL_ROCE_V2" },
20 { TNL_MPLSO_UDP, "TNL_MPLSO_UDP" },
21 { TNL_UDP2_END, "TNL_UDP2_END" },
22 { TNL_UPD_END, "TNL_UPD_END" },
26 static const u32 ice_sect_lkup[ICE_BLK_COUNT][ICE_SECT_COUNT] = {
30 ICE_SID_XLT_KEY_BUILDER_SW,
33 ICE_SID_PROFID_TCAM_SW,
34 ICE_SID_PROFID_REDIR_SW,
36 ICE_SID_CDID_KEY_BUILDER_SW,
43 ICE_SID_XLT_KEY_BUILDER_ACL,
46 ICE_SID_PROFID_TCAM_ACL,
47 ICE_SID_PROFID_REDIR_ACL,
49 ICE_SID_CDID_KEY_BUILDER_ACL,
50 ICE_SID_CDID_REDIR_ACL
56 ICE_SID_XLT_KEY_BUILDER_FD,
59 ICE_SID_PROFID_TCAM_FD,
60 ICE_SID_PROFID_REDIR_FD,
62 ICE_SID_CDID_KEY_BUILDER_FD,
69 ICE_SID_XLT_KEY_BUILDER_RSS,
72 ICE_SID_PROFID_TCAM_RSS,
73 ICE_SID_PROFID_REDIR_RSS,
75 ICE_SID_CDID_KEY_BUILDER_RSS,
76 ICE_SID_CDID_REDIR_RSS
82 ICE_SID_XLT_KEY_BUILDER_PE,
85 ICE_SID_PROFID_TCAM_PE,
86 ICE_SID_PROFID_REDIR_PE,
88 ICE_SID_CDID_KEY_BUILDER_PE,
94 * ice_sect_id - returns section ID
98 * This helper function returns the proper section ID given a block type and a
101 static u32 ice_sect_id(enum ice_block blk, enum ice_sect sect)
103 return ice_sect_lkup[blk][sect];
108 * @buf: pointer to the ice buffer
110 * This helper function validates a buffer's header.
112 static struct ice_buf_hdr *ice_pkg_val_buf(struct ice_buf *buf)
114 struct ice_buf_hdr *hdr;
118 hdr = (struct ice_buf_hdr *)buf->buf;
120 section_count = LE16_TO_CPU(hdr->section_count);
121 if (section_count < ICE_MIN_S_COUNT || section_count > ICE_MAX_S_COUNT)
124 data_end = LE16_TO_CPU(hdr->data_end);
125 if (data_end < ICE_MIN_S_DATA_END || data_end > ICE_MAX_S_DATA_END)
133 * @ice_seg: pointer to the ice segment
135 * Returns the address of the buffer table within the ice segment.
137 static struct ice_buf_table *ice_find_buf_table(struct ice_seg *ice_seg)
139 struct ice_nvm_table *nvms;
141 nvms = (struct ice_nvm_table *)(ice_seg->device_table +
142 LE32_TO_CPU(ice_seg->device_table_count));
144 return (struct ice_buf_table *)
145 (nvms->vers + LE32_TO_CPU(nvms->table_count));
150 * @ice_seg: pointer to the ice segment (or NULL on subsequent calls)
151 * @state: pointer to the enum state
153 * This function will enumerate all the buffers in the ice segment. The first
154 * call is made with the ice_seg parameter non-NULL; on subsequent calls,
155 * ice_seg is set to NULL which continues the enumeration. When the function
156 * returns a NULL pointer, then the end of the buffers has been reached, or an
157 * unexpected value has been detected (for example an invalid section count or
158 * an invalid buffer end value).
160 static struct ice_buf_hdr *
161 ice_pkg_enum_buf(struct ice_seg *ice_seg, struct ice_pkg_enum *state)
164 state->buf_table = ice_find_buf_table(ice_seg);
165 if (!state->buf_table)
169 return ice_pkg_val_buf(state->buf_table->buf_array);
172 if (++state->buf_idx < LE32_TO_CPU(state->buf_table->buf_count))
173 return ice_pkg_val_buf(state->buf_table->buf_array +
180 * ice_pkg_advance_sect
181 * @ice_seg: pointer to the ice segment (or NULL on subsequent calls)
182 * @state: pointer to the enum state
184 * This helper function will advance the section within the ice segment,
185 * also advancing the buffer if needed.
188 ice_pkg_advance_sect(struct ice_seg *ice_seg, struct ice_pkg_enum *state)
190 if (!ice_seg && !state->buf)
193 if (!ice_seg && state->buf)
194 if (++state->sect_idx < LE16_TO_CPU(state->buf->section_count))
197 state->buf = ice_pkg_enum_buf(ice_seg, state);
201 /* start of new buffer, reset section index */
207 * ice_pkg_enum_section
208 * @ice_seg: pointer to the ice segment (or NULL on subsequent calls)
209 * @state: pointer to the enum state
210 * @sect_type: section type to enumerate
212 * This function will enumerate all the sections of a particular type in the
213 * ice segment. The first call is made with the ice_seg parameter non-NULL;
214 * on subsequent calls, ice_seg is set to NULL which continues the enumeration.
215 * When the function returns a NULL pointer, then the end of the matching
216 * sections has been reached.
219 ice_pkg_enum_section(struct ice_seg *ice_seg, struct ice_pkg_enum *state,
225 state->type = sect_type;
227 if (!ice_pkg_advance_sect(ice_seg, state))
230 /* scan for next matching section */
231 while (state->buf->section_entry[state->sect_idx].type !=
232 CPU_TO_LE32(state->type))
233 if (!ice_pkg_advance_sect(NULL, state))
236 /* validate section */
237 offset = LE16_TO_CPU(state->buf->section_entry[state->sect_idx].offset);
238 if (offset < ICE_MIN_S_OFF || offset > ICE_MAX_S_OFF)
241 size = LE16_TO_CPU(state->buf->section_entry[state->sect_idx].size);
242 if (size < ICE_MIN_S_SZ || size > ICE_MAX_S_SZ)
245 /* make sure the section fits in the buffer */
246 if (offset + size > ICE_PKG_BUF_SIZE)
250 LE32_TO_CPU(state->buf->section_entry[state->sect_idx].type);
252 /* calc pointer to this section */
253 state->sect = ((u8 *)state->buf) +
254 LE16_TO_CPU(state->buf->section_entry[state->sect_idx].offset);
261 * @ice_seg: pointer to the ice segment (or NULL on subsequent calls)
262 * @state: pointer to the enum state
263 * @sect_type: section type to enumerate
264 * @offset: pointer to variable that receives the offset in the table (optional)
265 * @handler: function that handles access to the entries into the section type
267 * This function will enumerate all the entries in particular section type in
268 * the ice segment. The first call is made with the ice_seg parameter non-NULL;
269 * on subsequent calls, ice_seg is set to NULL which continues the enumeration.
270 * When the function returns a NULL pointer, then the end of the entries has
273 * Since each section may have a different header and entry size, the handler
274 * function is needed to determine the number and location entries in each
277 * The offset parameter is optional, but should be used for sections that
278 * contain an offset for each section table. For such cases, the section handler
279 * function must return the appropriate offset + index to give the absolution
280 * offset for each entry. For example, if the base for a section's header
281 * indicates a base offset of 10, and the index for the entry is 2, then
282 * section handler function should set the offset to 10 + 2 = 12.
285 ice_pkg_enum_entry(struct ice_seg *ice_seg, struct ice_pkg_enum *state,
286 u32 sect_type, u32 *offset,
287 void *(*handler)(u32 sect_type, void *section,
288 u32 index, u32 *offset))
296 if (!ice_pkg_enum_section(ice_seg, state, sect_type))
299 state->entry_idx = 0;
300 state->handler = handler;
309 entry = state->handler(state->sect_type, state->sect, state->entry_idx,
312 /* end of a section, look for another section of this type */
313 if (!ice_pkg_enum_section(NULL, state, 0))
316 state->entry_idx = 0;
317 entry = state->handler(state->sect_type, state->sect,
318 state->entry_idx, offset);
325 * ice_boost_tcam_handler
326 * @sect_type: section type
327 * @section: pointer to section
328 * @index: index of the boost TCAM entry to be returned
329 * @offset: pointer to receive absolute offset, always 0 for boost TCAM sections
331 * This is a callback function that can be passed to ice_pkg_enum_entry.
332 * Handles enumeration of individual boost TCAM entries.
335 ice_boost_tcam_handler(u32 sect_type, void *section, u32 index, u32 *offset)
337 struct ice_boost_tcam_section *boost;
342 if (sect_type != ICE_SID_RXPARSER_BOOST_TCAM)
345 if (index > ICE_MAX_BST_TCAMS_IN_BUF)
351 boost = (struct ice_boost_tcam_section *)section;
352 if (index >= LE16_TO_CPU(boost->count))
355 return boost->tcam + index;
359 * ice_find_boost_entry
360 * @ice_seg: pointer to the ice segment (non-NULL)
361 * @addr: Boost TCAM address of entry to search for
362 * @entry: returns pointer to the entry
364 * Finds a particular Boost TCAM entry and returns a pointer to that entry
365 * if it is found. The ice_seg parameter must not be NULL since the first call
366 * to ice_pkg_enum_entry requires a pointer to an actual ice_segment structure.
368 static enum ice_status
369 ice_find_boost_entry(struct ice_seg *ice_seg, u16 addr,
370 struct ice_boost_tcam_entry **entry)
372 struct ice_boost_tcam_entry *tcam;
373 struct ice_pkg_enum state;
375 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
378 return ICE_ERR_PARAM;
381 tcam = (struct ice_boost_tcam_entry *)
382 ice_pkg_enum_entry(ice_seg, &state,
383 ICE_SID_RXPARSER_BOOST_TCAM, NULL,
384 ice_boost_tcam_handler);
385 if (tcam && LE16_TO_CPU(tcam->addr) == addr) {
398 * ice_label_enum_handler
399 * @sect_type: section type
400 * @section: pointer to section
401 * @index: index of the label entry to be returned
402 * @offset: pointer to receive absolute offset, always zero for label sections
404 * This is a callback function that can be passed to ice_pkg_enum_entry.
405 * Handles enumeration of individual label entries.
408 ice_label_enum_handler(u32 __always_unused sect_type, void *section, u32 index,
411 struct ice_label_section *labels;
416 if (index > ICE_MAX_LABELS_IN_BUF)
422 labels = (struct ice_label_section *)section;
423 if (index >= LE16_TO_CPU(labels->count))
426 return labels->label + index;
431 * @ice_seg: pointer to the ice segment (NULL on subsequent calls)
432 * @type: the section type that will contain the label (0 on subsequent calls)
433 * @state: ice_pkg_enum structure that will hold the state of the enumeration
434 * @value: pointer to a value that will return the label's value if found
436 * Enumerates a list of labels in the package. The caller will call
437 * ice_enum_labels(ice_seg, type, ...) to start the enumeration, then call
438 * ice_enum_labels(NULL, 0, ...) to continue. When the function returns a NULL
439 * the end of the list has been reached.
442 ice_enum_labels(struct ice_seg *ice_seg, u32 type, struct ice_pkg_enum *state,
445 struct ice_label *label;
447 /* Check for valid label section on first call */
448 if (type && !(type >= ICE_SID_LBL_FIRST && type <= ICE_SID_LBL_LAST))
451 label = (struct ice_label *)ice_pkg_enum_entry(ice_seg, state, type,
453 ice_label_enum_handler);
457 *value = LE16_TO_CPU(label->value);
463 * @hw: pointer to the HW structure
464 * @ice_seg: pointer to the segment of the package scan (non-NULL)
466 * This function will scan the package and save off relevant information
467 * (hints or metadata) for driver use. The ice_seg parameter must not be NULL
468 * since the first call to ice_enum_labels requires a pointer to an actual
471 void ice_init_pkg_hints(struct ice_hw *hw, struct ice_seg *ice_seg)
473 struct ice_pkg_enum state;
478 ice_memset(&hw->tnl, 0, sizeof(hw->tnl), ICE_NONDMA_MEM);
483 label_name = ice_enum_labels(ice_seg, ICE_SID_LBL_RXPARSER_TMEM, &state,
486 while (label_name && hw->tnl.count < ICE_TUNNEL_MAX_ENTRIES) {
487 for (i = 0; tnls[i].type != TNL_LAST; i++) {
488 if (!strncmp(label_name, tnls[i].label_prefix,
489 strlen(tnls[i].label_prefix))) {
490 hw->tnl.tbl[hw->tnl.count].type = tnls[i].type;
491 hw->tnl.tbl[hw->tnl.count].valid = false;
492 hw->tnl.tbl[hw->tnl.count].in_use = false;
493 hw->tnl.tbl[hw->tnl.count].marked = false;
494 hw->tnl.tbl[hw->tnl.count].boost_addr = val;
495 hw->tnl.tbl[hw->tnl.count].port = 0;
501 label_name = ice_enum_labels(NULL, 0, &state, &val);
504 /* Cache the appropriate boost TCAM entry pointers */
505 for (i = 0; i < hw->tnl.count; i++) {
506 ice_find_boost_entry(ice_seg, hw->tnl.tbl[i].boost_addr,
507 &hw->tnl.tbl[i].boost_entry);
508 if (hw->tnl.tbl[i].boost_entry)
509 hw->tnl.tbl[i].valid = true;
515 #define ICE_DC_KEY 0x1 /* don't care */
516 #define ICE_DC_KEYINV 0x1
517 #define ICE_NM_KEY 0x0 /* never match */
518 #define ICE_NM_KEYINV 0x0
519 #define ICE_0_KEY 0x1 /* match 0 */
520 #define ICE_0_KEYINV 0x0
521 #define ICE_1_KEY 0x0 /* match 1 */
522 #define ICE_1_KEYINV 0x1
525 * ice_gen_key_word - generate 16-bits of a key/mask word
527 * @valid: valid bits mask (change only the valid bits)
528 * @dont_care: don't care mask
529 * @nvr_mtch: never match mask
530 * @key: pointer to an array of where the resulting key portion
531 * @key_inv: pointer to an array of where the resulting key invert portion
533 * This function generates 16-bits from a 8-bit value, an 8-bit don't care mask
534 * and an 8-bit never match mask. The 16-bits of output are divided into 8 bits
535 * of key and 8 bits of key invert.
537 * '0' = b01, always match a 0 bit
538 * '1' = b10, always match a 1 bit
539 * '?' = b11, don't care bit (always matches)
540 * '~' = b00, never match bit
544 * dont_care: b0 0 1 1 0 0
545 * never_mtch: b0 0 0 0 1 1
546 * ------------------------------
547 * Result: key: b01 10 11 11 00 00
549 static enum ice_status
550 ice_gen_key_word(u8 val, u8 valid, u8 dont_care, u8 nvr_mtch, u8 *key,
553 u8 in_key = *key, in_key_inv = *key_inv;
556 /* 'dont_care' and 'nvr_mtch' masks cannot overlap */
557 if ((dont_care ^ nvr_mtch) != (dont_care | nvr_mtch))
563 /* encode the 8 bits into 8-bit key and 8-bit key invert */
564 for (i = 0; i < 8; i++) {
568 if (!(valid & 0x1)) { /* change only valid bits */
569 *key |= (in_key & 0x1) << 7;
570 *key_inv |= (in_key_inv & 0x1) << 7;
571 } else if (dont_care & 0x1) { /* don't care bit */
572 *key |= ICE_DC_KEY << 7;
573 *key_inv |= ICE_DC_KEYINV << 7;
574 } else if (nvr_mtch & 0x1) { /* never match bit */
575 *key |= ICE_NM_KEY << 7;
576 *key_inv |= ICE_NM_KEYINV << 7;
577 } else if (val & 0x01) { /* exact 1 match */
578 *key |= ICE_1_KEY << 7;
579 *key_inv |= ICE_1_KEYINV << 7;
580 } else { /* exact 0 match */
581 *key |= ICE_0_KEY << 7;
582 *key_inv |= ICE_0_KEYINV << 7;
597 * ice_bits_max_set - determine if the number of bits set is within a maximum
598 * @mask: pointer to the byte array which is the mask
599 * @size: the number of bytes in the mask
600 * @max: the max number of set bits
602 * This function determines if there are at most 'max' number of bits set in an
603 * array. Returns true if the number for bits set is <= max or will return false
606 static bool ice_bits_max_set(const u8 *mask, u16 size, u16 max)
611 /* check each byte */
612 for (i = 0; i < size; i++) {
613 /* if 0, go to next byte */
617 /* We know there is at least one set bit in this byte because of
618 * the above check; if we already have found 'max' number of
619 * bits set, then we can return failure now.
624 /* count the bits in this byte, checking threshold */
625 for (j = 0; j < BITS_PER_BYTE; j++) {
626 count += (mask[i] & (0x1 << j)) ? 1 : 0;
636 * ice_set_key - generate a variable sized key with multiples of 16-bits
637 * @key: pointer to where the key will be stored
638 * @size: the size of the complete key in bytes (must be even)
639 * @val: array of 8-bit values that makes up the value portion of the key
640 * @upd: array of 8-bit masks that determine what key portion to update
641 * @dc: array of 8-bit masks that make up the dont' care mask
642 * @nm: array of 8-bit masks that make up the never match mask
643 * @off: the offset of the first byte in the key to update
644 * @len: the number of bytes in the key update
646 * This function generates a key from a value, a don't care mask and a never
648 * upd, dc, and nm are optional parameters, and can be NULL:
649 * upd == NULL --> udp mask is all 1's (update all bits)
650 * dc == NULL --> dc mask is all 0's (no don't care bits)
651 * nm == NULL --> nm mask is all 0's (no never match bits)
654 ice_set_key(u8 *key, u16 size, u8 *val, u8 *upd, u8 *dc, u8 *nm, u16 off,
660 /* size must be a multiple of 2 bytes. */
663 half_size = size / 2;
665 if (off + len > half_size)
668 /* Make sure at most one bit is set in the never match mask. Having more
669 * than one never match mask bit set will cause HW to consume excessive
670 * power otherwise; this is a power management efficiency check.
672 #define ICE_NVR_MTCH_BITS_MAX 1
673 if (nm && !ice_bits_max_set(nm, len, ICE_NVR_MTCH_BITS_MAX))
676 for (i = 0; i < len; i++)
677 if (ice_gen_key_word(val[i], upd ? upd[i] : 0xff,
678 dc ? dc[i] : 0, nm ? nm[i] : 0,
679 key + off + i, key + half_size + off + i))
686 * ice_acquire_global_cfg_lock
687 * @hw: pointer to the HW structure
688 * @access: access type (read or write)
690 * This function will request ownership of the global config lock for reading
691 * or writing of the package. When attempting to obtain write access, the
692 * caller must check for the following two return values:
694 * ICE_SUCCESS - Means the caller has acquired the global config lock
695 * and can perform writing of the package.
696 * ICE_ERR_AQ_NO_WORK - Indicates another driver has already written the
697 * package or has found that no update was necessary; in
698 * this case, the caller can just skip performing any
699 * update of the package.
701 static enum ice_status
702 ice_acquire_global_cfg_lock(struct ice_hw *hw,
703 enum ice_aq_res_access_type access)
705 enum ice_status status;
707 ice_debug(hw, ICE_DBG_TRACE, "ice_acquire_global_cfg_lock");
709 status = ice_acquire_res(hw, ICE_GLOBAL_CFG_LOCK_RES_ID, access,
710 ICE_GLOBAL_CFG_LOCK_TIMEOUT);
712 if (status == ICE_ERR_AQ_NO_WORK)
713 ice_debug(hw, ICE_DBG_PKG,
714 "Global config lock: No work to do\n");
720 * ice_release_global_cfg_lock
721 * @hw: pointer to the HW structure
723 * This function will release the global config lock.
725 static void ice_release_global_cfg_lock(struct ice_hw *hw)
727 ice_release_res(hw, ICE_GLOBAL_CFG_LOCK_RES_ID);
731 * ice_acquire_change_lock
732 * @hw: pointer to the HW structure
733 * @access: access type (read or write)
735 * This function will request ownership of the change lock.
737 static enum ice_status
738 ice_acquire_change_lock(struct ice_hw *hw, enum ice_aq_res_access_type access)
740 ice_debug(hw, ICE_DBG_TRACE, "ice_acquire_change_lock");
742 return ice_acquire_res(hw, ICE_CHANGE_LOCK_RES_ID, access,
743 ICE_CHANGE_LOCK_TIMEOUT);
747 * ice_release_change_lock
748 * @hw: pointer to the HW structure
750 * This function will release the change lock using the proper Admin Command.
752 static void ice_release_change_lock(struct ice_hw *hw)
754 ice_debug(hw, ICE_DBG_TRACE, "ice_release_change_lock");
756 ice_release_res(hw, ICE_CHANGE_LOCK_RES_ID);
760 * ice_aq_download_pkg
761 * @hw: pointer to the hardware structure
762 * @pkg_buf: the package buffer to transfer
763 * @buf_size: the size of the package buffer
764 * @last_buf: last buffer indicator
765 * @error_offset: returns error offset
766 * @error_info: returns error information
767 * @cd: pointer to command details structure or NULL
769 * Download Package (0x0C40)
771 static enum ice_status
772 ice_aq_download_pkg(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf,
773 u16 buf_size, bool last_buf, u32 *error_offset,
774 u32 *error_info, struct ice_sq_cd *cd)
776 struct ice_aqc_download_pkg *cmd;
777 struct ice_aq_desc desc;
778 enum ice_status status;
780 ice_debug(hw, ICE_DBG_TRACE, "ice_aq_download_pkg");
787 cmd = &desc.params.download_pkg;
788 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_download_pkg);
789 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
792 cmd->flags |= ICE_AQC_DOWNLOAD_PKG_LAST_BUF;
794 status = ice_aq_send_cmd(hw, &desc, pkg_buf, buf_size, cd);
795 if (status == ICE_ERR_AQ_ERROR) {
796 /* Read error from buffer only when the FW returned an error */
797 struct ice_aqc_download_pkg_resp *resp;
799 resp = (struct ice_aqc_download_pkg_resp *)pkg_buf;
801 *error_offset = LE32_TO_CPU(resp->error_offset);
803 *error_info = LE32_TO_CPU(resp->error_info);
810 * ice_aq_upload_section
811 * @hw: pointer to the hardware structure
812 * @pkg_buf: the package buffer which will receive the section
813 * @buf_size: the size of the package buffer
814 * @cd: pointer to command details structure or NULL
816 * Upload Section (0x0C41)
819 ice_aq_upload_section(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf,
820 u16 buf_size, struct ice_sq_cd *cd)
822 struct ice_aq_desc desc;
824 ice_debug(hw, ICE_DBG_TRACE, "ice_aq_upload_section");
825 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_upload_section);
826 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
828 return ice_aq_send_cmd(hw, &desc, pkg_buf, buf_size, cd);
833 * @hw: pointer to the hardware structure
834 * @pkg_buf: the package cmd buffer
835 * @buf_size: the size of the package cmd buffer
836 * @last_buf: last buffer indicator
837 * @error_offset: returns error offset
838 * @error_info: returns error information
839 * @cd: pointer to command details structure or NULL
841 * Update Package (0x0C42)
843 static enum ice_status
844 ice_aq_update_pkg(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf, u16 buf_size,
845 bool last_buf, u32 *error_offset, u32 *error_info,
846 struct ice_sq_cd *cd)
848 struct ice_aqc_download_pkg *cmd;
849 struct ice_aq_desc desc;
850 enum ice_status status;
852 ice_debug(hw, ICE_DBG_TRACE, "ice_aq_update_pkg");
859 cmd = &desc.params.download_pkg;
860 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_update_pkg);
861 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
864 cmd->flags |= ICE_AQC_DOWNLOAD_PKG_LAST_BUF;
866 status = ice_aq_send_cmd(hw, &desc, pkg_buf, buf_size, cd);
867 if (status == ICE_ERR_AQ_ERROR) {
868 /* Read error from buffer only when the FW returned an error */
869 struct ice_aqc_download_pkg_resp *resp;
871 resp = (struct ice_aqc_download_pkg_resp *)pkg_buf;
873 *error_offset = LE32_TO_CPU(resp->error_offset);
875 *error_info = LE32_TO_CPU(resp->error_info);
882 * ice_find_seg_in_pkg
883 * @hw: pointer to the hardware structure
884 * @seg_type: the segment type to search for (i.e., SEGMENT_TYPE_CPK)
885 * @pkg_hdr: pointer to the package header to be searched
887 * This function searches a package file for a particular segment type. On
888 * success it returns a pointer to the segment header, otherwise it will
891 struct ice_generic_seg_hdr *
892 ice_find_seg_in_pkg(struct ice_hw *hw, u32 seg_type,
893 struct ice_pkg_hdr *pkg_hdr)
897 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
898 ice_debug(hw, ICE_DBG_PKG, "Package version: %d.%d.%d.%d\n",
899 pkg_hdr->format_ver.major, pkg_hdr->format_ver.minor,
900 pkg_hdr->format_ver.update, pkg_hdr->format_ver.draft);
902 /* Search all package segments for the requested segment type */
903 for (i = 0; i < LE32_TO_CPU(pkg_hdr->seg_count); i++) {
904 struct ice_generic_seg_hdr *seg;
906 seg = (struct ice_generic_seg_hdr *)
907 ((u8 *)pkg_hdr + LE32_TO_CPU(pkg_hdr->seg_offset[i]));
909 if (LE32_TO_CPU(seg->seg_type) == seg_type)
918 * @hw: pointer to the hardware structure
919 * @bufs: pointer to an array of buffers
920 * @count: the number of buffers in the array
922 * Obtains change lock and updates package.
925 ice_update_pkg(struct ice_hw *hw, struct ice_buf *bufs, u32 count)
927 enum ice_status status;
930 status = ice_acquire_change_lock(hw, ICE_RES_WRITE);
934 for (i = 0; i < count; i++) {
935 bool last = ((i + 1) == count);
937 struct ice_buf_hdr *bh = (struct ice_buf_hdr *)(bufs + i);
939 status = ice_aq_update_pkg(hw, bh, LE16_TO_CPU(bh->data_end),
940 last, &offset, &info, NULL);
943 ice_debug(hw, ICE_DBG_PKG,
944 "Update pkg failed: err %d off %d inf %d\n",
945 status, offset, info);
950 ice_release_change_lock(hw);
957 * @hw: pointer to the hardware structure
958 * @bufs: pointer to an array of buffers
959 * @count: the number of buffers in the array
961 * Obtains global config lock and downloads the package configuration buffers
962 * to the firmware. Metadata buffers are skipped, and the first metadata buffer
963 * found indicates that the rest of the buffers are all metadata buffers.
965 static enum ice_status
966 ice_dwnld_cfg_bufs(struct ice_hw *hw, struct ice_buf *bufs, u32 count)
968 enum ice_status status;
969 struct ice_buf_hdr *bh;
973 return ICE_ERR_PARAM;
975 /* If the first buffer's first section has its metadata bit set
976 * then there are no buffers to be downloaded, and the operation is
977 * considered a success.
979 bh = (struct ice_buf_hdr *)bufs;
980 if (LE32_TO_CPU(bh->section_entry[0].type) & ICE_METADATA_BUF)
983 status = ice_acquire_global_cfg_lock(hw, ICE_RES_WRITE);
987 for (i = 0; i < count; i++) {
988 bool last = ((i + 1) == count);
991 /* check next buffer for metadata flag */
992 bh = (struct ice_buf_hdr *)(bufs + i + 1);
994 /* A set metadata flag in the next buffer will signal
995 * that the current buffer will be the last buffer
998 if (LE16_TO_CPU(bh->section_count))
999 if (LE32_TO_CPU(bh->section_entry[0].type) &
1004 bh = (struct ice_buf_hdr *)(bufs + i);
1006 status = ice_aq_download_pkg(hw, bh, LE16_TO_CPU(bh->data_end),
1007 last, &offset, &info, NULL);
1010 ice_debug(hw, ICE_DBG_PKG,
1011 "Pkg download failed: err %d off %d inf %d\n",
1012 status, offset, info);
1020 ice_release_global_cfg_lock(hw);
1026 * ice_aq_get_pkg_info_list
1027 * @hw: pointer to the hardware structure
1028 * @pkg_info: the buffer which will receive the information list
1029 * @buf_size: the size of the pkg_info information buffer
1030 * @cd: pointer to command details structure or NULL
1032 * Get Package Info List (0x0C43)
1034 static enum ice_status
1035 ice_aq_get_pkg_info_list(struct ice_hw *hw,
1036 struct ice_aqc_get_pkg_info_resp *pkg_info,
1037 u16 buf_size, struct ice_sq_cd *cd)
1039 struct ice_aq_desc desc;
1041 ice_debug(hw, ICE_DBG_TRACE, "ice_aq_get_pkg_info_list");
1042 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_pkg_info_list);
1044 return ice_aq_send_cmd(hw, &desc, pkg_info, buf_size, cd);
1049 * @hw: pointer to the hardware structure
1050 * @ice_seg: pointer to the segment of the package to be downloaded
1052 * Handles the download of a complete package.
1054 enum ice_status ice_download_pkg(struct ice_hw *hw, struct ice_seg *ice_seg)
1056 struct ice_buf_table *ice_buf_tbl;
1058 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1059 ice_debug(hw, ICE_DBG_PKG, "Segment version: %d.%d.%d.%d\n",
1060 ice_seg->hdr.seg_ver.major, ice_seg->hdr.seg_ver.minor,
1061 ice_seg->hdr.seg_ver.update, ice_seg->hdr.seg_ver.draft);
1063 ice_debug(hw, ICE_DBG_PKG, "Seg: type 0x%X, size %d, name %s\n",
1064 LE32_TO_CPU(ice_seg->hdr.seg_type),
1065 LE32_TO_CPU(ice_seg->hdr.seg_size), ice_seg->hdr.seg_name);
1067 ice_buf_tbl = ice_find_buf_table(ice_seg);
1069 ice_debug(hw, ICE_DBG_PKG, "Seg buf count: %d\n",
1070 LE32_TO_CPU(ice_buf_tbl->buf_count));
1072 return ice_dwnld_cfg_bufs(hw, ice_buf_tbl->buf_array,
1073 LE32_TO_CPU(ice_buf_tbl->buf_count));
1078 * @hw: pointer to the hardware structure
1079 * @pkg_hdr: pointer to the driver's package hdr
1081 * Saves off the package details into the HW structure.
1084 ice_init_pkg_info(struct ice_hw *hw, struct ice_pkg_hdr *pkg_hdr)
1086 struct ice_aqc_get_pkg_info_resp *pkg_info;
1087 struct ice_global_metadata_seg *meta_seg;
1088 struct ice_generic_seg_hdr *seg_hdr;
1089 enum ice_status status;
1093 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1095 return ICE_ERR_PARAM;
1097 meta_seg = (struct ice_global_metadata_seg *)
1098 ice_find_seg_in_pkg(hw, SEGMENT_TYPE_METADATA, pkg_hdr);
1100 hw->pkg_ver = meta_seg->pkg_ver;
1101 ice_memcpy(hw->pkg_name, meta_seg->pkg_name,
1102 sizeof(hw->pkg_name), ICE_NONDMA_TO_NONDMA);
1104 ice_debug(hw, ICE_DBG_PKG, "Pkg: %d.%d.%d.%d, %s\n",
1105 meta_seg->pkg_ver.major, meta_seg->pkg_ver.minor,
1106 meta_seg->pkg_ver.update, meta_seg->pkg_ver.draft,
1107 meta_seg->pkg_name);
1109 ice_debug(hw, ICE_DBG_INIT,
1110 "Did not find metadata segment in driver package\n");
1114 seg_hdr = ice_find_seg_in_pkg(hw, SEGMENT_TYPE_ICE, pkg_hdr);
1116 hw->ice_pkg_ver = seg_hdr->seg_ver;
1117 ice_memcpy(hw->ice_pkg_name, seg_hdr->seg_name,
1118 sizeof(hw->ice_pkg_name), ICE_NONDMA_TO_NONDMA);
1120 ice_debug(hw, ICE_DBG_PKG, "Ice Pkg: %d.%d.%d.%d, %s\n",
1121 seg_hdr->seg_ver.major, seg_hdr->seg_ver.minor,
1122 seg_hdr->seg_ver.update, seg_hdr->seg_ver.draft,
1125 ice_debug(hw, ICE_DBG_INIT,
1126 "Did not find ice segment in driver package\n");
1130 #define ICE_PKG_CNT 4
1131 size = sizeof(*pkg_info) + (sizeof(pkg_info->pkg_info[0]) *
1133 pkg_info = (struct ice_aqc_get_pkg_info_resp *)ice_malloc(hw, size);
1135 return ICE_ERR_NO_MEMORY;
1137 status = ice_aq_get_pkg_info_list(hw, pkg_info, size, NULL);
1139 goto init_pkg_free_alloc;
1141 for (i = 0; i < LE32_TO_CPU(pkg_info->count); i++) {
1142 #define ICE_PKG_FLAG_COUNT 4
1143 char flags[ICE_PKG_FLAG_COUNT + 1] = { 0 };
1146 if (pkg_info->pkg_info[i].is_active) {
1147 flags[place++] = 'A';
1148 hw->active_pkg_ver = pkg_info->pkg_info[i].ver;
1149 ice_memcpy(hw->active_pkg_name,
1150 pkg_info->pkg_info[i].name,
1151 sizeof(hw->active_pkg_name),
1152 ICE_NONDMA_TO_NONDMA);
1154 if (pkg_info->pkg_info[i].is_active_at_boot)
1155 flags[place++] = 'B';
1156 if (pkg_info->pkg_info[i].is_modified)
1157 flags[place++] = 'M';
1158 if (pkg_info->pkg_info[i].is_in_nvm)
1159 flags[place++] = 'N';
1161 ice_debug(hw, ICE_DBG_PKG, "Pkg[%d]: %d.%d.%d.%d,%s,%s\n",
1162 i, pkg_info->pkg_info[i].ver.major,
1163 pkg_info->pkg_info[i].ver.minor,
1164 pkg_info->pkg_info[i].ver.update,
1165 pkg_info->pkg_info[i].ver.draft,
1166 pkg_info->pkg_info[i].name, flags);
1169 init_pkg_free_alloc:
1170 ice_free(hw, pkg_info);
1176 * ice_find_label_value
1177 * @ice_seg: pointer to the ice segment (non-NULL)
1178 * @name: name of the label to search for
1179 * @type: the section type that will contain the label
1180 * @value: pointer to a value that will return the label's value if found
1182 * Finds a label's value given the label name and the section type to search.
1183 * The ice_seg parameter must not be NULL since the first call to
1184 * ice_enum_labels requires a pointer to an actual ice_seg structure.
1187 ice_find_label_value(struct ice_seg *ice_seg, char const *name, u32 type,
1190 struct ice_pkg_enum state;
1195 return ICE_ERR_PARAM;
1198 label_name = ice_enum_labels(ice_seg, type, &state, &val);
1199 if (label_name && !strcmp(label_name, name)) {
1205 } while (label_name);
1211 * ice_verify_pkg - verify package
1212 * @pkg: pointer to the package buffer
1213 * @len: size of the package buffer
1215 * Verifies various attributes of the package file, including length, format
1216 * version, and the requirement of at least one segment.
1218 static enum ice_status ice_verify_pkg(struct ice_pkg_hdr *pkg, u32 len)
1223 if (len < sizeof(*pkg))
1224 return ICE_ERR_BUF_TOO_SHORT;
1226 if (pkg->format_ver.major != ICE_PKG_FMT_VER_MAJ ||
1227 pkg->format_ver.minor != ICE_PKG_FMT_VER_MNR ||
1228 pkg->format_ver.update != ICE_PKG_FMT_VER_UPD ||
1229 pkg->format_ver.draft != ICE_PKG_FMT_VER_DFT)
1232 /* pkg must have at least one segment */
1233 seg_count = LE32_TO_CPU(pkg->seg_count);
1237 /* make sure segment array fits in package length */
1238 if (len < sizeof(*pkg) + ((seg_count - 1) * sizeof(pkg->seg_offset)))
1239 return ICE_ERR_BUF_TOO_SHORT;
1241 /* all segments must fit within length */
1242 for (i = 0; i < seg_count; i++) {
1243 u32 off = LE32_TO_CPU(pkg->seg_offset[i]);
1244 struct ice_generic_seg_hdr *seg;
1246 /* segment header must fit */
1247 if (len < off + sizeof(*seg))
1248 return ICE_ERR_BUF_TOO_SHORT;
1250 seg = (struct ice_generic_seg_hdr *)((u8 *)pkg + off);
1252 /* segment body must fit */
1253 if (len < off + LE32_TO_CPU(seg->seg_size))
1254 return ICE_ERR_BUF_TOO_SHORT;
1261 * ice_free_seg - free package segment pointer
1262 * @hw: pointer to the hardware structure
1264 * Frees the package segment pointer in the proper manner, depending on if the
1265 * segment was allocated or just the passed in pointer was stored.
1267 void ice_free_seg(struct ice_hw *hw)
1270 ice_free(hw, hw->pkg_copy);
1271 hw->pkg_copy = NULL;
1278 * ice_init_pkg_regs - initialize additional package registers
1279 * @hw: pointer to the hardware structure
1281 static void ice_init_pkg_regs(struct ice_hw *hw)
1283 #define ICE_SW_BLK_INP_MASK_L 0xFFFFFFFF
1284 #define ICE_SW_BLK_INP_MASK_H 0x0000FFFF
1285 #define ICE_SW_BLK_IDX 0
1287 /* setup Switch block input mask, which is 48-bits in two parts */
1288 wr32(hw, GL_PREEXT_L2_PMASK0(ICE_SW_BLK_IDX), ICE_SW_BLK_INP_MASK_L);
1289 wr32(hw, GL_PREEXT_L2_PMASK1(ICE_SW_BLK_IDX), ICE_SW_BLK_INP_MASK_H);
1293 * ice_init_pkg - initialize/download package
1294 * @hw: pointer to the hardware structure
1295 * @buf: pointer to the package buffer
1296 * @len: size of the package buffer
1298 * This function initializes a package. The package contains HW tables
1299 * required to do packet processing. First, the function extracts package
1300 * information such as version. Then it finds the ice configuration segment
1301 * within the package; this function then saves a copy of the segment pointer
1302 * within the supplied package buffer. Next, the function will cache any hints
1303 * from the package, followed by downloading the package itself. Note, that if
1304 * a previous PF driver has already downloaded the package successfully, then
1305 * the current driver will not have to download the package again.
1307 * The local package contents will be used to query default behavior and to
1308 * update specific sections of the HW's version of the package (e.g. to update
1309 * the parse graph to understand new protocols).
1311 * This function stores a pointer to the package buffer memory, and it is
1312 * expected that the supplied buffer will not be freed immediately. If the
1313 * package buffer needs to be freed, such as when read from a file, use
1314 * ice_copy_and_init_pkg() instead of directly calling ice_init_pkg() in this
1317 enum ice_status ice_init_pkg(struct ice_hw *hw, u8 *buf, u32 len)
1319 struct ice_pkg_hdr *pkg;
1320 enum ice_status status;
1321 struct ice_seg *seg;
1324 return ICE_ERR_PARAM;
1326 pkg = (struct ice_pkg_hdr *)buf;
1327 status = ice_verify_pkg(pkg, len);
1329 ice_debug(hw, ICE_DBG_INIT, "failed to verify pkg (err: %d)\n",
1334 /* initialize package info */
1335 status = ice_init_pkg_info(hw, pkg);
1339 /* find segment in given package */
1340 seg = (struct ice_seg *)ice_find_seg_in_pkg(hw, SEGMENT_TYPE_ICE, pkg);
1342 ice_debug(hw, ICE_DBG_INIT, "no ice segment in package.\n");
1346 /* initialize package hints and then download package */
1347 ice_init_pkg_hints(hw, seg);
1348 status = ice_download_pkg(hw, seg);
1349 if (status == ICE_ERR_AQ_NO_WORK) {
1350 ice_debug(hw, ICE_DBG_INIT,
1351 "package previously loaded - no work.\n");
1352 status = ICE_SUCCESS;
1357 /* on successful package download, update other required
1358 * registers to support the package
1360 ice_init_pkg_regs(hw);
1362 ice_debug(hw, ICE_DBG_INIT, "package load failed, %d\n",
1370 * ice_copy_and_init_pkg - initialize/download a copy of the package
1371 * @hw: pointer to the hardware structure
1372 * @buf: pointer to the package buffer
1373 * @len: size of the package buffer
1375 * This function copies the package buffer, and then calls ice_init_pkg() to
1376 * initialize the copied package contents.
1378 * The copying is necessary if the package buffer supplied is constant, or if
1379 * the memory may disappear shortly after calling this function.
1381 * If the package buffer resides in the data segment and can be modified, the
1382 * caller is free to use ice_init_pkg() instead of ice_copy_and_init_pkg().
1384 * However, if the package buffer needs to be copied first, such as when being
1385 * read from a file, the caller should use ice_copy_and_init_pkg().
1387 * This function will first copy the package buffer, before calling
1388 * ice_init_pkg(). The caller is free to immediately destroy the original
1389 * package buffer, as the new copy will be managed by this function and
1392 enum ice_status ice_copy_and_init_pkg(struct ice_hw *hw, const u8 *buf, u32 len)
1394 enum ice_status status;
1398 return ICE_ERR_PARAM;
1400 buf_copy = (u8 *)ice_memdup(hw, buf, len, ICE_NONDMA_TO_NONDMA);
1402 status = ice_init_pkg(hw, buf_copy, len);
1404 /* Free the copy, since we failed to initialize the package */
1405 ice_free(hw, buf_copy);
1407 /* Track the copied pkg so we can free it later */
1408 hw->pkg_copy = buf_copy;
1417 * @hw: pointer to the HW structure
1419 * Allocates a package buffer and returns a pointer to the buffer header.
1420 * Note: all package contents must be in Little Endian form.
1422 struct ice_buf_build *ice_pkg_buf_alloc(struct ice_hw *hw)
1424 struct ice_buf_build *bld;
1425 struct ice_buf_hdr *buf;
1427 bld = (struct ice_buf_build *)ice_malloc(hw, sizeof(*bld));
1431 buf = (struct ice_buf_hdr *)bld;
1432 buf->data_end = CPU_TO_LE16(sizeof(*buf) -
1433 sizeof(buf->section_entry[0]));
1439 * @sect_type: section type
1440 * @section: pointer to section
1441 * @index: index of the field vector entry to be returned
1442 * @offset: ptr to variable that receives the offset in the field vector table
1444 * This is a callback function that can be passed to ice_pkg_enum_entry.
1445 * This function treats the given section as of type ice_sw_fv_section and
1446 * enumerates offset field. "offset" is an index into the field vector
1450 ice_sw_fv_handler(u32 sect_type, void *section, u32 index, u32 *offset)
1452 struct ice_sw_fv_section *fv_section =
1453 (struct ice_sw_fv_section *)section;
1455 if (!section || sect_type != ICE_SID_FLD_VEC_SW)
1457 if (index >= LE16_TO_CPU(fv_section->count))
1460 /* "index" passed in to this function is relative to a given
1461 * 4k block. To get to the true index into the field vector
1462 * table need to add the relative index to the base_offset
1463 * field of this section
1465 *offset = LE16_TO_CPU(fv_section->base_offset) + index;
1466 return fv_section->fv + index;
1470 * ice_get_sw_fv_list
1471 * @hw: pointer to the HW structure
1472 * @prot_ids: field vector to search for with a given protocol ID
1473 * @ids_cnt: lookup/protocol count
1474 * @fv_list: Head of a list
1476 * Finds all the field vector entries from switch block that contain
1477 * a given protocol ID and returns a list of structures of type
1478 * "ice_sw_fv_list_entry". Every structure in the list has a field vector
1479 * definition and profile ID information
1480 * NOTE: The caller of the function is responsible for freeing the memory
1481 * allocated for every list entry.
1484 ice_get_sw_fv_list(struct ice_hw *hw, u16 *prot_ids, u8 ids_cnt,
1485 struct LIST_HEAD_TYPE *fv_list)
1487 struct ice_sw_fv_list_entry *fvl;
1488 struct ice_sw_fv_list_entry *tmp;
1489 struct ice_pkg_enum state;
1490 struct ice_seg *ice_seg;
1494 if (!ids_cnt || !hw->seg)
1495 return ICE_ERR_PARAM;
1501 fv = (struct ice_fv *)
1502 ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1503 &offset, ice_sw_fv_handler);
1505 for (i = 0; i < ids_cnt && fv; i++) {
1508 /* This code assumes that if a switch field vector line
1509 * has a matching protocol, then this line will contain
1510 * the entries necessary to represent every field in
1511 * that protocol header.
1513 for (j = 0; j < hw->blk[ICE_BLK_SW].es.fvw; j++)
1514 if (fv->ew[j].prot_id == prot_ids[i])
1516 if (j >= hw->blk[ICE_BLK_SW].es.fvw)
1518 if (i + 1 == ids_cnt) {
1519 fvl = (struct ice_sw_fv_list_entry *)
1520 ice_malloc(hw, sizeof(*fvl));
1524 fvl->profile_id = offset;
1525 LIST_ADD(&fvl->list_entry, fv_list);
1531 if (LIST_EMPTY(fv_list))
1536 LIST_FOR_EACH_ENTRY_SAFE(fvl, tmp, fv_list, ice_sw_fv_list_entry,
1538 LIST_DEL(&fvl->list_entry);
1542 return ICE_ERR_NO_MEMORY;
1546 * ice_pkg_buf_alloc_single_section
1547 * @hw: pointer to the HW structure
1548 * @type: the section type value
1549 * @size: the size of the section to reserve (in bytes)
1550 * @section: returns pointer to the section
1552 * Allocates a package buffer with a single section.
1553 * Note: all package contents must be in Little Endian form.
1555 static struct ice_buf_build *
1556 ice_pkg_buf_alloc_single_section(struct ice_hw *hw, u32 type, u16 size,
1559 struct ice_buf_build *buf;
1564 buf = ice_pkg_buf_alloc(hw);
1568 if (ice_pkg_buf_reserve_section(buf, 1))
1569 goto ice_pkg_buf_alloc_single_section_err;
1571 *section = ice_pkg_buf_alloc_section(buf, type, size);
1573 goto ice_pkg_buf_alloc_single_section_err;
1577 ice_pkg_buf_alloc_single_section_err:
1578 ice_pkg_buf_free(hw, buf);
1583 * ice_pkg_buf_reserve_section
1584 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1585 * @count: the number of sections to reserve
1587 * Reserves one or more section table entries in a package buffer. This routine
1588 * can be called multiple times as long as they are made before calling
1589 * ice_pkg_buf_alloc_section(). Once ice_pkg_buf_alloc_section()
1590 * is called once, the number of sections that can be allocated will not be able
1591 * to be increased; not using all reserved sections is fine, but this will
1592 * result in some wasted space in the buffer.
1593 * Note: all package contents must be in Little Endian form.
1596 ice_pkg_buf_reserve_section(struct ice_buf_build *bld, u16 count)
1598 struct ice_buf_hdr *buf;
1603 return ICE_ERR_PARAM;
1605 buf = (struct ice_buf_hdr *)&bld->buf;
1607 /* already an active section, can't increase table size */
1608 section_count = LE16_TO_CPU(buf->section_count);
1609 if (section_count > 0)
1612 if (bld->reserved_section_table_entries + count > ICE_MAX_S_COUNT)
1614 bld->reserved_section_table_entries += count;
1616 data_end = LE16_TO_CPU(buf->data_end) +
1617 (count * sizeof(buf->section_entry[0]));
1618 buf->data_end = CPU_TO_LE16(data_end);
1624 * ice_pkg_buf_unreserve_section
1625 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1626 * @count: the number of sections to unreserve
1628 * Unreserves one or more section table entries in a package buffer, releasing
1629 * space that can be used for section data. This routine can be called
1630 * multiple times as long as they are made before calling
1631 * ice_pkg_buf_alloc_section(). Once ice_pkg_buf_alloc_section()
1632 * is called once, the number of sections that can be allocated will not be able
1633 * to be increased; not using all reserved sections is fine, but this will
1634 * result in some wasted space in the buffer.
1635 * Note: all package contents must be in Little Endian form.
1638 ice_pkg_buf_unreserve_section(struct ice_buf_build *bld, u16 count)
1640 struct ice_buf_hdr *buf;
1645 return ICE_ERR_PARAM;
1647 buf = (struct ice_buf_hdr *)&bld->buf;
1649 /* already an active section, can't decrease table size */
1650 section_count = LE16_TO_CPU(buf->section_count);
1651 if (section_count > 0)
1654 if (count > bld->reserved_section_table_entries)
1656 bld->reserved_section_table_entries -= count;
1658 data_end = LE16_TO_CPU(buf->data_end) -
1659 (count * sizeof(buf->section_entry[0]));
1660 buf->data_end = CPU_TO_LE16(data_end);
1666 * ice_pkg_buf_alloc_section
1667 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1668 * @type: the section type value
1669 * @size: the size of the section to reserve (in bytes)
1671 * Reserves memory in the buffer for a section's content and updates the
1672 * buffers' status accordingly. This routine returns a pointer to the first
1673 * byte of the section start within the buffer, which is used to fill in the
1675 * Note: all package contents must be in Little Endian form.
1678 ice_pkg_buf_alloc_section(struct ice_buf_build *bld, u32 type, u16 size)
1680 struct ice_buf_hdr *buf;
1684 if (!bld || !type || !size)
1687 buf = (struct ice_buf_hdr *)&bld->buf;
1689 /* check for enough space left in buffer */
1690 data_end = LE16_TO_CPU(buf->data_end);
1692 /* section start must align on 4 byte boundary */
1693 data_end = ICE_ALIGN(data_end, 4);
1695 if ((data_end + size) > ICE_MAX_S_DATA_END)
1698 /* check for more available section table entries */
1699 sect_count = LE16_TO_CPU(buf->section_count);
1700 if (sect_count < bld->reserved_section_table_entries) {
1701 void *section_ptr = ((u8 *)buf) + data_end;
1703 buf->section_entry[sect_count].offset = CPU_TO_LE16(data_end);
1704 buf->section_entry[sect_count].size = CPU_TO_LE16(size);
1705 buf->section_entry[sect_count].type = CPU_TO_LE32(type);
1708 buf->data_end = CPU_TO_LE16(data_end);
1710 buf->section_count = CPU_TO_LE16(sect_count + 1);
1714 /* no free section table entries */
1719 * ice_pkg_buf_get_free_space
1720 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1722 * Returns the number of free bytes remaining in the buffer.
1723 * Note: all package contents must be in Little Endian form.
1725 u16 ice_pkg_buf_get_free_space(struct ice_buf_build *bld)
1727 struct ice_buf_hdr *buf;
1732 buf = (struct ice_buf_hdr *)&bld->buf;
1733 return ICE_MAX_S_DATA_END - LE16_TO_CPU(buf->data_end);
1737 * ice_pkg_buf_get_active_sections
1738 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1740 * Returns the number of active sections. Before using the package buffer
1741 * in an update package command, the caller should make sure that there is at
1742 * least one active section - otherwise, the buffer is not legal and should
1744 * Note: all package contents must be in Little Endian form.
1746 u16 ice_pkg_buf_get_active_sections(struct ice_buf_build *bld)
1748 struct ice_buf_hdr *buf;
1753 buf = (struct ice_buf_hdr *)&bld->buf;
1754 return LE16_TO_CPU(buf->section_count);
1758 * ice_pkg_buf_header
1759 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1761 * Return a pointer to the buffer's header
1763 struct ice_buf *ice_pkg_buf(struct ice_buf_build *bld)
1773 * @hw: pointer to the HW structure
1774 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1776 * Frees a package buffer
1778 void ice_pkg_buf_free(struct ice_hw *hw, struct ice_buf_build *bld)
1783 /* PTG Management */
1786 * ice_ptg_update_xlt1 - Updates packet type groups in HW via XLT1 table
1787 * @hw: pointer to the hardware structure
1790 * This function will update the XLT1 hardware table to reflect the new
1791 * packet type group configuration.
1793 enum ice_status ice_ptg_update_xlt1(struct ice_hw *hw, enum ice_block blk)
1795 struct ice_xlt1_section *sect;
1796 struct ice_buf_build *bld;
1797 enum ice_status status;
1800 bld = ice_pkg_buf_alloc_single_section(hw, ice_sect_id(blk, ICE_XLT1),
1801 ICE_XLT1_SIZE(ICE_XLT1_CNT),
1804 return ICE_ERR_NO_MEMORY;
1806 sect->count = CPU_TO_LE16(ICE_XLT1_CNT);
1807 sect->offset = CPU_TO_LE16(0);
1808 for (index = 0; index < ICE_XLT1_CNT; index++)
1809 sect->value[index] = hw->blk[blk].xlt1.ptypes[index].ptg;
1811 status = ice_update_pkg(hw, ice_pkg_buf(bld), 1);
1813 ice_pkg_buf_free(hw, bld);
1819 * ice_ptg_find_ptype - Search for packet type group using packet type (ptype)
1820 * @hw: pointer to the hardware structure
1822 * @ptype: the ptype to search for
1823 * @ptg: pointer to variable that receives the PTG
1825 * This function will search the PTGs for a particular ptype, returning the
1826 * PTG ID that contains it through the ptg parameter, with the value of
1827 * ICE_DEFAULT_PTG (0) meaning it is part the default PTG.
1830 ice_ptg_find_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 *ptg)
1832 if (ptype >= ICE_XLT1_CNT || !ptg)
1833 return ICE_ERR_PARAM;
1835 *ptg = hw->blk[blk].xlt1.ptypes[ptype].ptg;
1840 * ice_ptg_alloc_val - Allocates a new packet type group ID by value
1841 * @hw: pointer to the hardware structure
1843 * @ptg: the ptg to allocate
1845 * This function allocates a given packet type group ID specified by the ptg
1849 void ice_ptg_alloc_val(struct ice_hw *hw, enum ice_block blk, u8 ptg)
1851 hw->blk[blk].xlt1.ptg_tbl[ptg].in_use = true;
1855 * ice_ptg_alloc - Find a free entry and allocates a new packet type group ID
1856 * @hw: pointer to the hardware structure
1859 * This function allocates and returns a new packet type group ID. Note
1860 * that 0 is the default packet type group, so successfully created PTGs will
1861 * have a non-zero ID value; which means a 0 return value indicates an error.
1863 u8 ice_ptg_alloc(struct ice_hw *hw, enum ice_block blk)
1867 /* Skip the default PTG of 0 */
1868 for (i = 1; i < ICE_MAX_PTGS; i++)
1869 if (!hw->blk[blk].xlt1.ptg_tbl[i].in_use) {
1870 /* found a free PTG ID */
1871 ice_ptg_alloc_val(hw, blk, i);
1879 * ice_ptg_free - Frees a packet type group
1880 * @hw: pointer to the hardware structure
1882 * @ptg: the ptg ID to free
1884 * This function frees a packet type group, and returns all the current ptypes
1885 * within it to the default PTG.
1887 void ice_ptg_free(struct ice_hw *hw, enum ice_block blk, u8 ptg)
1889 struct ice_ptg_ptype *p, *temp;
1891 hw->blk[blk].xlt1.ptg_tbl[ptg].in_use = false;
1892 p = hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
1894 p->ptg = ICE_DEFAULT_PTG;
1895 temp = p->next_ptype;
1896 p->next_ptype = NULL;
1900 hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype = NULL;
1904 * ice_ptg_remove_ptype - Removes ptype from a particular packet type group
1905 * @hw: pointer to the hardware structure
1907 * @ptype: the ptype to remove
1908 * @ptg: the ptg to remove the ptype from
1910 * This function will remove the ptype from the specific ptg, and move it to
1911 * the default PTG (ICE_DEFAULT_PTG).
1913 static enum ice_status
1914 ice_ptg_remove_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 ptg)
1916 struct ice_ptg_ptype **ch;
1917 struct ice_ptg_ptype *p;
1919 if (ptype > ICE_XLT1_CNT - 1)
1920 return ICE_ERR_PARAM;
1922 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].in_use)
1923 return ICE_ERR_DOES_NOT_EXIST;
1925 /* Should not happen if .in_use is set, bad config */
1926 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype)
1929 /* find the ptype within this PTG, and bypass the link over it */
1930 p = hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
1931 ch = &hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
1933 if (ptype == (p - hw->blk[blk].xlt1.ptypes)) {
1934 *ch = p->next_ptype;
1938 ch = &p->next_ptype;
1942 hw->blk[blk].xlt1.ptypes[ptype].ptg = ICE_DEFAULT_PTG;
1943 hw->blk[blk].xlt1.ptypes[ptype].next_ptype = NULL;
1949 * ice_ptg_add_mv_ptype - Adds/moves ptype to a particular packet type group
1950 * @hw: pointer to the hardware structure
1952 * @ptype: the ptype to add or move
1953 * @ptg: the ptg to add or move the ptype to
1955 * This function will either add or move a ptype to a particular PTG depending
1956 * on if the ptype is already part of another group. Note that using a
1957 * a destination PTG ID of ICE_DEFAULT_PTG (0) will move the ptype to the
1961 ice_ptg_add_mv_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 ptg)
1963 enum ice_status status;
1966 if (ptype > ICE_XLT1_CNT - 1)
1967 return ICE_ERR_PARAM;
1969 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].in_use && ptg != ICE_DEFAULT_PTG)
1970 return ICE_ERR_DOES_NOT_EXIST;
1972 status = ice_ptg_find_ptype(hw, blk, ptype, &original_ptg);
1976 /* Is ptype already in the correct PTG? */
1977 if (original_ptg == ptg)
1980 /* Remove from original PTG and move back to the default PTG */
1981 if (original_ptg != ICE_DEFAULT_PTG)
1982 ice_ptg_remove_ptype(hw, blk, ptype, original_ptg);
1984 /* Moving to default PTG? Then we're done with this request */
1985 if (ptg == ICE_DEFAULT_PTG)
1988 /* Add ptype to PTG at beginning of list */
1989 hw->blk[blk].xlt1.ptypes[ptype].next_ptype =
1990 hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
1991 hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype =
1992 &hw->blk[blk].xlt1.ptypes[ptype];
1994 hw->blk[blk].xlt1.ptypes[ptype].ptg = ptg;
1995 hw->blk[blk].xlt1.t[ptype] = ptg;
2000 /* Block / table size info */
2001 struct ice_blk_size_details {
2002 u16 xlt1; /* # XLT1 entries */
2003 u16 xlt2; /* # XLT2 entries */
2004 u16 prof_tcam; /* # profile ID TCAM entries */
2005 u16 prof_id; /* # profile IDs */
2006 u8 prof_cdid_bits; /* # cdid one-hot bits used in key */
2007 u16 prof_redir; /* # profile redirection entries */
2008 u16 es; /* # extraction sequence entries */
2009 u16 fvw; /* # field vector words */
2010 u8 overwrite; /* overwrite existing entries allowed */
2011 u8 reverse; /* reverse FV order */
2014 static const struct ice_blk_size_details blk_sizes[ICE_BLK_COUNT] = {
2017 * XLT1 - Number of entries in XLT1 table
2018 * XLT2 - Number of entries in XLT2 table
2019 * TCAM - Number of entries Profile ID TCAM table
2020 * CDID - Control Domain ID of the hardware block
2021 * PRED - Number of entries in the Profile Redirection Table
2022 * FV - Number of entries in the Field Vector
2023 * FVW - Width (in WORDs) of the Field Vector
2024 * OVR - Overwrite existing table entries
2027 /* XLT1 , XLT2 ,TCAM, PID,CDID,PRED, FV, FVW */
2028 /* Overwrite , Reverse FV */
2029 /* SW */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 256, 0, 256, 256, 48,
2031 /* ACL */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 32,
2033 /* FD */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 24,
2035 /* RSS */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 24,
2037 /* PE */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 64, 32, 0, 32, 32, 24,
2042 ICE_SID_XLT1_OFF = 0,
2045 ICE_SID_PR_REDIR_OFF,
2050 /* Characteristic handling */
2053 * ice_match_prop_lst - determine if properties of two lists match
2054 * @list1: first properties list
2055 * @list2: second properties list
2057 * Count, cookies and the order must match in order to be considered equivalent.
2060 ice_match_prop_lst(struct LIST_HEAD_TYPE *list1, struct LIST_HEAD_TYPE *list2)
2062 struct ice_vsig_prof *tmp1;
2063 struct ice_vsig_prof *tmp2;
2067 /* compare counts */
2068 LIST_FOR_EACH_ENTRY(tmp1, list1, ice_vsig_prof, list) {
2071 LIST_FOR_EACH_ENTRY(tmp2, list2, ice_vsig_prof, list) {
2074 if (!count || count != chk_count)
2077 tmp1 = LIST_FIRST_ENTRY(list1, struct ice_vsig_prof, list);
2078 tmp2 = LIST_FIRST_ENTRY(list2, struct ice_vsig_prof, list);
2080 /* profile cookies must compare, and in the exact same order to take
2081 * into account priority
2084 if (tmp2->profile_cookie != tmp1->profile_cookie)
2087 tmp1 = LIST_NEXT_ENTRY(tmp1, struct ice_vsig_prof, list);
2088 tmp2 = LIST_NEXT_ENTRY(tmp2, struct ice_vsig_prof, list);
2094 /* VSIG Management */
2097 * ice_vsig_update_xlt2_sect - update one section of XLT2 table
2098 * @hw: pointer to the hardware structure
2100 * @vsi: HW VSI number to program
2101 * @vsig: vsig for the VSI
2103 * This function will update the XLT2 hardware table with the input VSI
2104 * group configuration.
2106 static enum ice_status
2107 ice_vsig_update_xlt2_sect(struct ice_hw *hw, enum ice_block blk, u16 vsi,
2110 struct ice_xlt2_section *sect;
2111 struct ice_buf_build *bld;
2112 enum ice_status status;
2114 bld = ice_pkg_buf_alloc_single_section(hw, ice_sect_id(blk, ICE_XLT2),
2115 sizeof(struct ice_xlt2_section),
2118 return ICE_ERR_NO_MEMORY;
2120 sect->count = CPU_TO_LE16(1);
2121 sect->offset = CPU_TO_LE16(vsi);
2122 sect->value[0] = CPU_TO_LE16(vsig);
2124 status = ice_update_pkg(hw, ice_pkg_buf(bld), 1);
2126 ice_pkg_buf_free(hw, bld);
2132 * ice_vsig_update_xlt2 - update XLT2 table with VSIG configuration
2133 * @hw: pointer to the hardware structure
2136 * This function will update the XLT2 hardware table with the input VSI
2137 * group configuration of used vsis.
2139 enum ice_status ice_vsig_update_xlt2(struct ice_hw *hw, enum ice_block blk)
2143 for (vsi = 0; vsi < ICE_MAX_VSI; vsi++) {
2144 /* update only vsis that have been changed */
2145 if (hw->blk[blk].xlt2.vsis[vsi].changed) {
2146 enum ice_status status;
2149 vsig = hw->blk[blk].xlt2.vsis[vsi].vsig;
2150 status = ice_vsig_update_xlt2_sect(hw, blk, vsi, vsig);
2154 hw->blk[blk].xlt2.vsis[vsi].changed = 0;
2162 * ice_vsig_find_vsi - find a VSIG that contains a specified VSI
2163 * @hw: pointer to the hardware structure
2165 * @vsi: VSI of interest
2166 * @vsig: pointer to receive the VSI group
2168 * This function will lookup the VSI entry in the XLT2 list and return
2169 * the VSI group its associated with.
2172 ice_vsig_find_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 *vsig)
2174 if (!vsig || vsi >= ICE_MAX_VSI)
2175 return ICE_ERR_PARAM;
2177 /* As long as there's a default or valid VSIG associated with the input
2178 * VSI, the functions returns a success. Any handling of VSIG will be
2179 * done by the following add, update or remove functions.
2181 *vsig = hw->blk[blk].xlt2.vsis[vsi].vsig;
2187 * ice_vsig_alloc_val - allocate a new VSIG by value
2188 * @hw: pointer to the hardware structure
2190 * @vsig: the vsig to allocate
2192 * This function will allocate a given VSIG specified by the vsig parameter.
2194 static u16 ice_vsig_alloc_val(struct ice_hw *hw, enum ice_block blk, u16 vsig)
2196 u16 idx = vsig & ICE_VSIG_IDX_M;
2198 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use) {
2199 INIT_LIST_HEAD(&hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst);
2200 hw->blk[blk].xlt2.vsig_tbl[idx].in_use = true;
2203 return ICE_VSIG_VALUE(idx, hw->pf_id);
2207 * ice_vsig_alloc - Finds a free entry and allocates a new VSIG
2208 * @hw: pointer to the hardware structure
2211 * This function will iterate through the VSIG list and mark the first
2212 * unused entry for the new VSIG entry as used and return that value.
2214 static u16 ice_vsig_alloc(struct ice_hw *hw, enum ice_block blk)
2218 for (i = 1; i < ICE_MAX_VSIGS; i++)
2219 if (!hw->blk[blk].xlt2.vsig_tbl[i].in_use)
2220 return ice_vsig_alloc_val(hw, blk, i);
2222 return ICE_DEFAULT_VSIG;
2226 * ice_find_dup_props_vsig - find VSI group with a specified set of properties
2227 * @hw: pointer to the hardware structure
2229 * @chs: characteristic list
2230 * @vsig: returns the VSIG with the matching profiles, if found
2232 * Each VSIG is associated with a characteristic set; i.e. all VSIs under
2233 * a group have the same characteristic set. To check if there exists a VSIG
2234 * which has the same characteristics as the input characteristics; this
2235 * function will iterate through the XLT2 list and return the VSIG that has a
2236 * matching configuration. In order to make sure that priorities are accounted
2237 * for, the list must match exactly, including the order in which the
2238 * characteristics are listed.
2241 ice_find_dup_props_vsig(struct ice_hw *hw, enum ice_block blk,
2242 struct LIST_HEAD_TYPE *chs, u16 *vsig)
2244 struct ice_xlt2 *xlt2 = &hw->blk[blk].xlt2;
2247 for (i = 0; i < xlt2->count; i++) {
2248 if (xlt2->vsig_tbl[i].in_use &&
2249 ice_match_prop_lst(chs, &xlt2->vsig_tbl[i].prop_lst)) {
2250 *vsig = ICE_VSIG_VALUE(i, hw->pf_id);
2255 return ICE_ERR_DOES_NOT_EXIST;
2259 * ice_vsig_free - free VSI group
2260 * @hw: pointer to the hardware structure
2262 * @vsig: VSIG to remove
2264 * The function will remove all VSIs associated with the input VSIG and move
2265 * them to the DEFAULT_VSIG and mark the VSIG available.
2268 ice_vsig_free(struct ice_hw *hw, enum ice_block blk, u16 vsig)
2270 struct ice_vsig_prof *dtmp, *del;
2271 struct ice_vsig_vsi *vsi_cur;
2274 idx = vsig & ICE_VSIG_IDX_M;
2275 if (idx >= ICE_MAX_VSIGS)
2276 return ICE_ERR_PARAM;
2278 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
2279 return ICE_ERR_DOES_NOT_EXIST;
2281 hw->blk[blk].xlt2.vsig_tbl[idx].in_use = false;
2283 vsi_cur = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2287 /* remove all vsis associated with this VSIG XLT2 entry */
2289 struct ice_vsig_vsi *tmp = vsi_cur->next_vsi;
2291 vsi_cur->vsig = ICE_DEFAULT_VSIG;
2292 vsi_cur->changed = 1;
2293 vsi_cur->next_vsi = NULL;
2297 /* NULL terminate head of vsi list */
2298 hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi = NULL;
2300 /* free characteristic list */
2301 LIST_FOR_EACH_ENTRY_SAFE(del, dtmp,
2302 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
2303 ice_vsig_prof, list) {
2304 LIST_DEL(&del->list);
2312 * ice_vsig_add_mv_vsi - add or move a VSI to a VSI group
2313 * @hw: pointer to the hardware structure
2316 * @vsig: destination VSI group
2318 * This function will move or add the input VSI to the target VSIG.
2319 * The function will find the original VSIG the VSI belongs to and
2320 * move the entry to the DEFAULT_VSIG, update the original VSIG and
2321 * then move entry to the new VSIG.
2324 ice_vsig_add_mv_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
2326 struct ice_vsig_vsi *tmp;
2327 enum ice_status status;
2330 idx = vsig & ICE_VSIG_IDX_M;
2332 if (vsi >= ICE_MAX_VSI || idx >= ICE_MAX_VSIGS)
2333 return ICE_ERR_PARAM;
2335 /* if VSIG not in use and VSIG is not default type this VSIG
2338 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use &&
2339 vsig != ICE_DEFAULT_VSIG)
2340 return ICE_ERR_DOES_NOT_EXIST;
2342 status = ice_vsig_find_vsi(hw, blk, vsi, &orig_vsig);
2346 /* no update required if vsigs match */
2347 if (orig_vsig == vsig)
2350 if (orig_vsig != ICE_DEFAULT_VSIG) {
2351 /* remove entry from orig_vsig and add to default VSIG */
2352 status = ice_vsig_remove_vsi(hw, blk, vsi, orig_vsig);
2357 if (idx == ICE_DEFAULT_VSIG)
2360 /* Create VSI entry and add VSIG and prop_mask values */
2361 hw->blk[blk].xlt2.vsis[vsi].vsig = vsig;
2362 hw->blk[blk].xlt2.vsis[vsi].changed = 1;
2364 /* Add new entry to the head of the VSIG list */
2365 tmp = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2366 hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi =
2367 &hw->blk[blk].xlt2.vsis[vsi];
2368 hw->blk[blk].xlt2.vsis[vsi].next_vsi = tmp;
2369 hw->blk[blk].xlt2.t[vsi] = vsig;
2375 * ice_vsig_remove_vsi - remove VSI from VSIG
2376 * @hw: pointer to the hardware structure
2378 * @vsi: VSI to remove
2379 * @vsig: VSI group to remove from
2381 * The function will remove the input VSI from its VSI group and move it
2382 * to the DEFAULT_VSIG.
2385 ice_vsig_remove_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
2387 struct ice_vsig_vsi **vsi_head, *vsi_cur, *vsi_tgt;
2390 idx = vsig & ICE_VSIG_IDX_M;
2392 if (vsi >= ICE_MAX_VSI || idx >= ICE_MAX_VSIGS)
2393 return ICE_ERR_PARAM;
2395 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
2396 return ICE_ERR_DOES_NOT_EXIST;
2398 /* entry already in default VSIG, don't have to remove */
2399 if (idx == ICE_DEFAULT_VSIG)
2402 vsi_head = &hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2406 vsi_tgt = &hw->blk[blk].xlt2.vsis[vsi];
2407 vsi_cur = (*vsi_head);
2409 /* iterate the VSI list, skip over the entry to be removed */
2411 if (vsi_tgt == vsi_cur) {
2412 (*vsi_head) = vsi_cur->next_vsi;
2415 vsi_head = &vsi_cur->next_vsi;
2416 vsi_cur = vsi_cur->next_vsi;
2419 /* verify if VSI was removed from group list */
2421 return ICE_ERR_DOES_NOT_EXIST;
2423 vsi_cur->vsig = ICE_DEFAULT_VSIG;
2424 vsi_cur->changed = 1;
2425 vsi_cur->next_vsi = NULL;
2431 * ice_find_prof_id - find profile ID for a given field vector
2432 * @hw: pointer to the hardware structure
2434 * @fv: field vector to search for
2435 * @prof_id: receives the profile ID
2437 static enum ice_status
2438 ice_find_prof_id(struct ice_hw *hw, enum ice_block blk,
2439 struct ice_fv_word *fv, u8 *prof_id)
2441 struct ice_es *es = &hw->blk[blk].es;
2444 for (i = 0; i < es->count; i++) {
2447 if (memcmp(&es->t[off], fv, es->fvw * 2))
2454 return ICE_ERR_DOES_NOT_EXIST;
2458 * ice_prof_id_rsrc_type - get profile ID resource type for a block type
2459 * @blk: the block type
2460 * @rsrc_type: pointer to variable to receive the resource type
2462 static bool ice_prof_id_rsrc_type(enum ice_block blk, u16 *rsrc_type)
2466 *rsrc_type = ICE_AQC_RES_TYPE_SWITCH_PROF_BLDR_PROFID;
2469 *rsrc_type = ICE_AQC_RES_TYPE_ACL_PROF_BLDR_PROFID;
2472 *rsrc_type = ICE_AQC_RES_TYPE_FD_PROF_BLDR_PROFID;
2475 *rsrc_type = ICE_AQC_RES_TYPE_HASH_PROF_BLDR_PROFID;
2478 *rsrc_type = ICE_AQC_RES_TYPE_QHASH_PROF_BLDR_PROFID;
2487 * ice_tcam_ent_rsrc_type - get TCAM entry resource type for a block type
2488 * @blk: the block type
2489 * @rsrc_type: pointer to variable to receive the resource type
2491 static bool ice_tcam_ent_rsrc_type(enum ice_block blk, u16 *rsrc_type)
2495 *rsrc_type = ICE_AQC_RES_TYPE_SWITCH_PROF_BLDR_TCAM;
2498 *rsrc_type = ICE_AQC_RES_TYPE_ACL_PROF_BLDR_TCAM;
2501 *rsrc_type = ICE_AQC_RES_TYPE_FD_PROF_BLDR_TCAM;
2504 *rsrc_type = ICE_AQC_RES_TYPE_HASH_PROF_BLDR_TCAM;
2507 *rsrc_type = ICE_AQC_RES_TYPE_QHASH_PROF_BLDR_TCAM;
2516 * ice_workaround_get_res_blk - determine the block from a resource type
2517 * @type: type of resource
2518 * @blk: pointer to a enum that will receive the block type
2519 * @tcam: pointer to variable that will be set to true for a TCAM resource type
2522 ice_status ice_workaround_get_res_blk(u16 type, enum ice_block *blk, bool *tcam)
2524 /* just need to support TCAM entries and Profile IDs for now */
2528 case ICE_AQC_RES_TYPE_SWITCH_PROF_BLDR_TCAM:
2532 case ICE_AQC_RES_TYPE_ACL_PROF_BLDR_TCAM:
2536 case ICE_AQC_RES_TYPE_FD_PROF_BLDR_TCAM:
2540 case ICE_AQC_RES_TYPE_HASH_PROF_BLDR_TCAM:
2544 case ICE_AQC_RES_TYPE_QHASH_PROF_BLDR_TCAM:
2548 case ICE_AQC_RES_TYPE_SWITCH_PROF_BLDR_PROFID:
2551 case ICE_AQC_RES_TYPE_ACL_PROF_BLDR_PROFID:
2554 case ICE_AQC_RES_TYPE_FD_PROF_BLDR_PROFID:
2557 case ICE_AQC_RES_TYPE_HASH_PROF_BLDR_PROFID:
2560 case ICE_AQC_RES_TYPE_QHASH_PROF_BLDR_PROFID:
2564 return ICE_ERR_PARAM;
2571 * ice_alloc_res_workaround
2572 * @hw: pointer to the hw struct
2573 * @type: type of resource
2574 * @num: number of resources to allocate
2575 * @res: pointer to array that will receive the resources
2577 static enum ice_status
2578 ice_alloc_res_workaround(struct ice_hw *hw, u16 type, u16 num, u16 *res)
2588 /* Number of PFs we support with this workaround */
2589 #define ICE_WA_PF_COUNT 4
2590 #define ICE_WA_1ST_TCAM 4
2591 #define ICE_WA_1ST_FV 4
2593 /* Only allow our supported PFs */
2594 if (hw->pf_id >= ICE_WA_PF_COUNT)
2595 return ICE_ERR_AQ_ERROR;
2597 if (ice_workaround_get_res_blk(type, &blk, &tcam))
2598 return ICE_ERR_AQ_ERROR;
2601 /* range of entries based on PF */
2602 max = hw->blk[blk].prof.count / ICE_WA_PF_COUNT;
2603 first = max * hw->pf_id;
2606 /* Profile IDs - start at non-zero index for PROF ID TCAM table
2607 * The first few entries are for bypass, default and errors
2608 * (only relevant for PF 0)
2610 first += hw->pf_id ? 0 : ICE_WA_1ST_TCAM;
2612 for (i = first; i < last && count < num; i++) {
2613 if (!hw->blk[blk].prof.resource_used_hack[i]) {
2615 hw->blk[blk].prof.resource_used_hack[i] = true;
2619 /* handle failure case */
2621 for (i = 0; i < count; i++) {
2622 hw->blk[blk].prof.resource_used_hack[res[i]] =
2627 return ICE_ERR_AQ_ERROR;
2630 /* range of entries based on PF */
2631 max = hw->blk[blk].es.count / ICE_WA_PF_COUNT;
2632 first = max * hw->pf_id;
2635 /* FV index - start at non-zero index for Field vector table
2636 * The first few entries are for bypass, default and errors
2637 * (only relevant for PF 0)
2639 first += hw->pf_id ? 0 : ICE_WA_1ST_FV;
2641 for (i = first; i < last && count < num; i++) {
2642 if (!hw->blk[blk].es.resource_used_hack[i]) {
2644 hw->blk[blk].es.resource_used_hack[i] = true;
2648 /* handle failure case */
2650 for (i = 0; i < count; i++) {
2651 hw->blk[blk].es.resource_used_hack[res[i]] =
2656 return ICE_ERR_AQ_ERROR;
2664 * ice_free_res_workaround
2665 * @hw: pointer to the hw struct
2666 * @type: type of resource to free
2667 * @num: number of resources
2668 * @res: array of resource ids to free
2670 static enum ice_status
2671 ice_free_res_workaround(struct ice_hw *hw, u16 type, u16 num, u16 *res)
2677 if (ice_workaround_get_res_blk(type, &blk, &tcam))
2678 return ICE_ERR_AQ_ERROR;
2682 for (i = 0; i < num; i++) {
2683 if (res[i] < hw->blk[blk].prof.count) {
2686 ice_free_hw_res(hw, type, 1, &idx);
2687 hw->blk[blk].prof.resource_used_hack[res[i]] =
2694 for (i = 0; i < num; i++) {
2695 if (res[i] < hw->blk[blk].es.count) {
2698 ice_free_hw_res(hw, type, 1, &idx);
2699 hw->blk[blk].es.resource_used_hack[res[i]] =
2709 * ice_alloc_tcam_ent - allocate hardware TCAM entry
2710 * @hw: pointer to the HW struct
2711 * @blk: the block to allocate the TCAM for
2712 * @tcam_idx: pointer to variable to receive the TCAM entry
2714 * This function allocates a new entry in a Profile ID TCAM for a specific
2717 static enum ice_status
2718 ice_alloc_tcam_ent(struct ice_hw *hw, enum ice_block blk, u16 *tcam_idx)
2722 if (!ice_tcam_ent_rsrc_type(blk, &res_type))
2723 return ICE_ERR_PARAM;
2725 return ice_alloc_res_workaround(hw, res_type, 1, tcam_idx);
2729 * ice_free_tcam_ent - free hardware TCAM entry
2730 * @hw: pointer to the HW struct
2731 * @blk: the block from which to free the TCAM entry
2732 * @tcam_idx: the TCAM entry to free
2734 * This function frees an entry in a Profile ID TCAM for a specific block.
2736 static enum ice_status
2737 ice_free_tcam_ent(struct ice_hw *hw, enum ice_block blk, u16 tcam_idx)
2741 if (!ice_tcam_ent_rsrc_type(blk, &res_type))
2742 return ICE_ERR_PARAM;
2744 return ice_free_res_workaround(hw, res_type, 1, &tcam_idx);
2748 * ice_alloc_prof_id - allocate profile ID
2749 * @hw: pointer to the HW struct
2750 * @blk: the block to allocate the profile ID for
2751 * @prof_id: pointer to variable to receive the profile ID
2753 * This function allocates a new profile ID, which also corresponds to a Field
2754 * Vector (Extraction Sequence) entry.
2756 static enum ice_status
2757 ice_alloc_prof_id(struct ice_hw *hw, enum ice_block blk, u8 *prof_id)
2759 enum ice_status status;
2763 if (!ice_prof_id_rsrc_type(blk, &res_type))
2764 return ICE_ERR_PARAM;
2766 status = ice_alloc_res_workaround(hw, res_type, 1, &get_prof);
2768 *prof_id = (u8)get_prof;
2774 * ice_free_prof_id - free profile ID
2775 * @hw: pointer to the HW struct
2776 * @blk: the block from which to free the profile ID
2777 * @prof_id: the profile ID to free
2779 * This function frees a profile ID, which also corresponds to a Field Vector.
2781 static enum ice_status
2782 ice_free_prof_id(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
2784 u16 tmp_prof_id = (u16)prof_id;
2787 if (!ice_prof_id_rsrc_type(blk, &res_type))
2788 return ICE_ERR_PARAM;
2790 return ice_free_res_workaround(hw, res_type, 1, &tmp_prof_id);
2791 /* The following code is a WORKAROUND until DCR 076 is available.
2792 * DCR 076 - Update to Profile ID TCAM Resource Allocation
2794 * Once the DCR 076 changes are available in FW, this code can be
2795 * restored. Original code:
2797 * return ice_free_res(hw, res_type, 1, &tmp_prof_id);
2802 * ice_prof_inc_ref - increment reference count for profile
2803 * @hw: pointer to the HW struct
2804 * @blk: the block from which to free the profile ID
2805 * @prof_id: the profile ID for which to increment the reference count
2807 static enum ice_status
2808 ice_prof_inc_ref(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
2810 if (prof_id > hw->blk[blk].es.count)
2811 return ICE_ERR_PARAM;
2813 hw->blk[blk].es.ref_count[prof_id]++;
2819 * ice_write_es - write an extraction sequence to hardware
2820 * @hw: pointer to the HW struct
2821 * @blk: the block in which to write the extraction sequence
2822 * @prof_id: the profile ID to write
2823 * @fv: pointer to the extraction sequence to write - NULL to clear extraction
2826 ice_write_es(struct ice_hw *hw, enum ice_block blk, u8 prof_id,
2827 struct ice_fv_word *fv)
2831 off = prof_id * hw->blk[blk].es.fvw;
2833 ice_memset(&hw->blk[blk].es.t[off], 0, hw->blk[blk].es.fvw *
2834 sizeof(*fv), ICE_NONDMA_MEM);
2835 hw->blk[blk].es.written[prof_id] = false;
2837 ice_memcpy(&hw->blk[blk].es.t[off], fv, hw->blk[blk].es.fvw *
2838 sizeof(*fv), ICE_NONDMA_TO_NONDMA);
2843 * ice_prof_dec_ref - decrement reference count for profile
2844 * @hw: pointer to the HW struct
2845 * @blk: the block from which to free the profile ID
2846 * @prof_id: the profile ID for which to decrement the reference count
2848 static enum ice_status
2849 ice_prof_dec_ref(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
2851 if (prof_id > hw->blk[blk].es.count)
2852 return ICE_ERR_PARAM;
2854 if (hw->blk[blk].es.ref_count[prof_id] > 0) {
2855 if (!--hw->blk[blk].es.ref_count[prof_id]) {
2856 ice_write_es(hw, blk, prof_id, NULL);
2857 return ice_free_prof_id(hw, blk, prof_id);
2864 /* Block / table section IDs */
2865 static const u32 ice_blk_sids[ICE_BLK_COUNT][ICE_SID_OFF_COUNT] = {
2869 ICE_SID_PROFID_TCAM_SW,
2870 ICE_SID_PROFID_REDIR_SW,
2877 ICE_SID_PROFID_TCAM_ACL,
2878 ICE_SID_PROFID_REDIR_ACL,
2885 ICE_SID_PROFID_TCAM_FD,
2886 ICE_SID_PROFID_REDIR_FD,
2893 ICE_SID_PROFID_TCAM_RSS,
2894 ICE_SID_PROFID_REDIR_RSS,
2901 ICE_SID_PROFID_TCAM_PE,
2902 ICE_SID_PROFID_REDIR_PE,
2908 * ice_fill_tbl - Reads content of a single table type into database
2909 * @hw: pointer to the hardware structure
2910 * @block_id: Block ID of the table to copy
2911 * @sid: Section ID of the table to copy
2913 * Will attempt to read the entire content of a given table of a single block
2914 * into the driver database. We assume that the buffer will always
2915 * be as large or larger than the data contained in the package. If
2916 * this condition is not met, there is most likely an error in the package
2919 static void ice_fill_tbl(struct ice_hw *hw, enum ice_block block_id, u32 sid)
2921 u32 dst_len, sect_len, offset = 0;
2922 struct ice_prof_redir_section *pr;
2923 struct ice_prof_id_section *pid;
2924 struct ice_xlt1_section *xlt1;
2925 struct ice_xlt2_section *xlt2;
2926 struct ice_sw_fv_section *es;
2927 struct ice_pkg_enum state;
2931 /* if the HW segment pointer is null then the first iteration of
2932 * ice_pkg_enum_section() will fail. In this case the Hw tables will
2933 * not be filled and return success.
2936 ice_debug(hw, ICE_DBG_PKG, "hw->seg is NULL, tables are not filled\n");
2940 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
2942 sect = ice_pkg_enum_section(hw->seg, &state, sid);
2946 case ICE_SID_XLT1_SW:
2947 case ICE_SID_XLT1_FD:
2948 case ICE_SID_XLT1_RSS:
2949 case ICE_SID_XLT1_ACL:
2950 case ICE_SID_XLT1_PE:
2951 xlt1 = (struct ice_xlt1_section *)sect;
2953 sect_len = LE16_TO_CPU(xlt1->count) *
2954 sizeof(*hw->blk[block_id].xlt1.t);
2955 dst = hw->blk[block_id].xlt1.t;
2956 dst_len = hw->blk[block_id].xlt1.count *
2957 sizeof(*hw->blk[block_id].xlt1.t);
2959 case ICE_SID_XLT2_SW:
2960 case ICE_SID_XLT2_FD:
2961 case ICE_SID_XLT2_RSS:
2962 case ICE_SID_XLT2_ACL:
2963 case ICE_SID_XLT2_PE:
2964 xlt2 = (struct ice_xlt2_section *)sect;
2965 src = (u8 *)xlt2->value;
2966 sect_len = LE16_TO_CPU(xlt2->count) *
2967 sizeof(*hw->blk[block_id].xlt2.t);
2968 dst = (u8 *)hw->blk[block_id].xlt2.t;
2969 dst_len = hw->blk[block_id].xlt2.count *
2970 sizeof(*hw->blk[block_id].xlt2.t);
2972 case ICE_SID_PROFID_TCAM_SW:
2973 case ICE_SID_PROFID_TCAM_FD:
2974 case ICE_SID_PROFID_TCAM_RSS:
2975 case ICE_SID_PROFID_TCAM_ACL:
2976 case ICE_SID_PROFID_TCAM_PE:
2977 pid = (struct ice_prof_id_section *)sect;
2978 src = (u8 *)pid->entry;
2979 sect_len = LE16_TO_CPU(pid->count) *
2980 sizeof(*hw->blk[block_id].prof.t);
2981 dst = (u8 *)hw->blk[block_id].prof.t;
2982 dst_len = hw->blk[block_id].prof.count *
2983 sizeof(*hw->blk[block_id].prof.t);
2985 case ICE_SID_PROFID_REDIR_SW:
2986 case ICE_SID_PROFID_REDIR_FD:
2987 case ICE_SID_PROFID_REDIR_RSS:
2988 case ICE_SID_PROFID_REDIR_ACL:
2989 case ICE_SID_PROFID_REDIR_PE:
2990 pr = (struct ice_prof_redir_section *)sect;
2991 src = pr->redir_value;
2992 sect_len = LE16_TO_CPU(pr->count) *
2993 sizeof(*hw->blk[block_id].prof_redir.t);
2994 dst = hw->blk[block_id].prof_redir.t;
2995 dst_len = hw->blk[block_id].prof_redir.count *
2996 sizeof(*hw->blk[block_id].prof_redir.t);
2998 case ICE_SID_FLD_VEC_SW:
2999 case ICE_SID_FLD_VEC_FD:
3000 case ICE_SID_FLD_VEC_RSS:
3001 case ICE_SID_FLD_VEC_ACL:
3002 case ICE_SID_FLD_VEC_PE:
3003 es = (struct ice_sw_fv_section *)sect;
3005 sect_len = LE16_TO_CPU(es->count) *
3006 hw->blk[block_id].es.fvw *
3007 sizeof(*hw->blk[block_id].es.t);
3008 dst = (u8 *)hw->blk[block_id].es.t;
3009 dst_len = hw->blk[block_id].es.count *
3010 hw->blk[block_id].es.fvw *
3011 sizeof(*hw->blk[block_id].es.t);
3017 /* if the section offset exceeds destination length, terminate
3020 if (offset > dst_len)
3023 /* if the sum of section size and offset exceed destination size
3024 * then we are out of bounds of the Hw table size for that PF.
3025 * Changing section length to fill the remaining table space
3028 if ((offset + sect_len) > dst_len)
3029 sect_len = dst_len - offset;
3031 ice_memcpy(dst + offset, src, sect_len, ICE_NONDMA_TO_NONDMA);
3033 sect = ice_pkg_enum_section(NULL, &state, sid);
3038 * ice_fill_blk_tbls - Read package content for tables of a block
3039 * @hw: pointer to the hardware structure
3040 * @block_id: The block ID which contains the tables to be copied
3042 * Reads the current package contents and populates the driver
3043 * database with the data it contains to allow for advanced driver
3046 static void ice_fill_blk_tbls(struct ice_hw *hw, enum ice_block block_id)
3048 ice_fill_tbl(hw, block_id, hw->blk[block_id].xlt1.sid);
3049 ice_fill_tbl(hw, block_id, hw->blk[block_id].xlt2.sid);
3050 ice_fill_tbl(hw, block_id, hw->blk[block_id].prof.sid);
3051 ice_fill_tbl(hw, block_id, hw->blk[block_id].prof_redir.sid);
3052 ice_fill_tbl(hw, block_id, hw->blk[block_id].es.sid);
3056 * ice_free_flow_profs - free flow profile entries
3057 * @hw: pointer to the hardware structure
3059 static void ice_free_flow_profs(struct ice_hw *hw)
3063 for (i = 0; i < ICE_BLK_COUNT; i++) {
3064 struct ice_flow_prof *p, *tmp;
3066 if (!&hw->fl_profs[i])
3069 /* This call is being made as part of resource deallocation
3070 * during unload. Lock acquire and release will not be
3073 LIST_FOR_EACH_ENTRY_SAFE(p, tmp, &hw->fl_profs[i],
3074 ice_flow_prof, l_entry) {
3075 struct ice_flow_entry *e, *t;
3077 LIST_FOR_EACH_ENTRY_SAFE(e, t, &p->entries,
3078 ice_flow_entry, l_entry)
3079 ice_flow_rem_entry(hw, ICE_FLOW_ENTRY_HNDL(e));
3081 LIST_DEL(&p->l_entry);
3083 ice_free(hw, p->acts);
3087 ice_destroy_lock(&hw->fl_profs_locks[i]);
3092 * ice_free_prof_map - frees the profile map
3093 * @hw: pointer to the hardware structure
3094 * @blk: the HW block which contains the profile map to be freed
3096 static void ice_free_prof_map(struct ice_hw *hw, enum ice_block blk)
3098 struct ice_prof_map *del, *tmp;
3100 if (LIST_EMPTY(&hw->blk[blk].es.prof_map))
3103 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &hw->blk[blk].es.prof_map,
3104 ice_prof_map, list) {
3105 LIST_DEL(&del->list);
3111 * ice_free_vsig_tbl - free complete VSIG table entries
3112 * @hw: pointer to the hardware structure
3113 * @blk: the HW block on which to free the VSIG table entries
3115 static void ice_free_vsig_tbl(struct ice_hw *hw, enum ice_block blk)
3119 if (!hw->blk[blk].xlt2.vsig_tbl)
3122 for (i = 1; i < ICE_MAX_VSIGS; i++)
3123 if (hw->blk[blk].xlt2.vsig_tbl[i].in_use)
3124 ice_vsig_free(hw, blk, i);
3128 * ice_free_hw_tbls - free hardware table memory
3129 * @hw: pointer to the hardware structure
3131 void ice_free_hw_tbls(struct ice_hw *hw)
3135 for (i = 0; i < ICE_BLK_COUNT; i++) {
3136 ice_free_prof_map(hw, (enum ice_block)i);
3137 ice_free_vsig_tbl(hw, (enum ice_block)i);
3138 ice_free(hw, hw->blk[i].xlt1.ptypes);
3139 ice_free(hw, hw->blk[i].xlt1.ptg_tbl);
3140 ice_free(hw, hw->blk[i].xlt1.t);
3141 ice_free(hw, hw->blk[i].xlt2.t);
3142 ice_free(hw, hw->blk[i].xlt2.vsig_tbl);
3143 ice_free(hw, hw->blk[i].xlt2.vsis);
3144 ice_free(hw, hw->blk[i].prof.t);
3145 ice_free(hw, hw->blk[i].prof_redir.t);
3146 ice_free(hw, hw->blk[i].es.t);
3147 ice_free(hw, hw->blk[i].es.ref_count);
3149 ice_free(hw, hw->blk[i].es.resource_used_hack);
3150 ice_free(hw, hw->blk[i].prof.resource_used_hack);
3151 ice_free(hw, hw->blk[i].es.written);
3154 ice_memset(hw->blk, 0, sizeof(hw->blk), ICE_NONDMA_MEM);
3156 ice_free_flow_profs(hw);
3160 * ice_init_flow_profs - init flow profile locks and list heads
3161 * @hw: pointer to the hardware structure
3163 static void ice_init_flow_profs(struct ice_hw *hw)
3167 for (i = 0; i < ICE_BLK_COUNT; i++) {
3168 ice_init_lock(&hw->fl_profs_locks[i]);
3169 INIT_LIST_HEAD(&hw->fl_profs[i]);
3174 * ice_init_sw_xlt1_db - init software XLT1 database from HW tables
3175 * @hw: pointer to the hardware structure
3176 * @blk: the HW block to initialize
3179 void ice_init_sw_xlt1_db(struct ice_hw *hw, enum ice_block blk)
3183 for (pt = 0; pt < hw->blk[blk].xlt1.count; pt++) {
3186 ptg = hw->blk[blk].xlt1.t[pt];
3187 if (ptg != ICE_DEFAULT_PTG) {
3188 ice_ptg_alloc_val(hw, blk, ptg);
3189 ice_ptg_add_mv_ptype(hw, blk, pt, ptg);
3195 * ice_init_sw_xlt2_db - init software XLT2 database from HW tables
3196 * @hw: pointer to the hardware structure
3197 * @blk: the HW block to initialize
3200 void ice_init_sw_xlt2_db(struct ice_hw *hw, enum ice_block blk)
3204 for (vsi = 0; vsi < hw->blk[blk].xlt2.count; vsi++) {
3207 vsig = hw->blk[blk].xlt2.t[vsi];
3209 ice_vsig_alloc_val(hw, blk, vsig);
3210 ice_vsig_add_mv_vsi(hw, blk, vsi, vsig);
3211 /* no changes at this time, since this has been
3212 * initialized from the original package
3214 hw->blk[blk].xlt2.vsis[vsi].changed = 0;
3220 * ice_init_sw_db - init software database from HW tables
3221 * @hw: pointer to the hardware structure
3224 void ice_init_sw_db(struct ice_hw *hw)
3228 for (i = 0; i < ICE_BLK_COUNT; i++) {
3229 ice_init_sw_xlt1_db(hw, (enum ice_block)i);
3230 ice_init_sw_xlt2_db(hw, (enum ice_block)i);
3235 * ice_init_hw_tbls - init hardware table memory
3236 * @hw: pointer to the hardware structure
3238 enum ice_status ice_init_hw_tbls(struct ice_hw *hw)
3242 ice_init_flow_profs(hw);
3244 for (i = 0; i < ICE_BLK_COUNT; i++) {
3245 struct ice_prof_redir *prof_redir = &hw->blk[i].prof_redir;
3246 struct ice_prof_tcam *prof = &hw->blk[i].prof;
3247 struct ice_xlt1 *xlt1 = &hw->blk[i].xlt1;
3248 struct ice_xlt2 *xlt2 = &hw->blk[i].xlt2;
3249 struct ice_es *es = &hw->blk[i].es;
3251 hw->blk[i].overwrite = blk_sizes[i].overwrite;
3252 es->reverse = blk_sizes[i].reverse;
3254 xlt1->sid = ice_blk_sids[i][ICE_SID_XLT1_OFF];
3255 xlt1->count = blk_sizes[i].xlt1;
3257 xlt1->ptypes = (struct ice_ptg_ptype *)
3258 ice_calloc(hw, xlt1->count, sizeof(*xlt1->ptypes));
3263 xlt1->ptg_tbl = (struct ice_ptg_entry *)
3264 ice_calloc(hw, ICE_MAX_PTGS, sizeof(*xlt1->ptg_tbl));
3269 xlt1->t = (u8 *)ice_calloc(hw, xlt1->count, sizeof(*xlt1->t));
3273 xlt2->sid = ice_blk_sids[i][ICE_SID_XLT2_OFF];
3274 xlt2->count = blk_sizes[i].xlt2;
3276 xlt2->vsis = (struct ice_vsig_vsi *)
3277 ice_calloc(hw, xlt2->count, sizeof(*xlt2->vsis));
3282 xlt2->vsig_tbl = (struct ice_vsig_entry *)
3283 ice_calloc(hw, xlt2->count, sizeof(*xlt2->vsig_tbl));
3284 if (!xlt2->vsig_tbl)
3287 xlt2->t = (u16 *)ice_calloc(hw, xlt2->count, sizeof(*xlt2->t));
3291 prof->sid = ice_blk_sids[i][ICE_SID_PR_OFF];
3292 prof->count = blk_sizes[i].prof_tcam;
3293 prof->max_prof_id = blk_sizes[i].prof_id;
3294 prof->cdid_bits = blk_sizes[i].prof_cdid_bits;
3295 prof->t = (struct ice_prof_tcam_entry *)
3296 ice_calloc(hw, prof->count, sizeof(*prof->t));
3301 prof_redir->sid = ice_blk_sids[i][ICE_SID_PR_REDIR_OFF];
3302 prof_redir->count = blk_sizes[i].prof_redir;
3303 prof_redir->t = (u8 *)ice_calloc(hw, prof_redir->count,
3304 sizeof(*prof_redir->t));
3309 es->sid = ice_blk_sids[i][ICE_SID_ES_OFF];
3310 es->count = blk_sizes[i].es;
3311 es->fvw = blk_sizes[i].fvw;
3312 es->t = (struct ice_fv_word *)
3313 ice_calloc(hw, es->count * es->fvw, sizeof(*es->t));
3318 es->ref_count = (u16 *)
3319 ice_calloc(hw, es->count, sizeof(*es->ref_count));
3321 es->written = (u8 *)
3322 ice_calloc(hw, es->count, sizeof(*es->written));
3327 es->resource_used_hack = (u8 *)
3328 ice_calloc(hw, hw->blk[i].es.count, sizeof(u8));
3330 if (!es->resource_used_hack)
3333 prof->resource_used_hack = (u8 *)ice_calloc(hw, prof->count,
3336 if (!prof->resource_used_hack)
3339 INIT_LIST_HEAD(&es->prof_map);
3341 /* Now that tables are allocated, read in package data */
3342 ice_fill_blk_tbls(hw, (enum ice_block)i);
3350 ice_free_hw_tbls(hw);
3351 return ICE_ERR_NO_MEMORY;
3355 * ice_prof_gen_key - generate profile ID key
3356 * @hw: pointer to the HW struct
3357 * @blk: the block in which to write profile ID to
3358 * @ptg: packet type group (PTG) portion of key
3359 * @vsig: VSIG portion of key
3360 * @cdid: cdid portion of key
3361 * @flags: flag portion of key
3362 * @vl_msk: valid mask
3363 * @dc_msk: don't care mask
3364 * @nm_msk: never match mask
3365 * @key: output of profile ID key
3367 static enum ice_status
3368 ice_prof_gen_key(struct ice_hw *hw, enum ice_block blk, u8 ptg, u16 vsig,
3369 u8 cdid, u16 flags, u8 vl_msk[ICE_TCAM_KEY_VAL_SZ],
3370 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ], u8 nm_msk[ICE_TCAM_KEY_VAL_SZ],
3371 u8 key[ICE_TCAM_KEY_SZ])
3373 struct ice_prof_id_key inkey;
3376 inkey.xlt2_cdid = CPU_TO_LE16(vsig);
3377 inkey.flags = CPU_TO_LE16(flags);
3379 switch (hw->blk[blk].prof.cdid_bits) {
3383 #define ICE_CD_2_M 0xC000U
3384 #define ICE_CD_2_S 14
3385 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_2_M);
3386 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_2_S);
3389 #define ICE_CD_4_M 0xF000U
3390 #define ICE_CD_4_S 12
3391 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_4_M);
3392 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_4_S);
3395 #define ICE_CD_8_M 0xFF00U
3396 #define ICE_CD_8_S 16
3397 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_8_M);
3398 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_8_S);
3401 ice_debug(hw, ICE_DBG_PKG, "Error in profile config\n");
3405 return ice_set_key(key, ICE_TCAM_KEY_SZ, (u8 *)&inkey, vl_msk, dc_msk,
3406 nm_msk, 0, ICE_TCAM_KEY_SZ / 2);
3410 * ice_tcam_write_entry - write TCAM entry
3411 * @hw: pointer to the HW struct
3412 * @blk: the block in which to write profile ID to
3413 * @idx: the entry index to write to
3414 * @prof_id: profile ID
3415 * @ptg: packet type group (PTG) portion of key
3416 * @vsig: VSIG portion of key
3417 * @cdid: cdid portion of key
3418 * @flags: flag portion of key
3419 * @vl_msk: valid mask
3420 * @dc_msk: don't care mask
3421 * @nm_msk: never match mask
3423 static enum ice_status
3424 ice_tcam_write_entry(struct ice_hw *hw, enum ice_block blk, u16 idx,
3425 u8 prof_id, u8 ptg, u16 vsig, u8 cdid, u16 flags,
3426 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ],
3427 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ],
3428 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ])
3430 struct ice_prof_tcam_entry;
3431 enum ice_status status;
3433 status = ice_prof_gen_key(hw, blk, ptg, vsig, cdid, flags, vl_msk,
3434 dc_msk, nm_msk, hw->blk[blk].prof.t[idx].key);
3436 hw->blk[blk].prof.t[idx].addr = CPU_TO_LE16(idx);
3437 hw->blk[blk].prof.t[idx].prof_id = prof_id;
3444 * ice_vsig_get_ref - returns number of VSIs belong to a VSIG
3445 * @hw: pointer to the hardware structure
3447 * @vsig: VSIG to query
3448 * @refs: pointer to variable to receive the reference count
3450 static enum ice_status
3451 ice_vsig_get_ref(struct ice_hw *hw, enum ice_block blk, u16 vsig, u16 *refs)
3453 u16 idx = vsig & ICE_VSIG_IDX_M;
3454 struct ice_vsig_vsi *ptr;
3457 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
3458 return ICE_ERR_DOES_NOT_EXIST;
3460 ptr = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
3463 ptr = ptr->next_vsi;
3470 * ice_get_ptg - get or allocate a ptg for a ptype
3471 * @hw: pointer to the hardware structure
3473 * @ptype: the ptype to retrieve the PTG for
3474 * @ptg: receives the PTG of the ptype
3475 * @add: receive boolean indicating whether PTG was added or not
3477 static enum ice_status
3478 ice_get_ptg(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 *ptg,
3481 enum ice_status status;
3483 *ptg = ICE_DEFAULT_PTG;
3486 status = ice_ptg_find_ptype(hw, blk, ptype, ptg);
3490 if (*ptg == ICE_DEFAULT_PTG) {
3491 /* need to allocate a PTG, and add ptype to it */
3492 *ptg = ice_ptg_alloc(hw, blk);
3493 if (*ptg == ICE_DEFAULT_PTG)
3494 return ICE_ERR_HW_TABLE;
3496 status = ice_ptg_add_mv_ptype(hw, blk, ptype, *ptg);
3498 return ICE_ERR_HW_TABLE;
3507 * ice_has_prof_vsig - check to see if VSIG has a specific profile
3508 * @hw: pointer to the hardware structure
3510 * @vsig: VSIG to check against
3511 * @hdl: profile handle
3514 ice_has_prof_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl)
3516 u16 idx = vsig & ICE_VSIG_IDX_M;
3517 struct ice_vsig_prof *ent;
3519 LIST_FOR_EACH_ENTRY(ent, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
3520 ice_vsig_prof, list) {
3521 if (ent->profile_cookie == hdl)
3525 ice_debug(hw, ICE_DBG_INIT,
3526 "Characteristic list for VSI group %d not found.\n",
3532 * ice_prof_bld_es - build profile ID extraction sequence changes
3533 * @hw: pointer to the HW struct
3534 * @blk: hardware block
3535 * @bld: the update package buffer build to add to
3536 * @chgs: the list of changes to make in hardware
3538 static enum ice_status
3539 ice_prof_bld_es(struct ice_hw *hw, enum ice_block blk,
3540 struct ice_buf_build *bld, struct LIST_HEAD_TYPE *chgs)
3542 u16 vec_size = hw->blk[blk].es.fvw * sizeof(struct ice_fv_word);
3543 struct ice_chs_chg *tmp;
3545 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
3546 if (tmp->type == ICE_PTG_ES_ADD && tmp->add_prof) {
3547 u16 off = tmp->prof_id * hw->blk[blk].es.fvw;
3548 struct ice_pkg_es *p;
3551 id = ice_sect_id(blk, ICE_VEC_TBL);
3552 p = (struct ice_pkg_es *)
3553 ice_pkg_buf_alloc_section(bld, id, sizeof(*p) +
3558 return ICE_ERR_MAX_LIMIT;
3560 p->count = CPU_TO_LE16(1);
3561 p->offset = CPU_TO_LE16(tmp->prof_id);
3563 ice_memcpy(p->es, &hw->blk[blk].es.t[off], vec_size,
3564 ICE_NONDMA_TO_NONDMA);
3572 * ice_prof_bld_tcam - build profile ID TCAM changes
3573 * @hw: pointer to the HW struct
3574 * @blk: hardware block
3575 * @bld: the update package buffer build to add to
3576 * @chgs: the list of changes to make in hardware
3578 static enum ice_status
3579 ice_prof_bld_tcam(struct ice_hw *hw, enum ice_block blk,
3580 struct ice_buf_build *bld, struct LIST_HEAD_TYPE *chgs)
3582 struct ice_chs_chg *tmp;
3584 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
3585 if (tmp->type == ICE_TCAM_ADD && tmp->add_tcam_idx) {
3586 struct ice_prof_id_section *p;
3589 id = ice_sect_id(blk, ICE_PROF_TCAM);
3590 p = (struct ice_prof_id_section *)
3591 ice_pkg_buf_alloc_section(bld, id, sizeof(*p));
3594 return ICE_ERR_MAX_LIMIT;
3596 p->count = CPU_TO_LE16(1);
3597 p->entry[0].addr = CPU_TO_LE16(tmp->tcam_idx);
3598 p->entry[0].prof_id = tmp->prof_id;
3600 ice_memcpy(p->entry[0].key,
3601 &hw->blk[blk].prof.t[tmp->tcam_idx].key,
3602 sizeof(hw->blk[blk].prof.t->key),
3603 ICE_NONDMA_TO_NONDMA);
3611 * ice_prof_bld_xlt1 - build XLT1 changes
3612 * @blk: hardware block
3613 * @bld: the update package buffer build to add to
3614 * @chgs: the list of changes to make in hardware
3616 static enum ice_status
3617 ice_prof_bld_xlt1(enum ice_block blk, struct ice_buf_build *bld,
3618 struct LIST_HEAD_TYPE *chgs)
3620 struct ice_chs_chg *tmp;
3622 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
3623 if (tmp->type == ICE_PTG_ES_ADD && tmp->add_ptg) {
3624 struct ice_xlt1_section *p;
3627 id = ice_sect_id(blk, ICE_XLT1);
3628 p = (struct ice_xlt1_section *)
3629 ice_pkg_buf_alloc_section(bld, id, sizeof(*p));
3632 return ICE_ERR_MAX_LIMIT;
3634 p->count = CPU_TO_LE16(1);
3635 p->offset = CPU_TO_LE16(tmp->ptype);
3636 p->value[0] = tmp->ptg;
3644 * ice_prof_bld_xlt2 - build XLT2 changes
3645 * @blk: hardware block
3646 * @bld: the update package buffer build to add to
3647 * @chgs: the list of changes to make in hardware
3649 static enum ice_status
3650 ice_prof_bld_xlt2(enum ice_block blk, struct ice_buf_build *bld,
3651 struct LIST_HEAD_TYPE *chgs)
3653 struct ice_chs_chg *tmp;
3655 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
3658 if (tmp->type == ICE_VSIG_ADD)
3660 else if (tmp->type == ICE_VSI_MOVE)
3662 else if (tmp->type == ICE_VSIG_REM)
3666 struct ice_xlt2_section *p;
3669 id = ice_sect_id(blk, ICE_XLT2);
3670 p = (struct ice_xlt2_section *)
3671 ice_pkg_buf_alloc_section(bld, id, sizeof(*p));
3674 return ICE_ERR_MAX_LIMIT;
3676 p->count = CPU_TO_LE16(1);
3677 p->offset = CPU_TO_LE16(tmp->vsi);
3678 p->value[0] = CPU_TO_LE16(tmp->vsig);
3686 * ice_upd_prof_hw - update hardware using the change list
3687 * @hw: pointer to the HW struct
3688 * @blk: hardware block
3689 * @chgs: the list of changes to make in hardware
3691 static enum ice_status
3692 ice_upd_prof_hw(struct ice_hw *hw, enum ice_block blk,
3693 struct LIST_HEAD_TYPE *chgs)
3695 struct ice_buf_build *b;
3696 struct ice_chs_chg *tmp;
3697 enum ice_status status;
3705 /* count number of sections we need */
3706 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
3707 switch (tmp->type) {
3708 case ICE_PTG_ES_ADD:
3726 sects = xlt1 + xlt2 + tcam + es;
3731 /* Build update package buffer */
3732 b = ice_pkg_buf_alloc(hw);
3734 return ICE_ERR_NO_MEMORY;
3736 status = ice_pkg_buf_reserve_section(b, sects);
3740 /* Preserve order of table update: ES, TCAM, PTG, VSIG */
3742 status = ice_prof_bld_es(hw, blk, b, chgs);
3748 status = ice_prof_bld_tcam(hw, blk, b, chgs);
3754 status = ice_prof_bld_xlt1(blk, b, chgs);
3760 status = ice_prof_bld_xlt2(blk, b, chgs);
3765 /* After package buffer build check if the section count in buffer is
3766 * non-zero and matches the number of sections detected for package
3769 pkg_sects = ice_pkg_buf_get_active_sections(b);
3770 if (!pkg_sects || pkg_sects != sects) {
3771 status = ICE_ERR_INVAL_SIZE;
3775 /* update package */
3776 status = ice_update_pkg(hw, ice_pkg_buf(b), 1);
3777 if (status == ICE_ERR_AQ_ERROR)
3778 ice_debug(hw, ICE_DBG_INIT, "Unable to update HW profile.");
3781 ice_pkg_buf_free(hw, b);
3786 * ice_add_prof - add profile
3787 * @hw: pointer to the HW struct
3788 * @blk: hardware block
3789 * @id: profile tracking ID
3790 * @ptypes: array of bitmaps indicating ptypes (ICE_FLOW_PTYPE_MAX bits)
3791 * @es: extraction sequence (length of array is determined by the block)
3793 * This function registers a profile, which matches a set of PTYPES with a
3794 * particular extraction sequence. While the hardware profile is allocated
3795 * it will not be written until the first call to ice_add_flow that specifies
3796 * the ID value used here.
3799 ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64 id, u8 ptypes[],
3800 struct ice_fv_word *es)
3802 u32 bytes = DIVIDE_AND_ROUND_UP(ICE_FLOW_PTYPE_MAX, BITS_PER_BYTE);
3803 struct ice_prof_map *prof;
3804 enum ice_status status;
3808 /* search for existing profile */
3809 status = ice_find_prof_id(hw, blk, es, &prof_id);
3811 /* allocate profile ID */
3812 status = ice_alloc_prof_id(hw, blk, &prof_id);
3814 goto err_ice_add_prof;
3816 /* and write new es */
3817 ice_write_es(hw, blk, prof_id, es);
3820 ice_prof_inc_ref(hw, blk, prof_id);
3822 /* add profile info */
3824 prof = (struct ice_prof_map *)ice_malloc(hw, sizeof(*prof));
3826 goto err_ice_add_prof;
3828 prof->profile_cookie = id;
3829 prof->prof_id = prof_id;
3830 prof->ptype_count = 0;
3833 /* build list of ptgs */
3834 while (bytes && prof->ptype_count < ICE_MAX_PTYPE_PER_PROFILE) {
3837 if (!ptypes[byte]) {
3842 /* Examine 8 bits per byte */
3843 for (bit = 0; bit < 8; bit++) {
3844 if (ptypes[byte] & 1 << bit) {
3848 ptype = byte * 8 + bit;
3849 if (ptype < ICE_FLOW_PTYPE_MAX) {
3850 prof->ptype[prof->ptype_count] = ptype;
3852 if (++prof->ptype_count >=
3853 ICE_MAX_PTYPE_PER_PROFILE)
3857 /* nothing left in byte, then exit */
3858 m = ~((1 << (bit + 1)) - 1);
3859 if (!(ptypes[byte] & m))
3867 LIST_ADD(&prof->list, &hw->blk[blk].es.prof_map);
3876 * ice_search_prof_id - Search for a profile tracking ID
3877 * @hw: pointer to the HW struct
3878 * @blk: hardware block
3879 * @id: profile tracking ID
3881 * This will search for a profile tracking ID which was previously added.
3883 struct ice_prof_map *
3884 ice_search_prof_id(struct ice_hw *hw, enum ice_block blk, u64 id)
3886 struct ice_prof_map *entry = NULL;
3887 struct ice_prof_map *map;
3889 LIST_FOR_EACH_ENTRY(map, &hw->blk[blk].es.prof_map, ice_prof_map,
3891 if (map->profile_cookie == id) {
3901 * ice_set_prof_context - Set context for a given profile
3902 * @hw: pointer to the HW struct
3903 * @blk: hardware block
3904 * @id: profile tracking ID
3907 struct ice_prof_map *
3908 ice_set_prof_context(struct ice_hw *hw, enum ice_block blk, u64 id, u64 cntxt)
3910 struct ice_prof_map *entry;
3912 entry = ice_search_prof_id(hw, blk, id);
3914 entry->context = cntxt;
3920 * ice_get_prof_context - Get context for a given profile
3921 * @hw: pointer to the HW struct
3922 * @blk: hardware block
3923 * @id: profile tracking ID
3924 * @cntxt: pointer to variable to receive the context
3926 struct ice_prof_map *
3927 ice_get_prof_context(struct ice_hw *hw, enum ice_block blk, u64 id, u64 *cntxt)
3929 struct ice_prof_map *entry;
3931 entry = ice_search_prof_id(hw, blk, id);
3933 *cntxt = entry->context;
3939 * ice_vsig_prof_id_count - count profiles in a VSIG
3940 * @hw: pointer to the HW struct
3941 * @blk: hardware block
3942 * @vsig: VSIG to remove the profile from
3945 ice_vsig_prof_id_count(struct ice_hw *hw, enum ice_block blk, u16 vsig)
3947 u16 idx = vsig & ICE_VSIG_IDX_M, count = 0;
3948 struct ice_vsig_prof *p;
3950 LIST_FOR_EACH_ENTRY(p, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
3951 ice_vsig_prof, list) {
3959 * ice_rel_tcam_idx - release a TCAM index
3960 * @hw: pointer to the HW struct
3961 * @blk: hardware block
3962 * @idx: the index to release
3964 static enum ice_status
3965 ice_rel_tcam_idx(struct ice_hw *hw, enum ice_block blk, u16 idx)
3967 /* Masks to invoke a never match entry */
3968 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
3969 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFE, 0xFF, 0xFF, 0xFF, 0xFF };
3970 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x01, 0x00, 0x00, 0x00, 0x00 };
3971 enum ice_status status;
3973 /* write the TCAM entry */
3974 status = ice_tcam_write_entry(hw, blk, idx, 0, 0, 0, 0, 0, vl_msk,
3979 /* release the TCAM entry */
3980 status = ice_free_tcam_ent(hw, blk, idx);
3986 * ice_rem_prof_id - remove one profile from a VSIG
3987 * @hw: pointer to the HW struct
3988 * @blk: hardware block
3989 * @prof: pointer to profile structure to remove
3991 static enum ice_status
3992 ice_rem_prof_id(struct ice_hw *hw, enum ice_block blk,
3993 struct ice_vsig_prof *prof)
3995 enum ice_status status;
3998 for (i = 0; i < prof->tcam_count; i++) {
3999 prof->tcam[i].in_use = false;
4000 status = ice_rel_tcam_idx(hw, blk, prof->tcam[i].tcam_idx);
4002 return ICE_ERR_HW_TABLE;
4009 * ice_rem_vsig - remove VSIG
4010 * @hw: pointer to the HW struct
4011 * @blk: hardware block
4012 * @vsig: the VSIG to remove
4013 * @chg: the change list
4015 static enum ice_status
4016 ice_rem_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig,
4017 struct LIST_HEAD_TYPE *chg)
4019 u16 idx = vsig & ICE_VSIG_IDX_M;
4020 struct ice_vsig_vsi *vsi_cur;
4021 struct ice_vsig_prof *d, *t;
4022 enum ice_status status;
4024 /* remove TCAM entries */
4025 LIST_FOR_EACH_ENTRY_SAFE(d, t,
4026 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4027 ice_vsig_prof, list) {
4028 status = ice_rem_prof_id(hw, blk, d);
4036 /* Move all VSIS associated with this VSIG to the default VSIG */
4037 vsi_cur = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
4042 struct ice_vsig_vsi *tmp = vsi_cur->next_vsi;
4043 struct ice_chs_chg *p;
4045 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4047 goto err_ice_rem_vsig;
4049 p->type = ICE_VSIG_REM;
4050 p->orig_vsig = vsig;
4051 p->vsig = ICE_DEFAULT_VSIG;
4052 p->vsi = vsi_cur - hw->blk[blk].xlt2.vsis;
4054 LIST_ADD(&p->list_entry, chg);
4056 status = ice_vsig_free(hw, blk, vsig);
4066 /* the caller will free up the change list */
4067 return ICE_ERR_NO_MEMORY;
4071 * ice_rem_prof_id_vsig - remove a specific profile from a VSIG
4072 * @hw: pointer to the HW struct
4073 * @blk: hardware block
4074 * @vsig: VSIG to remove the profile from
4075 * @hdl: profile handle indicating which profile to remove
4076 * @chg: list to receive a record of changes
4078 static enum ice_status
4079 ice_rem_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl,
4080 struct LIST_HEAD_TYPE *chg)
4082 u16 idx = vsig & ICE_VSIG_IDX_M;
4083 struct ice_vsig_prof *p, *t;
4084 enum ice_status status;
4086 LIST_FOR_EACH_ENTRY_SAFE(p, t,
4087 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4088 ice_vsig_prof, list) {
4089 if (p->profile_cookie == hdl) {
4090 if (ice_vsig_prof_id_count(hw, blk, vsig) == 1)
4091 /* this is the last profile, remove the VSIG */
4092 return ice_rem_vsig(hw, blk, vsig, chg);
4094 status = ice_rem_prof_id(hw, blk, p);
4103 return ICE_ERR_DOES_NOT_EXIST;
4107 * ice_rem_flow_all - remove all flows with a particular profile
4108 * @hw: pointer to the HW struct
4109 * @blk: hardware block
4110 * @id: profile tracking ID
4112 static enum ice_status
4113 ice_rem_flow_all(struct ice_hw *hw, enum ice_block blk, u64 id)
4115 struct ice_chs_chg *del, *tmp;
4116 struct LIST_HEAD_TYPE chg;
4117 enum ice_status status;
4120 INIT_LIST_HEAD(&chg);
4122 for (i = 1; i < ICE_MAX_VSIGS; i++) {
4123 if (hw->blk[blk].xlt2.vsig_tbl[i].in_use) {
4124 if (ice_has_prof_vsig(hw, blk, i, id)) {
4125 status = ice_rem_prof_id_vsig(hw, blk, i, id,
4128 goto err_ice_rem_flow_all;
4133 status = ice_upd_prof_hw(hw, blk, &chg);
4135 err_ice_rem_flow_all:
4136 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
4137 LIST_DEL(&del->list_entry);
4145 * ice_rem_prof - remove profile
4146 * @hw: pointer to the HW struct
4147 * @blk: hardware block
4148 * @id: profile tracking ID
4150 * This will remove the profile specified by the ID parameter, which was
4151 * previously created through ice_add_prof. If any existing entries
4152 * are associated with this profile, they will be removed as well.
4154 enum ice_status ice_rem_prof(struct ice_hw *hw, enum ice_block blk, u64 id)
4156 enum ice_status status;
4157 struct ice_prof_map *pmap;
4159 pmap = ice_search_prof_id(hw, blk, id);
4161 return ICE_ERR_DOES_NOT_EXIST;
4163 status = ice_free_prof_id(hw, blk, pmap->prof_id);
4168 /* remove all flows with this profile */
4169 status = ice_rem_flow_all(hw, blk, pmap->profile_cookie);
4172 /* dereference profile, and possibly remove */
4173 ice_prof_dec_ref(hw, blk, pmap->prof_id);
4175 LIST_DEL(&pmap->list);
4182 * ice_get_prof_ptgs - get ptgs for profile
4183 * @hw: pointer to the HW struct
4184 * @blk: hardware block
4185 * @hdl: profile handle
4188 static enum ice_status
4189 ice_get_prof_ptgs(struct ice_hw *hw, enum ice_block blk, u64 hdl,
4190 struct LIST_HEAD_TYPE *chg)
4192 struct ice_prof_map *map;
4193 struct ice_chs_chg *p;
4196 /* Get the details on the profile specified by the handle ID */
4197 map = ice_search_prof_id(hw, blk, hdl);
4199 return ICE_ERR_DOES_NOT_EXIST;
4201 for (i = 0; i < map->ptype_count; i++) {
4202 enum ice_status status;
4206 status = ice_get_ptg(hw, blk, map->ptype[i], &ptg, &add);
4208 goto err_ice_get_prof_ptgs;
4210 if (add || !hw->blk[blk].es.written[map->prof_id]) {
4211 /* add PTG to change list */
4212 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4214 goto err_ice_get_prof_ptgs;
4216 p->type = ICE_PTG_ES_ADD;
4217 p->ptype = map->ptype[i];
4221 p->add_prof = !hw->blk[blk].es.written[map->prof_id];
4222 p->prof_id = map->prof_id;
4224 hw->blk[blk].es.written[map->prof_id] = true;
4226 LIST_ADD(&p->list_entry, chg);
4232 err_ice_get_prof_ptgs:
4233 /* let caller clean up the change list */
4234 return ICE_ERR_NO_MEMORY;
4238 * ice_get_profs_vsig - get a copy of the list of profiles from a VSIG
4239 * @hw: pointer to the HW struct
4240 * @blk: hardware block
4241 * @vsig: VSIG from which to copy the list
4244 * This routine makes a copy of the list of profiles in the specified VSIG.
4246 static enum ice_status
4247 ice_get_profs_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig,
4248 struct LIST_HEAD_TYPE *lst)
4250 struct ice_vsig_prof *ent1, *ent2;
4251 u16 idx = vsig & ICE_VSIG_IDX_M;
4253 LIST_FOR_EACH_ENTRY(ent1, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4254 ice_vsig_prof, list) {
4255 struct ice_vsig_prof *p;
4257 /* copy to the input list */
4258 p = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*p));
4260 goto err_ice_get_profs_vsig;
4262 ice_memcpy(p, ent1, sizeof(*p), ICE_NONDMA_TO_NONDMA);
4264 LIST_ADD(&p->list, lst);
4269 err_ice_get_profs_vsig:
4270 LIST_FOR_EACH_ENTRY_SAFE(ent1, ent2, lst, ice_vsig_prof, list) {
4271 LIST_DEL(&ent1->list);
4275 return ICE_ERR_NO_MEMORY;
4279 * ice_add_prof_to_lst - add profile entry to a list
4280 * @hw: pointer to the HW struct
4281 * @blk: hardware block
4282 * @lst: the list to be added to
4283 * @hdl: profile handle of entry to add
4285 static enum ice_status
4286 ice_add_prof_to_lst(struct ice_hw *hw, enum ice_block blk,
4287 struct LIST_HEAD_TYPE *lst, u64 hdl)
4289 struct ice_vsig_prof *p;
4290 struct ice_prof_map *map;
4293 map = ice_search_prof_id(hw, blk, hdl);
4295 return ICE_ERR_DOES_NOT_EXIST;
4297 p = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*p));
4299 return ICE_ERR_NO_MEMORY;
4301 p->profile_cookie = map->profile_cookie;
4302 p->prof_id = map->prof_id;
4303 p->tcam_count = map->ptype_count;
4305 for (i = 0; i < map->ptype_count; i++) {
4308 p->tcam[i].prof_id = map->prof_id;
4309 p->tcam[i].tcam_idx = ICE_INVALID_TCAM;
4311 ice_ptg_find_ptype(hw, blk, map->ptype[i], &ptg);
4313 p->tcam[i].ptg = ptg;
4316 LIST_ADD(&p->list, lst);
4322 * ice_move_vsi - move VSI to another VSIG
4323 * @hw: pointer to the HW struct
4324 * @blk: hardware block
4325 * @vsi: the VSI to move
4326 * @vsig: the VSIG to move the VSI to
4327 * @chg: the change list
4329 static enum ice_status
4330 ice_move_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig,
4331 struct LIST_HEAD_TYPE *chg)
4333 enum ice_status status;
4334 struct ice_chs_chg *p;
4337 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4339 return ICE_ERR_NO_MEMORY;
4341 status = ice_vsig_find_vsi(hw, blk, vsi, &orig_vsig);
4343 status = ice_vsig_add_mv_vsi(hw, blk, vsi, vsig);
4349 p->type = ICE_VSI_MOVE;
4351 p->orig_vsig = orig_vsig;
4354 LIST_ADD(&p->list_entry, chg);
4360 * ice_prof_tcam_ena_dis - add enable or disable TCAM change
4361 * @hw: pointer to the HW struct
4362 * @blk: hardware block
4363 * @enable: true to enable, false to disable
4364 * @vsig: the vsig of the TCAM entry
4365 * @tcam: pointer the TCAM info structure of the TCAM to disable
4366 * @chg: the change list
4368 * This function appends an enable or disable TCAM entry in the change log
4370 static enum ice_status
4371 ice_prof_tcam_ena_dis(struct ice_hw *hw, enum ice_block blk, bool enable,
4372 u16 vsig, struct ice_tcam_inf *tcam,
4373 struct LIST_HEAD_TYPE *chg)
4375 enum ice_status status;
4376 struct ice_chs_chg *p;
4378 /* Default: enable means change the low flag bit to don't care */
4379 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x01, 0x00, 0x00, 0x00, 0x00 };
4380 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
4381 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x01, 0x00, 0x00, 0x00, 0x00 };
4383 /* If disabled, change the low flag bit to never match */
4389 /* add TCAM to change list */
4390 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4392 return ICE_ERR_NO_MEMORY;
4394 status = ice_tcam_write_entry(hw, blk, tcam->tcam_idx, tcam->prof_id,
4395 tcam->ptg, vsig, 0, 0, vl_msk, dc_msk,
4398 goto err_ice_prof_tcam_ena_dis;
4400 tcam->in_use = enable;
4402 p->type = ICE_TCAM_ADD;
4403 p->add_tcam_idx = true;
4404 p->prof_id = tcam->prof_id;
4407 p->tcam_idx = tcam->tcam_idx;
4410 LIST_ADD(&p->list_entry, chg);
4414 err_ice_prof_tcam_ena_dis:
4420 * ice_adj_prof_priorities - adjust profile based on priorities
4421 * @hw: pointer to the HW struct
4422 * @blk: hardware block
4423 * @vsig: the VSIG for which to adjust profile priorities
4424 * @chg: the change list
4426 static enum ice_status
4427 ice_adj_prof_priorities(struct ice_hw *hw, enum ice_block blk, u16 vsig,
4428 struct LIST_HEAD_TYPE *chg)
4430 ice_declare_bitmap(ptgs_used, ICE_XLT1_CNT);
4431 struct ice_vsig_prof *t;
4432 enum ice_status status;
4435 ice_memset(ptgs_used, 0, sizeof(ptgs_used), ICE_NONDMA_MEM);
4436 idx = vsig & ICE_VSIG_IDX_M;
4438 /* Priority is based on the order in which the profiles are added. The
4439 * newest added profile has highest priority and the oldest added
4440 * profile has the lowest priority. Since the profile property list for
4441 * a VSIG is sorted from newest to oldest, this code traverses the list
4442 * in order and enables the first of each PTG that it finds (that is not
4443 * already enabled); it also disables any duplicate PTGs that it finds
4444 * in the older profiles (that are currently enabled).
4447 LIST_FOR_EACH_ENTRY(t, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4448 ice_vsig_prof, list) {
4451 for (i = 0; i < t->tcam_count; i++) {
4452 /* Scan the priorities from newest to oldest.
4453 * Make sure that the newest profiles take priority.
4455 if (ice_is_bit_set(ptgs_used, t->tcam[i].ptg) &&
4456 t->tcam[i].in_use) {
4457 /* need to mark this PTG as never match, as it
4458 * was already in use and therefore duplicate
4459 * (and lower priority)
4461 status = ice_prof_tcam_ena_dis(hw, blk, false,
4467 } else if (!ice_is_bit_set(ptgs_used, t->tcam[i].ptg) &&
4468 !t->tcam[i].in_use) {
4469 /* need to enable this PTG, as it in not in use
4470 * and not enabled (highest priority)
4472 status = ice_prof_tcam_ena_dis(hw, blk, true,
4480 /* keep track of used ptgs */
4481 ice_set_bit(t->tcam[i].ptg, ptgs_used);
4489 * ice_add_prof_id_vsig - add profile to VSIG
4490 * @hw: pointer to the HW struct
4491 * @blk: hardware block
4492 * @vsig: the VSIG to which this profile is to be added
4493 * @hdl: the profile handle indicating the profile to add
4494 * @chg: the change list
4496 static enum ice_status
4497 ice_add_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl,
4498 struct LIST_HEAD_TYPE *chg)
4500 /* Masks that ignore flags */
4501 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4502 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0x00, 0x00, 0x00 };
4503 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
4504 struct ice_prof_map *map;
4505 struct ice_vsig_prof *t;
4506 struct ice_chs_chg *p;
4509 /* Get the details on the profile specified by the handle ID */
4510 map = ice_search_prof_id(hw, blk, hdl);
4512 return ICE_ERR_DOES_NOT_EXIST;
4514 /* Error, if this VSIG already has this profile */
4515 if (ice_has_prof_vsig(hw, blk, vsig, hdl))
4516 return ICE_ERR_ALREADY_EXISTS;
4518 /* new VSIG profile structure */
4519 t = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*t));
4521 goto err_ice_add_prof_id_vsig;
4523 t->profile_cookie = map->profile_cookie;
4524 t->prof_id = map->prof_id;
4525 t->tcam_count = map->ptype_count;
4527 /* create TCAM entries */
4528 for (i = 0; i < map->ptype_count; i++) {
4529 enum ice_status status;
4534 /* If properly sequenced, we should never have to allocate new
4537 status = ice_get_ptg(hw, blk, map->ptype[i], &ptg, &add);
4539 goto err_ice_add_prof_id_vsig;
4541 /* add TCAM to change list */
4542 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4544 goto err_ice_add_prof_id_vsig;
4546 /* allocate the TCAM entry index */
4547 status = ice_alloc_tcam_ent(hw, blk, &tcam_idx);
4550 goto err_ice_add_prof_id_vsig;
4553 t->tcam[i].ptg = ptg;
4554 t->tcam[i].prof_id = map->prof_id;
4555 t->tcam[i].tcam_idx = tcam_idx;
4556 t->tcam[i].in_use = true;
4558 p->type = ICE_TCAM_ADD;
4559 p->add_tcam_idx = true;
4560 p->prof_id = t->tcam[i].prof_id;
4561 p->ptg = t->tcam[i].ptg;
4563 p->tcam_idx = t->tcam[i].tcam_idx;
4565 /* write the TCAM entry */
4566 status = ice_tcam_write_entry(hw, blk, t->tcam[i].tcam_idx,
4568 t->tcam[i].ptg, vsig, 0, 0,
4569 vl_msk, dc_msk, nm_msk);
4571 goto err_ice_add_prof_id_vsig;
4574 LIST_ADD(&p->list_entry, chg);
4577 /* add profile to VSIG */
4579 &hw->blk[blk].xlt2.vsig_tbl[(vsig & ICE_VSIG_IDX_M)].prop_lst);
4583 err_ice_add_prof_id_vsig:
4584 /* let caller clean up the change list */
4586 return ICE_ERR_NO_MEMORY;
4590 * ice_create_prof_id_vsig - add a new VSIG with a single profile
4591 * @hw: pointer to the HW struct
4592 * @blk: hardware block
4593 * @vsi: the initial VSI that will be in VSIG
4594 * @hdl: the profile handle of the profile that will be added to the VSIG
4595 * @chg: the change list
4597 static enum ice_status
4598 ice_create_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl,
4599 struct LIST_HEAD_TYPE *chg)
4601 enum ice_status status;
4602 struct ice_chs_chg *p;
4605 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4607 return ICE_ERR_NO_MEMORY;
4609 new_vsig = ice_vsig_alloc(hw, blk);
4611 status = ICE_ERR_HW_TABLE;
4612 goto err_ice_create_prof_id_vsig;
4615 status = ice_move_vsi(hw, blk, vsi, new_vsig, chg);
4617 goto err_ice_create_prof_id_vsig;
4619 status = ice_add_prof_id_vsig(hw, blk, new_vsig, hdl, chg);
4621 goto err_ice_create_prof_id_vsig;
4623 p->type = ICE_VSIG_ADD;
4625 p->orig_vsig = ICE_DEFAULT_VSIG;
4628 LIST_ADD(&p->list_entry, chg);
4632 err_ice_create_prof_id_vsig:
4633 /* let caller clean up the change list */
4639 * ice_create_vsig_from_list - create a new VSIG with a list of profiles
4640 * @hw: pointer to the HW struct
4641 * @blk: hardware block
4642 * @vsi: the initial VSI that will be in VSIG
4643 * @lst: the list of profile that will be added to the VSIG
4644 * @chg: the change list
4646 static enum ice_status
4647 ice_create_vsig_from_lst(struct ice_hw *hw, enum ice_block blk, u16 vsi,
4648 struct LIST_HEAD_TYPE *lst, struct LIST_HEAD_TYPE *chg)
4650 struct ice_vsig_prof *t;
4651 enum ice_status status;
4654 vsig = ice_vsig_alloc(hw, blk);
4656 return ICE_ERR_HW_TABLE;
4658 status = ice_move_vsi(hw, blk, vsi, vsig, chg);
4662 LIST_FOR_EACH_ENTRY(t, lst, ice_vsig_prof, list) {
4663 status = ice_add_prof_id_vsig(hw, blk, vsig, t->profile_cookie,
4673 * ice_find_prof_vsig - find a VSIG with a specific profile handle
4674 * @hw: pointer to the HW struct
4675 * @blk: hardware block
4676 * @hdl: the profile handle of the profile to search for
4677 * @vsig: returns the VSIG with the matching profile
4680 ice_find_prof_vsig(struct ice_hw *hw, enum ice_block blk, u64 hdl, u16 *vsig)
4682 struct ice_vsig_prof *t;
4683 struct LIST_HEAD_TYPE lst;
4684 enum ice_status status;
4686 INIT_LIST_HEAD(&lst);
4688 t = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*t));
4692 t->profile_cookie = hdl;
4693 LIST_ADD(&t->list, &lst);
4695 status = ice_find_dup_props_vsig(hw, blk, &lst, vsig);
4700 return status == ICE_SUCCESS;
4704 * ice_add_prof_id_flow - add profile flow
4705 * @hw: pointer to the HW struct
4706 * @blk: hardware block
4707 * @vsi: the VSI to enable with the profile specified by ID
4708 * @hdl: profile handle
4710 * Calling this function will update the hardware tables to enable the
4711 * profile indicated by the ID parameter for the VSIs specified in the VSI
4712 * array. Once successfully called, the flow will be enabled.
4715 ice_add_prof_id_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl)
4717 struct ice_vsig_prof *tmp1, *del1;
4718 struct LIST_HEAD_TYPE union_lst;
4719 struct ice_chs_chg *tmp, *del;
4720 struct LIST_HEAD_TYPE chrs;
4721 struct LIST_HEAD_TYPE chg;
4722 enum ice_status status;
4723 u16 vsig, or_vsig = 0;
4725 INIT_LIST_HEAD(&union_lst);
4726 INIT_LIST_HEAD(&chrs);
4727 INIT_LIST_HEAD(&chg);
4729 status = ice_get_prof_ptgs(hw, blk, hdl, &chg);
4733 /* determine if VSI is already part of a VSIG */
4734 status = ice_vsig_find_vsi(hw, blk, vsi, &vsig);
4735 if (!status && vsig) {
4742 /* make sure that there is no overlap/conflict between the new
4743 * characteristics and the existing ones; we don't support that
4746 if (ice_has_prof_vsig(hw, blk, vsig, hdl)) {
4747 status = ICE_ERR_ALREADY_EXISTS;
4748 goto err_ice_add_prof_id_flow;
4751 /* last VSI in the VSIG? */
4752 status = ice_vsig_get_ref(hw, blk, vsig, &ref);
4754 goto err_ice_add_prof_id_flow;
4755 only_vsi = (ref == 1);
4757 /* create a union of the current profiles and the one being
4760 status = ice_get_profs_vsig(hw, blk, vsig, &union_lst);
4762 goto err_ice_add_prof_id_flow;
4764 status = ice_add_prof_to_lst(hw, blk, &union_lst, hdl);
4766 goto err_ice_add_prof_id_flow;
4768 /* search for an existing VSIG with an exact charc match */
4769 status = ice_find_dup_props_vsig(hw, blk, &union_lst, &vsig);
4771 /* found an exact match */
4772 /* move vsi to the VSIG that matches */
4773 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
4775 goto err_ice_add_prof_id_flow;
4777 /* remove original VSIG if we just moved the only VSI
4781 status = ice_rem_vsig(hw, blk, or_vsig, &chg);
4783 goto err_ice_add_prof_id_flow;
4785 } else if (only_vsi) {
4786 /* If the original VSIG only contains one VSI, then it
4787 * will be the requesting VSI. In this case the VSI is
4788 * not sharing entries and we can simply add the new
4789 * profile to the VSIG.
4791 status = ice_add_prof_id_vsig(hw, blk, vsig, hdl, &chg);
4793 goto err_ice_add_prof_id_flow;
4795 /* Adjust priorities */
4796 status = ice_adj_prof_priorities(hw, blk, vsig, &chg);
4798 goto err_ice_add_prof_id_flow;
4800 /* No match, so we need a new VSIG */
4801 status = ice_create_vsig_from_lst(hw, blk, vsi,
4804 goto err_ice_add_prof_id_flow;
4806 /* Adjust priorities */
4807 status = ice_adj_prof_priorities(hw, blk, vsig, &chg);
4809 goto err_ice_add_prof_id_flow;
4812 /* need to find or add a VSIG */
4813 /* search for an existing VSIG with an exact charc match */
4814 if (ice_find_prof_vsig(hw, blk, hdl, &vsig)) {
4815 /* found an exact match */
4816 /* add or move VSI to the VSIG that matches */
4817 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
4819 goto err_ice_add_prof_id_flow;
4821 /* we did not find an exact match */
4822 /* we need to add a VSIG */
4823 status = ice_create_prof_id_vsig(hw, blk, vsi, hdl,
4826 goto err_ice_add_prof_id_flow;
4830 /* update hardware */
4832 status = ice_upd_prof_hw(hw, blk, &chg);
4834 err_ice_add_prof_id_flow:
4835 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
4836 LIST_DEL(&del->list_entry);
4840 LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, &union_lst, ice_vsig_prof, list) {
4841 LIST_DEL(&del1->list);
4845 LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, &chrs, ice_vsig_prof, list) {
4846 LIST_DEL(&del1->list);
4854 * ice_add_flow - add flow
4855 * @hw: pointer to the HW struct
4856 * @blk: hardware block
4857 * @vsi: array of VSIs to enable with the profile specified by ID
4858 * @count: number of elements in the VSI array
4859 * @id: profile tracking ID
4861 * Calling this function will update the hardware tables to enable the
4862 * profile indicated by the ID parameter for the VSIs specified in the VSI
4863 * array. Once successfully called, the flow will be enabled.
4866 ice_add_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi[], u8 count,
4869 enum ice_status status;
4872 for (i = 0; i < count; i++) {
4873 status = ice_add_prof_id_flow(hw, blk, vsi[i], id);
4882 * ice_rem_prof_from_list - remove a profile from list
4883 * @hw: pointer to the HW struct
4884 * @lst: list to remove the profile from
4885 * @hdl: the profile handle indicating the profile to remove
4887 static enum ice_status
4888 ice_rem_prof_from_list(struct ice_hw *hw, struct LIST_HEAD_TYPE *lst, u64 hdl)
4890 struct ice_vsig_prof *ent, *tmp;
4892 LIST_FOR_EACH_ENTRY_SAFE(ent, tmp, lst, ice_vsig_prof, list) {
4893 if (ent->profile_cookie == hdl) {
4894 LIST_DEL(&ent->list);
4900 return ICE_ERR_DOES_NOT_EXIST;
4904 * ice_rem_prof_id_flow - remove flow
4905 * @hw: pointer to the HW struct
4906 * @blk: hardware block
4907 * @vsi: the VSI from which to remove the profile specified by ID
4908 * @hdl: profile tracking handle
4910 * Calling this function will update the hardware tables to remove the
4911 * profile indicated by the ID parameter for the VSIs specified in the VSI
4912 * array. Once successfully called, the flow will be disabled.
4915 ice_rem_prof_id_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl)
4917 struct ice_vsig_prof *tmp1, *del1;
4918 struct LIST_HEAD_TYPE chg, copy;
4919 struct ice_chs_chg *tmp, *del;
4920 enum ice_status status;
4923 INIT_LIST_HEAD(©);
4924 INIT_LIST_HEAD(&chg);
4926 /* determine if VSI is already part of a VSIG */
4927 status = ice_vsig_find_vsi(hw, blk, vsi, &vsig);
4928 if (!status && vsig) {
4934 last_profile = ice_vsig_prof_id_count(hw, blk, vsig) == 1;
4935 status = ice_vsig_get_ref(hw, blk, vsig, &ref);
4937 goto err_ice_rem_prof_id_flow;
4938 only_vsi = (ref == 1);
4941 /* If the original VSIG only contains one reference,
4942 * which will be the requesting VSI, then the VSI is not
4943 * sharing entries and we can simply remove the specific
4944 * characteristics from the VSIG.
4948 /* If there are no profiles left for this VSIG,
4949 * then simply remove the the VSIG.
4951 status = ice_rem_vsig(hw, blk, vsig, &chg);
4953 goto err_ice_rem_prof_id_flow;
4955 status = ice_rem_prof_id_vsig(hw, blk, vsig,
4958 goto err_ice_rem_prof_id_flow;
4960 /* Adjust priorities */
4961 status = ice_adj_prof_priorities(hw, blk, vsig,
4964 goto err_ice_rem_prof_id_flow;
4968 /* Make a copy of the VSIG's list of Profiles */
4969 status = ice_get_profs_vsig(hw, blk, vsig, ©);
4971 goto err_ice_rem_prof_id_flow;
4973 /* Remove specified profile entry from the list */
4974 status = ice_rem_prof_from_list(hw, ©, hdl);
4976 goto err_ice_rem_prof_id_flow;
4978 if (LIST_EMPTY(©)) {
4979 status = ice_move_vsi(hw, blk, vsi,
4980 ICE_DEFAULT_VSIG, &chg);
4982 goto err_ice_rem_prof_id_flow;
4984 } else if (!ice_find_dup_props_vsig(hw, blk, ©,
4986 /* found an exact match */
4987 /* add or move VSI to the VSIG that matches */
4988 /* Search for a VSIG with a matching profile
4992 /* Found match, move VSI to the matching VSIG */
4993 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
4995 goto err_ice_rem_prof_id_flow;
4997 /* since no existing VSIG supports this
4998 * characteristic pattern, we need to create a
4999 * new VSIG and TCAM entries
5001 status = ice_create_vsig_from_lst(hw, blk, vsi,
5004 goto err_ice_rem_prof_id_flow;
5006 /* Adjust priorities */
5007 status = ice_adj_prof_priorities(hw, blk, vsig,
5010 goto err_ice_rem_prof_id_flow;
5014 status = ICE_ERR_DOES_NOT_EXIST;
5017 /* update hardware tables */
5019 status = ice_upd_prof_hw(hw, blk, &chg);
5021 err_ice_rem_prof_id_flow:
5022 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
5023 LIST_DEL(&del->list_entry);
5027 LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, ©, ice_vsig_prof, list) {
5028 LIST_DEL(&del1->list);
5036 * ice_rem_flow - remove flow
5037 * @hw: pointer to the HW struct
5038 * @blk: hardware block
5039 * @vsi: array of VSIs from which to remove the profile specified by ID
5040 * @count: number of elements in the VSI array
5041 * @id: profile tracking ID
5043 * The function will remove flows from the specified VSIs that were enabled
5044 * using ice_add_flow. The ID value will indicated which profile will be
5045 * removed. Once successfully called, the flow will be disabled.
5048 ice_rem_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi[], u8 count,
5051 enum ice_status status;
5054 for (i = 0; i < count; i++) {
5055 status = ice_rem_prof_id_flow(hw, blk, vsi[i], id);