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.
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 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_fd_mask_regs - initialize Flow Director mask registers
1279 * @hw: pointer to the HW struct
1281 * This function sets up the Flow Director mask registers to allow for complete
1282 * masking off of any of the 24 Field Vector words. After this call, mask 0 will
1283 * mask off all of FV index 0, mask 1 will mask off all of FV index 1, etc.
1285 static void ice_init_fd_mask_regs(struct ice_hw *hw)
1289 for (i = 0; i < hw->blk[ICE_BLK_FD].es.fvw; i++) {
1290 wr32(hw, GLQF_FDMASK(i), i);
1291 ice_debug(hw, ICE_DBG_INIT, "init fd mask(%d): %x = %x\n", i,
1297 * ice_init_pkg_regs - initialize additional package registers
1298 * @hw: pointer to the hardware structure
1300 static void ice_init_pkg_regs(struct ice_hw *hw)
1302 #define ICE_SW_BLK_INP_MASK_L 0xFFFFFFFF
1303 #define ICE_SW_BLK_INP_MASK_H 0x0000FFFF
1304 #define ICE_SW_BLK_IDX 0
1306 /* setup Switch block input mask, which is 48-bits in two parts */
1307 wr32(hw, GL_PREEXT_L2_PMASK0(ICE_SW_BLK_IDX), ICE_SW_BLK_INP_MASK_L);
1308 wr32(hw, GL_PREEXT_L2_PMASK1(ICE_SW_BLK_IDX), ICE_SW_BLK_INP_MASK_H);
1309 /* setup default flow director masks */
1310 ice_init_fd_mask_regs(hw);
1314 * ice_init_pkg - initialize/download package
1315 * @hw: pointer to the hardware structure
1316 * @buf: pointer to the package buffer
1317 * @len: size of the package buffer
1319 * This function initializes a package. The package contains HW tables
1320 * required to do packet processing. First, the function extracts package
1321 * information such as version. Then it finds the ice configuration segment
1322 * within the package; this function then saves a copy of the segment pointer
1323 * within the supplied package buffer. Next, the function will cache any hints
1324 * from the package, followed by downloading the package itself. Note, that if
1325 * a previous PF driver has already downloaded the package successfully, then
1326 * the current driver will not have to download the package again.
1328 * The local package contents will be used to query default behavior and to
1329 * update specific sections of the HW's version of the package (e.g. to update
1330 * the parse graph to understand new protocols).
1332 * This function stores a pointer to the package buffer memory, and it is
1333 * expected that the supplied buffer will not be freed immediately. If the
1334 * package buffer needs to be freed, such as when read from a file, use
1335 * ice_copy_and_init_pkg() instead of directly calling ice_init_pkg() in this
1338 enum ice_status ice_init_pkg(struct ice_hw *hw, u8 *buf, u32 len)
1340 struct ice_pkg_hdr *pkg;
1341 enum ice_status status;
1342 struct ice_seg *seg;
1345 return ICE_ERR_PARAM;
1347 pkg = (struct ice_pkg_hdr *)buf;
1348 status = ice_verify_pkg(pkg, len);
1350 ice_debug(hw, ICE_DBG_INIT, "failed to verify pkg (err: %d)\n",
1355 /* initialize package info */
1356 status = ice_init_pkg_info(hw, pkg);
1360 /* find segment in given package */
1361 seg = (struct ice_seg *)ice_find_seg_in_pkg(hw, SEGMENT_TYPE_ICE, pkg);
1363 ice_debug(hw, ICE_DBG_INIT, "no ice segment in package.\n");
1367 /* initialize package hints and then download package */
1368 ice_init_pkg_hints(hw, seg);
1369 status = ice_download_pkg(hw, seg);
1370 if (status == ICE_ERR_AQ_NO_WORK) {
1371 ice_debug(hw, ICE_DBG_INIT,
1372 "package previously loaded - no work.\n");
1373 status = ICE_SUCCESS;
1378 /* on successful package download, update other required
1379 * registers to support the package
1381 ice_init_pkg_regs(hw);
1383 ice_debug(hw, ICE_DBG_INIT, "package load failed, %d\n",
1391 * ice_copy_and_init_pkg - initialize/download a copy of the package
1392 * @hw: pointer to the hardware structure
1393 * @buf: pointer to the package buffer
1394 * @len: size of the package buffer
1396 * This function copies the package buffer, and then calls ice_init_pkg() to
1397 * initialize the copied package contents.
1399 * The copying is necessary if the package buffer supplied is constant, or if
1400 * the memory may disappear shortly after calling this function.
1402 * If the package buffer resides in the data segment and can be modified, the
1403 * caller is free to use ice_init_pkg() instead of ice_copy_and_init_pkg().
1405 * However, if the package buffer needs to be copied first, such as when being
1406 * read from a file, the caller should use ice_copy_and_init_pkg().
1408 * This function will first copy the package buffer, before calling
1409 * ice_init_pkg(). The caller is free to immediately destroy the original
1410 * package buffer, as the new copy will be managed by this function and
1413 enum ice_status ice_copy_and_init_pkg(struct ice_hw *hw, const u8 *buf, u32 len)
1415 enum ice_status status;
1419 return ICE_ERR_PARAM;
1421 buf_copy = (u8 *)ice_memdup(hw, buf, len, ICE_NONDMA_TO_NONDMA);
1423 status = ice_init_pkg(hw, buf_copy, len);
1425 /* Free the copy, since we failed to initialize the package */
1426 ice_free(hw, buf_copy);
1428 /* Track the copied pkg so we can free it later */
1429 hw->pkg_copy = buf_copy;
1438 * @hw: pointer to the HW structure
1440 * Allocates a package buffer and returns a pointer to the buffer header.
1441 * Note: all package contents must be in Little Endian form.
1443 struct ice_buf_build *ice_pkg_buf_alloc(struct ice_hw *hw)
1445 struct ice_buf_build *bld;
1446 struct ice_buf_hdr *buf;
1448 bld = (struct ice_buf_build *)ice_malloc(hw, sizeof(*bld));
1452 buf = (struct ice_buf_hdr *)bld;
1453 buf->data_end = CPU_TO_LE16(sizeof(*buf) -
1454 sizeof(buf->section_entry[0]));
1460 * @sect_type: section type
1461 * @section: pointer to section
1462 * @index: index of the field vector entry to be returned
1463 * @offset: ptr to variable that receives the offset in the field vector table
1465 * This is a callback function that can be passed to ice_pkg_enum_entry.
1466 * This function treats the given section as of type ice_sw_fv_section and
1467 * enumerates offset field. "offset" is an index into the field vector
1471 ice_sw_fv_handler(u32 sect_type, void *section, u32 index, u32 *offset)
1473 struct ice_sw_fv_section *fv_section =
1474 (struct ice_sw_fv_section *)section;
1476 if (!section || sect_type != ICE_SID_FLD_VEC_SW)
1478 if (index >= LE16_TO_CPU(fv_section->count))
1481 /* "index" passed in to this function is relative to a given
1482 * 4k block. To get to the true index into the field vector
1483 * table need to add the relative index to the base_offset
1484 * field of this section
1486 *offset = LE16_TO_CPU(fv_section->base_offset) + index;
1487 return fv_section->fv + index;
1491 * ice_get_sw_fv_list
1492 * @hw: pointer to the HW structure
1493 * @prot_ids: field vector to search for with a given protocol ID
1494 * @ids_cnt: lookup/protocol count
1495 * @fv_list: Head of a list
1497 * Finds all the field vector entries from switch block that contain
1498 * a given protocol ID and returns a list of structures of type
1499 * "ice_sw_fv_list_entry". Every structure in the list has a field vector
1500 * definition and profile ID information
1501 * NOTE: The caller of the function is responsible for freeing the memory
1502 * allocated for every list entry.
1505 ice_get_sw_fv_list(struct ice_hw *hw, u16 *prot_ids, u8 ids_cnt,
1506 struct LIST_HEAD_TYPE *fv_list)
1508 struct ice_sw_fv_list_entry *fvl;
1509 struct ice_sw_fv_list_entry *tmp;
1510 struct ice_pkg_enum state;
1511 struct ice_seg *ice_seg;
1515 if (!ids_cnt || !hw->seg)
1516 return ICE_ERR_PARAM;
1522 fv = (struct ice_fv *)
1523 ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1524 &offset, ice_sw_fv_handler);
1526 for (i = 0; i < ids_cnt && fv; i++) {
1529 /* This code assumes that if a switch field vector line
1530 * has a matching protocol, then this line will contain
1531 * the entries necessary to represent every field in
1532 * that protocol header.
1534 for (j = 0; j < hw->blk[ICE_BLK_SW].es.fvw; j++)
1535 if (fv->ew[j].prot_id == prot_ids[i])
1537 if (j >= hw->blk[ICE_BLK_SW].es.fvw)
1539 if (i + 1 == ids_cnt) {
1540 fvl = (struct ice_sw_fv_list_entry *)
1541 ice_malloc(hw, sizeof(*fvl));
1545 fvl->profile_id = offset;
1546 LIST_ADD(&fvl->list_entry, fv_list);
1552 if (LIST_EMPTY(fv_list))
1557 LIST_FOR_EACH_ENTRY_SAFE(fvl, tmp, fv_list, ice_sw_fv_list_entry,
1559 LIST_DEL(&fvl->list_entry);
1563 return ICE_ERR_NO_MEMORY;
1567 * ice_pkg_buf_alloc_single_section
1568 * @hw: pointer to the HW structure
1569 * @type: the section type value
1570 * @size: the size of the section to reserve (in bytes)
1571 * @section: returns pointer to the section
1573 * Allocates a package buffer with a single section.
1574 * Note: all package contents must be in Little Endian form.
1576 static struct ice_buf_build *
1577 ice_pkg_buf_alloc_single_section(struct ice_hw *hw, u32 type, u16 size,
1580 struct ice_buf_build *buf;
1585 buf = ice_pkg_buf_alloc(hw);
1589 if (ice_pkg_buf_reserve_section(buf, 1))
1590 goto ice_pkg_buf_alloc_single_section_err;
1592 *section = ice_pkg_buf_alloc_section(buf, type, size);
1594 goto ice_pkg_buf_alloc_single_section_err;
1598 ice_pkg_buf_alloc_single_section_err:
1599 ice_pkg_buf_free(hw, buf);
1604 * ice_pkg_buf_reserve_section
1605 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1606 * @count: the number of sections to reserve
1608 * Reserves one or more section table entries in a package buffer. This routine
1609 * can be called multiple times as long as they are made before calling
1610 * ice_pkg_buf_alloc_section(). Once ice_pkg_buf_alloc_section()
1611 * is called once, the number of sections that can be allocated will not be able
1612 * to be increased; not using all reserved sections is fine, but this will
1613 * result in some wasted space in the buffer.
1614 * Note: all package contents must be in Little Endian form.
1617 ice_pkg_buf_reserve_section(struct ice_buf_build *bld, u16 count)
1619 struct ice_buf_hdr *buf;
1624 return ICE_ERR_PARAM;
1626 buf = (struct ice_buf_hdr *)&bld->buf;
1628 /* already an active section, can't increase table size */
1629 section_count = LE16_TO_CPU(buf->section_count);
1630 if (section_count > 0)
1633 if (bld->reserved_section_table_entries + count > ICE_MAX_S_COUNT)
1635 bld->reserved_section_table_entries += count;
1637 data_end = LE16_TO_CPU(buf->data_end) +
1638 (count * sizeof(buf->section_entry[0]));
1639 buf->data_end = CPU_TO_LE16(data_end);
1645 * ice_pkg_buf_unreserve_section
1646 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1647 * @count: the number of sections to unreserve
1649 * Unreserves one or more section table entries in a package buffer, releasing
1650 * space that can be used for section data. This routine can be called
1651 * multiple times as long as they are made before calling
1652 * ice_pkg_buf_alloc_section(). Once ice_pkg_buf_alloc_section()
1653 * is called once, the number of sections that can be allocated will not be able
1654 * to be increased; not using all reserved sections is fine, but this will
1655 * result in some wasted space in the buffer.
1656 * Note: all package contents must be in Little Endian form.
1659 ice_pkg_buf_unreserve_section(struct ice_buf_build *bld, u16 count)
1661 struct ice_buf_hdr *buf;
1666 return ICE_ERR_PARAM;
1668 buf = (struct ice_buf_hdr *)&bld->buf;
1670 /* already an active section, can't decrease table size */
1671 section_count = LE16_TO_CPU(buf->section_count);
1672 if (section_count > 0)
1675 if (count > bld->reserved_section_table_entries)
1677 bld->reserved_section_table_entries -= count;
1679 data_end = LE16_TO_CPU(buf->data_end) -
1680 (count * sizeof(buf->section_entry[0]));
1681 buf->data_end = CPU_TO_LE16(data_end);
1687 * ice_pkg_buf_alloc_section
1688 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1689 * @type: the section type value
1690 * @size: the size of the section to reserve (in bytes)
1692 * Reserves memory in the buffer for a section's content and updates the
1693 * buffers' status accordingly. This routine returns a pointer to the first
1694 * byte of the section start within the buffer, which is used to fill in the
1696 * Note: all package contents must be in Little Endian form.
1699 ice_pkg_buf_alloc_section(struct ice_buf_build *bld, u32 type, u16 size)
1701 struct ice_buf_hdr *buf;
1705 if (!bld || !type || !size)
1708 buf = (struct ice_buf_hdr *)&bld->buf;
1710 /* check for enough space left in buffer */
1711 data_end = LE16_TO_CPU(buf->data_end);
1713 /* section start must align on 4 byte boundary */
1714 data_end = ICE_ALIGN(data_end, 4);
1716 if ((data_end + size) > ICE_MAX_S_DATA_END)
1719 /* check for more available section table entries */
1720 sect_count = LE16_TO_CPU(buf->section_count);
1721 if (sect_count < bld->reserved_section_table_entries) {
1722 void *section_ptr = ((u8 *)buf) + data_end;
1724 buf->section_entry[sect_count].offset = CPU_TO_LE16(data_end);
1725 buf->section_entry[sect_count].size = CPU_TO_LE16(size);
1726 buf->section_entry[sect_count].type = CPU_TO_LE32(type);
1729 buf->data_end = CPU_TO_LE16(data_end);
1731 buf->section_count = CPU_TO_LE16(sect_count + 1);
1735 /* no free section table entries */
1740 * ice_pkg_buf_get_free_space
1741 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1743 * Returns the number of free bytes remaining in the buffer.
1744 * Note: all package contents must be in Little Endian form.
1746 u16 ice_pkg_buf_get_free_space(struct ice_buf_build *bld)
1748 struct ice_buf_hdr *buf;
1753 buf = (struct ice_buf_hdr *)&bld->buf;
1754 return ICE_MAX_S_DATA_END - LE16_TO_CPU(buf->data_end);
1758 * ice_pkg_buf_get_active_sections
1759 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1761 * Returns the number of active sections. Before using the package buffer
1762 * in an update package command, the caller should make sure that there is at
1763 * least one active section - otherwise, the buffer is not legal and should
1765 * Note: all package contents must be in Little Endian form.
1767 u16 ice_pkg_buf_get_active_sections(struct ice_buf_build *bld)
1769 struct ice_buf_hdr *buf;
1774 buf = (struct ice_buf_hdr *)&bld->buf;
1775 return LE16_TO_CPU(buf->section_count);
1779 * ice_pkg_buf_header
1780 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1782 * Return a pointer to the buffer's header
1784 struct ice_buf *ice_pkg_buf(struct ice_buf_build *bld)
1794 * @hw: pointer to the HW structure
1795 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1797 * Frees a package buffer
1799 void ice_pkg_buf_free(struct ice_hw *hw, struct ice_buf_build *bld)
1805 * ice_find_prot_off - find prot ID and offset pair, based on prof and FV index
1806 * @hw: pointer to the hardware structure
1807 * @blk: hardware block
1809 * @fv_idx: field vector word index
1810 * @prot: variable to receive the protocol ID
1811 * @off: variable to receive the protocol offset
1814 ice_find_prot_off(struct ice_hw *hw, enum ice_block blk, u8 prof, u8 fv_idx,
1817 struct ice_fv_word *fv_ext;
1819 if (prof >= hw->blk[blk].es.count)
1820 return ICE_ERR_PARAM;
1822 if (fv_idx >= hw->blk[blk].es.fvw)
1823 return ICE_ERR_PARAM;
1825 fv_ext = hw->blk[blk].es.t + (prof * hw->blk[blk].es.fvw);
1827 *prot = fv_ext[fv_idx].prot_id;
1828 *off = fv_ext[fv_idx].off;
1833 /* PTG Management */
1836 * ice_ptg_update_xlt1 - Updates packet type groups in HW via XLT1 table
1837 * @hw: pointer to the hardware structure
1840 * This function will update the XLT1 hardware table to reflect the new
1841 * packet type group configuration.
1843 enum ice_status ice_ptg_update_xlt1(struct ice_hw *hw, enum ice_block blk)
1845 struct ice_xlt1_section *sect;
1846 struct ice_buf_build *bld;
1847 enum ice_status status;
1850 bld = ice_pkg_buf_alloc_single_section(hw, ice_sect_id(blk, ICE_XLT1),
1851 ICE_XLT1_SIZE(ICE_XLT1_CNT),
1854 return ICE_ERR_NO_MEMORY;
1856 sect->count = CPU_TO_LE16(ICE_XLT1_CNT);
1857 sect->offset = CPU_TO_LE16(0);
1858 for (index = 0; index < ICE_XLT1_CNT; index++)
1859 sect->value[index] = hw->blk[blk].xlt1.ptypes[index].ptg;
1861 status = ice_update_pkg(hw, ice_pkg_buf(bld), 1);
1863 ice_pkg_buf_free(hw, bld);
1869 * ice_ptg_find_ptype - Search for packet type group using packet type (ptype)
1870 * @hw: pointer to the hardware structure
1872 * @ptype: the ptype to search for
1873 * @ptg: pointer to variable that receives the PTG
1875 * This function will search the PTGs for a particular ptype, returning the
1876 * PTG ID that contains it through the ptg parameter, with the value of
1877 * ICE_DEFAULT_PTG (0) meaning it is part the default PTG.
1880 ice_ptg_find_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 *ptg)
1882 if (ptype >= ICE_XLT1_CNT || !ptg)
1883 return ICE_ERR_PARAM;
1885 *ptg = hw->blk[blk].xlt1.ptypes[ptype].ptg;
1890 * ice_ptg_alloc_val - Allocates a new packet type group ID by value
1891 * @hw: pointer to the hardware structure
1893 * @ptg: the ptg to allocate
1895 * This function allocates a given packet type group ID specified by the ptg
1899 void ice_ptg_alloc_val(struct ice_hw *hw, enum ice_block blk, u8 ptg)
1901 hw->blk[blk].xlt1.ptg_tbl[ptg].in_use = true;
1905 * ice_ptg_alloc - Find a free entry and allocates a new packet type group ID
1906 * @hw: pointer to the hardware structure
1909 * This function allocates and returns a new packet type group ID. Note
1910 * that 0 is the default packet type group, so successfully created PTGs will
1911 * have a non-zero ID value; which means a 0 return value indicates an error.
1913 u8 ice_ptg_alloc(struct ice_hw *hw, enum ice_block blk)
1917 /* Skip the default PTG of 0 */
1918 for (i = 1; i < ICE_MAX_PTGS; i++)
1919 if (!hw->blk[blk].xlt1.ptg_tbl[i].in_use) {
1920 /* found a free PTG ID */
1921 ice_ptg_alloc_val(hw, blk, i);
1929 * ice_ptg_free - Frees a packet type group
1930 * @hw: pointer to the hardware structure
1932 * @ptg: the ptg ID to free
1934 * This function frees a packet type group, and returns all the current ptypes
1935 * within it to the default PTG.
1937 void ice_ptg_free(struct ice_hw *hw, enum ice_block blk, u8 ptg)
1939 struct ice_ptg_ptype *p, *temp;
1941 hw->blk[blk].xlt1.ptg_tbl[ptg].in_use = false;
1942 p = hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
1944 p->ptg = ICE_DEFAULT_PTG;
1945 temp = p->next_ptype;
1946 p->next_ptype = NULL;
1950 hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype = NULL;
1954 * ice_ptg_remove_ptype - Removes ptype from a particular packet type group
1955 * @hw: pointer to the hardware structure
1957 * @ptype: the ptype to remove
1958 * @ptg: the ptg to remove the ptype from
1960 * This function will remove the ptype from the specific ptg, and move it to
1961 * the default PTG (ICE_DEFAULT_PTG).
1963 static enum ice_status
1964 ice_ptg_remove_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 ptg)
1966 struct ice_ptg_ptype **ch;
1967 struct ice_ptg_ptype *p;
1969 if (ptype > ICE_XLT1_CNT - 1)
1970 return ICE_ERR_PARAM;
1972 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].in_use)
1973 return ICE_ERR_DOES_NOT_EXIST;
1975 /* Should not happen if .in_use is set, bad config */
1976 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype)
1979 /* find the ptype within this PTG, and bypass the link over it */
1980 p = hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
1981 ch = &hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
1983 if (ptype == (p - hw->blk[blk].xlt1.ptypes)) {
1984 *ch = p->next_ptype;
1988 ch = &p->next_ptype;
1992 hw->blk[blk].xlt1.ptypes[ptype].ptg = ICE_DEFAULT_PTG;
1993 hw->blk[blk].xlt1.ptypes[ptype].next_ptype = NULL;
1999 * ice_ptg_add_mv_ptype - Adds/moves ptype to a particular packet type group
2000 * @hw: pointer to the hardware structure
2002 * @ptype: the ptype to add or move
2003 * @ptg: the ptg to add or move the ptype to
2005 * This function will either add or move a ptype to a particular PTG depending
2006 * on if the ptype is already part of another group. Note that using a
2007 * a destination PTG ID of ICE_DEFAULT_PTG (0) will move the ptype to the
2011 ice_ptg_add_mv_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 ptg)
2013 enum ice_status status;
2016 if (ptype > ICE_XLT1_CNT - 1)
2017 return ICE_ERR_PARAM;
2019 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].in_use && ptg != ICE_DEFAULT_PTG)
2020 return ICE_ERR_DOES_NOT_EXIST;
2022 status = ice_ptg_find_ptype(hw, blk, ptype, &original_ptg);
2026 /* Is ptype already in the correct PTG? */
2027 if (original_ptg == ptg)
2030 /* Remove from original PTG and move back to the default PTG */
2031 if (original_ptg != ICE_DEFAULT_PTG)
2032 ice_ptg_remove_ptype(hw, blk, ptype, original_ptg);
2034 /* Moving to default PTG? Then we're done with this request */
2035 if (ptg == ICE_DEFAULT_PTG)
2038 /* Add ptype to PTG at beginning of list */
2039 hw->blk[blk].xlt1.ptypes[ptype].next_ptype =
2040 hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2041 hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype =
2042 &hw->blk[blk].xlt1.ptypes[ptype];
2044 hw->blk[blk].xlt1.ptypes[ptype].ptg = ptg;
2045 hw->blk[blk].xlt1.t[ptype] = ptg;
2050 /* Block / table size info */
2051 struct ice_blk_size_details {
2052 u16 xlt1; /* # XLT1 entries */
2053 u16 xlt2; /* # XLT2 entries */
2054 u16 prof_tcam; /* # profile ID TCAM entries */
2055 u16 prof_id; /* # profile IDs */
2056 u8 prof_cdid_bits; /* # cdid one-hot bits used in key */
2057 u16 prof_redir; /* # profile redirection entries */
2058 u16 es; /* # extraction sequence entries */
2059 u16 fvw; /* # field vector words */
2060 u8 overwrite; /* overwrite existing entries allowed */
2061 u8 reverse; /* reverse FV order */
2064 static const struct ice_blk_size_details blk_sizes[ICE_BLK_COUNT] = {
2067 * XLT1 - Number of entries in XLT1 table
2068 * XLT2 - Number of entries in XLT2 table
2069 * TCAM - Number of entries Profile ID TCAM table
2070 * CDID - Control Domain ID of the hardware block
2071 * PRED - Number of entries in the Profile Redirection Table
2072 * FV - Number of entries in the Field Vector
2073 * FVW - Width (in WORDs) of the Field Vector
2074 * OVR - Overwrite existing table entries
2077 /* XLT1 , XLT2 ,TCAM, PID,CDID,PRED, FV, FVW */
2078 /* Overwrite , Reverse FV */
2079 /* SW */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 256, 0, 256, 256, 48,
2081 /* ACL */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 32,
2083 /* FD */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 24,
2085 /* RSS */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 24,
2087 /* PE */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 64, 32, 0, 32, 32, 24,
2092 ICE_SID_XLT1_OFF = 0,
2095 ICE_SID_PR_REDIR_OFF,
2100 /* Characteristic handling */
2103 * ice_match_prop_lst - determine if properties of two lists match
2104 * @list1: first properties list
2105 * @list2: second properties list
2107 * Count, cookies and the order must match in order to be considered equivalent.
2110 ice_match_prop_lst(struct LIST_HEAD_TYPE *list1, struct LIST_HEAD_TYPE *list2)
2112 struct ice_vsig_prof *tmp1;
2113 struct ice_vsig_prof *tmp2;
2117 /* compare counts */
2118 LIST_FOR_EACH_ENTRY(tmp1, list1, ice_vsig_prof, list) {
2121 LIST_FOR_EACH_ENTRY(tmp2, list2, ice_vsig_prof, list) {
2124 if (!count || count != chk_count)
2127 tmp1 = LIST_FIRST_ENTRY(list1, struct ice_vsig_prof, list);
2128 tmp2 = LIST_FIRST_ENTRY(list2, struct ice_vsig_prof, list);
2130 /* profile cookies must compare, and in the exact same order to take
2131 * into account priority
2134 if (tmp2->profile_cookie != tmp1->profile_cookie)
2137 tmp1 = LIST_NEXT_ENTRY(tmp1, struct ice_vsig_prof, list);
2138 tmp2 = LIST_NEXT_ENTRY(tmp2, struct ice_vsig_prof, list);
2144 /* VSIG Management */
2147 * ice_vsig_update_xlt2_sect - update one section of XLT2 table
2148 * @hw: pointer to the hardware structure
2150 * @vsi: HW VSI number to program
2151 * @vsig: vsig for the VSI
2153 * This function will update the XLT2 hardware table with the input VSI
2154 * group configuration.
2156 static enum ice_status
2157 ice_vsig_update_xlt2_sect(struct ice_hw *hw, enum ice_block blk, u16 vsi,
2160 struct ice_xlt2_section *sect;
2161 struct ice_buf_build *bld;
2162 enum ice_status status;
2164 bld = ice_pkg_buf_alloc_single_section(hw, ice_sect_id(blk, ICE_XLT2),
2165 sizeof(struct ice_xlt2_section),
2168 return ICE_ERR_NO_MEMORY;
2170 sect->count = CPU_TO_LE16(1);
2171 sect->offset = CPU_TO_LE16(vsi);
2172 sect->value[0] = CPU_TO_LE16(vsig);
2174 status = ice_update_pkg(hw, ice_pkg_buf(bld), 1);
2176 ice_pkg_buf_free(hw, bld);
2182 * ice_vsig_update_xlt2 - update XLT2 table with VSIG configuration
2183 * @hw: pointer to the hardware structure
2186 * This function will update the XLT2 hardware table with the input VSI
2187 * group configuration of used vsis.
2189 enum ice_status ice_vsig_update_xlt2(struct ice_hw *hw, enum ice_block blk)
2193 for (vsi = 0; vsi < ICE_MAX_VSI; vsi++) {
2194 /* update only vsis that have been changed */
2195 if (hw->blk[blk].xlt2.vsis[vsi].changed) {
2196 enum ice_status status;
2199 vsig = hw->blk[blk].xlt2.vsis[vsi].vsig;
2200 status = ice_vsig_update_xlt2_sect(hw, blk, vsi, vsig);
2204 hw->blk[blk].xlt2.vsis[vsi].changed = 0;
2212 * ice_vsig_find_vsi - find a VSIG that contains a specified VSI
2213 * @hw: pointer to the hardware structure
2215 * @vsi: VSI of interest
2216 * @vsig: pointer to receive the VSI group
2218 * This function will lookup the VSI entry in the XLT2 list and return
2219 * the VSI group its associated with.
2222 ice_vsig_find_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 *vsig)
2224 if (!vsig || vsi >= ICE_MAX_VSI)
2225 return ICE_ERR_PARAM;
2227 /* As long as there's a default or valid VSIG associated with the input
2228 * VSI, the functions returns a success. Any handling of VSIG will be
2229 * done by the following add, update or remove functions.
2231 *vsig = hw->blk[blk].xlt2.vsis[vsi].vsig;
2237 * ice_vsig_alloc_val - allocate a new VSIG by value
2238 * @hw: pointer to the hardware structure
2240 * @vsig: the vsig to allocate
2242 * This function will allocate a given VSIG specified by the vsig parameter.
2244 static u16 ice_vsig_alloc_val(struct ice_hw *hw, enum ice_block blk, u16 vsig)
2246 u16 idx = vsig & ICE_VSIG_IDX_M;
2248 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use) {
2249 INIT_LIST_HEAD(&hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst);
2250 hw->blk[blk].xlt2.vsig_tbl[idx].in_use = true;
2253 return ICE_VSIG_VALUE(idx, hw->pf_id);
2257 * ice_vsig_alloc - Finds a free entry and allocates a new VSIG
2258 * @hw: pointer to the hardware structure
2261 * This function will iterate through the VSIG list and mark the first
2262 * unused entry for the new VSIG entry as used and return that value.
2264 static u16 ice_vsig_alloc(struct ice_hw *hw, enum ice_block blk)
2268 for (i = 1; i < ICE_MAX_VSIGS; i++)
2269 if (!hw->blk[blk].xlt2.vsig_tbl[i].in_use)
2270 return ice_vsig_alloc_val(hw, blk, i);
2272 return ICE_DEFAULT_VSIG;
2276 * ice_find_dup_props_vsig - find VSI group with a specified set of properties
2277 * @hw: pointer to the hardware structure
2279 * @chs: characteristic list
2280 * @vsig: returns the VSIG with the matching profiles, if found
2282 * Each VSIG is associated with a characteristic set; i.e. all VSIs under
2283 * a group have the same characteristic set. To check if there exists a VSIG
2284 * which has the same characteristics as the input characteristics; this
2285 * function will iterate through the XLT2 list and return the VSIG that has a
2286 * matching configuration. In order to make sure that priorities are accounted
2287 * for, the list must match exactly, including the order in which the
2288 * characteristics are listed.
2291 ice_find_dup_props_vsig(struct ice_hw *hw, enum ice_block blk,
2292 struct LIST_HEAD_TYPE *chs, u16 *vsig)
2294 struct ice_xlt2 *xlt2 = &hw->blk[blk].xlt2;
2297 for (i = 0; i < xlt2->count; i++) {
2298 if (xlt2->vsig_tbl[i].in_use &&
2299 ice_match_prop_lst(chs, &xlt2->vsig_tbl[i].prop_lst)) {
2300 *vsig = ICE_VSIG_VALUE(i, hw->pf_id);
2305 return ICE_ERR_DOES_NOT_EXIST;
2309 * ice_vsig_free - free VSI group
2310 * @hw: pointer to the hardware structure
2312 * @vsig: VSIG to remove
2314 * The function will remove all VSIs associated with the input VSIG and move
2315 * them to the DEFAULT_VSIG and mark the VSIG available.
2318 ice_vsig_free(struct ice_hw *hw, enum ice_block blk, u16 vsig)
2320 struct ice_vsig_prof *dtmp, *del;
2321 struct ice_vsig_vsi *vsi_cur;
2324 idx = vsig & ICE_VSIG_IDX_M;
2325 if (idx >= ICE_MAX_VSIGS)
2326 return ICE_ERR_PARAM;
2328 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
2329 return ICE_ERR_DOES_NOT_EXIST;
2331 hw->blk[blk].xlt2.vsig_tbl[idx].in_use = false;
2333 vsi_cur = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2334 /* If the VSIG has at least 1 VSI then iterate through the
2335 * list and remove the VSIs before deleting the group.
2338 /* remove all vsis associated with this VSIG XLT2 entry */
2340 struct ice_vsig_vsi *tmp = vsi_cur->next_vsi;
2342 vsi_cur->vsig = ICE_DEFAULT_VSIG;
2343 vsi_cur->changed = 1;
2344 vsi_cur->next_vsi = NULL;
2348 /* NULL terminate head of VSI list */
2349 hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi = NULL;
2352 /* free characteristic list */
2353 LIST_FOR_EACH_ENTRY_SAFE(del, dtmp,
2354 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
2355 ice_vsig_prof, list) {
2356 LIST_DEL(&del->list);
2364 * ice_vsig_add_mv_vsi - add or move a VSI to a VSI group
2365 * @hw: pointer to the hardware structure
2368 * @vsig: destination VSI group
2370 * This function will move or add the input VSI to the target VSIG.
2371 * The function will find the original VSIG the VSI belongs to and
2372 * move the entry to the DEFAULT_VSIG, update the original VSIG and
2373 * then move entry to the new VSIG.
2376 ice_vsig_add_mv_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
2378 struct ice_vsig_vsi *tmp;
2379 enum ice_status status;
2382 idx = vsig & ICE_VSIG_IDX_M;
2384 if (vsi >= ICE_MAX_VSI || idx >= ICE_MAX_VSIGS)
2385 return ICE_ERR_PARAM;
2387 /* if VSIG not in use and VSIG is not default type this VSIG
2390 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use &&
2391 vsig != ICE_DEFAULT_VSIG)
2392 return ICE_ERR_DOES_NOT_EXIST;
2394 status = ice_vsig_find_vsi(hw, blk, vsi, &orig_vsig);
2398 /* no update required if vsigs match */
2399 if (orig_vsig == vsig)
2402 if (orig_vsig != ICE_DEFAULT_VSIG) {
2403 /* remove entry from orig_vsig and add to default VSIG */
2404 status = ice_vsig_remove_vsi(hw, blk, vsi, orig_vsig);
2409 if (idx == ICE_DEFAULT_VSIG)
2412 /* Create VSI entry and add VSIG and prop_mask values */
2413 hw->blk[blk].xlt2.vsis[vsi].vsig = vsig;
2414 hw->blk[blk].xlt2.vsis[vsi].changed = 1;
2416 /* Add new entry to the head of the VSIG list */
2417 tmp = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2418 hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi =
2419 &hw->blk[blk].xlt2.vsis[vsi];
2420 hw->blk[blk].xlt2.vsis[vsi].next_vsi = tmp;
2421 hw->blk[blk].xlt2.t[vsi] = vsig;
2427 * ice_vsig_remove_vsi - remove VSI from VSIG
2428 * @hw: pointer to the hardware structure
2430 * @vsi: VSI to remove
2431 * @vsig: VSI group to remove from
2433 * The function will remove the input VSI from its VSI group and move it
2434 * to the DEFAULT_VSIG.
2437 ice_vsig_remove_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
2439 struct ice_vsig_vsi **vsi_head, *vsi_cur, *vsi_tgt;
2442 idx = vsig & ICE_VSIG_IDX_M;
2444 if (vsi >= ICE_MAX_VSI || idx >= ICE_MAX_VSIGS)
2445 return ICE_ERR_PARAM;
2447 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
2448 return ICE_ERR_DOES_NOT_EXIST;
2450 /* entry already in default VSIG, don't have to remove */
2451 if (idx == ICE_DEFAULT_VSIG)
2454 vsi_head = &hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2458 vsi_tgt = &hw->blk[blk].xlt2.vsis[vsi];
2459 vsi_cur = (*vsi_head);
2461 /* iterate the VSI list, skip over the entry to be removed */
2463 if (vsi_tgt == vsi_cur) {
2464 (*vsi_head) = vsi_cur->next_vsi;
2467 vsi_head = &vsi_cur->next_vsi;
2468 vsi_cur = vsi_cur->next_vsi;
2471 /* verify if VSI was removed from group list */
2473 return ICE_ERR_DOES_NOT_EXIST;
2475 vsi_cur->vsig = ICE_DEFAULT_VSIG;
2476 vsi_cur->changed = 1;
2477 vsi_cur->next_vsi = NULL;
2483 * ice_find_prof_id - find profile ID for a given field vector
2484 * @hw: pointer to the hardware structure
2486 * @fv: field vector to search for
2487 * @prof_id: receives the profile ID
2489 static enum ice_status
2490 ice_find_prof_id(struct ice_hw *hw, enum ice_block blk,
2491 struct ice_fv_word *fv, u8 *prof_id)
2493 struct ice_es *es = &hw->blk[blk].es;
2496 for (i = 0; i < es->count; i++) {
2499 if (memcmp(&es->t[off], fv, es->fvw * sizeof(*fv)))
2506 return ICE_ERR_DOES_NOT_EXIST;
2510 * ice_prof_id_rsrc_type - get profile ID resource type for a block type
2511 * @blk: the block type
2512 * @rsrc_type: pointer to variable to receive the resource type
2514 static bool ice_prof_id_rsrc_type(enum ice_block blk, u16 *rsrc_type)
2518 *rsrc_type = ICE_AQC_RES_TYPE_SWITCH_PROF_BLDR_PROFID;
2521 *rsrc_type = ICE_AQC_RES_TYPE_ACL_PROF_BLDR_PROFID;
2524 *rsrc_type = ICE_AQC_RES_TYPE_FD_PROF_BLDR_PROFID;
2527 *rsrc_type = ICE_AQC_RES_TYPE_HASH_PROF_BLDR_PROFID;
2530 *rsrc_type = ICE_AQC_RES_TYPE_QHASH_PROF_BLDR_PROFID;
2539 * ice_tcam_ent_rsrc_type - get TCAM entry resource type for a block type
2540 * @blk: the block type
2541 * @rsrc_type: pointer to variable to receive the resource type
2543 static bool ice_tcam_ent_rsrc_type(enum ice_block blk, u16 *rsrc_type)
2547 *rsrc_type = ICE_AQC_RES_TYPE_SWITCH_PROF_BLDR_TCAM;
2550 *rsrc_type = ICE_AQC_RES_TYPE_ACL_PROF_BLDR_TCAM;
2553 *rsrc_type = ICE_AQC_RES_TYPE_FD_PROF_BLDR_TCAM;
2556 *rsrc_type = ICE_AQC_RES_TYPE_HASH_PROF_BLDR_TCAM;
2559 *rsrc_type = ICE_AQC_RES_TYPE_QHASH_PROF_BLDR_TCAM;
2568 * ice_alloc_tcam_ent - allocate hardware TCAM entry
2569 * @hw: pointer to the HW struct
2570 * @blk: the block to allocate the TCAM for
2571 * @tcam_idx: pointer to variable to receive the TCAM entry
2573 * This function allocates a new entry in a Profile ID TCAM for a specific
2576 static enum ice_status
2577 ice_alloc_tcam_ent(struct ice_hw *hw, enum ice_block blk, u16 *tcam_idx)
2581 if (!ice_tcam_ent_rsrc_type(blk, &res_type))
2582 return ICE_ERR_PARAM;
2584 return ice_alloc_hw_res(hw, res_type, 1, true, tcam_idx);
2588 * ice_free_tcam_ent - free hardware TCAM entry
2589 * @hw: pointer to the HW struct
2590 * @blk: the block from which to free the TCAM entry
2591 * @tcam_idx: the TCAM entry to free
2593 * This function frees an entry in a Profile ID TCAM for a specific block.
2595 static enum ice_status
2596 ice_free_tcam_ent(struct ice_hw *hw, enum ice_block blk, u16 tcam_idx)
2600 if (!ice_tcam_ent_rsrc_type(blk, &res_type))
2601 return ICE_ERR_PARAM;
2603 return ice_free_hw_res(hw, res_type, 1, &tcam_idx);
2607 * ice_alloc_prof_id - allocate profile ID
2608 * @hw: pointer to the HW struct
2609 * @blk: the block to allocate the profile ID for
2610 * @prof_id: pointer to variable to receive the profile ID
2612 * This function allocates a new profile ID, which also corresponds to a Field
2613 * Vector (Extraction Sequence) entry.
2615 static enum ice_status
2616 ice_alloc_prof_id(struct ice_hw *hw, enum ice_block blk, u8 *prof_id)
2618 enum ice_status status;
2622 if (!ice_prof_id_rsrc_type(blk, &res_type))
2623 return ICE_ERR_PARAM;
2625 status = ice_alloc_hw_res(hw, res_type, 1, false, &get_prof);
2627 *prof_id = (u8)get_prof;
2633 * ice_free_prof_id - free profile ID
2634 * @hw: pointer to the HW struct
2635 * @blk: the block from which to free the profile ID
2636 * @prof_id: the profile ID to free
2638 * This function frees a profile ID, which also corresponds to a Field Vector.
2640 static enum ice_status
2641 ice_free_prof_id(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
2643 u16 tmp_prof_id = (u16)prof_id;
2646 if (!ice_prof_id_rsrc_type(blk, &res_type))
2647 return ICE_ERR_PARAM;
2649 return ice_free_hw_res(hw, res_type, 1, &tmp_prof_id);
2653 * ice_prof_inc_ref - increment reference count for profile
2654 * @hw: pointer to the HW struct
2655 * @blk: the block from which to free the profile ID
2656 * @prof_id: the profile ID for which to increment the reference count
2658 static enum ice_status
2659 ice_prof_inc_ref(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
2661 if (prof_id > hw->blk[blk].es.count)
2662 return ICE_ERR_PARAM;
2664 hw->blk[blk].es.ref_count[prof_id]++;
2670 * ice_write_es - write an extraction sequence to hardware
2671 * @hw: pointer to the HW struct
2672 * @blk: the block in which to write the extraction sequence
2673 * @prof_id: the profile ID to write
2674 * @fv: pointer to the extraction sequence to write - NULL to clear extraction
2677 ice_write_es(struct ice_hw *hw, enum ice_block blk, u8 prof_id,
2678 struct ice_fv_word *fv)
2682 off = prof_id * hw->blk[blk].es.fvw;
2684 ice_memset(&hw->blk[blk].es.t[off], 0, hw->blk[blk].es.fvw *
2685 sizeof(*fv), ICE_NONDMA_MEM);
2686 hw->blk[blk].es.written[prof_id] = false;
2688 ice_memcpy(&hw->blk[blk].es.t[off], fv, hw->blk[blk].es.fvw *
2689 sizeof(*fv), ICE_NONDMA_TO_NONDMA);
2694 * ice_prof_dec_ref - decrement reference count for profile
2695 * @hw: pointer to the HW struct
2696 * @blk: the block from which to free the profile ID
2697 * @prof_id: the profile ID for which to decrement the reference count
2699 static enum ice_status
2700 ice_prof_dec_ref(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
2702 if (prof_id > hw->blk[blk].es.count)
2703 return ICE_ERR_PARAM;
2705 if (hw->blk[blk].es.ref_count[prof_id] > 0) {
2706 if (!--hw->blk[blk].es.ref_count[prof_id]) {
2707 ice_write_es(hw, blk, prof_id, NULL);
2708 return ice_free_prof_id(hw, blk, prof_id);
2715 /* Block / table section IDs */
2716 static const u32 ice_blk_sids[ICE_BLK_COUNT][ICE_SID_OFF_COUNT] = {
2720 ICE_SID_PROFID_TCAM_SW,
2721 ICE_SID_PROFID_REDIR_SW,
2728 ICE_SID_PROFID_TCAM_ACL,
2729 ICE_SID_PROFID_REDIR_ACL,
2736 ICE_SID_PROFID_TCAM_FD,
2737 ICE_SID_PROFID_REDIR_FD,
2744 ICE_SID_PROFID_TCAM_RSS,
2745 ICE_SID_PROFID_REDIR_RSS,
2752 ICE_SID_PROFID_TCAM_PE,
2753 ICE_SID_PROFID_REDIR_PE,
2759 * ice_fill_tbl - Reads content of a single table type into database
2760 * @hw: pointer to the hardware structure
2761 * @block_id: Block ID of the table to copy
2762 * @sid: Section ID of the table to copy
2764 * Will attempt to read the entire content of a given table of a single block
2765 * into the driver database. We assume that the buffer will always
2766 * be as large or larger than the data contained in the package. If
2767 * this condition is not met, there is most likely an error in the package
2770 static void ice_fill_tbl(struct ice_hw *hw, enum ice_block block_id, u32 sid)
2772 u32 dst_len, sect_len, offset = 0;
2773 struct ice_prof_redir_section *pr;
2774 struct ice_prof_id_section *pid;
2775 struct ice_xlt1_section *xlt1;
2776 struct ice_xlt2_section *xlt2;
2777 struct ice_sw_fv_section *es;
2778 struct ice_pkg_enum state;
2782 /* if the HW segment pointer is null then the first iteration of
2783 * ice_pkg_enum_section() will fail. In this case the Hw tables will
2784 * not be filled and return success.
2787 ice_debug(hw, ICE_DBG_PKG, "hw->seg is NULL, tables are not filled\n");
2791 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
2793 sect = ice_pkg_enum_section(hw->seg, &state, sid);
2797 case ICE_SID_XLT1_SW:
2798 case ICE_SID_XLT1_FD:
2799 case ICE_SID_XLT1_RSS:
2800 case ICE_SID_XLT1_ACL:
2801 case ICE_SID_XLT1_PE:
2802 xlt1 = (struct ice_xlt1_section *)sect;
2804 sect_len = LE16_TO_CPU(xlt1->count) *
2805 sizeof(*hw->blk[block_id].xlt1.t);
2806 dst = hw->blk[block_id].xlt1.t;
2807 dst_len = hw->blk[block_id].xlt1.count *
2808 sizeof(*hw->blk[block_id].xlt1.t);
2810 case ICE_SID_XLT2_SW:
2811 case ICE_SID_XLT2_FD:
2812 case ICE_SID_XLT2_RSS:
2813 case ICE_SID_XLT2_ACL:
2814 case ICE_SID_XLT2_PE:
2815 xlt2 = (struct ice_xlt2_section *)sect;
2816 src = (u8 *)xlt2->value;
2817 sect_len = LE16_TO_CPU(xlt2->count) *
2818 sizeof(*hw->blk[block_id].xlt2.t);
2819 dst = (u8 *)hw->blk[block_id].xlt2.t;
2820 dst_len = hw->blk[block_id].xlt2.count *
2821 sizeof(*hw->blk[block_id].xlt2.t);
2823 case ICE_SID_PROFID_TCAM_SW:
2824 case ICE_SID_PROFID_TCAM_FD:
2825 case ICE_SID_PROFID_TCAM_RSS:
2826 case ICE_SID_PROFID_TCAM_ACL:
2827 case ICE_SID_PROFID_TCAM_PE:
2828 pid = (struct ice_prof_id_section *)sect;
2829 src = (u8 *)pid->entry;
2830 sect_len = LE16_TO_CPU(pid->count) *
2831 sizeof(*hw->blk[block_id].prof.t);
2832 dst = (u8 *)hw->blk[block_id].prof.t;
2833 dst_len = hw->blk[block_id].prof.count *
2834 sizeof(*hw->blk[block_id].prof.t);
2836 case ICE_SID_PROFID_REDIR_SW:
2837 case ICE_SID_PROFID_REDIR_FD:
2838 case ICE_SID_PROFID_REDIR_RSS:
2839 case ICE_SID_PROFID_REDIR_ACL:
2840 case ICE_SID_PROFID_REDIR_PE:
2841 pr = (struct ice_prof_redir_section *)sect;
2842 src = pr->redir_value;
2843 sect_len = LE16_TO_CPU(pr->count) *
2844 sizeof(*hw->blk[block_id].prof_redir.t);
2845 dst = hw->blk[block_id].prof_redir.t;
2846 dst_len = hw->blk[block_id].prof_redir.count *
2847 sizeof(*hw->blk[block_id].prof_redir.t);
2849 case ICE_SID_FLD_VEC_SW:
2850 case ICE_SID_FLD_VEC_FD:
2851 case ICE_SID_FLD_VEC_RSS:
2852 case ICE_SID_FLD_VEC_ACL:
2853 case ICE_SID_FLD_VEC_PE:
2854 es = (struct ice_sw_fv_section *)sect;
2856 sect_len = LE16_TO_CPU(es->count) *
2857 hw->blk[block_id].es.fvw *
2858 sizeof(*hw->blk[block_id].es.t);
2859 dst = (u8 *)hw->blk[block_id].es.t;
2860 dst_len = hw->blk[block_id].es.count *
2861 hw->blk[block_id].es.fvw *
2862 sizeof(*hw->blk[block_id].es.t);
2868 /* if the section offset exceeds destination length, terminate
2871 if (offset > dst_len)
2874 /* if the sum of section size and offset exceed destination size
2875 * then we are out of bounds of the Hw table size for that PF.
2876 * Changing section length to fill the remaining table space
2879 if ((offset + sect_len) > dst_len)
2880 sect_len = dst_len - offset;
2882 ice_memcpy(dst + offset, src, sect_len, ICE_NONDMA_TO_NONDMA);
2884 sect = ice_pkg_enum_section(NULL, &state, sid);
2889 * ice_fill_blk_tbls - Read package content for tables of a block
2890 * @hw: pointer to the hardware structure
2891 * @block_id: The block ID which contains the tables to be copied
2893 * Reads the current package contents and populates the driver
2894 * database with the data it contains to allow for advanced driver
2897 static void ice_fill_blk_tbls(struct ice_hw *hw, enum ice_block block_id)
2899 ice_fill_tbl(hw, block_id, hw->blk[block_id].xlt1.sid);
2900 ice_fill_tbl(hw, block_id, hw->blk[block_id].xlt2.sid);
2901 ice_fill_tbl(hw, block_id, hw->blk[block_id].prof.sid);
2902 ice_fill_tbl(hw, block_id, hw->blk[block_id].prof_redir.sid);
2903 ice_fill_tbl(hw, block_id, hw->blk[block_id].es.sid);
2907 * ice_free_flow_profs - free flow profile entries
2908 * @hw: pointer to the hardware structure
2910 static void ice_free_flow_profs(struct ice_hw *hw)
2914 for (i = 0; i < ICE_BLK_COUNT; i++) {
2915 struct ice_flow_prof *p, *tmp;
2917 if (!&hw->fl_profs[i])
2920 /* This call is being made as part of resource deallocation
2921 * during unload. Lock acquire and release will not be
2924 LIST_FOR_EACH_ENTRY_SAFE(p, tmp, &hw->fl_profs[i],
2925 ice_flow_prof, l_entry) {
2926 struct ice_flow_entry *e, *t;
2928 LIST_FOR_EACH_ENTRY_SAFE(e, t, &p->entries,
2929 ice_flow_entry, l_entry)
2930 ice_flow_rem_entry(hw, ICE_FLOW_ENTRY_HNDL(e));
2932 LIST_DEL(&p->l_entry);
2934 ice_free(hw, p->acts);
2938 ice_destroy_lock(&hw->fl_profs_locks[i]);
2943 * ice_free_prof_map - frees the profile map
2944 * @hw: pointer to the hardware structure
2945 * @blk: the HW block which contains the profile map to be freed
2947 static void ice_free_prof_map(struct ice_hw *hw, enum ice_block blk)
2949 struct ice_prof_map *del, *tmp;
2951 if (LIST_EMPTY(&hw->blk[blk].es.prof_map))
2954 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &hw->blk[blk].es.prof_map,
2955 ice_prof_map, list) {
2956 ice_rem_prof(hw, blk, del->profile_cookie);
2961 * ice_free_vsig_tbl - free complete VSIG table entries
2962 * @hw: pointer to the hardware structure
2963 * @blk: the HW block on which to free the VSIG table entries
2965 static void ice_free_vsig_tbl(struct ice_hw *hw, enum ice_block blk)
2969 if (!hw->blk[blk].xlt2.vsig_tbl)
2972 for (i = 1; i < ICE_MAX_VSIGS; i++)
2973 if (hw->blk[blk].xlt2.vsig_tbl[i].in_use)
2974 ice_vsig_free(hw, blk, i);
2978 * ice_free_hw_tbls - free hardware table memory
2979 * @hw: pointer to the hardware structure
2981 void ice_free_hw_tbls(struct ice_hw *hw)
2985 for (i = 0; i < ICE_BLK_COUNT; i++) {
2986 ice_free_prof_map(hw, (enum ice_block)i);
2987 ice_free_vsig_tbl(hw, (enum ice_block)i);
2988 ice_free(hw, hw->blk[i].xlt1.ptypes);
2989 ice_free(hw, hw->blk[i].xlt1.ptg_tbl);
2990 ice_free(hw, hw->blk[i].xlt1.t);
2991 ice_free(hw, hw->blk[i].xlt2.t);
2992 ice_free(hw, hw->blk[i].xlt2.vsig_tbl);
2993 ice_free(hw, hw->blk[i].xlt2.vsis);
2994 ice_free(hw, hw->blk[i].prof.t);
2995 ice_free(hw, hw->blk[i].prof_redir.t);
2996 ice_free(hw, hw->blk[i].es.t);
2997 ice_free(hw, hw->blk[i].es.ref_count);
2998 ice_free(hw, hw->blk[i].es.written);
3001 ice_memset(hw->blk, 0, sizeof(hw->blk), ICE_NONDMA_MEM);
3003 ice_free_flow_profs(hw);
3007 * ice_init_flow_profs - init flow profile locks and list heads
3008 * @hw: pointer to the hardware structure
3010 static void ice_init_flow_profs(struct ice_hw *hw)
3014 for (i = 0; i < ICE_BLK_COUNT; i++) {
3015 ice_init_lock(&hw->fl_profs_locks[i]);
3016 INIT_LIST_HEAD(&hw->fl_profs[i]);
3021 * ice_init_sw_xlt1_db - init software XLT1 database from HW tables
3022 * @hw: pointer to the hardware structure
3023 * @blk: the HW block to initialize
3026 void ice_init_sw_xlt1_db(struct ice_hw *hw, enum ice_block blk)
3030 for (pt = 0; pt < hw->blk[blk].xlt1.count; pt++) {
3033 ptg = hw->blk[blk].xlt1.t[pt];
3034 if (ptg != ICE_DEFAULT_PTG) {
3035 ice_ptg_alloc_val(hw, blk, ptg);
3036 ice_ptg_add_mv_ptype(hw, blk, pt, ptg);
3042 * ice_init_sw_xlt2_db - init software XLT2 database from HW tables
3043 * @hw: pointer to the hardware structure
3044 * @blk: the HW block to initialize
3047 void ice_init_sw_xlt2_db(struct ice_hw *hw, enum ice_block blk)
3051 for (vsi = 0; vsi < hw->blk[blk].xlt2.count; vsi++) {
3054 vsig = hw->blk[blk].xlt2.t[vsi];
3056 ice_vsig_alloc_val(hw, blk, vsig);
3057 ice_vsig_add_mv_vsi(hw, blk, vsi, vsig);
3058 /* no changes at this time, since this has been
3059 * initialized from the original package
3061 hw->blk[blk].xlt2.vsis[vsi].changed = 0;
3067 * ice_init_sw_db - init software database from HW tables
3068 * @hw: pointer to the hardware structure
3071 void ice_init_sw_db(struct ice_hw *hw)
3075 for (i = 0; i < ICE_BLK_COUNT; i++) {
3076 ice_init_sw_xlt1_db(hw, (enum ice_block)i);
3077 ice_init_sw_xlt2_db(hw, (enum ice_block)i);
3082 * ice_init_hw_tbls - init hardware table memory
3083 * @hw: pointer to the hardware structure
3085 enum ice_status ice_init_hw_tbls(struct ice_hw *hw)
3089 ice_init_flow_profs(hw);
3091 for (i = 0; i < ICE_BLK_COUNT; i++) {
3092 struct ice_prof_redir *prof_redir = &hw->blk[i].prof_redir;
3093 struct ice_prof_tcam *prof = &hw->blk[i].prof;
3094 struct ice_xlt1 *xlt1 = &hw->blk[i].xlt1;
3095 struct ice_xlt2 *xlt2 = &hw->blk[i].xlt2;
3096 struct ice_es *es = &hw->blk[i].es;
3098 hw->blk[i].overwrite = blk_sizes[i].overwrite;
3099 es->reverse = blk_sizes[i].reverse;
3101 xlt1->sid = ice_blk_sids[i][ICE_SID_XLT1_OFF];
3102 xlt1->count = blk_sizes[i].xlt1;
3104 xlt1->ptypes = (struct ice_ptg_ptype *)
3105 ice_calloc(hw, xlt1->count, sizeof(*xlt1->ptypes));
3110 xlt1->ptg_tbl = (struct ice_ptg_entry *)
3111 ice_calloc(hw, ICE_MAX_PTGS, sizeof(*xlt1->ptg_tbl));
3116 xlt1->t = (u8 *)ice_calloc(hw, xlt1->count, sizeof(*xlt1->t));
3120 xlt2->sid = ice_blk_sids[i][ICE_SID_XLT2_OFF];
3121 xlt2->count = blk_sizes[i].xlt2;
3123 xlt2->vsis = (struct ice_vsig_vsi *)
3124 ice_calloc(hw, xlt2->count, sizeof(*xlt2->vsis));
3129 xlt2->vsig_tbl = (struct ice_vsig_entry *)
3130 ice_calloc(hw, xlt2->count, sizeof(*xlt2->vsig_tbl));
3131 if (!xlt2->vsig_tbl)
3134 xlt2->t = (u16 *)ice_calloc(hw, xlt2->count, sizeof(*xlt2->t));
3138 prof->sid = ice_blk_sids[i][ICE_SID_PR_OFF];
3139 prof->count = blk_sizes[i].prof_tcam;
3140 prof->max_prof_id = blk_sizes[i].prof_id;
3141 prof->cdid_bits = blk_sizes[i].prof_cdid_bits;
3142 prof->t = (struct ice_prof_tcam_entry *)
3143 ice_calloc(hw, prof->count, sizeof(*prof->t));
3148 prof_redir->sid = ice_blk_sids[i][ICE_SID_PR_REDIR_OFF];
3149 prof_redir->count = blk_sizes[i].prof_redir;
3150 prof_redir->t = (u8 *)ice_calloc(hw, prof_redir->count,
3151 sizeof(*prof_redir->t));
3156 es->sid = ice_blk_sids[i][ICE_SID_ES_OFF];
3157 es->count = blk_sizes[i].es;
3158 es->fvw = blk_sizes[i].fvw;
3159 es->t = (struct ice_fv_word *)
3160 ice_calloc(hw, es->count * es->fvw, sizeof(*es->t));
3165 es->ref_count = (u16 *)
3166 ice_calloc(hw, es->count, sizeof(*es->ref_count));
3168 es->written = (u8 *)
3169 ice_calloc(hw, es->count, sizeof(*es->written));
3174 INIT_LIST_HEAD(&es->prof_map);
3176 /* Now that tables are allocated, read in package data */
3177 ice_fill_blk_tbls(hw, (enum ice_block)i);
3185 ice_free_hw_tbls(hw);
3186 return ICE_ERR_NO_MEMORY;
3190 * ice_prof_gen_key - generate profile ID key
3191 * @hw: pointer to the HW struct
3192 * @blk: the block in which to write profile ID to
3193 * @ptg: packet type group (PTG) portion of key
3194 * @vsig: VSIG portion of key
3195 * @cdid: cdid portion of key
3196 * @flags: flag portion of key
3197 * @vl_msk: valid mask
3198 * @dc_msk: don't care mask
3199 * @nm_msk: never match mask
3200 * @key: output of profile ID key
3202 static enum ice_status
3203 ice_prof_gen_key(struct ice_hw *hw, enum ice_block blk, u8 ptg, u16 vsig,
3204 u8 cdid, u16 flags, u8 vl_msk[ICE_TCAM_KEY_VAL_SZ],
3205 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ], u8 nm_msk[ICE_TCAM_KEY_VAL_SZ],
3206 u8 key[ICE_TCAM_KEY_SZ])
3208 struct ice_prof_id_key inkey;
3211 inkey.xlt2_cdid = CPU_TO_LE16(vsig);
3212 inkey.flags = CPU_TO_LE16(flags);
3214 switch (hw->blk[blk].prof.cdid_bits) {
3218 #define ICE_CD_2_M 0xC000U
3219 #define ICE_CD_2_S 14
3220 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_2_M);
3221 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_2_S);
3224 #define ICE_CD_4_M 0xF000U
3225 #define ICE_CD_4_S 12
3226 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_4_M);
3227 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_4_S);
3230 #define ICE_CD_8_M 0xFF00U
3231 #define ICE_CD_8_S 16
3232 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_8_M);
3233 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_8_S);
3236 ice_debug(hw, ICE_DBG_PKG, "Error in profile config\n");
3240 return ice_set_key(key, ICE_TCAM_KEY_SZ, (u8 *)&inkey, vl_msk, dc_msk,
3241 nm_msk, 0, ICE_TCAM_KEY_SZ / 2);
3245 * ice_tcam_write_entry - write TCAM entry
3246 * @hw: pointer to the HW struct
3247 * @blk: the block in which to write profile ID to
3248 * @idx: the entry index to write to
3249 * @prof_id: profile ID
3250 * @ptg: packet type group (PTG) portion of key
3251 * @vsig: VSIG portion of key
3252 * @cdid: cdid portion of key
3253 * @flags: flag portion of key
3254 * @vl_msk: valid mask
3255 * @dc_msk: don't care mask
3256 * @nm_msk: never match mask
3258 static enum ice_status
3259 ice_tcam_write_entry(struct ice_hw *hw, enum ice_block blk, u16 idx,
3260 u8 prof_id, u8 ptg, u16 vsig, u8 cdid, u16 flags,
3261 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ],
3262 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ],
3263 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ])
3265 struct ice_prof_tcam_entry;
3266 enum ice_status status;
3268 status = ice_prof_gen_key(hw, blk, ptg, vsig, cdid, flags, vl_msk,
3269 dc_msk, nm_msk, hw->blk[blk].prof.t[idx].key);
3271 hw->blk[blk].prof.t[idx].addr = CPU_TO_LE16(idx);
3272 hw->blk[blk].prof.t[idx].prof_id = prof_id;
3279 * ice_vsig_get_ref - returns number of VSIs belong to a VSIG
3280 * @hw: pointer to the hardware structure
3282 * @vsig: VSIG to query
3283 * @refs: pointer to variable to receive the reference count
3285 static enum ice_status
3286 ice_vsig_get_ref(struct ice_hw *hw, enum ice_block blk, u16 vsig, u16 *refs)
3288 u16 idx = vsig & ICE_VSIG_IDX_M;
3289 struct ice_vsig_vsi *ptr;
3292 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
3293 return ICE_ERR_DOES_NOT_EXIST;
3295 ptr = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
3298 ptr = ptr->next_vsi;
3305 * ice_get_ptg - get or allocate a ptg for a ptype
3306 * @hw: pointer to the hardware structure
3308 * @ptype: the ptype to retrieve the PTG for
3309 * @ptg: receives the PTG of the ptype
3310 * @add: receive boolean indicating whether PTG was added or not
3312 static enum ice_status
3313 ice_get_ptg(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 *ptg,
3316 enum ice_status status;
3318 *ptg = ICE_DEFAULT_PTG;
3321 status = ice_ptg_find_ptype(hw, blk, ptype, ptg);
3325 if (*ptg == ICE_DEFAULT_PTG) {
3326 /* need to allocate a PTG, and add ptype to it */
3327 *ptg = ice_ptg_alloc(hw, blk);
3328 if (*ptg == ICE_DEFAULT_PTG)
3329 return ICE_ERR_HW_TABLE;
3331 status = ice_ptg_add_mv_ptype(hw, blk, ptype, *ptg);
3333 return ICE_ERR_HW_TABLE;
3342 * ice_has_prof_vsig - check to see if VSIG has a specific profile
3343 * @hw: pointer to the hardware structure
3345 * @vsig: VSIG to check against
3346 * @hdl: profile handle
3349 ice_has_prof_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl)
3351 u16 idx = vsig & ICE_VSIG_IDX_M;
3352 struct ice_vsig_prof *ent;
3354 LIST_FOR_EACH_ENTRY(ent, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
3355 ice_vsig_prof, list) {
3356 if (ent->profile_cookie == hdl)
3360 ice_debug(hw, ICE_DBG_INIT,
3361 "Characteristic list for VSI group %d not found.\n",
3367 * ice_prof_bld_es - build profile ID extraction sequence changes
3368 * @hw: pointer to the HW struct
3369 * @blk: hardware block
3370 * @bld: the update package buffer build to add to
3371 * @chgs: the list of changes to make in hardware
3373 static enum ice_status
3374 ice_prof_bld_es(struct ice_hw *hw, enum ice_block blk,
3375 struct ice_buf_build *bld, struct LIST_HEAD_TYPE *chgs)
3377 u16 vec_size = hw->blk[blk].es.fvw * sizeof(struct ice_fv_word);
3378 struct ice_chs_chg *tmp;
3380 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
3381 if (tmp->type == ICE_PTG_ES_ADD && tmp->add_prof) {
3382 u16 off = tmp->prof_id * hw->blk[blk].es.fvw;
3383 struct ice_pkg_es *p;
3386 id = ice_sect_id(blk, ICE_VEC_TBL);
3387 p = (struct ice_pkg_es *)
3388 ice_pkg_buf_alloc_section(bld, id, sizeof(*p) +
3393 return ICE_ERR_MAX_LIMIT;
3395 p->count = CPU_TO_LE16(1);
3396 p->offset = CPU_TO_LE16(tmp->prof_id);
3398 ice_memcpy(p->es, &hw->blk[blk].es.t[off], vec_size,
3399 ICE_NONDMA_TO_NONDMA);
3407 * ice_prof_bld_tcam - build profile ID TCAM changes
3408 * @hw: pointer to the HW struct
3409 * @blk: hardware block
3410 * @bld: the update package buffer build to add to
3411 * @chgs: the list of changes to make in hardware
3413 static enum ice_status
3414 ice_prof_bld_tcam(struct ice_hw *hw, enum ice_block blk,
3415 struct ice_buf_build *bld, struct LIST_HEAD_TYPE *chgs)
3417 struct ice_chs_chg *tmp;
3419 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
3420 if (tmp->type == ICE_TCAM_ADD && tmp->add_tcam_idx) {
3421 struct ice_prof_id_section *p;
3424 id = ice_sect_id(blk, ICE_PROF_TCAM);
3425 p = (struct ice_prof_id_section *)
3426 ice_pkg_buf_alloc_section(bld, id, sizeof(*p));
3429 return ICE_ERR_MAX_LIMIT;
3431 p->count = CPU_TO_LE16(1);
3432 p->entry[0].addr = CPU_TO_LE16(tmp->tcam_idx);
3433 p->entry[0].prof_id = tmp->prof_id;
3435 ice_memcpy(p->entry[0].key,
3436 &hw->blk[blk].prof.t[tmp->tcam_idx].key,
3437 sizeof(hw->blk[blk].prof.t->key),
3438 ICE_NONDMA_TO_NONDMA);
3446 * ice_prof_bld_xlt1 - build XLT1 changes
3447 * @blk: hardware block
3448 * @bld: the update package buffer build to add to
3449 * @chgs: the list of changes to make in hardware
3451 static enum ice_status
3452 ice_prof_bld_xlt1(enum ice_block blk, struct ice_buf_build *bld,
3453 struct LIST_HEAD_TYPE *chgs)
3455 struct ice_chs_chg *tmp;
3457 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
3458 if (tmp->type == ICE_PTG_ES_ADD && tmp->add_ptg) {
3459 struct ice_xlt1_section *p;
3462 id = ice_sect_id(blk, ICE_XLT1);
3463 p = (struct ice_xlt1_section *)
3464 ice_pkg_buf_alloc_section(bld, id, sizeof(*p));
3467 return ICE_ERR_MAX_LIMIT;
3469 p->count = CPU_TO_LE16(1);
3470 p->offset = CPU_TO_LE16(tmp->ptype);
3471 p->value[0] = tmp->ptg;
3479 * ice_prof_bld_xlt2 - build XLT2 changes
3480 * @blk: hardware block
3481 * @bld: the update package buffer build to add to
3482 * @chgs: the list of changes to make in hardware
3484 static enum ice_status
3485 ice_prof_bld_xlt2(enum ice_block blk, struct ice_buf_build *bld,
3486 struct LIST_HEAD_TYPE *chgs)
3488 struct ice_chs_chg *tmp;
3490 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
3493 if (tmp->type == ICE_VSIG_ADD)
3495 else if (tmp->type == ICE_VSI_MOVE)
3497 else if (tmp->type == ICE_VSIG_REM)
3501 struct ice_xlt2_section *p;
3504 id = ice_sect_id(blk, ICE_XLT2);
3505 p = (struct ice_xlt2_section *)
3506 ice_pkg_buf_alloc_section(bld, id, sizeof(*p));
3509 return ICE_ERR_MAX_LIMIT;
3511 p->count = CPU_TO_LE16(1);
3512 p->offset = CPU_TO_LE16(tmp->vsi);
3513 p->value[0] = CPU_TO_LE16(tmp->vsig);
3521 * ice_upd_prof_hw - update hardware using the change list
3522 * @hw: pointer to the HW struct
3523 * @blk: hardware block
3524 * @chgs: the list of changes to make in hardware
3526 static enum ice_status
3527 ice_upd_prof_hw(struct ice_hw *hw, enum ice_block blk,
3528 struct LIST_HEAD_TYPE *chgs)
3530 struct ice_buf_build *b;
3531 struct ice_chs_chg *tmp;
3532 enum ice_status status;
3540 /* count number of sections we need */
3541 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
3542 switch (tmp->type) {
3543 case ICE_PTG_ES_ADD:
3561 sects = xlt1 + xlt2 + tcam + es;
3566 /* Build update package buffer */
3567 b = ice_pkg_buf_alloc(hw);
3569 return ICE_ERR_NO_MEMORY;
3571 status = ice_pkg_buf_reserve_section(b, sects);
3575 /* Preserve order of table update: ES, TCAM, PTG, VSIG */
3577 status = ice_prof_bld_es(hw, blk, b, chgs);
3583 status = ice_prof_bld_tcam(hw, blk, b, chgs);
3589 status = ice_prof_bld_xlt1(blk, b, chgs);
3595 status = ice_prof_bld_xlt2(blk, b, chgs);
3600 /* After package buffer build check if the section count in buffer is
3601 * non-zero and matches the number of sections detected for package
3604 pkg_sects = ice_pkg_buf_get_active_sections(b);
3605 if (!pkg_sects || pkg_sects != sects) {
3606 status = ICE_ERR_INVAL_SIZE;
3610 /* update package */
3611 status = ice_update_pkg(hw, ice_pkg_buf(b), 1);
3612 if (status == ICE_ERR_AQ_ERROR)
3613 ice_debug(hw, ICE_DBG_INIT, "Unable to update HW profile.");
3616 ice_pkg_buf_free(hw, b);
3621 * ice_update_fd_mask - set Flow Director Field Vector mask for a profile
3622 * @hw: pointer to the HW struct
3623 * @prof_id: profile ID
3624 * @mask_sel: mask select
3626 * This function enable any of the masks selected by the mask select parameter
3627 * for the profile specified.
3629 static void ice_update_fd_mask(struct ice_hw *hw, u16 prof_id, u32 mask_sel)
3631 wr32(hw, GLQF_FDMASK_SEL(prof_id), mask_sel);
3633 ice_debug(hw, ICE_DBG_INIT, "fd mask(%d): %x = %x\n", prof_id,
3634 GLQF_FDMASK_SEL(prof_id), mask_sel);
3637 #define ICE_SRC_DST_MAX_COUNT 8
3639 struct ice_fd_src_dst_pair {
3645 static const struct ice_fd_src_dst_pair ice_fd_pairs[] = {
3646 /* These are defined in pairs */
3647 { ICE_PROT_IPV4_OF_OR_S, 2, 12 },
3648 { ICE_PROT_IPV4_OF_OR_S, 2, 16 },
3650 { ICE_PROT_IPV4_IL, 2, 12 },
3651 { ICE_PROT_IPV4_IL, 2, 16 },
3653 { ICE_PROT_IPV6_OF_OR_S, 8, 8 },
3654 { ICE_PROT_IPV6_OF_OR_S, 8, 24 },
3656 { ICE_PROT_IPV6_IL, 8, 8 },
3657 { ICE_PROT_IPV6_IL, 8, 24 },
3659 { ICE_PROT_TCP_IL, 1, 0 },
3660 { ICE_PROT_TCP_IL, 1, 2 },
3662 { ICE_PROT_UDP_OF, 1, 0 },
3663 { ICE_PROT_UDP_OF, 1, 2 },
3665 { ICE_PROT_UDP_IL_OR_S, 1, 0 },
3666 { ICE_PROT_UDP_IL_OR_S, 1, 2 },
3668 { ICE_PROT_SCTP_IL, 1, 0 },
3669 { ICE_PROT_SCTP_IL, 1, 2 }
3672 #define ICE_FD_SRC_DST_PAIR_COUNT ARRAY_SIZE(ice_fd_pairs)
3675 * ice_update_fd_swap - set register appropriately for a FD FV extraction
3676 * @hw: pointer to the HW struct
3677 * @prof_id: profile ID
3678 * @es: extraction sequence (length of array is determined by the block)
3680 static enum ice_status
3681 ice_update_fd_swap(struct ice_hw *hw, u16 prof_id, struct ice_fv_word *es)
3683 ice_declare_bitmap(pair_list, ICE_FD_SRC_DST_PAIR_COUNT);
3684 u8 pair_start[ICE_FD_SRC_DST_PAIR_COUNT] = { 0 };
3685 #define ICE_FD_FV_NOT_FOUND (-2)
3686 s8 first_free = ICE_FD_FV_NOT_FOUND;
3687 u8 used[ICE_MAX_FV_WORDS] = { 0 };
3692 ice_memset(pair_list, 0, sizeof(pair_list), ICE_NONDMA_MEM);
3694 ice_init_fd_mask_regs(hw);
3696 /* This code assumes that the Flow Director field vectors are assigned
3697 * from the end of the FV indexes working towards the zero index, that
3698 * only complete fields will be included and will be consecutive, and
3699 * that there are no gaps between valid indexes.
3702 /* Determine swap fields present */
3703 for (i = 0; i < hw->blk[ICE_BLK_FD].es.fvw; i++) {
3704 /* Find the first free entry, assuming right to left population.
3705 * This is where we can start adding additional pairs if needed.
3707 if (first_free == ICE_FD_FV_NOT_FOUND && es[i].prot_id !=
3711 for (j = 0; j < ICE_FD_SRC_DST_PAIR_COUNT; j++) {
3712 if (es[i].prot_id == ice_fd_pairs[j].prot_id &&
3713 es[i].off == ice_fd_pairs[j].off) {
3714 ice_set_bit(j, pair_list);
3720 orig_free = first_free;
3722 /* determine missing swap fields that need to be added */
3723 for (i = 0; i < ICE_FD_SRC_DST_PAIR_COUNT; i += 2) {
3724 u8 bit1 = ice_is_bit_set(pair_list, i + 1);
3725 u8 bit0 = ice_is_bit_set(pair_list, i);
3730 /* add the appropriate 'paired' entry */
3736 /* check for room */
3737 if (first_free + 1 < ice_fd_pairs[index].count)
3738 return ICE_ERR_MAX_LIMIT;
3740 /* place in extraction sequence */
3741 for (k = 0; k < ice_fd_pairs[index].count; k++) {
3742 es[first_free - k].prot_id =
3743 ice_fd_pairs[index].prot_id;
3744 es[first_free - k].off =
3745 ice_fd_pairs[index].off + (k * 2);
3747 /* keep track of non-relevant fields */
3748 mask_sel |= 1 << (first_free - k);
3751 pair_start[index] = first_free;
3752 first_free -= ice_fd_pairs[index].count;
3756 /* fill in the swap array */
3757 si = hw->blk[ICE_BLK_FD].es.fvw - 1;
3759 u8 indexes_used = 1;
3761 /* assume flat at this index */
3762 #define ICE_SWAP_VALID 0x80
3763 used[si] = si | ICE_SWAP_VALID;
3765 if (orig_free == ICE_FD_FV_NOT_FOUND || si <= orig_free) {
3770 /* check for a swap location */
3771 for (j = 0; j < ICE_FD_SRC_DST_PAIR_COUNT; j++) {
3772 if (es[si].prot_id == ice_fd_pairs[j].prot_id &&
3773 es[si].off == ice_fd_pairs[j].off) {
3776 /* determine the appropriate matching field */
3777 idx = j + ((j % 2) ? -1 : 1);
3779 indexes_used = ice_fd_pairs[idx].count;
3780 for (k = 0; k < indexes_used; k++) {
3781 used[si - k] = (pair_start[idx] - k) |
3792 /* for each set of 4 swap indexes, write the appropriate register */
3793 for (j = 0; j < hw->blk[ICE_BLK_FD].es.fvw / 4; j++) {
3796 for (k = 0; k < 4; k++) {
3801 raw_entry |= used[idx] << (k * 8);
3804 /* write the appropriate register set, based on HW block */
3805 wr32(hw, GLQF_FDSWAP(prof_id, j), raw_entry);
3807 ice_debug(hw, ICE_DBG_INIT, "swap wr(%d, %d): %x = %x\n",
3808 prof_id, j, GLQF_FDSWAP(prof_id, j), raw_entry);
3811 /* update the masks for this profile to be sure we ignore fields that
3812 * are not relevant to our match criteria
3814 ice_update_fd_mask(hw, prof_id, mask_sel);
3820 * ice_add_prof - add profile
3821 * @hw: pointer to the HW struct
3822 * @blk: hardware block
3823 * @id: profile tracking ID
3824 * @ptypes: array of bitmaps indicating ptypes (ICE_FLOW_PTYPE_MAX bits)
3825 * @es: extraction sequence (length of array is determined by the block)
3827 * This function registers a profile, which matches a set of PTYPES with a
3828 * particular extraction sequence. While the hardware profile is allocated
3829 * it will not be written until the first call to ice_add_flow that specifies
3830 * the ID value used here.
3833 ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64 id, u8 ptypes[],
3834 struct ice_fv_word *es)
3836 u32 bytes = DIVIDE_AND_ROUND_UP(ICE_FLOW_PTYPE_MAX, BITS_PER_BYTE);
3837 struct ice_prof_map *prof;
3838 enum ice_status status;
3842 /* search for existing profile */
3843 status = ice_find_prof_id(hw, blk, es, &prof_id);
3845 /* allocate profile ID */
3846 status = ice_alloc_prof_id(hw, blk, &prof_id);
3848 goto err_ice_add_prof;
3849 if (blk == ICE_BLK_FD) {
3850 /* For Flow Director block, the extraction sequence may
3851 * need to be altered in the case where there are paired
3852 * fields that have no match. This is necessary because
3853 * for Flow Director, src and dest fields need to paired
3854 * for filter programming and these values are swapped
3857 status = ice_update_fd_swap(hw, prof_id, es);
3859 goto err_ice_add_prof;
3862 /* and write new es */
3863 ice_write_es(hw, blk, prof_id, es);
3866 ice_prof_inc_ref(hw, blk, prof_id);
3868 /* add profile info */
3870 prof = (struct ice_prof_map *)ice_malloc(hw, sizeof(*prof));
3872 goto err_ice_add_prof;
3874 prof->profile_cookie = id;
3875 prof->prof_id = prof_id;
3876 prof->ptype_count = 0;
3879 /* build list of ptgs */
3880 while (bytes && prof->ptype_count < ICE_MAX_PTYPE_PER_PROFILE) {
3883 if (!ptypes[byte]) {
3888 /* Examine 8 bits per byte */
3889 for (bit = 0; bit < 8; bit++) {
3890 if (ptypes[byte] & 1 << bit) {
3894 ptype = byte * 8 + bit;
3895 if (ptype < ICE_FLOW_PTYPE_MAX) {
3896 prof->ptype[prof->ptype_count] = ptype;
3898 if (++prof->ptype_count >=
3899 ICE_MAX_PTYPE_PER_PROFILE)
3903 /* nothing left in byte, then exit */
3904 m = ~((1 << (bit + 1)) - 1);
3905 if (!(ptypes[byte] & m))
3913 LIST_ADD(&prof->list, &hw->blk[blk].es.prof_map);
3922 * ice_search_prof_id - Search for a profile tracking ID
3923 * @hw: pointer to the HW struct
3924 * @blk: hardware block
3925 * @id: profile tracking ID
3927 * This will search for a profile tracking ID which was previously added.
3929 struct ice_prof_map *
3930 ice_search_prof_id(struct ice_hw *hw, enum ice_block blk, u64 id)
3932 struct ice_prof_map *entry = NULL;
3933 struct ice_prof_map *map;
3935 LIST_FOR_EACH_ENTRY(map, &hw->blk[blk].es.prof_map, ice_prof_map,
3937 if (map->profile_cookie == id) {
3947 * ice_set_prof_context - Set context for a given profile
3948 * @hw: pointer to the HW struct
3949 * @blk: hardware block
3950 * @id: profile tracking ID
3953 struct ice_prof_map *
3954 ice_set_prof_context(struct ice_hw *hw, enum ice_block blk, u64 id, u64 cntxt)
3956 struct ice_prof_map *entry;
3958 entry = ice_search_prof_id(hw, blk, id);
3960 entry->context = cntxt;
3966 * ice_get_prof_context - Get context for a given profile
3967 * @hw: pointer to the HW struct
3968 * @blk: hardware block
3969 * @id: profile tracking ID
3970 * @cntxt: pointer to variable to receive the context
3972 struct ice_prof_map *
3973 ice_get_prof_context(struct ice_hw *hw, enum ice_block blk, u64 id, u64 *cntxt)
3975 struct ice_prof_map *entry;
3977 entry = ice_search_prof_id(hw, blk, id);
3979 *cntxt = entry->context;
3985 * ice_vsig_prof_id_count - count profiles in a VSIG
3986 * @hw: pointer to the HW struct
3987 * @blk: hardware block
3988 * @vsig: VSIG to remove the profile from
3991 ice_vsig_prof_id_count(struct ice_hw *hw, enum ice_block blk, u16 vsig)
3993 u16 idx = vsig & ICE_VSIG_IDX_M, count = 0;
3994 struct ice_vsig_prof *p;
3996 LIST_FOR_EACH_ENTRY(p, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
3997 ice_vsig_prof, list) {
4005 * ice_rel_tcam_idx - release a TCAM index
4006 * @hw: pointer to the HW struct
4007 * @blk: hardware block
4008 * @idx: the index to release
4010 static enum ice_status
4011 ice_rel_tcam_idx(struct ice_hw *hw, enum ice_block blk, u16 idx)
4013 /* Masks to invoke a never match entry */
4014 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4015 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFE, 0xFF, 0xFF, 0xFF, 0xFF };
4016 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x01, 0x00, 0x00, 0x00, 0x00 };
4017 enum ice_status status;
4019 /* write the TCAM entry */
4020 status = ice_tcam_write_entry(hw, blk, idx, 0, 0, 0, 0, 0, vl_msk,
4025 /* release the TCAM entry */
4026 status = ice_free_tcam_ent(hw, blk, idx);
4032 * ice_rem_prof_id - remove one profile from a VSIG
4033 * @hw: pointer to the HW struct
4034 * @blk: hardware block
4035 * @prof: pointer to profile structure to remove
4037 static enum ice_status
4038 ice_rem_prof_id(struct ice_hw *hw, enum ice_block blk,
4039 struct ice_vsig_prof *prof)
4041 enum ice_status status;
4044 for (i = 0; i < prof->tcam_count; i++) {
4045 prof->tcam[i].in_use = false;
4046 status = ice_rel_tcam_idx(hw, blk, prof->tcam[i].tcam_idx);
4048 return ICE_ERR_HW_TABLE;
4055 * ice_rem_vsig - remove VSIG
4056 * @hw: pointer to the HW struct
4057 * @blk: hardware block
4058 * @vsig: the VSIG to remove
4059 * @chg: the change list
4061 static enum ice_status
4062 ice_rem_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig,
4063 struct LIST_HEAD_TYPE *chg)
4065 u16 idx = vsig & ICE_VSIG_IDX_M;
4066 struct ice_vsig_vsi *vsi_cur;
4067 struct ice_vsig_prof *d, *t;
4068 enum ice_status status;
4070 /* remove TCAM entries */
4071 LIST_FOR_EACH_ENTRY_SAFE(d, t,
4072 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4073 ice_vsig_prof, list) {
4074 status = ice_rem_prof_id(hw, blk, d);
4082 /* Move all VSIS associated with this VSIG to the default VSIG */
4083 vsi_cur = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
4084 /* If the VSIG has at least 1 VSI then iterate through the list
4085 * and remove the VSIs before deleting the group.
4089 struct ice_vsig_vsi *tmp = vsi_cur->next_vsi;
4090 struct ice_chs_chg *p;
4092 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4094 return ICE_ERR_NO_MEMORY;
4096 p->type = ICE_VSIG_REM;
4097 p->orig_vsig = vsig;
4098 p->vsig = ICE_DEFAULT_VSIG;
4099 p->vsi = vsi_cur - hw->blk[blk].xlt2.vsis;
4101 LIST_ADD(&p->list_entry, chg);
4107 status = ice_vsig_free(hw, blk, vsig);
4113 * ice_rem_prof_id_vsig - remove a specific profile from a VSIG
4114 * @hw: pointer to the HW struct
4115 * @blk: hardware block
4116 * @vsig: VSIG to remove the profile from
4117 * @hdl: profile handle indicating which profile to remove
4118 * @chg: list to receive a record of changes
4120 static enum ice_status
4121 ice_rem_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl,
4122 struct LIST_HEAD_TYPE *chg)
4124 u16 idx = vsig & ICE_VSIG_IDX_M;
4125 struct ice_vsig_prof *p, *t;
4126 enum ice_status status;
4128 LIST_FOR_EACH_ENTRY_SAFE(p, t,
4129 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4130 ice_vsig_prof, list) {
4131 if (p->profile_cookie == hdl) {
4132 if (ice_vsig_prof_id_count(hw, blk, vsig) == 1)
4133 /* this is the last profile, remove the VSIG */
4134 return ice_rem_vsig(hw, blk, vsig, chg);
4136 status = ice_rem_prof_id(hw, blk, p);
4145 return ICE_ERR_DOES_NOT_EXIST;
4149 * ice_rem_flow_all - remove all flows with a particular profile
4150 * @hw: pointer to the HW struct
4151 * @blk: hardware block
4152 * @id: profile tracking ID
4154 static enum ice_status
4155 ice_rem_flow_all(struct ice_hw *hw, enum ice_block blk, u64 id)
4157 struct ice_chs_chg *del, *tmp;
4158 struct LIST_HEAD_TYPE chg;
4159 enum ice_status status;
4162 INIT_LIST_HEAD(&chg);
4164 for (i = 1; i < ICE_MAX_VSIGS; i++) {
4165 if (hw->blk[blk].xlt2.vsig_tbl[i].in_use) {
4166 if (ice_has_prof_vsig(hw, blk, i, id)) {
4167 status = ice_rem_prof_id_vsig(hw, blk, i, id,
4170 goto err_ice_rem_flow_all;
4175 status = ice_upd_prof_hw(hw, blk, &chg);
4177 err_ice_rem_flow_all:
4178 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
4179 LIST_DEL(&del->list_entry);
4187 * ice_rem_prof - remove profile
4188 * @hw: pointer to the HW struct
4189 * @blk: hardware block
4190 * @id: profile tracking ID
4192 * This will remove the profile specified by the ID parameter, which was
4193 * previously created through ice_add_prof. If any existing entries
4194 * are associated with this profile, they will be removed as well.
4196 enum ice_status ice_rem_prof(struct ice_hw *hw, enum ice_block blk, u64 id)
4198 enum ice_status status;
4199 struct ice_prof_map *pmap;
4201 pmap = ice_search_prof_id(hw, blk, id);
4203 return ICE_ERR_DOES_NOT_EXIST;
4205 /* remove all flows with this profile */
4206 status = ice_rem_flow_all(hw, blk, pmap->profile_cookie);
4210 /* remove profile */
4211 status = ice_free_prof_id(hw, blk, pmap->prof_id);
4214 /* dereference profile, and possibly remove */
4215 ice_prof_dec_ref(hw, blk, pmap->prof_id);
4217 LIST_DEL(&pmap->list);
4224 * ice_get_prof_ptgs - get ptgs for profile
4225 * @hw: pointer to the HW struct
4226 * @blk: hardware block
4227 * @hdl: profile handle
4230 static enum ice_status
4231 ice_get_prof_ptgs(struct ice_hw *hw, enum ice_block blk, u64 hdl,
4232 struct LIST_HEAD_TYPE *chg)
4234 struct ice_prof_map *map;
4235 struct ice_chs_chg *p;
4238 /* Get the details on the profile specified by the handle ID */
4239 map = ice_search_prof_id(hw, blk, hdl);
4241 return ICE_ERR_DOES_NOT_EXIST;
4243 for (i = 0; i < map->ptype_count; i++) {
4244 enum ice_status status;
4248 status = ice_get_ptg(hw, blk, map->ptype[i], &ptg, &add);
4250 goto err_ice_get_prof_ptgs;
4252 if (add || !hw->blk[blk].es.written[map->prof_id]) {
4253 /* add PTG to change list */
4254 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4256 goto err_ice_get_prof_ptgs;
4258 p->type = ICE_PTG_ES_ADD;
4259 p->ptype = map->ptype[i];
4263 p->add_prof = !hw->blk[blk].es.written[map->prof_id];
4264 p->prof_id = map->prof_id;
4266 hw->blk[blk].es.written[map->prof_id] = true;
4268 LIST_ADD(&p->list_entry, chg);
4274 err_ice_get_prof_ptgs:
4275 /* let caller clean up the change list */
4276 return ICE_ERR_NO_MEMORY;
4280 * ice_get_profs_vsig - get a copy of the list of profiles from a VSIG
4281 * @hw: pointer to the HW struct
4282 * @blk: hardware block
4283 * @vsig: VSIG from which to copy the list
4286 * This routine makes a copy of the list of profiles in the specified VSIG.
4288 static enum ice_status
4289 ice_get_profs_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig,
4290 struct LIST_HEAD_TYPE *lst)
4292 struct ice_vsig_prof *ent1, *ent2;
4293 u16 idx = vsig & ICE_VSIG_IDX_M;
4295 LIST_FOR_EACH_ENTRY(ent1, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4296 ice_vsig_prof, list) {
4297 struct ice_vsig_prof *p;
4299 /* copy to the input list */
4300 p = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*p));
4302 goto err_ice_get_profs_vsig;
4304 ice_memcpy(p, ent1, sizeof(*p), ICE_NONDMA_TO_NONDMA);
4306 LIST_ADD_TAIL(&p->list, lst);
4311 err_ice_get_profs_vsig:
4312 LIST_FOR_EACH_ENTRY_SAFE(ent1, ent2, lst, ice_vsig_prof, list) {
4313 LIST_DEL(&ent1->list);
4317 return ICE_ERR_NO_MEMORY;
4321 * ice_add_prof_to_lst - add profile entry to a list
4322 * @hw: pointer to the HW struct
4323 * @blk: hardware block
4324 * @lst: the list to be added to
4325 * @hdl: profile handle of entry to add
4327 static enum ice_status
4328 ice_add_prof_to_lst(struct ice_hw *hw, enum ice_block blk,
4329 struct LIST_HEAD_TYPE *lst, u64 hdl)
4331 struct ice_vsig_prof *p;
4332 struct ice_prof_map *map;
4335 map = ice_search_prof_id(hw, blk, hdl);
4337 return ICE_ERR_DOES_NOT_EXIST;
4339 p = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*p));
4341 return ICE_ERR_NO_MEMORY;
4343 p->profile_cookie = map->profile_cookie;
4344 p->prof_id = map->prof_id;
4345 p->tcam_count = map->ptype_count;
4347 for (i = 0; i < map->ptype_count; i++) {
4350 p->tcam[i].prof_id = map->prof_id;
4351 p->tcam[i].tcam_idx = ICE_INVALID_TCAM;
4353 ice_ptg_find_ptype(hw, blk, map->ptype[i], &ptg);
4355 p->tcam[i].ptg = ptg;
4358 LIST_ADD(&p->list, lst);
4364 * ice_move_vsi - move VSI to another VSIG
4365 * @hw: pointer to the HW struct
4366 * @blk: hardware block
4367 * @vsi: the VSI to move
4368 * @vsig: the VSIG to move the VSI to
4369 * @chg: the change list
4371 static enum ice_status
4372 ice_move_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig,
4373 struct LIST_HEAD_TYPE *chg)
4375 enum ice_status status;
4376 struct ice_chs_chg *p;
4379 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4381 return ICE_ERR_NO_MEMORY;
4383 status = ice_vsig_find_vsi(hw, blk, vsi, &orig_vsig);
4385 status = ice_vsig_add_mv_vsi(hw, blk, vsi, vsig);
4391 p->type = ICE_VSI_MOVE;
4393 p->orig_vsig = orig_vsig;
4396 LIST_ADD(&p->list_entry, chg);
4402 * ice_prof_tcam_ena_dis - add enable or disable TCAM change
4403 * @hw: pointer to the HW struct
4404 * @blk: hardware block
4405 * @enable: true to enable, false to disable
4406 * @vsig: the vsig of the TCAM entry
4407 * @tcam: pointer the TCAM info structure of the TCAM to disable
4408 * @chg: the change list
4410 * This function appends an enable or disable TCAM entry in the change log
4412 static enum ice_status
4413 ice_prof_tcam_ena_dis(struct ice_hw *hw, enum ice_block blk, bool enable,
4414 u16 vsig, struct ice_tcam_inf *tcam,
4415 struct LIST_HEAD_TYPE *chg)
4417 enum ice_status status;
4418 struct ice_chs_chg *p;
4420 /* Default: enable means change the low flag bit to don't care */
4421 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x01, 0x00, 0x00, 0x00, 0x00 };
4422 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
4423 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x01, 0x00, 0x00, 0x00, 0x00 };
4425 /* If disabled, change the low flag bit to never match */
4431 /* add TCAM to change list */
4432 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4434 return ICE_ERR_NO_MEMORY;
4436 status = ice_tcam_write_entry(hw, blk, tcam->tcam_idx, tcam->prof_id,
4437 tcam->ptg, vsig, 0, 0, vl_msk, dc_msk,
4440 goto err_ice_prof_tcam_ena_dis;
4442 tcam->in_use = enable;
4444 p->type = ICE_TCAM_ADD;
4445 p->add_tcam_idx = true;
4446 p->prof_id = tcam->prof_id;
4449 p->tcam_idx = tcam->tcam_idx;
4452 LIST_ADD(&p->list_entry, chg);
4456 err_ice_prof_tcam_ena_dis:
4462 * ice_adj_prof_priorities - adjust profile based on priorities
4463 * @hw: pointer to the HW struct
4464 * @blk: hardware block
4465 * @vsig: the VSIG for which to adjust profile priorities
4466 * @chg: the change list
4468 static enum ice_status
4469 ice_adj_prof_priorities(struct ice_hw *hw, enum ice_block blk, u16 vsig,
4470 struct LIST_HEAD_TYPE *chg)
4472 ice_declare_bitmap(ptgs_used, ICE_XLT1_CNT);
4473 struct ice_vsig_prof *t;
4474 enum ice_status status;
4477 ice_memset(ptgs_used, 0, sizeof(ptgs_used), ICE_NONDMA_MEM);
4478 idx = vsig & ICE_VSIG_IDX_M;
4480 /* Priority is based on the order in which the profiles are added. The
4481 * newest added profile has highest priority and the oldest added
4482 * profile has the lowest priority. Since the profile property list for
4483 * a VSIG is sorted from newest to oldest, this code traverses the list
4484 * in order and enables the first of each PTG that it finds (that is not
4485 * already enabled); it also disables any duplicate PTGs that it finds
4486 * in the older profiles (that are currently enabled).
4489 LIST_FOR_EACH_ENTRY(t, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4490 ice_vsig_prof, list) {
4493 for (i = 0; i < t->tcam_count; i++) {
4494 /* Scan the priorities from newest to oldest.
4495 * Make sure that the newest profiles take priority.
4497 if (ice_is_bit_set(ptgs_used, t->tcam[i].ptg) &&
4498 t->tcam[i].in_use) {
4499 /* need to mark this PTG as never match, as it
4500 * was already in use and therefore duplicate
4501 * (and lower priority)
4503 status = ice_prof_tcam_ena_dis(hw, blk, false,
4509 } else if (!ice_is_bit_set(ptgs_used, t->tcam[i].ptg) &&
4510 !t->tcam[i].in_use) {
4511 /* need to enable this PTG, as it in not in use
4512 * and not enabled (highest priority)
4514 status = ice_prof_tcam_ena_dis(hw, blk, true,
4522 /* keep track of used ptgs */
4523 ice_set_bit(t->tcam[i].ptg, ptgs_used);
4531 * ice_add_prof_id_vsig - add profile to VSIG
4532 * @hw: pointer to the HW struct
4533 * @blk: hardware block
4534 * @vsig: the VSIG to which this profile is to be added
4535 * @hdl: the profile handle indicating the profile to add
4536 * @chg: the change list
4538 static enum ice_status
4539 ice_add_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl,
4540 struct LIST_HEAD_TYPE *chg)
4542 /* Masks that ignore flags */
4543 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4544 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0x00, 0x00, 0x00 };
4545 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
4546 struct ice_prof_map *map;
4547 struct ice_vsig_prof *t;
4548 struct ice_chs_chg *p;
4551 /* Get the details on the profile specified by the handle ID */
4552 map = ice_search_prof_id(hw, blk, hdl);
4554 return ICE_ERR_DOES_NOT_EXIST;
4556 /* Error, if this VSIG already has this profile */
4557 if (ice_has_prof_vsig(hw, blk, vsig, hdl))
4558 return ICE_ERR_ALREADY_EXISTS;
4560 /* new VSIG profile structure */
4561 t = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*t));
4563 goto err_ice_add_prof_id_vsig;
4565 t->profile_cookie = map->profile_cookie;
4566 t->prof_id = map->prof_id;
4567 t->tcam_count = map->ptype_count;
4569 /* create TCAM entries */
4570 for (i = 0; i < map->ptype_count; i++) {
4571 enum ice_status status;
4576 /* If properly sequenced, we should never have to allocate new
4579 status = ice_get_ptg(hw, blk, map->ptype[i], &ptg, &add);
4581 goto err_ice_add_prof_id_vsig;
4583 /* add TCAM to change list */
4584 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4586 goto err_ice_add_prof_id_vsig;
4588 /* allocate the TCAM entry index */
4589 status = ice_alloc_tcam_ent(hw, blk, &tcam_idx);
4592 goto err_ice_add_prof_id_vsig;
4595 t->tcam[i].ptg = ptg;
4596 t->tcam[i].prof_id = map->prof_id;
4597 t->tcam[i].tcam_idx = tcam_idx;
4598 t->tcam[i].in_use = true;
4600 p->type = ICE_TCAM_ADD;
4601 p->add_tcam_idx = true;
4602 p->prof_id = t->tcam[i].prof_id;
4603 p->ptg = t->tcam[i].ptg;
4605 p->tcam_idx = t->tcam[i].tcam_idx;
4607 /* write the TCAM entry */
4608 status = ice_tcam_write_entry(hw, blk, t->tcam[i].tcam_idx,
4610 t->tcam[i].ptg, vsig, 0, 0,
4611 vl_msk, dc_msk, nm_msk);
4613 goto err_ice_add_prof_id_vsig;
4616 LIST_ADD(&p->list_entry, chg);
4619 /* add profile to VSIG */
4621 &hw->blk[blk].xlt2.vsig_tbl[(vsig & ICE_VSIG_IDX_M)].prop_lst);
4625 err_ice_add_prof_id_vsig:
4626 /* let caller clean up the change list */
4628 return ICE_ERR_NO_MEMORY;
4632 * ice_create_prof_id_vsig - add a new VSIG with a single profile
4633 * @hw: pointer to the HW struct
4634 * @blk: hardware block
4635 * @vsi: the initial VSI that will be in VSIG
4636 * @hdl: the profile handle of the profile that will be added to the VSIG
4637 * @chg: the change list
4639 static enum ice_status
4640 ice_create_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl,
4641 struct LIST_HEAD_TYPE *chg)
4643 enum ice_status status;
4644 struct ice_chs_chg *p;
4647 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
4649 return ICE_ERR_NO_MEMORY;
4651 new_vsig = ice_vsig_alloc(hw, blk);
4653 status = ICE_ERR_HW_TABLE;
4654 goto err_ice_create_prof_id_vsig;
4657 status = ice_move_vsi(hw, blk, vsi, new_vsig, chg);
4659 goto err_ice_create_prof_id_vsig;
4661 status = ice_add_prof_id_vsig(hw, blk, new_vsig, hdl, chg);
4663 goto err_ice_create_prof_id_vsig;
4665 p->type = ICE_VSIG_ADD;
4667 p->orig_vsig = ICE_DEFAULT_VSIG;
4670 LIST_ADD(&p->list_entry, chg);
4674 err_ice_create_prof_id_vsig:
4675 /* let caller clean up the change list */
4681 * ice_create_vsig_from_list - create a new VSIG with a list of profiles
4682 * @hw: pointer to the HW struct
4683 * @blk: hardware block
4684 * @vsi: the initial VSI that will be in VSIG
4685 * @lst: the list of profile that will be added to the VSIG
4686 * @chg: the change list
4688 static enum ice_status
4689 ice_create_vsig_from_lst(struct ice_hw *hw, enum ice_block blk, u16 vsi,
4690 struct LIST_HEAD_TYPE *lst, struct LIST_HEAD_TYPE *chg)
4692 struct ice_vsig_prof *t;
4693 enum ice_status status;
4696 vsig = ice_vsig_alloc(hw, blk);
4698 return ICE_ERR_HW_TABLE;
4700 status = ice_move_vsi(hw, blk, vsi, vsig, chg);
4704 LIST_FOR_EACH_ENTRY(t, lst, ice_vsig_prof, list) {
4705 status = ice_add_prof_id_vsig(hw, blk, vsig, t->profile_cookie,
4715 * ice_find_prof_vsig - find a VSIG with a specific profile handle
4716 * @hw: pointer to the HW struct
4717 * @blk: hardware block
4718 * @hdl: the profile handle of the profile to search for
4719 * @vsig: returns the VSIG with the matching profile
4722 ice_find_prof_vsig(struct ice_hw *hw, enum ice_block blk, u64 hdl, u16 *vsig)
4724 struct ice_vsig_prof *t;
4725 struct LIST_HEAD_TYPE lst;
4726 enum ice_status status;
4728 INIT_LIST_HEAD(&lst);
4730 t = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*t));
4734 t->profile_cookie = hdl;
4735 LIST_ADD(&t->list, &lst);
4737 status = ice_find_dup_props_vsig(hw, blk, &lst, vsig);
4742 return status == ICE_SUCCESS;
4746 * ice_add_prof_id_flow - add profile flow
4747 * @hw: pointer to the HW struct
4748 * @blk: hardware block
4749 * @vsi: the VSI to enable with the profile specified by ID
4750 * @hdl: profile handle
4752 * Calling this function will update the hardware tables to enable the
4753 * profile indicated by the ID parameter for the VSIs specified in the VSI
4754 * array. Once successfully called, the flow will be enabled.
4757 ice_add_prof_id_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl)
4759 struct ice_vsig_prof *tmp1, *del1;
4760 struct LIST_HEAD_TYPE union_lst;
4761 struct ice_chs_chg *tmp, *del;
4762 struct LIST_HEAD_TYPE chrs;
4763 struct LIST_HEAD_TYPE chg;
4764 enum ice_status status;
4765 u16 vsig, or_vsig = 0;
4767 INIT_LIST_HEAD(&union_lst);
4768 INIT_LIST_HEAD(&chrs);
4769 INIT_LIST_HEAD(&chg);
4771 status = ice_get_prof_ptgs(hw, blk, hdl, &chg);
4775 /* determine if VSI is already part of a VSIG */
4776 status = ice_vsig_find_vsi(hw, blk, vsi, &vsig);
4777 if (!status && vsig) {
4784 /* make sure that there is no overlap/conflict between the new
4785 * characteristics and the existing ones; we don't support that
4788 if (ice_has_prof_vsig(hw, blk, vsig, hdl)) {
4789 status = ICE_ERR_ALREADY_EXISTS;
4790 goto err_ice_add_prof_id_flow;
4793 /* last VSI in the VSIG? */
4794 status = ice_vsig_get_ref(hw, blk, vsig, &ref);
4796 goto err_ice_add_prof_id_flow;
4797 only_vsi = (ref == 1);
4799 /* create a union of the current profiles and the one being
4802 status = ice_get_profs_vsig(hw, blk, vsig, &union_lst);
4804 goto err_ice_add_prof_id_flow;
4806 status = ice_add_prof_to_lst(hw, blk, &union_lst, hdl);
4808 goto err_ice_add_prof_id_flow;
4810 /* search for an existing VSIG with an exact charc match */
4811 status = ice_find_dup_props_vsig(hw, blk, &union_lst, &vsig);
4813 /* move VSI to the VSIG that matches */
4814 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
4816 goto err_ice_add_prof_id_flow;
4818 /* VSI has been moved out of or_vsig. If the or_vsig had
4819 * only that VSI it is now empty and can be removed.
4822 status = ice_rem_vsig(hw, blk, or_vsig, &chg);
4824 goto err_ice_add_prof_id_flow;
4826 } else if (only_vsi) {
4827 /* If the original VSIG only contains one VSI, then it
4828 * will be the requesting VSI. In this case the VSI is
4829 * not sharing entries and we can simply add the new
4830 * profile to the VSIG.
4832 status = ice_add_prof_id_vsig(hw, blk, vsig, hdl, &chg);
4834 goto err_ice_add_prof_id_flow;
4836 /* Adjust priorities */
4837 status = ice_adj_prof_priorities(hw, blk, vsig, &chg);
4839 goto err_ice_add_prof_id_flow;
4841 /* No match, so we need a new VSIG */
4842 status = ice_create_vsig_from_lst(hw, blk, vsi,
4845 goto err_ice_add_prof_id_flow;
4847 /* Adjust priorities */
4848 status = ice_adj_prof_priorities(hw, blk, vsig, &chg);
4850 goto err_ice_add_prof_id_flow;
4853 /* need to find or add a VSIG */
4854 /* search for an existing VSIG with an exact charc match */
4855 if (ice_find_prof_vsig(hw, blk, hdl, &vsig)) {
4856 /* found an exact match */
4857 /* add or move VSI to the VSIG that matches */
4858 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
4860 goto err_ice_add_prof_id_flow;
4862 /* we did not find an exact match */
4863 /* we need to add a VSIG */
4864 status = ice_create_prof_id_vsig(hw, blk, vsi, hdl,
4867 goto err_ice_add_prof_id_flow;
4871 /* update hardware */
4873 status = ice_upd_prof_hw(hw, blk, &chg);
4875 err_ice_add_prof_id_flow:
4876 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
4877 LIST_DEL(&del->list_entry);
4881 LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, &union_lst, ice_vsig_prof, list) {
4882 LIST_DEL(&del1->list);
4886 LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, &chrs, ice_vsig_prof, list) {
4887 LIST_DEL(&del1->list);
4895 * ice_add_flow - add flow
4896 * @hw: pointer to the HW struct
4897 * @blk: hardware block
4898 * @vsi: array of VSIs to enable with the profile specified by ID
4899 * @count: number of elements in the VSI array
4900 * @id: profile tracking ID
4902 * Calling this function will update the hardware tables to enable the
4903 * profile indicated by the ID parameter for the VSIs specified in the VSI
4904 * array. Once successfully called, the flow will be enabled.
4907 ice_add_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi[], u8 count,
4910 enum ice_status status;
4913 for (i = 0; i < count; i++) {
4914 status = ice_add_prof_id_flow(hw, blk, vsi[i], id);
4923 * ice_rem_prof_from_list - remove a profile from list
4924 * @hw: pointer to the HW struct
4925 * @lst: list to remove the profile from
4926 * @hdl: the profile handle indicating the profile to remove
4928 static enum ice_status
4929 ice_rem_prof_from_list(struct ice_hw *hw, struct LIST_HEAD_TYPE *lst, u64 hdl)
4931 struct ice_vsig_prof *ent, *tmp;
4933 LIST_FOR_EACH_ENTRY_SAFE(ent, tmp, lst, ice_vsig_prof, list) {
4934 if (ent->profile_cookie == hdl) {
4935 LIST_DEL(&ent->list);
4941 return ICE_ERR_DOES_NOT_EXIST;
4945 * ice_rem_prof_id_flow - remove flow
4946 * @hw: pointer to the HW struct
4947 * @blk: hardware block
4948 * @vsi: the VSI from which to remove the profile specified by ID
4949 * @hdl: profile tracking handle
4951 * Calling this function will update the hardware tables to remove the
4952 * profile indicated by the ID parameter for the VSIs specified in the VSI
4953 * array. Once successfully called, the flow will be disabled.
4956 ice_rem_prof_id_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl)
4958 struct ice_vsig_prof *tmp1, *del1;
4959 struct LIST_HEAD_TYPE chg, copy;
4960 struct ice_chs_chg *tmp, *del;
4961 enum ice_status status;
4964 INIT_LIST_HEAD(©);
4965 INIT_LIST_HEAD(&chg);
4967 /* determine if VSI is already part of a VSIG */
4968 status = ice_vsig_find_vsi(hw, blk, vsi, &vsig);
4969 if (!status && vsig) {
4975 last_profile = ice_vsig_prof_id_count(hw, blk, vsig) == 1;
4976 status = ice_vsig_get_ref(hw, blk, vsig, &ref);
4978 goto err_ice_rem_prof_id_flow;
4979 only_vsi = (ref == 1);
4982 /* If the original VSIG only contains one reference,
4983 * which will be the requesting VSI, then the VSI is not
4984 * sharing entries and we can simply remove the specific
4985 * characteristics from the VSIG.
4989 /* If there are no profiles left for this VSIG,
4990 * then simply remove the the VSIG.
4992 status = ice_rem_vsig(hw, blk, vsig, &chg);
4994 goto err_ice_rem_prof_id_flow;
4996 status = ice_rem_prof_id_vsig(hw, blk, vsig,
4999 goto err_ice_rem_prof_id_flow;
5001 /* Adjust priorities */
5002 status = ice_adj_prof_priorities(hw, blk, vsig,
5005 goto err_ice_rem_prof_id_flow;
5009 /* Make a copy of the VSIG's list of Profiles */
5010 status = ice_get_profs_vsig(hw, blk, vsig, ©);
5012 goto err_ice_rem_prof_id_flow;
5014 /* Remove specified profile entry from the list */
5015 status = ice_rem_prof_from_list(hw, ©, hdl);
5017 goto err_ice_rem_prof_id_flow;
5019 if (LIST_EMPTY(©)) {
5020 status = ice_move_vsi(hw, blk, vsi,
5021 ICE_DEFAULT_VSIG, &chg);
5023 goto err_ice_rem_prof_id_flow;
5025 } else if (!ice_find_dup_props_vsig(hw, blk, ©,
5027 /* found an exact match */
5028 /* add or move VSI to the VSIG that matches */
5029 /* Search for a VSIG with a matching profile
5033 /* Found match, move VSI to the matching VSIG */
5034 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5036 goto err_ice_rem_prof_id_flow;
5038 /* since no existing VSIG supports this
5039 * characteristic pattern, we need to create a
5040 * new VSIG and TCAM entries
5042 status = ice_create_vsig_from_lst(hw, blk, vsi,
5045 goto err_ice_rem_prof_id_flow;
5047 /* Adjust priorities */
5048 status = ice_adj_prof_priorities(hw, blk, vsig,
5051 goto err_ice_rem_prof_id_flow;
5055 status = ICE_ERR_DOES_NOT_EXIST;
5058 /* update hardware tables */
5060 status = ice_upd_prof_hw(hw, blk, &chg);
5062 err_ice_rem_prof_id_flow:
5063 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
5064 LIST_DEL(&del->list_entry);
5068 LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, ©, ice_vsig_prof, list) {
5069 LIST_DEL(&del1->list);
5077 * ice_rem_flow - remove flow
5078 * @hw: pointer to the HW struct
5079 * @blk: hardware block
5080 * @vsi: array of VSIs from which to remove the profile specified by ID
5081 * @count: number of elements in the VSI array
5082 * @id: profile tracking ID
5084 * The function will remove flows from the specified VSIs that were enabled
5085 * using ice_add_flow. The ID value will indicated which profile will be
5086 * removed. Once successfully called, the flow will be disabled.
5089 ice_rem_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi[], u8 count,
5092 enum ice_status status;
5095 for (i = 0; i < count; i++) {
5096 status = ice_rem_prof_id_flow(hw, blk, vsi[i], id);