1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2021 Intel Corporation
5 #include "ice_common.h"
6 #include "ice_flex_pipe.h"
7 #include "ice_protocol_type.h"
10 /* To support tunneling entries by PF, the package will append the PF number to
11 * the label; for example TNL_VXLAN_PF0, TNL_VXLAN_PF1, TNL_VXLAN_PF2, etc.
13 static const struct ice_tunnel_type_scan tnls[] = {
14 { TNL_VXLAN, "TNL_VXLAN_PF" },
15 { TNL_GENEVE, "TNL_GENEVE_PF" },
16 { TNL_ECPRI, "TNL_UDP_ECPRI_PF" },
20 static const u32 ice_sect_lkup[ICE_BLK_COUNT][ICE_SECT_COUNT] = {
24 ICE_SID_XLT_KEY_BUILDER_SW,
27 ICE_SID_PROFID_TCAM_SW,
28 ICE_SID_PROFID_REDIR_SW,
30 ICE_SID_CDID_KEY_BUILDER_SW,
37 ICE_SID_XLT_KEY_BUILDER_ACL,
40 ICE_SID_PROFID_TCAM_ACL,
41 ICE_SID_PROFID_REDIR_ACL,
43 ICE_SID_CDID_KEY_BUILDER_ACL,
44 ICE_SID_CDID_REDIR_ACL
50 ICE_SID_XLT_KEY_BUILDER_FD,
53 ICE_SID_PROFID_TCAM_FD,
54 ICE_SID_PROFID_REDIR_FD,
56 ICE_SID_CDID_KEY_BUILDER_FD,
63 ICE_SID_XLT_KEY_BUILDER_RSS,
66 ICE_SID_PROFID_TCAM_RSS,
67 ICE_SID_PROFID_REDIR_RSS,
69 ICE_SID_CDID_KEY_BUILDER_RSS,
70 ICE_SID_CDID_REDIR_RSS
76 ICE_SID_XLT_KEY_BUILDER_PE,
79 ICE_SID_PROFID_TCAM_PE,
80 ICE_SID_PROFID_REDIR_PE,
82 ICE_SID_CDID_KEY_BUILDER_PE,
88 * ice_sect_id - returns section ID
92 * This helper function returns the proper section ID given a block type and a
95 static u32 ice_sect_id(enum ice_block blk, enum ice_sect sect)
97 return ice_sect_lkup[blk][sect];
102 * @buf: pointer to the ice buffer
104 * This helper function validates a buffer's header.
106 static struct ice_buf_hdr *ice_pkg_val_buf(struct ice_buf *buf)
108 struct ice_buf_hdr *hdr;
112 hdr = (struct ice_buf_hdr *)buf->buf;
114 section_count = LE16_TO_CPU(hdr->section_count);
115 if (section_count < ICE_MIN_S_COUNT || section_count > ICE_MAX_S_COUNT)
118 data_end = LE16_TO_CPU(hdr->data_end);
119 if (data_end < ICE_MIN_S_DATA_END || data_end > ICE_MAX_S_DATA_END)
127 * @ice_seg: pointer to the ice segment
129 * Returns the address of the buffer table within the ice segment.
131 static struct ice_buf_table *ice_find_buf_table(struct ice_seg *ice_seg)
133 struct ice_nvm_table *nvms;
135 nvms = (struct ice_nvm_table *)
136 (ice_seg->device_table +
137 LE32_TO_CPU(ice_seg->device_table_count));
139 return (_FORCE_ struct ice_buf_table *)
140 (nvms->vers + LE32_TO_CPU(nvms->table_count));
145 * @ice_seg: pointer to the ice segment (or NULL on subsequent calls)
146 * @state: pointer to the enum state
148 * This function will enumerate all the buffers in the ice segment. The first
149 * call is made with the ice_seg parameter non-NULL; on subsequent calls,
150 * ice_seg is set to NULL which continues the enumeration. When the function
151 * returns a NULL pointer, then the end of the buffers has been reached, or an
152 * unexpected value has been detected (for example an invalid section count or
153 * an invalid buffer end value).
155 static struct ice_buf_hdr *
156 ice_pkg_enum_buf(struct ice_seg *ice_seg, struct ice_pkg_enum *state)
159 state->buf_table = ice_find_buf_table(ice_seg);
160 if (!state->buf_table)
164 return ice_pkg_val_buf(state->buf_table->buf_array);
167 if (++state->buf_idx < LE32_TO_CPU(state->buf_table->buf_count))
168 return ice_pkg_val_buf(state->buf_table->buf_array +
175 * ice_pkg_advance_sect
176 * @ice_seg: pointer to the ice segment (or NULL on subsequent calls)
177 * @state: pointer to the enum state
179 * This helper function will advance the section within the ice segment,
180 * also advancing the buffer if needed.
183 ice_pkg_advance_sect(struct ice_seg *ice_seg, struct ice_pkg_enum *state)
185 if (!ice_seg && !state->buf)
188 if (!ice_seg && state->buf)
189 if (++state->sect_idx < LE16_TO_CPU(state->buf->section_count))
192 state->buf = ice_pkg_enum_buf(ice_seg, state);
196 /* start of new buffer, reset section index */
202 * ice_pkg_enum_section
203 * @ice_seg: pointer to the ice segment (or NULL on subsequent calls)
204 * @state: pointer to the enum state
205 * @sect_type: section type to enumerate
207 * This function will enumerate all the sections of a particular type in the
208 * ice segment. The first call is made with the ice_seg parameter non-NULL;
209 * on subsequent calls, ice_seg is set to NULL which continues the enumeration.
210 * When the function returns a NULL pointer, then the end of the matching
211 * sections has been reached.
214 ice_pkg_enum_section(struct ice_seg *ice_seg, struct ice_pkg_enum *state,
220 state->type = sect_type;
222 if (!ice_pkg_advance_sect(ice_seg, state))
225 /* scan for next matching section */
226 while (state->buf->section_entry[state->sect_idx].type !=
227 CPU_TO_LE32(state->type))
228 if (!ice_pkg_advance_sect(NULL, state))
231 /* validate section */
232 offset = LE16_TO_CPU(state->buf->section_entry[state->sect_idx].offset);
233 if (offset < ICE_MIN_S_OFF || offset > ICE_MAX_S_OFF)
236 size = LE16_TO_CPU(state->buf->section_entry[state->sect_idx].size);
237 if (size < ICE_MIN_S_SZ || size > ICE_MAX_S_SZ)
240 /* make sure the section fits in the buffer */
241 if (offset + size > ICE_PKG_BUF_SIZE)
245 LE32_TO_CPU(state->buf->section_entry[state->sect_idx].type);
247 /* calc pointer to this section */
248 state->sect = ((u8 *)state->buf) +
249 LE16_TO_CPU(state->buf->section_entry[state->sect_idx].offset);
256 * @ice_seg: pointer to the ice segment (or NULL on subsequent calls)
257 * @state: pointer to the enum state
258 * @sect_type: section type to enumerate
259 * @offset: pointer to variable that receives the offset in the table (optional)
260 * @handler: function that handles access to the entries into the section type
262 * This function will enumerate all the entries in particular section type in
263 * the ice segment. The first call is made with the ice_seg parameter non-NULL;
264 * on subsequent calls, ice_seg is set to NULL which continues the enumeration.
265 * When the function returns a NULL pointer, then the end of the entries has
268 * Since each section may have a different header and entry size, the handler
269 * function is needed to determine the number and location entries in each
272 * The offset parameter is optional, but should be used for sections that
273 * contain an offset for each section table. For such cases, the section handler
274 * function must return the appropriate offset + index to give the absolution
275 * offset for each entry. For example, if the base for a section's header
276 * indicates a base offset of 10, and the index for the entry is 2, then
277 * section handler function should set the offset to 10 + 2 = 12.
280 ice_pkg_enum_entry(struct ice_seg *ice_seg, struct ice_pkg_enum *state,
281 u32 sect_type, u32 *offset,
282 void *(*handler)(u32 sect_type, void *section,
283 u32 index, u32 *offset))
291 if (!ice_pkg_enum_section(ice_seg, state, sect_type))
294 state->entry_idx = 0;
295 state->handler = handler;
304 entry = state->handler(state->sect_type, state->sect, state->entry_idx,
307 /* end of a section, look for another section of this type */
308 if (!ice_pkg_enum_section(NULL, state, 0))
311 state->entry_idx = 0;
312 entry = state->handler(state->sect_type, state->sect,
313 state->entry_idx, offset);
320 * ice_hw_ptype_ena - check if the PTYPE is enabled or not
321 * @hw: pointer to the HW structure
322 * @ptype: the hardware PTYPE
324 bool ice_hw_ptype_ena(struct ice_hw *hw, u16 ptype)
326 return ptype < ICE_FLOW_PTYPE_MAX &&
327 ice_is_bit_set(hw->hw_ptype, ptype);
331 * ice_marker_ptype_tcam_handler
332 * @sect_type: section type
333 * @section: pointer to section
334 * @index: index of the Marker PType TCAM entry to be returned
335 * @offset: pointer to receive absolute offset, always 0 for ptype TCAM sections
337 * This is a callback function that can be passed to ice_pkg_enum_entry.
338 * Handles enumeration of individual Marker PType TCAM entries.
341 ice_marker_ptype_tcam_handler(u32 sect_type, void *section, u32 index,
344 struct ice_marker_ptype_tcam_section *marker_ptype;
349 if (sect_type != ICE_SID_RXPARSER_MARKER_PTYPE)
352 /* cppcheck-suppress nullPointer */
353 if (index > ICE_MAX_MARKER_PTYPE_TCAMS_IN_BUF)
359 marker_ptype = (struct ice_marker_ptype_tcam_section *)section;
360 if (index >= LE16_TO_CPU(marker_ptype->count))
363 return marker_ptype->tcam + index;
367 * ice_fill_hw_ptype - fill the enabled PTYPE bit information
368 * @hw: pointer to the HW structure
371 ice_fill_hw_ptype(struct ice_hw *hw)
373 struct ice_marker_ptype_tcam_entry *tcam;
374 struct ice_seg *seg = hw->seg;
375 struct ice_pkg_enum state;
377 ice_zero_bitmap(hw->hw_ptype, ICE_FLOW_PTYPE_MAX);
381 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
384 tcam = (struct ice_marker_ptype_tcam_entry *)
385 ice_pkg_enum_entry(seg, &state,
386 ICE_SID_RXPARSER_MARKER_PTYPE, NULL,
387 ice_marker_ptype_tcam_handler);
389 LE16_TO_CPU(tcam->addr) < ICE_MARKER_PTYPE_TCAM_ADDR_MAX &&
390 LE16_TO_CPU(tcam->ptype) < ICE_FLOW_PTYPE_MAX)
391 ice_set_bit(LE16_TO_CPU(tcam->ptype), hw->hw_ptype);
398 * ice_boost_tcam_handler
399 * @sect_type: section type
400 * @section: pointer to section
401 * @index: index of the boost TCAM entry to be returned
402 * @offset: pointer to receive absolute offset, always 0 for boost TCAM sections
404 * This is a callback function that can be passed to ice_pkg_enum_entry.
405 * Handles enumeration of individual boost TCAM entries.
408 ice_boost_tcam_handler(u32 sect_type, void *section, u32 index, u32 *offset)
410 struct ice_boost_tcam_section *boost;
415 if (sect_type != ICE_SID_RXPARSER_BOOST_TCAM)
418 if (index > ICE_MAX_BST_TCAMS_IN_BUF)
424 boost = (struct ice_boost_tcam_section *)section;
425 if (index >= LE16_TO_CPU(boost->count))
428 return boost->tcam + index;
432 * ice_find_boost_entry
433 * @ice_seg: pointer to the ice segment (non-NULL)
434 * @addr: Boost TCAM address of entry to search for
435 * @entry: returns pointer to the entry
437 * Finds a particular Boost TCAM entry and returns a pointer to that entry
438 * if it is found. The ice_seg parameter must not be NULL since the first call
439 * to ice_pkg_enum_entry requires a pointer to an actual ice_segment structure.
441 static enum ice_status
442 ice_find_boost_entry(struct ice_seg *ice_seg, u16 addr,
443 struct ice_boost_tcam_entry **entry)
445 struct ice_boost_tcam_entry *tcam;
446 struct ice_pkg_enum state;
448 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
451 return ICE_ERR_PARAM;
454 tcam = (struct ice_boost_tcam_entry *)
455 ice_pkg_enum_entry(ice_seg, &state,
456 ICE_SID_RXPARSER_BOOST_TCAM, NULL,
457 ice_boost_tcam_handler);
458 if (tcam && LE16_TO_CPU(tcam->addr) == addr) {
471 * ice_label_enum_handler
472 * @sect_type: section type
473 * @section: pointer to section
474 * @index: index of the label entry to be returned
475 * @offset: pointer to receive absolute offset, always zero for label sections
477 * This is a callback function that can be passed to ice_pkg_enum_entry.
478 * Handles enumeration of individual label entries.
481 ice_label_enum_handler(u32 __ALWAYS_UNUSED sect_type, void *section, u32 index,
484 struct ice_label_section *labels;
489 if (index > ICE_MAX_LABELS_IN_BUF)
495 labels = (struct ice_label_section *)section;
496 if (index >= LE16_TO_CPU(labels->count))
499 return labels->label + index;
504 * @ice_seg: pointer to the ice segment (NULL on subsequent calls)
505 * @type: the section type that will contain the label (0 on subsequent calls)
506 * @state: ice_pkg_enum structure that will hold the state of the enumeration
507 * @value: pointer to a value that will return the label's value if found
509 * Enumerates a list of labels in the package. The caller will call
510 * ice_enum_labels(ice_seg, type, ...) to start the enumeration, then call
511 * ice_enum_labels(NULL, 0, ...) to continue. When the function returns a NULL
512 * the end of the list has been reached.
515 ice_enum_labels(struct ice_seg *ice_seg, u32 type, struct ice_pkg_enum *state,
518 struct ice_label *label;
520 /* Check for valid label section on first call */
521 if (type && !(type >= ICE_SID_LBL_FIRST && type <= ICE_SID_LBL_LAST))
524 label = (struct ice_label *)ice_pkg_enum_entry(ice_seg, state, type,
526 ice_label_enum_handler);
530 *value = LE16_TO_CPU(label->value);
536 * @hw: pointer to the HW structure
537 * @ice_seg: pointer to the segment of the package scan (non-NULL)
539 * This function will scan the package and save off relevant information
540 * (hints or metadata) for driver use. The ice_seg parameter must not be NULL
541 * since the first call to ice_enum_labels requires a pointer to an actual
544 static void ice_init_pkg_hints(struct ice_hw *hw, struct ice_seg *ice_seg)
546 struct ice_pkg_enum state;
551 ice_memset(&hw->tnl, 0, sizeof(hw->tnl), ICE_NONDMA_MEM);
552 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
557 label_name = ice_enum_labels(ice_seg, ICE_SID_LBL_RXPARSER_TMEM, &state,
560 while (label_name && hw->tnl.count < ICE_TUNNEL_MAX_ENTRIES) {
561 for (i = 0; tnls[i].type != TNL_LAST; i++) {
562 size_t len = strlen(tnls[i].label_prefix);
564 /* Look for matching label start, before continuing */
565 if (strncmp(label_name, tnls[i].label_prefix, len))
568 /* Make sure this label matches our PF. Note that the PF
569 * character ('0' - '7') will be located where our
570 * prefix string's null terminator is located.
572 if ((label_name[len] - '0') == hw->pf_id) {
573 hw->tnl.tbl[hw->tnl.count].type = tnls[i].type;
574 hw->tnl.tbl[hw->tnl.count].valid = false;
575 hw->tnl.tbl[hw->tnl.count].in_use = false;
576 hw->tnl.tbl[hw->tnl.count].marked = false;
577 hw->tnl.tbl[hw->tnl.count].boost_addr = val;
578 hw->tnl.tbl[hw->tnl.count].port = 0;
584 label_name = ice_enum_labels(NULL, 0, &state, &val);
587 /* Cache the appropriate boost TCAM entry pointers */
588 for (i = 0; i < hw->tnl.count; i++) {
589 ice_find_boost_entry(ice_seg, hw->tnl.tbl[i].boost_addr,
590 &hw->tnl.tbl[i].boost_entry);
591 if (hw->tnl.tbl[i].boost_entry)
592 hw->tnl.tbl[i].valid = true;
598 #define ICE_DC_KEY 0x1 /* don't care */
599 #define ICE_DC_KEYINV 0x1
600 #define ICE_NM_KEY 0x0 /* never match */
601 #define ICE_NM_KEYINV 0x0
602 #define ICE_0_KEY 0x1 /* match 0 */
603 #define ICE_0_KEYINV 0x0
604 #define ICE_1_KEY 0x0 /* match 1 */
605 #define ICE_1_KEYINV 0x1
608 * ice_gen_key_word - generate 16-bits of a key/mask word
610 * @valid: valid bits mask (change only the valid bits)
611 * @dont_care: don't care mask
612 * @nvr_mtch: never match mask
613 * @key: pointer to an array of where the resulting key portion
614 * @key_inv: pointer to an array of where the resulting key invert portion
616 * This function generates 16-bits from a 8-bit value, an 8-bit don't care mask
617 * and an 8-bit never match mask. The 16-bits of output are divided into 8 bits
618 * of key and 8 bits of key invert.
620 * '0' = b01, always match a 0 bit
621 * '1' = b10, always match a 1 bit
622 * '?' = b11, don't care bit (always matches)
623 * '~' = b00, never match bit
627 * dont_care: b0 0 1 1 0 0
628 * never_mtch: b0 0 0 0 1 1
629 * ------------------------------
630 * Result: key: b01 10 11 11 00 00
632 static enum ice_status
633 ice_gen_key_word(u8 val, u8 valid, u8 dont_care, u8 nvr_mtch, u8 *key,
636 u8 in_key = *key, in_key_inv = *key_inv;
639 /* 'dont_care' and 'nvr_mtch' masks cannot overlap */
640 if ((dont_care ^ nvr_mtch) != (dont_care | nvr_mtch))
646 /* encode the 8 bits into 8-bit key and 8-bit key invert */
647 for (i = 0; i < 8; i++) {
651 if (!(valid & 0x1)) { /* change only valid bits */
652 *key |= (in_key & 0x1) << 7;
653 *key_inv |= (in_key_inv & 0x1) << 7;
654 } else if (dont_care & 0x1) { /* don't care bit */
655 *key |= ICE_DC_KEY << 7;
656 *key_inv |= ICE_DC_KEYINV << 7;
657 } else if (nvr_mtch & 0x1) { /* never match bit */
658 *key |= ICE_NM_KEY << 7;
659 *key_inv |= ICE_NM_KEYINV << 7;
660 } else if (val & 0x01) { /* exact 1 match */
661 *key |= ICE_1_KEY << 7;
662 *key_inv |= ICE_1_KEYINV << 7;
663 } else { /* exact 0 match */
664 *key |= ICE_0_KEY << 7;
665 *key_inv |= ICE_0_KEYINV << 7;
680 * ice_bits_max_set - determine if the number of bits set is within a maximum
681 * @mask: pointer to the byte array which is the mask
682 * @size: the number of bytes in the mask
683 * @max: the max number of set bits
685 * This function determines if there are at most 'max' number of bits set in an
686 * array. Returns true if the number for bits set is <= max or will return false
689 static bool ice_bits_max_set(const u8 *mask, u16 size, u16 max)
694 /* check each byte */
695 for (i = 0; i < size; i++) {
696 /* if 0, go to next byte */
700 /* We know there is at least one set bit in this byte because of
701 * the above check; if we already have found 'max' number of
702 * bits set, then we can return failure now.
707 /* count the bits in this byte, checking threshold */
708 count += ice_hweight8(mask[i]);
717 * ice_set_key - generate a variable sized key with multiples of 16-bits
718 * @key: pointer to where the key will be stored
719 * @size: the size of the complete key in bytes (must be even)
720 * @val: array of 8-bit values that makes up the value portion of the key
721 * @upd: array of 8-bit masks that determine what key portion to update
722 * @dc: array of 8-bit masks that make up the don't care mask
723 * @nm: array of 8-bit masks that make up the never match mask
724 * @off: the offset of the first byte in the key to update
725 * @len: the number of bytes in the key update
727 * This function generates a key from a value, a don't care mask and a never
729 * upd, dc, and nm are optional parameters, and can be NULL:
730 * upd == NULL --> upd mask is all 1's (update all bits)
731 * dc == NULL --> dc mask is all 0's (no don't care bits)
732 * nm == NULL --> nm mask is all 0's (no never match bits)
735 ice_set_key(u8 *key, u16 size, u8 *val, u8 *upd, u8 *dc, u8 *nm, u16 off,
741 /* size must be a multiple of 2 bytes. */
744 half_size = size / 2;
746 if (off + len > half_size)
749 /* Make sure at most one bit is set in the never match mask. Having more
750 * than one never match mask bit set will cause HW to consume excessive
751 * power otherwise; this is a power management efficiency check.
753 #define ICE_NVR_MTCH_BITS_MAX 1
754 if (nm && !ice_bits_max_set(nm, len, ICE_NVR_MTCH_BITS_MAX))
757 for (i = 0; i < len; i++)
758 if (ice_gen_key_word(val[i], upd ? upd[i] : 0xff,
759 dc ? dc[i] : 0, nm ? nm[i] : 0,
760 key + off + i, key + half_size + off + i))
767 * ice_acquire_global_cfg_lock
768 * @hw: pointer to the HW structure
769 * @access: access type (read or write)
771 * This function will request ownership of the global config lock for reading
772 * or writing of the package. When attempting to obtain write access, the
773 * caller must check for the following two return values:
775 * ICE_SUCCESS - Means the caller has acquired the global config lock
776 * and can perform writing of the package.
777 * ICE_ERR_AQ_NO_WORK - Indicates another driver has already written the
778 * package or has found that no update was necessary; in
779 * this case, the caller can just skip performing any
780 * update of the package.
782 static enum ice_status
783 ice_acquire_global_cfg_lock(struct ice_hw *hw,
784 enum ice_aq_res_access_type access)
786 enum ice_status status;
788 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
790 status = ice_acquire_res(hw, ICE_GLOBAL_CFG_LOCK_RES_ID, access,
791 ICE_GLOBAL_CFG_LOCK_TIMEOUT);
793 if (status == ICE_ERR_AQ_NO_WORK)
794 ice_debug(hw, ICE_DBG_PKG, "Global config lock: No work to do\n");
800 * ice_release_global_cfg_lock
801 * @hw: pointer to the HW structure
803 * This function will release the global config lock.
805 static void ice_release_global_cfg_lock(struct ice_hw *hw)
807 ice_release_res(hw, ICE_GLOBAL_CFG_LOCK_RES_ID);
811 * ice_acquire_change_lock
812 * @hw: pointer to the HW structure
813 * @access: access type (read or write)
815 * This function will request ownership of the change lock.
818 ice_acquire_change_lock(struct ice_hw *hw, enum ice_aq_res_access_type access)
820 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
822 return ice_acquire_res(hw, ICE_CHANGE_LOCK_RES_ID, access,
823 ICE_CHANGE_LOCK_TIMEOUT);
827 * ice_release_change_lock
828 * @hw: pointer to the HW structure
830 * This function will release the change lock using the proper Admin Command.
832 void ice_release_change_lock(struct ice_hw *hw)
834 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
836 ice_release_res(hw, ICE_CHANGE_LOCK_RES_ID);
840 * ice_aq_download_pkg
841 * @hw: pointer to the hardware structure
842 * @pkg_buf: the package buffer to transfer
843 * @buf_size: the size of the package buffer
844 * @last_buf: last buffer indicator
845 * @error_offset: returns error offset
846 * @error_info: returns error information
847 * @cd: pointer to command details structure or NULL
849 * Download Package (0x0C40)
851 static enum ice_status
852 ice_aq_download_pkg(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf,
853 u16 buf_size, bool last_buf, u32 *error_offset,
854 u32 *error_info, struct ice_sq_cd *cd)
856 struct ice_aqc_download_pkg *cmd;
857 struct ice_aq_desc desc;
858 enum ice_status status;
860 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
867 cmd = &desc.params.download_pkg;
868 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_download_pkg);
869 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
872 cmd->flags |= ICE_AQC_DOWNLOAD_PKG_LAST_BUF;
874 status = ice_aq_send_cmd(hw, &desc, pkg_buf, buf_size, cd);
875 if (status == ICE_ERR_AQ_ERROR) {
876 /* Read error from buffer only when the FW returned an error */
877 struct ice_aqc_download_pkg_resp *resp;
879 resp = (struct ice_aqc_download_pkg_resp *)pkg_buf;
881 *error_offset = LE32_TO_CPU(resp->error_offset);
883 *error_info = LE32_TO_CPU(resp->error_info);
890 * ice_aq_upload_section
891 * @hw: pointer to the hardware structure
892 * @pkg_buf: the package buffer which will receive the section
893 * @buf_size: the size of the package buffer
894 * @cd: pointer to command details structure or NULL
896 * Upload Section (0x0C41)
899 ice_aq_upload_section(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf,
900 u16 buf_size, struct ice_sq_cd *cd)
902 struct ice_aq_desc desc;
904 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
905 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_upload_section);
906 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
908 return ice_aq_send_cmd(hw, &desc, pkg_buf, buf_size, cd);
913 * @hw: pointer to the hardware structure
914 * @pkg_buf: the package cmd buffer
915 * @buf_size: the size of the package cmd buffer
916 * @last_buf: last buffer indicator
917 * @error_offset: returns error offset
918 * @error_info: returns error information
919 * @cd: pointer to command details structure or NULL
921 * Update Package (0x0C42)
923 static enum ice_status
924 ice_aq_update_pkg(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf, u16 buf_size,
925 bool last_buf, u32 *error_offset, u32 *error_info,
926 struct ice_sq_cd *cd)
928 struct ice_aqc_download_pkg *cmd;
929 struct ice_aq_desc desc;
930 enum ice_status status;
932 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
939 cmd = &desc.params.download_pkg;
940 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_update_pkg);
941 desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD);
944 cmd->flags |= ICE_AQC_DOWNLOAD_PKG_LAST_BUF;
946 status = ice_aq_send_cmd(hw, &desc, pkg_buf, buf_size, cd);
947 if (status == ICE_ERR_AQ_ERROR) {
948 /* Read error from buffer only when the FW returned an error */
949 struct ice_aqc_download_pkg_resp *resp;
951 resp = (struct ice_aqc_download_pkg_resp *)pkg_buf;
953 *error_offset = LE32_TO_CPU(resp->error_offset);
955 *error_info = LE32_TO_CPU(resp->error_info);
962 * ice_find_seg_in_pkg
963 * @hw: pointer to the hardware structure
964 * @seg_type: the segment type to search for (i.e., SEGMENT_TYPE_CPK)
965 * @pkg_hdr: pointer to the package header to be searched
967 * This function searches a package file for a particular segment type. On
968 * success it returns a pointer to the segment header, otherwise it will
971 static struct ice_generic_seg_hdr *
972 ice_find_seg_in_pkg(struct ice_hw *hw, u32 seg_type,
973 struct ice_pkg_hdr *pkg_hdr)
977 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
978 ice_debug(hw, ICE_DBG_PKG, "Package format version: %d.%d.%d.%d\n",
979 pkg_hdr->pkg_format_ver.major, pkg_hdr->pkg_format_ver.minor,
980 pkg_hdr->pkg_format_ver.update,
981 pkg_hdr->pkg_format_ver.draft);
983 /* Search all package segments for the requested segment type */
984 for (i = 0; i < LE32_TO_CPU(pkg_hdr->seg_count); i++) {
985 struct ice_generic_seg_hdr *seg;
987 seg = (struct ice_generic_seg_hdr *)
988 ((u8 *)pkg_hdr + LE32_TO_CPU(pkg_hdr->seg_offset[i]));
990 if (LE32_TO_CPU(seg->seg_type) == seg_type)
999 * @hw: pointer to the hardware structure
1000 * @bufs: pointer to an array of buffers
1001 * @count: the number of buffers in the array
1003 * Obtains change lock and updates package.
1006 ice_update_pkg(struct ice_hw *hw, struct ice_buf *bufs, u32 count)
1008 enum ice_status status;
1009 u32 offset, info, i;
1011 status = ice_acquire_change_lock(hw, ICE_RES_WRITE);
1015 for (i = 0; i < count; i++) {
1016 struct ice_buf_hdr *bh = (struct ice_buf_hdr *)(bufs + i);
1017 bool last = ((i + 1) == count);
1019 status = ice_aq_update_pkg(hw, bh, LE16_TO_CPU(bh->data_end),
1020 last, &offset, &info, NULL);
1023 ice_debug(hw, ICE_DBG_PKG, "Update pkg failed: err %d off %d inf %d\n",
1024 status, offset, info);
1029 ice_release_change_lock(hw);
1035 * ice_dwnld_cfg_bufs
1036 * @hw: pointer to the hardware structure
1037 * @bufs: pointer to an array of buffers
1038 * @count: the number of buffers in the array
1040 * Obtains global config lock and downloads the package configuration buffers
1041 * to the firmware. Metadata buffers are skipped, and the first metadata buffer
1042 * found indicates that the rest of the buffers are all metadata buffers.
1044 static enum ice_status
1045 ice_dwnld_cfg_bufs(struct ice_hw *hw, struct ice_buf *bufs, u32 count)
1047 enum ice_status status;
1048 struct ice_buf_hdr *bh;
1049 u32 offset, info, i;
1051 if (!bufs || !count)
1052 return ICE_ERR_PARAM;
1054 /* If the first buffer's first section has its metadata bit set
1055 * then there are no buffers to be downloaded, and the operation is
1056 * considered a success.
1058 bh = (struct ice_buf_hdr *)bufs;
1059 if (LE32_TO_CPU(bh->section_entry[0].type) & ICE_METADATA_BUF)
1062 /* reset pkg_dwnld_status in case this function is called in the
1063 * reset/rebuild flow
1065 hw->pkg_dwnld_status = ICE_AQ_RC_OK;
1067 status = ice_acquire_global_cfg_lock(hw, ICE_RES_WRITE);
1069 if (status == ICE_ERR_AQ_NO_WORK)
1070 hw->pkg_dwnld_status = ICE_AQ_RC_EEXIST;
1072 hw->pkg_dwnld_status = hw->adminq.sq_last_status;
1076 for (i = 0; i < count; i++) {
1077 bool last = ((i + 1) == count);
1080 /* check next buffer for metadata flag */
1081 bh = (struct ice_buf_hdr *)(bufs + i + 1);
1083 /* A set metadata flag in the next buffer will signal
1084 * that the current buffer will be the last buffer
1087 if (LE16_TO_CPU(bh->section_count))
1088 if (LE32_TO_CPU(bh->section_entry[0].type) &
1093 bh = (struct ice_buf_hdr *)(bufs + i);
1095 status = ice_aq_download_pkg(hw, bh, ICE_PKG_BUF_SIZE, last,
1096 &offset, &info, NULL);
1098 /* Save AQ status from download package */
1099 hw->pkg_dwnld_status = hw->adminq.sq_last_status;
1101 ice_debug(hw, ICE_DBG_PKG, "Pkg download failed: err %d off %d inf %d\n",
1102 status, offset, info);
1111 status = ice_set_vlan_mode(hw);
1113 ice_debug(hw, ICE_DBG_PKG, "Failed to set VLAN mode: err %d\n",
1117 ice_release_global_cfg_lock(hw);
1123 * ice_aq_get_pkg_info_list
1124 * @hw: pointer to the hardware structure
1125 * @pkg_info: the buffer which will receive the information list
1126 * @buf_size: the size of the pkg_info information buffer
1127 * @cd: pointer to command details structure or NULL
1129 * Get Package Info List (0x0C43)
1131 static enum ice_status
1132 ice_aq_get_pkg_info_list(struct ice_hw *hw,
1133 struct ice_aqc_get_pkg_info_resp *pkg_info,
1134 u16 buf_size, struct ice_sq_cd *cd)
1136 struct ice_aq_desc desc;
1138 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1139 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_pkg_info_list);
1141 return ice_aq_send_cmd(hw, &desc, pkg_info, buf_size, cd);
1146 * @hw: pointer to the hardware structure
1147 * @ice_seg: pointer to the segment of the package to be downloaded
1149 * Handles the download of a complete package.
1151 static enum ice_status
1152 ice_download_pkg(struct ice_hw *hw, struct ice_seg *ice_seg)
1154 struct ice_buf_table *ice_buf_tbl;
1156 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1157 ice_debug(hw, ICE_DBG_PKG, "Segment format version: %d.%d.%d.%d\n",
1158 ice_seg->hdr.seg_format_ver.major,
1159 ice_seg->hdr.seg_format_ver.minor,
1160 ice_seg->hdr.seg_format_ver.update,
1161 ice_seg->hdr.seg_format_ver.draft);
1163 ice_debug(hw, ICE_DBG_PKG, "Seg: type 0x%X, size %d, name %s\n",
1164 LE32_TO_CPU(ice_seg->hdr.seg_type),
1165 LE32_TO_CPU(ice_seg->hdr.seg_size), ice_seg->hdr.seg_id);
1167 ice_buf_tbl = ice_find_buf_table(ice_seg);
1169 ice_debug(hw, ICE_DBG_PKG, "Seg buf count: %d\n",
1170 LE32_TO_CPU(ice_buf_tbl->buf_count));
1172 return ice_dwnld_cfg_bufs(hw, ice_buf_tbl->buf_array,
1173 LE32_TO_CPU(ice_buf_tbl->buf_count));
1178 * @hw: pointer to the hardware structure
1179 * @pkg_hdr: pointer to the driver's package hdr
1181 * Saves off the package details into the HW structure.
1183 static enum ice_status
1184 ice_init_pkg_info(struct ice_hw *hw, struct ice_pkg_hdr *pkg_hdr)
1186 struct ice_generic_seg_hdr *seg_hdr;
1188 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1190 return ICE_ERR_PARAM;
1192 seg_hdr = (struct ice_generic_seg_hdr *)
1193 ice_find_seg_in_pkg(hw, SEGMENT_TYPE_ICE, pkg_hdr);
1195 struct ice_meta_sect *meta;
1196 struct ice_pkg_enum state;
1198 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1200 /* Get package information from the Metadata Section */
1201 meta = (struct ice_meta_sect *)
1202 ice_pkg_enum_section((struct ice_seg *)seg_hdr, &state,
1205 ice_debug(hw, ICE_DBG_INIT, "Did not find ice metadata section in package\n");
1209 hw->pkg_ver = meta->ver;
1210 ice_memcpy(hw->pkg_name, meta->name, sizeof(meta->name),
1211 ICE_NONDMA_TO_NONDMA);
1213 ice_debug(hw, ICE_DBG_PKG, "Pkg: %d.%d.%d.%d, %s\n",
1214 meta->ver.major, meta->ver.minor, meta->ver.update,
1215 meta->ver.draft, meta->name);
1217 hw->ice_seg_fmt_ver = seg_hdr->seg_format_ver;
1218 ice_memcpy(hw->ice_seg_id, seg_hdr->seg_id,
1219 sizeof(hw->ice_seg_id), ICE_NONDMA_TO_NONDMA);
1221 ice_debug(hw, ICE_DBG_PKG, "Ice Seg: %d.%d.%d.%d, %s\n",
1222 seg_hdr->seg_format_ver.major,
1223 seg_hdr->seg_format_ver.minor,
1224 seg_hdr->seg_format_ver.update,
1225 seg_hdr->seg_format_ver.draft,
1228 ice_debug(hw, ICE_DBG_INIT, "Did not find ice segment in driver package\n");
1237 * @hw: pointer to the hardware structure
1239 * Store details of the package currently loaded in HW into the HW structure.
1241 static enum ice_status ice_get_pkg_info(struct ice_hw *hw)
1243 struct ice_aqc_get_pkg_info_resp *pkg_info;
1244 enum ice_status status;
1248 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1250 size = ice_struct_size(pkg_info, pkg_info, ICE_PKG_CNT);
1251 pkg_info = (struct ice_aqc_get_pkg_info_resp *)ice_malloc(hw, size);
1253 return ICE_ERR_NO_MEMORY;
1255 status = ice_aq_get_pkg_info_list(hw, pkg_info, size, NULL);
1257 goto init_pkg_free_alloc;
1259 for (i = 0; i < LE32_TO_CPU(pkg_info->count); i++) {
1260 #define ICE_PKG_FLAG_COUNT 4
1261 char flags[ICE_PKG_FLAG_COUNT + 1] = { 0 };
1264 if (pkg_info->pkg_info[i].is_active) {
1265 flags[place++] = 'A';
1266 hw->active_pkg_ver = pkg_info->pkg_info[i].ver;
1267 hw->active_track_id =
1268 LE32_TO_CPU(pkg_info->pkg_info[i].track_id);
1269 ice_memcpy(hw->active_pkg_name,
1270 pkg_info->pkg_info[i].name,
1271 sizeof(pkg_info->pkg_info[i].name),
1272 ICE_NONDMA_TO_NONDMA);
1273 hw->active_pkg_in_nvm = pkg_info->pkg_info[i].is_in_nvm;
1275 if (pkg_info->pkg_info[i].is_active_at_boot)
1276 flags[place++] = 'B';
1277 if (pkg_info->pkg_info[i].is_modified)
1278 flags[place++] = 'M';
1279 if (pkg_info->pkg_info[i].is_in_nvm)
1280 flags[place++] = 'N';
1282 ice_debug(hw, ICE_DBG_PKG, "Pkg[%d]: %d.%d.%d.%d,%s,%s\n",
1283 i, pkg_info->pkg_info[i].ver.major,
1284 pkg_info->pkg_info[i].ver.minor,
1285 pkg_info->pkg_info[i].ver.update,
1286 pkg_info->pkg_info[i].ver.draft,
1287 pkg_info->pkg_info[i].name, flags);
1290 init_pkg_free_alloc:
1291 ice_free(hw, pkg_info);
1297 * ice_verify_pkg - verify package
1298 * @pkg: pointer to the package buffer
1299 * @len: size of the package buffer
1301 * Verifies various attributes of the package file, including length, format
1302 * version, and the requirement of at least one segment.
1304 static enum ice_status ice_verify_pkg(struct ice_pkg_hdr *pkg, u32 len)
1309 if (len < ice_struct_size(pkg, seg_offset, 1))
1310 return ICE_ERR_BUF_TOO_SHORT;
1312 if (pkg->pkg_format_ver.major != ICE_PKG_FMT_VER_MAJ ||
1313 pkg->pkg_format_ver.minor != ICE_PKG_FMT_VER_MNR ||
1314 pkg->pkg_format_ver.update != ICE_PKG_FMT_VER_UPD ||
1315 pkg->pkg_format_ver.draft != ICE_PKG_FMT_VER_DFT)
1318 /* pkg must have at least one segment */
1319 seg_count = LE32_TO_CPU(pkg->seg_count);
1323 /* make sure segment array fits in package length */
1324 if (len < ice_struct_size(pkg, seg_offset, seg_count))
1325 return ICE_ERR_BUF_TOO_SHORT;
1327 /* all segments must fit within length */
1328 for (i = 0; i < seg_count; i++) {
1329 u32 off = LE32_TO_CPU(pkg->seg_offset[i]);
1330 struct ice_generic_seg_hdr *seg;
1332 /* segment header must fit */
1333 if (len < off + sizeof(*seg))
1334 return ICE_ERR_BUF_TOO_SHORT;
1336 seg = (struct ice_generic_seg_hdr *)((u8 *)pkg + off);
1338 /* segment body must fit */
1339 if (len < off + LE32_TO_CPU(seg->seg_size))
1340 return ICE_ERR_BUF_TOO_SHORT;
1347 * ice_free_seg - free package segment pointer
1348 * @hw: pointer to the hardware structure
1350 * Frees the package segment pointer in the proper manner, depending on if the
1351 * segment was allocated or just the passed in pointer was stored.
1353 void ice_free_seg(struct ice_hw *hw)
1356 ice_free(hw, hw->pkg_copy);
1357 hw->pkg_copy = NULL;
1364 * ice_init_pkg_regs - initialize additional package registers
1365 * @hw: pointer to the hardware structure
1367 static void ice_init_pkg_regs(struct ice_hw *hw)
1369 #define ICE_SW_BLK_INP_MASK_L 0xFFFFFFFF
1370 #define ICE_SW_BLK_INP_MASK_H 0x0000FFFF
1371 #define ICE_SW_BLK_IDX 0
1372 if (hw->dcf_enabled)
1375 /* setup Switch block input mask, which is 48-bits in two parts */
1376 wr32(hw, GL_PREEXT_L2_PMASK0(ICE_SW_BLK_IDX), ICE_SW_BLK_INP_MASK_L);
1377 wr32(hw, GL_PREEXT_L2_PMASK1(ICE_SW_BLK_IDX), ICE_SW_BLK_INP_MASK_H);
1381 * ice_chk_pkg_version - check package version for compatibility with driver
1382 * @pkg_ver: pointer to a version structure to check
1384 * Check to make sure that the package about to be downloaded is compatible with
1385 * the driver. To be compatible, the major and minor components of the package
1386 * version must match our ICE_PKG_SUPP_VER_MAJ and ICE_PKG_SUPP_VER_MNR
1389 static enum ice_status ice_chk_pkg_version(struct ice_pkg_ver *pkg_ver)
1391 if (pkg_ver->major != ICE_PKG_SUPP_VER_MAJ ||
1392 pkg_ver->minor != ICE_PKG_SUPP_VER_MNR)
1393 return ICE_ERR_NOT_SUPPORTED;
1399 * ice_chk_pkg_compat
1400 * @hw: pointer to the hardware structure
1401 * @ospkg: pointer to the package hdr
1402 * @seg: pointer to the package segment hdr
1404 * This function checks the package version compatibility with driver and NVM
1406 static enum ice_status
1407 ice_chk_pkg_compat(struct ice_hw *hw, struct ice_pkg_hdr *ospkg,
1408 struct ice_seg **seg)
1410 struct ice_aqc_get_pkg_info_resp *pkg;
1411 enum ice_status status;
1415 ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
1417 /* Check package version compatibility */
1418 status = ice_chk_pkg_version(&hw->pkg_ver);
1420 ice_debug(hw, ICE_DBG_INIT, "Package version check failed.\n");
1424 /* find ICE segment in given package */
1425 *seg = (struct ice_seg *)ice_find_seg_in_pkg(hw, SEGMENT_TYPE_ICE,
1428 ice_debug(hw, ICE_DBG_INIT, "no ice segment in package.\n");
1432 /* Check if FW is compatible with the OS package */
1433 size = ice_struct_size(pkg, pkg_info, ICE_PKG_CNT);
1434 pkg = (struct ice_aqc_get_pkg_info_resp *)ice_malloc(hw, size);
1436 return ICE_ERR_NO_MEMORY;
1438 status = ice_aq_get_pkg_info_list(hw, pkg, size, NULL);
1440 goto fw_ddp_compat_free_alloc;
1442 for (i = 0; i < LE32_TO_CPU(pkg->count); i++) {
1443 /* loop till we find the NVM package */
1444 if (!pkg->pkg_info[i].is_in_nvm)
1446 if ((*seg)->hdr.seg_format_ver.major !=
1447 pkg->pkg_info[i].ver.major ||
1448 (*seg)->hdr.seg_format_ver.minor >
1449 pkg->pkg_info[i].ver.minor) {
1450 status = ICE_ERR_FW_DDP_MISMATCH;
1451 ice_debug(hw, ICE_DBG_INIT, "OS package is not compatible with NVM.\n");
1453 /* done processing NVM package so break */
1456 fw_ddp_compat_free_alloc:
1463 * @sect_type: section type
1464 * @section: pointer to section
1465 * @index: index of the field vector entry to be returned
1466 * @offset: ptr to variable that receives the offset in the field vector table
1468 * This is a callback function that can be passed to ice_pkg_enum_entry.
1469 * This function treats the given section as of type ice_sw_fv_section and
1470 * enumerates offset field. "offset" is an index into the field vector table.
1473 ice_sw_fv_handler(u32 sect_type, void *section, u32 index, u32 *offset)
1475 struct ice_sw_fv_section *fv_section =
1476 (struct ice_sw_fv_section *)section;
1478 if (!section || sect_type != ICE_SID_FLD_VEC_SW)
1480 if (index >= LE16_TO_CPU(fv_section->count))
1483 /* "index" passed in to this function is relative to a given
1484 * 4k block. To get to the true index into the field vector
1485 * table need to add the relative index to the base_offset
1486 * field of this section
1488 *offset = LE16_TO_CPU(fv_section->base_offset) + index;
1489 return fv_section->fv + index;
1493 * ice_get_prof_index_max - get the max profile index for used profile
1494 * @hw: pointer to the HW struct
1496 * Calling this function will get the max profile index for used profile
1497 * and store the index number in struct ice_switch_info *switch_info
1498 * in hw for following use.
1500 static int ice_get_prof_index_max(struct ice_hw *hw)
1502 u16 prof_index = 0, j, max_prof_index = 0;
1503 struct ice_pkg_enum state;
1504 struct ice_seg *ice_seg;
1509 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1512 return ICE_ERR_PARAM;
1517 fv = (struct ice_fv *)
1518 ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1519 &offset, ice_sw_fv_handler);
1524 /* in the profile that not be used, the prot_id is set to 0xff
1525 * and the off is set to 0x1ff for all the field vectors.
1527 for (j = 0; j < hw->blk[ICE_BLK_SW].es.fvw; j++)
1528 if (fv->ew[j].prot_id != ICE_PROT_INVALID ||
1529 fv->ew[j].off != ICE_FV_OFFSET_INVAL)
1531 if (flag && prof_index > max_prof_index)
1532 max_prof_index = prof_index;
1538 hw->switch_info->max_used_prof_index = max_prof_index;
1544 * ice_init_pkg - initialize/download package
1545 * @hw: pointer to the hardware structure
1546 * @buf: pointer to the package buffer
1547 * @len: size of the package buffer
1549 * This function initializes a package. The package contains HW tables
1550 * required to do packet processing. First, the function extracts package
1551 * information such as version. Then it finds the ice configuration segment
1552 * within the package; this function then saves a copy of the segment pointer
1553 * within the supplied package buffer. Next, the function will cache any hints
1554 * from the package, followed by downloading the package itself. Note, that if
1555 * a previous PF driver has already downloaded the package successfully, then
1556 * the current driver will not have to download the package again.
1558 * The local package contents will be used to query default behavior and to
1559 * update specific sections of the HW's version of the package (e.g. to update
1560 * the parse graph to understand new protocols).
1562 * This function stores a pointer to the package buffer memory, and it is
1563 * expected that the supplied buffer will not be freed immediately. If the
1564 * package buffer needs to be freed, such as when read from a file, use
1565 * ice_copy_and_init_pkg() instead of directly calling ice_init_pkg() in this
1568 enum ice_status ice_init_pkg(struct ice_hw *hw, u8 *buf, u32 len)
1570 struct ice_pkg_hdr *pkg;
1571 enum ice_status status;
1572 struct ice_seg *seg;
1575 return ICE_ERR_PARAM;
1577 pkg = (struct ice_pkg_hdr *)buf;
1578 status = ice_verify_pkg(pkg, len);
1580 ice_debug(hw, ICE_DBG_INIT, "failed to verify pkg (err: %d)\n",
1585 /* initialize package info */
1586 status = ice_init_pkg_info(hw, pkg);
1590 /* before downloading the package, check package version for
1591 * compatibility with driver
1593 status = ice_chk_pkg_compat(hw, pkg, &seg);
1597 /* initialize package hints and then download package */
1598 ice_init_pkg_hints(hw, seg);
1599 status = ice_download_pkg(hw, seg);
1600 if (status == ICE_ERR_AQ_NO_WORK) {
1601 ice_debug(hw, ICE_DBG_INIT, "package previously loaded - no work.\n");
1602 status = ICE_SUCCESS;
1605 /* Get information on the package currently loaded in HW, then make sure
1606 * the driver is compatible with this version.
1609 status = ice_get_pkg_info(hw);
1611 status = ice_chk_pkg_version(&hw->active_pkg_ver);
1616 /* on successful package download update other required
1617 * registers to support the package and fill HW tables
1618 * with package content.
1620 ice_init_pkg_regs(hw);
1621 ice_fill_blk_tbls(hw);
1622 ice_fill_hw_ptype(hw);
1623 ice_get_prof_index_max(hw);
1625 ice_debug(hw, ICE_DBG_INIT, "package load failed, %d\n",
1633 * ice_copy_and_init_pkg - initialize/download a copy of the package
1634 * @hw: pointer to the hardware structure
1635 * @buf: pointer to the package buffer
1636 * @len: size of the package buffer
1638 * This function copies the package buffer, and then calls ice_init_pkg() to
1639 * initialize the copied package contents.
1641 * The copying is necessary if the package buffer supplied is constant, or if
1642 * the memory may disappear shortly after calling this function.
1644 * If the package buffer resides in the data segment and can be modified, the
1645 * caller is free to use ice_init_pkg() instead of ice_copy_and_init_pkg().
1647 * However, if the package buffer needs to be copied first, such as when being
1648 * read from a file, the caller should use ice_copy_and_init_pkg().
1650 * This function will first copy the package buffer, before calling
1651 * ice_init_pkg(). The caller is free to immediately destroy the original
1652 * package buffer, as the new copy will be managed by this function and
1655 enum ice_status ice_copy_and_init_pkg(struct ice_hw *hw, const u8 *buf, u32 len)
1657 enum ice_status status;
1661 return ICE_ERR_PARAM;
1663 buf_copy = (u8 *)ice_memdup(hw, buf, len, ICE_NONDMA_TO_NONDMA);
1665 status = ice_init_pkg(hw, buf_copy, len);
1667 /* Free the copy, since we failed to initialize the package */
1668 ice_free(hw, buf_copy);
1670 /* Track the copied pkg so we can free it later */
1671 hw->pkg_copy = buf_copy;
1680 * @hw: pointer to the HW structure
1682 * Allocates a package buffer and returns a pointer to the buffer header.
1683 * Note: all package contents must be in Little Endian form.
1685 static struct ice_buf_build *ice_pkg_buf_alloc(struct ice_hw *hw)
1687 struct ice_buf_build *bld;
1688 struct ice_buf_hdr *buf;
1690 bld = (struct ice_buf_build *)ice_malloc(hw, sizeof(*bld));
1694 buf = (struct ice_buf_hdr *)bld;
1695 buf->data_end = CPU_TO_LE16(offsetof(struct ice_buf_hdr,
1701 * ice_get_sw_prof_type - determine switch profile type
1702 * @hw: pointer to the HW structure
1703 * @fv: pointer to the switch field vector
1705 static enum ice_prof_type
1706 ice_get_sw_prof_type(struct ice_hw *hw, struct ice_fv *fv)
1710 for (i = 0; i < hw->blk[ICE_BLK_SW].es.fvw; i++) {
1711 /* UDP tunnel will have UDP_OF protocol ID and VNI offset */
1712 if (fv->ew[i].prot_id == (u8)ICE_PROT_UDP_OF &&
1713 fv->ew[i].off == ICE_VNI_OFFSET)
1714 return ICE_PROF_TUN_UDP;
1716 /* GRE tunnel will have GRE protocol */
1717 if (fv->ew[i].prot_id == (u8)ICE_PROT_GRE_OF)
1718 return ICE_PROF_TUN_GRE;
1720 /* PPPOE tunnel will have PPPOE protocol */
1721 if (fv->ew[i].prot_id == (u8)ICE_PROT_PPPOE)
1722 return ICE_PROF_TUN_PPPOE;
1725 return ICE_PROF_NON_TUN;
1729 * ice_get_sw_fv_bitmap - Get switch field vector bitmap based on profile type
1730 * @hw: pointer to hardware structure
1731 * @req_profs: type of profiles requested
1732 * @bm: pointer to memory for returning the bitmap of field vectors
1735 ice_get_sw_fv_bitmap(struct ice_hw *hw, enum ice_prof_type req_profs,
1738 struct ice_pkg_enum state;
1739 struct ice_seg *ice_seg;
1742 if (req_profs == ICE_PROF_ALL) {
1743 ice_bitmap_set(bm, 0, ICE_MAX_NUM_PROFILES);
1747 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1748 ice_zero_bitmap(bm, ICE_MAX_NUM_PROFILES);
1751 enum ice_prof_type prof_type;
1754 fv = (struct ice_fv *)
1755 ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1756 &offset, ice_sw_fv_handler);
1760 /* Determine field vector type */
1761 prof_type = ice_get_sw_prof_type(hw, fv);
1763 if (req_profs & prof_type)
1764 ice_set_bit((u16)offset, bm);
1770 * ice_get_sw_fv_list
1771 * @hw: pointer to the HW structure
1772 * @prot_ids: field vector to search for with a given protocol ID
1773 * @ids_cnt: lookup/protocol count
1774 * @bm: bitmap of field vectors to consider
1775 * @fv_list: Head of a list
1777 * Finds all the field vector entries from switch block that contain
1778 * a given protocol ID and returns a list of structures of type
1779 * "ice_sw_fv_list_entry". Every structure in the list has a field vector
1780 * definition and profile ID information
1781 * NOTE: The caller of the function is responsible for freeing the memory
1782 * allocated for every list entry.
1785 ice_get_sw_fv_list(struct ice_hw *hw, u8 *prot_ids, u16 ids_cnt,
1786 ice_bitmap_t *bm, struct LIST_HEAD_TYPE *fv_list)
1788 struct ice_sw_fv_list_entry *fvl;
1789 struct ice_sw_fv_list_entry *tmp;
1790 struct ice_pkg_enum state;
1791 struct ice_seg *ice_seg;
1795 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1797 if (!ids_cnt || !hw->seg)
1798 return ICE_ERR_PARAM;
1804 fv = (struct ice_fv *)
1805 ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1806 &offset, ice_sw_fv_handler);
1811 /* If field vector is not in the bitmap list, then skip this
1814 if (!ice_is_bit_set(bm, (u16)offset))
1817 for (i = 0; i < ids_cnt; i++) {
1820 /* This code assumes that if a switch field vector line
1821 * has a matching protocol, then this line will contain
1822 * the entries necessary to represent every field in
1823 * that protocol header.
1825 for (j = 0; j < hw->blk[ICE_BLK_SW].es.fvw; j++)
1826 if (fv->ew[j].prot_id == prot_ids[i])
1828 if (j >= hw->blk[ICE_BLK_SW].es.fvw)
1830 if (i + 1 == ids_cnt) {
1831 fvl = (struct ice_sw_fv_list_entry *)
1832 ice_malloc(hw, sizeof(*fvl));
1836 fvl->profile_id = offset;
1837 LIST_ADD(&fvl->list_entry, fv_list);
1842 if (LIST_EMPTY(fv_list))
1847 LIST_FOR_EACH_ENTRY_SAFE(fvl, tmp, fv_list, ice_sw_fv_list_entry,
1849 LIST_DEL(&fvl->list_entry);
1853 return ICE_ERR_NO_MEMORY;
1857 * ice_init_prof_result_bm - Initialize the profile result index bitmap
1858 * @hw: pointer to hardware structure
1860 void ice_init_prof_result_bm(struct ice_hw *hw)
1862 struct ice_pkg_enum state;
1863 struct ice_seg *ice_seg;
1866 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
1876 fv = (struct ice_fv *)
1877 ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW,
1878 &off, ice_sw_fv_handler);
1883 ice_zero_bitmap(hw->switch_info->prof_res_bm[off],
1886 /* Determine empty field vector indices, these can be
1887 * used for recipe results. Skip index 0, since it is
1888 * always used for Switch ID.
1890 for (i = 1; i < ICE_MAX_FV_WORDS; i++)
1891 if (fv->ew[i].prot_id == ICE_PROT_INVALID &&
1892 fv->ew[i].off == ICE_FV_OFFSET_INVAL)
1894 hw->switch_info->prof_res_bm[off]);
1900 * @hw: pointer to the HW structure
1901 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1903 * Frees a package buffer
1905 void ice_pkg_buf_free(struct ice_hw *hw, struct ice_buf_build *bld)
1911 * ice_pkg_buf_reserve_section
1912 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1913 * @count: the number of sections to reserve
1915 * Reserves one or more section table entries in a package buffer. This routine
1916 * can be called multiple times as long as they are made before calling
1917 * ice_pkg_buf_alloc_section(). Once ice_pkg_buf_alloc_section()
1918 * is called once, the number of sections that can be allocated will not be able
1919 * to be increased; not using all reserved sections is fine, but this will
1920 * result in some wasted space in the buffer.
1921 * Note: all package contents must be in Little Endian form.
1923 static enum ice_status
1924 ice_pkg_buf_reserve_section(struct ice_buf_build *bld, u16 count)
1926 struct ice_buf_hdr *buf;
1931 return ICE_ERR_PARAM;
1933 buf = (struct ice_buf_hdr *)&bld->buf;
1935 /* already an active section, can't increase table size */
1936 section_count = LE16_TO_CPU(buf->section_count);
1937 if (section_count > 0)
1940 if (bld->reserved_section_table_entries + count > ICE_MAX_S_COUNT)
1942 bld->reserved_section_table_entries += count;
1944 data_end = LE16_TO_CPU(buf->data_end) +
1945 FLEX_ARRAY_SIZE(buf, section_entry, count);
1946 buf->data_end = CPU_TO_LE16(data_end);
1952 * ice_pkg_buf_alloc_section
1953 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
1954 * @type: the section type value
1955 * @size: the size of the section to reserve (in bytes)
1957 * Reserves memory in the buffer for a section's content and updates the
1958 * buffers' status accordingly. This routine returns a pointer to the first
1959 * byte of the section start within the buffer, which is used to fill in the
1961 * Note: all package contents must be in Little Endian form.
1964 ice_pkg_buf_alloc_section(struct ice_buf_build *bld, u32 type, u16 size)
1966 struct ice_buf_hdr *buf;
1970 if (!bld || !type || !size)
1973 buf = (struct ice_buf_hdr *)&bld->buf;
1975 /* check for enough space left in buffer */
1976 data_end = LE16_TO_CPU(buf->data_end);
1978 /* section start must align on 4 byte boundary */
1979 data_end = ICE_ALIGN(data_end, 4);
1981 if ((data_end + size) > ICE_MAX_S_DATA_END)
1984 /* check for more available section table entries */
1985 sect_count = LE16_TO_CPU(buf->section_count);
1986 if (sect_count < bld->reserved_section_table_entries) {
1987 void *section_ptr = ((u8 *)buf) + data_end;
1989 buf->section_entry[sect_count].offset = CPU_TO_LE16(data_end);
1990 buf->section_entry[sect_count].size = CPU_TO_LE16(size);
1991 buf->section_entry[sect_count].type = CPU_TO_LE32(type);
1994 buf->data_end = CPU_TO_LE16(data_end);
1996 buf->section_count = CPU_TO_LE16(sect_count + 1);
2000 /* no free section table entries */
2005 * ice_pkg_buf_alloc_single_section
2006 * @hw: pointer to the HW structure
2007 * @type: the section type value
2008 * @size: the size of the section to reserve (in bytes)
2009 * @section: returns pointer to the section
2011 * Allocates a package buffer with a single section.
2012 * Note: all package contents must be in Little Endian form.
2014 struct ice_buf_build *
2015 ice_pkg_buf_alloc_single_section(struct ice_hw *hw, u32 type, u16 size,
2018 struct ice_buf_build *buf;
2023 buf = ice_pkg_buf_alloc(hw);
2027 if (ice_pkg_buf_reserve_section(buf, 1))
2028 goto ice_pkg_buf_alloc_single_section_err;
2030 *section = ice_pkg_buf_alloc_section(buf, type, size);
2032 goto ice_pkg_buf_alloc_single_section_err;
2036 ice_pkg_buf_alloc_single_section_err:
2037 ice_pkg_buf_free(hw, buf);
2042 * ice_pkg_buf_get_active_sections
2043 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
2045 * Returns the number of active sections. Before using the package buffer
2046 * in an update package command, the caller should make sure that there is at
2047 * least one active section - otherwise, the buffer is not legal and should
2049 * Note: all package contents must be in Little Endian form.
2051 static u16 ice_pkg_buf_get_active_sections(struct ice_buf_build *bld)
2053 struct ice_buf_hdr *buf;
2058 buf = (struct ice_buf_hdr *)&bld->buf;
2059 return LE16_TO_CPU(buf->section_count);
2064 * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc())
2066 * Return a pointer to the buffer's header
2068 struct ice_buf *ice_pkg_buf(struct ice_buf_build *bld)
2077 * ice_tunnel_port_in_use_hlpr - helper function to determine tunnel usage
2078 * @hw: pointer to the HW structure
2079 * @port: port to search for
2080 * @index: optionally returns index
2082 * Returns whether a port is already in use as a tunnel, and optionally its
2085 static bool ice_tunnel_port_in_use_hlpr(struct ice_hw *hw, u16 port, u16 *index)
2089 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
2090 if (hw->tnl.tbl[i].in_use && hw->tnl.tbl[i].port == port) {
2100 * ice_tunnel_port_in_use
2101 * @hw: pointer to the HW structure
2102 * @port: port to search for
2103 * @index: optionally returns index
2105 * Returns whether a port is already in use as a tunnel, and optionally its
2108 bool ice_tunnel_port_in_use(struct ice_hw *hw, u16 port, u16 *index)
2112 ice_acquire_lock(&hw->tnl_lock);
2113 res = ice_tunnel_port_in_use_hlpr(hw, port, index);
2114 ice_release_lock(&hw->tnl_lock);
2120 * ice_tunnel_get_type
2121 * @hw: pointer to the HW structure
2122 * @port: port to search for
2123 * @type: returns tunnel index
2125 * For a given port number, will return the type of tunnel.
2128 ice_tunnel_get_type(struct ice_hw *hw, u16 port, enum ice_tunnel_type *type)
2133 ice_acquire_lock(&hw->tnl_lock);
2135 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
2136 if (hw->tnl.tbl[i].in_use && hw->tnl.tbl[i].port == port) {
2137 *type = hw->tnl.tbl[i].type;
2142 ice_release_lock(&hw->tnl_lock);
2148 * ice_find_free_tunnel_entry
2149 * @hw: pointer to the HW structure
2150 * @type: tunnel type
2151 * @index: optionally returns index
2153 * Returns whether there is a free tunnel entry, and optionally its index
2156 ice_find_free_tunnel_entry(struct ice_hw *hw, enum ice_tunnel_type type,
2161 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
2162 if (hw->tnl.tbl[i].valid && !hw->tnl.tbl[i].in_use &&
2163 hw->tnl.tbl[i].type == type) {
2173 * ice_get_open_tunnel_port - retrieve an open tunnel port
2174 * @hw: pointer to the HW structure
2175 * @type: tunnel type (TNL_ALL will return any open port)
2176 * @port: returns open port
2179 ice_get_open_tunnel_port(struct ice_hw *hw, enum ice_tunnel_type type,
2185 ice_acquire_lock(&hw->tnl_lock);
2187 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
2188 if (hw->tnl.tbl[i].valid && hw->tnl.tbl[i].in_use &&
2189 (type == TNL_ALL || hw->tnl.tbl[i].type == type)) {
2190 *port = hw->tnl.tbl[i].port;
2195 ice_release_lock(&hw->tnl_lock);
2202 * @hw: pointer to the HW structure
2203 * @type: type of tunnel
2204 * @port: port of tunnel to create
2206 * Create a tunnel by updating the parse graph in the parser. We do that by
2207 * creating a package buffer with the tunnel info and issuing an update package
2211 ice_create_tunnel(struct ice_hw *hw, enum ice_tunnel_type type, u16 port)
2213 struct ice_boost_tcam_section *sect_rx, *sect_tx;
2214 enum ice_status status = ICE_ERR_MAX_LIMIT;
2215 struct ice_buf_build *bld;
2218 ice_acquire_lock(&hw->tnl_lock);
2220 if (ice_tunnel_port_in_use_hlpr(hw, port, &index)) {
2221 hw->tnl.tbl[index].ref++;
2222 status = ICE_SUCCESS;
2223 goto ice_create_tunnel_end;
2226 if (!ice_find_free_tunnel_entry(hw, type, &index)) {
2227 status = ICE_ERR_OUT_OF_RANGE;
2228 goto ice_create_tunnel_end;
2231 bld = ice_pkg_buf_alloc(hw);
2233 status = ICE_ERR_NO_MEMORY;
2234 goto ice_create_tunnel_end;
2237 /* allocate 2 sections, one for Rx parser, one for Tx parser */
2238 if (ice_pkg_buf_reserve_section(bld, 2))
2239 goto ice_create_tunnel_err;
2241 sect_rx = (struct ice_boost_tcam_section *)
2242 ice_pkg_buf_alloc_section(bld, ICE_SID_RXPARSER_BOOST_TCAM,
2243 ice_struct_size(sect_rx, tcam, 1));
2245 goto ice_create_tunnel_err;
2246 sect_rx->count = CPU_TO_LE16(1);
2248 sect_tx = (struct ice_boost_tcam_section *)
2249 ice_pkg_buf_alloc_section(bld, ICE_SID_TXPARSER_BOOST_TCAM,
2250 ice_struct_size(sect_tx, tcam, 1));
2252 goto ice_create_tunnel_err;
2253 sect_tx->count = CPU_TO_LE16(1);
2255 /* copy original boost entry to update package buffer */
2256 ice_memcpy(sect_rx->tcam, hw->tnl.tbl[index].boost_entry,
2257 sizeof(*sect_rx->tcam), ICE_NONDMA_TO_NONDMA);
2259 /* over-write the never-match dest port key bits with the encoded port
2262 ice_set_key((u8 *)§_rx->tcam[0].key, sizeof(sect_rx->tcam[0].key),
2263 (u8 *)&port, NULL, NULL, NULL,
2264 (u16)offsetof(struct ice_boost_key_value, hv_dst_port_key),
2265 sizeof(sect_rx->tcam[0].key.key.hv_dst_port_key));
2267 /* exact copy of entry to Tx section entry */
2268 ice_memcpy(sect_tx->tcam, sect_rx->tcam, sizeof(*sect_tx->tcam),
2269 ICE_NONDMA_TO_NONDMA);
2271 status = ice_update_pkg(hw, ice_pkg_buf(bld), 1);
2273 hw->tnl.tbl[index].port = port;
2274 hw->tnl.tbl[index].in_use = true;
2275 hw->tnl.tbl[index].ref = 1;
2278 ice_create_tunnel_err:
2279 ice_pkg_buf_free(hw, bld);
2281 ice_create_tunnel_end:
2282 ice_release_lock(&hw->tnl_lock);
2288 * ice_destroy_tunnel
2289 * @hw: pointer to the HW structure
2290 * @port: port of tunnel to destroy (ignored if the all parameter is true)
2291 * @all: flag that states to destroy all tunnels
2293 * Destroys a tunnel or all tunnels by creating an update package buffer
2294 * targeting the specific updates requested and then performing an update
2297 enum ice_status ice_destroy_tunnel(struct ice_hw *hw, u16 port, bool all)
2299 struct ice_boost_tcam_section *sect_rx, *sect_tx;
2300 enum ice_status status = ICE_ERR_MAX_LIMIT;
2301 struct ice_buf_build *bld;
2307 ice_acquire_lock(&hw->tnl_lock);
2309 if (!all && ice_tunnel_port_in_use_hlpr(hw, port, &index))
2310 if (hw->tnl.tbl[index].ref > 1) {
2311 hw->tnl.tbl[index].ref--;
2312 status = ICE_SUCCESS;
2313 goto ice_destroy_tunnel_end;
2316 /* determine count */
2317 for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
2318 if (hw->tnl.tbl[i].valid && hw->tnl.tbl[i].in_use &&
2319 (all || hw->tnl.tbl[i].port == port))
2323 status = ICE_ERR_PARAM;
2324 goto ice_destroy_tunnel_end;
2327 /* size of section - there is at least one entry */
2328 size = ice_struct_size(sect_rx, tcam, count);
2330 bld = ice_pkg_buf_alloc(hw);
2332 status = ICE_ERR_NO_MEMORY;
2333 goto ice_destroy_tunnel_end;
2336 /* allocate 2 sections, one for Rx parser, one for Tx parser */
2337 if (ice_pkg_buf_reserve_section(bld, 2))
2338 goto ice_destroy_tunnel_err;
2340 sect_rx = (struct ice_boost_tcam_section *)
2341 ice_pkg_buf_alloc_section(bld, ICE_SID_RXPARSER_BOOST_TCAM,
2344 goto ice_destroy_tunnel_err;
2345 sect_rx->count = CPU_TO_LE16(count);
2347 sect_tx = (struct ice_boost_tcam_section *)
2348 ice_pkg_buf_alloc_section(bld, ICE_SID_TXPARSER_BOOST_TCAM,
2351 goto ice_destroy_tunnel_err;
2352 sect_tx->count = CPU_TO_LE16(count);
2354 /* copy original boost entry to update package buffer, one copy to Rx
2355 * section, another copy to the Tx section
2357 for (i = 0, j = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
2358 if (hw->tnl.tbl[i].valid && hw->tnl.tbl[i].in_use &&
2359 (all || hw->tnl.tbl[i].port == port)) {
2360 ice_memcpy(sect_rx->tcam + j,
2361 hw->tnl.tbl[i].boost_entry,
2362 sizeof(*sect_rx->tcam),
2363 ICE_NONDMA_TO_NONDMA);
2364 ice_memcpy(sect_tx->tcam + j,
2365 hw->tnl.tbl[i].boost_entry,
2366 sizeof(*sect_tx->tcam),
2367 ICE_NONDMA_TO_NONDMA);
2368 hw->tnl.tbl[i].marked = true;
2372 status = ice_update_pkg(hw, ice_pkg_buf(bld), 1);
2374 for (i = 0; i < hw->tnl.count &&
2375 i < ICE_TUNNEL_MAX_ENTRIES; i++)
2376 if (hw->tnl.tbl[i].marked) {
2377 hw->tnl.tbl[i].ref = 0;
2378 hw->tnl.tbl[i].port = 0;
2379 hw->tnl.tbl[i].in_use = false;
2380 hw->tnl.tbl[i].marked = false;
2383 ice_destroy_tunnel_err:
2384 ice_pkg_buf_free(hw, bld);
2386 ice_destroy_tunnel_end:
2387 ice_release_lock(&hw->tnl_lock);
2393 * ice_find_prot_off - find prot ID and offset pair, based on prof and FV index
2394 * @hw: pointer to the hardware structure
2395 * @blk: hardware block
2397 * @fv_idx: field vector word index
2398 * @prot: variable to receive the protocol ID
2399 * @off: variable to receive the protocol offset
2402 ice_find_prot_off(struct ice_hw *hw, enum ice_block blk, u8 prof, u16 fv_idx,
2405 struct ice_fv_word *fv_ext;
2407 if (prof >= hw->blk[blk].es.count)
2408 return ICE_ERR_PARAM;
2410 if (fv_idx >= hw->blk[blk].es.fvw)
2411 return ICE_ERR_PARAM;
2413 fv_ext = hw->blk[blk].es.t + (prof * hw->blk[blk].es.fvw);
2415 *prot = fv_ext[fv_idx].prot_id;
2416 *off = fv_ext[fv_idx].off;
2421 /* PTG Management */
2424 * ice_ptg_find_ptype - Search for packet type group using packet type (ptype)
2425 * @hw: pointer to the hardware structure
2427 * @ptype: the ptype to search for
2428 * @ptg: pointer to variable that receives the PTG
2430 * This function will search the PTGs for a particular ptype, returning the
2431 * PTG ID that contains it through the PTG parameter, with the value of
2432 * ICE_DEFAULT_PTG (0) meaning it is part the default PTG.
2434 static enum ice_status
2435 ice_ptg_find_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 *ptg)
2437 if (ptype >= ICE_XLT1_CNT || !ptg)
2438 return ICE_ERR_PARAM;
2440 *ptg = hw->blk[blk].xlt1.ptypes[ptype].ptg;
2445 * ice_ptg_alloc_val - Allocates a new packet type group ID by value
2446 * @hw: pointer to the hardware structure
2448 * @ptg: the PTG to allocate
2450 * This function allocates a given packet type group ID specified by the PTG
2453 static void ice_ptg_alloc_val(struct ice_hw *hw, enum ice_block blk, u8 ptg)
2455 hw->blk[blk].xlt1.ptg_tbl[ptg].in_use = true;
2459 * ice_ptg_remove_ptype - Removes ptype from a particular packet type group
2460 * @hw: pointer to the hardware structure
2462 * @ptype: the ptype to remove
2463 * @ptg: the PTG to remove the ptype from
2465 * This function will remove the ptype from the specific PTG, and move it to
2466 * the default PTG (ICE_DEFAULT_PTG).
2468 static enum ice_status
2469 ice_ptg_remove_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 ptg)
2471 struct ice_ptg_ptype **ch;
2472 struct ice_ptg_ptype *p;
2474 if (ptype > ICE_XLT1_CNT - 1)
2475 return ICE_ERR_PARAM;
2477 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].in_use)
2478 return ICE_ERR_DOES_NOT_EXIST;
2480 /* Should not happen if .in_use is set, bad config */
2481 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype)
2484 /* find the ptype within this PTG, and bypass the link over it */
2485 p = hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2486 ch = &hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2488 if (ptype == (p - hw->blk[blk].xlt1.ptypes)) {
2489 *ch = p->next_ptype;
2493 ch = &p->next_ptype;
2497 hw->blk[blk].xlt1.ptypes[ptype].ptg = ICE_DEFAULT_PTG;
2498 hw->blk[blk].xlt1.ptypes[ptype].next_ptype = NULL;
2504 * ice_ptg_add_mv_ptype - Adds/moves ptype to a particular packet type group
2505 * @hw: pointer to the hardware structure
2507 * @ptype: the ptype to add or move
2508 * @ptg: the PTG to add or move the ptype to
2510 * This function will either add or move a ptype to a particular PTG depending
2511 * on if the ptype is already part of another group. Note that using a
2512 * a destination PTG ID of ICE_DEFAULT_PTG (0) will move the ptype to the
2515 static enum ice_status
2516 ice_ptg_add_mv_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 ptg)
2518 enum ice_status status;
2521 if (ptype > ICE_XLT1_CNT - 1)
2522 return ICE_ERR_PARAM;
2524 if (!hw->blk[blk].xlt1.ptg_tbl[ptg].in_use && ptg != ICE_DEFAULT_PTG)
2525 return ICE_ERR_DOES_NOT_EXIST;
2527 status = ice_ptg_find_ptype(hw, blk, ptype, &original_ptg);
2531 /* Is ptype already in the correct PTG? */
2532 if (original_ptg == ptg)
2535 /* Remove from original PTG and move back to the default PTG */
2536 if (original_ptg != ICE_DEFAULT_PTG)
2537 ice_ptg_remove_ptype(hw, blk, ptype, original_ptg);
2539 /* Moving to default PTG? Then we're done with this request */
2540 if (ptg == ICE_DEFAULT_PTG)
2543 /* Add ptype to PTG at beginning of list */
2544 hw->blk[blk].xlt1.ptypes[ptype].next_ptype =
2545 hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype;
2546 hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype =
2547 &hw->blk[blk].xlt1.ptypes[ptype];
2549 hw->blk[blk].xlt1.ptypes[ptype].ptg = ptg;
2550 hw->blk[blk].xlt1.t[ptype] = ptg;
2555 /* Block / table size info */
2556 struct ice_blk_size_details {
2557 u16 xlt1; /* # XLT1 entries */
2558 u16 xlt2; /* # XLT2 entries */
2559 u16 prof_tcam; /* # profile ID TCAM entries */
2560 u16 prof_id; /* # profile IDs */
2561 u8 prof_cdid_bits; /* # CDID one-hot bits used in key */
2562 u16 prof_redir; /* # profile redirection entries */
2563 u16 es; /* # extraction sequence entries */
2564 u16 fvw; /* # field vector words */
2565 u8 overwrite; /* overwrite existing entries allowed */
2566 u8 reverse; /* reverse FV order */
2569 static const struct ice_blk_size_details blk_sizes[ICE_BLK_COUNT] = {
2572 * XLT1 - Number of entries in XLT1 table
2573 * XLT2 - Number of entries in XLT2 table
2574 * TCAM - Number of entries Profile ID TCAM table
2575 * CDID - Control Domain ID of the hardware block
2576 * PRED - Number of entries in the Profile Redirection Table
2577 * FV - Number of entries in the Field Vector
2578 * FVW - Width (in WORDs) of the Field Vector
2579 * OVR - Overwrite existing table entries
2582 /* XLT1 , XLT2 ,TCAM, PID,CDID,PRED, FV, FVW */
2583 /* Overwrite , Reverse FV */
2584 /* SW */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 256, 0, 256, 256, 48,
2586 /* ACL */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 32,
2588 /* FD */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 24,
2590 /* RSS */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 24,
2592 /* PE */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 64, 32, 0, 32, 32, 24,
2597 ICE_SID_XLT1_OFF = 0,
2600 ICE_SID_PR_REDIR_OFF,
2605 /* Characteristic handling */
2608 * ice_match_prop_lst - determine if properties of two lists match
2609 * @list1: first properties list
2610 * @list2: second properties list
2612 * Count, cookies and the order must match in order to be considered equivalent.
2615 ice_match_prop_lst(struct LIST_HEAD_TYPE *list1, struct LIST_HEAD_TYPE *list2)
2617 struct ice_vsig_prof *tmp1;
2618 struct ice_vsig_prof *tmp2;
2622 /* compare counts */
2623 LIST_FOR_EACH_ENTRY(tmp1, list1, ice_vsig_prof, list)
2625 LIST_FOR_EACH_ENTRY(tmp2, list2, ice_vsig_prof, list)
2627 if (!count || count != chk_count)
2630 tmp1 = LIST_FIRST_ENTRY(list1, struct ice_vsig_prof, list);
2631 tmp2 = LIST_FIRST_ENTRY(list2, struct ice_vsig_prof, list);
2633 /* profile cookies must compare, and in the exact same order to take
2634 * into account priority
2637 if (tmp2->profile_cookie != tmp1->profile_cookie)
2640 tmp1 = LIST_NEXT_ENTRY(tmp1, struct ice_vsig_prof, list);
2641 tmp2 = LIST_NEXT_ENTRY(tmp2, struct ice_vsig_prof, list);
2647 /* VSIG Management */
2650 * ice_vsig_find_vsi - find a VSIG that contains a specified VSI
2651 * @hw: pointer to the hardware structure
2653 * @vsi: VSI of interest
2654 * @vsig: pointer to receive the VSI group
2656 * This function will lookup the VSI entry in the XLT2 list and return
2657 * the VSI group its associated with.
2660 ice_vsig_find_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 *vsig)
2662 if (!vsig || vsi >= ICE_MAX_VSI)
2663 return ICE_ERR_PARAM;
2665 /* As long as there's a default or valid VSIG associated with the input
2666 * VSI, the functions returns a success. Any handling of VSIG will be
2667 * done by the following add, update or remove functions.
2669 *vsig = hw->blk[blk].xlt2.vsis[vsi].vsig;
2675 * ice_vsig_alloc_val - allocate a new VSIG by value
2676 * @hw: pointer to the hardware structure
2678 * @vsig: the VSIG to allocate
2680 * This function will allocate a given VSIG specified by the VSIG parameter.
2682 static u16 ice_vsig_alloc_val(struct ice_hw *hw, enum ice_block blk, u16 vsig)
2684 u16 idx = vsig & ICE_VSIG_IDX_M;
2686 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use) {
2687 INIT_LIST_HEAD(&hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst);
2688 hw->blk[blk].xlt2.vsig_tbl[idx].in_use = true;
2691 return ICE_VSIG_VALUE(idx, hw->pf_id);
2695 * ice_vsig_alloc - Finds a free entry and allocates a new VSIG
2696 * @hw: pointer to the hardware structure
2699 * This function will iterate through the VSIG list and mark the first
2700 * unused entry for the new VSIG entry as used and return that value.
2702 static u16 ice_vsig_alloc(struct ice_hw *hw, enum ice_block blk)
2706 for (i = 1; i < ICE_MAX_VSIGS; i++)
2707 if (!hw->blk[blk].xlt2.vsig_tbl[i].in_use)
2708 return ice_vsig_alloc_val(hw, blk, i);
2710 return ICE_DEFAULT_VSIG;
2714 * ice_find_dup_props_vsig - find VSI group with a specified set of properties
2715 * @hw: pointer to the hardware structure
2717 * @chs: characteristic list
2718 * @vsig: returns the VSIG with the matching profiles, if found
2720 * Each VSIG is associated with a characteristic set; i.e. all VSIs under
2721 * a group have the same characteristic set. To check if there exists a VSIG
2722 * which has the same characteristics as the input characteristics; this
2723 * function will iterate through the XLT2 list and return the VSIG that has a
2724 * matching configuration. In order to make sure that priorities are accounted
2725 * for, the list must match exactly, including the order in which the
2726 * characteristics are listed.
2728 static enum ice_status
2729 ice_find_dup_props_vsig(struct ice_hw *hw, enum ice_block blk,
2730 struct LIST_HEAD_TYPE *chs, u16 *vsig)
2732 struct ice_xlt2 *xlt2 = &hw->blk[blk].xlt2;
2735 for (i = 0; i < xlt2->count; i++)
2736 if (xlt2->vsig_tbl[i].in_use &&
2737 ice_match_prop_lst(chs, &xlt2->vsig_tbl[i].prop_lst)) {
2738 *vsig = ICE_VSIG_VALUE(i, hw->pf_id);
2742 return ICE_ERR_DOES_NOT_EXIST;
2746 * ice_vsig_free - free VSI group
2747 * @hw: pointer to the hardware structure
2749 * @vsig: VSIG to remove
2751 * The function will remove all VSIs associated with the input VSIG and move
2752 * them to the DEFAULT_VSIG and mark the VSIG available.
2754 static enum ice_status
2755 ice_vsig_free(struct ice_hw *hw, enum ice_block blk, u16 vsig)
2757 struct ice_vsig_prof *dtmp, *del;
2758 struct ice_vsig_vsi *vsi_cur;
2761 idx = vsig & ICE_VSIG_IDX_M;
2762 if (idx >= ICE_MAX_VSIGS)
2763 return ICE_ERR_PARAM;
2765 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
2766 return ICE_ERR_DOES_NOT_EXIST;
2768 hw->blk[blk].xlt2.vsig_tbl[idx].in_use = false;
2770 vsi_cur = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2771 /* If the VSIG has at least 1 VSI then iterate through the
2772 * list and remove the VSIs before deleting the group.
2775 /* remove all vsis associated with this VSIG XLT2 entry */
2777 struct ice_vsig_vsi *tmp = vsi_cur->next_vsi;
2779 vsi_cur->vsig = ICE_DEFAULT_VSIG;
2780 vsi_cur->changed = 1;
2781 vsi_cur->next_vsi = NULL;
2785 /* NULL terminate head of VSI list */
2786 hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi = NULL;
2789 /* free characteristic list */
2790 LIST_FOR_EACH_ENTRY_SAFE(del, dtmp,
2791 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
2792 ice_vsig_prof, list) {
2793 LIST_DEL(&del->list);
2797 /* if VSIG characteristic list was cleared for reset
2798 * re-initialize the list head
2800 INIT_LIST_HEAD(&hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst);
2806 * ice_vsig_remove_vsi - remove VSI from VSIG
2807 * @hw: pointer to the hardware structure
2809 * @vsi: VSI to remove
2810 * @vsig: VSI group to remove from
2812 * The function will remove the input VSI from its VSI group and move it
2813 * to the DEFAULT_VSIG.
2815 static enum ice_status
2816 ice_vsig_remove_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
2818 struct ice_vsig_vsi **vsi_head, *vsi_cur, *vsi_tgt;
2821 idx = vsig & ICE_VSIG_IDX_M;
2823 if (vsi >= ICE_MAX_VSI || idx >= ICE_MAX_VSIGS)
2824 return ICE_ERR_PARAM;
2826 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
2827 return ICE_ERR_DOES_NOT_EXIST;
2829 /* entry already in default VSIG, don't have to remove */
2830 if (idx == ICE_DEFAULT_VSIG)
2833 vsi_head = &hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2837 vsi_tgt = &hw->blk[blk].xlt2.vsis[vsi];
2838 vsi_cur = (*vsi_head);
2840 /* iterate the VSI list, skip over the entry to be removed */
2842 if (vsi_tgt == vsi_cur) {
2843 (*vsi_head) = vsi_cur->next_vsi;
2846 vsi_head = &vsi_cur->next_vsi;
2847 vsi_cur = vsi_cur->next_vsi;
2850 /* verify if VSI was removed from group list */
2852 return ICE_ERR_DOES_NOT_EXIST;
2854 vsi_cur->vsig = ICE_DEFAULT_VSIG;
2855 vsi_cur->changed = 1;
2856 vsi_cur->next_vsi = NULL;
2862 * ice_vsig_add_mv_vsi - add or move a VSI to a VSI group
2863 * @hw: pointer to the hardware structure
2866 * @vsig: destination VSI group
2868 * This function will move or add the input VSI to the target VSIG.
2869 * The function will find the original VSIG the VSI belongs to and
2870 * move the entry to the DEFAULT_VSIG, update the original VSIG and
2871 * then move entry to the new VSIG.
2873 static enum ice_status
2874 ice_vsig_add_mv_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
2876 struct ice_vsig_vsi *tmp;
2877 enum ice_status status;
2880 idx = vsig & ICE_VSIG_IDX_M;
2882 if (vsi >= ICE_MAX_VSI || idx >= ICE_MAX_VSIGS)
2883 return ICE_ERR_PARAM;
2885 /* if VSIG not in use and VSIG is not default type this VSIG
2888 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use &&
2889 vsig != ICE_DEFAULT_VSIG)
2890 return ICE_ERR_DOES_NOT_EXIST;
2892 status = ice_vsig_find_vsi(hw, blk, vsi, &orig_vsig);
2896 /* no update required if vsigs match */
2897 if (orig_vsig == vsig)
2900 if (orig_vsig != ICE_DEFAULT_VSIG) {
2901 /* remove entry from orig_vsig and add to default VSIG */
2902 status = ice_vsig_remove_vsi(hw, blk, vsi, orig_vsig);
2907 if (idx == ICE_DEFAULT_VSIG)
2910 /* Create VSI entry and add VSIG and prop_mask values */
2911 hw->blk[blk].xlt2.vsis[vsi].vsig = vsig;
2912 hw->blk[blk].xlt2.vsis[vsi].changed = 1;
2914 /* Add new entry to the head of the VSIG list */
2915 tmp = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
2916 hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi =
2917 &hw->blk[blk].xlt2.vsis[vsi];
2918 hw->blk[blk].xlt2.vsis[vsi].next_vsi = tmp;
2919 hw->blk[blk].xlt2.t[vsi] = vsig;
2925 * ice_prof_has_mask_idx - determine if profile index masking is identical
2926 * @hw: pointer to the hardware structure
2928 * @prof: profile to check
2929 * @idx: profile index to check
2930 * @mask: mask to match
2933 ice_prof_has_mask_idx(struct ice_hw *hw, enum ice_block blk, u8 prof, u16 idx,
2936 bool expect_no_mask = false;
2941 /* If mask is 0x0000 or 0xffff, then there is no masking */
2942 if (mask == 0 || mask == 0xffff)
2943 expect_no_mask = true;
2945 /* Scan the enabled masks on this profile, for the specified idx */
2946 for (i = hw->blk[blk].masks.first; i < hw->blk[blk].masks.first +
2947 hw->blk[blk].masks.count; i++)
2948 if (hw->blk[blk].es.mask_ena[prof] & BIT(i))
2949 if (hw->blk[blk].masks.masks[i].in_use &&
2950 hw->blk[blk].masks.masks[i].idx == idx) {
2952 if (hw->blk[blk].masks.masks[i].mask == mask)
2957 if (expect_no_mask) {
2969 * ice_prof_has_mask - determine if profile masking is identical
2970 * @hw: pointer to the hardware structure
2972 * @prof: profile to check
2973 * @masks: masks to match
2976 ice_prof_has_mask(struct ice_hw *hw, enum ice_block blk, u8 prof, u16 *masks)
2980 /* es->mask_ena[prof] will have the mask */
2981 for (i = 0; i < hw->blk[blk].es.fvw; i++)
2982 if (!ice_prof_has_mask_idx(hw, blk, prof, i, masks[i]))
2989 * ice_find_prof_id_with_mask - find profile ID for a given field vector
2990 * @hw: pointer to the hardware structure
2992 * @fv: field vector to search for
2993 * @masks: masks for fv
2994 * @prof_id: receives the profile ID
2996 static enum ice_status
2997 ice_find_prof_id_with_mask(struct ice_hw *hw, enum ice_block blk,
2998 struct ice_fv_word *fv, u16 *masks, u8 *prof_id)
3000 struct ice_es *es = &hw->blk[blk].es;
3003 /* For FD and RSS, we don't want to re-use an existed profile with the
3004 * same field vector and mask. This will cause rule interference.
3006 if (blk == ICE_BLK_FD || blk == ICE_BLK_RSS)
3007 return ICE_ERR_DOES_NOT_EXIST;
3009 for (i = 0; i < (u8)es->count; i++) {
3010 u16 off = i * es->fvw;
3012 if (memcmp(&es->t[off], fv, es->fvw * sizeof(*fv)))
3015 /* check if masks settings are the same for this profile */
3016 if (masks && !ice_prof_has_mask(hw, blk, i, masks))
3023 return ICE_ERR_DOES_NOT_EXIST;
3027 * ice_prof_id_rsrc_type - get profile ID resource type for a block type
3028 * @blk: the block type
3029 * @rsrc_type: pointer to variable to receive the resource type
3031 static bool ice_prof_id_rsrc_type(enum ice_block blk, u16 *rsrc_type)
3035 *rsrc_type = ICE_AQC_RES_TYPE_SWITCH_PROF_BLDR_PROFID;
3038 *rsrc_type = ICE_AQC_RES_TYPE_ACL_PROF_BLDR_PROFID;
3041 *rsrc_type = ICE_AQC_RES_TYPE_FD_PROF_BLDR_PROFID;
3044 *rsrc_type = ICE_AQC_RES_TYPE_HASH_PROF_BLDR_PROFID;
3047 *rsrc_type = ICE_AQC_RES_TYPE_QHASH_PROF_BLDR_PROFID;
3056 * ice_tcam_ent_rsrc_type - get TCAM entry resource type for a block type
3057 * @blk: the block type
3058 * @rsrc_type: pointer to variable to receive the resource type
3060 static bool ice_tcam_ent_rsrc_type(enum ice_block blk, u16 *rsrc_type)
3064 *rsrc_type = ICE_AQC_RES_TYPE_SWITCH_PROF_BLDR_TCAM;
3067 *rsrc_type = ICE_AQC_RES_TYPE_ACL_PROF_BLDR_TCAM;
3070 *rsrc_type = ICE_AQC_RES_TYPE_FD_PROF_BLDR_TCAM;
3073 *rsrc_type = ICE_AQC_RES_TYPE_HASH_PROF_BLDR_TCAM;
3076 *rsrc_type = ICE_AQC_RES_TYPE_QHASH_PROF_BLDR_TCAM;
3085 * ice_alloc_tcam_ent - allocate hardware TCAM entry
3086 * @hw: pointer to the HW struct
3087 * @blk: the block to allocate the TCAM for
3088 * @btm: true to allocate from bottom of table, false to allocate from top
3089 * @tcam_idx: pointer to variable to receive the TCAM entry
3091 * This function allocates a new entry in a Profile ID TCAM for a specific
3094 static enum ice_status
3095 ice_alloc_tcam_ent(struct ice_hw *hw, enum ice_block blk, bool btm,
3100 if (!ice_tcam_ent_rsrc_type(blk, &res_type))
3101 return ICE_ERR_PARAM;
3103 return ice_alloc_hw_res(hw, res_type, 1, btm, tcam_idx);
3107 * ice_free_tcam_ent - free hardware TCAM entry
3108 * @hw: pointer to the HW struct
3109 * @blk: the block from which to free the TCAM entry
3110 * @tcam_idx: the TCAM entry to free
3112 * This function frees an entry in a Profile ID TCAM for a specific block.
3114 static enum ice_status
3115 ice_free_tcam_ent(struct ice_hw *hw, enum ice_block blk, u16 tcam_idx)
3119 if (!ice_tcam_ent_rsrc_type(blk, &res_type))
3120 return ICE_ERR_PARAM;
3122 return ice_free_hw_res(hw, res_type, 1, &tcam_idx);
3126 * ice_alloc_prof_id - allocate profile ID
3127 * @hw: pointer to the HW struct
3128 * @blk: the block to allocate the profile ID for
3129 * @prof_id: pointer to variable to receive the profile ID
3131 * This function allocates a new profile ID, which also corresponds to a Field
3132 * Vector (Extraction Sequence) entry.
3134 static enum ice_status
3135 ice_alloc_prof_id(struct ice_hw *hw, enum ice_block blk, u8 *prof_id)
3137 enum ice_status status;
3141 if (!ice_prof_id_rsrc_type(blk, &res_type))
3142 return ICE_ERR_PARAM;
3144 status = ice_alloc_hw_res(hw, res_type, 1, false, &get_prof);
3146 *prof_id = (u8)get_prof;
3152 * ice_free_prof_id - free profile ID
3153 * @hw: pointer to the HW struct
3154 * @blk: the block from which to free the profile ID
3155 * @prof_id: the profile ID to free
3157 * This function frees a profile ID, which also corresponds to a Field Vector.
3159 static enum ice_status
3160 ice_free_prof_id(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
3162 u16 tmp_prof_id = (u16)prof_id;
3165 if (!ice_prof_id_rsrc_type(blk, &res_type))
3166 return ICE_ERR_PARAM;
3168 return ice_free_hw_res(hw, res_type, 1, &tmp_prof_id);
3172 * ice_prof_inc_ref - increment reference count for profile
3173 * @hw: pointer to the HW struct
3174 * @blk: the block from which to free the profile ID
3175 * @prof_id: the profile ID for which to increment the reference count
3177 static enum ice_status
3178 ice_prof_inc_ref(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
3180 if (prof_id > hw->blk[blk].es.count)
3181 return ICE_ERR_PARAM;
3183 hw->blk[blk].es.ref_count[prof_id]++;
3189 * ice_write_prof_mask_reg - write profile mask register
3190 * @hw: pointer to the HW struct
3191 * @blk: hardware block
3192 * @mask_idx: mask index
3193 * @idx: index of the FV which will use the mask
3194 * @mask: the 16-bit mask
3197 ice_write_prof_mask_reg(struct ice_hw *hw, enum ice_block blk, u16 mask_idx,
3205 offset = GLQF_HMASK(mask_idx);
3206 val = (idx << GLQF_HMASK_MSK_INDEX_S) &
3207 GLQF_HMASK_MSK_INDEX_M;
3208 val |= (mask << GLQF_HMASK_MASK_S) & GLQF_HMASK_MASK_M;
3211 offset = GLQF_FDMASK(mask_idx);
3212 val = (idx << GLQF_FDMASK_MSK_INDEX_S) &
3213 GLQF_FDMASK_MSK_INDEX_M;
3214 val |= (mask << GLQF_FDMASK_MASK_S) &
3218 ice_debug(hw, ICE_DBG_PKG, "No profile masks for block %d\n",
3223 wr32(hw, offset, val);
3224 ice_debug(hw, ICE_DBG_PKG, "write mask, blk %d (%d): %x = %x\n",
3225 blk, idx, offset, val);
3229 * ice_write_prof_mask_enable_res - write profile mask enable register
3230 * @hw: pointer to the HW struct
3231 * @blk: hardware block
3232 * @prof_id: profile ID
3233 * @enable_mask: enable mask
3236 ice_write_prof_mask_enable_res(struct ice_hw *hw, enum ice_block blk,
3237 u16 prof_id, u32 enable_mask)
3243 offset = GLQF_HMASK_SEL(prof_id);
3246 offset = GLQF_FDMASK_SEL(prof_id);
3249 ice_debug(hw, ICE_DBG_PKG, "No profile masks for block %d\n",
3254 wr32(hw, offset, enable_mask);
3255 ice_debug(hw, ICE_DBG_PKG, "write mask enable, blk %d (%d): %x = %x\n",
3256 blk, prof_id, offset, enable_mask);
3260 * ice_init_prof_masks - initial prof masks
3261 * @hw: pointer to the HW struct
3262 * @blk: hardware block
3264 static void ice_init_prof_masks(struct ice_hw *hw, enum ice_block blk)
3269 ice_init_lock(&hw->blk[blk].masks.lock);
3271 per_pf = ICE_PROF_MASK_COUNT / hw->dev_caps.num_funcs;
3273 hw->blk[blk].masks.count = per_pf;
3274 hw->blk[blk].masks.first = hw->pf_id * per_pf;
3276 ice_memset(hw->blk[blk].masks.masks, 0,
3277 sizeof(hw->blk[blk].masks.masks), ICE_NONDMA_MEM);
3279 for (i = hw->blk[blk].masks.first;
3280 i < hw->blk[blk].masks.first + hw->blk[blk].masks.count; i++)
3281 ice_write_prof_mask_reg(hw, blk, i, 0, 0);
3285 * ice_init_all_prof_masks - initial all prof masks
3286 * @hw: pointer to the HW struct
3288 void ice_init_all_prof_masks(struct ice_hw *hw)
3290 ice_init_prof_masks(hw, ICE_BLK_RSS);
3291 ice_init_prof_masks(hw, ICE_BLK_FD);
3295 * ice_alloc_prof_mask - allocate profile mask
3296 * @hw: pointer to the HW struct
3297 * @blk: hardware block
3298 * @idx: index of FV which will use the mask
3299 * @mask: the 16-bit mask
3300 * @mask_idx: variable to receive the mask index
3302 static enum ice_status
3303 ice_alloc_prof_mask(struct ice_hw *hw, enum ice_block blk, u16 idx, u16 mask,
3306 bool found_unused = false, found_copy = false;
3307 enum ice_status status = ICE_ERR_MAX_LIMIT;
3308 u16 unused_idx = 0, copy_idx = 0;
3311 if (blk != ICE_BLK_RSS && blk != ICE_BLK_FD)
3312 return ICE_ERR_PARAM;
3314 ice_acquire_lock(&hw->blk[blk].masks.lock);
3316 for (i = hw->blk[blk].masks.first;
3317 i < hw->blk[blk].masks.first + hw->blk[blk].masks.count; i++)
3318 if (hw->blk[blk].masks.masks[i].in_use) {
3319 /* if mask is in use and it exactly duplicates the
3320 * desired mask and index, then in can be reused
3322 if (hw->blk[blk].masks.masks[i].mask == mask &&
3323 hw->blk[blk].masks.masks[i].idx == idx) {
3329 /* save off unused index, but keep searching in case
3330 * there is an exact match later on
3332 if (!found_unused) {
3333 found_unused = true;
3340 else if (found_unused)
3343 goto err_ice_alloc_prof_mask;
3345 /* update mask for a new entry */
3347 hw->blk[blk].masks.masks[i].in_use = true;
3348 hw->blk[blk].masks.masks[i].mask = mask;
3349 hw->blk[blk].masks.masks[i].idx = idx;
3350 hw->blk[blk].masks.masks[i].ref = 0;
3351 ice_write_prof_mask_reg(hw, blk, i, idx, mask);
3354 hw->blk[blk].masks.masks[i].ref++;
3356 status = ICE_SUCCESS;
3358 err_ice_alloc_prof_mask:
3359 ice_release_lock(&hw->blk[blk].masks.lock);
3365 * ice_free_prof_mask - free profile mask
3366 * @hw: pointer to the HW struct
3367 * @blk: hardware block
3368 * @mask_idx: index of mask
3370 static enum ice_status
3371 ice_free_prof_mask(struct ice_hw *hw, enum ice_block blk, u16 mask_idx)
3373 if (blk != ICE_BLK_RSS && blk != ICE_BLK_FD)
3374 return ICE_ERR_PARAM;
3376 if (!(mask_idx >= hw->blk[blk].masks.first &&
3377 mask_idx < hw->blk[blk].masks.first + hw->blk[blk].masks.count))
3378 return ICE_ERR_DOES_NOT_EXIST;
3380 ice_acquire_lock(&hw->blk[blk].masks.lock);
3382 if (!hw->blk[blk].masks.masks[mask_idx].in_use)
3383 goto exit_ice_free_prof_mask;
3385 if (hw->blk[blk].masks.masks[mask_idx].ref > 1) {
3386 hw->blk[blk].masks.masks[mask_idx].ref--;
3387 goto exit_ice_free_prof_mask;
3391 hw->blk[blk].masks.masks[mask_idx].in_use = false;
3392 hw->blk[blk].masks.masks[mask_idx].mask = 0;
3393 hw->blk[blk].masks.masks[mask_idx].idx = 0;
3395 /* update mask as unused entry */
3396 ice_debug(hw, ICE_DBG_PKG, "Free mask, blk %d, mask %d\n", blk,
3398 ice_write_prof_mask_reg(hw, blk, mask_idx, 0, 0);
3400 exit_ice_free_prof_mask:
3401 ice_release_lock(&hw->blk[blk].masks.lock);
3407 * ice_free_prof_masks - free all profile masks for a profile
3408 * @hw: pointer to the HW struct
3409 * @blk: hardware block
3410 * @prof_id: profile ID
3412 static enum ice_status
3413 ice_free_prof_masks(struct ice_hw *hw, enum ice_block blk, u16 prof_id)
3418 if (blk != ICE_BLK_RSS && blk != ICE_BLK_FD)
3419 return ICE_ERR_PARAM;
3421 mask_bm = hw->blk[blk].es.mask_ena[prof_id];
3422 for (i = 0; i < BITS_PER_BYTE * sizeof(mask_bm); i++)
3423 if (mask_bm & BIT(i))
3424 ice_free_prof_mask(hw, blk, i);
3430 * ice_shutdown_prof_masks - releases lock for masking
3431 * @hw: pointer to the HW struct
3432 * @blk: hardware block
3434 * This should be called before unloading the driver
3436 static void ice_shutdown_prof_masks(struct ice_hw *hw, enum ice_block blk)
3440 ice_acquire_lock(&hw->blk[blk].masks.lock);
3442 for (i = hw->blk[blk].masks.first;
3443 i < hw->blk[blk].masks.first + hw->blk[blk].masks.count; i++) {
3444 ice_write_prof_mask_reg(hw, blk, i, 0, 0);
3446 hw->blk[blk].masks.masks[i].in_use = false;
3447 hw->blk[blk].masks.masks[i].idx = 0;
3448 hw->blk[blk].masks.masks[i].mask = 0;
3451 ice_release_lock(&hw->blk[blk].masks.lock);
3452 ice_destroy_lock(&hw->blk[blk].masks.lock);
3456 * ice_shutdown_all_prof_masks - releases all locks for masking
3457 * @hw: pointer to the HW struct
3459 * This should be called before unloading the driver
3461 void ice_shutdown_all_prof_masks(struct ice_hw *hw)
3463 ice_shutdown_prof_masks(hw, ICE_BLK_RSS);
3464 ice_shutdown_prof_masks(hw, ICE_BLK_FD);
3468 * ice_update_prof_masking - set registers according to masking
3469 * @hw: pointer to the HW struct
3470 * @blk: hardware block
3471 * @prof_id: profile ID
3474 static enum ice_status
3475 ice_update_prof_masking(struct ice_hw *hw, enum ice_block blk, u16 prof_id,
3483 /* Only support FD and RSS masking, otherwise nothing to be done */
3484 if (blk != ICE_BLK_RSS && blk != ICE_BLK_FD)
3487 for (i = 0; i < hw->blk[blk].es.fvw; i++)
3488 if (masks[i] && masks[i] != 0xFFFF) {
3489 if (!ice_alloc_prof_mask(hw, blk, i, masks[i], &idx)) {
3490 ena_mask |= BIT(idx);
3492 /* not enough bitmaps */
3499 /* free any bitmaps we have allocated */
3500 for (i = 0; i < BITS_PER_BYTE * sizeof(ena_mask); i++)
3501 if (ena_mask & BIT(i))
3502 ice_free_prof_mask(hw, blk, i);
3504 return ICE_ERR_OUT_OF_RANGE;
3507 /* enable the masks for this profile */
3508 ice_write_prof_mask_enable_res(hw, blk, prof_id, ena_mask);
3510 /* store enabled masks with profile so that they can be freed later */
3511 hw->blk[blk].es.mask_ena[prof_id] = ena_mask;
3517 * ice_write_es - write an extraction sequence to hardware
3518 * @hw: pointer to the HW struct
3519 * @blk: the block in which to write the extraction sequence
3520 * @prof_id: the profile ID to write
3521 * @fv: pointer to the extraction sequence to write - NULL to clear extraction
3524 ice_write_es(struct ice_hw *hw, enum ice_block blk, u8 prof_id,
3525 struct ice_fv_word *fv)
3529 off = prof_id * hw->blk[blk].es.fvw;
3531 ice_memset(&hw->blk[blk].es.t[off], 0, hw->blk[blk].es.fvw *
3532 sizeof(*fv), ICE_NONDMA_MEM);
3533 hw->blk[blk].es.written[prof_id] = false;
3535 ice_memcpy(&hw->blk[blk].es.t[off], fv, hw->blk[blk].es.fvw *
3536 sizeof(*fv), ICE_NONDMA_TO_NONDMA);
3541 * ice_prof_dec_ref - decrement reference count for profile
3542 * @hw: pointer to the HW struct
3543 * @blk: the block from which to free the profile ID
3544 * @prof_id: the profile ID for which to decrement the reference count
3546 static enum ice_status
3547 ice_prof_dec_ref(struct ice_hw *hw, enum ice_block blk, u8 prof_id)
3549 if (prof_id > hw->blk[blk].es.count)
3550 return ICE_ERR_PARAM;
3552 if (hw->blk[blk].es.ref_count[prof_id] > 0) {
3553 if (!--hw->blk[blk].es.ref_count[prof_id]) {
3554 ice_write_es(hw, blk, prof_id, NULL);
3555 ice_free_prof_masks(hw, blk, prof_id);
3556 return ice_free_prof_id(hw, blk, prof_id);
3563 /* Block / table section IDs */
3564 static const u32 ice_blk_sids[ICE_BLK_COUNT][ICE_SID_OFF_COUNT] = {
3568 ICE_SID_PROFID_TCAM_SW,
3569 ICE_SID_PROFID_REDIR_SW,
3576 ICE_SID_PROFID_TCAM_ACL,
3577 ICE_SID_PROFID_REDIR_ACL,
3584 ICE_SID_PROFID_TCAM_FD,
3585 ICE_SID_PROFID_REDIR_FD,
3592 ICE_SID_PROFID_TCAM_RSS,
3593 ICE_SID_PROFID_REDIR_RSS,
3600 ICE_SID_PROFID_TCAM_PE,
3601 ICE_SID_PROFID_REDIR_PE,
3607 * ice_init_sw_xlt1_db - init software XLT1 database from HW tables
3608 * @hw: pointer to the hardware structure
3609 * @blk: the HW block to initialize
3611 static void ice_init_sw_xlt1_db(struct ice_hw *hw, enum ice_block blk)
3615 for (pt = 0; pt < hw->blk[blk].xlt1.count; pt++) {
3618 ptg = hw->blk[blk].xlt1.t[pt];
3619 if (ptg != ICE_DEFAULT_PTG) {
3620 ice_ptg_alloc_val(hw, blk, ptg);
3621 ice_ptg_add_mv_ptype(hw, blk, pt, ptg);
3627 * ice_init_sw_xlt2_db - init software XLT2 database from HW tables
3628 * @hw: pointer to the hardware structure
3629 * @blk: the HW block to initialize
3631 static void ice_init_sw_xlt2_db(struct ice_hw *hw, enum ice_block blk)
3635 for (vsi = 0; vsi < hw->blk[blk].xlt2.count; vsi++) {
3638 vsig = hw->blk[blk].xlt2.t[vsi];
3640 ice_vsig_alloc_val(hw, blk, vsig);
3641 ice_vsig_add_mv_vsi(hw, blk, vsi, vsig);
3642 /* no changes at this time, since this has been
3643 * initialized from the original package
3645 hw->blk[blk].xlt2.vsis[vsi].changed = 0;
3651 * ice_init_sw_db - init software database from HW tables
3652 * @hw: pointer to the hardware structure
3654 static void ice_init_sw_db(struct ice_hw *hw)
3658 for (i = 0; i < ICE_BLK_COUNT; i++) {
3659 ice_init_sw_xlt1_db(hw, (enum ice_block)i);
3660 ice_init_sw_xlt2_db(hw, (enum ice_block)i);
3665 * ice_fill_tbl - Reads content of a single table type into database
3666 * @hw: pointer to the hardware structure
3667 * @block_id: Block ID of the table to copy
3668 * @sid: Section ID of the table to copy
3670 * Will attempt to read the entire content of a given table of a single block
3671 * into the driver database. We assume that the buffer will always
3672 * be as large or larger than the data contained in the package. If
3673 * this condition is not met, there is most likely an error in the package
3676 static void ice_fill_tbl(struct ice_hw *hw, enum ice_block block_id, u32 sid)
3678 u32 dst_len, sect_len, offset = 0;
3679 struct ice_prof_redir_section *pr;
3680 struct ice_prof_id_section *pid;
3681 struct ice_xlt1_section *xlt1;
3682 struct ice_xlt2_section *xlt2;
3683 struct ice_sw_fv_section *es;
3684 struct ice_pkg_enum state;
3688 /* if the HW segment pointer is null then the first iteration of
3689 * ice_pkg_enum_section() will fail. In this case the HW tables will
3690 * not be filled and return success.
3693 ice_debug(hw, ICE_DBG_PKG, "hw->seg is NULL, tables are not filled\n");
3697 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
3699 sect = ice_pkg_enum_section(hw->seg, &state, sid);
3703 case ICE_SID_XLT1_SW:
3704 case ICE_SID_XLT1_FD:
3705 case ICE_SID_XLT1_RSS:
3706 case ICE_SID_XLT1_ACL:
3707 case ICE_SID_XLT1_PE:
3708 xlt1 = (struct ice_xlt1_section *)sect;
3710 sect_len = LE16_TO_CPU(xlt1->count) *
3711 sizeof(*hw->blk[block_id].xlt1.t);
3712 dst = hw->blk[block_id].xlt1.t;
3713 dst_len = hw->blk[block_id].xlt1.count *
3714 sizeof(*hw->blk[block_id].xlt1.t);
3716 case ICE_SID_XLT2_SW:
3717 case ICE_SID_XLT2_FD:
3718 case ICE_SID_XLT2_RSS:
3719 case ICE_SID_XLT2_ACL:
3720 case ICE_SID_XLT2_PE:
3721 xlt2 = (struct ice_xlt2_section *)sect;
3722 src = (_FORCE_ u8 *)xlt2->value;
3723 sect_len = LE16_TO_CPU(xlt2->count) *
3724 sizeof(*hw->blk[block_id].xlt2.t);
3725 dst = (u8 *)hw->blk[block_id].xlt2.t;
3726 dst_len = hw->blk[block_id].xlt2.count *
3727 sizeof(*hw->blk[block_id].xlt2.t);
3729 case ICE_SID_PROFID_TCAM_SW:
3730 case ICE_SID_PROFID_TCAM_FD:
3731 case ICE_SID_PROFID_TCAM_RSS:
3732 case ICE_SID_PROFID_TCAM_ACL:
3733 case ICE_SID_PROFID_TCAM_PE:
3734 pid = (struct ice_prof_id_section *)sect;
3735 src = (u8 *)pid->entry;
3736 sect_len = LE16_TO_CPU(pid->count) *
3737 sizeof(*hw->blk[block_id].prof.t);
3738 dst = (u8 *)hw->blk[block_id].prof.t;
3739 dst_len = hw->blk[block_id].prof.count *
3740 sizeof(*hw->blk[block_id].prof.t);
3742 case ICE_SID_PROFID_REDIR_SW:
3743 case ICE_SID_PROFID_REDIR_FD:
3744 case ICE_SID_PROFID_REDIR_RSS:
3745 case ICE_SID_PROFID_REDIR_ACL:
3746 case ICE_SID_PROFID_REDIR_PE:
3747 pr = (struct ice_prof_redir_section *)sect;
3748 src = pr->redir_value;
3749 sect_len = LE16_TO_CPU(pr->count) *
3750 sizeof(*hw->blk[block_id].prof_redir.t);
3751 dst = hw->blk[block_id].prof_redir.t;
3752 dst_len = hw->blk[block_id].prof_redir.count *
3753 sizeof(*hw->blk[block_id].prof_redir.t);
3755 case ICE_SID_FLD_VEC_SW:
3756 case ICE_SID_FLD_VEC_FD:
3757 case ICE_SID_FLD_VEC_RSS:
3758 case ICE_SID_FLD_VEC_ACL:
3759 case ICE_SID_FLD_VEC_PE:
3760 es = (struct ice_sw_fv_section *)sect;
3762 sect_len = (u32)(LE16_TO_CPU(es->count) *
3763 hw->blk[block_id].es.fvw) *
3764 sizeof(*hw->blk[block_id].es.t);
3765 dst = (u8 *)hw->blk[block_id].es.t;
3766 dst_len = (u32)(hw->blk[block_id].es.count *
3767 hw->blk[block_id].es.fvw) *
3768 sizeof(*hw->blk[block_id].es.t);
3774 /* if the section offset exceeds destination length, terminate
3777 if (offset > dst_len)
3780 /* if the sum of section size and offset exceed destination size
3781 * then we are out of bounds of the HW table size for that PF.
3782 * Changing section length to fill the remaining table space
3785 if ((offset + sect_len) > dst_len)
3786 sect_len = dst_len - offset;
3788 ice_memcpy(dst + offset, src, sect_len, ICE_NONDMA_TO_NONDMA);
3790 sect = ice_pkg_enum_section(NULL, &state, sid);
3795 * ice_fill_blk_tbls - Read package context for tables
3796 * @hw: pointer to the hardware structure
3798 * Reads the current package contents and populates the driver
3799 * database with the data iteratively for all advanced feature
3800 * blocks. Assume that the HW tables have been allocated.
3802 void ice_fill_blk_tbls(struct ice_hw *hw)
3806 for (i = 0; i < ICE_BLK_COUNT; i++) {
3807 enum ice_block blk_id = (enum ice_block)i;
3809 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].xlt1.sid);
3810 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].xlt2.sid);
3811 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].prof.sid);
3812 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].prof_redir.sid);
3813 ice_fill_tbl(hw, blk_id, hw->blk[blk_id].es.sid);
3820 * ice_free_prof_map - free profile map
3821 * @hw: pointer to the hardware structure
3822 * @blk_idx: HW block index
3824 static void ice_free_prof_map(struct ice_hw *hw, u8 blk_idx)
3826 struct ice_es *es = &hw->blk[blk_idx].es;
3827 struct ice_prof_map *del, *tmp;
3829 ice_acquire_lock(&es->prof_map_lock);
3830 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &es->prof_map,
3831 ice_prof_map, list) {
3832 LIST_DEL(&del->list);
3835 INIT_LIST_HEAD(&es->prof_map);
3836 ice_release_lock(&es->prof_map_lock);
3840 * ice_free_flow_profs - free flow profile entries
3841 * @hw: pointer to the hardware structure
3842 * @blk_idx: HW block index
3844 static void ice_free_flow_profs(struct ice_hw *hw, u8 blk_idx)
3846 struct ice_flow_prof *p, *tmp;
3848 ice_acquire_lock(&hw->fl_profs_locks[blk_idx]);
3849 LIST_FOR_EACH_ENTRY_SAFE(p, tmp, &hw->fl_profs[blk_idx],
3850 ice_flow_prof, l_entry) {
3851 struct ice_flow_entry *e, *t;
3853 LIST_FOR_EACH_ENTRY_SAFE(e, t, &p->entries,
3854 ice_flow_entry, l_entry)
3855 ice_flow_rem_entry(hw, (enum ice_block)blk_idx,
3856 ICE_FLOW_ENTRY_HNDL(e));
3858 LIST_DEL(&p->l_entry);
3860 ice_free(hw, p->acts);
3862 ice_destroy_lock(&p->entries_lock);
3865 ice_release_lock(&hw->fl_profs_locks[blk_idx]);
3867 /* if driver is in reset and tables are being cleared
3868 * re-initialize the flow profile list heads
3870 INIT_LIST_HEAD(&hw->fl_profs[blk_idx]);
3874 * ice_free_vsig_tbl - free complete VSIG table entries
3875 * @hw: pointer to the hardware structure
3876 * @blk: the HW block on which to free the VSIG table entries
3878 static void ice_free_vsig_tbl(struct ice_hw *hw, enum ice_block blk)
3882 if (!hw->blk[blk].xlt2.vsig_tbl)
3885 for (i = 1; i < ICE_MAX_VSIGS; i++)
3886 if (hw->blk[blk].xlt2.vsig_tbl[i].in_use)
3887 ice_vsig_free(hw, blk, i);
3891 * ice_free_hw_tbls - free hardware table memory
3892 * @hw: pointer to the hardware structure
3894 void ice_free_hw_tbls(struct ice_hw *hw)
3896 struct ice_rss_cfg *r, *rt;
3899 for (i = 0; i < ICE_BLK_COUNT; i++) {
3900 if (hw->blk[i].is_list_init) {
3901 struct ice_es *es = &hw->blk[i].es;
3903 ice_free_prof_map(hw, i);
3904 ice_destroy_lock(&es->prof_map_lock);
3905 ice_free_flow_profs(hw, i);
3906 ice_destroy_lock(&hw->fl_profs_locks[i]);
3908 hw->blk[i].is_list_init = false;
3910 ice_free_vsig_tbl(hw, (enum ice_block)i);
3911 ice_free(hw, hw->blk[i].xlt1.ptypes);
3912 ice_free(hw, hw->blk[i].xlt1.ptg_tbl);
3913 ice_free(hw, hw->blk[i].xlt1.t);
3914 ice_free(hw, hw->blk[i].xlt2.t);
3915 ice_free(hw, hw->blk[i].xlt2.vsig_tbl);
3916 ice_free(hw, hw->blk[i].xlt2.vsis);
3917 ice_free(hw, hw->blk[i].prof.t);
3918 ice_free(hw, hw->blk[i].prof_redir.t);
3919 ice_free(hw, hw->blk[i].es.t);
3920 ice_free(hw, hw->blk[i].es.ref_count);
3921 ice_free(hw, hw->blk[i].es.written);
3922 ice_free(hw, hw->blk[i].es.mask_ena);
3925 LIST_FOR_EACH_ENTRY_SAFE(r, rt, &hw->rss_list_head,
3926 ice_rss_cfg, l_entry) {
3927 LIST_DEL(&r->l_entry);
3930 ice_destroy_lock(&hw->rss_locks);
3931 if (!hw->dcf_enabled)
3932 ice_shutdown_all_prof_masks(hw);
3933 ice_memset(hw->blk, 0, sizeof(hw->blk), ICE_NONDMA_MEM);
3937 * ice_init_flow_profs - init flow profile locks and list heads
3938 * @hw: pointer to the hardware structure
3939 * @blk_idx: HW block index
3941 static void ice_init_flow_profs(struct ice_hw *hw, u8 blk_idx)
3943 ice_init_lock(&hw->fl_profs_locks[blk_idx]);
3944 INIT_LIST_HEAD(&hw->fl_profs[blk_idx]);
3948 * ice_clear_hw_tbls - clear HW tables and flow profiles
3949 * @hw: pointer to the hardware structure
3951 void ice_clear_hw_tbls(struct ice_hw *hw)
3955 for (i = 0; i < ICE_BLK_COUNT; i++) {
3956 struct ice_prof_redir *prof_redir = &hw->blk[i].prof_redir;
3957 struct ice_prof_tcam *prof = &hw->blk[i].prof;
3958 struct ice_xlt1 *xlt1 = &hw->blk[i].xlt1;
3959 struct ice_xlt2 *xlt2 = &hw->blk[i].xlt2;
3960 struct ice_es *es = &hw->blk[i].es;
3962 if (hw->blk[i].is_list_init) {
3963 ice_free_prof_map(hw, i);
3964 ice_free_flow_profs(hw, i);
3967 ice_free_vsig_tbl(hw, (enum ice_block)i);
3969 ice_memset(xlt1->ptypes, 0, xlt1->count * sizeof(*xlt1->ptypes),
3971 ice_memset(xlt1->ptg_tbl, 0,
3972 ICE_MAX_PTGS * sizeof(*xlt1->ptg_tbl),
3974 ice_memset(xlt1->t, 0, xlt1->count * sizeof(*xlt1->t),
3977 ice_memset(xlt2->vsis, 0, xlt2->count * sizeof(*xlt2->vsis),
3979 ice_memset(xlt2->vsig_tbl, 0,
3980 xlt2->count * sizeof(*xlt2->vsig_tbl),
3982 ice_memset(xlt2->t, 0, xlt2->count * sizeof(*xlt2->t),
3985 ice_memset(prof->t, 0, prof->count * sizeof(*prof->t),
3987 ice_memset(prof_redir->t, 0,
3988 prof_redir->count * sizeof(*prof_redir->t),
3991 ice_memset(es->t, 0, es->count * sizeof(*es->t) * es->fvw,
3993 ice_memset(es->ref_count, 0, es->count * sizeof(*es->ref_count),
3995 ice_memset(es->written, 0, es->count * sizeof(*es->written),
3997 ice_memset(es->mask_ena, 0, es->count * sizeof(*es->mask_ena),
4003 * ice_init_hw_tbls - init hardware table memory
4004 * @hw: pointer to the hardware structure
4006 enum ice_status ice_init_hw_tbls(struct ice_hw *hw)
4010 ice_init_lock(&hw->rss_locks);
4011 INIT_LIST_HEAD(&hw->rss_list_head);
4012 if (!hw->dcf_enabled)
4013 ice_init_all_prof_masks(hw);
4014 for (i = 0; i < ICE_BLK_COUNT; i++) {
4015 struct ice_prof_redir *prof_redir = &hw->blk[i].prof_redir;
4016 struct ice_prof_tcam *prof = &hw->blk[i].prof;
4017 struct ice_xlt1 *xlt1 = &hw->blk[i].xlt1;
4018 struct ice_xlt2 *xlt2 = &hw->blk[i].xlt2;
4019 struct ice_es *es = &hw->blk[i].es;
4022 if (hw->blk[i].is_list_init)
4025 ice_init_flow_profs(hw, i);
4026 ice_init_lock(&es->prof_map_lock);
4027 INIT_LIST_HEAD(&es->prof_map);
4028 hw->blk[i].is_list_init = true;
4030 hw->blk[i].overwrite = blk_sizes[i].overwrite;
4031 es->reverse = blk_sizes[i].reverse;
4033 xlt1->sid = ice_blk_sids[i][ICE_SID_XLT1_OFF];
4034 xlt1->count = blk_sizes[i].xlt1;
4036 xlt1->ptypes = (struct ice_ptg_ptype *)
4037 ice_calloc(hw, xlt1->count, sizeof(*xlt1->ptypes));
4042 xlt1->ptg_tbl = (struct ice_ptg_entry *)
4043 ice_calloc(hw, ICE_MAX_PTGS, sizeof(*xlt1->ptg_tbl));
4048 xlt1->t = (u8 *)ice_calloc(hw, xlt1->count, sizeof(*xlt1->t));
4052 xlt2->sid = ice_blk_sids[i][ICE_SID_XLT2_OFF];
4053 xlt2->count = blk_sizes[i].xlt2;
4055 xlt2->vsis = (struct ice_vsig_vsi *)
4056 ice_calloc(hw, xlt2->count, sizeof(*xlt2->vsis));
4061 xlt2->vsig_tbl = (struct ice_vsig_entry *)
4062 ice_calloc(hw, xlt2->count, sizeof(*xlt2->vsig_tbl));
4063 if (!xlt2->vsig_tbl)
4066 for (j = 0; j < xlt2->count; j++)
4067 INIT_LIST_HEAD(&xlt2->vsig_tbl[j].prop_lst);
4069 xlt2->t = (u16 *)ice_calloc(hw, xlt2->count, sizeof(*xlt2->t));
4073 prof->sid = ice_blk_sids[i][ICE_SID_PR_OFF];
4074 prof->count = blk_sizes[i].prof_tcam;
4075 prof->max_prof_id = blk_sizes[i].prof_id;
4076 prof->cdid_bits = blk_sizes[i].prof_cdid_bits;
4077 prof->t = (struct ice_prof_tcam_entry *)
4078 ice_calloc(hw, prof->count, sizeof(*prof->t));
4083 prof_redir->sid = ice_blk_sids[i][ICE_SID_PR_REDIR_OFF];
4084 prof_redir->count = blk_sizes[i].prof_redir;
4085 prof_redir->t = (u8 *)ice_calloc(hw, prof_redir->count,
4086 sizeof(*prof_redir->t));
4091 es->sid = ice_blk_sids[i][ICE_SID_ES_OFF];
4092 es->count = blk_sizes[i].es;
4093 es->fvw = blk_sizes[i].fvw;
4094 es->t = (struct ice_fv_word *)
4095 ice_calloc(hw, (u32)(es->count * es->fvw),
4100 es->ref_count = (u16 *)
4101 ice_calloc(hw, es->count, sizeof(*es->ref_count));
4106 es->written = (u8 *)
4107 ice_calloc(hw, es->count, sizeof(*es->written));
4112 es->mask_ena = (u32 *)
4113 ice_calloc(hw, es->count, sizeof(*es->mask_ena));
4121 ice_free_hw_tbls(hw);
4122 return ICE_ERR_NO_MEMORY;
4126 * ice_prof_gen_key - generate profile ID key
4127 * @hw: pointer to the HW struct
4128 * @blk: the block in which to write profile ID to
4129 * @ptg: packet type group (PTG) portion of key
4130 * @vsig: VSIG portion of key
4131 * @cdid: CDID portion of key
4132 * @flags: flag portion of key
4133 * @vl_msk: valid mask
4134 * @dc_msk: don't care mask
4135 * @nm_msk: never match mask
4136 * @key: output of profile ID key
4138 static enum ice_status
4139 ice_prof_gen_key(struct ice_hw *hw, enum ice_block blk, u8 ptg, u16 vsig,
4140 u8 cdid, u16 flags, u8 vl_msk[ICE_TCAM_KEY_VAL_SZ],
4141 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ], u8 nm_msk[ICE_TCAM_KEY_VAL_SZ],
4142 u8 key[ICE_TCAM_KEY_SZ])
4144 struct ice_prof_id_key inkey;
4147 inkey.xlt2_cdid = CPU_TO_LE16(vsig);
4148 inkey.flags = CPU_TO_LE16(flags);
4150 switch (hw->blk[blk].prof.cdid_bits) {
4154 #define ICE_CD_2_M 0xC000U
4155 #define ICE_CD_2_S 14
4156 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_2_M);
4157 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_2_S);
4160 #define ICE_CD_4_M 0xF000U
4161 #define ICE_CD_4_S 12
4162 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_4_M);
4163 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_4_S);
4166 #define ICE_CD_8_M 0xFF00U
4167 #define ICE_CD_8_S 16
4168 inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_8_M);
4169 inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_8_S);
4172 ice_debug(hw, ICE_DBG_PKG, "Error in profile config\n");
4176 return ice_set_key(key, ICE_TCAM_KEY_SZ, (u8 *)&inkey, vl_msk, dc_msk,
4177 nm_msk, 0, ICE_TCAM_KEY_SZ / 2);
4181 * ice_tcam_write_entry - write TCAM entry
4182 * @hw: pointer to the HW struct
4183 * @blk: the block in which to write profile ID to
4184 * @idx: the entry index to write to
4185 * @prof_id: profile ID
4186 * @ptg: packet type group (PTG) portion of key
4187 * @vsig: VSIG portion of key
4188 * @cdid: CDID portion of key
4189 * @flags: flag portion of key
4190 * @vl_msk: valid mask
4191 * @dc_msk: don't care mask
4192 * @nm_msk: never match mask
4194 static enum ice_status
4195 ice_tcam_write_entry(struct ice_hw *hw, enum ice_block blk, u16 idx,
4196 u8 prof_id, u8 ptg, u16 vsig, u8 cdid, u16 flags,
4197 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ],
4198 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ],
4199 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ])
4201 struct ice_prof_tcam_entry;
4202 enum ice_status status;
4204 status = ice_prof_gen_key(hw, blk, ptg, vsig, cdid, flags, vl_msk,
4205 dc_msk, nm_msk, hw->blk[blk].prof.t[idx].key);
4207 hw->blk[blk].prof.t[idx].addr = CPU_TO_LE16(idx);
4208 hw->blk[blk].prof.t[idx].prof_id = prof_id;
4215 * ice_vsig_get_ref - returns number of VSIs belong to a VSIG
4216 * @hw: pointer to the hardware structure
4218 * @vsig: VSIG to query
4219 * @refs: pointer to variable to receive the reference count
4221 static enum ice_status
4222 ice_vsig_get_ref(struct ice_hw *hw, enum ice_block blk, u16 vsig, u16 *refs)
4224 u16 idx = vsig & ICE_VSIG_IDX_M;
4225 struct ice_vsig_vsi *ptr;
4229 if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use)
4230 return ICE_ERR_DOES_NOT_EXIST;
4232 ptr = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
4235 ptr = ptr->next_vsi;
4242 * ice_has_prof_vsig - check to see if VSIG has a specific profile
4243 * @hw: pointer to the hardware structure
4245 * @vsig: VSIG to check against
4246 * @hdl: profile handle
4249 ice_has_prof_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl)
4251 u16 idx = vsig & ICE_VSIG_IDX_M;
4252 struct ice_vsig_prof *ent;
4254 LIST_FOR_EACH_ENTRY(ent, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4255 ice_vsig_prof, list)
4256 if (ent->profile_cookie == hdl)
4259 ice_debug(hw, ICE_DBG_INIT, "Characteristic list for VSI group %d not found.\n",
4265 * ice_prof_bld_es - build profile ID extraction sequence changes
4266 * @hw: pointer to the HW struct
4267 * @blk: hardware block
4268 * @bld: the update package buffer build to add to
4269 * @chgs: the list of changes to make in hardware
4271 static enum ice_status
4272 ice_prof_bld_es(struct ice_hw *hw, enum ice_block blk,
4273 struct ice_buf_build *bld, struct LIST_HEAD_TYPE *chgs)
4275 u16 vec_size = hw->blk[blk].es.fvw * sizeof(struct ice_fv_word);
4276 struct ice_chs_chg *tmp;
4278 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry)
4279 if (tmp->type == ICE_PTG_ES_ADD && tmp->add_prof) {
4280 u16 off = tmp->prof_id * hw->blk[blk].es.fvw;
4281 struct ice_pkg_es *p;
4284 id = ice_sect_id(blk, ICE_VEC_TBL);
4285 p = (struct ice_pkg_es *)
4286 ice_pkg_buf_alloc_section(bld, id,
4287 ice_struct_size(p, es,
4293 return ICE_ERR_MAX_LIMIT;
4295 p->count = CPU_TO_LE16(1);
4296 p->offset = CPU_TO_LE16(tmp->prof_id);
4298 ice_memcpy(p->es, &hw->blk[blk].es.t[off], vec_size,
4299 ICE_NONDMA_TO_NONDMA);
4306 * ice_prof_bld_tcam - build profile ID TCAM changes
4307 * @hw: pointer to the HW struct
4308 * @blk: hardware block
4309 * @bld: the update package buffer build to add to
4310 * @chgs: the list of changes to make in hardware
4312 static enum ice_status
4313 ice_prof_bld_tcam(struct ice_hw *hw, enum ice_block blk,
4314 struct ice_buf_build *bld, struct LIST_HEAD_TYPE *chgs)
4316 struct ice_chs_chg *tmp;
4318 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry)
4319 if (tmp->type == ICE_TCAM_ADD && tmp->add_tcam_idx) {
4320 struct ice_prof_id_section *p;
4323 id = ice_sect_id(blk, ICE_PROF_TCAM);
4324 p = (struct ice_prof_id_section *)
4325 ice_pkg_buf_alloc_section(bld, id,
4331 return ICE_ERR_MAX_LIMIT;
4333 p->count = CPU_TO_LE16(1);
4334 p->entry[0].addr = CPU_TO_LE16(tmp->tcam_idx);
4335 p->entry[0].prof_id = tmp->prof_id;
4337 ice_memcpy(p->entry[0].key,
4338 &hw->blk[blk].prof.t[tmp->tcam_idx].key,
4339 sizeof(hw->blk[blk].prof.t->key),
4340 ICE_NONDMA_TO_NONDMA);
4347 * ice_prof_bld_xlt1 - build XLT1 changes
4348 * @blk: hardware block
4349 * @bld: the update package buffer build to add to
4350 * @chgs: the list of changes to make in hardware
4352 static enum ice_status
4353 ice_prof_bld_xlt1(enum ice_block blk, struct ice_buf_build *bld,
4354 struct LIST_HEAD_TYPE *chgs)
4356 struct ice_chs_chg *tmp;
4358 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry)
4359 if (tmp->type == ICE_PTG_ES_ADD && tmp->add_ptg) {
4360 struct ice_xlt1_section *p;
4363 id = ice_sect_id(blk, ICE_XLT1);
4364 p = (struct ice_xlt1_section *)
4365 ice_pkg_buf_alloc_section(bld, id,
4371 return ICE_ERR_MAX_LIMIT;
4373 p->count = CPU_TO_LE16(1);
4374 p->offset = CPU_TO_LE16(tmp->ptype);
4375 p->value[0] = tmp->ptg;
4382 * ice_prof_bld_xlt2 - build XLT2 changes
4383 * @blk: hardware block
4384 * @bld: the update package buffer build to add to
4385 * @chgs: the list of changes to make in hardware
4387 static enum ice_status
4388 ice_prof_bld_xlt2(enum ice_block blk, struct ice_buf_build *bld,
4389 struct LIST_HEAD_TYPE *chgs)
4391 struct ice_chs_chg *tmp;
4393 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
4394 struct ice_xlt2_section *p;
4397 switch (tmp->type) {
4401 id = ice_sect_id(blk, ICE_XLT2);
4402 p = (struct ice_xlt2_section *)
4403 ice_pkg_buf_alloc_section(bld, id,
4409 return ICE_ERR_MAX_LIMIT;
4411 p->count = CPU_TO_LE16(1);
4412 p->offset = CPU_TO_LE16(tmp->vsi);
4413 p->value[0] = CPU_TO_LE16(tmp->vsig);
4424 * ice_upd_prof_hw - update hardware using the change list
4425 * @hw: pointer to the HW struct
4426 * @blk: hardware block
4427 * @chgs: the list of changes to make in hardware
4429 static enum ice_status
4430 ice_upd_prof_hw(struct ice_hw *hw, enum ice_block blk,
4431 struct LIST_HEAD_TYPE *chgs)
4433 struct ice_buf_build *b;
4434 struct ice_chs_chg *tmp;
4435 enum ice_status status;
4443 /* count number of sections we need */
4444 LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) {
4445 switch (tmp->type) {
4446 case ICE_PTG_ES_ADD:
4464 sects = xlt1 + xlt2 + tcam + es;
4469 /* Build update package buffer */
4470 b = ice_pkg_buf_alloc(hw);
4472 return ICE_ERR_NO_MEMORY;
4474 status = ice_pkg_buf_reserve_section(b, sects);
4478 /* Preserve order of table update: ES, TCAM, PTG, VSIG */
4480 status = ice_prof_bld_es(hw, blk, b, chgs);
4486 status = ice_prof_bld_tcam(hw, blk, b, chgs);
4492 status = ice_prof_bld_xlt1(blk, b, chgs);
4498 status = ice_prof_bld_xlt2(blk, b, chgs);
4503 /* After package buffer build check if the section count in buffer is
4504 * non-zero and matches the number of sections detected for package
4507 pkg_sects = ice_pkg_buf_get_active_sections(b);
4508 if (!pkg_sects || pkg_sects != sects) {
4509 status = ICE_ERR_INVAL_SIZE;
4513 /* update package */
4514 status = ice_update_pkg(hw, ice_pkg_buf(b), 1);
4515 if (status == ICE_ERR_AQ_ERROR)
4516 ice_debug(hw, ICE_DBG_INIT, "Unable to update HW profile\n");
4519 ice_pkg_buf_free(hw, b);
4524 * ice_update_fd_mask - set Flow Director Field Vector mask for a profile
4525 * @hw: pointer to the HW struct
4526 * @prof_id: profile ID
4527 * @mask_sel: mask select
4529 * This function enable any of the masks selected by the mask select parameter
4530 * for the profile specified.
4532 static void ice_update_fd_mask(struct ice_hw *hw, u16 prof_id, u32 mask_sel)
4534 wr32(hw, GLQF_FDMASK_SEL(prof_id), mask_sel);
4536 ice_debug(hw, ICE_DBG_INIT, "fd mask(%d): %x = %x\n", prof_id,
4537 GLQF_FDMASK_SEL(prof_id), mask_sel);
4540 struct ice_fd_src_dst_pair {
4546 static const struct ice_fd_src_dst_pair ice_fd_pairs[] = {
4547 /* These are defined in pairs */
4548 { ICE_PROT_IPV4_OF_OR_S, 2, 12 },
4549 { ICE_PROT_IPV4_OF_OR_S, 2, 16 },
4551 { ICE_PROT_IPV4_IL, 2, 12 },
4552 { ICE_PROT_IPV4_IL, 2, 16 },
4554 { ICE_PROT_IPV6_OF_OR_S, 8, 8 },
4555 { ICE_PROT_IPV6_OF_OR_S, 8, 24 },
4557 { ICE_PROT_IPV6_IL, 8, 8 },
4558 { ICE_PROT_IPV6_IL, 8, 24 },
4560 { ICE_PROT_TCP_IL, 1, 0 },
4561 { ICE_PROT_TCP_IL, 1, 2 },
4563 { ICE_PROT_UDP_OF, 1, 0 },
4564 { ICE_PROT_UDP_OF, 1, 2 },
4566 { ICE_PROT_UDP_IL_OR_S, 1, 0 },
4567 { ICE_PROT_UDP_IL_OR_S, 1, 2 },
4569 { ICE_PROT_SCTP_IL, 1, 0 },
4570 { ICE_PROT_SCTP_IL, 1, 2 }
4573 #define ICE_FD_SRC_DST_PAIR_COUNT ARRAY_SIZE(ice_fd_pairs)
4576 * ice_update_fd_swap - set register appropriately for a FD FV extraction
4577 * @hw: pointer to the HW struct
4578 * @prof_id: profile ID
4579 * @es: extraction sequence (length of array is determined by the block)
4581 static enum ice_status
4582 ice_update_fd_swap(struct ice_hw *hw, u16 prof_id, struct ice_fv_word *es)
4584 ice_declare_bitmap(pair_list, ICE_FD_SRC_DST_PAIR_COUNT);
4585 u8 pair_start[ICE_FD_SRC_DST_PAIR_COUNT] = { 0 };
4586 #define ICE_FD_FV_NOT_FOUND (-2)
4587 s8 first_free = ICE_FD_FV_NOT_FOUND;
4588 u8 used[ICE_MAX_FV_WORDS] = { 0 };
4593 ice_zero_bitmap(pair_list, ICE_FD_SRC_DST_PAIR_COUNT);
4595 /* This code assumes that the Flow Director field vectors are assigned
4596 * from the end of the FV indexes working towards the zero index, that
4597 * only complete fields will be included and will be consecutive, and
4598 * that there are no gaps between valid indexes.
4601 /* Determine swap fields present */
4602 for (i = 0; i < hw->blk[ICE_BLK_FD].es.fvw; i++) {
4603 /* Find the first free entry, assuming right to left population.
4604 * This is where we can start adding additional pairs if needed.
4606 if (first_free == ICE_FD_FV_NOT_FOUND && es[i].prot_id !=
4610 for (j = 0; j < ICE_FD_SRC_DST_PAIR_COUNT; j++)
4611 if (es[i].prot_id == ice_fd_pairs[j].prot_id &&
4612 es[i].off == ice_fd_pairs[j].off) {
4613 ice_set_bit(j, pair_list);
4618 orig_free = first_free;
4620 /* determine missing swap fields that need to be added */
4621 for (i = 0; i < ICE_FD_SRC_DST_PAIR_COUNT; i += 2) {
4622 u8 bit1 = ice_is_bit_set(pair_list, i + 1);
4623 u8 bit0 = ice_is_bit_set(pair_list, i);
4628 /* add the appropriate 'paired' entry */
4634 /* check for room */
4635 if (first_free + 1 < (s8)ice_fd_pairs[index].count)
4636 return ICE_ERR_MAX_LIMIT;
4638 /* place in extraction sequence */
4639 for (k = 0; k < ice_fd_pairs[index].count; k++) {
4640 es[first_free - k].prot_id =
4641 ice_fd_pairs[index].prot_id;
4642 es[first_free - k].off =
4643 ice_fd_pairs[index].off + (k * 2);
4646 return ICE_ERR_OUT_OF_RANGE;
4648 /* keep track of non-relevant fields */
4649 mask_sel |= BIT(first_free - k);
4652 pair_start[index] = first_free;
4653 first_free -= ice_fd_pairs[index].count;
4657 /* fill in the swap array */
4658 si = hw->blk[ICE_BLK_FD].es.fvw - 1;
4660 u8 indexes_used = 1;
4662 /* assume flat at this index */
4663 #define ICE_SWAP_VALID 0x80
4664 used[si] = si | ICE_SWAP_VALID;
4666 if (orig_free == ICE_FD_FV_NOT_FOUND || si <= orig_free) {
4671 /* check for a swap location */
4672 for (j = 0; j < ICE_FD_SRC_DST_PAIR_COUNT; j++)
4673 if (es[si].prot_id == ice_fd_pairs[j].prot_id &&
4674 es[si].off == ice_fd_pairs[j].off) {
4677 /* determine the appropriate matching field */
4678 idx = j + ((j % 2) ? -1 : 1);
4680 indexes_used = ice_fd_pairs[idx].count;
4681 for (k = 0; k < indexes_used; k++) {
4682 used[si - k] = (pair_start[idx] - k) |
4692 /* for each set of 4 swap and 4 inset indexes, write the appropriate
4695 for (j = 0; j < hw->blk[ICE_BLK_FD].es.fvw / 4; j++) {
4699 for (k = 0; k < 4; k++) {
4703 if (used[idx] && !(mask_sel & BIT(idx))) {
4704 raw_swap |= used[idx] << (k * BITS_PER_BYTE);
4705 #define ICE_INSET_DFLT 0x9f
4706 raw_in |= ICE_INSET_DFLT << (k * BITS_PER_BYTE);
4710 /* write the appropriate swap register set */
4711 wr32(hw, GLQF_FDSWAP(prof_id, j), raw_swap);
4713 ice_debug(hw, ICE_DBG_INIT, "swap wr(%d, %d): %x = %08x\n",
4714 prof_id, j, GLQF_FDSWAP(prof_id, j), raw_swap);
4716 /* write the appropriate inset register set */
4717 wr32(hw, GLQF_FDINSET(prof_id, j), raw_in);
4719 ice_debug(hw, ICE_DBG_INIT, "inset wr(%d, %d): %x = %08x\n",
4720 prof_id, j, GLQF_FDINSET(prof_id, j), raw_in);
4723 /* initially clear the mask select for this profile */
4724 ice_update_fd_mask(hw, prof_id, 0);
4729 /* The entries here needs to match the order of enum ice_ptype_attrib */
4730 static const struct ice_ptype_attrib_info ice_ptype_attributes[] = {
4731 { ICE_GTP_PDU_EH, ICE_GTP_PDU_FLAG_MASK },
4732 { ICE_GTP_SESSION, ICE_GTP_FLAGS_MASK },
4733 { ICE_GTP_DOWNLINK, ICE_GTP_FLAGS_MASK },
4734 { ICE_GTP_UPLINK, ICE_GTP_FLAGS_MASK },
4738 * ice_get_ptype_attrib_info - get ptype attribute information
4739 * @type: attribute type
4740 * @info: pointer to variable to the attribute information
4743 ice_get_ptype_attrib_info(enum ice_ptype_attrib_type type,
4744 struct ice_ptype_attrib_info *info)
4746 *info = ice_ptype_attributes[type];
4750 * ice_add_prof_attrib - add any PTG with attributes to profile
4751 * @prof: pointer to the profile to which PTG entries will be added
4752 * @ptg: PTG to be added
4753 * @ptype: PTYPE that needs to be looked up
4754 * @attr: array of attributes that will be considered
4755 * @attr_cnt: number of elements in the attribute array
4757 static enum ice_status
4758 ice_add_prof_attrib(struct ice_prof_map *prof, u8 ptg, u16 ptype,
4759 const struct ice_ptype_attributes *attr, u16 attr_cnt)
4764 for (i = 0; i < attr_cnt; i++) {
4765 if (attr[i].ptype == ptype) {
4768 prof->ptg[prof->ptg_cnt] = ptg;
4769 ice_get_ptype_attrib_info(attr[i].attrib,
4770 &prof->attr[prof->ptg_cnt]);
4772 if (++prof->ptg_cnt >= ICE_MAX_PTG_PER_PROFILE)
4773 return ICE_ERR_MAX_LIMIT;
4778 return ICE_ERR_DOES_NOT_EXIST;
4784 * ice_add_prof - add profile
4785 * @hw: pointer to the HW struct
4786 * @blk: hardware block
4787 * @id: profile tracking ID
4788 * @ptypes: array of bitmaps indicating ptypes (ICE_FLOW_PTYPE_MAX bits)
4789 * @attr: array of attributes
4790 * @attr_cnt: number of elements in attrib array
4791 * @es: extraction sequence (length of array is determined by the block)
4792 * @masks: mask for extraction sequence
4794 * This function registers a profile, which matches a set of PTYPES with a
4795 * particular extraction sequence. While the hardware profile is allocated
4796 * it will not be written until the first call to ice_add_flow that specifies
4797 * the ID value used here.
4800 ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64 id, u8 ptypes[],
4801 const struct ice_ptype_attributes *attr, u16 attr_cnt,
4802 struct ice_fv_word *es, u16 *masks)
4804 u32 bytes = DIVIDE_AND_ROUND_UP(ICE_FLOW_PTYPE_MAX, BITS_PER_BYTE);
4805 ice_declare_bitmap(ptgs_used, ICE_XLT1_CNT);
4806 struct ice_prof_map *prof;
4807 enum ice_status status;
4811 ice_zero_bitmap(ptgs_used, ICE_XLT1_CNT);
4813 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
4815 /* search for existing profile */
4816 status = ice_find_prof_id_with_mask(hw, blk, es, masks, &prof_id);
4818 /* allocate profile ID */
4819 status = ice_alloc_prof_id(hw, blk, &prof_id);
4821 goto err_ice_add_prof;
4822 if (blk == ICE_BLK_FD) {
4823 /* For Flow Director block, the extraction sequence may
4824 * need to be altered in the case where there are paired
4825 * fields that have no match. This is necessary because
4826 * for Flow Director, src and dest fields need to paired
4827 * for filter programming and these values are swapped
4830 status = ice_update_fd_swap(hw, prof_id, es);
4832 goto err_ice_add_prof;
4834 status = ice_update_prof_masking(hw, blk, prof_id, masks);
4836 goto err_ice_add_prof;
4838 /* and write new es */
4839 ice_write_es(hw, blk, prof_id, es);
4842 ice_prof_inc_ref(hw, blk, prof_id);
4844 /* add profile info */
4846 prof = (struct ice_prof_map *)ice_malloc(hw, sizeof(*prof));
4848 goto err_ice_add_prof;
4850 prof->profile_cookie = id;
4851 prof->prof_id = prof_id;
4855 /* build list of ptgs */
4856 while (bytes && prof->ptg_cnt < ICE_MAX_PTG_PER_PROFILE) {
4859 if (!ptypes[byte]) {
4865 /* Examine 8 bits per byte */
4866 ice_for_each_set_bit(bit, (ice_bitmap_t *)&ptypes[byte],
4871 ptype = byte * BITS_PER_BYTE + bit;
4873 /* The package should place all ptypes in a non-zero
4874 * PTG, so the following call should never fail.
4876 if (ice_ptg_find_ptype(hw, blk, ptype, &ptg))
4879 /* If PTG is already added, skip and continue */
4880 if (ice_is_bit_set(ptgs_used, ptg))
4883 ice_set_bit(ptg, ptgs_used);
4884 /* Check to see there are any attributes for this
4885 * ptype, and add them if found.
4887 status = ice_add_prof_attrib(prof, ptg, ptype, attr,
4889 if (status == ICE_ERR_MAX_LIMIT)
4892 /* This is simple a ptype/PTG with no
4895 prof->ptg[prof->ptg_cnt] = ptg;
4896 prof->attr[prof->ptg_cnt].flags = 0;
4897 prof->attr[prof->ptg_cnt].mask = 0;
4899 if (++prof->ptg_cnt >= ICE_MAX_PTG_PER_PROFILE)
4908 LIST_ADD(&prof->list, &hw->blk[blk].es.prof_map);
4909 status = ICE_SUCCESS;
4912 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
4917 * ice_search_prof_id - Search for a profile tracking ID
4918 * @hw: pointer to the HW struct
4919 * @blk: hardware block
4920 * @id: profile tracking ID
4922 * This will search for a profile tracking ID which was previously added.
4923 * The profile map lock should be held before calling this function.
4925 struct ice_prof_map *
4926 ice_search_prof_id(struct ice_hw *hw, enum ice_block blk, u64 id)
4928 struct ice_prof_map *entry = NULL;
4929 struct ice_prof_map *map;
4931 LIST_FOR_EACH_ENTRY(map, &hw->blk[blk].es.prof_map, ice_prof_map, list)
4932 if (map->profile_cookie == id) {
4941 * ice_vsig_prof_id_count - count profiles in a VSIG
4942 * @hw: pointer to the HW struct
4943 * @blk: hardware block
4944 * @vsig: VSIG to remove the profile from
4947 ice_vsig_prof_id_count(struct ice_hw *hw, enum ice_block blk, u16 vsig)
4949 u16 idx = vsig & ICE_VSIG_IDX_M, count = 0;
4950 struct ice_vsig_prof *p;
4952 LIST_FOR_EACH_ENTRY(p, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
4953 ice_vsig_prof, list)
4960 * ice_rel_tcam_idx - release a TCAM index
4961 * @hw: pointer to the HW struct
4962 * @blk: hardware block
4963 * @idx: the index to release
4965 static enum ice_status
4966 ice_rel_tcam_idx(struct ice_hw *hw, enum ice_block blk, u16 idx)
4968 /* Masks to invoke a never match entry */
4969 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4970 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFE, 0xFF, 0xFF, 0xFF, 0xFF };
4971 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x01, 0x00, 0x00, 0x00, 0x00 };
4972 enum ice_status status;
4974 /* write the TCAM entry */
4975 status = ice_tcam_write_entry(hw, blk, idx, 0, 0, 0, 0, 0, vl_msk,
4980 /* release the TCAM entry */
4981 status = ice_free_tcam_ent(hw, blk, idx);
4987 * ice_rem_prof_id - remove one profile from a VSIG
4988 * @hw: pointer to the HW struct
4989 * @blk: hardware block
4990 * @prof: pointer to profile structure to remove
4992 static enum ice_status
4993 ice_rem_prof_id(struct ice_hw *hw, enum ice_block blk,
4994 struct ice_vsig_prof *prof)
4996 enum ice_status status;
4999 for (i = 0; i < prof->tcam_count; i++)
5000 if (prof->tcam[i].in_use) {
5001 prof->tcam[i].in_use = false;
5002 status = ice_rel_tcam_idx(hw, blk,
5003 prof->tcam[i].tcam_idx);
5005 return ICE_ERR_HW_TABLE;
5012 * ice_rem_vsig - remove VSIG
5013 * @hw: pointer to the HW struct
5014 * @blk: hardware block
5015 * @vsig: the VSIG to remove
5016 * @chg: the change list
5018 static enum ice_status
5019 ice_rem_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig,
5020 struct LIST_HEAD_TYPE *chg)
5022 u16 idx = vsig & ICE_VSIG_IDX_M;
5023 struct ice_vsig_vsi *vsi_cur;
5024 struct ice_vsig_prof *d, *t;
5025 enum ice_status status;
5027 /* remove TCAM entries */
5028 LIST_FOR_EACH_ENTRY_SAFE(d, t,
5029 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
5030 ice_vsig_prof, list) {
5031 status = ice_rem_prof_id(hw, blk, d);
5039 /* Move all VSIS associated with this VSIG to the default VSIG */
5040 vsi_cur = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi;
5041 /* If the VSIG has at least 1 VSI then iterate through the list
5042 * and remove the VSIs before deleting the group.
5046 struct ice_vsig_vsi *tmp = vsi_cur->next_vsi;
5047 struct ice_chs_chg *p;
5049 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5051 return ICE_ERR_NO_MEMORY;
5053 p->type = ICE_VSIG_REM;
5054 p->orig_vsig = vsig;
5055 p->vsig = ICE_DEFAULT_VSIG;
5056 p->vsi = vsi_cur - hw->blk[blk].xlt2.vsis;
5058 LIST_ADD(&p->list_entry, chg);
5063 return ice_vsig_free(hw, blk, vsig);
5067 * ice_rem_prof_id_vsig - remove a specific profile from a VSIG
5068 * @hw: pointer to the HW struct
5069 * @blk: hardware block
5070 * @vsig: VSIG to remove the profile from
5071 * @hdl: profile handle indicating which profile to remove
5072 * @chg: list to receive a record of changes
5074 static enum ice_status
5075 ice_rem_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl,
5076 struct LIST_HEAD_TYPE *chg)
5078 u16 idx = vsig & ICE_VSIG_IDX_M;
5079 struct ice_vsig_prof *p, *t;
5080 enum ice_status status;
5082 LIST_FOR_EACH_ENTRY_SAFE(p, t,
5083 &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
5084 ice_vsig_prof, list)
5085 if (p->profile_cookie == hdl) {
5086 if (ice_vsig_prof_id_count(hw, blk, vsig) == 1)
5087 /* this is the last profile, remove the VSIG */
5088 return ice_rem_vsig(hw, blk, vsig, chg);
5090 status = ice_rem_prof_id(hw, blk, p);
5098 return ICE_ERR_DOES_NOT_EXIST;
5102 * ice_rem_flow_all - remove all flows with a particular profile
5103 * @hw: pointer to the HW struct
5104 * @blk: hardware block
5105 * @id: profile tracking ID
5107 static enum ice_status
5108 ice_rem_flow_all(struct ice_hw *hw, enum ice_block blk, u64 id)
5110 struct ice_chs_chg *del, *tmp;
5111 struct LIST_HEAD_TYPE chg;
5112 enum ice_status status;
5115 INIT_LIST_HEAD(&chg);
5117 for (i = 1; i < ICE_MAX_VSIGS; i++)
5118 if (hw->blk[blk].xlt2.vsig_tbl[i].in_use) {
5119 if (ice_has_prof_vsig(hw, blk, i, id)) {
5120 status = ice_rem_prof_id_vsig(hw, blk, i, id,
5123 goto err_ice_rem_flow_all;
5127 status = ice_upd_prof_hw(hw, blk, &chg);
5129 err_ice_rem_flow_all:
5130 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
5131 LIST_DEL(&del->list_entry);
5139 * ice_rem_prof - remove profile
5140 * @hw: pointer to the HW struct
5141 * @blk: hardware block
5142 * @id: profile tracking ID
5144 * This will remove the profile specified by the ID parameter, which was
5145 * previously created through ice_add_prof. If any existing entries
5146 * are associated with this profile, they will be removed as well.
5148 enum ice_status ice_rem_prof(struct ice_hw *hw, enum ice_block blk, u64 id)
5150 struct ice_prof_map *pmap;
5151 enum ice_status status;
5153 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
5155 pmap = ice_search_prof_id(hw, blk, id);
5157 status = ICE_ERR_DOES_NOT_EXIST;
5158 goto err_ice_rem_prof;
5161 /* remove all flows with this profile */
5162 status = ice_rem_flow_all(hw, blk, pmap->profile_cookie);
5164 goto err_ice_rem_prof;
5166 /* dereference profile, and possibly remove */
5167 ice_prof_dec_ref(hw, blk, pmap->prof_id);
5169 LIST_DEL(&pmap->list);
5173 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
5178 * ice_get_prof - get profile
5179 * @hw: pointer to the HW struct
5180 * @blk: hardware block
5181 * @hdl: profile handle
5184 static enum ice_status
5185 ice_get_prof(struct ice_hw *hw, enum ice_block blk, u64 hdl,
5186 struct LIST_HEAD_TYPE *chg)
5188 enum ice_status status = ICE_SUCCESS;
5189 struct ice_prof_map *map;
5190 struct ice_chs_chg *p;
5193 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
5194 /* Get the details on the profile specified by the handle ID */
5195 map = ice_search_prof_id(hw, blk, hdl);
5197 status = ICE_ERR_DOES_NOT_EXIST;
5198 goto err_ice_get_prof;
5201 for (i = 0; i < map->ptg_cnt; i++)
5202 if (!hw->blk[blk].es.written[map->prof_id]) {
5203 /* add ES to change list */
5204 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5206 status = ICE_ERR_NO_MEMORY;
5207 goto err_ice_get_prof;
5210 p->type = ICE_PTG_ES_ADD;
5212 p->ptg = map->ptg[i];
5213 p->attr = map->attr[i];
5217 p->prof_id = map->prof_id;
5219 hw->blk[blk].es.written[map->prof_id] = true;
5221 LIST_ADD(&p->list_entry, chg);
5225 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
5226 /* let caller clean up the change list */
5231 * ice_get_profs_vsig - get a copy of the list of profiles from a VSIG
5232 * @hw: pointer to the HW struct
5233 * @blk: hardware block
5234 * @vsig: VSIG from which to copy the list
5237 * This routine makes a copy of the list of profiles in the specified VSIG.
5239 static enum ice_status
5240 ice_get_profs_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig,
5241 struct LIST_HEAD_TYPE *lst)
5243 struct ice_vsig_prof *ent1, *ent2;
5244 u16 idx = vsig & ICE_VSIG_IDX_M;
5246 LIST_FOR_EACH_ENTRY(ent1, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
5247 ice_vsig_prof, list) {
5248 struct ice_vsig_prof *p;
5250 /* copy to the input list */
5251 p = (struct ice_vsig_prof *)ice_memdup(hw, ent1, sizeof(*p),
5252 ICE_NONDMA_TO_NONDMA);
5254 goto err_ice_get_profs_vsig;
5256 LIST_ADD_TAIL(&p->list, lst);
5261 err_ice_get_profs_vsig:
5262 LIST_FOR_EACH_ENTRY_SAFE(ent1, ent2, lst, ice_vsig_prof, list) {
5263 LIST_DEL(&ent1->list);
5267 return ICE_ERR_NO_MEMORY;
5271 * ice_add_prof_to_lst - add profile entry to a list
5272 * @hw: pointer to the HW struct
5273 * @blk: hardware block
5274 * @lst: the list to be added to
5275 * @hdl: profile handle of entry to add
5277 static enum ice_status
5278 ice_add_prof_to_lst(struct ice_hw *hw, enum ice_block blk,
5279 struct LIST_HEAD_TYPE *lst, u64 hdl)
5281 enum ice_status status = ICE_SUCCESS;
5282 struct ice_prof_map *map;
5283 struct ice_vsig_prof *p;
5286 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
5287 map = ice_search_prof_id(hw, blk, hdl);
5289 status = ICE_ERR_DOES_NOT_EXIST;
5290 goto err_ice_add_prof_to_lst;
5293 p = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*p));
5295 status = ICE_ERR_NO_MEMORY;
5296 goto err_ice_add_prof_to_lst;
5299 p->profile_cookie = map->profile_cookie;
5300 p->prof_id = map->prof_id;
5301 p->tcam_count = map->ptg_cnt;
5303 for (i = 0; i < map->ptg_cnt; i++) {
5304 p->tcam[i].prof_id = map->prof_id;
5305 p->tcam[i].tcam_idx = ICE_INVALID_TCAM;
5306 p->tcam[i].ptg = map->ptg[i];
5307 p->tcam[i].attr = map->attr[i];
5310 LIST_ADD(&p->list, lst);
5312 err_ice_add_prof_to_lst:
5313 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
5318 * ice_move_vsi - move VSI to another VSIG
5319 * @hw: pointer to the HW struct
5320 * @blk: hardware block
5321 * @vsi: the VSI to move
5322 * @vsig: the VSIG to move the VSI to
5323 * @chg: the change list
5325 static enum ice_status
5326 ice_move_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig,
5327 struct LIST_HEAD_TYPE *chg)
5329 enum ice_status status;
5330 struct ice_chs_chg *p;
5333 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5335 return ICE_ERR_NO_MEMORY;
5337 status = ice_vsig_find_vsi(hw, blk, vsi, &orig_vsig);
5339 status = ice_vsig_add_mv_vsi(hw, blk, vsi, vsig);
5346 p->type = ICE_VSI_MOVE;
5348 p->orig_vsig = orig_vsig;
5351 LIST_ADD(&p->list_entry, chg);
5357 * ice_set_tcam_flags - set TCAM flag don't care mask
5358 * @mask: mask for flags
5359 * @dc_mask: pointer to the don't care mask
5361 static void ice_set_tcam_flags(u16 mask, u8 dc_mask[ICE_TCAM_KEY_VAL_SZ])
5365 /* flags are lowest u16 */
5366 flag_word = (u16 *)dc_mask;
5371 * ice_rem_chg_tcam_ent - remove a specific TCAM entry from change list
5372 * @hw: pointer to the HW struct
5373 * @idx: the index of the TCAM entry to remove
5374 * @chg: the list of change structures to search
5377 ice_rem_chg_tcam_ent(struct ice_hw *hw, u16 idx, struct LIST_HEAD_TYPE *chg)
5379 struct ice_chs_chg *pos, *tmp;
5381 LIST_FOR_EACH_ENTRY_SAFE(tmp, pos, chg, ice_chs_chg, list_entry)
5382 if (tmp->type == ICE_TCAM_ADD && tmp->tcam_idx == idx) {
5383 LIST_DEL(&tmp->list_entry);
5389 * ice_prof_tcam_ena_dis - add enable or disable TCAM change
5390 * @hw: pointer to the HW struct
5391 * @blk: hardware block
5392 * @enable: true to enable, false to disable
5393 * @vsig: the VSIG of the TCAM entry
5394 * @tcam: pointer the TCAM info structure of the TCAM to disable
5395 * @chg: the change list
5397 * This function appends an enable or disable TCAM entry in the change log
5399 static enum ice_status
5400 ice_prof_tcam_ena_dis(struct ice_hw *hw, enum ice_block blk, bool enable,
5401 u16 vsig, struct ice_tcam_inf *tcam,
5402 struct LIST_HEAD_TYPE *chg)
5404 enum ice_status status;
5405 struct ice_chs_chg *p;
5407 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
5408 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0x00, 0x00, 0x00 };
5409 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
5411 /* if disabling, free the TCAM */
5413 status = ice_rel_tcam_idx(hw, blk, tcam->tcam_idx);
5415 /* if we have already created a change for this TCAM entry, then
5416 * we need to remove that entry, in order to prevent writing to
5417 * a TCAM entry we no longer will have ownership of.
5419 ice_rem_chg_tcam_ent(hw, tcam->tcam_idx, chg);
5425 /* for re-enabling, reallocate a TCAM */
5426 /* for entries with empty attribute masks, allocate entry from
5427 * the bottom of the TCAM table; otherwise, allocate from the
5428 * top of the table in order to give it higher priority
5430 status = ice_alloc_tcam_ent(hw, blk, tcam->attr.mask == 0,
5435 /* add TCAM to change list */
5436 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5438 return ICE_ERR_NO_MEMORY;
5440 /* set don't care masks for TCAM flags */
5441 ice_set_tcam_flags(tcam->attr.mask, dc_msk);
5443 status = ice_tcam_write_entry(hw, blk, tcam->tcam_idx, tcam->prof_id,
5444 tcam->ptg, vsig, 0, tcam->attr.flags,
5445 vl_msk, dc_msk, nm_msk);
5447 goto err_ice_prof_tcam_ena_dis;
5451 p->type = ICE_TCAM_ADD;
5452 p->add_tcam_idx = true;
5453 p->prof_id = tcam->prof_id;
5456 p->tcam_idx = tcam->tcam_idx;
5459 LIST_ADD(&p->list_entry, chg);
5463 err_ice_prof_tcam_ena_dis:
5469 * ice_ptg_attr_in_use - determine if PTG and attribute pair is in use
5470 * @ptg_attr: pointer to the PTG and attribute pair to check
5471 * @ptgs_used: bitmap that denotes which PTGs are in use
5472 * @attr_used: array of PTG and attributes pairs already used
5473 * @attr_cnt: count of entries in the attr_used array
5476 ice_ptg_attr_in_use(struct ice_tcam_inf *ptg_attr, ice_bitmap_t *ptgs_used,
5477 struct ice_tcam_inf *attr_used[], u16 attr_cnt)
5481 if (!ice_is_bit_set(ptgs_used, ptg_attr->ptg))
5484 /* the PTG is used, so now look for correct attributes */
5485 for (i = 0; i < attr_cnt; i++)
5486 if (attr_used[i]->ptg == ptg_attr->ptg &&
5487 attr_used[i]->attr.flags == ptg_attr->attr.flags &&
5488 attr_used[i]->attr.mask == ptg_attr->attr.mask)
5495 * ice_adj_prof_priorities - adjust profile based on priorities
5496 * @hw: pointer to the HW struct
5497 * @blk: hardware block
5498 * @vsig: the VSIG for which to adjust profile priorities
5499 * @chg: the change list
5501 static enum ice_status
5502 ice_adj_prof_priorities(struct ice_hw *hw, enum ice_block blk, u16 vsig,
5503 struct LIST_HEAD_TYPE *chg)
5505 ice_declare_bitmap(ptgs_used, ICE_XLT1_CNT);
5506 struct ice_tcam_inf **attr_used;
5507 enum ice_status status = ICE_SUCCESS;
5508 struct ice_vsig_prof *t;
5509 u16 attr_used_cnt = 0;
5512 #define ICE_MAX_PTG_ATTRS 1024
5513 attr_used = (struct ice_tcam_inf **)ice_calloc(hw, ICE_MAX_PTG_ATTRS,
5514 sizeof(*attr_used));
5516 return ICE_ERR_NO_MEMORY;
5518 ice_zero_bitmap(ptgs_used, ICE_XLT1_CNT);
5519 idx = vsig & ICE_VSIG_IDX_M;
5521 /* Priority is based on the order in which the profiles are added. The
5522 * newest added profile has highest priority and the oldest added
5523 * profile has the lowest priority. Since the profile property list for
5524 * a VSIG is sorted from newest to oldest, this code traverses the list
5525 * in order and enables the first of each PTG that it finds (that is not
5526 * already enabled); it also disables any duplicate PTGs that it finds
5527 * in the older profiles (that are currently enabled).
5530 LIST_FOR_EACH_ENTRY(t, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst,
5531 ice_vsig_prof, list) {
5534 for (i = 0; i < t->tcam_count; i++) {
5537 /* Scan the priorities from newest to oldest.
5538 * Make sure that the newest profiles take priority.
5540 used = ice_ptg_attr_in_use(&t->tcam[i], ptgs_used,
5541 attr_used, attr_used_cnt);
5543 if (used && t->tcam[i].in_use) {
5544 /* need to mark this PTG as never match, as it
5545 * was already in use and therefore duplicate
5546 * (and lower priority)
5548 status = ice_prof_tcam_ena_dis(hw, blk, false,
5553 goto err_ice_adj_prof_priorities;
5554 } else if (!used && !t->tcam[i].in_use) {
5555 /* need to enable this PTG, as it in not in use
5556 * and not enabled (highest priority)
5558 status = ice_prof_tcam_ena_dis(hw, blk, true,
5563 goto err_ice_adj_prof_priorities;
5566 /* keep track of used ptgs */
5567 ice_set_bit(t->tcam[i].ptg, ptgs_used);
5568 if (attr_used_cnt < ICE_MAX_PTG_ATTRS)
5569 attr_used[attr_used_cnt++] = &t->tcam[i];
5571 ice_debug(hw, ICE_DBG_INIT, "Warn: ICE_MAX_PTG_ATTRS exceeded\n");
5575 err_ice_adj_prof_priorities:
5576 ice_free(hw, attr_used);
5581 * ice_add_prof_id_vsig - add profile to VSIG
5582 * @hw: pointer to the HW struct
5583 * @blk: hardware block
5584 * @vsig: the VSIG to which this profile is to be added
5585 * @hdl: the profile handle indicating the profile to add
5586 * @rev: true to add entries to the end of the list
5587 * @chg: the change list
5589 static enum ice_status
5590 ice_add_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl,
5591 bool rev, struct LIST_HEAD_TYPE *chg)
5593 /* Masks that ignore flags */
5594 u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
5595 u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0x00, 0x00, 0x00 };
5596 u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
5597 enum ice_status status = ICE_SUCCESS;
5598 struct ice_prof_map *map;
5599 struct ice_vsig_prof *t;
5600 struct ice_chs_chg *p;
5603 /* Error, if this VSIG already has this profile */
5604 if (ice_has_prof_vsig(hw, blk, vsig, hdl))
5605 return ICE_ERR_ALREADY_EXISTS;
5607 /* new VSIG profile structure */
5608 t = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*t));
5610 return ICE_ERR_NO_MEMORY;
5612 ice_acquire_lock(&hw->blk[blk].es.prof_map_lock);
5613 /* Get the details on the profile specified by the handle ID */
5614 map = ice_search_prof_id(hw, blk, hdl);
5616 status = ICE_ERR_DOES_NOT_EXIST;
5617 goto err_ice_add_prof_id_vsig;
5620 t->profile_cookie = map->profile_cookie;
5621 t->prof_id = map->prof_id;
5622 t->tcam_count = map->ptg_cnt;
5624 /* create TCAM entries */
5625 for (i = 0; i < map->ptg_cnt; i++) {
5628 /* add TCAM to change list */
5629 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5631 status = ICE_ERR_NO_MEMORY;
5632 goto err_ice_add_prof_id_vsig;
5635 /* allocate the TCAM entry index */
5636 /* for entries with empty attribute masks, allocate entry from
5637 * the bottom of the TCAM table; otherwise, allocate from the
5638 * top of the table in order to give it higher priority
5640 status = ice_alloc_tcam_ent(hw, blk, map->attr[i].mask == 0,
5644 goto err_ice_add_prof_id_vsig;
5647 t->tcam[i].ptg = map->ptg[i];
5648 t->tcam[i].prof_id = map->prof_id;
5649 t->tcam[i].tcam_idx = tcam_idx;
5650 t->tcam[i].attr = map->attr[i];
5651 t->tcam[i].in_use = true;
5653 p->type = ICE_TCAM_ADD;
5654 p->add_tcam_idx = true;
5655 p->prof_id = t->tcam[i].prof_id;
5656 p->ptg = t->tcam[i].ptg;
5658 p->tcam_idx = t->tcam[i].tcam_idx;
5660 /* set don't care masks for TCAM flags */
5661 ice_set_tcam_flags(t->tcam[i].attr.mask, dc_msk);
5663 /* write the TCAM entry */
5664 status = ice_tcam_write_entry(hw, blk, t->tcam[i].tcam_idx,
5666 t->tcam[i].ptg, vsig, 0,
5667 t->tcam[i].attr.flags, vl_msk,
5671 goto err_ice_add_prof_id_vsig;
5675 LIST_ADD(&p->list_entry, chg);
5678 /* add profile to VSIG */
5679 vsig_idx = vsig & ICE_VSIG_IDX_M;
5681 LIST_ADD_TAIL(&t->list,
5682 &hw->blk[blk].xlt2.vsig_tbl[vsig_idx].prop_lst);
5685 &hw->blk[blk].xlt2.vsig_tbl[vsig_idx].prop_lst);
5687 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
5690 err_ice_add_prof_id_vsig:
5691 ice_release_lock(&hw->blk[blk].es.prof_map_lock);
5692 /* let caller clean up the change list */
5698 * ice_create_prof_id_vsig - add a new VSIG with a single profile
5699 * @hw: pointer to the HW struct
5700 * @blk: hardware block
5701 * @vsi: the initial VSI that will be in VSIG
5702 * @hdl: the profile handle of the profile that will be added to the VSIG
5703 * @chg: the change list
5705 static enum ice_status
5706 ice_create_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl,
5707 struct LIST_HEAD_TYPE *chg)
5709 enum ice_status status;
5710 struct ice_chs_chg *p;
5713 p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p));
5715 return ICE_ERR_NO_MEMORY;
5717 new_vsig = ice_vsig_alloc(hw, blk);
5719 status = ICE_ERR_HW_TABLE;
5720 goto err_ice_create_prof_id_vsig;
5723 status = ice_move_vsi(hw, blk, vsi, new_vsig, chg);
5725 goto err_ice_create_prof_id_vsig;
5727 status = ice_add_prof_id_vsig(hw, blk, new_vsig, hdl, false, chg);
5729 goto err_ice_create_prof_id_vsig;
5731 p->type = ICE_VSIG_ADD;
5733 p->orig_vsig = ICE_DEFAULT_VSIG;
5736 LIST_ADD(&p->list_entry, chg);
5740 err_ice_create_prof_id_vsig:
5741 /* let caller clean up the change list */
5747 * ice_create_vsig_from_lst - create a new VSIG with a list of profiles
5748 * @hw: pointer to the HW struct
5749 * @blk: hardware block
5750 * @vsi: the initial VSI that will be in VSIG
5751 * @lst: the list of profile that will be added to the VSIG
5752 * @new_vsig: return of new VSIG
5753 * @chg: the change list
5755 static enum ice_status
5756 ice_create_vsig_from_lst(struct ice_hw *hw, enum ice_block blk, u16 vsi,
5757 struct LIST_HEAD_TYPE *lst, u16 *new_vsig,
5758 struct LIST_HEAD_TYPE *chg)
5760 struct ice_vsig_prof *t;
5761 enum ice_status status;
5764 vsig = ice_vsig_alloc(hw, blk);
5766 return ICE_ERR_HW_TABLE;
5768 status = ice_move_vsi(hw, blk, vsi, vsig, chg);
5772 LIST_FOR_EACH_ENTRY(t, lst, ice_vsig_prof, list) {
5773 /* Reverse the order here since we are copying the list */
5774 status = ice_add_prof_id_vsig(hw, blk, vsig, t->profile_cookie,
5786 * ice_find_prof_vsig - find a VSIG with a specific profile handle
5787 * @hw: pointer to the HW struct
5788 * @blk: hardware block
5789 * @hdl: the profile handle of the profile to search for
5790 * @vsig: returns the VSIG with the matching profile
5793 ice_find_prof_vsig(struct ice_hw *hw, enum ice_block blk, u64 hdl, u16 *vsig)
5795 struct ice_vsig_prof *t;
5796 struct LIST_HEAD_TYPE lst;
5797 enum ice_status status;
5799 INIT_LIST_HEAD(&lst);
5801 t = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*t));
5805 t->profile_cookie = hdl;
5806 LIST_ADD(&t->list, &lst);
5808 status = ice_find_dup_props_vsig(hw, blk, &lst, vsig);
5813 return status == ICE_SUCCESS;
5817 * ice_add_vsi_flow - add VSI flow
5818 * @hw: pointer to the HW struct
5819 * @blk: hardware block
5821 * @vsig: target VSIG to include the input VSI
5823 * Calling this function will add the VSI to a given VSIG and
5824 * update the HW tables accordingly. This call can be used to
5825 * add multiple VSIs to a VSIG if we know beforehand that those
5826 * VSIs have the same characteristics of the VSIG. This will
5827 * save time in generating a new VSIG and TCAMs till a match is
5828 * found and subsequent rollback when a matching VSIG is found.
5831 ice_add_vsi_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig)
5833 struct ice_chs_chg *tmp, *del;
5834 struct LIST_HEAD_TYPE chg;
5835 enum ice_status status;
5837 /* if target VSIG is default the move is invalid */
5838 if ((vsig & ICE_VSIG_IDX_M) == ICE_DEFAULT_VSIG)
5839 return ICE_ERR_PARAM;
5841 INIT_LIST_HEAD(&chg);
5843 /* move VSI to the VSIG that matches */
5844 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5845 /* update hardware if success */
5847 status = ice_upd_prof_hw(hw, blk, &chg);
5849 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
5850 LIST_DEL(&del->list_entry);
5858 * ice_add_prof_id_flow - add profile flow
5859 * @hw: pointer to the HW struct
5860 * @blk: hardware block
5861 * @vsi: the VSI to enable with the profile specified by ID
5862 * @hdl: profile handle
5864 * Calling this function will update the hardware tables to enable the
5865 * profile indicated by the ID parameter for the VSIs specified in the VSI
5866 * array. Once successfully called, the flow will be enabled.
5869 ice_add_prof_id_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl)
5871 struct ice_vsig_prof *tmp1, *del1;
5872 struct LIST_HEAD_TYPE union_lst;
5873 struct ice_chs_chg *tmp, *del;
5874 struct LIST_HEAD_TYPE chg;
5875 enum ice_status status;
5878 INIT_LIST_HEAD(&union_lst);
5879 INIT_LIST_HEAD(&chg);
5882 status = ice_get_prof(hw, blk, hdl, &chg);
5886 /* determine if VSI is already part of a VSIG */
5887 status = ice_vsig_find_vsi(hw, blk, vsi, &vsig);
5888 if (!status && vsig) {
5896 /* make sure that there is no overlap/conflict between the new
5897 * characteristics and the existing ones; we don't support that
5900 if (ice_has_prof_vsig(hw, blk, vsig, hdl)) {
5901 status = ICE_ERR_ALREADY_EXISTS;
5902 goto err_ice_add_prof_id_flow;
5905 /* last VSI in the VSIG? */
5906 status = ice_vsig_get_ref(hw, blk, vsig, &ref);
5908 goto err_ice_add_prof_id_flow;
5909 only_vsi = (ref == 1);
5911 /* create a union of the current profiles and the one being
5914 status = ice_get_profs_vsig(hw, blk, vsig, &union_lst);
5916 goto err_ice_add_prof_id_flow;
5918 status = ice_add_prof_to_lst(hw, blk, &union_lst, hdl);
5920 goto err_ice_add_prof_id_flow;
5922 /* search for an existing VSIG with an exact charc match */
5923 status = ice_find_dup_props_vsig(hw, blk, &union_lst, &vsig);
5925 /* move VSI to the VSIG that matches */
5926 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5928 goto err_ice_add_prof_id_flow;
5930 /* VSI has been moved out of or_vsig. If the or_vsig had
5931 * only that VSI it is now empty and can be removed.
5934 status = ice_rem_vsig(hw, blk, or_vsig, &chg);
5936 goto err_ice_add_prof_id_flow;
5938 } else if (only_vsi) {
5939 /* If the original VSIG only contains one VSI, then it
5940 * will be the requesting VSI. In this case the VSI is
5941 * not sharing entries and we can simply add the new
5942 * profile to the VSIG.
5944 status = ice_add_prof_id_vsig(hw, blk, vsig, hdl, false,
5947 goto err_ice_add_prof_id_flow;
5949 /* Adjust priorities */
5950 status = ice_adj_prof_priorities(hw, blk, vsig, &chg);
5952 goto err_ice_add_prof_id_flow;
5954 /* No match, so we need a new VSIG */
5955 status = ice_create_vsig_from_lst(hw, blk, vsi,
5959 goto err_ice_add_prof_id_flow;
5961 /* Adjust priorities */
5962 status = ice_adj_prof_priorities(hw, blk, vsig, &chg);
5964 goto err_ice_add_prof_id_flow;
5967 /* need to find or add a VSIG */
5968 /* search for an existing VSIG with an exact charc match */
5969 if (ice_find_prof_vsig(hw, blk, hdl, &vsig)) {
5970 /* found an exact match */
5971 /* add or move VSI to the VSIG that matches */
5972 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
5974 goto err_ice_add_prof_id_flow;
5976 /* we did not find an exact match */
5977 /* we need to add a VSIG */
5978 status = ice_create_prof_id_vsig(hw, blk, vsi, hdl,
5981 goto err_ice_add_prof_id_flow;
5985 /* update hardware */
5987 status = ice_upd_prof_hw(hw, blk, &chg);
5989 err_ice_add_prof_id_flow:
5990 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
5991 LIST_DEL(&del->list_entry);
5995 LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, &union_lst, ice_vsig_prof, list) {
5996 LIST_DEL(&del1->list);
6004 * ice_rem_prof_from_list - remove a profile from list
6005 * @hw: pointer to the HW struct
6006 * @lst: list to remove the profile from
6007 * @hdl: the profile handle indicating the profile to remove
6009 static enum ice_status
6010 ice_rem_prof_from_list(struct ice_hw *hw, struct LIST_HEAD_TYPE *lst, u64 hdl)
6012 struct ice_vsig_prof *ent, *tmp;
6014 LIST_FOR_EACH_ENTRY_SAFE(ent, tmp, lst, ice_vsig_prof, list)
6015 if (ent->profile_cookie == hdl) {
6016 LIST_DEL(&ent->list);
6021 return ICE_ERR_DOES_NOT_EXIST;
6025 * ice_rem_prof_id_flow - remove flow
6026 * @hw: pointer to the HW struct
6027 * @blk: hardware block
6028 * @vsi: the VSI from which to remove the profile specified by ID
6029 * @hdl: profile tracking handle
6031 * Calling this function will update the hardware tables to remove the
6032 * profile indicated by the ID parameter for the VSIs specified in the VSI
6033 * array. Once successfully called, the flow will be disabled.
6036 ice_rem_prof_id_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl)
6038 struct ice_vsig_prof *tmp1, *del1;
6039 struct LIST_HEAD_TYPE chg, copy;
6040 struct ice_chs_chg *tmp, *del;
6041 enum ice_status status;
6044 INIT_LIST_HEAD(©);
6045 INIT_LIST_HEAD(&chg);
6047 /* determine if VSI is already part of a VSIG */
6048 status = ice_vsig_find_vsi(hw, blk, vsi, &vsig);
6049 if (!status && vsig) {
6055 last_profile = ice_vsig_prof_id_count(hw, blk, vsig) == 1;
6056 status = ice_vsig_get_ref(hw, blk, vsig, &ref);
6058 goto err_ice_rem_prof_id_flow;
6059 only_vsi = (ref == 1);
6062 /* If the original VSIG only contains one reference,
6063 * which will be the requesting VSI, then the VSI is not
6064 * sharing entries and we can simply remove the specific
6065 * characteristics from the VSIG.
6069 /* If there are no profiles left for this VSIG,
6070 * then simply remove the VSIG.
6072 status = ice_rem_vsig(hw, blk, vsig, &chg);
6074 goto err_ice_rem_prof_id_flow;
6076 status = ice_rem_prof_id_vsig(hw, blk, vsig,
6079 goto err_ice_rem_prof_id_flow;
6081 /* Adjust priorities */
6082 status = ice_adj_prof_priorities(hw, blk, vsig,
6085 goto err_ice_rem_prof_id_flow;
6089 /* Make a copy of the VSIG's list of Profiles */
6090 status = ice_get_profs_vsig(hw, blk, vsig, ©);
6092 goto err_ice_rem_prof_id_flow;
6094 /* Remove specified profile entry from the list */
6095 status = ice_rem_prof_from_list(hw, ©, hdl);
6097 goto err_ice_rem_prof_id_flow;
6099 if (LIST_EMPTY(©)) {
6100 status = ice_move_vsi(hw, blk, vsi,
6101 ICE_DEFAULT_VSIG, &chg);
6103 goto err_ice_rem_prof_id_flow;
6105 } else if (!ice_find_dup_props_vsig(hw, blk, ©,
6107 /* found an exact match */
6108 /* add or move VSI to the VSIG that matches */
6109 /* Search for a VSIG with a matching profile
6113 /* Found match, move VSI to the matching VSIG */
6114 status = ice_move_vsi(hw, blk, vsi, vsig, &chg);
6116 goto err_ice_rem_prof_id_flow;
6118 /* since no existing VSIG supports this
6119 * characteristic pattern, we need to create a
6120 * new VSIG and TCAM entries
6122 status = ice_create_vsig_from_lst(hw, blk, vsi,
6126 goto err_ice_rem_prof_id_flow;
6128 /* Adjust priorities */
6129 status = ice_adj_prof_priorities(hw, blk, vsig,
6132 goto err_ice_rem_prof_id_flow;
6136 status = ICE_ERR_DOES_NOT_EXIST;
6139 /* update hardware tables */
6141 status = ice_upd_prof_hw(hw, blk, &chg);
6143 err_ice_rem_prof_id_flow:
6144 LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) {
6145 LIST_DEL(&del->list_entry);
6149 LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, ©, ice_vsig_prof, list) {
6150 LIST_DEL(&del1->list);