171d10453SEric Joyner /* SPDX-License-Identifier: BSD-3-Clause */ 271d10453SEric Joyner /* Copyright (c) 2020, Intel Corporation 371d10453SEric Joyner * All rights reserved. 471d10453SEric Joyner * 571d10453SEric Joyner * Redistribution and use in source and binary forms, with or without 671d10453SEric Joyner * modification, are permitted provided that the following conditions are met: 771d10453SEric Joyner * 871d10453SEric Joyner * 1. Redistributions of source code must retain the above copyright notice, 971d10453SEric Joyner * this list of conditions and the following disclaimer. 1071d10453SEric Joyner * 1171d10453SEric Joyner * 2. Redistributions in binary form must reproduce the above copyright 1271d10453SEric Joyner * notice, this list of conditions and the following disclaimer in the 1371d10453SEric Joyner * documentation and/or other materials provided with the distribution. 1471d10453SEric Joyner * 1571d10453SEric Joyner * 3. Neither the name of the Intel Corporation nor the names of its 1671d10453SEric Joyner * contributors may be used to endorse or promote products derived from 1771d10453SEric Joyner * this software without specific prior written permission. 1871d10453SEric Joyner * 1971d10453SEric Joyner * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 2071d10453SEric Joyner * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2171d10453SEric Joyner * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2271d10453SEric Joyner * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 2371d10453SEric Joyner * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2471d10453SEric Joyner * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2571d10453SEric Joyner * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2671d10453SEric Joyner * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2771d10453SEric Joyner * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2871d10453SEric Joyner * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2971d10453SEric Joyner * POSSIBILITY OF SUCH DAMAGE. 3071d10453SEric Joyner */ 3171d10453SEric Joyner /*$FreeBSD$*/ 3271d10453SEric Joyner 3371d10453SEric Joyner #include "ice_common.h" 3471d10453SEric Joyner #include "ice_flex_pipe.h" 3571d10453SEric Joyner #include "ice_protocol_type.h" 3671d10453SEric Joyner #include "ice_flow.h" 3771d10453SEric Joyner 3871d10453SEric Joyner /* To support tunneling entries by PF, the package will append the PF number to 3971d10453SEric Joyner * the label; for example TNL_VXLAN_PF0, TNL_VXLAN_PF1, TNL_VXLAN_PF2, etc. 4071d10453SEric Joyner */ 4171d10453SEric Joyner static const struct ice_tunnel_type_scan tnls[] = { 4271d10453SEric Joyner { TNL_VXLAN, "TNL_VXLAN_PF" }, 4371d10453SEric Joyner { TNL_GENEVE, "TNL_GENEVE_PF" }, 4471d10453SEric Joyner { TNL_LAST, "" } 4571d10453SEric Joyner }; 4671d10453SEric Joyner 4771d10453SEric Joyner static const u32 ice_sect_lkup[ICE_BLK_COUNT][ICE_SECT_COUNT] = { 4871d10453SEric Joyner /* SWITCH */ 4971d10453SEric Joyner { 5071d10453SEric Joyner ICE_SID_XLT0_SW, 5171d10453SEric Joyner ICE_SID_XLT_KEY_BUILDER_SW, 5271d10453SEric Joyner ICE_SID_XLT1_SW, 5371d10453SEric Joyner ICE_SID_XLT2_SW, 5471d10453SEric Joyner ICE_SID_PROFID_TCAM_SW, 5571d10453SEric Joyner ICE_SID_PROFID_REDIR_SW, 5671d10453SEric Joyner ICE_SID_FLD_VEC_SW, 5771d10453SEric Joyner ICE_SID_CDID_KEY_BUILDER_SW, 5871d10453SEric Joyner ICE_SID_CDID_REDIR_SW 5971d10453SEric Joyner }, 6071d10453SEric Joyner 6171d10453SEric Joyner /* ACL */ 6271d10453SEric Joyner { 6371d10453SEric Joyner ICE_SID_XLT0_ACL, 6471d10453SEric Joyner ICE_SID_XLT_KEY_BUILDER_ACL, 6571d10453SEric Joyner ICE_SID_XLT1_ACL, 6671d10453SEric Joyner ICE_SID_XLT2_ACL, 6771d10453SEric Joyner ICE_SID_PROFID_TCAM_ACL, 6871d10453SEric Joyner ICE_SID_PROFID_REDIR_ACL, 6971d10453SEric Joyner ICE_SID_FLD_VEC_ACL, 7071d10453SEric Joyner ICE_SID_CDID_KEY_BUILDER_ACL, 7171d10453SEric Joyner ICE_SID_CDID_REDIR_ACL 7271d10453SEric Joyner }, 7371d10453SEric Joyner 7471d10453SEric Joyner /* FD */ 7571d10453SEric Joyner { 7671d10453SEric Joyner ICE_SID_XLT0_FD, 7771d10453SEric Joyner ICE_SID_XLT_KEY_BUILDER_FD, 7871d10453SEric Joyner ICE_SID_XLT1_FD, 7971d10453SEric Joyner ICE_SID_XLT2_FD, 8071d10453SEric Joyner ICE_SID_PROFID_TCAM_FD, 8171d10453SEric Joyner ICE_SID_PROFID_REDIR_FD, 8271d10453SEric Joyner ICE_SID_FLD_VEC_FD, 8371d10453SEric Joyner ICE_SID_CDID_KEY_BUILDER_FD, 8471d10453SEric Joyner ICE_SID_CDID_REDIR_FD 8571d10453SEric Joyner }, 8671d10453SEric Joyner 8771d10453SEric Joyner /* RSS */ 8871d10453SEric Joyner { 8971d10453SEric Joyner ICE_SID_XLT0_RSS, 9071d10453SEric Joyner ICE_SID_XLT_KEY_BUILDER_RSS, 9171d10453SEric Joyner ICE_SID_XLT1_RSS, 9271d10453SEric Joyner ICE_SID_XLT2_RSS, 9371d10453SEric Joyner ICE_SID_PROFID_TCAM_RSS, 9471d10453SEric Joyner ICE_SID_PROFID_REDIR_RSS, 9571d10453SEric Joyner ICE_SID_FLD_VEC_RSS, 9671d10453SEric Joyner ICE_SID_CDID_KEY_BUILDER_RSS, 9771d10453SEric Joyner ICE_SID_CDID_REDIR_RSS 9871d10453SEric Joyner }, 9971d10453SEric Joyner 10071d10453SEric Joyner /* PE */ 10171d10453SEric Joyner { 10271d10453SEric Joyner ICE_SID_XLT0_PE, 10371d10453SEric Joyner ICE_SID_XLT_KEY_BUILDER_PE, 10471d10453SEric Joyner ICE_SID_XLT1_PE, 10571d10453SEric Joyner ICE_SID_XLT2_PE, 10671d10453SEric Joyner ICE_SID_PROFID_TCAM_PE, 10771d10453SEric Joyner ICE_SID_PROFID_REDIR_PE, 10871d10453SEric Joyner ICE_SID_FLD_VEC_PE, 10971d10453SEric Joyner ICE_SID_CDID_KEY_BUILDER_PE, 11071d10453SEric Joyner ICE_SID_CDID_REDIR_PE 11171d10453SEric Joyner } 11271d10453SEric Joyner }; 11371d10453SEric Joyner 11471d10453SEric Joyner /** 11571d10453SEric Joyner * ice_sect_id - returns section ID 11671d10453SEric Joyner * @blk: block type 11771d10453SEric Joyner * @sect: section type 11871d10453SEric Joyner * 11971d10453SEric Joyner * This helper function returns the proper section ID given a block type and a 12071d10453SEric Joyner * section type. 12171d10453SEric Joyner */ 12271d10453SEric Joyner static u32 ice_sect_id(enum ice_block blk, enum ice_sect sect) 12371d10453SEric Joyner { 12471d10453SEric Joyner return ice_sect_lkup[blk][sect]; 12571d10453SEric Joyner } 12671d10453SEric Joyner 12771d10453SEric Joyner /** 12871d10453SEric Joyner * ice_pkg_val_buf 12971d10453SEric Joyner * @buf: pointer to the ice buffer 13071d10453SEric Joyner * 13171d10453SEric Joyner * This helper function validates a buffer's header. 13271d10453SEric Joyner */ 13371d10453SEric Joyner static struct ice_buf_hdr *ice_pkg_val_buf(struct ice_buf *buf) 13471d10453SEric Joyner { 13571d10453SEric Joyner struct ice_buf_hdr *hdr; 13671d10453SEric Joyner u16 section_count; 13771d10453SEric Joyner u16 data_end; 13871d10453SEric Joyner 13971d10453SEric Joyner hdr = (struct ice_buf_hdr *)buf->buf; 14071d10453SEric Joyner /* verify data */ 14171d10453SEric Joyner section_count = LE16_TO_CPU(hdr->section_count); 14271d10453SEric Joyner if (section_count < ICE_MIN_S_COUNT || section_count > ICE_MAX_S_COUNT) 14371d10453SEric Joyner return NULL; 14471d10453SEric Joyner 14571d10453SEric Joyner data_end = LE16_TO_CPU(hdr->data_end); 14671d10453SEric Joyner if (data_end < ICE_MIN_S_DATA_END || data_end > ICE_MAX_S_DATA_END) 14771d10453SEric Joyner return NULL; 14871d10453SEric Joyner 14971d10453SEric Joyner return hdr; 15071d10453SEric Joyner } 15171d10453SEric Joyner 15271d10453SEric Joyner /** 15371d10453SEric Joyner * ice_find_buf_table 15471d10453SEric Joyner * @ice_seg: pointer to the ice segment 15571d10453SEric Joyner * 15671d10453SEric Joyner * Returns the address of the buffer table within the ice segment. 15771d10453SEric Joyner */ 15871d10453SEric Joyner static struct ice_buf_table *ice_find_buf_table(struct ice_seg *ice_seg) 15971d10453SEric Joyner { 16071d10453SEric Joyner struct ice_nvm_table *nvms; 16171d10453SEric Joyner 16271d10453SEric Joyner nvms = (struct ice_nvm_table *) 16371d10453SEric Joyner (ice_seg->device_table + 16471d10453SEric Joyner LE32_TO_CPU(ice_seg->device_table_count)); 16571d10453SEric Joyner 16671d10453SEric Joyner return (_FORCE_ struct ice_buf_table *) 16771d10453SEric Joyner (nvms->vers + LE32_TO_CPU(nvms->table_count)); 16871d10453SEric Joyner } 16971d10453SEric Joyner 17071d10453SEric Joyner /** 17171d10453SEric Joyner * ice_pkg_enum_buf 17271d10453SEric Joyner * @ice_seg: pointer to the ice segment (or NULL on subsequent calls) 17371d10453SEric Joyner * @state: pointer to the enum state 17471d10453SEric Joyner * 17571d10453SEric Joyner * This function will enumerate all the buffers in the ice segment. The first 17671d10453SEric Joyner * call is made with the ice_seg parameter non-NULL; on subsequent calls, 17771d10453SEric Joyner * ice_seg is set to NULL which continues the enumeration. When the function 17871d10453SEric Joyner * returns a NULL pointer, then the end of the buffers has been reached, or an 17971d10453SEric Joyner * unexpected value has been detected (for example an invalid section count or 18071d10453SEric Joyner * an invalid buffer end value). 18171d10453SEric Joyner */ 18271d10453SEric Joyner static struct ice_buf_hdr * 18371d10453SEric Joyner ice_pkg_enum_buf(struct ice_seg *ice_seg, struct ice_pkg_enum *state) 18471d10453SEric Joyner { 18571d10453SEric Joyner if (ice_seg) { 18671d10453SEric Joyner state->buf_table = ice_find_buf_table(ice_seg); 18771d10453SEric Joyner if (!state->buf_table) 18871d10453SEric Joyner return NULL; 18971d10453SEric Joyner 19071d10453SEric Joyner state->buf_idx = 0; 19171d10453SEric Joyner return ice_pkg_val_buf(state->buf_table->buf_array); 19271d10453SEric Joyner } 19371d10453SEric Joyner 19471d10453SEric Joyner if (++state->buf_idx < LE32_TO_CPU(state->buf_table->buf_count)) 19571d10453SEric Joyner return ice_pkg_val_buf(state->buf_table->buf_array + 19671d10453SEric Joyner state->buf_idx); 19771d10453SEric Joyner else 19871d10453SEric Joyner return NULL; 19971d10453SEric Joyner } 20071d10453SEric Joyner 20171d10453SEric Joyner /** 20271d10453SEric Joyner * ice_pkg_advance_sect 20371d10453SEric Joyner * @ice_seg: pointer to the ice segment (or NULL on subsequent calls) 20471d10453SEric Joyner * @state: pointer to the enum state 20571d10453SEric Joyner * 20671d10453SEric Joyner * This helper function will advance the section within the ice segment, 20771d10453SEric Joyner * also advancing the buffer if needed. 20871d10453SEric Joyner */ 20971d10453SEric Joyner static bool 21071d10453SEric Joyner ice_pkg_advance_sect(struct ice_seg *ice_seg, struct ice_pkg_enum *state) 21171d10453SEric Joyner { 21271d10453SEric Joyner if (!ice_seg && !state->buf) 21371d10453SEric Joyner return false; 21471d10453SEric Joyner 21571d10453SEric Joyner if (!ice_seg && state->buf) 21671d10453SEric Joyner if (++state->sect_idx < LE16_TO_CPU(state->buf->section_count)) 21771d10453SEric Joyner return true; 21871d10453SEric Joyner 21971d10453SEric Joyner state->buf = ice_pkg_enum_buf(ice_seg, state); 22071d10453SEric Joyner if (!state->buf) 22171d10453SEric Joyner return false; 22271d10453SEric Joyner 22371d10453SEric Joyner /* start of new buffer, reset section index */ 22471d10453SEric Joyner state->sect_idx = 0; 22571d10453SEric Joyner return true; 22671d10453SEric Joyner } 22771d10453SEric Joyner 22871d10453SEric Joyner /** 22971d10453SEric Joyner * ice_pkg_enum_section 23071d10453SEric Joyner * @ice_seg: pointer to the ice segment (or NULL on subsequent calls) 23171d10453SEric Joyner * @state: pointer to the enum state 23271d10453SEric Joyner * @sect_type: section type to enumerate 23371d10453SEric Joyner * 23471d10453SEric Joyner * This function will enumerate all the sections of a particular type in the 23571d10453SEric Joyner * ice segment. The first call is made with the ice_seg parameter non-NULL; 23671d10453SEric Joyner * on subsequent calls, ice_seg is set to NULL which continues the enumeration. 23771d10453SEric Joyner * When the function returns a NULL pointer, then the end of the matching 23871d10453SEric Joyner * sections has been reached. 23971d10453SEric Joyner */ 24071d10453SEric Joyner static void * 24171d10453SEric Joyner ice_pkg_enum_section(struct ice_seg *ice_seg, struct ice_pkg_enum *state, 24271d10453SEric Joyner u32 sect_type) 24371d10453SEric Joyner { 24471d10453SEric Joyner u16 offset, size; 24571d10453SEric Joyner 24671d10453SEric Joyner if (ice_seg) 24771d10453SEric Joyner state->type = sect_type; 24871d10453SEric Joyner 24971d10453SEric Joyner if (!ice_pkg_advance_sect(ice_seg, state)) 25071d10453SEric Joyner return NULL; 25171d10453SEric Joyner 25271d10453SEric Joyner /* scan for next matching section */ 25371d10453SEric Joyner while (state->buf->section_entry[state->sect_idx].type != 25471d10453SEric Joyner CPU_TO_LE32(state->type)) 25571d10453SEric Joyner if (!ice_pkg_advance_sect(NULL, state)) 25671d10453SEric Joyner return NULL; 25771d10453SEric Joyner 25871d10453SEric Joyner /* validate section */ 25971d10453SEric Joyner offset = LE16_TO_CPU(state->buf->section_entry[state->sect_idx].offset); 26071d10453SEric Joyner if (offset < ICE_MIN_S_OFF || offset > ICE_MAX_S_OFF) 26171d10453SEric Joyner return NULL; 26271d10453SEric Joyner 26371d10453SEric Joyner size = LE16_TO_CPU(state->buf->section_entry[state->sect_idx].size); 26471d10453SEric Joyner if (size < ICE_MIN_S_SZ || size > ICE_MAX_S_SZ) 26571d10453SEric Joyner return NULL; 26671d10453SEric Joyner 26771d10453SEric Joyner /* make sure the section fits in the buffer */ 26871d10453SEric Joyner if (offset + size > ICE_PKG_BUF_SIZE) 26971d10453SEric Joyner return NULL; 27071d10453SEric Joyner 27171d10453SEric Joyner state->sect_type = 27271d10453SEric Joyner LE32_TO_CPU(state->buf->section_entry[state->sect_idx].type); 27371d10453SEric Joyner 27471d10453SEric Joyner /* calc pointer to this section */ 27571d10453SEric Joyner state->sect = ((u8 *)state->buf) + 27671d10453SEric Joyner LE16_TO_CPU(state->buf->section_entry[state->sect_idx].offset); 27771d10453SEric Joyner 27871d10453SEric Joyner return state->sect; 27971d10453SEric Joyner } 28071d10453SEric Joyner 28171d10453SEric Joyner /** 28271d10453SEric Joyner * ice_pkg_enum_entry 28371d10453SEric Joyner * @ice_seg: pointer to the ice segment (or NULL on subsequent calls) 28471d10453SEric Joyner * @state: pointer to the enum state 28571d10453SEric Joyner * @sect_type: section type to enumerate 28671d10453SEric Joyner * @offset: pointer to variable that receives the offset in the table (optional) 28771d10453SEric Joyner * @handler: function that handles access to the entries into the section type 28871d10453SEric Joyner * 28971d10453SEric Joyner * This function will enumerate all the entries in particular section type in 29071d10453SEric Joyner * the ice segment. The first call is made with the ice_seg parameter non-NULL; 29171d10453SEric Joyner * on subsequent calls, ice_seg is set to NULL which continues the enumeration. 29271d10453SEric Joyner * When the function returns a NULL pointer, then the end of the entries has 29371d10453SEric Joyner * been reached. 29471d10453SEric Joyner * 29571d10453SEric Joyner * Since each section may have a different header and entry size, the handler 29671d10453SEric Joyner * function is needed to determine the number and location entries in each 29771d10453SEric Joyner * section. 29871d10453SEric Joyner * 29971d10453SEric Joyner * The offset parameter is optional, but should be used for sections that 30071d10453SEric Joyner * contain an offset for each section table. For such cases, the section handler 30171d10453SEric Joyner * function must return the appropriate offset + index to give the absolution 30271d10453SEric Joyner * offset for each entry. For example, if the base for a section's header 30371d10453SEric Joyner * indicates a base offset of 10, and the index for the entry is 2, then 30471d10453SEric Joyner * section handler function should set the offset to 10 + 2 = 12. 30571d10453SEric Joyner */ 30671d10453SEric Joyner static void * 30771d10453SEric Joyner ice_pkg_enum_entry(struct ice_seg *ice_seg, struct ice_pkg_enum *state, 30871d10453SEric Joyner u32 sect_type, u32 *offset, 30971d10453SEric Joyner void *(*handler)(u32 sect_type, void *section, 31071d10453SEric Joyner u32 index, u32 *offset)) 31171d10453SEric Joyner { 31271d10453SEric Joyner void *entry; 31371d10453SEric Joyner 31471d10453SEric Joyner if (ice_seg) { 31571d10453SEric Joyner if (!handler) 31671d10453SEric Joyner return NULL; 31771d10453SEric Joyner 31871d10453SEric Joyner if (!ice_pkg_enum_section(ice_seg, state, sect_type)) 31971d10453SEric Joyner return NULL; 32071d10453SEric Joyner 32171d10453SEric Joyner state->entry_idx = 0; 32271d10453SEric Joyner state->handler = handler; 32371d10453SEric Joyner } else { 32471d10453SEric Joyner state->entry_idx++; 32571d10453SEric Joyner } 32671d10453SEric Joyner 32771d10453SEric Joyner if (!state->handler) 32871d10453SEric Joyner return NULL; 32971d10453SEric Joyner 33071d10453SEric Joyner /* get entry */ 33171d10453SEric Joyner entry = state->handler(state->sect_type, state->sect, state->entry_idx, 33271d10453SEric Joyner offset); 33371d10453SEric Joyner if (!entry) { 33471d10453SEric Joyner /* end of a section, look for another section of this type */ 33571d10453SEric Joyner if (!ice_pkg_enum_section(NULL, state, 0)) 33671d10453SEric Joyner return NULL; 33771d10453SEric Joyner 33871d10453SEric Joyner state->entry_idx = 0; 33971d10453SEric Joyner entry = state->handler(state->sect_type, state->sect, 34071d10453SEric Joyner state->entry_idx, offset); 34171d10453SEric Joyner } 34271d10453SEric Joyner 34371d10453SEric Joyner return entry; 34471d10453SEric Joyner } 34571d10453SEric Joyner 34671d10453SEric Joyner /** 34771d10453SEric Joyner * ice_boost_tcam_handler 34871d10453SEric Joyner * @sect_type: section type 34971d10453SEric Joyner * @section: pointer to section 35071d10453SEric Joyner * @index: index of the boost TCAM entry to be returned 35171d10453SEric Joyner * @offset: pointer to receive absolute offset, always 0 for boost TCAM sections 35271d10453SEric Joyner * 35371d10453SEric Joyner * This is a callback function that can be passed to ice_pkg_enum_entry. 35471d10453SEric Joyner * Handles enumeration of individual boost TCAM entries. 35571d10453SEric Joyner */ 35671d10453SEric Joyner static void * 35771d10453SEric Joyner ice_boost_tcam_handler(u32 sect_type, void *section, u32 index, u32 *offset) 35871d10453SEric Joyner { 35971d10453SEric Joyner struct ice_boost_tcam_section *boost; 36071d10453SEric Joyner 36171d10453SEric Joyner if (!section) 36271d10453SEric Joyner return NULL; 36371d10453SEric Joyner 36471d10453SEric Joyner if (sect_type != ICE_SID_RXPARSER_BOOST_TCAM) 36571d10453SEric Joyner return NULL; 36671d10453SEric Joyner 36771d10453SEric Joyner if (index > ICE_MAX_BST_TCAMS_IN_BUF) 36871d10453SEric Joyner return NULL; 36971d10453SEric Joyner 37071d10453SEric Joyner if (offset) 37171d10453SEric Joyner *offset = 0; 37271d10453SEric Joyner 37371d10453SEric Joyner boost = (struct ice_boost_tcam_section *)section; 37471d10453SEric Joyner if (index >= LE16_TO_CPU(boost->count)) 37571d10453SEric Joyner return NULL; 37671d10453SEric Joyner 37771d10453SEric Joyner return boost->tcam + index; 37871d10453SEric Joyner } 37971d10453SEric Joyner 38071d10453SEric Joyner /** 38171d10453SEric Joyner * ice_find_boost_entry 38271d10453SEric Joyner * @ice_seg: pointer to the ice segment (non-NULL) 38371d10453SEric Joyner * @addr: Boost TCAM address of entry to search for 38471d10453SEric Joyner * @entry: returns pointer to the entry 38571d10453SEric Joyner * 38671d10453SEric Joyner * Finds a particular Boost TCAM entry and returns a pointer to that entry 38771d10453SEric Joyner * if it is found. The ice_seg parameter must not be NULL since the first call 38871d10453SEric Joyner * to ice_pkg_enum_entry requires a pointer to an actual ice_segment structure. 38971d10453SEric Joyner */ 39071d10453SEric Joyner static enum ice_status 39171d10453SEric Joyner ice_find_boost_entry(struct ice_seg *ice_seg, u16 addr, 39271d10453SEric Joyner struct ice_boost_tcam_entry **entry) 39371d10453SEric Joyner { 39471d10453SEric Joyner struct ice_boost_tcam_entry *tcam; 39571d10453SEric Joyner struct ice_pkg_enum state; 39671d10453SEric Joyner 39771d10453SEric Joyner ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM); 39871d10453SEric Joyner 39971d10453SEric Joyner if (!ice_seg) 40071d10453SEric Joyner return ICE_ERR_PARAM; 40171d10453SEric Joyner 40271d10453SEric Joyner do { 40371d10453SEric Joyner tcam = (struct ice_boost_tcam_entry *) 40471d10453SEric Joyner ice_pkg_enum_entry(ice_seg, &state, 40571d10453SEric Joyner ICE_SID_RXPARSER_BOOST_TCAM, NULL, 40671d10453SEric Joyner ice_boost_tcam_handler); 40771d10453SEric Joyner if (tcam && LE16_TO_CPU(tcam->addr) == addr) { 40871d10453SEric Joyner *entry = tcam; 40971d10453SEric Joyner return ICE_SUCCESS; 41071d10453SEric Joyner } 41171d10453SEric Joyner 41271d10453SEric Joyner ice_seg = NULL; 41371d10453SEric Joyner } while (tcam); 41471d10453SEric Joyner 41571d10453SEric Joyner *entry = NULL; 41671d10453SEric Joyner return ICE_ERR_CFG; 41771d10453SEric Joyner } 41871d10453SEric Joyner 41971d10453SEric Joyner /** 42071d10453SEric Joyner * ice_label_enum_handler 42171d10453SEric Joyner * @sect_type: section type 42271d10453SEric Joyner * @section: pointer to section 42371d10453SEric Joyner * @index: index of the label entry to be returned 42471d10453SEric Joyner * @offset: pointer to receive absolute offset, always zero for label sections 42571d10453SEric Joyner * 42671d10453SEric Joyner * This is a callback function that can be passed to ice_pkg_enum_entry. 42771d10453SEric Joyner * Handles enumeration of individual label entries. 42871d10453SEric Joyner */ 42971d10453SEric Joyner static void * 43071d10453SEric Joyner ice_label_enum_handler(u32 __ALWAYS_UNUSED sect_type, void *section, u32 index, 43171d10453SEric Joyner u32 *offset) 43271d10453SEric Joyner { 43371d10453SEric Joyner struct ice_label_section *labels; 43471d10453SEric Joyner 43571d10453SEric Joyner if (!section) 43671d10453SEric Joyner return NULL; 43771d10453SEric Joyner 43871d10453SEric Joyner if (index > ICE_MAX_LABELS_IN_BUF) 43971d10453SEric Joyner return NULL; 44071d10453SEric Joyner 44171d10453SEric Joyner if (offset) 44271d10453SEric Joyner *offset = 0; 44371d10453SEric Joyner 44471d10453SEric Joyner labels = (struct ice_label_section *)section; 44571d10453SEric Joyner if (index >= LE16_TO_CPU(labels->count)) 44671d10453SEric Joyner return NULL; 44771d10453SEric Joyner 44871d10453SEric Joyner return labels->label + index; 44971d10453SEric Joyner } 45071d10453SEric Joyner 45171d10453SEric Joyner /** 45271d10453SEric Joyner * ice_enum_labels 45371d10453SEric Joyner * @ice_seg: pointer to the ice segment (NULL on subsequent calls) 45471d10453SEric Joyner * @type: the section type that will contain the label (0 on subsequent calls) 45571d10453SEric Joyner * @state: ice_pkg_enum structure that will hold the state of the enumeration 45671d10453SEric Joyner * @value: pointer to a value that will return the label's value if found 45771d10453SEric Joyner * 45871d10453SEric Joyner * Enumerates a list of labels in the package. The caller will call 45971d10453SEric Joyner * ice_enum_labels(ice_seg, type, ...) to start the enumeration, then call 46071d10453SEric Joyner * ice_enum_labels(NULL, 0, ...) to continue. When the function returns a NULL 46171d10453SEric Joyner * the end of the list has been reached. 46271d10453SEric Joyner */ 46371d10453SEric Joyner static char * 46471d10453SEric Joyner ice_enum_labels(struct ice_seg *ice_seg, u32 type, struct ice_pkg_enum *state, 46571d10453SEric Joyner u16 *value) 46671d10453SEric Joyner { 46771d10453SEric Joyner struct ice_label *label; 46871d10453SEric Joyner 46971d10453SEric Joyner /* Check for valid label section on first call */ 47071d10453SEric Joyner if (type && !(type >= ICE_SID_LBL_FIRST && type <= ICE_SID_LBL_LAST)) 47171d10453SEric Joyner return NULL; 47271d10453SEric Joyner 47371d10453SEric Joyner label = (struct ice_label *)ice_pkg_enum_entry(ice_seg, state, type, 47471d10453SEric Joyner NULL, 47571d10453SEric Joyner ice_label_enum_handler); 47671d10453SEric Joyner if (!label) 47771d10453SEric Joyner return NULL; 47871d10453SEric Joyner 47971d10453SEric Joyner *value = LE16_TO_CPU(label->value); 48071d10453SEric Joyner return label->name; 48171d10453SEric Joyner } 48271d10453SEric Joyner 48371d10453SEric Joyner /** 48471d10453SEric Joyner * ice_init_pkg_hints 48571d10453SEric Joyner * @hw: pointer to the HW structure 48671d10453SEric Joyner * @ice_seg: pointer to the segment of the package scan (non-NULL) 48771d10453SEric Joyner * 48871d10453SEric Joyner * This function will scan the package and save off relevant information 48971d10453SEric Joyner * (hints or metadata) for driver use. The ice_seg parameter must not be NULL 49071d10453SEric Joyner * since the first call to ice_enum_labels requires a pointer to an actual 49171d10453SEric Joyner * ice_seg structure. 49271d10453SEric Joyner */ 49371d10453SEric Joyner static void ice_init_pkg_hints(struct ice_hw *hw, struct ice_seg *ice_seg) 49471d10453SEric Joyner { 49571d10453SEric Joyner struct ice_pkg_enum state; 49671d10453SEric Joyner char *label_name; 49771d10453SEric Joyner u16 val; 49871d10453SEric Joyner int i; 49971d10453SEric Joyner 50071d10453SEric Joyner ice_memset(&hw->tnl, 0, sizeof(hw->tnl), ICE_NONDMA_MEM); 50171d10453SEric Joyner ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM); 50271d10453SEric Joyner 50371d10453SEric Joyner if (!ice_seg) 50471d10453SEric Joyner return; 50571d10453SEric Joyner 50671d10453SEric Joyner label_name = ice_enum_labels(ice_seg, ICE_SID_LBL_RXPARSER_TMEM, &state, 50771d10453SEric Joyner &val); 50871d10453SEric Joyner 50971d10453SEric Joyner while (label_name && hw->tnl.count < ICE_TUNNEL_MAX_ENTRIES) { 51071d10453SEric Joyner for (i = 0; tnls[i].type != TNL_LAST; i++) { 51171d10453SEric Joyner size_t len = strlen(tnls[i].label_prefix); 51271d10453SEric Joyner 51371d10453SEric Joyner /* Look for matching label start, before continuing */ 51471d10453SEric Joyner if (strncmp(label_name, tnls[i].label_prefix, len)) 51571d10453SEric Joyner continue; 51671d10453SEric Joyner 51771d10453SEric Joyner /* Make sure this label matches our PF. Note that the PF 51871d10453SEric Joyner * character ('0' - '7') will be located where our 51971d10453SEric Joyner * prefix string's null terminator is located. 52071d10453SEric Joyner */ 52171d10453SEric Joyner if ((label_name[len] - '0') == hw->pf_id) { 52271d10453SEric Joyner hw->tnl.tbl[hw->tnl.count].type = tnls[i].type; 52371d10453SEric Joyner hw->tnl.tbl[hw->tnl.count].valid = false; 52471d10453SEric Joyner hw->tnl.tbl[hw->tnl.count].in_use = false; 52571d10453SEric Joyner hw->tnl.tbl[hw->tnl.count].marked = false; 52671d10453SEric Joyner hw->tnl.tbl[hw->tnl.count].boost_addr = val; 52771d10453SEric Joyner hw->tnl.tbl[hw->tnl.count].port = 0; 52871d10453SEric Joyner hw->tnl.count++; 52971d10453SEric Joyner break; 53071d10453SEric Joyner } 53171d10453SEric Joyner } 53271d10453SEric Joyner 53371d10453SEric Joyner label_name = ice_enum_labels(NULL, 0, &state, &val); 53471d10453SEric Joyner } 53571d10453SEric Joyner 53671d10453SEric Joyner /* Cache the appropriate boost TCAM entry pointers */ 53771d10453SEric Joyner for (i = 0; i < hw->tnl.count; i++) { 53871d10453SEric Joyner ice_find_boost_entry(ice_seg, hw->tnl.tbl[i].boost_addr, 53971d10453SEric Joyner &hw->tnl.tbl[i].boost_entry); 54071d10453SEric Joyner if (hw->tnl.tbl[i].boost_entry) 54171d10453SEric Joyner hw->tnl.tbl[i].valid = true; 54271d10453SEric Joyner } 54371d10453SEric Joyner } 54471d10453SEric Joyner 54571d10453SEric Joyner /* Key creation */ 54671d10453SEric Joyner 54771d10453SEric Joyner #define ICE_DC_KEY 0x1 /* don't care */ 54871d10453SEric Joyner #define ICE_DC_KEYINV 0x1 54971d10453SEric Joyner #define ICE_NM_KEY 0x0 /* never match */ 55071d10453SEric Joyner #define ICE_NM_KEYINV 0x0 55171d10453SEric Joyner #define ICE_0_KEY 0x1 /* match 0 */ 55271d10453SEric Joyner #define ICE_0_KEYINV 0x0 55371d10453SEric Joyner #define ICE_1_KEY 0x0 /* match 1 */ 55471d10453SEric Joyner #define ICE_1_KEYINV 0x1 55571d10453SEric Joyner 55671d10453SEric Joyner /** 55771d10453SEric Joyner * ice_gen_key_word - generate 16-bits of a key/mask word 55871d10453SEric Joyner * @val: the value 55971d10453SEric Joyner * @valid: valid bits mask (change only the valid bits) 56071d10453SEric Joyner * @dont_care: don't care mask 56171d10453SEric Joyner * @nvr_mtch: never match mask 56271d10453SEric Joyner * @key: pointer to an array of where the resulting key portion 56371d10453SEric Joyner * @key_inv: pointer to an array of where the resulting key invert portion 56471d10453SEric Joyner * 56571d10453SEric Joyner * This function generates 16-bits from a 8-bit value, an 8-bit don't care mask 56671d10453SEric Joyner * and an 8-bit never match mask. The 16-bits of output are divided into 8 bits 56771d10453SEric Joyner * of key and 8 bits of key invert. 56871d10453SEric Joyner * 56971d10453SEric Joyner * '0' = b01, always match a 0 bit 57071d10453SEric Joyner * '1' = b10, always match a 1 bit 57171d10453SEric Joyner * '?' = b11, don't care bit (always matches) 57271d10453SEric Joyner * '~' = b00, never match bit 57371d10453SEric Joyner * 57471d10453SEric Joyner * Input: 57571d10453SEric Joyner * val: b0 1 0 1 0 1 57671d10453SEric Joyner * dont_care: b0 0 1 1 0 0 57771d10453SEric Joyner * never_mtch: b0 0 0 0 1 1 57871d10453SEric Joyner * ------------------------------ 57971d10453SEric Joyner * Result: key: b01 10 11 11 00 00 58071d10453SEric Joyner */ 58171d10453SEric Joyner static enum ice_status 58271d10453SEric Joyner ice_gen_key_word(u8 val, u8 valid, u8 dont_care, u8 nvr_mtch, u8 *key, 58371d10453SEric Joyner u8 *key_inv) 58471d10453SEric Joyner { 58571d10453SEric Joyner u8 in_key = *key, in_key_inv = *key_inv; 58671d10453SEric Joyner u8 i; 58771d10453SEric Joyner 58871d10453SEric Joyner /* 'dont_care' and 'nvr_mtch' masks cannot overlap */ 58971d10453SEric Joyner if ((dont_care ^ nvr_mtch) != (dont_care | nvr_mtch)) 59071d10453SEric Joyner return ICE_ERR_CFG; 59171d10453SEric Joyner 59271d10453SEric Joyner *key = 0; 59371d10453SEric Joyner *key_inv = 0; 59471d10453SEric Joyner 59571d10453SEric Joyner /* encode the 8 bits into 8-bit key and 8-bit key invert */ 59671d10453SEric Joyner for (i = 0; i < 8; i++) { 59771d10453SEric Joyner *key >>= 1; 59871d10453SEric Joyner *key_inv >>= 1; 59971d10453SEric Joyner 60071d10453SEric Joyner if (!(valid & 0x1)) { /* change only valid bits */ 60171d10453SEric Joyner *key |= (in_key & 0x1) << 7; 60271d10453SEric Joyner *key_inv |= (in_key_inv & 0x1) << 7; 60371d10453SEric Joyner } else if (dont_care & 0x1) { /* don't care bit */ 60471d10453SEric Joyner *key |= ICE_DC_KEY << 7; 60571d10453SEric Joyner *key_inv |= ICE_DC_KEYINV << 7; 60671d10453SEric Joyner } else if (nvr_mtch & 0x1) { /* never match bit */ 60771d10453SEric Joyner *key |= ICE_NM_KEY << 7; 60871d10453SEric Joyner *key_inv |= ICE_NM_KEYINV << 7; 60971d10453SEric Joyner } else if (val & 0x01) { /* exact 1 match */ 61071d10453SEric Joyner *key |= ICE_1_KEY << 7; 61171d10453SEric Joyner *key_inv |= ICE_1_KEYINV << 7; 61271d10453SEric Joyner } else { /* exact 0 match */ 61371d10453SEric Joyner *key |= ICE_0_KEY << 7; 61471d10453SEric Joyner *key_inv |= ICE_0_KEYINV << 7; 61571d10453SEric Joyner } 61671d10453SEric Joyner 61771d10453SEric Joyner dont_care >>= 1; 61871d10453SEric Joyner nvr_mtch >>= 1; 61971d10453SEric Joyner valid >>= 1; 62071d10453SEric Joyner val >>= 1; 62171d10453SEric Joyner in_key >>= 1; 62271d10453SEric Joyner in_key_inv >>= 1; 62371d10453SEric Joyner } 62471d10453SEric Joyner 62571d10453SEric Joyner return ICE_SUCCESS; 62671d10453SEric Joyner } 62771d10453SEric Joyner 62871d10453SEric Joyner /** 62971d10453SEric Joyner * ice_bits_max_set - determine if the number of bits set is within a maximum 63071d10453SEric Joyner * @mask: pointer to the byte array which is the mask 63171d10453SEric Joyner * @size: the number of bytes in the mask 63271d10453SEric Joyner * @max: the max number of set bits 63371d10453SEric Joyner * 63471d10453SEric Joyner * This function determines if there are at most 'max' number of bits set in an 63571d10453SEric Joyner * array. Returns true if the number for bits set is <= max or will return false 63671d10453SEric Joyner * otherwise. 63771d10453SEric Joyner */ 63871d10453SEric Joyner static bool ice_bits_max_set(const u8 *mask, u16 size, u16 max) 63971d10453SEric Joyner { 64071d10453SEric Joyner u16 count = 0; 64171d10453SEric Joyner u16 i; 64271d10453SEric Joyner 64371d10453SEric Joyner /* check each byte */ 64471d10453SEric Joyner for (i = 0; i < size; i++) { 64571d10453SEric Joyner /* if 0, go to next byte */ 64671d10453SEric Joyner if (!mask[i]) 64771d10453SEric Joyner continue; 64871d10453SEric Joyner 64971d10453SEric Joyner /* We know there is at least one set bit in this byte because of 65071d10453SEric Joyner * the above check; if we already have found 'max' number of 65171d10453SEric Joyner * bits set, then we can return failure now. 65271d10453SEric Joyner */ 65371d10453SEric Joyner if (count == max) 65471d10453SEric Joyner return false; 65571d10453SEric Joyner 65671d10453SEric Joyner /* count the bits in this byte, checking threshold */ 65771d10453SEric Joyner count += ice_hweight8(mask[i]); 65871d10453SEric Joyner if (count > max) 65971d10453SEric Joyner return false; 66071d10453SEric Joyner } 66171d10453SEric Joyner 66271d10453SEric Joyner return true; 66371d10453SEric Joyner } 66471d10453SEric Joyner 66571d10453SEric Joyner /** 66671d10453SEric Joyner * ice_set_key - generate a variable sized key with multiples of 16-bits 66771d10453SEric Joyner * @key: pointer to where the key will be stored 66871d10453SEric Joyner * @size: the size of the complete key in bytes (must be even) 66971d10453SEric Joyner * @val: array of 8-bit values that makes up the value portion of the key 67071d10453SEric Joyner * @upd: array of 8-bit masks that determine what key portion to update 67171d10453SEric Joyner * @dc: array of 8-bit masks that make up the don't care mask 67271d10453SEric Joyner * @nm: array of 8-bit masks that make up the never match mask 67371d10453SEric Joyner * @off: the offset of the first byte in the key to update 67471d10453SEric Joyner * @len: the number of bytes in the key update 67571d10453SEric Joyner * 67671d10453SEric Joyner * This function generates a key from a value, a don't care mask and a never 67771d10453SEric Joyner * match mask. 67871d10453SEric Joyner * upd, dc, and nm are optional parameters, and can be NULL: 679*7d7af7f8SEric Joyner * upd == NULL --> upd mask is all 1's (update all bits) 68071d10453SEric Joyner * dc == NULL --> dc mask is all 0's (no don't care bits) 68171d10453SEric Joyner * nm == NULL --> nm mask is all 0's (no never match bits) 68271d10453SEric Joyner */ 683*7d7af7f8SEric Joyner static enum ice_status 68471d10453SEric Joyner ice_set_key(u8 *key, u16 size, u8 *val, u8 *upd, u8 *dc, u8 *nm, u16 off, 68571d10453SEric Joyner u16 len) 68671d10453SEric Joyner { 68771d10453SEric Joyner u16 half_size; 68871d10453SEric Joyner u16 i; 68971d10453SEric Joyner 69071d10453SEric Joyner /* size must be a multiple of 2 bytes. */ 69171d10453SEric Joyner if (size % 2) 69271d10453SEric Joyner return ICE_ERR_CFG; 69371d10453SEric Joyner half_size = size / 2; 69471d10453SEric Joyner 69571d10453SEric Joyner if (off + len > half_size) 69671d10453SEric Joyner return ICE_ERR_CFG; 69771d10453SEric Joyner 69871d10453SEric Joyner /* Make sure at most one bit is set in the never match mask. Having more 69971d10453SEric Joyner * than one never match mask bit set will cause HW to consume excessive 70071d10453SEric Joyner * power otherwise; this is a power management efficiency check. 70171d10453SEric Joyner */ 70271d10453SEric Joyner #define ICE_NVR_MTCH_BITS_MAX 1 70371d10453SEric Joyner if (nm && !ice_bits_max_set(nm, len, ICE_NVR_MTCH_BITS_MAX)) 70471d10453SEric Joyner return ICE_ERR_CFG; 70571d10453SEric Joyner 70671d10453SEric Joyner for (i = 0; i < len; i++) 70771d10453SEric Joyner if (ice_gen_key_word(val[i], upd ? upd[i] : 0xff, 70871d10453SEric Joyner dc ? dc[i] : 0, nm ? nm[i] : 0, 70971d10453SEric Joyner key + off + i, key + half_size + off + i)) 71071d10453SEric Joyner return ICE_ERR_CFG; 71171d10453SEric Joyner 71271d10453SEric Joyner return ICE_SUCCESS; 71371d10453SEric Joyner } 71471d10453SEric Joyner 71571d10453SEric Joyner /** 71671d10453SEric Joyner * ice_acquire_global_cfg_lock 71771d10453SEric Joyner * @hw: pointer to the HW structure 71871d10453SEric Joyner * @access: access type (read or write) 71971d10453SEric Joyner * 72071d10453SEric Joyner * This function will request ownership of the global config lock for reading 72171d10453SEric Joyner * or writing of the package. When attempting to obtain write access, the 72271d10453SEric Joyner * caller must check for the following two return values: 72371d10453SEric Joyner * 72471d10453SEric Joyner * ICE_SUCCESS - Means the caller has acquired the global config lock 72571d10453SEric Joyner * and can perform writing of the package. 72671d10453SEric Joyner * ICE_ERR_AQ_NO_WORK - Indicates another driver has already written the 72771d10453SEric Joyner * package or has found that no update was necessary; in 72871d10453SEric Joyner * this case, the caller can just skip performing any 72971d10453SEric Joyner * update of the package. 73071d10453SEric Joyner */ 73171d10453SEric Joyner static enum ice_status 73271d10453SEric Joyner ice_acquire_global_cfg_lock(struct ice_hw *hw, 73371d10453SEric Joyner enum ice_aq_res_access_type access) 73471d10453SEric Joyner { 73571d10453SEric Joyner enum ice_status status; 73671d10453SEric Joyner 73771d10453SEric Joyner ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__); 73871d10453SEric Joyner 73971d10453SEric Joyner status = ice_acquire_res(hw, ICE_GLOBAL_CFG_LOCK_RES_ID, access, 74071d10453SEric Joyner ICE_GLOBAL_CFG_LOCK_TIMEOUT); 74171d10453SEric Joyner 74271d10453SEric Joyner if (status == ICE_ERR_AQ_NO_WORK) 743*7d7af7f8SEric Joyner ice_debug(hw, ICE_DBG_PKG, "Global config lock: No work to do\n"); 74471d10453SEric Joyner 74571d10453SEric Joyner return status; 74671d10453SEric Joyner } 74771d10453SEric Joyner 74871d10453SEric Joyner /** 74971d10453SEric Joyner * ice_release_global_cfg_lock 75071d10453SEric Joyner * @hw: pointer to the HW structure 75171d10453SEric Joyner * 75271d10453SEric Joyner * This function will release the global config lock. 75371d10453SEric Joyner */ 75471d10453SEric Joyner static void ice_release_global_cfg_lock(struct ice_hw *hw) 75571d10453SEric Joyner { 75671d10453SEric Joyner ice_release_res(hw, ICE_GLOBAL_CFG_LOCK_RES_ID); 75771d10453SEric Joyner } 75871d10453SEric Joyner 75971d10453SEric Joyner /** 76071d10453SEric Joyner * ice_acquire_change_lock 76171d10453SEric Joyner * @hw: pointer to the HW structure 76271d10453SEric Joyner * @access: access type (read or write) 76371d10453SEric Joyner * 76471d10453SEric Joyner * This function will request ownership of the change lock. 76571d10453SEric Joyner */ 766*7d7af7f8SEric Joyner static enum ice_status 76771d10453SEric Joyner ice_acquire_change_lock(struct ice_hw *hw, enum ice_aq_res_access_type access) 76871d10453SEric Joyner { 76971d10453SEric Joyner ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__); 77071d10453SEric Joyner 77171d10453SEric Joyner return ice_acquire_res(hw, ICE_CHANGE_LOCK_RES_ID, access, 77271d10453SEric Joyner ICE_CHANGE_LOCK_TIMEOUT); 77371d10453SEric Joyner } 77471d10453SEric Joyner 77571d10453SEric Joyner /** 77671d10453SEric Joyner * ice_release_change_lock 77771d10453SEric Joyner * @hw: pointer to the HW structure 77871d10453SEric Joyner * 77971d10453SEric Joyner * This function will release the change lock using the proper Admin Command. 78071d10453SEric Joyner */ 781*7d7af7f8SEric Joyner static void ice_release_change_lock(struct ice_hw *hw) 78271d10453SEric Joyner { 78371d10453SEric Joyner ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__); 78471d10453SEric Joyner 78571d10453SEric Joyner ice_release_res(hw, ICE_CHANGE_LOCK_RES_ID); 78671d10453SEric Joyner } 78771d10453SEric Joyner 78871d10453SEric Joyner /** 78971d10453SEric Joyner * ice_aq_download_pkg 79071d10453SEric Joyner * @hw: pointer to the hardware structure 79171d10453SEric Joyner * @pkg_buf: the package buffer to transfer 79271d10453SEric Joyner * @buf_size: the size of the package buffer 79371d10453SEric Joyner * @last_buf: last buffer indicator 79471d10453SEric Joyner * @error_offset: returns error offset 79571d10453SEric Joyner * @error_info: returns error information 79671d10453SEric Joyner * @cd: pointer to command details structure or NULL 79771d10453SEric Joyner * 79871d10453SEric Joyner * Download Package (0x0C40) 79971d10453SEric Joyner */ 80071d10453SEric Joyner static enum ice_status 80171d10453SEric Joyner ice_aq_download_pkg(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf, 80271d10453SEric Joyner u16 buf_size, bool last_buf, u32 *error_offset, 80371d10453SEric Joyner u32 *error_info, struct ice_sq_cd *cd) 80471d10453SEric Joyner { 80571d10453SEric Joyner struct ice_aqc_download_pkg *cmd; 80671d10453SEric Joyner struct ice_aq_desc desc; 80771d10453SEric Joyner enum ice_status status; 80871d10453SEric Joyner 80971d10453SEric Joyner ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__); 81071d10453SEric Joyner 81171d10453SEric Joyner if (error_offset) 81271d10453SEric Joyner *error_offset = 0; 81371d10453SEric Joyner if (error_info) 81471d10453SEric Joyner *error_info = 0; 81571d10453SEric Joyner 81671d10453SEric Joyner cmd = &desc.params.download_pkg; 81771d10453SEric Joyner ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_download_pkg); 81871d10453SEric Joyner desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD); 81971d10453SEric Joyner 82071d10453SEric Joyner if (last_buf) 82171d10453SEric Joyner cmd->flags |= ICE_AQC_DOWNLOAD_PKG_LAST_BUF; 82271d10453SEric Joyner 82371d10453SEric Joyner status = ice_aq_send_cmd(hw, &desc, pkg_buf, buf_size, cd); 82471d10453SEric Joyner if (status == ICE_ERR_AQ_ERROR) { 82571d10453SEric Joyner /* Read error from buffer only when the FW returned an error */ 82671d10453SEric Joyner struct ice_aqc_download_pkg_resp *resp; 82771d10453SEric Joyner 82871d10453SEric Joyner resp = (struct ice_aqc_download_pkg_resp *)pkg_buf; 82971d10453SEric Joyner if (error_offset) 83071d10453SEric Joyner *error_offset = LE32_TO_CPU(resp->error_offset); 83171d10453SEric Joyner if (error_info) 83271d10453SEric Joyner *error_info = LE32_TO_CPU(resp->error_info); 83371d10453SEric Joyner } 83471d10453SEric Joyner 83571d10453SEric Joyner return status; 83671d10453SEric Joyner } 83771d10453SEric Joyner 83871d10453SEric Joyner /** 83971d10453SEric Joyner * ice_aq_upload_section 84071d10453SEric Joyner * @hw: pointer to the hardware structure 84171d10453SEric Joyner * @pkg_buf: the package buffer which will receive the section 84271d10453SEric Joyner * @buf_size: the size of the package buffer 84371d10453SEric Joyner * @cd: pointer to command details structure or NULL 84471d10453SEric Joyner * 84571d10453SEric Joyner * Upload Section (0x0C41) 84671d10453SEric Joyner */ 84771d10453SEric Joyner enum ice_status 84871d10453SEric Joyner ice_aq_upload_section(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf, 84971d10453SEric Joyner u16 buf_size, struct ice_sq_cd *cd) 85071d10453SEric Joyner { 85171d10453SEric Joyner struct ice_aq_desc desc; 85271d10453SEric Joyner 85371d10453SEric Joyner ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__); 85471d10453SEric Joyner ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_upload_section); 85571d10453SEric Joyner desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD); 85671d10453SEric Joyner 85771d10453SEric Joyner return ice_aq_send_cmd(hw, &desc, pkg_buf, buf_size, cd); 85871d10453SEric Joyner } 85971d10453SEric Joyner 86071d10453SEric Joyner /** 86171d10453SEric Joyner * ice_aq_update_pkg 86271d10453SEric Joyner * @hw: pointer to the hardware structure 86371d10453SEric Joyner * @pkg_buf: the package cmd buffer 86471d10453SEric Joyner * @buf_size: the size of the package cmd buffer 86571d10453SEric Joyner * @last_buf: last buffer indicator 86671d10453SEric Joyner * @error_offset: returns error offset 86771d10453SEric Joyner * @error_info: returns error information 86871d10453SEric Joyner * @cd: pointer to command details structure or NULL 86971d10453SEric Joyner * 87071d10453SEric Joyner * Update Package (0x0C42) 87171d10453SEric Joyner */ 87271d10453SEric Joyner static enum ice_status 87371d10453SEric Joyner ice_aq_update_pkg(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf, u16 buf_size, 87471d10453SEric Joyner bool last_buf, u32 *error_offset, u32 *error_info, 87571d10453SEric Joyner struct ice_sq_cd *cd) 87671d10453SEric Joyner { 87771d10453SEric Joyner struct ice_aqc_download_pkg *cmd; 87871d10453SEric Joyner struct ice_aq_desc desc; 87971d10453SEric Joyner enum ice_status status; 88071d10453SEric Joyner 88171d10453SEric Joyner ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__); 88271d10453SEric Joyner 88371d10453SEric Joyner if (error_offset) 88471d10453SEric Joyner *error_offset = 0; 88571d10453SEric Joyner if (error_info) 88671d10453SEric Joyner *error_info = 0; 88771d10453SEric Joyner 88871d10453SEric Joyner cmd = &desc.params.download_pkg; 88971d10453SEric Joyner ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_update_pkg); 89071d10453SEric Joyner desc.flags |= CPU_TO_LE16(ICE_AQ_FLAG_RD); 89171d10453SEric Joyner 89271d10453SEric Joyner if (last_buf) 89371d10453SEric Joyner cmd->flags |= ICE_AQC_DOWNLOAD_PKG_LAST_BUF; 89471d10453SEric Joyner 89571d10453SEric Joyner status = ice_aq_send_cmd(hw, &desc, pkg_buf, buf_size, cd); 89671d10453SEric Joyner if (status == ICE_ERR_AQ_ERROR) { 89771d10453SEric Joyner /* Read error from buffer only when the FW returned an error */ 89871d10453SEric Joyner struct ice_aqc_download_pkg_resp *resp; 89971d10453SEric Joyner 90071d10453SEric Joyner resp = (struct ice_aqc_download_pkg_resp *)pkg_buf; 90171d10453SEric Joyner if (error_offset) 90271d10453SEric Joyner *error_offset = LE32_TO_CPU(resp->error_offset); 90371d10453SEric Joyner if (error_info) 90471d10453SEric Joyner *error_info = LE32_TO_CPU(resp->error_info); 90571d10453SEric Joyner } 90671d10453SEric Joyner 90771d10453SEric Joyner return status; 90871d10453SEric Joyner } 90971d10453SEric Joyner 91071d10453SEric Joyner /** 91171d10453SEric Joyner * ice_find_seg_in_pkg 91271d10453SEric Joyner * @hw: pointer to the hardware structure 91371d10453SEric Joyner * @seg_type: the segment type to search for (i.e., SEGMENT_TYPE_CPK) 91471d10453SEric Joyner * @pkg_hdr: pointer to the package header to be searched 91571d10453SEric Joyner * 91671d10453SEric Joyner * This function searches a package file for a particular segment type. On 91771d10453SEric Joyner * success it returns a pointer to the segment header, otherwise it will 91871d10453SEric Joyner * return NULL. 91971d10453SEric Joyner */ 92071d10453SEric Joyner static struct ice_generic_seg_hdr * 92171d10453SEric Joyner ice_find_seg_in_pkg(struct ice_hw *hw, u32 seg_type, 92271d10453SEric Joyner struct ice_pkg_hdr *pkg_hdr) 92371d10453SEric Joyner { 92471d10453SEric Joyner u32 i; 92571d10453SEric Joyner 92671d10453SEric Joyner ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__); 92771d10453SEric Joyner ice_debug(hw, ICE_DBG_PKG, "Package format version: %d.%d.%d.%d\n", 92871d10453SEric Joyner pkg_hdr->pkg_format_ver.major, pkg_hdr->pkg_format_ver.minor, 92971d10453SEric Joyner pkg_hdr->pkg_format_ver.update, 93071d10453SEric Joyner pkg_hdr->pkg_format_ver.draft); 93171d10453SEric Joyner 93271d10453SEric Joyner /* Search all package segments for the requested segment type */ 93371d10453SEric Joyner for (i = 0; i < LE32_TO_CPU(pkg_hdr->seg_count); i++) { 93471d10453SEric Joyner struct ice_generic_seg_hdr *seg; 93571d10453SEric Joyner 93671d10453SEric Joyner seg = (struct ice_generic_seg_hdr *) 93771d10453SEric Joyner ((u8 *)pkg_hdr + LE32_TO_CPU(pkg_hdr->seg_offset[i])); 93871d10453SEric Joyner 93971d10453SEric Joyner if (LE32_TO_CPU(seg->seg_type) == seg_type) 94071d10453SEric Joyner return seg; 94171d10453SEric Joyner } 94271d10453SEric Joyner 94371d10453SEric Joyner return NULL; 94471d10453SEric Joyner } 94571d10453SEric Joyner 94671d10453SEric Joyner /** 94771d10453SEric Joyner * ice_update_pkg 94871d10453SEric Joyner * @hw: pointer to the hardware structure 94971d10453SEric Joyner * @bufs: pointer to an array of buffers 95071d10453SEric Joyner * @count: the number of buffers in the array 95171d10453SEric Joyner * 95271d10453SEric Joyner * Obtains change lock and updates package. 95371d10453SEric Joyner */ 95471d10453SEric Joyner enum ice_status 95571d10453SEric Joyner ice_update_pkg(struct ice_hw *hw, struct ice_buf *bufs, u32 count) 95671d10453SEric Joyner { 95771d10453SEric Joyner enum ice_status status; 95871d10453SEric Joyner u32 offset, info, i; 95971d10453SEric Joyner 96071d10453SEric Joyner status = ice_acquire_change_lock(hw, ICE_RES_WRITE); 96171d10453SEric Joyner if (status) 96271d10453SEric Joyner return status; 96371d10453SEric Joyner 96471d10453SEric Joyner for (i = 0; i < count; i++) { 96571d10453SEric Joyner struct ice_buf_hdr *bh = (struct ice_buf_hdr *)(bufs + i); 96671d10453SEric Joyner bool last = ((i + 1) == count); 96771d10453SEric Joyner 96871d10453SEric Joyner status = ice_aq_update_pkg(hw, bh, LE16_TO_CPU(bh->data_end), 96971d10453SEric Joyner last, &offset, &info, NULL); 97071d10453SEric Joyner 97171d10453SEric Joyner if (status) { 972*7d7af7f8SEric Joyner ice_debug(hw, ICE_DBG_PKG, "Update pkg failed: err %d off %d inf %d\n", 97371d10453SEric Joyner status, offset, info); 97471d10453SEric Joyner break; 97571d10453SEric Joyner } 97671d10453SEric Joyner } 97771d10453SEric Joyner 97871d10453SEric Joyner ice_release_change_lock(hw); 97971d10453SEric Joyner 98071d10453SEric Joyner return status; 98171d10453SEric Joyner } 98271d10453SEric Joyner 98371d10453SEric Joyner /** 98471d10453SEric Joyner * ice_dwnld_cfg_bufs 98571d10453SEric Joyner * @hw: pointer to the hardware structure 98671d10453SEric Joyner * @bufs: pointer to an array of buffers 98771d10453SEric Joyner * @count: the number of buffers in the array 98871d10453SEric Joyner * 98971d10453SEric Joyner * Obtains global config lock and downloads the package configuration buffers 99071d10453SEric Joyner * to the firmware. Metadata buffers are skipped, and the first metadata buffer 99171d10453SEric Joyner * found indicates that the rest of the buffers are all metadata buffers. 99271d10453SEric Joyner */ 99371d10453SEric Joyner static enum ice_status 99471d10453SEric Joyner ice_dwnld_cfg_bufs(struct ice_hw *hw, struct ice_buf *bufs, u32 count) 99571d10453SEric Joyner { 99671d10453SEric Joyner enum ice_status status; 99771d10453SEric Joyner struct ice_buf_hdr *bh; 99871d10453SEric Joyner u32 offset, info, i; 99971d10453SEric Joyner 100071d10453SEric Joyner if (!bufs || !count) 100171d10453SEric Joyner return ICE_ERR_PARAM; 100271d10453SEric Joyner 100371d10453SEric Joyner /* If the first buffer's first section has its metadata bit set 100471d10453SEric Joyner * then there are no buffers to be downloaded, and the operation is 100571d10453SEric Joyner * considered a success. 100671d10453SEric Joyner */ 100771d10453SEric Joyner bh = (struct ice_buf_hdr *)bufs; 100871d10453SEric Joyner if (LE32_TO_CPU(bh->section_entry[0].type) & ICE_METADATA_BUF) 100971d10453SEric Joyner return ICE_SUCCESS; 101071d10453SEric Joyner 101171d10453SEric Joyner /* reset pkg_dwnld_status in case this function is called in the 101271d10453SEric Joyner * reset/rebuild flow 101371d10453SEric Joyner */ 101471d10453SEric Joyner hw->pkg_dwnld_status = ICE_AQ_RC_OK; 101571d10453SEric Joyner 101671d10453SEric Joyner status = ice_acquire_global_cfg_lock(hw, ICE_RES_WRITE); 101771d10453SEric Joyner if (status) { 101871d10453SEric Joyner if (status == ICE_ERR_AQ_NO_WORK) 101971d10453SEric Joyner hw->pkg_dwnld_status = ICE_AQ_RC_EEXIST; 102071d10453SEric Joyner else 102171d10453SEric Joyner hw->pkg_dwnld_status = hw->adminq.sq_last_status; 102271d10453SEric Joyner return status; 102371d10453SEric Joyner } 102471d10453SEric Joyner 102571d10453SEric Joyner for (i = 0; i < count; i++) { 102671d10453SEric Joyner bool last = ((i + 1) == count); 102771d10453SEric Joyner 102871d10453SEric Joyner if (!last) { 102971d10453SEric Joyner /* check next buffer for metadata flag */ 103071d10453SEric Joyner bh = (struct ice_buf_hdr *)(bufs + i + 1); 103171d10453SEric Joyner 103271d10453SEric Joyner /* A set metadata flag in the next buffer will signal 103371d10453SEric Joyner * that the current buffer will be the last buffer 103471d10453SEric Joyner * downloaded 103571d10453SEric Joyner */ 103671d10453SEric Joyner if (LE16_TO_CPU(bh->section_count)) 103771d10453SEric Joyner if (LE32_TO_CPU(bh->section_entry[0].type) & 103871d10453SEric Joyner ICE_METADATA_BUF) 103971d10453SEric Joyner last = true; 104071d10453SEric Joyner } 104171d10453SEric Joyner 104271d10453SEric Joyner bh = (struct ice_buf_hdr *)(bufs + i); 104371d10453SEric Joyner 104471d10453SEric Joyner status = ice_aq_download_pkg(hw, bh, ICE_PKG_BUF_SIZE, last, 104571d10453SEric Joyner &offset, &info, NULL); 104671d10453SEric Joyner 104771d10453SEric Joyner /* Save AQ status from download package */ 104871d10453SEric Joyner hw->pkg_dwnld_status = hw->adminq.sq_last_status; 104971d10453SEric Joyner if (status) { 1050*7d7af7f8SEric Joyner ice_debug(hw, ICE_DBG_PKG, "Pkg download failed: err %d off %d inf %d\n", 105171d10453SEric Joyner status, offset, info); 105271d10453SEric Joyner 105371d10453SEric Joyner break; 105471d10453SEric Joyner } 105571d10453SEric Joyner 105671d10453SEric Joyner if (last) 105771d10453SEric Joyner break; 105871d10453SEric Joyner } 105971d10453SEric Joyner 106071d10453SEric Joyner ice_release_global_cfg_lock(hw); 106171d10453SEric Joyner 106271d10453SEric Joyner return status; 106371d10453SEric Joyner } 106471d10453SEric Joyner 106571d10453SEric Joyner /** 106671d10453SEric Joyner * ice_aq_get_pkg_info_list 106771d10453SEric Joyner * @hw: pointer to the hardware structure 106871d10453SEric Joyner * @pkg_info: the buffer which will receive the information list 106971d10453SEric Joyner * @buf_size: the size of the pkg_info information buffer 107071d10453SEric Joyner * @cd: pointer to command details structure or NULL 107171d10453SEric Joyner * 107271d10453SEric Joyner * Get Package Info List (0x0C43) 107371d10453SEric Joyner */ 107471d10453SEric Joyner static enum ice_status 107571d10453SEric Joyner ice_aq_get_pkg_info_list(struct ice_hw *hw, 107671d10453SEric Joyner struct ice_aqc_get_pkg_info_resp *pkg_info, 107771d10453SEric Joyner u16 buf_size, struct ice_sq_cd *cd) 107871d10453SEric Joyner { 107971d10453SEric Joyner struct ice_aq_desc desc; 108071d10453SEric Joyner 108171d10453SEric Joyner ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__); 108271d10453SEric Joyner ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_pkg_info_list); 108371d10453SEric Joyner 108471d10453SEric Joyner return ice_aq_send_cmd(hw, &desc, pkg_info, buf_size, cd); 108571d10453SEric Joyner } 108671d10453SEric Joyner 108771d10453SEric Joyner /** 108871d10453SEric Joyner * ice_download_pkg 108971d10453SEric Joyner * @hw: pointer to the hardware structure 109071d10453SEric Joyner * @ice_seg: pointer to the segment of the package to be downloaded 109171d10453SEric Joyner * 109271d10453SEric Joyner * Handles the download of a complete package. 109371d10453SEric Joyner */ 109471d10453SEric Joyner static enum ice_status 109571d10453SEric Joyner ice_download_pkg(struct ice_hw *hw, struct ice_seg *ice_seg) 109671d10453SEric Joyner { 109771d10453SEric Joyner struct ice_buf_table *ice_buf_tbl; 109871d10453SEric Joyner 109971d10453SEric Joyner ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__); 110071d10453SEric Joyner ice_debug(hw, ICE_DBG_PKG, "Segment format version: %d.%d.%d.%d\n", 110171d10453SEric Joyner ice_seg->hdr.seg_format_ver.major, 110271d10453SEric Joyner ice_seg->hdr.seg_format_ver.minor, 110371d10453SEric Joyner ice_seg->hdr.seg_format_ver.update, 110471d10453SEric Joyner ice_seg->hdr.seg_format_ver.draft); 110571d10453SEric Joyner 110671d10453SEric Joyner ice_debug(hw, ICE_DBG_PKG, "Seg: type 0x%X, size %d, name %s\n", 110771d10453SEric Joyner LE32_TO_CPU(ice_seg->hdr.seg_type), 110871d10453SEric Joyner LE32_TO_CPU(ice_seg->hdr.seg_size), ice_seg->hdr.seg_id); 110971d10453SEric Joyner 111071d10453SEric Joyner ice_buf_tbl = ice_find_buf_table(ice_seg); 111171d10453SEric Joyner 111271d10453SEric Joyner ice_debug(hw, ICE_DBG_PKG, "Seg buf count: %d\n", 111371d10453SEric Joyner LE32_TO_CPU(ice_buf_tbl->buf_count)); 111471d10453SEric Joyner 111571d10453SEric Joyner return ice_dwnld_cfg_bufs(hw, ice_buf_tbl->buf_array, 111671d10453SEric Joyner LE32_TO_CPU(ice_buf_tbl->buf_count)); 111771d10453SEric Joyner } 111871d10453SEric Joyner 111971d10453SEric Joyner /** 112071d10453SEric Joyner * ice_init_pkg_info 112171d10453SEric Joyner * @hw: pointer to the hardware structure 112271d10453SEric Joyner * @pkg_hdr: pointer to the driver's package hdr 112371d10453SEric Joyner * 112471d10453SEric Joyner * Saves off the package details into the HW structure. 112571d10453SEric Joyner */ 112671d10453SEric Joyner static enum ice_status 112771d10453SEric Joyner ice_init_pkg_info(struct ice_hw *hw, struct ice_pkg_hdr *pkg_hdr) 112871d10453SEric Joyner { 112971d10453SEric Joyner struct ice_global_metadata_seg *meta_seg; 113071d10453SEric Joyner struct ice_generic_seg_hdr *seg_hdr; 113171d10453SEric Joyner 113271d10453SEric Joyner ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__); 113371d10453SEric Joyner if (!pkg_hdr) 113471d10453SEric Joyner return ICE_ERR_PARAM; 113571d10453SEric Joyner 113671d10453SEric Joyner meta_seg = (struct ice_global_metadata_seg *) 113771d10453SEric Joyner ice_find_seg_in_pkg(hw, SEGMENT_TYPE_METADATA, pkg_hdr); 113871d10453SEric Joyner if (meta_seg) { 113971d10453SEric Joyner hw->pkg_ver = meta_seg->pkg_ver; 114071d10453SEric Joyner ice_memcpy(hw->pkg_name, meta_seg->pkg_name, 114171d10453SEric Joyner sizeof(hw->pkg_name), ICE_NONDMA_TO_NONDMA); 114271d10453SEric Joyner 114371d10453SEric Joyner ice_debug(hw, ICE_DBG_PKG, "Pkg: %d.%d.%d.%d, %s\n", 114471d10453SEric Joyner meta_seg->pkg_ver.major, meta_seg->pkg_ver.minor, 114571d10453SEric Joyner meta_seg->pkg_ver.update, meta_seg->pkg_ver.draft, 114671d10453SEric Joyner meta_seg->pkg_name); 114771d10453SEric Joyner } else { 1148*7d7af7f8SEric Joyner ice_debug(hw, ICE_DBG_INIT, "Did not find metadata segment in driver package\n"); 114971d10453SEric Joyner return ICE_ERR_CFG; 115071d10453SEric Joyner } 115171d10453SEric Joyner 115271d10453SEric Joyner seg_hdr = ice_find_seg_in_pkg(hw, SEGMENT_TYPE_ICE, pkg_hdr); 115371d10453SEric Joyner if (seg_hdr) { 115471d10453SEric Joyner hw->ice_pkg_ver = seg_hdr->seg_format_ver; 115571d10453SEric Joyner ice_memcpy(hw->ice_pkg_name, seg_hdr->seg_id, 115671d10453SEric Joyner sizeof(hw->ice_pkg_name), ICE_NONDMA_TO_NONDMA); 115771d10453SEric Joyner 115871d10453SEric Joyner ice_debug(hw, ICE_DBG_PKG, "Ice Seg: %d.%d.%d.%d, %s\n", 115971d10453SEric Joyner seg_hdr->seg_format_ver.major, 116071d10453SEric Joyner seg_hdr->seg_format_ver.minor, 116171d10453SEric Joyner seg_hdr->seg_format_ver.update, 116271d10453SEric Joyner seg_hdr->seg_format_ver.draft, 116371d10453SEric Joyner seg_hdr->seg_id); 116471d10453SEric Joyner } else { 1165*7d7af7f8SEric Joyner ice_debug(hw, ICE_DBG_INIT, "Did not find ice segment in driver package\n"); 116671d10453SEric Joyner return ICE_ERR_CFG; 116771d10453SEric Joyner } 116871d10453SEric Joyner 116971d10453SEric Joyner return ICE_SUCCESS; 117071d10453SEric Joyner } 117171d10453SEric Joyner 117271d10453SEric Joyner /** 117371d10453SEric Joyner * ice_get_pkg_info 117471d10453SEric Joyner * @hw: pointer to the hardware structure 117571d10453SEric Joyner * 117671d10453SEric Joyner * Store details of the package currently loaded in HW into the HW structure. 117771d10453SEric Joyner */ 117871d10453SEric Joyner static enum ice_status ice_get_pkg_info(struct ice_hw *hw) 117971d10453SEric Joyner { 118071d10453SEric Joyner struct ice_aqc_get_pkg_info_resp *pkg_info; 118171d10453SEric Joyner enum ice_status status; 118271d10453SEric Joyner u16 size; 118371d10453SEric Joyner u32 i; 118471d10453SEric Joyner 118571d10453SEric Joyner ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__); 118671d10453SEric Joyner 1187*7d7af7f8SEric Joyner size = ice_struct_size(pkg_info, pkg_info, ICE_PKG_CNT); 118871d10453SEric Joyner pkg_info = (struct ice_aqc_get_pkg_info_resp *)ice_malloc(hw, size); 118971d10453SEric Joyner if (!pkg_info) 119071d10453SEric Joyner return ICE_ERR_NO_MEMORY; 119171d10453SEric Joyner 119271d10453SEric Joyner status = ice_aq_get_pkg_info_list(hw, pkg_info, size, NULL); 119371d10453SEric Joyner if (status) 119471d10453SEric Joyner goto init_pkg_free_alloc; 119571d10453SEric Joyner 119671d10453SEric Joyner for (i = 0; i < LE32_TO_CPU(pkg_info->count); i++) { 119771d10453SEric Joyner #define ICE_PKG_FLAG_COUNT 4 119871d10453SEric Joyner char flags[ICE_PKG_FLAG_COUNT + 1] = { 0 }; 119971d10453SEric Joyner u8 place = 0; 120071d10453SEric Joyner 120171d10453SEric Joyner if (pkg_info->pkg_info[i].is_active) { 120271d10453SEric Joyner flags[place++] = 'A'; 120371d10453SEric Joyner hw->active_pkg_ver = pkg_info->pkg_info[i].ver; 120471d10453SEric Joyner hw->active_track_id = 120571d10453SEric Joyner LE32_TO_CPU(pkg_info->pkg_info[i].track_id); 120671d10453SEric Joyner ice_memcpy(hw->active_pkg_name, 120771d10453SEric Joyner pkg_info->pkg_info[i].name, 120871d10453SEric Joyner sizeof(pkg_info->pkg_info[i].name), 120971d10453SEric Joyner ICE_NONDMA_TO_NONDMA); 121071d10453SEric Joyner hw->active_pkg_in_nvm = pkg_info->pkg_info[i].is_in_nvm; 121171d10453SEric Joyner } 121271d10453SEric Joyner if (pkg_info->pkg_info[i].is_active_at_boot) 121371d10453SEric Joyner flags[place++] = 'B'; 121471d10453SEric Joyner if (pkg_info->pkg_info[i].is_modified) 121571d10453SEric Joyner flags[place++] = 'M'; 121671d10453SEric Joyner if (pkg_info->pkg_info[i].is_in_nvm) 121771d10453SEric Joyner flags[place++] = 'N'; 121871d10453SEric Joyner 121971d10453SEric Joyner ice_debug(hw, ICE_DBG_PKG, "Pkg[%d]: %d.%d.%d.%d,%s,%s\n", 122071d10453SEric Joyner i, pkg_info->pkg_info[i].ver.major, 122171d10453SEric Joyner pkg_info->pkg_info[i].ver.minor, 122271d10453SEric Joyner pkg_info->pkg_info[i].ver.update, 122371d10453SEric Joyner pkg_info->pkg_info[i].ver.draft, 122471d10453SEric Joyner pkg_info->pkg_info[i].name, flags); 122571d10453SEric Joyner } 122671d10453SEric Joyner 122771d10453SEric Joyner init_pkg_free_alloc: 122871d10453SEric Joyner ice_free(hw, pkg_info); 122971d10453SEric Joyner 123071d10453SEric Joyner return status; 123171d10453SEric Joyner } 123271d10453SEric Joyner 123371d10453SEric Joyner /** 123471d10453SEric Joyner * ice_find_label_value 123571d10453SEric Joyner * @ice_seg: pointer to the ice segment (non-NULL) 123671d10453SEric Joyner * @name: name of the label to search for 123771d10453SEric Joyner * @type: the section type that will contain the label 123871d10453SEric Joyner * @value: pointer to a value that will return the label's value if found 123971d10453SEric Joyner * 124071d10453SEric Joyner * Finds a label's value given the label name and the section type to search. 124171d10453SEric Joyner * The ice_seg parameter must not be NULL since the first call to 124271d10453SEric Joyner * ice_enum_labels requires a pointer to an actual ice_seg structure. 124371d10453SEric Joyner */ 124471d10453SEric Joyner enum ice_status 124571d10453SEric Joyner ice_find_label_value(struct ice_seg *ice_seg, char const *name, u32 type, 124671d10453SEric Joyner u16 *value) 124771d10453SEric Joyner { 124871d10453SEric Joyner struct ice_pkg_enum state; 124971d10453SEric Joyner char *label_name; 125071d10453SEric Joyner u16 val; 125171d10453SEric Joyner 125271d10453SEric Joyner ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM); 125371d10453SEric Joyner 125471d10453SEric Joyner if (!ice_seg) 125571d10453SEric Joyner return ICE_ERR_PARAM; 125671d10453SEric Joyner 125771d10453SEric Joyner do { 125871d10453SEric Joyner label_name = ice_enum_labels(ice_seg, type, &state, &val); 125971d10453SEric Joyner if (label_name && !strcmp(label_name, name)) { 126071d10453SEric Joyner *value = val; 126171d10453SEric Joyner return ICE_SUCCESS; 126271d10453SEric Joyner } 126371d10453SEric Joyner 126471d10453SEric Joyner ice_seg = NULL; 126571d10453SEric Joyner } while (label_name); 126671d10453SEric Joyner 126771d10453SEric Joyner return ICE_ERR_CFG; 126871d10453SEric Joyner } 126971d10453SEric Joyner 127071d10453SEric Joyner /** 127171d10453SEric Joyner * ice_verify_pkg - verify package 127271d10453SEric Joyner * @pkg: pointer to the package buffer 127371d10453SEric Joyner * @len: size of the package buffer 127471d10453SEric Joyner * 127571d10453SEric Joyner * Verifies various attributes of the package file, including length, format 127671d10453SEric Joyner * version, and the requirement of at least one segment. 127771d10453SEric Joyner */ 127871d10453SEric Joyner static enum ice_status ice_verify_pkg(struct ice_pkg_hdr *pkg, u32 len) 127971d10453SEric Joyner { 128071d10453SEric Joyner u32 seg_count; 128171d10453SEric Joyner u32 i; 128271d10453SEric Joyner 1283*7d7af7f8SEric Joyner if (len < ice_struct_size(pkg, seg_offset, 1)) 128471d10453SEric Joyner return ICE_ERR_BUF_TOO_SHORT; 128571d10453SEric Joyner 128671d10453SEric Joyner if (pkg->pkg_format_ver.major != ICE_PKG_FMT_VER_MAJ || 128771d10453SEric Joyner pkg->pkg_format_ver.minor != ICE_PKG_FMT_VER_MNR || 128871d10453SEric Joyner pkg->pkg_format_ver.update != ICE_PKG_FMT_VER_UPD || 128971d10453SEric Joyner pkg->pkg_format_ver.draft != ICE_PKG_FMT_VER_DFT) 129071d10453SEric Joyner return ICE_ERR_CFG; 129171d10453SEric Joyner 129271d10453SEric Joyner /* pkg must have at least one segment */ 129371d10453SEric Joyner seg_count = LE32_TO_CPU(pkg->seg_count); 129471d10453SEric Joyner if (seg_count < 1) 129571d10453SEric Joyner return ICE_ERR_CFG; 129671d10453SEric Joyner 129771d10453SEric Joyner /* make sure segment array fits in package length */ 1298*7d7af7f8SEric Joyner if (len < ice_struct_size(pkg, seg_offset, seg_count)) 129971d10453SEric Joyner return ICE_ERR_BUF_TOO_SHORT; 130071d10453SEric Joyner 130171d10453SEric Joyner /* all segments must fit within length */ 130271d10453SEric Joyner for (i = 0; i < seg_count; i++) { 130371d10453SEric Joyner u32 off = LE32_TO_CPU(pkg->seg_offset[i]); 130471d10453SEric Joyner struct ice_generic_seg_hdr *seg; 130571d10453SEric Joyner 130671d10453SEric Joyner /* segment header must fit */ 130771d10453SEric Joyner if (len < off + sizeof(*seg)) 130871d10453SEric Joyner return ICE_ERR_BUF_TOO_SHORT; 130971d10453SEric Joyner 131071d10453SEric Joyner seg = (struct ice_generic_seg_hdr *)((u8 *)pkg + off); 131171d10453SEric Joyner 131271d10453SEric Joyner /* segment body must fit */ 131371d10453SEric Joyner if (len < off + LE32_TO_CPU(seg->seg_size)) 131471d10453SEric Joyner return ICE_ERR_BUF_TOO_SHORT; 131571d10453SEric Joyner } 131671d10453SEric Joyner 131771d10453SEric Joyner return ICE_SUCCESS; 131871d10453SEric Joyner } 131971d10453SEric Joyner 132071d10453SEric Joyner /** 132171d10453SEric Joyner * ice_free_seg - free package segment pointer 132271d10453SEric Joyner * @hw: pointer to the hardware structure 132371d10453SEric Joyner * 132471d10453SEric Joyner * Frees the package segment pointer in the proper manner, depending on if the 132571d10453SEric Joyner * segment was allocated or just the passed in pointer was stored. 132671d10453SEric Joyner */ 132771d10453SEric Joyner void ice_free_seg(struct ice_hw *hw) 132871d10453SEric Joyner { 132971d10453SEric Joyner if (hw->pkg_copy) { 133071d10453SEric Joyner ice_free(hw, hw->pkg_copy); 133171d10453SEric Joyner hw->pkg_copy = NULL; 133271d10453SEric Joyner hw->pkg_size = 0; 133371d10453SEric Joyner } 133471d10453SEric Joyner hw->seg = NULL; 133571d10453SEric Joyner } 133671d10453SEric Joyner 133771d10453SEric Joyner /** 133871d10453SEric Joyner * ice_init_pkg_regs - initialize additional package registers 133971d10453SEric Joyner * @hw: pointer to the hardware structure 134071d10453SEric Joyner */ 134171d10453SEric Joyner static void ice_init_pkg_regs(struct ice_hw *hw) 134271d10453SEric Joyner { 134371d10453SEric Joyner #define ICE_SW_BLK_INP_MASK_L 0xFFFFFFFF 134471d10453SEric Joyner #define ICE_SW_BLK_INP_MASK_H 0x0000FFFF 134571d10453SEric Joyner #define ICE_SW_BLK_IDX 0 134671d10453SEric Joyner 134771d10453SEric Joyner /* setup Switch block input mask, which is 48-bits in two parts */ 134871d10453SEric Joyner wr32(hw, GL_PREEXT_L2_PMASK0(ICE_SW_BLK_IDX), ICE_SW_BLK_INP_MASK_L); 134971d10453SEric Joyner wr32(hw, GL_PREEXT_L2_PMASK1(ICE_SW_BLK_IDX), ICE_SW_BLK_INP_MASK_H); 135071d10453SEric Joyner } 135171d10453SEric Joyner 135271d10453SEric Joyner /** 135371d10453SEric Joyner * ice_chk_pkg_version - check package version for compatibility with driver 135471d10453SEric Joyner * @pkg_ver: pointer to a version structure to check 135571d10453SEric Joyner * 135671d10453SEric Joyner * Check to make sure that the package about to be downloaded is compatible with 135771d10453SEric Joyner * the driver. To be compatible, the major and minor components of the package 135871d10453SEric Joyner * version must match our ICE_PKG_SUPP_VER_MAJ and ICE_PKG_SUPP_VER_MNR 135971d10453SEric Joyner * definitions. 136071d10453SEric Joyner */ 136171d10453SEric Joyner static enum ice_status ice_chk_pkg_version(struct ice_pkg_ver *pkg_ver) 136271d10453SEric Joyner { 136371d10453SEric Joyner if (pkg_ver->major != ICE_PKG_SUPP_VER_MAJ || 136471d10453SEric Joyner pkg_ver->minor != ICE_PKG_SUPP_VER_MNR) 136571d10453SEric Joyner return ICE_ERR_NOT_SUPPORTED; 136671d10453SEric Joyner 136771d10453SEric Joyner return ICE_SUCCESS; 136871d10453SEric Joyner } 136971d10453SEric Joyner 137071d10453SEric Joyner /** 137171d10453SEric Joyner * ice_chk_pkg_compat 137271d10453SEric Joyner * @hw: pointer to the hardware structure 137371d10453SEric Joyner * @ospkg: pointer to the package hdr 137471d10453SEric Joyner * @seg: pointer to the package segment hdr 137571d10453SEric Joyner * 137671d10453SEric Joyner * This function checks the package version compatibility with driver and NVM 137771d10453SEric Joyner */ 137871d10453SEric Joyner static enum ice_status 137971d10453SEric Joyner ice_chk_pkg_compat(struct ice_hw *hw, struct ice_pkg_hdr *ospkg, 138071d10453SEric Joyner struct ice_seg **seg) 138171d10453SEric Joyner { 138271d10453SEric Joyner struct ice_aqc_get_pkg_info_resp *pkg; 138371d10453SEric Joyner enum ice_status status; 138471d10453SEric Joyner u16 size; 138571d10453SEric Joyner u32 i; 138671d10453SEric Joyner 138771d10453SEric Joyner ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__); 138871d10453SEric Joyner 138971d10453SEric Joyner /* Check package version compatibility */ 139071d10453SEric Joyner status = ice_chk_pkg_version(&hw->pkg_ver); 139171d10453SEric Joyner if (status) { 139271d10453SEric Joyner ice_debug(hw, ICE_DBG_INIT, "Package version check failed.\n"); 139371d10453SEric Joyner return status; 139471d10453SEric Joyner } 139571d10453SEric Joyner 139671d10453SEric Joyner /* find ICE segment in given package */ 139771d10453SEric Joyner *seg = (struct ice_seg *)ice_find_seg_in_pkg(hw, SEGMENT_TYPE_ICE, 139871d10453SEric Joyner ospkg); 139971d10453SEric Joyner if (!*seg) { 140071d10453SEric Joyner ice_debug(hw, ICE_DBG_INIT, "no ice segment in package.\n"); 140171d10453SEric Joyner return ICE_ERR_CFG; 140271d10453SEric Joyner } 140371d10453SEric Joyner 140471d10453SEric Joyner /* Check if FW is compatible with the OS package */ 1405*7d7af7f8SEric Joyner size = ice_struct_size(pkg, pkg_info, ICE_PKG_CNT); 140671d10453SEric Joyner pkg = (struct ice_aqc_get_pkg_info_resp *)ice_malloc(hw, size); 140771d10453SEric Joyner if (!pkg) 140871d10453SEric Joyner return ICE_ERR_NO_MEMORY; 140971d10453SEric Joyner 141071d10453SEric Joyner status = ice_aq_get_pkg_info_list(hw, pkg, size, NULL); 141171d10453SEric Joyner if (status) 141271d10453SEric Joyner goto fw_ddp_compat_free_alloc; 141371d10453SEric Joyner 141471d10453SEric Joyner for (i = 0; i < LE32_TO_CPU(pkg->count); i++) { 141571d10453SEric Joyner /* loop till we find the NVM package */ 141671d10453SEric Joyner if (!pkg->pkg_info[i].is_in_nvm) 141771d10453SEric Joyner continue; 141871d10453SEric Joyner if ((*seg)->hdr.seg_format_ver.major != 141971d10453SEric Joyner pkg->pkg_info[i].ver.major || 142071d10453SEric Joyner (*seg)->hdr.seg_format_ver.minor > 142171d10453SEric Joyner pkg->pkg_info[i].ver.minor) { 142271d10453SEric Joyner status = ICE_ERR_FW_DDP_MISMATCH; 1423*7d7af7f8SEric Joyner ice_debug(hw, ICE_DBG_INIT, "OS package is not compatible with NVM.\n"); 142471d10453SEric Joyner } 142571d10453SEric Joyner /* done processing NVM package so break */ 142671d10453SEric Joyner break; 142771d10453SEric Joyner } 142871d10453SEric Joyner fw_ddp_compat_free_alloc: 142971d10453SEric Joyner ice_free(hw, pkg); 143071d10453SEric Joyner return status; 143171d10453SEric Joyner } 143271d10453SEric Joyner 143371d10453SEric Joyner /** 1434*7d7af7f8SEric Joyner * ice_sw_fv_handler 1435*7d7af7f8SEric Joyner * @sect_type: section type 1436*7d7af7f8SEric Joyner * @section: pointer to section 1437*7d7af7f8SEric Joyner * @index: index of the field vector entry to be returned 1438*7d7af7f8SEric Joyner * @offset: ptr to variable that receives the offset in the field vector table 1439*7d7af7f8SEric Joyner * 1440*7d7af7f8SEric Joyner * This is a callback function that can be passed to ice_pkg_enum_entry. 1441*7d7af7f8SEric Joyner * This function treats the given section as of type ice_sw_fv_section and 1442*7d7af7f8SEric Joyner * enumerates offset field. "offset" is an index into the field vector table. 1443*7d7af7f8SEric Joyner */ 1444*7d7af7f8SEric Joyner static void * 1445*7d7af7f8SEric Joyner ice_sw_fv_handler(u32 sect_type, void *section, u32 index, u32 *offset) 1446*7d7af7f8SEric Joyner { 1447*7d7af7f8SEric Joyner struct ice_sw_fv_section *fv_section = 1448*7d7af7f8SEric Joyner (struct ice_sw_fv_section *)section; 1449*7d7af7f8SEric Joyner 1450*7d7af7f8SEric Joyner if (!section || sect_type != ICE_SID_FLD_VEC_SW) 1451*7d7af7f8SEric Joyner return NULL; 1452*7d7af7f8SEric Joyner if (index >= LE16_TO_CPU(fv_section->count)) 1453*7d7af7f8SEric Joyner return NULL; 1454*7d7af7f8SEric Joyner if (offset) 1455*7d7af7f8SEric Joyner /* "index" passed in to this function is relative to a given 1456*7d7af7f8SEric Joyner * 4k block. To get to the true index into the field vector 1457*7d7af7f8SEric Joyner * table need to add the relative index to the base_offset 1458*7d7af7f8SEric Joyner * field of this section 1459*7d7af7f8SEric Joyner */ 1460*7d7af7f8SEric Joyner *offset = LE16_TO_CPU(fv_section->base_offset) + index; 1461*7d7af7f8SEric Joyner return fv_section->fv + index; 1462*7d7af7f8SEric Joyner } 1463*7d7af7f8SEric Joyner 1464*7d7af7f8SEric Joyner /** 1465*7d7af7f8SEric Joyner * ice_get_prof_index_max - get the max profile index for used profile 1466*7d7af7f8SEric Joyner * @hw: pointer to the HW struct 1467*7d7af7f8SEric Joyner * 1468*7d7af7f8SEric Joyner * Calling this function will get the max profile index for used profile 1469*7d7af7f8SEric Joyner * and store the index number in struct ice_switch_info *switch_info 1470*7d7af7f8SEric Joyner * in hw for following use. 1471*7d7af7f8SEric Joyner */ 1472*7d7af7f8SEric Joyner static int ice_get_prof_index_max(struct ice_hw *hw) 1473*7d7af7f8SEric Joyner { 1474*7d7af7f8SEric Joyner u16 prof_index = 0, j, max_prof_index = 0; 1475*7d7af7f8SEric Joyner struct ice_pkg_enum state; 1476*7d7af7f8SEric Joyner struct ice_seg *ice_seg; 1477*7d7af7f8SEric Joyner bool flag = false; 1478*7d7af7f8SEric Joyner struct ice_fv *fv; 1479*7d7af7f8SEric Joyner u32 offset; 1480*7d7af7f8SEric Joyner 1481*7d7af7f8SEric Joyner ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM); 1482*7d7af7f8SEric Joyner 1483*7d7af7f8SEric Joyner if (!hw->seg) 1484*7d7af7f8SEric Joyner return ICE_ERR_PARAM; 1485*7d7af7f8SEric Joyner 1486*7d7af7f8SEric Joyner ice_seg = hw->seg; 1487*7d7af7f8SEric Joyner 1488*7d7af7f8SEric Joyner do { 1489*7d7af7f8SEric Joyner fv = (struct ice_fv *) 1490*7d7af7f8SEric Joyner ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW, 1491*7d7af7f8SEric Joyner &offset, ice_sw_fv_handler); 1492*7d7af7f8SEric Joyner if (!fv) 1493*7d7af7f8SEric Joyner break; 1494*7d7af7f8SEric Joyner ice_seg = NULL; 1495*7d7af7f8SEric Joyner 1496*7d7af7f8SEric Joyner /* in the profile that not be used, the prot_id is set to 0xff 1497*7d7af7f8SEric Joyner * and the off is set to 0x1ff for all the field vectors. 1498*7d7af7f8SEric Joyner */ 1499*7d7af7f8SEric Joyner for (j = 0; j < hw->blk[ICE_BLK_SW].es.fvw; j++) 1500*7d7af7f8SEric Joyner if (fv->ew[j].prot_id != ICE_PROT_INVALID || 1501*7d7af7f8SEric Joyner fv->ew[j].off != ICE_FV_OFFSET_INVAL) 1502*7d7af7f8SEric Joyner flag = true; 1503*7d7af7f8SEric Joyner if (flag && prof_index > max_prof_index) 1504*7d7af7f8SEric Joyner max_prof_index = prof_index; 1505*7d7af7f8SEric Joyner 1506*7d7af7f8SEric Joyner prof_index++; 1507*7d7af7f8SEric Joyner flag = false; 1508*7d7af7f8SEric Joyner } while (fv); 1509*7d7af7f8SEric Joyner 1510*7d7af7f8SEric Joyner hw->switch_info->max_used_prof_index = max_prof_index; 1511*7d7af7f8SEric Joyner 1512*7d7af7f8SEric Joyner return ICE_SUCCESS; 1513*7d7af7f8SEric Joyner } 1514*7d7af7f8SEric Joyner 1515*7d7af7f8SEric Joyner /** 151671d10453SEric Joyner * ice_init_pkg - initialize/download package 151771d10453SEric Joyner * @hw: pointer to the hardware structure 151871d10453SEric Joyner * @buf: pointer to the package buffer 151971d10453SEric Joyner * @len: size of the package buffer 152071d10453SEric Joyner * 152171d10453SEric Joyner * This function initializes a package. The package contains HW tables 152271d10453SEric Joyner * required to do packet processing. First, the function extracts package 152371d10453SEric Joyner * information such as version. Then it finds the ice configuration segment 152471d10453SEric Joyner * within the package; this function then saves a copy of the segment pointer 152571d10453SEric Joyner * within the supplied package buffer. Next, the function will cache any hints 152671d10453SEric Joyner * from the package, followed by downloading the package itself. Note, that if 152771d10453SEric Joyner * a previous PF driver has already downloaded the package successfully, then 152871d10453SEric Joyner * the current driver will not have to download the package again. 152971d10453SEric Joyner * 153071d10453SEric Joyner * The local package contents will be used to query default behavior and to 153171d10453SEric Joyner * update specific sections of the HW's version of the package (e.g. to update 153271d10453SEric Joyner * the parse graph to understand new protocols). 153371d10453SEric Joyner * 153471d10453SEric Joyner * This function stores a pointer to the package buffer memory, and it is 153571d10453SEric Joyner * expected that the supplied buffer will not be freed immediately. If the 153671d10453SEric Joyner * package buffer needs to be freed, such as when read from a file, use 153771d10453SEric Joyner * ice_copy_and_init_pkg() instead of directly calling ice_init_pkg() in this 153871d10453SEric Joyner * case. 153971d10453SEric Joyner */ 154071d10453SEric Joyner enum ice_status ice_init_pkg(struct ice_hw *hw, u8 *buf, u32 len) 154171d10453SEric Joyner { 154271d10453SEric Joyner struct ice_pkg_hdr *pkg; 154371d10453SEric Joyner enum ice_status status; 154471d10453SEric Joyner struct ice_seg *seg; 154571d10453SEric Joyner 154671d10453SEric Joyner if (!buf || !len) 154771d10453SEric Joyner return ICE_ERR_PARAM; 154871d10453SEric Joyner 154971d10453SEric Joyner pkg = (struct ice_pkg_hdr *)buf; 155071d10453SEric Joyner status = ice_verify_pkg(pkg, len); 155171d10453SEric Joyner if (status) { 155271d10453SEric Joyner ice_debug(hw, ICE_DBG_INIT, "failed to verify pkg (err: %d)\n", 155371d10453SEric Joyner status); 155471d10453SEric Joyner return status; 155571d10453SEric Joyner } 155671d10453SEric Joyner 155771d10453SEric Joyner /* initialize package info */ 155871d10453SEric Joyner status = ice_init_pkg_info(hw, pkg); 155971d10453SEric Joyner if (status) 156071d10453SEric Joyner return status; 156171d10453SEric Joyner 156271d10453SEric Joyner /* before downloading the package, check package version for 156371d10453SEric Joyner * compatibility with driver 156471d10453SEric Joyner */ 156571d10453SEric Joyner status = ice_chk_pkg_compat(hw, pkg, &seg); 156671d10453SEric Joyner if (status) 156771d10453SEric Joyner return status; 156871d10453SEric Joyner 156971d10453SEric Joyner /* initialize package hints and then download package */ 157071d10453SEric Joyner ice_init_pkg_hints(hw, seg); 157171d10453SEric Joyner status = ice_download_pkg(hw, seg); 157271d10453SEric Joyner if (status == ICE_ERR_AQ_NO_WORK) { 1573*7d7af7f8SEric Joyner ice_debug(hw, ICE_DBG_INIT, "package previously loaded - no work.\n"); 157471d10453SEric Joyner status = ICE_SUCCESS; 157571d10453SEric Joyner } 157671d10453SEric Joyner 157771d10453SEric Joyner /* Get information on the package currently loaded in HW, then make sure 157871d10453SEric Joyner * the driver is compatible with this version. 157971d10453SEric Joyner */ 158071d10453SEric Joyner if (!status) { 158171d10453SEric Joyner status = ice_get_pkg_info(hw); 158271d10453SEric Joyner if (!status) 158371d10453SEric Joyner status = ice_chk_pkg_version(&hw->active_pkg_ver); 158471d10453SEric Joyner } 158571d10453SEric Joyner 158671d10453SEric Joyner if (!status) { 158771d10453SEric Joyner hw->seg = seg; 158871d10453SEric Joyner /* on successful package download update other required 158971d10453SEric Joyner * registers to support the package and fill HW tables 159071d10453SEric Joyner * with package content. 159171d10453SEric Joyner */ 159271d10453SEric Joyner ice_init_pkg_regs(hw); 159371d10453SEric Joyner ice_fill_blk_tbls(hw); 1594*7d7af7f8SEric Joyner ice_get_prof_index_max(hw); 159571d10453SEric Joyner } else { 159671d10453SEric Joyner ice_debug(hw, ICE_DBG_INIT, "package load failed, %d\n", 159771d10453SEric Joyner status); 159871d10453SEric Joyner } 159971d10453SEric Joyner 160071d10453SEric Joyner return status; 160171d10453SEric Joyner } 160271d10453SEric Joyner 160371d10453SEric Joyner /** 160471d10453SEric Joyner * ice_copy_and_init_pkg - initialize/download a copy of the package 160571d10453SEric Joyner * @hw: pointer to the hardware structure 160671d10453SEric Joyner * @buf: pointer to the package buffer 160771d10453SEric Joyner * @len: size of the package buffer 160871d10453SEric Joyner * 160971d10453SEric Joyner * This function copies the package buffer, and then calls ice_init_pkg() to 161071d10453SEric Joyner * initialize the copied package contents. 161171d10453SEric Joyner * 161271d10453SEric Joyner * The copying is necessary if the package buffer supplied is constant, or if 161371d10453SEric Joyner * the memory may disappear shortly after calling this function. 161471d10453SEric Joyner * 161571d10453SEric Joyner * If the package buffer resides in the data segment and can be modified, the 161671d10453SEric Joyner * caller is free to use ice_init_pkg() instead of ice_copy_and_init_pkg(). 161771d10453SEric Joyner * 161871d10453SEric Joyner * However, if the package buffer needs to be copied first, such as when being 161971d10453SEric Joyner * read from a file, the caller should use ice_copy_and_init_pkg(). 162071d10453SEric Joyner * 162171d10453SEric Joyner * This function will first copy the package buffer, before calling 162271d10453SEric Joyner * ice_init_pkg(). The caller is free to immediately destroy the original 162371d10453SEric Joyner * package buffer, as the new copy will be managed by this function and 162471d10453SEric Joyner * related routines. 162571d10453SEric Joyner */ 162671d10453SEric Joyner enum ice_status ice_copy_and_init_pkg(struct ice_hw *hw, const u8 *buf, u32 len) 162771d10453SEric Joyner { 162871d10453SEric Joyner enum ice_status status; 162971d10453SEric Joyner u8 *buf_copy; 163071d10453SEric Joyner 163171d10453SEric Joyner if (!buf || !len) 163271d10453SEric Joyner return ICE_ERR_PARAM; 163371d10453SEric Joyner 163471d10453SEric Joyner buf_copy = (u8 *)ice_memdup(hw, buf, len, ICE_NONDMA_TO_NONDMA); 163571d10453SEric Joyner 163671d10453SEric Joyner status = ice_init_pkg(hw, buf_copy, len); 163771d10453SEric Joyner if (status) { 163871d10453SEric Joyner /* Free the copy, since we failed to initialize the package */ 163971d10453SEric Joyner ice_free(hw, buf_copy); 164071d10453SEric Joyner } else { 164171d10453SEric Joyner /* Track the copied pkg so we can free it later */ 164271d10453SEric Joyner hw->pkg_copy = buf_copy; 164371d10453SEric Joyner hw->pkg_size = len; 164471d10453SEric Joyner } 164571d10453SEric Joyner 164671d10453SEric Joyner return status; 164771d10453SEric Joyner } 164871d10453SEric Joyner 164971d10453SEric Joyner /** 165071d10453SEric Joyner * ice_pkg_buf_alloc 165171d10453SEric Joyner * @hw: pointer to the HW structure 165271d10453SEric Joyner * 165371d10453SEric Joyner * Allocates a package buffer and returns a pointer to the buffer header. 165471d10453SEric Joyner * Note: all package contents must be in Little Endian form. 165571d10453SEric Joyner */ 165671d10453SEric Joyner static struct ice_buf_build *ice_pkg_buf_alloc(struct ice_hw *hw) 165771d10453SEric Joyner { 165871d10453SEric Joyner struct ice_buf_build *bld; 165971d10453SEric Joyner struct ice_buf_hdr *buf; 166071d10453SEric Joyner 166171d10453SEric Joyner bld = (struct ice_buf_build *)ice_malloc(hw, sizeof(*bld)); 166271d10453SEric Joyner if (!bld) 166371d10453SEric Joyner return NULL; 166471d10453SEric Joyner 166571d10453SEric Joyner buf = (struct ice_buf_hdr *)bld; 166671d10453SEric Joyner buf->data_end = CPU_TO_LE16(offsetof(struct ice_buf_hdr, 166771d10453SEric Joyner section_entry)); 166871d10453SEric Joyner return bld; 166971d10453SEric Joyner } 167071d10453SEric Joyner 167171d10453SEric Joyner /** 167271d10453SEric Joyner * ice_get_sw_prof_type - determine switch profile type 167371d10453SEric Joyner * @hw: pointer to the HW structure 167471d10453SEric Joyner * @fv: pointer to the switch field vector 167571d10453SEric Joyner */ 167671d10453SEric Joyner static enum ice_prof_type 167771d10453SEric Joyner ice_get_sw_prof_type(struct ice_hw *hw, struct ice_fv *fv) 167871d10453SEric Joyner { 167971d10453SEric Joyner u16 i; 168071d10453SEric Joyner 168171d10453SEric Joyner for (i = 0; i < hw->blk[ICE_BLK_SW].es.fvw; i++) { 168271d10453SEric Joyner /* UDP tunnel will have UDP_OF protocol ID and VNI offset */ 168371d10453SEric Joyner if (fv->ew[i].prot_id == (u8)ICE_PROT_UDP_OF && 168471d10453SEric Joyner fv->ew[i].off == ICE_VNI_OFFSET) 168571d10453SEric Joyner return ICE_PROF_TUN_UDP; 168671d10453SEric Joyner 168771d10453SEric Joyner /* GRE tunnel will have GRE protocol */ 168871d10453SEric Joyner if (fv->ew[i].prot_id == (u8)ICE_PROT_GRE_OF) 168971d10453SEric Joyner return ICE_PROF_TUN_GRE; 169071d10453SEric Joyner } 169171d10453SEric Joyner 169271d10453SEric Joyner return ICE_PROF_NON_TUN; 169371d10453SEric Joyner } 169471d10453SEric Joyner 169571d10453SEric Joyner /** 169671d10453SEric Joyner * ice_get_sw_fv_bitmap - Get switch field vector bitmap based on profile type 169771d10453SEric Joyner * @hw: pointer to hardware structure 169871d10453SEric Joyner * @req_profs: type of profiles requested 169971d10453SEric Joyner * @bm: pointer to memory for returning the bitmap of field vectors 170071d10453SEric Joyner */ 170171d10453SEric Joyner void 170271d10453SEric Joyner ice_get_sw_fv_bitmap(struct ice_hw *hw, enum ice_prof_type req_profs, 170371d10453SEric Joyner ice_bitmap_t *bm) 170471d10453SEric Joyner { 170571d10453SEric Joyner struct ice_pkg_enum state; 170671d10453SEric Joyner struct ice_seg *ice_seg; 170771d10453SEric Joyner struct ice_fv *fv; 170871d10453SEric Joyner 170971d10453SEric Joyner if (req_profs == ICE_PROF_ALL) { 1710*7d7af7f8SEric Joyner ice_bitmap_set(bm, 0, ICE_MAX_NUM_PROFILES); 171171d10453SEric Joyner return; 171271d10453SEric Joyner } 171371d10453SEric Joyner 1714*7d7af7f8SEric Joyner ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM); 171571d10453SEric Joyner ice_zero_bitmap(bm, ICE_MAX_NUM_PROFILES); 171671d10453SEric Joyner ice_seg = hw->seg; 171771d10453SEric Joyner do { 171871d10453SEric Joyner enum ice_prof_type prof_type; 171971d10453SEric Joyner u32 offset; 172071d10453SEric Joyner 172171d10453SEric Joyner fv = (struct ice_fv *) 172271d10453SEric Joyner ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW, 172371d10453SEric Joyner &offset, ice_sw_fv_handler); 172471d10453SEric Joyner ice_seg = NULL; 172571d10453SEric Joyner 172671d10453SEric Joyner if (fv) { 172771d10453SEric Joyner /* Determine field vector type */ 172871d10453SEric Joyner prof_type = ice_get_sw_prof_type(hw, fv); 172971d10453SEric Joyner 173071d10453SEric Joyner if (req_profs & prof_type) 173171d10453SEric Joyner ice_set_bit((u16)offset, bm); 173271d10453SEric Joyner } 173371d10453SEric Joyner } while (fv); 173471d10453SEric Joyner } 173571d10453SEric Joyner 173671d10453SEric Joyner /** 173771d10453SEric Joyner * ice_get_sw_fv_list 173871d10453SEric Joyner * @hw: pointer to the HW structure 173971d10453SEric Joyner * @prot_ids: field vector to search for with a given protocol ID 174071d10453SEric Joyner * @ids_cnt: lookup/protocol count 174171d10453SEric Joyner * @bm: bitmap of field vectors to consider 174271d10453SEric Joyner * @fv_list: Head of a list 174371d10453SEric Joyner * 174471d10453SEric Joyner * Finds all the field vector entries from switch block that contain 174571d10453SEric Joyner * a given protocol ID and returns a list of structures of type 174671d10453SEric Joyner * "ice_sw_fv_list_entry". Every structure in the list has a field vector 174771d10453SEric Joyner * definition and profile ID information 174871d10453SEric Joyner * NOTE: The caller of the function is responsible for freeing the memory 174971d10453SEric Joyner * allocated for every list entry. 175071d10453SEric Joyner */ 175171d10453SEric Joyner enum ice_status 175271d10453SEric Joyner ice_get_sw_fv_list(struct ice_hw *hw, u8 *prot_ids, u16 ids_cnt, 175371d10453SEric Joyner ice_bitmap_t *bm, struct LIST_HEAD_TYPE *fv_list) 175471d10453SEric Joyner { 175571d10453SEric Joyner struct ice_sw_fv_list_entry *fvl; 175671d10453SEric Joyner struct ice_sw_fv_list_entry *tmp; 175771d10453SEric Joyner struct ice_pkg_enum state; 175871d10453SEric Joyner struct ice_seg *ice_seg; 175971d10453SEric Joyner struct ice_fv *fv; 176071d10453SEric Joyner u32 offset; 176171d10453SEric Joyner 176271d10453SEric Joyner ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM); 176371d10453SEric Joyner 176471d10453SEric Joyner if (!ids_cnt || !hw->seg) 176571d10453SEric Joyner return ICE_ERR_PARAM; 176671d10453SEric Joyner 176771d10453SEric Joyner ice_seg = hw->seg; 176871d10453SEric Joyner do { 176971d10453SEric Joyner u16 i; 177071d10453SEric Joyner 177171d10453SEric Joyner fv = (struct ice_fv *) 177271d10453SEric Joyner ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW, 177371d10453SEric Joyner &offset, ice_sw_fv_handler); 177471d10453SEric Joyner if (!fv) 177571d10453SEric Joyner break; 177671d10453SEric Joyner ice_seg = NULL; 177771d10453SEric Joyner 177871d10453SEric Joyner /* If field vector is not in the bitmap list, then skip this 177971d10453SEric Joyner * profile. 178071d10453SEric Joyner */ 178171d10453SEric Joyner if (!ice_is_bit_set(bm, (u16)offset)) 178271d10453SEric Joyner continue; 178371d10453SEric Joyner 178471d10453SEric Joyner for (i = 0; i < ids_cnt; i++) { 178571d10453SEric Joyner int j; 178671d10453SEric Joyner 178771d10453SEric Joyner /* This code assumes that if a switch field vector line 178871d10453SEric Joyner * has a matching protocol, then this line will contain 178971d10453SEric Joyner * the entries necessary to represent every field in 179071d10453SEric Joyner * that protocol header. 179171d10453SEric Joyner */ 179271d10453SEric Joyner for (j = 0; j < hw->blk[ICE_BLK_SW].es.fvw; j++) 179371d10453SEric Joyner if (fv->ew[j].prot_id == prot_ids[i]) 179471d10453SEric Joyner break; 179571d10453SEric Joyner if (j >= hw->blk[ICE_BLK_SW].es.fvw) 179671d10453SEric Joyner break; 179771d10453SEric Joyner if (i + 1 == ids_cnt) { 179871d10453SEric Joyner fvl = (struct ice_sw_fv_list_entry *) 179971d10453SEric Joyner ice_malloc(hw, sizeof(*fvl)); 180071d10453SEric Joyner if (!fvl) 180171d10453SEric Joyner goto err; 180271d10453SEric Joyner fvl->fv_ptr = fv; 180371d10453SEric Joyner fvl->profile_id = offset; 180471d10453SEric Joyner LIST_ADD(&fvl->list_entry, fv_list); 180571d10453SEric Joyner break; 180671d10453SEric Joyner } 180771d10453SEric Joyner } 180871d10453SEric Joyner } while (fv); 180971d10453SEric Joyner if (LIST_EMPTY(fv_list)) 181071d10453SEric Joyner return ICE_ERR_CFG; 181171d10453SEric Joyner return ICE_SUCCESS; 181271d10453SEric Joyner 181371d10453SEric Joyner err: 181471d10453SEric Joyner LIST_FOR_EACH_ENTRY_SAFE(fvl, tmp, fv_list, ice_sw_fv_list_entry, 181571d10453SEric Joyner list_entry) { 181671d10453SEric Joyner LIST_DEL(&fvl->list_entry); 181771d10453SEric Joyner ice_free(hw, fvl); 181871d10453SEric Joyner } 181971d10453SEric Joyner 182071d10453SEric Joyner return ICE_ERR_NO_MEMORY; 182171d10453SEric Joyner } 182271d10453SEric Joyner 182371d10453SEric Joyner /** 182471d10453SEric Joyner * ice_init_prof_result_bm - Initialize the profile result index bitmap 182571d10453SEric Joyner * @hw: pointer to hardware structure 182671d10453SEric Joyner */ 182771d10453SEric Joyner void ice_init_prof_result_bm(struct ice_hw *hw) 182871d10453SEric Joyner { 182971d10453SEric Joyner struct ice_pkg_enum state; 183071d10453SEric Joyner struct ice_seg *ice_seg; 183171d10453SEric Joyner struct ice_fv *fv; 183271d10453SEric Joyner 183371d10453SEric Joyner ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM); 183471d10453SEric Joyner 183571d10453SEric Joyner if (!hw->seg) 183671d10453SEric Joyner return; 183771d10453SEric Joyner 183871d10453SEric Joyner ice_seg = hw->seg; 183971d10453SEric Joyner do { 184071d10453SEric Joyner u32 off; 184171d10453SEric Joyner u16 i; 184271d10453SEric Joyner 184371d10453SEric Joyner fv = (struct ice_fv *) 184471d10453SEric Joyner ice_pkg_enum_entry(ice_seg, &state, ICE_SID_FLD_VEC_SW, 184571d10453SEric Joyner &off, ice_sw_fv_handler); 184671d10453SEric Joyner ice_seg = NULL; 184771d10453SEric Joyner if (!fv) 184871d10453SEric Joyner break; 184971d10453SEric Joyner 185071d10453SEric Joyner ice_zero_bitmap(hw->switch_info->prof_res_bm[off], 185171d10453SEric Joyner ICE_MAX_FV_WORDS); 185271d10453SEric Joyner 185371d10453SEric Joyner /* Determine empty field vector indices, these can be 185471d10453SEric Joyner * used for recipe results. Skip index 0, since it is 185571d10453SEric Joyner * always used for Switch ID. 185671d10453SEric Joyner */ 185771d10453SEric Joyner for (i = 1; i < ICE_MAX_FV_WORDS; i++) 185871d10453SEric Joyner if (fv->ew[i].prot_id == ICE_PROT_INVALID && 185971d10453SEric Joyner fv->ew[i].off == ICE_FV_OFFSET_INVAL) 186071d10453SEric Joyner ice_set_bit(i, 186171d10453SEric Joyner hw->switch_info->prof_res_bm[off]); 186271d10453SEric Joyner } while (fv); 186371d10453SEric Joyner } 186471d10453SEric Joyner 186571d10453SEric Joyner /** 186671d10453SEric Joyner * ice_pkg_buf_free 186771d10453SEric Joyner * @hw: pointer to the HW structure 186871d10453SEric Joyner * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc()) 186971d10453SEric Joyner * 187071d10453SEric Joyner * Frees a package buffer 187171d10453SEric Joyner */ 187271d10453SEric Joyner static void ice_pkg_buf_free(struct ice_hw *hw, struct ice_buf_build *bld) 187371d10453SEric Joyner { 187471d10453SEric Joyner ice_free(hw, bld); 187571d10453SEric Joyner } 187671d10453SEric Joyner 187771d10453SEric Joyner /** 187871d10453SEric Joyner * ice_pkg_buf_reserve_section 187971d10453SEric Joyner * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc()) 188071d10453SEric Joyner * @count: the number of sections to reserve 188171d10453SEric Joyner * 188271d10453SEric Joyner * Reserves one or more section table entries in a package buffer. This routine 188371d10453SEric Joyner * can be called multiple times as long as they are made before calling 188471d10453SEric Joyner * ice_pkg_buf_alloc_section(). Once ice_pkg_buf_alloc_section() 188571d10453SEric Joyner * is called once, the number of sections that can be allocated will not be able 188671d10453SEric Joyner * to be increased; not using all reserved sections is fine, but this will 188771d10453SEric Joyner * result in some wasted space in the buffer. 188871d10453SEric Joyner * Note: all package contents must be in Little Endian form. 188971d10453SEric Joyner */ 189071d10453SEric Joyner static enum ice_status 189171d10453SEric Joyner ice_pkg_buf_reserve_section(struct ice_buf_build *bld, u16 count) 189271d10453SEric Joyner { 189371d10453SEric Joyner struct ice_buf_hdr *buf; 189471d10453SEric Joyner u16 section_count; 189571d10453SEric Joyner u16 data_end; 189671d10453SEric Joyner 189771d10453SEric Joyner if (!bld) 189871d10453SEric Joyner return ICE_ERR_PARAM; 189971d10453SEric Joyner 190071d10453SEric Joyner buf = (struct ice_buf_hdr *)&bld->buf; 190171d10453SEric Joyner 190271d10453SEric Joyner /* already an active section, can't increase table size */ 190371d10453SEric Joyner section_count = LE16_TO_CPU(buf->section_count); 190471d10453SEric Joyner if (section_count > 0) 190571d10453SEric Joyner return ICE_ERR_CFG; 190671d10453SEric Joyner 190771d10453SEric Joyner if (bld->reserved_section_table_entries + count > ICE_MAX_S_COUNT) 190871d10453SEric Joyner return ICE_ERR_CFG; 190971d10453SEric Joyner bld->reserved_section_table_entries += count; 191071d10453SEric Joyner 191171d10453SEric Joyner data_end = LE16_TO_CPU(buf->data_end) + 191271d10453SEric Joyner (count * sizeof(buf->section_entry[0])); 191371d10453SEric Joyner buf->data_end = CPU_TO_LE16(data_end); 191471d10453SEric Joyner 191571d10453SEric Joyner return ICE_SUCCESS; 191671d10453SEric Joyner } 191771d10453SEric Joyner 191871d10453SEric Joyner /** 191971d10453SEric Joyner * ice_pkg_buf_alloc_section 192071d10453SEric Joyner * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc()) 192171d10453SEric Joyner * @type: the section type value 192271d10453SEric Joyner * @size: the size of the section to reserve (in bytes) 192371d10453SEric Joyner * 192471d10453SEric Joyner * Reserves memory in the buffer for a section's content and updates the 192571d10453SEric Joyner * buffers' status accordingly. This routine returns a pointer to the first 192671d10453SEric Joyner * byte of the section start within the buffer, which is used to fill in the 192771d10453SEric Joyner * section contents. 192871d10453SEric Joyner * Note: all package contents must be in Little Endian form. 192971d10453SEric Joyner */ 193071d10453SEric Joyner static void * 193171d10453SEric Joyner ice_pkg_buf_alloc_section(struct ice_buf_build *bld, u32 type, u16 size) 193271d10453SEric Joyner { 193371d10453SEric Joyner struct ice_buf_hdr *buf; 193471d10453SEric Joyner u16 sect_count; 193571d10453SEric Joyner u16 data_end; 193671d10453SEric Joyner 193771d10453SEric Joyner if (!bld || !type || !size) 193871d10453SEric Joyner return NULL; 193971d10453SEric Joyner 194071d10453SEric Joyner buf = (struct ice_buf_hdr *)&bld->buf; 194171d10453SEric Joyner 194271d10453SEric Joyner /* check for enough space left in buffer */ 194371d10453SEric Joyner data_end = LE16_TO_CPU(buf->data_end); 194471d10453SEric Joyner 194571d10453SEric Joyner /* section start must align on 4 byte boundary */ 194671d10453SEric Joyner data_end = ICE_ALIGN(data_end, 4); 194771d10453SEric Joyner 194871d10453SEric Joyner if ((data_end + size) > ICE_MAX_S_DATA_END) 194971d10453SEric Joyner return NULL; 195071d10453SEric Joyner 195171d10453SEric Joyner /* check for more available section table entries */ 195271d10453SEric Joyner sect_count = LE16_TO_CPU(buf->section_count); 195371d10453SEric Joyner if (sect_count < bld->reserved_section_table_entries) { 195471d10453SEric Joyner void *section_ptr = ((u8 *)buf) + data_end; 195571d10453SEric Joyner 195671d10453SEric Joyner buf->section_entry[sect_count].offset = CPU_TO_LE16(data_end); 195771d10453SEric Joyner buf->section_entry[sect_count].size = CPU_TO_LE16(size); 195871d10453SEric Joyner buf->section_entry[sect_count].type = CPU_TO_LE32(type); 195971d10453SEric Joyner 196071d10453SEric Joyner data_end += size; 196171d10453SEric Joyner buf->data_end = CPU_TO_LE16(data_end); 196271d10453SEric Joyner 196371d10453SEric Joyner buf->section_count = CPU_TO_LE16(sect_count + 1); 196471d10453SEric Joyner return section_ptr; 196571d10453SEric Joyner } 196671d10453SEric Joyner 196771d10453SEric Joyner /* no free section table entries */ 196871d10453SEric Joyner return NULL; 196971d10453SEric Joyner } 197071d10453SEric Joyner 197171d10453SEric Joyner /** 197271d10453SEric Joyner * ice_pkg_buf_alloc_single_section 197371d10453SEric Joyner * @hw: pointer to the HW structure 197471d10453SEric Joyner * @type: the section type value 197571d10453SEric Joyner * @size: the size of the section to reserve (in bytes) 197671d10453SEric Joyner * @section: returns pointer to the section 197771d10453SEric Joyner * 197871d10453SEric Joyner * Allocates a package buffer with a single section. 197971d10453SEric Joyner * Note: all package contents must be in Little Endian form. 198071d10453SEric Joyner */ 198171d10453SEric Joyner static struct ice_buf_build * 198271d10453SEric Joyner ice_pkg_buf_alloc_single_section(struct ice_hw *hw, u32 type, u16 size, 198371d10453SEric Joyner void **section) 198471d10453SEric Joyner { 198571d10453SEric Joyner struct ice_buf_build *buf; 198671d10453SEric Joyner 198771d10453SEric Joyner if (!section) 198871d10453SEric Joyner return NULL; 198971d10453SEric Joyner 199071d10453SEric Joyner buf = ice_pkg_buf_alloc(hw); 199171d10453SEric Joyner if (!buf) 199271d10453SEric Joyner return NULL; 199371d10453SEric Joyner 199471d10453SEric Joyner if (ice_pkg_buf_reserve_section(buf, 1)) 199571d10453SEric Joyner goto ice_pkg_buf_alloc_single_section_err; 199671d10453SEric Joyner 199771d10453SEric Joyner *section = ice_pkg_buf_alloc_section(buf, type, size); 199871d10453SEric Joyner if (!*section) 199971d10453SEric Joyner goto ice_pkg_buf_alloc_single_section_err; 200071d10453SEric Joyner 200171d10453SEric Joyner return buf; 200271d10453SEric Joyner 200371d10453SEric Joyner ice_pkg_buf_alloc_single_section_err: 200471d10453SEric Joyner ice_pkg_buf_free(hw, buf); 200571d10453SEric Joyner return NULL; 200671d10453SEric Joyner } 200771d10453SEric Joyner 200871d10453SEric Joyner /** 200971d10453SEric Joyner * ice_pkg_buf_unreserve_section 201071d10453SEric Joyner * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc()) 201171d10453SEric Joyner * @count: the number of sections to unreserve 201271d10453SEric Joyner * 201371d10453SEric Joyner * Unreserves one or more section table entries in a package buffer, releasing 201471d10453SEric Joyner * space that can be used for section data. This routine can be called 201571d10453SEric Joyner * multiple times as long as they are made before calling 201671d10453SEric Joyner * ice_pkg_buf_alloc_section(). Once ice_pkg_buf_alloc_section() 201771d10453SEric Joyner * is called once, the number of sections that can be allocated will not be able 201871d10453SEric Joyner * to be increased; not using all reserved sections is fine, but this will 201971d10453SEric Joyner * result in some wasted space in the buffer. 202071d10453SEric Joyner * Note: all package contents must be in Little Endian form. 202171d10453SEric Joyner */ 202271d10453SEric Joyner enum ice_status 202371d10453SEric Joyner ice_pkg_buf_unreserve_section(struct ice_buf_build *bld, u16 count) 202471d10453SEric Joyner { 202571d10453SEric Joyner struct ice_buf_hdr *buf; 202671d10453SEric Joyner u16 section_count; 202771d10453SEric Joyner u16 data_end; 202871d10453SEric Joyner 202971d10453SEric Joyner if (!bld) 203071d10453SEric Joyner return ICE_ERR_PARAM; 203171d10453SEric Joyner 203271d10453SEric Joyner buf = (struct ice_buf_hdr *)&bld->buf; 203371d10453SEric Joyner 203471d10453SEric Joyner /* already an active section, can't decrease table size */ 203571d10453SEric Joyner section_count = LE16_TO_CPU(buf->section_count); 203671d10453SEric Joyner if (section_count > 0) 203771d10453SEric Joyner return ICE_ERR_CFG; 203871d10453SEric Joyner 203971d10453SEric Joyner if (count > bld->reserved_section_table_entries) 204071d10453SEric Joyner return ICE_ERR_CFG; 204171d10453SEric Joyner bld->reserved_section_table_entries -= count; 204271d10453SEric Joyner 204371d10453SEric Joyner data_end = LE16_TO_CPU(buf->data_end) - 204471d10453SEric Joyner (count * sizeof(buf->section_entry[0])); 204571d10453SEric Joyner buf->data_end = CPU_TO_LE16(data_end); 204671d10453SEric Joyner 204771d10453SEric Joyner return ICE_SUCCESS; 204871d10453SEric Joyner } 204971d10453SEric Joyner 205071d10453SEric Joyner /** 205171d10453SEric Joyner * ice_pkg_buf_get_free_space 205271d10453SEric Joyner * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc()) 205371d10453SEric Joyner * 205471d10453SEric Joyner * Returns the number of free bytes remaining in the buffer. 205571d10453SEric Joyner * Note: all package contents must be in Little Endian form. 205671d10453SEric Joyner */ 205771d10453SEric Joyner u16 ice_pkg_buf_get_free_space(struct ice_buf_build *bld) 205871d10453SEric Joyner { 205971d10453SEric Joyner struct ice_buf_hdr *buf; 206071d10453SEric Joyner 206171d10453SEric Joyner if (!bld) 206271d10453SEric Joyner return 0; 206371d10453SEric Joyner 206471d10453SEric Joyner buf = (struct ice_buf_hdr *)&bld->buf; 206571d10453SEric Joyner return ICE_MAX_S_DATA_END - LE16_TO_CPU(buf->data_end); 206671d10453SEric Joyner } 206771d10453SEric Joyner 206871d10453SEric Joyner /** 206971d10453SEric Joyner * ice_pkg_buf_get_active_sections 207071d10453SEric Joyner * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc()) 207171d10453SEric Joyner * 207271d10453SEric Joyner * Returns the number of active sections. Before using the package buffer 207371d10453SEric Joyner * in an update package command, the caller should make sure that there is at 207471d10453SEric Joyner * least one active section - otherwise, the buffer is not legal and should 207571d10453SEric Joyner * not be used. 207671d10453SEric Joyner * Note: all package contents must be in Little Endian form. 207771d10453SEric Joyner */ 207871d10453SEric Joyner static u16 ice_pkg_buf_get_active_sections(struct ice_buf_build *bld) 207971d10453SEric Joyner { 208071d10453SEric Joyner struct ice_buf_hdr *buf; 208171d10453SEric Joyner 208271d10453SEric Joyner if (!bld) 208371d10453SEric Joyner return 0; 208471d10453SEric Joyner 208571d10453SEric Joyner buf = (struct ice_buf_hdr *)&bld->buf; 208671d10453SEric Joyner return LE16_TO_CPU(buf->section_count); 208771d10453SEric Joyner } 208871d10453SEric Joyner 208971d10453SEric Joyner /** 209071d10453SEric Joyner * ice_pkg_buf 209171d10453SEric Joyner * @bld: pointer to pkg build (allocated by ice_pkg_buf_alloc()) 209271d10453SEric Joyner * 209371d10453SEric Joyner * Return a pointer to the buffer's header 209471d10453SEric Joyner */ 209571d10453SEric Joyner static struct ice_buf *ice_pkg_buf(struct ice_buf_build *bld) 209671d10453SEric Joyner { 209771d10453SEric Joyner if (!bld) 209871d10453SEric Joyner return NULL; 209971d10453SEric Joyner 210071d10453SEric Joyner return &bld->buf; 210171d10453SEric Joyner } 210271d10453SEric Joyner 210371d10453SEric Joyner /** 210471d10453SEric Joyner * ice_tunnel_port_in_use_hlpr - helper function to determine tunnel usage 210571d10453SEric Joyner * @hw: pointer to the HW structure 210671d10453SEric Joyner * @port: port to search for 210771d10453SEric Joyner * @index: optionally returns index 210871d10453SEric Joyner * 210971d10453SEric Joyner * Returns whether a port is already in use as a tunnel, and optionally its 211071d10453SEric Joyner * index 211171d10453SEric Joyner */ 211271d10453SEric Joyner static bool ice_tunnel_port_in_use_hlpr(struct ice_hw *hw, u16 port, u16 *index) 211371d10453SEric Joyner { 211471d10453SEric Joyner u16 i; 211571d10453SEric Joyner 211671d10453SEric Joyner for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++) 211771d10453SEric Joyner if (hw->tnl.tbl[i].in_use && hw->tnl.tbl[i].port == port) { 211871d10453SEric Joyner if (index) 211971d10453SEric Joyner *index = i; 212071d10453SEric Joyner return true; 212171d10453SEric Joyner } 212271d10453SEric Joyner 212371d10453SEric Joyner return false; 212471d10453SEric Joyner } 212571d10453SEric Joyner 212671d10453SEric Joyner /** 212771d10453SEric Joyner * ice_tunnel_port_in_use 212871d10453SEric Joyner * @hw: pointer to the HW structure 212971d10453SEric Joyner * @port: port to search for 213071d10453SEric Joyner * @index: optionally returns index 213171d10453SEric Joyner * 213271d10453SEric Joyner * Returns whether a port is already in use as a tunnel, and optionally its 213371d10453SEric Joyner * index 213471d10453SEric Joyner */ 213571d10453SEric Joyner bool ice_tunnel_port_in_use(struct ice_hw *hw, u16 port, u16 *index) 213671d10453SEric Joyner { 213771d10453SEric Joyner bool res; 213871d10453SEric Joyner 213971d10453SEric Joyner ice_acquire_lock(&hw->tnl_lock); 214071d10453SEric Joyner res = ice_tunnel_port_in_use_hlpr(hw, port, index); 214171d10453SEric Joyner ice_release_lock(&hw->tnl_lock); 214271d10453SEric Joyner 214371d10453SEric Joyner return res; 214471d10453SEric Joyner } 214571d10453SEric Joyner 214671d10453SEric Joyner /** 214771d10453SEric Joyner * ice_tunnel_get_type 214871d10453SEric Joyner * @hw: pointer to the HW structure 214971d10453SEric Joyner * @port: port to search for 215071d10453SEric Joyner * @type: returns tunnel index 215171d10453SEric Joyner * 215271d10453SEric Joyner * For a given port number, will return the type of tunnel. 215371d10453SEric Joyner */ 215471d10453SEric Joyner bool 215571d10453SEric Joyner ice_tunnel_get_type(struct ice_hw *hw, u16 port, enum ice_tunnel_type *type) 215671d10453SEric Joyner { 215771d10453SEric Joyner bool res = false; 215871d10453SEric Joyner u16 i; 215971d10453SEric Joyner 216071d10453SEric Joyner ice_acquire_lock(&hw->tnl_lock); 216171d10453SEric Joyner 216271d10453SEric Joyner for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++) 216371d10453SEric Joyner if (hw->tnl.tbl[i].in_use && hw->tnl.tbl[i].port == port) { 216471d10453SEric Joyner *type = hw->tnl.tbl[i].type; 216571d10453SEric Joyner res = true; 216671d10453SEric Joyner break; 216771d10453SEric Joyner } 216871d10453SEric Joyner 216971d10453SEric Joyner ice_release_lock(&hw->tnl_lock); 217071d10453SEric Joyner 217171d10453SEric Joyner return res; 217271d10453SEric Joyner } 217371d10453SEric Joyner 217471d10453SEric Joyner /** 217571d10453SEric Joyner * ice_find_free_tunnel_entry 217671d10453SEric Joyner * @hw: pointer to the HW structure 217771d10453SEric Joyner * @type: tunnel type 217871d10453SEric Joyner * @index: optionally returns index 217971d10453SEric Joyner * 218071d10453SEric Joyner * Returns whether there is a free tunnel entry, and optionally its index 218171d10453SEric Joyner */ 218271d10453SEric Joyner static bool 218371d10453SEric Joyner ice_find_free_tunnel_entry(struct ice_hw *hw, enum ice_tunnel_type type, 218471d10453SEric Joyner u16 *index) 218571d10453SEric Joyner { 218671d10453SEric Joyner u16 i; 218771d10453SEric Joyner 218871d10453SEric Joyner for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++) 218971d10453SEric Joyner if (hw->tnl.tbl[i].valid && !hw->tnl.tbl[i].in_use && 219071d10453SEric Joyner hw->tnl.tbl[i].type == type) { 219171d10453SEric Joyner if (index) 219271d10453SEric Joyner *index = i; 219371d10453SEric Joyner return true; 219471d10453SEric Joyner } 219571d10453SEric Joyner 219671d10453SEric Joyner return false; 219771d10453SEric Joyner } 219871d10453SEric Joyner 219971d10453SEric Joyner /** 220071d10453SEric Joyner * ice_get_open_tunnel_port - retrieve an open tunnel port 220171d10453SEric Joyner * @hw: pointer to the HW structure 220271d10453SEric Joyner * @type: tunnel type (TNL_ALL will return any open port) 220371d10453SEric Joyner * @port: returns open port 220471d10453SEric Joyner */ 220571d10453SEric Joyner bool 220671d10453SEric Joyner ice_get_open_tunnel_port(struct ice_hw *hw, enum ice_tunnel_type type, 220771d10453SEric Joyner u16 *port) 220871d10453SEric Joyner { 220971d10453SEric Joyner bool res = false; 221071d10453SEric Joyner u16 i; 221171d10453SEric Joyner 221271d10453SEric Joyner ice_acquire_lock(&hw->tnl_lock); 221371d10453SEric Joyner 221471d10453SEric Joyner for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++) 221571d10453SEric Joyner if (hw->tnl.tbl[i].valid && hw->tnl.tbl[i].in_use && 221671d10453SEric Joyner (type == TNL_ALL || hw->tnl.tbl[i].type == type)) { 221771d10453SEric Joyner *port = hw->tnl.tbl[i].port; 221871d10453SEric Joyner res = true; 221971d10453SEric Joyner break; 222071d10453SEric Joyner } 222171d10453SEric Joyner 222271d10453SEric Joyner ice_release_lock(&hw->tnl_lock); 222371d10453SEric Joyner 222471d10453SEric Joyner return res; 222571d10453SEric Joyner } 222671d10453SEric Joyner 222771d10453SEric Joyner /** 222871d10453SEric Joyner * ice_create_tunnel 222971d10453SEric Joyner * @hw: pointer to the HW structure 223071d10453SEric Joyner * @type: type of tunnel 223171d10453SEric Joyner * @port: port of tunnel to create 223271d10453SEric Joyner * 223371d10453SEric Joyner * Create a tunnel by updating the parse graph in the parser. We do that by 223471d10453SEric Joyner * creating a package buffer with the tunnel info and issuing an update package 223571d10453SEric Joyner * command. 223671d10453SEric Joyner */ 223771d10453SEric Joyner enum ice_status 223871d10453SEric Joyner ice_create_tunnel(struct ice_hw *hw, enum ice_tunnel_type type, u16 port) 223971d10453SEric Joyner { 224071d10453SEric Joyner struct ice_boost_tcam_section *sect_rx, *sect_tx; 224171d10453SEric Joyner enum ice_status status = ICE_ERR_MAX_LIMIT; 224271d10453SEric Joyner struct ice_buf_build *bld; 224371d10453SEric Joyner u16 index; 224471d10453SEric Joyner 224571d10453SEric Joyner ice_acquire_lock(&hw->tnl_lock); 224671d10453SEric Joyner 224771d10453SEric Joyner if (ice_tunnel_port_in_use_hlpr(hw, port, &index)) { 224871d10453SEric Joyner hw->tnl.tbl[index].ref++; 224971d10453SEric Joyner status = ICE_SUCCESS; 225071d10453SEric Joyner goto ice_create_tunnel_end; 225171d10453SEric Joyner } 225271d10453SEric Joyner 225371d10453SEric Joyner if (!ice_find_free_tunnel_entry(hw, type, &index)) { 225471d10453SEric Joyner status = ICE_ERR_OUT_OF_RANGE; 225571d10453SEric Joyner goto ice_create_tunnel_end; 225671d10453SEric Joyner } 225771d10453SEric Joyner 225871d10453SEric Joyner bld = ice_pkg_buf_alloc(hw); 225971d10453SEric Joyner if (!bld) { 226071d10453SEric Joyner status = ICE_ERR_NO_MEMORY; 226171d10453SEric Joyner goto ice_create_tunnel_end; 226271d10453SEric Joyner } 226371d10453SEric Joyner 226471d10453SEric Joyner /* allocate 2 sections, one for Rx parser, one for Tx parser */ 226571d10453SEric Joyner if (ice_pkg_buf_reserve_section(bld, 2)) 226671d10453SEric Joyner goto ice_create_tunnel_err; 226771d10453SEric Joyner 226871d10453SEric Joyner sect_rx = (struct ice_boost_tcam_section *) 226971d10453SEric Joyner ice_pkg_buf_alloc_section(bld, ICE_SID_RXPARSER_BOOST_TCAM, 2270*7d7af7f8SEric Joyner ice_struct_size(sect_rx, tcam, 1)); 227171d10453SEric Joyner if (!sect_rx) 227271d10453SEric Joyner goto ice_create_tunnel_err; 227371d10453SEric Joyner sect_rx->count = CPU_TO_LE16(1); 227471d10453SEric Joyner 227571d10453SEric Joyner sect_tx = (struct ice_boost_tcam_section *) 227671d10453SEric Joyner ice_pkg_buf_alloc_section(bld, ICE_SID_TXPARSER_BOOST_TCAM, 2277*7d7af7f8SEric Joyner ice_struct_size(sect_tx, tcam, 1)); 227871d10453SEric Joyner if (!sect_tx) 227971d10453SEric Joyner goto ice_create_tunnel_err; 228071d10453SEric Joyner sect_tx->count = CPU_TO_LE16(1); 228171d10453SEric Joyner 228271d10453SEric Joyner /* copy original boost entry to update package buffer */ 228371d10453SEric Joyner ice_memcpy(sect_rx->tcam, hw->tnl.tbl[index].boost_entry, 228471d10453SEric Joyner sizeof(*sect_rx->tcam), ICE_NONDMA_TO_NONDMA); 228571d10453SEric Joyner 228671d10453SEric Joyner /* over-write the never-match dest port key bits with the encoded port 228771d10453SEric Joyner * bits 228871d10453SEric Joyner */ 228971d10453SEric Joyner ice_set_key((u8 *)§_rx->tcam[0].key, sizeof(sect_rx->tcam[0].key), 229071d10453SEric Joyner (u8 *)&port, NULL, NULL, NULL, 229171d10453SEric Joyner (u16)offsetof(struct ice_boost_key_value, hv_dst_port_key), 229271d10453SEric Joyner sizeof(sect_rx->tcam[0].key.key.hv_dst_port_key)); 229371d10453SEric Joyner 229471d10453SEric Joyner /* exact copy of entry to Tx section entry */ 229571d10453SEric Joyner ice_memcpy(sect_tx->tcam, sect_rx->tcam, sizeof(*sect_tx->tcam), 229671d10453SEric Joyner ICE_NONDMA_TO_NONDMA); 229771d10453SEric Joyner 229871d10453SEric Joyner status = ice_update_pkg(hw, ice_pkg_buf(bld), 1); 229971d10453SEric Joyner if (!status) { 230071d10453SEric Joyner hw->tnl.tbl[index].port = port; 230171d10453SEric Joyner hw->tnl.tbl[index].in_use = true; 230271d10453SEric Joyner hw->tnl.tbl[index].ref = 1; 230371d10453SEric Joyner } 230471d10453SEric Joyner 230571d10453SEric Joyner ice_create_tunnel_err: 230671d10453SEric Joyner ice_pkg_buf_free(hw, bld); 230771d10453SEric Joyner 230871d10453SEric Joyner ice_create_tunnel_end: 230971d10453SEric Joyner ice_release_lock(&hw->tnl_lock); 231071d10453SEric Joyner 231171d10453SEric Joyner return status; 231271d10453SEric Joyner } 231371d10453SEric Joyner 231471d10453SEric Joyner /** 231571d10453SEric Joyner * ice_destroy_tunnel 231671d10453SEric Joyner * @hw: pointer to the HW structure 231771d10453SEric Joyner * @port: port of tunnel to destroy (ignored if the all parameter is true) 231871d10453SEric Joyner * @all: flag that states to destroy all tunnels 231971d10453SEric Joyner * 232071d10453SEric Joyner * Destroys a tunnel or all tunnels by creating an update package buffer 232171d10453SEric Joyner * targeting the specific updates requested and then performing an update 232271d10453SEric Joyner * package. 232371d10453SEric Joyner */ 232471d10453SEric Joyner enum ice_status ice_destroy_tunnel(struct ice_hw *hw, u16 port, bool all) 232571d10453SEric Joyner { 232671d10453SEric Joyner struct ice_boost_tcam_section *sect_rx, *sect_tx; 232771d10453SEric Joyner enum ice_status status = ICE_ERR_MAX_LIMIT; 232871d10453SEric Joyner struct ice_buf_build *bld; 232971d10453SEric Joyner u16 count = 0; 233071d10453SEric Joyner u16 index; 233171d10453SEric Joyner u16 size; 233271d10453SEric Joyner u16 i; 233371d10453SEric Joyner 233471d10453SEric Joyner ice_acquire_lock(&hw->tnl_lock); 233571d10453SEric Joyner 233671d10453SEric Joyner if (!all && ice_tunnel_port_in_use_hlpr(hw, port, &index)) 233771d10453SEric Joyner if (hw->tnl.tbl[index].ref > 1) { 233871d10453SEric Joyner hw->tnl.tbl[index].ref--; 233971d10453SEric Joyner status = ICE_SUCCESS; 234071d10453SEric Joyner goto ice_destroy_tunnel_end; 234171d10453SEric Joyner } 234271d10453SEric Joyner 234371d10453SEric Joyner /* determine count */ 234471d10453SEric Joyner for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++) 234571d10453SEric Joyner if (hw->tnl.tbl[i].valid && hw->tnl.tbl[i].in_use && 234671d10453SEric Joyner (all || hw->tnl.tbl[i].port == port)) 234771d10453SEric Joyner count++; 234871d10453SEric Joyner 234971d10453SEric Joyner if (!count) { 235071d10453SEric Joyner status = ICE_ERR_PARAM; 235171d10453SEric Joyner goto ice_destroy_tunnel_end; 235271d10453SEric Joyner } 235371d10453SEric Joyner 235471d10453SEric Joyner /* size of section - there is at least one entry */ 2355*7d7af7f8SEric Joyner size = ice_struct_size(sect_rx, tcam, count); 235671d10453SEric Joyner 235771d10453SEric Joyner bld = ice_pkg_buf_alloc(hw); 235871d10453SEric Joyner if (!bld) { 235971d10453SEric Joyner status = ICE_ERR_NO_MEMORY; 236071d10453SEric Joyner goto ice_destroy_tunnel_end; 236171d10453SEric Joyner } 236271d10453SEric Joyner 236371d10453SEric Joyner /* allocate 2 sections, one for Rx parser, one for Tx parser */ 236471d10453SEric Joyner if (ice_pkg_buf_reserve_section(bld, 2)) 236571d10453SEric Joyner goto ice_destroy_tunnel_err; 236671d10453SEric Joyner 236771d10453SEric Joyner sect_rx = (struct ice_boost_tcam_section *) 236871d10453SEric Joyner ice_pkg_buf_alloc_section(bld, ICE_SID_RXPARSER_BOOST_TCAM, 236971d10453SEric Joyner size); 237071d10453SEric Joyner if (!sect_rx) 237171d10453SEric Joyner goto ice_destroy_tunnel_err; 237271d10453SEric Joyner sect_rx->count = CPU_TO_LE16(1); 237371d10453SEric Joyner 237471d10453SEric Joyner sect_tx = (struct ice_boost_tcam_section *) 237571d10453SEric Joyner ice_pkg_buf_alloc_section(bld, ICE_SID_TXPARSER_BOOST_TCAM, 237671d10453SEric Joyner size); 237771d10453SEric Joyner if (!sect_tx) 237871d10453SEric Joyner goto ice_destroy_tunnel_err; 237971d10453SEric Joyner sect_tx->count = CPU_TO_LE16(1); 238071d10453SEric Joyner 238171d10453SEric Joyner /* copy original boost entry to update package buffer, one copy to Rx 238271d10453SEric Joyner * section, another copy to the Tx section 238371d10453SEric Joyner */ 238471d10453SEric Joyner for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++) 238571d10453SEric Joyner if (hw->tnl.tbl[i].valid && hw->tnl.tbl[i].in_use && 238671d10453SEric Joyner (all || hw->tnl.tbl[i].port == port)) { 238771d10453SEric Joyner ice_memcpy(sect_rx->tcam + i, 238871d10453SEric Joyner hw->tnl.tbl[i].boost_entry, 238971d10453SEric Joyner sizeof(*sect_rx->tcam), 239071d10453SEric Joyner ICE_NONDMA_TO_NONDMA); 239171d10453SEric Joyner ice_memcpy(sect_tx->tcam + i, 239271d10453SEric Joyner hw->tnl.tbl[i].boost_entry, 239371d10453SEric Joyner sizeof(*sect_tx->tcam), 239471d10453SEric Joyner ICE_NONDMA_TO_NONDMA); 239571d10453SEric Joyner hw->tnl.tbl[i].marked = true; 239671d10453SEric Joyner } 239771d10453SEric Joyner 239871d10453SEric Joyner status = ice_update_pkg(hw, ice_pkg_buf(bld), 1); 239971d10453SEric Joyner if (!status) 240071d10453SEric Joyner for (i = 0; i < hw->tnl.count && 240171d10453SEric Joyner i < ICE_TUNNEL_MAX_ENTRIES; i++) 240271d10453SEric Joyner if (hw->tnl.tbl[i].marked) { 240371d10453SEric Joyner hw->tnl.tbl[i].ref = 0; 240471d10453SEric Joyner hw->tnl.tbl[i].port = 0; 240571d10453SEric Joyner hw->tnl.tbl[i].in_use = false; 240671d10453SEric Joyner hw->tnl.tbl[i].marked = false; 240771d10453SEric Joyner } 240871d10453SEric Joyner 240971d10453SEric Joyner ice_destroy_tunnel_err: 241071d10453SEric Joyner ice_pkg_buf_free(hw, bld); 241171d10453SEric Joyner 241271d10453SEric Joyner ice_destroy_tunnel_end: 241371d10453SEric Joyner ice_release_lock(&hw->tnl_lock); 241471d10453SEric Joyner 241571d10453SEric Joyner return status; 241671d10453SEric Joyner } 241771d10453SEric Joyner 241871d10453SEric Joyner /** 241971d10453SEric Joyner * ice_replay_tunnels 242071d10453SEric Joyner * @hw: pointer to the HW structure 242171d10453SEric Joyner * 242271d10453SEric Joyner * Replays all tunnels 242371d10453SEric Joyner */ 242471d10453SEric Joyner enum ice_status ice_replay_tunnels(struct ice_hw *hw) 242571d10453SEric Joyner { 242671d10453SEric Joyner enum ice_status status = ICE_SUCCESS; 242771d10453SEric Joyner u16 i; 242871d10453SEric Joyner 242971d10453SEric Joyner ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__); 243071d10453SEric Joyner 243171d10453SEric Joyner for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++) { 243271d10453SEric Joyner enum ice_tunnel_type type = hw->tnl.tbl[i].type; 243371d10453SEric Joyner u16 refs = hw->tnl.tbl[i].ref; 243471d10453SEric Joyner u16 port = hw->tnl.tbl[i].port; 243571d10453SEric Joyner 243671d10453SEric Joyner if (!hw->tnl.tbl[i].in_use) 243771d10453SEric Joyner continue; 243871d10453SEric Joyner 243971d10453SEric Joyner /* Replay tunnels one at a time by destroying them, then 244071d10453SEric Joyner * recreating them 244171d10453SEric Joyner */ 244271d10453SEric Joyner hw->tnl.tbl[i].ref = 1; /* make sure to destroy in one call */ 244371d10453SEric Joyner status = ice_destroy_tunnel(hw, port, false); 244471d10453SEric Joyner if (status) { 2445*7d7af7f8SEric Joyner ice_debug(hw, ICE_DBG_PKG, "ERR: 0x%x - destroy tunnel port 0x%x\n", 244671d10453SEric Joyner status, port); 244771d10453SEric Joyner break; 244871d10453SEric Joyner } 244971d10453SEric Joyner 245071d10453SEric Joyner status = ice_create_tunnel(hw, type, port); 245171d10453SEric Joyner if (status) { 2452*7d7af7f8SEric Joyner ice_debug(hw, ICE_DBG_PKG, "ERR: 0x%x - create tunnel port 0x%x\n", 245371d10453SEric Joyner status, port); 245471d10453SEric Joyner break; 245571d10453SEric Joyner } 245671d10453SEric Joyner 245771d10453SEric Joyner /* reset to original ref count */ 245871d10453SEric Joyner hw->tnl.tbl[i].ref = refs; 245971d10453SEric Joyner } 246071d10453SEric Joyner 246171d10453SEric Joyner return status; 246271d10453SEric Joyner } 246371d10453SEric Joyner 246471d10453SEric Joyner /** 246571d10453SEric Joyner * ice_find_prot_off - find prot ID and offset pair, based on prof and FV index 246671d10453SEric Joyner * @hw: pointer to the hardware structure 246771d10453SEric Joyner * @blk: hardware block 246871d10453SEric Joyner * @prof: profile ID 246971d10453SEric Joyner * @fv_idx: field vector word index 247071d10453SEric Joyner * @prot: variable to receive the protocol ID 247171d10453SEric Joyner * @off: variable to receive the protocol offset 247271d10453SEric Joyner */ 247371d10453SEric Joyner enum ice_status 247471d10453SEric Joyner ice_find_prot_off(struct ice_hw *hw, enum ice_block blk, u8 prof, u16 fv_idx, 247571d10453SEric Joyner u8 *prot, u16 *off) 247671d10453SEric Joyner { 247771d10453SEric Joyner struct ice_fv_word *fv_ext; 247871d10453SEric Joyner 247971d10453SEric Joyner if (prof >= hw->blk[blk].es.count) 248071d10453SEric Joyner return ICE_ERR_PARAM; 248171d10453SEric Joyner 248271d10453SEric Joyner if (fv_idx >= hw->blk[blk].es.fvw) 248371d10453SEric Joyner return ICE_ERR_PARAM; 248471d10453SEric Joyner 248571d10453SEric Joyner fv_ext = hw->blk[blk].es.t + (prof * hw->blk[blk].es.fvw); 248671d10453SEric Joyner 248771d10453SEric Joyner *prot = fv_ext[fv_idx].prot_id; 248871d10453SEric Joyner *off = fv_ext[fv_idx].off; 248971d10453SEric Joyner 249071d10453SEric Joyner return ICE_SUCCESS; 249171d10453SEric Joyner } 249271d10453SEric Joyner 249371d10453SEric Joyner /* PTG Management */ 249471d10453SEric Joyner 249571d10453SEric Joyner /** 249671d10453SEric Joyner * ice_ptg_update_xlt1 - Updates packet type groups in HW via XLT1 table 249771d10453SEric Joyner * @hw: pointer to the hardware structure 249871d10453SEric Joyner * @blk: HW block 249971d10453SEric Joyner * 250071d10453SEric Joyner * This function will update the XLT1 hardware table to reflect the new 250171d10453SEric Joyner * packet type group configuration. 250271d10453SEric Joyner */ 250371d10453SEric Joyner enum ice_status ice_ptg_update_xlt1(struct ice_hw *hw, enum ice_block blk) 250471d10453SEric Joyner { 250571d10453SEric Joyner struct ice_xlt1_section *sect; 250671d10453SEric Joyner struct ice_buf_build *bld; 250771d10453SEric Joyner enum ice_status status; 250871d10453SEric Joyner u16 index; 250971d10453SEric Joyner 251071d10453SEric Joyner bld = ice_pkg_buf_alloc_single_section(hw, ice_sect_id(blk, ICE_XLT1), 2511*7d7af7f8SEric Joyner ice_struct_size(sect, value, 2512*7d7af7f8SEric Joyner ICE_XLT1_CNT), 251371d10453SEric Joyner (void **)§); 251471d10453SEric Joyner if (!bld) 251571d10453SEric Joyner return ICE_ERR_NO_MEMORY; 251671d10453SEric Joyner 251771d10453SEric Joyner sect->count = CPU_TO_LE16(ICE_XLT1_CNT); 251871d10453SEric Joyner sect->offset = CPU_TO_LE16(0); 251971d10453SEric Joyner for (index = 0; index < ICE_XLT1_CNT; index++) 252071d10453SEric Joyner sect->value[index] = hw->blk[blk].xlt1.ptypes[index].ptg; 252171d10453SEric Joyner 252271d10453SEric Joyner status = ice_update_pkg(hw, ice_pkg_buf(bld), 1); 252371d10453SEric Joyner 252471d10453SEric Joyner ice_pkg_buf_free(hw, bld); 252571d10453SEric Joyner 252671d10453SEric Joyner return status; 252771d10453SEric Joyner } 252871d10453SEric Joyner 252971d10453SEric Joyner /** 253071d10453SEric Joyner * ice_ptg_find_ptype - Search for packet type group using packet type (ptype) 253171d10453SEric Joyner * @hw: pointer to the hardware structure 253271d10453SEric Joyner * @blk: HW block 253371d10453SEric Joyner * @ptype: the ptype to search for 253471d10453SEric Joyner * @ptg: pointer to variable that receives the PTG 253571d10453SEric Joyner * 253671d10453SEric Joyner * This function will search the PTGs for a particular ptype, returning the 253771d10453SEric Joyner * PTG ID that contains it through the PTG parameter, with the value of 253871d10453SEric Joyner * ICE_DEFAULT_PTG (0) meaning it is part the default PTG. 253971d10453SEric Joyner */ 254071d10453SEric Joyner static enum ice_status 254171d10453SEric Joyner ice_ptg_find_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 *ptg) 254271d10453SEric Joyner { 254371d10453SEric Joyner if (ptype >= ICE_XLT1_CNT || !ptg) 254471d10453SEric Joyner return ICE_ERR_PARAM; 254571d10453SEric Joyner 254671d10453SEric Joyner *ptg = hw->blk[blk].xlt1.ptypes[ptype].ptg; 254771d10453SEric Joyner return ICE_SUCCESS; 254871d10453SEric Joyner } 254971d10453SEric Joyner 255071d10453SEric Joyner /** 255171d10453SEric Joyner * ice_ptg_alloc_val - Allocates a new packet type group ID by value 255271d10453SEric Joyner * @hw: pointer to the hardware structure 255371d10453SEric Joyner * @blk: HW block 255471d10453SEric Joyner * @ptg: the PTG to allocate 255571d10453SEric Joyner * 255671d10453SEric Joyner * This function allocates a given packet type group ID specified by the PTG 255771d10453SEric Joyner * parameter. 255871d10453SEric Joyner */ 255971d10453SEric Joyner static void ice_ptg_alloc_val(struct ice_hw *hw, enum ice_block blk, u8 ptg) 256071d10453SEric Joyner { 256171d10453SEric Joyner hw->blk[blk].xlt1.ptg_tbl[ptg].in_use = true; 256271d10453SEric Joyner } 256371d10453SEric Joyner 256471d10453SEric Joyner /** 256571d10453SEric Joyner * ice_ptg_free - Frees a packet type group 256671d10453SEric Joyner * @hw: pointer to the hardware structure 256771d10453SEric Joyner * @blk: HW block 256871d10453SEric Joyner * @ptg: the PTG ID to free 256971d10453SEric Joyner * 257071d10453SEric Joyner * This function frees a packet type group, and returns all the current ptypes 257171d10453SEric Joyner * within it to the default PTG. 257271d10453SEric Joyner */ 257371d10453SEric Joyner void ice_ptg_free(struct ice_hw *hw, enum ice_block blk, u8 ptg) 257471d10453SEric Joyner { 257571d10453SEric Joyner struct ice_ptg_ptype *p, *temp; 257671d10453SEric Joyner 257771d10453SEric Joyner hw->blk[blk].xlt1.ptg_tbl[ptg].in_use = false; 257871d10453SEric Joyner p = hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype; 257971d10453SEric Joyner while (p) { 258071d10453SEric Joyner p->ptg = ICE_DEFAULT_PTG; 258171d10453SEric Joyner temp = p->next_ptype; 258271d10453SEric Joyner p->next_ptype = NULL; 258371d10453SEric Joyner p = temp; 258471d10453SEric Joyner } 258571d10453SEric Joyner 258671d10453SEric Joyner hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype = NULL; 258771d10453SEric Joyner } 258871d10453SEric Joyner 258971d10453SEric Joyner /** 259071d10453SEric Joyner * ice_ptg_remove_ptype - Removes ptype from a particular packet type group 259171d10453SEric Joyner * @hw: pointer to the hardware structure 259271d10453SEric Joyner * @blk: HW block 259371d10453SEric Joyner * @ptype: the ptype to remove 259471d10453SEric Joyner * @ptg: the PTG to remove the ptype from 259571d10453SEric Joyner * 259671d10453SEric Joyner * This function will remove the ptype from the specific PTG, and move it to 259771d10453SEric Joyner * the default PTG (ICE_DEFAULT_PTG). 259871d10453SEric Joyner */ 259971d10453SEric Joyner static enum ice_status 260071d10453SEric Joyner ice_ptg_remove_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 ptg) 260171d10453SEric Joyner { 260271d10453SEric Joyner struct ice_ptg_ptype **ch; 260371d10453SEric Joyner struct ice_ptg_ptype *p; 260471d10453SEric Joyner 260571d10453SEric Joyner if (ptype > ICE_XLT1_CNT - 1) 260671d10453SEric Joyner return ICE_ERR_PARAM; 260771d10453SEric Joyner 260871d10453SEric Joyner if (!hw->blk[blk].xlt1.ptg_tbl[ptg].in_use) 260971d10453SEric Joyner return ICE_ERR_DOES_NOT_EXIST; 261071d10453SEric Joyner 261171d10453SEric Joyner /* Should not happen if .in_use is set, bad config */ 261271d10453SEric Joyner if (!hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype) 261371d10453SEric Joyner return ICE_ERR_CFG; 261471d10453SEric Joyner 261571d10453SEric Joyner /* find the ptype within this PTG, and bypass the link over it */ 261671d10453SEric Joyner p = hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype; 261771d10453SEric Joyner ch = &hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype; 261871d10453SEric Joyner while (p) { 261971d10453SEric Joyner if (ptype == (p - hw->blk[blk].xlt1.ptypes)) { 262071d10453SEric Joyner *ch = p->next_ptype; 262171d10453SEric Joyner break; 262271d10453SEric Joyner } 262371d10453SEric Joyner 262471d10453SEric Joyner ch = &p->next_ptype; 262571d10453SEric Joyner p = p->next_ptype; 262671d10453SEric Joyner } 262771d10453SEric Joyner 262871d10453SEric Joyner hw->blk[blk].xlt1.ptypes[ptype].ptg = ICE_DEFAULT_PTG; 262971d10453SEric Joyner hw->blk[blk].xlt1.ptypes[ptype].next_ptype = NULL; 263071d10453SEric Joyner 263171d10453SEric Joyner return ICE_SUCCESS; 263271d10453SEric Joyner } 263371d10453SEric Joyner 263471d10453SEric Joyner /** 263571d10453SEric Joyner * ice_ptg_add_mv_ptype - Adds/moves ptype to a particular packet type group 263671d10453SEric Joyner * @hw: pointer to the hardware structure 263771d10453SEric Joyner * @blk: HW block 263871d10453SEric Joyner * @ptype: the ptype to add or move 263971d10453SEric Joyner * @ptg: the PTG to add or move the ptype to 264071d10453SEric Joyner * 264171d10453SEric Joyner * This function will either add or move a ptype to a particular PTG depending 264271d10453SEric Joyner * on if the ptype is already part of another group. Note that using a 264371d10453SEric Joyner * a destination PTG ID of ICE_DEFAULT_PTG (0) will move the ptype to the 264471d10453SEric Joyner * default PTG. 264571d10453SEric Joyner */ 264671d10453SEric Joyner static enum ice_status 264771d10453SEric Joyner ice_ptg_add_mv_ptype(struct ice_hw *hw, enum ice_block blk, u16 ptype, u8 ptg) 264871d10453SEric Joyner { 264971d10453SEric Joyner enum ice_status status; 265071d10453SEric Joyner u8 original_ptg; 265171d10453SEric Joyner 265271d10453SEric Joyner if (ptype > ICE_XLT1_CNT - 1) 265371d10453SEric Joyner return ICE_ERR_PARAM; 265471d10453SEric Joyner 265571d10453SEric Joyner if (!hw->blk[blk].xlt1.ptg_tbl[ptg].in_use && ptg != ICE_DEFAULT_PTG) 265671d10453SEric Joyner return ICE_ERR_DOES_NOT_EXIST; 265771d10453SEric Joyner 265871d10453SEric Joyner status = ice_ptg_find_ptype(hw, blk, ptype, &original_ptg); 265971d10453SEric Joyner if (status) 266071d10453SEric Joyner return status; 266171d10453SEric Joyner 266271d10453SEric Joyner /* Is ptype already in the correct PTG? */ 266371d10453SEric Joyner if (original_ptg == ptg) 266471d10453SEric Joyner return ICE_SUCCESS; 266571d10453SEric Joyner 266671d10453SEric Joyner /* Remove from original PTG and move back to the default PTG */ 266771d10453SEric Joyner if (original_ptg != ICE_DEFAULT_PTG) 266871d10453SEric Joyner ice_ptg_remove_ptype(hw, blk, ptype, original_ptg); 266971d10453SEric Joyner 267071d10453SEric Joyner /* Moving to default PTG? Then we're done with this request */ 267171d10453SEric Joyner if (ptg == ICE_DEFAULT_PTG) 267271d10453SEric Joyner return ICE_SUCCESS; 267371d10453SEric Joyner 267471d10453SEric Joyner /* Add ptype to PTG at beginning of list */ 267571d10453SEric Joyner hw->blk[blk].xlt1.ptypes[ptype].next_ptype = 267671d10453SEric Joyner hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype; 267771d10453SEric Joyner hw->blk[blk].xlt1.ptg_tbl[ptg].first_ptype = 267871d10453SEric Joyner &hw->blk[blk].xlt1.ptypes[ptype]; 267971d10453SEric Joyner 268071d10453SEric Joyner hw->blk[blk].xlt1.ptypes[ptype].ptg = ptg; 268171d10453SEric Joyner hw->blk[blk].xlt1.t[ptype] = ptg; 268271d10453SEric Joyner 268371d10453SEric Joyner return ICE_SUCCESS; 268471d10453SEric Joyner } 268571d10453SEric Joyner 268671d10453SEric Joyner /* Block / table size info */ 268771d10453SEric Joyner struct ice_blk_size_details { 268871d10453SEric Joyner u16 xlt1; /* # XLT1 entries */ 268971d10453SEric Joyner u16 xlt2; /* # XLT2 entries */ 269071d10453SEric Joyner u16 prof_tcam; /* # profile ID TCAM entries */ 269171d10453SEric Joyner u16 prof_id; /* # profile IDs */ 269271d10453SEric Joyner u8 prof_cdid_bits; /* # CDID one-hot bits used in key */ 269371d10453SEric Joyner u16 prof_redir; /* # profile redirection entries */ 269471d10453SEric Joyner u16 es; /* # extraction sequence entries */ 269571d10453SEric Joyner u16 fvw; /* # field vector words */ 269671d10453SEric Joyner u8 overwrite; /* overwrite existing entries allowed */ 269771d10453SEric Joyner u8 reverse; /* reverse FV order */ 269871d10453SEric Joyner }; 269971d10453SEric Joyner 270071d10453SEric Joyner static const struct ice_blk_size_details blk_sizes[ICE_BLK_COUNT] = { 270171d10453SEric Joyner /** 270271d10453SEric Joyner * Table Definitions 270371d10453SEric Joyner * XLT1 - Number of entries in XLT1 table 270471d10453SEric Joyner * XLT2 - Number of entries in XLT2 table 270571d10453SEric Joyner * TCAM - Number of entries Profile ID TCAM table 270671d10453SEric Joyner * CDID - Control Domain ID of the hardware block 270771d10453SEric Joyner * PRED - Number of entries in the Profile Redirection Table 270871d10453SEric Joyner * FV - Number of entries in the Field Vector 270971d10453SEric Joyner * FVW - Width (in WORDs) of the Field Vector 271071d10453SEric Joyner * OVR - Overwrite existing table entries 271171d10453SEric Joyner * REV - Reverse FV 271271d10453SEric Joyner */ 271371d10453SEric Joyner /* XLT1 , XLT2 ,TCAM, PID,CDID,PRED, FV, FVW */ 271471d10453SEric Joyner /* Overwrite , Reverse FV */ 271571d10453SEric Joyner /* SW */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 256, 0, 256, 256, 48, 271671d10453SEric Joyner false, false }, 271771d10453SEric Joyner /* ACL */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 32, 271871d10453SEric Joyner false, false }, 271971d10453SEric Joyner /* FD */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 24, 272071d10453SEric Joyner false, true }, 272171d10453SEric Joyner /* RSS */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 512, 128, 0, 128, 128, 24, 272271d10453SEric Joyner true, true }, 272371d10453SEric Joyner /* PE */ { ICE_XLT1_CNT, ICE_XLT2_CNT, 64, 32, 0, 32, 32, 24, 272471d10453SEric Joyner false, false }, 272571d10453SEric Joyner }; 272671d10453SEric Joyner 272771d10453SEric Joyner enum ice_sid_all { 272871d10453SEric Joyner ICE_SID_XLT1_OFF = 0, 272971d10453SEric Joyner ICE_SID_XLT2_OFF, 273071d10453SEric Joyner ICE_SID_PR_OFF, 273171d10453SEric Joyner ICE_SID_PR_REDIR_OFF, 273271d10453SEric Joyner ICE_SID_ES_OFF, 273371d10453SEric Joyner ICE_SID_OFF_COUNT, 273471d10453SEric Joyner }; 273571d10453SEric Joyner 273671d10453SEric Joyner /* Characteristic handling */ 273771d10453SEric Joyner 273871d10453SEric Joyner /** 273971d10453SEric Joyner * ice_match_prop_lst - determine if properties of two lists match 274071d10453SEric Joyner * @list1: first properties list 274171d10453SEric Joyner * @list2: second properties list 274271d10453SEric Joyner * 274371d10453SEric Joyner * Count, cookies and the order must match in order to be considered equivalent. 274471d10453SEric Joyner */ 274571d10453SEric Joyner static bool 274671d10453SEric Joyner ice_match_prop_lst(struct LIST_HEAD_TYPE *list1, struct LIST_HEAD_TYPE *list2) 274771d10453SEric Joyner { 274871d10453SEric Joyner struct ice_vsig_prof *tmp1; 274971d10453SEric Joyner struct ice_vsig_prof *tmp2; 275071d10453SEric Joyner u16 chk_count = 0; 275171d10453SEric Joyner u16 count = 0; 275271d10453SEric Joyner 275371d10453SEric Joyner /* compare counts */ 2754*7d7af7f8SEric Joyner LIST_FOR_EACH_ENTRY(tmp1, list1, ice_vsig_prof, list) 275571d10453SEric Joyner count++; 2756*7d7af7f8SEric Joyner LIST_FOR_EACH_ENTRY(tmp2, list2, ice_vsig_prof, list) 275771d10453SEric Joyner chk_count++; 275871d10453SEric Joyner if (!count || count != chk_count) 275971d10453SEric Joyner return false; 276071d10453SEric Joyner 276171d10453SEric Joyner tmp1 = LIST_FIRST_ENTRY(list1, struct ice_vsig_prof, list); 276271d10453SEric Joyner tmp2 = LIST_FIRST_ENTRY(list2, struct ice_vsig_prof, list); 276371d10453SEric Joyner 276471d10453SEric Joyner /* profile cookies must compare, and in the exact same order to take 276571d10453SEric Joyner * into account priority 276671d10453SEric Joyner */ 276771d10453SEric Joyner while (count--) { 276871d10453SEric Joyner if (tmp2->profile_cookie != tmp1->profile_cookie) 276971d10453SEric Joyner return false; 277071d10453SEric Joyner 277171d10453SEric Joyner tmp1 = LIST_NEXT_ENTRY(tmp1, struct ice_vsig_prof, list); 277271d10453SEric Joyner tmp2 = LIST_NEXT_ENTRY(tmp2, struct ice_vsig_prof, list); 277371d10453SEric Joyner } 277471d10453SEric Joyner 277571d10453SEric Joyner return true; 277671d10453SEric Joyner } 277771d10453SEric Joyner 277871d10453SEric Joyner /* VSIG Management */ 277971d10453SEric Joyner 278071d10453SEric Joyner /** 278171d10453SEric Joyner * ice_vsig_update_xlt2_sect - update one section of XLT2 table 278271d10453SEric Joyner * @hw: pointer to the hardware structure 278371d10453SEric Joyner * @blk: HW block 278471d10453SEric Joyner * @vsi: HW VSI number to program 278571d10453SEric Joyner * @vsig: VSIG for the VSI 278671d10453SEric Joyner * 278771d10453SEric Joyner * This function will update the XLT2 hardware table with the input VSI 278871d10453SEric Joyner * group configuration. 278971d10453SEric Joyner */ 279071d10453SEric Joyner static enum ice_status 279171d10453SEric Joyner ice_vsig_update_xlt2_sect(struct ice_hw *hw, enum ice_block blk, u16 vsi, 279271d10453SEric Joyner u16 vsig) 279371d10453SEric Joyner { 279471d10453SEric Joyner struct ice_xlt2_section *sect; 279571d10453SEric Joyner struct ice_buf_build *bld; 279671d10453SEric Joyner enum ice_status status; 279771d10453SEric Joyner 279871d10453SEric Joyner bld = ice_pkg_buf_alloc_single_section(hw, ice_sect_id(blk, ICE_XLT2), 2799*7d7af7f8SEric Joyner ice_struct_size(sect, value, 1), 280071d10453SEric Joyner (void **)§); 280171d10453SEric Joyner if (!bld) 280271d10453SEric Joyner return ICE_ERR_NO_MEMORY; 280371d10453SEric Joyner 280471d10453SEric Joyner sect->count = CPU_TO_LE16(1); 280571d10453SEric Joyner sect->offset = CPU_TO_LE16(vsi); 280671d10453SEric Joyner sect->value[0] = CPU_TO_LE16(vsig); 280771d10453SEric Joyner 280871d10453SEric Joyner status = ice_update_pkg(hw, ice_pkg_buf(bld), 1); 280971d10453SEric Joyner 281071d10453SEric Joyner ice_pkg_buf_free(hw, bld); 281171d10453SEric Joyner 281271d10453SEric Joyner return status; 281371d10453SEric Joyner } 281471d10453SEric Joyner 281571d10453SEric Joyner /** 281671d10453SEric Joyner * ice_vsig_update_xlt2 - update XLT2 table with VSIG configuration 281771d10453SEric Joyner * @hw: pointer to the hardware structure 281871d10453SEric Joyner * @blk: HW block 281971d10453SEric Joyner * 282071d10453SEric Joyner * This function will update the XLT2 hardware table with the input VSI 282171d10453SEric Joyner * group configuration of used vsis. 282271d10453SEric Joyner */ 282371d10453SEric Joyner enum ice_status ice_vsig_update_xlt2(struct ice_hw *hw, enum ice_block blk) 282471d10453SEric Joyner { 282571d10453SEric Joyner u16 vsi; 282671d10453SEric Joyner 282771d10453SEric Joyner for (vsi = 0; vsi < ICE_MAX_VSI; vsi++) { 282871d10453SEric Joyner /* update only vsis that have been changed */ 282971d10453SEric Joyner if (hw->blk[blk].xlt2.vsis[vsi].changed) { 283071d10453SEric Joyner enum ice_status status; 283171d10453SEric Joyner u16 vsig; 283271d10453SEric Joyner 283371d10453SEric Joyner vsig = hw->blk[blk].xlt2.vsis[vsi].vsig; 283471d10453SEric Joyner status = ice_vsig_update_xlt2_sect(hw, blk, vsi, vsig); 283571d10453SEric Joyner if (status) 283671d10453SEric Joyner return status; 283771d10453SEric Joyner 283871d10453SEric Joyner hw->blk[blk].xlt2.vsis[vsi].changed = 0; 283971d10453SEric Joyner } 284071d10453SEric Joyner } 284171d10453SEric Joyner 284271d10453SEric Joyner return ICE_SUCCESS; 284371d10453SEric Joyner } 284471d10453SEric Joyner 284571d10453SEric Joyner /** 284671d10453SEric Joyner * ice_vsig_find_vsi - find a VSIG that contains a specified VSI 284771d10453SEric Joyner * @hw: pointer to the hardware structure 284871d10453SEric Joyner * @blk: HW block 284971d10453SEric Joyner * @vsi: VSI of interest 285071d10453SEric Joyner * @vsig: pointer to receive the VSI group 285171d10453SEric Joyner * 285271d10453SEric Joyner * This function will lookup the VSI entry in the XLT2 list and return 285371d10453SEric Joyner * the VSI group its associated with. 285471d10453SEric Joyner */ 285571d10453SEric Joyner enum ice_status 285671d10453SEric Joyner ice_vsig_find_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 *vsig) 285771d10453SEric Joyner { 285871d10453SEric Joyner if (!vsig || vsi >= ICE_MAX_VSI) 285971d10453SEric Joyner return ICE_ERR_PARAM; 286071d10453SEric Joyner 286171d10453SEric Joyner /* As long as there's a default or valid VSIG associated with the input 286271d10453SEric Joyner * VSI, the functions returns a success. Any handling of VSIG will be 286371d10453SEric Joyner * done by the following add, update or remove functions. 286471d10453SEric Joyner */ 286571d10453SEric Joyner *vsig = hw->blk[blk].xlt2.vsis[vsi].vsig; 286671d10453SEric Joyner 286771d10453SEric Joyner return ICE_SUCCESS; 286871d10453SEric Joyner } 286971d10453SEric Joyner 287071d10453SEric Joyner /** 287171d10453SEric Joyner * ice_vsig_alloc_val - allocate a new VSIG by value 287271d10453SEric Joyner * @hw: pointer to the hardware structure 287371d10453SEric Joyner * @blk: HW block 287471d10453SEric Joyner * @vsig: the VSIG to allocate 287571d10453SEric Joyner * 287671d10453SEric Joyner * This function will allocate a given VSIG specified by the VSIG parameter. 287771d10453SEric Joyner */ 287871d10453SEric Joyner static u16 ice_vsig_alloc_val(struct ice_hw *hw, enum ice_block blk, u16 vsig) 287971d10453SEric Joyner { 288071d10453SEric Joyner u16 idx = vsig & ICE_VSIG_IDX_M; 288171d10453SEric Joyner 288271d10453SEric Joyner if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use) { 288371d10453SEric Joyner INIT_LIST_HEAD(&hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst); 288471d10453SEric Joyner hw->blk[blk].xlt2.vsig_tbl[idx].in_use = true; 288571d10453SEric Joyner } 288671d10453SEric Joyner 288771d10453SEric Joyner return ICE_VSIG_VALUE(idx, hw->pf_id); 288871d10453SEric Joyner } 288971d10453SEric Joyner 289071d10453SEric Joyner /** 289171d10453SEric Joyner * ice_vsig_alloc - Finds a free entry and allocates a new VSIG 289271d10453SEric Joyner * @hw: pointer to the hardware structure 289371d10453SEric Joyner * @blk: HW block 289471d10453SEric Joyner * 289571d10453SEric Joyner * This function will iterate through the VSIG list and mark the first 289671d10453SEric Joyner * unused entry for the new VSIG entry as used and return that value. 289771d10453SEric Joyner */ 289871d10453SEric Joyner static u16 ice_vsig_alloc(struct ice_hw *hw, enum ice_block blk) 289971d10453SEric Joyner { 290071d10453SEric Joyner u16 i; 290171d10453SEric Joyner 290271d10453SEric Joyner for (i = 1; i < ICE_MAX_VSIGS; i++) 290371d10453SEric Joyner if (!hw->blk[blk].xlt2.vsig_tbl[i].in_use) 290471d10453SEric Joyner return ice_vsig_alloc_val(hw, blk, i); 290571d10453SEric Joyner 290671d10453SEric Joyner return ICE_DEFAULT_VSIG; 290771d10453SEric Joyner } 290871d10453SEric Joyner 290971d10453SEric Joyner /** 291071d10453SEric Joyner * ice_find_dup_props_vsig - find VSI group with a specified set of properties 291171d10453SEric Joyner * @hw: pointer to the hardware structure 291271d10453SEric Joyner * @blk: HW block 291371d10453SEric Joyner * @chs: characteristic list 291471d10453SEric Joyner * @vsig: returns the VSIG with the matching profiles, if found 291571d10453SEric Joyner * 291671d10453SEric Joyner * Each VSIG is associated with a characteristic set; i.e. all VSIs under 291771d10453SEric Joyner * a group have the same characteristic set. To check if there exists a VSIG 291871d10453SEric Joyner * which has the same characteristics as the input characteristics; this 291971d10453SEric Joyner * function will iterate through the XLT2 list and return the VSIG that has a 292071d10453SEric Joyner * matching configuration. In order to make sure that priorities are accounted 292171d10453SEric Joyner * for, the list must match exactly, including the order in which the 292271d10453SEric Joyner * characteristics are listed. 292371d10453SEric Joyner */ 292471d10453SEric Joyner static enum ice_status 292571d10453SEric Joyner ice_find_dup_props_vsig(struct ice_hw *hw, enum ice_block blk, 292671d10453SEric Joyner struct LIST_HEAD_TYPE *chs, u16 *vsig) 292771d10453SEric Joyner { 292871d10453SEric Joyner struct ice_xlt2 *xlt2 = &hw->blk[blk].xlt2; 292971d10453SEric Joyner u16 i; 293071d10453SEric Joyner 2931*7d7af7f8SEric Joyner for (i = 0; i < xlt2->count; i++) 293271d10453SEric Joyner if (xlt2->vsig_tbl[i].in_use && 293371d10453SEric Joyner ice_match_prop_lst(chs, &xlt2->vsig_tbl[i].prop_lst)) { 293471d10453SEric Joyner *vsig = ICE_VSIG_VALUE(i, hw->pf_id); 293571d10453SEric Joyner return ICE_SUCCESS; 293671d10453SEric Joyner } 293771d10453SEric Joyner 293871d10453SEric Joyner return ICE_ERR_DOES_NOT_EXIST; 293971d10453SEric Joyner } 294071d10453SEric Joyner 294171d10453SEric Joyner /** 294271d10453SEric Joyner * ice_vsig_free - free VSI group 294371d10453SEric Joyner * @hw: pointer to the hardware structure 294471d10453SEric Joyner * @blk: HW block 294571d10453SEric Joyner * @vsig: VSIG to remove 294671d10453SEric Joyner * 294771d10453SEric Joyner * The function will remove all VSIs associated with the input VSIG and move 294871d10453SEric Joyner * them to the DEFAULT_VSIG and mark the VSIG available. 294971d10453SEric Joyner */ 295071d10453SEric Joyner static enum ice_status 295171d10453SEric Joyner ice_vsig_free(struct ice_hw *hw, enum ice_block blk, u16 vsig) 295271d10453SEric Joyner { 295371d10453SEric Joyner struct ice_vsig_prof *dtmp, *del; 295471d10453SEric Joyner struct ice_vsig_vsi *vsi_cur; 295571d10453SEric Joyner u16 idx; 295671d10453SEric Joyner 295771d10453SEric Joyner idx = vsig & ICE_VSIG_IDX_M; 295871d10453SEric Joyner if (idx >= ICE_MAX_VSIGS) 295971d10453SEric Joyner return ICE_ERR_PARAM; 296071d10453SEric Joyner 296171d10453SEric Joyner if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use) 296271d10453SEric Joyner return ICE_ERR_DOES_NOT_EXIST; 296371d10453SEric Joyner 296471d10453SEric Joyner hw->blk[blk].xlt2.vsig_tbl[idx].in_use = false; 296571d10453SEric Joyner 296671d10453SEric Joyner vsi_cur = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi; 296771d10453SEric Joyner /* If the VSIG has at least 1 VSI then iterate through the 296871d10453SEric Joyner * list and remove the VSIs before deleting the group. 296971d10453SEric Joyner */ 297071d10453SEric Joyner if (vsi_cur) { 297171d10453SEric Joyner /* remove all vsis associated with this VSIG XLT2 entry */ 297271d10453SEric Joyner do { 297371d10453SEric Joyner struct ice_vsig_vsi *tmp = vsi_cur->next_vsi; 297471d10453SEric Joyner 297571d10453SEric Joyner vsi_cur->vsig = ICE_DEFAULT_VSIG; 297671d10453SEric Joyner vsi_cur->changed = 1; 297771d10453SEric Joyner vsi_cur->next_vsi = NULL; 297871d10453SEric Joyner vsi_cur = tmp; 297971d10453SEric Joyner } while (vsi_cur); 298071d10453SEric Joyner 298171d10453SEric Joyner /* NULL terminate head of VSI list */ 298271d10453SEric Joyner hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi = NULL; 298371d10453SEric Joyner } 298471d10453SEric Joyner 298571d10453SEric Joyner /* free characteristic list */ 298671d10453SEric Joyner LIST_FOR_EACH_ENTRY_SAFE(del, dtmp, 298771d10453SEric Joyner &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst, 298871d10453SEric Joyner ice_vsig_prof, list) { 298971d10453SEric Joyner LIST_DEL(&del->list); 299071d10453SEric Joyner ice_free(hw, del); 299171d10453SEric Joyner } 299271d10453SEric Joyner 299371d10453SEric Joyner /* if VSIG characteristic list was cleared for reset 299471d10453SEric Joyner * re-initialize the list head 299571d10453SEric Joyner */ 299671d10453SEric Joyner INIT_LIST_HEAD(&hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst); 299771d10453SEric Joyner 299871d10453SEric Joyner return ICE_SUCCESS; 299971d10453SEric Joyner } 300071d10453SEric Joyner 300171d10453SEric Joyner /** 300271d10453SEric Joyner * ice_vsig_remove_vsi - remove VSI from VSIG 300371d10453SEric Joyner * @hw: pointer to the hardware structure 300471d10453SEric Joyner * @blk: HW block 300571d10453SEric Joyner * @vsi: VSI to remove 300671d10453SEric Joyner * @vsig: VSI group to remove from 300771d10453SEric Joyner * 300871d10453SEric Joyner * The function will remove the input VSI from its VSI group and move it 300971d10453SEric Joyner * to the DEFAULT_VSIG. 301071d10453SEric Joyner */ 301171d10453SEric Joyner static enum ice_status 301271d10453SEric Joyner ice_vsig_remove_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig) 301371d10453SEric Joyner { 301471d10453SEric Joyner struct ice_vsig_vsi **vsi_head, *vsi_cur, *vsi_tgt; 301571d10453SEric Joyner u16 idx; 301671d10453SEric Joyner 301771d10453SEric Joyner idx = vsig & ICE_VSIG_IDX_M; 301871d10453SEric Joyner 301971d10453SEric Joyner if (vsi >= ICE_MAX_VSI || idx >= ICE_MAX_VSIGS) 302071d10453SEric Joyner return ICE_ERR_PARAM; 302171d10453SEric Joyner 302271d10453SEric Joyner if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use) 302371d10453SEric Joyner return ICE_ERR_DOES_NOT_EXIST; 302471d10453SEric Joyner 302571d10453SEric Joyner /* entry already in default VSIG, don't have to remove */ 302671d10453SEric Joyner if (idx == ICE_DEFAULT_VSIG) 302771d10453SEric Joyner return ICE_SUCCESS; 302871d10453SEric Joyner 302971d10453SEric Joyner vsi_head = &hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi; 303071d10453SEric Joyner if (!(*vsi_head)) 303171d10453SEric Joyner return ICE_ERR_CFG; 303271d10453SEric Joyner 303371d10453SEric Joyner vsi_tgt = &hw->blk[blk].xlt2.vsis[vsi]; 303471d10453SEric Joyner vsi_cur = (*vsi_head); 303571d10453SEric Joyner 303671d10453SEric Joyner /* iterate the VSI list, skip over the entry to be removed */ 303771d10453SEric Joyner while (vsi_cur) { 303871d10453SEric Joyner if (vsi_tgt == vsi_cur) { 303971d10453SEric Joyner (*vsi_head) = vsi_cur->next_vsi; 304071d10453SEric Joyner break; 304171d10453SEric Joyner } 304271d10453SEric Joyner vsi_head = &vsi_cur->next_vsi; 304371d10453SEric Joyner vsi_cur = vsi_cur->next_vsi; 304471d10453SEric Joyner } 304571d10453SEric Joyner 304671d10453SEric Joyner /* verify if VSI was removed from group list */ 304771d10453SEric Joyner if (!vsi_cur) 304871d10453SEric Joyner return ICE_ERR_DOES_NOT_EXIST; 304971d10453SEric Joyner 305071d10453SEric Joyner vsi_cur->vsig = ICE_DEFAULT_VSIG; 305171d10453SEric Joyner vsi_cur->changed = 1; 305271d10453SEric Joyner vsi_cur->next_vsi = NULL; 305371d10453SEric Joyner 305471d10453SEric Joyner return ICE_SUCCESS; 305571d10453SEric Joyner } 305671d10453SEric Joyner 305771d10453SEric Joyner /** 305871d10453SEric Joyner * ice_vsig_add_mv_vsi - add or move a VSI to a VSI group 305971d10453SEric Joyner * @hw: pointer to the hardware structure 306071d10453SEric Joyner * @blk: HW block 306171d10453SEric Joyner * @vsi: VSI to move 306271d10453SEric Joyner * @vsig: destination VSI group 306371d10453SEric Joyner * 306471d10453SEric Joyner * This function will move or add the input VSI to the target VSIG. 306571d10453SEric Joyner * The function will find the original VSIG the VSI belongs to and 306671d10453SEric Joyner * move the entry to the DEFAULT_VSIG, update the original VSIG and 306771d10453SEric Joyner * then move entry to the new VSIG. 306871d10453SEric Joyner */ 306971d10453SEric Joyner static enum ice_status 307071d10453SEric Joyner ice_vsig_add_mv_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig) 307171d10453SEric Joyner { 307271d10453SEric Joyner struct ice_vsig_vsi *tmp; 307371d10453SEric Joyner enum ice_status status; 307471d10453SEric Joyner u16 orig_vsig, idx; 307571d10453SEric Joyner 307671d10453SEric Joyner idx = vsig & ICE_VSIG_IDX_M; 307771d10453SEric Joyner 307871d10453SEric Joyner if (vsi >= ICE_MAX_VSI || idx >= ICE_MAX_VSIGS) 307971d10453SEric Joyner return ICE_ERR_PARAM; 308071d10453SEric Joyner 308171d10453SEric Joyner /* if VSIG not in use and VSIG is not default type this VSIG 308271d10453SEric Joyner * doesn't exist. 308371d10453SEric Joyner */ 308471d10453SEric Joyner if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use && 308571d10453SEric Joyner vsig != ICE_DEFAULT_VSIG) 308671d10453SEric Joyner return ICE_ERR_DOES_NOT_EXIST; 308771d10453SEric Joyner 308871d10453SEric Joyner status = ice_vsig_find_vsi(hw, blk, vsi, &orig_vsig); 308971d10453SEric Joyner if (status) 309071d10453SEric Joyner return status; 309171d10453SEric Joyner 309271d10453SEric Joyner /* no update required if vsigs match */ 309371d10453SEric Joyner if (orig_vsig == vsig) 309471d10453SEric Joyner return ICE_SUCCESS; 309571d10453SEric Joyner 309671d10453SEric Joyner if (orig_vsig != ICE_DEFAULT_VSIG) { 309771d10453SEric Joyner /* remove entry from orig_vsig and add to default VSIG */ 309871d10453SEric Joyner status = ice_vsig_remove_vsi(hw, blk, vsi, orig_vsig); 309971d10453SEric Joyner if (status) 310071d10453SEric Joyner return status; 310171d10453SEric Joyner } 310271d10453SEric Joyner 310371d10453SEric Joyner if (idx == ICE_DEFAULT_VSIG) 310471d10453SEric Joyner return ICE_SUCCESS; 310571d10453SEric Joyner 310671d10453SEric Joyner /* Create VSI entry and add VSIG and prop_mask values */ 310771d10453SEric Joyner hw->blk[blk].xlt2.vsis[vsi].vsig = vsig; 310871d10453SEric Joyner hw->blk[blk].xlt2.vsis[vsi].changed = 1; 310971d10453SEric Joyner 311071d10453SEric Joyner /* Add new entry to the head of the VSIG list */ 311171d10453SEric Joyner tmp = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi; 311271d10453SEric Joyner hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi = 311371d10453SEric Joyner &hw->blk[blk].xlt2.vsis[vsi]; 311471d10453SEric Joyner hw->blk[blk].xlt2.vsis[vsi].next_vsi = tmp; 311571d10453SEric Joyner hw->blk[blk].xlt2.t[vsi] = vsig; 311671d10453SEric Joyner 311771d10453SEric Joyner return ICE_SUCCESS; 311871d10453SEric Joyner } 311971d10453SEric Joyner 312071d10453SEric Joyner /** 312171d10453SEric Joyner * ice_find_prof_id - find profile ID for a given field vector 312271d10453SEric Joyner * @hw: pointer to the hardware structure 312371d10453SEric Joyner * @blk: HW block 312471d10453SEric Joyner * @fv: field vector to search for 312571d10453SEric Joyner * @prof_id: receives the profile ID 312671d10453SEric Joyner */ 312771d10453SEric Joyner static enum ice_status 312871d10453SEric Joyner ice_find_prof_id(struct ice_hw *hw, enum ice_block blk, 312971d10453SEric Joyner struct ice_fv_word *fv, u8 *prof_id) 313071d10453SEric Joyner { 313171d10453SEric Joyner struct ice_es *es = &hw->blk[blk].es; 313271d10453SEric Joyner u16 off; 313371d10453SEric Joyner u8 i; 313471d10453SEric Joyner 313571d10453SEric Joyner for (i = 0; i < (u8)es->count; i++) { 313671d10453SEric Joyner off = i * es->fvw; 313771d10453SEric Joyner 313871d10453SEric Joyner if (memcmp(&es->t[off], fv, es->fvw * sizeof(*fv))) 313971d10453SEric Joyner continue; 314071d10453SEric Joyner 314171d10453SEric Joyner *prof_id = i; 314271d10453SEric Joyner return ICE_SUCCESS; 314371d10453SEric Joyner } 314471d10453SEric Joyner 314571d10453SEric Joyner return ICE_ERR_DOES_NOT_EXIST; 314671d10453SEric Joyner } 314771d10453SEric Joyner 314871d10453SEric Joyner /** 314971d10453SEric Joyner * ice_prof_id_rsrc_type - get profile ID resource type for a block type 315071d10453SEric Joyner * @blk: the block type 315171d10453SEric Joyner * @rsrc_type: pointer to variable to receive the resource type 315271d10453SEric Joyner */ 315371d10453SEric Joyner static bool ice_prof_id_rsrc_type(enum ice_block blk, u16 *rsrc_type) 315471d10453SEric Joyner { 315571d10453SEric Joyner switch (blk) { 315671d10453SEric Joyner case ICE_BLK_RSS: 315771d10453SEric Joyner *rsrc_type = ICE_AQC_RES_TYPE_HASH_PROF_BLDR_PROFID; 315871d10453SEric Joyner break; 315971d10453SEric Joyner case ICE_BLK_PE: 316071d10453SEric Joyner *rsrc_type = ICE_AQC_RES_TYPE_QHASH_PROF_BLDR_PROFID; 316171d10453SEric Joyner break; 316271d10453SEric Joyner default: 316371d10453SEric Joyner return false; 316471d10453SEric Joyner } 316571d10453SEric Joyner return true; 316671d10453SEric Joyner } 316771d10453SEric Joyner 316871d10453SEric Joyner /** 316971d10453SEric Joyner * ice_tcam_ent_rsrc_type - get TCAM entry resource type for a block type 317071d10453SEric Joyner * @blk: the block type 317171d10453SEric Joyner * @rsrc_type: pointer to variable to receive the resource type 317271d10453SEric Joyner */ 317371d10453SEric Joyner static bool ice_tcam_ent_rsrc_type(enum ice_block blk, u16 *rsrc_type) 317471d10453SEric Joyner { 317571d10453SEric Joyner switch (blk) { 317671d10453SEric Joyner case ICE_BLK_RSS: 317771d10453SEric Joyner *rsrc_type = ICE_AQC_RES_TYPE_HASH_PROF_BLDR_TCAM; 317871d10453SEric Joyner break; 317971d10453SEric Joyner case ICE_BLK_PE: 318071d10453SEric Joyner *rsrc_type = ICE_AQC_RES_TYPE_QHASH_PROF_BLDR_TCAM; 318171d10453SEric Joyner break; 318271d10453SEric Joyner default: 318371d10453SEric Joyner return false; 318471d10453SEric Joyner } 318571d10453SEric Joyner return true; 318671d10453SEric Joyner } 318771d10453SEric Joyner 318871d10453SEric Joyner /** 318971d10453SEric Joyner * ice_alloc_tcam_ent - allocate hardware TCAM entry 319071d10453SEric Joyner * @hw: pointer to the HW struct 319171d10453SEric Joyner * @blk: the block to allocate the TCAM for 3192*7d7af7f8SEric Joyner * @btm: true to allocate from bottom of table, false to allocate from top 319371d10453SEric Joyner * @tcam_idx: pointer to variable to receive the TCAM entry 319471d10453SEric Joyner * 319571d10453SEric Joyner * This function allocates a new entry in a Profile ID TCAM for a specific 319671d10453SEric Joyner * block. 319771d10453SEric Joyner */ 319871d10453SEric Joyner static enum ice_status 3199*7d7af7f8SEric Joyner ice_alloc_tcam_ent(struct ice_hw *hw, enum ice_block blk, bool btm, 3200*7d7af7f8SEric Joyner u16 *tcam_idx) 320171d10453SEric Joyner { 320271d10453SEric Joyner u16 res_type; 320371d10453SEric Joyner 320471d10453SEric Joyner if (!ice_tcam_ent_rsrc_type(blk, &res_type)) 320571d10453SEric Joyner return ICE_ERR_PARAM; 320671d10453SEric Joyner 3207*7d7af7f8SEric Joyner return ice_alloc_hw_res(hw, res_type, 1, btm, tcam_idx); 320871d10453SEric Joyner } 320971d10453SEric Joyner 321071d10453SEric Joyner /** 321171d10453SEric Joyner * ice_free_tcam_ent - free hardware TCAM entry 321271d10453SEric Joyner * @hw: pointer to the HW struct 321371d10453SEric Joyner * @blk: the block from which to free the TCAM entry 321471d10453SEric Joyner * @tcam_idx: the TCAM entry to free 321571d10453SEric Joyner * 321671d10453SEric Joyner * This function frees an entry in a Profile ID TCAM for a specific block. 321771d10453SEric Joyner */ 321871d10453SEric Joyner static enum ice_status 321971d10453SEric Joyner ice_free_tcam_ent(struct ice_hw *hw, enum ice_block blk, u16 tcam_idx) 322071d10453SEric Joyner { 322171d10453SEric Joyner u16 res_type; 322271d10453SEric Joyner 322371d10453SEric Joyner if (!ice_tcam_ent_rsrc_type(blk, &res_type)) 322471d10453SEric Joyner return ICE_ERR_PARAM; 322571d10453SEric Joyner 322671d10453SEric Joyner return ice_free_hw_res(hw, res_type, 1, &tcam_idx); 322771d10453SEric Joyner } 322871d10453SEric Joyner 322971d10453SEric Joyner /** 323071d10453SEric Joyner * ice_alloc_prof_id - allocate profile ID 323171d10453SEric Joyner * @hw: pointer to the HW struct 323271d10453SEric Joyner * @blk: the block to allocate the profile ID for 323371d10453SEric Joyner * @prof_id: pointer to variable to receive the profile ID 323471d10453SEric Joyner * 323571d10453SEric Joyner * This function allocates a new profile ID, which also corresponds to a Field 323671d10453SEric Joyner * Vector (Extraction Sequence) entry. 323771d10453SEric Joyner */ 323871d10453SEric Joyner static enum ice_status 323971d10453SEric Joyner ice_alloc_prof_id(struct ice_hw *hw, enum ice_block blk, u8 *prof_id) 324071d10453SEric Joyner { 324171d10453SEric Joyner enum ice_status status; 324271d10453SEric Joyner u16 res_type; 324371d10453SEric Joyner u16 get_prof; 324471d10453SEric Joyner 324571d10453SEric Joyner if (!ice_prof_id_rsrc_type(blk, &res_type)) 324671d10453SEric Joyner return ICE_ERR_PARAM; 324771d10453SEric Joyner 324871d10453SEric Joyner status = ice_alloc_hw_res(hw, res_type, 1, false, &get_prof); 324971d10453SEric Joyner if (!status) 325071d10453SEric Joyner *prof_id = (u8)get_prof; 325171d10453SEric Joyner 325271d10453SEric Joyner return status; 325371d10453SEric Joyner } 325471d10453SEric Joyner 325571d10453SEric Joyner /** 325671d10453SEric Joyner * ice_free_prof_id - free profile ID 325771d10453SEric Joyner * @hw: pointer to the HW struct 325871d10453SEric Joyner * @blk: the block from which to free the profile ID 325971d10453SEric Joyner * @prof_id: the profile ID to free 326071d10453SEric Joyner * 326171d10453SEric Joyner * This function frees a profile ID, which also corresponds to a Field Vector. 326271d10453SEric Joyner */ 326371d10453SEric Joyner static enum ice_status 326471d10453SEric Joyner ice_free_prof_id(struct ice_hw *hw, enum ice_block blk, u8 prof_id) 326571d10453SEric Joyner { 326671d10453SEric Joyner u16 tmp_prof_id = (u16)prof_id; 326771d10453SEric Joyner u16 res_type; 326871d10453SEric Joyner 326971d10453SEric Joyner if (!ice_prof_id_rsrc_type(blk, &res_type)) 327071d10453SEric Joyner return ICE_ERR_PARAM; 327171d10453SEric Joyner 327271d10453SEric Joyner return ice_free_hw_res(hw, res_type, 1, &tmp_prof_id); 327371d10453SEric Joyner } 327471d10453SEric Joyner 327571d10453SEric Joyner /** 327671d10453SEric Joyner * ice_prof_inc_ref - increment reference count for profile 327771d10453SEric Joyner * @hw: pointer to the HW struct 327871d10453SEric Joyner * @blk: the block from which to free the profile ID 327971d10453SEric Joyner * @prof_id: the profile ID for which to increment the reference count 328071d10453SEric Joyner */ 328171d10453SEric Joyner static enum ice_status 328271d10453SEric Joyner ice_prof_inc_ref(struct ice_hw *hw, enum ice_block blk, u8 prof_id) 328371d10453SEric Joyner { 328471d10453SEric Joyner if (prof_id > hw->blk[blk].es.count) 328571d10453SEric Joyner return ICE_ERR_PARAM; 328671d10453SEric Joyner 328771d10453SEric Joyner hw->blk[blk].es.ref_count[prof_id]++; 328871d10453SEric Joyner 328971d10453SEric Joyner return ICE_SUCCESS; 329071d10453SEric Joyner } 329171d10453SEric Joyner 329271d10453SEric Joyner /** 329371d10453SEric Joyner * ice_write_es - write an extraction sequence to hardware 329471d10453SEric Joyner * @hw: pointer to the HW struct 329571d10453SEric Joyner * @blk: the block in which to write the extraction sequence 329671d10453SEric Joyner * @prof_id: the profile ID to write 329771d10453SEric Joyner * @fv: pointer to the extraction sequence to write - NULL to clear extraction 329871d10453SEric Joyner */ 329971d10453SEric Joyner static void 330071d10453SEric Joyner ice_write_es(struct ice_hw *hw, enum ice_block blk, u8 prof_id, 330171d10453SEric Joyner struct ice_fv_word *fv) 330271d10453SEric Joyner { 330371d10453SEric Joyner u16 off; 330471d10453SEric Joyner 330571d10453SEric Joyner off = prof_id * hw->blk[blk].es.fvw; 330671d10453SEric Joyner if (!fv) { 330771d10453SEric Joyner ice_memset(&hw->blk[blk].es.t[off], 0, hw->blk[blk].es.fvw * 330871d10453SEric Joyner sizeof(*fv), ICE_NONDMA_MEM); 330971d10453SEric Joyner hw->blk[blk].es.written[prof_id] = false; 331071d10453SEric Joyner } else { 331171d10453SEric Joyner ice_memcpy(&hw->blk[blk].es.t[off], fv, hw->blk[blk].es.fvw * 331271d10453SEric Joyner sizeof(*fv), ICE_NONDMA_TO_NONDMA); 331371d10453SEric Joyner } 331471d10453SEric Joyner } 331571d10453SEric Joyner 331671d10453SEric Joyner /** 331771d10453SEric Joyner * ice_prof_dec_ref - decrement reference count for profile 331871d10453SEric Joyner * @hw: pointer to the HW struct 331971d10453SEric Joyner * @blk: the block from which to free the profile ID 332071d10453SEric Joyner * @prof_id: the profile ID for which to decrement the reference count 332171d10453SEric Joyner */ 332271d10453SEric Joyner static enum ice_status 332371d10453SEric Joyner ice_prof_dec_ref(struct ice_hw *hw, enum ice_block blk, u8 prof_id) 332471d10453SEric Joyner { 332571d10453SEric Joyner if (prof_id > hw->blk[blk].es.count) 332671d10453SEric Joyner return ICE_ERR_PARAM; 332771d10453SEric Joyner 332871d10453SEric Joyner if (hw->blk[blk].es.ref_count[prof_id] > 0) { 332971d10453SEric Joyner if (!--hw->blk[blk].es.ref_count[prof_id]) { 333071d10453SEric Joyner ice_write_es(hw, blk, prof_id, NULL); 333171d10453SEric Joyner return ice_free_prof_id(hw, blk, prof_id); 333271d10453SEric Joyner } 333371d10453SEric Joyner } 333471d10453SEric Joyner 333571d10453SEric Joyner return ICE_SUCCESS; 333671d10453SEric Joyner } 333771d10453SEric Joyner 333871d10453SEric Joyner /* Block / table section IDs */ 333971d10453SEric Joyner static const u32 ice_blk_sids[ICE_BLK_COUNT][ICE_SID_OFF_COUNT] = { 334071d10453SEric Joyner /* SWITCH */ 334171d10453SEric Joyner { ICE_SID_XLT1_SW, 334271d10453SEric Joyner ICE_SID_XLT2_SW, 334371d10453SEric Joyner ICE_SID_PROFID_TCAM_SW, 334471d10453SEric Joyner ICE_SID_PROFID_REDIR_SW, 334571d10453SEric Joyner ICE_SID_FLD_VEC_SW 334671d10453SEric Joyner }, 334771d10453SEric Joyner 334871d10453SEric Joyner /* ACL */ 334971d10453SEric Joyner { ICE_SID_XLT1_ACL, 335071d10453SEric Joyner ICE_SID_XLT2_ACL, 335171d10453SEric Joyner ICE_SID_PROFID_TCAM_ACL, 335271d10453SEric Joyner ICE_SID_PROFID_REDIR_ACL, 335371d10453SEric Joyner ICE_SID_FLD_VEC_ACL 335471d10453SEric Joyner }, 335571d10453SEric Joyner 335671d10453SEric Joyner /* FD */ 335771d10453SEric Joyner { ICE_SID_XLT1_FD, 335871d10453SEric Joyner ICE_SID_XLT2_FD, 335971d10453SEric Joyner ICE_SID_PROFID_TCAM_FD, 336071d10453SEric Joyner ICE_SID_PROFID_REDIR_FD, 336171d10453SEric Joyner ICE_SID_FLD_VEC_FD 336271d10453SEric Joyner }, 336371d10453SEric Joyner 336471d10453SEric Joyner /* RSS */ 336571d10453SEric Joyner { ICE_SID_XLT1_RSS, 336671d10453SEric Joyner ICE_SID_XLT2_RSS, 336771d10453SEric Joyner ICE_SID_PROFID_TCAM_RSS, 336871d10453SEric Joyner ICE_SID_PROFID_REDIR_RSS, 336971d10453SEric Joyner ICE_SID_FLD_VEC_RSS 337071d10453SEric Joyner }, 337171d10453SEric Joyner 337271d10453SEric Joyner /* PE */ 337371d10453SEric Joyner { ICE_SID_XLT1_PE, 337471d10453SEric Joyner ICE_SID_XLT2_PE, 337571d10453SEric Joyner ICE_SID_PROFID_TCAM_PE, 337671d10453SEric Joyner ICE_SID_PROFID_REDIR_PE, 337771d10453SEric Joyner ICE_SID_FLD_VEC_PE 337871d10453SEric Joyner } 337971d10453SEric Joyner }; 338071d10453SEric Joyner 338171d10453SEric Joyner /** 338271d10453SEric Joyner * ice_init_sw_xlt1_db - init software XLT1 database from HW tables 338371d10453SEric Joyner * @hw: pointer to the hardware structure 338471d10453SEric Joyner * @blk: the HW block to initialize 338571d10453SEric Joyner */ 338671d10453SEric Joyner static void ice_init_sw_xlt1_db(struct ice_hw *hw, enum ice_block blk) 338771d10453SEric Joyner { 338871d10453SEric Joyner u16 pt; 338971d10453SEric Joyner 339071d10453SEric Joyner for (pt = 0; pt < hw->blk[blk].xlt1.count; pt++) { 339171d10453SEric Joyner u8 ptg; 339271d10453SEric Joyner 339371d10453SEric Joyner ptg = hw->blk[blk].xlt1.t[pt]; 339471d10453SEric Joyner if (ptg != ICE_DEFAULT_PTG) { 339571d10453SEric Joyner ice_ptg_alloc_val(hw, blk, ptg); 339671d10453SEric Joyner ice_ptg_add_mv_ptype(hw, blk, pt, ptg); 339771d10453SEric Joyner } 339871d10453SEric Joyner } 339971d10453SEric Joyner } 340071d10453SEric Joyner 340171d10453SEric Joyner /** 340271d10453SEric Joyner * ice_init_sw_xlt2_db - init software XLT2 database from HW tables 340371d10453SEric Joyner * @hw: pointer to the hardware structure 340471d10453SEric Joyner * @blk: the HW block to initialize 340571d10453SEric Joyner */ 340671d10453SEric Joyner static void ice_init_sw_xlt2_db(struct ice_hw *hw, enum ice_block blk) 340771d10453SEric Joyner { 340871d10453SEric Joyner u16 vsi; 340971d10453SEric Joyner 341071d10453SEric Joyner for (vsi = 0; vsi < hw->blk[blk].xlt2.count; vsi++) { 341171d10453SEric Joyner u16 vsig; 341271d10453SEric Joyner 341371d10453SEric Joyner vsig = hw->blk[blk].xlt2.t[vsi]; 341471d10453SEric Joyner if (vsig) { 341571d10453SEric Joyner ice_vsig_alloc_val(hw, blk, vsig); 341671d10453SEric Joyner ice_vsig_add_mv_vsi(hw, blk, vsi, vsig); 341771d10453SEric Joyner /* no changes at this time, since this has been 341871d10453SEric Joyner * initialized from the original package 341971d10453SEric Joyner */ 342071d10453SEric Joyner hw->blk[blk].xlt2.vsis[vsi].changed = 0; 342171d10453SEric Joyner } 342271d10453SEric Joyner } 342371d10453SEric Joyner } 342471d10453SEric Joyner 342571d10453SEric Joyner /** 342671d10453SEric Joyner * ice_init_sw_db - init software database from HW tables 342771d10453SEric Joyner * @hw: pointer to the hardware structure 342871d10453SEric Joyner */ 342971d10453SEric Joyner static void ice_init_sw_db(struct ice_hw *hw) 343071d10453SEric Joyner { 343171d10453SEric Joyner u16 i; 343271d10453SEric Joyner 343371d10453SEric Joyner for (i = 0; i < ICE_BLK_COUNT; i++) { 343471d10453SEric Joyner ice_init_sw_xlt1_db(hw, (enum ice_block)i); 343571d10453SEric Joyner ice_init_sw_xlt2_db(hw, (enum ice_block)i); 343671d10453SEric Joyner } 343771d10453SEric Joyner } 343871d10453SEric Joyner 343971d10453SEric Joyner /** 344071d10453SEric Joyner * ice_fill_tbl - Reads content of a single table type into database 344171d10453SEric Joyner * @hw: pointer to the hardware structure 344271d10453SEric Joyner * @block_id: Block ID of the table to copy 344371d10453SEric Joyner * @sid: Section ID of the table to copy 344471d10453SEric Joyner * 344571d10453SEric Joyner * Will attempt to read the entire content of a given table of a single block 344671d10453SEric Joyner * into the driver database. We assume that the buffer will always 344771d10453SEric Joyner * be as large or larger than the data contained in the package. If 344871d10453SEric Joyner * this condition is not met, there is most likely an error in the package 344971d10453SEric Joyner * contents. 345071d10453SEric Joyner */ 345171d10453SEric Joyner static void ice_fill_tbl(struct ice_hw *hw, enum ice_block block_id, u32 sid) 345271d10453SEric Joyner { 345371d10453SEric Joyner u32 dst_len, sect_len, offset = 0; 345471d10453SEric Joyner struct ice_prof_redir_section *pr; 345571d10453SEric Joyner struct ice_prof_id_section *pid; 345671d10453SEric Joyner struct ice_xlt1_section *xlt1; 345771d10453SEric Joyner struct ice_xlt2_section *xlt2; 345871d10453SEric Joyner struct ice_sw_fv_section *es; 345971d10453SEric Joyner struct ice_pkg_enum state; 346071d10453SEric Joyner u8 *src, *dst; 346171d10453SEric Joyner void *sect; 346271d10453SEric Joyner 346371d10453SEric Joyner /* if the HW segment pointer is null then the first iteration of 346471d10453SEric Joyner * ice_pkg_enum_section() will fail. In this case the HW tables will 346571d10453SEric Joyner * not be filled and return success. 346671d10453SEric Joyner */ 346771d10453SEric Joyner if (!hw->seg) { 346871d10453SEric Joyner ice_debug(hw, ICE_DBG_PKG, "hw->seg is NULL, tables are not filled\n"); 346971d10453SEric Joyner return; 347071d10453SEric Joyner } 347171d10453SEric Joyner 347271d10453SEric Joyner ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM); 347371d10453SEric Joyner 347471d10453SEric Joyner sect = ice_pkg_enum_section(hw->seg, &state, sid); 347571d10453SEric Joyner 347671d10453SEric Joyner while (sect) { 347771d10453SEric Joyner switch (sid) { 347871d10453SEric Joyner case ICE_SID_XLT1_SW: 347971d10453SEric Joyner case ICE_SID_XLT1_FD: 348071d10453SEric Joyner case ICE_SID_XLT1_RSS: 348171d10453SEric Joyner case ICE_SID_XLT1_ACL: 348271d10453SEric Joyner case ICE_SID_XLT1_PE: 348371d10453SEric Joyner xlt1 = (struct ice_xlt1_section *)sect; 348471d10453SEric Joyner src = xlt1->value; 348571d10453SEric Joyner sect_len = LE16_TO_CPU(xlt1->count) * 348671d10453SEric Joyner sizeof(*hw->blk[block_id].xlt1.t); 348771d10453SEric Joyner dst = hw->blk[block_id].xlt1.t; 348871d10453SEric Joyner dst_len = hw->blk[block_id].xlt1.count * 348971d10453SEric Joyner sizeof(*hw->blk[block_id].xlt1.t); 349071d10453SEric Joyner break; 349171d10453SEric Joyner case ICE_SID_XLT2_SW: 349271d10453SEric Joyner case ICE_SID_XLT2_FD: 349371d10453SEric Joyner case ICE_SID_XLT2_RSS: 349471d10453SEric Joyner case ICE_SID_XLT2_ACL: 349571d10453SEric Joyner case ICE_SID_XLT2_PE: 349671d10453SEric Joyner xlt2 = (struct ice_xlt2_section *)sect; 349771d10453SEric Joyner src = (_FORCE_ u8 *)xlt2->value; 349871d10453SEric Joyner sect_len = LE16_TO_CPU(xlt2->count) * 349971d10453SEric Joyner sizeof(*hw->blk[block_id].xlt2.t); 350071d10453SEric Joyner dst = (u8 *)hw->blk[block_id].xlt2.t; 350171d10453SEric Joyner dst_len = hw->blk[block_id].xlt2.count * 350271d10453SEric Joyner sizeof(*hw->blk[block_id].xlt2.t); 350371d10453SEric Joyner break; 350471d10453SEric Joyner case ICE_SID_PROFID_TCAM_SW: 350571d10453SEric Joyner case ICE_SID_PROFID_TCAM_FD: 350671d10453SEric Joyner case ICE_SID_PROFID_TCAM_RSS: 350771d10453SEric Joyner case ICE_SID_PROFID_TCAM_ACL: 350871d10453SEric Joyner case ICE_SID_PROFID_TCAM_PE: 350971d10453SEric Joyner pid = (struct ice_prof_id_section *)sect; 351071d10453SEric Joyner src = (u8 *)pid->entry; 351171d10453SEric Joyner sect_len = LE16_TO_CPU(pid->count) * 351271d10453SEric Joyner sizeof(*hw->blk[block_id].prof.t); 351371d10453SEric Joyner dst = (u8 *)hw->blk[block_id].prof.t; 351471d10453SEric Joyner dst_len = hw->blk[block_id].prof.count * 351571d10453SEric Joyner sizeof(*hw->blk[block_id].prof.t); 351671d10453SEric Joyner break; 351771d10453SEric Joyner case ICE_SID_PROFID_REDIR_SW: 351871d10453SEric Joyner case ICE_SID_PROFID_REDIR_FD: 351971d10453SEric Joyner case ICE_SID_PROFID_REDIR_RSS: 352071d10453SEric Joyner case ICE_SID_PROFID_REDIR_ACL: 352171d10453SEric Joyner case ICE_SID_PROFID_REDIR_PE: 352271d10453SEric Joyner pr = (struct ice_prof_redir_section *)sect; 352371d10453SEric Joyner src = pr->redir_value; 352471d10453SEric Joyner sect_len = LE16_TO_CPU(pr->count) * 352571d10453SEric Joyner sizeof(*hw->blk[block_id].prof_redir.t); 352671d10453SEric Joyner dst = hw->blk[block_id].prof_redir.t; 352771d10453SEric Joyner dst_len = hw->blk[block_id].prof_redir.count * 352871d10453SEric Joyner sizeof(*hw->blk[block_id].prof_redir.t); 352971d10453SEric Joyner break; 353071d10453SEric Joyner case ICE_SID_FLD_VEC_SW: 353171d10453SEric Joyner case ICE_SID_FLD_VEC_FD: 353271d10453SEric Joyner case ICE_SID_FLD_VEC_RSS: 353371d10453SEric Joyner case ICE_SID_FLD_VEC_ACL: 353471d10453SEric Joyner case ICE_SID_FLD_VEC_PE: 353571d10453SEric Joyner es = (struct ice_sw_fv_section *)sect; 353671d10453SEric Joyner src = (u8 *)es->fv; 353771d10453SEric Joyner sect_len = (u32)(LE16_TO_CPU(es->count) * 353871d10453SEric Joyner hw->blk[block_id].es.fvw) * 353971d10453SEric Joyner sizeof(*hw->blk[block_id].es.t); 354071d10453SEric Joyner dst = (u8 *)hw->blk[block_id].es.t; 354171d10453SEric Joyner dst_len = (u32)(hw->blk[block_id].es.count * 354271d10453SEric Joyner hw->blk[block_id].es.fvw) * 354371d10453SEric Joyner sizeof(*hw->blk[block_id].es.t); 354471d10453SEric Joyner break; 354571d10453SEric Joyner default: 354671d10453SEric Joyner return; 354771d10453SEric Joyner } 354871d10453SEric Joyner 354971d10453SEric Joyner /* if the section offset exceeds destination length, terminate 355071d10453SEric Joyner * table fill. 355171d10453SEric Joyner */ 355271d10453SEric Joyner if (offset > dst_len) 355371d10453SEric Joyner return; 355471d10453SEric Joyner 355571d10453SEric Joyner /* if the sum of section size and offset exceed destination size 355671d10453SEric Joyner * then we are out of bounds of the HW table size for that PF. 355771d10453SEric Joyner * Changing section length to fill the remaining table space 355871d10453SEric Joyner * of that PF. 355971d10453SEric Joyner */ 356071d10453SEric Joyner if ((offset + sect_len) > dst_len) 356171d10453SEric Joyner sect_len = dst_len - offset; 356271d10453SEric Joyner 356371d10453SEric Joyner ice_memcpy(dst + offset, src, sect_len, ICE_NONDMA_TO_NONDMA); 356471d10453SEric Joyner offset += sect_len; 356571d10453SEric Joyner sect = ice_pkg_enum_section(NULL, &state, sid); 356671d10453SEric Joyner } 356771d10453SEric Joyner } 356871d10453SEric Joyner 356971d10453SEric Joyner /** 357071d10453SEric Joyner * ice_fill_blk_tbls - Read package context for tables 357171d10453SEric Joyner * @hw: pointer to the hardware structure 357271d10453SEric Joyner * 357371d10453SEric Joyner * Reads the current package contents and populates the driver 357471d10453SEric Joyner * database with the data iteratively for all advanced feature 357571d10453SEric Joyner * blocks. Assume that the HW tables have been allocated. 357671d10453SEric Joyner */ 357771d10453SEric Joyner void ice_fill_blk_tbls(struct ice_hw *hw) 357871d10453SEric Joyner { 357971d10453SEric Joyner u8 i; 358071d10453SEric Joyner 358171d10453SEric Joyner for (i = 0; i < ICE_BLK_COUNT; i++) { 358271d10453SEric Joyner enum ice_block blk_id = (enum ice_block)i; 358371d10453SEric Joyner 358471d10453SEric Joyner ice_fill_tbl(hw, blk_id, hw->blk[blk_id].xlt1.sid); 358571d10453SEric Joyner ice_fill_tbl(hw, blk_id, hw->blk[blk_id].xlt2.sid); 358671d10453SEric Joyner ice_fill_tbl(hw, blk_id, hw->blk[blk_id].prof.sid); 358771d10453SEric Joyner ice_fill_tbl(hw, blk_id, hw->blk[blk_id].prof_redir.sid); 358871d10453SEric Joyner ice_fill_tbl(hw, blk_id, hw->blk[blk_id].es.sid); 358971d10453SEric Joyner } 359071d10453SEric Joyner 359171d10453SEric Joyner ice_init_sw_db(hw); 359271d10453SEric Joyner } 359371d10453SEric Joyner 359471d10453SEric Joyner /** 359571d10453SEric Joyner * ice_free_prof_map - free profile map 359671d10453SEric Joyner * @hw: pointer to the hardware structure 359771d10453SEric Joyner * @blk_idx: HW block index 359871d10453SEric Joyner */ 359971d10453SEric Joyner static void ice_free_prof_map(struct ice_hw *hw, u8 blk_idx) 360071d10453SEric Joyner { 360171d10453SEric Joyner struct ice_es *es = &hw->blk[blk_idx].es; 360271d10453SEric Joyner struct ice_prof_map *del, *tmp; 360371d10453SEric Joyner 360471d10453SEric Joyner ice_acquire_lock(&es->prof_map_lock); 360571d10453SEric Joyner LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &es->prof_map, 360671d10453SEric Joyner ice_prof_map, list) { 360771d10453SEric Joyner LIST_DEL(&del->list); 360871d10453SEric Joyner ice_free(hw, del); 360971d10453SEric Joyner } 361071d10453SEric Joyner INIT_LIST_HEAD(&es->prof_map); 361171d10453SEric Joyner ice_release_lock(&es->prof_map_lock); 361271d10453SEric Joyner } 361371d10453SEric Joyner 361471d10453SEric Joyner /** 361571d10453SEric Joyner * ice_free_flow_profs - free flow profile entries 361671d10453SEric Joyner * @hw: pointer to the hardware structure 361771d10453SEric Joyner * @blk_idx: HW block index 361871d10453SEric Joyner */ 361971d10453SEric Joyner static void ice_free_flow_profs(struct ice_hw *hw, u8 blk_idx) 362071d10453SEric Joyner { 362171d10453SEric Joyner struct ice_flow_prof *p, *tmp; 362271d10453SEric Joyner 362371d10453SEric Joyner ice_acquire_lock(&hw->fl_profs_locks[blk_idx]); 362471d10453SEric Joyner LIST_FOR_EACH_ENTRY_SAFE(p, tmp, &hw->fl_profs[blk_idx], 362571d10453SEric Joyner ice_flow_prof, l_entry) { 362671d10453SEric Joyner LIST_DEL(&p->l_entry); 3627*7d7af7f8SEric Joyner 362871d10453SEric Joyner ice_free(hw, p); 362971d10453SEric Joyner } 363071d10453SEric Joyner ice_release_lock(&hw->fl_profs_locks[blk_idx]); 363171d10453SEric Joyner 363271d10453SEric Joyner /* if driver is in reset and tables are being cleared 363371d10453SEric Joyner * re-initialize the flow profile list heads 363471d10453SEric Joyner */ 363571d10453SEric Joyner INIT_LIST_HEAD(&hw->fl_profs[blk_idx]); 363671d10453SEric Joyner } 363771d10453SEric Joyner 363871d10453SEric Joyner /** 363971d10453SEric Joyner * ice_free_vsig_tbl - free complete VSIG table entries 364071d10453SEric Joyner * @hw: pointer to the hardware structure 364171d10453SEric Joyner * @blk: the HW block on which to free the VSIG table entries 364271d10453SEric Joyner */ 364371d10453SEric Joyner static void ice_free_vsig_tbl(struct ice_hw *hw, enum ice_block blk) 364471d10453SEric Joyner { 364571d10453SEric Joyner u16 i; 364671d10453SEric Joyner 364771d10453SEric Joyner if (!hw->blk[blk].xlt2.vsig_tbl) 364871d10453SEric Joyner return; 364971d10453SEric Joyner 365071d10453SEric Joyner for (i = 1; i < ICE_MAX_VSIGS; i++) 365171d10453SEric Joyner if (hw->blk[blk].xlt2.vsig_tbl[i].in_use) 365271d10453SEric Joyner ice_vsig_free(hw, blk, i); 365371d10453SEric Joyner } 365471d10453SEric Joyner 365571d10453SEric Joyner /** 365671d10453SEric Joyner * ice_free_hw_tbls - free hardware table memory 365771d10453SEric Joyner * @hw: pointer to the hardware structure 365871d10453SEric Joyner */ 365971d10453SEric Joyner void ice_free_hw_tbls(struct ice_hw *hw) 366071d10453SEric Joyner { 366171d10453SEric Joyner struct ice_rss_cfg *r, *rt; 366271d10453SEric Joyner u8 i; 366371d10453SEric Joyner 366471d10453SEric Joyner for (i = 0; i < ICE_BLK_COUNT; i++) { 366571d10453SEric Joyner if (hw->blk[i].is_list_init) { 366671d10453SEric Joyner struct ice_es *es = &hw->blk[i].es; 366771d10453SEric Joyner 366871d10453SEric Joyner ice_free_prof_map(hw, i); 366971d10453SEric Joyner ice_destroy_lock(&es->prof_map_lock); 367071d10453SEric Joyner 367171d10453SEric Joyner ice_free_flow_profs(hw, i); 367271d10453SEric Joyner ice_destroy_lock(&hw->fl_profs_locks[i]); 367371d10453SEric Joyner 367471d10453SEric Joyner hw->blk[i].is_list_init = false; 367571d10453SEric Joyner } 367671d10453SEric Joyner ice_free_vsig_tbl(hw, (enum ice_block)i); 367771d10453SEric Joyner ice_free(hw, hw->blk[i].xlt1.ptypes); 367871d10453SEric Joyner ice_free(hw, hw->blk[i].xlt1.ptg_tbl); 367971d10453SEric Joyner ice_free(hw, hw->blk[i].xlt1.t); 368071d10453SEric Joyner ice_free(hw, hw->blk[i].xlt2.t); 368171d10453SEric Joyner ice_free(hw, hw->blk[i].xlt2.vsig_tbl); 368271d10453SEric Joyner ice_free(hw, hw->blk[i].xlt2.vsis); 368371d10453SEric Joyner ice_free(hw, hw->blk[i].prof.t); 368471d10453SEric Joyner ice_free(hw, hw->blk[i].prof_redir.t); 368571d10453SEric Joyner ice_free(hw, hw->blk[i].es.t); 368671d10453SEric Joyner ice_free(hw, hw->blk[i].es.ref_count); 368771d10453SEric Joyner ice_free(hw, hw->blk[i].es.written); 368871d10453SEric Joyner } 368971d10453SEric Joyner 369071d10453SEric Joyner LIST_FOR_EACH_ENTRY_SAFE(r, rt, &hw->rss_list_head, 369171d10453SEric Joyner ice_rss_cfg, l_entry) { 369271d10453SEric Joyner LIST_DEL(&r->l_entry); 369371d10453SEric Joyner ice_free(hw, r); 369471d10453SEric Joyner } 369571d10453SEric Joyner ice_destroy_lock(&hw->rss_locks); 369671d10453SEric Joyner ice_memset(hw->blk, 0, sizeof(hw->blk), ICE_NONDMA_MEM); 369771d10453SEric Joyner } 369871d10453SEric Joyner 369971d10453SEric Joyner /** 370071d10453SEric Joyner * ice_init_flow_profs - init flow profile locks and list heads 370171d10453SEric Joyner * @hw: pointer to the hardware structure 370271d10453SEric Joyner * @blk_idx: HW block index 370371d10453SEric Joyner */ 370471d10453SEric Joyner static void ice_init_flow_profs(struct ice_hw *hw, u8 blk_idx) 370571d10453SEric Joyner { 370671d10453SEric Joyner ice_init_lock(&hw->fl_profs_locks[blk_idx]); 370771d10453SEric Joyner INIT_LIST_HEAD(&hw->fl_profs[blk_idx]); 370871d10453SEric Joyner } 370971d10453SEric Joyner 371071d10453SEric Joyner /** 371171d10453SEric Joyner * ice_clear_hw_tbls - clear HW tables and flow profiles 371271d10453SEric Joyner * @hw: pointer to the hardware structure 371371d10453SEric Joyner */ 371471d10453SEric Joyner void ice_clear_hw_tbls(struct ice_hw *hw) 371571d10453SEric Joyner { 371671d10453SEric Joyner u8 i; 371771d10453SEric Joyner 371871d10453SEric Joyner for (i = 0; i < ICE_BLK_COUNT; i++) { 371971d10453SEric Joyner struct ice_prof_redir *prof_redir = &hw->blk[i].prof_redir; 372071d10453SEric Joyner struct ice_prof_tcam *prof = &hw->blk[i].prof; 372171d10453SEric Joyner struct ice_xlt1 *xlt1 = &hw->blk[i].xlt1; 372271d10453SEric Joyner struct ice_xlt2 *xlt2 = &hw->blk[i].xlt2; 372371d10453SEric Joyner struct ice_es *es = &hw->blk[i].es; 372471d10453SEric Joyner 372571d10453SEric Joyner if (hw->blk[i].is_list_init) { 372671d10453SEric Joyner ice_free_prof_map(hw, i); 372771d10453SEric Joyner ice_free_flow_profs(hw, i); 372871d10453SEric Joyner } 372971d10453SEric Joyner 373071d10453SEric Joyner ice_free_vsig_tbl(hw, (enum ice_block)i); 373171d10453SEric Joyner 373271d10453SEric Joyner ice_memset(xlt1->ptypes, 0, xlt1->count * sizeof(*xlt1->ptypes), 373371d10453SEric Joyner ICE_NONDMA_MEM); 373471d10453SEric Joyner ice_memset(xlt1->ptg_tbl, 0, 373571d10453SEric Joyner ICE_MAX_PTGS * sizeof(*xlt1->ptg_tbl), 373671d10453SEric Joyner ICE_NONDMA_MEM); 373771d10453SEric Joyner ice_memset(xlt1->t, 0, xlt1->count * sizeof(*xlt1->t), 373871d10453SEric Joyner ICE_NONDMA_MEM); 373971d10453SEric Joyner 374071d10453SEric Joyner ice_memset(xlt2->vsis, 0, xlt2->count * sizeof(*xlt2->vsis), 374171d10453SEric Joyner ICE_NONDMA_MEM); 374271d10453SEric Joyner ice_memset(xlt2->vsig_tbl, 0, 374371d10453SEric Joyner xlt2->count * sizeof(*xlt2->vsig_tbl), 374471d10453SEric Joyner ICE_NONDMA_MEM); 374571d10453SEric Joyner ice_memset(xlt2->t, 0, xlt2->count * sizeof(*xlt2->t), 374671d10453SEric Joyner ICE_NONDMA_MEM); 374771d10453SEric Joyner 374871d10453SEric Joyner ice_memset(prof->t, 0, prof->count * sizeof(*prof->t), 374971d10453SEric Joyner ICE_NONDMA_MEM); 375071d10453SEric Joyner ice_memset(prof_redir->t, 0, 375171d10453SEric Joyner prof_redir->count * sizeof(*prof_redir->t), 375271d10453SEric Joyner ICE_NONDMA_MEM); 375371d10453SEric Joyner 3754*7d7af7f8SEric Joyner ice_memset(es->t, 0, es->count * sizeof(*es->t) * es->fvw, 375571d10453SEric Joyner ICE_NONDMA_MEM); 375671d10453SEric Joyner ice_memset(es->ref_count, 0, es->count * sizeof(*es->ref_count), 375771d10453SEric Joyner ICE_NONDMA_MEM); 375871d10453SEric Joyner ice_memset(es->written, 0, es->count * sizeof(*es->written), 375971d10453SEric Joyner ICE_NONDMA_MEM); 376071d10453SEric Joyner } 376171d10453SEric Joyner } 376271d10453SEric Joyner 376371d10453SEric Joyner /** 376471d10453SEric Joyner * ice_init_hw_tbls - init hardware table memory 376571d10453SEric Joyner * @hw: pointer to the hardware structure 376671d10453SEric Joyner */ 376771d10453SEric Joyner enum ice_status ice_init_hw_tbls(struct ice_hw *hw) 376871d10453SEric Joyner { 376971d10453SEric Joyner u8 i; 377071d10453SEric Joyner 377171d10453SEric Joyner ice_init_lock(&hw->rss_locks); 377271d10453SEric Joyner INIT_LIST_HEAD(&hw->rss_list_head); 377371d10453SEric Joyner for (i = 0; i < ICE_BLK_COUNT; i++) { 377471d10453SEric Joyner struct ice_prof_redir *prof_redir = &hw->blk[i].prof_redir; 377571d10453SEric Joyner struct ice_prof_tcam *prof = &hw->blk[i].prof; 377671d10453SEric Joyner struct ice_xlt1 *xlt1 = &hw->blk[i].xlt1; 377771d10453SEric Joyner struct ice_xlt2 *xlt2 = &hw->blk[i].xlt2; 377871d10453SEric Joyner struct ice_es *es = &hw->blk[i].es; 377971d10453SEric Joyner u16 j; 378071d10453SEric Joyner 378171d10453SEric Joyner if (hw->blk[i].is_list_init) 378271d10453SEric Joyner continue; 378371d10453SEric Joyner 378471d10453SEric Joyner ice_init_flow_profs(hw, i); 378571d10453SEric Joyner ice_init_lock(&es->prof_map_lock); 378671d10453SEric Joyner INIT_LIST_HEAD(&es->prof_map); 378771d10453SEric Joyner hw->blk[i].is_list_init = true; 378871d10453SEric Joyner 378971d10453SEric Joyner hw->blk[i].overwrite = blk_sizes[i].overwrite; 379071d10453SEric Joyner es->reverse = blk_sizes[i].reverse; 379171d10453SEric Joyner 379271d10453SEric Joyner xlt1->sid = ice_blk_sids[i][ICE_SID_XLT1_OFF]; 379371d10453SEric Joyner xlt1->count = blk_sizes[i].xlt1; 379471d10453SEric Joyner 379571d10453SEric Joyner xlt1->ptypes = (struct ice_ptg_ptype *) 379671d10453SEric Joyner ice_calloc(hw, xlt1->count, sizeof(*xlt1->ptypes)); 379771d10453SEric Joyner 379871d10453SEric Joyner if (!xlt1->ptypes) 379971d10453SEric Joyner goto err; 380071d10453SEric Joyner 380171d10453SEric Joyner xlt1->ptg_tbl = (struct ice_ptg_entry *) 380271d10453SEric Joyner ice_calloc(hw, ICE_MAX_PTGS, sizeof(*xlt1->ptg_tbl)); 380371d10453SEric Joyner 380471d10453SEric Joyner if (!xlt1->ptg_tbl) 380571d10453SEric Joyner goto err; 380671d10453SEric Joyner 380771d10453SEric Joyner xlt1->t = (u8 *)ice_calloc(hw, xlt1->count, sizeof(*xlt1->t)); 380871d10453SEric Joyner if (!xlt1->t) 380971d10453SEric Joyner goto err; 381071d10453SEric Joyner 381171d10453SEric Joyner xlt2->sid = ice_blk_sids[i][ICE_SID_XLT2_OFF]; 381271d10453SEric Joyner xlt2->count = blk_sizes[i].xlt2; 381371d10453SEric Joyner 381471d10453SEric Joyner xlt2->vsis = (struct ice_vsig_vsi *) 381571d10453SEric Joyner ice_calloc(hw, xlt2->count, sizeof(*xlt2->vsis)); 381671d10453SEric Joyner 381771d10453SEric Joyner if (!xlt2->vsis) 381871d10453SEric Joyner goto err; 381971d10453SEric Joyner 382071d10453SEric Joyner xlt2->vsig_tbl = (struct ice_vsig_entry *) 382171d10453SEric Joyner ice_calloc(hw, xlt2->count, sizeof(*xlt2->vsig_tbl)); 382271d10453SEric Joyner if (!xlt2->vsig_tbl) 382371d10453SEric Joyner goto err; 382471d10453SEric Joyner 382571d10453SEric Joyner for (j = 0; j < xlt2->count; j++) 382671d10453SEric Joyner INIT_LIST_HEAD(&xlt2->vsig_tbl[j].prop_lst); 382771d10453SEric Joyner 382871d10453SEric Joyner xlt2->t = (u16 *)ice_calloc(hw, xlt2->count, sizeof(*xlt2->t)); 382971d10453SEric Joyner if (!xlt2->t) 383071d10453SEric Joyner goto err; 383171d10453SEric Joyner 383271d10453SEric Joyner prof->sid = ice_blk_sids[i][ICE_SID_PR_OFF]; 383371d10453SEric Joyner prof->count = blk_sizes[i].prof_tcam; 383471d10453SEric Joyner prof->max_prof_id = blk_sizes[i].prof_id; 383571d10453SEric Joyner prof->cdid_bits = blk_sizes[i].prof_cdid_bits; 383671d10453SEric Joyner prof->t = (struct ice_prof_tcam_entry *) 383771d10453SEric Joyner ice_calloc(hw, prof->count, sizeof(*prof->t)); 383871d10453SEric Joyner 383971d10453SEric Joyner if (!prof->t) 384071d10453SEric Joyner goto err; 384171d10453SEric Joyner 384271d10453SEric Joyner prof_redir->sid = ice_blk_sids[i][ICE_SID_PR_REDIR_OFF]; 384371d10453SEric Joyner prof_redir->count = blk_sizes[i].prof_redir; 384471d10453SEric Joyner prof_redir->t = (u8 *)ice_calloc(hw, prof_redir->count, 384571d10453SEric Joyner sizeof(*prof_redir->t)); 384671d10453SEric Joyner 384771d10453SEric Joyner if (!prof_redir->t) 384871d10453SEric Joyner goto err; 384971d10453SEric Joyner 385071d10453SEric Joyner es->sid = ice_blk_sids[i][ICE_SID_ES_OFF]; 385171d10453SEric Joyner es->count = blk_sizes[i].es; 385271d10453SEric Joyner es->fvw = blk_sizes[i].fvw; 385371d10453SEric Joyner es->t = (struct ice_fv_word *) 385471d10453SEric Joyner ice_calloc(hw, (u32)(es->count * es->fvw), 385571d10453SEric Joyner sizeof(*es->t)); 385671d10453SEric Joyner if (!es->t) 385771d10453SEric Joyner goto err; 385871d10453SEric Joyner 385971d10453SEric Joyner es->ref_count = (u16 *) 386071d10453SEric Joyner ice_calloc(hw, es->count, sizeof(*es->ref_count)); 386171d10453SEric Joyner 386271d10453SEric Joyner if (!es->ref_count) 386371d10453SEric Joyner goto err; 3864*7d7af7f8SEric Joyner 3865*7d7af7f8SEric Joyner es->written = (u8 *) 3866*7d7af7f8SEric Joyner ice_calloc(hw, es->count, sizeof(*es->written)); 3867*7d7af7f8SEric Joyner 3868*7d7af7f8SEric Joyner if (!es->written) 3869*7d7af7f8SEric Joyner goto err; 3870*7d7af7f8SEric Joyner 387171d10453SEric Joyner } 387271d10453SEric Joyner return ICE_SUCCESS; 387371d10453SEric Joyner 387471d10453SEric Joyner err: 387571d10453SEric Joyner ice_free_hw_tbls(hw); 387671d10453SEric Joyner return ICE_ERR_NO_MEMORY; 387771d10453SEric Joyner } 387871d10453SEric Joyner 387971d10453SEric Joyner /** 388071d10453SEric Joyner * ice_prof_gen_key - generate profile ID key 388171d10453SEric Joyner * @hw: pointer to the HW struct 388271d10453SEric Joyner * @blk: the block in which to write profile ID to 388371d10453SEric Joyner * @ptg: packet type group (PTG) portion of key 388471d10453SEric Joyner * @vsig: VSIG portion of key 388571d10453SEric Joyner * @cdid: CDID portion of key 388671d10453SEric Joyner * @flags: flag portion of key 388771d10453SEric Joyner * @vl_msk: valid mask 388871d10453SEric Joyner * @dc_msk: don't care mask 388971d10453SEric Joyner * @nm_msk: never match mask 389071d10453SEric Joyner * @key: output of profile ID key 389171d10453SEric Joyner */ 389271d10453SEric Joyner static enum ice_status 389371d10453SEric Joyner ice_prof_gen_key(struct ice_hw *hw, enum ice_block blk, u8 ptg, u16 vsig, 389471d10453SEric Joyner u8 cdid, u16 flags, u8 vl_msk[ICE_TCAM_KEY_VAL_SZ], 389571d10453SEric Joyner u8 dc_msk[ICE_TCAM_KEY_VAL_SZ], u8 nm_msk[ICE_TCAM_KEY_VAL_SZ], 389671d10453SEric Joyner u8 key[ICE_TCAM_KEY_SZ]) 389771d10453SEric Joyner { 389871d10453SEric Joyner struct ice_prof_id_key inkey; 389971d10453SEric Joyner 390071d10453SEric Joyner inkey.xlt1 = ptg; 390171d10453SEric Joyner inkey.xlt2_cdid = CPU_TO_LE16(vsig); 390271d10453SEric Joyner inkey.flags = CPU_TO_LE16(flags); 390371d10453SEric Joyner 390471d10453SEric Joyner switch (hw->blk[blk].prof.cdid_bits) { 390571d10453SEric Joyner case 0: 390671d10453SEric Joyner break; 390771d10453SEric Joyner case 2: 390871d10453SEric Joyner #define ICE_CD_2_M 0xC000U 390971d10453SEric Joyner #define ICE_CD_2_S 14 391071d10453SEric Joyner inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_2_M); 391171d10453SEric Joyner inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_2_S); 391271d10453SEric Joyner break; 391371d10453SEric Joyner case 4: 391471d10453SEric Joyner #define ICE_CD_4_M 0xF000U 391571d10453SEric Joyner #define ICE_CD_4_S 12 391671d10453SEric Joyner inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_4_M); 391771d10453SEric Joyner inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_4_S); 391871d10453SEric Joyner break; 391971d10453SEric Joyner case 8: 392071d10453SEric Joyner #define ICE_CD_8_M 0xFF00U 392171d10453SEric Joyner #define ICE_CD_8_S 16 392271d10453SEric Joyner inkey.xlt2_cdid &= ~CPU_TO_LE16(ICE_CD_8_M); 392371d10453SEric Joyner inkey.xlt2_cdid |= CPU_TO_LE16(BIT(cdid) << ICE_CD_8_S); 392471d10453SEric Joyner break; 392571d10453SEric Joyner default: 392671d10453SEric Joyner ice_debug(hw, ICE_DBG_PKG, "Error in profile config\n"); 392771d10453SEric Joyner break; 392871d10453SEric Joyner } 392971d10453SEric Joyner 393071d10453SEric Joyner return ice_set_key(key, ICE_TCAM_KEY_SZ, (u8 *)&inkey, vl_msk, dc_msk, 393171d10453SEric Joyner nm_msk, 0, ICE_TCAM_KEY_SZ / 2); 393271d10453SEric Joyner } 393371d10453SEric Joyner 393471d10453SEric Joyner /** 393571d10453SEric Joyner * ice_tcam_write_entry - write TCAM entry 393671d10453SEric Joyner * @hw: pointer to the HW struct 393771d10453SEric Joyner * @blk: the block in which to write profile ID to 393871d10453SEric Joyner * @idx: the entry index to write to 393971d10453SEric Joyner * @prof_id: profile ID 394071d10453SEric Joyner * @ptg: packet type group (PTG) portion of key 394171d10453SEric Joyner * @vsig: VSIG portion of key 3942*7d7af7f8SEric Joyner * @cdid: CDID portion of key 394371d10453SEric Joyner * @flags: flag portion of key 394471d10453SEric Joyner * @vl_msk: valid mask 394571d10453SEric Joyner * @dc_msk: don't care mask 394671d10453SEric Joyner * @nm_msk: never match mask 394771d10453SEric Joyner */ 394871d10453SEric Joyner static enum ice_status 394971d10453SEric Joyner ice_tcam_write_entry(struct ice_hw *hw, enum ice_block blk, u16 idx, 395071d10453SEric Joyner u8 prof_id, u8 ptg, u16 vsig, u8 cdid, u16 flags, 395171d10453SEric Joyner u8 vl_msk[ICE_TCAM_KEY_VAL_SZ], 395271d10453SEric Joyner u8 dc_msk[ICE_TCAM_KEY_VAL_SZ], 395371d10453SEric Joyner u8 nm_msk[ICE_TCAM_KEY_VAL_SZ]) 395471d10453SEric Joyner { 395571d10453SEric Joyner struct ice_prof_tcam_entry; 395671d10453SEric Joyner enum ice_status status; 395771d10453SEric Joyner 395871d10453SEric Joyner status = ice_prof_gen_key(hw, blk, ptg, vsig, cdid, flags, vl_msk, 395971d10453SEric Joyner dc_msk, nm_msk, hw->blk[blk].prof.t[idx].key); 396071d10453SEric Joyner if (!status) { 396171d10453SEric Joyner hw->blk[blk].prof.t[idx].addr = CPU_TO_LE16(idx); 396271d10453SEric Joyner hw->blk[blk].prof.t[idx].prof_id = prof_id; 396371d10453SEric Joyner } 396471d10453SEric Joyner 396571d10453SEric Joyner return status; 396671d10453SEric Joyner } 396771d10453SEric Joyner 396871d10453SEric Joyner /** 396971d10453SEric Joyner * ice_vsig_get_ref - returns number of VSIs belong to a VSIG 397071d10453SEric Joyner * @hw: pointer to the hardware structure 397171d10453SEric Joyner * @blk: HW block 397271d10453SEric Joyner * @vsig: VSIG to query 397371d10453SEric Joyner * @refs: pointer to variable to receive the reference count 397471d10453SEric Joyner */ 397571d10453SEric Joyner static enum ice_status 397671d10453SEric Joyner ice_vsig_get_ref(struct ice_hw *hw, enum ice_block blk, u16 vsig, u16 *refs) 397771d10453SEric Joyner { 397871d10453SEric Joyner u16 idx = vsig & ICE_VSIG_IDX_M; 397971d10453SEric Joyner struct ice_vsig_vsi *ptr; 398071d10453SEric Joyner 398171d10453SEric Joyner *refs = 0; 398271d10453SEric Joyner 398371d10453SEric Joyner if (!hw->blk[blk].xlt2.vsig_tbl[idx].in_use) 398471d10453SEric Joyner return ICE_ERR_DOES_NOT_EXIST; 398571d10453SEric Joyner 398671d10453SEric Joyner ptr = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi; 398771d10453SEric Joyner while (ptr) { 398871d10453SEric Joyner (*refs)++; 398971d10453SEric Joyner ptr = ptr->next_vsi; 399071d10453SEric Joyner } 399171d10453SEric Joyner 399271d10453SEric Joyner return ICE_SUCCESS; 399371d10453SEric Joyner } 399471d10453SEric Joyner 399571d10453SEric Joyner /** 399671d10453SEric Joyner * ice_has_prof_vsig - check to see if VSIG has a specific profile 399771d10453SEric Joyner * @hw: pointer to the hardware structure 399871d10453SEric Joyner * @blk: HW block 399971d10453SEric Joyner * @vsig: VSIG to check against 400071d10453SEric Joyner * @hdl: profile handle 400171d10453SEric Joyner */ 400271d10453SEric Joyner static bool 400371d10453SEric Joyner ice_has_prof_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl) 400471d10453SEric Joyner { 400571d10453SEric Joyner u16 idx = vsig & ICE_VSIG_IDX_M; 400671d10453SEric Joyner struct ice_vsig_prof *ent; 400771d10453SEric Joyner 400871d10453SEric Joyner LIST_FOR_EACH_ENTRY(ent, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst, 4009*7d7af7f8SEric Joyner ice_vsig_prof, list) 401071d10453SEric Joyner if (ent->profile_cookie == hdl) 401171d10453SEric Joyner return true; 401271d10453SEric Joyner 4013*7d7af7f8SEric Joyner ice_debug(hw, ICE_DBG_INIT, "Characteristic list for VSI group %d not found.\n", 401471d10453SEric Joyner vsig); 401571d10453SEric Joyner return false; 401671d10453SEric Joyner } 401771d10453SEric Joyner 401871d10453SEric Joyner /** 401971d10453SEric Joyner * ice_prof_bld_es - build profile ID extraction sequence changes 402071d10453SEric Joyner * @hw: pointer to the HW struct 402171d10453SEric Joyner * @blk: hardware block 402271d10453SEric Joyner * @bld: the update package buffer build to add to 402371d10453SEric Joyner * @chgs: the list of changes to make in hardware 402471d10453SEric Joyner */ 402571d10453SEric Joyner static enum ice_status 402671d10453SEric Joyner ice_prof_bld_es(struct ice_hw *hw, enum ice_block blk, 402771d10453SEric Joyner struct ice_buf_build *bld, struct LIST_HEAD_TYPE *chgs) 402871d10453SEric Joyner { 402971d10453SEric Joyner u16 vec_size = hw->blk[blk].es.fvw * sizeof(struct ice_fv_word); 403071d10453SEric Joyner struct ice_chs_chg *tmp; 403171d10453SEric Joyner 4032*7d7af7f8SEric Joyner LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) 403371d10453SEric Joyner if (tmp->type == ICE_PTG_ES_ADD && tmp->add_prof) { 403471d10453SEric Joyner u16 off = tmp->prof_id * hw->blk[blk].es.fvw; 403571d10453SEric Joyner struct ice_pkg_es *p; 403671d10453SEric Joyner u32 id; 403771d10453SEric Joyner 403871d10453SEric Joyner id = ice_sect_id(blk, ICE_VEC_TBL); 403971d10453SEric Joyner p = (struct ice_pkg_es *) 4040*7d7af7f8SEric Joyner ice_pkg_buf_alloc_section(bld, id, 4041*7d7af7f8SEric Joyner ice_struct_size(p, es, 4042*7d7af7f8SEric Joyner 1) + 404371d10453SEric Joyner vec_size - 404471d10453SEric Joyner sizeof(p->es[0])); 404571d10453SEric Joyner 404671d10453SEric Joyner if (!p) 404771d10453SEric Joyner return ICE_ERR_MAX_LIMIT; 404871d10453SEric Joyner 404971d10453SEric Joyner p->count = CPU_TO_LE16(1); 405071d10453SEric Joyner p->offset = CPU_TO_LE16(tmp->prof_id); 405171d10453SEric Joyner 405271d10453SEric Joyner ice_memcpy(p->es, &hw->blk[blk].es.t[off], vec_size, 405371d10453SEric Joyner ICE_NONDMA_TO_NONDMA); 405471d10453SEric Joyner } 405571d10453SEric Joyner 405671d10453SEric Joyner return ICE_SUCCESS; 405771d10453SEric Joyner } 405871d10453SEric Joyner 405971d10453SEric Joyner /** 406071d10453SEric Joyner * ice_prof_bld_tcam - build profile ID TCAM changes 406171d10453SEric Joyner * @hw: pointer to the HW struct 406271d10453SEric Joyner * @blk: hardware block 406371d10453SEric Joyner * @bld: the update package buffer build to add to 406471d10453SEric Joyner * @chgs: the list of changes to make in hardware 406571d10453SEric Joyner */ 406671d10453SEric Joyner static enum ice_status 406771d10453SEric Joyner ice_prof_bld_tcam(struct ice_hw *hw, enum ice_block blk, 406871d10453SEric Joyner struct ice_buf_build *bld, struct LIST_HEAD_TYPE *chgs) 406971d10453SEric Joyner { 407071d10453SEric Joyner struct ice_chs_chg *tmp; 407171d10453SEric Joyner 4072*7d7af7f8SEric Joyner LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) 407371d10453SEric Joyner if (tmp->type == ICE_TCAM_ADD && tmp->add_tcam_idx) { 407471d10453SEric Joyner struct ice_prof_id_section *p; 407571d10453SEric Joyner u32 id; 407671d10453SEric Joyner 407771d10453SEric Joyner id = ice_sect_id(blk, ICE_PROF_TCAM); 407871d10453SEric Joyner p = (struct ice_prof_id_section *) 4079*7d7af7f8SEric Joyner ice_pkg_buf_alloc_section(bld, id, 4080*7d7af7f8SEric Joyner ice_struct_size(p, 4081*7d7af7f8SEric Joyner entry, 4082*7d7af7f8SEric Joyner 1)); 408371d10453SEric Joyner 408471d10453SEric Joyner if (!p) 408571d10453SEric Joyner return ICE_ERR_MAX_LIMIT; 408671d10453SEric Joyner 408771d10453SEric Joyner p->count = CPU_TO_LE16(1); 408871d10453SEric Joyner p->entry[0].addr = CPU_TO_LE16(tmp->tcam_idx); 408971d10453SEric Joyner p->entry[0].prof_id = tmp->prof_id; 409071d10453SEric Joyner 409171d10453SEric Joyner ice_memcpy(p->entry[0].key, 409271d10453SEric Joyner &hw->blk[blk].prof.t[tmp->tcam_idx].key, 409371d10453SEric Joyner sizeof(hw->blk[blk].prof.t->key), 409471d10453SEric Joyner ICE_NONDMA_TO_NONDMA); 409571d10453SEric Joyner } 409671d10453SEric Joyner 409771d10453SEric Joyner return ICE_SUCCESS; 409871d10453SEric Joyner } 409971d10453SEric Joyner 410071d10453SEric Joyner /** 410171d10453SEric Joyner * ice_prof_bld_xlt1 - build XLT1 changes 410271d10453SEric Joyner * @blk: hardware block 410371d10453SEric Joyner * @bld: the update package buffer build to add to 410471d10453SEric Joyner * @chgs: the list of changes to make in hardware 410571d10453SEric Joyner */ 410671d10453SEric Joyner static enum ice_status 410771d10453SEric Joyner ice_prof_bld_xlt1(enum ice_block blk, struct ice_buf_build *bld, 410871d10453SEric Joyner struct LIST_HEAD_TYPE *chgs) 410971d10453SEric Joyner { 411071d10453SEric Joyner struct ice_chs_chg *tmp; 411171d10453SEric Joyner 4112*7d7af7f8SEric Joyner LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) 411371d10453SEric Joyner if (tmp->type == ICE_PTG_ES_ADD && tmp->add_ptg) { 411471d10453SEric Joyner struct ice_xlt1_section *p; 411571d10453SEric Joyner u32 id; 411671d10453SEric Joyner 411771d10453SEric Joyner id = ice_sect_id(blk, ICE_XLT1); 411871d10453SEric Joyner p = (struct ice_xlt1_section *) 4119*7d7af7f8SEric Joyner ice_pkg_buf_alloc_section(bld, id, 4120*7d7af7f8SEric Joyner ice_struct_size(p, 4121*7d7af7f8SEric Joyner value, 4122*7d7af7f8SEric Joyner 1)); 412371d10453SEric Joyner 412471d10453SEric Joyner if (!p) 412571d10453SEric Joyner return ICE_ERR_MAX_LIMIT; 412671d10453SEric Joyner 412771d10453SEric Joyner p->count = CPU_TO_LE16(1); 412871d10453SEric Joyner p->offset = CPU_TO_LE16(tmp->ptype); 412971d10453SEric Joyner p->value[0] = tmp->ptg; 413071d10453SEric Joyner } 413171d10453SEric Joyner 413271d10453SEric Joyner return ICE_SUCCESS; 413371d10453SEric Joyner } 413471d10453SEric Joyner 413571d10453SEric Joyner /** 413671d10453SEric Joyner * ice_prof_bld_xlt2 - build XLT2 changes 413771d10453SEric Joyner * @blk: hardware block 413871d10453SEric Joyner * @bld: the update package buffer build to add to 413971d10453SEric Joyner * @chgs: the list of changes to make in hardware 414071d10453SEric Joyner */ 414171d10453SEric Joyner static enum ice_status 414271d10453SEric Joyner ice_prof_bld_xlt2(enum ice_block blk, struct ice_buf_build *bld, 414371d10453SEric Joyner struct LIST_HEAD_TYPE *chgs) 414471d10453SEric Joyner { 414571d10453SEric Joyner struct ice_chs_chg *tmp; 414671d10453SEric Joyner 414771d10453SEric Joyner LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) { 414871d10453SEric Joyner struct ice_xlt2_section *p; 414971d10453SEric Joyner u32 id; 415071d10453SEric Joyner 415171d10453SEric Joyner switch (tmp->type) { 415271d10453SEric Joyner case ICE_VSIG_ADD: 415371d10453SEric Joyner case ICE_VSI_MOVE: 415471d10453SEric Joyner case ICE_VSIG_REM: 415571d10453SEric Joyner id = ice_sect_id(blk, ICE_XLT2); 415671d10453SEric Joyner p = (struct ice_xlt2_section *) 4157*7d7af7f8SEric Joyner ice_pkg_buf_alloc_section(bld, id, 4158*7d7af7f8SEric Joyner ice_struct_size(p, 4159*7d7af7f8SEric Joyner value, 4160*7d7af7f8SEric Joyner 1)); 416171d10453SEric Joyner 416271d10453SEric Joyner if (!p) 416371d10453SEric Joyner return ICE_ERR_MAX_LIMIT; 416471d10453SEric Joyner 416571d10453SEric Joyner p->count = CPU_TO_LE16(1); 416671d10453SEric Joyner p->offset = CPU_TO_LE16(tmp->vsi); 416771d10453SEric Joyner p->value[0] = CPU_TO_LE16(tmp->vsig); 416871d10453SEric Joyner break; 416971d10453SEric Joyner default: 417071d10453SEric Joyner break; 417171d10453SEric Joyner } 417271d10453SEric Joyner } 417371d10453SEric Joyner 417471d10453SEric Joyner return ICE_SUCCESS; 417571d10453SEric Joyner } 417671d10453SEric Joyner 417771d10453SEric Joyner /** 417871d10453SEric Joyner * ice_upd_prof_hw - update hardware using the change list 417971d10453SEric Joyner * @hw: pointer to the HW struct 418071d10453SEric Joyner * @blk: hardware block 418171d10453SEric Joyner * @chgs: the list of changes to make in hardware 418271d10453SEric Joyner */ 418371d10453SEric Joyner static enum ice_status 418471d10453SEric Joyner ice_upd_prof_hw(struct ice_hw *hw, enum ice_block blk, 418571d10453SEric Joyner struct LIST_HEAD_TYPE *chgs) 418671d10453SEric Joyner { 418771d10453SEric Joyner struct ice_buf_build *b; 418871d10453SEric Joyner struct ice_chs_chg *tmp; 418971d10453SEric Joyner enum ice_status status; 419071d10453SEric Joyner u16 pkg_sects; 419171d10453SEric Joyner u16 xlt1 = 0; 419271d10453SEric Joyner u16 xlt2 = 0; 419371d10453SEric Joyner u16 tcam = 0; 419471d10453SEric Joyner u16 es = 0; 419571d10453SEric Joyner u16 sects; 419671d10453SEric Joyner 419771d10453SEric Joyner /* count number of sections we need */ 419871d10453SEric Joyner LIST_FOR_EACH_ENTRY(tmp, chgs, ice_chs_chg, list_entry) { 419971d10453SEric Joyner switch (tmp->type) { 420071d10453SEric Joyner case ICE_PTG_ES_ADD: 420171d10453SEric Joyner if (tmp->add_ptg) 420271d10453SEric Joyner xlt1++; 420371d10453SEric Joyner if (tmp->add_prof) 420471d10453SEric Joyner es++; 420571d10453SEric Joyner break; 420671d10453SEric Joyner case ICE_TCAM_ADD: 420771d10453SEric Joyner tcam++; 420871d10453SEric Joyner break; 420971d10453SEric Joyner case ICE_VSIG_ADD: 421071d10453SEric Joyner case ICE_VSI_MOVE: 421171d10453SEric Joyner case ICE_VSIG_REM: 421271d10453SEric Joyner xlt2++; 421371d10453SEric Joyner break; 421471d10453SEric Joyner default: 421571d10453SEric Joyner break; 421671d10453SEric Joyner } 421771d10453SEric Joyner } 421871d10453SEric Joyner sects = xlt1 + xlt2 + tcam + es; 421971d10453SEric Joyner 422071d10453SEric Joyner if (!sects) 422171d10453SEric Joyner return ICE_SUCCESS; 422271d10453SEric Joyner 422371d10453SEric Joyner /* Build update package buffer */ 422471d10453SEric Joyner b = ice_pkg_buf_alloc(hw); 422571d10453SEric Joyner if (!b) 422671d10453SEric Joyner return ICE_ERR_NO_MEMORY; 422771d10453SEric Joyner 422871d10453SEric Joyner status = ice_pkg_buf_reserve_section(b, sects); 422971d10453SEric Joyner if (status) 423071d10453SEric Joyner goto error_tmp; 423171d10453SEric Joyner 423271d10453SEric Joyner /* Preserve order of table update: ES, TCAM, PTG, VSIG */ 423371d10453SEric Joyner if (es) { 423471d10453SEric Joyner status = ice_prof_bld_es(hw, blk, b, chgs); 423571d10453SEric Joyner if (status) 423671d10453SEric Joyner goto error_tmp; 423771d10453SEric Joyner } 423871d10453SEric Joyner 423971d10453SEric Joyner if (tcam) { 424071d10453SEric Joyner status = ice_prof_bld_tcam(hw, blk, b, chgs); 424171d10453SEric Joyner if (status) 424271d10453SEric Joyner goto error_tmp; 424371d10453SEric Joyner } 424471d10453SEric Joyner 424571d10453SEric Joyner if (xlt1) { 424671d10453SEric Joyner status = ice_prof_bld_xlt1(blk, b, chgs); 424771d10453SEric Joyner if (status) 424871d10453SEric Joyner goto error_tmp; 424971d10453SEric Joyner } 425071d10453SEric Joyner 425171d10453SEric Joyner if (xlt2) { 425271d10453SEric Joyner status = ice_prof_bld_xlt2(blk, b, chgs); 425371d10453SEric Joyner if (status) 425471d10453SEric Joyner goto error_tmp; 425571d10453SEric Joyner } 425671d10453SEric Joyner 425771d10453SEric Joyner /* After package buffer build check if the section count in buffer is 425871d10453SEric Joyner * non-zero and matches the number of sections detected for package 425971d10453SEric Joyner * update. 426071d10453SEric Joyner */ 426171d10453SEric Joyner pkg_sects = ice_pkg_buf_get_active_sections(b); 426271d10453SEric Joyner if (!pkg_sects || pkg_sects != sects) { 426371d10453SEric Joyner status = ICE_ERR_INVAL_SIZE; 426471d10453SEric Joyner goto error_tmp; 426571d10453SEric Joyner } 426671d10453SEric Joyner 426771d10453SEric Joyner /* update package */ 426871d10453SEric Joyner status = ice_update_pkg(hw, ice_pkg_buf(b), 1); 426971d10453SEric Joyner if (status == ICE_ERR_AQ_ERROR) 427071d10453SEric Joyner ice_debug(hw, ICE_DBG_INIT, "Unable to update HW profile\n"); 427171d10453SEric Joyner 427271d10453SEric Joyner error_tmp: 427371d10453SEric Joyner ice_pkg_buf_free(hw, b); 427471d10453SEric Joyner return status; 427571d10453SEric Joyner } 427671d10453SEric Joyner 427771d10453SEric Joyner /** 427871d10453SEric Joyner * ice_add_prof - add profile 427971d10453SEric Joyner * @hw: pointer to the HW struct 428071d10453SEric Joyner * @blk: hardware block 428171d10453SEric Joyner * @id: profile tracking ID 428271d10453SEric Joyner * @ptypes: array of bitmaps indicating ptypes (ICE_FLOW_PTYPE_MAX bits) 428371d10453SEric Joyner * @es: extraction sequence (length of array is determined by the block) 428471d10453SEric Joyner * 428571d10453SEric Joyner * This function registers a profile, which matches a set of PTGs with a 428671d10453SEric Joyner * particular extraction sequence. While the hardware profile is allocated 428771d10453SEric Joyner * it will not be written until the first call to ice_add_flow that specifies 428871d10453SEric Joyner * the ID value used here. 428971d10453SEric Joyner */ 429071d10453SEric Joyner enum ice_status 429171d10453SEric Joyner ice_add_prof(struct ice_hw *hw, enum ice_block blk, u64 id, u8 ptypes[], 429271d10453SEric Joyner struct ice_fv_word *es) 429371d10453SEric Joyner { 429471d10453SEric Joyner u32 bytes = DIVIDE_AND_ROUND_UP(ICE_FLOW_PTYPE_MAX, BITS_PER_BYTE); 429571d10453SEric Joyner ice_declare_bitmap(ptgs_used, ICE_XLT1_CNT); 429671d10453SEric Joyner struct ice_prof_map *prof; 429771d10453SEric Joyner enum ice_status status; 429871d10453SEric Joyner u8 byte = 0; 429971d10453SEric Joyner u8 prof_id; 430071d10453SEric Joyner 430171d10453SEric Joyner ice_zero_bitmap(ptgs_used, ICE_XLT1_CNT); 430271d10453SEric Joyner 430371d10453SEric Joyner ice_acquire_lock(&hw->blk[blk].es.prof_map_lock); 430471d10453SEric Joyner 430571d10453SEric Joyner /* search for existing profile */ 430671d10453SEric Joyner status = ice_find_prof_id(hw, blk, es, &prof_id); 430771d10453SEric Joyner if (status) { 430871d10453SEric Joyner /* allocate profile ID */ 430971d10453SEric Joyner status = ice_alloc_prof_id(hw, blk, &prof_id); 431071d10453SEric Joyner if (status) 431171d10453SEric Joyner goto err_ice_add_prof; 431271d10453SEric Joyner 431371d10453SEric Joyner /* and write new es */ 431471d10453SEric Joyner ice_write_es(hw, blk, prof_id, es); 431571d10453SEric Joyner } 431671d10453SEric Joyner 431771d10453SEric Joyner ice_prof_inc_ref(hw, blk, prof_id); 431871d10453SEric Joyner 431971d10453SEric Joyner /* add profile info */ 432071d10453SEric Joyner 432171d10453SEric Joyner prof = (struct ice_prof_map *)ice_malloc(hw, sizeof(*prof)); 432271d10453SEric Joyner if (!prof) 432371d10453SEric Joyner goto err_ice_add_prof; 432471d10453SEric Joyner 432571d10453SEric Joyner prof->profile_cookie = id; 432671d10453SEric Joyner prof->prof_id = prof_id; 432771d10453SEric Joyner prof->ptg_cnt = 0; 432871d10453SEric Joyner prof->context = 0; 432971d10453SEric Joyner 433071d10453SEric Joyner /* build list of ptgs */ 433171d10453SEric Joyner while (bytes && prof->ptg_cnt < ICE_MAX_PTG_PER_PROFILE) { 433271d10453SEric Joyner u8 bit; 433371d10453SEric Joyner 433471d10453SEric Joyner if (!ptypes[byte]) { 433571d10453SEric Joyner bytes--; 433671d10453SEric Joyner byte++; 433771d10453SEric Joyner continue; 433871d10453SEric Joyner } 4339*7d7af7f8SEric Joyner 434071d10453SEric Joyner /* Examine 8 bits per byte */ 4341*7d7af7f8SEric Joyner ice_for_each_set_bit(bit, (ice_bitmap_t *)&ptypes[byte], 4342*7d7af7f8SEric Joyner BITS_PER_BYTE) { 434371d10453SEric Joyner u16 ptype; 434471d10453SEric Joyner u8 ptg; 434571d10453SEric Joyner 434671d10453SEric Joyner ptype = byte * BITS_PER_BYTE + bit; 434771d10453SEric Joyner 4348*7d7af7f8SEric Joyner /* The package should place all ptypes in a non-zero 4349*7d7af7f8SEric Joyner * PTG, so the following call should never fail. 435071d10453SEric Joyner */ 435171d10453SEric Joyner if (ice_ptg_find_ptype(hw, blk, ptype, &ptg)) 435271d10453SEric Joyner continue; 435371d10453SEric Joyner 435471d10453SEric Joyner /* If PTG is already added, skip and continue */ 435571d10453SEric Joyner if (ice_is_bit_set(ptgs_used, ptg)) 435671d10453SEric Joyner continue; 435771d10453SEric Joyner 435871d10453SEric Joyner ice_set_bit(ptg, ptgs_used); 435971d10453SEric Joyner prof->ptg[prof->ptg_cnt] = ptg; 436071d10453SEric Joyner 436171d10453SEric Joyner if (++prof->ptg_cnt >= ICE_MAX_PTG_PER_PROFILE) 436271d10453SEric Joyner break; 436371d10453SEric Joyner } 436471d10453SEric Joyner 436571d10453SEric Joyner bytes--; 436671d10453SEric Joyner byte++; 436771d10453SEric Joyner } 436871d10453SEric Joyner 436971d10453SEric Joyner LIST_ADD(&prof->list, &hw->blk[blk].es.prof_map); 437071d10453SEric Joyner status = ICE_SUCCESS; 437171d10453SEric Joyner 437271d10453SEric Joyner err_ice_add_prof: 437371d10453SEric Joyner ice_release_lock(&hw->blk[blk].es.prof_map_lock); 437471d10453SEric Joyner return status; 437571d10453SEric Joyner } 437671d10453SEric Joyner 437771d10453SEric Joyner /** 437871d10453SEric Joyner * ice_search_prof_id - Search for a profile tracking ID 437971d10453SEric Joyner * @hw: pointer to the HW struct 438071d10453SEric Joyner * @blk: hardware block 438171d10453SEric Joyner * @id: profile tracking ID 438271d10453SEric Joyner * 438371d10453SEric Joyner * This will search for a profile tracking ID which was previously added. 4384*7d7af7f8SEric Joyner * The profile map lock should be held before calling this function. 438571d10453SEric Joyner */ 438671d10453SEric Joyner struct ice_prof_map * 438771d10453SEric Joyner ice_search_prof_id(struct ice_hw *hw, enum ice_block blk, u64 id) 438871d10453SEric Joyner { 4389*7d7af7f8SEric Joyner struct ice_prof_map *entry = NULL; 4390*7d7af7f8SEric Joyner struct ice_prof_map *map; 439171d10453SEric Joyner 4392*7d7af7f8SEric Joyner LIST_FOR_EACH_ENTRY(map, &hw->blk[blk].es.prof_map, ice_prof_map, list) 4393*7d7af7f8SEric Joyner if (map->profile_cookie == id) { 4394*7d7af7f8SEric Joyner entry = map; 4395*7d7af7f8SEric Joyner break; 4396*7d7af7f8SEric Joyner } 439771d10453SEric Joyner 439871d10453SEric Joyner return entry; 439971d10453SEric Joyner } 440071d10453SEric Joyner 440171d10453SEric Joyner /** 440271d10453SEric Joyner * ice_set_prof_context - Set context for a given profile 440371d10453SEric Joyner * @hw: pointer to the HW struct 440471d10453SEric Joyner * @blk: hardware block 440571d10453SEric Joyner * @id: profile tracking ID 440671d10453SEric Joyner * @cntxt: context 440771d10453SEric Joyner */ 4408*7d7af7f8SEric Joyner enum ice_status 440971d10453SEric Joyner ice_set_prof_context(struct ice_hw *hw, enum ice_block blk, u64 id, u64 cntxt) 441071d10453SEric Joyner { 4411*7d7af7f8SEric Joyner enum ice_status status = ICE_ERR_DOES_NOT_EXIST; 441271d10453SEric Joyner struct ice_prof_map *entry; 441371d10453SEric Joyner 4414*7d7af7f8SEric Joyner ice_acquire_lock(&hw->blk[blk].es.prof_map_lock); 441571d10453SEric Joyner entry = ice_search_prof_id(hw, blk, id); 4416*7d7af7f8SEric Joyner if (entry) { 441771d10453SEric Joyner entry->context = cntxt; 4418*7d7af7f8SEric Joyner status = ICE_SUCCESS; 4419*7d7af7f8SEric Joyner } 4420*7d7af7f8SEric Joyner ice_release_lock(&hw->blk[blk].es.prof_map_lock); 4421*7d7af7f8SEric Joyner return status; 442271d10453SEric Joyner } 442371d10453SEric Joyner 442471d10453SEric Joyner /** 442571d10453SEric Joyner * ice_get_prof_context - Get context for a given profile 442671d10453SEric Joyner * @hw: pointer to the HW struct 442771d10453SEric Joyner * @blk: hardware block 442871d10453SEric Joyner * @id: profile tracking ID 442971d10453SEric Joyner * @cntxt: pointer to variable to receive the context 443071d10453SEric Joyner */ 4431*7d7af7f8SEric Joyner enum ice_status 443271d10453SEric Joyner ice_get_prof_context(struct ice_hw *hw, enum ice_block blk, u64 id, u64 *cntxt) 443371d10453SEric Joyner { 4434*7d7af7f8SEric Joyner enum ice_status status = ICE_ERR_DOES_NOT_EXIST; 443571d10453SEric Joyner struct ice_prof_map *entry; 443671d10453SEric Joyner 4437*7d7af7f8SEric Joyner ice_acquire_lock(&hw->blk[blk].es.prof_map_lock); 443871d10453SEric Joyner entry = ice_search_prof_id(hw, blk, id); 4439*7d7af7f8SEric Joyner if (entry) { 444071d10453SEric Joyner *cntxt = entry->context; 4441*7d7af7f8SEric Joyner status = ICE_SUCCESS; 4442*7d7af7f8SEric Joyner } 4443*7d7af7f8SEric Joyner ice_release_lock(&hw->blk[blk].es.prof_map_lock); 4444*7d7af7f8SEric Joyner return status; 444571d10453SEric Joyner } 444671d10453SEric Joyner 444771d10453SEric Joyner /** 444871d10453SEric Joyner * ice_vsig_prof_id_count - count profiles in a VSIG 444971d10453SEric Joyner * @hw: pointer to the HW struct 445071d10453SEric Joyner * @blk: hardware block 445171d10453SEric Joyner * @vsig: VSIG to remove the profile from 445271d10453SEric Joyner */ 445371d10453SEric Joyner static u16 445471d10453SEric Joyner ice_vsig_prof_id_count(struct ice_hw *hw, enum ice_block blk, u16 vsig) 445571d10453SEric Joyner { 445671d10453SEric Joyner u16 idx = vsig & ICE_VSIG_IDX_M, count = 0; 445771d10453SEric Joyner struct ice_vsig_prof *p; 445871d10453SEric Joyner 445971d10453SEric Joyner LIST_FOR_EACH_ENTRY(p, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst, 4460*7d7af7f8SEric Joyner ice_vsig_prof, list) 446171d10453SEric Joyner count++; 446271d10453SEric Joyner 446371d10453SEric Joyner return count; 446471d10453SEric Joyner } 446571d10453SEric Joyner 446671d10453SEric Joyner /** 446771d10453SEric Joyner * ice_rel_tcam_idx - release a TCAM index 446871d10453SEric Joyner * @hw: pointer to the HW struct 446971d10453SEric Joyner * @blk: hardware block 447071d10453SEric Joyner * @idx: the index to release 447171d10453SEric Joyner */ 447271d10453SEric Joyner static enum ice_status 447371d10453SEric Joyner ice_rel_tcam_idx(struct ice_hw *hw, enum ice_block blk, u16 idx) 447471d10453SEric Joyner { 447571d10453SEric Joyner /* Masks to invoke a never match entry */ 447671d10453SEric Joyner u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; 447771d10453SEric Joyner u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFE, 0xFF, 0xFF, 0xFF, 0xFF }; 447871d10453SEric Joyner u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x01, 0x00, 0x00, 0x00, 0x00 }; 447971d10453SEric Joyner enum ice_status status; 448071d10453SEric Joyner 448171d10453SEric Joyner /* write the TCAM entry */ 448271d10453SEric Joyner status = ice_tcam_write_entry(hw, blk, idx, 0, 0, 0, 0, 0, vl_msk, 448371d10453SEric Joyner dc_msk, nm_msk); 448471d10453SEric Joyner if (status) 448571d10453SEric Joyner return status; 448671d10453SEric Joyner 448771d10453SEric Joyner /* release the TCAM entry */ 448871d10453SEric Joyner status = ice_free_tcam_ent(hw, blk, idx); 448971d10453SEric Joyner 449071d10453SEric Joyner return status; 449171d10453SEric Joyner } 449271d10453SEric Joyner 449371d10453SEric Joyner /** 449471d10453SEric Joyner * ice_rem_prof_id - remove one profile from a VSIG 449571d10453SEric Joyner * @hw: pointer to the HW struct 449671d10453SEric Joyner * @blk: hardware block 449771d10453SEric Joyner * @prof: pointer to profile structure to remove 449871d10453SEric Joyner */ 449971d10453SEric Joyner static enum ice_status 450071d10453SEric Joyner ice_rem_prof_id(struct ice_hw *hw, enum ice_block blk, 450171d10453SEric Joyner struct ice_vsig_prof *prof) 450271d10453SEric Joyner { 450371d10453SEric Joyner enum ice_status status; 450471d10453SEric Joyner u16 i; 450571d10453SEric Joyner 4506*7d7af7f8SEric Joyner for (i = 0; i < prof->tcam_count; i++) 450771d10453SEric Joyner if (prof->tcam[i].in_use) { 450871d10453SEric Joyner prof->tcam[i].in_use = false; 450971d10453SEric Joyner status = ice_rel_tcam_idx(hw, blk, 451071d10453SEric Joyner prof->tcam[i].tcam_idx); 451171d10453SEric Joyner if (status) 451271d10453SEric Joyner return ICE_ERR_HW_TABLE; 451371d10453SEric Joyner } 451471d10453SEric Joyner 451571d10453SEric Joyner return ICE_SUCCESS; 451671d10453SEric Joyner } 451771d10453SEric Joyner 451871d10453SEric Joyner /** 451971d10453SEric Joyner * ice_rem_vsig - remove VSIG 452071d10453SEric Joyner * @hw: pointer to the HW struct 452171d10453SEric Joyner * @blk: hardware block 452271d10453SEric Joyner * @vsig: the VSIG to remove 452371d10453SEric Joyner * @chg: the change list 452471d10453SEric Joyner */ 452571d10453SEric Joyner static enum ice_status 452671d10453SEric Joyner ice_rem_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, 452771d10453SEric Joyner struct LIST_HEAD_TYPE *chg) 452871d10453SEric Joyner { 452971d10453SEric Joyner u16 idx = vsig & ICE_VSIG_IDX_M; 453071d10453SEric Joyner struct ice_vsig_vsi *vsi_cur; 453171d10453SEric Joyner struct ice_vsig_prof *d, *t; 453271d10453SEric Joyner enum ice_status status; 453371d10453SEric Joyner 453471d10453SEric Joyner /* remove TCAM entries */ 453571d10453SEric Joyner LIST_FOR_EACH_ENTRY_SAFE(d, t, 453671d10453SEric Joyner &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst, 453771d10453SEric Joyner ice_vsig_prof, list) { 453871d10453SEric Joyner status = ice_rem_prof_id(hw, blk, d); 453971d10453SEric Joyner if (status) 454071d10453SEric Joyner return status; 454171d10453SEric Joyner 454271d10453SEric Joyner LIST_DEL(&d->list); 454371d10453SEric Joyner ice_free(hw, d); 454471d10453SEric Joyner } 454571d10453SEric Joyner 454671d10453SEric Joyner /* Move all VSIS associated with this VSIG to the default VSIG */ 454771d10453SEric Joyner vsi_cur = hw->blk[blk].xlt2.vsig_tbl[idx].first_vsi; 454871d10453SEric Joyner /* If the VSIG has at least 1 VSI then iterate through the list 454971d10453SEric Joyner * and remove the VSIs before deleting the group. 455071d10453SEric Joyner */ 4551*7d7af7f8SEric Joyner if (vsi_cur) 455271d10453SEric Joyner do { 455371d10453SEric Joyner struct ice_vsig_vsi *tmp = vsi_cur->next_vsi; 455471d10453SEric Joyner struct ice_chs_chg *p; 455571d10453SEric Joyner 455671d10453SEric Joyner p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p)); 455771d10453SEric Joyner if (!p) 455871d10453SEric Joyner return ICE_ERR_NO_MEMORY; 455971d10453SEric Joyner 456071d10453SEric Joyner p->type = ICE_VSIG_REM; 456171d10453SEric Joyner p->orig_vsig = vsig; 456271d10453SEric Joyner p->vsig = ICE_DEFAULT_VSIG; 456371d10453SEric Joyner p->vsi = vsi_cur - hw->blk[blk].xlt2.vsis; 456471d10453SEric Joyner 456571d10453SEric Joyner LIST_ADD(&p->list_entry, chg); 456671d10453SEric Joyner 456771d10453SEric Joyner vsi_cur = tmp; 456871d10453SEric Joyner } while (vsi_cur); 456971d10453SEric Joyner 457071d10453SEric Joyner return ice_vsig_free(hw, blk, vsig); 457171d10453SEric Joyner } 457271d10453SEric Joyner 457371d10453SEric Joyner /** 457471d10453SEric Joyner * ice_rem_prof_id_vsig - remove a specific profile from a VSIG 457571d10453SEric Joyner * @hw: pointer to the HW struct 457671d10453SEric Joyner * @blk: hardware block 457771d10453SEric Joyner * @vsig: VSIG to remove the profile from 457871d10453SEric Joyner * @hdl: profile handle indicating which profile to remove 457971d10453SEric Joyner * @chg: list to receive a record of changes 458071d10453SEric Joyner */ 458171d10453SEric Joyner static enum ice_status 458271d10453SEric Joyner ice_rem_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl, 458371d10453SEric Joyner struct LIST_HEAD_TYPE *chg) 458471d10453SEric Joyner { 458571d10453SEric Joyner u16 idx = vsig & ICE_VSIG_IDX_M; 458671d10453SEric Joyner struct ice_vsig_prof *p, *t; 458771d10453SEric Joyner enum ice_status status; 458871d10453SEric Joyner 458971d10453SEric Joyner LIST_FOR_EACH_ENTRY_SAFE(p, t, 459071d10453SEric Joyner &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst, 4591*7d7af7f8SEric Joyner ice_vsig_prof, list) 459271d10453SEric Joyner if (p->profile_cookie == hdl) { 459371d10453SEric Joyner if (ice_vsig_prof_id_count(hw, blk, vsig) == 1) 459471d10453SEric Joyner /* this is the last profile, remove the VSIG */ 459571d10453SEric Joyner return ice_rem_vsig(hw, blk, vsig, chg); 459671d10453SEric Joyner 459771d10453SEric Joyner status = ice_rem_prof_id(hw, blk, p); 459871d10453SEric Joyner if (!status) { 459971d10453SEric Joyner LIST_DEL(&p->list); 460071d10453SEric Joyner ice_free(hw, p); 460171d10453SEric Joyner } 460271d10453SEric Joyner return status; 460371d10453SEric Joyner } 460471d10453SEric Joyner 460571d10453SEric Joyner return ICE_ERR_DOES_NOT_EXIST; 460671d10453SEric Joyner } 460771d10453SEric Joyner 460871d10453SEric Joyner /** 460971d10453SEric Joyner * ice_rem_flow_all - remove all flows with a particular profile 461071d10453SEric Joyner * @hw: pointer to the HW struct 461171d10453SEric Joyner * @blk: hardware block 461271d10453SEric Joyner * @id: profile tracking ID 461371d10453SEric Joyner */ 461471d10453SEric Joyner static enum ice_status 461571d10453SEric Joyner ice_rem_flow_all(struct ice_hw *hw, enum ice_block blk, u64 id) 461671d10453SEric Joyner { 461771d10453SEric Joyner struct ice_chs_chg *del, *tmp; 461871d10453SEric Joyner enum ice_status status; 4619*7d7af7f8SEric Joyner struct LIST_HEAD_TYPE chg; 462071d10453SEric Joyner u16 i; 462171d10453SEric Joyner 462271d10453SEric Joyner INIT_LIST_HEAD(&chg); 462371d10453SEric Joyner 4624*7d7af7f8SEric Joyner for (i = 1; i < ICE_MAX_VSIGS; i++) 462571d10453SEric Joyner if (hw->blk[blk].xlt2.vsig_tbl[i].in_use) { 462671d10453SEric Joyner if (ice_has_prof_vsig(hw, blk, i, id)) { 462771d10453SEric Joyner status = ice_rem_prof_id_vsig(hw, blk, i, id, 462871d10453SEric Joyner &chg); 462971d10453SEric Joyner if (status) 463071d10453SEric Joyner goto err_ice_rem_flow_all; 463171d10453SEric Joyner } 463271d10453SEric Joyner } 463371d10453SEric Joyner 463471d10453SEric Joyner status = ice_upd_prof_hw(hw, blk, &chg); 463571d10453SEric Joyner 463671d10453SEric Joyner err_ice_rem_flow_all: 463771d10453SEric Joyner LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) { 463871d10453SEric Joyner LIST_DEL(&del->list_entry); 463971d10453SEric Joyner ice_free(hw, del); 464071d10453SEric Joyner } 464171d10453SEric Joyner 464271d10453SEric Joyner return status; 464371d10453SEric Joyner } 464471d10453SEric Joyner 464571d10453SEric Joyner /** 464671d10453SEric Joyner * ice_rem_prof - remove profile 464771d10453SEric Joyner * @hw: pointer to the HW struct 464871d10453SEric Joyner * @blk: hardware block 464971d10453SEric Joyner * @id: profile tracking ID 465071d10453SEric Joyner * 465171d10453SEric Joyner * This will remove the profile specified by the ID parameter, which was 465271d10453SEric Joyner * previously created through ice_add_prof. If any existing entries 465371d10453SEric Joyner * are associated with this profile, they will be removed as well. 465471d10453SEric Joyner */ 465571d10453SEric Joyner enum ice_status ice_rem_prof(struct ice_hw *hw, enum ice_block blk, u64 id) 465671d10453SEric Joyner { 465771d10453SEric Joyner struct ice_prof_map *pmap; 465871d10453SEric Joyner enum ice_status status; 465971d10453SEric Joyner 466071d10453SEric Joyner ice_acquire_lock(&hw->blk[blk].es.prof_map_lock); 466171d10453SEric Joyner 4662*7d7af7f8SEric Joyner pmap = ice_search_prof_id(hw, blk, id); 466371d10453SEric Joyner if (!pmap) { 466471d10453SEric Joyner status = ICE_ERR_DOES_NOT_EXIST; 466571d10453SEric Joyner goto err_ice_rem_prof; 466671d10453SEric Joyner } 466771d10453SEric Joyner 466871d10453SEric Joyner /* remove all flows with this profile */ 466971d10453SEric Joyner status = ice_rem_flow_all(hw, blk, pmap->profile_cookie); 467071d10453SEric Joyner if (status) 467171d10453SEric Joyner goto err_ice_rem_prof; 467271d10453SEric Joyner 467371d10453SEric Joyner /* dereference profile, and possibly remove */ 467471d10453SEric Joyner ice_prof_dec_ref(hw, blk, pmap->prof_id); 467571d10453SEric Joyner 467671d10453SEric Joyner LIST_DEL(&pmap->list); 467771d10453SEric Joyner ice_free(hw, pmap); 467871d10453SEric Joyner 467971d10453SEric Joyner err_ice_rem_prof: 468071d10453SEric Joyner ice_release_lock(&hw->blk[blk].es.prof_map_lock); 468171d10453SEric Joyner return status; 468271d10453SEric Joyner } 468371d10453SEric Joyner 468471d10453SEric Joyner /** 468571d10453SEric Joyner * ice_get_prof - get profile 468671d10453SEric Joyner * @hw: pointer to the HW struct 468771d10453SEric Joyner * @blk: hardware block 468871d10453SEric Joyner * @hdl: profile handle 468971d10453SEric Joyner * @chg: change list 469071d10453SEric Joyner */ 469171d10453SEric Joyner static enum ice_status 469271d10453SEric Joyner ice_get_prof(struct ice_hw *hw, enum ice_block blk, u64 hdl, 469371d10453SEric Joyner struct LIST_HEAD_TYPE *chg) 469471d10453SEric Joyner { 4695*7d7af7f8SEric Joyner enum ice_status status = ICE_SUCCESS; 469671d10453SEric Joyner struct ice_prof_map *map; 469771d10453SEric Joyner struct ice_chs_chg *p; 469871d10453SEric Joyner u16 i; 469971d10453SEric Joyner 4700*7d7af7f8SEric Joyner ice_acquire_lock(&hw->blk[blk].es.prof_map_lock); 470171d10453SEric Joyner /* Get the details on the profile specified by the handle ID */ 470271d10453SEric Joyner map = ice_search_prof_id(hw, blk, hdl); 4703*7d7af7f8SEric Joyner if (!map) { 4704*7d7af7f8SEric Joyner status = ICE_ERR_DOES_NOT_EXIST; 4705*7d7af7f8SEric Joyner goto err_ice_get_prof; 4706*7d7af7f8SEric Joyner } 470771d10453SEric Joyner 4708*7d7af7f8SEric Joyner for (i = 0; i < map->ptg_cnt; i++) 470971d10453SEric Joyner if (!hw->blk[blk].es.written[map->prof_id]) { 471071d10453SEric Joyner /* add ES to change list */ 471171d10453SEric Joyner p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p)); 4712*7d7af7f8SEric Joyner if (!p) { 4713*7d7af7f8SEric Joyner status = ICE_ERR_NO_MEMORY; 471471d10453SEric Joyner goto err_ice_get_prof; 4715*7d7af7f8SEric Joyner } 471671d10453SEric Joyner 471771d10453SEric Joyner p->type = ICE_PTG_ES_ADD; 471871d10453SEric Joyner p->ptype = 0; 471971d10453SEric Joyner p->ptg = map->ptg[i]; 472071d10453SEric Joyner p->add_ptg = 0; 472171d10453SEric Joyner 472271d10453SEric Joyner p->add_prof = 1; 472371d10453SEric Joyner p->prof_id = map->prof_id; 472471d10453SEric Joyner 472571d10453SEric Joyner hw->blk[blk].es.written[map->prof_id] = true; 472671d10453SEric Joyner 472771d10453SEric Joyner LIST_ADD(&p->list_entry, chg); 472871d10453SEric Joyner } 472971d10453SEric Joyner 473071d10453SEric Joyner err_ice_get_prof: 4731*7d7af7f8SEric Joyner ice_release_lock(&hw->blk[blk].es.prof_map_lock); 473271d10453SEric Joyner /* let caller clean up the change list */ 4733*7d7af7f8SEric Joyner return status; 473471d10453SEric Joyner } 473571d10453SEric Joyner 473671d10453SEric Joyner /** 473771d10453SEric Joyner * ice_get_profs_vsig - get a copy of the list of profiles from a VSIG 473871d10453SEric Joyner * @hw: pointer to the HW struct 473971d10453SEric Joyner * @blk: hardware block 474071d10453SEric Joyner * @vsig: VSIG from which to copy the list 474171d10453SEric Joyner * @lst: output list 474271d10453SEric Joyner * 474371d10453SEric Joyner * This routine makes a copy of the list of profiles in the specified VSIG. 474471d10453SEric Joyner */ 474571d10453SEric Joyner static enum ice_status 474671d10453SEric Joyner ice_get_profs_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, 474771d10453SEric Joyner struct LIST_HEAD_TYPE *lst) 474871d10453SEric Joyner { 474971d10453SEric Joyner struct ice_vsig_prof *ent1, *ent2; 475071d10453SEric Joyner u16 idx = vsig & ICE_VSIG_IDX_M; 475171d10453SEric Joyner 475271d10453SEric Joyner LIST_FOR_EACH_ENTRY(ent1, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst, 475371d10453SEric Joyner ice_vsig_prof, list) { 475471d10453SEric Joyner struct ice_vsig_prof *p; 475571d10453SEric Joyner 475671d10453SEric Joyner /* copy to the input list */ 475771d10453SEric Joyner p = (struct ice_vsig_prof *)ice_memdup(hw, ent1, sizeof(*p), 475871d10453SEric Joyner ICE_NONDMA_TO_NONDMA); 475971d10453SEric Joyner if (!p) 476071d10453SEric Joyner goto err_ice_get_profs_vsig; 476171d10453SEric Joyner 476271d10453SEric Joyner LIST_ADD_TAIL(&p->list, lst); 476371d10453SEric Joyner } 476471d10453SEric Joyner 476571d10453SEric Joyner return ICE_SUCCESS; 476671d10453SEric Joyner 476771d10453SEric Joyner err_ice_get_profs_vsig: 476871d10453SEric Joyner LIST_FOR_EACH_ENTRY_SAFE(ent1, ent2, lst, ice_vsig_prof, list) { 476971d10453SEric Joyner LIST_DEL(&ent1->list); 477071d10453SEric Joyner ice_free(hw, ent1); 477171d10453SEric Joyner } 477271d10453SEric Joyner 477371d10453SEric Joyner return ICE_ERR_NO_MEMORY; 477471d10453SEric Joyner } 477571d10453SEric Joyner 477671d10453SEric Joyner /** 477771d10453SEric Joyner * ice_add_prof_to_lst - add profile entry to a list 477871d10453SEric Joyner * @hw: pointer to the HW struct 477971d10453SEric Joyner * @blk: hardware block 478071d10453SEric Joyner * @lst: the list to be added to 478171d10453SEric Joyner * @hdl: profile handle of entry to add 478271d10453SEric Joyner */ 478371d10453SEric Joyner static enum ice_status 478471d10453SEric Joyner ice_add_prof_to_lst(struct ice_hw *hw, enum ice_block blk, 478571d10453SEric Joyner struct LIST_HEAD_TYPE *lst, u64 hdl) 478671d10453SEric Joyner { 4787*7d7af7f8SEric Joyner enum ice_status status = ICE_SUCCESS; 478871d10453SEric Joyner struct ice_prof_map *map; 478971d10453SEric Joyner struct ice_vsig_prof *p; 479071d10453SEric Joyner u16 i; 479171d10453SEric Joyner 4792*7d7af7f8SEric Joyner ice_acquire_lock(&hw->blk[blk].es.prof_map_lock); 479371d10453SEric Joyner map = ice_search_prof_id(hw, blk, hdl); 4794*7d7af7f8SEric Joyner if (!map) { 4795*7d7af7f8SEric Joyner status = ICE_ERR_DOES_NOT_EXIST; 4796*7d7af7f8SEric Joyner goto err_ice_add_prof_to_lst; 4797*7d7af7f8SEric Joyner } 479871d10453SEric Joyner 479971d10453SEric Joyner p = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*p)); 4800*7d7af7f8SEric Joyner if (!p) { 4801*7d7af7f8SEric Joyner status = ICE_ERR_NO_MEMORY; 4802*7d7af7f8SEric Joyner goto err_ice_add_prof_to_lst; 4803*7d7af7f8SEric Joyner } 480471d10453SEric Joyner 480571d10453SEric Joyner p->profile_cookie = map->profile_cookie; 480671d10453SEric Joyner p->prof_id = map->prof_id; 480771d10453SEric Joyner p->tcam_count = map->ptg_cnt; 480871d10453SEric Joyner 480971d10453SEric Joyner for (i = 0; i < map->ptg_cnt; i++) { 481071d10453SEric Joyner p->tcam[i].prof_id = map->prof_id; 481171d10453SEric Joyner p->tcam[i].tcam_idx = ICE_INVALID_TCAM; 481271d10453SEric Joyner p->tcam[i].ptg = map->ptg[i]; 481371d10453SEric Joyner } 481471d10453SEric Joyner 481571d10453SEric Joyner LIST_ADD(&p->list, lst); 481671d10453SEric Joyner 4817*7d7af7f8SEric Joyner err_ice_add_prof_to_lst: 4818*7d7af7f8SEric Joyner ice_release_lock(&hw->blk[blk].es.prof_map_lock); 4819*7d7af7f8SEric Joyner return status; 482071d10453SEric Joyner } 482171d10453SEric Joyner 482271d10453SEric Joyner /** 482371d10453SEric Joyner * ice_move_vsi - move VSI to another VSIG 482471d10453SEric Joyner * @hw: pointer to the HW struct 482571d10453SEric Joyner * @blk: hardware block 482671d10453SEric Joyner * @vsi: the VSI to move 482771d10453SEric Joyner * @vsig: the VSIG to move the VSI to 482871d10453SEric Joyner * @chg: the change list 482971d10453SEric Joyner */ 483071d10453SEric Joyner static enum ice_status 483171d10453SEric Joyner ice_move_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig, 483271d10453SEric Joyner struct LIST_HEAD_TYPE *chg) 483371d10453SEric Joyner { 483471d10453SEric Joyner enum ice_status status; 483571d10453SEric Joyner struct ice_chs_chg *p; 483671d10453SEric Joyner u16 orig_vsig; 483771d10453SEric Joyner 483871d10453SEric Joyner p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p)); 483971d10453SEric Joyner if (!p) 484071d10453SEric Joyner return ICE_ERR_NO_MEMORY; 484171d10453SEric Joyner 484271d10453SEric Joyner status = ice_vsig_find_vsi(hw, blk, vsi, &orig_vsig); 484371d10453SEric Joyner if (!status) 484471d10453SEric Joyner status = ice_vsig_add_mv_vsi(hw, blk, vsi, vsig); 484571d10453SEric Joyner 484671d10453SEric Joyner if (status) { 484771d10453SEric Joyner ice_free(hw, p); 484871d10453SEric Joyner return status; 484971d10453SEric Joyner } 485071d10453SEric Joyner 485171d10453SEric Joyner p->type = ICE_VSI_MOVE; 485271d10453SEric Joyner p->vsi = vsi; 485371d10453SEric Joyner p->orig_vsig = orig_vsig; 485471d10453SEric Joyner p->vsig = vsig; 485571d10453SEric Joyner 485671d10453SEric Joyner LIST_ADD(&p->list_entry, chg); 485771d10453SEric Joyner 485871d10453SEric Joyner return ICE_SUCCESS; 485971d10453SEric Joyner } 486071d10453SEric Joyner 486171d10453SEric Joyner /** 486271d10453SEric Joyner * ice_rem_chg_tcam_ent - remove a specific TCAM entry from change list 486371d10453SEric Joyner * @hw: pointer to the HW struct 486471d10453SEric Joyner * @idx: the index of the TCAM entry to remove 486571d10453SEric Joyner * @chg: the list of change structures to search 486671d10453SEric Joyner */ 486771d10453SEric Joyner static void 486871d10453SEric Joyner ice_rem_chg_tcam_ent(struct ice_hw *hw, u16 idx, struct LIST_HEAD_TYPE *chg) 486971d10453SEric Joyner { 487071d10453SEric Joyner struct ice_chs_chg *pos, *tmp; 487171d10453SEric Joyner 4872*7d7af7f8SEric Joyner LIST_FOR_EACH_ENTRY_SAFE(tmp, pos, chg, ice_chs_chg, list_entry) 487371d10453SEric Joyner if (tmp->type == ICE_TCAM_ADD && tmp->tcam_idx == idx) { 487471d10453SEric Joyner LIST_DEL(&tmp->list_entry); 487571d10453SEric Joyner ice_free(hw, tmp); 487671d10453SEric Joyner } 487771d10453SEric Joyner } 487871d10453SEric Joyner 487971d10453SEric Joyner /** 488071d10453SEric Joyner * ice_prof_tcam_ena_dis - add enable or disable TCAM change 488171d10453SEric Joyner * @hw: pointer to the HW struct 488271d10453SEric Joyner * @blk: hardware block 488371d10453SEric Joyner * @enable: true to enable, false to disable 488471d10453SEric Joyner * @vsig: the VSIG of the TCAM entry 488571d10453SEric Joyner * @tcam: pointer the TCAM info structure of the TCAM to disable 488671d10453SEric Joyner * @chg: the change list 488771d10453SEric Joyner * 488871d10453SEric Joyner * This function appends an enable or disable TCAM entry in the change log 488971d10453SEric Joyner */ 489071d10453SEric Joyner static enum ice_status 489171d10453SEric Joyner ice_prof_tcam_ena_dis(struct ice_hw *hw, enum ice_block blk, bool enable, 489271d10453SEric Joyner u16 vsig, struct ice_tcam_inf *tcam, 489371d10453SEric Joyner struct LIST_HEAD_TYPE *chg) 489471d10453SEric Joyner { 489571d10453SEric Joyner enum ice_status status; 489671d10453SEric Joyner struct ice_chs_chg *p; 489771d10453SEric Joyner 489871d10453SEric Joyner u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; 489971d10453SEric Joyner u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0x00, 0x00, 0x00 }; 490071d10453SEric Joyner u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x00, 0x00, 0x00, 0x00, 0x00 }; 490171d10453SEric Joyner 490271d10453SEric Joyner /* if disabling, free the TCAM */ 490371d10453SEric Joyner if (!enable) { 490471d10453SEric Joyner status = ice_rel_tcam_idx(hw, blk, tcam->tcam_idx); 490571d10453SEric Joyner 490671d10453SEric Joyner /* if we have already created a change for this TCAM entry, then 490771d10453SEric Joyner * we need to remove that entry, in order to prevent writing to 490871d10453SEric Joyner * a TCAM entry we no longer will have ownership of. 490971d10453SEric Joyner */ 491071d10453SEric Joyner ice_rem_chg_tcam_ent(hw, tcam->tcam_idx, chg); 491171d10453SEric Joyner tcam->tcam_idx = 0; 491271d10453SEric Joyner tcam->in_use = 0; 491371d10453SEric Joyner return status; 491471d10453SEric Joyner } 491571d10453SEric Joyner 491671d10453SEric Joyner /* for re-enabling, reallocate a TCAM */ 4917*7d7af7f8SEric Joyner status = ice_alloc_tcam_ent(hw, blk, true, &tcam->tcam_idx); 491871d10453SEric Joyner if (status) 491971d10453SEric Joyner return status; 492071d10453SEric Joyner 492171d10453SEric Joyner /* add TCAM to change list */ 492271d10453SEric Joyner p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p)); 492371d10453SEric Joyner if (!p) 492471d10453SEric Joyner return ICE_ERR_NO_MEMORY; 492571d10453SEric Joyner 492671d10453SEric Joyner status = ice_tcam_write_entry(hw, blk, tcam->tcam_idx, tcam->prof_id, 492771d10453SEric Joyner tcam->ptg, vsig, 0, 0, vl_msk, dc_msk, 492871d10453SEric Joyner nm_msk); 492971d10453SEric Joyner if (status) 493071d10453SEric Joyner goto err_ice_prof_tcam_ena_dis; 493171d10453SEric Joyner 493271d10453SEric Joyner tcam->in_use = 1; 493371d10453SEric Joyner 493471d10453SEric Joyner p->type = ICE_TCAM_ADD; 493571d10453SEric Joyner p->add_tcam_idx = true; 493671d10453SEric Joyner p->prof_id = tcam->prof_id; 493771d10453SEric Joyner p->ptg = tcam->ptg; 493871d10453SEric Joyner p->vsig = 0; 493971d10453SEric Joyner p->tcam_idx = tcam->tcam_idx; 494071d10453SEric Joyner 494171d10453SEric Joyner /* log change */ 494271d10453SEric Joyner LIST_ADD(&p->list_entry, chg); 494371d10453SEric Joyner 494471d10453SEric Joyner return ICE_SUCCESS; 494571d10453SEric Joyner 494671d10453SEric Joyner err_ice_prof_tcam_ena_dis: 494771d10453SEric Joyner ice_free(hw, p); 494871d10453SEric Joyner return status; 494971d10453SEric Joyner } 495071d10453SEric Joyner 495171d10453SEric Joyner /** 495271d10453SEric Joyner * ice_adj_prof_priorities - adjust profile based on priorities 495371d10453SEric Joyner * @hw: pointer to the HW struct 495471d10453SEric Joyner * @blk: hardware block 495571d10453SEric Joyner * @vsig: the VSIG for which to adjust profile priorities 495671d10453SEric Joyner * @chg: the change list 495771d10453SEric Joyner */ 495871d10453SEric Joyner static enum ice_status 495971d10453SEric Joyner ice_adj_prof_priorities(struct ice_hw *hw, enum ice_block blk, u16 vsig, 496071d10453SEric Joyner struct LIST_HEAD_TYPE *chg) 496171d10453SEric Joyner { 496271d10453SEric Joyner ice_declare_bitmap(ptgs_used, ICE_XLT1_CNT); 496371d10453SEric Joyner enum ice_status status = ICE_SUCCESS; 496471d10453SEric Joyner struct ice_vsig_prof *t; 496571d10453SEric Joyner u16 idx; 496671d10453SEric Joyner 496771d10453SEric Joyner ice_zero_bitmap(ptgs_used, ICE_XLT1_CNT); 496871d10453SEric Joyner idx = vsig & ICE_VSIG_IDX_M; 496971d10453SEric Joyner 497071d10453SEric Joyner /* Priority is based on the order in which the profiles are added. The 497171d10453SEric Joyner * newest added profile has highest priority and the oldest added 497271d10453SEric Joyner * profile has the lowest priority. Since the profile property list for 497371d10453SEric Joyner * a VSIG is sorted from newest to oldest, this code traverses the list 497471d10453SEric Joyner * in order and enables the first of each PTG that it finds (that is not 497571d10453SEric Joyner * already enabled); it also disables any duplicate PTGs that it finds 497671d10453SEric Joyner * in the older profiles (that are currently enabled). 497771d10453SEric Joyner */ 497871d10453SEric Joyner 497971d10453SEric Joyner LIST_FOR_EACH_ENTRY(t, &hw->blk[blk].xlt2.vsig_tbl[idx].prop_lst, 498071d10453SEric Joyner ice_vsig_prof, list) { 498171d10453SEric Joyner u16 i; 498271d10453SEric Joyner 498371d10453SEric Joyner for (i = 0; i < t->tcam_count; i++) { 498471d10453SEric Joyner bool used; 498571d10453SEric Joyner 498671d10453SEric Joyner /* Scan the priorities from newest to oldest. 498771d10453SEric Joyner * Make sure that the newest profiles take priority. 498871d10453SEric Joyner */ 498971d10453SEric Joyner used = ice_is_bit_set(ptgs_used, t->tcam[i].ptg); 499071d10453SEric Joyner 499171d10453SEric Joyner if (used && t->tcam[i].in_use) { 499271d10453SEric Joyner /* need to mark this PTG as never match, as it 499371d10453SEric Joyner * was already in use and therefore duplicate 499471d10453SEric Joyner * (and lower priority) 499571d10453SEric Joyner */ 499671d10453SEric Joyner status = ice_prof_tcam_ena_dis(hw, blk, false, 499771d10453SEric Joyner vsig, 499871d10453SEric Joyner &t->tcam[i], 499971d10453SEric Joyner chg); 500071d10453SEric Joyner if (status) 500171d10453SEric Joyner return status; 500271d10453SEric Joyner } else if (!used && !t->tcam[i].in_use) { 500371d10453SEric Joyner /* need to enable this PTG, as it in not in use 500471d10453SEric Joyner * and not enabled (highest priority) 500571d10453SEric Joyner */ 500671d10453SEric Joyner status = ice_prof_tcam_ena_dis(hw, blk, true, 500771d10453SEric Joyner vsig, 500871d10453SEric Joyner &t->tcam[i], 500971d10453SEric Joyner chg); 501071d10453SEric Joyner if (status) 501171d10453SEric Joyner return status; 501271d10453SEric Joyner } 501371d10453SEric Joyner 501471d10453SEric Joyner /* keep track of used ptgs */ 501571d10453SEric Joyner ice_set_bit(t->tcam[i].ptg, ptgs_used); 501671d10453SEric Joyner } 501771d10453SEric Joyner } 501871d10453SEric Joyner 501971d10453SEric Joyner return status; 502071d10453SEric Joyner } 502171d10453SEric Joyner 502271d10453SEric Joyner /** 502371d10453SEric Joyner * ice_add_prof_id_vsig - add profile to VSIG 502471d10453SEric Joyner * @hw: pointer to the HW struct 502571d10453SEric Joyner * @blk: hardware block 502671d10453SEric Joyner * @vsig: the VSIG to which this profile is to be added 502771d10453SEric Joyner * @hdl: the profile handle indicating the profile to add 502871d10453SEric Joyner * @rev: true to add entries to the end of the list 502971d10453SEric Joyner * @chg: the change list 503071d10453SEric Joyner */ 503171d10453SEric Joyner static enum ice_status 503271d10453SEric Joyner ice_add_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsig, u64 hdl, 503371d10453SEric Joyner bool rev, struct LIST_HEAD_TYPE *chg) 503471d10453SEric Joyner { 503571d10453SEric Joyner /* Masks that ignore flags */ 503671d10453SEric Joyner u8 vl_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; 503771d10453SEric Joyner u8 dc_msk[ICE_TCAM_KEY_VAL_SZ] = { 0xFF, 0xFF, 0x00, 0x00, 0x00 }; 503871d10453SEric Joyner u8 nm_msk[ICE_TCAM_KEY_VAL_SZ] = { 0x00, 0x00, 0x00, 0x00, 0x00 }; 5039*7d7af7f8SEric Joyner enum ice_status status = ICE_SUCCESS; 504071d10453SEric Joyner struct ice_prof_map *map; 504171d10453SEric Joyner struct ice_vsig_prof *t; 504271d10453SEric Joyner struct ice_chs_chg *p; 504371d10453SEric Joyner u16 vsig_idx, i; 504471d10453SEric Joyner 504571d10453SEric Joyner /* Error, if this VSIG already has this profile */ 504671d10453SEric Joyner if (ice_has_prof_vsig(hw, blk, vsig, hdl)) 504771d10453SEric Joyner return ICE_ERR_ALREADY_EXISTS; 504871d10453SEric Joyner 504971d10453SEric Joyner /* new VSIG profile structure */ 505071d10453SEric Joyner t = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*t)); 505171d10453SEric Joyner if (!t) 505271d10453SEric Joyner return ICE_ERR_NO_MEMORY; 505371d10453SEric Joyner 5054*7d7af7f8SEric Joyner ice_acquire_lock(&hw->blk[blk].es.prof_map_lock); 5055*7d7af7f8SEric Joyner /* Get the details on the profile specified by the handle ID */ 5056*7d7af7f8SEric Joyner map = ice_search_prof_id(hw, blk, hdl); 5057*7d7af7f8SEric Joyner if (!map) { 5058*7d7af7f8SEric Joyner status = ICE_ERR_DOES_NOT_EXIST; 5059*7d7af7f8SEric Joyner goto err_ice_add_prof_id_vsig; 5060*7d7af7f8SEric Joyner } 5061*7d7af7f8SEric Joyner 506271d10453SEric Joyner t->profile_cookie = map->profile_cookie; 506371d10453SEric Joyner t->prof_id = map->prof_id; 506471d10453SEric Joyner t->tcam_count = map->ptg_cnt; 506571d10453SEric Joyner 506671d10453SEric Joyner /* create TCAM entries */ 506771d10453SEric Joyner for (i = 0; i < map->ptg_cnt; i++) { 506871d10453SEric Joyner u16 tcam_idx; 506971d10453SEric Joyner 507071d10453SEric Joyner /* add TCAM to change list */ 507171d10453SEric Joyner p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p)); 5072*7d7af7f8SEric Joyner if (!p) { 5073*7d7af7f8SEric Joyner status = ICE_ERR_NO_MEMORY; 507471d10453SEric Joyner goto err_ice_add_prof_id_vsig; 5075*7d7af7f8SEric Joyner } 507671d10453SEric Joyner 507771d10453SEric Joyner /* allocate the TCAM entry index */ 5078*7d7af7f8SEric Joyner status = ice_alloc_tcam_ent(hw, blk, true, &tcam_idx); 507971d10453SEric Joyner if (status) { 508071d10453SEric Joyner ice_free(hw, p); 508171d10453SEric Joyner goto err_ice_add_prof_id_vsig; 508271d10453SEric Joyner } 508371d10453SEric Joyner 508471d10453SEric Joyner t->tcam[i].ptg = map->ptg[i]; 508571d10453SEric Joyner t->tcam[i].prof_id = map->prof_id; 508671d10453SEric Joyner t->tcam[i].tcam_idx = tcam_idx; 508771d10453SEric Joyner t->tcam[i].in_use = true; 508871d10453SEric Joyner 508971d10453SEric Joyner p->type = ICE_TCAM_ADD; 509071d10453SEric Joyner p->add_tcam_idx = true; 509171d10453SEric Joyner p->prof_id = t->tcam[i].prof_id; 509271d10453SEric Joyner p->ptg = t->tcam[i].ptg; 509371d10453SEric Joyner p->vsig = vsig; 509471d10453SEric Joyner p->tcam_idx = t->tcam[i].tcam_idx; 509571d10453SEric Joyner 509671d10453SEric Joyner /* write the TCAM entry */ 509771d10453SEric Joyner status = ice_tcam_write_entry(hw, blk, t->tcam[i].tcam_idx, 509871d10453SEric Joyner t->tcam[i].prof_id, 509971d10453SEric Joyner t->tcam[i].ptg, vsig, 0, 0, 510071d10453SEric Joyner vl_msk, dc_msk, nm_msk); 510171d10453SEric Joyner if (status) { 510271d10453SEric Joyner ice_free(hw, p); 510371d10453SEric Joyner goto err_ice_add_prof_id_vsig; 510471d10453SEric Joyner } 510571d10453SEric Joyner 510671d10453SEric Joyner /* log change */ 510771d10453SEric Joyner LIST_ADD(&p->list_entry, chg); 510871d10453SEric Joyner } 510971d10453SEric Joyner 511071d10453SEric Joyner /* add profile to VSIG */ 511171d10453SEric Joyner vsig_idx = vsig & ICE_VSIG_IDX_M; 511271d10453SEric Joyner if (rev) 511371d10453SEric Joyner LIST_ADD_TAIL(&t->list, 511471d10453SEric Joyner &hw->blk[blk].xlt2.vsig_tbl[vsig_idx].prop_lst); 511571d10453SEric Joyner else 511671d10453SEric Joyner LIST_ADD(&t->list, 511771d10453SEric Joyner &hw->blk[blk].xlt2.vsig_tbl[vsig_idx].prop_lst); 511871d10453SEric Joyner 5119*7d7af7f8SEric Joyner ice_release_lock(&hw->blk[blk].es.prof_map_lock); 5120*7d7af7f8SEric Joyner return status; 512171d10453SEric Joyner 512271d10453SEric Joyner err_ice_add_prof_id_vsig: 5123*7d7af7f8SEric Joyner ice_release_lock(&hw->blk[blk].es.prof_map_lock); 512471d10453SEric Joyner /* let caller clean up the change list */ 512571d10453SEric Joyner ice_free(hw, t); 5126*7d7af7f8SEric Joyner return status; 512771d10453SEric Joyner } 512871d10453SEric Joyner 512971d10453SEric Joyner /** 513071d10453SEric Joyner * ice_create_prof_id_vsig - add a new VSIG with a single profile 513171d10453SEric Joyner * @hw: pointer to the HW struct 513271d10453SEric Joyner * @blk: hardware block 513371d10453SEric Joyner * @vsi: the initial VSI that will be in VSIG 513471d10453SEric Joyner * @hdl: the profile handle of the profile that will be added to the VSIG 513571d10453SEric Joyner * @chg: the change list 513671d10453SEric Joyner */ 513771d10453SEric Joyner static enum ice_status 513871d10453SEric Joyner ice_create_prof_id_vsig(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl, 513971d10453SEric Joyner struct LIST_HEAD_TYPE *chg) 514071d10453SEric Joyner { 514171d10453SEric Joyner enum ice_status status; 514271d10453SEric Joyner struct ice_chs_chg *p; 514371d10453SEric Joyner u16 new_vsig; 514471d10453SEric Joyner 514571d10453SEric Joyner p = (struct ice_chs_chg *)ice_malloc(hw, sizeof(*p)); 514671d10453SEric Joyner if (!p) 514771d10453SEric Joyner return ICE_ERR_NO_MEMORY; 514871d10453SEric Joyner 514971d10453SEric Joyner new_vsig = ice_vsig_alloc(hw, blk); 515071d10453SEric Joyner if (!new_vsig) { 515171d10453SEric Joyner status = ICE_ERR_HW_TABLE; 515271d10453SEric Joyner goto err_ice_create_prof_id_vsig; 515371d10453SEric Joyner } 515471d10453SEric Joyner 515571d10453SEric Joyner status = ice_move_vsi(hw, blk, vsi, new_vsig, chg); 515671d10453SEric Joyner if (status) 515771d10453SEric Joyner goto err_ice_create_prof_id_vsig; 515871d10453SEric Joyner 515971d10453SEric Joyner status = ice_add_prof_id_vsig(hw, blk, new_vsig, hdl, false, chg); 516071d10453SEric Joyner if (status) 516171d10453SEric Joyner goto err_ice_create_prof_id_vsig; 516271d10453SEric Joyner 516371d10453SEric Joyner p->type = ICE_VSIG_ADD; 516471d10453SEric Joyner p->vsi = vsi; 516571d10453SEric Joyner p->orig_vsig = ICE_DEFAULT_VSIG; 516671d10453SEric Joyner p->vsig = new_vsig; 516771d10453SEric Joyner 516871d10453SEric Joyner LIST_ADD(&p->list_entry, chg); 516971d10453SEric Joyner 517071d10453SEric Joyner return ICE_SUCCESS; 517171d10453SEric Joyner 517271d10453SEric Joyner err_ice_create_prof_id_vsig: 517371d10453SEric Joyner /* let caller clean up the change list */ 517471d10453SEric Joyner ice_free(hw, p); 517571d10453SEric Joyner return status; 517671d10453SEric Joyner } 517771d10453SEric Joyner 517871d10453SEric Joyner /** 517971d10453SEric Joyner * ice_create_vsig_from_lst - create a new VSIG with a list of profiles 518071d10453SEric Joyner * @hw: pointer to the HW struct 518171d10453SEric Joyner * @blk: hardware block 518271d10453SEric Joyner * @vsi: the initial VSI that will be in VSIG 518371d10453SEric Joyner * @lst: the list of profile that will be added to the VSIG 518471d10453SEric Joyner * @new_vsig: return of new VSIG 518571d10453SEric Joyner * @chg: the change list 518671d10453SEric Joyner */ 518771d10453SEric Joyner static enum ice_status 518871d10453SEric Joyner ice_create_vsig_from_lst(struct ice_hw *hw, enum ice_block blk, u16 vsi, 518971d10453SEric Joyner struct LIST_HEAD_TYPE *lst, u16 *new_vsig, 519071d10453SEric Joyner struct LIST_HEAD_TYPE *chg) 519171d10453SEric Joyner { 519271d10453SEric Joyner struct ice_vsig_prof *t; 519371d10453SEric Joyner enum ice_status status; 519471d10453SEric Joyner u16 vsig; 519571d10453SEric Joyner 519671d10453SEric Joyner vsig = ice_vsig_alloc(hw, blk); 519771d10453SEric Joyner if (!vsig) 519871d10453SEric Joyner return ICE_ERR_HW_TABLE; 519971d10453SEric Joyner 520071d10453SEric Joyner status = ice_move_vsi(hw, blk, vsi, vsig, chg); 520171d10453SEric Joyner if (status) 520271d10453SEric Joyner return status; 520371d10453SEric Joyner 520471d10453SEric Joyner LIST_FOR_EACH_ENTRY(t, lst, ice_vsig_prof, list) { 520571d10453SEric Joyner /* Reverse the order here since we are copying the list */ 520671d10453SEric Joyner status = ice_add_prof_id_vsig(hw, blk, vsig, t->profile_cookie, 520771d10453SEric Joyner true, chg); 520871d10453SEric Joyner if (status) 520971d10453SEric Joyner return status; 521071d10453SEric Joyner } 521171d10453SEric Joyner 521271d10453SEric Joyner *new_vsig = vsig; 521371d10453SEric Joyner 521471d10453SEric Joyner return ICE_SUCCESS; 521571d10453SEric Joyner } 521671d10453SEric Joyner 521771d10453SEric Joyner /** 521871d10453SEric Joyner * ice_find_prof_vsig - find a VSIG with a specific profile handle 521971d10453SEric Joyner * @hw: pointer to the HW struct 522071d10453SEric Joyner * @blk: hardware block 522171d10453SEric Joyner * @hdl: the profile handle of the profile to search for 522271d10453SEric Joyner * @vsig: returns the VSIG with the matching profile 522371d10453SEric Joyner */ 522471d10453SEric Joyner static bool 522571d10453SEric Joyner ice_find_prof_vsig(struct ice_hw *hw, enum ice_block blk, u64 hdl, u16 *vsig) 522671d10453SEric Joyner { 522771d10453SEric Joyner struct ice_vsig_prof *t; 522871d10453SEric Joyner enum ice_status status; 5229*7d7af7f8SEric Joyner struct LIST_HEAD_TYPE lst; 523071d10453SEric Joyner 523171d10453SEric Joyner INIT_LIST_HEAD(&lst); 523271d10453SEric Joyner 523371d10453SEric Joyner t = (struct ice_vsig_prof *)ice_malloc(hw, sizeof(*t)); 523471d10453SEric Joyner if (!t) 523571d10453SEric Joyner return false; 523671d10453SEric Joyner 523771d10453SEric Joyner t->profile_cookie = hdl; 523871d10453SEric Joyner LIST_ADD(&t->list, &lst); 523971d10453SEric Joyner 524071d10453SEric Joyner status = ice_find_dup_props_vsig(hw, blk, &lst, vsig); 524171d10453SEric Joyner 524271d10453SEric Joyner LIST_DEL(&t->list); 524371d10453SEric Joyner ice_free(hw, t); 524471d10453SEric Joyner 524571d10453SEric Joyner return status == ICE_SUCCESS; 524671d10453SEric Joyner } 524771d10453SEric Joyner 524871d10453SEric Joyner /** 524971d10453SEric Joyner * ice_add_vsi_flow - add VSI flow 525071d10453SEric Joyner * @hw: pointer to the HW struct 525171d10453SEric Joyner * @blk: hardware block 525271d10453SEric Joyner * @vsi: input VSI 525371d10453SEric Joyner * @vsig: target VSIG to include the input VSI 525471d10453SEric Joyner * 525571d10453SEric Joyner * Calling this function will add the VSI to a given VSIG and 525671d10453SEric Joyner * update the HW tables accordingly. This call can be used to 525771d10453SEric Joyner * add multiple VSIs to a VSIG if we know beforehand that those 525871d10453SEric Joyner * VSIs have the same characteristics of the VSIG. This will 525971d10453SEric Joyner * save time in generating a new VSIG and TCAMs till a match is 526071d10453SEric Joyner * found and subsequent rollback when a matching VSIG is found. 526171d10453SEric Joyner */ 526271d10453SEric Joyner enum ice_status 526371d10453SEric Joyner ice_add_vsi_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u16 vsig) 526471d10453SEric Joyner { 526571d10453SEric Joyner struct ice_chs_chg *tmp, *del; 526671d10453SEric Joyner struct LIST_HEAD_TYPE chg; 526771d10453SEric Joyner enum ice_status status; 526871d10453SEric Joyner 526971d10453SEric Joyner /* if target VSIG is default the move is invalid */ 527071d10453SEric Joyner if ((vsig & ICE_VSIG_IDX_M) == ICE_DEFAULT_VSIG) 527171d10453SEric Joyner return ICE_ERR_PARAM; 527271d10453SEric Joyner 527371d10453SEric Joyner INIT_LIST_HEAD(&chg); 527471d10453SEric Joyner 527571d10453SEric Joyner /* move VSI to the VSIG that matches */ 527671d10453SEric Joyner status = ice_move_vsi(hw, blk, vsi, vsig, &chg); 527771d10453SEric Joyner /* update hardware if success */ 527871d10453SEric Joyner if (!status) 527971d10453SEric Joyner status = ice_upd_prof_hw(hw, blk, &chg); 528071d10453SEric Joyner 528171d10453SEric Joyner LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) { 528271d10453SEric Joyner LIST_DEL(&del->list_entry); 528371d10453SEric Joyner ice_free(hw, del); 528471d10453SEric Joyner } 528571d10453SEric Joyner 528671d10453SEric Joyner return status; 528771d10453SEric Joyner } 528871d10453SEric Joyner 528971d10453SEric Joyner /** 529071d10453SEric Joyner * ice_add_prof_id_flow - add profile flow 529171d10453SEric Joyner * @hw: pointer to the HW struct 529271d10453SEric Joyner * @blk: hardware block 529371d10453SEric Joyner * @vsi: the VSI to enable with the profile specified by ID 529471d10453SEric Joyner * @hdl: profile handle 529571d10453SEric Joyner * 529671d10453SEric Joyner * Calling this function will update the hardware tables to enable the 529771d10453SEric Joyner * profile indicated by the ID parameter for the VSIs specified in the VSI 529871d10453SEric Joyner * array. Once successfully called, the flow will be enabled. 529971d10453SEric Joyner */ 530071d10453SEric Joyner enum ice_status 530171d10453SEric Joyner ice_add_prof_id_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl) 530271d10453SEric Joyner { 530371d10453SEric Joyner struct ice_vsig_prof *tmp1, *del1; 530471d10453SEric Joyner struct ice_chs_chg *tmp, *del; 5305*7d7af7f8SEric Joyner struct LIST_HEAD_TYPE union_lst; 530671d10453SEric Joyner enum ice_status status; 5307*7d7af7f8SEric Joyner struct LIST_HEAD_TYPE chg; 530871d10453SEric Joyner u16 vsig; 530971d10453SEric Joyner 531071d10453SEric Joyner INIT_LIST_HEAD(&union_lst); 531171d10453SEric Joyner INIT_LIST_HEAD(&chg); 531271d10453SEric Joyner 531371d10453SEric Joyner /* Get profile */ 531471d10453SEric Joyner status = ice_get_prof(hw, blk, hdl, &chg); 531571d10453SEric Joyner if (status) 531671d10453SEric Joyner return status; 531771d10453SEric Joyner 531871d10453SEric Joyner /* determine if VSI is already part of a VSIG */ 531971d10453SEric Joyner status = ice_vsig_find_vsi(hw, blk, vsi, &vsig); 532071d10453SEric Joyner if (!status && vsig) { 532171d10453SEric Joyner bool only_vsi; 532271d10453SEric Joyner u16 or_vsig; 532371d10453SEric Joyner u16 ref; 532471d10453SEric Joyner 532571d10453SEric Joyner /* found in VSIG */ 532671d10453SEric Joyner or_vsig = vsig; 532771d10453SEric Joyner 532871d10453SEric Joyner /* make sure that there is no overlap/conflict between the new 532971d10453SEric Joyner * characteristics and the existing ones; we don't support that 533071d10453SEric Joyner * scenario 533171d10453SEric Joyner */ 533271d10453SEric Joyner if (ice_has_prof_vsig(hw, blk, vsig, hdl)) { 533371d10453SEric Joyner status = ICE_ERR_ALREADY_EXISTS; 533471d10453SEric Joyner goto err_ice_add_prof_id_flow; 533571d10453SEric Joyner } 533671d10453SEric Joyner 533771d10453SEric Joyner /* last VSI in the VSIG? */ 533871d10453SEric Joyner status = ice_vsig_get_ref(hw, blk, vsig, &ref); 533971d10453SEric Joyner if (status) 534071d10453SEric Joyner goto err_ice_add_prof_id_flow; 534171d10453SEric Joyner only_vsi = (ref == 1); 534271d10453SEric Joyner 534371d10453SEric Joyner /* create a union of the current profiles and the one being 534471d10453SEric Joyner * added 534571d10453SEric Joyner */ 534671d10453SEric Joyner status = ice_get_profs_vsig(hw, blk, vsig, &union_lst); 534771d10453SEric Joyner if (status) 534871d10453SEric Joyner goto err_ice_add_prof_id_flow; 534971d10453SEric Joyner 535071d10453SEric Joyner status = ice_add_prof_to_lst(hw, blk, &union_lst, hdl); 535171d10453SEric Joyner if (status) 535271d10453SEric Joyner goto err_ice_add_prof_id_flow; 535371d10453SEric Joyner 535471d10453SEric Joyner /* search for an existing VSIG with an exact charc match */ 535571d10453SEric Joyner status = ice_find_dup_props_vsig(hw, blk, &union_lst, &vsig); 535671d10453SEric Joyner if (!status) { 535771d10453SEric Joyner /* move VSI to the VSIG that matches */ 535871d10453SEric Joyner status = ice_move_vsi(hw, blk, vsi, vsig, &chg); 535971d10453SEric Joyner if (status) 536071d10453SEric Joyner goto err_ice_add_prof_id_flow; 536171d10453SEric Joyner 536271d10453SEric Joyner /* VSI has been moved out of or_vsig. If the or_vsig had 536371d10453SEric Joyner * only that VSI it is now empty and can be removed. 536471d10453SEric Joyner */ 536571d10453SEric Joyner if (only_vsi) { 536671d10453SEric Joyner status = ice_rem_vsig(hw, blk, or_vsig, &chg); 536771d10453SEric Joyner if (status) 536871d10453SEric Joyner goto err_ice_add_prof_id_flow; 536971d10453SEric Joyner } 537071d10453SEric Joyner } else if (only_vsi) { 537171d10453SEric Joyner /* If the original VSIG only contains one VSI, then it 537271d10453SEric Joyner * will be the requesting VSI. In this case the VSI is 537371d10453SEric Joyner * not sharing entries and we can simply add the new 537471d10453SEric Joyner * profile to the VSIG. 537571d10453SEric Joyner */ 537671d10453SEric Joyner status = ice_add_prof_id_vsig(hw, blk, vsig, hdl, false, 537771d10453SEric Joyner &chg); 537871d10453SEric Joyner if (status) 537971d10453SEric Joyner goto err_ice_add_prof_id_flow; 538071d10453SEric Joyner 538171d10453SEric Joyner /* Adjust priorities */ 538271d10453SEric Joyner status = ice_adj_prof_priorities(hw, blk, vsig, &chg); 538371d10453SEric Joyner if (status) 538471d10453SEric Joyner goto err_ice_add_prof_id_flow; 538571d10453SEric Joyner } else { 538671d10453SEric Joyner /* No match, so we need a new VSIG */ 538771d10453SEric Joyner status = ice_create_vsig_from_lst(hw, blk, vsi, 538871d10453SEric Joyner &union_lst, &vsig, 538971d10453SEric Joyner &chg); 539071d10453SEric Joyner if (status) 539171d10453SEric Joyner goto err_ice_add_prof_id_flow; 539271d10453SEric Joyner 539371d10453SEric Joyner /* Adjust priorities */ 539471d10453SEric Joyner status = ice_adj_prof_priorities(hw, blk, vsig, &chg); 539571d10453SEric Joyner if (status) 539671d10453SEric Joyner goto err_ice_add_prof_id_flow; 539771d10453SEric Joyner } 539871d10453SEric Joyner } else { 539971d10453SEric Joyner /* need to find or add a VSIG */ 540071d10453SEric Joyner /* search for an existing VSIG with an exact charc match */ 540171d10453SEric Joyner if (ice_find_prof_vsig(hw, blk, hdl, &vsig)) { 540271d10453SEric Joyner /* found an exact match */ 540371d10453SEric Joyner /* add or move VSI to the VSIG that matches */ 540471d10453SEric Joyner status = ice_move_vsi(hw, blk, vsi, vsig, &chg); 540571d10453SEric Joyner if (status) 540671d10453SEric Joyner goto err_ice_add_prof_id_flow; 540771d10453SEric Joyner } else { 540871d10453SEric Joyner /* we did not find an exact match */ 540971d10453SEric Joyner /* we need to add a VSIG */ 541071d10453SEric Joyner status = ice_create_prof_id_vsig(hw, blk, vsi, hdl, 541171d10453SEric Joyner &chg); 541271d10453SEric Joyner if (status) 541371d10453SEric Joyner goto err_ice_add_prof_id_flow; 541471d10453SEric Joyner } 541571d10453SEric Joyner } 541671d10453SEric Joyner 541771d10453SEric Joyner /* update hardware */ 541871d10453SEric Joyner if (!status) 541971d10453SEric Joyner status = ice_upd_prof_hw(hw, blk, &chg); 542071d10453SEric Joyner 542171d10453SEric Joyner err_ice_add_prof_id_flow: 542271d10453SEric Joyner LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) { 542371d10453SEric Joyner LIST_DEL(&del->list_entry); 542471d10453SEric Joyner ice_free(hw, del); 542571d10453SEric Joyner } 542671d10453SEric Joyner 542771d10453SEric Joyner LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, &union_lst, ice_vsig_prof, list) { 542871d10453SEric Joyner LIST_DEL(&del1->list); 542971d10453SEric Joyner ice_free(hw, del1); 543071d10453SEric Joyner } 543171d10453SEric Joyner 543271d10453SEric Joyner return status; 543371d10453SEric Joyner } 543471d10453SEric Joyner 543571d10453SEric Joyner /** 543671d10453SEric Joyner * ice_add_flow - add flow 543771d10453SEric Joyner * @hw: pointer to the HW struct 543871d10453SEric Joyner * @blk: hardware block 543971d10453SEric Joyner * @vsi: array of VSIs to enable with the profile specified by ID 544071d10453SEric Joyner * @count: number of elements in the VSI array 544171d10453SEric Joyner * @id: profile tracking ID 544271d10453SEric Joyner * 544371d10453SEric Joyner * Calling this function will update the hardware tables to enable the 544471d10453SEric Joyner * profile indicated by the ID parameter for the VSIs specified in the VSI 544571d10453SEric Joyner * array. Once successfully called, the flow will be enabled. 544671d10453SEric Joyner */ 544771d10453SEric Joyner enum ice_status 544871d10453SEric Joyner ice_add_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi[], u8 count, 544971d10453SEric Joyner u64 id) 545071d10453SEric Joyner { 545171d10453SEric Joyner enum ice_status status; 545271d10453SEric Joyner u16 i; 545371d10453SEric Joyner 545471d10453SEric Joyner for (i = 0; i < count; i++) { 545571d10453SEric Joyner status = ice_add_prof_id_flow(hw, blk, vsi[i], id); 545671d10453SEric Joyner if (status) 545771d10453SEric Joyner return status; 545871d10453SEric Joyner } 545971d10453SEric Joyner 546071d10453SEric Joyner return ICE_SUCCESS; 546171d10453SEric Joyner } 546271d10453SEric Joyner 546371d10453SEric Joyner /** 546471d10453SEric Joyner * ice_rem_prof_from_list - remove a profile from list 546571d10453SEric Joyner * @hw: pointer to the HW struct 546671d10453SEric Joyner * @lst: list to remove the profile from 546771d10453SEric Joyner * @hdl: the profile handle indicating the profile to remove 546871d10453SEric Joyner */ 546971d10453SEric Joyner static enum ice_status 547071d10453SEric Joyner ice_rem_prof_from_list(struct ice_hw *hw, struct LIST_HEAD_TYPE *lst, u64 hdl) 547171d10453SEric Joyner { 547271d10453SEric Joyner struct ice_vsig_prof *ent, *tmp; 547371d10453SEric Joyner 5474*7d7af7f8SEric Joyner LIST_FOR_EACH_ENTRY_SAFE(ent, tmp, lst, ice_vsig_prof, list) 547571d10453SEric Joyner if (ent->profile_cookie == hdl) { 547671d10453SEric Joyner LIST_DEL(&ent->list); 547771d10453SEric Joyner ice_free(hw, ent); 547871d10453SEric Joyner return ICE_SUCCESS; 547971d10453SEric Joyner } 548071d10453SEric Joyner 548171d10453SEric Joyner return ICE_ERR_DOES_NOT_EXIST; 548271d10453SEric Joyner } 548371d10453SEric Joyner 548471d10453SEric Joyner /** 548571d10453SEric Joyner * ice_rem_prof_id_flow - remove flow 548671d10453SEric Joyner * @hw: pointer to the HW struct 548771d10453SEric Joyner * @blk: hardware block 548871d10453SEric Joyner * @vsi: the VSI from which to remove the profile specified by ID 548971d10453SEric Joyner * @hdl: profile tracking handle 549071d10453SEric Joyner * 549171d10453SEric Joyner * Calling this function will update the hardware tables to remove the 549271d10453SEric Joyner * profile indicated by the ID parameter for the VSIs specified in the VSI 549371d10453SEric Joyner * array. Once successfully called, the flow will be disabled. 549471d10453SEric Joyner */ 549571d10453SEric Joyner enum ice_status 549671d10453SEric Joyner ice_rem_prof_id_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi, u64 hdl) 549771d10453SEric Joyner { 549871d10453SEric Joyner struct ice_vsig_prof *tmp1, *del1; 549971d10453SEric Joyner struct ice_chs_chg *tmp, *del; 5500*7d7af7f8SEric Joyner struct LIST_HEAD_TYPE chg, copy; 550171d10453SEric Joyner enum ice_status status; 550271d10453SEric Joyner u16 vsig; 550371d10453SEric Joyner 550471d10453SEric Joyner INIT_LIST_HEAD(©); 550571d10453SEric Joyner INIT_LIST_HEAD(&chg); 550671d10453SEric Joyner 550771d10453SEric Joyner /* determine if VSI is already part of a VSIG */ 550871d10453SEric Joyner status = ice_vsig_find_vsi(hw, blk, vsi, &vsig); 550971d10453SEric Joyner if (!status && vsig) { 551071d10453SEric Joyner bool last_profile; 551171d10453SEric Joyner bool only_vsi; 551271d10453SEric Joyner u16 ref; 551371d10453SEric Joyner 551471d10453SEric Joyner /* found in VSIG */ 551571d10453SEric Joyner last_profile = ice_vsig_prof_id_count(hw, blk, vsig) == 1; 551671d10453SEric Joyner status = ice_vsig_get_ref(hw, blk, vsig, &ref); 551771d10453SEric Joyner if (status) 551871d10453SEric Joyner goto err_ice_rem_prof_id_flow; 551971d10453SEric Joyner only_vsi = (ref == 1); 552071d10453SEric Joyner 552171d10453SEric Joyner if (only_vsi) { 552271d10453SEric Joyner /* If the original VSIG only contains one reference, 552371d10453SEric Joyner * which will be the requesting VSI, then the VSI is not 552471d10453SEric Joyner * sharing entries and we can simply remove the specific 552571d10453SEric Joyner * characteristics from the VSIG. 552671d10453SEric Joyner */ 552771d10453SEric Joyner 552871d10453SEric Joyner if (last_profile) { 552971d10453SEric Joyner /* If there are no profiles left for this VSIG, 5530*7d7af7f8SEric Joyner * then simply remove the VSIG. 553171d10453SEric Joyner */ 553271d10453SEric Joyner status = ice_rem_vsig(hw, blk, vsig, &chg); 553371d10453SEric Joyner if (status) 553471d10453SEric Joyner goto err_ice_rem_prof_id_flow; 553571d10453SEric Joyner } else { 553671d10453SEric Joyner status = ice_rem_prof_id_vsig(hw, blk, vsig, 553771d10453SEric Joyner hdl, &chg); 553871d10453SEric Joyner if (status) 553971d10453SEric Joyner goto err_ice_rem_prof_id_flow; 554071d10453SEric Joyner 554171d10453SEric Joyner /* Adjust priorities */ 554271d10453SEric Joyner status = ice_adj_prof_priorities(hw, blk, vsig, 554371d10453SEric Joyner &chg); 554471d10453SEric Joyner if (status) 554571d10453SEric Joyner goto err_ice_rem_prof_id_flow; 554671d10453SEric Joyner } 554771d10453SEric Joyner 554871d10453SEric Joyner } else { 554971d10453SEric Joyner /* Make a copy of the VSIG's list of Profiles */ 555071d10453SEric Joyner status = ice_get_profs_vsig(hw, blk, vsig, ©); 555171d10453SEric Joyner if (status) 555271d10453SEric Joyner goto err_ice_rem_prof_id_flow; 555371d10453SEric Joyner 555471d10453SEric Joyner /* Remove specified profile entry from the list */ 555571d10453SEric Joyner status = ice_rem_prof_from_list(hw, ©, hdl); 555671d10453SEric Joyner if (status) 555771d10453SEric Joyner goto err_ice_rem_prof_id_flow; 555871d10453SEric Joyner 555971d10453SEric Joyner if (LIST_EMPTY(©)) { 556071d10453SEric Joyner status = ice_move_vsi(hw, blk, vsi, 556171d10453SEric Joyner ICE_DEFAULT_VSIG, &chg); 556271d10453SEric Joyner if (status) 556371d10453SEric Joyner goto err_ice_rem_prof_id_flow; 556471d10453SEric Joyner 556571d10453SEric Joyner } else if (!ice_find_dup_props_vsig(hw, blk, ©, 556671d10453SEric Joyner &vsig)) { 556771d10453SEric Joyner /* found an exact match */ 556871d10453SEric Joyner /* add or move VSI to the VSIG that matches */ 556971d10453SEric Joyner /* Search for a VSIG with a matching profile 557071d10453SEric Joyner * list 557171d10453SEric Joyner */ 557271d10453SEric Joyner 557371d10453SEric Joyner /* Found match, move VSI to the matching VSIG */ 557471d10453SEric Joyner status = ice_move_vsi(hw, blk, vsi, vsig, &chg); 557571d10453SEric Joyner if (status) 557671d10453SEric Joyner goto err_ice_rem_prof_id_flow; 557771d10453SEric Joyner } else { 557871d10453SEric Joyner /* since no existing VSIG supports this 557971d10453SEric Joyner * characteristic pattern, we need to create a 558071d10453SEric Joyner * new VSIG and TCAM entries 558171d10453SEric Joyner */ 558271d10453SEric Joyner status = ice_create_vsig_from_lst(hw, blk, vsi, 558371d10453SEric Joyner ©, &vsig, 558471d10453SEric Joyner &chg); 558571d10453SEric Joyner if (status) 558671d10453SEric Joyner goto err_ice_rem_prof_id_flow; 558771d10453SEric Joyner 558871d10453SEric Joyner /* Adjust priorities */ 558971d10453SEric Joyner status = ice_adj_prof_priorities(hw, blk, vsig, 559071d10453SEric Joyner &chg); 559171d10453SEric Joyner if (status) 559271d10453SEric Joyner goto err_ice_rem_prof_id_flow; 559371d10453SEric Joyner } 559471d10453SEric Joyner } 559571d10453SEric Joyner } else { 559671d10453SEric Joyner status = ICE_ERR_DOES_NOT_EXIST; 559771d10453SEric Joyner } 559871d10453SEric Joyner 559971d10453SEric Joyner /* update hardware tables */ 560071d10453SEric Joyner if (!status) 560171d10453SEric Joyner status = ice_upd_prof_hw(hw, blk, &chg); 560271d10453SEric Joyner 560371d10453SEric Joyner err_ice_rem_prof_id_flow: 560471d10453SEric Joyner LIST_FOR_EACH_ENTRY_SAFE(del, tmp, &chg, ice_chs_chg, list_entry) { 560571d10453SEric Joyner LIST_DEL(&del->list_entry); 560671d10453SEric Joyner ice_free(hw, del); 560771d10453SEric Joyner } 560871d10453SEric Joyner 560971d10453SEric Joyner LIST_FOR_EACH_ENTRY_SAFE(del1, tmp1, ©, ice_vsig_prof, list) { 561071d10453SEric Joyner LIST_DEL(&del1->list); 561171d10453SEric Joyner ice_free(hw, del1); 561271d10453SEric Joyner } 561371d10453SEric Joyner 561471d10453SEric Joyner return status; 561571d10453SEric Joyner } 561671d10453SEric Joyner 561771d10453SEric Joyner /** 561871d10453SEric Joyner * ice_rem_flow - remove flow 561971d10453SEric Joyner * @hw: pointer to the HW struct 562071d10453SEric Joyner * @blk: hardware block 562171d10453SEric Joyner * @vsi: array of VSIs from which to remove the profile specified by ID 562271d10453SEric Joyner * @count: number of elements in the VSI array 562371d10453SEric Joyner * @id: profile tracking ID 562471d10453SEric Joyner * 562571d10453SEric Joyner * The function will remove flows from the specified VSIs that were enabled 562671d10453SEric Joyner * using ice_add_flow. The ID value will indicated which profile will be 562771d10453SEric Joyner * removed. Once successfully called, the flow will be disabled. 562871d10453SEric Joyner */ 562971d10453SEric Joyner enum ice_status 563071d10453SEric Joyner ice_rem_flow(struct ice_hw *hw, enum ice_block blk, u16 vsi[], u8 count, 563171d10453SEric Joyner u64 id) 563271d10453SEric Joyner { 563371d10453SEric Joyner enum ice_status status; 563471d10453SEric Joyner u16 i; 563571d10453SEric Joyner 563671d10453SEric Joyner for (i = 0; i < count; i++) { 563771d10453SEric Joyner status = ice_rem_prof_id_flow(hw, blk, vsi[i], id); 563871d10453SEric Joyner if (status) 563971d10453SEric Joyner return status; 564071d10453SEric Joyner } 564171d10453SEric Joyner 564271d10453SEric Joyner return ICE_SUCCESS; 564371d10453SEric Joyner } 5644